load->library('session'); $this->load->library('rhlib'); } function retValOrNull($val){ //especially for combo & looukup with no item selected $val = ($val=='')? null : $val; return $val; } function retValOrZero($val){ $val = ($val=='')? 0 : $val; return $val; } /* function get_kelmk(){ $q = "SELECT kdkodtbkod as kode, CASE WHEN ifnull(nmdata,'')='' THEN nmkodtbkod ELSE nmdata END as nama FROM tbkod WHERE kdapltbkod='10'"; $this->rhlib->jsonFromQuery($q); } */ function get_kurikulum(){ $kdprodi = $_POST['kdprodi']; $thnmasuk = $_POST['thnmasuk']; /* $q = "SELECT a.*, b.nmmkind, ifnull(c.nmsemester,c.kdsemester) as kdsemester, d.nmjkurikulum, e.nmjmk, f.nmstmk FROM kurikulum a LEFT JOIN matakuliah b ON b.kdmk=a.kdmk LEFT JOIN semester c ON c.idsemester=a.idsemester LEFT JOIN ( select kdkodtbkod as kdjkurikulum, nmkodtbkod as nmjkurikulum from tbkod where kdapltbkod='11')d ON d.kdjkurikulum=a.jnskurikulum LEFT JOIN ( select kdkodtbkod as kdjmk, nmkodtbkod as nmjmk from tbkod where kdapltbkod='28')e ON e.kdjmk=a.jnsmk LEFT JOIN ( select kdkodtbkod as kdstmk, nmkodtbkod as nmstmk from tbkod where kdapltbkod='14')f ON f.kdstmk=a.stmk WHERE a.kdprodi='".$kdprodi."' and a.thnmasuk='".$thnmasuk."'"; */ $q = "SELECT a.*, b.nmmkind FROM kurikulum a LEFT JOIN matakuliah b ON b.kdmk=a.kdmk and b.kdprodi=a.kdprodi WHERE a.kdprodi='".$kdprodi."' and a.thnmasuk='".$thnmasuk."' ORDER BY a.idsemester, a.idkurikulum"; $this->rhlib->jsonFromQueryWLimit($q); } function insert_kurikulum(){ $dataArray = $this->getFieldsAndValues(); $ret = $this->rhlib->insertRecord('kurikulum',$dataArray); /* $this->db->select('count(*) as task_count'); $this->db->from('tasks'); $this->db->where('tasksAssignedTo', $userId); $this->db->where('taskPriority_taskPriorityId !=', 6); $query = $this->db->get(); */ //$this->db->where('NOT EXISTS (SELECT * FROM kurikulum kur WHERE kurikulum.kdmk = kur.kdmk AND kurikulum.thnmasuk = kur.thnmasuk)'); //$this->db->insert('kurikulum', $dataArray); //$this->db->where('(SELECT kdmk NOT IN (SELECT kdmk FROM kurikulum) AND thnmasuk NOT IN (SELECT thnmasuk FROM kurikulum))'); //$ret = $this->db->get(); //$ret = $this->db->replace('kurikulum', $dataArray); return $ret; } function copy_kurikulum(){ $kdprodi = $_POST['kdprodi']; $thbaru = $_POST['thbaru']; $thlama = $_POST['thlama']; $sql = "INSERT kurikulum(kdprodi,thnmasuk,kdmk,idsemester,jmlsks,skstatapmuka,skspraktikum,sksprakteklap,jnskurikulum,jnsmk,stmk) SELECT kdprodi,".$thbaru.",kdmk,idsemester,jmlsks,skstatapmuka, skspraktikum,sksprakteklap,jnskurikulum,jnsmk,stmk FROM kurikulum WHERE kdprodi='".$kdprodi."' and thnmasuk='".$thlama."'"; $exec = $this->db->query($sql); if($this->db->affected_rows()){ $ret["success"]=true; $ret["msg"]='Copy Data Berhasil'; }else{ $ret["success"]=false; $ret["msg"]= 'Copy Data Gagal'; } return $ret; } function update_kurikulum(){ $fieldsAndValues = $this->getFieldsAndValues(); //UPDATE $this->db->where('kdprodi', $_POST['kdprodi']); $this->db->where('thnmasuk', $_POST['thnmasuk']); $this->db->where('kdmk', $_POST['kdmk']); $this->db->update('kurikulum', $fieldsAndValues); if($this->db->affected_rows()){ $ret["success"]=true; $ret["msg"]='Update Data Berhasil'; }else{ $ret["success"]=false; $ret["msg"]= 'Update Data Gagal'; } return $ret; } function update1field_kurikulum(){ $field = $_POST['field']; $value = $_POST['value']; //UPDATE $this->db->where('idkurikulum', $_POST['idkurikulum']); $this->db->where('kdprodi', $_POST['kdprodi']); $this->db->where('thnmasuk', $_POST['thnmasuk']); $this->db->where('kdmk', $_POST['kdmk']); $this->db->set($field, $value); $this->db->update('kurikulum'); if($this->db->affected_rows()){ $ret["success"]=true; $ret["msg"]='Update Data Berhasil'; }else{ $ret["success"]=false; $ret["msg"]= 'Update Data Gagal'; } return $ret; } function update2field_kurikulum(){ $field1 = $_POST['field1']; $value1 = $_POST['value1']; $field2 = $_POST['field2']; $value2 = $_POST['value2']; $dataArray = array( $field1 => $value1, $field2 => $value2, ); //UPDATE $this->db->where('idkurikulum', $_POST['idkurikulum']); $this->db->where('kdprodi', $_POST['kdprodi']); $this->db->where('thnmasuk', $_POST['thnmasuk']); $this->db->where('kdmk', $_POST['kdmk']); $this->db->update('kurikulum', $dataArray); if($this->db->affected_rows()){ $ret["success"]=true; $ret["msg"]='Update Data Berhasil'; }else{ $ret["success"]=false; $ret["msg"]= 'Update Data Gagal'; } return $ret; } function delete_kurikulum(){ $where['kdprodi'] = $_POST['kdprodi']; $where['thnmasuk'] = $_POST['thnmasuk']; $where['kdmk'] = $_POST['kdmk']; $ret = $this->rhlib->deleteRecord('kurikulum',$where); return $ret; } function delete_kurikulum_prodismt(){ $where['kdprodi'] = $_POST['kdprodi']; $where['thnmasuk'] = $_POST['thnmasuk']; $this->db->trans_begin(); $this->db->delete("kurikulum",$where); if ($this->db->trans_status() === FALSE){ $this->db->trans_rollback(); $return["success"]=false; $return["message"]="Hapus Data gagal"; }else{ $this->db->trans_commit(); $return["success"]=true; $return["message"]="Hapus Data Berhasil"; } return $return; } function getFieldsAndValues(){ $idsemester = (isset($_POST['idsemester']))? $_POST['idsemester'] : null; $jmlsks = (isset($_POST['jmlsks']))? $_POST['jmlsks'] : 0; $skstatapmuka = (isset($_POST['skstatapmuka']))? $_POST['skstatapmuka'] : 0; $skspraktikum = (isset($_POST['skspraktikum']))? $_POST['skspraktikum'] : 0; $sksprakteklap = (isset($_POST['sksprakteklap']))? $_POST['sksprakteklap'] : 0; $jnskurikulum = (isset($_POST['jnskurikulum']))? $_POST['jnskurikulum'] : null; $jnsmk = (isset($_POST['jnsmk']))? $_POST['jnsmk'] : null; $stmk = (isset($_POST['stmk']))? $_POST['stmk'] : null; $dataArray = array( 'kdprodi'=> $_POST['kdprodi'], 'thnmasuk' => $_POST['thnmasuk'], 'kdmk'=> $_POST['kdmk'], 'idsemester'=> $idsemester, 'jmlsks' => $jmlsks, 'skstatapmuka'=> $skstatapmuka, 'skspraktikum'=> $skspraktikum, 'sksprakteklap'=> $sksprakteklap, 'jnskurikulum' => $jnskurikulum, 'jnsmk'=> $jnsmk, 'stmk'=> $stmk, ); return $dataArray; } //menampilkan kurikulum dengan filter semester ganjil & genap function get_kurikulum_semester() { $kdprodi = $this->input->post('kdprodi'); $thnmasuk = $this->input->post('thnmasuk'); $idjnssemester = $this->input->post('idjnssemester'); $q = "SELECT a.*, b.nmmkind, c.kdsemester, c.nmsemester, c.idjnssemester, c.tingkat, 0 as skssimulasi FROM kurikulum a LEFT JOIN matakuliah b ON b.kdmk=a.kdmk and b.kdprodi=a.kdprodi LEFT JOIN semester c on a.idsemester = c.idsemester WHERE a.kdprodi = '".$kdprodi."' and a.thnmasuk = '".$thnmasuk."' and c.idjnssemester = '".$idjnssemester."' ORDER BY a.idsemester, a.idkurikulum"; $this->rhlib->jsonFromQuery($q); } function get_jsemester() { $q = "SELECT * FROM jsemester order by idjnssemester ASC"; $this->rhlib->jsonFromQuery($q); } } ?>