$html = str_replace("<!--preselect_ticket-->", To::BoolString(isset($_GET["pt"])), $html);
    $html = str_replace("<!--is_ie-->", To::BoolString(!empty($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false), $html);
    $html = str_replace("<!--is_ios-->", To::BoolString($MobileDetect->isIOS()), $html);
    $html = str_replace("<!--setup_error-->", base64_encode(buildLoginErrorField()), $html);
    $html = str_replace("<!--offline_message_mode-->", Server::$Configuration->File["gl_om_mode"], $html);
    $html = str_replace("<!--offline_message_http-->", Server::$Configuration->File["gl_om_http"], $html);
    $html = str_replace("<!--checkout_url-->", !empty(Server::$Configuration->Database["ccpp"]["Custom"]) ? Server::$Configuration->Database["ccpp"]["Custom"]->URL : "", $html);
    $html = str_replace("<!--checkout_only-->", To::BoolString(!empty($_GET["co"]) && !empty($_GET[GET_EXTERN_GROUP])), $html);
    $html = str_replace("<!--checkout_extend_success-->", To::BoolString(!empty($_GET["co"]) && !empty($_GET["vc"])), $html);
    $html = str_replace("<!--function_callback-->", To::BoolString(empty(VisitorChat::$DynamicGroup) && (!empty($_GET["cmb"]) || !empty($_GET["ofc"]))), $html);
    $html = str_replace("<!--function_ticket-->", To::BoolString(empty($_GET["nct"])), $html);
    $html = str_replace("<!--function_chat-->", To::BoolString(empty($_GET["hfc"])), $html);
    $html = str_replace("<!--function_knowledgebase-->", To::BoolString(empty($_GET["hfk"]) && !empty(Server::$Configuration->File["gl_knba"])), $html);
    $html = str_replace("<!--hide_group_select_chat-->", To::BoolString(Communication::GetParameter("hcgs", 0, $nu, FILTER_VALIDATE_INT) == "1" || !empty($_GET[GET_EXTERN_DYNAMIC_GROUP])), $html);
    $html = str_replace("<!--hide_group_select_ticket-->", To::BoolString(Communication::GetParameter("htgs", 0, $nu, FILTER_VALIDATE_INT) == "1"), $html);
    $html = str_replace("<!--require_group_selection-->", To::BoolString(Communication::GetParameter("rgs", 0, $nu, FILTER_VALIDATE_INT) == "1"), $html);
    $html = str_replace("<!--offline_message_pop-->", To::BoolString(!empty(Server::$Configuration->File["gl_om_pop_up"]) || empty(Server::$Configuration->File["gl_om_mode"])), $html);
    $html = str_replace("<!--dynamic_group-->", !empty(VisitorChat::$DynamicGroup) ? base64_encode(Server::$Groups[VisitorChat::$DynamicGroup]->Descriptions["EN"]) : "", $html);
} else {
    if ($_GET[GET_EXTERN_TEMPLATE] == "lz_chat_frame_lgin") {
        $html = IOStruct::GetFile(PATH_FRAMES . $_GET[GET_EXTERN_TEMPLATE] . ".tpl");
        $html = isset(Server::$Configuration->File["gl_site_name"]) ? str_replace("<!--config_name-->", Server::$Configuration->File["gl_site_name"], $html) : str_replace("<!--config_name-->", "LiveZilla", $html);
        $html = getChatLoginInputs($html, MAX_INPUT_LENGTH);
        $html = str_replace("<!--alert-->", getAlertTemplate(), $html);
        $html = str_replace("<!--com_chats-->", getChatVoucherTemplate(), $html);
        $html = str_replace("<!--ssl_secured-->", Communication::GetScheme() == SCHEME_HTTP_SECURE && !empty(Server::$Configuration->File["gl_sssl"]) ? "" : "display:none;", $html);
        $html = str_replace("<!--bgc-->", $color = Communication::ReadParameter("epc", "#73be28"), $html);
        $html = str_replace("<!--color-->", Colors::TransformHEX($color, 30), $html);
    } else {
        if ($_GET[GET_EXTERN_TEMPLATE] == "lz_chat_frame_chat") {
            $html = IOStruct::GetFile(PATH_FRAMES . $_GET[GET_EXTERN_TEMPLATE] . ".tpl");
 function Listen()
 {
     global $USER;
     $isOp = false;
     if ($USER->Browsers[0]->Status == CHAT_STATUS_ACTIVE) {
         $result = DBManager::Execute(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_CHAT_OPERATORS . "` WHERE `chat_id`='" . DBManager::RealEscape($USER->Browsers[0]->ChatId) . "' ORDER BY `status` DESC, `dtime` DESC;");
         while ($row = DBManager::FetchArray($result)) {
             if (isset(Server::$Operators[$row["user_id"]])) {
                 $ChatMember = new ChatMember($row["user_id"], $row["status"], !empty($row["declined"]), $row["jtime"], $row["ltime"]);
                 if ($ChatMember->Status == 1 && $ChatMember->Joined >= $USER->Browsers[0]->LastActive) {
                     $isOp = true;
                     $this->AddHTML(str_replace("<!--message-->", str_replace("<!--intern_name-->", Server::$Operators[$ChatMember->SystemId]->Fullname, LocalizationManager::$TranslationStrings["client_intern_arrives"]), IOStruct::GetFile(TEMPLATE_HTML_MESSAGE_OVERLAY_CHAT_STATUS)), "sys", "LMMJ" . $ChatMember->SystemId);
                 } else {
                     if (($ChatMember->Status == 9 || $ChatMember->Status == 2) && $ChatMember->Left >= $USER->Browsers[0]->LastActive && $ChatMember->Joined > 0) {
                         $this->AddHTML($this->GetLeaveChatHTML(false, Server::$Operators[$ChatMember->SystemId]->Fullname), "sys", "LCM01" . $ChatMember->SystemId);
                     }
                 }
                 if ($ChatMember->Status == 0) {
                     $isOp = true;
                 }
             }
         }
     } else {
         $isOp = true;
     }
     if (Communication::ReadParameter("ovlif")) {
         $this->InitFeedback();
     }
     $USER->Browsers[0]->Typing = isset($_GET["typ"]);
     if (!$USER->Browsers[0]->Declined) {
         $USER->Browsers[0]->Save();
     }
     $USER->Browsers[0]->ValidateOperator();
     $this->CurrentOperatorId = Communication::GetParameter("op", "", $c, FILTER_SANITIZE_SPECIAL_CHARS, null, 32);
     if ($USER->Browsers[0]->Waiting && $this->Botmode || empty($USER->Browsers[0]->OperatorId) && !empty($this->CurrentOperatorId) && isset(Server::$Operators[$this->CurrentOperatorId]) && !Server::$Operators[$this->CurrentOperatorId]->IsBot || !empty($this->CurrentOperatorId) && empty($USER->Browsers[0]->ChatId) && !$this->Botmode || !$isOp || $USER->Browsers[0]->Closed) {
         if (!$USER->Browsers[0]->ExternalClosed) {
             $USER->Browsers[0]->ExternalClose();
             $USER->Browsers[0]->Save();
             $USER->Browsers[0]->Load();
         }
         $USER->Browsers[0]->Members = array();
         if (!empty($this->CurrentOperatorId) && !empty(Server::$Operators[$this->CurrentOperatorId]) && $isOp) {
             $this->AddHTML($this->GetLeaveChatHTML(true, Server::$Operators[$this->CurrentOperatorId]->Fullname), "sys", "LCM01" . $this->CurrentOperatorId);
             if (!empty(Server::$Configuration->File["gl_fboe"]) && Communication::ReadParameter("po", 0) == 0 && !Server::$Operators[$this->CurrentOperatorId]->IsBot) {
                 if (!empty(Server::$Groups[$USER->Browsers[0]->DesiredChatGroup]->ChatFunctions[3])) {
                     $this->InitFeedback(false);
                 }
             }
             $this->Flags["LMR"] = "null";
             $USER->Browsers[0]->OperatorId = null;
             $this->CurrentOperatorId = "";
             $this->RepollRequired = true;
         }
     }
 }
 function AddCriteriaDataFromServerInput()
 {
     foreach (Server::$Configuration->Database["gl_fb"] as $criteria) {
         $this->CriteriaList[$criteria->Id] = Communication::GetParameter($criteria->GetPostKey(), "", $nu, FILTER_SANITIZE_SPECIAL_CHARS, null, 512, false, false);
     }
 }
 * 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";
Server::DefineURL("print.php");
@set_error_handler("handleError");
if (Server::InitDataProvider()) {
    if (!empty($_GET[GET_TRACK_CHATID]) && !empty($_GET[GET_TRACK_BROWSERID]) && !empty($_GET[GET_TRACK_USERID])) {
        $archive = new Chat();
        $archive->ChatId = intval(Communication::GetParameter("c", ""));
        $archive->Load();
        $chat = VisitorChat::GetByChatId($archive->ChatId);
        if ($chat->BrowserId == Communication::GetParameter(GET_TRACK_BROWSERID, "") && $chat->UserId == Communication::GetParameter(GET_TRACK_USERID, "") && $chat->LastActive > time() - 3600) {
            $print = IOStruct::GetFile(PATH_TEMPLATES . "print.tpl");
            $archive->Generate($archive->ChatId, "", true, true);
            $print = str_replace("<!--chat_id-->", $archive->ChatId, $print);
            $print = str_replace("<!--transcript-->", nl2br($archive->PlainText), $print);
        }
        exit($print);
    }
}
             VisitorMonitoring::Abort(3);
         }
         $currentURL = new HistoryURL(BaseURl::GetInputURL(), Communication::GetParameter(GET_TRACK_SPECIAL_AREA_CODE, "", $nu, null, null, 255), Communication::GetParameter(GET_EXTERN_DOCUMENT_TITLE, "", $nu, null, null, 255), Communication::GetParameter(GET_TRACK_REFERRER, "", $nu, FILTER_SANITIZE_URL, null, 510), time());
         if ($currentURL->Referrer->IsInternalDomain()) {
             $currentURL->Referrer = new BaseUrl("");
         }
         if ($currentURL->Url->Excluded) {
             VisitorMonitoring::Abort(4);
         }
     }
     if (VisitorMonitoring::$IsActive) {
         VisitorMonitoring::$Visitor->Save(array(Communication::GetParameter(GET_TRACK_RESOLUTION_WIDTH, "", $nu, FILTER_SANITIZE_SPECIAL_CHARS, null, 32), Communication::GetParameter(GET_TRACK_RESOLUTION_HEIGHT, "", $nu, FILTER_SANITIZE_SPECIAL_CHARS, null, 32)), Communication::GetParameter(GET_TRACK_COLOR_DEPTH, "", $nu, FILTER_SANITIZE_SPECIAL_CHARS, null, 32), Communication::GetParameter(GET_TRACK_TIMEZONE_OFFSET, "", $nu, FILTER_SANITIZE_SPECIAL_CHARS, null, 32), Communication::GetParameter(GEO_LATITUDE, -522, $nu, FILTER_VALIDATE_FLOAT, array(), 0, true, false), Communication::GetParameter(GEO_LONGITUDE, -522, $nu, FILTER_VALIDATE_FLOAT, array(), 0, true, false), Communication::GetParameter(GEO_COUNTRY_ISO_2, "", $nu, null, null, 32, true, false), Communication::GetParameter(GEO_CITY, "", $nu, null, null, 255, true, false), Communication::GetParameter(GEO_REGION, "", $nu, null, null, 255, true, false), Communication::GetParameter(GEO_TIMEZONE, "", $nu, null, null, 24, true, false), Communication::GetParameter(GEO_ISP, "", $nu, null, null, 255, true, false), Communication::GetParameter(GEO_SSPAN, 0, $nu, FILTER_VALIDATE_INT, array(), 0, false, false), Communication::GetParameter(GEO_RESULT_ID, "", $nu, FILTER_VALIDATE_INT, array(), 32, false, false));
     }
 } else {
     if (!empty($_SERVER["HTTP_REFERER"])) {
         $currentURL = new HistoryURL(Communication::GetParameter("HTTP_REFERER", "", $nu, FILTER_SANITIZE_URL, null, 500), Communication::GetParameter(GET_TRACK_SPECIAL_AREA_CODE, "", $nu, null, null, 255), "", "", time());
         if ($currentURL->Url->Excluded) {
             VisitorMonitoring::Abort(5);
         } else {
             if (!$currentURL->Url->IsInternalDomain()) {
                 VisitorMonitoring::Abort(6);
             }
         }
         if (VisitorMonitoring::$IsActive) {
             VisitorMonitoring::$Visitor->Save(null, "", "", -522, -522, "", "", "", "", "", "", "", false);
         }
     } else {
         VisitorMonitoring::Abort(-1);
     }
 }
 if (VisitorMonitoring::$Visitor->IsCrawler) {
                         $externalUser->Browsers[1]->UserData->LoadFromCookie();
                     }
                     $externalUser = $externalUser->Browsers[1]->ReplaceLoginDetails($externalUser);
                     $externalUser->ReloadGroups();
                 }
             } else {
                 $externalUser->Browsers[0]->CloseWindow();
                 exit;
             }
         }
     }
 }
 if (!isset($_POST[POST_EXTERN_RESOLUTION_WIDTH])) {
     $externalUser->KeepAlive();
 } else {
     $externalUser->Save(array(Communication::GetParameter(POST_EXTERN_RESOLUTION_WIDTH, "", $nu, FILTER_SANITIZE_SPECIAL_CHARS, null, 32), Communication::GetParameter(POST_EXTERN_RESOLUTION_HEIGHT, "", $nu, FILTER_SANITIZE_SPECIAL_CHARS, null, 32)), Communication::GetParameter(POST_EXTERN_COLOR_DEPTH, "", $nu, FILTER_SANITIZE_SPECIAL_CHARS, null, 32), Communication::GetParameter(POST_EXTERN_TIMEZONE_OFFSET, "", $nu, FILTER_SANITIZE_SPECIAL_CHARS, null, 32), Communication::GetParameter(GEO_LATITUDE, -522, $nu, FILTER_VALIDATE_FLOAT), Communication::GetParameter(GEO_LONGITUDE, -522, $nu, FILTER_VALIDATE_FLOAT), Communication::GetParameter(GEO_COUNTRY_ISO_2, "", $nu, null, null, 32), Communication::GetParameter(GEO_CITY, "", $nu, null, null, 255), Communication::GetParameter(GEO_REGION, "", $nu, null, null, 255), Communication::GetParameter(GEO_TIMEZONE, "", $nu, null, null, 24), Communication::GetParameter(GEO_ISP, "", $nu, null, null, 255), Communication::GetParameter(GEO_SSPAN, 0, $nu, FILTER_VALIDATE_INT), Communication::GetParameter(GEO_RESULT_ID, "", $nu, FILTER_SANITIZE_SPECIAL_CHARS, null, 32));
 }
 if ($externalUser->SignatureMismatch) {
     $externalUser->AddFunctionCall("lz_chat_set_signature(\"" . $externalUser->UserId . "\");", true);
     $externalUser->AddFunctionCall("lz_chat_reload_groups();", false);
 } else {
     $externalUser->Browsers[0]->VisitId = $externalUser->VisitId;
     if (isset($_GET[GET_TRACK_SPECIAL_AREA_CODE])) {
         $externalUser->Browsers[0]->Code = Encoding::Base64UrlDecode($_GET[GET_TRACK_SPECIAL_AREA_CODE]);
     }
     if (IS_FILTERED && !FILTER_ALLOW_CHATS) {
         $externalUser->Browsers[0]->CloseChat(8);
     } else {
         if (!$externalUser->Browsers[0]->Closed) {
             $externalUser->Browsers[0]->Save();
         }
 *
 * 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 (isset($_GET["id"]) && Server::InitDataProvider()) {
    Server::InitDataBlock(array("INTERNAL"));
    if (Operator::IPValidate()) {
        if (empty(Server::$Configuration->File["gl_avhe"])) {
            exit("HTML content is currently not being saved for security reasons. Please check your LiveZilla configuration:<br><br>LiveZilla Server Admin -> Server Configuration -> Security");
        }
        $c = null;
        $html = TicketEmail::GetHTML(Communication::GetParameter("id", "", $c, null, null));
        if (!empty($html)) {
            exit($html);
        }
        exit("Sorry, email does not exist or no HTML content was found.");
    }
}
 static function ReadParams()
 {
     if (!empty($_POST[POST_EXTERN_REQUESTED_INTERNID])) {
         return Communication::GetParameter(POST_EXTERN_REQUESTED_INTERNID, "", $c, FILTER_SANITIZE_SPECIAL_CHARS, null, 32);
     } else {
         if (!empty($_GET[GET_EXTERN_INTERN_USER_ID])) {
             return Communication::GetParameter(GET_EXTERN_INTERN_USER_ID, "", $c, FILTER_SANITIZE_SPECIAL_CHARS, null, 32);
         }
     }
     return "";
 }
     $OVERLAY->OperatorPostCount = -1;
 }
 if (!empty($OVERLAY->SpeakingToHTML) && !$OVERLAY->SpeakingToAdded) {
     $OVERLAY->AddHTML($OVERLAY->SpeakingToHTML, "sys", "SPKT" . Server::$Operators[$USER->Browsers[0]->OperatorId]->SystemId);
 }
 if (!empty($OVERLAY->PostHTML)) {
     $OVERLAY->AddHTML($OVERLAY->PostHTML, $OVERLAY->Flags["LPP"]);
 }
 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);
 }