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'));
 }
 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');
 }
 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');
 }
 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');
 }
Пример #5
0
 /**
  * Constructs a view of this form and returns it in a string.
  *
  * This function will construct a view of this form whether in edit mode
  * or submission mode and return it in a string for display.
  *
  * @param  boolean $edit Whether the view is in edit mode or not.
  * @return mixed   A templated string on success, or a FALSE on failure.
  * @access public
  */
 function view($edit = FALSE, $error = null)
 {
     if ($this->isHidden() && !$edit || !$this->isSaved() && !Current_User::allow('phatform', 'edit_forms')) {
         return dgettext('phatform', 'This form is not available for viewing at this time.');
     }
     $GLOBALS['CNT_phatform']['title'] = $this->getLabel();
     /* Do some basic checks if we're not in edit mode */
     if (!$edit) {
         /* If this form is not anonymous and the user is not logged in, print message and bail */
         if (($this->_editData || !$this->_anonymous) && !Current_User::isLogged()) {
             return dgettext('phatform', 'You must be logged in to view this form!');
         }
         /* If this form is not multi submit and the user has filled out this for before,
            print message and bail */
         if (!$this->_editData && !$this->_multiSubmit && $this->hasSubmission()) {
             return dgettext('phatform', 'You have already filled out this form!');
         }
         if (!Current_User::isDeity() && Current_User::allow('phatform', 'user_forms_only')) {
             if (Current_User::getUsername() != $this->getOwner()) {
                 return dgettext('phatform', 'You only have permission to edit your own forms!');
             }
         }
     }
     /* Assume the PHAT position :) */
     if (!isset($this->_position)) {
         $this->_position = 0;
     }
     /* Setup limit for loop */
     if ($this->_position + $this->_pageLimit > sizeof($this->_elements)) {
         $limit = $this->_position + (sizeof($this->_elements) - $this->_position);
     } else {
         $limit = $this->_position + $this->_pageLimit;
     }
     /* Begin view template array */
     if ($this->currentPage() == 1) {
         $viewTags['BLURB0'] = PHPWS_Text::parseOutput($this->_blurb0, ENCODE_PARSED_TEXT, false, true);
         if (!$this->_saved) {
             $viewTags['WARNING'] = dgettext('phatform', 'The form must be saved before it is available to the public.');
         }
     }
     $formTags = array();
     /* If this form has elements, loop and add them to the form template array */
     if (is_array($this->_elements) && sizeof($this->_elements) > 0) {
         for ($i = $this->_position; $i < $limit; $i++) {
             $sectionTags = array();
             $elementInfo = explode(':', $this->_elements[$i]);
             $this->element = new $elementInfo[0]($elementInfo[1]);
             /* If user can edit data, populate for element with it */
             if (!$edit && $this->_editData && is_array($this->_userData)) {
                 if (isset($this->_userData[$this->element->getLabel()]) && $this->isSerialized($this->_userData[$this->element->getLabel()])) {
                     $value = unserialize(stripslashes($this->_userData[$this->element->getLabel()]));
                     $this->element->setValue($value);
                 } else {
                     $this->element->setValue($this->_userData[$this->element->getLabel()]);
                 }
             }
             /* Setup color for alternating rows in the section template */
             if (isset($flag) && $flag) {
                 $flag = FALSE;
             } else {
                 $sectionTags['BGCOLOR'] = ' class="bgcolor1" ';
                 $flag = TRUE;
             }
             /* Get view of the current element */
             $sectionTags['ELEMENT'] = $this->element->view();
             if ($this->_showElementNumbers) {
                 $sectionTags['ELEMENT'] = $i + 1 . '. ' . $sectionTags['ELEMENT'];
             }
             /* If in edit mode, show the element editor for the current element */
             if ($edit) {
                 $sectionTags['ELEMENT_NAME'] = PHPWS_Text::parseOutput($this->element->getLabel(), ENCODE_PARSED_TEXT, false, true);
                 $sectionTags['ELEMENT_EDITOR'] = $this->_elementEditor($i);
             }
             if (!isset($formTags['ELEMENTS'])) {
                 $formTags['ELEMENTS'] = PHPWS_Template::processTemplate($sectionTags, 'phatform', 'form/section.tpl');
             } else {
                 $formTags['ELEMENTS'] .= PHPWS_Template::processTemplate($sectionTags, 'phatform', 'form/section.tpl');
             }
         }
         /* If we are on last page...show the submit button */
         if (!$edit) {
             if ($this->currentPage() == $this->numPages()) {
                 if ($this->_editData && $this->currentPage() > 1) {
                     $formTags['BACK_BUTTON'] = PHPWS_Form::formSubmit(dgettext('phatform', 'Back'), 'PHAT_Back');
                 }
                 if (PHATFORM_CAPTCHA && $this->_anonymous && !Current_User::isLogged()) {
                     PHPWS_Core::initCoreClass('Captcha.php');
                     $formTags['CAPTCHA'] = Captcha::get();
                 }
                 $formTags['SUBMIT_BUTTON'] = PHPWS_Form::formSubmit(dgettext('phatform', 'Finish'), 'PHAT_Submit');
             } else {
                 if ($this->_editData && $this->currentPage() > 1) {
                     $formTags['BACK_BUTTON'] = PHPWS_Form::formSubmit(dgettext('phatform', 'Back'), 'PHAT_Back');
                 }
                 $formTags['NEXT_BUTTON'] = PHPWS_Form::formSubmit(dgettext('phatform', 'Next'), 'PHAT_Next');
             }
         }
         /* Check if we're in edit mode and set the phat man accordingly */
         if ($edit) {
             $hiddens['PHAT_FORM_OP'] = 'EditAction';
         } else {
             $hiddens['PHAT_FORM_OP'] = 'Action';
         }
         /* Actually load hidden variables into the elements array */
         $hiddens['module'] = 'phatform';
         foreach ($hiddens as $key => $value) {
             $eles[] = PHPWS_Form::formHidden($key, $value);
         }
         $elements[] = implode("\n", $eles);
         $elements[0] .= PHPWS_Template::processTemplate($formTags, 'phatform', 'form/form.tpl');
         $viewTags['FORM'] = PHPWS_Form::makeForm('PHAT_Form', 'index.php', $elements);
     }
     /* Check to see if we should show page numbers or not */
     if ($this->_showPageNumbers) {
         $viewTags['PAGE_NUMBER'] = sprintf(dgettext('phatform', 'Page %1$s of %2$s'), $this->currentPage(), $this->numPages());
     }
     /* If in edit mode, display the toolbar */
     if ($edit) {
         $viewTags['TOOLBAR'] = $this->_toolbar();
     }
     $key = new Key($this->_key_id);
     $key->flag();
     if ($error) {
         $viewTags['WARNING'] = $error->getMessage();
     }
     return PHPWS_Template::processTemplate($viewTags, 'phatform', 'form/view.tpl');
 }
Пример #6
0
 public static function forgotForm()
 {
     PHPWS_Core::initCoreClass('Captcha.php');
     $form = new PHPWS_Form('forgot-password');
     $form->addHidden('module', 'users');
     $form->addHidden('action', 'user');
     $form->addHidden('command', 'post_forgot');
     $form->addText('fg_username');
     $form->setLabel('fg_username', dgettext('users', 'Enter your user name.'));
     $form->addText('fg_email');
     $form->setSize('fg_email', 40);
     $form->setLabel('fg_email', dgettext('users', 'Forgotten your user name? Enter your email address instead.'));
     if (ALLOW_CAPTCHA) {
         $form->addTplTag('CAPTCHA_IMAGE', Captcha::get());
     }
     $form->addSubmit(dgettext('users', 'Send reminder'));
     $tpl = $form->getTemplate();
     return PHPWS_Template::process($tpl, 'users', 'forms/forgot.tpl');
 }
Пример #7
0
 public function show()
 {
     PHPWS_Core::initModClass('hms', 'HMS_Util.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     $tpl = array();
     $submitCmd = CommandFactory::getCommand('LotteryConfirm');
     $submitCmd->setRoomId($this->roomId);
     $submitCmd->setMealPlan($this->mealPlan);
     $form = new PHPWS_Form();
     $submitCmd->initForm($form);
     # Add the beds and user names back to the form so they end up in the request in a pretty way
     foreach ($this->roommates as $key => $value) {
         if (isset($value) && $value != '') {
             $form->addHidden("roommates[{$key}]", $value);
         }
     }
     # List the student's room
     PHPWS_Core::initModClass('hms', 'HMS_Room.php');
     $room = new HMS_Room($this->roomId);
     $tpl['ROOM'] = $room->where_am_i();
     # List all the students which will be assigned and their beds
     $beds = $room->get_beds();
     foreach ($beds as $bed) {
         $bed_row = array();
         # Check for an assignment
         $bed->loadAssignment();
         # Check for a reservation
         $reservation = $bed->get_lottery_reservation_info();
         $bedLabel = $room->getRoomNumber();
         if ($room->get_number_of_beds() == 4) {
             $bedLabel = $bedLabel . $bed->getBedroomLabel();
         }
         $bedLabel = $bedLabel . $bed->getLetter();
         $bed_row['BED_LABEL'] = $bedLabel;
         $roommate = null;
         if ($bed->_curr_assignment != NULL) {
             # Bed is assigned
             $roommate = StudentFactory::getStudentByUsername($bed->_curr_assignment->asu_username, $this->term);
             $bed_row['TEXT'] = $roommate->getName();
         } else {
             if ($reservation != NULL) {
                 # Bed is reserved
                 $roommate = StudentFactory::getStudentByUsername($reservation['asu_username'], $this->term);
                 $bed_row['TEXT'] = $roommate->getName() . ' (reserved)';
             } else {
                 # Get the new roommate name out of the request
                 if (!isset($this->roommates[$bed->id]) || $this->roommates[$bed->id] == '') {
                     $bed_row['TEXT'] = 'Empty';
                 } else {
                     $roommate = StudentFactory::getStudentByUsername($this->roommates[$bed->id], $this->term);
                     $bed_row['TEXT'] = $roommate->getName() . ' ' . $this->roommates[$bed->id];
                 }
             }
         }
         $tpl['beds'][] = $bed_row;
     }
     # Show the meal plan
     $tpl['MEAL_PLAN'] = HMS_Util::formatMealOption($this->mealPlan);
     $form->addHidden('meal_plan', $this->mealPlan);
     PHPWS_Core::initCoreClass('Captcha.php');
     $form->addTplTag('CAPTCHA_IMAGE', Captcha::get());
     $form->addSubmit('submit_form', 'Confirm room & roommates');
     $form->mergeTemplate($tpl);
     Layout::addPageTitle("Confirm Re-Application");
     return PHPWS_Template::process($form->getTemplate(), 'hms', 'student/lottery_confirm.tpl');
 }