<?php
/*---------------------------------------------------+
| PHP-Fusion 6 Content Management System
+----------------------------------------------------+
| Copyright © 2002 - 2006 Nick Jones
| http://www.php-fusion.co.uk/
+----------------------------------------------------+
| Released under the terms & conditions of v2 of the
| GNU General Public License. For details refer to
| the included gpl.txt file or visit http://gnu.org
+----------------------------------------------------+
| Modified by PHP-Fusion SF Group
| Copyright © 2007 by SF
| http://www.rus-phpfusion.com/
+----------------------------------------------------*/
require_once "../maincore.php";
include LOCALE.LOCALESET."forum/main.php";
require_once FORUM."subheader.php";
if ($settings_forum['show_panel'] == 1){
	require_once BASEDIR."side_left.php";
}

if (empty($lastvisited)) { $lastvisited = time(); }



tablebreak();

echo "<style type='text/css'>
.globalmesswarnwrap{
						background: #F2DDDD;
						font-size: 10px;
						border: 1px solid #992A2A;
						border-top: 0;
						margin: 10px 0 0 0;
						padding: 0;
					}

					.globalmesswarnwrap h4{
						background: #E3C0C0;
						
						border: 1px solid #992A2A;
						border-left: 0;
						border-right: 0;
						color: #992A2A;
						font-size: 10px;
						font-weight: bold;
						margin: 0;
						padding: 5px;
					}

					.globalmesswarnwrap p{
						background: transparent;
						border: 0;
						font-size: 8px;
						color: #992A2A;
						margin: 0;
						padding: 8px;
					}

					.globalmesswarnwrap p a:link,
					.globalmesswarnwrap p a:visited,
					.globalmesswarnwrap p a:active{
						background: transparent;
						text-decoration: underline;
						color: #992A2A;
					}

					.globalmesswarnwrap p a:hover{
						background: transparent;
						text-decoration: underline;
						color: #7D1F1F;
					}
					</style>";


//Original Digi code begins here.
opentable($settings_forum['forumname']);
echo "<table cellpadding='0' cellspacing='0' width='98%' class='tbl-border' align='center'>";
if (!empty($settings_forum['forumintro']))
{
	echo "<tr><td class='tbl1'><div class='globalmesswarnwrap' width='98%'><h4>Объявление</h4><p>".$settings_forum['forumintro']."</p></div></td></tr>
	<tr><td class='tbl1'>&nbsp;</td></tr>";

}
echo "<tr>
<td>
<table border='0' cellpadding='0' cellspacing='1' width='100%'>

<tr>
<td colspan='2' class='tbl2'>".$locale['401']."</td>
<td align='center' width='50' class='tbl2'>".$locale['402']."</td>
<td align='center' width='50' class='tbl2'>".$locale['403']."</td>
<td width='120' class='tbl2'>".$locale['404']."</td>
</tr>\n";

$result = dbquery("SELECT * FROM ".$db_prefix."forums WHERE forum_cat='0'  ORDER BY forum_order");
if (dbrows($result) != 0) {
	while ($data = dbarray($result)) {
		$forums = "";
		$result2 = dbquery("SELECT * FROM ".$db_prefix."forums WHERE forum_cat='".$data['forum_id']."' AND forum_sub='0' ORDER BY forum_order");
		if (dbrows($result2) != 0) {
			while ($data2 = dbarray($result2)) {
				
								
				
				if (checkgroup($data2['forum_access'])) {
					$moderators = "";
					$forum_mods = ($data2['forum_moderators'] ? explode(".", $data2['forum_moderators']) : "");
					if (is_array($forum_mods)) {
						sort($forum_mods);
						for ($i=0;$i < count($forum_mods);$i++) {
							$data3 = dbarray(dbquery("SELECT user_id,user_name FROM ".$db_prefix."users WHERE user_id='".$forum_mods[$i]."'"));
							$moderators .= "<a href='".BASEDIR."profile.php?lookup=".$data3['user_id']."'>".$data3['user_name']."</a>".($i != (count($forum_mods)-1) ? ", " : "");
						}
					}
					
					$subForums = dbquery("SELECT * FROM ".$db_prefix."forums WHERE forum_sub='".$data2['forum_id']."' ORDER BY forum_order DESC");
					$smsg = "";
					if (dbrows($subForums)) {
						while($subForum = dbarray($subForums)){
							$smsg .= " OR forum_id='".$subForum['forum_id']."'";
						}
					} 
					$new_posts = dbcount("(*)", "posts", "(forum_id='".$data2['forum_id']."'".$smsg.") AND post_datestamp>'$lastvisited'");
					$thread_count = dbcount("(*)", "threads", "forum_id='".$data2['forum_id']."'".$smsg);
					$posts_count = dbcount("(*)", "posts", "forum_id='".$data2['forum_id']."'".$smsg);
					
					if ($new_posts > 0) {
						$fim = "<img src='".THEME."forum/foldernew.gif' alt='".$locale['560']."'>";
					} else {
						$fim = "<img src='".THEME."forum/folder.gif' alt='".$locale['561']."'>";
					}
	        			$forums .= "<tr>
<td align='center' class='tbl2' width='5%'>$fim</td>
<td class='tbl1' width='65%'><a href='viewforum.php?forum_id=".$data2['forum_id']."'>".$data2['forum_name']."</a><br>
<span class='small'>".$data2['forum_description'].($moderators ? "<br>\n".$locale['411'].$moderators."</span>\n" : "</span>");
$subForums = dbquery("SELECT * FROM ".$db_prefix."forums WHERE forum_sub='".$data2['forum_id']."'");
if(dbrows($subForums)){
$forums .= "<br /><span class='small'><b>".$locale['575'].":</b> ";
$i = dbrows($subForums);
while($subForum = dbarray($subForums)){
	$new_postssub = dbcount("(*)", "posts", "forum_id='".$subForum['forum_id']."' AND post_datestamp>'$lastvisited'");
	if ($new_postssub > 0) {
		$fims = "<img src='".FORUM."images/mpn.gif' alt='".$locale['560']."'>";
	} else {
		$fims = "<img src='".FORUM."images/mp.gif' alt='".$locale['561']."'>";
	}
$forums .= $fims."<a href='".FORUM."viewforum.php?forum_id=".$subForum['forum_id']."'>".$subForum['forum_name']."</a>";
$i--;
if($i > 0) $forums .= ", ";
}
$forums .= "</span>";
}
$forums .= "</td>\n
<td align='center' class='tbl2' width='5%'>".$thread_count."</td>
<td align='center' class='tbl1' width='5%'>".$posts_count."</td>
<td class='tbl2' width='20%'>";
					if ($data2['forum_lastpost'] == 0) {
						$forums .=  $locale['405']."</td>\n</tr>\n";
					} else {
						$data3 = dbarray(dbquery("SELECT user_name FROM ".$db_prefix."users WHERE user_id='".$data2['forum_lastuser']."'"));
						$data9 = dbarray(dbquery("SELECT * FROM ".$db_prefix."threads WHERE forum_id='".$data2['forum_id']."' ORDER BY thread_lastpost DESC"));
					
						$forums .= showdate("forumdate", $data2['forum_lastpost'])."<br>
<span class='small'><b>".$locale['406'].": </b><a href='".BASEDIR."profile.php?lookup=".$data2['forum_lastuser']."'>".$data3['user_name']."</a></span><br />
<span class='small'><b>Тема: </b><a href='".FORUM."viewthread.php?forum_id=".$data9['forum_id']."&thread_id=".$data9['thread_id']."'>".$data9['thread_subject']."</a></span>
</td>
</tr>\n";
					}
				}
			}
			if ($forums != "") {
				echo "<tr>\n<td colspan='5' class='forum-caption'>".$data['forum_name']."</td>\n</tr>\n".$forums;
				unset($forums);
			}
		}
	}
}

echo "</table>
</td>
</tr>
</table>
<table width='100%' cellpadding='0' cellspacing='0'>
<tr><td>&nbsp;<br>
&nbsp;<img src='".THEME."forum/foldernew.gif' style='vertical-align:middle;'> - ".$locale['409']."<br>
&nbsp;<img src='".THEME."forum/folder.gif' style='vertical-align:middle;'> - ".$locale['410']."</td></tr><tr><td>
<table border='0' cellpadding='0' cellspacing='1' width='100%'class='tbl-border'><tr><td class='forum-caption' width='5%'>&nbsp;
	<td class='forum-caption' align='left'><b>Статистика форума</b>
	<tr><td class='tbl2' align='middle'>";

$filename = "".THEME."forum/whosonline.gif";
if (file_exists($filename)) {
	echo "<img src=".$filename." align='left'>";
} else {
	echo "<img src='".THEME."images/blank.gif' width='40'>";
}     
	echo "</td><td width='100%' align='left' class='tbl1'>";

// Online Users Panel Code
if ($settings['maintenance'] != "1") {
	@$cond = ($userdata['user_level'] != 0 ? "'".$userdata['user_id']."'" : "'0' AND online_ip='".FUSION_IP."'");
	$result = dbquery("SELECT * FROM ".$db_prefix."online WHERE online_user=".$cond."");
	if (dbrows($result) != 0) {
		$result = dbquery("UPDATE ".$db_prefix."online SET online_lastactive='".time()."' WHERE online_user=".$cond."");
	} else {
		$name = ($userdata['user_level'] != 0 ? $userdata['user_id'] : "0");
		@$result = dbquery("INSERT INTO ".$db_prefix."online VALUES('$name', '".FUSION_IP."', '".time()."')");
	}
	if (isset($_POST['login'])) {
		$result = dbquery("DELETE FROM ".$db_prefix."online WHERE online_user='0' AND online_ip='".FUSION_IP."'");
	} else if (isset($logout)) {
		$result = dbquery("DELETE FROM ".$db_prefix."online WHERE online_ip='".FUSION_IP."'");
	}
	$result = dbquery("DELETE FROM ".$db_prefix."online WHERE online_lastactive<".(time()-60)."");
	$result = dbquery("SELECT * FROM ".$db_prefix."online WHERE online_user='0'");
	echo "<span class='small'>".$locale['011']." <b>".dbrows($result)."</b> </span><br>\n";
	$result = dbquery(
		"SELECT ton.*, user_id,user_name FROM ".$db_prefix."online ton
		LEFT JOIN ".$db_prefix."users tu ON ton.online_user=tu.user_id
		WHERE online_user!='0'"
	);

// This code reads the amount of Forum Post from the Database
	$tacount = dbquery("SELECT count(thread_id) FROM ".$db_prefix."threads");
	echo "<span class='small'>На форуме тем: </span><span class='small'><b>".dbresult($tacount, 0)."</b><br>";
	$facount = dbquery("SELECT count(post_id) FROM ".$db_prefix."posts");
	echo "<span class='small'>На форуме сообщений: </span><span class='small'><b>".dbresult($facount, 0)."</b><br>";
// Ends Forum Post code

	$members = dbrows($result);
	if ($members != 0) {
		$i = 1;
		echo $locale['012'];
		while($data = dbarray($result)) {
			echo "<a href='".BASEDIR."profile.php?lookup=".$data['user_id']."' class='side'>".$data['user_name']."</a>";
			if ($i != $members) echo ", ";
			$i++;
		}
		echo "<br>\n";
	} else {
		echo $locale['013']."<br>\n";
	}
	$result = dbquery("SELECT user_id,user_name FROM ".$db_prefix."users ORDER BY user_joined DESC");
	$total = dbrows($result);
	$data = dbarray($result);
	echo "<br><span class='small'>Зарегистрировано пользователей: <b>".$total."</b></span>\n";
}
// End Online Users Panel Code

	echo "</div></td></tr><br>
	</td></tr></td></tr></table>\n";
	
	echo "<table border='0' cellpadding='0' cellspacing='1' width='100%'class='tbl-border'><tr><td class='forum-caption' width='5%'>&nbsp;</td>
	<td class='forum-caption' align='left'><b>Сегодняшние именинники</b></td><tr>
	<tr><td class='tbl2' align='middle'>&nbsp;</td><td>
	<table class='tbl1' border='0' cellpadding='0' cellspacing='0' width='100%'>
	<tr><td>";
	$bdate = "____-".date('%m-%d',time());

	$result = dbquery("SELECT user_birthdate,user_name,user_id FROM ".$db_prefix."users WHERE user_birthdate like '$bdate' ORDER BY user_name ASC");

	if (mysql_num_rows($result) == 0) {
			echo "<b>Сегодня имеников нет...</b>";
} else {
	echo "<b>Поздравляем</b>, ";
while ($bdate2 = mysql_fetch_array($result)) {

		echo "<a href='".BASEDIR."profile.php?lookup=".$bdate2['user_id']."'>".$bdate2['user_name']."</a>!&nbsp;";
}
}
	echo "<hr><div align='right'>Вернуться на сайт: <a href='../index.php'>".$settings['sitename']."</a><br /><form name='search' method='post' action='".BASEDIR."search.php?stype=f'>
	<input type='textbox' name='stext' class='textbox' style='width:150px' onfocus=this.value='' value='Что найти?'>
	<input type='submit' name='search' value='".$locale['550']."' class='button'>
	</form></td></tr></table></div>
	</td></tr></table></td></tr></table>";

closetable();
if ($settings_forum['show_panel'] == 1){
	require_once BASEDIR."side_right.php";
}
require_once FORUM."footer.php";
?>
