public static function getHMS() { $rh = getallheaders(); if (isset(HMSFactory::$hms)) { return HMSFactory::$hms; } else { if (isset($_REQUEST['ajax']) || !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' || isset($_REQUEST['callback']) || array_key_exists('Accept', $rh) && stripos($rh['Accept'], 'application/json') !== FALSE) { PHPWS_Core::initModClass('hms', 'AjaxHMS.php'); HMSFactory::$hms = new AjaxHMS(); } else { if (UserStatus::isAdmin()) { PHPWS_Core::initModClass('hms', 'AdminHMS.php'); HMSFactory::$hms = new AdminHMS(); } else { if (UserStatus::isUser()) { PHPWS_Core::initModClass('hms', 'UserHMS.php'); HMSFactory::$hms = new UserHMS(); } else { // Guest PHPWS_Core::initModClass('hms', 'GuestHMS.php'); HMSFactory::$hms = new GuestHMS(); } } } } return HMSFactory::$hms; }
public function execute(CommandContext $context) { if (!UserStatus::isUser()) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to request a roommate.'); } $term = $context->get('term'); $requestee = $context->get('username'); $requestor = UserStatus::getUsername(); if (empty($term)) { throw new InvalidArgumentException('Term was not specified.'); } $err = CommandFactory::getCommand('ShowRequestRoommate'); $err->setTerm($term); if (empty($requestee)) { NQ::simple('hms', hms\NotificationView::WARNING, 'You did not enter a username.'); $err->redirect(); } if (!PHPWS_Text::isValidInput($requestee)) { NQ::simple('hms', hms\NotificationView::WARNING, 'You entered an invalid username. Please use letters and numbers only.'); $err->redirect(); } // Attempt to Create Roommate Request PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $request = new HMS_Roommate(); try { $request->request($requestor, $requestee, $term); } catch (RoommateCompatibilityException $rre) { NQ::simple('hms', hms\NotificationView::WARNING, $rre->getMessage()); $err->redirect(); } $request->save(); $endTime = $request->calc_req_expiration_date(); $expirationMsg = " expires on " . date('m/d/Y h:i:s a', $endTime); HMS_Activity_Log::log_activity($requestee, ACTIVITY_REQUESTED_AS_ROOMMATE, $requestor, "{$requestor} requested {$requestee}" . $expirationMsg); HMS_Activity_Log::log_activity($requestor, ACTIVITY_REQUESTED_AS_ROOMMATE, $requestee, "{$requestor} requested {$requestee}" . $expirationMsg); // Email both parties PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_request_emails($request); // Notify PHPWS_Core::initModClass('hms', 'StudentFactory.php'); $student = StudentFactory::getStudentByUsername($requestee, $term); $name = $student->getName(); $fname = $student->getFirstName(); NQ::simple('hms', hms\NotificationView::SUCCESS, "You have requested {$name} to be your roommate. {$fname} has been emailed, and will need to log into HMS and approve your roommate request."); $cmd = CommandFactory::getCommand('ShowStudentMenu'); $cmd->redirect(); }
public function execute(CommandContext $context) { if (!UserStatus::isUser()) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to request a roommate.'); } $term = $context->get('term'); if (is_null($term)) { throw new InvalidArgumentException('Must specify a term.'); } PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $username = UserStatus::getUsername(); $err = CommandFactory::getCommand('ShowStudentMenu'); // Make sure the user doesn't already have a request pending $result = HMS_Roommate::has_roommate_request($username, $term); if ($result === TRUE) { NQ::simple('hms', hms\NotificationView::WARNING, 'You have a pending roommate request. You can not request another roommate request until your current request is either denied or expires.'); $err->redirect(); } // Make sure the user doesn't already have a confirmed roommate $result = HMS_Roommate::has_confirmed_roommate($username, $term); if ($result === TRUE) { NQ::simple('hms', hms\NotificationView::WARNING, 'You already have a confirmed roommate.'); $err->redirect(); } $form = new PHPWS_Form(); $cmd = CommandFactory::getCommand('RequestRoommate'); $cmd->setTerm($term); $cmd->initForm($form); $form->addText('username'); $form->addCssClass('username', 'form-control'); $form->setExtra('username', 'autofocus'); $form->addSubmit('submit', 'Request Roommate'); $form->addButton('cancel', 'Cancel'); $form->setExtra('cancel', 'onClick="document.location=\'index.php\'"'); $tpl = $form->getTemplate(); $context->setContent(PHPWS_Template::process($tpl, 'hms', 'student/select_roommate.tpl')); }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); PHPWS_Core::initModClass('hms', 'RlcApplicationReView.php'); $application = new HMS_RLC_Application($context->get('appId')); if (is_null($application->username)) { NQ::simple('hms', hms\NotificationView::ERROR, 'There is no RLC application available with that id.'); $context->goBack(); } // This is used both on the admin side and on the student side, so the permission check is a bit more complex if (UserStatus::isAdmin() && !Current_User::allow('view_rlc_applications') || UserStatus::isUser() && $application->getUsername() != UserStatus::getUsername()) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to view this RLC application.'); } try { $student = StudentFactory::getStudentByUsername($application->username, $application->term); } catch (StudentNotFoundException $e) { NQ::simple('hms', hms\NotificationView::ERROR, 'Unknown student.'); $context->goBack(); } $view = new RlcApplicationReView($student, $application); $context->setContent($view->show()); }