281 lines
9.1 KiB
PHP
281 lines
9.1 KiB
PHP
<?php
|
|
/*
|
|
*Template Name: credit-step1
|
|
*
|
|
*/
|
|
|
|
use models\CRED_credit_step1;
|
|
|
|
|
|
// Désactiver l'affichage des dépréciations pour cette page (tout en conservant la journalisation).
|
|
ini_set('display_errors', '0'); // Masque l'affichage à l'écran
|
|
ini_set('log_errors', '1'); // Journalise selon WP_DEBUG_LOG
|
|
// Conserver le niveau d'erreur courant mais ignorer les DEPRECATED pour éviter l'avertissement visuel
|
|
error_reporting((int) @ini_get('error_reporting') & ~E_DEPRECATED & ~E_USER_DEPRECATED);
|
|
|
|
$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;
|
|
}
|
|
|
|
|
|
if(!class_exists('\models\CRED_credit')) {
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/app/models/credit.php');
|
|
}
|
|
|
|
if(!class_exists('\models\CRED_credit_step1')) {
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/app/models/credit-step1.php');
|
|
}
|
|
|
|
// Garde-fous précoces pour éviter que KSES/stripslashes ne reçoivent null.
|
|
add_filter('pre_kses', function($content, $allowed_html, $allowed_protocols) {
|
|
return (string) ($content ?? '');
|
|
}, 1, 3);
|
|
add_filter('the_title', function($title) { return (string) ($title ?? ''); }, 1, 2);
|
|
add_filter('sanitize_title', function($title, $raw_title = '', $context = 'save') { return (string) (($title ?? $raw_title) ?? ''); }, 1, 3);
|
|
|
|
|
|
get_header();
|
|
|
|
/* $currentUser = wp_get_current_user();
|
|
$idUser = $currentUser->ID;
|
|
if($idUser == 1) {
|
|
echo '<pre>';
|
|
print_r($_GET);
|
|
echo '</pre>';
|
|
die();
|
|
} */
|
|
|
|
//try to load the model
|
|
$post = $_POST;
|
|
$one_step_form_send = false;
|
|
$one_step_credits = ['am','amr','cied','frais_notaire','cdp'];
|
|
|
|
|
|
|
|
$model = new CRED_credit_step1();
|
|
|
|
if(isset($_POST['one_step_form']))
|
|
$one_step_form_send = true;
|
|
|
|
//exemple credit : 8d0f45319ba2ebcfc708a7e6a19922c6a478b655
|
|
|
|
if(!$one_step_form_send && !isset($_GET['credit-direct-token'])) {
|
|
$token = $model->save_step_0($post);
|
|
} else if(isset($_POST['credit_token'])) {
|
|
$token = $_POST['credit_token'];
|
|
} else if(isset($_GET['credit-direct-token'])) {
|
|
$token = $_GET['credit-direct-token'];
|
|
} else {
|
|
wp_redirect(home_url());
|
|
}
|
|
|
|
|
|
$currentCredit = $model->getCredit($token);
|
|
|
|
$exemple_info = $model->get_exemples_infos($currentCredit->type_credit);
|
|
|
|
if(!empty($exemple_info)) {
|
|
$currentCredit->exemple_info = $exemple_info;
|
|
}
|
|
|
|
if (!is_object($currentCredit)) {
|
|
wp_redirect(home_url());
|
|
}
|
|
|
|
/* echo '<pre>';
|
|
print_r($_POST);
|
|
echo '</pre>'; */
|
|
/* die(); */
|
|
|
|
// Débogage
|
|
/* error_log('POST one_step_form: ' . (isset($_POST['one_step_form']) ? $_POST['one_step_form'] : 'non défini'));
|
|
error_log('one_step_credits: ' . print_r($one_step_credits, true)); */
|
|
|
|
if (file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect/app/models/credit-step1.php') || file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect/app/models/credit-one-step.php')) {
|
|
|
|
|
|
|
|
$in_one_step = false;
|
|
$civilStatus = $model->getCivilStatus();
|
|
$works = $model->getWorks();
|
|
$existingCreditTypes = $model->getExistingCreditTypes();
|
|
$contractTypes = $model->getContractTypes();
|
|
|
|
|
|
|
|
/* echo '<pre>';
|
|
print_r($currentCredit);
|
|
echo '</pre>'; */
|
|
|
|
if(in_array($currentCredit->type_credit, $one_step_credits))
|
|
$in_one_step = true;
|
|
|
|
|
|
if($one_step_form_send) {
|
|
$model->save_one_step($post);
|
|
|
|
/* echo '<pre>';
|
|
print_r($_FILES);
|
|
echo '</pre>'; */
|
|
}
|
|
|
|
//try to load the view
|
|
if (file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/front/credit-step1.php')) {
|
|
|
|
$agencies = $model->getAgencies();
|
|
$map_credit_type = $model->getCreditTypes();
|
|
$mapHouseCreditTypes = $model->getHouseCreditTypes();
|
|
/*re-hydrate current credit*/
|
|
$currentCredit = $model->getCredit($token);
|
|
$message = null;
|
|
|
|
$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];
|
|
|
|
//save the credit options labels in a cookie for 2 months
|
|
/* $model->save_step($currentCredit); */
|
|
|
|
$attachments = [];
|
|
$upload_errors = [];
|
|
/*
|
|
// Exemple d'utilisation de la fonction handleUploads
|
|
$allowed_types = [
|
|
'application/pdf',
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', // docx
|
|
'application/msword', // doc
|
|
'image/jpeg',
|
|
'image/png',
|
|
'image/gif',
|
|
'image/bmp',
|
|
'image/webp'
|
|
];
|
|
$max_size = 2 * 1024 * 1024; // 2 Mo
|
|
$result = $model->handleUploads($_FILES, $allowed_types, $max_size, $token);
|
|
$attachments = $result['files'];
|
|
$upload_errors = $result['errors'];
|
|
$html_links = $result['html_links'];
|
|
*/
|
|
if(isset($_FILES)) {
|
|
if ($one_step_form_send) { // 4 = no file uploaded
|
|
$allowed_types = [
|
|
'application/pdf',
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', // docx
|
|
'application/msword', // doc
|
|
'image/jpeg',
|
|
'image/png',
|
|
'image/gif',
|
|
'image/bmp',
|
|
'image/webp'
|
|
];
|
|
|
|
//remove all the empty file from $_FILE
|
|
foreach($_FILES as $key => $value) {
|
|
if($value['error'] === 4) {
|
|
unset($_FILES[$key]);
|
|
}
|
|
}
|
|
|
|
$max_size = 4 * 1024 * 1024; // 4 Mo
|
|
$result = $model->handleUploads($_FILES, $allowed_types, $max_size, $token);
|
|
|
|
/* echo '<pre>';
|
|
print_r($result);
|
|
echo '</pre>';
|
|
die(); */
|
|
|
|
$attachments = $result['files'];
|
|
$upload_errors = $result['errors'];
|
|
}
|
|
}
|
|
|
|
$borrower = $model->getBorrower($currentCredit);
|
|
|
|
/* echo '<pre>';
|
|
print_r($borrower);
|
|
echo '</pre>';
|
|
die(); */
|
|
|
|
if($one_step_form_send) {
|
|
if (file_exists(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/email/credit-one-step-mail.php')) {
|
|
$currentCredit = $model->getCredit($token);
|
|
|
|
$coBorrower = $model->getCoBorrower($currentCredit);
|
|
|
|
/* echo '<pre>';
|
|
print_r($currentCredit);
|
|
echo '</pre>';
|
|
|
|
echo '<pre>';
|
|
print_r($borrower);
|
|
echo '</pre>';
|
|
die(); */
|
|
|
|
ob_start();
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/email/credit-one-step-mail.php');
|
|
$message = ob_get_clean();
|
|
|
|
ob_start();
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/email/clients_emails/credit-one-step-mail-client.php');
|
|
$message_client = ob_get_clean();
|
|
|
|
// Ajout des en-têtes pour une meilleure compatibilité Outlook
|
|
/* $headers = array(
|
|
'Content-Type: text/html; charset=UTF-8',
|
|
'X-Mailer: PHP/' . phpversion(),
|
|
'MIME-Version: 1.0'
|
|
); */
|
|
|
|
/* echo '<pre>';
|
|
print_r($attachments);
|
|
echo '</pre>';
|
|
die(); */
|
|
|
|
// Envoi de l'email au client
|
|
$model->sendEmail('Demande de crédit', $message_client, $borrower, $currentCredit, [], true);
|
|
|
|
// Envoi de l'email à l'administrateur
|
|
$model->sendEmail('Demande de crédit', $message, $borrower, $currentCredit, [], false);
|
|
|
|
// Nettoyage des fichiers temporaires
|
|
/* foreach ($attachments as $file) {
|
|
if (file_exists($file)) @unlink($file);
|
|
} */
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/front/credit-step5.php');
|
|
}
|
|
if (!empty($upload_errors)) {
|
|
foreach ($upload_errors as $err) {
|
|
echo '<div class="alert alert-danger">' . htmlspecialchars((string) $err) . '</div>';
|
|
}
|
|
}
|
|
} else {
|
|
if($in_one_step) {
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/front/credit-one-step.php');
|
|
} else {
|
|
include(WP_PLUGIN_DIR . '/ESI_creditDirect/templates/front/credit-step1.php');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
get_footer(); |