public function execute(CommandContext $context)
 {
     $term = Term::getSelectedTerm();
     $messageAll = Current_User::allow('hms', 'email_all');
     $db = new PHPWS_DB('hms_residence_hall');
     $db->addWhere('term', $term);
     $results = $db->getObjects('HMS_Residence_Hall');
     if (PHPWS_Error::logIfError($results) || is_null($results)) {
         $errorMsg = array();
         if (is_null($results)) {
             $errorMsg['error'] = 'You do not have permission to message any halls, sorry.';
         } else {
             $errorMsg['error'] = 'There was a problem reading the database, please try reloading the page.  If the problem persists contact ESS.';
         }
         echo json_encode($errorMsg);
         exit;
     }
     $permission = new HMS_Permission();
     $data = array();
     foreach ($results as $hall) {
         $somethingEnabled = false;
         $floors = $hall->get_floors();
         unset($obj);
         $obj = new stdClass();
         $obj->name = $hall->getHallName();
         $obj->id = $hall->getId();
         $obj->floors = array();
         //$blah = 'Verify: ' . ($permission->verify(UserStatus::getUsername(), $hall, 'email') ? 'true' : 'false');
         if ($permission->verify(UserStatus::getUsername(), $hall, 'email') || $messageAll) {
             $obj->enabled = true;
             $somethingEnabled = true;
             foreach ($floors as $floor) {
                 unset($floor_obj);
                 $floor_obj = new stdClass();
                 $floor_obj->name = "Floor: " . $floor->getFloorNumber();
                 $floor_obj->id = $floor->getId();
                 $floor_obj->enabled = true;
                 $obj->floors[] = $floor_obj;
             }
         } else {
             $obj->enabled = false;
             foreach ($floors as $floor) {
                 unset($floor_obj);
                 $floor_obj = new stdClass();
                 $floor_obj->name = "Floor: " . $floor->getFloorNumber();
                 $floor_obj->id = $floor->getId();
                 $floor_obj->enabled = $permission->verify(Current_User::getUsername(), $floor, 'email');
                 $obj->floors[] = $floor_obj;
                 if ($floor_obj->enabled) {
                     $somethingEnabled = true;
                 }
             }
         }
         if ($somethingEnabled) {
             $data[] = $obj;
         }
     }
     echo json_encode($data);
     exit;
 }
 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());
 }
예제 #3
0
 public function __construct()
 {
     parent::__construct();
     if (UserStatus::isAdmin()) {
         if (Current_User::allow('hms', 'assignment_maintenance')) {
             $this->addCommandByName('Assign student', 'ShowAssignStudent');
             $this->addCommandByName('Unassign student', 'ShowUnassignStudent');
             $this->addCommandByName('Set move-in times', 'ShowMoveinTimesView');
         }
         if (Current_User::allow('hms', 'run_hall_overview')) {
             $hallOverviewCmd = CommandFactory::getCommand('SelectResidenceHall');
             $hallOverviewCmd->setTitle('Hall Overview');
             $hallOverviewCmd->setOnSelectCmd(CommandFactory::getCommand('HallOverview'));
             $this->addCommand('Hall Overview', $hallOverviewCmd);
         }
         if (Current_User::allow('hms', 'assign_by_floor')) {
             $floorAssignCmd = CommandFactory::getCommand('AssignByFloor');
             $floorAssignCmd->setOnSelectCmd(CommandFactory::getCommand('ShowFloorAssignmentView'));
             $floorAssignCmd->setTitle('Assign Students to Floor');
             $this->addCommand('Assign students by floor', $floorAssignCmd);
         }
         if (UserStatus::isAdmin() && Current_User::allow('hms', 'roommate_maintenance')) {
             $this->addCommandByName('Edit freshmen roommate requests', 'EditRoommateGroupsView');
         }
         if (Current_User::allow('hms', 'autoassign')) {
             $autoAssignCmd = CommandFactory::getCommand('JSConfirm');
             $autoAssignCmd->setLink('Auto-assign');
             $autoAssignCmd->setTitle('Auto-assign');
             $autoAssignCmd->setQuestion('Start auto-assign process for the selected term?');
             $autoAssignCmd->setOnConfirmCommand(CommandFactory::getCommand('ScheduleAutoassign'));
             $this->addCommand('Start Autoassigner', $autoAssignCmd);
         }
         if (Current_User::allow('hms', 'withdrawn_search')) {
             $withdrawnSearchCmd = CommandFactory::getCommand('JSConfirm');
             $withdrawnSearchCmd->setLink('Withdrawn search');
             $withdrawnSearchCmd->setTitle('Withdrawn search');
             $withdrawnSearchCmd->setQuestion('Start search for withdrawn students for the selected term?');
             $withdrawnSearchCmd->setOnConfirmCommand(CommandFactory::getCommand('WithdrawnSearch'));
             $this->addCommand('Withdrawn search', $withdrawnSearchCmd);
         }
         $hms_perm = new HMS_Permission();
         $memberships = $hms_perm->getMembership('room_change_approve', NULL, UserStatus::getUsername());
         if (!empty($memberships)) {
             $RDRoomChangeCmd = CommandFactory::getCommand('ShowRDRoomChangeList');
             $this->addCommand('Room Change Approval (RD)', $RDRoomChangeCmd);
         }
         if (Current_User::allow('hms', 'admin_approve_room_change')) {
             $adminRoomChangeCmd = CommandFactory::getCommand('ShowAdminRoomChangeList');
             $this->addCommand('Room Change Approval (Admin)', $adminRoomChangeCmd);
         }
     }
 }
 public function execute(CommandContext $context)
 {
     $role_id = $context->get('role');
     $perm_id = $context->get('permission');
     if (is_null($role_id) || is_null($perm_id)) {
         echo json_encode(false);
         exit;
     }
     $role = new HMS_Role();
     $role->id = $role_id;
     $perm = new HMS_Permission();
     $perm->id = $perm_id;
     if ($role->load() && $perm->load()) {
         echo json_encode($role->addPermission($perm));
         exit;
     }
     echo json_encode(false);
     exit;
 }
예제 #5
0
 public function execute(CommandContext $context)
 {
     if (!Current_User::allow('hms', 'view_role_members')) {
         //PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         //throw new PermissionException('You do not have permission to view role members.');
         // Can't throw an exception here, since there's nothing to catch it and this is called
         // even when the user doesn't have permissions to do it
         // TODO: fix the interface so this isn't called unless the user has permissions
         // See Trac #664
         echo '';
         exit;
     }
     $class = $context->get('type');
     $instance = $context->get('instance');
     $class = new $class();
     $class->id = $instance;
     $hms_perm = new HMS_Permission();
     $members = $hms_perm->getMembership('email', $class, null, true);
     echo json_encode($members);
     exit;
 }
 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();
 }
 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));
 }
예제 #8
0
 /**
  * Copies this floor object to a new term, then calls copy on all
  * 'this' floor's rooms
  *
  * Setting $assignments to 'true' causes the copy public function to copy
  * the assignments as well as the hall structure.
  *
  * @return bool False if unsuccessful.
  */
 public function copy($to_term, $hall_id, $assignments = false, $roles = false)
 {
     if (!$this->id) {
         return false;
     }
     //echo "in hms_floor, copying this floor id: $this->id <br>";
     // Create a clone of the current floor object
     // Set id to 0, set term, and save
     $new_floor = clone $this;
     $new_floor->reset();
     $new_floor->term = $to_term;
     $new_floor->residence_hall_id = $hall_id;
     $new_floor->f_movein_time_id = null;
     $new_floor->t_movein_time_id = null;
     $new_floor->rt_movein_time_id = null;
     try {
         $new_floor->save();
     } catch (Exception $e) {
         throw $e;
     }
     // Copy any roles related to this floor.
     if ($roles) {
         PHPWS_Core::initModClass("hms", "HMS_Permission.php");
         PHPWS_Core::initModClass("hms", "HMS_Role.php");
         // Get memberships by object instance.
         $membs = HMS_Permission::getUserRolesForInstance($this);
         // Add each user to new floor
         foreach ($membs as $m) {
             // Lookup the username
             $user = new PHPWS_User($m['user_id']);
             // Load role and add user to new instance
             $role = new HMS_Role();
             $role->id = $m['role'];
             $role->load();
             $role->addUser($user->getUsername(), get_class($new_floor), $new_floor->id);
         }
     }
     // Load all the rooms for this floor
     if (empty($this->_rooms)) {
         try {
             $this->loadRooms();
         } catch (Exception $e) {
             throw $e;
         }
     }
     /**
      * Rooms exist. Start making copies.
      * Further copying is needed at the room level.
      */
     if (!empty($this->_rooms)) {
         foreach ($this->_rooms as $room) {
             try {
                 $room->copy($to_term, $new_floor->id, null, $assignments);
             } catch (Exception $e) {
                 throw $e;
             }
         }
     }
 }
예제 #9
0
 /**
  * Returns an array where each element is an associative sub-array of info for
  * the coordinators of this halll. Returns null if there is no coordinator.
  * NB: There may be multiple people with the coordinator role. This will return
  * the array of all of them.
  */
 public function getCoordinators()
 {
     return HMS_Permission::getUsersInRoleForInstance('Coordinator', $this);
 }
예제 #10
0
 /**
  * Returns an array of users names who have access to approve room changes for the
  * given bed id.
  *
  * @param int $bedId
  * @return multitype:array
  */
 private function getApproverList($bedId)
 {
     $bed = new HMS_Bed($bedId);
     $room = $bed->get_parent();
     $floor = $room->get_parent();
     $hall = $floor->get_parent();
     $hms_perm = new HMS_Permission();
     $hallMembers = $hms_perm->getMembership('room_change_approve', $hall);
     $floorMembers = $hms_perm->getMembership('room_change_approve', $floor);
     $hallMembers = array_merge($hallMembers, $floorMembers);
     $users = array();
     if (sizeof($hallMembers) <= 0) {
         return $users;
     }
     foreach ($hallMembers as $member) {
         $users[] = $member['username'];
     }
     return array_unique($users);
 }