function processAutoReplies($count = 0)
{
    while (isset($_POST["p_bfl_va_" . $count])) {
        queryDB(false, "DELETE FROM `" . DB_PREFIX . DATABASE_AUTO_REPLIES . "` WHERE `owner_id`='" . DBManager::RealEscape($_POST["p_bfl_va_" . $count]) . "';");
        $icount = 0;
        while (isset($_POST["p_bfl_vb_" . $count . "_" . $icount])) {
            $item = new ChatAutoReply($_POST["p_bfl_vb_" . $count . "_" . $icount], $_POST["p_bfl_vc_" . $count . "_" . $icount], $_POST["p_bfl_ve_" . $count . "_" . $icount], $_POST["p_bfl_vd_" . $count . "_" . $icount], $_POST["p_bfl_vf_" . $count . "_" . $icount], !empty($_POST["p_bfl_vg_" . $count . "_" . $icount]), $_POST["p_bfl_vh_" . $count . "_" . $icount], !empty($_POST["p_bfl_vi_" . $count . "_" . $icount]), !empty($_POST["p_bfl_vj_" . $count . "_" . $icount]), $_POST["p_bfl_vti_" . $count . "_" . $icount], $_POST["p_bfl_vte_" . $count . "_" . $icount], !empty($_POST["p_bfl_vcc_" . $count . "_" . $icount]), $_POST["p_bfl_vt_" . $count . "_" . $icount]);
            $item->Save($_POST["p_bfl_va_" . $count]);
            $icount++;
        }
        $count++;
    }
}
 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);
         }
     }
 }
 function GetAutoReplies($_question, $_chat)
 {
     global $DEFAULT_BROWSER_LANGUAGE, $GROUPS;
     $_question = str_replace(array("!", ",", ".", "?", "=", ")", "(", "-", "_", ":", "#", "~", "�"), "", strtolower($_question));
     $this->LoadAutoReplies();
     $GROUPS[$_chat->DesiredChatGroup]->LoadAutoReplies();
     $merged = array_merge($this->AutoReplies, $GROUPS[$_chat->DesiredChatGroup]->AutoReplies);
     $answers = ChatAutoReply::GetMatches($merged, $_question, $DEFAULT_BROWSER_LANGUAGE);
     if ($this->IsBot) {
         return $this->FormatBotAutoReplies($_chat, $answers);
     }
     return $this->FormatHumanAutoReplies($answers);
 }
function processAutoReplies($count = 0)
{
    while (isset($_POST["p_bfl_va_" . $count])) {
        DBManager::Execute(false, "DELETE FROM `" . DB_PREFIX . DATABASE_AUTO_REPLIES . "` WHERE `owner_id`='" . DBManager::RealEscape($_POST["p_bfl_va_" . $count]) . "';");
        $icount = 0;
        while (isset($_POST["p_bfl_vb_" . $count . "_" . $icount])) {
            $item = new ChatAutoReply($_POST["p_bfl_vb_" . $count . "_" . $icount], $_POST["p_bfl_vc_" . $count . "_" . $icount], $_POST["p_bfl_ve_" . $count . "_" . $icount], $_POST["p_bfl_vd_" . $count . "_" . $icount], $_POST["p_bfl_vf_" . $count . "_" . $icount], !empty($_POST["p_bfl_vg_" . $count . "_" . $icount]), $_POST["p_bfl_vh_" . $count . "_" . $icount], !empty($_POST["p_bfl_vi_" . $count . "_" . $icount]), !empty($_POST["p_bfl_vj_" . $count . "_" . $icount]), $_POST["p_bfl_vti_" . $count . "_" . $icount], $_POST["p_bfl_vte_" . $count . "_" . $icount], !empty($_POST["p_bfl_vcc_" . $count . "_" . $icount]), $_POST["p_bfl_vt_" . $count . "_" . $icount]);
            $item->Save($_POST["p_bfl_va_" . $count]);
            $icount++;
        }
        $count++;
    }
    if ($count > 0) {
        CacheManager::FlushKey(DATA_CACHE_KEY_OPERATORS);
    }
}
Пример #5
0
             }
         }
         if ($saved) {
             $USER->AddFunctionCall("lz_chat_release_post('" . 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 => $BROWSER->BrowserId);
         $USER->AddFunctionCall("lz_chat_release_post('" . base64UrlDecode($_GET["mi" . $pc]) . "');", false);
     }
     $pc++;
 }
 if (!empty($USER->Browsers[0]->InternalUser) && empty($pc) && !$USER->Browsers[0]->InternalUser->IsBot) {
     $autoReply = $USER->Browsers[0]->InternalUser->GetAutoReplies("", $USER->Browsers[0]);
     if (!empty($autoReply)) {
         ChatAutoReply::SendAutoReply($autoReply, $USER, $USER->Browsers[0]->InternalUser);
     }
 }
 $startTime = 0;
 $isOp = false;
 if ($USER->Browsers[0]->Status == CHAT_STATUS_ACTIVE) {
     $result = queryDB(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($INTERNAL[$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;
                 addHTML(str_replace("<!--message-->", str_replace("<!--intern_name-->", $INTERNAL[$ChatMember->SystemId]->Fullname, $LZLANG["client_intern_arrives"]), 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) {
                     addHTML(leaveChatHTML(false, $INTERNAL[$ChatMember->SystemId]->Fullname), "sys", "LCM01" . $ChatMember->SystemId);
 function GetAutoReplies($_question, $_chat)
 {
     $_question = str_replace(array("!", ",", ".", "?", "=", ")", "(", "-", "_", ":", "#", "~", "�"), "", strtolower($_question));
     $merged = array_merge($this->AutoReplies, Server::$Groups[$_chat->DesiredChatGroup]->AutoReplies);
     if ($this->IsBot) {
         $kbresults = KnowledgeBase::GetMatches($_question, Visitor::$BrowserLanguage, true);
         $merged = array_merge($merged, $kbresults);
     }
     $answers = ChatAutoReply::GetMatches($merged, $_question, Visitor::$BrowserLanguage, $_chat, $this);
     if ($this->IsBot) {
         return $this->FormatBotAutoReplies($_chat, $answers);
     } else {
         return $this->FormatHumanAutoReplies($answers, $_chat);
     }
 }
function processPosts($counter = 0)
{
    global $USER, $STATS, $GROUPS, $INTERNAL, $LZLANG;
    while (isset($_POST["p_p" . $counter])) {
        if (STATS_ACTIVE) {
            $STATS->ProcessAction(ST_ACTION_EXTERNAL_POST);
        }
        $id = md5($USER->Browsers[0]->SystemId . getOParam(POST_EXTERN_CHAT_ID, 0, $nu, FILTER_SANITIZE_NUMBER_INT) . base64UrlDecode($_POST["p_i" . $counter]));
        $senderName = !empty($USER->Browsers[0]->Fullname) ? $USER->Browsers[0]->Fullname : $LZLANG["client_guest"] . " " . getNoName($USER->UserId . getIP());
        $post = new Post($id, $USER->Browsers[0]->SystemId, "", base64UrlDecode($_POST["p_p" . $counter]), time(), $USER->Browsers[0]->ChatId, $senderName);
        foreach ($GROUPS as $groupid => $group) {
            if ($group->IsDynamic && isset($group->Members[$USER->Browsers[0]->SystemId])) {
                foreach ($group->Members as $member => $persistent) {
                    if ($member != $USER->Browsers[0]->SystemId) {
                        if (!empty($INTERNAL[$member])) {
                            processPost($id, $post, $member, $counter, $groupid, $USER->Browsers[0]->ChatId);
                        } else {
                            processPost($id, $post, $member, $counter, $groupid, getValueBySystemId($member, "chat_id", ""));
                        }
                    }
                }
                $pGroup = $group;
            }
        }
        foreach ($USER->Browsers[0]->Members as $systemid => $member) {
            if (!empty($member->Declined)) {
                continue;
            }
            if (!empty($INTERNAL[$systemid]) && isset($pGroup->Members[$systemid])) {
                continue;
            }
            if (!(!empty($pGroup) && !empty($INTERNAL[$systemid]))) {
                processPost($id, $post, $systemid, $counter, $USER->Browsers[0]->SystemId, $USER->Browsers[0]->ChatId);
            }
        }
        $autoReply = $USER->Browsers[0]->InternalUser->GetAutoReplies($post->Text, $USER->Browsers[0]);
        if (!empty($autoReply)) {
            ChatAutoReply::SendAutoReply($autoReply, $USER, $INTERNAL[$systemid]);
        }
        $USER->AddFunctionCall("lz_chat_release_post('" . base64UrlDecode($_POST["p_i" . $counter]) . "');", false);
        $counter++;
    }
    $counter = 0;
    while (isset($_POST["pr_i" . $counter])) {
        $post = new Post(base64UrlDecode($_POST["pr_i" . $counter]), "", "", "", "", "", "");
        $post->MarkReceived($USER->Browsers[0]->SystemId);
        $USER->AddFunctionCall("lz_chat_message_set_received('" . base64UrlDecode($_POST["pr_i" . $counter]) . "');", false);
        $counter++;
    }
}