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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" src="func.js"></script>
</head>
<?php
include ('includes/header.html');
?>
<?php
if (isset($_POST['submit'])) {
require_once ('../mysqli_connect.php');
$table=array_map('trim', $_POST);
$errors=array();
$result = array();
foreach ($table as $key => $i){
$output=array();
$output=explode("_", $key);
if ($output[0] == 'fname') {
$result[]=$output[1];
}
}
echo '<form method="POST" action="func.php">';
//print_r($result);
echo '<table align="center" border = "2" cellspacing ="0" cellpadding="3" id="table">
<tr>
<td><b>Functionality Name:</b></td>
<td><b>Description:</b></td>
<td><b>Status:</b></td>
<td><input type="button" Name= "Ajouter" Value="Add Functionality" onclick="go()"></td>
</tr>';
foreach ($result as $j) {
$fn='fname_' . $j;
$fd='fdescription_' . $j;
$fs='fstatus_' . $j;
echo'<tr>';
echo '<td><input type="text" name="' . $fn . '" size="20" maxlength="50"';
if (isset($table[$fn])){
echo 'value="' . $table[$fn] . '"></td>';
}
else {
echo 'value=""></td>';
}
echo '<td><textarea rows="4" cols="30" name="' . $fd . '">';
if (isset($table[$fd])){
echo $table[$fd];
echo'</textarea></td>';
}
else {
echo '</textarea></td>';
}
// Retrieve all the statuses of a functionality...
echo '<td><select name="' . $fs . '">';
$q = "SELECT F_status_ID, Functionality_status FROM fstatuses ORDER BY F_status_ID ASC";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) > 0) {
while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) {
$selected = (isset($table[$fs]) and $table[$fs] == $menu_row[0])?'selected="selected"':'';
echo '<option value="' .$menu_row[0]. '" '.$selected.'> ' . $menu_row[1] . '</option>\n';
}
}
echo '</select></td>';
mysqli_free_result($r);
unset($menu_row);
echo '<td align="center" valign="center"><input type="button" value="Delete" onclick="delRow(this)"></td>';
echo '</tr>';
}
echo '</table>';
echo '<p><input type="submit" name="submit" value="Enter"></p>';
echo '</form>';
echo '<script>update_globale()</script>';
$i=0;
foreach ($result as $k) {
$i++;
$fnk='fname_' . $k;
if (empty($table[$fnk])) {
$errors[]= 'The row number ' . $i .' is empty';
}
}
if (empty($errors)){
$errors_query=array();
foreach ($result as $m){
$fnm=$table['fname_' . $m];
$fdm=$table['fdescription_' . $m];
$fsm=$table['fstatus_' . $m];
$itemID=1;
$q = "INSERT INTO functionalities (F_name, F_description, Item_ID, F_status_ID) VALUES ('$fnm', '$fdm', '$itemID', '$fsm')";
$r = mysqli_query ($dbc, $q);
if (mysqli_affected_rows($dbc) != 1) { // KO
$errors_query[]= trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
}
}
if (empty($errors_query)){ // all rows were sucessfully inserted
echo '<p>your data have been entered in the database</p>';
}
else { // KO
echo '<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';
}
}
else {
echo '<h1>Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) {
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p>';
}
}
else {
?>
<form method="POST" action="func.php">
<table align="center" border = "2" cellspacing ="0" cellpadding="3" id="table">
<tr><td><b>Functionality Name:</b></td> <td><b>Description:</b></td> <td><b>Status:</b></td> <td><input type="button" Name= "Ajouter" Value="Add Functionality" onclick="go()"></td></tr>
</table>
<p><input type="submit" name="submit" value="Enter"></p>
</form>
<?php
}
?>
</body>
</html> |
Partager