Files
2024_WEBSITE_fipf/plugins/cipf_plugin/cipf_plugin.php

365 lines
17 KiB
PHP

<?php
/*
Plugin Name: hggg_cipf
Plugin URI:
Description:
Author: hugogogo
Version: 0.5.11.2
Author URI:
*/
/*
* it means someone outside wp is accessing the file, in this case kill it.
*/
if (!defined('ABSPATH')) {
die('You can not access this file!');
}
include_once( plugin_dir_path(__FILE__) . '/plgntls_class.php');
/*
* general inclusions
// utils :
*/
include_once(Plgntls::root_path() . 'php/utils/globals.php');
include_once(Plgntls::root_path() . 'php/utils/console_log.php');
// paypal
include_once(Plgntls::root_path() . 'php/paypal/paypal.php');
// profs
include_once(Plgntls::root_path() . 'php/profs_profil.php');
include_once(Plgntls::root_path() . 'php/profs_form_commande.php');
include_once(Plgntls::root_path() . 'php/profs_handle_states.php');
// partners
include_once(Plgntls::root_path() . 'php/partners_register.php');
include_once(Plgntls::root_path() . 'php/partners_page.php');
include_once(Plgntls::root_path() . 'php/partners_form.php');
include_once(Plgntls::root_path() . 'php/partners_handle_offers.php');
// utils
include_once(Plgntls::root_path() . 'php/_utils_acf_fields.php');
include_once(Plgntls::root_path() . 'php/_utils_acf_dates.php');
include_once(Plgntls::root_path() . 'php/_utils_acf_disabled.php');
include_once(Plgntls::root_path() . 'php/_utils_redirections.php');
include_once(Plgntls::root_path() . 'php/_utils_display_css.php');
include_once(Plgntls::root_path() . 'php/_utils_checks_roles.php');
// actions
include_once(Plgntls::root_path() . 'php/_actions_payments.php');
include_once(Plgntls::root_path() . 'php/_actions_random_posts.php');
include_once(Plgntls::root_path() . 'php/_actions_scheduled_events.php');
include_once(Plgntls::root_path() . 'php/_actions_emails.php');
// admin
include_once(Plgntls::root_path() . 'php/admin_hide_bar.php');
include_once(Plgntls::root_path() . 'php/admin_user_profil.php');
include_once(Plgntls::root_path() . 'php/admin_partner.php');
include_once(Plgntls::root_path() . 'php/admin_menu.php');
/*
*
*
*/
class Cipf {
/*
* const declarations
*
*/
// ACF
const ACF_CARD_STATE = ['_name'=>'etat_carte', 'new'=>'Commande', 'renew'=>'Renouvellement']; // radio button
const ACF_CARD_PAYMENT_METHOD = ['_name'=>'paiement', 'paypal'=>'Paypal', 'transfert'=>'Virement']; // radio button
const ACF_CARD_PRICE_CHOICE = ['_name'=>'tarif', 'low'=>'10', 'high'=>'15']; // radio button
const ACF_CARD_PRICE_DELIVERY = ['_name'=>'livraison', 'pdf'=>'0', 'post'=>'5']; // radio button
const ACF_PROF_IS_ACTIV = ['_name'=>'compte-actif', 'activ'=>'Actif', 'inactiv'=>'Inactif']; // radio button
const ACF_PROF_CGV = ['_name'=>'cgv', 'cgv'=>'cgv']; // checkbox
const ACF_CARD_PRICE_TOTAL = ['_name'=>'somme_a_regler']; // number
const ACF_CARD_NUMBER = ['_name'=>'numero_de_la_carte']; // number
const ACF_CARD_EXPIRATION = ['_name'=>'fin_de_validite']; // date picker
const ACF_CARD_PAYMENT_STATE = ['_name'=>'etat_paiement', 'started'=>'en_cours', 'success'=>'reussi', 'failure'=>'echec', 'nothing'=>'aucun']; // radio button
const ACF_ACCOUNT_STATE = ['_name'=>'etat_compte', 'new'=>'nouveau prof', 'to_pay'=>'doit payer', 'valid'=>'carte valide', 'waiting_invalid'=>'en attente invalide', 'waiting_valid'=>'en attente valide', 'expired'=>'carte expiree'];
const ACF_TRANSFERT_STATE = ['_name'=>'etat_virement', 'success'=>'virement validé'];
const ACF_CARD_ORDER_ID = ['_name'=>'order_id'];
const ACF_HISTORY = ['_name'=>'historique'];
const ACF_PROF_CHANGE_CARD = ['_name'=>'changement_de_carte'];
const ACF_PAGE_STATE = ['_name'=>'etat_page_partenaire', 'publish'=>'Publiee', 'draft'=>'Brouillon'];
const ACF_EMAILS_REMINDERS = ['_name'=>'rappels_emails'];
const ACF_PARTNER_DATE_OFFER_1 = ['_name'=>'fin_offre_1'];
const ACF_PARTNER_DATE_OFFER_2 = ['_name'=>'fin_offre_2'];
const ACF_PARTNER_DATE_OFFER_3 = ['_name'=>'fin_offre_3'];
const ACF_PARTNER_OFFER_1_DURATION = ['_name'=>'duree_offre_1', 'endless'=>'Permanente', 'tmp'=>'Temporaire'];
const ACF_PARTNER_OFFER_2_DURATION = ['_name'=>'duree_offre_2', 'endless'=>'Permanente', 'tmp'=>'Temporaire'];
const ACF_PARTNER_OFFER_3_DURATION = ['_name'=>'duree_offre_3', 'endless'=>'Permanente', 'tmp'=>'Temporaire'];
const ACF_PARTNER_OFFER_1_OUTPUT = ['_name'=>'afficher_offre_1', 'show'=>'Afficher', 'hide'=>'Masquer'];
const ACF_PARTNER_OFFER_2_OUTPUT = ['_name'=>'afficher_offre_2', 'show'=>'Afficher', 'hide'=>'Masquer'];
const ACF_PARTNER_OFFER_3_OUTPUT = ['_name'=>'afficher_offre_3', 'show'=>'Afficher', 'hide'=>'Masquer'];
const ACF_READONLY_CLASS = 'readonly_acf';
const ACF_DATE_FORMAT = 'Ymd';
// META
const META_PAYEMENT_STATUS = 'cipf_payement_status';
const META_ORDER_ID = 'cipf_order_id';
// SLUG
const SLUG_PROF_INACTIV = 'validation-en-cours';
const SLUG_COMMAND_CARD = 'commande';
const SLUG_PAGE_REDIRECTION = 'redirection_cipf';
const SLUG_PAYPAL_PAGE = 'paiement';
const SLUG_PAYPAL_REDIRECTION_SUCCESS = self::SLUG_PAGE_REDIRECTION;
const SLUG_PAYPAL_REDIRECTION_FAILURE = self::SLUG_PAGE_REDIRECTION;
const SLUG_ADMIN_VALIDATE_PROF = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
const SLUG_PARTNER_REGISTRATION = 'compte-partenaire';
const SLUG_PARTNER_CREATE_PAGE = 'ma-page-partenaire';
// URL
const URL_BASE_REST_ROUTE = 'cipf_plugin/api/v1'; // for routes, in php/paypal/routes.php && php/admin_modif_prof.php
// QUERY
const QUERY_TOGGLE_PARTNER_PAGE = 'toggle_partner_page_cipf';
// PAYPAL
const PAYPAL_SBOX_API_BASE_URL = "https://api-m.sandbox.paypal.com";
const PAYPAL_LIVE_API_BASE_URL = "https://api-m.paypal.com";
const PAYPAL_HUGO_SBOX_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
const PAYPAL_HUGO_SBOX_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-";
const PAYPAL_HUGO_LIVE_CLIENT_ID = "Aedn5e8z__hPBvKirqw5bwlhI9ChG8_N6c1xbgybYyBr4B4oP8uVzmVdH1QVKdPQKf6bWg7orPV4PDrO";
const PAYPAL_HUGO_LIVE_CLIENT_SECRET = "EGeGwfHGxHxsjnC-tH8W0IL4nN3_xlc3sXFRPCQOw5uUoWae3eOgghuDKMnZc5DVGTbP6yIjVJ1BaAra";
const PAYPAL_DIEGO_SBOX_CLIENT_ID = "AegZZ6vDrTBzUNGf-UOVoUwh51YU4cvjGGPQkOQ7gM3H2xij9Pdkf751WO1ZvLoFjqbeNN-M5F6WqrdL";
const PAYPAL_DIEGO_SBOX_CLIENT_SECRET = "ENH2n-trvWrs4B6IWdhl7NM_Wp-Rpyo5ONJJMjJFevGVJ2wtSdORPXFx-vPZ2RQGV0RUQzAp6qt4_qVn";
const PAYPAL_DIEGO_LIVE_CLIENT_ID = "Abp6y2Outx8bMsEQRXBjH7qYK7-sTHmCMWlmJcw0Ctl5c9XpNsbGt5Vl1tD1ZmFhuBGGjT8ec3FKoLCo";
const PAYPAL_DIEGO_LIVE_CLIENT_SECRET = "EFLFOATSMM1m9BZwfj209qAeYDrsH-ltcFnVBmyPAJM-KjQiMtUVDQNPeyikDO1Y41yMiKu_IoELp_vD";
//const PAYPAL_CLIENT_ID = self::PAYPAL_HUGO_LIVE_CLIENT_ID;
//const PAYPAL_CLIENT_SECRET = self::PAYPAL_HUGO_LIVE_CLIENT_SECRET;
//const PAYPAL_API_BASE_URL = self::PAYPAL_HUGO_LIVE_API_BASE_URL;
const PAYPAL_MESSAGE_SUCCESS = 'Paiement réussi, vous allez être redirigé-es vers votre espace';
const PAYPAL_MESSAGE_PROBLEM = "Paiement réussi, mais une erreure est survenue dans le traitement de la commande, si vous voyez que votre compte n'est pas mis à jour correctement, contactez la fipf directement";
const PAYPAL_MESSAGE_FAILURE = 'Paiement raté, vous allez être redirigé-es vers votre espace';
// ROLES
const ROLE_PROF = 'professeur__professeure';
const ROLE_PARTNER = 'partenaire';
const ROLE_FIPF = 'fipf';
const ROLE_ADMIN = 'administrator';
// SHORTCODES
// OPTIONS
const OPTION_PAYPAL = [
'_name'=>'cipf_paypal_credentials',
'_callback'=>'update_paypal_credentials_CIPF',
'_default' => [
'force_1_cent' =>false,
'is_sandbox' =>true,
'live_client_id' =>'Aedn5e8z__hPBvKirqw5bwlhI9ChG8_N6c1xbgybYyBr4B4oP8uVzmVdH1QVKdPQKf6bWg7orPV4PDrO',
'live_client_secret' =>'EGeGwfHGxHxsjnC-tH8W0IL4nN3_xlc3sXFRPCQOw5uUoWae3eOgghuDKMnZc5DVGTbP6yIjVJ1BaAra',
'sandbox_client_id' =>'AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl',
'sandbox_client_secret'=>'EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-',
],
];
const OPTION_PAYMENT = [
'_name'=>'cipf_payment_messages',
'_callback'=>'update_payment_messages_option_CIPF',
'_default'=>[
'success'=>
'Paiement réussi,
vous allez être redirigés vers votre espace',
'failure'=>
'Paiement échoué,
vous allez être redirigés vers votre espace',
'problem'=>
"Paiement réussi,
mais une erreur est survenue dans le traitement de la commande,
si vous voyez que votre compte n'est pas mis à jour correctement,
contactez la fipf directement",
],
];
const OPTION_EMAILS = [
'_name'=>'cipf_emails_option',
'_callback'=>'update_emails_settings_option_CIPF',
'_default'=>[
'payment_success'=>[
'name'=>'prof - le paiement a réussi',
'notification_send'=>'on',
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - paiement réussi]",
'notification_message'=>'paiement réussi de la part de $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>'on',
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - paiement réussi]",
'confirmation_message'=>"paiement réussi",
],
'payment_echec'=>[
'name'=>'prof - le paiement a echoué',
'notification_send'=>'on',
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - paiement echoué]",
'notification_message'=>'paiement echoué pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>'on',
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - paiement echoué]",
'confirmation_message'=>"votre paiement a echoué",
],
'payment_problem'=>[
'name'=>'prof - le paiement a rencontré un problem',
'notification_send'=>'on',
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - paiement probleme]",
'notification_message'=>'probleme de paiement pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>'off',
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - paiement problème]",
'confirmation_message'=>"votre paiement a rencontré un probleme",
],
'transfert_success'=>[
'name'=>'prof - le virement a été validé',
'notification_send'=>'on',
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - virement validé]",
'notification_message'=>'virement validé pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>'on',
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - virement validé]",
'confirmation_message'=>"votre virement a été validé",
],
'change_card_success'=>[
'name'=>'prof - le paiement pour changer la carte a réussi',
'notification_send'=>'on',
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - paiement changer carte reussi]",
'notification_message'=>'paiement pour changer sa carte a réussi de la part de $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>'on',
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - paiement changement carte réussi]",
'confirmation_message'=>"paiement changement carte réussi",
],
'card_will_expire'=>[
'name'=>'prof - la carte va bientot expirer',
'notification_send'=>'on',
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - carte va expirer]",
'notification_message'=>'la carte va expirer pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>'on',
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - carte va expirer]",
'confirmation_message'=>'votre carte va expirer bientot, renouvellez-la sur $$__base_url__$$',
],
'card_expired'=>[
'name'=>'prof - la carte a expiré',
'notification_send'=>'on',
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - carte expirée]",
'notification_message'=>'carte expirée pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>'on',
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - carte expirée]",
'confirmation_message'=>'votre carte a expiré, renouvelez-la sur $$__base_url__$$',
],
'account_will_be_deleted'=>[
'name'=>'prof - le compte va être supprimé',
'notification_send'=>'on',
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - compte bientot supprimé]",
'notification_message'=>'compte bientot supprimé pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>'on',
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - compte bientot supprimé]",
'confirmation_message'=>'votre compte va bientot être supprimé sur $$__base_url__$$',
],
'account_deleted'=>[
'name'=>'prof - le compte a été supprimé',
'notification_send'=>'on',
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /prof - compte supprimé]",
'notification_message'=>'compte supprimé pour $$user_login$$ : $$__author_page_url__$$',
'confirmation_send'=>'on',
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - compte supprimé]",
'confirmation_message'=>'votre compte a été supprimé sur $$__base_url__$$',
],
'offer_will_expire'=>[
'name'=>"partenaire - l'offre arrive bientot a expiration",
'notification_send'=>'on',
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /partenaire - offre va expirer]",
'notification_message'=>'offre va expirer pour $$user_login$$ : $$__user_post_url__$$',
'confirmation_send'=>'on',
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - offre va expirer]",
'confirmation_message'=>'une de vos offre va expirer, rendez-vous sur $$__base_url__$$',
],
'offer_expired'=>[
'name'=>"partenaire - l'offre partenaire a expirée",
'notification_send'=>'on',
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF /partenaire - offre expirée]",
'notification_message'=>'offre expirée pour $$user_login$$ : $$__user_post_url__$$',
'confirmation_send'=>'on',
'confirmation_from'=>'$$__admin_email__$$',
'confirmation_subject'=>"[CIPF - offre expirée]",
'confirmation_message'=>'votre offre a expiré, pour la renouveler rendez-vous sur $$__base_url__$$',
],
'cron_job'=>[
'name'=>"cron-job - une fois par jour",
'notification_send'=>'on',
'notification_from'=>'$$__admin_email__$$',
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"[CIPF - cron job]",
'notification_message'=>'la tache journaliere cron a bien fonctionné',
],
],
];
// ADMIN MENU
const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_cipf', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide'];
const TOGGLE_ADMIN_MENU = ['_name'=>'toggle_admin_menu_option_cipf', 'show'=>'show', 'hide'=>'hide'];
const ADMIN_POST_PAYPAL = 'paypal_credentials_CIPF';
const ADMIN_MENU_NONCE_PAYPAL = ['_name'=>'nonce_paypal_cipf', '_action'=>'action_admin_menu_paypal_cipf'];
const ADMIN_POST_EMAIL_REGISTRATION = 'email_registration_message_CIPF';
const ADMIN_MENU_NONCE_EMAIL_REGISTRATION = ['_name'=>'nonce_email_cipf', '_action'=>'action_admin_menu_email_registration_cipf'];
const ADMIN_POST_PAYMENT_MESSAGES = 'payment_messages_CIPF';
const ADMIN_MENU_NONCE_PAYMENT_MESSAGES = ['_name'=>'nonce_payment_cipf', '_action'=>'action_admin_menu_payment_messages_cipf'];
// FORMS
const FORM_PROF_COMMANDE_ID = 'prof_commande';
const FORM_PROF_TRANSFERT_ID = 'prof_valide_virement';
const FORM_PARTNER_PAGE_ID = 'crea_partenaire';
// DURATIONS
const DURATION_CARD_VALIDITY = '+1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days')
const DURATION_OLD_ORDER_ID = '+3 days';
const DURATION_ACCOUNT_DELETE_AFTER_EXPIRE = '+6 months';
const DURATION_REMINDERS_BEFORE_ACCOUNT_EXPIRE = ['-30 days', '-7 days'];
const DURATION_REMINDERS_BEFORE_ACCOUNT_DELETE = ['-30 days', '-7 days'];
const DURATION_REMINDERS_BEFORE_OFFER_EXPIRE = ['-7 days'];
// OTHER
const CARD_RENEW_PERIOD = 31; // int : number of days before expiration when renew card start to be possible
const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php)
const ADMIN_VALIDATE_PROF_FIELD = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
const INPUT_HIDDEN_ROLE = 'cipf_user_role';
}
?>