197 lines
6.2 KiB
PHP
197 lines
6.2 KiB
PHP
<?php
|
|
if (!defined('BASEPATH'))
|
|
exit('No direct script access allowed');
|
|
|
|
class Commonsql_model extends CI_Model {
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
}
|
|
|
|
function insert_table($tableName, $tableData = array()) {
|
|
// Insert the user record
|
|
if (isset($tableData) && count($tableData) > 0) {
|
|
$this->db->insert($tableName, $tableData);
|
|
return $this->db->insert_id();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/* get the data to table
|
|
* $tableName -> Name of the table
|
|
* $whereData -> Array -> where fields
|
|
* $showField -> Array -> what are the fields need to show
|
|
* */
|
|
|
|
public function selectTable($tableName, $whereData = array(), $showField = array('*'), $order = '') {
|
|
|
|
$this->db->select($showField);
|
|
$this->db->from($tableName);
|
|
if (!empty($whereData) > 0) {
|
|
$this->db->where($whereData);
|
|
}
|
|
if ($order != '') {
|
|
$this->db->order_by($order,"DESC");
|
|
}
|
|
/*if (count($limit>0)) {
|
|
//$this->db->limit($limit[0],$limit[1]);//example $limit[0] = "0,10" where 0 is for offset and 10 for limit
|
|
}*/
|
|
$query = $this->db->get();
|
|
|
|
return $query;
|
|
}
|
|
|
|
|
|
/* update the data to table
|
|
* $tableName -> Name of the table
|
|
* $whereData -> Array -> where fields
|
|
* $updateData -> Array -> updated fields and data
|
|
* */
|
|
|
|
public function updateTable($tableName, $whereData = array(), $updateData = array()) {
|
|
$this->db->where($whereData);
|
|
$this->db->update($tableName, $updateData);
|
|
$return = $this->db->affected_rows() > 0;
|
|
return $return;
|
|
//$query->result_array();
|
|
//$query->num_rows();
|
|
}
|
|
|
|
/* update the data to table
|
|
* $tableName -> Name of the table
|
|
* $whereData -> Array -> where fields
|
|
* $updateData -> Array -> updated fields and data
|
|
* */
|
|
|
|
public function deleteTableData($tableName, $whereData = array()) {
|
|
// Insert the user record
|
|
if (isset($whereData) && count($whereData) > 0) {
|
|
$insert_id = $this->db->delete($tableName, $whereData);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function user($username,$password)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('staff');
|
|
$this->db->where('username',$username);
|
|
$this->db->where(array('password'=>md5($password),'status'=>1));
|
|
$query = $this->db->get();
|
|
return $query;
|
|
}
|
|
function type()
|
|
{
|
|
$this->db->select('mat.mat_mas_id,mat.mat_mas_name,mat.opening,mat.minimum,mat.des,m.mat_type,u.mat_unit');
|
|
$this->db->from('material_master as mat');
|
|
$this->db->join('material_type as m',' m.type_id = mat.mat_mas_type', 'INNER');
|
|
$this->db->join('material_unit as u','u.unit_id = mat.mat_mas_unit','INNER');
|
|
$this->db->where('mat.status',1);
|
|
$query = $this->db->get();
|
|
return $query;
|
|
}
|
|
|
|
function role()
|
|
{
|
|
$this->db->select('emp.emp_id,emp.emp_name,emp.contact_number,emp.address,emp.role_id,r.role_name,r.role_id');
|
|
$this->db->from('employee as emp');
|
|
$this->db->join('role as r','emp.role_id= r.role_id ');
|
|
$this->db->where('emp.status',1);
|
|
$query = $this->db->get();
|
|
|
|
return $query;
|
|
}
|
|
function module_list()
|
|
{
|
|
$this->db->select('ms.sub_id,ms.sub_name,m.module_id,m.module_name');
|
|
$this->db->from('sub_module AS ms');
|
|
$this->db->join('module AS m','ms.module_id=m.module_id','INNER');
|
|
$this->db->where(array('ms.status'=>1,'m.status'=>1));
|
|
$query = $this->db->get();
|
|
return $query;
|
|
}
|
|
|
|
|
|
function rol($roleid) {
|
|
|
|
$this->db->select('*');
|
|
$this->db->from('page_access');
|
|
$this->db->where('role_id',$roleid);
|
|
$query = $this->db->get();
|
|
|
|
return $query;
|
|
}
|
|
|
|
function materialsku(){
|
|
$this->db->select('product_id,quantity,sk.sku_name,mm.mat_mas_name,sk.sku_id,mu.mat_unit');
|
|
$this->db->from('material_sku AS ms');
|
|
$this->db->join('material_master AS mm','mm.mat_mas_id=ms.product_id','INNER');
|
|
$this->db->join('sku AS sk','sk.sku_id=ms.sku_id','INNER');
|
|
$this->db->join('material_unit AS mu','mu.unit_id=mm.mat_mas_unit','LEFT');
|
|
$query = $this->db->get();
|
|
return $query;
|
|
}
|
|
function check_emp_userlogin($id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('login');
|
|
$this->db->where('emp_id',$id);
|
|
|
|
$query = $this->db->get();
|
|
return $query;
|
|
}
|
|
function check_emp_ledr($id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('employee');
|
|
$this->db->where('emp_id',$id);
|
|
|
|
$query = $this->db->get();
|
|
return $query;
|
|
}
|
|
function page_access_check($role,$userid,$module,$submodule,$page){
|
|
$this->db->select('p.*');
|
|
$this->db->from('page_access as p');
|
|
if($page==1){ $this->db->where('p.page_add',1);}
|
|
else if($page==2){ $this->db->where('p.page_view',1);}
|
|
else if($page==3){ $this->db->where('p.page_edit',1);}
|
|
else if($page==4){ $this->db->where('p.page_delete',1);}
|
|
else if($page==5){ $this->db->where('p.page_notify',1);}
|
|
$this->db->where(array('p.page_role_id'=>$role,'p.page_user_id'=>$userid,'p.page_module_id'=>$module,'p.page_submodule_id'=>$submodule,'p.status'=>1));
|
|
$query = $this->db->get();
|
|
return $query;
|
|
|
|
}
|
|
function page_access_module($role,$emp){
|
|
|
|
$this->db->select('p.page_id,p.page_role_id,p.page_user_id,p.page_module_id,p.status,m.*');
|
|
$this->db->from('page_access as p');
|
|
$this->db->join('module as m','p.page_module_id=m.module_id','LEFT');
|
|
//$this->db->join('module_sub as sm','p.page_submodule_id=sm.sub_module_id','LEFT');
|
|
$this->db->group_by('p.page_module_id');
|
|
$this->db->where(array('p.status'=>1,'p.page_role_id'=>$role,'p.page_user_id'=>$emp));
|
|
$query = $this->db->get();
|
|
return $query;
|
|
}
|
|
function pageaccess_submodule($id,$role,$emp)
|
|
{
|
|
$this->db->distinct();
|
|
$this->db->select('p.*,m.sub_module_id,m.sub_module_name,m.sub_module_route,m.sub_module_icon');
|
|
$this->db->from('page_access as p');
|
|
$this->db->join('module_sub as m','p.page_submodule_id=m.sub_module_id','RIGHT');
|
|
|
|
$this->db->where(array('p.page_module_id'=>$id,'p.status'=>1,'p.page_role_id'=>$role,'p.page_user_id'=>$emp));
|
|
$query = $this->db->get();
|
|
return $query;
|
|
}
|
|
function emp_bus_id($eid)
|
|
{
|
|
$this->db->select('emp_cmp_id');
|
|
$this->db->from('employee');
|
|
$this->db->where('emp_id',$eid);
|
|
$query = $this->db->get();
|
|
return $query;
|
|
}
|
|
}
|