load->library('rhlib'); } function get_uploadfiles(){ $q = "SELECT up.*, date_format(up.tglupload, '%d/%m/%Y') as tgluploadrender, pg.nmlengkap, date_format(up.tglupdate, '%d/%m/%Y') as tglupdaterender, pgup.nmlengkap AS nmlengkapupdate, st.nmstatus FROM uploadfile up LEFT JOIN status st ON up.idstatus = st.idstatus LEFT JOIN pengguna pg ON up.userid = pg.userid LEFT JOIN pengguna pgup ON up.useridupdate = pgup.userid"; $this->rhlib->jsonFromQuery($q); } function upload_file(){ $kode = $this->input->post('tf_kodeuploadfile'); $dir_files = 'resources/upload_files/'; $return["filename"]=$_FILES['fu_fileupload']['name']; $return["newname"]= $kode.'_'.str_replace(" ", "_", $return["filename"]); if ($_FILES['fu_fileupload']['size'] <= 5000000) { // jika foto kurang dari 5000kb (5MB) $isUpload = move_uploaded_file($_FILES['fu_fileupload']['tmp_name'], $dir_files . $return["newname"]); if ($isUpload) { $return["success"]='true'; } else { $return["success"]='false-up'; } } else { // jika foto lebih dari 5000kb (5MB) $return["success"]='false-size'; } return $return; } function insert_uploadfile(){ $uploadfile = $this->upload_file(); $data = array( 'kodeuploadfile'=>$_POST['tf_kodeuploadfile'], 'juduluploadfile'=>$_POST['tf_juduluploadfile'], 'deskripsi'=> ($_POST['hm_deskripsi']) ? $_POST['hm_deskripsi']:null, 'fileupload'=> $uploadfile['newname'], 'userid'=>$_POST['userid'], 'idstatus'=>$_POST['h_status'], 'tglupload'=> date('Y-m-d'), 'jamupload'=>date('H:i:s'), ); if ($uploadfile['success']=='true') { $this->db->insert('uploadfile', $data); if(!$this->db->affected_rows()){ unlink("resources/upload_files/".$_POST['fileupload']); } } echo json_encode($uploadfile); } function update_uploadfile(){ // ISTRA $data = array( 'juduluploadfile'=>$_POST['tf_juduluploadfile'], 'deskripsi'=> ($_POST['hm_deskripsi']) ? $_POST['hm_deskripsi']:null, 'idstatus'=>$_POST['h_status'], 'useridupdate'=>$_POST['userid'], 'tglupdate'=> date('Y-m-d'), 'jamupdate'=>date('H:i:s'), ); $this->db->trans_begin(); $where['kodeuploadfile']=$this->input->post('kodeuploadfile'); $this->db->where($where); $this->db->update("uploadfile", $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"; } echo json_encode($return); } function delete_uploadfile(){ //ISTRA $where['kodeuploadfile']=$this->input->post('kodeuploadfile'); $this->db->trans_begin(); $this->db->delete("uploadfile",$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"; unlink("resources/upload_files/".$_POST['fileupload']); } return $return; } }