<?
// lista.php
// Title:  downlink table

session_start();

include("ins/connect.inc.php"); 
include("header-list.html");
?>
<script type="text/javascript"> 
function conferma () { 
  chiediConferma = confirm('Are you sure of wanting to cancel the record?!!!!!'); 
  
  if (chiediConferma == true){ 
    location.href="lista.php"; //ricarica la pagina
		} 
		else{
		document.write("Cancelled procedure")
window.location.reload('lista.php');

}
  } 
</script> 
<?

if ( !isset($_SESSION["login"]) ) {
  echo "<hr><p align=left><font face=Verdana size=2><b><a href='ins/loginform.php'>Login Downlink</a> </b></font></p>";
} else {
  echo "<hr><p align=left><font face=Verdana size=2><b><a href='ins/logout.php'>Logout Downlink</a></b></font></p>";
}
if ( !isset($_SESSION["login"]) ) {
  echo "<hr><p align=left><font face=Verdana size=2><b><a href='action/loginform.php'>Login Action</a> </b></font></p>";
	echo "<hr>";
} else {
  echo "<hr><p align=left><font face=Verdana size=2><b><a href='action/logout.php'>Logout Action</a></b></font></p>";
		echo "<hr>";  
}
echo "<font face='verdana' size='2'><li><b><a href='ins/reg.php'>Form Downlink</a></b></font>";
echo "<br><br>";
echo "<font face='verdana' size='2'><li><b><a href='action/action.php'>Form Action</a></b></font>";
echo "<br>";
echo "<br><center><Font face='VERDANA' size=4 color=red><b>Downlink & Action Table</font></b></center><p>";

echo "<table width='100%' cellpadding='4' border='1'>";
echo "<tr><td bgcolor='#e4e9fc'>";

$totale=0.; 
$str_1 ="create temporary table tmp1 select orbit, count(edtt) as ttt from comm_downlink group by orbit";
$query = mysql_query($str_1); 
$str_2 ="select a.orbit, a.edtt, a.nome from comm_downlink as a, tmp1 as b where (a.error < 1000 AND (a.ipm LIKE '%3%' OR a.ipm LIKE '%4%') AND "
       ."a.orbit=b.orbit AND b.ttt>1)";
$query = mysql_query($str_2); 
while ($row = mysql_fetch_row($query))
{
 $or=$row[0];
 $time=$row[1];
 $file=$row[2];
 $str="select orbit, edtt, nome from comm_downlink where (error < 1000 AND (ipm LIKE '%3%' OR ipm LIKE '%4%') AND orbit=$or)";
 $query_ = MyQuery($str);
 $t=$time; 
 while ($row_ = mysql_fetch_row($query_))
 {
  $time_=$row_[1];
  $file_=$row_[2];
  if ($file_>$file) {$t=$time_;}
 } //echo "or=".$or." newor=".$row_[0]." time=".$t." file=".$file." newfile=".$file_."<BR>";
 $totale=$totale+$t; 
}
$str_3="create temporary table tmp2 select a.orbit from comm_downlink as a, tmp1 as b where a.orbit=b.orbit AND b.ttt<2";
$query = MyQuery($str_3);

$strsql = "select sum(a.edtt) as totalecolonna from comm_downlink as a, tmp2 as c  WHERE (a.error < 1000 AND (a.ipm LIKE '%3%' OR a.ipm LIKE '%4%') AND "
         ."a.orbit=c.orbit)";
$query = mysql_query($strsql); 
$row = mysql_fetch_array($query); //echo $totale."<BR>";
$totale = $totale+$row["totalecolonna"]; //echo $totale."<BR>";

//$strsql = "select sum(temp.edtt) as totalecolonna from (select distinct(orbit), edtt from comm_downlink WHERE (error < 1000 AND (ipm LIKE '%3%' OR ipm LIKE '%4%'))) as temp";
//$query = mysql_query($strsql); 
//$row = mysql_fetch_array($query); 
//$totale = $row["totalecolonna"]; 
echo "<font face=verdana size=1><b>TOT. Effective data taking time (s) with IPM 3/4:&nbsp;<font color='red'> $totale</b></font></font>";
echo "</td></tr>";

echo "<tr><td bgcolor='#e4e9fc'>";
//$strsql = "select sum(edtt) as totalecolonna from comm_downlink WHERE (ipm NOT LIKE '%3%' AND ipm NOT LIKE '%4%')";
MyQuery("create temporary table tmp3 select distinct(orbit), edtt from comm_downlink WHERE (ipm NOT LIKE '%3%' AND ipm NOT LIKE '%4%')");
$strsql = "select sum(edtt) as totalecolonna from tmp3";

$query = mysql_query($strsql); 
$row = mysql_fetch_array($query); 
$totale = $row["totalecolonna"]; 
echo "<font face=verdana size=1><b>TOT. Effective data taking time (s) without IPM 3/4:&nbsp;<font color='red'> $totale</b></font></font>";
echo "</td></tr>";

echo "<tr><td bgcolor='#e4e9fc'>";
//$strsql = "select sum(edtt) as totalecolonna from comm_downlink ";
MyQuery("create temporary table tmp4 select distinct(orbit), edtt from comm_downlink");
$strsql = "select sum(edtt) as totalecolonna from tmp4";
//$strsql = "select sum(temp2.edtt) as totalecolonna from (select distinct(orbit), edtt from comm_downlink) as temp2";

$query = mysql_query($strsql); 
$row = mysql_fetch_array($query)or die (mysql_error()); 
$totale = $row["totalecolonna"]; 
echo "<font face=verdana size=1><b>TOT. Effective data taking time (s):&nbsp;<font color='red'> $totale</b></font></font>";
echo "</td></tr>";

echo "</table>";
echo "<br>";
echo "<br>";
echo "<table width='100%' cellpadding='4'>";

echo "<tr bgcolor='#708090'>";
if ( isset($_SESSION["login"]) ) {
    echo "<td colspan='2'><center><font color='white' face='verdana' size='1'>Field modification</font></center></td>";
	}	
	echo "<td width='3%'><center><font color='white' face='verdana' size='1'><b>Counter</b></font></center></td>";
echo "<td width='10%'><center><font color='white' face='verdana' size='1'><b>Filename/Action</b></font></center></td>
		 												<td width='3%'><center><font color='white' face='verdana' size='1'><b>Orbit of download</b></font></center></td>
														<td width='3%'><center><font color='white' face='verdana' size='1'><b>Absolute time (s)</b></font></center></td>
														<td width='13%'><center><font color='white' face='verdana' size='1'><b>Effective Data<br>Taking Time (s)</b></font></center></td>
														<td width='13%'><center><font color='white' face='verdana' size='1'><b>Date &amp; Hour MWT Download/Action</b></font></center></td>
                            <td width='13%'><center><font color='white' face='verdana' size='1'><b>Date &amp; Hour MWT Downlink (for downloads)</b></font></center></td>
														<td width='5%'><center><font color='white' face='verdana' size='1'><b>Size (GB)</b></font></center></td>
														<td width='5%'><center><font color='white' face='verdana' size='1'><b>Error Rate</b></font></center></td>
														<td width='5%'><center><font color='white' face='verdana' size='1'><b>Trigger</b></font></center></td>
														<td width='5%'><center><font color='white' face='verdana' size='1'><b>IPM</b></font></center></td>
														<td width='5%'><center><font color='white' face='verdana' size='1'><b>ws</b></font></center></td>
                            <td width='40%'><center><font color='white' face='verdana' size='1'><b>Comments</b></font></center></td>";
														
echo "</tr>";


	
$sql = "SELECT * FROM comm_downlink ORDER BY orbit DESC ";
$res = MyQuery($sql);

//testo aggiunto per colorare righe
$bgcolor[0] = "bgcolor=#edf5fg";
$bgcolor[1] = "bgcolor=#cccccc";
$counter = 0;
//fine testo aggiunto per colorare righe
while( $row = mysql_fetch_array($res, MYSQL_ASSOC) ) {

// testo aggiunto per colorare righe
$bc = $bgcolor[$counter];
$counter = 1 - $counter;

echo "<tr $bc>";
//testo per modifica e eliminazione campo
  if ( isset($_SESSION["login"]) ) {
    echo "<td><font face=Verdana size=1><a href='ins/reg.php?id=".$row["id"]."'>change</a></td>";
    echo "<td><font face=Verdana size=1><a href='ins/delete.php?id=".$row["id"]."' onClick='conferma();'>delete</a></td>";
  }
echo "<td><font face=verdana size=1>".$row["id"]."</FONT></td>";	
echo "<td><font face=verdana size=1><a href='http://pamela-qlook.roma2.infn.it/filesFromYoda/".$row["nome"]."'>".$row["nome"]."</FONT></td>";
echo "<td><font face=verdana size=1>".$row["orbit"]."</FONT></td>";
echo "<td><font face=verdana size=1>".$row["time"]."</FONT></td>";
echo "<td><font face=verdana size=1>".$row["edtt"]."</FONT></td>";
$myData = Explode( "-", $row["datedld"] );

echo "<td><font face=verdana size=1>$myData[2]/$myData[1]/$myData[0] - ".$row["oradld"]."</font></td>";	
$myData1 = Explode( "-", $row["datedlk"] );

echo "<td><font face=verdana size=1>$myData1[2]/$myData1[1]/$myData1[0] - ".$row["oradlk"]."</font></td>";	
echo   "<td><font face=verdana size=1>".$row["rr"]."</font></td>";
echo   "<td><font face=verdana size=1>".$row["error"]."</font></td>";
echo   "<td><font face=verdana size=1>".$row["a18"]."</font></td>";
echo   "<td><font face=verdana size=1>".$row["ipm"]."</font></td>";
echo   "<td><font face=verdana size=1>".$row["ws"]."</font></td>";

echo   "<td><font face=verdana size=1>".$row["comments"]."</font></td>";


	 echo "</tr>";
	}
	//fine testo
echo "</table>";

         


//testo scoperto oggi

//fine del testo tolto
include("footer-list.html");
?>

