credit-direct/app/controllers/credit-step4.php
2025-12-18 09:44:42 +01:00

90 lines
2.4 KiB
PHP

<?php
/*
*Template Name: credit-step4
*
*/
use models\CRED_credit_step4;
/* $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(!class_exists('\models\CRED_credit')) {
include(WP_PLUGIN_DIR . '/ESI_creditDirect/app/models/credit.php');
}
if(!class_exists('\models\CRED_credit_step4')) {
include(WP_PLUGIN_DIR . '/ESI_creditDirect/app/models/credit_step4.php');
}
$model = new CRED_credit_step4();
// 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);
}
if (file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect/app/models/credit_step4.php')) {
$currentCredit = $model->getCredit($token);
$type_credit_selected = '';
$coBorrower = $model->getCoBorrower($currentCredit);
$borrower = $model->getBorrower($currentCredit);
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 3 seulement si on vient du formulaire POST
if (!empty($_POST)) {
$model->save_step_3($post, $currentCredit);
}
//try to load the view
if (file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/front/credit-step4.php')) {
include(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/front/credit-step4.php');
}
} else {
// Si le crédit n'existe pas, rediriger vers la page d'accueil
wp_redirect(home_url());
exit;
}
}
get_footer();