1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| <?php
// securité : echappement des caractères spéciaux
$hsc = function ($p) { return htmlspecialchars($p, ENT_QUOTES); };
$hasDut = (isset($_POST['dut_serialnumber']) && ctype_digit($_POST['dut_serialnumber']));
$hasDate = (isset($_POST['date_start']) && date_create($_POST['date_start']));
$hideData_dates = true;
$hideData_tests = true;
$selectedDut = null;
$selectedDate = null;
// si hasDut et hasDate -> on renvoie le formulaire et la liste des tests effectués
// si hasDut -> on renvoie le formulaire et la liste des date disponibles
if ($hasDut) {
$selectedDut = $_POST['dut_serialnumber'];
$dataDates = array('2011-12-01 17:54', '2011-11-01 10:00', '2011-10-01 07:54');
//$sql = 'SELECT date_start FROM dut_test_data WHERE dut_serialnumber='.$_POST['dut_serialnumber'];
//$dataDates = mysql_query($sql);
$hideData_dates = ( ! $dataDates); // au cas oà la requête planterait on affiche pas la zone de liste
}
if (( ! $hideData_dates) && $hasDate) {
$selectedDate = $_POST['date_start'];
}
if ($selectedDut && $selectedDate) {
$sql = <<<SQL
SELECT
test_name,
test_description,
test_frequency,
test_octopack_slot,
test_octopack_channel,
test_phase,
test_value,
test_limitlow,
test_limithigh,
test_result,
test_unit
FROM
dut_test_data
WHERE
test_date = '$selectedDate'
SQL;
//$dataTests = mysql_query($ql);
$dataTests = array(array_fill(0, 11, 'test1'), array_fill(0, 11, 'test2'), array_fill(0, 11, 'test3'));
$hideData_tests = ( ! $dataTests); // au cas oà la requête planterait on affiche pas la table
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="site1.css" />
<title>Demonstration N�2</title>
</head>
<style type="text/css">
h1 { text-align: center; font-weight: bold; border-width: 12px; border-color: grey; border-style: inset; padding: 5px; }
h3 { text-decoration: underline; }
table { border: 5px; }
</style>
<body>
<h1>Exploitation de la base de donnees TX_RACK</h1>
<h3>Choisir le dut_serial_number afin d'afficher les dates des tests r�alis�s :</h3>
<form method="post" action="test.php">
<label for="dut_serialnumber">Entrez le dut_serialnumber : </label>
<input id="dut_serialnumber" type="number" name="dut_serialnumber" required="required" value="<?php echo $selectedDut; ?>" />
<?php if ( ! $hideData_dates): ?>
<label for="listeDates">Dates : </label>
<select id="listeDates" name="date_start">
<?php foreach($dataDates as $row):
$isSelected = ($row === $selectedDate) ? ' selected="selected"' : null; ?>
<option value="<?php echo $hsc($row); ?>"<?php echo $isSelected; ?>><?php echo $hsc($row); ?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>
<input type="submit" value="Envoyer" />
</form>
<?php if ( ! $hideData_tests): ?>
<table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Frequency</th>
<th>Slot</th>
<th>Channel</th>
<th>Phase</th>
<th>Value</th>
<th>Limit low</th>
<th>Limit high</th>
<th>Result</th>
<th>Unit</th>
</tr>
</thead>
<tbody>
<?php foreach($dataTests as $row): ?>
<tr>
<td><?php echo $hsc($row[0]); ?></td>
<td><?php echo $hsc($row[1]); ?></td>
<td><?php echo $hsc($row[2]); ?></td>
<td><?php echo $hsc($row[3]); ?></td>
<td><?php echo $hsc($row[4]); ?></td>
<td><?php echo $hsc($row[5]); ?></td>
<td><?php echo $hsc($row[6]); ?></td>
<td><?php echo $hsc($row[7]); ?></td>
<td><?php echo $hsc($row[8]); ?></td>
<td><?php echo $hsc($row[9]); ?></td>
<td><?php echo $hsc($row[10]); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</body>
</html> |
Partager