public function render(array $appData, $templateName, \Core\Application $app, \Core\Database $db, \DBMappers\RoomItem $roomMapper, \Core\Registry $registry) { $rooms = $roomMapper->getAll($db); $nav_items = array(); foreach ($rooms as $room) { $nav_items[] = array('caption' => $room->getRoomName(), 'link' => $registry->get(REG_SITE_ROOT) . BROWSE_URL . "/room/" . $room->getId(), 'selected' => false); } $nav_items[] = array('caption' => 'Settings', 'link' => $registry->get(REG_SITE_ROOT) . 'employee/edit/' . $app->getEmpId(), 'selected' => false); $nav_items[] = array('caption' => 'Logout', 'link' => $registry->get(REG_SITE_ROOT) . LOGIN_URL, 'selected' => false); return (new \Utility\Template())->parse($templateName, array('nav_items' => $nav_items)); }
public function act($urlParameters, \Core\Http $http, \Core\Application $app, \Core\Database $db, \DBMappers\EmpItem $empItemMapper) { if ($app->isAuthorized()) { $empItem = $empItemMapper->getById($app->getEmpId(), $db); if ($empItem->isPasswordEqual(null)) { $app->setStateRedirect(EMPLOYEE_URL . '/edit/' . $empItem->getId()); } else { $app->setStateRedirect(BROWSE_URL); } } else { $app->setStateRedirect(LOGIN_URL); } }
private function saveExistedEmployee($urlParameters, \Core\Http $http, \Core\Application $app, \Core\Database $db, \DBMappers\EmpItem $empMapper) { $isOwnAccount = isset($urlParameters[0]) && $urlParameters[0] == $app->getEmpId(); $empItem = $empMapper->getById($urlParameters[0], $db); $empItem->fromArray(array('login' => $http->post()['login'], 'email' => $http->post()['email'], 'hour_mode' => $http->post()['hour_mode'], 'first_day' => $http->post()['first_day'], 'name' => $http->post()['name'])); // check for is_admin field if ($app->isAdmin()) { $empItem->fromArray(array('is_admin' => $http->post()['is_admin_proxy'])); } $emp_err = array(); $emp_err['login'] = $this->validateLogin($empItem->getLogin()); $emp_err['name'] = $this->validateName($empItem->getName()); $emp_err['email'] = $this->validateEmail($empItem->getEmail()); // пароль редактируется только если для своего аккаунта, в противном случае мы только можем сбросить пароль if ($isOwnAccount) { $emp_err['password'] = $this->validatePassword($empItem, $http->post()['password']); // check for new password setting // 1) check if we must setup new password if ($empItem->isPasswordEqual(null) && empty($http->post()['new_password']) && empty($http->post()['new_password_retype'])) { $emp_err['password'] = '******'; } else { if (!(empty($http->post()['new_password']) && empty($http->post()['new_password_retype']))) { if ($http->post()['new_password'] != $http->post()['new_password_retype']) { $emp_err['password'] = '******'; } else { $empItem->setPwd($http->post()['new_password']); $emp_err['password'] = ''; } } } } else { // we may drop password if ($http->post()['is_admin_proxy'] == 1) { $empItem->dropPwd(); $emp_err['password'] = ''; } } // success or reenter form if ($this->isEmptyValues($emp_err)) { $empMapper->save($empItem, $db); $app->setMessage('Employee ' . $empItem->getName() . ' modified successfully.'); if ($isOwnAccount) { $app->setStateRedirect(BROWSE_URL); } else { $app->setStateRedirect(EMPLOYEE_LIST_URL); } //error_log("\nredirect to:" . print_r(BROWSE_URL, true), 3, 'my_errors.txt'); } else { $app->setStateEmployee(array('emp_edit' => array('item' => $empItem, 'edit_own' => true, 'add_new' => false), 'emp_err' => $emp_err)); } }
public function act($urlParameters, \Core\Http $http, \Core\Application $app, \Core\Database $db, \DBMappers\AppointmentItem $appMapper, \DBMappers\EmpItem $empItemMapper) { if ($http->getRequestMethod() == 'GET') { $app->setStateBook(array()); } else { if ($http->getRequestMethod() == 'POST') { $bookErrors = array(); $bookValues = array_merge(array(), $http->post()); $bookingOrder = new \Application\BookingOrder(); $this->validateForm($bookValues, $bookErrors, $bookingOrder, $app->getHourMode()); //error_log("\nbookingData:" . print_r($bookingOrder, true), 3, 'my_errors.txt'); if ($this->isEmptyValues($bookErrors)) { $appMatcher = new \Application\AppointmentMatcher(); $chain = $appMatcher->makeChain($bookingOrder, $app->getEmpId(), $app->getCurrentRoom()); $crossings = $appMatcher->getCrossingAppointments($chain, $appMapper, $db); // test for crossing appointments if (count($crossings) > 0) { $message = \Utility\HtmlHelper::MakeCrossingMessage($crossings, $empItemMapper, $db); $app->setStateBook(array('book_values' => $bookValues, 'book_errors' => $bookErrors, 'error_message' => $message, 'book_crossings' => $crossings)); } else { $max_chain_id = $appMapper->getMaxChainId($db); if ($max_chain_id === false) { $max_chain_id = 1; } else { ++$max_chain_id; } $chain->setChainId($max_chain_id); foreach ($chain as $appointment) { $appMapper->save($appointment, $db); } $chain->rewind(); $message = \Utility\HtmlHelper::MakeSuccessAppCreationMessage($chain->current(), $app->getHourMode()); $app->setMessage($message); $app->setStateRedirect(BROWSE_URL); } } else { $app->setStateBook(array('book_values' => $bookValues, 'book_errors' => $bookErrors, 'error_message' => isset($bookErrors['common']) ? $bookErrors['common'] : null)); } } } }