<?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                                                  */
/*                                                                      */
/* =========================                                            */
/* Based on Parts of phpBB                                              */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
if (!function_exists("Mysql_Connexion")) {include ("mainfile.php");}
include('functions.php');
if ($SuperCache) {
   $cache_obj = new cacheManager();
}
include('auth.php');
global $pdst; $pdst="1";

   if ($arbre) {$url_ret="viewtopicH.php";}else {$url_ret="viewtopic.php";}

   $Mmod=false;
   $userX = base64_decode($user);
   $userdata = explode(":", $userX);
   settype($forum, "integer");
   $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);
   $moderator=explode(" ",get_moderator($myrow[forum_moderator]));
   for ($i = 0; $i < count($moderator); $i++) {
       if (($userdata[1] == $moderator[$i])) {
          if (user_is_moderator($userdata[0],$userdata[2],$myrow[forum_access])) {
             $Mmod=true;
          }
          break;
       }
   }
   if (!$Mmod) {
      forumerror('0007');
   }

   if (($submit) and ($mode=="move")) {
      $sql = "UPDATE forumtopics SET forum_id='$newforum' WHERE topic_id='$topic'";
      if (!$r = mysql_query($sql))
         forumerro('0010');
      $sql = "UPDATE posts SET forum_id='$newforum' WHERE topic_id='$topic'";
      if (!$r = mysql_query($sql))
         forumerror('0010');
      $sql = "DELETE FROM forum_read where topicid='$topic'";
      if (!$r = mysql_query($sql))
         forumerror('0001');
      $sql = "UPDATE $upload_table SET forum_id='$newforum' WHERE apli='forum_npds' and topic_id='$topic'";
      mysql_query($sql);
      $sql = "SELECT arbre FROM forums where forum_id='$newforum'";
      $arbre=mysql_fetch_array(mysql_query($sql));
      if ($arbre[arbre]) {$url_ret="viewtopicH.php";} else {$url_ret="viewtopic.php";}
      include("header.php");
      opentable();
      echo "<p align=\"center\" class=\"NOIR\">".translate("The topic has been moved.")."</p><br /> - <a href=\"$url_ret?topic=$topic&amp;forum=$newforum\" class=\"NOIR\">".translate("Click here to view the updated topic.")."</a><br /><br /> - <a href=\"forum.php\" class=\"NOIR\">".translate("Click here to return to the forum index.")."</a>";
      closetable();
      Q_Clean();
      include("footer.php");
   } else {
      if ($Mmod) {
         switch ($mode) {
            case 'move':
               include("header.php");
               opentable();
               echo "<br /><form action=\"topicadmin.php\" method=\"post\">
                     <table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\">
                     <tr>
                     <td class=\"HEADER\">".translate("Move Topic To: ")."</td>
                     <td class=\"HEADER\"><select class=\"TEXTBOX_STANDARD\" name=\"newforum\" size=\"0\">";
               $sql = "SELECT forum_id, forum_name FROM forums WHERE forum_id != '$forum' ORDER BY cat_id,forum_index,forum_id";
               if ($result = mysql_query($sql)) {
                  if ($myrow = mysql_fetch_array($result)) {
                     do {
                        echo "<option value=\"$myrow[forum_id]\">$myrow[forum_name]</option>\n";
                     } while($myrow = mysql_fetch_array($result));
                  } else {
                     echo "<option value=\"-1\">".translate("No More Forums")."</option>\n";
                  }
               } else {
                  echo "<option value=\"-1\">Database Error</OPTION>\n";
               }
               echo "</select>&nbsp;&nbsp;</td><td align=\"center\">
               <input type=\"hidden\" name=\"mode\" value=\"move\">
               <input type=\"hidden\" name=\"topic\" value=\"$topic\">
               <input type=\"hidden\" name=\"forum\" value=\"$forum\">
               <input type=\"hidden\" name=\"arbre\" value=\"$arbre\">
               <input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"submit\" value=\"".translate("Move Topic")."\">
               </td></tr></table>
               </form>";
               closetable();
               include("footer.php");
               break;
            case 'del':
               $sql = "DELETE FROM posts WHERE topic_id = '$topic'";
               if (!$result = mysql_query($sql))
                  forumerror('0009');
               $sql = "DELETE FROM forumtopics WHERE topic_id = '$topic'";
               if (!$result = mysql_query($sql))
                  forumerror('0010');
               $sql = "DELETE FROM forum_read where topicid = '$topic'";
               if (!$r = mysql_query($sql))
                  forumerror('0001');
               control_efface_post ("forum_npds", "",$topic,"");
               header("location: viewforum.php?forum=$forum");
               break;
            case 'lock':
               $sql = "UPDATE forumtopics SET topic_status = 1 WHERE topic_id = '$topic'";
               if (!$r = mysql_query($sql))
                  forumerror('0011');
               header("location: $url_ret?topic=$topic&forum=$forum");
               break;
            case 'unlock':
               $sql = "UPDATE forumtopics SET topic_status = '0', topic_first='1' WHERE topic_id = '$topic'";
               if (!$r = mysql_query($sql))
                  forumerror('0012');
               header("location: $url_ret?topic=$topic&forum=$forum");
               break;
            case 'first':
               $sql = "UPDATE forumtopics SET topic_status = '1', topic_first='0' WHERE topic_id = '$topic'";
               if (!$r = mysql_query($sql))
                  forumerror('0011');
               header("location: $url_ret?topic=$topic&forum=$forum");
               break;
            case 'viewip':
               include("header.php");
               opentable();
               $sql = "SELECT u.uname, p.poster_ip, p.poster_dns FROM users u, posts p WHERE p.post_id = '$post' AND u.uid = p.poster_id";
               if (!$r = mysql_query($sql))
                  forumerror('0013');
               if (!$m = mysql_fetch_array($r))
                  forumerror('0014');
               echo "<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\">
                     <tr>
                     <td class=\"HEADER\" colspan=\"2\">".translate("Users IP and Account information")."</td>
                     </tr><tr>
                     <td>".translate("Nickname: ")."</td>
                     <td>$m[uname]</td>
                     </tr><tr>
                     <td>".translate("User IP: ")."</td>
                     <td>$m[poster_ip]</td>
                     </tr><tr>
                     <td>".translate("User DNS: ")."</td>
                     <td>$m[poster_dns]</td>
                     </tr>
                     </table>";
               echo "<br /><p align=\"center\"><a href=\"$url_ret?topic=$topic&amp;forum=$forum\" class=\"NOIR\">".translate("Go Back")."</a></p>";
               closetable();
               include("footer.php");
               break;
            case 'aff':
               $sql = "UPDATE posts SET post_aff = '$ordre' WHERE post_id = '$post'";
               mysql_query($sql);
               header("location: $url_ret?topic=$topic&forum=$forum");
               break;
         }
      } else {
         include("header.php");
         opentable();
         echo "<p align=\"center\">".translate("You are not the moderator of this forum therefor you cannot perform this function.")."<br /><br />";
         echo "<a href=\"javascript:history.go(-1)\" class=\"NOIR\">".translate("Go Back")."</a></p>";
         closetable();
         include("footer.php");
      }
   }
?>