END; $header .= banner (); $header .= <<Test Versions for $historyFor END; return $header; } // createHeader function createPage ($testcase, $forEmail = false, $message = "") { global $webdir, $direction, $sortBy, $script; global $build, $level, $DUT, $test; $data = getData ($testcase); // Flip direction $direction = ($direction == "ascending") ? "descending" : "ascending"; if (isset ($testcase)) { $urlParms = "$script?testcase=$testcase&action=$action&direction=$direction&sortBy"; } else { $urlParms = "$script?build=$build&level=$level&DUT=$DUT&test=$test&action=$action&direction=$direction&sortBy"; } // if if (!$forEmail) { if ($sortBy == "Testcase") { $testcaseDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "Unit") { $unitDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "Type") { $typeDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "Status") { $statusDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "Duration") { $durationDirection = ($direction == "ascending") ? "" : ""; } elseif ($sortBy == "Version") { $versionDirection = ($direction == "ascending") ? "" : ""; } else { $dateDirection = ($direction == "ascending") ? "" : ""; } // if if (isset ($message)) { $page .= "
$message
"; } // if } // if $page .= << END; if (!$forEmail) { $page .= <<
END; $page .= emailUsersDropdown (); $page .= << END; } // if $page .= << # Testcase $testcaseDirection Start Date/Time $dateDirection Unit $unitDirection Type $typeDirection Status $statusDirection Duration $durationDirection Version $versionDirection END; foreach ($data as $line) { $row_nbr++; $row_color = setRowColor ($line["Status"]); $line["Status"] = colorResult ($line["Status"]); $duration = FormatDuration ($line["Duration"]); $page .= << $row_nbr $line[Testcase] $line[Start] $line[Unit] $line[Type] $line[Status] $duration $line[Version] END; } // foreach $page .= << END; return $page; } // createPage function exportTestVersionsCSV ($testcase) { global $historyFor; if (isset ($testcase)) { $title = "Test Versions for $historyFor"; $filename = "Test Versions." . $testcase . ".csv"; } else { $title = "Test Versions for All Tests"; $filename = "Test Versions for 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 mailTestVersionsReport ($testcase, $pnbr, $username) { global $historyFor; if (isset ($testcase)) { $subject = "Test Versions for $historyFor"; $filename = "Test Versions." . $testcase . ".csv"; } else { $subject = "Test Versions for All Tests"; $filename = "Test Versions for 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); } // mailTestVersionsReport openDB (); $historyFor = setTestcase (); switch ($action) { case "Export": exportTestVersionsCSV ($testcase); break; case "Mail": list ($pnbr, $username) = explode (":", $user); displayReport ($testcase, mailTestVersionsReport ($testcase, $pnbr, $username)); break; default: displayReport ($testcase); break; } // switch ?>