<?php
	/*
	*by Krite (http://upcoder.net)
	*/
	defined('_IN_JOHNCMS') or die('Error: restricted access');
	if($user_id)
	{
		$textl = 'Непрочитанные статьи';
		require_once('../incfiles/head.php');
		echo '<div class="phdr">'.$textl.'</div>';
		$req = mysql_query("SELECT * FROM `" . $prefix . "blogs` LEFT JOIN `" . $prefix . "blogs_rdm` ON `" . $prefix . "blogs`.`id`=`" . $prefix . "blogs_rdm`.`topic_id` AND `" . $prefix . "blogs_rdm`.`user_id`='" . $user_id . "' WHERE `" . $prefix . "blogs_rdm`.`topic_id` Is Null;");
		while ($res = mysql_fetch_array($req))
		{
			mysql_query("INSERT INTO `" . $prefix . "blogs_rdm` SET
			`topic_id`='" . $res['id'] . "',
			`user_id`='" . $user_id . "',
			`time`='" . $realtime . "'");
		}
		$req = mysql_query("SELECT * FROM `" . $prefix . "blogs` LEFT JOIN `" . $prefix . "blogs_rdm` ON `" . $prefix . "blogs`.`id`=`" . $prefix . "blogs_rdm`.`topic_id` AND `" . $prefix . "blogs_rdm`.`user_id`='" . $user_id . "' WHERE `" . $prefix . "blogs`.`time`>`" . $prefix . "blogs_rdm`.`time`;");
		while ($res = mysql_fetch_array($req))
		{
			mysql_query("UPDATE `" . $prefix . "blogs_rdm` SET `time`='" . $realtime . "' WHERE `topic_id`='" . $res['id'] . "' AND `user_id`='" . $user_id . "'");
		}
		echo '<p class="menu">Все темы приняты как прочитанные</p>';
		echo '<div class="phdr"><a href="./">Назад</a></div>';
	}
	else
	{
		header('Location: ../?err');
		exit;
	}
?>