function getParams($_getParams = "", $_allowed = null)
{
    foreach ($_GET as $key => $value) {
        if ($key != "template" && !($_allowed != null && !isset($_allowed[$key]))) {
            if (Encoding::IsBase64Encoded($value, true)) {
                $value = !($_allowed != null && !$_allowed[$key]) ? Encoding::Base64UrlEncode(Encoding::Base64UrlDecode($value)) : Encoding::Base64UrlEncode($value);
                $_getParams .= (strlen($_getParams) == 0 ? $_getParams : "&") . urlencode($key) . "=" . $value;
            }
        }
    }
    return $_getParams;
}
                }
            } 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)) {
 function InitFeedback($_userInitiated = true)
 {
     global $USER;
     Server::InitDataBlock(array("DBCONFIG"));
     if (empty(Server::$Configuration->Database["gl_fb"])) {
         return;
     }
     $cid = $USER->Browsers[0]->GetLastActiveChatId();
     if ($_userInitiated || !empty($cid)) {
         if ($_userInitiated || Feedback::GetByChatId($cid) == null) {
             $langparam = isset($_GET["el"]) ? "&el=" . $_GET["el"] : "";
             $value = "0;" . base64_encode(LIVEZILLA_URL . "feedback.php?cid=" . Encoding::Base64UrlEncode($cid) . $langparam);
             $fovl = new OverlayBox(CALLER_USER_ID, CALLER_BROWSER_ID, $value);
             $fovl->Id = md5($cid . CALLER_USER_ID . CALLER_BROWSER_ID);
             $fovl->Save();
             $fovl->SetStatus(false);
         }
     }
 }
 function GetHTML($_color, $_inChat = true, $_lineBreak = true)
 {
     $html = IOStruct::GetFile(PATH_TEMPLATES . ($this->Type == 2 || $this->Type == 3 || $this->Type == 4 ? "kb_result_link.tpl" : "kb_result_text.tpl"));
     $html = str_replace("<!--color-->", $_color, $html);
     $html = str_replace("<!--title-->", htmlentities($this->Title, ENT_QUOTES, "UTF-8"), $html);
     $html = str_replace("<!--href-->", $_inChat ? "javascript:parent.lz_chat_show_kb_entry('<!--id-->');" : LIVEZILLA_URL . "knowledgebase.php?id=<!--id-->", $html);
     if ($this->Type == 2) {
         $html = str_replace("<!--link-->", $this->Value, $html);
     } else {
         if ($this->Type == 3 || $this->Type == 4) {
             $html = str_replace("<!--link-->", LIVEZILLA_URL . "getfile.php?id=" . $this->Id, $html);
         } else {
             $html = str_replace("<!--id-->", Encoding::Base64UrlEncode($this->Id), $html);
         }
     }
     if (!$_lineBreak) {
         return $html;
     } else {
         return $html . "<br>";
     }
 }
function getJSCustomArray($_historyCustoms = null, $getCustomParams = "")
{
    Server::InitDataBlock(array("INPUTS"));
    $valArray = array();
    foreach (Server::$Inputs as $index => $input) {
        if ($input->Active && $input->Custom) {
            if (isset($_GET["cf" . $input->Index])) {
                $valArray[$index] = "'" . getParam("cf" . $input->Index) . "'";
            } else {
                if (is_array($_historyCustoms) && isset($_historyCustoms[$input->Index]) && !empty($_historyCustoms[$input->Index])) {
                    $valArray[$index] = "'" . Encoding::Base64UrlEncode($_historyCustoms[$input->Index]) . "'";
                } else {
                    $valArray[$index] = "''";
                }
            }
        } else {
            if ($input->Custom) {
                $valArray[$index] = "''";
            }
        }
    }
    ksort($valArray);
    foreach ($valArray as $param) {
        if (!empty($getCustomParams)) {
            $getCustomParams .= ",";
        }
        $getCustomParams .= $param;
    }
    return $getCustomParams;
}
    if (isset(Server::$Operators[$id])) {
        $sysid = $_GET["intid"];
        if (!empty(Server::$Operators[$id]->Profile)) {
            header("Content-Type: application/vcard;");
            header("Content-Disposition: attachment; filename=" . utf8_decode($sysid) . ".vcf");
            $vcard = IOStruct::GetFile("./templates/vcard.tpl");
            $vcard = str_replace("<!--Name-->", qp_encode(Server::$Operators[$id]->Profile->Name), $vcard);
            $vcard = str_replace("<!--Firstname-->", qp_encode(Server::$Operators[$id]->Profile->Firstname), $vcard);
            $vcard = str_replace("<!--Company-->", qp_encode(Server::$Operators[$id]->Profile->Company), $vcard);
            $vcard = str_replace("<!--Comments-->", qp_encode(Server::$Operators[$id]->Profile->Comments), $vcard);
            $vcard = str_replace("<!--Phone-->", qp_encode(Server::$Operators[$id]->Profile->Phone), $vcard);
            $vcard = str_replace("<!--Fax-->", qp_encode(Server::$Operators[$id]->Profile->Fax), $vcard);
            $vcard = str_replace("<!--Street-->", qp_encode(Server::$Operators[$id]->Profile->Street), $vcard);
            $vcard = str_replace("<!--City-->", qp_encode(Server::$Operators[$id]->Profile->City), $vcard);
            $vcard = str_replace("<!--ZIP-->", qp_encode(Server::$Operators[$id]->Profile->ZIP), $vcard);
            $vcard = str_replace("<!--Country-->", qp_encode(Server::$Operators[$id]->Profile->Country), $vcard);
            $vcard = str_replace("<!--URL-->", qp_encode("http://" . Server::$Configuration->File["gl_host"] . str_replace("visitcard.php", FILE_CHAT . "?intid=" . Encoding::Base64UrlEncode($_GET["intid"]), htmlentities($_SERVER["PHP_SELF"], ENT_QUOTES, "UTF-8"))), $vcard);
            $vcard = str_replace("<!--Languages-->", qp_encode(Server::$Operators[$id]->Profile->Languages), $vcard);
            $vcard = str_replace("<!--Email-->", Server::$Operators[$id]->Profile->Email, $vcard);
            $vcard = str_replace("<!--Gender-->", qp_encode(Server::$Operators[$id]->Profile->Gender), $vcard);
            $vcard = str_replace("<!--Picture-->", !empty(Server::$Operators[$id]->ProfilePicture) ? "\r\nPHOTO;TYPE=JPEG;ENCODING=BASE64:\r\n" . Server::$Operators[$id]->ProfilePicture : "", $vcard);
            exit($vcard);
        }
    }
}
function qp_encode($string)
{
    $string = str_replace(array('%20', '%0D%0A', '%'), array(' ', "\r\n", '='), rawurlencode(utf8_decode($string)));
    $string = preg_replace('/[^\\r\\n]{73}[^=\\r\\n]{2}/', "\$0=\r\n", $string);
    return $string;
}
        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);
    }
    VisitorMonitoring::$Browser = new VisitorBrowser(CALLER_BROWSER_ID, CALLER_USER_ID);
    VisitorMonitoring::$Visitor->AddBrowser(VisitorMonitoring::$Browser);
 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);
     }
 }
function processPlaceholders($html)
{
    $params = array(GET_EXTERN_USER_LANGUAGE, GET_EXTERN_USER_NAME, GET_EXTERN_USER_EMAIL, GET_EXTERN_USER_COMPANY, GET_TRACK_SPECIAL_AREA_CODE, GET_EXTERN_USER_QUESTION, GET_EXTERN_USER_HEADER);
    $placeholders = array("language", "name", "email", "company", "code", "question", "header_url");
    foreach ($params as $key => $value) {
        if (!empty($_GET[$value])) {
            $html = str_replace("&lt;!--replace_me_with_b64url_" . $placeholders[$key] . "--&gt;", Encoding::Base64UrlEncode(Encoding::Base64UrlDecode($_GET[$value])), $html);
        } else {
            $html = str_replace("&lt;!--replace_me_with_b64url_" . $placeholders[$key] . "--&gt;", "", $html);
        }
    }
    for ($i = 0; $i < 10; $i++) {
        if (!empty($_GET["cf" . $i])) {
            $html = str_replace("&lt;!--replace_me_with_b64url_custom_" . $i . "--&gt;", Encoding::Base64UrlEncode(Encoding::Base64UrlDecode($_GET["cf" . $i])), $html);
        } else {
            $html = str_replace("&lt;!--replace_me_with_b64url_custom_" . $i . "--&gt;", "", $html);
        }
    }
    return $html;
}
    }
    $html = IOStruct::GetFile(PATH_TEMPLATES . "payment/paypal.tpl");
    $html = str_replace("<!--account-->", Server::$Configuration->Database["ccpp"]["PayPal"]->Account, $html);
    $html = str_replace("<!--price-->", $_POST["form_total_price"] - $_POST["form_vat"], $html);
    $html = str_replace("<!--tax-->", $_POST["form_vat"], $html);
    $html = str_replace("<!--currency-->", $_POST["form_currency"], $html);
    $html = str_replace("<!--user_id-->", $_POST["form_visitor_id"], $html);
    $html = str_replace("<!--order_id-->", $ticket->Id, $html);
    $html = str_replace("<!--voucher_id-->", Encoding::Base64UrlEncode($ticket->Id), $html);
    $html = str_replace("<!--server-->", LIVEZILLA_URL, $html);
    $ofc = !empty($_POST["form_ofc"]) ? "&amp;ofc=MQ__" : "";
    if (!empty($_POST["form_extends"]) && !empty($_POST["form_group"])) {
        $html = str_replace("<!--co-->", "&amp;co=" . Encoding::Base64UrlEncode($_POST["form_extends"]) . "&amp;intgroup=" . Encoding::Base64UrlEncode($_POST["form_group"]) . $ofc, $html);
    } else {
        if (!empty($_POST["form_group"])) {
            $html = str_replace("<!--co-->", "&amp;intgroup=" . Encoding::Base64UrlEncode($_POST["form_group"]) . $ofc, $html);
        } else {
            $html = str_replace("<!--co-->", $ofc, $html);
        }
    }
    exit($html);
} else {
    if (!empty($_GET["confirm"]) && $_GET["confirm"] == "1" && !empty($_GET["vc"]) && strlen(Encoding::Base64UrlDecode($_GET["vc"])) == 16) {
        require LIVEZILLA_PATH . "_lib/functions.pp.paypal.inc.php";
        $voucher = new CommercialChatVoucher("", Encoding::Base64UrlDecode($_GET["vc"]));
        if ($voucher->Load()) {
            if (PayProvValidatePayment($voucher->Price)) {
                LocalizationManager::AutoLoad($voucher->Language);
                $voucher->SetPaymentDetails(PayProvGetPaymentId(), PayProvGetPayerId(), PayProvGetPaymentDetails());
                if (empty($PAYMENTERROR)) {
                    $voucher->SetVoucherParams(!empty($voucher->Voided), true, false, false, false, true, Encoding::Base64UrlDecode($_GET[GET_EXTERN_GROUP]));