$value) * @return string */ public static function button($nameId, array $attributes = []) { // Attributs par défaut $attributes = array_merge([ 'class' => '', 'disabled' => false, 'href' => 'javascript:void(0);', 'ico' => '', 'id' => $nameId, 'name' => $nameId, 'target' => '', 'uniqueSubmission' => false, 'value' => 'Bouton' ], $attributes); // Retourne le html return sprintf( '%s', helper::sprintAttributes($attributes, ['class', 'disabled', 'ico', 'value']), $attributes['disabled'] ? 'disabled' : '', $attributes['class'], $attributes['uniqueSubmission'] ? 'uniqueSubmission' : '', ($attributes['ico'] ? template::ico($attributes['ico'], 'right') : '') . $attributes['value'] ); } /** * Crée un champ capcha * @param string $nameId Nom et id du champ * @param array $attributes Attributs ($key => $value) * @return string */ public static function capcha($nameId, array $attributes = []) { // Attributs par défaut $attributes = array_merge([ 'class' => '', 'classWrapper' => '', 'help' => '', 'id' => $nameId, 'name' => $nameId, 'value' => '' ], $attributes); // Génère deux nombres pour le capcha $firstNumber = mt_rand(1, 15); $secondNumber = mt_rand(1, 15); // Début du wrapper $html = '
'; // Label $html .= self::label($attributes['id'], $firstNumber . ' + ' . $secondNumber . ' = ?', [ 'help' => $attributes['help'] ]); // Notice $notice = ''; if(array_key_exists($attributes['id'], common::$inputNotices)) { $notice = common::$inputNotices[$attributes['id']]; $attributes['class'] .= ' notice'; } $html .= self::notice($attributes['id'], $notice); // Capcha $html .= sprintf( '', helper::sprintAttributes($attributes) ); // Champs cachés contenant les nombres $html .= self::hidden($attributes['id'] . 'FirstNumber', [ 'value' => $firstNumber, 'before' => false ]); $html .= self::hidden($attributes['id'] . 'SecondNumber', [ 'value' => $secondNumber, 'before' => false ]); // Fin du wrapper $html .= '
'; // Retourne le html return $html; } /** * 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 = []) { // Attributs par défaut $attributes = array_merge([ 'before' => true, 'checked' => '', 'class' => '', 'classWrapper' => '', 'disabled' => false, 'help' => '', 'id' => $nameId, 'name' => $nameId ], $attributes); // Sauvegarde des données en cas d'erreur if($attributes['before'] AND array_key_exists($attributes['id'], common::$inputBefore)) { $attributes['checked'] = (bool) common::$inputBefore[$attributes['id']]; } // Début du wrapper $html = '
'; // Notice $notice = ''; if(array_key_exists($attributes['id'], common::$inputNotices)) { $notice = common::$inputNotices[$attributes['id']]; $attributes['class'] .= ' notice'; } $html .= self::notice($attributes['id'], $notice); // Case à cocher $html .= sprintf( '', $value, helper::sprintAttributes($attributes) ); // Label $html .= self::label($attributes['id'], '' . $label . '', [ 'help' => $attributes['help'] ]); // Fin du wrapper $html .= '
'; // Retourne le html return $html; } /** * Crée un champ date * @param string $nameId Nom et id du champ * @param array $attributes Attributs ($key => $value) * @return string */ public static function date($nameId, array $attributes = []) { // Attributs par défaut $attributes = array_merge([ 'autocomplete' => 'on', 'before' => true, 'class' => '', 'classWrapper' => '', 'noDirty' => false, 'disabled' => false, 'help' => '', 'id' => $nameId, 'label' => '', 'name' => $nameId, 'placeholder' => '', 'readonly' => true, 'value' => '' ], $attributes); // Sauvegarde des données en cas d'erreur if($attributes['before'] AND array_key_exists($attributes['id'], common::$inputBefore)) { $attributes['value'] = common::$inputBefore[$attributes['id']]; } else { $attributes['value'] = ($attributes['value'] ? helper::filter($attributes['value'], helper::FILTER_TIMESTAMP) : ''); } // Début du wrapper $html = '
'; // Label if($attributes['label']) { $html .= self::label($attributes['id'], $attributes['label'], [ 'help' => $attributes['help'] ]); } // Notice $notice = ''; if(array_key_exists($attributes['id'], common::$inputNotices)) { $notice = common::$inputNotices[$attributes['id']]; $attributes['class'] .= ' notice'; } $html .= self::notice($attributes['id'], $notice); // Date visible $html .= sprintf( '', $attributes['class'], $attributes['value'], helper::sprintAttributes($attributes, ['class', 'value']) ); // Fin du wrapper $html .= '
'; // Retourne le html return $html; } /** * 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 = []) { // 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, 'value' => '' ], $attributes); // Sauvegarde des données en cas d'erreur if($attributes['before'] AND array_key_exists($attributes['id'], common::$inputBefore)) { $attributes['value'] = common::$inputBefore[$attributes['id']]; } // Début du wrapper $html = '
'; // Label if($attributes['label']) { $html .= self::label($attributes['id'], $attributes['label'], [ 'help' => $attributes['help'] ]); } // Notice $notice = ''; if(array_key_exists($attributes['id'], common::$inputNotices)) { $notice = common::$inputNotices[$attributes['id']]; $attributes['class'] .= ' notice'; } $html .= self::notice($attributes['id'], $notice); // 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 $html .= '
'; $html .= sprintf( ' ' . self::ico('upload', 'right') . ' ', $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 .= '
'; // Fin du wrapper $html .= '
'; // Retourne le html return $html; } /** * Ferme un formulaire * @return string */ public static function formClose() { return ''; } /** * Ouvre un formulaire protégé par CSRF * @param string $id Id du formulaire * @return string */ public static function formOpen($id) { // Ouverture formulaire $html = '
'; // Stock le token CSRF $html .= self::hidden('csrf', [ 'value' => $_SESSION['csrf'] ]); // Retourne le html return $html; } /** * Crée une aide qui s'affiche au survole * @param string $text Texte de l'aide * @return string */ public static function help($text) { return '' . self::ico('help') . ''; } /** * 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 = []) { // 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 if($attributes['before'] AND array_key_exists($attributes['id'], common::$inputBefore)) { $attributes['value'] = common::$inputBefore[$attributes['id']]; } // Texte $html = sprintf('', helper::sprintAttributes($attributes, ['before'])); // Retourne le html return $html; } /** * Crée un icône * @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 * @return string */ public static function ico($ico, $margin = '', $animate = false, $fontSize = '1em') { return ''; } /** * 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 = []) { // Attributs par défaut $attributes = array_merge([ 'class' => '', 'for' => $for, 'help' => '' ], $attributes); // Ajout d'une aide if($attributes['help'] !== '') { $text = $text . self::help($attributes['help']); } // Retourne le html return sprintf( '', helper::sprintAttributes($attributes), $text ); } /** * 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 = []) { // 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); // Sauvegarde des données en cas d'erreur if($attributes['before'] AND array_key_exists($attributes['id'], common::$inputBefore)) { $attributes['value'] = common::$inputBefore[$attributes['id']]; } // Début du wrapper $html = '
'; // Label if($attributes['label']) { $html .= self::label($attributes['id'], $attributes['label'], [ 'help' => $attributes['help'] ]); } // Notice $notice = ''; if(array_key_exists($attributes['id'], common::$inputNotices)) { $notice = common::$inputNotices[$attributes['id']]; $attributes['class'] .= ' notice'; } $html .= self::notice($attributes['id'], $notice); // Texte $html .= sprintf( '', helper::sprintAttributes($attributes) ); // Fin du wrapper $html .= '
'; // Retourne le html return $html; } /** * Crée une notice * @param string $id Id du champ * @param string $notice Notice * @return string */ public static function notice($id, $notice) { return ' ' . $notice . ''; } /** * 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 = []) { // 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); // Début du wrapper $html = '
'; // Label if($attributes['label']) { $html .= self::label($attributes['id'], $attributes['label'], [ 'help' => $attributes['help'] ]); } // Notice $notice = ''; if(array_key_exists($attributes['id'], common::$inputNotices)) { $notice = common::$inputNotices[$attributes['id']]; $attributes['class'] .= ' notice'; } $html .= self::notice($attributes['id'], $notice); // Mot de passe $html .= sprintf( '', helper::sprintAttributes($attributes) ); // Fin du wrapper $html .= '
'; // Retourne le html return $html; } /** * 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 = []) { // Attributs par défaut $attributes = array_merge([ 'before' => true, 'class' => '', 'classWrapper' => '', 'noDirty' => false, 'disabled' => false, 'help' => '', 'id' => $nameId, 'label' => '', 'name' => $nameId, 'selected' => '', 'fonts' => false ], $attributes); // Sauvegarde des données en cas d'erreur if($attributes['before'] AND array_key_exists($attributes['id'], common::$inputBefore)) { $attributes['selected'] = common::$inputBefore[$attributes['id']]; } // Liste des polices à intégrer if ($attributes['fonts'] === true) { foreach ($options as $fontId) { echo "\n"; } } // Début du wrapper $html = '
'; // Label if($attributes['label']) { $html .= self::label($attributes['id'], $attributes['label'], [ 'help' => $attributes['help'] ]); } // Notice $notice = ''; if(array_key_exists($attributes['id'], common::$inputNotices)) { $notice = common::$inputNotices[$attributes['id']]; $attributes['class'] .= ' notice'; } $html .= self::notice($attributes['id'], $notice); // Début sélection $html .= sprintf(''; // Fin du wrapper $html .= '
'; // Retourne le html return $html; } /** * Crée une bulle de dialogue * @param string $text Texte de la bulle * @return string */ public static function speech($text) { return '
' . $text . '
' . template::ico('mimi speechMimi', '', false, '7em') . '
'; } /** * 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 = []) { // 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); // Retourne le html return sprintf( '', $attributes['class'], $attributes['uniqueSubmission'] ? 'uniqueSubmission' : '', helper::sprintAttributes($attributes, ['class', 'ico', 'value']), ($attributes['ico'] ? template::ico($attributes['ico'], 'right') : '') . $attributes['value'] ); } /** * 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]) * @param array $rowsId Id pour la numérotation des rows (format : [id colonne1, id colonne2, etc]) * @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); // Début du wrapper $html = '
'; // Début tableau $html .= ''; // Entêtes if($head) { // Début des entêtes $html .= ''; $html .= ''; $i = 0; foreach($head as $th) { $html .= ''; } // Fin des entêtes $html .= ''; $html .= ''; } // Pas de tableau d'Id transmis, générer une numérotation if (empty($rowsId)) { $rowsId = range(0,count($body)); } // Début contenu $j = 0; foreach($body as $tr) { // Id de ligne pour les tableaux drag and drop $html .= ''; $i = 0; foreach($tr as $td) { $html .= ''; } $html .= ''; } // Fin contenu $html .= ''; // Fin tableau $html .= '
' . $th . '
' . $td . '
'; // Fin container $html .= '
'; // Retourne le html return $html; } /** * 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 = []) { // 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); // Sauvegarde des données en cas d'erreur if($attributes['before'] AND array_key_exists($attributes['id'], common::$inputBefore)) { $attributes['value'] = common::$inputBefore[$attributes['id']]; } // Début du wrapper $html = '
'; // Label if($attributes['label']) { $html .= self::label($attributes['id'], $attributes['label'], [ 'help' => $attributes['help'] ]); } // Notice $notice = ''; if(array_key_exists($attributes['id'], common::$inputNotices)) { $notice = common::$inputNotices[$attributes['id']]; $attributes['class'] .= ' notice'; } $html .= self::notice($attributes['id'], $notice); // Texte $html .= sprintf( '', helper::sprintAttributes($attributes) ); // Fin du wrapper $html .= '
'; // Retourne le html return $html; } /** * 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 = []) { // Attributs par défaut $attributes = array_merge([ 'before' => true, 'class' => '', // editorWysiwyg et editor possible pour utiliser un éditeur (il faut également instancier les librairies) 'classWrapper' => '', 'disabled' => false, 'noDirty' => false, 'help' => '', 'id' => $nameId, 'label' => '', //'maxlength' => '500', 'name' => $nameId, 'readonly' => false, 'value' => '' ], $attributes); // Sauvegarde des données en cas d'erreur if($attributes['before'] AND array_key_exists($attributes['id'], common::$inputBefore)) { $attributes['value'] = common::$inputBefore[$attributes['id']]; } // Début du wrapper $html = '
'; // Label if($attributes['label']) { $html .= self::label($attributes['id'], $attributes['label'], [ 'help' => $attributes['help'] ]); } // Notice $notice = ''; if(array_key_exists($attributes['id'], common::$inputNotices)) { $notice = common::$inputNotices[$attributes['id']]; $attributes['class'] .= ' notice'; } $html .= self::notice($attributes['id'], $notice); // Texte long $html .= sprintf( '', helper::sprintAttributes($attributes, ['value']), $attributes['value'] ); // Fin du wrapper $html .= '
'; // Retourne le html return $html; } }