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(); } } }
exit; } if (is_object($chat) && $chat->hash == $Params['user_parameters']['hash'] && ($chat->status == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT || erLhcoreClassChat::canReopen($chat, true))) { 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()));