function CreateChatTemplate()
 {
     $this->ChatHTML = "";
     if (Visitor::$PollCount == 1) {
         $this->ChatHTML = str_replace("<!--server-->", LIVEZILLA_URL, IOStruct::GetFile(TEMPLATE_HTML_OVERLAY_CHAT));
         $this->ChatHTML = str_replace("<!--file_upload_template-->", IOStruct::GetFile(PATH_TEMPLATES . "file_upload.tpl"), $this->ChatHTML);
         $this->ChatHTML = str_replace("<!--dir-->", LocalizationManager::$Direction, $this->ChatHTML);
         $this->ChatHTML = getChatLoginInputs($this->ChatHTML, MAX_INPUT_LENGTH_OVERLAY, true);
         $this->ChatHTML = str_replace("<!--tr_vis-->", strlen(Server::$Configuration->File["gl_otrs"]) > 1 ? "block" : "none", $this->ChatHTML);
         $this->ChatHTML = str_replace("<!--overlay_input_max_length-->", MAX_INPUT_LENGTH_OVERLAY, $this->ChatHTML);
         $this->ChatHTML = Server::Replace($this->ChatHTML, true, false);
         $this->ChatHTML = OverlayChat::ReplaceColors($this->ChatHTML, false);
         $this->ChatHTML = str_replace("<!--tc-->", Communication::ReadParameter("ovlct", "#ffffff"), $this->ChatHTML);
         $this->ChatHTML = str_replace("<!--apo-->", !empty($_GET["ovlapo"]) ? "" : "display:none;", $this->ChatHTML);
         $this->ChatHTML = str_replace("<!--et_vis-->", !empty(Server::$Configuration->File["gl_retr"]) && !empty(Server::$Configuration->File["gl_soct"]) ? "block" : "none", $this->ChatHTML);
         $this->ChatHTML = str_replace("<!--activate_transcript-->", empty(Server::$Configuration->File["gl_soct"]) ? "" : "CHECKED", $this->ChatHTML);
         $this->ChatHTML = str_replace("<!--param-->", @Server::$Configuration->File["gl_cpas"], $this->ChatHTML);
         $tlanguages = getLanguageSelects(LocalizationManager::GetBrowserLocalization());
         $this->ChatHTML = str_replace("<!--languages-->", $tlanguages, $this->ChatHTML);
     }
 }
            } else {
                if (Communication::GetIP() == $visitor->IP) {
                    if (!empty($_POST["p_fu_a"])) {
                        exit(AbortFileUpload($chat, $_POST[POST_EXTERN_USER_FILE_UPLOAD_NAME]));
                    }
                    if (!empty($_POST["p_iu"])) {
                        exit(RequestFileUpload($visitor, $chat, $_POST[POST_EXTERN_USER_FILE_UPLOAD_NAME]));
                    } else {
                        $html = IOStruct::GetFile(PATH_TEMPLATES . "upload.tpl");
                        $html = str_replace("<!--upload-->", IOStruct::GetFile(PATH_TEMPLATES . "file_upload.tpl"), $html);
                        $html = str_replace("<!--action-->", "lz_chat_file_init_upload();", $html);
                        $html = str_replace("<!--connector_script-->", IOStruct::GetFile(TEMPLATE_SCRIPT_CONNECTOR), $html);
                        $html = str_replace("<!--cid-->", Encoding::Base64UrlEncode($chat->ChatId), $html);
                        $html = str_replace("<!--mwidth-->", "max-width:90%;", $html);
                        $html = str_replace("<!--chat_id-->", Encoding::Base64UrlEncode($chat->ChatId), $html);
                        exit(Server::Replace($html));
                    }
                }
            }
        }
    }
}
function StoreFile($_visitor, $_browserId, $_partner, $_fullname, $_chatId)
{
    $filename = IOStruct::GetNamebase($_FILES['form_userfile']['name']);
    Logging::GeneralLog($filename);
    if (!IOStruct::IsValidUploadFile($filename)) {
        return false;
    }
    if (empty($_fullname)) {
        $_fullname = Visitor::GetNoName($_visitor->UserId . Communication::GetIP());
 function DataInput($_values)
 {
     $this->Id = getId(15);
     if ($_values != null) {
         $_values = @unserialize(base64_decode($_values));
         array_walk($_values, "b64dcode");
         $this->Index = $_values[0];
         $this->Caption = strpos($_values[1], "<!--lang") !== false ? Server::Replace($_values[1], true, false) : $_values[1];
         $this->Name = $_values[2];
         $this->Type = $_values[3];
         $this->Active = empty($_GET["ofc"]) || $this->Index != 116 ? !empty($_values[4]) : true;
         $this->Cookie = !empty($_values[5]);
         $this->Position = $_values[6];
         $this->InputValue = strpos($_values[7], "<!--lang") !== false ? Server::Replace($_values[7], true, false) : $_values[7];
         $this->Custom = $this->Index < 100;
         $this->Validate = !empty($_values[8]);
         $this->ValidationURL = $_values[9];
         $this->ValidationTimeout = $_values[10];
         $this->ValidationContinueOnTimeout = !empty($_values[11]);
         if (count($_values) > 12) {
             $this->InfoText = $_values[12];
         }
     } else {
         $this->Index = 115;
         $this->Caption = @LocalizationManager::$TranslationStrings["client_voucher_id"];
         $this->Name = "chat_voucher_id";
         $this->Custom = false;
         $this->Position = 10000;
         $this->Cookie = false;
         $this->Active = true;
         $this->Validate = false;
         $this->Type = "Text";
     }
 }
/****************************************************************************************
 * LiveZilla report.php
 *
 * Copyright 2014 LiveZilla GmbH
 * All rights reserved.
 * LiveZilla is a registered trademark.
 *
 * Improper changes to this file may cause critical errors.
 ***************************************************************************************/
define("IN_LIVEZILLA", true);
header('Content-Type: text/html; charset=utf-8');
if (!defined("LIVEZILLA_PATH")) {
    define("LIVEZILLA_PATH", "./");
}
require LIVEZILLA_PATH . "_definitions/definitions.inc.php";
require LIVEZILLA_PATH . "_lib/functions.global.inc.php";
require LIVEZILLA_PATH . "_definitions/definitions.dynamic.inc.php";
require LIVEZILLA_PATH . "_definitions/definitions.protocol.inc.php";
@set_error_handler("handleError");
if (!empty($_GET["h"]) && !empty($_GET["y"]) && isset($_GET["m"]) && isset($_GET["d"]) && Server::InitDataProvider()) {
    Server::DefineURL("report.php");
    Server::InitStatisticProvider();
    $repData = StatisticProvider::GetReportFromHash($_GET["h"], $_GET["y"], $_GET["m"], $_GET["d"], !empty($_GET["u"]));
    if ($repData !== false) {
        LocalizationManager::AutoLoad(strtolower(Server::$Configuration->File["gl_default_language"]), true);
        $repData = Server::Replace($repData, true, false, false, true);
        exit($repData);
    }
}
exit("Sorry, report was not found.");
function buildReports($xml = "")
{
    if (empty($_POST[POST_INTERN_XMLCLIP_REPORTS_END_TIME])) {
        return;
    }
    if (empty(Server::$Statistic->CurrentDay) || Server::$Operators[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 = DBManager::Execute(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, $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"]);
                }
            }
            $type = -1;
            $update = false;
            $value = "";
            if ($report->Type == STATISTIC_PERIOD_TYPE_DAY) {
                if ($_POST[POST_INTERN_PROCESS_UPDATE_REPORT_TYPE] == 1) {
                    if (Server::$Statistic->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 = IOStruct::GetFile($report->GetFilename(true, true));
                        }
                    }
                    $type = 1;
                } else {
                    if ($_POST[POST_INTERN_PROCESS_UPDATE_REPORT_TYPE] == 0) {
                        if (Server::$Statistic->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 = IOStruct::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 = IOStruct::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 = 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"];
                        }
                    }
                }
                LocalizationManager::AutoLoad("", true);
                $value = Server::Replace($value, true, false, false, true);
                $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"]) . "\" />";
        }
    }
    Server::$Response->SetStandardResponse(1, $xml);
}
function processActions($actionData = "", $_chatsExternal)
{
    global $OVERLAY;
    if (!empty(VisitorMonitoring::$Browser->ChatRequest)) {
        Server::InitDataBlock(array("INTERNAL", "GROUPS"));
        if (Server::$Operators[VisitorMonitoring::$Browser->ChatRequest->SenderSystemId]->LastActive < time() - Server::$Configuration->File["timeout_clients"] || Server::$Operators[VisitorMonitoring::$Browser->ChatRequest->SenderSystemId]->Status != USER_STATUS_ONLINE || !Server::$Operators[VisitorMonitoring::$Browser->ChatRequest->SenderSystemId]->IsExternal(Server::$Groups, null, null) || VisitorMonitoring::$Browser->ChatRequest->Closed || !empty(VisitorMonitoring::$Browser->ChatRequest->Canceled)) {
            if (!VisitorMonitoring::$Browser->ChatRequest->Closed) {
                VisitorMonitoring::$Browser->ChatRequest->SetStatus(false, false, empty(VisitorMonitoring::$Browser->ChatRequest->Canceled), true);
                VisitorMonitoring::$Browser->ForceUpdate();
            }
            $actionData .= "top.lz_tracking_close_request('" . VisitorMonitoring::$Browser->ChatRequest->Id . "');";
        } else {
            if (isset($_GET["decreq"]) || isset($_GET["accreq"])) {
                if (isset($_GET["decreq"])) {
                    VisitorMonitoring::$Browser->ChatRequest->SetStatus(false, false, true, true);
                }
                if (isset($_GET["accreq"])) {
                    VisitorMonitoring::$Browser->ChatRequest->SetStatus(false, true, false, true);
                }
                if (isset($_GET["clreq"])) {
                    $actionData .= "top.lz_tracking_close_request();";
                }
                if (!VisitorMonitoring::$Browser->ChatRequest->Closed) {
                    VisitorMonitoring::$Browser->ForceUpdate();
                }
            } else {
                if (!VisitorMonitoring::$Browser->ChatRequest->Accepted && !VisitorMonitoring::$Browser->ChatRequest->Declined) {
                    if (!empty($_GET["ovlc"]) && !$_chatsExternal) {
                    } else {
                        if (empty(VisitorMonitoring::$Browser->ChatRequest->EventActionId)) {
                            $invitationSettings = @unserialize(base64_decode(Server::$Configuration->File["gl_invi"]));
                            array_walk($invitationSettings, "b64dcode");
                            $invitationHTML = Server::Replace(VisitorMonitoring::$Browser->ChatRequest->CreateInvitationTemplate($invitationSettings[13], Server::$Configuration->File["gl_site_name"], Server::$Configuration->File["wcl_window_width"], Server::$Configuration->File["wcl_window_height"], LIVEZILLA_URL, Server::$Operators[VisitorMonitoring::$Browser->ChatRequest->SenderSystemId], $invitationSettings[0]));
                            VisitorMonitoring::$Browser->ChatRequest->Invitation = new Invitation($invitationHTML, VisitorMonitoring::$Browser->ChatRequest->Text, $invitationSettings);
                        } else {
                            if (!Is::Null($action = Server::$Events->GetActionById(VisitorMonitoring::$Browser->ChatRequest->EventActionId))) {
                                $invitationHTML = Server::Replace(VisitorMonitoring::$Browser->ChatRequest->CreateInvitationTemplate($action->Invitation->Style, Server::$Configuration->File["gl_site_name"], Server::$Configuration->File["wcl_window_width"], Server::$Configuration->File["wcl_window_height"], LIVEZILLA_URL, Server::$Operators[VisitorMonitoring::$Browser->ChatRequest->SenderSystemId], $action->Invitation->CloseOnClick));
                                VisitorMonitoring::$Browser->ChatRequest->Invitation = $action->Invitation;
                                VisitorMonitoring::$Browser->ChatRequest->Invitation->Text = VisitorMonitoring::$Browser->ChatRequest->Text;
                                VisitorMonitoring::$Browser->ChatRequest->Invitation->HTML = $invitationHTML;
                            }
                        }
                    }
                    if (!VisitorMonitoring::$Browser->ChatRequest->Displayed) {
                        VisitorMonitoring::$Browser->ForceUpdate();
                        VisitorMonitoring::$Browser->ChatRequest->SetStatus(true, false, false, false);
                    }
                    if (!empty(VisitorMonitoring::$Browser->ChatRequest->Invitation) && (!VisitorMonitoring::$Browser->OverlayContainer || $_chatsExternal)) {
                        $actionData .= VisitorMonitoring::$Browser->ChatRequest->Invitation->GetCommand(VisitorMonitoring::$Browser->ChatRequest->Id);
                    }
                }
            }
        }
    }
    if (!empty(VisitorMonitoring::$Browser->WebsitePush)) {
        if (isset($_GET[GET_TRACK_WEBSITE_PUSH_DECLINED])) {
            VisitorMonitoring::$Browser->WebsitePush->SetStatus(false, false, true);
        } else {
            if (isset($_GET[GET_TRACK_WEBSITE_PUSH_ACCEPTED]) || !VisitorMonitoring::$Browser->WebsitePush->Ask && !VisitorMonitoring::$Browser->WebsitePush->Displayed) {
                VisitorMonitoring::$Browser->WebsitePush->SetStatus(false, true, false);
                $actionData .= VisitorMonitoring::$Browser->WebsitePush->GetExecCommand();
            } else {
                if (VisitorMonitoring::$Browser->WebsitePush->Ask && !VisitorMonitoring::$Browser->WebsitePush->Accepted && !VisitorMonitoring::$Browser->WebsitePush->Declined) {
                    VisitorMonitoring::$Browser->WebsitePush->SetStatus(true, false, false);
                    $actionData .= VisitorMonitoring::$Browser->WebsitePush->GetInitCommand();
                }
            }
        }
    }
    if (!empty(VisitorMonitoring::$Browser->Alert) && !VisitorMonitoring::$Browser->Alert->Accepted) {
        $actionData .= VisitorMonitoring::$Browser->Alert->GetCommand();
        VisitorMonitoring::$Browser->Alert->SetStatus(false, true);
    }
    if (!empty(VisitorMonitoring::$Browser->OverlayBox) && !VisitorMonitoring::$Browser->OverlayBox->Closed) {
        $action = Server::$Events->GetActionById(VisitorMonitoring::$Browser->OverlayBox->EventActionId);
        $template = null;
        if (!Is::Null($action)) {
            $template = $action->OverlayBox;
        } else {
            if (empty(VisitorMonitoring::$Browser->OverlayBox->EventActionId)) {
                $template = $OVERLAY->GetFeedbackTemplate();
            }
        }
        if ($template != null) {
            if (isset($_GET["confol"])) {
                VisitorMonitoring::$Browser->OverlayBox->SetStatus(true);
            } else {
                $boxHTML = Server::Replace(VisitorMonitoring::$Browser->OverlayBox->CreateOverlayTemplate($template->Style, Server::$Configuration->File["gl_site_name"], $template->Width, $template->Height, LIVEZILLA_URL));
                VisitorMonitoring::$Browser->OverlayBox->OverlayElement = $template;
                VisitorMonitoring::$Browser->OverlayBox->OverlayElement->HTML = $boxHTML;
                $actionData .= VisitorMonitoring::$Browser->OverlayBox->OverlayElement->GetCommand();
            }
        }
    }
    return $actionData;
}
            if (!$isSpam) {
                $feedback->AddCriteriaDataFromServerInput();
                $feedback->Save();
            } else {
                Logging::GeneralLog("Feedback matches SPAM filter rule.");
            }
            $fb_html = str_replace("<!--sub_title-->", "<br>" . LocalizationManager::$TranslationStrings["client_feedback_success"] . "<script>parent.parent.lz_chat_feedback_result();</script>", $fb_html);
            $fb_html = str_replace("<!--title-->", "<br><br><br>" . LocalizationManager::$TranslationStrings["client_thank_you"], $fb_html);
            $fb_html = str_replace("<!--visible-->", "none", $fb_html);
        } else {
            $inputs_html = $js_id_list = "";
            foreach (Server::$Configuration->Database["gl_fb"] as $id => $criteria) {
                if (!empty($js_id_list)) {
                    $js_id_list .= ",";
                }
                $js_id_list .= "'" . $id . "'";
                $inputs_html .= $criteria->GetHTML();
            }
            $fb_html = str_replace("<!--criteria-->", $inputs_html, $fb_html);
            $fb_html = str_replace("<!--ids-->", $js_id_list, $fb_html);
            $fb_html = str_replace("<!--visible-->", "", $fb_html);
            $fb_html = str_replace("<!--sub_title-->", "", $fb_html);
            if (!empty($chat) && !empty(Server::$Operators[$chat->DesiredChatPartner])) {
                $fb_html = str_replace("<!--title-->", str_replace("<!--fullname-->", Server::$Operators[$chat->DesiredChatPartner]->Fullname, LocalizationManager::$TranslationStrings["client_feedback_title_personal"]), $fb_html);
            } else {
                $fb_html = str_replace("<!--title-->", LocalizationManager::$TranslationStrings["client_feedback_title"], $fb_html);
            }
        }
    }
    exit(Server::Replace($fb_html));
}
        VisitorMonitoring::$Response = str_replace("<!--hide_group_select_chat-->", To::BoolString(Communication::GetParameter("hcgs", false)), VisitorMonitoring::$Response);
        VisitorMonitoring::$Response = str_replace("<!--hide_group_select_ticket-->", To::BoolString(Communication::GetParameter("htgs", false)), VisitorMonitoring::$Response);
        VisitorMonitoring::$Response = str_replace("<!--require_group_selection-->", To::BoolString(Communication::GetParameter("rgs", false)), VisitorMonitoring::$Response);
        VisitorMonitoring::$Response = OverlayChat::ReplaceColors(VisitorMonitoring::$Response, false);
        if ($eca == 1) {
            VisitorMonitoring::$Response = str_replace("<!--ec_header_text-->", Encoding::Base64UrlEncode(Communication::GetParameter("echt", @LocalizationManager::$TranslationStrings["client_ec_text"], $c, FILTER_HTML_ENTITIES)), VisitorMonitoring::$Response);
            VisitorMonitoring::$Response = str_replace("<!--ec_header_sub_text-->", Encoding::Base64UrlEncode(Communication::GetParameter("echst", @LocalizationManager::$TranslationStrings["client_ec_sub_text"], $c, FILTER_HTML_ENTITIES)), VisitorMonitoring::$Response);
            VisitorMonitoring::$Response = str_replace("<!--ec_o_header_text-->", Encoding::Base64UrlEncode(Communication::GetParameter("ecoht", @LocalizationManager::$TranslationStrings["client_ec_o_text"], $c, FILTER_HTML_ENTITIES)), VisitorMonitoring::$Response);
            VisitorMonitoring::$Response = str_replace("<!--ec_o_header_sub_text-->", Encoding::Base64UrlEncode(Communication::GetParameter("ecohst", @LocalizationManager::$TranslationStrings["client_ec_o_sub_text"], $c, FILTER_HTML_ENTITIES)), VisitorMonitoring::$Response);
        } else {
            if ($eca == 2) {
                VisitorMonitoring::$Response = str_replace("<!--ec_image-->", Encoding::Base64UrlEncode(Communication::ReadParameter("eci", "")), VisitorMonitoring::$Response);
                VisitorMonitoring::$Response = str_replace("<!--ec_o_image-->", Encoding::Base64UrlEncode(Communication::ReadParameter("ecio", "")), VisitorMonitoring::$Response);
            }
        }
        VisitorMonitoring::$Response = Server::Replace(VisitorMonitoring::$Response, true, false);
    }
    VisitorMonitoring::$Response = str_replace("<!--user_name-->", Encoding::Base64UrlEncode(VisitorMonitoring::$Browser->UserData->Fullname), VisitorMonitoring::$Response);
    VisitorMonitoring::$Response = str_replace("<!--user_email-->", Encoding::Base64UrlEncode(VisitorMonitoring::$Browser->UserData->Email), VisitorMonitoring::$Response);
    VisitorMonitoring::$Response = str_replace("<!--height-->", Server::$Configuration->File["wcl_window_height"], VisitorMonitoring::$Response);
    VisitorMonitoring::$Response = str_replace("<!--width-->", Server::$Configuration->File["wcl_window_width"], VisitorMonitoring::$Response);
    VisitorMonitoring::$Response = str_replace("<!--get_track_params-->", getParams("", array("deactr" => true, "prv" => true, "ecsgs" => true, "hcgs" => true, "htgs" => true, "ecsge" => true, "ecsc" => true, "ecsy" => true, "ecsx" => true, "ecsb" => true, "ecsa" => true, "ecslw" => true, "echc" => true, "ecfs" => true, "ecfe" => true, "echt" => true, "echst" => true, "ecoht" => true, "ecohst" => true, "ovlto" => true, "ovlt" => true, "ovlp" => true, "ovloe" => true, "ovlml" => true, "ovlmr" => true, "ovlhm" => true, "ovlmt" => true, "ovlmb" => true, "ovls" => true, "ovloo" => true, "ovlc" => true, "ovlch" => true, "ovlts" => true, "ovlapo" => true, "ovlct" => true, "ovlntwo" => true, "ovlw" => true, "ovlh" => true, GET_EXTERN_GROUP => true, "intid" => true, "pref" => true, "cboo" => true, "hg" => true, "fbpos" => false, "fbw" => false, "fbh" => false, "fbshx" => true, "fbshy" => true, "fbshb" => true, "fbshc" => true, "fbmt" => false, "fbmr" => false, "fbmb" => false, "fbml" => false, "fboo" => false, "eca" => true, "ecw" => true, "ech" => true, "echm" => true, "ecmb" => true, "ecfi" => true, "ecfo" => true, "ecml" => true, "cf0" => true, "cf1" => true, "cf2" => true, "cf3" => true, "cf4" => true, "cf5" => true, "cf6" => true, "cf7" => true, "cf8" => true, "cf9" => true)), VisitorMonitoring::$Response);
    VisitorMonitoring::$Response = str_replace("<!--server-->", LIVEZILLA_URL, VisitorMonitoring::$Response);
} else {
    Visitor::$PollCount = Communication::ReadParameter("pc", 0);
    VisitorMonitoring::$Response = "lz_tracking_set_sessid(\"" . base64_encode(CALLER_USER_ID) . "\",\"" . base64_encode(CALLER_BROWSER_ID) . "\");";
    if (BaseURL::IsInputURL() && strpos(BaseURL::GetInputURL(), "lzmobile") !== false && Visitor::$PollCount == 1) {
        exit("eval(lz_global_base64_decode('" . base64_encode(IOStruct::GetFile(PATH_TEMPLATES . "jscript/jstrack.mob.tpl")) . "'));lz_tracking_stop_tracking(75);");
    }
    if (BaseURL::IsInputURL() && strpos(BaseURL::GetInputURL(), GET_INTERN_COBROWSE) !== false) {
        VisitorMonitoring::Abort(1);
                 $navcats .= "<a href=\"#" . $match->Id . "\"><div>" . $match->Title . "<span>(" . count($match->ChildNodes) . ")</span></div></a>";
                 $catcount++;
             }
             $res = str_replace("<!--search-->", "false", $res);
             $res = str_replace("<!--entries-->", $entries, $res);
             if ($childcount > 0) {
                 $result .= $res;
             }
         }
         $main = IOStruct::GetFile(PATH_TEMPLATES . "kb_result_main.tpl");
         $main = str_replace("<!--show_cats-->", $catcount > 1 ? "''" : "none", $main);
         $main = str_replace("<!--categories-->", $catcount > 1 ? $navcats : "", $main);
         $main = str_replace("<!--content-->", $result, $main);
     }
     if (!empty($result) && !empty($main)) {
         $externalUser->AddFunctionCall("lz_chat_search_result('" . base64_encode(Server::Replace($main, true, false, false, false)) . "',0);", false);
     } else {
         $externalUser->AddFunctionCall("lz_chat_search_result('" . base64_encode("<div><br><br>" . LocalizationManager::$TranslationStrings["client_kb_no_entries"] . "</div>" . $result) . "',0);", false);
     }
 } else {
     if (strlen($query) >= 3) {
         $matches = KnowledgeBase::GetMatches($query, Visitor::$BrowserLanguage);
         if (count($matches) > 0) {
             foreach ($matches as $match) {
                 $result .= $match->GetHTML($color);
             }
             $res = IOStruct::GetFile(PATH_TEMPLATES . "kb_result_category.tpl");
             $res = str_replace("<!--title-->", "\"" . cutString($query, 50, true) . "\"", $res);
             $res = str_replace("<!--entries-->", $result, $res);
             $res = str_replace("<!--search-->", "true", $res);
             $res = str_replace("<!--id-->", "sr", $res);
$scheme = Communication::GetScheme();
$html = IOStruct::GetFile(TEMPLATE_HTML_INDEX);
$errorbox = null;
$errors['write'] = getFolderPermissions();
$errors['php_version'] = getPhpVersion();
$errors['mysql'] = getMySQL();
$errors['disabled'] = getDisabledFunctions();
if (!empty($errors['write']) || !empty($errors['php_version']) || !empty($errors['mysql']) || !empty($errors['disabled'])) {
    $errorbox = IOStruct::GetFile(TEMPLATE_HTML_INDEX_ERRORS);
    $errorbox = str_replace("<!--write_access-->", $errors['write'], $errorbox);
    if (strlen($errors['write']) > 0 && !empty($errors['php_version'])) {
        $errors['php_version'] = "<br><br>" . $errors['php_version'];
    }
    if ((strlen($errors['write']) > 0 || !empty($errors['php_version'])) && !empty($errors['mysql'])) {
        $errors['mysql'] = "<br><br>" . $errors['mysql'];
    }
    if ((strlen($errors['write']) > 0 || !empty($errors['php_version']) || !empty($errors['mysql'])) && !empty($errors['disabled'])) {
        $errors['disabled'] = "<br><br>" . $errors['disabled'];
    }
    $errorbox = str_replace("<!--mysql-->", $errors['mysql'], $errorbox);
    $errorbox = str_replace("<!--php_version-->", $errors['php_version'], $errorbox);
    $errorbox = str_replace("<!--disabled-->", $errors['disabled'], $errorbox);
}
$html = str_replace("<!--index_errors-->", $errorbox, $html);
$html = str_replace("<!--height-->", Server::$Configuration->File["wcl_window_height"], $html);
$html = str_replace("<!--width-->", Server::$Configuration->File["wcl_window_width"], $html);
$html = str_replace("<!--lz_version-->", VERSION, $html);
$html = str_replace("<!--time-->", date(DATE_W3C), $html);
$html = str_replace("<!--title-->", base64_decode($d[array_rand($d = array("TGl2ZVppbGxhIExpdmUgQ2hhdCBTb2Z0d2FyZQ==", "TGl2ZVppbGxhIExpdmUgU3VwcG9ydCBTb2Z0d2FyZQ==", "TGl2ZVppbGxhIExpdmUgQ2hhdCBTb2Z0d2FyZQ==", "TGl2ZVppbGxhIExpdmUgSGVscCBTb2Z0d2FyZQ==", "TGl2ZVppbGxhIExpdmUgQ2hhdCBTb2Z0d2FyZQ==", "TGl2ZVppbGxhIEN1c3RvbWVyIFN1cHBvcnQ=", "TGl2ZVppbGxhIE9ubGluZSBTdXBwb3J0", "TGl2ZVppbGxhIExpdmUgQ2hhdCBTb2Z0d2FyZQ=="), 1)]), $html);
echo Server::Replace($html);
 }
 if (!empty($OVERLAY->LastPost)) {
     $USER->AddFunctionCall("lz_chat_set_last_post('" . base64_encode(trim(html_entity_decode($OVERLAY->LastPost, ENT_COMPAT, "UTF-8"))) . "');", false);
 }
 if ($OVERLAY->PlaySound) {
     $USER->AddFunctionCall("lz_chat_play_sound('message');", false);
 }
 if (!empty($_GET["tid"])) {
     if ($ticket = $USER->SaveTicket(Communication::GetParameter("eg", "", $c), $USER->GeoCountryISO2, false, true, BaseURL::GetInputURL())) {
         $USER->Browsers[1]->ForceUpdate();
         $ticket->SendAutoresponder($USER, $USER->Browsers[0]);
     }
 }
 $OVERLAY->OverlayHTML = str_replace("<!--server-->", LIVEZILLA_URL, $OVERLAY->OverlayHTML);
 if ($OVERLAY->LanguageRequired) {
     $OVERLAY->OverlayHTML = Server::Replace($OVERLAY->OverlayHTML, $OVERLAY->LanguageRequired, false);
 }
 if (!empty($OVERLAY->OverlayHTML)) {
     $USER->AddFunctionCall("lz_chat_add_html_element('" . base64_encode($OVERLAY->OverlayHTML) . "',true," . $OVERLAY->LastPostReceived . "," . $OVERLAY->LastMessageReceived . ",'" . base64_encode($OVERLAY->LastPoster) . "','" . base64_encode(Communication::ReadParameter("lp", "")) . "'," . $OVERLAY->OperatorPostCount . ");", false);
 }
 $USER->AddFunctionCall("lz_chat_set_connecting(" . To::BoolString(!$OVERLAY->Botmode && (!empty($USER->Browsers[0]->ChatId) && !$USER->Browsers[0]->InternalActivation && !$USER->Browsers[0]->Closed && !$USER->Browsers[0]->Declined)) . ",'" . $USER->Browsers[0]->SystemId . "'," . To::BoolString(!empty($USER->Browsers[0]->OperatorId) && Server::$Operators[$USER->Browsers[0]->OperatorId]->Status == USER_STATUS_AWAY) . "," . $OVERLAY->GetWaitingMessage() . "," . intval(Server::$Configuration->File["gl_wmes"]) . ");", false);
 if ($OVERLAY->RepollRequired) {
     $USER->AddFunctionCall("lz_tracking_poll_server(1211);", false);
 }
 if ($USER->Browsers[0]->TranslationSettings != null) {
     $USER->AddFunctionCall("lz_chat_set_translation(" . $USER->Browsers[0]->TranslationSettings[0] . ",'" . base64_encode($USER->Browsers[0]->TranslationSettings[1]) . "','" . base64_encode($USER->Browsers[0]->TranslationSettings[2]) . "');", false);
 } else {
     $USER->AddFunctionCall("lz_chat_set_translation(null,null,null);", false);
 }
 if ($OVERLAY->FullLoad) {
     $USER->AddFunctionCall("lz_chat_load_input_values();", false);