<?php
ob_start();

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

class Admincontrollerpage extends CI_Controller {


		function __construct() {

        parent::__construct();

        $this->load->database();
            
			
			        	$this->load->model('provincemodel','',TRUE);
			        	

  $this->load->model('studentbiodatamodel','',TRUE);
   $this->load->model('studentprofilemodel','',TRUE);
   
  $this->load->model('schoolmodel','',TRUE);

				
	


		$this->load->model('usermodel','',TRUE);
	
		$this->load->model('districtmodel','',TRUE);
		$this->load->model('countymodel','',TRUE);
		$this->load->model('nationmodel','',TRUE);
	
		$this->load->model('adminusermodel','',TRUE);
		$this->load->model("adminusermodel", "login",TRUE);
     if(($this->session->userdata('adminadminlogged_in')=="")) {
            $this->session->set_flashdata('flash_data', 'You don\'t have access!');
            redirect('administrator');
        }

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

    
      show_error('No identifier provided', 500);
    }
    else {
		 $this->load->view("template/adminheaderpage");
		 	 $this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		$session_data = $this->session->userdata('logged_in');

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

        		$data['member'] = $this->adminusermodel->populateuser($itemid);
   

    
$data['itemid']=$itemid;
		
		 $this->load->view('admindata/bulkupdate', $data);
		$this->load->view("template/footerpage");
		
	}
  }
  
  
	 
public	function formatMoney($number, $fractional=false) {
						if ($fractional) {
							$number = sprintf('%.2f', $number);
						}
						while (true) {
							$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1$2', $number);
							if ($replaced != $number) {
								$number = $replaced;
							} else {
								break;
							}
						}
						return $number;
					}
						
 
  
  
  
	
	public function addfilemovement()
    {
		
		$session_data = $this->session->userdata('adminlogged_in');
		$type = $session_data['type'];
$adminid = $session_data['adminid'];
$createddate=date('Y-m-d');
        	 $name = $this->input->post("name");
		   	  $category = $this->input->post("category");
		  	 $subject = $this->input->post("subject");
         
          $receiver = $this->input->post("receiver");
		   $regno = $this->input->post("regno");
 			   $sender = $this->input->post("sender");
			    $category = $this->input->post("category");
					 $officer = $this->input->post("officer");
		   	  $actualdate = $this->input->post("actualdate");
		  	 $remarks = $this->input->post("remarks");
         

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

          //set validations
 			   		  	 $this->form_validation->set_rules("sender", "ID Number", "trim|required");

							$this->form_validation->set_rules('name', 'name', 'trim|required|min_length[2]|max_length[25]|xss_clean');
							$this->form_validation->set_rules('category', 'Other name', 'trim|required|min_length[2]|max_length[35]|xss_clean');

          	
			
			
			
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
			 redirect('admin/staffs');
		}
		 else
		{
			
					   //validation succeeds
					   if ($this->input->post('btn_addfilemovement') == "file")
					   {
								
								$data=array(
								'category'=>$category,
								'subject'=>$subject,
								'name'=>$name,
								'category'=>$category,
									'receiver'=>$receiver,
								'regno'=>$regno,
									'sender'=>$sender,
									'addedby'=>$adminid,

								'foliono'=>$foliono,


									'actualdate'=>$actualdate,
								'remarks'=>$remarks,
								'officer'=>$officer,			
								
									'createddate'=>$createddate,
								
								);
													$usr_result = $this->usermodel->add($data,'filemovement');

							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
											
						   	$this->session->set_flashdata('signupmsg', '<div class="alert alert-info fade in"><a href="#" class="close" data-dismiss="alert">&times;</a><strong>Success!</strong><br>You have  successfully added new staff.. </strong></div>');

				 	 redirect('admin/staffs');
							
								
							}
							else
							{     

						 $this->session->set_flashdata('signupmsg', '<div class="alert alert-danger fade in">
						 <a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Account not created.. It coud be that your ID Number number  already exisist! </div>');
								
								 redirect('admin/staffs');
							}
					   }
					   else
					   {
							redirect('admin');
					   }
	    }
    }
	
	
	
	
	
	
  
    public function recharge() {
   if (!isset($_GET['randomitemidentifier'])){

    
      show_error('No identifier provided', 500);
    }
    else {
		 $this->load->view("template/adminheaderpage");
		 	 $this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		$session_data = $this->session->userdata('logged_in');

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

        		$data['recharge'] = $this->adminusermodel->populateuser($itemid);
   

    
$data['itemid']=$itemid;
		
		 $this->load->view('admindata/recharge', $data);
		$this->load->view("template/footerpage");
		
	}
  }
  
  
	public function postpayment()
    {
		
			$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 ;
	
		  $userid = $this->input->post("userid");
	  $companyid = $this->input->post("companyid");		  
		  $amount = $this->input->post("amount");    
		 $code = $this->input->post("code"); 
		 		 $description = $this->input->post("description"); 

			
				 $rate = $this->input->post("rate");    
		 $units = $this->input->post("units"); 
		 		
				
			  		  $this->form_validation->set_rules("amount", "Amount", "trim|required");

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

		
		 $this->load->view('admindata/recharge', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   
					   
					   
					   	if ($this->input->post('btn_postpayment') == "volume")
					   {
						   
						   $finalvolume=  ($amount/$rate);
						   $finalvolume=  $this->formatMoney($finalvolume, true);
						   redirect('admin/recharge?randomitemidentifier='.$userid."&finalvolume=".$finalvolume."&amount=".$amount."&description=".$description."&code=".$code."&rate=".$rate);	
						   
					   }else 	if ($this->input->post('btn_postpayment') == "payment")
					   {
						   
						           		$getpayments = $this->adminusermodel->populateuser($userid);
										
										 $finalvolume=  ($amount/$rate);
																		$finalvolume= $this->formatMoney($finalvolume, true);


					$available=$getpayments[0]["totalsms"];
					$finalbalance=$finalvolume+$available;

						   
												$finaldata=array(		
		
			
			
		  	'totalsms'=>$finalbalance,
				 

			
		  
								);
												$data=array(		
		
			
				'companyid'=>$companyid,
				'balance'=>$finalbalance,
		  	'amount'=>$amount,
					  	'units'=>$units,
					  	'balancebefore'=>$available,

				'description'=>$description,
			'code' => $code,		  
		  'dateposted' => $dateposted,    
					 'userid' => $userid, 
	 'rate' => $rate, 
			
		  
								);
						
								$usr_result = $this->usermodel->updatedata($finaldata,'people','id',$userid);

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

								 
						 $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 posted the payment..</div>');	
						 redirect('admin/recharge?randomitemidentifier='.$userid);																
							}
							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 payment could not be posted. Try again</div>');
								
						 redirect('admin/recharge?randomitemidentifier='.$userid);																
							}
					   }
					   else
					   {
							redirect('admin');
					   }
	    }
    }
	
	
  public function updateaccount()
    {
		
			$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 ;
	
		  $userid = trim($this->input->post("userid"));
	  
		 $code = trim($this->input->post("code")); 
		 		 $module = trim($this->input->post("module")); 

				
				
				
			  		  $this->form_validation->set_rules("code", "Company Code", "trim|required");

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

		
		 $this->load->view('admindata/bulkupdate', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_updateaccount') == "account")
					   {
						   		   $confirmaccount= $this->usermodel->confirmaccountcode($code);

				   if ($confirmaccount ==false)
						   {
							    $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!  </strong>That Entry Number  does not exist in our database. try again</div>');
								
								 redirect('admin/bulkupdate?randomitemidentifier='.$userid);
								
						   
						   return false;
						   }
									$mycompanyid=trim($confirmaccount[0]->id);
									
									
						   
						   
						   
												$data=array(		
					
				'companyid'=>$mycompanyid,
			 
		   
								);
								
								
						if($module =="1"){
						$usr_result = $this->usermodel->updatedata($data,'category','userid',$userid);

							
						}else  if($module =="2"){
						$usr_result = $this->usermodel->updatedata($data,'people','userid',$userid);

							
						}
						else if($module =="3"){
						$usr_result = $this->usermodel->updatedata($data,'events','userid',$userid);

							
						}else if($module ="4"){
						$usr_result = $this->usermodel->updatedata($data,'sms','userid',$userid);

							
						}else  if($module =="5"){
						$usr_result = $this->usermodel->updatedata($data,'email','userid',$userid);

							
						}else  if($module =="6"){
						$usr_result = $this->usermodel->updatedata($data,'grouping','userid',$userid);

							
						}else  if($module =="7"){
							
						$usr_result = $this->usermodel->updatedata($data,'user','id',$userid);

							
						}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> The data   was not updated.. Kindly select correct range.</div>');
								
								 redirect('admin/bulkupdate?randomitemidentifier='.$userid);
						}

							//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('admin/bulkupdate?randomitemidentifier='.$userid);
							}
							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 data   was not updated.. Try again</div>');
								
								 redirect('admin/bulkupdate?randomitemidentifier='.$userid);
							}
					   }
					   else
					   {
							redirect('admin');
					   }
	    }
    }
  
	
	
	
	
	
	
	
	
	
  
function populateuser($id){

if($id!=null){
$this->db->select(" * from user where id='$id' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

  return $bioquery->result_array();
 
}else{

  return false;
}

}else{
 return false;	
}


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

    
      show_error('No identifier provided', 500);
    }
    else {
		 $this->load->view("template/adminheaderpage");
		 	 $this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		$session_data = $this->session->userdata('adminadminlogged_in');

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

        		$data['member'] = $this->adminusermodel->populateuser($itemid);
   

    
$data['itemid']=$itemid;
		
		 $this->load->view('admindata/edituser', $data);
		$this->load->view("template/footerpage");
		
	}
  }

		public function viewallusers()
	{ 
		 $this->load->view("template/adminheaderpage");
		 	 $this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		 $data['allusers'] = $this->adminusermodel->populateallusers();


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

		public function viewcompany()
	{ 
		 $this->load->view("template/adminheaderpage");
		 	 $this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		$data['viewcompany']= $this->usermodel->populatealldata(' smsconfig','id','DESC');


				$this->load->view('admindata/viewcompany',$data);
		$this->load->view("template/footerpage");
	}
		public function viewmodules()
	{ 
		 $this->load->view("template/adminheaderpage");
		 	 $this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		$data['module']= $this->usermodel->populatealldata('modules','sort','ASC');



				$this->load->view('admindata/viewmodules',$data);
		$this->load->view("template/footerpage");
	}
	
	public function viewmenu()
	{ 
		 $this->load->view("template/adminheaderpage");
		 	 $this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		$data['module']= $this->usermodel->populatealldata('mainmenu','sort','ASC');



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

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

     $itemid = $_GET['randomitemidentifier'];

   
        
	
        		$data['configuration'] = $this->usermodel->populateallarray('smsconfig','id',$itemid);
 $this->load->view("template/adminheaderpage");
        	
$this->load->view("template/adminnave");
$data['userid']=$itemid;
		 $this->load->view('admindata/configuration', $data);
		$this->load->view("template/footerpage");
		
	}
  }
  
  
  
  
  
  
  public function editmodules() {
	  if (!isset($_GET['randomitemidentifier'])){

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

     $itemid = $_GET['randomitemidentifier'];

   
        
	
        		$data['module'] = $this->usermodel->populateallarray(' modules','id',$itemid);
 $this->load->view("template/adminheaderpage");
        	
$this->load->view("template/adminnave");
$data['userid']=$itemid;
		 $this->load->view('admindata/editmodules', $data);
		$this->load->view("template/footerpage");
		
	}
  }
  
  
  
  
  
  
  
  
  
  
  
  
	public function updateconfiguration()
    {
		
			$session_data = $this->session->userdata('adminadminlogged_in');
  $data['adminid'] = $session_data['adminid'];
	 $userid = $data['adminid'];
   
 	$data['adminid'] = $session_data['adminid'];
         $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
	
		  $username = $this->input->post("username");
	  $password = $this->input->post("password");		  
		  $from = $this->input->post("from");    
		 $code = $this->input->post("code"); 
		 		 $apikey = $this->input->post("apikey"); 

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

	  $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"); 
				
			$description = $this->input->post("description");
			$returnpolicy = $this->input->post("returnpolicy");		  
		  $paymenttypes = $this->input->post("paymenttypes");    
		 $logo = $this->input->post("logo");   
				








$validationurl = $this->input->post("validationurl");   
		  $confirmationurl = $this->input->post("confirmationurl");   
		   $totalsms = $this->input->post("totalsms");   
		    $shortcode = $this->input->post("shortcode");   
			 $responseType = $this->input->post("responseType");   
			  $consumer_key = $this->input->post("consumer_key");   
			   $consumer_secret = $this->input->post("consumer_secret");   
			    $signature = $this->input->post("signature");   
				  



      






					
				
				
				
			  		  $this->form_validation->set_rules("businessname", "First name", "trim|required");

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

		
		 $this->load->view('admindata/configuration', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_updateconfig') == "config")
					   {
						   
						   
						 
						   
												$data=array(		
		
			
				'businessname'=>$businessname,
			
		  	'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, 
		
					 
		  	'code'=>$code,
				'username'=>$username,
			'password' => $password,		  
		  'from' => $from,   
		  'apikey' => $apikey,  
			'validationurl'=>$validationurl,
			'confirmationurl' => $confirmationurl,		  
		  'totalsms' => $totalsms,    
		 'shortcode' => $shortcode,   
		  'responseType' => $responseType,   
		   'consumer_key' => $consumer_key,   
		    'consumer_secret' => $consumer_secret,   
			 'signature' => $signature,  

		  
								);
						
								$usr_result = $this->usermodel->updatedata($data,'smsconfig','id',$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 Company settings..</div>');	
						 redirect('admin/viewcompany');																
							}
							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/viewcompany');
							}
					   }
					   else
					   {
							redirect('admin');
					   }
	    }
    }
	
		public function viewmodulesactions()
	{ 
		 $this->load->view("template/adminheaderpage");
		 	 $this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		$data['viewmodulesactions']= $this->usermodel->populatealldata('modulesactions','sort','ASC');



				$this->load->view('admindata/viewmodulesactions',$data);
		$this->load->view("template/footerpage");
	}
	
	
	
	
	
	
	 public function addmodule()
    {
		
		
         $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
		
		 
 	 		
 $code = trim($this->input->post("code"));
$name =  trim($this->input->post("name"));
	  $url =  trim($this->input->post("url"));
	  $icon =  trim($this->input->post("icon"));		  
		  $sort =  trim($this->input->post("sort"));    
		    
		  $type = trim( $this->input->post("type"));   
		     
			
			
  
				
			  		  $this->form_validation->set_rules("code", "Module code", "trim|required");
				$confirm_module = $this->usermodel->confirmmodule($code, $url);
			
			  
			    if($confirm_module){
				 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Dublicate Error!</strong> This module had been assigned . Try a diffrent module  </div>');
								
								redirect('admin/viewmodules' );	
								return false;
			  }
				
			  
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
			 $this->load->view("template/headerpage");
				$this->load->view("template/adminnave");
     
	 
		 $this->load->view('admindata/viewmodules ', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_module') == "module")
					   {
												$data=array(		
		
		
			
				'id'=>$code,
			'name'=>$name,
		  	'url'=>$url,
			
			
			'icon' => $icon,		  
		  'sort' => $sort,    
		
		  'type' => $type,   
		  
		  
			   
				
			
			
			
								);
							$usr_result = $this->usermodel->add($data,'modules');
							
							//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  module..</div>');	
							redirect('admin/viewmodules');																
							}
							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> module  was not added.. Try again</div>');
								
								 redirect('admin/viewmodules');
							}
					   }
					   else
					   {
							redirect('admin');
					   }
	    }
    }
 
 

				 
			
	
	 public function addmenu()
    {
		
		
         $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
		
		 
 	 		
 $code = trim($this->input->post("code"));
$name =  trim($this->input->post("name"));
	  $url =  trim($this->input->post("url"));
	  $icon =  trim($this->input->post("icon"));		  
		  $sort =  trim($this->input->post("sort"));    
		    
		  $type = trim( $this->input->post("type"));   
		     
			
			
  			  		  $this->form_validation->set_rules("name", "Menu name", "trim|required");

				
			  
			  
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
			 $this->load->view("template/headerpage");
				$this->load->view("template/adminnave");
     
	 
		 $this->load->view('admindata/viewmenu', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_menu') == "menu")
					   {
												$data=array(		
		
		
			
				'id'=>$code,
			'name'=>$name,
		  	'url'=>$url,
			
			
			'icon' => $icon,		  
		  'sort' => $sort,    
		
		  'type' => $type,   
		  
		  
			   
				
			
			
			
								);
							$usr_result = $this->usermodel->add($data,'mainmenu');
							
							//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  menu..</div>');	
							redirect('admin/viewmenu');																
							}
							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> Menu  was not added.. Try again</div>');
								
								 redirect('admin/viewmenu');
							}
					   }
					   else
					   {
							redirect('admin');
					   }
	    }
    }
 
 	 
		 
		
	
	 public function updatemodule()
    {
		
		
         $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
		
		  $menu = trim($this->input->post("menu"));

 	 		
 $myid = trim($this->input->post("code"));
$name =  trim($this->input->post("name"));
	  $url =  trim($this->input->post("url"));
	  $icon =  trim($this->input->post("icon"));		  
		  $sort =  trim($this->input->post("sort"));    
		    
		  $type = trim( $this->input->post("type"));   
		       $status = trim( $this->input->post("status")); 
			
			
  
				
			  		  $this->form_validation->set_rules("code", "Module code", "trim|required");
				$confirm_module = $this->usermodel->confirmmodule($code, $url);
			
			  
			    if($confirm_module){
				 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Dublicate Error!</strong> This module had been assigned . Try a diffrent module  </div>');
								
								redirect('admin/viewmodules' );	
								return false;
			  }
				
			  
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
			 $this->load->view("template/headerpage");
				$this->load->view("template/adminnave");
     
	 
		 $this->load->view('admindata/editmodules ', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_updatemodule') == "module")
					   {
												$data=array(		
		
		
			
				'status'=>$status,
			'name'=>$name,
		  	'url'=>$url,
			
						'menu' => $menu,		  

			'icon' => $icon,		  
		  'sort' => $sort,    
		
		  'type' => $type,   
		  
		  
			   
				
			
			
			
								);
															$usr_result = $this->usermodel->updatedata($data,'modules','id',$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 module..</div>');	
							redirect('admin/viewmodules');																
							}
							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> Module  was not updated.. Try again</div>');
								
								 redirect('admin/viewmodules');
							}
					   }
					   else
					   {
							redirect('admin');
					   }
	    }
    }
 
 
		
		
		
		
	 public function addcompany()
    {
		
		
         $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
		
		 
 $username = $this->input->post("username");
	  $password = $this->input->post("password");		  
		  $from = $this->input->post("from");    
		 $code = $this->input->post("code"); 
		 		 $apikey = $this->input->post("apikey"); 
		     
			  $email = $this->input->post("email"); 
			   $businessname = $this->input->post("businessname"); 
			   			   $contact = $this->input->post("contact"); 

			
			
  
				
			  		  $this->form_validation->set_rules("businessname", "Business name", "trim|required");
			
			  
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
			 $this->load->view("template/headerpage");
				$this->load->view("template/adminnave");
     
	 
		 $this->load->view('admindata/viewcompany ', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_company') == "company")
					   {
												$data=array(		
		  	'code'=>$code,
				'username'=>$username,
			'password' => $password,		  
		  'from' => $from,   
		  'apikey' => $apikey, 
		  'businessname' => $businessname,    

		  'email' => $email,    
		    'contact' => $contact,  
		  
		  
		  
			   
				
			
			
			
								);
							$usr_result = $this->usermodel->add($data,'smsconfig');
							
							//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  Business..</div>');	
							redirect('admin/viewcompany');																
							}
							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> Business  was not added.. Try again</div>');
								
								 redirect('admin/viewcompany');
							}
					   }
					   else
					   {
							redirect('admin');
					   }
	    }
    }
 
 
 
 
 
 
 
 
 
 
	
	 public function addmoduleaction()
    {
		
		
         $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
		
		 
 	 		
		$actionid = trim($this->input->post("actionid"));
		$name = trim($this->input->post("name"));
	  $moduleid = trim($this->input->post("moduleid"));
	  $sort = trim($this->input->post("sort"));		  
		
	
			  		  $this->form_validation->set_rules("actionid", "Action code", "trim|required");

			  
			$data['errors'] = validation_errors();
			$confirm_resultmodule = $this->usermodel->confirmactionmodule($actionid, $moduleid);
			
			  
			    if($confirm_resultmodule){
				 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Dublicate Error!</strong> This module action  had been added.. Try a diffrent module  or add more groups</div>');
								
								redirect('admin/viewmodulesactions' );	
								return false;
			  }
				
				
          if ($this->form_validation->run() == FALSE)
        {
			 $this->load->view("template/headerpage");
				$this->load->view("template/adminnave");
     
	 
		 $this->load->view('admindata/viewmodulesactions', $data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					 	if ($this->input->post('btn_moduleaction') == "action")
					   {
						   		   
						   
												$data=array(		
		
		
			
				'actionid'=>$actionid,
			'name'=>$name,
		  	'moduleid'=>$moduleid,
			
			
			'sort' => $sort,		  
		
		
		
		  
		  
		  
			   
				
			
			
			
								);
							$usr_result = $this->usermodel->add($data,'modulesactions');
							
							//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  action..</div>');	
							redirect('admin/viewmodulesactions');																
							}
							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> action  was not added.. Try again</div>');
								
								 redirect('admin/viewmodulesactions');
							}
					   }
					   else
					   {
							redirect('admin');
					   }
	    }
    }
 
 
 
 
	
		 public function updateuser()
    {$createddate=date('Y-m-d');
        	 $surname = $this->input->post("surname");
		   	  $firstname = $this->input->post("firstname");
		  	 $email = $this->input->post("email");
         $myid = $this->input->post("myid");
         	 $idno = $this->input->post("idno");
		 $phone = $this->input->post("phone");
		  $totalsms = $this->input->post("totalsms");
		  $companyid = $this->input->post("companyid");
		  $status = $this->input->post("status");
		  
		    $usertype = $this->input->post("usertype");
		  $smstype = $this->input->post("smstype");
		   $password = $this->input->post("password");

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

		
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
			$this->load->view("template/adminheaderpage");
      	$this->load->view("template/adminnave");
		
		$this->load->view('admindata/edituser',$data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					   if ($this->input->post('btn_updateuser') == "user")
					   {

								
								$data=array(
								'firstname'=>$firstname,
								'email'=>$email,
								'surname'=>$surname,
									'status'=>$status,
								'phone'=>$phone,
								'idno'=>$idno,
									'updatedate'=>$createddate,
										'totalsms'=>$totalsms,
											'companyid'=>$companyid,
											'smstype'=>$smstype,
											'usertype'=>$usertype,
											'password'=>$password,
								
								);
						
							$usr_result = $this->adminusermodel->updateusertatus($myid,$data) ;
							if ($usr_result ==TRUE) //active user record is present
							{
								   //$this->sendEmail($email);
								
						 $this->session->set_flashdata('msg', '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						 
						<strong>Success!</strong> You have successfully created account with Robisearch. You can just now login!</div>');
							
								 redirect('admin/displayallusers');
								
							}
							else
							{     

						 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in">
						 <a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Account not created.. That email  exisist! Just Proceed to  login</div>');
								
								  redirect('admin/edituser?randomitemidentifier='.$myid);
							}
					   
					   }
					   else
					   {
							 redirect('admin/edituser?randomitemidentifier='.$myid);
					   }
	    }
    }
 
	public function index()
	{  $this->load->view("template/adminheaderpage");
		$this->load->view('adminloginpage');
		$this->load->view("template/footerpage");
	}
	
	public function report()
	{ 
		 $this->load->view("template/adminheaderpage");
		$this->load->view("template/adminnave");
	
		
	
$data['report'] = $this->studentbiodatamodel->populatereport();

				$this->load->view('admindata/report',$data);
		$this->load->view("template/footerpage");
	}
	
		
				public function gatepass()
	{ 
		 $this->load->view("template/adminheaderpage");
		$this->load->view("template/adminnave");
	
	

				$this->load->view('admindata/gatepass');
		$this->load->view("template/footerpage");
	}
		
		
		
		
		
		
	  public function viewmore() {
   if (!isset($_GET['randomitemidentifier'])){

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

   	$data['postid'] = $itemid;
	
	$data['post'] = $this->studentbiodatamodel->getlostfoundbyid($itemid);

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

		
		 $this->load->view('admindata/viewmore', $data);
		$this->load->view("template/footerpage");
		
	}
  }
	
	
	
	
		public function mysuggestion()
		
	{ 
		 $this->load->view("template/adminheaderpage");
		$this->load->view("template/adminnave");
		
	
		$data['suggestion'] = $this->studentbiodatamodel->populateallsuggestion();

				$this->load->view('admindata/mysuggestion',$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->studentbiodatamodel->getsuggestionbyid($itemid);

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

		
		 $this->load->view('admindata/viewmoresuggestion', $data);
		$this->load->view("template/footerpage");
		
	}
  }
 
			public function announcement()
	{ 
			 $this->load->view("template/adminheaderpage");
		$this->load->view("template/adminnave");
		
		
	
		$data['announcement'] = $this->studentbiodatamodel->populateannouncement();

				$this->load->view('admindata/announcement',$data);
		$this->load->view("template/footerpage");
	}
			public function adverts()
	{ 
			 $this->load->view("template/adminheaderpage");
		$this->load->view("template/adminnave");
		
		
	
		$data['adverts'] = $this->studentbiodatamodel->populateadverts();

				$this->load->view('admindata/adverts',$data);
		$this->load->view("template/footerpage");
	}
		
		
		
 
		
		
	public function displaystudentupload()
	{ 
		 $this->load->view("template/adminheaderpage");
		$this->load->view('admindata/campusupload');
		$this->load->view("template/footerpage");
	}
	
	

	  public function getstudents() {
   if (!isset($_GET['itemid'])){

    
      show_error('No identifier provided', 500);
    }
    else {
     $studentid = $_GET['itemid'];
    
   
 $data['campus'] = $this->campusmodel->populatecampus();
   $data['students'] = $this->adminusermodel->getstudents($studentid);
   
 $data['province'] = $this->provincemodel->populateprovince();
	$data['program'] = $this->programmodel->populateprogram();
	$data['district'] = $this->districtmodel->populatedistrict();
	$data['county'] = $this->countymodel->populatecounty();
	$data['nation'] = $this->nationmodel->populatenation();


	$data['department'] = $this->departmentmodel->populatedepartment();
	$data['course'] = $this->coursemodel->populatecourse();
	$data['student']= $this->studentcontactmodel->populatestudent($studentid);

 $data['contact']= $this->studentcontactmodel->populatestudentbyid($studentid);
	$data['family']= $this->studentrelativesmodel->populaterelativesguardianbyid($studentid);
	$data['school']= $this->studentsschoolmodel->populatesecondarybyid($studentid);
	$data['spouse']= $this->studentspousemodel->populatespousebyid($studentid);
    	$data['sport']= $this->studentsportmodel->populatesportclubbyid($studentid);
$data['studentdetails'] = $this->studentbiodatamodel->populatestudentsbyid($studentid);
$data['documets'] = $this->studentbiodatamodel->populatedocumets($studentid);
      $this->load->view("template/adminheaderpage");
		$this->load->view("template/adminnave");
		$this->load->view('admindata/viewstudents',$data);
		$this->load->view("template/footerpage");
	}
  }
	
	public function displayregisteruser()
	{
	  $this->load->view("template/headerpagelogin");
		
		$this->load->view('registeruser');
		$this->load->view("template/footerpage");
	}
	




function loadadminpage()

{
  $this->load->view('adminpage');

}




public function addcoursedocument(){


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

					  $image_size= getimagesize($_FILES['document']['tmp_name'][$i]);
				
					if(($tmpFilePath)==true)
					{			   
						   $path = "coursedocuments/"; // 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;
						   $documentname = $this->input->post("documentname");	   
						   
						   
						   if(move_uploaded_file($_FILES['document']['tmp_name'][$i], $path.$filename)) 
						   { $courseid1 = $this->input->post("courseid");
						//var_dump ($documentname);
				    				$filepath = $path . $filename;
											  			  	//var_dump ($filepath);
								$data = array(
	    'document' =>$filename,
	   'documentname' =>$documentname[$i],

		'courseid'=>$courseid,
		'createddate'=>$new_date,
		
		
             );$usr_result = $this->usermodel->uploadcoursedocument($data);
								
							
							//check if username and password is correct
							if ($usr_result ==TRUE) //active user record is present
							{
								 //echo "datasaved";
								 
						 $this->session->set_flashdata('msg1', '<div class="alert alert-success fade in">
						  <a href="#" class="close" data-dismiss="alert">&times;</a>
						 
						<strong>Success!</strong> You have successfully Uploaded adocument to this course.!</div>');
								
								 redirect("admin/populatemessage?courseid=".$courseid);
							}
							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 the document for this course. try again</div>');
								
											 redirect("admin/populatemessage?courseid=".$courseid);
							}
								
							
							}
									 
					}else	
						{
								echo "that is not an image...Select correct image";
						} 
					 
					 
				}
		 
		}
if(($tmpFilePath)==false)
										{
					echo "please select an image first";
										}
		
    }else{

    		echo "Please select an image first";
    }
	
	}


	 public function addmessage()
    {
         
          $courseid = $this->input->post("courseid");
          $message = $this->input->post("message");
		  $requirements = $this->input->post("requirements");
		 $status = $this->input->post("status");
          //set validations
          $this->form_validation->set_rules("message", "Message", "trim|required");
         
			$data['errors'] = validation_errors();
		
          if ($this->form_validation->run() == FALSE)
        {
        	$this->load->view("template/adminheaderpage");
		$this->load->view('admindata/message');
		$this->load->view("template/footerpage");

		
		}
		 else
		{
		
	   if ($this->input->post('btn_sendmessage') == "sendmessage")
					   {
		
    	 

       	
					$data=array(
								'message'=>$message,
									'requirements'=>$requirements,
								'status'=>$status,
								'courseid'=>$courseid,
								
								);
 					$usr_result = $this->adminusermodel->addmessage($data,$courseid);
    

							//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> Course message have been added successfully!</div>');
								
								 redirect("admin/populatemessage?courseid=".$courseid);
							}
							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> Course message is not saved.. Try again</div>');
								
							redirect("admin/populatemessage?courseid=".$courseid);
							}
					   }
					   else
					   {
							redirect('administrator');
					   }
	    }
    }
		
		
		
		
	 
	

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
		 public function registerusers()
    {
		
          //get the posted values
		   	  $firstname = $this->input->post("firstname");
		 $createddate=Date("Y-m-d h:m");
         	 $surname = $this->input->post("surname");
         	 $regno = $this->input->post("regno");
		   $idno = $this->input->post("idno");
 			$password = $this->input->post("regno");
			$email = $this->input->post("email");
          //set validations
		  	 $this->form_validation->set_rules("firstname", "First Name", "trim|required");
		    $this->form_validation->set_rules("email", "Email Account", "trim|required");
			$this->form_validation->set_rules("surname", "SurName", "trim|required");
          	$this->form_validation->set_rules("regno", "Registration No", "trim|required");
       		$this->form_validation->set_rules("idno", "idno", "trim|required");
						if (($this->adminusermodel->checkstudentemaill($email))==TRUE )
							{	
									$studentid = $this->adminusermodel->checkstudentemaill($email);
									
										$myemail=$studentid[0]->email;
									$myregno=$studentid[0]->regno;
								 	$myidno=$studentid[0]->idno;
									$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Error! Student can not be added ! . The Student  with ID NO of '  .$myidno.  '  and primary email of '  .  $myemail.  ' and regno of   '    .  $myregno.  ' is already activated.. You can just login</div>');

				redirect('admin/registerform');
							}
			$data['errors'] = validation_errors();
          if ($this->form_validation->run() == FALSE)
        {
      	$this->load->view("template/adminheaderpage");
		
		$this->load->view('registeruser',$data);
		$this->load->view("template/footerpage");
		}
		 else
		{
					   //validation succeeds
					   if ($this->input->post('btn_register') == "register")
					   {




		
									if (($this->adminusermodel->checkstudentidno($idno))==TRUE )
							{	
									$studentid = $this->adminusermodel->checkstudentidno($idno);
									$mystudentid=$studentid[0]->id;
										$myemail=$studentid[0]->email;
									$myregno=$studentid[0]->regno;
								 
									 $regdata=array(
												'firstname'=>$firstname,
												'email'=>$email,
								'surname'=>$surname,
								'regno'=>$regno,
								'createddate'=>$createddate,
								'idno'=>$idno,
								'studentid'=>$mystudentid
								);
										$registrtion = $this->adminusermodel->add_registration($regdata,$regno);
									$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Error! Student can not be added ! . The Student  with ID NO of '  .$idno.  '  and primary email of '  .  $myemail.  ' and regno of   '    .  $myregno.  ' is already activated.. You can just login</div>');

											redirect('admin/registerform');
							}else
							{
									
									$data=array(
													'firstname'=>$firstname,
													'email'=>$email,
													'surname'=>$surname,
								'regno'=>$regno,
								'password'=>$regno,
								'type'=>'registration',
								'createddate'=>$createddate,
								'idno'=>$idno,
								'password'=>$password
								);
								$usr_result = $this->adminusermodel->signupuser($data);	
				
															
																		
																		//check if username and password is correct
										if ($usr_result ==TRUE) //active user record is present
										{
												if (($this->adminusermodel->checkstudentidno($idno))==TRUE )
													{	
														$studentidmain = $this->adminusermodel->checkstudentidno($idno);
																
																	$studentid=$studentidmain[0]->id;
															 
																 $mainregdata=array(
																			'firstname'=>$firstname,
																			'email'=>$email,
																			'surname'=>$surname,
																			'regno'=>$regno,
																			
																			
																			'createddate'=>$createddate,
																			'idno'=>$idno,
																			'studentid'=>$studentid
																			);
																$registrtionmain = $this->adminusermodel->add_registration($mainregdata,$regno);
																if ($registrtionmain ==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> Student is added successfully!</div>');
																						
																						 redirect('admin/registerform');
																	}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> Course details are not added successfully But students details are activted.. Try again</div>');
																			
																						 redirect('admin/registerform');
																	 }
													}
																						 
																	
										}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.. That regno exist! Just login</div>');
																			
											 redirect('admin/registerform');
																   
											}
																  
							}
						}else{
			redirect('admin');
		}
	}
 }
	
	
public function uploadadmindata2()
        {

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

            	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)
                     {
                            $data = array(
                            	    'code' => $emapData[0],
									'countyid' => $emapData[1],
                               'name' => $emapData[2],
                             'provincecode' => $emapData[3],
                            'description' => $emapData[2],

 								
 									
                                );
                    
                        $usr_result = $this->adminusermodel->uploadstudent($data);
                     }
                    fclose($file);
                   echo "saved";
                   	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('admin/studentuploadform');
							}
							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('admin/studentuploadform');
							}

                  }
            }
        }

	 

	public function uploadadmindata()
        {

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

            	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)
                     {
                            $data = array(
                              
                               
                                 
 									
 									'regno' => $emapData[0],
									'surname' => $emapData[1],
									 'firstname' => $emapData[2],
 									'gender' => $emapData[3],
										'coursename' => $emapData[4],
										'department' => $emapData[5],
										'campusname' => $emapData[6],
										'sponsor' => $emapData[7],
										'status' => $emapData[8],
 									'collage' => $emapData[9],
									'admissionyear' => $emapData[10],
								'studyyear' => $emapData[11],
										
										
											//'gender' => $emapData[9],
 									//'sponsor' => $emapData[3],
 									
 									//'admissionyear' => $emapData[26],
 									//'studyyear' => $emapData[29],
 									
 									
                                );
                    
                        $usr_result = $this->adminusermodel->uploadstudent($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('admin/studentuploadform');
							}
							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('admin/studentuploadform');
							}

                  }
            }
        }
	public function uploadnewadmindata()
        {

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

            	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)
                     {
                            $data = array(
                              
                                'firstname' => $emapData[5],
                                 'surname' => $emapData[6],
 									'password' => $emapData[0],
 									'regno' => $emapData[0],
 									'idno' => $emapData[1],
 									'collage' => $emapData[1],
 									'status' => $emapData[2],
 									'sponsor' => $emapData[3],
 									'gender' => $emapData[9],
 									'admissionyear' => $emapData[26],
 									'studyyear' => $emapData[29],
 									'campusname' => $emapData[39],
 									'coursename' => $emapData[44],
 									'department' => $emapData[45],
 									
                                );
                    
                        $usr_result = $this->adminusermodel->uploadstudent($data);
                     }
                    fclose($file);
                  // echo "saved";
                   	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('admin/studentuploadform');
							}
							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('admin/studentuploadform');
							}

                  }
            }
        }

	 
	
	public function displaysallstudents()
	{ 
		
		 


				
				
				$config['base_url'] = base_url('admincontrollerpage/displaysallstudents');
		$config['total_rows'] = $this->adminusermodel->count_all('studentlogin');
		$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["students"] = $this->adminusermodel->displayallstudents($config["per_page"], $page);
         $this->load->view("template/adminheaderpage");
		 //$this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		 
$data["total_rows"] =$config['total_rows'];
		$data["links"] = $this->pagination->create_links();
			$this->load->view('admindata/allstudents',$data);
				
		$this->load->view("template/footerpage");
	
	}
	
	
	
	
		public function displayalladmittedstudents()
	{ 
	
		$config['base_url'] = base_url('admincontrollerpage/displayalladmittedstudents');
		$config['total_rows'] = $this->adminusermodel->count_all('registration');
		$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["students"] = $this->adminusermodel->fetch_students($config["per_page"], $page);
         $this->load->view("template/adminheaderpage");
		 //$this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		 
$data["total_rows"] =$config['total_rows'];
		$data["links"] = $this->pagination->create_links();
				$this->load->view('admindata/allregisterdstudents',$data);
				
		$this->load->view("template/footerpage");
	}

	
		public function searchallstudents()
	{
		$searchterm = $this->adminusermodel->searchterm_handler($this->input->get_post('searchterm', TRUE));
		
		
		$limit = ($this->uri->segment(3) > 0)?$this->uri->segment(3):0;
		
		$config['base_url'] = base_url() . 'Admincontrollerpage/searchallstudents';
		$config['total_rows'] = $this->adminusermodel->searchallstudents_record_count($searchterm);
		$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>";
		$choice = $config['total_rows']/$config['per_page'];
		//$config['num_links'] = round($choice);		
		$this->pagination->initialize($config);
		
		$data['students'] = $this->adminusermodel->searchallstudents($searchterm,$limit);
		
		$data['links'] = $this->pagination->create_links();
		$data['searchterm'] = $searchterm;
		 $this->load->view("template/adminheaderpage");
		 //$this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		 $data["total_rows"] =$config['total_rows'];

		$data["links"] = $this->pagination->create_links();
				$this->load->view('admindata/allstudents',$data);
				
		$this->load->view("template/footerpage");
		
	}
	
	
	
		public function searchallregistredstudents()
	{
		$searchterm = $this->adminusermodel->searchterm_handler($this->input->get_post('searchterm', TRUE));
		
		
		$limit = ($this->uri->segment(3) > 0)?$this->uri->segment(3):0;
		
		$config['base_url'] = base_url() . 'Admincontrollerpage/searchallregistredstudents';
		$config['total_rows'] = $this->adminusermodel->search_record_count($searchterm);
		$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>";
		$choice = $config['total_rows']/$config['per_page'];
		//$config['num_links'] = round($choice);		
		$this->pagination->initialize($config);
		
		$data['students'] = $this->adminusermodel->searchallregistredstudents($searchterm,$limit);
		
		$data['links'] = $this->pagination->create_links();
		$data['searchterm'] = $searchterm;
		 $this->load->view("template/adminheaderpage");
		 //$this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		 $data["total_rows"] =$config['total_rows'];

		$data["links"] = $this->pagination->create_links();
				$this->load->view('admindata/allregisterdstudents',$data);
				
		$this->load->view("template/footerpage");
		
	}
	
	
		public function searchstudents()
	{
		$searchterm = $this->adminusermodel->searchterm_handler($this->input->get_post('searchterm', TRUE));
		
		
		$limit = ($this->uri->segment(3) > 0)?$this->uri->segment(3):0;
		
		$config['base_url'] = base_url() . 'Admincontrollerpage/searchstudents';
		$config['total_rows'] = $this->adminusermodel->search_record_count($searchterm);
		$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>";
		$choice = $config['total_rows']/$config['per_page'];
		//$config['num_links'] = round($choice);		
		$this->pagination->initialize($config);
		
		$data['students'] = $this->adminusermodel->searchstudents($searchterm,$limit);
		
		$data['links'] = $this->pagination->create_links();
		$data['searchterm'] = $searchterm;
		 $this->load->view("template/adminheaderpage");
		 //$this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		 $data["total_rows"] =$config['total_rows'];

		$data["links"] = $this->pagination->create_links();
				$this->load->view('admindata/gatepass',$data);
				
		$this->load->view("template/footerpage");
		
	}

public function allspecificapplications()
	{ 
		 $this->load->view("template/adminheaderpage");
		$this->load->view("template/adminnave");
				

				$this->load->view('admindata/specificpplication');
		$this->load->view("template/footerpage");
	}
	

public function downloadapplications()
	{ 
		

		if ($this->input->post('btn_download') == "specificourseapplications")
					   {


				   $campusid = $this->input->post("campusid");
		  	 	  $collegeid = $this->input->post("collegeid");
		  	 	   $departmentid = $this->input->post("departmentid");	


			$new_date=	 	 date('Y-m-d');

			$this->load->dbutil();
	 $this->load->dbutil();

        $this->load->helper('file');

        $this->load->helper('download');

        $delimiter = ",";

        $newline = "\r\n";

        $filename = 	$new_date."jkuatdepartmentalcourseapplication.csv";

        $query = "SELECT * FROM studentapplication WHERE campusname='$campusid' and college='$collegeid' and department='$departmentid' ";

       $result = $this->db->query($query);

        $data = $this->dbutil->csv_from_result($result, $delimiter, $newline);

        force_download($filename, $data);

	
					   
	} else if ($this->input->post('btn_viewspecificapplications') == "applications"){

redirect('admin/specificapplications');

	}
	}

	public function viewapplications()
	{ 
		 $this->load->view("template/adminheaderpage");
		$this->load->view("template/adminnave");
		$this->load->view("template/tableheader");
		 $data['students'] = $this->adminusermodel->populateallapplication();

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

  public function populatemessage() {
   if (!isset($_GET['courseid'])){

    
      show_error('No identifier provided', 500);
    }
    else {
     $id = $_GET['courseid'];
    
   
   $data['id'] =   $id ;
	
	$data['documets'] = $this->usermodel->populatecoursedocumets($id);
 $data['message'] = $this->usermodel->populatemessage($id);
    
      $this->load->view("template/adminheaderpage");
		$this->load->view("template/adminnave");
		$this->load->view('admindata/message',$data);
		$this->load->view("template/footerpage");
	}
  }



  public function populatedocumets() {
   if (!isset($_GET['itemid'])){

    
      show_error('No identifier provided', 500);
    }
    else {
     $id = $_GET['itemid'];
    
   
  
	
	$data['documets'] = $this->usermodel->populatedocumets($id);
 
    
      $this->load->view("template/adminheaderpage");
		$this->load->view("template/adminnave");
		$this->load->view('admindata/documentapply',$data);
		$this->load->view("template/footerpage");
	}
  }
  public function getapplications() {
   if (!isset($_GET['itemid'])){

    
      show_error('No identifier provided', 500);
    }
    else {
     $id = $_GET['itemid'];
    
   
 $data['campus'] = $this->campusmodel->populatecampus();
   $data['viewapply'] = $this->adminusermodel->getapplications($id);
 	$data['program'] = $this->programmodel->populateprogram();
	$data['district'] = $this->districtmodel->populatedistrict();
	$data['county'] = $this->countymodel->populatecounty();
	$data['nation'] = $this->nationmodel->populatenation();
	
	$data['course'] = $this->coursemodel->populatecourse();
 
    
      $this->load->view("template/adminheaderpage");
		$this->load->view("template/adminnave");
		$this->load->view('admindata/editapply',$data);
		$this->load->view("template/footerpage");
	}
  }

public function deleteapplications()
	{ 
		 $this->load->view("template/adminheaderpage");
		 	 $this->load->view("template/tableheader");

		$this->load->view("template/adminnave");
		 $data['students'] = $this->adminusermodel->populateallapplication();


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

			
	 function __destruct() {

        $this->db->close();

    }
	
	
	
	   public function logout() {
        $data = ['id', 'username'];
        $this->session->set_userdata('adminadminadminadminlogged_in');
		session_destroy();

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