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) && !$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); if (!is_object($currentCredit)) { wp_redirect(home_url()); } /* echo '
';
print_r($_POST);
echo '
'; */ /* 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 '
';
    print_r($currentCredit);
    echo '
'; */ if(in_array($currentCredit->type_credit, $one_step_credits)) $in_one_step = true; if($one_step_form_send) { $model->save_one_step($post); /* echo '
';
        print_r($_FILES);
        echo '
'; */ } //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 '
';
                print_r($result);
                echo '
'; die(); */ $attachments = $result['files']; $upload_errors = $result['errors']; } } $borrower = $model->getBorrower($currentCredit); /* echo '
';
        print_r($borrower);
        echo '
'; 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 '
';
                print_r($currentCredit);
                echo '
'; echo '
';
                print_r($borrower);
                echo '
'; 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 '
';
                print_r($attachments);
                echo '
'; die(); */ // Exception : ne pas envoyer de mail si l'utilisateur connecté a l'ID 1 if (!is_user_logged_in() || get_current_user_id() != 1) { // 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 '
' . htmlspecialchars($err) . '
'; } } } 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();