function preprocess() { global $FANNIE_OP_DB; $emp_no = FormLib::get_form_value('emp_no', 0); if (FormLib::get_form_value('fname') !== '') { $fname = FormLib::get_form_value('fname'); $lname = FormLib::get_form_value('lname'); $passwd = FormLib::get_form_value('passwd'); $fes = FormLib::get_form_value('fes'); $active = FormLib::get_form_value('active') !== '' ? 1 : 0; $dob = FormLib::get_form_value('birthdate'); $dbc = FannieDB::get($FANNIE_OP_DB); $employee = new EmployeesModel($dbc); $employee->emp_no($emp_no); $employee->FirstName($fname); $employee->LastName($lname); $employee->CashierPassword($passwd); $employee->AdminPassword($passwd); $employee->frontendsecurity($fes); $employee->backendsecurity($fes); $employee->EmpActive($active); $employee->birthdate($dob); $saved = $employee->save(); $map = new StoreEmployeeMapModel($dbc); $map->empNo($emp_no); $stores = FormLib::get('store', array()); foreach ($stores as $s) { $map->storeID($s); $map->save(); } $map->reset(); $map->empNo($emp_no); foreach ($map->find() as $obj) { if (!in_array($obj->storeID(), $stores)) { $obj->delete(); } } if ($saved) { $message = "Cashier Updated. <a href=ViewCashiersPage.php>Back to List of Cashiers</a>"; $this->add_onload_command("showBootstrapAlert('#alert-area', 'success', '{$message}');\n"); } else { $this->add_onload_command("showBootstrapAlert('#alert-area', 'danger', 'Error saving cashier');\n"); } } return true; }
private function saveStoreMapping($dbc, $emp_no, $stores) { $map = new StoreEmployeeMapModel($dbc); $map->empNo($emp_no); foreach ($stores as $s) { $map->storeID($s); $map->save(); } $map->reset(); $map->empNo($emp_no); foreach ($map->find() as $obj) { if (!in_array($obj->storeID(), $stores)) { $obj->delete(); } } }