?
Current Path : /home1/savoy/public_html/savoyglobal.net/rms/application/models/ |
Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 |
Current File : /home1/savoy/public_html/savoyglobal.net/rms/application/models/settingsmodel.php |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Settingsmodel extends CI_Model { function __construct() { // Call the Model constructor parent::__construct(); } /*functions for profile */ function checkprofileset($employee_id) { $this->db->from('user_profile'); $this->db->join('employee','employee.employee_designation_id=user_profile.designation_id'); $this->db->where('employee_id',$employee_id); return $this->db->count_all_results(); } function get_profile_permission_by_empid($employee_id) { $data=array(); $this->db->select('*'); $this->db->from('user_profile'); $this->db->join('employee','user_profile.designation_id=employee.employee_designation_id'); $this->db->where('employee_id',$employee_id); $this->db->order_by('profile_id','asc'); $Q=$this->db->get(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_user_permission_by_user_id($user_id) { $data=array(); $this->db->select('*'); $this->db->from('user'); $this->db->where('user_id',$user_id); $Q=$this->db->get(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getmoduledatamaster() { $data=array(); $res=$this->db->query("select module.module_name,module.module_title,menu.caption,menu.target,menu.menu_id,menu.module_id,menu.sort,menu.login_type from module join menu on module.module_id=menu.module_id where module.active = '1' and menu.active='1' order by module.sort, menu.sort"); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } /*functions for profile */ function search_profile($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('user_profile'); $this->db->join('master','master_id=profile_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('profile_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_profile($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'profile_id'=>$masterid, 'designation_id'=>$postdata['designation_id'], 'profile_modules'=>$postdata['role_permission'], 'profile_modules_home_page'=>$postdata['role_home_page'], 'profile_modules_permission'=>$postdata['role_edit_del_permission'] ); $this->db->insert('user_profile', $tblValues); $data['resfunction']='search_profile'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_profile($postdata) { $data=array(); $this->db->trans_begin(); $this->mastermodel->updatemasterdata($postdata['profile_id']); $tblValues=array( 'profile_modules'=>$postdata['role_permission'], 'profile_modules_home_page'=>$postdata['role_home_page'], 'profile_modules_permission'=>$postdata['role_edit_del_permission'] ); $this->db->where('profile_id',$postdata['profile_id']); $this->db->update('user_profile', $tblValues); $data['resfunction']='search_profile'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for reminder*/ function search_reminder($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('reminder'); $this->db->join('master','master_id=reminder_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('reminder_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_reminder($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'reminder_id'=>$masterid, 'reminder_subject'=>$postdata['reminder_subject'], 'remind_before'=>$postdata['remind_before'], 'reminder_date'=>$this->mastermodel->convertdateformat($postdata['reminder_date']), 'reminder_description'=>$postdata['reminder_description'] ); $this->db->insert('reminder', $tblValues); $data['resfunction']='search_reminder'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_reminder($postdata) { $data=array(); $this->db->trans_begin(); $this->mastermodel->updatemasterdata($postdata['reminder_id']); $tblValues=array( 'reminder_subject'=>$postdata['reminder_subject'], 'remind_before'=>$postdata['remind_before'], 'reminder_date'=>$this->mastermodel->convertdateformat($postdata['reminder_date']), 'reminder_description'=>$postdata['reminder_description'] ); $this->db->where('reminder_id',$postdata['reminder_id']); $this->db->update('reminder', $tblValues); $data['resfunction']='search_reminder'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for user */ function search_user($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('user'); $this->db->join('master','master_id=user_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('user_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_user($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'user_id'=>$masterid, 'user_name'=>$postdata['user_name'], 'password'=>md5($postdata['password']), 'employee_id'=>$postdata['employee_id'], 'user_modules'=>$postdata['user_modules'], 'modules_permission'=>$postdata['modules_permission'], 'home_page'=>$postdata['user_home_page'], ); $this->db->insert('user', $tblValues); $data['resfunction']='search_user'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_user($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'user_modules'=>$postdata['user_modules'], 'modules_permission'=>$postdata['modules_permission'], 'home_page'=>$postdata['user_home_page'], ); $this->db->where('user_id',$postdata['user_id']); $this->db->update('user', $tblValues); $data['resfunction']='search_user'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for module manager */ function search_module($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('login_type'); $this->db->order_by('login_type_id','asc'); $data['results']=$this->db->get(); return $data; } function insert_module($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'login_type_id'=>$masterid, 'login_type_name'=>$postdata['login_type_name'], ); $this->db->insert('login_type', $tblValues); $module= $this->db->get('module'); foreach ($module->result_array() as $row) { $this->db->where('module_id',$row['module_id']); $menu=$this->db->get('menu'); if(isset($postdata['view_'.$row['module_name']])) { $cheched=$postdata['view_'.$row['module_name']]; foreach ($menu->result_array() as $list) { if(in_array($list['caption'],$cheched)) { $val=$list['login_type']; $val=$val.','.$masterid; $tblValues=array( 'login_type'=>$val ); $this->db->where('caption',$list['caption']); $this->db->update('menu',$tblValues); } } } } $data['resfunction']='search_module'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_module($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'login_type_name'=>$postdata['login_type_name'], ); $this->db->where('login_type_id',$postdata['login_type_id']); $this->db->update('login_type', $tblValues); $menu=$this->db->get('menu'); foreach ($menu->result_array() as $list) { $val=$list['login_type']; $val_ar= explode(',', $val); if(isset($postdata['menu_'.$list['menu_id']])) { if(!in_array($postdata['login_type_id'],$val_ar)) { $val=$val.','.$postdata['login_type_id']; $val=str_replace(',,', ',', $val); } } else { if(in_array($postdata['login_type_id'],$val_ar)) { $val=str_replace($list['login_type'], '', $val); $val=str_replace(',,', ',', $val); } } $tblValues=array('login_type'=>$val); $this->db->where('menu_id',$list['menu_id']); $this->db->update('menu',$tblValues); } $data['resfunction']='search_module'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for prefix */ function search_prefix($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('prefix_code'); $this->db->order_by('prefix_code_id','asc'); $data['results']=$this->db->get(); return $data; } function update_prefix($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'prefix_name'=>$postdata['prefix_name'], 'prefix'=>$postdata['prefix'], 'prefix_digit'=>$postdata['prefix_digit'] ); $this->db->where('prefix_code_id',$postdata['prefix_code_id']); $this->db->update('prefix_code', $tblValues); $data['resfunction']='search_prefix'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for alert master*/ function search_alert_master($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('alert_master'); $this->db->order_by('alert_master_id','asc'); $data['results']=$this->db->get(); return $data; } function insert_alert_master($postdata) { $data=array(); $this->db->trans_begin(); $limit=$postdata['limit']; $this->db->where('alert_id',$postdata['alert_master_id']); $this->db->delete('alert_master_designation'); for($i=1;$i<$limit;$i++) { if(isset($postdata['select_designation_'.$i])) { $tblValues=array( 'alert_id'=>$postdata['alert_master_id'], 'alert_designation_id'=>$postdata['designation_id_'.$i] ); $this->db->insert('alert_master_designation',$tblValues); } } $data['resfunction']='search_alert_master'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for alert */ function search_alert($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('alert_master'); $this->db->order_by('alert_master_id','asc'); $data['results']=$this->db->get(); return $data; } function remove_alert($table,$id,$field) { $data=array(); $this->db->trans_begin(); $tblvalues=array( 'alert_status'=>'0' ); $this->db->where($field,$id); $this->db->update('alert',$tblvalues); $this->db->trans_status(); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Unable to Remove record because of associated data'; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Data Removed Successfully'; } return $data; } function get_num_alert($id) { $employee_id= $this->mastermodel->get_single_field_value('user','employee_id','user_id',$_SESSION['user_id']); $this->db->join('alert_employee','alert_employee.alert_id=alert.alert_id'); $this->db->where('alert_employee.employee_id',$employee_id); $this->db->where('alert_status','1'); $this->db->where('alert_master_id',$id); $Q=$this->db->get('alert'); return $Q->num_rows(); } function get_alert_employee($id) { $employee_id= $this->mastermodel->get_single_field_value('user','employee_id','user_id',$_SESSION['user_id']); $today = date("Y-m-d"); $data=array(); $this->db->select('*'); $this->db->from('alert_employee'); $this->db->join('alert','alert.alert_id=alert_employee.alert_id'); $this->db->join('employee','employee.employee_id=alert.alert_record_id','left'); $this->db->join('lease_agreement','lease_agreement.lease_id=alert.alert_record_id','left'); $this->db->join('building_details','building_details.building_id=lease_agreement.lease_building_id','left'); $this->db->where('alert_employee.employee_id',$employee_id); $this->db->where('alert.alert_master_id',$id); $this->db->where('alert.alert_status','1'); $this->db->where('alert.alert_date <=',$today); $Q= $this->db->get(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function update_password($postdata) { $data=array(); $data['resfunction']='search_user'; if($postdata['newpassword'] == $postdata['retypepassword']) { $tblValues=array('password'=>md5($postdata['newpassword'])); $this->db->where('user_id',$postdata['user_id']); $this->db->update('user', $tblValues); $data['res']='password'; $data['msg']='Password Changed Sucessfully'; return $data; } else { $data['res']='password'; $data['msg']='Passwords do not match'; return $data; } } }