/**
  * @see Command::execute()
  */
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'hall_attributes')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to edit halls.');
     }
     // Make sure a hall ID was set
     $hallId = $context->get('hallId');
     if (is_null($hallId)) {
         throw new InvalidArgumentException('Missing hall ID.');
     }
     $viewCmd = CommandFactory::getCommand('EditResidenceHallView');
     $viewCmd->setHallId($hallId);
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     // Create the hall object given the hall id
     $hall = new HMS_Residence_Hall($hallId);
     if (!$hall) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid hall.');
         $viewCmd->redirect();
     }
     if ($context->get('tab') == 'settings') {
         // Compare the hall's gender and the gender the user selected
         // If they're not equal, call 'can_change_gender' public function
         if ($hall->gender_type != $_REQUEST['gender_type']) {
             if (!$hall->can_change_gender($_REQUEST['gender_type'])) {
                 NQ::simple('hms', hms\NotificationView::ERROR, 'Incompatible gender detected. No changes were made.');
                 $viewCmd->redirect();
             }
         }
         // Grab all the input from the form and save the hall
         $hall->hall_name = $context->get('hall_name');
         $hall->gender_type = $context->get('gender_type');
         // Set the defaults for the check boxes
         $context->setDefault('air_conditioned', 0);
         $context->setDefault('is_online', 0);
         $context->setDefault('meal_plan_required', 0);
         $context->setDefault('assignment_notifications', 0);
         $hall->air_conditioned = $context->get('air_conditioned');
         $hall->is_online = $context->get('is_online');
         $hall->meal_plan_required = $context->get('meal_plan_required');
         $hall->assignment_notifications = $context->get('assignment_notifications');
         $hall->setPackageDeskId($context->get('package_desk'));
     } else {
         if ($context->get('tab') == 'images') {
             $hall->exterior_image_id = $context->get('exterior_image_id');
             $hall->other_image_id = $context->get('other_image_id');
             $hall->map_image_id = $context->get('map_image_id');
             $hall->room_plan_image_id = $context->get('room_plan_image_id');
         }
     }
     $result = $hall->save();
     if (!$result || PHPWS_Error::logIfError($result)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'There was a problem saving the Residence Hall. No changes were made.');
         $viewCmd->redirect();
     }
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'The Residence hall was updated successfully.');
     $viewCmd->redirect();
 }
 public function execute(CommandContext $context)
 {
     $term = Term::getCurrentTerm();
     // Get the list of role memberships this user has
     // NB: This gets memberships for all terms.. must filter later
     $hms_perm = new HMS_Permission();
     $memberships = $hms_perm->getMembership('room_change_approve', NULL, UserStatus::getUsername());
     // Use the roles to instantiate a list of floors this user has access to
     $floors = array();
     foreach ($memberships as $member) {
         if ($member['class'] == 'hms_residence_hall') {
             $hall = new HMS_Residence_Hall($member['instance']);
             // Filter out halls that aren't in the current term
             if ($hall->getTerm() != $term) {
                 continue;
             }
             $floors = array_merge($floors, $hall->getFloors());
         } else {
             if ($member['class'] == 'hms_floor') {
                 $f = new HMS_Floor($member['instance']);
                 // Filter out floors that aren't in the current term
                 if ($f->getTerm() != $term) {
                     continue;
                 }
                 $floors[] = $f;
             } else {
                 throw new Exception('Unknown object type.');
             }
         }
     }
     if (empty($floors)) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         NQ::simple('hms', hms\NotificationView::ERROR, "You do not have the 'RD' role on any residence halls or floors.");
         $cmd = CommandFactory::getCommand('ShowAdminMaintenanceMenu');
         $cmd->redirect();
     }
     // Remove duplicate floors
     $uniqueFloors = array();
     foreach ($floors as $floor) {
         $uniqueFloors[$floor->getId()] = $floor;
     }
     // Use the list of floors to get a unique list of hall names
     $hallNames = array();
     foreach ($uniqueFloors as $floor) {
         $hall = $floor->get_parent();
         $hallNames[$hall->getId()] = $hall->getHallName();
     }
     // Get the set of room changes which are not complete based on the floor list
     $needsApprovalChanges = RoomChangeRequestFactory::getRoomChangesNeedsApproval($term, $uniqueFloors);
     $approvedChanges = RoomChangeRequestFactory::getRoomChangesByFloor($term, $uniqueFloors, array('Approved'));
     $allPendingChanges = RoomChangeRequestFactory::getRoomChangesByFloor($term, $uniqueFloors, array('Pending', 'Hold'));
     $completedChanges = RoomChangeRequestFactory::getRoomChangesByFloor($term, $uniqueFloors, array('Complete'));
     $inactiveChanges = RoomChangeRequestFactory::getRoomChangesByFloor($term, $uniqueFloors, array('Cancelled', 'Denied'));
     $view = new RoomChangeApprovalView($needsApprovalChanges, $approvedChanges, $allPendingChanges, $completedChanges, $inactiveChanges, $hallNames, $term);
     $context->setContent($view->show());
 }
Ejemplo n.º 3
0
 public function execute()
 {
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     PHPWS_Core::initModClass('hms', 'HMS_Util.php');
     $halls = HMS_Residence_Hall::get_halls($this->term);
     $rows = array();
     foreach ($halls as $hall) {
         if ($hall->count_avail_lottery_rooms('1') || $hall->count_avail_lottery_rooms('0')) {
             $row = array();
             $row['HALL_NAME'] = $hall->getHallName();
             $row['MALE_FREE'] = $hall->count_avail_lottery_rooms('1');
             $row['FEMALE_FREE'] = $hall->count_avail_lottery_rooms('0');
             $rooms = $hall->get_rooms();
             $roomRows = "";
             foreach ($rooms as $room) {
                 if ($room->count_avail_lottery_beds() > 0) {
                     $roomRow = "<tr><td>";
                     $roomRow = $roomRow . $room->getRoomNumber();
                     $roomRow = $roomRow . "</td><td>";
                     $roomRow = $roomRow . HMS_Util::formatGender($room->getGender());
                     $roomRow = $roomRow . "</td><td>";
                     $roomRow = $roomRow . $room->count_avail_lottery_beds();
                     $roomRow = $roomRow . "</td></tr>";
                     $roomRows = $roomRows . $roomRow;
                 }
             }
             $row['ROOMS'] = $roomRows;
             $rows[] = $row;
         }
     }
     $this->data = $rows;
 }
Ejemplo n.º 4
0
 public function show()
 {
     $form = new PHPWS_Form('room_change_request');
     /* Cell phone */
     $form->addText('cell_num');
     $form->setLabel('cell_num', 'Cell phone Number');
     $form->addCssClass('cell_num', 'form-control');
     $form->addCheck('cell_opt_out');
     /* Preferences */
     $halls = array(0 => 'Choose from below...');
     $halls = $halls + HMS_Residence_Hall::get_halls_array(Term::getSelectedTerm());
     $form->addRadioAssoc('type', array('switch' => 'I want to change to an open bed.', 'swap' => 'I want to swap beds with someone I know.'));
     /* Swap */
     $form->addText('swap_with');
     $form->setLabel('swap_with', 'ASU Email Address');
     $form->addCssClass('swap_with', 'form-control');
     /* Switch */
     $form->addDropBox('first_choice', $halls);
     $form->setLabel('first_choice', 'First Choice');
     $form->addCssClass('first_choice', 'form-control');
     $form->addDropBox('second_choice', $halls);
     $form->setLabel('second_choice', 'Second Choice');
     $form->addCssClass('second_choice', 'form-control');
     /* Reason */
     $form->addTextArea('reason');
     $form->setLabel('reason', 'Reason');
     $form->addCssClass('reason', 'form-control');
     $form->setRows('reason', 5);
     /* POST location */
     $cmd = CommandFactory::getCommand('SubmitRoomChangeRequest');
     $cmd->initForm($form);
     $tpl = $form->getTemplate();
     return PHPWS_Template::process($tpl, 'hms', 'student/roomChangeRequestForm.tpl');
 }
Ejemplo n.º 5
0
 public function show()
 {
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     PHPWS_Core::initModClass('hms', 'HMS_Util.php');
     PHPWS_Core::initModClass('filecabinet', 'Cabinet.php');
     $hall = new HMS_Residence_Hall($this->hallId);
     $tpl = array();
     $tpl['HALL'] = $hall->hall_name;
     if (isset($hall->exterior_image_id)) {
         $tpl['EXTERIOR_IMAGE'] = Cabinet::getTag($hall->exterior_image_id);
     }
     if (isset($hall->room_plan_image_id) && $hall->room_plan_image_id != 0) {
         $file = Cabinet::getFile($hall->room_plan_image_id);
         $tpl['ROOM_PLAN_IMAGE'] = $file->parentLinked();
     }
     if (isset($hall->map_image_id)) {
         $tpl['MAP_IMAGE'] = Cabinet::getTag($hall->map_image_id);
     }
     if (isset($hall->other_image_id) && $hall->other_image_id != 0 && $hall->other_image_id != '0') {
         $file = Cabinet::getFile($hall->other_image_id);
         $tpl['OTHER_IMAGE'] = $file->parentLinked();
     }
     if ($this->rlcAssignment != null && ($this->rlcAssignment->getStateName() == 'confirmed' || $this->rlcAssignment->getStateName() == 'selfselect-invite')) {
         $rlcId = $this->rlcAssignment->getRlc()->getId();
     } else {
         $rlcId = null;
     }
     $floors = $hall->get_floors();
     foreach ($floors as $floor) {
         $row = array();
         if ($floor->count_avail_lottery_rooms($this->student->getGender(), $rlcId) <= 0) {
             $row['FLOOR'] = HMS_Util::ordinal($floor->floor_number);
             $row['ROW_TEXT_COLOR'] = 'class="text-muted"';
             $tpl['floor_list'][] = $row;
             continue;
         }
         $floorCmd = CommandFactory::getCommand('LotteryChooseFloor');
         $floorCmd->setFloorId($floor->id);
         $row['FLOOR'] = $floorCmd->getLink(HMS_Util::ordinal($floor->floor_number) . ' floor');
         $row['ROW_TEXT_COLOR'] = 'grey';
         $tpl['floor_list'][] = $row;
     }
     Layout::addPageTitle("Choose Floor");
     return PHPWS_Template::process($tpl, 'hms', 'student/lottery_choose_floor.tpl');
 }
Ejemplo n.º 6
0
 public function __construct($id = null, $type = null, Student $student = null, $term = null, HMS_Residence_Hall $hall = null, HMS_Bed $bed = null, $mealPlan = null, $mealCode = null, $percentRefund = null)
 {
     if (!is_null($id) && $id != 0) {
         $this->load();
         return;
     }
     if (is_null($type)) {
         return;
     }
     $this->type = $type;
     $this->asu_username = strtolower($student->getUsername());
     $this->term = $term;
     $this->building_code = $hall->getBannerBuildingCode();
     $this->bed_code = $bed->getBannerId();
     $this->meal_plan = $mealPlan;
     $this->meal_code = $mealCode;
     $this->percent_refund = $percentRefund;
 }
Ejemplo n.º 7
0
 public function execute()
 {
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     if (!isset($this->term) || is_null($this->term)) {
         throw new InvalidArgumentException('Missing term.');
     }
     // Get all of the residence halls for this term
     $halls = HMS_Residence_Hall::get_halls($this->term);
     $hallRow = array();
     foreach ($halls as $hall) {
         $hallName = $hall->hall_name;
         $maxOccupancy = $hall->get_number_of_online_nonoverflow_beds();
         $currOccupancy = $hall->get_number_of_assignees();
         $offline = "";
         // If the hall is offline, make a note of that
         if ($hall->is_online == 0) {
             $offline = '(Offline)';
         }
         $query = "select * from hms_room JOIN (SELECT hms_room.id, count(*) as c FROM hms_residence_hall JOIN hms_floor ON hms_residence_hall.id = hms_floor.residence_hall_id JOIN hms_room ON hms_floor.id = hms_room.floor_id JOIN hms_bed ON hms_room.id = hms_bed.room_id LEFT OUTER JOIN hms_assignment ON hms_bed.id = hms_assignment.bed_id WHERE ( hms_assignment.id IS NULL AND hms_residence_hall.id = '{$hall->id}' AND hms_room.offline = 0 AND hms_room.overflow = 0 AND hms_room.reserved = 0 AND hms_room.private = 0 AND hms_room.parlor = 0 AND hms_room.ra = 0 AND hms_bed.room_change_reserved = 0 AND hms_bed.ra_roommate = 0 AND hms_bed.international_reserved = 0) GROUP BY hms_room.id) as foo ON foo.id = hms_room.id ORDER BY hms_room.room_number";
         $results = PHPWS_DB::getAll($query);
         $maleRoomList = array();
         $femaleRoomList = array();
         $coedRoomList = array();
         // each room on this hall
         foreach ($results as $room) {
             $this->totalRooms++;
             $roomNum = $room['room_number'];
             // If the room has more than one avaialble bed, note that in the room number
             if ($room['c'] > 1) {
                 $roomNum .= '(x' . $room['c'] . ')';
             }
             // catagorize it by gender
             if ($room['gender_type'] == MALE) {
                 $maleRoomList[] = $roomNum;
                 $this->male += $room['c'];
                 $this->totalBeds += $room['c'];
             } else {
                 if ($room['gender_type'] == FEMALE) {
                     $femaleRoomList[] = $roomNum;
                     $this->female += $room['c'];
                     $this->totalBeds += $room['c'];
                 } else {
                     if ($room['gender_type'] == COED || $room['gender_type'] == AUTO) {
                         $coedRoomList[] = $roomNum;
                         $this->coed += $room['c'];
                         $this->totalBeds += $room['c'];
                     } else {
                         throw new InvalidArgumentException('Bad room gender. Room id: ' . $room['id']);
                     }
                 }
             }
         }
         $hallRow[] = array('hallName' => $hallName . $offline, 'maxOccupancy' => $maxOccupancy, 'currOccupancy' => $currOccupancy, 'maleRooms' => implode(", ", $maleRoomList), 'femaleRooms' => implode(", ", $femaleRoomList), 'coedRooms' => implode(", ", $coedRoomList));
     }
     $this->data = $hallRow;
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     PHPWS_Core::initModClass('hms', 'HMS_Util.php');
     //TODO check for a hallId
     $hall = new HMS_Residence_Hall($context->get('hallId'));
     $floors = $hall->getFloorsWithVacancies();
     $json_floors = array();
     $json_floors[0] = 'Select ...';
     foreach ($floors as $floor) {
         unset($text);
         $text = $floor->floor_number;
         if ($hall->gender_type == COED && $floor->gender_type != COED) {
             $text .= ' (' . HMS_Util::formatGender($floor->gender_type) . ')';
         }
         $json_floors[$floor->id] = $text;
     }
     $context->setContent(json_encode($json_floors));
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'SelectHallView.php');
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     $term = Term::getSelectedTerm();
     $halls = HMS_Residence_Hall::get_halls_array($term);
     $onSelectCmd = CommandFactory::getCommand($context->get('onSelectAction'));
     $hallView = new SelectHallView($onSelectCmd, $halls, $context->get('title'), $term);
     $context->setContent($hallView->show());
 }
Ejemplo n.º 10
0
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'AssignByFloorView.php');
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     $term = Term::getSelectedTerm();
     $halls = HMS_Residence_Hall::getHallsDropDownValues($term);
     $onSelectCmd = CommandFactory::getCommand($context->get('onSelectAction'));
     $onSelectCmd->setFloorId($context->get('floor'));
     $floorView = new AssignByFloorView($onSelectCmd, $halls, $context->get('title'), $term);
     $context->setContent($floorView->show());
 }
Ejemplo n.º 11
0
 /**
  * Queues a Remove Assignment
  *
  * NOTE: If the queue contains a Create Assignment for the same
  * user to the same room, this will NOT queue a room assignment,
  * but rather will delete the original assignment, UNLESS the
  * $force_queue flag is set.  The $force_queue flag being true will
  * queue a removal no matter what.
  *
  * MORE NOTE: If this requires immediate processing because banner
  * commits are enabled, the it will be sent straight to Banner,
  * and so the force_queue flag will be ignored.
  */
 public static function queueRemoveAssignment(Student $student, $term, HMS_Residence_Hall $hall, HMS_Bed $bed, $refund)
 {
     $entry = new BannerQueueItem(0, BANNER_QUEUE_REMOVAL, $student, $term, $hall, $bed, null, null, $refund);
     if (BannerQueue::processImmediately($term)) {
         return $entry->process();
     }
     // Otherwise, look for an corresponding assignment
     $db = new PHPWS_DB('hms_banner_queue');
     $db->addWhere('type', BANNER_QUEUE_ASSIGNMENT);
     $db->addWhere('asu_username', $student->getUsername());
     $db->addWhere('building_code', $hall->getBannerBuildingCode());
     $db->addWhere('bed_code', $bed->getBannerId());
     $db->addWhere('term', $term);
     $result = $db->count();
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     if ($result == 0) {
         return $entry->save();
     } else {
         return $db->delete();
     }
 }
Ejemplo n.º 12
0
 /**
  * Checks each hall, floor, and room for the given term and returns 
  * an associative array containing all of the invalid items.
  **/
 public function check($term = null)
 {
     $results = array();
     if (!isset($term)) {
         $term = Term::getCurrentTerm();
     }
     $halls = HMS_Residence_Hall::get_halls($term);
     foreach ($halls as $hall) {
         $floors = $hall->get_floors();
         if (!isset($floors)) {
             $results[$hall->hall_name] = "No Floors in Hall!";
         } else {
             foreach ($floors as $floor) {
                 if ($hall->gender_type != COED && $floor->gender_type != $hall->gender_type) {
                     $results[$hall->hall_name][$floor->floor_number] = "Gender Mismatch With Hall";
                     continue;
                 }
                 $rooms = $floor->get_rooms();
                 if (!isset($rooms)) {
                     $results[$hall->hall_name][$floor->floor_number] = "No rooms in Floor!";
                 } else {
                     foreach ($rooms as $room) {
                         if ($floor->gender_type != COED && $room->gender_type != $floor->gender_type) {
                             $results[$hall->hall_name][$floor->floor_number][$room->room_number] = "Gender Mismatch with Floor " . "(Floor: " . $floor->gender_type . ") (Room: " . $room->gender_type . ")";
                         }
                     }
                 }
                 $suites = $floor->get_suites();
                 if (isset($suites)) {
                     foreach ($suites as $suite) {
                         $rooms = $suite->get_rooms();
                         $suite_gender = null;
                         foreach ($rooms as $room) {
                             if (!isset($suite_gender)) {
                                 $suite_gender = $room->gender_type;
                                 continue;
                             }
                             if ($room->gender_type != $suite_gender) {
                                 $results[$hall->hall_name][$floor->floor_number][$room->room_number] = "Suite Gender Mismatch";
                             }
                         }
                     }
                 }
             }
         }
     }
     return $results;
 }
Ejemplo n.º 13
0
 public function getCountsForHall(HMS_Residence_Hall $hall)
 {
     return $this->hallCounts[$hall->getId()];
 }
Ejemplo n.º 14
0
 public function send_emails()
 {
     if (empty($_REQUEST['subject'])) {
         return Notification::show_edit_email('You must fill in the subject line of the email.', '', $_REQUEST['body']);
     } else {
         if (empty($_REQUEST['body'])) {
             return Notification::show_edit_email('You must fill in the message to be sent.', $_REQUEST['subject'], '');
         }
     }
     $from = isset($_REQUEST['anonymous']) && Current_User::allow('hms', 'anonymous_notification') ? FROM_ADDRESS : Current_User::getEmail();
     $subject = $_REQUEST['subject'];
     $body = $_REQUEST['body'];
     //Consider using a batch process instead of doing this this inline
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     // Log that this is happening
     if ($from == FROM_ADDRESS) {
         HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_ANON_NOTIFICATION_SENT, Current_User::getUsername());
     } else {
         HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_NOTIFICATION_SENT, Current_User::getUsername());
     }
     if (is_array($_REQUEST['hall'])) {
         foreach ($_REQUEST['hall'] as $hall_id) {
             $hall = new HMS_Residence_Hall($hall_id);
             $floors = $hall->get_floors();
             foreach ($floors as $floor) {
                 $rooms = $floor->get_rooms();
                 foreach ($rooms as $room) {
                     $students = $room->get_assignees();
                     foreach ($students as $student) {
                         HMS_Email::send_email($student->asu_username . '@appstate.edu', $from, $subject, $body);
                     }
                 }
             }
             if ($from == FROM_ADDRESS) {
                 HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_HALL_NOTIFIED_ANONYMOUSLY, Current_User::getUsername(), $hall->hall_name);
             } else {
                 HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_HALL_NOTIFIED, Current_User::getUsername(), $hall->hall_name);
             }
         }
     } else {
         $hall = new HMS_Residence_Hall($_REQUEST['hall']);
         $floors = $hall->get_floors();
         foreach ($floors as $floor) {
             $rooms = $floor->get_rooms();
             foreach ($rooms as $room) {
                 $students = $room->get_assignees();
                 foreach ($students as $student) {
                     HMS_Email::send_email($student->asu_username . '@appstate.edu', $from, $subject, $body);
                 }
             }
         }
         if ($from == FROM_ADDRESS) {
             HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_HALL_NOTIFIED_ANONYMOUSLY, Current_User::getUsername(), $hall->hall_name);
         } else {
             HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_HALL_NOTIFIED, Current_User::getUsername(), $hall->hall_name);
         }
     }
     return Notification::show_confirmation();
 }
Ejemplo n.º 15
0
 public function setHallPref2(HMS_Residence_Hall $hall)
 {
     $this->hall_pref2 = $hall->getId();
 }
 public function execute(CommandContext $context)
 {
     $term = $context->get('term');
     if (!isset($term)) {
         throw new InvalidArgumentException('Missing term.');
     }
     // Get the list of floors which the current user has permission to assess
     // Get the list of role memberships this user has
     $hms_perm = new HMS_Permission();
     $memberships = $hms_perm->getMembership('assess_damage', NULL, UserStatus::getUsername());
     if (empty($memberships)) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException("You do not have permission to assess damages on any residence halls or floors.");
     }
     // Use the roles to instantiate a list of floors this user has access to
     $floors = array();
     foreach ($memberships as $member) {
         if ($member['class'] == 'hms_residence_hall') {
             $hall = new HMS_Residence_Hall($member['instance']);
             if (!is_array($floors)) {
                 $floors = array();
             }
             $hallFloors = $hall->getFloors();
             if (!is_array($hallFloors)) {
                 $hallFloors = array();
             }
             $floors = array_merge($floors, $hallFloors);
         } else {
             if ($member['class'] == 'hms_floor') {
                 $floors[] = new HMS_Floor($member['instance']);
             } else {
                 throw new Exception('Unknown object type.');
             }
         }
     }
     // Remove duplicate floors
     $uniqueFloors = array();
     foreach ($floors as $floor) {
         $uniqueFloors[$floor->getId()] = $floor;
     }
     // Filter the list of floors for just the term we're interested in
     foreach ($uniqueFloors as $k => $f) {
         if ($f->getTerm() != $term) {
             unset($uniqueFloors[$k]);
         }
     }
     // Get the list of damages with pending assessments on those floors
     $damages = RoomDamageFactory::getDamagesToAssessByFloor($uniqueFloors, $term);
     $roomList = array();
     // For each damage, get the list of responsible students
     foreach ($damages as &$dmg) {
         $pId = $dmg->getRoomPersistentId();
         $dmg->responsibilities = RoomDamageResponsibilityFactory::getResponsibilitiesByDmg($dmg);
         foreach ($dmg->responsibilities as &$resp) {
             $student = StudentFactory::getStudentByBannerId($resp->getBannerId(), $term);
             $resp->studentName = $student->getName();
         }
         $roomList[$dmg->getRoomPersistentId()][] = $dmg;
     }
     $rooms = array();
     foreach ($roomList as $pId => $dmgList) {
         $roomObj = RoomFactory::getRoomByPersistentId($pId, $term);
         $roomObj->hallName = $roomObj->get_parent()->get_parent()->getHallName();
         $roomObj->damages = $dmgList;
         $rooms[] = $roomObj;
     }
     // JSON enocde it all and send it to Angular
     $context->setContent(json_encode($rooms));
 }
 public function execute(CommandContext $context)
 {
     // Cmd to redirect to when we're done or upon error.
     $formCmd = CommandFactory::getCommand('ShowRoomChangeRequestForm');
     $menuCmd = CommandFactory::getCommand('ShowStudentMenu');
     // Get input
     $cellNum = $context->get('cell_num');
     $optOut = $context->get('cell_opt_out');
     $firstHallPref = $context->get('first_choice');
     $secondHallPref = $context->get('second_choice');
     $term = Term::getCurrentTerm();
     // Create the student object
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     // Make sure the student is currently assigned
     $assignment = HMS_Assignment::getAssignmentByBannerId($student->getBannerId(), $term);
     if (is_null($assignment)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You are not currently assigned to a room, so you cannot request a room change.');
         $menuCmd->redirect();
     }
     // Get the HMS_Bed object corresponding to the student's current assignment
     $bed = $assignment->get_parent();
     $room = $bed->get_parent();
     // Check for an existing room change request
     $changeReq = RoomChangeRequestFactory::getPendingByStudent($student, $term);
     if (!is_null($changeReq)) {
         // has pending request
         NQ::simple('hms', hms\NotificationView::ERROR, 'You already have a pending room change request. You cannot submit another request until your pending request is processed.');
         $menuCmd->redirect();
     }
     // Check that a cell phone number was provided, or that the opt-out box was checked.
     if ((!isset($cellNum) || empty($cellNum)) && !isset($optOut)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Please provide a cell phone number or check the box indicating you do not wish to provide it.');
         $formCmd->redirect();
     }
     // Check the format of the cell phone number
     if (isset($cellNum)) {
         // Filter out non-numeric characters
         $cellNum = preg_replace("/[^0-9]/", '', $cellNum);
     }
     $reason = $context->get('reason');
     // Make sure a 'reason' was provided.
     if (!isset($reason) || empty($reason)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Please provide a brief explaniation of why you are requesting a room change.');
         $formCmd->redirect();
     }
     $type = $context->get('type');
     // Extra sanity checks if we're doing a switch
     if ($type == 'swap') {
         $switchUsername = $context->get('swap_with');
         // Can't switch with yourself
         if ($student->getUsername() == $switchUsername) {
             NQ::simple('hms', hms\NotificationView::ERROR, "You can't swtich rooms with yourself. Please choose someone other than yourself.");
             $formCmd->redirect();
         }
         // Load the other student
         try {
             $swapStudent = StudentFactory::getStudentByUsername($switchUsername, $term);
         } catch (StudentNotFoundException $e) {
             NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, we could not find a student with the user name '{$switchUsername}'. Please double-check the user name of the student you would like to switch places with.");
             $formCmd->redirect();
         }
         // Make sure the student is assigned
         $swapAssignment = HMS_Assignment::getAssignmentByBannerId($swapStudent->getBannerId(), $term);
         if (is_null($swapAssignment)) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$swapStudent->getName()} is not currently assigned. Please choose another student to switch rooms with.");
             $formCmd->redirect();
         }
         // Make sure the other student's room is the same gender as this room
         $swapBed = $swapAssignment->get_parent();
         $swapRoom = $swapBed->get_parent();
         if ($swapRoom->getGender() != $room->getGender()) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$swapStudent->getName()} is assigned to a room of a different gender than you. Please choose student of the same gender as yourself to switch rooms with.");
             $formCmd->redirect();
         }
         // Check to see if the other student is already involved in a room change request
         $swapStudentReq = RoomChangeRequestFactory::getPendingByStudent($swapStudent, $term);
         if (!is_null($swapStudentReq)) {
             // has pending request
             NQ::simple('hms', hms\NotificationView::ERROR, 'The student you are requesting to swap with already has a pending room change request. You cannot request to swap with him/her until the pending request is processed.');
             $menuCmd->redirect();
         }
     }
     //create the request object
     $request = new RoomChangeRequest($term, $reason);
     $request->save();
     // Main participant
     $participant = new RoomChangeParticipant($request, $student, $bed);
     if (isset($cellNum)) {
         $participant->setCellPhone($cellNum);
     }
     // Switching to a different room, so set params on main participant
     if ($type == 'switch') {
         // preferences
         if (!empty($firstHallPref)) {
             $hall = new HMS_Residence_Hall($firstHallPref);
             if (!is_null($hall->getId())) {
                 $participant->setHallPref1($hall);
             }
         }
         if (!empty($secondHallPref)) {
             $hall = new HMS_Residence_Hall($secondHallPref);
             if (!is_null($hall->getId())) {
                 $participant->setHallPref2($hall);
             }
         }
         // Save the main participant and its state
         $participant->save();
         // No further approval is required so we skip a step
         HMS_Email::sendRoomChangeCurrRDNotice($request);
     } else {
         if ($type == 'swap') {
             // Swapping with another student, so handle the other particpant
             // Set main participant's toBed to other student's bed
             $participant->setToBed($swapBed);
             // Create the other participant
             $swapParticipant = new RoomChangeParticipant($request, $swapStudent, $swapBed);
             // Set other student's toBed to main participant's bed
             $swapParticipant->setToBed($bed);
             $swapParticipant->save();
             // Save the main participant and its state
             $participant->save();
             // Send "request needs your approval" to other students
             // TODO: When you add the ability to have many people on this request, you will
             //       need to put a foreach loop here or something.
             HMS_Email::sendRoomChangeParticipantNotice($participant, $swapParticipant);
         }
     }
     // Immediately transition to the StudentApproved state.
     $participant->transitionTo(new ParticipantStateStudentApproved($participant, time(), null, UserStatus::getUsername()));
     HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_ROOM_CHANGE_SUBMITTED, UserStatus::getUsername(FALSE), $reason);
     // Email sender with acknowledgment
     HMS_Email::sendRoomChangeRequestReceivedConfirmation($student);
     if ($type == 'switch') {
         NQ::simple('hms', hms\NotificationView::SUCCESS, 'Your room change request has been received and is pending approval. You will be contacted by your Residence Director (RD) in the next 24-48 hours regarding your request.');
     } else {
         NQ::simple('hms', hms\NotificationView::SUCCESS, 'Your room change request has been received. The student(s) you selected to swap with must sign-in and agree to the request. It will then be forwarded to your Residence Director and the Housing Assignments Office for approval.');
     }
     $menuCmd->redirect();
 }
Ejemplo n.º 18
0
 /**
  * Returns the earliest check-in for the given student, in the given hall, which the student
  * has not checked out of yet.
  * //TODO update for persistent ID
  */
 public static function getPendingCheckoutForStudentByHall(Student $student, HMS_Residence_Hall $hall)
 {
     $db = new PHPWS_DB('hms_checkin');
     // Join the hall structure
     $db->addJoin('', 'hms_checkin', 'hms_hall_structure', 'bed_id', 'bedid');
     $db->addWhere('banner_id', $student->getBannerId());
     // Smarter term logic: If it's Spring or Summer 2 then we can also look in the previous term
     $term = $hall->getTerm();
     $sem = Term::getTermSem($term);
     if ($sem == TERM_SPRING || $sem == TERM_SUMMER2) {
         $db->addWhere('term', $term, '=', 'OR', 'term_group');
         $db->addWhere('term', Term::getPrevTerm($term), '=', 'OR', 'term_group');
     } else {
         $db->addWhere('term', $term);
     }
     // Checkin bed ID must be in the request hall
     //$db->addWhere('hms_hall_structure.hallid', $hall->getId());
     $db->addWhere('checkout_date', null, 'IS NULL');
     $db->addOrder(array('hms_checkin.checkin_date ASC'));
     // Earliest checkin first
     $checkin = new RestoredCheckin();
     $result = $db->loadObject($checkin);
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     if ($checkin->getId() == null) {
         return null;
     }
     return $checkin;
 }
Ejemplo n.º 19
0
 /**
  * Returns an associate array (key = hall id, value = hall name) of halls
  * which have an available lottery bed (based on the term, gender, the number
  * of lottery rooms allotted in the hall, the number of used lottery rooms, and
  * any pending lottery bed reservations.
  */
 public static function get_lottery_avail_hall_list($term)
 {
     $halls = HMS_Residence_Hall::get_halls($term);
     $output_list = array();
     foreach ($halls as $hall) {
         // Make sure we have a room of the specified gender available in the hall (or a co-ed room)
         if ($hall->count_avail_lottery_rooms($gender) <= 0 && $hall->count_avail_lottery_rooms(COED) <= 0) {
             continue;
         }
         $output_list[] = $hall;
     }
     return $output_list;
 }
 public function execute(CommandContext $context)
 {
     /*
     if(!Current_User::allow('hms', 'email_hall') && !Current_User::allow('hms', 'email_all')){
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to send messages.');
     }
     */
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     PHPWS_Core::initModClass('hms', 'HMS_Floor.php');
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     PHPWS_Core::initModClass('hms', 'HMS_Permission.php');
     // Sanity checks
     if (is_null($context->get('hall')) && is_null($context->get('floor'))) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You must select a hall or floor to continue!');
         $cmd = CommandFactory::getCommand('ShowHallNotificationSelect');
         $cmd->redirect();
     }
     $subject = $context->get('subject');
     $body = $context->get('body');
     $anonymous = !is_null($context->get('anonymous')) && $context->get('anonymous') ? true : false;
     $from = $anonymous && Current_User::allow('hms', 'anonymous_notifications') ? FROM_ADDRESS : Current_User::getUsername() . '@' . DOMAIN_NAME;
     $halls = $context->get('hall');
     $floors = $context->get('floor');
     if (empty($subject)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You must fill in the subject line of the email.');
         $cmd = CommandFactory::getCommand('ShowHallNotificationEdit');
         $cmd->loadContext($context);
         $cmd->redirect();
     } else {
         if (empty($body)) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'You must fill in the message to be sent.');
             $cmd = CommandFactory::getCommand('ShowHallNotificationEdit');
             $cmd->loadContext($context);
             $cmd->redirect();
         }
     }
     //Consider using a batch process instead of doing this this inline
     // Log that this is happening
     if ($anonymous) {
         HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_ANON_NOTIFICATION_SENT, Current_User::getUsername());
     } else {
         HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_NOTIFICATION_SENT, Current_User::getUsername());
     }
     //load the floors
     foreach ($floors as $key => $floor_id) {
         $floors[$key] = new HMS_Floor($floor_id);
     }
     // TODO accurate logging
     //HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_HALL_NOTIFIED_ANONYMOUSLY, Current_User::getUsername(), $hall->hall_name);
     //HMS_Activity_Log::log_activity(Current_User::getUsername(), ACTIVITY_HALL_NOTIFIED, Current_User::getUsername(), $hall->hall_name);
     $floorObj = array();
     //load the halls and add floors that aren't already present, if they have js enabled should be zero
     foreach ($halls as $hall) {
         $hallObj = new HMS_Residence_Hall($hall);
         $hallFloors = $hallObj->get_floors();
         //if the hall has zero floors, skip it
         if (!is_array($hallFloors)) {
             continue;
         }
         foreach ($hallFloors as $hallFloor) {
             if (!empty($floors)) {
                 foreach ($floors as $floor) {
                     if ($hallFloor->id == $floor->id) {
                         break;
                     }
                 }
             }
             if (!in_array($hallFloor, $floors)) {
                 $floorObj[] = $hallFloor;
             }
         }
     }
     if (!is_array($floorObj)) {
         $floorObj = array();
     }
     if (!is_array($floors)) {
         $floors = array();
     }
     $floorObj = array_merge($floorObj, $floors);
     $permission = new HMS_Permission();
     foreach ($floorObj as $floor) {
         if (!$permission->verify(Current_User::getUsername(), $floor, 'email') && !$permission->verify(Current_User::getUsername(), $floor->get_parent(), 'email') && !Current_User::allow('hms', 'email_all')) {
             continue;
         }
         /**
         $rooms = $floor->get_rooms();
         foreach($rooms as $room){
             $students = $room->get_assignees();
             foreach($students as $student){
                 $people[] = $student->getUsername();
                 HMS_Email::send_email($student->getUsername() . '@appstate.edu', $from, $subject, $body);
             }
         }
         */
         $students = $floor->getUsernames();
         foreach ($students as $student) {
             HMS_Email::send_email($student . '@' . DOMAIN_NAME, $from, $subject, $body);
         }
         HMS_Activity_Log::log_activity(Current_User::getUsername(), $anonymous ? ACTIVITY_FLOOR_NOTIFIED_ANONYMOUSLY : ACTIVITY_FLOOR_NOTIFIED, Current_User::getUsername(), $floor->where_am_i());
     }
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Emails sent successfully!');
     $cmd = CommandFactory::getCommand('ShowAdminMaintenanceMenu');
     $cmd->redirect();
 }
Ejemplo n.º 21
0
 /**
  * (non-PHPdoc)
  * @see View::show()
  */
 public function show()
 {
     PHPWS_Core::initCoreClass('Form.php');
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'assignment_maintenance')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to unassign students.');
     }
     javascript('jquery');
     javascript('modules/hms/assign_student');
     $tpl = array();
     $tpl['TERM'] = Term::getPrintableSelectedTerm();
     $form = new PHPWS_Form();
     $assignCmd = CommandFactory::getCommand('AssignStudent');
     $assignCmd->initForm($form);
     $form->addHidden('term', Term::getSelectedTerm());
     $form->addText('username');
     $form->setLabel('username', 'ASU Username: '******'username', $this->student->getUsername());
     }
     $form->addCssClass('username', 'form-control');
     $form->setExtra('username', 'autofocus');
     // Check to see if a bed_id was passed in, this means
     // the user clicked an 'unassigned' link. We need to pre-populate
     // the drop downs.
     unset($pre_populate);
     if (isset($this->bed)) {
         $pre_populate = true;
         $room = $this->bed->get_parent();
         $floor = $room->get_parent();
         $hall = $floor->get_parent();
     } else {
         $pre_populate = false;
     }
     $hallList = HMS_Residence_Hall::getHallsWithVacanciesArray(Term::getSelectedTerm());
     $form->addDropBox('residence_hall', $hallList);
     if ($pre_populate) {
         $form->setMatch('residence_hall', $hall->id);
     } else {
         $form->setMatch('residence_hall', 0);
     }
     $form->setLabel('residence_hall', 'Residence hall: ');
     $form->addCssClass('residence_hall', 'form-control');
     if ($pre_populate) {
         $form->addDropBox('floor', $hall->get_floors_array());
         $form->setMatch('floor', $floor->id);
     } else {
         $form->addDropBox('floor', array(0 => ''));
     }
     $form->setLabel('floor', 'Floor: ');
     $form->addCssClass('floor', 'form-control');
     if ($pre_populate) {
         $form->addDropBox('room', $floor->get_rooms_array());
         $form->setMatch('room', $room->id);
     } else {
         $form->addDropBox('room', array(0 => ''));
     }
     $form->setLabel('room', 'Room: ');
     $form->addCssClass('room', 'form-control');
     if ($pre_populate) {
         $form->addDropBox('bed', $room->get_beds_array());
         $form->setMatch('bed', $this->bed->id);
         $show_bed_drop = true;
     } else {
         $form->addDropBox('bed', array(0 => ''));
         $show_bed_drop = false;
     }
     $form->setLabel('bed', 'Bed: ');
     $form->addCssClass('bed', 'form-control');
     if ($show_bed_drop) {
         $tpl['BED_STYLE'] = '';
         $tpl['LINK_STYLE'] = 'display: none';
     } else {
         $tpl['BED_STYLE'] = 'display: none';
         $tpl['LINK_STYLE'] = '';
     }
     $form->addDropBox('meal_plan', array(BANNER_MEAL_LOW => 'Low', BANNER_MEAL_STD => 'Standard', BANNER_MEAL_HIGH => 'High', BANNER_MEAL_SUPER => 'Super', BANNER_MEAL_NONE => 'None', BANNER_MEAL_5WEEK => 'Summer (5 weeks)'));
     $form->setLabel('meal_plan', 'Meal plan: ');
     $form->addCssClass('meal_plan', 'form-control');
     // If the username was passed in, and that student has a meal plan
     // pre-select the student's chosen meal plan
     if (isset($this->application)) {
         $form->setMatch('meal_plan', $this->application->getMealPlan());
     } else {
         // Otherwise, select 'standard' meal plan
         $form->setMatch('meal_plan', BANNER_MEAL_STD);
     }
     // "Assignment Type", see defines.php for declarations
     $form->addDropBox('assignment_type', array(-1 => 'Choose assignment type...', ASSIGN_ADMIN => 'Administrative', ASSIGN_APPEALS => 'Appeals', ASSIGN_LOTTERY => 'Lottery', ASSIGN_FR => 'Freshmen', ASSIGN_TRANSFER => 'Transfer', ASSIGN_APH => 'APH', ASSIGN_RLC_FRESHMEN => 'RLC Freshmen', ASSIGN_RLC_TRANSFER => 'RLC Transfer', ASSIGN_RLC_CONTINUING => 'RLC Continuing', ASSIGN_HONORS_FRESHMEN => 'Honors Freshmen', ASSIGN_HONORS_CONTINUING => 'Honors Continuing', ASSIGN_LLC_FRESHMEN => 'LLC Freshmen', ASSIGN_LLC_CONTINUING => 'LLC Continuing', ASSIGN_INTL => 'International', ASSIGN_RA => 'RA', ASSIGN_RA_ROOMMATE => 'RA Roommate', ASSIGN_MEDICAL_FRESHMEN => 'Medical Freshmen', ASSIGN_MEDICAL_CONTINUING => 'Medical Continuing', ASSIGN_SPECIAL_FRESHMEN => 'Special Needs Freshmen', ASSIGN_SEPCIAL_CONTINUING => 'Special Needs Continuing', ASSIGN_RHA => 'RHA/NRHH', ASSIGN_SCHOLARS => 'Diversity &amp; Plemmons Scholars'));
     $form->setMatch('assignment_type', -1);
     $form->setLabel('assignment_type', 'Assignment Type: ');
     $form->addCssClass('assignment_type', 'form-control');
     if ($pre_populate) {
         $form->addHidden('use_bed', 'true');
     } else {
         $form->addHidden('use_bed', 'false');
     }
     $form->addTextarea('note');
     $form->setLabel('note', 'Note: ');
     $form->addCssClass('note', 'form-control');
     $form->mergeTemplate($tpl);
     $tpl = $form->getTemplate();
     Layout::addPageTitle("Assign Student");
     return PHPWS_Template::process($tpl, 'hms', 'admin/assignStudent.tpl');
 }
Ejemplo n.º 22
0
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'edit_terms')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to edit terms.');
     }
     $successCmd = CommandFactory::getCommand('ShowEditTerm');
     $errorCmd = CommandFactory::getCommand('ShowCreateTerm');
     $year = $context->get('year_drop');
     $sem = $context->get('term_drop');
     if (!isset($year) || is_null($year) || empty($year)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You must provide a year.');
         $errorCmd->redirect();
     }
     if (!isset($sem) || is_null($sem) || empty($sem)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You must provide a semester.');
         $errorCmd->redirect();
     }
     // Check to see if the specified term already exists
     if (!Term::isValidTerm($year . $sem)) {
         $term = new Term(NULL);
         $term->setTerm($year . $sem);
         $term->setBannerQueue(1);
         try {
             $term->save();
         } catch (DatabaseException $e) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error saving the term. Please try again or contact ESS.');
             $errorCmd->redirect();
         }
     } else {
         $term = new Term($year . $sem);
         // The term already exists, make sure there are no halls for this term
         $db = new PHPWS_DB('hms_residence_hall');
         $db->addWhere('term', $term->getTerm());
         $num = $db->count();
         if (!is_null($num) && $num > 0) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'One or more halls already exist for this term, so nothing can be copied.');
             $errorCmd->redirect();
         }
     }
     $text = Term::toString($term->getTerm());
     $copy = $context->get('copy_pick');
     $copyAssignments = false;
     $copyRoles = false;
     // If you want to copy roles and/or assignments
     // you must also copy the hall structure.
     if (isset($copy['struct'])) {
         // Copy hall structure
         if (isset($copy['assign'])) {
             // Copy assignments.
             $copyAssignments = true;
         }
         if (isset($copy['role'])) {
             // Copy roles.
             $copyRoles = true;
         }
     } else {
         // either $copy == 'nothing', or the view didn't specify... either way, we're done
         NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully.");
         $successCmd->redirect();
     }
     # Figure out which term we're copying from, if there isn't one then use the "current" term.
     $fromTerm = $context->get('from_term');
     if (is_null($fromTerm)) {
         $fromTerm = Term::getCurrentTerm();
     }
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     $db = new PHPWS_DB();
     try {
         $db->query('BEGIN');
         # Get the halls from the current term
         $halls = HMS_Residence_Hall::get_halls($fromTerm);
         set_time_limit(36000);
         foreach ($halls as $hall) {
             $hall->copy($term->getTerm(), $copyAssignments, $copyRoles);
         }
         $db->query('COMMIT');
     } catch (Exception $e) {
         $db->query('ROLLBACK');
         PHPWS_Error::log(print_r($e, true), 'hms');
         NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error copying the hall structure and/or assignments. The term was created, but nothing was copied.');
         $errorCmd->redirect();
     }
     if ($copyAssignments) {
         NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully. The hall structure and assignments were copied successfully.");
     } else {
         NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully and hall structure copied successfully.");
     }
     Term::setSelectedTerm($term->getTerm());
     $successCmd->redirect();
 }
 public function show()
 {
     $tpl = array();
     // Student info
     $tpl['NAME'] = $this->student->getProfileLink();
     $tpl['BANNER_ID'] = $this->student->getBannerId();
     // Participant ID
     // $tpl['PARTICIPANT_ID'] = $this->participant->getId();
     $tpl['CELL_PHONE'] = $this->participant->getCellPhone();
     // Hall Preferences
     $pref1 = $this->participant->getHallPref1();
     $pref2 = $this->participant->getHallPref2();
     if (!is_null($pref1)) {
         $hall1 = new HMS_Residence_Hall($pref1);
         $hallName = $hall1->getHallName();
         // Check if there's also a second hall preference
         if (!is_null($pref2)) {
             $hall2 = new HMS_Residence_Hall($pref2);
             $hallName .= ', ' . $hall2->getHallName();
         }
         $tpl['HALL_PREF'] = $hallName;
     }
     // From bed
     $fromBed = new HMS_Bed($this->participant->getFromBed());
     $tpl['FROM_ROOM'] = $fromBed->where_am_i();
     // To bed
     $toBedId = $this->participant->getToBed();
     if (isset($toBedId)) {
         // If there's already a bed set, show the selected bed
         $toBed = new HMS_Bed($toBedId);
         $tpl['TO_ROOM'] = $toBed->where_am_i();
     }
     /**
      * Check to see if the state is already approved or completed
      */
     $requestState = $this->request->getState();
     if ($requestState instanceof RoomChangeStatePending || $requestState instanceof RoomChangeStateHold) {
         /**
          * Check that the participant is checked into their current assignment
          */
         $checkin = CheckinFactory::getCheckinByBed($this->student, $fromBed);
         if ($checkin == null || $checkin != null && $checkin->getCheckoutDate() != null) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$this->student->getName()} is not checked-in at his/her current assignment. This must be fixed before this room change can be given final approval.");
         }
     }
     /**
      * **
      * Show approval buttons based on participant's current state
      */
     $particpantState = $this->participant->getState();
     $form = new PHPWS_Form('participant_form');
     if ($particpantState instanceof ParticipantStateNew) {
         // Particpant is in new state, waiting on this student'a approval
         // If the student is logged in, or the user is an admin, show the approve button
         if (UserStatus::getUsername() == $this->student->getUsername() || Current_User::allow('hms', 'admin_approve_room_change')) {
             $approveCmd = CommandFactory::getCommand('RoomChangeStudentApprove');
             $approveCmd->setParticipantId($this->participant->getId());
             $approveCmd->setRequestId($this->request->getId());
             $approveCmd->initForm($form);
             $form->mergeTemplate($tpl);
             $tpl = $form->getTemplate();
             $tpl['APPROVE_BTN'] = '';
             // dummy tag for approve button
         }
     } else {
         if ($particpantState instanceof ParticipantStateStudentApproved) {
             // Participant is in StudentApproved state
             // Get current list of RDs for this participant
             $rds = $this->participant->getCurrentRdList();
             // If current user is an RD for the "from bed" or an admin
             if (in_array(UserStatus::getUsername(), $rds) || Current_User::allow('hms', 'admin_approve_room_change')) {
                 if (!isset($toBedId) && count($this->participants) == 1) {
                     /*
                      * If there's only one particpant and the toBed is not already set,
                      * and the currnent user if the participants current RD, then show the bed selector
                      *
                      * Limit to 1 participant since room selection is for room "switch" requests only, not swaps.
                      * For swaps, the destination bed is already known and is not editable.
                      */
                     // Show the "select a bed" dialog, values are loaded via AJAX
                     $form->addDropBox('bed_select', array('-1' => 'Loading...'));
                     $form->addHidden('gender', $this->student->getGender());
                 }
                 $approveCmd = CommandFactory::getCommand('RoomChangeCurrRdApprove');
                 $approveCmd->setParticipantId($this->participant->getId());
                 $approveCmd->setRequestId($this->request->getId());
                 $approveCmd->initForm($form);
                 $form->mergeTemplate($tpl);
                 $tpl = $form->getTemplate();
                 $tpl['APPROVE_BTN'] = '';
                 // dummy tag for approve button
             }
         } else {
             if ($particpantState instanceof ParticipantStateCurrRdApproved) {
                 // Current RD has approved, Future RD needs to approve
                 // If current user if future RD or admin, show the approve button
                 // Get list of future RDs for "to bed"
                 $rds = $this->participant->getFutureRdList();
                 // Only future RDs and admins can approve
                 if (in_array(UserStatus::getUsername(), $rds) || Current_User::allow('hms', 'admin_approve_room_change')) {
                     $approveCmd = CommandFactory::getCommand('RoomChangeFutureRdApprove');
                     $approveCmd->setParticipantId($this->participant->getId());
                     $approveCmd->setRequestId($this->request->getId());
                     $approveCmd->initForm($form);
                     $form->mergeTemplate($tpl);
                     $tpl = $form->getTemplate();
                     $tpl['APPROVE_BTN'] = '';
                 }
             }
         }
     }
     // Show the edit link for to room if request type is a "switch", user has permissions, and status allows it
     // TODO
     /*** Participant History ***/
     $states = RoomChangeParticipantStateFactory::getStateHistory($this->participant);
     if (!is_null($states)) {
         $stateRows = array();
         foreach ($states as $historyState) {
             $stateRows[] = array('STATE_NAME' => $historyState->getFriendlyName(), 'EFFECTIVE_DATE' => date('M j, Y g:ia', $historyState->getEffectiveDate()), 'COMMITTED_BY' => $historyState->getCommittedBy());
         }
     }
     $tpl['history_rows'] = $stateRows;
     return PHPWS_Template::process($tpl, 'hms', 'admin/roomChangeParticipantView.tpl');
 }