fadlyshafa

Untitled

Mar 20th, 2020
211
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Subcategory1 extends CI_Controller
  4. {
  5. function __construct() {
  6. parent::__construct();
  7. $this->load->model('subcategory1_model');
  8. $this->load->model('log_model');
  9. }
  10. public function index(){
  11. $data['data'] = $this->subcategory1_model->getSubcategory();
  12. $this->load->view('subcategory1/list',$data);
  13. }
  14. /*
  15. call add subcategory view to add subcategory
  16. */
  17. public function add(){
  18. $data= $this->getCategory();
  19. $this->load->view('subcategory1/add',$data);
  20. }
  21. /*
  22. this function is used to get category list to select
  23. */
  24. public function getCategory(){
  25. $data['data'] = $this->subcategory1_model->getCategory();
  26. return $data;
  27. }
  28. /*
  29. this function is used to add subcategory record in database
  30. */
  31. public function addSubcategory(){
  32. $this->form_validation->set_rules('subcategory_name', 'Subcategory Name', 'trim|required|min_length[3]|callback_alpha_dash_space');
  33. $this->form_validation->set_rules('category', 'Category', 'trim|required|greater_than[0]');
  34. if ($this->form_validation->run() == FALSE)
  35. {
  36. $this->add();
  37. }
  38. else
  39. {
  40. // $subcategory_code = $this->subcategory_model->getMaxId();
  41. $data = array(
  42. "category_id" => $this->input->post('category'),
  43. "sub_category_code" => $this->input->post('subcategory_code'),
  44. "sub_category_name" => $this->input->post('subcategory_name')
  45. );
  46.  
  47. if($id = $this->subcategory1_model->addModel($data)){
  48. $log_data = array(
  49. 'user_id' => $this->session->userdata('user_id'),
  50. 'table_id' => $id,
  51. 'message' => 'Subcategory Inserted'
  52. );
  53. $this->log_model->insert_log($log_data);
  54. redirect('subcategory1');
  55. }
  56. else{
  57. $this->session->set_flashdata('fail', 'Subcategory can not be Inserted.');
  58. redirect("subcategory1",'refresh');
  59. }
  60. }
  61. }
  62. /*
  63. call edit view to edit record
  64. */
  65. public function edit($id){
  66. $data['category'] = $this->subcategory1_model->getCategory1();
  67. $data['data'] = $this->subcategory1_model->getRecord($id);
  68. $this->load->view('subcategory1/edit',$data);
  69. }
  70. /*
  71. this function is used to save edited record in database
  72. */
  73. public function editSubcategory(){
  74. echo 'asd';
  75. die;
  76. $id = $this->input->post('id');
  77. $this->form_validation->set_rules('subcategory_name', 'Subcategory Name', 'trim|required|min_length[3]|callback_alpha_dash_space');
  78. $this->form_validation->set_rules('category', 'Category', 'trim|required|greater_than[0]');
  79. if ($this->form_validation->run() == FALSE)
  80. {
  81. $this->edit($id);
  82. }
  83. else
  84. {
  85. $data = array(
  86. "category_id" => $this->input->post('category'),
  87. "sub_category_name" => $this->input->post('subcategory_name')
  88. );
  89. // $proses = $this->subcategory1_model->editModel($data,$id);
  90. // var_dump($proses);
  91. // die;
  92. if($this->subcategory1_model->editModel($data,$id)){
  93.  
  94.  
  95. $log_data = array(
  96. 'user_id' => $this->session->userdata('user_id'),
  97. 'table_id' => $id,
  98. 'message' => 'Subcategory Updated'
  99. );
  100. $this->log_model->insert_log($log_data);
  101. redirect('subcategory1');
  102. }
  103. else{
  104. $this->session->set_flashdata('fail', 'Subcategory1 can not be Updated.');
  105. redirect("subcategory1",'refresh');
  106. }
  107. }
  108. }
  109. /*
  110. This function is to delete subcategory from database
  111. */
  112. public function delete($id){
  113. if($this->subcategory1_model->deleteModel($id)){
  114. $log_data = array(
  115. 'user_id' => $this->session->userdata('user_id'),
  116. 'table_id' => $id,
  117. 'message' => 'Subcategory Deleted'
  118. );
  119. $this->log_model->insert_log($log_data);
  120. redirect('subcategory1','refresh');
  121. }
  122. else{
  123. $this->session->set_flashdata('fail', 'Subcategory1 can not be Deleted.');
  124. redirect("subcategory1",'refresh');
  125. }
  126. }
  127. function alpha_dash_space($str) {
  128. if (! preg_match("/^([-a-zA-Z ])+$/i", $str))
  129. {
  130. $this->form_validation->set_message('alpha_dash_space', 'The %s field may only contain alpha, spaces and dashes.');
  131. return FALSE;
  132. }
  133. else
  134. {
  135. return TRUE;
  136. }
  137. }
  138. }
  139. ?>
RAW Paste Data