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

class Home extends DatabaseObject
{
    protected static $table_name = "admin";
    public $id;
    public $surname;
    public $othernames;
    public $username;
    public $password;
   
    
   
    
   


public static function get_staff_login_details($username="", $password="")
{
    global $database;

    $sql = "SELECT * FROM ".self::$table_name."  WHERE username = '$username' AND password='$password' LIMIT 1";
    $result_array = self::find_by_sql($sql);
    return !empty($result_array) ? array_shift($result_array) : false;

}

public static function get_staff_single_details($id=""){

  global $database;
  
      $sql = "SELECT * FROM ".self::$table_name." WHERE id=$id LIMIT 1 ";
      $result_array = self::find_by_sql($sql);
    return !empty($result_array) ? array_shift($result_array) : false;

}

public static function get_single_news($table,$nid)
{
  global $database; 

  $sql = "SELECT * FROM $table WHERE nid=$nid LIMIT 1 ";
      $result_array = self::find_by_sql($sql);
    return !empty($result_array) ? array_shift($result_array) : false;                    

 }


public static function get_latest_news($table)
{
global $database;

$sql = "SELECT * FROM $table order by nid desc LIMIT 1 ";
      $result_array = self::find_by_sql($sql);
    return !empty($result_array) ? array_shift($result_array) : false; 

}

public static function get_certain_news($table)
{

    global $database;
  
      $sql = "SELECT * FROM $table order by nid desc limit 10 ";
     return $result_array = self::find_by_sql($sql);
    //return !empty($result_array) ? array_shift($result_array) : false;
}

public static function get_all($table){

  global $database;
  
      $sql = "SELECT * FROM $table ORDER BY id ";
     return $result_array = self::find_by_sql($sql);
   // return !empty($result_array) ? array_shift($result_array) : false;

}


public static function get_all_by_orders($table){

  global $database;
  
      $sql = "SELECT * FROM $table ORDER BY orders ASC";
     return $result_array = self::find_by_sql($sql);
   // return !empty($result_array) ? array_shift($result_array) : false;

}


public static function status ($key=""){

  global $database;
  
      $sql = "SELECT * FROM accesstbl WHERE access='{$key}' AND status= 1 LIMIT 1 ";
      $result_array = self::find_by_sql($sql);
    return !empty($result_array) ? array_shift($result_array) : false;

}


public static function check_st(){
    global $database;
   // $staffno = $database->escape_value($staffno);

    $sql = "SELECT id FROM " . self::$table_name . " ORDER BY id DESC LIMIT 0,1 ";
   // $sql .= " WHERE staffno='{$staffno}' ";
        
     $result_array = self::find_by_sql($sql);
    return !empty($result_array) ? array_shift($result_array) : false;


}

    public static function lu($id="",$email="",$question="",$answer="")
    {
        global $database;
        $id = $database->escape_value($id);
        $email = $database->escape_value($email);
        $question = $database->escape_value($question);
        $answer = $database->escape_value($answer);
    
        $sql = "SELECT count(*) as found FROM " . self::$table_name . " ";
        $sql .= " WHERE id= $id AND email='{$email}' ";
        $sql .= "AND question='{$question}' AND answer='{$answer}'  LIMIT 1";
         
        $result_array = self::find_by_sql($sql);
        return !empty($result_array) ? array_shift($result_array) : false;
//return $result_array;
    }


    public static function authenticate($matricno="",$email = "")
    {
        global $database;
        $matricno = $database->escape_value($matricno);
        $email = $database->escape_value($email);
   
    // }
        $sql = "SELECT * FROM " . self::$table_name . " ";
        $sql .= " WHERE matricno='{$matricno}' ";
        $sql .= "AND email='{$email}' and status='open' LIMIT 1";
         
        $result_array = self::find_by_sql($sql);
        return !empty($result_array) ? array_shift($result_array) : false;
//return $result_array;
    }

    public function fullname()
    {
        global $database;
        if (isset($this->title) && isset($this->surname) && isset($this->othernames)) {
            return ucfirst($this->title)." ".strtoupper($this->surname)."," . " " . ucfirst($this->othernames);
        } else {
            return "";
        }
    }
    public static function insert_member($table, $orders='', $photo='', $fullname='', $status='',$designation=''){
        global $database;
        $orders = $database->escape_value($orders);
        $photo = $database->escape_value($photo);
        $fullname = $database->escape_value($fullname);
        $status = $database->escape_value($status);
        $designation = $database->escape_value($designation);
       
        $sql = "INSERT INTO $table (";
        $sql .= "orders, photo, fullname, status,designation";

        $sql .= ") VALUES ('";
        $sql .= $orders . "', '";
      
        $sql .= $photo . "', '";
        $sql .= $fullname . "', '";
        $sql .= $status . "', '";
          
        $sql .= $designation . "'
       
            )";

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


    }




     public static function insert_member_hod($table, $orders='',$deanid='', $photo='', $fullname='', $status='',$designation=''){
        global $database;
        $orders = $database->escape_value($orders);
        $deanid = $database->escape_value($deanid);
        $photo = $database->escape_value($photo);
        $fullname = $database->escape_value($fullname);
        $status = $database->escape_value($status);
        $designation = $database->escape_value($designation);
       
        $sql = "INSERT INTO $table (";
        $sql .= "orders,deanid, photo, fullname, status,designation";

        $sql .= ") VALUES ('";
        $sql .= $orders . "', '";
        $sql .= $deanid . "', '";
      
        $sql .= $photo . "', '";
        $sql .= $fullname . "', '";
        $sql .= $status . "', '";
          
        $sql .= $designation . "'
       
            )";

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


    }

   
}

//Common database Methods
 $home = new Home();
?>