522 lines
19 KiB
PHP
522 lines
19 KiB
PHP
<?php
|
|
|
|
class CRED_factory extends CRED_base {
|
|
|
|
public static $instance;
|
|
public $main;
|
|
public $forms;
|
|
public $simulateur;
|
|
public $creditReminder;
|
|
public $creditManager;
|
|
public $societesCreditManager;
|
|
public $creditMailchimp;
|
|
public $creditSendy;
|
|
|
|
public function __construct() {
|
|
self::$instance = $this;
|
|
|
|
if($this->main === null)
|
|
$this->main = $this->getMain();
|
|
|
|
if($this->forms === null)
|
|
$this->forms = $this->getForms();
|
|
|
|
if($this->simulateur === null)
|
|
$this->simulateur = $this->getSimulateur();
|
|
|
|
if($this->creditReminder === null)
|
|
$this->creditReminder = $this->getCreditReminder();
|
|
|
|
if($this->creditManager === null)
|
|
$this->creditManager = $this->getCreditManager();
|
|
|
|
if($this->societesCreditManager === null)
|
|
$this->societesCreditManager = $this->getSocietesCreditManager();
|
|
|
|
if($this->creditMailchimp === null)
|
|
$this->creditMailchimp = $this->getCreditMailchimp();
|
|
|
|
if($this->creditSendy === null)
|
|
$this->creditSendy = $this->getCreditSendy();
|
|
}
|
|
|
|
public function load_actions() {
|
|
$this->action('template_redirect', array($this, 'load_frontend_assets'));
|
|
|
|
$this->action('init', array($this, 'init_hook'));
|
|
|
|
$this->action('init', array($this, 'load_shortcodes'));
|
|
|
|
$this->action('wp_ajax_ajax_regenerate_simulator', array($this->simulateur, 'ajax_regenerate_simulator'));
|
|
$this->action('wp_ajax_nopriv_ajax_regenerate_simulator', array($this->simulateur, 'ajax_regenerate_simulator'));
|
|
|
|
// Hook pour le menu d'administration du Credit Manager
|
|
$this->action('admin_menu', array($this, 'register_admin_menu'));
|
|
|
|
// Hook pour enregistrer les réglages Mailchimp (Settings API)
|
|
$this->action('admin_init', array($this->creditMailchimp, 'register_settings'));
|
|
|
|
// Hook pour enregistrer les réglages Sendy (Settings API)
|
|
$this->action('admin_init', array($this->creditSendy, 'register_settings'));
|
|
|
|
// Hook pour charger les assets du Credit Manager et Societes Credit Manager
|
|
$this->action('admin_enqueue_scripts', array($this, 'enqueue_credit_manager_assets'));
|
|
$this->action('admin_enqueue_scripts', array($this, 'enqueue_societes_credit_assets'));
|
|
// Hook pour charger les assets de la page Mailchimp (admin)
|
|
$this->action('admin_enqueue_scripts', array($this, 'enqueue_mailchimp_assets'));
|
|
// Hook pour charger les assets de la page Sendy (admin)
|
|
$this->action('admin_enqueue_scripts', array($this, 'enqueue_sendy_assets'));
|
|
|
|
// Hooks AJAX pour le Credit Manager
|
|
$this->action('wp_ajax_credit_manager_create', array($this->creditManager, 'ajax_create_credit'));
|
|
$this->action('wp_ajax_credit_manager_get', array($this->creditManager, 'ajax_get_credit'));
|
|
$this->action('wp_ajax_credit_manager_update', array($this->creditManager, 'ajax_update_credit'));
|
|
$this->action('wp_ajax_credit_manager_delete', array($this->creditManager, 'ajax_delete_credit'));
|
|
$this->action('wp_ajax_credit_manager_list', array($this->creditManager, 'ajax_list_credits'));
|
|
$this->action('wp_ajax_credit_manager_get_filter_options', array($this->creditManager, 'ajax_get_filter_options'));
|
|
$this->action('wp_ajax_credit_manager_change_status', array($this->creditManager, 'ajax_change_credit_status'));
|
|
$this->action('wp_ajax_credit_manager_update_status', array($this->creditManager, 'ajax_update_credit_status'));
|
|
|
|
// Hooks AJAX pour le Societes Credit Manager
|
|
$this->action('wp_ajax_societes_credit_create', array($this->societesCreditManager, 'ajax_create_societe'));
|
|
$this->action('wp_ajax_societes_credit_get', array($this->societesCreditManager, 'ajax_get_societe'));
|
|
$this->action('wp_ajax_societes_credit_update', array($this->societesCreditManager, 'ajax_update_societe'));
|
|
$this->action('wp_ajax_societes_credit_delete', array($this->societesCreditManager, 'ajax_delete_societe'));
|
|
$this->action('wp_ajax_societes_credit_list', array($this->societesCreditManager, 'ajax_list_societes'));
|
|
|
|
// Hook AJAX pour tester la connexion Mailchimp
|
|
$this->action('wp_ajax_cred_mailchimp_ping', array($this->creditMailchimp, 'ajax_ping'));
|
|
|
|
// Hook AJAX pour tester la connexion Sendy
|
|
$this->action('wp_ajax_cred_sendy_ping', array($this->creditSendy, 'ajax_ping'));
|
|
}
|
|
|
|
public function load_filters() {
|
|
$this->filter('page_template',array($this->main,'CRED_page_template'));
|
|
}
|
|
|
|
public function load_shortcodes() {
|
|
|
|
$this->shortcode('loan_simulator', array($this->simulateur,'simulateur_shortcode'));
|
|
|
|
}
|
|
|
|
public function action($hook, $function, $priority = 10, $accepted_args = 1) {
|
|
// Check Parameters
|
|
if(!trim($hook) or !$function) return false;
|
|
|
|
// Add it to WordPress actions
|
|
return add_action($hook, $function, $priority, $accepted_args);
|
|
}
|
|
|
|
public function filter($tag, $function, $priority = 10, $accepted_args = 1) {
|
|
// Check Parameters
|
|
if(!trim($tag) or !$function) return false;
|
|
|
|
// Add it to WordPress filters
|
|
return add_filter($tag, $function, $priority, $accepted_args);
|
|
}
|
|
|
|
public function load_frontend_assets() {
|
|
|
|
global $wpdb;
|
|
global $post;
|
|
|
|
if (null === $post)
|
|
return;
|
|
|
|
$includes_page = ['credit-step1', 'credit-step2', 'credit-step3', 'credit-step4', 'credit-step5', 'simulateur', 'simulateur-pret', 'accueil', 'page-daccueil', 'simulateur-pret-hypothecaire', 'pret-a-temperament-pret-personnel'];
|
|
//includes posts
|
|
$included_posts = ['simulation-pret-hypothecaire'];
|
|
$ids_parents = [495,497,824,5359];
|
|
$allooded_children = false;
|
|
|
|
if(null != $post && $post->post_pareent > 0) {
|
|
if(in_array($post->post_parent, $ids_parents)) {
|
|
$allooded_children = true;
|
|
}
|
|
}
|
|
|
|
$independent = $wpdb->get_results('SELECT * FROM cdf_Profession WHERE nom_profession IN ("Indépendant")');
|
|
|
|
//if page parent is not in the array, return
|
|
/* if(!in_array($post->post_parent, $ids_parents)) return; */
|
|
|
|
$noEmployer = [];
|
|
$info_pat = self::$instance->main->get_acf_audit_option('infos_pat_statut_maries_sans_separation_ds_biens');
|
|
$noEmployerQuery = $wpdb->get_results(
|
|
'SELECT * FROM cdf_Profession WHERE nom_profession IN (
|
|
"Chômeur",
|
|
"Invalide",
|
|
"Pensionné",
|
|
"Prépensionné",
|
|
"Sans profession"
|
|
)'
|
|
);
|
|
|
|
foreach ($noEmployerQuery as $a) {
|
|
$noEmployer[] = intval($a->idprofession);
|
|
}
|
|
|
|
// Include css files
|
|
|
|
//if(is page parent in the array, include css files)
|
|
|
|
|
|
if(!is_admin()) {
|
|
|
|
|
|
}
|
|
|
|
|
|
if(is_page($includes_page) || in_array($post->post_parent, $ids_parents) || is_single($included_posts)) {
|
|
|
|
wp_enqueue_style( 'bootstrap', $this->main->asset('css/bootstrap.min.css'), array(), '4.6.2' );
|
|
wp_enqueue_style('cd-frontend-style', $this->main->asset('css/cd_main.css'));
|
|
wp_enqueue_style('izimodal', $this->main->asset('css/iziModal.min.css'));
|
|
|
|
|
|
/* wp_enqueue_script("bootstrap", $this->main->asset("/js/libraries/bootstrap.bundle.min.js"),array('jquery'),false,true);*/
|
|
wp_enqueue_script("bootstrap-form", $this->main->asset("/js/libraries/jquery.bootstrap.wizard.min.js"),array('jquery'),false,true);
|
|
wp_enqueue_script("izimodal", $this->main->asset("/js/libraries/iziModal.min.js"),array('jquery'),false,true);
|
|
wp_enqueue_script("inputmask", $this->main->asset("/js/libraries/jquery.inputmask.min.js"),array('jquery'),false,true);
|
|
|
|
//include custom scripts
|
|
/* wp_enqueue_script("cred_custom_js", $this->main->asset('js/cred_js.php'),array('jquery'),false,true); */
|
|
//includes libraries scripts
|
|
|
|
wp_enqueue_script( 'jquery-ui-slider' );
|
|
wp_enqueue_script("validate", $this->main->asset("/js/libraries/jquery.validate.min.js"),array('jquery'),false,true);
|
|
wp_enqueue_script("additional-methods", $this->main->asset("/js/libraries/additional-methods.min.js"),array('jquery'),false,true);
|
|
|
|
wp_enqueue_script( 'jquery-ui-accordion' );
|
|
wp_enqueue_script("jquery_repeater", $this->main->asset("/js/libraries/jquery.repeater.min.js"),array('jquery'),false,true);
|
|
|
|
//include main script
|
|
wp_enqueue_script("cred_main_js", $this->main->asset('js/cd_main.js'),array('jquery'),'1.0.1',true);
|
|
wp_enqueue_script("cred_form_js", $this->main->asset('js/form_main.js'),array('jquery'),'1.0.0',true);
|
|
|
|
// Cloudflare Turnstile script
|
|
/* if (\libraries\TurnstileValidator::isConfigured()) {
|
|
wp_enqueue_script("cloudflare-turnstile", "https://challenges.cloudflare.com/turnstile/v0/api.js", array(), null, true);
|
|
} */
|
|
|
|
|
|
wp_localize_script( 'cred_main_js', 'cd_js',
|
|
array(
|
|
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
|
'groups' => CRED_Main::get_groups_vars(),
|
|
'site_url' => site_url(),
|
|
'nonce' => wp_create_nonce( "cd_47ax_412m" ),
|
|
'independent' => intval($independent[0]->idprofession),
|
|
'noEmployer' => $noEmployer,
|
|
'info_pat' => $info_pat
|
|
)
|
|
);
|
|
|
|
// Enregistrement du script du simulateur
|
|
wp_enqueue_script('cd-simulator', $this->main->asset('js/cd_simulator.js'), array('jquery'), '1.0.0', true);
|
|
|
|
// Localisation du script
|
|
wp_localize_script('cd-simulator', 'cred_simulator', array(
|
|
'ajax_url' => admin_url('admin-ajax.php'),
|
|
'nonce' => wp_create_nonce('cred_simulator_nonce')
|
|
));
|
|
|
|
// Charger les assets pour la gestion des bâtiments (credit-one-step)
|
|
if(is_page('credit-step1')) {
|
|
wp_enqueue_style('cd-buildings-style', $this->main->asset('css/buildings.css'), array(), '1.0.0');
|
|
wp_enqueue_script('cd-buildings-manager', $this->main->asset('js/buildings-manager.js'), array('jquery'), '1.0.0', true);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function load_backend_assets() {
|
|
|
|
if(is_admin()) {
|
|
wp_dequeue_style('bootstrap');
|
|
|
|
wp_dequeue_script('bootstrap');
|
|
wp_dequeue_script('bootstrap');
|
|
wp_dequeue_script('validate');
|
|
wp_dequeue_script('additional-methods');
|
|
wp_dequeue_script('bootstrap-form');
|
|
wp_dequeue_script('jquery_repeater');
|
|
wp_dequeue_script('cred_main_js');
|
|
wp_dequeue_script('cred_form_js');
|
|
|
|
// Enqueue des assets du credit manager pour l'administration
|
|
$this->action('admin_enqueue_scripts', array($this, 'enqueue_credit_manager_assets'));
|
|
$this->action('admin_enqueue_scripts', array($this, 'enqueue_societes_credit_assets'));
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* Enqueue des assets du credit manager - limité à la page credit-manager
|
|
*/
|
|
public function enqueue_credit_manager_assets($hook) {
|
|
// Charger seulement sur la page credit-manager (hook ou via le paramètre page)
|
|
$should_enqueue = ($hook === 'toplevel_page_credit-manager');
|
|
if (!$should_enqueue && isset($_GET['page']) && $_GET['page'] === 'credit-manager') {
|
|
$should_enqueue = true;
|
|
}
|
|
if (!$should_enqueue) {
|
|
return;
|
|
}
|
|
|
|
// Font Awesome 7 (Kit personnel)
|
|
wp_enqueue_style(
|
|
'font-awesome-kit',
|
|
'https://kit.fontawesome.com/a029b5a0f4.css',
|
|
array(),
|
|
'7.0.0'
|
|
);
|
|
|
|
// Enqueue des assets communs (DataTables + CSS personnalisé)
|
|
$this->enqueue_common_credit_admin_assets();
|
|
|
|
// DataTables Buttons CSS
|
|
wp_enqueue_style(
|
|
'datatables-buttons-css',
|
|
'https://cdn.datatables.net/buttons/2.4.2/css/buttons.dataTables.min.css',
|
|
array('datatables-css'),
|
|
'2.4.2'
|
|
);
|
|
|
|
// JSZip (requis pour Excel)
|
|
wp_enqueue_script(
|
|
'jszip',
|
|
'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js',
|
|
array(),
|
|
'3.10.1',
|
|
true
|
|
);
|
|
|
|
// DataTables Buttons
|
|
wp_enqueue_script(
|
|
'datatables-buttons',
|
|
'https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js',
|
|
array('datatables-js'),
|
|
'2.4.2',
|
|
true
|
|
);
|
|
|
|
// Buttons HTML5 export
|
|
wp_enqueue_script(
|
|
'datatables-buttons-html5',
|
|
'https://cdn.datatables.net/buttons/2.4.2/js/buttons.html5.min.js',
|
|
array('datatables-buttons', 'jszip'),
|
|
'2.4.2',
|
|
true
|
|
);
|
|
|
|
// JavaScript personnalisé
|
|
wp_enqueue_script(
|
|
'credit-manager-js',
|
|
$this->main->asset('js/credit-manager.js'),
|
|
array('datatables-js', 'datatables-buttons', 'datatables-buttons-html5', 'select2-js'),
|
|
'1.0.0',
|
|
true
|
|
);
|
|
|
|
// Localiser les variables JavaScript
|
|
wp_localize_script('credit-manager-js', 'creditManagerAjax', array(
|
|
'ajaxurl' => admin_url('admin-ajax.php'),
|
|
'nonce' => wp_create_nonce('credit_manager_action')
|
|
));
|
|
}
|
|
|
|
public function enqueue_mailchimp_assets($hook) {
|
|
$should_enqueue = ($hook === 'credit-manager_page_credit-mailchimp');
|
|
if (!$should_enqueue && isset($_GET['page']) && $_GET['page'] === 'credit-mailchimp') {
|
|
$should_enqueue = true;
|
|
}
|
|
if (!$should_enqueue) {
|
|
return;
|
|
}
|
|
|
|
// Charger uniquement le JS commun sans DataTables ni CSS lourds
|
|
wp_enqueue_script(
|
|
'credit-manager-js',
|
|
$this->main->asset('js/credit-manager.js'),
|
|
array('jquery', 'select2-js'),
|
|
'1.0.0',
|
|
true
|
|
);
|
|
|
|
// Localiser uniquement ce qui est nécessaire pour le test Mailchimp
|
|
wp_localize_script('credit-manager-js', 'creditManagerAjax', array(
|
|
'ajaxurl' => admin_url('admin-ajax.php'),
|
|
'mailchimpPingNonce' => wp_create_nonce('cred_mailchimp_ping')
|
|
));
|
|
}
|
|
|
|
public function enqueue_sendy_assets($hook) {
|
|
$should_enqueue = ($hook === 'credit-manager_page_credit-sendy');
|
|
if (!$should_enqueue && isset($_GET['page']) && $_GET['page'] === 'credit-sendy') {
|
|
$should_enqueue = true;
|
|
}
|
|
if (!$should_enqueue) {
|
|
return;
|
|
}
|
|
|
|
// Charger uniquement le JS commun sans DataTables ni CSS lourds
|
|
wp_enqueue_script(
|
|
'credit-manager-js',
|
|
$this->main->asset('js/credit-manager.js'),
|
|
array('jquery', 'select2-js'),
|
|
'1.0.0',
|
|
true
|
|
);
|
|
|
|
// Localiser uniquement ce qui est nécessaire pour le test Sendy
|
|
wp_localize_script('credit-manager-js', 'creditManagerAjax', array(
|
|
'ajaxurl' => admin_url('admin-ajax.php'),
|
|
'sendyPingNonce' => wp_create_nonce('cred_sendy_ping')
|
|
));
|
|
}
|
|
|
|
public function shortcode($shortcode, $function) {
|
|
// Check Parameters
|
|
if(!trim($shortcode) or !$function) return false;
|
|
|
|
// Add it to WordPress shortcodes
|
|
return add_shortcode($shortcode, $function);
|
|
}
|
|
|
|
public function init_hook() {
|
|
|
|
//create table
|
|
/* CRED_Main::create_db_tables(); */
|
|
|
|
/* CRED_Main::create_uploadr_page();
|
|
|
|
CRED_Main::start_session(); */
|
|
|
|
//register post type
|
|
CRED_Main::cred_register_post_type('agences','Agence Physique','Agence','Agences','dashicons-building','f');
|
|
|
|
//register agence taxonomy
|
|
CRED_Main::cred_register_post_taxonomy('agences_email','agences','Emails agence','Email','Emails','','m');
|
|
|
|
//load shortcode
|
|
$this->load_shortcodes();
|
|
|
|
//load frontend styles and scripts
|
|
/* $this->load_frontend_assets(); */
|
|
|
|
//load backend styles and scripts
|
|
$this->load_backend_assets();
|
|
}
|
|
|
|
/**
|
|
* Enregistrer le menu d'administration du Credit Manager
|
|
*/
|
|
public function register_admin_menu() {
|
|
$creditManager = $this->creditManager;
|
|
if ($creditManager) {
|
|
$creditManager->add_admin_menu();
|
|
}
|
|
|
|
$societesCreditManager = $this->societesCreditManager;
|
|
if ($societesCreditManager) {
|
|
$societesCreditManager->add_admin_menu();
|
|
}
|
|
|
|
$creditMailchimp = $this->creditMailchimp;
|
|
if ($creditMailchimp) {
|
|
$creditMailchimp->add_admin_menu();
|
|
}
|
|
|
|
$creditSendy = $this->creditSendy;
|
|
if ($creditSendy) {
|
|
$creditSendy->add_admin_menu();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Enqueue des assets du societes credit manager - limité à la page societes-credit-manager
|
|
*/
|
|
public function enqueue_societes_credit_assets($hook) {
|
|
// Charger seulement sur la page societes-credit-manager (sous-menu de credit-manager)
|
|
$should_enqueue = ($hook === 'credit-manager_page_societes-credit-manager');
|
|
if (!$should_enqueue && isset($_GET['page']) && $_GET['page'] === 'societes-credit-manager') {
|
|
$should_enqueue = true;
|
|
}
|
|
if (!$should_enqueue) {
|
|
return;
|
|
}
|
|
|
|
// Enqueue des assets communs (DataTables + CSS personnalisé)
|
|
$this->enqueue_common_credit_admin_assets();
|
|
|
|
// Script spécifique à la page Sociétés de Crédit
|
|
wp_enqueue_script(
|
|
'societes-credit-manager-js',
|
|
$this->main->asset('js/societes-credit-manager.js'),
|
|
array('datatables-js', 'select2-js'),
|
|
'1.0.0',
|
|
true
|
|
);
|
|
|
|
// Variables JS pour AJAX (nonce aligné avec les contrôleurs)
|
|
wp_localize_script('societes-credit-manager-js', 'societesCreditAjax', array(
|
|
'ajaxurl' => admin_url('admin-ajax.php'),
|
|
'nonce' => wp_create_nonce('societes_credit_action')
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Enqueue des assets communs aux pages d'administration liées au Credit Manager
|
|
* - DataTables CSS/JS
|
|
* - CSS commun du Credit Manager
|
|
*/
|
|
private function enqueue_common_credit_admin_assets() {
|
|
// Select2 CSS (CDN)
|
|
wp_enqueue_style(
|
|
'select2-css',
|
|
'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css',
|
|
array(),
|
|
'4.1.0-rc.0'
|
|
);
|
|
|
|
// Select2 JS (CDN)
|
|
wp_enqueue_script(
|
|
'select2-js',
|
|
'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js',
|
|
array('jquery'),
|
|
'4.1.0-rc.0',
|
|
true
|
|
);
|
|
|
|
// DataTables CSS
|
|
wp_enqueue_style(
|
|
'datatables-css',
|
|
$this->main->node_modules('datatables.net-dt/css/dataTables.dataTables.min.css'),
|
|
array(),
|
|
'1.13.7'
|
|
);
|
|
|
|
// DataTables JS
|
|
wp_enqueue_script(
|
|
'datatables-js',
|
|
$this->main->node_modules('datatables.net/js/dataTables.min.js'),
|
|
array('jquery'),
|
|
'1.13.7',
|
|
true
|
|
);
|
|
|
|
// CSS commun du Credit Manager
|
|
wp_enqueue_style(
|
|
'credit-manager-css',
|
|
$this->main->asset('css/credit-manager.css'),
|
|
array('datatables-css'),
|
|
'1.0.0'
|
|
);
|
|
}
|
|
|
|
} |