'; print_r($token); echo ''; */ 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();