load->library('session'); $this->load->library('rhlib'); } function retValOrNull($val){ //especially for combo & looukup with no item selected $val = ($val=='')? null : $val; return $val; } //view function get_bdnhukum(){ $this->load->library('rhlib'); $q = "SELECT * FROM badanhukum"; //$row = $q->num_rows(); $this->rhlib->jsonFromQueryWLimit($q); } //insert function insert_bdnhukum(){ /* $judul = $_POST['kdbadanhukum']; $foto1 = $_POST['userfile1']; $foto2 = $_POST['userfile2']; if ($foto1 <> '') { $nama_asli1 = $_FILES['filedata1']['name']; $config['file_name'] = $judul.'_'.'_'.$nama_asli1; } if ($foto2 <> ''){ $nama_asli2 = $_FILES['filedata2']['name']; $config['file_name'] = $judul.'_'.'_'.$nama_asli2; } */ //$this->resizeImg(); $config['upload_path'] = './resources/logo_unla/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = '1000'; $config['max_width'] = '1024'; $config['max_height'] = '768'; $this->load->library('upload', $config); if (!$this->upload->do_upload('filedata1') || !$this->upload->do_upload('filedata2')) { $error = array('error' => $this->upload->display_errors()); $return["success"]='false'; $return["message"]='Simpan Data Gagal'; echo json_encode($return); } else { $data=$this->upload->data(); $this->load->library('rhlib'); $dataArray = $this->getFieldsAndValues(); $ret = $this->rhlib->insertRecord('badanhukum',$dataArray); if ($ret) { $return["success"]='true'; $return["message"]='Simpan Data Berhasil'; } else { $return["success"]='true'; $return["message"]='Simpan Data Gagal'; } echo json_encode($return); } } //update function update_bdnhukum(){ $count=0; $img1 =$_POST['image1']; $img2 =$_POST['image2']; $config['upload_path'] = './resources/logo_unla/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = '1000'; $config['max_width'] = '1024'; $config['max_height'] = '768'; $this->load->library('upload', $config); //kondisi filedata1 if ($_FILES['filedata1']['name']) { //$sub_data['error'] = $this->upload->display_errors(); if($this->upload->do_upload('filedata1')) { unlink("resources/logo_unla/$img1"); $count=1; } else { $count=0; } } //kondisi filedata2 if ($_FILES['filedata2']['name']) { //$sub_data['error'] = $this->upload->display_errors(); if($this->upload->do_upload('filedata2')) { unlink("resources/logo_unla/$img2"); $count=1; } else { $count=0; } } //simpan data ke db $update = $this->updatedatanya(); //kondisi update if ($update) { $count=1; } else { $count=0; } 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 updatedatanya(){ $data=$this->upload->data(); $this->load->library('rhlib'); $dataArray = $this->getFieldsAndValues(); //UPDATE $this->db->where('kdbadanhukum', $_POST['kdbadanhukum']); $this->db->update('badanhukum', $dataArray); if($this->db->affected_rows()){ $ret["success"]=true; $ret["msg"]='Update Data Berhasil'; }else{ $ret["success"]=false; $ret["msg"]= 'Update Data Gagal'; } return $ret; } //delete function delete_bdnhukum(){ $gbr1= $_POST['gambar1']; $gbr2= $_POST['gambar2']; unlink("resources/logo_unla/$gbr1"); unlink("resources/logo_unla/$gbr2"); $this->load->library('rhlib'); $where['kdbadanhukum'] = $_POST['kdbadanhukum']; $ret = $this->rhlib->deleteRecord('badanhukum',$where); return $ret; } //resize function resizeImg(){ $config['image_library'] = 'gd2'; $config['source_image'] = '/resources/logo_unla/'; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['width'] = 75; $config['height'] = 50; $this->load->library('image_lib', $config); $this->image_lib->resize(); } //variable post function getFieldsAndValues(){ $dataArray = array( 'kdbadanhukum'=> $_POST['kdbadanhukum'], 'nmbadanhukum' => $_POST['nmbadanhukum'], 'alamat1'=> $_POST['alamat1'], 'alamat2'=> $_POST['alamat2'], 'kota' => $_POST['kota'], 'kdpos' => $_POST['kdpos'], 'notelp' => $_POST['notelp'], 'nofax' => $_POST['nofax'], 'tglakta' => $_POST['tglakta'], 'nmakta' => $_POST['nmakta'], 'tglpengesahan' => $_POST['tglpengesahan'], 'nopengesahan' => $_POST['nopengesahan'], 'email' => $_POST['email'], 'website' => $_POST['website'], 'tglberdiri' => $_POST['tglberdiri'], 'gambar1' => $_POST['userfile1'], 'gambar2' => $_POST['userfile2'], ); return $dataArray; } function grid(){ //ISTRA //====================================================================== $this->db->select("*"); $this->db->from("badanhukum"); $q = $this->db->get(); $data = array(); if ($q->num_rows() > 0) { $data = $q->result(); } $datax = $this->db->count_all('badanhukum'); $ttl = $datax; //====================================================================== $build_array = array ("success"=>true,"results"=>$ttl,"data"=>array()); foreach($data as $row) { array_push($build_array["data"],array( 'kdbadanhukum'=>$row->kdbadanhukum, 'nmbadanhukum'=>$row->nmbadanhukum, 'alamat1'=>$row->alamat1, 'alamat2'=>$row->alamat2, 'kota'=>$row->kota, 'kdpos'=>$row->kdpos, 'notelp'=>$row->notelp, 'nofax'=>$row->nofax, 'tglakta'=>$row->tglakta, 'nmakta'=>$row->nmakta, 'tglpengesahan'=>$row->tglpengesahan, 'nopengesahan'=>$row->nopengesahan, 'email'=>$row->email, 'pass'=>base64_decode($row->pass), //'pass'=>$row->pass, 'website'=>$row->website, 'tglberdiri'=>$row->tglberdiri, )); } echo json_encode($build_array); } function update(){ // ISTRA $arr_tgl1 = explode('/',$this->input->post("tglakta")); $tglakta = $arr_tgl1[2]."-".$arr_tgl1[0]."-".$arr_tgl1[1]; $arr_tgl2 = explode('/',$this->input->post("tglpengesahan")); $tglpengesahan = $arr_tgl2[2]."-".$arr_tgl2[0]."-".$arr_tgl2[1]; $arr_tgl3 = explode('/',$this->input->post("tglberdiri")); $tglberdiri = $arr_tgl2[2]."-".$arr_tgl2[0]."-".$arr_tgl2[1]; $temp = $this->input->post("nmthnakademik"); $tahun= substr($temp,0,4); $jenis= substr($temp,12); if ($jenis == 'Ganjil') { $tahunakademik = $tahun."1"; } else { $tahunakademik = $tahun."2"; } $data = array( 'kdbadanhukum'=>$_POST['kdbadanhukum'], 'nmbadanhukum'=>$_POST['nmbadanhukum'], 'alamat1'=>$_POST['alamat1'], 'alamat2'=>$_POST['alamat2'], 'kota'=>$_POST['kota'], 'kdpos'=>$_POST['kdpos'], 'notelp'=>$_POST['notelp'], 'nofax'=>$_POST['nofax'], 'tglakta'=>$tglakta, 'nmakta'=>$_POST['nmakta'], 'tglpengesahan'=>$tglpengesahan, 'nopengesahan'=>$_POST['nopengesahan'], 'email'=>$_POST['email'], 'pass'=>base64_encode($_POST['pass']), //'pass'=>$_POST['pass'], 'website'=>$_POST['website'], 'tglberdiri'=>$tglberdiri ); $this->db->trans_begin(); $where['kdbadanhukum']=$this->input->post('kdbadanhukum'); $this->db->where($where); $this->db->update("badanhukum", $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"; $this->rhlib->updateRecordPublic('badanhukum',$data,$where); } return $return; } } ?>