Changeset 2493


Ignore:
Timestamp:
04/02/09 16:38:42 (5 years ago)
Author:
mlutfy
Message:

allow to filter 'daily stats' by domain

File:
1 edited

Legend:

Unmodified
Added
Removed
  • alternc-stats/trunk/bureau/admin/stats_show_per_month.php

    r2492 r2493  
    9191 
    9292// $month param is not used for now, only generate stats for current month 
    93 function quota_get_usage_details_month($cuid, $month = 0) { 
     93function quota_get_usage_details_month($cuid, $month = 0, $domain = '') { 
    9494  global $db; 
     95 
    9596  $usage_month = array(); 
    96    
    97   $db->query(" 
    98   SELECT s.size AS cnt, s.uid, s.domain, date_format( DAY , '%Y-%m-%d' ) AS `month`, m.login 
    99   FROM `stat_http` s, `membres` m 
    100   WHERE `day` <=  NOW() 
    101     AND `day` >= date_format( DATE_SUB( NOW( ) , INTERVAL 1 MONTH ) , '%Y-%m-%d' ) 
    102     AND m.uid = $cuid 
    103     AND m.uid = s.uid 
    104   ORDER BY month ASC, day ASC 
    105   "); 
     97  $domain = (checkfqdn($domain) == 0 ? $domain : ''); 
     98 
     99  $q = "SELECT s.size AS cnt, s.uid, s.domain, date_format( DAY , '%Y-%m-%d' ) AS `month`, m.login 
     100         FROM `stat_http` s, `membres` m 
     101        WHERE `day` <=  NOW() 
     102          AND `day` >= date_format( DATE_SUB( NOW( ) , INTERVAL 1 MONTH ) , '%Y-%m-%d' ) 
     103          AND m.uid = $cuid 
     104          AND m.uid = s.uid " . 
     105          ( $domain ? " AND s.domain = '$domain' " : '' ) . " 
     106        ORDER BY month ASC, day ASC"; 
     107 
     108  $db->query($q); 
    106109   
    107110  while ($db->next_record()) { 
     
    115118if ($_REQUEST['graph']) { 
    116119  $overquota = false; 
     120  $domain = $_REQUEST['graphdomain']; 
     121 
     122  if (checkfqdn($domain)) { 
     123    $domain = ''; 
     124  } 
    117125 
    118126  // c.f. http://pear.veggerby.dk/wiki/image_graph:getting_started_guide 
    119   require 'Image/Graph.php';      
     127  require 'Image/Graph.php'; 
    120128 
    121129  $Graph =& Image_Graph::factory('graph', array(750, 300));  
    122130 
    123131  if ($_REQUEST['details'] == 'byday') { 
    124     $usage = quota_get_usage_details_month($cuid, 1); 
     132    $usage = quota_get_usage_details_month($cuid, 1, $domain); 
    125133    $dataset_domains = array(); 
    126134 
     
    156164 
    157165    if (count($dataset_domains)) { 
    158       $colors = array(0 => 'green', 1 => 'red', 2 => 'blue', 3 => 'yellow', 4 => 'black'); 
     166      $colors = array(0 => 'green', 1 => 'red', 2 => 'blue', 3 => 'yellow', 4 => 'black', 5 => 'brown'); 
    159167      $color_counter = 0; 
    160168 
     
    163171        $Plotx->setTitle($domain); 
    164172        $Plotx->setLineColor($colors[$color_counter] . '@1.1'); 
    165         $color_counter = ($color_counter + 1) % 4; 
     173        $color_counter = ($color_counter + 1) % 6; 
    166174      } 
    167175    } 
     
    288296 
    289297// Show bandwidth usage for the past 30 days 
    290 print "<img src='stats_show_per_month.php?graph=1&details=byday' />"; 
     298print "<img src='stats_show_per_month.php?graph=1&details=byday&graphdomain={$_REQUEST['graphdomain']}' />"; 
     299print "<ul>"; 
     300 
     301$usage = quota_get_usage_details_month($cuid, 1, $domain); 
     302 
     303foreach ($usage as $key => $val) { 
     304  if ($key != 'login' && $key != 'bwtotal') { 
     305    $total = 0; 
     306    foreach ($val as $key2 => $val2) { 
     307      $total += $val2; 
     308    } 
     309 
     310    print '<li><a href="stats_show_per_month.php?graphdomain=' . $key . '">' . $key . '</a> (' . format_size($total) . ')</li>'; 
     311  } 
     312} 
     313 
     314print "</ul>"; 
    291315 
    292316?> 
Note: See TracChangeset for help on using the changeset viewer.