private function setBrowseTime(\Core\Application $app, \Core\Http $http) { $cp = $app->getCurrentPeriod(); $cp_year = $cp->format('Y'); $cp_month = $cp->format('n'); if (isset($http->get()['year'])) { $cp_year = $http->get()['year']; } if (isset($http->get()['month'])) { $cp_month = $http->get()['month']; } $app->setCurrentPeriod((new \DateTime())->setDate($cp_year, $cp_month, 1)); }
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)); } } } }
public function act($urlParameters, \Core\Http $http, \Core\Application $app, \Core\Database $db, \DBMappers\EmpItem $empMapper) { $app->reopenSession(); if (isset($http->post()['login'])) { $loginValue = $http->post()['login']; //error_log("\nPOST:" . print_r($http->post(), true), 3, 'my_errors.txt'); $empItem = $empMapper->getByLogin($loginValue, $db); if (!$empItem) { $this->setWrongLoginState($app, $loginValue); return; } if (!$empItem->isPasswordEqual($http->post()['password'])) { $this->setWrongLoginState($app, $loginValue); return; } $app->setAuthorized($empItem->getId(), $empItem->isAdmin(), $empItem->getFirstDay(), $empItem->getHourMode()); $app->setStateRedirect(BROWSE_URL); } else { $app->setStateLogin(array()); } }
public function delete($urlParameters, \Core\Http $http, \Core\Application $app, \Core\Database $db, \DBMappers\AppointmentItem $appMapper) { $appointment = $appMapper->getById($urlParameters[0], $db); $chain = $appMapper->getChain($appointment->getChain(), $db); $chain->applyFilter(new \DateTime()); $deleted_count = 0; if ($http->post()['apply_chain_proxy'] == 1) { foreach ($chain as $member) { $appMapper->deleteById($member->getId(), $db); ++$deleted_count; } } else { if ($chain->isMeetFilter($appointment)) { $appMapper->deleteById($appointment->getId(), $db); ++$deleted_count; } } if ($deleted_count > 0) { $message = "{$deleted_count} events were deleted successfully."; } else { $message = 'No events were deleted.'; } //error_log("\ndelete:" . print_r($urlParameters, true), 3, 'my_errors.txt'); $app->setMessage($message); $app->setStateRedirect(DETAILS_RETURN_URL); }
public function remove($urlParameters, \Core\Http $http, \Core\Application $app, \Core\Database $db, \DBMappers\EmpItem $empMapper) { if (!$app->isAdmin() || $http->getRequestMethod() != 'POST') { $app->setMessage('You cannot manage employees.'); $app->setStateRedirect(BROWSE_URL); } else { if (isset($urlParameters[0])) { $empItem = $empMapper->getById($urlParameters[0], $db); $empMapper->remove($empItem->getId(), $db); $app->setMessage('Employee ' . $empItem->getName() . ' removed successfully.'); $app->setStateRedirect(EMPLOYEE_LIST_URL); } else { $app->setMessage('Employee id not set'); $app->setStateRedirect(EMPLOYEE_LIST_URL); } } }