| 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 | */ |
|---|
| 30 | require_once("../class/config.php"); |
|---|
| 31 | |
|---|
| 32 | include("head.php"); |
|---|
| 33 | |
|---|
| 34 | // max 100 months, 12 by default |
|---|
| 35 | $count = ($_GET['count'] ? $_GET['count'] % 100: 12); |
|---|
| 36 | ?> |
|---|
| 37 | </head> |
|---|
| 38 | <body> |
|---|
| 39 | <h3><?php __("Bandwidth usage in the last $count months"); ?></h3> |
|---|
| 40 | |
|---|
| 41 | <?php |
|---|
| 42 | |
|---|
| 43 | ?> |
|---|
| 44 | <form method="GET"> |
|---|
| 45 | Months: <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'); |
|---|
| 58 | print "<table><tr class=\"$class\"><td>"._("User")."</td>"; |
|---|
| 59 | |
|---|
| 60 | // figure out YYYY-MM for the last N months |
|---|
| 61 | // XXX: bad, bad boy should be using PEAR Date |
|---|
| 62 | for ($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 |
|---|
| 78 | WHERE `day` < CONCAT( date_format( DATE_ADD( NOW( ) , INTERVAL 1 |
|---|
| 79 | MONTH ) , '%Y-%m' ) , '-01' ) |
|---|
| 80 | AND `day` >= CONCAT( date_format( DATE_SUB( NOW( ) , INTERVAL " . (int) ($count - 1) . |
|---|
| 81 | " MONTH ) , '%Y-%m' ) , '-01' ) |
|---|
| 82 | ORDER BY month ASC"); |
|---|
| 83 | |
|---|
| 84 | $months = array(); |
|---|
| 85 | while ($db->next_record()) { |
|---|
| 86 | $months[] = $db->f('month'); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | foreach ($months as $m) { |
|---|
| 90 | print "<td>$m</td>"; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | if (! ($user_list = $admin->get_list())) { |
|---|
| 94 | $error = $err->errstr(); |
|---|
| 95 | } |
|---|
| 96 | $u = array(); |
|---|
| 97 | foreach ($user_list as $user) { |
|---|
| 98 | $u[$user['uid']] = $user['login']; |
|---|
| 99 | } |
|---|
| 100 | $u[0] = 'inconnu'; |
|---|
| 101 | |
|---|
| 102 | // the stats in the last $count months for all accounts |
|---|
| 103 | $db->query(" |
|---|
| 104 | SELECT SUM( size ) AS cnt, uid, date_format( |
|---|
| 105 | DAY , '%Y-%m' ) AS `month` |
|---|
| 106 | FROM `stat_http` |
|---|
| 107 | WHERE `day` < CONCAT( date_format( DATE_ADD( NOW( ) , INTERVAL 1 |
|---|
| 108 | MONTH ) , '%Y-%m' ) , '-01' ) |
|---|
| 109 | AND `day` >= CONCAT( date_format( DATE_SUB( NOW( ) , INTERVAL " . (int) ($count - 1) . |
|---|
| 110 | " MONTH ) , '%Y-%m' ) , '-01' ) |
|---|
| 111 | GROUP BY `uid` , `month` |
|---|
| 112 | ORDER BY `uid` |
|---|
| 113 | "); |
|---|
| 114 | |
|---|
| 115 | while ($db->next_record()) { |
|---|
| 116 | if (($user = $db->f("uid")) !== $current_user) { |
|---|
| 117 | # deal w/ $entries... |
|---|
| 118 | if (!is_null($current_user)) { // not the first time we enter this block |
|---|
| 119 | $class = ($class== 'lst1' ? 'lst2' : 'lst1'); |
|---|
| 120 | print "<tr class=\"$class\"><td><acronym title=\"$u[$current_user]\">" . $current_user . "</acronym></td>\n"; |
|---|
| 121 | foreach ($months as $m) { |
|---|
| 122 | print "<td>" . m_quota::display_val('bw_web', $entries[$m]) . "</td>\n"; |
|---|
| 123 | $monthly_size[$m] += $entries[$m]; |
|---|
| 124 | } |
|---|
| 125 | print "</tr>\n"; |
|---|
| 126 | } |
|---|
| 127 | $current_user = $user; |
|---|
| 128 | $entries = array(); |
|---|
| 129 | } |
|---|
| 130 | $entries[$db->f("month")] = $db->f("cnt"); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | print "</tr>\n"; |
|---|
| 134 | |
|---|
| 135 | print "<tr><td>Total</td>"; |
|---|
| 136 | |
|---|
| 137 | foreach ($monthly_size as $m => $size) { |
|---|
| 138 | print "<td>".m_quota::display_val('bw_web', $size)."</td>"; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | print "</table>"; |
|---|
| 142 | |
|---|
| 143 | ?> |
|---|
| 144 | </body> |
|---|
| 145 | </html> |
|---|