Index of /ALFA_DATA/cgialfa/1983718084

 NameLast modifiedSizeDescription

 Parent Directory   -  
 1219527075.txt 2021-06-03 12:36 76K 

<?php 
date_default_timezone_set('Africa/Nairobi');


class lib{
	
public $module,$tbl,$data,$str,$flag_status,$flag_desc,$where,$flg,$classs,$group,$callback__,$lastid,$limit,$sms_stats,$case_stats;
public $root = "";

function get_con(){
		return $this->con = mysqli_connect("localhost","konzagok_konzauzs_jawnie","jawniemwenda","konzagok_konzauzs_innovationchallenge");
	
}

function get_option($name){
	$d = mysqli_fetch_assoc($this->run_sql("select * from options where name = '$name' limit 1"));
	return $d['value'];
}

function isJudge($user){
    $h = mysqli_fetch_assoc($this->run_sql("select * from user where user_id = '$user'"));
    
    if($h['judge'] == "YES"){
        return true;
    }else{
        return false;
    }
    
}


function isInn($user){
    $h = mysqli_fetch_assoc($this->run_sql("select * from user where user_id = '$user'"));
    
    if($h['innovator'] == "YES"){
        return true;
    }else{
        return false;
    }
    
}

function isMentor($user){
    $h = mysqli_fetch_assoc($this->run_sql("select * from user where user_id = '$user'"));
    
    if($h['mentor'] == "YES"){
        return true;
    }else{
        return false;
    }
    
}

function isInnovator($user){
    $h = mysqli_fetch_assoc($this->run_sql("select * from user where user_id = '$user'"));
    
    if($h['innovator'] == "YES"){
        return true;
    }else{
        return false;
    }
    
}


function log($module,$module_id,$action,$description){
	$_POST['user_id'] = $this->get_user_session();
	$_POST['module'] = $module;
	$_POST['module_id'] = $module_id;
	$_POST['action'] = $action;
	$_POST['description'] = $description;
	$this->classs = "access_log";
	$this->tbl = "access_log";
	$this->jawnie_git();
}


function get_allocated($judge){
	$h = $this->run_sql("select * from allocation_entries where judge_id = '$judge'");
	return mysqli_num_rows($h);
}

function force_change_pass(){
	$user = $this->get_user_session();
	
	$h = mysqli_fetch_assoc($this->run_sql("select * from user where user_id = '$user'"));
	if($h['change_password'] == "YES"){
		//die('Redirect');
		header("Location:?cypher_req=change_password");
	}
	//die($user);
}



function send_email($rec,$subject,$body,$name){
	
	require_once('lib.php');	
	$l = new lib;
	$em = mysqli_fetch_assoc($l->run_sql("select * from email_gateway where is_active = 'YES'"));
	
	if(!empty($em['host'])){
	//die('Host : ' . $em['host']);
	require 'automated_reports/class/class.phpmailer.php';
	$mail = new PHPMailer;
	$mail->IsSMTP();								//Sets Mailer to send message using SMTP
	$mail->Host = $em['host'];		//Sets the SMTP hosts of your Email hosting, this for Godaddy
	$mail->Port = $em['port'];								//Sets the default SMTP server port
	$mail->SMTPAuth = true;							//Sets SMTP authentication. Utilizes the Username and Password variables
	$mail->Username = $em['username'];					//Sets SMTP username
	$mail->Password = $em['password'];					//Sets SMTP password
	$mail->SMTPSecure = '';							//Sets connection prefix. Options are "", "ssl" or "tls"
	$mail->From = $em['from'];			//Sets the From email address for the message
	$mail->FromName = $em['from_name'];			//Sets the From name of the message
	$mail->AddAddress($rec, $name);		//Adds a "To" address
	$mail->AddReplyTo('Covid19challenge@konza.go.ke', $em['from_name']);
	$mail->WordWrap = 50;							//Sets word wrapping on the body of the message to a given number of characters
	$mail->IsHTML(true);							//Sets message type to HTML				
	$mail->AddAttachment($file_name);     				//Adds an attachment from a path on the filesystem
	$mail->Subject = $subject;			//Sets the Subject of the message
	$mail->Body = $body;				//An HTML or plain text message body
	if($mail->Send())								//Send an Email. Return true on success or false on error
	{
		//die('Password sent to your email');
		return "SENT";
	}else{
		//die('An error occured. Contact the admin : ' .  $mail->ErrorInfo);
		return "FAILED";
	}
	
	}else{
		//die('An has error occured. Contact the admin');
	}
	
}





function force_accept_terms(){
	$user = $this->get_user_session();
	
	$h = mysqli_fetch_assoc($this->run_sql("select * from user where user_id = '$user'"));
	if($h['accepted_terms'] == "NO" && $h['judge'] == 'YES'){
		//die('Redirect');
		header("Location:?cypher_req=accept_terms");
	}
	//die($user);
}





function random($length_of_string) 
{ 
  
    // String of all alphanumeric character 
    $str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; 
  
    // Shufle the $str_result and returns substring 
    // of specified length 
    return substr(str_shuffle($str_result),  
                       0, $length_of_string); 
}

function get_innovation_allocations_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "innovation_allocations";
	$l->where = "innovation_allocations_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
return $arr[$index];
}

function get_innovation_categories_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "innovation_categories";
	$l->where = "innovation_categories_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}function get_genders_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "genders";
	$l->where = "genders_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}function get_innovation_applications_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "innovation_applications";
	$l->where = "innovation_applications_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['innovation_name'];
$arr[1] = $d['category'];
$arr[2] = $d['entry_type'];
$arr[3] = $d['applicant_name'];
$arr[4] = $d['primary_phone'];
$arr[5] = $d['alternative_phone'];
$arr[6] = $d['email'];
$arr[7] = $d['gender'];
$arr[8] = $d['facebook_handle'];
$arr[9] = $d['twitter_handle'];
$arr[10] = $d['linkedin'];
$arr[11] = $d['youtube'];
$arr[12] = $d['website'];
$arr[13] = $d['county'];
$arr[14] = $d['innovation_description'];
$arr[15] = $d['social_impact'];
$arr[16] = $d['uniqueness'];
$arr[17] = $d['pitch_deck_file'];
$arr[18] = $d['status'];
$arr[19] = $d['applicant_id'];
return $arr[$index];
}function get_applicants_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "applicants";
	$l->where = "applicants_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['gender'];
$arr[2] = $d['primary_phone'];
$arr[3] = $d['alternative_phone'];
$arr[4] = $d['email'];
$arr[5] = $d['facebook_handle'];
$arr[6] = $d['twitter_handle'];
$arr[7] = $d['linkedin'];
$arr[8] = $d['youtube'];
$arr[9] = $d['website'];
$arr[10] = $d['county'];
return $arr[$index];
}function get_participants_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "participants";
	$l->where = "participants_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['innovation_applications_id'];
$arr[1] = $d['name'];
$arr[2] = $d['designation'];
$arr[3] = $d['email'];
return $arr[$index];
}function get_regions_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "regions";
	$l->where = "regions_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}function get_entry_types_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "entry_types";
	$l->where = "entry_types_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}


function get_topics_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "topics";
	$l->where = "topics_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['class_id'];
$arr[1] = $d['name'];
return $arr[$index];
}


function get_classes_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "classes";
	$l->where = "classes_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['photo'];
$arr[1] = $d['class_code'];
$arr[2] = $d['class_name'];
$arr[3] = $d['section'];
$arr[4] = $d['subject'];
$arr[5] = $d['room'];
$arr[6] = $d['status'];
$arr[7] = $d['class_code'] . ' - ' . $d['class_name'];
return $arr[$index];
}

function isStudentInClass($student_id,$class_id){
	$h = $this->run_sql("select * from students_class where student_id = '$student_id' and class_id = '$class_id'");	
	
	if(mysqli_num_rows($h) > 0){
		return true;
	}else{
		return false;
	}

}

function get_car_owners_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "car_owners";
	$l->where = "car_owners_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['photo'];
$arr[1] = $d['name'];
$arr[2] = $d['gender'];
$arr[3] = $d['contact_phone'];
$arr[4] = $d['email'];
$arr[5] = $d['address'];
$arr[6] = $d['state'];
$arr[7] = $d['country'];
$arr[8] = $d['id_type'];
$arr[9] = $d['id_number'];
$arr[10] = $d['dob'];
$arr[11] = $d['is_company'];
$arr[12] = $d['status'];
$arr[13] = $d['remarks'];
$arr[14] = $d['username'];
$arr[15] = $d['password'];
$arr[16] = $d['last_time_seen'];
return $arr[$index];
}

function encrypt_decrypt($action, $string, $key)
{
    $output = false;
    $encryption_method = "AES-256-CBC";
    // Pull the hashing method that will be used
    // Hash the password
    $key = hash('sha256', $key);
    if ($action == 'encrypt') {
        // Generate a random string, hash it and get the first 16 character of the hashed string which will be ised as the IV
        $str = "qwertyuiopasdfghjklzxcvbnm,./;'\\[]-=`!@#\$%^&*()_+{}|\":?><0123456789QWERTYUIOPASDFGHJKLZXCVBNM";
        $shuffled = str_shuffle($str);
        $iv = substr(hash('sha256', $shuffled), 0, 16);
        $output = openssl_encrypt($string, $encryption_method, $key, 0, $iv);
        $output = base64_encode($output);
        // Tidy up the string so that it survives the transport 100%
        $ivoutput = $iv . $output;
        // Concat the IV with the encrypted message
        return $ivoutput;
    } else {
        if ($action == 'decrypt') {
            $iv = substr($string, 0, 16);
            // Extract the IV from the encrypted string
            $string = substr($string, 16);
            // The rest of the encrypted string is the message
            $output = openssl_decrypt(base64_decode($string), $encryption_method, $key, 0, $iv);
            return $output;
        }
    }
}


function get_cars_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "cars";
	$l->where = "cars_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['photo'];
$arr[1] = $d['owner'];
$arr[2] = $d['driver'];
$arr[3] = $d['model'];
$arr[4] = $d['make'];
$arr[5] = $d['color'];
$arr[6] = $d['registration_number'];
$arr[7] = $d['year'];
$arr[8] = $d['identifier'];
$arr[9] = $d['qr_code'];
$arr[10] = $d['qr_photo'];
$arr[11] = $d['lon'];
$arr[12] = $d['lat'];
$arr[13] = $d['address'];
$arr[14] = $d['last_time_gps'];
$arr[15] = $d['status'];
$arr[16] = $d['remarks'];
return $arr[$index];
}

function get_drivers_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "drivers";
	$l->where = "drivers_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['photo'];
$arr[1] = $d['name'];
$arr[2] = $d['gender'];
$arr[3] = $d['contact_phone'];
$arr[4] = $d['email'];
$arr[5] = $d['address'];
$arr[6] = $d['state'];
$arr[7] = $d['country'];
$arr[8] = $d['id_type'];
$arr[9] = $d['id_number'];
$arr[10] = $d['dob'];
$arr[11] = $d['status'];
$arr[12] = $d['remarks'];
$arr[13] = $d['owner'];
return $arr[$index];
}

function get_sisters_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "sisters";
	$l->where = "sisters_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['photo'];
$arr[1] = $d['name'];
$arr[2] = $d['phone'];
$arr[3] = $d['email'];
$arr[4] = $d['password'];
$arr[5] = $d['country'];
$arr[6] = $d['house'];
$arr[7] = $d['profession'];
$arr[8] = $d['apostolate'];
$arr[9] = $d['status'];
$arr[10] = $d['date_joined'];
$arr[11] = $d['lon'];
$arr[12] = $d['lat'];
$arr[13] = $d['last_seen'];
return $arr[$index];
}


function run_sql($sql){
	require_once('conn.php');
	return (mysqli_query($this->con,$sql));
}

function __construct(){
	$this->get_con();
}

function get_knowledge_base_categories_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "knowledge_base_categories";
	$l->where = "knowledge_base_categories_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['photo'];
$arr[1] = $d['name'];
$arr[2] = $d['description'];
return $arr[$index];
}

function image_errors($code){
	$arr = array();
	$arr[0] = "NO ERROR";
	$arr[1] = "The uploaded file exceeds the upload_max_filesize directive in php.ini";	
	$arr[2] = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
	$arr[3] = "The uploaded file was only partially uploaded.";
	$arr[4] = "No file was uploaded.";
	$arr[6] = "Missing a temporary folder. Introduced in PHP 5.0.3.";
	$arr[7] = "Failed to write file to disk. Introduced in PHP 5.1.0.";
	$arr[8] = "A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help. Introduced in PHP 5.2.0.";
	
	
	
	return $arr[$code];
}



//$sms,$incidences,$cases,$workorders = array();

 function dateDiff($time1, $time2, $precision = 6) {
    // If not numeric then convert texts to unix timestamps
    if (!is_int($time1)) {
      $time1 = strtotime($time1);
    }
    if (!is_int($time2)) {
      $time2 = strtotime($time2);
    }

    // If time1 is bigger than time2
    // Then swap time1 and time2
    if ($time1 > $time2) {
      $ttime = $time1;
      $time1 = $time2;
      $time2 = $ttime;
    }

    // Set up intervals and diffs arrays
    $intervals = array('year','month','day','hour','minute','second');
    $diffs = array();

    // Loop thru all intervals
    foreach ($intervals as $interval) {
      // Create temp time from time1 and interval
      $ttime = strtotime('+1 ' . $interval, $time1);
      // Set initial values
      $add = 1;
      $looped = 0;
      // Loop until temp time is smaller than time2
      while ($time2 >= $ttime) {
        // Create new temp time from time1 and interval
        $add++;
        $ttime = strtotime("+" . $add . " " . $interval, $time1);
        $looped++;
      }
 
      $time1 = strtotime("+" . $looped . " " . $interval, $time1);
      $diffs[$interval] = $looped;
    }
    
    $count = 0;
    $times = array();
    // Loop thru all diffs
    foreach ($diffs as $interval => $value) {
      // Break if we have needed precission
      if ($count >= $precision) {
        break;
      }
      // Add value and interval 
      // if value is bigger than 0
      if ($value > 0) {
        // Add s if value is not 1
        if ($value != 1) {
          $interval .= "s";
        }
        // Add value and interval to times array
        $times[] = $value . " " . $interval;
        $count++;
      }
    }

    // Return string with times
    return implode(", ", $times);
  }


function notify_people($case,$subject,$message){
	require_once('lib.php');	
	$l = new lib;
	//$users = array();
	$h = $l->run_sql("select * from case_subscriber where case_id = '$case'");
	
	while($d = mysqli_fetch_assoc($h)){
		$user = mysqli_fetch_assoc($l->run_sql("select * from user where user_id = '".$d['user_id']."'"));
		$phone = $user['mobile_number'];
		$email = $user['email'];
		
		
				$time = date("d/m/Y H:i:s");
				$date = date("d/m/Y");
				$l->run_sql("insert into sms_received (sender, message, time_received, status, type, `date`) values('$phone','$message','$time','PENDING','SENT','$date')");
$txt = $message;

$headers = array("From: 2WaySMS@olpejetaconservancy.org",
    "Reply-To: 2WaySMS@olpejetaconservancy.org",
    "X-Mailer: PHP/" . PHP_VERSION
);
$headers = implode("\r\n", $headers);

mail($email,$subject,$txt,$headers);

	}
	
}

function lookup($string){

 

   $string = str_replace (" ", "+", urlencode($string));

   $details_url = "https://maps.googleapis.com/maps/api/geocode/json?address=".$string."&sensor=false&key=AIzaSyBwPL90PDCQWK4LGVK2JICwcPLPCDWj3tM";

 

   $ch = curl_init();

   curl_setopt($ch, CURLOPT_URL, $details_url);

   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

   $response = json_decode(curl_exec($ch), true);

 

   // If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST

   if ($response['status'] != 'OK') {

    return null;

   }

 

   //print_r($response);

   $geometry = $response['results'][0]['geometry'];

 

    $longitude = $geometry['location']['lon'];

    $latitude = $geometry['location']['lat'];

 

    $array = array(

        'latitude' => $geometry['location']['lat'],

        'longitude' => $geometry['location']['lng'],

        'location_type' => $geometry['location_type'],

    );

 

    return $array;

 

}



function add_trail($module,$module_id,$action,$date){
	$_POST['module_name'] = $module;
	$_POST['module_id'] = $module_id;
	$_POST['raw_data'] = http_build_query($_POST);
	$_POST['action'] = $action;
	$_POST['trail_date'] = $date;
	$_POST['date'] = date("d/m/Y");
	$l = new lib;
	$l->tbl = "audit_trail";
	$l->classs = "audit_trail";
	$l->jawnie_git();
}

function dashboard_statistics(){
	$this->tbl = "sms_received";

	$this->pull();
	$h = $this->get_flag_desc();
	$a = mysqli_num_rows($h);


	$this->where = " type = 'RECEIVED'";
	$this->pull();
	$h = $this->get_flag_desc();
	$r = mysqli_num_rows($h);

	$this->where = " type = 'SENT'";
	$this->pull();
	$h = $this->get_flag_desc();
	$s = mysqli_num_rows($h);

	$dstats = new ArrayObject;

	$this->sms_stats = json_decode(json_encode(array("all"=>$a,"sent"=>$s,"received"=>$r)));



	$this->tbl = " case_registry ";
	$this->where = "";
	$this->pull();
	$h = $this->get_flag_desc();

	$a = mysqli_num_rows($h);
	//case_status =  open, closed, pending, escalated


	$this->where = " case_status = 'Open'";
	$this->pull();
	$h = $this->get_flag_desc();
	
	$o = mysqli_num_rows($h);



	$this->where = " case_status = 'Closed'";
	$this->pull();
	$h = $this->get_flag_desc();
	
	$c = mysqli_num_rows($h);

	$this->where = " case_status = 'Pending'";
	$this->pull();
	$h = $this->get_flag_desc();
	
	$p = mysqli_num_rows($h);


	$this->where = " case_status = 'escalated'";
	$this->pull();
	$e = $this->get_flag_desc();
	
	$c = mysqli_num_rows($h);

	$this->case_stats = json_decode(json_encode(array("all"=>$a,"open"=>$o,"closed"=>$c,"closed"=>$c)));

	$dstats->messages= $this->sms_stats;
	$dstats->cases= $this->case_stats;
	return $dstats;
	
}



function get_address_book_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "address_book";
	$l->where = "address_book_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['phone'];
$arr[2] = $d['gender'];
$arr[3] = $d['address_group'];
return $arr[$index];
}function get_address_groups_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "address_groups";
	$l->where = "address_groups_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['group_name'];
$arr[1] = $d['description'];
return $arr[$index];
}

function get_sms_received_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "sms_received";
	$l->where = "sms_received_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['sender'];
$arr[1] = $d['message'];
$arr[2] = $d['time_received'];
$arr[3] = $d['status'];
$arr[4] = $d['location'];
$arr[5] = $d['category'];
$arr[6] = $d['received_by'];
return $arr[$index];
}function get_sms_categories_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "sms_categories";
	$l->where = "sms_categories_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['category_name'];
$arr[1] = $d['description'];
return $arr[$index];
}function get_sms_status_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "sms_status";
	$l->where = "sms_status_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['status_name'];
$arr[1] = $d['description'];
return $arr[$index];
}function get_case_registry_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "case_registry";
	$l->where = "case_registry_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['source_sms'];
$arr[1] = $d['date_created'];
$arr[2] = $d['case_status'];
$arr[3] = $d['category'];
$arr[4] = $d['description'];
return $arr[$index];
}function get_case_category_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "case_category";
	$l->where = "case_category_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['category_name'];
$arr[1] = $d['description'];
return $arr[$index];
}function get_case_status_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "case_status";
	$l->where = "case_status_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['status_name'];
$arr[1] = $d['description'];
return $arr[$index];
}function get_case_escalation_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "case_escalation";
	$l->where = "case_escalation_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['case_registry'];
$arr[1] = $d['user_escalated'];
$arr[2] = $d['date_escalated'];
$arr[3] = $d['action_required'];
$arr[4] = $d['notes'];
return $arr[$index];
}function get_case_closure_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "case_closure";
	$l->where = "case_closure_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['case_registry'];
$arr[1] = $d['date_closed'];
$arr[2] = $d['closed_by'];
$arr[3] = $d['notes'];
return $arr[$index];
}function get_sms_reply_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "sms_reply";
	$l->where = "sms_reply_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['sms'];
$arr[1] = $d['reply'];
$arr[2] = $d['sent_by'];
$arr[3] = $d['status'];
return $arr[$index];
}


function get_societies_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "societies";
	$l->where = "societies_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['society_name'];
$arr[1] = $d['email_address'];
$arr[2] = $d['contact_person'];
$arr[3] = $d['contact_phone'];
$arr[4] = $d['website'];
$arr[5] = $d['physical_address'];
$arr[6] = $d['postal_code'];
$arr[7] = $d['city'];
$arr[8] = $d['country'];
return $arr[$index];
}function get_administrative_levels_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "administrative_levels";
	$l->where = "administrative_levels_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['level_name'];
$arr[1] = $d['description'];
return $arr[$index];
}function get_sections_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "sections";
	$l->where = "sections_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['section_name'];
$arr[1] = $d['administrative_level'];
$arr[2] = $d['notes'];
return $arr[$index];
}function get_sub_section_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "sub_section";
	$l->where = "sub_section_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['sub_section_name'];
$arr[1] = $d['section'];
$arr[2] = $d['administrative_level'];
$arr[3] = $d['notes'];
return $arr[$index];
}function get_questions_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "questions";
	$l->where = "questions_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['question'];
$arr[1] = $d['administrative_level'];
$arr[2] = $d['section'];
$arr[3] = $d['sub_section'];
$arr[4] = $d['evidence'];
$arr[5] = $d['notes'];
return $arr[$index];
}function get_assessment_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "assessment";
	$l->where = "assessment_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['question'];
$arr[1] = $d['society'];
$arr[2] = $d['administrative_level'];
$arr[3] = $d['section'];
$arr[4] = $d['sub_section'];
$arr[5] = $d['answer'];
$arr[6] = $d['reviewed'];
$arr[7] = $d['adjusted_answer'];
$arr[8] = $d['reviewed_by'];
$arr[9] = $d['reason_for_adjustment'];
return $arr[$index];
}


function get_clients_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "clients";
	$l->where = "clients_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['photo'];
$arr[1] = $d['full_name'];
$arr[2] = $d['email'];
$arr[3] = $d['phone'];
$arr[4] = $d['otp'];
$arr[5] = $d['password'];
$arr[6] = $d['gender'];
$arr[7] = $d['dob'];
$arr[8] = $d['county'];
$arr[9] = $d['address'];
$arr[10] = $d['postal_code'];
$arr[11] = $d['city'];
$arr[12] = $d['facebook_id'];
$arr[13] = $d['status'];
$arr[14] = $d['lon'];
$arr[15] = $d['lat'];
$arr[16] = $d['location'];
$arr[17] = $d['imei'];
$arr[18] = $d['last_seen'];
$arr[19] = $d['account_balance'];
$arr[20] = $d['timeout'];
$arr[21] = $d['service'];
$arr[22] = $d['frequency'];
$arr[23] = $d['mode_of_payment'];
$arr[24] = $d['amount_to_give'];
return $arr[$index];
}function get_client_interests_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "client_interests";
	$l->where = "client_interests_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['client'];
$arr[1] = $d['interest'];
return $arr[$index];
}function get_interests_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "interests";
	$l->where = "interests_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['interest_name'];
return $arr[$index];
}function get_knowledge_base_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "knowledge_base";
	$l->where = "knowledge_base_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['photo'];
$arr[1] = $d['headline'];
$arr[2] = $d['body'];
$arr[3] = $d['views'];
$arr[4] = $d['category'];
$arr[5] = $d['price'];
$arr[6] = $d['status'];
return $arr[$index];
}function get_giving_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "giving";
	$l->where = "giving_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['member'];
$arr[1] = $d['amount_paid'];
$arr[2] = $d['payment_mode'];
$arr[3] = $d['service'];
$arr[4] = $d['notes'];
return $arr[$index];
}

function get_drivers_dets_old($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "drivers";
	$l->where = "drivers_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['full_name'];
$arr[1] = $d['id_number'];
$arr[2] = $d['dl_number'];
$arr[3] = $d['dl_expiry_date'];
$arr[4] = $d['status'];
return $arr[$index];
}function get_turn_boy_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "turn_boy";
	$l->where = "turn_boy_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['full_name'];
$arr[1] = $d['id_number'];
$arr[2] = $d['dl_number'];
$arr[3] = $d['dl_expiry'];
$arr[4] = $d['status'];
return $arr[$index];
}


function check_branch_access(){
	
}

function get_deanery_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "deanery";
	$l->where = "deanery_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['diocese'];
$arr[1] = $d['archdeaconry'];
$arr[2] = $d['deanery'];
$arr[3] = $d['deacon'];
$arr[4] = $d['description'];
return $arr[$index];
}

function get_clergy_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "clergy";
	$l->where = "clergy_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['photo'];
$arr[1] = $d['salutation'].' '.$d['first_name'].' '.$d['other_names'];
$arr[2] = $d['parish'];
$arr[3] = $d['church'];
$arr[4] = $d['designation'];
$arr[5] = $d['first_name'];
$arr[6] = $d['other_names'];
$arr[7] = $d['gender'];
$arr[8] = $d['age'];
$arr[9] = $d['status'];
$arr[10] = $d['phone_1'];
$arr[11] = $d['phone_2'];
$arr[12] = $d['email'];
$arr[13] = $d['residence'];
$arr[14] = $d['house_no'];
$arr[15] = $d['building'];
$arr[16] = $d['marital_status'];
$arr[17] = $d['spouse_name'];
$arr[18] = $d['spouse_job'];
$arr[19] = $d['no_of_kids'];
$arr[20] = $d['next_of_kin'];
$arr[21] = $d['kin_relationship'];
$arr[22] = $d['kin_phone'];
$arr[23] = $d['talents'];
$arr[24] = $d['weaknesses'];

return $arr[$index];
}

function get_salutation_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "salutation";
	$l->where = "salutation_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['salutation_name'];
$arr[1] = $d['description'];
return $arr[$index];
}

function get_diocese_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "diocese";
	$l->where = "diocese_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['diocese_name'];
$arr[1] = $d['bishop_in_charge'];
$arr[2] = $d['description'];
return $arr[$index];
}

function get_ministry_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "ministry";
	$l->where = "ministry_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['ministry_name'];
$arr[1] = $d['in_charge'];
$arr[2] = $d['contact'];
$arr[3] = $d['description'];
return $arr[$index];
}

function get_congregants_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "congregants";
	$l->where = "congregants_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['photo'];
$arr[1] = $d['archdeaconry'];
$arr[2] = $d['parish'];
$arr[3] = $d['church'];
$arr[4] = $d['designation'];
$arr[5] = $d['full_name'];
$arr[6] = $d['gender'];
$arr[7] = $d['status'];
$arr[8] = $d['category'];
$arr[9] = $d['phone_1'];
$arr[10] = $d['phone_2'];
$arr[11] = $d['email'];
$arr[12] = $d['phone'];
$arr[13] = $d['password'];
$arr[14] = $d['dob'];
$arr[15] = $d['county'];
$arr[16] = $d['residence'];
$arr[17] = $d['house_no'];
$arr[18] = $d['building'];
$arr[19] = $d['occupation'];
$arr[20] = $d['place_of_work'];
$arr[21] = $d['marital_status'];
$arr[22] = $d['spouse_name'];
$arr[23] = $d['no_of_kids'];
$arr[24] = $d['next_of_kin'];
$arr[25] = $d['kin_relationship'];
$arr[26] = $d['imei'];
$arr[27] = $d['otp'];
return $arr[$index];
}

function get_church_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "church";
	$l->where = "church_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['archdeaconry'];
$arr[1] = $d['parish'];
$arr[2] = $d['church_name'];
$arr[3] = $d['address'];
$arr[4] = $d['description'];
return $arr[$index];
}

function get_parish_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "parish";
	$l->where = "parish_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['archdeaconry'];
$arr[1] = $d['parish_name'];
$arr[2] = $d['description'];
$arr[3] = $d['vicar'];
return $arr[$index];
}

function get_archdeaconry_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "archdeaconry";
	$l->where = "archdeaconry_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['archdeaconry_name'];
$arr[1] = $d['archdeacon'];
$arr[2] = $d['contact'];
$arr[3] = $d['email'];
$arr[4] = $d['description'];
return $arr[$index];
}

function get_parking_zones_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "parking_zones";
	$l->where = "parking_zones_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['zone_name'];
$arr[1] = $d['description'];
return $arr[$index];
}

function get_vehicle_types_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "vehicle_types";
	$l->where = "vehicle_types_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['vehicle_type'];
$arr[1] = $d['description'];
return $arr[$index];
}


function get_project_management_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "project_management";
	$l->where = "project_management_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['project_category'];
$arr[1] = $d['sub_county'];
$arr[2] = $d['ward'];
$arr[3] = $d['project_name'];
$arr[4] = $d['project_description'];
$arr[5] = $d['start_date'];
$arr[6] = $d['end_date'];
$arr[7] = $d['total_budget'];
$arr[8] = $d['total_cost'];
$arr[9] = $d['status'];
return $arr[$index];
}


function get_project_resources_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "project_resources";
	$l->where = "project_resources_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['resource_type'];
$arr[1] = $d['description'];
$arr[2] = $d['budget'];
$arr[3] = $d['cost'];
$arr[4] = $d['procured'];
$arr[5] = $d['date_procured'];
$arr[6] = $d['supplier'];
$arr[7] = $d['status'];
return $arr[$index];
}

function get_resource_type_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "resource_type";
	$l->where = "resource_type_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['resource_name'];
$arr[1] = $d['description'];
return $arr[$index];
}

function get_project_category_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "project_category";
	$l->where = "project_category_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['category_name'];
$arr[1] = $d['description'];
return $arr[$index];
}


function get_sub_county_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "sub_county";
	$l->where = "sub_county_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['sub_county_name'];
$arr[1] = $d['contact_person'];
$arr[2] = $d['contact_phone'];
$arr[3] = $d['description'];
return $arr[$index];
}function get_ward_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "ward";
	$l->where = "ward_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['sub_county'];
$arr[1] = $d['ward_name'];
$arr[2] = $d['contact_person'];
$arr[3] = $d['contact_phone'];
$arr[4] = $d['description'];
return $arr[$index];
}

function get_chart_of_accounts_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "chart_of_accounts";
	$l->where = "chart_of_accounts_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['account_code'];
$arr[1] = $d['account_name'];
$arr[2] = $d['account_type'];
$arr[3] = $d['description'];
return $arr[$index];
}

function get_child_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "child";
	$l->where = "child_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['photo'];
$arr[1] = $d['registration_number'];
$arr[2] = $d['name'];
$arr[3] = $d['gender'];
$arr[4] = $d['date_of_birth'];
$arr[5] = $d['age'];
$arr[6] = $d['date_of_admission'];
$arr[7] = $d['previous_school'];
$arr[8] = $d['class'];
$arr[9] = $d['current_school'];
$arr[10] = $d['other_siblings'];
$arr[11] = $d['home_district'];
$arr[12] = $d['division'];
$arr[13] = $d['location'];
$arr[14] = $d['village'];
$arr[15] = $d['status'];
return $arr[$index];
}

function get_patient_next_of_kin_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "patient_next_of_kin";
	$l->where = "patient_next_of_kin_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['first_name'];
$arr[1] = $d['middle_name'];
$arr[2] = $d['last_name'];
$arr[3] = $d['relationship'];
$arr[4] = $d['gender'];
$arr[5] = $d['phone_number'];
$arr[6] = $d['other_phone_number'];
$arr[7] = $d['email'];
$arr[8] = $d['address'];
$arr[9] = $d['county'];
$arr[10] = $d['location'];
$arr[11] = $d['sub_location'];
return $arr[$index];
}


function get_organizations_status_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "organizations_status";
	$l->where = "organizations_status_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}

function get_organizations_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "organizations";
	$l->where = "organizations_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['organization_name'];
$arr[1] = $d['address'];
$arr[2] = $d['status'];
$arr[3] = $d['is_insurance'];
return $arr[$index];
}

function get_employment_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "employment";
	$l->where = "employment_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}

function get_sub_location_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "sub_location";
	$l->where = "sub_location_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}

function get_location_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "location";
	$l->where = "location_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}


function get_counties_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "counties";
	$l->where = "counties_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}

function get_patient_status_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "patient_status";
	$l->where = "patient_status_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}

function get_patient_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "patient";
	$l->where = "patient_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['photo'];
$arr[1] = $d['first_name'];
$arr[2] = $d['middle_name'];
$arr[3] = $d['last_name'];
$arr[4] = $d['date_of_birth'];
$arr[5] = $d['op_file_no'];
$arr[6] = $d['ip_file_no'];
$arr[7] = $d['residence'];
$arr[8] = $d['id_number'];
$arr[9] = $d['phone'];
$arr[10] = $d['gender'];
$arr[11] = $d['description'];
$arr[12] = $d['home_phone'];
$arr[13] = $d['other_phone'];
$arr[14] = $d['postal_address'];
$arr[15] = $d['email'];
$arr[16] = $d['county'];
$arr[17] = $d['location'];
$arr[18] = $d['sub_location'];
$arr[19] = $d['occupation'];
$arr[20] = $d['employment'];
$arr[21] = $d['employer'];
$arr[22] = $d['personal_doctor'];
$arr[23] = $d['doctor_phone'];
$arr[24] = $d['bill_as_staff'];
$arr[25] = $d['status'];
$arr[26] = $d['in_patient'];
$arr[27] = $d['first_name'].' '.$d['middle_name'].' '.$d['last_name'];
return $arr[$index];
}function get_gender_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "gender";
	$l->where = "gender_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}

function get_branch_type_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "branch_type";
	$l->where = "branch_type_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['type_name'];
$arr[1] = $d['description'];
return $arr[$index];
}

function get_branches_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "branches";
	$l->where = "branches_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['branch_name'];
$arr[1] = $d['branch_type'];
$arr[2] = $d['head_of_branch'];
$arr[3] = $d['phone'];
$arr[4] = $d['email'];
$arr[5] = $d['address'];
$arr[6] = $d['city'];
$arr[7] = $d['county'];
$arr[8] = $d['country'];
$arr[9] = $d['parent_branch'];
$arr[10] = $d['longitude'];
$arr[11] = $d['latitude'];
return $arr[$index];
}


function get_houses_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "houses";
	$l->where = "houses_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['house_name'];
$arr[1] = $d['building'];
$arr[2] = $d['category'];
$arr[3] = $d['availability'];
$arr[4] = $d['rent_price'];
$arr[5] = $d['per'];
$arr[6] = $d['longitude'];
$arr[7] = $d['latitude'];
$arr[8] = $d['address'];
$arr[9] = $d['client'];
return $arr[$index];
}

function get_house_photos_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "house_photos";
	$l->where = "house_photos_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['photo'];
$arr[1] = $d['pic_name'];
$arr[2] = $d['house'];
$arr[3] = $d['client'];
$arr[4] = $d['lon'];
$arr[5] = $d['lat'];
return $arr[$index];
}

function get_income_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "income";
	$l->where = "income_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['income_date'];
$arr[1] = $d['account'];
$arr[2] = $d['bank'];
$arr[3] = $d['amount'];
$arr[4] = $d['description'];
return $arr[$index];
}







function get_expenses_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "expenses";
	$l->where = "expenses_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['date'];
$arr[1] = $d['amount'];
$arr[2] = $d['description'];
return $arr[$index];
}function get_bank_account_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "bank_account";
	$l->where = "bank_account_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'] . " A/C # " . $d['account_number'];
$arr[1] = $d['account_number'];
$arr[2] = $d['street_address'];
$arr[3] = $d['contact_person'];
$arr[4] = $d['contact_name'];
return $arr[$index];
}function get_asset_management_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "asset_management";
	$l->where = "asset_management_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['tag'];
$arr[2] = $d['date_bought'];
$arr[3] = $d['status'];
$arr[4] = $d['department'];
$arr[5] = $d['date_disposed'];
return $arr[$index];
}
function get_station_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "station";
	$l->where = "station_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['region'];
$arr[2] = $d['route'];
return $arr[$index];
}function get_regions_dets_($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "regions";
	$l->where = "regions_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}function get_route_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "route";
	$l->where = "route_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}



function get_milk_grades_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "milk_grades";
	$l->where = "milk_grades_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['name'];
$arr[1] = $d['description'];
return $arr[$index];
}
function get_collections_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "collections";
	$l->where = "collections_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	
$arr[0] = $d['client'];
$arr[1] = $d['quantity'];
$arr[2] = $d['grade'];
$arr[3] = $d['status'];
return $arr[$index];
}
function get_department_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "department";
	$l->where = "department_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	$arr = array();
	$arr[0] = $d['department_name'];
	
	return $arr[$index];
}

public function get_company($index){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;

	$l->tbl = 'company';
	$l->pull();
	$d = mysqli_fetch_assoc($l->get_flag_desc());
	$a = array();
	$a[0] = $d['company_name'];
	$a[1] = $d['email'];
	$a[2] = $d['mobile'];
	$a[3] = $d['postal'];
	$a[4] = $d['city'];
	$a[5] = $d['country'];
	$a[6] = $d['next_term_begins'];
	$a[7] = $d['next_term_ends'];
	$a[8] = "Ksh";
	return $a[$index];
	
}
function check_access($module,$access_level,$control){
	$l = new lib;
	$h = $l->run_sql("select * from access_control where module = '$module' and access_level = '$access_level' and control = '$control' limit 1");
	
	$nums = mysqli_num_rows($h);
	
	if($nums > 0){
		return true;
	}else{
		return false;
	}

	//return(mysqli_fetch_assoc($h));		
}


function isAllowed($module,$control){
	@session_start();
	$user = $_SESSION['userid'];
	
	$l = new lib;
	$access_level = $l->get_user_dets(2,$user);
	$h = $l->run_sql("select * from access_control where module = '$module' and access_level = '$access_level' and control = '$control' limit 1");
	
	$nums = mysqli_num_rows($h);
	
	if($nums > 0){
		return true;
	}else{
		return false;
	}

	//return(mysqli_fetch_assoc($h));		
}



function get_array_obj($obj,$id){
	$l = new lib;
	$objid = $obj.'_id';
	return(mysqli_fetch_assoc($l->run_sql("select * from ".$obj." where ".$objid." = '$id'")));	
}
function get_all_data($mod){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = $mod;
	$l->pull();
	$h = $l->get_flag_desc();
	return $h;
}


function get_access_level_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "access_level";
	$l->where = "access_level_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	$arr[0] = $d['name'];
	
	return $arr[$index];
}

function get_user_dets($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->tbl = "user";
	$l->where = "user_id = '$id'";
	$l->pull();
	$h = $l->get_flag_desc();
	$d = mysqli_fetch_assoc($h);
	if(mysqli_num_rows($h)<1){
		return '';	
	}
	$arr = array();
	$arr[0] = $d['first_name'].' '.$d['other_names'];
	$arr[1]= $d['category'];
	$arr[2] = $d['access_level'];
	if(!empty($d['photo'])){
		$arr[3] = $d['photo'];
	}else{
		$arr[3] = "https://icons.iconarchive.com/icons/iynque/ios7-style/64/Users-icon.png";
	}
	$arr[4]= $d['active'];
	return $arr[$index];
}

public function get_mod_tot($tbl){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	
	$l->tbl = $tbl;
	$l->pull();
	$nums = mysqli_num_rows($l->get_flag_desc());
	
	
	return $nums;
	
}


public function get_user($index,$id){
	require_once('conn.php');
	require_once('lib.php');	
	$l = new lib;
	$l->where = "user_id = '$id'";
	$l->tbl = 'user';
	$l->pull();
	$d = mysqli_fetch_assoc($l->get_flag_desc());
	$a = array();
	$a[0] = $d['first_name'].' '.$d['other_names'];
	$a[1] = $d['email'];
	$a[2] = $d['mobile'];
	$a[3] = $d['access_level'];
	$a[4] = $d['category'];
	
	return $a[$index];
	
}

public function get_file_downloads($id){
	require_once('classes/conn.php');
	require_once('classes/lib.php');	
	$l = new lib;
	$l->where = "file_id = '$id'";
	$l->tbl = 'file_track';
	$l->pull();
	$d = mysqli_fetch_assoc($l->get_flag_desc());
	$nums = mysqli_num_rows($l->get_flag_desc());
	return $nums;
	
}

public function jawnie_git_update(){
	require_once('conn.php');
	require_once('classes/'.$this->classs.'.php');
			require_once('classes/lib.php');
			$l = new $this->classs;
			$lib = new lib;
			
			
			$str = '';
			$data = '';
			
			
			foreach($l->attr as $ob){
					//$str = $str."`".$ob."`,";
					$data = $data."`".$ob."`= '".mysqli_real_escape_string($this->con,$_POST[$ob])."',";
					//echo $ob;
			}	
			
			//$str = substr($str,0,strlen($str)-1);
			$data = substr($data,0,strlen($data)-1);
			
			$lib->data = $data;
			//$lib->str = $str;
			$lib->tbl = $this->tbl;
			$lib->where =$this->where;
			
			$lib->stack();
			if($lib->get_flag_status() != '1'){
				$lib->set_err_mess('Oops!',$lib->get_flag_desc());	
			}else{
				$this->flag_status = 1;
				if($this->callback__ == '1'){
				$lib->set_suc_mess('Great!',$l->suc_message);
				}
			}		
}
public function jawnie_git(){
	require_once('conn.php');
	
		require_once('classes/'.$this->classs.'.php');
	
			require_once('classes/lib.php');
			$l = new $this->classs;
			$lib = new lib;
			
			
			$str = '';
			$data = '';
			
			foreach($l->attr as $ob){
					$str = $str."`".$ob."`,";
					$data = $data."'".mysqli_real_escape_string($this->con,$_POST[$ob])."',";
			}	
			
			$str = substr($str,0,strlen($str)-1);
			$data = substr($data,0,strlen($data)-1);
			
			//die($_POST['body']);
			
			$lib->data = $data;
			$lib->str = $str;
			$lib->tbl = $this->tbl;
			
			
			$lib->push();
			if($lib->get_flag_status() != '1'){
				$this->flag_status = 0;
				$this->flag_desc =  $lib->get_flag_desc();
				
				if($this->callback__ == '1'){
					$lib->set_err_mess('Oops!',$lib->get_flag_desc());	
				}
				
			}else{
				$this->flag_status = 1;
				$this->lastid = $lib->lastid;
				if($this->callback__ == '1'){
				$lib->set_suc_mess('Great!',$l->suc_message);
				}
			}		
}
public function humanTiming ($time)
{

    $time = time() - $time; // to get the time since that moment

    $tokens = array (
        31536000 => 'year',
        2592000 => 'month',
        604800 => 'week',
        86400 => 'day',
        3600 => 'hour',
        60 => 'minute',
        1 => 'second'
    );

    foreach ($tokens as $unit => $text) {
        if ($time < $unit) continue;
        $numberOfUnits = floor($time / $unit);
        return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
    }

}

public function pull(){
	require_once('conn.php');
	if($this->where == null){
		$this->where = 1;	
	}
	
	if($this->group == null){
		$this->group = '';	
	}else{
		$this->group = ' group by '.$this->group;	
	}
	
	if($this->limit == null){
		$this->group = '';
	}else{
		$this->limit = ' limit '.$this->limit;
	}
	
	$g = mysqli_query($this->con,"select * from ".strtolower($this->tbl)." where ".$this->where.$this->group.$this->limit);
	if($g){
		$this->flag_status = '1';
		$this->flag_desc = $g;
	}else{
		$this->flag_desc = mysqli_error($this->con);	
	}	
}
public function del(){
	require_once('conn.php');
	if($this->where == null){
		$this->flag_desc = "Application parameters mismatch";
		return;	
	}
	
	$g = mysqli_query($this->con,"delete  from ".strtolower($this->tbl)." where ".$this->where);
	if($g){
		$this->flag_status = '1';
		$this->flag_desc = "Delete completed";
		if($this->callback__ == ''){
		$this->set_suc_mess('Done: ','Record deleted');
		}
	}else{
		$this->flag_desc = mysqli_error($this->con);	
	}	
}
public function formatSizeUnits($bytes)
    {
        if ($bytes >= 1073741824)
        {
            $bytes = number_format($bytes / 1073741824, 2) . ' GB';
        }
        elseif ($bytes >= 1048576)
        {
            $bytes = number_format($bytes / 1048576, 2) . ' MB';
        }
        elseif ($bytes >= 1024)
        {
            $bytes = number_format($bytes / 1024, 2) . ' KB';
        }
        elseif ($bytes > 1)
        {
            $bytes = $bytes . ' bytes';
        }
        elseif ($bytes == 1)
        {
            $bytes = $bytes . ' byte';
        }
        else
        {
            $bytes = '0 bytes';
        }

        return $bytes;
}
public function login($user,$pass){
		require_once('classes/conn.php');
		$this->tbl = 'user';
		$pass = base64_encode(mysqli_real_escape_string($this->con,$pass));
		$user = mysqli_real_escape_string($this->con,$user);
		$this->where = "password = '$pass' and email = '$user'";
		
		$this->pull();
		if($this->get_flag_status() != '1'){
			$this->add_trail("LOGIN FAILED",$user,"FAILED TO LOGIN",date("d/m/Y H:i:s"));
			$this->set_err_mess('Oops!',$this->get_flag_desc());	
		}else{
			$handle = $this->get_flag_desc();
			$n = mysqli_num_rows($handle);
			$res = array();
			if($n == 0){
				$res['status'] = "ERR";
				$res['message'] = "INVALID LOGIN DETAILS";
				return $res;
				//$this->set_err_mess('Oops!','Invalid login details');	
			}else{
				$d = mysqli_fetch_assoc($handle);
				if($d['active'] == 'NO'){
				$res['status'] = "ERR";
				$res['message'] = "ACCOUNT INACTIVE. CONTACT THE ADMINISTRATOR";
				return $res;	
				}
				
				if($d['active'] == 'SUSPENDED'){
				$res['status'] = "ERR";
				$res['message'] = "ACCOUNT SUSPENDED";
				return $res;	
				}
				
				
				
				$ha = mysqli_fetch_assoc($this->run_sql("select * from access_level where access_level_id = '".$d['access_level']."'"));
				
				if($ha['status'] != 'ACTIVE'){
					$res['status'] = "ERR";
					$res['message'] = "ACCESS LEVEL IS ".$ha['status'].". CONTACT ADMIN";
					return $res;
				}
				
				
				
				@session_start();	
				$_SESSION['userid'] = $d['user_id'];
				$_SESSION['uname'] =$d['first_name'].' '.$d['other_names'];
				$_SESSION['access_level'] = $d['access_level'];
				$_SESSION['email'] = $d['email'];
				$_SESSION['photo'] = $d['photo'];
				$_SESSION['category'] = $d['category'];
				$_SESSION['user_loc'] = $_SERVER['REMOTE_ADDR'];
				$_SESSION['department'] = $d['department'];
				$_SESSION['branch'] = $d['branch'];
				
				$this->add_trail("LOGIN SUCCESS",$d['user_id'],"LOGIN SUCCESSFUL",date("d/m/Y H:i:s"));
				
				$this->log("LOGIN",$d['user_id'],"LOGIN SUCCESSFUL","User logged in successfully");
				
				$res['status'] = 'SUCC';
				$res['message'] = "LOGIN SUCCESSFULL. REDIRECTING..";
				return $res;
				
			}	
			
		}
		
}
public function login_public($user,$pass){
		require_once('classes/conn.php');
		$this->tbl = 'owners';
		$pass = base64_encode($pass);
		
		$this->where = "password = '$pass' and email = '$user'";
		
		$this->pull();
		if($this->get_flag_status() != '1'){
			$this->set_err_mess('Oops!',$this->get_flag_desc());	
		}else{
			$handle = $this->get_flag_desc();
			$n = mysqli_num_rows($handle);
			if($n == 0){
				$this->set_err_mess('Oops!','Invalid login details');	
			}else{
				$d = mysqli_fetch_assoc($handle);
				@session_start();	
				$_SESSION['userid'] = $d['user_id'];
				$_SESSION['uname'] =$d['name'];
				
				$_SESSION['email'] = $d['email'];
				$_SESSION['pass'] = $d['password'];
				?>
                <script language="javascript" type="application/javascript">
                	window.location = "dashboard.php";
                </script>
                <?php
				header("Location:portal_access.php");
			}	
			
		}
		
}

public function n($string){
	if(!is_numeric($string)){
		$string = 0;
	}
	$j = new lib;
	$curr = $j->get_company(8);
	if(empty($curr)){
	    return number_format($string,2);
	}else{
		return $curr.number_format($string,2);
	}
	}
public function push(){
		//$this->set_par();
		require_once('conn.php');
		$sql = "insert into ".$this->tbl." (".$this->str.") values(".($this->data).")";
		//die($sql);
		if(mysqli_query($this->con,$sql)){
			$this->flag_status = '1';	
			$this->lastid = mysqli_insert_id($this->con);	
		}else{
			$this->flag_ststus = '0';
			$this->flag_desc = mysqli_error($this->con);	
		}
}

public function stack(){
		//$this->set_par();
		require_once('classes/conn.php');
		$sql = "update ".$this->tbl." set ".$this->data." where ".$this->where;
		//die($sql);
		if(mysqli_query($this->con,$sql)){
			$this->flag_status = '1';		
		}else{
			$this->flag_ststus = '0';
			$this->flag_desc = mysqli_error($this->con);	
		}
}
public function get_flag_status(){
		return $this->flag_status;	
}
public function get_flag_desc(){
		return $this->flag_desc;	
}
public function set_err_mess($head,$mess){
		?>
    <div class="alert error no-margin-top"> <span class="icon"></span><span class="close">x</span> <strong><?php echo $head; ?>!</strong> <?php echo $mess; ?></div>
    <?php	
}

public function set_suc_mess($head,$mess){
		?>
   <div class="alert success">
					<span class="icon"></span><span class="close">x</span>
					<strong><?php echo $head; ?></strong><?php echo $mess; ?>
				</div>
    <?php	
}
public function set_par(){
		switch($this->module){
			case '283987':{
				$this->tbl = 'customers';
				break;	
			}	
		
		}
		
}
	
public function get_user_session(){
	@session_start();
	return @$_SESSION['userid'];	
}
	
public function user(){
	@session_start();
	return @$_SESSION['userid'];	
}
public function git_jawnie(){
	$flg = $this->flg;
	if(!isset($flg)){
	?>
<div class="alert error no-margin-top">
					<span class="icon"></span><span class="close">x</span>
					<strong>Oops!</strong> Invalid object call encountered. Contact the administrator.
				</div>
    
    <?php
	die();	
}else{
	switch($flg){
		case '283987':	{
			include('classes/customer.php');
			require_once('classes/lib.php');
			$l = new customer;
			$lib = new lib;
			$lib->module = $flg;
			$lib->tbl = 'customers';
			$str = '';
			$data = '';
			//$_POST['timestamp'] = time();
			$_POST['password'] = base64_encode(rand(1000,9999));
			$_POST['password'] = base64_encode($_POST['email']);
			foreach($l->attr as $ob){
					$str = $str."`".$ob."`,";
					$data = $data."'".$_POST[$ob]."',";
					//echo $ob;
			}	
			$str = substr($str,0,strlen($str)-1);
			$data = substr($data,0,strlen($data)-1);
			$lib->data = $data;
			$lib->str = $str;
			
			
			
			$lib->push();
			if($lib->get_flag_status() != '1'){
				$lib->set_err_mess('Oops!',$lib->get_flag_desc());	
			}else{
				$lib->set_suc_mess('Great!',$l->suc_message);
			}
			break;
		}
		case '283991':	{
			include('classes/user.php');
			require_once('classes/lib.php');
			$l = new user;
			$lib = new lib;
			$lib->module = $flg;
			$lib->tbl = 'users';
			
			$str = '';
			$data = '';
			//$_POST['timestamp'] = time();
			//$_POST['password'] = base64_encode(rand(1000,9999));
			$_POST['password'] = base64_encode($_POST['email']);
			$_POST['userid'] = $lib->get_user_session();
			foreach($l->attr as $ob){
					$str = $str."`".$ob."`,";
					$data = $data."'".$_POST[$ob]."',";
					//echo $ob;
			}	
			$str = substr($str,0,strlen($str)-1);
			$data = substr($data,0,strlen($data)-1);
			$lib->data = $data;
			$lib->str = $str;
			
			
			
			$lib->push();
			if($lib->get_flag_status() != '1'){
				$lib->set_err_mess('Oops!',$lib->get_flag_desc());	
			}else{
				$lib->set_suc_mess('Great!',$l->suc_message);
			}
			break;
		}
	case '283989':{
		require_once('classes/lib.php');
		$lib = new lib;
		$lib->tbl = $this->tbl;
		$lib->where = $this->where;
		$lib->pull();
		
		if($lib->get_flag_status() != '1'){
				return $lib->set_err_mess('Oops!',$lib->get_flag_desc());	
		}else{
				//$lib->set_suc_mess('Data fetched.',"Data has been fetched successfully");
				return $hand = $lib->get_flag_desc();
		}
		break;	
	}
	
	/////Combos
	///groups user
	case '183989':{
		require_once('classes/lib.php');
		$lib = new lib;
		$lib->tbl = $this->tbl;
		$lib->where = $this->where;
		$lib->pull();
		
		if($lib->get_flag_status() != '1'){
				return $lib->set_err_mess('Oops!',$lib->get_flag_desc());	
		}else{
				//$lib->set_suc_mess('Data fetched.',"Data has been fetched successfully");
				$hand = $lib->get_flag_desc();
				
				while($d = mysqli_fetch_assoc($hand)){
					?>
                    <option value="<?php echo $d['group_name']; ?>"><?php echo $d['group_name']; ?></option>
                    <?php
				}
		}
		break;	
	}
	
	///customers
	case '183990':{
		require_once('classes/lib.php');
		$lib = new lib;
		$lib->tbl = $this->tbl;
		$lib->where = $this->where;
		$lib->pull();
		
		if($lib->get_flag_status() != '1'){
				return $lib->set_err_mess('Oops!',$lib->get_flag_desc());	
		}else{
				//$lib->set_suc_mess('Data fetched.',"Data has been fetched successfully");
				$hand = $lib->get_flag_desc();
				while($d = mysqli_fetch_assoc($hand)){
					?>
                    <option value="<?php echo $d['customer_id']; ?>"><?php echo $d['name'].', '.$d['customer_number']; ?></option>
                    <?php
				}
		}
		break;	
	}
	
	case '183991':{
		require_once('classes/lib.php');
		$lib = new lib;
		$lib->tbl = $this->tbl;
		$lib->where = $this->where;
		$lib->pull();
		
		if($lib->get_flag_status() != '1'){
				return $lib->set_err_mess('Oops!',$lib->get_flag_desc());	
		}else{
				//$lib->set_suc_mess('Data fetched.',"Data has been fetched successfully");
				$hand = $lib->get_flag_desc();
				while($d = mysqli_fetch_assoc($hand)){
					?>
                    <option value="<?php echo $d['user_id']; ?>"><?php echo $d['name'];?></option>
                    <?php
				}
		}
		break;	
	}
	///tickets categories
	case '183992':{
		require_once('classes/lib.php');
		$lib = new lib;
		$lib->tbl = $this->tbl;
		$lib->where = $this->where;
		$lib->pull();
		
		if($lib->get_flag_status() != '1'){
				return $lib->set_err_mess('Oops!',$lib->get_flag_desc());	
		}else{
				//$lib->set_suc_mess('Data fetched.',"Data has been fetched successfully");
				$hand = $lib->get_flag_desc();
				while($d = mysqli_fetch_assoc($hand)){
					?>
                    <option value="<?php echo $d['category_name']; ?>"><?php echo $d['category_name']; ?></option>
                    <?php
				}
		}
		break;	
	}
	
	
	
	////end groups
	case '283990':{
			include('classes/user_group.php');
			require_once('classes/lib.php');
			$l = new usergroups;
			$lib = new lib;
			$lib->module = $flg;
			$lib->tbl = 'user_groups';
			$str = '';
			$data = '';
			
			$_POST['userid'] = $lib->get_user_session();
			foreach($l->attr as $ob){
					$str = $str."`".$ob."`,";
					$data = $data."'".$_POST[$ob]."',";
					//echo $ob;
			}	
			$str = substr($str,0,strlen($str)-1);
			$data = substr($data,0,strlen($data)-1);
			$lib->data = $data;
			$lib->str = $str;
			
			
			
			$lib->push();
			if($lib->get_flag_status() != '1'){
				$lib->set_err_mess('Oops!',$lib->get_flag_desc());	
			}else{
				$lib->set_suc_mess('Great!',$l->suc_message);
			}
		break;	
	}
	
	////Ticket Categories
	case '283992':{
			include('classes/ticket_category.php');
			require_once('classes/lib.php');
			$l = new ticketcategory;
			$lib = new lib;
			$lib->module = $flg;
			$lib->tbl = 'ticket_categories';
			$str = '';
			$data = '';
			
			$_POST['userid'] = $lib->get_user_session();
			foreach($l->attr as $ob){
					$str = $str."`".$ob."`,";
					$data = $data."'".$_POST[$ob]."',";
					//echo $ob;
			}	
			$str = substr($str,0,strlen($str)-1);
			$data = substr($data,0,strlen($data)-1);
			$lib->data = $data;
			$lib->str = $str;
			
			
			
			$lib->push();
			if($lib->get_flag_status() != '1'){
				$lib->set_err_mess('Oops!',$lib->get_flag_desc());	
			}else{
				$lib->set_suc_mess('Great!',$l->suc_message);
			}
		break;	
	}
	
	///End
	case '283990':{
			include('classes/users.php');
			require_once('classes/lib.php');
			$l = new usergroups;
			$lib = new lib;
			$lib->module = $flg;
			$lib->tbl = 'users';
			$str = '';
			$data = '';
			
			$_POST['userid'] = $lib->get_user_session();
			foreach($l->attr as $ob){
					$str = $str."`".$ob."`,";
					$data = $data."'".$_POST[$ob]."',";
					//echo $ob;
			}	
			$str = substr($str,0,strlen($str)-1);
			$data = substr($data,0,strlen($data)-1);
			$lib->data = $data;
			$lib->str = $str;
			
			
			
			$lib->push();
			if($lib->get_flag_status() != '1'){
				$lib->set_err_mess('Oops!',$lib->get_flag_desc());	
			}else{
				$lib->set_suc_mess('Great!',$l->suc_message);
			}
		break;	
	}
	///Tasks
	//////rickets
	case '283994':	{
			include('classes/task.php');
			require_once('classes/lib.php');
			$l = new task;
			$lib = new lib;
			$lib->module = $flg;
			$lib->tbl = 'task';
			$str = '';
			$data = '';
			//$_POST['timestamp'] = time();
			$_POST['userid'] = $lib->get_user_session();
			foreach($l->attr as $ob){
					$str = $str."`".$ob."`,";
					$data = $data."'".$_POST[$ob]."',";
					//echo $ob;
			}	
			$str = substr($str,0,strlen($str)-1);
			$data = substr($data,0,strlen($data)-1);
			$lib->data = $data;
			$lib->str = $str;
			
			
			
			$lib->push();
			if($lib->get_flag_status() != '1'){
				$lib->set_err_mess('Oops!',$lib->get_flag_desc());	
			}else{
				$lib->set_suc_mess('Great!',$l->suc_message);
			}
			break;
		}
	///end tasks
	//////rickets
	case '283993':	{
			include('classes/ticket.php');
			require_once('classes/lib.php');
			$l = new ticket;
			$lib = new lib;
			$lib->module = $flg;
			$lib->tbl = 'ticket';
			$str = '';
			$data = '';
			//$_POST['timestamp'] = time();
			$_POST['userid'] = $lib->get_user_session();
			foreach($l->attr as $ob){
					$str = $str."`".$ob."`,";
					$data = $data."'".$_POST[$ob]."',";
					//echo $ob;
			}	
			$str = substr($str,0,strlen($str)-1);
			$data = substr($data,0,strlen($data)-1);
			$lib->data = $data;
			$lib->str = $str;
			
			
			
			$lib->push();
			if($lib->get_flag_status() != '1'){
				$lib->set_err_mess('Oops!',$lib->get_flag_desc());	
			}else{
				$lib->set_suc_mess('Great!',$l->suc_message);
			}
			break;
		}
	}	
	
}

}	
	
	
	
}


	









?>