/** * 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('&', '&', $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(); }
public function emailOrderComplete($transactionInfo) { $params = Component::params(Request::getVar('option')); $items = unserialize($transactionInfo->tiItems); //print_r($items); die; // Build emails // Build order summary $summary = 'Order number: ' . $transactionInfo->tId . "\n\n"; $summary .= "\n====================\n\n"; $summary .= 'Subtotal: ' . '$' . number_format($transactionInfo->tiSubtotal, 2) . "\n"; if (!$transactionInfo->tiShipping) { $transactionInfo->tiShipping = 0; } if ($transactionInfo->tiShipping > 0) { $summary .= 'Shipping and handling: ' . '$' . number_format($transactionInfo->tiShipping, 2) . "\n"; } if (!$transactionInfo->tiTax) { $transactionInfo->tiTax = 0; } if ($transactionInfo->tiDiscounts > 0 || $transactionInfo->tiShippingDiscount > 0) { $summary .= 'Discounts: ' . '$' . number_format($transactionInfo->tiDiscounts + $transactionInfo->tiShippingDiscount, 2) . "\n"; } if ($transactionInfo->tiTax > 0) { $summary .= 'Tax: ' . '$' . number_format($transactionInfo->tiTax, 2) . "\n"; } $summary .= 'Total: ' . '$' . number_format($transactionInfo->tiTotal, 2) . "\n"; if (!empty($transactionInfo->tiShippingToFirst)) { $summary .= "\n\nShipping address:"; $summary .= "\n--------------------\n"; $summary .= $transactionInfo->tiShippingToFirst . ' ' . $transactionInfo->tiShippingToLast . "\n"; $summary .= $transactionInfo->tiShippingAddress . "\n"; $summary .= $transactionInfo->tiShippingCity . ', ' . $transactionInfo->tiShippingState . ' ' . $transactionInfo->tiShippingZip . "\n"; } $summary .= "\n\nItems ordered:"; $summary .= "\n--------------------\n"; require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php'; $warehouse = new \Components\Storefront\Models\Warehouse(); foreach ($items as $k => $item) { $itemInfo = $item['info']; $cartInfo = $item['cartInfo']; $itemMeta = $item['meta']; //print_r($item); die; $productType = $warehouse->getProductTypeInfo($itemInfo->ptId)['ptName']; // If course, generate a link to the course $action = false; if ($productType == 'Course') { $action = ' Go to the course page at: ' . ($action .= Route::url('index.php?option=com_courses', true, -1) . $itemMeta['courseId'] . '/' . $itemMeta['offeringId']); } elseif ($productType == 'Software Download') { $action = ' Download at: ' . ($action .= Route::url('index.php?option=com_cart', true, -1) . 'download/' . $transactionInfo->tId . '/' . $itemInfo->sId); if (isset($itemMeta['serial']) && !empty($itemMeta['serial'])) { $action .= "\n\t"; $action .= " Serial number: " . $itemMeta['serial']; } } $summary .= "{$cartInfo->qty} x "; $summary .= "{$itemInfo->pName}"; if (!empty($item['options'])) { $summary .= '('; $optionCount = 0; foreach ($item['options'] as $option) { if ($optionCount) { $summary .= ', '; } $summary .= $option; $optionCount++; } $summary .= ')'; } $summary .= ' @ ' . '$' . number_format($itemInfo->sPrice, 2); if ($action) { $summary .= "\n\t"; $summary .= $action; } $summary .= "\n"; } //print_r($summary); die; // Get message plugin JPluginHelper::importPlugin('xmessage'); // "from" info $from = array(); $from['name'] = Config::get('sitename'); $from['email'] = Config::get('mailfrom'); // Email to admin $adminEmail = "There is a new online store order: \n\n"; $adminEmail .= $summary; // Admin email $to = array($params->get('storeAdminId')); Event::trigger('onSendMessage', array('store_notifications', 'New order at ' . $from['name'], $adminEmail, $from, $to, '', null, '', 0, true)); // Email to client $clientEmail = 'Thank you for your order at ' . Config::get('sitename') . "!\n\n"; $clientEmail .= $summary; require_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'Cart.php'; $to = array(\Components\Cart\Models\Cart::getCartUser($transactionInfo->crtId)); Event::trigger('onSendMessage', array('store_notifications', 'Your order at ' . $from['name'], $clientEmail, $from, $to, '', null, '', 0, true)); // Email notification extra $notifyTo = $params->get('sendNotificationTo'); if (!empty($notifyTo)) { $notifyTo = explode(',', str_replace(' ', '', $notifyTo)); $notifyEmail = 'There is a new online store order at ' . Config::get('sitename') . "\n\n"; $notifyEmail .= $summary; // Plain text email $eview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'order_notify')); $eview->option = $this->_option; $eview->controller = $this->_controller; $eview->message = $notifyEmail; $plain = $eview->loadTemplate(); $plain = str_replace("\n", "\r\n", $plain); $message = new \Hubzero\Mail\Message(); $message->setSubject('ORDER NOTIFICATION: New order at ' . $from['name']); $message->addFrom(Config::get('mailfrom'), Config::get('sitename')); $message->addPart($plain, 'text/plain'); foreach ($notifyTo as $email) { if (\Hubzero\Utility\Validate::email($email)) { $message->addTo($email); } } $message->setBody($plain); $message->send(); } }
/** * Saves a trouble report as a ticket * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); $live_site = rtrim(Request::base(), '/'); // Trigger any events that need to be called before session stop Event::trigger('support.onPreTicketSubmission', array()); // Incoming $no_html = Request::getInt('no_html', 0); $verified = Request::getInt('verified', 0); if (!isset($_POST['reporter']) || !isset($_POST['problem'])) { // This really, REALLY shouldn't happen. throw new Exception(Lang::txt('COM_SUPPORT_ERROR_MISSING_DATA'), 400); } $reporter = Request::getVar('reporter', array(), 'post', 'none', 2); $problem = Request::getVar('problem', array(), 'post', 'none', 2); //$reporter = array_map('trim', $_POST['reporter']); //$problem = array_map('trim', $_POST['problem']); // Normally calling Request::getVar calls _cleanVar, but b/c of the way this page processes the posts // (with array square brackets in the html names) against the $_POST collection, we explicitly // call the clean_var function on these arrays after fetching them //$reporter = array_map(array('Request', '_cleanVar'), $reporter); //$problem = array_map(array('Request', '_cleanVar'), $problem); // [!] zooley - Who added this? Why? // Reporter login can only be for authenticated users -- ignore any form submitted login names //$reporterLogin = $this->_getUser(); //$reporter['login'] = $reporterLogin['login']; // Probably redundant after the change to call Request::_cleanVar change above, It is a bit hard to // tell if the Joomla _cleanvar function does enough to allow us to remove the purifyText call $reporter = array_map(array('\\Hubzero\\Utility\\Sanitize', 'stripAll'), $reporter); //$problem = array_map(array('\\Hubzero\\Utility\\Sanitize', 'stripAll'), $problem); $reporter['name'] = trim($reporter['name']); $reporter['email'] = trim($reporter['email']); $problem['long'] = trim($problem['long']); // Make sure email address is valid $validemail = Validate::email($reporter['email']); // Set page title $this->_buildTitle(); $this->view->title = $this->_title; // Set the pathway $this->_buildPathway(); // Trigger any events that need to be called $customValidation = true; $result = Event::trigger('support.onValidateTicketSubmission', array($reporter, $problem)); $customValidation = is_array($result) && !empty($result) ? $result[0] : $customValidation; // Check for some required fields if (!$reporter['name'] || !$reporter['email'] || !$validemail || !$problem['long'] || !$customValidation) { Request::setVar('task', 'new'); // Output form with error messages if (!$reporter['name'] || !$reporter['email'] || !$problem['long']) { $this->setError(Lang::txt('COM_SUPPORT_ERROR_MISSING_DATA')); } if (!$validemail) { $this->setError(Lang::txt('COM_SUPPORT_ERROR_INVALID_EMAIL')); } if (!$customValidation) { $this->setError(Lang::txt('COM_SUPPORT_ERROR_INVALID_DATA')); } foreach ($this->getErrors() as $error) { $this->view->setError($error); } return $this->newTask(); } // Get the user's IP $ip = Request::ip(); $hostname = gethostbyaddr(Request::getVar('REMOTE_ADDR', '', 'server')); if (!$verified) { // Check CAPTCHA $validcaptchas = Event::trigger('support.onValidateCaptcha'); if (count($validcaptchas) > 0) { foreach ($validcaptchas as $validcaptcha) { if (!$validcaptcha) { $this->setError(Lang::txt('COM_SUPPORT_ERROR_INVALID_CAPTCHA')); } } } } // Are they verified? if (!$verified) { // Quick spam filter $spam = $this->_detectSpam($problem['long'], $ip); if ($spam) { $this->setError(Lang::txt('COM_SUPPORT_ERROR_FLAGGED_AS_SPAM')); return; } // Quick bot check $botcheck = Request::getVar('botcheck', ''); if ($botcheck) { $this->setError(Lang::txt('COM_SUPPORT_ERROR_INVALID_BOTCHECK')); return; } } // Check for errors // If any found, push back into the submission form view if ($this->getError()) { if ($no_html) { // Output error messages (AJAX) $this->view->setLayout('error'); if ($this->getError()) { $this->view->setError($this->getError()); } $this->view->display(); return; } else { Request::setVar('task', 'new'); $this->view->setError($this->getError()); return $this->newTask(); } } // Cut suggestion at 70 characters if (!$problem['short'] && $problem['long']) { $problem['short'] = substr($problem['long'], 0, 70); if (strlen($problem['short']) >= 70) { $problem['short'] .= '...'; } } $group = isset($problem['group']) ? $problem['group'] : ''; // Initiate class and bind data to database fields $row = new Ticket(); $row->set('open', 1); $row->set('status', 0); $row->set('created', Date::toSql()); $row->set('login', $reporter['login']); $row->set('severity', isset($problem['severity']) ? $problem['severity'] : 'normal'); $row->set('owner', isset($problem['owner']) ? $problem['owner'] : null); $row->set('category', isset($problem['category']) ? $problem['category'] : ''); $row->set('summary', $problem['short']); $row->set('report', $problem['long']); $row->set('resolved', isset($problem['resolved']) ? $problem['resolved'] : null); $row->set('email', $reporter['email']); $row->set('name', $reporter['name']); $row->set('os', $problem['os'] . ' ' . $problem['osver']); $row->set('browser', $problem['browser'] . ' ' . $problem['browserver']); $row->set('ip', $ip); $row->set('hostname', $hostname); $row->set('uas', Request::getVar('HTTP_USER_AGENT', '', 'server')); $row->set('referrer', base64_decode($problem['referer'])); $row->set('cookies', Request::getVar('sessioncookie', '', 'cookie') ? 1 : 0); $row->set('instances', 1); $row->set('section', 1); $row->set('group', $group); if (isset($incoming['target_date'])) { if (!$incoming['target_date']) { $row->set('target_date', '0000-00-00 00:00:00'); } else { $row->set('target_date', Date::of($incoming['target_date'], Config::get('offset'))->toSql()); } } // check if previous ticket submitted is the same as this one. $ticket = new Tables\Ticket($this->database); $filters = array('status' => 'new', 'sort' => 'id', 'sortdir' => 'DESC', 'limit' => '1', 'start' => 0); $prevSubmission = $ticket->getTickets($filters, false); // for the first ticket ever if (isset($prevSubmission[0]) && $prevSubmission[0]->report == $row->get('report') && time() - strtotime($prevSubmission[0]->created) <= 15) { $this->setError(Lang::txt('COM_SUPPORT_TICKET_DUPLICATE_DETECTION')); return $this->newTask($row); } // Save the data if (!$row->store()) { $this->setError($row->getError()); } $attachment = $this->uploadTask($row->get('id')); // Save tags $row->set('tags', Request::getVar('tags', '', 'post')); $row->tag($row->get('tags'), User::get('id'), 1); // Get any set emails that should be notified of ticket submission $defs = explode(',', $this->config->get('emails', '{config.mailfrom}')); if ($defs) { $message = new \Hubzero\Mail\Message(); $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_SUPPORT_EMAIL_SUBJECT_NEW_TICKET', $row->get('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' => '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); $message->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')); } } } } $message->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 $message->setTo(array($def)); $message->send(); } } } // Log activity $creator = User::getInstance($row->get('login')); if ($creator && $creator->get('id')) { Event::trigger('system.logActivity', ['activity' => ['action' => 'created', 'scope' => 'support.ticket', 'scope_id' => $row->get('id'), 'description' => Lang::txt('COM_SUPPORT_ACTIVITY_TICKET_CREATED', '<a href="' . Route::url($row->link()) . '">#' . $row->get('id') . ' - ' . $row->get('summary') . '</a>'), 'details' => array('id' => $row->get('id'), 'summary' => $row->get('summary'), 'url' => Route::url($row->link()))], 'recipients' => [['support.tickets', 1], ['user', $creator->get('id')]]]); } if (!User::isGuest() && $this->acl->check('update', 'tickets') > 0) { // Only do the following if a comment was posted // otherwise, we're only recording a changelog $old = new Ticket(); $old->set('open', 1); $old->set('owner', 0); $old->set('status', 0); $old->set('tags', ''); $old->set('severity', 'normal'); $rowc = new Comment(); $rowc->set('ticket', $row->get('id')); $rowc->set('created', Date::toSql()); $rowc->set('created_by', User::get('id')); $rowc->set('access', 1); $rowc->set('comment', Lang::txt('COM_SUPPORT_TICKET_SUBMITTED')); // 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', '')); // Were there any changes, CCs, or comments to record? if (count($rowc->changelog()->get('changes')) > 0 || count($rowc->changelog()->get('cc')) > 0) { // Save the data if (!$rowc->store()) { throw new Exception($rowc->getError(), 500); } 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')); } $recipients = array(['support.tickets', 1]); // Check if the notify list has eny entries if (count($rowc->to())) { $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; } } $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']); // Send e-mail to admin? 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'], $row->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']), $this->_option))) { $this->setError(Lang::txt('COM_SUPPORT_ERROR_FAILED_TO_MESSAGE', $to['name'] . '(' . $to['role'] . ')')); } $rowc->changelog()->notified($to['role'], $to['name'], $to['email']); } foreach ($rowc->to('emails') as $to) { if ($allowEmailResponses) { $token = $encryptor->buildEmailToken(1, 1, -9999, $row->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 Utilities::sendEmail($email[0], $subject, $message, $from, $email[1]); } else { // email is just a plain 'ol string Utilities::sendEmail($to['email'], $subject, $message, $from); } $rowc->changelog()->notified($to['role'], $to['name'], $to['email']); } } // Were there any changes? if (count($rowc->changelog()->get('notifications')) > 0 || count($rowc->changelog()->get('cc')) > 0 || count($rowc->changelog()->get('changes')) > 0) { // Save the data if (!$rowc->store()) { $this->setError($rowc->getError()); } } // Record the activity if (!$rowc->isPrivate() && $creator->get('id')) { $recipients[] = ['user', $creator->get('id')]; } $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]); } } // Trigger any events that need to be called Event::trigger('support.onTicketSubmission', array($row)); // Output Thank You message $this->view->ticket = $row->get('id'); $this->view->no_html = $no_html; foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->display(); }
/** * 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); }
/** * 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(); }
/** * 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; }
/** * 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(); }
/** * 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; }
/** * Utility method to act on a user after it has been saved. * * This method sends a registration email to new users created in the backend. * * @param array $user Holds the new user data. * @param boolean $isnew True if a new user is stored. * @param boolean $success True if user was succesfully stored in the database. * @param string $msg Message. * @return void */ public function onUserAfterSave($user, $isnew, $success, $msg) { // Existing user - nothing to do...yet. if (!$isnew) { return; } // Initialise variables. $config = App::get('config'); if (App::isSite()) { if ($this->params->get('mail_to_admin', 1)) { $lang = App::get('language'); $lang->load('plg_user_' . $this->_name, PATH_APP . DS . 'bootstrap' . DS . 'site') || $lang->load('plg_user_' . $this->_name, PATH_APP . DS . 'bootstrap' . DS . 'administrator') || $lang->load('plg_user_' . $this->_name, __DIR__); $emailAddress = $config->get('mailfrom'); $eview = new Hubzero\Mail\View(array('base_path' => __DIR__, 'name' => 'emails', 'layout' => 'admincreate_plain')); $eview->set('user', $user); $eview->set('sitename', $config->get('sitename')); $plain = $eview->loadTemplate(false); $plain = str_replace("\n", "\r\n", $plain); $eview->setLayout('admincreate_html'); $html = $eview->loadTemplate(); $html = str_replace("\n", "\r\n", $html); // Assemble the email data $mail = new Hubzero\Mail\Message(); $mail->addFrom($emailAddress, Lang::txt('PLG_USER_JOOMLA_EMAIL_ADMIN', $config->get('sitename')))->addTo($emailAddress)->addHeader('X-Component', Request::getCmd('option', 'com_members'))->addHeader('X-Component-Object', 'user_creation_admin_notification')->setSubject(Lang::txt('PLG_USER_JOOMLA_EMAIL_ACCOUNT_CREATION', $config->get('sitename')))->addPart($plain, 'text/plain')->addPart($html, 'text/html'); if (!$mail->send()) { // TODO: Probably should raise a plugin error but this event is not error checked. Log::error(Lang::txt('PLG_USER_JOOMLA_EMAIL_ERROR', $emailAddress)); } } } // TODO: Suck in the frontend registration emails here as well. Job for a rainy day. if (App::isAdmin()) { if ($this->params->get('mail_to_user', 0)) { $lang = App::get('language'); $defaultLocale = $lang->getTag(); // Look for user language. Priority: // 1. User frontend language // 2. User backend language $userParams = new Hubzero\Config\Registry($user['params']); $userLocale = $userParams->get('language', $userParams->get('admin_language', $defaultLocale)); if ($userLocale != $defaultLocale) { $lang->setLanguage($userLocale); } $lang->load('plg_user_' . $this->_name, PATH_APP . DS . 'bootstrap' . DS . 'site') || $lang->load('plg_user_' . $this->_name, PATH_APP . DS . 'bootstrap' . DS . 'administrator') || $lang->load('plg_user_' . $this->_name, __DIR__); // Compute the mail subject. $emailSubject = Lang::txt('PLG_USER_JOOMLA_NEW_USER_EMAIL_SUBJECT', $user['name'], $config->get('sitename')); // Compute the mail body. $emailBody = Lang::txt('PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY', $user['name'], $config->get('sitename'), Request::root(), $user['username'], $user['password_clear']); // Assemble the email data...the sexy way! $mail = new Hubzero\Mail\Message(); $mail->addFrom($config->get('mailfrom'), $config->get('fromname'))->addTo($user['email'])->setSubject($emailSubject)->setBody($emailBody); // Set application language back to default if we changed it if ($userLocale != $defaultLocale) { $lang->setLanguage($defaultLocale); } if (!$mail->send()) { // TODO: Probably should raise a plugin error but this event is not error checked. throw new Exception(Lang::txt('PLG_USER_JOOMLA_EMAIL_ERROR'), 500); } } } }