OSDN Git Service

Fixed link error
[opengatem/opengatem.git] / phpsrc / updatemactable.php
1 <html>
2 <head>
3 <title></title>
4 </head>
5 <body>
6
7 <h2>Update Mac Address Registration</h2>
8
9 <?php
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   /************************************************************/
16    
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">');
23     print('</form>');
24     return;
25   }
26   $userId=$_POST['userId'];
27   
28   // setup MySql DB
29   $link = mysqli_connect('localhost', 'root', '');
30   if (!$link) die('Cannot connect DB'.mysqli_error());
31
32   $db_selected = mysqli_select_db($link, 'opengatem');
33   if (!$db_selected) die('cannot select DB'.mysqli_error());
34
35   mysqli_set_charset($link, 'utf8');
36
37   // if data is posted, update DB
38   $i=0;
39   while(isset($_POST['macAddress'][$i])){
40
41     if($_POST['status'][$i]=='D'){
42       // on delete 
43       // UPDATE macaddrs SET status="D",device="postdata",limitdate=now(),mailAddress="postdata"
44       //       WHERE macAddress="postdata" and userId="postdata" and status!="D"
45
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());
51
52     }else if($_POST['status'][$i]=='A'||$_POST['status'][$i]=='I'){
53       // other cases
54       // UPDATE macaddrs SET status="D",device="postdata",limitdate="postdata",mailAddress="postdata"
55       //       WHERE macAddress="postdata" and userId="postdata" and status!="D"
56
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());
62
63     }else{
64       print("<font color=red>Illegal status value</font>");
65     }
66     $i++;
67   }
68
69   // get data from DB to show on web
70   $result = mysqli_query($link, 'SELECT macAddress,status,device,limitDate,mailAddress FROM macaddrs where userId="'
71             .$userId.'"');
72   if (!$result) die('Fail select query'.mysqli_error());
73
74  // print html form
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">');
79
80   // print header
81   print("<table border=1>");
82   print('<tr>');
83   $count=0;
84   while ($field = mysqli_fetch_field($result)) {
85     print('<td>'.$field->name.'</td>');
86     $fieldName[$count]=$field->name;
87     $count++;
88   }
89   print('</tr>');
90
91   // print rows
92   while ($row = mysqli_fetch_row($result)) {
93     print('<tr>');
94     if($row[1]=='D'){  // deleted items
95       for($i=0; $i<$count; $i++){
96         print('<td>'.$row[$i].'</td>');
97       }
98     }else{                   // other items
99       for($i=0; $i<$count; $i++){
100         if($i==0){
101           print('<td><input size=30 type=text name='.$fieldName[$i].'[] value="'.$row[$i].'" readonly></td>');
102         }else{
103           print('<td><input size=30 type=text name='.$fieldName[$i].'[] value="'.$row[$i].'"></td>');
104         }
105       }
106     }
107     print('</tr>');
108   }
109   print('</table>');
110   print('</form>');
111   $close_flag = mysqli_close($link);
112
113 ?>
114 <p>status char: A=Actice, I=InActive, D=Deleted</p>
115 </body>
116 </html>