OSDN Git Service

Fixed CLang warning messages and other
[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   // if userid is not set, request input and return
12   if(!isset($_POST['userId'])){
13     print('<form method=POST action=updatemactable.php>');
14     print('UserId:<input type=text name=userId>');
15     print('<input type=submit value="Send">');
16     print('<input type=reset value="Reset">');
17     print('</form>');
18     return;
19   }
20   $userId=$_POST['userId'];
21   
22   // setup MySql DB
23   $link = mysqli_connect('localhost', 'root', '');
24   if (!$link) die('Cannot connect DB'.mysqli_error());
25
26   $db_selected = mysqli_select_db($link, 'opengatem');
27   if (!$db_selected) die('cannot select DB'.mysqli_error());
28
29   mysqli_set_charset($link, 'utf8');
30
31   // if data is posted, update DB
32   $i=0;
33   while(isset($_POST['macAddress'][$i])){
34
35     if($_POST['status'][$i]=='D'){
36       // on delete 
37       // UPDATE macaddrs SET status="D",device="postdata",limitdate=now(),mailAddress="postdata"
38       //       WHERE macAddress="postdata" and userId="postdata" and status!="D"
39
40       $result = mysqli_query($link, 'UPDATE macaddrs SET status="'.$_POST['status'][$i]
41               .'", device="'.$_POST['device'][$i].'", limitDate=now()'
42               .', mailAddress="'.$_POST['mailAddress'][$i].'" WHERE macAddress="'
43               .$_POST['macAddress'][$i].'" and userId="'.$userId.'" and status!="D"');
44       if (!$result) die('Fail update query'.mysqli_error());
45
46     }else if($_POST['status'][$i]=='A'||$_POST['status'][$i]=='I'){
47       // other cases
48       // UPDATE macaddrs SET status="D",device="postdata",limitdate="postdata",mailAddress="postdata"
49       //       WHERE macAddress="postdata" and userId="postdata" and status!="D"
50
51       $result = mysqli_query($link, 'UPDATE macaddrs SET status="'.$_POST['status'][$i]
52               .'", device="'.$_POST['device'][$i].'", limitDate="'.$_POST['limitDate'][$i]
53               .'", mailAddress="'.$_POST['mailAddress'][$i].'" WHERE macAddress="'
54               .$_POST['macAddress'][$i].'" and userId="'.$userId.'" and status!="D"');
55       if (!$result) die('Fail update query'.mysqli_error());
56
57     }else{
58       print("<font color=red>Illegal status value</font>");
59     }
60     $i++;
61   }
62
63   // get data from DB to show on web
64   $result = mysqli_query($link, 'SELECT macAddress,status,device,limitDate,mailAddress FROM macaddrs where userId="'
65             .$userId.'"');
66   if (!$result) die('Fail select query'.mysqli_error());
67
68  // print html form
69   print('<form method=POST action=updatemac.php>');
70   print('UserId:<input type=text name=userId value="'.$userId.'">');
71   print('<input type=submit value="Send">');
72   print('<input type=reset value="Reset">');
73
74   // print header
75   print("<table border=1>");
76   print('<tr>');
77   $count=0;
78   while ($field = mysqli_fetch_field($result)) {
79     print('<td>'.$field->name.'</td>');
80     $fieldName[$count]=$field->name;
81     $count++;
82   }
83   print('</tr>');
84
85   // print rows
86   while ($row = mysqli_fetch_row($result)) {
87     print('<tr>');
88     if($row[1]=='D'){  // deleted items
89       for($i=0; $i<$count; $i++){
90         print('<td>'.$row[$i].'</td>');
91       }
92     }else{                   // other items
93       for($i=0; $i<$count; $i++){
94         if($i==0){
95           print('<td><input size=30 type=text name='.$fieldName[$i].'[] value="'.$row[$i].'" readonly></td>');
96         }else{
97           print('<td><input size=30 type=text name='.$fieldName[$i].'[] value="'.$row[$i].'"></td>');
98         }
99       }
100     }
101     print('</tr>');
102   }
103   print('</table>');
104   print('</form>');
105   $close_flag = mysqli_close($link);
106
107 ?>
108 <p>status char: A=Actice, I=InActive, D=Deleted</p>
109 </body>
110 </html>