function execCreateDep($userID, $parentID, $departmentName) { if (!isValidID($parentID)) { return "Invalid parent ID!"; } if (!isValidDepartmentName($departmentName)) { return "Invalid department name!"; } $departDAO = new DepartmentDAO(); $parent = $departDAO->getDepartmentByID($parentID); if ($parent === null) { return "Could not find this parent department!"; } $userDAO = new UserDAO(); $user = $userDAO->getUserByID($userID); $role = $user->getRole(); if ($role->getRoleID() == "4" || $role->getRoleID() == "3") { return "You have no right to do this!"; } $depart = new Department($parentID, $departmentName); $departDAO->insertDepartment($depart); return true; }
function addDepartment($adminID, $parentDepartmentID, $departmentName) { $userDAO = new UserDAO(); $admin = $userDAO->getUserByID($adminID); if ($admin->getRole()->getRoleID !== 1 || $admin->getRole()->getRoleID !== 2) { return "You do not have the right to add department!"; } $departmentDAO = new DepartmentDAO(); $parentDepartment = $departmentDAO->getDepartmentByID($parentDepartmentID); if ($parentDepartment === null) { return "Invalid parent department!"; } $department = new Department($parentDepartment, $departmentName); $departmentDAO->insertDepartment($department); }