<html>
<head>
<link href="mytsm.css" rel="styleSheet" type="text/css">
<title> Occupancy Report
</title>
</head>
<body>
<?
if ($_POST['Aggregate'] == "Submit") {
include_once 'libraries/functions.php';
Connect();
$startdate=($_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']);
$enddate=($_POST['yearend'].'-'.$_POST['monthend'].'-'.$_POST['dayend']);
$sql = 'SELECT to_days("'.$enddate.'") - to_days("'.$startdate.'") AS range';
$output=Query($sql);
$range = mysql_fetch_array($output);
if ($range["range"] < 0) {
echo ('Date range is not valid');
exit();
}
echo '<table bgcolor="#353268" border = 0 cellpadding = 5>';
echo '<tr bgcolor="#575582"><td><font color="#FFFFFF">Date</font></td>';
echo '<td><font color="#FFFFFF"> Node </td>';
echo '<td><font color="#FFFFFF"> Total in GB stored </td><td><font color="#FFFFFF"> Number of files </td>';
if ($_POST['Type']) {
$sql = 'SELECT `Date` , `Node` , `Mb_Stored`, `Files` FROM Occupancy WHERE ( `Date` >= "'.$startdate.'" ) AND ( `Date` <= "'.$enddate.'")';
}
else
{
$sql = 'SELECT `Date` , `Node` , SUM(`Mb_Stored`) AS Mb_Stored, SUM(`Files`) AS Files FROM Occupancy WHERE ( `Date` >= "'.$startdate.'" ) AND ( `Date` <= "'.$enddate.'")';
}
if ($_POST['node'][0]) {
$element = count($_POST['node']);
$sql=$sql.' AND (';
for ($a = 0; $a < $element; $a++)
{
if ($a == 0) { $sql = $sql.' `Node` = "'.$_POST['node'][$a].'"' ; }
else { $sql = $sql.' OR `Node` = "'.$_POST['node'][$a].'"' ; }
}
$sql=$sql.')';
}
if ($_POST['Type']) {
$sql = $sql.'AND `Type` = "'.$_POST['Type'].'"' ;
}
if ($_POST['Order']) {
$sql = $sql.'ORDER BY '.$_POST['Order'].' DESC ' ;
}
if (!$_POST['Type']) {
$sql = $sql.'GROUP BY Date,Node' ;
}
if ($_POST['nrow']) {
$sql = $sql.'LIMIT 0 , '.$_POST['nrow'] ;
}
else $_POST['nrow']=50;
$sel=Query($sql);
$i=0;
while ($row = mysql_fetch_array($sel))
{
if ($i % 2) {
echo '<tr bgcolor="#f0f0e0"><td>'; }
else {
echo '<tr bgcolor="#e0e0f0"><td>'; }
echo ($row["Date"]).'</td><td>';
echo ($row["Node"]).'</td><td>';
echo round(($row["Mb_Stored"]/1024),2).'</td><td>';
echo ($row["Files"]).'</td>';
$gdate[$i]=substr($row["Date"],-2);
$gnode[$i]=substr($row["Node"],0,8);
$gmb[$i]=round(($row["Mb_Stored"]/1024),2);
$gfile[$i]=$row["Files"];
$i++;
}
echo '</table><p>';
if ($_POST['graph'])
{
// graphing related includes
if ($_POST['graph']=='line')
{
require_once('libraries/jpgraph.php');
require_once('libraries/jpgraph_line.php');
$title='Occupancy/Files Stored';
$graph_name = 'images/occupancy.png';
$graph = new graph(800, 500, $graph_name, 0, 0);
$graph->img->SetMargin(80, 50, 50, 80);
$graph->SetScale('textlin');
$graph->SetMarginColor('white');
$graph->SetShadow();
$graph->title->Set($title);
$graph->yaxis->SetLabelAngle(90);
$graph->yaxis->title->Set("GB Stored",CENTER);
$graph->SetY2Scale("lin");
$graph->y2axis->SetLabelAngle(90);
$graph->y2axis->title->Set("Files Stored",CENTER);
$line1=new LinePlot($gmb);
$line1->SetColor("blue");
$line1->SetLegend('GB Stored');
$line2=new LinePlot($gfile);
$line2->SetColor("green");
$line2->SetLegend('Files Stored');
if (($range["range"] < 14) and ((count ($gnode)) < 30)) {
$line1->mark->SetType(MARK_FILLEDCIRCLE);
$line1->mark->SetFillColor("navy");
$line1->mark->SetWidth(4);
$line1->mark->Show();
$line1->value ->Show();
$line2->mark->SetType(MARK_FILLEDCIRCLE);
$line2->mark->SetFillColor("darkgreen");
$line2->mark->SetWidth(4);
$line2->mark->Show();
$line2->value ->Show();
}
$graph-> Add($line1);
$graph-> AddY2($line2);
$rng=2;
if ($_POST['node'][0]) $graph->xaxis->SetTickLabels($gdate);
else {
$graph->xaxis->SetTickLabels($gnode);
$rng=1;
$graph->xaxis->SetLabelAngle(90);
}
$graph->xaxis->SetTextLabelInterval($rng);
$graph->xaxis->HideTicks(true,true);
$graph->legend->SetLayout(LEGEND_HOR);
$graph ->legend->Pos(0.15,0.10,"right","bottom");
$graph->Stroke($graph_name);
print "<img src='{$graph_name}'>\n";
}
else if ($_POST['graph']=='bar')
{
require_once('libraries/jpgraph.php');
require_once('libraries/jpgraph_bar.php');
$title='Occupancy/Files Stored';
$graph_name = 'images/occupancy.png';
$graph = new graph(800, 500, $graph_name, 0, 0);
$graph->img->SetMargin(80, 50, 50, 80);
$graph->SetScale('textlin');
$graph->SetMarginColor('white');
$graph->SetShadow();
$graph->title->Set($title);
$graph->yaxis->SetLabelAngle(90);
$graph->yaxis->title->Set("GB Stored",CENTER);
$bar = new BarPlot($gmb);
$bar->SetFillGradient("navy","lightsteelblue",GRAD_LEFT_REFLECTION);
$bar->SetLegend('MB Backup');
$graph->Add( $bar);
$rng=2;
if ($_POST['node'][0]) $graph->xaxis->SetTickLabels($gdate);
else {
$graph->xaxis->SetTickLabels($gnode);
$rng=1;
$graph->xaxis->SetLabelAngle(90);
}
$graph->xaxis->SetTextLabelInterval($rng);
$graph->xaxis->HideTicks(true,true);
$graph->legend->SetLayout(LEGEND_HOR);
$graph ->legend->Pos(0.15,0.10,"right","bottom");
$graph->Stroke($graph_name);
print "<img src='{$graph_name}'>\n";
}
else if ($_POST['graph']=='pie3d')
{
require_once('libraries/jpgraph.php');
require_once('libraries/jpgraph_pie.php');
require_once('libraries/jpgraph_pie3d.php');
$title='Occupancy Distribution';
$graph_name = 'images/occupancy_distr.png';
$graph = new PieGraph(800, 500);
$graph->SetShadow();
$graph->title-> Set($title);
$p1 = new PiePlot3D($gmb);
$p1->SetSize(0.5);
$p1->SetCenter(0.41);
$p1->SetLegends($gnode);
$graph->Add($p1);
$graph->Stroke($graph_name);
print "<img src='{$graph_name}'>\n";
}
else if ($_POST['graph']=='pie')
{
require_once('libraries/jpgraph.php');
require_once('libraries/jpgraph_pie.php');
$title='Occupancy Distribution';
$graph_name = 'images/occupancy_distr.png';
$graph = new PieGraph(800, 500);
$graph->SetShadow();
$graph->title-> Set($title);
$p1 = new PiePlot($gmb);
$p1->SetLegends($gnode);
$graph->Add($p1);
$graph->Stroke($graph_name);
print "<img src='{$graph_name}'>\n";
}
}
exit();
}
if ($_POST['Elabora'] == "Submit") {
include_once 'libraries/functions.php';
Connect();
echo "Checkpoint 1 just after the connect <br>";
$startdate=($_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']);
$enddate=($_POST['yearend'].'-'.$_POST['monthend'].'-'.$_POST['dayend']);
$sql = 'SELECT to_days("'.$enddate.'") - to_days("'.$startdate.'") AS range';
$output=Query($sql);
$range = mysql_fetch_array($output);
if ($range[" range"] < 0) {
echo ('Date range is not valid');
exit();
}
$date = $startdate;
echo "Checkpoint 2 after the check of the date <br>";
echo '<table bgcolor="#353268" border = 0 cellpadding = 5>';
echo '<tr bgcolor="#575582"><td><font color="#FFFFFF">Date</font></td>';
echo '<td><font color="#FFFFFF"> Total in TB Stored </td><td><font color="#FFFFFF"> Total in GB moved</td>';
for ($i = 0; $i <= $range["range"]; $i++) {
$sql1 = 'SELECT SUM( `Mb_Stored` ) AS Total FROM `Occupancy` WHERE `Date` = "'.$date.'"';
if ($_POST['Type']) {
$sql1 = $sql1.'AND `Type` = "'.$_POST['Type'].'"' ;
}
echo "checkpoint 3 this is the SQL i will run : $sql1 <br>";
$sel1=Query($sql1);
$row1 = mysql_fetch_array($sel1);
$sql2 = 'SELECT SUM( `KB_Total` ) AS Total2 FROM `Sessions` WHERE `Date` = "'.$date.'"';
echo "checkpoint 4 this is the second SQL i will run : $sql2 <br>";
$sel2=Query($sql2);
$row2 = mysql_fetch_array($sel2);
if ($i % 2) {
echo '<tr bgcolor="#f0f0e0"><td>'; }
else {
echo '<tr bgcolor="#e0e0f0"><td>'; }
echo $date.'</td><td>';
echo round(($row1["Total"]/1024/1024),2).'</td><td>';
echo round(($row2["Total2"]/1024/1024),2).'</td>';
$gdate[$i]=substr($date,-2);
$gback[$i]=round(($row1["Total"]/1024/1024),2);
$garch[$i]=round(($row2["Total2"]/1024/1024),2);
$sqlb = 'SELECT ("'.$date.'") + INTERVAL 1 DAY AS Newdate ';
$selb=Query($sqlb);
$rowb = mysql_fetch_array($selb);
$date = $rowb["Newdate"];
}
echo '</table><p>';
echo "checkpoint 5 end of table";
if (($range["range"] == 0) and ($_POST['graph']=='line'))
{
echo '<b>No Line Graph possible for this query, you need at least 2 points to draw a line</b>';
echo '</body>';
echo '</html>';
exit ();
}
if ($_POST['graph'])
{
// graphing related includes
require_once('libraries/jpgraph.php');
require_once('libraries/jpgraph_line.php');
$title='Occupancy/Traffic activity';
$graph_name = 'images/occupancy.png';
$graph = new graph(800, 500, $graph_name, 0, 0);
$graph->img->SetMargin(80, 50, 50, 80);
$graph->SetScale('textlin');
$graph->SetMarginColor('white');
$graph->SetShadow();
$graph->title->Set($title);
$graph->yaxis->SetLabelAngle(90);
$graph->yaxis->title->Set("TB Stored",CENTER);
$graph->SetY2Scale("lin");
$graph->y2axis->SetLabelAngle(90);
$graph->y2axis->title->Set("GB Moved",CENTER);
$line1=new LinePlot($gback);
$line1->SetColor("blue");
$line1->SetLegend('TB Stored');
$line2=new LinePlot($garch);
$line2->SetColor("green");
$line2->SetLegend('GB Moved');
if ($range["range"] < 32) {
$line1->mark->SetType(MARK_FILLEDCIRCLE);
$line1->mark->SetFillColor("navy");
$line1->mark->SetWidth(4);
$line1->mark->Show();
$line1->value ->Show();
$line2->mark->SetType(MARK_FILLEDCIRCLE);
$line2->mark->SetFillColor("darkgreen");
$line2->mark->SetWidth(4);
$line2->mark->Show();
$line2->value ->Show();
}
$graph-> Add($line1);
$graph-> AddY2($line2);
$rng=2;
$graph->xaxis->SetTextLabelInterval($rng);
$graph->xaxis->HideTicks(true,true);
$graph->xaxis->SetTickLabels($gdate);
$graph->legend->SetLayout(LEGEND_HOR);
$graph ->legend->Pos( 0.01,0.98,"left","bottom");
$graph->Stroke($graph_name);
print "<img src='{$graph_name}'>\n";
}
echo "checkpoint 6 end of graph";
exit ();
}
include_once 'libraries/functions.php';
Connect();
echo '<center><font size=1>';
echo 'First Record in the DB about Occupancy ';
$sql = 'SELECT MIN(`Date`) AS start FROM Occupancy';
$output=Query($sql);
$startdate = mysql_fetch_array($output);
echo $startdate["start"].'<br>';
echo 'Last Record in the DB about Occupancy ';
$sql = 'SELECT MAX(`Date`) AS end FROM Occupancy';
$output=Query($sql);
$enddate = mysql_fetch_array($output);
echo $enddate["end"].'</center></font><hr><p>';
?>
<form method="post">
<table bgcolor="#353268" cellspacing="0" cellpadding="0" border=1>
<tr bgcolor="#575582"><td>
<h2><font color="#FFFFFF"> Show storage used in TSM server and Traffic </font></h2>
</td>
<td bgcolor="#d0d0ff"><center>Online <a href=help.php#occupancy>Help </a></center></td>
</tr>
<tr bgcolor="#e0e0f0"><td>
Start Date </td>
<td>
<?
listatoday(day,month,year);
?>
</td>
<tr bgcolor="#e0e0f0"><td>
End Date </td>
<td>
<?
listatoday(dayend,monthend,yearend);
?>
</td>
<tr bgcolor="#e0e0f0">
<td>
Type of data (select none for sum of both)
</td>
<td>
<input type="radio" name="Type" value="Arch"> Total space in archive files <br>
<input type="radio" name="Type" value="Bkup"> Total space in back up files <br>
</td>
</tr>
<tr bgcolor="#e0e0f0"><td>
Graph type:
</td><td>
<INPUT TYPE=radio NAME="graph" VALUE="line" > Line<BR>
</td>
</table>
<INPUT TYPE=SUBMIT name="Elabora" value="Submit">
</FORM>
<p>
<form method="post">
<table bgcolor="#353268" cellspacing="0" cellpadding="0" border=1>
<tr bgcolor="#575582"><td>
<h2><font color="#FFFFFF"> View Nodes Occupancy </font></h2>
</td>
<td bgcolor="#d0d0ff"><center>Online <a href=help.php#occupancy>Help </a></center></td>
</tr>
<tr bgcolor="#f0e0d0"><td>
Start Date </td>
<td>
<?
listatoday(day,month,year);
?>
</td>
<tr bgcolor="#f0e0d0"><td>
End Date </td>
<td>
<?
listatoday(dayend,monthend,yearend);
?>
</td>
<tr bgcolor="#f0e0d0">
<td>
Show only Nodes (you can select a custom number)
</td>
<td>
<?
Lista2();
?>
</td>
<tr bgcolor="#f0e0d0">
<td>
Show only first XXX results
</td>
<td>
<input name="nrow" type=text size=3 maxlength=3 value=''>
</td>
</tr>
<tr bgcolor="#f0e0d0">
<td>
Type of data (select none for sum of both)
</td>
<td>
<input type="radio" name="Type" value="Arch"> Total space in archive files <br>
<input type="radio" name="Type" value="Bkup"> Total space in back up files <br>
</td>
</tr>
<tr bgcolor="#f0e0d0">
<td>
Order By
</td>
<td>
<input type="radio" name="Order" value="Mb_Stored"> Mb Stored <br>
<input type="radio" name="Order" value="Files"> Number of files <br>
</td>
</tr>
<tr bgcolor="#f0e0d0"><td>
Graph type:
</td><td>
<INPUT TYPE=radio NAME="graph" VALUE="line" >Show Space and Files in a Line Graph <BR>
<INPUT TYPE=radio NAME="graph" VALUE="bar" >Show Space in a Bar Graph <BR>
<INPUT TYPE=radio NAME="graph" VALUE="pie" >Show Occupancy distribution in a Pie Graph<BR>
<INPUT TYPE=radio NAME="graph" VALUE="pie3d" >Show Occupancy distribution in a Pie 3D Graph<BR>
</td>
</tr>
</table>
<INPUT TYPE=SUBMIT name="Aggregate" value="Submit">
</FORM>
</body>
</html>