<?php
include 'core/sys.php';
head('Журнал');
reg();
$journal_q = mysql_query("SELECT * FROM `journal` WHERE `user_id`='".$user['id']."' ORDER BY `time` DESC LIMIT ".$page.",".$set['str']."");
$total = mysql_num_rows(mysql_query("SELECT (id) FROM `journal` WHERE `user_id`='".$user['id']."'"));
if($total==0){
echo '<div id="error">Журнал пуст</div>';
foot();
exit;
}
if(isset($_GET['delete'])){
$jour_u = mysql_fetch_assoc(mysql_query("SELECT (id) FROM `journal` WHERE `user_id`='".$user['id']."'"));
if(!$jour_u){
header("Location: journal.php");
exit;
}
mysql_query("DELETE FROM `journal` WHERE `user_id`='".$user['id']."'");
mysql_query("UPDATE `users` SET `journal`=0 WHERE `id`='".$user['id']."'");
header("Location: journal.php");
exit;
}
if($user['journal']>0){
mysql_query("UPDATE `users` SET `journal`=0 WHERE `id`='".$user['id']."'");
}
$last_mess = mysql_fetch_assoc(mysql_query("SELECT * FROM `journal` WHERE `user_id`='".$user['id']."' ORDER BY `time` DESC LIMIT 1"));
echo '<div class="name">Журнал [<a href="journal.php?delete">Очистить</a>]</div>';
echo '<div class="row"><img src="img/other/npc/Shero.gif" alt=""> <b>Шеро</b> (Последняя весть)<br>
'.$last_mess['text'].'
</div>';
while($row = mysql_fetch_assoc($journal_q)){
if($row['read']==1){
echo '<div class="row"><font color="orange"><small>(новое)</small></font> ['.clock($row['time']).'] '.$row['text'].'<br></div>';

mysql_query("UPDATE `journal` SET `read`=0 WHERE `id`='".$row['id']."'");
}else{
	echo '<div class="row">['.clock($row['time']).'] '.$row['text'].'<br></div>';
	}
}

  if($total > $set['str'])
	{
		pages($page, $total, 'journal.php?', $set['str']);
	}
foot();
?>