public function execute(CommandContext $context) { $send_to = array(); $send_to[] = '*****@*****.**'; $send_to[] = '*****@*****.**'; $send_to[] = '*****@*****.**'; $send_to[] = '*****@*****.**'; $from = FROM_ADDRESS; $subject = 'HMS Contact Form'; $body = "Username: "******"\n"; $body .= "Application date: " . $context->get('application_term') . "\n"; $body .= "Student Type: " . $context->get('student_type') . "\n"; $body .= "\n\nInput from student:\n\n"; $body .= "Name: " . $context->get('name') . "\n"; $body .= "Email: " . $context->get('email') . "\n"; $body .= "Phone #: " . $context->get('phone') . "\n"; $body .= "Type: " . $context->get('stype') . "\n"; $body .= "Text field:\n"; $body .= "" . $context->get('comments') . "\n\n"; if (!HMS_Email::send_email($send_to, $from, $subject, $body)) { //Maybe we shouldn't say anything... //NQ::simple('hms', hms\NotificationView::ERROR, 'Error sending email!'); } $view = new ContactFormThankYouView(); $context->setContent($view->show()); }
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(); }
/** * Sends the email for the nightly withdrawn search output. * * @param String $text */ public static function sendWithdrawnSearchOutput($text) { $to = array('*****@*****.**', '*****@*****.**'); $subject = 'Withdrawn Student Search'; HMS_Email::send_email($to, null, $subject, $text); }
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(); }