public function index() { $this->load->database(); $this->load->model('Project_model', '', true); $this->load->model('Todo_status_model', '', true); $this->load->model('Todo_model', '', true); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $this->load->library(array('form_validation')); $this->form_validation->set_rules('todo_sid', 'Todo Sid', 'intval'); $this->form_validation->set_rules('priority', 'Priority', 'intval'); $this->form_validation->set_rules('project_sid', 'Project Sid', 'intval|callback_validate_project_sid'); $this->form_validation->set_rules('todo_status_sid', 'Todo Status Sid', 'intval|required|callback_validate_todo_status_sid'); $this->form_validation->set_rules('text', 'Text', 'trim|required|min_length[1]|max_length[10000]'); if ($this->form_validation->run()) { $data = $this->input->post(); if (empty($data['todo_sid'])) { $this->db->insert('todo', array('priority' => (int) $data['priority'], 'project_sid' => empty($data['project_sid']) ? null : (int) $data['project_sid'], 'todo_status_sid' => (int) $data['todo_status_sid'], 'text' => $data['text'], 'date_created' => dateSql())); } else { $this->db->where('todo_sid', (int) $data['todo_sid']); $this->db->update('todo', array('priority' => (int) $data['priority'], 'project_sid' => empty($data['project_sid']) ? null : (int) $data['project_sid'], 'todo_status_sid' => (int) $data['todo_status_sid'], 'text' => $data['text'], 'date_updated' => dateSql())); } } redirect('/'); } $filter = isset($_GET['filter']) ? $_GET['filter'] : array(); $this->load->view('layout/layout', array('content' => $this->load->view('todo/index', array('todos' => $this->Todo_model->fetch_filtered($filter), 'projects' => $this->Project_model->get_list(), 'todo_statuses' => $this->Todo_status_model->get_list(), 'filter' => $filter), true))); }
<?php if (isset($todo)) { $todo_sid = $todo['todo_sid']; $priority = $todo['priority']; $project_sid = $todo['project_sid']; $todo_status_sid = $todo['todo_status_sid']; $text = $todo['text']; $submitText = "Save"; $submitButtonClass = "primary"; $dateCreated = dateSql(strtotime($todo['date_created'])); $status = "status-" . $todo_statuses[$todo_status_sid]; } else { $todo_sid = null; $priority = null; $project_sid = null; $todo_status_sid = null; $text = null; $submitText = "Add"; $submitButtonClass = "success"; $dateCreated = null; $status = ""; } ?> <div class="todo <?php echo $status; ?> "> <form action="<?php echo $_SERVER['REQUEST_URI'];