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 show()
 {
     $excess_limit = 3;
     // Number of rows to show by default
     $count = 0;
     $tpl = array();
     $historyRows = array();
     $excessRows = array();
     $historyArray = $this->assignmentHistory->getHistory();
     foreach ($historyArray as $ah) {
         $row = array();
         if (defined($ah->assigned_reason)) {
             $assignedReason = constant($ah->assigned_reason);
             // for pretty text purposes
         } else {
             $assignedReason = $ah->assigned_reason;
         }
         if (defined($ah->removed_reason)) {
             $removedReason = constant($ah->removed_reason);
             // for pretty text purposes
         } else {
             $removedReason = $ah->removed_reason;
         }
         if (!is_null($ah->assigned_on)) {
             $assignedOn = date('M jS, Y \\a\\t g:ia', $ah->assigned_on);
         }
         if (!is_null($ah->removed_on)) {
             $removedOn = date('M jS, Y \\a\\t g:ia', $ah->removed_on);
         }
         $bed = new HMS_Bed($ah->getBedId());
         $row['room'] = $bed->where_am_i();
         $row['term'] = Term::toString($ah->term);
         // Combine for ease of view
         if (isset($ah->assigned_reason)) {
             $row['assignments'] = '<em>' . $assignedReason . '</em>' . ' by ' . $ah->assigned_by . '<br /><span style="font-size:11px;color:#7C7C7C;">on ' . $assignedOn . '</span>';
         } else {
             $row['assignments'] = '<em class="text-muted">None</em>';
         }
         if (isset($ah->removed_reason)) {
             $row['unassignments'] = '<em>' . $removedReason . '</em>' . ' by ' . $ah->removed_by . '<br /><span style="font-size:11px;color:#7C7C7C;">on ' . $removedOn . '</span>';
         } else {
             $row['unassignments'] = '<em class="text-muted">None</em>';
         }
         if ($count++ < $excess_limit) {
             $historyRows[] = $row;
         } else {
             $excessRows[] = $row;
         }
     }
     $tpl['HISTORY'] = $historyRows;
     $tpl['EXTRA_HISTORY'] = $excessRows;
     if (sizeof($historyArray) > $excess_limit) {
         $tpl['SHOW_MORE'] = "[ <a id='showMoreLink'>show more</a> ]";
     }
     return PHPWS_Template::process($tpl, 'hms', 'admin/StudentAssignmentHistoryView.tpl');
 }
예제 #3
0
 public function __construct(Student $student, HMS_Bed $bed, $term, $checkinBy, $keyCode)
 {
     $this->setBannerId($student->getBannerId());
     $this->setBedPersistentId($bed->getPersistentId());
     $this->setBedId($bed->getId());
     $this->setTerm($term);
     $this->setRoomId($bed->get_parent()->getId());
     $this->setCheckinDate(time());
     $this->setCheckinby($checkinBy);
     $this->setKeyCode($keyCode);
 }
예제 #4
0
 public function show()
 {
     $term = Term::getCurrentTerm();
     $student = StudentFactory::getStudentByBannerId($this->checkin->getBannerId(), $term);
     $bed = new HMS_Bed($this->checkin->getBedId());
     $tpl = array();
     $tpl['NAME'] = $student->getName();
     $tpl['ASSIGNMENT'] = $bed->where_am_i();
     $pdfCmd = CommandFactory::getCommand('GenerateInfoCard');
     $pdfCmd->setCheckinId($this->checkin->getId());
     $tpl['INFO_CARD_LINK'] = $pdfCmd->getLink('Resident Information Card', '_blank');
     return PHPWS_Template::process($tpl, 'hms', 'admin/checkinComplete.tpl');
 }
 public function show()
 {
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Util.php');
     # Get the roommate request record from the database
     $bed = new HMS_Bed($this->request['bed_id']);
     $room = $bed->get_parent();
     $tpl = array();
     $requestor = StudentFactory::getStudentByUsername($this->request['requestor'], $this->term);
     $tpl['REQUESTOR'] = $requestor->getName();
     $tpl['HALL_ROOM'] = $bed->where_am_i();
     # List all the students which will be assigned and their beds
     $beds = $room->get_beds();
     foreach ($beds as $bed) {
         $bed_row = array();
         # Check for an assignment
         $bed->loadAssignment();
         # Check for a reservation
         $reservation = $bed->get_lottery_reservation_info();
         $bed_row['BEDROOM_LETTER'] = $bed->bedroom_label;
         if ($bed->_curr_assignment != NULL) {
             # Bed is assigned
             $roommate = StudentFactory::getStudentByUsername($bed->_curr_assignment->asu_username, $this->term);
             $bed_row['TEXT'] = $roommate->getName();
         } else {
             if ($reservation != NULL) {
                 # Bed is reserved
                 $roommate = StudentFactory::getStudentByUsername($reservation['asu_username'], $this->term);
                 $bed_row['TEXT'] = $roommate->getName() . ' (reserved)';
             } else {
                 $bed_row['TEXT'] = 'Empty';
             }
         }
         $tpl['beds'][] = $bed_row;
     }
     $tpl['MEAL_PLAN'] = HMS_Util::formatMealOption($this->mealPlan);
     PHPWS_Core::initCoreClass('Captcha.php');
     $tpl['CAPTCHA'] = Captcha::get();
     $submitCmd = CommandFactory::getCommand('LotteryConfirmRoommateRequest');
     $submitCmd->setRequestId($this->request['id']);
     $submitCmd->setMealPlan($this->mealPlan);
     $form = new PHPWS_Form();
     $submitCmd->initForm($form);
     $form->addSubmit('confirm', 'Confirm Roommate');
     $form->mergeTemplate($tpl);
     $tpl = $form->getTemplate();
     Layout::addPageTitle("Lottery Confirm Roommate");
     return PHPWS_Template::process($tpl, 'hms', 'student/lottery_confirm_roommate_request.tpl');
 }
예제 #6
0
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'RoomDamageFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     $bedId = $context->get('bed_id');
     $bed = new HMS_Bed($bedId);
     $room = $bed->get_parent();
     // Get the damages for this student's room
     $damages = RoomDamageFactory::getDamagesByRoom($room);
     if ($damages == null) {
         $context->setContent(json_encode(array()));
         return;
     }
     $context->setContent(json_encode($damages));
 }
예제 #7
0
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'bed_structure')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to remove a bed.');
     }
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     $viewCmd = CommandFactory::getCommand('EditRoomView');
     $viewCmd->setRoomId($context->get('roomId'));
     $bedId = $context->get('bedId');
     $roomId = $context->get('roomId');
     if (!isset($roomId)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Missing room ID.');
         $viewCmd->redirect();
     }
     if (!isset($bedId)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Missing bed ID.');
         $viewCmd->redirect();
     }
     # Try to delete the bed
     try {
         HMS_Bed::deleteBed($bedId);
     } catch (Exception $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error deleting the bed: ' . $e->getMessage());
         $viewCmd->redirect();
     }
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Bed successfully deleted.');
     $viewCmd->redirect();
 }
예제 #8
0
 public static function getCheckinByBed(Student $student, HMS_Bed $bed)
 {
     $db = new PHPWS_DB('hms_checkin');
     $db->addWhere('banner_id', $student->getBannerId());
     //$db->addWhere('term', $term);
     //$db->addWhere('bed_id', $bed->getId());
     $db->addWhere('bed_persistent_id', $bed->getPersistentId());
     $checkin = new RestoredCheckin();
     $result = $db->loadObject($checkin);
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     if ($checkin->getId() == null) {
         return null;
     }
     return $checkin;
 }
예제 #9
0
 public function __construct($id = null, $type = null, Student $student = null, $term = null, HMS_Residence_Hall $hall = null, HMS_Bed $bed = null, $mealPlan = null, $mealCode = null, $percentRefund = null)
 {
     if (!is_null($id) && $id != 0) {
         $this->load();
         return;
     }
     if (is_null($type)) {
         return;
     }
     $this->type = $type;
     $this->asu_username = strtolower($student->getUsername());
     $this->term = $term;
     $this->building_code = $hall->getBannerBuildingCode();
     $this->bed_code = $bed->getBannerId();
     $this->meal_plan = $mealPlan;
     $this->meal_code = $mealCode;
     $this->percent_refund = $percentRefund;
 }
예제 #10
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();
 }
예제 #11
0
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'bed_structure')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to add a bed.');
     }
     PHPWS_Core::initModClass('hms', 'HMS_Room.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     $errorCmd = CommandFactory::getCommand('ShowAddBed');
     $errorCmd->setRoomId($context->get('roomId'));
     $errorCmd->setBedLetter($context->get('bed_letter'));
     $errorCmd->setBedroomLabel($context->get('bedroom_label'));
     $errorCmd->setBannerId($context->get('banner_id'));
     $viewCmd = CommandFactory::getCommand('EditRoomView');
     $viewCmd->setRoomId($context->get('roomId'));
     $bedLetter = $context->get('bed_letter');
     $bedroomLabel = $context->get('bedroom_label');
     $bannerId = $context->get('banner_id');
     $roomId = $context->get('roomId');
     $phoneNumber = $context->get('phone_number');
     if (!isset($bedLetter)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You must enter a bed letter.');
         $errorCmd->redirect();
     }
     if (!isset($bedroomLabel)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You must enter a bedroom label.');
         $errorCmd->redirect();
     }
     if (!isset($bannerId)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You must enter a banner ID.');
         $errorCmd->redirect();
     }
     if (!isset($roomId)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Missing room ID.');
         $errorCmd->redirect();
     }
     $raBed = $context->Get('ra') == 1 ? 1 : 0;
     $raRoommate = $context->get('ra_roommate') == 1 ? 1 : 0;
     $intlReserved = $context->get('international_reserved') == 1 ? 1 : 0;
     $room = new HMS_Room($roomId);
     if (is_null($room)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Could not create bed. Invalid room.');
         $errorCmd->redirect();
     }
     $term = $room->term;
     $persistentId = uniqid();
     # Try to create the bed
     try {
         HMS_Bed::addBed($roomId, $term, $bedLetter, $bedroomLabel, $phoneNumber, $bannerId, $raRoommate, $intlReserved, $raBed, $persistentId);
     } catch (Exception $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error creating the bed: ' . $e->getMessage());
         $errorCmd->redirect();
     }
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Bed added successfully.');
     $viewCmd->redirect();
 }
 public function execute(CommandContext $context)
 {
     try {
         if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'assign_by_floor')) {
             PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
             throw new PermissionException('You do not have permission to assign by floor!');
         }
         $bed = new HMS_Bed($context->get('bed_id'));
         $bed->term = Term::getSelectedTerm();
         if (!$bed->loadAssignment() || is_null($bed->_curr_assignment)) {
             $output = array('username' => '', 'fullname' => '', 'profile_link' => '');
         } else {
             $student = StudentFactory::getStudentByUsername($bed->_curr_assignment->asu_username, Term::getSelectedTerm());
             $output = array('username' => $student->getUsername(), 'fullname' => $student->getFullName(), 'profile_link' => $student->getProfileLink());
         }
     } catch (Exception $e) {
         $output = array('username' => $e->getMessage(), 'fullname' => 'Error', 'profile_link' => '<b style="color: red;">Error</b>');
     }
     echo json_encode($output);
     exit;
 }
 public function show()
 {
     $approveCmd = CommandFactory::getCommand('RoomChangeStudentApprove');
     $approveCmd->setParticipantId($this->thisParticipant->getId());
     $approveCmd->setRequestId($this->request->getId());
     $declineCmd = CommandFactory::getCommand('RoomChangeStudentDecline');
     $declineCmd->setParticipantId($this->thisParticipant->getId());
     $declineCmd->setRequestId($this->request->getId());
     $form = new PHPWS_Form('roomchange_student_approve');
     $form->addHidden('foo', 'bar');
     $tpl = $form->getTemplate();
     $tpl['APPROVE_URI'] = $approveCmd->getURI();
     $tpl['DECLINE_URI'] = $declineCmd->getURI();
     $requestor = StudentFactory::getStudentByUsername($this->request->getState()->getCommittedBy(), $this->term);
     $tpl['REQUESTOR'] = $requestor->getName();
     // Build the table showing who is moving from/to which beds
     $participantRows = array();
     foreach ($this->participants as $p) {
         $row = array();
         $student = StudentFactory::getStudentByBannerId($p->getBannerId(), $this->term);
         $row['NAME'] = $student->getName();
         // If this participant is the person logged in, bold their name
         if ($student->getBannerId() == $this->thisParticipant->getBannerId()) {
             $row['STRONG_STYLE'] = 'success';
         } else {
             $row['STRONG_STYLE'] = '';
         }
         $fromBed = new HMS_Bed($p->getFromBed());
         $toBed = new HMS_Bed($p->getToBed());
         $row['FROM_BED'] = $fromBed->where_am_i();
         $row['TO_BED'] = $toBed->where_am_i();
         $participantRows[] = $row;
     }
     $tpl['PARTICIPANTS'] = $participantRows;
     PHPWS_Core::initCoreClass('Captcha.php');
     $tpl['CAPTCHA'] = Captcha::get();
     return PHPWS_Template::process($tpl, 'hms', 'student/roomChangeRequestStudentApprove.tpl');
 }
예제 #14
0
 /**
  * Queues a Remove Assignment
  *
  * NOTE: If the queue contains a Create Assignment for the same
  * user to the same room, this will NOT queue a room assignment,
  * but rather will delete the original assignment, UNLESS the
  * $force_queue flag is set.  The $force_queue flag being true will
  * queue a removal no matter what.
  *
  * MORE NOTE: If this requires immediate processing because banner
  * commits are enabled, the it will be sent straight to Banner,
  * and so the force_queue flag will be ignored.
  */
 public static function queueRemoveAssignment(Student $student, $term, HMS_Residence_Hall $hall, HMS_Bed $bed, $refund)
 {
     $entry = new BannerQueueItem(0, BANNER_QUEUE_REMOVAL, $student, $term, $hall, $bed, null, null, $refund);
     if (BannerQueue::processImmediately($term)) {
         return $entry->process();
     }
     // Otherwise, look for an corresponding assignment
     $db = new PHPWS_DB('hms_banner_queue');
     $db->addWhere('type', BANNER_QUEUE_ASSIGNMENT);
     $db->addWhere('asu_username', $student->getUsername());
     $db->addWhere('building_code', $hall->getBannerBuildingCode());
     $db->addWhere('bed_code', $bed->getBannerId());
     $db->addWhere('term', $term);
     $result = $db->count();
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     if ($result == 0) {
         return $entry->save();
     } else {
         return $db->delete();
     }
 }
예제 #15
0
 public function show()
 {
     $historyRows = array();
     foreach ($this->checkins as $checkin) {
         $row = array();
         $bed = new HMS_Bed($checkin->getBedId());
         $row['room'] = $bed->where_am_i();
         $row['term'] = Term::toString($checkin->getTerm());
         $row['checkin'] = date("M j, Y g:i:sa", $checkin->getCheckinDate());
         $checkoutDate = $checkin->getCheckoutDate();
         if (isset($checkoutDate)) {
             $row['checkout'] = date("M j, Y g:i:sa", $checkoutDate);
         } else {
             $row['checkout'] = '';
         }
         $ricCommand = CommandFactory::getCommand('GenerateInfoCard');
         $ricCommand->setCheckinId($checkin->getId());
         $row['action'] = $ricCommand->getLink('Get RIC');
         $historyRows[] = $row;
     }
     $tpl = array();
     $tpl['HISTORY'] = $historyRows;
     return PHPWS_Template::process($tpl, 'hms', 'admin/StudentCheckinHistoryView.tpl');
 }
예제 #16
0
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'bed_view')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to view beds.');
     }
     // Check for a bed ID
     $bedId = $context->get('bed');
     if (!isset($bedId)) {
         throw new InvalidArgumentException('Missing bed ID.');
     }
     $bed = new HMS_Bed($bedId);
     if ($bed->term != Term::getSelectedTerm()) {
         $bedCmd = CommandFactory::getCommand('SelectBed');
         $bedCmd->setTitle('Edit a Bed');
         $bedCmd->setOnSelectCmd(CommandFactory::getCommand('EditBedView'));
         $bedCmd->redirect();
     }
     $room = $bed->get_parent();
     $floor = $room->get_parent();
     $hall = $floor->get_parent();
     $bedView = new BedView($hall, $floor, $room, $bed);
     $context->setContent($bedView->show());
 }
예제 #17
0
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'bed_attributes')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to edit beds.');
     }
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     $bedId = $context->get('bedId');
     $viewCmd = CommandFactory::getCommand('EditBedView');
     $viewCmd->setBedId($bedId);
     // Check that the Banner bed ID is valid (five digits)
     $bannerBedId = trim($context->get('banner_id'));
     if (!is_numeric($bannerBedId) || !preg_match("/\\d{5}/", $bannerBedId)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid Banner bed ID. No changes were saved.');
         $viewCmd->redirect();
     }
     # Create the bed object given the bed_id
     $bed = new HMS_Bed($bedId);
     if (!$bed) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid bed.');
         $viewCmd->redirect();
     }
     $bed->bedroom_label = $context->get('bedroom_label');
     $bed->phone_number = $context->get('phone_number');
     $bed->banner_id = $context->get('banner_id');
     $context->get('ra_roommate') == 1 ? $bed->ra_roommate = 1 : ($bed->ra_roommate = 0);
     $context->get('international_reserved') == 1 ? $bed->international_reserved = 1 : ($bed->international_reserved = 0);
     $context->get('ra') == 1 ? $bed->ra = 1 : ($bed->ra = 0);
     $result = $bed->save();
     if (!$result || PHPWS_Error::logIfError($result)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Error: There was a problem while saving the bed. No changes were made');
         $viewCmd->redirect();
     }
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'The room was updated successfully.');
     $viewCmd->redirect();
 }
예제 #18
0
 public static function deleteBed($bedId)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'bed_structure')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to delete a bed.');
     }
     if (!isset($bedId)) {
         throw new InvalidArgumentException('Invalid bed id.');
     }
     // Create the bed object
     $bed = new HMS_Bed($bedId);
     // Make sure the bed isn't assigned to anyone
     $bed->loadAssignment();
     if ($bed->_curr_assignment != NULL) {
         PHPWS_Core::initModClass('hms', 'exception/HallStructureException.php');
         throw new HallStructureException('A student is currently assigned to that bed and therefore it cannot deleted.');
     }
     try {
         $bed->delete();
     } catch (DatabaseException $e) {
         throw $e;
     }
     return true;
 }
예제 #19
0
 /**
  * Sends everyone involved in a room change notice when it is fully approved and
  * can happen in the real world.  Note this is a little different than the other
  * ones because it does the looping itself and sends multiple messages.
  *
  * @param $r RoomChangeRequest The Room Change Request that is in process
  * TODO: Add to/from bed for each participant
  */
 public static function sendRoomChangeInProcessNotice(RoomChangeRequest $r)
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     $subject = 'Room Change Approved!';
     $template = 'email/roomChangeApprovalNotice.tpl';
     $tags = array('PARTICIPANTS' => array());
     $recipients = array();
     foreach ($r->getParticipants() as $p) {
         $student = Studentfactory::getStudentByBannerID($p->getBannerID(), $r->getTerm());
         $current = new HMS_Bed($p->getFromBed());
         $future = new HMS_Bed($p->getToBed());
         $recipients[] = $student;
         $tags['PARTICIPANTS'][] = array('NAME' => $student->getName(), 'CURRENT_LOCATION' => $current->where_am_i(), 'FUTURE_LOCATION' => $future->where_am_i());
     }
     foreach ($r->getAllPotentialApprovers() as $a) {
         $recipients[] = array($a . TO_DOMAIN => '');
     }
     $message = self::makeSwiftmailMessage(null, $subject, $tags, $template);
     foreach ($recipients as $r) {
         if ($r instanceof Student) {
             $message->setTo($r->getUsername() . TO_DOMAIN);
         } else {
             $message->setTo($r);
         }
         self::sendSwiftmailMessage($message);
     }
 }
 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();
 }
예제 #22
0
 /**
  * @see View::show()
  */
 public function show()
 {
     $jsParams = array('LINK_SELECT' => '#addDamageLink');
     javascript('addRoomDamage', $jsParams, 'mod/hms/');
     // Drop down enhancements for room damage dialog
     javascript('chosen', null, 'mod/hms/');
     /*** Header Info ***/
     $tpl = array();
     $tpl['TERM'] = Term::getPrintableSelectedTerm();
     $tpl['HALL_NAME'] = $this->hall->getLink();
     $tpl['FLOOR_NUMBER'] = $this->floor->getLink('Floor');
     /*** Page Title ***/
     $tpl['ROOM'] = $this->room->getRoomNumber();
     /*** Room Attributes Labels ***/
     if ($this->room->isOffline()) {
         $tpl['OFFLINE_ATTRIB'] = 'Offline';
     }
     if ($this->room->isReserved()) {
         $tpl['RESERVED_ATTRIB'] = 'Reserved';
     }
     if ($this->room->isRa()) {
         $tpl['RA_ATTRIB'] = 'RA';
     }
     if ($this->room->isPrivate()) {
         $tpl['PRIVATE_ATTRIB'] = 'Private';
     }
     if ($this->room->isOverflow()) {
         $tpl['OVERFLOW_ATTRIB'] = 'Overflow';
     }
     if ($this->room->isParlor()) {
         $tpl['PARLOR_ATTRIB'] = 'Parlor';
     }
     if ($this->room->isADA()) {
         $tpl['ADA_ATTRIB'] = 'ADA';
     }
     if ($this->room->isHearingImpaired()) {
         $tpl['HEARING_ATTRIB'] = 'Hearing Impaired';
     }
     if ($this->room->bathEnSuite()) {
         $tpl['BATHENSUITE_ATTRIB'] = 'Bath en Suite';
     }
     $number_of_assignees = $this->room->get_number_of_assignees();
     $tpl['NUMBER_OF_BEDS'] = $this->room->get_number_of_beds();
     $tpl['NUMBER_OF_ASSIGNEES'] = $number_of_assignees;
     $form = new PHPWS_Form();
     $submitCmd = CommandFactory::getCommand('EditRoom');
     $submitCmd->setRoomId($this->room->id);
     $submitCmd->initForm($form);
     $form->addText('room_number', $this->room->getRoomNumber());
     $form->setLabel('room_number', 'Room Number');
     $form->addCssClass('room_number', 'form-control');
     /*** Room Gender ***/
     if ($number_of_assignees == 0) {
         // Room is empty, show the drop down so the user can change the gender
         $roomGenders = array(FEMALE => FEMALE_DESC, MALE => MALE_DESC, AUTO => AUTO_DESC);
         // Check if the user is allowed to set rooms to co-ed, if so add Co-ed to the drop down
         if (Current_User::allow('hms', 'coed_rooms')) {
             $roomGenders[COED] = COED_DESC;
         }
         $form->addDropBox('gender_type', $roomGenders);
         $form->setMatch('gender_type', $this->room->gender_type);
         $form->addCssClass('gender_type', 'form-control');
     } else {
         // Room is not empty so just show the gender (no drop down)
         $tpl['GENDER_MESSAGE'] = HMS_Util::formatGender($this->room->getGender());
         // Add a hidden variable for 'gender_type' so it will be defined upon submission
         $form->addHidden('gender_type', $this->room->gender_type);
         // Show the reason the gender could not be changed.
         if ($number_of_assignees != 0) {
             $tpl['GENDER_REASON'] = 'Remove occupants to change room gender.';
         }
     }
     //Always show the option to set the default gender
     $form->addDropBox('default_gender', array(FEMALE => FEMALE_DESC, MALE => MALE_DESC, AUTO => AUTO_DESC));
     $form->setLabel('default_gender', 'Default Gender');
     $form->setMatch('default_gender', $this->room->default_gender);
     $form->addCssClass('default_gender', 'form-control');
     $form->addDropBox('rlc_reserved', array("0" => "Choose RLC") + RlcFactory::getRlcList($this->room->getTerm()));
     $form->setLabel('rlc_reserved', 'Reserved for RLC');
     $form->setMatch('rlc_reserved', $this->room->getReservedRlcId());
     $form->addCssClass('rlc_reserved', 'form-control');
     $form->addCheck('offline', 1);
     $form->setLabel('offline', 'Offline');
     $form->setMatch('offline', $this->room->isOffline());
     $form->addCheck('reserved', 1);
     $form->setLabel('reserved', 'Reserved');
     $form->setMatch('reserved', $this->room->isReserved());
     $form->addCheck('ra', 1);
     $form->setLabel('ra', 'Reserved for RA');
     $form->setMatch('ra', $this->room->isRa());
     $form->addCheck('private', 1);
     $form->setLabel('private', 'Private');
     $form->setMatch('private', $this->room->isPrivate());
     $form->addCheck('overflow', 1);
     $form->setLabel('overflow', 'Overflow');
     $form->setMatch('overflow', $this->room->isOverflow());
     $form->addCheck('parlor', 1);
     $form->setLabel('parlor', 'Parlor');
     $form->setMatch('parlor', $this->room->isParlor());
     $form->addCheck('ada', 1);
     $form->setLabel('ada', 'ADA');
     $form->setMatch('ada', $this->room->isAda());
     $form->addCheck('hearing_impaired', 1);
     $form->setLabel('hearing_impaired', 'Hearing Impaired');
     $form->setMatch('hearing_impaired', $this->room->isHearingImpaired());
     $form->addCheck('bath_en_suite', 1);
     $form->setLabel('bath_en_suite', 'Bath en Suite');
     $form->setMatch('bath_en_suite', $this->room->bathEnSuite());
     $form->addSubmit('submit', 'Submit');
     // Assignment pagers
     $tpl['BED_PAGER'] = HMS_Bed::bed_pager_by_room($this->room->id);
     // if the user has permission to view the form but not edit it then
     // disable it
     if (Current_User::allow('hms', 'room_view') && !Current_User::allow('hms', 'room_attributes') && !Current_User::allow('hms', 'room_structure')) {
         $form_vars = get_object_vars($form);
         $elements = $form_vars['_elements'];
         foreach ($elements as $element => $value) {
             $form->setDisabled($element);
         }
     }
     $form->mergeTemplate($tpl);
     $tpl = $form->getTemplate();
     $reasonsList = HMS_Room::listReserveReasons();
     $tpl['ATHLETICS_OPTIONS'] = $reasonsList['Athletics'];
     $tpl['SPECIAL_NEEDS_OPTIONS'] = $reasonsList['SpecialNeeds'];
     $tpl['SCHOLARS_OPTIONS'] = $reasonsList['ScholarsOrganizations'];
     $tpl['MISC_OPTIONS'] = $reasonsList['Miscellaneous'];
     if ($this->room->getReservedReason() == "") {
         $tpl['CURRENT_REASON'] = 'none';
     } else {
         $tpl['CURRENT_REASON'] = $this->room->getReservedReason();
     }
     $tpl['RESERVED_NOTES'] = $this->room->getReservedNotes();
     Layout::addPageTitle("Edit Room");
     $tpl['ROOM_DAMAGE_LIST'] = $this->roomDamagePager();
     if (Current_User::allow('hms', 'add_room_dmg')) {
         $dmgCmd = CommandFactory::getCommand('ShowAddRoomDamage');
         $dmgCmd->setRoom($this->room);
         $tpl['ADD_DAMAGE_URI'] = $dmgCmd->getURI();
     }
     return PHPWS_Template::process($tpl, 'hms', 'admin/edit_room.tpl');
 }
예제 #23
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();
 }
예제 #24
0
 public static function deleteRoom($roomId)
 {
     if (!Current_User::allow('hms', 'room_structure')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to delete a room.');
     }
     // check that we're not about to do something stupid
     if (!isset($roomId)) {
         throw new InvalidArgumentException('Invalid room id.');
     }
     $room = new HMS_Room($roomId);
     // make sure there isn't an assignment
     if ($room->get_number_of_assignees() != 0) {
         PHPWS_Core::initModClass('hms', 'exception/HallStructureException.php');
         throw new HallStructureException('One or more students are currently assigned to that room and therefore it cannot deleted.');
     }
     // delete any beds
     try {
         if ($room->loadBeds()) {
             if (!empty($room->_beds)) {
                 foreach ($room->_beds as $bed) {
                     HMS_Bed::deleteBed($bed->id);
                 }
             }
         }
         $room->delete();
     } catch (Exception $e) {
         throw $e;
     }
     return true;
 }
예제 #25
0
 public function setToBed(HMS_Bed $bed)
 {
     $this->to_bed = $bed->getId();
 }
예제 #26
0
 /**
  * Does all the checks necessary to assign a student and makes the assignment
  *
  * The $room_id and $bed_id fields are optional, but one or the other must be specificed
  *
  * @param Student $student
  * @param Integer $term
  * @param Integer $room_id
  * @param Integer $bed_id
  * @param Integer $meal_plan
  * @param String $notes
  * @param boolean $lottery
  * @param string $reason
  * @throws InvalidArgumentException
  * @throws AssignmentException
  * @throws DatabaseException
  * @throws Exception
  */
 public static function assignStudent(Student $student, $term, $room_id = NULL, $bed_id = NULL, $meal_plan, $notes = "", $lottery = FALSE, $reason)
 {
     /**
      * Can't check permissions here because there are some student-facing commands that needs to make assignments (e.g.
      * the lottery/re-application code)
      *
      * if(!UserStatus::isAdmin() || !Current_User::allow('hms', 'assignment_maintenance')) {
      * PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
      * throw new PermissionException('You are not allowed to edit student assignments.');
      * }
      */
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     PHPWS_Core::initModClass('hms', 'HMS_Floor.php');
     PHPWS_Core::initModClass('hms', 'HMS_Room.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     PHPWS_Core::initModClass('hms', 'BannerQueue.php');
     PHPWS_Core::initModClass('hms', 'AssignmentHistory.php');
     PHPWS_Core::initModClass('hms', 'exception/AssignmentException.php');
     $username = $student->getUsername();
     // Make sure a username was entered
     if (!isset($username) || $username == '') {
         throw new InvalidArgumentException('Bad username.');
     }
     $username = strtolower($username);
     if ($student->getType() == TYPE_WITHDRAWN) {
         throw new AssignmentException('Invalid student type. Student is withdrawn.');
     }
     if (HMS_Assignment::checkForAssignment($username, $term)) {
         throw new AssignmentException('The student is already assigned.');
     }
     if (isset($bed_id)) {
         // A bed_id was given, so create that bed object
         $vacant_bed = new HMS_Bed($bed_id);
         if (!$vacant_bed) {
             throw new AssignmentException('Null bed object.');
         }
         // Get the room that this bed is in
         $room = $vacant_bed->get_parent();
     } else {
         if (isset($room_id)) {
             // A room_id was given, so create that room object
             $room = new HMS_Room($room_id);
             // And find a vacant bed in that room
             $beds = $room->getBedsWithVacancies();
             $vacant_bed = $beds[0];
         } else {
             // Both the bed and room IDs were null, so return an error
             throw new AssignmentException('No room nor bed specified.');
         }
     }
     if (!$room) {
         throw new AssignmentException('Null room object.');
     }
     // Make sure the room has a vacancy
     if (!$room->has_vacancy()) {
         throw new AssignmentException('The room is full.');
     }
     // Make sure the room is not offline
     if ($room->offline) {
         throw new AssignmentException('The room is offline');
     }
     // Double check that the bed is in the same term as we're being requested to assign for
     if ($vacant_bed->getTerm() != $term) {
         throw new AssignmentException('The bed\'s term and the assignment term do not match.');
     }
     // Double check that the resulting bed is empty
     if ($vacant_bed->get_number_of_assignees() > 0) {
         throw new AssignmentException('The bed is not empty.');
     }
     // Issue a warning if the bed was reserved for room change
     //TODO Move this to the room change view
     /*
     if ($vacant_bed->room_change_reserved != 0) {
         NQ::simple('hms', hms\NotificationView::WARNING, 'Room was reserved for room change');
     }
     */
     // Check that the room's gender and the student's gender match
     $student_gender = $student->getGender();
     if (is_null($student_gender)) {
         throw new AssignmentException('Student gender is null.');
     }
     // Genders must match unless the room is COED
     if ($room->getGender() != $student_gender && $room->getGender() != COED) {
         throw new AssignmentException('Room gender does not match the student\'s gender.');
     }
     // We probably shouldn't check permissions inside this method, since sometimes this can be
     // called from student-facing interfaces.. But, since I want to be really careful with co-ed rooms,
     // I'm going to take the extra step of making sure no students are putting themselves in co-ed rooms.
     if ($room->getGender() == COED && !Current_User::allow('hms', 'coed_assignment')) {
         throw new AssignmentException('You do not have permission to make assignments for Co-ed rooms.');
     }
     // Create the floor object
     $floor = $room->get_parent();
     if (!$floor) {
         throw new AssignmentException('Null floor object.');
     }
     // Create the hall object
     $hall = $floor->get_parent();
     if (!$hall) {
         throw new AssignmentException('Null hall object.');
     }
     if ($meal_plan == BANNER_MEAL_NONE) {
         $meal_plan = NULL;
     }
     // Determine which meal plan to use
     // If this is a freshmen student and they've somehow selected none or low, give them standard
     if ($student->getType() == TYPE_FRESHMEN && ($meal_plan == BANNER_MEAL_NONE || $meal_plan == BANNER_MEAL_LOW)) {
         $meal_plan = BANNER_MEAL_STD;
         // If a student is living in a dorm which requires a meal plan and they've selected none, give them low
     } else {
         if ($hall->meal_plan_required == 1 && $meal_plan == BANNER_MEAL_NONE) {
             $meal_plan = BANNER_MEAL_LOW;
         }
     }
     /**
      * ***************************
      * Temporary Assignment HACK *
      * ***************************
      */
     // Check for an assignment in the temp assignment table
     $db = new PHPWS_DB('hms_temp_assignment');
     $db->addWhere('banner_id', $student->getBannerId());
     $result = $db->select();
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     if (sizeof($result) > 0) {
         // Queue an unassign for this student
         $soap = SOAP::getInstance(UserStatus::getUsername(), UserStatus::isAdmin() ? SOAP::ADMIN_USER : SOAP::STUDENT_USER);
         try {
             $soap->removeRoomAssignment($student->getBannerId(), $term, 'TMPR', $result[0]['room_number'], 100);
             // Hard-code to 100% refund
         } catch (Exception $e) {
             throw $e;
         }
         $db = new PHPWS_DB('hms_temp_assignment');
         $db->addValue('banner_id', null);
         $db->addWhere('room_number', $result[0]['room_number']);
         $db->update();
         if (PHPWS_Error::logIfError($result)) {
             throw new DatabaseException($result->toString());
         }
         NQ::simple('hms', hms\NotificationView::WARNING, 'Temporary assignment was removed.');
     }
     // Send this off to the queue for assignment in banner
     $banner_success = BannerQueue::queueAssignment($student, $term, $hall, $vacant_bed, 'HOME', $meal_plan);
     if ($banner_success !== TRUE) {
         throw new AssignmentException('Error while adding the assignment to the Banner queue.');
     }
     // Make the assignment in HMS
     $assignment = new HMS_Assignment();
     $assignment->setBannerId($student->getBannerId());
     $assignment->asu_username = $username;
     $assignment->bed_id = $vacant_bed->id;
     $assignment->term = $term;
     $assignment->letter_printed = 0;
     $assignment->email_sent = 0;
     $assignment->meal_option = $meal_plan;
     $assignment->reason = $reason;
     $assignment->application_term = $student->getApplicationTerm();
     $assignment->class = $student->getComputedClass($term);
     // If this was a lottery assignment, flag it as such
     if ($lottery) {
         $assignment->lottery = 1;
         if (!isset($reason)) {
             // Automatically tag reason as lottery
             $assignment->reason = ASSIGN_LOTTERY;
         }
     } else {
         $assignment->lottery = 0;
     }
     $result = $assignment->save();
     if (!$result || PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     // Log the assignment
     HMS_Activity_Log::log_activity($username, ACTIVITY_ASSIGNED, UserStatus::getUsername(), $term . ' ' . $hall->hall_name . ' ' . $room->room_number . ' ' . $notes);
     // Insert assignment into History table
     AssignmentHistory::makeAssignmentHistory($assignment);
     // Look for roommates and flag their assignments as needing a new letter
     $room_id = $assignment->get_room_id();
     $room = new HMS_Room($room_id);
     // Go to the room level to get all the roommates
     $assignees = $room->get_assignees();
     // get an array of student objects for those assigned to this room
     if (sizeof($assignees) > 1) {
         foreach ($assignees as $roommate) {
             // Skip this student
             if ($roommate->getUsername() == $username) {
                 continue;
             }
             $roommate_assign = HMS_Assignment::getAssignment($roommate->getUsername(), $term);
             $roommate_assign->letter_printed = 0;
             $roommate_assign->email_sent = 0;
             $roommate_assign->save();
         }
     }
     // Return Sucess
     return true;
 }
 public function show()
 {
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     # Get the roommate request record from the database
     $bed = new HMS_Bed($this->request['bed_id']);
     $room = $bed->get_parent();
     $tpl = array();
     $requestor = StudentFactory::getStudentByUsername($this->request['requestor'], $this->term);
     $tpl['REQUESTOR'] = $requestor->getName();
     $tpl['HALL_ROOM'] = $bed->where_am_i();
     # List all the students which will be assigned and their beds
     $beds = $room->get_beds();
     foreach ($beds as $bed) {
         $bed_row = array();
         # Check for an assignment
         $bed->loadAssignment();
         # Check for a reservation
         $reservation = $bed->get_lottery_reservation_info();
         $bed_row['BEDROOM_LETTER'] = $bed->bedroom_label;
         if ($bed->_curr_assignment != NULL) {
             # Bed is assigned
             $roommate = StudentFactory::getStudentByUsername($bed->_curr_assignment->asu_username, $this->term);
             $bed_row['TEXT'] = $roommate->getName();
         } else {
             if ($reservation != NULL) {
                 # Bed is reserved
                 $roommate = StudentFactory::getStudentByUsername($reservation['asu_username'], $this->term);
                 $bed_row['TEXT'] = $roommate->getName() . ' (reserved)';
             } else {
                 $bed_row['TEXT'] = 'Empty';
             }
         }
         $tpl['beds'][] = $bed_row;
     }
     // Check if the student has already completed a housing application
     if ($this->housingApplication != null) {
         // Housing application complete, go straight to confirming roommate
         $submitCmd = CommandFactory::getCommand('LotteryShowConfirmRoommateRequest');
         $submitCmd->setRequestId($this->request['id']);
     } else {
         // No housing application, goto self-select start page for contract and emg contact
         $submitCmd = CommandFactory::getCommand('RlcSelfAssignStart');
         $submitCmd->setTerm($this->term);
         $submitCmd->setRoommateRequestId($this->request['id']);
     }
     $denyCmd = CommandFactory::getCommand('LotteryShowDenyRoommateRequest');
     $denyCmd->setRequestId($this->request['id']);
     $form = new PHPWS_Form();
     $submitCmd->initForm($form);
     # Decide which meal plan drop box to show based on whether or not the chosen room
     # is in a hall which requires a meal plan
     $floor = $room->get_parent();
     $hall = $floor->get_parent();
     if ($hall->meal_plan_required == 0) {
         $form->addDropBox('meal_plan', array(BANNER_MEAL_NONE => _('None'), BANNER_MEAL_LOW => _('Low'), BANNER_MEAL_STD => _('Standard'), BANNER_MEAL_HIGH => _('High'), BANNER_MEAL_SUPER => _('Super')));
     } else {
         $form->addDropBox('meal_plan', array(BANNER_MEAL_LOW => _('Low'), BANNER_MEAL_STD => _('Standard'), BANNER_MEAL_HIGH => _('High'), BANNER_MEAL_SUPER => _('Super')));
         $form->setMatch('meal_plan', BANNER_MEAL_STD);
     }
     // Set meal plan drop down default to what the student selected on the housing re-application.
     if ($this->housingApplication != null) {
         $form->setMatch('meal_plan', $this->housingApplication->getMealPlan());
     }
     $form->addSubmit('accept', 'Accept Roommate');
     $form->addButton('reject', 'Deny Roommate');
     javascript('modules/hms/buttonAction', array('ID' => 'phpws_form_reject', 'URI' => $denyCmd->getURI()));
     $form->mergeTemplate($tpl);
     $tpl = $form->getTemplate();
     Layout::addPageTitle("Lottery Request Roommate");
     return PHPWS_Template::process($tpl, 'hms', 'student/lottery_roommate_request.tpl');
 }
 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();
 }
예제 #29
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;
 }
예제 #30
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());
     }
 }