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