Sebuahhobi98

summernote controllel

Sep 12th, 2019
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. $this->output->set_content_type('application/json');
  2. $this->_rules();
  3. $this->form_validation->set_rules('judul', 'Judul', 'trim|required|is_unique[post.judul]',
  4. array(
  5. 'required' => 'Kolom %s harus di isi!',
  6. 'is_unique' => '%s dengan nama ini sudah ada!'
  7. ));
  8.  
  9. $foto['allowed_types'] = 'jpg|png|jpeg';
  10. $foto['overwrite'] = TRUE;
  11. $foto['file_name'] = judul_seo($this->input->post('judul')).'-'.get_data_dinamis('fakultas', 'nama_fsi', $this->config->item('fsi'), 'id');
  12. $foto['upload_path'] = './assets/upload/post/';
  13.  
  14. $this->load->library('upload', $foto);
  15.  
  16. $admin = array('admin','ketum');
  17. if($this->ion_auth->in_group($admin)){
  18. $this->form_validation->set_rules('status', 'Status Post', 'trim|required',array('required' => 'Kolom %s harus di isi!'));
  19. }
  20.  
  21. if ($this->form_validation->run() == FALSE) {
  22. $data = array(
  23. 'judul' => form_error('judul'),
  24. 'kategori' => form_error('kategori'),
  25. 'isi_post' => form_error('isi_post'),
  26. 'tags' => form_error('tags'),
  27. );
  28. if($this->ion_auth->in_group($admin)){
  29. $data['status'] = form_error('status');
  30. }
  31. if(! $this->upload->do_upload("foto")){
  32. $data['foto'] = $this->upload->display_errors('','');
  33. }
  34. echo json_encode([
  35. 'error' => $data,
  36. 'status_data' => 99,
  37. 'token' => $this->security->get_csrf_hash(),
  38. ]);
  39. }else{
  40. $data = array(
  41. 'judul' => $this->input->post('judul',TRUE),
  42. 'kategori' => $this->input->post('kategori',TRUE),
  43. 'isi_post' => $this->input->post('isi_post',TRUE),
  44. 'tags' => $this->input->post('tags',TRUE),
  45. 'uploader' => $this->session->userdata('user_login'),
  46. 'tgl_upload' => date('Y-m-d'),
  47. 'id_fsi' => $this->config->item('fsi'),
  48. 'status' => 'pending',
  49. );
  50.  
  51. if ($this->upload->do_upload("foto")) {
  52. $data['nama_foto'] = $this->upload->data('file_name');
  53. $data['type_foto'] = $this->upload->data('file_type');
  54. $data['ukuran_foto'] = $this->upload->data('file_size');
  55. $data['ext_foto'] = $this->upload->data('file_ext');
  56. }
  57.  
  58. if($this->ion_auth->in_group($admin)){
  59. $data['published'] = $this->session->userdata('user_login');
  60. $data['status'] = $this->input->post('status');
  61. }
  62. $this->Post_model->insert($data);
  63. $sukses=array(
  64. 'status_data' => $this->db->affected_rows(),
  65. 'sukses' => 'Sukses',
  66. 'token' => $this->security->get_csrf_hash(),
  67. );
  68. $this->session->set_flashdata('message', 'Create Record Success');
  69. echo json_encode($sukses);
  70. }
Add Comment
Please, Sign In to add comment