compile();
exit;
case 'save_item':
$id = (int)$_GET['id'];
if( !$id )
{
echoMenuEditMsg( 'Error', 'red' );
exit;
}
$aItemFields = array( 'Name', 'Caption', 'Link', 'Target' );
$aItem = array();
foreach( $aItemFields as $field )
$aItem[$field] = $_GET[$field];
$aVis = array();
if( (int)$_GET['Visible_non'] )
$aVis[] = 'non';
if( (int)$_GET['Visible_memb'] )
$aVis[] = 'memb';
$aItem['Visible'] = implode( ',', $aVis );
$res = saveItem( $id, $aItem );
updateLangFile( $_GET['Caption'], $_GET['LangCaption'] );
echo $res;
exit;
case 'delete_item':
$id = (int)$_GET['id'];
if( !$id )
{
echo 'Item ID is not specified';
exit;
}
$aItem = db_arr( "SELECT `Deletable` FROM `TopMenu` WHERE `ID` = $id" );
if( !$aItem )
{
echo 'Item not found';
exit;
}
if( !(int)$aItem['Deletable'] )
{
echo 'Item is non-deletable';
exit;
}
db_res( "DELETE FROM `TopMenu` WHERE `ID` = $id" );
if( mysql_affected_rows() )
echo 'OK';
else
echo 'Couldn\'t delete the item';
$oMenu -> compile();
exit;
case 'save_orders':
$sTop = $_GET['top'];
$aCustom = $_GET['custom'];
saveOrders( $sTop, $aCustom );
echo 'OK';
exit;
}
}
$sTopQuery = "SELECT `ID`, `Name` FROM `TopMenu` WHERE `Active`=1 AND `Type`='top' ORDER BY `Order`";
$rTopItems = db_res( $sTopQuery );
$sSysQuery = "SELECT `ID`, `Name` FROM `TopMenu` WHERE `Active`=1 AND `Type`='system' ORDER BY `Order`";
$rSysItems = db_res( $sSysQuery );
$sAllQuery = "SELECT `ID`, `Name` FROM `TopMenu` WHERE `Type`!='system'";
$rAllItems = db_res( $sAllQuery );
$sComposerInit = "
";
$_page['extraCodeInHead'] = <<
EOJ;
$_page['extraCodeInBody'] = <<
EOJ;
TopCodeAdmin();
?>
BottomCode();
function showEditForm( $aItem )
{
if( !$aItem['Editable'] )
$disabled = 'disabled="disabled"';
else
$disabled = '';
?>
}
function createNewElement( $type, $source )
{
global $oMenu;
if( $source )
{
$sourceActive = db_value( "SELECT `Active` FROM `TopMenu` WHERE `ID`=$source" );
if( !$sourceActive )
{
//convert to active
db_res( "UPDATE `TopMenu` SET `Active`=1, `Type`='$type' WHERE `ID`=$source" );
$newID = $source;
}
else
{
//create from source
db_res( "INSERT INTO `TopMenu`
( `Name`, `Caption`, `Link`, `Visible`, `Target`, `Onclick`, `Check`, `Type` )
SELECT
`Name`, `Caption`, `Link`, `Visible`, `Target`, `Onclick`, `Check`, '$type'
FROM `TopMenu`
WHERE `ID`=$source" );
$newID = mysql_insert_id();
}
}
else
{
//create new
db_res( "INSERT INTO `TopMenu` ( `Name`, `Type` ) VALUES ( 'NEW ITEM', '$type' )" );
$newID = mysql_insert_id();
}
$oMenu -> compile();
return $newID;
}
function echoMenuEditMsg( $text, $color = 'black' )
{
?>
= $text ?>
}
function saveItem( $id, $aItem )
{
global $oMenu;
$aOldItem = db_arr( "SELECT * FROM `TopMenu` WHERE `ID`=$id" );
if( !$aOldItem )
return echoMenuEditMsg( 'Error. Item not found', 'red' );
if( !(bool)(int)$aOldItem['Editable'] )
return echoMenuEditMsg( 'Error. Item is non-editable', 'red' );
$sQuerySet = '';
foreach( $aItem as $field => $value )
$sQuerySet .= ", `$field`='" . process_db_input( $value ) ."'";
$sQuerySet = substr( $sQuerySet, 1 );
$sQuery = "UPDATE `TopMenu` SET $sQuerySet WHERE `ID` = $id";
db_res( $sQuery );
$oMenu -> compile();
$ret = echoMenuEditMsg( 'Saved', 'green' );
$ret .= '';
return $ret;
}
function updateLangFile( $key, $string )
{
$langName = getParam( 'lang_default' );
$langID = db_value( "SELECT `ID` FROM `LocalizationLanguages` WHERE `Name` = '" . addslashes( $langName ) . "'" );
$keyID = db_value( "SELECT `ID` FROM `LocalizationKeys` WHERE `Key` = '" . process_db_input( $key ) . "'" );
if( $keyID )
{
db_res( "UPDATE `LocalizationStrings` SET `String` = '" .process_db_input( $string ) . "' WHERE `IDKey`=$keyID AND `IDLanguage`=$langID" );
}
else
{
db_res( "INSERT INTO `LocalizationKeys` SET `IDCategory` = 2, `Key` = '" . process_db_input( $key ) . "'" );
db_res( "INSERT INTO `LocalizationStrings` SET `IDKey` = " . mysql_insert_id() . ", `IDLanguage` = $langID, `String` = '" .process_db_input( $string ) . "'" );
}
compileLanguage($langID);
}
function saveOrders( $sTop, $aCustom )
{
global $oMenu;
db_res( "UPDATE `TopMenu` SET `Order` = 0, `Parent` = 0" );
$sTop = trim( $sTop, ' ,' );
$aTopIDs = explode( ',', $sTop );
foreach( $aTopIDs as $iOrd => $iID )
{
$iID = trim( $iID, ' ,' );
$iID = (int)$iID;
if( !$iID )
continue;
db_res( "UPDATE `TopMenu` SET `Order` = $iOrd, `Type` = 'top' WHERE `ID` = $iID" );
}
foreach( $aCustom as $iParent => $sCustom )
{
$iParent = (int)$iParent;
$sCustom = trim( $sCustom, ' ,' );
$aCustomIDs = explode( ',', $sCustom );
foreach( $aCustomIDs as $iOrd => $iID )
{
$iID = trim( $iID, ' ,' );
$iID = (int)$iID;
if( !$iID )
continue;
db_res( "UPDATE `TopMenu` SET `Order` = $iOrd, `Type` = 'custom', `Parent`=$iParent WHERE `ID` = $iID" );
}
}
$oMenu -> compile();
}