load->library('session'); $this->load->library('rhlib'); } function jsonFromQuery($q) { $this->rhlib->jsonFromQuery($q); } function jsonFromQueryWLimit($q){ $this->rhlib->jsonFromQueryWLimit($q); } function insertRecord($table,$dataArray){ return $this->rhlib->insertRecord($table,$dataArray); } function deleteRecord($table,$where){ return $this->rhlib->deleteRecord($table,$where); } function retValOrNull($val){ //especially for combo & looukup with no item selected $val = ($val=='')? null : $val; return $val; } function get_matkulByProdi(){ $kdprodi = $_POST['kdprodi']; $qtable_kelmk = "SELECT kdkodtbkod as kdkelmk, CASE WHEN ifnull(nmdata,'')='' THEN nmkodtbkod ELSE nmdata END as nmkelmk FROM tbkod WHERE kdapltbkod='10'"; $q = "SELECT a.*, b.nmprodi, c.nmkelmk FROM matakuliah a LEFT JOIN prodi b ON b.kdprodi=a.kdprodi LEFT JOIN (".$qtable_kelmk.")c ON c.kdkelmk=a.kdkelmk WHERE a.kdprodi='".$kdprodi."'"; $this->jsonFromQueryWLimit($q); } function insert_matkul(){ $dataArray = $this->getFieldsAndValues(); $ret = $this->insertRecord('matakuliah',$dataArray); return $ret; } function update_matkul(){ $fieldsAndValues = $this->getFieldsAndValues(); //UPDATE //$this->db->where('kdprodi', $_POST['kdprodi']); //$this->db->where('kdmk', $_POST['kdmk']); $this->db->where('idmk', $_POST['idmk']); $this->db->update('matakuliah', $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 delete_matkul(){ //$where['kdprodi'] = $_POST['kdprodi']; //$where['kdmk'] = $_POST['kdmk']; $where['idmk'] = $_POST['idmk']; $ret = $this->deleteRecord('matakuliah',$where); return $ret; } function getFieldsAndValues(){ $dataArray = array( 'kdprodi'=> $_POST['kdprodi'], 'kdmk'=> $_POST['kdmk'], 'nmmkind'=> $_POST['nmmkind'], 'nmmkeng'=> $_POST['nmmkeng'], 'nmmkalias'=> $_POST['nmmkalias'], 'kdkelmk'=> $_POST['kdkelmk'] ); return $dataArray; } } ?>