Advertisement
Guest User

dsdsds

a guest
Aug 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Tasks extends CI_Controller
  3. {
  4.  
  5. function __construct() {
  6. parent::__construct();
  7. }
  8.  
  9. function manage()
  10. {
  11. $data['query'] = $this->get('id');
  12. $data['query_priority'] = $this->get_where_custom('priority',1);
  13. $data['query_others'] = $this->get_where_custom('priority',0);
  14. $this->load->view('tasks/manage.php', $data);
  15. }
  16.  
  17. function create()
  18. {
  19. $mysql_query = "select * from users";
  20. $data['users']=$this->_custom_query($mysql_query);
  21.  
  22. $submit = $this->input->post('submit');
  23. if ($submit =="Cancel") {
  24. redirect('tasks/manage');
  25. }
  26. $this->form_validation->set_rules('task','Task','required');
  27. $this->form_validation->set_rules('user_id','Full Name','required');
  28. $this->form_validation->set_rules('priority','Priority');
  29. $this->form_validation->set_rules('date_started','date started','required');
  30. $this->form_validation->set_rules('date_finished','date finished','required');
  31.  
  32.  
  33. if ($this->form_validation->run() == FALSE) {
  34. $this->load->view('tasks/create.php', $data);
  35. } else {
  36. $data = $this->fetch_data_from_post();
  37. $this->_insert($data);
  38. redirect('tasks/manage');
  39. }
  40.  
  41. }
  42.  
  43. function fetch_data_from_post()
  44. {
  45. $employee['task'] = $this->input->post('task', TRUE);
  46. $employee['user_id'] = $this->input->post('user_id', TRUE);
  47. $value = $this->input->post('priority', TRUE);
  48. if (isset($value)) {
  49. $employee['priority'] = 1;
  50. }else{
  51. $employee['priority'] = 0;
  52. }
  53. $employee['date_started'] = $this->input->post('date_started', TRUE);
  54. $employee['date_finished'] = $this->input->post('date_finished', TRUE);
  55. return $employee;
  56. }
  57.  
  58. function update()
  59. {
  60.  
  61.  
  62. $update_id = $this->uri->segment(3);
  63. $submit = $this->input->post('submit');
  64. if ($submit =="Cancel") {
  65. redirect('tasks/manage');
  66. }
  67.  
  68. $this->form_validation->set_rules('task','Task','required');
  69. $this->form_validation->set_rules('user_id','Assigned','required');
  70. $this->form_validation->set_rules('priority','Priority');
  71. $this->form_validation->set_rules('date_started','date started','required');
  72. $this->form_validation->set_rules('date_finished','date finished','required');
  73.  
  74.  
  75. if ($this->form_validation->run() == FALSE) {
  76. $data = $this->fetch_data_from_db($update_id);
  77. $data['update_id'] = $update_id;
  78. $mysql_query = "select * from users";
  79. $data['users']=$this->_custom_query($mysql_query);
  80. $data['priority'] = $this->fetch_data_from_db($update_id);
  81. $this->load->view('tasks/update.php', $data);
  82. } else {
  83. $data = $this->fetch_data_from_post();
  84. $this->_update($update_id, $data);
  85. redirect('tasks/manage');
  86. }
  87. }
  88.  
  89. function delete()
  90. {
  91. $update_id = $this->uri->segment(3);
  92. $this->_delete($update_id);
  93. redirect('tasks/manage');
  94. }
  95.  
  96. function fetch_data_from_db($update_id)
  97. {
  98. $query = $this->get_where($update_id);
  99.  
  100. foreach ($query->result() as $row) {
  101. $data['task'] = $row->task;
  102. $data['user_id'] = $row->user_id;
  103. $data['priority'] = $row->priority;
  104. $data['date_started'] = $row->date_started;
  105. $data['date_finished'] = $row->date_finished;
  106. }
  107.  
  108. if(!isset($data)){
  109. $data = "";
  110. }
  111. return $data;
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. ///////////////////////////////////////////////////
  121. function get($order_by)
  122. {
  123. $this->load->model('mdl_tasks');
  124. $query = $this->mdl_tasks->get($order_by);
  125. return $query;
  126. }
  127.  
  128. function get_with_limit($limit, $offset, $order_by)
  129. {
  130. if ((!is_numeric($limit)) || (!is_numeric($offset))) {
  131. die('Non-numeric variable!');
  132. }
  133.  
  134. $this->load->model('mdl_tasks');
  135. $query = $this->mdl_tasks->get_with_limit($limit, $offset, $order_by);
  136. return $query;
  137. }
  138.  
  139.  
  140. function get_where_custom($col, $value)
  141. {
  142. $this->load->model('mdl_tasks');
  143. $query = $this->mdl_tasks->get_where_custom($col, $value);
  144. return $query;
  145. }
  146.  
  147. function _insert($data)
  148. {
  149. $this->load->model('mdl_tasks');
  150. $this->mdl_tasks->_insert($data);
  151. }
  152.  
  153. function _update($id, $data)
  154. {
  155. if (!is_numeric($id)) {
  156. die('Non-numeric variable!');
  157. }
  158.  
  159. $this->load->model('mdl_tasks');
  160. $this->mdl_tasks->_update($id, $data);
  161. }
  162.  
  163. function _delete($id)
  164. {
  165. if (!is_numeric($id)) {
  166. die('Non-numeric variable!');
  167. }
  168.  
  169. $this->load->model('mdl_tasks');
  170. $this->mdl_tasks->_delete($id);
  171. }
  172.  
  173. function count_where($column, $value)
  174. {
  175. $this->load->model('mdl_tasks');
  176. $count = $this->mdl_tasks->count_where($column, $value);
  177. return $count;
  178. }
  179.  
  180. function get_max()
  181. {
  182. $this->load->model('mdl_tasks');
  183. $max_id = $this->mdl_tasks->get_max();
  184. return $max_id;
  185. }
  186.  
  187. function _custom_query($mysql_query)
  188. {
  189. $this->load->model('mdl_tasks');
  190. $query = $this->mdl_tasks->_custom_query($mysql_query);
  191. return $query;
  192. }
  193.  
  194. function get_where($id)
  195. {
  196. if (!is_numeric($id)) {
  197. die('Non-numeric variable!');
  198. }
  199.  
  200. $this->load->model('mdl_tasks');
  201. $query = $this->mdl_tasks->get_where($id);
  202. return $query;
  203. }
  204.  
  205. }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement