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 show() { PHPWS_Core::initModClass('hms', 'HMS_Util.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); $tpl = array(); $submitCmd = CommandFactory::getCommand('LotteryConfirm'); $submitCmd->setRoomId($this->roomId); $submitCmd->setMealPlan($this->mealPlan); $form = new PHPWS_Form(); $submitCmd->initForm($form); # Add the beds and user names back to the form so they end up in the request in a pretty way foreach ($this->roommates as $key => $value) { if (isset($value) && $value != '') { $form->addHidden("roommates[{$key}]", $value); } } # List the student's room PHPWS_Core::initModClass('hms', 'HMS_Room.php'); $room = new HMS_Room($this->roomId); $tpl['ROOM'] = $room->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(); $bedLabel = $room->getRoomNumber(); if ($room->get_number_of_beds() == 4) { $bedLabel = $bedLabel . $bed->getBedroomLabel(); } $bedLabel = $bedLabel . $bed->getLetter(); $bed_row['BED_LABEL'] = $bedLabel; $roommate = null; 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 { # Get the new roommate name out of the request if (!isset($this->roommates[$bed->id]) || $this->roommates[$bed->id] == '') { $bed_row['TEXT'] = 'Empty'; } else { $roommate = StudentFactory::getStudentByUsername($this->roommates[$bed->id], $this->term); $bed_row['TEXT'] = $roommate->getName() . ' ' . $this->roommates[$bed->id]; } } } $tpl['beds'][] = $bed_row; } # Show the meal plan $tpl['MEAL_PLAN'] = HMS_Util::formatMealOption($this->mealPlan); $form->addHidden('meal_plan', $this->mealPlan); PHPWS_Core::initCoreClass('Captcha.php'); $form->addTplTag('CAPTCHA_IMAGE', Captcha::get()); $form->addSubmit('submit_form', 'Confirm room & roommates'); $form->mergeTemplate($tpl); Layout::addPageTitle("Confirm Re-Application"); return PHPWS_Template::process($form->getTemplate(), 'hms', 'student/lottery_confirm.tpl'); }