<?php
error_reporting(1);
 //require_once(LIB_PATH.DS.'database4.php');



class ONLINEPAY {
	protected static $table_name="acceptance_tranzact";
	public $id;
	public $surname;
	public $othernames;
	public $othername;
	public $programme;
	public $date_time;
	public $txn_ref;


	public $session;
	public $start_session;
	public $semester;
	public $ses_sem_id;
	public $amount;
	public $batch;
	public $matricno;
	public $regDate;
	public $datetime;
	public $courses;
	public $course_code;
	public $course_title;
	public $course_unit;
	public $course_status;
	public $sex;
	public $pix;
	public $dob;
	public $lga;
	public $department;
	public $departmentcode;
	public $email;
	public $state;
	public $reg_date;
	public $admitted_date;
	public $number_of_student;
	public $faculty;
	public $facultycode;
	public $formno;
	public $fno;
	public $level;
	public $levelcode;
	public $overhead;
	public $phone;

	public $programmecode;
	public $ptype;
	public $responsecode;
	public $status;
	public $center;
	public $txt_fees;
	public $txt_ref;
	public $verified;
	public $verified_date;
	public $verified_by;
	public $deptcode;
	public $prog;
	public $processing;
	public $fullname;
	public $allAd;
	public $allAc;
	public $allSchl;
	public $allCr;
	public $ticket;
	public $ticket_title;
	public $subject;
	public $datecreated;
	
	
	public $feedback;
	public $resolvedon;
	
	
	public $message;
	public $attachment;
	public $response;
	public $sumAc;
	public $sumSchl;
	public $sumCr;
	public $matListCode;
	
//*********************** MATRIC LIST GENERATION *****************************//

public static function showmatricnm($dept="",$se="",$le=""){

global $database;

$sql = "SELECT admission_list.name AS name, admission_list.formno, student_activity_level.matricno 
    From admission_list 
    INNER JOIN student_activity_level 
    ON admission_list.formno = student_activity_level.formno
    WHERE admission_list.department='{$dept}' AND student_activity_level.start_session='{$se}'
    ";
    return self::find_by_sql($sql);
}


public static function findstucourse($tbl,$matricno)
{
    global $database;
    $matricno = $database->escape_value($matricno);
    
    $sql = "SELECT * FROM $tbl ";
    $sql .=" WHERE matricno='{$matricno}' order by ses_sem_id ";
    return self::find_by_sql($sql);
    
}
//************************                     *******************************//

//***********************TEST PASS QUERIES*************************************

public static function testpshowalltranzact($table, $dept="",$level="", $session=""){
global $database;
    $sql = "SELECT * FROM $table WHERE department='{$dept}' and level='{$level}' and session = '{$session}' and responsecode = '00' ORDER BY formno ASC ";
    
    return self::find_by_sql($sql);
}

//============================================================================





//***********************API QUERIES******************************************

public static function countacceptance($table,$start_date="", $end_date="", $prog="", $level="", $session=""){
    global $database;
    
     $sql = "SELECT count(*) as allAc, SUM(*) as sumAc FROM $table 
     WHERE datetime BETWEEN date('{$start_date}') 
     AND date('{$end_date}') AND level='{$level}' 
     AND session = '{$session}' AND formno like '%$prog%' 
     AND responsecode = '00' ";
    
     $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;
}

public static function countschoolfees($table,$start_date="", $end_date="", $prog="", $level="", $session=""){
    global $database;
    
    
     $sql = "SELECT count(*) as allSchl, SUM(*) as sumSchl FROM $table 
     WHERE datetime BETWEEN date('{$start_date}') 
     AND date('{$end_date}') AND level='{$level}' 
     AND session = '{$session}' AND formno like '%$prog%' 
     AND responsecode = '00' ";
    
     $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;
}


public static function countcertificate($table,$start_date="", $end_date="", $prog="", $level="", $session=""){
    global $database;
    
    $sql = "SELECT count(*) as allCr, SUM(*) as sumCr FROM $table 
     WHERE datetime BETWEEN date('{$start_date}') 
     AND date('{$end_date}') AND level='{$level}' 
     AND session = '{$session}' AND formno like '%$prog%' 
     AND responsecode = '00' ";
    
     $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;
}



//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public static function authenticate($formno="", $email=""){
global $database;
//$formno= $database->escape_value($formno);
//$email = $database->escape_value($email);
$sql = "SELECT * FROM ".self ::$table_name." ";
$sql .= " WHERE formno='{$formno}' ";
$sql .= "AND email='{$email}' LIMIT 1";
//$sql .= "AND responsecode = 'Successful' LIMIT 1" ;	

$result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;
}


public static function showdept(){
global $database;

$sql = "SELECT * FROM department_tbl" ;


return self::find_by_sql($sql);
//return !empty($result_array)? array_shift($result_array):
//false;
}

public static function shownoresult($ctable,$dept="",$ses_sem_id="",$date=""){
global $database;
$sql = "SELECT * FROM $ctable WHERE department = '{$dept}' AND  ses_sem_id = '{$ses_sem_id}' AND regDate > date('$date')";
return self::find_by_sql($sql);
}



public static function getcourses($dept="", $level="", $semester=""){
global $database;
$sql = "SELECT * FROM tbl_courses WHERE department = '{$dept}' AND  level = '{$level}' AND semester='{$semester}'";
return self::find_by_sql($sql);
}

public static function showsessiondetails( $table, $dept, $level, $session){
global $database;
$sql = "SELECT  * FROM $table WHERE department= '{$dept}' and level= '{$level}' and session= '{$session}' and responsecode = '00' ORDER BY formno ASC" ;
return self::find_by_sql($sql);

}

public static function showsessionfaculty( $table, $fac, $level, $session){
global $database;
$sql = "SELECT  * FROM $table WHERE faculty= '{$fac}' and level= '{$level}' and session= '{$session}' and responsecode = '00' ORDER BY formno ASC" ;
return self::find_by_sql($sql);

}

public static function showsessionprog( $table, $prog, $level, $session){
global $database;
$sql = "SELECT  * FROM $table WHERE formno like '%{$prog}%' and level= '{$level}' and session= '{$session}' and responsecode = '00' ORDER BY formno ASC" ;
return self::find_by_sql($sql);

}



public static function showalltranzact($table, $level="", $session=""){
global $database;
    $sql = "SELECT * FROM $table WHERE level='{$level}' and session = '{$session}' and responsecode = '00' ORDER BY level ASC ";
    
    return self::find_by_sql($sql);
}

// All accceptance paid here
public static function showallacceptance($table, $session=""){
global $database;
    $sql = "SELECT count(*) allAc FROM $table WHERE session = '{$session}'  and statusMessage = 'Successful'";
    
     $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;
}

public static function showalladmitted($table, $session=""){
global $database;
    $sql = "SELECT count(*) as allAd FROM $table WHERE start_session = '{$session}'";
    
     $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;
}

// GET ALL SCHOOL FEES FOR EACH LEVEL
public static function puallschoolfee($table, $formno='', $level="", $session=""){
global $database;
    $sql = "SELECT count(*) as allSchl FROM $table WHERE level='{$level}' and session = '{$session}' and responsecode = '00' and formno like '$formno%' ";
    
     $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;
}


//SELECT * FROM `schoolfees_tranzact` WHERE `formno` LIKE '%DP21%' AND `level` LIKE 'ND I' AND `responsecode` LIKE '00'

public static function pushowallschoolfee($table, $formno='', $level="", $session=""){
global $database;
    $sql = "SELECT count(*) as allSchl FROM $table WHERE formno like '$formno%' and responsecode = '00' and level like '{$level}'  ";
    
     $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;
}

public static function dpshowallschoolfee($table, $formno='', $level="", $session=""){
global $database;
    $sql = "SELECT count(*) as allSchl FROM $table WHERE formno like '$formno%'   and responsecode = '00' and level like'{$level}' ";
    
     $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;
}

public static function dpallschoolfee($table, $formno='', $level="", $session="",$form=""){
global $database;
    $sql = "SELECT count(*) as allSchl FROM $table WHERE formno like '$formno%' and responsecode = '00' and level='{$level}'  ";
    
     $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;
}

public static function fthnd1showallschoolfee($table, $formno='', $level="", $session=""){
 
 global $database;
    $sql = "SELECT count(*) as allSchl FROM $table WHERE level='{$level}' and session = '{$session}' and responsecode = '00' and formno like '$formno%' ";
    
     $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;   
}


public static function dphnd1showallschoolfee($table, $formno='', $level="", $session=""){
 
 global $database;
    $sql = "SELECT count(*) as allSchl FROM $table WHERE formno like '$formno%' and responsecode = '00' and level='{$level}' ";
    
     $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;   
}



public static function fthnd2showallschoolfee($table, $formno='',$level="", $session=""){
 
 global $database;
    $sql = "SELECT count(*) as allSchl FROM $table WHERE formno like '$formno%' and responsecode = '00' and level='{$level}' ";
    
     $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;   
}


public static function dphnd2showallschoolfee($table, $formno='', $level="", $session=""){
 
 global $database;
    $sql = "SELECT count(*) as allSchl FROM $table WHERE formno like '$formno%' and responsecode = '00' and level='{$level}' ";
    
     $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;   
}
// END OF GET

public static function searchbydatebackends($table,$session,$level, $start_date,$end_date){
    
    global $database;
//$start_date = date('yyyy-mm-dd', $start_date);
//$end_date = date('yyyy-mm-dd', $end_date);
$sql = "SELECT * FROM $table WHERE session='{$session}' and level='{$level}' and responsecode = '00' AND datetime BETWEEN date('{$start_date}') AND date('{$end_date}') ORDER BY formno " ;
return self::find_by_sql($sql);
}


public static function searchbydatebackend($table,$session, $start_date,$end_date){
    
    global $database;
//$start_date = date('yyyy-mm-dd', $start_date);
//$end_date = date('yyyy-mm-dd', $end_date);
$sql = "SELECT * FROM $table WHERE session='{$session}' and responsecode = '00' AND datetime BETWEEN date('{$start_date}') AND date('{$end_date}') ORDER BY formno " ;
return self::find_by_sql($sql);
}

public static function searchbydate($table, $start_date,$end_date){
global $database;
//$start_date = date('yyyy-mm-dd', $start_date);
//$end_date = date('yyyy-mm-dd', $end_date);
$sql = "SELECT * FROM $table WHERE responsecode = '00' AND datetime BETWEEN date('{$start_date}') AND date('{$end_date}') order by formno,level " ;
return self::find_by_sql($sql);
}

public static function searchbydateportal1($table, $start_date,$end_date){
global $database2;
//echo $database2->DB_NAME;
$sql = "SELECT * FROM $table WHERE responsecode = '00' AND date_time BETWEEN date('{$start_date}') AND date('{$end_date}') order by fno, level" ;
return $database2->query($sql);
}


public static function searchbyprogramme($tab, $prog, $level){
   global $database; 
    $sql = "SELECT * FROM $tab WHERE formno LIKE '%$prog%' AND level='{$level}' AND responsecode = '00'";
    return self::find_by_sql($sql);
}
public static function searchbydatesessionlevel($table,$level, $session, $start_date,$end_date){
global $database;

$sql = "SELECT * FROM $table WHERE level='{$level}' AND session = '{$session}' AND responsecode = '00' AND datetime BETWEEN date('{$start_date}') AND date('{$end_date}') " ;
return self::find_by_sql($sql);
}

public static function search_txtid($matricno=''){
global $database;
    $sql = "SELECT a.* FROM acceptance_tranzact a INNER JOIN student_activity_level s ON s.formno = a.formno WHERE s.matricno ='{$matricno}' AND a.responsecode = '00' LIMIT 1";
    $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):false;
}

public static function restrictBl(){
    global $database;
    $sql = "SET SQL_BIG_SELECTS=1"; 
    return self::find_by_sql($sql);
    
} 
    
public static function search_schoolfees_txtid($matricno){
global $database;
$sql = "SELECT a.* FROM schoolfees_tranzact a INNER JOIN student_activity_level s ON s.formno = a.formno WHERE s.matricno ='$matricno' AND a.responsecode = '00' ORDER BY a.level";
   return $result_array = self::find_by_sql($sql);

}


public static function update_txtid($table='', $tranzID='',$id=0){
global $database; global $connection;
$newdate = date('Y-m-d h:i:s');
    $sql = "UPDATE $table SET verified=1, verified_date='{$newdate}', verified_by={$id} WHERE txt_ref ='{$tranzID}' AND status = 'Approved Successful' ";
    //return self::find_by_sql($sql);
    	$database->query($connection, $sql);
return ($database->affected_rows()==1)? true: false;
}

//  Update activities level with Student Matric Number-------------------------

//*********************************** Course form editig code ********************************


public static function updatestucourse($table='',$sem='',$mat='')

{
    global $database;
    
    $sql = "UPDATE $table ";
    $sql .=" SET ses_sem_id=$sem WHERE matricno='{$mat}' LIMIT 1";
    
    	$database->query($connection, $sql);
//      return ($database->affected_rows()==1)? true: false;
return true;
 }



public static function deletestucourse($table,$mat='')

{
    global $database;
    
    $sql = "DELETE FROM $table ";
    $sql .=" WHERE matricno='{$mat}' LIMIT 1";
    
    	$database->query($connection, $sql);
     return ($database->affected_rows()==1)? true: false;
}

//********************************** Course form editing ends here ***************************

public static function update_matricno($table='', $mat='',$formno='',$email =''){
global $database; global $connection;
    $sql = "UPDATE $table SET matricno = $mat WHERE formno ='{$formno}' AND email = '{$email}' ";
    //return self::find_by_sql($sql);
    	$database->query($connection, $sql);
return true;
}


// .--------------------------------------------------------------------------

public static function showallbyfac($table, $facul="", $level="", $session=""){
    
    global $database;
    $sql = "SELECT * FROM $table WHERE faculty = '{$facul}'and level='{$level}' AND session = '{$session}' and status = 'Approved Successful'";
    
    return self::find_by_sql($sql);
}

// Display all Course Registered Students  search Class.........................
// public static function reg_students($table, $dept = "", $ses_sem_id){
//     global $database;
//     $sql = "SELECT * FROM $table WHERE ses_sem_id = '{$ses_sem_id}' AND department = '{$dept}'";
//     return self::find_by_sql($sql);
// }

public static function reg_students($table, $dept = "", $ses_sem_id, $batch){
    global $database;
    $sql = "SELECT $table.matricno,$table.courses,$table.department,$table.regDate,student_activity_level.matricno, student_activity_level.formno, student_activity_level.email, admitted_student_details.surname, admitted_student_details.othernames FROM $table JOIN student_activity_level ON $table.matricno =student_activity_level.formno JOIN admitted_student_details ON
    $table.matricno =admitted_student_details.formno
    WHERE student_activity_level.matricno !=0 AND $table.ses_sem_id = '{$ses_sem_id}' AND $table.department = '{$dept}' AND student_activity_level.batch= $batch ORDER BY student_activity_level.matricno";
    return self::find_by_sql($sql);
}
public static function student_Epass($table, $dept = "", $ses_sem_id){
    global $database;
    $sql = "SELECT * FROM $table JOIN student_activity_level ON $table.matricno =student_activity_level.matricno
    WHERE student_activity_level.matricno !=0 AND $table.ses_sem_id = '{$ses_sem_id}' AND $table.department = '{$dept}' ORDER BY student_activity_level.matricno";
    return self::find_by_sql($sql);
}


public static function student_EpassFirst($table, $dept = "", $ses_sem_id){
    global $database;
    $sql = "SELECT * FROM $table JOIN student_activity_level ON $table.matricno =student_activity_level.formno
    WHERE student_activity_level.matricno !=0 AND $table.ses_sem_id = '{$ses_sem_id}' AND $table.department = '{$dept}' ORDER BY student_activity_level.matricno";
    return self::find_by_sql($sql);
}
// ndi_tbl.matricno, ndi_tbl.ses_sem_id, ndi_tbl.department, ndi_tbl.courses, ndi_tbl.regDate, student_activity_level.matricno FROM ndi_tbl JOIN student_activity_level ON ndi_tbl.matricno =student_activity_level.matricno

public static function Epass_attendance($table, $dept = "", $ses_sem_id,$prog){
    global $database;
    $sql = "SELECT * FROM $table JOIN student_activity_level ON $table.matricno =student_activity_level.matricno
    WHERE student_activity_level.matricno !=0 AND student_activity_level.formno LIKE '%$prog%' AND $table.ses_sem_id = '{$ses_sem_id}' AND $table.department = '{$dept}' ORDER BY student_activity_level.matricno";
    return self::find_by_sql($sql);
}

public static function Epass_details($matricno=""){
    global $database;
    $sql = "SELECT * FROM admitted_student_details JOIN student_activity_level ON admitted_student_details.formno =student_activity_level.formno
    WHERE student_activity_level.matricno = '{$matricno}'";
    return self::find_by_sql($sql);
}


public static function Epass_detailsFirst($matricno=""){
    global $database;
    $sql = "SELECT * FROM admitted_student_details_2019 JOIN student_activity_level ON admitted_student_details_2019.formno =student_activity_level.formno
    WHERE student_activity_level.formno = '{$matricno}' ORDER BY student_activity_level.matricno";
    //return self::find_by_sql($sql);
    $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;
}


public static function reg_students1($table, $dept = "", $ses_sem_id,$prog = ""){
    global $database;
    $sql = "SELECT $table.matricno,$table.courses,student_activity_level.formno,student_activity_level.matricno,admitted_student_details.surname, admitted_student_details.othernames FROM $table JOIN student_activity_level ON $table.matricno =student_activity_level.formno JOIN admitted_student_details ON
    $table.matricno =admitted_student_details.formno
    WHERE student_activity_level.matricno !=0 AND $table.ses_sem_id = '{$ses_sem_id}' AND $table.department = '{$dept}' AND $table.matricno LIKE '%$prog%' ORDER BY student_activity_level.matricno";
    return self::find_by_sql($sql);
}



public static function get_ses_sem_id($session, $semester){
    global $database;
    $sql = "SELECT ses_sem_id FROM session_semester WHERE session = '$session' AND semester ='$semester'";
    return self::find_by_sql($sql);
}


// ------------------ Get details by formno -----------------------------

public static function getdetails($formno = ""){
    global $database;
    $sql = "SELECT * FROM admitted_student_details WHERE `formno` = '$formno' order by formno";
    return self::find_by_sql($sql);
}


// public static function getdetails($formno = "", $batch = ""){
// global $database;
// $sql = "SELECT student_activity_level.matricno,student_activity_level.email,student_activity_level.formno,admitted_student_details.surname,admitted_student_details.courses, admitted_student_details.othernames FROM student_activity_level JOIN admitted_student_details ON student_activity_level.formno =admitted_student_details.formno
//     WHERE student_activity_level.formno = '{$formno}' AND student_activity_level.batch = $batch AND student_activity_level.matricno != 0 order by student_activity_level.matricno";
//     return self::find_by_sql($sql);
// }



public static function state_details($formno = "", $state=""){
    global $database;
    $sql = "SELECT * FROM admitted_student_details WHERE `formno` = '$formno' AND 'state' = '$state'";
    return self::find_by_sql($sql);
}

// ---------------- Get States of Students-----------------------------------

public static function get_state(){
    global $database;
    $sql = "SELECT state FROM admitted_student_details GROUP BY state ORDER BY state ASC";
    return self::find_by_sql($sql);
}

// ---------------- get LGA of Students by state of origin......................
public static function state_lga($state = "", $level = "", $prog = ""){
    global $database;
    $sql = "SELECT distinct(schoolfees_tranzact.formno),schoolfees_tranzact.surname,schoolfees_tranzact.othernames,schoolfees_tranzact.department, schoolfees_tranzact.faculty,schoolfees_tranzact.email,schoolfees_tranzact.level, admitted_student_details.state, admitted_student_details.lga, admitted_student_details.sex, admitted_student_details.dob 
        FROM admitted_student_details JOIN schoolfees_tranzact
        ON admitted_student_details.formno = schoolfees_tranzact.formno
    WHERE admitted_student_details.state = '$state' AND schoolfees_tranzact.formno LIKE '%$prog%' AND schoolfees_tranzact.level = '$level' AND responsecode = '00' ORDER BY schoolfees_tranzact.surname ASC";
    return self::find_by_sql($sql);
}
// ---------------- get Update on Registered Student 2018/2019 session......................
// public static function reg_update($level = "", $prog = ""){
//     global $database;
//     $sql = "SELECT distinct(schoolfees_tranzact.formno),student_activity_level.matricno,schoolfees_tranzact.surname,schoolfees_tranzact.othernames,schoolfees_tranzact.department, schoolfees_tranzact.faculty,schoolfees_tranzact.email,schoolfees_tranzact.level, admitted_student_details.state, admitted_student_details.lga, admitted_student_details.sex, admitted_student_details.dob 
//         FROM admitted_student_details JOIN schoolfees_tranzact
//         ON admitted_student_details.formno = schoolfees_tranzact.formno JOIN student_activity_level ON admitted_student_details.formno = student_activity_level.formno WHERE admitted_student_details.programme = '$level' AND schoolfees_tranzact.formno LIKE '%$prog%' AND responsecode = '00' ORDER BY schoolfees_tranzact.surname ASC";
//     return self::find_by_sql($sql);
// }
public static function reg_update($level = "", $prog = ""){
    global $database;
    $sql = "SELECT distinct(student_activity_level.matricno),admitted_student_details.surname,admitted_student_details.othernames,admitted_student_details.courses,admitted_student_details.email,admitted_student_details.programme, admitted_student_details.state, admitted_student_details.lga, admitted_student_details.sex, admitted_student_details.dob 
        FROM admitted_student_details JOIN student_activity_level ON admitted_student_details.formno = student_activity_level.formno WHERE student_activity_level.matricno !=0 AND admitted_student_details.programme = '$level' AND admitted_student_details.formno LIKE '%$prog%' ORDER BY student_activity_level.matricno ASC";
    return self::find_by_sql($sql);
}




// ------------------Search Per Programme---------------------------------
public static function searchbyprog19($level = "", $prog = "",$dept=""){
    global $database;
    $sql = "SELECT * FROM admitted_student_details_2019
    WHERE `formno` LIKE '%$prog%' AND level LIKE '%$level%' AND department LIKE '%$dept%'";
    return self::find_by_sql($sql);
}
public static function searchbyprog($level = "", $prog = ""){
    global $database;
    $sql = "SELECT formno,surname,othernames,courses,programme,session,reg_date FROM admitted_student_details
    WHERE `formno` LIKE '%$prog%' AND programme LIKE '%$level%'";
    return self::find_by_sql($sql);
}
//--------------------END-------------------------------------------------
public static function getdeptcode($dept = ""){
    global $database;
    $sql = "SELECT * FROM department_tbl WHERE department='{$dept}' LIMIT 1";
    
    $result_array = self::find_by_sql($sql);
    return !empty($result_array)? array_shift($result_array):
false;

    //return self::find_by_sql($sql);
}

public static function getdeptOption($dept=""){
    
    global $database;
    
    $sql = "SELECT * FROM department_tbl WHERE department='$dept'";
    $result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array):
false;

}

//--------------------Restrict already assigned mat no---------------------

public static function restrictB(){
    global $database;
    $sql = "SET SQL_BIG_SELECTS=1"; 
    return self::find_by_sql($sql);
    
} 

public static function restrictformno($dept = "", $level = "", $prog = ""){
    global $database;
     
    $sql = " SELECT distinct(schoolfees_tranzact.formno),schoolfees_tranzact.surname,schoolfees_tranzact.othernames,student_activity_level.email,schoolfees_tranzact.department, schoolfees_tranzact.level
     from schoolfees_tranzact JOIN student_activity_level ON student_activity_level.formno = schoolfees_tranzact.formno
    WHERE  schoolfees_tranzact.department = '$dept' AND schoolfees_tranzact.formno like '$prog%' AND schoolfees_tranzact.level = '$level' 
     AND responsecode = '00' AND student_activity_level.matricno=0 ORDER BY surname ASC ";
    // where student_activity_level.formno = schoolfees_tranzact.formno AND schoolfees_tranzact.responsecode = '00' AND 
    return self::find_by_sql($sql);
    
} 



public static function restrictformno11($dept = "", $level = "", $prog = ""){
    global $database;
     
    $sql = " SELECT distinct(schoolfees_tranzact_remita.formno),schoolfees_tranzact_remita.surname,schoolfees_tranzact_remita.othernames,student_activity_level.email,schoolfees_tranzact_remita.department, schoolfees_tranzact_remita.level
     from schoolfees_tranzact_remita JOIN student_activity_level ON student_activity_level.formno = schoolfees_tranzact_remita.formno
    WHERE  schoolfees_tranzact_remita.department = '$dept' AND schoolfees_tranzact_remita.formno like '$prog%' AND schoolfees_tranzact_remita.level = '$level' 
     AND schoolfees_tranzact_remita.statusMessage = 'Successful' AND student_activity_level.matricno=0 ORDER BY surname ASC ";
    // where student_activity_level.formno = schoolfees_tranzact.formno AND schoolfees_tranzact.responsecode = '00' AND 
    return self::find_by_sql($sql);
    
} 


public static function auto_mat($dept = "", $level = "", $prog = ""){
    global $database;
    $sql = "SELECT student_activity_level.matricno from student_activity_level JOIN schoolfees_tranzact ON schoolfees_tranzact.formno =student_activity_level.formno
    WHERE schoolfees_tranzact.department = '$dept' AND schoolfees_tranzact.formno LIKE '$prog%' AND schoolfees_tranzact.level = '$level' 
    AND responsecode = '00' order by matricno desc LIMIT 1";
    return self::find_by_sql($sql);
} 


public static function auto_mat11($dept = "", $level = "", $prog = ""){
    global $database;
    $sql = "SELECT student_activity_level.matricno from student_activity_level JOIN schoolfees_tranzact_remita ON schoolfees_tranzact_remita.formno =student_activity_level.formno
    WHERE schoolfees_tranzact_remita.department = '$dept' AND schoolfees_tranzact_remita.formno LIKE '$prog%' AND schoolfees_tranzact_remita.level = '$level' 
    AND responsecode = '00' order by matricno desc LIMIT 1";
    return self::find_by_sql($sql);
} 

public static function view_matricno($dept = "", $level = "", $prog = ""){
    global $database;
    $sql = "SELECT distinct(student_activity_level.matricno),admitted_student_details.surname,admitted_student_details.othernames,admitted_student_details.courses,admitted_student_details.email,admitted_student_details.programme, admitted_student_details.state, admitted_student_details.lga, admitted_student_details.sex, admitted_student_details.dob 
        FROM admitted_student_details JOIN student_activity_level ON admitted_student_details.formno = student_activity_level.formno WHERE student_activity_level.matricno !=0 AND admitted_student_details.courses = '$dept' AND admitted_student_details.formno LIKE '%$prog%' AND admitted_student_details.programme = '$level' AND student_activity_level.matricno!=0 ORDER BY matricno ASC";
    return self::find_by_sql($sql);
} 



//----------------------- Transcript Methods -------------------

public static function MsgUpdate($table2, $ticket,$response='')
{
    global $database;
    global $connection;
    
    $sql = "UPDATE $table2 set status='{$response}' WHERE ticket='{$ticket}' LIMIT 1";
    
    if ($database->query($connection, $sql)){
		//$this->id=$database->insert_id();
		return true;
	}else {
		return false;
	}
}
           
  public static function ContentUpdate($table1, $ticket,$response='')
  {
     global $database;
    global $connection;
    
    $sql = "UPDATE $table1 set response='{$response}' WHERE ticket='{$ticket}' LIMIT 1";
    
    if ($database->query($connection, $sql)){
		//$this->id=$database->insert_id();
		return true;
	}else {
		return false;
	} 
  }

public static function allmsg($access='')

{
    global $database;
    
    $sql = "SELECT m.*, t.*, c.*  from transcript_messages m ";
    
    $sql .= " INNER JOIN enquiry t ON m.subject = t.ticket_title ";
    
    $sql .=" INNER JOIN transcript_content c ON m.ticket = c.ticket ";
    
    $sql .=" WHERE t.office= '{$access}' AND m.status!='Answered' ";
     return self::find_by_sql($sql);
}
public static function find_cert_name1($table, $ptype=""){
    global $database;
    $sql = "SELECT * FROM $table WHERE ptype='$ptype' AND responsecode ='00' AND processing=0 ORDER BY fullname ASC";
     return self::find_by_sql($sql);
}

public static function find_omoluabi_cert_name1($table){
    global $database;
    $sql = "SELECT * FROM $table WHERE responsecode ='00' ORDER BY datetime ASC";
     return self::find_by_sql($sql);
}
public static function get_name_by_mat1($table, $matricno=""){
    global $database;
    $sql = "SELECT * FROM $table WHERE matricno='$matricno' AND responsecode='00' AND processing=0";
     return self::find_by_sql($sql);
}

public static function find_other_certificate_details1($table, $ptype="", $matricno=""){
    global $database;
    $sql = "SELECT fullname, email FROM $table WHERE matricno='{$matricno}' AND ptype='{$ptype}' AND responsecode !='00' LIMIT 1";
     
     $result_array = self::find_by_sql($sql);
     return !empty($result_array) ? array_shift($result_array) : false;

    
//return !empty($result_array)? array_shift($result_array) : false;

}
public static function update_completed_certificate1($table, $ptype='', $matricno=''){
    global $database; global $connection;
    $sql = "UPDATE $table SET processing=1 WHERE ptype='$ptype' AND matricno='$matricno' LIMIT 1";
      
    if ($database->query($connection, $sql)){
		//$this->id=$database->insert_id();
		return true;
	}else {
		return false;
	}
}


public static function find_other_certificate_details_completed1($table){
    global $database;
    $sql = "SELECT * FROM $table WHERE responsecode='00' AND processing=1 ";
     return self::find_by_sql($sql);
     //$result_array = self::find_by_sql($sql);
    
//return !empty($result_array)? array_shift($result_array) : false;

}


public static function find_other_certificate_details_pending1($table){
    global $database;
    $sql = "SELECT * FROM $table WHERE  responsecode='00' AND processing=0 ";
     return self::find_by_sql($sql);
   //return  $result_array = self::find_by_sql($sql);
   
//return !empty($result_array)? array_shift($result_array) : false;

}

public static function bursary_certificate_details1($table, $ptype = "", $level = ""){
    global $database;
    $sql = "SELECT * FROM $table WHERE responsecode='00' AND processing = 0 AND ptype = '$ptype' AND level='$level' ";
     return self::find_by_sql($sql);

}






// ----------------------Certificate Methods ------------------

public static function find_cert_name($table, $ptype=""){
    global $database;
    $sql = "SELECT * FROM $table WHERE ptype='$ptype' AND responsecode='00' AND processing=0 ORDER BY fullname ASC";
     return self::find_by_sql($sql);
}

public static function find_omoluabi_cert_name($table, $start_date, $end_date){
    global $database;
    $sql = "SELECT * FROM $table WHERE responsecode='00' AND datetime BETWEEN date('{$start_date}') AND date('{$end_date}') ORDER BY datetime, ptype ASC";
    
     return self::find_by_sql($sql);
}
public static function get_name_by_mat($table, $matricno=""){
    global $database;
    $sql = "SELECT * FROM $table WHERE matricno='$matricno' AND responsecode='00' AND processing=0";
     return self::find_by_sql($sql);
}

public static function find_other_certificate_details($table, $ptype="", $matricno=""){
    global $database;
    $sql = "SELECT fullname, email FROM $table WHERE matricno='{$matricno}' AND ptype='{$ptype}' AND responsecode='00' LIMIT 1";
     
     $result_array = self::find_by_sql($sql);
     return !empty($result_array) ? array_shift($result_array) : false;

    
//return !empty($result_array)? array_shift($result_array) : false;

}
public static function update_completed_certificate($table, $ptype='', $matricno=''){
    global $database; global $connection;
    $sql = "UPDATE $table SET processing=1 WHERE ptype='$ptype' AND matricno='$matricno' LIMIT 1";
      
    if ($database->query($connection, $sql)){
		//$this->id=$database->insert_id();
		return true;
	}else {
		return false;
	}
}


public static function find_other_certificate_details_completed($table){
    global $database;
    $sql = "SELECT * FROM $table WHERE responsecode='00' AND processing=1 ";
     return self::find_by_sql($sql);
     //$result_array = self::find_by_sql($sql);
    
//return !empty($result_array)? array_shift($result_array) : false;

}


public static function find_other_certificate_details_pending($table){
    global $database;
    $sql = "SELECT * FROM $table WHERE  responsecode='00' AND processing=0 ";
     return self::find_by_sql($sql);
   //return  $result_array = self::find_by_sql($sql);
   
//return !empty($result_array)? array_shift($result_array) : false;

}

public static function bursary_certificate_details($table, $ptype = "", $level = ""){
    global $database;
    $sql = "SELECT * FROM $table WHERE responsecode='00' AND processing = 0 AND ptype = '$ptype' AND level='$level' ";
     return self::find_by_sql($sql);

}



// ------------------Search Per Department and Programm-------------------------


public static function searchbydptprog($dept = "", $level = "", $prog = ""){
    global $database;
    $sql = "SELECT distinct(formno),surname,othernames,department,email,level FROM schoolfees_tranzact
    WHERE department = '$dept' AND `formno` LIKE '$prog%' AND level = '$level' AND responsecode = '00' ORDER BY surname ASC";
    return self::find_by_sql($sql);
}



public static function searchbydptprog11($dept = "", $level = "", $prog = ""){
    global $database;
    $sql = "SELECT distinct(formno),surname,othernames,department,email,level FROM schoolfees_tranzact_remita
    WHERE department = '$dept' AND `formno` LIKE '$prog%' AND level = '$level' AND statusMessage = 'Successful' ORDER BY surname ASC";
    return self::find_by_sql($sql);
}
public static function search_prog($level = "", $prog = ""){
    global $database;
    $sql = "SELECT * FROM schoolfees_tranzact
    WHERE `formno` LIKE '%$prog%' AND programme = '$level' AND responsecode = '00' ORDER BY surname ASC";
    return self::find_by_sql($sql);
}


public static function deptlev($dept = "", $level = ""){
    global $database;
    $sql = "SELECT * FROM schoolfees_tranzact
    WHERE department = '$dept' AND programme = '$level' AND responsecode = '00' ORDER BY surname ASC";
    return self::find_by_sql($sql);
}

//--------------------END-------------------------------------------------


public static function showdept_byf($faculty=""){
global $database;
$sql = "SELECT department FROM department_tbl WHERE faculty = '$faculty'" ;
return self::find_by_sql($sql);
}

public static function showdept_HoD($HoD=""){
global $database;
$sql = "SELECT department FROM department_tbl WHERE department = '$HoD'" ;
return self::find_by_sql($sql);
}

public static function showsession(){
global $database;
$sql = "SELECT  distinct (session) FROM session_semester where status='active'";

return $result_array = self::find_by_sql($sql);

}

public static function showsemester(){
global $database;
$sql = "SELECT distinct(semester) FROM session_semester" ;
return self::find_by_sql($sql);
}

public static function search_by_formno($formno){
global $database;
$sql = "SELECT * FROM admitted_students WHERE formno = '{$formno}'" ;
return self::find_by_sql($sql);
}

public static function search_by_formno_18($ctable, $formno=""){
global $database;
$sql = "SELECT * FROM $ctable WHERE formno = '{$formno}' LIMIT 1" ;
$result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array) : false;
}

public static function search_by_date($start_date,$end_date){
global $database;
$sql = "SELECT * FROM admitted_students WHERE admitted_date BETWEEN '{$start_date}' AND '{$end_date}'" ;
return self::find_by_sql($sql);
}

public static function search_all($level,$prog){
global $database;

$sql = "SELECT distinct(admission_status.formno),admitted_student_details.surname, admitted_student_details.othernames, admitted_student_details.programme, admitted_student_details.courses FROM admission_status JOIN admitted_student_details ON admitted_student_details.formno = admission_status.formno WHERE admission_status.formno LIKE '%$prog%' AND admitted_student_details.programme = '$level' GROUP BY admission_status.formno";
return self::find_by_sql($sql);

}

public static function search_session($dept,$level,$prog = ""){
global $database;

$sql = "SELECT distinct(admission_status.formno), admitted_student_details.surname, admitted_student_details.othernames, admitted_student_details.programme, admitted_student_details.courses FROM admission_status JOIN admitted_student_details ON admitted_student_details.formno = admission_status.formno WHERE admission_status.formno LIKE '%$prog%' AND admitted_student_details.programme = '$level' AND admitted_student_details.courses = '$dept' GROUP BY admission_status.formno";
return self::find_by_sql($sql);

}


public static function search_level($level, $session){
global $database;
// $date_search = self :: search_by_date()
$sql = "SELECT  * FROM admitted_students WHERE level= '{$level}' AND session= '{$session}' ORDER BY department ASC";
return self::find_by_sql($sql);
}


public static function search_level_count($level, $session){
global $database;
$sql = "SELECT department, COUNT(formno) FROM admitted_students WHERE level= '{$level}' AND session= '{$session}' GROUP BY department";
return self::find_by_sql($sql);
}

public static function search_date($dept, $level, $session, $start_date, $end_date){
global $database;
// $date_search = self :: search_by_date()
$sql = "SELECT  * FROM admitted_students WHERE department= '{$dept}' OR level= '{$level}' OR session= '{$session}' OR admitted_date BETWEEN '{$start_date}' AND '{$end_date}'";
return self::find_by_sql($sql);
}

// spread sheet-----------------------------------------------
public static function fetch_all_course($department, $level, $semester)
{
    global $database;
    $sql = "SELECT * FROM tbl_courses WHERE department = '$department' AND  level = '$level' AND semester = '$semester' ORDER BY course_code ASC";
    return self::find_by_sql($sql);
}
// get names and matric no for spread sheets......................
public static function spread_details($dept,$lev,$prog){
    global $database;
    $sql = "SELECT distinct(student_activity_level.matricno), student_activity_level.formno, student_activity_level.email, admitted_student_details.surname, admitted_student_details.othernames FROM student_activity_level JOIN admitted_student_details ON admitted_student_details.formno = student_activity_level.formno WHERE student_activity_level.matricno !=0 AND admitted_student_details.courses = '$dept' AND admitted_student_details.programme = '$lev' AND student_activity_level.formno LIKE '%$prog%' ORDER BY student_activity_level.matricno ASC";
    return self::find_by_sql($sql);
}
    




public static function joined_tables(){
global $database;
// $formno_class = self::showpayment_online("admission_status");
// $formno = $formno_class->formno;
// $sql = "SELECT  * FROM admission_status JOIN admitted_student_details ON admission_status.formno = admitted_student_details.formno";
$sql = "SELECT  * FROM status JOIN admitted_student_details ON status.formno = admitted_student_details.formno";
return self::find_by_sql($sql);
}


public function insert_table($formno,$surname,$othername,$email,$department,$sex,$level,$session,$admitted_date){
global $database;
	$sql = "INSERT INTO admitted_students (";
    // $sql = "INSERT INTO admitted_student (";
	$sql .= "formno,surname,othernames,email,department,sex,level,session,admitted_date";
	$sql .= ") 	VALUES ('";
	$sql .= $database->escape_value($formno)."', '"	;
	$sql .= $database->escape_value($surname)."', '";
	$sql .= $database->escape_value($othername)."', '";
	$sql .= $database->escape_value($email)."', '";
	$sql .= $database->escape_value($department)."', '";
	$sql .= $database->escape_value($sex)."', '";
	$sql .= $database->escape_value($level)."', '";
	$sql .= $database->escape_value($session)."', '";
	$sql .= $database->escape_value($admitted_date)."') ";
	
	if ($database->query($sql))
	{
// 		$id=$database->insert_id();
		return true;
	}else {
		return false;
	}
	
}





public static function showpayment_online($table=""){
global $database;
$sql = "SELECT * FROM {$table}" ;
return self::find_by_sql($sql);

}

public static function get_phone($table="",$prog="",$depart="",$level="",$session=""){
   global $database; 
    $sql = "SELECT * FROM {$table} WHERE formno LIKE '%$prog%' AND department= '{$depart}' AND programme='{$level}' 
    AND session='{$session}' AND responsecode = '00'";
    
    
    return self::find_by_sql($sql);
}

public static function getMatricNo($formno="", $session=""){
global $database;
$sql = "SELECT matricno, formno FROM student_activity_level WHERE formno = '{$formno}' LIMIT 1" ;
$result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array) : false;   
}


public static function getStudent($level="", $prog="", $department=""){
global $database;

$sql = "Select admission_list.department, count(*) as number_of_student, admission_list.admitted_date,student_activity_level.start_session FROM student_activity_level inner join admission_list ON student_activity_level.formno=admission_list.formno INNER join student_accountg ON student_activity_level.email=student_accountg.email WHERE  student_accountg.level='{$level}' and student_activity_level.formno like '$prog%' and admission_list.department='{$department}' group by admission_list.department order by admission_list.department";
        

 return $result_array = self::find_by_sql($sql);
//return !empty($result_array)? array_shift($result_array) : false;   
}

public static function getStudentI($level="", $prog="", $department=""){
global $database;

$sql = "Select admission_list.department, count(*) as number_of_student, admission_list.admitted_date,student_activity_level.start_session FROM student_activity_level inner join admission_list ON student_activity_level.formno=admission_list.formno INNER join student_accountg ON student_activity_level.email=student_accountg.email WHERE student_activity_level.matricno!=0 and student_accountg.level='{$level}' and student_activity_level.formno like '$prog%' and admission_list.department='{$department}' group by admission_list.department order by admission_list.department";
        

 return $result_array = self::find_by_sql($sql);
//return !empty($result_array)? array_shift($result_array) : false;   
}


public static function getStudentII($level="", $prog="", $department=""){
global $database;

$sql = "Select admission_list.department, count(*) as number_of_student, admission_list.admitted_date, student_activity_level.start_session FROM student_activity_level inner join admission_list ON student_activity_level.formno=admission_list.formno INNER join student_accountg ON student_activity_level.email=student_accountg.email WHERE  student_accountg.level='{$level}' and student_activity_level.formno like '$prog%' group by admission_list.department order by admission_list.department";
        

return $result_array = self::find_by_sql($sql);
//return !empty($result_array)? array_shift($result_array) : false;   
}

public static function getStudentIII($level="", $prog=""){
global $database;

$sql = "Select admission_list.department, count(*) as number_of_student, admission_list.admitted_date, student_activity_level.start_session FROM student_activity_level inner join admission_list ON student_activity_level.formno=admission_list.formno INNER join student_accountg ON student_activity_level.email=student_accountg.email WHERE  student_accountg.level='{$level}' and student_activity_level.formno like '$prog%' group by admission_list.department order by admission_list.department";
        

return $result_array = self::find_by_sql($sql);
//return !empty($result_array)? array_shift($result_array) : false;   
}
public static function getMatricNoRes($formno=""){
global $database;
$sql = "SELECT matricno, formno FROM student_activity_level WHERE formno = '{$formno}' LIMIT 1" ;
$result_array = self::find_by_sql($sql);
return !empty($result_array)? array_shift($result_array) : false;
}

public static function get_phone18($table="",$depart="",$prog="", $level="",$session=""){
   global $database; 
    $sql = "SELECT {$table}.formno,{$table}.surname,{$table}.othernames,{$table}.department,
    {$table}.level,admitted_student_details.phone,admitted_student_details.dob,admitted_student_details.lga,admitted_student_details.state
    FROM {$table} JOIN admitted_student_details ON {$table}.formno = admitted_student_details.formno 
    WHERE {$table}.formno LIKE '%$prog%' AND {$table}.department= '{$depart}' AND {$table}.programme='{$level}' 
    AND {$table}.session='{$session}' AND responsecode = '00'";
    return self::find_by_sql($sql);
}

public static function get_all_matric_all(){
   global $database; 
   
$sql="SET SQL_BIG_SELECTS=1";

   return self::find_by_sql($sql);
}

public static function get_all_matric($depart="",$prog="", $level=""){
   global $database; 
   
 $sql = "SELECT distinct(m.matricno),s.surname,s.othernames,m.formno FROM schoolfees_tranzact s INNER JOIN student_activity_level m ON s.formno=m.formno WHERE s.department='$depart' AND m.formno like '$prog%' AND s.level='$level' AND m.matricno!=0 AND m.std_process_id > 3 ORDER BY m.matricno";
    return self::find_by_sql($sql);
}



public static function t_processing($id=0, $curr_session=""){
	
global $database;
$user_data = Userdata::find_by_id($id);
 $biodata = Biodata::find_by_id($user_data->formno,$user_data->email);
 $dp = DEPARTMENTCLASS::department_authenticate($biodata->courses);
$alldp = DEPARTMENTCLASS::find_all($dp->faculty);
foreach ($alldp as $aldp){
	$faculty = $aldp->faculty;
}
if ($faculty=='Engineering'or $faculty=='Applied Sciences'or $faculty=='Enviromental Studies'){
$pay_cat='science';	
}elseif ($faculty=='Management Sciences'){
	$pay_cat='nonscience';
}
$level = $biodata->programme;
 $level = $level." "."I";
$time = date('Y-m-d h:i:s');
$a = (substr(rand(1, 10000000000),0,10));
					$txt_ref = $a.(substr( $biodata->surname,0,2));	


$pay_settings=Pay_settings::find_by_id(1,$level,$pay_cat);

$sql = "INSERT INTO ".self ::$table_name ." (";
$sql .= "formno,surname, othername,faculty,department,programme,phone,email,session,level,txt_ref,amount,txt_fees,overhead,datetime,status,responsecode";

$sql .= ") VALUES ('";
$sql .= $biodata->formno."', '";
$sql .= $biodata->surname."', '";
$sql .= $biodata->othernames. "', '";
$sql .=$biodata->courses. "', '";
$sql .=$biodata->courses. "', '";
$sql .=$biodata->programme."', '";
$sql .= $biodata->phone."', '";
$sql.=$biodata->email."', '";
$sql .= $curr_session ."', '";
$sql .=$biodata->programme."', '";
$sql .=$txt_ref."' ,'";
$sql.= $pay_settings->amount."', '"; 
$sql .=$pay_settings->charge_interswitch + $pay_settings->charge_omoluabi."' ,'";
$sql .=$pay_settings->charge_interswitch + $pay_settings->charge_omoluabi."' ,'";
$sql .= $time. "' ,'" ;
$sql .=$biodata->programme."', '";
$sql .='Approved Successful'.
"')" ;

if ($database->query($sql)){
		//$this->id=$database->insert_id();
		return true;
	}else {
		return false;
	}
	
//$result_array = self::find_by_sql($sql);
//return !empty($result_array)? array_shift($result_array) : false;
//return $result_array;

}
public function fullname(){
	
if (isset($this->formno)&& isset($this->username)){
	return $this->formno ." ". $this->username;	
	} else {
		return "";
	}
}



//Common database Methods
public static function find_all(){
	global $database;
	return self::find_by_sql("SELECT * FROM ".self:: $table_name);
	//return $result_set;
	
}
public static function find_by_id($id=0){
	global $database;
	$result_array = self::find_by_sql("SELECT * FROM  ".self::$table_name." WHERE id={$id} LIMIT 1");
	//$found = $database->fetch_array($result_set);
	//return $found;
	return !empty($result_array)? array_shift($result_array) : false;
	
}

public static function find_by_sql($sql=""){
	  global $database; $connection='';
        $result_set = $database->query($connection, $sql);
        $object_array = array();
        while ($row = $database->fetch_array($result_set)) {
            $object_array[] = self::instantiate($row);
        }
        return $object_array;

	
}
private static function instantiate($record){
	
	$object = new self;
	foreach ($record as $attribute=>$value){
	if ($object->has_attribute($attribute)){
	$object->$attribute = $value;
	}
		
	}
	return $object;
}
private function has_attribute($attribute){
	
$object_vars = get_object_vars($this);
return array_key_exists($attribute,$object_vars);	
}

public function save(){
return isset($this->id) ?	$this->update() : $this->create();	
}

public function create(){
global $database;
	$sql = "INSERT INTO ".self ::$table_name." (";
	$sql .= "formno, email";
	$sql .= ") 	VALUES ('";
	$sql .= $database->escape_value($this->formno)."', '"	;
	$sql .= $database->escape_value($this->email)."') '"	;
	if ($database->query($sql)){
		$this->id=$database->insert_id();
		return true;
	}else {
		return false;
	}
	
}

public function update(){
	
	global $database;
	$sql = "UPDATE ".self ::$table_name."(";
	$sql .="formno = '". $database->escape_value($this->formno)."',"; 
	$sql .= "email ='". $database->escape_value($this->email)."', ";	
	$sql .= "WHERE id=". $database->escape_value($this->id);
	
	$database->query($sql);
return ($database->affected_rows()==1)? true: false;
	}
public function delete(){
	
global $database;
$sql = "DELETE FROM ".self ::$table_name." ";
$sql .= "WHERE id=" . $database->escape_value($this->id);
$sql .= " LIMIT 1";	
$database->query($sql);
return ($database->affected_rows() ==1) ? true: false;
}

//Closing tags for user's class
}
$onlinepay = new ONLINEPAY();
?>