<?php   if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin_model extends CI_Model{
        
    public function __construct()
    {
        parent::__construct();
    }
    
    function checklogin()
    {
		$username = $this->input->post("username");
		$userpass = $this->input->post("userpass");
		if($username!="" && $userpass!="")
		{
			$this->db->select("*");
			$this->db->where("fld_username", $username);
			$this->db->where("fld_userpass", md5($userpass));
			$this->db->where("fld_status", "active");
			$result = $this->db->get("tbl_administrator");
			//echo $this->db->last_query();
			if($result->num_rows()>0)
			{
				$row = $result->row();
				$data = array(
					'sessID' => $row->fld_id,
					'sessName' => $row->fld_name,
					'sessUserName' => $row->fld_username,
					'sessType' => $row->fld_type,
					'sessEmail' => $row->fld_email,
					'sessLoggedInStatus' => true
					);
				$this->session->set_userdata('userLoggedIn', $data);
				return true;
			}
			else
			{
				return false;
			}			
		}
		
	}

	function manageuserpass($data, $currpass)
	{
		$returnvalue = "failed";
		$userid = $this->lguserinfo["sessID"];
		$this->db->select("*");
		$this->db->where("fld_id", $userid);
		$results = $this->db->get("tbl_administrator");
		if($results->num_rows()>0) // update if found
		{
			$row = $results->row();
			if($row->fld_userpass==md5($currpass))
			{
				$this->db->where('fld_id',$userid);
				$this->db->update("tbl_administrator", $data);
				$returnvalue = "success";
			}
			else
			{
				$returnvalue = "notmatched";
			}
		}
		return $returnvalue;
	}
	
        

}
?>
