<?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.
*/
  $FileName = $file;
  
  if ( !IsUserAdmin() ) { echo $L_015; }
  else
  {
    if ( isset($_POST['senden']) ) $senden = true;
    else  $senden = false;
    if ( $senden
       && ($_POST['Content']!="")
     )
    {
      $FormularKorrektAusgefuellt = true;
    }
    else
    {
      $Title = '';
      $Content = '';
      $Publish = '';
      $FormularKorrektAusgefuellt = false;
    }
    // Überschrift ausgeben
      echo '<p class="Headline">'.$L_Headline46.'</p>';

  $xUserRightEditContent = 1;
  
  if ( $xUserRightEditContent )
  {
    // Inhalt hier einfügen
      if ( !isset($_POST['senden']) )  // Gig editieren
      {
        if (isset($_REQUEST['timestamp'])) { $Date = $_REQUEST['timestamp']; }

        else { $Date = ''; }
        $SQLQuery = "SELECT * FROM ".$prefix."news WHERE Date = '$Date'";
        $Result = mysqli_query($db, $SQLQuery);
        while ($row = mysqli_fetch_array($Result))
        {
          extract($row);
          $Title = $Title;
          $Content = $Content;
          $Publish = $Publish;
        }
      }
      else
      {
        // Post-Variablen in Variablen speichern
          foreach ($_POST as $key => $value) {
            $$key = stripslashes($value); }
      }


      if ($FormularKorrektAusgefuellt == true)
      {

        // Content bearbeiten
          if ( !$datei = fopen($ContentPath."/".$FileName, "w+") )
            { echo 'ERROR: File not Found! ('.$FileName.')<br /><br />'; }
          if ( fwrite($datei, $Content) )
          {
            echo "XXX Content erfolgreich bearbeitet.<br /><br />";
          }
          else
          {
            echo "XXX Content News NICHT bearbeitet!<br /><br />";
          }
          fclose($datei);
        echo '<form method="post" action="index.php?submenue=admin&content=content" accept-charset="UTF-8">
            <fieldset>
              <input type="submit" value="'.$L_Button26.'" class="button" />
            </fieldset>
          </form>';
      }
      else
      {
        // Datei einlesen
          if ( !$datei = fopen($ContentPath."/".$FileName, 'r') )
            { echo 'ERROR: File not Found! ('.$FileName.')<br /><br />'; }
          $Content = fread($datei,10000);
          fclose($datei);
        echo '
          <form method="post" action="index.php?submenue=admin&amp;content=contentEditor&amp;file='.$file.'" accept-charset="UTF-8">
      	   <table summary="AddNews">
            ';
            // Content
              if ($senden && $_POST['Content']=="")
              { echo '<tr><td></td><td class="ErrorMessage">'.$L_170.'</td><td></td></tr>'; }

          echo '<tr>
                  <td><textarea name="Content" rows="15" cols="60" style="width:50em;">'.$Content.'</textarea></td>
                </tr>';



          // Button
          echo '
        	   <tr>
              <td>
                <input type="submit" name="senden" value="'.$L_Button01.'" class="button" />
                <input type="button" value="'.$L_Button03.'" onclick="history.go(-1)" class="button" />
                <input type="hidden" name="Date" value="'.$Date.'" />
                <input type="hidden" name="DEAKTIVIERT-http-equiv" value="showAllNews" />
              </td>
        	   </tr>
      	   </table>
    	 </form>
        ';
      }
    // Inhalt zuende
  }
  else
  { echo $L_015; }
  }
?>