Exemplo n.º 1
0
 /**
  * Create a new comment
  *
  * @apiMethod POST
  * @apiUri    /support/{ticket}/comments
  * @apiParameter {
  * 		"name":        "scope",
  * 		"description": "Scope type (group, member, etc.)",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "scope_id",
  * 		"description": "Scope object ID",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "title",
  * 		"description": "Entry title",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "alias",
  * 		"description": "Entry alias",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @return     void
  */
 public function createTask()
 {
     $this->requiresAuthentication();
     if (!$this->acl->check('create', 'comments')) {
         throw new Exception(Lang::txt('Not authorized'), 403);
     }
     $ticket_id = Request::getInt('ticket', 0, 'post');
     // Load the old ticket so we can compare for the changelog
     $old = new \Components\Support\Models\Ticket($ticket_id);
     $old->set('tags', $old->tags('string'));
     if (!$old->exists()) {
         $this->errorMessage(500, Lang::txt('Ticket "%s" does not exist.', $ticket_id));
         return;
     }
     // Initiate class and bind posted items to database fields
     $ticket = new \Components\Support\Models\Ticket($ticket_id);
     $ticket->set('status', Request::getInt('status', $ticket->get('status'), 'post'));
     $ticket->set('open', Request::getInt('open', $ticket->get('open'), 'post'));
     $ticket->set('category', Request::getInt('category', $ticket->get('category'), 'post'));
     $ticket->set('severity', Request::getVar('severity', $ticket->get('severity'), 'post'));
     $ticket->set('owner', Request::getVar('owner', $ticket->get('owner'), 'post'));
     $ticket->set('group', Request::getVar('group', $ticket->get('group'), 'post'));
     // If an existing ticket AND closed AND previously open
     if ($ticket_id && !$ticket->get('open') && $ticket->get('open') != $old->get('open')) {
         // Record the closing time
         $ticket->set('closed', Date::toSql());
     }
     // Any tags?
     if ($tags = trim(Request::getVar('tags', '', 'post'))) {
         $ticket->tag($tags, $user->get('uidNumber'));
         $ticket->set('tags', $ticket->tags('string'));
     }
     // Store new content
     if (!$ticket->store()) {
         $this->errorMessage(500, $ticket->getError());
         return;
     }
     // Create a new comment
     $comment = new \Components\Support\Models\Comment();
     $comment->set('ticket', $ticket->get('id'));
     $comment->set('comment', nl2br(Request::getVar('comment', '', 'post', 'none', 2)));
     if ($comment->get('comment')) {
         // If a comment was posted by the ticket submitter to a "waiting user response" ticket, change status.
         if ($ticket->isWaiting() && $user->get('username') == $ticket->get('login')) {
             $ticket->open();
         }
     }
     $comment->set('created', Date::toSql());
     $comment->set('created_by', $user->get('uidNumber'));
     $comment->set('access', Request::getInt('access', 0, 'post'));
     // Compare fields to find out what has changed for this ticket and build a changelog
     $comment->changelog()->diff($old, $ticket);
     $comment->changelog()->cced(Request::getVar('cc', '', 'post'));
     // Store new content
     if (!$comment->store()) {
         $this->errorMessage(500, $comment->getError());
         return;
     }
     if ($ticket->get('owner')) {
         $comment->addTo(array('role' => Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_OWNER'), 'name' => $ticket->owner('name'), 'email' => $ticket->owner('email'), 'id' => $ticket->owner('id')));
     }
     // Add any CCs to the e-mail list
     foreach ($comment->changelog()->get('cc') as $cc) {
         $comment->addTo($cc, Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_CC'));
     }
     // Check if the notify list has eny entries
     if (count($comment->to())) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'helpers' . DS . 'utilities.php';
         $allowEmailResponses = $ticket->config('email_processing');
         if ($allowEmailResponses) {
             try {
                 $encryptor = new \Hubzero\Mail\Token();
             } catch (Exception $e) {
                 $allowEmailResponses = false;
             }
         }
         $subject = Lang::txt('COM_SUPPORT_EMAIL_SUBJECT_TICKET_COMMENT', $ticket->get('id'));
         $from = array('name' => Lang::txt('COM_SUPPORT_EMAIL_FROM', Config::get('sitename')), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U')));
         $message = array();
         // Plain text email
         $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . '/components/com_support/site', 'name' => 'emails', 'layout' => 'comment_plain'));
         $eview->option = 'com_support';
         $eview->controller = 'tickets';
         $eview->comment = $comment;
         $eview->ticket = $ticket;
         $eview->delimiter = $allowEmailResponses ? '~!~!~!~!~!~!~!~!~!~!' : '';
         $message['plaintext'] = $eview->loadTemplate(false);
         $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
         // HTML email
         $eview->setLayout('comment_html');
         $message['multipart'] = $eview->loadTemplate();
         // Send e-mail to admin?
         foreach ($comment->to('ids') as $to) {
             if ($allowEmailResponses) {
                 // The reply-to address contains the token
                 $token = $encryptor->buildEmailToken(1, 1, $to['id'], $ticket->get('id'));
                 $from['replytoemail'] = 'htc-' . $token . strstr(Config::get('mailfrom'), '@');
             }
             // Get the user's email address
             if (!Event::trigger('xmessage.onSendMessage', array('support_reply_submitted', $subject, $message, $from, array($to['id']), 'com_support'))) {
                 $this->setError(Lang::txt('COM_SUPPORT_ERROR_FAILED_TO_MESSAGE', $to['name'] . '(' . $to['role'] . ')'));
             }
             $comment->changelog()->notified($to['role'], $to['name'], $to['email']);
         }
         foreach ($comment->to('emails') as $to) {
             if ($allowEmailResponses) {
                 $token = $encryptor->buildEmailToken(1, 1, -9999, $ticket->get('id'));
                 $email = array($to['email'], 'htc-' . $token . strstr(Config::get('mailfrom'), '@'));
                 // In this case each item in email in an array, 1- To, 2:reply to address
                 \Components\Support\Helpers\Utilities::sendEmail($email[0], $subject, $message, $from, $email[1]);
             } else {
                 // email is just a plain 'ol string
                 \Components\Support\Helpers\Utilities::sendEmail($to['email'], $subject, $message, $from);
             }
             $comment->changelog()->notified($to['role'], $to['name'], $to['email']);
         }
     }
     // Were there any changes?
     if (count($comment->changelog()->get('notifications')) > 0 || count($comment->changelog()->get('cc')) > 0 || count($comment->changelog()->get('changes')) > 0) {
         // Save the data
         if (!$comment->store()) {
             $this->errorMessage(500, $comment->getError());
             return;
         }
     }
     $msg = new stdClass();
     $msg->ticket = $ticket->get('id');
     $msg->comment = $comment->get('id');
     $msg->notified = $comment->changelog()->get('notifications');
     $this->setMessageType(Request::getVar('format', 'json'));
     $this->send($msg, 200, 'OK');
 }
Exemplo n.º 2
0
 /**
  * Send hub message
  *
  * @param      string 	$option
  * @param      object 	$project    Models\Project
  * @param      array 	$addressees
  * @param      string 	$subject
  * @param      string 	$component
  * @param      string 	$layout
  * @param      string 	$message
  * @param      string 	$reviewer
  * @return     void
  */
 public static function sendHUBMessage($option, $project, $addressees = array(), $subject = '', $component = '', $layout = 'admin', $message = '', $reviewer = '')
 {
     if (!$layout || !$subject || !$component || empty($addressees)) {
         return false;
     }
     // Is messaging turned on?
     if ($project->config()->get('messaging') != 1) {
         return false;
     }
     // Set up email config
     $from = array();
     $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_PROJECTS');
     $from['email'] = Config::get('mailfrom');
     // Html email
     $from['multipart'] = md5(date('U'));
     // Message body
     $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'site', 'name' => 'emails', 'layout' => $layout . '_plain'));
     $eview->option = $option;
     $eview->project = $project;
     $eview->message = $message;
     $eview->reviewer = $reviewer;
     $body = array();
     $body['plaintext'] = $eview->loadTemplate(false);
     $body['plaintext'] = str_replace("\n", "\r\n", $body['plaintext']);
     // HTML email
     $eview->setLayout($layout . '_html');
     $body['multipart'] = $eview->loadTemplate();
     $body['multipart'] = str_replace("\n", "\r\n", $body['multipart']);
     // Send HUB message
     Event::trigger('xmessage.onSendMessage', array($component, $subject, $body, $from, $addressees, $option));
 }
Exemplo n.º 3
0
 /**
  * Processes intial reset password request
  *
  * @return  void
  */
 public function resettingTask()
 {
     // Check the request token
     Session::checkToken('post') or exit(Lang::txt('JINVALID_TOKEN'));
     // Grab the incoming username
     if (!($username = trim(Request::getVar('username', false)))) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=reset', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_MISSING_USERNAME'), 'warning');
         return;
     }
     // Make sure it looks like a valid username
     require_once dirname(dirname(__DIR__)) . DS . 'helpers' . DS . 'utility.php';
     // Determine if attempting to log in via username or email address
     if (strpos($username, '@')) {
         $validator = 'validemail';
         $field = 'email';
     } else {
         $validator = 'validlogin';
         $field = 'username';
     }
     if (!\Components\Members\Helpers\Utility::$validator($username)) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=reset', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_INVALID_USERNAME'), 'warning');
         return;
     }
     // Find the user for the given username
     $user = \Hubzero\User\User::whereEquals($field, $username)->rows();
     // Make sure we have at least one and not more than one
     if ($user->count() < 1) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=reset', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_USER_NOT_FOUND'), 'warning');
         return;
     } else {
         if ($user->count() > 1) {
             App::redirect(Route::url('index.php?option=' . $this->_option . '&task=reset', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_MULTIPLE_RESULTS'), 'warning');
             return;
         }
     }
     // Get the user object
     $user = $user->first();
     // Make sure the user isn't blocked
     if ($user->get('block')) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=reset', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_USER_NOT_FOUND'), 'warning');
         return;
     }
     // Make sure the user isn't a super admin
     if ($user->authorise('core.admin')) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=reset', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_USER_IS_SUPER'), 'warning');
         return;
     }
     // Make sure the user has not exceeded the reset limit
     if ($this->hasExceededResetLimit($user)) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=reset', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_EXCEEDED_LIMIT'), 'warning');
         return;
     }
     // Set the confirmation token
     $token = App::hash(\JUserHelper::genRandomPassword());
     $salt = \JUserHelper::getSalt('crypt-md5');
     $hashedToken = md5($token . $salt) . ':' . $salt;
     // Save the token
     $user->tokens()->save(['token' => $hashedToken]);
     // Send an email
     $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'reset_plain'));
     $eview->config = Config::getRoot();
     $eview->baseUrl = rtrim(Request::base(), '/');
     $eview->user = $user;
     $eview->token = $token;
     $eview->return = Route::url('index.php?option=' . $this->_option . '&task=verify');
     $plain = $eview->loadTemplate(false);
     $plain = str_replace("\n", "\r\n", $plain);
     $eview->setLayout('reset_html');
     $html = $eview->loadTemplate();
     $html = str_replace("\n", "\r\n", $html);
     // Build message
     $message = new \Hubzero\Mail\Message();
     $message->setSubject(Lang::txt('COM_MEMBERS_CREDENTIALS_EMAIL_RESET_SUBJECT', Config::get('sitename')))->addFrom(Config::get('mailfrom'), Config::get('fromname'))->addTo($user->get('email'), $user->get('name'))->addHeader('X-Component', $this->_option)->addHeader('X-Component-Object', 'password_reset')->addPart($plain, 'text/plain')->addPart($html, 'text/html');
     // Send mail
     if (!$message->send()) {
         Log::error('Members password reset email failed: ' . Lang::txt('Failed to mail %s', $user->get('email')));
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=remind', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_FIAILED_TO_SEND_MAIL'), 'warning');
         return;
     }
     // Push the user data into the session
     User::setState('com_users.reset.user', $user->get('id'));
     // Everything went well...go to the token verification page
     App::redirect(Route::url('index.php?option=' . $this->_option . '&task=verify', false), Lang::txt('COM_MEMBERS_CREDENTIALS_EMAIL_SENT'), 'passed');
 }
Exemplo n.º 4
0
 /**
  * Save a question and redirect to the main listing when done
  *
  * @return     void
  */
 private function _save()
 {
     // Login required
     if (User::isGuest()) {
         return $this->_browse();
     }
     // Check for request forgeries
     Request::checkToken();
     Lang::load('com_answers');
     // Incoming
     $tags = Request::getVar('tags', '');
     $funds = Request::getInt('funds', 0);
     $reward = Request::getInt('reward', 0);
     // If offering a reward, do some checks
     if ($reward) {
         // Is it an actual number?
         if (!is_numeric($reward)) {
             App::abort(500, Lang::txt('COM_ANSWERS_REWARD_MUST_BE_NUMERIC'));
             return;
         }
         // Are they offering more than they can afford?
         if ($reward > $funds) {
             App::abort(500, Lang::txt('COM_ANSWERS_INSUFFICIENT_FUNDS'));
             return;
         }
     }
     // Initiate class and bind posted items to database fields
     $fields = Request::getVar('question', array(), 'post', 'none', 2);
     $row = new \Components\Answers\Models\Question($fields['id']);
     if (!$row->bind($fields)) {
         $this->setError($row->getError());
         return $this->_new($row);
     }
     if ($reward && $this->banking) {
         $row->set('reward', 1);
     }
     // Ensure the user added a tag
     /*
     if (!$tags)
     {
     	$this->setError(Lang::txt('COM_ANSWERS_QUESTION_MUST_HAVE_TAG'));
     	return $this->_new($row);
     }
     */
     // Store new content
     if (!$row->store(true)) {
         $row->set('tags', $tags);
         $this->setError($row->getError());
         return $this->_new($row);
     }
     // Hold the reward for this question if we're banking
     if ($reward && $this->banking) {
         $BTL = new \Hubzero\Bank\Teller($this->database, User::get('id'));
         $BTL->hold($reward, Lang::txt('COM_ANSWERS_HOLD_REWARD_FOR_BEST_ANSWER'), 'answers', $row->get('id'));
     }
     // Add the tags
     $row->tag($tags);
     // Add the tag to link to the resource
     $tag = $this->model->isTool() ? 'tool:' . $this->model->resource->alias : 'resource:' . $this->model->resource->id;
     $row->addTag($tag, User::get('id'), $this->model->isTool() ? 0 : 1);
     // Get users who need to be notified on every question
     $config = Component::params('com_answers');
     $apu = $config->get('notify_users', '');
     $apu = explode(',', $apu);
     $apu = array_map('trim', $apu);
     $receivers = array();
     // Get tool contributors if question is about a tool
     if ($tags) {
         $tags = explode(',', $tags);
         if (count($tags) > 0) {
             require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'author.php';
             require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'version.php';
             $TA = new \Components\Tools\Tables\Author($this->database);
             $objV = new \Components\Tools\Tables\Version($this->database);
             if ($this->model->isTool()) {
                 $toolname = $this->model->resource->alias;
                 $rev = $objV->getCurrentVersionProperty($toolname, 'revision');
                 $authors = $TA->getToolAuthors('', 0, $toolname, $rev);
                 if (count($authors) > 0) {
                     foreach ($authors as $author) {
                         $receivers[] = $author->uidNumber;
                     }
                 }
             }
         }
     }
     if (!empty($apu)) {
         foreach ($apu as $u) {
             $user = User::getInstance($u);
             if ($user) {
                 $receivers[] = $user->get('id');
             }
         }
     }
     $receivers = array_unique($receivers);
     // Send the message
     if (!empty($receivers)) {
         // Send a message about the new question to authorized users (specified admins or related content authors)
         $from = array('email' => Config::get('mailfrom'), 'name' => Config::get('sitename') . ' ' . Lang::txt('COM_ANSWERS_ANSWERS'), 'multipart' => md5(date('U')));
         // Build the message subject
         $subject = Lang::txt('COM_ANSWERS_ANSWERS') . ', ' . Lang::txt('new question about content you author or manage');
         // Build the message
         $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'site', 'name' => 'emails', 'layout' => 'question_plaintext'));
         $eview->option = 'com_answers';
         $eview->sitename = Config::get('sitename');
         $eview->question = $row;
         $eview->id = $row->get('id', 0);
         $eview->boundary = $from['multipart'];
         $message['plaintext'] = $eview->loadTemplate(false);
         $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
         // HTML message
         $eview->setLayout('question_html');
         $message['multipart'] = $eview->loadTemplate();
         $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
         if (!Event::trigger('xmessage.onSendMessage', array('new_question_admin', $subject, $message, $from, $receivers, 'com_answers'))) {
             $this->setError(Lang::txt('COM_ANSWERS_MESSAGE_FAILED'));
         }
     }
     // Redirect to the question
     App::redirect(Route::url('index.php?option=' . $this->option . '&id=' . $this->model->resource->id . '&active=' . $this->_name));
 }
Exemplo n.º 5
0
 /**
  * Send emails reminding people of their open tickets
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function sendTicketList(\Components\Cron\Models\Job $job)
 {
     $params = $job->get('params');
     $database = App::get('db');
     $sconfig = Component::params('com_support');
     Lang::load('com_support') || Lang::load('com_support', PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'site');
     $sql = "SELECT t.*, o.`name` AS owner_name FROM `#__support_tickets` AS t LEFT JOIN `#__users` AS o ON o.`id`=t.`owner`";
     $where = array();
     $where[] = "t.`type`=0";
     if (is_object($params)) {
         if ($val = $params->get('support_ticketlist_open', 1)) {
             $where[] = "t.`open`=" . $val;
         }
         $statuses = array();
         if (is_numeric($params->get('support_ticketlist_status1'))) {
             $statuses[] = $params->get('support_ticketlist_status1');
         }
         if (is_numeric($params->get('support_ticketlist_status2'))) {
             $statuses[] = $params->get('support_ticketlist_status2');
         }
         if (is_numeric($params->get('support_ticketlist_status3'))) {
             $statuses[] = $params->get('support_ticketlist_status3');
         }
         if (count($statuses)) {
             $where[] = "t.`status` IN (" . implode(',', $statuses) . ")";
         }
         if ($group = $params->get('support_ticketlist_group')) {
             $where[] = "t.`group`=" . $database->quote($group);
         }
         if ($owners = $params->get('support_ticketlist_owners')) {
             $usernames = explode(',', $owners);
             $usernames = array_map('trim', $usernames);
             foreach ($usernames as $k => $username) {
                 $user = User::getInstance($username);
                 $usernames[$k] = $database->quote($user->get('id'));
             }
             $where[] = "t.`owner` IN (" . implode(", ", $usernames) . ")";
         }
         if ($severity = $params->get('support_ticketlist_severity')) {
             if ($severity != 'all') {
                 $severities = explode(',', $severity);
                 $severities = array_map('trim', $severities);
                 foreach ($severities as $k => $severity) {
                     $severities[$k] = $database->quote($severity);
                 }
                 $where[] = "t.`severity` IN (" . implode(", ", $severities) . ")";
             }
         }
         if ($owned = intval($params->get('support_ticketlist_owned', 0))) {
             if ($owned == 1) {
                 $where[] = "(t.`owner` IS NULL OR t.`owner`='0')";
             } else {
                 if ($owned == 2) {
                     $where[] = "(t.`owner` IS NOT NULL AND t.`owner` !='0')";
                 }
             }
         }
         if ($submitters = $params->get('support_ticketlist_submitters')) {
             $usernames = explode(',', $submitters);
             $usernames = array_map('trim', $usernames);
             foreach ($usernames as $k => $username) {
                 $usernames[$k] = $database->quote($username);
             }
             $where[] = "t.`login` IN (" . implode(", ", $usernames) . ")";
         }
         if ($tags = $params->get('support_ticketlist_excludeTags')) {
             $tags = explode(',', $tags);
             $tags = array_map('trim', $tags);
             foreach ($tags as $k => $tag) {
                 $tags[$k] = $database->quote($tag);
             }
             $where[] = "t.`id` NOT IN (\n\t\t\t\t\t\t\tSELECT jto.`objectid` FROM `#__tags_object` AS jto\n\t\t\t\t\t\t\tJOIN `#__tags` AS jt ON jto.`tagid`=jt.`id`\n\t\t\t\t\t\t\tWHERE jto.`tbl`='support'\n\t\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t\tjt.`tag` IN (" . implode(", ", $tags) . ") OR jt.`raw_tag` IN (" . implode(", ", $tags) . ")\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)";
         }
         if ($tags = $params->get('support_ticketlist_includeTags')) {
             $tags = explode(',', $tags);
             $tags = array_map('trim', $tags);
             foreach ($tags as $k => $tag) {
                 $tags[$k] = $database->quote($tag);
             }
             $where[] = "t.`id` IN (\n\t\t\t\t\t\t\tSELECT jto.`objectid` FROM `#__tags_object` AS jto\n\t\t\t\t\t\t\tJOIN `#__tags` AS jt ON jto.`tagid`=jt.`id`\n\t\t\t\t\t\t\tWHERE jto.`tbl`='support'\n\t\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t\tjt.`tag` IN (" . implode(", ", $tags) . ") OR jt.`raw_tag` IN (" . implode(", ", $tags) . ")\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)";
         }
         if ($created = $params->get('support_ticketlist_created', '+week')) {
             $op = '';
             switch ($created) {
                 // Created before (older than)
                 case '-day':
                     $op = '<=';
                     $timestamp = Date::modify('-1 day');
                     break;
                 case '-week':
                     $op = '<=';
                     $timestamp = Date::modify('-1 week');
                     break;
                 case '-2week':
                     $op = '<=';
                     $timestamp = Date::modify('-2 week');
                     break;
                 case '-3week':
                     $op = '<=';
                     $timestamp = Date::modify('-3 week');
                     break;
                 case '-month':
                     $op = '<=';
                     $timestamp = Date::modify('-1 month');
                     break;
                 case '-6month':
                     $op = '<=';
                     $timestamp = Date::modify('-6 month');
                     break;
                 case '-year':
                     $op = '<=';
                     $timestamp = Date::modify('-1 year');
                     break;
                     // Created since (newer than)
                 // Created since (newer than)
                 case '+day':
                     $op = '>=';
                     $timestamp = Date::modify('-1 day');
                     break;
                 case '+week':
                     $op = '>=';
                     $timestamp = Date::modify('-1 week');
                     break;
                 case '+2week':
                     $op = '>=';
                     $timestamp = Date::modify('-2 week');
                     break;
                 case '+3week':
                     $op = '>=';
                     $timestamp = Date::modify('-3 week');
                     break;
                 case '+month':
                     $op = '>=';
                     $timestamp = Date::modify('-1 month');
                     break;
                 case '+6month':
                     $op = '>=';
                     $timestamp = Date::modify('-6 month');
                     break;
                 case '+year':
                     $op = '>=';
                     $timestamp = Date::modify('-1 year');
                     break;
             }
             if ($op) {
                 $where[] = "t.`created`" . $op . $database->quote($timestamp->toSql());
             }
         }
         if ($created = $params->get('support_ticketlist_activity', '--')) {
             $op = '';
             switch ($created) {
                 // Created before (older than)
                 case '-day':
                     $op = '<=';
                     $timestamp = Date::modify('-1 day');
                     break;
                 case '-week':
                     $op = '<=';
                     $timestamp = Date::modify('-1 week');
                     break;
                 case '-2week':
                     $op = '<=';
                     $timestamp = Date::modify('-2 week');
                     break;
                 case '-3week':
                     $op = '<=';
                     $timestamp = Date::modify('-3 week');
                     break;
                 case '-month':
                     $op = '<=';
                     $timestamp = Date::modify('-1 month');
                     break;
                 case '-6month':
                     $op = '<=';
                     $timestamp = Date::modify('-6 month');
                     break;
                 case '-year':
                     $op = '<=';
                     $timestamp = Date::modify('-1 year');
                     break;
                 case 'all':
                 case '--':
                     $op = '';
                     break;
             }
             if ($op) {
                 $where[] = "(SELECT MAX(c.`created`) FROM `#__support_comments` AS c WHERE c.`ticket`=t.`id`) " . $op . $database->quote($timestamp->toSql());
             }
         }
     } else {
         $where[] = "t.`open`=1";
     }
     if (count($where) > 0) {
         $sql .= " WHERE " . implode(" AND ", $where);
     }
     $sql .= " ORDER BY t.`created` ASC LIMIT 0, 500";
     $database->setQuery($sql);
     if (!($results = $database->loadObjectList())) {
         return true;
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'models' . DS . 'ticket.php';
     if ($params->get('support_ticketlist_severity', 'all') != 'all') {
         $severities = explode(',', $params->get('support_ticketlist_severity', 'all'));
     } else {
         include_once PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'helpers' . DS . 'utilities.php';
         $severities = \Components\Support\Helpers\Utilities::getSeverities($sconfig->get('severities'));
     }
     $from = array();
     $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_SUPPORT');
     $from['email'] = Config::get('mailfrom');
     $from['multipart'] = md5(date('U'));
     // Set mail additional args (mail return path - used for bounces)
     if ($host = Request::getVar('HTTP_HOST', '', 'server')) {
         $args = '-f hubmail-bounces@' . $host;
     }
     $subject = Lang::txt('COM_SUPPORT') . ': ' . Lang::txt('COM_SUPPORT_TICKETS');
     $usernames = array();
     if ($users = $params->get('support_ticketlist_notify')) {
         $usernames = explode(',', $users);
         $usernames = array_map('trim', $usernames);
     }
     $mailed = array();
     foreach ($usernames as $owner) {
         if ($owner == '{config.mailfrom}') {
             $name = Config::get('mailfrom');
             $email = Config::get('mailfrom');
         } else {
             if (strstr($owner, '@')) {
                 $name = $owner;
                 $email = $owner;
             } else {
                 // Get the user's account
                 $user = User::getInstance($owner);
                 if (!is_object($user) || !$user->get('id')) {
                     continue;
                 }
                 $name = $user->get('name');
                 $email = $user->get('email');
             }
         }
         // Try to ensure no duplicates
         if (in_array($email, $mailed)) {
             continue;
         }
         $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'site', 'name' => 'emails', 'layout' => 'ticketlist_plain'));
         $eview->option = 'com_support';
         $eview->controller = 'tickets';
         $eview->delimiter = '~!~!~!~!~!~!~!~!~!~!';
         $eview->boundary = $from['multipart'];
         $eview->tickets = $results;
         $eview->config = $sconfig;
         $plain = $eview->loadTemplate(false);
         $plain = str_replace("\n", "\r\n", $plain);
         // HTML
         $eview->setLayout('ticketlist_html');
         $html = $eview->loadTemplate();
         $html = str_replace("\n", "\r\n", $html);
         // Build message
         $message = new \Hubzero\Mail\Message();
         $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($email, $name)->addHeader('X-Component', 'com_support')->addHeader('X-Component-Object', 'support_ticket_list');
         $message->addPart($plain, 'text/plain');
         $message->addPart($html, 'text/html');
         // Send mail
         if (!$message->send()) {
             //$this->setError(Lang::txt('Failed to mail %s', $fullEmailAddress));
             Log::error('CRON email failed: ' . Lang::txt('Failed to mail %s', $email));
         }
         $mailed[] = $email;
     }
     return true;
 }
Exemplo n.º 6
0
 /**
  * Email Announcement
  *
  * @param   object  $announcement
  * @param   object  $group
  * @return  boolean
  */
 public static function send($announcement, $group)
 {
     // get all group members
     $groupMembers = array();
     foreach ($group->get('members') as $member) {
         if ($profile = User::getInstance($member)) {
             // Skip invalid emails
             if (preg_match('/^-[0-9]+@invalid$/', $profile->get('email'))) {
                 continue;
             }
             $groupMembers[$profile->get('email')] = $profile->get('name');
         }
     }
     if (!count($groupMembers)) {
         return true;
     }
     // create view object
     $eview = new \Hubzero\Mail\View(array('base_path' => __DIR__, 'name' => 'email', 'layout' => 'announcement_plain'));
     // plain text
     $eview->set('announcement', $announcement);
     $plain = $eview->loadTemplate(false);
     $plain = str_replace("\n", "\r\n", $plain);
     // HTML
     $eview->setLayout('announcement_html');
     $html = $eview->loadTemplate();
     $html = str_replace("\n", "\r\n", $html);
     // set from address
     $from = array('name' => Config::get('sitename') . ' Groups', 'email' => Config::get('mailfrom'));
     // define subject
     $subject = $group->get('description') . ' Group Announcement';
     foreach ($groupMembers as $email => $name) {
         // create message object
         $message = new \Hubzero\Mail\Message();
         // set message details and send
         $message->setSubject($subject)->addReplyTo($from['email'], $from['name'])->addFrom($from['email'], $from['name'])->setTo($email, $name)->addPart($plain, 'text/plain')->addPart($html, 'text/html')->send();
     }
     // all good
     return true;
 }
Exemplo n.º 7
0
 /**
  * Close tickets in a specified state
  *
  * @return  boolean
  */
 public function onAfterRepositoryUpdate()
 {
     $database = App::get('db');
     $sconfig = Component::params('com_support');
     $open = 0;
     $status = $this->params->get('support_ticket_closed', 0);
     $status = $status == '-1' ? 0 : $status;
     if ($status) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'tables' . DS . 'status.php';
         $st = new \Components\Support\Tables\Status($database);
         $st->load($status);
         $open = $st->open;
     }
     $slc = "SELECT id, login, email, name FROM `#__support_tickets` AS t";
     $upd = "UPDATE `#__support_tickets` AS t SET t.`open`=" . $database->quote($open) . ", t.`status`=" . $database->quote($status) . ", t.`closed`=" . $database->quote(Date::toSql());
     $where = array();
     $where[] = "t.`type`=0";
     $where[] = "t.`open`=1";
     // Gather a list of statuses
     $statuses = array();
     if (is_numeric($this->params->get('support_ticket_state1'))) {
         $statuses[] = $this->params->get('support_ticket_state1');
     }
     if (is_numeric($this->params->get('support_ticket_state2'))) {
         $statuses[] = $this->params->get('support_ticket_state2');
     }
     if (is_numeric($this->params->get('support_ticket_state3'))) {
         $statuses[] = $this->params->get('support_ticket_state3');
     }
     if (count($statuses)) {
         $where[] = "t.`status` IN (" . implode(',', $statuses) . ")";
     }
     // Only tickets for a specified group?
     if ($group = $this->params->get('support_ticket_group')) {
         $where[] = "t.`group`=" . $database->quote($group);
     }
     // Only tickets for specified owners?
     if ($owners = $this->params->get('support_ticket_owners')) {
         $usernames = explode(',', $owners);
         $usernames = array_map('trim', $usernames);
         foreach ($usernames as $k => $username) {
             $user = User::getInstance($username);
             $usernames[$k] = $database->quote($user->get('id'));
         }
         $where[] = "t.`owner` IN (" . implode(", ", $usernames) . ")";
     }
     // Tickets with a specified severity?
     if ($severity = $this->params->get('support_ticket_severity')) {
         if ($severity != 'all') {
             $severities = explode(',', $severity);
             $severities = array_map('trim', $severities);
             foreach ($severities as $k => $severity) {
                 $severities[$k] = $database->quote($severity);
             }
             $where[] = "t.`severity` IN (" . implode(", ", $severities) . ")";
         }
     }
     // Only tickets by specified submitters
     if ($submitters = $this->params->get('support_ticket_submitters')) {
         $usernames = explode(',', $submitters);
         $usernames = array_map('trim', $usernames);
         foreach ($usernames as $k => $username) {
             $usernames[$k] = $database->quote($username);
         }
         $where[] = "t.`login` IN (" . implode(", ", $usernames) . ")";
     }
     // Tickets WITHOUT specified tags
     if ($tags = $this->params->get('support_ticket_excludeTags', '')) {
         $tags = explode(',', $tags);
         $tags = array_map('trim', $tags);
         foreach ($tags as $k => $tag) {
             $tags[$k] = $database->quote($tag);
         }
         $where[] = "t.`id` NOT IN (\n\t\t\t\t\t\tSELECT jto.`objectid` FROM `#__tags_object` AS jto\n\t\t\t\t\t\tJOIN `#__tags` AS jt ON jto.`tagid`=jt.`id`\n\t\t\t\t\t\tWHERE jto.`tbl`='support'\n\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\tjt.`tag` IN (" . implode(", ", $tags) . ") OR jt.`raw_tag` IN (" . implode(", ", $tags) . ")\n\t\t\t\t\t\t)\n\t\t\t\t\t)";
     }
     // Tickets WITH specified tags
     if ($tags = $this->params->get('support_ticket_includeTags', '')) {
         $tags = explode(',', $tags);
         $tags = array_map('trim', $tags);
         foreach ($tags as $k => $tag) {
             $tags[$k] = $database->quote($tag);
         }
         $where[] = "t.`id` IN (\n\t\t\t\t\t\tSELECT jto.`objectid` FROM `#__tags_object` AS jto\n\t\t\t\t\t\tJOIN `#__tags` AS jt ON jto.`tagid`=jt.`id`\n\t\t\t\t\t\tWHERE jto.`tbl`='support'\n\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\tjt.`tag` IN (" . implode(", ", $tags) . ") OR jt.`raw_tag` IN (" . implode(", ", $tags) . ")\n\t\t\t\t\t\t)\n\t\t\t\t\t)";
     }
     // Last activity within specified time range
     if ($created = $this->params->get('support_ticket_activity')) {
         $op = '';
         switch ($created) {
             // Created before (older than)
             case '-day':
                 $op = '<=';
                 $timestamp = Date::modify('-1 day');
                 break;
             case '-week':
                 $op = '<=';
                 $timestamp = Date::modify('-1 week');
                 break;
             case '-2week':
                 $op = '<=';
                 $timestamp = Date::modify('-2 week');
                 break;
             case '-3week':
                 $op = '<=';
                 $timestamp = Date::modify('-3 week');
                 break;
             case '-month':
                 $op = '<=';
                 $timestamp = Date::modify('-1 month');
                 break;
             case '-6month':
                 $op = '<=';
                 $timestamp = Date::modify('-6 month');
                 break;
             case '-year':
                 $op = '<=';
                 $timestamp = Date::modify('-1 year');
                 break;
             case '--':
                 $op = '';
                 break;
         }
         if ($op) {
             $where[] = "(SELECT MAX(c.`created`) FROM `#__support_comments` AS c WHERE c.`ticket`=t.`id`) " . $op . $database->quote($timestamp->toSql());
         }
     }
     if (count($where) > 0) {
         $slc .= " WHERE " . implode(" AND ", $where);
         $upd .= " WHERE " . implode(" AND ", $where);
     }
     $message_id = $this->params->get('support_ticket_message');
     // Get a list of tickets before we update them
     $tickets = array();
     if ($message_id) {
         $database->setQuery($slc);
         $tickets = $database->loadObjectList();
     }
     // Update the tickets
     $database->setQuery($upd);
     if (!$database->query()) {
         Log::error('Ticket query failed: ' . $database->getErrorMsg());
         return false;
     }
     // If we're sending a message...
     if ($message_id && !empty($tickets)) {
         Lang::load('com_support') || Lang::load('com_support', PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'site');
         include_once PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'tables' . DS . 'message.php';
         include_once PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'models' . DS . 'ticket.php';
         $message = new \Components\Support\Tables\Message($database);
         $message->load($message_id);
         // Make sure we have a message to send
         if ($message->message) {
             $from = array('name' => Config::get('sitename') . ' ' . Lang::txt('COM_SUPPORT'), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U')));
             // Set mail additional args (mail return path - used for bounces)
             if ($host = Request::getVar('HTTP_HOST', '', 'server')) {
                 $args = '-f hubmail-bounces@' . $host;
             }
             $subject = Lang::txt('COM_SUPPORT') . ': ' . Lang::txt('COM_SUPPORT_TICKETS');
             $mailed = array();
             $message->message = str_replace('{sitename}', Config::get('sitename'), $message->message);
             $message->message = str_replace('{siteemail}', Config::get('mailfrom'), $message->message);
             $comment = new \Components\Support\Models\Comment();
             $comment->set('created', Date::toSql());
             $comment->set('created_by', 0);
             $comment->set('access', 0);
             $comment->set('comment', $message->message);
             foreach ($tickets as $submitter) {
                 $name = null;
                 $email = null;
                 if ($submitter->login) {
                     // Get the user's account
                     $user = User::getInstance($submitter->login);
                     if (is_object($user) && $user->get('id')) {
                         $name = $user->get('name');
                         $email = $user->get('email');
                     }
                 }
                 $email = $email ?: $submitter->email;
                 $name = $name ?: $submitter->name;
                 $name = $name ?: $email;
                 if (!$email) {
                     continue;
                 }
                 // Try to ensure no duplicates
                 if (in_array($email, $mailed)) {
                     continue;
                 }
                 $old = new \Components\Support\Models\Ticket($submitter->id);
                 $old->set('open', 1);
                 $row = clone $old;
                 $row->set('open', 0);
                 $comment->set('comment', str_replace('#XXX', '#' . $row->get('id'), $comment->get('comment')));
                 $comment->set('comment', str_replace('{ticket#}', $row->get('id'), $comment->get('comment')));
                 // Compare fields to find out what has changed for this ticket and build a changelog
                 $comment->changelog()->diff($old, $row);
                 $comment->set('ticket', $row->get('id'));
                 $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'site', 'name' => 'emails', 'layout' => 'comment_plain'));
                 $eview->option = 'com_support';
                 $eview->controller = 'tickets';
                 $eview->delimiter = '~!~!~!~!~!~!~!~!~!~!';
                 $eview->boundary = $from['multipart'];
                 $eview->comment = $comment;
                 $eview->config = $sconfig;
                 $eview->ticket = $row;
                 $plain = $eview->loadTemplate(false);
                 $plain = str_replace("\n", "\r\n", $plain);
                 // HTML
                 $eview->setLayout('comment_html');
                 $html = $eview->loadTemplate();
                 $html = str_replace("\n", "\r\n", $html);
                 // Build message
                 $message = new \Hubzero\Mail\Message();
                 $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($email, $name)->addHeader('X-Component', 'com_support')->addHeader('X-Component-Object', 'support_ticket_comment');
                 $message->addPart($plain, 'text/plain');
                 $message->addPart($html, 'text/html');
                 // Send mail
                 if (!$message->send()) {
                     Log::error('Ticket email failed: ' . Lang::txt('Failed to mail %s', $email));
                 }
                 $mailed[] = $email;
             }
         }
     }
     return true;
 }
Exemplo n.º 8
0
 /**
  * Final submission
  *
  * @return  void
  */
 public function submitTask()
 {
     // Incoming
     $id = Request::getInt('id', 0);
     // Ensure we have an ID to work with
     if (!$id) {
         App::abort(404, Lang::txt('COM_CONTRIBUTE_NO_ID'));
     }
     // Load resource info
     $resource = Resource::oneOrFail($id);
     // Set a flag for if the resource was already published or not
     $published = 0;
     if ($resource->get('published') != 2) {
         $published = 1;
     }
     // Check if a newly submitted resource was authorized to be published
     $authorized = Request::getInt('authorization', 0);
     if (!$authorized && !$published) {
         $this->setError(Lang::txt('COM_CONTRIBUTE_CONTRIBUTION_NOT_AUTHORIZED'));
         $this->_checkProgress($id);
         return $this->step_review();
     }
     // Allow for any other validation
     $results = Event::trigger('resources.onResourceBeforeSubmit', array($resource));
     foreach ($results as $result) {
         if ($result) {
             $this->setError($result);
             $this->_checkProgress($id);
             return $this->step_review();
         }
     }
     // Is this a newly submitted resource?
     if (!$published) {
         $activity = 'submitted';
         // 0 = unpublished, 1 = published, 2 = composing, 3 = pending (submitted), 4 = deleted
         // Are submissions auto-approved?
         if ($this->config->get('autoapprove') == 1) {
             //checks if autoapproved content has children (configurable in options on backend)
             if ($this->config->get('autoapprove_content_check') == 1) {
                 if ($resource->children()->total() < 1) {
                     $this->setError(Lang::txt('COM_CONTRIBUTE_NO_CONTENT'));
                     return $this->step_review();
                 }
             }
             // Set status to published
             $resource->set('published', 1);
             $resource->set('publish_up', Date::toSql());
             $activity = 'published';
         } else {
             $apu = $this->config->get('autoapproved_users');
             $apu = explode(',', $apu);
             $apu = array_map('trim', $apu);
             if (in_array(User::get('username'), $apu)) {
                 // Set status to published
                 $resource->set('published', 1);
                 $resource->set('publish_up', Date::toSql());
             } else {
                 // Set status to pending review (submitted)
                 $resource->set('published', 3);
             }
         }
         // Get the resource's contributors
         $authors = $resource->authors()->rows();
         if ($authors->count() <= 0) {
             $this->setError(Lang::txt('COM_CONTRIBUTE_CONTRIBUTION_HAS_NO_AUTHORS'));
             $this->_checkProgress($id);
             return $this->step_review();
         }
         // Get any set emails that should be notified of ticket submission
         $defs = explode(',', $this->config->get('email_when_submitted', '{config.mailfrom}'));
         if (!empty($defs)) {
             $message = new \Hubzero\Mail\Message();
             $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_RESOURCES_EMAIL_SUBJECT_NEW_SUBMISSION', $resource->id));
             $message->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_option)));
             // Plain text email
             $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'submitted_plain'));
             $eview->option = $this->_option;
             $eview->controller = $this->_controller;
             $eview->resource = $resource;
             $eview->delimiter = '';
             $plain = $eview->loadTemplate(false);
             $plain = str_replace("\n", "\r\n", $plain);
             $message->addPart($plain, 'text/plain');
             // HTML email
             $eview->setLayout('submitted_html');
             $html = $eview->loadTemplate();
             $html = str_replace("\n", "\r\n", $html);
             $message->addPart($html, 'text/html');
             // Loop through the addresses
             foreach ($defs as $def) {
                 $def = trim($def);
                 // Check if the address should come from config
                 if ($def == '{config.mailfrom}') {
                     $def = Config::get('mailfrom');
                 }
                 // Check for a valid address
                 if (\Hubzero\Utility\Validate::email($def)) {
                     // Send e-mail
                     $message->setTo(array($def));
                     $message->send();
                 }
             }
         }
         // Log activity
         $recipients = array(['resource', $resource->get('id')], ['user', $resource->get('created_by')]);
         foreach ($authors as $author) {
             if ($author->get('authorid') > 0) {
                 $recipients[] = ['user', $author->get('authorid')];
             }
         }
         Event::trigger('system.logActivity', ['activity' => ['action' => $activity, 'scope' => 'resource', 'scope_id' => $resource->get('title'), 'description' => Lang::txt('COM_RESOURCES_ACTIVITY_ENTRY_' . strtoupper($activity), '<a href="' . Route::url($resource->link()) . '">' . $resource->get('title') . '</a>'), 'details' => array('title' => $resource->get('title'), 'url' => Route::url($resource->link()))], 'recipients' => $recipients]);
     }
     // Is this resource licensed under Creative Commons?
     if ($this->config->get('cc_license')) {
         $license = Request::getVar('license', '');
         if ($license == 'custom') {
             $license .= $resource->get('id');
             $licenseText = Request::getVar('license-text', '');
             if ($licenseText == '[ENTER LICENSE HERE]') {
                 $this->setError(Lang::txt('Please enter a license.'));
                 $this->_checkProgress($id);
                 return $this->step_review();
             }
             $rl = License::oneOrNew($license);
             $rl->set('name', $license);
             $rl->set('text', $licenseText);
             $rl->set('info', $resource->get('id'));
             $rl->save();
         }
         // set license
         $params = new \Hubzero\Config\Registry($resource->get('params'));
         $params->set('license', $license);
         $resource->set('params', $params->toString());
     }
     // Save the resource
     $resource->save();
     Event::trigger('resources.onResourceAfterSubmit', array($resource));
     // If a previously published resource, redirect to the resource page
     if ($published == 1) {
         App::redirect(Route::url($resource->link()));
         return;
     }
     // Output HTML
     $this->setView($this->_controller, 'thanks');
     $this->view->set('title', $this->_title)->set('config', $this->config)->set('resource', $resource)->setErrors($this->getErrors())->display();
 }
Exemplo n.º 9
0
 /**
  * Updates a ticket with any changes and adds a new comment
  *
  * @return     void
  */
 public function updateTask()
 {
     // Make sure we are still logged in
     if (User::isGuest()) {
         $return = base64_encode(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=' . $this->_task, false, true));
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . $return, false));
         return;
     }
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $id = Request::getInt('id', 0, 'post');
     if (!$id) {
         throw new Exception(Lang::txt('COM_SUPPORT_ERROR_MISSING_TICKET_ID'), 500);
     }
     $comment = Request::getVar('comment', '', 'post', 'none', 2);
     $incoming = Request::getVar('ticket', array(), 'post');
     $incoming = array_map('trim', $incoming);
     if (isset($incoming['target_date'])) {
         if (!$incoming['target_date']) {
             $incoming['target_date'] = '0000-00-00 00:00:00';
         } else {
             $incoming['target_date'] = Date::of($incoming['target_date'], Config::get('offset'))->toSql();
         }
     }
     // Load the old ticket so we can compare for the changelog
     $old = new Ticket($id);
     $old->set('tags', $old->tags('string'));
     // Initiate class and bind posted items to database fields
     $row = new Ticket($id);
     if (!$row->bind($incoming)) {
         throw new Exception($row->getError(), 500);
     }
     $rowc = new Comment();
     $rowc->set('ticket', $id);
     // Check if changes were made inbetween the time the comment was started and posted
     $started = Request::getVar('started', Date::toSql(), 'post');
     $lastcomment = $row->comments('list', array('sort' => 'created', 'sort_Dir' => 'DESC', 'limit' => 1, 'start' => 0, 'ticket' => $id))->first();
     if ($lastcomment && $lastcomment->created() > $started) {
         $rowc->set('comment', $comment);
         $this->setError(Lang::txt('Changes were made to this ticket in the time since you began commenting/making changes. Please review your changes before submitting.'));
         return $this->ticketTask($rowc);
     }
     // Update ticket status if necessary
     if ($id && isset($incoming['status']) && $incoming['status'] == 0) {
         $row->set('open', 0);
         $row->set('resolved', Lang::txt('COM_SUPPORT_COMMENT_OPT_CLOSED'));
     }
     $row->set('open', $row->status('open'));
     // Check content
     if (!$row->check()) {
         throw new Exception($row->getError(), 500);
     }
     // If an existing ticket AND closed AND previously open
     if ($id && !$row->get('open') && $row->get('open') != $old->get('open')) {
         // Record the closing time
         $row->set('closed', Date::toSql());
     }
     // Incoming comment
     if ($comment) {
         // If a comment was posted by the ticket submitter to a "waiting user response" ticket, change status.
         if ($row->isWaiting() && User::get('username') == $row->get('login')) {
             $row->open();
         }
     }
     // Store new content
     if (!$row->store()) {
         throw new Exception($row->getError(), 500);
     }
     // Save the tags
     $row->tag(Request::getVar('tags', '', 'post'), User::get('id'), 1);
     $row->set('tags', $row->tags('string'));
     // Create a new support comment object and populate it
     $access = Request::getInt('access', 0);
     $rowc->set('ticket', $id);
     $rowc->set('comment', nl2br($comment));
     $rowc->set('created', Date::toSql());
     $rowc->set('created_by', User::get('id'));
     $rowc->set('access', $access);
     // Compare fields to find out what has changed for this ticket and build a changelog
     $rowc->changelog()->diff($old, $row);
     $rowc->changelog()->cced(Request::getVar('cc', ''));
     // Save the data
     if (!$rowc->store()) {
         throw new Exception($rowc->getError(), 500);
     }
     Event::trigger('support.onTicketUpdate', array($row, $rowc));
     $attach = new Tables\Attachment($this->database);
     if ($tmp = Request::getInt('tmp_dir')) {
         $attach->updateCommentId($tmp, $rowc->get('id'));
     }
     $attachment = $this->uploadTask($row->get('id'), $rowc->get('id'));
     // Only do the following if a comment was posted
     // otherwise, we're only recording a changelog
     if ($rowc->get('comment') || $row->get('owner') != $old->get('owner') || $row->get('group') != $old->get('group') || $rowc->attachments()->total() > 0) {
         // Send e-mail to ticket submitter?
         if (Request::getInt('email_submitter', 0) == 1) {
             // Is the comment private? If so, we do NOT send e-mail to the
             // submitter regardless of the above setting
             if (!$rowc->isPrivate()) {
                 $rowc->addTo(array('role' => Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_SUBMITTER'), 'name' => $row->submitter('name'), 'email' => $row->submitter('email'), 'id' => $row->submitter('id')));
             }
         }
         // Send e-mail to ticket owner?
         if (Request::getInt('email_owner', 0) == 1) {
             if ($old->get('owner') && $row->get('owner') != $old->get('owner')) {
                 $rowc->addTo(array('role' => Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_PRIOR_OWNER'), 'name' => $old->owner('name'), 'email' => $old->owner('email'), 'id' => $old->owner('id')));
             }
             if ($row->get('owner')) {
                 $rowc->addTo(array('role' => Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_OWNER'), 'name' => $row->owner('name'), 'email' => $row->owner('email'), 'id' => $row->owner('id')));
             } elseif ($row->get('group')) {
                 $group = \Hubzero\User\Group::getInstance($row->get('group'));
                 if ($group) {
                     foreach ($group->get('managers') as $manager) {
                         $manager = User::getInstance($manager);
                         if (!$manager || !$manager->get('id')) {
                             continue;
                         }
                         $rowc->addTo(array('role' => Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_GROUPMANAGER'), 'name' => $manager->get('name'), 'email' => $manager->get('email'), 'id' => $manager->get('id')));
                     }
                 }
             }
         }
         // Add any CCs to the e-mail list
         foreach ($rowc->changelog()->get('cc') as $cc) {
             $rowc->addTo($cc, Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_CC'));
         }
         // Message people watching this ticket,
         // but ONLY if the comment was NOT marked private
         foreach ($row->watchers() as $watcher) {
             $this->acl->setUser($watcher->user_id);
             if (!$rowc->isPrivate() || $rowc->isPrivate() && $this->acl->check('read', 'private_comments')) {
                 $rowc->addTo($watcher->user_id, 'watcher');
             }
         }
         $this->acl->setUser(User::get('id'));
         $recipients = array(['support.tickets', 1]);
         if (count($rowc->to())) {
             $this->config->set('email_terse', Request::getInt('email_terse', 0));
             $allowEmailResponses = $this->config->get('email_processing');
             if ($this->config->get('email_terse')) {
                 $allowEmailResponses = false;
             }
             if ($allowEmailResponses) {
                 try {
                     $encryptor = new \Hubzero\Mail\Token();
                 } catch (Exception $e) {
                     $allowEmailResponses = false;
                 }
             }
             // Build e-mail components
             $subject = Lang::txt('COM_SUPPORT_EMAIL_SUBJECT_TICKET_COMMENT', $row->get('id'));
             $from = array('name' => Lang::txt('COM_SUPPORT_EMAIL_FROM', Config::get('sitename')), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U')));
             $message = array();
             // Plain text email
             $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'comment_plain'));
             $eview->option = $this->_option;
             $eview->controller = $this->_controller;
             $eview->comment = $rowc;
             $eview->ticket = $row;
             $eview->config = $this->config;
             $eview->delimiter = $allowEmailResponses ? '~!~!~!~!~!~!~!~!~!~!' : '';
             $message['plaintext'] = $eview->loadTemplate(false);
             $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
             // HTML email
             $eview->setLayout('comment_html');
             $message['multipart'] = $eview->loadTemplate();
             $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
             $message['attachments'] = array();
             if (!$this->config->get('email_terse')) {
                 foreach ($rowc->attachments() as $attachment) {
                     if ($attachment->size() < 2097152) {
                         $message['attachments'][] = $attachment->link('filepath');
                     }
                 }
             }
             foreach ($rowc->to('ids') as $to) {
                 $recipients[] = ['user', $to['id']];
                 if ($allowEmailResponses) {
                     // The reply-to address contains the token
                     $token = $encryptor->buildEmailToken(1, 1, $to['id'], $id);
                     $from['replytoemail'] = 'htc-' . $token . strstr(Config::get('mailfrom'), '@');
                 }
                 // Get the user's email address
                 if (!Event::trigger('xmessage.onSendMessage', array('support_reply_submitted', $subject, $message, $from, array($to['id']), $this->_option))) {
                     $this->setError(Lang::txt('COM_SUPPORT_ERROR_FAILED_TO_MESSAGE', $to['name'] . '(' . $to['role'] . ')'));
                 }
                 // Watching should be anonymous
                 if ($to['role'] == 'watcher') {
                     continue;
                 }
                 $rowc->changelog()->notified($to['role'], $to['name'], $to['email']);
             }
             foreach ($rowc->to('emails') as $to) {
                 if ($allowEmailResponses) {
                     $token = $encryptor->buildEmailToken(1, 1, -9999, $id);
                     $email = array($to['email'], 'htc-' . $token . strstr(Config::get('mailfrom'), '@'));
                     // In this case each item in email in an array, 1- To, 2:reply to address
                     Utilities::sendEmail($email[0], $subject, $message, $from, $email[1]);
                 } else {
                     // email is just a plain 'ol string
                     Utilities::sendEmail($to['email'], $subject, $message, $from);
                 }
                 // Watching should be anonymous
                 if ($to['role'] == 'watcher') {
                     continue;
                 }
                 $rowc->changelog()->notified($to['role'], $to['name'], $to['email']);
             }
         } else {
             // Force entry to private if no comment or attachment was made
             if (!$rowc->get('comment') && $rowc->attachments()->total() <= 0) {
                 $rowc->set('access', 1);
             }
         }
         // Were there any changes?
         if (count($rowc->changelog()->get('notifications')) > 0 || $access != $rowc->get('access')) {
             if (!$rowc->store()) {
                 throw new Exception($rowc->getError(), 500);
             }
         }
         $desc = Lang::txt('COM_SUPPORT_ACTIVITY_TICKET_UPDATED', '<a href="' . Route::url($row->link()) . '">#' . $row->get('id') . ' - ' . $row->get('summary') . '</a>');
         if ($rowc->get('comment')) {
             $desc = Lang::txt('COM_SUPPORT_ACTIVITY_COMMENT_CREATED', $rowc->get('id'), '<a href="' . Route::url($row->link()) . '">#' . $row->get('id') . ' - ' . $row->get('summary') . '</a>');
         }
         Event::trigger('system.logActivity', ['activity' => ['action' => 'created', 'scope' => 'support.ticket.comment', 'scope_id' => $rowc->get('id'), 'description' => $desc, 'details' => array('id' => $row->get('id'), 'summary' => $row->get('summary'), 'url' => Route::url($row->link()), 'comment' => $rowc->get('id'))], 'recipients' => $recipients]);
     }
     // Display the ticket with changes, new comment
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=ticket&id=' . $id), $this->getError() ? $this->getError() : null, $this->getError() ? 'error' : null);
 }
Exemplo n.º 10
0
 /**
  * Save an abuse report and displays a "Thank you" message
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $this->view->cat = Request::getVar('category', '');
     $this->view->refid = Request::getInt('referenceid', 0);
     $this->view->returnlink = Request::getVar('link', '');
     $no_html = Request::getInt('no_html', 0);
     // Trim and addslashes all posted items
     $incoming = array_map('trim', $_POST);
     // Initiate class and bind posted items to database fields
     $row = new ReportAbuse($this->database);
     if (!$row->bind($incoming)) {
         if ($no_html) {
             echo json_encode(array('success' => false, 'message' => $row->getError(), 'id' => $this->view->refid, 'category' => $this->view->cat));
             return;
         }
         Request::setVar('id', $this->view->refid);
         $this->setError($row->getError());
         $this->displayTask();
         return;
     }
     $row->report = Sanitize::clean($row->report);
     $row->report = nl2br($row->report);
     $row->created_by = User::get('id');
     $row->created = Date::toSql();
     $row->state = 0;
     // Check content
     if (!$row->check()) {
         if ($no_html) {
             echo json_encode(array('success' => false, 'message' => $row->getError(), 'id' => $this->view->refid, 'category' => $this->view->cat));
             return;
         }
         Request::setVar('id', $this->view->refid);
         $this->setError($row->getError());
         $this->displayTask();
         return;
     }
     // Store new content
     if (!$row->store()) {
         if ($no_html) {
             echo json_encode(array('success' => false, 'message' => $row->getError(), 'id' => $this->view->refid, 'category' => $this->view->cat));
             return;
         }
         Request::setVar('id', $this->view->refid);
         $this->setError($row->getError());
         $this->displayTask();
         return;
     }
     // Get the search result totals
     $results = Event::trigger('support.onReportItem', array($this->view->refid, $this->view->cat));
     // Send notification email
     if ($this->config->get('abuse_notify', 1)) {
         $reported = new \stdClass();
         $reported->author = 0;
         // Get the search result totals
         $results = Event::trigger('support.getReportedItem', array($this->view->refid, $this->view->cat, 0));
         // Check the results returned for a reported item
         if ($results) {
             foreach ($results as $result) {
                 if ($result) {
                     $reported = $result[0];
                     break;
                 }
             }
         }
         // Get any set emails that should be notified of ticket submission
         $defs = str_replace("\r", '', $this->config->get('abuse_emails', '{config.mailfrom}'));
         $defs = str_replace('\\n', "\n", $defs);
         $defs = explode("\n", $defs);
         $defs = array_map('trim', $defs);
         $message = new \Hubzero\Mail\Message();
         $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_SUPPORT_ABUSE_REPORT'))->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_option)))->addHeader('X-Component', 'com_support')->addHeader('X-Component-Object', 'abuse_item_report');
         // Plain text email
         $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'abuse_plain'));
         $eview->option = $this->_option;
         $eview->controller = $this->_controller;
         $eview->report = $row;
         $eview->reported = $reported;
         $eview->author = null;
         $plain = $eview->loadTemplate(false);
         $plain = str_replace("\n", "\r\n", $plain);
         $message->addPart($plain, 'text/plain');
         // HTML email
         $eview->setLayout('abuse_html');
         $html = $eview->loadTemplate();
         $html = str_replace("\n", "\r\n", $html);
         $message->addPart($html, 'text/html');
         // Loop through the addresses
         foreach ($defs as $def) {
             // Check if the address should come from Joomla config
             if ($def == '{config.mailfrom}') {
                 $def = Config::get('mailfrom');
             }
             // Check for a valid address
             if (Validate::email($def)) {
                 $message->addTo($def);
             }
         }
         // Send e-mail
         if (!$message->send()) {
             $this->setError(Lang::txt('Uh-oh'));
         }
     }
     if ($no_html) {
         echo json_encode(array('success' => true, 'report_id' => $row->id, 'message' => Lang::txt('COM_SUPPORT_REPORT_NUMBER_REFERENCE', $row->id), 'id' => $this->view->refid, 'category' => $this->view->cat));
         return;
     }
     // Set the page title
     $this->_buildTitle();
     $this->view->title = $this->_title;
     $this->view->report = $row;
     // Set the pathway
     $this->_buildPathway();
     // Output HTML
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }
Exemplo n.º 11
0
 /**
  * Sends a message to authors (or creator) of a publication
  *
  * @param   string  $subject
  * @param   string  $subject
  * @param   array   $authors
  * @param   string  $subject
  * @return  void
  */
 private function _emailContributors($subject = '', $message = '', $authors = array(), $action = 'publish')
 {
     if (!$this->model->exists() || !$this->model->project()->exists()) {
         return false;
     }
     // Get pub authors' ids
     if (empty($authors)) {
         $authors = $this->model->table('Author')->getAuthors($this->model->version->id, 1, 1, 1);
     }
     // No authors – send to publication creator
     if (count($authors) == 0) {
         $authors = array($this->model->version->created_by);
     }
     // Make sure there are no duplicates
     $authors = array_unique($authors);
     if ($authors && count($authors) > 0) {
         // Email all the contributors
         $from = array();
         $from['email'] = Config::get('mailfrom');
         $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_PUBLICATIONS');
         $subject = $subject ? $subject : Lang::txt('COM_PUBLICATIONS_STATUS_UPDATE');
         // Get message body
         $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'admin_plain'));
         $eview->option = $this->_option;
         $eview->subject = $subject;
         $eview->action = $action;
         $eview->model = $this->model;
         $eview->message = $message;
         $eview->project = $this->model->project();
         $body = array();
         $body['plaintext'] = $eview->loadTemplate(false);
         $body['plaintext'] = str_replace("\n", "\r\n", $body['plaintext']);
         // HTML email
         $eview->setLayout('admin_html');
         $body['multipart'] = $eview->loadTemplate();
         $body['multipart'] = str_replace("\n", "\r\n", $body['multipart']);
         // Send message
         if (!Event::trigger('xmessage.onSendMessage', array('publication_status_changed', $subject, $body, $from, $authors, $this->_option))) {
             $this->setError(Lang::txt('COM_PUBLICATIONS_ERROR_FAILED_MESSAGE_AUTHORS'));
         }
     }
 }
Exemplo n.º 12
0
 /**
  * Finalize the purchase process
  *
  * @return     void
  */
 public function finalizeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Set page title
     $this->_buildTitle();
     // Set the pathway
     $this->_buildPathway();
     // Check authorization
     if (User::isGuest()) {
         $this->loginTask();
         return;
     }
     $now = \Date::toSql();
     // Get cart object
     $item = new Cart($this->database);
     // Calculate total
     $cost = $item->getCartItems(User::get('id'), 'cost');
     // Check available user funds
     $BTL = new Teller(User::get('id'));
     $balance = $BTL->summary();
     $credit = $BTL->credit_summary();
     $funds = $balance - $credit;
     $funds = $funds > 0 ? $funds : '0';
     // Get cart items
     $items = $item->getCartItems(User::get('id'));
     if (!$items or $cost > $funds) {
         $this->cartTask();
         return;
     }
     // Get shipping info
     $shipping = array_map('trim', $_POST);
     // make sure email address is valid
     $email = \Hubzero\Utility\Validate::email($shipping['email']) ? $shipping['email'] : User::get('email');
     // Format posted info
     $details = Lang::txt('COM_STORE_SHIP_TO') . ':' . "\r\n";
     $details .= $shipping['name'] . "\r\n";
     $details .= Sanitize::stripAll($shipping['address']) . "\r\n";
     $details .= Lang::txt('COM_STORE_COUNTRY') . ': ' . $shipping['country'] . "\r\n";
     $details .= '----------------------------------------------------------' . "\r\n";
     $details .= Lang::txt('COM_STORE_CONTACT') . ': ' . "\r\n";
     if ($shipping['phone']) {
         $details .= $shipping['phone'] . "\r\n";
     }
     $details .= $email . "\r\n";
     $details .= '----------------------------------------------------------' . "\r\n";
     $details .= Lang::txt('COM_STORE_DETAILS') . ': ';
     $details .= $shipping['comments'] ? "\r\n" . Sanitize::stripAll($shipping['comments']) : 'N/A';
     // Register a new order
     $order = new Order($this->database);
     $order->uid = User::get('id');
     $order->total = $cost;
     $order->status = '0';
     // order placed
     $order->ordered = $now;
     $order->email = $email;
     $order->details = $details;
     // Store new content
     if (!$order->store()) {
         throw new Exception($order->getError(), 500);
     }
     // Get order ID
     $objO = new Order($this->database);
     $orderid = $objO->getOrderID(User::get('id'), $now);
     if ($orderid) {
         // Transfer cart items to order
         foreach ($items as $itm) {
             $orderitem = new OrderItem($this->database);
             $orderitem->uid = User::get('id');
             $orderitem->oid = $orderid;
             $orderitem->itemid = $itm->itemid;
             $orderitem->price = $itm->price;
             $orderitem->quantity = $itm->quantity;
             $orderitem->selections = $itm->selections;
             // Save order item
             if (!$orderitem->store()) {
                 throw new Exception($orderitem->getError(), 500);
             }
         }
         // Put the purchase amount on hold
         $BTL = new Teller(User::get('id'));
         $BTL->hold($order->total, Lang::txt('COM_STORE_BANKING_HOLD'), 'store', $orderid);
         $message = new \Hubzero\Mail\Message();
         $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_STORE_EMAIL_SUBJECT_NEW_ORDER', $orderid));
         $message->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_option)));
         // Plain text email
         $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'confirmation_plain'));
         $eview->option = $this->_option;
         $eview->controller = $this->_controller;
         $eview->orderid = $orderid;
         $eview->cost = $cost;
         $eview->shipping = $shipping;
         $eview->details = $details;
         $eview->items = $items;
         $plain = $eview->loadTemplate(false);
         $plain = str_replace("\n", "\r\n", $plain);
         $message->addPart($plain, 'text/plain');
         // HTML email
         $eview->setLayout('confirmation_html');
         $html = $eview->loadTemplate();
         $html = str_replace("\n", "\r\n", $html);
         $message->addPart($html, 'text/html');
         // Send e-mail
         $message->setTo(array(User::get('email')));
         $message->send();
     }
     // Empty cart
     $item->deleteCartItem('', User::get('id'), 'all');
     if ($this->getError()) {
         \Notify::message($this->getError(), 'error');
     } else {
         \Notify::message(Lang::txt('COM_STORE_SUCCESS_MESSAGE', $orderid), 'success');
     }
     App::redirect(Route::url('index.php?option=' . $this->_option));
     return;
 }
Exemplo n.º 13
0
 /**
  * Final submission
  *
  * @return     void
  */
 public function submitTask()
 {
     // Incoming
     $id = Request::getInt('id', 0);
     // Ensure we have an ID to work with
     if (!$id) {
         throw new Exception(Lang::txt('COM_CONTRIBUTE_NO_ID'), 500);
     }
     // Load resource info
     $resource = new Resource($this->database);
     $resource->load($id);
     // Set a flag for if the resource was already published or not
     $published = 0;
     if ($resource->published != 2) {
         $published = 1;
     }
     // Check if a newly submitted resource was authorized to be published
     $authorized = Request::getInt('authorization', 0);
     if (!$authorized && !$published) {
         $this->setError(Lang::txt('COM_CONTRIBUTE_CONTRIBUTION_NOT_AUTHORIZED'));
         $this->_checkProgress($id);
         $this->step_review();
         return;
     }
     // Is this a newly submitted resource?
     if (!$published) {
         // 0 = unpublished, 1 = published, 2 = composing, 3 = pending (submitted), 4 = deleted
         // Are submissions auto-approved?
         if ($this->config->get('autoapprove') == 1) {
             //checks if autoapproved content has children (configurable in options on backend)
             if ($this->config->get('autoapprove_content_check') == 1) {
                 require_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'resource.php';
                 $item = new \Components\Resources\Models\Resource($id);
                 if (count($item->children()) < 1) {
                     $this->setError(Lang::txt('COM_CONTRIBUTE_NO_CONTENT'));
                     $this->step_review();
                     return;
                 }
             }
             // Set status to published
             $resource->published = 1;
             $resource->publish_up = Date::toSql();
         } else {
             $apu = $this->config->get('autoapproved_users');
             $apu = explode(',', $apu);
             $apu = array_map('trim', $apu);
             if (in_array(User::get('username'), $apu)) {
                 // Set status to published
                 $resource->published = 1;
                 $resource->publish_up = Date::toSql();
             } else {
                 // Set status to pending review (submitted)
                 $resource->published = 3;
             }
         }
         // Get the resource's contributors
         $helper = new Helper($id, $this->database);
         $helper->getCons();
         $contributors = $helper->_contributors;
         if (!$contributors || count($contributors) <= 0) {
             $this->setError(Lang::txt('COM_CONTRIBUTE_CONTRIBUTION_HAS_NO_AUTHORS'));
             $this->_checkProgress($id);
             $this->step_review();
             return;
         }
         // Get any set emails that should be notified of ticket submission
         $defs = explode(',', $this->config->get('email_when_submitted', '{config.mailfrom}'));
         if (!empty($defs)) {
             $message = new \Hubzero\Mail\Message();
             $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_RESOURCES_EMAIL_SUBJECT_NEW_SUBMISSION', $resource->id));
             $message->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_option)));
             // Plain text email
             $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'submitted_plain'));
             $eview->option = $this->_option;
             $eview->controller = $this->_controller;
             $eview->resource = $resource;
             $eview->delimiter = '';
             $plain = $eview->loadTemplate();
             $plain = str_replace("\n", "\r\n", $plain);
             $message->addPart($plain, 'text/plain');
             // HTML email
             $eview->setLayout('submitted_html');
             $html = $eview->loadTemplate();
             $html = str_replace("\n", "\r\n", $html);
             $message->addPart($html, 'text/html');
             // Loop through the addresses
             foreach ($defs as $def) {
                 $def = trim($def);
                 // Check if the address should come from config
                 if ($def == '{config.mailfrom}') {
                     $def = Config::get('mailfrom');
                 }
                 // Check for a valid address
                 if (\Hubzero\Utility\Validate::email($def)) {
                     // Send e-mail
                     $message->setTo(array($def));
                     $message->send();
                 }
             }
         }
     }
     // Is this resource licensed under Creative Commons?
     if ($this->config->get('cc_license')) {
         $license = Request::getVar('license', '');
         if ($license == 'custom') {
             $license .= $resource->id;
             $licenseText = Request::getVar('license-text', '');
             if ($licenseText == '[ENTER LICENSE HERE]') {
                 $this->setError(Lang::txt('Please enter a license.'));
                 $this->_checkProgress($id);
                 $this->step_review();
                 return;
             }
             include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'license.php';
             $rl = new License($this->database);
             $rl->load($license);
             $rl->name = $license;
             $rl->text = $licenseText;
             $rl->info = $resource->id;
             $rl->check();
             $rl->store();
         }
         // set license
         $params = new \Hubzero\Config\Registry($resource->params);
         $params->set('license', $license);
         $resource->params = $params->toString();
     }
     // Save and checkin the resource
     $resource->store();
     $resource->checkin();
     // If a previously published resource, redirect to the resource page
     if ($published == 1) {
         if ($resource->alias) {
             $url = Route::url('index.php?option=com_resources&alias=' . $resource->alias);
         } else {
             $url = Route::url('index.php?option=com_resources&id=' . $resource->id);
         }
         App::redirect($url);
         return;
     }
     // Output HTML
     $this->setView($this->_controller, 'thanks');
     $this->view->title = $this->_title;
     $this->view->config = $this->config;
     $this->view->resource = $resource;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }
Exemplo n.º 14
0
 /**
  * Handles the actual sending of emails (or queuing them to be sent)
  *
  * @param   int     $user      the user id to send to
  * @param   array   $posts     the posts to include in the email
  * @param   string  $interval  the distribution interval
  * @return  bool
  **/
 private function sendEmail($user, $posts, $interval = 'day')
 {
     if (!is_dir(PATH_CORE . DS . 'plugins' . DS . 'members' . DS . 'activity')) {
         $this->setError('PLG_CRON_ACTIVITY_REQUIRED_PLUGIN_NOT_FOUND');
         return false;
     }
     $user = User::oneOrNew($user);
     if (!$user->get('id')) {
         $this->setError('PLG_CRON_ACTIVITY_USER_NOT_FOUND', $user->get('id'));
         return false;
     }
     $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'plugins' . DS . 'members' . DS . 'activity', 'name' => 'emails', 'layout' => 'digest_plain'));
     $eview->member = $user;
     $eview->rows = $posts;
     $eview->interval = $interval;
     $plain = $eview->loadTemplate();
     $plain = str_replace("\n", "\r\n", $plain);
     // HTML
     $eview->setLayout('digest_html');
     $html = $eview->loadTemplate();
     $html = str_replace("\n", "\r\n", $html);
     // Build message
     $message = App::get('mailer');
     $message->setSubject(Lang::txt('PLG_MEMBERS_ACTIVITY_EMAIL_SUBJECT'))->addFrom(Config::get('mailfrom'), Config::get('sitename'))->addTo($user->get('email'), $user->get('name'))->addHeader('X-Component', 'com_members')->addHeader('X-Component-Object', 'members_activity_email_digest');
     $message->addPart($plain, 'text/plain');
     $message->addPart($html, 'text/html');
     // Send mail
     if (!$message->send($this->params->get('email_transport_mechanism'))) {
         $this->setError(Lang::txt('PLG_CRON_ACTIVITY_EMAIL_FAILED', $user->get('email')));
         return false;
     }
     return true;
 }
Exemplo n.º 15
0
 /**
  *  Save group settings
  *
  * @return 		void
  */
 public function saveTask()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask(Lang::txt('COM_GROUPS_CREATE_MUST_BE_LOGGED_IN'));
         return;
     }
     Request::checkToken();
     // Incoming
     $g_gidNumber = Request::getInt('gidNumber', 0, 'post');
     $c_gidNumber = Request::getVar('gidNumber', 0, 'post');
     if ((string) $g_gidNumber !== (string) $c_gidNumber) {
         App::abort(404, Lang::txt('COM_GROUPS_ERROR_NO_ID'));
     }
     if (!$g_gidNumber && !User::authorise('core.create', $this->_option) || $g_gidNumber && !User::authorise('core.edit', $this->_option)) {
         return App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_GROUPS_ERROR_NOT_AUTH'), 'warning');
     }
     $g_cn = trim(Request::getVar('cn', '', 'post'));
     $g_description = preg_replace('/\\s+/', ' ', trim(Request::getVar('description', Lang::txt('NONE'), 'post')));
     $g_discoverability = Request::getInt('discoverability', 0, 'post');
     $g_public_desc = Sanitize::stripScripts(trim(Request::getVar('public_desc', '', 'post', 'none', 2)));
     $g_private_desc = Sanitize::stripScripts(trim(Request::getVar('private_desc', '', 'post', 'none', 2)));
     $g_restrict_msg = Sanitize::stripScripts(trim(Request::getVar('restrict_msg', '', 'post', 'none', 2)));
     $g_join_policy = Request::getInt('join_policy', 0, 'post');
     $tags = trim(Request::getVar('tags', ''));
     $lid = Request::getInt('lid', 0, 'post');
     $customization = Request::getVar('group', '', 'POST', 'none', 2);
     $plugins = Request::getVar('group_plugin', '', 'POST');
     $params = Request::getVar('params', array(), 'POST');
     $g_discussion_email_autosubscribe = Request::getInt('discussion_email_autosubscribe', 0, 'post');
     //Check authorization
     if ($this->_authorize() != 'manager' && $g_gidNumber != 0 && !$this->_authorizedForTask('group.edit')) {
         $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH'));
     }
     //are we editing or creating
     if ($g_gidNumber) {
         $group = Group::getInstance($g_gidNumber);
         $this->_task = 'edit';
         $before = Group::getInstance($g_gidNumber);
     } else {
         $this->_task = 'new';
         $group = new Group();
         $before = new Group();
     }
     // Check for any missing info
     if (!$g_cn) {
         $this->setNotification(Lang::txt('COM_GROUPS_SAVE_ERROR_MISSING_INFORMATION') . ': ' . Lang::txt('COM_GROUPS_DETAILS_FIELD_CN'), 'error');
     }
     if (!$g_description) {
         $this->setNotification(Lang::txt('COM_GROUPS_SAVE_ERROR_MISSING_INFORMATION') . ': ' . Lang::txt('COM_GROUPS_DETAILS_FIELD_DESCRIPTION'), 'error');
     }
     // Ensure the data passed is valid
     if ($g_cn == 'new' || $g_cn == 'browse') {
         $this->setNotification(Lang::txt('COM_GROUPS_SAVE_ERROR_INVALID_ID'), 'error');
     }
     if (!$this->_validCn($g_cn)) {
         $this->setNotification(Lang::txt('COM_GROUPS_SAVE_ERROR_INVALID_ID'), 'error');
     }
     if ($this->_task == 'new' && Group::exists($g_cn, true)) {
         $this->setNotification(Lang::txt('COM_GROUPS_SAVE_ERROR_ID_TAKEN'), 'error');
     }
     // Get the logo
     $logo = '';
     if (isset($customization['logo'])) {
         $logo_parts = explode("/", $customization['logo']);
         $logo = array_pop($logo_parts);
     }
     // Plugin settings
     $plugin_access = '';
     foreach ($plugins as $plugin) {
         $plugin_access .= $plugin['name'] . '=' . $plugin['access'] . ',' . "\n";
     }
     // Run content through validation and spam filters
     if (trim($g_public_desc)) {
         $results = Event::trigger('content.onContentBeforeSave', array('com_groups.group.public_desc', &$g_public_desc, $this->_task == 'new'));
         foreach ($results as $result) {
             if ($result === false) {
                 $this->setNotification(Lang::txt('COM_GROUPS_SAVE_ERROR_FAILED_VALIDATION'), 'error');
                 break;
             }
         }
     }
     // Push back into edit mode if any errors
     if ($this->getNotifications()) {
         $group->set('cn', $g_cn);
         $group->set('description', $g_description);
         $group->set('public_desc', $g_public_desc);
         $group->set('private_desc', $g_private_desc);
         $group->set('join_policy', $g_join_policy);
         $group->set('restrict_msg', $g_restrict_msg);
         $group->set('discoverability', $g_discoverability);
         $group->set('discussion_email_autosubscribe', $g_discussion_email_autosubscribe);
         $group->set('logo', $logo);
         $group->set('plugins', $plugin_access);
         $this->lid = $lid;
         $this->group = $group;
         $this->tags = $tags;
         $this->editTask();
         return;
     }
     // Build the e-mail message
     if ($this->_task == 'new') {
         $subject = Lang::txt('COM_GROUPS_SAVE_EMAIL_REQUESTED_SUBJECT', $g_cn);
         $type = 'groups_created';
     } else {
         $subject = Lang::txt('COM_GROUPS_SAVE_EMAIL_UPDATED_SUBJECT', $g_cn);
         $type = 'groups_changed';
     }
     if ($this->_task == 'new') {
         $group->set('cn', $g_cn);
         $group->set('type', 1);
         $group->set('published', 1);
         $group->set('approved', $this->config->get('auto_approve', 1));
         $group->set('created', Date::toSql());
         $group->set('created_by', User::get('id'));
         $group->add('managers', array(User::get('id')));
         $group->add('members', array(User::get('id')));
         $group->create();
     }
     // merge incoming settings with existing params
     $params = new Registry($params);
     $gParams = new Registry($group->get('params'));
     $gParams->merge($params);
     //set group vars & Save group
     $group->set('description', $g_description);
     $group->set('public_desc', $g_public_desc);
     $group->set('private_desc', $g_private_desc);
     $group->set('join_policy', $g_join_policy);
     $group->set('restrict_msg', $g_restrict_msg);
     $group->set('discoverability', $g_discoverability);
     $group->set('logo', $logo);
     $group->set('plugins', $plugin_access);
     $group->set('discussion_email_autosubscribe', $g_discussion_email_autosubscribe);
     $group->set('params', $gParams->toString());
     $group->update();
     // Process tags
     $gt = new Tags($group->get('gidNumber'));
     $gt->setTags($tags, User::get('id'));
     // Rename the temporary upload directory if it exist
     $log_comments = '';
     Event::trigger('groups.onGroupAfterSave', array($before, $group));
     if ($this->_task == 'new') {
         if ($lid != $group->get('gidNumber')) {
             $config = $this->config;
             $bp = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/groups'), DS);
             if (is_dir($bp . DS . $lid)) {
                 rename($bp . DS . $lid, $bp . DS . $group->get('gidNumber'));
             }
         }
         $log_action = 'group_created';
         // Trigger the functions that delete associated content
         // Should return logs of what was deleted
         $logs = Event::trigger('groups.onGroupNew', array($group));
         if (count($logs) > 0) {
             $log_comments .= implode('', $logs);
         }
     } else {
         $log_action = 'group_edited';
     }
     // log invites
     Log::log(array('gidNumber' => $group->get('gidNumber'), 'action' => $log_action, 'comments' => $log_comments));
     // Build the e-mail message
     // Note: this is done *before* pushing the changes to the group so we can show, in the message, what was changed
     $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'saved_plain'));
     $eview->option = $this->_option;
     $eview->user = User::getRoot();
     $eview->group = $group;
     $plain = $eview->loadTemplate(false);
     $plain = str_replace("\n", "\r\n", $plain);
     $eview->setLayout('saved');
     $html = $eview->loadTemplate();
     $html = str_replace("\n", "\r\n", $html);
     // Get the administrator e-mail
     $emailadmin = Config::get('mailfrom');
     // Get the "from" info
     $from = array('name' => Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_name)), 'email' => Config::get('mailfrom'));
     //only email managers if updating group
     if ($type == 'groups_changed') {
         // build array of managers
         $managers = array();
         foreach ($group->get('managers') as $m) {
             $profile = \Hubzero\User\Profile::getInstance($m);
             if ($profile) {
                 $managers[$profile->get('email')] = $profile->get('name');
             }
         }
         // create new message
         $message = new \Hubzero\Mail\Message();
         // build message object and send
         $message->setSubject($subject)->addFrom($from['email'], $from['name'])->setTo($managers)->addHeader('X-Mailer', 'PHP/' . phpversion())->addHeader('X-Component', 'com_groups')->addHeader('X-Component-Object', 'group_saved')->addHeader('X-Component-ObjectId', $group->get('gidNumber'))->addPart($plain, 'text/plain')->addPart($html, 'text/html')->send();
     }
     //only inform site admin if the group wasn't auto-approved
     if (!$this->config->get('auto_approve', 1) && $group->get('approved') == 0) {
         // create approval subject
         $subject = Lang::txt('COM_GROUPS_SAVE_WAITING_APPROVAL', Config::get('sitename'));
         // build approval message
         $link = 'https://' . trim($_SERVER['HTTP_HOST'], DS) . DS . 'groups' . DS . $group->get('cn');
         $link2 = 'https://' . trim($_SERVER['HTTP_HOST'], DS) . DS . 'administrator';
         $html = Lang::txt('COM_GROUPS_SAVE_WAITING_APPROVAL_DESC', $group->get('description'), $link, $link2);
         // create new message
         $message = new \Hubzero\Mail\Message();
         // build message object and send
         $message->setSubject($subject)->addFrom($from['email'], $from['name'])->setTo($emailadmin)->addHeader('X-Mailer', 'PHP/' . phpversion())->addHeader('X-Component', 'com_groups')->addHeader('X-Component-Object', 'group_pending_approval')->addHeader('X-Component-ObjectId', $group->get('gidNumber'))->addPart($plain, 'text/plain')->addPart($html, 'text/html')->send();
     }
     // create home page
     if ($this->_task == 'new') {
         // create page
         $page = new Page(array('gidNumber' => $group->get('gidNumber'), 'parent' => 0, 'lft' => 1, 'rgt' => 2, 'depth' => 0, 'alias' => 'overview', 'title' => 'Overview', 'state' => 1, 'privacy' => 'default', 'home' => 1));
         $page->store(false);
         // create page version
         $version = new Page\Version(array('pageid' => $page->get('id'), 'version' => 1, 'content' => "<!-- {FORMAT:HTML} -->\n<p>[[Group.DefaultHomePage()]]</p>", 'created' => Date::toSql(), 'created_by' => User::get('id'), 'approved' => 1));
         $version->store(false);
     }
     // Show success message to user
     if ($this->_task == 'new') {
         $this->setNotification(Lang::txt('COM_GROUPS_CREATED_SUCCESS', $group->get('description')), 'passed');
     } else {
         $this->setNotification(Lang::txt('COM_GROUPS_UPDATED_SUCCESS', $group->get('description')), 'passed');
     }
     // Redirect back to the group page
     App::redirect(Route::url('index.php?option=' . $this->_option . '&cn=' . $group->get('cn')));
     return;
 }
Exemplo n.º 16
0
 /**
  * Notify project team
  *
  * @param   integer  $managers_only
  * @return  void
  */
 protected function _notifyTeam($managers_only = 0)
 {
     // Is messaging turned on?
     if ($this->config->get('messaging') != 1) {
         return false;
     }
     $message = array();
     // Get project
     if (empty($this->model) || !$this->model->exists()) {
         return false;
     }
     // Set up email config
     $from = array();
     $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_PROJECTS');
     $from['email'] = Config::get('mailfrom');
     // Get team
     $team = $this->model->team();
     // Must have addressees
     if (empty($team)) {
         return false;
     }
     $subject_active = Lang::txt('COM_PROJECTS_EMAIL_SUBJECT_ADDED') . ' ' . $this->model->get('alias');
     $subject_pending = Lang::txt('COM_PROJECTS_EMAIL_SUBJECT_INVITE') . ' ' . $this->model->get('alias');
     // Message body
     $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'invite_plain'));
     $eview->option = $this->_option;
     $eview->project = $this->model;
     $eview->delimiter = '';
     // Send out message/email
     foreach ($team as $member) {
         if ($managers_only && $member->role != 1) {
             continue;
         }
         $eview->role = $member->role;
         if ($member->userid && $member->userid != User::get('id')) {
             $eview->uid = $member->userid;
             $message['plaintext'] = $eview->loadTemplate(false);
             $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
             // HTML email
             $eview->setLayout('invite_html');
             $message['multipart'] = $eview->loadTemplate();
             $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
             // Creator
             if ($member->userid == $this->model->get('created_by_user')) {
                 $subject_active = Lang::txt('COM_PROJECTS_EMAIL_SUBJECT_CREATOR_CREATED') . ' ' . $this->model->get('alias') . '!';
             }
             // Send HUB message
             Event::trigger('xmessage.onSendMessage', array('projects_member_added', $subject_active, $message, $from, array($member->userid), $this->_option));
         } elseif ($member->invited_email && $member->invited_code) {
             $eview->uid = 0;
             $eview->code = $member->invited_code;
             $eview->email = $member->invited_email;
             $message['plaintext'] = $eview->loadTemplate(false);
             $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
             // HTML email
             $eview->setLayout('invite_html');
             $message['multipart'] = $eview->loadTemplate();
             $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
             Helpers\Html::email($member->invited_email, Config::get('sitename') . ': ' . $subject_pending, $message, $from);
         }
     }
 }
Exemplo n.º 17
0
 /**
  * sendConfirmEmail 
  * 
  * @static
  * @access public
  * @return void
  */
 public static function sendConfirmEmail($user, $xregistration)
 {
     $baseURL = rtrim(Request::base(), '/');
     $subject = Config::get('sitename') . ' ' . Lang::txt('COM_MEMBERS_REGISTER_EMAIL_CONFIRMATION');
     $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'create'));
     $eview->option = 'com_members';
     //$this->_option; //com_members
     $eview->controller = 'register';
     //$this->_controller; //register
     $eview->sitename = Config::get('sitename');
     $eview->xprofile = $user;
     $eview->baseURL = $baseURL;
     $eview->xregistration = $xregistration;
     $msg = new \Hubzero\Mail\Message();
     $msg->setSubject($subject)->addTo($user->get('email'), $user->get('name'))->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' Administrator')->addHeader('X-Component', 'com_members');
     $message = $eview->loadTemplate(false);
     $message = str_replace("\n", "\r\n", $message);
     $msg->addPart($message, 'text/plain');
     $eview->setLayout('create_html');
     $message = $eview->loadTemplate();
     $message = str_replace("\n", "\r\n", $message);
     $msg->addPart($message, 'text/html');
     if (!$msg->send()) {
         $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_EMAILING_CONFIRMATION'));
         // @FIXME: LOG ERROR SOMEWHERE
         return false;
     } else {
         return true;
     }
 }
Exemplo n.º 18
0
 /**
  * Handles the actual sending of emails
  *
  * @param   object  $subscriber
  * @param   string  $message
  * @param   string  $subject
  * @param   string  $url
  * @return  bool
  */
 private function _sendEmail($subscriber, $message, $subject, $url)
 {
     $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'site', 'name' => 'emails', 'layout' => 'watch_plain'));
     $eview->delimiter = '~!~!~!~!~!~!~!~!~!~!';
     $eview->message = $message;
     $eview->subject = $subject;
     $eview->publication = $this->publication;
     $eview->url = $url;
     $name = Config::get('sitename') . ' ' . Lang::txt('PLG_PUBLICATIONS_WATCH_SUBSCRIBER');
     $email = $subscriber->email;
     $eview->unsubscribeLink = Route::url($this->publication->link() . '&active=watch&action=unsubscribe&confirm=1&email=' . $email);
     // Get profile information
     if ($subscriber->created_by) {
         $user = User::getInstance($subscriber->created_by);
         $name = $user ? $user->get('name') : $name;
         $email = $user ? $user->get('email') : $email;
     }
     $plain = $eview->loadTemplate(false);
     $plain = str_replace("\n", "\r\n", $plain);
     // HTML
     $eview->setLayout('watch_html');
     $html = $eview->loadTemplate();
     $html = str_replace("\n", "\r\n", $html);
     if (empty($email)) {
         return false;
     }
     // Build message
     $message = new \Hubzero\Mail\Message();
     $message->setSubject($subject)->addFrom(Config::get('mailfrom'), Config::get('sitename'))->addTo($email, $name)->addHeader('X-Component', 'com_publications')->addHeader('X-Component-Object', 'publications_watch_email');
     $message->addPart($plain, 'text/plain');
     $message->addPart($html, 'text/html');
     // Send mail
     if (!$message->send()) {
         $this->setError('Failed to mail %s', $email);
         return false;
     }
     return true;
 }
Exemplo n.º 19
0
 /**
  * Change registered email
  *
  * @return     void
  */
 public function changeTask()
 {
     // Set the pathway
     $this->_buildPathway();
     // Set the page title
     $this->_buildTitle();
     // Check if the user is logged in
     if (User::isGuest()) {
         $return = base64_encode(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=' . $this->_task, false, true));
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . $return, false), Lang::txt('COM_MEMBERS_REGISTER_ERROR_LOGIN_TO_UPDATE'), 'warning');
         return;
     }
     $xprofile = \Hubzero\User\Profile::getInstance(User::get('id'));
     $login = $xprofile->get('username');
     $email = $xprofile->get('email');
     $email_confirmed = $xprofile->get('emailConfirmed');
     // Instantiate a new view
     $this->view->title = Lang::txt('COM_MEMBERS_REGISTER_CHANGE');
     $this->view->login = $login;
     $this->view->email = $email;
     $this->view->email_confirmed = $email_confirmed;
     $this->view->success = false;
     // Incoming
     $return = urldecode(Request::getVar('return', '/'));
     $this->view->return = $return;
     // Check if a new email was submitted
     $pemail = Request::getVar('email', '', 'post');
     $update = Request::getVar('update', '', 'post');
     if ($update) {
         if (!$pemail) {
             $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_INVALID_EMAIL'));
         }
         if ($pemail && \Components\Members\Helpers\Utility::validemail($pemail)) {
             // Check if the email address was actually changed
             if ($pemail == $email) {
                 // Addresses are the same! Redirect
                 App::redirect($return, '', 'message', true);
             } else {
                 // New email submitted - attempt to save it
                 $xprofile = \Hubzero\User\Profile::getInstance($login);
                 if ($xprofile) {
                     $dtmodify = Date::toSql();
                     $xprofile->set('email', $pemail);
                     $xprofile->set('modifiedDate', $dtmodify);
                     if ($xprofile->update()) {
                         $user = User::getInstance($login);
                         $user->set('email', $pemail);
                         $user->save();
                     } else {
                         $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_UPDATING_ACCOUNT'));
                     }
                 } else {
                     $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_UPDATING_ACCOUNT'));
                 }
                 // Any errors returned?
                 if (!$this->getError()) {
                     // No errors
                     // Attempt to send a new confirmation code
                     $confirm = \Components\Members\Helpers\Utility::genemailconfirm();
                     $xprofile = new \Hubzero\User\Profile();
                     $xprofile->load($login);
                     $xprofile->set('emailConfirmed', $confirm);
                     $xprofile->update();
                     $subject = Config::get('sitename') . ' ' . Lang::txt('COM_MEMBERS_REGISTER_EMAIL_CONFIRMATION');
                     $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'confirm'));
                     $eview->option = $this->_option;
                     $eview->controller = $this->_controller;
                     $eview->sitename = Config::get('sitename');
                     $eview->login = $login;
                     $eview->name = $xprofile->get('name');
                     $eview->registerDate = $xprofile->get('registerDate');
                     $eview->baseURL = $this->baseURL;
                     $eview->confirm = $confirm;
                     $msg = new \Hubzero\Mail\Message();
                     $msg->setSubject($subject)->addTo($pemail)->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' Administrator')->addHeader('X-Component', $this->_option);
                     $message = $eview->loadTemplate(false);
                     $message = str_replace("\n", "\r\n", $message);
                     $msg->addPart($message, 'text/plain');
                     $eview->setLayout('confirm_html');
                     $message = $eview->loadTemplate();
                     $message = str_replace("\n", "\r\n", $message);
                     $msg->addPart($message, 'text/html');
                     if (!$msg->send()) {
                         $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_EMAILING_CONFIRMATION', $pemail));
                     }
                     // Show the success form
                     $this->view->success = true;
                 }
             }
         } else {
             $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_INVALID_EMAIL'));
         }
     }
     // Output the view
     if ($this->getError()) {
         $this->view->email = $pemail;
         $this->view->setError($this->getError());
     }
     $this->view->display();
 }
Exemplo n.º 20
0
 /**
  * Saves changes to an order
  *
  * @return void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     $statusmsg = '';
     $data = array_map('trim', $_POST);
     $action = isset($data['action']) ? $data['action'] : '';
     $id = $data['id'] ? $data['id'] : 0;
     $cost = intval($data['total']);
     if ($id) {
         // initiate extended database class
         $row = new Order($this->database);
         $row->load($id);
         $row->notes = \Hubzero\Utility\Sanitize::clean($data['notes']);
         $hold = $row->total;
         $row->total = $cost;
         // get user bank account
         $xprofile = User::getInstance($row->uid);
         $BTL_Q = new Teller($this->database, $xprofile->get('id'));
         switch ($action) {
             case 'complete_order':
                 // adjust credit
                 $credit = $BTL_Q->credit_summary();
                 $adjusted = $credit - $hold;
                 $BTL_Q->credit_adjustment($adjusted);
                 // remove hold
                 $sql = "DELETE FROM `#__users_transactions` WHERE category='store' AND type='hold' AND referenceid='" . $id . "' AND uid=" . intval($row->uid);
                 $this->database->setQuery($sql);
                 if (!$this->database->query()) {
                     throw new Exception($this->database->getErrorMsg(), 500);
                 }
                 // debit account
                 if ($cost > 0) {
                     $BTL_Q->withdraw($cost, Lang::txt('COM_STORE_BANKING_PURCHASE') . ' #' . $id, 'store', $id);
                 }
                 // update order information
                 $row->status_changed = Date::toSql();
                 $row->status = 1;
                 $statusmsg = Lang::txt('COM_STORE_ORDER') . ' #' . $id . ' ' . Lang::txt('COM_STORE_HAS_BEEN') . ' ' . strtolower(Lang::txt('COM_STORE_COMPLETED')) . '.';
                 break;
             case 'cancel_order':
                 // adjust credit
                 $credit = $BTL_Q->credit_summary();
                 $adjusted = $credit - $hold;
                 $BTL_Q->credit_adjustment($adjusted);
                 // remove hold
                 $sql = "DELETE FROM `#__users_transactions` WHERE category='store' AND type='hold' AND referenceid='" . $id . "' AND uid=" . intval($row->uid);
                 $this->database->setQuery($sql);
                 if (!$this->database->query()) {
                     throw new Exception($this->database->getErrorMsg(), 500);
                 }
                 // update order information
                 $row->status_changed = Date::toSql();
                 $row->status = 2;
                 $statusmsg = Lang::txt('COM_STORE_ORDER') . ' #' . $id . ' ' . Lang::txt('COM_STORE_HAS_BEEN') . ' ' . strtolower(Lang::txt('COM_STORE_CANCELLED')) . '.';
                 break;
             case 'message':
                 $statusmsg = Lang::txt('COM_STORE_MSG_SENT') . '.';
                 break;
             default:
                 $statusmsg = Lang::txt('COM_STORE_ORDER_DETAILS_UPDATED') . '.';
                 break;
         }
         // check content
         if (!$row->check()) {
             throw new Exception($row->getError(), 500);
             return;
         }
         // store new content
         if (!$row->store()) {
             throw new Exception($row->getError(), 500);
         }
         // send email
         if ($action || $data['message']) {
             if (\Hubzero\Utility\Validate::email($row->email)) {
                 $message = new \Hubzero\Mail\Message();
                 $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_STORE_EMAIL_UPDATE_SHORT', $id));
                 $message->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' ' . Lang::txt('COM_STORE_STORE'));
                 // Plain text email
                 $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => '_plain'));
                 $eview->option = $this->_option;
                 $eview->controller = $this->_controller;
                 $eview->orderid = $id;
                 $eview->cost = $cost;
                 $eview->row = $row;
                 $eview->action = $action;
                 $eview->message = \Hubzero\Utility\Sanitize::stripAll($data['message']);
                 $plain = $eview->loadTemplate(false);
                 $plain = str_replace("\n", "\r\n", $plain);
                 $message->addPart($plain, 'text/plain');
                 // HTML email
                 $eview->setLayout('_html');
                 $html = $eview->loadTemplate();
                 $html = str_replace("\n", "\r\n", $html);
                 $message->addPart($html, 'text/html');
                 // Send e-mail
                 $message->setTo(array($row->email));
                 $message->send();
             }
         }
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $statusmsg);
 }
Exemplo n.º 21
0
 /**
  * Send mail to page approvers
  *
  * @param     $type      type of object needing approval
  * @param     $object    object needing approval
  * @return    void
  */
 public static function sendApproveNotification($type, $object)
 {
     // build title
     $title = Lang::txt('Page "%s" Requires Approval', $object->get('title'));
     if ($type == 'module') {
         $title = Lang::txt('Module "%s" Requires Approval', $object->get('title'));
     }
     // get approvers w/ emails
     $approvers = self::getPageApproversEmail();
     // subject details
     $subject = Config::get('sitename') . ' ' . Lang::txt('Groups') . ', ' . $title;
     // from details
     $from = array('name' => Config::get('sitename') . ' ' . Lang::txt('Groups'), 'email' => Config::get('mailfrom'));
     // build html email
     $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => $type . '_plain'));
     $eview->option = Request::getCmd('option', 'com_groups');
     $eview->controller = Request::getCmd('controller', 'groups');
     $eview->group = \Hubzero\User\Group::getInstance(Request::getCmd('cn', Request::getCmd('gid')));
     $eview->object = $object;
     $plain = $eview->loadTemplate(false);
     $plain = str_replace("\n", "\r\n", $plain);
     $eview->setLayout($type);
     $html = $eview->loadTemplate();
     $html = str_replace("\n", "\r\n", $html);
     // create new message
     $message = new \Hubzero\Mail\Message();
     // build message object and send
     $message->setSubject($subject)->addFrom($from['email'], $from['name'])->setTo($approvers)->addHeader('X-Mailer', 'PHP/' . phpversion())->addHeader('X-Component', 'com_groups')->addHeader('X-Component-Object', $type . '_approval')->addPart($plain, 'text/plain')->addPart($html, 'text/html')->send();
 }
Exemplo n.º 22
0
 /**
  * Send invite email
  *
  * @param  integer 	$uid
  * @param  string 	$email
  * @param  string 	$code
  * @param  integer 	$role
  * @param  object 	$project
  *
  * @return boolean True on success
  */
 public function sendInviteEmail($uid = 0, $email = '', $code = '', $role = 0, $model = '', $option = 'com_projects')
 {
     $uid = $uid ? $uid : 0;
     $email = $email ? $email : User::get('email');
     if (!$email || !$uid && !$code) {
         return false;
     }
     $option = $option ? $option : $this->_option;
     $model = $model ? $model : $this->model;
     if (!$model->exists()) {
         return false;
     }
     $database = App::get('db');
     // Validate email
     $regex = '/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/';
     if (!preg_match($regex, $email)) {
         return false;
     }
     // Set up email config
     $from = array('name' => Config::get('sitename') . ' ' . Lang::txt(strtoupper($option)), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U')));
     // Email message subject
     if ($model->isProvisioned()) {
         $objPub = new \Components\Publications\Tables\Publication($database);
         $pub = $objPub->getProvPublication($model->get('id'));
         if (!$pub || !$pub->id) {
             return false;
         }
         $subject = $uid ? Lang::txt('COM_PROJECTS_EMAIL_SUBJECT_ADDED_PROV') : Lang::txt('COM_PROJECTS_EMAIL_SUBJECT_INVITE_PROV');
     } else {
         $subject = $uid ? Lang::txt('COM_PROJECTS_EMAIL_SUBJECT_ADDED') . ' ' . $model->get('alias') : Lang::txt('COM_PROJECTS_EMAIL_SUBJECT_INVITE') . ' ' . $model->get('alias');
     }
     // Message body
     $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'site', 'name' => 'emails', 'layout' => 'invite_plain'));
     $eview->option = $option;
     $eview->project = $model;
     $eview->code = $code;
     $eview->email = $email;
     $eview->uid = $uid;
     $eview->role = $role;
     $eview->pub = isset($pub) ? $pub : '';
     $message['plaintext'] = $eview->loadTemplate(false);
     $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
     // HTML email
     $eview->setLayout('invite_html');
     $message['multipart'] = $eview->loadTemplate();
     $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
     if ($uid) {
         // Send HUB message
         if (Event::trigger('xmessage.onSendMessage', array('projects_member_added', $subject, $message, $from, array($uid), $option))) {
             return true;
         }
     } else {
         if (\Components\Projects\Helpers\Html::email($email, Config::get('sitename') . ': ' . $subject, $message, $from)) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 23
0
 /**
  * Saves posted data for a new/edited forum thread post
  *
  * @return     void
  */
 public function savethread()
 {
     if (User::isGuest()) {
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode(Route::url($this->base))));
         return;
     }
     // Incoming
     $section = Request::getVar('section', '');
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     $fields = array_map('trim', $fields);
     $this->_authorize('thread', intval($fields['id']));
     $asset = 'thread';
     if ($fields['parent']) {
         //$asset = 'post';
     }
     if ($fields['id']) {
         $old = new \Components\Forum\Tables\Post($this->database);
         $old->load(intval($fields['id']));
         if ($old->created_by == User::get('id')) {
             $this->params->set('access-edit-thread', true);
         }
     }
     if ($fields['id'] && !$this->params->get('access-edit-thread') || !$fields['id'] && !$this->params->get('access-create-thread')) {
         App::redirect(Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=forum'), Lang::txt('PLG_GROUPS_FORUM_NOT_AUTHORIZED'), 'warning');
         return;
     }
     $fields['sticky'] = isset($fields['sticky']) ? $fields['sticky'] : 0;
     $fields['closed'] = isset($fields['closed']) ? $fields['closed'] : 0;
     // Bind data
     $model = new \Components\Forum\Tables\Post($this->database);
     if (!$model->bind($fields)) {
         $this->addPluginMessage($model->getError(), 'error');
         return $this->editthread($model);
     }
     if (!$model->anonymous) {
         $model->anonymous = 0;
     }
     // Check content
     if (!$model->check()) {
         $this->addPluginMessage($model->getError(), 'error');
         return $this->editthread($model);
     }
     // Store new content
     if (!$model->store()) {
         $this->addPluginMessage($model->getError(), 'error');
         return $this->editthread($model);
     }
     $parent = $model->parent ? $model->parent : $model->id;
     //update
     $this->upload($parent, $model->id);
     if ($fields['id']) {
         if ($old->category_id != $fields['category_id']) {
             $model->updateReplies(array('category_id' => $fields['category_id']), $model->id);
         }
     }
     $category = new \Components\Forum\Tables\Category($this->database);
     $category->load(intval($model->category_id));
     $sectionTbl = new \Components\Forum\Tables\Section($this->database);
     $sectionTbl->load(intval($category->section_id));
     $tags = Request::getVar('tags', '', 'post');
     $tagger = new \Components\Forum\Models\Tags($model->id);
     $tagger->setTags($tags, User::get('id'));
     // Determine post save message
     // Also, get subject of post for outgoing email, either the title of parent post (for replies), or title of current post (for new threads)
     if (!$fields['parent']) {
         $message = Lang::txt('PLG_GROUPS_FORUM_THREAD_STARTED');
         $posttitle = $model->title;
     } else {
         $message = Lang::txt('PLG_GROUPS_FORUM_POST_ADDED');
         $parentForumTablePost = new \Components\Forum\Tables\Post($this->database);
         $parentForumTablePost->load(intval($fields['parent']));
         $posttitle = $parentForumTablePost->title;
     }
     if ($fields['id']) {
         $message = $model->modified_by ? Lang::txt('PLG_GROUPS_FORUM_POST_EDITED') : Lang::txt('PLG_GROUPS_FORUM_POST_ADDED');
     }
     // Determine route
     if ($model->parent) {
         $thread = $model->thread;
     } else {
         $thread = $model->id;
     }
     $params = Component::params('com_groups');
     // Email the group and insert email tokens to allow them to respond to group posts via email
     if ($params->get('email_comment_processing')) {
         $esection = new \Components\Forum\Models\Section($sectionTbl);
         $ecategory = new \Components\Forum\Models\Category($category);
         $ecategory->set('section_alias', $esection->get('alias'));
         $ethread = new \Components\Forum\Models\Thread(intval($thread));
         $ethread->set('section', $esection->get('alias'));
         $ethread->set('category', $ecategory->get('alias'));
         $epost = new \Components\Forum\Models\Thread($model);
         $epost->set('section', $esection->get('alias'));
         $epost->set('category', $ecategory->get('alias'));
         // Figure out who should be notified about this comment (all group members for now)
         $userIDsToEmail = array();
         foreach ($this->members as $mbr) {
             //Look up user info
             $user = User::getInstance($mbr);
             if ($user->get('id')) {
                 include_once PATH_CORE . DS . 'plugins' . DS . 'groups' . DS . 'memberoptions' . DS . 'memberoption.class.php';
                 // Find the user's group settings, do they want to get email (0 or 1)?
                 $groupMemberOption = new GroupsTableMemberoption($this->database);
                 $groupMemberOption->loadRecord($this->group->get('gidNumber'), $user->get('id'), GROUPS_MEMBEROPTION_TYPE_DISCUSSION_NOTIFICIATION);
                 $sendEmail = 0;
                 if ($groupMemberOption->id) {
                     $sendEmail = $groupMemberOption->optionvalue;
                 }
                 if ($sendEmail == 1) {
                     $userIDsToEmail[] = $user->get('id');
                 }
             }
         }
         $encryptor = new \Hubzero\Mail\Token();
         $from = array('name' => Config::get('sitename'), 'email' => Config::get('mailfrom'));
         // Email each group member separately, each needs a user specific token
         foreach ($userIDsToEmail as $userID) {
             // Construct User specific Email ThreadToken
             // Version, type, userid, xforumid
             $token = $encryptor->buildEmailToken(1, 2, $userID, $parent);
             // add unsubscribe link
             $unsubscribeToken = $encryptor->buildEmailToken(1, 3, $userID, $this->group->get('gidNumber'));
             $unsubscribeLink = rtrim(Request::base(), '/') . '/' . ltrim(Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=forum&action=unsubscribe&t=' . $unsubscribeToken), DS);
             $msg = array();
             // create view object
             $eview = new \Hubzero\Mail\View(array('base_path' => __DIR__, 'name' => 'email', 'layout' => 'comment_plain'));
             // plain text
             $eview->set('delimiter', '~!~!~!~!~!~!~!~!~!~!')->set('unsubscribe', $unsubscribeLink)->set('group', $this->group)->set('section', $esection)->set('category', $ecategory)->set('thread', $ethread)->set('post', $epost);
             $plain = $eview->loadTemplate(false);
             $msg['plaintext'] = str_replace("\n", "\r\n", $plain);
             // HTML
             $eview->setLayout('comment_html');
             $html = $eview->loadTemplate();
             $msg['multipart'] = str_replace("\n", "\r\n", $html);
             $subject = ' - ' . $this->group->get('cn') . ' - ' . $posttitle;
             $from['replytoemail'] = 'hgm-' . $token . '@' . $_SERVER['HTTP_HOST'];
             if (!Event::trigger('xmessage.onSendMessage', array('group_message', $subject, $msg, $from, array($userID), $this->option, null, '', $this->group->get('gidNumber')))) {
                 $this->setError(Lang::txt('GROUPS_ERROR_EMAIL_MEMBERS_FAILED'));
             }
         }
     }
     // Set the redirect
     App::redirect(Route::url($this->base . '&scope=' . $section . '/' . $category->alias . '/' . $thread), $message, 'passed');
 }
Exemplo n.º 24
0
 /**
  * Saves changes to a ticket, adds a new comment/changelog,
  * notifies any relevant parties
  *
  * @return void
  */
 public function saveTask($redirect = 1)
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $isNew = true;
     $id = Request::getInt('id', 0);
     if ($id) {
         $isNew = false;
     }
     // Load the old ticket so we can compare for the changelog
     $old = new Ticket($id);
     $old->set('tags', $old->tags('string'));
     // Initiate class and bind posted items to database fields
     $row = new Ticket($id);
     if (!$row->bind($_POST)) {
         throw new Exception($row->getError(), 500);
     }
     if ($row->get('target_date') && $row->get('target_date') != '0000-00-00 00:00:00') {
         $row->set('target_date', Date::of($row->get('target_date'), Config::get('offset'))->toSql());
     } else {
         $row->set('target_date', '0000-00-00 00:00:00');
     }
     $comment = Request::getVar('comment', '', 'post', 'none', 2);
     $rowc = new Comment();
     $rowc->set('ticket', $id);
     // Check if changes were made inbetween the time the comment was started and posted
     if ($id) {
         $started = Request::getVar('started', Date::toSql(), 'post');
         $lastcomment = $row->comments('list', array('sort' => 'created', 'sort_Dir' => 'DESC', 'limit' => 1, 'start' => 0, 'ticket' => $id))->first();
         if (isset($lastcomment) && $lastcomment->created() >= $started) {
             $rowc->set('comment', $comment);
             \Notify::error(Lang::txt('Changes were made to this ticket in the time since you began commenting/making changes. Please review your changes before submitting.'));
             return $this->editTask($rowc);
         }
     }
     if ($id && isset($_POST['status']) && $_POST['status'] == 0) {
         $row->set('open', 0);
         $row->set('resolved', Lang::txt('COM_SUPPORT_TICKET_COMMENT_OPT_CLOSED'));
     }
     $row->set('open', $row->status('open'));
     // If an existing ticket AND closed AND previously open
     if ($id && !$row->get('open') && $row->get('open') != $old->get('open')) {
         // Record the closing time
         $row->set('closed', Date::toSql());
     }
     // Check content
     if (!$row->check()) {
         throw new Exception($row->getError(), 500);
     }
     // Store new content
     if (!$row->store()) {
         throw new Exception($row->getError(), 500);
     }
     // Save the tags
     $row->tag(Request::getVar('tags', '', 'post'), User::get('id'), 1);
     $row->set('tags', $row->tags('string'));
     $base = Request::base();
     if (substr($base, -14) == 'administrator/') {
         $base = substr($base, 0, strlen($base) - 14);
     }
     $webpath = trim($this->config->get('webpath'), '/');
     $allowEmailResponses = $this->config->get('email_processing');
     $this->config->set('email_terse', Request::getInt('email_terse', 0));
     if ($this->config->get('email_terse')) {
         $allowEmailResponses = false;
     }
     if ($allowEmailResponses) {
         try {
             $encryptor = new \Hubzero\Mail\Token();
         } catch (Exception $e) {
             $allowEmailResponses = false;
         }
     }
     // If a new ticket...
     if ($isNew) {
         // Get any set emails that should be notified of ticket submission
         $defs = explode(',', $this->config->get('emails', '{config.mailfrom}'));
         if ($defs) {
             // Get some email settings
             $msg = new \Hubzero\Mail\Message();
             $msg->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_SUPPORT') . ', ' . Lang::txt('COM_SUPPORT_TICKET_NUMBER', $row->get('id')));
             $msg->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_option)));
             // Plain text email
             $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . $this->_option . DS . 'site', 'name' => 'emails', 'layout' => 'ticket_plain'));
             $eview->option = $this->_option;
             $eview->controller = $this->_controller;
             $eview->ticket = $row;
             $eview->config = $this->config;
             $eview->delimiter = '';
             $plain = $eview->loadTemplate(false);
             $plain = str_replace("\n", "\r\n", $plain);
             $msg->addPart($plain, 'text/plain');
             // HTML email
             $eview->setLayout('ticket_html');
             $html = $eview->loadTemplate();
             $html = str_replace("\n", "\r\n", $html);
             if (!$this->config->get('email_terse')) {
                 foreach ($row->attachments() as $attachment) {
                     if ($attachment->size() < 2097152) {
                         if ($attachment->isImage()) {
                             $file = basename($attachment->link('filepath'));
                             $html = preg_replace('/<a class="img" data\\-filename="' . str_replace('.', '\\.', $file) . '" href="(.*?)"\\>(.*?)<\\/a>/i', '<img src="' . $message->getEmbed($attachment->link('filepath')) . '" alt="" />', $html);
                         } else {
                             $message->addAttachment($attachment->link('filepath'));
                         }
                     }
                 }
             }
             $msg->addPart($html, 'text/html');
             // Loop through the addresses
             foreach ($defs as $def) {
                 $def = trim($def);
                 // Check if the address should come from Joomla config
                 if ($def == '{config.mailfrom}') {
                     $def = Config::get('mailfrom');
                 }
                 // Check for a valid address
                 if (Validate::email($def)) {
                     // Send e-mail
                     $msg->setTo(array($def));
                     $msg->send();
                 }
             }
         }
     }
     // Incoming comment
     if ($comment) {
         // If a comment was posted by the ticket submitter to a "waiting user response" ticket, change status.
         if ($row->isWaiting() && User::get('username') == $row->get('login')) {
             $row->open();
         }
     }
     // Create a new support comment object and populate it
     $access = Request::getInt('access', 0);
     //$rowc = new Comment();
     $rowc->set('ticket', $row->get('id'));
     $rowc->set('comment', nl2br($comment));
     $rowc->set('created', Date::toSql());
     $rowc->set('created_by', User::get('id'));
     $rowc->set('access', $access);
     // Compare fields to find out what has changed for this ticket and build a changelog
     $rowc->changelog()->diff($old, $row);
     $rowc->changelog()->cced(Request::getVar('cc', ''));
     // Save the data
     if (!$rowc->store()) {
         throw new Exception($rowc->getError(), 500);
     }
     Event::trigger('support.onTicketUpdate', array($row, $rowc));
     if ($tmp = Request::getInt('tmp_dir')) {
         $attach = new Tables\Attachment($this->database);
         $attach->updateCommentId($tmp, $rowc->get('id'));
     }
     if (!$isNew) {
         $attachment = $this->uploadTask($row->get('id'), $rowc->get('id'));
     }
     // Only do the following if a comment was posted or ticket was reassigned
     // otherwise, we're only recording a changelog
     if ($rowc->get('comment') || $row->get('owner') != $old->get('owner') || $row->get('group') != $old->get('group') || $rowc->attachments()->total() > 0) {
         // Send e-mail to ticket submitter?
         if (Request::getInt('email_submitter', 0) == 1) {
             // Is the comment private? If so, we do NOT send e-mail to the
             // submitter regardless of the above setting
             if (!$rowc->isPrivate()) {
                 $rowc->addTo(array('role' => Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_SUBMITTER'), 'name' => $row->submitter('name'), 'email' => $row->submitter('email'), 'id' => $row->submitter('id')));
             }
         }
         // Send e-mail to ticket owner?
         if (Request::getInt('email_owner', 0) == 1) {
             if ($old->get('owner') && $row->get('owner') != $old->get('owner')) {
                 $rowc->addTo(array('role' => Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_PRIOR_OWNER'), 'name' => $old->owner('name'), 'email' => $old->owner('email'), 'id' => $old->owner('id')));
             }
             if ($row->get('owner')) {
                 $rowc->addTo(array('role' => Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_OWNER'), 'name' => $row->owner('name'), 'email' => $row->owner('email'), 'id' => $row->owner('id')));
             } elseif ($row->get('group')) {
                 $group = \Hubzero\User\Group::getInstance($row->get('group'));
                 if ($group) {
                     foreach ($group->get('managers') as $manager) {
                         $manager = User::getInstance($manager);
                         if (!$manager || !$manager->get('id')) {
                             continue;
                         }
                         $rowc->addTo(array('role' => Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_GROUPMANAGER'), 'name' => $manager->get('name'), 'email' => $manager->get('email'), 'id' => $manager->get('id')));
                     }
                 }
             }
         }
         // Add any CCs to the e-mail list
         foreach ($rowc->changelog()->get('cc') as $cc) {
             $rowc->addTo($cc, Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_CC'));
         }
         // Message people watching this ticket,
         // but ONLY if the comment was NOT marked private
         $this->acl = ACL::getACL();
         foreach ($row->watchers() as $watcher) {
             $this->acl->setUser($watcher->user_id);
             if (!$rowc->isPrivate() || $rowc->isPrivate() && $this->acl->check('read', 'private_comments')) {
                 $rowc->addTo($watcher->user_id, 'watcher');
             }
         }
         $this->acl->setUser(User::get('id'));
         if (count($rowc->to())) {
             // Build e-mail components
             $subject = Lang::txt('COM_SUPPORT_EMAIL_SUBJECT_TICKET_COMMENT', $row->get('id'));
             $from = array('name' => Lang::txt('COM_SUPPORT_EMAIL_FROM', Config::get('sitename')), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U')));
             // Plain text email
             $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . $this->_option . DS . 'site', 'name' => 'emails', 'layout' => 'comment_plain'));
             $eview->option = $this->_option;
             $eview->controller = $this->_controller;
             $eview->comment = $rowc;
             $eview->ticket = $row;
             $eview->config = $this->config;
             $eview->delimiter = $allowEmailResponses ? '~!~!~!~!~!~!~!~!~!~!' : '';
             $message['plaintext'] = $eview->loadTemplate(false);
             $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
             // HTML email
             $eview->setLayout('comment_html');
             $message['multipart'] = $eview->loadTemplate();
             $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
             $message['attachments'] = array();
             if (!$this->config->get('email_terse')) {
                 foreach ($rowc->attachments() as $attachment) {
                     if ($attachment->size() < 2097152) {
                         $message['attachments'][] = $attachment->link('filepath');
                     }
                 }
             }
             // Send e-mail to admin?
             foreach ($rowc->to('ids') as $to) {
                 if ($allowEmailResponses) {
                     // The reply-to address contains the token
                     $token = $encryptor->buildEmailToken(1, 1, $to['id'], $id);
                     $from['replytoemail'] = 'htc-' . $token . strstr(Config::get('mailfrom'), '@');
                 }
                 // Get the user's email address
                 if (!Event::trigger('xmessage.onSendMessage', array('support_reply_submitted', $subject, $message, $from, array($to['id']), $this->_option))) {
                     $this->setError(Lang::txt('COM_SUPPORT_ERROR_FAILED_TO_MESSAGE', $to['name'] . '(' . $to['role'] . ')'));
                 }
                 // Watching should be anonymous
                 if ($to['role'] == 'watcher') {
                     continue;
                 }
                 $rowc->changelog()->notified($to['role'], $to['name'], $to['email']);
             }
             foreach ($rowc->to('emails') as $to) {
                 if ($allowEmailResponses) {
                     $token = $encryptor->buildEmailToken(1, 1, -9999, $id);
                     $email = array($to['email'], 'htc-' . $token . strstr(Config::get('mailfrom'), '@'));
                     // In this case each item in email in an array, 1- To, 2:reply to address
                     Utilities::sendEmail($email[0], $subject, $message, $from, $email[1]);
                 } else {
                     // Email is just a plain 'ol string
                     Utilities::sendEmail($to['email'], $subject, $message, $from);
                 }
                 // Watching should be anonymous
                 if ($to['role'] == 'watcher') {
                     continue;
                 }
                 $rowc->changelog()->notified($to['role'], $to['name'], $to['email']);
             }
         } else {
             // Force entry to private if no comment or attachment was made
             if (!$rowc->get('comment') && $rowc->attachments()->total() <= 0) {
                 $rowc->set('access', 1);
             }
         }
         // Were there any changes?
         if (count($rowc->changelog()->get('notifications')) > 0 || $access != $rowc->get('access')) {
             // Save the data
             if (!$rowc->store()) {
                 throw new Exception($rowc->getError(), 500);
             }
         }
     }
     // output messsage and redirect
     if ($redirect) {
         $filters = Request::getVar('filters', '');
         $filters = str_replace('&amp;', '&', $filters);
         // Redirect
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . ($filters ? '&' . $filters : ''), false), Lang::txt('COM_SUPPORT_TICKET_SUCCESSFULLY_SAVED', $row->get('id')));
         return;
     }
     $this->view->setLayout('edit');
     $this->editTask();
 }
Exemplo n.º 25
0
 /**
  * Send email
  *
  * @param      object 	$publication   Models\Publication
  * @param      array 	$addressees
  * @param      string 	$subject
  * @param      string 	$message
  * @return     void
  */
 public static function notify($publication, $addressees = array(), $subject = NULL, $message = NULL, $hubMessage = false)
 {
     if (!$subject || !$message || empty($addressees)) {
         return false;
     }
     // Is messaging turned on?
     if ($publication->config('email') != 1) {
         return false;
     }
     // Component params
     $params = Component::params('com_publications');
     $address = $params->get('curatorreplyto');
     // Set up email config
     $from = array();
     $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_PUBLICATIONS');
     if (!isset($address) || $address == '') {
         $from['email'] = Config::get('mailfrom');
     } else {
         $from['email'] = $address;
     }
     // Html email
     $from['multipart'] = md5(date('U'));
     // Get message body
     $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'site', 'name' => 'emails', 'layout' => '_plain'));
     $eview->publication = $publication;
     $eview->message = $message;
     $eview->subject = $subject;
     $body = array();
     $body['plaintext'] = $eview->loadTemplate(false);
     $body['plaintext'] = str_replace("\n", "\r\n", $body['plaintext']);
     // HTML email
     $eview->setLayout('_html');
     $body['multipart'] = $eview->loadTemplate();
     $body['multipart'] = str_replace("\n", "\r\n", $body['multipart']);
     $body_plain = is_array($body) && isset($body['plaintext']) ? $body['plaintext'] : $body;
     $body_html = is_array($body) && isset($body['multipart']) ? $body['multipart'] : NULL;
     // Send HUB message
     if ($hubMessage) {
         Event::trigger('xmessage.onSendMessage', array('publication_status_changed', $subject, $body, $from, $addressees, 'com_publications'));
     } else {
         // Send email
         foreach ($addressees as $userid) {
             $user = User::getInstance(trim($userid));
             if (!$user->get('id')) {
                 continue;
             }
             $mail = new \Hubzero\Mail\Message();
             $mail->setSubject($subject)->addTo($user->get('email'), $user->get('name'))->addFrom($from['email'], $from['name'])->setPriority('normal');
             $mail->addPart($body_plain, 'text/plain');
             if ($body_html) {
                 $mail->addPart($body_html, 'text/html');
             }
             $mail->send();
         }
     }
 }
Exemplo n.º 26
0
 /**
  * Save an answer (reply to question)
  *
  * @return  void
  */
 public function saveaTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Login required
     if (User::isGuest()) {
         $this->setError(Lang::txt('COM_ANSWERS_PLEASE_LOGIN'));
         return $this->loginTask();
     }
     // Incoming
     $response = Request::getVar('response', array(), 'post', 'none', 2);
     // clean input
     array_walk($response, function (&$field, $key) {
         $field = \Hubzero\Utility\Sanitize::clean($field);
     });
     // Initiate class and bind posted items to database fields
     $row = Response::oneOrNew($response['id'])->set($response);
     // Store new content
     if (!$row->save()) {
         App::abort(500, $row->getError());
     }
     // Load the question
     $question = Question::oneOrFail($row->get('question_id'));
     // Build the "from" info
     $from = array('email' => Config::get('mailfrom'), 'name' => Config::get('sitename') . ' ' . Lang::txt('COM_ANSWERS_ANSWERS'), 'multipart' => md5(date('U')));
     // Build the message subject
     $subject = Config::get('sitename') . ' ' . Lang::txt('COM_ANSWERS_ANSWERS') . ', ' . Lang::txt('COM_ANSWERS_QUESTION') . ' #' . $question->get('id') . ' ' . Lang::txt('COM_ANSWERS_RESPONSE');
     $message = array();
     // Plain text message
     $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'response_plaintext'));
     $eview->option = $this->_option;
     $eview->sitename = Config::get('sitename');
     $eview->question = $question;
     $eview->row = $row;
     $eview->id = $response['question_id'];
     $eview->boundary = $from['multipart'];
     $message['plaintext'] = $eview->loadTemplate(false);
     $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
     // HTML message
     $eview->setLayout('response_html');
     $message['multipart'] = $eview->loadTemplate();
     $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
     // ---
     $authorid = $question->get('created_by');
     $receivers = $this->recipients();
     // Send the message
     if (!in_array($authorid, $receivers) && $question->get('email')) {
         // Flag to mask identity of anonymous question asker
         // MCRN Ticket #134
         if ($question->get('anonymous') == '1') {
             $messageType = 'answers_reply_submitted_anonymous';
         } else {
             $messageType = 'answers_reply_submitted';
         }
         if (!Event::trigger('xmessage.onSendMessage', array($messageType, $subject, $message, $from, array($authorid), $this->_option))) {
             $this->setError(Lang::txt('COM_ANSWERS_MESSAGE_FAILED'));
         }
     }
     // Send the answers admins message
     if (!empty($receivers)) {
         if (!Event::trigger('xmessage.onSendMessage', array('new_answer_admin', $subject, $message, $from, $receivers, $this->_option))) {
             $this->setError(Lang::txt('COM_ANSWERS_MESSAGE_FAILED'));
         }
     }
     // Log activity
     $recipients = array($row->get('created_by'));
     if ($row->get('created_by') != $question->get('created_by')) {
         $recipients[] = $question->get('created_by');
     }
     $recipients = $this->recipients($recipients);
     Event::trigger('system.logActivity', ['activity' => ['action' => $response['id'] ? 'updated' : 'created', 'scope' => 'question.answer', 'scope_id' => $row->get('id'), 'description' => Lang::txt('COM_ANSWERS_ACTIVITY_ANSWER_SUBMITTED', '<a href="' . Route::url($question->link() . '#a' . $row->get('id')) . '">' . $question->get('subject') . '</a>'), 'details' => array('title' => $question->get('title'), 'question_id' => $question->get('id'), 'url' => $question->link())], 'recipients' => $recipients]);
     // Redirect to the question
     App::redirect(Route::url($question->link()), Lang::txt('COM_ANSWERS_NOTICE_POSTED_THANKS'), 'success');
 }
Exemplo n.º 27
0
 /**
  * Method to parse and send invites
  *
  * @return  void
  */
 public function doinviteTask()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask(Lang::txt('COM_GROUPS_INVITE_MUST_BE_LOGGED_IN'));
         return;
     }
     Request::checkToken();
     //check to make sure we have  cname
     if (!$this->cn) {
         $this->_errorHandler(400, Lang::txt('COM_GROUPS_ERROR_NO_ID'));
     }
     // Load the group page
     $this->view->group = Group::getInstance($this->cn);
     // Ensure we found the group info
     if (!$this->view->group || !$this->view->group->get('gidNumber')) {
         $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND'));
     }
     // Check authorization
     if ($this->_authorize() != 'manager' && !$this->_authorizedForTask('group.invite')) {
         $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH'));
     }
     //get request vars
     $logins = trim(Request::getVar('logins', ''));
     $msg = trim(Request::getVar('msg', ''));
     if (!$logins) {
         $this->setNotification(Lang::txt('COM_GROUPS_INVITE_MUST_ENTER_DATA'), 'error');
         $this->inviteTask();
         return;
     }
     // Get all the group's members
     $members = $this->view->group->get('members');
     $applicants = $this->view->group->get('applicants');
     $current_invitees = $this->view->group->get('invitees');
     // Get invite emails
     $group_inviteemails = new \Hubzero\User\Group\InviteEmail();
     $current_inviteemails = $group_inviteemails->getInviteEmails($this->view->group->get('gidNumber'), true);
     //vars needed
     $invitees = array();
     $inviteemails = array();
     $badentries = array();
     $apps = array();
     $mems = array();
     // Explode the string of logins/e-mails into an array
     $la = preg_split("/[,;]/", $logins);
     $la = array_map('trim', $la);
     // turn usernames into proper IDs
     foreach ($la as $k => $l) {
         // ignore uids & email addresses
         if (!is_numeric($l) && strpos($l, '@') === false) {
             // load by username
             $profile = User::getInstance($l);
             if ($profile && $profile->get('id')) {
                 unset($la[$k]);
                 $la[] = $profile->get('id');
             }
         }
     }
     // handle each entered
     foreach ($la as $l) {
         // If it was a user id
         if (is_numeric($l)) {
             $user = User::getInstance($l);
             $uid = $user->get('id');
             // Ensure we found an account
             if ($uid != '') {
                 // If not a member
                 if (!in_array($uid, $members) && !in_array($uid, $current_invitees)) {
                     // If an applicant
                     // Make applicant a member
                     if (in_array($uid, $applicants)) {
                         $apps[] = $uid;
                         $mems[] = $uid;
                     } else {
                         $invitees[] = $uid;
                     }
                 } else {
                     $badentries[] = array($uid, Lang::txt('COM_GROUPS_INVITE_USER_IS_ALREADY_MEMBER'));
                 }
             }
         } else {
             require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'helpers' . DS . 'utility.php';
             // If not a userid check if proper email
             if (\Components\Members\Helpers\Utility::validemail($l)) {
                 // Try to find an account that might match this e-mail
                 $this->database->setQuery("SELECT u.id FROM `#__users` AS u WHERE u.email=" . $this->database->quote($l) . " OR u.email LIKE " . $this->database->quote($l . '%') . " LIMIT 1;");
                 $uid = $this->database->loadResult();
                 if (!$this->database->query()) {
                     $this->setNotification($this->database->getErrorMsg(), 'error');
                 }
                 // If we found an ID, add it to the invitees list
                 if ($uid) {
                     // Check if user is already member or invitee
                     // Check if applicant remove from applicants and add as member
                     // Check if in current email invitee if not add a new email invite
                     if (in_array($uid, $members) || in_array($uid, $current_invitees)) {
                         $badentries[] = array($uid, Lang::txt('COM_GROUPS_INVITE_USER_IS_ALREADY_MEMBER'));
                     } elseif (in_array($uid, $applicants)) {
                         $apps[] = $uid;
                         $mems[] = $uid;
                     } else {
                         $invitees[] = $uid;
                     }
                 } else {
                     if (!in_array($l, $current_inviteemails)) {
                         $inviteemails[] = array('email' => $l, 'gidNumber' => $this->view->group->get('gidNumber'), 'token' => $this->_randomString(32));
                     } else {
                         $badentries[] = array($l, Lang::txt('COM_GROUPS_INVITE_EMAIL_ALREADY_INVITED'));
                     }
                 }
             } else {
                 $badentries[] = array($l, Lang::txt('COM_GROUPS_INVITE_EMAIL_NOT_VALID'));
             }
         }
     }
     // Add the users to the invitee list and save
     $this->view->group->remove('applicants', $apps);
     $this->view->group->add('members', $mems);
     $this->view->group->add('invitees', $invitees);
     $this->view->group->update();
     // Add the inviteemails
     foreach ($inviteemails as $ie) {
         $group_inviteemails = new \Hubzero\User\Group\InviteEmail();
         $group_inviteemails->set('email', $ie['email']);
         $group_inviteemails->set('gidNumber', $ie['gidNumber']);
         $group_inviteemails->set('token', $ie['token']);
         $group_inviteemails->save();
     }
     // log invites
     Log::log(array('gidNumber' => $this->view->group->get('gidNumber'), 'action' => 'membership_invites_sent', 'comments' => array_merge($invitees, $inviteemails)));
     // Build the "from" info for e-mails
     $from = array('name' => Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_name)), 'email' => Config::get('mailfrom'));
     // Message subject
     $subject = Lang::txt('COM_GROUPS_INVITE_EMAIL_SUBJECT', $this->view->group->get('cn'));
     // Message body for HUB user
     $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'invite_plain'));
     $eview->option = $this->_option;
     $eview->sitename = Config::get('sitename');
     $eview->user = User::getInstance();
     $eview->group = $this->view->group;
     $eview->msg = $msg;
     $plain = $eview->loadTemplate(false);
     $plain = str_replace("\n", "\r\n", $plain);
     $eview->setLayout('invite');
     $html = $eview->loadTemplate();
     $html = str_replace("\n", "\r\n", $html);
     // build array of group invites to send
     $groupInvitees = array();
     $activity = array();
     foreach ($invitees as $invitee) {
         if ($profile = User::getInstance($invitee)) {
             $groupInvitees[$profile->get('email')] = $profile->get('name');
             $activity[] = $profile->get('name') . '(' . $profile->get('email') . ')';
         }
     }
     // only email regular invitees if we have any
     if (count($groupInvitees) > 0) {
         // create new message
         $message = new \Hubzero\Mail\Message();
         // build message object and send
         $message->setSubject($subject)->addFrom($from['email'], $from['name'])->setTo($groupInvitees)->addHeader('X-Mailer', 'PHP/' . phpversion())->addHeader('X-Component', 'com_groups')->addHeader('X-Component-Object', 'group_invite')->addPart($plain, 'text/plain')->addPart($html, 'text/html')->send();
     }
     // Log activity
     $url = Route::url('index.php?option=' . $this->_option . '&cn=' . $this->view->group->get('cn'));
     foreach ($invitees as $invitee) {
         Event::trigger('system.logActivity', ['activity' => ['action' => 'invited', 'scope' => 'group', 'scope_id' => $this->view->group->get('gidNumber'), 'description' => Lang::txt('COM_GROUPS_ACTIVITY_GROUP_USER_INVITED', '<a href="' . $url . '">' . $this->view->group->get('description') . '</a>'), 'details' => array('title' => $this->view->group->get('description'), 'url' => $url, 'cn' => $this->view->group->get('cn'), 'gidNumber' => $this->view->group->get('gidNumber'))], 'recipients' => array(['user', $invitee])]);
     }
     $recipients = array(['group', $this->view->group->get('gidNumber')], ['user', User::get('id')]);
     foreach ($this->view->group->get('managers') as $recipient) {
         $recipients[] = ['user', $recipient];
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => 'invited', 'scope' => 'group', 'scope_id' => $this->view->group->get('gidNumber'), 'description' => Lang::txt('COM_GROUPS_ACTIVITY_GROUP_USERS_INVITED', implode(', ', $activity), '<a href="' . $url . '">' . $this->view->group->get('description') . '</a>'), 'details' => array('title' => $this->view->group->get('description'), 'url' => $url, 'cn' => $this->view->group->get('cn'), 'gidNumber' => $this->view->group->get('gidNumber'))], 'recipients' => $recipients]);
     // send message to users invited via email
     foreach ($inviteemails as $mbr) {
         // Message body for HUB user
         $eview2 = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'inviteemail_plain'));
         $eview2->option = $this->_option;
         $eview2->sitename = Config::get('sitename');
         $eview2->user = User::getInstance();
         $eview2->group = $this->view->group;
         $eview2->msg = $msg;
         $eview2->token = $mbr['token'];
         $plain = $eview2->loadTemplate(false);
         $plain = str_replace("\n", "\r\n", $plain);
         $eview2->setLayout('inviteemail');
         $html = $eview2->loadTemplate();
         $html = str_replace("\n", "\r\n", $html);
         // create new message
         $message = new \Hubzero\Mail\Message();
         // build message object and send
         $message->setSubject($subject)->addFrom($from['email'], $from['name'])->setTo(array($mbr['email']))->addHeader('X-Mailer', 'PHP/' . phpversion())->addHeader('X-Component', 'com_groups')->addHeader('X-Component-Object', 'group_inviteemail')->addPart($plain, 'text/plain')->addPart($html, 'text/html')->send();
     }
     // Push all invitees together
     $all_invites = array_merge($invitees, $inviteemails);
     // Declare success/error message vars
     $success_message = '';
     $error_message = '';
     if (count($all_invites) > 0) {
         $success_message = Lang::txt('COM_GROUPS_INVITE_SUCCESS_MESSAGE');
         foreach ($all_invites as $invite) {
             if (is_numeric($invite)) {
                 $user = User::getInstance($invite);
                 $success_message .= ' - ' . $user->get('name') . '<br />';
             } else {
                 $success_message .= ' - ' . $invite['email'] . '<br />';
             }
         }
     }
     if (count($badentries) > 0) {
         $error_message = Lang::txt('COM_GROUPS_INVITE_ERROR_MESSAGE');
         foreach ($badentries as $entry) {
             if (is_numeric($entry[0])) {
                 $user = User::getInstance($entry[0]);
                 if ($user->get('name') != '') {
                     $error_message .= ' - ' . $user->get('name') . ' &rarr; ' . $entry[1] . '<br />';
                 } else {
                     $error_message .= ' - ' . $entry[0] . ' &rarr; ' . $entry[1] . '<br />';
                 }
             } else {
                 $error_message .= ' - ' . $entry[0] . ' &rarr; ' . $entry[1] . '<br />';
             }
         }
     }
     // Push some notifications to the view
     $this->setNotification($success_message, 'passed');
     $this->setNotification($error_message, 'error');
     // Redirect back to view group
     App::redirect($url);
 }
Exemplo n.º 28
0
 /**
  * Save a wish comment
  *
  * @return     void
  */
 public function savereplyTask()
 {
     Request::checkToken();
     // Incoming
     $id = Request::getInt('referenceid', 0);
     $listid = Request::getInt('listid', 0);
     $wishid = Request::getInt('wishid', 0);
     $ajax = Request::getInt('ajax', 0);
     $category = Request::getVar('cat', '');
     $when = Date::toSql();
     // Get wishlist info
     $wishlist = Wishlist::getInstance($listid);
     if (!$wishlist->exists()) {
         throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISHLIST_NOT_FOUND'), 404);
     }
     $objWish = new Wish($wishid);
     // Get List Title
     $this->_list_title = $wishlist->get('title');
     // Build page title
     $this->_buildTitle();
     // Set the pathway
     $this->_buildPathway($wishlist);
     if (!$id && !$ajax) {
         // cannot proceed
         throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISH_NOT_FOUND'), 404);
     }
     // is the user logged in?
     if (User::isGuest()) {
         $this->_msg = Lang::txt('COM_WISHLIST_WARNING_LOGIN_TO_ADD_COMMENT');
         $this->loginTask();
         return;
     }
     if ($id && $category) {
         $row = new Comment();
         if (!$row->bind($_POST)) {
             throw new Exception($row->getError(), 500);
         }
         // Perform some text cleaning, etc.
         $row->set('content', $row->get('content') == Lang::txt('COM_WISHLIST_ENTER_COMMENTS') ? '' : $row->get('content'));
         if ($attachment = $this->uploadTask($wishid)) {
             $row->set('content', $row->get('content') . "\n" . $attachment);
         }
         $row->set('anonymous', $row->get('anonymous') ? $row->get('anonymous') : 0);
         $row->set('added', Date::toSql());
         $row->set('state', 0);
         $row->set('category', $category);
         $row->set('added_by', User::get('id'));
         // Save the data
         if (!$row->store(true)) {
             throw new Exception($row->getError(), 500);
         }
         // Build e-mail components
         $name = $row->creator('name', Lang::txt('UNKNOWN'));
         $login = $row->creator('username', Lang::txt('UNKNOWN'));
         if ($row->get('anonymous')) {
             $name = Lang::txt('ANONYMOUS');
         }
         $subject = Lang::txt(strtoupper($this->_option)) . ', ' . Lang::txt('COM_WISHLIST_MSG_COMENT_POSTED_YOUR_WISH') . ' #' . $wishid . ' ' . Lang::txt('BY') . ' ' . $name;
         // email components
         $from = array('name' => Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_option)), 'email' => Config::get('mailfrom'));
         // for the wish owner
         $subject1 = Lang::txt(strtoupper($this->_option)) . ', ' . $name . ' ' . Lang::txt('COM_WISHLIST_MSG_COMMENTED_YOUR_WISH') . ' #' . $wishid;
         // for the person to whom wish is assigned
         $subject2 = Lang::txt(strtoupper($this->_option)) . ', ' . $name . ' ' . Lang::txt('COM_WISHLIST_MSG_COMMENTED_ON_WISH') . ' #' . $wishid . ' ' . Lang::txt('COM_WISHLIST_MSG_ASSIGNED_TO_YOU');
         // for original commentor
         $subject3 = Lang::txt(strtoupper($this->_option)) . ', ' . $name . ' ' . Lang::txt('COM_WISHLIST_MSG_REPLIED_YOUR_COMMENT') . ' #' . $wishid;
         // for others included in the conversation thread.
         $subject4 = Lang::txt(strtoupper($this->_option)) . ', ' . $name . ' ' . Lang::txt('COM_WISHLIST_MSG_COMMENTED_AFTER_YOU') . ' #' . $wishid;
         $message = array();
         // Plain text email
         $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'comment_plain'));
         $eview->option = $this->_option;
         $eview->controller = $this->_controller;
         $eview->wish = $objWish;
         $eview->wishlist = $wishlist;
         $eview->comment = $row;
         $message['plaintext'] = $eview->loadTemplate(false);
         $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
         // HTML email
         $eview->setLayout('comment_html');
         $message['multipart'] = $eview->loadTemplate();
         $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
         // collect ids of people who were already emailed
         $contacted = array();
         if ($objWish->get('proposed_by') != $row->get('added_by')) {
             $contacted[] = $objWish->get('proposed_by');
             // send message to wish owner
             if (!Event::trigger('xmessage.onSendMessage', array('wishlist_comment_posted', $subject1, $message, $from, array($objWish->get('proposed_by')), $this->_option))) {
                 $this->setError(Lang::txt('COM_WISHLIST_ERROR_FAILED_MSG_AUTHOR'));
             }
         }
         // -- end send to wish author
         if ($objWish->get('assigned') && $objWish->get('assigned') != $row->get('added_by') && !in_array($objWish->get('assigned'), $contacted)) {
             $contacted[] = $objWish->get('assigned');
             // send message to person to who wish is assigned
             if (!Event::trigger('xmessage.onSendMessage', array('wishlist_comment_posted', $subject2, $message, $from, array($objWish->get('assigned')), $this->_option))) {
                 $this->setError(Lang::txt('COM_WISHLIST_ERROR_FAILED_MSG_ASSIGNEE'));
             }
         }
         // -- end send message to person to who wish is assigned
         // get comment author if reply is posted to a comment
         if ($category == 'wishcomment') {
             $parent = new Comment($id);
             // send message to comment author
             if ($parent->get('added_by') != $row->get('added_by') && !in_array($parent->get('added_by'), $contacted)) {
                 $contacted[] = $parent->get('added_by');
                 if (!Event::trigger('xmessage.onSendMessage', array('wishlist_comment_thread', $subject3, $message, $from, array($parent->get('added_by')), $this->_option))) {
                     $this->setError(Lang::txt('COM_WISHLIST_ERROR_FAILED_MSG_COMMENTOR'));
                 }
             }
         }
         // get all users who commented
         $commentors = $objWish->comments('authors');
         $comm = array_diff($commentors, $contacted);
         if (count($comm) > 0) {
             if (!Event::trigger('xmessage.onSendMessage', array('wishlist_comment_thread', $subject4, $message, $from, $comm, $this->_option))) {
                 $this->setError(Lang::txt('COM_WISHLIST_ERROR_FAILED_MSG_COMMENTOR'));
             }
         }
     }
     // -- end if id & category
     App::redirect(Route::url($objWish->link()));
 }
Exemplo n.º 29
0
 /**
  * Saves a project
  * Redirects to main listing
  *
  * @param   boolean  $redirect
  * @return  void
  */
 public function saveTask($redirect = false)
 {
     // Check for request forgeries
     Request::checkToken();
     // Config
     $setup_complete = $this->config->get('confirm_step', 0) ? 3 : 2;
     // Incoming
     $formdata = $_POST;
     $id = Request::getVar('id', 0);
     $action = Request::getVar('admin_action', '');
     $message = rtrim(\Hubzero\Utility\Sanitize::clean(Request::getVar('message', '')));
     // Load model
     $model = new Models\Project($id);
     if (!$model->exists()) {
         App::redirect('index.php?option=' . $this->_option, Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error');
     }
     $title = $formdata['title'] ? rtrim($formdata['title']) : $model->get('title');
     $type = isset($formdata['type']) ? $formdata['type'] : 1;
     $model->set('title', $title);
     $model->set('about', rtrim(\Hubzero\Utility\Sanitize::clean($formdata['about'])));
     $model->set('type', $type);
     $model->set('modified', Date::toSql());
     $model->set('modified_by', User::get('id'));
     $model->set('private', Request::getInt('private', 0));
     $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_SAVED');
     // Was project suspended?
     $suspended = false;
     if ($model->isInactive()) {
         $suspended = $model->table('Activity')->checkActivity($id, Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_SUSPENDED'));
     }
     $subject = Lang::txt('COM_PROJECTS_PROJECT') . ' "' . $model->get('alias') . '" ';
     $sendmail = 0;
     // Get project managers
     $managers = $model->table('Owner')->getIds($id, 1, 1);
     // Admin actions
     if ($action) {
         switch ($action) {
             case 'delete':
                 $model->set('state', 2);
                 $what = Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_DELETED');
                 $subject .= Lang::txt('COM_PROJECTS_MSG_ADMIN_DELETED');
                 $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_DELETED');
                 break;
             case 'suspend':
                 $model->set('state', 0);
                 $what = Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_SUSPENDED');
                 $subject .= Lang::txt('COM_PROJECTS_MSG_ADMIN_SUSPENDED');
                 $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_SUSPENDED');
                 break;
             case 'reinstate':
                 $model->set('state', 1);
                 $what = $suspended ? Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_REINSTATED') : Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_ACTIVATED');
                 $subject .= $suspended ? Lang::txt('COM_PROJECTS_MSG_ADMIN_REINSTATED') : Lang::txt('COM_PROJECTS_MSG_ADMIN_ACTIVATED');
                 $this->_message = $suspended ? Lang::txt('COM_PROJECTS_SUCCESS_REINSTATED') : Lang::txt('COM_PROJECTS_SUCCESS_ACTIVATED');
                 break;
         }
         // Add activity
         $model->recordActivity($what, 0, '', '', 'project', 0, $admin = 1);
         $sendmail = 1;
     } elseif ($message) {
         $subject .= ' - ' . Lang::txt('COM_PROJECTS_MSG_ADMIN_NEW_MESSAGE');
         $sendmail = 1;
         $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_MESSAGE_SENT');
     }
     // Save changes
     if (!$model->store()) {
         $this->setError($model->getError());
         return false;
     }
     // Incoming tags
     $tags = Request::getVar('tags', '', 'post');
     // Save the tags
     $cloud = new Models\Tags($model->get('id'));
     $cloud->setTags($tags, User::get('id'), 1);
     // Save params
     $incoming = Request::getVar('params', array());
     if (!empty($incoming)) {
         foreach ($incoming as $key => $value) {
             if ($key == 'quota' || $key == 'pubQuota') {
                 // convert GB to bytes
                 $value = Helpers\Html::convertSize(floatval($value), 'GB', 'b');
             }
             $model->saveParam($key, $value);
         }
     }
     // Add members if specified
     $this->model = $model;
     $this->_saveMember();
     // Change ownership
     $this->_changeOwnership();
     // Send message
     if ($this->config->get('messaging', 0) && $sendmail && count($managers) > 0) {
         // Email config
         $from = array();
         $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_PROJECTS');
         $from['email'] = Config::get('mailfrom');
         // Html email
         $from['multipart'] = md5(date('U'));
         // Message body
         $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'admin_plain'));
         $eview->option = $this->_option;
         $eview->subject = $subject;
         $eview->action = $action;
         $eview->project = $model;
         $eview->message = $message;
         $body = array();
         $body['plaintext'] = $eview->loadTemplate(false);
         $body['plaintext'] = str_replace("\n", "\r\n", $body['plaintext']);
         // HTML email
         $eview->setLayout('admin_html');
         $body['multipart'] = $eview->loadTemplate();
         $body['multipart'] = str_replace("\n", "\r\n", $body['multipart']);
         // Send HUB message
         Event::trigger('xmessage.onSendMessage', array('projects_admin_notice', $subject, $body, $from, $managers, $this->_option));
     }
     Notify::message($this->_message, 'success');
     // Redirect to edit view?
     if ($redirect) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=edit&id=' . $id, false));
     } else {
         App::redirect(Route::url('index.php?option=' . $this->_option, false));
     }
 }
Exemplo n.º 30
0
 /**
  * Send an email to a user
  * stating their account has been approved
  *
  * @param   object  $user
  * @return  bool
  */
 protected function emailApprovedUser($user)
 {
     // Compute the mail subject.
     $emailSubject = Lang::txt('COM_MEMBERS_APPROVED_USER_EMAIL_SUBJECT', $user->get('name'), Config::get('sitename'));
     // Compute the mail body.
     $eview = new \Hubzero\Mail\View(array('base_path' => dirname(dirname(__DIR__)) . DS . 'site', 'name' => 'emails', 'layout' => 'approved_plain'));
     $eview->option = $this->_option;
     $eview->controller = $this->_controller;
     $eview->config = $this->config;
     $eview->baseURL = Request::root();
     $eview->user = $user;
     $eview->sitename = Config::get('sitename');
     $plain = $eview->loadTemplate(false);
     $plain = str_replace("\n", "\r\n", $plain);
     $eview->setLayout('approved_html');
     $html = $eview->loadTemplate();
     $html = str_replace("\n", "\r\n", $html);
     // Build the message and send it
     $mail = new \Hubzero\Mail\Message();
     $mail->addFrom(Config::get('mailfrom'), Config::get('fromname'))->addTo($user->get('email'))->setSubject($emailSubject);
     $mail->addPart($plain, 'text/plain');
     $mail->addPart($html, 'text/html');
     if (!$mail->send()) {
         return false;
     }
     return true;
 }