<?php
/* 
SETI@HOME progress-script this script can be used to see
how much progress you've made with you're current work-unit
and you're statistics worldwide

To see your current WU-progress you need the commandline-version,
not the screensaver-version.

If you have setispy, you can also activate setispy-stats by altering
'var $setispy = 0;' -> 'var $setispy = 1;'
Than you'll have to set the seti-spy folder in the
var rootfolder = ""; (in the setispy-class)

********************************
******DO NOT ALTER ANYTHING*****
****** UNLESS STATED SO ********
*********Version 0.3 ***********
   application only uses PHP
********************************
*/


// alter this to your seti@home email adress
$email ="davebronckers@hotmail.com";


echo "<HTML><HEAD><TITLE>SETI@HOME Statistics VERSION 0.2</TITLE></HEAD><BODY>";

class currentprogress{

	// alter this to 1 if client installed, else set to zero. 
	var $client = 1;

	/* alter this to the SETI@HOME folder, for example: 
	var $rootfolder = "C:\Documents and Settings\User\Desktop\seti\\"; 		*/
	var $rootfolder = "C:\Documents and Settings\Bert\Bureaublad\seho\\";
	
	// Set this to 1 if you want so see more detailes
	// else turn to 0
	var $showdetails = 1;
		

	function currentprogress(){
		
		if($this->client == 1){
			
			if(!file_exists($this->rootfolder . "state.sah")){
			
				die("<P>Cannot Locate you're state.sah file in the <strong>" . $this->rootfolder . "</strong> directory. Please
				check if the state.sah file is in the right place or if you have installed the commandline version. If not, alter <em>'var \$client = 1;'</em> to <em>'var \$client = 0;'</em> in <strong>" . $_SERVER['PHP_SELF'] ."</strong>");
			}
			
			$file = $this->rootfolder . "state.sah";
			$data = file($file);
			
			// client version:
			$version = $this->rootfolder . "version.sah";
			$getversion = file($version);
			$big = ereg_replace("^major_version=", "", $getversion[0]);
			$small = ereg_replace("^minor_version=", "", $getversion[1]);
			
			echo "<font size=-1>Client-version: " . $big . ".0" . $small . "</font><P>";
			
			echo "<h1>Your Current WU: </h1>";
			
			// current workunit progress
			$progress = ereg_replace("^prog=", "", $data[4]);
			$progress *= 100;
			echo "Your current WU is at <strong>" . round($progress, 3) . "</strong> percent done<br>";
			
			// current CPU time on WU
			$cputime = ereg_replace("^cpu=", "", $data[3]);
			$cputime /= 60;
			echo "Your CPU is currently <strong>" . round($cputime, 3) . "</strong> minutes busy";
			
			$progtil100 = 100 / $progress;
			$progtil100 *= $cputime;
			echo "<br>Estimated Total time: <strong>" . round($progtil100, 2) . "</strong> Minutes";
			
			$tillcomp = 100 /  $progress;
			$tillcomp *= $cputime;
			$tillcomp -= $cputime;
			echo "<br>Estimated time till completation: <strong>" . round($tillcomp, 2) . "</strong> Minutes";
			
				if($this->showdetails == 1){
				
				// more detailed stats
				$powerspike = ereg_replace("^bs_power=", "", $data[8]);
				$scorespike = ereg_replace("^bs_score=", "", $data[9]);
				
				$scoregaussian = ereg_replace("^bg_score=", "", $data[14]);
				$powergaussian = ereg_replace("^bg_power=", "", $data[16]);
				
				$scorepulse = ereg_replace("^bp_score=", "", $data[87]);
				$powerpulse = ereg_replace("^bp_power=", "", $data[88]);
				
				$scoretriplet = ereg_replace("^bt_score=", "", $data[96]);
				$powertriplet = ereg_replace("^bt_power=", "", $data[97]);
				
				echo "<ul>";
					if($scorespike == 0.000000){
					echo "<li><p><strong>No</strong> spikes found yet</li><br>";
					}else{
					echo "<p><li>Spikes: <br> <strong>Best Score: </strong> $scorespike<br><strong>Best Power:</strong> $powerspike</li><br>";
					}if($scoregaussian == 0.000000){
					echo "<li><strong>No</strong> gaussians found yet</li><br>";
					}else{
					echo "<li>Gaussians<br><strong>Best Score: </strong> $scoregaussian<br><strong>Best Power:</strong> $powergaussian</li><br>";
					}if($scorepulse == 0.000000){
					echo "<li><strong>No</strong> pulses found yet</li><br>";
					}else{
					echo "<li>Pulses<br> <strong>Best Score: </strong> $scorepulse<br><strong>Best Power:</strong> $powerpulse</li><br>";
					}if($scoretriplet == 0.000000){
					echo "<li><strong>No</strong> triplets found yet<br></li>";
					}else{
					echo "<li>Triplets<br> <strong>Best Score: </strong> $scoretriplet<br><strong>Best Power:</strong> $powertriplet</li><br>";
					} 
				}echo "</ul>";
				
				
							
		}else{
		
			echo "You don't have the commandline-version so your current statistics are not available";
			}		
	}
}
class totalstatistics{

	function totalstatistics($email){
	
	
		// url to open:
		$url = "http://setiathome2.ssl.berkeley.edu/fcgi-bin/fcgi?cmd=user_xml&email=" . $email;
	
	
		echo "<HR><P><h1>World-Wide Stats: </h1><br><br>";
	
		$file = file($url) or die("Error getting the seti@home stats. Please check your emailadress you've filled in. Please check if this is the right adress! Also check if you have an internet connection.");
	
			if($file[6] == ""){
		
			die("Error getting the seti@home stats. Please check your emailadress you've filled in. Your current emailadress is <strong> " . $email . "</strong>. Please check if this is the right adress!");
			}
			
		// stats
		$username = "<strong>Username: </strong>" . $file[6] . "<br>";
		$WUnumber = "<strong>Number of WU's: </strong>" . $file[7] . "<br>";
		$CPUtime = "<strong>Total CPU time: </strong>" . $file[8] . "<br>";
		$AvCPUtime = "<strong>Average CPU time per WU: </strong>" . $file[9] . "<br>";
		$AvWUperday = "<strong>WU's per day: </strong>" . $file[10] . "<br>";
		$LastWU = "<strong>Last WU received: </strong>" . $file[11] . "<br>";
		$MemReg = "<strong>Date you registered S@H: </strong>" . $file[12] . "<br>";
		$MemTim = "<strong>Time you have registered S@H: </strong>" . $file[13] . "<br><br>";
	
		$MemGroup = "<strong>Member of Group: </strong>" . $file[16] . "<br>";
		$FouGroup = "<strong>Founder of Group: </strong>" . $file[17] . "<br><br>";
	
		$RankWW = "<strong>Rank World-Wide: </strong>" . $file[20] . "<br>";
		$MemWW = "<strong>Members World-Wide: </strong>" . $file[21] . "<br>";
		$MemSameWu = "<strong>Members With same WU's: </strong>" . $file[22] . "<br>";
		$RankTop = "<strong>Top-Ranked: </strong>" . $file[23];
	
		echo $username . $WUnumber . $CPUtime . $AvCPUtime . $AvWUperday . $WUnumber . $LastWU . $MemReg . $MemTim . $MemGroup . $FouGroup . $RankWW . $MemWW . $MemSameWu . $RankTop;
	
		}
	}
class setispystats{

	// alter this to 1 if setispy installed, else set to zero. 
	var $setispy = 1;
	
	// set the folder in witch you've installed setispy
	var $rootfolder = "C:\Documents and Settings\Bert\Bureaublad\seho\\";
	
		function setispystats(){
		
			if($this->setispy == 1){
		
				if(!file_exists($this->rootfolder . "setispy.ini")){
		
				die("<P>Cannot Locate you're setispy.ini file in the <strong>" . $this->rootfolder . "</strong> directory. Please
				check if the setispy.ini file is in the right place or if you have installed setispy. If not, alter <em>'var \$setispy = 1;'</em> to <em>'var \$setispy = 0;'</em> in the file: <strong>" . $_SERVER['PHP_SELF'] ."</strong>");
				}
			
			$files = $this->rootfolder . "setispy.ini";
			$sdata = file($files);
			
			// stats
			$cpu = ereg_replace("^CPUType=", "<strong>Processor: </strong>", $sdata[13]) . "<BR>";
			$speed = ereg_replace("^CPUSpeed=", "", $sdata[17]) . "<BR>";
			$os = ereg_replace("^OSVersion=", "<strong>Operating System: </strong>", $sdata[56]) . "<BR>";
			$memory = ereg_replace("^PhysicalMemory=", "", $sdata[57]);
			$memory /= 1024;
			$speed /= 1000000000;
			
			echo "<hr><h1>Computer Specs:</h1><br>" . $cpu . "<strong>Processor Frequenty: </strong>" . round($speed, 3) . " Gygaherz <br> " .  $os . "<strong>Physical Memory: </strong>" .  round($memory, 1) . " Mb <br>";
				
			}		
		}
	
	
}	
// echo current stats
$progress = new currentprogress;

// echo world-wide stats
$totalstats = new totalstatistics($email);

// echo setispy stats
$setispystats = new setispystats; 

echo "</BODY></HTML>";

?>