From 9654fd38cb43ea648c46e3c3e452b8752de7a9ed Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 8 Jun 2014 01:12:33 -0400 Subject: [PATCH 1/8] Created hacky web service to return basic ticket information --- web-services/models/ticket.php | 51 +++++++++++ .../repositories/ticketRepository.php | 84 +++++++++++++++++++ web-services/ticket/index.php | 24 ++++++ 3 files changed, 159 insertions(+) create mode 100644 web-services/models/ticket.php create mode 100644 web-services/repositories/ticketRepository.php create mode 100644 web-services/ticket/index.php diff --git a/web-services/models/ticket.php b/web-services/models/ticket.php new file mode 100644 index 00000000..78e9ef75 --- /dev/null +++ b/web-services/models/ticket.php @@ -0,0 +1,51 @@ + diff --git a/web-services/repositories/ticketRepository.php b/web-services/repositories/ticketRepository.php new file mode 100644 index 00000000..93c2566d --- /dev/null +++ b/web-services/repositories/ticketRepository.php @@ -0,0 +1,84 @@ +connect_error) + { + return ('An error occured when establishing a connection to the database.'); + } + + $sql = 'SELECT * FROM '.$settings['db_pfix'].'tickets WHERE id = '.$id; + $results = $connection->query($sql); + + //-- There will only ever be one result, as ID is the primary key on the tickets table. + $result = $results->fetch_assoc(); + + $ticket = new Ticket(); + + $ticket->id = $result['id']; + $ticket->trackingId = $result['trackid']; + $ticket->name = $result['name']; + $ticket->email = $result['email']; + $ticket->category = $result['category']; + $ticket->priority = $result['priority']; + $ticket->subject = $result['subject']; + $ticket->message = $result['message']; + $ticket->dateCreated = $result['dt']; + $ticket->dateModified = $result['lastchange']; + $ticket->ip = $result['ip']; + $ticket->language = $result['language']; + $ticket->status = $result['status']; + $ticket->owner = $result['owner']; + $ticket->timeWorked = $result['time_worked']; + $ticket->lastReplier = $result['lastreplier']; + $ticket->replierId = $result['replierid']; + $ticket->isArchived = $result['archive']; + $ticket->isLocked = $result['locked']; + $ticket->attachments = $result['attachments']; + $ticket->merged = $result['merged']; + + //-- Not currently returning history, as it can contain a metric shit-ton of HTML code and will cludder up the JSON response. + //$ticket->history = $result['history']; + $ticket->custom1 = $result['custom1']; + $ticket->custom2 = $result['custom2']; + $ticket->custom3 = $result['custom3']; + $ticket->custom4 = $result['custom4']; + $ticket->custom5 = $result['custom5']; + $ticket->custom6 = $result['custom6']; + $ticket->custom7 = $result['custom7']; + $ticket->custom8 = $result['custom8']; + $ticket->custom9 = $result['custom9']; + $ticket->custom10 = $result['custom10']; + $ticket->custom11 = $result['custom11']; + $ticket->custom12 = $result['custom12']; + $ticket->custom13 = $result['custom13']; + $ticket->custom14 = $result['custom14']; + $ticket->custom15 = $result['custom15']; + $ticket->custom16 = $result['custom16']; + $ticket->custom17 = $result['custom17']; + $ticket->custom18 = $result['custom18']; + $ticket->custom19 = $result['custom19']; + $ticket->custom20 = $result['custom20']; + + return $ticket; + } +} + +?> diff --git a/web-services/ticket/index.php b/web-services/ticket/index.php new file mode 100644 index 00000000..5049e044 --- /dev/null +++ b/web-services/ticket/index.php @@ -0,0 +1,24 @@ +getTicketForId(13, $hesk_settings); + //--A quick and dirty RESTful test using PHP. + echo json_encode($ticket); +} +else +{ + header(http_response_code(400)); +} + +?> From 404aea6318b1c722b2a5f30d8d70713d61186e36 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 8 Jun 2014 10:52:51 -0400 Subject: [PATCH 2/8] Ticket ID to retrieve is no longer hard-coded --- web-services/ticket/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-services/ticket/index.php b/web-services/ticket/index.php index 5049e044..f818e0d6 100644 --- a/web-services/ticket/index.php +++ b/web-services/ticket/index.php @@ -12,7 +12,7 @@ if(isset($_GET['id'])) { $ticketRepository = TicketRepository::getInstance(); - $ticket = $ticketRepository->getTicketForId(13, $hesk_settings); + $ticket = $ticketRepository->getTicketForId($_GET['id'], $hesk_settings); //--A quick and dirty RESTful test using PHP. echo json_encode($ticket); } From 34163f2c1d8a1add4229771b5c19dbb6903c75c9 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 8 Jun 2014 11:25:40 -0400 Subject: [PATCH 3/8] Now more specific/readable information is returned --- .../repositories/ticketRepository.php | 93 +++++++++++++++++-- 1 file changed, 85 insertions(+), 8 deletions(-) diff --git a/web-services/repositories/ticketRepository.php b/web-services/repositories/ticketRepository.php index 93c2566d..ddffd6ac 100644 --- a/web-services/repositories/ticketRepository.php +++ b/web-services/repositories/ticketRepository.php @@ -24,7 +24,52 @@ class TicketRepository { return ('An error occured when establishing a connection to the database.'); } - $sql = 'SELECT * FROM '.$settings['db_pfix'].'tickets WHERE id = '.$id; + $sql = 'SELECT T.id, '. + 'T.trackid, '. + 'T.name AS "ContactName", '. + 'T.email, '. + 'C.name AS "CategoryName", '. + 'T.priority, '. + 'T.subject, '. + 'T.message, '. + 'T.dt, '. + 'T.lastchange, '. + 'T.ip, '. + 'T.language, '. + 'T.status, '. + 'U.name AS "Owner", '. + 'T.time_worked, '. + 'T.lastreplier, '. + 'U2.name AS "LastReplierName", '. + 'T.archive, '. + 'T.locked, '. + 'T.attachments, '. + 'T.merged, '. + 'T.custom1, '. + 'T.custom2, '. + 'T.custom3, '. + 'T.custom4, '. + 'T.custom5, '. + 'T.custom6, '. + 'T.custom7, '. + 'T.custom8, '. + 'T.custom9, '. + 'T.custom10, '. + 'T.custom11, '. + 'T.custom12, '. + 'T.custom13, '. + 'T.custom14, '. + 'T.custom15, '. + 'T.custom16, '. + 'T.custom17, '. + 'T.custom18, '. + 'T.custom19, '. + 'T.custom20 '. + 'FROM '.$settings['db_pfix'].'tickets T '. + 'INNER JOIN '.$settings['db_pfix'].'categories C ON C.id = T.category '. + 'LEFT JOIN '.$settings['db_pfix'].'users U ON U.id = T.owner '. + 'LEFT JOIN '.$settings['db_pfix'].'users U2 ON U2.id = T.replierid '. + 'WHERE T.id = '.$id; $results = $connection->query($sql); //-- There will only ever be one result, as ID is the primary key on the tickets table. @@ -34,21 +79,21 @@ class TicketRepository { $ticket->id = $result['id']; $ticket->trackingId = $result['trackid']; - $ticket->name = $result['name']; + $ticket->name = $result['ContactName']; $ticket->email = $result['email']; - $ticket->category = $result['category']; - $ticket->priority = $result['priority']; + $ticket->category = $result['CategoryName']; + $ticket->priority = self::getPriorityForId($result['priority']); $ticket->subject = $result['subject']; $ticket->message = $result['message']; $ticket->dateCreated = $result['dt']; $ticket->dateModified = $result['lastchange']; $ticket->ip = $result['ip']; $ticket->language = $result['language']; - $ticket->status = $result['status']; - $ticket->owner = $result['owner']; + $ticket->status = self::getStatusForId($result['status']); + $ticket->owner = $result['Owner']; $ticket->timeWorked = $result['time_worked']; - $ticket->lastReplier = $result['lastreplier']; - $ticket->replierId = $result['replierid']; + $ticket->lastReplier = self::getWhoLastRepliedForId($result['lastreplier']); + $ticket->replierId = $result['LastReplierName']; $ticket->isArchived = $result['archive']; $ticket->isLocked = $result['locked']; $ticket->attachments = $result['attachments']; @@ -79,6 +124,38 @@ class TicketRepository { return $ticket; } + + public function getPriorityForId($id) { + if ($id == 0){ + return '* Critical *'; + } elseif ($id == 1){ + return 'High'; + } elseif ($id == 2){ + return 'Medium'; + } elseif ($id == 3){ + return 'Low'; + } + } + + private function getStatusForId($id) { + if ($id == 0) { + return 'New'; + } elseif ($id == 1) { + return 'Waiting Reply'; + } elseif ($id == 2) { + return 'Replied'; + } elseif ($id == 3) { + return 'Resolved'; + } elseif ($id == 4) { + return 'In Progress'; + } elseif ($id == 5) { + return 'On Hold'; + } + } + + private function getWhoLastRepliedForId($id) { + return ($id == 0 ? 'Contact' : 'Staff'); + } } ?> From 9435de19d529c61ffc7a373edf418c152aa98396 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 8 Jun 2014 11:30:21 -0400 Subject: [PATCH 4/8] Made a public function that should be private private --- web-services/repositories/ticketRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-services/repositories/ticketRepository.php b/web-services/repositories/ticketRepository.php index ddffd6ac..9d7adb33 100644 --- a/web-services/repositories/ticketRepository.php +++ b/web-services/repositories/ticketRepository.php @@ -125,7 +125,7 @@ class TicketRepository { return $ticket; } - public function getPriorityForId($id) { + private function getPriorityForId($id) { if ($id == 0){ return '* Critical *'; } elseif ($id == 1){ From c204e925bb5ecb92963926640685aae8bc48c8b4 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 8 Jun 2014 11:34:34 -0400 Subject: [PATCH 5/8] Now return true/false for archived/locked --- web-services/repositories/ticketRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web-services/repositories/ticketRepository.php b/web-services/repositories/ticketRepository.php index 9d7adb33..d4a94490 100644 --- a/web-services/repositories/ticketRepository.php +++ b/web-services/repositories/ticketRepository.php @@ -94,8 +94,8 @@ class TicketRepository { $ticket->timeWorked = $result['time_worked']; $ticket->lastReplier = self::getWhoLastRepliedForId($result['lastreplier']); $ticket->replierId = $result['LastReplierName']; - $ticket->isArchived = $result['archive']; - $ticket->isLocked = $result['locked']; + $ticket->isArchived = ($result['archive'] ? true : false); + $ticket->isLocked = ($result['locked'] ? true : false); $ticket->attachments = $result['attachments']; $ticket->merged = $result['merged']; From c63ca99ccc648016352cf83baa4c6f1cd85c72bb Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 8 Jun 2014 11:45:33 -0400 Subject: [PATCH 6/8] Updated README.md --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2d615196..1077a681 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ [![Analytics](https://ga-beacon.appspot.com/UA-49251479-1/hesk/README)](https://github.com/mkoch227/Hesk) -

HESK UI v1.1.5

+

HESK Web Services

-This branch contains all files modified from the base version of HESK to become HESK UI, a clean user interface for HESK v2.5.3 +This branch contains additional files on top of HESK UI that create the HESK Web Services, a REST API to retrieve / submit changes to support tickets.

Download

-You can download this tweak via two ways: +There are currently no releases available, however you will eventually be able to download this tweak via two ways:
  1. Stable Releases: Releases that have a release tag associated with a commit are considered releases. You can click on "releases" on the top of the repo, and then click "zip" or "tar.gz" to download the repo at that stage.
  2. @@ -18,7 +18,7 @@ You can download this tweak via two ways:
    1. Download HESK from http://www.hesk.com/download.php.
    2. Extract the contents of HESK to a directory of your choice.
    3. -
    4. Download HESK UI from one of the two methods described above.
    5. +
    6. Download the HESK Web Services + HESK UI bundle from one of the two methods described above.
    7. Copy and paste the contents of the zip/tar.gz bundle and overwrite any files in the original HESK 2.5.3 folder.
    8. Upload the resulting folder to your webserver.
    @@ -27,8 +27,9 @@ You can download this tweak via two ways:

    Languages

    As of current, only English is a supported language, as there have been several language items that have been edited/created. If you want to translate HESK UI to your own language, it is recommended to download the original HESK language file for your language, and then add/edit the lines listed under //Added or modified in HESK UI for your language.

    If you create a translation for HESK UI, please submit it via a pull request or via the PHP Junkyards forum, where it will be committed to this branch.

    +

    There are currently some hard-coded strings in the web-services folder that will also need to be translated if you wish to have the string translated.

    -

    Browser Compability

    +

    Browser Compability for HESK UI

    This list may be incomplete. Please leave a note on the PHP Junkyard forums for additional browser compatibility information.

    • Google Chrome 33+: Compatible
    • @@ -38,6 +39,7 @@ You can download this tweak via two ways:
    • Internet Explorer 9: Compatible

    There are no intentions of making HESK UI compatible with Internet Explorer 6 or 7, or any browser that is 2 or more major revisions older than its latest version.

    +

    Browser compatibility: any browser / application capable of reading a JSON response.

    Versioning

    HESK UI will be maintained under the Semantic Versioning guidelines as much as possible. Releases will be numbered with the following format:

    From 1fd00cf40e7b700a4348b0cfc0ca734190a1982f Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 8 Jun 2014 11:46:07 -0400 Subject: [PATCH 7/8] fixed name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1077a681..2a4be37b 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ There are currently no releases available, however you will eventually be able t

    Browser compatibility: any browser / application capable of reading a JSON response.

    Versioning

    -

    HESK UI will be maintained under the Semantic Versioning guidelines as much as possible. Releases will be numbered with the following format:

    +

    HESK Web Services will be maintained under the Semantic Versioning guidelines as much as possible. Releases will be numbered with the following format:

    <major>.<minor>.<patch> From 01ccbde4f36537904ac1f40c65a788d26d9e93c1 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 8 Jun 2014 11:46:34 -0400 Subject: [PATCH 8/8] added name for clarity --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a4be37b..a6546814 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ There are currently no releases available, however you will eventually be able t
  3. Internet Explorer 9: Compatible
  4. There are no intentions of making HESK UI compatible with Internet Explorer 6 or 7, or any browser that is 2 or more major revisions older than its latest version.

    -

    Browser compatibility: any browser / application capable of reading a JSON response.

    +

    Browser compatibility for HESK Web Services: any browser / application capable of reading a JSON response.

    Versioning

    HESK Web Services will be maintained under the Semantic Versioning guidelines as much as possible. Releases will be numbered with the following format: