function Save() { if ($this->Size == 0) { $this->Size = strlen($this->Title); } $result = DBManager::Execute(true, "SELECT `id`,`value` FROM `" . DB_PREFIX . DATABASE_RESOURCES . "` WHERE `id`='" . DBManager::RealEscape($this->Id) . "'"); if (DBManager::GetRowCount($result) == 0) { if (!$this->IsDiscarded) { DBManager::Execute(true, "INSERT INTO `" . DB_PREFIX . DATABASE_RESOURCES . "` (`id`,`owner`,`editor`,`value`,`edited`,`title`,`created`,`type`,`discarded`,`parentid`,`size`,`tags`,`languages`,`kb_public`,`kb_bot`,`kb_ft_search`,`shortcut_word`) VALUES ('" . DBManager::RealEscape($this->Id) . "','" . DBManager::RealEscape($this->OwnerId) . "','" . DBManager::RealEscape($this->EditorId) . "','" . DBManager::RealEscape($this->Value) . "'," . intval(time()) . ",'" . DBManager::RealEscape($this->Title) . "'," . intval(time()) . "," . intval($this->Type) . "," . intval($this->IsDiscarded ? 1 : 0) . ",'" . DBManager::RealEscape($this->ParentId) . "','" . DBManager::RealEscape($this->Size) . "','" . DBManager::RealEscape($this->Tags) . "','" . DBManager::RealEscape($this->Languages) . "'," . intval($this->IsPublic ? 1 : 0) . "," . intval($this->AllowBotAccess ? 1 : 0) . "," . intval($this->FulltextSearch ? 1 : 0) . ",'" . DBManager::RealEscape($this->ShortcutWord) . "')"); } } else { $row = DBManager::FetchArray($result); DBManager::Execute(true, $result = "UPDATE `" . DB_PREFIX . DATABASE_RESOURCES . "` SET `value`='" . DBManager::RealEscape($this->Value) . "',`editor`='" . DBManager::RealEscape($this->EditorId) . "',`tags`='" . DBManager::RealEscape($this->Tags) . "',`title`='" . DBManager::RealEscape($this->Title) . "',`edited`=" . intval(time()) . ",`discarded`='" . intval($this->IsDiscarded ? 1 : 0) . "',`parentid`='" . DBManager::RealEscape($this->ParentId) . "',`size`='" . DBManager::RealEscape($this->Size) . "',`languages`='" . DBManager::RealEscape($this->Languages) . "',`kb_public`=" . intval($this->IsPublic ? 1 : 0) . ",`kb_bot`=" . intval($this->AllowBotAccess ? 1 : 0) . ",`kb_ft_search`=" . intval($this->FulltextSearch ? 1 : 0) . ",`kb_bot`=" . intval($this->AllowBotAccess ? 1 : 0) . ",`shortcut_word`='" . DBManager::RealEscape($this->ShortcutWord) . "' WHERE id='" . DBManager::RealEscape($this->Id) . "' LIMIT 1"); if (!empty($_disc) && ($this->Type == RESOURCE_TYPE_FILE_INTERNAL || $this->Type == RESOURCE_TYPE_FILE_EXTERNAL) && @file_exists("./uploads/" . $row["value"]) && strpos($row["value"], "..") === false) { @unlink("./uploads/" . $row["value"]); } } }
function BuildElements() { global $USER; $this->SpeakingToHTML = $this->GetSpeakingToHTML($this->CurrentOperatorId); $this->PostHTML = ""; $pstrchngreq = $this->PlaySound = $this->SpeakingToAdded = false; $this->OperatorPostCount = 0; $this->LastPost = ""; $this->Flags["LPP"] = $this->LastPoster; if (!$USER->FirstCall && !$USER->Browsers[0]->Declined && ($result = DBManager::Execute(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_POSTS . "` WHERE `chat_id`='" . DBManager::RealEscape($USER->Browsers[0]->ChatId) . "' AND `chat_id`!='' AND `chat_id`!='0' AND (`receiver`='" . DBManager::RealEscape($USER->Browsers[0]->SystemId) . "' OR (`sender`='" . DBManager::RealEscape($USER->Browsers[0]->SystemId) . "' AND `repost`=0)) GROUP BY `id` ORDER BY `time` ASC, `micro` ASC;"))) { $all = DBManager::GetRowCount($result); if ($all > 0) { $count = OverlayChat::$MaxPosts - $all; while ($row = DBManager::FetchArray($result)) { if ($count++ >= 0) { $postobj = new Post($row); if (empty(Server::$Operators[$postobj->Sender])) { $postobj->Text = htmlentities($postobj->Text, ENT_QUOTES, 'UTF-8'); $postobj->Translation = htmlentities($postobj->Translation, ENT_QUOTES, 'UTF-8'); } if ($USER->Browsers[0]->AllocatedTime > 0 && $USER->Browsers[0]->AllocatedTime && !$this->SpeakingToAdded) { $this->Flags["LPP"] = "sys"; $this->PostHTML .= $this->SpeakingToHTML; $this->SpeakingToAdded = true; } $post = $this->GetPostHTML($postobj->Text, $postobj->Translation, $this->Flags["LPP"] != $postobj->Sender || $pstrchngreq, $postobj->Sender != $USER->Browsers[0]->SystemId, $postobj->Sender != $USER->Browsers[0]->SystemId ? $postobj->SenderName : htmlentities($USER->Browsers[0]->UserData->Fullname, ENT_QUOTES, "UTF-8"), $postobj->Created, $postobj->Sender); $pstrchngreq = false; if ($postobj->Sender != $USER->Browsers[0]->SystemId) { $this->OperatorPostCount++; } if (!$postobj->Received && $postobj->Sender != $USER->Browsers[0]->SystemId) { $this->PlaySound = true; } $postobj->MarkReceived($USER->Browsers[0]->SystemId); if ($this->FullLoad || $postobj->Sender != $USER->Browsers[0]->SystemId || $postobj->BrowserId != VisitorMonitoring::$Browser->BrowserId) { $this->Flags["LPP"] = $postobj->Sender; } if (empty($_GET["full"]) && $postobj->Id == $this->Flags["LPR"]) { $this->PlaySound = false; $this->PostHTML = $this->SpeakingToHTML; $this->SpeakingToAdded = true; $this->OperatorPostCount = 0; $this->Flags["LPP"] = !empty($this->SpeakingToHTML) ? "sys" : $this->LastPoster; if ($USER->Browsers[0]->AllocatedTime > 0 && $postobj->Created < $USER->Browsers[0]->AllocatedTime) { $pstrchngreq = true; } } else { if ($this->FullLoad || $postobj->Sender != $USER->Browsers[0]->SystemId || $postobj->BrowserId != VisitorMonitoring::$Browser->BrowserId) { $this->PostHTML .= $post; } } $this->LastPostReceived = "'" . base64_encode($postobj->Id) . "'"; if ($postobj->Sender == $USER->Browsers[0]->SystemId) { $this->LastPost = $postobj->Text; } } } } } }
function Load() { $result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_STATS_AGGS . "` WHERE" . $this->GetDateMatch() . ";"); if (DBManager::GetRowCount($result) === 1) { $row = DBManager::FetchArray($result); $this->AVGTimeOnSiteTotal = $row["avg_time_site"]; $this->VisitorsTotal = $row["sessions"]; $this->VisitorsUnique = $row["visitors_unique"]; $this->ConversionsTotal = $row["conversions"]; $resultc = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_CHATS . "` WHERE" . $this->GetNoneAggregatedDateMatch() . ";"); while ($rowc = DBManager::FetchArray($resultc)) { $this->ChatsTotal += $rowc["amount"] - $rowc["multi"]; $this->ChatsDeclinedTotal += $rowc["declined"]; $this->ChatsAcceptedTotal += $rowc["accepted"]; $this->ChatsMissedTotal += $rowc["amount"] - $rowc["multi"] - ($rowc["declined"] + $rowc["accepted"]); $this->AVGTimeInChat += $rowc["avg_duration"] * $rowc["amount"]; $this->AVGWaitingTime += $rowc["avg_waiting_time"] * $rowc["amount"]; } if (!empty($this->ChatsTotal)) { $this->AVGWaitingTime = floor($this->AVGWaitingTime / $this->ChatsTotal); $this->AVGTimeInChat = floor($this->AVGTimeInChat / $this->ChatsTotal); } $row = DBManager::FetchArray(queryDB(true, "SELECT SUM(`seconds`) AS `avail` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_AVAILABILITIES . "` WHERE `user_id`='everyoneintern' AND" . $this->GetNoneAggregatedDateMatch() . ";")); $this->ChatAvailabilityTotal = $row["avail"]; $row = DBManager::FetchArray(queryDB(true, "SELECT SUM(`amount`) AS `queries` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_QUERIES . "` INNER JOIN `" . DB_PREFIX . DATABASE_VISITOR_DATA_QUERIES . "` ON `" . DB_PREFIX . DATABASE_STATS_AGGS_QUERIES . "`.query=`" . DB_PREFIX . DATABASE_VISITOR_DATA_QUERIES . "`.id WHERE`" . DB_PREFIX . DATABASE_VISITOR_DATA_QUERIES . "`.query!='' AND" . $this->GetDateMatch() . ";")); $this->QueryAmountTotal = $row["queries"]; $row = DBManager::FetchArray(queryDB(true, "SELECT SUM(`amount`) AS `crawlers` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_CRAWLERS . "` WHERE" . $this->GetDateMatch() . ";")); $this->CrawlerAccessTotal = $row["crawlers"]; if ($this->VisitorsTotal > 0) { $this->AVGPagesTotal = @round($this->PageImpressionsTotal / $this->VisitorsTotal, StatisticProvider::$RoundPrecision); $this->AVGBrowserInstances = @round($this->BrowserInstancesTotal / $this->VisitorsTotal, StatisticProvider::$RoundPrecision); } if ($this->AVGTimeOnSiteTotal > 0 && $this->AVGPagesTotal > 0) { $this->AVGTimeOnPageTotal = round($this->AVGTimeOnSiteTotal / $this->AVGPagesTotal, 4); } $this->DirectAccessTotal = $this->VisitorsTotal - $this->FromReferrerTotal - $this->FromSearchEngineTotal; $this->TCP = round($this->PageImpressionsTotal * 0.5 / 1000, 4); $this->LoadTopTable(3, 100, array(DATABASE_STATS_AGGS_QUERIES, DATABASE_VISITOR_DATA_QUERIES), array("query", "query"), false, $this->QueryAmountTotal); $this->LoadTopTable(0, 32, array(DATABASE_STATS_AGGS_BROWSERS, DATABASE_VISITOR_DATA_BROWSERS), array("browser", "browser"), true, $this->VisitorsTotal); $this->LoadTopTable(1, 32, array(DATABASE_STATS_AGGS_SYSTEMS, DATABASE_VISITOR_DATA_SYSTEMS), array("system", "system"), true, $this->VisitorsTotal); $this->LoadTopTable(2, 32, array(DATABASE_STATS_AGGS_COUNTRIES), array("country", "country"), true, $this->VisitorsTotal); $this->LoadTopTable(4, 32, array(DATABASE_STATS_AGGS_CITIES, DATABASE_VISITOR_DATA_CITIES), array("city", "city"), true, $this->VisitorsTotal); $this->LoadTopTable(5, 32, array(DATABASE_STATS_AGGS_RESOLUTIONS, DATABASE_VISITOR_DATA_RESOLUTIONS), array("resolution", "resolution"), true, $this->VisitorsTotal); $this->LoadTopTable(6, 32, array(DATABASE_STATS_AGGS_LANGUAGES), array("language", "language"), true, $this->VisitorsTotal); $this->LoadTopTable(7, 32, array(DATABASE_STATS_AGGS_REGIONS, DATABASE_VISITOR_DATA_REGIONS), array("region", "region"), true, $this->VisitorsTotal); $this->LoadTopTable(11, 32, array(DATABASE_STATS_AGGS_VISITS), array("visits", "visits"), true, $this->VisitorsTotal, false); $this->LoadTopTable(12, 100, array(DATABASE_STATS_AGGS_ISPS, DATABASE_VISITOR_DATA_ISPS), array("isp", "isp"), true, $this->VisitorsTotal, false); $this->LoadTopTable(16, 100, array(DATABASE_STATS_AGGS_CRAWLERS, DATABASE_VISITOR_DATA_CRAWLERS), array("crawler", "crawler"), true, $this->CrawlerAccessTotal, false); $this->LoadTopTable(13, 32, array(DATABASE_STATS_AGGS_DURATIONS), array("duration", "duration"), true, $this->VisitorsTotal, false, "amount", "duration", "ASC"); $this->LoadTopTable(14, 100, array(DATABASE_STATS_AGGS_DOMAINS, DATABASE_VISITOR_DATA_DOMAINS), array("domain", "domain"), true, $this->PageImpressionsTotal); $this->LoadURLTable(DATABASE_STATS_AGGS_PAGES, 9, 90, false, $this->PageImpressionsTotal); $this->LoadURLTable(DATABASE_STATS_AGGS_PAGES, 10, 90, true, $this->PageImpressionsTotal); $this->LoadURLTable(DATABASE_STATS_AGGS_PAGES_ENTRANCE, 17, 90, false, $this->BrowserInstancesTotal - $this->ChatPagesTotal); $this->LoadURLTable(DATABASE_STATS_AGGS_PAGES_ENTRANCE, 18, 90, true, $this->BrowserInstancesTotal - $this->ChatPagesTotal); $this->LoadURLTable(DATABASE_STATS_AGGS_PAGES_EXIT, 19, 90, false, $this->BrowserInstancesTotal - $this->ChatPagesTotal); $this->LoadURLTable(DATABASE_STATS_AGGS_PAGES_EXIT, 20, 90, true, $this->BrowserInstancesTotal - $this->ChatPagesTotal); $this->LoadReferrerTable(30, 80, DATABASE_STATS_AGGS_REFERRERS, true, $this->FromReferrerTotal); $this->LoadReferrerTable(31, 80, DATABASE_STATS_AGGS_REFERRERS, false, $this->FromReferrerTotal, "`" . DB_PREFIX . DATABASE_VISITOR_DATA_DOMAINS . "`.`domain`"); $this->LoadSearchEngineTable(15, 80, $this->FromSearchEngineTotal); $this->Tops[21] = array(); $result = queryDB(true, "SELECT `title`,`description`,`id` AS `gid`,(SELECT SUM(`amount`) FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_GOALS . "` WHERE" . $this->GetDateMatch() . " AND `goal`=`gid`) AS `gcount` FROM `" . DB_PREFIX . DATABASE_GOALS . "` ORDER BY `ind` ASC;"); while ($row = DBManager::FetchArray($result)) { if ($this->VisitorsTotal > 0 && !empty($row["gcount"])) { $tqueries = array(); $results = queryDB(true, "SELECT t1.amount,t2.query FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_GOALS_QUERIES . "` AS t1 INNER JOIN `" . DB_PREFIX . DATABASE_VISITOR_DATA_QUERIES . "` AS t2 ON t1.query=t2.id WHERE" . $this->GetDateMatch() . " AND t1.goal='" . DBManager::RealEscape($row["gid"]) . "' ORDER BY t1.amount DESC LIMIT " . StatisticProvider::$DayItemAmount . ";"); while ($rows = DBManager::FetchArray($results)) { $tqueries[] = array("qa", $rows["query"], $rows["amount"]); } $this->Tops[21][$row["gid"]] = array($row["gcount"], round(100 * $row["gcount"] / $this->VisitorsTotal, StatisticProvider::$RoundPrecision), 100 - floor(100 * $row["gcount"] / $this->VisitorsTotal), $row["title"], $row["description"], $tqueries); } else { $this->Tops[21][$row["gid"]] = array(0, 0, 100, $row["title"], $row["description"]); } } return true; } return false; }
function buildReports($xml = "") { global $RESPONSE, $STATS, $INTERNAL; if (empty($_POST[POST_INTERN_XMLCLIP_REPORTS_END_TIME])) { return; } if (empty($STATS->CurrentDay) || $INTERNAL[CALLER_SYSTEM_ID]->GetPermission(PERMISSION_REPORTS) == PERMISSION_NONE) { return; } if ($_POST[POST_INTERN_XMLCLIP_REPORTS_END_TIME] == XML_CLIP_NULL) { $_POST[POST_INTERN_XMLCLIP_REPORTS_END_TIME] = "0_0"; } $parts = explode("_", $_POST[POST_INTERN_XMLCLIP_REPORTS_END_TIME]); if ($result = queryDB(true, "SELECT *,(SELECT MAX(`time`) FROM `" . DB_PREFIX . DATABASE_STATS_AGGS . "`) AS `maxtime`,(SELECT MAX(`mtime`) FROM `" . DB_PREFIX . DATABASE_STATS_AGGS . "` WHERE `maxtime`=`time`) AS `maxmtime` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS . "` WHERE (`time` = " . DBManager::RealEscape($parts[0]) . " AND `mtime` > " . DBManager::RealEscape($parts[1]) . ") OR (`time` > " . DBManager::RealEscape($parts[0]) . ") ORDER BY `time` ASC,`mtime` ASC LIMIT 1")) { while ($row = DBManager::FetchArray($result)) { if ($row["month"] == 0) { $report = new StatisticYear($row["year"], 0, 0); } else { if ($row["day"] == 0) { $report = new StatisticMonth($row["year"], $row["month"], 0); } else { $report = new StatisticDay($row["year"], $row["month"], $row["day"]); } } $type = -1; $update = false; $value = ""; if ($report->Type == STATISTIC_PERIOD_TYPE_DAY) { if ($_POST[POST_INTERN_PROCESS_UPDATE_REPORT_TYPE] == 1) { if ($STATS->CurrentDay->CreateVisitorList) { if (empty($row["aggregated"]) && (!@file_exists($report->GetFilename(true, true)) || $row["time"] < time() - StatisticProvider::$AutoUpdateTime)) { $report->SaveVisitorListToFile(); } if (@file_exists($report->GetFilename(true, true))) { $value = getFile($report->GetFilename(true, true)); } } $type = 1; } else { if ($_POST[POST_INTERN_PROCESS_UPDATE_REPORT_TYPE] == 0) { if ($STATS->CurrentDay->CreateReport) { if (empty($row["aggregated"]) && (!@file_exists($report->GetFilename(true, false)) || $row["time"] < time() - StatisticProvider::$AutoUpdateTime)) { $update = true; $report->SaveReportToFile(); } else { if (@file_exists($report->GetFilename(true, false))) { $value = getFile($report->GetFilename(true, false)); } } } $type = 0; } } } else { if (empty($row["aggregated"]) && (!@file_exists($report->GetFilename(true, false)) || $row["time"] < time() - StatisticProvider::$AutoUpdateTime)) { $report->SaveReportToFile(); } if (@file_exists($report->GetFilename(true, false))) { $value = getFile($report->GetFilename(true, false)); } $type = $report->Type == STATISTIC_PERIOD_TYPE_MONTH ? 2 : 3; } if ($type > -1) { $convrate = $row["sessions"] > 0 ? round(100 * $row["conversions"] / $row["sessions"], StatisticProvider::$RoundPrecision) : 0; $chats = $chatsd = 0; $qmonth = $report->Type == STATISTIC_PERIOD_TYPE_YEAR ? "" : " AND `month`='" . DBManager::RealEscape($row["month"]) . "'"; $qday = $report->Type != STATISTIC_PERIOD_TYPE_DAY ? "" : " AND `day`='" . DBManager::RealEscape($row["day"]) . "'"; if ($results = queryDB(true, "SELECT (SUM(`amount`)-SUM(`multi`)) AS `samount` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_CHATS . "` WHERE `year`='" . DBManager::RealEscape($row["year"]) . "'" . $qmonth . $qday . "")) { if (DBManager::GetRowCount($results) == 1) { $rows = DBManager::FetchArray($results); if (is_numeric($rows["samount"])) { $chats = $rows["samount"]; } } } $xml .= "<r cid=\"" . base64_encode(getId(3)) . "\" ragg=\"" . base64_encode(empty($row["aggregated"]) ? 0 : 1) . "\" rtype=\"" . base64_encode($type) . "\" convrate=\"" . base64_encode($convrate) . "\" chats=\"" . base64_encode($chats) . "\" update=\"" . base64_encode($update ? 1 : 0) . "\" visitors=\"" . base64_encode($row["sessions"]) . "\" time=\"" . base64_encode($row["time"]) . "\" mtime=\"" . base64_encode($row["mtime"]) . "\" year=\"" . base64_encode($row["year"]) . "\" month=\"" . base64_encode($row["month"]) . "\" day=\"" . base64_encode($row["day"]) . "\">" . base64_encode($value) . "</r>\r\n"; } $xml .= "<ri maxtime=\"" . base64_encode($row["maxtime"]) . "\" maxmtime=\"" . base64_encode($row["maxmtime"]) . "\" />"; } } $RESPONSE->SetStandardResponse(1, $xml); }
function CreateArchiveEntry($_internalUser, $_visitor, $custom = "", $etpl = "", $_customsInTranscript = true, $pdm = null) { global $CONFIG, $INPUTS, $GROUPS, $LZLANG; if ($this->ArchiveCreated) { return; } if ($INPUTS[111]->Active) { $custom .= strip_tags($INPUTS[111]->Caption) . " %efullname%\r\n"; } if ($INPUTS[112]->Active) { $custom .= strip_tags($INPUTS[112]->Caption) . " %eemail%\r\n"; } if (!empty($this->Company) && $INPUTS[113]->Active) { $custom .= strip_tags($INPUTS[113]->Caption) . " " . trim($this->Company) . "\r\n"; } if (!empty($this->Question) && $INPUTS[114]->Active) { $custom .= strip_tags($INPUTS[114]->Caption) . " " . trim($this->Question) . "\r\n"; } if (!empty($this->Phone) && $INPUTS[116]->Active) { $custom .= strip_tags($INPUTS[116]->Caption) . " " . trim($this->Phone) . "\r\n"; } if (!empty($this->ChatVoucherId)) { $custom .= strip_tags($LZLANG["client_voucher_id"]) . " " . trim($this->ChatVoucherId) . "\r\n"; } $customs = array(); if (is_array($this->Customs)) { foreach ($this->Customs as $cind => $value) { if ($INPUTS[$cind]->Active && $INPUTS[$cind]->Custom) { $customs[$INPUTS[$cind]->Name] = $value; if (!isset($GROUPS[$this->DesiredChatGroup]->ChatInputsHidden[$cind]) && $_customsInTranscript) { if ($INPUTS[$cind]->Type == "CheckBox") { $custom .= strip_tags($INPUTS[$cind]->Caption) . " " . (!empty($value) ? "<!--lang_client_yes-->" : "<!--lang_client_no-->") . "\r\n"; } else { if ($INPUTS[$cind]->Type == "ComboBox") { $custom .= strip_tags($INPUTS[$cind]->Caption) . " " . $INPUTS[$cind]->GetClientValue($value) . "\r\n"; } else { $custom .= strip_tags($INPUTS[$cind]->Caption) . " " . $value . "\r\n"; } } } } } } if (!empty($GROUPS[$this->DesiredChatGroup]->PredefinedMessages)) { $pdm = getPredefinedMessage($GROUPS[$this->DesiredChatGroup]->PredefinedMessages, $_visitor->Language); if (!empty($pdm->EmailChatTranscript)) { $etpl = $pdm->EmailChatTranscript; } } $etpl = str_replace("%external_ip%", getIP(), $etpl); $etpl = str_replace("%chat_id%", $this->ChatId, $etpl); $etpl = str_replace("%website_name%", $CONFIG["gl_site_name"], $etpl); $etpl = str_replace("%details%", $custom, $etpl); $etpl = str_replace("%group_description%", $GROUPS[$this->DesiredChatGroup]->GetDescription($_visitor->Language), $etpl); $etpl = str_replace(array("%group_name%", "%group_id%"), $this->DesiredChatGroup, $etpl); if ($this->InternalUser) { $etpl = str_replace("%operator_name%", $this->InternalUser->Fullname, $etpl); $etpl = str_replace("%operator_email%", $this->InternalUser->Email, $etpl); } $etpl = str_replace("%external_name%", "%efullname%", $etpl); $etpl = str_replace("%external_email%", "%eemail%", $etpl); $etpl = str_replace("%external_company%", $this->Company, $etpl); $etpl = str_replace("%external_phone%", $this->Phone, $etpl); $etpl = str_replace("%question%", $this->Question, $etpl); $subject = $pdm != null ? $pdm->SubjectChatTranscript : ""; $subject = getSubject($subject, $this->Email, $this->Fullname, $this->DesiredChatGroup, $this->ChatId, $this->Company, $this->Phone, getIP(), $this->Question, $GROUPS[$this->DesiredChatGroup]->GetDescription($_visitor->Language), $this->Customs); $internal = $_internalUser != null && $_internalUser->IsBot ? $_internalUser->SystemId : ""; $result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` WHERE `chat_id`='" . DBManager::RealEscape($this->ChatId) . "';"); if ($result && DBManager::GetRowCount($result) == 0) { if ($CONFIG["gl_adct"] == 1 || (!empty($CONFIG["gl_rm_chats_time"]) || empty($CONFIG["gl_rm_chats"]))) { queryDB(true, "INSERT INTO `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` (`time`,`endtime`,`closed`,`chat_id`,`external_id`,`fullname`,`internal_id`,`group_id`,`area_code`,`html`,`plaintext`,`transcript_text`,`email`,`company`,`iso_language`,`iso_country`,`host`,`ip`,`gzip`,`transcript_sent`,`transcript_receiver`,`question`,`customs`,`subject`,`voucher_id`) VALUES ('" . DBManager::RealEscape($this->FirstActive) . "',0,0,'" . DBManager::RealEscape($this->ChatId) . "','" . DBManager::RealEscape($this->UserId) . "','','" . DBManager::RealEscape($internal) . "','','" . DBManager::RealEscape($this->Code) . "','','','" . DBManager::RealEscape($etpl) . "','','','" . DBManager::RealEscape($_visitor->Language) . "','" . DBManager::RealEscape($_visitor->GeoCountryISO2) . "','" . DBManager::RealEscape($_visitor->Host) . "','" . DBManager::RealEscape($_visitor->IP) . "',0,0,'" . DBManager::RealEscape($this->Email) . "','','" . DBManager::RealEscape(@serialize($customs)) . "','" . DBManager::RealEscape($subject) . "','" . DBManager::RealEscape($this->ChatVoucherId) . "');"); } $this->ArchiveCreated = true; ChatRequest::AcceptAll($this->UserId); } }
function demandReports() { if (!STATS_ACTIVE || !isset($_POST["p_dr_p"]) || Server::$Operators[CALLER_SYSTEM_ID]->GetPermission(PERMISSION_REPORTS) == PERMISSION_NONE) { return; } if (!CacheManager::IsDataUpdate(POST_INTERN_DUT_REPORTS, DATA_UPDATE_KEY_REPORTS)) { return; } $limit = !empty($_POST["p_dr_p"]) && is_numeric($_POST["p_dr_p"]) && $_POST["p_dr_p"] > 1 ? ($_POST["p_dr_p"] - 1) * DATA_DEMAND_LOADS : 0; $type = !empty($_POST["p_dr_t"]) && in_array($_POST["p_dr_t"], array(STATISTIC_PERIOD_TYPE_DAY, STATISTIC_PERIOD_TYPE_MONTH, STATISTIC_PERIOD_TYPE_YEAR)) ? $_POST["p_dr_t"] : STATISTIC_PERIOD_TYPE_DAY; $xml = ""; if ($type == STATISTIC_PERIOD_TYPE_DAY) { $type = "`day` > 0"; } else { if ($type == STATISTIC_PERIOD_TYPE_MONTH) { $type = "`month` > 0 AND `day`=0"; } else { if ($type == STATISTIC_PERIOD_TYPE_YEAR) { $type = "`year` > 0 AND `day`=0 AND `month`=0"; } } } $result = DBManager::Execute(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_STATS_AGGS . "` WHERE " . $type . " ORDER BY `time` DESC,`mtime` DESC LIMIT " . $limit . "," . DBManager::RealEscape(DATA_DEMAND_LOADS) . ";"); if ($result) { while ($row = DBManager::FetchArray($result)) { if ($row["month"] == 0 && $row["day"] == 0) { $report = new StatisticYear($row["year"], 0, 0, $row["aggregated"], $row["mtime"]); } else { if ($row["day"] == 0) { $report = new StatisticMonth($row["year"], $row["month"], 0, $row["aggregated"], $row["mtime"]); } else { $report = new StatisticDay($row["year"], $row["month"], $row["day"], $row["aggregated"], $row["mtime"]); } } $chats = 0; $qmonth = $report->Type == STATISTIC_PERIOD_TYPE_YEAR ? "" : " AND `month`='" . DBManager::RealEscape($row["month"]) . "'"; $qday = $report->Type != STATISTIC_PERIOD_TYPE_DAY ? "" : " AND `day`='" . DBManager::RealEscape($row["day"]) . "'"; if ($results = DBManager::Execute(true, "SELECT (SUM(`amount`)-SUM(`multi`)) AS `samount` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_CHATS . "` WHERE `year`='" . DBManager::RealEscape($row["year"]) . "'" . $qmonth . $qday . "")) { if (DBManager::GetRowCount($results) == 1) { $rows = DBManager::FetchArray($results); if (is_numeric($rows["samount"])) { $chats = $rows["samount"]; } } } $convrate = $row["sessions"] > 0 ? round(100 * $row["conversions"] / $row["sessions"], StatisticProvider::$RoundPrecision) : 0; $xml .= "<r i=\"" . base64_encode($report->GetHash()) . "\" a=\"" . base64_encode($row["aggregated"]) . "\" ch=\"" . base64_encode($chats) . "\" c=\"" . base64_encode($convrate) . "\" r=\"" . base64_encode($report->Type) . "\" s=\"" . base64_encode($row["sessions"]) . "\" v=\"" . base64_encode($row["visitors_unique"]) . "\" t=\"" . base64_encode($row["time"]) . "\" mt=\"" . base64_encode($row["mtime"]) . "\" y=\"" . base64_encode($row["year"]) . "\" m=\"" . base64_encode($row["month"]) . "\" d=\"" . base64_encode($row["day"]) . "\"></r>\r\n"; } } $result = DBManager::Execute(true, "SELECT count(`time`) AS `total` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS . "`;"); $trow = DBManager::FetchArray($result); $result = DBManager::Execute(true, "SELECT count(`time`) AS `ttotal` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS . "` WHERE " . $type . ";"); $ttrow = DBManager::FetchArray($result); Server::$Response->Reports = "<dr dut=\"" . base64_encode(CacheManager::$DataUpdateTimes[DATA_UPDATE_KEY_REPORTS]) . "\" p=\"" . base64_encode(DATA_ITEM_LOADS) . "\" t=\"" . base64_encode($trow["total"]) . "\" q=\"" . base64_encode($ttrow["ttotal"]) . "\">\r\n" . $xml . "\r\n</dr>"; }
function listen($_user, $init = false) { global $CONFIG, $GROUPS, $INTERNAL, $USER, $INTLIST, $INTBUSY, $VOUCHER, $DEFAULT_BROWSER_LANGUAGE; $USER = $_user; if (!IS_FILTERED) { if (!empty($_POST["p_tid"])) { $VOUCHER = VisitorChat::GetMatchingVoucher(base64UrlDecode($_POST[POST_EXTERN_USER_GROUP]), base64UrlDecode($_POST["p_tid"])); if ($VOUCHER != null) { $USER->Browsers[0]->ChatVoucherId = $VOUCHER->Id; } } if (empty($USER->Browsers[0]->ChatId)) { $result = queryDB(true, "SELECT `visit_id` FROM `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "` WHERE `visitor_id`='" . DBManager::RealEscape($USER->Browsers[0]->UserId) . "' AND `id`='" . DBManager::RealEscape($USER->Browsers[0]->BrowserId) . "' LIMIT 1;"); if ($result && ($row = DBManager::FetchArray($result)) && $row["visit_id"] != $USER->Browsers[0]->VisitId && !empty($USER->Browsers[0]->VisitId)) { $USER->Browsers[0]->CloseChat(2); $USER->AddFunctionCall("lz_chat_set_status(lz_chat_data.STATUS_STOPPED);", false); $USER->AddFunctionCall("lz_chat_add_system_text(99,'" . base64_encode("Your browser session has expired (" . $row["visit_id"] . "-" . $USER->Browsers[0]->VisitId . "). Please close this browser instance and try again.") . "');", false); $USER->AddFunctionCall("lz_chat_stop_system();", false); return $USER; } $USER->Browsers[0]->SetChatId(); $init = true; } if ($USER->Browsers[0]->Status == CHAT_STATUS_OPEN) { initData(array("INTERNAL")); if (!empty($_POST[POST_EXTERN_USER_GROUP]) && (empty($USER->Browsers[0]->DesiredChatGroup) || $init)) { $USER->Browsers[0]->DesiredChatGroup = base64UrlDecode($_POST[POST_EXTERN_USER_GROUP]); } $USER->Browsers[0]->SetCookieGroup(); if (!setOperator() && $INTBUSY == 0) { $USER->AddFunctionCall("lz_chat_add_system_text(8,null);", false); $USER->AddFunctionCall("lz_chat_stop_system();", false); } else { if (count($INTLIST) + $INTBUSY > 0) { $USER->AddFunctionCall("lz_chat_set_id('" . $USER->Browsers[0]->ChatId . "');", false); $chatPosition = getQueuePosition($USER->UserId, $USER->Browsers[0]->DesiredChatGroup); $chatWaitingTime = getQueueWaitingTime($chatPosition, $INTBUSY); login(); $USER->Browsers[0]->SetWaiting(!($chatPosition == 1 && count($INTLIST) > 0 && !(!empty($USER->Browsers[0]->DesiredChatPartner) && $INTERNAL[$USER->Browsers[0]->DesiredChatPartner]->Status == USER_STATUS_BUSY))); if (!$USER->Browsers[0]->Waiting) { $USER->AddFunctionCall("lz_chat_show_connected();", false); $USER->AddFunctionCall("lz_chat_set_status(lz_chat_data.STATUS_ALLOCATED);", false); if ($CONFIG["gl_alloc_mode"] != ALLOCATION_MODE_ALL || !empty($USER->Browsers[0]->DesiredChatPartner)) { $USER->Browsers[0]->CreateChat($INTERNAL[$USER->Browsers[0]->DesiredChatPartner], $USER, true); } else { $run = 0; foreach ($INTLIST as $intid => $am) { $USER->Browsers[0]->CreateChat($INTERNAL[$intid], $USER, false, "", "", true, $run++ == 0); } } } else { if (!empty($_GET["acid"])) { $USER->AddFunctionCall("lz_chat_show_connected();", false); $pchatid = base64UrlDecode($_GET["acid"]); $result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` WHERE `visitor_id`='" . DBManager::RealEscape($USER->Browsers[0]->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"])) { $posts = unserialize($row["queue_posts"]); foreach ($posts as $post) { $USER->AddFunctionCall("lz_chat_repost_from_queue('" . $post[0] . "');", false); } $USER->AddFunctionCall("lz_chat_data.QueuePostsAdded = true;", false); } } } if ($USER->Browsers[0]->IsMaxWaitingTime(true)) { displayDeclined(); return $USER; } $pdm = getPredefinedMessage($GROUPS[$USER->Browsers[0]->DesiredChatGroup]->PredefinedMessages, $USER != null ? $USER->Language : ""); if ($pdm != null && !empty($pdm->QueueMessage) && time() - $USER->Browsers[0]->FirstActive > $pdm->QueueMessageTime && !$USER->Browsers[0]->QueueMessageShown) { $USER->Browsers[0]->QueueMessageShown = true; if (empty($_GET["acid"])) { $USER->AddFunctionCall("lz_chat_add_system_text(99,'" . base64_encode($pdm->QueueMessage) . "');", false); } } if (empty($_GET["acid"])) { $USER->AddFunctionCall("lz_chat_show_queue_position(" . $chatPosition . "," . min($chatWaitingTime, 30) . ");", false); } $USER->Browsers[0]->CreateArchiveEntry(null, $USER); } } } } else { $action = $USER->Browsers[0]->GetMaxWaitingTimeAction(false); if ($action == "MESSAGE" || $action == "FORWARD" && !$USER->Browsers[0]->CreateAutoForward()) { $USER->Browsers[0]->InternalDecline($USER->Browsers[0]->InternalUser->SystemId); displayDeclined(); } else { if (!$USER->Browsers[0]->ArchiveCreated && !empty($USER->Browsers[0]->DesiredChatPartner)) { $USER->Browsers[0]->CreateChat($INTERNAL[$USER->Browsers[0]->DesiredChatPartner], $USER, true); } activeListen(); } } if ($USER->Browsers[0]->Status <= CHAT_STATUS_WAITING && empty($_POST["p_wls"])) { $USER->AddFunctionCall("lz_chat_show_waiting_links('" . base64_encode($wl = $GROUPS[$USER->Browsers[0]->DesiredChatGroup]->GetWaitingLinks($USER->Browsers[0]->Question, $DEFAULT_BROWSER_LANGUAGE)) . "');", false); } } else { displayFiltered(); } return $USER; }
function GetUniqueMessageTime($_database, $_column) { $time = time(); while (true) { $result = queryDB(true, "SELECT `" . $_column . "` FROM `" . DB_PREFIX . $_database . "` WHERE `" . $_column . "`=" . DBManager::RealEscape($time) . ";"); if (DBManager::GetRowCount($result) > 0) { $time++; } else { break; } } return $time; }
static function ValidateDatabase($_host, $_user, $_pass, $_dbname, $_prefix, $_extension = "", $_intense = false, $_engine) { $connection = new DBManager($_user, $_pass, $_host, "", $_prefix); $_engine = empty($_engine) ? "MyISAM" : $_engine; if (!empty($_extension)) { DBManager::$Extension = $_extension; } if (DBManager::$Extension == "mysql" && !function_exists("mysql_connect")) { return "PHP MySQL extension is missing (php_mysql.dll)"; } else { if (DBManager::$Extension == "mysqli" && !function_exists("mysqli_connect")) { return "PHP/MySQLi extension is missing (php_mysqli.dll)"; } } $connection->InitConnection(); if (!DBManager::$Provider) { $error = DBManager::GetError(); return "Can't connect to database. Invalid host or login! (" . DBManager::GetErrorCode() . (!empty($error) ? ": " . $error : "") . ")"; } else { $db_selected = $connection->SelectDatabase(DBManager::RealEscape($_dbname)); if (!$db_selected) { return DBManager::GetErrorCode() . ": " . DBManager::GetError(); } else { $resultv = $connection->Query(false, "SELECT VERSION() as `mysql_version`"); if (!$resultv) { return DBManager::GetErrorCode() . ": " . DBManager::GetError(); } else { $mrow = @DBManager::FetchArray($resultv); $mversion = explode(".", $mrow["mysql_version"]); if (count($mversion) > 0 && $mversion[0] < MYSQL_NEEDED_MAJOR) { return "LiveZilla requires MySQL version " . MYSQL_NEEDED_MAJOR . " or greater. The MySQL version installed on your server is " . $mrow["mysql_version"] . "."; } } $result = $connection->Query(false, "SELECT `version`,`chat_id`,`ticket_id` FROM `" . DBManager::RealEscape($_prefix) . DATABASE_INFO . "` ORDER BY `version` DESC LIMIT 1"); $row = @DBManager::FetchArray($result); $version = $row["version"]; if (!$result || empty($version)) { return "Cannot read the LiveZilla Database version. Please try to recreate the table structure. If you experience this message during installation process, please try to setup a prefix (for example lz_)."; } if ($version != VERSION && defined("SERVERSETUP") && SERVERSETUP) { $upres = ServerManager::InitUpdateDatabase($version, $connection, $_prefix, $_engine); if ($upres !== true) { return "Cannot update database structure from [" . $version . "] to [" . VERSION . "]. Please make sure that the user " . $_user . " has the MySQL permission to ALTER tables in " . $_dbname . ".\r\n\r\nError: " . $upres; } } else { if ($version != VERSION && empty($_GET["iv"])) { return "Invalid database version: " . $version . " (required: " . VERSION . "). Please validate the database in the server administration panel first.\r\n\r\n"; } } DBManager::$Connector = $connection; $result = $connection->Query(false, "SELECT * FROM `" . DBManager::RealEscape($_prefix) . DATABASE_OPERATORS . "`"); if (DBManager::GetRowCount($result) == 0) { ServerManager::UpdateUserManagement($_prefix, false, true); } if ($_intense && empty($_GET["iv"])) { foreach (get_defined_constants() as $constant => $val) { if (substr($constant, 0, 9) == "DATABASE_") { if (!$connection->Query(false, "SELECT * FROM `" . DBManager::RealEscape($_prefix) . $val . "` LIMIT 1;")) { $code = DBManager::GetErrorCode(); $error = DBManager::GetError(); if ($code == 144 || $code == 145 || $code == 1194) { $connection->Query(true, "REPAIR TABLE `" . DBManager::RealEscape($_prefix) . $val . "`;"); $error .= " - (trying to repair ...)"; } return $code . ": " . $error; } } } } return null; } } }
static function SetDataUpdateTime($_areaIndex, $_reload = false) { global $DUTU; $mt = round(microtime(true) * 1000); if (!(isset($DUTU[$_areaIndex]) && $DUTU[$_areaIndex] == $mt)) { $DUTU[$_areaIndex] = $mt; $result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_DATA_UPDATES . "`;"); if (DBManager::GetRowCount($result) == 0 && !$_reload) { queryDB(true, "TRUNCATE `" . DB_PREFIX . DATABASE_DATA_UPDATES . "`;"); queryDB(true, "INSERT INTO `" . DB_PREFIX . DATABASE_DATA_UPDATES . "` (`update_tickets`, `update_archive`, `update_ratings`, `update_emails`, `update_events`, `update_vouchers`, `update_filters`) VALUES ('0', '0', '0', '0', '0', '0', '0');"); CacheManager::SetDataUpdateTime($_areaIndex, true); } else { queryDB(true, "UPDATE `" . DB_PREFIX . DATABASE_DATA_UPDATES . "` SET `" . $_areaIndex . "`=" . $mt . ";"); } } }
$USER->Browsers[1]->ForceUpdate(); } } } $tymes = !empty($USER->Browsers[0]->InternalUser) && $USER->Browsers[0]->InternalUser->Typing == $USER->Browsers[0]->SystemId ? "'" . base64_encode(str_replace("<!--operator_name-->", $USER->Browsers[0]->InternalUser->Fullname, $LZLANG["client_representative_is_typing"])) . "'" : "null"; $USER->AddFunctionCall("lz_chat_set_typing(" . $tymes . ",false);", false); $maxposts = 30; $spkthtml = speakingToHTML(); $posthtml = ""; $pstrchngreq = $psound = $spkt = false; $oppostcount = 0; $LASTPOST = ""; $lppflag = $LASTPOSTER; $rand = rand(); if (!$USER->Browsers[0]->Declined && ($result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_POSTS . "` WHERE `chat_id`='" . DBManager::RealEscape($USER->Browsers[0]->ChatId) . "' AND `chat_id`!='' AND `chat_id`!='0' AND (`receiver`='" . DBManager::RealEscape($USER->Browsers[0]->SystemId) . "' OR (`sender`='" . DBManager::RealEscape($USER->Browsers[0]->SystemId) . "' AND `repost`=0)) GROUP BY `id` ORDER BY `time` ASC, `micro` ASC;"))) { $all = DBManager::GetRowCount($result); $toshow = min($maxposts, $all); if ($all > 0) { $count = $maxposts - $all; while ($row = DBManager::FetchArray($result)) { if ($count++ >= 0) { $postobj = new Post($row); if (empty($INTERNAL[$postobj->Sender])) { $postobj->Text = htmlentities($postobj->Text, ENT_QUOTES, 'UTF-8'); $postobj->Translation = htmlentities($postobj->Translation, ENT_QUOTES, 'UTF-8'); } if ($USER->Browsers[0]->AllocatedTime > 0 && $USER->Browsers[0]->AllocatedTime && !$spkt) { $lppflag = "sys"; $posthtml .= $spkthtml; $spkt = true; }
static function Exists($_hash, &$id, &$group, &$language) { $_hash = strtoupper(str_replace(array("[", "]"), "", $_hash)); $result = queryDB(true, "SELECT `dbt`.`id`,`dbt`.`target_group_id`,`dbt`.`iso_language` FROM `" . DB_PREFIX . DATABASE_TICKETS . "` AS `dbt` INNER JOIN `" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "` AS `dbm` ON `dbt`.`id`=`dbm`.`ticket_id` WHERE (`dbt`.`hash`='" . DBManager::RealEscape($_hash) . "' OR `dbm`.`hash`='" . DBManager::RealEscape($_hash) . "') AND `deleted`=0 LIMIT 1;"); if ($result && ($row = DBManager::FetchArray($result))) { $id = $row["id"]; $group = $row["target_group_id"]; $language = $row["iso_language"]; } return DBManager::GetRowCount($result) == 1; }
function CreateArchiveEntry($_internalUser, $_visitor, $custom = "", $etpl = "", $_customsInTranscript = true, $pdm = null) { if (!empty($this->ArchiveCreated)) { return; } if (Server::$Inputs[111]->Active) { $custom .= strip_tags(Server::$Inputs[111]->Caption) . " %efullname%\r\n"; } if (Server::$Inputs[112]->Active) { $custom .= strip_tags(Server::$Inputs[112]->Caption) . " %eemail%\r\n"; } if (!empty($this->Company) && Server::$Inputs[113]->Active) { $custom .= strip_tags(Server::$Inputs[113]->Caption) . " " . trim($this->UserData->Company) . "\r\n"; } if (!empty($this->Question) && Server::$Inputs[114]->Active) { $custom .= strip_tags(Server::$Inputs[114]->Caption) . " " . trim($this->UserData->Text) . "\r\n"; } if (!empty($this->Phone) && Server::$Inputs[116]->Active) { $custom .= strip_tags(Server::$Inputs[116]->Caption) . " " . trim($this->UserData->Phone) . "\r\n"; } if (!empty($this->ChatVoucherId)) { $custom .= strip_tags(LocalizationManager::$TranslationStrings["client_voucher_id"]) . " " . trim($this->ChatVoucherId) . "\r\n"; } $customs = array(); if (is_array($this->UserData->Customs)) { foreach ($this->UserData->Customs as $cind => $value) { if (Server::$Inputs[$cind]->Active && Server::$Inputs[$cind]->Custom) { $customs[Server::$Inputs[$cind]->Name] = $value; if (!isset(Server::$Groups[$this->DesiredChatGroup]->ChatInputsHidden[$cind]) && $_customsInTranscript) { if (Server::$Inputs[$cind]->Type == "CheckBox") { $custom .= strip_tags(Server::$Inputs[$cind]->Caption) . " " . (!empty($value) ? "<!--lang_client_yes-->" : "<!--lang_client_no-->") . "\r\n"; } else { if (Server::$Inputs[$cind]->Type == "ComboBox") { $custom .= strip_tags(Server::$Inputs[$cind]->Caption) . " " . Server::$Inputs[$cind]->GetClientValue($value) . "\r\n"; } else { $custom .= strip_tags(Server::$Inputs[$cind]->Caption) . " " . $value . "\r\n"; } } } } } } $tsData = array("", ""); if (!empty(Server::$Groups[$this->DesiredChatGroup]->PredefinedMessages)) { $pdm = PredefinedMessage::GetByLanguage(Server::$Groups[$this->DesiredChatGroup]->PredefinedMessages, $_visitor->Language); if (!empty($pdm->EmailChatTranscriptBodyPlaintext)) { $tsData[0] = $pdm->EmailChatTranscriptBodyPlaintext; } if (!empty($pdm->EmailChatTranscriptBodyHTML)) { $tsData[1] = $pdm->EmailChatTranscriptBodyHTML; } } for ($i = 0; $i < count($tsData); $i++) { $tsData[$i] = str_replace("%chat_id%", $this->ChatId, $tsData[$i]); $tsData[$i] = str_replace("%details%", $custom, $tsData[$i]); $tsData[$i] = str_replace("%external_name%", "%efullname%", $tsData[$i]); $tsData[$i] = str_replace("%external_email%", "%eemail%", $tsData[$i]); $tsData[$i] = str_replace("%external_company%", $this->UserData->Company, $tsData[$i]); $tsData[$i] = str_replace("%external_phone%", $this->UserData->Phone, $tsData[$i]); $tsData[$i] = str_replace("%question%", $this->UserData->Text, $tsData[$i]); $tsData[$i] = str_replace("%feedback_link%", Feedback::GetLink("cid=" . Encoding::Base64UrlEncode($this->ChatId)), $tsData[$i]); $tsData[$i] = Server::$Groups[$this->DesiredChatGroup]->TextReplace($tsData[$i], $_visitor->Language); if (!empty($this->OperatorId)) { $tsData[$i] = Server::$Operators[$this->OperatorId]->TextReplace($tsData[$i]); } $tsData[$i] = $_visitor->TextReplace($tsData[$i]); $tsData[$i] = Configuration::Replace($tsData[$i]); } $subject = $pdm != null ? $pdm->SubjectChatTranscript : ""; $subject = Mailbox::GetSubject($subject, $this->UserData->Email, $this->UserData->Fullname, $this->DesiredChatGroup, $this->ChatId, $this->UserData->Company, $this->UserData->Phone, Communication::GetIP(), $this->UserData->Text, Server::$Groups[$this->DesiredChatGroup]->GetDescription($_visitor->Language), $this->UserData->Customs); $internal = $_internalUser != null && $_internalUser->IsBot ? $_internalUser->SystemId : ""; $result = DBManager::Execute(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` WHERE `chat_id`='" . DBManager::RealEscape($this->ChatId) . "';"); if ($result && DBManager::GetRowCount($result) == 0) { if (Server::$Configuration->File["gl_adct"] == 1 || (!empty(Server::$Configuration->File["gl_rm_chats_time"]) || empty(Server::$Configuration->File["gl_rm_chats"]))) { $url = Visitor::GetLastURLFromVisitor($this->UserId); DBManager::Execute(true, "INSERT INTO `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` (`time`,`endtime`,`closed`,`chat_id`,`external_id`,`fullname`,`internal_id`,`group_id`,`area_code`,`html`,`plaintext`,`transcript_text`,`transcript_html`,`email`,`company`,`iso_language`,`iso_country`,`host`,`ip`,`gzip`,`transcript_sent`,`transcript_receiver`,`question`,`customs`,`subject`,`voucher_id`,`ref_url`) VALUES ('" . DBManager::RealEscape($this->FirstActive) . "',0,0,'" . DBManager::RealEscape($this->ChatId) . "','" . DBManager::RealEscape($this->UserId) . "','','" . DBManager::RealEscape($internal) . "','','" . DBManager::RealEscape($this->Code) . "','','','" . DBManager::RealEscape($tsData[0]) . "','" . DBManager::RealEscape($tsData[1]) . "','','','" . DBManager::RealEscape($_visitor->Language) . "','" . DBManager::RealEscape($_visitor->GeoCountryISO2) . "','" . DBManager::RealEscape($_visitor->Host) . "','" . DBManager::RealEscape($_visitor->IP) . "',0,0,'" . DBManager::RealEscape($this->UserData->Email) . "','','" . DBManager::RealEscape(@serialize($customs)) . "','" . DBManager::RealEscape($subject) . "','" . DBManager::RealEscape($this->ChatVoucherId) . "','" . DBManager::RealEscape($url) . "');"); } $this->ArchiveCreated = 1; ChatRequest::AcceptAll($this->UserId); } }