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 id_field_second($column,$tbl,$whereb, $wherea){ $KEDUA= $this->load->database('second', TRUE); $q = "SELECT ".$column." as id FROM ".$tbl." where ".$whereb." = '".$wherea."' " ; $query = $KEDUA->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 //====================================================================== $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"); $this->db->select("*"); if($id_module!=''){ $where['kdjurnal']=$id_module; $this->db->where($where); } 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'); $this->db->or_like($d, $query); // $this->db->bracket('close','like'); } //$this->db->order_by("JDASHBOARD"); if ($start!=null){ $this->db->limit($limit,$start); }else{ $this->db->limit(50,0); } $q = $this->db->get(); // $q = $this->db->get(); $data = array(); if ($q->num_rows() > 0) { $data = $q->result(); } $datax = $this->db->count_all('v_jurnal'); $ttl = $datax; //====================================================================== $build_array = array ("success"=>true,"results"=>$ttl,"data"=>array()); foreach($data as $row) { array_push($build_array["data"],array( 'kdjurnal'=>$row->kdjurnal, 'idjnsjurnal'=>$row->idjnsjurnal, 'judul'=>$row->judul, 'penulis'=>$row->penulis, 'warganegara'=>$row->warganegara, 'tglterbit'=>date("Y-m-d",strtotime($row->tglterbit)), 'deskripsi'=>$row->deskripsi, //'file'=>$row->file, 'idstpublish'=>$row->idstpublish, 'userid'=>$row->userid, 'tgluserinput'=>$row->tgluserinput, 'download'=>($row->download==null) ? 0:$row->download, 'url'=>$row->url, 'tipe'=>$row->tipe, 'dilihat'=>$row->dilihat, 'issn'=>$row->issn, //'cover'=>$row->cover, 'kdfakultas'=>$row->kdfakultas, 'kdprodi'=>$row->kdprodi, //'nmfakultas'=>$row->nmfakultas, //'nmprodi'=>$row->nmprodi, )); } echo json_encode($build_array); } function grid_list_jurnal(){ //ISTRA //====================================================================== $start = $this->input->post("start"); $limit = $this->input->post("limit"); $fields = $this->input->post("fields"); $query = $this->input->post("query"); $idjnsjurnal = $this->input->post("idjjurnal"); $issn = $this->input->post("issn"); $jdl = $this->input->post("judul"); $pengarang = $this->input->post("pengarang"); $this->db->select("*"); $this->db->from("v_jurnal"); $where = array(); if($this->input->post('cbjjurnal')=='true'){ $where['idjnsjurnal']=$idjnsjurnal; } if($this->input->post('cbissn')=='true'){ $k=array('[',']','"'); $r=str_replace($k, '', 'issn'); $b=explode(',', $r); $c=count($b); for($i=0;$i<$c;$i++){ $d[$b[$i]]=$issn; } $this->db->or_like($d, $issn); } if($this->input->post('cbjudul')=='true'){ $k=array('[',']','"'); $r=str_replace($k, '', 'judul'); $b=explode(',', $r); $c=count($b); for($i=0;$i<$c;$i++){ $d[$b[$i]]=$jdl; } $this->db->or_like($d, $jdl); } if($this->input->post('cbpengarang')=='true'){ $k=array('[',']','"'); $r=str_replace($k, '', 'penulis'); $b=explode(',', $r); $c=count($b); for($i=0;$i<$c;$i++){ $d[$b[$i]]=$pengarang; } $this->db->or_like($d, $pengarang); } $this->db->where($where); if ($start!=null){ $this->db->limit($limit,$start); }else{ $this->db->limit(15,0); } $q = $this->db->get(); $data = array(); if ($q->num_rows() > 0) { $data = $q->result(); } $datax = $this->db->count_all('v_jurnal'); $ttl = $datax; //====================================================================== $build_array = array ("success"=>true,"results"=>$ttl,"data"=>array()); foreach($data as $row) { array_push($build_array["data"],array( 'kdjurnal'=>$row->kdjurnal, 'idjnsjurnal'=>$row->idjnsjurnal, 'nmjnsjurnal'=>$row->nmjnsjurnal, 'judul'=>$row->judul, 'penulis'=>$row->penulis, 'warganegara'=>$row->warganegara, 'tglterbit'=>date("Y-m-d",strtotime($row->tglterbit)), 'deskripsi'=>$row->deskripsi, 'file'=>$row->file, 'idstpublish'=>$row->idstpublish, 'nmstpublish'=>$row->nmstpublish, 'userid'=>$row->userid, 'tgluserinput'=>$row->tgluserinput, 'download'=>($row->download==null) ? 0:$row->download, 'url'=>$row->url, 'tipe'=>$row->tipe, 'dilihat'=>$row->dilihat, 'issn'=>$row->issn, 'cover'=>$row->cover, 'kdfakultas'=>$row->kdfakultas, 'kdprodi'=>$row->kdprodi, 'nmfakultas'=>$row->nmfakultas, 'nmprodi'=>$row->nmprodi, )); } echo json_encode($build_array); } ///////////////////////////////START SAVE///////////////////////////////// function upload_save(){ $kdbig; $name_cover= str_replace(" ", "_", $_FILES['cover']['name']); $query = $this->db->query('SELECT max(kdjurnal) AS big FROM jurnal'); foreach ($query->result() as $row){ $kdbig = $row->big + 1; } if ($_FILES['cover']['size'] <= 800000) { // jika file kurang dari 800kb $_FILES['cover']['size'] <= 800000 //echo ''; //upload cover if (isset($_FILES['cover']['name']) && $_FILES['cover']['name'] != '') { //unset($configC); //$data = date("dmy"); //path where to save the video $configC['upload_path'] = './resources/jurnal/'; //$configC['max_size'] = '2048'; $configC['allowed_types'] = 'jpg|png|jpeg|JPG|PNG|JPEG'; $configC['overwrite'] = FALSE; $configC['file_name'] = $kdbig.$name_cover; //$configC['max_width'] = '1024'; //$configC['max_height'] = '768'; //$configC['remove_spaces'] = TRUE; //$file_nameC = $data.$_FILES['cover']['name']; //$configC['file_name'] = TRUE; //$file_nameC; $this->load->library('upload', $configC); $this->upload->initialize($configC); if (!$this->upload->do_upload('cover')) { echo $this->upload->display_errors(); } } //upload file if (isset($_FILES['file']['name']) && $_FILES['file']['name'] != '') { unset($configC); //$data = date("dmy"); //path where to save the image $configF['upload_path'] = './resources/jurnal/'; $configF['full_path'] = TRUE; $configF['file_ext'] = TRUE; $configF['allowed_types'] = 'doc|docx|pdf|rar|zip|DOC|DOCX|PDF|RAR|ZIP'; $configF['overwrite'] = FALSE; $configC['file_name'] = $kdbig; //$configF['remove_spaces'] = TRUE; //$file_nameF = $data.$_FILES['file']['name']; //$configF['file_name'] = TRUE; //$file_nameF; //$this->load->library('upload', $configF); $this->upload->initialize($configF); if (!$this->upload->do_upload('file')) { echo $this->upload->display_errors(); } } $data = $this->upload->data(); $update=$this->save($data); $return["success"]='true'; echo json_encode($return); }else{ //echo ''; $ret["success"]=false; return $ret; } } function save($dt){ // ISTRA $arr_tgl1 = explode('/',$this->input->post("tglterbit")); $tglterbit = $arr_tgl1[2]."-".$arr_tgl1[0]."-".$arr_tgl1[1]; $arr_tgl2 = explode('/',$this->input->post("tgluserinput")); $tgluserinput = $arr_tgl2[2]."-".$arr_tgl2[0]."-".$arr_tgl2[1]; //$data = date("dmy"); $name_file= str_replace(" ", "_", $_FILES['file']['name']); $name_cover= str_replace(" ", "_", $_FILES['cover']['name']); $kdbig; $query = $this->db->query('SELECT max(kdjurnal) AS big FROM jurnal'); foreach ($query->result() as $row){ $kdbig = $row->big + 1; } //$name_file = $_FILES['file']['name']; //$data.$_FILES['file']['name']; //$name_cover = $_FILES['cover']['name']; //$data.$_FILES['cover']['name']; /* $hit; $query = $this->db->query('SELECT COUNT(cover) AS hit FROM jurnal WHERE cover ="'.$name_cover.'"'); foreach ($query->result() as $row){ $hit = $row->hit; } if($hit > 0){ $name_cover = $name_cover.$hit; } */ $data = array( /* 'kdjurnal'=> $this->autoNumber('kdjurnal','jurnal'), */ 'idjnsjurnal'=> ($_POST['h_jnsjurnal']=="Pilih...") ? null:$_POST['h_jnsjurnal'], 'judul'=> strtoupper($_POST['judul']), 'penulis'=> $_POST['penulis'], 'warganegara'=> $_POST['warganegara'], 'tglterbit'=> $tglterbit, 'deskripsi'=> $_POST['deskripsi'], 'file'=> $name_file, 'idstpublish'=> ($_POST['h_status']=="Pilih...") ? null:$_POST['h_status'], 'userid'=> $_POST['userid'], 'tgluserinput'=> $tgluserinput, 'download'=>0, 'url'=> $dt['full_path'], //'C:/xampp/htdocs/unla.ac.id/resources/jurnal/'.$name_file, 'tipe'=> $dt['file_ext'], //$file_ext, 'issn'=> $_POST['issn'], 'cover'=> $kdbig.$name_cover, 'kdfakultas'=> ($_POST['h_fakultas']=="Pilih...") ? null:$_POST['h_fakultas'], 'kdprodi'=> ($_POST['h_prodi']=="Pilih...") ? null:$_POST['h_prodi'], ); $this->db->insert('jurnal', $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; } ///////////////////////////////END SAVE///////////////////////////////// ///////////////////////////////START UPDATE///////////////////////////////// function upload_update(){ $count=0; $kodejurnal = $this->input->post("kdjurnal"); $filedata; $coverdata; $query = $this->db->query('SELECT file,cover FROM jurnal WHERE kdjurnal ="'.$kodejurnal.'"'); foreach ($query->result() as $row){ $filedata = $row->file; $coverdata= $row->cover; } $lokasi_file = $_FILES['file']['tmp_name']; $lokasi_cover = $_FILES['cover']['tmp_name']; $kdbig; $name_cover= str_replace(" ", "_", $_FILES['cover']['name']); $query = $this->db->query('SELECT max(kdjurnal) AS big FROM jurnal'); foreach ($query->result() as $row){ $kdbig = $row->big + 1; } //--/--jika file dan cover kosong-----// if (empty($lokasi_file) && empty($lokasi_cover)){ $this->update_tanpafile(); $count=1; } //-----jika file isi-----// else if(isset($lokasi_file) && empty($lokasi_cover)){ //upload file if (isset($_FILES['file']['name']) && $_FILES['file']['name'] != '') { //$data = date("dmy"); //path where to save the image $configF['upload_path'] = './resources/jurnal/'; $configF['full_path'] = TRUE; $configF['file_ext'] = TRUE; $configF['allowed_types'] = 'doc|docx|pdf|rar|zip|DOC|DOCX|PDF|RAR|ZIP'; $configF['overwrite'] = FALSE; //$configF['remove_spaces'] = TRUE; //$file_nameF = $data.$_FILES['file']['name']; //$configF['file_name'] = TRUE; //$file_nameF; $this->load->library('upload', $configF); $this->upload->initialize($configF); if (!$this->upload->do_upload('file')) { echo $this->upload->display_errors(); } } //hapus file unlink("resources/jurnal/$filedata"); $count=1; //simpan data ke db $data=$this->upload->data(); $update = $this->update_denganfileisi($data); if ($update) { $count=1; } else { $count=0; } } //-----jika cover isi-----// else if(isset($lokasi_cover) && empty($lokasi_file)){ //upload cover if (isset($_FILES['cover']['name']) && $_FILES['cover']['name'] != '') { unset($configF); //$data = date("dmy"); //path where to save the video $configC['upload_path'] = './resources/jurnal/'; $configC['max_size'] = '2048'; $configC['allowed_types'] = 'jpg|png|jpeg|JPG|PNG|JPEG'; $configC['overwrite'] = FALSE; $configC['file_name'] = $kdbig.$name_cover; $configC['max_width'] = '1024'; $configC['max_height'] = '768'; //$configC['remove_spaces'] = TRUE; //$file_nameC = $data.$_FILES['cover']['name']; //$configC['file_name'] = TRUE; //$file_nameC; $this->load->library('upload', $configC); $this->upload->initialize($configC); if (!$this->upload->do_upload('cover')) { echo $this->upload->display_errors(); } } //hapus file unlink("resources/jurnal/$coverdata"); $count=1; //simpan data ke db $data=$this->upload->data(); $update = $this->update_dengancoverisi($data); if ($update) { $count=1; } else { $count=0; } } //-----jika file dan cover isi-----// else if(isset($lokasi_file) && isset($lokasi_cover)){ //upload cover if (isset($_FILES['cover']['name']) && $_FILES['cover']['name'] != '') { unset($configF); //$data = date("dmy"); //path where to save the video $configC['upload_path'] = '/resources/jurnal/'; $configC['max_size'] = '2048'; $configC['allowed_types'] = 'jpg|png|jpeg|JPG|PNG|JPEG'; $configC['overwrite'] = FALSE; $configC['file_name'] = $kdbig.$name_cover; $configC['max_width'] = '1024'; $configC['max_height'] = '768'; //$configC['remove_spaces'] = TRUE; //$file_nameC = $data.$_FILES['cover']['name']; //$configC['file_name'] = TRUE; //$file_nameC; $this->load->library('upload', $configC); $this->upload->initialize($configC); if (!$this->upload->do_upload('cover')) { echo $this->upload->display_errors(); } } //upload file if (isset($_FILES['file']['name']) && $_FILES['file']['name'] != '') { //$data = date("dmy"); //path where to save the image $configF['upload_path'] = './resources/jurnal/'; $configF['full_path'] = TRUE; $configF['file_ext'] = TRUE; $configF['allowed_types'] = 'doc|docx|pdf|rar|zip|DOC|DOCX|PDF|RAR|ZIP'; $configF['overwrite'] = FALSE; //$configF['remove_spaces'] = TRUE; //$file_nameF = $data.$_FILES['file']['name']; //$configF['file_name'] = TRUE; //$file_nameF; $this->load->library('upload', $configF); $this->upload->initialize($configF); if (!$this->upload->do_upload('file')) { echo $this->upload->display_errors(); } } //hapus file unlink("resources/jurnal/$filedata"); unlink("resources/jurnal/$coverdata"); $count=1; //simpan data ke db $data=$this->upload->data(); $update = $this->update_denganfile($data); if ($update) { $count=1; } else { $count=0; } } //validasi if ($count==0){ $return["success"]='false'; $return["message"]='Simpan Data Gagal'; }else if($count==1){ $return["success"]='true'; $return["message"]='Simpan Data Berhasil'; } echo json_encode($return); } function update_denganfile($dta){ // ISTRA $arr_tgl1 = explode('/',$this->input->post("tglterbit")); $tglterbit = $arr_tgl1[2]."-".$arr_tgl1[0]."-".$arr_tgl1[1]; $arr_tgl2 = explode('/',$this->input->post("tgluserinput")); $tgluserinput = $arr_tgl2[2]."-".$arr_tgl2[0]."-".$arr_tgl2[1]; //$data = date("dmy"); //$name_file = $_FILES['file']['name']; //$data.$_FILES['file']['name']; //$name_cover = $_FILES['cover']['name']; //$data.$_FILES['cover']['name']; $name_file= str_replace(" ", "_", $_FILES['file']['name']); $name_cover= str_replace(" ", "_", $_FILES['cover']['name']); $kdbig; $query = $this->db->query('SELECT max(kdjurnal) AS big FROM jurnal'); foreach ($query->result() as $row){ $kdbig = $row->big + 1; } $data = array( //'kdjurnal'=> $this->autoNumber('kdjurnal','jurnal'), 'idjnsjurnal'=> ($_POST['h_jnsjurnal']=="Pilih...") ? null:$_POST['h_jnsjurnal'], 'judul'=> strtoupper($_POST['judul']), 'penulis'=> $_POST['penulis'], 'warganegara'=> $_POST['warganegara'], 'tglterbit'=> $tglterbit, 'deskripsi'=> $_POST['deskripsi'], 'file'=> $name_file, 'idstpublish'=> ($_POST['h_status']=="Pilih...") ? null:$_POST['h_status'], 'userid'=> $_POST['userid'], 'tgluserinput'=> $tgluserinput, 'download'=>$_POST['download'], 'url'=> $dta['full_path'], //'C:/xampp/htdocs/unla.ac.id/resources/jurnal/'.$name_file, 'tipe'=> $dta['file_ext'], //$file_ext, 'issn'=> $_POST['issn'], 'cover'=> $kdbig.$name_cover, 'kdfakultas'=> ($_POST['h_fakultas']=="Pilih...") ? null:$_POST['h_fakultas'], 'kdprodi'=> ($_POST['h_prodi']=="Pilih...") ? null:$_POST['h_prodi'], ); $where['kdjurnal']=$this->input->post('kdjurnal'); $this->db->where($where); $this->db->update("jurnal", $data); if($this->db->affected_rows()){ $return["success"]=true; $return["message"]='Simpan Data Berhasil'; }else{ $return["success"]=false; $return["message"]='Simpan Data Gagal'; } return $return; } function update_tanpafile(){ // ISTRA $arr_tgl1 = explode('/',$this->input->post("tglterbit")); $tglterbit = $arr_tgl1[2]."-".$arr_tgl1[0]."-".$arr_tgl1[1]; $arr_tgl2 = explode('/',$this->input->post("tgluserinput")); $tgluserinput = $arr_tgl2[2]."-".$arr_tgl2[0]."-".$arr_tgl2[1]; $data = array( //'kdjurnal'=> $this->autoNumber('kdjurnal','jurnal'), 'idjnsjurnal'=> ($_POST['h_jnsjurnal']=="Pilih...") ? null:$_POST['h_jnsjurnal'], 'judul'=> strtoupper($_POST['judul']), 'penulis'=> $_POST['penulis'], 'warganegara'=> $_POST['warganegara'], 'tglterbit'=> $tglterbit, 'deskripsi'=> $_POST['deskripsi'], 'idstpublish'=> ($_POST['h_status']=="Pilih...") ? null:$_POST['h_status'], 'userid'=> $_POST['userid'], 'tgluserinput'=> $tgluserinput, 'download'=>$_POST['download'], 'issn'=> $_POST['issn'], 'kdfakultas'=> ($_POST['h_fakultas']=="Pilih...") ? null:$_POST['h_fakultas'], 'kdprodi'=> ($_POST['h_prodi']=="Pilih...") ? null:$_POST['h_prodi'], ); $where['kdjurnal']=$this->input->post('kdjurnal'); $this->db->where($where); $this->db->update("jurnal", $data); if($this->db->affected_rows()){ $return["success"]=true; $return["message"]='Simpan Data Berhasil'; }else{ $return["success"]=false; $return["message"]='Simpan Data Gagal'; } return $return; } function update_denganfileisi($dta){ // ISTRA $arr_tgl1 = explode('/',$this->input->post("tglterbit")); $tglterbit = $arr_tgl1[2]."-".$arr_tgl1[0]."-".$arr_tgl1[1]; $arr_tgl2 = explode('/',$this->input->post("tgluserinput")); $tgluserinput = $arr_tgl2[2]."-".$arr_tgl2[0]."-".$arr_tgl2[1]; //$data = date("dmy"); //$name_file = $_FILES['file']['name']; //$data.$_FILES['file']['name']; $name_file= str_replace(" ", "_", $_FILES['file']['name']); //$name_cover= str_replace(" ", "_", $_FILES['cover']['name']); $data = array( //'kdjurnal'=> $this->autoNumber('kdjurnal','jurnal'), 'idjnsjurnal'=> ($_POST['h_jnsjurnal']=="Pilih...") ? null:$_POST['h_jnsjurnal'], 'judul'=> strtoupper($_POST['judul']), 'penulis'=> $_POST['penulis'], 'warganegara'=> $_POST['warganegara'], 'tglterbit'=> $tglterbit, 'deskripsi'=> $_POST['deskripsi'], 'file'=> $name_file, 'idstpublish'=> ($_POST['h_status']=="Pilih...") ? null:$_POST['h_status'], 'userid'=> $_POST['userid'], 'tgluserinput'=> $tgluserinput, 'download'=>$_POST['download'], 'url'=> $dta['full_path'], //'C:/xampp/htdocs/unla.ac.id/resources/jurnal/'.$name_file, 'tipe'=> $dta['file_ext'], //$file_ext, 'issn'=> $_POST['issn'], 'kdfakultas'=> ($_POST['h_fakultas']=="Pilih...") ? null:$_POST['h_fakultas'], 'kdprodi'=> ($_POST['h_prodi']=="Pilih...") ? null:$_POST['h_prodi'], ); $where['kdjurnal']=$this->input->post('kdjurnal'); $this->db->where($where); $this->db->update("jurnal", $data); if($this->db->affected_rows()){ $return["success"]=true; $return["message"]='Simpan Data Berhasil'; }else{ $return["success"]=false; $return["message"]='Simpan Data Gagal'; } return $return; } function update_dengancoverisi($dta){ // ISTRA $arr_tgl1 = explode('/',$this->input->post("tglterbit")); $tglterbit = $arr_tgl1[2]."-".$arr_tgl1[0]."-".$arr_tgl1[1]; $arr_tgl2 = explode('/',$this->input->post("tgluserinput")); $tgluserinput = $arr_tgl2[2]."-".$arr_tgl2[0]."-".$arr_tgl2[1]; //$data = date("dmy"); //$name_cover = $_FILES['cover']['name']; //$data.$_FILES['cover']['name']; //$name_file= str_replace(" ", "_", $_FILES['file']['name']); $name_cover= str_replace(" ", "_", $_FILES['cover']['name']); $kdbig; $query = $this->db->query('SELECT max(kdjurnal) AS big FROM jurnal'); foreach ($query->result() as $row){ $kdbig = $row->big + 1; } $data = array( //'kdjurnal'=> $this->autoNumber('kdjurnal','jurnal'), 'idjnsjurnal'=> ($_POST['h_jnsjurnal']=="Pilih...") ? null:$_POST['h_jnsjurnal'], 'judul'=> strtoupper($_POST['judul']), 'penulis'=> $_POST['penulis'], 'warganegara'=> $_POST['warganegara'], 'tglterbit'=> $tglterbit, 'deskripsi'=> $_POST['deskripsi'], 'idstpublish'=> ($_POST['h_status']=="Pilih...") ? null:$_POST['h_status'], 'userid'=> $_POST['userid'], 'tgluserinput'=> $tgluserinput, 'download'=>$_POST['download'], 'issn'=> $_POST['issn'], 'cover'=> $kdbig.$name_cover, 'kdfakultas'=> ($_POST['h_fakultas']=="Pilih...") ? null:$_POST['h_fakultas'], 'kdprodi'=> ($_POST['h_prodi']=="Pilih...") ? null:$_POST['h_prodi'], ); $where['kdjurnal']=$this->input->post('kdjurnal'); $this->db->where($where); $this->db->update("jurnal", $data); if($this->db->affected_rows()){ $return["success"]=true; $return["message"]='Simpan Data Berhasil'; }else{ $return["success"]=false; $return["message"]='Simpan Data Gagal'; } return $return; } ///////////////////////////////END UPDATE///////////////////////////////// ///////////////////////////////START DELETE///////////////////////////////// function delete(){ //ISTRA $kodejurnal = $this->input->post('hapus_id'); $cover; $query = $this->db->query('SELECT cover FROM jurnal WHERE kdjurnal ="'.$kodejurnal.'"'); foreach ($query->result() as $row){ $cover = $row->cover; } $where['kdjurnal']=$this->input->post('hapus_id'); $where2=$this->input->post('hapus_id'); $data = $this->nm_field('url', 'jurnal', 'kdjurnal', $where2); $this->db->trans_begin(); // $this->db->where($where); $this->db->delete("jurnal",$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($data); unlink("resources/jurnal/$cover"); } return $return; } ///////////////////////////////END SAVE///////////////////////////////// function update_download(){ // ISTRA $kdjurnal=$this->input->post('kdjurnal'); $updatedown=$this->getdownload($kdjurnal); $data = array( 'download'=>$updatedown, ); $this->db->trans_begin(); $where['kdjurnal']=$kdjurnal; $this->db->where($where); $this->db->update("jurnal", $data); $this->simpandownload(); 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 getdownload($kdjurnal){ $q = "SELECT download AS down FROM jurnal WHERE kdjurnal='".$kdjurnal."'"; $query = $this->db->query($q); $newdown = ''; if ($query->num_rows() != 0) { $row = $query->row(); $newdown=$row->down + 1; } if ($newdown == null){ $newdown=0; } return $newdown; } function simpandownload(){ // ISTRA $userid=$this->id_field('userid', 'pengguna', 'nmlengkap',$_POST['pengguna']); $kdjurnal=$this->input->post('kdjurnal'); $this->db->query("CALL SP_simpan_jurnal_download (?,?)", array( $userid, $kdjurnal, )); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $return["success"]=false; $return["message"]="Simpan Data gagal"; } else { $this->db->trans_commit(); $return["success"]=true; $return["message"]="Simpan Data Berhasil"; } return $return; } function update_stpublish(){ $kdjurnal = $this->input->post('kdjurnal'); $idstpublish = $this->input->post('idstpublish'); //UPDATE $this->db->where('kdjurnal', $kdjurnal); $this->db->set('idstpublish', $idstpublish); $this->db->update('jurnal'); if($this->db->affected_rows()){ $ret["success"]=true; $ret["msg"]='Update Data Berhasil'; }else{ $ret["success"]=false; $ret["msg"]= 'Update Data Gagal'; } return $ret; } }