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 execute(CommandContext $context) { // Get input $requestId = $context->get('requestId'); $participantId = $context->get('participantId'); // Command for showing the request, redirected to on success/error $cmd = CommandFactory::getCommand('ShowManageRoomChange'); $cmd->setRequestId($requestId); // Load the request $request = RoomChangeRequestFactory::getRequestById($requestId); // Load the participant $participant = RoomChangeParticipantFactory::getParticipantById($participantId); // Load the Student $student = StudentFactory::getStudentByBannerId($participant->getBannerId(), $request->getTerm()); // Check permissions. Must be the participant or an admin if (UserStatus::getUsername() != $student->getUsername() && !Current_User::allow('hms', 'admin_approve_room_change')) { throw new PermissionException('You do not have permission to appove this room change.'); } // Check for CAPTCHA if this is the student; admins don't need a CAPTCHA $captchaResult = Captcha::verify(true); if (UserStatus::getUsername() == $student->getUsername() && $captchaResult === false) { // Failed the captcha NQ::simple('hms', hms\NotificationView::ERROR, "You didn't type the magic words correctly. Please try again."); $cmd = CommandFactory::getCommand('ShowRoomChangeRequestApproval'); $cmd->redirect(); } // If there was a captcha, then log the activity if ($captchaResult !== false) { HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_ROOM_CHANGE_AGREED, UserStatus::getUsername(FALSE), 'Request id: ' . $requestId . ' Captcha: ' . $captchaResult); } // Transition to StudentApproved state $participant->transitionTo(new ParticipantStateStudentApproved($participant, time(), null, UserStatus::getUsername())); // If all students have approved, notify RDs if ($request->isApprovedByAllParticipants()) { HMS_Email::sendRoomChangeCurrRDNotice($request); } // If the student is logged in, redirect to the main menu, other wise go back to the room change management view if (UserStatus::getUsername() == $student->getUsername()) { NQ::simple('hms', hms\NotificationView::SUCCESS, 'You have agreed to the room change request. You will be notified by email when the reqeust is approved or denied.'); $menuCmd = CommandFactory::getCommand('ShowStudentMenu'); $menuCmd->redirect(); } else { $cmd->redirect(); } }
public function show() { PHPWS_Core::initModClass('hms', 'RoomChangeParticipantFactory.php'); $tpl = array(); PHPWS_Core::initModClass('hms', 'HMS_Util.php'); $tpl['DATES'] = HMS_Util::getPrettyDateRange($this->startDate, $this->endDate); if (time() < $this->startDate) { // too early $tpl['BEGIN_DEADLINE'] = HMS_Util::getFriendlyDate($this->startDate); $tpl['ICON'] = FEATURE_NOTYET_ICON; } else { if (time() > $this->endDate) { // too late $tpl['ICON'] = FEATURE_LOCKED_ICON; $tpl['END_DEADLINE'] = HMS_Util::getFriendlyDate($this->endDate); } else { if (is_null($this->assignment)) { // Not assigned anywhere $tpl['ICON'] = FEATURE_NOTYET_ICON; $tpl['NOT_ASSIGNED'] = ""; } else { if (!is_null($this->changeRequest) && !$this->changeRequest->getState() instanceof CompletedChangeRequest && !$this->changeRequest->getState() instanceof DeniedChangeRequest) { // has pending request // Currently has a request open, so check to see if this student has approved it $participant = RoomChangeParticipantFactory::getParticipantByRequestStudent($this->changeRequest, $this->student); $state = $participant->getState(); // If this student needs to approve their part of this request if ($state instanceof ParticipantStateNew) { $approvalCmd = CommandFactory::getCommand('ShowRoomChangeRequestApproval'); $tpl['APPROVAL_CMD'] = $approvalCmd->getLink('View the request'); } else { // Request if pending, but this student doesn't need to do anything $tpl['PENDING'] = ""; } $tpl['ICON'] = FEATURE_OPEN_ICON; } else { $tpl['ICON'] = FEATURE_OPEN_ICON; $changeReqCmd = CommandFactory::getCommand('ShowRoomChangeRequestForm'); $tpl['NEW_REQUEST'] = $changeReqCmd->getLink('request a room change'); } } } } return PHPWS_Template::process($tpl, 'hms', 'student/menuBlocks/roomChangeMenuBlock.tpl'); }
public function execute(CommandContext $context) { // Get input $requestId = $context->get('requestId'); $participantId = $context->get('participantId'); // Load the request $request = RoomChangeRequestFactory::getRequestById($requestId); // Load the participant $participant = RoomChangeParticipantFactory::getParticipantById($participantId); // Load the Student $student = StudentFactory::getStudentByBannerId($participant->getBannerId(), $request->getTerm()); // Check permissions. Must be the participant or an admin if (UserStatus::getUsername() != $student->getUsername() && !Current_User::allow('hms', 'admin_approve_room_change')) { throw new PermissionException('You do not have permission to decline this room change.'); } // Check for CAPTCHA if this is the student; admins don't need a CAPTCHA $captchaResult = Captcha::verify(true); if ($captchaResult === false) { // Failed the captcha NQ::simple('hms', hms\NotificationView::ERROR, "You didn't type the magic words correctly. Please try again."); $cmd = CommandFactory::getCommand('ShowRoomChangeRequestApproval'); $cmd->redirect(); } HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_ROOM_CHANGE_DECLINE, UserStatus::getUsername(FALSE), 'Request id: ' . $requestId . ' Captcha: ' . $captchaResult); // Transition request to cancelled status $request->transitionTo(new RoomChangeStateCancelled($request, time(), null, UserStatus::getUsername())); // Transition all participants to cancelled // TODO... Do this in the cancelled transition? $participants = $request->getParticipants(); foreach ($participants as $p) { $p->transitionTo(new ParticipantStateCancelled($p, time(), null, UserStatus::getUsername())); } // TODO Notify everyone that the request was cancelled NQ::simple('hms', hms\NotificationView::SUCCESS, 'You have declined the room change request.'); $menuCmd = CommandFactory::getCommand('ShowStudentMenu'); $menuCmd->redirect(); }
public function execute(CommandContext $context) { // 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 getParticipants() { PHPWS_Core::initModClass('hms', 'RoomChangeParticipantFactory.php'); return RoomChangeParticipantFactory::getParticipantsByRequest($this); }
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; }