Merge branch '10400' into data_engine

This commit is contained in:
Fred Tempez 2020-10-31 17:40:57 +01:00
commit 2f27ca0235

View File

@ -50,43 +50,49 @@ class template {
'limit' => false 'limit' => false
], $attributes); ], $attributes);
// Tirage de l'opération et des nombres // Captcha quatre opérations
// Correspondance tableau des images // Limite addition et soustraction selon le type de captcha
$numbers = array(0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20); $numbers = [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'); $letters = ['u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a'];
// Détermination de la limitation
$limit = $attributes['limit'] ? count($letters)-1 : 10; $limit = $attributes['limit'] ? count($letters)-1 : 10;
mt_srand((float) microtime()*1000000);
$operator = mt_rand (0, 3);
// Limiter les valuers si pas une addition // Tirage de l'opération
if ($operator > 1) $limit = 10; mt_srand((float) microtime()*1000000);
$operator = mt_rand (1, 4);
// Limite si multiplication ou division
if ($operator > 2) {
$limit = 10;
}
// Tirage des nombres
mt_srand((float) microtime()*1000000);
$firstNumber = mt_rand (1, $limit); $firstNumber = mt_rand (1, $limit);
mt_srand((float) microtime()*1000000);
$secondNumber = mt_rand (1, $limit); $secondNumber = mt_rand (1, $limit);
// Ordre des valeurs selon type d'opération // Permutation si addition ou soustraction
if (($operator < 2) AND ($firstNumber < $secondNumber)) { if (($operator < 3) and ($firstNumber < $secondNumber)) {
$temp = $firstNumber; $temp = $firstNumber;
$firstNumber = $secondNumber; $firstNumber = $secondNumber;
$secondNumber = $temp; $secondNumber = $temp;
} }
// Calcul du résultat et icône de l'opérateur // Icône de l'opérateur et calcul du résultat
switch ($operator) { switch ($operator) {
case 0: case 1:
$operator = template::ico('plus'); $operator = template::ico('plus');
$result = $firstNumber + $secondNumber; $result = $firstNumber + $secondNumber;
break; break;
case 1: case 2:
$operator = template::ico('minus'); $operator = template::ico('minus');
$result = $firstNumber - $secondNumber; $result = $firstNumber - $secondNumber;
break; break;
case 2: case 3:
$operator = template::ico('cancel'); $operator = template::ico('cancel');
$result = $firstNumber * $secondNumber; $result = $firstNumber * $secondNumber;
break; break;
case 3: case 4:
$operator = template::ico('divide'); $operator = template::ico('divide');
$limit2 = [10, 10, 6, 5, 4, 3, 2, 2, 2, 2]; $limit2 = [10, 10, 6, 5, 4, 3, 2, 2, 2, 2];
for ($i = 1; $i <= $firstNumber; $i++) { for ($i = 1; $i <= $firstNumber; $i++) {