<?
require_once("ssh2.server.php");

include "header.php";


if(!(empty($_FILES["uploadCFile"])) && !(empty($_FILES["uploadDFile"])))
{
	if($_FILES['uploadDFile']['size'] > 2 && $_FILES['uploadCFile']['size'] > 2){
		$upload = $uploaddir.$_FILES['uploadDFile']['name'];
//		print($upload."<BR>");
		move_uploaded_file($_FILES['uploadDFile']['tmp_name'],$upload);
		
		$upload = $uploaddir.$_FILES['uploadCFile']['name'];
		move_uploaded_file($_FILES['uploadCFile']['tmp_name'],$upload);

		//get the requested application
		$app = $_REQUEST['appli'];
		fnSendAllData($app,$_FILES['uploadDFile']['name'],$_FILES['uploadCFile']['name']);
		$upload = $uploaddir.$_FILES['uploadCFile']['name'];
		unlink($upload);
		$upload = $uploaddir.$_FILES['uploadDFile']['name'];
		unlink($upload);

	} else if ($_FILES['uploadCFile']['size'] > 2){

		$upload = $uploaddir.$_FILES['uploadCFile']['name'];
                 move_uploaded_file($_FILES['uploadCFile']['tmp_name'],$upload);
                //get the requested application
                $app = $_REQUEST['appli'];
                fnSendComData($app,$_FILES['uploadCFile']['name']);

                unlink($upload);
	}
}

	$table = $GLOBALS['commandtable'];
	mysql_select_db($GLOBALS['database']);
	$query = "SELECT softname FROM $table";
	$res = mysql_query($query);
?>
<div id="content">
<br><br><br>
<form name="upload" enctype="multipart/form-data" method='post' action="<?$_SERVER['PHP_SELF']?>">
Select a command file from your computer:<br><br>
<input type="file" size=42 name="uploadCFile">
<br>

Select a data file from your computer:<br><br>
<input type="file" size=42 name="uploadDFile">
<br>

<br>
Please select application you intend to run:<br><br>
<?

$apps = array();
$r = 0;
if ($res) {

	while($row = mysql_fetch_row($res))
	foreach($row as $data){
		$apps[$r++] = $data;
	}
} else {
print(mysql_error());}

$apps = array_unique($apps);
for ($a = 0; $a < count ($apps); $a++){
	echo "<input type=\"radio\" name=\"appli\" value=\"$apps[$a]\"> $apps[$a]<br>";
}

?>
<input type="submit" name="submit" value="send">
</form>
</div>
<?
if (isset($GLOBALS['rkey'])){
	print ("<div id=\"footer\"> Key to obtain results: ".$GLOBALS['rkey']."</div>");
}

?>

</body>
</html>
