<?php

class EmployeeAuthoritySetup {

    public static function AddEmployeeAuthority($data) {
        global $db;
        $id = $db->query_insert(TABLE_EMPLOYEE_AUTHORITY_SETUP, $data);
        return ($db->affected_rows > 0) ? $id : false;
    }

    public static function UpdateEmployeeAuthority($id, $data) {
        global $db;
        $result = $db->query_update(TABLE_EMPLOYEE_AUTHORITY_SETUP, $data, "id = '$id'");
        return $result;
    }
  
  public static function GetEmployeeAuthorityByName($name) {
    global $db;
    $query = "SELECT * FROM " . TABLE_EMPLOYEE_AUTHORITY_SETUP . " WHERE name = '{$name}' LIMIT 1";
    return $db->query_first($query);
}

    public static function GetEmployeeAuthorityById($id) {
        global $db;
        $query = "SELECT * FROM " . TABLE_EMPLOYEE_AUTHORITY_SETUP . " WHERE id = '$id'";
        $row = $db->query_first($query);
        return ($db->affected_rows > 0) ? $row : false;
    }

    public static function CheckDuplicateName($name, $category, $excludeId = 0) {
        global $db;
        $query = "SELECT * FROM " . TABLE_EMPLOYEE_AUTHORITY_SETUP . " 
                  WHERE name = '$name' AND category = '$category' AND id != '$excludeId'";
        $row = $db->query_first($query);
        return ($db->affected_rows > 0) ? $row : false;
    }

    public static function GetEmployeeAuthorityList($filter = "", $pageno = "null", $pagesize = "null") {
        global $db;
        $query = "SELECT * FROM " . TABLE_EMPLOYEE_AUTHORITY_SETUP . " $filter ORDER BY name";
      	echo $query;
        $rows = $db->fetch_all_array($query, $pageno, $pagesize);
        return ($db->affected_rows > 0) ? $rows : false;
    }

    public static function GetNumRows() {
        global $db;
        return $db->GetNumRows();
    }

    public static function GetNumberOfPages() {
        global $db;
        return $db->GetNumberOfPages();
    }
}
?>
