PageRenderTime 42ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/content/jobstatus.php

http://github.com/jquery/testswarm
PHP | 139 lines | 113 code | 24 blank | 2 comment | 43 complexity | b3f9cb4adece63bf93c8557379ba460e MD5 | raw file
  1. <?php
  2. function get_status($num){
  3. if ( $num == 0 ) {
  4. return "Not started yet.";
  5. } else if ( $num == 1 ) {
  6. return "In progress.";
  7. } else {
  8. return "Completed.";
  9. }
  10. }
  11. function get_status2($num, $fail, $error, $total){
  12. if ( $num == 0 ) {
  13. return "notstarted notdone";
  14. } else if ( $num == 1 ) {
  15. return "progress notdone";
  16. } else if ( $num == 2 && $fail == -1 ) {
  17. return "timeout";
  18. } else if ( $num == 2 && ($error > 0 || $total == 0) ) {
  19. return "error";
  20. } else {
  21. return $fail > 0 ? "fail" : "pass";
  22. }
  23. }
  24. $job_id = preg_replace("/[^0-9]/", "", $_REQUEST["job_id"]);
  25. $result = mysql_queryf("SELECT jobs.name, jobs.status, users.name FROM jobs, users WHERE jobs.id=%u AND users.id=jobs.user_id;", $job_id);
  26. if ( $row = mysql_fetch_array($result) ) {
  27. $job_name = $row[0];
  28. $job_status = get_status(intval($row[1]));
  29. $owner = ($row[2] == $_SESSION["username"]);
  30. }
  31. ?>
  32. <h3><?php echo $job_name; ?></h3>
  33. <?php if ( $owner && $_SESSION["auth"] == "yes" ) { ?>
  34. <form action="" method="POST">
  35. <input type="hidden" name="state" value="wipejob"/>
  36. <input type="hidden" name="job_id" value="<?php echo $job_id; ?>"/>
  37. <input type="submit" name="type" value="delete"/>
  38. <input type="submit" name="type" value="reset"/>
  39. </form>
  40. <?php } ?>
  41. <table class="results"><tbody>
  42. <?php
  43. $result = mysql_queryf("SELECT runs.id as run_id, runs.url as run_url, runs.name as run_name, useragents.engine as browser, useragents.name as browsername, useragents.id as useragent_id, run_useragent.status as status FROM run_useragent, runs, useragents WHERE runs.job_id=%u AND run_useragent.run_id=runs.id AND run_useragent.useragent_id=useragents.id ORDER BY run_id, browsername;", $job_id);
  44. $last = "";
  45. $output = "";
  46. $browsers = array();
  47. $addBrowser = true;
  48. while ( $row = mysql_fetch_assoc($result) ) {
  49. if ( $row["run_id"] != $last ) {
  50. if ( $last ) {
  51. $addBrowser = false;
  52. }
  53. $useragents = array();
  54. $runResult = mysql_queryf("SELECT run_client.client_id as client_id, run_client.status as status, run_client.fail as fail, run_client.error as error, run_client.total as total, clients.useragent_id as useragent_id FROM run_client, clients WHERE run_client.run_id=%u AND run_client.client_id=clients.id ORDER BY useragent_id;", $row["run_id"]);
  55. while ( $ua_row = mysql_fetch_assoc($runResult) ) {
  56. if ( !$useragents[ $ua_row['useragent_id'] ] ) {
  57. $useragents[ $ua_row['useragent_id'] ] = array();
  58. }
  59. array_push( $useragents[ $ua_row['useragent_id'] ], $ua_row );
  60. }
  61. $output .= '<tr><th><a href="' . $row["run_url"] . '">' . $row["run_name"] . "</a></th>\n";
  62. }
  63. if ( $addBrowser ) {
  64. array_push( $browsers, array(
  65. "name" => $row["browsername"],
  66. "engine" => $row["browser"],
  67. "id" => $row["useragent_id"]
  68. ) );
  69. }
  70. #echo "<li>" . $row["browser"] . " (" . get_status(intval($row["status"])) . ")<ul>";
  71. $last_browser = -1;
  72. if ( $useragents[ $row["useragent_id"] ] ) {
  73. foreach ( $useragents[ $row["useragent_id"] ] as $ua ) {
  74. $status = get_status2(intval($ua["status"]), intval($ua["fail"]), intval($ua["error"]), intval($ua["total"]));
  75. if ( $last_browser != $ua["useragent_id"] ) {
  76. $output .= "<td class='$status " . $row["browser"] . "'><a href='" . swarmpath ( '/' ) . "?state=runresults&run_id=" . $row["run_id"] . "&client_id=" . $ua["client_id"] . "'>" .
  77. ($ua["status"] == 2 ?
  78. ($ua["total"] < 0 ?
  79. "Err" :
  80. ($ua["error"] > 0 ?
  81. $ua["error"] :
  82. ($ua["fail"] > 0 ?
  83. $ua["fail"] :
  84. $ua["total"])))
  85. : "") . "</a></td>\n";
  86. }
  87. $last_browser = $ua["useragent_id"];
  88. }
  89. } else {
  90. $output .= "<td class='notstarted notdone'>&nbsp;</td>";
  91. }
  92. #echo "</ul></li>";
  93. $last = $row["run_id"];
  94. }
  95. if ( $last ) {
  96. $header = "<tr><th></th>\n";
  97. $last_browser = array();
  98. foreach ( $browsers as $browser ) {
  99. if ( $last_browser["id"] != $browser["id"] ) {
  100. $header .= '<th><div class="browser">' .
  101. '<img src="' . swarmpath( 'images/' ) . $browser["engine"] .
  102. '.sm.png" class="browser-icon ' . $browser["engine"] .
  103. '" alt="' . $browser["name"] .
  104. '" title="' . $browser["name"] .
  105. '"/><span class="browser-name">' .
  106. preg_replace('/\w+ /', "", $browser["name"]) . ', ' .
  107. '</span></div></th>';
  108. }
  109. $last_browser = $browser;
  110. }
  111. $header .= "</tr>\n";
  112. $output = $header . $output;
  113. $output .= "</tr>\n";
  114. }
  115. echo "$output</tr>\n</tbody>\n</table>";