public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php');
     $term = $context->get('term');
     // Application must exist
     $app = HMS_RLC_Application::getApplicationByUsername(UserStatus::getUsername(), $term);
     if (is_null($app)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'No RLC application exists.');
         $context->goBack();
     } else {
         if (!HMS_RLC_Assignment::checkForAssignment(UserStatus::getUsername(), $term)) {
             // Delete the app
             $app->delete();
             // Log it
             PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
             HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_RLC_APPLICATION_DELETED, UserStatus::getUsername());
             // Show a notification and go back
             NQ::simple('hms', hms\NotificationView::SUCCESS, 'RLC application deleted.');
             $context->goBack();
         } else {
             NQ::simple('hms', hms\NotificationView::WARNING, 'You have already been assigned to an RLC.');
             $context->goBack();
         }
     }
 }
 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;
 }
Exemplo n.º 3
0
 public function getMenuBlockView(Student $student)
 {
     // Get an application if one exists
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
     $application = HMS_RLC_Application::getApplicationByUsername($student->getUsername(), $this->getTerm());
     // Check for an assignment
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php');
     $assignment = HMS_RLC_Assignment::getAssignmentByUsername($student->getUsername(), $this->getTerm());
     PHPWS_Core::initModClass('hms', 'RlcApplicationMenuView.php');
     return new RlcApplicationMenuView($this->term, $student, $this->getStartDate(), $this->getEditDate(), $this->getEndDate(), $application, $assignment);
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
0
 public function show()
 {
     javascript('jquery');
     javascript('jquery_ui');
     javascriptMod('hms', 'StudentProfile');
     $tpl = array();
     $tpl['USERNAME'] = $this->student->getUsername();
     if (Current_User::allow('hms', 'login_as_student')) {
         $loginAsStudent = CommandFactory::getCommand('LoginAsStudent');
         $loginAsStudent->setUsername($this->student->getUsername());
         $tpl['LOGIN_AS_STUDENT_URI'] = $loginAsStudent->getURI();
     }
     $tpl['BANNER_ID'] = $this->student->getBannerId();
     $tpl['NAME'] = $this->student->getFullName();
     $tpl['TERM'] = Term::getPrintableSelectedTerm();
     $tpl['GENDER'] = $this->student->getPrintableGender();
     $tpl['DOB'] = $this->student->getDOB();
     if (strtotime($this->student->getDOB()) < strtotime("-25 years")) {
         NQ::simple('hms', hms\NotificationView::WARNING, 'Student is 25 years old or older!');
     }
     $tpl['CLASS'] = $this->student->getPrintableClass();
     $tpl['TYPE'] = $this->student->getPrintableType();
     $tpl['STUDENT_LEVEL'] = $this->student->getPrintableLevel();
     $tpl['ADMISSION_DECISION'] = $this->student->getAdmissionDecisionCode();
     $tpl['INTERNATIONAL'] = $this->student->isInternational() ? 'Yes' : 'No';
     $tpl['HONORS'] = $this->student->isHonors() ? 'Yes' : 'No';
     $tpl['TEACHING_FELLOW'] = $this->student->isTeachingFellow() ? 'Yes' : 'No';
     $tpl['WATAUGA'] = $this->student->isWataugaMember() ? 'Yes' : 'No';
     if ($this->student->pinDisabled()) {
         NQ::simple('hms', hms\NotificationView::WARNING, "This student's PIN is disabled.");
     }
     try {
         $tpl['APPLICATION_TERM'] = Term::toString($this->student->getApplicationTerm());
     } catch (InvalidTermException $e) {
         NQ::simple('hms', hms\NotificationView::WARNING, 'Application term is bad or missing.');
         $tpl['APPLICATION_TERM'] = 'WARNING: Application Term is bad or missing: "' . $this->student->getApplicationTerm() . '"';
     }
     /*****************
      * Phone Numbers *
      *****************/
     $phoneNumberList = $this->student->getPhoneNumberList();
     if (isset($phoneNumberList) && !is_null($phoneNumberList)) {
         foreach ($this->student->getPhoneNumberList() as $phone_number) {
             $tpl['phone_number'][] = array('NUMBER' => $phone_number);
         }
     }
     /*************
      * Addresses *
      *************/
     foreach ($this->student->getAddressList() as $address) {
         //If it's not a PS or PR address, skip it
         if ($address->atyp_code != 'PR' && $address->atyp_code != 'PS') {
             continue;
         }
         switch ($address->atyp_code) {
             case 'PS':
                 $addr_type = 'Student Address';
                 break;
             case 'PR':
                 $addr_type = 'Permanent Residence Address';
                 break;
             default:
                 $addr_type = 'Unknown-type address';
         }
         $addr_array = array();
         $addr_array['ADDR_TYPE'] = $addr_type;
         $addr_array['ADDRESS_L1'] = $address->line1;
         if (isset($address->line2)) {
             $addr_array['ADDRESS_L2'] = $address->line2;
         }
         if (isset($address->line3)) {
             $addr_array['ADDRESS_L3'] = $address->line3;
         }
         $addr_array['CITY'] = $address->city;
         $addr_array['STATE'] = $address->state;
         $addr_array['ZIP'] = $address->zip;
         $tpl['addresses'][] = $addr_array;
     }
     /**************
      * Assignment *
      **************/
     if (!is_null($this->assignment)) {
         $reassignCmd = CommandFactory::getCommand('ShowAssignStudent');
         $reassignCmd->setUsername($this->student->getUsername());
         $unassignCmd = CommandFactory::getCommand('ShowUnassignStudent');
         $unassignCmd->setUsername($this->student->getUsername());
         $tpl['ASSIGNMENT'] = $this->assignment->where_am_i(true) . ' ' . $reassignCmd->getLink('Reassign') . ' ' . $unassignCmd->getLink('Unassign');
     } else {
         $assignCmd = CommandFactory::getCommand('ShowAssignStudent');
         $assignCmd->setUsername($this->student->getUsername());
         $tpl['NOT_ASSIGNED'] = $assignCmd->getURI();
     }
     /*************
      * Roommates
      *************/
     if (isset($this->roommates) && !empty($this->roommates)) {
         // Remember, student can only have one confirmed or pending request
         // but multiple assigned roommates
         if (isset($this->roommates['PENDING'])) {
             $tpl['pending'][]['ROOMMATE'] = $this->roommates['PENDING'];
         } else {
             if (isset($this->roommates['CONFIRMED'])) {
                 $tpl['confirmed'][]['ROOMMATE'] = $this->roommates['CONFIRMED'];
             } else {
                 if (isset($this->roommates['NO_BED_AVAILABLE'])) {
                     $tpl['error_status'][]['ROOMMATE'] = $this->roommates['NO_BED_AVAILABLE'];
                 } else {
                     if (isset($this->roommates['MISMATCHED_ROOMS'])) {
                         $tpl['error_status'][]['ROOMMATE'] = $this->roommates['MISMATCHED_ROOMS'];
                     }
                 }
             }
         }
         if (isset($this->roommates['ASSIGNED'])) {
             foreach ($this->roommates['ASSIGNED'] as $roommate) {
                 $tpl['assigned'][]['ROOMMATE'] = $roommate;
             }
         }
     }
     /**************
      * RLC Status *
      *************/
     $rlc_names = RlcFactory::getRlcList(Term::getSelectedTerm());
     $rlc_assignment = HMS_RLC_Assignment::getAssignmentByUsername($this->student->getUsername(), Term::getSelectedTerm());
     $rlc_application = HMS_RLC_Application::getApplicationByUsername($this->student->getUsername(), Term::getSelectedTerm());
     if (!is_null($rlc_assignment)) {
         $tpl['RLC_STATUS'] = "This student is assigned to: " . $rlc_names[$rlc_assignment->rlc_id];
     } else {
         if (!is_null($rlc_application)) {
             $rlcViewCmd = CommandFactory::getCommand('ShowRlcApplicationReView');
             $rlcViewCmd->setAppId($rlc_application->getId());
             $tpl['RLC_STATUS'] = "This student has a " . $rlcViewCmd->getLink('pending RLC application') . ".";
         } else {
             $tpl['RLC_STATUS'] = "This student is not in a Learning Community and has no pending application.";
         }
     }
     /*************************
      * Re-application status *
      *************************/
     $reapplication = HousingApplicationFactory::getAppByStudent($this->student, Term::getSelectedTerm());
     # If this is a re-application, then check the special interest group status
     # TODO: incorporate all this into the LotteryApplication class
     if ($reapplication !== FALSE && $reapplication instanceof LotteryApplication) {
         if (isset($reapplication->special_interest) && !is_null($reapplication->special_interest) && !empty($reapplication->special_interest)) {
             # Student has been approved for a special group
             # TODO: format the name according to the specific group (sororities, etc)
             $tpl['SPECIAL_INTEREST'] = $reapplication->special_interest . '(confirmed)';
         } else {
             # Check if the student selected a group on the application, but hasn't been approved
             if (!is_null($reapplication->sorority_pref)) {
                 $tpl['SPECIAL_INTEREST'] = $reapplication->sorority_pref . ' (pending)';
                 //}else if($reapplication->tf_pref == 1){
                 //$tpl['SPECIAL_INTEREST'] = 'Teaching Fellow (pending)';
             } else {
                 if ($reapplication->wg_pref == 1) {
                     $tpl['SPECIAL_INTEREST'] = 'Watauga Global (pending)';
                 } else {
                     if ($reapplication->honors_pref == 1) {
                         $tpl['SPECIAL_INTEREST'] = 'Honors (pending)';
                     } else {
                         if ($reapplication->rlc_interest == 1) {
                             $tpl['SPECIAL_INTEREST'] = 'RLC (pending)';
                         } else {
                             # Student didn't select anything
                             $tpl['SPECIAL_INTEREST'] = 'No';
                         }
                     }
                 }
             }
         }
     } else {
         # Not a re-application, so can't have a special group
         $tpl['SPECIAL_INTEREST'] = 'No';
     }
     /******************
      * Housing Waiver *
      *************/
     $tpl['HOUSING_WAIVER'] = $this->student->housingApplicationWaived() ? 'Yes' : 'No';
     if ($this->student->housingApplicationWaived()) {
         NQ::simple('hms', hms\NotificationView::WARNING, "This student's housing application has been waived for this term.");
     }
     /****************
      * Applications *
      *************/
     $appList = new ProfileHousingAppList($this->applications);
     $tpl['APPLICATIONS'] = $appList->show();
     /*********
      * Assignment History *
      *********/
     $historyArray = StudentAssignmentHistory::getAssignments($this->student->getBannerId());
     $historyView = new StudentAssignmentHistoryView($historyArray);
     $tpl['HISTORY'] = $historyView->show();
     /**********
      * Checkins
      */
     $checkins = CheckinFactory::getCheckinsForStudent($this->student);
     $checkinHistory = new CheckinHistoryView($checkins);
     $tpl['CHECKINS'] = $checkinHistory->show();
     /*********
      * Notes *
      *********/
     $addNoteCmd = CommandFactory::getCommand('AddNote');
     $addNoteCmd->setUsername($this->student->getUsername());
     $form = new PHPWS_Form('add_note_dialog');
     $addNoteCmd->initForm($form);
     $form->addTextarea('note');
     $form->addSubmit('Add Note');
     /********
      * Logs *
      ********/
     $everything_but_notes = HMS_Activity_Log::get_activity_list();
     unset($everything_but_notes[array_search(ACTIVITY_ADD_NOTE, $everything_but_notes)]);
     if (Current_User::allow('hms', 'view_activity_log') && Current_User::allow('hms', 'view_student_log')) {
         PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
         $activityLogPager = new ActivityLogPager($this->student->getUsername(), null, null, true, null, null, $everything_but_notes, true, 10);
         $activityNotePager = new ActivityLogPager($this->student->getUsername(), null, null, true, null, null, array(0 => ACTIVITY_ADD_NOTE), true, 10);
         $tpl['LOG_PAGER'] = $activityLogPager->show();
         $tpl['NOTE_PAGER'] = $activityNotePager->show();
         $logsCmd = CommandFactory::getCommand('ShowActivityLog');
         $logsCmd->setActeeUsername($this->student->getUsername());
         $tpl['LOG_PAGER'] .= $logsCmd->getLink('View more');
         $notesCmd = CommandFactory::getCommand('ShowActivityLog');
         $notesCmd->setActeeUsername($this->student->getUsername());
         $notesCmd->setActivity(array(0 => ACTIVITY_ADD_NOTE));
         $tpl['NOTE_PAGER'] .= $notesCmd->getLink('View more');
     }
     $tpl = array_merge($tpl, $form->getTemplate());
     // TODO logs
     // TODO tabs
     Layout::addPageTitle("Student Profile");
     return PHPWS_Template::process($tpl, 'hms', 'admin/StudentProfile.tpl');
 }
Exemplo n.º 6
0
 public function show()
 {
     // TODO: Load application in controller and pass it to HousingApplicationView constructor.
     $application = HousingApplicationFactory::getApplicationById($this->id);
     $student = StudentFactory::getStudentByUsername($application->username, $application->term);
     $tpl = array();
     //If the application has been submitted plug in the date it was created
     if (isset($application->created_on)) {
         $tpl['RECEIVED_DATE'] = "Received on: " . date('d-F-Y h:i:s a', $application->created_on);
     }
     if ($application instanceof LotteryApplication && $application->getWaitingListDate() != null) {
         $tpl['WAITING_LIST_DATE'] = date("d-F-y h:i:sa", $application->getWaitingListDate());
     }
     // Check if the application has been cancelled
     // isWithdrawn() has been depricated, but I'm leaving it here just for historical sake
     // on the off-chance that it catches an older application that's withdrawn but not cancelled.
     if ($application->isCancelled() || $application->isWithdrawn()) {
         NQ::simple('hms', hms\NotificationView::WARNING, 'This application has been cancelled.');
     }
     $tpl['STUDENT_NAME'] = $student->getFullName();
     $tpl['GENDER'] = $student->getPrintableGender();
     $tpl['ENTRY_TERM'] = Term::toString($application->term);
     $tpl['CLASSIFICATION_FOR_TERM_LBL'] = $student->getPrintableClass();
     $tpl['STUDENT_STATUS_LBL'] = $student->getPrintableType();
     $tpl['MEAL_OPTION'] = HMS_Util::formatMealOption($application->meal_plan);
     if (isset($application->lifestyle_option)) {
         $tpl['LIFESTYLE_OPTION'] = $application->lifestyle_option == 1 ? 'Single gender' : 'Co-ed';
     } else {
         $tpl['LIFESTYLE_OPTION'] = 'n/a';
     }
     if (isset($application->preferred_bedtime)) {
         $tpl['PREFERRED_BEDTIME'] = $application->preferred_bedtime == 1 ? 'Early' : 'Late';
     } else {
         $tpl['PREFERRED_BEDTIME'] = 'n/a';
     }
     if (isset($application->room_condition)) {
         $tpl['ROOM_CONDITION'] = $application->room_condition == 1 ? 'Neat' : 'Cluttered';
     } else {
         $tpl['ROOM_CONDITION'] = 'n/a';
     }
     if (isset($application->smoking_preference)) {
         $tpl['SMOKING_PREFERENCE'] = $application->smoking_preference == 1 ? 'No' : 'Yes';
     } else {
         $tpl['SMOKING_PREFERENCE'] = 'n/a';
     }
     if (isset($application->room_type)) {
         $tpl['ROOM_TYPE'] = $application->room_type == ROOM_TYPE_DOUBLE ? 'Double' : 'Private (if available)';
     }
     $tpl['CELLPHONE'] = '';
     if (strlen($application->cell_phone) == 10) {
         $tpl['CELLPHONE'] .= '(' . substr($application->cell_phone, 0, 3) . ')';
         $tpl['CELLPHONE'] .= '-' . substr($application->cell_phone, 3, 3);
         $tpl['CELLPHONE'] .= '-' . substr($application->cell_phone, 6, 4);
     }
     /* Emergency Contact */
     $tpl['EMERGENCY_CONTACT_NAME'] = $application->getEmergencyContactName();
     $tpl['EMERGENCY_CONTACT_RELATIONSHIP'] = $application->getEmergencyContactRelationship();
     $tpl['EMERGENCY_CONTACT_PHONE'] = $application->getEmergencyContactPhone();
     $tpl['EMERGENCY_CONTACT_EMAIL'] = $application->getEmergencyContactEmail();
     $tpl['EMERGENCY_MEDICAL_CONDITION'] = $application->getEmergencyMedicalCondition();
     /* Missing Person */
     if (Current_User::allow('hms', 'view_missing_person_info')) {
         $tpl['MISSING_PERSON_NAME'] = $application->getMissingPersonName();
         $tpl['MISSING_PERSON_RELATIONSHIP'] = $application->getMissingPersonRelationship();
         $tpl['MISSING_PERSON_PHONE'] = $application->getMissingPersonPhone();
         $tpl['MISSING_PERSON_EMAIL'] = $application->getMissingPersonEmail();
     }
     /* Special Needs */
     $special_needs = "";
     if ($application->physical_disability == 1) {
         $special_needs = 'Physical disability<br />';
     }
     if ($application->psych_disability) {
         $special_needs .= 'Psychological disability<br />';
     }
     if ($application->medical_need) {
         $special_needs .= 'Medical need<br />';
     }
     if ($application->gender_need) {
         $special_needs .= 'Gender need<br />';
     }
     if ($special_needs == '') {
         $special_needs = 'None';
     }
     $tpl['SPECIAL_NEEDS_RESULT'] = $special_needs;
     if ($application instanceof FallApplication) {
         PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
         $rlcApp = HMS_RLC_Application::getApplicationByUsername($student->getUsername(), $application->getTerm());
         if (!is_null($rlcApp)) {
             $tpl['RLC_INTEREST_1'] = 'Yes (Completed - Use the main menu to view/modify.)';
         } else {
             $tpl['RLC_INTEREST_1'] = $application->rlc_interest == 0 ? 'No' : 'Yes';
         }
     }
     if (Current_User::getUsername() == "hms_student") {
         $tpl['MENU_LINK'] = PHPWS_Text::secureLink('Back to main menu', 'hms', array('type' => 'student', 'op' => 'show_main_menu'));
     }
     Layout::addPageTitle("Housing Application");
     return PHPWS_Template::process($tpl, 'hms', 'admin/student_application.tpl');
 }
Exemplo n.º 7
0
 /**
  * Handles removing RLC applications.
  * @param Student $student
  */
 private function handleRlcApplication(Student $student)
 {
     // Mark any RLC applications as denied
     $rlcApp = HMS_RLC_Application::getApplicationByUsername($student->getUsername(), $this->term);
     if (!is_null($rlcApp)) {
         // TODO catch/handle exceptions
         $rlcApp->delete();
         $this->actions[$student->getUsername()][] = 'Marked RLC application as denied.';
         HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_WITHDRAWN_RLC_APP_DENIED, UserStatus::getUsername(), 'Withdrawn search');
     }
 }
Exemplo n.º 8
0
 /**
  * TODO: Deprecate this and/or move to RlcMembershipFactory
  * @see RlcMembershipFactory
  *
  * @param unknown $username
  * @param unknown $term
  * @throws DatabaseException
  * @return NULL|HMS_RLC_Assignment
  */
 public static function getAssignmentByUsername($username, $term)
 {
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
     $app = HMS_RLC_Application::getApplicationByUsername($username, $term);
     if (is_null($app)) {
         return null;
     }
     $assignment = new HMS_RLC_Assignment();
     $db = new PHPWS_DB('hms_learning_community_assignment');
     $db->addWhere('application_id', $app->id);
     $result = $db->loadObject($assignment);
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     if (is_null($assignment->id)) {
         return null;
     }
     return $assignment;
 }
 public function execute(CommandContext $context)
 {
     $term = $context->get('term');
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), Term::getCurrentTerm());
     $errorCmd = CommandFactory::getCommand('ShowRlcApplicationView');
     $errorCmd->setTerm($term);
     $choice1 = new HMS_Learning_Community($context->get('rlc_first_choice'));
     $choice2 = new HMS_Learning_Community($context->get('rlc_second_choice'));
     $choice3 = new HMS_Learning_Community($context->get('rlc_third_choice'));
     if (!$choice1->allowStudentType($student->getType()) || $choice2->id != -1 && !$choice2->allowStudentType($student->getType()) || $choice3->id != -1 && !$choice3->allowStudentType($student->getType())) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, you cannot apply for the selected RLC. Please contact University Housing if you believe this to be in error.');
         $errorCmd->redirect();
     }
     // Check the lengths of the responses to the short answer questions
     $question0 = $context->get('rlc_question_0');
     $question1 = $context->get('rlc_question_1');
     $question2 = $context->get('rlc_question_2');
     $whySpecific = $context->get('why_specific_communities');
     $strengthsWeaknesses = $context->get('strengths_weaknesses');
     if (str_word_count($whySpecific) > HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Your respose to the question is too long. Please limit your response to ' . HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT . ' words.');
         $errorCmd->redirect();
     }
     if (str_word_count($strengthsWeaknesses) > HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Your respose to the question is too long. Please limit your response to ' . HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT . ' words.');
         $errorCmd->redirect();
     }
     if (str_word_count($question0) > HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Your respose to the first question is too long. Please limit your response to ' . HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT . ' words.');
         $errorCmd->redirect();
     }
     if (str_word_count($question1) > HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Your respose to the second question is too long. Please limit your response to ' . HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT . ' words.');
         $errorCmd->redirect();
     }
     if (str_word_count($question2) > HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Your respose to the third question is too long. Please limit your response to ' . HMS_RLC_Application::RLC_RESPONSE_WORD_LIMIT . ' words.');
         $errorCmd->redirect();
     }
     // Check for an existing application and delete it
     $oldApp = HMS_RLC_Application::getApplicationByUsername($student->getUsername(), $term);
     if (isset($oldApp) && $oldApp->id != NULL) {
         //TODO check if the student has already been assigned to an RLC via the old application
         // Delete the old application to make way for this one
         try {
             $oldApp->delete();
         } catch (Exception $e) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, an error occured while attempting to replace your existing Residential Learning Community Application.  If this problem persists please contact University Housing.');
             $errorCmd->redirect();
         }
     }
     // Setup the new application
     $application = new HMS_RLC_Application();
     $application->setUsername($student->getUsername());
     $application->setDateSubmitted(time());
     $application->setFirstChoice($context->get('rlc_first_choice'));
     $application->setSecondChoice($choice2->id > 0 ? $choice2->id : NULL);
     $application->setThirdChoice($choice3->id > 0 ? $choice3->id : NULL);
     $application->setWhySpecificCommunities($context->get('why_specific_communities'));
     $application->setStrengthsWeaknesses($context->get('strengths_weaknesses'));
     $application->setRLCQuestion0($context->get('rlc_question_0'));
     $application->setRLCQuestion1(is_null($context->get('rlc_question_1')) ? '' : $context->get('rlc_question_1'));
     $application->setRLCQuestion2(is_null($context->get('rlc_question_2')) ? '' : $context->get('rlc_question_2'));
     $application->setEntryTerm($context->get('term'));
     $application->setApplicationType(RLC_APP_FRESHMEN);
     try {
         $application->save();
     } catch (Exception $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, an error occured while attempting to submit your application.  If this problem persists please contact University Housing.');
         $errorCmd->redirect();
     }
     # Log that this happened
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_SUBMITTED_RLC_APPLICATION, $student->getUsername());
     # Send the notification email
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     HMS_Email::send_rlc_application_confirmation($student);
     # Show a success message and redirect
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Your Residential Learning Community (RLC) application has been successfully submitted. You should receive a confirmation email (sent to your Appalachian State email account) soon. Notification of your acceptance into an RLC will also be sent to your Appalachian State email account.  Please continue to check your ASU email account regularly.  For more information on the RLC acceptance timeline or frequently asked questions, please visit <a href="http://housing.appstate.edu/rlc" target="_blank">housing.appstate.edu/rlc</a>.');
     $cmd = CommandFactory::getCommand('ShowStudentMenu');
     $cmd->redirect();
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'RlcReapplicationView.php');
     PHPWS_Core::initModClass('hms', 'HMS_Learning_Community.php');
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php');
     $errorCmd = CommandFactory::getCommand('ShowStudentMenu');
     $term = $context->get('term');
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     // Check deadlines
     PHPWS_Core::initModClass('hms', 'ApplicationFeature.php');
     $feature = ApplicationFeature::getInstanceByNameAndTerm('RlcReapplication', $term);
     if (is_null($feature) || !$feature->isEnabled()) {
         NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, RLC re-applications are not avaialable for this term.");
         $errorCmd->redirect();
     }
     if ($feature->getStartDate() > time()) {
         NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, it is too soon to submit a RLC re-application.");
         $errorCmd->redirect();
     } else {
         if ($feature->getEndDate() < time()) {
             NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, the RLC re-application deadline has already passed. Please contact University Housing if you are interested in applying for a RLC.");
             $errorCmd->redirect();
         }
     }
     // 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 Residential Learning Community.');
         $errorCmd->redirect();
     }
     // Make sure that the student has not already applied for this term
     $rlcApp = HMS_RLC_Application::getApplicationByUsername($student->getUsername(), $term);
     if (!is_null($rlcApp)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You have already re-applied for a Residential Learning Community for this term.');
         $errorCmd->redirect();
     }
     // Look up any existing RLC assignment (for the fall term; current term should be the Spring term, so the previous term should be the Fall)
     $rlcAssignment = HMS_RLC_Assignment::getAssignmentByUsername($student->getUsername(), Term::getPrevTerm(Term::getCurrentTerm()));
     // Get the list of RLCs that the student is eligible for
     // Note: hard coded to 'C' because we know they're continuing at this point.
     // This accounts for freshmen addmitted in the spring, who will still have the 'F' type.
     $communities = HMS_Learning_Community::getRlcListReapplication(false, 'C');
     // If the student has an existing assignment, and that community always allows returning students, then make sure the community is in the list (if it's not already)
     if (isset($rlcAssignment)) {
         // Load the RLC
         $rlc = $rlcAssignment->getRlc();
         // If members can always reapply, make sure community id exists as an array index
         if ($rlc->getMembersReapply() == 1 && !isset($communities[$rlc->get_id()])) {
             $communities[$rlc->get_id()] = $rlc->get_community_name();
         }
     }
     session_write_close();
     session_start();
     if (isset($_SESSION['RLC_REAPP'])) {
         $reApp = $_SESSION['RLC_REAPP'];
     } else {
         $reApp = null;
     }
     $view = new RlcReapplicationView($student, $term, $rlcAssignment, $communities, $reApp);
     $context->setContent($view->show());
 }