EOJ;
$aFields = array(
'Value' => 'The value stored in the database',
'LKey' => 'Primary language key used for displaying',
'LKey2' => 'Secondary language key used for displaying in some other places',
'LKey3' => 'Miscelaniuos language key used for displaying in some other places.',
'Extra' => 'Extra parameter. Used for example as link to profile image for Sex list.',
'Extra2' => 'Miscelanious extra parameter',
'Extra3' => 'Miscelanious extra parameter'
);
if( isset( $_REQUEST['popup'] ) and $_REQUEST['popup'] == 1 ) {
$iAmInPopup = true;
TopCodeAdminPopup();
PageCompPageMainCode();
BottomCodeAdminPopup();
} else {
$iAmInPopup = false;
TopCodeAdmin();
PageCompPageMainCode();
BottomCode();
}
function PageCompPageMainCode() {
global $iAmInPopup;
global $aFields;
$sPopupAdd = $iAmInPopup ? '&popup=1' : '';
if( isset( $_POST['action'] ) and $_POST['action'] == 'Save' and isset( $_POST['PreList'] ) and is_array( $_POST['PreList'] ) ) {
saveList( $_POST['list'], $_POST['PreList'] );
return;
}
//get lists
$aLists = array( '' => '- Select -' );
$sQuery = "SELECT DISTINCT `Key` FROM `PreValues`";
$rLists = db_res( $sQuery );
while( $aList = mysql_fetch_assoc( $rLists ) ) {
$aLists[ $aList['Key'] ] = $aList['Key'];
}
if( isset( $_REQUEST['list'] ) ) {
$sList_db = process_db_input( $_REQUEST['list'] );
$sList = process_pass_data( $_REQUEST['list'] );
$sQuery = "SELECT * FROM `PreValues` WHERE `Key` = '$sList_db' ORDER BY `Order`";
$rValues = db_res( $sQuery );
if( !mysql_num_rows( $rValues ) ) //if no rows returned...
$aLists[ $sList ] = $sList; //create new list
} else {
$sList = '';
}
?>
}
function genListOptions( $aLists, $sActive ) {
$sRet = '';
foreach( $aLists as $sKey => $sValue ) {
$sRet .= '
';
}
return $sRet;
}
function genListRows( $sList_db ) {
global $aFields;
$sQuery = "SELECT * FROM `PreValues` WHERE `Key` = '$sList_db' ORDER BY `Order`";
$rList = db_res( $sQuery );
?>
$iCounter = 0;
while( $aRow = mysql_fetch_assoc( $rList ) ) {
?>
foreach( $aFields as $sField => $sHelp ) {
?>
|
}
?>
|
$iCounter ++;
}
?>
return $iCounter;
}
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 . "
\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 ) {
?>
} else {
?>
}
}
function compilePreValues() {
$sQuery = "SELECT DISTINCT `Key` FROM `PreValues`";
$rKeys = db_res( $sQuery );
$rProf = @fopen( BX_DIRECTORY_PATH_INC . 'prof.inc.php', 'w' );
if( !$rProf ) {
echo 'Warning! Couldn\'t compile prof.inc.php. Please check permissions.';
return false;
}
fwrite( $rProf, "\n\$aPreValues = array(\n" );
while( $aKey = mysql_fetch_assoc( $rKeys ) ) {
$sKey = $aKey['Key'];
$sKey_db = addslashes( $sKey );
fwrite( $rProf, " '$sKey_db' => array(\n" );
$sQuery = "SELECT * FROM `PreValues` WHERE `Key` = '$sKey_db' ORDER BY `Order`";
$rRows = db_res( $sQuery );
while( $aRow = mysql_fetch_assoc( $rRows ) ) {
$sValue_db = addslashes( $aRow['Value'] );
fwrite( $rProf, " '{$sValue_db}' => array( " );
foreach( $aRow as $sValKey => $sValue ) {
if( $sValKey == 'Key' or $sValKey == 'Value' or $sValKey == 'Order' )
continue; //skip key, value and order. they already used
if( !strlen( $sValue ) )
continue; //skip empty values
fwrite( $rProf, "'$sValKey' => '" . addslashes( $sValue ) . "', " );
}
fwrite( $rProf, "),\n" );
}
fwrite( $rProf, " ),\n" );
}
fwrite( $rProf, ");\n" );
fwrite( $rProf, '
$aPreValues[\'Country\'] = sortArrByLang( $aPreValues[\'Country\'] );
function sortArrByLang( $aArr ) {
if( !function_exists( \'_t\' ) )
return $aArr;
$aSortArr = array();
foreach( $aArr as $sKey => $aValue )
$aSortArr[$sKey] = _t( $aValue[\'LKey\'] );
asort( $aSortArr );
$aNewArr = array();
foreach( $aSortArr as $sKey => $sVal )
$aNewArr[$sKey] = $aArr[$sKey];
return $aNewArr;
}
' );
fclose( $rProf );
return true;
}