<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CFTT Federated Testing - test a Mobile Device tool</title>
<link rel="stylesheet" type="text/css" href="../css/reset.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/main_style.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/layout.css" media="screen" />
<style>
	table, th, td {
	   border-collapse: collapse;
	   border: 1px solid black;
	   } 
	tr {
	   border-collapse: collapse;
	   border: 2px solid black;
	   } 
</style>
</head>
<body id="menu1">
	<div id="mainWrapper">
		<div id="topBannerContainer">
			<div id="logoContainer">
  				<img src="../images/banner.png" alt="CFTT Federated Testing - NIST">
			</div>
            <!-- Menu Starts-->
			<div id="menuContainer">
				  <?php
						include '../include/global.php';
						print_main_horizontal_menu_contents();
				  ?>
    		</div>
            <!-- Menu Ends-->
		</div>
		<!-- TopBanner Ends-->
	  
		<!-- Main Content Starts-->	
		<div id="subContentContainer">
		  <div id="leftContent">
		    <div id="leftLinks">
<div>
<?php
include '../include/mdt-global.php';
?>
		    </div>
		    </div>
		  </div>			
		  <div id="rightContent">
<!--		    <div id="breadcrumb"><a href="../Federated_Testing_Home_Page.php">Home</a> > Test a disk imaging tool</div>-->
			<div id="breadcrumb"><a href="../Federated_Testing_Home_Page.php" class="nav">Home</a> &gt; <a href="/mobiledevice/mdt.php" class="nav"> Mobile Device Testing Home</a> &gt; Recording Device Setup</div>

<?php

$continue = 1;

// is_ftlogs_mounted() returns the path to where we should store log files (e.g.,  
// /tmp or /media/FT-LOGS). It also checks if the user has mounted their log drive.
// is_ftlogs_mounted() will return 0/false and print an error message if the 
// user's log drive is not mounted
$root = is_ftlogs_mounted(FALSE);

if (!$root) { 
	// if the user's log drive isn't mounted, don't continue
	$continue = 0;
}
	
// if the user's log drive isn't mounted, don't continue
if ($continue){
	echo '<h1 style="font-size:1.8em">Recording Device Setup (3 of 3)</h1>';
	echo '<h2 style="font-size:1.7em; color:#008000">Saving Device Setup</h2>';

	extract($_POST);
	$have_phones = FALSE;
	$dname = sprintf ("%s/devices.txt",$root);
	if (file_exists($dname)){
		$dfile = fopen($dname,"r");
		$p_line = fgets($dfile);
		while (!feof($dfile)){
			//$the_phones [] = $p_line;
			$pxp = explode(';',$p_line);
			// if the current device is the selected device, get its make and model
			if ($pxp[0] == $selected_device){
				$manufacturer = $pxp[1];
				$model = $pxp[2];
			}
			$p_line = fgets($dfile);
			$have_phones = TRUE;
		}
		fclose($dfile);
	}
			/*
	if (isset($_POST)){
		echo "<br>Start of form items list<br>";
		$keys = array_keys($_POST);
		foreach ($keys as $dongxi){
			printf ("<br>DongXI: %s ",$dongxi);
			printf (" Value: [%s] \n",$_POST[$dongxi]);
			printf ("<br>DongXI: %s (%s)\n",$dongxi,$_POST($dongxi));
		}
			*/
		/*
		echo '<br>DEV: ';
		echo $selected_device;
		echo ' ';
		echo $work_on;
		*/
	/*
	}
	echo "<br>End of form items list<br>";
	*/
	$pname = sprintf("%s_init.txt",$selected_device);
	// try to open $pname
	if ($pfile = fopen($root.'/'.$pname,"w")){
		$keys = array_keys($_POST);
		foreach ($keys as $dongxi){
			/*
			printf ("<br>write DongXI: %s ",$dongxi);
			printf (" Value: [%s] \n",$_POST[$dongxi]);
			*/
			$out = sprintf("%s:%s\n",$dongxi,$_POST[$dongxi]);
			if ($dongxi != 'select' && $dongxi != 'selected_device'){
				fwrite($pfile,sprintf("%s:%s\n",$dongxi,$_POST[$dongxi]));
			}
		}
		fclose ($pfile);
		echo "'".$pname."' written to '".$root."'<br><br>";
		echo "<p><i>Success! ".$manufacturer." ".$model." device setup saved!!</i></p>";
	} else { // couldn't open phone___init.txt to write device setup; fail
		echo "<p><b>Error: <i>".basename($_SERVER['PHP_SELF'])."</i> encountered ";
		echo "an error trying to write to ".$root."/".$pname.". Device ";
		echo "setup COULD NOT be saved.</b></p>";
	}
	
	echo '<p>Click <a href="ft_mdt_select_setup.php">Record Device Setup</a> to record the setup for another device.</p>';
	echo '<p>If you are finished recording the setup of your test devices, click <a href="ft_mdt_test_tool.php">';
	echo 'Mobile Tool Testing</a> to continue to the next step and run tests for your tool.</p>';	
}
 ?>

		</div>
		<div class="push"></div>
	</div>
    <!-- Footer Starts-->
        <?php
     $fn = $_SERVER["SCRIPT_FILENAME"];
          print_footer_contents($fn);
        ?>
    <!-- Footer Ends-->

</div></body></html>
