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');
 }
 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->get_floors();
     #test($floors, 1);
     $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)
 {
     /*
     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();
 }
Beispiel #4
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();
 }