<?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.
*/
  if ( isset($_POST['senden']) ) $senden = true;
  else  $senden = false;
  if ( $senden
       && ($_POST['Title']!="")
       && ($_POST['Text']!="")
       && ($_POST['Publish']!="")
     )
  {
    $FormularKorrektAusgefuellt = true;
  }
  else 
  {
    $Title = '';
    $Text = '';
    $Publish = ''; 
    $FormularKorrektAusgefuellt = false;
  }
  // Überschrift ausgeben
    if ($_REQUEST['job']=='add'){ echo '<p class="Headline">'.$L_Headline29.':</p>'; } 
    if ($_REQUEST['job']=='edit') { echo '<p class="Headline">'.$L_Headline30.':</p>'; }

  $xUserRightAddNews = getCurrentUserVar('UserRightAddNews');
  $xUserRightEditNews = getCurrentUserVar('UserRightEditNews');
  if ( $xUserRightAddNews OR $xUserRightEditNews )
  {
    // Inhalt hier einfügen
      if ( !isset($_POST['senden']) )  // Gig editieren
      {
        if (isset($_REQUEST['newsid'])) { $NewsID = $_REQUEST['newsid']; }
          else { $NewsID = ''; }
        $SQLQuery = "SELECT * FROM ".$prefix."news WHERE NewsID = '$NewsID'";
        $Result = mysqli_query($db, $SQLQuery);
        while ($row = mysqli_fetch_array($Result))
        {
          extract($row);
          $Title = $Title;
          $Text = $Text;
          $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)
      {
        include ('news/functions.php');
        // News hinzufügen
        if ($_REQUEST['job']=='add')
        {
          /// echo $Title.' '.$Text.' '.$Publish.'<br >';
          if (addNews ($Title, $Text, $Publish) )
          {
            echo $L_News_successfully_added.'<br /><br />';
          }
          else
          {
            echo '<span class="ErrorMessage">'.$L_ERROR_News_not_added.'</span><br /><br />';
          }
        }
        // News bearbeiten
        if ($_REQUEST['job']=='edit')
        {
          if (editNews ($NewsID, $Title, $Text, $Publish) )
          {
            echo $L_News_successfully_edited.'<br /><br />';
          }
          else
          {
            echo '<span class="ErrorMessage">'.$L_ERROR_News_not_edited.'</span><br /><br />';
          }
        }
        echo '
          <form method="post" action="index.php?submenue=news&content=backend_showAllNews" accept-charset="UTF-8">
            <fieldset>
              <input type="submit" value="'.$L_Button26.'" class="button" />
            </fieldset>
          </form>';
      }
      else
      {
        // Post-Variablen in Variablen speichern
          foreach ($_POST as $key => $value) $$key = stripslashes($value);
        echo '
          <form method="post" action="index.php?submenue=news&amp;content=backend_addNews&amp;job='.$_REQUEST['job'].'" accept-charset="UTF-8">
      	   <table summary="AddNews">
            ';
            // Title
              if ($senden && $_POST['Title']=="")
              { echo '<tr><td></td><td class="ErrorMessage">'.$L_169.'</td><td></td></tr>'; }
              $Title = htmlspecialchars($Title);
              echo '<tr>
                  <td align="right" valign="top">'.$L_NewsTitle.':</td>
                  <td><input type="text" name="Title" value="'.$Title.'" maxlength="'.$CharsNewsTitle.'" /></td>
                  <td valign="top">*</td>
                </tr>';
            // Text
              if ($senden && $_POST['Text']=="")
              { echo '<tr><td></td><td class="ErrorMessage">'.$L_170.'</td><td></td></tr>'; }
              $Text = htmlspecialchars($Text);
              echo '<tr>
                      <td align="right" valign="top">'.$L_NewsText.':</td>
                      <td><textarea class="ckeditor" name="Text" rows="15" cols="60" style="width:50em;">'.$Text.'</textarea></td>
                      <script>
                        CKEDITOR.replace( "Text", {
                          language: "'.$LanguageCodeISO6391.'",
                          basicEntities: false,
                          entities: false,
                          contentsCss: "includes/editor.css"});
                      </script>
                      <td valign="top">*</td>
                    </tr>';
            // Publish
              if ($senden && ($_POST['Publish']==""))
              { echo '<tr><td></td><td class="ErrorMessage">'.$L_171.'</td><td></td></tr>'; }
            echo '<tr>
                    <td align="right" valign="top">'.$L_NewsPublish.':</td>
                    <td>
                      <select name="Publish">';
            if ( $Publish=='' ) echo '<option></option>';
            echo '<option value="1" '; if ($Publish=="1") echo ' selected="selected"'; echo'>'.$L_091.'</option>
                  <option value="0" '; if ($Publish=="0") echo ' selected="selected"'; echo'>'.$L_092.'</option>
                </select>
              </td>
              <td valign="top">*</td>
            </tr>';
          // Button
          echo '
        	   <tr>
              <td></td>
              <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="NewsID" value="'.$NewsID.'" />
                <input type="hidden" name="DEAKTIVIERT-http-equiv" value="showAllNews" />
              </td>
        	   </tr>
      	   </table>
    	 </form>
        ';
      }
    // Inhalt zuende
  }
  else
  { echo $L_015; }
?>