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 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("*"); $this->db->from("pengarang_buku"); if($id_module!=''){ $where['id_pengarang']=$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('pengarang_buku'); $ttl = $datax; //====================================================================== $build_array = array ("success"=>true,"results"=>$ttl,"data"=>array()); foreach($data as $row) { array_push($build_array["data"],array( 'id_pengarang'=>$row->id_pengarang, 'kd_pengarang'=>$row->kd_pengarang, 'nama_pengarang'=>$row->nama_pengarang, )); } echo json_encode($build_array); } function save(){ // ISTRA $data = array( 'id_pengarang'=> $this->autoNumber('id_pengarang','pengarang_buku'), 'kd_pengarang'=> $_POST['kd_pengarang'], 'nama_pengarang'=> $_POST['nama_pengarang'], ); $this->db->insert('pengarang_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 $data = array( 'kd_pengarang'=> $_POST['kd_pengarang'], 'nama_pengarang'=> $_POST['nama_pengarang'], ); $this->db->trans_begin(); $where['id_pengarang']=$this->input->post('id_pengarang'); $this->db->where($where); $this->db->update("pengarang_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"; } return $return; } function delete(){ //ISTRA $where['id_pengarang']=$this->input->post('hapus_id'); $this->db->trans_begin(); // $this->db->where($where); $this->db->delete("pengarang_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; } //END JENIS KELOMPOK PENGGUNA }