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;
}
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;
}