<? 
//kontrola a start sesion s uzivatelovymi udaji
session_start();
if (!$_SESSION['nick'] )
{
 header("Location:index.php");
 exit;
}
echo "    	 <h2> Servers</h2>
    <br />
  	<br />
	<table border=\"0\" cellpadding=\"3\" cellspacing=\"2\" style=\"border-collapse: collapse bordercolor=#111111;\" >
  	<tr>
    	 <td align=\"center\" colspan=\"2\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\">Server´s name</td>
    	 <td align=\"center\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-right: 6; padding-top: 1; padding-bottom: 1\">Server´s IP</td>
    	 <td align=\"center\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\">Last contact</td>
    	 <td align=\"center\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\">Services enough/runnig</td>
    	 <td align=\"center\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\">Availability</td>
    	 <td align=\"center\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\">Run time</td>
    	 <td align=\"center\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\">-</td>
    	 <td align=\"center\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\">-</td>
    	 <td align=\"center\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\">-</td>
    	 <td align=\"center\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\">-</td>
  	</tr>
     ";

include("./config.php"); //soubor s pripojenim k db

$aa=MySQL_Query("SELECT * FROM servers ORDER BY id_server ");
while($bb=mysql_fetch_array($aa))
{
 if ($bb["dostupnost"]=="")
  $bb["dostupnost"] = "Insufficiency of data for count";

 $sqlo="SELECT Count(*) FROM services WHERE id_server=".$bb["id_server"]." AND !(stav like 'S%' OR stav like 'R%') ";
 $aao=MySQL_Query($sqlo);
 while($bbo=mysql_fetch_array($aao))
  $chyb=$bbo["Count(*)"];

 $sqlos="SELECT Count(*) FROM services WHERE id_server=".$bb["id_server"]."  ";
 $aaos=MySQL_Query($sqlos);
 while($bbos=mysql_fetch_array($aaos))
  $sluzeb=$bbos["Count(*)"];
 
 if ($bb["time"]!=0)
  $dat =  date ("H:i:s j.n.Y",$bb["time"]);
 else
  $dat = "Any";

 $uptime=$bb["uptime"];
 if ($uptime!="" AND $uptime!=0)
 {
  $den = floor($uptime/(24*60*60));
  $hod = floor(($uptime-($den*24*60*60))/(60*60));
  $min = floor(($uptime-(($den*24*60*60)+($hod*60*60)))/60);
  $uptime=$den." d ".$hod." h ".$min." m";
 }
  if ($bb["activ"])
   echo "<tr> 
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2;\"  colspan=\"2\" > <a href=\"./main.php?title=services&amp;id_server=".$bb["id_server"]."\" title=\"servises\">".$bb["nazev"]."</a></td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-right: 6; padding-top: 1; padding-bottom: 1\"> ".$bb["ip"]."</td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-right: 6; padding-top: 1; padding-bottom: 1\"> $dat</td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"> $sluzeb / ".($sluzeb-$chyb)."</td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"> ".$bb["dostupnost"]." %</td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\">&nbsp;$uptime</td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><a href=\"./main.php?title=deactiv&amp;id_server=".$bb["id_server"]."\" >Deactivated</a></td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><a href=\"./main.php?title=my_stat&amp;id_server=".$bb["id_server"]."\" ><img border=\"0\" src=\"./img/graf.png\" alt=\"Statistics of server in graphs\" title=\"Statics of server in graphs\" /></a></td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><a href=\"./main.php?title=edit&amp;id_server=".$bb["id_server"]."\" ><img border=\"0\" src=\"./img/pen.png\" alt=\"Edit server\" title=\"Edit server\" /></a></td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><a href=\"./main.php?title=smazserver&amp;id_server=".$bb["id_server"]."\" ><img border=\"0\" src=\"./img/b_empty.png\" alt=\"Delete server\" title=\"Delete server\" /></a></td>
	</tr>
 
      "; 
  else
   echo "<tr>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\" colspan=\"2\" ><font color=\"#FF0000\"><a href=\"./main.php?title=services&amp;id_server=".$bb["id_server"]."\" title=\"servises\">".$bb["nazev"]."</a></font></td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><font color=\"#FF0000\">".$bb["ip"]."</font></td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><font color=\"#FF0000\">$dat</font></td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><font color=\"#FF0000\">$sluzeb / ".($sluzeb-$chyb)."</font></td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><font color=\"#FF0000\"> ".$bb["dostupnost"]." %</font></td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\">&nbsp;$uptime</td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><a href=\"./main.php?title=activ&amp;id_server=".$bb["id_server"]."\" >Activated</a></td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><a href=\"./main.php?title=my_stat&amp;id_server=".$bb["id_server"]."\" ><img border=\"0\" src=\"./img/graf.png\" alt=\"Statistics of server in graphs\" title=\"Statics of server in graphs\" /></a></td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><a href=\"./main.php?title=edit&amp;id_server=".$bb["id_server"]."\" ><img border=\"0\" src=\"./img/pen.png\" alt=\"Edit server\" title=\"Edit server\" /></a></td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 2; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><a href=\"./main.php?title=smazserver&amp;id_server=".$bb["id_server"]."\" ><img border=\"0\" src=\"./img/b_empty.png\" alt=\"Delete server\" title=\"Delete server\" /></a></td>
	</tr>
      "; 

  if ($chyb !=0)
  {
   echo "<tr>
	 <td align=\"left\" style=\"border-right-style: solid; border-right-width: 1; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"> </td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 1;\" colspan=\"2\" >Název služby</td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 1;\" colspan=\"2\">Vlastník</td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 1;\">Stav</td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 1; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\" colspan=\"3\">Restart/Start</td>

	</tr>
 
      "; 
   $aas=MySQL_Query("SELECT * FROM services WHERE id_server=".$bb["id_server"]." AND !(stav like 'S%' OR stav like 'R%')  ORDER BY id_services ");
   while($bbs=mysql_fetch_array($aas))
   {
     echo "<tr>
	 <td align=\"left\" style=\"border-right-style: solid; border-right-width: 1; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><font color=\"#FF0000\"> </font></td>
    	 <td align=\"left\" colspan=\"2\" style=\"border-style: solid; border-width: 1; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><font color=\"#FF0000\">".$bbs["nazev"]."</font></td>
    	 <td align=\"left\" colspan=\"2\" style=\"border-style: solid; border-width: 1; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><font color=\"#FF0000\">".$bbs["vlastnik"]."</font></td>
    	 <td align=\"left\" style=\"border-style: solid; border-width: 1; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\">";
  
     switch ($bbs["stav"][0]) 
     {
      case D:
        echo "<font color=\"#FF0000\">Dead</font>";
         break;
      case T:
        echo "<font color=\"#FF0000\">Stoped</font>";
        break;
      case X:
        echo  "<font color=\"#FF0000\">Dead</font>";
        break;
      case Z:
        echo "<font color=\"#FF0000\">Dead</font>";
        break;
     }
     echo "</td>
    	 <td align=\"left\" colspan=\"3\" style=\"border-style: solid; border-width: 1; padding-left: 6; padding-left: 6; padding-top: 1; padding-bottom: 1\"><font color=\"#FF0000\"><a href=\"send.php?server=http://".$bb["ip"]."/server/action.php&amp;action=R&amp;pid=".$bbs["ppid"]."&amp;nazev=".$bbs["nazev"]."&amp;ip=".$bb["ip"]."\" target=_blank>Restart/Start</a></font></td>

	</tr>
 
      "; 
   }
  }

}
echo "</table><br />";
?>