function CreateChat($_internalUser, $_visitor, $_host = false, $custom = "", $etpl = "", $_customsInTranscript = true, $_externalSelf = true, $pdm = null) { global $CONFIG; if (!empty($CONFIG["gl_sfc"]) && createSPAMFilter() || empty($this->ChatId)) { return; } UserGroup::PersistentJoin($this->UserId, $this->SystemId); $this->InternalUser = $_internalUser; $this->InternalUser->SetLastChatAllocation(); $this->SetStatus(CHAT_STATUS_WAITING); initData(array("INPUTS")); queryDB(false, "INSERT INTO `" . DB_PREFIX . DATABASE_VISITOR_CHAT_OPERATORS . "` (`chat_id`,`user_id`,`jtime`,`status`) VALUES ('" . DBManager::RealEscape($this->ChatId) . "','" . DBManager::RealEscape($this->InternalUser->SystemId) . "'," . time() . "," . ($_host ? 0 : 1) . ");"); $this->CreateArchiveEntry($_internalUser, $_visitor, $custom, $etpl, $_customsInTranscript, $pdm); if ($_internalUser->IsBot) { define("CALLER_SYSTEM_ID", $_internalUser->SystemId); $this->InternalActivate(); $this->ExternalActivate(); $this->SetStatus(CHAT_STATUS_ACTIVE); } else { if (!empty($_internalUser->AppDeviceId) && $_internalUser->AppBackgroundMode) { $name = !empty($this->Fullname) ? $this->Fullname : getNoName($this->UserId . getIP()); $_internalUser->AddPushMessage($this->ChatId, $this->SystemId, $name, 0); } } if (!empty($_GET["acid"])) { $pchatid = base64UrlDecode($_GET["acid"]); $result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` WHERE `visitor_id`='" . DBManager::RealEscape($this->UserId) . "' AND `chat_id`='" . DBManager::RealEscape($pchatid) . "' AND (`exit` > " . (time() - 30) . " OR `exit`=0) LIMIT 1;"); if ($result && DBManager::GetRowCount($result) == 1) { $row = DBManager::FetchArray($result); if (empty($row["waiting"])) { $this->RepostChatHistory(2, $pchatid, $this->InternalUser->SystemId, 0, 0, $this->UserId . "~" . $this->UserId . "_OVL", $this->ChatId, $this->SystemId, true, false, $_externalSelf); } } } }
function processPosts($counter = 0) { global $USER, $STATS, $GROUPS, $INTERNAL, $LZLANG; while (isset($_POST["p_p" . $counter])) { if (STATS_ACTIVE) { $STATS->ProcessAction(ST_ACTION_EXTERNAL_POST); } $id = md5($USER->Browsers[0]->SystemId . base64UrlDecode($_POST[POST_EXTERN_CHAT_ID]) . base64UrlDecode($_POST["p_i" . $counter])); $senderName = !empty($USER->Browsers[0]->Fullname) ? $USER->Browsers[0]->Fullname : $LZLANG["client_guest"] . " " . getNoName($USER->UserId . getIP()); $post = new Post($id, $USER->Browsers[0]->SystemId, "", base64UrlDecode($_POST["p_p" . $counter]), time(), $USER->Browsers[0]->ChatId, $senderName); foreach ($GROUPS as $groupid => $group) { if ($group->IsDynamic && !empty($group->Members[$USER->Browsers[0]->SystemId])) { foreach ($group->Members as $member => $persistent) { if ($member != $USER->Browsers[0]->SystemId) { if (!empty($INTERNAL[$member])) { processPost($id, $post, $member, $counter, $groupid, $USER->Browsers[0]->ChatId); } else { processPost($id, $post, $member, $counter, $groupid, getValueBySystemId($member, "chat_id", "")); } } } $pGroup = $group; } } foreach ($USER->Browsers[0]->Members as $systemid => $member) { if (!empty($member->Declined)) { continue; } if (!empty($INTERNAL[$systemid]) && !empty($pGroup->Members[$systemid])) { continue; } if (!(!empty($pGroup) && !empty($INTERNAL[$systemid]))) { processPost($id, $post, $systemid, $counter, $USER->Browsers[0]->SystemId, $USER->Browsers[0]->ChatId); } } $autoReply = $USER->Browsers[0]->InternalUser->GetAutoReplies($post->Text, $USER->Browsers[0]); if (!empty($autoReply)) { $arpost = new Post($id = getId(32), $USER->Browsers[0]->InternalUser->SystemId, $USER->Browsers[0]->SystemId, $autoReply, time(), $USER->Browsers[0]->ChatId, $USER->Browsers[0]->InternalUser->Fullname); $arpost->ReceiverOriginal = $arpost->ReceiverGroup = $USER->Browsers[0]->SystemId; $arpost->Save(); foreach ($USER->Browsers[0]->Members as $opsysid => $member) { $rpost = new Post($id, $USER->Browsers[0]->InternalUser->SystemId, $opsysid, $autoReply, time(), $USER->Browsers[0]->ChatId, $INTERNAL[$systemid]->Fullname); $rpost->ReceiverOriginal = $rpost->ReceiverGroup = $USER->Browsers[0]->SystemId; $rpost->Save(); } } $USER->AddFunctionCall("lz_chat_release_post('" . base64UrlDecode($_POST["p_i" . $counter]) . "');", false); $counter++; } $counter = 0; while (isset($_POST["pr_i" . $counter])) { $post = new Post(base64UrlDecode($_POST["pr_i" . $counter]), "", "", "", "", "", ""); $post->MarkReceived($USER->Browsers[0]->SystemId); $USER->AddFunctionCall("lz_chat_message_set_received('" . base64UrlDecode($_POST["pr_i" . $counter]) . "');", false); $counter++; } }
function closeArchiveEntry($_chatId, $_externalFullname, $_externalId, $_internalId, $_groupId, $_email, $_company, $_phone, $_host, $_ip, $_question, $_transcriptSent = false, $_waitingtime, $_startResult, $_endResult) { global $CONFIG, $LZLANG; $result = queryDB(true, "SELECT `voucher_id`,`endtime`,`transcript_text`,`iso_language`,`time` FROM `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` WHERE `chat_type`=1 AND `chat_id`='" . DBManager::RealEscape($_chatId) . "' LIMIT 1;"); $row = DBManager::FetchArray($result); languageSelect($row["iso_language"], true); $etpl = $row["transcript_text"]; $etpl = applyReplacements($etpl, true, false, false); CacheManager::SetDataUpdateTime(DATA_UPDATE_KEY_CHATS); $_externalFullname = empty($_externalFullname) ? $LZLANG["client_guest"] . " " . getNoName($_externalId . $_ip) : $_externalFullname; $filter = new Chat(); $filter->Generate($_chatId, $_externalFullname, true, true, $_question, $row["time"]); $filter->PlainText = applyReplacements($filter->PlainText, true, false, false); $filter->HTML = applyReplacements($filter->HTML, true, false, false); if (!empty($filter->PlainText)) { $etpl = str_replace("%localdate%", date("r", $filter->FirstPost), $etpl); if (strpos($etpl, "%transcript%") === false && strpos($etpl, "%mailtext%") === false) { $etpl .= $filter->PlainText; } else { if (strpos($etpl, "%transcript%") !== false) { $etpl = str_replace("%transcript%", $filter->PlainText, $etpl); } else { if (strpos($etpl, "%mailtext%") !== false) { $etpl = str_replace("%mailtext%", $filter->PlainText, $etpl); } } } } else { $etpl = ""; } $etpl = str_replace(array("%email%", "%eemail%"), $_email, $etpl); $etpl = str_replace(array("%fullname%", "%efullname%"), $_externalFullname, $etpl); $etpl = str_replace("%rating%", getRatingAVGFromChatId($_chatId), $etpl); $name = !empty($_externalFullname) ? ",`fullname`='" . DBManager::RealEscape($_externalFullname) . "'" : ""; queryDB(true, "UPDATE `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` SET `external_id`='" . DBManager::RealEscape($_externalId) . "',`closed`='" . DBManager::RealEscape(time()) . "'" . $name . ",`internal_id`='" . DBManager::RealEscape($_internalId) . "',`group_id`='" . DBManager::RealEscape($_groupId) . "',`html`='" . DBManager::RealEscape($filter->HTML) . "',`plaintext`='" . DBManager::RealEscape($filter->PlainText) . "',`transcript_text`='" . DBManager::RealEscape($etpl) . "',`email`='" . DBManager::RealEscape($_email) . "',`company`='" . DBManager::RealEscape($_company) . "',`phone`='" . DBManager::RealEscape($_phone) . "',`host`='" . DBManager::RealEscape($_host) . "',`ip`='" . DBManager::RealEscape($_ip) . "',`gzip`=0,`wait`='" . DBManager::RealEscape($_waitingtime) . "',`accepted`='" . DBManager::RealEscape($_startResult) . "',`ended`='" . DBManager::RealEscape($_endResult) . "',`transcript_sent`='" . DBManager::RealEscape(empty($CONFIG["gl_soct"]) && empty($CONFIG["gl_scct"]) && empty($CONFIG["gl_scto"]) && empty($CONFIG["gl_sctg"]) || empty($etpl) || $filter->ElementCount == 0 || $_transcriptSent ? "1" : "0") . "',`question`='" . DBManager::RealEscape(cutString($_question, 255)) . "' WHERE `chat_id`='" . DBManager::RealEscape($_chatId) . "' AND `closed`=0 LIMIT 1;"); $result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "` WHERE `channel_id`='" . DBManager::RealEscape($_chatId) . "';"); if ($result && ($rowc = DBManager::FetchArray($result))) { $Ticket = new Ticket($rowc["ticket_id"], true); $Ticket->LinkChat($rowc["channel_id"], $rowc["id"]); } }
initChat(); } } if (!empty($USER->Browsers[0]->Forward) && !$USER->Browsers[0]->Forward->Received && $USER->Browsers[0]->Forward->Processed) { $USER->Browsers[0]->Forward->Save(true, true); $ACTIVE_OVLC = !$USER->Browsers[0]->Declined; } } if (!empty($USER->Browsers[0]->ChatId)) { $USER->AddFunctionCall("lz_chat_id='" . $USER->Browsers[0]->ChatId . "';", false); } $HTML = ""; $USER->Browsers[0]->VisitId = $USER->VisitId; while (!empty($_GET["mi" . $pc])) { $id = !empty($_GET["mrid" . $pc]) ? $_GET["mrid" . $pc] : md5($USER->Browsers[0]->SystemId . $USER->Browsers[0]->ChatId . $_GET["mi" . $pc]); $senderName = !empty($USER->Browsers[0]->Fullname) ? $USER->Browsers[0]->Fullname : $LZLANG["client_guest"] . " " . getNoName($USER->UserId . getIP()); $post = new Post($id, $USER->Browsers[0]->SystemId, "", base64UrlDecode($_GET["mp" . $pc]), !empty($_GET["mc" . $pc]) ? $_GET["mc" . $pc] : time(), $USER->Browsers[0]->ChatId, $senderName); $post->BrowserId = $BROWSER->BrowserId; if (!empty($_GET["mpti" . $pc])) { $post->Translation = base64UrlDecode($_GET["mpt" . $pc]); $post->TranslationISO = base64UrlDecode($_GET["mpti" . $pc]); } $saved = false; if (!$USER->Browsers[0]->Waiting) { foreach ($GROUPS as $groupid => $group) { if ($group->IsDynamic && $USER->Browsers[0]->Status == CHAT_STATUS_ACTIVE && !empty($group->Members[$USER->Browsers[0]->SystemId])) { foreach ($group->Members as $member => $persistent) { if ($member != $USER->Browsers[0]->SystemId) { if (!empty($INTERNAL[$member])) { processPost($id, $post, $member, $pc, $groupid, $USER->Browsers[0]->ChatId); } else {