| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /wamp/www/SIPBOS_2020/application/modules/auth/models/ |
Upload File : |
<?php
class User_model extends Base_Model {
var $fieldmap_daftar;
var $fieldmap_filter;
var $fieldmap_user;
var $data;
var $GROUP_COLUMN;
function __construct()
{
parent::__construct();
if ($this->app_id == 'SIPKD') $this->GROUP_COLUMN = 'GROUP_ID';
else if ($this->app_id == 'APBD') $this->GROUP_COLUMN = 'GROUP_ID2';
$this->fieldmap_daftar = array(
'ID',
'USERNAME',
'NAME',
'EMAIL',
'NAMA_GROUP',
'NAMA_SKPD',
'JABATAN',
'SYS_ADMIN',
'PPKD',
'STATUS',
);
$this->fieldmap_filter = array(
'username' => 'a.username',
'nama' => 'a.name',
'email' => 'a.email',
'group' => 'b.name',
'nm_skpd' => 's.nama_skpd',
'roles' => "case a.roles when 0 then '-' when 1 then 'PPK' when 2 then 'Bendahara Penerimaan' when 3 then 'Bendahara Pengeluaran' end"
);
$this->fieldmap_user = array(
'id' => 'ID',
'username' => 'USERNAME',
'nama' => 'NAME',
'email' => 'EMAIL',
'id_skpd' => 'SKPD_ID',
'id_group' => $this->GROUP_COLUMN,
'admin' => 'SYS_ADMIN',
'ppkd' => 'PPKD',
'roles' => 'ROLES',
'status' => 'STATUS',
);
}
function fill_data()
{
foreach($this->fieldmap_user as $key => $value){
switch ($key){
case 'status' : $$key = $this->input->post($key) == 'true' ? 1 : 0; break;
case 'admin' : $$key = $this->input->post($key) == 'true' ? 1 : 0; break;
case 'id_skpd' : $this->data[$value] = $this->input->post($key) ? $this->input->post($key) : NULL; break;
case 'ppkd' : $$key = $this->input->post($key); break;
case 'roles' : $$key = $this->input->post($key); break;
default : $$key = $this->input->post($key) ? $this->input->post($key) : NULL;
}
if(isset($$key))
$this->data[$value] = $$key;
}
// Jika id_skpd diisi, maka roles di set 0
if (is_null($this->data['SKPD_ID'])) $this->data['ROLES'] = 0;
}
function get_grid_model()
{
$grid = array(
'colNames' => array('Username', 'Nama', 'Email', 'Group', 'SKPD', 'Jabatan', 'Admin', 'PPKD', 'Aktif'),
'colModel' => array(
array('name' => 'username', 'width' => 100, 'sortable' => true),
array('name' => 'name', 'width' => 150, 'sortable' => true),
array('name' => 'email', 'width' => 150, 'sortable' => true),
array('name' => 'group', 'width' => 150, 'sortable' => true),
array('name' => 'nm_skpd', 'width' => 200, 'sortable' => true),
array('name' => 'roles', 'width' => 150, 'sortable' => true),
array('name' => 'admin', 'width' => 30, 'sortable' => true, 'edittype' => 'checkbox', 'formatter' => 'checkbox', 'editoptions' => '{value:"1:0"}', 'formatoptions' => '{disabled:true}', 'align' => 'center'),
array('name' => 'ppkd', 'width' => 40, 'sortable' => true, 'edittype' => 'checkbox', 'formatter' => 'checkbox', 'editoptions' => '{value:"1:0"}', 'formatoptions' => '{disabled:true}', 'align' => 'center'),
array('name' => 'status', 'width' => 30, 'sortable' => true, 'edittype' => 'checkbox', 'formatter' => 'checkbox', 'editoptions' => '{value:"1:0"}', 'formatoptions' => '{disabled:true}', 'align' => 'center'),
),
'footerrow' => false,
'userDataOnFooter' => false
);
return $grid;
}
// ----- search advance ---- >>
function get_data_fields()
{
$fields = array(
'username' => array('name' => 'Username', 'kategori'=>'string'),
'nama' => array('name' => 'Nama', 'kategori'=>'string'),
'group' => array('name' => 'Group', 'kategori'=>'string'),
'nm_skpd' => array('name' => 'SKPD', 'kategori'=>'string'),
'roles' => array('name' => 'Jabatan', 'kategori'=>'string'),
);
return $fields;
}
// Username hanya boleh dipakai sekali
function check_duplikasi_username()
{
$id = $this->input->post('id') ? $this->input->post('id') : 0;
$username = $this->input->post('username') ? $this->input->post('username') : '';
$this->db->select('count(1) dup')
->from('users a')
->where("a.$this->GROUP_COLUMN is not null")
->where('a.id <>', $id)
->where('a.username', $username);
$rs = $this->db->get()->row_array();
return (integer) $rs['DUP'] < 1;
}
// Username hanya boleh dipakai sekali
function check_duplikasi_email()
{
$id = $this->input->post('id') ? $this->input->post('id') : 0;
$email = $this->input->post('email') ? $this->input->post('email') : '';
$this->db->select('count(1) dup')
->from('users a')
->where("a.$this->GROUP_COLUMN is not null")
->where('a.id <>', $id)
->where('a.email', $email);
$rs = $this->db->get()->row_array();
return (integer) $rs['DUP'] < 1;
}
/* Simpan data User */
function insert_user()
{
$id = isset($this->data['ID']) ? $this->data['ID'] : 0;
$mode = $this->input->post('mode');
if ($mode == 'new')
{
/* password hanya diproses saat user pertama kali di entri */
/* untuk mengubah password menggunakan fungsi tersendiri */
$passwd = $this->input->post('passwd');
/* siapkan salt */
$salt = strtotime(date('Y-m-d H:i:s'));
$this->data['SALT'] = $salt;
$this->data['PASSWD'] = sha1($salt.$passwd);
}
else {
unset($this->data['PASSWD']);
}
$this->db->select('1')->from('users')->where('id', $id);
$rs = $this->db->get()->row_array();
if ($rs)
{
$this->db->where('id', $id);
$this->db->update('users', $this->data);
$this->id = $this->data['ID'];
}
else
{
unset($this->data['ID']);
$this->db->insert('users', $this->data);
$this->db->select_max('id')->from('users');
$rs = $this->db->get()->row_array();
$this->id = $rs['ID'];
}
}
function save_detail()
{
$this->insert_user();
}
// cek apakah password yang diberikan valid
function check_password()
{
$id = $this->input->post('id') ? $this->input->post('id') : 0;
$passwd = $this->input->post('oldpasswd') ? $this->input->post('oldpasswd') : '';
$this->db->select('passwd, salt')->from('users')->where('id', $id);
$rs = $this->db->get()->row_array();
$old_passwd = $rs['PASSWD'];
$salt = $rs['SALT'];
return (sha1($salt.$passwd) === $old_passwd);
}
// simpan password baru
function save_password()
{
$id = $this->input->post('id') ? $this->input->post('id') : 0;
$passwd = $this->input->post('newpasswd') ? $this->input->post('newpasswd') : '';
$this->db->select('passwd, salt')->from('users')->where('id', $id);
$rs = $this->db->get()->row_array();
$data = array(
'passwd' => sha1($rs['SALT'].$passwd),
);
$this->db->trans_begin();
$this->db->where('id', $id);
$this->db->update('users', $data);
if ($this->db->trans_status() === FALSE)
{
$this->last_error_id = $this->db->_error_number();
$this->last_error_message = $this->db->_error_message();
$this->db->trans_rollback();
return FALSE;
}
$this->db->trans_commit();
return TRUE;
}
/* query hapus */
function build_query_hapus($id=0)
{
$this->db->where('id', $id)->delete('users');
}
/* Query daftar */
function build_query_daftar()
{
$this->db->select("
a.id,
a.username,
a.name,
a.email,
a.skpd_id,
s.kode_skpd_lkp,
s.nama_skpd,
a.sys_admin,
a.ppkd,
a.status,
case a.roles when 0 then '-' when 1 then 'PPK' when 2 then 'Bendahara Penerimaan' when 3 then 'Bendahara Pengeluaran' end jabatan,
a.$this->GROUP_COLUMN group_id,
b.name nama_group
");
$this->db->from('users a');
$this->db->join('v_skpd s', 's.id_skpd = a.skpd_id', 'left');
$this->db->join('groups b' , "b.id = a.$this->GROUP_COLUMN");
if ($this->session->userdata('id_skpd') !== 0)
{
$this->db->where('a.skpd_id', $this->session->userdata('id_skpd'));
}
}
function build_query_form($id=0)
{
$this->db->select("
a.id,
a.username,
a.name,
a.email,
a.skpd_id,
s.kode_skpd_lkp,
s.nama_skpd,
a.sys_admin,
a.ppkd,
a.status,
a.roles,
a.$this->GROUP_COLUMN group_id,
b.name group_nama
");
$this->db->from('users a');
$this->db->join('v_skpd s', 's.id_skpd = a.skpd_id', 'left');
$this->db->join('groups b' , "b.id = a.$this->GROUP_COLUMN");
$this->db->where('a.id', $id);
}
function get_prev_id($id)
{
$this->db->select('coalesce(max(a.id), 0) id')
->from('users a')
->where("a.$this->GROUP_COLUMN is not null")
->where('id < ', $id);
if ($this->id_skpd !== 0)
{
$this->db->where('a.id_skpd', $this->id_skpd);
}
$result = $this->db->get()->row_array();
return $result['ID'];
}
function get_next_id($id)
{
$this->db->select('coalesce(min(a.id), 0) id')
->from('users a')
->where("a.$this->GROUP_COLUMN is not null")
->where('id > ', $id);
if ($this->id_skpd !== 0)
{
$this->db->where('a.id_skpd', $this->id_skpd);
}
$result = $this->db->get()->row_array();
return $result['ID'];
}
function check_dependency($id)
{
// cegah user menghapus dirinya sendiri
if (!is_array($id)) $id = array($id);
$total = count($id);
for($i = 0;$i < $total;$i++){
return !($id[$i]== $this->session->userdata('id_user'));
}
}
}