From cea781a711caac5d96ff33c1e15a6414f4a41443 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 27 Sep 2022 16:21:55 +0200 Subject: [PATCH] FIX CSRF + lost value of constant after use save button --- htdocs/admin/ticket_public.php | 67 +++++++++++++++++----------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/htdocs/admin/ticket_public.php b/htdocs/admin/ticket_public.php index a0df28a8f84..622a8aaf927 100644 --- a/htdocs/admin/ticket_public.php +++ b/htdocs/admin/ticket_public.php @@ -150,44 +150,45 @@ if ($action == 'setTICKET_ENABLE_PUBLIC_INTERFACE') { $error++; $errors[] = $db->lasterror(); } +} elseif (preg_match('/set_(.*)/', $action, $reg)) { + $code = $reg[1]; + $value = GETPOSTISSET($code) ? GETPOST($code, 'int') : 1; - if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { + if ($code == 'TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS' && $conf->global->MAIN_FEATURES_LEVEL >= 2) { $param_notification_also_main_addressemail = GETPOST('TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS', 'alpha'); $res = dolibarr_set_const($db, 'TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS', $param_notification_also_main_addressemail, 'chaine', 0, '', $conf->entity); if (!($res > 0)) { $error++; $errors[] = $db->lasterror(); } - } -} elseif (preg_match('/set_(.*)/', $action, $reg)) { - $code = $reg[1]; - $value = GETPOSTISSET($code) ? GETPOST($code, 'int') : 1; - $res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity); - if (!($res > 0)) { - $error++; - $errors[] = $db->lasterror(); - } + } else { + $res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity); + if (!($res > 0)) { + $error++; + $errors[] = $db->lasterror(); + } - if (!$error) { - if ($code == 'TICKET_EMAIL_MUST_EXISTS') { - $res = dolibarr_del_const($db, 'TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST', $conf->entity); - if (!($res > 0)) { - $error++; - $errors[] = $db->lasterror(); - } - } elseif ($code == 'TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST') { - $res = dolibarr_del_const($db, 'TICKET_EMAIL_MUST_EXISTS', $conf->entity); - if (!($res > 0)) { - $error++; - $errors[] = $db->lasterror(); - } + if (!$error) { + if ($code == 'TICKET_EMAIL_MUST_EXISTS') { + $res = dolibarr_del_const($db, 'TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST', $conf->entity); + if (!($res > 0)) { + $error++; + $errors[] = $db->lasterror(); + } + } elseif ($code == 'TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST') { + $res = dolibarr_del_const($db, 'TICKET_EMAIL_MUST_EXISTS', $conf->entity); + if (!($res > 0)) { + $error++; + $errors[] = $db->lasterror(); + } - // enable captcha by default - // TODO Add a visible option in this setup page for this - $res = dolibarr_set_const($db, 'MAIN_SECURITY_ENABLECAPTCHA_TICKET', 1, 'chaine', 0, '', $conf->entity); - if (!($res > 0)) { - $error++; - $errors[] = $db->lasterror(); + // enable captcha by default + // TODO Add a visible option in this setup page for this + $res = dolibarr_set_const($db, 'MAIN_SECURITY_ENABLECAPTCHA_TICKET', 1, 'chaine', 0, '', $conf->entity); + if (!($res > 0)) { + $error++; + $errors[] = $db->lasterror(); + } } } } @@ -276,9 +277,9 @@ if (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE)) { print ''.$langs->trans("TicketsEmailMustExist").''; print ''; if (empty(getDolGlobalInt('TICKET_EMAIL_MUST_EXISTS'))) { - print '' . img_picto($langs->trans('Disabled'), 'switch_off') . ''; + print '' . img_picto($langs->trans('Disabled'), 'switch_off') . ''; } else { - print '' . img_picto($langs->trans('Enabled'), 'switch_on') . ''; + print '' . img_picto($langs->trans('Enabled'), 'switch_on') . ''; } print ''; print ''; @@ -290,9 +291,9 @@ if (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE)) { print ''.$langs->trans("TicketCreateThirdPartyWithContactIfNotExist").''; print ''; if (empty(getDolGlobalInt('TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST'))) { - print '' . img_picto($langs->trans('Disabled'), 'switch_off') . ''; + print '' . img_picto($langs->trans('Disabled'), 'switch_off') . ''; } else { - print '' . img_picto($langs->trans('Enabled'), 'switch_on') . ''; + print '' . img_picto($langs->trans('Enabled'), 'switch_on') . ''; } print ''; print '';