<?php
/**
 * @package embed-sharepoint-onedrive-documents
 * @author miniOrange
 * @link https://plugins.miniorange.com
 */


namespace MoSharePointObjectSync\Controller;

use MoSharePointObjectSync\API\Azure;
use MoSharePointObjectSync\Wrappers\pluginConstants;
use MoSharePointObjectSync\Wrappers\sharepointWrapper;
use MoSharePointObjectSync\Wrappers\wpWrapper;
use MoSharePointObjectSync\LicenseLibrary\Mo_License_Service;
class appConfig
{
    private static $instance;
    private static $isliveri;
    public static function getController()
    {
        if (isset(self::$instance)) {
            goto AQ;
        }
        $pj = __CLASS__;
        self::$instance = new $pj();
        self::$isliveri = Mo_License_Service::is_customer_license_valid();
        AQ:
        return self::$instance;
    }
    public function mo_sps_save_settings()
    {
        $lN = sanitize_text_field($_POST["\x6f\160\164\151\x6f\156"]);
        switch ($lN) {
            case "\x6d\x6f\137\163\x70\163\137\x63\x6c\x69\x65\x6e\x74\137\143\157\x6e\x66\x69\x67\x5f\x6f\160\164\x69\157\156":
                $this->mo_sps_save_client_config();
                goto ao;
            case "\x6d\157\137\163\160\x73\137\x72\145\x6d\x6f\x76\145\x5f\143\157\156\x66\151\147\x75\x72\x65\144\137\141\x63\143\157\165\156\x74":
                $this->mo_sps_remove_configured_account();
                goto ao;
        }
        ha:
        ao:
    }
    private function mo_sps_remove_configured_account()
    {
        wpWrapper::mo_sps_delete_option(pluginConstants::TEST_CONNECTION_STATUS);
        wpWrapper::mo_sps_delete_option(pluginConstants::USER_INFO);
        wpWrapper::mo_sps_delete_option(pluginConstants::SPS_RFTK);
        wpWrapper::mo_sps_delete_option(pluginConstants::CURRENT_STATE);
        wpWrapper::mo_sps_delete_option(pluginConstants::APP_CONFIG);
        wpWrapper::mo_sps_delete_option(pluginConstants::SPSAUTHCODE);
        wpWrapper::mo_sps_delete_option(pluginConstants::USER_INFO);
        wpWrapper::mo_sps_delete_option(pluginConstants::SYNC_INTERVAL);
        wpWrapper::mo_sps_delete_option(pluginConstants::MOPKEWSFATT);
        wpWrapper::mo_sps_delete_option(pluginConstants::CRON_OPTION);
        wpWrapper::mo_sps_delete_option(pluginConstants::SC_PATH);
        wpWrapper::mo_sps_delete_option("\x6d\157\137\163\160\x73\x5f\147\145\x74\137\141\x6c\154\137\144\162\151\166\145\163");
        wpWrapper::mo_sps_delete_option("\155\x6f\137\163\x70\163\x5f\147\x65\164\x5f\141\x6c\154\x5f\x73\151\164\145\163");
        wpWrapper::mo_sps_delete_option("\155\x6f\x5f\x73\x70\x73\137\147\145\x74\137\x73\145\x6c\145\x63\x74\x65\144\x5f\163\x69\x74\145");
        wpWrapper::mo_sps_delete_option("\x6d\157\137\x73\x70\x73\137\147\x65\164\x5f\x73\x65\x6c\145\x63\164\145\x64\137\144\x72\x69\x76\145");
        wpWrapper::mo_sps_delete_option("\x6d\157\137\x73\160\163\137\x67\145\164\x5f\x73\x65\x6c\145\x63\164\145\144\x5f\x66\x6f\154\x64\x65\162");
        wpWrapper::mo_sps_delete_option("\x6d\x65\x64\151\141\137\154\x69\142\x5f\163\171\156\x63\137\x63\x6f\156\x66\151\147");
        wpWrapper::mo_sps__show_success_notice(esc_html__("\101\x63\143\x6f\165\156\164\40\x52\145\x6d\x6f\166\145\144\40\123\x75\143\x63\x65\163\x73\x66\x75\154\x6c\171\x2c\40\120\154\x65\141\x73\x65\x20\143\x6f\156\x6e\x65\143\x74\x20\166\x69\x61\x20\x61\x6e\171\x20\x6f\164\x68\x65\x72\40\141\143\x63\x6f\165\156\x74\x2e"));
    }
    private function mo_sps_check_for_empty_or_null(&$LZ, $gs)
    {
        foreach ($gs as $cD) {
            if (!(!isset($_POST[$cD]) || empty($_POST[$cD]))) {
                goto gF;
            }
            return false;
            gF:
            $LZ[$cD] = sanitize_text_field($_POST[$cD]);
            rw:
        }
        lc:
        return $LZ;
    }
    private function mo_sps_save_client_config()
    {
        check_admin_referer("\155\157\137\163\x70\163\137\143\x6c\x69\x65\156\x74\x5f\x63\157\156\146\151\x67\137\x6f\160\164\151\x6f\x6e");
        if (self::$isliveri) {
            goto OZ;
        }
        return;
        OZ:
        $Ar = ["\x63\154\151\145\x6e\x74\x5f\151\x64", "\143\x6c\151\145\156\x74\137\163\x65\x63\x72\145\x74", "\x74\145\156\x61\x6e\x74\x5f\151\x64"];
        $Z5 = [];
        if ($this->mo_sps_check_for_empty_or_null($Z5, $Ar)) {
            goto GI;
        }
        wpWrapper::mo_sps__show_error_notice(esc_html__("\111\156\160\x75\x74\40\x69\163\x20\x65\x6d\x70\164\171\x20\x6f\x72\x20\160\x72\x65\163\145\x6e\x74\x20\x69\x6e\x20\164\150\x65\x20\151\x6e\143\157\162\x72\x65\143\x74\x20\146\x6f\162\x6d\141\x74\x2e"));
        return;
        GI:
        $Z5["\163\x69\x74\145\137\165\162\154"] = isset($_POST["\163\x69\164\145\x5f\x75\162\154"]) ? $_POST["\x73\151\x74\x65\x5f\165\162\x6c"] : '';
        $Z5["\x63\154\x69\x65\156\164\x5f\x73\x65\143\x72\x65\x74"] = wpWrapper::mo_sps_encrypt_data($Z5["\143\x6c\x69\145\156\164\137\x73\x65\143\162\x65\164"], hash("\163\150\x61\x32\x35\x36", $Z5["\143\154\x69\145\x6e\x74\x5f\151\x64"]));
        wpWrapper::mo_sps_set_option(pluginConstants::APP_CONFIG, $Z5);
        wpWrapper::mo_sps__show_success_notice(esc_html__("\x53\145\164\x74\x69\x6e\147\x73\40\x53\x61\166\145\144\x20\123\x75\143\x63\145\x73\163\x66\x75\x6c\x6c\x79\x2e"));
    }
}
