public function process()
 {
     $list = erLhcoreClassChat::getList(array('limit' => 100, 'filterlt' => array('time' => $this->range_to), 'filtergt' => array('time' => $this->range_from)));
     self::$archiveTable = "lh_chat_archive_{$this->id}";
     self::$archiveMsgTable = "lh_chat_archive_msg_{$this->id}";
     $pending_archive = count($list);
     $messagesArchived = 0;
     $firstChatID = 0;
     $lastChatID = 0;
     foreach ($list as $item) {
         if ($firstChatID == 0) {
             $firstChatID = $item->id;
         }
         $archive = new erLhcoreClassModelChatArchive();
         $archive->setState(get_object_vars($item));
         $archive->id = null;
         $archive->saveThis();
         $messages = erLhcoreClassModelmsg::getList(array('limit' => 1000, 'filter' => array('chat_id' => $item->id)));
         $messagesArchived += count($messages);
         foreach ($messages as $msg) {
             $msgArchive = new erLhcoreClassModelChatArchiveMsg();
             $msgArchive->setState(get_object_vars($msg));
             $msgArchive->id = null;
             $msgArchive->chat_id = $archive->id;
             erLhcoreClassChat::getSession()->save($msgArchive);
         }
         $lastChatID = $item->id;
         $item->removeThis();
     }
     return array('error' => 'false', 'fcid' => $firstChatID, 'lcid' => $lastChatID, 'messages_archived' => $messagesArchived, 'chats_archived' => count($list), 'pending_archive' => $pending_archive == 100 ? 'true' : 'false');
 }
Exemplo n.º 2
0
 public function fillDataByChat($chat)
 {
     $this->getConfig();
     $messages = array_reverse(erLhcoreClassModelmsg::getList(array('limit' => 5000, 'sort' => 'id DESC', 'filter' => array('chat_id' => $chat->id))));
     $messagesContent = '';
     foreach ($messages as $msg) {
         if ($msg->user_id == -1) {
             $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmin', 'System assistant') . ': ' . htmlspecialchars($msg->msg) . "\n";
         } else {
             $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . ($msg->user_id == 0 ? htmlspecialchars($chat->nick) : htmlspecialchars($msg->name_support)) . ': ' . htmlspecialchars($msg->msg) . "\n";
         }
     }
     $data = array('name' => $chat->nick, 'email' => $chat->email, 'subject' => str_replace(array('{referrer}', '{nick}', '{email}', '{country_code}', '{country_name}', '{city}', '{user_tz_identifier}'), array($chat->referrer, $chat->nick, $chat->email, $chat->country_code, $chat->country_name, $chat->city, $chat->user_tz_identifier), $this->configData['subject']), 'message' => str_replace(array('{time_created_front}', '{additional_data}', '{id}', '{url}', '{referrer}', '{messages}', '{remarks}', '{nick}', '{email}', '{country_code}', '{country_name}', '{city}', '{user_tz_identifier}'), array(date(erLhcoreClassModule::$dateDateHourFormat, $chat->time), $chat->additional_data, $chat->id, (erLhcoreClassSystem::$httpsMode == true ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('user/login') . '/(r)/' . rawurlencode(base64_encode('chat/single/' . $chat->id)), $chat->referrer, $messagesContent, $chat->remarks, $chat->nick, $chat->email, $chat->country_code, $chat->country_name, $chat->city, $chat->user_tz_identifier), $this->configData['message']), 'ip' => $chat->ip);
     return $data;
 }
 /**
  * Arguments
  * array('chat' => & $chat)
  * */
 public function sevabot($params)
 {
     $settings = (include 'extension/sevabot/settings/settings.ini.php');
     // Format message content
     $chat = $params['chat'];
     $messages = array_reverse(erLhcoreClassModelmsg::getList(array('limit' => 5, 'sort' => 'id DESC', 'filter' => array('chat_id' => $chat->id))));
     $messagesContent = '';
     foreach ($messages as $msg) {
         if ($msg->user_id == -1) {
             $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmin', 'System assistant') . ': ' . htmlspecialchars($msg->msg) . "\n";
         } else {
             $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . ($msg->user_id == 0 ? htmlspecialchars($chat->nick) : htmlspecialchars($msg->name_support)) . ': ' . htmlspecialchars($msg->msg) . "\n";
         }
     }
     $cfgSite = erConfigClassLhConfig::getInstance();
     $secretHash = $cfgSite->getSetting('site', 'secrethash');
     $chatDataItems = $settings['chat'];
     if (isset($settings['chat_dep'][$chat->dep_id]) && !empty($settings['chat_dep'][$chat->dep_id])) {
         $chatDataItems = array_merge($chatDataItems, $settings['chat_dep'][$chat->dep_id]);
     }
     // Global notifications
     foreach ($chatDataItems as $chatData) {
         $veryfyEmail = sha1(sha1($chatData['email'] . $secretHash) . $secretHash);
         $msgParsed = str_replace(array('{messages}', '{url_accept}', '{chat_id}', '{user_name}'), array($messagesContent, erLhcoreClassXMP::getBaseHost() . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('chat/accept') . '/' . erLhcoreClassModelChatAccept::generateAcceptLink($chat) . '/' . $veryfyEmail . '/' . $chatData['email'], $chat->id, $chat->user_name), $settings['msg']);
         $md5 = md5($chatData['chat_id'] . $msgParsed . $settings['sevabot_secret']);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $settings['url']);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_TIMEOUT, 5);
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, array('md5' => $md5, 'msg' => $msgParsed, 'chat' => $chatData['chat_id']));
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
         @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
         // Some hostings produces wargning...
         $content = curl_exec($ch);
         if ($content != 'OK') {
             erLhcoreClassLog::write(print_r($content, true));
         }
     }
 }
Exemplo n.º 4
0
<div class="fs11">
<h2><?php 
echo htmlspecialchars($chat->nick);
$chat->city != '' ? print ', ' . htmlspecialchars($chat->city) : '';
?>
, <?php 
echo date(erLhcoreClassModule::$dateDateHourFormat, $chat->time);
?>
 <div class="right">IP:<?php 
echo $chat->ip;
?>
, ID: <?php 
echo $chat->id;
?>
</div></h2>
<?php 
$messages = erLhcoreClassModelmsg::getList(array('limit' => 1000, 'sort' => 'id ASC', 'filter' => array('chat_id' => $chat->id)));
include erLhcoreClassDesign::designtpl('lhchat/lists/msg_obj_list.tpl.php');
?>
</div>
Exemplo n.º 5
0
 public static function informChatClosed(erLhcoreClassModelChat $chat, $operator = false)
 {
     $sendMail = erLhAbstractModelEmailTemplate::fetch(5);
     $mail = new PHPMailer();
     $mail->CharSet = "UTF-8";
     if ($sendMail->from_email != '') {
         $mail->Sender = $mail->From = $sendMail->from_email;
     }
     $mail->FromName = $sendMail->from_name;
     $mail->Subject = $sendMail->subject;
     $messages = array_reverse(erLhcoreClassModelmsg::getList(array('limit' => 10, 'sort' => 'id DESC', 'filter' => array('chat_id' => $chat->id))));
     $messagesContent = '';
     foreach ($messages as $msg) {
         if ($msg->user_id == -1) {
             $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmin', 'System assistant') . ': ' . htmlspecialchars($msg->msg) . "\n";
         } else {
             $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . ($msg->user_id == 0 ? htmlspecialchars($chat->nick) : htmlspecialchars($msg->name_support)) . ': ' . htmlspecialchars($msg->msg) . "\n";
         }
     }
     $emailRecipient = array();
     if ($sendMail->recipient != '') {
         // This time we give priority to template recipients
         $emailRecipient = explode(',', $sendMail->recipient);
     } elseif ($chat->department !== false && $chat->department->email != '') {
         $emailRecipient = explode(',', $chat->department->email);
     } else {
         // Lets find first user and send him an e-mail
         $list = erLhcoreClassModelUser::getUserList(array('limit' => 1, 'sort' => 'id ASC'));
         $user = array_pop($list);
         $emailRecipient = array($user->email);
     }
     self::setupSMTP($mail);
     $cfgSite = erConfigClassLhConfig::getInstance();
     $secretHash = $cfgSite->getSetting('site', 'secrethash');
     if ($chat->email != '') {
         $mail->AddReplyTo($chat->email, $chat->nick);
     }
     // Format user friendly additional data
     if ($chat->additional_data != '') {
         $paramsAdditional = json_decode($chat->additional_data, true);
         $elementsAdditional = array();
         if (is_array($paramsAdditional) && !empty($paramsAdditional)) {
             foreach ($paramsAdditional as $param) {
                 $elementsAdditional[] = $param['key'] . ' - ' . $param['value'];
             }
             $additional_data = implode("\n", $elementsAdditional);
         } else {
             $additional_data = $chat->additional_data;
         }
     } else {
         $additional_data = '';
     }
     foreach ($emailRecipient as $receiver) {
         $veryfyEmail = sha1(sha1($receiver . $secretHash) . $secretHash);
         $mail->Body = str_replace(array('{chat_id}', '{phone}', '{name}', '{email}', '{message}', '{additional_data}', '{url_request}', '{ip}', '{department}', '{url_accept}', '{operator}', '{country}', '{city}'), array($chat->id, $chat->phone, $chat->nick, $chat->email, $messagesContent, $additional_data, $chat->referrer, erLhcoreClassIPDetect::getIP(), (string) $chat->department, 'http://' . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('chat/accept') . '/' . erLhcoreClassModelChatAccept::generateAcceptLink($chat) . '/' . $veryfyEmail . '/' . $receiver, $operator, $chat->country_name, $chat->city), $sendMail->content);
         $mail->AddAddress($receiver);
         $mail->Send();
         $mail->ClearAddresses();
     }
     if ($sendMail->bcc_recipients != '') {
         $recipientsBCC = explode(',', $sendMail->bcc_recipients);
         foreach ($recipientsBCC as $receiver) {
             $receiver = trim($receiver);
             $veryfyEmail = sha1(sha1($receiver . $secretHash) . $secretHash);
             $mail->Body = str_replace(array('{chat_id}', '{phone}', '{name}', '{email}', '{message}', '{additional_data}', '{url_request}', '{ip}', '{department}', '{url_accept}', '{operator}', '{country}', '{city}'), array($chat->id, $chat->phone, $chat->nick, $chat->email, $messagesContent, $additional_data, $chat->referrer, erLhcoreClassIPDetect::getIP(), (string) $chat->department, 'http://' . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('chat/accept') . '/' . erLhcoreClassModelChatAccept::generateAcceptLink($chat) . '/' . $veryfyEmail . '/' . $receiver, $operator, $chat->country_name, $chat->city), $sendMail->content);
             $mail->AddAddress($receiver);
             $mail->Send();
             $mail->ClearAddresses();
         }
     }
 }
Exemplo n.º 6
0
<?php

try {
    $chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChat', $Params['user_parameters']['chat_id']);
    if ($chat->hash == $Params['user_parameters']['hash']) {
        $msg = erLhcoreClassModelmsg::fetch($Params['user_parameters']['msgid']);
        if ($msg->chat_id == $chat->id) {
            $tpl = erLhcoreClassTemplate::getInstance('lhchat/syncuser.tpl.php');
            $tpl->set('messages', array((array) $msg));
            $tpl->set('chat', $chat);
            $tpl->set('sync_mode', isset($Params['user_parameters_unordered']['mode']) ? $Params['user_parameters_unordered']['mode'] : '');
            echo json_encode(array('msg' => $tpl->fetch(), 'error' => 'f'));
            exit;
        }
    }
} catch (Exception $e) {
}
echo json_encode(array('error' => 't'));
exit;
 if (ezcInputForm::hasPostData()) {
     $definition = array('email' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'validate_email'));
     $form = new ezcInputForm(INPUT_POST, $definition);
     $Errors = array();
     if (!$form->hasValidData('email')) {
         $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/edit', 'Wrong email address');
     }
     if (!isset($_SERVER['HTTP_X_CSRFTOKEN']) || !isset($_POST['csfr_token']) || $_POST['csfr_token'] != $_SERVER['HTTP_X_CSRFTOKEN']) {
         $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/edit', 'Invalid CSRF token!');
     }
     if (empty($Errors)) {
         $tpl = erLhcoreClassTemplate::getInstance('lhchat/sendmail.tpl.php');
         $mailTemplate = erLhAbstractModelEmailTemplate::fetch(3);
         erLhcoreClassChatMail::prepareSendMail($mailTemplate);
         $mailTemplate->recipient = $form->email;
         $messages = array_reverse(erLhcoreClassModelmsg::getList(array('customfilter' => array('user_id != -1'), 'limit' => 500, 'sort' => 'id DESC', 'filter' => array('chat_id' => $chat->id))));
         // Fetch chat messages
         $tpl = new erLhcoreClassTemplate('lhchat/messagelist/plain.tpl.php');
         $tpl->set('chat', $chat);
         $tpl->set('messages', $messages);
         $mailTemplate->content = str_replace(array('{user_chat_nick}', '{messages_content}'), array($chat->nick, $tpl->fetch()), $mailTemplate->content);
         erLhcoreClassChatMail::sendMail($mailTemplate, $chat);
         echo json_encode(array('error' => 'false'));
         exit;
     } else {
         $tpl = erLhcoreClassTemplate::getInstance('lhkernel/validation_error.tpl.php');
         $tpl->set('errors', $Errors);
         echo json_encode(array('error' => 'true', 'result' => $tpl->fetch()));
         exit;
     }
 } else {
Exemplo n.º 8
0
 /**
  * translations recent chat messages to chat locale
  * 
  * @param erLhcoreClassModelChat $chat
  * 
  * @return void || Exception 
  * */
 public static function translateChatMessages(erLhcoreClassModelChat $chat)
 {
     // Allow callback provide translation config first
     $response = erLhcoreClassChatEventDispatcher::getInstance()->dispatch('translation.get_config', array());
     if ($response !== false && isset($response['status']) && $response['status'] == erLhcoreClassChatEventDispatcher::STOP_WORKFLOW) {
         $translationData = $response['data'];
     } else {
         $translationConfig = erLhcoreClassModelChatConfig::fetch('translation_data');
         $translationData = $translationConfig->data;
     }
     if (isset($translationData['translation_handler']) && $translationData['translation_handler'] == 'bing') {
         $response = erLhcoreClassChatEventDispatcher::getInstance()->dispatch('translation.get_bing_token', array('translation_config' => &$translationConfig, 'translation_data' => &$translationData));
         if ($response !== false && isset($response['status']) && $response['status'] == erLhcoreClassChatEventDispatcher::STOP_WORKFLOW) {
             // Do nothing
         } else {
             self::getBingAccessToken($translationConfig, $translationData);
         }
         // Only last 10 messages are translated
         $msgs = erLhcoreClassModelmsg::getList(array('filter' => array('chat_id' => $chat->id), 'limit' => 10, 'sort' => 'id DESC'));
         foreach ($msgs as $msg) {
             // Visitor message
             // Remove old Translation
             $msg->msg = preg_replace('#\\[translation\\](.*?)\\[/translation\\]#is', '', $msg->msg);
             if ($msg->user_id == 0) {
                 $msgTranslated = erLhcoreClassTranslateBing::translate($translationData['bing_access_token'], $msg->msg, $chat->chat_locale, $chat->chat_locale_to);
             } else {
                 // Operator message
                 $msgTranslated = erLhcoreClassTranslateBing::translate($translationData['bing_access_token'], $msg->msg, $chat->chat_locale_to, $chat->chat_locale);
             }
             // If translation was successfull store it
             if (!empty($msgTranslated)) {
                 $msg->msg .= "[translation]{$msgTranslated}[/translation]";
                 $msg->saveThis();
             }
         }
     } else {
         // Only last 10 messages are translated
         $msgs = erLhcoreClassModelmsg::getList(array('filter' => array('chat_id' => $chat->id), 'limit' => 10, 'sort' => 'id DESC'));
         foreach ($msgs as $msg) {
             // Visitor message
             // Remove old Translation
             $msg->msg = preg_replace('#\\[translation\\](.*?)\\[/translation\\]#is', '', $msg->msg);
             if ($msg->user_id == 0) {
                 $msgTranslated = erLhcoreClassTranslateGoogle::translate($translationData['google_api_key'], $msg->msg, $chat->chat_locale, $chat->chat_locale_to);
             } else {
                 // Operator message
                 $msgTranslated = erLhcoreClassTranslateGoogle::translate($translationData['google_api_key'], $msg->msg, $chat->chat_locale_to, $chat->chat_locale);
             }
             // If translation was successfull store it
             if (!empty($msgTranslated)) {
                 $msg->msg .= "[translation]{$msgTranslated}[/translation]";
                 $msg->saveThis();
             }
         }
     }
 }
Exemplo n.º 9
0
            ?>
>
				<?php 
        }
        ?>
		</operator_variable>
	<?php 
    }
}
?>

</operator_variables_filled>

<transcripts type="array">
<?php 
foreach (erLhcoreClassModelmsg::getList(array('limit' => 5000, 'filter' => array('chat_id' => $chat->id))) as $msg) {
    ?>
<transcript>
	<id><?php 
    echo $msg->user_id;
    ?>
</id>
	<date type="datetime"><?php 
    echo date('r', $msg->time);
    ?>
</date>
	<message><![CDATA[<?php 
    echo htmlspecialchars($msg->msg);
    ?>
]]></message>
	<user_id><?php 
Exemplo n.º 10
0
<?php

$definition = array('msg' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::REQUIRED, 'unsafe_raw'), 'msgid' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::REQUIRED, 'int', array('min_range' => 1)));
$form = new ezcInputForm(INPUT_POST, $definition);
if ($form->hasValidData('msg') && trim($form->msg) != '' && mb_strlen($form->msg) < (int) erLhcoreClassModelChatConfig::fetch('max_message_length')->current_value) {
    $db = ezcDbInstance::get();
    $db->beginTransaction();
    try {
        $chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChat', $Params['user_parameters']['chat_id']);
        if ($chat->hash == $Params['user_parameters']['hash'] && ($chat->status == erLhcoreClassModelChat::STATUS_PENDING_CHAT || $chat->status == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT)) {
            $msg = erLhcoreClassModelmsg::fetch($form->msgid);
            if ($msg->chat_id == $chat->id && $msg->user_id == 0) {
                $msg->msg = trim($form->msg);
                if ($chat->chat_locale != '' && $chat->chat_locale_to != '') {
                    erLhcoreClassTranslate::translateChatMsgVisitor($chat, $msg);
                }
                erLhcoreClassChat::getSession()->update($msg);
                $tpl = erLhcoreClassTemplate::getInstance('lhchat/syncuser.tpl.php');
                $tpl->set('messages', array((array) $msg));
                $tpl->set('chat', $chat);
                $tpl->set('sync_mode', isset($Params['user_parameters_unordered']['mode']) ? $Params['user_parameters_unordered']['mode'] : '');
                $chat->operation_admin .= "lhinst.updateMessageRowAdmin({$chat->id},{$msg->id});\n";
                $chat->user_typing = time();
                $chat->user_typing_txt = htmlspecialchars_decode(erTranslationClassLhTranslation::getInstance()->getTranslation('chat/updatemsguser', 'User has edited his last message'), ENT_QUOTES);
                $chat->updateThis();
                echo json_encode(array('error' => 'f', 'msg' => trim($tpl->fetch())));
            }
        }
        $db->commit();
    } catch (Exception $e) {
        $db->rollback();
Exemplo n.º 11
0
 public static function chatListExportXLS($chats, $params = array())
 {
     include 'lib/core/lhform/PHPExcel.php';
     $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
     $cacheSettings = array('memoryCacheSize ' => '64MB');
     PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
     $objPHPExcel = new PHPExcel();
     $objPHPExcel->setActiveSheetIndex(0);
     $objPHPExcel->getActiveSheet()->getStyle('A1:AW1')->getFont()->setBold(true);
     $objPHPExcel->getActiveSheet()->setTitle('Report');
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 1, "ID");
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Visitor Name'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'E-mail'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Phone'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Wait time'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Country'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'City'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'IP'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Operator'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Department'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Date'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(11, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Minutes'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(12, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Vote status'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(13, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Mail send'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(14, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Page'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(15, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Came from'));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(16, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Link'));
     if (isset($params['type']) && $params['type'] == 2) {
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(17, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Chat content'));
     }
     $attributes = array('id', 'nick', 'email', 'phone', 'wait_time', 'country_name', 'city', 'ip', 'user', 'department');
     $i = 2;
     foreach ($chats as $item) {
         foreach ($attributes as $key => $attr) {
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, (string) $item->{$attr});
         }
         $key++;
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, date(erLhcoreClassModule::$dateFormat, $item->time));
         $key++;
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, date('H:i:s', $item->time));
         $key++;
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, $item->fbst == 1 ? 'UP' : ($item->fbst == 2 ? 'DOWN' : 'NONE'));
         $key++;
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, $item->mail_send == 1 ? 'Yes' : 'No');
         $key++;
         if ($item->referrer != '') {
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, $item->referrer);
         }
         $key++;
         if ($item->session_referrer != '') {
             $referer = parse_url($item->session_referrer);
             if (isset($referer['host'])) {
                 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, $referer['host']);
             }
         }
         $key++;
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, "URL");
         $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($key, $i)->getHyperlink()->setUrl(erLhcoreClassXMP::getBaseHost() . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('user/login') . '/(r)/' . rawurlencode(base64_encode('chat/single/' . $item->id)));
         // Print chat content to last column
         if (isset($params['type']) && $params['type'] == 2) {
             $key++;
             $messages = erLhcoreClassModelmsg::getList(array('limit' => 10000, 'sort' => 'id ASC', 'filter' => array('chat_id' => $item->id)));
             $messagesContent = '';
             foreach ($messages as $msg) {
                 if ($msg->user_id == -1) {
                     $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmin', 'System assistant') . ': ' . htmlspecialchars($msg->msg) . "\n";
                 } else {
                     $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . ($msg->user_id == 0 ? htmlspecialchars($item->nick) : htmlspecialchars($msg->name_support)) . ': ' . htmlspecialchars($msg->msg) . "\n";
                 }
             }
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, trim($messagesContent));
         }
         $i++;
     }
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
     // We'll be outputting an excel file
     header('Content-type: application/vnd.ms-excel');
     // It will be called file.xls
     header('Content-Disposition: attachment; filename="report.xlsx"');
     // Write file to the browser
     $objWriter->save('php://output');
 }
Exemplo n.º 12
0
 public static function sendXMPMessage($chat, $params = array())
 {
     $data = (array) erLhcoreClassModelChatConfig::fetch('xmp_data')->data;
     $templateMessage = 'xmp_message';
     if (isset($params['template'])) {
         $templateMessage = $params['template'];
     }
     if (isset($data['use_xmp']) && $data['use_xmp'] == 1) {
         if (isset($data['use_standard_xmp']) && $data['use_standard_xmp'] == '0' || !isset($data['use_standard_xmp'])) {
             $conn = new XMPPHP_XMPP($data['host'], $data['port'], $data['username'], $data['password'], $data['resource'], $data['server'], $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO);
             try {
                 $conn->connect();
                 $conn->processUntil('session_start');
                 $emailRecipient = array();
                 // Email messages
                 $groupRecipients = array();
                 // Group messages
                 if ($chat->department !== false && $chat->department->xmpp_recipients != '') {
                     // Perhaps department has assigned email
                     $emailRecipient = explode(',', $chat->department->xmpp_recipients);
                 } elseif (isset($data['recipients']) && $data['recipients'] != '') {
                     $emailRecipient = explode(',', $data['recipients']);
                 }
                 if ($chat->department !== false && $chat->department->xmpp_group_recipients != '') {
                     $groupRecipients = explode(',', $chat->department->xmpp_group_recipients);
                 }
                 // change status
                 foreach ($groupRecipients as $recipient) {
                     $conn->presence(NULL, 'available', $recipient);
                 }
                 if (!empty($emailRecipient)) {
                     $conn->presence();
                 }
                 $messages = array_reverse(erLhcoreClassModelmsg::getList(array('limit' => 5, 'sort' => 'id DESC', 'filter' => array('chat_id' => $chat->id))));
                 $messagesContent = '';
                 foreach ($messages as $msg) {
                     if ($msg->user_id == -1) {
                         $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmin', 'System assistant') . ': ' . htmlspecialchars($msg->msg) . "\n";
                     } else {
                         $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . ($msg->user_id == 0 ? htmlspecialchars($chat->nick) : htmlspecialchars($msg->name_support)) . ': ' . htmlspecialchars($msg->msg) . "\n";
                     }
                 }
                 $cfgSite = erConfigClassLhConfig::getInstance();
                 $secretHash = $cfgSite->getSetting('site', 'secrethash');
                 foreach ($emailRecipient as $email) {
                     $veryfyEmail = sha1(sha1($email . $secretHash) . $secretHash);
                     $messagesParsed = str_replace(array('{messages}', '{url_accept}', '{chat_id}', '{user_name}'), array($messagesContent, self::getBaseHost() . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('chat/accept') . '/' . erLhcoreClassModelChatAccept::generateAcceptLink($chat) . '/' . $veryfyEmail . '/' . $email, $chat->id, $chat->user_name), $data[$templateMessage]);
                     $conn->message($email, $messagesParsed);
                 }
                 foreach ($groupRecipients as $email) {
                     list($emailGroup) = explode('/', $email);
                     $veryfyEmail = sha1(sha1($emailGroup . $secretHash) . $secretHash);
                     $messagesParsed = str_replace(array('{messages}', '{url_accept}', '{chat_id}', '{user_name}'), array($messagesContent, self::getBaseHost() . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('chat/accept') . '/' . erLhcoreClassModelChatAccept::generateAcceptLink($chat) . '/' . $veryfyEmail . '/' . $emailGroup, $chat->id, $chat->user_name), $data[$templateMessage]);
                     $conn->message($emailGroup, $messagesParsed, 'groupchat');
                 }
                 foreach ($groupRecipients as $recipient) {
                     $conn->presence(NULL, 'unavailable', $recipient);
                 }
                 $conn->disconnect();
                 return true;
             } catch (Exception $e) {
                 throw $e;
             }
         } else {
             if (($accessToken = self::getAccessToken()) !== false) {
                 $dataLogin = self::get_dns_srv('gmail.com');
                 $conn = new XMPPHP_XMPP($dataLogin[0], $dataLogin[1], $data['email_gtalk'], $accessToken, 'xmpphp', $dataLogin[0], $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO, true);
                 try {
                     $conn->connect();
                     $conn->processUntil('session_start');
                     $conn->presence();
                     $emailRecipient = array();
                     if ($chat->department !== false && $chat->department->xmpp_recipients != '') {
                         // Perhaps department has assigned email
                         $emailRecipient = explode(',', $chat->department->xmpp_recipients);
                     } elseif (isset($data['recipients']) && $data['recipients'] != '') {
                         $emailRecipient = explode(',', $data['recipients']);
                     }
                     $messages = array_reverse(erLhcoreClassModelmsg::getList(array('limit' => 5, 'sort' => 'id DESC', 'filter' => array('chat_id' => $chat->id))));
                     $messagesContent = '';
                     foreach ($messages as $msg) {
                         if ($msg->user_id == -1) {
                             $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmin', 'System assistant') . ': ' . htmlspecialchars($msg->msg) . "\n";
                         } else {
                             $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . ($msg->user_id == 0 ? htmlspecialchars($chat->nick) : htmlspecialchars($msg->name_support)) . ': ' . htmlspecialchars($msg->msg) . "\n";
                         }
                     }
                     $cfgSite = erConfigClassLhConfig::getInstance();
                     $secretHash = $cfgSite->getSetting('site', 'secrethash');
                     foreach ($emailRecipient as $email) {
                         $veryfyEmail = sha1(sha1($email . $secretHash) . $secretHash);
                         $conn->message($email, str_replace(array('{messages}', '{url_accept}', '{chat_id}', '{user_name}'), array($messagesContent, self::getBaseHost() . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('chat/accept') . '/' . erLhcoreClassModelChatAccept::generateAcceptLink($chat) . '/' . $veryfyEmail . '/' . $email, $chat->id, $chat->user_name), $data[$templateMessage]));
                     }
                     $conn->disconnect();
                     return true;
                 } catch (Exception $e) {
                     throw $e;
                 }
             } else {
                 throw new Exception('Invalid access token');
             }
         }
     }
 }
Exemplo n.º 13
0
<?php

// Do not edit this file but create an override
echo json_encode(array('chat' => $chat, 'msg' => erLhcoreClassModelmsg::getList(array('limit' => 5000, 'filter' => array('chat_id' => $chat->id)))));
Exemplo n.º 14
0
 public static function chatListExportXLS($chats, $params = array())
 {
     include 'lib/core/lhform/PHPExcel.php';
     $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
     $cacheSettings = array('memoryCacheSize ' => '64MB');
     PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
     $chatArray = array();
     $id = "ID";
     $name = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Visitor Name');
     $email = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'E-mail');
     $phone = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Phone');
     $wait = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Wait time');
     $country = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Country');
     $city = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'City');
     $ip = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'IP');
     $operator = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Operator');
     $dept = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Department');
     $date = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Date');
     $minutes = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Minutes');
     $vote = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Vote status');
     $mail = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Mail send');
     $page = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Page');
     $from = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Came from');
     $link = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Link');
     if (isset($params['type']) && $params['type'] == 2) {
         $content = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Chat content');
     } else {
         $content = null;
     }
     $chatArray[] = array($id, $name, $email, $phone, $wait, $country, $city, $ip, $operator, $dept, $date, $minutes, $vote, $mail, $page, $from, $link, $content);
     foreach ($chats as $item) {
         $id = (string) $item->{'id'};
         $nick = (string) $item->{'nick'};
         $email = (string) $item->{'email'};
         $phone = (string) $item->{'phone'};
         $wait = (string) $item->{'wait_time'};
         $country = (string) $item->{'country_name'};
         $city = (string) $item->{'city'};
         $ip = (string) $item->{'ip'};
         $user = (string) $item->{'user'};
         $dept = (string) $item->{'department'};
         $date = date(erLhcoreClassModule::$dateFormat, $item->time);
         $minutes = date('H:i:s', $item->time);
         $vote = $item->fbst == 1 ? 'UP' : ($item->fbst == 2 ? 'DOWN' : 'NONE');
         $mail = $item->mail_send == 1 ? 'Yes' : 'No';
         $page = $item->referrer;
         if ($item->session_referrer != '') {
             $referer = parse_url($item->session_referrer);
             if (isset($referer['host'])) {
                 $from = $referer['host'];
             } else {
                 $from = null;
             }
         } else {
             $from = null;
         }
         $url = erLhcoreClassXMP::getBaseHost() . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('user/login') . '/(r)/' . rawurlencode(base64_encode('chat/single/' . $item->id));
         // Print chat content to last column
         if (isset($params['type']) && $params['type'] == 2) {
             $messages = erLhcoreClassModelmsg::getList(array('limit' => 10000, 'sort' => 'id ASC', 'filter' => array('chat_id' => $item->id)));
             $messagesContent = '';
             foreach ($messages as $msg) {
                 if ($msg->user_id == -1) {
                     $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmin', 'System assistant') . ': ' . htmlspecialchars($msg->msg) . "\n";
                 } else {
                     $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . ($msg->user_id == 0 ? htmlspecialchars($item->nick) : htmlspecialchars($msg->name_support)) . ': ' . htmlspecialchars($msg->msg) . "\n";
                 }
             }
             $chatArray[] = array($id, $nick, $email, $phone, $wait, $country, $city, $ip, $user, $dept, $date, $minutes, $vote, $mail, $page, $from, $url, trim($messagesContent));
         } else {
             $chatArray[] = array($id, $nick, $email, $phone, $wait, $country, $city, $ip, $user, $dept, $date, $minutes, $vote, $mail, $page, $from, $url);
         }
     }
     // Create new PHPExcel object
     $objPHPExcel = new PHPExcel();
     $objPHPExcel->setActiveSheetIndex(0);
     // Set the starting point and array of data
     $objPHPExcel->getActiveSheet()->fromArray($chatArray, null, 'A1');
     // Set style for top row
     $objPHPExcel->getActiveSheet()->getStyle('A1:AW1')->getFont()->setBold(true);
     // Set file type and name of file
     header('Content-Type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename="report.xlsx"');
     header('Cache-Control: max-age=0');
     $writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
     $writer->save('php://output');
 }