<?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.
*/
  include ('cms/functions.php');
  if ( !isset($_REQUEST['MenuItemID'])) $MenuItemID = '';
  if ( isset($senden)
       && $MenuItemKind
       && $MenuItemName
       && !doubleMenuItemPresent($MenuItemKind, $MenuItemName)
       && ($MenuItemKind!='Page' OR $MenuItemName )
     )
  { 
    $FormularKorrektAusgefuellt = true;
  }
  else 
  {
    $MenuItemKind = '';
    $MenuItemName = '';
    $MenuItemFile = '';
    $senden = '';
    $FormularKorrektAusgefuellt = false;
  }
  $UserRightAddMenuItem = 1;
  $UserRightEditMenuItem = 1;
  if ( $UserRightAddMenuItem OR $UserRightEditMenuItem )
  {
    // Content Begin
      if ( !$senden AND $job=='edit' )  // MenueItem editieren
      {
        $sql = "SELECT * FROM ".DB_PREFIX."menu WHERE MenuItemID = ".$MenuItemID;
        $resultat = mysql_query($sql);
        while ($row = mysql_fetch_array($resultat))
        {
          extract($row);
          $MenuItemKind = $MenuItemKind;
          $MenuItemName = $MenuItemName;
          $MenuItemFile = $MenuItemFile;
        }
      }
      else
      {
        // Post-Variablen in Variablen speichern
          foreach ($_POST as $key => $value)
          {
            if (get_magic_quotes_gpc()) $$key = stripslashes($value);
            else $$key = $value;
          }
      }
      if ($FormularKorrektAusgefuellt == true)
      {
        // MenuItem hinzufuegen
        if ( $job=='add' )
        {
          if (addMenuItem ($MenuItemKind, $MenuItemName, $MenuItemParent, $MenuItemFile) )
          {
            echo $L_Menu_item_successfully_added."<br /><br />";
          }
          else
          {
            echo '<span class="ERROR"'.$L_ERROR_Menu_item_not_added."</span><br /><br />";
          }
        }
        // SubItem hinzufuegen
        if ( $job=='addSubitem' )
        {
          if (addSubitem ($MenuItemID, $MenuItemKind, $MenuItemName, $MenuItemFile) )
          {
            echo $L_Menu_item_successfully_added."<br /><br />";
          }
          else
          {
            echo '<span class="ERROR"'.$L_ERROR_Menu_item_not_added."</span><br /><br />";
          }
        }
        // MenuItem bearbeiten
        if ( $job=='edit' )
        {
          if (editMenuItem ($MenuItemID, $MenuItemKind, $MenuItemName) )
          {
            echo $L_Menu_item_successfully_edited."<br /><br />";
          }
          else
          {
            echo '<span class="ERROR"'.$L_ERROR_Menu_item_not_edited."</span><br /><br />";
          }
        }
        echo '
          <form method="post" action="index.php?submenu=cms&amp;page=menu" accept-charset="UTF-8">
            <fieldset>
              <input type="submit" value="'.$L_Button26.'" class="button" />
            </fieldset>
          </form>';
      }
      else
      {
        echo '<form method="post" action="index.php?submenu=cms&amp;page=addMenuItem&amp;job='.$job.'" accept-charset="UTF-8">
      	       <table summary="AddNews">';
      	       // Item schon vorhanden
      	       
      	       if ($senden && doubleMenuItemPresent($MenuItemKind, $MenuItemName) )
                  { echo '<tr><td></td><td class="ERROR">'.$L_214.'</td><td></td></tr>'; }
            // MenuItemKind
              if ($senden && !$MenuItemKind )
              { echo '<tr><td></td><td class="ERROR">'.$L_212.'</td><td></td></tr>'; }
            echo '<tr>
                    <td align="right" valign="top">'.$L_MenuItemKind.':</td>
                    <td>
                      <select name="MenuItemKind">';
            if ( $MenuItemKind=='' ) echo '<option></option>';
            echo '<option value="Menu" '; if ($MenuItemKind=='Menu') echo ' selected="selected"'; echo'>'.$L_Menu.'</option>
                  <option value="Page" '; if ($MenuItemKind=='Page') echo ' selected="selected"'; echo'>'.$L_Page.'</option>
                  <option value="Guestbook" '; if ($MenuItemKind=='Guestbook') echo ' selected="selected"'; echo'>'.$L_Guestbook.'</option>
                  <option value="News" '; if ($MenuItemKind=='News') echo ' selected="selected"'; echo'>'.$L_News.'</option>
                  <option value="Calendar" '; if ($MenuItemKind=='Calendar') echo ' selected="selected"'; echo'>'.$L_Calendar.'</option>
                </select>
              </td>
            </tr>';
              // MenuItemName
              if ( $senden && !$MenuItemName )
              { echo '<tr><td></td><td class="ERROR">'.$L_213.'</td><td></td></tr>'; }
              echo '<tr>
                  <td align="right" valign="top">'.$L_MenuItemName.':</td>
                  <td><input type="text" name="MenuItemName" value="'.$MenuItemName.'" maxlength="'.$CharsMenuItemName.'" /></td>
                </tr>';
              // MenuItemFile
              if ( $senden && ($MenuItemKind=='Page' AND $MenuItemFile=='' ))
              { echo '<tr><td></td><td class="ERROR">x'.$L_213.'</td><td></td></tr>'; }
              echo '<tr>
                  <td align="right" valign="top">'.$L_MenuItemFile.':</td>
                  <td><input type="text" name="MenuItemFile" value="'.$MenuItemFile.'" maxlength="'.$CharsMenuItemFile.'" /></td>
                </tr>';
          // Button
          echo '
        	   <tr>
              <td></td>
              <td>
                <input type="submit" name="senden" value="'.$L_Button01.'" class="button" />
                <input type="hidden" name="MenuItemID" value="'.$MenuItemID.'" />
                <input type="hidden" name="MenuItemParent" value="'.$MenuItemParent.'" />
                <input type="button" value="'.$L_Button03.'" onclick="self.location.href=\'index.php?submenu=cms&amp;page=menu\'" class="button" />
              </td>
        	   </tr>
      	   </table>
    	 </form>';
      }
    // Inhalt zuende
  }
  else
  { echo $L_015; }
?>