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 KATALOG 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"); $user = $this->my_usessionpublic->userdata('user_id1'); $this->db->select("*"); $this->db->from("katalog_buku"); $where = array(); if($this->my_usessionpublic->userdata('level_member1') != 1){ $where['id_katalog']=$user; } if($id_module){ $where['id_katalog']=$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(); $data = array(); if ($q->num_rows() > 0) { $data = $q->result(); } $datax = $this->db->count_all('katalog_buku'); $ttl = $datax; //====================================================================== $build_array = array ("success"=>true,"results"=>$ttl,"data"=>array()); foreach($data as $row) { array_push($build_array["data"],array( 'id_katalog'=>$row->id_katalog, 'kd_katalog'=>$row->kd_katalog, 'nama_pengarang'=>$this->nm_field('nama_pengarang','pengarang_buku','id_pengarang',$row->id_pengarang), 'nama_kategori'=>$this->nm_field('nama_kategori','kategori_buku','id_kategori',$row->id_kategori), 'isbn'=>$row->isbn, 'judul_buku'=>$row->judul_buku, 'deskripsi'=>$row->deskripsi, 'tgl_terbit'=>date("Y-m-d",strtotime($row->tgl_terbit)), 'thn_terbit'=>$row->thn_terbit, )); } echo json_encode($build_array); } function grid_materi_prodi(){ //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("idmateri"); $q= $this->db->query("SELECT `prodi`.`kdprodi` AS `kdprodi` , `prodi`.`nmprodi` AS `nmprodi` , if(((SELECT `materiprodi`.`kdprodi` AS `kdprodi` FROM `materiprodi` WHERE ((`materiprodi`.`idmateri` = '".$id_module."') AND (`materiprodi`.`kdprodi` = `prodi`.`kdprodi`))) = `prodi`.`kdprodi`), 1, 0) AS `pilih` FROM `prodi`"); if($fields!="" || $query !=""){ $k=array('[',']','"'); $r=str_replace($k, '', $fields); $b=explode(',', $r); $c=count($b); for($i=0;$i<$c;$i++){ $d[$b[$i]]=$query; } $this->db->or_like($d, $query); } if ($start!=null){ $this->db->limit($limit,$start); }else{ $this->db->limit(50,0); } $data = array(); if ($q->num_rows() > 0) { $data = $q->result(); } $datax = $this->db->count_all('prodi'); $ttl = $datax; //====================================================================== $build_array = array ("success"=>true,"results"=>$ttl,"data"=>array()); foreach($data as $row) { array_push($build_array["data"],array( 'kdprodi'=>$row->kdprodi, 'nmprodi'=>$row->nmprodi, 'pilih'=>$row->pilih, )); } echo json_encode($build_array); } function grid_list_materi(){ //ISTRA //====================================================================== $start = $this->input->post("start"); $limit = $this->input->post("limit"); $fields = $this->input->post("fields"); $query = $this->input->post("query"); $mk = $this->id_field('idmk', 'matakuliah', 'nmmk',$this->input->post('idmk')); $dsn = $this->id_field_second('nidu', 'dosen', 'nmdostpgelar',$this->input->post('dosen')); $jdl = $this->input->post("judul"); $this->db->select("*"); $this->db->from("materi"); $where = array(); if($this->input->post('cbmk')=='true'){ $where['idmk']=$mk; } if($this->input->post('cbdosen')=='true'){ $where['userid']=$dsn; } if($this->input->post('cbjudul')=='true'){ $k=array('[',']','"'); $r=str_replace($k, '', 'subjek'); $b=explode(',', $r); $c=count($b); for($i=0;$i<$c;$i++){ $d[$b[$i]]=$jdl; } $this->db->or_like($d, $jdl); } $this->db->where($where); if ($start!=null){ $this->db->limit($limit,$start); }else{ $this->db->limit(50,0); } $q = $this->db->get(); $data = array(); if ($q->num_rows() > 0) { $data = $q->result(); } $datax = $this->db->count_all('materi'); $ttl = $datax; //====================================================================== $build_array = array ("success"=>true,"results"=>$ttl,"data"=>array()); foreach($data as $row) { array_push($build_array["data"],array( 'idmateri'=>$row->idmateri, 'idmk'=>$this->nm_field('nmmk','matakuliah','idmk',$row->idmk), 'idsesi'=>$this->nm_field('nmsesi','sesi','idsesi',$row->idsesi), 'pengguna'=>$this->nm_field('nmlengkap','pengguna','userid',$row->userid), 'subjek'=>$row->subjek, 'deskripsi'=>$row->deskripsi, 'tujuan'=>$row->tujuan, 'catatan'=>$row->catatan, 'idstpublish'=>$this->nm_field('nmstpublish','stpublish','idstpublish',$row->idstpublish), 'tglpublish'=>date("Y-m-d",strtotime($row->tglpublish)), 'jampublish'=>$row->jampublish, 'file'=>$row->file, 'url'=>$row->url, 'tipe'=>$row->tipe, 'download'=>($row->download==null) ? 0:$row->download, )); } echo json_encode($build_array); } function save(){ // ISTRA $data = array( 'id_katalog'=> $this->autoNumber('id_katalog','katalog_buku'), 'kd_katalog'=> $_POST['kd_katalog'], 'id_pengarang'=>($_POST['nama_pengarang']=="Pilih...") ? null:$this->id_field('id_pengarang', 'pengarang_buku', 'nama_pengarang',$_POST['nama_pengarang']), 'id_kategori'=>($_POST['nama_kategori']=="Pilih...") ? null:$this->id_field('id_kategori', 'kategori_buku', 'nama_kategori',$_POST['nama_kategori']), 'isbn'=> $_POST['isbn'], 'judul_buku'=> $_POST['judul_buku'], 'deskripsi'=> $_POST['deskripsi'], 'tgl_terbit'=> $_POST['tgl_terbit'], 'thn_terbit'=> $_POST['thn_terbit'], ); $this->db->insert('katalog_buku', $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("tgl_terbit")); $tglterbit = $arr_tgl1[2]."-".$arr_tgl1[0]."-".$arr_tgl1[1]; $data = array( 'id_katalog'=> $this->autoNumber('id_katalog','katalog_buku'), 'kd_katalog'=> $_POST['kd_katalog'], 'id_pengarang'=>($_POST['nama_pengarang']=="Pilih...") ? null:$this->id_field('id_pengarang', 'pengarang_buku', 'nama_pengarang',$_POST['nama_pengarang']), 'id_kategori'=>($_POST['nama_kategori']=="Pilih...") ? null:$this->id_field('id_kategori', 'kategori_buku', 'nama_kategori',$_POST['nama_kategori']), 'isbn'=> $_POST['isbn'], 'judul_buku'=> $_POST['judul_buku'], 'deskripsi'=> $_POST['deskripsi'], 'tgl_terbit'=> $tglterbit, 'thn_terbit'=> $_POST['thn_terbit'], ); $this->db->trans_begin(); $where['id_katalog']=$this->input->post('id_katalog'); $this->db->where($where); $this->db->update("katalog_buku", $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(){ //ISTRA $where['id_katalog']=$this->input->post('hapus_id'); $this->db->trans_begin(); // $this->db->where($where); $this->db->delete("katalog_buku",$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; } function simpanmateriprodi(){ $data=$this->input->post("pilihmateriprodi"); $this->db->trans_begin(); $rows = explode(";",$data); $row_count = count($rows); for($ri=0;$ri<$row_count;$ri++){ $rows2 = explode("x",$rows[$ri]); $this->db->query("CALL SP_simpan_materi_prodi (?,?,?)", array( $rows2[0], //idmateri $rows2[1], //kdprodi $rows2[2], //pilih )); } 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_download(){ // ISTRA $idmateri=$this->input->post('idmateri'); $updatedown=$this->getdownload($idmateri); $data = array( 'download'=>$updatedown, ); $this->db->trans_begin(); $where['idmateri']=$idmateri; $this->db->where($where); $this->db->update("materi", $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($idmateri){ $q = "SELECT download as down FROM materi where idmateri='".$idmateri."'"; $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']); $idmateri=$this->input->post('idmateri'); $this->db->query("CALL SP_simpan_materi_download (?,?)", array( $userid, $idmateri, )); 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; } }