<?
require_once"../system/start.php";
require_once"../system/sid.php";
require("../config.php");
$tyu="left";
$title="Форум";
head();
list($row, $myid, $ps, $fs1, $fs2) = check_login($link);
echo $fs1;

$total = forum_new();

echo "$div1 Непрочитанное (<b>".$total."</b>) $div9";

if (isset($_GET['reset'])){
echo '<br />';
$req = mysql_query("SELECT * FROM `forum_topic` LEFT JOIN `forum_rdm` ON `forum_topic`.`id` = `forum_rdm`.`topic_id` AND `forum_rdm`.`user_id` = '" . $row['id'] .
"'
WHERE  `forum_rdm`.`topic_id` Is Null");
while ($res = mysql_fetch_array($req)) {
mysql_query("INSERT INTO `forum_rdm` SET `topic_id`='" . $res['id'] . "', `user_id`='" . $row['id'] . "', `time`='" . time() . "'");
}
$req = mysql_query("SELECT * FROM `forum_topic` LEFT JOIN `forum_rdm` ON `forum_topic`.`id` = `forum_rdm`.`topic_id` AND `forum_rdm`.`user_id` = '" . $row['id'] . "' WHERE `forum_topic`.`time` > `forum_rdm`.`time`");
while ($res = mysql_fetch_array($req)) {
mysql_query("UPDATE `forum_rdm` SET `time`='" . time() . "' WHERE `topic_id`='" . $res['id'] . "' AND `user_id`='" . $row['id'] . "'");
}

echo '<b>Все темы приняты как прочитанные</b><br />';
echo "<br />$div1<img src=\"../img/naz.gif\" alt=\"[N]\"/> <a href=\"./index.php\">Форум</a>$div9";
if($autorize){ echo "$div1<img src=\"../img/naz.gif\" alt=\"[N]\"/> <a href=\"../enter.php\">На Главную</a>$div9";}

foot ();
exit();
}


if (isset($_GET['all'])){
if (empty($act)){

echo '<b>Показать за период</b><br />';
echo '<form action="?all&amp;act=new" method="post">Период(в часах):<br/>';
echo '<input type="text" maxlength="3" name="vr" value="24" size="3"/>';
echo '&nbsp;<input type="hidden" name="act" value="all"/><input type="submit" name="submit" class="ibutton" value="Показать"/></form><br />';
echo '<a href="new.php">Назад</a>';

}else{

$vr = isset ($_REQUEST['vr']) ? abs(intval($_REQUEST['vr'])) : null;
if (!$vr) {
echo "Вы не ввели время!<br/><a href='index.php?act=new&amp;do=all'>Повторить</a><br/>";
require_once ("../incfiles/end.php");
exit;
}
$vr1 = time() - $vr * 3600;
$req = mysql_query("SELECT COUNT(*) FROM `forum_topic` WHERE `time` > '" . $vr1 . "' AND `close` != '1'");

$count = mysql_result($req, 0);
if ($count > 0) {

$max = $row['max'];
$k_page=k_page($count,$max);
$page=page($k_page);
$start=$max*$page-$max;

echo '<div class="c4"><b>Все за период '.$vr.' часов: '.$count.'</b></div>';
echo '<br />';

$req = mysql_query("SELECT * FROM `forum_topic` WHERE `time` > '" . $vr1 . "' AND `close` != '1' ORDER BY `time` DESC LIMIT ".$start."," .$max);

$i = 0;

while ($them = mysql_fetch_array($req)) {

$forum=mysql_fetch_array(mysql_query("SELECT * FROM `forum_sections` WHERE `id` = '$them[section]' LIMIT 1"));
$razdel=mysql_fetch_array(mysql_query("SELECT * FROM `forum_subfor` WHERE `id` = '$them[subfor]' LIMIT 1"));
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = $them[login] LIMIT 1"));

echo "$div2<a href='./tema/".$them['id']."'>$them[name]</a> <a href='./tema/".$them['id']."/end'>(".mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_message` WHERE `section` = '$forum[id]' AND `subfor` = '$razdel[id]' AND `topic` = '$them[id]'"),0).")</a>$div9\n";




echo "<a href='subfs/".$them['section']."'>$forum[name]</a> &gt; <a href='temes/".$them['subfor']."'>$razdel[name]</a><br />\n";

$post1=mysql_fetch_array(mysql_query("SELECT * FROM `forum_message` WHERE `topic` = '$them[id]' AND `subfor` = '$razdel[id]' AND `section` = '$forum[id]' AND `login` = '$them[login]' LIMIT 1"));
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = $them[login] LIMIT 1"));
echo "Автор: <a href='".H."$ank[id]' title='Анкета \"$ank[user]\"'>$ank[user]</a> (".date("d.m в H:i", $post1['time']).")<br />\n";

$post=mysql_fetch_array(mysql_query("SELECT * FROM `forum_message` WHERE `topic` = '$them[id]' AND `subfor` = '$razdel[id]' AND `section` = '$forum[id]' ORDER BY `time` DESC LIMIT 1"));
$ank2=mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = $post[login] LIMIT 1"));
echo "Посл.: <a href='".H."$ank2[id]' title='Анкета \"$ank2[user]\"'>$ank2[user]</a> (".date("d.m в H:i", $post['time']).")<br />\n";
echo'';
}


if ($k_page>1){
echo '<br/><dl><dt></dt></dl>';
str("?",$k_page,$page); // Вывод страниц
echo '<br/><dl><dt></dt></dl>';
}

}else echo '<b>За выбранный период нового  на форуме нет.</b><br /><br />';

}


echo "<br />$div1<img src=\"../img/naz.gif\" alt=\"[N]\"/> <a href=\"./index.php\">Форум</a>$div9";
if($autorize){ echo "$div1<img src=\"../img/naz.gif\" alt=\"[N]\"/> <a href=\"../enter.php\">На Главную</a>$div9";}

foot ();
exit();
}
echo '<br />';
$max = $row['max'];
$k_page=k_page($total,$max);
$page=page($k_page);
$start=$max*$page-$max;

$req = mysql_query("SELECT * FROM `forum_topic` LEFT JOIN `forum_rdm` ON `forum_topic`.`id` = `forum_rdm`.`topic_id` AND `forum_rdm`.`user_id` = '" . $row['id'] . "' WHERE  `forum_topic`.`close` != '1' AND (`forum_rdm`.`topic_id` Is Null OR `forum_topic`.`time` > `forum_rdm`.`time`) ORDER BY `forum_topic`.`time` DESC LIMIT $start, $max");
while ($them = mysql_fetch_array($req)) {

$forum=mysql_fetch_array(mysql_query("SELECT * FROM `forum_sections` WHERE `id` = '$them[section]' LIMIT 1"));
$razdel=mysql_fetch_array(mysql_query("SELECT * FROM `forum_subfor` WHERE `id` = '$them[subfor]' LIMIT 1"));
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = $them[login] LIMIT 1"));

echo "$div2<a href='./tema/".$them['id']."'>$them[name]</a> <a href='./tema/".$them['id']."/end'>(".mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_message` WHERE `section` = '$forum[id]' AND `subfor` = '$razdel[id]' AND `topic` = '$them[id]'"),0).")</a>$div9\n";




echo "<a href='subfs/".$them['section']."'>$forum[name]</a> &gt; <a href='temes/".$them['subfor']."'>$razdel[name]</a><br />\n";

$post1=mysql_fetch_array(mysql_query("SELECT * FROM `forum_message` WHERE `topic` = '$them[id]' AND `subfor` = '$razdel[id]' AND `section` = '$forum[id]' AND `login` = '$them[login]' LIMIT 1"));
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = $them[login] LIMIT 1"));
echo "Автор: <a href='".H."$ank[id]' title='Анкета \"$ank[user]\"'>$ank[user]</a> (".date("d.m в H:i", $post1['time']).")<br />\n";

$post=mysql_fetch_array(mysql_query("SELECT * FROM `forum_message` WHERE `topic` = '$them[id]' AND `subfor` = '$razdel[id]' AND `section` = '$forum[id]' ORDER BY `time` DESC LIMIT 1"));
$ank2=mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = $post[login] LIMIT 1"));
echo "Посл.: <a href='".H."$ank2[id]' title='Анкета \"$ank2[user]\"'>$ank2[user]</a> (".date("d.m в H:i", $post['time']).")<br />\n";
echo'';
}


if ($k_page>1){
echo '<br/><dl><dt></dt></dl>';
str("?",$k_page,$page); // Вывод страниц
echo '<br/><dl><dt></dt></dl>';
}

echo '<br /><a href="?reset">Сбросить все</a><br/>';
echo '<a href="?all">Показать за период</a><br/>';
echo "<br />$div1<img src=\"../img/naz.gif\" alt=\"[N]\"/> <a href=\"./index.php\">Форум</a>$div9";
if($autorize){ echo "$div1<img src=\"../img/naz.gif\" alt=\"[N]\"/> <a href=\"../enter.php\">На Главную</a>$div9";}

foot ();
?>