Merge branch '357-calendar-planning-phase-two' into '3-3-0'
Resolve "Calendar Planning, Phase Two" See merge request mike-koch/Mods-for-HESK!86master
commit
cfabdb950d
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Calendar;
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractEvent {
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
public $startTime;
|
||||||
|
|
||||||
|
public $title;
|
||||||
|
|
||||||
|
public $categoryId;
|
||||||
|
|
||||||
|
public $categoryName;
|
||||||
|
|
||||||
|
public $backgroundColor;
|
||||||
|
|
||||||
|
public $foregroundColor;
|
||||||
|
|
||||||
|
public $displayBorder;
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Calendar;
|
||||||
|
|
||||||
|
|
||||||
|
use BusinessLogic\Tickets\AuditTrail;
|
||||||
|
|
||||||
|
class CalendarEvent extends AbstractEvent {
|
||||||
|
public $type = 'CALENDAR';
|
||||||
|
|
||||||
|
public $endTime;
|
||||||
|
|
||||||
|
/* @var $allDay bool */
|
||||||
|
public $allDay;
|
||||||
|
|
||||||
|
public $location;
|
||||||
|
|
||||||
|
public $comments;
|
||||||
|
|
||||||
|
public $reminderValue;
|
||||||
|
|
||||||
|
public $reminderUnits;
|
||||||
|
|
||||||
|
/* @var $auditTrail AuditTrail[] */
|
||||||
|
public $auditTrail = array();
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Calendar;
|
||||||
|
|
||||||
|
|
||||||
|
use BusinessLogic\DateTimeHelpers;
|
||||||
|
use BusinessLogic\Security\UserContext;
|
||||||
|
use BusinessLogic\Tickets\AuditTrailEntityType;
|
||||||
|
use DataAccess\AuditTrail\AuditTrailGateway;
|
||||||
|
use DataAccess\Calendar\CalendarGateway;
|
||||||
|
|
||||||
|
class CalendarHandler extends \BaseClass {
|
||||||
|
private $calendarGateway;
|
||||||
|
private $auditTrailGateway;
|
||||||
|
|
||||||
|
public function __construct(CalendarGateway $calendarGateway,
|
||||||
|
AuditTrailGateway $auditTrailGateway) {
|
||||||
|
$this->calendarGateway = $calendarGateway;
|
||||||
|
$this->auditTrailGateway = $auditTrailGateway;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEventsForStaff($searchEventsFilter, $heskSettings) {
|
||||||
|
return $this->calendarGateway->getEventsForStaff($searchEventsFilter, $heskSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $calendarEvent CalendarEvent
|
||||||
|
* @param $userContext UserContext
|
||||||
|
* @param $heskSettings array
|
||||||
|
* @return CalendarEvent
|
||||||
|
* @throws \Exception If more than one event is returned for the given ID
|
||||||
|
*/
|
||||||
|
public function updateEvent($calendarEvent, $userContext, $heskSettings) {
|
||||||
|
$this->calendarGateway->updateEvent($calendarEvent, $userContext, $heskSettings);
|
||||||
|
|
||||||
|
$this->auditTrailGateway->insertAuditTrailRecord($calendarEvent->id,
|
||||||
|
AuditTrailEntityType::CALENDAR_EVENT,
|
||||||
|
'audit_event_updated',
|
||||||
|
DateTimeHelpers::heskDate($heskSettings),
|
||||||
|
array(0 => $userContext->name . ' (' . $userContext->username . ')'), $heskSettings);
|
||||||
|
|
||||||
|
$eventFilter = new SearchEventsFilter();
|
||||||
|
$eventFilter->eventId = $calendarEvent->id;
|
||||||
|
$eventFilter->reminderUserId = $userContext->id;
|
||||||
|
|
||||||
|
$events = $this->calendarGateway->getEventsForStaff($eventFilter, $heskSettings);
|
||||||
|
|
||||||
|
if (count($events) !== 1) {
|
||||||
|
throw new \Exception("Expected exactly 1 event, found: " . count($events));
|
||||||
|
}
|
||||||
|
|
||||||
|
$event = $events[0];
|
||||||
|
|
||||||
|
return $event;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $calendarEvent CalendarEvent
|
||||||
|
* @param $userContext UserContext
|
||||||
|
* @param $heskSettings array
|
||||||
|
* @return AbstractEvent
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function createEvent($calendarEvent, $userContext, $heskSettings) {
|
||||||
|
$this->calendarGateway->createEvent($calendarEvent, $userContext, $heskSettings);
|
||||||
|
|
||||||
|
$eventFilter = new SearchEventsFilter();
|
||||||
|
$eventFilter->eventId = $calendarEvent->id;
|
||||||
|
$eventFilter->reminderUserId = $userContext->id;
|
||||||
|
|
||||||
|
$events = $this->calendarGateway->getEventsForStaff($eventFilter, $heskSettings);
|
||||||
|
|
||||||
|
if (count($events) !== 1) {
|
||||||
|
throw new \Exception("Expected exactly 1 event, found: " . count($events));
|
||||||
|
}
|
||||||
|
|
||||||
|
$event = $events[0];
|
||||||
|
|
||||||
|
$this->auditTrailGateway->insertAuditTrailRecord($event->id,
|
||||||
|
AuditTrailEntityType::CALENDAR_EVENT,
|
||||||
|
'audit_event_created',
|
||||||
|
DateTimeHelpers::heskDate($heskSettings),
|
||||||
|
array(0 => $userContext->name . ' (' . $userContext->username . ')'), $heskSettings);
|
||||||
|
|
||||||
|
return $event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteEvent($id, $userContext, $heskSettings) {
|
||||||
|
$this->calendarGateway->deleteEvent($id, $userContext, $heskSettings);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Calendar;
|
||||||
|
|
||||||
|
|
||||||
|
class ReminderUnit {
|
||||||
|
const MINUTE = 0;
|
||||||
|
const HOUR = 1;
|
||||||
|
const DAY = 2;
|
||||||
|
const WEEK = 3;
|
||||||
|
|
||||||
|
static function getByValue($value) {
|
||||||
|
switch ($value) {
|
||||||
|
case 0:
|
||||||
|
return 'MINUTE';
|
||||||
|
case 1:
|
||||||
|
return 'HOUR';
|
||||||
|
case 2:
|
||||||
|
return 'DAY';
|
||||||
|
case 3:
|
||||||
|
return 'WEEK';
|
||||||
|
default:
|
||||||
|
return 'UNKNOWN';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static function getByName($name) {
|
||||||
|
switch ($name) {
|
||||||
|
case 'MINUTE':
|
||||||
|
return self::MINUTE;
|
||||||
|
case 'HOUR':
|
||||||
|
return self::HOUR;
|
||||||
|
case 'DAY':
|
||||||
|
return self::DAY;
|
||||||
|
case 'WEEK':
|
||||||
|
return self::WEEK;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Calendar;
|
||||||
|
|
||||||
|
|
||||||
|
class SearchEventsFilter {
|
||||||
|
/* @var $startTime int|null */
|
||||||
|
public $startTime;
|
||||||
|
|
||||||
|
/* @var $endTime int|null */
|
||||||
|
public $endTime;
|
||||||
|
|
||||||
|
/* @var $id int|null */
|
||||||
|
public $eventId;
|
||||||
|
|
||||||
|
/* @var $categories int[]|null */
|
||||||
|
public $categories;
|
||||||
|
|
||||||
|
/* @var $reminderUserId int|null */
|
||||||
|
public $reminderUserId;
|
||||||
|
|
||||||
|
/* @var $includeTickets bool */
|
||||||
|
public $includeTickets;
|
||||||
|
|
||||||
|
/* @var $includeUnassignedTickets bool */
|
||||||
|
public $includeUnassignedTickets;
|
||||||
|
|
||||||
|
/* @var $includeTicketsAssignedToOthers bool */
|
||||||
|
public $includeTicketsAssignedToOthers;
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Calendar;
|
||||||
|
|
||||||
|
|
||||||
|
class TicketEvent extends AbstractEvent {
|
||||||
|
public $type = 'TICKET';
|
||||||
|
|
||||||
|
public $trackingId;
|
||||||
|
|
||||||
|
public $subject;
|
||||||
|
|
||||||
|
public $url;
|
||||||
|
|
||||||
|
public $owner;
|
||||||
|
|
||||||
|
public $priority;
|
||||||
|
|
||||||
|
public $status;
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Tickets;
|
||||||
|
|
||||||
|
|
||||||
|
class AuditTrailEvent extends \BaseClass {
|
||||||
|
const DUE_DATE_REMOVED = 'audit_due_date_removed';
|
||||||
|
const DUE_DATE_CHANGED = 'audit_due_date_changed';
|
||||||
|
}
|
@ -0,0 +1,127 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Controllers\Calendar;
|
||||||
|
|
||||||
|
|
||||||
|
use BusinessLogic\Calendar\CalendarEvent;
|
||||||
|
use BusinessLogic\Calendar\CalendarHandler;
|
||||||
|
use BusinessLogic\Calendar\RecurringRule;
|
||||||
|
use BusinessLogic\Calendar\ReminderUnit;
|
||||||
|
use BusinessLogic\Calendar\SearchEventsFilter;
|
||||||
|
use BusinessLogic\Categories\CategoryHandler;
|
||||||
|
use BusinessLogic\Exceptions\ValidationException;
|
||||||
|
use BusinessLogic\Helpers;
|
||||||
|
use BusinessLogic\Security\UserContext;
|
||||||
|
use BusinessLogic\Security\UserPrivilege;
|
||||||
|
use BusinessLogic\ValidationModel;
|
||||||
|
use Controllers\JsonRetriever;
|
||||||
|
use DataAccess\Settings\ModsForHeskSettingsGateway;
|
||||||
|
use RRule\RRule;
|
||||||
|
use RRule\RSet;
|
||||||
|
|
||||||
|
class CalendarController extends \BaseClass {
|
||||||
|
function get() {
|
||||||
|
/* @var $userContext UserContext */
|
||||||
|
global $applicationContext, $hesk_settings, $userContext;
|
||||||
|
|
||||||
|
if (!isset($_GET['start']) || !isset($_GET['end'])) {
|
||||||
|
$validationModel = new ValidationModel();
|
||||||
|
$validationModel->errorKeys = array('START_AND_END_TIMES_REQUIRED');
|
||||||
|
throw new ValidationException($validationModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
$startTime = $_GET['start'];
|
||||||
|
$endTime = $_GET['end'];
|
||||||
|
|
||||||
|
/* @var $calendarHandler CalendarHandler */
|
||||||
|
$calendarHandler = $applicationContext->get(CalendarHandler::clazz());
|
||||||
|
|
||||||
|
$searchEventsFilter = new SearchEventsFilter();
|
||||||
|
$searchEventsFilter->startTime = $startTime;
|
||||||
|
$searchEventsFilter->endTime = $endTime;
|
||||||
|
$searchEventsFilter->reminderUserId = $userContext->id;
|
||||||
|
|
||||||
|
if ($userContext->isAnonymousUser()) {
|
||||||
|
$searchEventsFilter->includeTicketsAssignedToOthers = false;
|
||||||
|
$searchEventsFilter->includeUnassignedTickets = false;
|
||||||
|
$searchEventsFilter->includeTickets = false;
|
||||||
|
|
||||||
|
/* @var $categoryHandler CategoryHandler */
|
||||||
|
$categoryHandler = $applicationContext->get(CategoryHandler::clazz());
|
||||||
|
|
||||||
|
$publicCategories = $categoryHandler->getPublicCategories($hesk_settings);
|
||||||
|
$ids = array();
|
||||||
|
foreach ($publicCategories as $category) {
|
||||||
|
$ids[] = $category->id;
|
||||||
|
}
|
||||||
|
$searchEventsFilter->categories = $ids;
|
||||||
|
} else {
|
||||||
|
$searchEventsFilter->includeTicketsAssignedToOthers = in_array(UserPrivilege::CAN_VIEW_ASSIGNED_TO_OTHER, $userContext->permissions);
|
||||||
|
$searchEventsFilter->includeUnassignedTickets = in_array(UserPrivilege::CAN_VIEW_UNASSIGNED, $userContext->permissions);
|
||||||
|
$searchEventsFilter->includeTickets = true;
|
||||||
|
$searchEventsFilter->categories = $userContext->admin ? null : $userContext->categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
$events = $calendarHandler->getEventsForStaff($searchEventsFilter, $hesk_settings);
|
||||||
|
|
||||||
|
return output($events);
|
||||||
|
}
|
||||||
|
|
||||||
|
function post() {
|
||||||
|
/* @var $userContext UserContext */
|
||||||
|
/* @var $hesk_settings array */
|
||||||
|
global $applicationContext, $hesk_settings, $userContext;
|
||||||
|
|
||||||
|
$json = JsonRetriever::getJsonData();
|
||||||
|
|
||||||
|
$event = $this->transformJson($json);
|
||||||
|
|
||||||
|
/* @var $calendarHandler CalendarHandler */
|
||||||
|
$calendarHandler = $applicationContext->get(CalendarHandler::clazz());
|
||||||
|
|
||||||
|
return output($calendarHandler->createEvent($event, $userContext, $hesk_settings), 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
function put($id) {
|
||||||
|
/* @var $userContext UserContext */
|
||||||
|
global $applicationContext, $hesk_settings, $userContext;
|
||||||
|
|
||||||
|
$json = JsonRetriever::getJsonData();
|
||||||
|
|
||||||
|
$event = $this->transformJson($json, $id);
|
||||||
|
|
||||||
|
/* @var $calendarHandler CalendarHandler */
|
||||||
|
$calendarHandler = $applicationContext->get(CalendarHandler::clazz());
|
||||||
|
|
||||||
|
return output($calendarHandler->updateEvent($event, $userContext, $hesk_settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
function delete($id) {
|
||||||
|
/* @var $userContext UserContext */
|
||||||
|
global $applicationContext, $hesk_settings, $userContext;
|
||||||
|
|
||||||
|
/* @var $calendarHandler CalendarHandler */
|
||||||
|
$calendarHandler = $applicationContext->get(CalendarHandler::clazz());
|
||||||
|
|
||||||
|
$calendarHandler->deleteEvent($id, $userContext, $hesk_settings);
|
||||||
|
|
||||||
|
return http_response_code(204);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function transformJson($json, $id = null) {
|
||||||
|
$event = new CalendarEvent();
|
||||||
|
|
||||||
|
$event->id = $id;
|
||||||
|
$event->startTime = date('Y-m-d H:i:s', strtotime(Helpers::safeArrayGet($json, 'startTime')));
|
||||||
|
$event->endTime = date('Y-m-d H:i:s', strtotime(Helpers::safeArrayGet($json, 'endTime')));
|
||||||
|
$event->allDay = Helpers::safeArrayGet($json, 'allDay');
|
||||||
|
$event->title = Helpers::safeArrayGet($json, 'title');
|
||||||
|
$event->location = Helpers::safeArrayGet($json, 'location');
|
||||||
|
$event->comments = Helpers::safeArrayGet($json, 'comments');
|
||||||
|
$event->categoryId = Helpers::safeArrayGet($json, 'categoryId');
|
||||||
|
$event->reminderValue = Helpers::safeArrayGet($json, 'reminderValue');
|
||||||
|
$event->reminderUnits = ReminderUnit::getByName(Helpers::safeArrayGet($json, 'reminderUnits'));
|
||||||
|
|
||||||
|
return $event;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,246 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DataAccess\Calendar;
|
||||||
|
|
||||||
|
|
||||||
|
use BusinessLogic\Calendar\AbstractEvent;
|
||||||
|
use BusinessLogic\Calendar\CalendarEvent;
|
||||||
|
use BusinessLogic\Calendar\ReminderUnit;
|
||||||
|
use BusinessLogic\Calendar\SearchEventsFilter;
|
||||||
|
use BusinessLogic\Calendar\TicketEvent;
|
||||||
|
use BusinessLogic\Helpers;
|
||||||
|
use BusinessLogic\Security\UserContext;
|
||||||
|
use BusinessLogic\Tickets\AuditTrail;
|
||||||
|
use BusinessLogic\Tickets\AuditTrailEntityType;
|
||||||
|
use Core\Constants\Priority;
|
||||||
|
use DataAccess\CommonDao;
|
||||||
|
|
||||||
|
class CalendarGateway extends CommonDao {
|
||||||
|
/**
|
||||||
|
* @param $searchEventsFilter SearchEventsFilter
|
||||||
|
* @param $heskSettings array
|
||||||
|
* @return AbstractEvent[]
|
||||||
|
*/
|
||||||
|
public function getEventsForStaff($searchEventsFilter, $heskSettings) {
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
$events = array();
|
||||||
|
|
||||||
|
// EVENTS
|
||||||
|
$sql = "SELECT `events`.*, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`,
|
||||||
|
`categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`,
|
||||||
|
`reminders`.`amount` AS `reminder_value`, `reminders`.`unit` AS `reminder_unit`
|
||||||
|
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` AS `events`
|
||||||
|
INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories`
|
||||||
|
ON `events`.`category` = `categories`.`id`
|
||||||
|
LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` AS `reminders`
|
||||||
|
ON `reminders`.`user_id` = " . intval($searchEventsFilter->reminderUserId) . "
|
||||||
|
AND `reminders`.`event_id` = `events`.`id`
|
||||||
|
WHERE 1=1";
|
||||||
|
|
||||||
|
if ($searchEventsFilter->startTime !== null && $searchEventsFilter->endTime !== null) {
|
||||||
|
$startTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($searchEventsFilter->startTime) . " / 1000), @@session.time_zone, '+00:00')";
|
||||||
|
$endTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($searchEventsFilter->endTime) . " / 1000), @@session.time_zone, '+00:00')";
|
||||||
|
|
||||||
|
|
||||||
|
$sql .= " AND NOT (`end` < {$startTimeSql} OR `start` > {$endTimeSql})
|
||||||
|
AND `categories`.`usage` <> 1";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($searchEventsFilter->eventId !== null) {
|
||||||
|
$sql .= " AND `events`.`id` = " . intval($searchEventsFilter->eventId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($searchEventsFilter->categories)) {
|
||||||
|
$categoriesAsString = implode(',', $searchEventsFilter->categories);
|
||||||
|
$sql .= " AND `events`.`category` IN (" . $categoriesAsString . ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
$rs = hesk_dbQuery($sql);
|
||||||
|
while ($row = hesk_dbFetchAssoc($rs)) {
|
||||||
|
$event = new CalendarEvent();
|
||||||
|
$event->id = intval($row['id']);
|
||||||
|
$event->startTime = $row['start'];
|
||||||
|
$event->endTime = $row['end'];
|
||||||
|
$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 = Helpers::heskHtmlSpecialCharsDecode($row['category_name']);
|
||||||
|
$event->backgroundColor = $row['background_color'];
|
||||||
|
$event->foregroundColor = $row['foreground_color'];
|
||||||
|
$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']);
|
||||||
|
|
||||||
|
$auditTrailSql = "SELECT `at`.`id` AS `id`, `at`.`entity_id`, `at`.`language_key`, `at`.`date`,
|
||||||
|
`values`.`replacement_index`, `values`.`replacement_value`
|
||||||
|
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "audit_trail` AS `at`
|
||||||
|
INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "audit_trail_to_replacement_values` AS `values`
|
||||||
|
ON `at`.`id` = `values`.`audit_trail_id`
|
||||||
|
WHERE `entity_id` = " . intval($event->id) . "
|
||||||
|
AND `entity_type` = '" . AuditTrailEntityType::CALENDAR_EVENT . "'";
|
||||||
|
$auditTrailRs = hesk_dbQuery($auditTrailSql);
|
||||||
|
/* @var $auditTrailEntry AuditTrail */
|
||||||
|
$auditTrailEntry = null;
|
||||||
|
while ($row = hesk_dbFetchAssoc($auditTrailRs)) {
|
||||||
|
if ($auditTrailEntry == null || intval($auditTrailEntry->id) !== intval($row['id'])) {
|
||||||
|
if ($auditTrailEntry !== null) {
|
||||||
|
$event->auditTrail[] = $auditTrailEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
$auditTrailEntry = new AuditTrail();
|
||||||
|
$auditTrailEntry->id = intval($row['id']);
|
||||||
|
$auditTrailEntry->entityId = intval($row['entity_id']);
|
||||||
|
$auditTrailEntry->entityType = AuditTrailEntityType::CALENDAR_EVENT;
|
||||||
|
$auditTrailEntry->languageKey = $row['language_key'];
|
||||||
|
$auditTrailEntry->date = $row['date'];
|
||||||
|
$auditTrailEntry->replacementValues = array();
|
||||||
|
}
|
||||||
|
$auditTrailEntry->replacementValues[intval($row['replacement_index'])] = $row['replacement_value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($auditTrailEntry !== null) {
|
||||||
|
$event->auditTrail[] = $auditTrailEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
$events[] = $event;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TICKETS
|
||||||
|
if ($searchEventsFilter->includeTickets) {
|
||||||
|
$oldTimeSetting = $heskSettings['timeformat'];
|
||||||
|
$heskSettings['timeformat'] = 'Y-m-d';
|
||||||
|
$currentDate = hesk_date();
|
||||||
|
$heskSettings['timeformat'] = $oldTimeSetting;
|
||||||
|
|
||||||
|
$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`, `text_to_status_xref`.`text` AS `status_name`
|
||||||
|
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` AS `tickets`
|
||||||
|
INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories`
|
||||||
|
ON `categories`.`id` = `tickets`.`category`
|
||||||
|
AND `categories`.`usage` <> 2
|
||||||
|
LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` AS `owner`
|
||||||
|
ON `tickets`.`owner` = `owner`.`id`
|
||||||
|
LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "text_to_status_xref` AS `text_to_status_xref`
|
||||||
|
ON `tickets`.`status` = `text_to_status_xref`.`status_id`
|
||||||
|
AND `text_to_status_xref`.`language` = '" . hesk_dbEscape($heskSettings['language']) . "'
|
||||||
|
WHERE `due_date` >= {$startTimeSql}
|
||||||
|
AND `due_date` <= {$endTimeSql}
|
||||||
|
AND `status` IN (SELECT `id` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "statuses` WHERE `IsClosed` = 0)
|
||||||
|
AND (`owner` = " . $searchEventsFilter->reminderUserId;
|
||||||
|
|
||||||
|
if ($searchEventsFilter->includeUnassignedTickets) {
|
||||||
|
$sql .= " OR `owner` = 0 ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($searchEventsFilter->includeTicketsAssignedToOthers) {
|
||||||
|
$sql .= " OR `owner` NOT IN (0, " . $searchEventsFilter->reminderUserId . ") ";
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= ")";
|
||||||
|
|
||||||
|
if (!empty($searchEventsFilter->categories)) {
|
||||||
|
$categoriesAsString = implode(',', $searchEventsFilter->categories);
|
||||||
|
$sql .= " AND `tickets`.`category` IN (" . $categoriesAsString . ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
$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 = Helpers::heskHtmlSpecialCharsDecode($row['category_name']);
|
||||||
|
$event->backgroundColor = $row['background_color'];
|
||||||
|
$event->foregroundColor = $row['foreground_color'];
|
||||||
|
$event->displayBorder = Helpers::boolval($row['display_border']);
|
||||||
|
$event->owner = $row['owner_name'];
|
||||||
|
$event->priority = Priority::getByValue($row['priority']);
|
||||||
|
$event->status = $row['status_name'];
|
||||||
|
|
||||||
|
$events[] = $event;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
|
||||||
|
return $events;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $event CalendarEvent
|
||||||
|
* @param $userContext UserContext
|
||||||
|
* @param $heskSettings array
|
||||||
|
* @return CalendarEvent
|
||||||
|
*/
|
||||||
|
public function createEvent($event, $userContext, $heskSettings) {
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` (`start`, `end`, `all_day`, `name`,
|
||||||
|
`location`, `comments`, `category`) VALUES ('" . hesk_dbEscape($event->startTime) . "', '" . hesk_dbEscape($event->endTime) . "',
|
||||||
|
'" . ($event->allDay ? 1 : 0) . "', '" . hesk_dbEscape(addslashes($event->title)) . "',
|
||||||
|
'" . hesk_dbEscape(addslashes($event->location)) . "', '". hesk_dbEscape(addslashes($event->comments)) . "', " . intval($event->categoryId) . ")");
|
||||||
|
|
||||||
|
$event->id = hesk_dbInsertID();
|
||||||
|
|
||||||
|
if ($event->reminderValue !== null) {
|
||||||
|
hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` (`user_id`, `event_id`,
|
||||||
|
`amount`, `unit`) VALUES (" . intval($userContext->id) . ", " . intval($event->id) . ", " . intval($event->reminderValue) . ",
|
||||||
|
" . intval($event->reminderUnits) . ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $event CalendarEvent
|
||||||
|
* @param $userContext UserContext
|
||||||
|
* @param $heskSettings array
|
||||||
|
*/
|
||||||
|
public function updateEvent($event, $userContext, $heskSettings) {
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
$sql = "UPDATE `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` SET `start` = '" . hesk_dbEscape($event->startTime)
|
||||||
|
. "', `end` = '" . hesk_dbEscape($event->endTime) . "', `all_day` = '" . ($event->allDay ? 1 : 0) . "', `name` = '"
|
||||||
|
. hesk_dbEscape(addslashes($event->title)) . "', `location` = '" . hesk_dbEscape(addslashes($event->location)) . "', `comments` = '"
|
||||||
|
. hesk_dbEscape(addslashes($event->comments)) . "', `category` = " . intval($event->categoryId) . " WHERE `id` = " . intval($event->id);
|
||||||
|
|
||||||
|
if ($event->reminderValue !== null) {
|
||||||
|
$delete_sql = "DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` WHERE `event_id` = " . intval($event->id)
|
||||||
|
. " AND `user_id` = " . intval($userContext->id);
|
||||||
|
hesk_dbQuery($delete_sql);
|
||||||
|
$insert_sql = "INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` (`user_id`, `event_id`,
|
||||||
|
`amount`, `unit`) VALUES (" . intval($userContext->id) . ", " . intval($event->id) . ", " . intval($event->reminderValue) . ",
|
||||||
|
" . intval($event->reminderUnits) . ")";
|
||||||
|
hesk_dbQuery($insert_sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
hesk_dbQuery($sql);
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $id int
|
||||||
|
* @param $userContext UserContext
|
||||||
|
* @param $heskSettings array
|
||||||
|
*/
|
||||||
|
public function deleteEvent($id, $userContext, $heskSettings) {
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder`
|
||||||
|
WHERE `event_id` = " . intval($id) . " AND `user_id` = " . intval($userContext->id));
|
||||||
|
hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event`
|
||||||
|
WHERE `id` = " . intval($id));
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
|
}
|
@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
define('IN_SCRIPT', 1);
|
|
||||||
define('HESK_PATH', '../../');
|
|
||||||
define('INTERNAL_API_PATH', '../');
|
|
||||||
require_once(HESK_PATH . 'hesk_settings.inc.php');
|
|
||||||
require_once(HESK_PATH . 'inc/common.inc.php');
|
|
||||||
require_once(HESK_PATH . 'inc/attachments.inc.php');
|
|
||||||
require_once(HESK_PATH . 'inc/posting_functions.inc.php');
|
|
||||||
require_once(INTERNAL_API_PATH . 'core/output.php');
|
|
||||||
require_once(INTERNAL_API_PATH . 'dao/calendar_dao.php');
|
|
||||||
require_once(INTERNAL_API_PATH . 'core/cors.php');
|
|
||||||
|
|
||||||
hesk_session_start();
|
|
||||||
hesk_load_internal_api_database_functions();
|
|
||||||
hesk_dbConnect();
|
|
||||||
|
|
||||||
$modsForHesk_settings = mfh_getSettings();
|
|
||||||
|
|
||||||
// Routing
|
|
||||||
$request_method = $_SERVER['REQUEST_METHOD'];
|
|
||||||
if ($request_method === 'GET') {
|
|
||||||
$start = hesk_GET('start');
|
|
||||||
$end = hesk_GET('end');
|
|
||||||
$events = get_events($start, $end, $hesk_settings, false);
|
|
||||||
|
|
||||||
return output($events);
|
|
||||||
}
|
|
||||||
|
|
||||||
return http_response_code(400);
|
|
@ -1,218 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
function get_events($start, $end, $hesk_settings, $staff = true) {
|
|
||||||
global $hesk_settings, $hesklang;
|
|
||||||
|
|
||||||
$start_time_sql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($start) . " / 1000), @@session.time_zone, '+00:00')";
|
|
||||||
$end_time_sql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($end) . " / 1000), @@session.time_zone, '+00:00')";
|
|
||||||
|
|
||||||
$sql = "SELECT `events`.*, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`,
|
|
||||||
`categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border` ";
|
|
||||||
|
|
||||||
if ($staff) {
|
|
||||||
$sql .= ",`reminders`.`amount` AS `reminder_value`, `reminders`.`unit` AS `reminder_unit` ";
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql .= "FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event` AS `events`
|
|
||||||
INNER JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` AS `categories`
|
|
||||||
ON `events`.`category` = `categories`.`id` ";
|
|
||||||
|
|
||||||
if ($staff) {
|
|
||||||
$sql .= "LEFT JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event_reminder` AS `reminders` ON
|
|
||||||
`reminders`.`user_id` = " . intval($_SESSION['id']) . " AND `reminders`.`event_id` = `events`.`id`";
|
|
||||||
}
|
|
||||||
$sql .= "WHERE NOT (`end` < {$start_time_sql} OR `start` > {$end_time_sql}) AND `categories`.`usage` <> 1";
|
|
||||||
|
|
||||||
if (!$staff) {
|
|
||||||
$sql .= " AND `categories`.`type` = '0'";
|
|
||||||
}
|
|
||||||
|
|
||||||
$rs = hesk_dbQuery($sql);
|
|
||||||
|
|
||||||
$events = array();
|
|
||||||
while ($row = hesk_dbFetchAssoc($rs)) {
|
|
||||||
// Skip the event if the user does not have access to it
|
|
||||||
if ($staff && !$_SESSION['isadmin'] && !in_array($row['category'], $_SESSION['categories'])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
mfh_log_debug('Calendar', "Creating event with id: {$row['id']}", '');
|
|
||||||
|
|
||||||
$event['type'] = 'CALENDAR';
|
|
||||||
$event['id'] = intval($row['id']);
|
|
||||||
$event['startTime'] = $row['start'];
|
|
||||||
$event['endTime'] = $row['end'];
|
|
||||||
$event['allDay'] = $row['all_day'] ? true : false;
|
|
||||||
$event['title'] = $row['name'];
|
|
||||||
$event['location'] = $row['location'];
|
|
||||||
$event['comments'] = $row['comments'];
|
|
||||||
$event['categoryId'] = $row['category'];
|
|
||||||
$event['categoryName'] = $row['category_name'];
|
|
||||||
$event['backgroundColor'] = $row['background_color'];
|
|
||||||
$event['foregroundColor'] = $row['foreground_color'];
|
|
||||||
$event['displayBorder'] = $row['display_border'];
|
|
||||||
|
|
||||||
if ($staff) {
|
|
||||||
$event['reminderValue'] = $row['reminder_value'];
|
|
||||||
$event['reminderUnits'] = $row['reminder_unit'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$events[] = $event;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($staff) {
|
|
||||||
$old_time_setting = $hesk_settings['timeformat'];
|
|
||||||
$hesk_settings['timeformat'] = 'Y-m-d';
|
|
||||||
$current_date = hesk_date();
|
|
||||||
$hesk_settings['timeformat'] = $old_time_setting;
|
|
||||||
|
|
||||||
$sql = "SELECT `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` < '{$current_date}' THEN 1 ELSE 0 END AS `overdue`, `owner`.`name` AS `owner_name`, `tickets`.`owner` AS `owner_id`,
|
|
||||||
`tickets`.`priority` AS `priority`
|
|
||||||
FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` AS `tickets`
|
|
||||||
INNER JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` AS `categories`
|
|
||||||
ON `categories`.`id` = `tickets`.`category`
|
|
||||||
AND `categories`.`usage` <> 2
|
|
||||||
LEFT JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` AS `owner`
|
|
||||||
ON `tickets`.`owner` = `owner`.`id`
|
|
||||||
WHERE `due_date` >= CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($start)
|
|
||||||
. " / 1000), @@session.time_zone, '+00:00')
|
|
||||||
AND `due_date` <= CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($end) . " / 1000), @@session.time_zone, '+00:00')
|
|
||||||
AND `status` IN (SELECT `id` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` WHERE `IsClosed` = 0) ";
|
|
||||||
|
|
||||||
$rs = hesk_dbQuery($sql);
|
|
||||||
while ($row = hesk_dbFetchAssoc($rs)) {
|
|
||||||
// Skip the ticket if the user does not have access to it
|
|
||||||
if (!hesk_checkPermission('can_view_tickets', 0)
|
|
||||||
|| ($row['owner_id'] && $row['owner_id'] != $_SESSION['id'] && !hesk_checkPermission('can_view_ass_others', 0))
|
|
||||||
|| (!$row['owner_id'] && !hesk_checkPermission('can_view_unassigned', 0))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$event['type'] = 'TICKET';
|
|
||||||
$event['trackingId'] = $row['trackid'];
|
|
||||||
$event['subject'] = $row['subject'];
|
|
||||||
$event['title'] = $row['subject'];
|
|
||||||
$event['startTime'] = $row['due_date'];
|
|
||||||
$event['url'] = $hesk_settings['hesk_url'] . '/' . $hesk_settings['admin_dir'] . '/admin_ticket.php?track=' . $event['trackingId'];
|
|
||||||
$event['categoryId'] = $row['category'];
|
|
||||||
$event['categoryName'] = $row['category_name'];
|
|
||||||
$event['backgroundColor'] = $row['background_color'];
|
|
||||||
$event['foregroundColor'] = $row['foreground_color'];
|
|
||||||
$event['displayBorder'] = $row['display_border'];
|
|
||||||
$event['owner'] = $row['owner_name'];
|
|
||||||
|
|
||||||
$priorities = array(
|
|
||||||
0 => $hesklang['critical'],
|
|
||||||
1 => $hesklang['high'],
|
|
||||||
2 => $hesklang['medium'],
|
|
||||||
3 => $hesklang['low']
|
|
||||||
);
|
|
||||||
$event['priority'] = $priorities[$row['priority']];
|
|
||||||
|
|
||||||
$events[] = $event;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $events;
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_event($event, $hesk_settings) {
|
|
||||||
// Make sure the user can create events in this category
|
|
||||||
if (!$_SESSION['isadmin'] && !in_array($event['category'], $_SESSION['categories'])) {
|
|
||||||
print_error('Access Denied', 'You cannot create an event in this category');
|
|
||||||
}
|
|
||||||
|
|
||||||
$event['start'] = date('Y-m-d H:i:s', strtotime($event['start']));
|
|
||||||
$event['end'] = date('Y-m-d H:i:s', strtotime($event['end']));
|
|
||||||
$event['all_day'] = $event['all_day'] ? 1 : 0;
|
|
||||||
|
|
||||||
$sql = "INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event` (`start`, `end`, `all_day`,
|
|
||||||
`name`, `location`, `comments`, `category`) VALUES (
|
|
||||||
'" . hesk_dbEscape($event['start']) . "', '" . hesk_dbEscape($event['end']) . "', '" . hesk_dbEscape($event['all_day']) . "',
|
|
||||||
'" . hesk_dbEscape(addslashes($event['title'])) . "', '" . hesk_dbEscape(addslashes($event['location'])) . "', '" . hesk_dbEscape(addslashes($event['comments'])) . "',
|
|
||||||
" . intval($event['category']) . ")";
|
|
||||||
|
|
||||||
hesk_dbQuery($sql);
|
|
||||||
$event_id = hesk_dbInsertID();
|
|
||||||
|
|
||||||
if ($event['reminder_amount'] != null) {
|
|
||||||
$sql = "INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event_reminder` (`user_id`, `event_id`,
|
|
||||||
`amount`, `unit`) VALUES (" . intval($event['reminder_user']) . ", " . intval($event_id) . ", " . intval($event['reminder_amount']) . ",
|
|
||||||
" . intval($event['reminder_units']) . ")";
|
|
||||||
|
|
||||||
hesk_dbQuery($sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $event_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
function update_event($event, $hesk_settings) {
|
|
||||||
// Make sure the user can edit events in this category
|
|
||||||
if (!$_SESSION['isadmin'] && !in_array($event['category'], $_SESSION['categories'])) {
|
|
||||||
print_error('Access Denied', 'You cannot edit an event in this category');
|
|
||||||
}
|
|
||||||
|
|
||||||
$event['start'] = date('Y-m-d H:i:s', strtotime($event['start']));
|
|
||||||
$event['end'] = date('Y-m-d H:i:s', strtotime($event['end']));
|
|
||||||
if ($event['create_ticket_date'] != null) {
|
|
||||||
$event['create_ticket_date'] = date('Y-m-d H:i:s', strtotime($event['create_ticket_date']));
|
|
||||||
}
|
|
||||||
$event['all_day'] = $event['all_day'] ? 1 : 0;
|
|
||||||
$event['assign_to'] = $event['assign_to'] != null ? intval($event['assign_to']) : 'NULL';
|
|
||||||
|
|
||||||
$sql = "UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event` SET `start` = '" . hesk_dbEscape($event['start'])
|
|
||||||
. "', `end` = '" . hesk_dbEscape($event['end']) . "', `all_day` = '" . hesk_dbEscape($event['all_day']) . "', `name` = '"
|
|
||||||
. hesk_dbEscape(addslashes($event['title'])) . "', `location` = '" . hesk_dbEscape(addslashes($event['location'])) . "', `comments` = '"
|
|
||||||
. hesk_dbEscape(addslashes($event['comments'])) . "', `category` = " . intval($event['category']) . " WHERE `id` = " . intval($event['id']);
|
|
||||||
|
|
||||||
if ($event['reminder_amount'] != null) {
|
|
||||||
$delete_sql = "DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event_reminder` WHERE `event_id` = " . intval($event['id'])
|
|
||||||
. " AND `user_id` = " . intval($event['reminder_user']);
|
|
||||||
hesk_dbQuery($delete_sql);
|
|
||||||
$insert_sql = "INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event_reminder` (`user_id`, `event_id`,
|
|
||||||
`amount`, `unit`) VALUES (" . intval($event['reminder_user']) . ", " . intval($event['id']) . ", " . intval($event['reminder_amount']) . ",
|
|
||||||
" . intval($event['reminder_units']) . ")";
|
|
||||||
hesk_dbQuery($insert_sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
hesk_dbQuery($sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
function delete_event($id, $hesk_settings) {
|
|
||||||
// Make sure the user can delete events in this category
|
|
||||||
$categoryRs = hesk_dbQuery('SELECT `category` FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'calendar_event` WHERE `id` = ' . intval($id));
|
|
||||||
$category = hesk_dbFetchAssoc($categoryRs);
|
|
||||||
if (!$_SESSION['isadmin'] && !in_array($category['category'], $_SESSION['categories'])) {
|
|
||||||
print_error('Access Denied', 'You cannot delete events in this category');
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event` WHERE `id` = " . intval($id);
|
|
||||||
|
|
||||||
hesk_dbQuery($sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
function update_ticket_due_date($ticket, $hesk_settings) {
|
|
||||||
$ticket_id_rs = hesk_dbQuery("SELECT `id` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` WHERE `trackid` = '" . hesk_dbEscape($ticket['trackid']) . "'");
|
|
||||||
$ticket_id = hesk_dbFetchAssoc($ticket_id_rs);
|
|
||||||
|
|
||||||
$due_date = 'NULL';
|
|
||||||
$language_key = 'audit_due_date_removed';
|
|
||||||
$audit_array = array(0 => $_SESSION['name'] . ' (' . $_SESSION['user'] . ')');
|
|
||||||
if ($ticket['due_date'] != NULL) {
|
|
||||||
$audit_array = array(
|
|
||||||
0 => $_SESSION['name'] . ' (' . $_SESSION['user'] . ')',
|
|
||||||
1 => date('Y-m-d H:i:s', strtotime($ticket['due_date']))
|
|
||||||
);
|
|
||||||
$due_date = "'" . date('Y-m-d H:i:s', strtotime($ticket['due_date'])) . "'";
|
|
||||||
$language_key = 'audit_due_date_changed';
|
|
||||||
}
|
|
||||||
$sql = "UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `due_date` = {$due_date}, `overdue_email_sent` = '0'
|
|
||||||
WHERE `trackid` = '" . hesk_dbEscape($ticket['trackid']) . "'";
|
|
||||||
|
|
||||||
mfh_insert_audit_trail_record($ticket_id['id'], 'TICKET', $language_key, hesk_date(),
|
|
||||||
$audit_array);
|
|
||||||
|
|
||||||
hesk_dbQuery($sql);
|
|
||||||
}
|
|
@ -0,0 +1,3 @@
|
|||||||
|
/*! sprintf-js v1.1.0 | Copyright (c) 2007-present, Alexandru Marasteanu <hello@alexei.ro> | BSD-3-Clause */
|
||||||
|
!function(e){"use strict";function t(){var e=arguments[0],r=t.cache;return r[e]||(r[e]=t.parse(e)),t.format.call(null,r[e],arguments)}function r(e){return"number"==typeof e?"number":"string"==typeof e?"string":Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function n(e,t){return t>=0&&t<=7&&i[e]?i[e][t]:Array(t+1).join(e)}var s={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[\+\-]/};t.format=function(e,a){var i,o,l,c,p,f,u,g=1,_=e.length,d="",b=[],h=!0,x="";for(o=0;o<_;o++)if("string"===(d=r(e[o])))b[b.length]=e[o];else if("array"===d){if(c=e[o],c[2])for(i=a[g],l=0;l<c[2].length;l++){if(!i.hasOwnProperty(c[2][l]))throw new Error(t('[sprintf] property "%s" does not exist',c[2][l]));i=i[c[2][l]]}else i=c[1]?a[c[1]]:a[g++];if(s.not_type.test(c[8])&&s.not_primitive.test(c[8])&&"function"==r(i)&&(i=i()),s.numeric_arg.test(c[8])&&"number"!=r(i)&&isNaN(i))throw new TypeError(t("[sprintf] expecting number but found %s",r(i)));switch(s.number.test(c[8])&&(h=i>=0),c[8]){case"b":i=parseInt(i,10).toString(2);break;case"c":i=String.fromCharCode(parseInt(i,10));break;case"d":case"i":i=parseInt(i,10);break;case"j":i=JSON.stringify(i,null,c[6]?parseInt(c[6]):0);break;case"e":i=c[7]?parseFloat(i).toExponential(c[7]):parseFloat(i).toExponential();break;case"f":i=c[7]?parseFloat(i).toFixed(c[7]):parseFloat(i);break;case"g":i=c[7]?parseFloat(i).toPrecision(c[7]):parseFloat(i);break;case"o":i=i.toString(8);break;case"s":i=String(i),i=c[7]?i.substring(0,c[7]):i;break;case"t":i=String(!!i),i=c[7]?i.substring(0,c[7]):i;break;case"T":i=r(i),i=c[7]?i.substring(0,c[7]):i;break;case"u":i=parseInt(i,10)>>>0;break;case"v":i=i.valueOf(),i=c[7]?i.substring(0,c[7]):i;break;case"x":i=parseInt(i,10).toString(16);break;case"X":i=parseInt(i,10).toString(16).toUpperCase()}s.json.test(c[8])?b[b.length]=i:(!s.number.test(c[8])||h&&!c[3]?x="":(x=h?"+":"-",i=i.toString().replace(s.sign,"")),f=c[4]?"0"===c[4]?"0":c[4].charAt(1):" ",u=c[6]-(x+i).length,p=c[6]&&u>0?n(f,u):"",b[b.length]=c[5]?x+i+p:"0"===f?x+p+i:p+x+i)}return b.join("")},t.cache=Object.create(null),t.parse=function(e){for(var t=e,r=[],n=[],a=0;t;){if(null!==(r=s.text.exec(t)))n[n.length]=r[0];else if(null!==(r=s.modulo.exec(t)))n[n.length]="%";else{if(null===(r=s.placeholder.exec(t)))throw new SyntaxError("[sprintf] unexpected placeholder");if(r[2]){a|=1;var i=[],o=r[2],l=[];if(null===(l=s.key.exec(o)))throw new SyntaxError("[sprintf] failed to parse named argument key");for(i[i.length]=l[1];""!==(o=o.substring(l[0].length));)if(null!==(l=s.key_access.exec(o)))i[i.length]=l[1];else{if(null===(l=s.index_access.exec(o)))throw new SyntaxError("[sprintf] failed to parse named argument key");i[i.length]=l[1]}r[2]=i}else a|=2;if(3===a)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");n[n.length]=r}t=t.substring(r[0].length)}return n};var a=function(e,r,n){return n=(r||[]).slice(0),n.splice(0,0,e),t.apply(null,n)},i={0:["","0","00","000","0000","00000","000000","0000000"]," ":[""," "," "," "," "," "," "," "],_:["","_","__","___","____","_____","______","_______"]};"undefined"!=typeof exports&&(exports.sprintf=t,exports.vsprintf=a),void 0!==e&&(e.sprintf=t,e.vsprintf=a,"function"==typeof define&&define.amd&&define(function(){return{sprintf:t,vsprintf:a}}))}("undefined"==typeof window?this:window);
|
||||||
|
//# sourceMappingURL=sprintf.min.js.map
|
Loading…
Reference in New Issue