Files
2024_WEBSITE_fipf/plugins/cipf_plugin/php/admin_menu.php
2024-04-14 21:00:58 +02:00

261 lines
5.3 KiB
PHP

<?php
/*
* it means someone outside wp is accessing the file, in this case kill it.
*/
if (!defined('ABSPATH')) {
die('You can not access this file!');
}
/*
* menu plugin
*/
function cipf_plugin_menu_CIPF() {
Plgntls::debug_infos();
Plgntls::add_menu('add_plugin_content_CIPF');
}
add_action('admin_menu', 'cipf_plugin_menu_CIPF');
function add_plugin_content_CIPF() {
Plgntls::debug_infos();
$option_paypal_object = Cipf::OPTION_PAYPAL;
$option_payment_object = Cipf::OPTION_PAYMENT;
$option_emails_object = Cipf::OPTION_EMAILS;
/*
* options
*
*/
//delete_option($option_paypal_object['_name']);
$option_paypal = Plgntls::get_option_safe($option_paypal_object, true);
//delete_option($option_payment_object['_name']);
$option_payment = Plgntls::get_option_safe($option_payment_object, true);
//delete_option($option_emails_object['_name']);
$option_emails = Plgntls::get_option_safe($option_emails_object, true);
ob_start();
include(Plgntls::root_path() . '/html/menu/cipf_menu.html');
$html = ob_get_clean();
echo $html;
}
function update_payment_messages_option_CIPF($request, $option_name, $option_data, $option_default) {
Plgntls::debug_infos();
/*
* success
* failure
*
*/
$success = '';
$failure = '';
$problem = '';
if (!isset($request['message_success'])) {
return;
}
if (!isset($request['message_failure'])) {
return;
}
if (!isset($request['message_problem'])) {
return;
}
$success = $request['message_success'];
$failure = $request['message_failure'];
$problem = $request['message_problem'];
/*
* update the option with new values
*
set_payment_messages_option_CIPF($success, $failure);
*/
$data = array(
'success' => $success,
'failure' => $failure,
'problem' => $problem,
);
Plgntls::update_option_safe($option_name, $data);
}
function update_paypal_credentials_CIPF($request, $option_name, $option_data, $option_default) {
Plgntls::debug_infos();
if (!isset(
$request['sandbox_or_live'],
$request['live_client_id'],
$request['live_client_secret'],
$request['sandbox_client_id'],
$request['sandbox_client_secret'],
)) {
return;
}
/*
* force price 1 cent ?
*
*/
$force_1_cent = false;
if (isset($request['force_1_cent'])) {
$force_1_cent = true;
}
/*
* is sandbox or live ?
*
*/
$is_sandbox = false;
if ($request['sandbox_or_live'] === 'sandbox') {
$is_sandbox = true;
}
else if ($request['sandbox_or_live'] === 'live') {
$is_sandbox = false;
}
/*
* ids
*
*/
$live_client_id = $request['live_client_id'];
$live_client_secret = $request['live_client_secret'];
$sandbox_client_id = $request['sandbox_client_id'];
$sandbox_client_secret = $request['sandbox_client_secret'];
/*
* update the option with new credentials
*
set_paypal_options_CIPF($is_sandbox, $client_id, $client_secret);
*/
$data = array(
'force_1_cent' => $force_1_cent,
'is_sandbox' => $is_sandbox,
'live_client_id' => $live_client_id,
'live_client_secret' => $live_client_secret,
'sandbox_client_id' => $sandbox_client_id,
'sandbox_client_secret' => $sandbox_client_secret,
);
Plgntls::update_option_safe($option_name, $data);
}
/*
* update emails
*
*/
function update_emails_settings_option_CIPF($request, $option_name, $option_data, $option_default) {
Plgntls::debug_infos();
/*
* first check if saved option has the same data as default option
*
*/
$new_option = update_option_with_default_CIPF($option_data, $option_default);
/*
* then update the option with the request
*
*/
foreach ($new_option as $email_type => $email_options) {
$new_option[$email_type] = update_email_type_with_request_CIPF($email_type, $email_options, $request);
}
Plgntls::update_option_safe($option_name, $new_option);
}
/*
* utility
*
*/
function update_option_with_default_CIPF($option_data, $option_default) {
Plgntls::debug_infos();
$new_option_values = array();
foreach ($option_default as $email_type => $email_default_options) {
if (!isset($option_data[$email_type])) {
$new_option_values[$email_type] = $email_default_options;
}
else {
$new_email_options = update_email_type_with_default_CIPF($option_data[$email_type], $email_default_options);
$new_option_values[$email_type] = $new_email_options;
}
}
return $new_option_values;
}
function update_email_type_with_default_CIPF($email_options, $email_default_options) {
Plgntls::debug_infos();
$new_email_type = array();
foreach ($email_default_options as $default_key => $default_value) {
if (!isset($email_options[$default_key])) {
$new_email_type[$default_key] = $default_value;
}
else {
$new_email_type[$default_key] = $email_options[$default_key];
}
}
return $new_email_type;
}
function update_email_type_with_request_CIPF($email_type, $email_options, $request) {
Plgntls::debug_infos();
foreach ($email_options as $email_key => $email_value) {
/*
* special update for notification/confirmation_send
* default them to false, since they will only be in request if they value 'on'
*
*/
if (in_array($email_key, array('notification_send', 'confirmation_send'))) {
$email_options[$email_key] = 'off';
}
/*
* search in request needs the prefix
*
*/
$request_name = $email_type.'_'.$email_key;
if (isset($request[$request_name])) {
$email_options[$email_key] = $request[$request_name];
}
}
return $email_options;
}
?>