source: trunk/bureau/admin/stats_show_per_month.php @ 1416

Revision 1416, 4.0 KB checked in by darcs, 8 years ago (diff)

alternc-stats: changeset afficher le bon user

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2/*
3 $Id$
4 ----------------------------------------------------------------------
5 AlternC - Web Hosting System
6 Copyright (C) 2002 by the AlternC Development Team.
7 http://alternc.org/
8 ----------------------------------------------------------------------
9 Based on:
10 Valentin Lacambre's web hosting softwares: http://altern.org/
11 ----------------------------------------------------------------------
12 LICENSE
13
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License (GPL)
16 as published by the Free Software Foundation; either version 2
17 of the License, or (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 GNU General Public License for more details.
23
24 To read the license please visit http://www.gnu.org/copyleft/gpl.html
25 ----------------------------------------------------------------------
26 Original Author of file:
27 Purpose of file:
28 ----------------------------------------------------------------------
29*/
30require_once("../class/config.php");
31
32include("head.php");
33
34// max 100 months, 12 by default
35$count = ($_GET['count'] ? $_GET['count'] % 100: 12);
36?>
37<style>
38.right { text-align: right; }
39</style>
40</head>
41<body>
42<h3><?php __("Bandwidth usage in the last $count months"); ?></h3>
43
44<form method="GET">
45Months: <input type="text" size="3" name="count" value="<?=$count?>">
46<input type="submit" value="<?=_("Go")?>">
47</form>
48<?php
49
50/*
51 * find all the entries for a user
52 */
53$current_user = null;
54
55$months = array();
56
57$class = ($class== 'lst1' ? 'lst2' : 'lst1');
58print "<table><tr class=\"$class\"><td class=\"right\">"._("User")."</td>";
59
60// figure out YYYY-MM for the last N months
61// XXX: bad, bad boy should be using PEAR Date
62for ($i = ($count - 1); $i >= 0; $i--) {
63  if ((date('m') - $i) < 1) { // we're switching a year (or more?)
64    $y = round(date('Y') - ($i / 12));
65    $m = date('m') - ($i % 12);
66    while ($m < 0) {
67      $m+=12;
68    }
69    if ($m == 0) $m = 12;
70    $m = $y .'-'.$m;
71  } else {
72    $m = date('Y') .'-' . (sprintf("%02d", date('m') - $i));
73  }
74  $months[] = $m;
75}
76
77$db->query("SELECT DISTINCT date_format(day, '%Y-%m') AS `month` FROM stat_http
78WHERE `day` < CONCAT( date_format( DATE_ADD( NOW( ) , INTERVAL 1
79MONTH ) , '%Y-%m' ) , '-01' )
80AND `day` >= CONCAT( date_format( DATE_SUB( NOW( ) , INTERVAL " . (int) ($count - 1) .
81" MONTH ) , '%Y-%m' ) , '-01' )
82ORDER BY month ASC");
83
84$months = array();
85while ($db->next_record()) {
86  $months[] = $db->f('month');
87}
88
89foreach ($months as $m) {
90  print "<td>$m</td>";
91}
92
93// the stats in the last $count months for all accounts
94$db->query("
95SELECT SUM( s.size ) AS cnt, s.uid, date_format(
96DAY , '%Y-%m' ) AS `month`, m.login
97FROM `stat_http` s, membres m
98WHERE `day` < CONCAT( date_format( DATE_ADD( NOW( ) , INTERVAL 1
99MONTH ) , '%Y-%m' ) , '-01' )
100AND `day` >= CONCAT( date_format( DATE_SUB( NOW( ) , INTERVAL " . (int) ($count - 1) .
101" MONTH ) , '%Y-%m' ) , '-01' )
102AND m.uid = s.uid
103GROUP BY `uid` , `month`
104ORDER BY `login`
105");
106
107while ($db->next_record()) {
108  if (($user = $db->f("uid")) !== $current_user) {
109    # deal w/ $entries...
110    if (!is_null($current_user)) { // not the first time we enter this block
111      $class = ($class== 'lst1' ? 'lst2' : 'lst1');
112      print "<tr class=\"$class\"><td class=\"right\"><acronym title=\"$current_user\">".$login."</acronym></td>\n";
113      foreach ($months as $m) {
114        print "<td>" . m_quota::display_val('bw_web', $entries[$m]) . "</td>\n";
115        $monthly_size[$m] += $entries[$m];
116      }
117      print "</tr>\n";
118    }
119    $current_user = $user;
120    $login = $db->f('login');
121    $entries = array();
122  }
123  $entries[$db->f("month")] = $db->f("cnt");
124}
125
126print "</tr>\n";
127
128print "<tr><td class=\"right\">"._("Total")."</td>";
129
130foreach ($monthly_size as $m => $size) {
131  print "<td>".m_quota::display_val('bw_web', $size)."</td>";
132}
133
134print "</table>";
135
136?>
137</body>
138</html>
Note: See TracBrowser for help on using the repository browser.