public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php'); PHPWS_Core::initModClass('hms', 'exception/InvalidTermException.php'); $term = $context->get('term'); $username = UserStatus::getUsername(); $student = StudentFactory::getStudentByUsername($username, $term); $sem = Term::getTermSem($term); // Check for an existing application and delete it $app_result = HousingApplication::checkForApplication($username, $term); // If there's an existing housing application, handle deleting it if ($app_result !== FALSE) { switch ($sem) { case TERM_SPRING: $application = new SpringApplication($app_result['id']); break; case TERM_SUMMER1: case TERM_SUMMER2: $application = new SummerApplication($app_result['id']); break; case TERM_FALL: $application = new FallApplication($app_result['id']); break; default: throw new InvalidTermException('Invalid term specified.'); } // Save the old created on dates for re-use on new application $oldCreatedOn = $application->getCreatedOn(); $oldCreatedBy = $application->getCreatedBy(); $application->delete(); } switch ($sem) { case TERM_FALL: $appType = 'fall'; break; case TERM_SPRING: $appType = 'spring'; break; case TERM_SUMMER1: case TERM_SUMMER2: $appType = 'summer'; break; default: throw new Exception('Unknown application type'); } $application = HousingApplicationFactory::getApplicationFromSession($_SESSION['application_data'], $term, $student, $appType); // If old created dates exist, use them as the 'created on' dates if (isset($oldCreatedOn)) { $application->setCreatedOn($oldCreatedOn); $application->setCreatedBy($oldCreatedBy); } $application->setCancelled(0); // Hard code a summer meal option for all summer applications. // Application for other terms use whatever the student selected if ($sem == TERM_SUMMER1 || $sem == TERM_SUMMER2) { $application->setMealPlan(BANNER_MEAL_5WEEK); } $result = $application->save(); if ($result == TRUE) { // Log the fact that the application was submitted PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); HMS_Activity_Log::log_activity($username, ACTIVITY_SUBMITTED_APPLICATION, $username); try { // report the application to banner; $application->reportToBanner(); } catch (Exception $e) { // ignore any errors reporting this to banner, they'll be logged and admins notified // we've saved the student's application locally, so it's ok if this doesn't work } // Send the email confirmation PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_hms_application_confirmation($student, $application->getTerm()); } $friendly_term = Term::toString($application->getTerm()); NQ::simple('hms', hms\NotificationView::SUCCESS, "Your application for {$friendly_term} was successfully processed! You will receive an email confirmation in the next 24 hours."); PHPWS_Core::initModClass('hms', 'applicationFeature/RlcApplication.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); $rlcReg = new RLCApplicationRegistration(); if (ApplicationFeature::isEnabledForStudent($rlcReg, $term, $student) && HMS_RLC_Application::checkForApplication($student->getUsername(), $term) == FALSE && $application->rlc_interest == 1) { $rlcCmd = CommandFactory::getCommand('ShowRlcApplicationPage1View'); $rlcCmd->setTerm($term); $rlcCmd->redirect(); } else { $successCmd = CommandFactory::getCommand('ShowStudentMenu'); $successCmd->redirect(); } }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php'); session_write_close(); session_start(); $menuCmd = CommandFactory::getCommand('ShowStudentMenu'); if (!isset($_SESSION['RLC_REAPP'])) { $menuCmd->redirect(); } $reApp = $_SESSION['RLC_REAPP']; $term = $context->get('term'); $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term); $errorCmd = CommandFactory::getCommand('ShowRlcReapplicationPageTwo'); $errorCmd->setTerm($term); // Double check the the student is eligible $housingApp = HousingApplication::getApplicationByUser($student->getUsername(), $term); if (!$housingApp instanceof LotteryApplication) { NQ::simple('hms', hms\NotificationView::ERROR, 'You are not eligible to re-apply for a Learning Community.'); $menuCmd->redirect(); } // Make sure the user doesn't already have an application on file for this term $app = HMS_RLC_Application::checkForApplication($student->getUsername(), $term); if ($app !== FALSE) { NQ::simple('hms', hms\NotificationView::WARNING, 'You have already re-applied for a Learning Community for that term.'); $menuCmd->redirect(); } # Look up any existing RLC assignment (for the current term, should be the Spring term) //$rlcAssignment = HMS_RLC_Assignment::getAssignmentByUsername($student->getUsername(), Term::getPrevTerm(Term::getCurrentTerm())); $question0 = $context->get('rlc_question_0'); $question1 = $context->get('rlc_question_1'); $question2 = $context->get('rlc_question_2'); $reApp->rlc_question_0 = $question0; $reApp->rlc_question_1 = $question1; $reApp->rlc_question_2 = $question2; $_SESSION['RLC_REAPP'] = $reApp; //$rlcChoice0 = $reApp->rlc_first_choice_id; $rlcChoice1 = $reApp->rlc_second_choice_id; $rlcChoice2 = $reApp->rlc_third_choice_id; if (isset($rlcChoice1) && (!isset($question1) || empty($question1))) { NQ::simple('hms', hms\NotificationView::ERROR, 'Please respond to all of the short answer questions.'); $errorCmd->redirect(); } if (isset($rlcChoice2) && (!isset($question2) || empty($question2))) { NQ::simple('hms', hms\NotificationView::ERROR, 'Please respond to all of the short answer questions.'); $errorCmd->redirect(); } // Check response lengths $wordLimit = 500; if (str_word_count($question0) > $wordLimit) { NQ::simple('hms', hms\NotificationView::ERROR, 'Your answer to question number one is too long. Please limit your response to 500 words or less.'); $errorCmd->redirect(); } if (isset($rlcChoice2) && str_word_count($question1) > $wordLimit) { NQ::simple('hms', hms\NotificationView::ERROR, 'Your answer to question number two is too long. Please limit your response to 500 words or less.'); $errorCmd->redirect(); } if (isset($rlcChoice3) && str_word_count($question2) > $wordLimit) { NQ::simple('hms', hms\NotificationView::ERROR, 'Your answer to question number three is too long. Please limit your response to 500 words or less.'); $errorCmd->redirect(); } $reApp->setDateSubmitted(time()); $reApp->setRLCQuestion0($question0); $reApp->setRLCQuestion1($question1); $reApp->setRLCQuestion2($question2); $reApp->setTerm($term); $reApp->setApplicationType(RLC_APP_RETURNING); $reApp->setDeniedEmailSent(0); $reApp->save(); unset($_SESSION['RLC_REAPP']); // Redirect back to the main menu NQ::simple('hms', hms\NotificationView::SUCCESS, 'Your Residential Learning Community Re-application was saved successfully.'); $menuCmd->redirect(); }
/** * Depricated per ticket #530 * @deprecated */ public function check_rlc_applications() { PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); $result = HMS_RLC_Application::checkForApplication($this->requestor, $this->term, false); $resultb = HMS_RLC_Application::checkForApplication($this->requestee, $this->term, false); if ($result === false && $resultb === false) { return true; } if ($result === false || $resultb === false) { return false; } // Check to see if any of a's choices match any of b's choices if ($result['rlc_first_choice_id'] == $resultb['rlc_first_choice_id'] || $result['rlc_first_choice_id'] == $resultb['rlc_second_choice_id'] || $result['rlc_first_choice_id'] == $resultb['rlc_third_choice_id'] || $result['rlc_second_choice_id'] == $resultb['rlc_first_choice_id'] || $result['rlc_second_choice_id'] == $resultb['rlc_second_choice_id'] || $result['rlc_second_choice_id'] == $resultb['rlc_third_choice_id'] || $result['rlc_third_choice_id'] == $resultb['rlc_first_choice_id'] || $result['rlc_third_choice_id'] == $resultb['rlc_second_choice_id'] || $result['rlc_third_choice_id'] == $resultb['rrlc_third_choice_id']) { return true; } return false; }
public function show() { PHPWS_Core::initCoreClass('Form.php'); $form = new PHPWS_Form(); $submitCmd = CommandFactory::getCommand('HousingApplicationFormSubmit'); $submitCmd->setTerm($this->term); $submitCmd->initForm($form); $tpl = array(); /**************** * Display Info * ****************/ $tpl['STUDENT_NAME'] = $this->student->getFullName(); $tpl['GENDER'] = $this->student->getPrintableGender(); $tpl['ENTRY_TERM'] = Term::toString($this->student->getApplicationTerm()); $tpl['CLASSIFICATION_FOR_TERM_LBL'] = HMS_Util::formatClass($this->student->getClass()); $tpl['STUDENT_STATUS_LBL'] = HMS_Util::formatType($this->student->getType()); $tpl['TERM'] = Term::toString($this->term); /************** * Cell Phone * **************/ $form->addText('number'); $form->setSize('number', 10); $form->setMaxSize('number', 10); $form->addCssClass('number', 'form-control'); if (!is_null($this->existingApplication)) { $form->setValue('number', substr($this->existingApplication->getCellPhone(), 0)); } $form->addCheck('do_not_call', 1); if (!is_null($this->existingApplication) && is_null($this->existingApplication->getCellPhone())) { $form->setMatch('do_not_call', 1); } // This is just getting worse and worse. // TODO: this, correctly. $sem = Term::getTermSem($this->term); if ($sem == TERM_SPRING || $sem == TERM_FALL) { /************* * Lifestyle * *************/ // TODO: get rid of the magic numbers!!! $form->addDropBox('lifestyle_option', array('1' => _('Single Gender Building'), '2' => _('Co-Ed Building'))); if (!is_null($this->existingApplication)) { $form->setMatch('lifestyle_option', $this->existingApplication->getLifestyleOption()); } else { $form->setMatch('lifestyle_option', '1'); } $form->addCssClass('lifestyle_option', 'form-control'); /************ * Bed time * ************/ // TODO: magic numbers $form->addDropBox('preferred_bedtime', array('1' => _('Early'), '2' => _('Late'))); $form->setClass('preferred_bedtime', 'form-control'); if (!is_null($this->existingApplication)) { $form->setMatch('preferred_bedtime', $this->existingApplication->getPreferredBedtime()); } else { $form->setMatch('preferred_bedtime', '1'); } /****************** * Room condition * ******************/ //TODO: magic numbers $form->addDropBox('room_condition', array('1' => _('Neat'), '2' => _('Cluttered'))); if (!is_null($this->existingApplication)) { $form->setMatch('room_condition', $this->existingApplication->getRoomCondition()); } else { $form->setMatch('room_condition', '1'); } $form->addCssClass('room_condition', 'form-control'); } else { if ($sem == TERM_SUMMER1 || $sem == TERM_SUMMER2) { /* Private room option for Summer terms */ $form->addDropBox('room_type', array(ROOM_TYPE_DOUBLE => 'Two person', ROOM_TYPE_PRIVATE => 'Private (if available)')); $form->setClass('room_type', 'form-control'); if (!is_null($this->existingApplication)) { $form->setMatch('room_type', $this->existingApplication->getRoomType()); } else { $form->setMatch('room_type', '0'); } } } /********************* * Smoking Preference * *********************/ $form->addDropBox('smoking_preference', array('1' => _('No'), '2' => _('Yes'))); if (!is_null($this->existingApplication)) { $form->setMatch('smoking_preference', $this->existingApplication->getSmokingPreference()); } else { $form->setMatch('smoking_preference', '1'); } $form->addCssClass('smoking_preference', 'form-control'); /*************** * Meal Option * ***************/ if ($sem == TERM_FALL || $sem == TERM_SPRING) { if ($this->student->getType() == TYPE_FRESHMEN) { $mealOptions = array(BANNER_MEAL_STD => 'Standard', BANNER_MEAL_HIGH => 'High', BANNER_MEAL_SUPER => 'Super'); } else { $mealOptions = array(BANNER_MEAL_LOW => _('Low'), BANNER_MEAL_STD => _('Standard'), BANNER_MEAL_HIGH => _('High'), BANNER_MEAL_SUPER => _('Super')); } } else { if ($sem == TERM_SUMMER1 || $sem == TERM_SUMMER2) { $mealOptions = array(BANNER_MEAL_5WEEK => 'Summer 5-Week Plan'); } } $form->addDropBox('meal_option', $mealOptions); $form->setClass('meal_option', 'form-control'); $form->setMatch('meal_option', BANNER_MEAL_STD); $form->addCssClass('meal_option', 'form-control'); if (!is_null($this->existingApplication)) { $form->setMatch('meal_option', $this->existingApplication->getMealPlan()); } else { $form->setMatch('meal_option', BANNER_MEAL_STD); } /********************* * Emergency Contact * *********************/ $form->addText('emergency_contact_name'); $form->addCssClass('emergency_contact_name', 'form-control'); $form->addText('emergency_contact_relationship'); $form->addCssClass('emergency_contact_relationship', 'form-control'); $form->addText('emergency_contact_phone'); $form->addCssClass('emergency_contact_phone', 'form-control'); $form->addText('emergency_contact_email'); $form->addCssClass('emergency_contact_email', 'form-control'); $form->addTextArea('emergency_medical_condition'); $form->addCssClass('emergency_medical_condition', 'form-control'); $form->setRows('emergency_medical_condition', 4); if (!is_null($this->existingApplication)) { $form->setValue('emergency_contact_name', $this->existingApplication->getEmergencyContactName()); $form->setValue('emergency_contact_relationship', $this->existingApplication->getEmergencyContactRelationship()); $form->setValue('emergency_contact_phone', $this->existingApplication->getEmergencyContactPhone()); $form->setValue('emergency_contact_email', $this->existingApplication->getEmergencyContactEmail()); $form->setValue('emergency_medical_condition', $this->existingApplication->getEmergencyMedicalCondition()); } /** * Missing Person */ $form->addText('missing_person_name'); $form->addCssClass('missing_person_name', 'form-control'); $form->addText('missing_person_relationship'); $form->addCssClass('missing_person_relationship', 'form-control'); $form->addText('missing_person_phone'); $form->addCssClass('missing_person_phone', 'form-control'); $form->addText('missing_person_email'); $form->addCssClass('missing_person_email', 'form-control'); if (!is_null($this->existingApplication)) { $form->setValue('missing_person_name', $this->existingApplication->getMissingPersonName()); $form->setValue('missing_person_relationship', $this->existingApplication->getMissingPersonRelationship()); $form->setValue('missing_person_phone', $this->existingApplication->getMissingPersonPhone()); $form->setValue('missing_person_email', $this->existingApplication->getMissingPersonEmail()); } /** * Special needs */ $tpl['SPECIAL_NEEDS_TEXT'] = ''; // setting this template variable to anything causes the special needs text to be displayed $form->addCheck('special_need', array('special_need')); $form->setLabel('special_need', array('Yes, I require special needs housing.')); if (isset($this->existingApplication)) { if (!is_null($this->existingApplication->physical_disability) && $this->existingApplication->physical_disability != "0" || !is_null($this->existingApplication->psych_disability) && $this->existingApplication->psych_disability != "0" || !is_null($this->existingApplication->medical_need) && $this->existingApplication->medical_need != "0" || !is_null($this->existingApplication->gender_need) && $this->existingApplication->gender_need != "0") { $form->setMatch('special_need', 'special_need'); } } if (isset($_REQUEST['special_needs'])) { $form->addHidden('special_needs', $_REQUEST['special_needs']); } /******* * RLC * *******/ PHPWS_Core::initModClass('hms', 'applicationFeature/RlcApplication.php'); $rlcReg = new RLCApplicationRegistration(); if (HMS_RLC_Application::checkForApplication($this->student->getUsername(), $this->term) == TRUE) { // Student has an RLC application on file already $tpl['RLC_SUBMITTED'] = ''; $form->addHidden('rlc_interest', 0); } else { if (ApplicationFeature::isEnabledForStudent($rlcReg, $this->term, $this->student)) { // Feature is enabled, but student hasn't submitted one yet $form->addRadio('rlc_interest', array(0, 1)); $form->setLabel('rlc_interest', array(_("No"), _("Yes"))); if (!is_null($this->existingApplication) && !is_null($this->existingApplication->getRLCInterest())) { $form->setMatch('rlc_interest', 'rlc_interest'); } else { $form->setMatch('rlc_interest', '0'); } } else { // Feature is not enabled $form->addHidden('rlc_interest', 0); } } $tpl['CONTINUE_BTN'] = ''; $form->mergeTemplate($tpl); $tpl = $form->getTemplate(); Layout::addPageTitle("Housing Application Form"); return PHPWS_Template::process($tpl, 'hms', 'student/student_application.tpl'); }