root > toolstats > index.php.bak

index.php.bak

text/x-php, 4549 bytes (load raw)
<?

#print_r($_SERVER);

$dir=dirname($_SERVER['SCRIPT_FILENAME']);
$path=dirname($_SERVER['PHP_SELF']);
$self=$_SERVER['PHP_SELF'];

$script= @$_REQUEST['s'];
$value= @$_REQUEST['v'];
$span= @$_REQUEST['t'];

if (get_magic_quotes_gpc()) {
    if ($script) $script= stripslashes($script);
    if ($value) $value= stripslashes($value);
    if ($span) $span= stripslashes($span);
}

$home= '/';
$header= NULL;
$footer= NULL;

#--------------------------------------

$graphdir= "$dir/graphs";
$graphpath= "$path/graphs";

$home= "/~daniel/";
$header= "header.php";
$footer= "footer.php";

$values= array(
    'runs' => 'Calls',
    'time' => 'Time',
    'ftime' => 'Time per Call',
    #'errors' => 'Errors',
    'ferrors' => 'Errors per Call',
);

$spans= array(
    '24h' => '24 hours',
    '7d' => '7 days',
    '100d' => '100 days',
);

#--------------------------------------
$scripts= array(
    'all' => 'All',
    'total' => 'Total',
);

#print "$dir";

$ff= glob("$dir/*.rrd");

#print_r($ff);

foreach ($ff as $f) {
  $n= preg_replace('/\..*$/', '', basename($f));
  if ($n=='total') continue;
  if ($n=='all') continue;
  
  $scripts[$n]= $n;
}

#--------------------------------------

function listAll() {
    global $scripts, $values, $spans, $home;
    global $graphpath, $self, $title;
    
    if ($home) print "\t\t\t<p><b>&lt;&lt; <a href='$home'>Home</a></b></p>\n";
   
    print "\t\t<p>\n";
    foreach ($scripts as $script => $title) {
        print " <a href='#$script'>".htmlspecialchars($title)."</a> ";
    }
    print "\t\t</p>\n";
    
    foreach ($scripts as $script => $title) {
        $img= "$graphpath/$script-24h-runs.png";
        $u= $self.'?s='.urlencode($script).'&amp;v=runs&amp;t=24h';
        print "\n\t<a href='$u' style='float:right'><img src='$img' border='0' width='300' height='137'/></a>\n";
        
        print "\n\t<h2 id='".htmlspecialchars($script)."'>".htmlspecialchars($title)."</h2>\n";
        
        print "\t\t<ul>\n";
        foreach ($values as $val => $label) {
            print "\t\t\t<li>";
            print "<b>".htmlspecialchars($label).": </b>";
            
            foreach ($spans as $span => $name) {
                $u= $self.'?s='.urlencode($script).'&amp;v='.urlencode($val).'&amp;t='.urlencode($span);
                print " <a href='$u'>".htmlspecialchars($name)."</a> ";
            }
            
            print "</li>\n";
        }
        print "\t\t</ul>\n";
    }
}

function showGraph($script, $val, $span) {
    global $scripts, $values, $spans, $home;
    global $graphpath, $self, $title;
    
    print "\t\t<ul style='float:left; margin:1ex; padding-left:1ex;'>\n";
    if ($home) print "\t\t\t<li><b><a href='$home'>Home</a></b></li>\n";
    print "\t\t\t<li><b><a href='$self'>Index</a></b></li>\n";
    foreach ($scripts as $s => $title) {
        $u= $self.'?s='.urlencode($s).'&amp;v='.urlencode($val).'&amp;t='.urlencode($span);
        print "\t\t\t<li><a href='$u'>".htmlspecialchars($title)."</a></li>\n";
    }
    print "\t\t</ul>\n";
        
    print "\t\t<ul>\n";
    print "\t\t\t<li>\n";
    foreach ($values as $v => $title) {
        $u= $self.'?s='.urlencode($script).'&amp;v='.urlencode($v).'&amp;t='.urlencode($span);
        print "\t\t\t<a href='$u'>".htmlspecialchars($title)."</a>\n";
    }
    print "\t\t\t</li>\n";
    print "\t\t\t<li>\n";
    foreach ($spans as $t => $title) {
        $u= $self.'?s='.urlencode($script).'&amp;v='.urlencode($val).'&amp;t='.urlencode($t);
        print "\t\t\t<a href='$u'>".htmlspecialchars($title)."</a>\n";
    }
    print "\t\t\t</li>\n";
    print "\t\t</ul>\n";
        
    $img= $graphpath.'/'.urlencode($script).'-'.urlencode($span).'-'.urlencode($val).'.png';
    print "\t\t<img src='$img'/>\n";
}

#--------------------------------------
if ($script && $value && $span) {
    $title= "{$values[$value]} - {$scripts[$script]}, last {$spans[$span]}";
}
else {
    $title= "Available Statistics";
}

?>
<html>
<head>
  <title><?= htmlspecialchars($title) ?></title>
  
  <style>
      ul    { list-style: none; text-indent:0; margin:1ex; padding:0; text-align:left; }
      ul li { list-style: none; text-indent:0; margin:0;   padding:0; text-align:left; }
  </style>
</head>
<body>
  <? if ($header) include($header) ?>
  
  <h1 id='top'><?= htmlspecialchars($title) ?></h1>
    <?
    if ($script && $value && $span) {
        showGraph($script, $value, $span);
    }
    else {
        listAll();
    }
    ?>
  
  <? if ($footer) include($footer) ?>
</body>    
</html>