load->library('session'); } function retValOrNull($val){ //especially for combo & looukup with no item selected $val = ($val=='')? null : $val; return $val; } //view function get_ptinggi(){ $this->load->library('rhlib'); $q = "SELECT * FROM pt"; //$row = $q->num_rows(); $this->rhlib->jsonFromQueryWLimit($q); } //insert function insert_ptinggi(){ /* $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('pt',$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_ptinggi(){ $count=0; $img1 =$_POST['idimage1']; $img2 =$_POST['idimage2']; $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('kdpt', $_POST['kdpt']); $this->db->update('pt', $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_ptinggi(){ $gbr1= $_POST['gambar1']; $gbr2= $_POST['gambar2']; unlink("resources/logo_unla/$gbr1"); unlink("resources/logo_unla/$gbr2"); $this->load->library('rhlib'); $where['kdpt'] = $_POST['kdpt']; $ret = $this->rhlib->deleteRecord('pt',$where); return $ret; } //variable post function getFieldsAndValues(){ $dataArray = array( 'kdbadanhukum'=> $_POST['kdbdnhukum'], 'kdpt'=> $_POST['kdpt'], 'nmpt' => $_POST['nmpt'], 'alamat1'=> $_POST['alamat1'], 'alamat2'=> $_POST['alamat2'], 'kota' => $_POST['kota'], 'kdpos' => $_POST['kdpos'], 'notelp' => $_POST['notelp'], 'nofax' => $_POST['nofax'], 'tglakta' => $_POST['tglakta'], 'noakta' => $_POST['noakta'], 'email' => $_POST['email'], 'website' => $_POST['website'], 'tglberdiri' => $_POST['tglberdiri'], 'gambar1' => $_POST['userfile1'], 'gambar2' => $_POST['userfile2'], ); return $dataArray; } } ?>