<?php


######################################################################
# Modulo Splatt Forum per PHP-NUKE ver.5.X
#-------------------------
# Versione: 3.1
#
# Copyright (c) 2002 by:
#
# Giorgio Ciranni (~Splatt~)
# (http://www.splatt.it)
# (webmaster@splatt.it)
#
# Supporto tecnico disponibile sul Forum di www.splatt.it
######################################################################
# PHP-NUKE Add-On 2.0 :
# =====================
#
#              PHPBB Integration 
#        Brought to you by PHPNuke Add-On Team
#
# Copyright (c) 2000 by Richard Tirtadji AKA King Richard (rtirtadji@hotmail.com)
#                       Hutdik Hermawan AKA hotFix (hutdik76@hotmail.com)
# http://www.phpnuke.web.id
#
#
######################################################################
# PHPBB
#
# Copyright (C) 2000 by James Atkinson (james@totalgeek.org)
# http://www.phpbb.com
#
#
######################################################################
# Splatt Forum 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.
# Splatt Forum is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   
# 02111-1307  USA
######################################################################

$module_name = "$name";

include("config.php");
include("modules/".$module_name."/functions.php");
include("modules/".$module_name."/auth.php");


if($forum == -1)
        $forum += 2;

$sql = "SELECT f.forum_id, f.forum_type, f.forum_pass, f.forum_name, u.uname, u.uid,m.forum_id,m.user_id FROM ${prefix}_forums f, ".$prefix."_users u, ${prefix}_forum_mods m WHERE f.forum_id = '$forum' AND m.forum_id = '$forum' AND m.user_id = u.uid";
if(!$result = mysql_query($sql, $db))
        die("<font size=+1>"._ERRORE1."</font><hr>"._FCOULDNOT."");
if(!$myrow = mysql_fetch_array($result))
        die(""._FNOTEXIST."");
$forum_name = stripslashes($myrow[forum_name]);
$moderator = $myrow[uname];
$moderators = get_moderators($forum, $db);
$mypass = $myrow[forum_pass];
$forum_id = $myrow[forum_id];



$valore = "$passwd:$forum_id";
$info = explode(":",$HTTP_COOKIE_VARS["Accessfpriv"]);	
if(($info[0] != $mypass || $info[1] != $forum_id) && $myrow[forum_type] == 1){
	setcookie ("Accessfpriv", $valore, time()+(24*60*60));
}

include('header.php');

	if($myrow[forum_type] == 1 && ($info[0] != $mypass || $info[1] != $forum_id) && (($myrow[forum_name] != $forum_name)  || ($bypass != 1))){

?>

<TABLE BORDER="0" WIDTH="100%"><TR><TD ALIGN=LEFT>
<FONT SIZE=1><b>

<?
echo ""._MODERATED."&nbsp;&nbsp;&nbsp;";
$count = 0;
reset ($moderators);
while(list($null, $mods) = each($moderators)) {
        while(list($mod_id, $mod_name) = each($mods)) {

                if($count > 0) { echo " , "; }

                echo"<a href=\"modules.php?name=Your_Account&op=userinfo&uname=$mod_name\">$mod_name</a>";

                $count++;
        }
}

?>
</b><br><br>
<a href="modules.php?op=modload&name=<?php echo $module_name?>&file=index"><?php echo "$sitename : "._FINDEX;?></a> <b>» »</b>
<a href="modules.php?op=modload&name=<?php echo $module_name?>&file=viewforum&forum=<?php echo $forum?>"><?php echo stripslashes($forum_name)?></a>


</TD></TR></TABLE>
<FORM ACTION="modules.php?op=modload&name=<?php echo $module_name?>&file=viewforum" METHOD="POST">
<TABLE BORDER="0" CELLPADDING="1" CELLSPACING="0" ALIGN="CENTER" VALIGN="TOP" WIDTH="95%"><TR><TD  BGCOLOR="<?php echo $table_bgcolor?>">
<TABLE BORDER="0" CELLPADDING="1" CELLSPACING="1" WIDTH="100%">
<TR BGCOLOR="<?php echo $bgcolor2?>" ALIGN="LEFT">
        <TD ALIGN="CENTER"><FONT COLOR="<?php echo $textcolor1;?>"><img src="images/forum/keys.gif" border="0" height="32" width="32" alt=""><br><?php echo _FPRIVATE?></FONT></TD>
</TR>
<TR BGCOLOR="<?php echo $bgcolor1?>" ALIGN="LEFT">
        <TD ALIGN="CENTER"><INPUT TYPE="PASSWORD" NAME="passwd" SIZE="25" MAXLENGTH="30"></TD>
</TR>
<TR BGCOLOR="<?php echo $bgcolor2?>" ALIGN="LEFT">
        <TD ALIGN="CENTER">
                <INPUT TYPE="HIDDEN" NAME="forum" VALUE="<?php echo $forum?>">
                <INPUT TYPE="SUBMIT" NAME="submit" VALUE="Enter">
                <INPUT TYPE="HIDDEN" NAME="bypass" VALUE="1">
                <INPUT TYPE="RESET" VALUE="Clear">
        </TD>
</TR>
</TABLE></TD></TR></TABLE>
</FORM>
<?php

}
else {

        if(($passwd != $mypass && $mypass != $info[0]) && $myrow[forum_type] >= 1)
                die("<center><h1>Errore - Password Incorretta!</h1><br><a href=javascript:history.go(-1)>Back</a></center>");


?>

<TABLE BORDER="0" WIDTH="100%"><TR><TD ALIGN=LEFT>
<FONT SIZE=1><b>


<?
echo _MODERATED;

$count = 0;
reset ($moderators);
while(list($null, $mods) = each($moderators)) {
        while(list($mod_id, $mod_name) = each($mods)) {

                if($count > 0) { echo " , "; }

                echo "<a href=\"modules.php?name=Your_Account&op=userinfo&uname=$mod_name\">$mod_name</a>";

                $count++;
        }
}

?>

</b><br><br>
<a href="modules.php?op=modload&name=<?php echo $module_name?>&file=index"><?php echo "$sitename : "._FINDEX;?></a> <b>» »</b>
<a href="modules.php?op=modload&name=<?php echo $module_name?>&file=viewforum&forum=<?php echo $forum?>"><?php echo stripslashes($forum_name)?></a></FONT>
</TD><TD ALIGN=RIGHT><a href="modules.php?op=modload&name=<?php echo $module_name?>&file=newtopic&forum=<?php echo $forum?>&mod=<? echo $moderator_data[uid]?>"><IMG SRC="images/forum/nuovomess<? if($currentlang == english || $currentlang == french || $currentlang == german){echo "-$currentlang";}?>.gif" BORDER="0"></a>
</TD></TR></TABLE>
<TABLE BORDER="0" CELLPADDING="1" CELLSPACING="0" ALIGN="CENTER" VALIGN="TOP" WIDTH="100%"><TR><TD>
<TABLE BORDER="0" CELLPADDING="1" CELLSPACING="1" WIDTH="100%">
<TR BGCOLOR="silver" ALIGN="LEFT">
        <TD WIDTH=2%>&nbsp;</TD>
        <TD WIDTH=2%>&nbsp;</TD>
        <TD><font size="1" COLOR="<?php echo $textcolor1?>"><B>&nbsp;<?php echo _FTOPICS;?></B></font></TD>
        <TD WIDTH=9% ALIGN="CENTER"><font size="1" COLOR="<?php echo $textcolor1?>"><B><?php echo _FREPLIES;?></B></font></TD>
        <TD WIDTH=20% ALIGN="CENTER"><font size="1" COLOR="<?php echo $textcolor1?>"><B><?php echo _FPOSTER;?></B></font></TD>
        <TD WIDTH=8% ALIGN="CENTER"><font size="1" COLOR="<?php echo $textcolor1?>"><B><?php echo _FVIEWS;?></B></font></TD>
        <TD WIDTH=15% ALIGN="CENTER"><font size="1" COLOR="<?php echo $textcolor1?>"><B><?php echo _FODATE;?></B></font></TD>
</TR>
<?php
if(!$start) $start = 0;

$sql = "SELECT t.*, u.uname FROM ${prefix}_forumtopics t left outer join ".$prefix."_users u on t.topic_poster = u.uid WHERE t.forum_id = '$forum' ORDER BY topic_time DESC LIMIT $start, $topics_per_page";
if(!$result = mysql_query($sql, $db))
        die("</table></table><font size=+1>"._ERRORE1."</font><hr>"._UNABLETOQUERY."");
if($myrow = mysql_fetch_array($result)) {
   do {
    if($myrow["topic_poster"]=='1') $myrow["uname"]=""._FANONIMO."";
      echo"<TR>\n";
      $replys = get_total_posts($myrow[topic_id], $db, "topic");
      $last_post = get_last_post($myrow[topic_id], $db, "topic");
      list ($image_subject) = mysql_fetch_array(mysql_query("SELECT image FROM ${prefix}_posts WHERE topic_id = '$myrow[topic_id]' ORDER BY post_time DESC"));
      $replys--;
      if($replys >= $hot_threshold) {
         if($userdata["lastvisit"] > $last_post[post_time])
           $image = "images/forum/icons/hot_red_folder.gif";
         else
           $image = "images/forum/icons/hot_folder.gif";
      }
      else {
         if($userdata["lastvisit"] > $last_post[post_time])
        $image = "images/forum/icons/folder.gif";
         else
           $image = "images/forum/icons/red_folder.gif";
      }
      if($myrow[topic_status] == 1)
        $image = "images/forum/icons/lock.gif";

      echo "<TD BGCOLOR=\"$bgcolor1\"><IMG SRC=\"$image\"></TD>\n";

      if($image_subject != "") echo "<TD BGCOLOR=\"$bgcolor3\"><IMG SRC=\"images/forum/subject/$image_subject\"></TD>\n";
      else echo "<TD BGCOLOR=\"$bgcolor3\"><IMG SRC=\"images/forum/icons/posticon.gif\"></TD>\n";

      $topic_title = stripslashes($myrow[topic_title]);
      echo "<TD BGCOLOR=\"$bgcolor3\"><font face=\"Verdana\" size=\"2\">&nbsp;<a href=\"modules.php?op=modload&name=".$module_name."&file=viewtopic&topic=$myrow[topic_id]&forum=$forum\">$topic_title</a></font>";

//    Keledan inizio

      $total = $replys + 1;            // $total = il totale dei post
      if($total > $posts_per_page)     // $post_per_page che auth.php Ricava dalla tabella forum_config
      {
             echo "<br>"._FPAGED.": ";
             $times = 1;
             for($x = 0; $x < $total; $x += $posts_per_page)
             { // scrive i link alle varie pagine
                   if($times != 1)
                   echo " | ";
                   echo "<a href=\"modules.php?op=modload&name=".$module_name."&file=viewtopic&topic=$myrow[topic_id]&forum=$forum&start=$x\">$times</a>";
                   $times++;
             }
      }
//    Keledan fine




ECHO "</TD>\n";
      echo "<TD BGCOLOR=\"$bgcolor1\" ALIGN=\"CENTER\" VALIGN=\"MIDDLE\"><font size=\"2\">$replys</font></TD>\n";
      echo "<TD BGCOLOR=\"$bgcolor3\" ALIGN=\"CENTER\" VALIGN=\"MIDDLE\"><font size=\"2\">$myrow[uname]</font></TD>\n";
      echo "<TD BGCOLOR=\"$bgcolor1\" ALIGN=\"CENTER\" VALIGN=\"MIDDLE\"><font size=\"2\">$myrow[topic_views]</font></TD>\n";
      echo "<TD BGCOLOR=\"$bgcolor3\" ALIGN=\"CENTER\" VALIGN=\"MIDDLE\"><font size=\"1\">".convertiData($last_post[post_time])." "._BY." $last_post[user]</font></TD></TR>\n";

   } while($myrow = mysql_fetch_array($result));
}
else {
        echo "<TD BGCOLOR=\"$bgcolor1\" colspan = 7 ALIGN=CENTER>"._FNOTOPICS."<br><a href=\"modules.php?op=modload&name=".$module_name."&file=newtopic&forum=$forum\">"._FPOSTONE."</a></TD></TR>\n";
}
?>
<TR ALIGN="right" BGCOLOR="silver">
<TD COLSPAN=7 NOWRAP >
<?php
/*
$sql = "SELECT count(*) AS total FROM ${prefix}_forumtopics WHERE forum_id = '$forum'";
if(!$r = mysql_query($sql, $db))
     die(""._FCOULDNOT."</TABLE></TABLE>");
list($all_topics) = mysql_fetch_array($r);
$count = 1;
$next = $start + $topics_per_page;
if($all_topics > $topics_per_page) {
    if($next >= $all_topics)
                 echo "<b><font size=1 color=$textcolor2>"._FNEXTP."</font></b>\n";
               else
                 echo "<a href=\"modules.php?op=modload&name=".$module_name."&file=viewforum&forum=$forum&start=$next\"><font size=1 color=$textcolor2>"._FNEXTP."</font></a><font size=1 color=$textcolor2> | </font>";
   for($x = 0; $x < $all_topics; $x++) {
      if(!($x % $topics_per_page)) {
         if($x == $start)
           echo "<b><font size=1 color=$textcolor2>$count</font></b>\n";
         else
           echo "<a href=\"modules.php?op=modload&name=".$module_name."&file=viewforum&forum=$forum&start=$x\"><font size=1 color=$textcolor2>$count</a>\n";
         $count++;
         if(!($count % 50)) echo "<BR>";
      }
   }
}
*/
// Subxero DESDE AQUI
$sql = "SELECT count(*) AS total FROM ".$prefix."_forumtopics WHERE forum_id = '$forum'";
if(!$r = mysql_query($sql, $db))
     die(""._FCOULDNOT."</TABLE></TABLE>");
list($all_topics) = mysql_fetch_array($r);
// ****** EMPEZAMOS.


		if( $all_topics > $topics_per_page ) {
			$current_page = $start/$topics_per_page + 1;
			$total_pages = ceil($all_topics/$topics_per_page);
			$goto_page = "- "._FPAGE." $current_page "._FDI." $total_pages - [ "._FGOTO." ";

			$times = 1;
			for($j = 0; $j < $all_topics; $j += $topics_per_page) {
				if ($j == $start) $goto_page .= "<b><font size=1 color=$textcolor2>$times</font></b>";
				else $goto_page .= "<a href=\"modules.php?op=modload&name=".$module_name."&file=viewforum&forum=$forum&start=$j\"><font size=1 color=$textcolor2>$times</font></a>";
				if( $total_pages > 6 && $times == $current_page + 1 && $current_page < $total_pages -4) {
					if ($current_page == 1) $goto_page .= " | <a href=\"modules.php?op=modload&name=".$module_name."&file=viewforum&forum=$forum&start=".($j+$topics_per_page)."\"><font size=1 color=$textcolor2>".($times+1)."</font></a>";
					$goto_page .= " ... ";
					$times = $total_pages - 3;
					$j = ( $total_pages - 4 ) * $topics_per_page;
				} else if ( $total_pages > 6 && $current_page > 5 && $times == 3 ) {
					$goto_page .= " ... ";
					$times = $current_page - 2;
					if ($current_page == $total_pages) $times = $times - 1;
					$j = ($times - 1)* $topics_per_page;
				} else if ( $times < $total_pages ) {
					$goto_page .= " | ";
				}
				$times++;
			}
			$goto_page .= " ]&nbsp; ";
		} else {
			$goto_page = "";
		}
		echo $goto_page;
// Subxero HASTA AQUI


/*
echo "<BR>\n";
?>
</TD></TR>
<TR ALIGN="LEFT" BGCOLOR="<?php echo $bgcolor1?>">
<TD COLSPAN=7 NOWRAP ><b><?php echo "<font color=$textcolor2>"._PMSG."</font>";?></b></TD>
<TR ALIGN="LEFT" BGCOLOR="<?php echo $bgcolor3?>">
<TD COLSPAN=7 NOWRAP >&nbsp;<img src="images/forum/icons/inbox.gif">&nbsp;<a href="viewpmsg.php"><?php echo _PINBOX;?></a><br>
<?
if (!$user) echo "&nbsp;<font size=1 color=\"$textcolor2\">"._LOGINTOR."</font></TD></TR>";
else {
$user = base64_decode($user);
$userdata = explode(":", $user);
$total_messages = mysql_num_rows(mysql_query("SELECT msg_id FROM ".$prefix."_priv_msgs WHERE to_userid = '$userdata[0]'"));
$new_messages = mysql_num_rows(mysql_query("SELECT msg_id FROM ".$prefix."_priv_msgs WHERE to_userid = '$userdata[0]' AND read_msg='0'"));
echo "&nbsp;<font size=1 color=\"$textcolor2\">";
if ($total_messages > 0) {
        if ($new_messages > 1) echo "$new_messages&nbsp;"._VNMS." | ";
        if ($new_messages == 1) echo "$new_messages&nbsp;"._ENM." | ";

 if ($total_messages > 1) echo "$total_messages&nbsp;"._TVM."</font>";
 if ($total_messages == 1) echo "$total_messages&nbsp;"._FPOSTS."</font>";
}
else echo ""._NPM."</font>";
}
*/
?>

</TD></TR>
<TR ALIGN="RIGHT" >
<TD COLSPAN=7 BGCOLOR="<?php echo $bgcolor2?>" ><font color="<?php echo $textcolor1;?>"><b><?php bbsearchblock()?></b></font></TD></TR>
</TABLE></TD></TR></TABLE>
<TABLE ALIGN="CENTER" BORDER="0" WIDTH="95%"><TR><TD VALIGN="TOP">
<font face="Verdana" size="1">
<IMG SRC="images/forum/icons/red_folder.gif"> = <?php echo _NPO;?> (<IMG SRC="images/forum/icons/hot_red_folder.gif"> = <?php echo ""._MORETHEN." $hot_threshold "._FPOSTS;?>)
<BR><IMG SRC="images/forum/icons/folder.gif"> = <?php echo _NNPO;?> (<IMG SRC="images/forum/icons/hot_folder.gif"> = <?php echo ""._MORETHEN." $hot_threshold "._FPOSTS;?>)
<BR><IMG SRC="images/forum/icons/lock.gif"> = <?php echo _TLOCKED;?>
</font></TD>
<TD ALIGN="RIGHT">
<FORM ACTION="modules.php?op=modload&name=<?php echo $module_name?>&file=viewforum" METHOD="POST">
<font face="Verdana" size="2"><?php echo _JUMPTO;?></font> <SELECT NAME="forum"><OPTION VALUE="-1"><?php echo _FSELECTF?></OPTION>
<?php
        $sql = "SELECT cat_id, cat_title FROM ${prefix}_catagories ORDER BY cat_id";
        if($result = mysql_query($sql, $db)) {
                $myrow = mysql_fetch_array($result);
                do {
                        echo "<OPTION VALUE=\"-1\">&nbsp;</OPTION>\n";
                        echo "<OPTION VALUE=\"-1\">$myrow[cat_title]</OPTION>\n";
                        echo "<OPTION VALUE=\"-1\">----------------</OPTION>\n";
                        $sub_sql = "SELECT forum_id, forum_name FROM ${prefix}_forums WHERE cat_id = '$myrow[cat_id]' ORDER BY forum_id";
                        if($res = mysql_query($sub_sql, $db)) {
                                if($row = mysql_fetch_array($res)) {
                                        do {
                                                $name = stripslashes($row[forum_name]);
                                                echo "<OPTION VALUE=\"$row[forum_id]\">$name</OPTION>\n";
                                        } while($row = mysql_fetch_array($res));
                                }
                                else {
                                        echo "<OPTION VALUE=\"0\">"._FNOMORE."</OPTION>\n";
                                }
                        }
                        else {
                                echo "<OPTION VALUE=\"0\">Error Connecting to DB</OPTION>\n";
                        }
                } while($myrow = mysql_fetch_array($result));
        }
        else {
                echo "<OPTION VALUE=\"-1\">ERROR</OPTION>\n";
        }
?>
</SELECT>
<INPUT TYPE="SUBMIT" VALUE="Go">
</FORM>
</tr>
</TABLE>
<!-- Don't touch the lines above please! --> 
<p align="center"><font size="1">Splatt Forum By: <a href="http://www.splatt.it">Splatt.it</a><br>Versione: 3.1</font></p>
<br>
<?php
}
include("footer.php");
?>