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

class Card extends DatabaseObject
{
    protected static $table_name = "admission_card_pin";
    public $id;
    public $pin;
    public $serial_no;

    public $status;
    public $std_id;
    public $formno;
    public $acc_id;
    public $logintimedate;
    
    
    
    
    public static  function accid($id)
    {
        global $database;

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

         $sql = "SELECT * FROM ". static::$table_name ." " ;
         $sql .= " WHERE acc_id='$id' AND status='used' LIMIT 1 ";
 
        $result_array = self::find_by_sql($sql);

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


         
         

    } 


   public static function update_pin($pin='', $serial_no='', $id='')

   {

      global $database;$connection;
        //  $pin = $database->escape_value($connection, $pin);
        //  $serial_no = $database->escape_value($connection, $serial_no);

        //  $id = $database->escape_value($connection, $id);
         
         
        //  $formno = $database->escape_value($formno);

         $sql = "UPDATE ".self::$table_name." ";
         $sql .="SET status= 'used', acc_id= $id, logintimedate=NOW() ";
         $sql .="WHERE pin='$pin' AND serial_no='$serial_no'  LIMIT 1";

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

   }
        
        public static function update_form($pin='', $serial_no='',$id='',$formno='')

   {

      global $database;$connection;
        //  $pin = $database->escape_value($connection,$pin);
        //  $serial_no = $database->escape_value($connection,$serial_no);
        
        // $id = $database->escape_value($connection, $id);
         
        //  $formno = $database->escape_value($connection, $formno);

         $sql = "UPDATE ".self::$table_name." ";
         $sql .="SET status= 'used', acc_id= $id, formno='$formno', logintimedate=NOW() ";
         $sql .="WHERE pin='$pin' AND serial_no='$serial_no'  LIMIT 1";

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

   }

    

public static  function check_pin($pin='', $serial_no='')
    {
        global $database;
        $pin = $database->escape_value($pin);
        $serial_no = $database->escape_value($serial_no);
        
       
           

        $sql = "SELECT * FROM admission_card_pin ";
         $sql .= " WHERE pin='$pin' and serial_no='{$serial_no}' limit 1 ";
 
         
     $result_array = self::find_by_sql( $sql);
        return !empty($result_array) ? array_shift($result_array) : false;



    

    }



   
//Common database Methods

}
 $card = new Card();
?>