<?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-2004 by Philippe Brunier   */
/* Great mods by snipe                                                  */
/*                                                                      */
/* =========================                                            */
/* Part of phpBB integration                                            */
/* Copyright (c) 2001 by                                                */
/*    Richard Tirtadji AKA King Richard (rtirtadji@hotmail.com)         */
/*    Hutdik Hermawan AKA hotFix (hutdik76@hotmail.com)                 */
/* http://www.phpnuke.web.id                                            */
/*                                                                      */
/* 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 ($cancel) {
   header("Location: viewforum.php?forum=$forum");
}

if (!function_exists("Mysql_Connexion")) {include ("mainfile.php");}
include('functions.php');
if ($SuperCache) {
   $cache_obj = new cacheManager();
}
include('auth.php');
global $pdst; $pdst="0";

$rowQ1=Q_Select ("SELECT forum_name, forum_moderator, forum_type, forum_pass, forum_access, arbre FROM forums WHERE forum_id = '$forum'", 3600);
if (!$rowQ1)
   forumerror('0001');
list(,$myrow) = each($rowQ1);
$forum_name = $myrow[forum_name];
$forum_access = $myrow[forum_access];
$moderator = get_moderator($myrow[forum_moderator]);
$moderator=explode(" ",$moderator);
if (isset($user)) {
   $userX = base64_decode($user);
   $userdataX = explode(":", $userX);
   $Mmod=false;
   for ($i = 0; $i < count($moderator); $i++) {
       if (($userdataX[1]==$moderator[$i])) { $Mmod=true; break;}
   }
   $userdata = get_userdata($userdataX[1]);
}

if ( ($myrow[forum_type] == 1) and ($Forum_passwd != $myrow[forum_pass]) ) {
   header("Location: forum.php");
}
if ($forum_access== 9) {
   header("Location: forum.php");
}
if (!does_exists($forum, "forum")) {
   forumerror(0030);
}
// Forum ARBRE
if ($myrow[arbre])
   $hrefX="viewtopicH.php";
else
   $hrefX="viewtopic.php";

if ($submitS) {
   if ($message == '')  {
      $stop=1;
   }
   if ($subject == '') {
      $stop=1;
   }
   if (!$user) {
      if ($forum_access == 0) {
         $userdata = array("uid" => 1);
         include('header.php');
      } else {
         if (($username=="") or ($password=="")) {
            forumerror('0027');
         } else {
            $result = mysql_query("select pass FROM users WHERE uname='$username'");
            list($pass) = mysql_fetch_row($result);
            if (!$system) {
               $passwd=crypt($password,$pass);
            } else {
              $passwd=$password;
            }
            if ((strcmp($passwd,$pass)==0) and ($pass != "")) {
               $userdata = get_userdata($username);
               include('header.php');
            } else {
               forumerror('0028');
            }
         }
      }
   } else {
      include('header.php');
   }
   // Either valid user/pass, or valid session. continue with post.
   if ($stop != 1) {
      $poster_ip =  getip();
      if ($dns_verif)
         $hostname=@gethostbyaddr($poster_ip);

      $modo=user_is_moderator($userdataX[0],$userdataX[2],$forum_access);
      anti_flood ($modo, $anti_flood, $poster_ip, $userdataX, $gmt);

      if ($myrow[forum_type]==8) {
         $formulaire=$myrow[forum_pass];
         include ("modules/sform/forum/forum_extender.php");
      }
      if ($allow_html == 0 || isset($html))
         $message = htmlspecialchars($message);
      if ($sig && $userdata[uid] != 1 && $myrow[forum_type]!=6 && $myrow[forum_type]!=5) {
         $message .= " [addsig]";
      }
      if (($myrow[forum_type]!=6) and ($myrow[forum_type]!=5)) {
         $message = aff_code($message);
         $message = str_replace("\n", "<br />", $message);
      }
      if ((!$smile) and ($myrow[forum_type]!=6) and ($myrow[forum_type]!=5)) {
         $message = smile($message);
      }
      if (($myrow[forum_type]!=6) and ($myrow[forum_type]!=5)) {
         $message = make_clickable($message);
         $message = removeHack($message);
      }
      $message = addslashes($message);
      if (!$Mmod) {
         $subject = removeHack(strip_tags($subject));
      }

      $Msubject = $subject;
      $time = date("Y-m-d H:i",time()+($gmt*3600));
      $sql = "INSERT INTO forumtopics (topic_title, topic_poster, current_poster, forum_id, topic_time, topic_notify) VALUES ('$subject', '$userdata[uid]', '$userdata[uid]', '$forum', '$time'";
      if (isset($notify2) && $userdata[uid] != 1) {
         $sql .= ", '1'";
      } else {
         $sql .= ", '0'";
      }
      $sql .= ")";
      if(!$result = mysql_query($sql)) {
         forumerror(0020);
      }
      $topic_id = mysql_insert_id();
      $sql = "INSERT INTO posts (topic_id, image, forum_id, poster_id, post_text, post_time, poster_ip, poster_dns) VALUES ('$topic_id', '$image_subject', '$forum', '$userdata[uid]', '$message', '$time', '$poster_ip', '$hostname')";
      if (!$result = mysql_query($sql)) {
         forumerror(0020);
      } else {
         $IdPost=mysql_insert_id();
      }
      $sql = "UPDATE users_status SET posts=posts+1 WHERE (uid='$userdata[uid]')";
      $result = mysql_query($sql);
      if (!$result) {
         forumerror(0029);
      }
      $topic = $topic_id;
      global $subscribe;
      if ($subscribe) {
         subscribe_mail("forum",$topic,stripslashes($forum),stripslashes($Msubject),$userdata[uid]);
      }
      if ($upload) {
         include("modules/upload/upload_forum.php");
         win_upload("forum_npds",$IdPost,$forum,$topic,"win");
      }
      redirect_url($hrefX."?forum=$forum&topic=$topic");
   } else {
      OpenTable();
      echo "<p align=\"center\">".translate("You must provide subject and message to post your topic.")."</p>";
      CloseTable();
   }

} else {
   include('header.php');
   if ($allow_bbcode==1) {
      include("lib/formhelp.java.php");
   }

   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
   echo "<b>".translate("Moderated By: ")."</b>";
   for ($i = 0; $i < count($moderator); $i++) {
      echo "<a href=\"user.php?op=userinfo&amp;uname=$moderator[$i]\" class=\"BOX\">$moderator[$i]</a> ";
   }
   echo "</td></tr></table><br />";
   echo "<b>".translate("Post New Topic in:")."</b>";
   echo "&nbsp;<a href=\"viewforum.php?forum=$forum\" class=\"NOIR\">$forum_name</a>&nbsp;&nbsp;|&nbsp;&nbsp;";
   echo "<a href=\"forum.php\" class=\"NOIR\">".translate("Forum Index")."</a>\n";
   echo "<br />";
   echo "<form action=\"newtopic.php\" method=\"post\" name=\"coolsus\">";
   echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">";
   echo "<tr><td class=\"HEADER\" colspan=\"2\">".translate("About Posting:")."</td></tr>";
   echo "<tr>";
   if ($forum_access == 0) {
      echo "<td colspan=\"2\">".translate("Anonymous users can post new topics and replies in this forum.")."</td>";
   } else if($forum_access == 1) {
      echo "<td colspan=\"2\">".translate("All registered users can post new topics and replies to this forum.")."</td>";
   } else if($forum_access == 2) {
      echo "<td colspan=\"2\">".translate("Only Moderators can post new topics and replies in this forum.")."</td>";
   }
   echo "</tr>";
   $userX = base64_decode($user);
   $userdata = explode(":", $userX);
   if ($forum_access == 1) {
      if (!isset($user)) {
         echo "<tr align=\"left\">";
         echo "<td class=\"LIGNB\" width=\"25%\"><b>".translate("Nickname: ")."<b></td>";
         echo "<td class=\"LIGNB\">";
         echo "<input class=\"textbox\" type=\"text\" name=\"username\" size=\"25\" maxlength=\"40\" value=\"$username\"></td>";
         echo "</tr><tr align=\"left\">";
         echo "<td class=\"LIGNB\" width=\"25%\"><b>".translate("Password: ")."</b></td>";
         echo "<td class=\"LIGNB\"><input class=\"textbox\" type=\"password\" name=\"password\" size=\"25\" maxlength=\"25\" value=\"$password\"></td>";
         echo "</tr>";
         $allow_to_post = 1;
      } else {
         echo "<tr align=\"left\">";
         echo "<td class=\"LIGNB\" width=\"25%\"><b>".translate("Author")." :<b></td>";
         echo "<td class=\"LIGNB\">";
         echo $userdata[1];
         echo "</td></tr>";
         $allow_to_post = 1;
      }
   } elseif ($forum_access==2) {
         if (user_is_moderator($userdata[0],$userdata[2],$forum_access)) {
            echo "<tr align=\"left\">";
            echo "<td class=\"LIGNB\" width=\"25%\"><b>".translate("Author")." :<b></td>";
            echo "<td class=\"LIGNB\">";
            echo $userdata[1];
            echo "</td></tr>";
            $allow_to_post = 1;
         }
   } elseif ($forum_access == 0) {
      $allow_to_post = 1;
   }

   if ($allow_to_post) {
      if ($submitP) {
         $acc = "newtopic";
         $subject=stripslashes($subject);
         $message=stripslashes($message);
         $username=stripslashes($username);
         $password=stripslashes($password);
         echo "<tr><td colspan=\"2\">";
         include ("preview.php");
         echo "</td></tr>";
      } else {
        $username=$password='';
        $subject=$message='';
      }
      echo "<tr align=\"left\">";
      if ($myrow[forum_type]==8) {
         echo "<td colspan=2>";
         $formulaire=$myrow[forum_pass];
         include ("modules/sform/forum/forum_extender.php");
      } else {
         echo "<td class=\"LIGNB\" width=\"25%\"><b>".translate("Subject: ")."</b></td>";
         echo "<td class=\"LIGNB\"><input class=\"textbox\" type=\"text\" name=\"subject\" size=\"45\" maxlength=\"100\" value=\"$subject\"></td>";
         echo "</tr>";
         if ($smilies) {
            echo "<tr align=\"left\" valign=\"top\">
            <td class=\"LIGNB\" width=\"25%\"><b>".translate("Message Icon: ")."<b></td>
            <td class=\"LIGNB\">";
            echo emotion_add($image_subject);
            echo "</td></tr>";
         }
         echo "<tr align=\"left\">";
         echo "<td class=\"LIGNB\" width=\"25%\" valign=\"top\"><b>".translate("Message: ")."</b><br /><br />";
         echo "<span style=\"font-size: 10px;\">";
         echo "HTML : ";
         if ($allow_html==1) {
            echo translate("On")."<br />";
            echo HTML_Add($allow_forum_hide);
         } else
            echo translate("Off")."<br />";
         echo "</span></td>";
         echo "<td class=\"LIGNB\">";
         if ($allow_bbcode==1)
            $xJava = 'name="message" onSelect="storeCaret(this);" onClick="storeCaret(this);" onKeyup="storeCaret(this);" onFocus="storeForm(this)"';
         echo "<textarea class=\"textbox\" $xJava name=\"message\" rows=\"10\" cols=\"80\" wrap=\"virtual\">$message</textarea><br />";
         if ($allow_bbcode == 1)
            putitems();
         echo "</td></tr><tr align=\"left\">";
         echo "<td class=\"LIGNB\" width=\"25%\"><b>".translate("Options: ")."</b></td>";
         echo "<td class=\"LIGNB\">";
         if (($allow_html==1) and ($myrow[forum_type]!=6) and ($myrow[forum_type]!=5)) {
         if ($html == "on") {
            $sethtml = "checked";
         }
         echo "<input type=\"checkbox\" name=\"html\" $sethtml>".translate("Disable HTML on this Post")."<br />";
         }
         if ($user) {
            if ($allow_sig == 1) {
               $asig = mysql_query("select attachsig from users_status where uid='$cookie[0]'");
               list($attachsig) = mysql_fetch_row($asig);
               if ($attachsig == 1||$sig == "on") {
                  $s = "checked";
               }
               if (($myrow[forum_type]!=6) and ($myrow[forum_type]!=5)) {
                  echo "<input type=\"checkbox\" name=\"sig\" $s>".translate("Show signature")." <span style=\"font-size: 10px;\">(".translate("This can be altered or added in your profile").")</span><br />";
               }
            }
            if ($allow_upload_forum) {
               if ($upload == "on") {
                  $up = "checked";
               }                
               echo "<input type=\"checkbox\" name=\"upload\" $up>".translate("Upload file after send accepted")."<br />";
            }
            if ($notify2=="on") {
               $selnot="checked";
            }
            echo "<input type=\"checkbox\" name=\"notify2\" $selnot>".translate("Notify by email when replies are posted")."<br />";
         }
         echo "</td></tr><tr>";
         echo "<td class=\"LIGNA\" colspan=\"2\" align=\"center\">";
         echo "<input type=\"hidden\" name=\"forum\" value=\"$forum\">";
         echo "<br /><input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"submitS\" value=\"".translate("Submit")."\">&nbsp;";
         echo "&nbsp;<input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"submitP\" value=\"".translate("Preview")."\">&nbsp;";
         echo "&nbsp;<input class=\"BOUTON_STANDARD\" type=\"reset\" value=\"".translate("Clear")."\">&nbsp;";
         echo "&nbsp;<input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"cancel\" value=\"".translate("Cancel Post")."\"><br /><br />";
      }
      echo "</td></tr>";
   }
   echo "</table></form>";
}
include('footer.php');
?>