Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Tasks extends CI_Controller
- {
- function __construct() {
- parent::__construct();
- }
- function manage()
- {
- $data['query'] = $this->get('id');
- $data['query_priority'] = $this->get_where_custom('priority',1);
- $data['query_others'] = $this->get_where_custom('priority',0);
- $this->load->view('tasks/manage.php', $data);
- }
- function create()
- {
- $mysql_query = "select * from users";
- $data['users']=$this->_custom_query($mysql_query);
- $submit = $this->input->post('submit');
- if ($submit =="Cancel") {
- redirect('tasks/manage');
- }
- $this->form_validation->set_rules('task','Task','required');
- $this->form_validation->set_rules('user_id','Full Name','required');
- $this->form_validation->set_rules('priority','Priority');
- $this->form_validation->set_rules('date_started','date started','required');
- $this->form_validation->set_rules('date_finished','date finished','required');
- if ($this->form_validation->run() == FALSE) {
- $this->load->view('tasks/create.php', $data);
- } else {
- $data = $this->fetch_data_from_post();
- $this->_insert($data);
- redirect('tasks/manage');
- }
- }
- function fetch_data_from_post()
- {
- $employee['task'] = $this->input->post('task', TRUE);
- $employee['user_id'] = $this->input->post('user_id', TRUE);
- $value = $this->input->post('priority', TRUE);
- if (isset($value)) {
- $employee['priority'] = 1;
- }else{
- $employee['priority'] = 0;
- }
- $employee['date_started'] = $this->input->post('date_started', TRUE);
- $employee['date_finished'] = $this->input->post('date_finished', TRUE);
- return $employee;
- }
- function update()
- {
- $update_id = $this->uri->segment(3);
- $submit = $this->input->post('submit');
- if ($submit =="Cancel") {
- redirect('tasks/manage');
- }
- $this->form_validation->set_rules('task','Task','required');
- $this->form_validation->set_rules('user_id','Assigned','required');
- $this->form_validation->set_rules('priority','Priority');
- $this->form_validation->set_rules('date_started','date started','required');
- $this->form_validation->set_rules('date_finished','date finished','required');
- if ($this->form_validation->run() == FALSE) {
- $data = $this->fetch_data_from_db($update_id);
- $data['update_id'] = $update_id;
- $mysql_query = "select * from users";
- $data['users']=$this->_custom_query($mysql_query);
- $data['priority'] = $this->fetch_data_from_db($update_id);
- $this->load->view('tasks/update.php', $data);
- } else {
- $data = $this->fetch_data_from_post();
- $this->_update($update_id, $data);
- redirect('tasks/manage');
- }
- }
- function delete()
- {
- $update_id = $this->uri->segment(3);
- $this->_delete($update_id);
- redirect('tasks/manage');
- }
- function fetch_data_from_db($update_id)
- {
- $query = $this->get_where($update_id);
- foreach ($query->result() as $row) {
- $data['task'] = $row->task;
- $data['user_id'] = $row->user_id;
- $data['priority'] = $row->priority;
- $data['date_started'] = $row->date_started;
- $data['date_finished'] = $row->date_finished;
- }
- if(!isset($data)){
- $data = "";
- }
- return $data;
- }
- ///////////////////////////////////////////////////
- function get($order_by)
- {
- $this->load->model('mdl_tasks');
- $query = $this->mdl_tasks->get($order_by);
- return $query;
- }
- function get_with_limit($limit, $offset, $order_by)
- {
- if ((!is_numeric($limit)) || (!is_numeric($offset))) {
- die('Non-numeric variable!');
- }
- $this->load->model('mdl_tasks');
- $query = $this->mdl_tasks->get_with_limit($limit, $offset, $order_by);
- return $query;
- }
- function get_where_custom($col, $value)
- {
- $this->load->model('mdl_tasks');
- $query = $this->mdl_tasks->get_where_custom($col, $value);
- return $query;
- }
- function _insert($data)
- {
- $this->load->model('mdl_tasks');
- $this->mdl_tasks->_insert($data);
- }
- function _update($id, $data)
- {
- if (!is_numeric($id)) {
- die('Non-numeric variable!');
- }
- $this->load->model('mdl_tasks');
- $this->mdl_tasks->_update($id, $data);
- }
- function _delete($id)
- {
- if (!is_numeric($id)) {
- die('Non-numeric variable!');
- }
- $this->load->model('mdl_tasks');
- $this->mdl_tasks->_delete($id);
- }
- function count_where($column, $value)
- {
- $this->load->model('mdl_tasks');
- $count = $this->mdl_tasks->count_where($column, $value);
- return $count;
- }
- function get_max()
- {
- $this->load->model('mdl_tasks');
- $max_id = $this->mdl_tasks->get_max();
- return $max_id;
- }
- function _custom_query($mysql_query)
- {
- $this->load->model('mdl_tasks');
- $query = $this->mdl_tasks->_custom_query($mysql_query);
- return $query;
- }
- function get_where($id)
- {
- if (!is_numeric($id)) {
- die('Non-numeric variable!');
- }
- $this->load->model('mdl_tasks');
- $query = $this->mdl_tasks->get_where($id);
- return $query;
- }
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement