<?php

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

  
  
  
  if(!$user['id']){
  header('Location: /index.php'); exit;
  }

  switch($_GET['m']){

  case 'clear':

  $ops = mysql_result(mysql_query("SELECT COUNT(*) FROM `op` where `who` = '".$user['id']."'"),0);
  mysql_query("DELETE FROM `op` WHERE `who`='".$user['id']."' limit $ops");

  header('Location: /op'); exit;
  break;
  
  #Главная
  default:
  $_title = 'Оповещения';
  include '../../system/header.php';
  


echo '<div class="tegi">Оповeщения</div><div class="poste"><a href="/op?m=clear">Очистить</a></div>';  


  $cop = $user['on_page'];
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `op` where `who` = '".$user['id']."'"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p'])){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
  $op = mysql_query("SELECT * FROM `op` where `who` = '".$user['id']."' ORDER BY `id` DESC LIMIT $start,$cop");
  while($op2 = mysql_fetch_assoc($op)){
  $op2_ho = mysql_fetch_array(mysql_query('select * from `user` where `id` = '.$op2['ho'].''));
echo '<div class="post1"><table cellpadding="0" cellspacing="4"><tr><td style="width: 40px; vertical-align: top; height: 40px; margin: 0; padding:0; border: 0;" id="mail_avatar">';
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/modules/profile/ava/'.$op2['ho'].'.jpg')) {
echo '<img src="/modules/profile/ava/'.$op2['ho'].'.jpg" alt="Ava" style="max-width:40px;">';
}
else
{
echo '<img src="/modules/profile/images/noava.png" alt="Ava" style="max-width:40px;">';
}
echo '</td><td style="vertical-align: top;" id="mail_textarea">'.ustatus($op2['ho']).' <a href="/us'.$op2['ho'].'">'.uname($op2['ho']).' </a>'.uaccess($op2['ho']).' '.smiles(bbcode($op2['text'])).' ['.times($op2['time']).']';
  if($op2['read'] == 0) echo ' <font color="red"><b>[new!]</b></font>';
  echo '</td></tr></table></div>';
  mysql_query("UPDATE `op` SET `read`='1' WHERE `id`='".$op2['id']."' limit 1");
  }

  echo '<div class="levo">Стр. ';
  if($p-2>0) echo '<a href="/op/p1"><<</a> ';
  if($p-1>0) echo '<a href="/op/p'.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/op/p'.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/op/p'.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/op/p'.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/op/p'.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/op/p'.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/op/p'.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/op/p'.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/op/p'.ceil($ca/$cop).'">>></a>';
  echo '</div></div>';
  
  break;
  
  }

  include '../../system/footer.php';

?>