<? 
//kontrola a start sesion s uzivatelovymi udaji
session_start();
if (!$_SESSION['nick'] )
{
 header("Location:index.php");
 exit;
}
include("./config.php"); //soubor s pripojenim k db

$sqlo="SELECT ip FROM servers WHERE id_server=$id_server";
$aao=MySQL_Query($sqlo);
while($bbo=mysql_fetch_array($aao))
{
$adresa=$bbo["ip"];
}
$sqlo="SELECT Count(*) FROM services WHERE id_server=$id_server";
$aao=MySQL_Query($sqlo);
while($bbo=mysql_fetch_array($aao))
{
$countservices=$bbo["Count(*)"];
}


 $tim=time();
 @$pridej = MySQL_query( "UPDATE users SET last_akce='$tim' where userid='$userid' "); 


echo "	<table border=\"1\" cellpadding=\"3\" cellspacing=\"3\" style=\"border-collapse: collapse bordercolor=#111111;\" >
  	<tr>
    	 <td align=\"center\">Servicesīs name</td>
    	 <td align=\"center\">Owner</td>
    	 <td align=\"center\">Status</td>
    	 <td align=\"center\">CPU</td>
    	 <td align=\"center\">RAM</td>
    	 <td align=\"center\">Start</td>
    	 <td align=\"center\">Action</td>
  	</tr>
     ";

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

$aa=MySQL_Query("SELECT * FROM services WHERE id_server=$id_server ORDER BY id_services ");
while($bb=mysql_fetch_array($aa))
{
  echo "<tr>
    	    <td align=\"left\">";
  if ($bb["nazev"][0]=="-")
  {
   $name=explode('-',$bb["nazev"]);
			echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$name[1]."";
  }
  else
			echo "".$bb["nazev"]."";
    	 
  echo " </td>
    	 <td align=\"left\">".$bb["vlastnik"]."</td>
    	 <td align=\"left\">";
 
switch ($bb["stav"][0]) {
    case D:
        echo "<font color=\"#FF0000\">Dead</font>";
        $tiskni="<a href=\"send.php?server=http://".$adresa."/server/action.php&amp;amp;action=R&amp;amp;pid=".$bb["ppid"]."&amp;amp;nazev=".$bb["nazev"]."&amp;amp;ip=".$adresa."\" target=\"_blank\">Restart/Start</a>";
        break;
    case R:
        echo  "<font color=\"#00FF00\">Runnig</font>";
        $tiskni="<a href=\"send.php?server=http://".$adresa."/server/action.php&amp;amp;action=R&amp;amp;pid=".$bb["ppid"]."&amp;nazev=".$bb["nazev"]."&amp;ip=".$adresa."\" target=\"_blank\">Restart/Start</a> <a href=\"send.php?server=http://".$adresa."/server/action.php&amp;action=S&amp;pid=".$bb["ppid"]."&amp;nazev=".$bb["nazev"]."&amp;ip=".$adresa."\" target=\"_blank\">Stop</a>";
        break;
    case S:
        echo  "<font color=\"#00FF00\">Waiting</font>";
        $tiskni="<a href=\"send.php?server=http://".$adresa."/server/action.php&amp;action=R&amp;pid=".$bb["ppid"]."&amp;nazev=".$bb["nazev"]."&amp;ip=".$adresa."\" target=\"_blank\">Restart/Start</a> <a href=\"send.php?server=http://".$adresa."/server/action.php&amp;action=S&amp;pid=".$bb["ppid"]."&amp;nazev=".$bb["nazev"]."&amp;ip=".$adresa."\" target=\"_blank\">Stop</a>";
        break;
    case T:
        echo "<font color=\"#FF0000\">Stoped</font>";
        $tiskni="<a href=\"send.php?server=http://".$adresa."/server/action.php&amp;action=R&amp;pid=".$bb["ppid"]."&amp;nazev=".$bb["nazev"]."&amp;ip=".$adresa."\" target=\"_blank\">Restart/Start</a>";
        break;
    case X:
        echo  "<font color=\"#FF0000\">Dead</font>";
        $tiskni="<a href=\"send.php?server=http://".$adresa."/server/action.php&amp;action=R&amp;pid=".$bb["ppid"]."&amp;nazev=".$bb["nazev"]."&amp;ip=".$adresa."\" target=\"_blank\">Restart/Start</a>";
        break;
    case Z:
        echo "<font color=\"#FF0000\">Dead</font>";
        $tiskni="<a href=\"send.php?server=http://".$adresa."/server/action.php&amp;action=R&amp;pid=".$bb["ppid"]."&amp;nazev=".$bb["nazev"]."&amp;ip=".$adresa."\" target=\"_blank\">Restart/Start</a>";
        break;
  }

  echo "</td>
    	 <td align=\"left\">".$bb["cpu"]."</td>
    	 <td align=\"left\">".$bb["ram"]."</td>
    	 <td align=\"left\">";
  $cas=time();
  $line=explode('-',$bb[start]) ;
  $casapl=0;
  if ($line[1]!="")
  {
   $casapl=$line[0] *24*60*60;
   $line2=explode(":",$line[1]);   
   $casapl=$casapl + $line2[0] *60*60;
   $casapl=$casapl + $line2[1] *60;
   $casapl=$casapl + $line2[2] ;
  }
  else
  {
   $line2=explode(":",$line[1]);
   if ($line2[2]!="")
   {
    $casapl=$casapl + $line2[0] *60*60;
    $casapl=$casapl + $line2[1] *60;
    $casapl=$casapl + $line2[2] ;
   }
   else
   {
    $casapl=$casapl + $line2[0] *60;
    $casapl=$casapl + $line2[1] ;
   }
  }
  $casapl =  date ("H:i:s-j/n/Y",$cas - $casapl);
  echo "$casapl</td>
    	 <td align=\"left\">";
   echo "$tiskni"; 
  echo "</td>
   	</tr>
 
      "; 

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