 <?php
include 'core/system.php';

head('Журнал');
reg();
$journal_q = $dbc->query("SELECT * FROM `journal` WHERE `user_id`='".$user['id']."' ORDER BY `time` DESC LIMIT ".$page.",".$set['str']."");

$total = $dbc->query("SELECT `id` FROM `journal` WHERE `user_id`='".$user['id']."'"); $total = $total->num_rows;

if($total==0){
echo '<div class="main">

<div class="block_zero center">Журнал пуст</div></div>';
foot();
exit;
}
if(isset($_GET['delete'])){
$jour_u = $dbc->query("SELECT (id) FROM `journal` WHERE `user_id`='".$user['id']."'")->fetch_assoc();

if(!$jour_u){
header("Location: journal.php");
exit;
}
$dbc->query("DELETE FROM `journal` WHERE `user_id`='".$user['id']."'");

$dbc->query("UPDATE `users` SET `journal`=0 WHERE `id`='".$user['id']."'");

header("Location: journal.php");
exit;
}
if($user['journal']>0){
$dbc->query("UPDATE `users` SET `journal`=0 WHERE `id`='".$user['id']."'");

}
$last_mess = $dbc->query("SELECT * FROM `journal` WHERE `user_id`='".$user['id']."' ORDER BY `time` DESC LIMIT 1")->fetch_assoc();


echo '




<center><a href="journal.php?delete"><input class="btn big" type="submit" value="Очистить"></a></center>












<div class="mini-line"></div>';

/*

<div class="block_zero">

<font color="lime">

Последняя весть:

</font>

<br>

'.$last_mess['text'].'

</div>

*/
echo'



';

while($row = $journal_q->fetch_assoc()){

if($row['read']==1){
echo '<div class="b-panel-new dblue-panel bordered mt2"><div class="panel-inner-2"><font color="lime"><small>(новое)</small></font> ( '.clock($row['time']).' )<br>'.$row['text'].'<div class="separ"></div></div></div>';


$dbc->query("UPDATE `journal` SET `read`=0 WHERE `id`='".$row['id']."'");

}else{
echo '
<div class="b-panel-new dblue-panel bordered mt2"><div class="panel-inner-2"><small>

( '.clock($row['time']).' )<br/>
'.$row['text'].'
</small>
</div></div>

';
    }
}

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

