Ejemplo n.º 1
0
 /**
  * Create a new comment
  *
  * @apiMethod POST
  * @apiUri    /support/comments
  * @apiParameter {
  * 		"name":        "ticket",
  * 		"description": "Id of the ticket to make a comment on",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":		 null
  * }
  * @apiParameter {
  * 		"name":        "comment",
  * 		"description": "Comment text",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":		 null
  * }
  * @apiParameter {
  * 		"name":        "group",
  * 		"description": "Group to assign the ticket to (by alias)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":		 null
  * }
  * @apiParameter {
  * 		"name":        "owner",
  * 		"description": "Id of the owner to assign ticket to",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":		 null
  * }
  * @apiParameter {
  * 		"name":        "severity",
  * 		"description": "Severity of the ticket",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":		 null
  *		"allowed_values":	"minor, normal, major, critical"
  * }
  * @apiParameter {
  * 		"name":        "status",
  * 		"description": "Status of the ticket",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":		 null
  * }
  * @apiParameter {
  * 		"name":        "target_date",
  * 		"description": "Target date for completion of ticket (YYYY-MM-DD hh:mm:ss)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":		 null
  * }
  * @apiParameter {
  * 		"name":        "cc",
  * 		"description": "Comma seperated list of email addresses to email updates to",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":		 submitter,owner
  * }
  * @apiParameter {
  * 		"name":        "private",
  * 		"description": "Should the comment be flagged as private",
  * 		"type":        "boolean",
  * 		"required":    false,
  * 		"default":		 false
  * }
  * @apiParameter {
  * 		"name":        "email_submitter",
  * 		"description": "Should the submitter be emailed about this comment",
  * 		"type":        "boolean",
  * 		"required":    false,
  * 		"default":		 false
  * }
  * @apiParameter {
  * 		"name":        "email_owner",
  * 		"description": "Should the ticket owner be emailed about this comment",
  * 		"type":        "boolean",
  * 		"required":    false,
  * 		"default":		 false
  * }
  * @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', null);
     if (!isset($ticket_id)) {
         throw new Exception(Lang::txt('Bad request - ticket ID required'), 400);
     }
     $comment_text = Request::getString('comment', '');
     if ($comment_text == '') {
         throw new Exception(Lang::txt('Bad request - comment required'), 400);
     }
     $ticket = \Components\Support\Models\Orm\Ticket::oneOrFail($ticket_id);
     $comment = new \Components\Support\Models\Orm\Comment();
     $changelog = new stdClass();
     $comment->set('ticket', Request::get('ticket', ''));
     $comment->set('comment', nl2br(Request::get('comment')));
     $comment->set('created_by', User::get('id'));
     $comment->set('access', Request::get('private', false) == 'true' ? 1 : 0);
     $changes = array();
     foreach (['group', 'owner', 'severity', 'status', 'target_date', 'category'] as $index) {
         if (Request::get($index, null)) {
             if (Request::get($index) != $ticket->get($index)) {
                 $temp = new stdClass();
                 $temp->field = $index;
                 $temp->before = $ticket->get($index);
                 $temp->after = Request::get($index);
                 if ($index == 'status') {
                     if ($ticket->get('status') == 0) {
                         $status_model = new \Components\Support\Models\Orm\Status();
                         $status_model->set('title', 'Closed');
                         $status_model->set('open', 0);
                     } else {
                         $status_model = \Components\Support\Models\Orm\Status::oneOrFail(Request::get('status'));
                     }
                     if ($ticket->get('status') == 0) {
                         $old_status = new \Components\Support\Models\Orm\Status();
                         $old_status->set('title', 'Closed');
                         $old_status->set('open', 0);
                     } else {
                         $old_status = \Components\Support\Models\Orm\Status::oneOrFail($ticket->get('status'));
                     }
                     $temp->before = $old_status->get('title');
                     $temp->after = $status_model->get('title');
                     $ticket->set('open', $status_model->get('open'));
                     if ($status_model->get('get') == 'open' && $ticket->get('status', null) == 'closed') {
                         $tiket->set('closed', '0000-00-00 00:00:00');
                     }
                     if ($status_model->get('get') == 'closed' && $ticket->get('status', null) == 'open') {
                         $ticket->set('closed', Date::toSql());
                     }
                 }
                 if ($index == 'owner') {
                     $old_owner = User::getInstance($ticket->get('owner'));
                     $new_owner = User::getInstance(Request::get('owner'));
                     $temp->before = $old_owner->get('username');
                     $temp->after = $new_owner->get('username');
                 }
                 $ticket->set($index, Request::get($index));
                 $changes[] = $temp;
             }
         }
     }
     $changelog->changes = $changes;
     if ($comment->get('comment')) {
         // If a comment was posted by the ticket submitter to a "waiting user response" ticket, change status.
         $user = User::getInstance(User::get('id'));
         if ($ticket->get('status') == 2 && $user->get('username') == $ticket->get('login')) {
             $ticket->set('status', 0);
         }
     }
     $comment->set('changelog', json_encode($changelog));
     if (!$comment->save()) {
         throw new Exception(print_r($comment->getErrors(), 1), 500);
     }
     if (!$ticket->save()) {
         throw new Exception(print_r($ticket->getErrors(), 1), 500);
     }
     // There's now a ticket and a comment, lets add attachments
     \Components\Support\Helpers\Utilities::addAttachments($ticket->get('id'), $comment->get('id'));
     $msg = new stdClass();
     $msg->id = $comment->get('id');
     $msg->notified = $comment->get('changelog');
     $this->send($msg, 200, 'OK');
     /*
     		$changlog->notifications = array();
     		if (Request::get('email_owner'))
     		{
     			$comment->addTo(array(
     				'role'  => Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_OWNER'),
     				'name'  => $ticket->get_owner->get('name'),
     				'email' => $ticket->get_owner->get('email'),
     				'id'    => $ticket->get_owner->get('id')
     			));
     			$changelog->notifications[] = json_encode(array('role'=>'Ticket owner', 'address'=>$ticket->get_owner()->get('email'), 'name'=>$ticket->get_owner()->get('name')));
     		}
     
     		// Add any CCs to the e-mail list
     		$cc = Request::get('cc', null);
     		if ($cc)
     		{
     			$cc = explode(',', $cc);
     			foreach ($cc)
     			{
     				$comment->addTo($cc, Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_CC'));
     			}
     			$changelog->cc = json_encode($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']
     				);
     			}
     		}
     		$comment->set('changelog', json_encode($changelog));
     		$comment->save();
     		$ticket->save();
     
     		$msg = new stdClass;
     		$msg->id  = $comment->get('id');
     		$msg->notified = $comment->get('changelog');
     
     		$this->send($msg, 200, 'OK');
     */
 }
Ejemplo n.º 2
0
 /**
  * Create a new ticket
  *
  * @apiMethod POST
  * @apiUri    /support/tickets
  * @apiParameter {
  * 		"name":        "username",
  * 		"description": "The submitter's username",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "name",
  * 		"description": "The submitter's name",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "email",
  * 		"description": "The submitter's email address",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "os",
  * 		"description": "The submitter's operating system",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "Unknown"
  * }
  * @apiParameter {
  * 		"name":        "browser",
  * 		"description": "The submitter's browser type",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "Unknown"
  * }
  * @apiParameter {
  * 		"name":        "report",
  * 		"description": "Description of the user's problem",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "status",
  * 		"description": "The status code of the ticket",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "severity",
  * 		"description": "The severity of the issue",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "normal" ,
  *		"allowed_values": "minor, normal, major, critical"
  * }
  * @apiParameter {
  * 		"name":        "owner",
  * 		"description": "The id of the user to assign this ticket to",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "group",
  * 		"description": "Alias of the group to assign the ticket to",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "files",
  * 		"description": "***STUB*** NOT WORKING",
  * 		"type":        "binary",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @return     void
  */
 public function createTask()
 {
     //get the userid and attempt to load user profile
     $userid = User::get('id');
     $result = User::getInstance($userid);
     //make sure we have a user
     if (!$result || !$result->get('id')) {
         throw new Exception(Lang::txt('User not found.'), 500);
     }
     //check required fields
     if (!Request::get('name', null)) {
         throw new Exception(Lang::txt('COM_SUPPORT_ERROR_NAME_NOT_FOUND'), 404);
     }
     if (!Request::get('email', null)) {
         throw new Exception(Lang::txt('COM_SUPPORT_ERROR_EMAIL_NOT_FOUND'), 404);
     }
     if (!Request::get('report', null)) {
         throw new Exception(Lang::txt('COM_SUPPORT_ERROR_REPORT_NOT_FOUND'), 404);
     }
     // Initiate class and bind data to database fields
     $ticket = new \Components\Support\Models\Orm\Ticket();
     // Set the column values for our new row
     $ticket->set('status', Request::getInt('status', 0));
     //check if a username was sent, otherwise fill in with the session's username
     if (Request::getString('username', null)) {
         $ticket->set('login', Request::get('username', 'None'));
     } else {
         $ticket->set('login', $result->get('username'));
     }
     //setting more optional values
     $ticket->set('severity', Request::get('severity', 'normal'));
     $ticket->set('owner', Request::get('owner', 0));
     //check if the report was good
     $ticket->set('report', Request::get('report', '', 'none', 2));
     if (!$ticket->get('report')) {
         throw new Exception(Lang::txt('Error: Report contains no text.'), 500);
     }
     // build the summary
     $summary = substr($ticket->get('report'), 0, 70);
     if (strlen($summary) >= 70) {
         $summary .= '...';
     }
     $ticket->set('summary', $summary);
     //continue setting values
     $ticket->set('email', Request::get('email', 'None'));
     $ticket->set('name', Request::get('name', 'None'));
     $ticket->set('os', Request::get('os', 'Unknown'));
     $ticket->set('browser', Request::get('browser', 'Unknown'));
     $ticket->set('ip', Request::ip());
     //$ticket->set('hostname', gethostbyaddr(Request::get('REMOTE_ADDR','','server')));
     $ticket->set('uas', 'API Submission');
     $ticket->set('referrer', '/api/v2.0/support/tickets');
     $ticket->set('instances', 1);
     $ticket->set('section', 1);
     $ticket->set('group', Request::get('group', ''));
     $ticket->set('open', 1);
     // Save the data
     if (!$ticket->save()) {
         throw new Exception($ticket->getErrors(), 500);
     }
     // Now we have a ticket ID, lets check for attachments
     \Components\Support\Helpers\Utilities::addAttachments($ticket->get('id'));
     // Set the response
     $msg = new stdClass();
     $msg->submitted = $ticket->get('created');
     $msg->ticket = $ticket->get('id');
     $this->send($msg, 201);
 }