load->library('session'); #start check auth $authorizationHeader['Authorization'] = str_replace('Bearer ', '', $_SERVER['HTTP_AUTHORIZATION']); $login = @$this->my_usessionpublic->logged_in ? : false; if ($authorizationHeader['Authorization'] && $login) { if(strpos($_SERVER['HTTP_AUTHORIZATION'], 'Bearer ') !== 0){ $cek['status'] = false; $cek['message'] = "Wrong number of segments"; $this->my_usessionpublic->set_userdata('pesan', $cek['message']); echo json_encode($cek); redirect('index.php/user/ext_logout'); die; } } else { $cek['status'] = false; $cek['message'] = "Please try login again."; $this->my_usessionpublic->set_userdata('pesan', $cek['message']); echo json_encode($cek); redirect('index.php/user/ext_logout'); die; } $cek = check_auth($authorizationHeader, $login); if(isset($cek['status']) && $cek['status'] == true){ // continue; } else{ $this->my_usessionpublic->set_userdata('pesan', $cek['message']); echo json_encode($cek); redirect('index.php/user/ext_logout'); die; } #end check auth } 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"); $user = $this->my_usessionpublic->userdata('user_id1'); $this->db->select("*"); $this->db->from("materi"); $where = array(); if($this->my_usessionpublic->userdata('level_member1') != 1){ $where['userid']=$user; } if($id_module){ $where['idmateri']=$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('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 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_katalog(){ //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('id_pengarang', 'pengarang_buku', 'nama_pengarang',$this->input->post('id_pengarang')); $dsn = $this->id_field('id_kategori', 'kategori_buku', 'nama_kategori',$this->input->post('id_kategori')); $jdl = $this->input->post("judul_buku"); $this->db->select("*"); $this->db->from("katalog_buku"); $where = array(); if($this->input->post('cpengarang')=='true'){ $where['id_pengarang']=$mk; } if($this->input->post('ckategori')=='true'){ $where['id_kategori']=$dsn; } if($this->input->post('cjudul')=='true'){ $k=array('[',']','"'); $r=str_replace($k, '', 'judul_buku'); $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('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, 'id_pengarang'=>$this->nm_field('nama_pengarang','pengarang_buku','id_pengarang',$row->id_pengarang), 'id_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 upload(){ $config['upload_path'] = './resources/materi_file/'; $config['allowed_types'] = 'doc|docx|pdf|ppt|pptx|xls|xlsx|txt|rar|zip'; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('file-path')) { $return["success"]='false'; } else { $data=$this->upload->data(); $this->save($data); $return["success"]='true'; } echo json_encode($return); } function save($dt){ // ISTRA $arr_tgl1 = explode('/',$this->input->post("tglpublish")); $tglpublish = $arr_tgl1[2]."-".$arr_tgl1[0]."-".$arr_tgl1[1]; $data = array( 'idmateri'=> $this->autoNumber('idmateri','materi'), 'idmk'=> ($_POST['idmk']=="Pilih...") ? null:$this->id_field('idmk', 'matakuliah', 'nmmk',$_POST['idmk']), 'idsesi'=> ($_POST['idsesi']=="Pilih...") ? null:$this->id_field('idsesi', 'sesi', 'nmsesi',$_POST['idsesi']), 'userid'=> $this->id_field('userid', 'pengguna', 'nmlengkap',$_POST['pengguna']), 'subjek'=> $_POST['subjek'], 'deskripsi'=> $_POST['deskripsi'], 'tujuan'=>$_POST['tujuan'], 'catatan'=>$_POST['catatan'], 'idstpublish'=> ($_POST['idstpublish']=="Pilih...") ? null:$this->id_field('idstpublish', 'stpublish', 'nmstpublish',$_POST['idstpublish']), 'tglpublish'=> $tglpublish, 'jampublish'=>$_POST['jampublish'], 'file'=>$dt["file_name"], 'url'=> $dt['full_path'], 'tipe'=>$dt['file_ext'], 'download'=>NULL, ); $this->db->insert('materi', $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 $data = array( 'idmk'=> ($_POST['idmk']=="Pilih...") ? null:$this->id_field('idmk', 'matakuliah', 'nmmk',$_POST['idmk']), 'idsesi'=> ($_POST['idsesi']=="Pilih...") ? null:$this->id_field('idsesi', 'sesi', 'nmsesi',$_POST['idsesi']), 'userid'=> $this->id_field('userid', 'pengguna', 'nmlengkap',$_POST['pengguna']), 'subjek'=> $_POST['subjek'], 'deskripsi'=> $_POST['deskripsi'], 'tujuan'=>$_POST['tujuan'], 'catatan'=>$_POST['catatan'], 'idstpublish'=> ($_POST['idstpublish']=="Pilih...") ? null:$this->id_field('idstpublish', 'stpublish', 'nmstpublish',$_POST['idstpublish']), ); $this->db->trans_begin(); $where['idmateri']=$this->input->post('idmateri'); $this->db->where($where); $this->db->update("materi", $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['idmateri']=$this->input->post('hapus_id'); $where2=$this->input->post('hapus_id'); $data = $this->nm_field('url', 'materi', 'idmateri', $where2); unlink($data); $this->db->trans_begin(); // $this->db->where($where); $this->db->delete("materi",$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; } }