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; }
public function unitTest($phpunit) { if (!class_exists('CashierTests', false)) { include dirname(__FILE__) . '/CashierTests.php'; } $tester = new CashierTests($this->connection, $this->config, $this->logger); $tester->testAddCashier($this, $phpunit); $map = new StoreEmployeeMapModel($this->connection); $map->empNo(35); $map->storeID(1); // map $this->saveStoreMapping($this->connection, 35, array(1)); $phpunit->assertEquals(true, $map->load()); // unmap $this->saveStoreMapping($this->connection, 35, array()); $phpunit->assertEquals(false, $map->load()); }
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *********************************************************************************/ include dirname(__FILE__) . '/../../config.php'; require_once dirname(__FILE__) . '/generic.mysql.php'; /** Sync the whole table using mysqldump. Then look up employees numbers that are valid for this store and construct a DELETE query to remove all others. Run the DELETE query at each lane. */ $config = FannieConfig::factory(); $dbc = FannieDB::get($config->get('OP_DB')); $map = new StoreEmployeeMapModel($dbc); $map->storeID($config->get('STORE_ID')); $query = ' DELETE FROM employees WHERE emp_no NOT IN ('; $args = array(); foreach ($map->find() as $obj) { $query .= '?,'; $args[] = $obj->empNo(); } $query = substr($query, 0, strlen($query) - 1) . ')'; foreach ($FANNIE_LANES as $lane) { $sql = new SQLManager($lane['host'], $lane['type'], $lane['op'], $lane['user'], $lane['pw']); if ($sql->connections[$lane['op']] !== false) { $prep = $sql->prepare($query); $sql->execute($prep, $args); }