Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

set_config_option()

Description

Save/ Update config option

Parameters

ColumnTypeDefaultDescription
$user_id integer Current user ID. Use NULL for system wide config options
$param_name string Parameter name
$param_value string Parameter value

Return

boolean

Location

include/config_functions.php lines 113 to 173

Definition

 
function set_config_option($user_id$param_name$param_value)
    {
    
// We do allow for param values to be empty strings or 0 (zero)
    
if(empty($param_name) || is_null($param_value))
        {
        return 
false;
        }

    
// Prepare the value before inserting it
    
$param_value config_clean($param_value);
    
$param_value escape_check($param_value);

    
$query sprintf('
            INSERT INTO user_preferences (
                                             user,
                                             parameter,
                                             `value`
                                         )
                 VALUES (
                            %s,     # user
                            \'%s\', # parameter
                            \'%s\'  # value
                        );
        '
,
        
is_null($user_id) ? 'NULL' '\'' escape_check($user_id) . '\'',
        
escape_check($param_name),
        
$param_value
    
);
    
$current_param_value null;
    if(
get_config_option($user_id$param_name$current_param_value))
        {
        if(
$current_param_value == $param_value)
            {
            return 
true;
            }

        
$query sprintf('
                UPDATE user_preferences
                   SET `value` = \'%s\'
                 WHERE user %s
                   AND parameter = \'%s\';
            '
,
            
$param_value,
            
is_null($user_id) ? 'IS NULL' '= \'' escape_check($user_id) . '\'',
            
escape_check($param_name)
        );

        if (
is_null($user_id))        // only log activity for system changes, i.e. when user not specified
            
{
            
log_activity(nullLOG_CODE_EDITED$param_value'user_preferences''value'"parameter='" escape_check($param_name) . "'"null$current_param_value);
            }

        }

    
sql_query($query);

    
// Clear disk cache
    
clear_query_cache("preferences");

    return 
true;
    }

This article was last updated 24th November 2020 18:35 Europe/London time based on the source file dated 6th October 2020 10:25 Europe/London time.