コード例 #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');
     */
 }
コード例 #2
0
ファイル: ticketsv2_0.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Delete a ticket
  *
  * @apiMethod DELETE
  * @apiUri    /support/tickets/{ticket}
  * @apiParameter {
  * 		"name":        "ticket",
  * 		"description": "Ticket identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     0
  * }
  * @return    void
  */
 public function deleteTask()
 {
     $this->requiresAuthentication();
     if (!$this->acl->check('delete', 'tickets')) {
         throw new Exception(Lang::txt('Not authorized'), 403);
     }
     // Initiate class and bind data to database fields
     $ticket_id = Request::getInt('id', 0);
     // Initiate class and bind data to database fields
     $model = \Components\Support\Models\Orm\Ticket::oneOrFail($ticket_id);
     if (!$model->destroy()) {
         throw new Exception($model->getError(), 500);
     }
     $this->send(null, 204);
 }