2021-11-02 17:49:45 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Calendar controller.
|
|
|
|
*
|
|
|
|
* @category Alerts
|
|
|
|
* @package Pandora FMS
|
|
|
|
* @subpackage Community
|
|
|
|
* @version 1.0.0
|
|
|
|
* @license See below
|
|
|
|
*
|
|
|
|
* ______ ___ _______ _______ ________
|
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
|
|
|
* Please see http://pandorafms.org for full contribution list
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation for version 2.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Begin.
|
|
|
|
namespace PandoraFMS;
|
|
|
|
|
|
|
|
use PandoraFMS\Calendar;
|
|
|
|
use PandoraFMS\SpecialDay;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller for CalendarManager.
|
|
|
|
*/
|
|
|
|
class CalendarManager
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base url for ajax calls.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private const BASE_AJAX_PAGE = '/godmode/alerts/alert_special_days.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base url.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $url;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajax url.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $ajaxUrl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Some error message.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $message;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allowed methods to be called using AJAX request.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2021-11-03 10:59:00 +01:00
|
|
|
public static $AJAXMethods = [
|
|
|
|
'drawListCalendar',
|
|
|
|
'drawAlertTemplates',
|
|
|
|
'dataAlertTemplates',
|
|
|
|
];
|
2021-11-02 17:49:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if target method is available to be called using AJAX.
|
|
|
|
*
|
|
|
|
* @param string $method Target method.
|
|
|
|
*
|
|
|
|
* @return boolean True allowed, false not.
|
|
|
|
*/
|
|
|
|
public static function ajaxMethod(string $method):bool
|
|
|
|
{
|
|
|
|
return in_array($method, self::$AJAXMethods);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a JSON error.
|
|
|
|
*
|
|
|
|
* @param string $msg Error message.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function error(string $msg)
|
|
|
|
{
|
|
|
|
echo json_encode(
|
|
|
|
['error' => $msg]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiate controller.
|
|
|
|
*
|
|
|
|
* @param string $url Utility url.
|
|
|
|
* @param string|null $ajax_url Ajax url.
|
|
|
|
*/
|
|
|
|
public function __construct(string $url, ?string $ajax_url=null)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$this->access = 'LM';
|
|
|
|
|
|
|
|
check_login();
|
|
|
|
// ACL Check.
|
|
|
|
if ((bool) check_acl($config['id_user'], 0, $this->access) !== true) {
|
|
|
|
db_pandora_audit(
|
2022-01-20 10:55:23 +01:00
|
|
|
AUDIT_LOG_ACL_VIOLATION,
|
2021-11-02 17:49:45 +01:00
|
|
|
'Trying to access Alert calendar view'
|
|
|
|
);
|
|
|
|
include 'general/noaccess.php';
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->url = $url;
|
|
|
|
$this->ajaxUrl = self::BASE_AJAX_PAGE;
|
|
|
|
|
|
|
|
if (empty($ajax_url) === false) {
|
|
|
|
$this->ajaxUrl = $ajax_url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a list of.
|
|
|
|
*
|
|
|
|
* @param string $tab Active tab.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getTabs(string $tab='list')
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$buttons = [];
|
|
|
|
|
|
|
|
$buttons['list'] = [
|
|
|
|
'active' => false,
|
|
|
|
'text' => '<a href="'.ui_get_full_url(
|
2021-11-08 13:07:31 +01:00
|
|
|
$this->url.'&tab_calendar=list'
|
2021-11-02 17:49:45 +01:00
|
|
|
).'&pure='.(int) $config['pure'].'">'.html_print_image(
|
|
|
|
'images/list.png',
|
|
|
|
true,
|
|
|
|
[
|
|
|
|
'title' => __('Alert calendar list'),
|
|
|
|
'class' => 'invert_filter',
|
|
|
|
]
|
|
|
|
).'</a>',
|
|
|
|
];
|
|
|
|
|
2021-11-04 13:07:17 +01:00
|
|
|
$id_calendar = get_parameter('id_calendar', 0);
|
|
|
|
$id = get_parameter('id', 0);
|
|
|
|
|
|
|
|
$op = get_parameter('op', '');
|
|
|
|
$action = get_parameter('action', '');
|
|
|
|
|
|
|
|
if (($id_calendar !== 0 || $id !== 0)) {
|
|
|
|
$id = ($id_calendar === 0) ? $id : $id_calendar;
|
|
|
|
$buttons['list_edit'] = [
|
|
|
|
'active' => false,
|
|
|
|
'text' => '<a href="'.ui_get_full_url(
|
2021-11-08 13:07:31 +01:00
|
|
|
$this->url.'&tab_calendar=list&op=edit&id='.$id
|
2021-11-04 13:07:17 +01:00
|
|
|
).'&pure='.(int) $config['pure'].'">'.html_print_image(
|
|
|
|
'images/pencil.png',
|
|
|
|
true,
|
|
|
|
[
|
|
|
|
'title' => __('Edit calendar'),
|
|
|
|
'class' => 'invert_filter',
|
|
|
|
]
|
|
|
|
).'</a>',
|
|
|
|
];
|
|
|
|
|
2021-11-02 17:49:45 +01:00
|
|
|
$buttons['special_days'] = [
|
|
|
|
'active' => false,
|
|
|
|
'text' => '<a href="'.ui_get_full_url(
|
2021-11-08 13:07:31 +01:00
|
|
|
$this->url.'&tab_calendar=special_days&id_calendar='.$id
|
2021-11-02 17:49:45 +01:00
|
|
|
).'&pure='.(int) $config['pure'].'">'.html_print_image(
|
|
|
|
'images/templates.png',
|
|
|
|
true,
|
|
|
|
[
|
|
|
|
'title' => __('Alert special days'),
|
|
|
|
'class' => 'invert_filter',
|
|
|
|
]
|
|
|
|
).'</a>',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-11-04 13:07:17 +01:00
|
|
|
if ($op === 'edit' && $action === '') {
|
|
|
|
$tab = 'list_edit';
|
|
|
|
}
|
|
|
|
|
2021-11-02 17:49:45 +01:00
|
|
|
$buttons[$tab]['active'] = true;
|
|
|
|
|
|
|
|
return $buttons;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute page and show interface.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
2021-11-03 17:30:54 +01:00
|
|
|
\ui_require_css_file('alert');
|
2021-11-02 17:49:45 +01:00
|
|
|
$op = get_parameter('op');
|
2021-11-08 13:07:31 +01:00
|
|
|
$tab = get_parameter('tab_calendar');
|
2021-11-02 17:49:45 +01:00
|
|
|
switch ($tab) {
|
|
|
|
case 'special_days':
|
|
|
|
if ($op === 'edit') {
|
|
|
|
if ($this->showSpecialDaysEdition() !== true) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if ($op === 'delete') {
|
2021-11-03 17:30:54 +01:00
|
|
|
$this->deleteSpecialDay();
|
|
|
|
} else if ($op === 'upload_ical') {
|
|
|
|
$this->iCalendarSpecialDay();
|
2021-11-02 17:49:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->showSpecialDays();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'list':
|
|
|
|
default:
|
|
|
|
if ($op === 'edit') {
|
|
|
|
if ($this->showCalendarEdition() !== true) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if ($op === 'delete') {
|
2021-11-03 17:30:54 +01:00
|
|
|
$this->deleteCalendar();
|
2021-11-02 17:49:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->showCalendarList();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-03 17:30:54 +01:00
|
|
|
/**
|
|
|
|
* Delete calendar
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function deleteCalendar()
|
|
|
|
{
|
2022-06-03 11:39:58 +02:00
|
|
|
global $config;
|
|
|
|
|
2021-11-03 17:30:54 +01:00
|
|
|
$id = (int) get_parameter('id');
|
|
|
|
try {
|
|
|
|
$calendar = new Calendar($id);
|
|
|
|
if ($id === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
if ($id > 0) {
|
|
|
|
$this->message = \ui_print_error_message(
|
|
|
|
\__('Calendar not found: %s', $e->getMessage()),
|
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-03 11:39:58 +02:00
|
|
|
if (is_numeric($id) === true) {
|
|
|
|
if ((bool) check_acl(
|
|
|
|
$config['id_user'],
|
|
|
|
$calendar->id_group(),
|
|
|
|
'LM'
|
|
|
|
) === false
|
|
|
|
) {
|
|
|
|
db_pandora_audit(
|
|
|
|
AUDIT_LOG_ACL_VIOLATION,
|
|
|
|
'Trying to access calendar delete'
|
|
|
|
);
|
|
|
|
include 'general/noaccess.php';
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-03 17:30:54 +01:00
|
|
|
// Remove.
|
|
|
|
$calendar->delete();
|
|
|
|
$this->message = \ui_print_success_message(
|
|
|
|
\__('Calendar successfully deleted'),
|
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete special day.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function deleteSpecialDay()
|
|
|
|
{
|
|
|
|
$id = (int) get_parameter('id');
|
|
|
|
try {
|
|
|
|
$specialDay = new SpecialDay($id);
|
|
|
|
if ($id === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
if ($id > 0) {
|
|
|
|
$this->message = \ui_print_error_message(
|
|
|
|
\__('Special day not found: %s', $e->getMessage()),
|
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove.
|
|
|
|
$specialDay->delete();
|
|
|
|
$this->message = \ui_print_success_message(
|
|
|
|
\__('Special day successfully deleted'),
|
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Icalendar.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function iCalendarSpecialDay()
|
|
|
|
{
|
2021-11-04 09:55:37 +01:00
|
|
|
include_once 'include/ics-parser/class.iCalReader.php';
|
|
|
|
|
2021-11-03 17:30:54 +01:00
|
|
|
$day_code = (string) get_parameter('day_code');
|
|
|
|
$overwrite = (bool) get_parameter('overwrite', 0);
|
|
|
|
$values = [];
|
|
|
|
$values['id_group'] = (string) get_parameter('id_group');
|
|
|
|
$values['id_calendar'] = get_parameter('id_calendar');
|
|
|
|
$values['day_code'] = $day_code;
|
|
|
|
$error = $_FILES['ical_file']['error'];
|
|
|
|
$extension = substr($_FILES['ical_file']['name'], -3);
|
|
|
|
|
|
|
|
if ($error == 0 && strcasecmp($extension, 'ics') == 0) {
|
2021-11-04 09:55:37 +01:00
|
|
|
$result = true;
|
2021-11-03 17:30:54 +01:00
|
|
|
$skipped_dates = '';
|
|
|
|
$this_month = date('Ym');
|
|
|
|
$ical = new \ICal($_FILES['ical_file']['tmp_name']);
|
|
|
|
$events = $ical->events();
|
|
|
|
foreach ($events as $event) {
|
|
|
|
$event_date = substr($event['DTSTART'], 0, 8);
|
|
|
|
$event_month = substr($event['DTSTART'], 0, 6);
|
|
|
|
if ($event_month >= $this_month) {
|
|
|
|
$values['description'] = @$event['SUMMARY'];
|
|
|
|
$values['date'] = $event_date;
|
|
|
|
$date = date('Y-m-d', strtotime($event_date));
|
|
|
|
$date_check = '';
|
|
|
|
$filter['id_group'] = $values['id_group'];
|
|
|
|
$filter['date'] = $date;
|
2021-11-04 09:55:37 +01:00
|
|
|
$filter['id_calendar'] = $values['id_calendar'];
|
2021-11-03 17:30:54 +01:00
|
|
|
$date_check = db_get_value_filter(
|
|
|
|
'date',
|
|
|
|
'talert_special_days',
|
|
|
|
$filter
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($date_check === $date) {
|
|
|
|
if ($overwrite === true) {
|
|
|
|
$id_special_day = db_get_value_filter(
|
|
|
|
'id',
|
|
|
|
'talert_special_days',
|
|
|
|
$filter
|
|
|
|
);
|
|
|
|
try {
|
|
|
|
$specialDay = new SpecialDay($id_special_day);
|
|
|
|
$specialDay->date($values['date']);
|
|
|
|
$specialDay->id_group($values['id_group']);
|
|
|
|
$specialDay->day_code($values['day_code']);
|
|
|
|
$specialDay->description($values['description']);
|
|
|
|
$specialDay->id_calendar($values['id_calendar']);
|
|
|
|
|
|
|
|
if ($specialDay->save() === true) {
|
|
|
|
$result = true;
|
|
|
|
} else {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($skipped_dates == '') {
|
|
|
|
$skipped_dates = __('Skipped dates: ');
|
|
|
|
}
|
|
|
|
|
|
|
|
$skipped_dates .= $date.' ';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
$specialDay = new SpecialDay();
|
|
|
|
$specialDay->date($values['date']);
|
|
|
|
$specialDay->id_group($values['id_group']);
|
|
|
|
$specialDay->day_code($values['day_code']);
|
|
|
|
$specialDay->description($values['description']);
|
|
|
|
$specialDay->id_calendar($values['id_calendar']);
|
|
|
|
|
|
|
|
if ($specialDay->save() === true) {
|
|
|
|
$result = true;
|
|
|
|
} else {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($result === true) {
|
|
|
|
db_pandora_audit(
|
2022-02-01 13:39:18 +01:00
|
|
|
AUDIT_LOG_SYSTEM,
|
|
|
|
'Special Days. Upload iCalendar '.$_FILES['ical_file']['name']
|
2021-11-03 17:30:54 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->message = \ui_print_result_message(
|
|
|
|
$result,
|
|
|
|
\__('Success to upload iCalendar').'<br />'.$skipped_dates,
|
|
|
|
\__('Fail to upload iCalendar')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-02 17:49:45 +01:00
|
|
|
/**
|
|
|
|
* Show a list of models registered in this system.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function showCalendarList()
|
|
|
|
{
|
|
|
|
View::render(
|
|
|
|
'calendar/list',
|
|
|
|
[
|
|
|
|
'ajax_url' => $this->ajaxUrl,
|
|
|
|
'url' => $this->url,
|
|
|
|
'tabs' => $this->getTabs('list'),
|
|
|
|
'message' => $this->message,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a list of network configuration templates.
|
|
|
|
*
|
|
|
|
* @return boolean Continue showing list or not.
|
|
|
|
*/
|
|
|
|
public function showCalendarEdition()
|
|
|
|
{
|
2021-11-03 17:30:54 +01:00
|
|
|
global $config;
|
2021-11-02 17:49:45 +01:00
|
|
|
$id = (int) get_parameter('id');
|
|
|
|
$new = false;
|
|
|
|
try {
|
|
|
|
$calendar = new Calendar($id);
|
|
|
|
if ($id === 0) {
|
|
|
|
$new = true;
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
if ($id > 0) {
|
|
|
|
$this->message = \ui_print_error_message(
|
|
|
|
\__('Calendar not found: %s', $e->getMessage()),
|
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$calendar = new Calendar();
|
|
|
|
$new = true;
|
|
|
|
}
|
|
|
|
|
2022-06-03 11:39:58 +02:00
|
|
|
$group_id = null;
|
|
|
|
|
|
|
|
if ($new === true) {
|
|
|
|
if (is_numeric(get_parameter('id_group')) === true) {
|
|
|
|
$group_id = get_parameter('id_group');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (is_numeric($calendar->id_group()) === true) {
|
|
|
|
$group_id = $calendar->id_group();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_numeric($group_id) === true) {
|
|
|
|
// Check for permissions before rendering edit view or performing save action.
|
|
|
|
if ((bool) check_acl(
|
|
|
|
$config['id_user'],
|
|
|
|
$group_id,
|
|
|
|
'LM'
|
|
|
|
) === false
|
|
|
|
) {
|
|
|
|
db_pandora_audit(
|
|
|
|
AUDIT_LOG_ACL_VIOLATION,
|
|
|
|
'Trying to access calendar editor'
|
|
|
|
);
|
|
|
|
include 'general/noaccess.php';
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-02 17:49:45 +01:00
|
|
|
$action = get_parameter('action');
|
|
|
|
if ($action === 'save') {
|
|
|
|
$success = false;
|
|
|
|
|
|
|
|
$msg_ok = \__('Successfully updated');
|
|
|
|
$msg_err = \__('Failed to update');
|
|
|
|
if ($new === true) {
|
|
|
|
$msg_ok = \__('Successfully created');
|
|
|
|
$msg_err = \__('Failed to create');
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2021-11-03 17:30:54 +01:00
|
|
|
$name = get_parameter('name', null);
|
|
|
|
$change_name = true;
|
|
|
|
if ($new === false && $name === $calendar->name()) {
|
|
|
|
$change_name = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$calendar->name($name);
|
2021-11-02 17:49:45 +01:00
|
|
|
$calendar->id_group(get_parameter('id_group', null));
|
|
|
|
$calendar->description(get_parameter('description', null));
|
|
|
|
|
2021-11-03 17:30:54 +01:00
|
|
|
if ($change_name === true && empty($calendar->search(['name' => $calendar->name()])) === false) {
|
2021-11-02 17:49:45 +01:00
|
|
|
$reason = \__(
|
2021-11-03 17:30:54 +01:00
|
|
|
'Failed saving calendar: name exists',
|
2021-11-02 17:49:45 +01:00
|
|
|
$config['dbconnection']->error
|
|
|
|
);
|
2021-11-03 17:30:54 +01:00
|
|
|
} else {
|
|
|
|
// Save template.
|
|
|
|
if ($calendar->save() === true) {
|
|
|
|
$success = true;
|
|
|
|
} else {
|
|
|
|
$reason = \__(
|
|
|
|
'Failed saving calendar: ',
|
|
|
|
$config['dbconnection']->error
|
|
|
|
);
|
|
|
|
}
|
2021-11-02 17:49:45 +01:00
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->message = \ui_print_error_message(
|
|
|
|
\__('Error: %s', $e->getMessage()),
|
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->message .= \ui_print_result_message(
|
|
|
|
$success,
|
|
|
|
$msg_ok,
|
|
|
|
sprintf('%s%s', $msg_err, $reason),
|
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($success === true) {
|
|
|
|
return $success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
View::render(
|
|
|
|
'calendar/edit',
|
|
|
|
[
|
|
|
|
'ajax_url' => $this->ajaxUrl,
|
2021-11-08 13:07:31 +01:00
|
|
|
'url' => $this->url.'&op=edit&tab_calendar=list',
|
2021-11-02 17:49:45 +01:00
|
|
|
'tabs' => $this->getTabs('list'),
|
|
|
|
'calendar' => $calendar,
|
|
|
|
'message' => $this->message,
|
|
|
|
'create' => $new,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AJAX Method, draws calendar list.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function drawListCalendar()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
// Datatables offset, limit and order.
|
|
|
|
$filter = get_parameter('filter', []);
|
|
|
|
$start = get_parameter('start', 0);
|
|
|
|
$length = get_parameter('length', $config['block_size']);
|
|
|
|
$order = get_datatable_order(true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
ob_start();
|
|
|
|
|
|
|
|
$fields = ['`talert_calendar`.*'];
|
|
|
|
|
|
|
|
// Retrieve data.
|
|
|
|
$data = Calendar::calendars(
|
|
|
|
// Fields.
|
|
|
|
$fields,
|
|
|
|
// Filter.
|
|
|
|
$filter,
|
|
|
|
// Count.
|
|
|
|
false,
|
|
|
|
// Offset.
|
|
|
|
$start,
|
|
|
|
// Limit.
|
|
|
|
$length,
|
|
|
|
// Order.
|
|
|
|
$order['direction'],
|
|
|
|
// Sort field.
|
|
|
|
$order['field']
|
|
|
|
);
|
|
|
|
|
|
|
|
// Retrieve counter.
|
|
|
|
$count = Calendar::calendars(
|
|
|
|
$fields,
|
|
|
|
$filter,
|
|
|
|
true
|
|
|
|
)['count'];
|
|
|
|
|
2021-11-08 13:07:31 +01:00
|
|
|
$is_management_allowed = \is_management_allowed();
|
|
|
|
|
2021-11-02 17:49:45 +01:00
|
|
|
if ((bool) $data === true) {
|
2022-06-03 11:39:58 +02:00
|
|
|
$user_id = $config['id_user'];
|
2021-11-02 17:49:45 +01:00
|
|
|
|
|
|
|
$data = array_reduce(
|
|
|
|
$data,
|
2022-06-03 11:39:58 +02:00
|
|
|
function ($carry, $item) use ($user_id, $is_management_allowed) {
|
2021-11-02 17:49:45 +01:00
|
|
|
// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
|
|
|
// Transforms array of arrays $data into an array
|
|
|
|
// of objects, making a post-process of certain fields.
|
2022-06-03 11:39:58 +02:00
|
|
|
// Users must only be able to manage items that belong to their groups.
|
|
|
|
// IMPORTANT: if user does not have permission over 'All' group, items belonging to such
|
|
|
|
// group must be listed but they must not allow for edition.
|
|
|
|
$manage = check_acl_restricted_all(
|
|
|
|
$user_id,
|
|
|
|
$item['id_group'],
|
|
|
|
'LM'
|
|
|
|
);
|
|
|
|
|
2021-11-02 17:49:45 +01:00
|
|
|
$tmp = (object) $item;
|
|
|
|
|
|
|
|
if ((bool) $manage === true) {
|
|
|
|
$name = '<b><a href="';
|
|
|
|
$name .= ui_get_full_url(
|
2021-11-08 13:07:31 +01:00
|
|
|
$this->url.'&op=special_days&tab_calendar=special_days&id_calendar='.$tmp->id
|
2021-11-02 17:49:45 +01:00
|
|
|
);
|
|
|
|
$name .= '">';
|
|
|
|
$name .= $tmp->name;
|
|
|
|
$name .= '</a></b>';
|
|
|
|
$tmp->name = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tmp->id_group = \ui_print_group_icon(
|
|
|
|
$tmp->id_group,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
// Options. View.
|
|
|
|
$tmp->options = '';
|
|
|
|
if ((bool) $manage === true) {
|
2021-11-08 13:07:31 +01:00
|
|
|
if ($is_management_allowed === true) {
|
|
|
|
// Options. Edit.
|
|
|
|
$tmp->options .= '<a href="';
|
|
|
|
$tmp->options .= ui_get_full_url(
|
|
|
|
$this->url.'&op=edit&id='.$tmp->id
|
|
|
|
);
|
|
|
|
$tmp->options .= '">';
|
|
|
|
$tmp->options .= html_print_image(
|
|
|
|
'images/config.png',
|
|
|
|
true,
|
|
|
|
[
|
|
|
|
'title' => __('Edit'),
|
|
|
|
'class' => 'invert_filter',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$tmp->options .= '</a>';
|
|
|
|
}
|
2021-11-02 17:49:45 +01:00
|
|
|
|
|
|
|
// Options. Especial days.
|
|
|
|
$tmp->options .= '<a href="';
|
|
|
|
$tmp->options .= ui_get_full_url(
|
2021-11-08 13:07:31 +01:00
|
|
|
$this->url.'&op=special_days&tab_calendar=special_days&id_calendar='.$tmp->id
|
2021-11-02 17:49:45 +01:00
|
|
|
);
|
|
|
|
$tmp->options .= '">';
|
|
|
|
$tmp->options .= html_print_image(
|
|
|
|
'images/add.png',
|
|
|
|
true,
|
|
|
|
[
|
|
|
|
'title' => __('Special days'),
|
|
|
|
'class' => 'invert_filter',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$tmp->options .= '</a>';
|
|
|
|
|
2021-11-08 13:07:31 +01:00
|
|
|
if ($is_management_allowed === true && $tmp->id != 1) {
|
2021-11-04 10:10:11 +01:00
|
|
|
// Options. Delete.
|
|
|
|
$tmp->options .= '<a href="';
|
|
|
|
$tmp->options .= ui_get_full_url(
|
|
|
|
$this->url.'&op=delete&id='.$tmp->id
|
|
|
|
);
|
|
|
|
$tmp->options .= '">';
|
|
|
|
$tmp->options .= html_print_image(
|
|
|
|
'images/cross.png',
|
|
|
|
true,
|
|
|
|
[
|
|
|
|
'title' => __('Delete'),
|
|
|
|
'class' => 'invert_filter',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$tmp->options .= '</a>';
|
|
|
|
}
|
2021-11-02 17:49:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$carry[] = $tmp;
|
|
|
|
return $carry;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Datatables format: RecordsTotal && recordsfiltered.
|
|
|
|
echo json_encode(
|
|
|
|
[
|
|
|
|
'data' => $data,
|
|
|
|
'recordsTotal' => $count,
|
|
|
|
'recordsFiltered' => $count,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
// Capture output.
|
|
|
|
$response = ob_get_clean();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo json_encode(['error' => $e->getMessage()]);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If not valid, show error with issue.
|
|
|
|
json_decode($response);
|
|
|
|
if (json_last_error() === JSON_ERROR_NONE) {
|
|
|
|
// If valid dump.
|
|
|
|
echo $response;
|
|
|
|
} else {
|
|
|
|
echo json_encode(
|
|
|
|
['error' => $response]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a list of models registered in this system.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function showSpecialDays()
|
|
|
|
{
|
|
|
|
global $config;
|
2021-11-03 17:30:54 +01:00
|
|
|
$id_calendar = (int) get_parameter('id_calendar');
|
|
|
|
|
2021-11-03 10:59:00 +01:00
|
|
|
$display_range = (int) get_parameter('display_range', 0);
|
2021-11-02 17:49:45 +01:00
|
|
|
try {
|
|
|
|
// Datatables offset, limit and order.
|
2021-11-03 10:59:00 +01:00
|
|
|
if ($display_range === 0) {
|
|
|
|
$date = date('Y').'-'.date('m').'-1';
|
|
|
|
} else {
|
|
|
|
$date = $display_range.'-1-1';
|
|
|
|
}
|
|
|
|
|
2021-11-02 17:49:45 +01:00
|
|
|
$futureDate = date('Y-m-d', strtotime('+1 year', strtotime($date)));
|
|
|
|
|
2021-11-03 10:59:00 +01:00
|
|
|
$filter = [];
|
2021-11-02 17:49:45 +01:00
|
|
|
$filter['date'] = $date;
|
|
|
|
$filter['futureDate'] = $futureDate;
|
2021-11-03 17:30:54 +01:00
|
|
|
$filter['id_calendar'] = $id_calendar;
|
2021-11-02 17:49:45 +01:00
|
|
|
if (!is_user_admin($config['id_user'])) {
|
|
|
|
$filter['id_group'] = array_keys(
|
|
|
|
users_get_groups(false, 'LM')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$fields = ['`talert_special_days`.*'];
|
|
|
|
|
|
|
|
$specialDays = specialDay::specialDays(
|
|
|
|
// Fields.
|
|
|
|
$fields,
|
|
|
|
// Filter.
|
2021-11-03 10:59:00 +01:00
|
|
|
$filter,
|
|
|
|
// Count.
|
|
|
|
false,
|
|
|
|
// Offset.
|
|
|
|
null,
|
|
|
|
// Limit.
|
|
|
|
null,
|
|
|
|
// Order.
|
|
|
|
null,
|
|
|
|
// Sort field.
|
|
|
|
null,
|
|
|
|
// Reduce array.
|
|
|
|
true
|
2021-11-02 17:49:45 +01:00
|
|
|
);
|
|
|
|
} catch (\Exception $e) {
|
2021-11-03 17:30:54 +01:00
|
|
|
if ($id_calendar > 0) {
|
2021-11-02 17:49:45 +01:00
|
|
|
$this->message = \ui_print_error_message(
|
|
|
|
\__('Special days not found: %s', $e->getMessage()),
|
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
View::render(
|
|
|
|
'calendar/special_days',
|
|
|
|
[
|
2021-11-03 10:59:00 +01:00
|
|
|
'ajax_url' => $this->ajaxUrl,
|
2021-11-08 13:07:31 +01:00
|
|
|
'url' => $this->url.'&tab_calendar=special_days',
|
2021-11-03 10:59:00 +01:00
|
|
|
'tabs' => $this->getTabs('special_days'),
|
|
|
|
'message' => $this->message,
|
|
|
|
'specialDays' => $specialDays,
|
2021-11-03 17:30:54 +01:00
|
|
|
'id_calendar' => $id_calendar,
|
2021-11-03 10:59:00 +01:00
|
|
|
'display_range' => $display_range,
|
2021-11-02 17:49:45 +01:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show form special day.
|
|
|
|
*
|
|
|
|
* @return boolean Continue showing list or not.
|
|
|
|
*/
|
|
|
|
public function showSpecialDaysEdition()
|
|
|
|
{
|
2021-11-03 17:30:54 +01:00
|
|
|
global $config;
|
|
|
|
|
2021-11-02 17:49:45 +01:00
|
|
|
$id = (int) get_parameter('id');
|
|
|
|
$new = false;
|
|
|
|
try {
|
|
|
|
$specialDay = new SpecialDay($id);
|
|
|
|
if ($id === 0) {
|
2021-11-03 10:59:00 +01:00
|
|
|
$specialDay->date(get_parameter('date', null));
|
2021-11-03 17:30:54 +01:00
|
|
|
$specialDay->id_calendar(get_parameter('id_calendar', null));
|
2021-11-02 17:49:45 +01:00
|
|
|
$new = true;
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
if ($id > 0) {
|
|
|
|
$this->message = \ui_print_error_message(
|
|
|
|
\__('SpecialDay not found: %s', $e->getMessage()),
|
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$specialDay = new SpecialDay();
|
|
|
|
$new = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$action = get_parameter('action');
|
|
|
|
if ($action === 'save') {
|
|
|
|
$success = false;
|
|
|
|
|
|
|
|
$msg_ok = \__('Successfully updated');
|
|
|
|
$msg_err = \__('Failed to update');
|
|
|
|
if ($new === true) {
|
|
|
|
$msg_ok = \__('Successfully created');
|
|
|
|
$msg_err = \__('Failed to create');
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2021-11-03 17:30:54 +01:00
|
|
|
$date = get_parameter('date', null);
|
|
|
|
$id_group = get_parameter('id_group', null);
|
|
|
|
$day_code = get_parameter('day_code', null);
|
|
|
|
$id_calendar = get_parameter('id_calendar', null);
|
2023-01-23 14:44:10 +01:00
|
|
|
$description = io_safe_input(get_parameter('description', null));
|
2021-11-03 17:30:54 +01:00
|
|
|
$change = true;
|
|
|
|
if ($new === false
|
|
|
|
&& ($date === $specialDay->date()
|
|
|
|
|| $id_group === $specialDay->id_group()
|
|
|
|
|| $day_code === $specialDay->day_code())
|
|
|
|
) {
|
|
|
|
$change = false;
|
|
|
|
}
|
2021-11-02 17:49:45 +01:00
|
|
|
|
2021-11-03 17:30:54 +01:00
|
|
|
$specialDay->date($date);
|
|
|
|
$specialDay->id_group($id_group);
|
|
|
|
$specialDay->day_code($day_code);
|
|
|
|
$specialDay->description($description);
|
|
|
|
$specialDay->id_calendar($id_calendar);
|
|
|
|
|
|
|
|
$search = specialDay::specialDays(
|
|
|
|
[ '`talert_special_days`.*' ],
|
|
|
|
[
|
|
|
|
'date_match' => $specialDay->date(),
|
|
|
|
'id_group' => [$specialDay->id_group()],
|
|
|
|
'day_code' => $specialDay->day_code(),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($change === true && empty($search) === false) {
|
2021-11-02 17:49:45 +01:00
|
|
|
$reason = \__(
|
2021-11-04 12:33:40 +01:00
|
|
|
'Failed saving calendar: already exists',
|
2021-11-02 17:49:45 +01:00
|
|
|
$config['dbconnection']->error
|
|
|
|
);
|
2021-11-03 17:30:54 +01:00
|
|
|
} else {
|
|
|
|
// Save template.
|
|
|
|
if ($specialDay->save() === true) {
|
|
|
|
$success = true;
|
|
|
|
} else {
|
|
|
|
$reason = \__(
|
|
|
|
'Failed saving special day: ',
|
|
|
|
$config['dbconnection']->error
|
|
|
|
);
|
|
|
|
}
|
2021-11-02 17:49:45 +01:00
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->message = \ui_print_error_message(
|
|
|
|
\__('Error: %s', $e->getMessage()),
|
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->message .= \ui_print_result_message(
|
|
|
|
$success,
|
|
|
|
$msg_ok,
|
|
|
|
sprintf('%s%s', $msg_err, $reason),
|
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($success === true) {
|
|
|
|
return $success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
View::render(
|
|
|
|
'calendar/special_days_edit',
|
|
|
|
[
|
2021-11-04 09:55:37 +01:00
|
|
|
'ajax_url' => $this->ajaxUrl,
|
2021-11-08 13:07:31 +01:00
|
|
|
'url' => $this->url.'&id_calendar='.$specialDay->id_calendar().'&op=edit&tab_calendar=special_days',
|
2021-11-04 09:55:37 +01:00
|
|
|
'tabs' => $this->getTabs('special_days'),
|
|
|
|
'specialDay' => $specialDay,
|
|
|
|
'message' => $this->message,
|
|
|
|
'create' => $new,
|
|
|
|
'id_calendar' => $specialDay->id_calendar(),
|
2021-11-02 17:49:45 +01:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-03 10:59:00 +01:00
|
|
|
/**
|
|
|
|
* AJAX Method, draw Alert Template list.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function drawAlertTemplates()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$date = get_parameter('date', '');
|
|
|
|
$id_group = get_parameter('id_group', 0);
|
2021-11-03 17:30:54 +01:00
|
|
|
$day_code = get_parameter('day_code', '');
|
2021-11-04 09:55:37 +01:00
|
|
|
$id_calendar = get_parameter('id_calendar', 0);
|
2021-11-03 10:59:00 +01:00
|
|
|
|
2021-11-04 13:07:17 +01:00
|
|
|
$weekdays = [
|
|
|
|
1 => 'monday',
|
|
|
|
2 => 'tuesday',
|
|
|
|
3 => 'wednesday',
|
|
|
|
4 => 'thursday',
|
|
|
|
5 => 'friday',
|
|
|
|
6 => 'saturday',
|
|
|
|
7 => 'sunday',
|
|
|
|
8 => 'holidays',
|
|
|
|
];
|
|
|
|
|
|
|
|
$output = '<h4>'.__('Same as %s', $weekdays[$day_code]);
|
2021-11-03 10:59:00 +01:00
|
|
|
$output .= ' » ';
|
|
|
|
$output .= __('Templates not being fired');
|
|
|
|
$output .= '</h4>';
|
|
|
|
|
|
|
|
$columns = [
|
|
|
|
'name',
|
|
|
|
'id_group',
|
|
|
|
'type',
|
|
|
|
'monday',
|
|
|
|
'tuesday',
|
|
|
|
'wednesday',
|
|
|
|
'thursday',
|
|
|
|
'friday',
|
|
|
|
'saturday',
|
|
|
|
'sunday',
|
|
|
|
];
|
|
|
|
|
|
|
|
$column_names = [
|
|
|
|
__('Name'),
|
|
|
|
__('Group'),
|
|
|
|
__('Type'),
|
|
|
|
__('Mon'),
|
|
|
|
__('Tue'),
|
|
|
|
__('Wed'),
|
|
|
|
__('Thu'),
|
|
|
|
__('Fri'),
|
|
|
|
__('Sat'),
|
|
|
|
__('Sun'),
|
|
|
|
];
|
|
|
|
try {
|
|
|
|
$output .= ui_print_datatable(
|
|
|
|
[
|
|
|
|
'id' => 'templates_alerts_special_days',
|
|
|
|
'return' => true,
|
|
|
|
'class' => 'info_table',
|
|
|
|
'style' => 'width: 100%',
|
|
|
|
'columns' => $columns,
|
|
|
|
'column_names' => $column_names,
|
|
|
|
'ajax_url' => 'godmode/alerts/alert_special_days',
|
|
|
|
'ajax_data' => [
|
2021-11-04 09:55:37 +01:00
|
|
|
'method' => 'dataAlertTemplates',
|
|
|
|
'day_code' => $day_code,
|
|
|
|
'id_calendar' => $id_calendar,
|
2021-11-04 12:33:40 +01:00
|
|
|
'id_group' => $id_group,
|
2021-11-03 10:59:00 +01:00
|
|
|
],
|
|
|
|
'no_sortable_columns' => [-1],
|
|
|
|
'order' => [
|
|
|
|
'field' => 'name',
|
|
|
|
'direction' => 'asc',
|
|
|
|
],
|
|
|
|
'search_button_class' => 'sub filter float-right',
|
|
|
|
'form' => [
|
|
|
|
'inputs' => [
|
|
|
|
[
|
|
|
|
'label' => __('Type'),
|
|
|
|
'type' => 'select',
|
|
|
|
'name' => 'type',
|
|
|
|
'fields' => alerts_get_alert_templates_types(),
|
|
|
|
'selected' => 0,
|
|
|
|
'nothing' => 'None',
|
|
|
|
'nothing_value' => 0,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => __('Search'),
|
|
|
|
'type' => 'text',
|
|
|
|
'class' => 'mw250px',
|
|
|
|
'id' => 'name',
|
|
|
|
'name' => 'name',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$output .= $e->getMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $output;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AJAX Method, draw Alert Template list.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function dataAlertTemplates()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$filters = get_parameter('filter', []);
|
|
|
|
if (empty($filters['type']) === false) {
|
|
|
|
$filter['type'] = $filters['type'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($filters['name']) === false) {
|
|
|
|
$filter[] = "name LIKE '%".$filters['name']."%'";
|
|
|
|
}
|
|
|
|
|
2021-11-04 12:33:40 +01:00
|
|
|
$id_calendar = (int) get_parameter('id_calendar', 0);
|
|
|
|
$id_group = (int) get_parameter('id_group', 0);
|
2021-11-04 09:55:37 +01:00
|
|
|
$filter['special_day'] = $id_calendar;
|
2021-11-04 12:33:40 +01:00
|
|
|
|
|
|
|
if ($id_group !== 0) {
|
|
|
|
$filter['id_group'] = $id_group;
|
|
|
|
}
|
|
|
|
|
2021-11-03 10:59:00 +01:00
|
|
|
$templates = alerts_get_alert_templates($filter);
|
2021-11-04 09:55:37 +01:00
|
|
|
|
2021-11-03 10:59:00 +01:00
|
|
|
$count = alerts_get_alert_templates($filter, ['COUNT(*) AS total']);
|
|
|
|
|
|
|
|
$day_code = get_parameter('day_code', '');
|
2021-11-04 09:55:37 +01:00
|
|
|
|
|
|
|
$weekdays = [
|
|
|
|
1 => 'monday',
|
|
|
|
2 => 'tuesday',
|
|
|
|
3 => 'wednesday',
|
|
|
|
4 => 'thursday',
|
|
|
|
5 => 'friday',
|
|
|
|
6 => 'saturday',
|
|
|
|
7 => 'sunday',
|
|
|
|
];
|
|
|
|
|
2021-11-03 10:59:00 +01:00
|
|
|
$data = [];
|
|
|
|
if (empty($templates) === false) {
|
|
|
|
foreach ($templates as $template) {
|
2021-11-04 09:55:37 +01:00
|
|
|
if ((bool) $template[$weekdays[$day_code]] === false) {
|
2021-11-03 10:59:00 +01:00
|
|
|
$data[] = [
|
|
|
|
'name' => $template['name'],
|
|
|
|
'id_group' => ui_print_group_icon(
|
|
|
|
$template['id_group'],
|
|
|
|
true
|
|
|
|
),
|
|
|
|
'type' => $template['type'],
|
|
|
|
'monday' => (bool) $template['monday'] === true
|
|
|
|
? html_print_image(
|
|
|
|
'images/tick.png',
|
|
|
|
true,
|
|
|
|
['class' => 'invert_filter']
|
|
|
|
)
|
|
|
|
: '',
|
|
|
|
'tuesday' => (bool) $template['tuesday'] === true
|
|
|
|
? html_print_image(
|
|
|
|
'images/tick.png',
|
|
|
|
true,
|
|
|
|
['class' => 'invert_filter']
|
|
|
|
)
|
|
|
|
: '',
|
|
|
|
'wednesday' => (bool) $template['wednesday'] === true
|
|
|
|
? html_print_image(
|
|
|
|
'images/tick.png',
|
|
|
|
true,
|
|
|
|
['class' => 'invert_filter']
|
|
|
|
)
|
|
|
|
: '',
|
|
|
|
'thursday' => (bool) $template['thursday'] === true
|
|
|
|
? html_print_image(
|
|
|
|
'images/tick.png',
|
|
|
|
true,
|
|
|
|
['class' => 'invert_filter']
|
|
|
|
)
|
|
|
|
: '',
|
|
|
|
'friday' => (bool) $template['friday'] === true
|
|
|
|
? html_print_image(
|
|
|
|
'images/tick.png',
|
|
|
|
true,
|
|
|
|
['class' => 'invert_filter']
|
|
|
|
)
|
|
|
|
: '',
|
|
|
|
'saturday' => (bool) $template['saturday'] === true
|
|
|
|
? html_print_image(
|
|
|
|
'images/tick.png',
|
|
|
|
true,
|
|
|
|
['class' => 'invert_filter']
|
|
|
|
)
|
|
|
|
: '',
|
|
|
|
'sunday' => (bool) $template['sunday'] === true
|
|
|
|
? html_print_image(
|
|
|
|
'images/tick.png',
|
|
|
|
true,
|
|
|
|
['class' => 'invert_filter']
|
|
|
|
)
|
|
|
|
: '',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode(
|
|
|
|
[
|
|
|
|
'data' => $data,
|
|
|
|
'recordsTotal' => $count[0]['total'],
|
|
|
|
'recordsFiltered' => count($data),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-02 17:49:45 +01:00
|
|
|
}
|