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_struprog(){ $kdprodi = $_POST['kdprodi']; $kdstsemester = $_POST['kdstsemester']; $q = "SELECT a.*, b.nmmkind, IFNULL(c.jmldos,0) as jmldos FROM struprog a LEFT JOIN matakuliah b ON b.kdmk=a.kdmk and b.kdprodi=a.kdprodi LEFT JOIN (select kdmk, count(DISTINCT nidu) as jmldos from struprogdet s WHERE s.kdprodi='".$kdprodi."' and s.kdstsemester='".$kdstsemester."' GROUP BY kdmk)c ON c.kdmk=a.kdmk WHERE a.kdprodi='".$kdprodi."' and a.kdstsemester='".$kdstsemester."'"; $this->rhlib->jsonFromQueryWLimit($q); } function get_matkulfromkurikulum(){ $kdprodi = $_POST['kdprodi']; $kdstsemester = $_POST['kdstsemester']; $q = "SELECT DISTINCT(kurikulum.kdmk) ,kurikulum.kdprodi ,kurikulum.idsemester ,kurikulum.jmlsks ,concat(kurikulum.idsemester, ' / ', semester.tingkat) as semestertingkat ,matakuliah.nmmkind ,matakuliah.nmmkeng ,matakuliah.nmmkalias ,matakuliah.kdkelmk ,tbkod.nmkelmk FROM kurikulum LEFT JOIN matakuliah ON matakuliah.kdprodi = kurikulum.kdprodi AND matakuliah.kdmk = kurikulum.kdmk LEFT JOIN (SELECT kdkodtbkod as kdkelmk, CASE WHEN ifnull(nmdata,'')='' THEN nmkodtbkod ELSE nmdata END as nmkelmk FROM tbkod WHERE kdapltbkod='10')tbkod ON tbkod.kdkelmk=matakuliah.kdkelmk LEFT JOIN semester ON semester.idsemester = kurikulum.idsemester WHERE CASE WHEN right('$kdstsemester', 1) = 1 THEN kurikulum.kdprodi='$kdprodi' AND kurikulum.idsemester MOD 2 = 1 WHEN right('$kdstsemester', 1) = 2 THEN kurikulum.kdprodi='$kdprodi' AND (kurikulum.idsemester MOD 2 = 0 OR kurikulum.idsemester = 9) END ORDER BY kurikulum.idsemester"; $this->rhlib->jsonFromQueryWLimit($q); } function insert_struprog(){ $dataArray = $this->getFieldsAndValues(); $ret = $this->rhlib->insertRecord('struprog',$dataArray); return $ret; } function copy_struprog(){ $kdprodi = $_POST['kdprodi']; $smtbaru = $_POST['smtbaru']; $smtlama = $_POST['smtlama']; $sql = "INSERT struprog(kdprodi,kdstsemester,kdmk,idsemester,jmlsks,skstatapmuka,skspraktikum,sksprakteklap,jnskurikulum,jnsmk,stmk) SELECT kdprodi,".$smtbaru.",kdmk,idsemester,jmlsks,skstatapmuka, skspraktikum,sksprakteklap,jnskurikulum,jnsmk,stmk FROM struprog WHERE kdprodi='".$kdprodi."' and kdstsemester='".$smtlama."'"; $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_struprog(){ $fieldsAndValues = $this->getFieldsAndValues(); //UPDATE $this->db->where('kdprodi', $_POST['kdprodi']); $this->db->where('kdstsemester', $_POST['kdstsemester']); $this->db->where('kdmk', $_POST['kdmk']); $this->db->update('struprog', $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_struprog(){ $field = $_POST['field']; $value = $_POST['value']; //UPDATE $this->db->where('kdprodi', $_POST['kdprodi']); $this->db->where('kdstsemester', $_POST['kdstsemester']); $this->db->where('kdmk', $_POST['kdmk']); $this->db->set($field, $value); $this->db->update('struprog'); 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_detail($where){ $this->db->trans_begin(); $this->db->delete("struprogdet",$where); if ($this->db->trans_status() === FALSE){ $this->db->trans_rollback(); return false; }else{ $this->db->trans_commit(); return true; } } function delete_struprog(){ $where['kdprodi'] = $_POST['kdprodi']; $where['kdstsemester'] = $_POST['kdstsemester']; $where['kdmk'] = $_POST['kdmk']; $delDet = $this->delete_detail($where); //delete details first if($delDet){ $this->db->trans_begin(); $this->db->delete("struprog",$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"; } } else{ $return["success"]=false; $return["message"]="Hapus Detail gagal"; } return $return; } function deleteByProdiSmt_struprog(){ $where['kdprodi'] = $_POST['kdprodi']; $where['kdstsemester'] = $_POST['kdstsemester']; $delDet = $this->delete_detail($where); //delete details first if($delDet){ $this->db->trans_begin(); $this->db->delete("struprog",$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"; } } else{ $return["success"]=false; $return["message"]="Hapus Detail gagal"; } return $return; } function getFieldsAndValues(){ $kdstsemester = (isset($_POST['kdstsemester']))? $_POST['kdstsemester'] : null; //kdstsemester perlu diextract digit terakhir utk default idsemester --belum $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'], 'kdstsemester' => $_POST['kdstsemester'], 'kdmk'=> $_POST['kdmk'], 'idsemester'=> $idsemester, 'jmlsks' => $jmlsks, 'skstatapmuka'=> $skstatapmuka, 'skspraktikum'=> $skspraktikum, 'sksprakteklap'=> $sksprakteklap, 'jnskurikulum' => $jnskurikulum, 'jnsmk'=> $jnsmk, 'stmk'=> $stmk, ); return $dataArray; } } ?>