$tree ='<a href="index.php">Форум</a> / Последние темы'.($time ?' за '.$timeRes.' час.':'');
}
echo '<div class="fmenu">'.$tree.'</div>';
if(isset($_GET['reset'])){
$sql->query("SELECT `forum_topics`.`id`, `forum_topics`.`lastpost` FROM `forum_topics` LEFT JOIN `forum_readed` ON `forum_topics`.`id` = `forum_readed`.`topic` AND `forum_readed`.`user_id` = '$user_id' WHERE `forum_readed`.`topic` Is Null ");
while($res = $sql->fetch()){
$lastPost = explode(':|:', $res['lastpost']);
$sql->query("INSERT INTO `forum_readed` SET
`topic` = '".$res['id']."',
`user_id` = '$user_id',
`time` = '".time()."',
`lastpost` = '".$lastPost[1]."' ",true);
}
$sql->query("SELECT `forum_topics`.`id`, `forum_topics`.`lastpost` FROM `forum_topics` LEFT JOIN `forum_readed` ON `forum_topics`.`id` = `forum_readed`.`topic` AND `forum_readed`.`user_id` = '$user_id' WHERE `forum_topics`.`time` > `forum_readed`.`time` ");
while($res = $sql->fetch()){
$lastPost = explode(':|:', $res['lastpost']);
$sql->query("UPDATE `forum_readed` SET
`time` = '".time()."',
`lastpost` = '".$lastPost[1]."'
WHERE `topic` = '".$res['id']."' AND `user_id` = '$user_id' ",true);
}
echo '<div class="post">Все темы приняты как прочитанные<br /><a href="index.php">Форум</a></div>';
include H .'engine/includes/foot.php';
}
if($unread){
$total = $sql->query("SELECT COUNT(*) FROM `forum_topics` LEFT JOIN `forum_readed` ON `forum_topics`.`id` = `forum_readed`.`topic` AND `forum_readed`.`user_id` = '$user_id' WHERE (`forum_readed`.`topic` Is Null OR `forum_topics`.`time` > `forum_readed`.`time`) ")->result();
$req = $sql->query("SELECT *, `forum_topics`.`time` AS `topictime`, `forum_topics`.`lastpost` AS `lastpost` FROM `forum_topics` LEFT JOIN `forum_readed` ON `forum_topics`.`id` = `forum_readed`.`topic` AND `forum_readed`.`user_id` = '$user_id' WHERE (`forum_readed`.`topic` Is Null OR `forum_topics`.`time` > `forum_readed`.`time`) ORDER BY `forum_topics`.`time` DESC LIMIT ".$page->limit());
}else{
$req = $sql->query("SELECT *, `forum_topics`.`time` AS `topictime` FROM `forum_topics` ".($time ?"WHERE `time` > '$time' ":"")."ORDER BY `time` DESC LIMIT ".$page->limit());