<?php 

// session_start();

require_once("../../../config.php");
require_once("../../../app/functions.php");
// require_once("../../../app/includes/phpmailer/class.phpmailer.php");
spl_autoload_register(function($class_name) {
	$file = "../../../app/classes/class-".$class_name.".php";
	if (file_exists($file)) {
		include $file;
	}
});

require_once("../plugins.php");
$plugins = new plugins();
$plugins->load();
$session = Session::getInstance();

if ($_SERVER["REQUEST_METHOD"] == "POST") :

	if(isset($_POST['action'])){
		$response = array();
		$args = $_POST;
		unset($args['action']);
		$user = new user;
		$post = new post;
		$support = new support(['software_engineer', 'super_admin']);

		switch ($_POST['action']) {
			case 'settings':
				$live_mode = ($args['live_mode'] == 1) ? 1 : 0;
				update_option('paystack_test_sk', $args['test_sk']);
				update_option('paystack_test_pk', $args['test_pk']);
				update_option('paystack_live_sk', $args['live_sk']);
				update_option('paystack_live_pk', $args['live_pk']);
				update_option('paystack_live_mode', $live_mode);
				
				$response['msg'] = 'Settings updated successfully';
				$response['error'] = 0;
				echo json_encode($response);
				exit();
				break;

			default:
				# code...
				break;
		}
		// json_encode($response);
	}

endif;