Location: PHPKode > scripts > GigKalender > cms/functions.php
<?php
/*
    CREATIVE COMMONS - Attribution-No Derivative Works 3.0 Germany:
    - You may not alter, transform, or build upon this work.
    - Dieses Werk darf nicht bearbeitet oder in anderer Weise verändert werden.
*/
function getNextSubItem($MenuItemID)
{
  
  global $prefix;
  
  $MenuItemName = getMenuItemVarFromID ($MenuItemID, 'MenuItemName');
  
  $sql = "SELECT * FROM ".$prefix."menu
    WHERE MenuItemParent='".$MenuItemName."' LIMIT 1";
  $resultat = mysql_query($sql);
  if ( $Array=mysql_fetch_assoc($resultat) )
  {
    return $Array['MenuItemID'];
  }
  return false;
}

function doubleMenuItemPresent ( $MenuItemKind, $MenuItemName )
{
  
  global $prefix;

  if ( $MenuItemKind AND $MenuItemName )
  {
    $sql = "SELECT count( * ) as `Anzahl` FROM ".$prefix."menu
      WHERE MenuItemKind='".$MenuItemKind."' AND MenuItemName='".$MenuItemName."'";
    $resultat = mysql_query($sql);
    $Array = mysql_fetch_array($resultat);
    if ($Array['Anzahl']==0) return false;
    else return true;
  }
  else return false;
}
function getAmountSubMenus ()
{
  
  global $prefix;

  $sql = "SELECT count( * ) as `Anzahl` FROM ".$prefix."menu WHERE MenuItemKind='Menu'";
  $resultat = mysql_query($sql);
  $Array = mysql_fetch_array($resultat);
  return $Array['Anzahl'];
}

function td ( $MenuItemParent )
{
  
  global $prefix;
  global $counter;
  global $REQUEST_URI;
  global $L_Edit_page;
  global $L_Edit_page;
  global $L_Add_subitem;
  global $UserRightDeleteMenuItem;
  global $UserRightEditMenuItem;
  global $L_009;
  global $L_010;

  $AmountSubMenus = getAmountSubMenus();
  $AmountSubMenuItems = getAmountSubMenuItems($MenuItemParent);
  for ($i=0; $i<=$AmountSubMenuItems-1; $i++)
  {
    $sql = "SELECT * FROM ".$prefix."menu WHERE MenuItemParent='".$MenuItemParent."' AND MenuItemSequence=".$i;
    $resultat = mysql_query($sql);
    $Array=mysql_fetch_assoc($resultat);
    $MenuItemID = $Array['MenuItemID'];
    $MenuItemKind = $Array['MenuItemKind'];
    $MenuItemName = $Array['MenuItemName'];
    $MenuItemSequence = $Array['MenuItemSequence'];
    $MenuItemParent = $Array['MenuItemParent'];
    $MenuItemFile = $Array['MenuItemFile'];

    echo '<tr>';
    if ( $UserRightDeleteMenuItem )
            {
              echo '<td>
                      <a href="index.php?submenu=cms&amp;page=delMenuItem&amp;MenuItemID='.$MenuItemID.'">
                        <img src="images/delete.gif" alt="'.$L_009.'" title="'.$L_009.'" /></a>
                    </td>';
            }
            if ( $UserRightEditMenuItem )
            {
              echo '<td>
                      <a href="index.php?submenu=cms&amp;page=addMenuItem&amp;job=edit&amp;MenuItemID='.$MenuItemID.'&amp;MenuItemParent='.$MenuItemParent.'">
                        <img src="images/edit.png" alt="'.$L_010.'" title="'.$L_010.'" /></a>
                    </td>';
            }
    echo '<td>';
    for ($j=1; $j<=$counter; $j++)
    {
      if ( $j==$counter ) echo '<img src="images/cms_menu_sub.gif" alt="" title="" />&nbsp;';
      else echo '<img src="images/blank.gif" alt="" title="" />&nbsp;';
    }
    echo $MenuItemName.'</td>';
    echo '<td>';
    if ( $MenuItemKind=='Menu' )
      echo '<a href="index.php?submenu=cms&amp;page=addMenuItem&amp;job=add&amp;MenuItemID='.$MenuItemID.'&amp;MenuItemParent='.$MenuItemName.'">
              <img src="images/cms_menu_add.gif" alt="'.$L_Add_subitem.'" title="'.$L_Add_subitem.'" /></a>';
    if ( $MenuItemKind=='Page' )
      echo '<a href="index.php?submenu=cms&amp;page=addPage&amp;file=addSubitem">
              <img src="images/cms_pages.gif" alt="'.$L_Edit_page.'" title="'.$L_Edit_page.'" /></a>';
    echo '</td>';
    echo '<td>'.$MenuItemID.'</td>';
    echo '<td>'.$MenuItemKind.'</td>';
    echo '<td>'.$MenuItemSequence.'</td>';
    echo '<td>'.$MenuItemParent.'</td>';
    echo '<td>'.$MenuItemFile.'</td>';
    echo '<td>';
    // Icon zum höher setzen
    if ( $MenuItemSequence!=0 )
    {
      echo '<form style="display:inline" method="post" action="'.$REQUEST_URI.'">
              <fieldset style="display:inline">
                <input type="hidden" name="MenuItemSequence" value="'.$MenuItemSequence.'" />
                <input type="hidden" name="MenuItemParent" value="'.$MenuItemParent.'" />
                <input title="" name="MenuItemUp" src="images/up.gif" style="border:0; width:16px;" type="image" value="'.$MenuItemSequence.'" />
              </fieldset>
            </form>';
    }
    echo '</td>';
    echo '<td>';
    // Icon zum tiefer setzen
    if ( $MenuItemSequence<$AmountSubMenuItems-1 )
    {
      echo '<form style="display:inline" method="post" action="'.$REQUEST_URI.'">
              <fieldset style="display:inline">
                <input type="hidden" name="MenuItemSequence" value="'.$MenuItemSequence.'" />
                <input type="hidden" name="MenuItemParent" value="'.$MenuItemParent.'" />
                <input title="" name="MenuItemDown" src="images/down.gif" style="border:0; width:16px;" type="image" value="'.$MenuItemSequence.'" />
              </fieldset>
            </form>';
    }
    echo '</td>';
    echo '</tr>';
    if ($MenuItemKind=='Menu') { $counter++; td($MenuItemName);$counter--;  }
    if ($MenuItemParent=='main') $counter=0;
  }
}

function addSubitem ($MenuItemID, $MenuItem, $MenuItemName)
{
  
  global $prefix;

  echo $MenuItemID.'<br />';
  echo $MenuItem.'<br />';
  echo $MenuItemName.'<br />';

  return true;
}
function moveDownMenuItem ($MenuItemSequence, $MenuItemParent)
{
  
  global $prefix;

  $sql = "UPDATE ".$prefix."menu SET MenuItemSequence = -1 WHERE MenuItemSequence=".$MenuItemSequence."+1 AND MenuItemParent='".$MenuItemParent."' LIMIT 1";
  $resultat = mysql_query($sql);
  if ($resultat)
  {
    $sql = "UPDATE ".$prefix."menu SET MenuItemSequence = MenuItemSequence+1 WHERE MenuItemSequence=".$MenuItemSequence." AND MenuItemParent='".$MenuItemParent."' LIMIT 1";
    $resultat = mysql_query($sql);
    if ($resultat)
    {
      $sql = "UPDATE ".$prefix."menu SET MenuItemSequence = ".$MenuItemSequence." WHERE MenuItemSequence=-1 AND MenuItemParent='".$MenuItemParent."' LIMIT 1";
      $resultat = mysql_query($sql);
      if ($resultat)
      {
        return true;
      }
      else return false;
    }
    else return false;
  }
  else return false;
}

function moveUpMenuItem ($MenuItemSequence, $MenuItemParent)
{
  
  global $prefix;

  $sql = "UPDATE ".$prefix."menu SET MenuItemSequence = -1 WHERE MenuItemSequence=".$MenuItemSequence."-1 AND MenuItemParent='".$MenuItemParent."' LIMIT 1";
  $resultat = mysql_query($sql);
  if ($resultat)
  {
    $sql = "UPDATE ".$prefix."menu SET MenuItemSequence = MenuItemSequence-1 WHERE MenuItemSequence=".$MenuItemSequence." AND MenuItemParent='".$MenuItemParent."' LIMIT 1";
    $resultat = mysql_query($sql);
    if ($resultat)
    {
      $sql = "UPDATE ".$prefix."menu SET MenuItemSequence = ".$MenuItemSequence." WHERE MenuItemSequence=-1 AND MenuItemParent='".$MenuItemParent."' LIMIT 1";
      $resultat = mysql_query($sql);
      if ($resultat)
      {
        return true;
      }
      else return false;
    }
    else return false;
  }
  else return false;
}

function getMenuItemVarFromID ($MenuItemID, $Var)
{
  
  global $prefix;

  $SQL = "SELECT ".$Var." FROM ".$prefix."menu
    WHERE MenuItemID='".$MenuItemID."' LIMIT 1";
  $result = mysql_query($SQL);
  if ( mysql_num_rows($result)==1)
  {
    $temp=mysql_fetch_assoc($result);
    return $temp[$Var];
  }
  else return false;
}
function del ( $MenuItemID )
{
  global $prefix;
  
  
  $currentSequence = getMenuItemVarFromID($MenuItemID, 'MenuItemSequence');
  $MenuItemParent = getMenuItemVarFromID($MenuItemID, 'MenuItemParent');
  $sql = "DELETE FROM ".$prefix."menu WHERE MenuItemID = '$MenuItemID'";
  echo $MenuItemParent;
  $resultat = mysql_query($sql);
  if ($resultat)
  {
    // Dekrementieren
    $sql = "UPDATE ".$prefix."menu SET
      MenuItemSequence = MenuItemSequence-1
      WHERE MenuItemSequence>".$currentSequence."
        AND MenuItemParent='".$MenuItemParent."'";
    echo $sql.'<br />';
    $resultat = mysql_query($sql);
    if ($resultat) return true;
    else return false;
  }
  else return false;
}
function delMenuItem ( $MenuItemID )
{
  $MenuItemName = getMenuItemVarFromID($MenuItemID, 'MenuItemName');
  $AmountSubMenuItems = getAmountSubMenuItems($MenuItemName);
  for ($i=1; $i<=$AmountSubMenuItems; $i++)
  {
    $NextSubItem = getNextSubItem($MenuItemID);
    $MenuItemKind = getMenuItemVarFromID($NextSubItem, 'MenuItemKind');
    echo $NextSubItem.$MenuItemKind.'<br />';
    if ( $MenuItemKind=='Menu' )
    {
      delMenuItem ( $NextSubItem );
      del($NextSubItem);
    }
    else del($NextSubItem);
  }
  del($MenuItemID);
}

function editMenuItem ( $MenuItemID, $MenuItemKind, $MenuItemName, $MenuItemFile )
{
  global $prefix;
  

  // HTML-Tags entfernen
  $MenuItemName = strip_tags($MenuItemName);
  $MenuItemFile = strip_tags($MenuItemFile);
  // Sonderzeichen umwandeln
  $MenuItemName = htmlspecialchars($MenuItemName, ENT_QUOTES);

  $currentMenuItemName = getMenuItemVarFromID($MenuItemID, 'MenuItemName');

  $sql = "UPDATE ".$prefix."menu SET
    MenuItemKind = '".$MenuItemKind."',
    MenuItemName = '".$MenuItemName."',
    MenuItemFile = '".$MenuItemFile."'
    WHERE MenuItemID = '".$MenuItemID."'
    LIMIT 1";
  $resultat = mysql_query($sql);
  if ($resultat)
  {
    if ( $MenuItemKind=='Menu' )
    {
      $sql = "UPDATE ".$prefix."menu SET
        MenuItemParent = '".$MenuItemName."',
        MenuItemFile = '".$MenuItemFile."'
        WHERE MenuItemParent = '".$currentMenuItemName."'
        LIMIT 1";
      $resultat = mysql_query($sql);
      if ($resultat) return true;
      else return false;
    }
    return true;
  }
  else return false;
}

function addMenuItem ( $MenuItemKind, $MenuItemName, $MenuItemParent, $MenuItemFile )
  {
    global $prefix;
    
    // HTML-Tags entfernen
    $MenuItemName = strip_tags($MenuItemName);
    $MenuItemFile = strip_tags($MenuItemFile);
    // Sonderzeichen umwandeln
    $MenuItemName = htmlspecialchars($MenuItemName, ENT_QUOTES);
    $MenuItemSequence = getAmountSubMenuItems($MenuItemParent);
    // Leere numerische Variablen als NULL definieren
      if ( $MenuItemSequence=='' ) $MenuItemSequence="NULL";
    $sql = "INSERT INTO ".$prefix."menu (MenuItemKind, MenuItemName, MenuItemSequence, MenuItemParent, MenuItemFile)
      VALUES ( '$MenuItemKind', '$MenuItemName', $MenuItemSequence, '$MenuItemParent', '$MenuItemFile' )";
    $resultat = mysql_query($sql);
    if ($resultat)
    {
      return true;
    }
    else return false;
}

function getAmountSubMenuItems ($MenuItemParent)
  {
    global $prefix;
    

    $sql = "SELECT count(*) as zahl FROM ".$prefix."menu WHERE MenuItemParent='".$MenuItemParent."'";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    return $row['zahl'];
  }

function getAmountMenuItems ()
  {
    global $prefix;
    

    $sql = "SELECT count(*) as zahl FROM ".$prefix."menu";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    return $row['zahl'];
  }
?>
Return current item: GigKalender