function loadEmployees($cid, $id) { // employees $employees = array(); $request = "SELECT * FROM employee WHERE did = {$id}"; $result = mysql_query($request); $count = mysql_num_rows($result); while ($row = mysql_fetch_object($result)) { $maximumSalary = getMaximumSalaryForEmployee($row->did, $row->manager); $employee = new Employee(); if ($row->salary > $maximumSalary) { $employee->setInconsistent(true); $employee->setMessage("Salary > {$maximumSalary}"); } $employee->setId($row->id); $employee->setName($row->name); $employee->setManager($row->manager); $employees[] = $employee; } return $employees; }
function saveEmployee($jsonObject) { $id = $jsonObject->id; $name = $jsonObject->newName; $address = $jsonObject->newAddress; $salary = $jsonObject->newSalary; $minimumSalary = getMinimumSalaryForEmployee($id); $maximumSalary = getMaximumSalaryForEmployee($id); if ($minimumSalary > $salary || $maximumSalary < $salary) { $status = new Errormessage(); $status->addFailure("salary", "Enter a valid (" . $minimumSalary . " to " . $maximumSalary . ") salary, please."); return $status; } $request = "UPDATE employee SET name = '" . $name . "', address = '" . $address . "', salary = '" . $salary . "' WHERE id = " . $id; mysql_query($request); $error = mysql_error(); if ($error == '' || $error == null) { return loadEmployee($jsonObject); } else { $status = new Errormessage(); $status->addFailure("nameaddress", "Duplicate entry for name and address.<br>Enter a unique name and address combination,<br> please."); return $status; } }
function create($jsonObject) { $name = $jsonObject->name; $address = $jsonObject->address; $salary = $jsonObject->salary; $parent = $jsonObject->parent; $manager = 0; $minimumSalary = getMinimumSalaryForEmployee($parent, $manager); $maximumSalary = getMaximumSalaryForEmployee($parent, $manager); if ($minimumSalary > $salary || $maximumSalary < $salary) { $status = new Errormessage(); $status->addFailure("salary", "Enter a valid (" . $minimumSalary . " to " . $maximumSalary . ") salary, please."); return $status; } $request = "INSERT employee (name, address, salary, manager, cid, did) VALUES ('" . $name . "', '" . $address . "', " . $salary . ", " . $manager . ", 1, " . $parent . ")"; mysql_query($request); $error = mysql_error(); if ($error == '' || $error == null) { $request = "SELECT * FROM employee WHERE name = '" . $name . "'"; $result = mysql_query($request); $row = mysql_fetch_object($result); return loadEmployee($row->id); } else { $status = new Errormessage(); $status->addFailure("nameaddress", "Duplicate entry for name and address.<br>Enter a unique name and address combination,<br> please."); return $status; } }