<?



include 'connect.php';


//Только для авторизованных
if($u['id']){

include 'head.php';
//Подзаголовок
if($u['id'])
echo '<div class="title"><img src= "img/jurnal.gif"> Мой журнал</div>';
else
echo '<div class="title"><img src= "img/jurnal.gif"> Мой журнал</div>';

//Заголовок раздела
//echo '<div class="menu_my2">';
//echo '<a href = "mail.php">Принятые ('.$mi.')</a> | <b>Отправленные ('.$mo.')</b> | <a href = "mail.php?act=write">Новое</a></b>';
//echo '</div>';
echo '<div class="main_menu">';

//Удалить
if($_GET['del']){
$del = num($_GET['del']);
   $req = mysql_query("SELECT * FROM `jurnal` WHERE `user` = '".$u['id']."' and `id` = '$del' LIMIT 1");
   if (mysql_num_rows($req)) {
   mysql_query("DELETE FROM `jurnal` WHERE `id` = '$del'");
   echo '<div class = "action">Сообщение удалено!</div><hr>';
   } else {
   
   }
}

//Сообщений на страницу
if($u['setting_jurnal_list']) $count = $u['setting_jurnal_list']; else $count = 10;

$all = mysql_result(mysql_query("SELECT COUNT(*) FROM `jurnal` WHERE `user` = '".$u['id']."'"), 0);
if($all > 0){
   $total = intval(($all - 1) / $count) + 1;
   $page = num($_GET['page']);
   if(empty($page) or $page < 0) $page = 1; 
   if($page > $total) $page = $total;
   $start = $page * $count - $count;
   $result = mysql_query("SELECT * FROM `jurnal` WHERE `user` = '".$u['id']."' ORDER BY `time` DESC LIMIT $start, $count");
      while($jurnal = mysql_fetch_assoc($result)){
	  $user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".$jurnal["outuser"]."'"));
	  //Вывод
	  echo $i % 2 ? '<div class="block2">' : '<div class="block1">';
	  if($jurnal['new'] == 1) echo '<div class="new">';
	  echo '<table>
      <tr>
      <td>';
	  ava($user['id'],50);
	  echo '</td>
	  <td VALIGN=top>';
	  echo ''.ico($user['sex'],$user['admin']).' <a href = "page.php?id='.$user['id'].'">'.$user['login'].'</a> '.online($user['online']).''; echo ' ('.vremya($jurnal['time']).')'; echo '  <a href = "jurnal.php?del='.$jurnal['id'].'"><img src = "img/del_msg.gif"></a>';
	  echo '<br/>';
	  echo '<br/> '.$jurnal['text'].'';
	  echo '<br/>';
	  echo '</td>
      </tr>
      </table>';
	  if($jurnal['new'] == 1) echo '</div>';
	  if($jurnal['new'] == 1) mysql_query("UPDATE `jurnal` SET `new` = 0 WHERE `id` = '".$jurnal['id']."'");
      echo '<hr>';
      echo '</div>';
	  $i++;
	  }
	  navigation($page, $total,'jurnal.php?');
}else{
echo 'У Вас еще нет сообщений в журнале!';
}
echo '</div>';
include 'foot.php';

} else {
header ("Location: index.php");
}
?>