protected function createPairing(HousingApplication $a, HousingApplication $b)
 {
     // Determine lifestyle option
     $option = LO_COED;
     if ($a->lifestyle_option == LO_SINGLE_GENDER || $b->lifestyle_option == LO_SINGLE_GENDER) {
         $option = LO_SINGLE_GENDER;
     }
     try {
         $studentA = StudentFactory::getStudentByUsername($a->username, $this->term);
     } catch (StudentNotFoundException $e) {
         echo 'StudentNotFoundException: ' . $a->username . ' Could not pair ' . $a->username . ', ' . $b->username . "\n";
         return null;
     }
     try {
         $studentB = Studentfactory::getStudentByUsername($b->username, $this->term);
     } catch (StudentNotFoundException $e) {
         echo 'StudentNotFoundException: ' . $b->username . ' Could not pair ' . $a->username . ', ' . $b->username . "\n";
         return null;
     }
     if ($a->getCreatedOn() < $b->getCreatedOn()) {
         $earliestTime = $a->getCreatedOn();
     } else {
         $earliestTime = $b->getCreatedOn();
     }
     // Looks like there is no problem here.
     return new AssignmentPairing($studentA, $studentB, $option, $earliestTime);
 }
 public function execute()
 {
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     $this->reasons = HousingApplication::getCancellationReasons();
     // All students
     $db = new PHPWS_DB('hms_new_application');
     $db->addColumn('cancelled_reason');
     $db->addColumn('id', null, 'ount', true);
     $db->addWhere('term', $this->getTerm());
     $db->addWhere('cancelled', 1);
     $db->addGroupBy('cancelled_reason');
     $this->reasonCounts = $db->select('assoc');
     // Freshmen
     $db = new PHPWS_DB('hms_new_application');
     $db->addColumn('cancelled_reason');
     $db->addColumn('id', null, 'count', true);
     $db->addWhere('term', $this->getTerm());
     $db->addWhere('cancelled', 1);
     $db->addWhere('student_type', TYPE_FRESHMEN);
     $db->addGroupBy('cancelled_reason');
     $this->freshmenReasonCounts = $db->select('assoc');
     // Continuing
     $db = new PHPWS_DB('hms_new_application');
     $db->addColumn('cancelled_reason');
     $db->addColumn('id', null, 'count', true);
     $db->addWhere('term', $this->getTerm());
     $db->addWhere('cancelled', 1);
     $db->addWhere('student_type', TYPE_CONTINUING);
     $db->addGroupBy('cancelled_reason');
     $this->continuingReasonCounts = $db->select('assoc');
 }
 /**
  * (non-PHPdoc)
  * @see Command::execute()
  */
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     $term = $context->get('term');
     // Check if the student has already applied. If so, redirect to the student menu
     $app = HousingApplication::getApplicationByUser(UserStatus::getUsername(), $term);
     if (isset($result) && $result->getApplicationType == 'offcampus_waiting_list') {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You have already enrolled on the on-campus housing Open Waiting List for this term.');
         $menuCmd = CommandFactory::getCommand('ShowStudentMenu');
         $menuCmd->redirect();
     }
     // Make sure the student agreed to the terms, if not, send them back to the terms & agreement command
     $event = $context->get('event');
     $_SESSION['application_data'] = array();
     // If they haven't agreed, redirect to the agreement
     if (is_null($event) || !isset($event) || $event != 'signing_complete' && $event != 'viewing_complete') {
         $onAgree = CommandFactory::getCommand('ShowOffCampusWaitListApplication');
         $onAgree->setTerm($term);
         $agreementCmd = CommandFactory::getCommand('ShowTermsAgreement');
         $agreementCmd->setTerm($term);
         $agreementCmd->setAgreedCommand($onAgree);
         $agreementCmd->redirect();
     }
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     PHPWS_Core::initModClass('hms', 'ReApplicationOffCampusFormView.php');
     $view = new ReApplicationOffCampusFormView($student, $term);
     $context->setContent($view->show());
 }
 protected function assign(AssignmentPairing $pair, HMS_Room $room)
 {
     if (!$this->allowed($pair, $room)) {
         PHPWS_Core::initModClass('hms', 'exception/AssignmentException.php');
         throw new AssignmentException('Cannot assign ' . $pair->__tostring() . ' to ' . $room->__tostring());
     }
     echo get_class($this) . " is assigning " . $pair->__tostring() . " to room " . $room->__tostring() . "\n";
     // Actually assign the given pairing to the given room
     try {
         $application = HousingApplication::getApplicationByUser($pair->getStudent1()->getUsername(), $this->term);
         if (is_null($application)) {
             $student1MealPlan = BANNER_MEAL_STD;
         } else {
             $student1MealPlan = $application->getMealPlan();
         }
         HMS_Assignment::assignStudent($pair->getStudent1(), $this->term, $room->id, NULL, $student1MealPlan, 'Auto-assigned', false, ASSIGN_FR_AUTO);
     } catch (Exception $e) {
         echo "Could not assign '{$pair->getStudent1()->getUsername()}': {get_class({$e})}: {$e->getMessage()}<br />\n";
     }
     $pair->setBed1($room->__toString());
     try {
         $application = HousingApplication::getApplicationByUser($pair->getStudent2()->getUsername(), $this->term);
         if (is_null($application)) {
             $student2MealPlan = BANNER_MEAL_STD;
         } else {
             $student2MealPlan = $application->getMealPlan();
         }
         HMS_Assignment::assignStudent($pair->getStudent2(), $this->term, $room->id, NULL, $student2MealPlan, 'Auto-assigned', false, ASSIGN_FR_AUTO);
     } catch (Exception $e) {
         echo "Could not assign '{$pair->getStudent2()->getUsername()}': " . get_class($e) . ": {$e->getMessage()}<br />\n";
     }
     $pair->setBed2($room->__toString());
 }
Example #5
0
 public function __construct($term)
 {
     $this->term = $term;
     echo "Term is {$term}\n\n";
     PHPWS_Core::initModClass('hms', 'RoommatePairingStrategy.php');
     PHPWS_Core::initModClass('hms', 'RequestedRoommatePairingStrategy.php');
     PHPWS_Core::initModClass('hms', 'PreferencesRoommatePairingStrategy.php');
     PHPWS_Core::initModClass('hms', 'AssignmentStrategy.php');
     PHPWS_Core::initModClass('hms', 'SpecialAssignmentStrategy.php');
     PHPWS_Core::initModClass('hms', 'SingleGenderAssignmentStrategy.php');
     PHPWS_Core::initModClass('hms', 'CoedAssignmentStrategy.php');
     PHPWS_Core::initModClass('hms', 'RandomAssignmentStrategy.php');
     # Load all the unassigned applicants for this term
     $this->applications = HousingApplication::getUnassignedFreshmenApplications($term, null);
     # Setup the pairing strategies
     $this->pairingStrategies = array();
     $this->pairingStrategies[] = new RequestedRoommatePairingStrategy($term);
     $this->pairingStrategies[] = new PreferencesRoommatePairingStrategy($term);
     # Setup the assignment strategies
     $this->assignmentStrategies = array();
     $this->assignmentStrategies[] = new SpecialAssignmentStrategy($term);
     $this->assignmentStrategies[] = new SingleGenderAssignmentStrategy($term);
     $this->assignmentStrategies[] = new CoedAssignmentStrategy($term);
     $this->assignmentStrategies[] = new RandomAssignmentStrategy($term);
 }
Example #6
0
 public function getMenuBlockView(Student $student)
 {
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'ApplicationMenuBlockView.php');
     $application = HousingApplication::getApplicationByUser($student->getUsername(), $this->term);
     return new ApplicationMenuBlockView($this->term, $this->getStartDate(), $this->getEditDate(), $this->getEndDate(), $application);
 }
Example #7
0
 public function execute()
 {
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'HMS_Util.php');
     // Select all cancelled apps for the given term
     $db = new PHPWS_DB('hms_new_application');
     $db->addWhere('cancelled', 1);
     $db->addWhere('term', $this->term);
     $results = $db->select();
     // Initialize storage for processed rows
     $this->rows = array();
     // Get friendly cancellation reasons from HousingApplication
     $reasons = HousingApplication::getCancellationReasons();
     // Process and store each result
     foreach ($results as $app) {
         $row = array();
         $row['bannerId'] = $app['banner_id'];
         $row['username'] = $app['username'];
         $row['gender'] = HMS_Util::formatGender($app['gender']);
         $row['application_term'] = $app['application_term'];
         $row['student_type'] = $app['student_type'];
         $row['cancelled_reason'] = $reasons[$app['cancelled_reason']];
         $row['cancelled_on'] = HMS_Util::get_long_date($app['cancelled_on']);
         $row['cancelled_by'] = $app['cancelled_by'];
         $this->rows[] = $row;
     }
 }
Example #8
0
 public function getMenuBlockView(Student $student)
 {
     PHPWS_Core::initModClass('hms', 'ReapplicationWaitingListMenuBlockView.php');
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     $term = PHPWS_Settings::get('hms', 'lottery_term');
     $application = HousingApplication::getApplicationByUser(UserStatus::getUsername(), $term, 'lottery');
     return new ReapplicationWaitingListMenuBlockView($this->term, $this->getStartDate(), $this->getEndDate(), $application);
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'RlcMembershipFactory.php');
     PHPWS_Core::initModClass('hms', 'RlcAssignmentSelfAssignedState.php');
     $requestId = $context->get('requestId');
     $mealPlan = $context->get('mealPlan');
     $errorCmd = CommandFactory::getCommand('LotteryShowConfirmRoommateRequest');
     $errorCmd->setRequestId($requestId);
     $errorCmd->setMealPlan($mealPlan);
     // Confirm the captcha
     PHPWS_Core::initCoreClass('Captcha.php');
     $captcha = Captcha::verify(TRUE);
     if ($captcha === FALSE) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'The words you entered were incorrect. Please try again.');
         $errorCmd->redirect();
     }
     // Check for a meal plan
     if (!isset($mealPlan) || $mealPlan == '') {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Please choose a meal plan.');
         $errorCmd->redirect();
     }
     $term = PHPWS_Settings::get('hms', 'lottery_term');
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     // Update the meal plan field on the application
     $app = HousingApplication::getApplicationByUser(UserStatus::getUsername(), $term);
     $app->setMealPlan($mealPlan);
     try {
         $app->save();
     } catch (Exception $e) {
         PHPWS_Error::log('hms', $e->getMessage());
         NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, there was an error confirming your roommate invitation. Please contact University Housing.');
         $errorCmd->redirect();
     }
     // Try to actually make the assignment
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     try {
         HMS_Lottery::confirm_roommate_request(UserStatus::getUsername(), $requestId, $mealPlan);
     } catch (Exception $e) {
         PHPWS_Error::log('hms', $e->getMessage());
         NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, there was an error confirming your roommate invitation. Please contact University Housing.');
         $errorCmd->redirect();
     }
     # Log the fact that the roommate was accepted and successfully assigned
     HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_LOTTERY_CONFIRMED_ROOMMATE, UserStatus::getUsername(), "Captcha: \"{$captcha}\"");
     // Check for an RLC membership and update status if necessary
     // If this student was an RLC self-select, update the RLC memberhsip state
     $rlcAssignment = RlcMembershipFactory::getMembership($student, $term);
     if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') {
         $rlcAssignment->changeState(new RlcAssignmentSelfAssignedState($rlcAssignment));
     }
     $invite = HMS_Lottery::get_lottery_roommate_invite_by_id($requestId);
     $successCmd = CommandFactory::getCommand('LotteryShowConfirmedRoommateThanks');
     $successCmd->setRequestId($requestId);
     $successCmd->redirect();
 }
 public function execute(CommandContext $context)
 {
     if (!Current_User::allow('hms', 'cancel_housing_application')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to cancel housing applications.');
     }
     // Check for a housing application id
     $applicationId = $context->get('applicationId');
     if (!isset($applicationId) || is_null($applicationId)) {
         throw new InvalidArgumentException('Missing housing application id.');
     }
     // Check for a cancellation reason
     $cancelReason = $context->get('cancel_reason');
     if (!isset($cancelReason) || is_null($cancelReason)) {
         throw new InvalidArgumentException('Missing cancellation reason.');
     }
     // Load the housing application
     PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php');
     $application = HousingApplicationFactory::getApplicationById($applicationId);
     // Load the student
     $student = $application->getStudent();
     $username = $student->getUsername();
     $term = $application->getTerm();
     // Load the cancellation reasons
     $reasons = HousingApplication::getCancellationReasons();
     // Check for an assignment and remove it
     // Decide which term to use - If this application is in a past fall term, then use the current term
     if ($term < Term::getCurrentTerm() && Term::getTermSem($term) == TERM_FALL) {
         $assignmentTerm = Term::getCurrentTerm();
     } else {
         $assignmentTerm = $term;
     }
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     $assignment = HMS_Assignment::getAssignmentByBannerId($student->getBannerId(), $assignmentTerm);
     if (isset($assignment)) {
         // TODO: Don't hard code cancellation refund percentage
         HMS_Assignment::unassignStudent($student, $assignmentTerm, 'Application cancellation: ' . $reasons[$cancelReason], UNASSIGN_CANCEL, 100);
     }
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php');
     $rlcAssignment = HMS_RLC_Assignment::getAssignmentByUsername($username, $term);
     if (!is_null($rlcAssignment)) {
         $rlcAssignment->delete();
     }
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
     $rlcApplication = HMS_RLC_Application::getApplicationByUsername($username, $term);
     if (!is_null($rlcApplication)) {
         $rlcApplication->denied = 1;
         $rlcApplication->save();
         HMS_Activity_Log::log_activity($username, ACTIVITY_DENIED_RLC_APPLICATION, \Current_User::getUsername(), Term::toString($term) . ' Denied RLC Application due to Contract Cancellation');
     }
     // Cancel the application
     $application->cancel($cancelReason);
     $application->save();
     echo 'success';
     exit;
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php');
     PHPWS_Core::initModClass('hms', 'HousingApplicationFormView.php');
     // Make sure we have a valid term
     $term = $context->get('term');
     if (is_null($term) || !isset($term)) {
         throw new InvalidArgumentException('Missing term.');
     }
     // Determine the application type, based on the term
     $sem = Term::getTermSem($term);
     switch ($sem) {
         case TERM_FALL:
             $appType = 'fall';
             break;
         case TERM_SPRING:
             $appType = 'spring';
             break;
         case TERM_SUMMER1:
         case TERM_SUMMER2:
             $appType = 'summer';
             break;
     }
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     // Make sure the student agreed to the terms, if not, send them back to the terms & agreement command
     //$event = $context->get('event');
     // If they haven't agreed, redirect to the agreement
     // TODO: actually check via docusign API
     /*
     if(is_null($event) || !isset($event) || ($event != 'signing_complete' && $event != 'viewing_complete')){
         $agreementCmd = CommandFactory::getCommand('ShowTermsAgreement');
         $agreementCmd->setTerm($term);
         $agreementCmd->setAgreedCommand(CommandFactory::getCommand('ShowHousingApplicationForm'));
         $agreementCmd->redirect();
     }
     */
     // Check to see if the student's PIN is enabled. Don't let the student apply if the PIN is disabled.
     if ($student->pinDisabled()) {
         $pinCmd = CommandFactory::getCommand('ShowPinDisabled');
         $pinCmd->redirect();
     }
     // Check to see if the user has an existing application for the term in question
     $existingApplication = HousingApplication::getApplicationByUser($student->getUsername(), $term);
     // Check for an in-progress application on the context, ignore any exceptions (in case there isn't an application on the context)
     try {
         //TODO check to see if it looks like there might be something on the context before trying this
         $existingApplication = HousingApplicationFactory::getApplicationFromContext($context, $term, $student, $appType);
     } catch (Exception $e) {
         // ignored
         $contextApplication = NULL;
     }
     $appView = new HousingApplicationFormView($student, $term, $existingApplication);
     $context->setContent($appView->show());
 }
 public function show()
 {
     $tpl = array();
     if (empty($this->housingApps)) {
         $tpl['APPLICATIONS_EMPTY'] = 'No applications found.';
         return PHPWS_Template::process($tpl, 'hms', 'admin/profileHousingAppList.tpl');
     }
     // Include javascript for cancel application jquery dialog
     $jsParams = array('LINK_SELECT' => '.cancelAppLink');
     javascript('profileCancelApplication', $jsParams, 'mod/hms/');
     $app_rows = "";
     // Get the list of cancellation reasons
     $reasons = HousingApplication::getCancellationReasons();
     // Show a row for each application
     foreach ($this->housingApps as $app) {
         $term = Term::toString($app->getTerm());
         $mealPlan = HMS_Util::formatMealOption($app->getMealPlan());
         $phone = HMS_Util::formatCellPhone($app->getCellPhone());
         $type = $app->getPrintableAppType();
         // Clean/dirty and early/late preferences are only fields on the FallApplication
         if ($app instanceof FallApplication && isset($app->room_condition)) {
             $clean = $app->room_condition == 1 ? 'Neat' : 'Cluttered';
         } else {
             $clean = '';
         }
         if ($app instanceof FallApplication && isset($app->preferred_bedtime)) {
             $bedtime = $app->preferred_bedtime == 1 ? 'Early' : 'Late';
         } else {
             $bedtime = '';
         }
         $viewCmd = CommandFactory::getCommand('ShowApplicationView');
         $viewCmd->setAppId($app->getId());
         $view = $viewCmd->getURI();
         $row = array('term' => $term, 'type' => $type, 'meal_plan' => $mealPlan, 'cell_phone' => $phone, 'clean' => $clean, 'bedtime' => $bedtime, 'view' => $view);
         if ($app->isCancelled()) {
             $reInstateCmd = CommandFactory::getCommand('ReinstateApplication');
             $reInstateCmd->setAppID($app->getId());
             $row['reinstate'] = $reInstateCmd->getURI();
             $cancelledReason = "({$reasons[$app->getCancelledReason()]})";
             $row['cancelledReason'] = $cancelledReason;
             $row['row_style'] = 'warning';
         } else {
             // Show Cancel Command, if user has permission to cancel apps
             if (Current_User::allow('hms', 'cancel_housing_application')) {
                 $cancelCmd = CommandFactory::getCommand('ShowCancelHousingApplication');
                 $cancelCmd->setHousingApp($app);
                 $cancel = $cancelCmd->getURI();
                 $row['cancel'] = $cancel;
             }
         }
         $app_rows[] = $row;
     }
     $tpl['APPLICATIONS'] = $app_rows;
     return PHPWS_Template::process($tpl, 'hms', 'admin/profileHousingAppList.tpl');
 }
 public function delete()
 {
     $db = new PHPWS_DB('hms_waitlist_application');
     $db->addWhere('id', $this->id);
     $result = $db->delete();
     if (!$result || PHPWS_Error::logIfError($result)) {
         return $result;
     }
     if (!parent::delete()) {
         return false;
     }
     return TRUE;
 }
Example #14
0
 public function copy($to_term, $room_id, $assignments)
 {
     if (!$this->id) {
         return false;
     }
     // echo "in hms_beds, making a copy of this bed<br>";
     $new_bed = clone $this;
     $new_bed->reset();
     $new_bed->term = $to_term;
     $new_bed->room_id = $room_id;
     $new_bed->clearRoomChangeReserved();
     try {
         $new_bed->save();
     } catch (Exception $e) {
         throw $e;
     }
     // Copy assignment
     if ($assignments) {
         // echo "loading assignments for this bed<br>";
         PHPWS_Core::initModClass('hms', 'HousingApplication.php');
         PHPWS_Core::initModClass('hms', 'Term.php');
         PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
         PHPWS_Core::initModClass('hms', 'StudentFactory.php');
         try {
             $this->loadAssignment();
         } catch (Exception $e) {
             throw $e;
         }
         if (isset($this->_curr_assignment)) {
             try {
                 try {
                     $student = StudentFactory::getStudentByUsername($this->_curr_assignment->asu_username, Term::getCurrentTerm());
                     $app = HousingApplication::getApplicationByUser($this->_curr_assignment->asu_username, Term::getCurrentTerm());
                 } catch (StudentNotFoundException $e) {
                     NQ::simple('hms', hms\NotificationView::ERROR, 'Could not copy assignment for ' . $this->_curr_assignment->asu_username);
                     return;
                 }
                 // meal option defaults to standard
                 $meal_option = BANNER_MEAL_STD;
                 if (!is_null($app)) {
                     $meal_option = $app->getMealPlan();
                 }
                 $note = "Assignment copied from " . Term::getPrintableCurrentTerm() . " to " . Term::toString($to_term);
                 HMS_Assignment::assignStudent($student, $to_term, null, $new_bed->id, $meal_option, $note, false, $this->_curr_assignment->getReason());
             } catch (Exception $e) {
                 throw $e;
             }
         }
     }
 }
Example #15
0
 public function getMenuBlockView(Student $student)
 {
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'ReapplicationMenuBlockView.php');
     $assignment = HMS_Assignment::getAssignment($student->getUsername(), $this->term);
     $application = HousingApplication::getApplicationByUser($student->getUsername(), $this->term);
     if (!$application instanceof LotteryApplication) {
         $application = null;
     }
     $roommateRequests = HMS_Lottery::get_lottery_roommate_invites($student->getUsername(), $this->term);
     return new ReapplicationMenuBlockView($this->term, $this->getStartDate(), $this->getEndDate(), $assignment, $application, $roommateRequests);
 }
 public function show()
 {
     $tpl = array();
     $tpl['ENTRY_TERM'] = Term::toString($this->student->getApplicationTerm());
     $tpl['REQUIRED_TERMS'] = array();
     $appsOnFile = HousingApplication::getAllApplicationsForStudent($this->student);
     # Make a list of the terms the student has completed
     $termsOnFile = array();
     if (isset($appsOnFile) && !is_null($appsOnFile)) {
         foreach ($appsOnFile as $term => $app) {
             $termsOnFile[] = $term;
         }
     }
     foreach ($this->requiredTerms as $t) {
         if ($t['required'] == 0) {
             continue;
         }
         $completed = '';
         if (in_array($t['term'], $termsOnFile)) {
             $completed = ' <span style="color: #0000AA">(Completed)</span>';
         }
         // If the application is cancelled, overwrite the "complete" text with "cancelled"
         if (isset($appsOnFile[$t['term']]) && $appsOnFile[$t['term']]->isCancelled()) {
             $completed = ' <span style="color: #F00">(Cancelled)</span>';
         }
         if (Term::getTermSem($t['term']) == TERM_FALL) {
             $tpl['REQUIRED_TERMS'][] = array('REQ_TERM' => Term::toString($t['term']) . ' - ' . Term::toString(Term::getNextTerm($t['term'])), 'COMPLETED' => $completed);
         } else {
             $tpl['REQUIRED_TERMS'][] = array('REQ_TERM' => Term::toString($t['term']), 'COMPLETED' => $completed);
         }
     }
     $contactCmd = CommandFactory::getCommand('ShowContactForm');
     $tpl['CONTACT_LINK'] = $contactCmd->getLink('contact us');
     # Setup the form for the 'continue' button.
     $form = new PHPWS_Form();
     $this->submitCmd->initForm($form);
     $form->mergeTemplate($tpl);
     $tpl = $form->getTemplate();
     $studentType = $this->student->getType();
     Layout::addPageTitle("Welcome");
     if (count($appsOnFile) > 0) {
         // User is now past step one.  No longer just welcoming, we are now welcoming back.
         return PHPWS_Template::process($tpl, 'hms', 'student/welcome_back_screen.tpl');
     }
     if ($studentType == TYPE_FRESHMEN || $studentType == TYPE_NONDEGREE || $this->student->isInternational()) {
         return PHPWS_Template::process($tpl, 'hms', 'student/welcome_screen_freshmen.tpl');
     } else {
         return PHPWS_Template::process($tpl, 'hms', 'student/welcome_screen_transfer.tpl');
     }
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php');
     PHPWS_Core::initModClass('hms', 'EmergencyContactFormView.php');
     // Make sure we have a valid term
     $term = $context->get('term');
     if (is_null($term) || !isset($term)) {
         throw new InvalidArgumentException('Missing term.');
     }
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     $application = HousingApplication::getApplicationByUser($student->getUsername(), $term);
     $formView = new EmergencyContactFormView($student, $term, $application);
     $context->setContent($formView->show());
 }
Example #18
0
 public function getMenuBlockView(Student $student)
 {
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'RlcReapplicationMenuBlockView.php');
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php');
     $application = HousingApplication::getApplicationByUser($student->getUsername(), $this->term);
     if (!$application instanceof LotteryApplication) {
         $application = null;
     }
     $rlcApp = HMS_RLC_Application::getApplicationByUsername($student->getUsername(), $this->term);
     if (!$rlcApp instanceof HMS_RLC_Application) {
         $rlcApp = null;
     }
     // Check for an assignment
     $assignment = HMS_RLC_Assignment::getAssignmentByUsername($student->getUsername(), $this->getTerm());
     return new RlcReapplicationMenuBlockView($this->term, $this->getStartDate(), $this->getEndDate(), $application, $rlcApp, $assignment);
 }
Example #19
0
 /**
  * Handles looking up and withdrawing housing applications.
  * @param Student $student
  */
 private function handleApplication(Student $student)
 {
     // Get the application and mark it withdrawn
     $app = HousingApplication::getApplicationByUser($student->getUsername(), $this->term);
     if (!is_null($app)) {
         //$app->setWithdrawn(1);
         //$app->setStudentType(TYPE_WITHDRAWN);
         $app->cancel(CANCEL_WITHDRAWN);
         try {
             $app->save();
         } catch (Exception $e) {
             // TODO
         }
         $this->actions[$student->getUsername()][] = 'Found Housing Application; Student Type: ' . $app->getStudentType() . ' App Term: ' . $app->getApplicationTerm();
         $this->actions[$student->getUsername()][] = 'Marked application as cancelled (reason: withdrawn)';
         HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_CANCEL_HOUSING_APPLICATION, UserStatus::getUsername(), 'Application automatically cancelled by Withdrawn Search');
     }
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     PHPWS_Core::initModClass('hms', 'LotteryRoommateRequestView.php');
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'RlcMembershipFactory.php');
     $request = HMS_Lottery::get_lottery_roommate_invite_by_id($context->get('requestId'));
     $term = PHPWS_Settings::get('hms', 'lottery_term');
     $housingApp = HousingApplication::getApplicationByUser(UserStatus::getUsername(), $term);
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     // Check for a self-select RLC membership for the logged-in student
     $rlcAssign = RlcMembershipFactory::getMembership($student, $term);
     if ($rlcAssign == false) {
         $rlcAssign = null;
     }
     $view = new LotteryRoommateRequestView($request, $term, $housingApp, $rlcAssign);
     $context->setContent($view->show());
 }
 public function execute(CommandContext $context)
 {
     if (!Current_User::allow('hms', 'lottery_admin')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have remove students from the waiting list.');
     }
     $username = $context->get('username');
     $cmd = CommandFactory::getCommand('ShowLotteryWaitingList');
     if (!is_null($username)) {
         $app = HousingApplication::getApplicationByUser($username, PHPWS_Settings::get('hms', 'lottery_term'));
         $app->waiting_list_hide = 1;
         $result = $app->save();
         if (!PHPWS_Error::logIfError($result)) {
             NQ::simple('hms', hms\NotificationView::SUCCESS, "{$username} removed from the waiting list!");
             $cmd->redirect();
         }
     }
     NQ::simple('hms', hms\NotificationView::SUCCESS, "Unable to remove {$username} from the waiting list!");
     $cmd->redirect();
 }
 public function show()
 {
     $terms = HousingApplication::getAvailableApplicationTermsForStudent($this->student);
     $applications = HousingApplication::getAllApplicationsForStudent($this->student);
     $tpl = array();
     foreach ($terms as $t) {
         # If the student has a withdrawn application,
         # then show a message instead of the normal menu block.
         if (isset($applications[$t['term']]) && $applications[$t['term']]->isCancelled()) {
             $termBlock = new StudentMenuWithdrawnTermBlock($this->student, $t['term']);
         } else {
             // Look up the student again in each term, because student type can change depending on which term we ask about
             $student = StudentFactory::getStudentByBannerId($this->student->getBannerId(), $t['term']);
             $termBlock = new StudentMenuTermBlock($student, $t['term']);
         }
         $tpl['TERMBLOCK'][] = array('TERMBLOCK_CONTENT' => $termBlock->show());
     }
     Layout::addPageTitle("Main Menu");
     return PHPWS_Template::process($tpl, 'hms', 'student/freshmenMenu.tpl');
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'ApplicationFeature.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'HousingApplicationWelcomeView.php');
     $term = $context->get('term');
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     $submitCmd = CommandFactory::getCommand('ShowHousingApplicationForm');
     $submitCmd->setTerm($term);
     //TODO get rid of the magic string
     $feature = ApplicationFeature::getInstanceByNameAndTerm('Application', $term);
     // If there is no feature, or if we're not inside the feature's deadlines...
     if (is_null($feature) || $feature->getStartDate() > time() || $feature->getEndDate() < time() || !$feature->isEnabled()) {
         PHPWS_Core::initModClass('hms', 'HousingApplicationNotAvailableView.php');
         $view = new HousingApplicationNotAvailableView($student, $feature, $term);
     } else {
         $requiredTerms = HousingApplication::getAvailableApplicationTermsForStudent($student);
         $view = new HousingApplicationWelcomeView($student, $submitCmd, $requiredTerms);
     }
     $context->setContent($view->show());
 }
 public function show()
 {
     $tpl = array();
     $tpl['NAME'] = $this->student->getName();
     $tpl['TERM'] = Term::toString($this->application->getTerm());
     if (isset($this->assignment)) {
         $tpl['ASSIGNMENT'] = $this->assignment->where_am_i();
     } else {
         $tpl['NO_ASSIGNMENT'] = "";
         // dummy tag
     }
     $form = new PHPWS_Form('cancel_app_form');
     $submitCmd = CommandFactory::getCommand('CancelHousingApplication');
     $submitCmd->initForm($form);
     $reasons = array_merge(array(-1 => 'Select...'), HousingApplication::getCancellationReasons());
     $form->addDropBox('cancel_reason', $reasons);
     $form->setLabel('cancel_reason', 'Reason');
     $form->addHidden('applicationId', $this->application->getId());
     $form->addHidden('term', $this->application->getTerm());
     $form->mergeTemplate($tpl);
     $tpl = $form->getTemplate();
     return PHPWS_Template::process($tpl, 'hms', 'admin/housingApplicationCancelView.tpl');
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     $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();
     }
     # Check if the student has already applied. If so, redirect to the student menu
     $result = HousingApplication::checkForApplication(UserStatus::getUsername(), $term);
     if ($result !== FALSE) {
         NQ::simple('hms', hms\NotificationView::WARNING, 'You have already re-applied for on-campus housing for that term.');
         $menuCmd = CommandFactory::getCommand('ShowStudentMenu');
         $menuCmd->redirect();
     }
     # Make sure the student agreed to the terms, if not, send them back to the terms & agreement command
     $event = $context->get('event');
     $_SESSION['application_data'] = array();
     # If they haven't agreed, redirect to the agreement
     if (is_null($event) || !isset($event) || $event != 'signing_complete' && $event != 'viewing_complete') {
         $onAgree = CommandFactory::getCommand('ShowReApplication');
         $onAgree->setTerm($term);
         $agreementCmd = CommandFactory::getCommand('ShowTermsAgreement');
         $agreementCmd->setTerm($term);
         $agreementCmd->setAgreedCommand($onAgree);
         $agreementCmd->redirect();
     }
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     PHPWS_Core::initModClass('hms', 'ReApplicationFormView.php');
     $view = new ReApplicationFormView($student, $term);
     $context->setContent($view->show());
 }
 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();
 }
 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();
 }
Example #28
0
 /**
  * Returns the fields specific to the SummerApplications (used in the UnassignedStudents Report).
  *
  * @return Array Array of fields for this SummerApplication.
  */
 public function unassignedStudentsFields()
 {
     $fields = parent::unassignedStudentsFields();
     switch ($this->getRoomType()) {
         case ROOM_TYPE_DOUBLE:
             $fields['room_type'] = 'Double';
             break;
         case ROOM_TYPE_PRIVATE:
             $fields['room_type'] = 'Private';
             break;
         default:
             $fields['room_type'] = 'Unknown';
             break;
     }
     $fields['smoking_preference'] = $this->getSmokingPreference() == 1 ? 'No' : 'Yes';
     return $fields;
 }
 public function show()
 {
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'LotteryApplication.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Room.php');
     javascript('jquery');
     $tpl = array();
     #TODO: place a temporary reservation on the entire room
     # Grab all of their preferred roommates
     $lotteryApplication = HousingApplication::getApplicationByUser($this->student->getUsername(), $this->term);
     # List each bed in the room and if it's available, assigned, or reserved
     $room = new HMS_Room($this->roomId);
     $beds = $room->get_beds();
     $tpl['ROOM'] = $room->where_am_i();
     $form = new PHPWS_Form();
     $submitCmd = CommandFactory::getCommand('LotteryChooseRoommates');
     $submitCmd->setRoomId($this->roomId);
     $submitCmd->initForm($form);
     $assigned_self = FALSE;
     // Whether or not we've placed *this* student in a bed yet
     // Search the request to see if the student has already assigned themselves previously (this is only used if the user is being
     // set back from a subsequent page after an error).
     if (isset($_REQUEST['roommates']) && !(array_search($this->student->getUsername(), $_REQUEST['roommates']) === FALSE)) {
         $assigned_self = TRUE;
     }
     $bedCount = count($beds);
     for ($i = 0; $i < $bedCount; $i++) {
         $bed = $beds[$i];
         $bed_row = array();
         $bedLabel = $room->getRoomNumber();
         if ($room->get_number_of_beds() == 4) {
             $bedLabel = $bedLabel . $bed->getBedroomLabel();
         }
         $bedLabel = $bedLabel . $bed->getLetter();
         $bed_row['BED_LABEL'] = $bedLabel;
         # Check for an assignment
         $bed->loadAssignment();
         # Check for a reservation
         $reservation = $bed->get_lottery_reservation_info();
         if ($bed->_curr_assignment != NULL) {
             # Bed is assigned, so show who's in it
             $assignedStudent = StudentFactory::getStudentByUsername($bed->_curr_assignment->asu_username, $this->term);
             $bed_row['TEXT'] = $assignedStudent->getName() . ' (assigned)';
         } else {
             if ($reservation != NULL) {
                 # Bed is reserved
                 $reservedStudent = StudentFactory::getStudentByUsername($reservation['asu_username'], $this->term);
                 $bed_row['TEXT'] = $reservedStudent->getName() . ' (unconfirmed invitation)';
             } else {
                 if ($bed->isInternationalReserved() || $bed->isRaRoommateReserved() || $bed->isRa()) {
                     $bed_row['TEXT'] = "<input type=\"text\" class=\"form-control\" value=\"Reserved\" disabled>";
                 } else {
                     # Bed is empty, so decide what we should do with it
                     if (isset($_REQUEST['roommates'][$bed->id])) {
                         # The user already submitted the form once, put the value in the request in the text box by default
                         $bed_row['TEXT'] = "<input type=\"text\" class=\"form-control\" name=\"roommates[{$bed->id}]\" class=\"roommate_entry\" value=\"{$_REQUEST['roommates'][$bed->id]}\">";
                     } else {
                         if (!$assigned_self) {
                             # No value in the request, this bed is empty, and this user hasn't been assigned anywhere yet
                             # So put their user name in this field by default
                             $bed_row['TEXT'] = "<input type=\"text\" class=\"form-control\" name=\"roommates[{$bed->id}]\" class=\"roommate_entry\" value=\"{$this->student->getUsername()}\">";
                             $assigned_self = TRUE;
                         } else {
                             $bed_row['TEXT'] = "<input type=\"text\" class=\"form-control\" name=\"roommates[{$bed->id}]\" class=\"roommate_entry\">";
                         }
                     }
                 }
             }
         }
         $tpl['beds'][] = $bed_row;
     }
     # 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')));
         $form->addCssClass('meal_plan', 'form-control');
     } else {
         $form->addDropBox('meal_plan', array(BANNER_MEAL_LOW => _('Low'), BANNER_MEAL_STD => _('Standard'), BANNER_MEAL_HIGH => _('High'), BANNER_MEAL_SUPER => _('Super')));
         $form->addCssClass('meal_plan', 'form-control');
     }
     $form->setMatch('meal_plan', $lotteryApplication->getMealPlan());
     $form->addSubmit('submit_form', 'Review Roommate & Room Selection');
     $form->mergeTemplate($tpl);
     $tpl = $form->getTemplate();
     Layout::addPageTitle("Lottery Choose Roommate");
     return PHPWS_Template::process($tpl, 'hms', 'student/lottery_select_roommate.tpl');
 }
 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();
     }
 }