if (isset($_GET["id"])) {
    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 . "_lib/functions.external.inc.php";
    require LIVEZILLA_PATH . "_definitions/definitions.dynamic.inc.php";
    require LIVEZILLA_PATH . "_definitions/definitions.protocol.inc.php";
    @set_error_handler("handleError");
    Server::InitDataProvider();
    Server::DefineURL("knowledgebase.php");
    LocalizationManager::AutoLoad();
    $color = ExternalChat::ReadTextColor();
    $entry = KnowledgeBaseEntry::GetById(Communication::ReadParameter("id", ""), true);
    if (!empty($entry)) {
        $html = IOStruct::GetFile(PATH_TEMPLATES . "kb_entry.tpl");
        if (!empty(Server::$Configuration->File["gl_kcss"])) {
            $html = str_replace("<!--custom_css-->", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . Server::$Configuration->File["gl_kcss"] . "\">", $html);
        }
        if (Server::$Configuration->File["gl_knbr"]) {
            $rresult = $entry->GetRateResult();
            if (($rate = Communication::ReadParameter("h", -1)) != -1) {
                $html = str_replace("<!--rate_text-->", "<br><div id=\"lz_chat_dialog_kb_rate\">" . $LZLANG["client_feedback_success"] . "</div>", $html);
                $entry->SaveRateResult($rate);
            } else {
                $bhtml = "<a href=\"./knowledgebase.php?id=<!--id-->&h=MQ__\"><!--lang_client_yes--></a><a href=\"./knowledgebase.php?id=<!--id-->&h=MA__\"><!--lang_client_no--></a>";
                $fhtml = $rresult[0] > 0 ? str_replace("<!--users-->", $rresult[0], str_replace("<!--total-->", $rresult[1], $LZLANG["client_found_helpful"])) . " " : "";
                $html = str_replace("<!--rate_text-->", "<br><div id=\"lz_chat_dialog_kb_rate\">" . $fhtml . $LZLANG["client_was_helpful"] . $bhtml . "</div>", $html);
 $html = str_replace("<!--bookmark_name-->", base64_encode(Server::$Configuration->File["gl_site_name"]), $html);
 $html = str_replace("<!--user_id-->", SESSION, $html);
 $html = str_replace("<!--connection_error_span-->", CONNECTION_ERROR_SPAN, $html);
 $html = GeoTracking::Replace($html);
 $html = str_replace("<!--requested_intern_userid-->", base64_encode(!empty($_GET[GET_EXTERN_INTERN_USER_ID]) && isset(Server::$Operators[Operator::GetSystemId(Encoding::Base64UrlDecode($_GET[GET_EXTERN_INTERN_USER_ID]))]) ? Encoding::Base64UrlDecode($_GET[GET_EXTERN_INTERN_USER_ID]) : ""), $html);
 $html = str_replace("<!--requested_intern_fullname-->", base64_encode(!empty($_GET[GET_EXTERN_INTERN_USER_ID]) && isset(Server::$Operators[Operator::GetSystemId(Encoding::Base64UrlDecode($_GET[GET_EXTERN_INTERN_USER_ID]))]) ? Server::$Operators[Operator::GetSystemId(Encoding::Base64UrlDecode($_GET[GET_EXTERN_INTERN_USER_ID]))]->Fullname : ""), $html);
 $html = str_replace("<!--debug-->", To::BoolString(!empty($_GET["debug"])), $html);
 $html = str_replace("<!--geo_resolute-->", To::BoolString(!empty(Server::$Configuration->File["gl_use_ngl"]) && !(Cookie::Get("geo_data") != null && Cookie::Get("geo_data") > time() - 2592000) && !GeoTracking::SpanExists()), $html);
 $html = str_replace("<!--chat_id-->", !empty($_GET["cid"]) ? getParam("cid") : "", $html);
 $html = str_replace("<!--gtv2_api_key-->", strlen(Server::$Configuration->File["gl_otrs"]) > 1 ? Server::$Configuration->File["gl_otrs"] : "", $html);
 $html = str_replace("<!--template_message_intern-->", base64_encode(str_replace("<!--color-->", ExternalChat::ReadBackgroundColor(), str_replace("<!--dir-->", LocalizationManager::$Direction, IOStruct::GetFile(TEMPLATE_HTML_MESSAGE_INTERN)))), $html);
 $html = str_replace("<!--template_message_extern-->", base64_encode(str_replace("<!--dir-->", LocalizationManager::$Direction, IOStruct::GetFile(TEMPLATE_HTML_MESSAGE_EXTERN))), $html);
 $html = str_replace("<!--template_message_add-->", base64_encode(str_replace("<!--dir-->", LocalizationManager::$Direction, IOStruct::GetFile(TEMPLATE_HTML_MESSAGE_ADD))), $html);
 $html = str_replace("<!--template_message_add_alt-->", base64_encode(str_replace("<!--dir-->", LocalizationManager::$Direction, IOStruct::GetFile(TEMPLATE_HTML_MESSAGE_ADD_ALTERNATE))), $html);
 $html = str_replace("<!--primary_color-->", ExternalChat::ReadBackgroundColor(), $html);
 $html = str_replace("<!--secondary_color-->", ExternalChat::ReadTextColor(), $html);
 $html = str_replace("<!--direct_login-->", To::BoolString(isset($_GET[GET_EXTERN_USER_NAME]) && !isset($_GET[GET_EXTERN_RESET]) || isset($_GET["dl"])), $html);
 $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);
 function GetWaitingLinks($_question, $_language, $html = "", $count = 0)
 {
     $knowledgebase = false;
     $answers = ChatAutoReply::GetMatches($this->AutoReplies, $_question, $_language, null, null);
     if (!empty(Server::$Configuration->File["gl_knbq"]) && count($answers) == 0) {
         $answers = KnowledgeBase::GetMatches($_question, Visitor::$BrowserLanguage);
         $knowledgebase = true;
         $color = ExternalChat::ReadTextColor();
     }
     if (count($answers) > 0) {
         foreach ($answers as $qa) {
             if ((!empty($qa->ResourceId) || !empty($qa->Answer)) && $qa->Waiting) {
                 $res = KnowledgeBaseEntry::GetById($qa->ResourceId);
                 $target = $qa->NewWindow ? "target=\"_blank\" " : "";
                 $html .= "<li>";
                 if ($res == null) {
                     $html .= $qa->Answer;
                 } else {
                     if ($res["type"] == 2) {
                         $html .= "<a class=\"lz_chat_link\" href=\"" . $res["value"] . "\" " . $target . ">" . $res["title"] . "</a>";
                     } else {
                         if ($res["type"] == 3 || $res["type"] == 4) {
                             $html .= "<a class=\"lz_chat_link\" href=\"" . LIVEZILLA_URL . "getfile.php?id=" . $res["id"] . "\" " . $target . ">" . $res["title"] . "</a>";
                         } else {
                             $html .= "<b>" . $res["title"] . "</b><br>" . str_replace("<a ", "<a " . $target, str_replace("<A", "<a", $res["value"]));
                         }
                     }
                 }
                 $html .= "</li>";
             } else {
                 if ($knowledgebase) {
                     $ehtml = trim($qa->GetHTML($color, true, false));
                     if (!empty($ehtml)) {
                         $html .= $ehtml;
                     }
                 }
             }
             if (++$count > 5) {
                 break;
             }
         }
         if (!empty($html)) {
             $html = "<div id=\"lz_chat_waiting_links\">" . LocalizationManager::$TranslationStrings["client_while_waiting"] . "<ul>" . $html . "</ul></div>";
             return $html;
         }
     }
     return "";
 }