<?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;
    }

  $xUserRightEditContent = 1;
  
  if ( $xUserRightEditContent )
  {
    // Content Begin
      if ( !isset($_POST['senden']) )  // Gig editieren
      {
        if (isset($_REQUEST['timestamp'])) { $Date = $_REQUEST['timestamp']; }

        else { $Date = ''; }
        $sql = "SELECT * FROM ".DB_PREFIX."news WHERE Date = '$Date'";
        $resultat = mysql_query($sql);
        while ($row = mysql_fetch_array($resultat))
        {
          extract($row);
          $Title = $Title;
          $Content = $Content;
          $Publish = $Publish;
        }
      }
      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)
      {

        // 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?submenu=admin&amp;page=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?submenu=admin&amp;page=contentEditor&amp;file='.$file.'" accept-charset="UTF-8">
      	   <table summary="AddNews">
            ';
            // Content
              if ($senden && $_POST['Content']=="")
              { echo '<tr><td></td><td class="ERROR">'.$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="self.location.href=\'index.php?submenu=cms&amp;page=pages\'" class="button" />
                <input type="hidden" name="Date" value="'.$Date.'" />
                <input type="hidden" name="http-equiv" value="../cms/pages" />
              </td>
        	   </tr>
      	   </table>
    	 </form>
        ';
      }
    // Inhalt zuende
  }
  else
  { echo $L_015; }
  }
?>