public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     $requestId = $context->get('requestId');
     $errorCmd = CommandFactory::getCommand('LotteryShowDenyRoommateRequest');
     $errorCmd->setRequestId($requestId);
     # 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();
     }
     # Get the roommate request
     $request = HMS_Lottery::get_lottery_roommate_invite_by_id($context->get('requestId'));
     # Make sure that the logged in user is the same as the confirming the request
     if (UserStatus::getUsername() != $request['asu_username']) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid roommate request. You can not confirm that roommate request.');
         $errorCmd->redirect();
     }
     # Deny the roommate requst
     try {
         HMS_Lottery::denyRoommateRequest($requestId);
     } catch (Exception $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error denying the roommate request. Please contact University Housing.');
         $errorCmd->redirect();
     }
     # Log that it happened
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_LOTTERY_ROOMMATE_DENIED, UserStatus::getUsername(), 'Captcha words: ' . $captcha);
     # Success
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'The roommate request was successfully declined.');
     $successCmd = CommandFactory::getCommand('ShowStudentMenu');
     $successCmd->redirect();
 }
예제 #2
0
파일: FaxPager.php 프로젝트: sinkdb/faxserv
 public function __construct($type = 'default')
 {
     PHPWS_Core::initCoreClass('DBPager.php');
     PHPWS_Core::initModClass('faxmaster', 'Fax.php');
     $this->pager = new DBPager('faxmaster_fax', 'Fax');
     $this->pager->setModule('faxmaster');
     $this->pager->setLink('index.php?module=faxmaster');
     // Don't show hidden faxes
     $this->pager->addWhere('hidden', 0);
     // By default, sort the faxes in reverse chronological order
     $this->pager->setOrder('dateReceived', 'DESC', true);
     if ($type == 'archived') {
         $this->pager->setTemplate('archivePager.tpl');
         $this->pager->setEmptyMessage('No archived faxes found.');
         $this->pager->addRowTags('pagerRowTags', 'archived');
         $this->pager->addWhere('archived', 1);
         $this->pager->setSearch('bannerId', 'firstName', 'lastName', 'whichArchive');
     } else {
         $this->pager->setTemplate('faxPager.tpl');
         $this->pager->setEmptyMessage('No faxes found.');
         $this->pager->addRowTags('pagerRowTags');
         $this->pager->addPageTags(array('UNPRINTED_COUNT' => Fax::getUnprintedCount()));
         $this->pager->addWhere('archived', 0);
         $this->pager->setSearch('bannerId', 'firstName', 'lastName');
     }
 }
 public function execute(CommandContext $context)
 {
     $id = $context->get('roommateId');
     if (is_null($id)) {
         throw new InvalidArgumentException('Must set roommateId');
     }
     PHPWS_Core::initModClass('hms', 'HMS_Roommate.php');
     $roommate = new HMS_Roommate($id);
     if ($roommate->id = 0) {
         throw new InvalidArgumentException('Invalid roommateId ' . $id);
     }
     $username = UserStatus::getUsername();
     if ($username != $roommate->requestor && $username != $roommate->requestee) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException("{$username} tried to break roommate pairing {$roommate->id}");
     }
     PHPWS_Core::initCoreClass('Captcha.php');
     // get other roommate
     $other = StudentFactory::getStudentByUsername($roommate->get_other_guy($username), $roommate->term);
     $form = new PHPWS_Form();
     $cmd = CommandFactory::getCommand('RoommateBreak');
     $cmd->setRoommateId($id);
     $cmd->initForm($form);
     $form->addTplTag('CAPTCHA_IMAGE', Captcha::get());
     $form->addTplTag('NAME', $other->getFullName());
     $form->addSubmit('Confirm');
     $form->addCssClass('submit', 'btn btn-danger');
     $context->setContent(PHPWS_Template::process($form->getTemplate(), 'hms', 'student/roommate_break_confirm.tpl'));
 }
예제 #4
0
 public function show()
 {
     PHPWS_Core::initCoreClass('Form.php');
     javascript('jquery');
     javascript('modules/hms/assign_student');
     $unassignCmd = CommandFactory::getCommand('UnassignStudent');
     $form = new PHPWS_Form();
     $unassignCmd->initForm($form);
     $form->addText('username');
     if (!is_null($this->student)) {
         $form->setValue('username', $this->student->getUsername());
     }
     $form->addCssClass('username', 'form-control');
     $form->setExtra('username', 'autofocus');
     // Addition of "Unassignment Type"
     $form->addDropBox('unassignment_type', array('-1' => 'Choose a reason...', UNASSIGN_ADMIN => 'Administrative', UNASSIGN_REASSIGN => 'Re-assign', UNASSIGN_CANCEL => 'Contract Cancellation', UNASSIGN_PRE_SPRING => 'Pre-spring room change', UNASSIGN_RELEASE => 'Contract Release'));
     //$form->setMatch('unassignment_type', UNASSIGN_ADMIN);
     $form->setLabel('unassignment_type', 'Unassignment Type: ');
     $form->addCssClass('unassignment_type', 'form-control');
     $form->addText('refund');
     $form->setLabel('refund', 'Refund Percentage');
     $form->setSize('refund', 4);
     $form->setMaxSize('refund', 3);
     $form->addCssClass('refund', 'form-control');
     $form->addTextarea('note');
     $form->setLabel('note', 'Note: ');
     $form->addCssClass('note', 'form-control');
     $tpl = $form->getTemplate();
     $tpl['TERM'] = Term::getPrintableSelectedTerm();
     Layout::addPageTitle("Unassign Student");
     return PHPWS_Template::process($tpl, 'hms', 'admin/unassignStudent.tpl');
 }
 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 show()
 {
     $f = $this->feature;
     $reg = $f->getRegistration();
     PHPWS_Core::initCoreClass('Form.php');
     $form = new PHPWS_Form($reg->getName());
     $cmd = CommandFactory::getCommand('SaveApplicationFeature');
     if ($f->getId() < 1) {
         $cmd->setName($reg->getName());
         $cmd->setTerm($f->getTerm());
     } else {
         $cmd->setFeatureId($f->getId());
     }
     $cmd->initForm($form);
     // TODO: Command Business
     $form->addCheck('enabled');
     if ($f->isEnabled()) {
         $form->setMatch('enabled', true);
     }
     $form->setLabel('enabled', $reg->getDescription());
     if ($reg->requiresStartDate()) {
         $form->addText('start_date');
         $form->setExtra('start_date', 'class="datepicker"');
         if (!is_null($f->getStartDate())) {
             $form->setValue('start_date', strftime('%m/%d/%Y', $f->getStartDate()));
         }
         $form->setLabel('start_date', dgettext('hms', 'Start Date:'));
         $form->addCssClass('start_date', 'form-control');
         $form->addCssClass('start_date', 'datepicker');
     }
     if ($reg->requiresEditDate()) {
         $form->addText('edit_date');
         if (!is_null($f->getEditDate())) {
             $form->setValue('edit_date', strftime('%m/%d/%Y', $f->getEditDate()));
         }
         $form->setLabel('edit_date', dgettext('hms', 'Edit Date:'));
         $form->addCssClass('edit_date', 'form-control');
         $form->addCssClass('edit_date', 'datepicker');
     }
     if ($reg->requiresEndDate()) {
         $form->addText('end_date');
         if (!is_null($f->getEndDate())) {
             $form->setValue('end_date', strftime('%m/%d/%Y', $f->getEndDate()));
         }
         $form->setLabel('end_date', dgettext('hms', 'End Date:'));
         $form->addCssClass('end_date', 'form-control');
         $form->addCssClass('end_date', 'datepicker');
     }
     $form->addSubmit('Save');
     $form->addReset('Undo');
     javascript('datepicker');
     $vars = array('FORM_SELECT' => '.app-feature-setting form', 'ENABLE_SELECT' => 'input[name="enabled"]', 'HIDDEN_SELECT' => '.app-feature-setting-hidable', 'SUBMIT_SELECT' => '.app-feature-setting-submit');
     javascript('modules/hms/ajaxForm', $vars);
     $tpl = $form->getTemplate();
     return PHPWS_Template::process($tpl, 'hms', 'admin/ApplicationFeatureSettingsView.tpl');
 }
 public function show()
 {
     PHPWS_Core::initCoreClass('Form.php');
     $form = new PHPWS_Form();
     $submitCmd = CommandFactory::getCommand('EmergencyContactFormSubmit');
     $submitCmd->setTerm($this->term);
     $submitCmd->initForm($form);
     $tpl = array();
     /****************
      * Display Info *
      ****************/
     $tpl['TERM'] = Term::toString($this->term);
     $tpl['STUDENT_NAME'] = $this->student->getFullName();
     /*********************
      * 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');
     if (!is_null($this->application)) {
         $form->setValue('emergency_contact_name', $this->application->getEmergencyContactName());
         $form->setValue('emergency_contact_relationship', $this->application->getEmergencyContactRelationship());
         $form->setValue('emergency_contact_phone', $this->application->getEmergencyContactPhone());
         $form->setValue('emergency_contact_email', $this->application->getEmergencyContactEmail());
         $form->setValue('emergency_medical_condition', $this->application->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->application)) {
         $form->setValue('missing_person_name', $this->application->getMissingPersonName());
         $form->setValue('missing_person_relationship', $this->application->getMissingPersonRelationship());
         $form->setValue('missing_person_phone', $this->application->getMissingPersonPhone());
         $form->setValue('missing_person_email', $this->application->getMissingPersonEmail());
     }
     $form->mergeTemplate($tpl);
     $tpl = $form->getTemplate();
     Layout::addPageTitle("Emergency Contact Form");
     return PHPWS_Template::process($tpl, 'hms', 'student/emergency_contact_form.tpl');
 }
예제 #8
0
 public static function shortcuts()
 {
     if (!Current_User::allow('access')) {
         Current_User::disallow();
         return;
     }
     $modal = new Modal('access-shortcut', null, dgettext('access', 'Shortcuts'));
     $modal->sizeSmall();
     $button = '<button class="btn btn-success" id="save-shortcut">Save</button>';
     $modal->addButton($button);
     \Layout::add((string) $modal);
     javascript('jquery');
     \Layout::includeJavascript('mod/access/javascript/access.min.js');
     PHPWS_Core::initModClass('access', 'Shortcut.php');
     PHPWS_Core::initCoreClass('DBPager.php');
     $pager = new DBPager('access_shortcuts', 'Access_Shortcut');
     $pager->setModule('access');
     $pager->setTemplate('forms/shortcut_list.tpl');
     $pager->setLink('index.php?module=access&amp;tab=shortcuts');
     $pager->addToggle('class="bgcolor1"');
     $pager->setSearch('keyword');
     $form = new PHPWS_Form('shortcut_list');
     $form->addHidden('module', 'access');
     $form->addHidden('command', 'post_shortcut_list');
     $options['none'] = '';
     if (Current_User::allow('access', 'admin_options')) {
         $options['active'] = dgettext('access', 'Activate');
         $options['deactive'] = dgettext('access', 'Deactivate');
     }
     $options['delete'] = dgettext('access', 'Delete');
     $form->addSelect('list_action', $options);
     $page_tags = $form->getTemplate();
     $page_tags['MENU_FIX'] = PHPWS_Text::secureLink(dgettext('access', 'Update menu links'), 'access', array('command' => 'menu_fix'));
     $page_tags['PAGE_FIX'] = PHPWS_Text::secureLink(dgettext('access', 'Shortcut all pages'), 'access', array('command' => 'page_fix'));
     if (PHPWS_Settings::get('access', 'forward_ids')) {
         $page_tags['PAGE_FORWARDING'] = PHPWS_Text::secureLink(dgettext('access', 'Turn OFF autoforwarding of Pagesmith id pages'), 'access', array('command' => 'autoforward_off'));
     } else {
         $page_tags['PAGE_FORWARDING'] = PHPWS_Text::secureLink(dgettext('access', 'Turn ON autoforwarding of Pagesmith id pages'), 'access', array('command' => 'autoforward_on'));
     }
     $page_tags['MENU_WARNING'] = dgettext('menu', 'This change is irreversable. Please backup menu_links prior to running it.');
     $page_tags['URL_LABEL'] = dgettext('access', 'Url');
     $page_tags['ACTIVE_LABEL'] = dgettext('access', 'Active?');
     $page_tags['ACTION_LABEL'] = dgettext('access', 'Action');
     $page_tags['CHECK_ALL_SHORTCUTS'] = javascript('check_all', array('checkbox_name' => 'shortcut[]'));
     $js_vars['value'] = dgettext('access', 'Go');
     $js_vars['select_id'] = $form->getId('list_action');
     $js_vars['action_match'] = 'delete';
     $js_vars['message'] = dgettext('access', 'Are you sure you want to delete the checked shortcuts?');
     $page_tags['SUBMIT'] = javascript('select_confirm', $js_vars);
     $pager->addPageTags($page_tags);
     $pager->addRowTags('rowTags');
     $content = $pager->get();
     return $content;
 }
예제 #9
0
 public static function doPager()
 {
     PHPWS_Core::initCoreClass('DBPager.php');
     PHPWS_Core::initModClass('intern', 'Major.php');
     $pager = new DBPager('intern_major', 'Major');
     $pager->db->addOrder('name asc');
     $pager->setModule('intern');
     $pager->setTemplate('major_pager.tpl');
     $pager->setEmptyMessage('No Majors Found.');
     $pager->addRowTags('getRowTags');
     return $pager->get();
 }
 public static function doPager()
 {
     PHPWS_Core::initCoreClass('DBPager.php');
     PHPWS_Core::initModClass('intern', 'GradProgram.php');
     $pager = new DBPager('intern_grad_prog', 'GradProgram');
     $pager->db->addOrder('name asc');
     $pager->setModule('intern');
     $pager->setTemplate('grad_pager.tpl');
     $pager->setEmptyMessage('No Graduate Programs Found.');
     $pager->addRowTags('getRowTags');
     return $pager->get();
 }
 public function show()
 {
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Util.php');
     # Get the roommate request record from the database
     $bed = new HMS_Bed($this->request['bed_id']);
     $room = $bed->get_parent();
     $tpl = array();
     $requestor = StudentFactory::getStudentByUsername($this->request['requestor'], $this->term);
     $tpl['REQUESTOR'] = $requestor->getName();
     $tpl['HALL_ROOM'] = $bed->where_am_i();
     # List all the students which will be assigned and their beds
     $beds = $room->get_beds();
     foreach ($beds as $bed) {
         $bed_row = array();
         # Check for an assignment
         $bed->loadAssignment();
         # Check for a reservation
         $reservation = $bed->get_lottery_reservation_info();
         $bed_row['BEDROOM_LETTER'] = $bed->bedroom_label;
         if ($bed->_curr_assignment != NULL) {
             # Bed is assigned
             $roommate = StudentFactory::getStudentByUsername($bed->_curr_assignment->asu_username, $this->term);
             $bed_row['TEXT'] = $roommate->getName();
         } else {
             if ($reservation != NULL) {
                 # Bed is reserved
                 $roommate = StudentFactory::getStudentByUsername($reservation['asu_username'], $this->term);
                 $bed_row['TEXT'] = $roommate->getName() . ' (reserved)';
             } else {
                 $bed_row['TEXT'] = 'Empty';
             }
         }
         $tpl['beds'][] = $bed_row;
     }
     $tpl['MEAL_PLAN'] = HMS_Util::formatMealOption($this->mealPlan);
     PHPWS_Core::initCoreClass('Captcha.php');
     $tpl['CAPTCHA'] = Captcha::get();
     $submitCmd = CommandFactory::getCommand('LotteryConfirmRoommateRequest');
     $submitCmd->setRequestId($this->request['id']);
     $submitCmd->setMealPlan($this->mealPlan);
     $form = new PHPWS_Form();
     $submitCmd->initForm($form);
     $form->addSubmit('confirm', 'Confirm Roommate');
     $form->mergeTemplate($tpl);
     $tpl = $form->getTemplate();
     Layout::addPageTitle("Lottery Confirm Roommate");
     return PHPWS_Template::process($tpl, 'hms', 'student/lottery_confirm_roommate_request.tpl');
 }
예제 #12
0
 public function show_username_change()
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'username_change')) {
         $tpl = array();
         return PHPWS_Template::process($tpl, 'hms', 'admin/permission_denied.tpl');
     }
     PHPWS_Core::initCoreClass('Form.php');
     $form =& new PHPWS_Form();
     $form->addTextarea('usernames');
     $form->addSubmit('submit', 'Submit');
     $form->addHidden('module', 'hms');
     $form->addHidden('type', 'admin');
     $form->addHidden('op', 'process_username_change');
     return PHPWS_Template::process($form->getTemplate(), 'hms', 'admin/username_change.tpl');
 }
예제 #13
0
 public function show()
 {
     PHPWS_Core::initCoreClass('Form.php');
     $form = new PHPWS_Form();
     $form->addDropBox('rlc', HMS_Learning_Community::getRlcList());
     $form->setClass('rlc', 'form-control');
     $form->addHidden('module', 'hms');
     $form->addHidden('action', 'ShowSearchByRlc');
     $form->addSubmit('submit', _('Search'));
     $form->setClass('submit', 'btn btn-primary pull-right');
     $tags = $form->getTemplate();
     $tags['TITLE'] = "RLC Search";
     Layout::addPageTitle("RLC Search");
     $final = PHPWS_Template::processTemplate($tags, 'hms', 'admin/search_by_rlc.tpl');
     return $final;
 }
예제 #14
0
 public function execute(CommandContext $context)
 {
     $id = $context->get('roommateId');
     if (is_null($id)) {
         throw new InvalidArgumentException('Must set roommateId');
     }
     PHPWS_Core::initModClass('hms', 'HMS_Roommate.php');
     $roommate = new HMS_Roommate($id);
     if ($roommate->id == 0) {
         throw new InvalidArgumentException('Invalid roommateId ' . $id);
     }
     $username = UserStatus::getUsername();
     if ($username != $roommate->requestee) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException("{$username} tried to confirm roommate pairing {$roommate->id}");
     }
     $err = CommandFactory::getCommand('ShowRoommateConfirmAccept');
     $err->setRoommateId($id);
     PHPWS_Core::initCoreClass('Captcha.php');
     $verified = Captcha::verify(TRUE);
     if ($verified === FALSE || is_null($verified)) {
         NQ::Simple('hms', hms\NotificationView::ERROR, 'Sorry, please try again.');
         $err->redirect();
     }
     try {
         $roommate->confirm();
     } catch (RoommateCompatibilityException $rce) {
         NQ::simple('hms', hms\NotificationView::WARNING, $rce->getMessage());
         $err->redirect();
     }
     $roommate->save();
     HMS_Activity_Log::log_activity($roommate->requestor, ACTIVITY_ACCEPTED_AS_ROOMMATE, $roommate->requestee, "{$roommate->requestee} accepted request, CAPTCHA: {$verified}");
     HMS_Activity_Log::log_activity($roommate->requestee, ACTIVITY_ACCEPTED_AS_ROOMMATE, $roommate->requestor, "{$roommate->requestee} accepted request, CAPTCHA: {$verified}");
     // Email both parties
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     HMS_Email::send_confirm_emails($roommate);
     // Remove any other requests for the requestor
     HMS_Roommate::removeOutstandingRequests($roommate->requestor, $roommate->term);
     // Remove any other requests for the requestee
     HMS_Roommate::removeOutstandingRequests($roommate->requestee, $roommate->term);
     $requestor = StudentFactory::getStudentByUsername($roommate->requestor, $roommate->term);
     $name = $requestor->getFullName();
     NQ::Simple('hms', hms\NotificationView::SUCCESS, "You and {$name} are confirmed as roommates.");
     $cmd = CommandFactory::getCommand('ShowStudentMenu');
     $cmd->redirect();
 }
예제 #15
0
 public function __construct($type = 'default')
 {
     PHPWS_Core::initCoreClass('DBPager.php');
     PHPWS_Core::initModClass('faxmaster', 'ActionLog.php');
     $this->pager = new DBPager('faxmaster_action_log', 'RestoredActionLog');
     $this->pager->setModule('faxmaster');
     $this->pager->setLink('index.php?module=faxmaster');
     // Zebra stripe the fax list
     $this->pager->addToggle('class="bgcolor1"');
     $this->pager->addToggle('class="bgcolor2"');
     // By default, sort the faxes in reverse chronological order
     $this->pager->setOrder('timePerformed', 'DESC', true);
     $this->pager->setTemplate('actionLogList.tpl');
     $this->pager->setEmptyMessage('No actions found.');
     $this->pager->addRowTags('rowTags');
     $this->pager->setSearch('username');
 }
예제 #16
0
 /**
  * Shows filtering options for the log view.  The first argument is usually
  * $_SESSION. The second argument is laid out in the same way, and
  * specifies default values.  If a default value is specified in the second
  * argument, that option will not appear in the filter; this way, if you're
  * in the Student Info thing, you can show the activity log for only that
  * user.
  */
 public static function showFilters($selection = NULL)
 {
     PHPWS_Core::initCoreClass('Form.php');
     $submitCmd = CommandFactory::getCommand('ShowActivityLog');
     $form = new PHPWS_Form();
     $submitCmd->initForm($form);
     $form->setMethod('get');
     $form->addText('actor');
     $form->setLabel('actor', 'Action Performed By:');
     if (isset($selection['actor'])) {
         $form->setValue('actor', $selection['actor']);
     }
     $form->addText('actee');
     $form->setLabel('actee', 'Action Affected:');
     if (isset($selection['actee'])) {
         $form->setValue('actee', $selection['actee']);
     }
     // "exact" flag
     $form->addCheck('exact', 'yes');
     $form->setMatch('exact', 'yes');
     $form->setLabel('exact', 'Exact? ');
     $form->addText('begin', isset($selection['begin']) ? $selection['begin'] : '');
     $form->setClass('begin', 'datepicker');
     $form->addText('end', isset($selection['end']) ? $selection['end'] : '');
     $form->setClass('end', 'datepicker');
     $form->addText('notes');
     $form->setLabel('notes', 'Note:');
     if (isset($selection['notes'])) {
         $form->setValue('notes', $selection['notes']);
     }
     $activities = HMS_Activity_Log::getActivityMapping();
     foreach ($activities as $id => $text) {
         $name = "a{$id}";
         $form->addCheckbox($name);
         $form->setLabel($name, $text);
         $form->setMatch($name, isset($selection[$name]));
     }
     $form->addSubmit('Refresh');
     $tpl = $form->getTemplate();
     $tpl['BEGIN_LABEL'] = 'After:';
     $tpl['END_LABEL'] = 'Before:';
     javascript('jquery');
     javascript('modules/hms/activity_log');
     return PHPWS_Template::process($tpl, 'hms', 'admin/activity_log_filters.tpl');
 }
예제 #17
0
 public function init()
 {
     PHPWS_Core::initCoreClass('Module.php');
     $db = new PHPWS_DB('users_my_page_mods');
     $db->addColumn('mod_title');
     $result = $db->select('col');
     if (PHPWS_Error::isError($result)) {
         return $result;
     }
     if ($result) {
         foreach ($result as $mod_title) {
             $this->modules[$mod_title] = new PHPWS_Module($mod_title);
         }
     } else {
         return FALSE;
     }
     return TRUE;
 }
 public function show()
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initCoreClass('Captcha.php');
     $requestor = StudentFactory::getStudentByUsername($this->request['requestor'], $this->term);
     $tpl = array();
     $tpl['REQUESTOR'] = $requestor->getName();
     $tpl['CAPTCHA'] = Captcha::get();
     $submitCmd = CommandFactory::getCommand('LotteryDenyRoommateRequest');
     $submitCmd->setRequestId($this->request['id']);
     $form = new PHPWS_Form();
     $submitCmd->initForm($form);
     $form->addSubmit('deny', 'Deny Roommate Request');
     $form->mergeTemplate($tpl);
     $tpl = $form->getTemplate();
     $this->setTitle('Deny Roommate Request');
     return PHPWS_Template::process($tpl, 'hms', 'student/lottery_deny_roommate_request.tpl');
 }
예제 #19
0
 public static function sendEmail($to, $from, $subject, $content, $cc = NULL, $bcc = NULL)
 {
     $settings = InternSettings::getInstance();
     // Sanity checking
     if (!isset($to) || is_null($to)) {
         return false;
     }
     if (!isset($from) || is_null($from)) {
         $from = $settings->getSystemName() . ' <' . $settings->getEmailFromAddress() . '>';
     }
     if (!isset($subject) || is_null($subject)) {
         return false;
     }
     if (!isset($content) || is_nulL($content)) {
         return false;
     }
     // Create a Mail object and set it up
     PHPWS_Core::initCoreClass('Mail.php');
     $message = new PHPWS_Mail();
     $message->addSendTo($to);
     $message->setFrom($from);
     $message->setSubject($subject);
     $message->setMessageBody($content);
     if (isset($cc)) {
         $message->addCarbonCopy($cc);
     }
     if (isset($bcc)) {
         $message->addBlindCopy($bcc);
     }
     // Send the message
     if (EMAIL_TEST_FLAG) {
         $result = true;
     } else {
         $result = $message->send();
     }
     if (PEAR::isError($result)) {
         PHPWS_Error::log($result);
         return false;
     }
     self::logEmail($message);
     return true;
 }
예제 #20
0
 public function loadTemplate()
 {
     PHPWS_Core::initCoreClass('XMLParser.php');
     $xml = new XMLParser($this->file);
     $xml->setContentOnly(true);
     if (PHPWS_Error::isError($xml->error)) {
         return $xml->error;
     }
     $result = $xml->format();
     if (empty($result['TEMPLATE'])) {
         return;
     }
     $this->data = $result['TEMPLATE'];
     if (!isset($this->data['TITLE'])) {
         $this->error[] = PHPWS_Error::get(PS_TPL_NO_TITLE, 'pagesmith', 'PS_Template::loadTemplate', $this->name);
         return;
     }
     $this->title =& $this->data['TITLE'];
     if (isset($this->data['SUMMARY'])) {
         $this->summary =& $this->data['SUMMARY'];
     }
     if (empty($this->data['THUMBNAIL'])) {
         $this->error[] = PHPWS_Error::get(PS_TPL_NO_TN, 'pagesmith', 'PS_Template::loadTemplate', $this->name);
         return;
     }
     $this->thumbnail =& $this->data['THUMBNAIL'];
     if (isset($this->data['STYLE'])) {
         $this->style =& $this->data['STYLE'];
     }
     if (empty($this->data['STRUCTURE']['SECTION'])) {
         $this->error[] = PHPWS_Error::get(PS_TPL_NO_SECTIONS, 'pagesmith', 'PS_Template::loadTemplate', $this->name);
         return;
     }
     $this->structure =& $this->data['STRUCTURE']['SECTION'];
     if (isset($this->data['FOLDERS'])) {
         if (is_array($this->data['FOLDERS']['NAME'])) {
             $this->folders =& $this->data['FOLDERS']['NAME'];
         } else {
             $this->folders = array($this->data['FOLDERS']['NAME']);
         }
     }
 }
예제 #21
0
 public static function send_email($to, $from, $subject, $content, $cc = NULL, $bcc = NULL)
 {
     # Sanity checking
     if (!isset($to) || is_null($to)) {
         return false;
     }
     if (!isset($from) || is_null($from)) {
         $from = SYSTEM_NAME . ' <' . FROM_ADDRESS . '>';
     }
     if (!isset($subject) || is_null($subject)) {
         return false;
     }
     if (!isset($content) || is_nulL($content)) {
         return false;
     }
     # Create a Mail object and set it up
     \PHPWS_Core::initCoreClass('Mail.php');
     $message = new PHPWS_Mail();
     $message->addSendTo($to);
     $message->setFrom($from);
     $message->setSubject($subject);
     $message->setMessageBody($content);
     if (isset($cc)) {
         $message->addCarbonCopy($cc);
     }
     if (isset($bcc)) {
         $message->addBlindCopy($bcc);
     }
     # Send the message
     if (EMAIL_TEST_FLAG) {
         HMS_Email::log_email($message);
         $result = true;
     } else {
         $result = $message->send();
     }
     if (PEAR::isError($result)) {
         PHPWS_Error::log($result);
         return false;
     }
     return true;
 }
예제 #22
0
 public static function listTrackers()
 {
     PHPWS_Core::initModClass('analytics', 'GenericTracker.php');
     PHPWS_Core::initCoreClass('DBPager.php');
     $pager = new DBPager('analytics_tracker', 'GenericTracker');
     $pager->addSortHeader('name', dgettext('analytics', 'Name'));
     $pager->addSortHeader('type', dgettext('analytics', 'Type'));
     $pager->addSortHeader('active', dgettext('analytics', 'Active'));
     $pageTags = array();
     $pageTags['ACTION'] = dgettext('analytics', 'Action');
     $pageTags['ACCOUNT'] = dgettext('analytics', 'Account ID');
     $pager->setModule('analytics');
     $pager->setTemplate('list.tpl');
     $pager->addToggle('class="toggle1"');
     $pager->addRowTags('getPagerTags');
     $pager->addPageTags($pageTags);
     $pager->setSearch('name');
     $pager->setDefaultOrder('name', 'asc');
     $pager->cacheQueries();
     return $pager->get();
 }
예제 #23
0
 public function show()
 {
     $tpl = array();
     $tpl['TITLE'] = $this->title;
     $tpl['TERM'] = Term::getPrintableSelectedTerm();
     if ($this->halls == NULL) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'There are no halls available for the selected term.');
         $cmd = CommandFactory::getCommand('ShowAdminMaintenanceMenu');
         $cmd->redirect();
     }
     PHPWS_Core::initCoreClass('Form.php');
     $form = new PHPWS_Form();
     $this->onSelectCmd->initForm($form);
     $form->setMethod('get');
     $form->addDropBox('hallId', $this->halls);
     $form->addCssClass('hallId', 'form-control');
     $form->addSubmit('submit', _('Select Hall'));
     $form->mergeTemplate($tpl);
     $tpl = $form->getTemplate();
     Layout::addPageTitle("Select Hall");
     return PHPWS_Template::process($tpl, 'hms', 'admin/select_residence_hall.tpl');
 }
예제 #24
0
 public function show()
 {
     PHPWS_Core::initCoreClass('DBPager.php');
     $tags = array();
     $tags['TITLE'] = "View Final RLC Assignments " . Term::toString(Term::getSelectedTerm());
     $pager = new DBPager('hms_learning_community_assignment', 'HMS_RLC_Assignment');
     //$pager->db->addWhere('hms_learning_community_applications.hms_assignment_id','hms_learning_community_assignment.id','=');
     $pager->db->addJoin('LEFT OUTER', 'hms_learning_community_assignment', 'hms_learning_community_applications', 'application_id', 'id');
     $pager->db->addWhere('hms_learning_community_applications.term', Term::getSelectedTerm());
     $pager->db->addWhere('hms_learning_community_assignment.state', 'confirmed');
     $pager->joinResult('application_id', 'hms_learning_community_applications', 'id', 'username', 'username');
     $pager->joinResult('application_id', 'hms_learning_community_applications', 'id', 'term', 'term');
     $pager->setModule('hms');
     $pager->setTemplate('admin/display_final_rlc_assignments.tpl');
     $pager->setLink('index.php?module=hms&type=rlc&op=assign_applicants_to_rlcs');
     $pager->setEmptyMessage('No RLC assignments have been made.');
     $pager->addPageTags($tags);
     $pager->addRowTags('getAdminPagerTags');
     $pager->setReportRow('getAdminCsvRow');
     Layout::addPageTitle("RLC Assignments");
     return $pager->get();
 }
 public function show()
 {
     $approveCmd = CommandFactory::getCommand('RoomChangeStudentApprove');
     $approveCmd->setParticipantId($this->thisParticipant->getId());
     $approveCmd->setRequestId($this->request->getId());
     $declineCmd = CommandFactory::getCommand('RoomChangeStudentDecline');
     $declineCmd->setParticipantId($this->thisParticipant->getId());
     $declineCmd->setRequestId($this->request->getId());
     $form = new PHPWS_Form('roomchange_student_approve');
     $form->addHidden('foo', 'bar');
     $tpl = $form->getTemplate();
     $tpl['APPROVE_URI'] = $approveCmd->getURI();
     $tpl['DECLINE_URI'] = $declineCmd->getURI();
     $requestor = StudentFactory::getStudentByUsername($this->request->getState()->getCommittedBy(), $this->term);
     $tpl['REQUESTOR'] = $requestor->getName();
     // Build the table showing who is moving from/to which beds
     $participantRows = array();
     foreach ($this->participants as $p) {
         $row = array();
         $student = StudentFactory::getStudentByBannerId($p->getBannerId(), $this->term);
         $row['NAME'] = $student->getName();
         // If this participant is the person logged in, bold their name
         if ($student->getBannerId() == $this->thisParticipant->getBannerId()) {
             $row['STRONG_STYLE'] = 'success';
         } else {
             $row['STRONG_STYLE'] = '';
         }
         $fromBed = new HMS_Bed($p->getFromBed());
         $toBed = new HMS_Bed($p->getToBed());
         $row['FROM_BED'] = $fromBed->where_am_i();
         $row['TO_BED'] = $toBed->where_am_i();
         $participantRows[] = $row;
     }
     $tpl['PARTICIPANTS'] = $participantRows;
     PHPWS_Core::initCoreClass('Captcha.php');
     $tpl['CAPTCHA'] = Captcha::get();
     return PHPWS_Template::process($tpl, 'hms', 'student/roomChangeRequestStudentApprove.tpl');
 }
예제 #26
0
 public function execute(CommandContext $context)
 {
     $id = $context->get('roommateId');
     if (is_null($id)) {
         throw new InvalidArgumentException('Must set roommateId');
     }
     PHPWS_Core::initModClass('hms', 'HMS_Roommate.php');
     $roommate = new HMS_Roommate($id);
     if ($roommate->id == 0) {
         throw new InvalidArgumentException('Invalid roommateId ' . $id);
     }
     $username = UserStatus::getUsername();
     if ($username != $roommate->requestor && $username != $roommate->requestee) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException("{$username} tried to break roommate pairing {$roommate->id}");
     }
     $err = CommandFactory::getCommand('ShowRoommateBreak');
     $err->setRoommateId($id);
     PHPWS_Core::initCoreClass('Captcha.php');
     $verified = Captcha::verify(TRUE);
     if ($verified === FALSE || is_null($verified)) {
         NQ::Simple('hms', hms\NotificationView::ERROR, 'Sorry, please try again.');
         $err->redirect();
     }
     $roommate->delete();
     $other = StudentFactory::getStudentByUsername($roommate->get_other_guy($username), $roommate->term);
     HMS_Activity_Log::log_activity($other->getUsername(), ACTIVITY_STUDENT_BROKE_ROOMMATE, $username, "{$username} broke pairing, CAPTCHA: {$verified}");
     HMS_Activity_Log::log_activity($username, ACTIVITY_STUDENT_BROKE_ROOMMATE, $other->getUsername(), "{$username} broke pairing, CAPTCHA: {$verified}");
     // Email both parties
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     HMS_Email::send_break_emails($roommate, $username);
     $name = $other->getFullName();
     NQ::Simple('hms', hms\NotificationView::SUCCESS, "You have removed your roommate request for {$name}.");
     $cmd = CommandFactory::getCommand('ShowStudentMenu');
     $cmd->redirect();
 }
예제 #27
0
 public function getAddress($include_http = TRUE)
 {
     PHPWS_Core::initCoreClass('Link.php');
     $link = new PHPWS_Link();
     $link->full_url = $include_http;
     $link->setRewrite();
     $link->setModule('rss');
     $link->addValues(array('mod_title' => $this->module));
     return $link->getAddress();
 }
예제 #28
0
 public static function import()
 {
     $source_http = PHPWS_SOURCE_HTTP;
     $script = "<script src='{$source_http}mod/rss/javascript/feed.js'></script>";
     javascript('jquery');
     \Layout::addJSHeader($script);
     PHPWS_Core::requireConfig('rss');
     if (!ini_get('allow_url_fopen')) {
         $tpl['TITLE'] = dgettext('rss', 'Sorry');
         $tpl['CONTENT'] = dgettext('rss', 'You must enable allow_url_fopen in your php.ini file.');
         return $tpl;
     }
     PHPWS_Core::initCoreClass('DBPager.php');
     PHPWS_Core::initModClass('rss', 'Feed.php');
     $content = NULL;
     $template['ADD_LINK'] = '<button class="btn btn-success edit-feed"><i></i> Add Feed</button>';
     /*
      $vars['address'] = 'index.php?module=rss&command=add_feed';
      $vars['label'] = dgettext('rss', 'Add feed');
      $vars['width'] = '450';
      $vars['height'] = '350';
      $template['ADD_LINK'] = javascript('open_window', $vars);
     * 
     */
     $template['TITLE_LABEL'] = dgettext('rss', 'Title');
     $template['ADDRESS_LABEL'] = dgettext('rss', 'Address');
     $template['DISPLAY_LABEL'] = dgettext('rss', 'Display?');
     $template['ACTION_LABEL'] = dgettext('rss', 'Action');
     $template['REFRESH_TIME_LABEL'] = dgettext('rss', 'Refresh feed');
     $modal = new \Modal('rss-modal');
     $modal->addButton('<button class="btn btn-primary" id="save-feed"><i class="fa fa-save"></i> Save</button>');
     $modal_content = RSS_Admin::editFeed();
     $modal->setContent($modal_content);
     $modal->setTitle('Edit feed');
     $modal->setWidthPixel('400');
     $template['MODAL'] = $modal->get();
     $pager = new DBPager('rss_feeds', 'RSS_Feed');
     $pager->setModule('rss');
     $pager->setTemplate('admin_feeds.tpl');
     $pager->addPageTags($template);
     $pager->addRowTags('pagerTags');
     $content = $pager->get();
     $tpl['TITLE'] = dgettext('rss', 'Import RSS Feeds');
     $tpl['CONTENT'] = $content;
     if (!defined('ALLOW_CACHE_LITE') || !ALLOW_CACHE_LITE) {
         $tpl['MESSAGE'] = dgettext('rss', 'Please enable Cache Lite in your config/core/config.php file.');
     }
     return $tpl;
 }
예제 #29
0
} else {
    define('SITE_HASH', md5(rand()));
}
if (!defined('PHPWS_SOURCE_DIR')) {
    define('PHPWS_SOURCE_DIR', getcwd() . '/');
}
if (!defined('PHPWS_SOURCE_HTTP')) {
    define('PHPWS_SOURCE_HTTP', './');
}
require_once 'core/conf/defines.dist.php';
loadTimeZone();
require_once './setup/config.php';
require_once './core/class/Template.php';
require_once './setup/class/Setup.php';
// Core is loaded in Init
PHPWS_Core::initCoreClass('Form.php');
PHPWS_Core::initModClass('boost', 'Boost.php');
PHPWS_Core::initModClass('users', 'Current_User.php');
$setup = new Setup();
/**
 * Starts session, checks if supported on client and server
 * Program exits here if fails.
 */
$setup->checkSession();
/**
 * Check the server for certain settings before getting into the meat
 * of the installation. Will return if successfully or previously passed.
 */
$setup->checkServerSettings();
$setup->goToStep();
exit('end of switch');
예제 #30
0
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     $roomId = $context->get('roomId');
     $roommates = $context->get('roommates');
     $mealPlan = $context->get('mealPlan');
     $term = PHPWS_Settings::get('hms', 'lottery_term');
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     $errorCmd = CommandFactory::getCommand('LotteryShowConfirm');
     $errorCmd->setRoomId($roomId);
     $errorCmd->setRoommates($roommates);
     $errorCmd->setMealPlan($mealPlan);
     $successCmd = CommandFactory::getCommand('LotteryShowConfirmed');
     $successCmd->setRoomId($roomId);
     PHPWS_Core::initCoreClass('Captcha.php');
     $captcha = Captcha::verify(TRUE);
     // returns the words entered if correct, FALSE otherwise
     //$captcha = TRUE;
     if ($captcha === FALSE) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, the words you eneted were incorrect. Please try again.');
         $errorCmd->redirect();
     }
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'HMS_Room.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     PHPWS_Core::initModClass('hms', 'HMS_Util.php');
     PHPWS_Core::initModClass('hms', 'RlcMembershipFactory.php');
     PHPWS_Core::initModClass('hms', 'RlcAssignmentSelfAssignedState.php');
     $room = new HMS_Room($roomId);
     // Check for an RLC assignment in the self-select status
     $rlcAssignment = RlcMembershipFactory::getMembership($student, $term);
     // Check roommates for validity
     foreach ($roommates as $bed_id => $username) {
         // Double check the student is valid
         try {
             $roommate = StudentFactory::getStudentByUsername($username, $term);
         } catch (StudentNotFoundException $e) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is not a valid student. Please choose a different roommate.");
             $errorCmd->redirect();
         }
         // Make sure the bed is still empty
         $bed = new HMS_Bed($bed_id);
         if ($bed->has_vacancy() != TRUE) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'One or more of the beds in the room you selected is no longer available. Please try again.');
             $errorCmd->redirect();
         }
         // Make sure none of the needed beds are reserved
         if ($bed->is_lottery_reserved()) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'One or more of the beds in the room you selected is no longer available. Please try again.');
             $errorCmd->redirect();
         }
         // Double check the genders are all the same as the person logged in
         if ($student->getGender() != $roommate->getGender()) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is a different gender. Please choose a roommate of the same gender.");
             $errorCmd->redirect();
         }
         // Double check the genders are the same as the room (as long as the room isn't AUTO)
         if ($room->gender_type != AUTO && $roommate->getGender() != $room->gender_type) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is a different gender. Please choose a roommate of the same gender.");
             $errorCmd->redirect();
         }
         // If this student is an RLC-self-selection, then each roommate must be in the same RLC and in the selfselect-invite state too
         if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') {
             // This student is an RLC-self-select, so check the roommate's RLC status
             $roommateRlcAssign = RlcMembershipFactory::getMembership($roommate, $term);
             // Make sure the roommate is a member of the same RLC and is eligible for self-selection
             if ($roommateRlcAssign == null || $roommateRlcAssign->getStateName() != 'selfselect-invite' || $rlcAssignment->getRlc()->getId() != $roommateRlcAssign->getRlc()->getId()) {
                 NQ::simple('hms', hms\NotificationView::ERROR, "{$roommate} must be a member of the same learning community as you, and must also be eligible for self-selction.");
                 $errorCmd->redirect();
             }
             // Otherwise (if not RLC members), make sure each roommate is eligible
         } else {
             if (HMS_Lottery::determineEligibility($username) !== TRUE) {
                 NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is not eligible for assignment.");
                 $errorCmd->redirect();
             }
         }
         // If this student is a self-select RLC member, then this student must also be a self-select RLC member of the same RLC
         if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') {
             $roommateRlcAssign = RlcMembershipFactory::getMembership($roommate, $term);
             if ($roommateRlcAssign == null || $roommateRlcAssign->getStateName() != 'selfselect-invite' || $rlcAssignment->getRlc()->getId() != $roommateRlcAssign->getRlc()->getId()) {
                 NQ::simple('hms', hms\NotificationView::ERROR, "{$username} must be a member of the same learning community as you, and must also be eligible for self-selction.");
                 $errorCmd->redirect();
             }
         }
     }
     // If the room's gender is 'AUTO' and no one is assigned to it yet, switch it to the student's gender
     if ($room->gender_type == AUTO && $room->get_number_of_assignees() == 0) {
         $room->gender_type = $student->getGender();
         $room->save();
     }
     // Assign the student to the requested bed
     $bed_id = array_search(UserStatus::getUsername(), $roommates);
     // Find the bed id of the student who's logged in
     try {
         $result = HMS_Assignment::assignStudent($student, PHPWS_Settings::get('hms', 'lottery_term'), NULL, $bed_id, $mealPlan, 'Confirmed lottery invite', TRUE, ASSIGN_LOTTERY);
     } catch (Exception $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, there was an error creating your room assignment. Please try again or contact University Housing.');
         $errorCmd->redirect();
     }
     // Log the assignment
     HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_LOTTERY_ROOM_CHOSEN, UserStatus::getUsername(), 'Captcha: ' . $captcha);
     // Update the student's meal plan in the housing application, just for future reference
     $app = HousingApplication::getApplicationByUser($student->getUsername(), $term);
     $app->setMealPlan($mealPlan);
     $app->save();
     // If this student was an RLC self-select, update the RLC memberhsip state
     if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') {
         $rlcAssignment->changeState(new RlcAssignmentSelfAssignedState($rlcAssignment));
     }
     foreach ($roommates as $bed_id => $username) {
         // Skip the current user
         if ($username == $student->getUsername()) {
             continue;
         }
         # Reserve the bed for the roommate
         $expires_on = time() + INVITE_TTL_HRS * 3600;
         $bed = new HMS_Bed($bed_id);
         if (!$bed->lottery_reserve($username, $student->getUsername(), $expires_on)) {
             NQ::smiple('hms', hms\NotificationView::WARNING, "You were assigned, but there was a problem reserving space for your roommates. Please contact University Housing.");
             $successCmd->redirect();
         }
         HMS_Activity_Log::log_activity($username, ACTIVITY_LOTTERY_REQUESTED_AS_ROOMMATE, $student->getUsername(), 'Expires: ' . HMS_Util::get_long_date_time($expires_on));
         # Invite the selected roommates
         $roomie = StudentFactory::getStudentByUsername($username, $term);
         $term = PHPWS_Settings::get('hms', 'lottery_term');
         $year = Term::toString($term) . ' - ' . Term::toString(Term::getNextTerm($term));
         HMS_Email::send_lottery_roommate_invite($roomie, $student, $expires_on, $room->where_am_i(), $year);
     }
     HMS_Email::send_lottery_assignment_confirmation($student, $room->where_am_i(), $term);
     $successCmd->redirect();
 }