OSDN Git Service

modified comments
[opengatem/opengatem.git] / phpsrc / showlog.php
1 <html>
2 <head>
3 <title></title>
4 </head>
5 <body>
6
7 <h2>Show Log</h2>
8
9 <?php
10   /************************************************************/
11   // show the opengatem usage log in the web page.
12   // the query condition is acquired from the html input from.
13   // default is as follows: any user, any device, last 3 days 
14   // database connecttion parameters might be modified.
15   // As this script should be used only by the administrators, 
16   // it should be protected by some access control method.
17   /************************************************************/
18
19   // set default values
20   $userId=$device='%';
21   $now=date('Y-m-d H:i:s');
22   $fromTime=date('Y-m-d H:i:s', strtotime($now." -3 day"));
23   $toTime=$now;
24
25   // get request data
26   if(isset($_GET['userId']))$userId=$_GET['userId'];
27   if(isset($_GET['device']))$device=$_GET['device'];
28   if(isset($_GET['fromTime']))$fromTime=$_GET['fromTime'];
29   if(isset($_GET['toTime']))$toTime=$_GET['toTime'];
30
31   // show html table for query parameters
32   print("<p><table>");
33   print("<form method=GET action=showlog.php");
34   print("<tr><td>UserId</td><td><input size=30 type=text name=userId value='".$userId."'></td></tr>");
35   print("<tr><td>Device</td><td><input size=30 type=text name=device value='".$device."'></td></tr>");
36   print("<tr><td>FromTime</td><td><input size=30 type=text name=fromTime value='".$fromTime."'></td></tr>");
37   print("<tr><td>ToTime</td><td><input size=30 type=text name=toTime value='".$toTime."'></td></tr>");
38   print("<tr><td></td><td><input type=submit value='send'></td></tr>");
39   print("</table></p>");
40
41   // connect and access to MySql db
42   $link = mysqli_connect('localhost', 'root', '');
43   if (!$link) die('Cannot connet to DB'.mysqli_error());
44
45   $db_selected = mysqli_select_db($link, 'opengatem');
46   if (!$db_selected) die('Cannot select DB'.mysqli_error());
47
48   mysqli_set_charset($link, 'utf8');
49
50   $result = mysqli_query($link, 'SELECT * FROM sessionview where userId like "'.$userId.'" and device like "'.$device.'" and "'.$fromTime.'"<openTime and openTime<"'.$toTime.'"');
51
52   if (!$result) die('Fail query'.mysqli_error());
53
54   // show header line
55   print("<table border=1>");
56   print('<tr>');
57   $count=0;
58   while ($field = mysqli_fetch_field($result)) {
59     print('<td>'.$field->name.'</td>');
60     $count++;
61   }
62   print('</tr>');
63
64   // show rows
65   while ($row = mysqli_fetch_row($result)) {
66     print('<tr>');
67     for($i=0; $i<$count; $i++){
68       print('<td>'.$row[$i].'</td>');
69     }
70     print('</tr>');
71   }
72
73   print("</table>");
74   $close_flag = mysqli_close($link);
75
76 ?>
77
78 </body>
79 </html>