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

632 lines
23 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class CRED_Main extends CRED_base {
public static $instance;
public function __construct()
{
self::$instance = $this;
}
/**
* Returns plugin absolute path
* @return string
*/
public function get_plugin_path()
{
return _CRED_ABSPATH_;
}
/**
* Returns full URL of an asset
* @param string $asset
* @return string
*/
public function asset($asset)
{
return self::URL('CRED') . 'assets/' . $asset;
}
/**
* return the path of the node modules
* @return string
*/
public function node_modules($module)
{
return self::URL('CRED') . 'node_modules/' . $module;
}
/**
* Returns full URL of a template
* @params string $template, string $domain, boolean $is_email
* @return string
*/
public static function template($template, $domain='admin', $is_email = false) {
$template_url = self::full_path().'templates/admin/'.$template;
if($domain !== 'admin')
$template_url = self::full_path().'templates/'.$domain.'/'.$template;
if($is_email)
$template_url = self::full_path().'templates/email/'.$template;
return $template_url;
}
/**
* return a template html
* @param url
* @return string
* */
public function renderTemplate($url, $vars = array(), $used_var_index = true) {
if(!empty($vars)) {
if($used_var_index) {
foreach ($vars as $key => $value) {
$$key = $value;
}
}
}
ob_start();
include $url;
return ob_get_clean();
}
/**
* Returns URL of WordPress items such as site, admin, plugins, ANA plugin etc.
* @param string $type
* @return string
*/
public static function URL($type = 'site')
{
// Make it lowercase
$type = strtolower($type);
$url = "";
// Frontend
if(in_array($type, array('frontend','site'))) $url = site_url().'/';
// Backend
elseif(in_array($type, array('backend','admin'))) $url = admin_url();
// WordPress Content directory URL
elseif($type === 'content') $url = content_url().'/';
// WordPress plugins directory URL
elseif($type === 'plugin') $url = plugins_url().'/';
// WordPress include directory URL
elseif($type === 'include') $url = includes_url();
// Webnus MEC plugin URL
elseif($type === 'cred')
{
// If plugin installed regularly on plugins directory
if(!defined('CRED_IN_THEME')) $url = plugins_url() .'/'._CRED_DIRNAME_.'/';
// If plugin embeded into one theme
else $url = get_template_directory_uri().'/plugins/'._CRED_DIRNAME_.'/';
}
return $url;
}
/**
* Returns absolute path of file
* @param string $type
* @return string
*/
public static function full_path() {
$path = WP_PLUGIN_DIR .'/'._CRED_DIRNAME_.'/';
return $path;
}
/**
* Return an acf option based on the field name
* @return string, object or array depending on the field type
* */
public static function get_acf_audit_option($field_name) {
if(empty($field_name) && !isset($field_name)) return false;
$field = get_field($field_name, 'option');
if(!$field)
return false;
return $field;
}
public static function get_groups_vars() {
$vars_groups = array(
'pret_personnel__tous_motifs__achats_divers' => self::get_acf_audit_option('pret_personnel__tous_motifs__achats_divers'),
'financement_frais_de_notaire' => self::get_acf_audit_option('financement_frais_de_notaire'),
'credit_travaux__renovation__energie' => self::get_acf_audit_option('credit_travaux__renovation__energie'),
'financement_vehicule_neuf' => self::get_acf_audit_option('financement_vehicule_neuf'),
'financement_vehicule_doccasion_moins_de_3_ans' => self::get_acf_audit_option('financement_vehicule_doccasion_moins_de_3_ans'),
'financement_vehicule_doccasion_plus_de_3_ans' => self::get_acf_audit_option('financement_vehicule_doccasion_plus_de_3_ans'),
'financement_mobilhome_et_caravane_de_moins_de_3_ans' => self::get_acf_audit_option('financement_mobilhome_et_caravane_de_moins_de_3_ans'),
'credit_hypothecaire_classique' => self::get_acf_audit_option('credit_hypothecaire_classique'),
'credit_hypothecaire_social' => self::get_acf_audit_option('credit_hypothecaire_social'),
'achat_maison_de_rapport' => self::get_acf_audit_option('achat_maison_de_rapport'),
'credit_pont' => self::get_acf_audit_option('credit_pont'),
'independants_et_entreprises_en_difficultes' => self::get_acf_audit_option('independants_et_entreprises_en_difficultes'),
'regroupement_de_credit__rachats_de_credits' => self::get_acf_audit_option('regroupement_de_credit__rachats_de_credits'),
'fonds_roulement_independants' => self::get_acf_audit_option('fonds_roulement_independants'),
);
return $vars_groups;
}
public static function create_db_tables() {
global $wpdb;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$charset_collate = $wpdb->get_charset_collate();
/**
* CREATE TABLE `$wpdb->dbname`.`cdf_Agences` (
`idAgences` INT NOT NULL AUTO_INCREMENT,
`Nom_agence` VARCHAR(45) NULL,
`description_agence` VARCHAR(255) NULL,
PRIMARY KEY (`idAgences`))
ENGINE = InnoDB;
CREATE TABLE `$wpdb->dbname`.`cdf_Emails` (
`idEmails` INT NOT NULL AUTO_INCREMENT,
`email` VARCHAR(45) NOT NULL,
PRIMARY KEY (`idEmails`))
ENGINE = InnoDB;
CREATE TABLE `$wpdb->dbname`.`cdf_Agences_emails` (
`FK_agence` INT NULL,
`FK_email` INT NULL,
`type_email` VARCHAR(45) NOT NULL,
CONSTRAINT `FK_agence`
FOREIGN KEY (`FK_agence`)
REFERENCES `cdf_Agences` (`idAgences`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_email`
FOREIGN KEY (`FK_email`)
REFERENCES `cdf_Emails` (`idEmails`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
*/
$sql = "
CREATE TABLE `$wpdb->dbname`.`cdf_Profession` (
`idprofession` INT NOT NULL AUTO_INCREMENT,
`nom_profession` VARCHAR(45) NULL,
PRIMARY KEY (`idprofession`))
ENGINE = InnoDB;
CREATE TABLE `$wpdb->dbname`.`cdf_Options_credit_auto` (
`idOptions_credit_auto` INT NOT NULL AUTO_INCREMENT,
`marque` VARCHAR(45) NULL,
`date_immatriculation` DATE NULL,
`nom_vendeur` VARCHAR(45) NULL,
`adresse_vendeur` VARCHAR(45) NULL,
`prix_vehicule` FLOAT NULL,
`montant_accompte` FLOAT NULL,
`montant_reprise` FLOAT NULL,
`montant_emprunt` FLOAT NULL,
`duree` INT NULL,
PRIMARY KEY (`idOptions_credit_auto`))
ENGINE = InnoDB;
CREATE TABLE `$wpdb->dbname`.`cdf_Options_credit_hypotecaire` (
`idOptions_credit_hypotecaire` INT NOT NULL AUTO_INCREMENT,
`type_credit` VARCHAR(45) NULL,
`prix_achat` FLOAT NULL,
`prix_construction_tvac` FLOAT NULL,
`frais_notaire_pays` FLOAT NULL,
`valeur_batiment` FLOAT NULL,
`fonds_propre` FLOAT NULL,
`compromis_signe` INT NULL,
`montant_revenu_cadastral` FLOAT NULL,
`montant_a_emprunter` FLOAT NULL,
`duree` INT NULL,
PRIMARY KEY (`idOptions_credit_hypotecaire`))
ENGINE = InnoDB;
CREATE TABLE `$wpdb->dbname`.`cdf_Credit` (
`idCredit` INT NOT NULL AUTO_INCREMENT,
`type_credit` VARCHAR(45) NULL,
`capital` VARCHAR(45) NULL,
`duree` VARCHAR(45) NULL,
`cout_total` VARCHAR(45) NULL,
`mensualite` VARCHAR(45) NULL,
`taux_nominal_annuel` VARCHAR(45) NULL,
`rgpd` VARCHAR(45) NULL,
`create_date` DATETIME NULL DEFAULT NULL,
`last_update_date` DATETIME NULL DEFAULT NULL,
`last_step` TINYINT NOT NULL DEFAULT '1',
`token` VARCHAR(45) NULL,
`FK_credit_auto` INT NULL,
`FK_credit_hypothecaire` INT NULL,
PRIMARY KEY (`idCredit`),
INDEX `FK_credit_auto_idx` (`FK_credit_auto` ASC),
INDEX `FK_credit_hypothecaire_idx` (`FK_credit_hypothecaire` ASC),
CONSTRAINT `FK_credit_auto`
FOREIGN KEY (`FK_credit_auto`)
REFERENCES `cdf_Options_credit_auto` (`idOptions_credit_auto`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_credit_hypothecaire`
FOREIGN KEY (`FK_credit_hypothecaire`)
REFERENCES `cdf_Options_credit_hypotecaire` (`idOptions_credit_hypotecaire`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
CREATE TABLE `$wpdb->dbname`.`cdf_Etat_civil` (
`idetat_civil` INT NOT NULL AUTO_INCREMENT,
`nom_etat_civil` VARCHAR(45) NULL,
PRIMARY KEY (`idetat_civil`))
ENGINE = InnoDB;
CREATE TABLE `$wpdb->dbname`.`cdf_Emprunteur` (
`idemprunteur` INT NOT NULL AUTO_INCREMENT,
`nom` VARCHAR(45) NULL,
`num_registre_national` VARCHAR(45) NULL,
`prenom` VARCHAR(45) NULL,
`telephone` VARCHAR(45) NULL,
`email` VARCHAR(45) NULL,
`date_naissance` DATE NULL,
`lieu_naissance` VARCHAR(45) NULL,
`nationalité` VARCHAR(45) NULL,
`num_carte_identite` VARCHAR(45) NULL,
`carte_identite_validite` DATE NULL,
`num_compte_bancaire` VARCHAR(45) NULL,
`adresse` VARCHAR(45) NULL,
`code_postal` INT NULL,
`localite` VARCHAR(45) NULL,
`pays` VARCHAR(45) NULL,
`date_emmenagement` DATE NULL,
`enfant_charge` INT NULL,
`contract_type` VARCHAR(45) NULL,
`nom_employeur` VARCHAR(45) NULL,
`numero_entreprise` VARCHAR(45) NULL,
`adresse_employeur` VARCHAR(45) NULL,
`code_postal_employeur` VARCHAR(45) NULL,
`localite_employeur` VARCHAR(45) NULL,
`pays_employeur` VARCHAR(45) NULL,
`date_engagement` DATE NULL,
`salaire` FLOAT NULL,
`cheque_repas` FLOAT NULL,
`revenus_locatifs` FLOAT NULL,
`chomage` FLOAT NULL,
`autre_revenu_montant` FLOAT NULL,
`autre_revenu_type` VARCHAR(45) NULL,
`parent_emprunteur` INT NULL,
`habitation_type` VARCHAR(45) NULL,
`habitation_loyer` FLOAT NULL,
`habitation_charge_hypothecaire` VARCHAR(45) NULL,
`habitation_sans_charge_locative` VARCHAR(45) NULL,
`remarques` TEXT NULL,
`FK_demande_creditdirect` INT NULL,
`FK_agence` INT NULL,
`FK_profession` INT NULL,
`FK_etat_civil` INT NULL,
PRIMARY KEY (`idemprunteur`),
INDEX `FK_profession_idx` (`FK_profession` ASC),
INDEX `FK_agences_idx` (`FK_agence` ASC),
INDEX `FK_demande_credit_idx` (`FK_demande_creditdirect` ASC),
INDEX `FK_etat_civil_idx` (`FK_etat_civil` ASC),
CONSTRAINT `FK_profession`
FOREIGN KEY (`FK_profession`)
REFERENCES `cdf_Profession` (`idprofession`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_agences`
FOREIGN KEY (`FK_agence`)
REFERENCES `cdf_Agences` (`idAgences`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_demande_credit`
FOREIGN KEY (`FK_demande_creditdirect`)
REFERENCES `cdf_Credit` (`idCredit`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_etat_civil`
FOREIGN KEY (`FK_etat_civil`)
REFERENCES `cdf_Etat_civil` (`idetat_civil`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
CREATE TABLE `$wpdb->dbname`.`cdf_Type_creance` (
`idtype_creance` INT NOT NULL AUTO_INCREMENT,
`nom_creance` VARCHAR(45) NULL,
PRIMARY KEY (`idtype_creance`))
ENGINE = InnoDB;
CREATE TABLE `$wpdb->dbname`.`cdf_Autre_credit` (
`idautrecredit` INT NOT NULL AUTO_INCREMENT,
`banque` VARCHAR(45) NULL,
`montant` FLOAT NULL,
`duree_credit` INT NULL,
`mensualite` INT NULL,
`date_premiere_echeance` DATE NULL,
`solde_restant_du` FLOAT NULL,
`cloture` INT NULL,
`solde` FLOAT NULL,
`FK_type_creance` INT NULL,
`FK_emprunteur` INT NULL,
PRIMARY KEY (`idautrecredit`),
INDEX `FK_type_creance_idx` (`FK_type_creance` ASC),
INDEX `FK_emprunteur_idx` (`FK_emprunteur` ASC),
CONSTRAINT `FK_type_creance`
FOREIGN KEY (`FK_type_creance`)
REFERENCES `cdf_Type_creance` (`idtype_creance`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FK_emprunteur`
FOREIGN KEY (`FK_emprunteur`)
REFERENCES `cdf_Emprunteur` (`idemprunteur`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
";
dbDelta( $sql );
/**
* Hydrate table Agence
*/
/* $result = $wpdb->get_results('SELECT * FROM cdf_Agences LIMIT 0,1');
if (empty($result)) {
dbDelta(
"INSERT INTO cdf_Agences (Nom_agence, description_agence) VALUES
(\"Verviers\", NULL),
(\"Mons\", NULL),
(\"Liège\", NULL),
(\"Arlon\", NULL);"
);
} */
/**
* Hydrate table Email
*/
/* $result = $wpdb->get_results('SELECT * FROM cdf_Emails LIMIT 0,1');
if (empty($result)) {
dbDelta(
"INSERT INTO cdf_Emails (email) VALUES
(\"pat@credit-direct.be\"),
(\"sylviane@credit-direct.be\"),
(\"annick@credit-direct.be\");"
);
} */
/**
* Hydrate table Email
*/
/* $result = $wpdb->get_results('SELECT * FROM cdf_Agences_emails LIMIT 0,1');
if (empty($result)) {
dbDelta(
"INSERT INTO cdf_Agences_emails (FK_agence, FK_email, type_email) VALUES
(1, 1, \"to\"),
(2, 2, \"to\"),
(2, 1, \"cc\"),
(2, 3, \"cc\"),
(3, 1, \"to\"),
(4, 1, \"to\");"
);
} */
/**
* Hydrate table Etat_civil
*/
$result = $wpdb->get_results('SELECT * FROM cdf_Etat_civil LIMIT 0,1');
if (empty($result)) {
dbDelta(
"INSERT INTO cdf_Etat_civil (nom_etat_civil) VALUES
(\"Célibataire\"),
(\"Divorcé(e)\"),
(\"Marié(e) avec contract de séparation de biens\"),
(\"Marié(e) sans contract de séparation de biens\"),
(\"Séparé(e)\"),
(\"Veuf(ve)\");"
);
}
/**
* Hydrate table Profession
*/
$result = $wpdb->get_results('SELECT * FROM cdf_Profession LIMIT 0,1');
if (empty($result)) {
dbDelta(
"INSERT INTO cdf_Profession (nom_profession) VALUES
(\"Chômeur\"),
(\"Employé\"),
(\"Enseignant\"),
(\"Fonctionnaire\"),
(\"Indépendant\"),
(\"Invalide\"),
(\"Militaire\"),
(\"Ouvrier\"),
(\"Pensionné\"),
(\"Policier\"),
(\"Prépensionné\"),
(\"Sans profession\");"
);
}
/**
* Hydrate table Profession
*/
$result = $wpdb->get_results('SELECT * FROM cdf_Type_creance LIMIT 0,1');
if (empty($result)) {
dbDelta(
"INSERT INTO cdf_Type_creance (nom_creance) VALUES
(\"Carte de crédit\"),
(\"Crédit ballon\"),
(\"Découvert bancaire\"),
(\"Financement véhicule\"),
(\"Leasing\"),
(\"Pension alimentaire à payer\"),
(\"Prêt à tempérament\"),
(\"Prêt hypothécaire\"),
(\"Réserve d'argent\");"
);
}
}
public static function create_uploadr_page() {
// Setup custom vars
$author_id = 1;
$total_step = 4;
for($i=1; $i<=$total_step; $i++){
$possibleCurrentPage = get_page_by_path('credit-step' . $i);
if (is_null($possibleCurrentPage)) {
$step = array(
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_author' => $author_id,
'post_name' => "credit-step" . $i,
'post_title' => "credit-step" . $i,
'post_status' => 'publish',
'post_type' => 'page',
'page_template' => 'credit-step' . $i
);
$post_id = wp_insert_post($step);
}
}
}
public static function start_session() {
if(!session_id()) {
session_start();
}
}
public static function CRED_page_template($page_template) {
if (!defined('WP_CREDIT_FORM_PATH')) {
define('WP_CREDIT_FORM_PATH', dirname(__FILE__));
}
if ( is_page( 'credit-step1' ) ) {
$page_template = _CRED_BASE_PATH_ . '/app/controllers/credit-step1.php';
}elseif (is_page( 'credit-step2' )) {
$page_template = _CRED_BASE_PATH_ . '/app/controllers/credit-step2.php';
}elseif (is_page( 'credit-step3' )) {
$page_template = _CRED_BASE_PATH_ . '/app/controllers/credit-step3.php';
}elseif (is_page( 'credit-step4' )) {
$page_template = _CRED_BASE_PATH_ . '/app/controllers/credit-step4.php';
}elseif (is_page( 'credit-step5' )) {
$page_template = _CRED_BASE_PATH_ . '/app/controllers/credit-step5.php';
}
return $page_template;
}
/**
*
*/
public static function cred_register_post_type($name, $label, $singular_label, $plural_label, $icon, $genre,$support=array()) {
$genre_labels = array(
array('f' => 'Toutes', 'm' => 'Tous'),
array('f' => 'Nouvelle', 'm' => 'Nouveau'),
array('f' => 'trouvée', 'm' => 'trouvé'),
array('f' => 'une', 'm' => 'un'),
);
if(empty($support)) {
$support = array(
'title',
);
}
register_post_type(
$name,
array(
'label' => $label,
'labels' => array(
'name' => $label,
'singular_name' => $singular_label,
'all_items' => $genre_labels[0][$genre].' les '.strtolower($plural_label),
'add_new_item' => 'Ajouter une '.strtolower($singular_label),
'edit_item' => 'Éditer '.$genre_labels[3][$genre].' '.strtolower($singular_label),
'new_item' => $genre_labels[1][$genre].' '.strtolower($singular_label),
'view_item' => 'Voir le '.strtolower($plural_label),
'search_items' => 'Rechercher parmi les '.strtolower($plural_label),
'not_found' => 'Pas de '.strtolower($plural_label).' trouvées',
'not_found_in_trash'=> 'Pas de '.strtolower($singular_label).' dans la corbeille',
),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => $icon,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
'supports' => $support,
'has_archive' => true
)
);
}
public static function cred_register_post_taxonomy($name,$post_type, $label, $singular_label, $plural_label, $icon, $genre, $link_to_post_type = true) {
$genre_labels = array(
array('f' => 'Toutes', 'm' => 'Tous'),
array('f' => 'Nouvelle', 'm' => 'Nouveau'),
array('f' => 'trouvée', 'm' => 'trouvé'),
array('f' => 'une', 'm' => 'un'),
array('f' => 'utilisée', 'm' => 'utilisé'),
);
register_taxonomy(
$name,
$post_type,
array(
'label' => $label,
'labels' => array(
'name' => $label,
'singular_name' => $singular_label,
'all_items' => strtolower($singular_label),
'edit_item' => 'Éditer un '.strtolower($singular_label),
'view_item' => 'Voir '.$genre_labels[3][$genre].' '.strtolower($singular_label),
'update_item' => 'Mettre à jour '.$genre_labels[3][$genre].' '.strtolower($singular_label),
'add_new_item' => 'Ajouter '.$genre_labels[3][$genre].' '.strtolower($singular_label),
'new_item_name' => $genre_labels[1][$genre].' '.strtolower($singular_label),
'search_items' => 'Rechercher parmi les '.strtolower($plural_label),
'popular_items' => $singular_label.' les plus '.$genre_labels[4][$genre]
),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'show_admin_column' => true,
'menu_position' => 5,
'menu_icon' => $icon,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
)
);
if($link_to_post_type) {
register_taxonomy_for_object_type( $name, $post_type );
}
}
}