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

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