fadlyshafa

Untitled

Mar 20th, 2020
185
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. $id = $this->input->post('id');
  75. $this->form_validation->set_rules('subcategory_name', 'Subcategory Name', 'trim|required|min_length[3]|callback_alpha_dash_space');
  76. $this->form_validation->set_rules('category', 'Category', 'trim|required|greater_than[0]');
  77. if ($this->form_validation->run() == FALSE)
  78. {
  79. $this->edit($id);
  80. }
  81. else
  82. {
  83. $data = array(
  84. "category_id" => $this->input->post('category'),
  85. "sub_category_name" => $this->input->post('subcategory_name')
  86. );
  87. $proses = $this->subcategory1_model->editModel($data,$id);
  88. var_dump($proses);
  89. die;
  90. if($this->subcategory1_model->editModel($data,$id)){
  91.  
  92.  
  93. $log_data = array(
  94. 'user_id' => $this->session->userdata('user_id'),
  95. 'table_id' => $id,
  96. 'message' => 'Subcategory Updated'
  97. );
  98. $this->log_model->insert_log($log_data);
  99. redirect('subcategory1');
  100. }
  101. else{
  102. $this->session->set_flashdata('fail', 'Subcategory1 can not be Updated.');
  103. redirect("subcategory1",'refresh');
  104. }
  105. }
  106. }
  107. /*
  108. This function is to delete subcategory from database
  109. */
  110. public function delete($id){
  111. if($this->subcategory1_model->deleteModel($id)){
  112. $log_data = array(
  113. 'user_id' => $this->session->userdata('user_id'),
  114. 'table_id' => $id,
  115. 'message' => 'Subcategory Deleted'
  116. );
  117. $this->log_model->insert_log($log_data);
  118. redirect('subcategory1','refresh');
  119. }
  120. else{
  121. $this->session->set_flashdata('fail', 'Subcategory1 can not be Deleted.');
  122. redirect("subcategory1",'refresh');
  123. }
  124. }
  125. function alpha_dash_space($str) {
  126. if (! preg_match("/^([-a-zA-Z ])+$/i", $str))
  127. {
  128. $this->form_validation->set_message('alpha_dash_space', 'The %s field may only contain alpha, spaces and dashes.');
  129. return FALSE;
  130. }
  131. else
  132. {
  133. return TRUE;
  134. }
  135. }
  136. }
  137. ?>
RAW Paste Data