Вход Регистрация
Файл: monst/core/pag/dialog/view.php
Строк: 100
<?
$dialog_id 
= (int)$index[2];

$dialog $_dialog -> findOne(
    [
        
'id' => $dialog_id,
//        'user' => $user['id']
    
]
);

if ( 
$dialog['user1'] != $user['id'] AND $dialog['user2'] != $user['id'] ) {
    
g('/main');
}


if ( isset(
$_GET['delete']) ) {
    if ( isset(
$_GET['1']) ) {
        
$_dialog_mess -> remove(
            [
                
'dialog_id' => $dialog['id']
            ]
        );

        
$_dialog -> remove(
            [
                
'id' => $dialog['id']
            ]
        );

        
g('/dialog');
    } else {
        
?>
        <div class='padding'>
            <?=$lang['dialog.php']['del_dialog_desc']?><br/>
        </div>
        <a href='/dialog/view/<?=$dialog['id']?>?delete&amp;1'><div class='bt_black'><span style='color: indianred;'><?=$lang['dialog.php']['confirm']?></span></div></a>
        <a href='/dialog/view/<?=$dialog['id']?>'><div class='bt_black'><?=$lang['dialog.php']['cancel']?></div></a>
        <br/><br/>
        <?
    
}
}



$on_page 10;

$find $_dialog_mess -> find(
    [
        
'dialog_id' => $dialog_id,
  
//      'user' => $user['id']
    
]
);


$find -> limit($on_page);

$find -> sort(
    [
        
'time' => -1
    
]
);

$count $find -> count();

$nav nav($on_page);

if ( 
$dialog['user1'] == $user['id'] ) {
    
$user2_id $dialog['user2'];
}  else {
    
$user2_id $dialog['user1'];
}


$user2_array $_users -> findOne(
    [
        
'id' => $user2_id
    
]
);



//
if ( !empty($_POST['mess']) ) {
    
$mess null_html($_POST['mess']);

    
$find2 $_dialog_mess -> find(
        [
            
'dialog_id' => $dialog['id']
        ]
    );

    
$find2 -> sort(
        [
            
'time' => -1
        
]
    );

    foreach ( 
$find2 as $f2 ) {
        
$last_mess_array $f2;
        break;
    }

    
$last_mess $last_mess_array['mess'];

    if ( 
$mess != $last_mess ) {

        if ( 
mb_strlen($mess'UTF-8') > 100000 ) {
            
g('/dialog/view/'.$dialog['id'].'?the_long');
        }

        
$time time();

        
$new_mess_id new_id('_dialog_mess');
        
$_dialog_mess -> insert(
            [
                
'id' => $new_mess_id,
                
'dialog_id' => $dialog['id'],
                
'user_id' => $user['id'],
                
'to_user_id' => $user2_id,
                
'time' => $time,
                
'mess' => $mess,
                
'read' => 0,
//                'user' => $user['id']
            
]
        );

//        // find dialog 2
//        $dialog2_array = $_dialog -> findOne(
//            [
//                'user' => $user2_id,
//
//                '$or' => [
//                    [
//                        'user1' => $user['id'],
//                        'user2' => $user2_id
//                    ],
//                    [
//                        'user2' => $user['id'],
//                        'user1' => $user2_id
//                    ]
//                ],
//            ]
//        );
//
//        $dialog2_id = $dialog2_array['id'];
//
//        if ( !$dialog2_array ) {
//            $new_dialog_id2 = new_id('_dialog');
//            $_dialog -> insert(
//                [
//                    'id' => $new_dialog_id2,
//                    'user1' => $user['id'],
//                    'user2' => $user2_id,
//                    'time' => time(),
//                    'last_upd' => time(),
//                    'user' => $user2_id
//                ]
//            );
//
//            $dialog2_id = $new_dialog_id2;
//        }
//
//        $new_mess_id2 = new_id('_dialog_mess');
//        $_dialog_mess -> insert(
//            [
//                'id' => $new_mess_id2,
//                'dialog_id' => $dialog2_id,
//                'user_id' => $user['id'],
//                'to_user_id' => $user2_id,
//                'time' => $time,
//                'mess' => $mess,
//                'read' => 0,
//                'user' => $user2_id
//            ]
//        );

        
$_dialog -> update(
            [
                
'id' => $dialog['id']
            ],

            [
                
'$set' => [
                    
'last_upd' => time(),
                ]
            ]
        );

//        $_dialog -> update(
//            [
//                'id' => $dialog2_id
//            ],
//
//            [
//                '$set' => [
//                    'last_upd' => time(),
//                ]
//            ]
//        );

        
$_users -> update(
            [
                
'id' => $user['id']
            ],

            [
                
'$set' => [
                    
'dialog_count' => $user['dialog_count'] + 1
                
]
            ]
        );


    }

    
g('/dialog/view/' $dialog['id']);

}
//

$online Online($user2_array['l_time']);

?>

    <form method='post' action='/dialog/view/<?=$dialog['id']?>'>
        <textarea name='mess' rows='5' style='width: 90%;'></textarea>
        <br/>

        <div style='float: left; margin-left: 10px;'>
            <a href='/id<?=$user2_id?>'>
                <?=$lang['dialog.php']['dialog_with']?> <img src='<?=av($user2_id)?>' alt='' width='15'/><?=Name($user2_id)?> <?=$online?>
            </a>
        </div>


        <div style='text-align: right;'>
            <input type='submit' value='<?=$lang['dialog.php']['submit']['send']?>' style='padd2ing: 10px;'/>
        </div>
    </form>

<br/>
<?


foreach ( $find as $f ) {
    if ( 
$f['to_user_id'] == $user['id'] AND !$f['read'] ) {
        
$_dialog_mess -> update(
            [
                
'id' => $f['id']
            ],

            [
                
'$set' => [
                    
'read' => 1
                
]
            ]
        );

        
/////

//        // find dialog 2
//        $dialog2_array = $_dialog -> findOne(
//            [
////                'user' => $user2_id,
//
//                '$or' => [
//                    [
//                        'user1' => $user['id'],
//                        'user2' => $user2_id
//                    ],
//                    [
//                        'user2' => $user['id'],
//                        'user1' => $user2_id
//                    ]
//                ],
//            ]
//        );
//
//        if ( $dialog2_array ) {
//            $find2 = $_dialog_mess -> findOne(
//                [
//                    'dialog_id' => $dialog2_array['id'],
//                    'time' => $f['time'],
//                    'mess' => $f['mess']
//                ]
//            );
//
//            if ( $find2 ) {
//                $_dialog_mess -> update(
//                    [
//                        'id' => $find2['id']
//                    ],
//
//                    [
//                        '$set' => [
//                            'read' => 1
//                        ]
//                    ]
//                );
//
//            }
//
//        }
    
}

    
?>
    <div style='backg2round: #111; padding: 10px; margin-top: 5px;'>

            <a href='/id<?=$f['user_id']?>'>
                <img src='<?=av($f['user_id'])?>' alt='' width='70' style='float: left; margin-right: 10px;' class='av'/>
            </a>

        <?=Name($f['user_id'])?>
        <?
        
if ( $f['user_id'] != $user['id'] ) {
            
?>
            <?=$online?>
            <?
        
}
        
?>
        <span style='color: #777; font-size: 11px;'><?=replace_time($f['time'])?></span>
        <?
        
if ( !$f['read'] ) {
            
?>
            <span style='color: <?=$user['theme_color']?>;'><?=$lang['dialog.php']['not_read']?></span>
            <?
        
}
        
?>
        <br/>
        <span style='color: #ccc;'><?=$f['mess']?></span>
        <div style='clear: both;'></div>

    </div>
    <?
}

?>
<?
print $nav;

?>
<br/>
<a href='/dialog/view/<?=$dialog['id']?>?delete'><div class='bt_black'><span style='color: <?=$user['theme_color']?>;'><?=$lang['dialog.php']['del_dialog']?></span></div></a>
<a href='/dialog'><div class='bt_black'><?=$lang['dialog.php']['back_to_dialog']?></div></a>
<?
Онлайн: 1
Реклама