1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
stat_table.php
См. документацию.
1<?
3
5{
6 var $country_avail = false;
7 var $city_avail = false;
8
9 public static function OnCityLookup($arDBRecord = false)
10 {
11 return new CCityLookup_stat_table($arDBRecord);
12 }
13
14 function __construct($arDBRecord = false)
15 {
16 parent::__construct($arDBRecord);
17 $DB = CDatabase::GetModuleConnection('statistic');
18
19 if(!$arDBRecord)
20 {
21 $country_recs = COption::GetOptionString("statistic", "COUNTRY_INDEX_LOADED", "N");
22 if($country_recs !== "Y")
23 {
24 $rs = $DB->Query(CStatistics::DBTopSql("SELECT /*TOP*/ * FROM b_stat_country", 1));
25 if($rs->Fetch())
26 {
27 $country_recs = "Y";
28 COption::SetOptionString("statistic", "COUNTRY_INDEX_LOADED", "Y");
29 }
30 }
31
32 $this->country_avail = $country_recs === "Y";
33
34
35 if($this->country_avail)
36 {
37 $city_recs = COption::GetOptionString("statistic", "CITY_INDEX_LOADED", "N");
38 if($city_recs !== "Y")
39 {
40 $rs = $DB->Query(CStatistics::DBTopSql("SELECT /*TOP*/ * FROM b_stat_city_ip", 1));
41 if($rs->Fetch())
42 COption::SetOptionString("statistic", "CITY_INDEX_LOADED", "Y");
43 }
44 $this->city_avail = COption::GetOptionString("statistic", "CITY_INDEX_LOADED", "N") === "Y";
45 }
46
47 $this->is_installed = $this->country_avail;
48 }
49 }
50
51 function GetFullInfo()
52 {
53 if(!$this->country_full_name && !$this->region_name && !$this->city_name)
54 {
55 if($this->city_id > 0)
56 {
57 $DB = CDatabase::GetModuleConnection('statistic');
58 $rs = $DB->Query("
59 SELECT
60 C.NAME COUNTRY_NAME,
61 CITY.REGION REGION_NAME,
62 CITY.NAME CITY_NAME
63 from
64 b_stat_city CITY
65 INNER JOIN b_stat_country C on C.ID = CITY.COUNTRY_ID
66 WHERE
67 CITY.ID = ".intval($this->city_id));
68 $ar = $rs->Fetch();
69 if($ar)
70 {
71 $this->country_full_name = $ar["COUNTRY_NAME"];
72 $this->region_name = $ar["REGION_NAME"];
73 $this->city_name = $ar["CITY_NAME"];
74 }
75 }
76 }
77 return parent::GetFullInfo();
78 }
79
80 function GetDescription()
81 {
82 return array(
83 "CLASS" => "CCityLookup_stat_table",
84 "DESCRIPTION" => GetMessage("STAT_CITY_TABLE_DESCR", array("#WIZARD_HREF#"=>"javascript:WizardWindow.Open('bitrix:statistic.locations','".bitrix_sessid()."')")),
85 "IS_INSTALLED" => true,
86 "CAN_LOOKUP_COUNTRY" => $this->country_avail,
87 "CAN_LOOKUP_CITY" => $this->city_avail,
88 );
89 }
90
91 function IsInstalled()
92 {
93 return true;
94 }
95
96 function Lookup()
97 {
98 $DB = CDatabase::GetModuleConnection('statistic');
99
100 if($this->city_avail && $this->ip_number)
101 {
102 $rs = $DB->Query("
103 SELECT *
104 FROM b_stat_city_ip
105 WHERE START_IP = (
106 SELECT MAX(START_IP)
107 FROM b_stat_city_ip
108 WHERE START_IP <= ".$this->ip_number."
109 )
110 AND END_IP >= ".$this->ip_number."
111 ", true);
112
113 if($rs)
114 {
115 $ar = $rs->Fetch();
116 if($ar)
117 {
118 $this->country_code = $ar["COUNTRY_ID"];
119 $this->city_id = $ar["CITY_ID"];
120 }
121 }
122 else
123 {
124 //Here is mysql 4.0 version which does not supports subqueries
125 //and not smart to optimeze query
126 $rs = $DB->Query("
127 SELECT START_IP
128 FROM b_stat_city_ip
129 WHERE START_IP <= ".$this->ip_number."
130 ORDER BY START_IP DESC
131 LIMIT 1
132 ");
133 $ar = $rs->Fetch();
134 if($ar && $ar["START_IP"] <> '')
135 {
136 $rs = $DB->Query("
137 SELECT *
138 FROM b_stat_city_ip
139 WHERE START_IP = ".$ar["START_IP"]."
140 AND END_IP >= ".$this->ip_number."
141 ");
142 $ar = $rs->Fetch();
143 if($ar)
144 {
145 $this->country_code = $ar["COUNTRY_ID"];
146 $this->city_id = $ar["CITY_ID"];
147 }
148 }
149 }
150 }
151 if(!$this->country_code && $this->country_avail)
152 {
153 $this->country_code = i2c_get_country();
154 }
155 }
156}
157?>
$city_avail
Определения stat_table.php:7
GetFullInfo()
Определения stat_table.php:51
$country_avail
Определения stat_table.php:6
static OnCityLookup($arDBRecord=false)
Определения stat_table.php:9
IsInstalled()
Определения stat_table.php:91
Lookup()
Определения stat_table.php:96
GetDescription()
Определения stat_table.php:80
__construct($arDBRecord=false)
Определения stat_table.php:14
Определения city.php:10
static DBTopSql($strSql, $nTopCount=false)
Определения statistic.php:628
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
i2c_get_country($ip=false)
Определения ip_tools.php:251
global $DB
Определения cron_frame.php:29
bitrix_sessid()
Определения tools.php:4656
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$ar
Определения options.php:199
$rs
Определения action.php:82