2019-12-15 10:47:18 +01:00
|
|
|
<?php
|
|
|
|
|
2022-09-29 08:45:59 +02:00
|
|
|
class template
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un bouton
|
|
|
|
* @param string $nameId Nom et id du champ
|
|
|
|
* @param array $attributes Attributs ($key => $value)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function button($nameId, array $attributes = [])
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'class' => '',
|
|
|
|
'disabled' => false,
|
|
|
|
'href' => 'javascript:void(0);',
|
|
|
|
'ico' => '',
|
|
|
|
'id' => $nameId,
|
|
|
|
'name' => $nameId,
|
|
|
|
'target' => '',
|
|
|
|
'uniqueSubmission' => false,
|
2022-02-18 12:43:48 +01:00
|
|
|
'value' => 'Bouton',
|
|
|
|
'help' => ''
|
2019-12-15 10:47:18 +01:00
|
|
|
], $attributes);
|
2022-09-02 19:03:22 +02:00
|
|
|
// Traduction de l'aide et de l'étiquette
|
2023-01-23 14:40:03 +01:00
|
|
|
$attributes['value'] = helper::translate($attributes['value']);
|
2022-09-02 19:03:22 +02:00
|
|
|
$attributes['help'] = helper::translate($attributes['help']);
|
2019-12-15 10:47:18 +01:00
|
|
|
// Retourne le html
|
2024-08-13 21:33:01 +02:00
|
|
|
return sprintf(
|
2022-02-18 12:43:48 +01:00
|
|
|
'<a %s class="button %s %s %s" %s>%s</a>',
|
2019-12-15 10:47:18 +01:00
|
|
|
helper::sprintAttributes($attributes, ['class', 'disabled', 'ico', 'value']),
|
|
|
|
$attributes['disabled'] ? 'disabled' : '',
|
|
|
|
$attributes['class'],
|
|
|
|
$attributes['uniqueSubmission'] ? 'uniqueSubmission' : '',
|
2022-09-29 08:45:59 +02:00
|
|
|
$attributes['help'] ? ' title="' . $attributes['help'] . '" ' : '',
|
2022-08-27 10:17:43 +02:00
|
|
|
($attributes['ico'] ? template::ico($attributes['ico'], ['margin' => 'right']) : '') . $attributes['value']
|
2019-12-15 10:47:18 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-29 08:45:59 +02:00
|
|
|
/**
|
|
|
|
* Crée un champ captcha
|
|
|
|
* @param string $nameId Nom et id du champ
|
|
|
|
* @param array $attributes Attributs ($key => $value)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function captcha($nameId, array $attributes = [])
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'class' => '',
|
|
|
|
'classWrapper' => '',
|
|
|
|
'help' => '',
|
|
|
|
'id' => $nameId,
|
|
|
|
'name' => $nameId,
|
2020-10-11 19:29:33 +02:00
|
|
|
'value' => '',
|
2021-11-12 18:22:06 +01:00
|
|
|
'limit' => false, // captcha simple
|
2022-09-29 08:45:59 +02:00
|
|
|
'type' => 'alpha' // num(érique) ou alpha(bétique)
|
2019-12-15 10:47:18 +01:00
|
|
|
], $attributes);
|
2022-09-02 19:03:22 +02:00
|
|
|
// Traduction de l'aide et de l'étiquette
|
2022-09-03 09:09:26 +02:00
|
|
|
// $attributes['value'] = helper::translate($attributes['value']);
|
2022-09-02 19:03:22 +02:00
|
|
|
$attributes['help'] = helper::translate($attributes['help']);
|
|
|
|
// Captcha quatre opérations
|
|
|
|
// Limite addition et soustraction selon le type de captcha
|
2022-09-29 08:45:59 +02:00
|
|
|
$numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20];
|
|
|
|
$letters = ['u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'];
|
2024-08-13 21:33:01 +02:00
|
|
|
$limit = $attributes['limit'] ? count($letters) - 1 : 10;
|
2022-09-02 19:03:22 +02:00
|
|
|
|
|
|
|
// Tirage de l'opération
|
2023-01-18 15:01:52 +01:00
|
|
|
mt_srand();
|
2022-09-02 19:03:22 +02:00
|
|
|
// Captcha simple limité à l'addition
|
2024-08-13 21:33:01 +02:00
|
|
|
$operator = $attributes['limit'] ? mt_rand(1, 4) : 1;
|
2022-09-02 19:03:22 +02:00
|
|
|
|
|
|
|
// Limite si multiplication ou division
|
|
|
|
if ($operator > 2) {
|
|
|
|
$limit = 10;
|
2022-09-29 08:45:59 +02:00
|
|
|
}
|
2022-09-02 19:03:22 +02:00
|
|
|
|
|
|
|
// Tirage des nombres
|
2023-01-18 15:01:52 +01:00
|
|
|
mt_srand();
|
2022-09-29 08:45:59 +02:00
|
|
|
$firstNumber = mt_rand(1, $limit);
|
2023-01-18 15:01:52 +01:00
|
|
|
mt_srand();
|
2022-09-29 08:45:59 +02:00
|
|
|
$secondNumber = mt_rand(1, $limit);
|
2022-09-02 19:03:22 +02:00
|
|
|
|
|
|
|
// Permutation si addition ou soustraction
|
|
|
|
if (($operator < 3) and ($firstNumber < $secondNumber)) {
|
|
|
|
$temp = $firstNumber;
|
|
|
|
$firstNumber = $secondNumber;
|
|
|
|
$secondNumber = $temp;
|
2020-10-29 19:14:19 +01:00
|
|
|
}
|
|
|
|
|
2022-09-02 19:03:22 +02:00
|
|
|
// Icône de l'opérateur et calcul du résultat
|
|
|
|
switch ($operator) {
|
|
|
|
case 1:
|
2023-10-12 18:38:13 +02:00
|
|
|
$operator = template::ico('plus', ['fontSize' => '2em;']);
|
2024-08-13 21:33:01 +02:00
|
|
|
$result = $firstNumber + $secondNumber;
|
2022-09-02 19:03:22 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2023-10-12 18:38:13 +02:00
|
|
|
$operator = template::ico('minus', ['fontSize' => '2em;']);
|
2024-08-13 21:33:01 +02:00
|
|
|
$result = $firstNumber - $secondNumber;
|
2022-09-02 19:03:22 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2023-10-12 18:38:13 +02:00
|
|
|
$operator = template::ico('cancel', ['fontSize' => '2em;']);
|
2024-08-13 21:33:01 +02:00
|
|
|
$result = $firstNumber * $secondNumber;
|
2022-09-02 19:03:22 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
2023-10-12 18:38:13 +02:00
|
|
|
$operator = template::ico('divide', ['fontSize' => '2em;']);
|
2022-09-02 19:03:22 +02:00
|
|
|
$limit2 = [10, 10, 6, 5, 4, 3, 2, 2, 2, 2];
|
|
|
|
for ($i = 1; $i <= $firstNumber; $i++) {
|
2022-09-29 08:45:59 +02:00
|
|
|
$limit = $limit2[$i - 1];
|
|
|
|
}
|
2023-01-18 15:01:52 +01:00
|
|
|
mt_srand();
|
2022-09-02 19:03:22 +02:00
|
|
|
$secondNumber = mt_rand(1, $limit);
|
2024-08-13 21:33:01 +02:00
|
|
|
$firstNumber = $firstNumber * $secondNumber;
|
2022-09-02 19:03:22 +02:00
|
|
|
$result = $firstNumber / $secondNumber;
|
|
|
|
break;
|
2020-10-29 13:50:10 +01:00
|
|
|
}
|
2020-10-29 19:14:19 +01:00
|
|
|
|
2022-09-29 08:45:59 +02:00
|
|
|
// Hashage du résultat
|
2020-10-01 15:50:19 +02:00
|
|
|
$result = password_hash($result, PASSWORD_BCRYPT);
|
2020-10-29 19:14:19 +01:00
|
|
|
|
2022-09-29 08:45:59 +02:00
|
|
|
// Codage des valeurs de l'opération
|
2020-10-01 20:20:16 +02:00
|
|
|
$firstLetter = uniqid();
|
|
|
|
$secondLetter = uniqid();
|
2020-10-29 19:14:19 +01:00
|
|
|
|
|
|
|
// Masquage image source pour éviter un décodage
|
2024-08-13 21:33:01 +02:00
|
|
|
copy('core/vendor/zwiico/png/' . $attributes['type'] . '/' . $letters[$firstNumber] . '.png', 'site/tmp/' . $firstLetter . '.png');
|
|
|
|
copy('core/vendor/zwiico/png/' . $attributes['type'] . '/' . $letters[$secondNumber] . '.png', 'site/tmp/' . $secondLetter . '.png');
|
2020-10-29 19:14:19 +01:00
|
|
|
|
2022-04-21 18:38:19 +02:00
|
|
|
|
2019-12-15 10:47:18 +01:00
|
|
|
// Début du wrapper
|
2020-12-01 21:07:07 +01:00
|
|
|
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="captcha inputWrapper ' . $attributes['classWrapper'] . '">';
|
2019-12-15 10:47:18 +01:00
|
|
|
// Label
|
2022-09-29 08:45:59 +02:00
|
|
|
$html .= self::label(
|
|
|
|
$attributes['id'],
|
2024-08-13 21:33:01 +02:00
|
|
|
'<img class="captcha' . ucFirst($attributes['type']) . '" src="' . helper::baseUrl(false) . 'site/tmp/' . $firstLetter . '.png" /> <strong>' . $operator . '</strong> <img class="captcha' . ucFirst($attributes['type']) . '" src="' . helper::baseUrl(false) . 'site/tmp/' . $secondLetter . '.png" />' . template::ico('eq', ['fontSize' => '2em;']),
|
2022-09-29 08:45:59 +02:00
|
|
|
[
|
|
|
|
'help' => $attributes['help']
|
|
|
|
]
|
|
|
|
);
|
2020-10-29 19:14:19 +01:00
|
|
|
|
2019-12-15 10:47:18 +01:00
|
|
|
// Notice
|
|
|
|
$notice = '';
|
2022-09-29 08:45:59 +02:00
|
|
|
if (array_key_exists($attributes['id'], common::$inputNotices)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$notice = common::$inputNotices[$attributes['id']];
|
|
|
|
$attributes['class'] .= ' notice';
|
|
|
|
}
|
|
|
|
$html .= self::notice($attributes['id'], $notice);
|
2020-10-29 19:14:19 +01:00
|
|
|
|
2020-08-10 19:07:17 +02:00
|
|
|
// captcha
|
2019-12-15 10:47:18 +01:00
|
|
|
$html .= sprintf(
|
|
|
|
'<input type="text" %s>',
|
|
|
|
helper::sprintAttributes($attributes)
|
|
|
|
);
|
2020-10-29 19:14:19 +01:00
|
|
|
|
2020-10-28 08:21:58 +01:00
|
|
|
// Champ résultat codé
|
2020-10-01 15:50:19 +02:00
|
|
|
$html .= self::hidden($attributes['id'] . 'Result', [
|
|
|
|
'value' => $result,
|
|
|
|
'before' => false
|
2020-10-01 20:20:16 +02:00
|
|
|
]);
|
2020-10-29 19:14:19 +01:00
|
|
|
|
2019-12-15 10:47:18 +01:00
|
|
|
// Fin du wrapper
|
|
|
|
$html .= '</div>';
|
2020-10-29 19:14:19 +01:00
|
|
|
|
2019-12-15 10:47:18 +01:00
|
|
|
// Retourne le html
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée une case à cocher à sélection multiple
|
|
|
|
* @param string $nameId Nom et id du champ
|
|
|
|
* @param string $value Valeur de la case à cocher
|
|
|
|
* @param string $label Label de la case à cocher
|
|
|
|
* @param array $attributes Attributs ($key => $value)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function checkbox($nameId, $value, $label, array $attributes = [])
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'before' => true,
|
|
|
|
'checked' => '',
|
|
|
|
'class' => '',
|
|
|
|
'classWrapper' => '',
|
|
|
|
'disabled' => false,
|
|
|
|
'help' => '',
|
|
|
|
'id' => $nameId,
|
|
|
|
'name' => $nameId
|
|
|
|
], $attributes);
|
2022-09-02 19:03:22 +02:00
|
|
|
// Traduction de l'aide et de l'étiquette
|
|
|
|
$label = helper::translate($label);
|
|
|
|
$attributes['help'] = helper::translate($attributes['help']);
|
2019-12-15 10:47:18 +01:00
|
|
|
// Sauvegarde des données en cas d'erreur
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['before'] and array_key_exists($attributes['id'], common::$inputBefore)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$attributes['checked'] = (bool) common::$inputBefore[$attributes['id']];
|
|
|
|
}
|
|
|
|
// Début du wrapper
|
|
|
|
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="inputWrapper ' . $attributes['classWrapper'] . '">';
|
|
|
|
// Notice
|
|
|
|
$notice = '';
|
2022-09-29 08:45:59 +02:00
|
|
|
if (array_key_exists($attributes['id'], common::$inputNotices)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$notice = common::$inputNotices[$attributes['id']];
|
|
|
|
$attributes['class'] .= ' notice';
|
|
|
|
}
|
|
|
|
$html .= self::notice($attributes['id'], $notice);
|
|
|
|
// Case à cocher
|
|
|
|
$html .= sprintf(
|
|
|
|
'<input type="checkbox" value="%s" %s>',
|
|
|
|
$value,
|
|
|
|
helper::sprintAttributes($attributes)
|
|
|
|
);
|
|
|
|
// Label
|
|
|
|
$html .= self::label($attributes['id'], '<span>' . $label . '</span>', [
|
|
|
|
'help' => $attributes['help']
|
|
|
|
]);
|
|
|
|
// Fin du wrapper
|
|
|
|
$html .= '</div>';
|
|
|
|
// Retourne le html
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un champ date
|
|
|
|
* @param string $nameId Nom et id du champ
|
|
|
|
* @param array $attributes Attributs ($key => $value)
|
2024-08-14 09:21:32 +02:00
|
|
|
* @param string type date seule ; time heure seule ; datetime-local (jour et heure)
|
2022-09-29 08:45:59 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function date($nameId, array $attributes = [])
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'autocomplete' => 'on',
|
|
|
|
'before' => true,
|
|
|
|
'class' => '',
|
|
|
|
'classWrapper' => '',
|
|
|
|
'noDirty' => false,
|
|
|
|
'disabled' => false,
|
|
|
|
'help' => '',
|
|
|
|
'id' => $nameId,
|
|
|
|
'label' => '',
|
|
|
|
'name' => $nameId,
|
|
|
|
'placeholder' => '',
|
2023-02-17 10:59:25 +01:00
|
|
|
'readonly' => false,
|
|
|
|
'value' => '',
|
2024-08-13 21:33:01 +02:00
|
|
|
'type' => 'date',
|
2019-12-15 10:47:18 +01:00
|
|
|
], $attributes);
|
2022-09-02 19:03:22 +02:00
|
|
|
// Traduction de l'aide et de l'étiquette
|
|
|
|
$attributes['label'] = helper::translate($attributes['label']);
|
|
|
|
$attributes['help'] = helper::translate($attributes['help']);
|
2022-09-05 20:17:50 +02:00
|
|
|
//$attributes['placeholder'] = helper::translate($attributes['placeholder']);
|
2024-08-13 21:33:01 +02:00
|
|
|
// Filtre selon le type
|
|
|
|
switch ($attributes['type']) {
|
|
|
|
case 'datetime-local':
|
2024-08-14 09:11:06 +02:00
|
|
|
$filter = helper::FILTER_TIMESTAMP;
|
2024-08-13 21:33:01 +02:00
|
|
|
break;
|
|
|
|
case 'date':
|
2024-08-14 09:21:32 +02:00
|
|
|
$filter = helper::FILTER_DATE; // Pour générer une valeur uniquement sur la date
|
2024-08-13 21:33:01 +02:00
|
|
|
break;
|
|
|
|
case 'time':
|
2024-08-14 09:21:32 +02:00
|
|
|
$filter = helper::FILTER_TIME; // Pour générer une valeur uniquement sur l'heure
|
2024-08-13 21:33:01 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$filter = null; // pas de filtre pour month and year
|
|
|
|
break;
|
|
|
|
}
|
2019-12-15 10:47:18 +01:00
|
|
|
// Sauvegarde des données en cas d'erreur
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['before'] and array_key_exists($attributes['id'], common::$inputBefore)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$attributes['value'] = common::$inputBefore[$attributes['id']];
|
2022-09-29 08:45:59 +02:00
|
|
|
} else {
|
2024-08-13 21:33:01 +02:00
|
|
|
$attributes['value'] = ($attributes['value'] ? helper::filter($attributes['value'], $filter) : '');
|
2019-12-15 10:47:18 +01:00
|
|
|
}
|
|
|
|
// Début du wrapper
|
|
|
|
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="inputWrapper ' . $attributes['classWrapper'] . '">';
|
|
|
|
// Label
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['label']) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$html .= self::label($attributes['id'], $attributes['label'], [
|
|
|
|
'help' => $attributes['help']
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Notice
|
|
|
|
$notice = '';
|
2022-09-29 08:45:59 +02:00
|
|
|
if (array_key_exists($attributes['id'], common::$inputNotices)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$notice = common::$inputNotices[$attributes['id']];
|
|
|
|
$attributes['class'] .= ' notice';
|
|
|
|
}
|
|
|
|
$html .= self::notice($attributes['id'], $notice);
|
|
|
|
// Date visible
|
2021-05-14 19:14:59 +02:00
|
|
|
$html .= '<div class="inputDateManagerWrapper">';
|
2019-12-15 10:47:18 +01:00
|
|
|
$html .= sprintf(
|
2023-02-17 10:59:25 +01:00
|
|
|
'<input type="' . $attributes['type'] . '" class="datepicker %s" value="%s" %s>',
|
2019-12-15 10:47:18 +01:00
|
|
|
$attributes['class'],
|
|
|
|
$attributes['value'],
|
|
|
|
helper::sprintAttributes($attributes, ['class', 'value'])
|
|
|
|
);
|
2021-05-14 19:14:59 +02:00
|
|
|
$html .= '</div>';
|
2019-12-15 10:47:18 +01:00
|
|
|
// Fin du wrapper
|
|
|
|
$html .= '</div>';
|
|
|
|
// Retourne le html
|
|
|
|
return $html;
|
2024-08-13 21:33:01 +02:00
|
|
|
}
|
2023-02-17 10:59:25 +01:00
|
|
|
|
2019-12-15 10:47:18 +01:00
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un champ d'upload de fichier
|
|
|
|
* @param string $nameId Nom et id du champ
|
|
|
|
* @param array $attributes Attributs ($key => $value)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function file($nameId, array $attributes = [])
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'before' => true,
|
|
|
|
'class' => '',
|
|
|
|
'classWrapper' => '',
|
|
|
|
'noDirty' => false,
|
|
|
|
'disabled' => false,
|
|
|
|
'extensions' => '',
|
|
|
|
'help' => '',
|
|
|
|
'id' => $nameId,
|
|
|
|
'label' => '',
|
|
|
|
'maxlength' => '500',
|
|
|
|
'name' => $nameId,
|
|
|
|
'type' => 2,
|
2022-10-23 17:27:57 +02:00
|
|
|
'value' => '',
|
2024-09-05 11:02:01 +02:00
|
|
|
'folder' => '',
|
2022-10-23 17:27:57 +02:00
|
|
|
'language' => 'fr_FR'
|
2019-12-15 10:47:18 +01:00
|
|
|
], $attributes);
|
2022-09-02 19:03:22 +02:00
|
|
|
// Traduction de l'aide et de l'étiquette
|
|
|
|
$attributes['value'] = helper::translate($attributes['value']);
|
|
|
|
$attributes['help'] = helper::translate($attributes['help']);
|
2019-12-15 10:47:18 +01:00
|
|
|
// Sauvegarde des données en cas d'erreur
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['before'] and array_key_exists($attributes['id'], common::$inputBefore)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$attributes['value'] = common::$inputBefore[$attributes['id']];
|
|
|
|
}
|
|
|
|
// Début du wrapper
|
|
|
|
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="inputWrapper ' . $attributes['classWrapper'] . '">';
|
|
|
|
// Notice
|
|
|
|
$notice = '';
|
2022-09-29 08:45:59 +02:00
|
|
|
if (array_key_exists($attributes['id'], common::$inputNotices)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$notice = common::$inputNotices[$attributes['id']];
|
|
|
|
$attributes['class'] .= ' notice';
|
|
|
|
}
|
|
|
|
$html .= self::notice($attributes['id'], $notice);
|
2022-02-09 16:10:13 +01:00
|
|
|
// Label
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['label']) {
|
2022-02-09 16:10:13 +01:00
|
|
|
$html .= self::label($attributes['id'], $attributes['label'], [
|
|
|
|
'help' => $attributes['help']
|
|
|
|
]);
|
|
|
|
}
|
2019-12-15 10:47:18 +01:00
|
|
|
// Champ caché contenant l'url de la page
|
|
|
|
$html .= self::hidden($attributes['id'], [
|
|
|
|
'class' => 'inputFileHidden',
|
|
|
|
'disabled' => $attributes['disabled'],
|
|
|
|
'maxlength' => $attributes['maxlength'],
|
|
|
|
'value' => $attributes['value']
|
|
|
|
]);
|
|
|
|
// Champ d'upload
|
2020-08-12 17:39:43 +02:00
|
|
|
$html .= '<div class="inputFileManagerWrapper">';
|
2019-12-15 10:47:18 +01:00
|
|
|
$html .= sprintf(
|
|
|
|
'<a
|
|
|
|
href="' .
|
2024-08-13 21:33:01 +02:00
|
|
|
helper::baseUrl(false) . 'core/vendor/filemanager/dialog.php' .
|
|
|
|
'?relative_url=1' .
|
|
|
|
'&lang=' . $attributes['language'] .
|
|
|
|
'&field_id=' . $attributes['id'] .
|
|
|
|
'&type=' . $attributes['type'] .
|
|
|
|
'&akey=' . md5_file(core::DATA_DIR . 'core.json') .
|
2024-09-05 11:02:01 +02:00
|
|
|
// Ajoute le nom du dossier si la variable est passée
|
2024-12-05 18:59:30 +01:00
|
|
|
(empty($attributes['folder']) ? '&fldr=/': '&fldr=' . $attributes['folder']) .
|
2024-08-13 21:33:01 +02:00
|
|
|
($attributes['extensions'] ? '&extensions=' . $attributes['extensions'] : '')
|
|
|
|
. '"
|
2019-12-15 10:47:18 +01:00
|
|
|
class="inputFile %s %s"
|
|
|
|
%s
|
|
|
|
data-lity
|
|
|
|
>
|
2024-01-04 16:46:19 +01:00
|
|
|
' . self::ico('upload-cloud', ['margin' => 'right']) . '
|
2019-12-15 10:47:18 +01:00
|
|
|
<span class="inputFileLabel"></span>
|
|
|
|
</a>',
|
|
|
|
$attributes['class'],
|
|
|
|
$attributes['disabled'] ? 'disabled' : '',
|
|
|
|
helper::sprintAttributes($attributes, ['class', 'extensions', 'type', 'maxlength'])
|
|
|
|
|
|
|
|
);
|
|
|
|
$html .= self::button($attributes['id'] . 'Delete', [
|
|
|
|
'class' => 'inputFileDelete',
|
|
|
|
'value' => self::ico('cancel')
|
|
|
|
]);
|
|
|
|
$html .= '</div>';
|
|
|
|
// Fin du wrapper
|
|
|
|
$html .= '</div>';
|
|
|
|
// Retourne le html
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Ferme un formulaire
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function formClose()
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
return '</form>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Ouvre un formulaire protégé par CSRF
|
|
|
|
* @param string $id Id du formulaire
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function formOpen($id)
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Ouverture formulaire
|
|
|
|
$html = '<form id="' . $id . '" method="post">';
|
|
|
|
// Stock le token CSRF
|
|
|
|
$html .= self::hidden('csrf', [
|
2023-06-19 19:46:00 +02:00
|
|
|
'value' => htmlentities($_SESSION['csrf'], ENT_QUOTES | ENT_HTML5, 'UTF-8')
|
2019-12-15 10:47:18 +01:00
|
|
|
]);
|
|
|
|
// Retourne le html
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée une aide qui s'affiche au survole
|
|
|
|
* @param string $text Texte de l'aide
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function help($text)
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
return '<span class="helpButton" data-tippy-content="' . $text . '">' . self::ico('help') . '<!----></span>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un champ caché
|
|
|
|
* @param string $nameId Nom et id du champ
|
|
|
|
* @param array $attributes Attributs ($key => $value)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function hidden($nameId, array $attributes = [])
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'before' => true,
|
|
|
|
'class' => '',
|
|
|
|
'noDirty' => false,
|
|
|
|
'id' => $nameId,
|
|
|
|
//'maxlength' => '500',
|
|
|
|
'name' => $nameId,
|
|
|
|
'value' => ''
|
|
|
|
], $attributes);
|
|
|
|
// Sauvegarde des données en cas d'erreur
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['before'] and array_key_exists($attributes['id'], common::$inputBefore)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$attributes['value'] = common::$inputBefore[$attributes['id']];
|
|
|
|
}
|
|
|
|
// Texte
|
|
|
|
$html = sprintf('<input type="hidden" %s>', helper::sprintAttributes($attributes, ['before']));
|
|
|
|
// Retourne le html
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un icône
|
|
|
|
* @Array :
|
|
|
|
* @param string $ico Classe de l'icône
|
|
|
|
* @param string $margin Ajoute un margin autour de l'icône (choix : left, right, all)
|
|
|
|
* @param bool $animate Ajoute une animation à l'icône
|
|
|
|
* @param string $fontSize Taille de la police
|
|
|
|
* @param string $href lien vers une url
|
|
|
|
* @param string $help popup d'aide
|
|
|
|
* @param string $id de l'élement
|
|
|
|
* @return string
|
|
|
|
*/
|
2022-08-27 10:17:43 +02:00
|
|
|
// public static function ico($ico, $margin = '', $animate = false, $fontSize = '1em') {
|
2022-09-29 08:45:59 +02:00
|
|
|
public static function ico($ico, array $attributes = [])
|
|
|
|
{
|
2022-08-27 10:17:43 +02:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'margin' => '',
|
2022-08-28 19:37:58 +02:00
|
|
|
'animate' => false,
|
|
|
|
'fontSize' => '1em',
|
|
|
|
'href' => '',
|
|
|
|
'attr' => '',
|
|
|
|
'help' => '',
|
2022-12-13 08:13:16 +01:00
|
|
|
'id' => '',
|
2022-08-27 10:17:43 +02:00
|
|
|
], $attributes);
|
2022-09-02 19:03:22 +02:00
|
|
|
// Traduction de l'aide
|
2022-09-02 15:36:05 +02:00
|
|
|
$attributes['help'] = helper::translate($attributes['help']);
|
2022-09-02 19:03:22 +02:00
|
|
|
// Contenu de l'icône
|
2024-08-13 21:33:01 +02:00
|
|
|
$alt = $attributes['help'] ? $attributes['help'] : $ico;
|
2023-03-07 16:44:11 +01:00
|
|
|
$item = $attributes['href'] ? '<a id="' . $attributes['id'] . '" data-tippy-content="' . $attributes['help'] . '" alt="' . $alt . '" href="' . $attributes['href'] . '" ' . $attributes['attr'] . ' >' : '';
|
2022-09-06 20:07:15 +02:00
|
|
|
$item .= '<span class="zwiico-' . $ico . ($attributes['margin'] ? ' zwiico-margin-' . $attributes['margin'] : '') . ($attributes['animate'] ? ' animate-spin' : '') . '" style="font-size:' . $attributes['fontSize'] . '"><!----></span>';
|
2022-08-28 19:37:58 +02:00
|
|
|
$item .= ($attributes['href']) ? '</a>' : '';
|
|
|
|
return $item;
|
2019-12-15 10:47:18 +01:00
|
|
|
}
|
|
|
|
|
2022-09-28 14:58:21 +02:00
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un drapeau du site courante
|
|
|
|
* @param string $langId Id de la langue à affiche ou selected pour la langue courante
|
|
|
|
* @param string size en pixels ou en rem
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function flag($langId, $size = 'auto')
|
|
|
|
{
|
2022-10-18 11:03:48 +02:00
|
|
|
$lang = 'fr_FR';
|
2021-10-03 17:26:05 +02:00
|
|
|
switch ($langId) {
|
|
|
|
case '':
|
|
|
|
break;
|
2022-10-18 11:07:48 +02:00
|
|
|
case array_key_exists($langId, core::$languages):
|
2021-10-03 17:26:05 +02:00
|
|
|
$lang = $langId;
|
|
|
|
break;
|
2022-09-28 14:58:21 +02:00
|
|
|
case 'selected':
|
2024-05-06 16:18:35 +02:00
|
|
|
if (isset($_SESSION['ZWII_SITE_CONTENT'])) {
|
|
|
|
$lang = $_SESSION['ZWII_SITE_CONTENT'];
|
2021-10-03 17:26:05 +02:00
|
|
|
} else {
|
2022-09-24 18:06:32 +02:00
|
|
|
$lang = 'fr_FR';
|
2021-10-03 17:26:05 +02:00
|
|
|
}
|
2021-10-02 14:15:27 +02:00
|
|
|
}
|
2022-10-18 11:03:48 +02:00
|
|
|
return '<img class="flag" src="' . helper::baseUrl(false) . 'core/vendor/i18n/png/' . $lang . '.png"
|
2022-09-29 08:45:59 +02:00
|
|
|
width="' . $size . '"
|
|
|
|
height="' . $size . '"
|
2022-10-18 11:03:48 +02:00
|
|
|
title="' . $lang . '"
|
|
|
|
alt="(' . $lang . ')"/>';
|
2021-10-02 14:15:27 +02:00
|
|
|
}
|
|
|
|
|
2019-12-15 10:47:18 +01:00
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un label
|
|
|
|
* @param string $for For du label
|
|
|
|
* @param array $attributes Attributs ($key => $value)
|
|
|
|
* @param string $text Texte du label
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function label($for, $text, array $attributes = [])
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'class' => '',
|
|
|
|
'for' => $for,
|
|
|
|
'help' => ''
|
|
|
|
], $attributes);
|
2022-12-31 10:37:11 +01:00
|
|
|
// Traduction de l'aide et de l'étiquette
|
|
|
|
$text = helper::translate($text);
|
|
|
|
$attributes['help'] = helper::translate($attributes['help']);
|
|
|
|
|
2022-09-29 08:45:59 +02:00
|
|
|
if (
|
2022-09-05 09:00:23 +02:00
|
|
|
get_called_class() !== 'template'
|
|
|
|
) {
|
|
|
|
$attributes['help'] = helper::translate($attributes['help']);
|
|
|
|
}
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['help'] !== '') {
|
2019-12-15 10:47:18 +01:00
|
|
|
$text = $text . self::help($attributes['help']);
|
|
|
|
}
|
|
|
|
// Retourne le html
|
|
|
|
return sprintf(
|
|
|
|
'<label %s>%s</label>',
|
|
|
|
helper::sprintAttributes($attributes),
|
|
|
|
$text
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un champ mail
|
|
|
|
* @param string $nameId Nom et id du champ
|
|
|
|
* @param array $attributes Attributs ($key => $value)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function mail($nameId, array $attributes = [])
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'autocomplete' => 'on',
|
|
|
|
'before' => true,
|
|
|
|
'class' => '',
|
|
|
|
'classWrapper' => '',
|
|
|
|
'noDirty' => false,
|
|
|
|
'disabled' => false,
|
|
|
|
'help' => '',
|
|
|
|
'id' => $nameId,
|
|
|
|
'label' => '',
|
|
|
|
//'maxlength' => '500',
|
|
|
|
'name' => $nameId,
|
|
|
|
'placeholder' => '',
|
|
|
|
'readonly' => false,
|
|
|
|
'value' => ''
|
|
|
|
], $attributes);
|
2022-09-02 19:03:22 +02:00
|
|
|
// Traduction de l'aide et de l'étiquette
|
2022-11-07 10:25:13 +01:00
|
|
|
$attributes['label'] = helper::translate($attributes['label']);
|
2022-09-02 19:03:22 +02:00
|
|
|
$attributes['help'] = helper::translate($attributes['help']);
|
2022-09-05 20:17:50 +02:00
|
|
|
//$attributes['placeholder'] = helper::translate($attributes['placeholder']);
|
2019-12-15 10:47:18 +01:00
|
|
|
// Sauvegarde des données en cas d'erreur
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['before'] and array_key_exists($attributes['id'], common::$inputBefore)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$attributes['value'] = common::$inputBefore[$attributes['id']];
|
|
|
|
}
|
|
|
|
// Début du wrapper
|
|
|
|
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="inputWrapper ' . $attributes['classWrapper'] . '">';
|
|
|
|
// Label
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['label']) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$html .= self::label($attributes['id'], $attributes['label'], [
|
|
|
|
'help' => $attributes['help']
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Notice
|
|
|
|
$notice = '';
|
2022-09-29 08:45:59 +02:00
|
|
|
if (array_key_exists($attributes['id'], common::$inputNotices)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$notice = common::$inputNotices[$attributes['id']];
|
|
|
|
$attributes['class'] .= ' notice';
|
|
|
|
}
|
|
|
|
$html .= self::notice($attributes['id'], $notice);
|
|
|
|
// Texte
|
|
|
|
$html .= sprintf(
|
|
|
|
'<input type="email" %s>',
|
|
|
|
helper::sprintAttributes($attributes)
|
|
|
|
);
|
|
|
|
// Fin du wrapper
|
|
|
|
$html .= '</div>';
|
|
|
|
// Retourne le html
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée une notice
|
|
|
|
* @param string $id Id du champ
|
|
|
|
* @param string $notice Notice
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function notice($id, $notice)
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
return ' <span id="' . $id . 'Notice" class="notice ' . ($notice ? '' : 'displayNone') . '">' . $notice . '</span>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un champ mot de passe
|
|
|
|
* @param string $nameId Nom et id du champ
|
|
|
|
* @param array $attributes Attributs ($key => $value)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function password($nameId, array $attributes = [])
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'autocomplete' => 'on',
|
|
|
|
'class' => '',
|
|
|
|
'classWrapper' => '',
|
|
|
|
'noDirty' => false,
|
|
|
|
'disabled' => false,
|
|
|
|
'help' => '',
|
|
|
|
'id' => $nameId,
|
|
|
|
'label' => '',
|
|
|
|
//'maxlength' => '500',
|
|
|
|
'name' => $nameId,
|
|
|
|
'placeholder' => '',
|
|
|
|
'readonly' => false
|
|
|
|
], $attributes);
|
2022-09-02 19:03:22 +02:00
|
|
|
// Traduction de l'aide et de l'étiquette
|
|
|
|
$attributes['label'] = helper::translate($attributes['label']);
|
2022-09-05 20:17:50 +02:00
|
|
|
//$attributes['placeholder'] = helper::translate($attributes['placeholder']);
|
2022-09-02 19:03:22 +02:00
|
|
|
$attributes['help'] = helper::translate($attributes['help']);
|
2019-12-15 10:47:18 +01:00
|
|
|
// Début du wrapper
|
|
|
|
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="inputWrapper ' . $attributes['classWrapper'] . '">';
|
|
|
|
// Label
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['label']) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$html .= self::label($attributes['id'], $attributes['label'], [
|
|
|
|
'help' => $attributes['help']
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Notice
|
|
|
|
$notice = '';
|
2022-09-29 08:45:59 +02:00
|
|
|
if (array_key_exists($attributes['id'], common::$inputNotices)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$notice = common::$inputNotices[$attributes['id']];
|
|
|
|
$attributes['class'] .= ' notice';
|
|
|
|
}
|
|
|
|
$html .= self::notice($attributes['id'], $notice);
|
|
|
|
// Mot de passe
|
|
|
|
$html .= sprintf(
|
|
|
|
'<input type="password" %s>',
|
|
|
|
helper::sprintAttributes($attributes)
|
|
|
|
);
|
|
|
|
// Fin du wrapper
|
|
|
|
$html .= '</div>';
|
|
|
|
// Retourne le html
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un champ sélection
|
|
|
|
* @param string $nameId Nom et id du champ
|
|
|
|
* @param array $options Liste des options du champ de sélection ($value => $text)
|
|
|
|
* @param array $attributes Attributs ($key => $value)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function select($nameId, array $options, array $attributes = [])
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'before' => true,
|
|
|
|
'class' => '',
|
|
|
|
'classWrapper' => '',
|
|
|
|
'noDirty' => false,
|
|
|
|
'disabled' => false,
|
|
|
|
'help' => '',
|
|
|
|
'id' => $nameId,
|
|
|
|
'label' => '',
|
|
|
|
'name' => $nameId,
|
2020-02-18 15:07:57 +01:00
|
|
|
'selected' => '',
|
2024-08-13 21:33:01 +02:00
|
|
|
'font' => [],
|
2023-11-21 11:56:37 +01:00
|
|
|
'multiple' => ''
|
2019-12-15 10:47:18 +01:00
|
|
|
], $attributes);
|
2022-09-02 19:03:22 +02:00
|
|
|
// Traduction de l'aide et de l'étiquette
|
|
|
|
$attributes['label'] = helper::translate($attributes['label']);
|
2024-08-13 21:33:01 +02:00
|
|
|
$attributes['help'] = helper::translate($attributes['help']);
|
2022-04-21 18:38:19 +02:00
|
|
|
// Stocker les fontes et remettre à zéro le tableau des fontes transmis pour éviter une erreur de sprintAttributes
|
2023-03-01 15:50:41 +01:00
|
|
|
if (empty($attributes['font']) === false) {
|
|
|
|
$fonts = $attributes['font'];
|
|
|
|
$attributes['font'] = [];
|
2022-04-21 18:38:19 +02:00
|
|
|
}
|
2019-12-15 10:47:18 +01:00
|
|
|
// Sauvegarde des données en cas d'erreur
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['before'] and array_key_exists($attributes['id'], common::$inputBefore)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$attributes['selected'] = common::$inputBefore[$attributes['id']];
|
|
|
|
}
|
|
|
|
// Début du wrapper
|
|
|
|
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="inputWrapper ' . $attributes['classWrapper'] . '">';
|
|
|
|
// Label
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['label']) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$html .= self::label($attributes['id'], $attributes['label'], [
|
|
|
|
'help' => $attributes['help']
|
|
|
|
]);
|
|
|
|
}
|
2022-09-29 08:45:59 +02:00
|
|
|
// Notice
|
2019-12-15 10:47:18 +01:00
|
|
|
$notice = '';
|
2022-09-29 08:45:59 +02:00
|
|
|
if (array_key_exists($attributes['id'], common::$inputNotices)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$notice = common::$inputNotices[$attributes['id']];
|
|
|
|
$attributes['class'] .= ' notice';
|
|
|
|
}
|
|
|
|
$html .= self::notice($attributes['id'], $notice);
|
2023-11-21 11:56:37 +01:00
|
|
|
// Attribut multiple
|
|
|
|
if ($attributes['multiple'] === true) {
|
|
|
|
echo "ppp";
|
|
|
|
$attributes['multiple'] = 'multiple';
|
|
|
|
}
|
2019-12-15 10:47:18 +01:00
|
|
|
// Début sélection
|
2022-09-29 08:45:59 +02:00
|
|
|
$html .= sprintf(
|
|
|
|
'<select %s>',
|
2019-12-15 10:47:18 +01:00
|
|
|
helper::sprintAttributes($attributes)
|
|
|
|
);
|
2022-09-29 08:45:59 +02:00
|
|
|
foreach ($options as $value => $text) {
|
2022-04-21 18:38:19 +02:00
|
|
|
// Select des liste de fontes
|
2024-08-13 21:33:01 +02:00
|
|
|
$html .= isset($fonts) ? sprintf(
|
2022-09-29 08:45:59 +02:00
|
|
|
'<option value="%s"%s style="font-family: %s;">%s</option>',
|
|
|
|
$value,
|
|
|
|
$attributes['selected'] == $value ? ' selected' : '', // Double == pour ignorer le type de variable car $_POST change les types en string
|
|
|
|
$fonts[$value],
|
|
|
|
$text
|
2022-04-21 18:38:19 +02:00
|
|
|
// Select standard
|
2022-09-29 08:45:59 +02:00
|
|
|
) : sprintf(
|
|
|
|
'<option value="%s"%s>%s</option>',
|
|
|
|
$value,
|
|
|
|
$attributes['selected'] == $value ? ' selected' : '', // Double == pour ignorer le type de variable car $_POST change les types en string
|
2023-01-02 17:23:11 +01:00
|
|
|
helper::translate($text)
|
2022-09-29 08:45:59 +02:00
|
|
|
);
|
2019-12-15 10:47:18 +01:00
|
|
|
}
|
|
|
|
// Fin sélection
|
|
|
|
$html .= '</select>';
|
|
|
|
// Fin du wrapper
|
|
|
|
$html .= '</div>';
|
|
|
|
// Retourne le html
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
2023-11-21 11:56:37 +01:00
|
|
|
|
2019-12-15 10:47:18 +01:00
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée une bulle de dialogue
|
|
|
|
* @param string $text Texte de la bulle
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function speech($text)
|
|
|
|
{
|
2023-01-10 15:18:07 +01:00
|
|
|
return '<div class="speech"><div class="speechBubble">' . helper::translate($text) . '</div>' . template::ico('mimi speechMimi', ['fontSize' => '7em']) . '</div>';
|
2019-12-15 10:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un bouton validation
|
|
|
|
* @param string $nameId Nom & id du bouton validation
|
|
|
|
* @param array $attributes Attributs ($key => $value)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function submit($nameId, array $attributes = [])
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'class' => '',
|
|
|
|
'disabled' => false,
|
|
|
|
'ico' => 'check',
|
|
|
|
'id' => $nameId,
|
|
|
|
'name' => $nameId,
|
|
|
|
'uniqueSubmission' => false, //true avant 9.1.08
|
|
|
|
'value' => 'Enregistrer'
|
|
|
|
], $attributes);
|
2022-09-19 19:31:06 +02:00
|
|
|
// Traduction de l'aide et de l'étiquette
|
|
|
|
$attributes['value'] = helper::translate($attributes['value']);
|
2019-12-15 10:47:18 +01:00
|
|
|
// Retourne le html
|
2024-08-13 21:33:01 +02:00
|
|
|
return sprintf(
|
2019-12-15 10:47:18 +01:00
|
|
|
'<button type="submit" class="%s%s" %s>%s</button>',
|
|
|
|
$attributes['class'],
|
|
|
|
$attributes['uniqueSubmission'] ? 'uniqueSubmission' : '',
|
|
|
|
helper::sprintAttributes($attributes, ['class', 'ico', 'value']),
|
2022-08-27 10:17:43 +02:00
|
|
|
($attributes['ico'] ? template::ico($attributes['ico'], ['margin' => 'right']) : '') . $attributes['value']
|
2019-12-15 10:47:18 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un tableau
|
|
|
|
* @param array $cols Cols des colonnes (format: [col colonne1, col colonne2, etc])
|
|
|
|
* @param array $body Contenu (format: [[contenu1, contenu2, etc], [contenu1, contenu2, etc]])
|
|
|
|
* @param array $head Entêtes (format : [[titre colonne1, titre colonne2, etc])
|
2020-04-04 15:58:09 +02:00
|
|
|
* @param array $rowsId Id pour la numérotation des rows (format : [id colonne1, id colonne2, etc])
|
2022-09-29 08:45:59 +02:00
|
|
|
* @param array $attributes Attributs ($key => $value)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function table(array $cols = [], array $body = [], array $head = [], array $attributes = [], array $rowsId = [])
|
|
|
|
{
|
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'class' => '',
|
|
|
|
'classWrapper' => '',
|
|
|
|
'id' => ''
|
|
|
|
], $attributes);
|
2022-09-19 19:31:06 +02:00
|
|
|
// Traduction de l'aide et de l'étiquette
|
2022-09-29 08:45:59 +02:00
|
|
|
foreach ($head as $value) {
|
2024-08-13 21:33:01 +02:00
|
|
|
$head[array_search($value, $head)] = helper::translate($value);
|
2022-09-29 08:45:59 +02:00
|
|
|
}
|
|
|
|
// Début du wrapper
|
|
|
|
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="tableWrapper ' . $attributes['classWrapper'] . '">';
|
|
|
|
// Début tableau
|
|
|
|
$html .= '<table id="' . $attributes['id'] . '" class="table ' . $attributes['class'] . '">';
|
|
|
|
// Entêtes
|
|
|
|
if ($head) {
|
|
|
|
// Début des entêtes
|
|
|
|
$html .= '<thead>';
|
|
|
|
$html .= '<tr class="nodrag">';
|
|
|
|
$i = 0;
|
|
|
|
foreach ($head as $th) {
|
|
|
|
$html .= '<th class="col' . $cols[$i++] . '">' . $th . '</th>';
|
|
|
|
}
|
|
|
|
// Fin des entêtes
|
|
|
|
$html .= '</tr>';
|
|
|
|
$html .= '</thead>';
|
2020-04-04 15:54:19 +02:00
|
|
|
}
|
|
|
|
// Pas de tableau d'Id transmis, générer une numérotation
|
2020-04-04 15:56:46 +02:00
|
|
|
if (empty($rowsId)) {
|
2022-09-29 08:45:59 +02:00
|
|
|
$rowsId = range(0, count($body));
|
|
|
|
}
|
|
|
|
// Début contenu
|
|
|
|
$j = 0;
|
|
|
|
foreach ($body as $tr) {
|
|
|
|
// Id de ligne pour les tableaux drag and drop
|
|
|
|
$html .= '<tr id="' . $rowsId[$j++] . '">';
|
|
|
|
$i = 0;
|
|
|
|
foreach ($tr as $td) {
|
|
|
|
$html .= '<td class="col' . $cols[$i++] . '">' . $td . '</td>';
|
|
|
|
}
|
|
|
|
$html .= '</tr>';
|
|
|
|
}
|
|
|
|
// Fin contenu
|
|
|
|
$html .= '</tbody>';
|
|
|
|
// Fin tableau
|
|
|
|
$html .= '</table>';
|
|
|
|
// Fin container
|
|
|
|
$html .= '</div>';
|
|
|
|
// Retourne le html
|
|
|
|
return $html;
|
|
|
|
}
|
2019-12-15 10:47:18 +01:00
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un champ texte court
|
|
|
|
* @param string $nameId Nom et id du champ
|
|
|
|
* @param array $attributes Attributs ($key => $value)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function text($nameId, array $attributes = [])
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'autocomplete' => 'on',
|
|
|
|
'before' => true,
|
|
|
|
'class' => '',
|
|
|
|
'classWrapper' => '',
|
|
|
|
'noDirty' => false,
|
|
|
|
'disabled' => false,
|
|
|
|
'help' => '',
|
|
|
|
'id' => $nameId,
|
|
|
|
'label' => '',
|
|
|
|
//'maxlength' => '500',
|
|
|
|
'name' => $nameId,
|
|
|
|
'placeholder' => '',
|
|
|
|
'readonly' => false,
|
2023-02-02 09:39:05 +01:00
|
|
|
'value' => '',
|
|
|
|
'type' => 'text'
|
2019-12-15 10:47:18 +01:00
|
|
|
], $attributes);
|
2022-09-02 19:03:22 +02:00
|
|
|
// Traduction de l'aide et de l'étiquette
|
|
|
|
$attributes['label'] = helper::translate($attributes['label']);
|
|
|
|
$attributes['help'] = helper::translate($attributes['help']);
|
2022-09-05 20:17:50 +02:00
|
|
|
//$attributes['placeholder'] = helper::translate($attributes['placeholder']);
|
2019-12-15 10:47:18 +01:00
|
|
|
// Sauvegarde des données en cas d'erreur
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['before'] and array_key_exists($attributes['id'], common::$inputBefore)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$attributes['value'] = common::$inputBefore[$attributes['id']];
|
|
|
|
}
|
|
|
|
// Début du wrapper
|
|
|
|
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="inputWrapper ' . $attributes['classWrapper'] . '">';
|
|
|
|
// Label
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['label']) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$html .= self::label($attributes['id'], $attributes['label'], [
|
|
|
|
'help' => $attributes['help']
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Notice
|
|
|
|
$notice = '';
|
2022-09-29 08:45:59 +02:00
|
|
|
if (array_key_exists($attributes['id'], common::$inputNotices)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$notice = common::$inputNotices[$attributes['id']];
|
|
|
|
$attributes['class'] .= ' notice';
|
|
|
|
}
|
|
|
|
$html .= self::notice($attributes['id'], $notice);
|
|
|
|
// Texte
|
|
|
|
$html .= sprintf(
|
2024-08-13 21:33:01 +02:00
|
|
|
'<input type="' . $attributes['type'] . '" %s>',
|
2019-12-15 10:47:18 +01:00
|
|
|
helper::sprintAttributes($attributes)
|
|
|
|
);
|
|
|
|
// Fin du wrapper
|
|
|
|
$html .= '</div>';
|
|
|
|
// Retourne le html
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-29 08:45:59 +02:00
|
|
|
* Crée un champ texte long
|
|
|
|
* @param string $nameId Nom et id du champ
|
|
|
|
* @param array $attributes Attributs ($key => $value)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function textarea($nameId, array $attributes = [])
|
|
|
|
{
|
2019-12-15 10:47:18 +01:00
|
|
|
// Attributs par défaut
|
|
|
|
$attributes = array_merge([
|
|
|
|
'before' => true,
|
2020-05-12 16:28:10 +02:00
|
|
|
'class' => '', // editorWysiwyg et editor possible pour utiliser un éditeur (il faut également instancier les librairies)
|
2019-12-15 10:47:18 +01:00
|
|
|
'classWrapper' => '',
|
|
|
|
'disabled' => false,
|
|
|
|
'noDirty' => false,
|
|
|
|
'help' => '',
|
|
|
|
'id' => $nameId,
|
|
|
|
'label' => '',
|
|
|
|
//'maxlength' => '500',
|
|
|
|
'name' => $nameId,
|
|
|
|
'readonly' => false,
|
|
|
|
'value' => ''
|
|
|
|
], $attributes);
|
2022-09-02 19:03:22 +02:00
|
|
|
// Traduction de l'aide et de l'étiquette
|
|
|
|
$attributes['label'] = helper::translate($attributes['label']);
|
|
|
|
$attributes['help'] = helper::translate($attributes['help']);
|
2019-12-15 10:47:18 +01:00
|
|
|
// Sauvegarde des données en cas d'erreur
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['before'] and array_key_exists($attributes['id'], common::$inputBefore)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$attributes['value'] = common::$inputBefore[$attributes['id']];
|
|
|
|
}
|
|
|
|
// Début du wrapper
|
|
|
|
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="inputWrapper ' . $attributes['classWrapper'] . '">';
|
|
|
|
// Label
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($attributes['label']) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$html .= self::label($attributes['id'], $attributes['label'], [
|
|
|
|
'help' => $attributes['help']
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Notice
|
|
|
|
$notice = '';
|
2022-09-29 08:45:59 +02:00
|
|
|
if (array_key_exists($attributes['id'], common::$inputNotices)) {
|
2019-12-15 10:47:18 +01:00
|
|
|
$notice = common::$inputNotices[$attributes['id']];
|
|
|
|
$attributes['class'] .= ' notice';
|
|
|
|
}
|
|
|
|
$html .= self::notice($attributes['id'], $notice);
|
|
|
|
// Texte long
|
|
|
|
$html .= sprintf(
|
|
|
|
'<textarea %s>%s</textarea>',
|
|
|
|
helper::sprintAttributes($attributes, ['value']),
|
|
|
|
$attributes['value']
|
|
|
|
);
|
|
|
|
// Fin du wrapper
|
|
|
|
$html .= '</div>';
|
|
|
|
// Retourne le html
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
}
|