public function createDepartment() { if ($this->session->admin) { $post = $this->input->post(); $nameExists = Department_Model::doesDeptNameExist($post['name']); $colorExists = Department_Model::doesDeptColorExist($post['color']); if ($nameExists) { $error = array('status' => 'error', 'msg' => 'A department with that name already exists. Please choose a different name.'); echo json_encode($error); exit; } elseif ($colorExists) { $error = array('status' => 'error', 'msg' => 'A department with that color already exists. Please pick another color.'); echo json_encode($error); exit; } else { Department_Model::createNewDepartment($post['name'], $post['color']); $msg = array('status' => 'success', 'msg' => 'You have successfully created the ' . $post['name'] . ' department.'); echo json_encode($msg); } } else { $this->session->set_flashdata('error', 'You do not have permission to add a department'); redirect('home'); } }