Beispiel #1
0
 /**
  * Process a batch change
  *
  * @return  void
  */
 public function processTask()
 {
     // Incoming
     $tmpl = Request::getVar('tmpl');
     $ids = Request::getVar('id', array());
     $fields = Request::getVar('fields', array());
     $tags = Request::getVar('tags', '');
     $access = 1;
     $fields['owner'] = Request::getVar('owner', '');
     /*$comment = nl2br(Request::getVar('comment', '', 'post', 'none', 2));
     		$cc      = Request::getVar('cc', '');
     		$access  = Request::getInt('access', 0);
     		$email_submitter = Request::getInt('email_submitter', 0);
     		$email_owner = Request::getInt('email_owner', 0);
     
     		$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');
     		if ($allowEmailResponses)
     		{
     			try
     			{
     				$encryptor = new \Hubzero\Mail\Token();
     			}
     			catch (Exception $e)
     			{
     				$allowEmailResponses = false;
     			}
     		}*/
     // Only take the fields that have had a value set
     foreach ($fields as $key => $value) {
         if ($value === '') {
             unset($fields[$key]);
         }
     }
     $processed = array();
     foreach ($ids as $id) {
         if (!$id) {
             continue;
         }
         // Initiate class and bind posted items to database fields
         $row = new Ticket($id);
         if (!$row->exists()) {
             continue;
         }
         $old = new Ticket($id);
         $old->set('tags', $old->tags('string'));
         if (!$row->bind($fields)) {
             $this->setError($row->getError());
             continue;
         }
         // Store new content
         if (!$row->store(true)) {
             $this->setError($row->getError());
         }
         // Only set the tags if any tags have been provided
         if ($tags) {
             $row->set('tags', $tags);
             $row->tag($row->get('tags'), User::get('id'), 1);
         } else {
             $row->set('tags', $row->tags('string'));
         }
         // Create a new support comment object and populate it
         $rowc = new Comment();
         $rowc->set('ticket', $id);
         $rowc->set('comment', $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($cc);
         // Save the data
         if (!$rowc->store()) {
             $this->setError($rowc->getError());
             continue;
         }
         // 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'))
         			{
         				// Send e-mail to ticket submitter?
         				if ($email_submitter == 1 && !$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 ($email_owner == 1 && $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')
         					));
         				}
         
         				// 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
         				if (!$rowc->isPrivate())
         				{
         					foreach ($row->watchers() as $watcher)
         					{
         						$rowc->addTo($watcher->user_id, 'watcher');
         					}
         				}
         
         				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'))  // Html email
         					);
         
         					// Plain text email
         					$eview = new \Hubzero\Component\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->delimiter  = ($allowEmailResponses ? '~!~!~!~!~!~!~!~!~!~!' : '');
         
         					$message['plaintext'] = $eview->loadTemplate();
         					$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?
         					Plugin::import('xmessage');
         
         					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'] . ')'));
         						}
         						$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);
         						}
         
         						$rowc->changelog()->notified(
         							$to['role'],
         							$to['name'],
         							$to['email']
         						);
         					}
         
         					// Were there any changes?
         					if (count($rowc->changelog()->get('notifications')) > 0)
         					{
         						// Save the data
         						if (!$rowc->store())
         						{
         							$this->setError($rowc->getError());
         						}
         					}
         				}
         			}*/
         $processed[] = $id;
     }
     if ($tmpl) {
         echo Lang::txt('COM_SUPPORT_TICKETS_SUCCESSFULLY_SAVED', count($processed));
         return;
     }
     // Output messsage and redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . (Request::getInt('no_html', 0) ? '&no_html=1' : ''), false), Lang::txt('COM_SUPPORT_TICKETS_SUCCESSFULLY_SAVED', count($ids)));
 }
Beispiel #2
0
 /**
  * Checks for a ticket and increases instance count if found
  * Creates new ticket if not
  *
  * NOTE: This method is called by Rappture
  * TODO: Create a proper API
  *
  *   option  = 'com_support';
  *   task    = 'create';
  *   no_html = 1;
  *   type    = 1;
  *   sesstoken (optional)
  *
  *   login    (optional) default: automated
  *   severity (optional) default: normal
  *   category (optional) default: Tools
  *   summary  (optional) default: first 75 characters of report
  *   report
  *   email    (optional) default: supportemail
  *   name     (optional) default: Automated Error Report
  *   os       (optional)
  *   browser  (optional)
  *   ip       (optional)
  *   hostname (optional)
  *   uas      (optional)
  *   referrer (optional)
  *   cookies  (optional) default: 1 (since it's coming from rappture we assume they're already logged in and thus have cookies enabled)
  *   section  (optional)
  *   upload   (optional)
  *
  * @return  string
  */
 public function createTask()
 {
     // trim and addslashes all posted items
     $incoming = array_map('trim', $_POST);
     $incoming = array_map('addslashes', $incoming);
     // initiate class and bind posted items to database fields
     $row = new Ticket();
     if (!$row->bind($incoming)) {
         echo $row->getError();
         return;
     }
     $row->set('summary', $row->content('clean', 200));
     // Check for a session token
     $sessnum = '';
     if ($sess = Request::getVar('sesstoken', '')) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'helpers' . DS . 'utils.php';
         $mwdb = \Components\Tools\Helpers\Utils::getMWDBO();
         // retrieve the username and IP from session with this session token
         $query = "SELECT * FROM session WHERE session.sesstoken=" . $this->database->quote($sess) . " LIMIT 1";
         $mwdb->setQuery($query);
         $viewperms = $mwdb->loadObjectList();
         if ($viewperms) {
             foreach ($viewperms as $sinfo) {
                 $row->set('login', $sinfo->username);
                 $row->set('ip', $sinfo->remoteip);
                 $sessnum = $sinfo->sessnum;
             }
             // get user's infor from login
             $user = User::getInstance($row->get('login'));
             $row->set('name', $user->get('name'));
             $row->set('email', $user->get('email'));
         }
     }
     $row->set('login', $row->get('login') ? $row->get('login') : 'automated');
     // check for an existing ticket with this report
     $summary = $row->get('summary');
     if (strstr($summary, '"') || strstr($summary, "'")) {
         $summary = str_replace("\\'", "\\\\\\\\\\'", $summary);
         $summary = str_replace('\\"', '\\\\\\\\\\"', $summary);
         $query = "SELECT id FROM `#__support_tickets` WHERE LOWER(summary) LIKE " . $this->database->quote('%' . strtolower($summary) . '%') . " AND type=1 LIMIT 1";
     }
     $query = "SELECT id FROM `#__support_tickets` WHERE LOWER(summary) LIKE " . $this->database->quote('%' . strtolower($summary) . '%') . " AND type=1 LIMIT 1";
     $this->database->setQuery($query);
     if ($ticket = $this->database->loadResult()) {
         $changelog = '';
         // open existing ticket if closed
         $oldticket = new Ticket($ticket);
         $oldticket->set('instances', $oldticket->get('instances') + 1);
         if (!$oldticket->isOpen()) {
             $before = new Ticket($ticket);
             $oldticket->set('open', 1);
             $oldticket->set('status', 1);
             $oldticket->set('resolved', '');
             $rowc = new Comment();
             $rowc->set('ticket', $ticket);
             $rowc->set('comment', '');
             $rowc->set('created', Date::toSql());
             $rowc->set('created_by', User::get('id'));
             $rowc->set('access', 1);
             // Compare fields to find out what has changed for this ticket and build a changelog
             $rowc->changelog()->diff($before, $oldticket);
             if (!$rowc->store(true)) {
                 echo $rowc->getError();
                 return;
             }
         }
         // store new content
         if (!$oldticket->store(true)) {
             echo $oldticket->getError();
             return;
         }
         $status = $oldticket->status('text');
         $count = $oldticket->get('instances');
     } else {
         // set some defaults
         $row->set('status', 0);
         $row->set('open', 1);
         $row->set('created', Date::toSql());
         $row->set('severity', $row->get('severity') ? $row->get('severity') : 'normal');
         $row->set('category', $row->get('category') ? $row->get('category') : Lang::txt('COM_SUPPORT_CATEGORY_TOOLS'));
         $row->set('resolved', '');
         $row->set('email', $row->get('email') ? $row->get('email') : $this->_data['supportemail']);
         $row->set('name', $row->get('name') ? $row->get('name') : Lang::txt('COM_SUPPORT_AUTOMATED_REPORT'));
         $row->set('cookies', $row->get('cookies') ? $row->get('cookies') : 1);
         $row->set('instances', 1);
         $row->set('section', $row->get('section') ? $row->get('section') : 1);
         $row->set('type', 1);
         // store new content
         if (!$row->store(true)) {
             echo $row->getError();
             return;
         }
         $row->tag($incoming['tags'], User::get('id'), 1);
         if ($attachment = $this->uploadTask($row->get('id'))) {
             $row->set('report', $row->get('report') . "\n\n" . $attachment);
             if (!$row->store()) {
                 $this->setError($row->getError());
             }
         }
         $ticket = $row->get('id');
         $status = 'new';
         $count = 1;
     }
     echo 'Ticket #' . $ticket . ' (' . $status . ') ' . $count . ' times';
 }