<?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");}
global $pdst; $pdst="0";

function modone() {
   global $admin, $moderate;
   if (((isset($admin)) && ($moderate == 1)) || ($moderate==2)) echo "<form action=\"pollcomments.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($pollID, $mode, $order, $thold=0) {
   global $admin, $user, $moderate;
   if ((((isset($admin)) && ($moderate == 1)) || ($moderate==2)) && ($user)) {
      echo "<center><input type=\"hidden\" name=\"pollID\" value=\"$pollID\">
      <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($pollID, $title, $thold, $mode, $order) {
   global $user;
   $query = mysql_query("select pollID FROM pollcomments where pollID='$pollID'");
   if (!$query) $count = 0; else $count = mysql_num_rows($query);
   $result = mysql_query("select pollTitle from poll_desc where pollID='$pollID'");
   list($title) = mysql_fetch_row($result);
   if (!isset($thold)) $thold=-1;
   $row_color=tablos();
   echo "<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" border=\"0\">";
   if ($title) {
      echo "<tr $rowcolor><td align=center class=\"HEADER\">\"".aff_langue($title)."\" | ";
      if ($user) {
         echo "<a href=\"user.php\" class=\"BOX\">".translate("Configure")."</a>";
      } else {
         echo "<a href=\"user.php\" class=\"BOX\">".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>";
      }
   }
   $row_color=tablos();
   echo "<tr $row_color><td align=\"center\">";
   echo "<form method=\"get\" action=\"pollBooth.php\">
         <input type=\"hidden\" name=\"op\" value=\"results\">";
   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=\"pollID\" value=\"$pollID\"</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, pollID, date, name, email, url, host_name, subject, comment, score, reason from pollcomments where pid='$tid' order by date, tid");
   if ($mode == 'nested') {
      while (list($r_tid, $r_pid, $r_pollID, $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>".aff_langue($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>".aff_langue($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&amp;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=\"pollcomments.php?pollID=$r_pollID&amp;tid=$r_tid&amp;mode=$mode&amp;order=$order&amp;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=\"pollcomments.php?pollID=$r_pollID&amp;tid=$r_tid&amp;mode=$mode&amp;order=$order&amp;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=\"pollcomments.php?op=Reply&amp;pid=$r_tid&amp;pollID=$r_pollID&amp;mode=$mode&amp;order=$order&amp;thold=$thold\" class=\"BOX\">".translate("Reply")."</a>";
            }
            modtwo($r_tid, $r_score, $r_reason);
            if ($admin) {
               echo " | <a href=\"admin.php?op=RemovePollComment&amp;tid=$r_tid&amp;pollID=$r_pollID&amp;mode=$mode&amp;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_pollID, $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\">";
            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>".aff_langue($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>".aff_langue($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&amp;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=\"pollcomments.php?pollID=$r_pollID&amp;tid=$r_tid&amp;mode=$mode&amp;order=$order&amp;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 /><b><a href=\"pollcomments.php?pollID=$r_pollID&amp;tid=$r_tid&amp;mode=$mode&amp;order=$order&amp;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=\"pollcomments.php?op=Reply&amp;pid=$r_tid&amp;pollID=$r_pollID&amp;mode=$mode&amp;order=$order&amp;thold=$thold\" class=\"BOX\">".translate("Reply")."</a>";
            }
            modtwo($r_tid, $r_score, $r_reason);
            if ($admin) {
               echo " | <a href=\"admin.php?op=RemovePollComment&amp;tid=$r_tid&amp;pollID=$r_pollID&amp;mode=$mode&amp;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_pollID, $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=\"pollcomments.php?op=showreply&amp;tid=$r_tid&amp;pollID=$r_pollID&amp;pid=$r_pid&amp;mode=$mode&amp;order=$order&amp;thold=$thold#$r_tid\" class=\"NOIR\">".aff_langue($r_subject)."</a> ".translate("by")." $r_name ".translate("on")." $datetime<br />";
            DisplayKids($r_tid, $mode, $order, $thold, $level+1, $dummy+1);
         }
      }
   }
}

function DisplayTopic ($pollID, $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, pollID, date, name, email, url, host_name, subject, comment, score, reason from pollcomments where pollID='$pollID' 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($pollID, $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, $pollID, $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>".aff_langue($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>".aff_langue($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&amp;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 pollcomments 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=\"pollcomments.php?pollID=$pollID&amp;tid=$tid&amp;mode=$mode&amp;order=$order&amp;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=\"pollcomments.php?pollID=$pollID&amp;tid=$tid&amp;mode=$mode&amp;order=$order&amp;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=\"pollcomments.php?op=Reply&amp;pid=$tid&amp;pollID=$pollID&amp;mode=$mode&amp;order=$order&amp;thold=$thold\" class=\"BOX\">".translate("Reply")."</a>";
      } else {
         $anonymousMess=true;
      }
      if ($pid != 0) {
         list($erin) = mysql_fetch_row(mysql_query("select pid from pollcomments where tid='$pid'"));
         if (!$anonymousMess) {echo " | ";}
         echo "<a href=\"pollcomments.php?pollID=$pollID&amp;pid=$erin&amp;mode=$mode&amp;order=$order&amp;thold=$thold\" class=\"BOX\">".translate("Parent")."</a>";
      }
      modtwo($tid, $score, $reason);
      if ($admin) {
         echo " | <a href=\"admin.php?op=RemovePollComment&amp;tid=$tid&amp;pollID=$pollID&amp;mode=$mode&amp;order=$order\" class=\"BOX\">".translate("Delete")."</a> ]";
      } elseif ($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($pollID, $mode, $order, $thold);
   if ($pid==0) return array($pollID, $pid, $subject);
   else include("footer.php");
}

function singlecomment($tid, $pollID, $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 pollcomments where tid='$tid' and pollID='$pollID'");
   list($date, $name, $email, $url, $subject, $comment, $score, $reason) = mysql_fetch_row($deekayen);
   $titlebar = "<b>".aff_langue($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>".aff_langue($subject)."</b> (".translate("Score: ")."$score)<br />".translate("by")." <a href=\"mailto:$email\" class=\"NOIR\">$name</a> ($email) ".translate("on")." $datetime";
   else echo "<b>".aff_langue($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=\"pollcomments.php?op=Reply&amp;pid=$tid&amp;pollID=$pollID&amp;mode=$mode&amp;order=$order&amp;thold=$thold\" class=\"BOX\">".translate("Reply")."</a> | <a href=\"pollBooth.php?op=results&amp;pollID=$pollID\" 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, $pollID, $mode, $order, $thold) {
   global $user, $datetime, $AllowableHTML, $anonymous;
   global $pdst; $pdst="1";
   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 pollcomments where tid='$pid'"));
   } else {
      list($subject) = mysql_fetch_row(mysql_query("select pollTitle FROM poll_desc where pollID='$pollID'"));
   }
   if ($comment == "") {
      $comment = $temp_comment;
      $temp_comment = "";
   }
   $titlebar = "<b>".aff_langue($subject)."</b>";
   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 {
      echo "<font class=\"TITREA\">".aff_langue($subject)."</font><br />";
   }
   echo "</td></tr></table>";

   if (!isset($pid) || !isset($pollID)) { exit(); }
   if ($pid == 0) {
      list($subject) = mysql_fetch_row(mysql_query("select pollTitle from poll_desc where pollID='$pollID'"));
   } else {
      list($subject) = mysql_fetch_row(mysql_query("select subject from pollcomments where tid='$pid'"));
   }

   echo "<form action=\"pollcomments.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=\"pollID\" value=\"$pollID\"><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, $pollID, $subject, $comment, $xanonpost, $mode, $order, $thold, $posttype) {
   global $AllowableHTML, $anonymous;
   global $user, $cookie;
   global $pdst; $pdst="1";
   include("header.php");
   $subject = stripslashes($subject);
   $comment = stripslashes($comment);

   if (!isset($pid) || !isset($pollID)) { 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\">".aff_langue($subject)."</font><br />";
   if ($posttype=="exttrans") {
      echo nl2br(htmlspecialchars($comment));
   } elseif ($posttype=="plaintext") {
      echo nl2br($comment);
   } else {
      echo $comment;
   }
   echo "<form action=\"pollcomments.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=\"".aff_langue($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=\"pollID\" value=\"$pollID\"><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, $pollID, $host_name, $mode, $order, $thold, $posttype) {
   global $user, $troll_limit, $anonpost;

   if (($anonpost=="0" and $xanonpost!="") OR ($anonpost=="0" and !$user)) {
      Header("Location: pollBooth.php?op=results&pollID=$pollID&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();
   //begin fake thread control
   list($fake) = mysql_fetch_row(mysql_query("select count(*) from poll_desc where pollID='$pollID'"));
   mysql_query("LOCK TABLES pollcomments WRITE");
   //begin duplicate control
   list($tia) = mysql_fetch_row(mysql_query("select count(*) from pollcomments where pid='$pid' and pollID='$pollID' and subject='$subject' and comment='$comment'"));
   //begin troll control
   if ($user) {
      list($troll) = mysql_fetch_row(mysql_query("select count(*) from pollcomments where (name='$name') and (to_days(now()) - to_days(date) < 1)"));
   } elseif(!$score) {
      list($troll) = mysql_fetch_row(mysql_query("select count(*) from pollcomments where (host_name='$ip') and (to_days(now()) - to_days(date) < 1)"));
   }
   if ((!$tia) && ($fake == 1) && ($troll < $troll_limit)) {
      mysql_query("insert into pollcomments values (NULL, '$pid', '$pollID', now(), '$name', '$email', '$url', '$ip', '$subject', '$comment', '$score', '0')");
   } else {
      mysql_query("UNLOCK TABLES");
      global $pdst; $pdst="1";
      include("header.php");
      if ($tia) {
         echo translate("Duplicate. Did you submit twice")." ?<br /><br /><a href=\"pollBooth.php?op=results&amp;pollID=$pollID\">".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.");
         echo "<br /><br /><a href=\"pollBooth.php?op=results&amp;pollID=$pollID\" 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.");
         echo "<br /><br /><a href=\"pollBooth.php?op=results&amp;pollID=$pollID\" class=\"NOIR\">".translate("Go Back")."</a>";
      }
      include("footer.php");
      exit;
   }
   mysql_query("UNLOCK TABLES");
   Header("Location: pollBooth.php?op=results&pollID=$pollID&mode=$mode&order=$order&thold=$thold");
}

switch($op) {

   case "Reply":
        if ($anonpost==1 OR $admin OR $user)
           reply($pid, $pollID, $mode, $order, $thold);
        else
           header("location: pollBooth.php");
        break;

   case "Preview":
   case "Prévisualiser":
        replyPreview ($pid, $pollID, $subject, $comment, $xanonpost, $mode, $order, $thold, $posttype);
        break;

   case "Ok":
        list($ibid,$pollClose)=pollSecur($pollID);
        if (!$pollClose)
           CreateTopic($xanonpost, $subject, $comment, $pid, $pollID, $host_name, $mode, $order, $thold, $posttype);
        else
           Header("Location: pollBooth.php?op=results&pollID=$pollID&mode=$mode&order=$order&thold=$thold");
        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 pollcomments SET";
                    if (($emp[1] == 9) && ($emp[0]>=0)) { # Overrated
                       $q .= " score=score-1 where tid=$tdw";
                    } elseif (($emp[1] == 10) && ($emp[0]<=4)) { # Underrated
                       $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: pollBooth.php?op=results&pollID=$pollID");
        break;

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

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