emails in admin menu and updating options seems to work

This commit is contained in:
asus
2024-04-03 13:19:12 +02:00
parent 59b9acc55e
commit ffc47a0295
3 changed files with 89 additions and 98 deletions

View File

@@ -32,6 +32,9 @@
margin: 0px;
border: none;
padding: 0px;
> input[type="submit"] {
margin-left: 15px;
}
details.set_email_options_cipf {
margin: 15px;
padding: 0px 20px;
@@ -65,7 +68,7 @@
<!-- https://developer.wordpress.org/reference/hooks/admin_post_action/ -->
<h1>paypal credentials</h1>
<?php echo Plgntls::open_form_option($option_paypal_name); ?>
<?php echo Plgntls::open_form_option($option_paypal['_name']); ?>
<div class="define_paypal_credentials_cipf define_paypal_client_id_cipf vertical_wrapper_cipf">
<label for="paypal_client_id_cipf">client id : </label>
<input type="text" id="paypal_client_id_cipf" name="client_id" value="<?php echo $option_paypal['client_id']; ?>" />
@@ -94,20 +97,20 @@
<!--
-->
<h1>messages apres paiement, avant redirection</h1>
<?php echo Plgntls::open_form_option($option_payment_name); ?>
<?php echo Plgntls::open_form_option($option_payment['_name']); ?>
<div class="define_payment_message_cipf vertical_wrapper_cipf">
<label for="define_payment_message_success_cipf">paiement réussi : </label>
<textarea id="define_payment_message_success_cipf" name="message_success"><?php echo esc_html($option_payment['success']); ?></textarea>
<textarea id="define_payment_message_success_cipf" name="message_success"><?php echo esc_html(stripslashes($option_payment['success'])); ?></textarea>
</div>
<div class="define_payment_message_cipf vertical_wrapper_cipf">
<label for="define_payment_message_failure_cipf">paiement echec : </label>
<textarea id="define_payment_message_failure_cipf" name="message_failure"><?php echo esc_html($option_payment['failure']); ?></textarea>
<textarea id="define_payment_message_failure_cipf" name="message_failure"><?php echo esc_html(stripslashes($option_payment['failure'])); ?></textarea>
</div>
<div class="define_payment_message_cipf vertical_wrapper_cipf">
<label for="define_payment_message_problem_cipf">paiement problem (dans le cas où le paiement est réussi, mais il y eu une erreur dans son traitement sur le site) : </label>
<textarea id="define_payment_message_problem_cipf" name="message_problem"><?php echo esc_html($option_payment['problem']); ?></textarea>
<textarea id="define_payment_message_problem_cipf" name="message_problem"><?php echo esc_html(stripslashes($option_payment['problem'])); ?></textarea>
</div>
<input type="submit" value="send"/>
@@ -129,32 +132,37 @@
'confirmation_message'=>"donne l'argent",
-->
<h1>emails :</h1>
<?php echo Plgntls::open_form_option($option_emails_name, 'POST', 'emails_form_cipf'); ?>
<?php echo Plgntls::open_form_option($option_emails['_name'], 'POST', 'emails_form_cipf'); ?>
<?php foreach($option_emails as $name => $email_options) { ?>
<?php
foreach($option_emails as $name => $email_options) {
if ($name === '_name') {
continue;
}
?>
<details class="set_email_options_cipf">
<summary><h2><?php echo esc_html($name); ?> :</h2></summary>
<summary><h2><?php echo esc_html(stripslashes($email_options['name'])); ?> :</h2></summary>
<div class="email_type_wrapper_cipf email_type_notification_wrapper_cipf">
<div class="send_or_not_cipf">
<input type="checkbox" id="<?php echo esc_html($name); ?>_notification_cipf" name="<?php echo esc_html($name); ?>_notification_send" <?php if ($email_options['notification_send'] === true) {echo 'checked';} ?> />
<label for="<?php echo esc_html($name); ?>_notification_cipf">envoyer une notification ?</label>
<input type="checkbox" id="<?php echo esc_html(stripslashes($name)); ?>_notification_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_send" <?php if ($email_options['notification_send'] === true) {echo 'checked';} ?> />
<label for="<?php echo esc_html(stripslashes($name)); ?>_notification_cipf">envoyer une notification ?</label>
</div>
<div class="email_options_cipf">
<div class="vertical_wrapper_cipf">
<label for="<?php echo esc_html($name); ?>_notification_to_cipf">destinataire : </label>
<input type="text" id="<?php echo esc_html($name); ?>_notification_to_cipf" name="<?php echo esc_html($name); ?>_notification_to" value="<?php echo esc_html($email_options['notification_to']); ?>" />
<label for="<?php echo esc_html(stripslashes($name)); ?>_notification_to_cipf">destinataire : </label>
<input type="text" id="<?php echo esc_html(stripslashes($name)); ?>_notification_to_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_to" value="<?php echo esc_html(stripslashes($email_options['notification_to'])); ?>" />
</div>
<div class="vertical_wrapper_cipf">
<label for="<?php echo esc_html($name); ?>_notification_subject_cipf">sujet : </label>
<textarea id="<?php echo esc_html($name); ?>_notification_subject_cipf" name="<?php echo esc_html($name); ?>_notification_subject"><?php echo esc_html($email_options['notification_subject']); ?></textarea>
<label for="<?php echo esc_html(stripslashes($name)); ?>_notification_subject_cipf">sujet : </label>
<textarea id="<?php echo esc_html(stripslashes($name)); ?>_notification_subject_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_subject"><?php echo esc_html(stripslashes($email_options['notification_subject'])); ?></textarea>
</div>
<div class="vertical_wrapper_cipf">
<label for="<?php echo esc_html($name); ?>_notification_message_cipf">message : </label>
<textarea id="<?php echo esc_html($name); ?>_notification_message_cipf" name="<?php echo esc_html($name); ?>_notification_message"><?php echo esc_html($email_options['notification_message']); ?></textarea>
<label for="<?php echo esc_html(stripslashes($name)); ?>_notification_message_cipf">message : </label>
<textarea id="<?php echo esc_html(stripslashes($name)); ?>_notification_message_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_notification_message"><?php echo esc_html(stripslashes($email_options['notification_message'])); ?></textarea>
</div>
</div>
@@ -163,19 +171,19 @@
<div class="email_type_wrapper_cipf email_type_confirmation_wrapper_cipf">
<div class="send_or_not_cipf">
<input type="checkbox" id="<?php echo esc_html($name); ?>_confirmation_cipf" name="<?php echo esc_html($name); ?>_confirmation_send" <?php if ($email_options['confirmation_send'] === true) {echo 'checked';} ?> />
<label for="<?php echo esc_html($name); ?>_confirmation_cipf">envoyer une confirmation ?</label>
<input type="checkbox" id="<?php echo esc_html(stripslashes($name)); ?>_confirmation_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_confirmation_send" <?php if ($email_options['confirmation_send'] === true) {echo 'checked';} ?> />
<label for="<?php echo esc_html(stripslashes($name)); ?>_confirmation_cipf">envoyer une confirmation ?</label>
</div>
<div class="email_options_cipf">
<div class="vertical_wrapper_cipf">
<label for="<?php echo esc_html($name); ?>_confirmation_subject_cipf">sujet : </label>
<textarea id="<?php echo esc_html($name); ?>_confirmation_subject_cipf" name="<?php echo esc_html($name); ?>_confirmation_subject"><?php echo esc_html($email_options['confirmation_subject']); ?></textarea>
<label for="<?php echo esc_html(stripslashes($name)); ?>_confirmation_subject_cipf">sujet : </label>
<textarea id="<?php echo esc_html(stripslashes($name)); ?>_confirmation_subject_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_confirmation_subject"><?php echo esc_html(stripslashes($email_options['confirmation_subject'])); ?></textarea>
</div>
<div class="vertical_wrapper_cipf">
<label for="<?php echo esc_html($name); ?>_confirmation_message_cipf">message : </label>
<textarea id="<?php echo esc_html($name); ?>_confirmation_message_cipf" name="<?php echo esc_html($name); ?>_confirmation_message"><?php echo esc_html($email_options['confirmation_message']); ?></textarea>
<label for="<?php echo esc_html(stripslashes($name)); ?>_confirmation_message_cipf">message : </label>
<textarea id="<?php echo esc_html(stripslashes($name)); ?>_confirmation_message_cipf" name="<?php echo esc_html(stripslashes($name)); ?>_confirmation_message"><?php echo esc_html(stripslashes($email_options['confirmation_message'])); ?></textarea>
</div>
</div>

View File

@@ -35,12 +35,9 @@ function add_plugin_content_CIPF() {
* options
*
*/
$option_paypal_name = $option_paypal_object['_name'];
$option_paypal = Plgntls::get_option_safe($option_paypal_object);
$option_payment_name = $option_payment_object['_name'];
$option_paypal = Plgntls::get_option_safe($option_paypal_object);
$option_payment = Plgntls::get_option_safe($option_payment_object);
$option_emails_name = $option_emails_object['_name'];
$option_emails = Plgntls::get_option_safe($option_emails_object);
$option_emails = Plgntls::get_option_safe($option_emails_object);
ob_start();
include(Plgntls::root_path() . '/html/menu/cipf_menu.html');
@@ -160,88 +157,73 @@ function update_paypal_credentials_CIPF($request, $option_name, $option_data, $o
/*
* update emails
*
*/
function update_emails_settings_option_CIPF($request, $option_name, $option_data, $option_default) {
Plgntls::debug_infos();
//error_log("---");
//error_log("request: " . json_encode($request));
//error_log("option_data bedore: " . json_encode($option_data));
foreach ($option_data as $email_type => $email_options) {
//error_log("email_type: " . $email_type);
$option_data[$email_type] = update_email_by_type_CIPF($email_type, $email_options, $request);
}
//error_log("option_data after : " . json_encode($option_data));
error_log("option 2: " . json_encode($option_data['payment_success']['confirmation_message']));
Plgntls::update_option_safe($option_name, $option_data);
}
/*
* utility function to update the emails
*
*/
function update_email_by_type_CIPF($email_type, $email_options, $request) {
Plgntls::debug_infos();
//error_log("email type: " . $email_type);
/*
*
* set notification/confirmation_send to false by default,
* because the request only contains the value 'on' if checked, nothing for false
*
*/
error_log("request: " . json_encode($request));
error_log("option_data: " . json_encode($option_data));
foreach ($option_data as $email => $email_options) {
error_log("email: " . $email);
error_log("email_options: " . json_encode($email_options));
if (isset($request[$email])) {
error_log("email is set");
$email_options['notification_send'] = false;
$email_options['confirmation_send'] = false;
/*
* loop through all options to update them
*
*/
foreach ($email_options as $option => $value) {
if (!isset($request[$email_type.'_'.$option])) {
continue;
}
$new_value = $request[$email_type.'_'.$option];
if ($new_value === $value) {
continue;
}
if ($option === 'notification_send' || $option === 'confirmation_send') {
$email_options[$option] = true;
}
else {
// error_log("option: " . $option);
// error_log("- previous value: " . $value);
// error_log("- newvalue : " . $new_value);
$email_options[$option] = $new_value;
}
}
// $is_sandbox = false;
// if (!isset($request['sandbox_or_live'])) {
// return;
// }
// if ($request['sandbox_or_live'] === 'sandbox') {
// $is_sandbox = true;
// }
// else if ($request['sandbox_or_live'] === 'live') {
// $is_sandbox = false;
// }
// else {
// return;
// }
//
//
// /*
// * client id
// *
// */
// $client_id = '';
// if (!isset($request['client_id'])) {
// return;
// }
// else {
// $client_id = $request['client_id'];
// }
//
//
// /*
// * client secret
// *
// */
// $client_secret = '';
// if (!isset($request['client_secret'])) {
// return;
// }
// else {
// $client_secret = $request['client_secret'];
// }
//
//
// /*
// * update the option with new credentials
// *
// set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret);
// */
// $data = array(
// 'is_sandbox' => $is_sandbox,
// 'client_id' => $client_id,
// 'client_secret' => $client_secret,
// );
// Plgntls::update_option_safe($option_name, $data);
//error_log("email_options: " . json_encode($email_options));
error_log("option 1: " . json_encode($email_options['confirmation_message']));
return $email_options;
}
/*
'payment_success'=>[
'notification_send'=>true,
'notification_to'=>'$$__admin_email__$$',
'notification_subject'=>"paiement réussi",
'notification_message'=>"par ici la monnaie",
'confirmation_send'=>true,
'confirmation_subject'=>"paiement réussi",
'confirmation_message'=>"donne l'argent",
*/

View File

@@ -1120,6 +1120,7 @@ error_log("toggle menu: " . json_encode($option_toggle));
* it also works if the option is the name directly
*
*/
error_log("option 3: " . json_encode($option_data['payment_success']['confirmation_message']));
$option_name = self::_init_option($option);
if (false === $option_name) {
return;