color
This commit is contained in:
parent
3ed3a14443
commit
25268ec9b4
|
@ -0,0 +1,27 @@
|
|||
START TRANSACTION;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `talert_calendar` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100) NOT NULL default '',
|
||||
`id_group` INT(10) NOT NULL DEFAULT 0,
|
||||
`description` text,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
INSERT IGNORE INTO `talert_calendar` VALUES (1, 'Default', 0, 'Default calendar');
|
||||
|
||||
ALTER TABLE `talert_special_days` ADD COLUMN `id_calendar` int(10) unsigned NOT NULL DEFAULT 1;
|
||||
ALTER TABLE `talert_special_days` ADD COLUMN `day_code` tinyint(2) unsigned NOT NULL DEFAULT 0;
|
||||
|
||||
UPDATE `talert_special_days` set `day_code` = 1 WHERE `same_day` = 'monday';
|
||||
UPDATE `talert_special_days` set `day_code` = 2 WHERE `same_day` = 'tuesday';
|
||||
UPDATE `talert_special_days` set `day_code` = 3 WHERE `same_day` = 'wednesday';
|
||||
UPDATE `talert_special_days` set `day_code` = 4 WHERE `same_day` = 'thursday';
|
||||
UPDATE `talert_special_days` set `day_code` = 5 WHERE `same_day` = 'friday';
|
||||
UPDATE `talert_special_days` set `day_code` = 6 WHERE `same_day` = 'saturday';
|
||||
UPDATE `talert_special_days` set `day_code` = 7 WHERE `same_day` = 'sunday';
|
||||
|
||||
ALTER TABLE `talert_special_days` DROP COLUMN `same_day`;
|
||||
ALTER TABLE `talert_special_days` ADD FOREIGN KEY (`id_calendar`) REFERENCES `talert_calendar`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
COMMIT;
|
|
@ -4221,3 +4221,30 @@ INSERT INTO `tncm_script` VALUES
|
|||
(5,5,'enable
expect:Password:\s*
_enablepass_
term length 0
config term
end
end
exit
');
|
||||
|
||||
INSERT INTO `tncm_template_scripts`(`id_template`, `id_script`) VALUES (1,1),(1,2),(1,3),(1,4),(1,5);
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- Table `talert_calendar`
|
||||
-- ----------------------------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `talert_calendar` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100) NOT NULL default '',
|
||||
`id_group` INT(10) NOT NULL DEFAULT 0,
|
||||
`description` text,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
INSERT IGNORE INTO `talert_calendar` VALUES (1, 'Default', 0, 'Default calendar');
|
||||
|
||||
ALTER TABLE `talert_special_days` ADD COLUMN `id_calendar` int(10) unsigned NOT NULL DEFAULT 1;
|
||||
ALTER TABLE `talert_special_days` ADD COLUMN `day_code` tinyint(2) unsigned NOT NULL DEFAULT 0;
|
||||
|
||||
UPDATE `talert_special_days` set `day_code` = 1 WHERE `same_day` = 'monday';
|
||||
UPDATE `talert_special_days` set `day_code` = 2 WHERE `same_day` = 'tuesday';
|
||||
UPDATE `talert_special_days` set `day_code` = 3 WHERE `same_day` = 'wednesday';
|
||||
UPDATE `talert_special_days` set `day_code` = 4 WHERE `same_day` = 'thursday';
|
||||
UPDATE `talert_special_days` set `day_code` = 5 WHERE `same_day` = 'friday';
|
||||
UPDATE `talert_special_days` set `day_code` = 6 WHERE `same_day` = 'saturday';
|
||||
UPDATE `talert_special_days` set `day_code` = 7 WHERE `same_day` = 'sunday';
|
||||
|
||||
ALTER TABLE `talert_special_days` DROP COLUMN `same_day`;
|
||||
ALTER TABLE `talert_special_days` ADD FOREIGN KEY (`id_calendar`) REFERENCES `talert_calendar`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Special days.
|
||||
* Calendar controller.
|
||||
*
|
||||
* @category Alerts
|
||||
* @package Pandora FMS
|
||||
|
@ -26,890 +26,50 @@
|
|||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Load global vars.
|
||||
// Begin.
|
||||
global $config;
|
||||
|
||||
require_once 'include/functions_alerts.php';
|
||||
require_once 'include/ics-parser/class.iCalReader.php';
|
||||
require_once $config['homedir'].'/vendor/autoload.php';
|
||||
require_once $config['homedir'].'/include/class/CalendarManager.class.php';
|
||||
|
||||
check_login();
|
||||
use PandoraFMS\CalendarManager;
|
||||
|
||||
if (! check_acl($config['id_user'], 0, 'LM')) {
|
||||
db_pandora_audit(
|
||||
'ACL Violation',
|
||||
'Trying to access Alert Management'
|
||||
);
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
$ajaxPage = 'godmode/alerts/alert_special_days';
|
||||
$url = 'index.php?sec=galertas&sec2=godmode/alerts/alert_special_days';
|
||||
|
||||
if (is_ajax() === true) {
|
||||
$get_alert_command = (bool) get_parameter('get_alert_command');
|
||||
if ($get_alert_command === true) {
|
||||
$id = (int) get_parameter('id');
|
||||
$command = alerts_get_alert_command($id);
|
||||
echo json_encode($command);
|
||||
}
|
||||
|
||||
$get_template_alerts = (bool) get_parameter('get_template_alerts');
|
||||
if ($get_template_alerts === true) {
|
||||
$filter['special_day'] = 1;
|
||||
$templates = alerts_get_alert_templates($filter);
|
||||
$date = get_parameter('date', '');
|
||||
$id_group = get_parameter('id_group', 0);
|
||||
$same_day = get_parameter('same_day', '');
|
||||
|
||||
$output = '<h4>'.__('Same as %s', ucfirst($same_day));
|
||||
$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' => [
|
||||
'get_template_alerts_data' => 1,
|
||||
'same_day' => $same_day,
|
||||
],
|
||||
'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;
|
||||
}
|
||||
|
||||
$get_template_alerts_data = (bool) get_parameter('get_template_alerts_data');
|
||||
if ($get_template_alerts_data === true) {
|
||||
$filters = get_parameter('filter', []);
|
||||
if (empty($filters['type']) === false) {
|
||||
$filter['type'] = $filters['type'];
|
||||
}
|
||||
|
||||
if (empty($filters['name']) === false) {
|
||||
$filter[] = "name LIKE '%".$filters['name']."%'";
|
||||
}
|
||||
|
||||
$filter['special_day'] = 1;
|
||||
|
||||
$templates = alerts_get_alert_templates($filter);
|
||||
$count = alerts_get_alert_templates($filter, ['COUNT(*) AS total']);
|
||||
|
||||
$same_day = get_parameter('same_day', '');
|
||||
$data = [];
|
||||
if (empty($templates) === false) {
|
||||
foreach ($templates as $template) {
|
||||
if ((bool) $template[$same_day] === false) {
|
||||
$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;
|
||||
// Control call flow.
|
||||
try {
|
||||
// User access and validation is being processed on class constructor.
|
||||
$cs = new CalendarManager($url, $ajaxPage);
|
||||
} catch (Exception $e) {
|
||||
if ((bool) is_ajax() === true) {
|
||||
echo json_encode(['error' => '[CalendarManager]'.$e->getMessage() ]);
|
||||
exit;
|
||||
} else {
|
||||
echo '[CalendarManager]'.$e->getMessage();
|
||||
}
|
||||
|
||||
// Stop this execution, but continue 'globally'.
|
||||
return;
|
||||
}
|
||||
|
||||
// Header.
|
||||
ui_print_page_header(
|
||||
__('Alerts').' » '.__('Special days list'),
|
||||
'images/gm_alerts.png',
|
||||
false,
|
||||
'alert_special_days',
|
||||
true
|
||||
);
|
||||
// AJAX controller.
|
||||
if ((bool) is_ajax() === true) {
|
||||
$method = get_parameter('method');
|
||||
|
||||
$update_special_day = (bool) get_parameter('update_special_day');
|
||||
$create_special_day = (bool) get_parameter('create_special_day');
|
||||
$delete_special_day = (bool) get_parameter('delete_special_day');
|
||||
$upload_ical = (bool) get_parameter('upload_ical', 0);
|
||||
$display_range = (int) get_parameter('display_range');
|
||||
|
||||
$url = 'index.php?sec=galertas&sec2=godmode/alerts/alert_special_days';
|
||||
$url_alert = 'index.php?sec=galertas&sec2=';
|
||||
$url_alert .= 'godmode/alerts/configure_alert_special_days';
|
||||
|
||||
if ($upload_ical === true) {
|
||||
$same_day = (string) get_parameter('same_day');
|
||||
$overwrite = (bool) get_parameter('overwrite', 0);
|
||||
$values = [];
|
||||
$values['id_group'] = (string) get_parameter('id_group');
|
||||
$values['same_day'] = $same_day;
|
||||
|
||||
$error = $_FILES['ical_file']['error'];
|
||||
$extension = substr($_FILES['ical_file']['name'], -3);
|
||||
|
||||
if ($error == 0 && strcasecmp($extension, 'ics') == 0) {
|
||||
$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;
|
||||
$date_check = db_get_value_filter(
|
||||
'date',
|
||||
'talert_special_days',
|
||||
$filter
|
||||
);
|
||||
if ($date_check == $date) {
|
||||
if ($overwrite) {
|
||||
$id_special_day = db_get_value_filter(
|
||||
'id',
|
||||
'talert_special_days',
|
||||
$filter
|
||||
);
|
||||
alerts_update_alert_special_day(
|
||||
$id_special_day,
|
||||
$values
|
||||
);
|
||||
} else {
|
||||
if ($skipped_dates == '') {
|
||||
$skipped_dates = __('Skipped dates: ');
|
||||
}
|
||||
|
||||
$skipped_dates .= $date.' ';
|
||||
}
|
||||
} else {
|
||||
alerts_create_alert_special_day($date, $same_day, $values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = true;
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if ($result === true) {
|
||||
db_pandora_audit(
|
||||
'Special days list',
|
||||
'Upload iCalendar '.$_FILES['ical_file']['name']
|
||||
);
|
||||
}
|
||||
|
||||
ui_print_result_message(
|
||||
$result,
|
||||
__('Success to upload iCalendar').'<br />'.$skipped_dates,
|
||||
__('Fail to upload iCalendar')
|
||||
);
|
||||
}
|
||||
|
||||
if ($create_special_day === true) {
|
||||
$date = (string) get_parameter('date');
|
||||
$same_day = (string) get_parameter('same_day');
|
||||
$values = [];
|
||||
$values['id_group'] = (string) get_parameter('id_group');
|
||||
$values['description'] = io_safe_input(
|
||||
strip_tags(io_safe_output((string) get_parameter('description')))
|
||||
);
|
||||
|
||||
$aviable_description = true;
|
||||
if (preg_match('/script/i', $values['description'])) {
|
||||
$aviable_description = false;
|
||||
}
|
||||
|
||||
$array_date = explode('-', $date);
|
||||
|
||||
$year = $array_date[0];
|
||||
$month = $array_date[1];
|
||||
$day = $array_date[2];
|
||||
|
||||
if ($year == '*') {
|
||||
$year = '0001';
|
||||
$date = $year.'-'.$month.'-'.$day;
|
||||
}
|
||||
|
||||
if (!checkdate($month, $day, $year)) {
|
||||
$result = '';
|
||||
} else {
|
||||
$filter['id_group'] = $values['id_group'];
|
||||
$filter['same_day'] = $same_day;
|
||||
$filter['date'] = $date;
|
||||
$date_check = db_get_value_filter(
|
||||
'date',
|
||||
'talert_special_days',
|
||||
$filter
|
||||
);
|
||||
|
||||
if ($date_check == $date) {
|
||||
$result = '';
|
||||
$messageAction = __('Could not be created, it already exists');
|
||||
if (method_exists($cs, $method) === true) {
|
||||
if (CalendarManager::ajaxMethod($method) === true) {
|
||||
$cs->{$method}();
|
||||
} else {
|
||||
if ($aviable_description === true) {
|
||||
$result = alerts_create_alert_special_day(
|
||||
$date,
|
||||
$same_day,
|
||||
$values
|
||||
);
|
||||
$info = '{"Date":"'.$date;
|
||||
$info .= '","Same day of the week":"'.$same_day;
|
||||
$info .= '","Description":"'.$values['description'].'"}';
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
$cs->error('Unavailable method.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
db_pandora_audit(
|
||||
'Command management',
|
||||
'Create special day '.$result,
|
||||
false,
|
||||
false,
|
||||
$info
|
||||
);
|
||||
} else {
|
||||
db_pandora_audit(
|
||||
'Command management',
|
||||
'Fail try to create special day',
|
||||
false,
|
||||
false
|
||||
);
|
||||
$cs->error('Method not found. ['.$method.']');
|
||||
}
|
||||
|
||||
// Show errors.
|
||||
if (isset($messageAction) === false) {
|
||||
$messageAction = __('Could not be created');
|
||||
}
|
||||
|
||||
$messageAction = ui_print_result_message(
|
||||
$result,
|
||||
__('Successfully created'),
|
||||
$messageAction
|
||||
);
|
||||
}
|
||||
|
||||
if ($update_special_day === true) {
|
||||
$id = (int) get_parameter('id');
|
||||
$alert = alerts_get_alert_special_day($id);
|
||||
$date = (string) get_parameter('date');
|
||||
$date_orig = (string) get_parameter('date_orig');
|
||||
$same_day = (string) get_parameter('same_day');
|
||||
$description = io_safe_input(strip_tags(io_safe_output((string) get_parameter('description'))));
|
||||
$id_group = (string) get_parameter('id_group');
|
||||
$id_group_orig = (string) get_parameter('id_group_orig');
|
||||
|
||||
$aviable_description = true;
|
||||
if (preg_match('/script/i', $description)) {
|
||||
$aviable_description = false;
|
||||
}
|
||||
|
||||
$array_date = explode('-', $date);
|
||||
|
||||
$year = $array_date[0];
|
||||
$month = $array_date[1];
|
||||
$day = $array_date[2];
|
||||
|
||||
if ($year == '*') {
|
||||
// '0001' means every year.
|
||||
$year = '0001';
|
||||
$date = $year.'-'.$month.'-'.$day;
|
||||
}
|
||||
|
||||
$values = [];
|
||||
$values['date'] = $date;
|
||||
$values['id_group'] = $id_group;
|
||||
$values['same_day'] = $same_day;
|
||||
$values['description'] = $description;
|
||||
|
||||
if (!checkdate($month, $day, $year)) {
|
||||
$result = '';
|
||||
} else {
|
||||
$filter['id_group'] = $id_group;
|
||||
$filter['date'] = $date;
|
||||
$filter['same_day'] = $same_day;
|
||||
$date_check = db_get_value_filter('date', 'talert_special_days', $filter);
|
||||
if ($date_check == $date) {
|
||||
$result = '';
|
||||
$messageAction = __('Could not be updated, it already exists');
|
||||
} else {
|
||||
if ($aviable_description !== false) {
|
||||
$result = alerts_update_alert_special_day($id, $values);
|
||||
$info = '{"Date":"'.$date;
|
||||
$info .= '","Same day of the week":"'.$same_day;
|
||||
$info .= '","Description":"'.$description.'"}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
db_pandora_audit(
|
||||
'Command management',
|
||||
'Update special day '.$id,
|
||||
false,
|
||||
false,
|
||||
$info
|
||||
);
|
||||
} else {
|
||||
db_pandora_audit(
|
||||
'Command management',
|
||||
'Fail to update special day '.$id,
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Show errors.
|
||||
if (isset($messageAction) === false) {
|
||||
$messageAction = __('Could not be updated');
|
||||
}
|
||||
|
||||
$messageAction = ui_print_result_message(
|
||||
$result,
|
||||
__('Successfully updated'),
|
||||
$messageAction
|
||||
);
|
||||
}
|
||||
|
||||
if ($delete_special_day === true) {
|
||||
$id = (int) get_parameter('id');
|
||||
|
||||
$result = alerts_delete_alert_special_day($id);
|
||||
|
||||
if ($result) {
|
||||
db_pandora_audit(
|
||||
'Command management',
|
||||
'Delete special day '.$id
|
||||
);
|
||||
} else {
|
||||
db_pandora_audit(
|
||||
'Command management',
|
||||
'Fail to delete special day '.$id
|
||||
);
|
||||
}
|
||||
|
||||
ui_print_result_message(
|
||||
$result,
|
||||
__('Successfully deleted'),
|
||||
__('Could not be deleted')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
echo "<table cellpadding='4' cellspacing='4' class='databox upload bolder margin-bottom-10' width='100%
|
||||
'><tr>";
|
||||
echo "<form id='icalendar-special-days' method='post' enctype='multipart/form-data' action='index.php?sec=gagente&sec2=godmode/alerts/alert_special_days'>";
|
||||
echo '<td>';
|
||||
echo __('iCalendar(.ics) file').' ';
|
||||
html_print_input_file('ical_file', false, false);
|
||||
echo '</td><td>';
|
||||
echo __('Same day of the week');
|
||||
$days = [];
|
||||
$days['monday'] = __('Monday');
|
||||
$days['tuesday'] = __('Tuesday');
|
||||
$days['wednesday'] = __('Wednesday');
|
||||
$days['thursday'] = __('Thursday');
|
||||
$days['friday'] = __('Friday');
|
||||
$days['saturday'] = __('Saturday');
|
||||
$days['sunday'] = __('Sunday');
|
||||
html_print_select($days, 'same_day', $same_day, '', '', 0, false, false, false);
|
||||
echo '</td><td>';
|
||||
echo __('Group').' ';
|
||||
$own_info = get_user_info($config['id_user']);
|
||||
if (!users_can_manage_group_all('LM')) {
|
||||
$can_manage_group_all = false;
|
||||
// Stop any execution.
|
||||
exit;
|
||||
} else {
|
||||
$can_manage_group_all = true;
|
||||
// Run.
|
||||
$cs->run();
|
||||
}
|
||||
|
||||
echo '<div class="inline w250px">';
|
||||
html_print_select_groups(
|
||||
false,
|
||||
'LM',
|
||||
$can_manage_group_all,
|
||||
'id_group',
|
||||
$id_group,
|
||||
false,
|
||||
'',
|
||||
0,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
'',
|
||||
false,
|
||||
'width:100px;'
|
||||
);
|
||||
echo '</div>';
|
||||
echo '</td><td>';
|
||||
echo __('Overwrite');
|
||||
ui_print_help_tip(
|
||||
__('Check this box, if you want to overwrite existing same days.'),
|
||||
false
|
||||
);
|
||||
echo ' ';
|
||||
html_print_checkbox('overwrite', 1, $overwrite, false, false, false, true);
|
||||
echo '</td><td>';
|
||||
html_print_input_hidden('upload_ical', 1);
|
||||
echo "<input id='srcbutton' name='srcbutton' type='submit' class='sub next' value='".__('Upload')."'>";
|
||||
echo '</td></form>';
|
||||
echo '</tr></table>';
|
||||
|
||||
|
||||
$this_year = date('Y');
|
||||
$this_month = date('m');
|
||||
|
||||
$filter = [];
|
||||
if (!is_user_admin($config['id_user'])) {
|
||||
$filter['id_group'] = array_keys(users_get_groups(false, 'LM'));
|
||||
}
|
||||
|
||||
// Show display range.
|
||||
$html = "<table cellpadding='4' cellspacing='4' width='100%' margin-bottom: 10px;'><tr><td>".__('Display range: ');
|
||||
if ($display_range) {
|
||||
$html .= '<a href="'.$url.'">['.__('Default').']</a> ';
|
||||
if ($display_range > 1970) {
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= ($display_range - 1);
|
||||
$html .= '"><< </a>';
|
||||
}
|
||||
|
||||
$html .= '<a href="'.$url.'&display_range='.$display_range.'" class="bolder">['.$display_range.']</a>';
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= ($display_range + 1);
|
||||
$html .= '"> >></a>';
|
||||
} else {
|
||||
$html .= '<a href="'.$url.'" class="bolder">['.__('Default').']</a> ';
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= ($this_year - 1);
|
||||
$html .= '"><< </a>';
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= $this_year;
|
||||
$html .= '">[';
|
||||
$html .= $this_year;
|
||||
$html .= ']</a>';
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= ($this_year + 1);
|
||||
$html .= '"> >></a>';
|
||||
}
|
||||
|
||||
$html .= '</td></tr>';
|
||||
echo $html;
|
||||
|
||||
// Show calendar.
|
||||
for ($month = 1; $month <= 12; $month++) {
|
||||
if ($display_range) {
|
||||
$display_month = $month;
|
||||
$display_year = $display_range;
|
||||
} else {
|
||||
$display_month = ($this_month + $month - 1);
|
||||
$display_year = $this_year;
|
||||
}
|
||||
|
||||
if ($display_month > 12) {
|
||||
$display_month -= 12;
|
||||
$display_year++;
|
||||
}
|
||||
|
||||
$cal_table = new stdClass();
|
||||
$cal_table->width = '100%';
|
||||
$cal_table->class = 'databox data';
|
||||
|
||||
$cal_table->data = [];
|
||||
$cal_table->head = [];
|
||||
$cal_table->head[0] = __('Sun');
|
||||
$cal_table->head[1] = __('Mon');
|
||||
$cal_table->head[2] = __('Tue');
|
||||
$cal_table->head[3] = __('Wed');
|
||||
$cal_table->head[4] = __('Thu');
|
||||
$cal_table->head[5] = __('Fri');
|
||||
$cal_table->head[6] = __('Sat');
|
||||
$cal_table->cellstyle = [];
|
||||
$cal_table->size = [];
|
||||
$cal_table->size[0] = '14%';
|
||||
$cal_table->size[1] = '14%';
|
||||
$cal_table->size[2] = '14%';
|
||||
$cal_table->size[3] = '14%';
|
||||
$cal_table->size[4] = '14%';
|
||||
$cal_table->size[5] = '14%';
|
||||
$cal_table->size[6] = '14%';
|
||||
$cal_table->align = [];
|
||||
$cal_table->border = '1';
|
||||
$cal_table->titlestyle = 'text-align:center; font-weight: bold;';
|
||||
switch ($display_month) {
|
||||
case 1:
|
||||
$cal_table->title = __('January');
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$cal_table->title = __('February');
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$cal_table->title = __('March');
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$cal_table->title = __('April');
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$cal_table->title = __('May');
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$cal_table->title = __('June');
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$cal_table->title = __('July');
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$cal_table->title = __('August');
|
||||
break;
|
||||
|
||||
case 9:
|
||||
$cal_table->title = __('September');
|
||||
break;
|
||||
|
||||
case 10:
|
||||
$cal_table->title = __('October');
|
||||
break;
|
||||
|
||||
case 11:
|
||||
$cal_table->title = __('November');
|
||||
break;
|
||||
|
||||
case 12:
|
||||
$cal_table->title = __('December');
|
||||
break;
|
||||
|
||||
default:
|
||||
// Not possible.
|
||||
break;
|
||||
}
|
||||
|
||||
$cal_table->title .= ' / '.$display_year;
|
||||
|
||||
$last_day = date('j', mktime(0, 0, 0, ($display_month + 1), 0, $display_year));
|
||||
$cal_line = 0;
|
||||
|
||||
for ($day = 1; $day < ($last_day + 1); $day++) {
|
||||
$week = date('w', mktime(0, 0, 0, $display_month, $day, $display_year));
|
||||
if ($cal_line == 0 && $week != 0 && $day == 1) {
|
||||
for ($i = 0; $i < $week; $i++) {
|
||||
$cal_table->cellstyle[$cal_line][$i] = 'font-size: 18px;';
|
||||
$cal_table->data[$cal_line][$i] = '-';
|
||||
}
|
||||
}
|
||||
|
||||
if ($week == 0 || $week == 6) {
|
||||
$cal_table->cellstyle[$cal_line][$week] = 'color: red;';
|
||||
}
|
||||
|
||||
$date = sprintf('%04d-%02d-%02d', $display_year, $display_month, $day);
|
||||
$date_wildcard = sprintf('0001-%02d-%02d', $display_month, $day);
|
||||
$special_days = '';
|
||||
$filter['date'] = [
|
||||
$date,
|
||||
$date_wildcard,
|
||||
];
|
||||
$filter['order']['field'] = 'date';
|
||||
$filter['order']['order'] = 'DESC';
|
||||
$special_days = db_get_all_rows_filter('talert_special_days', $filter);
|
||||
|
||||
$cal_table->cellstyle[$cal_line][$week] .= 'font-size: 18px;';
|
||||
$cal_table->data[$cal_line][$week] = $day.' ';
|
||||
|
||||
$cal_table->data[$cal_line][$week] .= '<a href="'.$url_alert.'&create_special_day=1&date='.$date.'" title=';
|
||||
$cal_table->data[$cal_line][$week] .= __('Create');
|
||||
$cal_table->data[$cal_line][$week] .= '>'.html_print_image(
|
||||
'images/add_mc.png',
|
||||
true,
|
||||
['class' => 'invert_filter']
|
||||
).'</a>';
|
||||
|
||||
if (empty($special_days) === false) {
|
||||
$cal_table->data[$cal_line][$week] .= '<br>';
|
||||
foreach ($special_days as $special_day) {
|
||||
// Only show description if is filled.
|
||||
$cal_table->data[$cal_line][$week] .= '<div class="note-special-day">';
|
||||
$cal_table->data[$cal_line][$week] .= '<div>';
|
||||
$cal_table->data[$cal_line][$week] .= ui_print_group_icon(
|
||||
$special_day['id_group'],
|
||||
true
|
||||
);
|
||||
|
||||
if (empty($special_day['description']) === false) {
|
||||
$cal_table->data[$cal_line][$week] .= ui_print_help_tip($special_day['description'], true);
|
||||
}
|
||||
|
||||
if ($special_day['date'] == $date_wildcard) {
|
||||
$cal_table->data[$cal_line][$week] .= '(';
|
||||
$cal_table->data[$cal_line][$week] .= ui_print_help_tip(
|
||||
'This is valid every year. However, this will be ignored if indivisual setting for the same group is available.',
|
||||
true
|
||||
);
|
||||
$cal_table->data[$cal_line][$week] .= ') ';
|
||||
}
|
||||
|
||||
$cal_table->data[$cal_line][$week] .= __('As ');
|
||||
switch ($special_day['same_day']) {
|
||||
case 'monday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Monday');
|
||||
break;
|
||||
|
||||
case 'tuesday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Tuesday');
|
||||
break;
|
||||
|
||||
case 'wednesday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Wednesday');
|
||||
break;
|
||||
|
||||
case 'thursday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Thursday');
|
||||
break;
|
||||
|
||||
case 'friday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Friday');
|
||||
break;
|
||||
|
||||
case 'saturday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Saturday');
|
||||
break;
|
||||
|
||||
case 'sunday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Sunday');
|
||||
break;
|
||||
|
||||
default:
|
||||
// Not possible.
|
||||
break;
|
||||
}
|
||||
|
||||
$cal_table->data[$cal_line][$week] .= '</div>';
|
||||
$cal_table->data[$cal_line][$week] .= '<div>';
|
||||
if ($special_day['id_group'] || ($can_manage_group_all && $special_day['id_group'] == 0)) {
|
||||
$script_delete = '';
|
||||
$dateformat = date_create($special_day['date']);
|
||||
$options_zoom = htmlspecialchars(
|
||||
json_encode(
|
||||
[
|
||||
'date' => $special_day['date'],
|
||||
'id_group' => $special_day['id_group'],
|
||||
'same_day' => $special_day['same_day'],
|
||||
'btn_ok_text' => __('Create'),
|
||||
'btn_cancel_text' => __('Cancel'),
|
||||
'title' => date_format($dateformat, 'd M Y'),
|
||||
'url' => ui_get_full_url('ajax.php', false, false, false),
|
||||
'page' => 'godmode/alerts/alert_special_days',
|
||||
'loading' => __('Loading, this operation might take several minutes...'),
|
||||
]
|
||||
),
|
||||
ENT_QUOTES,
|
||||
'UTF-8'
|
||||
);
|
||||
|
||||
$onclick_zoom = 'load_templates_alerts_special_days('.$options_zoom.')';
|
||||
$cal_table->data[$cal_line][$week] .= '<a href="#" onclick="'.$onclick_zoom.'"';
|
||||
$cal_table->data[$cal_line][$week] .= 'title="';
|
||||
$cal_table->data[$cal_line][$week] .= __('Show templates');
|
||||
$cal_table->data[$cal_line][$week] .= '">';
|
||||
$cal_table->data[$cal_line][$week] .= html_print_image(
|
||||
'images/zoom.png',
|
||||
true,
|
||||
['class' => 'invert_filter']
|
||||
).'</a>';
|
||||
$cal_table->data[$cal_line][$week] .= '<a href="'.$url_alert.'&id='.$special_day['id'].'" title=';
|
||||
$cal_table->data[$cal_line][$week] .= __('Edit');
|
||||
$cal_table->data[$cal_line][$week] .= '>'.html_print_image(
|
||||
'images/config.png',
|
||||
true,
|
||||
['class' => 'invert_filter']
|
||||
).'</a> ';
|
||||
$url_delete = $url.'&delete_special_day=1&id='.$special_day['id'];
|
||||
$script_delete = 'if (!confirm(\''.__('Are you sure?').'\')) return false;';
|
||||
$cal_table->data[$cal_line][$week] .= '<a href="'.$url_delete.'"';
|
||||
$cal_table->data[$cal_line][$week] .= ' onClick="'.$script_delete.'"';
|
||||
$cal_table->data[$cal_line][$week] .= 'title="';
|
||||
$cal_table->data[$cal_line][$week] .= __('Remove');
|
||||
$cal_table->data[$cal_line][$week] .= '">';
|
||||
$cal_table->data[$cal_line][$week] .= html_print_image(
|
||||
'images/cross.png',
|
||||
true,
|
||||
['class' => 'invert_filter']
|
||||
).'</a>';
|
||||
}
|
||||
|
||||
$cal_table->data[$cal_line][$week] .= '</div>';
|
||||
$cal_table->data[$cal_line][$week] .= '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($week == 6) {
|
||||
$cal_line++;
|
||||
}
|
||||
}
|
||||
|
||||
for ($padding = ($week + 1); $padding <= 6; $padding++) {
|
||||
$cal_table->cellstyle[$cal_line][$padding] = 'font-size: 18px;';
|
||||
$cal_table->data[$cal_line][$padding] = '-';
|
||||
}
|
||||
|
||||
html_print_table($cal_table);
|
||||
}
|
||||
|
||||
echo '<div class="action-buttons" style="width: '.$table->width.'">';
|
||||
echo '<form method="post" action="'.$url_alert.'">';
|
||||
html_print_submit_button(__('Create'), 'create', false, 'class="sub next"');
|
||||
html_print_input_hidden('create_special_day', 1);
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
echo '<div id="modal-alert-templates" class="invisible"></div>';
|
||||
ui_require_javascript_file('pandora_alerts');
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$(document).ready (function () {
|
||||
$("#srcbutton").click (function (e) {
|
||||
e.preventDefault();
|
||||
load_templates_alerts_special_days({
|
||||
date: '',
|
||||
id_group: $("#id_group").val(),
|
||||
same_day: $("#same_day").val(),
|
||||
btn_ok_text: '<?php echo __('Create'); ?>',
|
||||
btn_cancel_text: '<?php echo __('Cancel'); ?>',
|
||||
title: '<?php echo __('Load calendar'); ?>',
|
||||
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>',
|
||||
page: "godmode/alerts/alert_special_days",
|
||||
loading: '<?php echo __('Loading, this operation might take several minutes...'); ?>',
|
||||
name_form: 'icalendar-special-days'
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1,915 @@
|
|||
<?php
|
||||
/**
|
||||
* Special days.
|
||||
*
|
||||
* @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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Load global vars.
|
||||
global $config;
|
||||
|
||||
require_once 'include/functions_alerts.php';
|
||||
require_once 'include/ics-parser/class.iCalReader.php';
|
||||
|
||||
check_login();
|
||||
|
||||
if (! check_acl($config['id_user'], 0, 'LM')) {
|
||||
db_pandora_audit(
|
||||
'ACL Violation',
|
||||
'Trying to access Alert Management'
|
||||
);
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
if (is_ajax() === true) {
|
||||
$get_alert_command = (bool) get_parameter('get_alert_command');
|
||||
if ($get_alert_command === true) {
|
||||
$id = (int) get_parameter('id');
|
||||
$command = alerts_get_alert_command($id);
|
||||
echo json_encode($command);
|
||||
}
|
||||
|
||||
$get_template_alerts = (bool) get_parameter('get_template_alerts');
|
||||
if ($get_template_alerts === true) {
|
||||
$filter['special_day'] = 1;
|
||||
$templates = alerts_get_alert_templates($filter);
|
||||
$date = get_parameter('date', '');
|
||||
$id_group = get_parameter('id_group', 0);
|
||||
$same_day = get_parameter('same_day', '');
|
||||
|
||||
$output = '<h4>'.__('Same as %s', ucfirst($same_day));
|
||||
$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' => [
|
||||
'get_template_alerts_data' => 1,
|
||||
'same_day' => $same_day,
|
||||
],
|
||||
'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;
|
||||
}
|
||||
|
||||
$get_template_alerts_data = (bool) get_parameter('get_template_alerts_data');
|
||||
if ($get_template_alerts_data === true) {
|
||||
$filters = get_parameter('filter', []);
|
||||
if (empty($filters['type']) === false) {
|
||||
$filter['type'] = $filters['type'];
|
||||
}
|
||||
|
||||
if (empty($filters['name']) === false) {
|
||||
$filter[] = "name LIKE '%".$filters['name']."%'";
|
||||
}
|
||||
|
||||
$filter['special_day'] = 1;
|
||||
|
||||
$templates = alerts_get_alert_templates($filter);
|
||||
$count = alerts_get_alert_templates($filter, ['COUNT(*) AS total']);
|
||||
|
||||
$same_day = get_parameter('same_day', '');
|
||||
$data = [];
|
||||
if (empty($templates) === false) {
|
||||
foreach ($templates as $template) {
|
||||
if ((bool) $template[$same_day] === false) {
|
||||
$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;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Header.
|
||||
ui_print_page_header(
|
||||
__('Alerts').' » '.__('Special days list'),
|
||||
'images/gm_alerts.png',
|
||||
false,
|
||||
'alert_special_days',
|
||||
true
|
||||
);
|
||||
|
||||
$update_special_day = (bool) get_parameter('update_special_day');
|
||||
$create_special_day = (bool) get_parameter('create_special_day');
|
||||
$delete_special_day = (bool) get_parameter('delete_special_day');
|
||||
$upload_ical = (bool) get_parameter('upload_ical', 0);
|
||||
$display_range = (int) get_parameter('display_range');
|
||||
|
||||
$url = 'index.php?sec=galertas&sec2=godmode/alerts/alert_special_days';
|
||||
$url_alert = 'index.php?sec=galertas&sec2=';
|
||||
$url_alert .= 'godmode/alerts/configure_alert_special_days';
|
||||
|
||||
if ($upload_ical === true) {
|
||||
$same_day = (string) get_parameter('same_day');
|
||||
$overwrite = (bool) get_parameter('overwrite', 0);
|
||||
$values = [];
|
||||
$values['id_group'] = (string) get_parameter('id_group');
|
||||
$values['same_day'] = $same_day;
|
||||
|
||||
$error = $_FILES['ical_file']['error'];
|
||||
$extension = substr($_FILES['ical_file']['name'], -3);
|
||||
|
||||
if ($error == 0 && strcasecmp($extension, 'ics') == 0) {
|
||||
$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;
|
||||
$date_check = db_get_value_filter(
|
||||
'date',
|
||||
'talert_special_days',
|
||||
$filter
|
||||
);
|
||||
if ($date_check == $date) {
|
||||
if ($overwrite) {
|
||||
$id_special_day = db_get_value_filter(
|
||||
'id',
|
||||
'talert_special_days',
|
||||
$filter
|
||||
);
|
||||
alerts_update_alert_special_day(
|
||||
$id_special_day,
|
||||
$values
|
||||
);
|
||||
} else {
|
||||
if ($skipped_dates == '') {
|
||||
$skipped_dates = __('Skipped dates: ');
|
||||
}
|
||||
|
||||
$skipped_dates .= $date.' ';
|
||||
}
|
||||
} else {
|
||||
alerts_create_alert_special_day($date, $same_day, $values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = true;
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if ($result === true) {
|
||||
db_pandora_audit(
|
||||
'Special days list',
|
||||
'Upload iCalendar '.$_FILES['ical_file']['name']
|
||||
);
|
||||
}
|
||||
|
||||
ui_print_result_message(
|
||||
$result,
|
||||
__('Success to upload iCalendar').'<br />'.$skipped_dates,
|
||||
__('Fail to upload iCalendar')
|
||||
);
|
||||
}
|
||||
|
||||
if ($create_special_day === true) {
|
||||
$date = (string) get_parameter('date');
|
||||
$same_day = (string) get_parameter('same_day');
|
||||
$values = [];
|
||||
$values['id_group'] = (string) get_parameter('id_group');
|
||||
$values['description'] = io_safe_input(
|
||||
strip_tags(io_safe_output((string) get_parameter('description')))
|
||||
);
|
||||
|
||||
$aviable_description = true;
|
||||
if (preg_match('/script/i', $values['description'])) {
|
||||
$aviable_description = false;
|
||||
}
|
||||
|
||||
$array_date = explode('-', $date);
|
||||
|
||||
$year = $array_date[0];
|
||||
$month = $array_date[1];
|
||||
$day = $array_date[2];
|
||||
|
||||
if ($year == '*') {
|
||||
$year = '0001';
|
||||
$date = $year.'-'.$month.'-'.$day;
|
||||
}
|
||||
|
||||
if (!checkdate($month, $day, $year)) {
|
||||
$result = '';
|
||||
} else {
|
||||
$filter['id_group'] = $values['id_group'];
|
||||
$filter['same_day'] = $same_day;
|
||||
$filter['date'] = $date;
|
||||
$date_check = db_get_value_filter(
|
||||
'date',
|
||||
'talert_special_days',
|
||||
$filter
|
||||
);
|
||||
|
||||
if ($date_check == $date) {
|
||||
$result = '';
|
||||
$messageAction = __('Could not be created, it already exists');
|
||||
} else {
|
||||
if ($aviable_description === true) {
|
||||
$result = alerts_create_alert_special_day(
|
||||
$date,
|
||||
$same_day,
|
||||
$values
|
||||
);
|
||||
$info = '{"Date":"'.$date;
|
||||
$info .= '","Same day of the week":"'.$same_day;
|
||||
$info .= '","Description":"'.$values['description'].'"}';
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
db_pandora_audit(
|
||||
'Command management',
|
||||
'Create special day '.$result,
|
||||
false,
|
||||
false,
|
||||
$info
|
||||
);
|
||||
} else {
|
||||
db_pandora_audit(
|
||||
'Command management',
|
||||
'Fail try to create special day',
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
// Show errors.
|
||||
if (isset($messageAction) === false) {
|
||||
$messageAction = __('Could not be created');
|
||||
}
|
||||
|
||||
$messageAction = ui_print_result_message(
|
||||
$result,
|
||||
__('Successfully created'),
|
||||
$messageAction
|
||||
);
|
||||
}
|
||||
|
||||
if ($update_special_day === true) {
|
||||
$id = (int) get_parameter('id');
|
||||
$alert = alerts_get_alert_special_day($id);
|
||||
$date = (string) get_parameter('date');
|
||||
$date_orig = (string) get_parameter('date_orig');
|
||||
$same_day = (string) get_parameter('same_day');
|
||||
$description = io_safe_input(strip_tags(io_safe_output((string) get_parameter('description'))));
|
||||
$id_group = (string) get_parameter('id_group');
|
||||
$id_group_orig = (string) get_parameter('id_group_orig');
|
||||
|
||||
$aviable_description = true;
|
||||
if (preg_match('/script/i', $description)) {
|
||||
$aviable_description = false;
|
||||
}
|
||||
|
||||
$array_date = explode('-', $date);
|
||||
|
||||
$year = $array_date[0];
|
||||
$month = $array_date[1];
|
||||
$day = $array_date[2];
|
||||
|
||||
if ($year == '*') {
|
||||
// '0001' means every year.
|
||||
$year = '0001';
|
||||
$date = $year.'-'.$month.'-'.$day;
|
||||
}
|
||||
|
||||
$values = [];
|
||||
$values['date'] = $date;
|
||||
$values['id_group'] = $id_group;
|
||||
$values['same_day'] = $same_day;
|
||||
$values['description'] = $description;
|
||||
|
||||
if (!checkdate($month, $day, $year)) {
|
||||
$result = '';
|
||||
} else {
|
||||
$filter['id_group'] = $id_group;
|
||||
$filter['date'] = $date;
|
||||
$filter['same_day'] = $same_day;
|
||||
$date_check = db_get_value_filter('date', 'talert_special_days', $filter);
|
||||
if ($date_check == $date) {
|
||||
$result = '';
|
||||
$messageAction = __('Could not be updated, it already exists');
|
||||
} else {
|
||||
if ($aviable_description !== false) {
|
||||
$result = alerts_update_alert_special_day($id, $values);
|
||||
$info = '{"Date":"'.$date;
|
||||
$info .= '","Same day of the week":"'.$same_day;
|
||||
$info .= '","Description":"'.$description.'"}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
db_pandora_audit(
|
||||
'Command management',
|
||||
'Update special day '.$id,
|
||||
false,
|
||||
false,
|
||||
$info
|
||||
);
|
||||
} else {
|
||||
db_pandora_audit(
|
||||
'Command management',
|
||||
'Fail to update special day '.$id,
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Show errors.
|
||||
if (isset($messageAction) === false) {
|
||||
$messageAction = __('Could not be updated');
|
||||
}
|
||||
|
||||
$messageAction = ui_print_result_message(
|
||||
$result,
|
||||
__('Successfully updated'),
|
||||
$messageAction
|
||||
);
|
||||
}
|
||||
|
||||
if ($delete_special_day === true) {
|
||||
$id = (int) get_parameter('id');
|
||||
|
||||
$result = alerts_delete_alert_special_day($id);
|
||||
|
||||
if ($result) {
|
||||
db_pandora_audit(
|
||||
'Command management',
|
||||
'Delete special day '.$id
|
||||
);
|
||||
} else {
|
||||
db_pandora_audit(
|
||||
'Command management',
|
||||
'Fail to delete special day '.$id
|
||||
);
|
||||
}
|
||||
|
||||
ui_print_result_message(
|
||||
$result,
|
||||
__('Successfully deleted'),
|
||||
__('Could not be deleted')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
echo "<table cellpadding='4' cellspacing='4' class='databox upload bolder margin-bottom-10' width='100%
|
||||
'><tr>";
|
||||
echo "<form id='icalendar-special-days' method='post' enctype='multipart/form-data' action='index.php?sec=gagente&sec2=godmode/alerts/alert_special_days'>";
|
||||
echo '<td>';
|
||||
echo __('iCalendar(.ics) file').' ';
|
||||
html_print_input_file('ical_file', false, false);
|
||||
echo '</td><td>';
|
||||
echo __('Same day of the week');
|
||||
$days = [];
|
||||
$days['monday'] = __('Monday');
|
||||
$days['tuesday'] = __('Tuesday');
|
||||
$days['wednesday'] = __('Wednesday');
|
||||
$days['thursday'] = __('Thursday');
|
||||
$days['friday'] = __('Friday');
|
||||
$days['saturday'] = __('Saturday');
|
||||
$days['sunday'] = __('Sunday');
|
||||
html_print_select($days, 'same_day', $same_day, '', '', 0, false, false, false);
|
||||
echo '</td><td>';
|
||||
echo __('Group').' ';
|
||||
$own_info = get_user_info($config['id_user']);
|
||||
if (!users_can_manage_group_all('LM')) {
|
||||
$can_manage_group_all = false;
|
||||
} else {
|
||||
$can_manage_group_all = true;
|
||||
}
|
||||
|
||||
echo '<div class="inline w250px">';
|
||||
html_print_select_groups(
|
||||
false,
|
||||
'LM',
|
||||
$can_manage_group_all,
|
||||
'id_group',
|
||||
$id_group,
|
||||
false,
|
||||
'',
|
||||
0,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
'',
|
||||
false,
|
||||
'width:100px;'
|
||||
);
|
||||
echo '</div>';
|
||||
echo '</td><td>';
|
||||
echo __('Overwrite');
|
||||
ui_print_help_tip(
|
||||
__('Check this box, if you want to overwrite existing same days.'),
|
||||
false
|
||||
);
|
||||
echo ' ';
|
||||
html_print_checkbox('overwrite', 1, $overwrite, false, false, false, true);
|
||||
echo '</td><td>';
|
||||
html_print_input_hidden('upload_ical', 1);
|
||||
echo "<input id='srcbutton' name='srcbutton' type='submit' class='sub next' value='".__('Upload')."'>";
|
||||
echo '</td></form>';
|
||||
echo '</tr></table>';
|
||||
|
||||
|
||||
$this_year = date('Y');
|
||||
$this_month = date('m');
|
||||
|
||||
$filter = [];
|
||||
if (!is_user_admin($config['id_user'])) {
|
||||
$filter['id_group'] = array_keys(users_get_groups(false, 'LM'));
|
||||
}
|
||||
|
||||
// Show display range.
|
||||
$html = "<table cellpadding='4' cellspacing='4' width='100%' margin-bottom: 10px;'><tr><td>".__('Display range: ');
|
||||
if ($display_range) {
|
||||
$html .= '<a href="'.$url.'">['.__('Default').']</a> ';
|
||||
if ($display_range > 1970) {
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= ($display_range - 1);
|
||||
$html .= '"><< </a>';
|
||||
}
|
||||
|
||||
$html .= '<a href="'.$url.'&display_range='.$display_range.'" class="bolder">['.$display_range.']</a>';
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= ($display_range + 1);
|
||||
$html .= '"> >></a>';
|
||||
} else {
|
||||
$html .= '<a href="'.$url.'" class="bolder">['.__('Default').']</a> ';
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= ($this_year - 1);
|
||||
$html .= '"><< </a>';
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= $this_year;
|
||||
$html .= '">[';
|
||||
$html .= $this_year;
|
||||
$html .= ']</a>';
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= ($this_year + 1);
|
||||
$html .= '"> >></a>';
|
||||
}
|
||||
|
||||
$html .= '</td></tr>';
|
||||
echo $html;
|
||||
|
||||
// Show calendar.
|
||||
for ($month = 1; $month <= 12; $month++) {
|
||||
if ($display_range) {
|
||||
$display_month = $month;
|
||||
$display_year = $display_range;
|
||||
} else {
|
||||
$display_month = ($this_month + $month - 1);
|
||||
$display_year = $this_year;
|
||||
}
|
||||
|
||||
if ($display_month > 12) {
|
||||
$display_month -= 12;
|
||||
$display_year++;
|
||||
}
|
||||
|
||||
$cal_table = new stdClass();
|
||||
$cal_table->width = '100%';
|
||||
$cal_table->class = 'databox data';
|
||||
|
||||
$cal_table->data = [];
|
||||
$cal_table->head = [];
|
||||
$cal_table->head[0] = __('Sun');
|
||||
$cal_table->head[1] = __('Mon');
|
||||
$cal_table->head[2] = __('Tue');
|
||||
$cal_table->head[3] = __('Wed');
|
||||
$cal_table->head[4] = __('Thu');
|
||||
$cal_table->head[5] = __('Fri');
|
||||
$cal_table->head[6] = __('Sat');
|
||||
$cal_table->cellstyle = [];
|
||||
$cal_table->size = [];
|
||||
$cal_table->size[0] = '14%';
|
||||
$cal_table->size[1] = '14%';
|
||||
$cal_table->size[2] = '14%';
|
||||
$cal_table->size[3] = '14%';
|
||||
$cal_table->size[4] = '14%';
|
||||
$cal_table->size[5] = '14%';
|
||||
$cal_table->size[6] = '14%';
|
||||
$cal_table->align = [];
|
||||
$cal_table->border = '1';
|
||||
$cal_table->titlestyle = 'text-align:center; font-weight: bold;';
|
||||
switch ($display_month) {
|
||||
case 1:
|
||||
$cal_table->title = __('January');
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$cal_table->title = __('February');
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$cal_table->title = __('March');
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$cal_table->title = __('April');
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$cal_table->title = __('May');
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$cal_table->title = __('June');
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$cal_table->title = __('July');
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$cal_table->title = __('August');
|
||||
break;
|
||||
|
||||
case 9:
|
||||
$cal_table->title = __('September');
|
||||
break;
|
||||
|
||||
case 10:
|
||||
$cal_table->title = __('October');
|
||||
break;
|
||||
|
||||
case 11:
|
||||
$cal_table->title = __('November');
|
||||
break;
|
||||
|
||||
case 12:
|
||||
$cal_table->title = __('December');
|
||||
break;
|
||||
|
||||
default:
|
||||
// Not possible.
|
||||
break;
|
||||
}
|
||||
|
||||
$cal_table->title .= ' / '.$display_year;
|
||||
|
||||
$last_day = date('j', mktime(0, 0, 0, ($display_month + 1), 0, $display_year));
|
||||
$cal_line = 0;
|
||||
|
||||
for ($day = 1; $day < ($last_day + 1); $day++) {
|
||||
$week = date('w', mktime(0, 0, 0, $display_month, $day, $display_year));
|
||||
if ($cal_line == 0 && $week != 0 && $day == 1) {
|
||||
for ($i = 0; $i < $week; $i++) {
|
||||
$cal_table->cellstyle[$cal_line][$i] = 'font-size: 18px;';
|
||||
$cal_table->data[$cal_line][$i] = '-';
|
||||
}
|
||||
}
|
||||
|
||||
if ($week == 0 || $week == 6) {
|
||||
$cal_table->cellstyle[$cal_line][$week] = 'color: red;';
|
||||
}
|
||||
|
||||
$date = sprintf('%04d-%02d-%02d', $display_year, $display_month, $day);
|
||||
$date_wildcard = sprintf('0001-%02d-%02d', $display_month, $day);
|
||||
$special_days = '';
|
||||
$filter['date'] = [
|
||||
$date,
|
||||
$date_wildcard,
|
||||
];
|
||||
$filter['order']['field'] = 'date';
|
||||
$filter['order']['order'] = 'DESC';
|
||||
$special_days = db_get_all_rows_filter('talert_special_days', $filter);
|
||||
|
||||
$cal_table->cellstyle[$cal_line][$week] .= 'font-size: 18px;';
|
||||
$cal_table->data[$cal_line][$week] = $day.' ';
|
||||
|
||||
$cal_table->data[$cal_line][$week] .= '<a href="'.$url_alert.'&create_special_day=1&date='.$date.'" title=';
|
||||
$cal_table->data[$cal_line][$week] .= __('Create');
|
||||
$cal_table->data[$cal_line][$week] .= '>'.html_print_image(
|
||||
'images/add_mc.png',
|
||||
true,
|
||||
['class' => 'invert_filter']
|
||||
).'</a>';
|
||||
|
||||
if (empty($special_days) === false) {
|
||||
$cal_table->data[$cal_line][$week] .= '<br>';
|
||||
foreach ($special_days as $special_day) {
|
||||
// Only show description if is filled.
|
||||
$cal_table->data[$cal_line][$week] .= '<div class="note-special-day">';
|
||||
$cal_table->data[$cal_line][$week] .= '<div>';
|
||||
$cal_table->data[$cal_line][$week] .= ui_print_group_icon(
|
||||
$special_day['id_group'],
|
||||
true
|
||||
);
|
||||
|
||||
if (empty($special_day['description']) === false) {
|
||||
$cal_table->data[$cal_line][$week] .= ui_print_help_tip($special_day['description'], true);
|
||||
}
|
||||
|
||||
if ($special_day['date'] == $date_wildcard) {
|
||||
$cal_table->data[$cal_line][$week] .= '(';
|
||||
$cal_table->data[$cal_line][$week] .= ui_print_help_tip(
|
||||
'This is valid every year. However, this will be ignored if indivisual setting for the same group is available.',
|
||||
true
|
||||
);
|
||||
$cal_table->data[$cal_line][$week] .= ') ';
|
||||
}
|
||||
|
||||
$cal_table->data[$cal_line][$week] .= __('As ');
|
||||
switch ($special_day['same_day']) {
|
||||
case 'monday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Monday');
|
||||
break;
|
||||
|
||||
case 'tuesday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Tuesday');
|
||||
break;
|
||||
|
||||
case 'wednesday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Wednesday');
|
||||
break;
|
||||
|
||||
case 'thursday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Thursday');
|
||||
break;
|
||||
|
||||
case 'friday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Friday');
|
||||
break;
|
||||
|
||||
case 'saturday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Saturday');
|
||||
break;
|
||||
|
||||
case 'sunday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Sunday');
|
||||
break;
|
||||
|
||||
default:
|
||||
// Not possible.
|
||||
break;
|
||||
}
|
||||
|
||||
$cal_table->data[$cal_line][$week] .= '</div>';
|
||||
$cal_table->data[$cal_line][$week] .= '<div>';
|
||||
if ($special_day['id_group'] || ($can_manage_group_all && $special_day['id_group'] == 0)) {
|
||||
$script_delete = '';
|
||||
$dateformat = date_create($special_day['date']);
|
||||
$options_zoom = htmlspecialchars(
|
||||
json_encode(
|
||||
[
|
||||
'date' => $special_day['date'],
|
||||
'id_group' => $special_day['id_group'],
|
||||
'same_day' => $special_day['same_day'],
|
||||
'btn_ok_text' => __('Create'),
|
||||
'btn_cancel_text' => __('Cancel'),
|
||||
'title' => date_format($dateformat, 'd M Y'),
|
||||
'url' => ui_get_full_url('ajax.php', false, false, false),
|
||||
'page' => 'godmode/alerts/alert_special_days',
|
||||
'loading' => __('Loading, this operation might take several minutes...'),
|
||||
]
|
||||
),
|
||||
ENT_QUOTES,
|
||||
'UTF-8'
|
||||
);
|
||||
|
||||
$onclick_zoom = 'load_templates_alerts_special_days('.$options_zoom.')';
|
||||
$cal_table->data[$cal_line][$week] .= '<a href="#" onclick="'.$onclick_zoom.'"';
|
||||
$cal_table->data[$cal_line][$week] .= 'title="';
|
||||
$cal_table->data[$cal_line][$week] .= __('Show templates');
|
||||
$cal_table->data[$cal_line][$week] .= '">';
|
||||
$cal_table->data[$cal_line][$week] .= html_print_image(
|
||||
'images/zoom.png',
|
||||
true,
|
||||
['class' => 'invert_filter']
|
||||
).'</a>';
|
||||
$cal_table->data[$cal_line][$week] .= '<a href="'.$url_alert.'&id='.$special_day['id'].'" title=';
|
||||
$cal_table->data[$cal_line][$week] .= __('Edit');
|
||||
$cal_table->data[$cal_line][$week] .= '>'.html_print_image(
|
||||
'images/config.png',
|
||||
true,
|
||||
['class' => 'invert_filter']
|
||||
).'</a> ';
|
||||
$url_delete = $url.'&delete_special_day=1&id='.$special_day['id'];
|
||||
$script_delete = 'if (!confirm(\''.__('Are you sure?').'\')) return false;';
|
||||
$cal_table->data[$cal_line][$week] .= '<a href="'.$url_delete.'"';
|
||||
$cal_table->data[$cal_line][$week] .= ' onClick="'.$script_delete.'"';
|
||||
$cal_table->data[$cal_line][$week] .= 'title="';
|
||||
$cal_table->data[$cal_line][$week] .= __('Remove');
|
||||
$cal_table->data[$cal_line][$week] .= '">';
|
||||
$cal_table->data[$cal_line][$week] .= html_print_image(
|
||||
'images/cross.png',
|
||||
true,
|
||||
['class' => 'invert_filter']
|
||||
).'</a>';
|
||||
}
|
||||
|
||||
$cal_table->data[$cal_line][$week] .= '</div>';
|
||||
$cal_table->data[$cal_line][$week] .= '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($week == 6) {
|
||||
$cal_line++;
|
||||
}
|
||||
}
|
||||
|
||||
for ($padding = ($week + 1); $padding <= 6; $padding++) {
|
||||
$cal_table->cellstyle[$cal_line][$padding] = 'font-size: 18px;';
|
||||
$cal_table->data[$cal_line][$padding] = '-';
|
||||
}
|
||||
|
||||
html_print_table($cal_table);
|
||||
}
|
||||
|
||||
echo '<div class="action-buttons" style="width: '.$table->width.'">';
|
||||
echo '<form method="post" action="'.$url_alert.'">';
|
||||
html_print_submit_button(__('Create'), 'create', false, 'class="sub next"');
|
||||
html_print_input_hidden('create_special_day', 1);
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
echo '<div id="modal-alert-templates" class="invisible"></div>';
|
||||
ui_require_javascript_file('pandora_alerts');
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$(document).ready (function () {
|
||||
$("#srcbutton").click (function (e) {
|
||||
e.preventDefault();
|
||||
load_templates_alerts_special_days({
|
||||
date: '',
|
||||
id_group: $("#id_group").val(),
|
||||
same_day: $("#same_day").val(),
|
||||
btn_ok_text: '<?php echo __('Create'); ?>',
|
||||
btn_cancel_text: '<?php echo __('Cancel'); ?>',
|
||||
title: '<?php echo __('Load calendar'); ?>',
|
||||
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>',
|
||||
page: "godmode/alerts/alert_special_days",
|
||||
loading: '<?php echo __('Loading, this operation might take several minutes...'); ?>',
|
||||
name_form: 'icalendar-special-days'
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,651 @@
|
|||
<?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
|
||||
*/
|
||||
public static $AJAXMethods = ['drawListCalendar'];
|
||||
|
||||
|
||||
/**
|
||||
* 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(
|
||||
'ACL Violation',
|
||||
'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(
|
||||
$this->url.'&tab=list'
|
||||
).'&pure='.(int) $config['pure'].'">'.html_print_image(
|
||||
'images/list.png',
|
||||
true,
|
||||
[
|
||||
'title' => __('Alert calendar list'),
|
||||
'class' => 'invert_filter',
|
||||
]
|
||||
).'</a>',
|
||||
];
|
||||
|
||||
if ($tab !== 'list') {
|
||||
$buttons['special_days'] = [
|
||||
'active' => false,
|
||||
'text' => '<a href="'.ui_get_full_url(
|
||||
$this->url.'&tab=special_days'
|
||||
).'&pure='.(int) $config['pure'].'">'.html_print_image(
|
||||
'images/templates.png',
|
||||
true,
|
||||
[
|
||||
'title' => __('Alert special days'),
|
||||
'class' => 'invert_filter',
|
||||
]
|
||||
).'</a>',
|
||||
];
|
||||
}
|
||||
|
||||
$buttons[$tab]['active'] = true;
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute page and show interface.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$op = get_parameter('op');
|
||||
$tab = get_parameter('tab');
|
||||
switch ($tab) {
|
||||
case 'special_days':
|
||||
if ($op === 'edit') {
|
||||
if ($this->showSpecialDaysEdition() !== true) {
|
||||
return;
|
||||
}
|
||||
} else if ($op === 'delete') {
|
||||
// $this->deleteVendor();
|
||||
hd('delete special days');
|
||||
}
|
||||
|
||||
echo 'WIP special list';
|
||||
$this->showSpecialDays();
|
||||
break;
|
||||
|
||||
case 'list':
|
||||
default:
|
||||
if ($op === 'edit') {
|
||||
if ($this->showCalendarEdition() !== true) {
|
||||
return;
|
||||
}
|
||||
} else if ($op === 'delete') {
|
||||
// $this->deleteVendor();
|
||||
hd('delete calendar');
|
||||
}
|
||||
|
||||
$this->showCalendarList();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
$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 {
|
||||
$calendar->name(get_parameter('name', null));
|
||||
$calendar->id_group(get_parameter('id_group', null));
|
||||
$calendar->description(get_parameter('description', null));
|
||||
|
||||
// Save template.
|
||||
if ($calendar->save() === true) {
|
||||
$success = true;
|
||||
} else {
|
||||
global $config;
|
||||
$reason = \__(
|
||||
'Failed saving calendar: ',
|
||||
$config['dbconnection']->error
|
||||
);
|
||||
}
|
||||
} 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,
|
||||
'url' => $this->url.'&op=edit&tab=list',
|
||||
'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'];
|
||||
|
||||
if ((bool) $data === true) {
|
||||
$manage = check_acl(
|
||||
$config['id_user'],
|
||||
0,
|
||||
'LM',
|
||||
true
|
||||
);
|
||||
|
||||
$data = array_reduce(
|
||||
$data,
|
||||
function ($carry, $item) use ($manage) {
|
||||
// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
// Transforms array of arrays $data into an array
|
||||
// of objects, making a post-process of certain fields.
|
||||
$tmp = (object) $item;
|
||||
|
||||
if ((bool) $manage === true) {
|
||||
$name = '<b><a href="';
|
||||
$name .= ui_get_full_url(
|
||||
$this->url.'&op=edit&id='.$tmp->id
|
||||
);
|
||||
$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) {
|
||||
// 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>';
|
||||
|
||||
// Options. Especial days.
|
||||
$tmp->options .= '<a href="';
|
||||
$tmp->options .= ui_get_full_url(
|
||||
$this->url.'&op=special_days&tab=special_days&id='.$tmp->id
|
||||
);
|
||||
$tmp->options .= '">';
|
||||
$tmp->options .= html_print_image(
|
||||
'images/add.png',
|
||||
true,
|
||||
[
|
||||
'title' => __('Special days'),
|
||||
'class' => 'invert_filter',
|
||||
]
|
||||
);
|
||||
$tmp->options .= '</a>';
|
||||
|
||||
// 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>';
|
||||
}
|
||||
|
||||
$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;
|
||||
$id = (int) get_parameter('id');
|
||||
$display_range = (int) get_parameter('display_range', date('Y'));
|
||||
try {
|
||||
// Datatables offset, limit and order.
|
||||
$date = $display_range.'-'.date('m').'-1';
|
||||
$futureDate = date('Y-m-d', strtotime('+1 year', strtotime($date)));
|
||||
$filter = [];
|
||||
|
||||
$filter['date'] = $date;
|
||||
$filter['futureDate'] = $futureDate;
|
||||
$filter['id_calendar'] = $id;
|
||||
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.
|
||||
$filter
|
||||
);
|
||||
|
||||
hd($specialDays);
|
||||
} catch (\Exception $e) {
|
||||
if ($id > 0) {
|
||||
$this->message = \ui_print_error_message(
|
||||
\__('Special days not found: %s', $e->getMessage()),
|
||||
'',
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
View::render(
|
||||
'calendar/special_days',
|
||||
[
|
||||
'ajax_url' => $this->ajaxUrl,
|
||||
'url' => $this->url.'&tab=special_days',
|
||||
'tabs' => $this->getTabs('special_days'),
|
||||
'message' => $this->message,
|
||||
'specialDays' => $specialDays,
|
||||
'id_calendar' => $id,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show form special day.
|
||||
*
|
||||
* @return boolean Continue showing list or not.
|
||||
*/
|
||||
public function showSpecialDaysEdition()
|
||||
{
|
||||
$id = (int) get_parameter('id');
|
||||
$new = false;
|
||||
try {
|
||||
$specialDay = new SpecialDay($id);
|
||||
if ($id === 0) {
|
||||
$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 {
|
||||
$specialDay->name(get_parameter('name', null));
|
||||
$specialDay->id_group(get_parameter('id_group', null));
|
||||
$specialDay->description(get_parameter('description', null));
|
||||
|
||||
// Save template.
|
||||
if ($specialDay->save() === true) {
|
||||
$success = true;
|
||||
} else {
|
||||
global $config;
|
||||
$reason = \__(
|
||||
'Failed saving special day: ',
|
||||
$config['dbconnection']->error
|
||||
);
|
||||
}
|
||||
} 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',
|
||||
[
|
||||
'ajax_url' => $this->ajaxUrl,
|
||||
'url' => $this->url.'&op=edit&tab=special_days',
|
||||
'tabs' => $this->getTabs('special_days'),
|
||||
'specialDay' => $specialDay,
|
||||
'message' => $this->message,
|
||||
'create' => $new,
|
||||
]
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,217 @@
|
|||
<?php
|
||||
// phpcs:disable Squiz.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Calendar entity class.
|
||||
*
|
||||
* @category Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage OpenSource
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* PandoraFMS agent entity.
|
||||
*/
|
||||
class Calendar extends Entity
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Builds a PandoraFMS\Calendar object from given id.
|
||||
*
|
||||
* @param integer $id Id special day.
|
||||
*/
|
||||
public function __construct(?int $id=null)
|
||||
{
|
||||
if (is_numeric($id) === true
|
||||
&& $id > 0
|
||||
) {
|
||||
parent::__construct(
|
||||
'talert_calendar',
|
||||
['id' => $id]
|
||||
);
|
||||
} else {
|
||||
// Create empty skel.
|
||||
parent::__construct('talert_calendar');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves current definition to database.
|
||||
*
|
||||
* @return mixed Affected rows of false in case of error.
|
||||
* @throws \Exception On error.
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
if ($this->fields['id'] > 0) {
|
||||
// Update.
|
||||
$updates = $this->fields;
|
||||
|
||||
$rs = \db_process_sql_update(
|
||||
'talert_calendar',
|
||||
$updates,
|
||||
['id' => $this->fields['id']]
|
||||
);
|
||||
|
||||
if ($rs === false) {
|
||||
global $config;
|
||||
throw new \Exception(
|
||||
__METHOD__.' error: '.$config['dbconnection']->error
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Creation.
|
||||
$inserts = $this->fields;
|
||||
|
||||
// Clean null fields.
|
||||
foreach ($inserts as $k => $v) {
|
||||
if ($v === null) {
|
||||
unset($inserts[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
$rs = \db_process_sql_insert(
|
||||
'talert_calendar',
|
||||
$inserts
|
||||
);
|
||||
|
||||
if ($rs === false) {
|
||||
global $config;
|
||||
throw new \Exception(
|
||||
__METHOD__.' error: '.$config['dbconnection']->error
|
||||
);
|
||||
}
|
||||
|
||||
$this->fields['id'] = $rs;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array with all calendar filtered.
|
||||
*
|
||||
* @param array $fields Fields array or 'count' keyword to retrieve count.
|
||||
* @param array $filter Filters to be applied.
|
||||
* @param boolean $count Retrieve count of items instead results.
|
||||
* @param integer $offset Offset (pagination).
|
||||
* @param integer $limit Limit (pagination).
|
||||
* @param string $order Sort order.
|
||||
* @param string $sort_field Sort field.
|
||||
*
|
||||
* @return array With all results.
|
||||
* @throws \Exception On error.
|
||||
*/
|
||||
public static function calendars(
|
||||
array $fields=[ '`talert_calendar`.*' ],
|
||||
array $filter=[],
|
||||
bool $count=false,
|
||||
?int $offset=null,
|
||||
?int $limit=null,
|
||||
?string $order=null,
|
||||
?string $sort_field=null
|
||||
) {
|
||||
$sql_filters = [];
|
||||
$order_by = '';
|
||||
$pagination = '';
|
||||
|
||||
if (isset($filter['free_search']) === true
|
||||
&& empty($filter['free_search']) === false
|
||||
) {
|
||||
$sql_filters[] = vsprintf(
|
||||
' AND (`talert_calendar`.`name` like "%%%s%%"
|
||||
OR `talert_calendar`.`description` like "%%%s%%")',
|
||||
array_fill(0, 2, $filter['free_search'])
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($order) === true) {
|
||||
$dir = 'asc';
|
||||
if ($order === 'desc') {
|
||||
$dir = 'desc';
|
||||
};
|
||||
|
||||
if (in_array(
|
||||
$sort_field,
|
||||
[ 'name' ]
|
||||
) === true
|
||||
) {
|
||||
$order_by = sprintf(
|
||||
'ORDER BY `talert_calendar`.`%s` %s',
|
||||
$sort_field,
|
||||
$dir
|
||||
);
|
||||
} else {
|
||||
// Custom field order.
|
||||
$order_by = sprintf(
|
||||
'ORDER BY `%s` %s',
|
||||
$sort_field,
|
||||
$dir
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($limit) === true && $limit > 0
|
||||
&& isset($offset) === true && $offset >= 0
|
||||
) {
|
||||
$pagination = sprintf(
|
||||
' LIMIT %d OFFSET %d ',
|
||||
$limit,
|
||||
$offset
|
||||
);
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT %s
|
||||
FROM `talert_calendar`
|
||||
WHERE 1=1
|
||||
%s
|
||||
%s
|
||||
%s',
|
||||
join(',', $fields),
|
||||
join(' ', $sql_filters),
|
||||
$order_by,
|
||||
$pagination
|
||||
);
|
||||
|
||||
if ($count === true) {
|
||||
$sql = sprintf('SELECT count(*) as n FROM ( %s ) tt', $sql);
|
||||
|
||||
return ['count' => \db_get_value_sql($sql)];
|
||||
}
|
||||
|
||||
$return = \db_get_all_rows_sql($sql);
|
||||
|
||||
if (is_array($return) === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,254 @@
|
|||
<?php
|
||||
// phpcs:disable Squiz.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Special day entity class.
|
||||
*
|
||||
* @category Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage OpenSource
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* PandoraFMS agent entity.
|
||||
*/
|
||||
class SpecialDay extends Entity
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Builds a PandoraFMS\SpecialDay object from given id.
|
||||
*
|
||||
* @param integer $id Id special day.
|
||||
*/
|
||||
public function __construct(?int $id=null)
|
||||
{
|
||||
if (is_numeric($id) === true
|
||||
&& $id > 0
|
||||
) {
|
||||
parent::__construct(
|
||||
'talert_special_days',
|
||||
['id' => $id]
|
||||
);
|
||||
} else {
|
||||
// Create empty skel.
|
||||
parent::__construct('talert_special_days');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves current definition to database.
|
||||
*
|
||||
* @return mixed Affected rows of false in case of error.
|
||||
* @throws \Exception On error.
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
if ($this->fields['id'] > 0) {
|
||||
// Update.
|
||||
$updates = $this->fields;
|
||||
|
||||
$rs = \db_process_sql_update(
|
||||
'talert_special_days',
|
||||
$updates,
|
||||
['id' => $this->fields['id']]
|
||||
);
|
||||
|
||||
if ($rs === false) {
|
||||
global $config;
|
||||
throw new \Exception(
|
||||
__METHOD__.' error: '.$config['dbconnection']->error
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Creation.
|
||||
$inserts = $this->fields;
|
||||
|
||||
// Clean null fields.
|
||||
foreach ($inserts as $k => $v) {
|
||||
if ($v === null) {
|
||||
unset($inserts[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
$rs = \db_process_sql_insert(
|
||||
'talert_special_days',
|
||||
$inserts
|
||||
);
|
||||
|
||||
if ($rs === false) {
|
||||
global $config;
|
||||
throw new \Exception(
|
||||
__METHOD__.' error: '.$config['dbconnection']->error
|
||||
);
|
||||
}
|
||||
|
||||
$this->fields['id'] = $rs;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array with all special days filtered.
|
||||
*
|
||||
* @param array $fields Fields array or 'count' keyword to retrieve count.
|
||||
* @param array $filter Filters to be applied.
|
||||
* @param boolean $count Retrieve count of items instead results.
|
||||
* @param integer $offset Offset (pagination).
|
||||
* @param integer $limit Limit (pagination).
|
||||
* @param string $order Sort order.
|
||||
* @param string $sort_field Sort field.
|
||||
*
|
||||
* @return array With all results.
|
||||
* @throws \Exception On error.
|
||||
*/
|
||||
public static function specialDays(
|
||||
array $fields=[ '`talert_special_days`.*' ],
|
||||
array $filter=[],
|
||||
bool $count=false,
|
||||
?int $offset=null,
|
||||
?int $limit=null,
|
||||
?string $order=null,
|
||||
?string $sort_field=null
|
||||
) {
|
||||
$sql_filters = [];
|
||||
$order_by = '';
|
||||
$pagination = '';
|
||||
|
||||
if (isset($filter['free_search']) === true
|
||||
&& empty($filter['free_search']) === false
|
||||
) {
|
||||
$sql_filters[] = vsprintf(
|
||||
' AND `talert_special_days`.`name` like "%%%s%%"',
|
||||
array_fill(0, 1, $filter['free_search'])
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($filter['id_calendar']) === true
|
||||
&& empty($filter['id_calendar']) === false
|
||||
) {
|
||||
$sql_filters[] = sprintf(
|
||||
' AND `talert_special_days`.`id_calendar` = %d',
|
||||
$filter['id_calendar']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($filter['date']) === true
|
||||
&& empty($filter['date']) === false
|
||||
) {
|
||||
$sql_filters[] = sprintf(
|
||||
' AND `talert_special_days`.`date` >= "%s"',
|
||||
$filter['date']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($filter['futureDate']) === true
|
||||
&& empty($filter['futureDate']) === false
|
||||
) {
|
||||
$sql_filters[] = sprintf(
|
||||
' AND `talert_special_days`.`date` <= "%s"',
|
||||
$filter['futureDate']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($filter['id_group']) === true
|
||||
&& empty($filter['id_group']) === false
|
||||
) {
|
||||
$sql_filters[] = sprintf(
|
||||
' AND `talert_special_days`.`id_group` IN ("%s")',
|
||||
implode(',', $filter['id_group'])
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($order) === true) {
|
||||
$dir = 'asc';
|
||||
if ($order === 'desc') {
|
||||
$dir = 'desc';
|
||||
};
|
||||
|
||||
if (in_array(
|
||||
$sort_field,
|
||||
[ 'name' ]
|
||||
) === true
|
||||
) {
|
||||
$order_by = sprintf(
|
||||
'ORDER BY `talert_special_days`.`%s` %s',
|
||||
$sort_field,
|
||||
$dir
|
||||
);
|
||||
} else {
|
||||
// Custom field order.
|
||||
$order_by = sprintf(
|
||||
'ORDER BY `%s` %s',
|
||||
$sort_field,
|
||||
$dir
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($limit) === true && $limit > 0
|
||||
&& isset($offset) === true && $offset >= 0
|
||||
) {
|
||||
$pagination = sprintf(
|
||||
' LIMIT %d OFFSET %d ',
|
||||
$limit,
|
||||
$offset
|
||||
);
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT %s
|
||||
FROM `talert_special_days`
|
||||
WHERE 1=1
|
||||
%s
|
||||
%s
|
||||
%s',
|
||||
join(',', $fields),
|
||||
join(' ', $sql_filters),
|
||||
$order_by,
|
||||
$pagination
|
||||
);
|
||||
|
||||
hd($sql);
|
||||
|
||||
if ($count === true) {
|
||||
$sql = sprintf('SELECT count(*) as n FROM ( %s ) tt', $sql);
|
||||
|
||||
return ['count' => \db_get_value_sql($sql)];
|
||||
}
|
||||
|
||||
$return = \db_get_all_rows_sql($sql);
|
||||
|
||||
if (is_array($return) === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -570,16 +570,31 @@ CREATE TABLE IF NOT EXISTS `talert_template_module_actions` (
|
|||
ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `talert_calendar`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `talert_calendar` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100) NOT NULL default '',
|
||||
`id_group` INT(10) NOT NULL DEFAULT 0,
|
||||
`description` text,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `talert_special_days`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `talert_special_days` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id_calendar` int(10) unsigned NOT NULL DEFAULT 1,
|
||||
`id_group` INT(10) NOT NULL DEFAULT 0,
|
||||
`date` date NOT NULL DEFAULT '1970-01-01',
|
||||
`same_day` enum('monday','tuesday','wednesday','thursday','friday','saturday','sunday') NOT NULL DEFAULT 'sunday',
|
||||
`day_code` tinyint(2) NOT NULL,
|
||||
`description` text,
|
||||
PRIMARY KEY (`id`)
|
||||
PRIMARY KEY (`id`),
|
||||
FOREIGN KEY (`id_calendar`) REFERENCES talert_calendar(`id`)
|
||||
ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
|
|
|
@ -2788,3 +2788,5 @@ INSERT INTO `tncm_script` VALUES
|
|||
(5,5,'enable
expect:Password:\s*
_enablepass_
term length 0
config term
end
end
exit
');
|
||||
|
||||
INSERT INTO `tncm_template_scripts`(`id_template`, `id_script`) VALUES (1,1),(1,2),(1,3),(1,4),(1,5);
|
||||
|
||||
INSERT INTO `talert_calendar` VALUES (1, 'Default', 0, 'Default calendar');
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
/**
|
||||
* Calendar: edit page
|
||||
*
|
||||
* @category View
|
||||
* @package Pandora FMS
|
||||
* @subpackage Alert
|
||||
* @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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Extras required.
|
||||
ui_require_css_file('wizard');
|
||||
|
||||
// Header.
|
||||
\ui_print_page_header(
|
||||
// Title.
|
||||
__('Calendars Edit'),
|
||||
// Icon.
|
||||
'images/gm_alerts.png',
|
||||
// Return.
|
||||
false,
|
||||
// Help.
|
||||
'alert_special_days',
|
||||
// Godmode.
|
||||
true,
|
||||
// Options.
|
||||
$tabs
|
||||
);
|
||||
|
||||
if (empty($message) === false) {
|
||||
echo $message;
|
||||
}
|
||||
|
||||
$inputs = [];
|
||||
|
||||
// Name.
|
||||
$inputs[] = [
|
||||
'label' => __('Name'),
|
||||
'arguments' => [
|
||||
'type' => 'text',
|
||||
'name' => 'name',
|
||||
'required' => true,
|
||||
'value' => $calendar->name(),
|
||||
],
|
||||
];
|
||||
|
||||
// Group.
|
||||
$inputs[] = [
|
||||
'label' => __('Group'),
|
||||
'arguments' => [
|
||||
'type' => 'select_groups',
|
||||
'returnAllGroup' => true,
|
||||
'name' => 'id_group',
|
||||
'selected' => $calendar->id_group(),
|
||||
],
|
||||
];
|
||||
|
||||
// Description.
|
||||
$inputs[] = [
|
||||
'label' => __('Description'),
|
||||
'arguments' => [
|
||||
'type' => 'textarea',
|
||||
'name' => 'description',
|
||||
'required' => false,
|
||||
'value' => $calendar->description(),
|
||||
'rows' => 50,
|
||||
'columns' => 30,
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
// Submit.
|
||||
$inputs[] = [
|
||||
'arguments' => [
|
||||
'name' => 'button',
|
||||
'label' => (($create === true) ? __('Create') : __('Update')),
|
||||
'type' => 'submit',
|
||||
'attributes' => 'class="sub next"',
|
||||
],
|
||||
];
|
||||
|
||||
// Print form.
|
||||
HTML::printForm(
|
||||
[
|
||||
'form' => [
|
||||
'action' => $url.'&op=edit&action=save&id='.$calendar->id(),
|
||||
'method' => 'POST',
|
||||
],
|
||||
'inputs' => $inputs,
|
||||
],
|
||||
false,
|
||||
true
|
||||
);
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
/**
|
||||
* Calendar: Calendar list page.
|
||||
*
|
||||
* @category View
|
||||
* @package Pandora FMS
|
||||
* @subpackage Alert
|
||||
* @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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Header.
|
||||
\ui_print_page_header(
|
||||
// Title.
|
||||
__('Calendars'),
|
||||
// Icon.
|
||||
'images/gm_alerts.png',
|
||||
// Return.
|
||||
false,
|
||||
// Help.
|
||||
'alert_special_days',
|
||||
// Godmode.
|
||||
true,
|
||||
// Options.
|
||||
$tabs
|
||||
);
|
||||
|
||||
if (empty($message) === false) {
|
||||
echo $message;
|
||||
}
|
||||
|
||||
// Datatables list.
|
||||
try {
|
||||
$columns = [
|
||||
'name',
|
||||
'id_group',
|
||||
'description',
|
||||
[
|
||||
'text' => 'options',
|
||||
'class' => 'w150px action_buttons',
|
||||
],
|
||||
];
|
||||
|
||||
$column_names = [
|
||||
__('Name'),
|
||||
__('Group'),
|
||||
__('Description'),
|
||||
__('Options'),
|
||||
];
|
||||
|
||||
$tableId = 'calendar_list';
|
||||
// Load datatables user interface.
|
||||
ui_print_datatable(
|
||||
[
|
||||
'id' => $tableId,
|
||||
'class' => 'info_table',
|
||||
'style' => 'width: 100%',
|
||||
'columns' => $columns,
|
||||
'column_names' => $column_names,
|
||||
'ajax_url' => $ajax_url,
|
||||
'ajax_data' => ['method' => 'drawListCalendar'],
|
||||
'no_sortable_columns' => [-1],
|
||||
'order' => [
|
||||
'field' => 'name',
|
||||
'direction' => 'asc',
|
||||
],
|
||||
'search_button_class' => 'sub filter float-right',
|
||||
'form' => [
|
||||
'inputs' => [
|
||||
[
|
||||
'label' => __('Free search'),
|
||||
'type' => 'text',
|
||||
'class' => 'mw250px',
|
||||
'id' => 'free_search',
|
||||
'name' => 'free_search',
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
if ((bool) check_acl($config['id_user'], 0, 'LM') === true) {
|
||||
HTML::printForm(
|
||||
[
|
||||
'form' => [
|
||||
'action' => $url.'&op=edit',
|
||||
'method' => 'POST',
|
||||
],
|
||||
'inputs' => [
|
||||
[
|
||||
'arguments' => [
|
||||
'name' => 'button',
|
||||
'label' => __('Create'),
|
||||
'type' => 'submit',
|
||||
'attributes' => 'class="sub next"',
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
|
@ -0,0 +1,455 @@
|
|||
<?php
|
||||
/**
|
||||
* Calendar: Calendar list page.
|
||||
*
|
||||
* @category View
|
||||
* @package Pandora FMS
|
||||
* @subpackage Alert
|
||||
* @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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Header.
|
||||
\ui_print_page_header(
|
||||
// Title.
|
||||
__('Special days'),
|
||||
// Icon.
|
||||
'images/gm_alerts.png',
|
||||
// Return.
|
||||
false,
|
||||
// Help.
|
||||
'alert_special_days',
|
||||
// Godmode.
|
||||
true,
|
||||
// Options.
|
||||
$tabs
|
||||
);
|
||||
|
||||
if (empty($message) === false) {
|
||||
echo $message;
|
||||
}
|
||||
|
||||
$inputs = [];
|
||||
|
||||
// Name.
|
||||
$inputs[] = [
|
||||
'label' => __('iCalendar(.ics) file'),
|
||||
'arguments' => [
|
||||
'name' => 'ical_file',
|
||||
'type' => 'file',
|
||||
'columns' => 25,
|
||||
'rows' => 10,
|
||||
],
|
||||
];
|
||||
|
||||
$days = [];
|
||||
$days['monday'] = __('Monday');
|
||||
$days['tuesday'] = __('Tuesday');
|
||||
$days['wednesday'] = __('Wednesday');
|
||||
$days['thursday'] = __('Thursday');
|
||||
$days['friday'] = __('Friday');
|
||||
$days['saturday'] = __('Saturday');
|
||||
$days['sunday'] = __('Sunday');
|
||||
|
||||
// Same day of the week.
|
||||
$inputs[] = [
|
||||
'label' => __('Same day of the week'),
|
||||
'arguments' => [
|
||||
'name' => 'day_code',
|
||||
'type' => 'select',
|
||||
'fields' => $days,
|
||||
],
|
||||
];
|
||||
|
||||
// Group.
|
||||
$inputs[] = [
|
||||
'label' => __('Group'),
|
||||
'arguments' => [
|
||||
'type' => 'select_groups',
|
||||
'returnAllGroup' => true,
|
||||
'name' => 'id_group',
|
||||
],
|
||||
];
|
||||
|
||||
// Group.
|
||||
$inputs[] = [
|
||||
'label' => __('Overwrite').ui_print_help_tip(
|
||||
__('Check this box, if you want to overwrite existing same days.'),
|
||||
true
|
||||
),
|
||||
'arguments' => [
|
||||
'type' => 'checkbox',
|
||||
'name' => 'overwrite',
|
||||
'id' => 'overwrite',
|
||||
'disabled_hidden' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Submit.
|
||||
$inputs[] = [
|
||||
'arguments' => [
|
||||
'name' => 'button',
|
||||
'label' => __('Upload'),
|
||||
'type' => 'submit',
|
||||
'attributes' => 'class="sub next"',
|
||||
],
|
||||
];
|
||||
|
||||
// Print form.
|
||||
HTML::printForm(
|
||||
[
|
||||
'form' => [
|
||||
'action' => $url.'&op=edit&action=upload_ical&id='.$id_calendar,
|
||||
'method' => 'POST',
|
||||
],
|
||||
'inputs' => $inputs,
|
||||
],
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
$this_year = date('Y');
|
||||
$this_month = date('m');
|
||||
|
||||
$filter = [];
|
||||
if (!is_user_admin($config['id_user'])) {
|
||||
$filter['id_group'] = array_keys(users_get_groups(false, 'LM'));
|
||||
}
|
||||
|
||||
// Show display range.
|
||||
$html = "<table cellpadding='4' cellspacing='4' width='100%' margin-bottom: 10px;'><tr><td>".__('Display range: ');
|
||||
if ($display_range) {
|
||||
$html .= '<a href="'.$url.'">['.__('Default').']</a> ';
|
||||
if ($display_range > 1970) {
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= ($display_range - 1);
|
||||
$html .= '"><< </a>';
|
||||
}
|
||||
|
||||
$html .= '<a href="'.$url.'&display_range='.$display_range.'" class="bolder">['.$display_range.']</a>';
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= ($display_range + 1);
|
||||
$html .= '"> >></a>';
|
||||
} else {
|
||||
$html .= '<a href="'.$url.'" class="bolder">['.__('Default').']</a> ';
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= ($this_year - 1);
|
||||
$html .= '"><< </a>';
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= $this_year;
|
||||
$html .= '">[';
|
||||
$html .= $this_year;
|
||||
$html .= ']</a>';
|
||||
$html .= '<a href="'.$url.'&display_range=';
|
||||
$html .= ($this_year + 1);
|
||||
$html .= '"> >></a>';
|
||||
}
|
||||
|
||||
$html .= '</td></tr>';
|
||||
echo $html;
|
||||
|
||||
// Show calendar.
|
||||
for ($month = 1; $month <= 12; $month++) {
|
||||
if ($display_range) {
|
||||
$display_month = $month;
|
||||
$display_year = $display_range;
|
||||
} else {
|
||||
$display_month = ($this_month + $month - 1);
|
||||
$display_year = $this_year;
|
||||
}
|
||||
|
||||
if ($display_month > 12) {
|
||||
$display_month -= 12;
|
||||
$display_year++;
|
||||
}
|
||||
|
||||
$cal_table = new stdClass();
|
||||
$cal_table->width = '100%';
|
||||
$cal_table->class = 'databox data';
|
||||
|
||||
$cal_table->data = [];
|
||||
$cal_table->head = [];
|
||||
$cal_table->head[0] = __('Sun');
|
||||
$cal_table->head[1] = __('Mon');
|
||||
$cal_table->head[2] = __('Tue');
|
||||
$cal_table->head[3] = __('Wed');
|
||||
$cal_table->head[4] = __('Thu');
|
||||
$cal_table->head[5] = __('Fri');
|
||||
$cal_table->head[6] = __('Sat');
|
||||
$cal_table->cellstyle = [];
|
||||
$cal_table->size = [];
|
||||
$cal_table->size[0] = '14%';
|
||||
$cal_table->size[1] = '14%';
|
||||
$cal_table->size[2] = '14%';
|
||||
$cal_table->size[3] = '14%';
|
||||
$cal_table->size[4] = '14%';
|
||||
$cal_table->size[5] = '14%';
|
||||
$cal_table->size[6] = '14%';
|
||||
$cal_table->align = [];
|
||||
$cal_table->border = '1';
|
||||
$cal_table->titlestyle = 'text-align:center; font-weight: bold;';
|
||||
switch ($display_month) {
|
||||
case 1:
|
||||
$cal_table->title = __('January');
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$cal_table->title = __('February');
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$cal_table->title = __('March');
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$cal_table->title = __('April');
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$cal_table->title = __('May');
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$cal_table->title = __('June');
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$cal_table->title = __('July');
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$cal_table->title = __('August');
|
||||
break;
|
||||
|
||||
case 9:
|
||||
$cal_table->title = __('September');
|
||||
break;
|
||||
|
||||
case 10:
|
||||
$cal_table->title = __('October');
|
||||
break;
|
||||
|
||||
case 11:
|
||||
$cal_table->title = __('November');
|
||||
break;
|
||||
|
||||
case 12:
|
||||
$cal_table->title = __('December');
|
||||
break;
|
||||
|
||||
default:
|
||||
// Not possible.
|
||||
break;
|
||||
}
|
||||
|
||||
$cal_table->title .= ' / '.$display_year;
|
||||
|
||||
$last_day = date('j', mktime(0, 0, 0, ($display_month + 1), 0, $display_year));
|
||||
$cal_line = 0;
|
||||
|
||||
for ($day = 1; $day < ($last_day + 1); $day++) {
|
||||
$week = date('w', mktime(0, 0, 0, $display_month, $day, $display_year));
|
||||
if ($cal_line == 0 && $week != 0 && $day == 1) {
|
||||
for ($i = 0; $i < $week; $i++) {
|
||||
$cal_table->cellstyle[$cal_line][$i] = 'font-size: 18px;';
|
||||
$cal_table->data[$cal_line][$i] = '-';
|
||||
}
|
||||
}
|
||||
|
||||
if ($week == 0 || $week == 6) {
|
||||
$cal_table->cellstyle[$cal_line][$week] = 'color: red;';
|
||||
}
|
||||
|
||||
$date = sprintf('%04d-%02d-%02d', $display_year, $display_month, $day);
|
||||
$date_wildcard = sprintf('0001-%02d-%02d', $display_month, $day);
|
||||
$special_days = '';
|
||||
$filter['date'] = [
|
||||
$date,
|
||||
$date_wildcard,
|
||||
];
|
||||
$filter['order']['field'] = 'date';
|
||||
$filter['order']['order'] = 'DESC';
|
||||
$special_days = db_get_all_rows_filter('talert_special_days', $filter);
|
||||
|
||||
$cal_table->cellstyle[$cal_line][$week] .= 'font-size: 18px;';
|
||||
$cal_table->data[$cal_line][$week] = $day.' ';
|
||||
|
||||
$cal_table->data[$cal_line][$week] .= '<a href="'.$url_alert.'&create_special_day=1&date='.$date.'" title=';
|
||||
$cal_table->data[$cal_line][$week] .= __('Create');
|
||||
$cal_table->data[$cal_line][$week] .= '>'.html_print_image(
|
||||
'images/add_mc.png',
|
||||
true,
|
||||
['class' => 'invert_filter']
|
||||
).'</a>';
|
||||
|
||||
if (empty($special_days) === false) {
|
||||
$cal_table->data[$cal_line][$week] .= '<br>';
|
||||
foreach ($special_days as $special_day) {
|
||||
// Only show description if is filled.
|
||||
$cal_table->data[$cal_line][$week] .= '<div class="note-special-day">';
|
||||
$cal_table->data[$cal_line][$week] .= '<div>';
|
||||
$cal_table->data[$cal_line][$week] .= ui_print_group_icon(
|
||||
$special_day['id_group'],
|
||||
true
|
||||
);
|
||||
|
||||
if (empty($special_day['description']) === false) {
|
||||
$cal_table->data[$cal_line][$week] .= ui_print_help_tip($special_day['description'], true);
|
||||
}
|
||||
|
||||
if ($special_day['date'] == $date_wildcard) {
|
||||
$cal_table->data[$cal_line][$week] .= '(';
|
||||
$cal_table->data[$cal_line][$week] .= ui_print_help_tip(
|
||||
'This is valid every year. However, this will be ignored if indivisual setting for the same group is available.',
|
||||
true
|
||||
);
|
||||
$cal_table->data[$cal_line][$week] .= ') ';
|
||||
}
|
||||
|
||||
$cal_table->data[$cal_line][$week] .= __('As ');
|
||||
switch ($special_day['same_day']) {
|
||||
case 'monday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Monday');
|
||||
break;
|
||||
|
||||
case 'tuesday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Tuesday');
|
||||
break;
|
||||
|
||||
case 'wednesday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Wednesday');
|
||||
break;
|
||||
|
||||
case 'thursday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Thursday');
|
||||
break;
|
||||
|
||||
case 'friday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Friday');
|
||||
break;
|
||||
|
||||
case 'saturday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Saturday');
|
||||
break;
|
||||
|
||||
case 'sunday':
|
||||
$cal_table->data[$cal_line][$week] .= __('Sunday');
|
||||
break;
|
||||
|
||||
default:
|
||||
// Not possible.
|
||||
break;
|
||||
}
|
||||
|
||||
$cal_table->data[$cal_line][$week] .= '</div>';
|
||||
$cal_table->data[$cal_line][$week] .= '<div>';
|
||||
if ($special_day['id_group'] || ($can_manage_group_all && $special_day['id_group'] == 0)) {
|
||||
$script_delete = '';
|
||||
$dateformat = date_create($special_day['date']);
|
||||
$options_zoom = htmlspecialchars(
|
||||
json_encode(
|
||||
[
|
||||
'date' => $special_day['date'],
|
||||
'id_group' => $special_day['id_group'],
|
||||
'same_day' => $special_day['same_day'],
|
||||
'btn_ok_text' => __('Create'),
|
||||
'btn_cancel_text' => __('Cancel'),
|
||||
'title' => date_format($dateformat, 'd M Y'),
|
||||
'url' => ui_get_full_url('ajax.php', false, false, false),
|
||||
'page' => 'godmode/alerts/alert_special_days',
|
||||
'loading' => __('Loading, this operation might take several minutes...'),
|
||||
]
|
||||
),
|
||||
ENT_QUOTES,
|
||||
'UTF-8'
|
||||
);
|
||||
|
||||
$onclick_zoom = 'load_templates_alerts_special_days('.$options_zoom.')';
|
||||
$cal_table->data[$cal_line][$week] .= '<a href="#" onclick="'.$onclick_zoom.'"';
|
||||
$cal_table->data[$cal_line][$week] .= 'title="';
|
||||
$cal_table->data[$cal_line][$week] .= __('Show templates');
|
||||
$cal_table->data[$cal_line][$week] .= '">';
|
||||
$cal_table->data[$cal_line][$week] .= html_print_image(
|
||||
'images/zoom.png',
|
||||
true,
|
||||
['class' => 'invert_filter']
|
||||
).'</a>';
|
||||
$cal_table->data[$cal_line][$week] .= '<a href="'.$url_alert.'&id='.$special_day['id'].'" title=';
|
||||
$cal_table->data[$cal_line][$week] .= __('Edit');
|
||||
$cal_table->data[$cal_line][$week] .= '>'.html_print_image(
|
||||
'images/config.png',
|
||||
true,
|
||||
['class' => 'invert_filter']
|
||||
).'</a> ';
|
||||
$url_delete = $url.'&delete_special_day=1&id='.$special_day['id'];
|
||||
$script_delete = 'if (!confirm(\''.__('Are you sure?').'\')) return false;';
|
||||
$cal_table->data[$cal_line][$week] .= '<a href="'.$url_delete.'"';
|
||||
$cal_table->data[$cal_line][$week] .= ' onClick="'.$script_delete.'"';
|
||||
$cal_table->data[$cal_line][$week] .= 'title="';
|
||||
$cal_table->data[$cal_line][$week] .= __('Remove');
|
||||
$cal_table->data[$cal_line][$week] .= '">';
|
||||
$cal_table->data[$cal_line][$week] .= html_print_image(
|
||||
'images/cross.png',
|
||||
true,
|
||||
['class' => 'invert_filter']
|
||||
).'</a>';
|
||||
}
|
||||
|
||||
$cal_table->data[$cal_line][$week] .= '</div>';
|
||||
$cal_table->data[$cal_line][$week] .= '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($week == 6) {
|
||||
$cal_line++;
|
||||
}
|
||||
}
|
||||
|
||||
for ($padding = ($week + 1); $padding <= 6; $padding++) {
|
||||
$cal_table->cellstyle[$cal_line][$padding] = 'font-size: 18px;';
|
||||
$cal_table->data[$cal_line][$padding] = '-';
|
||||
}
|
||||
|
||||
html_print_table($cal_table);
|
||||
}
|
||||
|
||||
if ((bool) check_acl($config['id_user'], 0, 'LM') === true) {
|
||||
HTML::printForm(
|
||||
[
|
||||
'form' => [
|
||||
'action' => $url.'&op=edit',
|
||||
'method' => 'POST',
|
||||
],
|
||||
'inputs' => [
|
||||
[
|
||||
'arguments' => [
|
||||
'name' => 'button',
|
||||
'label' => __('Create'),
|
||||
'type' => 'submit',
|
||||
'attributes' => 'class="sub next"',
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
echo '<div id="modal-alert-templates" class="invisible"></div>';
|
|
@ -0,0 +1,187 @@
|
|||
<?php
|
||||
/**
|
||||
* Special days.
|
||||
*
|
||||
* @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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Extras required.
|
||||
ui_require_css_file('wizard');
|
||||
|
||||
// Header.
|
||||
\ui_print_page_header(
|
||||
// Title.
|
||||
__('Alerts').' » '.__('Configure special day'),
|
||||
// Icon.
|
||||
'images/gm_alerts.png',
|
||||
// Return.
|
||||
false,
|
||||
// Help.
|
||||
'alert_special_days',
|
||||
// Godmode.
|
||||
true,
|
||||
// Options.
|
||||
$tabs
|
||||
);
|
||||
|
||||
if (empty($message) === false) {
|
||||
echo $message;
|
||||
}
|
||||
|
||||
$inputs = [];
|
||||
|
||||
// Name.
|
||||
$inputs[] = [
|
||||
'label' => __('Date'),
|
||||
'arguments' => [
|
||||
'type' => 'text',
|
||||
'name' => 'date',
|
||||
'required' => true,
|
||||
'value' => $specialDay->date(),
|
||||
],
|
||||
];
|
||||
|
||||
if (users_can_manage_group_all('LM') === true) {
|
||||
$display_all_group = true;
|
||||
} else {
|
||||
$display_all_group = false;
|
||||
}
|
||||
|
||||
// Group.
|
||||
$inputs[] = [
|
||||
'label' => __('Group'),
|
||||
'arguments' => [
|
||||
'type' => 'select_groups',
|
||||
'returnAllGroup' => $display_all_group,
|
||||
'name' => 'id_group',
|
||||
'selected' => $specialDay->id_group(),
|
||||
],
|
||||
];
|
||||
|
||||
$days = [];
|
||||
$days[1] = __('Monday');
|
||||
$days[2] = __('Tuesday');
|
||||
$days[3] = __('Wednesday');
|
||||
$days[4] = __('Thursday');
|
||||
$days[5] = __('Friday');
|
||||
$days[6] = __('Saturday');
|
||||
$days[7] = __('Sunday');
|
||||
$days[8] = __('Holidays');
|
||||
|
||||
// Same day of the week.
|
||||
$inputs[] = [
|
||||
'label' => __('Same day of the week'),
|
||||
'arguments' => [
|
||||
'name' => 'day_code',
|
||||
'type' => 'select',
|
||||
'fields' => $days,
|
||||
'selected' => $specialDay->day_code(),
|
||||
],
|
||||
];
|
||||
|
||||
// Description.
|
||||
$inputs[] = [
|
||||
'label' => __('Description'),
|
||||
'arguments' => [
|
||||
'type' => 'textarea',
|
||||
'name' => 'description',
|
||||
'required' => false,
|
||||
'value' => $specialDay->description(),
|
||||
'rows' => 50,
|
||||
'columns' => 30,
|
||||
],
|
||||
];
|
||||
|
||||
// Submit.
|
||||
$inputs[] = [
|
||||
'arguments' => [
|
||||
'name' => 'button',
|
||||
'label' => (($create === true) ? __('Create') : __('Update')),
|
||||
'type' => 'submit',
|
||||
'attributes' => 'class="sub next"',
|
||||
],
|
||||
];
|
||||
|
||||
// Print form.
|
||||
HTML::printForm(
|
||||
[
|
||||
'form' => [
|
||||
'action' => $url.'&op=edit&action=save&id='.$specialDay->id(),
|
||||
'method' => 'POST',
|
||||
],
|
||||
'inputs' => $inputs,
|
||||
],
|
||||
false,
|
||||
true
|
||||
);
|
||||
/*
|
||||
$table->data[0][0] = __('Date');
|
||||
$table->data[0][1] = html_print_input_text(
|
||||
'date',
|
||||
$date,
|
||||
'',
|
||||
10,
|
||||
10,
|
||||
true
|
||||
);
|
||||
$table->data[0][1] .= html_print_image(
|
||||
'images/calendar_view_day.png',
|
||||
true,
|
||||
[
|
||||
'alt' => 'calendar',
|
||||
'onclick' => "scwShow(scwID('text-date'),this);",
|
||||
'class' => 'invert_filter',
|
||||
]
|
||||
);
|
||||
*/
|
||||
echo '<div id="modal-alert-templates" class="invisible"></div>';
|
||||
|
||||
ui_require_javascript_file('calendar');
|
||||
ui_require_javascript_file('pandora_alerts');
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$(document).ready (function () {
|
||||
$("#submit-button").click (function (e) {
|
||||
e.preventDefault();
|
||||
var date = new Date($("#text-date").val());
|
||||
var dateformat = date.toLocaleString(
|
||||
'default',
|
||||
{day: 'numeric', month: 'short', year: 'numeric'}
|
||||
);
|
||||
|
||||
load_templates_alerts_special_days({
|
||||
date: $("#text-date").val(),
|
||||
id_group: $("#id_group").val(),
|
||||
same_day: $("#same_day").val(),
|
||||
btn_ok_text: '<?php echo __('Create'); ?>',
|
||||
btn_cancel_text: '<?php echo __('Cancel'); ?>',
|
||||
title: dateformat,
|
||||
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>',
|
||||
page: "godmode/alerts/alert_special_days",
|
||||
loading: '<?php echo __('Loading, this operation might take several minutes...'); ?>',
|
||||
name_form: 'form-special-days'
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
Loading…
Reference in New Issue