<?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   */
/*                                                                      */
/* 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");}

function modone() {
   global $admin, $moderate;
   if (((isset($admin)) && ($moderate == 1)) || ($moderate==2)) echo "<form action=\"comments.php\" method=\"post\">";
}

function modtwo($tid, $score, $reason) {
   global $admin, $user, $moderate, $reasons;
   if ((((isset($admin)) && ($moderate == 1)) || ($moderate == 2)) && ($user)) {
      echo " | <select CLASS=\"TEXTBOX_STANDARD\" name=dkn$tid>";
      for ($i=0; $i<sizeof($reasons); $i++) {
         echo "<option value=\"$score:$i\">$reasons[$i]</option>\n";
      }
      echo "</select>";
   }
}

function modthree($sid, $mode, $order, $thold=0) {
   global $admin, $user, $moderate;
   if ((((isset($admin)) && ($moderate == 1)) || ($moderate==2)) && ($user)) {
      echo "<center><input type=hidden name=sid value=$sid>
      <input type=hidden name=mode value=$mode>
      <input type=hidden name=order value=$order>
      <input type=hidden name=thold value=$thold>
      <input type=hidden name=op value=moderate>";
      echo "<input CLASS=\"BOUTON_STANDARD\" type=submit name=submit value=\"".translate("Moderate")."\"></form></center>";
   }
}

function navbar($sid, $title, $thold, $mode, $order) {
   global $user;
   $query = mysql_query("select sid FROM comments where sid='$sid'");
   if (!$query) $count = 0; else $count = mysql_num_rows($query);
   if (!isset($thold)) $thold=-1;
   $rowcolor=tablos();
   echo "<TABLE cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" BORDER=\"0\">";
   if ($title) {
      echo "<tr $rowcolor><td align=center>\"$title\" | ";
      if ($user) {
         echo "<a href=\"user.php\" CLASS=\"NOIR\">".translate("Configure")."</a>";
      } else {
         echo "<a href=\"user.php\" CLASS=\"NOIR\">".translate("Login/Create Account")."</a>";
      }
      if (($count<=1)) {
         echo " | <B>$count</B> ".translate("comment")."</TD></TR>";
      } else {
         echo " | <B>$count</B> ".translate("comment")."s</TD></TR>";
      }
   }
   echo "<tr $rowcolor><td align=center>";
   echo "<form method=get action=article.php>";
   echo translate("Threshold")." <select CLASS=\"TEXTBOX_STANDARD\" name=thold>";
   if ($thold==-1) {$sel=" selected";} else {$sel="";} echo "<option value=\"-1\"$sel>-1";
   if ($thold==0) {$sel=" selected";} else {$sel="";} echo "<option value=\"0\"$sel>0";
   if ($thold==1) {$sel=" selected";} else {$sel="";} echo "<option value=\"1\"$sel>1";
   if ($thold==2) {$sel=" selected";} else {$sel="";} echo "<option value=\"2\"$sel>2";
   if ($thold==3) {$sel=" selected";} else {$sel="";} echo "<option value=\"3\"$sel>3";
   if ($thold==4) {$sel=" selected";} else {$sel="";} echo "<option value=\"4\"$sel>4";
   if ($thold==5) {$sel=" selected";} else {$sel="";} echo "<option value=\"5\"$sel>5";
   echo "</select> <select CLASS=\"TEXTBOX_STANDARD\" name=mode>";
   if ($mode=='nocomments') {$sel=" selected";} else {$sel="";} echo "<option value=\"nocomments\"$sel>".translate("No Comments");
   if ($mode=='nested') {$sel=" selected";} else {$sel="";} echo "<option value=\"nested\"$sel>".translate("Nested");
   if ($mode=='flat') {$sel=" selected";} else {$sel="";} echo "<option value=\"flat\"$sel>".translate("Flat");
   if (!isset($mode) || $mode=='thread' || $mode=="") {$sel=" selected";} else {$sel="";} echo "<option value=\"thread\"$sel>".translate("Thread");
   echo "</select> <select CLASS=\"TEXTBOX_STANDARD\"name=order>";
   if (!$order) {$sel=" selected";} else {$sel="";} echo "<option value=\"0\"$sel>".translate("Oldest First");
   if ($order==1) {$sel=" selected";} else {$sel="";} echo "<option value=\"1\"$sel>".translate("Newest First");
   if ($order==2) {$sel=" selected";} else {$sel="";} echo "<option value=\"2\"$sel>".translate("Highest Scores First");
   echo "</select> ";
   echo "<input CLASS=BOUTON_STANDARD type=submit value=\"".translate("Refresh")."\">
   <input type=hidden name=sid value=\"$sid\"><BR><BR></td></tr>";
   echo "<tr $rowcolor><td  CLASS=\"HEADER\" align=center><font size=1>".translate("The comments are owned by the poster. We aren't responsible for their content.")."</FONT></td></tr>";
   echo "</form></table><BR>";
}

function DisplayKids ($tid, $mode, $order=0, $thold=0, $level=0, $dummy=0, $tblwidth=0) {
   global $datetime, $bgcolor1, $bgcolor2, $reasons, $anonymous, $anonpost, $commentlimit, $admin, $theme;
   global $user, $cookie;
   $comments = 0;
   $result = mysql_query("select tid, pid, sid, date, name, email, url, host_name, subject, comment, score, reason from comments where pid = '$tid' order by date, tid");
   if ($mode == 'nested') {
      while (list($r_tid, $r_pid, $r_sid, $r_date, $r_name, $r_email, $r_url, $r_host_name, $r_subject, $r_comment, $r_score, $r_reason) = mysql_fetch_row($result)) {
         if ($r_score >= $thold) {
            if (isset($level)) {
               if (!$comments) {
                  $tblwidth += 15;
                  $tbl="<td width=$tblwidth bgcolor=white></td>";
               }
            }
            $comments++;
            if (!eregi("[a-z0-9]",$r_name)) $r_name = $anonymous;
            if (!eregi("[a-z0-9]",$r_subject)) $r_subject = "[".translate("No Subject")."]";
            $r_bgcolor = ($dummy%2)?"":"$bgcolor2";
            echo "<a name=\"$r_tid\">";
            if ($ibid=theme_image("spacer.gif")) {$imgtmp="<TD><IMG height=\"2\" ALT=\"\" src=\"$ibid\" width=\"1\" BORDER=\"0\"></TD>";} else {$imgtmp="<TD width=\"1\">&nbsp;</TD>";}
            echo "<TABLE cellSpacing=\"0\" cellPadding=\"2\" width=\"100%\" BORDER=\"0\"><TR bgcolor=\"$bgcolor1\">$tbl $imgtmp</TR><tr bgcolor=\"$r_bgcolor\">$tbl<td>";
            formatTimestamp($r_date);
            if ($r_email) {
               echo "<b>$r_subject</b> ";
               if (!$cookie[7]) {
                  echo "(".translate("Score: ")."$r_score";
                  if ($r_reason>0) echo ", $reasons[$r_reason]";
                  echo ")";
               }
               echo "<BR>".translate("by")." <a href=\"mailto:$r_email\" CLASS=\"NOIR\">$r_name</a> ($r_email) ".translate("on")." $datetime";
            } else {
               echo "<b>$r_subject</b> ";
               if (!$cookie[7]) {
                  echo "(".translate("Score: ")."$r_score";
                  if ($r_reason>0) echo ", $reasons[$r_reason]";
                  echo ")";
               }
               echo "<BR>".translate("by")." $r_name ".translate("on")." $datetime";
            }
            if ($r_name != $anonymous) { echo "<BR>(<a href=\"user.php?op=userinfo&uname=$r_name\" CLASS=\"NOIR\">".translate("User Info")."</a>) "; }
            if (eregi("http://",$r_url)) { echo "<a href=\"$r_url\" target=\"_blank\" CLASS=\"NOIR\">$r_url</a> "; }
            echo "</TD></TR><TR>$tbl<TD>";
            if (($cookie[10]) && (strlen($r_comment) > $cookie[10])) echo substr("$r_comment", 0, $cookie[10])."<BR><BR><a href=\"comments.php?sid=$r_sid&tid=$r_tid&mode=$mode&order=$order&thold=$thold\" CLASS=\"NOIR\">".translate("Read the rest of this comment...")."</a>";
            elseif (strlen($r_comment) > $commentlimit) echo substr("$r_comment", 0, $commentlimit)."<BR><BR><a href=\"comments.php?sid=$r_sid&tid=$r_tid&mode=$mode&order=$order&thold=$thold\" CLASS=\"NOIR\">".translate("Read the rest of this comment...")."</a>";
            else echo $r_comment;
            echo "</TD></TR><TR>$tbl<TD align=\"LEFT\" CLASS=\"HEADER\">";
            if ($anonpost==1 OR $admin OR $user) {
               echo " [ <a href=\"comments.php?op=Reply&pid=$r_tid&sid=$r_sid&mode=$mode&order=$order&thold=$thold\" CLASS=\"BOX\">".translate("Reply")."</a>";
            }
            modtwo($r_tid, $r_score, $r_reason);
            if ($admin) {
               echo " | <a href=\"admin.php?op=RemoveComment&tid=$r_tid&sid=$r_sid&mode=$mode&order=$order\" CLASS=\"BOX\">".translate("Delete")."</a>";
            }
            if ($anonpost==1 OR $admin OR $user) {
               echo " ]";
            }
            echo "</TD></TR></TABLE><BR>";
            DisplayKids($r_tid, $mode, $order, $thold, $level+1, $dummy+1, $tblwidth);
         }
      }
   } elseif ($mode == 'flat') {
      while (list($r_tid, $r_pid, $r_sid, $r_date, $r_name, $r_email, $r_url, $r_host_name, $r_subject, $r_comment, $r_score, $r_reason) = mysql_fetch_row($result)) {
         if ($r_score >= $thold) {
            if (!eregi("[a-z0-9]",$r_name)) $r_name = $anonymous;
            if (!eregi("[a-z0-9]",$r_subject)) $r_subject = "[".translate("No Subject")."]";
            echo "<a name=\"$r_tid\"></a>";
            if ($ibid=theme_image("spacer.gif")) {$imgtmp="<TD><IMG height=\"2\" ALT=\"\" src=\"$ibid\" width=\"1\" BORDER=\"0\"></TD>";} else {$imgtmp="<TD width=\"1\">&nbsp;</TD>";}
            echo "<TABLE cellSpacing=\"0\" cellPadding=\"2\" width=\"100%\" BORDER=\"0\"><TR bgcolor=\"$bgcolor1\">$imgtmp</TR><tr bgcolor=\"$bgcolor1\"><td>";
            formatTimestamp($r_date);
            if ($r_email) {
               echo "<b>$r_subject</b> ";
               if (!$cookie[7]) {
                  echo "(".translate("Score: ")."$r_score";
                  if ($r_reason>0) echo ", $reasons[$r_reason]";
                  echo ")";
               }
               echo "<BR>".translate("by")." <a href=\"mailto:$r_email\" CLASS=\"NOIR\">$r_name</a> ($r_email) ".translate("on")." $datetime";
            } else {
               echo "<b>$r_subject</b> ";
               if (!$cookie[7]) {
                  echo "(".translate("Score: ")."$r_score";
                  if ($r_reason>0) echo ", $reasons[$r_reason]";
                  echo ")";
               }
               echo "<BR>".translate("by")." $r_name ".translate("on")." $datetime";
            }
            if ($r_name != $anonymous) { echo "<BR>(<a href=\"user.php?op=userinfo&uname=$r_name\" CLASS=\"NOIR\">".translate("User Info")."</a>) "; }
            if (eregi("http://",$r_url)) { echo "<a href=\"$r_url\" target=\"_blank\" CLASS=\"NOIR\">$r_url</a> "; }
            echo "</TD></TR><TR bgcolor=\"$bgcolor1\">$imgtmp</TR><TR><TD>";
            if (($cookie[10]) && (strlen($r_comment) > $cookie[10])) echo substr("$r_comment", 0, $cookie[10])."<BR><BR><a href=\"comments.php?sid=$r_sid&tid=$r_tid&mode=$mode&order=$order&thold=$thold\" CLASS=\"NOIR\">".translate("Read the rest of this comment...")."</a>";
            elseif (strlen($r_comment) > $commentlimit) echo substr("$r_comment", 0, $commentlimit)."<BR><BR><a href=\"comments.php?sid=$r_sid&tid=$r_tid&mode=$mode&order=$order&thold=$thold\" CLASS=\"NOIR\">".translate("Read the rest of this comment...")."</a>";
            else echo $r_comment;
            echo "</TD></TR><TR><TD align=\"LEFT\" CLASS=\"HEADER\">";
            if ($anonpost==1 OR $admin OR $user) {
               echo " [ <a href=\"comments.php?op=Reply&pid=$r_tid&sid=$r_sid&mode=$mode&order=$order&thold=$thold\" CLASS=\"BOX\">".translate("Reply")."</a>";
            }
            modtwo($r_tid, $r_score, $r_reason);
            if ($admin) {
               echo " | <a href=\"admin.php?op=RemoveComment&tid=$r_tid&sid=$r_sid&mode=$mode&order=$order\" CLASS=\"BOX\">".translate("Delete")."</a>";
            }
            if ($anonpost==1 OR $admin OR $user) {
               echo " ]";
            }
            echo " </TD></TR></TABLE><BR>";
            DisplayKids($r_tid, $mode, $order, $thold);
         }
      }
   } else {
      while (list($r_tid, $r_pid, $r_sid, $r_date, $r_name, $r_email, $r_url, $r_host_name, $r_subject, $r_comment, $r_score, $r_reason) = mysql_fetch_row($result)) {
         if ($r_score >= $thold) {
            if (isset($level)) {
               if (!$comments) {
                  echo "<ul>";
               }
            }
            $comments++;
            if (!eregi("[a-z0-9]",$r_name)) $r_name = $anonymous;
            if (!eregi("[a-z0-9]",$r_subject)) $r_subject = "[".translate("No Subject")."]";
            formatTimestamp($r_date);
            echo "<li><a href=\"comments.php?op=showreply&tid=$r_tid&sid=$r_sid&pid=$r_pid&mode=$mode&order=$order&thold=$thold#$r_tid\" CLASS=\"NOIR\">$r_subject</a> ".translate("by")." $r_name ".translate("on")." $datetime<BR>";
            DisplayKids($r_tid, $mode, $order, $thold, $level+1, $dummy+1);
         }
      }
   }
}

function DisplayTopic ($sid, $pid=0, $tid=0, $mode="thread", $order=0, $thold=0, $level=0, $nokids=0) {
   global $admin, $commentlimit, $anonymous, $reasons, $anonpost, $title, $bgcolor1, $datetime;
   global $user, $cookie;
   $count_times = 0;
   $q = "select tid, pid, sid, date, name, email, url, host_name, subject, comment, score, reason from comments where sid='$sid' and pid='$pid'";
   if ($thold != "") {
      settype($thold,"integer");
      $q .= " and score>='$thold'";
   } else {
      $q .= " and score>='0'";
   }
   if ($order==1) $q .= " order by date desc";
   if ($order==2) $q .= " order by score desc";
   $something = mysql_query("$q");
   $num_tid = mysql_num_rows($something);
   navbar($sid, $title, $thold, $mode, $order);
   modone();
   if ($ibid=theme_image("spacer.gif")) {$imgtmp="<TD><IMG height=\"2\" ALT=\"\" src=\"$ibid\" width=\"1\" BORDER=\"0\"></TD>";} else {$imgtmp="<TD width=\"1\">&nbsp;</TD>";}
   while ($count_times < $num_tid) {
      list($tid, $pid, $sid, $date, $name, $email, $url, $host_name, $subject, $comment, $score, $reason) = mysql_fetch_row($something);
      if ($name == "") { $name = $anonymous; }
      if ($subject == "") { $subject = "[".translate("No Subject")."]"; }
      echo "<a name=\"$tid\"></a>";
      echo "<TABLE cellSpacing=\"0\" cellPadding=\"2\" width=\"100%\" BORDER=\"0\"><TR bgcolor=\"$bgcolor1\">$imgtmp</TD></TR><tr bgcolor=\"$bgcolor1\"><td>";
      formatTimestamp($date);
      if ($email) {
         echo "<b>$subject</b> ";
         if (!$cookie[7]) {
            echo "(".translate("Score: ")."$score";
            if ($reason>0) echo ", $reasons[$reason]";
            echo ")";
         }
         echo "<BR>".translate("by")." <a href=\"mailto:$email\" CLASS=\"NOIR\">$name</a> ($email) ".translate("on")." $datetime";
      } else {
         echo "<b>$subject</b> ";
         if (!$cookie[7]) {
            echo "(".translate("Score: ")."$score";
            if ($reason>0) echo ", $reasons[$reason]";
            echo ")";
         }
         echo "<BR>".translate("by")." $name ".translate("on")." $datetime";
      }
      if ($name != $anonymous) { echo "<BR>[ <a href=\"user.php?op=userinfo&uname=$name\" CLASS=\"NOIR\">".translate("Author Infos")."</a> ] "; }
      if (eregi("http://",$url)) { echo "<a href=\"$url\" target=\"_blank\" CLASS=\"NOIR\">$url</a> "; }
      if ($admin) {
         $result= mysql_query("select host_name from comments where tid='$tid'");
         list($host_name) = mysql_fetch_row($result);
         echo " -::- [IP : $host_name]";
      }
      echo "</TD></TR><TR bgcolor=\"$bgcolor1\">$imgtmp</TR><TR><TD>";
      if (($cookie[10]) && (strlen($comment) > $cookie[10])) echo substr("$comment", 0, $cookie[10])."<BR><BR><a href=\"comments.php?sid=$sid&tid=$tid&mode=$mode&order=$order&thold=$thold\" CLASS=\"NOIR\">".translate("Read the rest of this comment...")."</a>";
      elseif (strlen($comment) > $commentlimit) echo substr("$comment", 0, $commentlimit)."<BR><BR><a href=\"comments.php?sid=$sid&tid=$tid&mode=$mode&order=$order&thold=$thold\" CLASS=\"NOIR\">".translate("Read the rest of this comment...")."</a>";
      else echo $comment;
      echo "</TD></TR><tr><td align=\"LEFT\" CLASS=\"HEADER\">";
      if ($anonpost==1 OR $admin OR $user) {
         echo " [ <a href=\"comments.php?op=Reply&pid=$tid&sid=$sid&mode=$mode&order=$order&thold=$thold\" CLASS=\"BOX\">".translate("Reply")."</a>";
      } else {
         $anonymousMess=true;
      }
      if ($pid != 0) {
         list($erin) = mysql_fetch_row(mysql_query("select pid from comments where tid='$pid'"));
         if (!$anonymousMess) {echo " | ";}
         echo "<a href=\"comments.php?sid=$sid&pid=$erin&mode=$mode&order=$order&thold=$thold\" CLASS=\"BOX\">".translate("Parent")."</a>";
      }
      modtwo($tid, $score, $reason);
      if ($admin) {
         echo " | <a href=\"admin.php?op=RemoveComment&tid=$tid&sid=$sid&mode=$mode&order=$order\" CLASS=\"BOX\">".translate("Delete")."</a>";
      }
      if ($anonpost==1 OR $admin OR $user) {
         echo " ]";
      }
      echo "</TD></TR></TABLE><BR>";
      echo "<TABLE cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" align=\"center\" BORDER=\"0\"><tr><td>";
      DisplayKids($tid, $mode, $order, $thold, $level);
      echo "</TD></TR></TABLE><BR>";
      $count_times += 1;
   }
   if ($anonymousMess==true) {
      echo "<center>[ <font CLASS=\"ROUGE\">".translate("No Comments Allowed for Anonymous,")."</font> <a href=\"user.php\" CLASS=\"NOIR\">".translate("Register Now! It's Free!")."</a> ]</center>";
   }
   modthree($sid, $mode, $order, $thold);
   if ($pid==0) return array($sid, $pid, $subject);
   else include("footer.php");
}

function singlecomment($tid, $sid, $mode, $order, $thold) {
   global $user, $datetime, $bgcolor1, $admin, $anonpost;
   include("header.php");

   $deekayen = mysql_query("select date, name, email, url, subject, comment, score, reason from comments where tid='$tid' and sid='$sid'");
   list($date, $name, $email, $url, $subject, $comment, $score, $reason) = mysql_fetch_row($deekayen);
   $titlebar = "<b>$subject</b>";
   if ($name == "") $name = $anonymous;
   if ($subject == "") $subject = "[".translate("No Subject")."]";
   modone();
   if ($ibid=theme_image("spacer.gif")) {$imgtmp="<TD><IMG height=\"2\" ALT=\"\" src=\"$ibid\" width=\"1\" BORDER=\"0\"></TD>";} else {$imgtmp="<TD width=\"1\">&nbsp;</TD>";}
   echo "<TABLE cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" BORDER=\"0\"><TR bgcolor=\"$bgcolor1\">$imgtmp</TR><tr bgcolor=\"$bgcolor1\"><td>";
   formatTimestamp($date);
   if ($email) echo "<b>$subject</b> (".translate("Score: ")."$score)<BR>".translate("by")." <a href=\"mailto:$email\" CLASS=\"NOIR\">$name</a> ($email) ".translate("on")." $datetime";
   else echo "<b>$subject</b> (".translate("Score: ")."$score)<BR>".translate("by")." $name ".translate("on")." $datetime";
   echo "</TD></TR><tr><td>$comment</TD></TR><TR><TD align=\"LEFT\" CLASS=\"HEADER\">";
   if ($anonpost==1 OR $admin OR $user) {
      echo " [ <a href=\"comments.php?op=Reply&pid=$tid&sid=$sid&mode=$mode&order=$order&thold=$thold\" CLASS=\"BOX\">".translate("Reply")."</a> | <a href=\"article.php?sid=$sid&mode=$mode&order=$order&thold=$thold\" CLASS=\"BOX\">".translate("Parent")."</a>";
   }
   modtwo($tid, $score, $reason);
   echo " ]";
   echo " </TD></TR></TABLE><BR>";
   modthree($sid, $mode, $order, $thold);

   include("footer.php");
}

function reply ($pid, $sid, $mode, $order, $thold) {
   global $user, $datetime, $AllowableHTML, $anonymous;
   include("header.php");

   if ($pid!=0) {
      list($date, $name, $email, $url, $subject, $comment, $score) = mysql_fetch_row(mysql_query("select date, name, email, url, subject, comment, score from comments where tid='$pid'"));
   } else {
      list($date, $subject, $temp_comment, $comment, $name, $notes) = mysql_fetch_row(mysql_query("select time, title, hometext, bodytext, informant, notes FROM stories where sid='$sid'"));
   }

   if ($comment == "") {
      $comment = $temp_comment;
      $temp_comment="";
   }

   $comment=aff_code(aff_langue($comment));
   $temp_comment=aff_code(aff_langue($temp_comment));

   if ($name == "") $name = $anonymous;
   if ($subject == "") $subject = "[".translate("No Subject")."]";
   echo "<table border=0 cellpadding=3 cellspacing=0 width=100%><tr><td>";
   formatTimestamp($date);
   if ($email) {
      echo "<table border=0 cellpadding=3 cellspacing=0 width=100%><tr><td>";
      if (!$temp_comment) echo"(".translate("Score: ")."$score)";
      echo "<BR>".translate("by")." <a href=\"mailto:$email\" CLASS=\"NOIR\">$name</a> <b>($email)</b> ".translate("on")." $datetime";
      echo "</TD></TR></TABLE><DIV class=\"SEPAR\"></DIV>";
      echo "<FONT CLASS=\"TITREA\">".aff_langue($subject)."</FONT><BR>";
   } else {
      if (!$temp_comment) echo"(".translate("Score: ")."$score)";
      echo "<table border=0 cellpadding=3 cellspacing=0 width=100%><tr><td>".translate('Posted on')." $datetime";
      echo "<BR>".translate("by")." : <FONT CLASS=\"TITBOXC\">$name</FONT>";
      echo "</TD></TR></TABLE><DIV class=\"SEPAR\"></DIV>";
      echo "<FONT CLASS=\"TITREA\">".aff_langue($subject)."</FONT><BR>";
   }
   if ($notes!="") $notes="<DIV CLASS=\"AIDE\">".translate("Note")." : \"".aff_code(aff_langue($notes))."\"</DIV>";
   echo "</TD></TR><tr><td>$temp_comment<BR><BR>$comment<BR>$notes</TD></TR></TABLE>";

   if (!isset($pid) || !isset($sid)) { echo "Something is not right. This message is just to keep things from messing up down the road"; exit(); }
   if ($pid == 0) {
      list($subject) = mysql_fetch_row(mysql_query("select title from stories where sid='$sid'"));
   } else {
      list($subject) = mysql_fetch_row(mysql_query("select subject from comments where tid='$pid'"));
   }

   echo "<FORM action=\"comments.php\" method=post>";
   echo "<TABLE WIDTH=100% CELLSPACING=2 CELLPADDING=2 BORDER=0><TR><TD CLASS=\"HEADER\">\n";
   echo translate("Your Name")." : ";
   if ($user) {
      global $cookie;
      echo "$cookie[1]";
   } else {
      echo "<FONT CLASS=\"ROUGE\">$anonymous</FONT>";
      echo " [ <a href=\"user.php\" CLASS=\"BOX\">".translate("New User")."</a> ] ";
   }
   echo "</TD></TR></TABLE>\n";
   opentable();
   echo "<B>".translate("Subject")."</B> :<BR>";
   if (!eregi("Re:",$subject)) $subject = "Re: $subject";
   if (strstr(getenv("HTTP_USER_AGENT"),"MSIE")) {$max_car=65;} else {$max_car=45;}
   echo "<input class=textbox type=\"text\" NAME=\"subject\" SIZE=45 maxlength=60 value=\"".aff_langue($subject)."\"><BR><BR>";
   echo "<B>".translate("Comment")."</B> :<BR>"
       ."<TEXTAREA CLASS=\"TEXTBOX\" wrap=virtual cols=$max_car rows=10 name=comment></TEXTAREA><BR>"
       .translate("Allowed HTML:");
   while (list($key,)= each($AllowableHTML)) echo " &lt;".$key."&gt;";
   echo "<BR>";
   if ($user) { echo "<input type=\"checkbox\" name=\"xanonpost\"> ".translate("Post Anonymously")."<BR>"; }
   echo "<input type=\"hidden\" name=\"pid\" value=\"$pid\">"
       ."<input type=\"hidden\" name=\"sid\" value=\"$sid\"><input type=\"hidden\" name=\"mode\" value=\"$mode\">"
       ."<input type=\"hidden\" name=\"order\" value=\"$order\"><input type=\"hidden\" name=\"thold\" value=\"$thold\">"
       ."<input CLASS=\"BOUTON_STANDARD\" type=\"submit\" name=\"op\" value=\"".translate("Preview")."\"> - "
       ."<input CLASS=\"BOUTON_STANDARD\" type=\"submit\" name=\"op\" value=\"Ok\"> <SELECT CLASS=\"TEXTBOX_STANDARD\" name=\"posttype\"><OPTION value=\"exttrans\">".translate("Extrans (html tags to text)")."<OPTION value=\"html\" >".translate("HTML Formatted")."<OPTION value=\"plaintext\" SELECTED>".translate("Plain Old Text")."</SELECT></FORM><BR>";
   closetable();
   include("footer.php");
}

function replyPreview ($pid, $sid, $subject, $comment, $xanonpost, $mode, $order, $thold, $posttype) {
   global $AllowableHTML, $anonymous;
   global $user, $cookie;
   include("header.php");

   $subject = stripslashes($subject);
   $comment = stripslashes($comment);
   if (!isset($pid) || !isset($sid)) {
      echo "Something is not right. This message is just to keep things from messing up down the road";
      exit();
   }
   echo "<table border=0 cellpadding=3 cellspacing=0 width=100%><tr><td>";
   echo translate("by")." ";
   if ($user) {
      echo "$cookie[1]";
   } else {
      echo "<FONT CLASS=\"ROUGE\">$anonymous</FONT>";
   }
   echo translate(" on...")."";
   echo "</TD></TR></TABLE><DIV class=\"SEPAR\"></DIV>";
   opentable();
   echo "<FONT CLASS=\"TITREA\">$subject</FONT><BR>";
   if ($posttype=="exttrans") {
      echo nl2br(htmlspecialchars($comment));
   } elseif ($posttype=="plaintext") {
      echo nl2br($comment);
   } else {
      echo $comment;
   }
   echo "<FORM action=\"comments.php\" method=post>";
   if (strstr(getenv("HTTP_USER_AGENT"),"MSIE")) {$max_car=65;} else {$max_car=45;}
   echo "<B>".translate("Subject")."</B> :<BR>"
       ."<input class=textbox type=\"text\" NAME=\"subject\" SIZE=45 maxlength=60 value=\"$subject\"><BR><BR>"
       ."<B>".translate("Comment")."</B> :<BR>"
       ."<TEXTAREA class=textbox wrap=virtual cols=$max_car rows=10 name=comment>$comment</TEXTAREA><BR>";
   echo translate("Allowed HTML:")." : ";
   while (list($key,) = each($AllowableHTML)) echo " &lt;".$key."&gt;";
   echo "<BR>";
   if ($xanonpost) {
      echo "<input type=\"checkbox\" name=\"xanonpost\" checked> ".translate("Post Anonymously")."<BR>";
   } elseif($user) {
      echo "<input type=\"checkbox\" name=\"xanonpost\"> ".translate("Post Anonymously")."<BR>";
   }
   echo "<input type=\"hidden\" name=\"pid\" value=\"$pid\">"
   ."<input type=\"hidden\" name=\"sid\" value=\"$sid\"><input type=\"hidden\" name=\"mode\" value=\"$mode\">"
   ."<input type=\"hidden\" name=\"order\" value=\"$order\"><input type=\"hidden\" name=\"thold\" value=\"$thold\">"
   ."<input CLASS=\"BOUTON_STANDARD\" type=submit name=op value=\"".translate("Preview")."\"> - "
   ."<input CLASS=\"BOUTON_STANDARD\" type=submit name=op value=\"Ok\"> <SELECT CLASS=\"TEXTBOX_STANDARD\" name=\"posttype\"><OPTION value=\"exttrans\"";
   if ($posttype=="exttrans") {
      echo" SELECTED";
   }
   echo  ">".translate("Extrans (html tags to text)")."<OPTION value=\"html\"";;
   if ($posttype=="html") {
      echo" SELECTED";
   }
   echo ">".translate("HTML Formatted")."<OPTION value=\"plaintext\"";
   if (($posttype!="exttrans") && ($posttype!="html")) {
      echo" SELECTED";
   }
   echo ">".translate("Plain Old Text")."</SELECT></FORM><BR>";
   closetable();
   include("footer.php");
}

function CreateTopic ($xanonpost, $subject, $comment, $pid, $sid, $host_name, $mode, $order, $thold, $posttype) {
   global $user, $troll_limit, $anonpost;

   if (($anonpost=="0" and $xanonpost!="") OR ($anonpost=="0" and !$user)) {
      Header("Location: article.php?sid=$sid&mode=$mode&order=$order&thold=$thold");
      die();
   }

    if ($posttype=="exttrans") {
       $comment = FixQuotes(nl2br(htmlspecialchars(check_words($comment))));
    } elseif($posttype=="plaintext") {
       $comment = FixQuotes(nl2br(filter_text($comment,"nohtml")));
    } else {
       $comment = FixQuotes(filter_text($comment,""));
    }
    $author=FixQuotes($author);
    $subject=FixQuotes(filter_text($subject, "nohtml"));
    if (($user) && ($xanonpost!="on")) {
       $userinfo=getusrinfo($user);
       $name = $userinfo[uname];
       $email = $userinfo[femail];
       $url = $userinfo[url];
       $score = 1;
    } else {
       $name = ""; $email = ""; $url = "";
       $score = 0;
    }
    $ip = getip();
    list($fake) = mysql_fetch_row(mysql_query("select count(*) from stories where sid='$sid'"));
    mysql_query("LOCK TABLES comments WRITE");
    list($tia) = mysql_fetch_row(mysql_query("select count(*) from comments where pid='$pid' and sid='$sid' and subject='$subject' and comment='$comment'"));
    if ($user) {
       list($troll) = mysql_fetch_row(mysql_query("select count(*) from comments where (name='$name') and (to_days(now()) - to_days(date) < 1)"));
    } elseif(!$score) {
       list($troll) = mysql_fetch_row(mysql_query("select count(*) from comments where (host_name='$ip') and (to_days(now()) - to_days(date) < 1)"));
    }
    if ((!$tia) && ($fake == 1) && ($troll < $troll_limit)) {
       mysql_query("insert into comments values (NULL, '$pid', '$sid', now(), '$name', '$email', '$url', '$ip', '$subject', '$comment', '$score', '0')");
    } else {
       mysql_query("UNLOCK TABLES");
       include("header.php");
       opentable();
       if ($tia) {
          echo translate("Duplicate. Did you submit twice")." ?<BR><BR><a href=\"article.php?sid=$sid&mode=$mode&order=$order&thold=$thold\" CLASS=\"NOIR\">".translate("Go Back")."</a>";
       } elseif ($troll > ($troll_limit-1)) {
          echo translate("This account or IP has been temporarily disabled. This means that either this IP, or user account has been moderated down more than x times in the last few hours. If you think this is unfair, you should contact the admin.")."
          <BR><BR><a href=\"article.php?sid=$sid&mode=$mode&order=$order&thold=$thold\" CLASS=\"NOIR\">".translate("Go Back")."</a>";
       } elseif ($fake == 0) {
          echo translate("According to my records, the topic you are trying to reply to does not exist.");
       }
       closetable();
       include("footer.php");
       exit;
    }
    mysql_query("UNLOCK TABLES");
    mysql_query("update stories set comments=comments+1 where sid='$sid'");
    if ($ultramode) {
       ultramode();
    }
    Header("Location: article.php?sid=$sid&mode=$mode&order=$order=thold=$thold");
}

switch($op) {
    case "Reply":
         reply($pid, $sid, $mode, $order, $thold);
         break;

    case "Preview":
    case translate("Preview"):
         replyPreview ($pid, $sid, $subject, $comment, $xanonpost, $mode, $order, $thold, $posttype);
         break;

    case "Ok":
         CreateTopic($xanonpost, $subject, $comment, $pid, $sid, $host_name, $mode, $order, $thold, $posttype);
         break;

    case "moderate":
         if (($admintest==1) || ($moderate==2)) {
            while(list($tdw, $emp) = each($HTTP_POST_VARS)) {
               if (eregi("dkn",$tdw)) {
                  $emp = explode(":", $emp);
                  if ($emp[1] != 0) {
                     $tdw = ereg_replace("dkn", "", $tdw);
                     $q = "UPDATE comments SET";
                     if (($emp[1] == 9) && ($emp[0]>=0)) {
                        $q .= " score=score-1 where tid='$tdw'";
                     } elseif (($emp[1] == 10) && ($emp[0]<=4)) {
                        $q .= " score=score+1 where tid='$tdw'";
                     } elseif (($emp[1] > 4) && ($emp[0]<=4)) {
                        $q .= " score=score+1, reason='$emp[1]' where tid='$tdw'";
                     } elseif (($emp[1] < 5) && ($emp[0] > -1)) {
                        $q .= " score=score-1, reason='$emp[1]' where tid='$tdw'";
                     } elseif (($emp[0] == -1) || ($emp[0] == 5)) {
                        $q .= " reason=$emp[1] where tid='$tdw'";
                     }
                     if (strlen($q) > 20) mysql_query("$q");
                  }
               }
            }
         }
         Header("Location: article.php?sid=$sid&mode=$mode&order=$order&thold=$thold");
         break;

    case "showreply":
         include("header.php");
         DisplayTopic($sid, $pid, $tid, $mode, $order, $thold);
         break;

    default:
         if ((isset($tid)) && (!isset($pid))) {
            singlecomment($tid, $sid, $mode, $order, $thold);
         } elseif (($mainfile) xor (($pid==0) || (!isset($pid)))) {
            Header("Location: article.php?sid=$sid&mode=$mode&order=$order&thold=$thold");
         } else {
            if (!isset($pid)) $pid=0;
            if (!isset($header)) { include("header.php"); }
            DisplayTopic($sid, $pid, $tid, $mode, $order, $thold);
         }
         break;
}
?>