128 lines
4.0 KiB
PHP
128 lines
4.0 KiB
PHP
<?php
|
|
/*
|
|
*Template Name: credit-step5
|
|
*
|
|
*/
|
|
|
|
use models\CRED_credit_step5;
|
|
|
|
/* $is_from_simulator = false;
|
|
$is_from_back = false;
|
|
|
|
if(isset($_GET['credit-direct-token']) && !empty($_GET['credit-direct-token'])) {
|
|
$is_from_back = true;
|
|
}
|
|
|
|
if(isset($_POST['loan_type']) && !empty($_POST['loan_type'])) {
|
|
$is_from_simulator = true;
|
|
}
|
|
|
|
if (empty($_POST) && (!$is_from_simulator || !$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);
|
|
|
|
/* echo '<pre>';
|
|
print_r($token);
|
|
echo '</pre>'; */
|
|
|
|
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_step5.php')) {
|
|
|
|
if(!class_exists('\models\CRED_credit')) {
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/app/models/credit.php');
|
|
}
|
|
|
|
if(!class_exists('\models\CRED_credit_step5')) {
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/app/models/credit_step5.php');
|
|
}
|
|
|
|
$model = new CRED_credit_step5();
|
|
|
|
$currentCredit = $model->getCredit($token);
|
|
|
|
|
|
if (is_object($currentCredit)) {
|
|
// Sauvegarder l'étape 4 seulement si on vient du formulaire POST
|
|
|
|
|
|
if (!empty($_POST)) {
|
|
$model->save_step_4($post, $currentCredit);
|
|
}
|
|
|
|
$borrower = $model->getBorrower($currentCredit);
|
|
$coBorrower = $model->getCoBorrower($currentCredit);
|
|
$agencies = $model->getAgencies();
|
|
$civilStatus = $model->getCivilStatus();
|
|
$works = $model->getWorks();
|
|
$existingCreditTypes = $model->getExistingCreditTypes();
|
|
$map_credit_type = $model->getCreditTypes();
|
|
$contractTypes = $model->getContractTypes();
|
|
$mapHouseCreditTypes = $model->getHouseCreditTypes();
|
|
|
|
$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'];
|
|
|
|
|
|
$creditOptionsLabels = !empty($type_credit_selected) ? $model->getCreditLabel($type_credit_selected) : $map_credit_type[$currentCredit->type_credit];
|
|
|
|
$message = null;
|
|
|
|
|
|
if (file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/email/credit-step4-mail.php')) {
|
|
ob_start();
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/email/credit-step4-mail.php');
|
|
$message = ob_get_clean();
|
|
|
|
ob_start();
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/email/clients_emails/credit-step4-mail-client.php');
|
|
$message_client = ob_get_clean();
|
|
|
|
|
|
// Ajout des en-têtes pour une meilleure compatibilité Outlook
|
|
|
|
// Exception : ne pas envoyer de mail si l'utilisateur connecté a l'ID 1
|
|
if (!is_user_logged_in() || get_current_user_id() != 1) {
|
|
$model->sendEmail('Demande de crédit', $message, $borrower, $currentCredit, [], false);
|
|
$model->sendEmail('Demande de crédit', $message_client, $borrower, $currentCredit, [], true);
|
|
}
|
|
}
|
|
|
|
//try to load the view
|
|
if (file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/front/credit-step5.php')) {
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/front/credit-step5.php');
|
|
}
|
|
|
|
/* if (!is_null($message)) {
|
|
echo $message;
|
|
} */
|
|
} else {
|
|
// Si le crédit n'existe pas, rediriger vers la page d'accueil
|
|
wp_redirect(home_url());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
get_footer();
|