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();
 }
Exemplo n.º 2
0
 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();
 }
 /**
  * Executes this pulse. Does the withdrawn search and emails the results.
  */
 public function execute()
 {
     // Reschedule the next run of this process
     $sp = $this->makeClone();
     $sp->execute_at = strtotime("tomorrow");
     $sp->save();
     // Load some classes
     PHPWS_Core::initModClass('hms', 'HMS.php');
     PHPWS_Core::initModClass('hms', 'WithdrawnSearch.php');
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     PHPWS_Core::initModClass('hms', 'UserStatus.php');
     UserStatus::wearMask('HMS System');
     // The search is run over all future terms
     $terms = Term::getFutureTerms();
     $text = "";
     foreach ($terms as $term) {
         $search = new WithdrawnSearch($term);
         $search->doSearch();
         $text .= "\n\n=========== " . Term::toString($term) . " ===========\n\n";
         $text .= $search->getTextView();
     }
     $text = $search->getTextView();
     HMS_Email::sendWithdrawnSearchOutput($text);
     UserStatus::removeMask();
     HMS::quit();
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'RoomDamageFactory.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     PHPWS_Core::initModClass('hms', 'CheckinFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     $term = Term::getSelectedTerm();
     // Get the total damages assessed for each student
     $damages = RoomDamageFactory::getAssessedDamagesStudentTotals($term);
     foreach ($damages as $dmg) {
         $student = StudentFactory::getStudentByBannerId($dmg['banner_id'], $term);
         // Get the student's last checkout
         // (NB: the damages may be for multiple check-outs,
         // but we'll just take the last one)
         $checkout = CheckinFactory::getLastCheckoutForStudent($student);
         $bed = new HMS_Bed($checkout->getBedId());
         $room = $bed->get_parent();
         $floor = $room->get_parent();
         $hall = $floor->get_parent();
         $coordinators = $hall->getCoordinators();
         if ($coordinators != null) {
             $coordinatorName = $coordinators[0]->getDisplayName();
             $coordinatorEmail = $coordinators[0]->getEmail();
         } else {
             $coordinatorName = '(No coordinator set for this hall.)';
             $coordinatorEmail = '(No coordinator set for this hall.)';
         }
         HMS_Email::sendDamageNotification($student, $term, $dmg['sum'], $coordinatorName, $coordinatorEmail);
     }
     // Show a success message and redirect back to the main admin menu
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Room damage noties sent.');
     $cmd = CommandFactory::getCommand('ShowAdminMaintenanceMenu');
     $cmd->redirect();
 }
 public function execute(CommandContext $context)
 {
     $send_to = array();
     $send_to[] = '*****@*****.**';
     $send_to[] = '*****@*****.**';
     $send_to[] = '*****@*****.**';
     $send_to[] = '*****@*****.**';
     $from = FROM_ADDRESS;
     $subject = 'HMS Contact Form';
     $body = "Username: "******"\n";
     $body .= "Application date: " . $context->get('application_term') . "\n";
     $body .= "Student Type: " . $context->get('student_type') . "\n";
     $body .= "\n\nInput from student:\n\n";
     $body .= "Name: " . $context->get('name') . "\n";
     $body .= "Email: " . $context->get('email') . "\n";
     $body .= "Phone #: " . $context->get('phone') . "\n";
     $body .= "Type: " . $context->get('stype') . "\n";
     $body .= "Text field:\n";
     $body .= "" . $context->get('comments') . "\n\n";
     if (!HMS_Email::send_email($send_to, $from, $subject, $body)) {
         //Maybe we shouldn't say anything...
         //NQ::simple('hms', hms\NotificationView::ERROR, 'Error sending email!');
     }
     $view = new ContactFormThankYouView();
     $context->setContent($view->show());
 }
 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);
     // Check permissions. Must be an RD for current bed, or an admin
     $rds = $participant->getFutureRdList();
     if (!in_array(UserStatus::getUsername(), $rds) && !Current_User::allow('hms', 'admin_approve_room_change')) {
         throw new PermissionException('You do not have permission to approve this room change.');
     }
     // Transition to CurrRdApproved
     $participant->transitionTo(new ParticipantStateFutureRdApproved($participant, time(), null, UserStatus::getUsername()));
     //TODO If all participants are approved, send notification to Housing
     if ($request->isApprovedByAllFutureRDs()) {
         HMS_Email::sendRoomChangeAdministratorNotice($request);
     }
     // Redirect to the manage request page
     $cmd->redirect();
 }
 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)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'email_rlc_rejections')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to send RLC rejections.');
     }
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
     PHPWS_Core::initModClass('hms', 'Term.php');
     $term = Term::getSelectedTerm();
     $deniedApps = HMS_RLC_Application::getNonNotifiedDeniedApplicantsByTerm($term);
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     $email = new HMS_Email();
     foreach ($deniedApps as $app) {
         $student = StudentFactory::getStudentByUsername($app['username'], $term);
         $email->sendRlcApplicationRejected($student, $term);
         $application = HMS_RLC_Application::getApplicationById($app['id']);
         $application->setDeniedEmailSent(1);
         $application->save();
     }
     NQ::Simple('hms', hms\NotificationView::SUCCESS, 'RLC rejection emails sent.');
     $context->goBack();
 }
Exemplo n.º 9
0
 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();
 }
Exemplo n.º 10
0
 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();
     }
 }
Exemplo n.º 12
0
 public function execute(CommandContext $context)
 {
     $requestId = $context->get('requestId');
     $reason = $context->get('cancel-reason');
     // Load the request
     $request = RoomChangeRequestFactory::getRequestById($requestId);
     // TODO Check permissions, based on state
     // Command for redirecting back to the request view on success or error
     $cmd = CommandFactory::getCommand('ShowManageRoomChange');
     $cmd->setRequestId($request->getId());
     // Make sure user gave a reason
     if (!isset($reason) or $reason == '') {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Please enter a cancellation reason.');
         $cmd->redirect();
     }
     // Set the denied reason
     $request->setDeniedReasonPublic($reason);
     $request->save();
     // 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()));
         //Release the bed reservation, if any
         $bedId = $p->getToBed();
         if ($bedId != null) {
             $bed = new HMS_Bed($bedId);
             $bed->clearRoomChangeReserved();
             $bed->save();
         }
     }
     // Notify everyone involved
     try {
         PHPWS_Core::initModClass('hms', 'StudentFactory.php');
         $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $request->getTerm());
     } catch (StudentNotFoundException $e) {
         $student = null;
     }
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     HMS_Email::sendRoomChangeCancelledNotice($request, $student);
     $cmd->redirect();
 }
Exemplo n.º 13
0
 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();
 }
Exemplo n.º 14
0
 public function execute(CommandContext $context)
 {
     // Check permissions
     if (!Current_User::allow('hms', 'checkin')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to checkin students.');
     }
     $bannerId = $context->get('bannerId');
     $hallId = $context->get('hallId');
     // Check for key code
     $keyCode = $context->get('key_code');
     if (!isset($keyCode) || $keyCode == '') {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Please enter a key code.');
         $errorCmd = CommandFactory::getCommand('ShowCheckinForm');
         $errorCmd->setBannerId($bannerId);
         $errorCmd->setHallId($hallId);
         $errorCmd->redirect();
     }
     $term = Term::getSelectedTerm();
     // Lookup the student
     $student = StudentFactory::getStudentByBannerId($bannerId, $term);
     // Get the student's current assignment
     $assignment = HMS_Assignment::getAssignmentByBannerId($bannerId, $term);
     $bed = $assignment->get_parent();
     // Get the currently logged in user
     $currUser = Current_User::getUsername();
     // Check for an existing Check-in
     $checkin = CheckinFactory::getCheckinByBed($student, $bed);
     // If there's not already a checkin for this bed, create a new one
     if (is_null($checkin)) {
         $checkin = new Checkin($student, $bed, $term, $currUser, $keyCode);
     } else {
         if ($checkin->getBedId() == $bed->getId() && time() - $checkin->getCheckinDate() < Checkin::CHECKIN_TIMEOUT) {
             // Check-in already exists, and it's within the timout window, so we'll overwrite the existing checkin
             $updatedCheckin = new Checkin($student, $bed, $term, $currUser, $keyCode);
             $updatedCheckin->substitueForExistingCheckin($checkin);
             // Use the old checkin to replace this one
             $checkin = $updatedCheckin;
         } else {
             // There's an existing checkin, but it's after the timeout, so we need to make a new checkin
             $checkin = new Checkin($student, $bed, $term, $currUser, $keyCode);
         }
     }
     $checkin->save();
     // Add this to the activity log
     HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_CHECK_IN, UserStatus::getUsername(), $assignment->where_am_i());
     // Generate the RIC
     PHPWS_Core::initModClass('hms', 'InfoCard.php');
     PHPWS_Core::initModClass('hms', 'InfoCardPdfView.php');
     $infoCard = new InfoCard($checkin);
     $infoCardView = new InfoCardPdfView();
     $infoCardView->addInfoCard($infoCard);
     // Send confirmation Email with the RIC form to the student
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     HMS_Email::sendCheckinConfirmation($student, $infoCard, $infoCardView);
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Checkin successful.');
     // Redirect to success page with option to print check-in document.
     $cmd = CommandFactory::getCommand('ShowCheckinDocument');
     $cmd->setBannerId($student->getBannerId());
     $cmd->setCheckinId($checkin->getId());
     $cmd->redirect();
 }
Exemplo n.º 15
0
 public static function confirm_roommate_request($username, $requestId, $meal_plan)
 {
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     $term = PHPWS_Settings::get('hms', 'lottery_term');
     // Get the roommate invite
     $invite = HMS_Lottery::get_lottery_roommate_invite_by_id($requestId);
     // If the invite wasn't found, show an error
     if ($invite === false) {
         return E_LOTTERY_ROOMMATE_INVITE_NOT_FOUND;
     }
     // Check that the reserved bed is still empty
     $bed = new HMS_Bed($invite['bed_id']);
     if (!$bed->has_vacancy()) {
         return E_ASSIGN_BED_NOT_EMPTY;
     }
     // Make sure the student isn't assigned anywhere else
     if (HMS_Assignment::checkForAssignment($username, $term)) {
         return E_ASSIGN_ALREADY_ASSIGNED;
     }
     $student = StudentFactory::getStudentByUsername($username, $term);
     $requestor = StudentFactory::getStudentByUsername($invite['requestor'], $term);
     // Actually make the assignment
     HMS_Assignment::assignStudent($student, $term, null, $invite['bed_id'], $meal_plan, 'Confirmed roommate invite', true, ASSIGN_LOTTERY);
     // return successfully
     HMS_Email::send_roommate_confirmation($student, $requestor);
     return E_SUCCESS;
 }
 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 function execute(CommandContext $context)
 {
     // Get input
     $requestId = $context->get('requestId');
     $participantId = $context->get('participantId');
     // destinationBedId - This can be null for "swap" requests, because it's already known
     $toBedSelected = $context->get('bed_select');
     // 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);
     // Check permissions. Must be an RD for current bed, or an admin
     $rds = $participant->getCurrentRdList();
     if (!in_array(UserStatus::getUsername(), $rds) && !Current_User::allow('hms', 'admin_approve_room_change')) {
         throw new PermissionException('You do not have permission to approve this room change.');
     }
     // Check that a destination bed has already been set, or that the RD
     // has just selected a bed
     $toBedId = $participant->getToBed();
     if (is_null($toBedId) && $toBedSelected == '-1') {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Please select a destination bed.');
         $cmd->redirect();
     }
     // Set the selected bed, if needed
     if (is_null($toBedId) && $toBedSelected != '-1') {
         $bed = new HMS_Bed($toBedSelected);
         // Check that the bed isn't already reserved for a room change
         if ($bed->isRoomChangeReserved()) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'The bed you selected is already reserved for a room change. Please choose a different bed.');
             $cmd->redirect();
         }
         // Reserve the bed for room change
         $bed->setRoomChangeReserved();
         $bed->save();
         // Save the bed to this participant
         $participant->setToBed($bed);
         $participant->save();
     }
     // Transition to CurrRdApproved
     $participant->transitionTo(new ParticipantStateCurrRdApproved($participant, time(), null, UserStatus::getUsername()));
     // If the future RD is the same as the current user Logged in, then go ahead and transition to FutureRdApproved too.
     //TODO
     if ($request->isApprovedByAllCurrentRDs()) {
         // If all Current RDs have approved, notify Future RDs
         HMS_Email::sendRoomChangeFutureRDNotice($request);
         // If all Current RDs have approved, notify future roommates
         foreach ($request->getParticipants() as $p) {
             $bed = new HMS_Bed($p->getToBed());
             $room = $bed->get_parent();
             foreach ($room->get_assignees() as $a) {
                 if ($a instanceof Student && $a->getBannerID() != $p->getBannerID()) {
                     HMS_Email::sendRoomChangePreliminaryRoommateNotice($a);
                 }
             }
         }
     }
     // Redirect to the manage request page
     $cmd->redirect();
 }
 public function execute(CommandContext $context)
 {
     if (!Current_User::allow('hms', 'assignment_notify')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to send assignment notifications.');
     }
     PHPWS_Core::initModClass('hms', 'Term.php');
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Movein_Time.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php');
     // Check if any move-in times are set for the selected term
     $moveinTimes = HMS_Movein_Time::get_movein_times_array(Term::getSelectedTerm());
     // If the array of move-in times ONLY has the zero-th element ['None'] then it's no good
     // Or, of course, if the array is null or emtpy it is no good
     if (count($moveinTimes) <= 1 || is_null($moveinTimes) || empty($moveinTimes)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'There are no move-in times set for ' . Term::getPrintableSelectedTerm());
         $context->goBack();
     }
     // Keep track of floors missing move-in times
     $missingMovein = array();
     $term = Term::getSelectedTerm();
     $db = new PHPWS_DB('hms_assignment');
     $db->addWhere('email_sent', 0);
     $db->addWhere('term', $term);
     $result = $db->getObjects("HMS_Assignment");
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     foreach ($result as $assignment) {
         //get the students real name from their asu_username
         $student = StudentFactory::getStudentByUsername($assignment->getUsername(), $term);
         //get the location of their assignment
         PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
         $bed = new HMS_Bed($assignment->getBedId());
         $room = $bed->get_parent();
         $location = $bed->where_am_i() . ' - Bedroom ' . $bed->bedroom_label;
         // Lookup the floor and hall to make sure the
         // assignment notifications flag is true for this hall
         $floor = $room->get_parent();
         $hall = $floor->get_parent();
         if ($hall->assignment_notifications == 0) {
             continue;
         }
         // Get the student type for determining move-in time
         $type = $student->getType();
         // Check for an accepted and confirmed RLC assignment
         $rlcAssignment = HMS_RLC_Assignment::getAssignmentByUsername($student->getUsername(), $term);
         // If there is an assignment, make sure the student "confirmed" the rlc invite
         if (!is_null($rlcAssignment)) {
             if ($rlcAssignment->getStateName() != 'confirmed' && $rlcAssignment->getStateName() != 'selfselect-assigned') {
                 $rlcAssignment = null;
             }
         }
         // Make sure this is re-initialized
         $moveinTimeId = null;
         $rlcSetMoveinTime = false;
         // Determine the move-in time
         if (!is_null($rlcAssignment)) {
             // If there is a 'confirmed' RLC assignment, use the RLC's move-in times
             $rlc = $rlcAssignment->getRlc();
             if ($type == TYPE_CONTINUING) {
                 $moveinTimeId = $rlc->getContinuingMoveinTime();
             } else {
                 if ($type == TYPE_TRANSFER) {
                     $moveinTimeId = $rlc->getTransferMoveinTime();
                 } else {
                     if ($type == TYPE_FRESHMEN) {
                         $moveinTimeId = $rlc->getFreshmenMoveinTime();
                     }
                 }
             }
         }
         // If there's a non-null move-in time ID at this point, then we know the RLC must have set it
         if (!is_null($moveinTimeId)) {
             $rlcSetMoveinTime = true;
         }
         // If the RLC didn't set a movein time, set it according to the floor
         // TODO: Find continuing students by checking the student's application term
         // against the term we're wending assignment notices for
         if (is_null($moveinTimeId)) {
             if ($type == TYPE_CONTINUING) {
                 $moveinTimeId = $assignment->get_rt_movein_time_id();
             } else {
                 if ($type == TYPE_TRANSFER) {
                     $moveinTimeId = $assignment->get_t_movein_time_id();
                 } else {
                     $moveinTimeId = $assignment->get_f_movein_time_id();
                 }
             }
         }
         // Check for missing move-in times
         if ($moveinTimeId == NULL) {
             //test($assignment, 1); // Will only happen if there's no move-in time set for the floor,student type
             // Lets only keep a set of the floors
             if (!in_array($floor, $missingMovein)) {
                 $missingMovein[] = $floor;
             }
             // Missing move-in time, so skip to the next assignment
             continue;
         }
         // TODO: Grab all the move-in times and index them in an array by ID so we don't have to query the DB every single time
         $movein_time_obj = new HMS_Movein_Time($moveinTimeId);
         $movein_time = $movein_time_obj->get_formatted_begin_end();
         // Add a bit of text if the move-in time was for an RLC
         if ($rlcSetMoveinTime) {
             $movein_time .= ' (for the ' . $rlc->get_community_name() . ' Residential Learning Community)';
         }
         //get the list of roommates
         $roommates = array();
         $beds = $room->get_beds();
         foreach ($beds as $bed) {
             $roommate = $bed->get_assignee();
             if ($roommate == false || is_null($roommate) || $roommate->getUsername() == $student->getUsername()) {
                 continue;
             }
             $roommates[] = $roommate->getFullName() . ' (' . $roommate->getUsername() . '@appstate.edu) - Bedroom ' . $bed->bedroom_label;
         }
         // Send the email
         HMS_Email::sendAssignmentNotice($student->getUsername(), $student->getName(), $term, $location, $roommates, $movein_time);
         // Mark the student as having received an email
         $db->reset();
         $db->addWhere('asu_username', $assignment->getUsername());
         $db->addWhere('term', $term);
         $db->addValue('email_sent', 1);
         $rslt = $db->update();
         if (PHPWS_Error::logIfError($rslt)) {
             throw new DatabaseException($result->toString());
         }
     }
     // Check for floors with missing move-in times.
     if (empty($missingMovein) || is_null($missingMovein)) {
         // Ther are none, so show a success message
         NQ::simple('hms', hms\NotificationView::SUCCESS, "Assignment notifications sent.");
     } else {
         // Show a warning for each floor that was missing a move-in time
         foreach ($missingMovein as $floor) {
             $hall = $floor->get_parent();
             $text = $floor->getLink($hall->getHallName() . " floor ") . " move-in times not set.";
             NQ::simple('hms', hms\NotificationView::WARNING, $text);
         }
     }
     $context->goBack();
 }
 public function execute(CommandContext $context)
 {
     $term = $context->get('term');
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), Term::getCurrentTerm());
     $errorCmd = CommandFactory::getCommand('ShowRlcApplicationView');
     $errorCmd->setTerm($term);
     $choice1 = new HMS_Learning_Community($context->get('rlc_first_choice'));
     $choice2 = new HMS_Learning_Community($context->get('rlc_second_choice'));
     $choice3 = new HMS_Learning_Community($context->get('rlc_third_choice'));
     if (!$choice1->allowStudentType($student->getType()) || $choice2->id != -1 && !$choice2->allowStudentType($student->getType()) || $choice3->id != -1 && !$choice3->allowStudentType($student->getType())) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, you cannot apply for the selected RLC. Please contact University Housing if you believe this to be in error.');
         $errorCmd->redirect();
     }
     // Check the lengths of the responses to the short answer questions
     $question0 = $context->get('rlc_question_0');
     $question1 = $context->get('rlc_question_1');
     $question2 = $context->get('rlc_question_2');
     $whySpecific = $context->get('why_specific_communities');
     $strengthsWeaknesses = $context->get('strengths_weaknesses');
     if (str_word_count($whySpecific) > HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Your respose to the question is too long. Please limit your response to ' . HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT . ' words.');
         $errorCmd->redirect();
     }
     if (str_word_count($strengthsWeaknesses) > HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Your respose to the question is too long. Please limit your response to ' . HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT . ' words.');
         $errorCmd->redirect();
     }
     if (str_word_count($question0) > HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Your respose to the first question is too long. Please limit your response to ' . HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT . ' words.');
         $errorCmd->redirect();
     }
     if (str_word_count($question1) > HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Your respose to the second question is too long. Please limit your response to ' . HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT . ' words.');
         $errorCmd->redirect();
     }
     if (str_word_count($question2) > HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Your respose to the third question is too long. Please limit your response to ' . HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT . ' words.');
         $errorCmd->redirect();
     }
     // Check for an existing application and delete it
     $oldApp = HMS_RLC_Application::getApplicationByUsername($student->getUsername(), $term);
     if (isset($oldApp) && $oldApp->id != NULL) {
         //TODO check if the student has already been assigned to an RLC via the old application
         // Delete the old application to make way for this one
         try {
             $oldApp->delete();
         } catch (Exception $e) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, an error occured while attempting to replace your existing Residential Learning Community Application.  If this problem persists please contact University Housing.');
             $errorCmd->redirect();
         }
     }
     // Setup the new application
     $application = new HMS_RLC_Application();
     $application->setUsername($student->getUsername());
     $application->setDateSubmitted(time());
     $application->setFirstChoice($context->get('rlc_first_choice'));
     $application->setSecondChoice($choice2->id > 0 ? $choice2->id : NULL);
     $application->setThirdChoice($choice3->id > 0 ? $choice3->id : NULL);
     $application->setWhySpecificCommunities($context->get('why_specific_communities'));
     $application->setStrengthsWeaknesses($context->get('strengths_weaknesses'));
     $application->setRLCQuestion0($context->get('rlc_question_0'));
     $application->setRLCQuestion1(is_null($context->get('rlc_question_1')) ? '' : $context->get('rlc_question_1'));
     $application->setRLCQuestion2(is_null($context->get('rlc_question_2')) ? '' : $context->get('rlc_question_2'));
     $application->setEntryTerm($context->get('term'));
     $application->setApplicationType(RLC_APP_FRESHMEN);
     try {
         $application->save();
     } catch (Exception $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, an error occured while attempting to submit your application.  If this problem persists please contact University Housing.');
         $errorCmd->redirect();
     }
     # Log that this happened
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_SUBMITTED_RLC_APPLICATION, $student->getUsername());
     # Send the notification email
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     HMS_Email::send_rlc_application_confirmation($student);
     # Show a success message and redirect
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Your Residential Learning Community (RLC) application has been successfully submitted. You should receive a confirmation email (sent to your Appalachian State email account) soon. Notification of your acceptance into an RLC will also be sent to your Appalachian State email account.  Please continue to check your ASU email account regularly.  For more information on the RLC acceptance timeline or frequently asked questions, please visit <a href="http://housing.appstate.edu/rlc" target="_blank">housing.appstate.edu/rlc</a>.');
     $cmd = CommandFactory::getCommand('ShowStudentMenu');
     $cmd->redirect();
 }
Exemplo n.º 20
0
 private function sendRoommateReminderEmails()
 {
     // 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={$this->term}) as foo ON hms_lottery_reservation.asu_username = foo.asu_username\n                        WHERE foo.asu_username IS NULL\n                        AND hms_lottery_reservation.term = {$this->term}\n                        AND hms_lottery_reservation.expires_on > " . $this->now;
     $result = PHPWS_DB::getAll($query);
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     foreach ($result as $row) {
         $student = StudentFactory::getStudentByUsername($row['asu_username'], $this->term);
         $requestor = StudentFactory::getStudentByUsername($row['requestor'], $this->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, $this->academicYear);
         HMS_Activity_Log::log_activity($row['asu_username'], ACTIVITY_LOTTERY_ROOMMATE_REMINDED, UserStatus::getUsername());
     }
 }
 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();
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'WaitingListApplication.php');
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     $term = $context->get('term');
     $errorCmd = CommandFactory::getCommand('ShowOffCampusWaitListApplication');
     $errorCmd->setTerm($term);
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     // Data sanity checking
     $doNotCall = $context->get('do_not_call');
     $areaCode = $context->get('area_code');
     $exchange = $context->get('exchange');
     $number = $context->get('number');
     if (is_null($doNotCall)) {
         // do not call checkbox was not selected, so check the number
         if (is_null($areaCode) || is_null($exchange) || is_null($number)) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'Please provide a cell-phone number or click the checkbox stating that you do not wish to share your number with us.');
             $errorCmd->redirect();
         }
     }
     if (!is_null($doNotCall)) {
         $cellPhone = null;
     } else {
         $cellPhone = $areaCode . $exchange . $number;
     }
     $mealPlan = $context->get('meal_plan');
     $specialNeeds = $context->get('special_needs');
     $physicalDisability = isset($specialNeeds['physical_disability']) ? 1 : 0;
     $psychDisability = isset($specialNeeds['psych_disability']) ? 1 : 0;
     $genderNeed = isset($specialNeeds['gender_need']) ? 1 : 0;
     $medicalNeed = isset($specialNeeds['medical_need']) ? 1 : 0;
     $international = $student->isInternational();
     $application = new WaitingListApplication(0, $term, $student->getBannerId(), $student->getUsername(), $student->getGender(), $student->getType(), $student->getApplicationTerm(), $cellPhone, $mealPlan, $physicalDisability, $psychDisability, $genderNeed, $medicalNeed, $international);
     $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'));
     $application->setEmergencyMedicalCondition($context->get('emergency_medical_condition'));
     $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'));
     try {
         $application->save();
     } catch (Exception $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error saving your application. Please try again or contact the Department of University Housing.');
         $errorCmd->redirect();
     }
     // Log the fact that the entry was saved
     HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_LOTTERY_ENTRY, UserStatus::getUsername());
     // Send a confirmation email
     $year = Term::toString($term) . ' - ' . Term::toString(Term::getNextTerm($term));
     HMS_Email::sendWaitListApplicationConfirmation($student, $year);
     // Show a sucess message and redirect to the main menu
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Your application to the Open Waiting List was submitted successfully.');
     $cmd = CommandFactory::getCommand('ShowStudentMenu');
     $cmd->redirect();
 }
Exemplo n.º 23
0
 public static function sendReportCompleteNotification($username, $reportName)
 {
     $to = $username . TO_DOMAIN;
     $subject = '[hms] Report Complete: ' . $reportName;
     $tpl = array();
     $tpl['REPORT_NAME'] = $reportName;
     HMS_Email::send_template_message($to, $subject, 'email/ReportCompleteNotification.tpl', $tpl);
 }
Exemplo n.º 24
0
 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();
 }
Exemplo n.º 25
0
 private static function emailError($message)
 {
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     //$to = HMSSettings::getUberAdminEmail();
     $to = HMS_Email::get_tech_contacts();
     $tags = array('MESSAGE' => $message);
     HMS_Email::send_template_message($to, '[hms] Uncaught Report Exception', 'email/UncaughtException.tpl', $tags);
 }
 public function execute(CommandContext $context)
 {
     // Check permissions
     if (!Current_User::allow('hms', 'checkin')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to checkin students.');
     }
     // Grab data from JSON source
     $bannerId = filter_input(INPUT_POST, 'bannerId', FILTER_VALIDATE_INT);
     $checkinId = filter_input(INPUT_POST, 'checkinId', FILTER_VALIDATE_INT);
     if (empty($bannerId)) {
         throw new InvalidArgumentException('Missing banner id.');
     }
     if (empty($checkinId)) {
         throw new InvalidArgumentException('Missing checkin id.');
     }
     // Check for key code
     //$keyCode = filter_input(INPUT_POST, 'keyCode',FILTER_SANITIZE_SPECIAL_CHARS);
     $keyCode = filter_input(INPUT_POST, 'keyCode', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/[^\\W]/')));
     $keyReturned = filter_input(INPUT_POST, 'keyReturned', FILTER_VALIDATE_BOOLEAN);
     if (!isset($keyReturned) || !isset($keyCode)) {
         throw new InvalidArgumentException('Missing key return information.');
     }
     if ($keyReturned == "1" && empty($keyCode)) {
         throw new InvalidArgumentException('Missing key code.');
     }
     $properCheckout = filter_input(INPUT_POST, 'properCheckout', FILTER_VALIDATE_BOOLEAN);
     $term = Term::getCurrentTerm();
     $this->term = $term;
     // Lookup the student
     $student = StudentFactory::getStudentByBannerId($bannerId, $term);
     // Get the existing check-in
     $checkin = CheckinFactory::getCheckinById($checkinId);
     // Make sure we found a check-in
     if (is_null($checkin)) {
         /*
         NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, we couldn't find a corresponding check-in for this check-out.");
         $errorCmd = CommandFactory::getCommand('ShowCheckoutForm');
         $errorCmd->setBannerId($bannerId);
         $errorCmd->setHallId($hallId);
         $errorCmd->redirect();
         */
         throw new Exception('Could not find a corresponding checkin.');
     }
     // Create the bed
     $bed = BedFactory::getBedByPersistentId($checkin->getBedPersistentId(), $term);
     // Get the room
     $room = $bed->get_parent();
     /*****
      * Add new damages
      */
     $newDamages = filter_input(INPUT_POST, 'newDamage', FILTER_SANITIZE_SPECIAL_CHARS, FILTER_REQUIRE_ARRAY);
     if (!empty($newDamages)) {
         foreach ($newDamages as $dmg) {
             $this->addDamage($dmg, $room);
         }
     }
     /******
      * Complete the Checkout
      */
     // Set checkout date and user
     $checkin->setCheckoutDate(time());
     $checkin->setCheckoutBy(Current_User::getUsername());
     // Set the checkout code code, if any
     $checkin->setCheckoutKeyCode($keyCode);
     // Improper checkout handling
     if ($properCheckout == "1") {
         $checkin->setImproperCheckout(false);
     } else {
         $checkin->setImproperCheckout(true);
         $improperNote = filter_input(INPUT_POST, 'improperNote', FILTER_SANITIZE_SPECIAL_CHARS);
         // Add damage for improper checkout
         // TODO: Find a better way to handle the magic number for dmg type
         $dmg = array('damage_type' => 105, 'side' => 'both', 'note' => $improperNote, 'residents' => array(array('studentId' => $student->getBannerId(), 'selected' => true)));
         $this->addDamage($dmg, $room);
         // Add the improper checkout note
         $checkin->setImproperCheckoutNote($improperNote);
     }
     if ($keyReturned == "1") {
         $checkin->setKeyNotReturned(false);
     } else {
         $checkin->setKeyNotReturned(true);
         // Add a damage record for key not returned
         // TODO: Find a better way to handle the magic number for dmg type
         $dmg = array('damage_type' => 79, 'side' => 'both', 'note' => 'Key not returned.', 'residents' => array(array('studentId' => $student->getBannerId(), 'selected' => true)));
         $this->addDamage($dmg, $room);
     }
     // Save the check-in
     $checkin->save();
     // Add this to the activity log
     HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_CHECK_OUT, UserStatus::getUsername(), $bed->where_am_i());
     // Generate the RIC
     PHPWS_Core::initModClass('hms', 'InfoCard.php');
     PHPWS_Core::initModClass('hms', 'InfoCardPdfView.php');
     $infoCard = new InfoCard($checkin);
     /*
      * Info card removed per #869
     $infoCardView = new InfoCardPdfView();
     $infoCardView->addInfoCard($infoCard);
     */
     // Send confirmation Email with the RIC form to the student
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     HMS_Email::sendCheckoutConfirmation($student, $infoCard);
     /***** Room Change Request Handling *******/
     // Check if this checkout was part of a room change request
     PHPWS_Core::initModClass('hms', 'RoomChangeRequestFactory.php');
     PHPWS_Core::initModClass('hms', 'RoomChangeParticipantFactory.php');
     $request = RoomChangeRequestFactory::getRequestPendingCheckout($student, $term);
     if (!is_null($request)) {
         $participant = RoomChangeParticipantFactory::getParticipantByRequestStudent($request, $student);
         // Transition to StudentApproved state
         $participant->transitionTo(new ParticipantStateCheckedOut($participant, time(), null, UserStatus::getUsername()));
         // If all the participants are in CheckedOut state, then this room change is complete, so transition it
         if ($request->allParticipantsInState('CheckedOut')) {
             $request->transitionTo(new RoomChangeStateComplete($request, time(), null, UserStatus::getUsername()));
         }
     }
     // Cleanup and redirect
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Checkout successful.');
     NQ::close();
     exit;
 }
 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();
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'LotteryApplication.php');
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     // TODO Use the HousingApplicationFactory class to get all this data
     $term = $context->get('term');
     # Double check that the student is eligible
     if (!HMS_Lottery::determineEligibility(UserStatus::getUsername())) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You are not eligible to re-apply for on-campus housing for this semester.');
         $menuCmd = CommandFactory::getCommand('ShowStudentMenu');
         $menuCmd->redirect();
     }
     $errorCmd = CommandFactory::getCommand('ShowReApplication');
     $errorCmd->setTerm($term);
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     // Data sanity checking
     $doNotCall = $context->get('do_not_call');
     $number = $context->get('number');
     if (is_null($doNotCall)) {
         // do not call checkbox was not selected, so check the number
         if (is_null($number)) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'Please provide a cell-phone number or click the checkbox stating that you do not wish to share your number with us.');
             $errorCmd->redirect();
         }
     }
     if (!is_null($doNotCall)) {
         $cellPhone = null;
     } else {
         $cellPhone = $number;
     }
     $mealPlan = $context->get('meal_plan');
     $specialNeeds = $context->get('special_needs');
     $physicalDisability = isset($specialNeeds['physical_disability']) ? 1 : 0;
     $psychDisability = isset($specialNeeds['psych_disability']) ? 1 : 0;
     $genderNeed = isset($specialNeeds['gender_need']) ? 1 : 0;
     $medicalNeed = isset($specialNeeds['medical_need']) ? 1 : 0;
     /**
      * Special interest housing groups
      */
     // Sororities - If they checked the box, and their pref is APH,
     // then record her sorority choice
     $sororityCheck = $context->get('sorority_check');
     if (isset($sororityCheck) && $context->get('sorority_pref') == 'aph') {
         $sororityPref = $context->get('sorority_drop');
     } else {
         $sororityPref = null;
     }
     // Teaching Fellows, Watauga Global, and Honors
     //$tfPref = ($context->get('tf_pref') == 'with_tf')?1:0;
     $wgPref = $context->get('wg_pref') == 'with_wg' ? 1 : 0;
     $honorsPref = $context->get('honors_pref') == 'with_honors' ? 1 : 0;
     // Learning Community Interest
     $rlcInterest = $context->get('rlc_interest');
     $rlcInterest = isset($rlcInterest) ? 1 : 0;
     // Contract early release
     $earlyRelease = $context->get('early_release');
     if ($earlyRelease == 'no') {
         $earlyRelease = NULL;
     }
     // International
     $international = $student->isInternational();
     $magicWinner = 0;
     // The student's type should always be 'C' (continuing),
     // even if thes student began in the Spring.
     $studentType = 'C';
     /**************************
      * Emergency Contact Info *
      */
     $application = new LotteryApplication(0, $term, $student->getBannerId(), $student->getUsername(), $student->getGender(), $studentType, $student->getApplicationTerm(), $cellPhone, $mealPlan, $physicalDisability, $psychDisability, $genderNeed, $medicalNeed, $international, NULL, $magicWinner, $sororityPref, $wgPref, $honorsPref, $rlcInterest, $earlyRelease);
     $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'));
     $application->setEmergencyMedicalCondition($context->get('emergency_medical_condition'));
     $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'));
     try {
         $application->save();
     } catch (Exception $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error saving your re-application. Please try again or contact the Department of University Housing.');
         $errorCmd->redirect();
     }
     // Log the fact that the entry was saved
     HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_LOTTERY_ENTRY, UserStatus::getUsername());
     // Send email confirmation
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     $year = Term::toString($term) . ' - ' . Term::toString(Term::getNextTerm($term));
     HMS_Email::send_lottery_application_confirmation($student, $year);
     // Show success message
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Your re-application was submitted successfully.');
     // Redirect to the RLC Reapplication form is the student is interested in RLCs, otherwise, show the student menu
     if ($rlcInterest == 1) {
         $cmd = CommandFactory::getCommand('ShowRlcReapplication');
         $cmd->setTerm($term);
     } else {
         $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();
 }
Exemplo n.º 30
0
 public function execute(CommandContext $context)
 {
     // Get input
     $requestId = $context->get('requestId');
     // Get the current term
     $term = Term::getCurrentTerm();
     // Load the request
     $request = RoomChangeRequestFactory::getRequestById($requestId);
     // Load the participants
     $participants = $request->getParticipants();
     // Make sure everyone is checked into their current assignments
     if (!$request->allParticipantsCheckedIn()) {
         // Return the user to the room change request page
         // NB, don't need an error message here because it should already be printed
         // by the RoomChangeParticipantView.
         $cmd = CommandFactory::getCommand('ShowManageRoomChange');
         $cmd->setRequestId($requestId);
         $cmd->redirect();
     }
     // Transition the request to 'Approved'
     $request->transitionTo(new RoomChangeStateApproved($request, time(), null, UserStatus::getUsername()));
     // Remove each participants existing assignment
     foreach ($participants as $participant) {
         $bannerId = $participant->getBannerId();
         // Lookup the student
         $student = StudentFactory::getStudentByBannerId($bannerId, $term);
         // Save student object for later
         $this->students[$bannerId] = $student;
         // Save student's current assignment reason for later re-use
         $assignment = HMS_Assignment::getAssignmentByBannerId($bannerId, $term);
         //TODO - Student might not be assigned!!
         $this->assignmentReasons[$bannerId] = $assignment->getReason();
         // Remove existing assignment
         // TODO: Don't hard code refund percentage
         HMS_Assignment::unassignStudent($student, $term, 'Room Change Request Approved', UNASSIGN_CHANGE, 100);
     }
     // Create new assignments for each participant
     foreach ($participants as $participant) {
         // Grab the student object which was previously saved
         $student = $this->students[$participant->getBannerId()];
         // Create each new assignment
         HMS_Assignment::assignStudent($student, $term, null, $participant->getToBed(), BANNER_MEAL_STD, 'Room Change Approved', FALSE, $this->assignmentReasons[$bannerId]);
         // Release bed reservation
         $bed = new HMS_Bed($participant->getToBed());
         $bed->clearRoomChangeReserved();
         $bed->save();
     }
     // Transition each participant to 'In Process'
     foreach ($participants as $participant) {
         $participant->transitionTo(new ParticipantStateInProcess($participant, time(), null, UserStatus::getUsername()));
         // TODO: Send notifications
     }
     // Notify everyone that they can do the move
     HMS_Email::sendRoomChangeInProcessNotice($request);
     // Notify roommates that their circumstances are going to change
     foreach ($request->getParticipants() as $p) {
         $student = $this->students[$p->getBannerId()];
         // New Roommate
         $newbed = new HMS_Bed($p->getToBed());
         $newroom = $newbed->get_parent();
         foreach ($newroom->get_assignees() as $a) {
             if ($a instanceof Student && $a->getBannerID() != $p->getBannerID()) {
                 HMS_Email::sendRoomChangeApprovedNewRoommateNotice($a, $student);
             }
         }
         // Old Roommate
         $oldbed = new HMS_Bed($p->getFromBed());
         $oldroom = $oldbed->get_parent();
         foreach ($oldroom->get_assignees() as $a) {
             if ($a instanceof Student && $a->getBannerID() != $p->getBannerID()) {
                 HMS_Email::sendRoomChangeApprovedOldRoommateNotice($a, $student);
             }
         }
     }
     // Return the user to the room change request page
     $cmd = CommandFactory::getCommand('ShowManageRoomChange');
     $cmd->setRequestId($requestId);
     $cmd->redirect();
 }