| 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("  Error-Number: %s <br>", mysql_errno()); | 
|---|
| 20 | if (mysql_error()!="") | 
|---|
| 21 | printf("  Error-Message: %s <br>", mysql_error()); | 
|---|
| 22 | if (mysql_info()!="") | 
|---|
| 23 | printf("  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       ON Sequences.fSequenceFirst=SequenceProcessStatus.fSequenceFirst "; | 
|---|
| 48 | $query0 .= "LEFT JOIN Project         ON Project.fProjectKEY=Sequences.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, fFailedCode=NULL, fFailedCodeAdd=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("  Errorno: %s <br>", mysql_errno()); | 
|---|
| 91 | if (mysql_error()!="") | 
|---|
| 92 | printf("  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&insert=On\"'>   \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("91.64.78.187", "132.187.47.10", "132.187.47.67", "132.187.47.63", "129.217.160.151"); | 
|---|
| 224 | if (!in_array($_SERVER['REMOTE_ADDR'], $ips)) | 
|---|
| 225 | { | 
|---|
| 226 | echo "You are not allowed to reset sequences.<br>"; | 
|---|
| 227 | echo "If you want to reset your sequences in the automatic analysis, please contact Daniela Dorner.<br>"; | 
|---|
| 228 | echo (file_get_contents("index-footer.html")); | 
|---|
| 229 | return; | 
|---|
| 230 | } | 
|---|
| 231 |  | 
|---|
| 232 | $environment = sizeof($_GET); | 
|---|
| 233 |  | 
|---|
| 234 | //init | 
|---|
| 235 | if (empty($_GET["Seqs"])) | 
|---|
| 236 | $_GET["Seqs"]=""; | 
|---|
| 237 | if (empty($_GET["step"])) | 
|---|
| 238 | $_GET["step"]=""; | 
|---|
| 239 |  | 
|---|
| 240 | //print form | 
|---|
| 241 | printf("<center>\n"); | 
|---|
| 242 | printf("<form action=\"resetseq.php\" METHOD=\"GET\">\n"); | 
|---|
| 243 |  | 
|---|
| 244 | printf("<input type='radio' name='step' value='crashed' %s> crashed processes  ", $_GET["step"]=="crashed" ? "checked" : ""); | 
|---|
| 245 | printf("<input type='radio' name='step' value='callisto' %s> callisto  ", $_GET["step"]=="callisto" ? "checked" : ""); | 
|---|
| 246 | printf("<input type='radio' name='step' value='star' %s> star<br>", $_GET["step"]=="star" ? "checked" : ""); | 
|---|
| 247 |  | 
|---|
| 248 | printf("<table>\n<tr>\n<td align='left'>\nSequences: \n</td>\n</tr>\n<tr>\n<td>\n"); | 
|---|
| 249 | printf("<input name='Seqs' type='text' size='80' maxlength='300' value='%s'>\n</td>\n</tr>\n</table>\n<br>\n", $_GET["Seqs"]); | 
|---|
| 250 |  | 
|---|
| 251 | ini_set("mysql.trace_mode", "Off"); | 
|---|
| 252 | //    ini_set("display_errors", "Off"); | 
|---|
| 253 |  | 
|---|
| 254 | printf("<input type='submit' value='Check Sequence Status'>   \n"); | 
|---|
| 255 | printf("<input class='Width' type='button' value='Clear Form' onClick='self.location.href=\"resetseq.php\"'>   \n"); | 
|---|
| 256 | //    if (!empty($_GET["step"]) && ereg("^([ ]*[0-9]{5,8}[ ]*[,])*[ ]*[0-9]{5,8}[ ]*$",$_GET["Seqs"])) | 
|---|
| 257 | //        printf("<input type='checkbox' name='insert' value='On'>insert\n"); | 
|---|
| 258 | printf("<br>\n"); | 
|---|
| 259 | printf("</form>\n"); | 
|---|
| 260 | printf("</center>\n"); | 
|---|
| 261 | printf("</td>\n</tr>\n"); | 
|---|
| 262 | printf("<tr class='Block'>\n<td>\n"); | 
|---|
| 263 |  | 
|---|
| 264 | if ($environment==0) | 
|---|
| 265 | { | 
|---|
| 266 | printf("No query submitted yet.<br>\n"); | 
|---|
| 267 | printf("To reset sequences, please insert them in the following format: <i>12345,87654321</i><br>\n"); | 
|---|
| 268 | printf("and choose whether you want to reset just crashed processes, callisto (this includes star) or just star.<br>\n"); | 
|---|
| 269 | printf("You can enter up to 300 characters in the sequences field.<br>\n"); | 
|---|
| 270 | } | 
|---|
| 271 | else | 
|---|
| 272 | PrintPage($host, $user, $pw, $db); | 
|---|
| 273 |  | 
|---|
| 274 | echo (file_get_contents("index-footer.html")); | 
|---|
| 275 |  | 
|---|
| 276 | ini_set("display_errors", "Off"); | 
|---|
| 277 | ini_set("mysql.trace_mode", "Off"); | 
|---|
| 278 | } | 
|---|
| 279 | ?> | 
|---|