7 <h2>Update Mac Address Registration</h2>
10 /************************************************************/
11 // Modify the MAC address registration in the management database
12 // the database connection parameters might be modified.
13 // As this script should be used only by the administrators,
14 // it should be protected by some access control method.
15 /************************************************************/
17 // if userid is not set, request input and return
18 if(!isset($_POST['userId'])){
19 print('<form method=POST action=updatemactable.php>');
20 print('UserId:<input type=text name=userId>');
21 print('<input type=submit value="Send">');
22 print('<input type=reset value="Reset">');
26 $userId=$_POST['userId'];
29 $link = mysqli_connect('localhost', 'root', '');
30 if (!$link) die('Cannot connect DB'.mysqli_error());
32 $db_selected = mysqli_select_db($link, 'opengatem');
33 if (!$db_selected) die('cannot select DB'.mysqli_error());
35 mysqli_set_charset($link, 'utf8');
37 // if data is posted, update DB
39 while(isset($_POST['macAddress'][$i])){
41 if($_POST['status'][$i]=='D'){
43 // UPDATE macaddrs SET status="D",device="postdata",limitdate=now(),mailAddress="postdata"
44 // WHERE macAddress="postdata" and userId="postdata" and status!="D"
46 $result = mysqli_query($link, 'UPDATE macaddrs SET status="'.$_POST['status'][$i]
47 .'", device="'.$_POST['device'][$i].'", limitDate=now()'
48 .', mailAddress="'.$_POST['mailAddress'][$i].'" WHERE macAddress="'
49 .$_POST['macAddress'][$i].'" and userId="'.$userId.'" and status!="D"');
50 if (!$result) die('Fail update query'.mysqli_error());
52 }else if($_POST['status'][$i]=='A'||$_POST['status'][$i]=='I'){
54 // UPDATE macaddrs SET status="D",device="postdata",limitdate="postdata",mailAddress="postdata"
55 // WHERE macAddress="postdata" and userId="postdata" and status!="D"
57 $result = mysqli_query($link, 'UPDATE macaddrs SET status="'.$_POST['status'][$i]
58 .'", device="'.$_POST['device'][$i].'", limitDate="'.$_POST['limitDate'][$i]
59 .'", mailAddress="'.$_POST['mailAddress'][$i].'" WHERE macAddress="'
60 .$_POST['macAddress'][$i].'" and userId="'.$userId.'" and status!="D"');
61 if (!$result) die('Fail update query'.mysqli_error());
64 print("<font color=red>Illegal status value</font>");
69 // get data from DB to show on web
70 $result = mysqli_query($link, 'SELECT macAddress,status,device,limitDate,mailAddress FROM macaddrs where userId="'
72 if (!$result) die('Fail select query'.mysqli_error());
75 print('<form method=POST action=updatemac.php>');
76 print('UserId:<input type=text name=userId value="'.$userId.'">');
77 print('<input type=submit value="Send">');
78 print('<input type=reset value="Reset">');
81 print("<table border=1>");
84 while ($field = mysqli_fetch_field($result)) {
85 print('<td>'.$field->name.'</td>');
86 $fieldName[$count]=$field->name;
92 while ($row = mysqli_fetch_row($result)) {
94 if($row[1]=='D'){ // deleted items
95 for($i=0; $i<$count; $i++){
96 print('<td>'.$row[$i].'</td>');
99 for($i=0; $i<$count; $i++){
101 print('<td><input size=30 type=text name='.$fieldName[$i].'[] value="'.$row[$i].'" readonly></td>');
103 print('<td><input size=30 type=text name='.$fieldName[$i].'[] value="'.$row[$i].'"></td>');
111 $close_flag = mysqli_close($link);
114 <p>status char: A=Actice, I=InActive, D=Deleted</p>