source: trunk/Mars/datacenter/db/resetseq.php@ 18564

Last change on this file since 18564 was 17386, checked in by tbretz, 11 years ago
Removed svn:executable property, these are no executables.
File size: 12.2 KB
Line 
1<?php
2{
3 function PrintPage($host, $user, $pw, $db)
4 {
5 $db_id = mysql_connect($host, $user, $pw);
6 if ($db_id==FALSE)
7 {
8 printf("mysql_connect returned the following error: %s\n", mysql_error());
9 die("");
10 }
11 mysql_select_db($db);
12
13 $query1="SELECT fMarsVersionName, fStartDate FROM MarsVersion ORDER BY fMarsVersion DESC LIMIT 0,1";
14 $marsresult=mysql_query($query1);
15 $row = mysql_fetch_row($marsresult);
16 $mars=$row[0];
17 $date=$row[1];
18 if (mysql_errno()>0)
19 printf("&nbsp; Error-Number: %s <br>", mysql_errno());
20 if (mysql_error()!="")
21 printf("&nbsp; Error-Message: %s <br>", mysql_error());
22 if (mysql_info()!="")
23 printf("&nbsp; Mysql-Info: %s <br>", mysql_info());
24 mysql_free_result($marsresult);
25 if (empty($mars))
26 {
27 printf("Could not get information for latest Mars version from the database.");
28 return;
29 }
30
31 if (empty($_GET["insert"]))
32 {
33 $query0 = "SELECT SequenceProcessStatus.fSequenceFirst, ";
34// $query0 .= "if (fCallisto " . " < '" . $date . "', 'to be resetted', ";
35 $query0 .= "if (fCallisto " . " < '" . $date . "', CONCAT('outdated (', (SELECT fMarsVersionName FROM MarsVersion WHERE fCallisto > fStartDate ORDER BY fMarsVersion DESC LIMIT 0,1), ')'), ";
36 $query0 .= "if (not isnull(fCallisto), 'up to date (" . $mars . ")', ";
37 $query0 .= "if (fStartTime > ADDDATE(Now(), INTERVAL -1 DAY) AND isnull(fFailedTime), 'running (" . $mars . ")',";
38 $query0 .= "if (isnull(fFailedTime), 'already resetted', ";
39 $query0 .= " 'crashed or failed')))) as 'calstat', ";
40// $query0 .= "if (fStar " . " < '" . $date . "', 'to be resetted', ";
41 $query0 .= "if (fStar " . " < '" . $date . "', CONCAT('outdated (', (SELECT fMarsVersionName FROM MarsVersion WHERE fStar > fStartDate ORDER BY fMarsVersion DESC LIMIT 0,1), ')'), ";
42 $query0 .= "if (not isnull(fStar), 'up to date (" . $mars . ")', ";
43 $query0 .= "if (fStartTime > ADDDATE(Now(), INTERVAL -1 DAY) AND isnull(fFailedTime) AND not isnull(fCallisto), 'running (" . $mars . ")',";
44 $query0 .= "if (isnull(fFailedTime), 'already resetted', ";
45 $query0 .= " 'crashed or failed')))) as 'starstat', fProjectName, fRunStart ";
46 $query0 .= "FROM SequenceProcessStatus ";
47 $query0 .= "LEFT JOIN Sequences USING(fSequenceFirst,fTelescopeNumber) ";
48 $query0 .= "LEFT JOIN Project USING(fProjectKEY) ";
49 }
50 else
51 {
52 $query0 = "UPDATE SequenceProcessStatus SET ";
53 if ($_GET["step"]=="callisto")
54 $query0 .="fCallisto=NULL, fFillCallisto=NULL, fStar=NULL, fFillStar=NULL, ";
55 else
56 if ($_GET["step"]=="star")
57 $query0 .="fStar=NULL, fFillStar=NULL, ";
58 $query0 .="fStartTime=NULL, fFailedTime=NULL, fProgramId=NULL, fReturnCode=NULL ";
59
60 if ($_GET["step"]=="callisto")
61 $query0 .= " WHERE fCallisto " . " < '" . $date . "'";
62 else
63 if ($_GET["step"]=="star")
64 $query0 .= " WHERE fStar " . " < '" . $date . "'";
65 else
66 $query0 .= " WHERE (NOT ISNULL(fFailedTime) OR fStartTime < ADDDATE(Now(), INTERVAL -1 DAY))";
67 }
68 if (ereg("^([ ]*[0-9]{5,8}[ ]*[,])*[ ]*[0-9]{5,8}[ ]*$",$_GET["Seqs"]))
69 {
70 if (strpos($query0, " WHERE ")==FALSE || (strpos($query0, " CONCAT(")==TRUE && strpos($query0, " WHERE ")==TRUE))
71 $query0 .= " WHERE ";
72 else
73 $query0 .= " AND ";
74 $query0 .=" SequenceProcessStatus.fSequenceFirst IN (" . $_GET["Seqs"] . ")";
75 }
76 else
77 {
78 echo "You have to give the sequences, which you want to reset, in the correct format, i.e. sequence numbers separated by ','.<br>";
79 return;
80 }
81 if (empty($_GET["step"]))
82 {
83 echo "Please choose what you want to reset: <br>";
84 echo "crashed processes (i.e. running longer than 1 day or failed), callisto or star.<br>";
85 return;
86 }
87
88 $result0=mysql_query($query0);
89 if (mysql_errno()>0)
90 printf("&nbsp; Errorno: %s <br>", mysql_errno());
91 if (mysql_error()!="")
92 printf("&nbsp; Errormsg: %s <br>", mysql_error());
93 if (!empty($_GET["insert"]) && !empty($_GET["step"]))
94 {
95 printf("%s Sequences have been resetted. <br><br>\n", mysql_affected_rows());
96 if (mysql_info()!="")
97 printf("Mysql-Info: %s <br><br>\n", mysql_info());
98 }
99 else
100 {
101 if (mysql_affected_rows()==0)
102 {
103 echo "No sequence to reset.<br>";
104 echo "The sequences you listed are already resetted.<br>";
105 mysql_free_result($result0);
106 return;
107 }
108// echo "The status of the sequences you entered: <br>\n";
109 $star="";
110 $callisto="";
111 $crashed="";
112 $calcolor='black';
113 $starcolor='black';
114 $style='normal';
115 $col = FALSE;
116 $bgcolor='#C0C0C0';
117 $checked=0;
118 printf("<table border='0' align='center'>\n");
119 printf("<tr bgcolor='%s'>\n<th style='padding-left:1ex;padding-right:1ex'>\n<u>Sequence</u>\n</th>\n", $bgcolor);
120 printf("\n<th>\n<u>ProjectName</u>\n</th>\n");
121 printf("<th>\n<u>Status Callisto</u>\n</th>");
122 printf("\n<th>\n<u>Status Star</u>\n</th>\n");
123 printf("\n<th>\n<u>Starttime</u>\n</th>\n");
124 printf("</tr>\n");
125 while ($row = mysql_fetch_row($result0))
126 {
127 if (ereg('outdated', $row[2]) && $_GET["step"]=='star')
128 {
129 $star[]=$row[0];
130 $starcolor='green';
131 $style='bold';
132 $row[2]=str_replace('outdated', 'marked for reset', $row[2]);
133 }
134 if (ereg('outdated', $row[1]) && $_GET["step"]=='callisto')
135 {
136 $callisto[]=$row[0];
137 $calcolor='green';
138 $starcolor='green';
139 $style='bold';
140 }
141 if (($row[1]=='crashed or failed' || $row[2]=='crashed or failed') && $_GET["step"]=='crashed')
142 {
143 $crashed[]=$row[0];
144 if ($row[1]=='crashed or failed')
145 {
146 $calcolor='green';
147 $style='bold';
148 }
149 else
150 {
151 $starcolor='green';
152 $style='bold';
153 }
154 }
155 if (!$col)
156 $bgcolor='#E0E0E0';
157 else
158 $bgcolor='#D0D0D0';
159 $col = !$col;
160 printf("<tr bgcolor='%s'>\n<td align='center' style='font-weight:%s'>\n%s \n</td>\n", $bgcolor, $style, $row[0]);
161 printf("<td style='padding-left:1ex;padding-right:1ex'>\n %s \n</td>\n", $row[3]);
162 printf("<td style='padding-left:1ex;padding-right:1ex'>\n <font color='%s'>%s </font>\n</td>\n", $calcolor, $row[1]);
163 printf("<td style='padding-left:1ex;padding-right:1ex'>\n <font color='%s'>%s </font>\n</td>\n", $starcolor, $row[2]);
164 printf("<td style='padding-left:1ex;padding-right:1ex'>\n %s \n</td>\n", $row[4]);
165 printf("</tr>\n");
166 $calcolor='black';
167 $starcolor='black';
168 $style='normal';
169 $checked+=1;
170 }
171 printf("</table>\n");
172
173 if ($_GET["step"]=="crashed")
174 printf("<br>\n You chose to reset only the sequences which are crashed or failed.<br>\n");
175 else
176 printf("<br>\n Only the sequences which are not 'up to date', 'running' or 'resetted', can be resetted.<br>\n");
177 if (empty($star) && empty($callisto) && empty($crashed))
178 echo "With your choice no sequences would be resetted.";
179 else
180 echo "With your choice the following sequences would be resetted:\n ";
181 $marked=0;
182 if (!empty($star))
183 {
184 foreach($star as $num => $seq)
185 echo $seq . " ";
186 $marked+=count($star);
187 }
188 if (!empty($callisto))
189 {
190 foreach($callisto as $num => $seq)
191 echo $seq . " ";
192 $marked+=count($callisto);
193 }
194 if (!empty($crashed))
195 {
196 foreach($crashed as $num => $seq)
197 echo $seq . " ";
198 $marked+=count($crashed);
199 }
200 printf("<br>\n Listed: %d <br> Marked: %d", $checked, $marked);
201 printf("<br>\n<br>\nTo <b>reset</b> the <font color='green'>green marked entries</font>, please press the button 'Reset Sequences'.<br><br>\n");
202
203 mysql_free_result($result0);
204 printf("<input type='button' value='Reset Sequences' onClick='self.location.href=\"%s&amp;insert=On\"'>&nbsp;&nbsp;&nbsp;\n", htmlspecialchars($_SERVER["REQUEST_URI"]));
205
206 }
207 mysql_close($db_id);
208
209// PrintSubmittedQuery($query0, "1", $db, "old");
210
211 }
212
213 include ("include.php");
214 include ("menu.php");
215 include ("db.php");
216 include ("magicdefs.php");
217
218 ini_set("display_errors", "On");
219 ini_set("mysql.trace_mode", "On");
220
221 echo (file_get_contents("index-header.html"));
222
223 $ips=array("132.187.47.10", //Thomas
224 "129.194.169.21" //Dani ISDC
225 );
226 if (!in_array($_SERVER['REMOTE_ADDR'], $ips))
227 {
228 echo "You are not allowed to reset sequences.<br>";
229 echo "If you want to reset your sequences in the automatic analysis, please contact Daniela Dorner.<br>";
230 echo (file_get_contents("index-footer.html"));
231 return;
232 }
233
234 $environment = sizeof($_GET);
235
236 //init
237 if (empty($_GET["Seqs"]))
238 $_GET["Seqs"]="";
239 if (empty($_GET["step"]))
240 $_GET["step"]="";
241
242 //print form
243 printf("<center>\n");
244 printf("<form action=\"resetseq.php\" METHOD=\"GET\">\n");
245
246 printf("<input type='radio' name='step' value='crashed' %s> crashed processes &nbsp;", $_GET["step"]=="crashed" ? "checked" : "");
247 printf("<input type='radio' name='step' value='callisto' %s> callisto &nbsp;", $_GET["step"]=="callisto" ? "checked" : "");
248 printf("<input type='radio' name='step' value='star' %s> star<br>", $_GET["step"]=="star" ? "checked" : "");
249
250 printf("<table>\n<tr>\n<td align='left'>\nSequences: \n</td>\n</tr>\n<tr>\n<td>\n");
251 printf("<input name='Seqs' type='text' size='80' maxlength='300' value='%s'>\n</td>\n</tr>\n</table>\n<br>\n", $_GET["Seqs"]);
252
253 ini_set("mysql.trace_mode", "Off");
254// ini_set("display_errors", "Off");
255
256 printf("<input type='submit' value='Check Sequence Status'>&nbsp;&nbsp;&nbsp;\n");
257 printf("<input class='Width' type='button' value='Clear Form' onClick='self.location.href=\"resetseq.php\"'>&nbsp;&nbsp;&nbsp;\n");
258// if (!empty($_GET["step"]) && ereg("^([ ]*[0-9]{5,8}[ ]*[,])*[ ]*[0-9]{5,8}[ ]*$",$_GET["Seqs"]))
259// printf("<input type='checkbox' name='insert' value='On'>insert\n");
260 printf("<br>\n");
261 printf("</form>\n");
262 printf("</center>\n");
263 printf("</td>\n</tr>\n");
264 printf("<tr class='Block'>\n<td>\n");
265
266 if ($environment==0)
267 {
268 printf("No query submitted yet.<br>\n");
269 printf("To reset sequences, please insert them in the following format: <i>12345,87654321</i><br>\n");
270 printf("and choose whether you want to reset just crashed processes, callisto (this includes star) or just star.<br>\n");
271 printf("You can enter up to 300 characters in the sequences field.<br>\n");
272 }
273 else
274 PrintPage($host, $user, $pw, $db);
275
276 echo (file_get_contents("index-footer.html"));
277
278 ini_set("display_errors", "Off");
279 ini_set("mysql.trace_mode", "Off");
280}
281?>
Note: See TracBrowser for help on using the repository browser.