diff --git a/2 b/2 new file mode 100644 index 0000000..b33c33b --- /dev/null +++ b/2 @@ -0,0 +1,108 @@ + diff --git a/plugins/cipf_plugin/fipfcard_plugin.php b/plugins/cipf_plugin/fipfcard_plugin.php index 8f7ba3c..85e09bf 100644 --- a/plugins/cipf_plugin/fipfcard_plugin.php +++ b/plugins/cipf_plugin/fipfcard_plugin.php @@ -47,6 +47,8 @@ include_once(PLGNTLS_class::root_path() . 'php/prof_check_page.php'); include_once(PLGNTLS_class::root_path() . 'php/renew_card.php'); //include_once(PLGNTLS_class::root_path() . 'php/reset_card_form.php'); include_once(PLGNTLS_class::root_path() . 'php/partner_check_page.php'); +include_once(PLGNTLS_class::root_path() . 'php/format_user_infos.php'); +include_once(PLGNTLS_class::root_path() . 'php/admin_modif_prof.php'); // form builder patch : diff --git a/plugins/cipf_plugin/js/admin_prevent_submit.js b/plugins/cipf_plugin/js/admin_prevent_submit.js new file mode 100644 index 0000000..d05b4dd --- /dev/null +++ b/plugins/cipf_plugin/js/admin_prevent_submit.js @@ -0,0 +1,24 @@ +/* + +cipf_admin_activate_prof_form +*/ + +function admin_activate_form_submit_prevent_CIPF() { + let form_activate_prof = document.querySelector('#cipf_admin_activate_prof_form form'); + console.log("form:"); + console.log(form_activate_prof); + if (form_activate_prof === null) + return; + + function handle_form(event) { + event.preventDefault(); + let form_data = new FormData(event.target); + for (var pair of form_data.entries()) { + console.log(pair[0]+ ': ' + pair[1]); + } + } + + form_activate_prof.addEventListener('submit', handle_form); +} +admin_activate_form_submit_prevent_CIPF(); + diff --git a/plugins/cipf_plugin/js/form_builder_patch/form_calculation.js b/plugins/cipf_plugin/js/form_builder_patch/form_calculation.js index d420f3d..80c03be 100644 --- a/plugins/cipf_plugin/js/form_builder_patch/form_calculation.js +++ b/plugins/cipf_plugin/js/form_builder_patch/form_calculation.js @@ -1,66 +1,71 @@ -/* -* finds the input:checked in the element .calculate_field -* and trigger the event 'change' on it -* - this event 'change' is added by form builder in divi-form-calc-min.js : -* $(document).on( -* 'change', -* '.calculate_field input:not([type="hidden"]), .calculate_field select', -* function () { -* ... -* } -* ); -* -*/ -function trigger_change_CIPF(element) { - /* - * jquery version - * - let inputs = $(element).find('input:checked'); - inputs.trigger('change'); - */ +function patch_form_calculation_CIPF() { + let form_calculation = document.querySelector('form.fb_form.multistep'); + if (form_calculation === null) + return; /* - * js version + * finds the input:checked in the element .calculate_field + * and trigger the event 'change' on it + * - this event 'change' is added by form builder in divi-form-calc-min.js : + * $(document).on( + * 'change', + * '.calculate_field input:not([type="hidden"]), .calculate_field select', + * function () { + * ... + * } + * ); * */ - let inputs = element.querySelectorAll('input:checked'); - // loop through inputs and trigger 'change' event on each - inputs.forEach(function(input) { - // Triggering 'change' event - let change_event = new Event('change', { - bubbles: true, - cancelable: true, + function trigger_change(element) { + /* + * jquery version + * + let inputs = $(element).find('input:checked'); + inputs.trigger('change'); + */ + + /* + * js version + * + */ + let inputs = element.querySelectorAll('input:checked'); + // loop through inputs and trigger 'change' event on each + inputs.forEach(function(input) { + // Triggering 'change' event + let change_event = new Event('change', { + bubbles: true, + cancelable: true, + }); + input.dispatchEvent(change_event); }); - input.dispatchEvent(change_event); - }); -} - - -let form_CIPF = document.querySelector('form.fb_form.multistep'); - -// create an observer on form to check if child nodes are modified -const observer_form_CIPF = new MutationObserver(wait_for_calculation_class_CIPF); -observer_form_CIPF.observe(form_CIPF, { - subtree: true, - attributes: true, -}); - -// observe mutations to see if they include the addition of class .calculate_field -// if the class is added, call the function that might trigger the change event on it -function wait_for_calculation_class_CIPF(mutationsList) { - mutationsList.forEach((mutation) => { - // check if class where added - if (mutation.type !== 'attributes') - return; - if (mutation.attributeName !== 'class') - return; - // check if added class is .calculate_field - let target = mutation.target; - if (target.classList.contains('calculate_field')) { - // If the class is added, trigger the 'change' event - trigger_change_CIPF(target); - } + } + + + // create an observer on form to check if child nodes are modified + const observer_form = new MutationObserver(wait_for_calculation_class); + observer_form.observe(form_calculation, { + subtree: true, + attributes: true, }); + + // observe mutations to see if they include the addition of class .calculate_field + // if the class is added, call the function that might trigger the change event on it + function wait_for_calculation_class(mutationsList) { + mutationsList.forEach((mutation) => { + // check if class where added + if (mutation.type !== 'attributes') + return; + if (mutation.attributeName !== 'class') + return; + // check if added class is .calculate_field + let target = mutation.target; + if (target.classList.contains('calculate_field')) { + // If the class is added, trigger the 'change' event + trigger_change(target); + } + }); + } } +patch_form_calculation_CIPF(); diff --git a/plugins/cipf_plugin/php/admin_modif_prof.php b/plugins/cipf_plugin/php/admin_modif_prof.php new file mode 100644 index 0000000..19c3620 --- /dev/null +++ b/plugins/cipf_plugin/php/admin_modif_prof.php @@ -0,0 +1,166 @@ + 'Form submitted successfully' ), 200 ); +} +function endpoint_form_admin_activate_prof_CIPF() { + PLGNTLS_class::debug_infos(); + $base_rest_route = PLGNTLS_class::BASE_REST_ROUTE; + register_rest_route($base_rest_route, '/admin_prof_activate_form', array( + 'methods' => 'POST', + 'callback' => 'admin_validate_prof_form_CIPF', + )); +}; +add_action('rest_api_init', 'endpoint_form_admin_activate_prof_CIPF'); + + + + +/* +* ABORTED +* enqueue script that should prevent the form to submit, but does not work +* +function admin_validate_prof_prevent_CIPF() { + PLGNTLS_class::debug_infos(); + $handle = 'admin_prevent_submit'; + $url = PLGNTLS_class::root_url() . 'js/admin_prevent_submit.js'; + $dependencies = array(); + $version = null; + $defer = true; + wp_enqueue_script($handle, $url, $dependencies, $version, $defer); +} +add_action('wp_enqueue_scripts', 'admin_validate_prof_prevent_CIPF'); +*/ + + + + + +?> diff --git a/plugins/cipf_plugin/php/filter_mail.php b/plugins/cipf_plugin/php/filter_mail.php index f12017a..f655e0f 100644 --- a/plugins/cipf_plugin/php/filter_mail.php +++ b/plugins/cipf_plugin/php/filter_mail.php @@ -7,6 +7,7 @@ if (!defined('ABSPATH')) { die('You can not access this file!'); } +include_once(PLGNTLS_class::root_path() . 'php/format_user_infos.php'); @@ -22,6 +23,7 @@ function replace_words_CIPF($matches, $user_id = null) { } else if (is_user_logged_in()) { $current_user = wp_get_current_user(); + $user_id = get_current_user_id(); } else { return ""; @@ -31,7 +33,7 @@ function replace_words_CIPF($matches, $user_id = null) { return ""; $query = $matches[1]; - $result = $current_user->$query; + $result = format_user_info_CIPF($query, $current_user, $user_id); /* * if result is array, take the first element (not ideal) diff --git a/plugins/cipf_plugin/php/form_builder_patch/form_calculation.php b/plugins/cipf_plugin/php/form_builder_patch/form_calculation.php index 0a6d8b7..5add040 100644 --- a/plugins/cipf_plugin/php/form_builder_patch/form_calculation.php +++ b/plugins/cipf_plugin/php/form_builder_patch/form_calculation.php @@ -15,7 +15,7 @@ function add_form_calculation_patch_CIPF() { $handle = 'form_calculation_patch'; $url = PLGNTLS_class::root_url() . 'js/form_builder_patch/form_calculation.js'; $dependencies = array('de_fb_calc'); - $version = ''; + $version = null; $defer = true; wp_enqueue_script( $handle, $url, $dependencies, $version, $defer); } diff --git a/plugins/cipf_plugin/php/form_builder_patch/url_validation.php b/plugins/cipf_plugin/php/form_builder_patch/url_validation.php index 9fa6078..48d6f33 100644 --- a/plugins/cipf_plugin/php/form_builder_patch/url_validation.php +++ b/plugins/cipf_plugin/php/form_builder_patch/url_validation.php @@ -20,7 +20,7 @@ function add_my_jquery_patch() $handle = 'jquery_validator_url_patch'; $url = PLGNTLS_class::root_url() . 'js/form_builder_patch/url_validation.js'; $dependencies = array('de_fb_validate'); - $version = ''; + $version = null; $defer = true; wp_enqueue_script( $handle, $url, $dependencies, $version, $defer); } diff --git a/plugins/cipf_plugin/php/format_user_infos.php b/plugins/cipf_plugin/php/format_user_infos.php new file mode 100644 index 0000000..0ca6742 --- /dev/null +++ b/plugins/cipf_plugin/php/format_user_infos.php @@ -0,0 +1,92 @@ +$_acf_field; + if (!empty($acf_field)) + $is_acf = true; + */ + + /* + * check if it's an acf field, and a date + * second method : check what get_field_object() returns + * + */ + $acf_id = 'user_'.$user_id; + $acf_object = get_field_object($query, $acf_id); + if ($acf_object !== false) + $is_acf = true; + + + /* + * if is acf, use the acf return format + * otherwise, use the default wordpress value + * + */ + if ($is_acf) + $output = get_field($query, $acf_id); + else + $output = $current_user->$query; + + + /* + * check if is date + * + */ + if ($is_acf) { + $acf_type = $acf_object['type']; + if ($acf_type && $acf_type === "date_picker") + $is_date = true; + } + + + /* + * if is date, transform format + * + */ + if ($is_date) { + $acf_date_string = $acf_object['value']; + $acf_date_format = $acf_object['return_format']; + $date = date_create_from_format($acf_date_format, $acf_date_string); + $output = $date->format($output_date_format); + } + + + /* + * return the result + * + */ + while (is_array($output) && count($output) === 1) + $output = reset($output); + if (is_array($output) && count($output) === 0) + $output = ''; + if (!is_string($output)) + $output = json_encode($output, JSON_UNESCAPED_SLASHES); + return esc_html($output); +} + + + + + +?> diff --git a/plugins/cipf_plugin/php/partner_check_page.php b/plugins/cipf_plugin/php/partner_check_page.php index a658f67..be78da8 100644 --- a/plugins/cipf_plugin/php/partner_check_page.php +++ b/plugins/cipf_plugin/php/partner_check_page.php @@ -107,7 +107,6 @@ post_array form_type "post" -*/ function test_partner_CIPF($form_id, $post_array) { error_log("---"); @@ -119,6 +118,7 @@ function test_partner_CIPF($form_id, $post_array) { } add_action( 'df_before_process', 'test_partner_CIPF', 10, 2); add_action( 'df_after_process', 'test_partner_CIPF', 10, 2); +*/ diff --git a/plugins/cipf_plugin/php/paypal/routes.php b/plugins/cipf_plugin/php/paypal/routes.php index 48a9e0d..7540c34 100644 --- a/plugins/cipf_plugin/php/paypal/routes.php +++ b/plugins/cipf_plugin/php/paypal/routes.php @@ -13,7 +13,7 @@ if (!defined('ABSPATH')) { // diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573 function routes_endpoints_CIPF() { PLGNTLS_class::debug_infos(); - $base_rest_route = "cipf_plugin/api/v1"; + $base_rest_route = PLGNTLS_class::BASE_REST_ROUTE; register_rest_route($base_rest_route, '/orders', array( 'methods' => 'POST', 'callback' => 'handle_orders_request_CIPF', diff --git a/plugins/cipf_plugin/php/prof_check_page.php b/plugins/cipf_plugin/php/prof_check_page.php index c1f6721..d0d03ff 100644 --- a/plugins/cipf_plugin/php/prof_check_page.php +++ b/plugins/cipf_plugin/php/prof_check_page.php @@ -23,7 +23,7 @@ function handle_prof_is_activ_CIPF($author_id) { * */ $is_activ = get_field($acf_prof_is_activ['_name'], $acf_id); - if ($is_activ === 'Actif') + if ($is_activ === $acf_prof_is_activ['activ']) return; @@ -81,9 +81,11 @@ function show_prof_paiement_messages_CIPF($user_id) { * */ $is_activ = get_field($acf_prof_is_activ['_name'], $acf_id); - if (is_null($is_activ) || empty($is_activ)) + if (is_null($is_activ)) return; - if ($is_activ === 'Inactif') + if (empty($is_activ)) + return; + if ($is_activ === $acf_prof_is_activ['activ']) return; $cipf_prof_payement = new PLGNTLS_class(); diff --git a/plugins/cipf_plugin/php/reset_card_form.php b/plugins/cipf_plugin/php/reset_card_form.php index ef42dab..02214d8 100644 --- a/plugins/cipf_plugin/php/reset_card_form.php +++ b/plugins/cipf_plugin/php/reset_card_form.php @@ -1,5 +1,13 @@ $_acf_field; - if (!empty($acf_field)) - $is_acf = true; - */ - - /* - * check if it's an acf field, and a date - * second method : check what get_field_object() returns - * - */ - $acf_id = 'user_'.$user_id; - $acf_object = get_field_object($query, $acf_id); - if ($acf_object !== false) - $is_acf = true; - - - /* - * if is acf, use the acf return format - * otherwise, use the default wordpress value - * - */ - if ($is_acf) - $output = get_field($query, $acf_id); - else - $output = $current_user->$query; - - - /* - * check if is date - * - */ - if ($is_acf) { - $acf_type = $acf_object['type']; - if ($acf_type && $acf_type === "date_picker") - $is_date = true; - } - - - /* - * if is date, transform format - * - */ - if ($is_date) { - $acf_date_string = $acf_object['value']; - $acf_date_format = $acf_object['return_format']; - $date = date_create_from_format($acf_date_format, $acf_date_string); - $output = $date->format($output_date_format); - } - - - /* - * return the result - * - */ - while (is_array($output) && count($output) === 1) - $output = reset($output); - if (is_array($output) && count($output) === 0) - $output = ''; - if (!is_string($output)) - $output = json_encode($output, JSON_UNESCAPED_SLASHES); - return esc_html($output); -} - /* * shortcode to write user info of post author diff --git a/plugins/cipf_plugin/utils/plgntls_class.php b/plugins/cipf_plugin/utils/plgntls_class.php index fe42896..fc386ca 100644 --- a/plugins/cipf_plugin/utils/plgntls_class.php +++ b/plugins/cipf_plugin/utils/plgntls_class.php @@ -68,7 +68,7 @@ class PLGNTLS_class 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_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 @@ -97,9 +97,11 @@ class PLGNTLS_class const ROLE_ADMIN = 'administrator'; // OTHER - const CARD_RENEW_PERIOD = 31; // int : number of days before expiration when renew card start to be possible - const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days') - const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php) + const CARD_RENEW_PERIOD = 31; // int : number of days before expiration when renew card start to be possible + const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days') + 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 = 'cipf_admin_activate_prof'; // for admin_modif_prof.php + const BASE_REST_ROUTE = 'cipf_plugin/api/v1'; // for routes, in php/paypal/routes.php && php/admin_modif_prof.php diff --git a/private b/private index 56b1f35..de5ea3a 160000 --- a/private +++ b/private @@ -1 +1 @@ -Subproject commit 56b1f351d4983cb88a16ee9e0133b571c1e31505 +Subproject commit de5ea3a591024f68dbf54d635908e28c1ec8cb46