<?php
ob_start();

defined('BASEPATH') OR exit('No direct script access allowed');
 

class Accomodation extends CI_Controller
{
	
	
    function __construct() {
        parent::__construct();
		ini_set('max_execution_time', 0); 
ini_set('memory_limit','4048M');
        	$this->load->model('usermodel','',TRUE);
			        	$this->load->model('accomodationmodel','',TRUE);
$this->load->model('adminusermodel','',TRUE);
	$this->load->library('encrypt');

		$this->load->model('districtmodel','',TRUE);
		$this->load->model('countymodel','',TRUE);
		
		
		$this->load->model('nationmodel','',TRUE);
		$this->load->model('countymodel','',TRUE);
 
 
 
  $this->load->model('systemusermodel','',TRUE);
   
   	  $this->load->helper('AfricasTalkingGateway');
        if(empty($this->session->userdata('logged_in'))) {
            $this->session->set_flashdata('flash_data', 'You don\'t have access!');
            redirect('login');
        }
		if( !isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], "order/place") === -1 ) {
    $this->load->helper('url');
    redirect('/page404');
}	
	
	
	
		
    }

	

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

   if (!($session_data)){

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

    $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
 $data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
        
		
			 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	 
	 if($usertype!="admin"){
		 
		 echo "You do not have right to accessthis page.";
		 return false;
	 }
	
        		$data['configuration'] = $this->accomodationmodel->populateallarray('smsconfig','id',$companyid);

        	

    	$this->load->view("template/headerpage", $data);
$data['userid']=$userid;
		$data['companyid']=$companyid;
		 $this->load->view('userdata/configuration', $data);
		$this->load->view("template/footerpage");
		
	}
  }
  
  
  function backup()
	{
		set_time_limit(0);
		$this->load->dbutil();
		$prefs = array(
			'format'      => 'txt',             // gzip, zip, txt
			'add_drop'    => FALSE,              // Whether to add DROP TABLE statements to backup file
			'add_insert'  => TRUE,              // Whether to add INSERT data to backup file
			'newline'     => "\n"               // Newline character used in backup file
    	);
		$backup =&$this->dbutil->backup($prefs);
		$backup = 'SET FOREIGN_KEY_CHECKS = 0;'."\n".$backup."\n".'SET FOREIGN_KEY_CHECKS = 1;';
		force_download('robihotel.sql', $backup);
	}
	
	
	
	
  
	
	 public function updateconfiguration()
    {
		
			$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 ;
	
			  $companyid = $this->input->post("companyid");		
 $businessname = $this->input->post("businessname");

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

		  $display2 = $this->input->post("display2");		
 $display1 = $this->input->post("display1");

	  $email = $this->input->post("email");
	  $contact = $this->input->post("contact");		  
		  $contact2 = $this->input->post("contact2");    
		 $address = $this->input->post("address");   
		  $location = $this->input->post("location");   
		   $contactperson = $this->input->post("contactperson");   
		    $country = $this->input->post("country");   
			 $currencysymbol = $this->input->post("currencysymbol");   
			  $image_id = $this->input->post("image_id");   
			   $tax1 = $this->input->post("tax1");   
			    $tax1rate = $this->input->post("tax1rate");   
				 $tax2 = $this->input->post("tax2");   
				  
				 $website = $this->input->post("website"); 
				 $tax2rate = $this->input->post("tax2rate"); 
				 				 $tillno = $this->input->post("tillno"); 

								
				
								 $receiptdescription = $this->input->post("receiptdescription"); 
								 $invoicedetails = $this->input->post("invoicedetails"); 

				
				
				
				
				
				 $description = $this->input->post("description");
	  $returnpolicy = $this->input->post("returnpolicy");		  
		  $paymenttypes = $this->input->post("paymenttypes");    
		 $logo = $this->input->post("logo");   
				
				 $maindiscount = $this->input->post("maindiscount");   
				
							 $fromdate = $this->input->post("fromdate");
	  $todate = $this->input->post("todate");		  
		  $starttime = $this->input->post("starttime");    
		 $duetime = $this->input->post("duetime");   
				
				
			  		  $this->form_validation->set_rules("businessname", "First name", "trim|required");

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

		
		 $this->load->view('userdata/configuration', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_updateconfig') == "config")
					   {
						   
						   
						   
						   
												$data=array(		
		
						'todate'=>$todate,

				'starttime'=>$starttime,
			'duetime'=>$duetime,
		  	'fromdate'=>$fromdate,
		
							'barcode'=>$barcode,

				'businessname'=>$businessname,
			'tillno'=>$tillno,
		  	'email'=>$email,
				'description'=>$description,
			'returnpolicy' => $returnpolicy,		  
		  'paymenttypes' => $paymenttypes,    
		
			
			'updatedat'=>$dateposted,
			'contact' => $contact,		  
		  'contact2' => $contact2,    
		 'address' => $address,   
		  'location' => $location,   
		   'contactperson' => $contactperson,   
		    'country' => $country,   
			 'currencysymbol' => $currencysymbol,   
			  
			   'tax1' => $tax1,   
			    'tax1rate' => $tax1rate,  
				'tax2' => $tax2,   
				  
				 'website' => $website, 
				 'tax2rate' => $tax2rate, 
				 'userid' => $userid, 
		 'logo' => $logo, 
		'display1' => $display1,
		'display2' => $display2,
		'maindiscount' => $maindiscount,
		'receiptdescription' => $receiptdescription,	
				'invoicedetails' => $invoicedetails,	

		
								);
						
								$usr_result = $this->accomodationmodel->updatedata($data,'smsconfig','id',$companyid);

							//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 Company settings..</div>');	
						 redirect('admin/viewconfiguration');																
							}
							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 Company settings  was not updated.. Try again</div>');
								
								 redirect('admin/viewconfiguration');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }
	
	
	
	  public function viewexpenditure()
	{ 
		
		 $session_data = $this->session->userdata('logged_in');

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


				
				
				$config['base_url'] = base_url('Systemusers/viewexpenditure');
		$config['total_rows'] = $this->accomodationmodel->count_allwhere('expenses','type','plot');
		$config['per_page'] = '20';
		$config['uri_segment'] = 3;
		$config['full_tag_open'] = "<ul class='pagination'>";
		$config['full_tag_close'] ="</ul>";
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
		$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
		$config['next_tag_open'] = "<li>";
		$config['next_tagl_close'] = "</li>";
		$config['prev_tag_open'] = "<li>";
		$config['prev_tagl_close'] = "</li>";
		$config['first_tag_open'] = "<li>";
		$config['first_tagl_close'] = "</li>";
		$config['last_tag_open'] = "<li>";
		$config['last_tagl_close'] = "</li>";

		$this->pagination->initialize($config);
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		//$data['mycategory'] = $this->accomodationmodel->populateproductcategorybyid($userid);
        $data["viewexpenses"] = $this->accomodationmodel->displayall($config["per_page"], $page,'expenses','type','plot');
         $this->load->view("template/headerpagemin");
		// $this->load->view("template/tableheader");
			//$data['total_people'] = $this->accomodationmodel->countMembers($userid); 
		$data["total_rows"] =$config['total_rows'];
		$data["links"] = $this->pagination->create_links();
		$data["page"]=$page;
			$this->load->view('userdata/allexpenditure',$data);
				
		$this->load->view("template/footerpage");
	
	}
  
	public function viewexpenses()
	{ 
		
		 $session_data = $this->session->userdata('logged_in');

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


				
				
				$config['base_url'] = base_url('Systemusers/viewexpenses');
		$config['total_rows'] = $this->accomodationmodel->count_allwhere('expenses','userid',$userid);
		$config['per_page'] = '20';
		$config['uri_segment'] = 3;
		$config['full_tag_open'] = "<ul class='pagination'>";
		$config['full_tag_close'] ="</ul>";
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
		$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
		$config['next_tag_open'] = "<li>";
		$config['next_tagl_close'] = "</li>";
		$config['prev_tag_open'] = "<li>";
		$config['prev_tagl_close'] = "</li>";
		$config['first_tag_open'] = "<li>";
		$config['first_tagl_close'] = "</li>";
		$config['last_tag_open'] = "<li>";
		$config['last_tagl_close'] = "</li>";

		$this->pagination->initialize($config);
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		//$data['mycategory'] = $this->accomodationmodel->populateproductcategorybyid($userid);
        $data["viewexpenses"] = $this->accomodationmodel->displayall($config["per_page"], $page,'expenses','userid',$userid);
         $this->load->view("template/headerpagemin");
		// $this->load->view("template/tableheader");
			//$data['total_people'] = $this->accomodationmodel->countMembers($userid); 
		$data["total_rows"] =$config['total_rows'];
		$data["links"] = $this->pagination->create_links();
		$data["page"]=$page;
			$this->load->view('userdata/viewexpenses',$data);
				
		$this->load->view("template/footerpage");
	
	}
	
	
	
	
	
		public function viewmydailycollections()
	{ 
		
		 $session_data = $this->session->userdata('logged_in');
 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];


				
				
				$config['base_url'] = base_url('Systemusers/viewmydailycollections');
		$config['total_rows'] = $this->accomodationmodel->count_allwhere('dailycollections','companyid',$companyid);
		$config['per_page'] = '20';
		$config['uri_segment'] = 3;
		$config['full_tag_open'] = "<ul class='pagination'>";
		$config['full_tag_close'] ="</ul>";
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
		$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
		$config['next_tag_open'] = "<li>";
		$config['next_tagl_close'] = "</li>";
		$config['prev_tag_open'] = "<li>";
		$config['prev_tagl_close'] = "</li>";
		$config['first_tag_open'] = "<li>";
		$config['first_tagl_close'] = "</li>";
		$config['last_tag_open'] = "<li>";
		$config['last_tagl_close'] = "</li>";

		$this->pagination->initialize($config);
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		//$data['mycategory'] = $this->accomodationmodel->populateproductcategorybyid($userid);
        $data["collections"] = $this->accomodationmodel->displayall($config["per_page"], $page,'dailycollections','companyid',$companyid);
         $this->load->view("template/headerpagemin");
		// $this->load->view("template/tableheader");
			//$data['total_people'] = $this->accomodationmodel->countMembers($userid); 
		$data["total_rows"] =$config['total_rows'];
		$data["links"] = $this->pagination->create_links();
		$data["page"]=$page;
			$this->load->view('pmsdata/viewdailycollections',$data);
				
		$this->load->view("template/footerpage");
	
	}
	
	
	
	
	
	
	
	
	
	
	
		public function viewplotsms()
	{ 
		
		 $session_data = $this->session->userdata('logged_in');

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

$mytotal_amount = $this->accomodationmodel->countamount($userid);

	$total_amount=$mytotal_amount[0]['totalsms'];			
				
				$config['base_url'] = base_url('Systemusers/viewplotsms');
		if($usertype=="admin"){
		$config['total_rows'] = $this->accomodationmodel->count_allwhere('sms','companyid',$companyid);

				}else{
		$config['total_rows'] = $this->accomodationmodel->count_allwhere('sms','userid',$userid);

				}
		$config['per_page'] = '20';
		$config['uri_segment'] = 3;
		$config['full_tag_open'] = "<ul class='pagination'>";
		$config['full_tag_close'] ="</ul>";
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
		$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
		$config['next_tag_open'] = "<li>";
		$config['next_tagl_close'] = "</li>";
		$config['prev_tag_open'] = "<li>";
		$config['prev_tagl_close'] = "</li>";
		$config['first_tag_open'] = "<li>";
		$config['first_tagl_close'] = "</li>";
		$config['last_tag_open'] = "<li>";
		$config['last_tagl_close'] = "</li>";

		$this->pagination->initialize($config);
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
			if($usertype=="admin"){
        $data["viewplotsms"] = $this->accomodationmodel->displayall($config["per_page"], $page,'sms','companyid',$companyid);


				}else{
        $data["viewplotsms"] = $this->accomodationmodel->displayall($config["per_page"], $page,'sms','userid',$userid);

				}
				
				
         $this->load->view("template/headerpagemin");
		 					$data['agent'] = $this->accomodationmodel->populateallstatus('agent', 'companyid',$companyid, 'status','1');
		 					$data['tenant'] = $this->accomodationmodel->populateallstatus('people', 'companyid',$companyid, 'status','1');
		 					$data['myplots'] = $this->accomodationmodel->populateallstatus('plot', 'companyid',$companyid, 'status','1');

				$data['landlord'] = $this->accomodationmodel->populateallstatus('landlord', 'companyid',$companyid, 'status','1');
				$data['mycategory'] = $this->accomodationmodel->populateallstatus('category', 'companyid',$companyid, 'status','1');


				
		
	//$data['mycategory'] = $this->accomodationmodel->populatecategory($userid);
			$data['total_sms'] = $this->accomodationmodel->countSMS($userid); 
			$data['total_sms'] = $this->accomodationmodel->countamount($userid); 
		$data["total_rows"] =$config['total_rows'];
		$data["total_amount"] =$total_amount;
		$data["links"] = $this->pagination->create_links();
			$this->load->view('userdata/viewplotsms',$data);
				
		$this->load->view("template/footerpage");
	
	}
	
	public function viewmyplotsms()
	{ 
		
		 $session_data = $this->session->userdata('logged_in');

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

$mytotal_amount = $this->accomodationmodel->countamount($userid);

	$total_amount=$mytotal_amount[0]['totalsms'];			
				
				$config['base_url'] = base_url('Systemusers/viewplotsms');
		if($usertype=="admin"){
		$config['total_rows'] = $this->accomodationmodel->count_allwhere('sms','companyid',$companyid);

				}else{
		$config['total_rows'] = $this->accomodationmodel->count_allwhere('sms','userid',$userid);

				}
		$config['per_page'] = '20';
		$config['uri_segment'] = 3;
		$config['full_tag_open'] = "<ul class='pagination'>";
		$config['full_tag_close'] ="</ul>";
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
		$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
		$config['next_tag_open'] = "<li>";
		$config['next_tagl_close'] = "</li>";
		$config['prev_tag_open'] = "<li>";
		$config['prev_tagl_close'] = "</li>";
		$config['first_tag_open'] = "<li>";
		$config['first_tagl_close'] = "</li>";
		$config['last_tag_open'] = "<li>";
		$config['last_tagl_close'] = "</li>";

		$this->pagination->initialize($config);
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
			if($usertype=="admin"){
        $data["viewplotsms"] = $this->accomodationmodel->displayall($config["per_page"], $page,'sms','companyid',$companyid);


				}else{
        $data["viewplotsms"] = $this->accomodationmodel->displayall($config["per_page"], $page,'sms','userid',$userid);

				}
				
				
         $this->load->view("template/headerpagemin");
		 					$data['agent'] = $this->accomodationmodel->populateallstatus('agent', 'companyid',$companyid, 'status','1');
		 					$data['tenant'] = $this->accomodationmodel->populateallstatus('tenant', 'companyid',$companyid, 'status','1');
		 					$data['myplots'] = $this->accomodationmodel->populateallstatus('plot', 'companyid',$companyid, 'status','1');

				$data['landlord'] = $this->accomodationmodel->populateallstatus('landlord', 'companyid',$companyid, 'status','1');
				$data['mycategory'] = $this->accomodationmodel->populateallstatus('category', 'companyid',$companyid, 'status','1');


				
		
	//$data['mycategory'] = $this->accomodationmodel->populatecategory($userid);
			$data['total_sms'] = $this->accomodationmodel->countSMS($userid); 
			$data['total_sms'] = $this->accomodationmodel->countamount($userid); 
		$data["total_rows"] =$config['total_rows'];
		$data["total_amount"] =$total_amount;
		$data["links"] = $this->pagination->create_links();
			$this->load->view('userdata/viewmyplotsms',$data);
				
		$this->load->view("template/footerpage");
	
	}
	
			public function viewcategory()
	{ $session_data = $this->session->userdata('logged_in');
		 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
				$this->load->view("template/headerpagemin");
		
		$this->load->view("template/tableheader");
					$data['viewcategory'] = $this->accomodationmodel->populateall('category', 'companyid',$companyid);

		//$data['viewcategory'] = $this->accomodationmodel->populatecategory($companyid);

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

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

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


				
				
				$config['base_url'] = base_url('Systemusers/viewmember');
		$config['total_rows'] = $this->accomodationmodel->count_allwhere('people','userid',$userid);
		$config['per_page'] = '20';
		$config['uri_segment'] = 3;
		$config['full_tag_open'] = "<ul class='pagination'>";
		$config['full_tag_close'] ="</ul>";
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
		$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
		$config['next_tag_open'] = "<li>";
		$config['next_tagl_close'] = "</li>";
		$config['prev_tag_open'] = "<li>";
		$config['prev_tagl_close'] = "</li>";
		$config['first_tag_open'] = "<li>";
		$config['first_tagl_close'] = "</li>";
		$config['last_tag_open'] = "<li>";
		$config['last_tagl_close'] = "</li>";

		$this->pagination->initialize($config);
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		$data['mycategory'] = $this->accomodationmodel->populatecategory($userid);
        $data["viewmember"] = $this->accomodationmodel->displayallmembersperuser($config["per_page"], $page,$userid);
         $this->load->view("template/headerpagemin");
		// $this->load->view("template/tableheader");
			$data['total_people'] = $this->accomodationmodel->countMembers($userid); 
		$data["total_rows"] =$config['total_rows'];
		$data["links"] = $this->pagination->create_links();
			$this->load->view('userdata/viewmember',$data);
				
		$this->load->view("template/footerpage");
	
	}
	
	public function viewsms()
	{ 
		
		 $session_data = $this->session->userdata('logged_in');

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

$mytotal_amount = $this->accomodationmodel->countamount($userid);

	$total_amount=$mytotal_amount[0]['totalsms'];			
				
				$config['base_url'] = base_url('Systemusers/viewsms');
		$config['total_rows'] = $this->accomodationmodel->count_allwhere('sms','userid',$userid);
		$config['per_page'] = '20';
		$config['uri_segment'] = 3;
		$config['full_tag_open'] = "<ul class='pagination'>";
		$config['full_tag_close'] ="</ul>";
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
		$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
		$config['next_tag_open'] = "<li>";
		$config['next_tagl_close'] = "</li>";
		$config['prev_tag_open'] = "<li>";
		$config['prev_tagl_close'] = "</li>";
		$config['first_tag_open'] = "<li>";
		$config['first_tagl_close'] = "</li>";
		$config['last_tag_open'] = "<li>";
		$config['last_tagl_close'] = "</li>";

		$this->pagination->initialize($config);
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["viewsms"] = $this->accomodationmodel->displayallsmsperuser($config["per_page"], $page,$userid);
         $this->load->view("template/headerpagemin");
				$data['receiver'] = $this->accomodationmodel->populateall('people', 'userid',$userid);
		
	$data['mycategory'] = $this->accomodationmodel->populatecategory($userid);
			$data['total_sms'] = $this->accomodationmodel->countSMS($userid); 
			$data['total_sms'] = $this->accomodationmodel->countamount($userid); 
		$data["total_rows"] =$config['total_rows'];
		$data["total_amount"] =$total_amount;
		$data["links"] = $this->pagination->create_links();
			$this->load->view('userdata/viewsms',$data);
				
		$this->load->view("template/footerpage");
	
	}
	
	
	
	
	
	
	
	
	
   
	
	
	

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

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

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 
		  $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
				$this->load->view("template/headerpagemin");
		
		
	
		$data['viewcategory'] = $this->accomodationmodel->populatecategory($companyid);

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

		




	}
	
	
	
			public function viewemployees()
	{ 
				$this->load->view("template/headerpagemin");
		
		
	
		$data['viewemployees'] = $this->accomodationmodel->populateviewemployees();

				$this->load->view('userdata/viewemployees',$data);
		$this->load->view("template/footerpage");
	}
	
	
				public function viewloyality()
	{ 
				$this->load->view("template/headerpagemin");
		
		
	
		$data['viewloyality'] = $this->accomodationmodel->populateviewloyality();

				$this->load->view('userdata/viewloyality',$data);
		$this->load->view("template/footerpage");
	}
	
				public function setting()
	{ 
				$this->load->view("template/headerpagemin");
		
		
	
		$data['setting'] = $this->accomodationmodel->populateviewsetting();

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

			public function postsuggestion()
	{ 
		 $this->load->view("template/headerpagemin");
		
	

				$this->load->view('userdata/postsuggestion');
		$this->load->view("template/footerpage");
	}
	
		
	public function allmydata()
	{ 
		
	$session_data = $this->session->userdata('logged_in');

     $data['username'] = $session_data['username'];
 	$data['id'] = $session_data['id'];
 		$data['firstname'] = $session_data['firstname'];
 			$data['surname'] = $session_data['surname'];
 		
 			
 	$username= $data['username'] ;
	$id= $data['id'] ;
	

$data['province'] = $this->provincemodel->populateprovince();

	$data['county'] = $this->countymodel->populatecounty();
	$data['nation'] = $this->nationmodel->populatenation();


	
	$biodata['bio']= $this->systemaccomodationmodel->populatebiodata($id);

	$this->load->view("template/headerpagemin");
	
		
		 $this->load->view('userdata/biodata', $biodata,$data);
		$this->load->view("template/footerpage");
	}
	
	
	
		public function mysuggestion()
		
	{ 
	$session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 $this->load->view("template/headerpagemin");
		
	
		$data['suggestion'] = $this->systemaccomodationmodel->populatesuggestion($userid);

				$this->load->view('userdata/mysuggestion',$data);
		$this->load->view("template/footerpage");
	}
	
			
			public function adverts()
	{ 
		$session_data = $this->session->userdata('logged_in');

   
		 $this->load->view("template/headerpagemin");
		
	
		$data['adverts'] = $this->systemaccomodationmodel->populateadverts();

				$this->load->view('userdata/adverts',$data);
		$this->load->view("template/footerpage");
	}
	
	  public function editmember() {
   if (!isset($_GET['randomitemidentifier'])){

    
      show_error('No identifier provided', 500);
    }
    else {
		$session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
     $itemid = $_GET['randomitemidentifier'];

        		$data['member'] = $this->accomodationmodel->populatemember($itemid);
   	$data['mycategory'] = $this->accomodationmodel->populatecategory($userid);

    	$this->load->view("template/headerpagemin", $data);
$data['itemid']=$itemid;
		
		 $this->load->view('userdata/editmember', $data);
		$this->load->view("template/footerpage");
		
	}
  }
	
	
public function uploadmembers()
        {

          if(isset($_POST["btn_uploadmembers"]))
            { 

            	set_time_limit(0);
                $filename=$_FILES["file"]["tmp_name"];
              var_dump($_FILES["file"]["size"]);
                if($_FILES["file"]["size"] > 0)
                  {
                    $file = fopen($filename, "r");
                     while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
                     {
						 
						
						  $new_date=	date('Y-m-d');
                            $data = array(
                              
                               
                                 'firstname' => $emapData[1],
 								'lastname' => $emapData[2],
 									'phone' => $emapData[3],
									'email' => $emapData[4],
									'country' => $emapData[5],
									'idno' => $emapData[6],
									'gender' => $emapData[7],
									'category' => 'member',
									'userid' => $emapData[8],
 									
 									
 									
                                );
                    
                        $usr_result = $this->accomodationmodel->uploadmembers($data);
                     }
					
                    fclose($file);
                
                   	if ($usr_result ==TRUE) //active user record is present
							{
								 //echo "datasaved";
								 
						 $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 uploaded student data!</div>');
								
								 redirect('user/viewmember');
							}
							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> Data are not saved.. Try again</div>');
								
								 redirect('user/viewmember');
							}

                  }
            }
        }


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

    
      show_error('No identifier provided', 500);
    }
    else {
			$this->load->view("template/headerpagemin");
		$session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
 $userid = $data['id'];
 $transactionid = $_GET['randomitemidentifier'];
$status = $_GET['needed'];
$itemid = $_GET['itemid'];
		   	 
			  $mystatus="";
			  if( $status =="0"){
				  $mystatus="1"; 
			  }else if( $status =="1"){
				   $mystatus="0"; 
				  
			  }
		    
 $update=$this->accomodationmodel->updatememberstatus($transactionid,$mystatus); 
	

        	  if( $update ==true){

$this->session->set_flashdata('activemsg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Dublicate Error!</strong> The status of this member has been changed succussesfully</div>');
								
								redirect('user/viewmygrouping?randomitemidentifier='.$itemid );
								}else{


		$this->session->set_flashdata('activemsg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Dublicate Error!</strong> The status of this member has  not been changed.. Try again</div>');
								
								redirect('user/viewmygrouping?randomitemidentifier='.$itemid );
	}
  }
	}
	
	
	
	
	
	 public function viewmygrouping() {
   if (!isset($_GET['randomitemidentifier'])){

    
      show_error('No identifier provided', 500);
    }
    else {
			$this->load->view("template/headerpagemin");
		$session_data = $this->session->userdata('logged_in');

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

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 
		  $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
	 
 	$data['id'] = $session_data['id'];
        
 $userid = $data['id'];
     $itemid = $_GET['randomitemidentifier'];

        		$data['mygrouping'] = $this->accomodationmodel->populatemembergrouping($itemid, $userid);
   	$data['itemid'] = $itemid;
	
	$data['member'] = $this->accomodationmodel->populatemember($itemid);
$data['mycategory'] = $this->accomodationmodel->populatecategory($companyid);
		$data['viewcategory'] = $this->accomodationmodel->populatecategory($userid);
    

		
		 $this->load->view('userdata/viewmygrouping',$data);
		$this->load->view("template/footerpage");
		
	}
  }
	
	
	
	
	 public function viewmembersbygrouping() {
   if (!isset($_GET['randomitemidentifier'])){

    
      show_error('No identifier provided', 500);
    }
    else {
			$this->load->view("template/headerpagemin");
		$session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
 $userid = $data['id'];
      $groupid = $_GET['randomitemidentifier'];
 $needed = $_GET['needed'];
      $data['mygrouping'] = $this->accomodationmodel->populatememberbygrouping($groupid,$userid,$needed);









	
$data['mycategory'] = $this->accomodationmodel->populatecategory($userid);
		$data['viewcategory'] = $this->accomodationmodel->populatecategory($userid);
  

		
		 $this->load->view('userdata/viewgroupmember',$data);
		$this->load->view("template/footerpage");
		
	
  }}
	
	
   public function viewmysuggestions() {
   if (!isset($_GET['randomitemidentifier'])){

    
      show_error('No identifier provided', 500);
    }
    else {
     $itemid = $_GET['randomitemidentifier'];

   	$data['postid'] = $itemid;
	
	$data['suggestion'] = $this->systemaccomodationmodel->getsuggestionbyid($itemid);

    	$this->load->view("template/headerpagemin", $data);

		
		 $this->load->view('userdata/viewmoresuggestion', $data);
		$this->load->view("template/footerpage");
		
	}
  }
 
 
 
  
 
  
  public function addcategory()
    {
		
$session_data = $this->session->userdata('logged_in');

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

		   	  $description = $this->input->post("description");
			  
		    
		
				
			  		  $this->form_validation->set_rules("name", "Product name", "trim|required");

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

		
		 $this->load->view('userdata/viewcategory', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_addcategory') == "category")
					   {
												$data=array(		
			'userid'=>$userid,
			
				'name'=>$name,
			
		  	'description'=>$description,
			
			'companyid' => $companyid,
				'userid' => $userid,
			'createdate'=>$dateposted,
				
			
								);
							$usr_result = $this->accomodationmodel->add($data,'category');
							
							//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 Added a new  Product..</div>');	
							redirect('user/viewcategory');																
							}
							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> Product  was not added.. Try again</div>');
								
								 redirect('user/viewcategory');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

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

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 
		  $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
	
         $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
		 $userid = $data['id'];
		 
		 		
		 		 $memberid = $this->input->post("itemid");
				$categoryid = $this->input->post("categoryid");
		   	  $status = $this->input->post("status");
			  $mystatus="";
			  if( $status =="active"){
				  $mystatus="1"; 
			  }else{
				   $mystatus="0"; 
				  
			  }
		    
			
				
			  		  $this->form_validation->set_rules("itemid", "Member name", "trim|required");
					  
$confirm_result = $this->accomodationmodel->confirmgrouping($memberid,$userid,$categoryid);
			  
			  
			    if($confirm_result ==TRUE){
				 $this->session->set_flashdata('groupmsg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Dublicate Error!</strong> This member had been assigned to that group.. Try a diffrent group or add more groups</div>');
								
								redirect('user/viewmygrouping?randomitemidentifier='.$memberid );	
			  }
		    
			
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      $this->load->view("template/headerpagemin");

		
		 $this->load->view('userdata/viewmygrouping', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_addgrouppingy') == "category")
					   {
												$data=array(		
			'userid'=>$userid,
			
				'memberid'=>$memberid,
				'status'=>$mystatus,
		  	'categoryid'=>$categoryid,
			
			 'companyid' => $companyid,
				
			'createdate'=>$dateposted,
				
			
								);
							$usr_result = $this->accomodationmodel->add($data,'grouping');
							
							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
								
								 
						 $this->session->set_flashdata('groupmsg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
								<strong>Success!</strong> You have successfully Added a Member to a new agroup  ..</div>');	
							redirect('user/viewmygrouping?randomitemidentifier='.$memberid );																
							}
							else if ($usr_result ==FALSE) 
							{     

			 $this->session->set_flashdata('groupmsg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Member  was not added into anew group.. Try again</div>');
								
								redirect('user/viewmygrouping?randomitemidentifier='.$memberid );	
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

 
 
 
	 public function addplotsms()
    {
		
			$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 = $data['companyid'];
		 		
		 		 $contact = trim($this->input->post("contact"));

		   	  $message = trim($this->input->post("message"));
			 
		  
			  		  $this->form_validation->set_rules("contact", "Contact", "trim|required");

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

		
		 $this->load->view('userdata/viewplotsms', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_addplotsms') == "sms")

					   {
						   
				
			
				
			
			$myArray = explode(',', $contact);
foreach($myArray as $allcontacts){
			    $confirmaccount_result = $this->accomodationmodel->confirmaccount($userid);
$totalsms=$confirmaccount_result[0]['totalsms'];
$apiid=$confirmaccount_result[0]['companyid'];
						   
						   $countmessage =strlen($message);
					 $COST="";
				 if($countmessage<=160){
				
					$COST=1;
				 }else if($countmessage<=320){
					 
					$COST=2;
				 }else if($countmessage<=480){
					$COST=3;
					
				 }
				 else if($countmessage<=640){
					$COST=4;
				
				 }
				 else if($countmessage<=800){
					 $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('user/viewplotsms');
		}else{
			
			 $confirmsmsaccount_result = $this->accomodationmodel->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,
				
			
								);
					$url = 'http://sms.robisearch.com/sendsms.jsp?';
			$xml_data ='<?xml version="1.0"?><smslist><sms><user>'.$username.'</user><password>'.$password.'</password><message>'.$message.'</message><mobiles>'.$allcontacts.'</mobiles><senderid>'.$from.'</senderid><cdmasenderid>00201009546310</cdmasenderid><group>-1</group><clientsmsid>0</clientsmsid></sms></smslist>'; 

 
			$ch = curl_init($url);			
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
			curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$output = curl_exec($ch);
			curl_close($ch);


				
		try{
		$xml = new SimpleXMLElement($output);
			
			$code="error-code";
			$mydescription="error-description";
			$finalcode=$xml->error->$code;
			$description=$xml->error->$mydescription;
			if($finalcode== 0) {
				$usr_result = $this->accomodationmodel->add($data,'sms');
				
					 $countmessage =strlen($message);
				 if($countmessage<=160){
					$finaltotalsms=$totalsms-1;
				 }else if($countmessage<=320){
					 
					$finaltotalsms=$totalsms-2;
				 }else if($countmessage<=480){
					 $finaltotalsms=$totalsms-3;
					
				 }
				 else if($countmessage<=640){
					 $finaltotalsms=$totalsms-4;
				
				 }
				 else if($countmessage<=800){
					 $finaltotalsms=$totalsms-5;
					
				 }

				$usr_result2 = $this->accomodationmodel->updateusersms($userid,$finaltotalsms);
			}
				
						
			} catch (Exception $e) {
								//echo 'Error occurred during Sending Message: Please check on your internet connection or balance or ',  $e->getMessage(), "\n .Try again ";

				$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('user/viewplotsms');		
				}
				
			
}
}
			
if ($finalcode== 0) {
	
			
				
				$this->session->set_flashdata('msg','<div class="alert alert-success text-center">sms   is sent Successfully ! !!!</div>');
					
			
				redirect('user/viewplotsms');
			}else if  ($finalcode== $finalcode) {
				
				
				$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> '.$description .' .SMS  not Sent to  '.$allcontacts .' <a href=' .base_url(). 'user/viewsms> clicke here to go back  </a> </div>');
							redirect('user/viewplotsms');

			}else{
				$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>SMS not sent!   </strong> Please check on your internet connection or balance .Try again</div>');
							redirect('user/viewplotsms');
			
				
			}
			
			
			
			


						   
						   
						   
						   
						   
			
							
							//check if username and password is correct
			
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

 
 

 
  
 

 
  
  public function addgroupsms()
    {
		$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 = $data['companyid'];
	 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
		 			
		 		 $categoryid = $this->input->post("categoryid");

		   	  $mymessage = $this->input->post("message")	;
			  
			 
			  		  $this->form_validation->set_rules("message", "message", "trim|required");
		$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      $this->load->view("template/headerpagemin");

		
		 $this->load->view('userdata/viewsms', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
			 	if ($this->input->post('btn_groupaddsms') == "oursms")

					   {
						  
			
			
			
					   	if($companyid==2){
							
			
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>ALERT!</strong> You can not send group sms because you have note subcribe to unlimited/premium account. You are still using test account . You can contact us through :0780655987 or info@robisearch.com for full/unlimited (premium) account setup to enjoy more services</div>');
							
								 redirect('user/viewsms');
								 return false;
								 
		}
			
			 $confirmgroups= $this->accomodationmodel->confirmgroupsaccount($categoryid); 
			
			
			
			
			
			
			if(is_array($confirmgroups)) {
				   	 
							
						$finalcode="";			
  
  	foreach ($confirmgroups as $row){ 


		$memberid=$row->memberid;
		$viewmember = $this->accomodationmodel->populatmyemember($memberid);
					
					if(is_array($viewmember)) {

   foreach($viewmember as $c){
			 
				 

              

	   $mycontact= $c->phone ; 
	   					   
						   
			 $confirmaccount_result = $this->accomodationmodel->confirmaccount($userid);
$totalsms=$confirmaccount_result[0]['totalsms'];
$apiid=$confirmaccount_result[0]['companyid'];
						   
						  	   $countmessage =strlen($mymessage);
					 $COST="";
				 if($countmessage<=160){
				
					$COST=1;
				 }else if($countmessage<=320){
					 
					$COST=2;
				 }else if($countmessage<=480){
					$COST=3;
					
				 }
				 else if($countmessage<=640){
					$COST=4;
				
				 }
				 else if($countmessage<=800){
					 $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('user/viewsms');
								 return false;
		}else{
			
			 $confirmsmsaccount_result = $this->accomodationmodel->confirmasmsccount($apiid);
$myusername=$confirmsmsaccount_result[0]['username'];
$from=$confirmsmsaccount_result[0]['from'];
$mypassword=$confirmsmsaccount_result[0]['password'];

    // DONE!!! 
											$data=array(		
			'userid'=>$userid,
			
				'contact'=>$mycontact,
			
		  	'message'=>$mymessage,
			
			'companyid'=>$companyid,
			'postedtime'=>$dateposted,
				
			
								);
$url = 'http://sms.robisearch.com/sendsms.jsp?';
$xml_data ='<?xml version="1.0"?><smslist><sms><user>'.$myusername.'</user><password>'.$mypassword.'</password><message>'.$mymessage.'</message><mobiles>'.$mycontact.'</mobiles><senderid>'.$from.'</senderid><cdmasenderid>00201009546310</cdmasenderid><group>-1</group><clientsmsid>0</clientsmsid></sms></smslist>'; 
//$xml = "<SendMessage><message id='292' sentdate='636742' message='$message' source='$allcontacts'/></SendMessage>";

 
 //$xml = "<smslist><sms><user>robiseach</user><password>r12345</password><message>Hi robert Manyala</message><mobiles>25418667391</mobiles><senderid>INFOTEXT</senderid><cdmasenderid>00201009546310</cdmasenderid><group>-1</group><clientsmsid>0</clientsmsid><accountusagetypeid>1</accountusagetypeid></sms></smslist>";

			$ch = curl_init($url);			
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
			curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$output = curl_exec($ch);
			curl_close($ch);
			try{
				
	
			$xml = new SimpleXMLElement($output);
			
			$code="error-code";
			$mydescription="error-description";
			$finalcode=$xml->error->$code;
			$description=$xml->error->$mydescription;
			if($finalcode== 0) {
				$usr_result = $this->accomodationmodel->add($data,'sms');
				
				 $countmessage =strlen($mymessage);
				 if($countmessage<=160){
					$finaltotalsms=$totalsms-1;
				 }else if($countmessage<=320){
					 
					$finaltotalsms=$totalsms-2;
				 }else if($countmessage<=480){
					 $finaltotalsms=$totalsms-3;
					
				 }
				 else if($countmessage<=640){
					 $finaltotalsms=$totalsms-4;
				
				 }
				 else if($countmessage<=800){
					 $finaltotalsms=$totalsms-5;
					
				 }
				
				$usr_result2 = $this->accomodationmodel->updateusersms($userid,$finaltotalsms);
			}
				
				} catch (Exception $e) {
								//echo 'Error occurred during Sending Message: Please check on your internet connection or balance or ',  $e->getMessage(), "\n .Try again ";

				$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('user/viewsms');		
				}		
			
				

				}
	
	 
	 

}
	
			



}
					
	

}
								
if ($finalcode== 0) {
	
			
				
				$this->session->set_flashdata('msg','<div class="alert alert-success text-center">sms   is sent Successfully ! !!!</div>');
					
			
				redirect('user/viewsms');
			}else if  ($finalcode== $finalcode) {
				
				
				$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> '.$description .' .SMS  not Sent to  '.$allcontacts .' <a href=' .base_url(). 'user/viewsms> clicke here to go back  </a> </div>');
							redirect('user/viewsms');

			}else{
				$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>SMS not sent!   </strong> Please check on your internet connection or balance .Try again</div>');
							redirect('user/viewsms');
			
				
			}






								
								   }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> There is no any member who is active from the group you have selected.. Try again</div>');
								
								 redirect('user/viewsms');
										}
		
		
}else{
	redirect('login');	
	
	
}
}
	
	}
	
	
	
	
	
	
	
	
	
	
	


 public function addmygroupsms()
    {
		$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 = $data['companyid'];
	 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
		 			
		 		 $categoryid = trim($this->input->post("categoryid"));

		   	  $mymessage = $this->input->post("message")	;
			  
			 
			  		  $this->form_validation->set_rules("message", "message", "trim|required");
		$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      $this->load->view("template/headerpagemin");

		
		 $this->load->view('userdata/viewplotsms', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
			 	if ($this->input->post('btn_groupaddplotsms') == "oursms")

					   {
						  
			
			
			
					   	if($companyid==2){
							
			
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>ALERT!</strong> You can not send group sms because you have note subcribe to unlimited/premium account. You are still using test account . You can contact us through :0780655987 or info@robisearch.com for full/unlimited (premium) account setup to enjoy more services</div>');
							
								 redirect('user/viewplotsms');
								 return false;
								 
		}
			
			
			
			
			
			
			
				   	 
								
					   if($categoryid=="Landlords"){
						   
				$viewmember = $this->accomodationmodel->populateallstatus('landlord', 'companyid',$companyid, 'status','1');

					   }else if($categoryid=="Agents"){
						   				$viewmember = $this->accomodationmodel->populateallstatus('agent', 'companyid',$companyid, 'status','1');

					}else if($categoryid=="Tenants"){
						
										$viewmember = $this->accomodationmodel->populateallstatus('tenant', 'companyid',$companyid, 'status','1');

					}else{
					
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>ALERT!</strong> You have selected wrong group or can not send group sms because you have note subcribe to unlimited/premium account. You are still using test account . You can contact us through :0780655987 or info@robisearch.com for full/unlimited (premium) account setup to enjoy more services</div>');
							
								 redirect('user/viewplotsms');	
						 return false;
					}
					
					


	
	
	
					if(is_array($viewmember)) {

   foreach($viewmember as $c){
			 
				 

              

	   $mycontact= $c->phone ; 
	   
	   			if($mycontact!="")	{
					
				   
						   
			 $confirmaccount_result = $this->accomodationmodel->confirmaccount($userid);
$totalsms=$confirmaccount_result[0]['totalsms'];
$apiid=$confirmaccount_result[0]['companyid'];
						   
						  	   $countmessage =strlen($mymessage);
					 $COST="";
				 if($countmessage<=160){
				
					$COST=1;
				 }else if($countmessage<=320){
					 
					$COST=2;
				 }else if($countmessage<=480){
					$COST=3;
					
				 }
				 else if($countmessage<=640){
					$COST=4;
				
				 }
				 else if($countmessage<=800){
					 $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('user/viewplotsms');
								 return false;
		}else{
			
			 $confirmsmsaccount_result = $this->accomodationmodel->confirmasmsccount($apiid);
$myusername=$confirmsmsaccount_result[0]['username'];
$from=$confirmsmsaccount_result[0]['from'];
$mypassword=$confirmsmsaccount_result[0]['password'];

    // DONE!!! 
											$data=array(		
			'userid'=>$userid,
			
				'contact'=>$mycontact,
			
		  	'message'=>$mymessage,
			
			'companyid'=>$companyid,
			'postedtime'=>$dateposted,
				
			
								);
		$url = 'http://sms.robisearch.com/sendsms.jsp?';
			$xml_data ='<?xml version="1.0"?><smslist><sms><user>'.$myusername.'</user><password>'.$mypassword.'</password><message>'.$mymessage.'</message><mobiles>'.$mycontact.'</mobiles><senderid>'.$from.'</senderid><cdmasenderid>00201009546310</cdmasenderid><group>-1</group><clientsmsid>0</clientsmsid></sms></smslist>'; 


			$ch = curl_init($url);			
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
			curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$output = curl_exec($ch);
			curl_close($ch);


				
		try{
		$xml = new SimpleXMLElement($output);
			
			$code="error-code";
			$mydescription="error-description";
			$finalcode=$xml->error->$code;
			$description=$xml->error->$mydescription;
			if($finalcode== 0) {
				$usr_result = $this->accomodationmodel->add($data,'sms');
				
					 $countmessage =strlen($mymessage);
				 if($countmessage<=160){
					$finaltotalsms=$totalsms-1;
				 }else if($countmessage<=320){
					 
					$finaltotalsms=$totalsms-2;
				 }else if($countmessage<=480){
					 $finaltotalsms=$totalsms-3;
					
				 }
				 else if($countmessage<=640){
					 $finaltotalsms=$totalsms-4;
				
				 }
				 else if($countmessage<=800){
					 $finaltotalsms=$totalsms-5;
					
				 }

				$usr_result2 = $this->accomodationmodel->updateusersms($userid,$finaltotalsms);
			}
				
						
			} catch (Exception $e) {
								//echo 'Error occurred during Sending Message: Please check on your internet connection or balance or ',  $e->getMessage(), "\n .Try again ";

				$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('user/viewplotsms');		
				}
		
		
			
				

				}
	
   }
	 

}
	
			



}   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> There is no any member who is active from the group you have selected.. Try again</div>');
								
								 redirect('user/viewplotsms');
										}
					
	

								
if ($finalcode== 0) {
	
			
				
				$this->session->set_flashdata('msg','<div class="alert alert-success text-center">sms   is sent Successfully ! !!!</div>');
					
			
				redirect('user/viewplotsms');
			}else if  ($finalcode== $finalcode) {
				
				
				$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> '.$description .' .SMS  not Sent to  '.$mycontact .' <a href=' .base_url(). 'user/viewsms> clicke here to go back  </a> </div>');
							redirect('user/viewplotsms');

			}else{
				$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>SMS not sent!   </strong> Please check on your internet connection or balance .Try again</div>');
							redirect('user/viewplotsms');
			
				
			}






								
								
		
		
}else{
	redirect('login');	
	
	
}
}
	
	}
	
	
	
	
	
	

 public function addmygroupsms2()
    {
		$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 = $data['companyid'];
	 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
		 			
		 		 $categoryid = trim($this->input->post("categoryid"));

		   	  $mymessage = $this->input->post("message")	;
			  
			 
			  		  $this->form_validation->set_rules("message", "message", "trim|required");
		$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      $this->load->view("template/headerpagemin");

		
		 $this->load->view('userdata/viewplotsms', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
			 	if ($this->input->post('btn_groupaddplotsms') == "oursms")

					   {
						  
			
			
			
					   	if($companyid==2){
							
			
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>ALERT!</strong> You can not send group sms because you have note subcribe to unlimited/premium account. You are still using test account . You can contact us through :0780655987 or info@robisearch.com for full/unlimited (premium) account setup to enjoy more services</div>');
							
								 redirect('user/viewplotsms');
								 return false;
								 
		}
			
			
			
			
			
			
			
				   	 
								
					   if($categoryid=="Landlords"){
						   
				$viewmember = $this->accomodationmodel->populateallstatus('landlord', 'companyid',$companyid, 'status','1');

					   }else if($categoryid=="Agents"){
						   				$viewmember = $this->accomodationmodel->populateallstatus('agent', 'companyid',$companyid, 'status','1');

					}else if($categoryid=="Tenants"){
						
										$viewmember = $this->accomodationmodel->populateallstatus('tenant', 'companyid',$companyid, 'status','1');

					}else{
					
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>ALERT!</strong> You have selected wrong group or can not send group sms because you have note subcribe to unlimited/premium account. You are still using test account . You can contact us through :0780655987 or info@robisearch.com for full/unlimited (premium) account setup to enjoy more services</div>');
							
								 redirect('user/viewplotsms');	
						 return false;
					}
					
					


	
	
	
					if(is_array($viewmember)) {

   foreach($viewmember as $c){
			 
				 

              

	   $mycontact= $c->phone ; 
	   			if($mycontact!="")	{
					
				   
						   
			 $confirmaccount_result = $this->accomodationmodel->confirmaccount($userid);
$totalsms=$confirmaccount_result[0]['totalsms'];
$apiid=$confirmaccount_result[0]['companyid'];
						   
						  	   $countmessage =strlen($mymessage);
					 $COST="";
				 if($countmessage<=160){
				
					$COST=1;
				 }else if($countmessage<=320){
					 
					$COST=2;
				 }else if($countmessage<=480){
					$COST=3;
					
				 }
				 else if($countmessage<=640){
					$COST=4;
				
				 }
				 else if($countmessage<=800){
					 $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('user/viewplotsms');
								 return false;
		}else{
			
			 $confirmsmsaccount_result = $this->accomodationmodel->confirmasmsccount($apiid);
$myusername=$confirmsmsaccount_result[0]['username'];
$from=$confirmsmsaccount_result[0]['from'];
$mypassword=$confirmsmsaccount_result[0]['password'];

    // DONE!!! 
											$data=array(		
			'userid'=>$userid,
			
				'contact'=>$mycontact,
			
		  	'message'=>$mymessage,
			
			'companyid'=>$companyid,
			'postedtime'=>$dateposted,
				
			
								);

			
			
			$url = 'http://mybettersms.net/BetterSmsPost/Default.aspx';
$xml = "<SendMessage><message id='292' sentdate='636742' message='$mymessage' source='$mycontact'/></SendMessage>";
$ch = curl_init();

curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HEADER, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $xml );

$finalcode = curl_exec($ch);


				
		try{
		
			if($finalcode==TRUE){
				$usr_result = $this->accomodationmodel->add($data,'sms');
				
				 $countmessage =strlen($mymessage);
				 if($countmessage<=160){
					$finaltotalsms=$totalsms-1;
				 }else if($countmessage<=320){
					 
					$finaltotalsms=$totalsms-2;
				 }else if($countmessage<=480){
					 $finaltotalsms=$totalsms-3;
					
				 }
				 else if($countmessage<=640){
					 $finaltotalsms=$totalsms-4;
				
				 }
				 else if($countmessage<=800){
					 $finaltotalsms=$totalsms-5;
					
				 }
				
				$usr_result2 = $this->accomodationmodel->updateusersms($userid,$finaltotalsms);
			}
				
				} catch (Exception $e) {
								//echo 'Error occurred during Sending Message: Please check on your internet connection or balance or ',  $e->getMessage(), "\n .Try again ";

				$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('user/viewplotsms');		
				}		
			
				

				}
	
   }
	 

}
	
			



}   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> There is no any member who is active from the group you have selected.. Try again</div>');
								
								 redirect('user/viewplotsms');
										}
					
	


								
if($finalcode==TRUE){
	
			
				
				$this->session->set_flashdata('msg','<div class="alert alert-success text-center">sms   is sent Successfully ! !!!</div>');
					
			
				redirect('user/viewplotsms');
			}else if  ($finalcode== $finalcode) {
				
				
				$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> '.$description .' .SMS  not Sent to  '.$allcontacts .' <a href=' .base_url(). 'user/viewsms> clicke here to go back  </a> </div>');
							redirect('user/viewplotsms');

			}else{
				$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>SMS not sent!   </strong> Please check on your internet connection or balance .Try again</div>');
							redirect('user/viewplotsms');
			
				
			}






								
								
		
		
}else{
	redirect('login');	
	
	
}
}
	
	}
	
	
	
	public function addgroupplotsms()
    {
		$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 = $data['companyid'];
	 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
		 			
		 		 $categoryid = $this->input->post("categoryid");

		   	  $mymessage = $this->input->post("message")	;
			  
			 
			  		  $this->form_validation->set_rules("message", "message", "trim|required");
		$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      $this->load->view("template/headerpagemin");

		
		 $this->load->view('userdata/viewplotsms', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
			 	if ($this->input->post('btn_groupaddplotsms') == "oursms")

					   {
						  
			
			
			
					   	if($companyid==2){
							
			
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>ALERT!</strong> You can not send group sms because you have note subcribe to unlimited/premium account. You are still using test account . You can contact us through :0780655987 or info@robisearch.com for full/unlimited (premium) account setup to enjoy more services</div>');
							
								 redirect('user/viewplotsms');
								 return false;
								 
		}
			
			 //$confirmgroups= $this->accomodationmodel->confirmgroupsaccount($categoryid); 
			
							$confirmgroups = $this->accomodationmodel->populateallstatus('bookroom', 'plotno',$categoryid, 'status','active');

			
			
			
			
			if(is_array($confirmgroups)) {
				   	 
							
						$finalcode="";			
  
  	foreach ($confirmgroups as $row){ 


		$memberid=$row->tenantid;
		$viewmember = $this->accomodationmodel->populattenantbyid($memberid);
					
					if(is_array($viewmember)) {

   foreach($viewmember as $c){
			 
				 

            

	   $mycontact= $c->phone ; 
	   		if($mycontact!="")	{
				
					   
						   
			 $confirmaccount_result = $this->accomodationmodel->confirmaccount($userid);
$totalsms=$confirmaccount_result[0]['totalsms'];
$apiid=$confirmaccount_result[0]['companyid'];
						   
						  	   $countmessage =strlen($mymessage);
					 $COST="";
				 if($countmessage<=160){
				
					$COST=1;
				 }else if($countmessage<=320){
					 
					$COST=2;
				 }else if($countmessage<=480){
					$COST=3;
					
				 }
				 else if($countmessage<=640){
					$COST=4;
				
				 }
				 else if($countmessage<=800){
					 $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('user/viewplotsms');
								 return false;
		}else{
			
			 $confirmsmsaccount_result = $this->accomodationmodel->confirmasmsccount($apiid);
$myusername=$confirmsmsaccount_result[0]['username'];
$from=$confirmsmsaccount_result[0]['from'];
$mypassword=$confirmsmsaccount_result[0]['password'];

    // DONE!!! 
											$data=array(		
			'userid'=>$userid,
			
				'contact'=>$mycontact,
			
		  	'message'=>$mymessage,
			
			'companyid'=>$companyid,
			'postedtime'=>$dateposted,
				
			
								);
								
					$url = 'http://sms.robisearch.com/sendsms.jsp?';
			$xml_data ='<?xml version="1.0"?><smslist><sms><user>'.$myusername.'</user><password>'.$mypassword.'</password><message>'.$mymessage.'</message><mobiles>'.$mycontact.'</mobiles><senderid>'.$from.'</senderid><cdmasenderid>00201009546310</cdmasenderid><group>-1</group><clientsmsid>0</clientsmsid></sms></smslist>'; 

 
			$ch = curl_init($url);			
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
			curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$output = curl_exec($ch);
			curl_close($ch);

	


				
		try{
			$xml = new SimpleXMLElement($output);
			
			$code="error-code";
			$mydescription="error-description";
			$finalcode=$xml->error->$code;
			$description=$xml->error->$mydescription;
			if($finalcode== 0) {
				$usr_result = $this->accomodationmodel->add($data,'sms');
				
				 $countmessage =strlen($mymessage);
				 if($countmessage<=160){
					$finaltotalsms=$totalsms-1;
				 }else if($countmessage<=320){
					 
					$finaltotalsms=$totalsms-2;
				 }else if($countmessage<=480){
					 $finaltotalsms=$totalsms-3;
					
				 }
				 else if($countmessage<=640){
					 $finaltotalsms=$totalsms-4;
				
				 }
				 else if($countmessage<=800){
					 $finaltotalsms=$totalsms-5;
					
				 }
				
				$usr_result2 = $this->accomodationmodel->updateusersms($userid,$finaltotalsms);
			}
				
				} catch (Exception $e) {
								//echo 'Error occurred during Sending Message: Please check on your internet connection or balance or ',  $e->getMessage(), "\n .Try again ";

				$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('user/viewplotsms');		
				}		
			
				

				}
	
	 
   }

}
	
			



}
					
	

}
								
if($finalcode==0){
	
			
				
				$this->session->set_flashdata('msg','<div class="alert alert-success text-center">sms   is sent Successfully ! !!!</div>');
					
			
				redirect('user/viewplotsms');
			}else if  ($finalcode== $finalcode) {
				
				
				$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> '.$description .' .SMS  not Sent to  '.$allcontacts .' <a href=' .base_url(). 'user/viewsms> clicke here to go back  </a> </div>');
							redirect('user/viewplotsms');

			}else{
				$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>SMS not sent!   </strong> Please check on your internet connection or balance .Try again</div>');
							redirect('user/viewplotsms');
			
				
			}






								
								   }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> There is no any member who is active from the group you have selected.. Try again</div>');
								
								 redirect('user/viewplotsms');
										}
		
		
}else{
	redirect('login');	
	
	
}
}
	
	}
 
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	
		
	
	public function addgroumemberpsms()
    {
		$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 = $data['companyid'];
	 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
		 			
		 		 $categoryid = $this->input->post("categoryid");

		   	  $mymessage = $this->input->post("message")	;
			  
			 
			  		  $this->form_validation->set_rules("message", "message", "trim|required");
		$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      $this->load->view("template/headerpage");

		
		 $this->load->view('userdata/viewsms', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
			 	if ($this->input->post('btn_groupaddsms') == "oursms")

					   {
						  
			
			
			
					   	if($companyid==2){
							
			
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>ALERT!</strong> You can not send group sms because you have note subcribe to unlimited/premium account. You are still using test account . You can contact us through :0780655987 or info@robisearch.com for full/unlimited (premium) account setup to enjoy more services</div>');
							
									redirect('user/viewplotsms');
								 return false;
								 
		}
			
			 $confirmgroups= $this->accomodationmodel->confirmgroupsaccount($categoryid); 
			
			
			
			
			
			
			if(is_array($confirmgroups)) {
				   	 
							
						$finalcode="";			
  
  	foreach ($confirmgroups as $row){ 


		$memberid=$row->memberid;
		$viewmember = $this->accomodationmodel->populatmyemember($memberid);
					
					if(is_array($viewmember)) {

   foreach($viewmember as $c){
			 
				 

              

	   $mycontact= $c->phone ; 
	   					   
						   
			 $confirmaccount_result = $this->accomodationmodel->confirmaccount($userid);
$totalsms=$confirmaccount_result[0]['totalsms'];
$apiid=$confirmaccount_result[0]['companyid'];
						   
						  	   $countmessage =strlen($mymessage);
					 $COST="";
				 if($countmessage<=160){
				
					$COST=1;
				 }else if($countmessage<=320){
					 
					$COST=2;
				 }else if($countmessage<=480){
					$COST=3;
					
				 }
				 else if($countmessage<=640){
					$COST=4;
				
				 }
				 else if($countmessage<=800){
					 $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('user/viewplotsms');
								 return false;
		}else{
			
			 $confirmsmsaccount_result = $this->accomodationmodel->confirmasmsccount($apiid);
$myusername=$confirmsmsaccount_result[0]['username'];
$from=$confirmsmsaccount_result[0]['from'];
$mypassword=$confirmsmsaccount_result[0]['password'];

    // DONE!!! 
											$data=array(		
			'userid'=>$userid,
			
				'contact'=>$mycontact,
			
		  	'message'=>$mymessage,
			
			'companyid'=>$companyid,
			'postedtime'=>$dateposted,
				
			
								);
$url = 'http://sms.robisearch.com/sendsms.jsp?';
$xml_data ='<?xml version="1.0"?><smslist><sms><user>'.$myusername.'</user><password>'.$mypassword.'</password><message>'.$mymessage.'</message><mobiles>'.$mycontact.'</mobiles><senderid>'.$from.'</senderid><cdmasenderid>00201009546310</cdmasenderid><group>-1</group><clientsmsid>0</clientsmsid></sms></smslist>'; 

			$ch = curl_init($url);			
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
			curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$output = curl_exec($ch);
			curl_close($ch);
			try{
				
	
			$xml = new SimpleXMLElement($output);
			
			$code="error-code";
			$mydescription="error-description";
			$finalcode=$xml->error->$code;
			$description=$xml->error->$mydescription;
			if($finalcode== 0) {
				$usr_result = $this->accomodationmodel->add($data,'sms');
				
				 $countmessage =strlen($mymessage);
				 if($countmessage<=160){
					$finaltotalsms=$totalsms-1;
				 }else if($countmessage<=320){
					 
					$finaltotalsms=$totalsms-2;
				 }else if($countmessage<=480){
					 $finaltotalsms=$totalsms-3;
					
				 }
				 else if($countmessage<=640){
					 $finaltotalsms=$totalsms-4;
				
				 }
				 else if($countmessage<=800){
					 $finaltotalsms=$totalsms-5;
					
				 }
				
				$usr_result2 = $this->accomodationmodel->updateusersms($userid,$finaltotalsms);
			}
				
				} catch (Exception $e) {
								//echo 'Error occurred during Sending Message: Please check on your internet connection or balance or ',  $e->getMessage(), "\n .Try again ";

				$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('user/viewplotsms');		
				}		
			
				

				}
	
	 
	 

}
	
			



}
					
	

}
								
if ($finalcode== 0) {
	
			
				
				$this->session->set_flashdata('msg','<div class="alert alert-success text-center">sms   is sent Successfully ! !!!</div>');
					
			
					redirect('user/viewplotsms');
			}else if  ($finalcode== $finalcode) {
				
				
				$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> '.$description .' .SMS  not Sent to  '.$allcontacts .' <a href=' .base_url(). 'user/viewsms> clicke here to go back  </a> </div>');
								redirect('user/viewplotsms');

			}else{
				$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>SMS not sent!   </strong> Please check on your internet connection or balance .Try again</div>');
								redirect('user/viewplotsms');
			
				
			}






								
								   }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> There is no any member who is active from the group you have selected.. Try again</div>');
								
									redirect('user/viewplotsms');
										}
		
		
}else{
	redirect('login');	
	
	
}
}
	
	}
	
	
	
	
	
	
	
	
	

	public function uploadbulksms()
        {

          if(isset($_POST["btn_uploadsms"]))
            { 
		$session_data = $this->session->userdata('logged_in');
		 	 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
	
		 $message = trim($this->input->post("message",true));
		$data['id'] = $session_data['id'];
        
		$userid = $data['id'];
		
		$postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
		
		
		
					   	if($companyid==2){
			
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>ALERT!</strong> You can not upload bulk /group contacts/members because you have note subcribe to unlimited/premium account. You are still using test account . You can contact us through :0780655987 or info@robisearch.com for full/unlimited (premium) account setup to enjoy more services</div>');
							
								redirect('user/viewplotsms');
								 return false;
								 
		}
				
		
		
            	set_time_limit(0);
                $filename=$_FILES["file"]["tmp_name"];
       
                if($_FILES["file"]["size"] > 0)
                  {
                    $file = fopen($filename, "r");
                     while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
                     {
						 	$confirmaccount_result = $this->accomodationmodel->confirmaccount($userid);
					$totalsms=$confirmaccount_result[0]['totalsms'];
					$apiid=$confirmaccount_result[0]['companyid'];
								 $confirmsmsaccount_result = $this->accomodationmodel->confirmasmsccount($apiid);
					$username=$confirmsmsaccount_result[0]['username'];
					$from=$confirmsmsaccount_result[0]['from'];
					$password=$confirmsmsaccount_result[0]['password'];	
					$totalsent=count($emapData[0]);
					
					
						  	   $countmessage =strlen($message);
					 $COST="";
				 if($countmessage<=160){
				
					$COST=1;
				 }else if($countmessage<=320){
					 
					$COST=2;
				 }else if($countmessage<=480){
					$COST=3;
					
				 }
				 else if($countmessage<=640){
					$COST=4;
				
				 }
				 else if($countmessage<=800){
					 $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> Some SMS were not sent. Your account has insufficient balance . Please recharge and try again</div>');
								
								 redirect('user/viewplotsms');
								 return false;
						}
					 $new_date=	date('Y-m-d');
						  $contacts=	$emapData[0];
						  $url = 'http://sms.robisearch.com/sendsms.jsp?';
								$xml_data ='<?xml version="1.0"?><smslist><sms><user>'.$username.'</user><password>'.$password.'</password><message>'.$message.'</message><mobiles>'.$contacts.'</mobiles><senderid>'.$from.'</senderid><cdmasenderid>00201009546310</cdmasenderid><group>-1</group><clientsmsid>0</clientsmsid></sms></smslist>'; 
	$data=array(		
										'userid'=>$userid,
										
											'contact'=>$emapData[0],
										
										'message'=>$message,
										'companyid'=>$companyid,

										
										'postedtime'=>$dateposted,
				
			
											);
								
								
						
			$ch = curl_init($url);			
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
			curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$output = curl_exec($ch);
			curl_close($ch);
			try{
				
	
			$xml = new SimpleXMLElement($output);
			
			$code="error-code";
			$mydescription="error-description";
			$finalcode=$xml->error->$code;
			$description=$xml->error->$mydescription;
			if($finalcode== 0) {
				$usr_result = $this->accomodationmodel->add($data,'sms');
				
					 $countmessage =strlen($message);
				 if($countmessage<=160){
					$finaltotalsms=$totalsms-1;
				 }else if($countmessage<=320){
					 
					$finaltotalsms=$totalsms-2;
				 }else if($countmessage<=480){
					 $finaltotalsms=$totalsms-3;
					
				 }
				 else if($countmessage<=640){
					 $finaltotalsms=$totalsms-4;
				
				 }
				 else if($countmessage<=800){
					 $finaltotalsms=$totalsms-5;
					
				 }
				$usr_result2 = $this->accomodationmodel->updateusersms($userid,$finaltotalsms);
			}
				
				} catch (Exception $e) {
								//echo 'Error occurred during Sending Message: Please check on your internet connection or balance or ',  $e->getMessage(), "\n .Try again ";

				$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('user/viewplotsms');	
				}	
								
					
                     }
					
                    fclose($file);
                
                   	if ($finalcode== 0) {
	
			
				
				$this->session->set_flashdata('msg','<div class="alert alert-success text-center">sms   is sent Successfully ! !!!</div>');
					
			
				redirect('user/viewplotsms');
			}else if  ($finalcode== $finalcode) {
				
				
				$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> '.$description .' .SMS  not Sent to  '.$allcontacts .' <a href=' .base_url(). 'user/viewsms> clicke here to go back  </a> </div>');
							redirect('user/viewplotsms');

			}else{
				$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>SMS not sent!   </strong> Please check on your internet connection or balance .Try again</div>');
							redirect('user/viewplotsms');
			
				
			}

                  }
            }
        }
		
							
							
			
			
		
		
	
	
	
	
	
	
	
	public function uploadbulksms1()
        {

          if(isset($_POST["btn_uploadsms"]))
            { 
		$session_data = $this->session->userdata('logged_in');
		 	 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
	
		 $message = $this->input->post("message");
		$data['id'] = $session_data['id'];
        
		$userid = $data['id'];
		
		$postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
		
		
		
					   	if($companyid==2){
			
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>ALERT!</strong> You can not upload bulk /group contacts/members because you have note subcribe to unlimited/premium account. You are still using test account . You can contact us through :0780655987 or info@robisearch.com for full/unlimited (premium) account setup to enjoy more services</div>');
							
								 redirect('user/viewplotsms');
								 return false;
								 
		}
				
		
		
            	set_time_limit(0);
                $filename=$_FILES["file"]["tmp_name"];
              var_dump($_FILES["file"]["size"]);
                if($_FILES["file"]["size"] > 0)
                  {
                    $file = fopen($filename, "r");
                     while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
                     {
						 	$confirmaccount_result = $this->accomodationmodel->confirmaccount($userid);
					$totalsms=$confirmaccount_result[0]['totalsms'];
					$apiid=$confirmaccount_result[0]['companyid'];
								 $confirmsmsaccount_result = $this->accomodationmodel->confirmasmsccount($apiid);
					$username=$confirmsmsaccount_result[0]['username'];
					$from=$confirmsmsaccount_result[0]['from'];
					$password=$confirmsmsaccount_result[0]['password'];	
					$totalsent=count($emapData[0]);
					
					
						  	   $countmessage =strlen($message);
					 $COST="";
				 if($countmessage<=160){
				
					$COST=1;
				 }else if($countmessage<=320){
					 
					$COST=2;
				 }else if($countmessage<=480){
					$COST=3;
					
				 }
				 else if($countmessage<=640){
					$COST=4;
				
				 }
				 else if($countmessage<=800){
					 $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> Some SMS were not sent. Your account has insufficient balance . Please recharge and try again</div>');
								
								 redirect('user/viewsms');
								 return false;
						}
					 $new_date=	date('Y-m-d');
						  $contacts=	$emapData[0];
						

								$data=array(		
										'userid'=>$userid,
										
											'contact'=>$emapData[0],
										
										'message'=>$message,
										'companyid'=>$companyid,

										
										'postedtime'=>$dateposted,
				
			
											);
								
								
						
						$url = 'http://mybettersms.net/BetterSmsPost/Default.aspx';
$xml = "<SendMessage><message id='292' sentdate='636742' message='$message' source='$contacts'/></SendMessage>";
$ch = curl_init();

curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HEADER, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $xml );

$finalcode = curl_exec($ch);


	


				
		try{
		
			if($finalcode==TRUE){
				$usr_result = $this->accomodationmodel->add($data,'sms');
				
					 $countmessage =strlen($message);
				 if($countmessage<=160){
					$finaltotalsms=$totalsms-1;
				 }else if($countmessage<=320){
					 
					$finaltotalsms=$totalsms-2;
				 }else if($countmessage<=480){
					 $finaltotalsms=$totalsms-3;
					
				 }
				 else if($countmessage<=640){
					 $finaltotalsms=$totalsms-4;
				
				 }
				 else if($countmessage<=800){
					 $finaltotalsms=$totalsms-5;
					
				 }
				$usr_result2 = $this->accomodationmodel->updateusersms($userid,$finaltotalsms);
			}
				
				} catch (Exception $e) {
								//echo 'Error occurred during Sending Message: Please check on your internet connection or balance or ',  $e->getMessage(), "\n .Try again ";

				$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('user/viewplotsms');		
				}	
								
					
                     }
					
                    fclose($file);
                
                   	if ($finalcode== 0) {
	
			
				
				$this->session->set_flashdata('msg','<div class="alert alert-success text-center">sms   is sent Successfully ! !!!</div>');
					
			
				redirect('user/viewplotsms');
			}else if  ($finalcode== $finalcode) {
				
				
				$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> '.$description .' .SMS  not Sent to  '.$allcontacts .' <a href=' .base_url(). 'user/viewsms> clicke here to go back  </a> </div>');
							redirect('user/viewplotsms');

			}else{
				$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>SMS not sent!   </strong> Please check on your internet connection or balance .Try again</div>');
							redirect('user/viewplotsms');
			
				
			}

                  }
            }
        }
		
		
	
	
	
	
	
	
 
  public function addgroupsms1()
    {
		
			$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'];
		 
		 		echo $categoryid = $this->input->post("categoryid");
		 		 $contact = $this->input->post("contact");

		   	 echo $message = $this->input->post("message");
		
		    
	
				
			  		  $this->form_validation->set_rules("message", "message", "trim|required");
  $confirmgroups= $this->accomodationmodel->confirmgroupsaccount($categoryid); 
  
				   	 	if ($confirmgroups != false)
								{
			  
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      $this->load->view("template/headerpagemin");

		
		 $this->load->view('userdata/viewsms', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
			
			
			
			
			
			
			
			
			
			
					   //validation succeeds
					 	if ($this->input->post('btn_groupaddsms') == "oursms")

					   {
						   
						
						   
						   
						   
						   	  $confirmaccount_result = $this->accomodationmodel->confirmaccount($userid);
$totalsms=$confirmaccount_result[0]['totalsms'];
$apiid=$confirmaccount_result[0]['companyid'];
						   
						   	if($confirmaccount_result[0]['totalsms']<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 account has insufficient balance . Please recharge and try again</div>');
								
								 redirect('user/viewsms');
		}else{
			
			 $confirmsmsaccount_result = $this->accomodationmodel->confirmasmsccount($apiid);
$username=$confirmsmsaccount_result[0]['username'];
$from=$confirmsmsaccount_result[0]['from'];
$apikey=$confirmsmsaccount_result[0]['apikey'];
		    $gateway    = new AfricasTalkingGateway($username, $apikey);
		  try 
    { 
     
       $results = $gateway->sendMessage($contact, $message, $from);
                
      foreach($results as $result) {
       
				   
						   
												$data=array(		
			'userid'=>$userid,
			
				'contact'=>$contact,
			
		  	'message'=>$message,
			
			
			'postedtime'=>$dateposted,
				
			
								);
							$usr_result = $this->accomodationmodel->add($data,'sms');
				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 Sent SMS..</div>');	
							//redirect('user/viewsms');																
							}
							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> SMS  was not Sent.. Try again</div>');
								
								 //redirect('user/viewsms');
		}
      }
	  		 
  
    }
    catch ( AfricasTalkingGatewayException $e )
    {
    // SMS  not Sent to  ".  $recipients .".Error was Encountered  while sending SMS.: ".$e->getMessage().";
	
	  $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>SMS was not sent!   </strong>   Error was Encountered  while sending SMS.'.$e->getMessage().'.Check your balance or internet availability then try again</div>');
								
								 redirect('user/viewsms');
    }
    // DONE!!! 
if(isset($usr_result)){

 $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 Sent SMS..</div>');	

								
								 redirect('user/viewsms');
		

}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> SMS  was not Sent.. Try a different group</div>');
								
								 redirect('user/viewsms');
		
	
	
	
}
}
						   
						   
						   
						   
						   
			
							
							//check if username and password is correct
			
					   }
					   else
					   {
							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> There is no any member who is active from the group you have selected.. Try again</div>');
								
								 redirect('user/viewsms');
	}
	}
 
 
 
 
 
 
  public function addloyality()
    {
		
			$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'];
		 
		 		
		 		 $value = $this->input->post("value");
				$cardnumber = $this->input->post("cardnumber");
		   	  $customer_id = $this->input->post("customer_id");
			   $description = $this->input->post("description");
		    
		
				
			  		  $this->form_validation->set_rules("cardnumber", "Card number ", "trim|required");
			  		  $this->form_validation->set_rules("value", "Amount ", "trim|required");

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

		
		 $this->load->view('userdata/viewcategory', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_addloyality') == "loyatity")
					   {
												$data=array(		
			'userid'=>$userid,
			'value'=>$value,
				'cardnumber'=>$cardnumber,
			
		  	'description'=>$description,
			'customer_id'=>$customer_id,
			
			'dateposted'=>$dateposted,
				
			
								);
							$usr_result = $this->accomodationmodel->add($data,'loyalitycards');
							
							//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 Created a new Loyality Point..</div>');	
							redirect('user/viewloyality');																
							}
							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> Loyality point  was not created.. Try again</div>');
								
								 redirect('user/viewloyality');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

	
	
  public function adddocuments()
    {
		
			$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'];
		 
		 			 $documentname = $this->input->post("documentname");
		 		 $documentname = $this->input->post("documentname");
				$idno = $this->input->post("idno");
		   	  $category = $this->input->post("category");
			   $description = $this->input->post("description");
		     $entrydate = $this->input->post("entrydate");
		
				
			  		  $this->form_validation->set_rules("category", "Category Name ", "trim|required");
			  		  $this->form_validation->set_rules("documentname", "Amount ", "trim|required");

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

		
		 $this->load->view('userdata/viewdocument', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_adddocuments') == "documents")
					   {
												$data=array(		
			'userid'=>$userid,
			'documentname'=>$documentname,
				'idno'=>$idno,
			
		  	'description'=>$description,
			'category'=>$category,
			'entrydate'=>$entrydate,
			'dateposted'=>$dateposted,
				
			
								);
							$usr_result = $this->accomodationmodel->add($data,'documents');
							
							//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 added a new document.</div>');	
							redirect('user/viewdocuments');																
							}
							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 document  was not created.. Try again</div>');
								
								 redirect('user/viewdocuments');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

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

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

		 $userid = $data['id'];
		 
		 		
					 $view = $this->input->post("view");
		 		 $amount = $this->input->post("amount");
				$type = $this->input->post("type");
			   $description = $this->input->post("description");
		    $user = $this->input->post("user");
		$datespent = $this->input->post("datespent");
				$controller = $this->input->post("controller");
				$idno = $this->input->post("idno");
				$contact = $this->input->post("contact");
				$receiptno = $this->input->post("receiptno");
				$img_id = $this->input->post("img_id");
				$houseno = $this->input->post("houseno");
				$plotno = $this->input->post("plotno");
		 		 $finalamount = ((-1)* ($amount));

			  		  $this->form_validation->set_rules("datespent", "Date of Expenditure ", "trim|required");
			  		  $this->form_validation->set_rules("amount", "Amount ", "trim|required");

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

		
		 $this->load->view('userdata/viewexpenses', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_addexpense') == "expense")
					   {
												$data=array(		
			'img_id'=>$img_id,
			'amount'=>$finalamount,
				'type'=>$type,
			'user'=>$user,
		  	'description'=>$description,
		'datespent'=>$datespent,
			
			'dateposted'=>$dateposted,
			'controller' =>$controller,
				'idno' =>$idno,
				'contact'=>$contact,
				'receiptno'=>$receiptno,
				'userid'=>$userid,
								'plotno'=>$plotno,
				'houseno'=>$houseno,
'companyid' => $companyid,
			
								);
							$usr_result = $this->accomodationmodel->add($data,'expenses');
							
							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
										 $file= trim($_FILES["photo"]['name']);
			
					if($file!=""){
						$this->uploadimage($view, $img_id,$userid);
						
					}
						
								 
						 $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 a new expense  ..</div>');	
								 redirect($view);
							
							}
							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> Expense  was not created.. Try again</div>');
								
								 redirect($view);
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

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

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

		 $userid = $data['id'];
		 
		 		
					 $view = $this->input->post("view");
		 		 $cash = $this->input->post("cash");
							   $name = $this->input->post("name");

			   $description = $this->input->post("description");
		    $user = $this->input->post("user");
		$entrydate = $this->input->post("entrydate");
				$controller = $this->input->post("controller");
				$idno = $this->input->post("idno");
				  $mpesa = $this->input->post("mpesa");		  
	  	        $cheque = $this->input->post("cheque");		  
	            $card = $this->input->post("card");	
		    	$voucher = $this->input->post("voucher");
		 			$credit = $this->input->post("credit");
							 			$discount = 0;

							 			$points = $this->input->post("points");
							 			$contact = $this->input->post("contact");
							 			$expense = $this->input->post("expense");


			  		  $this->form_validation->set_rules("entrydate", "Date of income ", "trim|required");
			  		  $this->form_validation->set_rules("controller", "Approver ", "trim|required");

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

		
		 $this->load->view('userdata/viewdailycollections', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_addcollections') == "collections")
					   {
												$data=array(		
				 	'companyid'=>$companyid,
			 'cash' => $cash,  
		  'mpesa' => $mpesa,    
		     'cheque' => $cheque,  
		     'card' => $card, 
			   'voucher' => $voucher, 
			   'credit' => $credit, 
				'points' => $points,
				'expense' => $expense,

								
		  	'description'=>$description,
		'entrydate'=>$entrydate,
			'createdat'=>$dateposted,
			
			'discount'=>$discount,
			'controller' =>$controller,
				'idno' =>$idno,
				'contact'=>$contact,
				'userid'=>$userid,
						'name'=>$name,	
			
								);
							$usr_result = $this->accomodationmodel->add($data,'dailycollections');
							
							//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 Added a new Income  ..</div>');	
								 redirect($view);
							
							}
							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> Income  was not created.. Try again</div>');
								
								 redirect($view);
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

   
   
   
   
	

	
		public function uploadimage($view, $img_id,$userid) {
    
    $file= $_FILES["photo"]['name'];

if($file!=""){
		
	  
	  
	  

		$config['upload_path'] = is_dir($file).'docs/';
  		$new_date=date('Y-m-d');
		$ext = explode(".", strtolower($file));
		 $ext = strtolower(end($ext));
					
     	 $new_name = $new_date.time().".".$ext;
	
		$config['file_name'] = $new_name;
        $config['overwrite'] = FALSE;
        $config["allowed_types"] = 'jpg|jpeg|png|gif|pdf|doc|docx';
        $config["max_size"] = 3024;
        $config['encrypt_name'] = FALSE;
      $this->load->library('upload', $config);
	  
	 

        if(!$this->upload->do_upload('photo')) {               
           echo  $this->data['error'] = $this->upload->display_errors();
           $this->session->set_flashdata('imagemsg', '<div class="alert alert-danger fade in">
						 <a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>Document could not be uploaded.. Please select correct image type  .e.g jpg,jpeg,png,gif.
						  </div>');
             redirect($view);
         
       
        } else {
				$data1=array(		
			'name'=>$new_name,
		  	'img_id'=>$img_id,
				'userid'=>$userid,
			
								);
		$usr_result1 = $this->accomodationmodel->add($data1,'alldocuments');
         if($usr_result1 ==TRUE){
		 		$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 Added adocument!</div>');
 redirect($view);
		 }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>Document could not be uploaded.. Please try again..
						  </div>');
		  redirect($view);
		 }
        



        }  


}



		
		}

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

    
      show_error('No identifier provided', 500);
    }
    else {
		$session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
     $itemid = $_GET['randomitemidentifier'];

        		$data['mydocuments'] = $this->accomodationmodel->populateall('alldocuments','img_id', $itemid);
   	

    	$this->load->view("template/headerpagemin", $data);
$data['itemid']=$itemid;
		
		 $this->load->view('userdata/viewmoredocs', $data);
		$this->load->view("template/footerpage");
		
	}
  }
	
   
   
   
  public function addsupplier()
    {
		
			$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'];
		 
		 		
 $firstname = $this->input->post("firstname");
$lastname = $this->input->post("lastname");
	  $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");   
				  $account = $this->input->post("account"); 
 $website = $this->input->post("website"); 
 $idno = $this->input->post("idno"); 
 $balance = $this->input->post("balance");  
				
			  		  $this->form_validation->set_rules("firstname", "First name", "trim|required");

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

		
		 $this->load->view('userdata/viewsuppliers', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_addsupplier') == "supplier")
					   {
												$data=array(		
			'userid'=>$userid,
			
				'firstname'=>$firstname,
			'lastname'=>$lastname,
		  	'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,   
				  'account' => $account, 
				 'website' => $website, 
				 'idno' => $idno, 
				 'balance' => $balance,  
			
			
			
								);
							$usr_result = $this->accomodationmodel->add($data,'people');
							
							//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 Added a new  Supplier..</div>');	
							redirect('user/viewsuppliers');																
							}
							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> Supplier  was not added.. Try again</div>');
								
								 redirect('user/viewsuppliers');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

 
 
 
 
 
 
 
 
 
 
 
 
 
 
	public function uploadlostfoundimage($imgid) {
    
    $file= $_FILES["photo"]['name'];
$imgid = $this->input->post("imgid");
if($file!=""){
		$photo = $this->input->post("photo");
		$config['upload_path'] = is_dir($photo).'alllostfound/';
  		$new_date=date('Ymd');
     	 $new_name = $new_date.time().$_FILES["photo"]['name'];
		$config['file_name'] = $new_name;
        $config['overwrite'] = FALSE;
        $config["allowed_types"] = 'jpg|jpeg|png|gif';
        $config["max_size"] = 1024;
        $config['encrypt_name'] = FALSE;
      $this->load->library('upload', $config);



        if(!$this->upload->do_upload('photo')) {               
           echo  $this->data['error'] = $this->upload->display_errors();
           $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in">
						 <a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong>Image could not be uploaded.. Please select correct image type  .e.g jpg,jpeg,png,gif.
						  </div>');
             redirect('user/viewproducts');
         
       
        } else {
				$data1=array(		
			'name'=>$new_name,
		  	'imgid'=>$imgid,
			
			
								);
		$usr_result1 = $this->systemaccomodationmodel->uploadimage($data1,$imgid);
         if($usr_result1 ==TRUE){
		 		$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 made a post!</div>');
 redirect('user/viewproducts');
		 }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>Image could not be uploaded.. Please try again  ..........
						  </div>');
		 
		 }
        



        }  


}



		
		}
 
 
 
 
 
 
 
 
   public function addmember()
    {
		
			$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'];
		 
		 		
 $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");   
				  
 $website = $this->input->post("website"); 
 $idno = $this->input->post("idno"); 
 
				
			  		  $this->form_validation->set_rules("firstname", "First name", "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")
					   {
						   
						   
						   
						   
												$data=array(		
			'userid'=>$userid,
			
				'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, 
				 
			
			
			
								);
							$usr_result = $this->accomodationmodel->add($data,'people');
							
							//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 Added a new  Member..</div>');	
							redirect('user/viewmember');																
							}
							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('user/viewmember');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }
 
  public function updatemember()
    {
		
			$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'];
		 
		  $myid = $this->input->post("myid");		
 $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");   
				  
 $website = $this->input->post("website"); 
 $idno = $this->input->post("idno"); 
 
				
			  		  $this->form_validation->set_rules("firstname", "First name", "trim|required");

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

		
		 $this->load->view('userdata/editmember', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_addmember') == "member")
					   {
						   
						   
						   
						   
												$data=array(		
			'userid'=>$userid,
			
				'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, 
				 
			
			
			
								);
							$usr_result = $this->accomodationmodel->updatemember($data,$myid) ;
							
							//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 data..</div>');	
						 redirect('user/viewmember');																
							}
							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> Data  was not updated.. Try again</div>');
								
								 redirect('user/editmember?randomitemidentifier='.$myid);
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

 
 
 
  public function addemployee()
    {
		
			$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'];
		 
		 		
 $firstname = $this->input->post("firstname");
$lastname = $this->input->post("lastname");
	  $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");   
				  $account = $this->input->post("account"); 
 $website = $this->input->post("website"); 
 $idno = $this->input->post("idno"); 
 $balance = $this->input->post("balance");  
				
			  		  $this->form_validation->set_rules("firstname", "First name", "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_addemployee') == "employee")
					   {
												$data=array(		
			'userid'=>$userid,
			
				'firstname'=>$firstname,
			'lastname'=>$lastname,
		  	'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,   
				  'account' => $account, 
				 'website' => $website, 
				 'idno' => $idno, 
				 'balance' => $balance,  
			
			
			
								);
							$usr_result = $this->accomodationmodel->add($data,'people');
							
							//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 Added a new  Supplier..</div>');	
							redirect('user/viewemployees');																
							}
							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> Supplier  was not added.. Try again</div>');
								
								 redirect('user/viewemployees');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }
 public function addtasks()
    {
		
			$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'];
		 
 	 		
 $taskowner = $this->input->post("taskowner");
$subject = $this->input->post("subject");
	  $fromdate = $this->input->post("fromdate");
	  $todate = $this->input->post("todate");		  
		  $contact = $this->input->post("contact");    
		 $status = $this->input->post("status");   
		  $controller = $this->input->post("controller");   
		   $priority = $this->input->post("priority");   
		    $notification = $this->input->post("notification");   
			 $comments = $this->input->post("comments");   
			  $repeated = $this->input->post("repeated");   
			     
			    $status = $this->input->post("status");   
				  
  
				
			  		  $this->form_validation->set_rules("taskowner", "Task Person", "trim|required");

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

		
		 $this->load->view('userdata/viewsuppliers', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_addtask') == "task")
					   {
												$data=array(		
			'userid'=>$userid,
			
				'taskowner'=>$taskowner,
			'subject'=>$subject,
		  	'fromdate'=>$fromdate,
			
			
			'dateposted'=>$dateposted,
			'todate' => $todate,		  
		  'contact' => $contact,    
		 'status' => $status,   
		  'controller' => $controller,   
		   'priority' => $priority,   
		    'notification' => $notification,   
			 'comments' => $comments,   
			  
			   
			    'status' => $status,  
			   
				
			
			
			
								);
							$usr_result = $this->accomodationmodel->add($data,'tasks');
							
							//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 Added a new  Task..</div>');	
							redirect('user/viewgrouping');																
							}
							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> Task  was not added.. Try again</div>');
								
								 redirect('user/viewgrouping');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

 
 public function addevents()
    {
		
			$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'];
		 
 	 		
 $location = $this->input->post("location");
$title = $this->input->post("title");
	  $fromdate = $this->input->post("fromdate");
	  $todate = $this->input->post("todate");		  
		  $host = $this->input->post("host");    
		    
		  $participants = $this->input->post("participants");   
		     
			 $comments = $this->input->post("comments");   
			  $repeated = $this->input->post("repeated");   
			     
			    $status = $this->input->post("status");   
				  
  
				
			  		  $this->form_validation->set_rules("location", "Task Location", "trim|required");

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

		
		 $this->load->view('userdata/viewevents ', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_addevent') == "event")
					   {
												$data=array(		
			'userid'=>$userid,
			
				'location'=>$location,
			'title'=>$title,
		  	'fromdate'=>$fromdate,
			
			
			'dateposted'=>$dateposted,
			'todate' => $todate,		  
		  'host' => $host,    
		 'status' => $status,   
		  'participants' => $participants,   
		   
			 'comments' => $comments,   
			  
			       'repeated' => $repeated,  
			    'status' => $status,  
			   
				
			
			
			
								);
							$usr_result = $this->accomodationmodel->add($data,'events');
							
							//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 Added a new  Event..</div>');	
							redirect('user/viewevents');																
							}
							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> Event  was not added.. Try again</div>');
								
								 redirect('user/viewevents');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }
 
 
 
 
  public function addsale()
    {
		
			$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'];
		 
 	 		
 $code = $this->input->post("code");
$qty = $this->input->post("qty");
	  $discount = $this->input->post("discount");
	  $mode = $this->input->post("mode");		  
		  $type = $this->input->post("type");    
		    
		      $invoice = $this->input->post("invoice"); 
				        $productname = $this->accomodationmodel->geteproductbyid($code);
  
     $sellingprice=$productname[0]['sellingprice']; 
  $amount= (($sellingprice*$qty)- $discount);
				
			  		  $this->form_validation->set_rules("code", "Product code", "trim|required");

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

		
		 $this->load->view('userdata/viewsales ', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_addsale') == "sale")
					   {
												$data=array(		
			'userid'=>$userid,
			
				'code'=>$code,
			'qty'=>$qty,
		  	'discount'=>$discount,
			
			
			'dateposted'=>$dateposted,
			'mode' => $mode,		  
		  'type' => $type,    
		     'invoice' => $invoice,  
		    'sprice' => $sellingprice, 
			      'amount' => $amount, 
			   
				
			
			
			
								);
							$usr_result = $this->accomodationmodel->add($data,'sales_order');
							
							//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 Added a new  Sales..</div>');	
							redirect('user/viewsales');																
							}
							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> Sales  was not added.. Try again</div>');
								
								 redirect('user/viewsales');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }
 
 
 
 
 
 
 
 public function savesales()
    {
		
			$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'];
		 
 	 		
 $type = $this->input->post("type");
$customer = $this->input->post("customer");
	  $cash = $this->input->post("cash");
	  $total = $this->input->post("total");		  
	  
		    
		      $invoice = $this->input->post("invoice"); 
			
  $balance= ($total- $cash);
			  		  $this->form_validation->set_rules("cash", "Amount Paid ", "trim|required");

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

		
		 $this->load->view('userdata/viewsales ', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_savesales') == "sales")
					   {
												$data=array(		
			'userid'=>$userid,
			
				'type'=>$type,
			'customer'=>$customer,
		  	'cash'=>$cash,
			
			
			'dateposted'=>$dateposted,
			'total' => $total,		  
		  'type' => $type,    
		     'invoice' => $invoice,  
		     'balance' => $balance, 
			   
				
			
			
			
								);
							$usr_result = $this->accomodationmodel->add($data,'sales');
							
							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
								
								 
						 $this->session->set_flashdata('salestmsg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
								<strong>Success!</strong> You have successfully Completed a new  Sales..</div>');	
																			
							
							 
							            redirect("user/printreceipts?invoice=". $invoice."");

							
							}
							else if ($usr_result ==FALSE) 
							{     

			 $this->session->set_flashdata('salestmsg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Sales  was not Completed.. Try again</div>');
								
								 redirect('user/viewsales');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }
 
 
 
 
 public function printreceipts() {
   if (!isset($_GET['invoice'])){

    
      show_error('No identifier provided', 500);
    }
    else {
     $invoiceid = $_GET['invoice'];
 
 $data['setting'] = $this->accomodationmodel->getsetting();
 $data['viewreceipt'] = $this->accomodationmodel->populateinvoice($invoiceid);
  $data['viewsales'] = $this->accomodationmodel->getesales_order($invoiceid);
	 $this->load->view("template/headerpagemin");
				
						$this->load->view('userdata/printreceipt', $data);
		
	}
  }
 
 
 
  public function adddeals()
    {
		
			$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'];
		 
 	 		
 $owner = $this->input->post("owner");
$title = $this->input->post("title");
	  $fromdate = $this->input->post("fromdate");
	  $todate = $this->input->post("todate");		  
		  $contact = $this->input->post("contact");    
		 $type = $this->input->post("type");   
		  $nextstep = $this->input->post("nextstep");   
		     
			 $comments = $this->input->post("comments");   
			  $source = $this->input->post("source");   
			     
			   
				 $contactname = $this->input->post("contactname");  
					$amount = $this->input->post("amount"); 
						$probability = $this->input->post("probability"); 
					$expectedrevenue	 = $this->input->post("expectedrevenue"); 
					$stage	 = $this->input->post("stage"); 

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

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

		
		 $this->load->view('userdata/viewdeals ', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_adddeal') == "deal")
					   {
												$data=array(		
			'userid'=>$userid,
			
				'owner'=>$owner,
			'title'=>$title,
		  	'fromdate'=>$fromdate,
			
			
			'dateposted'=>$dateposted,
			'todate' => $todate,
			'fromdate' => $fromdate,
			'type' => $type,			
		  'contact' => $contact,    
		   
		  'nextstep' => $nextstep,   
		   
			 'comments' => $comments,   
			  
			   
			   
			   'contactname' => $contactname,  
				'amount' => $amount, 
				'probability' => $probability,
					'expectedrevenue' => $expectedrevenue,
						'stage' => $stage,
			
								);
							$usr_result = $this->accomodationmodel->add($data,'deals');
							
							//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 Added a new  Deal..</div>');	
							redirect('user/viedeals');																
							}
							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> Deal  was not added.. Try again</div>');
								
								 redirect('user/viedeals');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }
 
  public function studentbio() {


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

     $data['username'] = $session_data['username'];
 	$data['id'] = $session_data['id'];
 		$data['firstname'] = $session_data['firstname'];
 			$data['surname'] = $session_data['surname'];
 		
 			
 	$surname= $data['surname'] ;
	$id= $data['id'] ;
	$studentid= $data['id'] ;

$data['province'] = $this->provincemodel->populateprovince();
	
	$data['district'] = $this->districtmodel->populatedistrict();
	$data['county'] = $this->countymodel->populatecounty();
	$data['nation'] = $this->nationmodel->populatenation();



	
	$biodata['student']= $this->studentcontactmodel->populatestudent($studentid);
	$biodata['bio']= $this->systemaccomodationmodel->populatebiodata($studentid);

	$this->load->view("template/headerpagemin");
	
		
		 $this->load->view('userdata/biodata', $biodata,$data);
		$this->load->view("template/footerpage");


     
    }


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

     $data['surname'] = $session_data['surname'];
 	$data['id'] = $session_data['id'];
	
	 	$this->load->view("template/headerpagemin");
		
		
		$this->load->view('userdata/sportclubdata', $data);
		$this->load->view("template/footerpage");
     
    }
	 
     public function document() {
	 
	$session_data = $this->session->userdata('logged_in');

     $data['surname'] = $session_data['username'];
 	$data['id'] = $session_data['id'];
	$id=$data['id'];
	 	$this->load->view("template/headerpagemin");
		$data['documets'] = $this->systemaccomodationmodel->populatedocumets($id);
		
		$this->load->view('userdata/document', $data);
		$this->load->view("template/footerpage");
     
    }
	
	  public function adddocument1() {
	$session_data = $this->session->userdata('logged_in');

     $data['username'] = $session_data['username'];
 	$data['id'] = $session_data['id'];
	
	 	$this->load->view("template/headerpagemin");
	
		
		$this->load->view('userdata/schoolbackground', $data);
		$this->load->view("template/footerpage");
     
    }

  public function updatecategory()
    {
		
			$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:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
		 $userid = $data['id'];
		  $companyid = $data['companyid'];
		 		
		 		 $name = $this->input->post("name");
		 		 $mycategoryid = $this->input->post("mycategoryid");

		   	  $description = $this->input->post("description");
			  
		    
		
				
			  		  $this->form_validation->set_rules("name", "Product name", "trim|required");

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

		
		 $this->load->view('userdata/viewcategory', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_updatecategory') == "category")
					   {
												$data=array(		
			'userid'=>$userid,
			
				'name'=>$name,
			
		  	'description'=>$description,
			 	'companyid'=>$companyid,
			
			'createdate'=>$dateposted,
				
			
								);
														$usr_result = $this->accomodationmodel->updatedata($data,'category','id',$mycategoryid);


														
							//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 category..</div>');	
							redirect('user/viewcategory');																
							}
							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> Category  was not Updated.. Try again</div>');
								
								 redirect('user/viewcategory');
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }

 
 
 
 
 
 
 
 
	
	public function adddocument(){

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

     $data['username'] = $session_data['username'];
 	$data['id'] = $session_data['id'];
//$session_user=$_SESSION['id'];
$currentdate = date('Y:m:d h:i sa');
$new_date=date('Ymd');
$user="user";   
    if(!empty($_FILES['document']['tmp_name']))
    {
        $filepath="";
				
        for($i=0; $i<count($_FILES['document']['name']); $i++) 
        {
               $tmpFilePath = $_FILES['document']['tmp_name'][$i]; 
			 $documentname = $this->input->post("documentname");					  

               if ($tmpFilePath ==true)
               {  

					$image_size= getimagesize($_FILES['document']['tmp_name'][$i]);
				
					if(($tmpFilePath)==true)
					{			   
						   $path = "studentdocs/"; // create folder 
						   $name = $_FILES['document']['name'][$i];
						  $size = $_FILES['document']['size'][$i];
                        
							$ext = explode("/", strtolower($name));
						  $ext = strtolower(end($ext));
				
						  $filename = rand(100, 9900) . '_' . time()  . $ext;
						 
										   
						   
						   
						   if(move_uploaded_file($_FILES['document']['tmp_name'][$i], $path.$filename)) 
						   { $studentid1 = $this->input->post("studentid");
						//var_dump ($documentname);
				    				$filepath = $path . $filename;
											  			  	//var_dump ($filepath);
								$data = array(
	    'document' =>$filename,
	   'documentname' =>$documentname[$i],

		'studentid'=>$studentid1,
		'createddate'=>$new_date,
		
		
             );
									$usr_result = $this->systemaccomodationmodel->uploaddstudentocument($data);
							
							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
								
								
												 			  $statusdata=array(
		'step6'=>'complete',
		
							);
								 $this->systemaccomodationmodel->updatestudentstatus($statusdata,$studentid1); 
								
								 
						 $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 Uploaded your documents .but make sure all admission documents are uploaded..!</div>');
								
								 redirect('student/documents');
							}
							else
							{     

						 $this->session->set_flashdata('msg1', '<div class="alert alert-danger fade in">
						 <a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> You have not been able to upload your documents. try again</div>');
								
								 redirect('student/documents');
							}
								
							
							}
									 
					}else	
						{
								echo "that is not an image...Select correct image";
						} 
					 
					 
				}
		 
		}
if(($tmpFilePath)==false)
										{
					echo "please select an image first";
										}
		
    }
	
	}
	
	
	
	
		
			 public function registerstudentbio()
    {
          //get the posted values
		   	  $firstname = $this->input->post("firstname");
		  	 $surname = $this->input->post("surname");
			
       
		    $idno = $this->input->post("idno");
		     $country = $this->input->post("country");
			   $county = $this->input->post("county");
			 
		  	 $dob = $this->input->post("dob");
         
         	 $gender = $this->input->post("gender");

		 
         	 $province = $this->input->post("province");
		   	$email = $this->input->post("email");
			  $phone = $this->input->post("phone");
		  	 $gender = $this->input->post("gender");
			 
         	 $box = $this->input->post("box");
         	 $code = $this->input->post("code");
		   	$town = $this->input->post("town"); 
		
	
		 
 		$id = $this->input->post("id");

		
	

		  
		
			$this->form_validation->set_rules('surname', 'Surname', 'trim|required|min_length[2]|max_length[25]|xss_clean');
			$this->form_validation->set_rules('firstname', 'first name', 'trim|required|min_length[2]|max_length[35]|xss_clean');

       		$this->form_validation->set_rules("idno", "Id Number", "trim|required|min_length[8]|max_length[13]|numeric|xss_clean");
			
			
			

			
					$this->form_validation->set_rules('code', 'Town Code', 'trim|required|min_length[2]|numeric|max_length[60]|xss_clean');
			$this->form_validation->set_rules('email', 'Email Account', 'trim|required|valid_email|min_length[5]');
								$this->form_validation->set_rules('town', 'Town Name', 'trim|required|min_length[2]|max_length[60]|xss_clean');

					$this->form_validation->set_rules('phone', 'Mobile Number', 'trim|required|min_length[10]|numeric|max_length[15]|xss_clean');

						$this->form_validation->set_rules('box', 'Box Number', 'trim|required|min_length[1]|max_length[25]|xss_clean');

			
			$data['province'] = $this->provincemodel->populateprovince();
	
	$data['county'] = $this->countymodel->populatecounty();
	$data['nation'] = $this->nationmodel->populatenation();




	$biodata['bio']= $this->systemaccomodationmodel->populatebiodata($id);
			
			
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      // redirect('student/biodataform');
	  
	   $this->load->view("template/headerpagemin");
	
		
		 $this->load->view('userdata/biodata', $biodata,$data);
		$this->load->view("template/footerpage");

	   
		}
		 else
		{
					   //validation succeeds
					   if ($this->input->post('btn_savebio') == "registerbio")
					   {
								
								$data=array(
								
								
			'firstname'=>$firstname,
		  	'surname'=>$surname,
			
         
		    'idno'=>$idno,
		    'country' =>$country,
		  	 'dob'=>$dob,
         	
         	 'gender'=>$gender,
		   	
         	'province' =>$province,
		 	 'email'	=>$email,
			 'phone' =>$phone,
		  	'gender' =>$gender,
         	'box' =>$box,
         	 'code'=>$code,
		   	'town'	=>$town, 
			'county'	=>$county, 
			
		 'country'	=>$country, 
			
		   
         	
		 	
								);


								
								
								
								$usr_result = $this->systemaccomodationmodel->addstudentbio($data,$id);
							
							//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 your bio data.</div>');
							redirect('user/mydata'); 	
								 
							}
							else if ($usr_result ==FALSE) 
							{     
 redirect('addstudentbio');
						 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in">
						 <a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Data are not saved.. Try again</div>');
								
								
							}
					   }
					   else
					   {
							redirect('login');
					   }
	    }
    }
		
		
 
    public function logout() {
	
        $data = ['id', 'email'];
        $this->session->unset_userdata('logged_in');
		session_destroy();

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