2024-08-16 15:57:50 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file is part of Zwii.
|
|
|
|
*
|
|
|
|
* For full copyright and license information, please see the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* @author Rémi Jean <remi.jean@outlook.com>
|
|
|
|
* @copyright Copyright (C) 2008-2018, Rémi Jean
|
|
|
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
|
|
|
* @copyright Copyright (C) 2018-2024, Frédéric Tempez
|
|
|
|
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
|
|
|
* @link http://zwiicms.fr/
|
|
|
|
*/
|
|
|
|
|
2024-08-23 11:25:15 +02:00
|
|
|
class calendar extends common
|
2024-08-16 15:57:50 +02:00
|
|
|
{
|
|
|
|
|
2024-08-25 02:36:26 +02:00
|
|
|
const VERSION = '1.0';
|
2024-08-23 11:25:15 +02:00
|
|
|
const REALNAME = 'Calendrier';
|
|
|
|
const DATA_DIRECTORY = self::DATA_DIR . 'calendar/';
|
2024-08-16 15:57:50 +02:00
|
|
|
|
|
|
|
const SORT_ASC = 'SORT_ASC';
|
|
|
|
const SORT_DSC = 'SORT_DSC';
|
|
|
|
const SORT_HAND = 'SORT_HAND';
|
|
|
|
|
|
|
|
|
|
|
|
public static $agendas = [];
|
|
|
|
|
|
|
|
public static $classes = ['' => ''];
|
|
|
|
|
|
|
|
public static $actions = [
|
|
|
|
'config' => self::GROUP_EDITOR,
|
|
|
|
'delete' => self::GROUP_EDITOR,
|
|
|
|
'dirs' => self::GROUP_EDITOR,
|
|
|
|
'add' => self::GROUP_EDITOR,
|
|
|
|
'edit' => self::GROUP_EDITOR,
|
|
|
|
'index' => self::GROUP_VISITOR
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mise à jour du module
|
|
|
|
* Appelée par les fonctions index et config
|
|
|
|
*/
|
|
|
|
private function update()
|
|
|
|
{
|
|
|
|
|
|
|
|
//$versionData = $this->getData(['module', $this->getUrl(0), 'config', 'versionData']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configuration
|
|
|
|
*/
|
|
|
|
public function config()
|
|
|
|
{
|
|
|
|
// Soumission du formulaire
|
|
|
|
if (
|
|
|
|
$this->getUser('permission', __CLASS__, __FUNCTION__) === true
|
|
|
|
) {
|
|
|
|
$agendas = $this->getData(['module', $this->getUrl(0), 'content']);
|
|
|
|
if (is_null($agendas)) {
|
|
|
|
$this->setData(['module', $this->getUrl(0), 'content', []]);
|
|
|
|
} elseif (!empty($agendas)) {
|
|
|
|
foreach ($agendas as $agendaId => $agendaData) {
|
|
|
|
self::$agendas[] = [
|
|
|
|
$agendaData['eventName'],
|
|
|
|
helper::dateUTF8('%d %m %Y', $agendaData['date'], self::$i18nUI),
|
|
|
|
empty($agendaData['time']) ? '' : helper::dateUTF8('%H:%M', $agendaData['time'], self::$i18nUI),
|
|
|
|
template::button('agendaConfigEdit' . $agendaId, [
|
|
|
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $agendaId,
|
|
|
|
'value' => template::ico('pencil'),
|
|
|
|
'help' => 'Configuration'
|
|
|
|
]),
|
|
|
|
template::button('galleryConfigDelete' . $agendaId, [
|
|
|
|
'class' => 'galleryConfigDelete buttonRed',
|
|
|
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $agendaId,
|
|
|
|
'value' => template::ico('trash'),
|
|
|
|
'help' => 'Supprimer'
|
|
|
|
])
|
|
|
|
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'showBarEditButton' => true,
|
|
|
|
'title' => helper::translate('Configuration'),
|
|
|
|
'view' => 'config'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajout d'une événement
|
|
|
|
*/
|
|
|
|
public function add()
|
|
|
|
{
|
|
|
|
// Soumission du formulaire d'ajout d'une galerie
|
|
|
|
if (
|
|
|
|
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
|
|
|
|
$this->isPost()
|
|
|
|
) {
|
|
|
|
|
|
|
|
$this->setData([
|
|
|
|
'module',
|
|
|
|
$this->getUrl(0),
|
|
|
|
'content',
|
|
|
|
uniqid(),
|
|
|
|
[
|
|
|
|
'eventName' => $this->getInput('agendaAddEventName', null, true),
|
|
|
|
'date' => $this->getInput('agendaAddDate', helper::FILTER_DATETIME, true),
|
|
|
|
'time' => $this->getInput('agendaAddAllDay', helper::FILTER_BOOLEAN) === false ? $this->getInput('agendaAddTime', helper::FILTER_DATETIME) : '',
|
|
|
|
'className' => $this->getInput('agendaAddDateClassName', null),
|
|
|
|
'dateColor' => $this->getInput('agendaAddDateColor', null),
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
|
|
|
'notification' => helper::translate('Modifications enregistrées'),
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
// Liste des classes disponibles
|
|
|
|
$classes = $this->getData(['page', $this->getUrl(0), 'css']);
|
|
|
|
preg_match_all('/\.(\w+)/', $classes, $matches);
|
|
|
|
if (isset($matches[1])) {
|
|
|
|
// Créer un tableau associatif avec les clés égales aux valeurs
|
|
|
|
$associativeClasses = array_combine($matches[1], $matches[1]);
|
|
|
|
|
|
|
|
// Fusionner ce tableau avec le tableau self::$classes
|
|
|
|
self::$classes = array_merge(self::$classes, $associativeClasses);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => helper::translate('Nouvel événement'),
|
|
|
|
'view' => 'add',
|
|
|
|
'vendor' => [
|
|
|
|
'tinycolorpicker'
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajout d'une événement
|
|
|
|
*/
|
|
|
|
public function edit()
|
|
|
|
{
|
|
|
|
// Soumission du formulaire d'ajout d'une galerie
|
|
|
|
if (
|
|
|
|
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
|
|
|
|
$this->isPost()
|
|
|
|
) {
|
|
|
|
|
|
|
|
$this->setData([
|
|
|
|
'module',
|
|
|
|
$this->getUrl(0),
|
|
|
|
'content',
|
|
|
|
$this->getUrl(2),
|
|
|
|
[
|
|
|
|
'eventName' => $this->getInput('agendaEditEventName', null, true),
|
|
|
|
'date' => $this->getInput('agendaEditDate', helper::FILTER_DATETIME, true),
|
|
|
|
'time' => $this->getInput('agendaEditAllDay', helper::FILTER_BOOLEAN) === false ? $this->getInput('agendaEditTime', helper::FILTER_DATETIME) : '',
|
|
|
|
'className' => $this->getInput('agendaEditDateClassName', null),
|
|
|
|
'dateColor' => $this->getInput('agendaEditDateColor', null),
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
|
|
|
'notification' => helper::translate('Modifications enregistrées'),
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
// Liste des classes disponibles
|
|
|
|
$classes = $this->getData(['page', $this->getUrl(0), 'css']);
|
|
|
|
preg_match_all('/\.(\w+)/', $classes, $matches);
|
|
|
|
if (isset($matches[1])) {
|
|
|
|
// Créer un tableau associatif avec les clés égales aux valeurs
|
|
|
|
$associativeClasses = array_combine($matches[1], $matches[1]);
|
|
|
|
|
|
|
|
// Fusionner ce tableau avec le tableau self::$classes
|
|
|
|
self::$classes = array_merge(self::$classes, $associativeClasses);
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => helper::translate('Edition'),
|
|
|
|
'view' => 'edit',
|
|
|
|
'vendor' => [
|
|
|
|
'tinycolorpicker'
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Suppression
|
|
|
|
*/
|
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
// La galerie n'existe pas
|
|
|
|
if (
|
|
|
|
$this->getUser('permission', __CLASS__, __FUNCTION__) !== true ||
|
|
|
|
$this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2)]) === null
|
|
|
|
) {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Suppression
|
|
|
|
else {
|
|
|
|
$this->deleteData(['module', $this->getUrl(0), 'content', $this->getUrl(2)]);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
|
|
|
'notification' => helper::translate('Evenement effacé'),
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Accueil (deux affichages en un pour éviter une url à rallonge)
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
|
|
|
|
// Mise à jour des données de module
|
|
|
|
$this->update();
|
|
|
|
|
|
|
|
$agendas = $this->getData(['module', $this->getUrl(0), 'content']);
|
|
|
|
|
|
|
|
// Initialise la feuille de style
|
|
|
|
if (empty($this->getData(['page', $this->getUrl(0), 'css']))) {
|
|
|
|
$this->initCss();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Affichage du template si les données sont disponibles
|
|
|
|
if (is_null($agendas)) {
|
|
|
|
$this->setData(['module', $this->getUrl(0), 'content', []]);
|
|
|
|
} elseif (!empty($agendas)) {
|
|
|
|
// Lecture des données
|
|
|
|
foreach ($agendas as $agendasId => $data) {
|
|
|
|
// Convertion du timestamp en ISO
|
|
|
|
$data['date'] = helper::dateUTF8('%Y-%m-%d', $data['date']);
|
|
|
|
// Ajouter l'horaire
|
|
|
|
if (!empty($data['time'])) {
|
|
|
|
$data['time'] = helper::dateUTF8('%H:%M', $data['time']);
|
|
|
|
$data['date'] = $data['date'] . 'T' . $data['time'];
|
|
|
|
}
|
|
|
|
|
|
|
|
self::$agendas[] = $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'showBarEditButton' => true,
|
|
|
|
'showPageContent' => true,
|
|
|
|
'view' => 'index',
|
|
|
|
'vendor' => [
|
|
|
|
'animated-calendar'
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Page de module vide
|
|
|
|
private function initCss()
|
|
|
|
{
|
|
|
|
// Feuille de styles
|
|
|
|
$cssContent =
|
|
|
|
'.textRed {
|
|
|
|
padding: 2px;
|
|
|
|
border-radius: 5px;
|
|
|
|
color: red;
|
|
|
|
background-color: lightgrey;
|
|
|
|
font-size: 18px;
|
2024-08-16 16:21:11 +02:00
|
|
|
width: 90% ;
|
2024-08-16 15:57:50 +02:00
|
|
|
}
|
|
|
|
.textGreen {
|
|
|
|
border-radius: 5px;
|
|
|
|
padding: 2px;
|
|
|
|
color: lightgreen;
|
|
|
|
background-color: darkgrey;
|
|
|
|
font-size: 18px;
|
2024-08-16 16:21:11 +02:00
|
|
|
width: 90% ;
|
2024-08-16 15:57:50 +02:00
|
|
|
}
|
|
|
|
.textOrange {
|
|
|
|
padding: 2px;
|
|
|
|
border-radius: 5px;
|
|
|
|
color: orange;
|
|
|
|
background-color: green;
|
|
|
|
font-size: 18px;
|
2024-08-16 16:21:11 +02:00
|
|
|
width: 90% ;
|
2024-08-16 15:57:50 +02:00
|
|
|
}';
|
|
|
|
$this->setData(['page', $this->getUrl(0), 'css', $cssContent]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|