Initial add of defaria.com
[clearscm.git] / defaria.com / GD / php / RantestDB.php
1 <?php
2 ////////////////////////////////////////////////////////////////////////////////
3 //
4 // File:        RantestDB.php
5 // Revision:    1.0
6 // Description: PHP Module to access the rantest database
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 include_once ("Utils.php");
26
27 // DEBUG Flag
28 $debug = 1;
29
30 // Read only access
31 $userid         = "pswitreader";
32 $password       = "reader";
33 $dbserver       = "seast1";
34 $dbname         = "rantest";
35
36 $sortBy         = (empty ($_REQUEST["sortBy"]))    ? "Start"        : $_REQUEST["sortBy"];
37 $direction      = (empty ($_REQUEST["direction"])) ? "descending"   : $_REQUEST["direction"];
38 $day            = (empty ($_REQUEST["day"]))       ? date ("m/d/Y") : $_REQUEST["day"];
39
40 // N/A
41 $na = "<font color=#999999>N/A</font>";
42
43 $failureTypes = array (
44   "Aborted",
45   "Exit",
46   "Incomplete",
47   "Other",
48   "p2pDataVal",
49   "Parsing",
50   "Timed out",
51   "valMsgs.pl"
52 );
53
54 $nonFailures = array (
55   "Success",
56   "In progress",
57   "Logging started"
58 );
59
60 $testTypes = array (
61   "All",
62   "Normal",
63   "Regression",
64   "Run for Record"
65 );
66
67 function dbError ($msg, $statement) {
68   $errno  = mysql_errno ();
69   $errmsg = mysql_error ();
70
71   print <<<END
72 <h2><font color="red">ERROR:</font> $msg</h2>
73 <b>Error #$errno:</b><br>
74 <blockquote>$errmsg</blockquote>
75 <b>SQL Statement:</b><br>
76 <blockquote>$statement</blockquote>
77 END;
78
79   exit ($errno);
80 } // dbError
81
82 function openDB () {
83   global $dbserver;
84   global $userid;
85   global $password;
86   global $dbname;
87
88   $db = mysql_connect ($dbserver, $userid, $password)
89     or dbError (__FUNCTION__ . ": Unable to connect to database server $dbserver", "Connect");
90
91   mysql_select_db ($dbname)
92     or dbError (__FUNCTION__ . ": Unable to select the $dbname database", "$dbname");
93 } // openDB
94
95 function getDays () {
96   $days = array ();
97
98   $statement = "select start from testrun group by left (start, 10) order by start desc";
99
100   $result = mysql_query ($statement)
101     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
102
103   while ($row = mysql_fetch_array ($result)) {
104     array_push ($days, YMD2MDY ($row["start"]));
105   } // while
106
107   return $days;
108 } // getDays
109
110 function setRowColor ($result) {
111   if ($result == "Success") {
112     return " class=success";
113   } elseif ($result == "Failure") {
114     return " class=failure";
115   } elseif ($result == "Timed out") {
116     return " class=timed_out";
117   } elseif ($result == "In progress" ||
118              $result == "Logging started") {
119     return " class=in_progress";
120   } else {
121     return " class=white";
122   } // if
123 } // setRowColor
124
125 function colorResult ($result) {
126   if ($result == "Success") {
127     return "<b><font color=green>$result</b></font>";
128   } elseif ($result == "Failure") {
129     return "<b><font color=red>$result</b></font>";
130   } else {
131     return $result;
132   } // if
133 } // colorResult
134
135 function sortPassed ($a, $b) {
136   global $direction;
137
138   return cmpNbr ($a, $b, "Passed", $direction);
139 } // sortPassed
140
141 function sortFailed ($a, $b) {
142   global $direction;
143
144   return cmpNbr ($a, $b, "Failed", $direction);
145 } // sortFailed
146
147 function sortSuccess ($a, $b) {
148   global $direction;
149
150   return cmpNbr ($a, $b, "Success", $direction);
151 } // sortSuccess
152
153 function sortFailure ($a, $b) {
154   global $direction;
155
156   return cmpNbr ($a, $b, "Failure", $direction);
157 } // sortFailure
158
159 function sortTotal ($a, $b) {
160   global $direction;
161
162   return cmpNbr ($a, $b, "Total", $direction);
163 } // sortTotal
164
165 function sortSuite ($a, $b) {
166   global $direction;
167
168   return cmpStr ($a, $b, "Suite", $direction);
169 } // sortSuite
170
171 function sortStart ($a, $b) {
172   global $direction;
173
174   return cmpStr ($a, $b, "Start", $direction);
175 } // sortStart
176
177 function sortDate ($a, $b) {
178   global $direction;
179
180   return cmpStr ($a, $b, "Date", $direction);
181 } // sortDate
182
183 function sortEnd ($a, $b) {
184   global $direction;
185
186   return cmpStr ($a, $b, "End", $direction);
187 } // sortEnd
188
189 function sortTestcase ($a, $b) {
190   global $direction;
191
192   return cmpStr ($a, $b, "Testcase", $direction);
193 } // sortTestcase
194
195 function sortType ($a, $b) {
196   global $direction;
197
198   return cmpStr ($a, $b, "Type", $direction);
199 } // sortType
200
201 function sortUnitVersion ($a, $b) {
202   global $direction;
203
204   return cmpStr ($a, $b, "Unit/Version", $direction);
205 } // sortUnitVersion
206
207 function sortUnit ($a, $b) {
208   global $direction;
209
210   return cmpStr ($a, $b, "Unit", $direction);
211 } // sortUnit
212
213 function sortStatus ($a, $b) {
214   global $direction;
215
216   return cmpStr ($a, $b, "Status", $direction);
217 } // sortStatus
218
219 function sortDuration ($a, $b) {
220   global $direction;
221
222   return cmpNbr ($a, $b, "Duration", $direction);
223 } // sortDuration
224
225 function getName ($table, $id) {
226   $statement = "select name from $table where id=$id";
227
228   $result = mysql_query ($statement)
229     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
230
231   $row = mysql_fetch_array ($result);
232
233   return $row["name"];
234 } // getName
235
236 function getTestNames () {
237   $statement = "select name from test order by name";
238
239   $result = mysql_query ($statement)
240     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
241
242   $names = array ("&lt;All Tests&gt;");
243
244   while ($row = mysql_fetch_array ($result)) {
245     array_push ($names, $row["name"]);
246   } // while
247
248   return $names;
249 } // getTestNames
250
251 function getBuildNbr ($runid) {
252   global $na;
253
254   $statement = "select name from version where type=\"ran_version\" and runid=$runid";
255
256   $result = mysql_query ($statement)
257     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
258
259   $row = mysql_fetch_array ($result);
260
261   if (isset ($row["name"])) {
262     $buildNbr = preg_replace ("/.*\-(\w+)/", "$1", $row["name"]);
263     return $buildNbr;
264   } else {
265     return $na;
266   } // if
267 } // getBuildNbr
268
269 function getVersion ($type, $runid) {
270   global $na;
271
272   $statement = "select name from version where type=\"$type\" and runid=$runid";
273
274   $result = mysql_query ($statement)
275     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
276
277   $row = mysql_fetch_array ($result);
278
279   if (isset ($row["name"])) {
280     return $row["name"];
281   } else {
282     return $na;
283   } // if
284 } // getVersion
285
286 function getVersions ($type) {
287   $statement = "select name from version where type=\"$type\" group by name";
288
289   $result = mysql_query ($statement)
290     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
291
292 //  $names = array ("&lt;All Versions&gt;");
293   $names = array ();
294
295   while ($row = mysql_fetch_array ($result)) {
296     array_push ($names, $row["name"]);
297   } // while
298
299   return $names;
300 } // getVersions
301
302 function getTestVersions ($testcase) {
303   if (isset ($testcase)) {
304     $testcase = preg_replace ("/\*/", "%", $testcase);
305     $condition = "and test.name like \"$testcase\"";
306   } else {
307     $condition = "";
308   } // if
309
310   $statement = <<<END
311 select
312   testruns.runid        as runid,
313   testrun.start         as start,
314   testruns.end          as end,
315   testruns.unit         as unit,
316   testruns.exectype     as type,
317   test.name             as testcase,
318   status.name           as status,
319   testruns.eastlogs     as eastlogs,
320   version.name          as version
321 from
322   testrun,
323   testruns,
324   status,
325   test,
326   version
327 where
328   version.runid         = testruns.runid        and
329   test.id               = testruns.tcid         and
330   testrun.id            = testruns.runid        and
331   testruns.statusid     = status.id             and
332   version.type          = "ran_version"
333 $condition
334 END;
335
336   $result = mysql_query ($statement)
337     or DBError ("Unable to execute query: ", $statement);
338
339   $data = array ();
340
341   while ($row = mysql_fetch_array ($result)) {
342     $line["Testcase"]   = $row["testcase"];
343     $line["Start"]      = $row["start"];
344     $line["Version"]    = $row["version"];
345     $line["End"]        = $row["end"];
346     $line["Unit"]       = $row["unit"];
347     $line["Type"]       = $row["type"];
348     $line["Status"]     = $row["status"];
349     $line["Duration"]   = strtotime ($row["end"]) - strtotime ($row["start"]);
350     $line["Version"]    = $row["version"];
351     $line["_eastlogs"]  = $row["eastlogs"];
352     $line["_runid"]     = $row["runid"];
353
354     array_push ($data, $line);
355   } // while
356
357   return $data;
358 } // getTestVersions
359
360 function getLatestDate () {
361   $statement = "select left (start,10) as start from testrun order by start desc limit 0,1";
362
363   $result = mysql_query ($statement)
364     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
365
366   $row = mysql_fetch_array ($result);
367
368   return $row["start"];
369 } // getLastestDate
370
371 function getEarliestDate () {
372   $statement = "select left (start,10) as start from testrun order by start limit 0,1";
373
374   $result = mysql_query ($statement)
375     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
376
377   $row = mysql_fetch_array ($result);
378
379   return $row["start"];
380 } // getLastestDate
381
382 function reportDateDropdown () {
383   global $script, $day;
384
385   $days = getDays ();
386
387   $dateDropdown .= "<select name=day class=inputfield onChange=\"ChangeDay(this.value,'$script');\">";
388
389   if (count ($days) < 2) {
390     $day = $days[0];
391   } elseif (!isset ($day)) {
392     $day = date ("m/d/Y");
393   } // if
394
395   foreach ($days as $d) {
396     $dateDropdown .= "<option";
397
398     if ($d == $day) {
399       $dateDropdown .= " selected=\"selected\"";
400     } // if
401
402     $dateDropdown .= ">$d</option>";
403   } // foreach
404
405   $dateDropdown .= "</select>";
406
407   return $dateDropdown;
408 } // reportDateDropdown
409
410 function stats ($date = "", $type = "") {
411   if (empty ($date)) {
412     $date = getLatestDate ();
413   } else {
414     $date = MDY2YMD ($date);
415   } // if
416
417   if (empty ($type)) {
418     $type = "All";
419   } // if
420
421   $typecond     = ($type == "All") ? "" : "exectype = \"$type\" and";
422
423   $statement = <<<END
424 select
425   count(*)      as count,
426   status.name   as result
427 from 
428   testrun,
429   testruns,
430   status
431 where
432   left (start,10)       = "$date"               and
433   $typecond
434   testrun.id            = testruns.runid        and
435   testruns.statusid     = status.id
436 group by
437   statusid
438 END;
439
440   $result = mysql_query ($statement)
441     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
442
443   while ($row = mysql_fetch_array ($result)) {
444     if ($row["count"] == 0) {
445        $stats .= "No $row[result] ";
446     } elseif ($row["count"] == 1) {
447        $stats .= "1 $row[result] ";
448     } else {
449       if ($row["result"] == "Failure") {
450        $stats .= "$row[count] Failures ";
451       } else {
452         $stats .= "$row[count] Successes ";
453       } // if
454     } // if
455   } // while
456
457   return $stats;
458 } // stats
459
460 function logs ($logs, $forEmail = false) {
461   global $na;
462
463   if (file_exists ($logs)) {
464     if ($forEmail) {
465       return "Yes";
466     } else {
467       // Chop off "/east/seast1"
468       $logs = substr ($logs, 12);
469       return "<a href=\"$logs\"><img border=0 src=\"/images/log.png\" height=20 title=\"Browse to logfiles\"></a>";
470     } // if
471   } else {
472     if ($forEmail) {
473       return "No";
474     } else {
475       return "<img border=0 src=\"/icons/broken.png\" height=20 title=\"Unable to find log file for this test execution - Perhaps the logfiles have aged away\">";
476       return $na;
477     } // if
478   } // if
479 } # logs
480
481 function getStatus ($startDate, $endDate, $type = "") {
482   $dateCond = "";
483
484   if (isset ($startDate)) {
485     $startDate  = MDY2YMD ($startDate);
486   } // if
487
488   if (isset ($endDate)) {
489     $endDate    = MDY2YMD ($endDate);
490   } // if
491
492   if (isset ($startDate) and isset ($endDate)) {
493     $dateCond = "and left (testrun.start, 10) >= \"$startDate\" " .
494                 "and left (testruns.end,  10) <= \"$endDate\"" ;
495   } elseif ($startDate) {
496     $dateCond = "and left (testrun.start, 10) >= \"$startDate\"";
497   } elseif ($endDate) {
498     $dateCond = "and left (testruns.end,  10) <= \"$endDate\"";
499   } # if
500
501   $exectypeCond = "";
502
503   if ($type != "" and $type != "All") {
504     $exectypeCond = "and testruns.exectype = \"$type\"";
505   } // if
506
507   $statement = <<<END
508 select
509   status.name                   as status,
510   left (testrun.start,10)       as date
511 from
512   test,
513   status,
514   testrun,
515   testruns
516 where
517   test.id                       = testruns.tcid         and
518   testrun.id                    = testruns.runid        and
519   testruns.statusid             = status.id
520   $dateCond
521   $exectypeCond
522 END;
523
524   $result = mysql_query ($statement)
525     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
526
527   while ($row = mysql_fetch_array ($result)) {
528     if (empty ($status{$row["date"]}["Success"])) {
529       $status{$row["date"]}["Success"] = 0;
530     } // if
531     if (empty ($status{$row["date"]}["Failure"])) {
532       $status{$row["date"]}["Failure"] = 0;
533     } // if
534     $status{$row["date"]}{$row["status"]}++;
535     $status{$row["date"]}{Total}++;
536   } // while
537
538   // We used $row["date"] as the key so that we could do the totalling
539   // above but return an array with date inside it.
540   $stats = array ();
541
542   foreach ($status as $key => $value) {
543     $data["Date"]       = $key;
544     $data["Success"]    = $value["Success"];
545     $data["Failure"]    = $value["Failure"];
546     $data["Total"]      = $value["Total"];
547     
548     array_push ($stats, $data);
549   } // foreach
550
551   return $stats;
552 } // getStatus
553
554 function getStepFailures ($runid) {
555   global $failureTypes, $nonFailures;
556
557   $statement = <<<END
558 select
559   step.name             as step,
560   status.name           as status
561 from
562   steprun,
563   step,
564   status
565 where
566   steprun.stepid        = step.id       and
567   steprun.statusid      = status.id     and
568   runid                 = $runid
569 order by
570   step.name
571 END;
572
573   $result = mysql_query ($statement)
574     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
575
576   $stepFailures = array ();
577
578   while ($row = mysql_fetch_array ($result)) {
579     // We only care about failures...
580     if (array_search ($row["status"], $nonFailures) !== false) {
581       continue;
582     } // if
583
584     $stepFailure["Step"]        = $row["step"];
585     $stepFailure["Reason"]      = $row["status"];
586     $stepFailure["Count"]       = $row["count"];
587
588     array_push ($stepFailures, $stepFailure);
589   } // while
590
591   return $stepFailures;
592 } // getStepFailures
593
594 function getFailures ($day) {
595   global $failureTypes;
596
597   $dateCond = "and left (testrun.start, 10) = \"" . MDY2YMD ($day) . "\"";
598
599   $statement = <<<END
600 select
601   test.name             as testcase,
602   testruns.unit         as unit,
603   status.name           as status,
604   testrun.start         as timestamp,
605   testruns.runid        as runid
606 from
607   test,
608   status,
609   testrun,
610   testruns
611 where
612   test.id               = testruns.tcid         and
613   testrun.id            = testruns.runid        and
614   testruns.statusid     = status.id
615   $dateCond
616 order by
617   test.name
618 END;
619
620   $result = mysql_query ($statement)
621     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
622
623   $data = array ();
624
625   while ($row = mysql_fetch_array ($result)) {
626     // We only care about failures...
627     if ($row["status"] == "Success") {
628       continue;
629     } // if
630
631     $record = array ();
632
633     $record["Testcase"] = $row["testcase"];
634     $record["Unit"]     = $row["unit"];
635     $record["Time"]     = substr ($row["timestamp"], 11, 8);
636     $record["_runid"]   = $row["runid"];
637     $record["Failures"] = getStepFailures ($row["runid"]);
638
639     array_push ($data, $record);
640   } // while
641
642   return $data;
643 } // getFailures
644
645 function getTestHistory ($testcase) {
646   if (empty ($testcase)) {
647     $testcase = "%";
648   } else {
649     $testcase = preg_replace ("/\*/", "%", $testcase);
650   } // if
651
652   if ($testcase != "%") {
653     $statement = <<<END
654 select
655   testruns.runid        as runid,
656   testrun.start         as start,
657   testruns.end          as end,
658   testruns.unit         as unit,
659   testruns.exectype     as type,
660   test.name             as testname,
661   status.name           as status,
662   testruns.eastlogs     as eastlogs
663 from
664   testrun,
665   testruns,
666   status,
667   test
668 where
669   test.name             like "$testcase"        and
670   test.id               = testruns.tcid         and
671   testrun.id            = testruns.runid        and
672   testruns.statusid     = status.id
673 END;
674   } else {
675     $statement = <<<END
676 select
677   test.name                                     as testname,
678   status.name                                   as status,
679   count(if(status.name="Success",1,NULL))       as passed,
680   count(if(status.name="Failure",1,NULL))       as failed,
681   count(*)                                      as total
682 from
683   testruns,
684   status,
685   test
686 where
687   test.id               = testruns.tcid and 
688   testruns.statusid     = status.id
689 group by
690   testname
691 END;
692   } // if
693
694   $result = mysql_query ($statement)
695     or DBError ("Unable to execute query: ", $statement);
696
697   $data = array ();
698
699   while ($row = mysql_fetch_array ($result)) {
700     $line["Testcase"]   = $row["testname"];
701
702     if ($testcase != "%") {
703       $line["DUT"]              = $row["unit"];
704       $line["Type"]             = $row["type"];
705       $line["Start"]            = $row["start"];
706       $line["End"]              = $row["end"];
707       $line["Duration"]         = strtotime ($row["end"]) - strtotime ($row["start"]);
708       $line["_eastlogs"]        = $row["eastlogs"];
709       $line["Status"]           = $row["status"];
710       $line["_runid"]           = $row["runid"];
711
712       array_push ($data, $line);
713     } else {
714       $line["Passed"]           = $row["passed"];
715       $line["Failed"]           = $row["failed"];
716       $line["Total"]            = $row["total"];
717       $line["AvgRunTime"]       = averageRunTime ($row["testname"]);
718
719       array_push ($data, $line);
720     } // if
721   } // while
722
723   return $data;
724 } // getTestHistory
725
726 function getTestcaseVersions ($version) {
727   if ($version == "<All Versions>") {
728     unset ($version);
729   } // if
730
731   if (isset ($version)) {
732     $condition = "and version.name = \"$version\"";
733   } else {
734     $condition = "";
735   } // if
736
737   $statement = <<<END
738 select
739   testruns.runid        as runid,
740   testrun.start         as start,
741   testruns.end          as end,
742   testruns.unit         as unit,
743   testruns.exectype     as type,
744   test.name             as testcase,
745   status.name           as status,
746   version.name          as version
747 from
748   testrun,
749   testruns,
750   status,
751   test,
752   version
753 where
754   version.runid         = testruns.runid        and
755   test.id               = testruns.tcid         and
756   testrun.id            = testruns.runid        and
757   testruns.statusid     = status.id
758 $condition
759 END;
760
761   $result = mysql_query ($statement)
762     or DBError ("Unable to execute query: ", $statement);
763
764   $data = array ();
765
766   while ($row = mysql_fetch_array ($result)) {
767     $line["Testcase"]   = $row["testcase"];
768     $line["Start"]      = $row["start"];
769     $line["End"]        = $row["end"];
770     $line["Unit"]       = $row["unit"];
771     $line["Type"]       = $row["type"];
772     $line["Status"]     = $row["status"];
773     $line["Duration"]   = strtotime ($row["end"]) - strtotime ($row["start"]);
774     $line["Version"]    = $row["version"];
775     $line["_runid"]     = $row["runid"];
776
777     array_push ($data, $line);
778   } // while
779
780   return $data;
781 } // getTestcaseVersions
782
783 function averageRunTime ($name) {
784   $statement = <<<END
785 select
786   testrun.start         as start,
787   testruns.end          as end
788 from
789   test,
790   testrun,
791   testruns
792 where
793   test.id       = testruns.tcid         and
794   testrun.id    = testruns.runid        and
795   test.name     = "$name"
796 END;
797
798   $result = mysql_query ($statement)
799     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
800
801   $i = 0;
802
803   while ($row = mysql_fetch_array ($result)) {
804     $duration = (strtotime ($row["end"]) - strtotime ($row["start"]));
805
806     $total += $duration;
807     $i++;
808   } // while
809
810   return round ($total / $i);
811 } // averageRunTime
812
813 function getSuiteruns ($id) {
814   global $sortBy, $direction;
815
816   $statement = <<<END
817 select
818   status.name as Status,
819   Start,
820   End
821 from
822   suiterun,
823   status
824 where
825   suiteid       = $id and
826   statusid      = status.id
827 END;
828
829   $result = mysql_query ($statement)
830     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
831
832   $data = array ();
833
834   while ($row = mysql_fetch_array ($result)) {
835     $line["Status"]     = $row["Status"];
836     $line["Start"]      = $row["Start"];
837     $line["End"]        = $row["End"];
838     $line[Duration]     = strtotime ($row["End"]) - strtotime ($row["Start"]);
839
840     array_push ($data, $line);
841   } // while
842
843   // Sort data
844   if ($sortBy == "Status") {
845     uasort ($data, "sortStatus");
846   } elseif ($sortBy == "End") {
847     uasort ($data, "sortEnd");
848   } elseif ($sortBy == "Duration") {
849     uasort ($data, "sortDuration");
850   } else {
851     uasort ($data, "sortStart");
852   } // if
853
854   return $data;
855 } // getSuiteruns
856
857 function getTestSteps ($runid) {
858   $data["_header"]["DUTVersion"]        = getVersion ("ran_version",            $runid);
859   $data["_header"]["EASTVersion"]       = getVersion ("east_version",           $runid);
860   $data["_header"]["TM500Version"]      = getVersion ("tm500_version",          $runid);
861   $data["_header"]["NMSVersion"]        = getVersion ("nms_version",            $runid);
862   $data["_header"]["RANTESTVersion"]    = getVersion ("rantest_version",        $runid);
863
864   $statement = <<<END
865 select
866   steprun.runid         as _runid,
867   step.name             as step,
868   left (start, 10)      as date,
869   start,
870   steprun.end           as end,
871   status.name           as status,
872   eastlogs              as _eastlogs,
873   userid
874 from
875   steprun,
876   step,
877   testruns,
878   status
879 where
880   steprun.runid = $runid                and
881   steprun.runid = testruns.runid        and
882   step.id       = steprun.stepid        and
883   status.id     = steprun.statusid
884 order by
885   start
886 END;
887
888   $result = mysql_query ($statement)
889     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
890
891   $data["_header"]["userid"]    = "Unknown";
892   $data["_steps"]               = array ();
893
894   while ($row = mysql_fetch_array ($result)) {
895     $line["Step"]                       = $row["step"];
896     $line["Status"]                     = $row["status"];
897     $data["_header"]["Date"]            = $row["date"];
898     $line["Start"]                      = $row["start"];
899     $line["End"]                        = $row["end"];
900     $line["Duration"]                   = strtotime ($row["end"]) - strtotime ($row["start"]);
901     $data["_header"]["userid"]          = $row["userid"];
902     $data["_header"]["_eastlogs"]       = $row["_eastlogs"];
903
904     array_push ($data[_steps], $line);
905   } // while
906
907   return $data;
908 } // getTestSteps
909
910 function getTestRunTimestamp ($runid) {
911   $statement = <<<END
912 select
913   left (start, 10)      as startDate,
914   right (start, 8)      as startTime
915 from
916   steprun
917 where
918   runid = $runid
919 END;
920
921   $result = mysql_query ($statement)
922     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
923
924   $row = mysql_fetch_array ($result);
925
926   return $row["startDate"] . "." . $row["startTime"];
927 } // getTestRunTimestamp
928
929 function getTestRuns ($day, $type, $export = false) {
930   global $sortBy, $direction;
931
932   $typecond = ($type == "All") ? "" : "exectype = \"$type\" and";
933
934   $statement = <<<END
935 select
936   test.name             as testcase,
937   status.name           as status,
938   suite.name            as suite,
939   testrun.start         as start,
940   testruns.runid        as _runid,
941   testruns.end          as end,
942   testruns.unit         as unit,
943   testruns.exectype     as exectype,
944   testruns.eastlogs     as _eastlogs,
945   testruns.suiteid      as _suiteid
946 from
947   testruns,
948   testrun,
949   test,
950   status,
951   suite
952 where
953   left (start, 10)      = "$day"        and
954   $typecond
955   testruns.runid        = testrun.id    and
956   testruns.tcid         = test.id       and
957   statusid              = status.id     and
958   (suiteid              = suite.id      or
959    suiteid              = 0)
960 group by
961 concat(tcid, start)
962 END;
963
964   $result = mysql_query ($statement)
965     or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
966
967   $data = array ();
968   $i    = 1;
969
970   while ($row = mysql_fetch_array ($result)) {
971     if (!$export) {
972       $line["#"] = $i++;
973     } // if
974
975     $line["Suite"]              = $row["suite"];
976     $line["Testcase"]           = $row["testcase"];
977     $line["Type"]               = $row["exectype"];
978     $line["Unit/Version"]       = "$row[unit]-" . getBuildNbr ($row["_runid"]);
979     $line["Logs"]               = (file_exists ($row["eastlogs"])) ? "yes" : "no";
980     $line["Status"]             = $row["status"];
981     $line["Start"]              = substr ($row["start"], 11);
982     $line["End"]                = substr ($row["end"], 11);
983     $line["Duration"]           = strtotime ($row["end"]) - strtotime ($row["start"]);
984
985     $line["_runid"]             = $row["_runid"];
986     $line["_eastlogs"]          = $row["_eastlogs"];
987     $line["_suiteid"]           = $row["_suiteid"];
988
989     array_push ($data, $line);
990   } // while
991
992   // Sort data
993   if ($sortBy == "Suite") {
994     uasort ($data, "sortSuite");
995   } elseif ($sortBy == "Testcase") {
996     uasort ($data, "sortTestcase");
997   } elseif ($sortBy == "Type") {
998     uasort ($data, "sortType");
999   } elseif ($sortBy == "Unit") {
1000     uasort ($data, "sortUnitVersion");
1001   } elseif ($sortBy == "Status") {
1002     uasort ($data, "sortStatus");
1003   } elseif ($sortBy == "End") {
1004     uasort ($data, "sortEnd");
1005   } elseif ($sortBy == "Duration") {
1006     uasort ($data, "sortDuration");
1007   } else {
1008     uasort ($data, "sortStart");
1009   } // if
1010
1011   return $data;
1012 } // getTestRuns
1013 ?>