27 if(is_array($arDBRecord))
29 if(array_key_exists(
"IPA", $arDBRecord)) $this->ip_addr = $arDBRecord[
"IPA"];
30 if(array_key_exists(
"IPN", $arDBRecord)) $this->ip_number = $arDBRecord[
"IPN"];
31 if(array_key_exists(
"COC", $arDBRecord)) $this->country_code = $arDBRecord[
"COC"];
32 if(array_key_exists(
"COS", $arDBRecord)) $this->country_short_name = $arDBRecord[
"COS"];
33 if(array_key_exists(
"COF", $arDBRecord)) $this->country_full_name = $arDBRecord[
"COF"];
34 if(array_key_exists(
"REN", $arDBRecord)) $this->region_name = $arDBRecord[
"REN"];
35 if(array_key_exists(
"CIN", $arDBRecord)) $this->city_name = $arDBRecord[
"CIN"];
36 if(array_key_exists(
"CID", $arDBRecord)) $this->city_id = $arDBRecord[
"CID"];
40 $ip = $this->ip_addr =
$_SERVER[
"REMOTE_ADDR"];
79 "VALUE~" => $this->ip_addr,
82 "COUNTRY_CODE" =>
array(
83 "TITLE" =>
GetMessage(
"STAT_CITY_COUNTRY_CODE"),
84 "VALUE~" => $this->country_code,
87 "COUNTRY_NAME" =>
array(
88 "TITLE" =>
GetMessage(
"STAT_CITY_COUNTRY_NAME"),
89 "VALUE~" => $this->country_full_name,
92 "REGION_NAME" =>
array(
93 "TITLE" =>
GetMessage(
"STAT_CITY_REGION_NAME"),
94 "VALUE~" => $this->region_name,
99 "VALUE~" => $this->city_name,
111 $res[
"ID"] =
"CCityLookup";
112 $res[
"DESCRIPTION"] =
"";
113 $res[
"IS_INSTALLED"] =
false;
114 $res[
"CAN_LOOKUP_COUNTRY"] =
true;
115 $res[
"CAN_LOOKUP_CITY"] =
false;
132 $this->country_code =
"N0";
133 $this->country_short_name =
"N00";
134 $this->country_full_name =
"NA";
147 $DB = CDatabase::GetModuleConnection(
'statistic');
149 $arQueryOrder =
array();
150 if(is_array($arOrder))
152 foreach($arOrder as $strColumn => $strDirection)
154 $strColumn = mb_strtoupper($strColumn);
155 $strDirection = mb_strtoupper($strDirection) ===
"ASC"?
"ASC":
"DESC";
159 case "COUNTRY_SHORT_NAME":
162 $arQueryOrder[$strColumn] = $strColumn.
" ".$strDirection;
165 $arQueryOrder[
"COUNTRY_ID"] =
"COUNTRY_ID ".$strDirection;
166 $arQueryOrder[
"REGION_NAME"] =
"REGION_NAME ".$strDirection;
176 "COUNTRY_ID" =>
array(
177 "TABLE_ALIAS" =>
"R",
178 "FIELD_NAME" =>
"R.COUNTRY_ID",
179 "FIELD_TYPE" =>
"string",
182 "COUNTRY_SHORT_NAME" =>
array(
183 "TABLE_ALIAS" =>
"C",
184 "FIELD_NAME" =>
"C.SHORT_NAME",
185 "FIELD_TYPE" =>
"string",
188 "COUNTRY_NAME" =>
array(
189 "TABLE_ALIAS" =>
"C",
190 "FIELD_NAME" =>
"C.NAME",
191 "FIELD_TYPE" =>
"string",
194 "REGION_NAME" =>
array(
195 "TABLE_ALIAS" =>
"R",
196 "FIELD_NAME" =>
"R.REGION",
197 "FIELD_TYPE" =>
"string",
205 ,C.SHORT_NAME COUNTRY_SHORT_NAME
207 ,R.REGION REGION_NAME
210 INNER JOIN b_stat_country C on C.ID = R.COUNTRY_ID
213 $strQueryWhere = $obQueryWhere->GetQuery(
$arFilter);
215 if($strQueryWhere <>
'')
224 R.COUNTRY_ID, R.REGION, C.SHORT_NAME, C.NAME
227 if(
count($arQueryOrder) > 0)
231 ".implode(
", ", $arQueryOrder).
"
235 return $DB->Query($strSql);
241 private $lookup_class =
"";
242 private $lookup =
null;
243 private $country_code =
"";
244 private $city_id =
"";
252 $arDBRecord = unserialize($dbRecord, [
'allowed_classes' =>
false]);
256 if(is_array($arDBRecord))
258 $this->lookup_class = $arDBRecord[
"LC"];
259 if(!$this->lookup_class || !class_exists(mb_strtolower($this->lookup_class)))
260 $this->lookup_class =
"CCityLookup";
262 $this->lookup = call_user_func_array(
array($this->lookup_class,
"OnCityLookup"),
array($arDBRecord[
"LD"]));
264 $this->country_code = $arDBRecord[
"CC"];
265 $this->city_id = $arDBRecord[
"CI"];
270 if(!$this->lookup_class || !class_exists(mb_strtolower($this->lookup_class)))
271 $this->lookup_class =
"CCityLookup";
273 $ob = call_user_func_array(
array($this->lookup_class,
"OnCityLookup"),
array());
275 if(!$ob || !$ob->IsInstalled())
277 $this->lookup_class =
"CCityLookup";
294 $DB = CDatabase::GetModuleConnection(
'statistic');
296 if(!is_array($arOrder))
299 $arQueryOrder =
array();
300 foreach($arOrder as $strColumn => $strDirection)
302 $strColumn = mb_strtoupper($strColumn);
303 $strDirection = mb_strtoupper($strDirection) ===
"ASC"?
"ASC":
"DESC";
307 case "COUNTRY_SHORT_NAME":
311 $arQueryOrder[$strColumn] = $strColumn.
" ".$strDirection;
314 $arQueryOrder[
"COUNTRY_ID"] =
"COUNTRY_ID ".$strDirection;
315 $arQueryOrder[
"REGION_NAME"] =
"REGION_NAME ".$strDirection;
316 $arQueryOrder[
"CITY_NAME"] =
"CITY_NAME ".$strDirection;
326 "TABLE_ALIAS" =>
"CITY",
327 "FIELD_NAME" =>
"CITY.ID",
328 "FIELD_TYPE" =>
"int",
331 "COUNTRY_ID" =>
array(
332 "TABLE_ALIAS" =>
"CITY",
333 "FIELD_NAME" =>
"CITY.COUNTRY_ID",
334 "FIELD_TYPE" =>
"string",
337 "COUNTRY_SHORT_NAME" =>
array(
338 "TABLE_ALIAS" =>
"C",
339 "FIELD_NAME" =>
"C.SHORT_NAME",
340 "FIELD_TYPE" =>
"string",
343 "COUNTRY_NAME" =>
array(
344 "TABLE_ALIAS" =>
"C",
345 "FIELD_NAME" =>
"C.NAME",
346 "FIELD_TYPE" =>
"string",
349 "REGION_NAME" =>
array(
350 "TABLE_ALIAS" =>
"CITY",
351 "FIELD_NAME" =>
"CITY.REGION",
352 "FIELD_TYPE" =>
"string",
355 "CITY_NAME" =>
array(
356 "TABLE_ALIAS" =>
"CITY",
357 "FIELD_NAME" =>
"CITY.NAME",
358 "FIELD_TYPE" =>
"string",
367 ,C.SHORT_NAME COUNTRY_SHORT_NAME
369 ,CITY.REGION REGION_NAME
373 INNER JOIN b_stat_country C on C.ID = CITY.COUNTRY_ID
375 $strQueryWhere = $obQueryWhere->GetQuery(
$arFilter);
377 if($strQueryWhere <>
'')
385 if(
count($arQueryOrder) > 0)
389 ".implode(
", ", $arQueryOrder).
"
393 return $DB->Query($strSql);
402 $DB = CDatabase::GetModuleConnection(
'statistic');
404 "LC" => $this->lookup_class,
405 "LD" => $this->lookup->ArrayForDB(),
406 "CC" => $this->country_code,
407 "CI" => $this->city_id,
414 return $this->lookup->GetFullInfo();
419 $selected = COption::GetOptionString(
"statistic",
"IP_LOOKUP_CLASS",
"");
422 $arResolvers =
array();
423 foreach(
GetModuleEvents(
"statistic",
"OnCityLookup",
true) as $arEvent)
426 $ar = $ob->GetDescription();
427 $arResolvers[
$ar[
"CLASS"]] = $ob;
429 if(!array_key_exists($selected, $arResolvers))
431 foreach($arResolvers as
$ID => $ob)
433 if($ob->IsInstalled())
440 COption::SetOptionString(
"statistic",
"IP_LOOKUP_CLASS", $selected);
447 if(!$this->country_code)
449 $this->lookup->Lookup();
450 $this->country_code = $this->lookup->country_code;
452 return $this->country_code? $this->country_code:
"N0";
457 if(
$str && $this->lookup->charset)
466 $DB = CDatabase::GetModuleConnection(
'statistic');
470 $this->city_id = $this->lookup->city_id;
474 $city_name = $this->
Recode($this->lookup->city_name);
475 $region_name = $this->
Recode($this->lookup->region_name);
480 WHERE COUNTRY_ID = '".
$DB->ForSQL($country_code, 2).
"'
481 AND ".($region_name?
"REGION = '".$DB->ForSQL($region_name, 255).
"'":
"REGION IS NULL").
"
482 AND ".($city_name?
"NAME = '".$DB->ForSQL($city_name, 255).
"'":
"NAME IS NULL").
"
487 $this->city_id =
$ar[
"ID"];
494 WHERE ID = '".
$DB->ForSQL($country_code, 2).
"'
499 $country_short_name = $this->
Recode($this->lookup->country_short_name);
500 $country_full_name = $this->
Recode($this->lookup->country_full_name);
502 INSERT INTO b_stat_country (ID, SHORT_NAME, NAME) VALUES (
503 '".
$DB->ForSql($country_code, 2).
"',
504 ".($country_short_name?
"'".$DB->ForSql($country_short_name, 3).
"'":
"'N00'").
",
505 ".($country_full_name?
"'".$DB->ForSql($country_full_name, 50).
"'":
"'NA'").
"
509 $this->city_id =
$DB->Add(
"b_stat_city",
array(
510 "COUNTRY_ID" => $country_code,
511 "REGION" => $region_name ? $region_name:
false,
512 "NAME" => $city_name ? $city_name:
false,
516 return $this->city_id > 0? intval($this->city_id):
"";
522 $DB = CDatabase::GetModuleConnection(
'statistic');
523 $arSqlSearch = Array();
535 if( ((
string)
$val ==
'') || (
$val ===
"NOT_REF") )
538 $match_value_set = array_key_exists(
$key.
"_EXACT_MATCH",
$arFilter);
548 $arSqlSearch[] =
"D.DATE_STAT>=".$DB->CharToDateFunction(
$val,
"SHORT");
552 $arSqlSearch[] =
"D.DATE_STAT<=".$DB->CharToDateFunction(
$val.
" 23:59:59",
"FULL");
562 ".$DB->DateToCharFunction(
"D.DATE_STAT",
"SHORT").
" DATE_STAT,
563 ".
$DB->DateFormatToDB(
"DD",
"D.DATE_STAT").
" DAY,
564 ".
$DB->DateFormatToDB(
"MM",
"D.DATE_STAT").
" MONTH,
565 ".
$DB->DateFormatToDB(
"YYYY",
"D.DATE_STAT").
" YEAR,
572 C.SESSIONS TOTAL_SESSIONS,
573 C.NEW_GUESTS TOTAL_NEW_GUESTS,
575 C.C_EVENTS TOTAL_C_EVENTS
578 INNER JOIN b_stat_city C ON (C.ID = D.CITY_ID)
582 D.DATE_STAT, D.CITY_ID
585 $rsD =
$DB->Query($strSql);
586 while ($arD = $rsD->Fetch())
588 $arrDays[$arD[
"DATE_STAT"]][
"D"] = $arD[
"DAY"];
589 $arrDays[$arD[
"DATE_STAT"]][
"M"] = $arD[
"MONTH"];
590 $arrDays[$arD[
"DATE_STAT"]][
"Y"] = $arD[
"YEAR"];
591 $arrDays[$arD[
"DATE_STAT"]][$arD[
"CITY_ID"]][
"SESSIONS"] = $arD[
"SESSIONS"];
592 $arrDays[$arD[
"DATE_STAT"]][$arD[
"CITY_ID"]][
"NEW_GUESTS"] = $arD[
"NEW_GUESTS"];
593 $arrDays[$arD[
"DATE_STAT"]][$arD[
"CITY_ID"]][
"HITS"] = $arD[
"HITS"];
594 $arrDays[$arD[
"DATE_STAT"]][$arD[
"CITY_ID"]][
"C_EVENTS"] = $arD[
"C_EVENTS"];
596 $arLegend[$arD[
"CITY_ID"]][
"CITY_ID"] = intval($arD[
"CITY_ID"]);
597 $arLegend[$arD[
"CITY_ID"]][
"NAME"] = $arD[
"NAME"];
598 $arLegend[$arD[
"CITY_ID"]][
"SESSIONS"] += $arD[
"SESSIONS"];
599 $arLegend[$arD[
"CITY_ID"]][
"NEW_GUESTS"] += $arD[
"NEW_GUESTS"];
600 $arLegend[$arD[
"CITY_ID"]][
"HITS"] += $arD[
"HITS"];
601 $arLegend[$arD[
"CITY_ID"]][
"C_EVENTS"] += $arD[
"C_EVENTS"];
603 $arLegend[$arD[
"CITY_ID"]][
"TOTAL_SESSIONS"] = $arD[
"TOTAL_SESSIONS"];
604 $arLegend[$arD[
"CITY_ID"]][
"TOTAL_NEW_GUESTS"] = $arD[
"TOTAL_NEW_GUESTS"];
605 $arLegend[$arD[
"CITY_ID"]][
"TOTAL_HITS"] = $arD[
"TOTAL_HITS"];
606 $arLegend[$arD[
"CITY_ID"]][
"TOTAL_C_EVENTS"] = $arD[
"TOTAL_C_EVENTS"];
623 "TOTAL_SESSIONS" => 0,
624 "TOTAL_NEW_GUESTS" => 0,
626 "TOTAL_C_EVENTS" => 0,
629 while(
count($arLegend) > $top)
632 $tail = array_pop($arLegend);
633 $totals[
"SESSIONS"] += $tail[
"SESSIONS"];
634 $totals[
"NEW_GUESTS"] += $tail[
"NEW_GUESTS"];
635 $totals[
"HITS"] += $tail[
"HITS"];
636 $totals[
"C_EVENTS"] += $tail[
"C_EVENTS"];
637 $totals[
"TOTAL_SESSIONS"] += $tail[
"TOTAL_SESSIONS"];
638 $totals[
"TOTAL_NEW_GUESTS"] += $tail[
"TOTAL_NEW_GUESTS"];
639 $totals[
"TOTAL_HITS"] += $tail[
"TOTAL_HITS"];
640 $totals[
"TOTAL_C_EVENTS"] += $tail[
"TOTAL_C_EVENTS"];
643 $arLegend[0] = $totals;
645 foreach($arrDays as $DATE_STAT => $arDate)
647 foreach($arDate as $CITY_ID => $arCity)
649 if(intval($CITY_ID) > 0)
651 if(!array_key_exists($CITY_ID, $arLegend))
653 $arrDays[$DATE_STAT][0][
"CITY_ID"] = 0;
654 $arrDays[$DATE_STAT][0][
"NAME"] =
GetMessage(
"STAT_CITY_OTHER");
655 $arrDays[$DATE_STAT][0][
"SESSIONS"] += $arCity[
"SESSIONS"];
656 $arrDays[$DATE_STAT][0][
"NEW_GUESTS"] += $arCity[
"NEW_GUESTS"];
657 $arrDays[$DATE_STAT][0][
"HITS"] += $arCity[
"HITS"];
658 $arrDays[$DATE_STAT][0][
"C_EVENTS"] += $arCity[
"C_EVENTS"];
659 unset($arrDays[$DATE_STAT][$CITY_ID]);
667 $total =
count($arLegend);
670 if ($arCityColor[
$key] <>
'')
672 $color = $arCityColor[
$key];
677 $color_getnext = $color;
679 $arr[
"COLOR"] = $color;
692 while(
false!==($fname = readdir(
$handle)))
694 if (is_file(
$_SERVER[
"DOCUMENT_ROOT"].
$path.
"/".$fname) && $fname!=
"." && $fname!=
"..")
696 $ext = mb_substr(mb_strtolower($fname), -4);
697 if($ext ===
".csv" || $ext ===
".txt")
714 case "MAXMIND-IP-COUNTRY":
715 if(
$type ==
'country')
718 "SIZE" => filesize(
$_SERVER[
"DOCUMENT_ROOT"].
$path.
"/".$file),
719 "SOURCE" =>
"MAXMIND-IP-COUNTRY",
722 case "IP-TO-COUNTRY":
723 if(
$type ==
'country')
726 "SIZE" => filesize(
$_SERVER[
"DOCUMENT_ROOT"].
$path.
"/".$file),
727 "SOURCE" =>
"IP-TO-COUNTRY",
730 case "MAXMIND-IP-LOCATION":
734 "SIZE" => filesize(
$_SERVER[
"DOCUMENT_ROOT"].
$path.
"/".$file),
735 "SOURCE" =>
"MAXMIND-IP-LOCATION",
738 case "MAXMIND-CITY-LOCATION":
742 "SIZE" => filesize(
$_SERVER[
"DOCUMENT_ROOT"].
$path.
"/".$file),
743 "SOURCE" =>
"MAXMIND-CITY-LOCATION",
750 "SIZE" => filesize(
$_SERVER[
"DOCUMENT_ROOT"].
$path.
"/".$file),
751 "SOURCE" =>
"IPGEOBASE",
758 "SIZE" => filesize(
$_SERVER[
"DOCUMENT_ROOT"].
$path.
"/".$file),
759 "SOURCE" =>
"IPGEOBASE2",
762 case "IPGEOBASE2-CITY":
766 "SIZE" => filesize(
$_SERVER[
"DOCUMENT_ROOT"].
$path.
"/".$file),
767 "SOURCE" =>
"IPGEOBASE2-CITY",
779 $line = trim(fgets($fp, 1024),
" \t\n\r");
780 if(preg_match(
'/maxmind/i', $line))
781 $line = trim(fgets($fp, 1024),
" \t\n\r");
784 preg_match(
'/^"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})","(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})","(\d+)","(\d+)","..",".*?"$/', $line, $match)
789 return "MAXMIND-IP-COUNTRY";
792 preg_match(
'/^"\d+","\d+","..","...",".*?"$/', $line)
795 return "IP-TO-COUNTRY";
798 preg_match(
'/^startIpNum,endIpNum,locId$/', $line)
801 return "MAXMIND-IP-LOCATION";
804 preg_match(
'/^locId,country,region,city,postalCode,latitude,longitude,metroCode,areaCode$/', $line)
807 return "MAXMIND-CITY-LOCATION";
810 preg_match(
'/^(\d+)\t(\d+)\t(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) - (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\t(..)\t(.+?)\t(.+?)\t(.+?)\t(.+?)\t(.+)$/', $line, $match)
818 preg_match(
'/^(\d+)\t(\d+)\t(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) - (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\t(..)/', $line, $match)
826 preg_match(
'/^\d+\t(.+?)\t(.+?)\t(.+?)\t([0-9.]+?)\t([0-9.]+?)$/', $line)
829 return "IPGEOBASE2-CITY";
841 $rsConflictIP =
$DB->Query(
"
842 select * from b_stat_city_ip
843 where start_ip between ".$newStartIP.
" and ".$newEndIP.
"
845 select * from b_stat_city_ip
846 where end_ip between ".$newStartIP.
" and ".$newEndIP.
"
848 select * from b_stat_city_ip
852 WHERE START_IP <= ".$newStartIP.
"
854 AND END_IP >= ".$newStartIP.
"
858 while($arConflictIP = $rsConflictIP->Fetch())
862 $arConflictIP[
"START_IP"] == $newStartIP
863 && $arConflictIP[
"END_IP"] == $newEndIP
866 $arToUpdate = $arConflictIP;
870 $newStartIP <= $arConflictIP[
"START_IP"]
871 && $newEndIP < $arConflictIP[
"END_IP"]
876 UPDATE b_stat_city_ip
877 SET START_IP = '".($newEndIP+1).
"'
878 WHERE START_IP = '".$arConflictIP[
"START_IP"].
"'
883 DELETE FROM b_stat_city_ip
884 WHERE START_IP = '".$arConflictIP[
"START_IP"].
"'
889 $newStartIP <= $arConflictIP[
"START_IP"]
890 && $arConflictIP[
"END_IP"] < $newEndIP
895 DELETE FROM b_stat_city_ip
896 WHERE START_IP = '".$arConflictIP[
"START_IP"].
"'
901 $arConflictIP[
"START_IP"] < $newStartIP
902 && $arConflictIP[
"END_IP"] <= $newEndIP
907 UPDATE b_stat_city_ip
908 SET END_IP = '".($newStartIP-1).
"'
909 WHERE START_IP = '".$arConflictIP[
"START_IP"].
"'
920 UPDATE b_stat_city_ip
921 SET END_IP = '".($newStartIP-1).
"'
922 WHERE START_IP = '".$arConflictIP[
"START_IP"].
"'
925 INSERT INTO b_stat_city_ip
926 (START_IP, END_IP, COUNTRY_ID, CITY_ID)
928 ('".($newEndIP+1).
"', '".$arConflictIP[
"END_IP"].
"', '".$arConflictIP[
"COUNTRY_ID"].
"', '".$arConflictIP[
"CITY_ID"].
"')
933 DELETE FROM b_stat_city_ip
934 WHERE START_IP = '".$arConflictIP[
"START_IP"].
"'
943 public static function LoadCSV($file_name, $step, &$file_position)
945 $DB = CDatabase::GetModuleConnection(
'statistic');
947 $arLookupCache =
array();
948 $arCountryCache =
array();
950 $fp = fopen(
$_SERVER[
"DOCUMENT_ROOT"].$file_name,
"rb");
955 $file_position = intval($file_position);
956 fseek($fp, $file_position);
959 $end_time = microtime(
true) + $step;
965 case "MAXMIND-IP-COUNTRY":
968 $table_name =
"b_stat_country";
969 $arFieldsMap =
array(
970 "ID" =>
array(
"key" =>
true,
"index" => 4,
"type" =>
"varchar",
"len" => 2,
"default" =>
"NA"),
971 "NAME" =>
array(
"index" => 5,
"type" =>
"varchar",
"len" => 50,
"default" =>
"N00",
"enc" =>
true),
974 case "IP-TO-COUNTRY":
977 $table_name =
"b_stat_country";
978 $arFieldsMap =
array(
979 "ID" =>
array(
"key" =>
true,
"index" => 2,
"type" =>
"varchar",
"len" => 2,
"default" =>
"NA"),
980 "SHORT_NAME" =>
array(
"index" => 3,
"type" =>
"varchar",
"len" => 3,
"default" =>
"N00"),
981 "NAME" =>
array(
"index" => 4,
"type" =>
"varchar",
"len" => 50,
"enc" =>
true),
984 case "MAXMIND-IP-LOCATION":
987 $table_name =
"b_stat_city_ip";
988 $arFieldsMap =
array(
989 "START_IP" =>
array(
"key" =>
true,
"index" => 0,
"type" =>
"ipnum"),
990 "END_IP" =>
array(
"index" => 1,
"type" =>
"ipnum"),
991 "XML_ID" =>
array(
"index" => 2,
"type" =>
"lookup"),
992 "COUNTRY_ID" =>
array(
"index" => -1,
"type" =>
"varchar"),
993 "CITY_ID" =>
array(
"index" => -2,
"type" =>
"number"),
996 if($file_position <= 0)
1002 case "MAXMIND-CITY-LOCATION":
1004 $char_set =
"iso-8859-1";
1005 $table_name =
"b_stat_city";
1006 $arFieldsMap =
array(
1007 "COUNTRY_ID" =>
array(
"index" => 1,
"type" =>
"varchar",
"len" => 2,
"default" =>
"NA"),
1008 "REGION" =>
array(
"index" => 2,
"type" =>
"varchar",
"len" => 255,
"enc" =>
true),
1009 "NAME" =>
array(
"index" => 3,
"type" =>
"varchar",
"len" => 255,
"enc" =>
true),
1010 "XML_ID" =>
array(
"key" =>
true,
"index" => 0,
"type" =>
"varchar",
"len" => 255),
1013 if($file_position <= 0)
1021 $char_set =
"Windows-1251";
1022 $table_name =
"b_stat_city_ip";
1023 $arFieldsMap =
array(
1024 "START_IP" =>
array(
"key" =>
true,
"index" => 0,
"type" =>
"ipnum"),
1025 "END_IP" =>
array(
"index" => 1,
"type" =>
"ipnum"),
1026 "COUNTRY_ID" =>
array(
"index" => 3,
"type" =>
"varchar",
"len" => 2,
"default" =>
"NA"),
1027 "XML_ID" =>
array(
"index" =>
array(3, 4, 5),
"type" =>
"upsert",
"enc" =>
true,
1029 "COUNTRY_ID" =>
array(
"index" => 3,
"type" =>
"varchar",
"len" => 2,
"default" =>
"NA"),
1030 "REGION" =>
array(
"index" => 5,
"type" =>
"varchar",
"len" => 255,
"enc" =>
true),
1031 "NAME" =>
array(
"index" => 4,
"type" =>
"varchar",
"len" => 255,
"enc" =>
true),
1034 "CITY_ID" =>
array(
"index" => -1,
"type" =>
"number"),
1039 $char_set =
"Windows-1251";
1040 $table_name =
"b_stat_city_ip";
1041 $arFieldsMap =
array(
1042 "START_IP" =>
array(
"key" =>
true,
"index" => 0,
"type" =>
"ipnum"),
1043 "END_IP" =>
array(
"index" => 1,
"type" =>
"ipnum"),
1044 "COUNTRY_ID" =>
array(
"index" => 3,
"type" =>
"varchar",
"len" => 2,
"default" =>
"NA",
"update_city" => 4),
1045 "XML_ID" =>
array(
"index" => 4,
"type" =>
"lookup"),
1046 "CITY_ID" =>
array(
"index" => -1,
"type" =>
"number"),
1049 case "IPGEOBASE2-CITY":
1051 $char_set =
"Windows-1251";
1052 $table_name =
"b_stat_city";
1053 $arFieldsMap =
array(
1054 "COUNTRY_ID" =>
array(
"skip_update" =>
true,
"index" => 100,
"type" =>
"varchar",
"len" => 2,
"default" =>
"NA"),
1055 "REGION" =>
array(
"index" => 2,
"type" =>
"varchar",
"len" => 255,
"enc" =>
true),
1056 "NAME" =>
array(
"index" => 1,
"type" =>
"varchar",
"len" => 255,
"enc" =>
true),
1057 "XML_ID" =>
array(
"key" =>
true,
"index" => 0,
"type" =>
"varchar",
"len" => 255),
1069 $arr = fgets($fp, 4096);
1070 if($bConv && preg_match(
"/[^a-zA-Z0-9 \t\n\r]/",
$arr))
1072 $arr = preg_split(
"/".$delimiter.
"/u",
$arr);
1074 $arAllSQLFields =
array();
1081 foreach($arFieldsMap as $FIELD_ID => $arField)
1083 if(is_array($arField[
"index"]))
1086 foreach($arField[
"index"] as $index)
1087 $value .= trim(
$arr[$index],
"\" \n\r\t");
1088 $value = md5($value);
1092 $value = trim(
$arr[$arField[
"index"]],
"\" \n\r\t");
1094 if(!$value && $arField[
"default"])
1095 $value = $arField[
"default"];
1097 if($arField[
"type"] ==
"upsert")
1099 if(!array_key_exists($value, $arLookupCache))
1101 $rs =
$DB->Query(
"SELECT ID as CITY_ID FROM b_stat_city WHERE XML_ID = '".
$DB->ForSQL($value).
"'");
1105 $arNewMaster =
array(
1108 foreach($arField[
"master"] as $MASTER_FIELD_ID => $arMasterField)
1110 $m_value = trim(
$arr[$arMasterField[
"index"]],
"\"");
1111 if(!$m_value && $arMasterField[
"default"])
1112 $m_value = $arMasterField[
"default"];
1113 $arNewMaster[$MASTER_FIELD_ID] = $m_value;
1115 $ar =
array(
"CITY_ID" =>
$DB->Add(
"b_stat_city", $arNewMaster));
1117 $arLookupCache[$value] =
$ar;
1119 foreach($arLookupCache[$value] as
$key =>
$val)
1124 if($arField[
"type"] ==
"lookup")
1126 if(!array_key_exists($value, $arLookupCache))
1128 $rs =
$DB->Query(
"SELECT COUNTRY_ID, ID as CITY_ID FROM b_stat_city WHERE XML_ID = '".
$DB->ForSQL($value).
"'");
1131 $ar =
array(
"COUNTRY_ID" =>
"NA",
"CITY_ID" => 0);
1132 $arLookupCache[$value] =
$ar;
1134 foreach($arLookupCache[$value] as
$key =>
$val)
1140 $FIELD_ID ===
"COUNTRY_ID"
1141 && !array_key_exists($value, $arCountryCache)
1145 $cid =
$DB->ForSQL($value, 2);
1146 $rs =
$DB->Query(
"SELECT ID FROM b_stat_country WHERE ID = '".$cid.
"'");
1148 $DB->Query(
"insert into b_stat_country (ID) values ('".$cid.
"')");
1149 $arCountryCache[$value] =
true;
1153 $FIELD_ID ===
"COUNTRY_ID"
1154 && isset($arField[
"update_city"])
1158 $city_id =
$DB->ForSQL(trim(
$arr[$arField[
"update_city"]],
"\" \n\r\t"));
1159 $cid =
$DB->ForSQL($value, 2);
1160 $rs =
$DB->Query(
"UPDATE b_stat_city SET COUNTRY_ID = '".$cid.
"' WHERE XML_ID = '".$city_id.
"'");
1163 switch($arField[
"type"])
1166 $sql_value =
"'".$DB->ForSQL($value, $arField[
"len"]).
"'";
1170 $sql_value = preg_replace(
"/[^0-9]/",
"", $value);
1173 $sql_value =
"'".$DB->ForSQL($value).
"'";
1177 $arAllSQLFields[$FIELD_ID] = $sql_value;
1184 $strWhere .=
" AND ";
1185 $strWhere .= $FIELD_ID.
" = ".$sql_value;
1197 $strUpdate .= $FIELD_ID.
" = ".$sql_value;
1201 $strInsert1 .=
", ";
1202 $strInsert1 .= $FIELD_ID;
1205 $strInsert2 .=
", ";
1206 $strInsert2 .= $sql_value;
1209 if(!$bEmptyKey && $strWhere && $strUpdate && !array_key_exists($strWhere, $arCache))
1211 if($table_name ==
"b_stat_city_ip" && $arAllSQLFields[
"START_IP"] && $arAllSQLFields[
"END_IP"])
1217 $rs =
$DB->Query(
"SELECT * FROM $table_name WHERE $strWhere");
1218 $arToUpdate =
$rs->Fetch();
1222 $bNeedUpdate =
false;
1223 foreach(
$arFields as $UPD_FIELD_ID => $upd_value)
1225 if(!isset($arFieldsMap[$UPD_FIELD_ID][
"skip_update"]))
1227 if($upd_value != $arToUpdate[$UPD_FIELD_ID])
1229 $bNeedUpdate =
true;
1235 $DB->Query(
"UPDATE $table_name SET $strUpdate WHERE $strWhere");
1239 $DB->Query(
"INSERT INTO $table_name ($strInsert1) VALUES ($strInsert2)");
1241 $arCache[$strWhere] =
true;
1244 if($end_time && microtime(
true) > $end_time)
1246 $file_position = ftell($fp);
1250 $file_position = ftell($fp);
static convertEncoding($data, $charsetFrom, $charsetTo)
__construct($dbRecord="")
static GetCSVFormatType($fp)
static ResolveIPRange($newStartIP, $newEndIP)
static GetGraphArray($arFilter, &$arLegend, $sort=false, $top=0)
static FindFiles($type='country', $path='/bitrix/modules/statistic/ip2country')
static LoadCSV($file_name, $step, &$file_position)
static GetList($arOrder=array(), $arFilter=array())
static OnCityLookup($arDBRecord=array())
__construct($arDBRecord=array())
GetList($arOrder=array(), $arFilter=array())
static Sort(&$ar, $field)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$_SERVER["DOCUMENT_ROOT"]
GetNextRGB($base_color, $total)
ExecuteModuleEventEx($arEvent, $arParams=[])
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
CheckDateTime($datetime, $format=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"