OSDN Git Service

Ver.0.8.1
[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   // check basic auth 
12   if(getenv('REMOTE_USER')=='')  die('Cannot get auth');
13
14   // set default values
15   $userId=$device='%';
16   $now=date('Y-m-d H:i:s');
17   $fromTime=date('Y-m-d H:i:s', strtotime($now." -3 day"));
18   $toTime=$now;
19
20   // get request data
21   if(isset($_GET['userId']))$userId=$_GET['userId'];
22   if(isset($_GET['device']))$device=$_GET['device'];
23   if(isset($_GET['fromTime']))$fromTime=$_GET['fromTime'];
24   if(isset($_GET['toTime']))$toTime=$_GET['toTime'];
25
26   // show html table for query parameters
27   print("<p><table>");
28   print("<form method=GET action=showlog.php");
29   print("<tr><td>UserId</td><td><input size=30 type=text name=userId value='".$userId."'></td></tr>");
30   print("<tr><td>Device</td><td><input size=30 type=text name=device value='".$device."'></td></tr>");
31   print("<tr><td>FromTime</td><td><input size=30 type=text name=fromTime value='".$fromTime."'></td></tr>");
32   print("<tr><td>ToTime</td><td><input size=30 type=text name=toTime value='".$toTime."'></td></tr>");
33   print("<tr><td></td><td><input type=submit value='send'></td></tr>");
34   print("</table></p>");
35
36   // connect and access to MySql db
37   $link = mysql_connect('localhost', 'root', '');
38   if (!$link) die('Cannot connet to DB'.mysql_error());
39
40   $db_selected = mysql_select_db('opengatem', $link);
41   if (!$db_selected) die('Cannot select DB'.mysql_error());
42
43   mysql_set_charset('utf8');
44
45   $result = mysql_query('SELECT * FROM sessionview where userId like "'.$userId.'" and device like "'.$device.'" and "'.$fromTime.'"<openTime and openTime<"'.$toTime.'"');
46
47   if (!$result) die('Fail query'.mysql_error());
48
49   // show header line
50   print("<table border=1>");
51   print('<tr>');
52   $count=0;
53   while ($field = mysql_fetch_field($result)) {
54     print('<td>'.$field->name.'</td>');
55     $count++;
56   }
57   print('</tr>');
58
59   // show rows
60   while ($row = mysql_fetch_row($result)) {
61     print('<tr>');
62     for($i=0; $i<$count; $i++){
63       print('<td>'.$row[$i].'</td>');
64     }
65     print('</tr>');
66   }
67
68   print("</table>");
69   $close_flag = mysql_close($link);
70
71 ?>
72
73 </body>
74 </html>