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