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

380 lines
18 KiB
PHP

<?php
class CRED_simulateur extends CRED_base {
public static $instance;
public function __construct() {
self::$instance = $this;
/* add_action('wp_ajax_cred_regenerate_simulator', array($this, 'ajax_regenerate_simulator'));
add_action('wp_ajax_nopriv_cred_regenerate_simulator', array($this, 'ajax_regenerate_simulator')); */
}
public static function post_simulateur_form() {
}
public static function ajax_regenerate_simulator() {
error_log('POST data: ' . print_r($_POST, true));
if (!isset($_POST['nonce'])) {
wp_send_json_error(array('message' => 'Nonce manquant'));
return;
}
if (!wp_verify_nonce($_POST['nonce'], 'cd_47ax_412m')) {
wp_send_json_error(array('message' => 'Nonce invalide'));
return;
}
$type = isset($_POST['type']) ? $_POST['type'] : 'pat';
$atts = array(
'cd_default_loan_stimulator' => $type,
'check_credit_type' => ''
);
$content = self::simulateur_shortcode($atts);
wp_send_json_success(array(
'html' => $content
));
}
/* public static function generate_loan_stimulator_with_vc() {
vc_map( array(
"name" => __( "Generate Loan Stimulator", "cd-loan-stimulator" ),
"base" => "loan_simulator",
"class" => "",
"category" => __( "Credit Direct Custom Blocks", "cd-custom-blocks"),
"params" => array(
array(
"type" => "dropdown",
"holder" => "div",
"class" => "",
"heading" => __( "Default Stimulator", "cd-loan-stimulator" ),
"param_name" => "cd_default_loan_stimulator",
"value" => array(
__( "Prêt personnel / Tous motifs / Achats divers", "cd_loan_stimulator" ) => "pat",
__( "Financement frais de notaire ", "cd_loan_stimulator" ) => "frais_notaire",
__( "Crédit travaux / Rénovation / Energie", "cd_loan_stimulator" ) => "but_immo",
__( "Financement véhicule NEUF", "cd_loan_stimulator" ) => "fin_neuve",
__( "Financement véhicule d'occasion MOINS de 3 ans", "cd_loan_stimulator" ) => "fin_occ_m3a",
__( "Financement véhicule d'occasion PLUS de 3 ans", "cd_loan_stimulator" ) => "fin_occ_p3a",
__( "Crédit hypothécaire classique (achat maison, construction, refinancement, regroupement, travaux, achat à l'étranger)" ) => "am",
__( "Crédit hypothécaire social (achat maison, construction)", "cd_loan_stimulator" ) => "ph",
),
"description" => __( "", "cd-loan-stimulator" )
)
)
) );
} */
public static function simulateur_shortcode($atts) {
global $post;
$current_post_id = $post->ID;
$vars = shortcode_atts(
array(
'cd_default_loan_stimulator' => '',
'check_credit_type' => '',
), $atts );
$options = array(
array(
'value' => 'pat',
'heading' => 'Prêt personnel / Tous motifs / Achats divers',
'short_title' => 'Prêt personnel',
'page_slug' => 'pret-personnel',
'page_id' => 55
),
array(
'value' => 'financement_frais_de_notaire',
'heading' => 'Financement frais de notaire',
'short_title' => '',
'page_slug' => 'financement-frais-de-notaire',
'page_id' => 887
),
array(
'value' => 'but_immo',
'heading' => 'Crédit travaux / Rénovation / Energie',
'short_title' => 'Prêt travaux',
'page_slug' => 'credit-classique-achat-maison-travaux',
'page_id' => 30
),
array(
'value' => 'fin_neuve',
'heading' => 'Financement véhicule NEUF',
'short_title' => 'Crédit Auto',
'page_id' => 'achat-vehicule-auto-moto-caravane',
'page_slug' => 57
),
array(
'value' => 'fin_occ_m3a',
'heading' => 'Financement véhicule d\'occasion MOINS de 3 ans',
'short_title' => '',
'page_slug' => 'achat-vehicule-auto-moto-caravane',
'page_id' => 57
),
array(
'value' => 'fin_occ_p3a',
'heading' => 'Financement véhicule d\'occasion PLUS de 3 ans',
'short_title' => '',
'page_slug' => 'achat-vehicule-auto-moto-caravane',
'page_id' => 57
),
array(
'value' => 'am',
'heading' => 'Crédit hypothécaire classique (achat maison, construction, refinancement, regroupement, travaux, achat à l\'étranger)',
'short_title' => 'Crédit hypothécaire',
'page_slug' => 'credit-classique-achat-maison-travaux',
'page_id' => 30
)
);
$fin_neuve_sub_credits = [
'fin_neuve' => array('label' => 'Financement auto neuve', 'icon' => 'icon-toiturecar-neuve', 'page' => 'achat-vehicule-auto-moto-caravane','page_ids' => array(57),'checked' => 1, 'sub_class' => 'fin_neuve', 'hidden' => 1),
'fin_occ_m3a' => array('label' => 'Financement auto d\'occasion < 3 ans', 'icon' => 'icon-toiturecar-light', 'page' => 'achat-vehicule-auto-moto-caravane','page_ids' => array(57),'checked' => 0, 'sub_class' => 'fin_occ_m3a', 'hidden' => 0),
'fin_occ_p3a' => array('label' => 'Financement auto d\'occasion > 3 ans', 'icon' => 'icon-toiturecar-old', 'page' => 'achat-vehicule-auto-moto-caravane','page_ids' => array(57),'checked' => 0, 'sub_class' => 'fin_occ_p3a', 'hidden' => 0),
'mobil_carav' => array('label' => 'Mobil-home et caravane', 'icon' => 'icon-toiturecar-light', 'page' => 'achat-mobilhome-caravane','page_ids' => array(57),'checked' => 0, 'sub_class' => 'mobil_carav', 'hidden' => 0),
];
$travaux_sub_credits = [
'but_immo' => array('label' => 'Travaux de rénovation', 'icon' => 'icon-toituretravaux-renovation', 'page' => 'travaux-de-renovation','page_ids' => array(800),'checked' => 0),
'reno_energie' => array('label' => 'Rénovation énergétique', 'icon' => 'icon-toituretravaux-renovation', 'page' => 'renovation-energetique','page_ids' => array(800),'checked' => 0),
];
$creditTypes = [
'pat' => array('label' => 'Prêt personnel tous motifs', 'icon' => 'icon-toiturepret-tout-motif', 'page' => 'pret-personnel-tous-motifs', 'page_ids' => array(3187),'checked' => 1, 'insertAfter' => ''),
'regrouping' => array('label' => 'Regroupement de crédits', 'icon' => 'icon-toitureregroupement-credit', 'page' => 'regroupement-de-credits','page_ids' => array(55),'checked' => 0, 'insertAfter' => ''),
'fin_neuve' => array('label' => 'Financement auto', 'icon' => 'icon-toiturecar-neuve', 'page' => 'achat-vehicule-auto-moto-caravane','page_ids' => array(57),'checked' => 0, 'insertAfter' => ''),
'fin_occ_m3a' => array('label' => 'Financement auto d\'occasion < 3 ans', 'icon' => 'icon-toiturecar-light', 'page' => 'achat-vehicule-auto-moto-caravane','page_ids' => array(57),'checked' => 0, 'insertAfter' => ''),
'fin_occ_p3a' => array('label' => 'Financement auto d\'occasion > 3 ans', 'icon' => 'icon-toiturecar-old', 'page' => 'achat-vehicule-auto-moto-caravane','page_ids' => array(57),'checked' => 0, 'insertAfter' => ''),
'mobil_carav' => array('label' => 'Mobil-home et caravane', 'icon' => 'icon-toiturecar-light', 'page' => 'achat-mobilhome-caravane','page_ids' => array(57),'checked' => 0, 'insertAfter' => ''),
'but_immo' => array('label' => 'Crédits travaux, rénovation', 'icon' => 'icon-toituretravaux-renovation', 'page' => 'travaux-renovation','page_ids' => array(62),'checked' => 0, 'insertAfter' => ''),
'reno_energie' => array('label' => 'Rénovation énergétique', 'icon' => 'icon-toituretravaux-renovation', 'page' => 'renovation-energetique','page_ids' => array(800),'checked' => 0, 'insertAfter' => ''),
];
$houseCreditTypes = [
'purchasehouse' => array('label' => 'Achat maison', 'icon' => 'icon-toitureachat-maison', 'page' => 'achat-maison','page_ids' => array(30),'checked' => 1),
'construction' => array('label' => 'Nouvelle construction', 'icon' => 'icon-toiturenouvel-construction', 'page' => 'nouvelle-construction','page_ids' => array(33),'checked' => 0),
'regrouping_immo' => array('label' => 'Regroupement de crédits', 'icon' => 'icon-toitureregroupement-credit', 'page' => 'regroupement-de-credit-hypothecaire-et-autre','page_ids' => array(838),'checked' => 0),
'refinancing' => array('label' => 'Refinancement crédit(s) hypothécaire(s)', 'icon' => 'icon-toiturerefinancement', 'page' => 'refinancement-credit-hypothecaire','page_ids' => array(824),'checked' => 0),
'purchaseabroad' => array('label' => 'Achat d\'une 2éme résidence (à l\'étranger, en belgique)', 'icon' => 'icon-toituremaison-vacances', 'page' => 'achat-seconde-residence','page_ids' => array(870),'checked' => 0),
'but_immo_hypo' => array('label' => 'Travaux de rénovation', 'icon' => 'icon-toituretravaux-renovation', 'page' => 'travaux-de-renovation','page_ids' => array(800),'checked' => 0),
'achat_maison_de_rapport' => array('label' => 'Achat maison de rapport', 'icon' => 'icon-toitureachat-maison', 'page' => 'achat-maison-de-rapport','page_ids' => array(871),'checked' => 0),
'credit_pont' => array('label' => 'Crédit pont', 'icon' => 'icon-toiturerefinancement', 'page' => 'credit-pont','page_ids' => array(872),'checked' => 0),
'independants_et_entreprises_en_difficultes' => array('label' => 'Indépendants et entreprises en difficultés', 'icon' => 'icon-toitureagrandissement-maison', 'page' => 'credit-pont-travaux','page_ids' => array(873),'checked' => 0),
'regroupement_de_credit__rachats_de_credits' => array('label' => 'Rachats de crédits', 'icon' => 'icon-toitureregroupement-credit', 'page' => 'regroupement-de-credit-hypothecaire-et-autre','page_ids' => array(874),'checked' => 0),
'financement_frais_de_notaire' => array('label' => 'Financement frais de notaire', 'icon' => 'icon-toituregavel-light', 'page' => 'financement-frais-de-notaire','page_ids' => array(875),'checked' => 0),
'fonds_roulement_independants' => array('label' => 'Fonds de roulement pour indépendants', 'icon' => 'icon-toitureagrandissement-maison', 'page' => 'fonds-roulement-independants','page_ids' => array(876),'checked' => 0),
];
$select_options = '';
$select_buttons = '';
$select_radio = '';
$select_radio_orig = '';
$select_radio_immo = '';
$select_radio_pat = '';
$select_subradio_auto = '';
$select_subradio = '';
$after_select_tags = '';
$select_subradio_travaux = '';
$is_credit_hypothecaire = false;
$is_credit_pat = false;
$is_credit_auto = false;
$type_credit_grid_class = 'col-md-6';
$type_credit_auto_class = 'col-md-6';
$house_credit_grid_class = 'col-md-2';
$start_column_counter = 1;
$type_credit_length = count($creditTypes);
$house_credit_length = count($houseCreditTypes);
$insertAfter = '';
$check_credit_type = $vars['check_credit_type'];
$cd_default_loan_stimulator = ($vars['cd_default_loan_stimulator'] == "ph")?'am':$vars['cd_default_loan_stimulator'];
if($vars['cd_default_loan_stimulator'] == 'am')
$is_credit_hypothecaire = true;
if($vars['cd_default_loan_stimulator'] == 'fin_neuve')
$is_credit_auto = true;
if(empty($cd_default_loan_stimulator))
$cd_default_loan_stimulator = 'pat';
if($cd_default_loan_stimulator == 'pat')
$is_credit_pat = true;
/* foreach($options as $option){
$cd_default_loan_stimulator = ($vars['cd_default_loan_stimulator'] == "ph")?'am':$vars['cd_default_loan_stimulator'];
$selected = ($option['value'] == $cd_default_loan_stimulator)?'selected="selected" ':'';
$select_options .= '<option '.$selected.'value="'.$option['value'].'" data-heading="'.$option["heading"].'">'.$option['heading'].'</option>';
if(!empty($option['short_title'])) {
$checked = '';
if($option['value'] == $cd_default_loan_stimulator || (empty($cd_default_loan_stimulator) && $option['value'] == 'pat'))
$checked = ' checked ';
$url = get_permalink( $option['page_id'] );
$select_buttons .= '<li class="col-md-6"><a href="'.$url.'" data-heading="'.$option["heading"].'">'.$option['short_title'].'</a></li>';
ob_start();
?>
<div class="form_check col-md-6">
<input class="form-check-input loan_type" type="radio" name="loan_type" id="<?= $option['value'] ?>"
value="<?= $option['value'] ?>" <?= $checked ?>data-heading="<?= $option['heading'] ?>">
<label class="form-check-label" for="<?= $option['value'] ?>"><?= $option['short_title'] ?></label>
</div>
<?php
$select_radio_orig .= ob_get_clean();
}
} */
foreach($fin_neuve_sub_credits as $k => $v) {
$checked = '';
$typeCreditPages = $v['page_ids'];
ob_start();
?>
<div class="form_check test col-md-6 <?php echo $v['hidden'] ? 'hidden' : ''; ?> icon-check">
<input class="form-check-input <?= $v['sub_class'] ?>" type="radio" name="<?= $v['sub_class'] ?>" id="sub_<?= $k ?>"
value="<?= $k ?>" <?= $checked ?> data-page="<?= $v['page'] ?>">
<label class="form-check-label" for="sub_<?= $k ?>"><i class="glyphicon <?= $v['icon'] ?>" aria-hidden="true"></i>
<span class="label_text"><?= $v['label'] ?></span></label>
</div>
<?php
$select_subradio .= ob_get_clean();
}
foreach($creditTypes as $k => $v) {
$checked = '';
$typeCreditPages = $v['page_ids'];
$hasInsertAfter = !empty($v['insertAfter']) ? true : false;
if($hasInsertAfter) {
$insertAfter = $v['insertAfter'];
} else {
$insertAfter = '';
}
if($hasInsertAfter) {
if($start_column_counter % 2 != 0) {
$type_credit_grid_class = 'col-md-12';
}
ob_start();
?>
<div id="<?= $insertAfter['id'] ?>" class="form_group row sub_radio_sel<?= empty($insertAfter['class']) ? '' : ' '.$insertAfter['class'] ?>">
<?php
if (is_array($insertAfter['value'])) {
foreach($insertAfter['value'] as $key => $val) {
?>
<div class="form_check col-md-6 <?php echo $val['hidden'] ? 'hidden' : ''; ?> icon-check">
<input class="form-check-input sub_auto_loan_type" type="radio" name="sub_auto_loan_type" id="sub_<?= $key ?>"
value="<?= $key ?>" <?= $checked ?> data-page="<?= $val['page'] ?>">
<label class="form-check-label" for="sub_<?= $key ?>"><i class="glyphicon <?= $val['icon'] ?>"
aria-hidden="true"></i> <span class="label_text"><?= $val['label'] ?></span></label>
</div>
<?php
}
}
?>
</div>
<?php
$after_select_tags = ob_get_clean();
}
if(in_array($current_post_id, $typeCreditPages) || $v['checked'] == '1' || $check_credit_type == $k)
$checked = ' checked';
ob_start();
?>
<div class="form_check <?= $type_credit_grid_class ?> icon-check">
<input class="form-check-input sub_loan_type" type="radio" name="sub_loan_type" id="<?= $k ?>" value="<?= $k ?>"
<?= $checked ?> data-page="<?= $v['page'] ?>">
<label class="form-check-label" for="<?= $k ?>"><i class="glyphicon <?= $v['icon'] ?>" aria-hidden="true"></i> <span
class="label_text"><?= $v['label'] ?></span></label>
</div>
<?php
if($hasInsertAfter)
echo $after_select_tags;
$select_radio_pat .= ob_get_clean();
$start_column_counter++;
}
foreach($houseCreditTypes as $k => $v) {
$checked = '';
$typeCreditPages = $v['page_ids'];
$type_credit_grid_class = 'col-md-6';
if(in_array($current_post_id, $typeCreditPages) || $v['checked'] == '1' || $check_credit_type == $k)
$checked = ' checked';
ob_start();
?>
<div class="form_check <?= $type_credit_grid_class ?> icon-check">
<input class="form-check-input sub_loan_type" type="radio" name="sub_loan_type" id="<?= $k ?>" value="<?= $k ?>"
<?= $checked ?> data-page="<?= $v['page'] ?>">
<label class="form-check-label" for="<?= $k ?>"><i class="glyphicon <?= $v['icon'] ?>" aria-hidden="true"></i> <span
class="label_text"><?= $v['label'] ?></span></label>
</div>
<?php
$select_radio_immo .= ob_get_clean();
}
if($is_credit_hypothecaire)
$select_radio = $select_radio_immo;
else
$select_radio = $select_radio_pat;
$template_url = CRED_Main::template('newSim.php','front');
if(isset($_GET['debug']))
$template_url = CRED_Main::template('simulateur.php','front');
ob_start();
include $template_url;
$content = ob_get_clean();
return $content;
}
}