From: Vincent Vanwaelscappel Date: Wed, 14 May 2025 10:45:12 +0000 (+0200) Subject: wait #7530 @2.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=2796e7c9a3e33ac23e61ef8f7ab58ea83a11be20;p=ccv-wordpress.git wait #7530 @2.5 --- diff --git a/local-config-dev.php b/local-config-dev.php new file mode 100644 index 0000000..1c17ec2 --- /dev/null +++ b/local-config-dev.php @@ -0,0 +1,10 @@ +set_form_title(__('Rendez-vous', 'ccv')); $this->doctors = [ - __('Première disponibilité', 'ccv') => [ 'legend' => __('La première date disponible vous sera proposée.','ccv'), 'url' => @asset('images/doctors/premiere_dispo.jpg')], - __('Dr Martin GRAU ORTIZ') => [ 'legend' => 'Chirurgien orthopédiste spécialisé en chirurgie vertébrale.', 'url' => @asset('images/doctors/martin_grau_ortiz.jpg')], - __('Dr Guilhaume GENESTE') => [ 'legend' => 'Chirurgien orthopédiste spécialisé en chirurgie vertébrale.', 'url' => @asset('images/doctors/guilhaume_geneste.jpg')], - __('Dr Caroline HIRSCH') => [ 'legend' => 'Chirurgien orthopédiste spécialisé en chirurgie vertébrale.', 'url' => @asset('images/doctors/caroline_hirsch.jpg')], - __('Dr Grégory EDGARD-ROSA') => [ 'legend' => 'Chirurgien orthopédiste spécialisé en chirurgie vertébrale.', 'url' => @asset('images/doctors/gregory_edgard_rosa.jpg')] + __('Première disponibilité', 'ccv') => ['legend' => __('La première date disponible vous sera proposée.', 'ccv'), 'url' => @asset('images/doctors/premiere_dispo.jpg')], + __('Dr Martin GRAU ORTIZ') => ['legend' => 'Chirurgien orthopédiste spécialisé en chirurgie vertébrale.', 'email' => 'dr.grauortiz@ccv-montpellier.fr', 'url' => @asset('images/doctors/martin_grau_ortiz.jpg')], + __('Dr Guilhaume GENESTE') => ['legend' => 'Chirurgien orthopédiste spécialisé en chirurgie vertébrale.', 'email' => 'dr.geneste@ccv-montpellier.fr', 'url' => @asset('images/doctors/guilhaume_geneste.jpg')], + __('Dr Caroline HIRSCH') => ['legend' => 'Chirurgien orthopédiste spécialisé en chirurgie vertébrale.', 'email' => 'dr.hirsch@ccv-montpellier.fr', 'url' => @asset('images/doctors/caroline_hirsch.jpg')], + __('Dr Grégory EDGARD-ROSA') => ['legend' => 'Chirurgien orthopédiste spécialisé en chirurgie vertébrale.', 'email' => 'dr.edgard-rosa@ccv-montpellier.fr', 'url' => @asset('images/doctors/gregory_edgard_rosa.jpg')] ]; } - function register_fields() { + function register_fields() + { parent::register_fields(); $this->add_fields([ Radio::field('doctor', __('Choisissez un chirurgien', 'ccv')) @@ -33,4 +37,19 @@ class Appointment extends Consultation ]), ]); } + + public function pre_process() + { + + parent::pre_process(); + + // If a surgeon is selected, send the form directly to them + $d = $this->get_data('doctor'); + if (!empty($d) && array_key_exists($d, $this->doctors)) { + if (isset($this->doctors[$d]['email'])) { + $this->set_destination($this->doctors[$d]['email']); + } + + } + } } \ No newline at end of file diff --git a/wp-content/mu-plugins/cube/src/Forms/Base.php b/wp-content/mu-plugins/cube/src/Forms/Base.php index c9ad77d..92eaba7 100644 --- a/wp-content/mu-plugins/cube/src/Forms/Base.php +++ b/wp-content/mu-plugins/cube/src/Forms/Base.php @@ -31,17 +31,20 @@ class Base // Early setup called by Init.php in mu-plugin to register // This is separated from init() so we can set up hooks for every request // but only register scripts when we are going to display the form... - public function register() { + public function register() + { $this->hook(); } - public function hook() { + public function hook() + { // Catch AJAX requests (handles both logged in and logged out users) - add_action('wp_ajax_nopriv_'. $this->action_name, [$this, 'handle_ajax_request']); - add_action('wp_ajax_'. $this->action_name, [$this, 'handle_ajax_request']); + add_action('wp_ajax_nopriv_' . $this->action_name, [$this, 'handle_ajax_request']); + add_action('wp_ajax_' . $this->action_name, [$this, 'handle_ajax_request']); } - public function init() { + public function init() + { // Prepare the form // NOTE: previously register_scripts() and $this->builder weren't set for AJAX requests @@ -51,10 +54,11 @@ class Base $this->register_fields(); $this->register_scripts(); - $this->builder = new FormBuilder($this->get_fields(),$this->doctors); + $this->builder = new FormBuilder($this->get_fields(), $this->doctors); } - public function register_scripts() { + public function register_scripts() + { //=== Cube Forms // Base forms functionality - enqueued directly since it is always required @@ -63,8 +67,8 @@ class Base // JS variables wp_add_inline_script( 'cube-forms', - 'cube_forms_config = '. json_encode([ - 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'cube_forms_config = ' . json_encode([ + 'ajax_url' => admin_url('admin-ajax.php'), 'action' => $this->action_name, 'nonce' => wp_create_nonce($this->action_name), ]), @@ -107,10 +111,10 @@ class Base foreach ($flatpickr_languages as $flatpickr_language) { wp_register_script("flatpickr-locale-{$flatpickr_language}", - asset("scripts/flatpickr/locale/{$flatpickr_language}.js"), - ['flatpickr'], // Dependencies - null, // Version - true // In footer? + asset("scripts/flatpickr/locale/{$flatpickr_language}.js"), + ['flatpickr'], // Dependencies + null, // Version + true // In footer? ); } @@ -118,13 +122,17 @@ class Base } - public function register_fields() {} + public function register_fields() + { + } - public function get_forms() { + public function get_forms() + { return $this->forms; } - public function get_request_data() { + public function get_request_data() + { $data = $this->sanitize($_POST); $files = $this->normalise_files($_FILES); @@ -143,13 +151,14 @@ class Base // Normalise PHP's $_FILES array so the structure is consistent between single and multi-file uploads // This also gives a more sensible structure than PHP's default because each upload is grouped // Ref: https://www.php.net/manual/en/features.file-upload.post-method.php#118858 - protected function normalise_files($files = []) { + protected function normalise_files($files = []) + { if (empty($files)) return []; $normalised_array = []; - foreach($files as $index => $file) { + foreach ($files as $index => $file) { // Single upload only if (!is_array($file['name'])) { @@ -158,7 +167,7 @@ class Base } // Multi-file upload - foreach($file['name'] as $idx => $name) { + foreach ($file['name'] as $idx => $name) { $normalised_array[$index][$idx] = [ 'name' => $name, 'type' => $file['type'][$idx], @@ -174,7 +183,8 @@ class Base // Temporarily hook directly into PHPMailer so we can attach files AND set their names // Ref: https://stackoverflow.com/a/57778561 - public function attach_files($PHPMailer) { + public function attach_files($PHPMailer) + { $files = $this->normalise_files($_FILES); @@ -188,14 +198,15 @@ class Base } - public function handle_ajax_request() { + public function handle_ajax_request() + { // Here we handle the form ajax requests, ensuring they're valid and loading the appropriate sub-class // First, check that request is valid via nonce value if (check_ajax_referer($this->action_name, 'nonce', false) === false) { wp_send_json([ - 'message' => [ + 'message' => [ 'type' => 'error', 'text' => __('Une erreur est survenue. Veuillez réessayer.', 'ccv'), ], @@ -211,7 +222,7 @@ class Base if (!($form_name && array_key_exists($form_name, $this->forms))) { wp_send_json([ - 'message' => [ + 'message' => [ 'type' => 'error', 'text' => __('Une erreur est survenue. Veuillez réessayer.', 'ccv'), ], @@ -230,36 +241,43 @@ class Base exit; } - public function pre_process() {} + public function pre_process() + { + } - public function process() { + public function process() + { $this->pre_process(); $headers = []; $data = []; - $to = $this->destination; - $from = 'CCV Montpellier '; - $subject = $this->form_title; + $to = $this->destination; + $from = 'CCV Montpellier '; + $subject = $this->form_title; $content_type = 'text/html'; - $charset = get_bloginfo('charset'); - $headers[] = sprintf('Content-Type: %s; charset=%s', $content_type, $charset); - $headers[] = sprintf('From: %s', $from); + $charset = get_bloginfo('charset'); + $headers[] = sprintf('Content-Type: %s; charset=%s', $content_type, $charset); + $headers[] = sprintf('From: %s', $from); + if (ENV === 'dev') { + $to = 'test+ccv@cubedesigners.com'; + $headers[] = 'X-Debug-To: ' . $this->destination; + } $first_data_names = [ 'doctor', ]; // Gather filled fields into label/value pairs foreach ($first_data_names as $first_data_name) { - if($this->fields[$first_data_name]) { + if ($this->fields[$first_data_name]) { $data[$this->fields[$first_data_name]->get_title()] = $this->get_data($first_data_name); } } foreach ($this->fields as $field_name => $field) { - if(!in_array($field_name,$first_data_names)) { + if (!in_array($field_name, $first_data_names)) { if ($value = $this->get_data($field_name)) { $title = $field->get_title(); - if(in_array($field_name, ['strength-loss-date','tingling-numbness-date'])) { + if (in_array($field_name, ['strength-loss-date', 'tingling-numbness-date'])) { $title = $field_name; } $data[$title] = $value; @@ -269,9 +287,9 @@ class Base $message = view('forms.common.email', compact('data', 'subject')); - if($this->get_data('social-cover') === __('Accident du travail') && empty($this->get_data('work-accident'))) { + if ($this->get_data('social-cover') === __('Accident du travail') && empty($this->get_data('work-accident'))) { wp_send_json([ - 'message' => [ + 'message' => [ 'type' => 'error', 'text' => __("Veuillez indiquer une date d'accident de travail.", "ccv"), ] @@ -303,9 +321,12 @@ class Base } - public function post_process() {} + public function post_process() + { + } - public function get_data($name, $default = null) { + public function get_data($name, $default = null) + { if (isset($this->data[$name])) { return $this->data[$name]; } @@ -313,15 +334,18 @@ class Base return $default; } - public function set_data($name, $value) { + public function set_data($name, $value) + { $this->data[$name] = $value; } - public function get_destination() { + public function get_destination() + { return $this->destination; } - public function set_form_title($title = '', $append = false) { + public function set_form_title($title = '', $append = false) + { if (!empty($title)) { if ($append) { $this->form_title .= $title; @@ -331,13 +355,15 @@ class Base } } - public function set_destination($address = '') { + public function set_destination($address = '') + { if (!empty($address)) { $this->destination = $address; } } - public function add_fields($fields) { + public function add_fields($fields) + { if (!is_array($fields)) { $fields[] = $fields; @@ -353,7 +379,8 @@ class Base * @param $name * @return bool */ - public function exists($name) { + public function exists($name) + { return isset($this->fields[$name]); } @@ -362,7 +389,8 @@ class Base * @param $name * @return mixed|null */ - public function get_field($name) { + public function get_field($name) + { return $this->fields[$name] ?? null; } @@ -371,7 +399,8 @@ class Base * @param $name * @return bool */ - public function remove_field($name) { + public function remove_field($name) + { if (!$this->exists($name)) { return false; @@ -385,7 +414,8 @@ class Base * Get all fields * @return array */ - public function get_fields() { + public function get_fields() + { return $this->fields; } @@ -395,39 +425,40 @@ class Base * @param mixed $value * @return mixed */ - public function sanitize( $value ) { - if ( is_string( $value ) ) { + public function sanitize($value) + { + if (is_string($value)) { // do nothing if empty string - if ( $value === '' ) { + if ($value === '') { return $value; } // strip slashes - $value = stripslashes( $value ); + $value = stripslashes($value); // strip all whitespace - $value = trim( $value ); + $value = trim($value); // convert & back to & - $value = html_entity_decode( $value, ENT_NOQUOTES ); - } elseif ( is_array( $value ) || is_object( $value ) ) { + $value = html_entity_decode($value, ENT_NOQUOTES); + } elseif (is_array($value) || is_object($value)) { $new_value = array(); - $vars = is_array( $value ) ? $value : get_object_vars( $value ); + $vars = is_array($value) ? $value : get_object_vars($value); // do nothing if empty array or object - if ( count( $vars ) === 0 ) { + if (count($vars) === 0) { return $value; } - foreach ( $vars as $key => $sub_value ) { + foreach ($vars as $key => $sub_value) { // strip all whitespace & HTML from keys (!) - $key = trim( strip_tags( $key ) ); + $key = trim(strip_tags($key)); // sanitize sub value - $new_value[ $key ] = $this->sanitize( $sub_value ); + $new_value[$key] = $this->sanitize($sub_value); } - $value = is_object( $value ) ? (object) $new_value : $new_value; + $value = is_object($value) ? (object)$new_value : $new_value; } return $value; diff --git a/wp-content/mu-plugins/cube/src/Forms/Consultation.php b/wp-content/mu-plugins/cube/src/Forms/Consultation.php index 98f8209..f09d3dd 100644 --- a/wp-content/mu-plugins/cube/src/Forms/Consultation.php +++ b/wp-content/mu-plugins/cube/src/Forms/Consultation.php @@ -15,27 +15,31 @@ use Cube\Forms\Builder\Fields\Textarea; use function Roots\asset; -class Consultation extends Base { - public function __construct() { - $this->set_form_title(__('E-diagnostic', 'ccv')); - } +class Consultation extends Base +{ + public function __construct() + { + $this->set_form_title(__('E-diagnostic', 'ccv')); + } - public function register_scripts() { + public function register_scripts() + { - parent::register_scripts(); + parent::register_scripts(); - wp_enqueue_script('ccv-consultation', asset('scripts/consultation.js'), ['jquery'], null, true); - wp_enqueue_script('lity', asset('scripts/lity.js'), ['jquery'], null, true); - wp_enqueue_style('lity-css', asset('styles/lity.css')); - } + wp_enqueue_script('ccv-consultation', asset('scripts/consultation.js'), ['jquery'], null, true); + wp_enqueue_script('lity', asset('scripts/lity.js'), ['jquery'], null, true); + wp_enqueue_style('lity-css', asset('styles/lity.css')); + } - function register_fields() { + function register_fields() + { - $this->add_fields([ + $this->add_fields([ - //=== PERSONAL INFORMATION + //=== PERSONAL INFORMATION // Special field: if a surgeon is selected, their e-mail address will be override the default delivery address Select::field('surgeon', __('Chirurgien spécifique', 'ccv')) ->required(false) @@ -45,8 +49,8 @@ class Consultation extends Base { 'Dr Martin GRAU ORTIZ' => 'dr.grauortiz@ccv-montpellier.fr', 'Dr Caroline HIRSH' => 'dr.hirsch@ccv-montpellier.fr', ]), - Text::field('last-name', __('Nom', 'ccv')), - Text::field('first-name', __('Prénom', 'ccv')), + Text::field('last-name', __('Nom', 'ccv')), + Text::field('first-name', __('Prénom', 'ccv')), Radio::field('sex', __('Sexe :', 'ccv')) ->options([ _x('M', 'Sexe (M)', 'ccv'), @@ -55,9 +59,9 @@ class Consultation extends Base { Date::field('birthdate', __('Date de naissance', 'ccv')), Text::field('size', __('Taille :', 'ccv')), Text::field('weight', __('Poids :', 'ccv')), - Text::field('profession', __('Profession', 'ccv')), - Text::field('postcode', __('Code postal', 'ccv')), - Text::field('city', __('Ville', 'ccv')), + Text::field('profession', __('Profession', 'ccv')), + Text::field('postcode', __('Code postal', 'ccv')), + Text::field('city', __('Ville', 'ccv')), Text::field('country', __('Pays', 'ccv')), Text::field('phone', __('Tel', 'ccv')), Email::field('email', __('Email', 'ccv')), @@ -115,11 +119,11 @@ class Consultation extends Base { Textarea::field('symptoms', __('Dites-nous en quelques mots ce qui vous invalide le plus dans vos symptômes :', 'ccv')), Textarea::field('surgeries', __('Indiquez ici vos précédentes chirurgies de la colonne et leurs dates (le cas échéant)', 'ccv'))->required(false), - // Unique session identifier for uploads that go directly to CCV's NAS (upload.ccv-montpellier.fr) - // Made up of timestamp YYMMDDHHMM + nonce - Hidden::field('imagery-phone-token', __('ID sur le NAS', 'ccv'))->value(date('ymdHi') . '_' . wp_create_nonce('NAS-upload')), + // Unique session identifier for uploads that go directly to CCV's NAS (upload.ccv-montpellier.fr) + // Made up of timestamp YYMMDDHHMM + nonce + Hidden::field('imagery-phone-token', __('ID sur le NAS', 'ccv'))->value(date('ymdHi') . '_' . wp_create_nonce('NAS-upload')), - //=== TREATMENTS + //=== TREATMENTS Binary::field('kine-osteo', __('Kinésithérapie ou ostéopathie', 'ccv')), Binary::field('infiltration', __('Infiltration ou thermocoagulation', 'ccv')), Binary::field('rheumatological', __('Suivi rhumatologique ou médecine spécialisée', 'ccv')), @@ -133,8 +137,8 @@ class Consultation extends Base { Radio::field('imagery-type', __('Imagerie', 'ccv'))->required(false), Radio::field('imagery-condition', __('IRM de moins de 6 mois', 'ccv')) ->options([ - __('J\'ai bien noté que mon dossier ne pourra être étudié si je ne fournis pas une IRM de moins de 6 mois', 'ccv'), - ]), + __('J\'ai bien noté que mon dossier ne pourra être étudié si je ne fournis pas une IRM de moins de 6 mois', 'ccv'), + ]), Text::field('link-1', __('Lien internet 1', 'ccv'))->required(false), Text::field('id-1', __('Identifiant', 'ccv'))->required(false), @@ -152,42 +156,42 @@ class Consultation extends Base { Textarea::field('message', __('Avez vous un message (ou une demande) spécifique à nous formuler ?', 'ccv'))->required(false), //Text::field('age', __('Âge :', 'ccv')), - ]); - } + ]); + } - public function pre_process() { + public function pre_process() + { - // Include patient name in subject line - $this->set_form_title(' - ' . strtoupper($this->get_data('last-name')) . ', ' . $this->get_data('first-name'), true); + // Include patient name in subject line + $this->set_form_title(' - ' . strtoupper($this->get_data('last-name')) . ', ' . $this->get_data('first-name'), true); - // Due to the complexity of the "Imagery" section of the form, there's no validation on these fields - // so it's possible to submit the form without ever selecting an imagery-type. In this case, we update - // the field value so it is clear to CCV that the client never filled out this section... - if (empty($this->get_data('imagery-type'))) { - $this->set_data('imagery-type', __('Aucune image envoyée', 'ccv')); - } + // Due to the complexity of the "Imagery" section of the form, there's no validation on these fields + // so it's possible to submit the form without ever selecting an imagery-type. In this case, we update + // the field value so it is clear to CCV that the client never filled out this section... + if (empty($this->get_data('imagery-type'))) { + $this->set_data('imagery-type', __('Aucune image envoyée', 'ccv')); + } if (!empty($this->get_data('link-1')) || !empty($this->get_data('link-2')) || - !empty($this->get_data('link-3')) || !empty($this->get_data('link-4')) ) { + !empty($this->get_data('link-3')) || !empty($this->get_data('link-4'))) { $this->set_data('imagery-type', __('Lien web', 'ccv')); } - // If the user didn't select the NAS upload option, there's no point including the NAS ID in the form data - // NOTE: This relies on the value of the field so make sure it is always the same in both places (consultation.blade.php) - if ($this->get_data('imagery-type') !== __('Images téléversées depuis portable', 'ccv')) { - $this->remove_field('imagery-phone-token'); - } - - // If a surgeon is selected, send the form directly to them - $surgeons = $this->get_field('surgeon')->get_options(); - if (!empty($this->get_data('surgeon')) && array_key_exists($this->get_data('surgeon'), $surgeons)) { - if (!defined('ENV') || ENV !== 'dev') { - $this->set_destination($surgeons[$this->get_data('surgeon')]); - } - } - - if($this->form_title === "appointment") { + // If the user didn't select the NAS upload option, there's no point including the NAS ID in the form data + // NOTE: This relies on the value of the field so make sure it is always the same in both places (consultation.blade.php) + if ($this->get_data('imagery-type') !== __('Images téléversées depuis portable', 'ccv')) { + $this->remove_field('imagery-phone-token'); + } + + // If a surgeon is selected, send the form directly to them + $surgeons = $this->get_field('surgeon')->get_options(); + if (!empty($this->get_data('surgeon')) && array_key_exists($this->get_data('surgeon'), $surgeons)) { + $this->set_destination($surgeons[$this->get_data('surgeon')]); + + } + + if ($this->form_title === "appointment") { $this->remove_field('surgeon'); } - } + } }