<?

class radek
{
    var $cislo;
    var $nazev;
    var $vlastnik;
    var $stav;
    var $cpu;
    var $ram;
    var $start;
    var $ppid;
}

$hmenu = new radek;
//$cislo2=time();
$time=time();
$time2=$time - (24*60*60);
$ip_zdroje = $_SERVER["REMOTE_ADDR"];
 
include("./config.php"); //soubor s pripojenim k db
$aae=MySQL_Query("SELECT * FROM servers WHERE ip='$ip_zdroje' AND activ='1' ORDER BY id_server ");
while($bbe=mysql_fetch_array($aae))
{ 
 $id_server =  $bbe["id_server"];
 $memdnu =  $bbe["memdnu"];
 if ($bbe["naposled"]< $time2) // osetreni dostupnosti
 { 
   $dostup=round(100* $bbe["pocethitu"]/(24*60), 2); // jednoduche pocitani dostupnosti
   //$dostupnost=$bbe["dostupnost"];
   @$pridej = MySQL_query( "INSERT INTO dostupnost VALUES ('$id_server','$time','$dostup')"); 
   @$pridej = MySQL_query( "UPDATE servers SET pocethitu='0',dostupnost='$dostup',naposled='$time' WHERE id_server='$id_server' ");
 }
 else
 if ($bbe["naposled"]=="") // osetreni jestli vubec nekdy byla dostupnost realizovana
   @$pridej = MySQL_query( "UPDATE servers SET naposled='$time' WHERE id_server='$id_server' ");

  // nulovani services kvuli omezene velikost auto_increamntujiciho ID
	$aae=MySQL_Query("SELECT * FROM services WHERE id_services > '1000000000'");
	while($bbe=mysql_fetch_array($aae))
  @$prid = MySQL_query( " TRUNCATE TABLE `services`"); 

  // vymaze vsechny services  od daneho zdroje
 @$pridej = MySQL_query( "DELETE FROM services WHERE id_server='$id_server' ");
  // vymaze vsechny stare zaznamy zateze od daneho zdroje
 @$pridej = MySQL_query( "DELETE FROM zatez WHERE id_server='$id_server' AND time < ($time-$memdnu*24*60*60)  ");

  // inicializace SOAP clienta na dane ip zdroje
 $client = new SoapClient(null, array('location' => "http://".$ip_zdroje."/server/my_data.php", 'uri' => "http://test-uri/"));
	 // volani metod pro ziskani sledovacich dat
 $cpu = $client->prtcpu();
  // parametr kB,MB,GB,TB
 $ramall = $client->prtramall();
 $ramused = $client->prtramused();
 $uptime = $client->prtuptime();
 $pole =$client->prtobj();

  // zpracovani dat a ulozeni do databaze
 for ($i=0;$i<count($pole);$i++)
 {
   $hmenu2 =$pole[$i];
 
   @$pridej = MySQL_query( "INSERT INTO services VALUES ('','$id_server','$hmenu2->nazev','$hmenu2->vlastnik','$hmenu2->stav','$hmenu2->cpu','$hmenu2->ram','$hmenu2->start','$hmenu2->ppid')"); 

 }
  @$pridej = MySQL_query( "INSERT INTO zatez VALUES ('$id_server','$time','$cpu','$ramused','$ramall')"); 

 @$pridej = MySQL_query( "UPDATE servers SET uptime='$uptime',time='$time', pocethitu=pocethitu + 1 WHERE id_server='$id_server' ");
}
?>

 
    
 