forked from poppyred/1.6.x
/
miniadm.webstats.ByMember.ByCategory.php
executable file
·381 lines (300 loc) · 11.4 KB
/
miniadm.webstats.ByMember.ByCategory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
session_start();
ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string',"<p class=text-error>");
ini_set('error_append_string',"</p>");
if(!isset($_SESSION["uid"])){die();}
include_once(dirname(__FILE__)."/ressources/class.templates.inc");
include_once(dirname(__FILE__)."/ressources/class.users.menus.inc");
include_once(dirname(__FILE__)."/ressources/class.miniadm.inc");
include_once(dirname(__FILE__)."/ressources/class.mysql.postfix.builder.inc");
include_once(dirname(__FILE__)."/ressources/class.user.inc");
Privileges_members_ownstats();
if(isset($_GET["tabs"])){tabs();exit;}
if(isset($_GET["www-graĥs"])){www_graphs();exit;}
if(isset($_GET["graph1"])){graph1();exit;}
if(isset($_GET["graph2"])){graph2();exit;}
if(isset($_GET["graph3"])){graph3();exit;}
if(isset($_GET["graph4"])){graph4();exit;}
if(isset($_GET["www-table"])){www_table();exit;}
if(isset($_GET["www-top"])){www_top();exit;}
if(isset($_GET["www-top-table"])){www_top_table();exit;}
js();
function js(){
$page=CurrentPageName();
$tpl=new templates();
header("content-type: application/x-javascript");
$title="{$_GET["uid"]}::{$_GET["category"]}";
if($_GET["category"]==null){$title=$tpl->javascript_parse_text("{$_GET["uid"]}::{unkown}");}
$fsite=urlencode($_GET["category"]);
$_GET["uid"]=urlencode($_GET["uid"]);
$html="YahooWin3('800','$page?tabs=yes&category=$fsite&uid={$_GET["uid"]}','$title')";
echo $html;
}
function FormatNumber($number, $decimals = 0, $thousand_separator = ' ', $decimal_point = '.'){
$tmp1 = round((float) $number, $decimals);
while (($tmp2 = preg_replace('/(\d+)(\d\d\d)/', '\1 \2', $tmp1)) != $tmp1)
$tmp1 = $tmp2;
return strtr($tmp1, array(' ' => $thousand_separator, '.' => $decimal_point));
}
function tabs(){
$page=CurrentPageName();
$tpl=new templates();
$t=time();
$boot=new boostrap_form();
$title=$tpl->_ENGINE_parse_body("{member}:{$_GET["uid"]}, {category}:{$_GET["category"]}");
if($_GET["category"]==null){$title=$tpl->_ENGINE_parse_body("{member}:{$_GET["uid"]}, {category}:{unkown}");}
$_GET["uid"]=urlencode($_GET["uid"]);
$fsite=urlencode($_GET["category"]);
$array["{graphs}"]="$page?www-graĥs=yes&category=$fsite&uid={$_GET["uid"]}";
$array["{values}"]="$page?www-table=yes&category=$fsite&uid={$_GET["uid"]}";
$array["{top_websites}"]="$page?www-top=yes&category=$fsite&uid={$_GET["uid"]}";
$array["{top_websites} {values}"]="$page?www-top-table=yes&category=$fsite&uid={$_GET["uid"]}";
echo "<H3>$title</H3>". $boot->build_tab($array);
}
function www_graphs(){
$page=CurrentPageName();
$tpl=new templates();
$t=time();
$_GET["uid"]=urlencode($_GET["uid"]);
$fsite=urlencode($_GET["category"]);
$html="
<div id='$t-1' style='width:780px;height:450px'></div>
<div id='$t-2' style='width:780px;height:450px'></div>
<script>
AnimateDiv('$t-1');
AnimateDiv('$t-2');
Loadjs('$page?graph1=yes&category=$fsite&uid={$_GET["uid"]}&by={$_GET["by"]}&xtime={$_GET["xtime"]}&container=$t-1');
Loadjs('$page?graph2=yes&category=$fsite&uid={$_GET["uid"]}&by={$_GET["by"]}&xtime={$_GET["xtime"]}&container=$t-2');
</script>
";
echo $html;
}
function www_top(){
$page=CurrentPageName();
$tpl=new templates();
$t=time();
$_GET["uid"]=urlencode($_GET["uid"]);
$fsite=urlencode($_GET["category"]);
$html="
<div id='$t-1' style='width:780px;height:450px'></div>
<div id='$t-2' style='width:780px;height:450px'></div>
<script>
AnimateDiv('$t-1');
AnimateDiv('$t-2');
Loadjs('$page?graph3=yes&category=$fsite&uid={$_GET["uid"]}&by={$_GET["by"]}&xtime={$_GET["xtime"]}&container=$t-1');
Loadjs('$page?graph4=yes&category=$fsite&uid={$_GET["uid"]}&by={$_GET["by"]}&xtime={$_GET["xtime"]}&container=$t-2');
</script>
";
echo $html;
}
function graph1(){
$q=new mysql_squid_builder();
$tpl=new templates();
$tablename="www_".$q->uid_to_tablename($_GET["uid"]);
$sql="SELECT SUM(hits) as hits,DAY(zDate) as hour,category FROM `$tablename` GROUP BY
category,`hour` HAVING category='{$_GET["category"]}' ORDER BY `hour`";
if($_GET["category"]==null){
$sql="SELECT SUM(hits) as hits,DAY(zDate) as hour,category FROM `$tablename` GROUP BY
category,`hour` HAVING category IS NULL ORDER BY `hour`";
}
$results=$q->QUERY_SQL($sql);
if(!$q->ok){$tpl->javascript_senderror($q->mysql_error);}
while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
$size=$ligne["hits"];
$xdata[]=$ligne["hour"];
$ydata[]=$size;
}
$highcharts=new highcharts();
$highcharts->container=$_GET["container"];
$highcharts->xAxis=$xdata;
$highcharts->Title="{$_GET["category"]} {requests}/{day}";
$highcharts->yAxisTtitle="{hits}";
$highcharts->xAxisTtitle="{days}";
$highcharts->datas=array("{requests}"=>$ydata);
echo $highcharts->BuildChart();
}
function graph2(){
$q=new mysql_squid_builder();
$tpl=new templates();
$tablename="www_".$q->uid_to_tablename($_GET["uid"]);
$sql="SELECT SUM(size) as size,DAY(zDate) as hour,category FROM `$tablename` GROUP BY
category,`hour` HAVING category='{$_GET["category"]}' ORDER BY `hour`";
if($_GET["category"]==null){
$sql="SELECT SUM(size) as size,DAY(zDate) as hour,category FROM `$tablename` GROUP BY
category,`hour` HAVING category IS NULL ORDER BY `hour`";
}
$results=$q->QUERY_SQL($sql);
if(!$q->ok){$tpl->javascript_senderror($q->mysql_error);}
while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
$size=$ligne["size"];
$size=$size/1024;
$size=$size/1024;
$size=round($size,2);
$xdata[]=$ligne["hour"];
$ydata[]=$size;
}
$highcharts=new highcharts();
$highcharts->container=$_GET["container"];
$highcharts->xAxis=$xdata;
$highcharts->Title="{$_GET["category"]} {requests}/{size} (MB)";
$highcharts->yAxisTtitle="{size}";
$highcharts->xAxisTtitle="{days}";
$highcharts->datas=array("{requests}"=>$ydata);
echo $highcharts->BuildChart();
}
function www_table(){
$q=new mysql_squid_builder();
$tpl=new templates();
$boot=new boostrap_form();
$tablename="www_".$q->uid_to_tablename($_GET["uid"]);
$q=new mysql_squid_builder();
if(!$q->TABLE_EXISTS($tablename)){
echo "<p class=text-error>No table «$tablename» for {$_GET["uid"]}</p>";
return;
}
$sql="SELECT SUM(hits) as hits,SUM(size) as size,category,zDate FROM `$tablename` GROUP BY
category,zDate HAVING category='{$_GET["category"]}' ORDER BY zDate";
if($_GET["category"]==null){
$sql="SELECT SUM(hits) as hits,SUM(size) as size,category,zDate FROM `$tablename` GROUP BY
category,zDate HAVING category IS NULL ORDER BY zDate";
}
$results=$q->QUERY_SQL($sql);
$_GET["uid"]=urlencode($_GET["uid"]);
if(!$q->ok){echo "<p class=text-error>$q->mysql_error<br>$sql</p>";return;}
while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
$size=FormatBytes($ligne["size"]/1024);
$hits=FormatNumber($ligne["hits"]);
$category=urlencode($ligne["category"]);
$xtime=strtotime($ligne["zDate"]."00:00:00");
$hits=FormatNumber($ligne["hits"]);
$dateT=date("{l} {F} d",$xtime);
if($tpl->language=="fr"){$dateT=date("{l} d {F} ",$xtime);}
$dateT=$tpl->_ENGINE_parse_body($dateT);
//$jslink="Loadjs('miniadm.webstats.ByMember.website.php?familysite=$fsite&member-value={$_GET["member-value"]}&by={$_GET["by"]}')";
$link=$boot->trswitch($jslink);
$tr[]="
<tr id='$id'>
<td $link><i class='icon-tag'></i> $dateT</a></td>
<td $link><i class='icon-info-sign'></i> $size</td>
<td $link><i class='icon-info-sign'></i> $hits</td>
</tr>";
}
echo $tpl->_ENGINE_parse_body("
<table class='table table-bordered table-hover'>
<thead>
<tr>
<th>{date}</th>
<th>{size}</th>
<th>{hits}</th>
</tr>
</thead>
<tbody>
").@implode("", $tr)."</tbody></table>";
}
function www_top_table(){
$q=new mysql_squid_builder();
$tpl=new templates();
$boot=new boostrap_form();
$tablename="www_".$q->uid_to_tablename($_GET["uid"]);
$member=urlencode($_GET["uid"]);
$q=new mysql_squid_builder();
if(!$q->TABLE_EXISTS($tablename)){
echo "<p class=text-error>No table «$tablename» for {$_GET["uid"]}</p>";
return;
}
$sql="SELECT SUM(hits) as hits,SUM(size) as size,familysite FROM `$tablename` GROUP BY
category,familysite HAVING category='{$_GET["category"]}' ORDER BY size DESC,hits DESC LIMIT 0,100";
if($_GET["category"]==null){
$sql="SELECT SUM(hits) as hits,SUM(size) as size,familysite FROM `$tablename` GROUP BY
category,familysite HAVING category IS NULL ORDER BY size DESC,hits DESC LIMIT 0,100";
}
$results=$q->QUERY_SQL($sql);
$_GET["uid"]=urlencode($_GET["uid"]);
if(!$q->ok){echo "<p class=text-error>$q->mysql_error<br>$sql</p>";return;}
while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
$size=FormatBytes($ligne["size"]/1024);
$hits=FormatNumber($ligne["hits"]);
$familysite=$ligne["familysite"];
$fsite=urlencode($familysite);
$jslink="Loadjs('miniadm.webstats.ByMember.website.php?familysite=$fsite&member-value=$member&by=uid')";
$link=$boot->trswitch($jslink);
$tr[]="
<tr>
<td $link><i class='icon-globe'></i> $familysite</a></td>
<td $link><i class='icon-info-sign'></i> $size</td>
<td $link><i class='icon-info-sign'></i> $hits</td>
</tr>";
}
echo $tpl->_ENGINE_parse_body("
<table class='table table-bordered table-hover'>
<thead>
<tr>
<th>{websites}</th>
<th>{size}</th>
<th>{hits}</th>
</tr>
</thead>
<tbody>
").@implode("", $tr)."</tbody></table>";
}
function graph3(){
$q=new mysql_squid_builder();
$tpl=new templates();
$tablename="www_".$q->uid_to_tablename($_GET["uid"]);
$sql="SELECT SUM(size) as size,familysite,category FROM `$tablename` GROUP BY familysite,category
HAVING `category`='{$_GET["category"]}'
ORDER BY size DESC LIMIT 0,15";
if($_GET["category"]==null){
$sql="SELECT SUM(size) as size,familysite,category FROM `$tablename` GROUP BY familysite,category
HAVING `category` IS NULL
ORDER BY size DESC LIMIT 0,15";
}
$results=$q->QUERY_SQL($sql);
while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
$size=$ligne["size"];
$size=$size/1024;
$size=$size/1024;
$size=round($size,2);
$PieData[$ligne["familysite"]]=$size;
}
if(!$q->ok){
$tpl->javascript_senderror($q->mysql_error,$_GET["container"]);
}
$tpl=new templates();
$highcharts=new highcharts();
$highcharts->container=$_GET["container"];
$highcharts->PieDatas=$PieData;
$highcharts->ChartType="pie";
$highcharts->PiePlotTitle="{size} (MB)";
$highcharts->Title=$tpl->_ENGINE_parse_body("{$_GET["category"]}/{top_websites}/{size}");
echo $highcharts->BuildChart();
}
function graph4(){
$q=new mysql_squid_builder();
$tpl=new templates();
$tablename="www_".$q->uid_to_tablename($_GET["uid"]);
$sql="SELECT SUM(hits) as hits,familysite,category FROM `$tablename` GROUP BY familysite,category
HAVING `category`='{$_GET["category"]}'
ORDER BY hits DESC LIMIT 0,15";
if($_GET["category"]==null){
$sql="SELECT SUM(hits) as hits,familysite,category FROM `$tablename` GROUP BY familysite,category
HAVING `category` IS NULL
ORDER BY hits DESC LIMIT 0,15";
}
$results=$q->QUERY_SQL($sql);
while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
$size=$ligne["hits"];
$PieData[$ligne["familysite"]]=$size;
}
if(!$q->ok){
$tpl->javascript_senderror($q->mysql_error,$_GET["container"]);
}
$tpl=new templates();
$highcharts=new highcharts();
$highcharts->container=$_GET["container"];
$highcharts->PieDatas=$PieData;
$highcharts->ChartType="pie";
$highcharts->PiePlotTitle="{hits}";
$highcharts->Title=$tpl->_ENGINE_parse_body("{$_GET["category"]}/{top_websites}/{size}");
echo $highcharts->BuildChart();
}