<?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   */
/* 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.       */
/************************************************************************/

function get_total_topics($forum_id) {
   $sql = "SELECT count(*) AS total FROM forumtopics WHERE forum_id='$forum_id'";
   if (!$result = mysql_query($sql))
      return("ERROR");
   if (!$myrow = mysql_fetch_array($result))
      return("ERROR");

   mysql_free_result($result);
   return($myrow[total]);
}

function get_total_posts($fid, $tid, $type, $Mmod) {
   if ($Mmod) {
      $post_aff="";
   } else {
      $post_aff=" and post_aff='1'";
   }
   switch($type) {
      case 'forum':
           $sql = "SELECT count(*) AS total FROM posts WHERE forum_id='$fid'$post_aff";
           break;

      case 'topic':
           $sql = "SELECT count(*) AS total FROM posts WHERE topic_id='$tid'$post_aff";
           break;

      case 'user':
           forumerror(0031);
   }

   if (!$result = mysql_query($sql))
      return("ERROR");
   if (!$myrow = mysql_fetch_array($result))
      return("0");

   mysql_free_result($result);
   return($myrow[total]);
}

function get_last_post($id, $type, $cmd, $Mmod) {
   // $Mmod ne sert plus - maintenu pour compatibilité
   switch($type) {
      case 'forum':
           $sql1 = "SELECT topic_time, current_poster FROM forumtopics WHERE forum_id = '$id' ORDER BY topic_time DESC LIMIT 0,1";
           $sql2 = "SELECT uname FROM users WHERE uid=";
           break;

      case 'topic':
           $sql1 = "SELECT topic_time, current_poster FROM forumtopics WHERE topic_id = '$id'";
           $sql2 = "SELECT uname FROM users WHERE uid=";
           break;
   }
   if (!$result = mysql_query($sql1))
      return("ERROR");

   if ($cmd=="infos") {
      if (!$myrow = mysql_fetch_array($result)) {
         $val=translate("No posts");
      } else {
         $rowQ1=Q_Select ($sql2.$myrow[1], 3600);
         if (is_array($rowQ1))
            list(,$myrow2) = each($rowQ1);
         $val=convertdate($myrow[0])."<br /><a href=\"user.php?op=userinfo&amp;uname=$myrow2[0]\" style=\"font-size: 10px;\">$myrow2[0]</a>";
      }
   }
   mysql_free_result($result);
   return($val);
}

function convertdateTOtimestamp($myrow) {
   if (substr($myrow,2,1)=="-") {
      $day=substr($myrow,0,2);
      $month=substr($myrow,3,2);
      $year=substr($myrow,6,4);
   } else {
      $day=substr($myrow,8,2);
      $month=substr($myrow,5,2);
      $year=substr($myrow,0,4);
   }
   $hour=substr($myrow,11,2);
   $mns=substr($myrow,14,2);
   $sec=substr($myrow,17,2);
   $tmst=mktime($hour,$mns,$sec,$month,$day,$year);
   return ($tmst);
}
function post_convertdate($tmst) {
   if ($tmst>0)
      $val=date(translate("dateinternal"),$tmst);
   else
      $val="";
   return ($val);
}
function convertdate($myrow) {
   $tmst=convertdateTOtimestamp($myrow);
   $val=post_convertdate($tmst);
   return ($val);
}

function get_moderator($user_id) {
   $user_id=str_replace(",","' or uid='",$user_id);
   if ($user_id == 0)
      return("None");

   $rowQ1=Q_Select("SELECT uname FROM users WHERE uid='$user_id'", 3600);
   while(list(,$uname) = each($rowQ1)) {
      $myrow[uname].=$uname[uname]." ";
   }
   return(chop($myrow[uname]));
}

function user_is_moderator($uidX,$passwordX,$forum_accessX) {
   $result1=mysql_query("SELECT pass FROM users where uid = '$uidX'");
   $result2=mysql_query("SELECT level FROM users_status where uid = '$uidX'");
   $userX=mysql_fetch_array($result1);
   $password = $userX[pass];
   $userX=mysql_fetch_array($result2);
   if ((md5($password) == $passwordX) and ($forum_accessX<=$userX[level]) and ($userX[level]>1)) {
      return ($userX[level]);
   } else {
      return(false);
   }
}

function get_userdata_from_id($userid) {
   $sql1 = "SELECT * FROM users WHERE uid='$userid'";
   $sql2 = "SELECT * FROM users_status WHERE uid='$userid'";
   if (!$result = mysql_query($sql1)) {
      $userdata = array("error" => "1");
      return ($userdata);
   }
   if (!$myrow = mysql_fetch_array($result)) {
      $userdata = array("error" => "1");
      return ($userdata);
   }
   $myrow=array_merge($myrow,mysql_fetch_array(mysql_query($sql2)));
   return($myrow);
}

function get_userdata($username) {
   $sql = "SELECT * FROM users WHERE uname = '$username'";
   if (!$result = mysql_query($sql))
      $userdata = array("error" => "1");
   if (!$myrow = mysql_fetch_array($result))
      $userdata = array("error" => "1");
   return($myrow);
}

function does_exists($id, $type) {
   switch($type) {
      case 'forum':
           $sql = "SELECT forum_id FROM forums WHERE forum_id = '$id'";
           break;
      case 'topic':
           $sql = "SELECT topic_id FROM forumtopics WHERE topic_id = '$id'";
           break;
   }
   if (!$result = mysql_query($sql))
      return(0);
   if (!$myrow = mysql_fetch_array($result))
      return(0);
   return(1);
}

function is_locked($topic) {
   $sql = "SELECT topic_status FROM forumtopics WHERE topic_id = '$topic'";
   if (!$r = mysql_query($sql))
      return(FALSE);
   if (!$m = mysql_fetch_array($r))
      return(FALSE);
   if ($m[topic_status] == 1)
      return(TRUE);
   else
      return(FALSE);
}

function Smilie($message) {
   global $theme;
   if ($ibid=theme_image("forum/smilies/smilies.php")) {$imgtmp="themes/$theme/images/forum/smilies/";} else {$imgtmp="images/forum/smilies/";}
   if (file_exists($imgtmp."smilies.php")) {
      include ($imgtmp."smilies.php");
      foreach ($smilies AS $tab_smilies) {
         $suffix=strtoLower(substr(strrchr($tab_smilies[1],'.'),1));
         if ($suffix=="gif")
            $message = str_replace($tab_smilies[0], "<img src='".$imgtmp.$tab_smilies[1]."'>", $message);
         else
            $message = str_replace($tab_smilies[0], $tab_smilies[1], $message);
      }
   }
   if ($ibid=theme_image("forum/smilies/more/smilies.php")) {$imgtmp="themes/$theme/images/forum/smilies/more/";} else {$imgtmp="images/forum/smilies/more/";}
   if (file_exists($imgtmp."smilies.php")) {
      include ($imgtmp."smilies.php");
      foreach ($smilies AS $tab_smilies) {
         $message = str_replace($tab_smilies[0], "<img src='".$imgtmp.$tab_smilies[1]."'>", $message);
      }
   }
   return($message);
}

function smile($message) {
   global $theme;
   if ($ibid=theme_image("forum/smilies/smilies.php")) {$imgtmp="themes/$theme/images/forum/smilies/";} else {$imgtmp="images/forum/smilies/";}
   if (file_exists($imgtmp."smilies.php")) {
      include ($imgtmp."smilies.php");
      foreach ($smilies AS $tab_smilies) {
         $message = str_replace("<img src='".$imgtmp.$tab_smilies[1]."'>", $tab_smilies[0],  $message);
      }
   }
   if ($ibid=theme_image("forum/smilies/more/smilies.php")) {$imgtmp="themes/$theme/images/forum/smilies/more/";} else {$imgtmp="images/forum/smilies/more/";}
   if (file_exists($imgtmp."smilies.php")) {
      include ($imgtmp."smilies.php");
      foreach ($smilies AS $tab_smilies) {
         $message = str_replace("<img src='".$imgtmp.$tab_smilies[1]."'>", $tab_smilies[0],  $message);
      }
   }
   return($message);
}

function putitems_more() {
   global $theme;
   echo translate("Click on Smilies to insert it on your Message")." :<br />";
   if ($ibid=theme_image("forum/smilies/more/smilies.php")) {$imgtmp="themes/$theme/images/forum/smilies/more/";} else {$imgtmp="images/forum/smilies/more/";}
   if (file_exists($imgtmp."smilies.php")) {
      include ($imgtmp."smilies.php");
      echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"4\"><tr>";
      $i=0;
      foreach ($smilies AS $tab_smilies) {
         if ($tab_smilies[3]) {
            echo "<td width=\"20%\" align=\"center\"><a href=\"javascript: DoAdd('true','message',' ".$tab_smilies[0]." ');\"><img src=\"".$imgtmp.$tab_smilies[1]."\" border=\"0\" alt=\"$tab_smilies[2]";
            if ($tab_smilies[2]) echo " => ";
            echo $tab_smilies[0]."\" /></a></td>";
            $i++;
            if ($i==5) {
               echo "</tr><tr>";
               $i=0;
            }
         }
      }
      echo "</tr></table>";
   }
}
function putitems() {
   global $theme;
   echo translate("Click on Smilies to insert it on your Message")." :<br /><span style =\"background-color: #F8F8F8; width:100%;\">&nbsp;";
   if ($ibid=theme_image("forum/smilies/smilies.php")) {$imgtmp="themes/$theme/images/forum/smilies/";} else {$imgtmp="images/forum/smilies/";}
   if (file_exists($imgtmp."smilies.php")) {
      include ($imgtmp."smilies.php");
      foreach ($smilies AS $tab_smilies) {
         if ($tab_smilies[3]) {
            echo "<a href=\"javascript: emoticon('".$tab_smilies[0]."');\"><img src=\"".$imgtmp.$tab_smilies[1]."\" border=\"0\" alt=\"$tab_smilies[2]";
            if ($tab_smilies[2]) echo " => ";
            echo $tab_smilies[0]."\" /></a> ";
         }
      }
   }
   echo "</span>";
}

function HTML_Add($allow_forum_hide) {
   $affich="<hr noshade class=\"ONGL\">"
          ."<a href=\"javascript: addText('<b>','</b>');\"><img src=\"editeur/editor_images/med_bold.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;"
          ."<a href=\"javascript: addText('<i>','</i>');\"><img src=\"editeur/editor_images/med_italic.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;"
          ."<a href=\"javascript: addText('<u>','</u>');\"><img src=\"editeur/editor_images/med_underline.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;"
          ."<a href=\"javascript: addText('<p align=\'left\'>','</p>');\"><img src=\"editeur/editor_images/left.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;"
          ."<a href=\"javascript: addText('<p align=\'center\'>','</p>');\"><img src=\"editeur/editor_images/centre.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;"
          ."<a href=\"javascript: addText('<p align=\'right\'>','</p>');\"><img src=\"editeur/editor_images/right.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;"
          ."<a href=\"javascript: addText('<p align=\'justify\'>','</p>');\"><img src=\"editeur/editor_images/justify.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;"
          ."<br /><br />"
          ."<a href=\"javascript: addText('<ul><li>','</li></ul>');\"><img src=\"editeur/editor_images/para_bul.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;"
          ."<a href=\"javascript: addText('<ol><li>','</li></ol>');\"><img src=\"editeur/editor_images/para_num.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;"
          ."<a href=\"javascript: addText(' http://www.','');\"><img src=\"editeur/editor_images/med_link.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;"
          ."<a href=\"javascript: addText('<table width=\'90%\' cellspacing=\'1\' cellpadding=\'3\' border=\'0\' align=\'center\' class=\'LIGNB\'><tr><td>',' ... </td></tr></table>');\"><img src=\"editeur/editor_images/med_table.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;";

   if ($allow_forum_hide)
      $affich.="<a href=\"javascript: addText('[hide]','[/hide]');\"><img src=\"editeur/editor_images/med_hiden.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;";

   $affich.="<a href=\"javascript: addText('<table width=\'90%\' cellspacing=\'1\' cellpadding=\'3\' border=\'0\' align=\'center\' class=\'LIGNA\'><tr><td>Spoiler</td></tr><tr><td><table width=\'100%\' border=\'0\' cellpadding=\'1\' cellspacing=\'0\'><tr><td style=\'background-color: #FFFFFF;\'><span style=\'color: #FFFFFF;\'> ...\\n</span></td></tr></table></td></tr></table>','');\"><img src=\"editeur/editor_images/med_spoiler.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;"
          ."<a href=\"javascript: addText('[code]\\n','\\n[/code]');\"><img src=\"editeur/editor_images/med_code.gif\" border=\"0\" alt=\"\" width=\"18\" height=\"18\" /></a>&nbsp;";

   global $allow_bbcode;
   if ($allow_bbcode) {
      if ($ibid=theme_image("forum/smilies/more/smilies.php")) {$imgtmp="themes/$theme/images/forum/smilies/more/";} else {$imgtmp="images/forum/smilies/more/";}
      if (file_exists($imgtmp."smilies.php"))
         $affich.="<hr noshade class=\"ONGL\"><br /><a href=\"javascript:void(0);\" onClick=\"window.open('more_emoticon.php','EMOTICON','menubar=no,location=no,directories=no,status=no,copyhistory=no,height=250,width=350,toolbar=no,scrollbars=yes,resizable=yes');\">".translate("More smilies")."</a>";
   }
   return($affich);
}

function emotion_add($image_subject) {
   global $theme;

   if ($ibid=theme_image("forum/subject/index.html")) {$imgtmp="themes/$theme/images/forum/subject";} else {$imgtmp="images/forum/subject";}
   $handle=opendir($imgtmp);
   while ($file = readdir($handle)) {
      $filelist[] = $file;
   }
   asort($filelist);
   $count=1;
   $temp="";
   while (list ($key, $file) = each ($filelist)) {
      if (!eregi("(.gif|.jpg|.png)$",$file)) continue;
      if ($image_subject!="") {
         if ($file == $image_subject) {
            $temp .= "<input type=\"radio\" value=\"$file\" name=\"image_subject\" checked>&nbsp;";
         } else {
            $temp .= "<input type=\"radio\" value=\"$file\" name=\"image_subject\">&nbsp;";
         }
      } else {
         $temp .= "<input type=\"radio\" value=\"$file\" name=\"image_subject\" checked>&nbsp;";
         $image_subject="no image";
      }
      $temp .= "<img src=\"images/forum/subject/$file\" border=\"0\" alt=\"\" />&nbsp;";
      if ($count == 11) { $temp .= "<br />"; $count = 0; }
      $count++;
   }
   return $temp;
}

function make_clickable($text) {
   $ret = eregi_replace(" ([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", " <a href='\\1://\\2\\3' target='_blank' class='NOIR'>\\1://\\2\\3</a>", $text);
   if (eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$ret)) {
      $ret="<a href='mailto:".anti_spam($ret)."' target='_blank' class='NOIR'>$ret</a>";
   }
   return($ret);
}

function undo_htmlspecialchars($input) {
   $input = preg_replace("/&gt;/i", ">", $input);
   $input = preg_replace("/&lt;/i", "<", $input);
   $input = preg_replace("/&quot;/i", "\"", $input);
   $input = preg_replace("/&amp;/i", "&", $input);
   return ($input);
}

function searchblock() {
   echo "<br /><table width=\"100%\" cellspacing=\"0\" cellpadding=\"4\" border=\"0\">
   <form action=\"searchbb.php\" method=\"post\"><tr><td nowrap class=\"HEADER\">
   <input type=\"hidden\" name=\"addterm\" value=\"any\">
   <input type=\"hidden\" name=\"sortby\" value=\"p.post_id\">";
   echo "<center><b>".translate('Search')."</b>&nbsp;&nbsp;<input class=\"TEXTBOX_STANDARD\" type=\"text\" name=\"term\" size=\"50\">&nbsp;&nbsp;<input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"submit\" Value=\"".translate("Submit")."\"></center>";
   echo "</td></tr></form></table><br />";
}

function member_qualif($poster, $posts, $rank) {
   global $anonymous;
   $tmp="";
   if ($ibid=theme_image("forum/rank/post.gif")) {$imgtmpP=$ibid;} else {$imgtmpP="images/forum/rank/post.gif";}
   if ($ibid=theme_image("forum/rank/level.gif")) {$imgtmpN=$ibid;} else {$imgtmpN="images/forum/rank/level.gif";}
   $tmp="<img src=\"".$imgtmpP."\" border=\"0\" alt=\"\" />".$posts."&nbsp;&nbsp;";
   if ($poster!=$anonymous) {
      if ($posts>=10 and $posts<30) {$nux=1;}
      if ($posts>=30 and $posts<100) {$nux=2;}
      if ($posts>=100 and $posts<300) {$nux=3;}
      if ($posts>=300 and $posts<1000) {$nux=4;}
      if ($posts>=1000) {$nux=5;}
      for ($i=0; $i<$nux; $i++) {
         $tmp.="<img src=\"".$imgtmpN."\" border=\"\" alt=\"\" />&nbsp;";
      }
      
      if ($rank) {
         if ($ibid=theme_image("forum/rank/".$rank.".gif")) {$imgtmpA=$ibid;} else {$imgtmpA="images/forum/rank/".$rank.".gif";}
         $rank="rank".$rank;
         global $$rank;
         $tmp.="<br /><img src=\"".$imgtmpA."\" border=\"\" alt=\"\" />&nbsp;".aff_langue($$rank);
      }
   }
   return ($tmp);
}

function forumerror($e_code) {
   global $sitename, $header;

   if ($e_code == "0001") {
      $error_msg = translate("Could not connect to the forums database.");
   }
   if ($e_code == "0002") {
      $error_msg = translate("The forum you selected does not exist. Please go back and try again.");
   }
   if ($e_code == "0004") {
      $error_msg = translate("Could not query the topics database.");
   }
   if ($e_code == "0005") {
      $error_msg = translate("Error getting messages from the database.");
   }
   if ($e_code == "0006") {
      $error_msg = translate("Please enter the Nickname and the Password.");
   }
   if ($e_code == "0007") {
      $error_msg = translate("You are not the Moderator of this forum therefore you can't perform this function.");
   }
   if ($e_code == "0008") {
      $error_msg = translate("You did not enter the correct password, please go back and try again.");
   }
   if ($e_code == "0009") {
      $error_msg = translate("Could not remove posts from the database.");
   }
   if ($e_code == "0010") {
      $error_msg = translate("Could not move selected topic to selected forum. Please go back and try again.");
   }
   if ($e_code == "0011") {
      $error_msg = translate("Could not lock the selected topic. Please go back and try again.");
   }
   if ($e_code == "0012") {
      $error_msg = translate("Could not unlock the selected topic. Please go back and try again.");
   }
   if ($e_code == "0013") {
      $error_msg = translate("Could not query the database.")."<BR>Error: mysql_error()";
   }
   if ($e_code == "0014") {
      $error_msg = translate("No such user or post in the database.");
   }
   if ($e_code == "0015") {
      $error_msg = translate("Search Engine was unable to query the forums database.");
   }
   if ($e_code == "0016") {
      $error_msg = translate("That user does not exist. Please go back and search again.");
   }
   if ($e_code == "0017") {
      $error_msg = translate("You must type a subject to post. You can't post an empty subject. Go back and enter the subject");
   }
   if ($e_code == "0018") {
      $error_msg = translate("You must choose message icon to post. Go back and choose message icon.");
   }
   if ($e_code == "0019") {
      $error_msg = translate("You must type a message to post. You can't post an empty message. Go back and enter a message.");
   }
   if ($e_code == "0020") {
      $error_msg = translate("Could not enter data into the database. Please go back and try again.");
   }
   if ($e_code == "0021") {
      $error_msg = translate("Can't delete the selected message.");
   }
   if ($e_code == "0022") {
      $error_msg = translate("An error ocurred while querying the database.");
   }
   if ($e_code == "0023") {
      $error_msg = translate("Selected message was not found in the forum database.");
   }
   if ($e_code == "0024") {
      $error_msg = translate("You can't reply to that message. It wasn't sent to you.");
   }
   if ($e_code == "0025") {
      $error_msg = translate("You can't post a reply to this topic, it has been locked. Contact the administrator if you have any question.");
   }
   if ($e_code == "0026") {
      $error_msg = translate("The forum or topic you are attempting to post to does not exist. Please try again.");
   }
   if ($e_code == "0027") {
      $error_msg = translate("You must enter your username and password. Go back and do so.");
   }
   if ($e_code == "0028") {
      $error_msg = translate("You have entered an incorrect password. Go back and try again.");
   }
   if ($e_code == "0029") {
      $error_msg = translate("Couldn't update post count.");
   }
   if ($e_code == "0030") {
      $error_msg = translate("The forum you are attempting to post to does not exist. Please try again.");
   }
   if ($e_code == "0031") {
      return(0);
   }
   if ($e_code == "0035") {
      $error_msg = translate("You can't edit a post that's not yours.");
   }
   if ($e_code == "0036") {
      $error_msg = translate("You do not have permission to edit this post.");
   }
   if ($e_code == "0037") {
      $error_msg = translate("You did not supply the correct password or do not have permission to edit this post. Please go back and try again.");
   }
   if ($e_code == "0101") {
      $error_msg = translate("You can't reply to that message.");
   }
   if (!isset($header)) {
      global $pdst; $pdst=0;
      include("header.php");
   }
   OpenTable();
   echo "<center><b>$sitename ".translate("Forum Error")."</b><br /><br />";
   echo translate("Error Code:")." $e_code<br /><br />";
   echo "$error_msg<br /><br />";
   echo "[ <a href=\"javascript:history.go(-1)\" class=\"NOIR\">".translate("Go Back")."</a> ]<br /><center>";
   CloseTable();
   include("footer.php");
   die("");
}

function control_efface_post($apli,$post_id,$topic_id,$IdForum) {
   global $upload_table;
   include ("modules/upload/include_forum/upload.conf.forum.php");
   $sql1= "SELECT att_id, att_name, att_path from $upload_table WHERE apli='$apli' and";
   $sql2= "DELETE FROM $upload_table WHERE apli='$apli' and";
   if ($IdForum!='') {
      $sql1.=" forum_id = '$IdForum'";
      $sql2.=" forum_id = '$IdForum'";
   } elseif ($post_id!='') {
      $sql1.=" post_id = '$post_id'";
      $sql2.=" post_id = '$post_id'";
   } elseif ($topic_id!='') {
      $sql1.=" topic_id = '$topic_id'";
      $sql2.=" topic_id = '$topic_id'";
   }
   $result=mysql_query($sql1);
   while(list($att_id, $att_name, $att_path)=mysql_fetch_row($result)){
      $fic=$DOCUMENTROOT.$att_path.$att_id.".".$apli.".".$att_name;
      @unlink($fic);
   }
   @mysql_query($sql2);
}

function control_hide_post($message,$show_hide) {
   if (!(strpos($message, "[") && strpos($message, "]"))) {
      return $message;
   }
   $message = " ".$message;
   $patterns = array("#\[hide\](.*?)\[\/hide\]#si");
   if ($show_hide){
      $replacements = array("<table border=\"0\" align=\"center\" width=\"90%\" cellpadding=\"3\" cellspacing=\"1\"><tr><td><span class=\"ROUGE\" style=\"font-size: 10px;\">".translate("Protected Area")." -></span>\\1<span class=\"ROUGE\" style=\"font-size: 10px;\"><- ".translate("Protected Area")."</span></td></tr></table>");
   } else {
      $replacements = array("<table border=\"0\" align=\"center\" width=\"90%\" cellpadding=\"3\" cellspacing=\"1\"><tr><td><span class=\"ROUGE\" style=\"font-size: 10px;\">... ".translate("Protected Area")." ...</span></td></tr></table>");
   }

   $message = preg_replace($patterns, $replacements, $message);
   $message = substr($message,1);
   return $message;
}

function autorize() {
   global $apli,$IdPost,$IdTopic,$IdForum,$user;
   list($poster_id)= mysql_fetch_array(mysql_query("SELECT poster_id FROM posts WHERE post_id='$IdPost' and topic_id='$IdTopic'"));
   $Mmod=false;
   if ($poster_id) {
      $myrow = mysql_fetch_array(mysql_query("SELECT forum_moderator FROM forums WHERE (forum_id='$IdForum')"));
      if ($myrow) {
         $moderator = get_moderator($myrow[forum_moderator]);
         $moderator=explode(" ",$moderator);
         if (isset($user)) {
            $userX = base64_decode($user);
            $userdata = explode(":", $userX);
            for ($i = 0; $i < count($moderator); $i++) {
               if (($userdata[1]==$moderator[$i])) { $Mmod=true; break;}
            }
            if ($userdata[0]==$poster_id) {
               $Mmod=true;
            }
         }
      }
   }
   return ($Mmod);
}

function anti_flood ($modoX, $paramAFX, $poster_ipX, $userdataX, $gmtX) {
   // anti_flood : nd de post dans les 90 puis 30 dernières minutes / les modérateurs echappent à cette règle
   // security.log est utilisée pour enregistrer les tentatives
   global $anonymous;
   if (!$userdataX[uname]) $compte=$anonymous; else $compte=$userdataX[uname];

   if ((!$modoX) AND ($paramAFX>0)) {
      $sql="SELECT count(poster_ip) as total FROM posts WHERE post_time>'";
      if ($userdataX[uid]!=1)
         $sql2="' AND (poster_ip='$poster_ipX' OR poster_id='$userdataX[uid]')";
      else
         $sql2="' AND poster_ip='$poster_ipX'";

      $timebase=date("Y-m-d H:i",time()+($gmtX*3600)-5400);
      list($time90)=mysql_fetch_row(mysql_query ($sql.$timebase.$sql2));
      if ($time90>($paramAFX*2)) {
         Ecr_Log("security", "Forum Anti-Flood : ".$compte, "");
         forumerror(translate("You are not allowed to post in this forum"));
      } else {
         $timebase=date("Y-m-d H:i",time()+($gmtX*3600)-1800);
         list($time30)=mysql_fetch_row(mysql_query($sql.$timebase.$sql2));
         if ($time30>$paramAFX) {
            Ecr_Log("security", "Forum Anti-Flood : ".$compte, "");
            forumerror(translate("You are not allowed to post in this forum"));
         }
      }
   }
}
?>