load->library('session'); } function insert(){ // ISTRA $KEDUA= $this->load->database('second', TRUE); $arr_tgl1 = explode('T',$this->input->post("waktu")); $tglchat = $arr_tgl1[0]; //$arr_tgl2 = explode('T',$this->input->post("waktu")); $jamchat = date('g:i:s a');//$arr_tgl2[1]; $data = array( 'nim'=> $_POST['nim'], 'nidu'=> $_POST['nidu'], 'idjnspengguna'=> '0', 'kdstsemester'=> $_POST['kdstsemester'], 'tglchatpo'=>$tglchat." ".$jamchat, 'pesan'=> $_POST['pesan'], 'idpengirim'=> $_POST['idpengirim'], ); // $this->db->trans_begin(); $KEDUA->insert("chatpo", $data); if($KEDUA->affected_rows()){ $ret["success"]=true; $ret["message"]='Pesan Berhasil'; $ret["nim"]=$_POST['nim']; $ret["nidu"]=$_POST['nidu']; $ret["pesan"]=$_POST['pesan']; $ret["tglchatpo"]= date('g:i:s a');//$tglchat." ".$jamchat; }else{ $ret["success"]=false; $ret["message"]='Pesan Gagal'; $ret["nim"]=$_POST['nim']; $ret["nidu"]=$_POST['nidu']; $ret["pesan"]=$_POST['pesan']; $ret["tglchatpo"]=date('g:i:s a'); } echo json_encode($ret); } function grid(){ $KEDUA= $this->load->database('second', TRUE); $kdstsemester = $this->input->post("kdstsemester"); $nidu = $this->input->post("nidu"); $nim = $this->input->post("nim"); $KEDUA->select("*"); $KEDUA->from("chatpo"); if($kdstsemester!='' || $nidu!='' || $nim!=''){ $where['kdstsemester']=$kdstsemester; $where['nidu']=$nidu; $where['nim']=$nim; $KEDUA->where($where); } $KEDUA->order_by('idchatpo'); $q = $KEDUA->get(); $data = array(); if ($q->num_rows() > 0) { $data = $q->result(); } $datax = $KEDUA->count_all('chatpo'); $ttl = $datax; $tanggalkeluar=''; //====================================================================== $build_array = array ("success"=>true,"results"=>$ttl,"data"=>array()); foreach($data as $row) { if(trim(substr($row->tglchatpo,0,10))== date('Y-m-d')){ $tanggalkeluar=substr($row->tglchatpo,12,8);//date('g:i:s a'); }else{ $tanggalkeluar=date('d/m/Y', strtotime(substr($row->tglchatpo,0,10)));//date('d/m/Y'); } array_push($build_array["data"],array( 'success'=>true, 'idchatpo'=>$row->idchatpo, 'nim'=>$row->nim, //'nama'=>$row->nmpengirim, 'nidu'=>$row->nidu, 'pesan'=>$row->pesan, 'idpengirim'=>$row->idpengirim, 'tglchatpo'=>$tanggalkeluar, 'jumlah'=>$ttl )); } echo json_encode($build_array); } function delete(){ //ISTRA $KEDUA= $this->load->database('second', TRUE); $where['idchatpo']=$this->input->post('hapus_id'); $KEDUA->trans_begin(); $KEDUA->delete("chatpo",$where); if ($KEDUA->trans_status() === FALSE) { $KEDUA->trans_rollback(); $return["success"]=false; $return["message"]="Hapus Data gagal"; } else { $KEDUA->trans_commit(); $return["success"]=true; $return["message"]="Hapus Data Berhasil"; } return $return; } }