608 lines
29 KiB
PHP
608 lines
29 KiB
PHP
<?php
|
||
/**
|
||
* Класс работы с календарями событий - модуля Unicalendar
|
||
*
|
||
* @autor Repellent
|
||
* @package AVE.cms
|
||
* @subpackage module_unicalendar
|
||
* @filesource
|
||
*/
|
||
|
||
class Unicalendar
|
||
{
|
||
/**
|
||
* ФУНКЦИИ ПУБЛИЧНОЙ ЧАСТИ
|
||
*/
|
||
|
||
/**
|
||
* Вывод календаря событий
|
||
* @param string $tpl_dir - путь к папке с шаблонами модуля
|
||
* @param int $id - идентификатор календаря
|
||
*/
|
||
function unicalendarShow($tpl_dir, $id)
|
||
{
|
||
$id = (int)$id;
|
||
|
||
$user_lang = preg_replace('/[^a-zA-Z0-9_-]/', '', $_SESSION['user_language'] ?? 'ru');
|
||
$lang_path = BASE_DIR . '/modules/unicalendar/lang/' . $user_lang . '.php';
|
||
|
||
if (file_exists($lang_path)) {
|
||
require($lang_path);
|
||
} else {
|
||
$default_lang = BASE_DIR . '/modules/unicalendar/lang/ru.php';
|
||
if (file_exists($default_lang)) require($default_lang);
|
||
}
|
||
|
||
$eventCalendar_css = '<link rel="stylesheet" href="'.ABS_PATH.'modules/unicalendar/css/eventCalendar.css" type="text/css" media="screen" />';
|
||
$eventCalendar_theme_responsive_css = '<link rel="stylesheet" href="'.ABS_PATH.'modules/unicalendar/css/eventCalendar_theme_responsive.css" type="text/css" media="screen" />';
|
||
$moment_js = '<script src="'.ABS_PATH.'modules/unicalendar/js/moment.js" type="text/javascript"></script>';
|
||
$jquery_eventCalendar_js = '<script src="'.ABS_PATH.'modules/unicalendar/js/jquery.eventCalendar.js" type="text/javascript"></script>';
|
||
|
||
$GLOBALS['user_header']['module_unicalendar_'] = $eventCalendar_css."\n".$eventCalendar_theme_responsive_css."\n".$moment_js."\n".$jquery_eventCalendar_js;
|
||
|
||
$data_dir = "/modules/unicalendar/js/data-files";
|
||
$filename = BASE_DIR . $data_dir . "/data" . $id . ".js";
|
||
|
||
if (file_exists($filename)) {
|
||
$GLOBALS['user_header']['module_unicalendar_' . $id] = '<script src="'.ABS_PATH.'modules/unicalendar/js/data-files/data'.$id.'.js" type="text/javascript"></script>';
|
||
} else {
|
||
echo $uca_file_not_found.$id.".js"; // если не смогли подключить файл -выводим сообщение-подсказку;
|
||
}
|
||
|
||
global $AVE_Template;
|
||
$AVE_Template->assign('id', $id);
|
||
$AVE_Template->display($tpl_dir . 'unicalendar.tpl');
|
||
}
|
||
|
||
/**
|
||
* ФУНКЦИИ АДМИНИСТРАТИВНОЙ ЧАСТИ
|
||
*/
|
||
|
||
|
||
/**
|
||
* Вывод списка календарей
|
||
*
|
||
* @param string $tpl_dir - путь к папке с шаблонами модуля
|
||
*/
|
||
function unicalendarList($tpl_dir)
|
||
{
|
||
global $AVE_DB, $AVE_Template;
|
||
|
||
$unicalendars = array();
|
||
|
||
$limit = 20;
|
||
$current_page = (int)get_current_page();
|
||
if ($current_page < 1) $current_page = 1;
|
||
$start = ($current_page * $limit) - $limit;
|
||
|
||
$sql = $AVE_DB->Query("
|
||
SELECT SQL_CALC_FOUND_ROWS
|
||
u.*,
|
||
COUNT(u.id) AS uca_count
|
||
FROM
|
||
" . PREFIX . "_module_unicalendar AS u
|
||
GROUP BY u.id
|
||
ORDER BY u.id ASC
|
||
LIMIT " . (int)$start . "," . (int)$limit . "
|
||
");
|
||
|
||
$sql_num = $AVE_DB->Query("SELECT FOUND_ROWS()");
|
||
$num = (int)$sql_num->GetCell();
|
||
|
||
while($row = $sql->FetchAssocArray())
|
||
{
|
||
$unicalendars[] = $row;
|
||
}
|
||
|
||
if ($num > $limit)
|
||
{
|
||
$page_nav_tpl = "<li><a href=\"index.php?do=modules&action=modedit&mod=unicalendar&moduleaction=1&page={s}&cp=" . SESSION . "\">{t}</a></li>";
|
||
$page_nav = get_pagination(ceil($num / $limit), 'page', $page_nav_tpl);
|
||
}
|
||
else
|
||
{
|
||
$page_nav = '';
|
||
}
|
||
|
||
$AVE_Template->assign('page_nav', $page_nav);
|
||
|
||
// 4. Безопасный вывод алертов
|
||
if (!empty($_REQUEST['alert']))
|
||
{
|
||
$alert = htmlspecialchars(stripslashes((string)$_REQUEST['alert']), ENT_QUOTES, 'UTF-8');
|
||
$AVE_Template->assign('alert', $alert);
|
||
}
|
||
|
||
$AVE_Template->assign('unicalendars', $unicalendars);
|
||
$AVE_Template->assign('formaction', 'index.php?do=modules&action=modedit&mod=unicalendar&moduleaction=new&sub=save&cp=' . SESSION);
|
||
|
||
$AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . 'admin_unicalendar_list.tpl'));
|
||
}
|
||
|
||
/**
|
||
* Создание календаря
|
||
*/
|
||
function unicalendarNew()
|
||
{
|
||
if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'save')
|
||
{
|
||
global $AVE_DB;
|
||
$alert = '';
|
||
|
||
if (empty($_POST['uca_title']))
|
||
{
|
||
header('Location:index.php?do=modules&action=modedit&mod=unicalendar&moduleaction=1&alert=empty_uca_title');
|
||
exit;
|
||
}
|
||
|
||
$uca_ttl_field = (int)($_POST['i_uca_ttl_field'] ?? 0);
|
||
$uca_str_field = (int)($_POST['i_uca_str_field'] ?? 0);
|
||
$uca_end_field = (int)($_POST['i_uca_end_field'] ?? 0);
|
||
|
||
$AVE_DB->Query("
|
||
INSERT INTO " . PREFIX . "_module_unicalendar
|
||
SET
|
||
uca_title = '" . addslashes($_POST['uca_title']) . "',
|
||
uca_date_format = '" . addslashes($_POST['uca_date_format']) . "',
|
||
uca_events = '" . addslashes($_POST['uca_events']) . "',
|
||
uca_rubric_id = '" . (int)$_POST['uca_rubric_id'] . "',
|
||
uca_rubric_title = '" . addslashes($_POST['uca_rubric_title']) . "',
|
||
uca_doc_id = '" . addslashes($_POST['uca_doc_id'] ?? '') . "',
|
||
uca_link = '" . ($_POST['uca_link'] == 'true' ? 'true' : 'false') . "',
|
||
uca_day = '" . ($_POST['uca_day'] == 'true' ? 'true' : 'false') . "',
|
||
uca_scroll = '" . ($_POST['uca_scroll'] == 'true' ? 'true' : 'false') . "',
|
||
uca_descript = '" . ($_POST['uca_descript'] == 'true' ? 'true' : 'false') . "',
|
||
uca_events_limit = '" . (int)$_POST['uca_events_limit'] . "',
|
||
uca_ttl_field = '" . $uca_ttl_field . "',
|
||
uca_img_field = '" . (int)$_POST['i_uca_img_field'] . "',
|
||
uca_dsc_field = '" . (int)$_POST['i_uca_dsc_field'] . "',
|
||
uca_place_field = '" . (int)$_POST['i_uca_place_field'] . "',
|
||
uca_str_field = '" . $uca_str_field . "',
|
||
uca_end_field = '" . $uca_end_field . "'
|
||
");
|
||
|
||
$uca_id = $AVE_DB->InsertId();
|
||
|
||
require(BASE_DIR . '/modules/unicalendar/lang/'.($_SESSION['admin_language'] ?? 'ru').'.php');
|
||
|
||
$sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_module_unicalendar WHERE id = '" . $uca_id . "'");
|
||
$v = $sql->FetchAssocArray();
|
||
|
||
if ($v)
|
||
{
|
||
$uni_data = "";
|
||
$rubric_count_ids = [];
|
||
|
||
$where = "rubric_id = '" . (int)$v['uca_rubric_id'] . "' AND Id != 1 AND Id != '" . PAGE_NOT_FOUND_ID . "'";
|
||
|
||
if ($v['uca_events'] == '2' && !empty($v['uca_doc_id'])) {
|
||
$where .= " AND (" . $v['uca_doc_id'] . ")";
|
||
}
|
||
|
||
$sql_docs = $AVE_DB->Query("
|
||
SELECT Id, document_alias, document_title, document_published, document_expire
|
||
FROM " . PREFIX . "_documents
|
||
WHERE " . $where
|
||
);
|
||
|
||
while ($res = $sql_docs->FetchAssocArray())
|
||
{
|
||
// --- ЗАГОЛОВОК (Очистка + Лимит 100) ---
|
||
$raw_title = ($v['uca_ttl_field'] > 0)
|
||
? get_document_field($res['Id'], $v['uca_ttl_field'])
|
||
: $res['document_title'];
|
||
if (empty($raw_title)) $raw_title = $res['document_title'];
|
||
|
||
$clean_title = preg_replace('|[\s]+|su', ' ', strip_tags($raw_title));
|
||
$event_title = mb_substr($clean_title, 0, 100, 'UTF-8');
|
||
if (mb_strlen($clean_title, 'UTF-8') > 100) $event_title .= '...';
|
||
|
||
// --- ДАТЫ ---
|
||
$date_start = ($v['uca_str_field'] > 0)
|
||
? get_document_field($res['Id'], $v['uca_str_field'])
|
||
: $res['document_published'];
|
||
|
||
$date_end = ($v['uca_end_field'] > 0)
|
||
? get_document_field($res['Id'], $v['uca_end_field'])
|
||
: $res['document_expire'];
|
||
|
||
// --- ИЗОБРАЖЕНИЕ ---
|
||
$img_raw = get_document_field($res['Id'], $v['uca_img_field']);
|
||
$img = strstr($img_raw, '|', true) ?: $img_raw;
|
||
|
||
// --- ОПИСАНИЕ (Очистка + Лимит 250) ---
|
||
$raw_desc = get_document_field($res['Id'], $v['uca_dsc_field']);
|
||
$clean_desc = preg_replace('|[\s]+|su', ' ', strip_tags($raw_desc));
|
||
$desc = rtrim(mb_substr($clean_desc, 0, 250, 'UTF-8'), "!,.-");
|
||
if (mb_strlen($clean_desc, 'UTF-8') > 250) $desc .= '...';
|
||
|
||
// --- МЕСТО (Очистка + Лимит 250) ---
|
||
$raw_place = get_document_field($res['Id'], $v['uca_place_field']);
|
||
$clean_place = preg_replace('|[\s]+|su', ' ', strip_tags($raw_place));
|
||
$place = mb_substr($clean_place, 0, 250, 'UTF-8');
|
||
if (mb_strlen($clean_place, 'UTF-8') > 250) $place .= '...';
|
||
|
||
// Формируем JSON
|
||
$uni_data .= "{
|
||
\"date\": \"" . pretty_date(ave_date_format('%Y-%m-%d %H:%M:%S', $date_start)) . "\",
|
||
\"expire_date\": \"" . pretty_date(ave_date_format('%Y-%m-%d %H:%M:%S', $date_end)) . "\",
|
||
\"title\": " . json_encode($event_title, JSON_UNESCAPED_UNICODE) . ",
|
||
\"image\": " . json_encode($img, JSON_UNESCAPED_UNICODE) . ",
|
||
\"description\": " . json_encode($desc, JSON_UNESCAPED_UNICODE) . ",
|
||
\"location\": " . json_encode($place, JSON_UNESCAPED_UNICODE) . ",
|
||
\"url\": " . json_encode($res['document_alias'], JSON_UNESCAPED_UNICODE) . "
|
||
},";
|
||
|
||
$rubric_count_ids[] = $res['Id'];
|
||
}
|
||
|
||
// Формирование JS файла
|
||
$js_data_files = "(function(){function initUcaData(){if(window.jQuery&&jQuery.fn.eventCalendar){jQuery(function($){var data".$uca_id."=[".rtrim($uni_data, ',')."];$('#eventCalendar".$uca_id."').eventCalendar({jsonData:data".$uca_id.",jsonDateFormat:'human',startWeekOnMonday:".($v['uca_day'] == 'true' ? 'true' : 'false').",eventsScrollable:".($v['uca_scroll'] == 'true' ? 'true' : 'false').",openEventInNewWindow:".($v['uca_link'] == 'true' ? 'true' : 'false').",dateFormat:'".addslashes($v['uca_date_format'])."',showDescription:".($v['uca_descript'] == 'true' ? 'true' : 'false').",eventsLimit:".(int)$v['uca_events_limit'].",locales:{locale:'".($uca_locale ?? 'ru')."',txt_noEvents:".json_encode($uca_no_events ?? '').",txt_SpecificEvents_prev:'',txt_SpecificEvents_after:".json_encode($uca_real_events ?? '').",txt_NextEvents:".json_encode($uca_next_events ?? '').",txt_GoToEventUrl:".json_encode($uca_look_events ?? '').",moment:{'months':".($uca_months_events ?? '[]').",'monthsShort':".($uca_monshort_events ?? '[]').",'weekdays':".($uca_weekdays_events ?? '[]').",'weekdaysShort':".($uca_wdayshort_events ?? '[]').",'weekdaysMin':".($uca_wdaymin_events ?? '[]')."}}});});}else{setTimeout(initUcaData,50);}}initUcaData();})();";
|
||
|
||
if ($v['uca_events'] == '1' && !empty($rubric_count_ids)) {
|
||
$doc_ids_str = 'Id=' . implode(' OR Id=', $rubric_count_ids);
|
||
$AVE_DB->Query("UPDATE " . PREFIX . "_module_unicalendar SET uca_doc_id = '" . addslashes($doc_ids_str) . "' WHERE id = '" . $uca_id . "'");
|
||
}
|
||
|
||
$fdir = BASE_DIR . "/modules/unicalendar/js/data-files/";
|
||
if (!is_dir($fdir)) mkdir($fdir, 0755, true);
|
||
|
||
$file_path = $fdir . "data" . $uca_id . ".js";
|
||
if ($df = fopen($file_path, "w")) {
|
||
flock($df, LOCK_EX);
|
||
fwrite($df, $js_data_files);
|
||
flock($df, LOCK_UN);
|
||
fclose($df);
|
||
chmod($file_path, 0644);
|
||
}
|
||
}
|
||
|
||
header('Location:index.php?do=modules&action=modedit&mod=unicalendar&moduleaction=1' . $alert);
|
||
exit;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Редактирование календаря
|
||
* @param string $tpl_dir - путь к шаблонам модуля
|
||
* @param int $unicalendar_id - идентификатор календаря
|
||
*/
|
||
function unicalendarEdit($tpl_dir, $unicalendar_id)
|
||
{
|
||
global $AVE_DB, $AVE_Template;
|
||
|
||
$sql = $AVE_DB->Query("
|
||
SELECT *
|
||
FROM " . PREFIX . "_module_unicalendar
|
||
WHERE id = '" . (int)$unicalendar_id . "'
|
||
LIMIT 1
|
||
");
|
||
|
||
$unicalendars = $sql->FetchAssocArray();
|
||
|
||
if (!$unicalendars) {
|
||
return;
|
||
}
|
||
|
||
$uevents = $unicalendars['uca_events'];
|
||
$urubric_id = (int)$unicalendars['uca_rubric_id'];
|
||
$udoc_id = $unicalendars['uca_doc_id'];
|
||
|
||
$unidocs = [];
|
||
$check_docs = [];
|
||
|
||
if ($uevents == 2)
|
||
{
|
||
// Получаем все документы рубрики
|
||
$sql_docs = $AVE_DB->Query("
|
||
SELECT Id, document_alias, document_title, document_published, document_expire, document_meta_description
|
||
FROM " . PREFIX . "_documents
|
||
WHERE rubric_id = '" . $urubric_id . "'
|
||
AND Id != 1
|
||
AND Id != '" . PAGE_NOT_FOUND_ID . "'
|
||
");
|
||
|
||
while ($row = $sql_docs->FetchAssocArray()) {
|
||
$unidocs[] = $row;
|
||
}
|
||
|
||
if (!empty($udoc_id) && trim($udoc_id) != '') {
|
||
$sql_check = $AVE_DB->Query("
|
||
SELECT Id
|
||
FROM " . PREFIX . "_documents
|
||
WHERE rubric_id = '" . $urubric_id . "'
|
||
AND Id != 1
|
||
AND Id != '" . PAGE_NOT_FOUND_ID . "'
|
||
AND (" . $udoc_id . ")
|
||
");
|
||
|
||
if ($sql_check) {
|
||
while ($row = $sql_check->FetchAssocArray()) {
|
||
$check_docs[] = $row;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
$AVE_Template->assign([
|
||
'unidocs' => $unidocs,
|
||
'check_docs' => $check_docs,
|
||
'unicalendars' => $unicalendars
|
||
]);
|
||
|
||
$AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . 'admin_unicalendar_edit.tpl'));
|
||
}
|
||
|
||
/**
|
||
* Сохранение календаря после редактирования
|
||
* @param int $unicalendar_id - идентификатор календаря
|
||
*/
|
||
function unicalendarEditSave($unicalendar_id)
|
||
{
|
||
global $AVE_DB;
|
||
$unicalendar_id = (int)$unicalendar_id;
|
||
|
||
$AVE_DB->Query("
|
||
UPDATE " . PREFIX . "_module_unicalendar
|
||
SET
|
||
uca_title = '" . addslashes($_POST['uca_title']) . "',
|
||
uca_date_format = '" . addslashes($_POST['uca_date_format']) . "',
|
||
uca_doc_id = '" . addslashes($_POST['uca_doc_id'] ?? '') . "',
|
||
uca_events = '" . addslashes($_POST['uca_events']) . "',
|
||
uca_rubric_id = '" . (int)$_POST['uca_rubric_id'] . "',
|
||
uca_rubric_title = '" . addslashes($_POST['uca_rubric_title']) . "',
|
||
uca_link = '" . ($_POST['uca_link'] == 'true' ? 'true' : 'false') . "',
|
||
uca_day = '" . ($_POST['uca_day'] == 'true' ? 'true' : 'false') . "',
|
||
uca_scroll = '" . ($_POST['uca_scroll'] == 'true' ? 'true' : 'false') . "',
|
||
uca_descript = '" . ($_POST['uca_descript'] == 'true' ? 'true' : 'false') . "',
|
||
uca_events_limit = '" . (int)$_POST['uca_events_limit'] . "',
|
||
uca_ttl_field = '" . (int)$_POST['send_uca_ttl_field'] . "',
|
||
uca_img_field = '" . (int)$_POST['send_uca_img_field'] . "',
|
||
uca_dsc_field = '" . (int)$_POST['send_uca_dsc_field'] . "',
|
||
uca_place_field = '" . (int)$_POST['send_uca_place_field'] . "',
|
||
uca_str_field = '" . (int)$_POST['send_uca_str_field'] . "',
|
||
uca_end_field = '" . (int)$_POST['send_uca_end_field'] . "'
|
||
WHERE id = '" . $unicalendar_id . "'
|
||
");
|
||
|
||
$as = [
|
||
'title' => is_array($_POST['uca_title']) ? ($_POST['uca_title'][0] ?? '') : $_POST['uca_title'],
|
||
'rubric_title' => is_array($_POST['uca_rubric_title']) ? ($_POST['uca_rubric_title'][0] ?? '') : $_POST['uca_rubric_title']
|
||
];
|
||
|
||
require(BASE_DIR . '/modules/unicalendar/lang/' . ($_SESSION['admin_language'] ?? 'ru') . '.php');
|
||
|
||
$sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_module_unicalendar WHERE id = '" . $unicalendar_id . "' LIMIT 1");
|
||
$v = $sql->FetchAssocArray();
|
||
|
||
if ($v) {
|
||
$uni_data = '';
|
||
$rubric_count_ids = [];
|
||
|
||
$where = "rubric_id = '" . (int)$v['uca_rubric_id'] . "' AND Id != 1 AND Id != '" . PAGE_NOT_FOUND_ID . "'";
|
||
|
||
if ($v['uca_events'] == '2' && !empty($v['uca_doc_id'])) {
|
||
$where .= " AND (" . $v['uca_doc_id'] . ")";
|
||
}
|
||
|
||
$sql_docs = $AVE_DB->Query("SELECT Id, document_alias, document_title, document_published, document_expire FROM " . PREFIX . "_documents WHERE $where");
|
||
|
||
while ($res = $sql_docs->FetchAssocArray()) {
|
||
// --- ЗАГОЛОВОК (Очистка + Лимит 100) ---
|
||
$custom_title = get_document_field($res['Id'], $v['uca_ttl_field']);
|
||
$raw_title = (!empty($custom_title)) ? $custom_title : $res['document_title'];
|
||
|
||
$clean_title = preg_replace('|[\s]+|su', ' ', strip_tags($raw_title));
|
||
$event_title = mb_substr($clean_title, 0, 100, 'UTF-8');
|
||
if (mb_strlen($clean_title, 'UTF-8') > 100) $event_title .= '...';
|
||
|
||
// --- ДАТЫ ---
|
||
$custom_start = get_document_field($res['Id'], $v['uca_str_field']);
|
||
$custom_end = get_document_field($res['Id'], $v['uca_end_field']);
|
||
$date_start = (!empty($custom_start)) ? $custom_start : $res['document_published'];
|
||
$date_end = (!empty($custom_end)) ? $custom_end : $res['document_expire'];
|
||
|
||
// --- ИЗОБРАЖЕНИЕ ---
|
||
$img_raw = get_document_field($res['Id'], $v['uca_img_field']);
|
||
$img = strstr($img_raw, '|', true) ?: $img_raw;
|
||
|
||
// --- ОПИСАНИЕ (Очистка + Лимит 250) ---
|
||
$raw_desc = get_document_field($res['Id'], $v['uca_dsc_field']);
|
||
$clean_desc = preg_replace('|[\s]+|su', ' ', strip_tags($raw_desc));
|
||
$desc = rtrim(mb_substr($clean_desc, 0, 250, 'UTF-8'), "!,.-");
|
||
if (mb_strlen($clean_desc, 'UTF-8') > 250) $desc .= '...';
|
||
|
||
// --- МЕСТО (Очистка + Лимит 250) ---
|
||
$raw_place = get_document_field($res['Id'], $v['uca_place_field']);
|
||
$clean_place = preg_replace('|[\s]+|su', ' ', strip_tags($raw_place));
|
||
$place = mb_substr($clean_place, 0, 250, 'UTF-8');
|
||
if (mb_strlen($clean_place, 'UTF-8') > 250) $place .= '...';
|
||
|
||
$uni_data .= "{
|
||
\"date\": \"" . pretty_date(ave_date_format('%Y-%m-%d %H:%M:%S', $date_start)) . "\",
|
||
\"expire_date\": \"" . pretty_date(ave_date_format('%Y-%m-%d %H:%M:%S', $date_end)) . "\",
|
||
\"title\": " . json_encode($event_title, JSON_UNESCAPED_UNICODE) . ",
|
||
\"image\": " . json_encode($img, JSON_UNESCAPED_UNICODE) . ",
|
||
\"description\": " . json_encode($desc, JSON_UNESCAPED_UNICODE) . ",
|
||
\"location\": " . json_encode($place, JSON_UNESCAPED_UNICODE) . ",
|
||
\"url\": " . json_encode($res['document_alias'], JSON_UNESCAPED_UNICODE) . "
|
||
},";
|
||
|
||
$rubric_count_ids[] = $res['Id'];
|
||
}
|
||
|
||
// Формирование JS файла
|
||
$js_data_files = "(function(){function initUcaData(){if(window.jQuery&&jQuery.fn.eventCalendar){jQuery(function($){var data".$unicalendar_id."=[".rtrim($uni_data, ',')."];$('#eventCalendar".$unicalendar_id."').eventCalendar({jsonData:data".$unicalendar_id.",jsonDateFormat:'human',startWeekOnMonday:".($v['uca_day'] == 'true' ? 'true' : 'false').",eventsScrollable:".($v['uca_scroll'] == 'true' ? 'true' : 'false').",openEventInNewWindow:".($v['uca_link'] == 'true' ? 'true' : 'false').",dateFormat:'".addslashes($v['uca_date_format'])."',showDescription:".($v['uca_descript'] == 'true' ? 'true' : 'false').",eventsLimit:".(int)$v['uca_events_limit'].",locales:{locale:'".($uca_locale??'ru')."',txt_noEvents:".json_encode($uca_no_events??'').",txt_SpecificEvents_prev:'',txt_SpecificEvents_after:".json_encode($uca_real_events??'').",txt_NextEvents:".json_encode($uca_next_events??'').",txt_GoToEventUrl:".json_encode($uca_look_events??'').",moment:{'months':".($uca_months_events?? '[]').",'monthsShort':".($uca_monshort_events?? '[]').",'weekdays':".($uca_weekdays_events?? '[]').",'weekdaysShort':".($uca_wdayshort_events?? '[]').",'weekdaysMin':".($uca_wdaymin_events?? '[]')."}}});});}else{setTimeout(initUcaData,50);}}initUcaData();})();";
|
||
|
||
if ($v['uca_events'] == '1' && !empty($rubric_count_ids)) {
|
||
$ids_str = 'Id=' . implode(' OR Id=', $rubric_count_ids);
|
||
$AVE_DB->Query("UPDATE " . PREFIX . "_module_unicalendar SET uca_doc_id = '" . addslashes($ids_str) . "' WHERE id = '$unicalendar_id'");
|
||
}
|
||
|
||
$fdir = BASE_DIR . "/modules/unicalendar/js/data-files/";
|
||
if (!is_dir($fdir)) {
|
||
mkdir($fdir, 0755, true);
|
||
}
|
||
|
||
$file_path = $fdir . "data" . $unicalendar_id . ".js";
|
||
if ($df = fopen($file_path, "w")) {
|
||
flock($df, LOCK_EX);
|
||
fwrite($df, $js_data_files);
|
||
flock($df, LOCK_UN);
|
||
fclose($df);
|
||
chmod($file_path, 0644);
|
||
} else {
|
||
die($uca_not_write_file ?? 'Error writing JS file');
|
||
}
|
||
}
|
||
|
||
header('Content-Type: application/json');
|
||
echo json_encode($as);
|
||
exit;
|
||
}
|
||
|
||
/**
|
||
* Выбор событий календаря (AJAX-обработчик)
|
||
*/
|
||
function unicalendarEventsNew()
|
||
{
|
||
// Защита от прямого вызова файла (вне ядра системы)
|
||
if (!defined('BASE_DIR')) exit;
|
||
|
||
// Проверяем либо право на модули, либо полные права (alles)
|
||
if (!check_permission_acp('modules_admin') && !check_permission_acp('alles')) {
|
||
header('HTTP/1.1 403 Forbidden');
|
||
exit('Access Denied');
|
||
}
|
||
|
||
global $AVE_DB;
|
||
|
||
$lang = $_SESSION['admin_language'] ?? 'ru';
|
||
require_once(BASE_DIR . '/modules/unicalendar/lang/' . $lang . '.php');
|
||
|
||
// --- Выбор рубрик ---
|
||
if (isset($_POST['c']))
|
||
{
|
||
$sql = $AVE_DB->Query("SELECT Id, rubric_title FROM " . PREFIX . "_rubrics");
|
||
echo "<option style='color: #ABABAB;' value=''>" . ($select_category ?? '...') . "</option>";
|
||
while ($row = $sql->FetchRow()) {
|
||
echo "<option value='" . (int)$row->Id . "'>" . htmlspecialchars($row->rubric_title) . "</option>";
|
||
}
|
||
}
|
||
|
||
// --- Выбор документов рубрики ---
|
||
if (isset($_POST['a']) && isset($_POST['b']))
|
||
{
|
||
$rubric_id = (int)$_POST['b'];
|
||
$sql = $AVE_DB->Query("
|
||
SELECT Id, document_alias, document_title, document_published, document_expire
|
||
FROM " . PREFIX . "_documents
|
||
WHERE rubric_id = '$rubric_id' AND Id != 1 AND Id != '" . (int)PAGE_NOT_FOUND_ID . "'
|
||
");
|
||
|
||
while ($v = $sql->FetchAssocArray()) {
|
||
$pub = pretty_date(ave_date_format(TIME_FORMAT, $v['document_published']));
|
||
$exp = pretty_date(ave_date_format(TIME_FORMAT, $v['document_expire']));
|
||
|
||
echo "<tr class='noborder'>
|
||
<td align='center'><input type='checkbox' class='my-checkbox' name='u_chek" . (int)$v['Id'] . "' value='" . (int)$v['Id'] . "'></td>
|
||
<td align='center'>" . (int)$v['Id'] . "</td>
|
||
<td>" . htmlspecialchars($v['document_title']) . "</td>
|
||
<td align='center'>" . $pub . "</td>
|
||
<td align='center'>" . $exp . "</td>
|
||
</tr>";
|
||
}
|
||
}
|
||
|
||
// --- Получаем текущие настройки полей из базы ---
|
||
$id = (int)($_POST['id'] ?? $_GET['id'] ?? 0);
|
||
$saved = ['ttl' => 0, 'img' => 0, 'dsc' => 0, 'plc' => 0, 'str' => 0, 'end' => 0];
|
||
|
||
if ($id > 0) {
|
||
$sql = $AVE_DB->Query("SELECT uca_ttl_field, uca_img_field, uca_dsc_field, uca_place_field, uca_str_field, uca_end_field
|
||
FROM " . PREFIX . "_module_unicalendar WHERE id = '$id' LIMIT 1");
|
||
$v = $sql->FetchAssocArray();
|
||
if ($v) {
|
||
$saved['ttl'] = (int)$v['uca_ttl_field'];
|
||
$saved['img'] = (int)$v['uca_img_field'];
|
||
$saved['dsc'] = (int)$v['uca_dsc_field'];
|
||
$saved['plc'] = (int)$v['uca_place_field'];
|
||
$saved['str'] = (int)$v['uca_str_field'];
|
||
$saved['end'] = (int)$v['uca_end_field'];
|
||
}
|
||
}
|
||
|
||
// --- Определяем, какое именно поле запрашивает JS ---
|
||
$field_request = null;
|
||
if (isset($_POST['uca_rub_field'])) $field_request = 'all';
|
||
if (isset($_POST['uca_edit_rub_field_ttl'])) $field_request = 'ttl';
|
||
if (isset($_POST['uca_edit_rub_field_img'])) $field_request = 'img';
|
||
if (isset($_POST['uca_edit_rub_field_dsc'])) $field_request = 'dsc';
|
||
if (isset($_POST['uca_edit_rub_field_plc'])) $field_request = 'plc';
|
||
if (isset($_POST['uca_edit_rub_field_str'])) $field_request = 'str';
|
||
if (isset($_POST['uca_edit_rub_field_end'])) $field_request = 'end';
|
||
|
||
if ($field_request && isset($_POST['uca_frub_id']))
|
||
{
|
||
$frub_id = (int)$_POST['uca_frub_id'];
|
||
$sql = $AVE_DB->Query("SELECT Id, rubric_field_title FROM " . PREFIX . "_rubric_fields WHERE rubric_id = '$frub_id'");
|
||
|
||
while ($res = $sql->FetchRow()) {
|
||
$sel = '';
|
||
$current_id = (int)$res->Id;
|
||
if ($field_request == 'ttl' && $current_id == $saved['ttl']) $sel = 'selected="selected"';
|
||
if ($field_request == 'img' && $current_id == $saved['img']) $sel = 'selected="selected"';
|
||
if ($field_request == 'dsc' && $current_id == $saved['dsc']) $sel = 'selected="selected"';
|
||
if ($field_request == 'plc' && $current_id == $saved['plc']) $sel = 'selected="selected"';
|
||
if ($field_request == 'str' && $current_id == $saved['str']) $sel = 'selected="selected"';
|
||
if ($field_request == 'end' && $current_id == $saved['end']) $sel = 'selected="selected"';
|
||
|
||
echo "<option $sel value='" . $current_id . "'>" . htmlspecialchars($res->rubric_field_title) . "</option>";
|
||
}
|
||
}
|
||
|
||
// --- Вспомогательные запросы для зависимостей ---
|
||
if (isset($_POST['check_rel']) || isset($_POST['allowed_rub']))
|
||
{
|
||
$r_id = (int)($_POST['r_id'] ?? $_POST['allowed_rub_id'] ?? 0);
|
||
$filter_sql = "";
|
||
if (isset($_POST['check_rel'])) {
|
||
$filter_sql = " AND Id != 1 AND Id != '" . (int)PAGE_NOT_FOUND_ID . "'";
|
||
}
|
||
|
||
$sql = $AVE_DB->Query("SELECT Id FROM " . PREFIX . "_documents WHERE rubric_id = '$r_id' $filter_sql");
|
||
$ids = [];
|
||
while ($row = $sql->FetchAssocArray()) {
|
||
$ids[] = (int)$row['Id'];
|
||
}
|
||
echo implode(',', $ids);
|
||
}
|
||
|
||
exit;
|
||
}
|
||
|
||
/**
|
||
* Удаление календаря
|
||
*
|
||
* @param int $unicalendar_id - идентификатор календаря
|
||
*/
|
||
function unicalendarDelete($unicalendar_id)
|
||
{
|
||
global $AVE_DB;
|
||
|
||
$unicalendar_id = (int)$unicalendar_id;
|
||
|
||
$AVE_DB->Query("DELETE FROM " . PREFIX . "_module_unicalendar WHERE id = '$unicalendar_id'");
|
||
|
||
$data_dir = "/modules/unicalendar/js/data-files/";
|
||
$filename = BASE_DIR . $data_dir . "data" . $unicalendar_id . ".js";
|
||
|
||
if (is_file($filename)) {
|
||
@unlink($filename);
|
||
}
|
||
|
||
header('Location: index.php?do=modules&action=modedit&mod=unicalendar&moduleaction=1&cp=' . SESSION);
|
||
exit;
|
||
}
|
||
}
|
||
?>
|