153 lines
5.0 KiB
PHP
153 lines
5.0 KiB
PHP
<?php
|
|
/*
|
|
*Template Name: credit-step2
|
|
*
|
|
*/
|
|
/* ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL); */
|
|
|
|
use models\CRED_credit_step2;
|
|
|
|
$is_from_simulator = false;
|
|
$is_from_back = false;
|
|
|
|
if(isset($_GET['credit-direct-token']) && !empty($_GET['credit-direct-token'])) {
|
|
$is_from_back = true;
|
|
}
|
|
|
|
/* if (empty($_POST) && (!$is_from_back)) {
|
|
wp_redirect(home_url());
|
|
exit;
|
|
} */
|
|
|
|
if (file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect/app/models/credit_step2.php')) {
|
|
|
|
if(!class_exists('\models\CRED_credit')) {
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/app/models/credit.php');
|
|
}
|
|
|
|
if(!class_exists('\libraries\FormValidator')) {
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/app/libraries/FormValidator.php');
|
|
}
|
|
|
|
if(!class_exists('\libraries\TurnstileValidator')) {
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/app/libraries/TurnstileValidator.php');
|
|
}
|
|
|
|
if(!class_exists('\models\CRED_credit_step2')) {
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/app/models/credit_step2.php');
|
|
}
|
|
|
|
$model = new CRED_credit_step2();
|
|
|
|
$ongoing_credit = $model->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 '<pre>';
|
|
print_r($_COOKIE);
|
|
echo '</pre>'; */
|
|
|
|
|
|
//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(); |