<?php
ob_start();
ini_set('display_errors', 'off');
error_reporting(0);
define('MP_DB_DEBUG', false); 
defined('BASEPATH') OR exit('No direct script access allowed');

class Userpage extends CI_Controller {


		function __construct() {

        parent::__construct();
		
		$this->load->library('email');
        $this->load->database();
				$this->load->model('nationmodel','',TRUE);

		$this->load->model('usermodel','',TRUE);
		//	$this->load->database('smsdb', TRUE);
			$this->load->library('encryption');

		//$this->load->library('encrypt');
		$this->load->model('adminusermodel','',TRUE);
		$this->load->model("usermodel", "login",TRUE);
		$this->load->model('usermodel','',TRUE);

		 $this->load->model('studentprofilemodel','',TRUE);
      if( !isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], "order/place") === -1 ) {
    $this->load->helper('url');
    redirect('alert/page404');
}	


	$custom_key = 'KENGA';

        $encryption_config = [
            'cipher' => 'aes-256',
            'mode'   => 'cbc',
            'key'    => hash('sha256', $custom_key), 
        ];

        
        $this->encryption->initialize($encryption_config);







    }
	
	
	
   public function addmember()
    {
		
			$session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
         $postedtime = date('Y-m-d');
		$currenttime = date('H:i:s');
 		  $dateposted = date('Y-m-d H:i:s');
		 $userid = $data['id'];
		  $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
	 	 $myurl = $this->input->post("myurl");	 		

	 $computerno = trim($this->input->post("computerno"));	 		
 $firstname = $this->input->post("firstname");

	  $email = $this->input->post("email");
	  $phone = $this->input->post("phone");		  
		  $address_1 = $this->input->post("address_1");    
		 $gender = $this->input->post("gender");   
		  $city = $this->input->post("city");   
		   $zip = $this->input->post("zip");   
		    $country = $this->input->post("country");   
			 $comments = $this->input->post("comments");   
			  $image_id = $this->input->post("image_id");   
			   $category = $this->input->post("category");   
			    $status = $this->input->post("status");   
				 $company = $this->input->post("company");
				 $myidnumber = $this->input->post("idnumber");
			 $idnumber="";
			  $correctbranchid = $this->input->post("branchid");
			  $mybranch="";
			  			   $myphone = $this->input->post("myphone");

			   $name = $this->input->post("name");
			 $computernouserdata="Submited by ". $name. ", With Phone No: ". $myphone." at ".  $dateposted;

			 
		
			 
			 
			 
			 
			 

			 $categoryid="";
				 			  $group = $this->input->post("categoryid");
 
 $website = $this->input->post("website"); 
 $idno = $this->input->post("idno"); 
  $entrydate = $this->input->post("entrydate"); 

		  $view = $this->input->post("view"); 
		
			  		  $this->form_validation->set_rules("phone", "Phone", "trim|required");

			  
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      $this->load->view("template/headerpagemin");

		
		 $this->load->view('userdata/viewmember', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_addmember') == "member")
					   {
				
						   				   								$confirmuser = $this->usermodel->populatealldataarray('peopleregistration','computerno', $computerno,'computernostatus', "new");
						   			$details="Details are :Name: ".$confirmuser[0]['firstname'].", Company: ".$confirmuser[0]['company'].",Phone: ".$confirmuser[0]['phone']." .";




	  if($confirmuser !=false){
							   
						   
						   			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> That computer key had been submitted to Robisearch team. Try again.</div>');


	$message="That computer key had been submitted to Robisearch team earlier but has not been approved. Reach out to Robisearch team to approve the key on : 0790962631/0716413386/0718667391. Then try submitting it again";
redirect($myurl."newserial?msg=".$message);	





						  	//redirect($myurl."newserial");
								//redirect($view);	
	   return false;
					   }
					     
						    
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   				   								$confirmusers = $this->usermodel->populatealldataarray('peopleregistration','phone', $phone,'id >', 1);
						   			$details="Details are :Name: ".$confirmusers[0]['firstname'].", Company: ".$confirmusers[0]['company'].",Phone: ".$confirmusers[0]['phone']." .";
	   if($confirmusers !=false){
							   
						   
						   			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> That computer key already exist on the system.'.	$details.' Try again.</div>');

						  						 // 	redirect($myurl."newserial");



	$message="That computer key already exist on the system.'.	$details.' Try again.";
redirect($myurl."serial?msg=".$message);	






								//redirect($view);	
	   return false;
					   }
					   
					   
						   
												$data=array(		
			'userid'=>"0",
							'computerno'=>$computerno,
							'computernouserdata'=>$computernouserdata,

				'firstname'=>$firstname,
			
		  	'email'=>$email,
			
			
			'createdate'=>$dateposted,
			'phone' => $phone,		  
		  'address_1' => $address_1,    
		 'gender' => $gender,   
		  'city' => $city,   
		   'zip' => $zip,   
		    'country' => $country,   
			 'comments' => $comments,   
			  
			   'category' => $category,   
			    'status' => $status,  
				'company' => $company,   
				  
				 'website' => $website, 
				 'idno' => $idno, 
				  'companyid' => 1, 
							  'entrydate' => $entrydate, 
							  'idnumber' => $idnumber, 
					'group' => $group, 

							  							  'branchid' => 1, 


			
			
								);
							$usr_result = $this->usermodel->add($data,'peopleregistration');
							
							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{


   
					


									 $this->pushroomsmsNull("Computer with key: $computerno has been sent for activation by $name: $phone " ,"254790962631","");

							
								 
						 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
								<strong>Success!</strong> You have successfully Submitted Computer Key for Activation..</div>');	
													 // 	redirect($myurl."newserial");

								//redirect($view);	
															//redirect($myurl."newserial");
	$message="You have successfully Submitted Computer Key for Activation. Kindly try refresh after few minutes and now request for existing key or reach out to Robisearch team on : 0790962631/0716413386/0718667391.";
redirect($myurl."serial?msg=".$message);	
																							
							}
							else if ($usr_result ==FALSE) 
							{     

			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Member  was not added.. Try again</div>');
							//redirect($myurl."newserial");

								$message="Business was not submitted.. Try again";

						   
						  				redirect($myurl."newserial?msg=".$message);								//redirect($view);	

							}
					   }
					   else
					   {
						   						  	redirect($myurl."login");

							//redirect('login');
					   }
	    }
    }
	public function getcompserial()
		
	{ 
 if (!$this->input->post('btn_updaConfirm') == "Confirm")
					   {
						  

      show_error('No identifier provided.try again', 500);
    }
    else {
		
		 
		//$name="";
			 		  $createddate = date('Y-m-d H:i:s');

		
		     $computerno = trim($this->input->post('computerno'));
			
		     $phone = $this->input->post('phone');

			 		     $myurl = $this->input->post('myurl');
   $name = $this->input->post('name');
		  
$computernouserdata="Submited by ". $name. ", With Phone No: ". $phone." at ".  $createddate;

			//$this->load->view("template/headerpagegeneral");

		
						$confirmcodes = $this->usermodel->populatealldatanorraythree('computers','computerno', $computerno,'computernostatus',"closed",'status',"1");

			if($confirmcodes !=FALSE){
						
			$data['myurl']=$myurl;
			
$data['computerno']=$computerno;
			
			//  $message=$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 // <strong>Warning!</strong> This computer  key '.$computerno.' does not exist. It seems like that code has been activated in the main database or it has not been fowarded to Robisearch LTD for activation.Kindly foward the code to any of these numbers:0790962631/0716413386/0718667391.</div>');
						  

					redirect($myurl.'nocomputernoexist');

					return false;
					}
		
		
				$confirmcode = $this->usermodel->populatealldatanorraythree('computers','computerno', trim($computerno),'computernostatus',"new",'status',"1");

		
		
		
		
		
		
		
		
		
			if($confirmcode==FALSE){
						
			$data['myurl']=$myurl;
			
$data['computerno']=$computerno;
			
			  $message=$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Warning!</strong> This computer  key '.$computerno.' does not exist. It seems like that code has been activated in the main database or it has not been fowarded to Robisearch LTD for activation.Kindly foward the code to any of these numbers:0790962631/0716413386/0718667391.</div>');
						  

					redirect($myurl.'nocomputerno');

					return false;
					}else{
					 				$correctkey="MANDELAFILGONA#@!!@#";

						
					

 							 $businesskey = trim($this->encryption->encrypt(($computerno.$correctkey))); 
								 
				
						 
						

	$data['myurl']=$myurl;
			
$data['computerno']=$computerno;
	//$data['businesskey']=$businesskey;
			
$data['name']=$name;
		 
								 
								 			$updatecomputerno=array(		
		
			
			
		  	//'computernostatus'=>"createddate",
				 
	
		  	'computernodate'=>$createddate,
			'computernouserdata'=>$computernouserdata,
		  
								);
							$message="The computer key has been approved. Kindly Click to activate the key button";

					$this->usermodel->updatedata($updatecomputerno,'people','computerno',$computerno);
						 					$this->usermodel->updatedata($updatecomputerno,'computers','computerno',$computerno);

						 redirect($myurl.'getcompnoready?businesskey='.$businesskey."&phone=".$phone."&name=".$name."&msg=".$message);




						   
						  			//	redirect($myurl."config?msg=".$message);










						  // redirect($myurl.'getpaymentready?business='.$business."&phone=".$phone."&units=".$units."&amount=".$amount."&description=".$description."&code=".$code."&rate=".$rate);	

         //$this->load->view("template/headerpage");
		          //$this->load->view("template/page404");
		//$this->load->view("userdata/startpayment",$data);
				//	$this->load->view("template/footerpage");


					}
		
					     		
								
								 
											
										
		
	}
	
	}
  
	
	
	
	
	
	
	
	
	
	
	
	
	
		public function getetimsrequest()
		
	{ 
 if (!$this->input->post('btn_Confirmetimsapproval') == "Confirm")
					   {
						  

      show_error('No identifier provided.try again', 500);
    }
    else {
		
		 
		//$name="";
			 		  $createddate = date('Y-m-d H:i:s');

		
		      $invoice = trim($this->input->post('invoice'));
		     $mrcNo = $this->input->post('mrcNo');

			 		     $myurl = $this->input->post('myurl');
   $name = $this->input->post('name');
		  
$computernouserdata="Submited by ". $name. ", With Phone No: ". $phone." at ".  $createddate;

			//$this->load->view("template/headerpagegeneral");

		
			$confirmcodes = $this->usermodel->populatealldatanorraythree('etimsactivations','mrcNo',trim($mrcNo),'invoice',trim($invoice),'status',"Closed");

			if($confirmcodes !=FALSE){
						
			$data['myurl']=$myurl;
			
$data['computerno']=$mrcNo;
			
			//  $message=$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 // <strong>Warning!</strong> This computer  key '.$computerno.' does not exist. It seems like that code has been activated in the main database or it has not been fowarded to Robisearch LTD for activation.Kindly foward the code to any of these numbers:0790962631/0716413386/0718667391.</div>');
						  

					//redirect($myurl.'nocomputernoexist');

					//return false;
					}
		
		
			$confirmcode = $this->usermodel->populatealldatanorraythree('etimsactivations','mrcNo', trim($mrcNo),'invoice',trim($invoice),'status',"Ready");

		
			if($confirmcode==FALSE){
						
			$data['myurl']=$myurl;
			
$data['computerno']=$mrcNo;
			$data['invoice']=$invoice;

			  $message=$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Warning!</strong> This Device serial number does not exist. It seems like that code has been activated in the main database or it has not been submitted for  to Robisearch LTD for activation.Kindly foward the code to any of these numbers:0790962631/0716413386/0718667391.</div>');
						  

					redirect($myurl.'nocomputerno');

					return false;
					}else{
				
				
						 
				$confirmcode[0]['mrcNo'];		

	$data['myurl']=$myurl;
	$data['computerno']=$confirmcode[0]['mrcNo'];
	$data['invoice']=$confirmcode[0]['invoice'];		
	$data['verification']=$confirmcode[0]['verification'];
	$data['businesskey']=$confirmcode[0]['businesskey'];;
				$verification=$confirmcode[0]['verification'];
	$businesskey=$confirmcode[0]['businesskey'];;
		$data['name']=$name;
		 
								 
								 			$updatecomputerno=array(		
		
			
			
		  	//'computernostatus'=>"createddate",
				 
	
		  	'computernodate'=>$createddate,
			'computernouserdata'=>$computernouserdata,
		  			'status'=>"Closed",
					'computernostatus'=>"Closed",
								);
							$message="The ETIMS Device serial has been approved. Kindly Click to activate the key button";

					//$this->usermodel->updatedata($updatecomputerno,'people','computerno',$computerno);
						 					$this->usermodel->updatedata($updatecomputerno,'etimsactivations','invoice',$invoice);

						 redirect($myurl.'getcompnoreadyetims?businesskey='.$businesskey."&invoice=".$invoice."&mrcNo=".$mrcNo."&name=".$name."&verification=".$verification."&msg=".$message);




					}
		
					     		
								
								 
											
										
		
	}
	
	}
  
	
	
	
	
	
	
	
	
	
	
	 public function updateetimsurl()
    {
		
			$session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
	$data['companyid'] = $session_data['companyid'];
         $postedtime = date('Y-m-d');
		$currenttime = date('H:i:s');
 		  $dateposted = date('Y-m-d H:i:s');
		 $userid = $data['id'];
		  $companyid = $data['companyid'];
		 		 $invoice = $this->input->post("invoice");

		 		 $verification = $this->input->post("verification");
		 		 $name = $this->input->post("name");
	 $msrl = $this->input->post("name");
		   	  $url = $this->input->post("url");
			  
		    
		
				
			  		  $this->form_validation->set_rules("invoice", "invoice", "trim|required");

			  
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      $this->load->view("template/headerpagemin");

		
		 $this->load->view('etimsconfig', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_updateetimsconfirmation') == "updateurlMAIN")
					   {
												$data=array(		
		
			
				//'url'=>$url,
			
		  	'verification'=>$verification,
			 	//'companyid'=>$companyid,
			
			//'createdate'=>$dateposted,
				
			
								);
														$usr_result = $this->usermodel->updatedata($data,'etiminitialization','bhfSttsCd',$invoice);


														
							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
								
								 
						 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
								<strong>Success!</strong> You have successfully updated the Url..</div>');	
							redirect('user/viewetiminitialize');																
							}
							else if ($usr_result ==FALSE) 
							{     

			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Url  was not Updated.. Try again</div>');
								
								 redirect('user/viewetiminitialize');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

	
	
	
	 public function getpaymentready()
    {
		if (!isset($_GET['code'])){

    
      show_error('No identifier provided', 500);
    }
    else {

   
 
    	  $phone = $_GET['phone'];	  
		  $amount = $_GET['amount'];    
		 $code = $_GET['code'];
		 		 $description = $_GET['description']; 
	  $business = $_GET['business'];	  

			
				 $rate = $_GET['rate'];   
		 $units = $_GET['units'];
	 
		 	         $this->load->view("template/headerpage");

	 $this->load->view("userdata/startpayment");
					$this->load->view("template/footerpage");
	 
	 
	}}
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
   public function getcompnoreadydate()
    {
		if (!isset($_GET['deadline'])){

    
      show_error('No identifier provided', 500);
    }
    else {

   
 
   
    
		 		 $deadline =( $_GET['deadline']); 
	 
	 
			
		 	         	$this->load->view("template/headerpagelogin");
		      	$this->load->view("template/headerpagegeneral");

			$data['deadline']=$deadline;
		 $this->load->view('config', $data);
	// $this->load->view("config");
					$this->load->view("template/footerpage");
	 
	 
	}
	}
		
	
	
	 public function getcompnoready()
    {
		if (!isset($_GET['businesskey'])){

    
      show_error('No identifier provided', 500);
    }
    else {

   
 
    	  $phone = $_GET['phone'];	  
		  $name = $_GET['name'];    
		 $computerno = $_GET['computerno'];
		 		 $businesskey = $_GET['businesskey']; 
	 
	 		 		 $msg = $_GET['msg']; 

		 	         	$this->load->view("template/headerpagelogin");
		      	$this->load->view("template/headerpagegeneral");

	 $this->load->view("config");
					$this->load->view("template/footerpage");
	 
	 
	}}
  
	
	public function getcompnoreadyetims()
    {
		if (!isset($_GET['businesskey'])){

    
      show_error('No identifier provided', 500);
    }
    else {

   
 
    	  $phone = $_GET['phone'];	  
		  $name = $_GET['name'];    
		 $computerno = $_GET['computerno'];
		 		 $verification = $_GET['verification']; 
	  $businesskey = $_GET['businesskey']; 
	 		 		 $msg = $_GET['msg']; 

		 	         	$this->load->view("template/headerpagelogin");
		      	$this->load->view("template/headerpagegeneral");

	 $this->load->view("etimsconfig");
					$this->load->view("template/footerpage");
	 
	 
	}}
  
	
		public function nocomputerno()
	{  	
      $this->load->view("template/headerpagelogin");
		
		$this->load->view("template/headerpagegeneral");
		

		
		$this->load->view('nocomputerno');
		$this->load->view("template/footerpage");
	}
		
		public function nocomputernoexist()
	{  	
      $this->load->view("template/headerpagelogin");
		
		$this->load->view("template/headerpagegeneral");
		

		
		$this->load->view('nocomputernoexist');
		$this->load->view("template/footerpage");
	}
	
	
		public function nopayement()
	{  	
        $this->load->view("template/headerpage");

		
		$this->load->view('userdata/nopayment');
		$this->load->view("template/footerpage");
	}
	
	
	
		public function search()

	{

		$json = [];


	//	$this->load->database();


		

		if(!empty($this->input->get("q"))){

			$this->db->like('name', $this->input->get("q"));

			$query = $this->db->select('id,name')

						->limit(10)

						->get("county");

			$json = $query->result();

		}



		//echo json_encode($json);

	}
	
	
	
	
		
	public function index33()
	{  	$this->load->view("template/headerpagelogin");
		
		$this->load->view("template/headerpagegeneral");
		
		

	

		$this->load->view('index33');


	
}
			
	public function page404()
	{  	$this->load->view("template/headerpagelogin");
		
		$this->load->view("template/headerpagegeneral");
		
		

	

		$this->load->view('page404');


	
}
	
	
	
	
	
	public function index()
	{  
		
		
		
		
		 $smsconfig = $this->usermodel->populateallarray('smsconfig','id',1);
		 	  $view=$smsconfig[0]['view'];	
  $ecommerce=$smsconfig[0]['ecommerce'];	
  
  if($ecommerce=="activate"){
	  
	  
	  								 redirect('viewproductlist');

  }else{
	  
	  

		$this->load->view("template/headerpagelogin");
		
		$this->load->view("template/headerpagegeneral");
						

if($view=="CompleteTouch"){
		$this->load->view('index');

	
}else{
		$this->load->view('index2');


	
}

		$this->load->view("template/footerpage");
  }
	}
	
	public function more()
	{  	$this->load->view("template/headerpagelogin");
			$this->load->view("template/headerpagegeneral");
		$this->load->view('more');
		$this->load->view("template/footerpage");
	}
			public function extendserial()
	{  	$this->load->view("template/headerpagelogin");
			$this->load->view("template/headerpagegeneral");
		$this->load->view('extendserial');
		//$this->load->view("template/footerpage");
	}
	
		public function newserial()
	{  	$this->load->view("template/headerpagelogin");
	
	
			$this->load->view("template/headerpagegeneral");
			
if(isset($_GET['msg'])) {
			      $msg = $_GET['msg'];

			$data['msg']=$msg;
		 $this->load->view('newserial', $data);
			 }else{
				$this->load->view('newserial');

			 }
			
			
		
		$this->load->view("template/footerpage");
	}
	public function serial()
	{  	$this->load->view("template/headerpagelogin");
			$this->load->view("template/headerpagegeneral");
		
		if(isset($_GET['msg'])) {
			      $msg = $_GET['msg'];

			$data['msg']=$msg;
		 $this->load->view('serial', $data);
			 }else{
				$this->load->view('serial');

			 }
		$this->load->view("template/footerpage");
	}
	
	
	
	
	
	
	
		public function price()
	{  	$this->load->view("template/headerpagelogin");
			$this->load->view("template/headerpagegeneral");
		$this->load->view('price');
		$this->load->view("template/footerpage");
	}
	
		
	public function signup()
	{  	$this->load->view("template/headerpagelogin");
			$this->load->view("template/headerpagegeneral");
		$this->load->view('signupuser');
		$this->load->view("template/footerpage");
	}
	

		  public function config() {
	  
	 
$session_data = $this->session->userdata('logged_in');
	 	$this->load->view("template/headerpagelogin");

$this->load->view("template/headerpagegeneral");
   
 	$data['id'] = $session_data['id'];
         $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
		 $userid = $data['id'];
		 	 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
	 

        		$data['configuration'] = $this->usermodel->populateallarray('smsconfig','id >',0);

				
		
		$this->load->view("template/tableheader");
	
$data['userid']=$companyid;

if(isset($_GET['msg'])) {
			      $msg = $_GET['msg'];

			$data['msg']=$msg;
		 $this->load->view('config', $data);
			 }else{
				$this->load->view('config');

			 }
		$this->load->view("template/footerpage");
		
	
  }
  
	
public function login()
	{  	$this->load->view("template/headerpagelogin");
		$this->load->view("template/headerpagegeneral");
	
		
			
		 $smsconfig = $this->usermodel->populateallarray('smsconfig','id',1);
		 	  $view=$smsconfig[0]['view'];	


	
						

if($view=="CompleteTouch"){
		$this->load->view('index');

	
}else{
		$this->load->view('index2');


	
}

		$this->load->view("template/footerpage");
	}
	
 
	
	
	public function updatebusinessconfiguration()
    {
		//
			$session_data = $this->session->userdata('logged_in');
  $data['id'] = $session_data['id'];
	 $userid = $data['id'];
   
 	$data['id'] = $session_data['id'];
         $postedtime = date('Y-m-d');
		$currenttime = date('H:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
	
				$session_data = $this->session->userdata('logged_in');
		 	 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];	

//$encrypted = $this->encryption->encrypt('mysecret');
//$decrypted = $this->encryption->decrypt($encrypted);
//
 //$confirmkey = trim($this->encryption->encrypt($finalbusinesskey)); 
	$custom_key = 'KENGA';

        $encryption_config = [
            'cipher' => 'aes-256',
            'mode'   => 'cbc',
            'key'    => hash('sha256', $custom_key), 
        ];

        
        $this->encryption->initialize($encryption_config);


 		  $MYbusiness = trim($this->input->post("businesskey"));		
 							  $MYbusinesskey =trim($this->encryption->decrypt($MYbusiness));

			 		  $tester = trim($this->input->post("tester"));		

$correctkey ="FILGONA#@!!@#";
			 $this->form_validation->set_rules("businesskey", "businesskey ", "trim|required");

			  
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      $this->load->view("template/headerpagelogin");
			$this->load->view("template/headerpagegeneral");

		
		 $this->load->view('config', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
			
					   //validation succeeds
					 	if ($this->input->post('btn_updabusinessteconfig') == "myconfig")
					   {
						   
						   
						   
						   
						   
						   if(($tester=="") || ($tester!="ROBERT")) {
					
				
				
				 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 						  <strong>Error!</strong>You do not have valid  license to use our software.Kindly purchase a license or use correct software. NOT counterfeit/Fake product. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');
						 

								
							 redirect('config');
								 return false;
				}
				
						   
						   
						   
						    $serial =trim(`wmic bios get serialnumber 2>&1`) ;
$myfinalserial= explode("SerialNumber",str_replace("", "", $serial));
$finalserial = trim($myfinalserial[1]);

						   
						   
						 
								
								  
								  $localIP = getHostByName(getHostName());
										if($finalserial==""){
										$finalserial=trim($localIP);
										}	

								  
								  
								  
								   // $MYfinalserial = trim($myfinalserial[1]);
								
								    $CORRECTCODE= explode("MANDELA",$MYbusinesskey);
								
						
								     $CONFIRMcorrectkey = ($CORRECTCODE[1]);

 							  $finalserialdecoded =trim($CORRECTCODE[0]);
							

								  
							if($correctkey != $CONFIRMcorrectkey){
					
				
				
				 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 <strong>Error!</strong> The Activation key entered is not allowed/ AUTHORIZED. It seems like you are using cracked system of ROBISEARCH LTD. Ensure you contact ROBISEARCH LTD(0718667391) to be allowed to use this system </div>');
								
							 redirect('config');
								 return false;
				}
							  



 $ckey="OUKOMANDELA#@!!@#FILGONA#@!";



$finalbusinesskey=trim($finalserialdecoded. $ckey);


 $confirmkey = trim($this->encryption->encrypt($finalbusinesskey)); 

        		$data['configuration'] = $this->usermodel->populateallarray('smsconfig','id > ',0);
				
				
				
				
				if($finalserialdecoded != ($finalserial)){
					
				
				
				 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 <strong>Error!</strong> The Activation key entered is not correct.. Try again</div>');
								
							 redirect('config');
								 return false;
				}
				


				
				//$dbpassword =$this->encryption->decrypt($usr_result[0]->password);
				
				
				
			
		
						   
						   
												$data=array(		
		
							
			'businesskey'=>$confirmkey,
		

		
								);
						
								$usr_result = $this->usermodel->updatedata($data,'smsconfig','id >',0);

							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
								
								 
						 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
								<strong>Success!</strong> You have successfully updated  the license key..</div>');	
						 redirect('config');																
							}
							else if ($usr_result ==FALSE) 
							{     

			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> The license key was not updated.. Try again</div>');
								
								 redirect('config');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }
	
		public function updatebusisinessconfiguration()
    {
		
			$session_data = $this->session->userdata('logged_in');
  $data['id'] = $session_data['id'];
	 $userid = $data['id'];
   
 	$data['id'] = $session_data['id'];
         $postedtime = date('Y-m-d');
		$currenttime = date('H:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
	
				$session_data = $this->session->userdata('logged_in');
		 	 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];	
	$custom_key = 'KENGA';

        $encryption_config = [
            'cipher' => 'aes-256',
            'mode'   => 'cbc',
            'key'    => hash('sha256', $custom_key), 
        ];

        
        $this->encryption->initialize($encryption_config);


 		  $MYbusiness = trim($this->input->post("businesskey"));		
 		   $MYbusinesskey =($this->encryption->decrypt($MYbusiness));
		 

			 		  $tester = trim($this->input->post("tester"));		

$correctkey ="FILGONA#@!!@#";
			 $this->form_validation->set_rules("businesskey", "businesskey ", "trim|required");

			  
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      $this->load->view("template/headerpage");

		
		 $this->load->view('config', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
			
					   //validation succeeds
					 	if ($this->input->post('btn_updabusinessteconfig') == "myconfig")
					   {
						   
						   
						 
						   
						   if(($tester=="") || ($tester!="ROBERT")) {
					
				
				
				 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 						  <strong>Error!</strong>You do not have valid  license to use our software.Kindly purchase a license or use correct software. NOT counterfeit/Fake product. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0780655987 /0718667391 /0716413386 ).</div>');
						 

								
							 redirect('config');
								 return false;
				}
				
						   
						   
						   
						   
						   
						   
						   
						    $serial =`wmic bios get serialnumber 2>&1` ;

							//$serial =  shell_exec('wmic DISKDRIVE GET SerialNumber 2>&1');
							  $myfinalserial= explode("SerialNumber",str_replace("", "", $serial));

								  $finalserial = trim($myfinalserial[1]);
								  
								  
								   // $MYfinalserial = trim($myfinalserial[1]);
								
								    $CORRECTCODE= explode("MANDELA",$MYbusinesskey);
								
						
								     $CONFIRMcorrectkey = ($CORRECTCODE[1]);

 							  $finalserialdecoded =trim($CORRECTCODE[0]);
							

								  
							if($correctkey != $CONFIRMcorrectkey){
					
				
				
				 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 <strong>Error!</strong> The Activation key entered is not allowed/ AUTHORIZED. It seems like you are using cracked system of ROBISEARCH LTD. Ensure you contact ROBISEARCH LTD(0718667391) to be allowed to use this system </div>');
								
							 redirect('config');
								 return false;
				}
							  

 $ckey="OUKOMANDELA#@!!@#FILGONA#@!";



$finalbusinesskey=$finalserialdecoded.$ckey;


 $confirmkey = trim($this->encryption->encrypt($finalbusinesskey)); 

        		$data['configuration'] = $this->usermodel->populateallarray('smsconfig','id > ',0);
				
								  
 $localIP = getHostByName(getHostName());
if($finalserial==""){
$finalserial=$localIP;
}	
				
				if($finalserialdecoded != $finalserial){
					
				
				
				 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 <strong>Error!</strong> The Activation key entered is not correct.. Try again</div>');
								
							 redirect('config');
								 return false;
				}
				


				
				//$dbpassword =$this->encryption->decrypt($usr_result[0]->password);
				
				
				
			
		
						   
						   
												$data=array(		
		
							
			'businesskey'=>$confirmkey,
		

		
								);
						
								$usr_result = $this->usermodel->updatedata($data,'smsconfig','id >',0);

							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
								
								 
						 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
								<strong>Success!</strong> You have successfully updated  the license key..</div>');	
						 redirect('config');																
							}
							else if ($usr_result ==FALSE) 
							{     

			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> The license key was not updated.. Try again</div>');
								
								 redirect('config');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }
	
	
	
	public function updatedate()
    {
		
			$session_data = $this->session->userdata('logged_in');
  $data['id'] = $session_data['id'];
	 $userid = $data['id'];
   
 	$data['id'] = $session_data['id'];
         $postedtime = date('Y-m-d');
		$currenttime = date('H:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
	
				$session_data = $this->session->userdata('logged_in');
		 	 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];	

 		  $tester = trim($this->input->post("tester"));		

 		  $mykey = trim($this->input->post("mykey"));		
 		  $deadline = trim($this->input->post("deadline"));		

			

			 $this->form_validation->set_rules("mykey", "mykey ", "trim|required");

			  
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      $this->load->view("template/headerpage");

		
		 $this->load->view('config', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_updatedate') == "date")
					   {
						   
						   
						   	$custom_key = 'KENGA';

        $encryption_config = [
            'cipher' => 'aes-256',
            'mode'   => 'cbc',
            'key'    => hash('sha256', $custom_key), 
        ];

        
        $this->encryption->initialize($encryption_config);

						   			   
						   if(($tester=="") || ($tester!="OUKO")) {
					
				
				
				 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 						  <strong>Error!</strong>You do not have valid  license to use our software.Kindly purchase a license or use correct software. NOT counterfeit/Fake product. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0780655987 /0718667391 /0716413386 ).</div>');
						 

								
							 redirect('config');
								 return false;
				}
				
								 
								  	$myyear = $deadline[4].$deadline[5].$deadline[6].$deadline[7];
								  	$mymonth = $deadline[8].$deadline[9];
								  
								  	$mydate = $deadline[10].$deadline[11];
							 $finaldate=$myyear."-".$mymonth ."-".$mydate;

							 $myfinaldate=$myyear."-".$mymonth ."-".$mydate;

		   
						   
						   
						   
						   
						     $CURRENTDATA="#@!!@#FILGONAMANDELA#@!";
								  //$mymin =date('i');
								$mymin =date('i');$myday =date('l');  $myhour =date('H');$mydate =date('d');$mymonth =date('m');$myyear =date('Y');$ourfinaldate=$myyear-$mydate;$born=2015+$mydate;





$normalday="";
$ubnormalday="";
$combineddays="";
if($myday=="Monday"){
	
$ubnormalday=2;
$normalday=1;
}else if($myday=="Tuesday"){
$ubnormalday=3;
$normalday=2;
	
}else if($myday=="Wednesday"){
	$ubnormalday=4;
$normalday=3;
}else if($myday=="Thursday"){
		$ubnormalday=5;
$normalday=4;
}else if($myday=="Friday"){
	$ubnormalday=6;
$normalday=5;
}else if($myday=="Saturday"){
	$ubnormalday=7;
$normalday=6;
}else if($myday=="Sunday"){
		$ubnormalday=1;
$normalday=7;
}else{
			$ubnormalday=11;

}
$combineddays=$ubnormalday.$normalday;


$factormin="";
$combinedminutes="";
if($mymin <=12){
	
$combinedminutes=12;
}else if($mymin <=24){
$combinedminutes=24;

	
}else if($mymin <=36){
$combinedminutes=36;
}else if($mymin <=48){
$combinedminutes=48;

}else if($mymin <=60){
$combinedminutes=60;
}else{
	$combinedminutes=1;

}

$factormin=$combinedminutes;
$differntdate=$combineddays-$mydate;
if($differntdate < 0){
	$differntdate=	$differntdate*-1;
}else{
		$differntdate=	$differntdate;

}

								  $mainkey=$combineddays*$differntdate*$myhour*$factormin*$ourfinaldate;
								
								$firstTwoCharacters = $mainkey[0] . $mainkey[1];
								 
								$firstTwoCharacters = substr($mainkey, 0, 2);
								  
								  	$first2characters = $mykey[0] . $mykey[1];
								 
								$first2characters = substr($mykey, 0, 2);
								  $different=$combinedminutes-$mymin;
							  
									function removeChar($value) {
										$value2 = substr($value, 2); 
										return $value2;
									}
								
								
									$finalkey=($mainkey);
									if($mykey==$CURRENTDATA){
									
								

$decodedate = trim($this->encryption->encrypt($myfinaldate)); 

				
		   
						   
												$data=array(		
		
							
			'deadline'=>$decodedate,
		

		
								);
						
								$usr_result = $this->usermodel->updatedata($data,'smsconfig','id >',0);

							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
								
								 
						 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
								<strong>Success!</strong> You have successfully updated  the  details ..</div>');	
						 redirect('config');																
							}
							else if ($usr_result ==FALSE) 
							{     

			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> The  details  were not updated.. Try again</div>');
								
								 redirect('config');
							}
										
										
									}else{
										
								
									
										$finalcurrentkey=($mykey);
										
										
										
									if($finalcurrentkey==$finalkey){





$decodedate = trim($this->encryption->encrypt($myfinaldate)); 

						   
						   
						   
												$data=array(		
		
							
			'deadline'=>$decodedate,
		

		
								);
						
								$usr_result = $this->usermodel->updatedata($data,'smsconfig','id >',0);

							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
								
								 
						 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
								<strong>Success!</strong> You have successfully updated  the  details ..</div>');	
						 redirect('config');																
							}
							else if ($usr_result ==FALSE) 
							{     

			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> The  details  were not updated.. Try again</div>');
								
								 redirect('config');
							}
							
							
									}else{
									
								$this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Incorrect password... Try again or contact system admin.</div>');
								
									   redirect("config");	
								}
					   
					   	}
					   
					   
					   
					   
					   
					   
					   
					   

//
									
									}
									
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   


				
				//$dbpassword =$this->encryption->decrypt($usr_result[0]->password);
				
				
				
			
		
						   
						   
						   
						   
						   
					 
					   else
					   {
							redirect('login');
					   }
	    }
    }
	
	
	
	
	public function newupdatedate()
    {
		
			$session_data = $this->session->userdata('logged_in');
  $data['id'] = $session_data['id'];
	 $userid = $data['id'];
   
 	$data['id'] = $session_data['id'];
         $postedtime = date('Y-m-d');
		$currenttime = date('H:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
	
				$session_data = $this->session->userdata('logged_in');
		 	 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];	

 		  $tester = trim($this->input->post("tester"));		
 		  $myurl = trim($this->input->post("myurl"));		

 		  $mykey = trim($this->input->post("mykey"));		
 		  $deadline = trim($this->input->post("deadline"));		











			 		  $invoice = trim($this->input->post("invoice"));		


			 $this->form_validation->set_rules("deadline", "deadline ", "trim|required");

			  
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
     $this->load->view("template/headerpagelogin");
			$this->load->view("template/headerpagegeneral");

		
		 $this->load->view('config', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_updatedate') == "date")
					   {
	
	
	
			   if(($tester=="") || ($tester!="ROBERT")) {
					
				
				
				 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 						  <strong>Error!</strong>You do not have valid  license to use our software.Kindly purchase a license or use correct software. NOT counterfeit/Fake product. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');
						 

								
							 redirect('config');
								 return false;
				}
				
						   
	
	
	
	

						   
						   
						   
												$data=array(		
		
							
			'deadline'=>$deadline,
		

		
								);
						
								$usr_result = $this->usermodel->updatedata($data,'smsconfig','id >',0);

							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
								
								
						redirect("https://erp.robisearch.com/updatedaysextended?invoice=".$invoice);
								//invoice///
								 
						 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
								<strong>Success!</strong> You have successfully updated  the  details ..</div>');	
						 
						 redirect('config');																
							}
							else if ($usr_result ==FALSE) 
							{     

			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> The  details  were not updated.. Try again</div>');
								
								 redirect('config');
							}
								
	
	
					   }
	
	
	}
	}
	
	
	
	
	
	
	   public function updatedaysextended()
	
    {
		if (!isset($_GET['invoice'])){

    
      show_error('No identifier provided', 500);
    }
    else {

   
 	 $myurl = $_GET['myurl']; 
    
		 		 $invoice = $_GET['invoice']; 
	 		$data=array(		
		
							
			'status'=>"Closed",
		

		
								);
			
		$this->usermodel->updatedata($data,'renewals','invoice',$invoice);
			
			 $message=	 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
								<strong>Success!</strong> You have successfully updated  the  details ..</div>');	
			

					redirect($myurl);
	 
	}
	}
		
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function updateuserroles()
    {
		
			$session_data = $this->session->userdata('logged_in');
  $data['id'] = $session_data['id'];
	 $userid = $data['id'];
   
 	$data['id'] = $session_data['id'];
         $postedtime = date('Y-m-d');
		$currenttime = date('H:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
	
				$session_data = $this->session->userdata('logged_in');
		 	 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];	

 		  $tester = trim($this->input->post("tester"));		

 		  $mykey = trim($this->input->post("mykey"));		
 		  $deadline = trim($this->input->post("deadline"));		

			

			 $this->form_validation->set_rules("mykey", "mykey ", "trim|required");

			  
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      $this->load->view("template/headerpage");

		
		 $this->load->view('config', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_updatedate') == "date")
					   {
						   
						   
						   
						   			   
						   if(($tester=="") || ($tester!="OUKO")) {
					
				
				
				 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 						  <strong>Error!</strong>You do not have valid  license to use our software.Kindly purchase a license or use correct software. NOT counterfeit/Fake product. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');
						 

								
							 redirect('config');
								 return false;
				}
					$custom_key = 'KENGA';

        $encryption_config = [
            'cipher' => 'aes-256',
            'mode'   => 'cbc',
            'key'    => hash('sha256', $custom_key), 
        ];

        
        $this->encryption->initialize($encryption_config);

								 
								  	$myyear = $deadline[4].$deadline[5].$deadline[6].$deadline[7];
								  	$mymonth = $deadline[8].$deadline[9];
								  
								  	$mydate = $deadline[10].$deadline[11];
							 $finaldate=$myyear."-".$mymonth ."-".$mydate;

							echo $myfinaldate=$myyear."-".$mymonth ."-".$mydate;

		   
						   
						   
						   
						   
						     $CURRENTDATA="#@!!@#FILGONAMANDELA#@!";
								  //$mymin =date('i');
								$mymin =date('i');$myday =date('l');  $myhour =date('H');$mydate =date('d');$mymonth =date('m');$myyear =date('Y');$ourfinaldate=$myyear-$mydate;$born=2015+$mydate;





$normalday="";
$ubnormalday="";
$combineddays="";
if($myday=="Monday"){
	
$ubnormalday=2;
$normalday=1;
}else if($myday=="Tuesday"){
$ubnormalday=3;
$normalday=2;
	
}else if($myday=="Wednesday"){
	$ubnormalday=4;
$normalday=3;
}else if($myday=="Thursday"){
		$ubnormalday=5;
$normalday=4;
}else if($myday=="Friday"){
	$ubnormalday=6;
$normalday=5;
}else if($myday=="Saturday"){
	$ubnormalday=7;
$normalday=6;
}else if($myday=="Sunday"){
		$ubnormalday=1;
$normalday=7;
}else{
			$ubnormalday=11;

}
$combineddays=$ubnormalday.$normalday;


$factormin="";
$combinedminutes="";
if($mymin <=12){
	
$combinedminutes=12;
}else if($mymin <=24){
$combinedminutes=24;

	
}else if($mymin <=36){
$combinedminutes=36;
}else if($mymin <=48){
$combinedminutes=48;

}else if($mymin <=60){
$combinedminutes=60;
}else{
	$combinedminutes=1;

}

$factormin=$combinedminutes;
$differntdate=$combineddays-$mydate;
if($differntdate < 0){
	$differntdate=	$differntdate*-1;
}else{
		$differntdate=	$differntdate;

}
$CURRENTTIME=$differntdate;
								  $mainkey=$combineddays*$CURRENTTIME* $differntdate*$myhour*$factormin*$ourfinaldate;
								
								$firstTwoCharacters = $mainkey[0] . $mainkey[1];
								 
								$firstTwoCharacters = substr($mainkey, 0, 2);
								  
								  	$first2characters = $mykey[0] . $mykey[1];
								 
								$first2characters = substr($mykey, 0, 2);
								  $different=$combinedminutes-$mymin;
							  
									function removeChar($value) {
										$value2 = substr($value, 2); 
										return $value2;
									}
								
								
									$finalkey=($mainkey);
									if($mykey==$CURRENTDATA){
									
								


$decodedate = trim($this->encryption->encrypt($myfinaldate)); 

						   
						   
						   
												$data=array(		
		
							
			'deadline'=>$decodedate,
		

		
								);
						
								$usr_result = $this->usermodel->updatedata($data,'smsconfig','id >',0);

							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
								
								 
						 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
								<strong>Success!</strong> You have successfully updated  the  details ..</div>');	
						 redirect('config');																
							}
							else if ($usr_result ==FALSE) 
							{     

			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> The  details  were not updated.. Try again</div>');
								
								 redirect('config');
							}
										
										
									}else{
										
								
									
										$finalcurrentkey=($mykey);
										
										
										
									if($finalcurrentkey==$finalkey){





$decodedate = trim($this->encryption->encrypt($myfinaldate)); 

						   
						   
						   
												$data=array(		
		
							
			'deadline'=>$decodedate,
		

		
								);
						
								$usr_result = $this->usermodel->updatedata($data,'smsconfig','id >',0);

							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
								
								 
						 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
								<strong>Success!</strong> You have successfully updated  the  details ..</div>');	
						 redirect('config');																
							}
							else if ($usr_result ==FALSE) 
							{     

			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> The  details  were not updated.. Try again</div>');
								
								 redirect('config');
							}
							
							
									}else{
									
								$this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Incorrect password... Try again or contact system admin.</div>');
								
									   redirect("config");	
								}
					   
					   	}
					   
					   
					   
					   
					   
					   
					   
					   

//
									
									}
									
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   


				
				//$dbpassword =$this->encryption->decrypt($usr_result[0]->password);
				
				
				
			
		
						   
						   
						   
						   
						   
					 
					   else
					   {
							redirect('login');
					   }
	    }
    }
	
	
	
	public function Receivedata()
	
	{ 
 $postedtime = date('Y-m-d');
		$currenttime = date('H:i sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
			
									$Receivedata= $this->usermodel->populatealldb2('sms_in','used','0');

					 if(is_array($Receivedata)) {				
                
      foreach($Receivedata as $result) {
       
				   $smsid=$result->id;
						   
							$data=array(		
			'message'=>$result->sms_text,
			
				'phone'=>$result->sender_number	,
			
		  	'arrivaltime'=>$result->sent_dt,
						'transactioncode'=>$result->code,

			
			'amount'=>$result->amount,
					'firstname'=>$result->firstname,
			'lastname'=>$result->lastname,
				
			'type'=>'received',
			'status'=>$result->used,
						'createdate'=>$dateposted,

								);
								
								 
							$usr_result = $this->usermodel->add($data,'mpesa');
				if ($usr_result ==TRUE) //active user record is present
				
							{
									$updatedata=array(		
			'used'=>"1",
			
								);
					$usr_result = $this->usermodel->updatedatadb($updatedata,'sms_in','id',$smsid);


							echo "SMS is successfully received";														
							}
							else if ($usr_result ==FALSE) 
							{     

										echo "SMS was not received";															

								}
      }	
					 }else{
						 echo "There is no new SMS  received";
						 
					 }							
									

	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	 public function registerusers()
    {$createddate=date('Y-m-d');
        	 $surname = $this->input->post("surname");
		   	  $othername = $this->input->post("othername");
		  	 $email = $this->input->post("email");
         
         	 $examyear = $this->input->post("examyear");
		   $indexno = $this->input->post("indexno");
 			   $sponsor = $this->input->post("sponsor");
          //set validations
 			   		  	 $this->form_validation->set_rules("sponsor", "sponsor type", "trim|required");

							$this->form_validation->set_rules('surname', 'Surname', 'trim|required|min_length[2]|max_length[25]|xss_clean');
							$this->form_validation->set_rules('othername', 'Other name', 'trim|required|min_length[2]|max_length[35]|xss_clean');
			$this->form_validation->set_rules('email', 'Email Account', 'trim|required|valid_email|is_unique[studentlogin.email]|min_length[5]');

          	//$this->form_validation->set_rules("examyear", "Year of KCSE exam", "trim|required|min_length[4]|[25]|numeric|xss_clean");
       		$this->form_validation->set_rules("indexno", "Index Number", "trim|required|min_length[8]|max_length[13]|numeric|xss_clean");
		
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
			$this->load->view("template/headerpagelogin");
      	$this->load->view("template/headerpagegeneral");
		
		$this->load->view('applycourse',$data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					   if ($this->input->post('btn_signup') == "signup")
					   {
								
								$data=array(
								'othername'=>$othername,
								'email'=>$email,
								'surname'=>$surname,
								'examyear'=>$examyear,
								'indexno'=>$indexno,
									'sponsor'=>$sponsor,
									'createddate'=>$createddate,
								
								);
								$usr_result = $this->usermodel->signupuser($data);
							
							//check if email and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
								   $this->sendEmail($email);
								
						 $this->session->set_flashdata('signupmsg', '<div class="alert alert-success fade in">
						  <a href="#" class="close" data-dismiss="alert">&times;</a>
						 
						<strong>Success!</strong> You have successfully created account. Your login credentials has been sent  '.$email.' . Please check your email!</div>');
							
								 redirect('apply');
								
							}
							else
							{     

						 $this->session->set_flashdata('signupmsg', '<div class="alert alert-danger fade in">
						 <a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Account not created.. That index number exisist! Proceed to  login</div>');
								
								 redirect('apply');
							}
					   }
					   else
					   {
							redirect('apply');
					   }
	    }
    }
	
	
	public function addcustomers()
    {
	 		  $createddate = date('Y-m-d H:i:s');

        	 $surname = trim($this->input->post("surname"));
		   	  $othername = trim($this->input->post("othername"));
		  	 $email = trim($this->input->post("email"));
         	 $service = trim($this->input->post("service"));
			 			  $category = trim($this->input->post("category"));
			  $idno = trim($this->input->post("idno"));

			  $phone = trim($this->input->post("phone"));
         	 $business = trim($this->input->post("business"));
			          	 $website = trim($this->input->post("website"));
		 $source = trim($this->input->post("source"));

		 $description = trim($this->input->post("description"));
		 
							$this->form_validation->set_rules('phone', 'Phone Number', 'trim|required|min_length[6]|max_length[100]|xss_clean');

							//$this->form_validation->set_rules('surname', 'Surname', 'trim|required|min_length[2]|max_length[25]|xss_clean');
			$this->form_validation->set_rules('description', 'description', 'trim');
			$this->form_validation->set_rules('email', 'Email Account', 'trim|required|valid_email|min_length[5]');
						$this->form_validation->set_rules('service', 'service', 'trim');

						$this->form_validation->set_rules('category', 'category', 'trim');
						//$this->form_validation->set_rules('idno', 'idno', 'trim');
						$this->form_validation->set_rules('business', 'business', 'trim');
						//$this->form_validation->set_rules('website', 'website', 'trim');
											$this->form_validation->set_rules('source', 'source', 'trim');

			$data['errors'] = validation_errors();
			
			
			
			

				  
			
			
          if ($this->form_validation->run() == FALSE)
        {
			$this->load->view("template/headerpagelogin");
      	$this->load->view("template/headerpagegeneral");
		
		$this->load->view('agent',$data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					   if ($this->input->post('btn_addcustomeragent') == "customer")
					   {
					
								
								$data=array(
								'firstname'=>$othername,
								'email'=>trim($email),
								'surname'=>$surname,
								'business'=>$business,
							'website'=>$website,

									'createddate'=>$createddate,
								'phone'=>$phone,
								'service'=>$service,
								'category'=>$category,
								'idno'=>$idno,
								'source'=>$source,

								'description'=>$description,

								'status'=>"New",

			

								
								);
															$usr_result = $this->usermodel->add($data,'customer');

							
							if ($usr_result ==TRUE) //active user record is present
							{
								   //$this->sendEmail($email);
								
						 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
						<strong>Success!</strong> You have successfully submitted your data. Our team shall get back to you!</div>');
							
								 redirect('agent');
								
							}
							else
							{     

						 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Account not created.. Please enter all the detais then try again</div>');
								
								 redirect('agent');
							}
					   
					   }
					   else
					   {
							redirect('agent');
					   }
	    }
    }



	public function postneworder()
    {
		     		  $dateposted=date("Y-m-d H:i:s");

			$transactionid = time();
		//$createddate=date('Y-m-d');
				     		  $createddate=date("Y-m-d H:i:s");

        	 $country = trim($this->input->post("country"));
		   	  $firstname = trim($this->input->post("firstname"));
		  	 $email = trim($this->input->post("email"));
         	 $box = trim($this->input->post("box"));
			 			 			  $uniqueid = ($this->input->post("uniqueid"));

			 			  $code = ($this->input->post("code"));
						  			 			  $postcode = ($this->input->post("postcode"));
						  			 			  $salestype = ($this->input->post("salestype"));

						  			 			  $myid = ($this->input->post("myid"));

			  $idno = trim($this->input->post("idno"));

			  $phone = trim($this->input->post("phone"));
         	 $town = trim($this->input->post("town"));
			          	 $location = ($this->input->post("location"));
			          	 $quantity = ($this->input->post("quantity"));
			          	 $price = ($this->input->post("price"));
			          	 $transactioncode = ($this->input->post("transactioncode"));
						 
						 
						 
						 
						 	
						
						$customerid="";

  
								 
						   
				 
						 
						 
						 
						 
						 
						 
						 
						 
						 

							//$this->form_validation->set_rules('town', 'town', 'trim|required|min_length[2]|max_length[100]|xss_clean');
							//$this->form_validation->set_rules('location', 'location', 'trim|required|min_length[2]|max_length[100]|xss_clean');
							$this->form_validation->set_rules('phone', 'Phone Number', 'trim|required|min_length[6]|max_length[100]|xss_clean');

							$this->form_validation->set_rules('firstname', 'first name', 'trim|required|min_length[2]|max_length[50]|xss_clean');
			$this->form_validation->set_rules('email', 'Email Account', 'trim|required|valid_email|min_length[5]');
			
			$this->form_validation->set_rules('idno', 'ID Number', 'trim|required|min_length[5]');


			$data['errors'] = validation_errors();
			
			
			
			
			
          if ($this->form_validation->run() == FALSE)
        {
			$this->load->view("template/headerpagelogin");
			$this->load->view("template/headerpagegeneral");
		$this->load->view('cartcheckout',$data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					   if ($this->input->post('btn_addorder') == "ordernow")
					   {
	
			$insertdebit = array();

							
								  		$confirmdetails = $this->usermodel->Confirmdetails($idno,$phone,$email);

								  	

						  						$description=$location."  ".$box." ".$postcode."".$town;

					
						   
						  
						   if ($confirmdetails !=false)
						   
						   {
							  
								  	        $customerid=($confirmdetails[0]['id']); 

						   }else{
							
					$data=array(
								'firstname'=>$firstname,
								'email'=>trim($email),
								'country'=>$country,
								'town'=>$town,
									'createddate'=>$createddate,
								'phone'=>$phone,
								'city'=>$location,
								'category'=>"member",
								'idno'=>$idno,
								'box'=>$box,

								'code'=>$postcode,
								'transactionid'=>$uniqueid,
								'status'=>1,

							'companyid'=>1,

								
								);
						if($this->usermodel->add($data,'people')){
					$customers = $this->usermodel->populateallarray('people','transactionid',$uniqueid);
						  $customerid=($customers[0]['id']); 
							   
						   }
						   }
						   
					
			
						
										$mytotal=0;			
										 $count = count($myid);
								

   for($i=0; $i< $count; $i++) {

					 $productname = $this->usermodel->populatealldataarray('productlist','code', $code[$i],'branch', 1);

   $productid=$productname[0]['id'];  
  $buyingprice=$productname[0]['buyingprice']; 
      $newsellingprice=trim($productname[0]['sellingprice']); 
	  	        $taxtype=trim($productname[0]['taxtype']); 
	  	        $uom=trim($productname[0]['uom']); 
	  	        $vattype=trim($productname[0]['vattype']); 

		
	        $categoryid=trim($productname[0]['category']); 
$categoryid=trim($productname[0]['category']); 
			$maincategory = $this->usermodel->populateallarray('productcategory','id',$categoryid);
	        $maincategoryid=trim($maincategory[0]['maincategory']); 
					//$taxindicator=$productname[0]['taxindicator'];

	  										$mytotal=($mytotal+	($price[$i])*($quantity[$i]));	

       $insertdebit[] = array(
	   	'qty'=>$quantity[$i],
		'taxtype'=>$taxtype,
		  		   'vattype' => $vattype, 
	'uomqty'=>$quantity[$i],
		  'bprice' => $buyingprice, 
	'maincategory' => $maincategoryid, 
	 //'taxindicator' => $taxindicator, 
		'dateposted' => $dateposted, 
'companyid' => 1, 
	     'uom' => $uom, 
		'category' => $categoryid, 
			'code'=>$code[$i],
			'sprice'=>$price[$i],
			'amount'=>(($price[$i])*($quantity[$i])),
			'invoice'=>$transactionid,
             );
			 
			 
	 $productdata=array(		
						'qty'=>$mytotal,
						);

	$this->usermodel->updateproductlist($productdata,$code[$i],1); 
		 
			 
			 
			 	
   }
   
 
							$usr_result =$this->db->insert_batch('sales_order', $insertdebit); 
								
		 if($this->db->affected_rows() > 0)
	{
		
				
				
			
 $salesdata=array(	


										
			
			
				'type'=>"order",
			'customer'=>$customerid,
		  	'cash'=>$mytotal,
					  	'salestype'=>$salestype,
			   			   'cashier' =>$transactioncode,
'branch'=>1,
			'companyid'=>1,
			'dateposted'=>$createddate,
			'total' => $mytotal,		  
		    
		     'invoice' => $transactionid,  
		     'balance' => $mytotal, 
			   'due_date' => $createddate, 
					   'maindiscount' => 0,   
							'name' => "",  					   
		     'discountedtotal' => 0, 
		  'description' => $description , 

					 'mytable' => "",  
					  'maincategory' =>"",  

			  'mpesa' => 0,    
		     'cheque' => 0,  
		     'card' => 0, 
			   'voucher' => 0, 
			   'credit' => $mytotal, 
					   'points' => 0,   
					 'paymentstatus' =>"order",  

							 'ordersales' => "order", 
							
							 	
		
								);

						   
								
								
					$usr_result = $this->usermodel->add($salesdata,'sales');
		
								unset($_SESSION["shopping_cart"]);
												 
						 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
								<strong>Success!</strong> You have successfully added products   ..</div>');	
								 //redirect("viewproductlist");
								 								 redirect("printinvoice?refnumber=".$transactionid);

								 
	}else {
							   

			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Products were not added into the system.. Try again</div>');
								
								 redirect("cartcheckout");
	}
		
		
								
								
						
					   
					 
	    }  else  {
							redirect('cartcheckout');
					   }
		
    }
	
	
	}
	
	
	
	public function signupuser()
    {$createddate=date('Y-m-d');
        	 $surname = trim($this->input->post("surname"));
		   	  $othername = trim($this->input->post("othername"));
		  	 $email = trim($this->input->post("email"));
         	 $service = trim($this->input->post("service"));
			 			  $category = trim($this->input->post("category"));
			  $idno = trim($this->input->post("idno"));

			  $phone = trim($this->input->post("phone"));
         	 $password = trim($this->input->post("password"));
			          	 $cpassword = trim($this->input->post("cpassword"));

		 $companyid = trim($this->input->post("companyid"));
							$this->form_validation->set_rules('password', 'password', 'trim|required|min_length[8]|max_length[100]|xss_clean');
							$this->form_validation->set_rules('cpassword', 'Confirm password', 'trim|required|min_length[8]|max_length[100]|xss_clean');
							$this->form_validation->set_rules('phone', 'Phone Number', 'trim|required|min_length[6]|max_length[100]|xss_clean');

							$this->form_validation->set_rules('surname', 'Surname', 'trim|required|min_length[2]|max_length[25]|xss_clean');
							$this->form_validation->set_rules('othername', 'Other name', 'trim|required|min_length[2]|max_length[35]|xss_clean');
			$this->form_validation->set_rules('email', 'Email Account', 'trim|required|valid_email|min_length[5]');
			
			$this->form_validation->set_rules('idno', 'ID Number', 'trim|required|is_unique[people.idno]|min_length[5]');


			$data['errors'] = validation_errors();
			
			
			
			
											   $confirmaccount= $this->usermodel->confirmaccountcode($companyid);

				   if ($confirmaccount ==false)
						   {
							    $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!  </strong>That Entry Number  does not exist in our database. Make sure you contact us through :0790962631/0780655987 or info@robisearch.com  for full/unlimited (premium) account or enter TEST-2017002 as Entry Number for test (limited) account to signup.</div>');
								
								 //redirect("login");
								 	$this->load->view("template/headerpagelogin");
      	$this->load->view("template/headerpagegeneral");
		
		$this->load->view('signupuser',$data);
		$this->load->view("template/footerpage");
						   
						   return false;
						   }
									$mycompanyid=$confirmaccount[0]->id;
									
			
			
			
			
          if ($this->form_validation->run() == FALSE)
        {
			$this->load->view("template/headerpagelogin");
      	$this->load->view("template/headerpagegeneral");
		
		$this->load->view('signupuser',$data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					   if ($this->input->post('btn_signup') == "signup")
					   {
						   
						   $confirmemail = $this->usermodel->confirmemail($email);
						   
						  
						   if ($confirmemail ==true)
						   {
							    $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!  </strong>That email exist in our database. Just proceed to login or try again.</div>');
								
								
								 redirect("signup");
						   
						   return false;
						   }

						   if($phone!=""){
							   						   $confirmphone = $this->usermodel->confirmphone($phone);

       		   if ($confirmphone ==true)
						   {
								
							$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!  </strong>That Phone Number exist in our database. Just proceed to login or try again.</div>');
								


								redirect("signup");
						   
						   return false;
						   }
	   		 }
						   
						   
						   
						   
						   
						   
						   
						   
						   
						   
   			 if($password!=$cpassword){
       		 //return "false";


            $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!  </strong>Password dont match...Try again</div>');
            redirect('signup');
	   		 }else
	   			 {
								
								$data=array(
								'firstname'=>$othername,
								'email'=>trim($email),
								'surname'=>$surname,
								'password'=>$password,
									'createddate'=>$createddate,
								'phone'=>$phone,
								'service'=>$service,
								'category'=>$category,
								'idno'=>$idno,

								'usertype'=>$category,

								'status'=>1,

							'companyid'=>trim($mycompanyid),

								
								);
								$usr_result = $this->usermodel->signup($data);
							
							if ($usr_result ==TRUE) //active user record is present
							{
								   //$this->sendEmail($email);
								   
								   	    
					$configuration= $this->usermodel->populateallarray('smsconfig','id',1);




				$myuserid=$configuration[0]["paymenttypes"];
						$confirmusers = $this->usermodel->populatealldataarray('people', 'id',$myuserid,'id >',  0);
		  // loginall
						   $myfirstname=$confirmusers[0]['firstname'];
						   						   $contact=$confirmusers[0]['phone'];

						    $correctime=date("Y-m-d H:i:s");

		$smscode =  $userid.$this->createRandomPasswordForLogin();

	
		$myview="";
		 	$taskmessage = "Hi! You have new user (". $category .") called ". $othername .".  who signed up at  ". $correctime .". with phone number : ". $phone .". Login for more.";
		 	$usermessage = "Dear (". $othername .")! We thank you for signing up with us. Our customer care team will reach out to you soonest for help. For more, call /0790962631/0754413386/0718667391/0780655987.";


									  $this->pushroomsms($taskmessage,$contact,$myview);
												  $this->pushroomsms($usermessage,$phone,$myview);

								   
								   
								   
								   
								   
								
						 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
						<strong>Success!</strong> You have successfully created account. You can just now login!</div>');
							
								 redirect('login');
								
							}
							else
							{     

						 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Account not created.. That email  exisist! Just Proceed to  login</div>');
								
								 redirect('signup');
							}
					   }
					   }
					   else
					   {
							redirect('signup');
					   }
	    }
    }
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	function sendEmail()
	
{			$url='bulksms.robisearch.com';
		$email = $this->input->post("email");
      $surname = $this->input->post("surname");
	 $password = $this->input->post("password");
    $this->load->library('email'); // load email library
    $this->email->from('robisearch@gmail.com', 'ROBISEARCH BULK SMS');
    $this->email->to($email);
    //$this->email->cc('rmanyala@jkuat.ac.ke'); 
    $this->email->subject('Account Activation');
    $this->email->message("Hi!  ". $surname. "<br> We are glad you have  successfully created account  with Robisearch Bulk SMS platform........<br> You are encouraged to contact us through :0790962631/0780655987 to set up your unlimited account after enjoying this free/ test account.<br> You credentials for login are:  Password :". $password. " and Email: ". $email ."<br> We are greateful for choosing Robisearch Limited. Kindly click here to login and enjoy our bulk sms platform:".$url);


   // $this->email->attach('/path/to/file1.png'); // attach file
    //$this->email->attach('/path/to/file2.pdf');
    if ($this->email->send())
        echo "Mail Sent!";
    else
        echo "There is error in sending mail!";
}










	 public function getkey()
    {
          
		  
          $category = $this->input->post("category");
        
          $othermykey = trim($this->input->post("othermykey"));

          $mykey = trim($this->input->post("mykey"));

          //set validations

		  
			
          $this->form_validation->set_rules("mykey", "", "trim|required|xss_clean");
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
              	$this->load->view("template/headerpagelogin");
		      	$this->load->view("template/headerpagegeneral");

		$this->load->view('config');
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					   if ($this->input->post('btn_updaConfirm') == "Confirm")
					   {
						   	$custom_key = 'KENGA';

        $encryption_config = [
            'cipher' => 'aes-256',
            'mode'   => 'cbc',
            'key'    => hash('sha256', $custom_key), 
        ];

        
        $this->encryption->initialize($encryption_config);

						   
												$correctkey="MANDELAFILGONA#@!!@#";


							//check if email and password is correct
						
								 #@!!@#!@##@!
								  $CURRENTDATA="#@!!@#FILGONAMANDELA#@!";
								  //$mymin =date('i');
								$mymin =date('i');$myday =date('l');  $myhour =date('H');$mydate =date('d');$mymonth =date('m');$myyear =date('Y');$finaldate=$myyear+$mydate;$born=2015+$mydate;





$normalday="";
$ubnormalday="";
$combineddays="";
if($myday=="Monday"){
	
$ubnormalday=2;
$normalday=1;
}else if($myday=="Teusday"){
$ubnormalday=3;
$normalday=2;
	
}else if($myday=="Wednesday"){
	$ubnormalday=4;
$normalday=3;
}else if($myday=="Thursday"){
		$ubnormalday=5;
$normalday=4;
}else if($myday=="Friday"){
	$ubnormalday=6;
$normalday=5;
}else if($myday=="Saturday"){
	$ubnormalday=7;
$normalday=6;
}else if($myday=="Sunday"){
		$ubnormalday=1;
$normalday=7;
}else{
			$ubnormalday=11;

}
$combineddays=$ubnormalday.$normalday;


$factormin="";
$combinedminutes="";
if($mymin <=12){
	
$combinedminutes=12;
}else if($mymin <=24){
$combinedminutes=24;

	
}else if($mymin <=36){
$combinedminutes=36;
}else if($mymin <=48){
$combinedminutes=48;

}else if($mymin <=60){
$combinedminutes=60;
}else{
	$combinedminutes=1;

}

$factormin=$combinedminutes;
$differntdate=$combineddays-$mydate;
if($differntdate < 0){
	$differntdate=	$differntdate*-1;
}else{
		$differntdate=	$differntdate;

}

								  $mainkey=$combineddays*$differntdate*$myhour*$factormin*$finaldate;
								
								$firstTwoCharacters = $mainkey[0] . $mainkey[1];
								 
								$firstTwoCharacters = substr($mainkey, 0, 2);
								  
								  	$first2characters = $mykey[0] . $mykey[1];
								 
								$first2characters = substr($mykey, 0, 2);
								  $different=$combinedminutes-$mymin;
							  
									function removeChar($value) {
										$value2 = substr($value, 2); 
										return $value2;
									}

									$finalkey=removeChar($mainkey);
								
								 		
								if($mykey==$CURRENTDATA){
									
									  
					
								 if(($category=="mykey") && ($mykey !=""))  {
									    $serial =`wmic bios get serialnumber 2>&1` ;

									//$serial =  shell_exec('wmic DISKDRIVE GET SerialNumber 2>&1');
									  $myfinalserial= explode("SerialNumber",str_replace("", "", $serial));

								  $finalserial = trim($myfinalserial[1]);
								  
 $localIP = getHostByName(getHostName());
if($finalserial==""){
$finalserial=$localIP;
}	
						
 							echo $finalserialdecoded = trim($this->encryption->encrypt(($finalserial.$correctkey))); 
							

								//echo "correctkey";
				//	exit;
								 }else  if(($category=="otherkey")&& ($othermykey !=""))  {
									 

						
 								echo $myfinalserialdecoded =trim($this->encryption->encrypt(($othermykey.$correctkey)));  
								 }
								
								
								
								
								
								
								
								  
							}else if($different<=15){
									$finalcurrentkey=removeChar($mykey);
									if($finalcurrentkey==$finalkey){
										
									

								 if(($category=="mykey") && ($mykey !=""))  {
									     $serial =`wmic bios get serialnumber 2>&1` ;

									//$serial =  shell_exec('wmic DISKDRIVE GET SerialNumber 2>&1');
									  $myfinalserial= explode("SerialNumber",str_replace("", "", $serial));

								  $finalserial = trim($myfinalserial[1]);
									
									
								   $localIP = getHostByName(getHostName());
if($finalserial==""){
$finalserial=$localIP;
}	
						
 							echo $finalserialdecoded = trim($this->encryption->encrypt(($finalserial.$correctkey))); 
								 }else  if(($category=="otherkey")&& ($othermykey !=""))  {
									 

						
 								echo $myfinalserialdecoded =trim($this->encryption->encrypt(($othermykey.$correctkey)));  
								 }
								
								
								
								
								
								}else{
									
								$this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Incorrect password... Try again or contact system admin.</div>');
								
									   redirect("serial");	
								}
								
								  
							}
							else 
							{     
						
						
								
								 $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Incorrect password OR your password may have expired... Try again or contact system admin.</div>');
								
									   redirect("serial");
								
								
							}
								
								
								
								
								
								
								
								
								
								
								
								
								
						
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

	







	 public function getkey2()
    {
          
		  
          $category = $this->input->post("category");
        
          $othermykey = trim($this->input->post("othermykey"));

          $mykey = trim($this->input->post("mykey"));

          //set validations

		  
			
          $this->form_validation->set_rules("mykey", "", "trim|required|xss_clean");
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
              	$this->load->view("template/headerpagelogin");
		      	$this->load->view("template/headerpagegeneral");

		$this->load->view('config');
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					   if ($this->input->post('btn_updaConfirm') == "Confirm")
					   {
						   
						

							//check if email and password is correct
						
								 
								  $CURRENTDATA="FILGONA!@##@!";
								  $mymin =date('i');$myhour =date('H');$mydate =date('d');$mymonth =date('m');$myyear =date('Y');$finaldate=$myyear-$mydate;$born=1990-$mydate;

								  $mainkey=$mymin.$finaldate.$myhour.$mydate.$born.$mymonth;
								$firstTwoCharacters = $mainkey[0] . $mainkey[1];
								 
								$firstTwoCharacters = substr($mainkey, 0, 2);
								  
								  	$first2characters = $mykey[0] . $mykey[1];
								 
								$first2characters = substr($mykey, 0, 2);
								  $different=$mymin-$first2characters;
							  
									function removeChar($value) {
										$value2 = substr($value, 2); 
										return $value2;
									}

									$finalkey=removeChar($mainkey);
								
								 		
								if($mykey==$CURRENTDATA){
									
									  
					
								
								 if(($category=="mykey") && ($mykey !=""))  {
									    $serial =`wmic bios get serialnumber 2>&1` ;

									//$serial =  shell_exec('wmic DISKDRIVE GET SerialNumber 2>&1');
									  $myfinalserial= explode("SerialNumber",str_replace("", "", $serial));

								  $finalserial = trim($myfinalserial[1]);
								   $localIP = getHostByName(getHostName());
if($finalserial==""){
$finalserial=$localIP;
}	
								  
								  
 							 $finalserialdecoded = trim($this->encryption->encrypt($finalserial)); 
								 }else  if(($category=="otherkey")&& ($othermykey !=""))  {
									 

						
 								 $myfinalserialdecoded =trim($this->encryption->encrypt($othermykey));  
								 }
								
								
								
								
								
								
								
								  
							}else if($different<=15){
									$finalcurrentkey=removeChar($mykey);
									if($finalcurrentkey==$finalkey){
										
									

								 if(($category=="mykey") && ($mykey !=""))  {
									    $serial =`wmic bios get serialnumber 2>&1` ;

									//$serial =  shell_exec('wmic DISKDRIVE GET SerialNumber 2>&1');
									  $myfinalserial= explode("SerialNumber",str_replace("", "", $serial));

								  $finalserial = trim($myfinalserial[1]);
								   $localIP = getHostByName(getHostName());
if($finalserial==""){
$finalserial=$localIP;
}	
								  
								  
 							echo $finalserialdecoded = trim($this->encryption->encrypt($finalserial)); 
								 }else  if(($category=="otherkey")&& ($othermykey !=""))  {
									 

						
 								echo $myfinalserialdecoded =trim($this->encryption->encrypt($othermykey));  
								 }
								
								
								
								
								
								}else{
									
								$this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Incorrect password... Try again or contact system admin.</div>');
								
									   redirect("serial");	
								}
								
								  
							}
							else 
							{     
						
						
								
								 $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Incorrect password OR your password may have expired... Try again or contact system admin.</div>');
								
									   redirect("serial");
								
								
							}
								
								
								
								
								
								
								
								
								
								
								
								
								
						
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

	
 function createRandomPasswordForLogin() {
	  	$session_data = $this->session->userdata('logged_in');

			$data['id'] = $session_data['id'];
         $userid = $data['id'];
		   $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];

	$chars =  $userid.time()."003232303232023232023456789453242131231425325212312353253256325213213546121425453553245352444343422323";
					  //$chars = '2342355ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-+';

	srand((int)microtime()*100000000);
	$i = 0;
	$pass = '' ;
	while ($i <= 5) {

		$num = rand() % 33;

		$tmp = substr($chars, $num, 1);

		$pass = $pass . $tmp;

		$i++;

	}
	return $pass;
}




	public function receivesmscode()
	{ 
	
	
	
	  if (!isset($_GET['randomitemidentifier'])){

    
      show_error('No identifier provided', 500);
    }
    else {
     $invoice_number = $_GET['randomitemidentifier'];
	 
	      $randomitemidentifier = $_GET['randomitemidentifier'];
	  $contact = $_GET['contact'];
	 	  $deadline = $_GET['deadline'];
	  $currentdate = $_GET['currentdate'];
	  $branch = $_GET['branch'];

		$session_data = $this->session->userdata('logged_in');

    $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
	 
	$data['id'] = $session_data['id'];
        		          		$data['configuration'] = $this->usermodel->populateallarray('smsconfig','id',$companyid);

		 $userid = $data['id'];
				$this->load->view("template/headerpagelogin");
		      	$this->load->view("template/headerpagegeneral");
		
$data['randomitemidentifier'] = $randomitemidentifier;
$data['contact'] = $contact;
$data['currentdate'] = $currentdate;
$data['deadline'] = $deadline;
$data['days'] = $days;
$data['branch'] = $branch;

	
	
				$this->load->view('loginpage',$data);
		$this->load->view("template/footerpage");
	}
	}






	 public function loginall()
    {
          
		  
           $myuserid = $this->input->post("myuserid");
           $branch = $this->input->post("branch");
           $smscode = $this->input->post("smscode");
           $contact = $this->input->post("contact");


          //set validations

         $this->form_validation->set_rules("myuserid", "SMS Code", "trim|required|xss_clean");
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
              	$this->load->view("template/headerpagelogin");
		      	$this->load->view("template/headerpagegeneral");

		$this->load->view('loginpage',$data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					   if ($this->input->post('btn_login') == "loginall")
					   {
						   
						   
						   	   if($smscode ==""){
							   
							    $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Your have not entered any verification code sent to your sms. Please enter the code then try again. .</div>');

							     redirect("user/receivesmscode?randomitemidentifier=".$myuserid."&contact=".$contact."&branch=".$branch);

							   return false;
							   
							   
							   
						   }
						   
						   
						   
						   
						   
						   
						   
						   	$custom_key = 'KENGA';

        $encryption_config = [
            'cipher' => 'aes-256',
            'mode'   => 'cbc',
            'key'    => hash('sha256', $custom_key), 
        ];

        
        $this->encryption->initialize($encryption_config);

						   
						   
						$confirmusers = $this->usermodel->populatealldataarray('people', 'id',$myuserid,'smscode',  $smscode);
		  // loginall
		  
		
						   if($confirmusers !=true){
							   
							    $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Your have entered wrong verification code.. Kindy enter the code sent to your phone and try again. .</div>');

							     redirect("user/receivesmscode?randomitemidentifier=".$myuserid."&contact=".$contact."&branch=".$branch);

							   return false;
							   
							   
							   
						   }
						   
	$correctime=date("Y-m-d H:i:s");					   
$to_time = strtotime($correctime);
   $fromdatetime=$confirmusers[0]['timesent'];
$from_time = strtotime($fromdatetime);
 $timedifference= round(abs($to_time - $from_time) / 60,2);
						   
						   

						   
	   if($timedifference > 4){
							   
							    $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> The verification code has expired. Try resend the code  using the orenge button and use the new code  within 3 minutes. try again. .</div>');

							     redirect("user/receivesmscode?randomitemidentifier=".$myuserid."&contact=".$contact."&branch=".$branch);

							   return false;
							   
							   
							   
						   }					   
						   
						   
						   
						$currentdate=date('Y-m-d');
						   
						$usr_result = $this->usermodel->loginallusers($myuserid);
				
							//check if email and password is correct
							if ($usr_result > 0) //active user record is present
							{
								 //set the session variables
								  $companyid=$usr_result[0]->companyid;
								    	$contact=$usr_result[0]->phone;
								$employeeno=$usr_result[0]->id;

								  $confirmuser = $this->usermodel->populatealldataarrayboolean('modules', 'id','displaycounter','status',1);

						if($confirmuser==true){
							
													   
	$productname  = $this->usermodel->populatealldatanoarray('assignbranches','branchid', $branch,'employeeno', $employeeno);
 
					
					  if ($productname ==false)
						   {
							   
							   
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> You do not have right to access that branch. Try another one .</div>');

						  
								 redirect('login');
	   return false;
						   }
							
						}
								  
							
								  
								  		$MAINbusinesskey = $this->usermodel->populateallarray('smsconfig','id',$companyid);

								  		//$businesskey = $this->usermodel->populateall('smsconfig', 'id',$companyid);

								    //$deadline=$businesskey[0]->deadline;
									
						$deadline =trim($this->encryption->decrypt($MAINbusinesskey[0]["deadline"]));
		
									 $confirmsmslogin=$MAINbusinesskey[0]["smslogin"];
									
									 $deadlinedetails=$MAINbusinesskey[0]["deadlinedetails"];
									   $businesskey=trim($MAINbusinesskey[0]["businesskey"]);
				
								  $finaldate = strtotime(date($deadline));
									$mycurrentdate = strtotime(date($currentdate));

									$secs = $finaldate - $mycurrentdate;// == <seconds between the two times>
									$days = $secs / 86400;
								
		   $serial =`wmic bios get serialnumber 2>&1` ;

									//$serial =  shell_exec('wmic DISKDRIVE GET SerialNumber 2>&1');
									  $myfinalserial= explode("SerialNumber",str_replace("", "", $serial));

								  $finalserial = trim($myfinalserial[1]);
								  
$localIP = getHostByName(getHostName());
if($finalserial==""){
$finalserial=$localIP;
}	
								   
							 
							 
								$confirmkey="#@!!@#FILGONA#@!";
 								 $MYBUSINESSKEY =trim($this->encryption->decrypt($businesskey));
								  $CORRECTDATA= explode("OUKOMANDELA",$MYBUSINESSKEY);
								  $finalserialdecoded = ($CORRECTDATA[0]);
								   $correctdbkey = trim($CORRECTDATA[1]);
								   
								     /// $CORRECTDATA=  explode(',', $MYBUSINESSKEY);
									  
								if($businesskey==""){
									$this->session->set_userdata('logged_in', $sessiondata);

									$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>You do not have valid  license to use our software.Kindly purchase a license first to be able to use our software. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

									   
								 redirect('login');
									  return  false;
								  }
										
	
 
							if($confirmkey != $correctdbkey){
									$this->session->set_userdata('logged_in', $sessiondata);

									$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>You do not have valid  license to use our software.Kindly purchase a license first to be able to use our software. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

									   
								 redirect('login');
									  return  false;
								  }




			  							
				if($finalserialdecoded == $finalserial){
					
					
								
								  
								 $sessiondata = array(
										  'branchid' => $branch,

									  'id' => $usr_result[0]->id,
									 'firstname' =>  $usr_result[0]->firstname,
									  'email' => $usr_result[0]->email, 
									  'surname' => $usr_result[0]->surname, 
									  'companyid' => $usr_result[0]->companyid, 
										'usertype' => $usr_result[0]->usertype, 
																				'category' => $usr_result[0]->category, 

									  										'original' => "usercontroller", 
																			'days' => $days, 


								 );
								  $mydata = array(
									
									  'userid' => $usr_result[0]->id,
									    'companyid' => $usr_result[0]->companyid,
									  		'ip' => $this->input->ip_address(),		
									
									  'type' =>$usr_result[0]->usertype, 
									
									  'timein' =>  Date('Y-m-d H:i:s') ,

								 );
								
								 		

								  if($deadline==$currentdate){
									$this->session->set_userdata('logged_in', $sessiondata);
										$usr_result = $this->usermodel->add($mydata,'loggs');


									$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>Your license will expire today and you will not be able to acces your details though your data is safely stored.This is because of:'.$deadlinedetails.'.. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

									   redirect("user/verifysetails");
								  }else   if($deadline<$currentdate){
									  
									$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>Your license  has expired and   you can not be able to acces your details though your data is safely stored.This is because of:'.$deadlinedetails.'.. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');
								
								 redirect('login/login');
								   return  false;
								
									  
								  }else{
									  if($days<=7){
											
										$this->session->set_userdata('logged_in', $sessiondata);
										$usr_result = $this->usermodel->add($mydata,'loggs');

												

									   		  if($days<1){
												  	 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Your  have '.$days.' days remaining to renew or comply with your agreement and ROBISEARCH LTD. Your license will expire on '.$deadline.' thereafter  you will not be able to acces your details though your data is safely stored.This is because of:'.$deadlinedetails.'.. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

								 redirect('login/login');
									   
											      }else{
													  
													  	 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Your  have '.$days.' days remaining to renew or comply with your agreement and ROBISEARCH LTD. Your license will expire on '.$deadline.' thereafter  you will not be able to acces your details though your data is safely stored.This is because of:'.$deadlinedetails.'.. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

									   redirect("user/verifysetails");
													  
												  }
												  
									   
									   
									  return  false;	
										}else{
											  $this->session->set_userdata('logged_in', $sessiondata);
										$usr_result = $this->usermodel->add($mydata,'loggs');

								 
								 redirect("user/verifysetails");
										}
									 
									  
									  
								  }
								  
								  	}else{
					 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 <strong>Error!</strong> You dont have valid License Key to use ROBISEARCH SYSTEM. Contact ROBISEARCH LTD. 0790962631/0718667391/0716413386/0780655987 to get the License Key</div>');
								
									   
								redirect('login');
								}
								  
								  
								  
							}
							else 
							{     
						
						
								
								 $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Incorrect password... Try again or contact system admin.</div>');
								
								 redirect('login/login');
								
								
							}
								
								
								
								
								
								
								
								
								
								
								
								
								
						
					   
						   	    }else if ($this->input->post('btn_login') == "resendcode")
					   {
						   
						    
						$confirmusers = $this->usermodel->populatealldataarray('people', 'id',$myuserid,'id >',  0);
		  // loginall
						   $firstname=$confirmusers[0]['firstname'];
						    $correctime=date("Y-m-d H:i:s");

		$smscode =  $userid.$this->createRandomPasswordForLogin();

	
		$myview="";
		 	$taskmessage = "Dear ". $firstname ."! Your one time login code is: .". $smscode ." at  ". $correctime .". Use it within 3 minutes.";


//$myview="user/receivesmscode?randomitemidentifier=".$myuserid."&contact=".$contact."&branch=".$branch;
									  $this->pushroomsms($taskmessage,$contact,$myview);
									$updatesmsdata=array(		
		
							'smscode'=>$smscode,
							'timesent'=>$correctime,

							);
						
	
							   	$this->usermodel->updatedata($updatesmsdata,'people','id',$myuserid);  
									  
									  
									  
				 redirect("user/receivesmscode?randomitemidentifier=".$myuserid."&contact=".$contact."&branch=".$branch);
   
						   
						   
					   }else
					   {
							redirect('login');
					   }
	    }
    }


	 public function logincashier()
    {
          
		  
          $password = $this->input->post("password");
          $branch = $this->input->post("branch");


          //set validations

		  
			
          $this->form_validation->set_rules("password", "Password", "trim|required|xss_clean");
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
              	$this->load->view("template/headerpagelogin");
		      	$this->load->view("template/headerpagegeneral");

		$this->load->view('index',$data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					   if ($this->input->post('btn_login') == "cashier")
					   {
						   
						$currentdate=date('Y-m-d');
						   
						$usr_result = $this->usermodel->getcashiers($password);
				
							//check if email and password is correct
							if ($usr_result > 0) //active user record is present
							{
								 //set the session variables
								  $companyid=$usr_result[0]->companyid;
								    	$contact=$usr_result[0]->phone;
								$employeeno=$usr_result[0]->id;

								  $confirmuser = $this->usermodel->populatealldataarrayboolean('modules', 'id','displaycounter','status',1);

						if($confirmuser==true){
							
													   
	$productname  = $this->usermodel->populatealldatanoarray('assignbranches','branchid', $branch,'employeeno', $employeeno);
 
					
					  if ($productname ==false)
						   {
							   
							   
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> You do not have right to access that branch. Try another one .</div>');

						  
								 redirect('login');
	   return false;
						   }
							
						}
															  
		

      // $encrypted = $this->encryption->encrypt($data);
     // $decrypted = $this->encryption->decrypt($encrypted);
  
			  		$MAINbusinesskey = $this->usermodel->populateallarray('smsconfig','id',$companyid);

								  		//$businesskey = $this->usermodel->populateall('smsconfig', 'id',$companyid);

					

						$deadline =trim($this->encryption->decrypt($MAINbusinesskey[0]["deadline"]));
		
									 $confirmsmslogin=$MAINbusinesskey[0]["smslogin"];
									
									 $deadlinedetails=$MAINbusinesskey[0]["deadlinedetails"];
									   $businesskey=trim($MAINbusinesskey[0]["businesskey"]);
				
								  $finaldate = strtotime(date($deadline));
									$mycurrentdate = strtotime(date($currentdate));

									$secs = $finaldate - $mycurrentdate;// == <seconds between the two times>
									$days = $secs / 86400;
								
		   $serial =`wmic bios get serialnumber 2>&1` ;

									//$serial =  shell_exec('wmic DISKDRIVE GET SerialNumber 2>&1');
									  $myfinalserial= explode("SerialNumber",str_replace("", "", $serial));

								  $finalserial = trim($myfinalserial[1]);
								   $localIP = getHostByName(getHostName());
if($finalserial==""){
$finalserial=$localIP;
}	
								  
								  
							 
							 //
								$confirmkey="#@!!@#FILGONA#@!";
 								 $MYBUSINESSKEY =trim($this->encryption->decrypt($businesskey));
								  $CORRECTDATA= explode("OUKOMANDELA",$MYBUSINESSKEY);
								  $finalserialdecoded = ($CORRECTDATA[0]);
								   $correctdbkey = trim($CORRECTDATA[1]);
								   
								     /// $CORRECTDATA=  explode(',', $MYBUSINESSKEY);
									  
								if($businesskey==""){
									$this->session->set_userdata('logged_in', $sessiondata);

									$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>You do not have valid  license to use our software.Kindly purchase a license first to be able to use our software. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

									   
								 redirect('login');
									  return  false;
								  }
										
	
 
							if($confirmkey != $correctdbkey){
									$this->session->set_userdata('logged_in', $sessiondata);

									$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>You do not have valid  license to use our software.Kindly purchase a license first to be able to use our software. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

									   
								 redirect('login');
									  return  false;
								  }



if($confirmsmslogin=="yes"){
	     		  $correctime=date("Y-m-d H:i:s");

		$smscode =  $userid.$this->createRandomPasswordForLogin();

	
		$myview="";
		 	$taskmessage = "Dear ". $usr_result[0]->firstname ."! Your one time login code is: .". $smscode ." at  ". $correctime .". Use it within 3 minutes.";


//$myview="user/receivesmscode?randomitemidentifier=".$employeeno."&contact=".$contact."&branch=".$branch;
									  $this->pushroomsms($taskmessage,$contact,$myview);
									//

			$updatesmsdata=array(		
		
							'smscode'=>$smscode,
							'timesent'=>$correctime,

							);
						
	
							   	$this->usermodel->updatedata($updatesmsdata,'people','id',$employeeno);
								     redirect("user/receivesmscode?randomitemidentifier=".$employeeno."&contact=".$contact."&branch=".$branch);

	
return false;	
}


			  							
				if($finalserialdecoded == $finalserial){
					
					
								
								  
								 $sessiondata = array(
										  'branchid' => $branch,

									  'id' => $usr_result[0]->id,
									 'firstname' =>  $usr_result[0]->firstname,
									  'email' => $usr_result[0]->email, 
									  'surname' => $usr_result[0]->surname, 
									  'companyid' => $usr_result[0]->companyid, 
										'usertype' => $usr_result[0]->usertype, 
																				'category' => $usr_result[0]->category, 

									  										'original' => "usercontroller", 
																			'days' => $days, 


								 );
								  $mydata = array(
									
									  'userid' => $usr_result[0]->id,
									    'companyid' => $usr_result[0]->companyid,
									  		'ip' => $this->input->ip_address(),		
									
									  'type' =>$usr_result[0]->usertype, 
									
									  'timein' =>  Date('Y-m-d H:i:s') ,

								 );
								
								 		

								  if($deadline==$currentdate){
									$this->session->set_userdata('logged_in', $sessiondata);
										$usr_result = $this->usermodel->add($mydata,'loggs');


									$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>Your license will expire today and you will not be able to acces your details though your data is safely stored.This is because of:'.$deadlinedetails.'.. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

									   redirect("user/verifysetails");
								  }else   if($deadline<$currentdate){
									  
									$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>Your license  has expired and   you can not be able to acces your details though your data is safely stored.This is because of:'.$deadlinedetails.'.. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');
								
								 redirect('login/login');
								   return  false;
								
									  
								  }else{
									  if($days<=7){
											
										$this->session->set_userdata('logged_in', $sessiondata);
										$usr_result = $this->usermodel->add($mydata,'loggs');

												

									   		  if($days<1){
												  	 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Your  have '.$days.' days remaining to renew or comply with your agreement and ROBISEARCH LTD. Your license will expire on '.$deadline.' thereafter  you will not be able to acces your details though your data is safely stored.This is because of:'.$deadlinedetails.'.. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

								 redirect('login/login');
									   
											      }else{
													  
													  	 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Your  have '.$days.' days remaining to renew or comply with your agreement and ROBISEARCH LTD. Your license will expire on '.$deadline.' thereafter  you will not be able to acces your details though your data is safely stored.This is because of:'.$deadlinedetails.'.. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

									   redirect("user/verifysetails");
													  
												  }
												  
									   
									   
									  return  false;	
										}else{
											  $this->session->set_userdata('logged_in', $sessiondata);
										$usr_result = $this->usermodel->add($mydata,'loggs');

								 
								 redirect("user/verifysetails");
										}
									 
									  
									  
								  }
								  
								  	}else{
					 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 <strong>Error!</strong> You dont have valid License Key to use ROBISEARCH SYSTEM. Contact ROBISEARCH LTD. /0790962631/0718667391/0716413386/0780655987 to get the License Key</div>');
								
									   
								redirect('login');
								}
								  
								  
								  
							}
							else 
							{     
						
						
								
								 $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Incorrect password... Try again or contact system admin.</div>');
								
								 redirect('login/login');
								
								
							}
								
								
								
								
								
								
								
								
								
								
								
								
								
						
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

	












	function pushroomsms($mainmessage,$maincontact,$myview)
	{
 
		
			//SS$session_data = $this->session->userdata('logged_in');

   
 	//$data['id'] = $session_data['id'];
         $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
		 //$userid = $data['id'];
		 	// $data['companyid'] = $session_data['companyid'];
	 $companyid = 1;
		 		
		 		// $contact = trim($this->input->post("contact"));
				
				
				
				
				
					$configuration= $this->usermodel->populateallarray('smsconfig','id',$companyid);




				$userid=$configuration[0]["paymenttypes"];



	
				
					$sigature=$configuration[0]["sigature"];

	if($sigature!=""){
		
		$mainmessage=$mainmessage. " ".$sigature;
	}else{
				$mainmessage=$mainmessage;
	}
				
			
				
				
				
				
				
				
				
				
				
				
				
								$contact = htmlspecialchars(trim($maincontact));

		   	  $mymessage = trim($mainmessage);
			
				
				
				
				
				
			
			// htmlspecialchars($_POST['firstname'])
			 $message = htmlspecialchars($mymessage);
			 
			 
			
			 
			
			 
			 
						   
				
					 
			
				// $xml = "<smslist><sms><user>robiseach</user><password>r12345</password><message>Hi robert Manyala</message><mobiles>25418667391</mobiles><senderid>INFOTEXT</senderid><cdmasenderid>00201009546244</cdmasenderid><group>-1</group><clientsmsid>0</clientsmsid><accountusagetypeid>1</accountusagetypeid></sms></smslist>";

			
			$myArray = explode(',', $contact);
foreach($myArray as $allcontacts){
			    $confirmaccount_result = $this->usermodel->confirmaccount($userid);
$totalsms=$confirmaccount_result[0]['totalsms'];
$apiid=$confirmaccount_result[0]['companyid'];
//$stop=$confirmaccount_result[0]['stop'];

						   
						   $countmessage =strlen($message);
					 $COST="";
				 if($countmessage<=144){
				
					$COST=1;
				 }else if($countmessage<=304){
					 
					$COST=2;
				 }else if($countmessage<=464){
					$COST=3;
					
				 }
				 else if($countmessage<=624){
					$COST=4;
				
				 }
				 else if($countmessage<=784){
					 $COST=5;
					
				 }
												if($confirmaccount_result[0]['totalsms']< $COST){
			
			
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Your account has insufficient balance . Please recharge and try again</div>');
								
								 //redirect($myview);
		}else{
			
			 $confirmsmsaccount_result = $this->usermodel->confirmasmsccount($apiid);
$username=$confirmsmsaccount_result[0]['username'];
$from=$confirmsmsaccount_result[0]['from'];
$password=$confirmsmsaccount_result[0]['password'];
		  
		
   // echo $my_Array.'<br>';  

												$data=array(		
			'userid'=>$userid,
			
				'contact'=>$allcontacts,
			
		  	'message'=>$message,
			
			'companyid'=>$companyid,
			'postedtime'=>$dateposted,
				
			
								);
									
		
			
			
			
			$finalURL = "https://sms.bulksmschapchap.com/api/services/sendsms/?apikey=" . urlencode($password) . "&partnerID=" . urlencode($username) . "&message=" . urlencode($message) . "&shortcode=".urlencode($from)."&mobile=$allcontacts";

			//$finalURL = "https://sms.bulksmschapchap.com/api/services/sendsms/?apikey=" . urlencode($password) . "&partnerID=" . urlencode($username) . "&message=" . urlencode($message) . "&shortcode=$from&mobile=$allcontacts";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $finalURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
$finalcode="";

			    if ($output != null) {
        $responseData = json_decode($output, TRUE);


	
	 if(isset($responseData["responses"][0]["response-description"])){
	$finalcode=$responseData["responses"][0]["response-description"];

	} 
	if(isset($responseData["response-description"])){
		
		$finalcode=$responseData["response-description"];
		
	}
 

				if($finalcode=="Success"){
	$usr_result = $this->usermodel->add($data,'sms');
				
					 $countmessage =strlen($message);
				 if($countmessage<=144){
					$finaltotalsms=$totalsms-1;
				 }else if($countmessage<=304){
					 
					$finaltotalsms=$totalsms-2;
				 }else if($countmessage<=464){
					 $finaltotalsms=$totalsms-3;
					
				 }
				 else if($countmessage<=624){
					 $finaltotalsms=$totalsms-4;
				
				 }
				 else if($countmessage<=784){
					 $finaltotalsms=$totalsms-5;
					
				 }

				$usr_result2 = $this->usermodel->updateusersms($userid,$finaltotalsms);
			}
				
						
			} else {

				$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error occurred during Sending Message!</strong> Please check on your internet connection or balance.Try again </div>');
								// redirect($myview);
				}
				
			
}
}
			
				if($finalcode=="Success"){	
			
				
				$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Verification sms   is sent successfully to your phone.</div>');
					
			
								// redirect($myview);
			}else{
				
				
				$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error occurred during Sending Message!</strong> '.$finalcode .' .SMS  not sent to your phone. <a href=' .base_url(). 'user/viewsms> clicke here to go back  </a> </div>');
												//	  <strong>Error occurred during Sending Message!</strong> '.$finalcode .' .SMS  not Sent to  '.$allcontacts .' <a href=' .base_url(). 'user/viewsms> clicke here to go back  </a> </div>');


							//redirect($myview);

			}
			
			
			


						   
						   
						   
						   
						   
			
							
							//check if username and password is correct
			
					  
	    
    }
  
  





	function pushroomsmsNull($mainmessage,$maincontact,$myview)
	{
 
		
			//SS$session_data = $this->session->userdata('logged_in');

   
 	//$data['id'] = $session_data['id'];
         $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
		 //$userid = $data['id'];
		 	// $data['companyid'] = $session_data['companyid'];
	 $companyid = 1;
		 		
		 		// $contact = trim($this->input->post("contact"));
				
				
				
				
				
					$configuration= $this->usermodel->populateallarray('smsconfig','id',$companyid);




				$userid=$configuration[0]["paymenttypes"];



	
				
					$sigature=$configuration[0]["sigature"];

	if($sigature!=""){
		
		$mainmessage=$mainmessage. " ".$sigature;
	}else{
				$mainmessage=$mainmessage;
	}
				
			
				
				
				
				
				
				
				
				
				
				
				
								$contact = htmlspecialchars(trim($maincontact));

		   	  $mymessage = trim($mainmessage);
			
				
				
				
				
				
			
			// htmlspecialchars($_POST['firstname'])
			 $message = htmlspecialchars($mymessage);
			 
			 
			
			 
			
			 
			 
						   
				
					 
			
				// $xml = "<smslist><sms><user>robiseach</user><password>r12345</password><message>Hi robert Manyala</message><mobiles>25418667391</mobiles><senderid>INFOTEXT</senderid><cdmasenderid>00201009546244</cdmasenderid><group>-1</group><clientsmsid>0</clientsmsid><accountusagetypeid>1</accountusagetypeid></sms></smslist>";

			
			$myArray = explode(',', $contact);
foreach($myArray as $allcontacts){
			    $confirmaccount_result = $this->usermodel->confirmaccount($userid);
$totalsms=$confirmaccount_result[0]['totalsms'];
$apiid=$confirmaccount_result[0]['companyid'];
//$stop=$confirmaccount_result[0]['stop'];

						   
						   $countmessage =strlen($message);
					 $COST="";
				 if($countmessage<=144){
				
					$COST=1;
				 }else if($countmessage<=304){
					 
					$COST=2;
				 }else if($countmessage<=464){
					$COST=3;
					
				 }
				 else if($countmessage<=624){
					$COST=4;
				
				 }
				 else if($countmessage<=784){
					 $COST=5;
					
				 }
												if($confirmaccount_result[0]['totalsms']< $COST){
			
			
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Your account has insufficient balance . Please recharge and try again</div>');
								
								 //redirect($myview);
		}else{
			
			 $confirmsmsaccount_result = $this->usermodel->confirmasmsccount($apiid);
$username=$confirmsmsaccount_result[0]['username'];
$from=$confirmsmsaccount_result[0]['from'];
$password=$confirmsmsaccount_result[0]['password'];
		  
		
   // echo $my_Array.'<br>';  

												$data=array(		
			'userid'=>$userid,
			
				'contact'=>$allcontacts,
			
		  	'message'=>$message,
			
			'companyid'=>$companyid,
			'postedtime'=>$dateposted,
				
			
								);
									
		
			
			
			
			$finalURL = "https://sms.bulksmschapchap.com/api/services/sendsms/?apikey=" . urlencode($password) . "&partnerID=" . urlencode($username) . "&message=" . urlencode($message) . "&shortcode=".urlencode($from)."&mobile=$allcontacts";

			//$finalURL = "https://sms.bulksmschapchap.com/api/services/sendsms/?apikey=" . urlencode($password) . "&partnerID=" . urlencode($username) . "&message=" . urlencode($message) . "&shortcode=$from&mobile=$allcontacts";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $finalURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
$finalcode="";

			    if ($output != null) {
        $responseData = json_decode($output, TRUE);


	
	 if(isset($responseData["responses"][0]["response-description"])){
	$finalcode=$responseData["responses"][0]["response-description"];

	} 
	if(isset($responseData["response-description"])){
		
		$finalcode=$responseData["response-description"];
		
	}
 

				if($finalcode=="Success"){
	$usr_result = $this->usermodel->add($data,'sms');
				
					 $countmessage =strlen($message);
				 if($countmessage<=144){
					$finaltotalsms=$totalsms-1;
				 }else if($countmessage<=304){
					 
					$finaltotalsms=$totalsms-2;
				 }else if($countmessage<=464){
					 $finaltotalsms=$totalsms-3;
					
				 }
				 else if($countmessage<=624){
					 $finaltotalsms=$totalsms-4;
				
				 }
				 else if($countmessage<=784){
					 $finaltotalsms=$totalsms-5;
					
				 }

				$usr_result2 = $this->usermodel->updateusersms($userid,$finaltotalsms);
			}
				
						
			} else {

				
				}
				
			
}
}
			
				if($finalcode=="Success"){	
			
				
					
			
								// redirect($myview);
			}else{
				
				
				

							//redirect($myview);

			}
			
			
			


						   
						   
						   
						   
						   
			
							
							//check if username and password is correct
			
					  
	    
    }
  
  








	 public function loginusers()
    {
      //  
		//get the posted values
          $email = $this->input->post("email");
          $password = $this->input->post("password");
          $branch = $this->input->post("branch");
						$currentdate=date('Y-m-d');

          //set validations
		  	$this->form_validation->set_rules("email", "email", "trim|required|max_length[50]|xss_clean");
			
			
          $this->form_validation->set_rules("password", "Password", "trim|required|xss_clean");
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
              	$this->load->view("template/headerpagelogin");
		      	$this->load->view("template/headerpagegeneral");

		$this->load->view('index',$data);
		$this->load->view("template/footerpage");
		}
		 else
		{
			
			
			
			

					   //validation succeeds
					   if ($this->input->post('btn_login') == "login")
					   {
						   
							 $smsconfig = $this->usermodel->populateallarray('smsconfig','id',1);
		 	  $view=$smsconfig[0]['view'];	



						   
						   
								$usr_result = $this->usermodel->getusers($email, $password);
							
							//check if email and password is correct
							if ($usr_result > 0) //active user record is present
							{
								 //set the session variables
								  //set the session variables
								  $companyid=$usr_result[0]->companyid;
								  $category=$usr_result[0]->category;
								    	$contact=$usr_result[0]->phone;

								  
								$employeeno=$usr_result[0]->id;

								  $confirmuser = $this->usermodel->populatealldataarrayboolean('modules', 'id','displaycounter','status',1);

						if($confirmuser==true){
							
													   
	$productname  = $this->usermodel->populatealldatanoarray('assignbranches','branchid', $branch,'employeeno', $employeeno);
 
					
					  if ($productname ==false)
						   {
							   
							   
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> You do not have right to access that branch. Try another one .</div>');

						  
								 redirect('login');
	   return false;
						   }
							
						}
								  
							$custom_key = 'KENGA';

        $encryption_config = [
            'cipher' => 'aes-256',
            'mode'   => 'cbc',
            'key'    => hash('sha256', $custom_key), 
        ];

        
        $this->encryption->initialize($encryption_config);
		  
								  
								  
								  
								  
								  
								  
								  
								  
								  	$MAINbusinesskey = $this->usermodel->populateallarray('smsconfig','id',$companyid);

								  		//$businesskey = $this->usermodel->populateall('smsconfig', 'id',$companyid);

								    //$deadline=$businesskey[0]->deadline;
									
						$deadline =trim($this->encryption->decrypt($MAINbusinesskey[0]["deadline"]));
											 $confirmsmslogin=$MAINbusinesskey[0]["smslogin"];

									
									
									 $deadlinedetails=$MAINbusinesskey[0]["deadlinedetails"];
									  $businesskey=trim($MAINbusinesskey[0]["businesskey"]);
								  
								  
								  
						
								  $finaldate = strtotime(date($deadline));
									$mycurrentdate = strtotime(date($currentdate));

									$secs = $finaldate - $mycurrentdate;// == <seconds between the two times>
									$days = $secs / 86400;
								
									   $serial =`wmic bios get serialnumber 2>&1` ;

									//$serial =  shell_exec('wmic DISKDRIVE GET SerialNumber 2>&1');
									  $myfinalserial= explode("SerialNumber",str_replace("", "", $serial));

								  $finalserial = trim($myfinalserial[1]);
								  
								  $localIP = getHostByName(getHostName());
if($finalserial==""){
$finalserial=$localIP;
}	


								  




								$confirmkey="#@!!@#FILGONA#@!";
 								 $MYBUSINESSKEY =trim($this->encryption->decrypt($businesskey));
								  $CORRECTDATA= explode("OUKOMANDELA",$MYBUSINESSKEY);
								  $finalserialdecoded = ($CORRECTDATA[0]);
								   $correctdbkey = trim($CORRECTDATA[1]);
								   
								     /// $CORRECTDATA=  explode(',', $MYBUSINESSKEY);
									  
								if($businesskey==""){
									$this->session->set_userdata('logged_in', $sessiondata);

									$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>You do not have valid  license to use our software.Kindly purchase a license first to be able to use our software. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

									   
								 redirect('login');
									  return  false;
								  }
										
	
 
							if($confirmkey != $correctdbkey){
									$this->session->set_userdata('logged_in', $sessiondata);

									$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>You do not have valid  license to use our software.Kindly purchase a license first to be able to use our software. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

									   
								 redirect('login');
									  return  false;
								  }

	
							



if($confirmsmslogin=="yes"){
	     		  $correctime=date("Y-m-d H:i:s");

		$smscode =  $userid.$this->createRandomPasswordForLogin();

	
		$myview="";
		 	$taskmessage = "Dear ". $usr_result[0]->firstname ."! Your one time login code is: .". $smscode ." at  ". $correctime .". Use it within 3 minutes.";


//$myview="user/receivesmscode?randomitemidentifier=".$employeeno."&contact=".$contact."&branch=".$branch;
									  $this->pushroomsms($taskmessage,$contact,$myview);
									

			$updatesmsdata=array(		
		
							'smscode'=>$smscode,
							'timesent'=>$correctime,

							);
						
	
							   	$this->usermodel->updatedata($updatesmsdata,'people','id',$employeeno);
								     redirect("user/receivesmscode?randomitemidentifier=".$employeeno."&contact=".$contact."&branch=".$branch);

	
return false;	
}






			  							
				if($finalserialdecoded == $finalserial){
					
			
				
			  $mydata = array(
									
									  'userid' => $usr_result[0]->id,
									  		'ip' => $this->input->ip_address(),		
										    'companyid' => $usr_result[0]->companyid,
									  'type' =>$usr_result[0]->usertype, 
									
									  'timein' =>  Date('Y-m-d H:i:s') ,

								 );
				
			
								  
								  
								 $sessiondata = array(
										  'branchid' => $branch,

									  'id' => $usr_result[0]->id,
									 'firstname' =>  $usr_result[0]->firstname,
									  'email' => $usr_result[0]->email, 
									  'surname' => $usr_result[0]->surname, 
									  'companyid' => $usr_result[0]->companyid, 
										'usertype' => $usr_result[0]->usertype, 
										'category' => $usr_result[0]->category,
																			'days' => $days, 
										'original' => "usercontroller", 

									  

								 );
								 
								 		if($days<=7){
											
										$this->session->set_userdata('logged_in', $sessiondata);
																				$usr_result = $this->usermodel->add($mydata,'loggs');


									   		  if($days<1){
												  	 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Your  have '.$days.' days remaining to renew or comply with your agreement and ROBISEARCH LTD. Your license will expire on '.$deadline.' thereafter  you will not be able to acces your details though your data is safely stored.This is because of:'.$deadlinedetails.'.. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

								 redirect('login');
									   
											      }else{
													  
													  	 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Your  have '.$days.' days remaining to renew or comply with your agreement and ROBISEARCH LTD. Your license will expire on '.$deadline.' thereafter  you will not be able to acces your details though your data is safely stored.This is because of:'.$deadlinedetails.'.. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

									   
									   if($category=="user"){
										   									   redirect("user/verifysetails");

									   }else{
										   									   redirect("user/updatedata");

										   
									   }
									   
									   
									   
													  
												  }
									   
									   
									   
									  return  false;	
										}
								 
								 
								 
								 
								 
								 
							

								  if($deadline==$currentdate){
									$this->session->set_userdata('logged_in', $sessiondata);
										$usr_result = $this->usermodel->add($mydata,'loggs');

									$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>Your license will expire today and you will not be able to acces your details though your data is safely stored.This is because of:'.$deadlinedetails.'.. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');

									   //redirect("user/viewsales");
									      
									   if($category=="user"){
										   									   redirect("user/verifysetails");

									   }else{
										   									   redirect("user/updatedata");

										   
									   }
									   
								  }else   if($deadline<$currentdate){
									  
									$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>Your license  has expired and   you can not be able to acces your details though your data is safely stored.This is because of:'.$deadlinedetails.'.. Kindly contact Robisearch Limited( www.robisearch.com/ info@robisearch.com /0790962631/0780655987 /0718667391 /0716413386 ).</div>');
								
								 redirect('login');
								   return  false;
								
									  
								  }else{
									  
									   $this->session->set_userdata('logged_in', $sessiondata);
										$usr_result = $this->usermodel->add($mydata,'loggs');

								 
								// redirect("user/viewsales");
									  
									     
									   if($category=="user"){
										   									   redirect("user/verifysetails");

									   }else{
										   									   redirect("user/updatedata");

										   
									   }
									   
								  }
								  
			
							 								
				}else{
					 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 <strong>Error!</strong> You dont have valid License Key to use ROBISEARCH SYSTEM. Contact ROBISEARCH LTD. 0790962631/0718667391/0716413386/0780655987 to get the License Key</div>');
								
									   
								redirect('login');
				}
					  
								  
								  
								  
								  
								  
								  
								  
							}
							else 
							{     
						
						
								
								 $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Incorrect email or password... Try again or create account if you have not.</div>');
								
								 redirect('login');
								
								
							}
								
								
								
								
								
								
								
								
					
								
								
								
								
						
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

	





	
	
	
	
	
	
	
	
	
	



	
	
	
	   public function logout() {
        $data = ['id', 'email'];
        $this->session->unset_userdata('logged_in');
		session_destroy();

  		 redirect('login', 'refresh');
       
    }
	
	
	
	
}
 ?>