function Save($_config, $_resolution, $_color, $_timezone, $_lat, $_long, $_countryiso2, $_city, $_region, $_geotimezone, $_isp, $_geosspan, $_grid, $_js = true, $_fromCookie = false)
 {
     global $STATS, $COUNTRIES, $COUNTRY_ALIASES;
     if (!$this->FirstCall) {
         $this->KeepAlive();
     } else {
         if (!isnull(getCookieValue("visits")) && $this->Visits == 1) {
             $this->Visits = getCookieValue("visits") + 1;
         }
         setCookieValue("visits", $this->Visits);
         if (!isnull(getCookieValue("last_visit"))) {
             $this->VisitLast = getCookieValue("last_visit");
         }
         setCookieValue("last_visit", time());
         $this->IP = getIP();
         $this->SystemInfo = !empty($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : "";
         $localization = getBrowserLocalization();
         $this->Language = $localization[0];
         $this->GeoCountryISO2 = $localization[1];
         $this->Resolution = !empty($_resolution) && count($_resolution) == 2 && !empty($_resolution[0]) && !empty($_resolution[1]) ? $_resolution[0] . " x " . $_resolution[1] : "";
         $this->Resolution .= !empty($_color) ? " (" . $_color . " Bit)" : "";
         $this->GeoTimezoneOffset = getLocalTimezone($_timezone);
         $this->GeoResult = 0;
         if (!empty($_geosspan)) {
             createSSpanFile($_geosspan);
         }
         if (!empty($_config["gl_pr_ngl"]) && $_js) {
             if (!empty($_lat) && base64_decode($_lat) > -180) {
                 setCookieValue(GEO_LATITUDE, $this->GeoLatitude = base64_decode($_lat));
                 setCookieValue(GEO_LONGITUDE, $this->GeoLongitude = base64_decode($_long));
                 setCookieValue(GEO_COUNTRY_ISO_2, $this->GeoCountryISO2 = base64_decode($_countryiso2));
                 setCookieValue(GEO_CITY, $this->GeoCity = base64_decode($_city));
                 setCookieValue(GEO_REGION, $this->GeoRegion = base64_decode($_region));
                 setCookieValue(GEO_TIMEZONE, $this->GeoTimezoneOffset = base64_decode($_geotimezone));
                 setCookieValue(GEO_ISP, $this->GeoISP = utf8_decode(base64_decode($_isp)));
                 setCookieValue("geo_data", time());
             } else {
                 if (isset($_lat) && !empty($_lat)) {
                     $this->GeoLatitude = base64_decode($_lat);
                     $this->GeoLongitude = base64_decode($_long);
                 } else {
                     if (!isnull(getCookieValue("geo_data")) && !isnull(getCookieValue(GEO_LATITUDE))) {
                         $this->GeoLatitude = getCookieValue(GEO_LATITUDE);
                         $this->GeoLongitude = getCookieValue(GEO_LONGITUDE);
                         $this->GeoCountryISO2 = getCookieValue(GEO_COUNTRY_ISO_2);
                         $this->GeoCity = getCookieValue(GEO_CITY);
                         $this->GeoRegion = getCookieValue(GEO_REGION);
                         $this->GeoTimezoneOffset = getCookieValue(GEO_TIMEZONE);
                         $this->GeoISP = getCookieValue(GEO_ISP);
                         $_fromCookie = true;
                     }
                 }
             }
             removeSSpanFile(false);
             if ($_fromCookie) {
                 $this->GeoResultId = 6;
             } else {
                 if (!isnull($span = getSpanValue())) {
                     if ($span > time() + CONNECTION_ERROR_SPAN) {
                         $this->GeoResultId = 5;
                     } else {
                         $this->GeoResultId = 4;
                     }
                 } else {
                     if (base64_decode($_lat) == -777) {
                         $this->GeoResultId = 5;
                     } else {
                         if (base64_decode($_lat) == -522) {
                             $this->GeoResultId = 2;
                         } else {
                             if ($_grid != 4) {
                                 $this->GeoResultId = 3;
                             } else {
                                 $this->GeoResultId = $_grid;
                             }
                         }
                     }
                 }
             }
         } else {
             $this->GeoResultId = 7;
         }
         initData(false, false, false, false, false, false, true);
         if (isset($COUNTRY_ALIASES[$this->GeoCountryISO2])) {
             $this->GeoCountryISO2 = $COUNTRY_ALIASES[$this->GeoCountryISO2];
         } else {
             if (!isset($COUNTRIES[$this->GeoCountryISO2]) && DEBUG_MODE) {
                 logit($this->GeoCountryISO2, LIVEZILLA_PATH . "_log/unknown_countries.txt");
             }
         }
         $detector = new DeviceDetector();
         $detector->DetectBrowser();
         if ($detector->AgentType == AGENT_TYPE_BROWSER || $detector->AgentType == AGENT_TYPE_UNKNOWN) {
             $detector->DetectOperatingSystem();
             if (DEBUG_MODE && !empty($_SERVER["HTTP_USER_AGENT"])) {
                 if ($detector->OperatingSystemUnknown) {
                     logit("OS UNKNOWN: " . $_SERVER["HTTP_USER_AGENT"], LIVEZILLA_PATH . "_log/unknown_os.txt");
                 } else {
                     if ($detector->AgentType == AGENT_TYPE_UNKNOWN) {
                         logit("AGENT UNKNOWN: " . $_SERVER["HTTP_USER_AGENT"], LIVEZILLA_PATH . "_log/unknown_ag.txt");
                     }
                 }
             }
             $bid = $this->GetBrowserId($detector->Browser, $detector->AgentType);
             $oid = $this->GetOSId($detector->OperatingSystem);
             $row = $this->CreateSignature();
             if (is_array($row) && $row["id"] != $this->UserId) {
                 $this->UserId = $row["id"];
                 $this->SignatureMismatch = true;
             } else {
                 queryDB(true, "INSERT INTO `" . DB_PREFIX . DATABASE_VISITORS . "` (`id`, `entrance`,`last_active`, `host`,`ip`,`system`,`browser`, `visits`,`visit_id`,`visit_last`,`resolution`, `language`, `country`, `city`, `region`, `isp`, `timezone`, `latitude`, `longitude`, `geo_result`, `js`, `signature`) VALUES ('" . @mysql_real_escape_string($this->UserId) . "', '" . @mysql_real_escape_string(time()) . "','" . @mysql_real_escape_string(time()) . "', '" . @mysql_real_escape_string($this->Host) . "', '" . @mysql_real_escape_string($this->IP) . "', '" . @mysql_real_escape_string($oid) . "','" . @mysql_real_escape_string($bid) . "', '" . @mysql_real_escape_string($this->Visits) . "', '" . @mysql_real_escape_string($this->VisitId) . "','" . @mysql_real_escape_string($this->VisitLast) . "', '" . @mysql_real_escape_string(getValueId(DATABASE_VISITOR_DATA_RESOLUTIONS, "resolution", $this->Resolution, false, 32)) . "', '" . @mysql_real_escape_string(substr(strtoupper($this->Language), 0, 5)) . "','" . @mysql_real_escape_string($this->GeoCountryISO2) . "', '" . @mysql_real_escape_string(getValueId(DATABASE_VISITOR_DATA_CITIES, "city", $this->GeoCity, false)) . "', '" . @mysql_real_escape_string(getValueId(DATABASE_VISITOR_DATA_REGIONS, "region", $this->GeoRegion, false)) . "', '" . @mysql_real_escape_string(getValueId(DATABASE_VISITOR_DATA_ISPS, "isp", utf8_encode($this->GeoISP), false)) . "', '" . @mysql_real_escape_string($this->GeoTimezoneOffset) . "', '" . @mysql_real_escape_string($this->GeoLatitude) . "', '" . @mysql_real_escape_string($this->GeoLongitude) . "', '" . @mysql_real_escape_string($this->GeoResultId) . "', '" . @mysql_real_escape_string($_js ? 1 : 0) . "', '" . @mysql_real_escape_string($this->Signature) . "');");
                 if (mysql_affected_rows() == 1) {
                     queryDB(true, "UPDATE `" . DB_PREFIX . DATABASE_VISITORS . "` SET `visit_latest`=0 WHERE `id`='" . @mysql_real_escape_string($this->UserId) . "' AND `visit_id`!='" . @mysql_real_escape_string($this->VisitId) . "';");
                 }
             }
         } else {
             if (STATS_ACTIVE) {
                 $this->IsCrawler = true;
                 $STATS->ProcessAction(ST_ACTION_LOG_CRAWLER_ACCESS, array($this->GetCrawlerId($detector->Browser), null));
             }
         }
     }
 }
 function Save()
 {
     if ($this->IsExternal) {
         $pid = getValueId(DATABASE_VISITOR_DATA_PATHS, "path", $this->Path . $this->Params, false, 255);
     } else {
         $pid = getValueId(DATABASE_VISITOR_DATA_PATHS, "path", $this->Path, false, 255);
     }
     $did = $this->GetDomainId();
     $cid = getValueId(DATABASE_VISITOR_DATA_AREA_CODES, "area_code", $this->AreaCode);
     $tid = $this->GetTitleId($did, $pid, $cid);
     queryDB(true, "INSERT INTO `" . DB_PREFIX . DATABASE_VISITOR_DATA_PAGES . "` (`id`, `path`, `domain`,  `title`, `area_code`) VALUES (NULL, '" . @mysql_real_escape_string($pid) . "',  '" . @mysql_real_escape_string($did) . "',  '" . @mysql_real_escape_string($tid) . "', '" . @mysql_real_escape_string($cid) . "');");
     $row = mysql_fetch_array(queryDB(true, "SELECT `id`,`title` FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_PAGES . "` WHERE `path`='" . @mysql_real_escape_string($pid) . "' AND `domain`='" . @mysql_real_escape_string($did) . "';"), MYSQL_BOTH);
     if (STATS_ACTIVE && $tid != $row["title"]) {
         queryDB(true, "UPDATE `" . DB_PREFIX . DATABASE_VISITOR_DATA_PAGES . "` SET `title`=(SELECT `id` FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_TITLES . "` WHERE id='" . @mysql_real_escape_string($tid) . "' OR id='" . @mysql_real_escape_string($row["title"]) . "' ORDER BY `confirmed` DESC LIMIT 1) WHERE `path`='" . @mysql_real_escape_string($pid) . "' AND `domain`='" . @mysql_real_escape_string($did) . "';");
     }
     return $row["id"];
 }
function getValueId($_database, $_column, $_value, $_canBeNumeric = true, $_maxlength = null)
{
    if (!$_canBeNumeric && is_numeric($_value)) {
        return $_value;
    }
    if ($_maxlength != null && strlen($_value) > $_maxlength) {
        $_value = substr($_value, 0, $_maxlength);
    }
    queryDB(true, "INSERT IGNORE INTO `" . DB_PREFIX . $_database . "` (`id`, `" . $_column . "`) VALUES (NULL, '" . DBManager::RealEscape($_value) . "');");
    $row = DBManager::FetchArray(queryDB(true, "SELECT `id` FROM `" . DB_PREFIX . $_database . "` WHERE `" . $_column . "`='" . DBManager::RealEscape($_value) . "';"));
    if (is_numeric($row["id"]) || $_value == "INVALID_DATA") {
        return $row["id"];
    } else {
        return getValueId($_database, $_column, "INVALID_DATA", $_canBeNumeric, $_maxlength);
    }
}
 function Save()
 {
     if ($this->IsExternal) {
         $pid = getValueId(DATABASE_VISITOR_DATA_PATHS, "path", $this->Path . $this->Params, false, 255);
     } else {
         $pid = getValueId(DATABASE_VISITOR_DATA_PATHS, "path", $this->Path, false, 255);
     }
     $did = $this->GetDomainId();
     $tid = $this->GetTitleId($did, $pid, 0);
     queryDB(true, "INSERT IGNORE INTO `" . DB_PREFIX . DATABASE_VISITOR_DATA_PAGES . "` (`id`,`path`,`domain`,`title`) VALUES (NULL, '" . DBManager::RealEscape($pid) . "',  '" . DBManager::RealEscape($did) . "',  '" . DBManager::RealEscape($tid) . "');");
     $row = DBManager::FetchArray(queryDB(true, "SELECT `id`,`title` FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_PAGES . "` WHERE `path`='" . DBManager::RealEscape($pid) . "' AND `domain`='" . DBManager::RealEscape($did) . "';"));
     if (STATS_ACTIVE && $tid != $row["title"]) {
         queryDB(true, "UPDATE `" . DB_PREFIX . DATABASE_VISITOR_DATA_PAGES . "` SET `title`=(SELECT `id` FROM `" . DB_PREFIX . DATABASE_VISITOR_DATA_TITLES . "` WHERE id='" . DBManager::RealEscape($tid) . "' OR id='" . DBManager::RealEscape($row["title"]) . "' ORDER BY `confirmed` DESC LIMIT 1) WHERE `path`='" . DBManager::RealEscape($pid) . "' AND `domain`='" . DBManager::RealEscape($did) . "';");
     }
     return $row["id"];
 }