checkOngoingCreditRequest(); if(!$ongoing_credit && empty($_POST) && !$is_from_back) { wp_redirect(home_url()); exit; } // Vérifier le token soit en POST soit en GET $token = isset($_POST['credit-direct-token']) ? $_POST['credit-direct-token'] : (isset($_GET['credit-direct-token']) ? $_GET['credit-direct-token'] : null); if(null === $token) { $token = $model->get_ongoing_credit_token(); } if (empty($token)) { wp_redirect(home_url()); exit; } get_header(); //try to load the model $post = $_POST; if (empty($post)) { $post = array('credit-direct-token' => $token); } $currentCredit = $model->getCredit($token); $borrower = $model->getBorrower($currentCredit); $coBorrower = $model->getCoBorrower($currentCredit); $hasCoBorrower = $model->hasCoBorrower($currentCredit); $is_credit_auto = $model->is_credit_auto($currentCredit); $type_credit_selected = ''; if(isset($currentCredit->sel_credit) && !empty($currentCredit->sel_credit)) { $type_credit_selected = $currentCredit->sel_credit; } if(isset($_POST['type_credit_selected']) && !empty($_POST['type_credit_selected']) || isset($_POST['sub_loan_type']) && !empty($_POST['sub_loan_type'])) $type_credit_selected = isset($_POST['sub_loan_type']) ? $_POST['sub_loan_type'] : $_POST['type_credit_selected']; if(empty($type_credit_selected)) { $type_credit_selected = $currentCredit->type_credit; } if (is_object($currentCredit)) { // Sauvegarder l'étape 1 seulement si on vient du formulaire POST if (!empty($_POST)) { // Validation Turnstile si configuré if (\libraries\TurnstileValidator::isConfigured()) { $turnstileToken = isset($_POST['cf-turnstile-response']) ? $_POST['cf-turnstile-response'] : ''; $turnstileValidator = new \libraries\TurnstileValidator(); $turnstileResult = $turnstileValidator->validateForDisplay($turnstileToken, $_SERVER['REMOTE_ADDR'] ?? null); if (!$turnstileResult['valid']) { $turnstile_error = $turnstileResult['message']; } } // Ne traiter le formulaire que si Turnstile est valide (ou non configuré) if (!isset($turnstile_error)) { $result = $model->save_step_1($post); // Vérifier s'il y a des erreurs de validation if (is_array($result) && isset($result['success']) && !$result['success']) { $validation_errors = $result['formatted_errors']; } else { $model->save_step($currentCredit); } } } $contractTypes = $model->getContractTypes(); $mapHouseCreditTypes = $model->getHouseCreditTypes(); // Utilisation du mode debug pour charger les templates $template_a = CRED::getTemplatePath('/templates/front/credit-step2-a.php'); $template_b = CRED::getTemplatePath('/templates/front/credit-step2-b.php'); $template_c = CRED::getTemplatePath('/templates/front/credit-step2-c.php'); /* echo '
';
print_r($_COOKIE);
echo ''; */
//try to load the view
if (file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect' . $template_a)) {
include(WP_PLUGIN_DIR . '/ESI_creditDirect' . $template_a);
}
if (file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect' . $template_b)) {
include(WP_PLUGIN_DIR . '/ESI_creditDirect' . $template_b);
}
if (file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect' . $template_c)) {
include(WP_PLUGIN_DIR . '/ESI_creditDirect' . $template_c);
}
} else {
// Si le crédit n'existe pas, rediriger vers la page d'accueil
wp_redirect(home_url());
exit;
}
}
get_footer();