<?

if ( $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) {
    define( 'ROOT', 'http://'.$_SERVER['HTTP_HOST'] );
    define( 'ROOT_DIR', $_SERVER['DOCUMENT_ROOT'] );
    session_start();
    header( 'Content-type: text/html; charset=windows-1251' );
    include_once ROOT_DIR . '/engine/config.php';
    include_once ROOT_DIR . '/engine/function.php';
    include_once ROOT_DIR . '/engine/classes/bbcode.class.php';
} else {
    if ( !defined( 'MISOFT' ) ) { exit(); }
}

if ( !isset( $_SESSION['iduser'] ) ) {
    echo '<div class="error" style="width: 90%; margin: 10px auto; text-align: center"><b>Ошибка!</b> Вы не авторизированы.<br />Пожалуйста, воспользуйтесь формой авторизации.</div>';
} else {
include_once ROOT_DIR . '/modules/message/menu.php';

$check_read = mysql_query( "SELECT * FROM messages WHERE (to_id = '" . ( int ) $_GET['id'] . "' and from_id = '" . $_SESSION['iduser'] . "' and m_state = 'outbox' and to_del = 0) or (to_id = '" . $_SESSION['iduser'] . "' and from_id = '" . ( int ) $_GET['id'] . "' and m_state = 'inbox' and from_del = 0) ORDER BY data ASC" );
if ( mysql_num_rows( $check_read ) > 0 ) {
    ?>
    <script type="text/javascript">
    function forum_drweb(e) {
        $('body').Qbox({
            'title': 'Проверка на вирусы',
            'width': 410,
            'minHeight': 45,
            'fadespeed': 300,
            'url': 'modules/check_drweb.php',
            'param': 'url='+e
        });
        return false;
    }
    </script>
    <div class="wrap_read_mess" style="overflow: hidden; height: inherit; border-bottom: none;">
    <?
    
    while ( $get_mess_row = mysql_fetch_array( $check_read ) ) {
        $info_from_id = mysql_fetch_array( mysql_query( "SELECT username, avatar FROM user WHERE id = '" . $get_mess_row['from_id'] . "' LIMIT 1" ) );
        
        /*---формируем дату сообщения---*/
        $month = array( 'янв', 'фев', 'мар', 'апр', 'май', 'июн', 'июл', 'авг', 'сен', 'окт', 'ноя', 'дек' );
        
        if ( date( 'd.m.Y', $get_mess_row['data'] ) == date( 'd.m.Y', time() ) ) {
            $mess_time = 'сегодня в ' . date( 'H:i', $get_mess_row['data'] );
        } else
        if ( date( 'd.m.Y', $get_mess_row['data'] ) == date( 'd.m.Y', time() - 86400 ) ) {
            $mess_time = 'вчера в ' . date( 'H:i', $get_mess_row['data'] );
        } else {
            $mess_time = ( int ) date( 'd', $get_mess_row['data'] ) . ' ' . $month[( int ) date( 'm', $get_mess_row['data'] ) - 1] . ' ' . date( 'Y', $get_mess_row['data'] )  . ' в ' . date( 'H:i', $get_mess_row['data'] );
        }
        
        ?>
        <div class="wrap_in_mess"><div style="width: 40px; text-align: center; float: left;"><img src="<?=ROOT?>/temp/avatar/<?=$info_from_id['avatar']?>" width="30" height="30" class="avatar" alt="" /></div><div class="in_mess_text"><div class="us_name_mess"><?=$info_from_id['username']?></div><?=$get_mess_row['text']?><div class="time_mess"><?=$mess_time?></div></div></div>
        <?
    }
    ?>
    </div>
    <?
} else {
    echo '<div style="text-align:center; margin-top:56px; padding:20px 10px; font-weight:bold; color:#999999;">Сообщений не найдено.</div>';
}
}
?>