1<?php
2/*=========================================================================
3
4  Program:   CDash - Cross-Platform Dashboard System
5  Module:    $Id$
6  Language:  PHP
7  Date:      $Date$
8  Version:   $Revision$
9
10  Copyright (c) 2002 Kitware, Inc.  All rights reserved.
11  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12
13     This software is distributed WITHOUT ANY WARRANTY; without even
14     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15     PURPOSE.  See the above copyright notices for more information.
16
17=========================================================================*/
18$noforcelogin = 1;
19include("cdash/config.php");
20require_once("cdash/pdo.php");
21include('login.php');
22include_once("cdash/common.php");
23include("cdash/version.php");
24
25@$buildid = $_GET["buildid"];
26if ($buildid != NULL)
27  {
28  $buildid = pdo_real_escape_numeric($buildid);
29  }
30@$fileid = $_GET["fileid"];
31if ($fileid != NULL)
32  {
33  $fileid = pdo_real_escape_numeric($fileid);
34  }
35@$date = $_GET["date"];
36if ($date != NULL)
37  {
38  $date = htmlspecialchars(pdo_real_escape_string($date));
39  }
40
41// Checks
42if(!isset($buildid) || !is_numeric($buildid))
43  {
44  echo "Not a valid buildid!";
45  return;
46  }
47
48@$userid = $_SESSION['cdash']['loginid'];
49if(!isset($userid))
50  {
51  $userid = 0;
52  }
53
54$db = pdo_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS");
55pdo_select_db("$CDASH_DB_NAME",$db);
56
57$build_array = pdo_fetch_array(pdo_query("SELECT starttime,projectid FROM build WHERE id='$buildid'"));
58$projectid = $build_array["projectid"];
59if(!isset($projectid) || $projectid==0)
60  {
61  echo "This build doesn't exist. Maybe it has been deleted.";
62  exit();
63  }
64
65checkUserPolicy($userid,$projectid);
66
67$project = pdo_query("SELECT * FROM project WHERE id='$projectid'");
68if(pdo_num_rows($project) == 0)
69  {
70  echo "This project doesn't exist.";
71  exit();
72  }
73
74$project_array = pdo_fetch_array($project);
75$projectname = $project_array["name"];
76
77$role=0;
78$user2project = pdo_query("SELECT role FROM user2project WHERE userid='$userid' AND projectid='$projectid'");
79if(pdo_num_rows($user2project)>0)
80  {
81  $user2project_array = pdo_fetch_array($user2project);
82  $role = $user2project_array["role"];
83  }
84if(!$project_array["showcoveragecode"] && $role<2)
85  {
86  echo "This project doesn't allow display of coverage code. Contact the administrator of the project.";
87  exit();
88  }
89
90list ($previousdate, $currenttime, $nextdate) = get_dates($date,$project_array["nightlytime"]);
91$logoid = getLogoID($projectid);
92
93$xml = begin_XML_for_XSLT();
94$xml .= "<title>CDash : ".$projectname."</title>";
95
96$xml .= get_cdash_dashboard_xml_by_name($projectname,$date);
97
98  // Build
99  $xml .= "<build>";
100  $build = pdo_query("SELECT * FROM build WHERE id='$buildid'");
101  $build_array = pdo_fetch_array($build);
102  $siteid = $build_array["siteid"];
103  $site_array = pdo_fetch_array(pdo_query("SELECT name FROM site WHERE id='$siteid'"));
104  $xml .= add_XML_value("site",$site_array["name"]);
105  $xml .= add_XML_value("buildname",$build_array["name"]);
106  $xml .= add_XML_value("buildid",$build_array["id"]);
107  $xml .= add_XML_value("buildtime",$build_array["starttime"]);
108  $xml .= "</build>";
109
110  // coverage
111  $coveragefile_array = pdo_fetch_array(pdo_query("SELECT fullpath,file FROM coveragefile WHERE id='$fileid'"));
112
113  $xml .= "<coverage>";
114  $xml .= add_XML_value("fullpath",$coveragefile_array["fullpath"]);
115
116  if($CDASH_USE_COMPRESSION)
117    {
118    if($CDASH_DB_TYPE == "pgsql")
119      {
120      if(is_resource($coveragefile_array["file"]))
121        {
122        $file = base64_decode(stream_get_contents($coveragefile_array["file"]));
123        }
124      else
125        {
126        $file = base64_decode($coveragefile_array["file"]);
127        }
128      }
129    else
130      {
131      $file = $coveragefile_array["file"];
132      }
133
134    @$uncompressedrow = gzuncompress($file);
135    if($uncompressedrow !== false)
136      {
137      $file = $uncompressedrow;
138      }
139    }
140  else
141    {
142    $file = $coveragefile_array["file"];
143    }
144
145    // Generating the html file
146  $file_array = explode("<br>",$file);
147  $i = 0;
148
149  // Get the codes in an array
150  $linecodes = array();
151  $coveragefilelog = pdo_query("SELECT log FROM coveragefilelog WHERE fileid=".qnum($fileid)." AND buildid=".qnum($buildid));
152  if(pdo_num_rows($coveragefilelog)>0)
153    {
154    $coveragefilelog_array = pdo_fetch_array($coveragefilelog);
155    if($CDASH_DB_TYPE == "pgsql")
156      {
157      $log = stream_get_contents($coveragefilelog_array['log']);
158      }
159    else
160      {
161      $log = $coveragefilelog_array['log'];
162      }
163    $linecode = explode(';',$log);
164    foreach($linecode as $value)
165      {
166      if(!empty($value))
167        {
168        $code = explode(':',$value);
169        $linecodes[$code[0]] = $code[1];
170        }
171      }
172    }
173
174  foreach($file_array as $line)
175    {
176    $linenumber = $i+1;
177    $line = htmlentities($line);
178
179    $file_array[$i] = '<span class="warning">'.str_pad($linenumber,5,' ', STR_PAD_LEFT).'</span>';
180
181    if(array_key_exists($i,$linecodes))
182      {
183      $code = $linecodes[$i];
184      if($code==0)
185        {
186        $file_array[$i] .= '<span class="error">';
187        }
188      else
189        {
190        $file_array[$i] .= '<span class="normal">';
191        }
192      $file_array[$i] .= str_pad($code,5,' ', STR_PAD_LEFT)." | ".$line;
193      $file_array[$i] .= "</span>";
194      }
195    else
196      {
197      $file_array[$i] .= str_pad('',5,' ', STR_PAD_LEFT)." | ".$line;
198      }
199    $i++;
200    }
201
202  $file = implode("<br>",$file_array);
203
204  $xml .= "<file>".utf8_encode(htmlspecialchars($file))."</file>";
205  $xml .= "</coverage>";
206  $xml .= "</cdash>";
207
208// Now doing the xslt transition
209generate_XSLT($xml,"viewCoverageFile");
210?>
211