diff --git a/api/BusinessLogic/Calendar/AbstractEvent.php b/api/BusinessLogic/Calendar/AbstractEvent.php index 5413ef48..27f2a184 100644 --- a/api/BusinessLogic/Calendar/AbstractEvent.php +++ b/api/BusinessLogic/Calendar/AbstractEvent.php @@ -4,6 +4,8 @@ namespace BusinessLogic\Calendar; class AbstractEvent { + public $id; + public $startTime; public $title; diff --git a/api/BusinessLogic/Calendar/CalendarEvent.php b/api/BusinessLogic/Calendar/CalendarEvent.php index 893cbccb..91a45761 100644 --- a/api/BusinessLogic/Calendar/CalendarEvent.php +++ b/api/BusinessLogic/Calendar/CalendarEvent.php @@ -4,8 +4,6 @@ namespace BusinessLogic\Calendar; class CalendarEvent extends AbstractEvent { - public $id; - public $type = 'CALENDAR'; public $endTime; diff --git a/api/BusinessLogic/Helpers.php b/api/BusinessLogic/Helpers.php index f2a49c6d..b841fd27 100644 --- a/api/BusinessLogic/Helpers.php +++ b/api/BusinessLogic/Helpers.php @@ -30,4 +30,8 @@ class Helpers extends \BaseClass { static function boolval($val) { return $val == true; } + + static function heskHtmlSpecialCharsDecode($in) { + return str_replace(array('&', '<', '>', '"'), array('&', '<', '>', '"'), $in); + } } \ No newline at end of file diff --git a/api/Controllers/Tickets/StaffTicketController.php b/api/Controllers/Tickets/StaffTicketController.php index ea4761a1..e049bca5 100644 --- a/api/Controllers/Tickets/StaffTicketController.php +++ b/api/Controllers/Tickets/StaffTicketController.php @@ -53,7 +53,11 @@ class StaffTicketController extends \BaseClass { /* @var $ticketEditor TicketEditor */ $ticketEditor = $applicationContext->get(TicketEditor::clazz()); + $json = JsonRetriever::getJsonData(); + $dueDate = date('Y-m-d H:i:s', strtotime(Helpers::safeArrayGet($json, 'dueDate'))); + + $ticketEditor->updateDueDate($id, $dueDate, $userContext, $hesk_settings); } private function getEditTicketModel($id, $jsonRequest) { diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index a644370d..f101f1bd 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -8,6 +8,7 @@ use BusinessLogic\Calendar\CalendarEvent; use BusinessLogic\Calendar\ReminderUnit; use BusinessLogic\Calendar\SearchEventsFilter; use BusinessLogic\Calendar\TicketEvent; +use BusinessLogic\Helpers; use BusinessLogic\Security\UserContext; use Core\Constants\Priority; use DataAccess\CommonDao; @@ -61,15 +62,15 @@ class CalendarGateway extends CommonDao { $event->id = intval($row['id']); $event->startTime = $row['start']; $event->endTime = $row['end']; - $event->allDay = $row['all_day'] ? true : false; + $event->allDay = Helpers::boolval($row['all_day']); $event->title = $row['name']; $event->location = $row['location']; $event->comments = $row['comments']; $event->categoryId = intval($row['category']); - $event->categoryName = $row['category_name']; + $event->categoryName = Helpers::heskHtmlSpecialCharsDecode($row['category_name']); $event->backgroundColor = $row['background_color']; $event->foregroundColor = $row['foreground_color']; - $event->displayBorder = $row['display_border'] === '1'; + $event->displayBorder = Helpers::boolval($row['display_border']); $event->reminderValue = $row['reminder_value'] === null ? null : floatval($row['reminder_value']); $event->reminderUnits = $row['reminder_unit'] === null ? null : ReminderUnit::getByValue($row['reminder_unit']); @@ -83,7 +84,7 @@ class CalendarGateway extends CommonDao { $currentDate = hesk_date(); $heskSettings['timeformat'] = $oldTimeSetting; - $sql = "SELECT `trackid`, `subject`, `due_date`, `category`, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, + $sql = "SELECT `tickets`.`id` AS `id`, `trackid`, `subject`, `due_date`, `category`, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, CASE WHEN `due_date` < '{$currentDate}' THEN 1 ELSE 0 END AS `overdue`, `owner`.`name` AS `owner_name`, `tickets`.`owner` AS `owner_id`, `tickets`.`priority` AS `priority` @@ -116,16 +117,17 @@ class CalendarGateway extends CommonDao { $rs = hesk_dbQuery($sql); while ($row = hesk_dbFetchAssoc($rs)) { $event = new TicketEvent(); + $event->id = intval($row['id']); $event->trackingId = $row['trackid']; $event->subject = $row['subject']; $event->title = $row['subject']; $event->startTime = $row['due_date']; $event->url = $heskSettings['hesk_url'] . '/' . $heskSettings['admin_dir'] . '/admin_ticket.php?track=' . $event->trackingId; $event->categoryId = intval($row['category']); - $event->categoryName = $row['category_name']; + $event->categoryName = Helpers::heskHtmlSpecialCharsDecode($row['category_name']); $event->backgroundColor = $row['background_color']; $event->foregroundColor = $row['foreground_color']; - $event->displayBorder = $row['display_border'] === '0'; + $event->displayBorder = Helpers::boolval($row['display_border']); $event->owner = $row['owner_name']; $event->priority = Priority::getByValue($row['priority']); diff --git a/api/index.php b/api/index.php index 00bd9af3..3888685c 100644 --- a/api/index.php +++ b/api/index.php @@ -194,6 +194,7 @@ Link::all(array( '/v1/tickets' => action(\Controllers\Tickets\CustomerTicketController::clazz(), RequestMethod::all(), SecurityHandler::OPEN), // Tickets - Staff '/v1/staff/tickets/{i}' => action(\Controllers\Tickets\StaffTicketController::clazz(), RequestMethod::all()), + '/v1/staff/tickets/{i}/due-date' => action(\Controllers\Tickets\StaffTicketController::clazz() . '::updateDueDate', array(RequestMethod::PATCH), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), // Attachments '/v1/tickets/{a}/attachments/{i}' => action(\Controllers\Attachments\PublicAttachmentController::clazz() . '::getRaw', RequestMethod::all()), '/v1/staff/tickets/{i}/attachments' => action(\Controllers\Attachments\StaffTicketAttachmentsController::clazz(), RequestMethod::all()), diff --git a/js/calendar/mods-for-hesk-calendar.js b/js/calendar/mods-for-hesk-calendar.js index 1ccfe7eb..1d6729f4 100644 --- a/js/calendar/mods-for-hesk-calendar.js +++ b/js/calendar/mods-for-hesk-calendar.js @@ -482,15 +482,19 @@ function updateCategoryVisibility() { function respondToDragAndDrop(event, delta, revertFunc) { var heskPath = $('p#hesk-path').text(); + if (event.type === 'TICKET') { + var uri = 'api/v1/staff/tickets/' + event.id + '/due-date'; $.ajax({ method: 'POST', - url: heskPath + 'internal-api/admin/calendar/', - data: { - trackingId: event.trackingId, - action: 'update-ticket', - dueDate: event.start.format('YYYY-MM-DD') + url: heskPath + uri, + headers: { + 'X-Internal-Call': true, + 'X-HTTP-Method-Override': 'PATCH' }, + data: JSON.stringify({ + dueDate: event.start.format('YYYY-MM-DD') + }), success: function() { event.fontIconMarkup = getIcon({ startTime: event.start @@ -519,7 +523,6 @@ function respondToDragAndDrop(event, delta, revertFunc) { end += ' ' + event.end.format('HH:mm:ss'); } var data = { - id: event.id, title: event.title, location: event.location, startTime: start, @@ -533,8 +536,12 @@ function respondToDragAndDrop(event, delta, revertFunc) { }; $.ajax({ method: 'POST', - url: heskPath + 'internal-api/admin/calendar/', - data: data, + url: heskPath + 'api/v1/calendar/events/staff/' + event.id, + data: JSON.stringify(data), + headers: { + 'X-Internal-Call': true, + 'X-HTTP-Method-Override': 'PUT' + }, success: function() { mfhAlert.success(mfhLang.text('event_updated')); },