<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of adminmodel
 *
 * @author BusyMan
 */
class adminmodel extends CI_Model {

    //put your code here
    private $_table = "tbl_admin";

    public function __construct() {
        parent::__construct();
    }

    public function login_info() {

        $user_check = $this->db->get_where($this->_table, array(
            'userName' => $this->security->xss_clean($this->input->post('username')),
            'password' => $this->security->xss_clean($this->input->post('password'))
            // 'password' => $this->security->xss_clean(sha1(md5($this->input->post('password'))))
        ));

        if ($user_check->num_rows() > 0) { // check 
            $rec = $user_check->row_array();

            $admin_id = $rec['admin_id'];
            $admin_username = $rec['userName'];
            $admin_name = $rec['admin_name'];
            $admin_email = $rec['admin_email'];
            $admin_access = $rec['admin_access'];
            $employeeId = $rec['employeeId'];
            $admin_level = $rec['admin_level'];
            $admin_info = array(// user info retrive 
                'admin_id' => $admin_id,
                'admin_username' => $admin_username,
                'admin_name' => $admin_name,
                'admin_email' => $admin_email,
                'admin_access' => $admin_access,
                'employeeId' => $employeeId,
                'admin_level' => $admin_level,
                'login_validation' => TRUE
            );
            return $admin_info;
//        print_r($admin_info); exit;
        } else {
            return FALSE;
        }
    }

    public function checkpassword($data) {
        $query = $this->db->get_where($this->_table, array('password' => $data['courrentPassword'],
        // $query = $this->db->get_where($this->_table, array('password' => sha1(md5($data['courrentPassword'])),
            'admin_id' => $data['admin_id'],
            'userName' => $data['userName'],
            'admin_name' => $data['admin_name'],
            'admin_email' => $data['admin_email'],
            'admin_access' => $data['admin_access'],
            'employeeId' => $data['employeeId'],
            'admin_level' => $data['admin_level']
                )
        );
        $result = $query->row_array();
        if (!empty($result)) {
            return $result;
        }
    }

    public function updatePassword($data) {
        // $datax['password'] = sha1(md5($data['password']));
        // $this->db->update($this->_table, $datax, array('admin_id' => $data['admin_id'], 'employeeId' => $data['employeeId']));
        // return $this->db->affected_rows();


        /* ---------amother process query ----------------------
          $this->db->set('password',sha1(md5($data['password'])))
          ->where('admin_id',$data['admin_id'])
          ->where('employeeId',$data['employeeId'])
          ->update($this->_table);
          -------------------------------------------------------------------- */
    }

}
