Source for file statgraph.php
Documentation is available at statgraph.php
* Long description for file:
* Generate a grphic given a query.
* This script generates a webpage with no text, and graphics must be generated before text.
* @author Core team, Originally T.Dagonnier
* @copyright 2008 FreeNAC
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License Version 3
* @version SVN: $Id: find.php,v 1.1 2008/02/22 13:04:57 root Exp root $
* @link http://freenac.net
* To test call from a browser with parameters like this:
* http://SERVERNAME/nac/statgraph.php?stattype=os&order=DESC&graphtype=bar
## Initialise (standard header for all modules)
require_once('webfuncs.inc');
$logger->setDebugLevel(0); // set to 0 to see graphs
## Loggin in? User identified?
include 'session.inc.php';
#$logger->debug('Start, uid=' .$_SESSION['uid'], 3);
## end of standardc header ------
if ($_SESSION['nac_rights']<
1) {
else if ($_SESSION['nac_rights']==
1) {
else if ($_SESSION['nac_rights']==
2) {
//$action_menu=array('Print','Edit'); // 'buttons' in action column
else if ($_SESSION['nac_rights']==
99) {
//$action_menu=array('Print', 'Edit', 'Delete'); // 'buttons' in action column
return sprintf("%.0f",$aVal); // Convert to string
// ------------ main () ----------------
$report=
new WebCommon(false); // new webpage, no header
$report->logger->setDebugLevel(0); // set to 0 to see graphs
$conn=
$report->getConnection(); // make sure we have a DB connection
// Clean inputs from the web, (security)
$_POST=
array_map('validate_webinput',$_POST);
$_REQUEST=
array_map('validate_webinput',$_REQUEST);
$_COOKIE=
array_map('validate_webinput',$_COOKIE);
if ( isset
($_GET["stattype"]) )
$stattype =
$_GET["stattype"];
if ( isset
($_GET["graphtype"]) )
$graphtype =
$_GET["graphtype"];
if ( isset
($_GET["order"]) )
$report->debug("stattype=$stattype, graphtype=$graphtype, order=$order", 2);
include_once('graphdefs.inc'); // generic queries
$incs=
array($conf->web_jpgraph.
'/jpgraph.php', $conf->web_jpgraph.
'/jpgraph_'.
$graphtype.
'.php');
$logger->debug("include $f", 3);
// build and run the query
$q =
$sel[$stattype]['graph'] ;
$q =
$sel[$stattype]['graph'] .
" ORDER BY count(*) $order";
while (($row =
$res->fetch_assoc()) !==
NULL) {
$data_names[] =
$row["datax"]; //." (%.0f%%)";
if ($graphtype ==
'bar' && isset
($data) ) {
$graph =
new Graph(800,400);
$bar1 =
new BarPlot($data);
$graph->SetScale("textlin");
$graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,8);
$graph->yaxis->SetFont(FF_VERDANA,FS_NORMAL,8);
$graph->xaxis->SetTickLabels($data_names);
$graph->xaxis->SetLabelAngle(45);
$bar1->SetFillGradient("navy","lightsteelblue",GRAD_MIDVER);
$bar1->value->SetFont(FF_VERDANA,FS_NORMAL,8);
$bar1->value->SetFormatCallback("cbFmtPercentage");
// Add the plot to the graph
else if ($graphtype ==
'pie' && isset
($data) ) {
$graph =
new Graph(500,500);
$graph =
new PieGraph(800,400);//,$filename,60);
// Set A title for the plot
// $graph->title->Set($PIE_TITLE);
// $graph->title->SetFont(FF_FONT1,FS_BOLD);
$p1 =
new PiePlot($data);
$p1->SetCenter(0.35,0.5);
// $p1->SetLegends($data_names);
// $p1->SetLabelType(PIE_VALUE_PER);
$p1->SetLabels($data_names);
$p1->value->SetFont(FF_VERDANA,FS_NORMAL,8);
if ( (($graphtype ==
'pie') ||
($graphtype ==
'bar') )
Documentation generated on Mon, 17 Nov 2008 01:10:50 +0100 by phpDocumentor 1.4.0