<?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;
  }
  // Überschrift ausgeben
    if ($_REQUEST['job']=='add'){ echo '<p class="Headline">'.$L_Headline49.'</p>'; }
    if ($_REQUEST['job']=='addSubitem'){ echo '<p class="Headline">'.$L_Add_subitem.':</p>'; }
    if ($_REQUEST['job']=='edit') { echo '<p class="Headline">'.$L_Headline50.':</p>'; }
  $UserRightAddMenuItem = 1;
  $UserRightEditMenuItem = 1;
  if ( $UserRightAddMenuItem OR $UserRightEditMenuItem )
  {
    // Inhalt hier einfügen
      if ( !$senden AND $job=='edit' )  // MenueItem editieren
      {
        $SQLQuery = "SELECT * FROM ".$prefix."menu WHERE MenuItemID = ".$MenuItemID;
        $Result = mysqli_query($db, $SQLQuery);
        while ($row = mysqli_fetch_array($Result))
        {
          extract($row);
          $MenuItemKind = $MenuItemKind;
          $MenuItemName = $MenuItemName;
          $MenuItemFile = $MenuItemFile;
        }
      }
      else
      {
        // Post-Variablen in Variablen speichern
          foreach ($_POST as $key => $value) {
            $$key = stripslashes($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="ErrorMessage"'.$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="ErrorMessage"'.$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="ErrorMessage"'.$L_ERROR_Menu_item_not_edited."</span><br /><br />";
          }
        }
        echo '
          <form method="post" action="index.php?submenue=cms&content=menu" accept-charset="UTF-8">
            <fieldset>
              <input type="submit" value="'.$L_Button26.'" class="button" />
            </fieldset>
          </form>';
      }
      else
      {
        echo '<form method="post" action="index.php?submenue=cms&amp;content=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="ErrorMessage">'.$L_214.'</td><td></td></tr>'; }
            // MenuItemKind
              if ($senden && !$MenuItemKind )
              { echo '<tr><td></td><td class="ErrorMessage">'.$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="ErrorMessage">'.$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="ErrorMessage">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="history.go(-1)" class="button" />
              </td>
        	   </tr>
      	   </table>
    	 </form>
        ';
      }
    // Inhalt zuende
  }
  else
  { echo $L_015; }
?>