Added rantest and cqtool to repo
[clearscm.git] / rantest / web / Rantest / TestcasePerVersion.php
1 <?php
2 ////////////////////////////////////////////////////////////////////////////////
3 //
4 // File:        TestcasePerVersion.php
5 // Revision:    1.2
6 // Description: Produce a report of the testcases per version
7 // Author:      Andrew@ClearSCM.com
8 // Created:     Mon Apr 28 15:20:06 MST 2008
9 // Modified:    
10 // Language:    PHP
11 //
12 // (c) Copyright 2008, General Dynamics, all rights reserved.
13 //
14 // All rights reserved except as subject to DFARS 252.227-7014 of contract
15 // number CP02H8901N issued under prime contract N00039-04-C-2009.
16 //
17 // Warning: This document contains technical data whose export is restricted
18 // by the Arms Export Control Act (Title 22, U.S.C., Sec 2751, et seq.) or the
19 // Export Administration Act of 1979, as amended, Title, 50, U.S.C., App. 2401
20 // et seq. Violations of these export laws are subject to severe criminal
21 // penalties. Disseminate in accordance with provisions of DoD Directive
22 // 5230.25.
23 //
24 ////////////////////////////////////////////////////////////////////////////////
25 $script = basename ($_SERVER["PHP_SELF"]);
26
27 include_once "$_SERVER[DOCUMENT_ROOT]/php/Utils.php";
28 include_once "$_SERVER[DOCUMENT_ROOT]/php/RantestDB.php";
29
30 $version        = $_REQUEST["version"];
31 $user           = $_REQUEST["user"];
32
33 $action         = (empty ($_REQUEST["action"]))    ? "Report"     : $_REQUEST["action"];
34 $type           = (empty ($_REQUEST["type"]))      ? "All"        : $_REQUEST["type"];
35 $sortBy         = (empty ($_REQUEST["sortBy"]))    ? "Start"       : $_REQUEST["sortBy"];
36 $direction      = (empty ($_REQUEST["direction"])) ? "descending" : $_REQUEST["direction"];
37
38 function getData ($version) {
39   global $sortBy;
40
41   $data = getTestcaseVersions ($version);
42
43   // Sort data
44   if ($sortBy == "Testcase") {
45     uasort ($data, "sortTestcase");
46   } elseif ($sortBy == "Unit") {
47     uasort ($data, "sortUnit");
48   } elseif ($sortBy == "Type") {
49     uasort ($data, "sortType");
50   } elseif ($sortBy == "Status") {
51     uasort ($data, "sortStatus");
52   } elseif ($sortBy == "Duration") {
53     uasort ($data, "sortDuration");
54   } else {
55     uasort ($data, "sortStart");
56   } // if    
57
58   return $data;
59 } // getData
60
61 function createHeader () {
62   global $versionFor;
63
64   $header = <<<END
65 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
66    "http://www.w3.org/TR/html4/strict.dtd">
67 <html>
68 <head>
69   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
70   <link rel="stylesheet" type="text/css" media="screen" href="/css/Testing.css">
71   <link rel="stylesheet" type="text/css" media="screen" href="/css/Tables.css">
72   <title>Testcases for $versionFor</title>
73 </head>
74
75 <body>
76 END;
77
78   $header .= banner ();
79   $header .= <<<END
80 <h1 align="center">Testcases for $versionFor</h1>
81 END;
82
83   return $header;
84 } // createHeader
85
86 function createPage ($version, $forEmail = false, $message = "") {
87   global $webdir, $direction, $sortBy, $script;
88
89   $data = getData ($version);
90
91   // Flip direction
92   $direction = ($direction == "ascending") ? "descending" : "ascending";
93
94   $urlParms  = "$script?version=$version&action=$action&direction=$direction&sortBy";
95
96   if (!$forEmail) {
97     if ($sortBy == "Testcase") {
98       $testcaseDirection = ($direction == "ascending") 
99         ? "<img src=/images/down.png border=0>"
100         : "<img src=/images/up.png border=0>";
101     } elseif ($sortBy == "Unit") {
102       $unitDirection = ($direction == "ascending") 
103         ? "<img src=/images/down.png border=0>"
104         : "<img src=/images/up.png border=0>";
105     } elseif ($sortBy == "Type") {
106       $typeDirection = ($direction == "ascending") 
107         ? "<img src=/images/down.png border=0>"
108         : "<img src=/images/up.png border=0>";
109     } elseif ($sortBy == "Status") {
110       $statusDirection = ($direction == "ascending") 
111         ? "<img src=/images/down.png border=0>"
112         : "<img src=/images/up.png border=0>";
113     } elseif ($sortBy == "Duration") {
114       $durationDirection = ($direction == "ascending") 
115         ? "<img src=/images/down.png border=0>"
116         : "<img src=/images/up.png border=0>";
117     } else {
118       $startDirection = ($direction == "ascending") 
119         ? "<img src=/images/down.png border=0>"
120         : "<img src=/images/up.png border=0>";
121     } // if
122       
123     if (isset ($message)) {
124       $page .= "<div align=\"center\">$message</div>";
125     } // if
126   } // if
127
128   $page .= <<<END
129 <table align="center" width="90%">
130   <thead>
131 END;
132
133   if (!$forEmail) {
134     $page .= <<<END
135     <tr>
136       <th class=clear align="left" colspan="2"><a href="$script?action=Export&version=$version"><input type="submit" value="Export to CSV"></a></th>
137       <th class=clear align="right" colspan="8"><form action="$script?action=Mail&version=$version" method="post">
138 END;
139
140     $page .= emailUsersDropdown ();
141     $page .= <<<END
142         <input type="submit" value="Send"></form>
143       </th>
144     </tr>
145 END;
146   } // if
147
148   $page .= <<<END
149     <tr>
150       <th class=left>#</th>
151       <th><a href="$urlParms=Testcase">Testcase&nbsp;$testcaseDirection</a></th>
152       <th><a href="$urlParms=Start">Start Date/Time&nbsp;$startDirection</a></th>
153       <th><a href="$urlParms=Unit">Unit&nbsp;$unitDirection</a></th>
154       <th><a href="$urlParms=Type">Type&nbsp;$typeDirection</a></th>
155       <th><a href="$urlParms=Status">Status&nbsp;$statusDirection</a></th>
156       <th class=right><a href="$urlParms=Duration">Duration&nbsp;$durationDirection</a></th>
157     </tr>
158   </thead>
159   <tbody>
160 END;
161
162   foreach ($data as $line) {
163     $row_nbr++;
164     $row_color          = setRowColor ($line["Status"]);
165     $line["Status"]     = colorResult ($line["Status"]);
166     $duration           = FormatDuration ($line["Duration"]);
167
168     $page .= <<<END
169     <tr $row_color>
170       <td align="center">$row_nbr</td>
171       <td><a href="rantest.php?testName=$line[Testcase]&runid=$line[_runid]&start=$line[Start]">$line[Testcase]</a></td>
172       <td align="center">$line[Start]</td>
173       <td align="center">$line[Unit]</td>
174       <td align="center">$line[Type]</td>
175       <td align="center">$line[Status]</td>
176       <td align="right">$duration</td>
177     </tr>
178 END;
179   } // foreach
180
181   $page .= <<<END
182   </tbody>
183 </table>
184 END;
185
186   return $page;
187 } // createPage
188
189 function exportTestVersionsCSV ($version) {
190   if (isset ($version)) {
191     $title      = "Testcases for $version";
192     $filename   = "Testcases." . $version . ".csv";
193   } else {
194     $title      = "Testcases for All Versions";
195     $filename   = "Testcases for All Versionss.csv";
196   } // if
197
198   header ("Content-Type: application/octect-stream");
199   header ("Content-Disposition: attachment; filename=\"$filename\"");
200
201   print exportCSV (getData ($version), $title);
202
203   exit;
204 } // exportTestVersionsCSV
205
206 function setVersion () {
207   global $version;
208
209   return (isset ($version)) ? $version : "All Versions";
210 } // setVersion
211
212 function displayReport ($version, $message = "") {
213   print createHeader    ();
214   print createPage      ($version, false, $message);
215
216   copyright ();
217 } // displayReport
218
219 function mailTestVersionsReport ($version, $pnbr, $username) {
220   if (isset ($version)) {
221     $subject    = "Testcases for $version";
222     $filename   = "Testcases." . $version . ".csv";
223   } else {
224     $subject    = "Test Versions for All Tests";
225     $filename   = "Test Versions for All Tests.csv";
226   } // if
227
228   $body         = createPage ($version, true);
229   $attachment   = exportCSV (getData ($version, true), $subject);
230
231   return mailReport ($pnbr, $username, $subject, $body, $filename, $attachment);
232 } // mailTestVersionsReport
233
234 openDB ();
235
236 $versionFor = setVersion ();
237
238 switch ($action) {
239   case "Export":
240     exportTestVersionsCSV ($version);
241     break;
242
243   case "Mail":
244     list ($pnbr, $username) = explode (":", $user);
245     displayReport ($version, mailTestVersionsReport ($version, $pnbr, $username));
246     break;
247
248   default:
249     displayReport ($version);
250     break;
251 } // switch  
252 ?>
253 </body>
254 </html>