source: trunk/Mars/datacenter/db/run_comment.php@ 12667

Last change on this file since 12667 was 12667, checked in by Daniela Dorner, 13 years ago
added (webinterface to query, insert and update comments concerning runs)
  • Property svn:executable set to *
File size: 7.1 KB
Line 
1<?php
2{
3 ini_set("display_errors", "On");
4 ini_set("mysql.trace_mode", "On");
5
6 echo (file_get_contents("index-header.html"));
7
8 if (empty($_GET["fMode"]))
9 $_GET["fMode"]="view";
10
11 if (empty($_GET["fFileNumber"]))
12 $_GET["fFileNumber"]="001";
13
14 if (empty($_GET["fRunNumber"]))
15 $_GET["fRunNumber"]=date("Ymd", time()-(12*60*60));
16
17
18
19 //
20 // insert/update part
21 //
22 include ("ldap_include.php");
23 if (strcmp($_GET["fMode"], "insert")==0 || strcmp($_GET["fMode"], "update")==0)
24 {
25 if (!isset($_SERVER['PHP_AUTH_USER']))
26 {
27 header('WWW-Authenticate: Basic realm="Edit Run Comments"');
28 header('HTTP/1.0 401 Unauthorized');
29 return;
30 }
31 else
32 {
33 //echo "The password is not yet evaluated, but the username is inserted into the DB.<br>";
34 if (!CheckUsernameAndPassword($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], GetLDAPOptions()))
35 return;
36 }
37 if (!empty($_GET["fComment"]))
38 {
39 include("db2.php");
40 $db_id = mysql_pconnect($host, $user, $pw);
41 if ($db_id==FALSE)
42 {
43 printf("mysql_connect returned the following error: %s\n", mysql_error());
44 die("");
45 }
46 mysql_select_db($db);
47 //for insert
48 if (strcmp($_GET["fMode"], "insert")==0)
49 $query0 = "INSERT RunComments SET ";
50 //for update
51 if (strcmp($_GET["fMode"], "update")==0)
52 $query0 = "UPDATE RunComments SET ";
53 //for both
54 $query0.= " fComment='".str_replace("'", "\'", $_GET["fComment"])."'";
55 $query0.= ", fUser='".$_SERVER['PHP_AUTH_USER']."'";
56 //for insert
57 if (strcmp($_GET["fMode"], "insert")==0)
58 {
59 $query0.=", fRunNumber=".$_GET["fRunNumber"];
60 $query0.= ", fFileNumber=".$_GET["fFileNumber"];
61 }
62 //for update
63 if (strcmp($_GET["fMode"], "update")==0)
64 {
65 $query2="SELECT fCommentKEY FROM RunComments ";
66 $query2.=" WHERE fRunNumber=".$_GET["fRunNumber"];
67 $query2.=" AND fFileNumber=".$_GET["fFileNumber"];
68 $query2.=" AND fComment='".str_replace("'", "\'", $_GET["fOldComment"])."'";
69 $result2=mysql_query($query2, $db_id);
70 $row2 = mysql_fetch_row($result2);
71 $commentkey=$row2[0];
72 mysql_free_result($result2);
73 $query0.=" WHERE fCommentKEY=".$commentkey;
74 }
75 $result0=mysql_query($query0, $db_id);
76 mysql_close($db_id);
77 }
78 }
79
80
81
82 //
83 // display part
84 //
85 include("db.php");
86 printf("With this page, you can \n");
87 //view mode
88 if (strcmp($_GET["fMode"], "view")==0)
89 printf("view,\n");
90 else
91 printf("<a href='%s'>view</a>,\n", str_replace($_GET["fMode"], 'view', $_SERVER['REQUEST_URI']));
92 //update mode
93 if (strcmp($_GET["fMode"], "update")==0)
94 printf("update and\n");
95 else
96 printf("<a href='%s'>update</a> and \n", str_replace($_GET["fMode"], 'update', $_SERVER['REQUEST_URI']));
97 //insert mode
98 if (strcmp($_GET["fMode"], "insert")==0)
99 printf("insert\n");
100 else
101 printf("<a href='%s'>insert</a> \n", str_replace($_GET["fMode"], 'insert', $_SERVER['REQUEST_URI']));
102 printf("entries in the table <b>RunComment</b> from the DB <b>%s</b>.<br><br>\n", $db);
103
104 //insert field for run number
105 printf("<form action=\"run_comment.php\" METHOD=\"GET\">\n");
106 printf("Run#&nbsp;(YYYYMMDD_FFF)&nbsp;<input name=\"fRunNumber\" type=\"text\" size=\"8\" maxlength=\"8\" value=\"%s\">\n", $_GET["fRunNumber"]);
107 printf("_ <input name=\"fFileNumber\" type=\"text\" size=\"3\" maxlength=\"3\" value=\"%s\">\n", $_GET["fFileNumber"]);
108 printf("<input type='hidden' name='fMode' value='%s'>", $_GET["fMode"]);
109 printf("<input type='submit' value='Get Comments'><br><br>\n");
110 printf("</form>\n");
111
112 $db_id = mysql_pconnect($host, $user, $pw);
113 if ($db_id==FALSE)
114 {
115 printf("mysql_connect returned the following error: %s\n", mysql_error());
116 die("");
117 }
118 mysql_select_db($db);
119
120 $query1 = "SELECT CONCAT(fRunNumber,'_', LPAD(fFileNumber, 3, 0)), fComment FROM RunComments ";
121 $query1 .= "WHERE fRunNumber=".$_GET["fRunNumber"]." AND fFileNumber=".$_GET["fFileNumber"];
122 $result1=mysql_query($query1, $db_id);
123 printf("Found %d comment(s).<br>", mysql_num_rows($result1));
124 printf("<table BORDER='0' style='margin-top:1ex'>");
125 $col = FALSE;
126 printf("<tr BGCOLOR='#C0C0C0'><td>Run#</td><td>Comment</td></tr>");
127 while ($row1 = mysql_fetch_row($result1))
128 {
129 if (!$col)
130 printf("<tr BGCOLOR='#E0E0E0'>\n");
131 else
132 printf("<tr BGCOLOR='#D0D0D0'>\n");
133 $col = !$col;
134
135 if (strcmp($_GET["fMode"], "update")==0)
136 printf("<form style='display:inline' action=\"run_comment.php\" METHOD=\"GET\">\n");
137 printf("<td>\n%s\n</td>\n", $row1[0]);
138 if (strcmp($_GET["fMode"], "update")==0)
139 {
140 printf("<td>\n");
141 printf("<input type='text' size='50' maxlength='255' name='fComment' value='%s'>\n", htmlspecialchars($row1[1],ENT_QUOTES));
142 printf("<input type='hidden' name='fOldComment' value='%s'>\n", htmlspecialchars($row1[1],ENT_QUOTES));
143 printf("<input type='hidden' name='fMode' value='%s'>\n", $_GET["fMode"]);
144 printf("<input type='hidden' name='fRunNumber' value='%s'>\n", $_GET["fRunNumber"]);
145 printf("<input type='hidden' name='fFileNumber' value='%s'>\n", $_GET["fFileNumber"]);
146 printf("<input type='submit' value='Update Comment'>\n");
147 printf("</td>\n");
148 printf("</form>\n");
149 }
150 else
151 printf("<td>\n%s\n</td>\n", $row1[1]);
152 printf("</tr>\n");
153 }
154 //insert mode
155 if (strcmp($_GET["fMode"], "insert")==0)
156 {
157 printf("<tr BGCOLOR='#C0C0C0'>");
158 printf("<td>%s_%s</td>\n", $_GET["fRunNumber"], $_GET["fFileNumber"]);
159 printf("<td>\n");
160 printf("<form style='display:inline' action=\"run_comment.php\" METHOD=\"GET\">\n");
161 printf("<input type='text' size='50' maxlength='255' name='fComment'>\n");
162 printf("<input type='hidden' name='fMode' value='%s'>\n", $_GET["fMode"]);
163 printf("<input type='hidden' name='fRunNumber' value='%s'>\n", $_GET["fRunNumber"]);
164 printf("<input type='hidden' name='fFileNumber' value='%s'>\n", $_GET["fFileNumber"]);
165 printf("<input type='submit' value='Insert Comment'>\n");
166 printf("</form>\n");
167 printf("</td>\n");
168 printf("</tr>\n");
169 }
170 printf("</table>");
171
172 if (strcmp($_GET["fMode"], "update")==0)
173 printf("Remark: You can update only one comment at once.");
174
175 mysql_free_result($result1);
176 mysql_close($db_id);
177
178 echo (file_get_contents("index-footer.html"));
179
180 ini_set("display_errors", "Off");
181 ini_set("mysql.trace_mode", "Off");
182}
183?>
Note: See TracBrowser for help on using the repository browser.