public static function mainUnansweredChatWorkflow()
 {
     $output = '';
     if (erLhcoreClassModelChatConfig::fetch('run_unaswered_chat_workflow')->current_value > 0) {
         $output .= "Starting unaswered chats workflow\n";
         $delay = time() - erLhcoreClassModelChatConfig::fetch('run_unaswered_chat_workflow')->current_valu * 60;
         foreach (erLhcoreClassChat::getList(array('limit' => 500, 'filterlt' => array('time' => $delay), 'filter' => array('status' => erLhcoreClassModelChat::STATUS_PENDING_CHAT, 'na_cb_executed' => 0))) as $chat) {
             erLhcoreClassChatWorkflow::unansweredChatWorkflow($chat);
             $output .= "executing unanswered callback for chat - " . $chat->id . "\n";
         }
         $output .= "Ended unaswered chats workflow\n";
     }
     return $output;
 }
             $baseURL = isset($Params['user_parameters_unordered']['mode']) && $Params['user_parameters_unordered']['mode'] == 'widget' ? erLhcoreClassDesign::baseurl('chat/chatwidget') : erLhcoreClassDesign::baseurl('chat/startchat');
             $ru = $baseURL . '/(department)/' . $department->id . '/(offline)/true/(leaveamessage)/true/(chatprefill)/' . $chat->id . '_' . $chat->hash;
             $msg = new erLhcoreClassModelmsg();
             $msg->msg = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/checkchatstatus', 'Visitor has been redirected to contact form');
             $msg->chat_id = $chat->id;
             $msg->user_id = -1;
             $msg->time = time();
             erLhcoreClassChat::getSession()->save($msg);
             // We do not store last msg time for chat here, because in any case none of opeators has opened it
             $contactRedirected = true;
             if ($chat->status_sub != erLhcoreClassModelChat::STATUS_SUB_CONTACT_FORM) {
                 $chat->status_sub = erLhcoreClassModelChat::STATUS_SUB_CONTACT_FORM;
                 $chat->updateThis();
             }
         } else {
             erLhcoreClassChatWorkflow::autoAssign($chat, $department);
         }
     }
 }
 if (erLhcoreClassChat::isOnline($chat->dep_id, false, array('online_timeout' => (int) erLhcoreClassModelChatConfig::fetch('sync_sound_settings')->data['online_timeout']))) {
     $tpl->set('is_online', true);
 } else {
     $tpl->set('is_online', false);
 }
 if ($chat->chat_initiator == erLhcoreClassModelChat::CHAT_INITIATOR_PROACTIVE) {
     $tpl->set('is_proactive_based', true);
 } else {
     $tpl->set('is_proactive_based', false);
 }
 if ($chat->status == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT) {
     $activated = 'true';
        $chat->unread_messages_informed = 0;
        erLhcoreClassChat::getSession()->update($chat);
        echo $tpl->fetch();
        flush();
        session_write_close();
        if (function_exists('fastcgi_finish_request')) {
            fastcgi_finish_request();
        }
        if ($chatDataChanged == true) {
            erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.data_changed', array('chat' => &$chat, 'user' => $currentUser));
        }
        if ($operatorAccepted == true) {
            erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.accept', array('chat' => &$chat, 'user' => $currentUser));
            erLhcoreClassChat::updateActiveChats($chat->user_id);
            if ($chat->department !== false) {
                erLhcoreClassChat::updateDepartmentStats($chat->department);
            }
            erLhcoreClassChatWorkflow::presendCannedMsg($chat);
            $options = $chat->department->inform_options_array;
            erLhcoreClassChatWorkflow::chatAcceptedWorkflow(array('department' => $chat->department, 'options' => $options), $chat);
        }
        exit;
    }
    echo $tpl->fetch();
    exit;
} else {
    $tpl->setFile('lhchat/errors/adminchatnopermission.tpl.php');
    $tpl->set('show_close_button', true);
    echo $tpl->fetch();
    exit;
}
Exemple #4
0
echo "Starting chat/workflow\n";
if (erLhcoreClassModelChatConfig::fetch('run_departments_workflow')->current_value == 1) {
    echo "Starting departments workflow\n";
    $ts = time();
    foreach (erLhcoreClassChat::getList(array('limit' => 500, 'customfilter' => array('transfer_timeout_ts < (' . $ts . '-transfer_timeout_ac)'), 'filter' => array('status' => erLhcoreClassModelChat::STATUS_PENDING_CHAT, 'transfer_if_na' => 1))) as $chat) {
        $canExecuteWorkflow = true;
        if (erLhcoreClassModelChatConfig::fetch('pro_active_limitation')->current_value >= 0) {
            if ($chat->department !== false && $chat->department->department_transfer_id > 0) {
                $canExecuteWorkflow = erLhcoreClassChat::getPendingChatsCountPublic($chat->department->department_transfer_id) <= erLhcoreClassModelChatConfig::fetch('pro_active_limitation')->current_value;
            }
        }
        if ($canExecuteWorkflow == true) {
            erLhcoreClassChatWorkflow::transferWorkflow($chat);
            echo "executing department transfer workflow for - ", $chat->id, "\n";
        } else {
            echo "Skipping transfer because dedicated department queue is full\n";
        }
    }
    echo "Ended departments workflow\n";
}
// Unanswered chats callback
echo erLhcoreClassChatWorkflow::mainUnansweredChatWorkflow();
echo "Closed chats - ", erLhcoreClassChatWorkflow::automaticChatClosing(), "\n";
echo "Purged chats - ", erLhcoreClassChatWorkflow::automaticChatPurge(), "\n";
foreach (erLhcoreClassChat::getList(array('limit' => 500, 'filter' => array('status' => erLhcoreClassModelChat::STATUS_PENDING_CHAT))) as $chat) {
    erLhcoreClassChatWorkflow::autoAssign($chat, $chat->department);
    erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.pending_process_workflow', array('chat' => &$chat));
}
// Inform visitors about unread messages
erLhcoreClassChatWorkflow::autoInformVisitor(erLhcoreClassModelChatConfig::fetch('inform_unread_message')->current_value);
echo "Ended chat/workflow\n";
Exemple #5
0
 if ($chat->status == erLhcoreClassModelChat::STATUS_PENDING_CHAT && $chat->transfer_if_na == 1 && $chat->transfer_timeout_ts < time() - $chat->transfer_timeout_ac) {
     $canExecuteWorkflow = true;
     if (erLhcoreClassModelChatConfig::fetch('pro_active_limitation')->current_value >= 0) {
         if ($chat->department !== false && $chat->department->department_transfer_id > 0) {
             $canExecuteWorkflow = erLhcoreClassChat::getPendingChatsCountPublic($chat->department->department_transfer_id) <= erLhcoreClassModelChatConfig::fetch('pro_active_limitation')->current_value;
         }
     }
     if ($canExecuteWorkflow == true) {
         erLhcoreClassChatWorkflow::transferWorkflow($chat);
     }
 }
 if ($chat->reinform_timeout > 0 && $chat->unread_messages_informed == 0 && $chat->has_unread_messages == 1 && time() - $chat->last_user_msg_time > $chat->reinform_timeout) {
     $department = $chat->department;
     if ($department !== false) {
         $options = $department->inform_options_array;
         erLhcoreClassChatWorkflow::unreadInformWorkflow(array('department' => $department, 'options' => $options), $chat);
     }
 }
 // Sync only if chat is pending or active
 if ($chat->status == erLhcoreClassModelChat::STATUS_PENDING_CHAT || $chat->status == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT) {
     // Check for new messages only if chat last message id is greater than user last message id
     if ((int) $Params['user_parameters']['message_id'] < $chat->last_msg_id) {
         $Messages = erLhcoreClassChat::getPendingMessages((int) $Params['user_parameters']['chat_id'], (int) $Params['user_parameters']['message_id']);
         if (count($Messages) > 0) {
             $tpl = erLhcoreClassTemplate::getInstance('lhchat/syncuser.tpl.php');
             $tpl->set('messages', $Messages);
             $tpl->set('chat', $chat);
             $tpl->set('sync_mode', isset($Params['user_parameters_unordered']['mode']) ? $Params['user_parameters_unordered']['mode'] : '');
             $content = $tpl->fetch();
             foreach ($Messages as $msg) {
                 if ($msg['user_id'] > 0) {
Exemple #6
0
<?php

$tpl = erLhcoreClassTemplate::getInstance('lhchat/maintenance.tpl.php');
if ($Params['user_parameters_unordered']['action'] == 'closechats' || $Params['user_parameters_unordered']['action'] == 'purgechats' || $Params['user_parameters_unordered']['action'] == 'updateduration') {
    $currentUser = erLhcoreClassUser::instance();
    if (!$currentUser->validateCSFRToken($Params['user_parameters_unordered']['csfr'])) {
        die('Invalid CSRF Token');
        exit;
    }
    if ($Params['user_parameters_unordered']['action'] == 'closechats') {
        $tpl->set('closedchats', erLhcoreClassChatWorkflow::automaticChatClosing());
    }
    if ($Params['user_parameters_unordered']['action'] == 'purgechats') {
        $tpl->set('purgedchats', erLhcoreClassChatWorkflow::automaticChatPurge());
    }
    if ($Params['user_parameters_unordered']['action'] == 'updateduration') {
        $db = ezcDbInstance::get();
        $db->query('UPDATE lh_chat SET chat_duration = (SELECT MAX(lh_msg.time) FROM lh_msg WHERE lh_msg.chat_id = lh_chat.id AND lh_msg.user_id = 0)-(lh_chat.time+lh_chat.wait_time)');
        $db->query('UPDATE lh_chat SET chat_duration = 0 WHERE chat_duration < 0');
        $tpl->set('updatedduration', true);
    }
}
$Result['content'] = $tpl->fetch();
$Result['path'] = array(array('url' => erLhcoreClassDesign::baseurl('system/configuration'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('department/departments', 'System configuration')), array('title' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/maintenance', 'Maintenance')));
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.maintenance_path', array('result' => &$Result));