END; $header .= banner (); $header .= <<Test history for $historyFor END; return $header; } // createHeader function createPage ($testcase, $forEmail = false, $message = "") { global $webdir, $direction, $sortBy, $script; $data = getData ($testcase); if (!$forEmail) { // Flip direction $direction = ($direction == "ascending") ? "descending" : "ascending"; if ($sortBy == "DUT") { $DUTDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "Type") { $typeDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "Start") { $startDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "End") { $endDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "Duration") { $durationDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "Status") { $statusDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "Passed") { $passedDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "Failed") { $failedDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "Total") { $totalDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "AvgRunTime") { $avgRunTimeDirection = ($direction == "ascending") ? "" : ""; } else { $testcaseDirection = ($direction == "ascending") ? "" : ""; } // if if (isset ($message)) { $page .= "
$message
"; } // if } // if $page .= << END; if (!$forEmail) { if (isset ($testcase)) { $page .= <<
END; } else { $page .= << END; } // if $page .= emailUsersDropdown (); $page .= << END; } // if if (isset ($testcase)) { $urlParms = "$script?testcase=$testcase&action=$action&direction=$direction&sortBy"; $page .= << # Testcase $testcaseDirection DUT $DUTDirection Type $typeDirection Start $startDirection End $endDirection Duration $durationDirection Logs Status $statusDirection END; } else { $urlParms = "$script?build=$build&level=$level&DUT=$DUT&test=$test&action=$action&direction=$direction&sortBy"; $page .= << # Testcase $testcaseDirection Passed $passedDirection Failed $failedDirection Total $totalDirection Avg Run Time $avgRunTimeDirection END; } // if $page .= << END; $total_passed = $total_failed = $total_total = 0; foreach ($data as $line) { $row_nbr++; if (isset ($testcase)) { $class = SetRowColor ($line["Status"]); $status = colorResult ($line["Status"]); $date = YMD2MDY (substr ($line["Start"], 0, 10)); $duration = FormatDuration ($line["Duration"]); $logs = logs ($line["_eastlogs"]); $page .= << $row_nbr $line[Testcase] $line[DUT] $line[Type] $line[Start] $line[End] $duration $logs $status END; } else { $row_color = ($row_nbr % 2 == 0) ? " class=other" : " class=white"; $page .= << $row_nbr $line[Testcase] $line[Passed] $line[Failed] $line[Total] END; $page .= FormatDuration ($line[AvgRunTime]); $page .= ""; $total_passed += $line["Passed"]; $total_failed += $line["Failed"]; $total_total += $line["Total"]; } // if } // foreach // Print total if (empty ($testcase)) { $page .= << Total $total_passed $total_failed $total_total   END; } // if $page .= << END; return $page; } // createPage function exportTestHistoryCSV ($testcase) { global $historyFor; if (isset ($testcase)) { $title = "Test History for $historyFor"; $filename = "Test History." . $testcase . ".csv"; } else { $title = "Test History for All Tests"; $filename = "Test History.All Tests.csv"; } // if // Protect $filename from wildcards $filename = preg_replace ("/\*/", "%", $filename); header ("Content-Type: application/octect-stream"); header ("Content-Disposition: attachment; filename=\"$filename\""); print exportCSV (getData ($testcase), $title); exit; } // exportTestHistoryCSV function setTestcase () { global $testcase, $build, $level, $DUT, $test; if (empty ($testcase)) { if (empty ($test)) { $test = "*"; } // if if ($build == "*" and $level == "*" and $DUT == "*" and $test == "*") { unset ($testcase); return "All Tests"; } else { $testcase = "${build}_${level}_${DUT}_${test}"; } // if } // if return $testcase; } // setTestcase function displayReport ($testcase, $message = "") { print createHeader (); print createPage ($testcase, false, $message); copyright (); } // displayReport function mailTestHistoryReport ($testcase, $pnbr, $username) { global $historyFor; if (isset ($testcase)) { $subject = "Test History for $historyFor"; $filename = "Test History." . $testcase . ".csv"; } else { $subject = "Test History for All Tests"; $filename = "Test History.All Tests.csv"; } // if // Protect $filename from wildcards $filename = preg_replace ("/\*/", "%", $filename); $body = createPage ($testcase, true); $attachment = exportCSV (getData ($testcase, true), $subject); return mailReport ($pnbr, $username, $subject, $body, $filename, $attachment); } // mailTestHistoryReport openDB (); $historyFor = setTestcase (); switch ($action) { case "Export": exportTestHistoryCSV ($testcase); break; case "Mail": list ($pnbr, $username) = explode (":", $user); displayReport ($testcase, mailTestHistoryReport ($testcase, $pnbr, $username)); break; default: displayReport ($testcase); break; } // switch ?>