function WriteConfigValue($szPropName, $is_global = true, $userid = false, $groupid = false, $bForceStripSlahes = false)
{
    global $content;
    // --- Abort in this case!
    if (GetConfigSetting("UserDBEnabled", false) == false) {
        return;
    }
    // ---
    if ($is_global) {
        if (isset($content[$szPropName])) {
            // Copy value for DB and check for BadDB Chars!
            $szDbValue = PrepareValueForDB($content[$szPropName], $bForceStripSlahes);
        } else {
            // Set empty in this case
            $szDbValue = "";
            $content[$szPropName] = "";
        }
        // Copy to $CFG array as well
        $CFG[$szPropName] = $content[$szPropName];
        // Check if we need to INSERT or UPDATE
        $result = DB_Query("SELECT propname FROM `" . DB_CONFIG . "` WHERE propname = '" . $szPropName . "' AND is_global = " . $is_global);
        $rows = DB_GetAllRows($result, true);
        if (!isset($rows)) {
            // New Entry
            if (strlen($szDbValue) < 255) {
                $result = DB_Query("INSERT INTO  `" . DB_CONFIG . "` (propname, propvalue, is_global) VALUES ( '" . $szPropName . "', '" . $szDbValue . "', " . $is_global . ")");
            } else {
                $result = DB_Query("INSERT INTO  `" . DB_CONFIG . "` (propname, propvalue_text, is_global) VALUES ( '" . $szPropName . "', '" . $szDbValue . "', " . $is_global . ")");
            }
            DB_FreeQuery($result);
        } else {
            // Update Entry
            if (strlen($szDbValue) < 255) {
                $result = DB_Query("UPDATE `" . DB_CONFIG . "` SET propvalue = '" . $szDbValue . "', propvalue_text = '' WHERE propname = '" . $szPropName . "' AND is_global = " . $is_global);
            } else {
                $result = DB_Query("UPDATE `" . DB_CONFIG . "` SET propvalue_text = '" . $szDbValue . "', propvalue = '' WHERE propname = '" . $szPropName . "' AND is_global = " . $is_global);
            }
            DB_FreeQuery($result);
        }
    } else {
        if ($userid != false) {
            global $USERCFG;
            if (isset($USERCFG[$szPropName])) {
                // Copy value for DB and check for BadDB Chars!
                $szDbValue = PrepareValueForDB($USERCFG[$szPropName], $bForceStripSlahes);
            } else {
                // Set empty in this case
                $szDbValue = "";
                $USERCFG[$szPropName] = "";
            }
            // Check if we need to INSERT or UPDATE
            $result = DB_Query("SELECT propname FROM `" . DB_CONFIG . "` WHERE propname = '" . $szPropName . "' AND userid = " . $userid);
            $rows = DB_GetAllRows($result, true);
            if (!isset($rows)) {
                // New Entry
                $result = DB_Query("INSERT INTO  `" . DB_CONFIG . "` (propname, propvalue, userid) VALUES ( '" . $szPropName . "', '" . $szDbValue . "', " . $userid . ")");
                DB_FreeQuery($result);
            } else {
                // Update Entry
                $result = DB_Query("UPDATE `" . DB_CONFIG . "` SET propvalue = '" . $szDbValue . "' WHERE propname = '" . $szPropName . "' AND userid = " . $userid);
                DB_FreeQuery($result);
            }
        } else {
            if ($groupid != false) {
                DieWithFriendlyErrorMsg("Critical Error occured in WriteConfigValue, writing GROUP specific properties is not supported yet!");
            }
        }
    }
}
function ConvertCustomSources()
{
    global $CFG, $content;
    // Insert all searches into the DB!
    foreach ($CFG['Sources'] as $sourceid => &$mySource) {
        // Correct VIEWID!
        if (isset($mySource['ViewID'])) {
            if (isset($CFG['Views'][$mySource['ViewID']]['DBID'])) {
                $mySource['ViewID'] = $CFG['Views'][$mySource['ViewID']]['DBID'];
            }
        } else {
            $mySource['ViewID'] = "";
        }
        // Set empty default
        // Add New Entry
        if ($mySource['SourceType'] == SOURCE_DISK) {
            $result = DB_Query("INSERT INTO `" . DB_SOURCES . "` (Name, Description, SourceType, MsgParserList, MsgNormalize, ViewID, LogLineType, DiskFile) VALUES ( " . "'" . PrepareValueForDB($mySource['Name']) . "', " . "'" . PrepareValueForDB($mySource['Description']) . "', " . " " . PrepareValueForDB($mySource['SourceType']) . " , " . "'" . PrepareValueForDB($mySource['MsgParserList']) . "', " . " " . PrepareValueForDB($mySource['MsgNormalize']) . " , " . "'" . PrepareValueForDB($mySource['ViewID']) . "', " . "'" . PrepareValueForDB($mySource['LogLineType']) . "', " . "'" . PrepareValueForDB($mySource['DiskFile']) . "'" . ")");
        } else {
            if ($mySource['SourceType'] == SOURCE_DB || $mySource['SourceType'] == SOURCE_PDO) {
                // Set Default for number fields
                if (!isset($mySource['DBEnableRowCounting'])) {
                    $mySource['DBEnableRowCounting'] = 0;
                } else {
                    // Force to number
                    $mySource['DBEnableRowCounting'] = intval($mySource['DBEnableRowCounting']);
                }
                if (!isset($mySource['DBType'])) {
                    $mySource['DBType'] = DB_MYSQL;
                }
                // Perform the insert
                $result = DB_Query("INSERT INTO `" . DB_SOURCES . "` (Name, Description, SourceType, MsgParserList, MsgNormalize, ViewID, DBTableType, DBType, DBServer, DBName, DBUser, DBPassword, DBTableName, DBEnableRowCounting) VALUES ( " . "'" . PrepareValueForDB($mySource['Name']) . "', " . "'" . PrepareValueForDB($mySource['Description']) . "', " . " " . PrepareValueForDB($mySource['SourceType']) . " , " . "'" . PrepareValueForDB($mySource['MsgParserList']) . "', " . " " . PrepareValueForDB($mySource['MsgNormalize']) . " , " . "'" . PrepareValueForDB($mySource['ViewID']) . "', " . "'" . PrepareValueForDB($mySource['DBTableType']) . "', " . " " . PrepareValueForDB($mySource['DBType']) . " , " . "'" . PrepareValueForDB($mySource['DBServer']) . "', " . "'" . PrepareValueForDB($mySource['DBName']) . "', " . "'" . PrepareValueForDB($mySource['DBUser']) . "', " . "'" . PrepareValueForDB($mySource['DBPassword']) . "', " . "'" . PrepareValueForDB($mySource['DBTableName']) . "', " . " " . PrepareValueForDB($mySource['DBEnableRowCounting']) . " " . ")");
            } else {
                DieWithFriendlyErrorMsg(GetAndReplaceLangStr($content['LN_CONVERT_ERROR_SOURCEIMPORT'], $mySource['SourceType']));
            }
        }
        // Copy DBID!
        $mySource['DBID'] = DB_ReturnLastInsertID($result);
        DB_FreeQuery($result);
    }
    // --- Check and set DefaultSourceID!
    if (isset($content['DefaultSourceID']) && strlen($content['DefaultSourceID']) > 0 && isset($CFG['Sources'][$content['DefaultSourceID']]['DBID'])) {
        // Copy the new DefaultSourceID back!
        $content['DefaultSourceID'] = $CFG['Sources'][$content['DefaultSourceID']]['DBID'];
        $CFG['DefaultSourceID'] = $content['DefaultSourceID'];
    }
    // ---
}