<html>
<head>
<link href="mytsm.css" rel="styleSheet" type="text/css">
<title> Tape Report
</title>
</head>
<body>
<?
function dateadd($datestr, $num, $unit) {
$units = array("Y","m","d","H","i","s");
$unix = strtotime($datestr);
while(list(,$u) = each($units)) $$u = date($u, $unix);
$$unit += $num;
return mktime($H, $i, $s, $m, $d, $Y);
}
if ($_POST['Reclamation'] == "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);
$diff = $range["range"];
if ($diff < 0) {
echo ('Date range is not valid');
exit();
}
$sql = 'SELECT SUM( UNIX_TIMESTAMP(`End`) - UNIX_TIMESTAMP(`Start`)) AS Seconds FROM Reclamation WHERE ( `Start` >= "'.$startdate.' 00:00:00" ) AND ( `End` <= "'.$enddate.' 23:59:59") GROUP BY (TO_DAYS( `Start` )) ';
$range=Query($sql);
$counter=0;
while ($row = mysql_fetch_array($range))
{
$reclamation[$counter]=$row['Seconds'];
$counter++;
}
$sql = 'SELECT SUM( UNIX_TIMESTAMP(`End`) - UNIX_TIMESTAMP(`Start`)) AS Seconds FROM Tape WHERE ( `Start` >= "'.$startdate.' 00:00:00" ) AND ( `End` <= "'.$enddate.' 23:59:59") GROUP BY (TO_DAYS( `Start` )) ';
$tape=Query($sql);
$counter=0;
while ($row = mysql_fetch_array($tape))
{
$tapes[$counter]=$row['Seconds'];
$counter++;
}
echo '<table bgcolor="#353268" border = 0 cellpadding=5>';
echo '<tr bgcolor="#575582">';
echo ' <td><font color="#FFFFFF"> Date</td>';
echo '<td><font color="#FFFFFF"> Total time spent in reclamation (hour) </td>';
echo '<td><font color="#FFFFFF"> Summed time spent in all tape usage (hour) </td>';
echo '<td><font color="#FFFFFF"> % of reclamation over total usage </td>';
for ($count=0; $count <= $diff; $count++)
{
if ($count % 2) {
echo '<tr bgcolor="#f0f0e0"><td>'; }
else {
echo '<tr bgcolor="#e0e0f0"><td>'; }
echo date("Y-m-d", dateadd($startdate, $count, "d")).'</td><td>';
$a=round ($reclamation[$count]/1800,3);
$b= round ($tapes[$count]/3600,3);
echo $a.'</td><td>';
echo $b.'</td><td>';
echo round ((($a/$b)*100),0).'</td>';
}
echo '</table>';
exit ();
}
if ($_POST['Elabora'] == "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();
}
$date = $startdate;
echo '<table bgcolor="#353268" border = 0 cellpadding=5>';
echo '<tr bgcolor="#575582">';
echo '<td><font color="#FFFFFF"> Mounted at </td><td><font color="#FFFFFF"> Dismounted at</td>';
echo '<td><font color="#FFFFFF"> Volume Name </td><td><font color="#FFFFFF"> Drive used</td>';
echo '<td><font color="#FFFFFF"> Library Name </td>';
$sql = 'SELECT `Start` , `End` , `Volume`, `Drive` , `Library` FROM Tape WHERE (( `End` >= "'.$startdate.'" ) AND ( `Start` <= "'.$enddate.'"))';
if ($_POST['library']) {
$sql = $sql.' AND (`Library` = "'.$_POST['library'].'")' ;
}
if ($_POST['drive']) {
$sql = $sql.' AND (`Drive` = "'.$_POST['drive'].'")' ;
}
$sel=Query($sql);
if ($_POST['graph'])
{
$sql = 'SELECT UNIX_TIMESTAMP("'.$startdate.' 00:00:00") AS Start';
$range=Query($sql);
$gdatea=mysql_fetch_array($range);
$sql = 'SELECT UNIX_TIMESTAMP("'.$enddate.' 00:00:00") AS End';
$range=Query($sql);
$gdateb=mysql_fetch_array($range);
$sql = 'SELECT DISTINCT ( `Drive` ) FROM Tape WHERE (( `End` >= "'.$startdate.'" ) AND ( `Start` <= "'.$enddate.'"))';
if ($_POST['drive']) {
$sql = $sql.' AND (`Drive` = "'.$_POST['drive'].'")' ;
}
if ($_POST['library']) {
$sql = $sql.' AND `Library` = "'.$_POST['library'].'"' ;
}
$tape=Query($sql);
$a=0;
while ($row = mysql_fetch_array($tape))
{
$sqltape = 'SELECT `Volume`, `Drive` , `Library` , UNIX_TIMESTAMP( `Start` ) AS Ustart, UNIX_TIMESTAMP( `End` ) AS Uend FROM Tape WHERE (( `End` >= "'.$startdate.'" ) AND ( `Start` <= "'.$enddate.'")) AND `Drive` = "'.$row["Drive"].'"';
$out=Query($sqltape);
$b=0;
while ($row = mysql_fetch_array($out))
{
$gstart[$a][$b]=$row['Ustart'];
$gstart[$a][$b+1]=$row['Uend'];
$gdrive[$a]=$row['Drive'];
$glib[$a]=$row['Library'];
$b++;
$b++;
}
$a++;
}
}
$i=1;
while ($row = mysql_fetch_array($sel))
{
if ($i % 2) {
echo '<tr bgcolor="#f0f0e0"><td>'; }
else {
echo '<tr bgcolor="#e0e0f0"><td>'; }
echo ($row["Start"]).'</td><td>';
echo ($row["End"]).'</td><td>';
echo ($row["Volume"]).'</td><td>';
echo ($row["Drive"]).'</td><td>';
echo ($row["Library"]).'</td>';
$i++;
}
echo '</table><p>';
if ($_POST['graph'])
{
// graphing related includes
require_once('libraries/jpgraph.php');
require_once('libraries/jpgraph_line.php');
function TimeCallback($aVal) {
return Date('d/m-H:i',$aVal);
}
$g=0;
while ($g < $a)
{
$title='Tape usage activity for '.$gdrive[$g];
$graph_name = 'images/tape'.$g.'.png';
$graph = new graph(750, 180, $graph_name, 0, 0);
$graph->img->SetMargin(60, 50, 50, 90);
$num = count ($gstart[$g]);
// $graph->SetScale("intint",0,1,$gstart[$g][0],$gstart[$g][$num-1]);
$graph->SetScale("intint",0,1,$gdatea["Start"],$gdateb["End"]);
$graph->xaxis->SetLabelFormatCallback('TimeCallback');
$graph->xaxis->SetLabelAngle(90);
$i=0;
while ($i < $num)
{
if ($i % 2) $gvalue[$g][$i]=0;
else $gvalue[$g][$i]=1;
$i++;
}
$lineplot=new LinePlot($gvalue[$g],$gstart[$g]);
$lineplot->SetStepStyle();
$lineplot->SetColor("blue");
$lineplot->SetFillColor("lightblue");
$lineplot->SetWeight(2);
$graph->Add($lineplot);
$graph->SetMarginColor('white');
$graph->SetShadow();
$graph->title->Set($title);
$graph->yaxis->SetLabelAngle(90);
$graph->yaxis->title->Set("Tape activity",CENTER);
$graph->xaxis->HideTicks(true,true);
$graph->legend->SetLayout(LEGEND_HOR);
$graph ->legend->Pos( 0.01,0.98,"left","bottom");
$graph->Stroke($graph_name);
print "<img src='{$graph_name}'>\n";
$g++;
}
}
exit ();
}
include_once 'libraries/functions.php';
Connect();
echo '<center><font size=1>';
echo 'First Record in the DB about Tape usage ';
$sql = 'SELECT MIN(`Start`) AS start FROM Tape';
$output=Query($sql);
$startdate = mysql_fetch_array($output);
echo $startdate["start"].'<br>';
echo 'Last Record in the DB about Tape usage ';
$sql = 'SELECT MAX(`End`) AS end FROM Tape';
$output=Query($sql);
$enddate = mysql_fetch_array($output);
echo $enddate["end"].'<p>';
echo 'First Record in the DB about Reclamation ';
$sql = 'SELECT MIN(`Start`) AS start FROM Reclamation';
$output=Query($sql);
$startdate = mysql_fetch_array($output);
echo $startdate["start"].'<br>';
echo 'Last Record in the DB about Reclamation ';
$sql = 'SELECT MAX(`End`) AS end FROM Reclamation';
$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 Tape usage distribution </font></h2>
</td>
<td bgcolor="#d0d0ff"><center>Online <a href=help.php#tape>Help </a></center></td>
</tr>
<tr bgcolor="#e0e0f0"><td>
Start Date </td>
<td>
<?
include_once 'libraries/functions.php';
Connect();
listatoday(day,month,year);
?>
</td>
<tr bgcolor="#e0e0f0"><td>
End Date </td>
<td>
<?
listatoday(dayend,monthend,yearend);
?>
</td>
<tr bgcolor="#e0e0f0"><td>
Show only Library:
</td><td>
<?
echo '<select name="library">';
echo '<option selected value=""> </option>';
$sql = 'SELECT distinct(`Library`) FROM `Tape` ORDER BY `Library`';
$sel=Query($sql);
while ($row = mysql_fetch_array($sel))
{
echo '<option value="'.$row['Library'].'">'.$row['Library'].'</option>';
}
echo '</select>';
?>
</td>
<tr bgcolor="#e0e0f0"><td>
Show only Tape:
</td><td>
<?
echo '<select name="drive">';
echo '<option selected value=""> </option>';
$sql = 'SELECT distinct(`Drive`) FROM `Tape` ORDER BY `Drive`';
$sel=Query($sql);
while ($row = mysql_fetch_array($sel))
{
echo '<option value="'.$row['Drive'].'">'.$row['Drive'].'</option>';
}
echo '</select>';
?>
</td>
<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>
<form method="post">
<table bgcolor="#353268" cellspacing="0" cellpadding="0" border=1>
<tr bgcolor="#575582"><td>
<h2><font color="#FFFFFF"> Show Tape usage and Reclamation </font></h2>
</td>
<td bgcolor="#d0d0ff"><center>Online <a href=help.php#tape>Help </a></center></td>
</tr>
<tr bgcolor="#f0e0d0"><td>
Start Date </td>
<td>
<?
include_once 'libraries/functions.php';
Connect();
listatoday(day,month,year);
?>
</td>
<tr bgcolor="#f0e0d0"><td>
End Date </td>
<td>
<?
listatoday(dayend,monthend,yearend);
?>
</td>
</table>
<INPUT TYPE=SUBMIT name="Reclamation" value="Submit">
</FORM>
</body>
</html>