<?php
require_once(LIB_PATH . DS . 'database.php');

class Online extends DatabaseObject
{
    protected static $table_name = "admission_online_payment";
    public $id;


    public $surname;
    public $othernames;
    public $email;
    public $department;
    public $level;
    public $formno;
    public $token;


    public $acc_id;
    public $txt_ref;
    public $amount;
    public $txt_fee;
    
    public $status;
    public $responsecode;
    public $responsedesc;
   
    
    
    public $title;
    public $phone;
    public $dob;
    public $sex;
    public $hometown;
    public $nationality;
    public $state;
    public $lga;
    public $religion;
    public $marital;

    public $sitting;

    public $examno;
    public $examno2;
    public $examyear;
    public $examyear2;
    public $sub1;
    public $sub2;
    public $sub3;
    public $sub4;
    public $sub5;
    public $institution;
    public $grag;

    public $gragD;

   

    public static function check_id($stdid='')
    {
        global $database;
        
         $stdid = $database->escape_value($stdid);
         
        $sql = "SELECT * FROM ".self::$table_name." ";
        $sql .= " WHERE acc_id= '$stdid' and responsecode='00' LIMIT 1";
        
         $result_array = self::find_by_sql($sql);
        return !empty($result_array) ? array_shift($result_array) : false;

    }
    
     public static function check_failed_trans($stdid='')
    {
        global $database;
        
         $stdid = $database->escape_value($stdid);
         
        $sql = "SELECT * FROM ".self::$table_name." ";
        $sql .= " WHERE acc_id= '$stdid'  ";
        
        return $result_array = self::find_by_sql($sql);
       // return !empty($result_array) ? array_shift($result_array) : false;

    }
    
    
    public static function fetch_trans($trans='')
    {
        global $database;
        
         //$trans = $database->escape_value($trans);
         
        $sql = "SELECT a.*, s.* FROM admission_online_payment a INNER JOIN student_account s  ";
        $sql .=" ON s.id = a.acc_id ";
        $sql .= " WHERE txt_ref= '$trans' LIMIT 1";
        
         $result_array = self::find_by_sql($sql);
        return !empty($result_array) ? array_shift($result_array) : false;

    }
    public static function update_formno($stdid='',$formno='')
    {
        
        global $database; $connection;
         $stdid = $database->escape_value($stdid);
         $formno = $database->escape_value($formno);
         
          $sql = "UPDATE ". self::$table_name." ";
        $sql .= " SET formno = '$formno', gen=1 ";
        $sql .= " WHERE acc_id='$stdid' and responsecode='00' LIMIT 1";
        
        
         if ($database->query($connection,$sql)) {
          
            return true;
          
        } else {
           return false;
          
        }
        
         
    }
    public static function respUpdate($responsedesc='', $responsecode='', $submittedref='')
    {
        
        global $database; $connection;
        
        //  $responsedesc = $database->escape_value($responsedesc);
        //  $responsecode = $database->escape_value($responsecode);
        //  $submittedref = $database->escape_value($submittedref);
        
        $sql = "UPDATE ". self::$table_name." ";
        $sql .= " SET status = '$responsedesc', responsecode='$responsecode' ";
        $sql .= " WHERE txt_ref='$submittedref' LIMIT 1";
        
        
         if ($database->query($connection,$sql)) {
          
            return true;
          
        } else {
           return false;
          
        }
        
        
        
    }

    public static function acc_online($id=''){

        global $database;

        $id = $database->escape_value($id);

        $sql = "SELECT * FROM student_account  "; 
       
        $sql .=" WHERE activated='Y' AND id='{$id}' LIMIT 1";

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

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

    }


    public static function fetch_stu_data($id='')

{
    global $database;
    
        $id = $database->escape_value($id);
         $amount = $database->escape_value($amount);
         $txt_ref = $database->escape_value($txt_ref);
         
    $sql = "SELECT a.*, s.* FROM admission_online_payment a ";
    $sql.=" INNER JOIN student_account s ON a.acc_id=s.id ";
    $sql .=" WHERE a.acc_id=$id AND s.activated='Y' ";
    $sql .= " AND a.status!='Approved Successful' LIMIT 0,1";
    
      $result_array = self::find_by_sql($sql);

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

    }
    
    
    

    public static function submit_stu_data($id='',$amount='',$txt_fee='',$txt_ref='',$ftype='')
    {
        global $database; $connection='';
        
         $id = $database->escape_value($id);
         $ftype = $database->escape_value($ftype);
         $amount = $database->escape_value($amount);
         $txt_ref = $database->escape_value($txt_ref);
         $txt_fee=$database->escape_value($txt_fee);
         
         $sql = "INSERT INTO admission_online_payment (";
        $sql .= "acc_id,formno,txt_ref,amount,txt_fee ";

        $sql .= ") VALUES ('";
        $sql .= $id . "', '";
        $sql .= $ftype . "', '";
        $sql .= $txt_ref . "', '";
        $sql .= $amount . "', '";
        $sql .= $txt_fee . "'
        
            )";
            
         if ($database->query($connection,$sql)) {
           
            return true;
         
        } else {
           return false;
           
        }
       
    }

         
         
         
    
  
    // public static function update_payment_details($id,$status,$responseCode){

    //         global $database; $connection='';
    //         $id = $database->escape_value($id);
    //         $passport = $database->escape_value($passport);

    //         $sql = "UPDATE ".self::$table_name." ";
    //         $sql .= "SET status='{$status}', responsecode='{$responseCode}' WHERE acc_id='{$id}' LIMIT 1";

    //  if ($database->query($connection,$sql)) {
    //         //$this->id=$database->insert_id();
    //         return true;
    //       // return 'Success';
    //     } else {
    //       return false;
    //         // return 'Error'; 
    //     }

    // }
    
    
    public static function saveInfo($stdid='', $title='', $phone='', $dob='', $sex='', $home='', $nationality='', $state='',$lga='', $religion='', $marital=''){

        global $database;$connection='';

        $stdid = $database->escape_value($stdid);
        $title = $database->escape_value($title);
        
        $phone = $database->escape_value($phone);
        $dob = $database->escape_value($dob);

        $sex = $database->escape_value($sex);
        $home = $database->escape_value($home);

        $nationality = $database->escape_value($nationality);
        $state = $database->escape_value($state);

       $lga = $database->escape_value($lga);
       $religion = $database->escape_value($religion);

       $marital = $database->escape_value($marital);

       $sql = "INSERT INTO ".self::$table_name." (";
        $sql .= "acc_id,title,phone,dob, sex, hometown, nationality, state, lga, religion, marital ";

        $sql .= ") VALUES ('";
        $sql .= $stdid . "', '";
        $sql .= $title . "', '";
        $sql .= $phone . "', '";
        $sql .= $dob . "', '";
        $sql .= $sex . "', '";
        $sql .= $home . "', '";

        $sql .= $nationality . "', '";
        $sql .= $state . "', '";
        $sql .= $lga . "', '";

        $sql .= $religion . "', '";
        $sql .= $marital . "'
              
            )";

        if ($database->query($connection,$sql)) {
            //$this->id=$database->insert_id();
            return true;
          // return 'Success';
        } else {
           return false;
            // return 'Error'; 
        }
    }

    
//Common database Methods

}
 $biodata = new Biodata();
?>