load->library('session'); } function autoNumber($column,$tbl){ $q = "SELECT max(".$column.")+1 as max FROM ".$tbl."" ; $query = $this->db->query($q); $max = ''; if ($query->num_rows() != 0) { $row = $query->row(); $max=$row->max; } if ($max == null){ $max=0; } return $max; } function id_field($column,$tbl,$whereb, $wherea){ $q = "SELECT ".$column." as id FROM ".$tbl." where ".$whereb." = '".$wherea."' " ; $query = $this->db->query($q); $id = ''; if ($query->num_rows() != 0) { $row = $query->row(); $id=$row->id; } return $id; } function nm_field($column,$tbl,$whereb, $wherea){ $q = "SELECT ".$column." as nm FROM ".$tbl." where ".$whereb." = '".$wherea."' " ; $query = $this->db->query($q); $nm= ''; if ($query->num_rows() != 0) { $row = $query->row(); $nm=$row->nm; } return $nm; } // START PENGGUNA function grid(){ //ISTRA $KEDUA= $this->load->database('second', TRUE); //====================================================================== $start = $this->input->post("start"); $limit = $this->input->post("limit"); $fields = $this->input->post("fields"); $query = $this->input->post("query"); $id_module = $this->input->post("id_module"); $kdstsemester = $this->input->post("kdstsemester"); $KEDUA->select("*"); $KEDUA->from("v_studentbody"); if($kdstsemester!=''){ $where['kdstsemester']=$kdstsemester; } if($id_module!=''){ $where['kdjadwalpmb']=$id_module; } if($fields!="" || $query !=""){ $k=array('[',']','"'); $r=str_replace($k, '', $fields); // $a[explode(',', $r)]; $b=explode(',', $r); $c=count($b); for($i=0;$i<$c;$i++){ $d[$b[$i]]=$query; } // $this->db->bracket('open','like'); $KEDUA->or_like($d, $query); // $this->db->bracket('close','like'); } //$this->db->order_by("JDASHBOARD"); if ($start!=null){ $KEDUA->limit($limit,$start); }else{ // $KEDUA->limit(50,0); } $KEDUA->where($where); $q = $KEDUA->get(); $data = array(); if ($q->num_rows() > 0) { $data = $q->result(); } $datax = count($q);//$this->db->count_all('jadwalpmb'); $ttl = $datax; //====================================================================== $build_array = array ("success"=>true,"results"=>$ttl,"data"=>array()); foreach($data as $row) { array_push($build_array["data"],array( 'nourutprodi'=>$row->nourutprodi, 'nmprodi'=>$row->nmprodi, 'nmjenjangstudi'=>$row->nmjenjangstudi, 'jumlah'=>$row->jumlah, 'aktif'=>$row->aktif, 'cuti'=>$row->cuti, 'do'=>$row->do, 'keluar'=>$row->keluar, 'lulus'=>$row->lulus, 'nonaktif'=>$row->nonaktif, 'sdd'=>$row->sdd, )); } echo json_encode($build_array); } function save(){ // ISTRA $arr_tgl1 = explode('/',$this->input->post("daritgl")); $daritgl = $arr_tgl1[2]."-".$arr_tgl1[0]."-".$arr_tgl1[1]; $arr_tgl2 = explode('/',$this->input->post("sampaitgl")); $sampaitgl = $arr_tgl2[2]."-".$arr_tgl2[0]."-".$arr_tgl2[1]; $data = array( 'idjadwalpmb'=> $this->autoNumber('idjadwalpmb','jadwalpmb'), 'kdjadwalpmb'=> $_POST['kdjadwalpmb'], 'nmjadwalpmb'=> $_POST['nmjadwalpmb'], 'deskripsi'=> $_POST['deskripsi'], 'kdstsemester'=> $_POST['kdstsemester'], 'idstatus'=> $this->id_field('idstatus', 'status', 'nmstatus',$_POST['idstatus']), 'daritgl'=> $daritgl, 'sampaitgl'=>$sampaitgl, ); $this->db->insert('jadwalpmb', $data); if($this->db->affected_rows()){ $ret["success"]=true; $ret["message"]='Simpan Data Berhasil'; }else{ $ret["success"]=false; $ret["message"]='Simpan Data Gagal'; } return $ret; } function update(){ // ISTRA $arr_tgl1 = explode('/',$this->input->post("daritgl")); $daritgl = $arr_tgl1[2]."-".$arr_tgl1[0]."-".$arr_tgl1[1]; $arr_tgl2 = explode('/',$this->input->post("sampaitgl")); $sampaitgl = $arr_tgl2[2]."-".$arr_tgl2[0]."-".$arr_tgl2[1]; $data = array( 'nmjadwalpmb'=> $_POST['nmjadwalpmb'], 'deskripsi'=> $_POST['deskripsi'], 'kdstsemester'=> $_POST['kdstsemester'], 'idstatus'=> $this->id_field('idstatus', 'status', 'nmstatus',$_POST['idstatus']), 'daritgl'=> $daritgl, 'sampaitgl'=>$sampaitgl ); $this->db->trans_begin(); $where['kdjadwalpmb']=$this->input->post('kdjadwalpmb'); $this->db->where($where); $this->db->update("jadwalpmb", $data); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $return["success"]=false; $return["message"]="Ubah Data gagal"; } else { $this->db->trans_commit(); $return["success"]=true; $return["message"]="Ubah Data Berhasil"; } return $return; } function delete(){ //ISTRA $where['kdjadwalpmb']=$this->input->post('hapus_id'); $this->db->trans_begin(); // $this->db->where($where); $this->db->delete("jadwalpmb",$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; } //END STUDENT BODY } ?>