2015-11-02 12:55:32 -05:00
< ? php
define ( 'IN_SCRIPT' , 1 );
2015-11-02 22:13:37 -05:00
define ( 'HESK_PATH' , '../../../' );
define ( 'API_PATH' , '../../' );
2015-11-02 12:55:32 -05:00
require_once ( HESK_PATH . 'hesk_settings.inc.php' );
require_once ( HESK_PATH . 'inc/common.inc.php' );
2015-11-23 12:38:53 -05:00
require_once ( API_PATH . 'core/headers.php' );
2015-11-02 12:55:32 -05:00
require_once ( API_PATH . 'core/output.php' );
2015-11-29 00:51:30 -05:00
require_once ( API_PATH . 'businesslogic/ticket_retriever.php' );
2015-11-23 12:38:53 -05:00
require_once ( API_PATH . 'businesslogic/security_retriever.php' );
2015-11-02 12:55:32 -05:00
hesk_load_api_database_functions ();
hesk_dbConnect ();
// Routing
$request_method = $_SERVER [ 'REQUEST_METHOD' ];
2015-11-28 22:25:51 -05:00
/**
* @ api { get } / admin / ticket Retrieve a ticket ( staff - side )
* @ apiVersion 0.0 . 0
* @ apiName GetTicketStaff
* @ apiGroup Ticket
* @ apiPermission protected
*
* @ apiParam { Number } [ id ] The ID of the ticket . Omit for all tickets .
*
* @ apiSuccess { Number } id ID of the ticket
2015-11-29 15:39:38 -05:00
* @ apiSuccess { String } trackingId The tracking id of the ticket
2015-11-28 22:25:51 -05:00
* @ apiSuccess { String } name The name of the contact
* @ apiSuccess { String } email The email address of the ticket ( empty string if no email )
* @ apiSuccess { Integer } category The ID of the category the ticket is in
* @ apiSuccess { Integer } priority The ID of the priority the ticket is in
* @ apiSuccess { String } subject The subject of the ticket
* @ apiSuccess { String } message The original message of the ticket
2016-05-01 22:18:35 -04:00
* @ apiSuccess { Date } dateCreated The date and time the ticket was submitted
2015-11-28 22:25:51 -05:00
* @ apiSuccess { Integer } articles The knowledgebase article IDs suggested when the user created the ticket
* @ apiSuccess { String } ip The IP address of the submitter
* @ apiSuccess { String } language The language the ticket was submitted in
* @ apiSuccess { Integer } status The ID of the status the ticket is set to
* @ apiSuccess { Integer } owner The user ID of the ticket owner
2015-11-29 15:39:38 -05:00
* @ apiSuccess { String } timeWorked The total time worked on the ticket , in `hh:mm:ss`
2015-11-28 22:25:51 -05:00
* @ apiSuccess { Boolean } archive `true` if the ticket is tagged < br > `false` otherwise
* @ apiSuccess { Boolean } locked `true` if the ticket is locked < br > `false` otherwise
* @ apiSuccess { Integer []} merged Array of merged ticket IDs
2015-11-29 15:39:38 -05:00
* @ apiSuccess { String } legacyAuditTrail HTML markup of the entire " Audit Trail " section
2015-11-28 22:25:51 -05:00
* @ apiSuccess { String } custom1 - 20 Custom fields 1 - 20 ' s values .
2015-11-29 15:39:38 -05:00
* @ apiSuccess { Integer } linkedTo The ID of the ticket linked to this ticket
2015-11-28 22:25:51 -05:00
* @ apiSuccess { String } latitude The latitudinal coordinate of the user ' s location , or one of the corresponding error codes .
* @ apiSuccess { String } longitude The longitudinal coordinate of the user ' s location , or one of the corresponding error codes .
* @ apiSuccess { Boolean } html `true` if the ticket was created with HTML encoding < br > `false` otherwise
2015-11-29 15:39:38 -05:00
* @ apiSuccess { String } userAgent The user agent of the user who submitted the ticket
* @ apiSuccess { Integer } screenResolutionWidth The width of the screen resolution of the user who submitted the ticket
* @ apiSuccess { Integer } screenResolutionHeight The height of the screen resolution of the user who submitted the ticket
2016-05-01 22:18:35 -04:00
* @ apiSuccess { Date } dueDate The ticket ' s due date , if there is one
* @ apiSuccess { Boolean } overdueEmailSent Set to `true` if an overdue email has been sent .< br > `false` otherwise
2015-11-28 22:25:51 -05:00
*
* @ apiSuccessExample { json } Success - Response :
* HTTP / 1.1 200 OK
* {
* " id " : 22 ,
2015-11-29 15:39:38 -05:00
* " trackingId " : " EVL-RRL-DUBG " ,
2015-11-28 22:25:51 -05:00
* " name " : " Test " ,
* " email " : " " ,
* " category " : 1 ,
* " priority " : 3 ,
* " subject " : " test " ,
* " message " : " test " ,
2015-11-29 15:39:38 -05:00
* " dateCreated " : " 2014-12-28 00:57:26 " ,
2015-11-28 22:25:51 -05:00
* " articles " : null ,
2015-11-29 00:51:30 -05:00
* " ip " : " 127.0.0.1 " ,
2015-11-28 22:25:51 -05:00
* " language " : null ,
* " status " : 3 ,
2015-11-29 00:51:30 -05:00
* " owner " : 1 ,
2015-11-29 15:39:38 -05:00
* " timeWorked " : " 00:05:07 " ,
2015-11-28 22:25:51 -05:00
* " archive " : true ,
* " locked " : true ,
* " attachments " : " " ,
* " merged " : " " ,
2015-11-29 15:39:38 -05:00
* " legacyAuditTrail " : " <li class= \" smaller \" >2014-12-28 06:57:28 | ticket created by Your name (username)</li><li class= \" smaller \" >2014-12-31 21:00:59 | closed by Your name (username)</li><li class= \" smaller \" >2014-12-31 21:01:05 | status changed to Waiting reply by Your name (username)</li><li class= \" smaller \" >2014-12-31 21:01:58 | closed by Your name (username)</li><li class= \" smaller \" >2015-01-17 16:21:18 | closed by Your name (username)</li> " ,
2015-11-28 22:25:51 -05:00
* " custom1 " : " 1420671600 " ,
* " custom2 " : " " ,
* " custom3 " : " " ,
* " custom4 " : " " ,
* " custom5 " : " " ,
* " custom6 " : " " ,
* " custom7 " : " " ,
* " custom8 " : " " ,
* " custom9 " : " " ,
* " custom10 " : " " ,
* " custom11 " : " " ,
* " custom12 " : " " ,
* " custom13 " : " " ,
* " custom14 " : " " ,
* " custom15 " : " " ,
* " custom16 " : " " ,
* " custom17 " : " " ,
* " custom18 " : " " ,
* " custom19 " : " " ,
* " custom20 " : " " ,
2015-11-29 00:51:30 -05:00
* " parent " : 139 ,
2015-11-28 22:25:51 -05:00
* " latitude " : " E-0 " ,
* " longitude " : " E-0 " ,
* " html " : false ,
2015-11-29 15:39:38 -05:00
* " userAgent " : null ,
* " screenResolutionWidth " : null ,
2016-05-01 22:18:35 -04:00
* " screenResolutionHeight " : null ,
* " dueDate " : " 2016-01-01 00:00:00 " ,
* " overdueEmailSent " : " true "
2015-11-28 22:25:51 -05:00
* }
*
* @ apiError ( noTokenProvided ) 400 No `X-Auth-Token` was provided where it is required
* @ apiError ( invalidXAuthToken ) 401 The `X-Auth-Token` provided was invalid
*/
2015-11-02 12:55:32 -05:00
if ( $request_method == 'GET' ) {
2015-11-23 12:38:53 -05:00
$token = get_header ( 'X-Auth-Token' );
2016-05-01 22:18:35 -04:00
$user = NULL ;
2015-11-23 12:38:53 -05:00
try {
2016-05-01 22:18:35 -04:00
$user = get_user_for_token ( $token , $hesk_settings );
2015-11-23 12:38:53 -05:00
} catch ( AccessException $e ) {
return http_response_code ( $e -> getCode ());
}
2015-11-02 12:55:32 -05:00
if ( isset ( $_GET [ 'id' ])) {
2016-05-01 22:18:35 -04:00
$results = get_ticket_for_staff ( $hesk_settings , $user , $_GET [ 'id' ]);
2015-11-02 12:55:32 -05:00
} else {
2016-05-01 22:18:35 -04:00
$results = get_ticket_for_staff ( $hesk_settings , $user );
2015-11-02 12:55:32 -05:00
}
if ( $results == NULL ) {
return http_response_code ( 404 );
}
2015-11-02 13:00:34 -05:00
return output ( $results );
}
return http_response_code ( 405 );