static function LoadOverlayChat()
 {
     global $USER, $OVERLAY;
     //++
     if (!empty($_GET["ovlc"]) && !VisitorMonitoring::$HideOverlayOnMobile) {
         require_once LIVEZILLA_PATH . "ovl.php";
         Visitor::$IsActiveOverlayChat = false;
         VisitorMonitoring::$Response .= OverlayChat::$Response;
     }
 }
 function ProcessPosts()
 {
     global $USER;
     $pc = 0;
     if (!empty($USER->Browsers[0]->QueuedPosts)) {
         if (!$USER->Browsers[0]->Waiting) {
             while (!empty($_GET["mi" . $pc])) {
                 $pc++;
             }
             foreach ($USER->Browsers[0]->QueuedPosts as $id => $postar) {
                 $_GET["mp" . $pc] = $postar[0];
                 $_GET["mrid" . $pc] = $_GET["mi" . $pc] = Encoding::Base64UrlEncode($id);
                 $_GET["mc" . $pc++] = Encoding::Base64UrlEncode($postar[1]);
                 DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_POSTS . "` WHERE `id`='" . DBManager::RealEscape($id) . "' LIMIT 1;");
             }
             $pc = 0;
             $USER->Browsers[0]->QueuedPosts = array();
         }
     }
     $this->OverlayHTML = "";
     if (!empty($_GET["mi" . $pc]) || $USER->Browsers[0]->Waiting || !empty($USER->Browsers[0]->InitChatWith) || !empty($USER->Browsers[0]->Forward) && !$USER->Browsers[0]->Forward->Received && $USER->Browsers[0]->Forward->Processed) {
         if ($USER->Browsers[0]->Waiting && $this->Botmode && !empty($USER->Browsers[0]->QueuedPosts)) {
             $USER->Browsers[0]->QueuedPosts = array();
         } else {
             if (!Visitor::$OpenChatExternal) {
                 $this->Init();
             }
         }
         if (!empty($USER->Browsers[0]->Forward) && !$USER->Browsers[0]->Forward->Received && $USER->Browsers[0]->Forward->Processed) {
             $USER->Browsers[0]->Forward->Save(true, true);
             Visitor::$IsActiveOverlayChat = !$USER->Browsers[0]->Declined;
         }
     }
     if (!empty($USER->Browsers[0]->ChatId)) {
         $USER->AddFunctionCall("lz_chat_id='" . $USER->Browsers[0]->ChatId . "';", false);
     }
     $USER->Browsers[0]->VisitId = $USER->VisitId;
     while (!empty($_GET["mi" . $pc])) {
         $id = Communication::ReadParameter("mrid" . $pc, md5($USER->Browsers[0]->SystemId . $USER->Browsers[0]->ChatId . $_GET["mi" . $pc]));
         $senderName = !empty($USER->Browsers[0]->UserData->Fullname) ? $USER->Browsers[0]->UserData->Fullname : LocalizationManager::$TranslationStrings["client_guest"] . " " . Visitor::GetNoName($USER->UserId . Communication::GetIP());
         $post = new Post($id, $USER->Browsers[0]->SystemId, "", Encoding::Base64UrlDecode($_GET["mp" . $pc]), Communication::ReadParameter("mc" . $pc, time()), $USER->Browsers[0]->ChatId, $senderName);
         $post->BrowserId = VisitorMonitoring::$Browser->BrowserId;
         if (!empty($_GET["mpti" . $pc])) {
             $post->Translation = Encoding::Base64UrlDecode($_GET["mpt" . $pc]);
             $post->TranslationISO = Encoding::Base64UrlDecode($_GET["mpti" . $pc]);
         }
         $saved = false;
         if (!$USER->Browsers[0]->Waiting) {
             foreach (Server::$Groups as $groupid => $group) {
                 if ($group->IsDynamic && $USER->Browsers[0]->Status == CHAT_STATUS_ACTIVE && isset($group->Members[$USER->Browsers[0]->SystemId])) {
                     foreach ($group->Members as $member => $persistent) {
                         if ($member != $USER->Browsers[0]->SystemId) {
                             if (!empty(Server::$Operators[$member])) {
                                 processPost($id, $post, $member, $pc, $groupid, $USER->Browsers[0]->ChatId);
                             } else {
                                 processPost($id, $post, $member, $pc, $groupid, CacheManager::GetValueBySystemId($member, "chat_id", ""));
                             }
                             $saved = true;
                         }
                     }
                     $pGroup = $group;
                 }
             }
             foreach ($USER->Browsers[0]->Members as $systemid => $member) {
                 if (!empty($member->Declined)) {
                     continue;
                 }
                 if (!empty(Server::$Operators[$systemid]) && !empty($pGroup) && isset($pGroup->Members[$systemid])) {
                     continue;
                 }
                 if (!(!empty($pGroup) && !empty(Server::$Operators[$systemid]))) {
                     $saved = processPost($id, $post, $systemid, $pc, $USER->Browsers[0]->SystemId, $USER->Browsers[0]->ChatId, Server::$Operators[$systemid]->IsBot);
                 }
             }
             if (!empty($USER->Browsers[0]->OperatorId) && (Server::$Operators[$USER->Browsers[0]->OperatorId]->IsBot || $USER->Browsers[0]->Status == CHAT_STATUS_ACTIVE)) {
                 $rpost = new Post($id = getId(32), Server::$Operators[$USER->Browsers[0]->OperatorId]->SystemId, $USER->Browsers[0]->SystemId, $answer = Server::$Operators[$USER->Browsers[0]->OperatorId]->GetAutoReplies($post->Text . " " . $post->Translation, $USER->Browsers[0]), time(), $USER->Browsers[0]->ChatId, Server::$Operators[$USER->Browsers[0]->OperatorId]->Fullname);
                 if (!empty($answer)) {
                     if (Server::$Operators[$USER->Browsers[0]->OperatorId]->IsBot) {
                         sleep(1);
                         $USER->AddFunctionCall("lz_chat_input_bot_state(true,false);", false);
                     }
                     $rpost->ReceiverOriginal = $rpost->ReceiverGroup = $USER->Browsers[0]->SystemId;
                     $rpost->Save();
                     $saved = true;
                     foreach ($USER->Browsers[0]->Members as $opsysid => $member) {
                         if ($opsysid != Server::$Operators[$USER->Browsers[0]->OperatorId]->SystemId || !Server::$Operators[$USER->Browsers[0]->OperatorId]->IsBot) {
                             $rpost = new Post($id, Server::$Operators[$USER->Browsers[0]->OperatorId]->SystemId, $opsysid, $answer, time(), $USER->Browsers[0]->ChatId, Server::$Operators[$opsysid]->Fullname);
                             $rpost->ReceiverOriginal = $rpost->ReceiverGroup = $USER->Browsers[0]->SystemId;
                             $rpost->Save();
                         }
                     }
                 }
             }
             if ($saved) {
                 $USER->AddFunctionCall("lz_chat_release_post('" . Encoding::Base64UrlDecode($_GET["mi" . $pc]) . "');", false);
             }
         } else {
             processPost($id, $post, "", $pc, $USER->Browsers[0]->SystemId, $USER->Browsers[0]->ChatId, false);
             $USER->Browsers[0]->QueuedPosts[$id] = array(0 => $_GET["mp" . $pc], 1 => time(), 2 => VisitorMonitoring::$Browser->BrowserId);
             $USER->AddFunctionCall("lz_chat_release_post('" . Encoding::Base64UrlDecode($_GET["mi" . $pc]) . "');", false);
         }
         $pc++;
     }
     if (!empty($USER->Browsers[0]->OperatorId) && empty($pc) && !Server::$Operators[$USER->Browsers[0]->OperatorId]->IsBot) {
         $autoReply = Server::$Operators[$USER->Browsers[0]->OperatorId]->GetAutoReplies("", $USER->Browsers[0]);
         if (!empty($autoReply)) {
             ChatAutoReply::SendAutoReply($autoReply, $USER, $USER->Browsers[0]->OperatorId);
         }
     }
 }
Esempio n. 3
0
         $USER->Browsers[0]->ExternalClose();
         $USER->Browsers[0]->DesiredChatGroup = $USER->Browsers[0]->Forward->TargetGroupId;
         $USER->Browsers[0]->DesiredChatPartner = $USER->Browsers[0]->Forward->TargetSessId;
         $USER->Browsers[0]->FirstActive = time();
         $USER->Browsers[0]->Save(true);
         $USER->Browsers[0]->SetCookieGroup();
         $OVERLAY->SetHost(null);
     }
     if (!empty(Server::$Operators[$USER->Browsers[0]->Forward->SenderSystemId]) && $USER->Browsers[0]->InternalActivation) {
         if (!empty($USER->Browsers[0]->OperatorId) && Server::$Operators[$USER->Browsers[0]->OperatorId]->IsBot) {
             $USER->AddFunctionCall("lz_chat_set_talk_to_human(true,true);", false);
         } else {
             $OVERLAY->AddHTML($OVERLAY->GetLeaveChatHTML(true, Server::$Operators[$USER->Browsers[0]->Forward->SenderSystemId]->Fullname, " " . LocalizationManager::$TranslationStrings["client_forwarding"]), "sys", "");
         }
     }
     Visitor::$IsActiveOverlayChat = !$USER->Browsers[0]->Declined;
 } else {
     if ($OVERLAY->IsChatAvailable && (empty($USER->Browsers[0]->Forward) && !(!empty($USER->Browsers[1]->ChatRequest) && !$USER->Browsers[1]->ChatRequest->Closed) && empty($USER->Browsers[0]->OperatorId) && !$USER->Browsers[0]->Waiting || !empty($USER->Browsers[0]->OperatorId) && Server::$Operators[$USER->Browsers[0]->OperatorId]->IsBot && $OVERLAY->Flags["LMR"] == "ONM01" || $OVERLAY->FullLoad)) {
         if (($OVERLAY->Flags["LMR"] != "ONM01" || $OVERLAY->FullLoad) && (!$OVERLAY->Botmode || !empty($USER->Browsers[0]->OperatorId) && !Server::$Operators[$USER->Browsers[0]->OperatorId]->IsBot || !empty($USER->Browsers[1]->ChatRequest) && !$USER->Browsers[1]->ChatRequest->Closed)) {
             if (!$OVERLAY->Botmode && (!empty($USER->Browsers[0]->ChatId) && !$USER->Browsers[0]->InternalActivation && !$USER->Browsers[0]->Closed && !$USER->Browsers[0]->Declined && !$USER->Browsers[0]->Waiting)) {
                 $OVERLAY->AddHTML(str_replace("<!--message-->", LocalizationManager::$TranslationStrings["client_int_is_connected"], IOStruct::GetFile(TEMPLATE_HTML_MESSAGE_OVERLAY_CHAT_STATUS)), "sys", "ONM01");
             } else {
                 if ($USER->Browsers[0]->Status == CHAT_STATUS_OPEN && !$USER->Browsers[0]->Waiting) {
                     $OVERLAY->AddHTML(str_replace("<!--message-->", LocalizationManager::$TranslationStrings["client_chat_available"], IOStruct::GetFile(TEMPLATE_HTML_MESSAGE_OVERLAY_CHAT_STATUS)), "sys", "ONM01");
                 }
             }
             if (!empty($USER->Browsers[0]->ChatId) && !$USER->Browsers[0]->InternalActivation && !empty($USER->Browsers[0]->Forward) && !$USER->Browsers[0]->Forward->Invite && !empty($USER->Browsers[0]->Forward->TargetGroupId) && $USER->Browsers[0]->Forward->Processed) {
                 $OVERLAY->AddHTML(str_replace("<!--message-->", LocalizationManager::$TranslationStrings["client_forwarding"], IOStruct::GetFile(TEMPLATE_HTML_MESSAGE_OVERLAY_CHAT_STATUS)), "sys", "ONM01");
             }
         } else {
             if ($OVERLAY->Botmode && (($OVERLAY->Flags["LMR"] != "OBM01" || $OVERLAY->FullLoad) && (empty($USER->Browsers[0]->OperatorId) && empty($OVERLAY->CurrentOperatorId) || !empty($USER->Browsers[0]->OperatorId) && Server::$Operators[$USER->Browsers[0]->OperatorId]->IsBot))) {