public function execute(CommandContext $context) { if (!Current_User::allow('hms', 'approve_rlc_applications')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to approve/deny RLC applications.'); } PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); // Remove assignment $assignment = HMS_RLC_Assignment::getAssignmentById($context->get('assignId')); $rlcName = $assignment->getRlcName(); $rlcApp = $assignment->getApplication(); if (!is_null($assignment)) { $assignment->delete(); } else { NQ::simple('hms', hms\NotificationView::ERROR, 'Could not find an RLC assignment with that id.'); } HMS_Activity_Log::log_activity($rlcApp->getUsername(), ACTIVITY_RLC_UNASSIGN, Current_User::getUsername(), "Removed from {$rlcName}"); NQ::simple('hms', hms\NotificationView::SUCCESS, 'Removed from RLC'); // Deny application $rlcApp->denied = 1; $rlcApp->save(); NQ::simple('hms', hms\NotificationView::SUCCESS, 'RLC Application denied'); HMS_Activity_Log::log_activity($rlcApp->getUsername(), ACTIVITY_DENIED_RLC_APPLICATION, Current_User::getUsername(), 'RLC Application Denied'); $context->goBack(); }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php'); $term = $context->get('term'); // Application must exist $app = HMS_RLC_Application::getApplicationByUsername(UserStatus::getUsername(), $term); if (is_null($app)) { NQ::simple('hms', hms\NotificationView::ERROR, 'No RLC application exists.'); $context->goBack(); } else { if (!HMS_RLC_Assignment::checkForAssignment(UserStatus::getUsername(), $term)) { // Delete the app $app->delete(); // Log it PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_RLC_APPLICATION_DELETED, UserStatus::getUsername()); // Show a notification and go back NQ::simple('hms', hms\NotificationView::SUCCESS, 'RLC application deleted.'); $context->goBack(); } else { NQ::simple('hms', hms\NotificationView::WARNING, 'You have already been assigned to an RLC.'); $context->goBack(); } } }
public function execute(CommandContext $context) { if (!Current_User::allow('hms', 'approve_rlc_applications')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to approve RLC applications.'); } PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); # Foreach rlc assignment made # $app_id is the 'id' column in the 'learning_community_applications' table, tells which student we're assigning # $rlc_id is the 'id' column in the 'learning_communitites' table, and refers to the RLC selected for the student foreach ($_REQUEST['final_rlc'] as $app_id => $rlc_id) { if ($rlc_id <= 0) { continue; } $app = HMS_RLC_Application::getApplicationById($app_id); $student = StudentFactory::getStudentByUsername($app->username, $app->term); # Insert a new assignment in the 'learning_community_assignment' table $assign = new HMS_RLC_Assignment(); $assign->rlc_id = $rlc_id; $assign->gender = $student->getGender(); $assign->assigned_by = UserStatus::getUsername(); $assign->application_id = $app->id; $assign->state = 'new'; $assign->save(); # Log the assignment PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); HMS_Activity_Log::log_activity($app->username, ACTIVITY_ASSIGN_TO_RLC, UserStatus::getUsername(), "New Assignment"); } // Show a success message NQ::simple('hms', hms\NotificationView::SUCCESS, 'Successfully assigned RLC applicant(s).'); $context->goBack(); }
public function execute(CommandContext $context) { $id = $context->get('roommateId'); if (is_null($id)) { throw new InvalidArgumentException('Must set roommateId'); } PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $roommate = new HMS_Roommate($id); if ($roommate->id == 0) { throw new InvalidArgumentException('Invalid roommateId ' . $id); } $username = UserStatus::getUsername(); if ($username != $roommate->requestor) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException("{$username} tried to break roommate pairing {$roommate->id}"); } $roommate->delete(); $other = StudentFactory::getStudentByUsername($roommate->get_other_guy($username), $roommate->term); HMS_Activity_Log::log_activity($other->getUsername(), ACTIVITY_STUDENT_CANCELLED_ROOMMATE_REQUEST, $username, "{$username} cancelled roommate request"); HMS_Activity_Log::log_activity($username, ACTIVITY_STUDENT_CANCELLED_ROOMMATE_REQUEST, $other->getUsername(), "{$username} cancelled roommate request"); // Email both parties PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_cancel_emails($roommate); $name = $other->getFullName(); NQ::Simple('hms', hms\NotificationView::SUCCESS, "You have cancelled your roommate request for {$name}."); $cmd = CommandFactory::getCommand('ShowStudentMenu'); $cmd->redirect(); }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'HMS_Lottery.php'); $requestId = $context->get('requestId'); $errorCmd = CommandFactory::getCommand('LotteryShowDenyRoommateRequest'); $errorCmd->setRequestId($requestId); # Confirm the captcha PHPWS_Core::initCoreClass('Captcha.php'); $captcha = Captcha::verify(TRUE); if ($captcha === FALSE) { NQ::simple('hms', hms\NotificationView::ERROR, 'The words you entered were incorrect. Please try again.'); $errorCmd->redirect(); } # Get the roommate request $request = HMS_Lottery::get_lottery_roommate_invite_by_id($context->get('requestId')); # Make sure that the logged in user is the same as the confirming the request if (UserStatus::getUsername() != $request['asu_username']) { NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid roommate request. You can not confirm that roommate request.'); $errorCmd->redirect(); } # Deny the roommate requst try { HMS_Lottery::denyRoommateRequest($requestId); } catch (Exception $e) { NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error denying the roommate request. Please contact University Housing.'); $errorCmd->redirect(); } # Log that it happened PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_LOTTERY_ROOMMATE_DENIED, UserStatus::getUsername(), 'Captcha words: ' . $captcha); # Success NQ::simple('hms', hms\NotificationView::SUCCESS, 'The roommate request was successfully declined.'); $successCmd = CommandFactory::getCommand('ShowStudentMenu'); $successCmd->redirect(); }
public function execute(CommandContext $context) { if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'roommate_maintenance')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to create/edit roommate groups.'); } PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $id = $context->get('id'); if (is_null($id)) { throw new InvalidArgumentException('Missing roommate group id.'); } $viewCmd = CommandFactory::getCommand('EditRoommateGroupsView'); try { $roommate = new HMS_Roommate($id); $roommate->delete(); } catch (Exception $e) { NQ::simple('hms', hms\NotificationView::SUCCESS, 'Error deleting roommate group: ' . $e->getMessage()); $viewCmd->redirect(); } // Log the success $notes = "{$roommate->getRequestor()} requested {$roommate->getRequestee()}"; HMS_Activity_Log::log_activity($roommate->getRequestor(), ACTIVITY_ADMIN_REMOVED_ROOMMATE, UserStatus::getUsername(), $notes); HMS_Activity_Log::log_activity($roommate->getRequestee(), ACTIVITY_ADMIN_REMOVED_ROOMMATE, UserStatus::getUsername(), $notes); NQ::simple('hms', hms\NotificationView::SUCCESS, 'Roommate group successfully deleted.'); $viewCmd->redirect(); }
/** * (non-PHPdoc) * @see Command::execute() */ public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php'); $term = $context->get('term'); if (!isset($term)) { throw new InvalidArgumentException('Missing term.'); } $user = UserStatus::getUsername(); $student = StudentFactory::getStudentByUsername($user, $term); // Load the student's application. Should be a lottery application. $application = HousingApplicationFactory::getAppByStudent($student, $term); // If there isn't a valid application in the DB, then we have a problem. if (!isset($application) || !$application instanceof LotteryApplication) { throw new InvalidArgumentException('Null application object.'); } // Check to make sure the date isn't already set $time = $application->getWaitingListDate(); if (isset($time)) { NQ::simple('hms', hms\NotificationView::ERROR, 'You have already applied for the waiting list.'); $cmd = CommandFactory::getCommand('ShowStudentMenu'); $cmd->redirect(); } // Set the date $application->setWaitingListDate(time()); // Save the application again $application->save(); // Log it to the activity log HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_REAPP_WAITINGLIST_APPLY, UserStatus::getUsername()); // Success command $cmd = CommandFactory::getCommand('ShowStudentMenu'); $cmd->redirect(); }
public function execute(CommandContext $context) { $id = $context->get('roommateId'); if (is_null($id)) { throw new InvalidArgumentException('Must set roommateId'); } PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $roommate = new HMS_Roommate($id); if ($roommate->id == 0) { throw new InvalidArgumentException('Invalid roommateId ' . $id); } if (UserStatus::getUsername() != $roommate->requestee) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException("{$username} tried to reject roommate pairing {$roommate->id}"); } $requestor = StudentFactory::getStudentByUsername($roommate->requestor, $roommate->term); $name = $requestor->getFullName(); $username = $requestor->getUsername(); $roommate->delete(); HMS_Activity_Log::log_activity($roommate->requestor, ACTIVITY_REJECTED_AS_ROOMMATE, $roommate->requestee, "{$roommate->requestee} rejected {$roommate->requestor}'s request"); HMS_Activity_Log::log_activity($roommate->requestee, ACTIVITY_REJECTED_AS_ROOMMATE, $roommate->requestor, "{$roommate->requestee} rejected {$roommate->requestor}'s request"); // Email both parties PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_reject_emails($roommate); NQ::Simple('hms', hms\NotificationView::SUCCESS, "<b>You rejected the roommate request from {$name}.</b> If this was an error, you may re-request using their username, <b>{$username}</b>."); $cmd = CommandFactory::getCommand('ShowStudentMenu'); $cmd->redirect(); }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'RlcMembershipFactory.php'); PHPWS_Core::initModClass('hms', 'RlcAssignmentSelfAssignedState.php'); $requestId = $context->get('requestId'); $mealPlan = $context->get('mealPlan'); $errorCmd = CommandFactory::getCommand('LotteryShowConfirmRoommateRequest'); $errorCmd->setRequestId($requestId); $errorCmd->setMealPlan($mealPlan); // Confirm the captcha PHPWS_Core::initCoreClass('Captcha.php'); $captcha = Captcha::verify(TRUE); if ($captcha === FALSE) { NQ::simple('hms', hms\NotificationView::ERROR, 'The words you entered were incorrect. Please try again.'); $errorCmd->redirect(); } // Check for a meal plan if (!isset($mealPlan) || $mealPlan == '') { NQ::simple('hms', hms\NotificationView::ERROR, 'Please choose a meal plan.'); $errorCmd->redirect(); } $term = PHPWS_Settings::get('hms', 'lottery_term'); $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term); // Update the meal plan field on the application $app = HousingApplication::getApplicationByUser(UserStatus::getUsername(), $term); $app->setMealPlan($mealPlan); try { $app->save(); } catch (Exception $e) { PHPWS_Error::log('hms', $e->getMessage()); NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, there was an error confirming your roommate invitation. Please contact University Housing.'); $errorCmd->redirect(); } // Try to actually make the assignment PHPWS_Core::initModClass('hms', 'HMS_Lottery.php'); try { HMS_Lottery::confirm_roommate_request(UserStatus::getUsername(), $requestId, $mealPlan); } catch (Exception $e) { PHPWS_Error::log('hms', $e->getMessage()); NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, there was an error confirming your roommate invitation. Please contact University Housing.'); $errorCmd->redirect(); } # Log the fact that the roommate was accepted and successfully assigned HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_LOTTERY_CONFIRMED_ROOMMATE, UserStatus::getUsername(), "Captcha: \"{$captcha}\""); // Check for an RLC membership and update status if necessary // If this student was an RLC self-select, update the RLC memberhsip state $rlcAssignment = RlcMembershipFactory::getMembership($student, $term); if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') { $rlcAssignment->changeState(new RlcAssignmentSelfAssignedState($rlcAssignment)); } $invite = HMS_Lottery::get_lottery_roommate_invite_by_id($requestId); $successCmd = CommandFactory::getCommand('LotteryShowConfirmedRoommateThanks'); $successCmd->setRequestId($requestId); $successCmd->redirect(); }
public function execute(CommandContext $context) { if (!Current_User::allow('hms', 'cancel_housing_application')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to cancel housing applications.'); } // Check for a housing application id $applicationId = $context->get('applicationId'); if (!isset($applicationId) || is_null($applicationId)) { throw new InvalidArgumentException('Missing housing application id.'); } // Check for a cancellation reason $cancelReason = $context->get('cancel_reason'); if (!isset($cancelReason) || is_null($cancelReason)) { throw new InvalidArgumentException('Missing cancellation reason.'); } // Load the housing application PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php'); $application = HousingApplicationFactory::getApplicationById($applicationId); // Load the student $student = $application->getStudent(); $username = $student->getUsername(); $term = $application->getTerm(); // Load the cancellation reasons $reasons = HousingApplication::getCancellationReasons(); // Check for an assignment and remove it // Decide which term to use - If this application is in a past fall term, then use the current term if ($term < Term::getCurrentTerm() && Term::getTermSem($term) == TERM_FALL) { $assignmentTerm = Term::getCurrentTerm(); } else { $assignmentTerm = $term; } PHPWS_Core::initModClass('hms', 'HMS_Assignment.php'); $assignment = HMS_Assignment::getAssignmentByBannerId($student->getBannerId(), $assignmentTerm); if (isset($assignment)) { // TODO: Don't hard code cancellation refund percentage HMS_Assignment::unassignStudent($student, $assignmentTerm, 'Application cancellation: ' . $reasons[$cancelReason], UNASSIGN_CANCEL, 100); } PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php'); $rlcAssignment = HMS_RLC_Assignment::getAssignmentByUsername($username, $term); if (!is_null($rlcAssignment)) { $rlcAssignment->delete(); } PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); $rlcApplication = HMS_RLC_Application::getApplicationByUsername($username, $term); if (!is_null($rlcApplication)) { $rlcApplication->denied = 1; $rlcApplication->save(); HMS_Activity_Log::log_activity($username, ACTIVITY_DENIED_RLC_APPLICATION, \Current_User::getUsername(), Term::toString($term) . ' Denied RLC Application due to Contract Cancellation'); } // Cancel the application $application->cancel($cancelReason); $application->save(); echo 'success'; exit; }
public function onEnter() { PHPWS_Core::initModClass('hms', 'HMS_Email.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); $application = $this->rlcAssignment->getApplication(); $term = $application->getTerm(); $username = $application->getUsername(); $community = $this->rlcAssignment->getRlc(); $student = StudentFactory::getStudentByUsername($username, $term); HMS_Email::sendRlcInviteEmail($student, $community, $term, $this->respondByTimestamp); HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_RLC_INVITE_SENT, UserStatus::getUsername()); }
public function execute(CommandContext $context) { $term = $context->get('term'); if (!isset($term)) { throw new InvalidArgumentException('Missing term!'); } PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php'); PHPWS_Core::initModClass('hms', 'RlcAssignmentConfirmedState.php'); PHPWS_Core::initModClass('hms', 'RlcAssignmentDeclinedState.php'); PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); $rlcAssignment = HMS_RLC_Assignment::getAssignmentByUsername(UserStatus::getUsername(), $term); $rlcApplication = $rlcAssignment->getApplication(); $student = StudentFactory::getStudentByUsername($rlcApplication->getUsername(), $rlcApplication->getTerm()); $acceptStatus = $context->get('acceptance'); $termsCheck = $context->get('terms_cond'); if ($acceptStatus == 'accept' && !isset($termsCheck)) { // Student accepted the invite, but didn't check the terms/conditions box $errorCmd = CommandFactory::getCommand('ShowAcceptRlcInvite'); $errorCmd->setTerm($term); NQ::simple('hms', hms\NotificationView::ERROR, 'Please check the box indicating that you agree to the learning communitiy terms and conditions.'); $errorCmd->redirect(); } else { if ($acceptStatus == 'accept' && isset($termsCheck)) { // Student accepted the invite and checked the terms/conditions box $rlcAssignment->changeState(new RlcAssignmentConfirmedState($rlcAssignment)); NQ::simple('hms', hms\NotificationView::SUCCESS, 'You have <strong>accepted</strong> your Residential Learning Community invitation.'); // Log this! HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_ACCEPT_RLC_INVITE, UserStatus::getUsername(), $rlcAssignment->getRlcName()); $successCmd = CommandFactory::getCommand('ShowStudentMenu'); $successCmd->redirect(); } else { if ($acceptStatus == 'decline') { // student declined $rlcAssignment->changeState(new RlcAssignmentDeclinedState($rlcAssignment)); NQ::simple('hms', hms\NotificationView::SUCCESS, 'You have <strong>declined</strong> your Residential Learning Community invitation.'); // Log this! HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_DECLINE_RLC_INVITE, UserStatus::getUsername(), $rlcAssignment->getRlcName()); $successCmd = CommandFactory::getCommand('ShowStudentMenu'); $successCmd->redirect(); } else { // Didn't choose $errorCmd = CommandFactory::getCommand('ShowAcceptRlcInvite'); $errorCmd->setTerm($term); NQ::simple('hms', hms\NotificationView::ERROR, 'Please choose to either accept or decline your learning community invitation.'); $errorCmd->redirect(); } } } $context->setContent('confirmed or denied'); }
public function execute(CommandContext $context) { if (!Current_User::allow('hms', 'approve_rlc_applications')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to approve/deny RLC applications.'); } PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); $app = HMS_RLC_Application::getApplicationById($context->get('applicationId')); $app->denied = 1; $app->save(); PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); HMS_Activity_Log::log_activity($app->username, 28, Current_User::getUsername(), 'Application Denied'); NQ::simple('hms', hms\NotificationView::SUCCESS, 'Application denied.'); $context->goBack(); }
public function execute(CommandContext $context) { $username = $context->get('username'); $note = $context->get('note'); if (!isset($username) || empty($username)) { throw new InvalidArgumentException('Missing username'); } if (!isset($note) || empty($note)) { throw new InvalidArgumentException('No text was provided for the note.'); } PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); HMS_Activity_Log::log_activity($username, ACTIVITY_ADD_NOTE, UserStatus::getUsername(), $note); # Redirect back to whereever the user came from $context->goBack(); }
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 (!Current_User::allow('hms', 'approve_rlc_applications')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to approve/deny RLC applications.'); } PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); $app = HMS_RLC_Application::getApplicationById($context->get('applicationId')); $app->denied = 0; $app->save(); PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); HMS_Activity_Log::log_activity($app->username, 29, UserStatus::getUsername(), "Application un-denied"); NQ::simple('hms', hms\NotificationView::SUCCESS, 'Application un-denied.'); $successCmd = CommandFactory::getCommand('ShowDeniedRlcApplicants'); $successCmd->redirect(); }
public function execute(CommandContext $context) { $id = $context->get('roommateId'); if (is_null($id)) { throw new InvalidArgumentException('Must set roommateId'); } PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $roommate = new HMS_Roommate($id); if ($roommate->id == 0) { throw new InvalidArgumentException('Invalid roommateId ' . $id); } $username = UserStatus::getUsername(); if ($username != $roommate->requestee) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException("{$username} tried to confirm roommate pairing {$roommate->id}"); } $err = CommandFactory::getCommand('ShowRoommateConfirmAccept'); $err->setRoommateId($id); PHPWS_Core::initCoreClass('Captcha.php'); $verified = Captcha::verify(TRUE); if ($verified === FALSE || is_null($verified)) { NQ::Simple('hms', hms\NotificationView::ERROR, 'Sorry, please try again.'); $err->redirect(); } try { $roommate->confirm(); } catch (RoommateCompatibilityException $rce) { NQ::simple('hms', hms\NotificationView::WARNING, $rce->getMessage()); $err->redirect(); } $roommate->save(); HMS_Activity_Log::log_activity($roommate->requestor, ACTIVITY_ACCEPTED_AS_ROOMMATE, $roommate->requestee, "{$roommate->requestee} accepted request, CAPTCHA: {$verified}"); HMS_Activity_Log::log_activity($roommate->requestee, ACTIVITY_ACCEPTED_AS_ROOMMATE, $roommate->requestor, "{$roommate->requestee} accepted request, CAPTCHA: {$verified}"); // Email both parties PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_confirm_emails($roommate); // Remove any other requests for the requestor HMS_Roommate::removeOutstandingRequests($roommate->requestor, $roommate->term); // Remove any other requests for the requestee HMS_Roommate::removeOutstandingRequests($roommate->requestee, $roommate->term); $requestor = StudentFactory::getStudentByUsername($roommate->requestor, $roommate->term); $name = $requestor->getFullName(); NQ::Simple('hms', hms\NotificationView::SUCCESS, "You and {$name} are confirmed as roommates."); $cmd = CommandFactory::getCommand('ShowStudentMenu'); $cmd->redirect(); }
public function execute(CommandContext $context) { // Get input $requestId = $context->get('requestId'); $participantId = $context->get('participantId'); // Command for showing the request, redirected to on success/error $cmd = CommandFactory::getCommand('ShowManageRoomChange'); $cmd->setRequestId($requestId); // Load the request $request = RoomChangeRequestFactory::getRequestById($requestId); // Load the participant $participant = RoomChangeParticipantFactory::getParticipantById($participantId); // Load the Student $student = StudentFactory::getStudentByBannerId($participant->getBannerId(), $request->getTerm()); // Check permissions. Must be the participant or an admin if (UserStatus::getUsername() != $student->getUsername() && !Current_User::allow('hms', 'admin_approve_room_change')) { throw new PermissionException('You do not have permission to appove this room change.'); } // Check for CAPTCHA if this is the student; admins don't need a CAPTCHA $captchaResult = Captcha::verify(true); if (UserStatus::getUsername() == $student->getUsername() && $captchaResult === false) { // Failed the captcha NQ::simple('hms', hms\NotificationView::ERROR, "You didn't type the magic words correctly. Please try again."); $cmd = CommandFactory::getCommand('ShowRoomChangeRequestApproval'); $cmd->redirect(); } // If there was a captcha, then log the activity if ($captchaResult !== false) { HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_ROOM_CHANGE_AGREED, UserStatus::getUsername(FALSE), 'Request id: ' . $requestId . ' Captcha: ' . $captchaResult); } // Transition to StudentApproved state $participant->transitionTo(new ParticipantStateStudentApproved($participant, time(), null, UserStatus::getUsername())); // If all students have approved, notify RDs if ($request->isApprovedByAllParticipants()) { HMS_Email::sendRoomChangeCurrRDNotice($request); } // If the student is logged in, redirect to the main menu, other wise go back to the room change management view if (UserStatus::getUsername() == $student->getUsername()) { NQ::simple('hms', hms\NotificationView::SUCCESS, 'You have agreed to the room change request. You will be notified by email when the reqeust is approved or denied.'); $menuCmd = CommandFactory::getCommand('ShowStudentMenu'); $menuCmd->redirect(); } else { $cmd->redirect(); } }
public function process() { // This hack is the most awful hack ever. Fix phpWebSite so that // user logins are logged separately. if (Current_User::isLogged() && !isset($_SESSION['HMS_LOGGED_THE_LOGIN'])) { $username = strtolower(Current_User::getUsername()); HMS_Activity_Log::log_activity($username, ACTIVITY_LOGIN, $username, NULL); $_SESSION['HMS_LOGGED_THE_LOGIN'] = $username; } if (!Current_User::isLogged() && $this->context->get('action') != 'ShowFrontPage') { NQ::simple('hms', hms\NotificationView::ERROR, 'You must be logged in to do that.'); $action = 'ShowFrontPage'; } else { $action = $this->context->get('action'); } $cmd = CommandFactory::getCommand($action); if (HMS_DEBUG) { $cmd->execute($this->context); } else { try { $cmd->execute($this->context); } catch (PermissionException $p) { NQ::Simple('hms', hms\NotificationView::ERROR, 'You do not have permission to perform that action. If you believe this is an error, please contact University Housing.'); $nv = new hms\NotificationView(); $nv->popNotifications(); Layout::add($nv->show()); } catch (Exception $e) { try { $message = $this->formatException($e); NQ::Simple('hms', hms\NotificationView::ERROR, 'An internal error has occurred, and the authorities have been notified. We apologize for the inconvenience.'); $this->emailError($message); $nv = new hms\NotificationView(); $nv->popNotifications(); Layout::add($nv->show()); } catch (Exception $e) { $message2 = $this->formatException($e); echo "HMS has experienced a major internal error. Attempting to email an admin and then exit."; $message = "Something terrible has happened, and the exception catch-all threw an exception.\n\nThe first exception was:\n\n{$message}\n\nThe second exception was:\n\n{$message2}"; mail(FROM_ADDRESS, 'A Major HMS Error Has Occurred', $message); exit; } } } }
public function execute(CommandContext $context) { if (!Current_User::allow('hms', 'cancel_housing_application')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to cancel housing applications.'); } // Check for a housing application id $this->setAppId($context->get('applicationId')); if (!isset($this->applicationId) || is_null($this->applicationId)) { throw new InvalidArgumentException('Missing housing application id.'); } $application = HousingApplicationFactory::getApplicationById($this->applicationId); $application->setCancelled(0); $application->setCancelledBy(null); $application->setCancelledReason(null); $application->setCancelledOn(null); $application->save(); HMS_Activity_Log::log_activity($application->getUsername(), ACTIVITY_REINSTATE_APPLICATION, UserStatus::getUsername()); $returnCmd = CommandFactory::getCommand('ShowStudentProfile'); $returnCmd->setBannerId($application->getBannerId()); $returnCmd->redirect(); }
public function execute(CommandContext $context) { // Get input $requestId = $context->get('requestId'); $participantId = $context->get('participantId'); // Load the request $request = RoomChangeRequestFactory::getRequestById($requestId); // Load the participant $participant = RoomChangeParticipantFactory::getParticipantById($participantId); // Load the Student $student = StudentFactory::getStudentByBannerId($participant->getBannerId(), $request->getTerm()); // Check permissions. Must be the participant or an admin if (UserStatus::getUsername() != $student->getUsername() && !Current_User::allow('hms', 'admin_approve_room_change')) { throw new PermissionException('You do not have permission to decline this room change.'); } // Check for CAPTCHA if this is the student; admins don't need a CAPTCHA $captchaResult = Captcha::verify(true); if ($captchaResult === false) { // Failed the captcha NQ::simple('hms', hms\NotificationView::ERROR, "You didn't type the magic words correctly. Please try again."); $cmd = CommandFactory::getCommand('ShowRoomChangeRequestApproval'); $cmd->redirect(); } HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_ROOM_CHANGE_DECLINE, UserStatus::getUsername(FALSE), 'Request id: ' . $requestId . ' Captcha: ' . $captchaResult); // Transition request to cancelled status $request->transitionTo(new RoomChangeStateCancelled($request, time(), null, UserStatus::getUsername())); // Transition all participants to cancelled // TODO... Do this in the cancelled transition? $participants = $request->getParticipants(); foreach ($participants as $p) { $p->transitionTo(new ParticipantStateCancelled($p, time(), null, UserStatus::getUsername())); } // TODO Notify everyone that the request was cancelled NQ::simple('hms', hms\NotificationView::SUCCESS, 'You have declined the room change request.'); $menuCmd = CommandFactory::getCommand('ShowStudentMenu'); $menuCmd->redirect(); }
public function execute(CommandContext $context) { $id = $context->get('roommateId'); if (is_null($id)) { throw new InvalidArgumentException('Must set roommateId'); } PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $roommate = new HMS_Roommate($id); if ($roommate->id == 0) { throw new InvalidArgumentException('Invalid roommateId ' . $id); } $username = UserStatus::getUsername(); if ($username != $roommate->requestor && $username != $roommate->requestee) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException("{$username} tried to break roommate pairing {$roommate->id}"); } $err = CommandFactory::getCommand('ShowRoommateBreak'); $err->setRoommateId($id); PHPWS_Core::initCoreClass('Captcha.php'); $verified = Captcha::verify(TRUE); if ($verified === FALSE || is_null($verified)) { NQ::Simple('hms', hms\NotificationView::ERROR, 'Sorry, please try again.'); $err->redirect(); } $roommate->delete(); $other = StudentFactory::getStudentByUsername($roommate->get_other_guy($username), $roommate->term); HMS_Activity_Log::log_activity($other->getUsername(), ACTIVITY_STUDENT_BROKE_ROOMMATE, $username, "{$username} broke pairing, CAPTCHA: {$verified}"); HMS_Activity_Log::log_activity($username, ACTIVITY_STUDENT_BROKE_ROOMMATE, $other->getUsername(), "{$username} broke pairing, CAPTCHA: {$verified}"); // Email both parties PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_break_emails($roommate, $username); $name = $other->getFullName(); NQ::Simple('hms', hms\NotificationView::SUCCESS, "You have removed your roommate request for {$name}."); $cmd = CommandFactory::getCommand('ShowStudentMenu'); $cmd->redirect(); }
public function execute(CommandContext $context) { /* if(!Current_User::allow('hms', 'email_hall') && !Current_User::allow('hms', 'email_all')){ PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to send messages.'); } */ PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php'); PHPWS_Core::initModClass('hms', 'HMS_Floor.php'); PHPWS_Core::initModClass('hms', 'HMS_Email.php'); PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); PHPWS_Core::initModClass('hms', 'HMS_Permission.php'); // Sanity checks if (is_null($context->get('hall')) && is_null($context->get('floor'))) { NQ::simple('hms', hms\NotificationView::ERROR, 'You must select a hall or floor to continue!'); $cmd = CommandFactory::getCommand('ShowHallNotificationSelect'); $cmd->redirect(); } $subject = $context->get('subject'); $body = $context->get('body'); $anonymous = !is_null($context->get('anonymous')) && $context->get('anonymous') ? true : false; $from = $anonymous && Current_User::allow('hms', 'anonymous_notifications') ? FROM_ADDRESS : Current_User::getUsername() . '@' . DOMAIN_NAME; $halls = $context->get('hall'); $floors = $context->get('floor'); if (empty($subject)) { NQ::simple('hms', hms\NotificationView::ERROR, 'You must fill in the subject line of the email.'); $cmd = CommandFactory::getCommand('ShowHallNotificationEdit'); $cmd->loadContext($context); $cmd->redirect(); } else { if (empty($body)) { NQ::simple('hms', hms\NotificationView::ERROR, 'You must fill in the message to be sent.'); $cmd = CommandFactory::getCommand('ShowHallNotificationEdit'); $cmd->loadContext($context); $cmd->redirect(); } } //Consider using a batch process instead of doing this this inline // Log that this is happening if ($anonymous) { HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_ANON_NOTIFICATION_SENT, Current_User::getUsername()); } else { HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_NOTIFICATION_SENT, Current_User::getUsername()); } //load the floors foreach ($floors as $key => $floor_id) { $floors[$key] = new HMS_Floor($floor_id); } // TODO accurate logging //HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_HALL_NOTIFIED_ANONYMOUSLY, Current_User::getUsername(), $hall->hall_name); //HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_HALL_NOTIFIED, Current_User::getUsername(), $hall->hall_name); $floorObj = array(); //load the halls and add floors that aren't already present, if they have js enabled should be zero foreach ($halls as $hall) { $hallObj = new HMS_Residence_Hall($hall); $hallFloors = $hallObj->get_floors(); //if the hall has zero floors, skip it if (!is_array($hallFloors)) { continue; } foreach ($hallFloors as $hallFloor) { if (!empty($floors)) { foreach ($floors as $floor) { if ($hallFloor->id == $floor->id) { break; } } } if (!in_array($hallFloor, $floors)) { $floorObj[] = $hallFloor; } } } if (!is_array($floorObj)) { $floorObj = array(); } if (!is_array($floors)) { $floors = array(); } $floorObj = array_merge($floorObj, $floors); $permission = new HMS_Permission(); foreach ($floorObj as $floor) { if (!$permission->verify(Current_User::getUsername(), $floor, 'email') && !$permission->verify(Current_User::getUsername(), $floor->get_parent(), 'email') && !Current_User::allow('hms', 'email_all')) { continue; } /** $rooms = $floor->get_rooms(); foreach($rooms as $room){ $students = $room->get_assignees(); foreach($students as $student){ $people[] = $student->getUsername(); HMS_Email::send_email($student->getUsername() . '@appstate.edu', $from, $subject, $body); } } */ $students = $floor->getUsernames(); foreach ($students as $student) { HMS_Email::send_email($student . '@' . DOMAIN_NAME, $from, $subject, $body); } HMS_Activity_Log::log_activity(Current_User::getUsername(), $anonymous ? ACTIVITY_FLOOR_NOTIFIED_ANONYMOUSLY : ACTIVITY_FLOOR_NOTIFIED, Current_User::getUsername(), $floor->where_am_i()); } NQ::simple('hms', hms\NotificationView::SUCCESS, 'Emails sent successfully!'); $cmd = CommandFactory::getCommand('ShowAdminMaintenanceMenu'); $cmd->redirect(); }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'StudentFactory.php'); $roomId = $context->get('roomId'); $roommates = $context->get('roommates'); $mealPlan = $context->get('mealPlan'); $term = PHPWS_Settings::get('hms', 'lottery_term'); $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term); $errorCmd = CommandFactory::getCommand('LotteryShowConfirm'); $errorCmd->setRoomId($roomId); $errorCmd->setRoommates($roommates); $errorCmd->setMealPlan($mealPlan); $successCmd = CommandFactory::getCommand('LotteryShowConfirmed'); $successCmd->setRoomId($roomId); PHPWS_Core::initCoreClass('Captcha.php'); $captcha = Captcha::verify(TRUE); // returns the words entered if correct, FALSE otherwise //$captcha = TRUE; if ($captcha === FALSE) { NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, the words you eneted were incorrect. Please try again.'); $errorCmd->redirect(); } PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'HMS_Room.php'); PHPWS_Core::initModClass('hms', 'HMS_Bed.php'); PHPWS_Core::initModClass('hms', 'HMS_Assignment.php'); PHPWS_Core::initModClass('hms', 'HMS_Lottery.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HMS_Email.php'); PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); PHPWS_Core::initModClass('hms', 'HMS_Util.php'); PHPWS_Core::initModClass('hms', 'RlcMembershipFactory.php'); PHPWS_Core::initModClass('hms', 'RlcAssignmentSelfAssignedState.php'); $room = new HMS_Room($roomId); // Check for an RLC assignment in the self-select status $rlcAssignment = RlcMembershipFactory::getMembership($student, $term); // Check roommates for validity foreach ($roommates as $bed_id => $username) { // Double check the student is valid try { $roommate = StudentFactory::getStudentByUsername($username, $term); } catch (StudentNotFoundException $e) { NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is not a valid student. Please choose a different roommate."); $errorCmd->redirect(); } // Make sure the bed is still empty $bed = new HMS_Bed($bed_id); if ($bed->has_vacancy() != TRUE) { NQ::simple('hms', hms\NotificationView::ERROR, 'One or more of the beds in the room you selected is no longer available. Please try again.'); $errorCmd->redirect(); } // Make sure none of the needed beds are reserved if ($bed->is_lottery_reserved()) { NQ::simple('hms', hms\NotificationView::ERROR, 'One or more of the beds in the room you selected is no longer available. Please try again.'); $errorCmd->redirect(); } // Double check the genders are all the same as the person logged in if ($student->getGender() != $roommate->getGender()) { NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is a different gender. Please choose a roommate of the same gender."); $errorCmd->redirect(); } // Double check the genders are the same as the room (as long as the room isn't AUTO) if ($room->gender_type != AUTO && $roommate->getGender() != $room->gender_type) { NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is a different gender. Please choose a roommate of the same gender."); $errorCmd->redirect(); } // If this student is an RLC-self-selection, then each roommate must be in the same RLC and in the selfselect-invite state too if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') { // This student is an RLC-self-select, so check the roommate's RLC status $roommateRlcAssign = RlcMembershipFactory::getMembership($roommate, $term); // Make sure the roommate is a member of the same RLC and is eligible for self-selection if ($roommateRlcAssign == null || $roommateRlcAssign->getStateName() != 'selfselect-invite' || $rlcAssignment->getRlc()->getId() != $roommateRlcAssign->getRlc()->getId()) { NQ::simple('hms', hms\NotificationView::ERROR, "{$roommate} must be a member of the same learning community as you, and must also be eligible for self-selction."); $errorCmd->redirect(); } // Otherwise (if not RLC members), make sure each roommate is eligible } else { if (HMS_Lottery::determineEligibility($username) !== TRUE) { NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is not eligible for assignment."); $errorCmd->redirect(); } } // If this student is a self-select RLC member, then this student must also be a self-select RLC member of the same RLC if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') { $roommateRlcAssign = RlcMembershipFactory::getMembership($roommate, $term); if ($roommateRlcAssign == null || $roommateRlcAssign->getStateName() != 'selfselect-invite' || $rlcAssignment->getRlc()->getId() != $roommateRlcAssign->getRlc()->getId()) { NQ::simple('hms', hms\NotificationView::ERROR, "{$username} must be a member of the same learning community as you, and must also be eligible for self-selction."); $errorCmd->redirect(); } } } // If the room's gender is 'AUTO' and no one is assigned to it yet, switch it to the student's gender if ($room->gender_type == AUTO && $room->get_number_of_assignees() == 0) { $room->gender_type = $student->getGender(); $room->save(); } // Assign the student to the requested bed $bed_id = array_search(UserStatus::getUsername(), $roommates); // Find the bed id of the student who's logged in try { $result = HMS_Assignment::assignStudent($student, PHPWS_Settings::get('hms', 'lottery_term'), NULL, $bed_id, $mealPlan, 'Confirmed lottery invite', TRUE, ASSIGN_LOTTERY); } catch (Exception $e) { NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, there was an error creating your room assignment. Please try again or contact University Housing.'); $errorCmd->redirect(); } // Log the assignment HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_LOTTERY_ROOM_CHOSEN, UserStatus::getUsername(), 'Captcha: ' . $captcha); // Update the student's meal plan in the housing application, just for future reference $app = HousingApplication::getApplicationByUser($student->getUsername(), $term); $app->setMealPlan($mealPlan); $app->save(); // If this student was an RLC self-select, update the RLC memberhsip state if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') { $rlcAssignment->changeState(new RlcAssignmentSelfAssignedState($rlcAssignment)); } foreach ($roommates as $bed_id => $username) { // Skip the current user if ($username == $student->getUsername()) { continue; } # Reserve the bed for the roommate $expires_on = time() + INVITE_TTL_HRS * 3600; $bed = new HMS_Bed($bed_id); if (!$bed->lottery_reserve($username, $student->getUsername(), $expires_on)) { NQ::smiple('hms', hms\NotificationView::WARNING, "You were assigned, but there was a problem reserving space for your roommates. Please contact University Housing."); $successCmd->redirect(); } HMS_Activity_Log::log_activity($username, ACTIVITY_LOTTERY_REQUESTED_AS_ROOMMATE, $student->getUsername(), 'Expires: ' . HMS_Util::get_long_date_time($expires_on)); # Invite the selected roommates $roomie = StudentFactory::getStudentByUsername($username, $term); $term = PHPWS_Settings::get('hms', 'lottery_term'); $year = Term::toString($term) . ' - ' . Term::toString(Term::getNextTerm($term)); HMS_Email::send_lottery_roommate_invite($roomie, $student, $expires_on, $room->where_am_i(), $year); } HMS_Email::send_lottery_assignment_confirmation($student, $room->where_am_i(), $term); $successCmd->redirect(); }
/** * Processes a queued item. This can be something actually queued, * or an immediate processing because the queue is disabled. */ public function process() { PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); PHPWS_Core::initModClass('hms', 'SOAP.php'); $soap = SOAP::getInstance(UserStatus::getUsername(), UserStatus::isAdmin() ? SOAP::ADMIN_USER : SOAP::STUDENT_USER); $result = null; switch ($this->type) { case BANNER_QUEUE_ASSIGNMENT: $result = $soap->reportRoomAssignment($this->asu_username, $this->term, $this->building_code, $this->bed_code, 'HOME', $this->meal_code); if ($result === TRUE) { HMS_Activity_Log::log_activity($this->asu_username, ACTIVITY_ASSIGNMENT_REPORTED, Current_User::getUsername(), $this->term . ' ' . $this->building_code . ' ' . $this->bed_code . ' ' . 'HOME' . ' ' . $this->meal_code); } break; case BANNER_QUEUE_REMOVAL: // Get the Banner ID from the user name // TODO fix this to use BannerID directly $bannerId = $soap->getBannerId($this->asu_username); $result = $soap->removeRoomAssignment($bannerId, $this->term, $this->building_code, $this->bed_code, $this->percent_refund); if ($result === TRUE) { HMS_Activity_Log::log_activity($this->asu_username, ACTIVITY_REMOVAL_REPORTED, Current_User::getUsername(), $this->term . ' ' . $this->building_code . ' ' . $this->bed_code . ' '); } break; } return $result; }
public function execute(CommandContext $context) { // Cmd to redirect to when we're done or upon error. $formCmd = CommandFactory::getCommand('ShowRoomChangeRequestForm'); $menuCmd = CommandFactory::getCommand('ShowStudentMenu'); // Get input $cellNum = $context->get('cell_num'); $optOut = $context->get('cell_opt_out'); $firstHallPref = $context->get('first_choice'); $secondHallPref = $context->get('second_choice'); $term = Term::getCurrentTerm(); // Create the student object $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term); // Make sure the student is currently assigned $assignment = HMS_Assignment::getAssignmentByBannerId($student->getBannerId(), $term); if (is_null($assignment)) { NQ::simple('hms', hms\NotificationView::ERROR, 'You are not currently assigned to a room, so you cannot request a room change.'); $menuCmd->redirect(); } // Get the HMS_Bed object corresponding to the student's current assignment $bed = $assignment->get_parent(); $room = $bed->get_parent(); // Check for an existing room change request $changeReq = RoomChangeRequestFactory::getPendingByStudent($student, $term); if (!is_null($changeReq)) { // has pending request NQ::simple('hms', hms\NotificationView::ERROR, 'You already have a pending room change request. You cannot submit another request until your pending request is processed.'); $menuCmd->redirect(); } // Check that a cell phone number was provided, or that the opt-out box was checked. if ((!isset($cellNum) || empty($cellNum)) && !isset($optOut)) { NQ::simple('hms', hms\NotificationView::ERROR, 'Please provide a cell phone number or check the box indicating you do not wish to provide it.'); $formCmd->redirect(); } // Check the format of the cell phone number if (isset($cellNum)) { // Filter out non-numeric characters $cellNum = preg_replace("/[^0-9]/", '', $cellNum); } $reason = $context->get('reason'); // Make sure a 'reason' was provided. if (!isset($reason) || empty($reason)) { NQ::simple('hms', hms\NotificationView::ERROR, 'Please provide a brief explaniation of why you are requesting a room change.'); $formCmd->redirect(); } $type = $context->get('type'); // Extra sanity checks if we're doing a switch if ($type == 'swap') { $switchUsername = $context->get('swap_with'); // Can't switch with yourself if ($student->getUsername() == $switchUsername) { NQ::simple('hms', hms\NotificationView::ERROR, "You can't swtich rooms with yourself. Please choose someone other than yourself."); $formCmd->redirect(); } // Load the other student try { $swapStudent = StudentFactory::getStudentByUsername($switchUsername, $term); } catch (StudentNotFoundException $e) { NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, we could not find a student with the user name '{$switchUsername}'. Please double-check the user name of the student you would like to switch places with."); $formCmd->redirect(); } // Make sure the student is assigned $swapAssignment = HMS_Assignment::getAssignmentByBannerId($swapStudent->getBannerId(), $term); if (is_null($swapAssignment)) { NQ::simple('hms', hms\NotificationView::ERROR, "{$swapStudent->getName()} is not currently assigned. Please choose another student to switch rooms with."); $formCmd->redirect(); } // Make sure the other student's room is the same gender as this room $swapBed = $swapAssignment->get_parent(); $swapRoom = $swapBed->get_parent(); if ($swapRoom->getGender() != $room->getGender()) { NQ::simple('hms', hms\NotificationView::ERROR, "{$swapStudent->getName()} is assigned to a room of a different gender than you. Please choose student of the same gender as yourself to switch rooms with."); $formCmd->redirect(); } // Check to see if the other student is already involved in a room change request $swapStudentReq = RoomChangeRequestFactory::getPendingByStudent($swapStudent, $term); if (!is_null($swapStudentReq)) { // has pending request NQ::simple('hms', hms\NotificationView::ERROR, 'The student you are requesting to swap with already has a pending room change request. You cannot request to swap with him/her until the pending request is processed.'); $menuCmd->redirect(); } } //create the request object $request = new RoomChangeRequest($term, $reason); $request->save(); // Main participant $participant = new RoomChangeParticipant($request, $student, $bed); if (isset($cellNum)) { $participant->setCellPhone($cellNum); } // Switching to a different room, so set params on main participant if ($type == 'switch') { // preferences if (!empty($firstHallPref)) { $hall = new HMS_Residence_Hall($firstHallPref); if (!is_null($hall->getId())) { $participant->setHallPref1($hall); } } if (!empty($secondHallPref)) { $hall = new HMS_Residence_Hall($secondHallPref); if (!is_null($hall->getId())) { $participant->setHallPref2($hall); } } // Save the main participant and its state $participant->save(); // No further approval is required so we skip a step HMS_Email::sendRoomChangeCurrRDNotice($request); } else { if ($type == 'swap') { // Swapping with another student, so handle the other particpant // Set main participant's toBed to other student's bed $participant->setToBed($swapBed); // Create the other participant $swapParticipant = new RoomChangeParticipant($request, $swapStudent, $swapBed); // Set other student's toBed to main participant's bed $swapParticipant->setToBed($bed); $swapParticipant->save(); // Save the main participant and its state $participant->save(); // Send "request needs your approval" to other students // TODO: When you add the ability to have many people on this request, you will // need to put a foreach loop here or something. HMS_Email::sendRoomChangeParticipantNotice($participant, $swapParticipant); } } // Immediately transition to the StudentApproved state. $participant->transitionTo(new ParticipantStateStudentApproved($participant, time(), null, UserStatus::getUsername())); HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_ROOM_CHANGE_SUBMITTED, UserStatus::getUsername(FALSE), $reason); // Email sender with acknowledgment HMS_Email::sendRoomChangeRequestReceivedConfirmation($student); if ($type == 'switch') { NQ::simple('hms', hms\NotificationView::SUCCESS, 'Your room change request has been received and is pending approval. You will be contacted by your Residence Director (RD) in the next 24-48 hours regarding your request.'); } else { NQ::simple('hms', hms\NotificationView::SUCCESS, 'Your room change request has been received. The student(s) you selected to swap with must sign-in and agree to the request. It will then be forwarded to your Residence Director and the Housing Assignments Office for approval.'); } $menuCmd->redirect(); }
/** * Handles removing RLC applications. * @param Student $student */ private function handleRlcApplication(Student $student) { // Mark any RLC applications as denied $rlcApp = HMS_RLC_Application::getApplicationByUsername($student->getUsername(), $this->term); if (!is_null($rlcApp)) { // TODO catch/handle exceptions $rlcApp->delete(); $this->actions[$student->getUsername()][] = 'Marked RLC application as denied.'; HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_WITHDRAWN_RLC_APP_DENIED, UserStatus::getUsername(), 'Withdrawn search'); } }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php'); PHPWS_Core::initModClass('hms', 'exception/InvalidTermException.php'); $term = $context->get('term'); $username = UserStatus::getUsername(); $student = StudentFactory::getStudentByUsername($username, $term); $sem = Term::getTermSem($term); // Check for an existing application and delete it $app_result = HousingApplication::checkForApplication($username, $term); // If there's an existing housing application, handle deleting it if ($app_result !== FALSE) { switch ($sem) { case TERM_SPRING: $application = new SpringApplication($app_result['id']); break; case TERM_SUMMER1: case TERM_SUMMER2: $application = new SummerApplication($app_result['id']); break; case TERM_FALL: $application = new FallApplication($app_result['id']); break; default: throw new InvalidTermException('Invalid term specified.'); } // Save the old created on dates for re-use on new application $oldCreatedOn = $application->getCreatedOn(); $oldCreatedBy = $application->getCreatedBy(); $application->delete(); } switch ($sem) { case TERM_FALL: $appType = 'fall'; break; case TERM_SPRING: $appType = 'spring'; break; case TERM_SUMMER1: case TERM_SUMMER2: $appType = 'summer'; break; default: throw new Exception('Unknown application type'); } $application = HousingApplicationFactory::getApplicationFromSession($_SESSION['application_data'], $term, $student, $appType); // If old created dates exist, use them as the 'created on' dates if (isset($oldCreatedOn)) { $application->setCreatedOn($oldCreatedOn); $application->setCreatedBy($oldCreatedBy); } $application->setCancelled(0); // Hard code a summer meal option for all summer applications. // Application for other terms use whatever the student selected if ($sem == TERM_SUMMER1 || $sem == TERM_SUMMER2) { $application->setMealPlan(BANNER_MEAL_5WEEK); } $result = $application->save(); if ($result == TRUE) { // Log the fact that the application was submitted PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); HMS_Activity_Log::log_activity($username, ACTIVITY_SUBMITTED_APPLICATION, $username); try { // report the application to banner; $application->reportToBanner(); } catch (Exception $e) { // ignore any errors reporting this to banner, they'll be logged and admins notified // we've saved the student's application locally, so it's ok if this doesn't work } // Send the email confirmation PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_hms_application_confirmation($student, $application->getTerm()); } $friendly_term = Term::toString($application->getTerm()); NQ::simple('hms', hms\NotificationView::SUCCESS, "Your application for {$friendly_term} was successfully processed! You will receive an email confirmation in the next 24 hours."); PHPWS_Core::initModClass('hms', 'applicationFeature/RlcApplication.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); $rlcReg = new RLCApplicationRegistration(); if (ApplicationFeature::isEnabledForStudent($rlcReg, $term, $student) && HMS_RLC_Application::checkForApplication($student->getUsername(), $term) == FALSE && $application->rlc_interest == 1) { $rlcCmd = CommandFactory::getCommand('ShowRlcApplicationPage1View'); $rlcCmd->setTerm($term); $rlcCmd->redirect(); } else { $successCmd = CommandFactory::getCommand('ShowStudentMenu'); $successCmd->redirect(); } }
public static function send_roommate_reminder_emails($term) { PHPWS_Core::initModClass('hms', 'HMS_Bed.php'); PHPWS_Core::initModclass('hms', 'StudentFactory.php'); // Get a list of outstanding roommate requests, send them reminder emails $query = "select hms_lottery_reservation.* FROM hms_lottery_reservation\n LEFT OUTER JOIN (SELECT asu_username FROM hms_assignment WHERE term={$term} AND lottery = 1) as foo ON hms_lottery_reservation.asu_username = foo.asu_username\n WHERE foo.asu_username IS NULL\n AND hms_lottery_reservation.expires_on > " . time(); $result = PHPWS_DB::getAll($query); if (PEAR::isError($result)) { PHPWS_Error::log($result); test($result, 1); } $year = Term::toString($term) . ' - ' . Term::toString(Term::getNextTerm($term)); foreach ($result as $row) { $student = StudentFactory::getStudentByUsername($row['asu_username'], $term); $requestor = StudentFactory::getStudentByUsername($row['requestor'], $term); $bed = new HMS_Bed($row['bed_id']); $hall_room = $bed->where_am_i(); HMS_Email::send_lottery_roommate_reminder($row['asu_username'], $student->getName(), $row['expires_on'], $requestor->getName(), $hall_room, $year); HMS_Activity_Log::log_activity($row['asu_username'], ACTIVITY_LOTTERY_ROOMMATE_REMINDED, 'hms'); } }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php'); PHPWS_Core::initModClass('hms', 'exception/InvalidTermException.php'); $term = $context->get('term'); $username = UserStatus::getUsername(); $student = StudentFactory::getStudentByUsername($username, $term); $sem = Term::getTermSem($term); // Check for an existing application and load it $application = NULL; $app_result = HousingApplication::checkForApplication($username, $term); if ($app_result !== FALSE) { switch ($sem) { case TERM_SPRING: $application = new SpringApplication($app_result['id']); break; case TERM_SUMMER1: case TERM_SUMMER2: $application = new SummerApplication($app_result['id']); break; case TERM_FALL: $application = new FallApplication($app_result['id']); break; default: throw new InvalidTermException('Invalid term specified.'); } } else { // TODO What if there is no application found? Should I cry? // Execution shouldn't be able to make it this far if an application doesn't exist. throw new Exception('No application found.'); } // Update the Emergency Contact and Missing Person information // TODO Sanity check all this new contact information /* Emergency Contact */ $application->setEmergencyContactName($context->get('emergency_contact_name')); $application->setEmergencyContactRelationship($context->get('emergency_contact_relationship')); $application->setEmergencyContactPhone($context->get('emergency_contact_phone')); $application->setEmergencyContactEmail($context->get('emergency_contact_email')); /* Emergency Medical Condition */ $application->setEmergencyMedicalCondition($context->get('emergency_medical_condition')); /* Missing Person */ $application->setMissingPersonName($context->get('missing_person_name')); $application->setMissingPersonRelationship($context->get('missing_person_relationship')); $application->setMissingPersonPhone($context->get('missing_person_phone')); $application->setMissingPersonEmail($context->get('missing_person_email')); // Save the modified application $result = $application->save(); if ($result == TRUE) { // Log the fact that the application updated PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); HMS_Activity_Log::log_activity($username, ACTIVITY_EMERGENCY_CONTACT_UPDATED, $username); try { // report the application to banner; $application->reportToBanner(); } catch (Exception $e) { // ignore any errors reporting this to banner, they'll be logged and admins notified. // we've saved the student's application locally, so it's ok if this doesn't work. } // Send the email confirmation PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_emergency_contact_updated_confirmation($student, $application->getTerm()); } // Notify user of success //$friendly_term = Term::toString($application->getTerm()); //NQ::simple('hms', hms\NotificationView::SUCCESS, "Your Emergency Contact & Missing Person information for $friendly_term was successfully modified! You will receive an email confirmation in the next 24 hours."); // Redirect to the student menu $successCmd = CommandFactory::getCommand('ShowStudentMenu'); $successCmd->redirect(); }