<html>
<head>
<title>PIForce-Web+</title>
  <link rel="stylesheet" href="piforceweb.css">
  <style>
	
  </style>
</head>
<body>
<?php

$log='logs/log.txt';

echo '<div class="game_btn"><font face="verdana" color="grey">';
echo '</br>';

echo 'loading ' . htmlspecialchars($_GET["rom"]) . ' ...';
echo '<br/>';
//need to delete log file first..
//shell_exec('rm logs/log.txt');
//or
if(file_exists($log)){
	unlink($log);
	}

if($fp = fopen($log,'a+')){
	if($res = fwrite($fp,date('Y-m-d H:i:s').'--'.$_GET["rom"].'
'))
	{
		//echo $res;
	}else{
		echo 'Erreur d écriture dans le log';
	}
}
else
	echo 'Erreur d ouverture/création du fichier: ./logs/log.txt';
	
//without LCD display
//$command = escapeshellcmd('sudo python /sbin/piforce/webforce.py '.$_GET["rom"]);
//with LCD display
$command = escapeshellcmd('sudo python /boot/piforcetools/webforcePlus.py '.$_GET["rom"]);

//echo 'command = '.$command . '</br>';
$output = exec($command,$output,$return);
echo "<pre>$output</pre>";

if($fp = fopen($log,'a+')){
	fwrite($fp,date('Y-m-d H:i:s').'--fin');
}else{
	echo 'Erreur d ouverture/création du fichier: ./logs/log.txt';
}




if($fp = fopen($log,'r+')){
	while (!feof($fp)){
		echo nl2br(fgets($fp));
	}
}
fclose($fp);
echo '</div></br>';

//echo 'Voir le log</div></a></center>';
//echo '<center><a href="logs/log.txt"><div id="log" class="game_btn">';

echo '</br>';
echo '<center><a href="javascript:history.back()"><div class="game_btn">Retour Liste</div></a></center>';

?>
</body>
</html>
