<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* Original Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)   */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2005 by Philippe Brunier   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
if (!function_exists("Mysql_Connexion")) {include ("mainfile.php");}
include ("publication.php");

if ($mod_admin_news>0) {
   if ($admin=="" and $user=="") {
      Header("Location: index.php");
      exit;
   }
   if ($mod_admin_news==1) {
      if ($user!="" and $admin=="") {
         global $cookie;
         $result = mysql_query("select level from users_status where uid='$cookie[0]'");
         if (mysql_num_rows($result)==1) {
            list($userlevel) = mysql_fetch_row($result);
            if ($userlevel==1) {
               Header("Location: index.php");
               exit;
            }
         }
      }
   }
}

function defaultDisplay() {
   include ('header.php');
   global $user, $anonymous;
   OpenTable();
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
   echo translate("Submit News");
   echo "</td></tr></table>\n";
   echo "<br />";
   if (isset($user)) $userinfo=getusrinfo($user);
   echo "<form action=\"submit.php\" method=\"post\" name=\"adminForm\">"
        ."<b>".translate("Your Name")."</b> : ";
   if ($user) {
      echo "<a href=\"user.php\" class=\"NOIR\">$userinfo[name]</a> [ <a href=\"user.php?op=logout\" class=\"ROUGE\">".translate("Logout")."</a> ]";
      echo "<input type=\"hidden\" name=\"name\" value=\"$userinfo[name]\">";
   } else {
      echo "$anonymous [ <a href=\"user.php\" class=\"NOIR\">".translate("New User")."</a> ]";
      echo "<input type=\"hidden\" name=\"name\" value=\"$anonymous\">";
   }
   echo "<br /><br /><b>".translate("Title")." </b> (".translate ("Be Descriptive, Clear and Simple").") : ";
   echo "<input class=\"TEXTBOX_STANDARD\" type=\"text\" name=\"subject\" size=\"55\" maxlength=\"255\"> ".translate("bad titles='Check This Out!' or 'An Article'.");
   echo "<br /><br /><b>".translate("Topic")."</b> : <select class=\"TEXTBOX_STANDARD\" name=\"topic\">";
   $toplist = mysql_query("select topicid, topictext from topics order by topictext");
   echo "<option value=\"\">".translate("Select Topic")."</option>\n";
   while (list($topicid, $topics) = mysql_fetch_row($toplist)) {
      if ($topicid==$topic) { $sel = "selected "; }
      echo "<option $sel value=\"$topicid\">".aff_langue($topics)."</option>\n";
      $sel = "";
   }
   echo "</select><br /><br />";
   echo "<b>".translate("Intro Text")."</b> ( ".translate("HTML is fine, but double check those URLs and HTML tags!")." ) :<br />";
   echo "<textarea class=\"textbox\" wrap=\"virtual\" cols=\"70\" rows=\"25\" name=\"story\" style=\"width: 100%;\"></textarea>";
   echo aff_editeur("story", "true");
   echo "<br /><br /><b>".translate("Full Text")."</b> :<br />";
   echo "<textarea class=\"textbox\" wrap=\"virtual\" cols=\"70\" rows=\"25\" name=\"bodytext\" style=\"width: 100%;\"></textarea>";
   echo aff_editeur("bodytext", "true");

   publication(0,0,0,0,0, 0,0,0,0,0, 0);

   echo "<br />&nbsp;(".translate("Are you sure you included a URL? Did you test them for typos?").")";
   echo "<br /><br /><input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"op\" value=\"".translate("Preview")."\"> -";
   echo translate("You must preview once before you can submit");
   echo "</form>";

   CloseTable();
   include ('footer.php');
}

function PreviewStory($name, $subject, $story, $bodytext,$topic, $deb_day,$deb_month,$deb_year,$deb_hour,$deb_min, $fin_day,$fin_month,$fin_year,$fin_hour,$fin_min, $epur) {
   global $tipath;
   include ('header.php');
   $subject = stripslashes(str_replace("\"","&quot;",(check_html($subject, "nohtml"))));
   $story = stripslashes($story);
   $bodytext = stripslashes($bodytext);
   OpenTable();
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
   echo translate("Submit News");
   echo "</td></tr></table>\n";
   echo "<form action=\"submit.php\" method=\"post\" name=\"adminForm\">"
        ."<b>".translate("Your Name")."</b> : $name";
   echo "<input type=\"hidden\" name=\"name\" value=\"$name\">";
   echo "<br /><p align=\"center\">";
   $rowcolor = tablos();
   echo "<table border=\"0\" width=\"85%\" cellpadding=\"0\" cellspacing=\"1\"><tr $rowcolor><td>";
   $rowcolor = tablos();
   echo "<table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"1\"><tr $rowcolor>";
   if ($topic=="") {
      $topicimage="all-topics.gif";
      $warning = "<br /><p align=\"center\" class=\"ROUGE\"><b>".translate("Select Topic")."</b></p>";
   } else {
      $warning = "";
      $result = mysql_query("select topictext, topicimage from topics where topicid='$topic'");
      list($topictext, $topicimage) = mysql_fetch_row($result);
   }
   $no_img=false;
   if ((file_exists("$tipath$topicimage")) and ($topicimage!="")) {
      echo "<td><img src=\"".$tipath.$topicimage."\" border=\"0\" align=\"right\" alt=\"\" />";
   } else {
      echo "<td>";
      $no_img=true;
   }

   $storyX=aff_code($story);
   $bodytextX=aff_code($bodytext);
   themepreview($subject, $storyX, $bodytextX);

   if ($no_img) {
      echo "</td><td width=\"10%\" align=\"center\" valign=\"center\"><b>".aff_langue($topictext)."</b>";
   }
   echo "$warning";
   echo "</td></tr></table></td></tr></table></p>";

   echo "<br /><b>".translate("Title")."</b>&nbsp;:&nbsp;&nbsp;";
   echo "<input class=\"TEXTBOX_STANDARD\" type=\"text\" name=\"subject\" size=\"70\" maxlength=\"255\" value=\"$subject\"><br /><br />";
   echo "<b>".translate("Topic")."</b> : <select class=\"TEXTBOX_STANDARD\" name=\"topic\">";
   $toplist = mysql_query("select topicid, topictext from topics order by topictext");
   echo "<option value=\"\">".translate("Select Topic")."</option>\n";
   while (list($topicid, $topics) = mysql_fetch_row($toplist)) {
      if ($topicid==$topic) { $sel = "selected "; }
      echo "<option $sel value=\"$topicid\">".aff_langue($topics)."</option>\n";
      $sel = "";
   }
   echo "</select><br /><br />";
   echo "<b>".translate("Intro Text")."</b> ( ".translate("HTML is fine, but double check those URLs and HTML tags!")." ) :<br />";
   echo "<textarea class=\"textbox\" wrap=\"virtual\" cols=\"70\" rows=\"25\" name=\"story\" style=\"width: 100%;\">$story</textarea>";
   echo aff_editeur("story", "true");
   echo "<br /><br /><b>".translate("Full Text")."</b> :<br />";
   echo "<textarea class=\"textbox\" wrap=\"virtual\" cols=\"$max_car\" rows=\"25\" name=\"bodytext\" style=\"width: 100%;\">$bodytext</textarea>";
   echo aff_editeur("bodytext", "true");

   publication($deb_day,$deb_month,$deb_year,$deb_hour,$deb_min, $fin_day,$fin_month,$fin_year,$fin_hour,$fin_min, $epur);

   echo "<br />(".translate("Are you sure you included a URL? Did you test them for typos?").") ";
   echo "<input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"op\" value=\"".translate("Preview")."\"> - <input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"op\" value=\"Ok\"></form>";
   closetable();
   include ('footer.php');
}

function submitStory($subject, $story, $bodytext, $topic, $date_debval,$date_finval,$epur) {
   global $user, $EditedMessage, $anonymous, $notify;
   if ($user) {
      global $cookie;
      $uid = $cookie[0];
      $name = $cookie[1];
   } else {
      $uid = -1;
      $name = $anonymous;
   }
   $subject=removeHack(stripslashes(FixQuotes(str_replace("\"","&quot;",(check_html($subject, "nohtml"))))));
   $story=removeHack(stripslashes(FixQuotes($story)));
   $bodytext=removeHack(stripslashes(FixQuotes($bodytext)));
   $upload=false;
   include("modules/upload/upload_f.php");
   if ($Xstring=prepa_upload("",$story)) {$story=$Xstring[0];$Xname=$Xstring[1];$upload=true;}
   if ($Xstring=prepa_upload($Xname,$bodytext)) {$bodytext=$Xstring[0];$Xname=$Xstring[1];$upload=true;}
   if ($upload) {
      global $pdst; $pdst="1";
      include ('header.php');
      win_upload($Xname);
      opentable();
      $subject="!urlencode!".urlencode($subject);
      $story=urlencode($story);
      $bodytext=urlencode($bodytext);
      echo "<br /><form action=\"submit.php\" method=\"post\" name=\"adminForm\">";
      echo "<b>".translate("Submission in progress. After Uploading your files, please click on the OK button to finish.")."</b>";
      echo "<input type=\"hidden\" name=\"subject\" value=\"$subject\">";
      echo "<input type=\"hidden\" name=\"story\" value=\"$story\">";
      echo "<input type=\"hidden\" name=\"bodytext\" value=\"$bodytext\">";
      echo "<input type=\"hidden\" name=\"topic\" value=\"$topic\">";
      echo "<input type=\"hidden\" name=\"date_debval\" value=\"$date_debval\">";
      echo "<input type=\"hidden\" name=\"date_finval\" value=\"$date_finval\">";
      echo "<input type=\"hidden\" name=\"epur\" value=\"$epur\">";
      echo "<br /><br /><p align=\"center\"><input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"op\" value=\"Ok\">&nbsp;&nbsp;<a href=\"javascript: history.go(-1)\" class=\"NOIR\">[ ".translate("Go Back")." ]</a></p>";
      echo "</form>";
      closetable();
      include ('footer.php');
   } else {
      if (substr($subject,0,11)=="!urlencode!") {
         $subject=str_replace("!urlencode!","",urldecode($subject));
         $story=urldecode($story);
         $bodytext=urldecode($bodytext);
      }
      $result = mysql_query("insert into queue values (NULL, '$uid', '$name', '$subject', '$story', '$bodytext', now(), '$topic','$date_debval','$date_finval','$epur')");
      if ($notify) {
         global $notify_email, $notify_subject, $notify_message, $notify_from;
         send_email($notify_email, $notify_subject, $notify_message, $notify_from , false, "text");
      }
      global $pdst; $pdst="1";
      include ('header.php');
      opentable();
      echo translate("Thanks for your submission.");
      closetable();
      include ('footer.php');
   }
}

switch($op) {
   case "Preview":
   case translate("Preview"):
        PreviewStory($name, $subject, $story, $bodytext, $topic, $deb_day,$deb_month,$deb_year,$deb_hour,$deb_min, $fin_day,$fin_month,$fin_year,$fin_hour,$fin_min,  $epur);
        break;

   case "Ok":
        if (!$date_debval) {
           if (strlen($deb_day)==1) {
              $deb_day = "0$deb_day";
           }
           if (strlen($deb_month)==1) {
              $deb_month = "0$deb_month";
           }
           $date_debval = "$deb_year-$deb_month-$deb_day $deb_hour:$deb_min:00";
        }
        if (!$date_finval) {
           if (strlen($fin_day)==1) {
              $fin_day = "0$fin_day";
           }
           if (strlen($fin_month)==1) {
              $fin_month = "0$fin_month";
           }
           $date_finval = "$fin_year-$fin_month-$fin_day $fin_hour:$fin_min:00";
        }
        if ($date_finval<$date_debval) {
           $date_finval = $date_debval;
        }
        SubmitStory($subject, $story, $bodytext, $topic, $date_debval,$date_finval,$epur);
        break;

   default:
        defaultDisplay();
        break;
}
?>