Example #1
0
function saveList($sList, $aData)
{
    global $aFields;
    global $iAmInPopup;
    $sList_db = trim(process_db_input($sList));
    if ($sList_db == '') {
        return false;
    }
    $sQuery = "DELETE FROM `" . BX_SYS_PRE_VALUES_TABLE . "` WHERE `Key` = '{$sList_db}'";
    db_res($sQuery);
    $sValuesAlter = '';
    foreach ($aData as $iInd => $aRow) {
        $aRow['Value'] = str_replace(',', '', trim($aRow['Value']));
        if ($aRow['Value'] == '') {
            continue;
        }
        $sValuesAlter .= "'" . process_db_input($aRow['Value']) . "', ";
        $sInsFields = '';
        $sInsValues = '';
        foreach ($aFields as $sField => $sTemp) {
            $sValue = trim(process_db_input($aRow[$sField]));
            $sInsFields .= "`{$sField}`, ";
            $sInsValues .= "'{$sValue}', ";
        }
        $sInsFields = substr($sInsFields, 0, -2);
        //remove ', '
        $sInsValues = substr($sInsValues, 0, -2);
        $sQuery = "INSERT INTO `" . BX_SYS_PRE_VALUES_TABLE . "` ( `Key`, {$sInsFields}, `Order` ) VALUES ( '{$sList_db}', {$sInsValues}, {$iInd} )";
        db_res($sQuery);
    }
    //alter Profiles table
    $sValuesAlter = substr($sValuesAlter, 0, -2);
    //remove ', '
    $sQuery = "SELECT `Name` FROM `sys_profile_fields` WHERE `Type` = 'select_set' AND `Values` = '#!{$sList_db}'";
    $rFields = db_res($sQuery);
    while ($aField = mysql_fetch_assoc($rFields)) {
        $sField = $aField['Name'];
        $sQuery = "ALTER TABLE `Profiles` CHANGE `{$sField}` `{$sField}` set({$sValuesAlter}) NOT NULL default ''";
        db_res($sQuery);
    }
    compilePreValues();
    if ($iAmInPopup) {
        echo '<script type="text/javascript">window.close()</script>';
    }
    return true;
}
Example #2
0
<?php

/**
 * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
 * CC-BY License - http://creativecommons.org/licenses/by/3.0/
 */
define('BX_SYS_PRE_VALUES_TABLE', 'sys_pre_values');
$oCache = $GLOBALS['MySQL']->getDbCacheObject();
$GLOBALS['aPreValues'] = $oCache->getData($GLOBALS['MySQL']->genDbCacheKey('sys_pre_values'));
if (null === $GLOBALS['aPreValues']) {
    compilePreValues();
}
function getPreKeys()
{
    return $GLOBALS['MySQL']->fromCache('sys_prevalues_keys', 'getAll', "SELECT DISTINCT `Key` FROM `" . BX_SYS_PRE_VALUES_TABLE . "`");
}
function getPreValues($sKey, $aFields = array(), $iTagsFilter = BX_TAGS_NO_ACTION)
{
    $sqlFields = "*";
    if (is_array($aFields) && !empty($aFields)) {
        foreach ($aFields as $sValue) {
            $sqlFields .= "`{$sValue}`, ";
        }
        $sqlFields = trim($sqlFields, ', ');
    }
    $sqlQuery = "SELECT {$sqlFields} FROM `" . BX_SYS_PRE_VALUES_TABLE . "`\n                WHERE `Key` = ?\n                ORDER BY `Order` ASC";
    return $GLOBALS['MySQL']->getAllWithKey($sqlQuery, 'Value', [$sKey]);
}
function getPreValuesCount($sKey, $aFields = array(), $iTagsFilter = BX_TAGS_NO_ACTION)
{
    $sKeyDb = process_db_input($sKey, $iTagsFilter);
 /**
  * Compile all prevalues value;
  * 
  * @return boolean - true if file was compiled;
  */
 function compilePreValues()
 {
     compilePreValues();
 }
function saveList($sList, $aData)
{
    global $aFields;
    global $iAmInPopup;
    $sList_db = trim(process_db_input($sList));
    if ($sList_db == '') {
        return false;
    }
    $sQuery = "DELETE FROM `PreValues` WHERE `Key` = '{$sList_db}'";
    db_res($sQuery);
    $sValuesAlter = '';
    foreach ($aData as $iInd => $aRow) {
        $aRow['Value'] = str_replace(',', '', trim($aRow['Value']));
        if ($aRow['Value'] == '') {
            continue;
        }
        $sValuesAlter .= "'" . process_db_input($aRow['Value']) . "', ";
        $sInsFields = '';
        $sInsValues = '';
        foreach ($aFields as $sField => $sTemp) {
            $sValue = trim(process_db_input($aRow[$sField]));
            $sInsFields .= "`{$sField}`, ";
            $sInsValues .= "'{$sValue}', ";
        }
        $sInsFields = substr($sInsFields, 0, -2);
        //remove ', '
        $sInsValues = substr($sInsValues, 0, -2);
        $sQuery = "INSERT INTO `PreValues` ( `Key`, {$sInsFields}, `Order` ) VALUES ( '{$sList_db}', {$sInsValues}, {$iInd} )";
        //echo $sQuery . "<br />\n";
        db_res($sQuery);
    }
    //alter Profiles table
    $sValuesAlter = substr($sValuesAlter, 0, -2);
    //remove ', '
    $sQuery = "SELECT `Name` FROM `ProfileFields` WHERE `Type` = 'select_set' AND `Values` = '#!{$sList_db}'";
    $rFields = db_res($sQuery);
    while ($aField = mysql_fetch_assoc($rFields)) {
        $sField = $aField['Name'];
        $sQuery = "ALTER TABLE `Profiles` CHANGE `{$sField}` `{$sField}` set({$sValuesAlter}) NOT NULL default ''";
        db_res($sQuery);
    }
    compilePreValues();
    if ($iAmInPopup) {
        ?>
		<script type="text/javascript">window.close()</script>
		<?php 
    } else {
        ?>
		<div style="text-align:center;color:green;">
			Saved.
			<a href="<?php 
        echo $_SERVER['PHP_SELF'];
        ?>
?list=<?php 
        echo urlencode(process_pass_data($sList));
        ?>
">
				Return back
			</a>
		</div>
		<?php 
    }
}