function getDataUpdateTimes()
{
    global $DUT, $CM;
    if (!empty($CM) && $CM->GetData(118, $DUT)) {
        return;
    }
    $DUT = array(DATA_UPDATE_KEY_TICKETS => 0, DATA_UPDATE_KEY_EMAILS => 0, DATA_UPDATE_KEY_EVENTS => 0, DATA_UPDATE_KEY_CHATS => 0);
    if (DB_CONNECTION) {
        $result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_DATA_UPDATES . "`;");
        if ($result && ($row = DBManager::FetchArray($result))) {
            $DUT = array(DATA_UPDATE_KEY_TICKETS => $row[DATA_UPDATE_KEY_TICKETS], DATA_UPDATE_KEY_EMAILS => $row[DATA_UPDATE_KEY_EMAILS], DATA_UPDATE_KEY_EVENTS => $row[DATA_UPDATE_KEY_EVENTS], DATA_UPDATE_KEY_CHATS => $row[DATA_UPDATE_KEY_CHATS]);
        }
    }
    if (!empty($CM)) {
        $CM->SetData(118, $DUT);
    }
}
function buildExtern()
{
    Server::$Response->Tracking = "";
    $result = DBManager::Execute(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_CHAT_FORWARDS . "` WHERE `auto`=0 AND `closed`=0 AND `received`=0 ORDER BY `created` ASC;");
    while ($row = DBManager::FetchArray($result)) {
        $forward = new Forward($row);
        Server::$Response->Forwards .= $forward->GetXml();
        if (!empty(Server::$Visitors[$forward->ReceiverUserId]) && Server::$Visitors[$forward->ReceiverUserId]->GetBrowser($forward->ReceiverBrowserId) != null) {
            if (!$forward->Invite) {
                Server::$Visitors[$forward->ReceiverUserId]->GetBrowser($forward->ReceiverBrowserId)->Forward = $forward;
            } else {
                if (CALLER_SYSTEM_ID == $forward->TargetSessId) {
                    $forward->Save(true, true);
                }
            }
        }
    }
    $isex = !empty(Server::$Operators[CALLER_SYSTEM_ID]->Groups) && Server::$Groups[Server::$Operators[CALLER_SYSTEM_ID]->Groups[0]]->IsExternal;
    $builder = new ExternalXMLBuilder(Server::$Operators[CALLER_SYSTEM_ID], Server::$Visitors, NO_CLIPPING || isset($_POST[POST_INTERN_RESYNC]), $isex);
    $builder->SessionFileSizes = Server::$Operators[CALLER_SYSTEM_ID]->VisitorFileSizes;
    $builder->StaticReload = Server::$Operators[CALLER_SYSTEM_ID]->VisitorStaticReload;
    $base = array();
    $builder->SetDiscardedObject($base);
    $builder->Generate();
    Server::$Response->Tracking = $builder->XMLCurrent;
    foreach ($builder->DiscardedObjects as $uid => $list) {
        Server::$Response->Tracking .= "<cd id=\"" . base64_encode($uid) . "\">\r\n";
        if ($list != null) {
            foreach ($list as $bid) {
                Server::$Response->Tracking .= " <bd id=\"" . base64_encode($bid) . "\" />\r\n";
            }
        }
        Server::$Response->Tracking .= "</cd>\r\n";
    }
    Server::$Response->Typing .= $builder->XMLTyping;
    Server::$Operators[CALLER_SYSTEM_ID]->VisitorFileSizes = $builder->SessionFileSizes;
    Server::$Operators[CALLER_SYSTEM_ID]->VisitorStaticReload = $builder->StaticReload;
    if ($builder->GetAll && !LOGIN) {
        Server::$Response->Tracking .= "<resync />\r\n";
    }
    if (count(Server::$Visitors) == 0) {
        Server::$Operators[CALLER_SYSTEM_ID]->VisitorFileSizes = array();
    }
}
 function Update($_optional = true)
 {
     global $INTERNAL;
     if ($INTERNAL[CALLER_SYSTEM_ID]->GetPermission(PERMISSION_REPORTS) == PERMISSION_FULL) {
         if (!$_optional) {
             $result = queryDB(true, "SELECT `time` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS . "` WHERE `year`='" . DBManager::RealEscape($this->Year) . "' AND `month`='" . DBManager::RealEscape($this->Month) . "' AND `day`='" . DBManager::RealEscape($this->Day) . "' AND `aggregated`=0 LIMIT 1;");
         } else {
             if (is_numeric(StatisticProvider::$UpdateInterval)) {
                 $result = queryDB(true, "SELECT `time` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS . "` WHERE `year`='" . DBManager::RealEscape($this->Year) . "' AND `month`='" . DBManager::RealEscape($this->Month) . "' AND `day`='" . DBManager::RealEscape($this->Day) . "' AND `aggregated`=0 AND `time`<" . (time() - StatisticProvider::$UpdateInterval) . " LIMIT 1;");
             }
         }
         if ($result) {
             if ($row = DBManager::FetchArray($result)) {
                 if ($this->Type == STATISTIC_PERIOD_TYPE_DAY) {
                     $this->SaveVisitorListToFile();
                 }
                 $this->SaveReportToFile();
             } else {
                 if (@file_exists($this->GetFilename(true, false))) {
                     $result = queryDB(true, "SELECT `time`,`mtime` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS . "` WHERE `year`='" . DBManager::RealEscape($this->Year) . "' AND `month`='" . DBManager::RealEscape($this->Month) . "' AND `day`='" . DBManager::RealEscape($this->Day) . "' LIMIT 1;");
                     if ($result) {
                         if ($row = DBManager::FetchArray($result)) {
                             $parts = explode("_", $_POST[POST_INTERN_XMLCLIP_REPORTS_END_TIME]);
                             if ($parts[0] > $row["time"]) {
                                 $_POST[POST_INTERN_XMLCLIP_REPORTS_END_TIME] = $row["time"] . "_" . ($row["mtime"] - 1);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #4
0
function getFileById($_id, $_online, $_type)
{
    $result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_IMAGES . "` WHERE `id`='" . DBManager::RealEscape($_id) . "' AND `button_type`='" . DBManager::RealEscape($_type) . "' AND `online`='" . DBManager::RealEscape($_online ? "1" : "0") . "' LIMIT 1;");
    if ($row = DBManager::FetchArray($result)) {
        header("Content-Type: image/" . $row["image_type"] . ";");
        return base64_decode($row["data"]);
    } else {
        header("Content-Type: image/gif;");
        return file_get_contents(PATH_IMAGES . "chat_blank.gif");
    }
}
 public static function GetMatchingVoucher($_groupId, $_voucherid)
 {
     global $CONFIG, $GROUPS;
     initData(array("GROUPS"));
     $ticket = new CommercialChatVoucher("", $_voucherid);
     $ticket->Load();
     $result = queryDB(true, $d = "SELECT *,`t1`.`id` AS `voucherid`, SUM(`chat_time_max`) AS `chat_time_max`, SUM(`chat_time`) AS `chat_time`, SUM(`chat_sessions`) AS `chat_sessions`, SUM(`chat_sessions_max`) AS `chat_sessions_max`, MAX(`expires`) AS `expires` FROM `" . DB_PREFIX . DATABASE_COMMERCIAL_CHAT_VOUCHERS . "` AS `t1` INNER JOIN `" . DB_PREFIX . DATABASE_COMMERCIAL_CHAT_TYPES . "` AS `t2` ON `t1`.`tid`=`t2`.`id` WHERE `t1`.`id`='" . DBManager::RealEscape($_voucherid) . "' ORDER BY `created` ASC;");
     while ($row = @DBManager::FetchArray($result)) {
         if (!empty($CONFIG["db"]["cct"][$row["tid"]])) {
             $ticket = new CommercialChatVoucher($row);
             if (in_array($row["tid"], $GROUPS[$_groupId]->ChatVouchersRequired)) {
                 return $ticket;
             }
         }
     }
     return null;
 }
 static function Maintain($_randStandard, $_timeouts)
 {
     if (!Is::Defined("NO_DB_LOG")) {
         define("NO_DB_LOG", true);
     }
     if ($_randStandard == 1) {
         if (!STATS_ACTIVE) {
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITORS . "` WHERE `last_active`<" . DBManager::RealEscape(time() - Server::$Configuration->File["gl_dvhd"] * 86400) . ";");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_OPERATOR_STATUS . "` WHERE `" . DB_PREFIX . DATABASE_OPERATOR_STATUS . "`.`confirmed`<" . DBManager::RealEscape(time() - Server::$Configuration->File["gl_dvhd"] * 86400) . ";");
         } else {
             StatisticProvider::DeleteHTMLReports();
         }
         DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_TRIGGERS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITORS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_TRIGGERS . "`.`receiver_user_id`)");
         DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` WHERE (`html` = '0' OR `html` = '') AND `time` < " . DBManager::RealEscape(time() - $_timeouts[3]));
         DBManager::Execute(true, "UPDATE `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` SET `closed`='" . time() . "' WHERE `chat_type`<>1 AND `closed`<`endtime` AND `endtime`<" . (time() - 1800) . ";");
         DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` WHERE `closed`=0 AND `chat_type`=1 AND NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` WHERE `chat_id` = `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "`.`chat_id`)");
         DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_POSTS . "` WHERE `time` < " . DBManager::RealEscape(time() - $_timeouts[3]));
         DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_POSTS . "` WHERE `persistent` = '0' AND `time` < " . DBManager::RealEscape(time() - $_timeouts[1]));
         DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_POSTS . "` WHERE `repost` = '1' AND `time` < " . DBManager::RealEscape(time() - $_timeouts[0]));
         DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_OPERATOR_LOGINS . "` WHERE `time` < " . DBManager::RealEscape(time() - $_timeouts[1]));
         DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_ACTION_INTERNALS . "` WHERE `created` < " . DBManager::RealEscape(time() - $_timeouts[0]));
         DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_PROFILE_PICTURES . "` WHERE `webcam`=1 AND `time` < " . DBManager::RealEscape(time() - $_timeouts[0]));
         $clr = "";
         if (!empty(Server::$Configuration->File["gl_colt"])) {
             $clr = "`create` < " . intval(time() - Server::$Configuration->File["gl_colt"] * 86400) . " AND ";
         }
         DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_USER_DATA . "` WHERE " . $clr . "NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "` WHERE `data_id` = `" . DB_PREFIX . DATABASE_USER_DATA . "`.`id`) AND NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_FEEDBACKS . "` WHERE `data_id` = `" . DB_PREFIX . DATABASE_USER_DATA . "`.`id`);");
         DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_FEEDBACKS . "` WHERE `resource_id` != '' AND NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_RESOURCES . "` WHERE `id` = `" . DB_PREFIX . DATABASE_FEEDBACKS . "`.`resource_id`);");
     } else {
         if ($_randStandard == 2) {
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_ALERTS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITORS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_ALERTS . "`.`receiver_user_id`)");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_CHAT_FILES . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITORS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_CHAT_FILES . "`.`visitor_id`)");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_CHAT_FORWARDS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` WHERE `chat_id` = `" . DB_PREFIX . DATABASE_CHAT_FORWARDS . "`.`chat_id`)");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_CHAT_REQUESTS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_CHAT_REQUESTS . "`.`receiver_browser_id`)");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_GOALS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_GOALS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_STATS_AGGS_GOALS . "`.`goal`)");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_PAGES . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_PAGES . "` WHERE `id` = `" . DB_PREFIX . DATABASE_STATS_AGGS_PAGES . "`.`url`)");
             DBManager::Execute(true, "DELETE `" . DB_PREFIX . DATABASE_TICKETS . "` FROM `" . DB_PREFIX . DATABASE_TICKETS . "` INNER JOIN `" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "` ON `" . DB_PREFIX . DATABASE_TICKETS . "`.`id`=`" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "`.`ticket_id` WHERE `deleted`=1 AND `time` < " . DBManager::RealEscape(time() - $_timeouts[3]) . ";");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_TICKET_CUSTOMS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_TICKETS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_TICKET_CUSTOMS . "`.`ticket_id`)");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_TICKET_EDITORS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_TICKETS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_TICKET_EDITORS . "`.`ticket_id`)");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_TICKET_LOGS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_TICKETS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_TICKET_LOGS . "`.`ticket_id`)");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_TICKET_COMMENTS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_TICKETS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_TICKET_COMMENTS . "`.`ticket_id`)");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_TICKETS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "`.`ticket_id`)");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_TICKETS . "` WHERE `last_update` < " . DBManager::RealEscape(time() - $_timeouts[1]) . " AND NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "` WHERE `ticket_id` = `" . DB_PREFIX . DATABASE_TICKETS . "`.`id`)");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_TICKET_ATTACHMENTS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "` WHERE `id` = `" . DB_PREFIX . DATABASE_TICKET_ATTACHMENTS . "`.`parent_id`) AND NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_TICKET_EMAILS . "` WHERE `email_id` = `" . DB_PREFIX . DATABASE_TICKET_ATTACHMENTS . "`.`parent_id`)");
         } else {
             if ($_randStandard == 3) {
                 if (empty(Server::$Configuration->File["gl_vmac"]) && !Is::Defined("STATS_ACTIVE")) {
                     DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITORS . "` WHERE `last_active`<" . (time() - Server::$Configuration->File["timeout_track"]) . " LIMIT 250;");
                 }
                 DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITORS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "`.`visitor_id`)");
                 DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITOR_BROWSER_URLS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_VISITOR_BROWSER_URLS . "`.`browser_id`)");
                 DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITORS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "`.`visitor_id`)");
                 DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITOR_CHAT_OPERATORS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` WHERE `chat_id` = `" . DB_PREFIX . DATABASE_VISITOR_CHAT_OPERATORS . "`.`chat_id`)");
                 DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITOR_GOALS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITORS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_VISITOR_GOALS . "`.`visitor_id`)");
                 DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_WEBSITE_PUSHS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_WEBSITE_PUSHS . "`.`receiver_browser_id`)");
                 DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_OVERLAY_BOXES . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_OVERLAY_BOXES . "`.`receiver_browser_id`)");
                 DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_GROUP_MEMBERS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_GROUPS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_GROUP_MEMBERS . "`.`group_id`)");
                 DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_COMMERCIAL_CHAT_LOCALIZATIONS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_COMMERCIAL_CHAT_TYPES . "` WHERE `id` = `" . DB_PREFIX . DATABASE_COMMERCIAL_CHAT_LOCALIZATIONS . "`.`tid`)");
                 DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_COMMERCIAL_CHAT_VOUCHERS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_COMMERCIAL_CHAT_TYPES . "` WHERE `id` = `" . DB_PREFIX . DATABASE_COMMERCIAL_CHAT_VOUCHERS . "`.`tid`)");
                 DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_TICKET_EMAILS . "` WHERE `deleted`=1 AND `edited` < " . DBManager::RealEscape(time() - $_timeouts[3]));
                 DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITOR_COMMENTS . "` WHERE `created` < " . DBManager::RealEscape(time() - max(1, Server::$Configuration->File["gl_colt"]) * 86400));
             } else {
                 if ($_randStandard == 4) {
                     DBManager::Execute(true, "UPDATE `" . DB_PREFIX . DATABASE_RESOURCES . "` SET `discarded`=1,`edited`=UNIX_TIMESTAMP() WHERE NOT EXISTS(SELECT * FROM `" . DB_PREFIX . DATABASE_TICKET_ATTACHMENTS . "` WHERE `res_id` = `" . DB_PREFIX . DATABASE_RESOURCES . "`.`id`) AND `created` < " . intval(time() - 7 * 86400) . " AND `discarded`=0 AND `type`=3 AND `parentid`=100 LIMIT 10;");
                     if (Server::$Configuration->File["gl_adct"] != 1) {
                         if (!empty(Server::$Configuration->File["gl_rm_chats"])) {
                             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` WHERE `chat_type`=1 AND `time` < " . intval(time() - Server::$Configuration->File["gl_rm_chats_time"]));
                         }
                         if (!empty(Server::$Configuration->File["gl_rm_oc"])) {
                             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` WHERE `chat_type`=0 AND `time` < " . intval(time() - Server::$Configuration->File["gl_rm_oc_time"]));
                         }
                         if (!empty(Server::$Configuration->File["gl_rm_gc"])) {
                             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` WHERE `chat_type`=2 AND `time` < " . intval(time() - Server::$Configuration->File["gl_rm_gc_time"]));
                         }
                         if (!empty(Server::$Configuration->File["gl_rm_rt"])) {
                             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_FEEDBACKS . "` WHERE `created` < " . intval(time() - Server::$Configuration->File["gl_rm_rt_time"]));
                             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_FEEDBACK_CRITERIA . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_FEEDBACKS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_FEEDBACK_CRITERIA . "`.`fid`)");
                         }
                         if (!empty(Server::$Configuration->File["gl_rm_cf"])) {
                             DBManager::Execute(true, "UPDATE `" . DB_PREFIX . DATABASE_RESOURCES . "` SET `discarded`=1,`edited`=UNIX_TIMESTAMP() WHERE `discarded`=0 AND `type`=4 AND `created` < " . intval(time() - Server::$Configuration->File["gl_rm_cf_time"]) . " ORDER BY `created` ASC LIMIT 5;");
                             if (!empty(Server::$Operators)) {
                                 foreach (Server::$Operators as $sid => $operator) {
                                     if (!$operator->IsBot) {
                                         DBManager::Execute(true, "UPDATE `" . DB_PREFIX . DATABASE_RESOURCES . "` SET `discarded`=1,`edited`=UNIX_TIMESTAMP() WHERE `discarded`=0 AND `type`=3 AND `parentid`='" . DBManager::RealEscape($sid) . "' AND `created` < " . intval(time() - Server::$Configuration->File["gl_rm_cf_time"]) . " ORDER BY `created` ASC LIMIT 5;");
                                     }
                                 }
                             }
                             DBManager::Execute(true, "UPDATE `" . DB_PREFIX . DATABASE_RESOURCES . "` SET `discarded`=1,`edited`=UNIX_TIMESTAMP() WHERE `discarded`=0 AND `type`=0 AND `parentid`=5 AND `created` < " . intval(time() - Server::$Configuration->File["gl_rm_cf_time"]) . " ORDER BY `created` ASC LIMIT 5;");
                         }
                         if (!empty(Server::$Configuration->File["gl_rm_tf"])) {
                             DBManager::Execute(true, "UPDATE `" . DB_PREFIX . DATABASE_RESOURCES . "` SET `discarded`=1,`edited`=UNIX_TIMESTAMP() WHERE `discarded`=0 AND `type`=3 AND `created` < " . intval(time() - Server::$Configuration->File["gl_rm_tf_time"]) . " ORDER BY `created` ASC LIMIT 5;");
                         }
                         if (!empty(Server::$Configuration->File["gl_rm_om"])) {
                             DBManager::Execute(true, "DELETE `" . DB_PREFIX . DATABASE_TICKETS . "` FROM `" . DB_PREFIX . DATABASE_TICKETS . "` INNER JOIN `" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "` ON `" . DB_PREFIX . DATABASE_TICKETS . "`.`id`=`" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "`.`ticket_id` WHERE `" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "`.`time` < " . DBManager::RealEscape(time() - Server::$Configuration->File["gl_rm_om_time"]));
                         }
                         if (!empty(Server::$Configuration->File["gl_rm_tid"])) {
                             DBManager::Execute(true, "DELETE `" . DB_PREFIX . DATABASE_TICKETS . "` FROM `" . DB_PREFIX . DATABASE_TICKETS . "` INNER JOIN `" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "` ON `" . DB_PREFIX . DATABASE_TICKETS . "`.`id`=`" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "`.`ticket_id` INNER JOIN `" . DB_PREFIX . DATABASE_TICKET_EDITORS . "` ON `" . DB_PREFIX . DATABASE_TICKETS . "`.`id`=`" . DB_PREFIX . DATABASE_TICKET_EDITORS . "`.`ticket_id` WHERE `" . DB_PREFIX . DATABASE_TICKET_EDITORS . "`.`status`=3 AND `" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "`.`time` < " . DBManager::RealEscape(time() - Server::$Configuration->File["gl_rm_tid_time"]));
                         }
                         if (!empty(Server::$Operators) && !empty(Server::$Configuration->File["gl_rm_bc"])) {
                             foreach (Server::$Operators as $sid => $operator) {
                                 if ($operator->IsBot) {
                                     DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` WHERE `chat_type`=1 AND `internal_id`='" . DBManager::RealEscape($sid) . "' AND `time` < " . DBManager::RealEscape(time() - Server::$Configuration->File["gl_rm_bc_time"]));
                                 }
                             }
                         }
                     }
                     if ($result = DBManager::Execute(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_RESOURCES . "` WHERE `discarded`=1 AND `type` > 2")) {
                         while ($result && ($row = DBManager::FetchArray($result))) {
                             $resultb = DBManager::Execute(true, "SELECT count(value) as `linked` FROM `" . DB_PREFIX . DATABASE_RESOURCES . "` WHERE `value`='" . DBManager::RealEscape($row["value"]) . "';");
                             $rowb = DBManager::FetchArray($resultb);
                             if ($rowb["linked"] == 1) {
                                 @unlink(PATH_UPLOADS . $row["value"]);
                             }
                         }
                     }
                     DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_RESOURCES . "` WHERE `discarded`='1' AND `edited` < " . DBManager::RealEscape(time() - $_timeouts[3]));
                 }
             }
         }
     }
 }
function up_5402_6000($_prefix, $_link, $_engine)
{
    $commands[] = array(1060, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "resources` ADD `languages` VARCHAR( 32 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',ADD `kb_public` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',ADD `kb_bot` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',ADD `kb_ft_search` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',ADD INDEX ( `languages` , `kb_public` ) ");
    $commands[] = array(1060, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "resources` ADD `shortcut_word` VARCHAR( 32 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '';");
    $commands[] = array(1060, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "visitor_browsers` ADD `data_id` VARCHAR( 32 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' AFTER `visit_id`;");
    $commands[] = array(1054, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "data_updates` CHANGE `update_ratings` `update_feedbacks` BIGINT( 20 ) UNSIGNED NOT NULL DEFAULT '0';");
    $commands[] = array(1060, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "administration_log` ADD `trace` TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL AFTER `value`;");
    $commands[] = array(1060, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "events` ADD `exclude_mobile` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';");
    $commands[] = array(1060, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "events` ADD `exclude_countries` VARCHAR( 128 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '';");
    $commands[] = array(1050, "CREATE TABLE IF NOT EXISTS `" . DBManager::RealEscape($_prefix) . "user_data` (`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',`create` int(10) unsigned NOT NULL DEFAULT '0',`h_fullname` varchar(254) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',`h_email` varchar(254) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',`h_company` varchar(254) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',`h_phone` varchar(254) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',`h_customs` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,`h_text` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,PRIMARY KEY (`id`)) ENGINE=" . $_engine . " DEFAULT CHARSET=utf8 COLLATE=utf8_bin;");
    $commands[] = array(1050, "CREATE TABLE IF NOT EXISTS `" . DBManager::RealEscape($_prefix) . "feedbacks` (`id` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`created` int(10) unsigned NOT NULL DEFAULT '0',`chat_id` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`ticket_id` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`resource_id` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`user_id` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`operator_id` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`group_id` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`data_id` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`ip_hash` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',PRIMARY KEY (`id`)) ENGINE=" . $_engine . " DEFAULT CHARSET=utf8 COLLATE=utf8_bin;");
    $commands[] = array(1050, "CREATE TABLE IF NOT EXISTS `" . DBManager::RealEscape($_prefix) . "feedback_criteria` (`fid` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`cid` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`value` varchar(512) COLLATE utf8_bin NOT NULL DEFAULT '',PRIMARY KEY (`fid`,`cid`)) ENGINE=" . $_engine . " DEFAULT CHARSET=utf8 COLLATE=utf8_bin;");
    $commands[] = array(1050, "CREATE TABLE IF NOT EXISTS `" . DBManager::RealEscape($_prefix) . "feedback_criteria_config` (`id` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`type` tinyint(1) unsigned NOT NULL DEFAULT '0',`name` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`title` varchar(128) COLLATE utf8_bin NOT NULL DEFAULT '',PRIMARY KEY (`id`)) ENGINE=" . $_engine . " DEFAULT CHARSET=utf8 COLLATE=utf8_bin;");
    $commands[] = array(1050, "CREATE TABLE IF NOT EXISTS `" . DBManager::RealEscape($_prefix) . "stats_aggs_feedbacks` (`year` smallint(5) unsigned NOT NULL DEFAULT '0',`month` tinyint(3) unsigned NOT NULL DEFAULT '0',`day` tinyint(3) unsigned NOT NULL DEFAULT '0',`operator_id` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`group_id` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',`amount` int(10) unsigned NOT NULL DEFAULT '0',`ca` double unsigned NOT NULL DEFAULT '0',`cb` double unsigned NOT NULL DEFAULT '0',`cc` double unsigned NOT NULL DEFAULT '0',`cd` double unsigned NOT NULL DEFAULT '0',PRIMARY KEY (`year`,`month`,`day`,`operator_id`,`group_id`)) ENGINE=" . $_engine . " DEFAULT CHARSET=utf8 COLLATE=utf8_bin;");
    $commands[] = array(1091, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "resources` DROP `rank`;");
    $commands[] = array(1091, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "visitor_chats` DROP `fullname`;");
    $commands[] = array(1091, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "visitor_chats` DROP `email`;");
    $commands[] = array(1091, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "visitor_chats` DROP `company`;");
    $commands[] = array(1091, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "visitor_chats` DROP `phone`;");
    $commands[] = array(1091, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "visitor_chats` DROP `customs`;");
    $commands[] = array(1091, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "visitor_chats` DROP `question`;");
    $commands[] = array(1091, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "visitor_browsers` DROP `fullname`;");
    $commands[] = array(1091, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "visitor_browsers` DROP `email`;");
    $commands[] = array(1091, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "visitor_browsers` DROP `company`;");
    $commands[] = array(1091, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "visitor_browsers` DROP `phone`;");
    $commands[] = array(1091, "ALTER TABLE `" . DBManager::RealEscape($_prefix) . "visitor_browsers` DROP `customs`;");
    $res = processCommandList($commands, $_link);
    // import ratings
    $_link->Query(true, "INSERT INTO `" . DBManager::RealEscape($_prefix) . "feedback_criteria_config` (`id`, `type`, `name`, `title`) VALUES ('d0', 0, 'Knowledge', '<!--lang_client_feedback_knowledge-->'),('d1', 0, 'Friendlyness', '<!--lang_client_feedback_friendliness-->'),('d2', 0, 'Responsivenness', '<!--lang_client_feedback_responsiveness-->'),('d3', 0, 'Overall', '<!--lang_client_feedback_overall-->'),('d4', 1, 'Comment', '<!--lang_client_feedback_comment-->');");
    $sttime = time();
    $max_fb_time = null;
    if ($result = $_link->Query(true, "SELECT * FROM `" . DB_PREFIX . "ratings` ORDER BY `time` DESC;")) {
        while ($sttime > time() - 15 && ($row = DBManager::FetchArray($result))) {
            $userData = new UserData($row["fullname"], $row["email"], $row["company"], "");
            $hash = $userData->Hash();
            $_link->Query(true, "INSERT IGNORE INTO `" . DBManager::RealEscape($_prefix) . "user_data` (`id`,`create`,`h_fullname`,`h_email`,`h_company`,`h_customs`) VALUES ('" . DBManager::RealEscape($hash) . "'," . intval(time()) . ",'" . DBManager::RealEscape($row["fullname"]) . "','" . DBManager::RealEscape($row["email"]) . "','" . DBManager::RealEscape($row["company"]) . "','');");
            $_link->Query(true, "INSERT INTO `" . DBManager::RealEscape($_prefix) . "feedbacks` (`id`, `created`, `chat_id`, `user_id`, `operator_id`, `data_id`, `ip_hash`) VALUES ('" . DBManager::RealEscape($id = getId(32)) . "', " . intval($row["time"]) . ", '" . DBManager::RealEscape($row["chat_id"]) . "', '" . DBManager::RealEscape($row["user_id"]) . "', '" . DBManager::RealEscape($row["internal_id"]) . "','" . DBManager::RealEscape($hash) . "','" . DBManager::RealEscape(md5($row["ip"])) . "');");
            $_link->Query(true, "INSERT INTO `" . DBManager::RealEscape($_prefix) . "feedback_criteria` (`fid`, `cid`, `value`) VALUES ('" . DBManager::RealEscape($id) . "', 'd0', '" . DBManager::RealEscape($row["qualification"]) . "');");
            $_link->Query(true, "INSERT INTO `" . DBManager::RealEscape($_prefix) . "feedback_criteria` (`fid`, `cid`, `value`) VALUES ('" . DBManager::RealEscape($id) . "', 'd1', '" . DBManager::RealEscape($row["politeness"]) . "');");
            if ($max_fb_time == null) {
                $max_fb_time = $row["time"];
            }
        }
    }
    if ($max_fb_time == null) {
        $max_fb_time = time();
    }
    CacheManager::WriteDataUpdateTime(DATA_UPDATE_KEY_FEEDBACKS, false, $_link, $_prefix, intval($max_fb_time) * 1000);
    CacheManager::WriteDataUpdateTime(DATA_UPDATE_KEY_FILTERS, false, $_link, $_prefix, intval(time()) * 1000);
    return $res;
}
function getChatVoucherTemplate($html = "")
{
    global $CONFIG, $COUNTRIES, $LZLANG;
    if (!is("DB_CONNECTION") || !empty($CONFIG["db"]["ccpp"]["Custom"])) {
        return "";
    }
    if (!empty($CONFIG["gl_ccac"])) {
        foreach ($CONFIG["db"]["cct"] as $type) {
            $html .= $type->GetTemplate();
        }
    }
    $cchtml = getFile(PATH_TEMPLATES . "chat_voucher_checkout.tpl");
    $mycountry = "";
    $replacements = array("<!--lp_company-->" => "", "<!--lp_firstname-->" => "", "<!--lp_email-->" => "", "<!--lp_lastname-->" => "", "<!--lp_taxid-->" => "", "<!--lp_business_type-->" => "", "<!--lp_address_1-->" => "", "<!--lp_address_2-->" => "", "<!--lp_city-->" => "", "<!--lp_state-->" => "", "<!--lp_country-->" => "", "<!--lp_phone-->" => "", "<!--lp_zip-->" => "");
    $prefillco = !empty($_GET["co"]) ? " OR id='" . DBManager::RealEscape(base64URLDecode($_GET["co"])) . "'" : "";
    if (!isnull(getCookieValue("userid")) || !empty($prefillco)) {
        $result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_COMMERCIAL_CHAT_VOUCHERS . "` WHERE `visitor_id`='" . DBManager::RealEscape(getCookieValue("userid")) . "'" . $prefillco . " ORDER BY `created` DESC LIMIT 1;");
        if ($result) {
            if ($row = DBManager::FetchArray($result)) {
                $replacements = array("<!--lp_company-->" => $row["company"], "<!--lp_firstname-->" => $row["firstname"], "<!--lp_lastname-->" => $row["lastname"], "<!--lp_taxid-->" => $row["tax_id"], "<!--lp_email-->" => $row["email"], "<!--lp_business_type-->" => $row["business_type"], "<!--lp_address_1-->" => $row["address_1"], "<!--lp_address_2-->" => $row["address_2"], "<!--lp_city-->" => $row["city"], "<!--lp_state-->" => $row["state"], "<!--lp_country-->" => $row["country"], "<!--lp_phone-->" => $row["phone"], "<!--lp_zip-->" => $row["zip"]);
                $mycountry = $row["country"];
            }
        }
    }
    $clist = $COUNTRIES;
    asort($clist);
    $countrieshtml = "";
    foreach ($clist as $isokey => $value) {
        if (!empty($isokey)) {
            $countrieshtml .= $isokey == $mycountry ? "<option value=\"" . $isokey . "\" SELECTED>" . utf8_encode($value) . "</option>" : "<option value=\"" . $isokey . "\">" . utf8_encode($value) . "</option>";
        }
    }
    $cchtml = str_replace("<!--countries-->", $countrieshtml, $cchtml);
    foreach ($replacements as $key => $value) {
        $cchtml = str_replace($key, $value, $cchtml);
    }
    $cchtml = str_replace("<!--show_VAT-->", !empty($CONFIG["gl_ccsv"]) ? "''" : "none", $cchtml);
    $cchtml = str_replace("<!--voucher_form-->", $html, $cchtml);
    if (!empty($CONFIG["db"]["ccpp"]["PayPal"]->LogoURL)) {
        $cchtml = str_replace("<!--pp_logo_url-->", " src=\"" . $CONFIG["db"]["ccpp"]["PayPal"]->LogoURL . "\"", $cchtml);
    } else {
        $cchtml = str_replace("<!--pp_logo_url-->", "", $cchtml);
    }
    $cchtml = str_replace("<!--extends_voucher-->", !empty($_GET["co"]) && strlen(base64UrlDecode($_GET["co"])) == 16 ? base64UrlDecode($_GET["co"]) : "", $cchtml);
    $cchtml = str_replace("<!--ofc-->", !empty($_GET["ofc"]) ? "MQ__" : "", $cchtml);
    $cchtml = str_replace("<!--VAT-->", str_replace("<!--VAT-->", $CONFIG["gl_ccva"], $LZLANG["client_voucher_include_vat"]), $cchtml);
    return $cchtml;
}
 function GetQueueWaitingTime($_position, $min = 1)
 {
     if ($this->OperatorsBusy == 0) {
         $this->OperatorsBusy++;
     }
     $result = DBManager::Execute(true, "SELECT AVG(`endtime`-`time`) AS `waitingtime` FROM `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` AS `db1` INNER JOIN `" . DB_PREFIX . DATABASE_OPERATORS . "` as `db2` ON `db1`.`internal_id`=`db2`.`system_id` WHERE `chat_type`=1 AND `bot`=0 AND `endtime`>0 AND `endtime`>`time` AND `endtime`-`time` < 3600;");
     if ($result) {
         $row = DBManager::FetchArray($result);
         if (!empty($row["waitingtime"])) {
             $min = $row["waitingtime"] / 60 / $this->OperatorsBusy;
         } else {
             $min = $min / $this->OperatorsBusy;
         }
         $minb = $min;
         for ($i = 1; $i < $_position; $i++) {
             $minb *= 0.9;
             $min += $minb;
         }
         $min /= Server::$Configuration->File["gl_sim_ch"];
         $min -= abs((time() - CHAT_START_TIME) / 60);
         if ($min <= 0) {
             $min = 1;
         }
     }
     return min(10, ceil($min));
 }
function testDataBase($_host, $_user, $_pass, $_dbname, $_prefix, $_extension = "", $_intense = false)
{
    global $DB_CONNECTOR;
    $connection = new DBManager($_user, $_pass, $_host, "", $_prefix);
    if (!empty($_extension)) {
        DBManager::$Extension = $_extension;
    }
    if (DBManager::$Extension == "mysql" && !function_exists("mysql_connect")) {
        return "PHP MySQL extension is missing (php_mysql.dll)";
    } else {
        if (DBManager::$Extension == "mysqli" && !function_exists("mysqli_connect")) {
            return "PHP/MySQLi extension is missing (php_mysqli.dll)";
        }
    }
    $connection->InitConnection();
    $connection->Query(false, "SET NAMES 'utf8'");
    if (!DBManager::$Provider) {
        $error = DBManager::GetError();
        return "Can't connect to database. Invalid host or login! (" . DBManager::GetErrorCode() . (!empty($error) ? ": " . $error : "") . ")";
    } else {
        $db_selected = $connection->SelectDatabase(DBManager::RealEscape($_dbname));
        if (!$db_selected) {
            return DBManager::GetErrorCode() . ": " . DBManager::GetError();
        } else {
            $resultv = $connection->Query(false, "SELECT VERSION() as `mysql_version`");
            if (!$resultv) {
                return DBManager::GetErrorCode() . ": " . DBManager::GetError();
            } else {
                $mrow = @DBManager::FetchArray($resultv);
                $mversion = explode(".", $mrow["mysql_version"]);
                if (count($mversion) > 0 && $mversion[0] < MYSQL_NEEDED_MAJOR) {
                    return "LiveZilla requires MySQL version " . MYSQL_NEEDED_MAJOR . " or greater. The MySQL version installed on your server is " . $mrow["mysql_version"] . ".";
                }
            }
            $result = $connection->Query(false, "SELECT `version`,`chat_id`,`ticket_id` FROM `" . DBManager::RealEscape($_prefix) . DATABASE_INFO . "` ORDER BY `version` DESC LIMIT 1");
            $row = @DBManager::FetchArray($result);
            $version = $row["version"];
            if (!$result || empty($version)) {
                return "Cannot read the LiveZilla Database version. Please try to recreate the table structure. If you experience this message during installation process, please try to setup a prefix (for example lz_).";
            }
            if ($version != VERSION && defined("SERVERSETUP") && SERVERSETUP) {
                $upres = initUpdateDatabase($version, $connection, $_prefix);
                if ($upres !== true) {
                    return "Cannot update database structure from [" . $version . "] to [" . VERSION . "]. Please make sure that the user " . $_user . " has the MySQL permission to ALTER tables in " . $_dbname . ".\r\n\r\nError: " . $upres;
                }
            } else {
                if ($version != VERSION && empty($_GET["iv"])) {
                    return "Invalid database version: " . $version . " (required: " . VERSION . "). Please validate the database in the server administration panel first.\r\n\r\n";
                }
            }
            $DB_CONNECTOR = $connection;
            $result = $connection->Query(false, "SELECT * FROM `" . DBManager::RealEscape($_prefix) . DATABASE_OPERATORS . "`");
            if (DBManager::GetRowCount($result) == 0) {
                setManagement($_prefix, false, true);
            }
            if ($_intense && empty($_GET["iv"])) {
                foreach (get_defined_constants() as $constant => $val) {
                    if (substr($constant, 0, 9) == "DATABASE_") {
                        if (!$connection->Query(false, "SELECT * FROM `" . DBManager::RealEscape($_prefix) . $val . "` LIMIT 1;")) {
                            $code = DBManager::GetErrorCode();
                            $error = DBManager::GetError();
                            if ($code == 144 || $code == 145 || $code == 1194) {
                                $connection->Query(true, "REPAIR TABLE `" . DBManager::RealEscape($_prefix) . $val . "`;");
                                $error .= " - (trying to repair ...)";
                            }
                            return $code . ": " . $error;
                        }
                    }
                }
            }
            return null;
        }
    }
}
 static function UpdateUserManagement($_prefix)
 {
     if (OperatorRequest::IsValidated() && Is::Defined("VALIDATED_FULL_LOGIN") && OperatorRequest::IsAdministrator(true)) {
         Logging::SecurityLog("ServerManager::UpdateUserManagement", "", CALLER_SYSTEM_ID);
         $count = 0;
         while (isset($_POST["p_operators_" . $count . "_id"])) {
             if (!empty($_POST["p_operators_" . $count . "_delete"])) {
                 DBManager::Execute(true, "DELETE FROM `" . $_prefix . DATABASE_OPERATORS . "` WHERE `id`='" . DBManager::RealEscape($_POST["p_operators_" . $count . "_id"]) . "' LIMIT 1;");
             } else {
                 $did = !empty(Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]) ? Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]->AppDeviceId : "";
                 $abm = !empty(Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]) ? Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]->AppBackgroundMode : false;
                 $aos = !empty(Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]) ? Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]->AppOS : "";
                 $lac = !empty(Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]) ? Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]->LastActive : 0;
                 $fac = !empty(Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]) ? Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]->FirstActive : 0;
                 $wcl = !empty(Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]) ? Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]->ClientWeb : 0;
                 $acl = !empty(Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]) ? Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]->AppClient : 0;
                 $sta = !empty(Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]) ? Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]->Status : 2;
                 $tok = !empty(Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]) ? Server::$Operators[$_POST["p_operators_" . $count . "_system_id"]]->Token : "";
                 DBManager::Execute(true, "REPLACE INTO `" . $_prefix . DATABASE_OPERATORS . "` (`id`, `system_id`, `token`, `fullname`, `description`, `email`, `permissions`, `webspace`, `password`, `status`, `level`, `visitor_file_sizes`, `groups`, `groups_status`, `groups_hidden`,`reposts`, `languages`, `auto_accept_chats`, `login_ip_range`, `websites_users`, `websites_config`, `bot`, `wm`, `wmohca`,`first_active`,`last_active`,`sign_off`,`lweb`,`lapp`,`mobile_os`,`mobile_device_id`,`mobile_background`,`mobile_ex`,`max_chats`) VALUES ('" . DBManager::RealEscape($_POST["p_operators_" . $count . "_id"]) . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_system_id"]) . "','" . DBManager::RealEscape($tok) . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_fullname"]) . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_description"]) . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_email"]) . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_permissions"]) . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_webspace"]) . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_password"]) . "','" . $sta . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_level"]) . "','','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_groups"]) . "','','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_groups_hidden"]) . "','','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_languages"]) . "',0,'" . DBManager::RealEscape($_POST["p_operators_" . $count . "_lipr"]) . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_websites_users"]) . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_websites_config"]) . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_bot"]) . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_wm"]) . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_wmohca"]) . "'," . $fac . "," . $lac . "," . intval(empty($_POST["p_operators_" . $count . "_deac"]) ? 0 : 2) . "," . intval($wcl ? 1 : 0) . "," . intval($acl ? 1 : 0) . ",'" . DBManager::RealEscape($aos) . "','" . DBManager::RealEscape($did) . "'," . intval($abm ? 1 : 0) . ",'" . DBManager::RealEscape(@$_POST["p_operators_" . $count . "_mobile_ex"]) . "'," . intval(@$_POST["p_operators_" . $count . "_max_chats"]) . ");");
             }
             if (!empty($_POST["p_operators_" . $count . "_pp"])) {
                 DBManager::Execute(true, "DELETE FROM `" . $_prefix . DATABASE_PROFILE_PICTURES . "` WHERE `webcam`='0' AND `internal_id`='" . DBManager::RealEscape($_POST["p_operators_" . $count . "_system_id"]) . "';");
                 if ($_POST["p_operators_" . $count . "_pp"] != "DEFAULT") {
                     DBManager::Execute(true, "INSERT INTO `" . $_prefix . DATABASE_PROFILE_PICTURES . "` (`id` ,`internal_id`,`time` ,`webcam` ,`data`) VALUES ('" . DBManager::RealEscape(getId(32)) . "','" . DBManager::RealEscape($_POST["p_operators_" . $count . "_system_id"]) . "','" . DBManager::RealEscape(time()) . "',0,'" . DBManager::RealEscape($_POST["p_operators_" . $count . "_pp"]) . "');");
                 }
             }
             $count++;
         }
         $count = 0;
         while (isset($_POST["p_groups_" . $count . "_id"])) {
             if (!empty($_POST["p_groups_" . $count . "_delete"])) {
                 DBManager::Execute(true, "DELETE FROM `" . $_prefix . DATABASE_GROUPS . "`  WHERE `id`='" . DBManager::RealEscape($_POST["p_groups_" . $count . "_id"]) . "' LIMIT 1;");
             } else {
                 $f_functions = "000000";
                 $result = DBManager::Execute(true, "SELECT * FROM `" . $_prefix . DATABASE_GROUPS . "` WHERE `id`='" . DBManager::RealEscape($_POST["p_groups_" . $count . "_id"]) . "' LIMIT 1;");
                 if ($row = DBManager::FetchArray($result)) {
                     $f_functions = $row["functions"];
                 }
                 $f_functions = !empty($_POST["p_groups_" . $count . "_functions"]) ? $_POST["p_groups_" . $count . "_functions"] : $f_functions;
                 DBManager::Execute(true, "REPLACE INTO `" . $_prefix . DATABASE_GROUPS . "` (`id`, `dynamic`, `description`, `external`, `internal`, `created`, `email`, `standard`, `opening_hours`, `functions`, `chat_inputs_hidden`, `ticket_inputs_hidden`, `chat_inputs_required`, `ticket_inputs_required`, `chat_inputs_masked`, `ticket_inputs_masked`, `chat_inputs_cap`, `ticket_inputs_cap`, `max_chats`, `visitor_filters`, `chat_vouchers_required`, `pre_chat_js`, `post_chat_js`, `ticket_email_out`, `ticket_email_in`, `ticket_handle_unknown`, `chat_email_out`,`ticket_assignment`,`priorities`,`priority_sleep`) VALUES ('" . DBManager::RealEscape($_POST["p_groups_" . $count . "_id"]) . "',0,'" . DBManager::RealEscape($_POST["p_groups_" . $count . "_description"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_external"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_internal"]) . "'," . time() . ",'" . DBManager::RealEscape($_POST["p_groups_" . $count . "_email"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_standard"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_opening_hours"]) . "','" . DBManager::RealEscape($f_functions) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_chat_inputs_hidden"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_ticket_inputs_hidden"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_chat_inputs_required"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_ticket_inputs_required"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_chat_inputs_masked"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_ticket_inputs_masked"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_chat_inputs_cap"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_ticket_inputs_cap"]) . "'," . intval($_POST["p_groups_" . $count . "_max_chats"]) . ",'" . DBManager::RealEscape($_POST["p_groups_" . $count . "_visitor_filters"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_chat_vouchers_required"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_pre_js"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_post_js"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_ticket_email_out"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_ticket_email_in"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_ticket_email_handling"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_chat_email_out"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_ticket_assign"]) . "','" . DBManager::RealEscape($_POST["p_groups_" . $count . "_priorities"]) . "'," . intval($_POST["p_groups_" . $count . "_ps"]) . ");");
             }
             SocialMediaChannel::DeleteByGroup($_prefix, $_POST["p_groups_" . $count . "_id"]);
             $count++;
         }
         DBManager::Execute(true, "DELETE FROM `" . $_prefix . DATABASE_OPERATOR_LOGINS . "`;");
         Server::$Operators = Server::$Groups = Server::$Visitors = null;
         Server::InitDataBlock(array("INTERNAL", "GROUPS", "VISITOR"));
         ServerManager::UpdatePredefinedMessages($_prefix);
         ServerManager::UpdateSignatures($_prefix);
         ServerManager::UpdateSocialMedia($_prefix);
         if (!empty($_POST["p_operators_0_id"])) {
             DBManager::Execute(true, "DELETE FROM `" . $_prefix . DATABASE_AUTO_REPLIES . "` WHERE NOT EXISTS (SELECT * FROM `" . $_prefix . DATABASE_OPERATORS . "` WHERE `system_id` = `" . $_prefix . DATABASE_AUTO_REPLIES . "`.`owner_id`) AND NOT EXISTS (SELECT * FROM `" . $_prefix . DATABASE_GROUPS . "` WHERE `id` = `" . $_prefix . DATABASE_AUTO_REPLIES . "`.`owner_id`)");
             DBManager::Execute(true, "DELETE FROM `" . $_prefix . DATABASE_PROFILE_PICTURES . "` WHERE NOT EXISTS (SELECT * FROM `" . $_prefix . DATABASE_OPERATORS . "` WHERE `system_id` = `" . $_prefix . DATABASE_PROFILE_PICTURES . "`.`internal_id`);");
             DBManager::Execute(true, "DELETE FROM `" . $_prefix . DATABASE_PROFILES . "` WHERE NOT EXISTS (SELECT * FROM `" . $_prefix . DATABASE_OPERATORS . "` WHERE `system_id` = `" . $_prefix . DATABASE_PROFILES . "`.`id`);");
             if (isset($_POST[POST_INTERN_EDIT_USER])) {
                 $combos = explode(";", $_POST[POST_INTERN_EDIT_USER]);
                 for ($i = 0; $i < count($combos); $i++) {
                     if (strpos($combos[$i], ",") !== false) {
                         $vals = explode(",", $combos[$i]);
                         if (strlen($vals[1]) > 0) {
                             Server::$Operators[$vals[0]]->ChangePassword($vals[1]);
                         }
                         if ($vals[2] == 1) {
                             Server::$Operators[$vals[0]]->SetPasswordChangeNeeded();
                         }
                     }
                 }
             }
         }
         CacheManager::Flush();
         Server::$Response->SetStandardResponse(1, "");
     }
 }
Пример #12
0
 function Read()
 {
     $loadedKeys = array();
     foreach ($this->Fields as $key => $name) {
         $data = "";
         if (CacheManager::$Engine == "PSHM") {
             $Shmid = @shmop_open($this->BaseMemId . $key, "a", 0666, 0);
             if ($Shmid) {
                 $shm_size = @shmop_size($Shmid);
                 $data = @shmop_read($Shmid, 0, $shm_size);
             }
             @shmop_close($Shmid);
         } else {
             if (CacheManager::$Engine == "APC") {
                 $data = apc_fetch($this->BaseMemId . $key);
             } else {
                 if (CacheManager::$Engine == "MEMCACHED" || CacheManager::$Engine == "MEMCACHE") {
                     $data = $this->Provider->get($this->BaseMemId . $key);
                 } else {
                     if (CacheManager::$Engine == "MYSQL") {
                         if (empty($loadedKeys) && ($result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_DATA_CACHE . "`;"))) {
                             while ($row = DBManager::FetchArray($result)) {
                                 $loadedKeys[$row["key"]] = $row["data"];
                             }
                         }
                         if (isset($loadedKeys[$key])) {
                             $data = $loadedKeys[$key];
                         }
                     }
                 }
             }
         }
         if (!empty($data)) {
             if ($this->Encryption) {
                 $upos = strpos($data, "_");
                 if ($upos !== false) {
                     $data = base64_decode(substr($data, $upos + 1, strlen($data) - ($upos + 1)));
                     $data = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->BaseId, $data, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND));
                 } else {
                     continue;
                 }
             }
             $arra = @unserialize($data);
             if (!empty($arra) && is_array($arra)) {
                 if (!(!empty($arra[3]) && getIdent() != "" && $arra[3] == getIdent())) {
                     if ($arra[0] > time() - $this->TTL || isset($this->Fields[$key][2]) && $arra[0] > time() - $this->Fields[$key][2]) {
                         $this->Data[$key] = $arra;
                         $this->Data[$key][2] = false;
                     }
                 }
             }
         }
     }
 }
 function KnowledgebaseEntriesList()
 {
     $sql_limit = "";
     if (!empty($_POST["p_limit"])) {
         if (is_int($_POST["p_limit"])) {
             $sql_limit = " LIMIT " . intval($_POST["p_limit"]);
         } else {
             $this->ErrorFilter = "Limit";
             return;
         }
         if (!empty($_POST["p_offset"])) {
             if (is_int($_POST["p_offset"])) {
                 $sql_limit .= " OFFSET " . intval($_POST["p_offset"]);
             } else {
                 $this->ErrorFilter = "Offset";
                 exit("dsf");
                 return;
             }
         }
     }
     $sql_where = "WHERE `discarded`=0 AND `parentid`<>100";
     if (!empty($_POST["p_id"])) {
         $sql_where .= " AND `id`='" . DBManager::RealEscape($_POST["p_id"]) . "'";
     }
     if (empty($_POST["p_show_private"])) {
         $sql_where .= " AND `kb_public`=1";
     }
     $results = array("KnowledgeBaseEntries" => array());
     $result = DBManager::Execute(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_RESOURCES . "` " . $sql_where . " ORDER BY `title` ASC " . $sql_limit . ";");
     while ($row = DBManager::FetchArray($result)) {
         $kbe = new KnowledgeBaseEntry($row);
         $results["KnowledgeBaseEntries"][] = array("KnowledgeBaseEntry" => ApiV2::ClearObject(ApiV2::GetObjectFields("KnowledgeBaseEntry"), $kbe));
     }
     $this->JSONOutput = APIV2::Encode($results, $this->JSONParams);
 }
Пример #14
0
 function TicketsList()
 {
     $sql_limit = "";
     if (!empty($_POST["p_limit"])) {
         if (is_numeric($_POST["p_limit"])) {
             $sql_limit = " LIMIT " . $_POST["p_limit"];
         } else {
             $this->ErrorFilter = "Limit";
             return;
         }
     }
     $sql_where = "WHERE `t1`.`id`>0 ";
     if (!empty($_POST["p_id"])) {
         $sql_where .= " AND `t1`.`id`='" . DBManager::RealEscape($_POST["p_id"]) . "'";
     } else {
         if (!empty($_POST["p_group"])) {
             $sql_where .= " AND `group_id`='" . DBManager::RealEscape($_POST["p_group"]) . "'";
         }
         if (!empty($_POST["p_operator"])) {
             $opsid = Operator::GetSystemId($_POST["p_operator"]);
             if ($opsid != null) {
                 $sql_where .= " AND `internal_id`='" . DBManager::RealEscape($opsid) . "'";
             } else {
                 $this->ErrorFilter = "Operator";
                 return;
             }
         }
         if (!empty($_POST["p_created_after"])) {
             if (is_numeric($_POST["p_created_after"]) && !empty($_POST["p_created_after"])) {
                 $sql_where .= " AND `time` > " . $_POST["p_created_after"];
             } else {
                 $this->ErrorFilter = "Created After";
                 return;
             }
         }
         if (!empty($_POST["p_created_before"])) {
             if (is_numeric($_POST["p_created_before"]) && !empty($_POST["p_created_before"])) {
                 $sql_where .= " AND `time` < " . $_POST["p_created_before"];
             } else {
                 $this->ErrorFilter = "Created Before";
                 return;
             }
         }
     }
     $results = array("Tickets" => array());
     $result = queryDB(true, $d = "SELECT * FROM `" . DB_PREFIX . DATABASE_TICKETS . "` as `t1` INNER JOIN `" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "` as `t2` ON `t1`.`id`=`t2`.`id` " . $sql_where . " ORDER BY `t1`.`id` ASC " . $sql_limit . ";");
     while ($row = DBManager::FetchArray($result)) {
         $ticket = new Ticket($row, true, true);
         $results["Tickets"][] = array("Ticket" => ApiV2::ClearObject(ApiV2::GetObjectFields("Ticket"), $ticket));
     }
     $this->JSONOutput = APIV2::Encode($results, $this->JSONParams);
 }
function buildExtern()
{
    global $VISITOR, $INTERNAL, $GROUPS, $RESPONSE;
    $RESPONSE->Tracking = "";
    $result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_CHAT_FORWARDS . "` WHERE `auto`=0 AND `closed`=0 AND `received`=0 ORDER BY `created` ASC;");
    while ($row = DBManager::FetchArray($result)) {
        $forward = new Forward($row);
        $RESPONSE->Forwards .= $forward->GetXml();
        if (!empty($VISITOR[$forward->ReceiverUserId]) && $VISITOR[$forward->ReceiverUserId]->GetBrowser($forward->ReceiverBrowserId) != null) {
            if (!$forward->Invite) {
                $VISITOR[$forward->ReceiverUserId]->GetBrowser($forward->ReceiverBrowserId)->Forward = $forward;
            } else {
                if (CALLER_SYSTEM_ID == $forward->TargetSessId) {
                    $forward->Save(true, false);
                }
            }
        }
    }
    $isex = !empty($INTERNAL[CALLER_SYSTEM_ID]->Groups) && $GROUPS[$INTERNAL[CALLER_SYSTEM_ID]->Groups[0]]->IsExternal;
    $builder = new ExternalXMLBuilder($INTERNAL[CALLER_SYSTEM_ID], $VISITOR, NO_CLIPPING || isset($_POST[POST_INTERN_RESYNC]), $isex);
    $builder->SessionFileSizes = $INTERNAL[CALLER_SYSTEM_ID]->VisitorFileSizes;
    $builder->StaticReload = $INTERNAL[CALLER_SYSTEM_ID]->VisitorStaticReload;
    //$base = (!empty($INTERNAL[CALLER_SYSTEM_ID]->VisitorFileSizes["discarded"])) ? $INTERNAL[CALLER_SYSTEM_ID]->VisitorFileSizes["discarded"] : array();
    $base = array();
    $builder->SetDiscardedObject($base);
    $builder->Generate();
    $RESPONSE->Tracking = $builder->XMLCurrent;
    foreach ($builder->DiscardedObjects as $uid => $list) {
        $RESPONSE->Tracking .= "<cd id=\"" . base64_encode($uid) . "\">\r\n";
        if ($list != null) {
            foreach ($list as $bid) {
                $RESPONSE->Tracking .= " <bd id=\"" . base64_encode($bid) . "\" />\r\n";
            }
        }
        $RESPONSE->Tracking .= "</cd>\r\n";
    }
    $RESPONSE->Typing .= $builder->XMLTyping;
    $INTERNAL[CALLER_SYSTEM_ID]->VisitorFileSizes = $builder->SessionFileSizes;
    $INTERNAL[CALLER_SYSTEM_ID]->VisitorStaticReload = $builder->StaticReload;
    if ($builder->GetAll && !LOGIN) {
        $RESPONSE->Tracking .= "<resync />\r\n";
    }
    if (count($VISITOR) == 0) {
        $INTERNAL[CALLER_SYSTEM_ID]->VisitorFileSizes = array();
    }
}
function sendPushMessages()
{
    global $CONFIG;
    if (!empty($CONFIG["gl_mpm"]) && DB_CONNECTION && defined("IS_PUSH_MESSAGE")) {
        $count = 0;
        $result = queryDB(false, "SELECT * FROM `" . DB_PREFIX . DATABASE_PUSH_MESSAGES . "` WHERE `sent`=0 ORDER BY `created` ASC LIMIT 10;");
        if ($result) {
            $data = array();
            while ($row = @DBManager::FetchArray($result)) {
                $data = array_merge($data, array('p_app_os_' . $count => $row["device_os"], 'p_device_id_' . $count => $row["device_id"], 'p_message_type_' . $count => $row["push_key"], 'p_message_' . $count => base64UrlEncode($row["push_value"]), 'p_chatpartner_id_' . $count => $row["chat_partner_id"], 'p_chat_id_' . $count++ => $row["chat_id"]));
            }
            queryDB(false, "UPDATE `" . DB_PREFIX . DATABASE_PUSH_MESSAGES . "` SET `sent`=1 ORDER BY `created` ASC LIMIT 10;");
            if (!empty($data)) {
                $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($data)));
                $context = stream_context_create($opts);
                $result = file_get_contents(CONFIG_LIVEZILLA_PUSH, false, $context);
                if ($result !== "1") {
                    handleError("116", " Push Message Error: " . $result, CONFIG_LIVEZILLA_PUSH, 0);
                }
            }
        }
    }
}
function optimizeTables($_table)
{
    global $RESPONSE;
    if ($_table == DATABASE_VISITOR_DATA_PAGES) {
        $result = queryDB(true, "SELECT `id` FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_PAGES . "`;");
        while ($row = DBManager::FetchArray($result)) {
            $rows = DBManager::FetchArray(queryDB(true, "(SELECT COUNT(*) AS `csap` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_PAGES . "` WHERE `url` = '" . $row["id"] . "');"));
            if (!empty($rows["csap"])) {
                continue;
            }
            $rows = DBManager::FetchArray(queryDB(true, "(SELECT COUNT(*) AS `csap` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_PAGES_EXIT . "` WHERE `url` = '" . $row["id"] . "');"));
            if (!empty($rows["csap"])) {
                continue;
            }
            $rows = DBManager::FetchArray(queryDB(true, "(SELECT COUNT(*) AS `csap` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_PAGES_ENTRANCE . "` WHERE `url` = '" . $row["id"] . "');"));
            if (!empty($rows["csap"])) {
                continue;
            }
            $rows = DBManager::FetchArray(queryDB(true, "(SELECT COUNT(*) AS `csap` FROM `" . DB_PREFIX . DATABASE_VISITOR_BROWSER_URLS . "` WHERE `url` = '" . $row["id"] . "' OR `referrer` = '" . $row["id"] . "');"));
            if (!empty($rows["csap"])) {
                continue;
            }
            $rows = DBManager::FetchArray(queryDB(true, "(SELECT COUNT(*) AS `csap` FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_REFERRERS . "` WHERE `referrer` = '" . $row["id"] . "');"));
            if (!empty($rows["csap"])) {
                continue;
            }
        }
        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_PAGES . "`;");
        queryDB(true, "REPAIR TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_PAGES . "`;");
    } else {
        if ($_table == DATABASE_VISITOR_DATA_DOMAINS) {
            queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_DOMAINS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_PAGES . "` WHERE `domain` = `" . DB_PREFIX . DATABASE_VISITOR_DATA_DOMAINS . "`.`id`) AND NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_DOMAINS . "` WHERE `domain` = `" . DB_PREFIX . DATABASE_VISITOR_DATA_DOMAINS . "`.`id`);");
            queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_DOMAINS . "`;");
            queryDB(true, "REPAIR TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_DOMAINS . "`;");
        } else {
            if ($_table == DATABASE_VISITOR_DATA_PATHS) {
                queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_PATHS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_PAGES . "` WHERE `path` = `" . DB_PREFIX . DATABASE_VISITOR_DATA_PATHS . "`.`id`);");
                queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_PATHS . "`;");
                queryDB(true, "REPAIR TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_PATHS . "`;");
            } else {
                if ($_table == DATABASE_VISITOR_DATA_ISPS) {
                    queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_ISPS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_ISPS . "` WHERE `isp` = `" . DB_PREFIX . DATABASE_VISITOR_DATA_ISPS . "`.`id`) AND NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITORS . "` WHERE `isp` = `" . DB_PREFIX . DATABASE_VISITOR_DATA_ISPS . "`.`id`);");
                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_ISPS . "`;");
                    queryDB(true, "REPAIR TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_ISPS . "`;");
                } else {
                    if ($_table == DATABASE_VISITOR_DATA_QUERIES) {
                        queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_QUERIES . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_QUERIES . "` WHERE `query` = `" . DB_PREFIX . DATABASE_VISITOR_DATA_QUERIES . "`.`id`) AND NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "` WHERE `query` = `" . DB_PREFIX . DATABASE_VISITOR_DATA_QUERIES . "`.`id`) AND NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_GOALS_QUERIES . "` WHERE `query` = `" . DB_PREFIX . DATABASE_VISITOR_DATA_QUERIES . "`.`id`);");
                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_QUERIES . "`;");
                        queryDB(true, "REPAIR TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_QUERIES . "`;");
                    } else {
                        if ($_table == DATABASE_VISITOR_DATA_CITIES) {
                            queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_CITIES . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_CITIES . "` WHERE `city` = `" . DB_PREFIX . DATABASE_VISITOR_DATA_CITIES . "`.`id`) AND NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITORS . "` WHERE `city` = `" . DB_PREFIX . DATABASE_VISITOR_DATA_CITIES . "`.`id`);");
                            queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_CITIES . "`;");
                            queryDB(true, "REPAIR TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_CITIES . "`;");
                        } else {
                            if ($_table == DATABASE_VISITOR_DATA_REGIONS) {
                                queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_REGIONS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_STATS_AGGS_REGIONS . "` WHERE `region` = `" . DB_PREFIX . DATABASE_VISITOR_DATA_REGIONS . "`.`id`) AND NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_VISITORS . "` WHERE `region` = `" . DB_PREFIX . DATABASE_VISITOR_DATA_REGIONS . "`.`id`);");
                                queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_REGIONS . "`;");
                                queryDB(true, "REPAIR TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_REGIONS . "`;");
                            } else {
                                if ($_table == DATABASE_VISITORS) {
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_POSTS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_TICKETS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_TICKET_MESSAGES . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_TICKET_EDITORS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_TICKET_CUSTOMS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_EVENT_TRIGGERS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_CHAT_REQUESTS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_BROWSERS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_SYSTEMS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_RESOLUTIONS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_DATA_TITLES . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITORS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_FILTERS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "`;");
                                    queryDB(true, "REPAIR TABLE `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_CHAT_OPERATORS . "`;");
                                    queryDB(true, "REPAIR TABLE `" . DB_PREFIX . DATABASE_VISITOR_CHAT_OPERATORS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "`;");
                                    queryDB(true, "REPAIR TABLE `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_BROWSER_URLS . "`;");
                                    queryDB(true, "REPAIR TABLE `" . DB_PREFIX . DATABASE_VISITOR_BROWSER_URLS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_OPERATOR_STATUS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_OPERATORS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_OPERATOR_LOGINS . "`;");
                                    queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_VISITOR_GOALS . "`;");
                                } else {
                                    if ($_table == DATABASE_STATS_AGGS) {
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_BROWSERS . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_RESOLUTIONS . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_COUNTRIES . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_VISITS . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_SYSTEMS . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_LANGUAGES . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_CITIES . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_REGIONS . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_ISPS . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_QUERIES . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_PAGES . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_DOMAINS . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_REFERRERS . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_AVAILABILITIES . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_DURATIONS . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_CHATS . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_SEARCH_ENGINES . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_VISITORS . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_CRAWLERS . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_PAGES_ENTRANCE . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_PAGES_EXIT . "`;");
                                        queryDB(true, "OPTIMIZE TABLE `" . DB_PREFIX . DATABASE_STATS_AGGS_GOALS . "`;");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $RESPONSE->SetStandardResponse(1, base64_encode(1));
}
Пример #18
0
 function AddPredefinedMessageSet($_userSystemId, $_groupId, $_langISO, $_standard, $_chatInviteManual, $_chatInviteAuto, $_welcomeMessage, $_webSitePushManual, $_webSitePushAuto, $_chatTranscriptMail, $_ticketMail)
 {
     $result = queryDB(true, "SELECT MAX(`id`) AS `pcount` FROM `" . DB_PREFIX . DATABASE_PREDEFINED . "`;");
     if ($row = DBManager::FetchArray($result)) {
         $pdm = new PredefinedMessage($row["pcount"] + 1, $_userSystemId, $_groupId, $_langISO, $_chatInviteManual, $_chatInviteAuto, $_welcomeMessage, $_webSitePushManual, $_webSitePushAuto, '', '', '1', $_standard ? '1' : '0', '1', '1', $_chatTranscriptMail, $_ticketMail, '', '', '');
         $pdm->Save(DB_PREFIX);
         return $pdm;
     }
     return false;
 }
 static function FromSystemId($_systemId)
 {
     $d = new UserData();
     $browserid = explode("~", $_systemId);
     $browserid = $browserid[1];
     $result = DBManager::Execute(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "` AS `tb` INNER JOIN `" . DB_PREFIX . DATABASE_USER_DATA . "` AS `td` ON `tb`.`data_id`=`td`.`id` WHERE `tb`.`id`='" . DBManager::RealEscape($browserid) . "' LIMIT 1;");
     if ($result) {
         if ($row = DBManager::FetchArray($result)) {
             $d->SetDetails($row);
         }
     }
     return $d;
 }
 function GetForwards()
 {
     $list = array();
     $result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_CHAT_FORWARDS . "` WHERE `target_group_id`='" . DBManager::RealEscape($this->DesiredChatGroup) . "' AND `visitor_id`='" . DBManager::RealEscape($this->UserId) . "' AND `browser_id`='" . DBManager::RealEscape($this->BrowserId) . "' ORDER BY `created` ASC;");
     while ($row = DBManager::FetchArray($result)) {
         $list[] = new Forward($row);
     }
     return $list;
 }
 function Listen()
 {
     global $USER;
     $isOp = false;
     if ($USER->Browsers[0]->Status == CHAT_STATUS_ACTIVE) {
         $result = DBManager::Execute(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(Server::$Operators[$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;
                     $this->AddHTML(str_replace("<!--message-->", str_replace("<!--intern_name-->", Server::$Operators[$ChatMember->SystemId]->Fullname, LocalizationManager::$TranslationStrings["client_intern_arrives"]), IOStruct::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) {
                         $this->AddHTML($this->GetLeaveChatHTML(false, Server::$Operators[$ChatMember->SystemId]->Fullname), "sys", "LCM01" . $ChatMember->SystemId);
                     }
                 }
                 if ($ChatMember->Status == 0) {
                     $isOp = true;
                 }
             }
         }
     } else {
         $isOp = true;
     }
     if (Communication::ReadParameter("ovlif")) {
         $this->InitFeedback();
     }
     $USER->Browsers[0]->Typing = isset($_GET["typ"]);
     if (!$USER->Browsers[0]->Declined) {
         $USER->Browsers[0]->Save();
     }
     $USER->Browsers[0]->ValidateOperator();
     $this->CurrentOperatorId = Communication::GetParameter("op", "", $c, FILTER_SANITIZE_SPECIAL_CHARS, null, 32);
     if ($USER->Browsers[0]->Waiting && $this->Botmode || empty($USER->Browsers[0]->OperatorId) && !empty($this->CurrentOperatorId) && isset(Server::$Operators[$this->CurrentOperatorId]) && !Server::$Operators[$this->CurrentOperatorId]->IsBot || !empty($this->CurrentOperatorId) && empty($USER->Browsers[0]->ChatId) && !$this->Botmode || !$isOp || $USER->Browsers[0]->Closed) {
         if (!$USER->Browsers[0]->ExternalClosed) {
             $USER->Browsers[0]->ExternalClose();
             $USER->Browsers[0]->Save();
             $USER->Browsers[0]->Load();
         }
         $USER->Browsers[0]->Members = array();
         if (!empty($this->CurrentOperatorId) && !empty(Server::$Operators[$this->CurrentOperatorId]) && $isOp) {
             $this->AddHTML($this->GetLeaveChatHTML(true, Server::$Operators[$this->CurrentOperatorId]->Fullname), "sys", "LCM01" . $this->CurrentOperatorId);
             if (!empty(Server::$Configuration->File["gl_fboe"]) && Communication::ReadParameter("po", 0) == 0 && !Server::$Operators[$this->CurrentOperatorId]->IsBot) {
                 if (!empty(Server::$Groups[$USER->Browsers[0]->DesiredChatGroup]->ChatFunctions[3])) {
                     $this->InitFeedback(false);
                 }
             }
             $this->Flags["LMR"] = "null";
             $USER->Browsers[0]->OperatorId = null;
             $this->CurrentOperatorId = "";
             $this->RepollRequired = true;
         }
     }
 }
function processGoals($count = 0)
{
    global $RESPONSE;
    if (isset($_POST[POST_INTERN_PROCESS_GOALS . "_va_" . $count])) {
        $goallinks = array();
        if ($result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_EVENT_GOALS . "`")) {
            while ($row = DBManager::FetchArray($result)) {
                $goallinks[] = array($row["event_id"], $row["goal_id"]);
            }
        }
        queryDB(true, "TRUNCATE TABLE `" . DB_PREFIX . DATABASE_GOALS . "`;");
        while (isset($_POST[POST_INTERN_PROCESS_GOALS . "_va_" . $count])) {
            if ($_POST[POST_INTERN_PROCESS_GOALS . "_vb_" . $count] != "-1") {
                queryDB(true, "INSERT INTO `" . DB_PREFIX . DATABASE_GOALS . "` (`id`, `title`, `description`, `conversion`, `ind`) VALUES ('" . DBManager::RealEscape($_POST[POST_INTERN_PROCESS_GOALS . "_vb_" . $count]) . "', '" . DBManager::RealEscape($_POST[POST_INTERN_PROCESS_GOALS . "_vd_" . $count]) . "', '" . DBManager::RealEscape($_POST[POST_INTERN_PROCESS_GOALS . "_vc_" . $count]) . "', '" . DBManager::RealEscape($_POST[POST_INTERN_PROCESS_GOALS . "_ve_" . $count]) . "','" . DBManager::RealEscape($count) . "');");
            }
            $count++;
        }
        foreach ($goallinks as $lpair) {
            queryDB(false, "INSERT INTO `" . DB_PREFIX . DATABASE_EVENT_GOALS . "` (`event_id`, `goal_id`) VALUES ('" . DBManager::RealEscape($lpair[0]) . "', '" . DBManager::RealEscape($lpair[1]) . "');");
        }
        $RESPONSE->SetStandardResponse(1, "");
    }
}
Пример #23
0
}
require LIVEZILLA_PATH . "_definitions/definitions.inc.php";
require LIVEZILLA_PATH . "_lib/functions.global.inc.php";
require LIVEZILLA_PATH . "_definitions/definitions.dynamic.inc.php";
require LIVEZILLA_PATH . "_definitions/definitions.protocol.inc.php";
require LIVEZILLA_PATH . "_lib/functions.external.inc.php";
@set_error_handler("handleError");
@error_reporting(E_ALL);
header("Pragma: no-cache");
header("Cache-Control: no-cache, must-revalidate");
header("Keep-Alive: timeout=5, max=100");
Server::InitDataProvider();
if (!empty($_GET["value"]) && strlen($_GET["value"]) == 16) {
    $ticket = VisitorChat::GetMatchingVoucher($_GET[GET_EXTERN_GROUP], $_GET["value"]);
    if (!empty($ticket) && !$ticket->CheckForVoid() && $ticket->Paid) {
        $ticket->UpdateVoucherChatTime(0, empty($ticket->FirstUsed));
        $sessions = $ticket->ChatSessionsMax < 0 ? 0 : $ticket->ChatSessionsMax;
        if ($result = DBManager::Execute(true, "SELECT `exit` FROM `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` WHERE `chat_ticket_id`='" . DBManager::RealEscape($ticket->Id) . "' AND `exit`=0 LIMIT 1;")) {
            if ($row = DBManager::FetchArray($result)) {
                exit("lz_validate_com_chat_input_result(false,true,1,'',0,0,0,false,false,false);");
            }
        }
        exit("lz_validate_com_chat_input_result(true,false,1,'" . $ticket->Id . "'," . $ticket->ChatTime . "," . $ticket->ChatTimeMax . "," . $ticket->ChatSessions . "," . $ticket->ChatSessionsMax . "," . $ticket->VoucherAutoExpire . "," . To::BoolString($ticket->VoucherAutoExpire < time()) . ");");
    } else {
        if (!empty($ticket)) {
            exit("lz_validate_com_chat_input_result(false,false,1,'',0,0,0,false,false,false);");
        }
    }
}
exit("lz_validate_com_chat_input_result(false,false,0,'',0,0,0,false,false,false);");
Server::UnloadDataProvider();
 static function IsChatBrowserIdAvailable($_browserId, $_allowExisting = true)
 {
     if (empty($_browserId)) {
         return false;
     }
     $result = DBManager::Execute(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "` WHERE `id`='" . DBManager::RealEscape($_browserId) . "';");
     if ($result) {
         if ($row = DBManager::FetchArray($result)) {
             if (!$_allowExisting) {
                 return false;
             }
             if (!empty($row["overlay_container"]) || empty($row["is_chat"])) {
                 return false;
             }
         }
     }
     return true;
 }