/
accepttransfer.php
48 lines (38 loc) · 1.39 KB
/
accepttransfer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
header('Content-type: application/json');
$currentUser = erLhcoreClassUser::instance();
if (!$currentUser->isLogged() && !$currentUser->authenticate($_POST['username'],$_POST['password']))
{
exit;
}
try {
$chatTransfer = erLhcoreClassTransfer::getSession()->load( 'erLhcoreClassModelTransfer', $Params['user_parameters']['transfer_id']);
$chat = erLhcoreClassChat::getSession()->load( 'erLhcoreClassModelChat', $chatTransfer->chat_id);
} catch (Exception $e) {
exit;
}
// Set new chat owner
$currentUser = erLhcoreClassUser::instance();
$chat->user_id = $currentUser->getUserID();
if ($chatTransfer->dep_id > 0) {
$chat->dep_id = $chatTransfer->dep_id;
// User does not have access to chat in this department, that mean we do not have to do anything
if (!erLhcoreClassChat::hasAccessToRead($chat)){
exit;
}
}
if ( !erLhcoreClassChat::hasAccessToRead($chat) )
{
if ($currentUser->getUserID() == $chatTransfer->transfer_to_user_id) {
$chat->dep_id = erLhcoreClassUserDep::getDefaultUserDepartment();
} else {
exit; // User does not have permission to assign chat to himself
}
}
// All ok, we can make changes
erLhcoreClassChat::getSession()->update($chat);
erLhcoreClassTransfer::getSession()->delete($chatTransfer);
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.chat_transfer_accepted',array('chat' => & $chat));
echo json_encode(array('error' => 'false'));
exit;
?>