17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// in_table:compta_categories,id
\KD2\Form::registerValidationRule('in_table', function ($name, $params, $value) {
$db = DB::getInstance();
return $db->test($params[0], $db->where($params[1], $value));
});
}
public function run(callable $fn, ?string $csrf_key = null): bool
{
if (!$this->check($csrf_key)) {
return false;
}
try {
call_user_func($fn);
return true;
}
catch (UserException $e) {
$this->addError($e->getMessage());
return false;
}
}
public function runIf($condition, callable $fn, ?string $csrf_key = null): ?bool
{
if (is_string($condition) && empty($_POST[$condition])) {
return null;
}
elseif (is_bool($condition) && !$condition) {
return null;
}
return $this->run($fn, $csrf_key);
}
public function check($token_action = '', Array $rules = null)
{
if (!\KD2\Form::tokenCheck($token_action))
{
$this->errors[] = 'Une erreur est survenue, merci de bien vouloir renvoyer le formulaire.';
|
|
>
>
>
>
>
|
|
|
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// in_table:compta_categories,id
\KD2\Form::registerValidationRule('in_table', function ($name, $params, $value) {
$db = DB::getInstance();
return $db->test($params[0], $db->where($params[1], $value));
});
}
public function run(callable $fn, ?string $csrf_key = null, ?string $redirect = null): bool
{
if (!$this->check($csrf_key)) {
return false;
}
try {
call_user_func($fn);
if (null !== $redirect) {
Utils::redirect(ADMIN_URL . $redirect);
}
return true;
}
catch (UserException $e) {
$this->addError($e->getMessage());
return false;
}
}
public function runIf($condition, callable $fn, ?string $csrf_key = null, ?string $redirect = null): ?bool
{
if (is_string($condition) && empty($_POST[$condition])) {
return null;
}
elseif (is_bool($condition) && !$condition) {
return null;
}
return $this->run($fn, $csrf_key, $redirect);
}
public function check($token_action = '', Array $rules = null)
{
if (!\KD2\Form::tokenCheck($token_action))
{
$this->errors[] = 'Une erreur est survenue, merci de bien vouloir renvoyer le formulaire.';
|