1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | Plugin : AStat.2 |
---|
4 | Author : Grum |
---|
5 | email : grum@piwigo.org |
---|
6 | website : http://photos.grum.dnsalias.com |
---|
7 | |
---|
8 | << May the Little SpaceFrog be with you ! >> |
---|
9 | ------------------------------------------------------------------------------ |
---|
10 | See main.inc.php for release information |
---|
11 | |
---|
12 | AI classe => manage integration in administration interface |
---|
13 | |
---|
14 | --------------------------------------------------------------------------- */ |
---|
15 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
---|
16 | |
---|
17 | include_once('astat_aim.class.inc.php'); |
---|
18 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
19 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); |
---|
20 | |
---|
21 | class AStat_AIP extends AStat_AIM |
---|
22 | { |
---|
23 | protected $tabsheet; |
---|
24 | protected $list_periods = array('global', 'all', 'year', 'month', 'day'); |
---|
25 | protected $list_sortcat = array('page', 'picture', 'nbpicture'); |
---|
26 | protected $list_sortimg = array('picture', 'catname'); |
---|
27 | protected $list_sortip = array('page', 'picture', 'ip'); |
---|
28 | |
---|
29 | protected $catfilter; //filter on categories |
---|
30 | protected $max_width; |
---|
31 | protected $seetimerequest; |
---|
32 | |
---|
33 | function AStat_AIP($prefixeTable, $filelocation) |
---|
34 | { |
---|
35 | parent::__construct($prefixeTable, $filelocation); |
---|
36 | |
---|
37 | $this->loadConfig(); |
---|
38 | $this->initEvents(); |
---|
39 | |
---|
40 | $this->tabsheet = new tabsheet(); |
---|
41 | $this->tabsheet->add('stats_by_period', |
---|
42 | l10n('AStat_by_period'), |
---|
43 | $this->getAdminLink().'&fAStat_tabsheet=stats_by_period'); |
---|
44 | $this->tabsheet->add('stats_by_ip', |
---|
45 | l10n('AStat_by_ip'), |
---|
46 | $this->getAdminLink().'&fAStat_tabsheet=stats_by_ip'); |
---|
47 | $this->tabsheet->add('stats_by_category', |
---|
48 | l10n('AStat_by_category'), |
---|
49 | $this->getAdminLink().'&fAStat_tabsheet=stats_by_category'); |
---|
50 | $this->tabsheet->add('stats_by_image', |
---|
51 | l10n('AStat_by_image'), |
---|
52 | $this->getAdminLink().'&fAStat_tabsheet=stats_by_image'); |
---|
53 | $this->tabsheet->add('config', |
---|
54 | l10n('AStat_config'), |
---|
55 | $this->getAdminLink().'&fAStat_tabsheet=config'); |
---|
56 | $this->tabsheet->add('tools', |
---|
57 | l10n('AStat_tools'), |
---|
58 | $this->getAdminLink().'&fAStat_tabsheet=tools'); |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | /* |
---|
63 | initialize events call for the plugin |
---|
64 | */ |
---|
65 | function initEvents() |
---|
66 | { |
---|
67 | add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS')); |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | /* --------------------------------------------------------------------------- |
---|
73 | Public classe functions |
---|
74 | --------------------------------------------------------------------------- */ |
---|
75 | |
---|
76 | /* |
---|
77 | manage plugin integration into piwigo's admin interface |
---|
78 | */ |
---|
79 | public function manage() |
---|
80 | { |
---|
81 | global $template; |
---|
82 | |
---|
83 | $this->return_ajax_content(); |
---|
84 | |
---|
85 | $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/astat_admin.tpl"); |
---|
86 | |
---|
87 | $this->init_request(); |
---|
88 | |
---|
89 | $this->make_filter_list($_REQUEST['fAStat_catfilter']); |
---|
90 | if($_REQUEST['fAStat_catfilter']!="") |
---|
91 | { |
---|
92 | $this->setAdminLink($this->getAdminLink()."&fAStat_catfilter=".$_REQUEST['fAStat_catfilter']); |
---|
93 | } |
---|
94 | |
---|
95 | if($_REQUEST['fAStat_tabsheet']=='stats_by_period') |
---|
96 | { |
---|
97 | $this->display_stats_by_period( |
---|
98 | $_REQUEST['fAStat_all'], |
---|
99 | $_REQUEST['fAStat_year'], |
---|
100 | $_REQUEST['fAStat_month'], |
---|
101 | $_REQUEST['fAStat_day'], |
---|
102 | $this->config['AStat_MaxBarWidth'], |
---|
103 | $this->config['AStat_SeeTimeRequests'] |
---|
104 | ); |
---|
105 | } |
---|
106 | elseif($_REQUEST['fAStat_tabsheet']=='stats_by_ip') |
---|
107 | { |
---|
108 | if(isset($_REQUEST['fAStat_IP_BL'])) |
---|
109 | { |
---|
110 | $this->add_ip_to_filter($_REQUEST['fAStat_IP_BL']); |
---|
111 | } |
---|
112 | |
---|
113 | $this->display_stats_by_ip( |
---|
114 | $_REQUEST['fAStat_year'], |
---|
115 | $_REQUEST['fAStat_month'], |
---|
116 | $_REQUEST['fAStat_day'], |
---|
117 | $this->config['AStat_MaxBarWidth'], |
---|
118 | $this->config['AStat_NpIPPerPages'], |
---|
119 | $_REQUEST['fAStat_page_number'], |
---|
120 | $_REQUEST['fAStat_SortIP'], |
---|
121 | $this->config['AStat_SeeTimeRequests'] |
---|
122 | ); |
---|
123 | } |
---|
124 | elseif($_REQUEST['fAStat_tabsheet']=='stats_by_category') |
---|
125 | { |
---|
126 | $this->display_stats_by_category( |
---|
127 | $_REQUEST['fAStat_year'], |
---|
128 | $_REQUEST['fAStat_month'], |
---|
129 | $_REQUEST['fAStat_day'], |
---|
130 | $this->config['AStat_MaxBarWidth'], |
---|
131 | $this->config['AStat_NpCatPerPages'], |
---|
132 | $_REQUEST['fAStat_page_number'], |
---|
133 | $this->config['AStat_ShowThumbCat'], |
---|
134 | $_REQUEST['fAStat_SortCat'], |
---|
135 | $this->config['AStat_SeeTimeRequests'] |
---|
136 | ); |
---|
137 | } |
---|
138 | elseif($_REQUEST['fAStat_tabsheet']=='stats_by_image') |
---|
139 | { |
---|
140 | $this->display_stats_by_image( |
---|
141 | $_REQUEST['fAStat_year'], |
---|
142 | $_REQUEST['fAStat_month'], |
---|
143 | $_REQUEST['fAStat_day'], |
---|
144 | $this->config['AStat_MaxBarWidth'], |
---|
145 | $this->config['AStat_NbImgPerPages'], |
---|
146 | $_REQUEST['fAStat_page_number'], |
---|
147 | $this->config['AStat_ShowThumbImg'], |
---|
148 | $_REQUEST['fAStat_SortImg'], |
---|
149 | $_REQUEST['fAStat_IP'], |
---|
150 | $this->config['AStat_SeeTimeRequests'] |
---|
151 | ); |
---|
152 | } |
---|
153 | elseif($_REQUEST['fAStat_tabsheet']=='config') |
---|
154 | { |
---|
155 | $this->display_config(); |
---|
156 | } |
---|
157 | elseif($_REQUEST['fAStat_tabsheet']=='tools') |
---|
158 | { |
---|
159 | $this->display_tools(); |
---|
160 | } |
---|
161 | |
---|
162 | $this->tabsheet->select($_REQUEST['fAStat_tabsheet']); |
---|
163 | $this->tabsheet->assign(); |
---|
164 | $selected_tab=$this->tabsheet->get_selected(); |
---|
165 | $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]"); |
---|
166 | |
---|
167 | $template_plugin["ASTAT_VERSION"] = "<i>AStat</i> ".l10n('AStat_version').ASTAT_VERSION; |
---|
168 | $template_plugin["ASTAT_PAGE"] = $_REQUEST['fAStat_tabsheet']; |
---|
169 | |
---|
170 | $template->assign('plugin', $template_plugin); |
---|
171 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
172 | } |
---|
173 | |
---|
174 | /* --------------------------------------------------------------------------- |
---|
175 | Private classe functions |
---|
176 | --------------------------------------------------------------------------- */ |
---|
177 | |
---|
178 | /* |
---|
179 | return ajax content |
---|
180 | */ |
---|
181 | protected function return_ajax_content() |
---|
182 | { |
---|
183 | global $ajax, $template; |
---|
184 | |
---|
185 | if(isset($_REQUEST['ajaxfct'])) |
---|
186 | { |
---|
187 | //$this->debug("AJAXFCT:".$_REQUEST['ajaxfct']); |
---|
188 | $result="<p class='errors'>An error has occured</p>"; |
---|
189 | switch($_REQUEST['ajaxfct']) |
---|
190 | { |
---|
191 | case 'astat_listip': |
---|
192 | if(!isset($_REQUEST['ipfilter'])) $_REQUEST['ipfilter']=""; |
---|
193 | if(!isset($_REQUEST['exclude'])) $_REQUEST['exclude']=""; |
---|
194 | $result=$this->ajax_listip($_REQUEST['ipfilter'], $_REQUEST['exclude']); |
---|
195 | break; |
---|
196 | } |
---|
197 | GPCAjax::returnResult($result); |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | |
---|
202 | |
---|
203 | |
---|
204 | |
---|
205 | |
---|
206 | |
---|
207 | private function init_request() |
---|
208 | { |
---|
209 | $default_request = array('all'=>'Y', 'year'=>'', 'month'=>'', 'day'=>''); |
---|
210 | |
---|
211 | //initialise $REQUEST values if not defined |
---|
212 | if(!array_key_exists('fAStat_tabsheet', $_REQUEST)) |
---|
213 | { |
---|
214 | $_REQUEST['fAStat_tabsheet']='stats_by_period'; |
---|
215 | } |
---|
216 | if(!array_key_exists('fAStat_defper', $_REQUEST)) |
---|
217 | { |
---|
218 | $_REQUEST['fAStat_defper']='Y'; |
---|
219 | } |
---|
220 | if(!array_key_exists('fAStat_SortCat', $_REQUEST)) |
---|
221 | { |
---|
222 | $_REQUEST['fAStat_SortCat']=$this->config['AStat_DefaultSortCat']; |
---|
223 | } |
---|
224 | if(!array_key_exists('fAStat_SortImg', $_REQUEST)) |
---|
225 | { |
---|
226 | $_REQUEST['fAStat_SortImg']=$this->config['AStat_DefaultSortImg']; |
---|
227 | } |
---|
228 | if(!array_key_exists('fAStat_SortIP', $_REQUEST)) |
---|
229 | { |
---|
230 | $_REQUEST['fAStat_SortIP']=$this->config['AStat_DefaultSortIP']; |
---|
231 | } |
---|
232 | if(!array_key_exists('fAStat_page_number', $_REQUEST)) |
---|
233 | { |
---|
234 | $_REQUEST['fAStat_page_number']='1'; |
---|
235 | } |
---|
236 | if(!array_key_exists('fAStat_IP', $_REQUEST)) |
---|
237 | { |
---|
238 | $_REQUEST['fAStat_IP']=""; |
---|
239 | } |
---|
240 | if(!array_key_exists('fAStat_purge_history_date', $_REQUEST)) |
---|
241 | { |
---|
242 | $_REQUEST['fAStat_purge_history_date']=""; |
---|
243 | } |
---|
244 | if(!array_key_exists('fAStat_catfilter', $_REQUEST)) |
---|
245 | { |
---|
246 | $_REQUEST['fAStat_catfilter']=""; |
---|
247 | } |
---|
248 | |
---|
249 | if(($_REQUEST['fAStat_tabsheet']=='stats_by_period')&&($_REQUEST['fAStat_defper']=='Y')) |
---|
250 | { |
---|
251 | if($this->config['AStat_default_period']!='global') |
---|
252 | { |
---|
253 | $default_request['all'] = 'N'; |
---|
254 | } |
---|
255 | |
---|
256 | if(($this->config['AStat_default_period']=='year')|| |
---|
257 | ($this->config['AStat_default_period']=='month')|| |
---|
258 | ($this->config['AStat_default_period']=='day')) |
---|
259 | { |
---|
260 | $default_request['year'] = date('Y'); |
---|
261 | } |
---|
262 | |
---|
263 | if(($this->config['AStat_default_period']=='month')|| |
---|
264 | ($this->config['AStat_default_period']=='day')) |
---|
265 | { |
---|
266 | $default_request['month'] = date('n'); |
---|
267 | } |
---|
268 | |
---|
269 | if($this->config['AStat_default_period']=='day') |
---|
270 | { |
---|
271 | $default_request['day'] = date('j'); |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | if(!array_key_exists('fAStat_all', $_REQUEST)) |
---|
276 | { |
---|
277 | $_REQUEST['fAStat_all']=$default_request['all']; |
---|
278 | } |
---|
279 | if(!array_key_exists('fAStat_year', $_REQUEST)) |
---|
280 | { |
---|
281 | $_REQUEST['fAStat_year']=$default_request['year']; |
---|
282 | } |
---|
283 | if(!array_key_exists('fAStat_month', $_REQUEST)) |
---|
284 | { |
---|
285 | $_REQUEST['fAStat_month']=$default_request['month']; |
---|
286 | } |
---|
287 | if(!array_key_exists('fAStat_day', $_REQUEST)) |
---|
288 | { |
---|
289 | $_REQUEST['fAStat_day']=$default_request['day']; |
---|
290 | } |
---|
291 | |
---|
292 | $this->catfilter=$_REQUEST['fAStat_catfilter']; |
---|
293 | |
---|
294 | } //init_request |
---|
295 | |
---|
296 | |
---|
297 | /* |
---|
298 | request functions |
---|
299 | |
---|
300 | theses functions made SQL requests and returns datas |
---|
301 | */ |
---|
302 | |
---|
303 | |
---|
304 | /* |
---|
305 | Stat by period |
---|
306 | Number of Pages |
---|
307 | Number IP |
---|
308 | Number of Images |
---|
309 | by : |
---|
310 | total |
---|
311 | years |
---|
312 | years/months |
---|
313 | years/months/days |
---|
314 | years/months/days/hours |
---|
315 | */ |
---|
316 | private function stats_by_period($total, $year, $month, $day) |
---|
317 | { |
---|
318 | $returned = array(); |
---|
319 | $delta = 0; |
---|
320 | |
---|
321 | $sql = " count(id) as NbPages, count(distinct IP) as NbIP, |
---|
322 | count(image_id) as NbImg, count(distinct category_id) as NbCat "; |
---|
323 | $sql_nfomax = ", MaxPages, MaxIP, MaxImg"; |
---|
324 | $sql_from = " from ".HISTORY_TABLE." "; |
---|
325 | $sql_where = ""; |
---|
326 | $sql_order = ""; |
---|
327 | $sql_select = ""; |
---|
328 | $sql_group = ""; |
---|
329 | $sql_groupdef=""; |
---|
330 | |
---|
331 | if($day!="") |
---|
332 | { |
---|
333 | $sql_groupdef="HOUR(time) as GId,"; |
---|
334 | $sql_select="select HOUR(time) as GId, "; |
---|
335 | $sql_where=" where YEAR(date) = $year and MONTH(date) = $month and DAY(date) = $day "; |
---|
336 | $sql_group=" group by GId "; |
---|
337 | $sql_order=" order by GId asc"; |
---|
338 | |
---|
339 | for($i=0;$i<24;$i++) |
---|
340 | { |
---|
341 | $returned[$i] = array( |
---|
342 | "GId" => $i, |
---|
343 | "NbPages" => 0, |
---|
344 | "NbIP" => 0, |
---|
345 | "NbImg" => 0, |
---|
346 | "NbCat"=>0, |
---|
347 | "MaxPages" => 0, |
---|
348 | "MaxIP" => 0, |
---|
349 | "MaxImg" => 0 |
---|
350 | ); |
---|
351 | } |
---|
352 | } |
---|
353 | elseif($month!="") |
---|
354 | { |
---|
355 | $sql_groupdef="DAY(date) as GId,"; |
---|
356 | $sql_select="select DAY(date) as GId, "; |
---|
357 | $sql_where=" where YEAR(date) = $year and MONTH(date) = $month "; |
---|
358 | $sql_group=" group by GId "; |
---|
359 | $sql_order=" order by GId asc"; |
---|
360 | |
---|
361 | $delta = 1; |
---|
362 | $NbDays = strftime('%d', mktime(0,0,0,$month+1,0,$year)); |
---|
363 | for($i=0;$i<$NbDays;$i++) |
---|
364 | { |
---|
365 | $returned[$i] = array( |
---|
366 | "GId" => $i+1, |
---|
367 | "NbPages" => 0, |
---|
368 | "NbIP" => 0, |
---|
369 | "NbImg" => 0, |
---|
370 | "NbCat"=>0, |
---|
371 | "MaxPages" => 0, |
---|
372 | "MaxIP" => 0, |
---|
373 | "MaxImg" => 0 |
---|
374 | ); |
---|
375 | } |
---|
376 | } |
---|
377 | elseif($year!="") |
---|
378 | { |
---|
379 | $sql_groupdef="MONTH(date) as GId,"; |
---|
380 | $sql_select="select MONTH(date) as GId, "; |
---|
381 | $sql_where=" where YEAR(date) = $year "; |
---|
382 | $sql_group=" group by GId "; |
---|
383 | $sql_order=" order by GId asc "; |
---|
384 | |
---|
385 | $delta = 1; |
---|
386 | for($i=0;$i<12;$i++) |
---|
387 | { |
---|
388 | $returned[$i] = array( |
---|
389 | "GId" => $i+1, |
---|
390 | "NbPages" => 0, |
---|
391 | "NbIP" => 0, |
---|
392 | "NbImg" => 0, |
---|
393 | "NbCat"=>0, |
---|
394 | "MaxPages" => 0, |
---|
395 | "MaxIP" => 0, |
---|
396 | "MaxImg" => 0 |
---|
397 | ); |
---|
398 | } |
---|
399 | } |
---|
400 | elseif($total!="Y") |
---|
401 | { |
---|
402 | $sql_groupdef="YEAR(date) as GId,"; |
---|
403 | $sql_select="select YEAR(date) as GId, "; |
---|
404 | $sql_group=" group by GId "; |
---|
405 | $sql_order=" order by GId desc"; |
---|
406 | } |
---|
407 | else |
---|
408 | { |
---|
409 | $sql_select="select 'Tout' as GId, "; $sql_nfomax=", 0 as MaxPages, 0 as MaxIP, 0 as MaxImg"; |
---|
410 | } |
---|
411 | |
---|
412 | if($this->catfilter!="") |
---|
413 | { |
---|
414 | $catfilter=$this->make_where_clause($this->catfilter); |
---|
415 | ($sql_where=="")?$sql_where=" where ":$sql_where.=" and "; |
---|
416 | $sql_where.=" category_id IN (".$catfilter.")"; |
---|
417 | } |
---|
418 | |
---|
419 | if(($this->config['AStat_UseBlackList']!="false")&&($this->config['AStat_BlackListedIP']!="")) |
---|
420 | { |
---|
421 | ($sql_where=="")?$sql_where=" where ":$sql_where.=" AND "; |
---|
422 | ($this->config['AStat_UseBlackList']=="true")?$sql_where .= " NOT ":""; |
---|
423 | $sql_where .= $this->make_IP_where_clause($this->config['AStat_BlackListedIP']); |
---|
424 | } |
---|
425 | |
---|
426 | $sql_max=", (select max(n.MaxPages) as MaxPages, max(n.MaxIP) as MaxIP, max(n.MaxImg) as MaxImg |
---|
427 | from (select ".$sql_groupdef." count(id) as MaxPages, count(distinct IP) as MaxIP, count(image_id) as MaxImg |
---|
428 | from ".HISTORY_TABLE.$sql_where.$sql_group.") as n) as n "; |
---|
429 | $sql=$sql_select.$sql.$sql_nfomax.$sql_from.$sql_max.$sql_where.$sql_group.$sql_order; |
---|
430 | |
---|
431 | $result = pwg_query($sql); |
---|
432 | |
---|
433 | $i=0; |
---|
434 | while ($row = pwg_db_fetch_assoc($result)) |
---|
435 | { |
---|
436 | if($year.$month.$day=="") |
---|
437 | { $returned[$i] = $row; $i++; } |
---|
438 | else |
---|
439 | { $returned[$row["GId"]-$delta] = $row; } |
---|
440 | } |
---|
441 | |
---|
442 | return($returned); |
---|
443 | } //stat by period |
---|
444 | |
---|
445 | /* |
---|
446 | Stats by IP |
---|
447 | Number of Pages |
---|
448 | Number of Images |
---|
449 | by : |
---|
450 | IP |
---|
451 | IP/years |
---|
452 | IP/years/months |
---|
453 | IP/years/months/days |
---|
454 | */ |
---|
455 | private function stats_by_ip($year, $month, $day, $nbipperpage, $pagenumber, $sortip) |
---|
456 | { |
---|
457 | $returned0 = array(); |
---|
458 | $sortlist = array( |
---|
459 | "page" => "NbPages desc", |
---|
460 | "picture" => "NbImg desc", |
---|
461 | "ip" => "IP_USER asc" |
---|
462 | ); |
---|
463 | |
---|
464 | $sql_select="select SQL_CALC_FOUND_ROWS "; |
---|
465 | $sql= " if(".HISTORY_TABLE.".user_id = 2, IP, if(".USERS_TABLE.".username is null, ' [".l10n("AStat_deleted_user")."]', CONCAT(' ', ".USERS_TABLE.".username))) as IP_USER, count(".HISTORY_TABLE.".id) as NbPages, count(image_id) as NbImg "; |
---|
466 | $sql_nfomax = ", MaxPages, MaxImg"; |
---|
467 | $sql_from = " from ".HISTORY_TABLE." LEFT JOIN ".USERS_TABLE." ON ".HISTORY_TABLE.".user_id = ".USERS_TABLE.".id "; |
---|
468 | $sql_where = ""; |
---|
469 | $sql_group=" group by IP_USER "; |
---|
470 | $sql_order=" order by ".$sortlist[$sortip]." "; |
---|
471 | $sql_limit=" limit ".(($pagenumber-1)* $nbipperpage).", ".$nbipperpage; |
---|
472 | |
---|
473 | |
---|
474 | if($day!="") |
---|
475 | { |
---|
476 | $sql_where=" where YEAR(date) = $year and MONTH(date) = $month and DAY(date) = $day "; |
---|
477 | } |
---|
478 | elseif($month!="") |
---|
479 | { |
---|
480 | $sql_where=" where YEAR(date) = $year and MONTH(date) = $month "; |
---|
481 | } |
---|
482 | elseif($year!="") |
---|
483 | { |
---|
484 | $sql_where=" where YEAR(date) = $year "; |
---|
485 | } |
---|
486 | else |
---|
487 | { |
---|
488 | $sql_nfomax = ", 0 as MaxPages, 0 as MaxImg"; |
---|
489 | } |
---|
490 | |
---|
491 | if($this->catfilter!="") |
---|
492 | { |
---|
493 | $catfilter=$this->make_where_clause($this->catfilter); |
---|
494 | ($sql_where=="")?$sql_where=" where ":$sql_where.=" and "; |
---|
495 | $sql_where.=" category_id IN (".$catfilter.")"; |
---|
496 | } |
---|
497 | |
---|
498 | if(($this->config['AStat_UseBlackList']!="false")&&($this->config['AStat_BlackListedIP']!="")) |
---|
499 | { |
---|
500 | ($sql_where=="")?$sql_where=" where ":$sql_where.=" AND "; |
---|
501 | ($this->config['AStat_UseBlackList']=="true")?$sql_where .= " NOT ":""; |
---|
502 | $sql_where .= $this->make_IP_where_clause($this->config['AStat_BlackListedIP']); |
---|
503 | $sql.=" , 'N' AS blacklist"; |
---|
504 | } |
---|
505 | else |
---|
506 | { |
---|
507 | if($this->config['AStat_BlackListedIP']=='') |
---|
508 | { |
---|
509 | $sql.=" , 'N' AS blacklist"; |
---|
510 | } |
---|
511 | else |
---|
512 | { |
---|
513 | $sql.=" , (CASE "; |
---|
514 | $tmp=explode(',', $this->config['AStat_BlackListedIP']); |
---|
515 | foreach($tmp as $key=>$val) |
---|
516 | { |
---|
517 | $sql.=" WHEN IP LIKE '".$val."' THEN 'Y' "; |
---|
518 | } |
---|
519 | $sql.="ELSE 'N' END) AS blacklist "; |
---|
520 | } |
---|
521 | } |
---|
522 | |
---|
523 | $sql_max=", (select max(n.MaxPages) as MaxPages, max(n.MaxImg) as MaxImg |
---|
524 | from (select if(".HISTORY_TABLE.".user_id = 2, IP, if(".USERS_TABLE.".username is null, '[".l10n("AStat_deleted_user")."]', ".USERS_TABLE.".username)) as IP_USER, count(".HISTORY_TABLE.".id) as MaxPages, count(image_id) as MaxImg |
---|
525 | from ".HISTORY_TABLE." LEFT JOIN ".USERS_TABLE." ON ".HISTORY_TABLE.".user_id = ".USERS_TABLE.".id ".$sql_where.$sql_group.") as n) as n "; |
---|
526 | $sql=$sql_select.$sql.$sql_nfomax.$sql_from.$sql_max.$sql_where.$sql_group.$sql_order.$sql_limit; |
---|
527 | |
---|
528 | |
---|
529 | $result = pwg_query($sql); |
---|
530 | $sql="select FOUND_ROWS()"; |
---|
531 | |
---|
532 | $i=0; |
---|
533 | while ($row = pwg_db_fetch_assoc($result)) |
---|
534 | { |
---|
535 | $returned0[$i] = $row; $i++; |
---|
536 | } |
---|
537 | $returned[0] = $returned0; |
---|
538 | |
---|
539 | $result = pwg_query($sql); |
---|
540 | if($result) |
---|
541 | { |
---|
542 | $row = pwg_db_fetch_row($result); $returned[1] = $row[0]; |
---|
543 | } |
---|
544 | else |
---|
545 | { |
---|
546 | $returned[1] = -1; |
---|
547 | } |
---|
548 | |
---|
549 | return($returned); |
---|
550 | } //stat by ip |
---|
551 | |
---|
552 | /* |
---|
553 | Stats per categories |
---|
554 | %Pages |
---|
555 | %Images |
---|
556 | by : |
---|
557 | Categories |
---|
558 | Categories/years |
---|
559 | Categories/years/months |
---|
560 | Categories/years/months/day |
---|
561 | */ |
---|
562 | private function stats_by_category($year, $month, $day, $nbipperpage, $pagenumber, $show_thumb, $sortcat) |
---|
563 | { |
---|
564 | $sortlist = array( |
---|
565 | "page" => "PctPages desc, PctImg desc", |
---|
566 | "picture" => "PctImg desc, PctPages desc", |
---|
567 | "nbpicture" => "RatioImg desc, PctPages desc" |
---|
568 | ); |
---|
569 | $returned0 = array(); |
---|
570 | |
---|
571 | $sql_select="SELECT SQL_CALC_FOUND_ROWS "; |
---|
572 | |
---|
573 | $sql= "category_id, IF(category_id > 0, ".CATEGORIES_TABLE.".name, section) AS IdCat, |
---|
574 | COUNT(".HISTORY_TABLE.".id) AS NbPages, MaxPages.somme, 100*(count(".HISTORY_TABLE.".id)/MaxPages.somme) AS PctPages, |
---|
575 | COUNT(".HISTORY_TABLE.".image_id) AS NbImg, MaxImg.somme, 100*(count(".HISTORY_TABLE.".image_id)/MaxImg.somme) AS PctImg, ic2.nb_images as NbImgCat, (COUNT(".HISTORY_TABLE.".image_id)/ic2.nb_images) AS RatioImg, greatest(100*(COUNT(".HISTORY_TABLE.".id)/MaxPages.somme), 100*(COUNT(".HISTORY_TABLE.".image_id)/MaxImg.somme)) AS MaxPct "; |
---|
576 | |
---|
577 | if($show_thumb=='true') |
---|
578 | { |
---|
579 | $sql_thumb = ', '.IMAGES_TABLE.'.path as ThumbPath, '.IMAGES_TABLE.'.file as ThumbFile, '.IMAGES_TABLE.'.tn_ext as Extension'; |
---|
580 | $sql_fromthumb = "LEFT JOIN ".IMAGES_TABLE." ON ic2.representative_picture_id = ".IMAGES_TABLE.".id "; |
---|
581 | } |
---|
582 | else |
---|
583 | { |
---|
584 | $sql_thumb = ""; |
---|
585 | $sql_fromthumb = ""; |
---|
586 | } |
---|
587 | |
---|
588 | $sql_from = " FROM (".HISTORY_TABLE." LEFT JOIN ".CATEGORIES_TABLE." ON ".CATEGORIES_TABLE.".id = ".HISTORY_TABLE.".category_id), |
---|
589 | (SELECT category_id AS catid, COUNT(image_id) AS nb_images, representative_picture_id |
---|
590 | FROM ".IMAGE_CATEGORY_TABLE.", ".CATEGORIES_TABLE." |
---|
591 | WHERE ".CATEGORIES_TABLE.".id = ".IMAGE_CATEGORY_TABLE.".category_id group by category_id) AS ic2 "; |
---|
592 | $sql_where = ""; |
---|
593 | $sql_group=" GROUP BY category_id, section "; |
---|
594 | $sql_group2=""; |
---|
595 | $sql_order=" ORDER BY ".$sortlist[$sortcat]; |
---|
596 | $sql_limit=" LIMIT ".(($pagenumber-1)* $nbipperpage).", ".$nbipperpage; |
---|
597 | |
---|
598 | if($day!="") |
---|
599 | { |
---|
600 | $sql_where=" WHERE YEAR(date) = $year AND MONTH(date) = $month AND DAY(date)= $day "; |
---|
601 | } |
---|
602 | elseif($month!="") |
---|
603 | { |
---|
604 | $sql_where=" WHERE YEAR(date) = $year AND MONTH(date) = $month "; |
---|
605 | } |
---|
606 | elseif($year!="") |
---|
607 | { |
---|
608 | $sql_where=" WHERE YEAR(date) = $year "; |
---|
609 | } |
---|
610 | else { } |
---|
611 | |
---|
612 | if($this->catfilter!="") |
---|
613 | { |
---|
614 | $catfilter=$this->make_where_clause($this->catfilter); |
---|
615 | ($sql_where=="")?$sql_where=" where ":$sql_where.=" and "; |
---|
616 | $sql_where.=" category_id IN (".$catfilter.")"; |
---|
617 | } |
---|
618 | |
---|
619 | $sql_max=", (SELECT COUNT(id) AS somme FROM ".HISTORY_TABLE.$sql_where.$sql_group2.") AS MaxPages, |
---|
620 | (SELECT COUNT(image_id) AS somme FROM ".HISTORY_TABLE.$sql_where.$sql_group2.") AS MaxImg "; |
---|
621 | |
---|
622 | ($sql_where=="")?$sql_where=" WHERE ":$sql_where.=" AND "; |
---|
623 | $sql_where .= " ic2.catid = ".HISTORY_TABLE.".category_id "; |
---|
624 | |
---|
625 | if(($this->config['AStat_UseBlackList']!="false")&&($this->config['AStat_BlackListedIP']!="")) |
---|
626 | { |
---|
627 | ($this->config['AStat_UseBlackList']=="true")?$sql_where .= " AND NOT ":""; |
---|
628 | $sql_where .= $this->make_IP_where_clause($this->config['AStat_BlackListedIP']); |
---|
629 | } |
---|
630 | |
---|
631 | $sql=$sql_select.$sql.$sql_thumb.$sql_from.$sql_fromthumb.$sql_max.$sql_where.$sql_group.$sql_order.$sql_limit; |
---|
632 | |
---|
633 | $result = pwg_query($sql); |
---|
634 | $sql="SELECT FOUND_ROWS()"; |
---|
635 | |
---|
636 | $i=0; |
---|
637 | while ($row = pwg_db_fetch_assoc($result)) |
---|
638 | { |
---|
639 | $returned0[$i] = $row; $i++; |
---|
640 | } |
---|
641 | $returned[0] = $returned0; |
---|
642 | |
---|
643 | $result = pwg_query($sql); |
---|
644 | if($result) |
---|
645 | { |
---|
646 | $row = pwg_db_fetch_row($result); $returned[1] = $row[0]; |
---|
647 | } |
---|
648 | else |
---|
649 | { |
---|
650 | $returned[1] = -1; |
---|
651 | } |
---|
652 | |
---|
653 | return($returned); |
---|
654 | } // stats per categories |
---|
655 | |
---|
656 | /* |
---|
657 | Stats by image |
---|
658 | Num of view per image |
---|
659 | %view on period |
---|
660 | by : |
---|
661 | Images |
---|
662 | Images/years |
---|
663 | Images/years/months |
---|
664 | Images/years/months/days |
---|
665 | */ |
---|
666 | private function stats_by_image($year, $month, $day, $nbipperpage, $pagenumber, $sortimg, $ip) |
---|
667 | { |
---|
668 | $sortlist = array( |
---|
669 | "picture" => "NbVues desc, CatName asc, ImgName asc, ImgId asc", |
---|
670 | "catname" => "CatName asc, ImgName asc, ImgId asc" |
---|
671 | ); |
---|
672 | $returned0 = array(); |
---|
673 | |
---|
674 | $sql_select="select SQL_CALC_FOUND_ROWS "; |
---|
675 | |
---|
676 | |
---|
677 | $sql=" image_id as ImgId, ".IMAGES_TABLE.".name as ImgName, |
---|
678 | if(category_id > 0, ".CATEGORIES_TABLE.".name, section) as CatName, |
---|
679 | ".HISTORY_TABLE.".category_id as IdCat, count(".HISTORY_TABLE.".image_id) as NbVues, |
---|
680 | MaxImg.somme, 100*(count(".HISTORY_TABLE.".image_id)/MaxImg.somme) as PctImg, |
---|
681 | ".IMAGES_TABLE.".path as ThumbPath, ".IMAGES_TABLE.".file as ThumbFile, |
---|
682 | MaxImg2.somme as NbVuesMax, ".IMAGES_TABLE.".tn_ext as Extension "; |
---|
683 | |
---|
684 | $sql_from = " from ((".HISTORY_TABLE." LEFT JOIN ".IMAGES_TABLE." ON |
---|
685 | ".IMAGES_TABLE.".id = ".HISTORY_TABLE.".image_id) LEFT JOIN ".CATEGORIES_TABLE." |
---|
686 | ON ".CATEGORIES_TABLE.".id = ".HISTORY_TABLE.".category_id) "; |
---|
687 | $sql_from_ip=""; |
---|
688 | |
---|
689 | $sql_where = " where ".HISTORY_TABLE.".image_id is not null "; |
---|
690 | $sql_group=" group by image_id, category_id "; |
---|
691 | $sql_order=" order by ".$sortlist[$sortimg]; |
---|
692 | $sql_limit=" limit ".(($pagenumber-1)* $nbipperpage).", ".$nbipperpage; |
---|
693 | |
---|
694 | if($day!="") |
---|
695 | { |
---|
696 | $sql_where.=" and YEAR(date) = $year and MONTH(date) = $month and DAY(date)= $day "; |
---|
697 | } |
---|
698 | elseif($month!="") |
---|
699 | { |
---|
700 | $sql_where.=" and YEAR(date) = $year and MONTH(date) = $month "; |
---|
701 | } |
---|
702 | elseif($year!="") |
---|
703 | { |
---|
704 | $sql_where.=" and YEAR(date) = $year "; |
---|
705 | } |
---|
706 | else { } |
---|
707 | |
---|
708 | if($ip!="") |
---|
709 | { |
---|
710 | $sql_where.=" and ( ((IP = '$ip') and ( user_id = 2 )) or (".USERS_TABLE.".username = '$ip') )"; |
---|
711 | $sql_from_ip=" LEFT JOIN ".USERS_TABLE." ON ".USERS_TABLE.".id = ".HISTORY_TABLE.".user_id "; |
---|
712 | } |
---|
713 | |
---|
714 | if($this->catfilter!="") |
---|
715 | { |
---|
716 | $catfilter=$this->make_where_clause($this->catfilter); |
---|
717 | ($sql_where=="")?$sql_where=" where ":$sql_where.=" and "; |
---|
718 | $sql_where.=" category_id IN (".$catfilter.")"; |
---|
719 | } |
---|
720 | |
---|
721 | if(($this->config['AStat_UseBlackList']!="false")&&($this->config['AStat_BlackListedIP']!="")) |
---|
722 | { |
---|
723 | ($sql_where=="")?$sql_where=" where ":$sql_where.=" AND "; |
---|
724 | ($this->config['AStat_UseBlackList']=="true")?$sql_where .= " NOT ":""; |
---|
725 | $sql_where .= $this->make_IP_where_clause($this->config['AStat_BlackListedIP']); |
---|
726 | } |
---|
727 | |
---|
728 | |
---|
729 | $sql_max=", (select count(image_id) as somme from ".HISTORY_TABLE.$sql_from_ip.$sql_where.") as MaxImg, (select count(image_id) as somme from ".HISTORY_TABLE.$sql_from_ip.$sql_where." and ".HISTORY_TABLE.".image_id is not null group by image_id order by somme desc limit 0,1) as MaxImg2 "; |
---|
730 | |
---|
731 | $sql=$sql_select.$sql.$sql_from.$sql_from_ip.$sql_max.$sql_where.$sql_group.$sql_order.$sql_limit; |
---|
732 | |
---|
733 | $result = pwg_query($sql); |
---|
734 | $sql="select FOUND_ROWS()"; |
---|
735 | |
---|
736 | $i=0; |
---|
737 | while ($row = pwg_db_fetch_assoc($result)) |
---|
738 | { |
---|
739 | $returned0[$i] = $row; $i++; |
---|
740 | } |
---|
741 | $returned[0] = $returned0; |
---|
742 | |
---|
743 | $result = pwg_query($sql); |
---|
744 | if($result) |
---|
745 | { |
---|
746 | $row = pwg_db_fetch_row($result); $returned[1] = $row[0]; |
---|
747 | } |
---|
748 | else |
---|
749 | { |
---|
750 | $returned[1] = -1; |
---|
751 | } |
---|
752 | |
---|
753 | return($returned); |
---|
754 | } //stat by images |
---|
755 | |
---|
756 | |
---|
757 | /* |
---|
758 | template related functions |
---|
759 | |
---|
760 | theses functions call stat function, and display result with template usage |
---|
761 | */ |
---|
762 | |
---|
763 | |
---|
764 | |
---|
765 | private function display_stats_by_period($total, $year, $month, $day, $max_width, $seetimerequest) |
---|
766 | { |
---|
767 | global $template; |
---|
768 | |
---|
769 | $template->set_filename('body_page', dirname(__FILE__)."/admin/astat_by_period.tpl"); |
---|
770 | |
---|
771 | |
---|
772 | $template_datas=array(); |
---|
773 | $template_datarows=array(); |
---|
774 | |
---|
775 | |
---|
776 | /* requete */ |
---|
777 | //calc_time(true); |
---|
778 | $stats = $this->stats_by_period($total, $year, $month, $day); |
---|
779 | //$timerequest=calc_time(false); |
---|
780 | |
---|
781 | $dir_links = ""; |
---|
782 | $a_links=array("global" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=Y", |
---|
783 | "all" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N", |
---|
784 | "year" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year", |
---|
785 | "month" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year&fAStat_month=$month", |
---|
786 | "day" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year&fAStat_month=$month&fAStat_day=$day"); |
---|
787 | |
---|
788 | $ip_links=array("all" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_ip", |
---|
789 | "year" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_ip&fAStat_year=", |
---|
790 | "month" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_ip&fAStat_year=$year&fAStat_month=", |
---|
791 | "day" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_ip&fAStat_year=$year&fAStat_month=$month&fAStat_day="); |
---|
792 | |
---|
793 | $cat_links=array("all" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_category", |
---|
794 | "year" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_category&fAStat_year=", |
---|
795 | "month" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_category&fAStat_year=$year&fAStat_month=", |
---|
796 | "day" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_category&fAStat_year=$year&fAStat_month=$month&fAStat_day="); |
---|
797 | |
---|
798 | $img_links=array("all" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_image", |
---|
799 | "year" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_image&fAStat_year=", |
---|
800 | "month" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_image&fAStat_year=$year&fAStat_month=", |
---|
801 | "day" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_image&fAStat_year=$year&fAStat_month=$month&fAStat_day="); |
---|
802 | |
---|
803 | |
---|
804 | /* period label + navigation links */ |
---|
805 | if($day!="") |
---|
806 | { |
---|
807 | $template_datas["PERIOD_LABEL"] = l10n("AStat_period_label_hours"); |
---|
808 | $template_datas["L_STAT_TITLE"] = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".$this->format_link(l10n("AStat_month_of_year_".$month), $a_links["month"])." / ".l10n("AStat_day_of_week_".date("w",mktime(0, 0, 0, $month, $day, $year)))." $day"; |
---|
809 | } |
---|
810 | elseif($month!="") |
---|
811 | { |
---|
812 | $template_datas["PERIOD_LABEL"] = l10n("AStat_period_label_days"); |
---|
813 | $template_datas["L_STAT_TITLE"] = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".l10n("AStat_month_of_year_".$month); |
---|
814 | } |
---|
815 | elseif($year!="") |
---|
816 | { |
---|
817 | $template_datas["PERIOD_LABEL"] = l10n("AStat_period_label_months"); |
---|
818 | $template_datas["L_STAT_TITLE"] = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$year; |
---|
819 | } |
---|
820 | elseif($total!="Y") |
---|
821 | { |
---|
822 | $template_datas["PERIOD_LABEL"] = l10n("AStat_period_label_years"); |
---|
823 | $template_datas["L_STAT_TITLE"] = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".l10n("AStat_period_label_all"); |
---|
824 | } |
---|
825 | else |
---|
826 | { |
---|
827 | $template_datas["PERIOD_LABEL"] = l10n("AStat_period_label_all"); |
---|
828 | $template_datas["L_STAT_TITLE"] = l10n("AStat_period_label_global"); |
---|
829 | } |
---|
830 | $template_datas["MAX_WIDTH"] = $max_width+10; |
---|
831 | $template_datas["ASTAT_NFO_STAT"] = l10n("AStat_Nfo_Period"); |
---|
832 | |
---|
833 | if($seetimerequest=='true') |
---|
834 | { |
---|
835 | $template_datas["ASTAT_TIME_REQUEST"] = l10n('AStat_time_request_label').' '.$timerequest.'s'; |
---|
836 | } |
---|
837 | |
---|
838 | /* tableau de stat */ |
---|
839 | for($i=0;$i<count($stats);$i++) |
---|
840 | { |
---|
841 | if($stats[$i]["MaxPages"] > 0) |
---|
842 | { |
---|
843 | $width_pages = ceil(($stats[$i]["NbPages"] * $max_width) / $stats[$i]["MaxPages"] ); |
---|
844 | $width_img = ceil(($stats[$i]["NbImg"] * $max_width) / $stats[$i]["MaxPages"] ); |
---|
845 | $width_ip = ceil(($stats[$i]["NbIP"] * $max_width) / $stats[$i]["MaxPages"] ); |
---|
846 | $width_cat = ceil(($stats[$i]["NbCat"] * $max_width) / $stats[$i]["MaxPages"] ); |
---|
847 | } |
---|
848 | else |
---|
849 | { |
---|
850 | $width_pages = 0; |
---|
851 | $width_img = 0; |
---|
852 | $width_ip = 0; |
---|
853 | $width_cat = 0; |
---|
854 | } |
---|
855 | |
---|
856 | |
---|
857 | if($day!="") |
---|
858 | { // si jours sélectionné, heures affichées |
---|
859 | $value=$stats[$i]["GId"]; |
---|
860 | $link=""; |
---|
861 | $value_ip=""; |
---|
862 | $value_cat=""; |
---|
863 | $value_img=""; |
---|
864 | } |
---|
865 | elseif($month!="") |
---|
866 | { // si mois sélectionné, jours affichés |
---|
867 | $value = $stats[$i]["GId"]." (".l10n("AStat_day_of_week_".date("w",mktime(0, 0, 0, $month, $stats[$i]["GId"], $year))).")"; |
---|
868 | $link=$this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year&fAStat_month=$month&fAStat_day=".$stats[$i]["GId"]; |
---|
869 | $value_ip=$ip_links["day"].$stats[$i]["GId"]; |
---|
870 | $value_cat=$cat_links["day"].$stats[$i]["GId"]; |
---|
871 | $value_img=$img_links["day"].$stats[$i]["GId"]; |
---|
872 | } |
---|
873 | elseif($year!="") |
---|
874 | { // si année sélectionnée, mois affichés |
---|
875 | $value = l10n("AStat_month_of_year_".$stats[$i]["GId"]); |
---|
876 | $link=$this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year&fAStat_month=".$stats[$i]["GId"]; |
---|
877 | $value_ip=$ip_links["month"].$stats[$i]["GId"]; |
---|
878 | $value_cat=$cat_links["month"].$stats[$i]["GId"]; |
---|
879 | $value_img=$img_links["month"].$stats[$i]["GId"]; |
---|
880 | } |
---|
881 | elseif($total!="Y") |
---|
882 | { // si total sélectionné, années affichées |
---|
883 | $value = $stats[$i]["GId"]; |
---|
884 | $link=$this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=".$stats[$i]["GId"]; |
---|
885 | $value_ip=$ip_links["year"].$stats[$i]["GId"]; |
---|
886 | $value_cat=$cat_links["year"].$stats[$i]["GId"]; |
---|
887 | $value_img=$img_links["year"].$stats[$i]["GId"]; |
---|
888 | } |
---|
889 | else |
---|
890 | { |
---|
891 | $value=l10n("AStat_period_label_all"); |
---|
892 | $link=$this->getAdminLink()."&fAStat_defper=N&fAStat_all=N"; |
---|
893 | $value_ip=$ip_links["all"]; |
---|
894 | $value_cat=$cat_links["all"]; |
---|
895 | $value_img=$img_links["all"]; |
---|
896 | } |
---|
897 | |
---|
898 | |
---|
899 | if((($stats[$i]["NbPages"] + $stats[$i]["NbImg"] + $stats[$i]["NbIP"])>0)&&($link!="")) |
---|
900 | { $value=$this->format_link($value, $link); } |
---|
901 | |
---|
902 | if((($stats[$i]["NbIP"])>0)&&($value_ip!="")) |
---|
903 | { $value_ip=$this->format_link($stats[$i]["NbIP"], $value_ip); } |
---|
904 | else |
---|
905 | { $value_ip = $stats[$i]["NbIP"]; } |
---|
906 | |
---|
907 | if((($stats[$i]["NbCat"])>0)&&($value_cat!="")) |
---|
908 | { $value_cat=$this->format_link($stats[$i]["NbCat"], $value_cat); } |
---|
909 | else |
---|
910 | { $value_cat= $stats[$i]["NbCat"]; } |
---|
911 | |
---|
912 | if((($stats[$i]["NbImg"])>0)&&($value_img!="")) |
---|
913 | { $value_img=$this->format_link($stats[$i]["NbImg"], $value_img); } |
---|
914 | else |
---|
915 | { $value_img= $stats[$i]["NbImg"]; } |
---|
916 | |
---|
917 | |
---|
918 | |
---|
919 | $template_datarows[]=array( |
---|
920 | 'VALUE' => $value, |
---|
921 | 'PAGES' => $stats[$i]["NbPages"], |
---|
922 | 'PICTURES' => $value_img, |
---|
923 | 'CATEGORIES' => $value_cat, |
---|
924 | 'IPVISIT' => $value_ip, |
---|
925 | 'WIDTH1' => $width_ip, |
---|
926 | 'WIDTH2' => $width_img, |
---|
927 | 'WIDTH3' => $width_pages, |
---|
928 | 'WIDTH4' => $width_cat, |
---|
929 | ); |
---|
930 | |
---|
931 | } |
---|
932 | |
---|
933 | $template->assign('datas', $template_datas); |
---|
934 | $template->assign('datarows', $template_datarows); |
---|
935 | $template->assign_var_from_handle('ASTAT_BODY_PAGE', 'body_page'); |
---|
936 | } //display_stats_by_period |
---|
937 | |
---|
938 | |
---|
939 | |
---|
940 | /* |
---|
941 | display stat by ip |
---|
942 | */ |
---|
943 | private function display_stats_by_ip($year, $month, $day, $max_width, $nbipperpage, $pagenumber, $sortip, $seetimerequest) |
---|
944 | { |
---|
945 | global $template; |
---|
946 | |
---|
947 | $template->set_filename('body_page', dirname(__FILE__)."/admin/astat_by_ip.tpl"); |
---|
948 | |
---|
949 | |
---|
950 | $template_datas=array(); |
---|
951 | $template_datarows=array(); |
---|
952 | |
---|
953 | |
---|
954 | /* requete */ |
---|
955 | //calc_time(true); |
---|
956 | $returned = $this->stats_by_ip($year, $month, $day, $nbipperpage, $pagenumber, $sortip); |
---|
957 | //$timerequest=calc_time(false); |
---|
958 | $stats=$returned[0]; |
---|
959 | $nbfoundrows=$returned[1]; |
---|
960 | $nbpages=ceil($nbfoundrows / $nbipperpage); |
---|
961 | |
---|
962 | |
---|
963 | $dir_links = ""; |
---|
964 | $page_link = ""; |
---|
965 | $a_links=array("global" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=Y", |
---|
966 | "all" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N", |
---|
967 | "year" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year", |
---|
968 | "month" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year&fAStat_month=$month", |
---|
969 | "day" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year&fAStat_month=$month&fAStat_day=$day"); |
---|
970 | |
---|
971 | $ip_links=array("all" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_ip", |
---|
972 | "year" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_ip&fAStat_year=$year", |
---|
973 | "month" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_ip&fAStat_year=$year&fAStat_month=$month", |
---|
974 | "day" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_ip&fAStat_year=$year&fAStat_month=$month&fAStat_day=$day"); |
---|
975 | |
---|
976 | $img_links=array("all" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_image", |
---|
977 | "year" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_image&fAStat_year=$year", |
---|
978 | "month" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_image&fAStat_year=$year&fAStat_month=$month", |
---|
979 | "day" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_image&fAStat_year=$year&fAStat_month=$month&fAStat_day=$day"); |
---|
980 | |
---|
981 | |
---|
982 | /* periode label + navigation links */ |
---|
983 | if($day!="") |
---|
984 | { |
---|
985 | $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".$this->format_link(l10n("AStat_month_of_year_".$month), $a_links["month"])." / ".l10n("AStat_day_of_week_".date("w",mktime(0, 0, 0, $month, $day, $year)))." $day"; |
---|
986 | $page_link=$ip_links["day"]; |
---|
987 | $img_link=$img_links["day"]; |
---|
988 | } |
---|
989 | elseif($month!="") |
---|
990 | { |
---|
991 | $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".l10n("AStat_month_of_year_".$month); |
---|
992 | $page_link=$ip_links["month"]; |
---|
993 | $img_link=$img_links["month"]; |
---|
994 | } |
---|
995 | elseif($year!="") |
---|
996 | { |
---|
997 | $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$year; |
---|
998 | $page_link=$ip_links["year"]; |
---|
999 | $img_link=$img_links["year"]; |
---|
1000 | } |
---|
1001 | else |
---|
1002 | { |
---|
1003 | $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".l10n("AStat_period_label_all"); |
---|
1004 | $page_link=$ip_links["all"]; |
---|
1005 | $img_link=$img_links["all"]; |
---|
1006 | } |
---|
1007 | |
---|
1008 | |
---|
1009 | if($nbpages>1) { $plural="s"; } else { $plural=""; } |
---|
1010 | $pages_links=l10n("AStat_page".$plural."_label")." : "; |
---|
1011 | for($i=1;$i<=$nbpages;$i++) |
---|
1012 | { |
---|
1013 | if($i==$pagenumber) |
---|
1014 | { $pages_links.=" $i "; } |
---|
1015 | else |
---|
1016 | { |
---|
1017 | $pages_links.=$this->format_link(" $i ", $page_link."&fAStat_page_number=$i&fAStat_SortIP=$sortip"); |
---|
1018 | } |
---|
1019 | } |
---|
1020 | |
---|
1021 | $template_datas["L_STAT_TITLE"] = $dir_links; |
---|
1022 | $template_datas["MAX_WIDTH"]=$max_width+10; |
---|
1023 | $template_datas["NB_TOTAL_IP"] = l10n('AStat_nb_total_ip')." : $nbfoundrows"; |
---|
1024 | $template_datas["PAGES_LINKS"] = $pages_links; |
---|
1025 | $template_datas["ASTAT_NFO_STAT"]= l10n("AStat_Nfo_IP"); |
---|
1026 | |
---|
1027 | $template_datas["ASTAT_SORT_LABEL"] = l10n("AStat_SortIPLabel").strtolower(l10n("AStat_sortip_$sortip")); |
---|
1028 | |
---|
1029 | $template_datas["ASTAT_LABEL_IP_label"] = $this->format_link(l10n("AStat_RefIPLabel"), $page_link."&fAStat_SortIP=ip"); |
---|
1030 | $template_datas["ASTAT_LABEL_Pages_seen"] = $this->format_link(l10n("Pages seen"), $page_link."&fAStat_SortIP=page"); |
---|
1031 | $template_datas["ASTAT_LABEL_Pictures_seen"] = $this->format_link(l10n("Pictures_seen"), $page_link."&fAStat_SortIP=picture"); |
---|
1032 | |
---|
1033 | if($seetimerequest=='true') |
---|
1034 | { |
---|
1035 | $template_datas["ASTAT_TIME_REQUEST"] = l10n('AStat_time_request_label').' '.$timerequest.'s'; |
---|
1036 | } |
---|
1037 | |
---|
1038 | for($i=0;$i<count($stats);$i++) |
---|
1039 | { |
---|
1040 | if($stats[$i]["MaxPages"] > 0) |
---|
1041 | { |
---|
1042 | $width_pages = ceil(($stats[$i]["NbPages"] * $max_width) / $stats[$i]["MaxPages"] ); |
---|
1043 | $width_img = ceil(($stats[$i]["NbImg"] * $max_width) / $stats[$i]["MaxPages"] ); |
---|
1044 | } |
---|
1045 | else |
---|
1046 | { |
---|
1047 | $width_pages = 0; |
---|
1048 | $width_img = 0; |
---|
1049 | } |
---|
1050 | |
---|
1051 | |
---|
1052 | if($this->is_ip($stats[$i]["IP_USER"])) |
---|
1053 | { |
---|
1054 | $ip_geolocalisation='<a href="http://www.geoiptool.com/fr/?IP='.$stats[$i]["IP_USER"].'" title="Geo IP localisation" target="_blank">['.l10n('AStat_IP_geolocalisation').'] </a>'; |
---|
1055 | $ip_adress='<a href="http://www.ripe.net/whois?form_type=simple&full_query_string=&searchtext='.$stats[$i]["IP_USER"].'+&do_search=Search" title="Ripe Whois" target="_blank">'.$stats[$i]["IP_USER"].'</a>'; |
---|
1056 | $ip_blacklist=$page_link."&fAStat_IP_BL=".$stats[$i]["IP_USER"]; |
---|
1057 | |
---|
1058 | if($pagenumber>1) |
---|
1059 | { |
---|
1060 | $ip_blacklist.="&fAStat_page_number=$pagenumber"; |
---|
1061 | } |
---|
1062 | |
---|
1063 | if($sortip!="page") |
---|
1064 | { |
---|
1065 | $ip_blacklist.="&fAStat_SortIP=$sortip"; |
---|
1066 | } |
---|
1067 | |
---|
1068 | if($stats[$i]["blacklist"]=='Y') |
---|
1069 | { |
---|
1070 | $ip_blacklist="[".l10n('AStat_IP_blacklist')."]"; |
---|
1071 | } |
---|
1072 | else |
---|
1073 | { |
---|
1074 | $ip_blacklist=$this->format_link("[".l10n('AStat_IP_blacklist')."]", $ip_blacklist); |
---|
1075 | } |
---|
1076 | } |
---|
1077 | else |
---|
1078 | { |
---|
1079 | $ip_geolocalisation=''; |
---|
1080 | $ip_adress=$stats[$i]["IP_USER"]; |
---|
1081 | $ip_blacklist=''; |
---|
1082 | } |
---|
1083 | |
---|
1084 | |
---|
1085 | |
---|
1086 | $template_datarows[]=array( |
---|
1087 | 'ASTAT_IP_BLACKLIST' => $ip_blacklist, |
---|
1088 | 'ASTAT_IP_GEOLOCALISATION' => $ip_geolocalisation, |
---|
1089 | 'ASTAT_IP_ADRESS' => $ip_adress, |
---|
1090 | 'PAGES' => $stats[$i]["NbPages"], |
---|
1091 | 'PICTURES' => $this->format_link($stats[$i]["NbImg"], $img_link."&fAStat_IP=".trim($stats[$i]["IP_USER"])), |
---|
1092 | 'WIDTH1' => $width_img, |
---|
1093 | 'WIDTH2' => $width_pages, |
---|
1094 | ); |
---|
1095 | } |
---|
1096 | |
---|
1097 | $template->assign('datas', $template_datas); |
---|
1098 | $template->assign('datarows', $template_datarows); |
---|
1099 | $template->assign_var_from_handle('ASTAT_BODY_PAGE', 'body_page'); |
---|
1100 | } // display_stat_by_ip |
---|
1101 | |
---|
1102 | |
---|
1103 | |
---|
1104 | |
---|
1105 | |
---|
1106 | /* |
---|
1107 | display stat by category |
---|
1108 | */ |
---|
1109 | private function display_stats_by_category($year, $month, $day, $max_width, $nbipperpage, $pagenumber,$showthumb, $sortcat, $seetimerequest) |
---|
1110 | { |
---|
1111 | global $template, $conf; |
---|
1112 | |
---|
1113 | $template->set_filename('body_page', dirname(__FILE__)."/admin/astat_by_category.tpl"); |
---|
1114 | |
---|
1115 | $template_datas=array(); |
---|
1116 | $template_datarows=array(); |
---|
1117 | |
---|
1118 | /* requete */ |
---|
1119 | //calc_time(true); |
---|
1120 | $returned = $this->stats_by_category($year, $month, $day, $nbipperpage, $pagenumber, $showthumb, $sortcat); |
---|
1121 | //$timerequest=calc_time(false); |
---|
1122 | $stats=$returned[0]; |
---|
1123 | $nbfoundrows=$returned[1]; |
---|
1124 | $nbpages=ceil($nbfoundrows / $nbipperpage); |
---|
1125 | |
---|
1126 | |
---|
1127 | $dir_links = ""; |
---|
1128 | $page_link = ""; |
---|
1129 | $a_links=array("global" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=Y", |
---|
1130 | "all" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N", |
---|
1131 | "year" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year", |
---|
1132 | "month" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year&fAStat_month=$month", |
---|
1133 | "day" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year&fAStat_month=$month&fAStat_day=$day"); |
---|
1134 | |
---|
1135 | $cat_links=array("all" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_category", |
---|
1136 | "year" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_category&fAStat_year=$year", |
---|
1137 | "month" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_category&fAStat_year=$year&fAStat_month=$month", |
---|
1138 | "day" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_category&fAStat_year=$year&fAStat_month=$month&fAStat_day=$day"); |
---|
1139 | |
---|
1140 | /* make navigation links */ |
---|
1141 | if($day!="") |
---|
1142 | { |
---|
1143 | $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".$this->format_link(l10n("AStat_month_of_year_".$month), $a_links["month"])." / ".l10n("AStat_day_of_week_".date("w",mktime(0, 0, 0, $month, $day, $year)))." $day"; |
---|
1144 | $page_link=$cat_links["day"]; |
---|
1145 | } |
---|
1146 | elseif($month!="") |
---|
1147 | { |
---|
1148 | $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".l10n("AStat_month_of_year_".$month); |
---|
1149 | $page_link=$cat_links["month"]; |
---|
1150 | } |
---|
1151 | elseif($year!="") |
---|
1152 | { |
---|
1153 | $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$year; |
---|
1154 | $page_link=$cat_links["year"]; |
---|
1155 | } |
---|
1156 | else |
---|
1157 | { |
---|
1158 | $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".l10n("AStat_period_label_all"); |
---|
1159 | $page_link=$cat_links["all"]; |
---|
1160 | } |
---|
1161 | |
---|
1162 | |
---|
1163 | if($nbpages>1) |
---|
1164 | { |
---|
1165 | $plural="s"; |
---|
1166 | } |
---|
1167 | else |
---|
1168 | { |
---|
1169 | $plural=""; |
---|
1170 | } |
---|
1171 | |
---|
1172 | $pages_links=l10n("AStat_page".$plural."_label")." : "; |
---|
1173 | for($i=1;$i<=$nbpages;$i++) |
---|
1174 | { |
---|
1175 | if($i==$pagenumber) |
---|
1176 | { |
---|
1177 | $pages_links.=" $i "; |
---|
1178 | } |
---|
1179 | else |
---|
1180 | { |
---|
1181 | $pages_links.=$this->format_link(" $i ", $page_link."&fAStat_SortCat=$sortcat&fAStat_page_number=$i"); |
---|
1182 | } |
---|
1183 | } |
---|
1184 | |
---|
1185 | |
---|
1186 | /* navigation */ |
---|
1187 | $template_datas["L_STAT_TITLE"] = $dir_links; |
---|
1188 | $template_datas["MAX_WIDTH"] = $max_width; |
---|
1189 | $template_datas["NB_TOTAL_CATEGORY"] = l10n('AStat_nb_total_category')." : $nbfoundrows"; |
---|
1190 | $template_datas["PAGES_LINKS"] = $pages_links; |
---|
1191 | $template_datas["ASTAT_NFO_STAT"] = l10n("AStat_Nfo_Category"); |
---|
1192 | $template_datas["ASTAT_SORT_LABEL"] = l10n("AStat_SortCatLabel").strtolower(l10n("AStat_sortcat_$sortcat")); |
---|
1193 | |
---|
1194 | $template_datas["ASTAT_LABEL_pct_Pages_seen"] = $this->format_link(l10n("pct_Pages_seen"), $page_link."&fAStat_SortCat=page"); |
---|
1195 | $template_datas["ASTAT_LABEL_pct_Pictures_seen"] = $this->format_link(l10n("pct_Pictures_seen"), $page_link."&fAStat_SortCat=picture"); |
---|
1196 | $template_datas["ASTAT_LABEL_ratio_Pictures_seen"] = $this->format_link(l10n("ratio_Pictures_seen"), $page_link."&fAStat_SortCat=nbpicture"); |
---|
1197 | |
---|
1198 | if($seetimerequest=='true') |
---|
1199 | { |
---|
1200 | $template_datas["ASTAT_TIME_REQUEST"] = l10n('AStat_time_request_label').' '.$timerequest.'s'; |
---|
1201 | } |
---|
1202 | |
---|
1203 | for($i=0;$i<count($stats);$i++) |
---|
1204 | { |
---|
1205 | $width_pages = ceil(($stats[$i]["PctPages"] * $max_width)/100); |
---|
1206 | $width_img = ceil(($stats[$i]["PctImg"] * $max_width)/100 ); |
---|
1207 | |
---|
1208 | if($showthumb=='true') |
---|
1209 | { |
---|
1210 | $filethumb=$this->change_file_ext($stats[$i]["ThumbFile"], $stats[$i]["Extension"]); |
---|
1211 | $filethumb=str_replace($stats[$i]["ThumbFile"],"thumbnail/".$conf['prefix_thumbnail'].$filethumb,$stats[$i]["ThumbPath"]); } |
---|
1212 | else |
---|
1213 | { |
---|
1214 | $filethumb=''; |
---|
1215 | } |
---|
1216 | |
---|
1217 | if($stats[$i]["category_id"]>0) |
---|
1218 | { $category = $this->format_link($stats[$i]["IdCat"], PHPWG_ROOT_PATH."index.php?/category/".$stats[$i]["category_id"]); } |
---|
1219 | else |
---|
1220 | { |
---|
1221 | $category = "<i>".l10n('AStat_section_label').' : '; |
---|
1222 | if(l10n('AStat_section_'.$stats[$i]["IdCat"])!='AStat_section_'.$stats[$i]["IdCat"]) |
---|
1223 | { |
---|
1224 | $category.=l10n('AStat_section_'.$stats[$i]["IdCat"]); |
---|
1225 | } |
---|
1226 | else |
---|
1227 | { |
---|
1228 | $category.=sprintf(l10n('AStat_section_unknown'), $stats[$i]["IdCat"]); |
---|
1229 | } |
---|
1230 | |
---|
1231 | $category.="</i>"; |
---|
1232 | } |
---|
1233 | |
---|
1234 | $template_datarows[]=array( |
---|
1235 | 'THUMBJPG' => $filethumb, |
---|
1236 | 'CATEGORY' => $category, |
---|
1237 | 'PCTPAGES' => $stats[$i]["PctPages"], |
---|
1238 | 'PCTPICTURES' => $stats[$i]["PctImg"], |
---|
1239 | 'RATIOPICTURES' => $stats[$i]["RatioImg"], |
---|
1240 | 'WIDTH1' => $width_img, |
---|
1241 | 'WIDTH2' => $width_pages, |
---|
1242 | ); |
---|
1243 | } |
---|
1244 | |
---|
1245 | $template->assign('datas', $template_datas); |
---|
1246 | $template->assign('datarows', $template_datarows); |
---|
1247 | $template->assign_var_from_handle('ASTAT_BODY_PAGE', 'body_page'); |
---|
1248 | } // display_stat_by_category |
---|
1249 | |
---|
1250 | |
---|
1251 | |
---|
1252 | /* ------------------------------------------------------------------------------------------ |
---|
1253 | display stats for images |
---|
1254 | ------------------------------------------------------------------------------------------ */ |
---|
1255 | function display_stats_by_image($year, $month, $day, $max_width, $nbipperpage, $pagenumber,$showthumb, $sortimg, $ip, $seetimerequest) |
---|
1256 | { |
---|
1257 | global $template, $conf; |
---|
1258 | |
---|
1259 | $template->set_filename('body_page', dirname(__FILE__)."/admin/astat_by_image.tpl"); |
---|
1260 | |
---|
1261 | |
---|
1262 | $template_datas=array(); |
---|
1263 | $template_datarows=array(); |
---|
1264 | |
---|
1265 | |
---|
1266 | //calc_time(true); |
---|
1267 | $returned = $this->stats_by_image($year, $month, $day, $nbipperpage, $pagenumber, $sortimg, $ip); |
---|
1268 | //$timerequest=calc_time(false); |
---|
1269 | $stats=$returned[0]; |
---|
1270 | $nbfoundrows=$returned[1]; |
---|
1271 | $nbpages=ceil($nbfoundrows / $nbipperpage); |
---|
1272 | |
---|
1273 | $dir_links = ""; |
---|
1274 | $page_link = ""; |
---|
1275 | $a_links=array("global" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=Y", |
---|
1276 | "all" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N", |
---|
1277 | "year" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year", |
---|
1278 | "month" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year&fAStat_month=$month", |
---|
1279 | "day" => $this->getAdminLink()."&fAStat_defper=N&fAStat_all=N&fAStat_year=$year&fAStat_month=$month&fAStat_day=$day"); |
---|
1280 | |
---|
1281 | $img_links=array("all" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_image", |
---|
1282 | "year" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_image&fAStat_year=$year", |
---|
1283 | "month" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_image&fAStat_year=$year&fAStat_month=$month", |
---|
1284 | "day" => $this->getAdminLink()."&fAStat_tabsheet=stats_by_image&fAStat_year=$year&fAStat_month=$month&fAStat_day=$day"); |
---|
1285 | |
---|
1286 | /* navigation links */ |
---|
1287 | if($day!="") |
---|
1288 | { |
---|
1289 | $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".$this->format_link(l10n("AStat_month_of_year_".$month), $a_links["month"])." / ".l10n("AStat_day_of_week_".date("w",mktime(0, 0, 0, $month, $day, $year)))." $day"; |
---|
1290 | $page_link=$img_links["day"]; |
---|
1291 | } |
---|
1292 | elseif($month!="") |
---|
1293 | { |
---|
1294 | $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".l10n("AStat_month_of_year_".$month); |
---|
1295 | $page_link=$img_links["month"]; |
---|
1296 | } |
---|
1297 | elseif($year!="") |
---|
1298 | { |
---|
1299 | $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$year; |
---|
1300 | $page_link=$img_links["year"]; |
---|
1301 | } |
---|
1302 | else |
---|
1303 | { |
---|
1304 | $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".l10n("AStat_period_label_all"); |
---|
1305 | $page_link=$img_links["all"]; |
---|
1306 | } |
---|
1307 | |
---|
1308 | if($ip!="") |
---|
1309 | { |
---|
1310 | $dir_links.= " [IP : $ip]"; |
---|
1311 | } |
---|
1312 | |
---|
1313 | |
---|
1314 | if($nbpages>1) { $plural="s"; } else { $plural=""; } |
---|
1315 | $pages_links=l10n("AStat_page".$plural."_label")." : "; |
---|
1316 | for($i=1;$i<=$nbpages;$i++) |
---|
1317 | { |
---|
1318 | if($i==$pagenumber) |
---|
1319 | { $pages_links.=" $i "; } |
---|
1320 | else |
---|
1321 | { |
---|
1322 | if($ip!="") { $ip_link="&fAStat_IP=$ip"; } else { $ip_link=""; } |
---|
1323 | $pages_links.=$this->format_link(" $i ", $page_link."&fAStat_SortImg=$sortimg&fAStat_page_number=$i".$ip_link); |
---|
1324 | } |
---|
1325 | } |
---|
1326 | |
---|
1327 | |
---|
1328 | /* navigation */ |
---|
1329 | $template_datas["L_STAT_TITLE"] = $dir_links; |
---|
1330 | $template_datas["MAX_WIDTH"] = $max_width; |
---|
1331 | $template_datas["NB_TOTAL_IMAGE"] = l10n('AStat_nb_total_image')." : $nbfoundrows"; |
---|
1332 | $template_datas["PAGES_LINKS"] = $pages_links; |
---|
1333 | $template_datas["ASTAT_NFO_STAT"] = l10n("AStat_Nfo_Image"); |
---|
1334 | $template_datas["ASTAT_SORT_LABEL"] = l10n("AStat_SortImgLabel").strtolower(l10n("AStat_sortimg_$sortimg")); |
---|
1335 | |
---|
1336 | $template_datas["ASTAT_LABEL_AStat_RefImageLabel"] = $this->format_link(l10n("AStat_RefImageLabel"), $page_link."&fAStat_SortImg=catname"); |
---|
1337 | $template_datas["ASTAT_LABEL_Pictures_seen"] = $this->format_link(l10n("Pictures_seen"), $page_link."&fAStat_SortImg=picture"); |
---|
1338 | $template_datas["ASTAT_LABEL_pct_Pictures_seen"] = l10n("pct_Pictures_seen"); |
---|
1339 | |
---|
1340 | if($seetimerequest=='true') |
---|
1341 | { |
---|
1342 | $template_datas["ASTAT_TIME_REQUEST"] = l10n('AStat_time_request_label').' '.$timerequest.'s'; |
---|
1343 | } |
---|
1344 | |
---|
1345 | for($i=0;$i<count($stats);$i++) |
---|
1346 | { |
---|
1347 | $width_pages = ceil(($stats[$i]["NbVues"] * $max_width)/$stats[$i]["NbVuesMax"] ); |
---|
1348 | $width_img = ceil(($stats[$i]["PctImg"] * $max_width)/100 ); |
---|
1349 | |
---|
1350 | if($showthumb=='true') |
---|
1351 | { |
---|
1352 | $filethumb=$this->change_file_ext($stats[$i]["ThumbFile"], $stats[$i]["Extension"]); |
---|
1353 | $filethumb=str_replace($stats[$i]["ThumbFile"],"thumbnail/".$conf['prefix_thumbnail'].$filethumb,$stats[$i]["ThumbPath"]); |
---|
1354 | } |
---|
1355 | else |
---|
1356 | { |
---|
1357 | $filethumb=''; |
---|
1358 | } |
---|
1359 | |
---|
1360 | |
---|
1361 | if($stats[$i]["IdCat"]>0) |
---|
1362 | { |
---|
1363 | $image_links = $this->format_link($stats[$i]["CatName"], PHPWG_ROOT_PATH."index.php?/category/".$stats[$i]["IdCat"])." / "; |
---|
1364 | if($stats[$i]["ImgName"]!="") |
---|
1365 | { |
---|
1366 | $image_links.=$this->format_link($stats[$i]["ImgName"], PHPWG_ROOT_PATH."picture.php?/".$stats[$i]["ImgId"]."/category/".$stats[$i]["IdCat"]); |
---|
1367 | } |
---|
1368 | else |
---|
1369 | { |
---|
1370 | if($stats[$i]["ThumbFile"]!="") |
---|
1371 | { |
---|
1372 | $image_links.=$this->format_link("[ ".$stats[$i]["ThumbFile"]." ]", PHPWG_ROOT_PATH."picture.php?/".$stats[$i]["ImgId"]."/category/".$stats[$i]["IdCat"]); |
---|
1373 | } |
---|
1374 | else |
---|
1375 | { |
---|
1376 | $image_links=l10n('AStat_deleted_picture')." [ Id #".$stats[$i]["ImgId"]." ]"; |
---|
1377 | } |
---|
1378 | } |
---|
1379 | } |
---|
1380 | else |
---|
1381 | { |
---|
1382 | $image_links = "<i>".l10n('AStat_section_label').' : '; |
---|
1383 | if(l10n('AStat_section_'.$stats[$i]["CatName"])!='AStat_section_'.$stats[$i]["CatName"]) |
---|
1384 | { |
---|
1385 | $image_links.=l10n('AStat_section_'.$stats[$i]["CatName"]); |
---|
1386 | } |
---|
1387 | else |
---|
1388 | { |
---|
1389 | $image_links.=sprintf(l10n('AStat_section_unknown'), $stats[$i]["CatName"]); |
---|
1390 | } |
---|
1391 | |
---|
1392 | $image_links.="</i> / "; |
---|
1393 | |
---|
1394 | if($stats[$i]["ImgName"]!="") |
---|
1395 | { |
---|
1396 | $image_links.=$stats[$i]["ImgName"]; |
---|
1397 | } |
---|
1398 | else |
---|
1399 | { |
---|
1400 | if($stats[$i]["ThumbFile"]!="") |
---|
1401 | { |
---|
1402 | $image_links.="[ ".$stats[$i]["ThumbFile"]." ]"; |
---|
1403 | } |
---|
1404 | else |
---|
1405 | { |
---|
1406 | $image_links=l10n('AStat_deleted_picture')." [ Id #".$stats[$i]["ImgId"]." ]"; |
---|
1407 | } |
---|
1408 | } |
---|
1409 | } |
---|
1410 | |
---|
1411 | |
---|
1412 | |
---|
1413 | $template_datarows[]=array( |
---|
1414 | 'THUMBJPG' => $filethumb, |
---|
1415 | 'IMAGE' => $image_links, |
---|
1416 | 'NBPICTURES' => $stats[$i]["NbVues"], |
---|
1417 | 'PCTPICTURES' => $stats[$i]["PctImg"], |
---|
1418 | 'WIDTH1' => $width_img, |
---|
1419 | 'WIDTH2' => $width_pages, |
---|
1420 | ); |
---|
1421 | } |
---|
1422 | |
---|
1423 | $template->assign('datas', $template_datas); |
---|
1424 | $template->assign('datarows', $template_datarows); |
---|
1425 | $template->assign_var_from_handle('ASTAT_BODY_PAGE', 'body_page'); |
---|
1426 | } // display_stat_by_image |
---|
1427 | |
---|
1428 | |
---|
1429 | |
---|
1430 | |
---|
1431 | private function add_ip_to_filter($ip) |
---|
1432 | { |
---|
1433 | if(strpos($this->config['AStat_BlackListedIP'].",", $ip.",")===false) |
---|
1434 | { |
---|
1435 | ($this->config['AStat_BlackListedIP']!='')?$this->config['AStat_BlackListedIP'].=",":""; |
---|
1436 | $this->config['AStat_BlackListedIP'].=$ip; |
---|
1437 | $this->saveConfig(); |
---|
1438 | } |
---|
1439 | } |
---|
1440 | |
---|
1441 | |
---|
1442 | /* |
---|
1443 | display config page |
---|
1444 | */ |
---|
1445 | private function display_config() |
---|
1446 | { |
---|
1447 | global $template, $page; |
---|
1448 | |
---|
1449 | $save_status=false; |
---|
1450 | |
---|
1451 | if(isset($_POST['submit'])) |
---|
1452 | { |
---|
1453 | if(!is_adviser()) |
---|
1454 | { |
---|
1455 | reset($this->config); |
---|
1456 | while (list($key, $val) = each($this->config)) |
---|
1457 | { |
---|
1458 | if(isset($_POST['f_'.$key])) |
---|
1459 | { |
---|
1460 | $this->config[$key] = $_POST['f_'.$key]; |
---|
1461 | } |
---|
1462 | } |
---|
1463 | if($this->saveConfig()) |
---|
1464 | { |
---|
1465 | array_push($page['infos'], l10n('AStat_config_saved')); |
---|
1466 | } |
---|
1467 | else |
---|
1468 | { |
---|
1469 | array_push($page['errors'], l10n('AStat_adviser_not_authorized')); |
---|
1470 | } |
---|
1471 | } |
---|
1472 | else |
---|
1473 | { |
---|
1474 | array_push($page['errors'], l10n('AStat_adviser_not_authorized')); |
---|
1475 | } |
---|
1476 | } |
---|
1477 | |
---|
1478 | $template->set_filename('body_page', dirname(__FILE__).'/admin/astat_config.tpl'); |
---|
1479 | |
---|
1480 | $template_datas=array(); |
---|
1481 | $template_list_values=array(); |
---|
1482 | $template_list_labels=array(); |
---|
1483 | |
---|
1484 | //standards inputs zones |
---|
1485 | reset($this->config); |
---|
1486 | while (list($key, $val) = each($this->config)) |
---|
1487 | { |
---|
1488 | $template_datas["f_".$key]=$val; |
---|
1489 | } |
---|
1490 | |
---|
1491 | // |
---|
1492 | $template_datas['ajaxurl']=$this->getAdminLink(); |
---|
1493 | |
---|
1494 | // define selected item for lists zones |
---|
1495 | $template_datas['AStat_periods_selected']=$this->config['AStat_default_period']; |
---|
1496 | $template_datas['AStat_defaultsortcat_selected']=$this->config['AStat_DefaultSortCat']; |
---|
1497 | $template_datas['AStat_defaultsortip_selected']=$this->config['AStat_DefaultSortIP']; |
---|
1498 | $template_datas['AStat_defaultsortimg_selected']=$this->config['AStat_DefaultSortImg']; |
---|
1499 | |
---|
1500 | $template_datas['AStat_showthumbcat_selected']=$this->config['AStat_ShowThumbCat']; |
---|
1501 | $template_datas['AStat_showthumbimg_selected']=$this->config['AStat_ShowThumbImg']; |
---|
1502 | $template_datas['AStat_UseBlackList_selected']=$this->config['AStat_UseBlackList']; |
---|
1503 | |
---|
1504 | // making lists zones |
---|
1505 | // default period |
---|
1506 | reset($this->list_periods); |
---|
1507 | while (list($key, $val) = each($this->list_periods)) |
---|
1508 | { |
---|
1509 | $template_list_values['periods'][]=$val; |
---|
1510 | $template_list_labels['periods'][]=l10n('AStat_PeriodPerDefault_'.$val); |
---|
1511 | } |
---|
1512 | // default category order |
---|
1513 | reset($this->list_sortcat); |
---|
1514 | while (list($key, $val) = each($this->list_sortcat)) |
---|
1515 | { |
---|
1516 | $template_list_values['sortcat'][]=$val; |
---|
1517 | $template_list_labels['sortcat'][]=l10n('AStat_sortcat_'.$val); |
---|
1518 | } |
---|
1519 | // default ip order |
---|
1520 | reset($this->list_sortip); |
---|
1521 | while (list($key, $val) = each($this->list_sortip)) |
---|
1522 | { |
---|
1523 | $template_list_values['sortip'][]=$val; |
---|
1524 | $template_list_labels['sortip'][]=l10n('AStat_sortip_'.$val); |
---|
1525 | } |
---|
1526 | // default picture order |
---|
1527 | reset($this->list_sortimg); |
---|
1528 | while (list($key, $val) = each($this->list_sortimg)) |
---|
1529 | { |
---|
1530 | $template_list_values['sortimg'][]=$val; |
---|
1531 | $template_list_labels['sortimg'][]=l10n('AStat_sortimg_'.$val); |
---|
1532 | } |
---|
1533 | |
---|
1534 | /* yes/no lists */ |
---|
1535 | $template_list_values['yesno'][]='true'; |
---|
1536 | $template_list_labels['yesno'][]=l10n('AStat_yesno_true'); |
---|
1537 | $template_list_values['yesno'][]='false'; |
---|
1538 | $template_list_labels['yesno'][]=l10n('AStat_yesno_false'); |
---|
1539 | |
---|
1540 | $template_list_values['enableddisabled'][]='true'; |
---|
1541 | $template_list_values['enableddisabled'][]='false'; |
---|
1542 | $template_list_values['enableddisabled'][]='invert'; |
---|
1543 | $template_list_labels['enableddisabled'][]=l10n('AStat_enableddisabled_true'); |
---|
1544 | $template_list_labels['enableddisabled'][]=l10n('AStat_enableddisabled_false'); |
---|
1545 | $template_list_labels['enableddisabled'][]=l10n('AStat_enableddisabled_invert'); |
---|
1546 | |
---|
1547 | $template_datas["L_STAT_TITLE"]=l10n('AStat_config_title'); |
---|
1548 | |
---|
1549 | $template->assign("datas", $template_datas); |
---|
1550 | $template->assign("AStat_periods_list_values", $template_list_values['periods']); |
---|
1551 | $template->assign("AStat_periods_list_labels", $template_list_labels['periods']); |
---|
1552 | $template->assign("AStat_defaultsortip_list_values", $template_list_values['sortip']); |
---|
1553 | $template->assign("AStat_defaultsortip_list_labels", $template_list_labels['sortip']); |
---|
1554 | $template->assign("AStat_defaultsortcat_list_values", $template_list_values['sortcat']); |
---|
1555 | $template->assign("AStat_defaultsortcat_list_labels", $template_list_labels['sortcat']); |
---|
1556 | $template->assign("AStat_defaultsortimg_list_values", $template_list_values['sortimg']); |
---|
1557 | $template->assign("AStat_defaultsortimg_list_labels", $template_list_labels['sortimg']); |
---|
1558 | $template->assign("AStat_yesno_list_values", $template_list_values['yesno']); |
---|
1559 | $template->assign("AStat_yesno_list_labels", $template_list_labels['yesno']); |
---|
1560 | $template->assign("AStat_enableddisabled_list_values", $template_list_values['enableddisabled']); |
---|
1561 | $template->assign("AStat_enableddisabled_list_labels", $template_list_labels['enableddisabled']); |
---|
1562 | |
---|
1563 | $template->assign_var_from_handle('ASTAT_BODY_PAGE', 'body_page'); |
---|
1564 | } // display_config |
---|
1565 | |
---|
1566 | |
---|
1567 | |
---|
1568 | /* |
---|
1569 | display tools page |
---|
1570 | */ |
---|
1571 | private function display_tools() |
---|
1572 | { |
---|
1573 | global $template, $page; |
---|
1574 | |
---|
1575 | $action_result=array('result' => '', 'action' => '', 'msg' => '', 'nfo' => ''); |
---|
1576 | |
---|
1577 | $template->set_filename('body_page', dirname(__FILE__).'/admin/astat_tools.tpl'); |
---|
1578 | |
---|
1579 | $template_datas=array(); |
---|
1580 | |
---|
1581 | // >> PURGE HISTORY -------------------------------------------------------- |
---|
1582 | if(isset($_POST['apply_tool_purge_history'])) |
---|
1583 | { |
---|
1584 | if(!is_adviser()) |
---|
1585 | { |
---|
1586 | $action_result['action']='AStat_tools_purge_history'; |
---|
1587 | $action_result['result']='false'; |
---|
1588 | $action_result['msg']='AStat_tools_result_ko'; |
---|
1589 | |
---|
1590 | $ok_to_purge=true; |
---|
1591 | if($_REQUEST['fAStat_purge_history_type']=='bydate') |
---|
1592 | { |
---|
1593 | // may be this functionnality could be optimized with pcre functions |
---|
1594 | $date=explode('/', $_REQUEST['fAStat_purge_history_date']); |
---|
1595 | if(!isset($date[0])) { $date[0]=0; } |
---|
1596 | if(!isset($date[1])) { $date[1]=0; } |
---|
1597 | if(!isset($date[2])) { $date[2]=0; } |
---|
1598 | |
---|
1599 | $purge_date=mktime(0,0,0,$date[1],$date[0],$date[2]); |
---|
1600 | $fparam=date("Y-m-d", mktime(0,0,0,$date[1],$date[0],$date[2])); |
---|
1601 | |
---|
1602 | if(date("d/m/Y", $purge_date)!=$_REQUEST['fAStat_purge_history_date']) |
---|
1603 | { |
---|
1604 | $action_result['nfo']='AStat_tools_invalid_date'; |
---|
1605 | $ok_to_purge=false; |
---|
1606 | } |
---|
1607 | elseif(date("Ymd", $purge_date)>=date("Ymd")) |
---|
1608 | { |
---|
1609 | $action_result['nfo']='AStat_tools_invalid_date2'; |
---|
1610 | $ok_to_purge=false; |
---|
1611 | } |
---|
1612 | } |
---|
1613 | elseif($_REQUEST['fAStat_purge_history_type']=='byipid0') |
---|
1614 | { |
---|
1615 | $fparam=$this->config['AStat_BlackListedIP']; |
---|
1616 | } |
---|
1617 | else |
---|
1618 | { |
---|
1619 | $fparam=""; |
---|
1620 | } |
---|
1621 | |
---|
1622 | if($ok_to_purge) |
---|
1623 | { |
---|
1624 | $result=$this->do_purge_history( $fparam, $_REQUEST['fAStat_purge_history_type']); |
---|
1625 | if($result) |
---|
1626 | { |
---|
1627 | $action_result['result']='true'; |
---|
1628 | $action_result['msg']='AStat_tools_result_ok'; |
---|
1629 | } |
---|
1630 | } |
---|
1631 | } |
---|
1632 | else |
---|
1633 | { |
---|
1634 | array_push($page['errors'], l10n('AStat_adviser_not_authorized')); |
---|
1635 | } |
---|
1636 | } |
---|
1637 | // << PURGE HISTORY -------------------------------------------------------- |
---|
1638 | |
---|
1639 | // >> DELETED_PICTURE ------------------------------------------------------ |
---|
1640 | elseif(isset($_POST['apply_tool_deleted_picture_resync'])) |
---|
1641 | { |
---|
1642 | if(!is_adviser()) |
---|
1643 | { |
---|
1644 | $action_result['action']='AStat_tools_deleted_picture'; |
---|
1645 | $action_result['result']='false'; |
---|
1646 | $action_result['msg']='AStat_tools_result_ko'; |
---|
1647 | |
---|
1648 | if($_POST['fAStat_tools_deleted_picture_action']=='prepare') |
---|
1649 | { |
---|
1650 | if($this->prepare_AStat_picture_table()) |
---|
1651 | { |
---|
1652 | $action_result['result']='true'; |
---|
1653 | $action_result['msg']='AStat_tools_result_ok'; |
---|
1654 | $action_result['nfo']='AStat_tools_deleted_picture_ok0'; |
---|
1655 | } |
---|
1656 | else |
---|
1657 | { |
---|
1658 | $action_result['nfo']='AStat_tools_deleted_picture_error0'; |
---|
1659 | } |
---|
1660 | } |
---|
1661 | elseif($_POST['fAStat_tools_deleted_picture_action']=='apply') |
---|
1662 | { |
---|
1663 | if($this->apply_AStat_picture_table()) |
---|
1664 | { |
---|
1665 | $action_result['result']='true'; |
---|
1666 | $action_result['msg']='AStat_tools_result_ok'; |
---|
1667 | $action_result['nfo']='AStat_tools_deleted_picture_ok1'; |
---|
1668 | } |
---|
1669 | else |
---|
1670 | { |
---|
1671 | $action_result['nfo']='AStat_tools_deleted_picture_error1'; |
---|
1672 | } |
---|
1673 | } |
---|
1674 | } |
---|
1675 | else |
---|
1676 | { |
---|
1677 | array_push($page['errors'], l10n('AStat_adviser_not_authorized')); |
---|
1678 | } |
---|
1679 | } |
---|
1680 | // |
---|
1681 | elseif(isset($_POST['apply_tool_deleted_picture'])) |
---|
1682 | { |
---|
1683 | if(!is_adviser()) |
---|
1684 | { |
---|
1685 | $action_result['action']='AStat_tools_deleted_picture'; |
---|
1686 | $action_result['result']='false'; |
---|
1687 | $action_result['msg']='AStat_tools_result_ko'; |
---|
1688 | |
---|
1689 | $nfo = $this->tools_deleted_picture('to0'); |
---|
1690 | if($nfo[0]==1) |
---|
1691 | { |
---|
1692 | $action_result['result']='true'; |
---|
1693 | $action_result['msg']='AStat_tools_result_ok'; |
---|
1694 | } |
---|
1695 | } |
---|
1696 | else |
---|
1697 | { |
---|
1698 | array_push($page['errors'], l10n('AStat_adviser_not_authorized')); |
---|
1699 | } |
---|
1700 | } |
---|
1701 | // << DELETED_PICTURE ------------------------------------------------------ |
---|
1702 | |
---|
1703 | // >> DELETED_CATEGORY ----------------------------------------------------- |
---|
1704 | elseif(isset($_POST['apply_tool_deleted_category'])) |
---|
1705 | { |
---|
1706 | if(!is_adviser()) |
---|
1707 | { |
---|
1708 | $action_result['action']='AStat_tools_deleted_category'; |
---|
1709 | $action_result['result']='false'; |
---|
1710 | $action_result['msg']='AStat_tools_result_ko'; |
---|
1711 | |
---|
1712 | $nfo = $this->tools_deleted_category('to0'); |
---|
1713 | if($nfo[0]==1) |
---|
1714 | { |
---|
1715 | $action_result['result']='true'; |
---|
1716 | $action_result['msg']='AStat_tools_result_ok'; |
---|
1717 | } |
---|
1718 | } |
---|
1719 | else |
---|
1720 | { |
---|
1721 | array_push($page['errors'], l10n('AStat_adviser_not_authorized')); |
---|
1722 | } |
---|
1723 | } |
---|
1724 | // << DELETED_CATEGORY ----------------------------------------------------- |
---|
1725 | |
---|
1726 | // >> DELETED USER --------------------------------------------------------- |
---|
1727 | elseif(isset($_POST['apply_tool_deleted_user'])) |
---|
1728 | { |
---|
1729 | if(!is_adviser()) |
---|
1730 | { |
---|
1731 | $action_result['action']='AStat_tools_deleted_user'; |
---|
1732 | $action_result['result']='false'; |
---|
1733 | $action_result['msg']='AStat_tools_result_ko'; |
---|
1734 | |
---|
1735 | $nfo = $this->tools_deleted_user('resynchro'); |
---|
1736 | if($nfo[0]==1) |
---|
1737 | { |
---|
1738 | $action_result['result']='true'; |
---|
1739 | $action_result['msg']='AStat_tools_result_ok'; |
---|
1740 | } |
---|
1741 | } |
---|
1742 | else |
---|
1743 | { |
---|
1744 | array_push($page['errors'], l10n('AStat_adviser_not_authorized')); |
---|
1745 | } |
---|
1746 | } |
---|
1747 | // << DELETED USER --------------------------------------------------------- |
---|
1748 | |
---|
1749 | |
---|
1750 | // >> DISPLAY DELETED_PICTURE NFO ------------------------------------------ |
---|
1751 | $table_exists=$this->verify_AStat_picture_table_status(); |
---|
1752 | if($table_exists==true) |
---|
1753 | { |
---|
1754 | $template_datas["ASTAT_DELETED_PICTURE_DO_ACTION"] = "checked"; |
---|
1755 | $template_datas["ASTAT_DELETED_PICTURE_PREPARE"] = "disabled"; |
---|
1756 | } |
---|
1757 | else |
---|
1758 | { |
---|
1759 | $template_datas["ASTAT_DELETED_PICTURE_PREPARE"]="checked"; |
---|
1760 | $template_datas["ASTAT_DELETED_PICTURE_DO_ACTION"]="disabled"; |
---|
1761 | } |
---|
1762 | |
---|
1763 | $nfo=$this->count_AStat_picture_table(); |
---|
1764 | $template_datas["ASTAT_DELETED_PICTURE_NFO_NB"] = sprintf(l10n('AStat_tools_deleted_picture_nfo_nb'), $nfo[1], $nfo[2]); |
---|
1765 | |
---|
1766 | $nfo = $this->tools_deleted_picture('analyse'); |
---|
1767 | if($nfo[0]>0) |
---|
1768 | { |
---|
1769 | $list=''; |
---|
1770 | for($i=0;$i<count($nfo[2]);$i++) |
---|
1771 | { |
---|
1772 | if($nfo[2][$i][0]>1) { $s='s'; } else { $s=''; } |
---|
1773 | $list.="<li>image_id #".$nfo[2][$i][1]." : ".$nfo[2][$i][0]." ".l10n("AStat_event$s")."</li>"; |
---|
1774 | } |
---|
1775 | $template_datas["ASTAT_DELETED_PICTURE_NFO"] = sprintf(l10n('AStat_tools_deleted_picture_nfo1'), $nfo[0], $nfo[1], $list); |
---|
1776 | //function not yet implemented |
---|
1777 | $template_datas['AStat_deleted_picture_submit0'] = 'yes'; |
---|
1778 | } |
---|
1779 | else |
---|
1780 | { |
---|
1781 | $template_datas["ASTAT_DELETED_PICTURE_NFO"] = l10n('AStat_tools_deleted_picture_nfo2'); |
---|
1782 | } |
---|
1783 | // << DISPLAY DELETED_PICTURE NFO ------------------------------------------ |
---|
1784 | |
---|
1785 | // >> DISPLAY DELETED_CATEGORY NFO ----------------------------------------- |
---|
1786 | $nfo = $this->tools_deleted_category('analyse'); |
---|
1787 | if($nfo[0]>0) |
---|
1788 | { |
---|
1789 | $list=''; |
---|
1790 | for($i=0;$i<count($nfo[2]);$i++) |
---|
1791 | { |
---|
1792 | if($nfo[2][$i][0]>1) { $s='s'; } else { $s=''; } |
---|
1793 | $list.="<li>category_id #".$nfo[2][$i][1]." : ".$nfo[2][$i][0]." ".l10n("AStat_event$s")."</li>"; |
---|
1794 | } |
---|
1795 | $template_datas["ASTAT_DELETED_CATEGORY_NFO"] = sprintf(l10n('AStat_tools_deleted_category_nfo1'), $nfo[0], $nfo[1], $list); |
---|
1796 | //function not yet implemented |
---|
1797 | $template_datas['AStat_deleted_category_submit0'] = 'yes'; |
---|
1798 | } |
---|
1799 | else |
---|
1800 | { |
---|
1801 | $template_datas["ASTAT_DELETED_CATEGORY_NFO"] = l10n('AStat_tools_deleted_category_nfo2'); |
---|
1802 | } |
---|
1803 | // << DISPLAY DELETED_CATEGORY NFO ----------------------------------------- |
---|
1804 | |
---|
1805 | // >> DISPLAY DELETED USER NFO --------------------------------------------- |
---|
1806 | $nfo = $this->tools_deleted_user('analyse'); |
---|
1807 | if($nfo[0]>0) |
---|
1808 | { |
---|
1809 | $list=''; |
---|
1810 | for($i=0;$i<count($nfo[2]);$i++) |
---|
1811 | { |
---|
1812 | if($nfo[2][$i][0]>1) { $s='s'; } else { $s=''; } |
---|
1813 | $list.="<li>user_id #".$nfo[2][$i][1]." : ".$nfo[2][$i][0]." ".l10n("AStat_event$s")."</li>"; |
---|
1814 | } |
---|
1815 | $template_datas["ASTAT_DELETED_USER_NFO"] = sprintf(l10n('AStat_tools_deleted_user_nfo1'), $nfo[0], $nfo[1], $list); |
---|
1816 | $template_datas['AStat_deleted_user_submit'] = 'yes'; |
---|
1817 | } |
---|
1818 | else |
---|
1819 | { |
---|
1820 | $template_datas["ASTAT_DELETED_USER_NFO"] = l10n('AStat_tools_deleted_user_nfo2'); |
---|
1821 | } |
---|
1822 | // << DISPLAY DELETED USER NFO --------------------------------------------- |
---|
1823 | |
---|
1824 | |
---|
1825 | // >> DISPLAY GENERAL NFO -------------------------------------------------- |
---|
1826 | $nfo = $this->tools_general_nfo(); |
---|
1827 | if($nfo[0]>0) |
---|
1828 | { |
---|
1829 | $template_datas["ASTAT_GENERAL_NFO"] = sprintf(l10n('AStat_tools_general_nfo_nfo'), |
---|
1830 | $nfo[0], |
---|
1831 | $this->formatoctet($nfo[3]+$nfo[4], "A", " ", 2, true), |
---|
1832 | $this->formatoctet($nfo[3], "A", " ", 2, true), |
---|
1833 | $this->formatoctet($nfo[4], "A", " ", 2, true), |
---|
1834 | date(l10n('AStat_date_time_format'), strtotime($nfo[2])), |
---|
1835 | date(l10n('AStat_date_time_format'), strtotime($nfo[1])) ); |
---|
1836 | $template_datas["ASTAT_MINDATE"]=date("m/d/Y",strtotime($nfo[2])); |
---|
1837 | } |
---|
1838 | |
---|
1839 | $nfo=$this->purge_history_count_imageid0(); |
---|
1840 | $template_datas["ASTAT_PURGE_HISTORY_IMAGE_NFO"] = sprintf(l10n('AStat_tools_purge_history_imageid0'), $nfo); |
---|
1841 | if($nfo==0) |
---|
1842 | { |
---|
1843 | $template_datas["ASTAT_PURGE_HISTORY_IMAGE_DISABLED"] = " disabled "; |
---|
1844 | } |
---|
1845 | $nfo=$this->purge_history_count_categoryid0(); |
---|
1846 | $template_datas["ASTAT_PURGE_HISTORY_CATEGORY_NFO"] = sprintf(l10n('AStat_tools_purge_history_categoryid0'), $nfo); |
---|
1847 | if($nfo==0) |
---|
1848 | { |
---|
1849 | $template_datas["ASTAT_PURGE_HISTORY_CATEGORY_DISABLED"] = " disabled "; |
---|
1850 | } |
---|
1851 | $nfo=$this->purge_history_count_ipid0(); |
---|
1852 | $template_datas["ASTAT_PURGE_HISTORY_IP_NFO"] = sprintf(l10n('AStat_tools_purge_history_ipid0'), $nfo[1], $nfo[0]); |
---|
1853 | if($nfo[0]==0) |
---|
1854 | { |
---|
1855 | $template_datas["ASTAT_PURGE_HISTORY_IP_DISABLED"] = " disabled "; |
---|
1856 | } |
---|
1857 | // << GENERAL NFO ---------------------------------------------------------- |
---|
1858 | |
---|
1859 | |
---|
1860 | if($action_result['result']!='') |
---|
1861 | { |
---|
1862 | if($action_result['result']=='true') |
---|
1863 | { |
---|
1864 | $value="<p class='infos'>"; |
---|
1865 | } |
---|
1866 | else |
---|
1867 | { |
---|
1868 | $value="<p class='errors'>"; |
---|
1869 | } |
---|
1870 | $value.="<i>".l10n($action_result['action'])."</i><br>".l10n($action_result['msg'])."<br>"; |
---|
1871 | |
---|
1872 | if($action_result['nfo']!='') |
---|
1873 | { |
---|
1874 | $value.="[".l10n($action_result['nfo'])."]</p>"; |
---|
1875 | } |
---|
1876 | |
---|
1877 | $template_datas["ASTAT_RESULT_OK"] = $value; |
---|
1878 | } |
---|
1879 | |
---|
1880 | $template_datas["L_STAT_TITLE"] = l10n('AStat_tools_title'); |
---|
1881 | |
---|
1882 | $template->assign('datas', $template_datas); |
---|
1883 | $template->assign_var_from_handle('ASTAT_BODY_PAGE', 'body_page'); |
---|
1884 | } // display_tools |
---|
1885 | |
---|
1886 | |
---|
1887 | /* |
---|
1888 | tools functions |
---|
1889 | */ |
---|
1890 | |
---|
1891 | |
---|
1892 | |
---|
1893 | /* |
---|
1894 | tools : deleted_user |
---|
1895 | allow to force HISTORY_TABLE.user_id at 2 (guest) for records with user ident |
---|
1896 | doesn't exist anymore in the USERS_TABLE |
---|
1897 | |
---|
1898 | Two usages : |
---|
1899 | - analyse : return infos about records wich need to be updated |
---|
1900 | * number of users |
---|
1901 | * number of records in HISTORY_TABLE |
---|
1902 | * the users list |
---|
1903 | - resynchro : update table |
---|
1904 | */ |
---|
1905 | private function tools_deleted_user($mode) |
---|
1906 | { |
---|
1907 | $returned = array(-1,0,''); |
---|
1908 | |
---|
1909 | if($mode=='analyse') |
---|
1910 | { |
---|
1911 | $sql="SELECT count(id) as NbRecord, user_id "; |
---|
1912 | $sql.=" FROM ".HISTORY_TABLE; |
---|
1913 | $sql.=" WHERE ".HISTORY_TABLE.".user_id NOT IN (SELECT id FROM ".USERS_TABLE.") "; |
---|
1914 | $sql.=" GROUP BY user_id ORDER BY NbRecord"; |
---|
1915 | $result=pwg_query($sql); |
---|
1916 | if($result) |
---|
1917 | { |
---|
1918 | $returned[0]=0; |
---|
1919 | while ($row = pwg_db_fetch_row($result)) |
---|
1920 | { |
---|
1921 | $returned[2][$returned[0]][0] = $row[0]; |
---|
1922 | $returned[2][$returned[0]][1] = $row[1]; |
---|
1923 | $returned[0]++; |
---|
1924 | $returned[1]+=$row[0]; |
---|
1925 | } |
---|
1926 | |
---|
1927 | } |
---|
1928 | } |
---|
1929 | elseif($mode=='resynchro') |
---|
1930 | { |
---|
1931 | $sql="UPDATE ".HISTORY_TABLE." SET user_id = 2 "; |
---|
1932 | $sql.=" WHERE ".HISTORY_TABLE.".user_id NOT IN (SELECT id FROM ".USERS_TABLE.") "; |
---|
1933 | $result=pwg_query($sql); |
---|
1934 | if($result) |
---|
1935 | { $returned[0]=1; } |
---|
1936 | } |
---|
1937 | return($returned); |
---|
1938 | } |
---|
1939 | |
---|
1940 | |
---|
1941 | /* |
---|
1942 | tools : deleted_picture |
---|
1943 | analyse history to find deleted pictures |
---|
1944 | Two functions : |
---|
1945 | - analyse : return infos |
---|
1946 | * number of pictures |
---|
1947 | * number of record in HISTORY_TABLE |
---|
1948 | * pictures list |
---|
1949 | - to0 : update picture ident to 0 |
---|
1950 | */ |
---|
1951 | private function tools_deleted_picture($mode) |
---|
1952 | { |
---|
1953 | $returned = array(-1,0,''); |
---|
1954 | |
---|
1955 | if($mode=='analyse') |
---|
1956 | { |
---|
1957 | $sql="SELECT count(id) as NbRecord, image_id "; |
---|
1958 | $sql.=" FROM ".HISTORY_TABLE; |
---|
1959 | $sql.=" WHERE ".HISTORY_TABLE.".image_id NOT IN (SELECT id FROM ".IMAGES_TABLE.") and image_id > 0 "; |
---|
1960 | $sql.=" GROUP BY image_id ORDER BY NbRecord"; |
---|
1961 | $result=pwg_query($sql); |
---|
1962 | |
---|
1963 | if($result) |
---|
1964 | { |
---|
1965 | $returned[0]=0; |
---|
1966 | while ($row = pwg_db_fetch_row($result)) |
---|
1967 | { |
---|
1968 | $returned[2][$returned[0]][0] = $row[0]; |
---|
1969 | $returned[2][$returned[0]][1] = $row[1]; |
---|
1970 | $returned[0]++; |
---|
1971 | $returned[1]+=$row[0]; |
---|
1972 | } |
---|
1973 | |
---|
1974 | } |
---|
1975 | } |
---|
1976 | elseif($mode=='to0') |
---|
1977 | { |
---|
1978 | $sql="UPDATE ".HISTORY_TABLE." |
---|
1979 | SET image_id = 0 |
---|
1980 | WHERE ".HISTORY_TABLE.".image_id > 0 |
---|
1981 | AND ".HISTORY_TABLE.".image_id NOT IN (SELECT id FROM ".IMAGES_TABLE.")"; |
---|
1982 | $result=pwg_query($sql); |
---|
1983 | |
---|
1984 | if($result) |
---|
1985 | { |
---|
1986 | $returned[0]=1; |
---|
1987 | } |
---|
1988 | } |
---|
1989 | return($returned); |
---|
1990 | } |
---|
1991 | |
---|
1992 | |
---|
1993 | /* |
---|
1994 | tools : deleted_category |
---|
1995 | analyse history to find deleted categories |
---|
1996 | Two functions : |
---|
1997 | - analyse : return infos |
---|
1998 | * number of category |
---|
1999 | * number of record in HISTORY_TABLE |
---|
2000 | * catgories list |
---|
2001 | - to0 : update categories ident to 0 |
---|
2002 | */ |
---|
2003 | private function tools_deleted_category($mode) |
---|
2004 | { |
---|
2005 | $returned = array(-1,0,''); |
---|
2006 | |
---|
2007 | if($mode=='analyse') |
---|
2008 | { |
---|
2009 | $sql="SELECT count(id) as NbRecord, category_id "; |
---|
2010 | $sql.=" FROM ".HISTORY_TABLE; |
---|
2011 | $sql.=" WHERE ".HISTORY_TABLE.".category_id NOT IN (SELECT id FROM ".CATEGORIES_TABLE.") and category_id > 0"; |
---|
2012 | $sql.=" GROUP BY category_id ORDER BY NbRecord"; |
---|
2013 | $result=pwg_query($sql); |
---|
2014 | |
---|
2015 | if($result) |
---|
2016 | { |
---|
2017 | $returned[0]=0; |
---|
2018 | while ($row = pwg_db_fetch_row($result)) |
---|
2019 | { |
---|
2020 | $returned[2][$returned[0]][0] = $row[0]; |
---|
2021 | $returned[2][$returned[0]][1] = $row[1]; |
---|
2022 | $returned[0]++; |
---|
2023 | $returned[1]+=$row[0]; |
---|
2024 | } |
---|
2025 | |
---|
2026 | } |
---|
2027 | } |
---|
2028 | elseif($mode=='to0') |
---|
2029 | { |
---|
2030 | $sql="UPDATE ".HISTORY_TABLE." |
---|
2031 | SET category_id = NULL, section = 'deleted_cat' |
---|
2032 | WHERE ".HISTORY_TABLE.".category_id > 0 |
---|
2033 | AND ".HISTORY_TABLE.".category_id NOT IN (SELECT id FROM ".CATEGORIES_TABLE.")"; |
---|
2034 | $result=pwg_query($sql); |
---|
2035 | |
---|
2036 | if($result) |
---|
2037 | { |
---|
2038 | $returned[0]=1; |
---|
2039 | } |
---|
2040 | } |
---|
2041 | return($returned); |
---|
2042 | } |
---|
2043 | |
---|
2044 | |
---|
2045 | /* |
---|
2046 | tools : general_nfo |
---|
2047 | return infos about historic |
---|
2048 | 0 : nulber of records |
---|
2049 | 1 : date of newest record |
---|
2050 | 2 : date of oldesr record |
---|
2051 | 3 : table size |
---|
2052 | 4 : index size |
---|
2053 | */ |
---|
2054 | private function tools_general_nfo() |
---|
2055 | { |
---|
2056 | $returned = array(-1,'','',0,0); |
---|
2057 | |
---|
2058 | $sql="SELECT count(id) AS NbRecord, MAX(concat(date,' ', time)) AS LastDate, MIN(concat(date,' ', time)) AS FirstDate "; |
---|
2059 | $sql.=" FROM ".HISTORY_TABLE; |
---|
2060 | $result=pwg_query($sql); |
---|
2061 | if($result) |
---|
2062 | { |
---|
2063 | $row = pwg_db_fetch_row($result); |
---|
2064 | if(is_array($row)) |
---|
2065 | { |
---|
2066 | $returned = $row; |
---|
2067 | $sql="SHOW TABLE STATUS LIKE '".HISTORY_TABLE."';"; |
---|
2068 | $result=pwg_query($sql); |
---|
2069 | if($result) |
---|
2070 | { |
---|
2071 | $row2=pwg_db_fetch_assoc($result); |
---|
2072 | array_push($returned, $row2['Data_length'], $row2['Index_length']); |
---|
2073 | } |
---|
2074 | } |
---|
2075 | } |
---|
2076 | return($returned); |
---|
2077 | } |
---|
2078 | |
---|
2079 | |
---|
2080 | /* |
---|
2081 | tools : do_purge_history |
---|
2082 | do a purge of history table : |
---|
2083 | - $purgetype='bydate' : purge all record wich date is less than given date |
---|
2084 | - $purgetype='byimageid0' : with and image_id = 0 |
---|
2085 | ------------------------------------------------------------------------------------ */ |
---|
2086 | private function do_purge_history($param, $purgetype) |
---|
2087 | { |
---|
2088 | if($purgetype=='bydate') |
---|
2089 | { |
---|
2090 | $sql="DELETE FROM ".HISTORY_TABLE." WHERE date < '$param'"; |
---|
2091 | } |
---|
2092 | elseif($purgetype=='byimageid0') |
---|
2093 | { |
---|
2094 | $sql="DELETE FROM ".HISTORY_TABLE." WHERE image_id = 0"; |
---|
2095 | } |
---|
2096 | elseif($purgetype=='bycategoryid0') |
---|
2097 | { |
---|
2098 | $sql="DELETE FROM ".HISTORY_TABLE." WHERE category_id is null and section='deleted_cat'"; |
---|
2099 | } |
---|
2100 | elseif($purgetype=='byipid0') |
---|
2101 | { |
---|
2102 | $sql="DELETE FROM ".HISTORY_TABLE." WHERE ".$this->make_IP_where_clause($param); |
---|
2103 | } |
---|
2104 | else |
---|
2105 | { |
---|
2106 | return(false); |
---|
2107 | } |
---|
2108 | |
---|
2109 | $result=pwg_query($sql); |
---|
2110 | if($result) |
---|
2111 | { |
---|
2112 | $sql="OPTIMIZE TABLE ".HISTORY_TABLE; |
---|
2113 | $result=pwg_query($sql); |
---|
2114 | return($result); |
---|
2115 | } |
---|
2116 | return(false); |
---|
2117 | } |
---|
2118 | |
---|
2119 | private function purge_history_count_imageid0() |
---|
2120 | { |
---|
2121 | $sql="SELECT COUNT(id) FROM ".HISTORY_TABLE." WHERE image_id = 0"; |
---|
2122 | $result=pwg_query($sql); |
---|
2123 | if($result) |
---|
2124 | { |
---|
2125 | $row=pwg_db_fetch_row($result); |
---|
2126 | return($row[0]); |
---|
2127 | } |
---|
2128 | return(0); |
---|
2129 | } |
---|
2130 | |
---|
2131 | private function purge_history_count_categoryid0() |
---|
2132 | { |
---|
2133 | $sql="SELECT COUNT(id) FROM ".HISTORY_TABLE." WHERE category_id is null and section = 'deleted_cat'" ; |
---|
2134 | $result=pwg_query($sql); |
---|
2135 | if($result) |
---|
2136 | { |
---|
2137 | $row=pwg_db_fetch_row($result); |
---|
2138 | return($row[0]); |
---|
2139 | } |
---|
2140 | return(0); |
---|
2141 | } |
---|
2142 | |
---|
2143 | private function purge_history_count_ipid0() |
---|
2144 | { |
---|
2145 | if($this->config['AStat_BlackListedIP']!="") |
---|
2146 | { |
---|
2147 | $list=explode(',', $this->config['AStat_BlackListedIP']); |
---|
2148 | } |
---|
2149 | else |
---|
2150 | { |
---|
2151 | $list=array(); |
---|
2152 | } |
---|
2153 | |
---|
2154 | $returned=array(0,count($list)); |
---|
2155 | |
---|
2156 | if($this->config['AStat_BlackListedIP']!='') |
---|
2157 | { |
---|
2158 | $sql="SELECT COUNT(id) |
---|
2159 | FROM ".HISTORY_TABLE." |
---|
2160 | WHERE ".$this->make_IP_where_clause($this->config['AStat_BlackListedIP']); |
---|
2161 | $result=pwg_query($sql); |
---|
2162 | if($result) |
---|
2163 | { |
---|
2164 | $row=pwg_db_fetch_row($result); |
---|
2165 | $returned[0]=$row[0]; |
---|
2166 | } |
---|
2167 | } |
---|
2168 | return($returned); |
---|
2169 | } |
---|
2170 | |
---|
2171 | |
---|
2172 | /* |
---|
2173 | tools : deleted_picture |
---|
2174 | > verify_AStat_picture_table_status : |
---|
2175 | > prepare_AStat_picture_table : |
---|
2176 | */ |
---|
2177 | private function verify_AStat_picture_table_status() |
---|
2178 | { |
---|
2179 | global $prefixeTable; |
---|
2180 | |
---|
2181 | $sql="SHOW TABLE STATUS LIKE '".$prefixeTable."AStat_picture'"; |
---|
2182 | $result=pwg_query($sql); |
---|
2183 | if($result) |
---|
2184 | { |
---|
2185 | if(pwg_db_num_rows($result)==1) |
---|
2186 | { |
---|
2187 | return(true); |
---|
2188 | } |
---|
2189 | } |
---|
2190 | return(false); |
---|
2191 | } |
---|
2192 | |
---|
2193 | private function prepare_AStat_picture_table() |
---|
2194 | { |
---|
2195 | global $prefixeTable; |
---|
2196 | |
---|
2197 | $sql="CREATE TABLE ".$prefixeTable."AStat_picture (PRIMARY KEY (id), KEY ifile(file)) |
---|
2198 | SELECT id, file |
---|
2199 | FROM ".IMAGES_TABLE; |
---|
2200 | $result=pwg_query($sql); |
---|
2201 | if($result) |
---|
2202 | { |
---|
2203 | return(true); |
---|
2204 | } |
---|
2205 | return(false); |
---|
2206 | } |
---|
2207 | |
---|
2208 | private function count_AStat_picture_table() |
---|
2209 | { |
---|
2210 | global $prefixeTable; |
---|
2211 | $returned=array(false,0,0); |
---|
2212 | |
---|
2213 | if($this->verify_AStat_picture_table_status()) |
---|
2214 | { |
---|
2215 | $sql="SELECT count(DISTINCT ".$prefixeTable."AStat_picture.id), count(".HISTORY_TABLE.".id) |
---|
2216 | FROM ".HISTORY_TABLE.", ".$prefixeTable."AStat_picture |
---|
2217 | WHERE ".HISTORY_TABLE.".image_id = ".$prefixeTable."AStat_picture.id |
---|
2218 | AND ".HISTORY_TABLE.".image_id NOT IN (SELECT id FROM ".IMAGES_TABLE.") |
---|
2219 | ORDER BY ".$prefixeTable."AStat_picture.id"; |
---|
2220 | $result=pwg_query($sql); |
---|
2221 | if($result) |
---|
2222 | { |
---|
2223 | if(pwg_db_num_rows($result)>0) |
---|
2224 | { |
---|
2225 | $row=pwg_db_fetch_row($result); |
---|
2226 | $returned[0]=true; |
---|
2227 | $returned[1]=$row[0]; |
---|
2228 | $returned[2]=$row[1]; |
---|
2229 | } |
---|
2230 | } |
---|
2231 | } |
---|
2232 | return($returned); |
---|
2233 | } |
---|
2234 | |
---|
2235 | private function apply_AStat_picture_table() |
---|
2236 | { |
---|
2237 | global $prefixeTable; |
---|
2238 | $returned=false; |
---|
2239 | |
---|
2240 | $sql="CREATE TABLE ".$prefixeTable."AStat_picture2 (PRIMARY KEY (OldId)) |
---|
2241 | SELECT AStat_tmp.id as OldId , ".IMAGES_TABLE.".id as NewId, ".IMAGES_TABLE.".storage_category_id as NewCatId |
---|
2242 | FROM (SELECT DISTINCT ".$prefixeTable."AStat_picture.* |
---|
2243 | FROM ".HISTORY_TABLE.", ".$prefixeTable."AStat_picture |
---|
2244 | WHERE ".HISTORY_TABLE.".image_id = ".$prefixeTable."AStat_picture.id |
---|
2245 | AND ".HISTORY_TABLE.".image_id NOT IN (SELECT id FROM ".IMAGES_TABLE.") |
---|
2246 | ORDER BY ".$prefixeTable."AStat_picture.id |
---|
2247 | ) as AStat_tmp |
---|
2248 | LEFT JOIN ".IMAGES_TABLE." ON AStat_tmp.file = ".IMAGES_TABLE.".file"; |
---|
2249 | $result=pwg_query($sql); |
---|
2250 | if($result) |
---|
2251 | { |
---|
2252 | $sql="UPDATE ".HISTORY_TABLE.", ".$prefixeTable."AStat_picture2, ".IMAGES_TABLE." |
---|
2253 | SET ".HISTORY_TABLE.".image_id = ".$prefixeTable."AStat_picture2.NewId, |
---|
2254 | ".HISTORY_TABLE.".category_id = ".$prefixeTable."AStat_picture2.NewCatId |
---|
2255 | WHERE ".$prefixeTable."AStat_picture2.OldId = ".HISTORY_TABLE.".image_id"; |
---|
2256 | $result=pwg_query($sql); |
---|
2257 | if($result) |
---|
2258 | { |
---|
2259 | $returned=true; |
---|
2260 | } |
---|
2261 | $sql="DROP TABLE IF EXISTS ".$prefixeTable."AStat_picture2"; |
---|
2262 | $result=pwg_query($sql); |
---|
2263 | $sql="DROP TABLE IF EXISTS ".$prefixeTable."AStat_picture"; |
---|
2264 | $result=pwg_query($sql); |
---|
2265 | } |
---|
2266 | return($returned); |
---|
2267 | } |
---|
2268 | |
---|
2269 | |
---|
2270 | |
---|
2271 | |
---|
2272 | /* |
---|
2273 | generics functions |
---|
2274 | */ |
---|
2275 | |
---|
2276 | /* |
---|
2277 | this function make filter list and apply template |
---|
2278 | |
---|
2279 | $selected : category_id of selected item ("" if none) |
---|
2280 | */ |
---|
2281 | private function make_filter_list($selected="") |
---|
2282 | { |
---|
2283 | global $template; |
---|
2284 | |
---|
2285 | $template_datarows_values=array(); |
---|
2286 | $template_datarows_labels=array(); |
---|
2287 | $template_hiddenrows=array(); |
---|
2288 | |
---|
2289 | |
---|
2290 | $template_datarows_values[]=""; |
---|
2291 | $template_datarows_labels[]=l10n("AStat_nofilter"); |
---|
2292 | |
---|
2293 | $sql="SELECT id, name, global_rank FROM ".CATEGORIES_TABLE." order by global_rank"; |
---|
2294 | $result = pwg_query($sql); |
---|
2295 | if($result) |
---|
2296 | { |
---|
2297 | while ($row = pwg_db_fetch_assoc($result)) |
---|
2298 | { |
---|
2299 | $text=str_repeat(' ', substr_count($row['global_rank'], '.')); |
---|
2300 | $template_datarows_values[]=$row['id']; |
---|
2301 | $template_datarows_labels[]=$text.$row['name']; |
---|
2302 | } |
---|
2303 | } |
---|
2304 | |
---|
2305 | $query=explode('&', $_SERVER['QUERY_STRING']); |
---|
2306 | foreach($query as $key => $value) |
---|
2307 | { |
---|
2308 | $nfo=explode('=', $value); |
---|
2309 | $template_hiddenrows[]=array( |
---|
2310 | 'VALUE' => urldecode($nfo[1]), |
---|
2311 | 'NAME' => $nfo[0] |
---|
2312 | ); |
---|
2313 | } |
---|
2314 | |
---|
2315 | $template->assign('ASTAT_LINK', $_SERVER['SCRIPT_NAME']); |
---|
2316 | $template->assign('f_AStat_catfilter_list_values', $template_datarows_values); |
---|
2317 | $template->assign('f_AStat_catfilter_list_labels', $template_datarows_labels); |
---|
2318 | $template->assign('f_AStat_catfilter_selected', $selected); |
---|
2319 | $template->assign('f_AStat_parameters', $template_hiddenrows); |
---|
2320 | } //make_filter_list |
---|
2321 | |
---|
2322 | |
---|
2323 | /* |
---|
2324 | this function make SELECT "WHERE" clause for filter list |
---|
2325 | |
---|
2326 | $selected : category_id of selected item ("" if none) |
---|
2327 | */ |
---|
2328 | private function make_where_clause($catfilter) |
---|
2329 | { |
---|
2330 | $returned=array(); |
---|
2331 | $sql="SELECT id, ".CATEGORIES_TABLE.".global_rank |
---|
2332 | FROM ".CATEGORIES_TABLE.", |
---|
2333 | (SELECT global_rank FROM ".CATEGORIES_TABLE." WHERE id = '".$catfilter."') as tmp1 |
---|
2334 | WHERE ".CATEGORIES_TABLE.".global_rank LIKE CONCAT(tmp1.global_rank, '%') |
---|
2335 | ORDER BY ".CATEGORIES_TABLE.".global_rank"; |
---|
2336 | $result = pwg_query($sql); |
---|
2337 | |
---|
2338 | if($result) |
---|
2339 | { |
---|
2340 | while ($row = pwg_db_fetch_row($result)) |
---|
2341 | { |
---|
2342 | $returned[]=$row[0]; |
---|
2343 | } |
---|
2344 | } |
---|
2345 | |
---|
2346 | return(implode(',', $returned)); |
---|
2347 | } |
---|
2348 | |
---|
2349 | |
---|
2350 | /* |
---|
2351 | format text : <a href="$link">$value</a> |
---|
2352 | */ |
---|
2353 | private function format_link($value, $link) |
---|
2354 | { |
---|
2355 | return("<a href='$link'>$value</a>"); |
---|
2356 | } |
---|
2357 | |
---|
2358 | /* |
---|
2359 | return true if IP adress is given |
---|
2360 | */ |
---|
2361 | private function is_IP($ip) |
---|
2362 | { //basic test, maybe a pcre will be more appropriate... |
---|
2363 | $tmp=explode('.', $ip); |
---|
2364 | if(count($tmp)!=4) |
---|
2365 | { return (false); } |
---|
2366 | |
---|
2367 | for($i=0;$i<4;$i++) |
---|
2368 | { |
---|
2369 | if(!is_numeric($tmp[$i])) { return (false); } |
---|
2370 | } |
---|
2371 | return (true); |
---|
2372 | } |
---|
2373 | |
---|
2374 | /* |
---|
2375 | change filename extension |
---|
2376 | */ |
---|
2377 | private function change_file_ext($file, $newext) |
---|
2378 | { //filename can be <filename.truc.jpeg> for example |
---|
2379 | $tmp = explode('.', $file); |
---|
2380 | if(count($tmp)>1) { $tmp[count($tmp)-1] = $newext; } |
---|
2381 | return implode('.', $tmp); |
---|
2382 | } |
---|
2383 | |
---|
2384 | /* |
---|
2385 | format number $octets with unit |
---|
2386 | $format = "A" : auto |
---|
2387 | "O" : o |
---|
2388 | "K" : Ko |
---|
2389 | "M" : Mo |
---|
2390 | "G" : Go |
---|
2391 | $thsep = thousand separator |
---|
2392 | $prec = number of decimal |
---|
2393 | $unitevis = true/false > renvoi l'unité ou non dans le résultat |
---|
2394 | */ |
---|
2395 | private function formatoctet($octets, $format="A", $thsep=" ", $prec=2, $unitevis=true) |
---|
2396 | { |
---|
2397 | if($format=="A") |
---|
2398 | { |
---|
2399 | if($octets<1024) |
---|
2400 | { $format="O"; } |
---|
2401 | elseif($octets<1024000) |
---|
2402 | { $format="K"; } |
---|
2403 | elseif($octets<1024000000) |
---|
2404 | { $format="M"; } |
---|
2405 | else |
---|
2406 | { $format="G"; } |
---|
2407 | } |
---|
2408 | switch($format) |
---|
2409 | { |
---|
2410 | case "O": |
---|
2411 | $unite="o"; $div=1; |
---|
2412 | break; |
---|
2413 | case "K": |
---|
2414 | $unite="Ko"; $div=1024; |
---|
2415 | break; |
---|
2416 | case "M": |
---|
2417 | $unite="Mo"; $div=1024000; |
---|
2418 | break; |
---|
2419 | case "G": |
---|
2420 | $unite="Go"; $div=1024000000; |
---|
2421 | break; |
---|
2422 | } |
---|
2423 | |
---|
2424 | $retour=number_format($octets/$div, $prec, '.', $thsep); |
---|
2425 | if($unitevis) |
---|
2426 | { $retour.=" ".$unite; } |
---|
2427 | return($retour); |
---|
2428 | } |
---|
2429 | |
---|
2430 | private function make_IP_where_clause($list) |
---|
2431 | { |
---|
2432 | $returned=""; |
---|
2433 | |
---|
2434 | $tmp=explode(",", $list); |
---|
2435 | foreach($tmp as $key=>$val) |
---|
2436 | { |
---|
2437 | if($returned!="") { $returned.=" OR "; } |
---|
2438 | $returned.=" IP LIKE '".$val."' "; |
---|
2439 | } |
---|
2440 | if($returned!="") |
---|
2441 | { |
---|
2442 | $returned ="(".$returned.")"; |
---|
2443 | } |
---|
2444 | return($returned); |
---|
2445 | } |
---|
2446 | |
---|
2447 | |
---|
2448 | /* --------------------------------------------------------------------------- |
---|
2449 | * AJAX functions |
---|
2450 | * ------------------------------------------------------------------------- */ |
---|
2451 | protected function ajax_listip($filter, $exclude) |
---|
2452 | { |
---|
2453 | $sql="SELECT IP, COUNT(id) as NbEvents FROM ".HISTORY_TABLE; |
---|
2454 | |
---|
2455 | $where=array(); |
---|
2456 | if($filter!="") |
---|
2457 | { |
---|
2458 | $where[]=" IP LIKE '".$filter."' "; |
---|
2459 | } |
---|
2460 | if($exclude!="") |
---|
2461 | { |
---|
2462 | $where[]=" NOT ".$this->make_IP_where_clause($exclude); |
---|
2463 | } |
---|
2464 | if(count($where)>0) |
---|
2465 | { |
---|
2466 | $sql.=" WHERE ".implode(" AND ", $where); |
---|
2467 | } |
---|
2468 | $sql.=" GROUP BY IP ORDER BY NbEvents desc, IP asc LIMIT 0,100"; |
---|
2469 | |
---|
2470 | $list="<select multiple id='iipsellist'>"; |
---|
2471 | $result=pwg_query($sql); |
---|
2472 | if($result) |
---|
2473 | { |
---|
2474 | while($row=pwg_db_fetch_assoc($result)) |
---|
2475 | { |
---|
2476 | $list.="<option value='".$row['IP']."'>".$row['IP'].str_repeat(" ", 15-strlen($row['IP']))." (".$row['NbEvents'].")</option>"; |
---|
2477 | } |
---|
2478 | } |
---|
2479 | $list.="</select>"; |
---|
2480 | |
---|
2481 | return($list); |
---|
2482 | } |
---|
2483 | |
---|
2484 | |
---|
2485 | } // AStat_AI class |
---|
2486 | |
---|
2487 | |
---|
2488 | ?> |
---|