| 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 : D:/wamp/www/sipapbd_2020_pergeseran2/application/modules/program/models/ |
Upload File : |
<?php
class Program_model extends Base_Model {
var $fieldmap_daftar;
var $fieldmap_filter;
var $fieldmap_program;
var $data;
function __construct()
{
parent::__construct();
$this->fieldmap_daftar = array(
'ID_BIDANG',
'KODE_BIDANG_LKP',
'NAMA_BIDANG',
'KODE_PROGRAM',
'NAMA_PROGRAM',
'LAST_CHANGED',
'PARAM'
);
$this->fieldmap_filter = array(
'kdb' => 'b.kode_bidang_lkp',
'nmb' => 'b.nama_bidang',
'kode' => 'a.kode_program',
'nama' => 'a.nama_program',
);
$this->fieldmap_program = array(
'id' => 'ID_PROGRAM',
'idb' => 'ID_BIDANG',
'kode' => 'KODE_PROGRAM',
'nama' => 'NAMA_PROGRAM',
'last_changed' => 'LAST_CHANGED',
);
}
function fill_data()
{
foreach($this->fieldmap_program as $key => $value){
switch ($key){
case 'last_changed' : $$key = date('d.m.Y.H.i.s'); break;
default : $$key = $this->input->post($key) ? $this->input->post($key) : NULL;
}
if(isset($$key))
$this->data[$value] = $$key;
}
}
// ----- search advance ---- >>
function get_data_fields()
{
$fields = array(
'kdb' => array('name' => 'Kode Bidang', 'kategori'=>'string'),
'nmb' => array('name' => 'Nama Bidang', 'kategori'=>'string'),
'kode' => array('name' => 'Kode Program', 'kategori'=>'string'),
'nama' => array('name' => 'Nama Program', 'kategori'=>'string'),
);
return $fields;
}
// Kode Program hanya boleh dipakai sekali
function check_duplikasi_program()
{
$id = $this->input->post('id') ? $this->input->post('id') : NULL;
$idb = $this->input->post('idb') ? $this->input->post('idb') : NULL;
$kode = $this->input->post('kode') ? $this->input->post('kode') : NULL;
$this->db->select('count(1) dup')
->where('a.kode_program', $kode)
->where('a.id_bidang', $idb)
->where('a.id_program <>', $id);
$rs = $this->db->get('program a')->row_array();
return (integer) $rs['DUP'] < 1;
}
/* Simpan data Program */
function insert_program()
{
$id = $this->data['ID_PROGRAM'];
$this->db->select('1')->from('program')->where('id_program', $id);
$rs = $this->db->get()->row_array();
if ($rs)
{
$this->db->where('id_program', $id);
$this->db->update('program', $this->data);
$this->check_trans_status('update program failed');
}
else
{
$id = $this->get_id('g_id_program');
$this->data['ID_PROGRAM'] = $id;
$this->db->insert('program', $this->data);
$this->check_trans_status('insert program failed');
}
$this->id = $id;
$this->last_changed = $this->get_last_changed('program','id_program',$this->id);
}
function save_detail()
{
$this->insert_program();
}
/* query hapus */
function build_query_hapus($id=0)
{
$this->db->where('id_program', $id)->delete('program');
$this->check_trans_status('delete program failed');
}
/* Query daftar */
function build_query_daftar()
{
$vbidang = "
select x.id_bidang, u.kode_urusan, x.kode_bidang, x.kode_bidang_lkp, x.nama_bidang
from v_bidang x
join urusan u on u.id_urusan = x.id_urusan
union
select cast(null as integer), cast('-' as varchar(10)), cast('-' as varchar(10)), cast('-' as varchar(10)), cast('NON BIDANG' as varchar(200))
from rdb\$database
";
$this->db->select("
a.id_program,
b.id_bidang,
b.kode_urusan,
b.kode_bidang,
b.kode_bidang_lkp,
b.nama_bidang,
cast('' as varchar(10)) kode_skpd,
a.kode_program,
a.nama_program,
a.last_changed,
0 param
");
$this->db->from("(".$vbidang.') b');
$this->db->join('program a', 'a.id_bidang is null and b.id_bidang is null or a.id_bidang = b.id_bidang', 'left');
$this->db->order_by('b.kode_bidang_lkp, a.kode_program');
}
function check_dependency($id)
{
$this->db->select("
(select count(b.id_program) from kegiatan b where b.id_program = a.id_program) kegiatan_pakai,
");
$this->db->where('a.id_program', $id);
$result = $this->db->get('program a')->row_array();
return !($result['KEGIATAN_PAKAI'] > 0);
}
function cek_exist()
{
if($this->input->post('id') > 0){
$this->db->select('count(fa.id_program) program_exists');
$this->db->from('program fa');
$this->db->where('fa.id_program',$this->input->post('id'));
$result = $this->db->get()->row_array();
if($result && $result['PROGRAM_EXISTS'] > 0)
{
return 1;
}
else{
return 0;
}
}
else{
return 1;
}
}
function cek_changed()
{
if($this->input->post('id') > 0 || $this->input->post('last_changed') !=''){
$this->db->select('fa.last_changed');
$this->db->from('program fa');
$this->db->where('fa.id_program',$this->input->post('id'));
$result = $this->db->get()->row_array();
if($result)
{
if($result['LAST_CHANGED'] <= $this->input->post('last_changed')){
return 1;
}
else{
return $result['LAST_CHANGED'];
}
}
else{
return 1;
}
}
else{
return 1;
}
}
}