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

class Biodata extends DatabaseObject
{
    protected static $table_name = "form_data22";
    public $id;


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

    public $txt_ref;
    public $amount;
    public $responsecode;
    public $status;
    
    
    public $acc_id;
    public $passport;
    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 $jinstitution;
    public $institution;
    public $grag;

    public $gragD;
    public $datetime;
    public $itcompany;
    public $dstarted;
    public $dcompleted;
    public $gen;

   public static function fetchdetails($formno)
   {
       global $database;
       
        $sql="SELECT s.*,f.* FROM form_data22 f INNER JOIN student_account s ON s.id=f.acc_id";
       $sql.=" WHERE formno='$formno' LIMIT 1";
       
        $result_array = self::find_by_sql($sql);

     return !empty($result_array) ? array_shift($result_array) : false;
       
   }
   public static function checkStudentonlinepayment($stdid)
   {
       global $database;
       
        $sql="SELECT * FROM admission_online_payment ";
       $sql.=" WHERE acc_id={$stdid} and gen=1 LIMIT 1";
       
        $result_array = self::find_by_sql($sql);

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

     return !empty($result_array) ? array_shift($result_array) : false;
       
   }
   
   public static function restrictB(){
    global $database;
    $sql = "SET SQL_BIG_SELECTS=1"; 
    return self::find_by_sql($sql);
    
} 
   public static function checkStudentDetails($stdid)
   {
       global $database;
       
       $sql="SELECT * FROM ".self::$table_name." ";
       $sql.=" WHERE acc_id={$stdid} LIMIT 1";
       
        $result_array = self::find_by_sql($sql);

     return !empty($result_array) ? array_shift($result_array) : false;
     
   }
    public static function fetch_last_id(){

        global $database;
        

        $sql = "SELECT * FROM ".self::$table_name." ";
        $sql .=" ORDER BY id DESC LIMIT 1";

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

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

    }

    public static function track_stu($table='', $id=''){

        global $database;

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

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

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

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

    }


    public static function track_bio_aca($table='', $id=''){

        global $database;

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

        $sql = "SELECT * FROM $table ";
        $sql .=" WHERE acc_id='{$id}' LIMIT 1";

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

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

    }

public static function track_online_pay($table='', $id=''){

        global $database;

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

        $sql = "SELECT * FROM $table ";
        $sql .=" WHERE acc_id='{$id}' and responsecode='00' LIMIT 1";

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

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

    }

    public static function reportonline($table, $id=''){

        global $database;

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

        $sql = "SELECT s.id,s.surname,s.othernames,s.department,s.email,s.level,f.*, c.* FROM student_account s "; 
        $sql .=" INNER JOIN  {$table} f ON s.id = f.acc_id ";
           
        $sql .=" INNER JOIN admission_online_payment c ON f.acc_id=c.acc_id ";
        
        $sql .=" WHERE s.activated='Y' AND s.id='{$id}' LIMIT 1";

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

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

    }

public static function report($table, $id=''){

        global $database;

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

        $sql = "SELECT s.id,s.surname,s.othernames,s.department,s.email,s.level,f.*, c.* FROM student_account s "; 
        $sql .=" INNER JOIN  {$table} f ON s.id = f.acc_id ";
           
        $sql .=" INNER JOIN admission_card_pin c ON f.acc_id=c.acc_id ";
        
        $sql .=" WHERE s.activated='Y' AND s.id='{$id}' LIMIT 1";

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

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

    }


// public static function report1($table, $id=''){

//         global $database;

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

//         $sql = "SELECT s.*, a.*,c.* FROM student_account s "; 
       
//         $sql .= "INNER JOIN {$table} a ON s.id=a.acc_id ";
//         $sql .=" INNER JOIN admission_online_payment c ON a.acc_id=c.acc_id ";
//         $sql .=" WHERE s.activated='Y' AND s.id='{$id}' AND c.responsecode='00' LIMIT 1";

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

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

//     }



       public static function chkPass($id=''){
           
           global $database;
           $id = $database->escape_value($id);
           
           $sql = " SELECT * from form_data ";
           $sql .= " WHERE acc_id = $id LIMIT 1 ";
           
            $result_array = self::find_by_sql($sql);

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

           
       }
        
        
        public static function report2($id=''){

        global $database;

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

        $sql = "SELECT s.*, a.* FROM student_account s "; 
       
        $sql .= "INNER JOIN academics_data a ON s.id=a.acc_id ";
       
        $sql .=" WHERE s.activated='Y' AND s.id='{$id}' LIMIT 1";

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

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

    }
    
    
     public static function report22($table, $id){

        global $database;

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

        $sql = "SELECT s.*,f.*,c.* FROM student_account s "; 
        $sql .=" INNER JOIN  $table f ON s.id = f.acc_id ";
        $sql .=" INNER JOIN admission_online_payment c ON f.acc_id=c.acc_id ";
        $sql .=" WHERE s.activated='Y' AND s.id='{$id}' AND c.responsecode='00' LIMIT 1";

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

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

    }

         public static function reQuery($id='', $amount=''){

        global $database;

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

        $sql = "SELECT s.*, a.* FROM student_account s "; 
        $sql .=" INNER JOIN  admission_online_payment a ON s.id = a.acc_id ";
        
        $sql .=" WHERE a.acc_id='{$id}' and amount='{$amount}' order by a.id desc limit 0,100";

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

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

    }
   public static function Cform($id=''){

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

      $sql = "SELECT * FROM ".self::$table_name." ";
         
      $sql .= " WHERE acc_id='{$id}' limit 1 ";
 
         
        $result_array = self::find_by_sql($sql);

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


   }
    public static function up_formno($id='', $passport=''){

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

            $sql = "UPDATE ".self::$table_name." ";
            $sql .= "SET passport='{$passport}' 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='',$formno='', $title='', $phone='', $dob='', $sex='', $home='', $nationality='', $state='',$lga='', $religion='', $marital=''){

        global $database;$connection='';

        $stdid = $database->escape_value($stdid);
        $formno = $database->escape_value($formno);
        $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,formno,title,phone,dob, sex, hometown, nationality, state, lga, religion, marital ";

        $sql .= ") VALUES ('";
        $sql .= $stdid . "', '";
        $sql .= $formno . "', '";
        $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();
?>