View file user/notification/index.php

File size: 3.8Kb
<?php
require( '../../sys/inc/core.php' );
only_reg();
$width = ( $webbrowser == 'web' ? '100' : '70' );
if ( isset( $_GET['delete'] ) && $_GET['delete'] == 'all' ) {
    if ( isset( $user ) ) {
        db::query( "DELETE FROM `notification` WHERE `id_user` = '$user[id]'" );
        $_SESSION['message'] = 'Уведомления очищены';
        header( 'Location: ?' );
        exit;
    }
}
if ( isset( $_GET['del'] ) ) {
    if ( isset( $user ) ) {
        $id = (int) $_GET['del'];
        if ( db::count( "SELECT COUNT(*) FROM `notification`  WHERE `id_user` = '$user[id]' AND `id` = '$id'" ) == 1 ) {
            db::query( "DELETE FROM `notification` WHERE `id_user` = '$user[id]' AND `id` = '$id' LIMIT 1" );
            $_SESSION['message'] = 'Уведомление удалено';
            header( 'Location: ?page=' . $id );
            exit;
        }
    }
}
$set['title'] = __( 'Уведомления' );
include_once H . 'sys/inc/thead.php';
title();
aut();
$k_notif = db::count( "SELECT COUNT(`read`) FROM `notification` WHERE `id_user` = '$user[id]' AND `read` = '0'" );
if ( $k_notif > 0 )
    $k_notif = '<font color=red>(' . $k_notif . ')</font>';
else
    $k_notif = null;
$discuss = db::count( "SELECT COUNT(`count`) FROM `discussions` WHERE `id_user` = '$user[id]' AND `count` > '0' " );
if ( $discuss > 0 )
    $discuss = '<font color=red>(' . $discuss . ')</font>';
else
    $discuss = null;
$lenta = db::count( "SELECT COUNT(`read`) FROM `tape` WHERE `id_user` = '$user[id]' AND `read` = '0' " );
if ( $lenta > 0 )
    $lenta = '<font color=red>(' . $lenta . ')</font>';
else
    $lenta = null;
?>
<div id='comments' class='menus'>
  <div class='webmenu'>
    <a href='/user/tape/'><?= __( 'Лента' ) . $lenta ?></a>
  </div>

  <div class='webmenu'>
    <a href='/user/discussions/' ><?= __( 'Обсуждения' ) . $discuss ?></a>
  </div>

  <div class='webmenu'>
    <a href='/user/notification/' class='activ'><?= __( 'Уведомления' ) . $k_notif ?></a>
  </div>
</div>
<?php
$k_post = db::count( "SELECT COUNT(*) FROM `notification`  WHERE `id_user` = '$user[id]'" );
$k_page = k_page( $k_post, $set['p_str'] );
$page   = page( $k_page );
$start  = $set['p_str'] * $page - $set['p_str'];
$q      = db::query( "SELECT * FROM `notification` WHERE `id_user` = '$user[id]' ORDER BY `time` DESC LIMIT $start, $set[p_str]" );
if ( $k_post == 0 ) {
?><div class='mess'><?= __( 'Нет новых уведомлений' ) ?></div><?php
}
while ( $post =  $q->fetch_assoc() ) {
    $num++;
?><div class="<?= ( $num % 2 ? 'nav2' : 'nav1' ) ?>"><?php
    $type  = $post['type'];
    $avtor = user::get_user( $post['avtor'], 1 );
    if ( is_file( 'inc/' . $type . '.php' ) ) {
        require 'inc/' . $type . '.php';
    } else {
        echo __( 'К сожалению плагин уведомления не найден, пожалуйста сообщите об этом администрации.' );
?>
    <br />Error: <?= $type ?> 
    <?php
    }
    if ( $post['read'] == 0 ) {
        db::query( "UPDATE `notification` SET `read` = '1' WHERE `id` = '$post[id]' LIMIT 1" );
    }
?>
  <span class="<?= ( $post['read'] == 0 ? 'off' : 'time' ) ?>"><?= vremja( $post['time'] ) ?></span> 
  <div class="right"><a href="?del=<?= $post['id'] ?>&amp;page=<?= $page ?>" title="<?= __( 'Удалить это уведомление' ) ?>"><img src="/style/icons/delete.gif" alt="*" /></a></div>
  </div>
  <?php
}
if ( $k_page > 1 ) {
    str( '?', $k_page, $page );
}
?>
<div class="foot">
<img src='/style/icons/str2.gif' alt='*'> <?= user::nick( $user['id'], 1 ) ?> | <b><?= __( 'Уведомления' ) ?></b> | <a href="settings.php"><?= __( 'Настройки' ) ?></a>
</div>
<?php
include_once H . 'sys/inc/tfoot.php';
?>