Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $this->output->set_content_type('application/json');
- $this->_rules();
- $this->form_validation->set_rules('judul', 'Judul', 'trim|required|is_unique[post.judul]',
- array(
- 'required' => 'Kolom %s harus di isi!',
- 'is_unique' => '%s dengan nama ini sudah ada!'
- ));
- $foto['allowed_types'] = 'jpg|png|jpeg';
- $foto['overwrite'] = TRUE;
- $foto['file_name'] = judul_seo($this->input->post('judul')).'-'.get_data_dinamis('fakultas', 'nama_fsi', $this->config->item('fsi'), 'id');
- $foto['upload_path'] = './assets/upload/post/';
- $this->load->library('upload', $foto);
- $admin = array('admin','ketum');
- if($this->ion_auth->in_group($admin)){
- $this->form_validation->set_rules('status', 'Status Post', 'trim|required',array('required' => 'Kolom %s harus di isi!'));
- }
- if ($this->form_validation->run() == FALSE) {
- $data = array(
- 'judul' => form_error('judul'),
- 'kategori' => form_error('kategori'),
- 'isi_post' => form_error('isi_post'),
- 'tags' => form_error('tags'),
- );
- if($this->ion_auth->in_group($admin)){
- $data['status'] = form_error('status');
- }
- if(! $this->upload->do_upload("foto")){
- $data['foto'] = $this->upload->display_errors('','');
- }
- echo json_encode([
- 'error' => $data,
- 'status_data' => 99,
- 'token' => $this->security->get_csrf_hash(),
- ]);
- }else{
- $data = array(
- 'judul' => $this->input->post('judul',TRUE),
- 'kategori' => $this->input->post('kategori',TRUE),
- 'isi_post' => $this->input->post('isi_post',TRUE),
- 'tags' => $this->input->post('tags',TRUE),
- 'uploader' => $this->session->userdata('user_login'),
- 'tgl_upload' => date('Y-m-d'),
- 'id_fsi' => $this->config->item('fsi'),
- 'status' => 'pending',
- );
- if ($this->upload->do_upload("foto")) {
- $data['nama_foto'] = $this->upload->data('file_name');
- $data['type_foto'] = $this->upload->data('file_type');
- $data['ukuran_foto'] = $this->upload->data('file_size');
- $data['ext_foto'] = $this->upload->data('file_ext');
- }
- if($this->ion_auth->in_group($admin)){
- $data['published'] = $this->session->userdata('user_login');
- $data['status'] = $this->input->post('status');
- }
- $this->Post_model->insert($data);
- $sukses=array(
- 'status_data' => $this->db->affected_rows(),
- 'sukses' => 'Sukses',
- 'token' => $this->security->get_csrf_hash(),
- );
- $this->session->set_flashdata('message', 'Create Record Success');
- echo json_encode($sukses);
- }
Add Comment
Please, Sign In to add comment