function _save_config_details()
{
    $reseller_id = $_POST['resellerid'];
    $password = htmlspecialchars_decode($_POST['password']);
    $config = _get_config_details_from_db();
    if (is_array($config) && count($config) > 0) {
        if (_check_resellerclub_credentials($reseller_id, $password)) {
            $sql_update_config_details_resellerid = "UPDATE `" . RCLUB_ADDON_DB_TABLE . "` SET value = '{$reseller_id}' WHERE config = 'resellerid'";
            $update_resellerid_res = mysql_query($sql_update_config_details_resellerid);
            if ($update_resellerid_res == false) {
                throw new Exception(mysql_error());
            }
            $password = mysql_real_escape_string($password);
            $sql_update_config_details_password = "******" . RCLUB_ADDON_DB_TABLE . "` SET value = '{$password}' WHERE config = 'password'";
            $update_password_res = mysql_query($sql_update_config_details_password);
            if ($update_password_res == false) {
                throw new Exception(mysql_error());
            }
        } else {
            $message = "Incorrect credentials ( {$reseller_id}/ *** )";
            _display_error_block($message);
            return false;
        }
    } else {
        if (strlen(trim($reseller_id)) == 0 || strlen(trim($password)) == 0) {
            return false;
        } else {
            if (_check_resellerclub_credentials($reseller_id, $password)) {
                $password = mysql_real_escape_string($password);
                $sql_insert_config_details = "INSERT INTO `" . RCLUB_ADDON_DB_TABLE . "` ( config, value ) VALUES ( 'resellerid' , '{$reseller_id}'), ( 'password' , '{$password}')";
                $insert_res = mysql_query($sql_insert_config_details);
                if ($insert_res == false) {
                    throw new Exception(mysql_error());
                }
            } else {
                $message = "Invalid credentials ({$reseller_id}/ *** ) ";
                _display_error_block($message);
                return false;
            }
        }
    }
    $message = "Reseller id and password saved successfully.";
    _display_success_block($message);
    return true;
}
// AddOn Module Name
define('ADDON_MODULE_NAME', 'officialresellerclub');
// AddOn Module Path
$addon_module_file_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . ADDON_MODULE_NAME . DIRECTORY_SEPARATOR . ADDON_MODULE_NAME . '.php';
$addon_module_file_path = realpath($addon_module_file_path);
//Include AddOn Module if exists/ installed and get $resellerclub_config details
if (file_exists($addon_module_file_path)) {
    include_once $addon_module_file_path;
    try {
        $resellerclub_config = _get_config_details_from_db();
    } catch (Exception $e) {
        $resellerclub_config = array();
        _display_error_block($e->getMessage());
    }
} else {
    _display_error_block("Please install Official ResellerClub Addon Module '" . ADDON_MODULE_NAME . "' before using product provisioning module.");
}
/**
 *  Initialize OrderboxAPI object
 */
global $orderbox;
$orderbox = new orderboxapi($resellerclub_config['resellerid'], $resellerclub_config['apikey'], $resellerclub_config['enable_log'], 'rc-whmcs-resellerclubsdhosting-in');
/**
 * WHMCS provisional module core functions
 */
function resellerclubsdhostingin_ConfigOptions()
{
    global $orderbox;
    $hosting_plan_names = array();
    $active_products = $orderbox->api('GET', '/products/category-keys-mapping.json', array(), $response, 'resellerclubsdhostingin', 'configoptions');
    if (in_array('singledomainhostinglinuxin', $active_products['hosting']) || in_array('singledomainhostingwindowsin', $active_products['hosting'])) {
function _save_config_details()
{
    $reseller_id = $_POST['resellerid'];
    $apikey = htmlspecialchars_decode($_POST['apikey']);
    $enable_log = array_key_exists('enable_log', $_POST) && $_POST['enable_log'] == 1 ? 1 : 0;
    $config = _get_config_details_from_db();
    if (is_array($config) && count($config) > 0) {
        if (_check_resellerclub_credentials($reseller_id, $apikey)) {
            $sql_update_config_details_resellerid = "UPDATE `" . RCLUB_ADDON_DB_TABLE . "` SET value = '{$reseller_id}' WHERE config = 'resellerid'";
            $update_resellerid_res = mysql_query($sql_update_config_details_resellerid);
            if ($update_resellerid_res == false) {
                throw new Exception(mysql_error());
            }
            $apikey = mysql_real_escape_string($apikey);
            $sql_update_config_details_apikey = "UPDATE `" . RCLUB_ADDON_DB_TABLE . "` SET value = '{$apikey}' WHERE config = 'apikey'";
            $update_apikey_res = mysql_query($sql_update_config_details_apikey);
            if ($update_apikey_res == false) {
                throw new Exception(mysql_error());
            }
            $sql_update_config_details_log_flag = "UPDATE `" . RCLUB_ADDON_DB_TABLE . "` SET value = '{$enable_log}' WHERE config = 'enable_log'";
            $update_log_flag_res = mysql_query($sql_update_config_details_log_flag);
            if ($update_log_flag_res == false) {
                throw new Exception(mysql_error());
            }
        } else {
            $message = "Incorrect credentials for {$reseller_id}.";
            _display_error_block($message);
            return false;
        }
    } else {
        if (strlen(trim($reseller_id)) == 0 || strlen(trim($apikey)) == 0) {
            return false;
        } else {
            if (_check_resellerclub_credentials($reseller_id, $apikey)) {
                $apikey = mysql_real_escape_string($apikey);
                $sql_insert_config_details = "INSERT INTO `" . RCLUB_ADDON_DB_TABLE . "` ( config, value ) VALUES ( 'resellerid' , '{$reseller_id}'), ( 'apikey' , '{$apikey}'), ( 'enable_log' , '{$enable_log}')";
                $insert_res = mysql_query($sql_insert_config_details);
                if ($insert_res == false) {
                    throw new Exception(mysql_error());
                }
            } else {
                $message = "Invalid credentials for {$reseller_id} ";
                _display_error_block($message);
                return false;
            }
        }
    }
    $message = "Reseller details saved successfully.";
    _display_success_block($message);
    return true;
}