function getInternal($desired = "", $util = 0, $fromCookie = null)
{
    global $CONFIG, $INTERNAL, $GROUPS, $USER, $INTLIST, $INTBUSY;
    $INTLIST = array();
    $INTBUSY = 0;
    $backup_target = null;
    $fromDepartment = $fromDepartmentBusy = false;
    if (!empty($USER->Browsers[0]->DesiredChatPartner) && isset($INTERNAL[$USER->Browsers[0]->DesiredChatPartner]) && $INTERNAL[$USER->Browsers[0]->DesiredChatPartner]->Status < USER_STATUS_OFFLINE) {
        if (!(!empty($USER->Browsers[0]->DesiredChatGroup) && !in_array($USER->Browsers[0]->DesiredChatGroup, $INTERNAL[$USER->Browsers[0]->DesiredChatPartner]->Groups))) {
            $desired = $USER->Browsers[0]->DesiredChatPartner;
        }
    } else {
        $USER->Browsers[0]->DesiredChatPartner = null;
        if (isset($_POST[POST_EXTERN_REQUESTED_INTERNID]) && !empty($_POST[POST_EXTERN_REQUESTED_INTERNID])) {
            $desired = getInternalSystemIdByUserId(AJAXDecode($_POST[POST_EXTERN_REQUESTED_INTERNID]));
        } else {
            if (!isnull(getCookieValue("internal_user")) && !empty($CONFIG["gl_save_op"])) {
                $desired = getInternalSystemIdByUserId(getCookieValue("internal_user"));
                if (!(!empty($USER->Browsers[0]->DesiredChatGroup) && !in_array($USER->Browsers[0]->DesiredChatGroup, $INTERNAL[$desired]->Groups))) {
                    $fromCookie = $desired;
                } else {
                    $desired = "";
                }
            }
        }
    }
    foreach ($GROUPS as $id => $group) {
        $utilization[$id] = 0;
    }
    foreach ($INTERNAL as $sessId => $internal) {
        if ($internal->LastActive > time() - $CONFIG["timeout_clients"]) {
            $group_chats[$sessId] = $internal->GetExternalChatAmount();
            $group_names[$sessId] = $internal->Fullname;
            $group_available[$sessId] = GROUP_STATUS_UNAVAILABLE;
            if (in_array($USER->Browsers[0]->DesiredChatGroup, $internal->Groups)) {
                if ($internal->Status == USER_STATUS_ONLINE && $internal->LastChatAllocation < time() - $CONFIG["poll_frequency_clients"] * 3) {
                    $group_available[$sessId] = GROUP_STATUS_AVAILABLE;
                } elseif ($internal->Status == USER_STATUS_BUSY || $internal->LastChatAllocation >= time() - $CONFIG["poll_frequency_clients"] * 3) {
                    $group_available[$sessId] = GROUP_STATUS_BUSY;
                    $INTBUSY++;
                    if (empty($fromCookie) && $desired == $sessId) {
                        return;
                    }
                }
            } else {
                if ($internal->Status == USER_STATUS_ONLINE) {
                    $backup_target = $internal;
                } else {
                    if ($internal->Status == USER_STATUS_BUSY && empty($backup_target)) {
                        $backup_target = $internal;
                    }
                }
                if (!empty($USER->Browsers[0]->DesiredChatPartner) && $USER->Browsers[0]->DesiredChatPartner == $sessId) {
                    $USER->Browsers[0]->DesiredChatPartner = null;
                }
            }
            for ($count = 0; $count < count($internal->Groups); $count++) {
                if ($USER->Browsers[0]->DesiredChatGroup == $internal->Groups[$count]) {
                    if (!is_array($utilization[$internal->Groups[$count]])) {
                        $utilization[$internal->Groups[$count]] = array();
                    }
                    if ($group_available[$sessId] == GROUP_STATUS_AVAILABLE) {
                        $utilization[$internal->Groups[$count]][$sessId] = $group_chats[$sessId];
                    }
                }
            }
        }
    }
    if (isset($utilization[$USER->Browsers[0]->DesiredChatGroup]) && is_array($utilization[$USER->Browsers[0]->DesiredChatGroup])) {
        arsort($utilization[$USER->Browsers[0]->DesiredChatGroup]);
        reset($utilization[$USER->Browsers[0]->DesiredChatGroup]);
        $util = end($utilization[$USER->Browsers[0]->DesiredChatGroup]);
        $INTLIST = $utilization[$USER->Browsers[0]->DesiredChatGroup];
    }
    if (isset($group_available) && is_array($group_available) && in_array(GROUP_STATUS_AVAILABLE, $group_available)) {
        $fromDepartment = true;
    } elseif (isset($group_available) && is_array($group_available) && in_array(GROUP_STATUS_BUSY, $group_available)) {
        $fromDepartmentBusy = true;
    }
    if (isset($group_chats) && is_array($group_chats) && isset($fromDepartment) && $fromDepartment) {
        foreach ($group_chats as $sessId => $amount) {
            if ($group_available[$sessId] == GROUP_STATUS_AVAILABLE && $amount <= $util || !empty($USER->Browsers[0]->Forward) && $USER->Browsers[0]->Forward->Processed && isset($desired) && $sessId == $desired) {
                $available_internals[] = $sessId;
            }
        }
    }
    if ($fromDepartment && sizeof($available_internals) > 0) {
        if (is_array($available_internals)) {
            if (!empty($desired) && (in_array($desired, $available_internals) || $INTERNAL[$desired]->Status == USER_STATUS_ONLINE)) {
                $matching_internal = $desired;
            } else {
                if (!isnull($inv_sender = $USER->Browsers[0]->GetLastInvitationSender()) && in_array($inv_sender, $available_internals)) {
                    $matching_internal = $inv_sender;
                } else {
                    $matching_internal = array_rand($available_internals, 1);
                    $matching_internal = $available_internals[$matching_internal];
                }
            }
        }
        if ($CONFIG["gl_alloc_mode"] != ALLOCATION_MODE_ALL || $fromCookie == $matching_internal) {
            $USER->Browsers[0]->DesiredChatPartner = $matching_internal;
        }
    } elseif ($fromDepartmentBusy) {
        if (!$USER->Browsers[0]->Waiting) {
            $USER->Browsers[0]->Waiting = true;
        }
    } else {
        $USER->AddFunctionCall("lz_chat_add_system_text(8,null);", false);
        $USER->AddFunctionCall("lz_chat_stop_system();", false);
        $USER->Browsers[0]->CloseChat(3);
        $INTLIST = null;
    }
}
 function SetChatId()
 {
     if (isset($_POST[POST_EXTERN_CHAT_ID]) && $this->Status != CHAT_STATUS_OPEN) {
         $this->ChatId = AJAXDecode($_POST[POST_EXTERN_CHAT_ID]);
     } else {
         $result = queryDB(true, "SELECT `chat_id` FROM `" . DB_PREFIX . DATABASE_INFO . "`");
         $row = mysql_fetch_array($result, MYSQL_BOTH);
         $cid = $row["chat_id"] + 1;
         queryDB(true, "UPDATE `" . DB_PREFIX . DATABASE_INFO . "` SET `chat_id`='" . @mysql_real_escape_string($cid) . "' WHERE `chat_id`='" . @mysql_real_escape_string($row["chat_id"]) . "'");
         if (mysql_affected_rows() == 0) {
             $this->ChatId = $this->SetChatId();
             return;
         } else {
             $this->ChatId = $cid;
         }
     }
     $this->FirstActive = time();
     queryDB(true, "UPDATE `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` SET `last_active`='" . @mysql_real_escape_string(time()) . "',`first_active`='" . @mysql_real_escape_string(time()) . "',`chat_id`='" . @mysql_real_escape_string($this->ChatId) . "' WHERE `exit`=0 AND `visitor_id`='" . @mysql_real_escape_string($this->UserId) . "' AND `browser_id`='" . @mysql_real_escape_string($this->BrowserId) . "' ORDER BY `first_active` DESC LIMIT 1;");
     return $this->ChatId;
 }
예제 #3
0
파일: extern.php 프로젝트: afzet/cake-cart
     $externalUser->Browsers[0]->Load();
 }
 $externalUser->ExternalStatic->Language = getServerParam("HTTP_ACCEPT_LANGUAGE") != null ? getServerParam("HTTP_ACCEPT_LANGUAGE") : "";
 $externalUser->Browsers[0]->LoadChat($CONFIG, null);
 if ($_POST[POST_EXTERN_SERVER_ACTION] == EXTERN_ACTION_LISTEN) {
     $externalUser = listen($externalUser);
 } else {
     if ($_POST[POST_EXTERN_SERVER_ACTION] == EXTERN_ACTION_MAIL) {
         getData(false, true, false, false);
         if ($externalUser->SaveTicket(AJAXDecode($_POST[POST_EXTERN_USER_GROUP])) && ($CONFIG["gl_scom"] != null || $CONFIG["gl_sgom"] != null)) {
             $externalUser->SendCopyOfMail(AJAXDecode($_POST[POST_EXTERN_USER_GROUP]), $CONFIG, $GROUPS);
         }
     } else {
         if ($_POST[POST_EXTERN_SERVER_ACTION] == EXTERN_ACTION_RATE) {
             getData(true, false, false, false);
             $externalUser->SaveRate(AJAXDecode($_POST[POST_EXTERN_REQUESTED_INTERNID]));
         } else {
             if ($externalUser->Browsers[0]->Chat != null) {
                 $externalUser->Browsers[0]->DestroyChatFiles();
                 $externalUser->Browsers[0]->Chat->ExternalDestroy();
             }
             unregisterChat(@$_POST[POST_EXTERN_CHAT_ID]);
             $externalUser->Browsers[0]->Waiting = false;
             $externalUser->Browsers[0]->WaitingMessageDisplayed = null;
             if ($_POST[POST_EXTERN_SERVER_ACTION] == EXTERN_ACTION_RELOAD_GROUPS) {
                 if (isset($_GET[GET_EXTERN_USER_NAME]) && !isnull($_GET[GET_EXTERN_USER_NAME])) {
                     $externalUser->Browsers[0]->Fullname = base64UrlDecode($_GET[GET_EXTERN_USER_NAME]);
                 }
                 if (isset($_GET[GET_EXTERN_USER_EMAIL]) && !isnull($_GET[GET_EXTERN_USER_EMAIL])) {
                     $externalUser->Browsers[0]->Email = base64UrlDecode($_GET[GET_EXTERN_USER_EMAIL]);
                 }
예제 #4
0
 function SaveRate($_internalId)
 {
     $rate = new Rating(time() . "_" . getIP());
     if (!$rate->IsFlood()) {
         $rate->RateComment = AJAXDecode($_POST[POST_EXTERN_RATE_COMMENT]);
         $rate->RatePoliteness = $_POST[POST_EXTERN_RATE_POLITENESS];
         $rate->RateQualification = $_POST[POST_EXTERN_RATE_QUALIFICATION];
         $rate->Fullname = AJAXDecode($_POST[POST_EXTERN_USER_NAME]);
         $rate->Email = AJAXDecode($_POST[POST_EXTERN_USER_EMAIL]);
         $rate->Company = AJAXDecode($_POST[POST_EXTERN_USER_COMPANY]);
         $rate->UserId = $_POST[POST_EXTERN_USER_USERID];
         $rate->InternId = $_internalId;
         saveRating($rate);
         $this->AddFunctionCall("lz_chat_send_rate_callback(true);", false);
     } else {
         $this->AddFunctionCall("lz_chat_send_rate_callback(false);", false);
     }
 }
예제 #5
0
                 if (isset($_GET[GET_EXTERN_USER_QUESTION]) && !empty($_GET[GET_EXTERN_USER_QUESTION])) {
                     $externalUser->Browsers[0]->Question = base64UrlDecode($_GET[GET_EXTERN_USER_QUESTION]);
                 }
                 $externalUser->Browsers[0]->Customs = getCustomArray();
                 $externalUser = reloadGroups($externalUser);
             } else {
                 $externalUser->Browsers[0]->CloseWindow();
                 exit;
             }
         }
     }
 }
 if (!isset($_POST[POST_EXTERN_RESOLUTION_WIDTH])) {
     $externalUser->KeepAlive();
 } else {
     $externalUser->Save($CONFIG, array(AJAXDecode($_POST[POST_EXTERN_RESOLUTION_WIDTH]), AJAXDecode($_POST[POST_EXTERN_RESOLUTION_HEIGHT])), AJAXDecode($_POST[POST_EXTERN_COLOR_DEPTH]), AJAXDecode($_POST[POST_EXTERN_TIMEZONE_OFFSET]), isset($_POST[GEO_LATITUDE]) ? AJAXDecode($_POST[GEO_LATITUDE]) : "", isset($_POST[GEO_LONGITUDE]) ? AJAXDecode($_POST[GEO_LONGITUDE]) : "", isset($_POST[GEO_COUNTRY_ISO_2]) ? AJAXDecode($_POST[GEO_COUNTRY_ISO_2]) : "", isset($_POST[GEO_CITY]) ? AJAXDecode($_POST[GEO_CITY]) : "", isset($_POST[GEO_REGION]) ? AJAXDecode($_POST[GEO_REGION]) : "", isset($_POST[GEO_TIMEZONE]) ? AJAXDecode($_POST[GEO_TIMEZONE]) : "", isset($_POST[GEO_ISP]) ? AJAXDecode($_POST[GEO_ISP]) : "", isset($_POST[GEO_SSPAN]) ? AJAXDecode($_POST[GEO_SSPAN]) : "", isset($_POST[GEO_RESULT_ID]) ? AJAXDecode($_POST[GEO_RESULT_ID]) : "");
 }
 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 = base64UrlDecode($_GET[GET_TRACK_SPECIAL_AREA_CODE]);
     }
     if (IS_FILTERED) {
         $externalUser->Browsers[0]->CloseChat(8);
     } else {
         if (!$externalUser->Browsers[0]->Closed) {
             $externalUser->Browsers[0]->Save();
         }