1000 )
{
$id = $id - 1000;
db_res( "DELETE FROM `AdminMenuCateg` WHERE `ID`=$id" );
echo mysql_affected_rows();
}
else
echo 1;
exit;
case 'save_item':
$id = (int)$_GET['id'];
if( !$id )
{
echoMenuEditMsg( 'Error', 'red' );
exit;
}
if( $id < 1000 )
{
$aItemFields = array( 'Title', 'Url', 'Desc', 'Check', 'Icon' );
$aItem = array();
foreach( $aItemFields as $field )
$aItem[$field] = $_GET[$field];
$res = saveItemCustom( $id, $aItem );
echo $res;
}
else
{
$id = $id - 1000;
$aItemFields = array( 'Title', 'Icon', 'Icon_thumb', 'User' );
$aItem = array();
foreach( $aItemFields as $field )
$aItem[$field] = $_GET[$field];
$res = saveItemTop( $id, $aItem );
echo $res;
}
exit;
case 'delete_item':
$id = (int)$_GET['id'];
if( !$id )
{
echo 'Item ID is not specified';
exit;
}
if( $id > 1000 )
{
$id = $id - 1000;
db_res( "DELETE FROM `AdminMenuCateg` WHERE `ID` = $id" );
}
else
{
db_res( "DELETE FROM `AdminMenu` WHERE `ID` = $id" );
}
if( mysql_affected_rows() )
echo 'OK';
else
echo 'Couldn\'t delete the item';
exit;
case 'save_orders':
$sTop = $_GET['top'];
$aCustom = $_GET['custom'];
saveOrders( $sTop, $aCustom );
echo 'OK';
exit;
}
}
$sTopQuery = "SELECT `ID`, `Title` FROM `AdminMenuCateg` ORDER BY `User`, `Order`";
$rTopItems = db_res( $sTopQuery );
$sAllQuery = "SELECT `ID`, `Title` FROM `AdminMenu`";
$rAllItems = db_res( $sAllQuery );
$sAllTopQuery = "SELECT `ID`, `Title` FROM `AdminMenuCateg`";
$rAllTopItems = db_res( $sAllTopQuery );
$sComposerInit = "
";
$_page['extraCodeInHead'] = <<
EOJ;
$_page['extraCodeInBody'] = <<
EOJ;
TopCodeAdmin();
?>
BottomCode();
function showEditFormCustom( $aItem )
{
?>
}
function showEditFormTop( $aItem )
{
?>
}
function createNewElement( $type, $source )
{
if( $source )
{
if( $type == 'top' and $source > 1000 )
{
$source = $source - 1000;
db_res( "
INSERT INTO `AdminMenuCateg`
( `Title`, `Icon`, `Icon`, `Icon_thumb`, `User` )
SELECT
`Title`, `Icon`, `Icon`, `Icon_thumb`, `User`
FROM `AdminMenuCateg`
WHERE `ID` = $source
" );
$newID = mysql_insert_id();
}
elseif( $type == 'custom' and $source < 1000 )
{
$aItem = db_res( "SELECT * FROM `AdminMenu` WHERE `ID` = $source" );
if( $aItem['Categ'] == 0 )
$newID = $source;
else
{
db_res( "
INSERT INTO `AdminMenu`
( `Title`, `Url`, `Desc`, `Check`, `Icon` )
SELECT
`Title`, `Url`, `Desc`, `Check`, `Icon`
FROM `AdminMenu`
WHERE `ID` = $source
" );
$newID = mysql_insert_id();
}
}
elseif( $type == 'custom' and $source > 1000 )
{
$source = $source - 1000;
db_res( "
INSERT INTO `AdminMenu`
( `Title` )
SELECT
`Title`
FROM `AdminMenuCateg`
WHERE `ID` = $source
" );
$newID = mysql_insert_id();
}
elseif( $type == 'top' and $source < 1000 )
{
db_res( "
INSERT INTO `AdminMenuCateg`
( `Title` )
SELECT
`Title`
FROM `AdminMenu`
WHERE `ID` = $source
" );
$newID = mysql_insert_id();
}
}
else
{
if( $type == 'top' )
db_res( "INSERT INTO `AdminMenuCateg` SET `Title` = 'NEW ITEM'" );
elseif( $type == 'custom' )
db_res( "INSERT INTO `AdminMenu` SET `Title` = 'NEW ITEM'" );
$newID = mysql_insert_id();
}
return $newID;
}
function echoMenuEditMsg( $text, $color = 'black' )
{
?>
= $text ?>
}
function saveItemCustom( $id, $aItem )
{
$aOldItem = db_arr( "SELECT * FROM `AdminMenu` WHERE `ID`=$id" );
if( !$aOldItem )
return echoMenuEditMsg( 'Error. Item not found', 'red' );
$sQuerySet = '';
foreach( $aItem as $field => $value )
$sQuerySet .= ", `$field`='" . process_db_input( $value ) ."'";
$sQuerySet = substr( $sQuerySet, 1 );
$sQuery = "UPDATE `AdminMenu` SET $sQuerySet WHERE `ID` = $id";
db_res( $sQuery );
$ret = echoMenuEditMsg( 'Save succesfull', 'green' );
$ret .= '';
return $ret;
}
function saveItemTop( $id, $aItem )
{
$aOldItem = db_arr( "SELECT * FROM `AdminMenuCateg` WHERE `ID`=$id" );
if( !$aOldItem )
return echoMenuEditMsg( 'Error. Item not found', 'red' );
$sQuerySet = '';
foreach( $aItem as $field => $value )
$sQuerySet .= ", `$field`='" . process_db_input( $value ) ."'";
$sQuerySet = substr( $sQuerySet, 1 );
$sQuery = "UPDATE `AdminMenuCateg` SET $sQuerySet WHERE `ID` = $id";
$res .= $sQuery;
db_res( $sQuery );
$ret = echoMenuEditMsg( 'Save succesfull', 'green' );
$ret .= '';
return $ret;
}
function saveOrders( $sTop, $aCustom )
{
db_res( "UPDATE `AdminMenuCateg` SET `Order` = 0" );
db_res( "UPDATE `AdminMenu` SET `Order` = 0, `Categ` = 0" );
$sTop = trim( $sTop, ' ,' );
$aTopIDs = explode( ',', $sTop );
foreach( $aTopIDs as $iOrd => $iID )
{
$iID = trim( $iID, ' ,' );
$iID = (int)$iID;
if( !$iID )
continue;
$iID = $iID - 1000;
db_res( "UPDATE `AdminMenuCateg` SET `Order` = $iOrd WHERE `ID` = $iID" );
}
foreach( $aCustom as $iParent => $sCustom )
{
$iParent = (int)$iParent;
$iParent = $iParent - 1000;
$sCustom = trim( $sCustom, ' ,' );
$aCustomIDs = explode( ',', $sCustom );
foreach( $aCustomIDs as $iOrd => $iID )
{
$iID = trim( $iID, ' ,' );
$iID = (int)$iID;
if( !$iID )
continue;
db_res( "UPDATE `AdminMenu` SET `Order` = $iOrd, `Categ`=$iParent WHERE `ID` = $iID" );
}
}
}
?>