$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 captcha
* @param string $nameId Nom et id du champ
* @param array $attributes Attributs ($key => $value)
* @return string
*/
public static function captcha($nameId, array $attributes = []) {
// Attributs par défaut
$attributes = array_merge([
'class' => '',
'classWrapper' => '',
'help' => '',
'id' => $nameId,
'name' => $nameId,
'value' => '',
'limit' => false
], $attributes);
// Génère deux nombres
$numbers = array(0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20);
$letters = array('u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a');
$limit = $attributes['limit'] ? count($letters)-1 : 10;
mt_srand((float) microtime()*1000000);
$firstNumber = mt_rand (1, $limit);
mt_srand((float) microtime()*1000000);
$secondNumber = mt_rand (1, $limit);
// Choisit l'opération
mt_srand((float) microtime()*1000000);
$operator = mt_rand (0, 3);
switch ($operator) {
case 0:
$operator = '+';
if ($firstNumber < $secondNumber) {
$temp = $firstNumber;
$firstNumber = $secondNumber;
$secondNumber = $temp;
// [$firstNumber, $secondNumber] = [$secondNumber, $firstNumber]; // ---> A partir de PHP 7.1
}
$result = $firstNumber + $secondNumber;
$operator = template::ico('plus');
break;
case 1:
$operator = '-';
if ($firstNumber < $secondNumber) {
$temp = $firstNumber;
$firstNumber = $secondNumber;
$secondNumber = $temp;
// [$firstNumber, $secondNumber] = [$secondNumber, $firstNumber]; // ---> A partir de PHP 7.1
}
$result = $firstNumber - $secondNumber;
$operator = template::ico('minus');
break;
case 2:
$operator = 'x';
mt_srand((float) microtime()*1000000);
$firstNumber = mt_rand (1, 10);
mt_srand((float) microtime()*1000000);
$secondNumber = mt_rand (1, 10);
$result = $firstNumber * $secondNumber;
$operator = template::ico('cancel');
break;
case 3:
$operator = ':';
mt_srand((float) microtime()*1000000);
$firstNumber = mt_rand (1, 10);
mt_srand((float) microtime()*1000000);
if ($firstNumber < 3) {
$secondNumber = mt_rand(1, 10);
}
elseif ($firstNumber = 3) {
$secondNumber = mt_rand(1, 6);
}
elseif ($firstNumber = 4) {
$secondNumber = mt_rand(1, 5);
}
elseif ($firstNumber = 5) {
$secondNumber = mt_rand(1, 4);
}
elseif ($firstNumber = 6 ) {
$secondNumber = mt_rand(1, 3);
}
elseif ($firstNumber > 6) {
$secondNumber = mt_rand(1, 2);
}
$firstNumber = $firstNumber * $secondNumber;
$result = $firstNumber / $secondNumber;
$operator = template::ico('divide');
break;
}
$result = password_hash($result, PASSWORD_BCRYPT);
$firstLetter = uniqid();
$secondLetter = uniqid();
// Masquage image source
copy ('core/vendor/zwiico/png/'.$letters[$firstNumber] . '.png', 'site/tmp/' . $firstLetter . '.png');
copy ('core/vendor/zwiico/png/'.$letters[$secondNumber] . '.png', 'site/tmp/' . $secondLetter . '.png');
// Début du wrapper
$html = '
';
// Label
$html .= self::label($attributes['id'],
'
' . $operator . ' en chiffres ?', [
'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);
// captcha
$html .= sprintf(
'
',
helper::sprintAttributes($attributes)
);
// Champ résultat caché
$html .= self::hidden($attributes['id'] . 'Result', [
'value' => $result,
'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 = '';
// 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 = '