Example #1
0
 public function saveDepartmentModification()
 {
     if ($this->session->admin) {
         $post = $this->input->post();
         $nameExists = Department_Model::checkDepartmentName($post['id'], $post['name']);
         $colorExists = Department_Model::checkDepartmentColor($post['id'], $post['color']);
         if ($nameExists) {
             $error = array('status' => 'error', 'msg' => 'A department with that name already exists. Please choose a different name or keep the current name.');
             echo json_encode($error);
             exit;
         } elseif ($colorExists) {
             $error = array('status' => 'error', 'msg' => 'A department with that color already exists. Please pick another color, or keep your current one.');
             echo json_encode($error);
             exit;
         } else {
             Department_model::updateDepartment($post);
             $msg = array('status' => 'success', 'msg' => 'You have successfully updated the ' . $post['name'] . ' department.');
             echo json_encode($msg);
         }
     } else {
         $this->session->set_flashdata('error', 'You do not have permission to modify a department');
         redirect('home');
     }
 }