Browse Source

#189 Display public events on the calendar

merge-requests/1/head
Mike Koch 6 years ago
parent
commit
e7107996eb
  1. 20
      calendar.php
  2. 28
      internal-api/calendar/index.php
  3. 50
      internal-api/dao/calendar_dao.php
  4. 4
      js/calendar/mods-for-hesk-customer-calendar.js

20
calendar.php

@ -94,4 +94,24 @@ require_once(HESK_PATH . 'inc/header.inc.php');
</div>
</div>
</div>
</div>
<div class="popover-template" style="display: none">
<div>
<div class="popover-location">
<strong>Location</strong>
<span></span>
</div>
<div class="popover-category">
<strong>Category</strong>
<span></span>
</div>
<div class="popover-from">
<strong>From</strong>
<span></span>
</div>
<div class="popover-to">
<strong>To</strong>
<span></span>
</div>
</div>
</div>

28
internal-api/calendar/index.php

@ -0,0 +1,28 @@
<?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');
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);

50
internal-api/dao/calendar_dao.php

@ -1,12 +1,16 @@
<?php
function get_events($start, $end, $hesk_settings) {
function get_events($start, $end, $hesk_settings, $staff = true) {
$sql = "SELECT `events`.*, `categories`.`name` AS `category_name`, `categories`.`color` AS `category_color`
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`
WHERE `start` >= FROM_UNIXTIME(" . hesk_dbEscape($start)
. " / 1000) AND `end` <= FROM_UNIXTIME(" . hesk_dbEscape($end) . " / 1000)";
. " / 1000) AND `end` <= FROM_UNIXTIME(" . hesk_dbEscape($end) . " / 1000) AND `categories`.`usage` <> 1";
if (!$staff) {
$sql .= " AND `categories`.`type` = '0'";
}
$rs = hesk_dbQuery($sql);
@ -26,26 +30,28 @@ function get_events($start, $end, $hesk_settings) {
$events[] = $event;
}
$sql = "SELECT `trackid`, `subject`, `due_date`, `category`, `categories`.`name` AS `category_name`, `categories`.`color` AS `category_color`,
CASE WHEN `due_date` < CURDATE() THEN 1 ELSE 0 END AS `overdue`
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`
WHERE `due_date` >= FROM_UNIXTIME(" . intval($start) . " / 1000)
AND `due_date` <= FROM_UNIXTIME(" . intval($end) . " / 1000)
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)) {
$event['type'] = 'TICKET';
$event['trackingId'] = $row['trackid'];
$event['title'] = '[' . $row['trackid'] . '] ' . $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['categoryColor'] = $row['overdue'] ? '#dd0000' : $row['category_color'];
$events[] = $event;
if ($staff) {
$sql = "SELECT `trackid`, `subject`, `due_date`, `category`, `categories`.`name` AS `category_name`, `categories`.`color` AS `category_color`,
CASE WHEN `due_date` < CURDATE() THEN 1 ELSE 0 END AS `overdue`
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`
WHERE `due_date` >= FROM_UNIXTIME(" . intval($start) . " / 1000)
AND `due_date` <= FROM_UNIXTIME(" . intval($end) . " / 1000)
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)) {
$event['type'] = 'TICKET';
$event['trackingId'] = $row['trackid'];
$event['title'] = '[' . $row['trackid'] . '] ' . $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['categoryColor'] = $row['overdue'] ? '#dd0000' : $row['category_color'];
$events[] = $event;
}
}
return $events;

4
js/calendar/mods-for-hesk-customer-calendar.js

@ -147,7 +147,7 @@ function buildEvent(id, dbObject) {
};
}
return {
var data = {
id: id,
title: dbObject.title,
allDay: dbObject.allDay,
@ -164,6 +164,8 @@ function buildEvent(id, dbObject) {
reminderValue: dbObject.reminderValue == null ? '' : dbObject.reminderValue,
reminderUnits: dbObject.reminderUnits
};
console.log(data);
return data;
}
function calculateTextColor(color) {

Loading…
Cancel
Save