1<?php
2/*=========================================================================
3
4  Program:   CDash - Cross-Platform Dashboard System
5  Module:    $Id: buildOverview.php 1161 2008-09-19 14:56:14Z jjomier $
6  Language:  PHP
7  Date:      $Date: 2008-02-04 17:50:42 -0500 (Mon, 04 Feb 2008) $
8  Version:   $Revision: 435 $
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");
23require_once("models/project.php");
24require_once("models/subproject.php");
25
26@$projectid = $_GET["projectid"];
27if ($projectid != NULL)
28  {
29  $projectid = pdo_real_escape_numeric($projectid);
30  }
31
32// Checks
33if(!isset($projectid) || !is_numeric($projectid))
34  {
35  echo "Not a valid projectid!";
36  return;
37  }
38
39$db = pdo_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS");
40pdo_select_db("$CDASH_DB_NAME",$db);
41
42$project = pdo_query("SELECT * FROM project WHERE id='$projectid'");
43if(pdo_num_rows($project)==0)
44  {
45  return;
46  }
47
48$project_array = pdo_fetch_array($project);
49checkUserPolicy(@$_SESSION['cdash']['loginid'],$project_array["id"]);
50
51$ctestconfig  = "## This file should be placed in the root directory of your project.\n";
52$ctestconfig .= "## Then modify the CMakeLists.txt file in the root directory of your\n";
53$ctestconfig .= "## project to incorporate the testing dashboard.\n";
54$ctestconfig .= "##\n";
55$ctestconfig .= "## # The following are required to submit to the CDash dashboard:\n";
56$ctestconfig .= "##   ENABLE_TESTING()\n";
57$ctestconfig .= "##   INCLUDE(CTest)\n";
58$ctestconfig .= "\n";
59
60$ctestconfig .= "set(CTEST_PROJECT_NAME \"".$project_array["name"]."\")\n";
61$ctestconfig .= "set(CTEST_NIGHTLY_START_TIME \"".$project_array["nightlytime"]."\")\n\n";
62
63$ctestconfig .= "set(CTEST_DROP_METHOD \"http\")\n";
64
65$ctestconfig .= "set(CTEST_DROP_SITE \"".$_SERVER['SERVER_NAME']."\")\n";
66
67$currentURI = $_SERVER['REQUEST_URI'];
68$currentURI = substr($currentURI,0,strrpos($currentURI,"/"));
69
70$ctestconfig .= "set(CTEST_DROP_LOCATION \"".$currentURI."/submit.php?project=".urlencode($project_array["name"])."\")\n";
71$ctestconfig .= "set(CTEST_DROP_SITE_CDASH TRUE)\n";
72
73// Add the subproject
74$Project = new Project();
75$Project->Id = $projectid;
76$subprojectids = $Project->GetSubprojects();
77
78function get_graph_depth($a,$value)
79  {
80  $SubProject = new SubProject();
81  $SubProject->Id = $a;
82  $parents = $SubProject->GetDependencies();
83  foreach($parents as $parentid)
84    {
85    $subvalue = get_graph_depth($parentid,$value+1);
86    if($subvalue>$value)
87      {
88      $value = $subvalue;
89      }
90    }
91  return $value;
92  }
93
94// Compare two subprojects to check the depth
95function cmp($a, $b)
96  {
97  $va = get_graph_depth($a,0);
98  $vb = get_graph_depth($b,0);
99  if ($va == $vb)
100    {
101    return 0;
102    }
103  return ($va < $vb) ? -1 : 1;
104  }
105usort($subprojectids,"cmp");
106
107if(count($subprojectids)>0)
108  {
109  $ctestconfig .= "\nset(CTEST_PROJECT_SUBPROJECTS\n";
110  }
111
112foreach($subprojectids as $subprojectid)
113  {
114  $SubProject = new SubProject();
115  $SubProject->Id = $subprojectid;
116  $ctestconfig .= $SubProject->GetName()."\n";
117  }
118
119if(count($subprojectids)>0)
120  {
121  $ctestconfig .= ")\n";
122  }
123
124header('Vary: User-Agent');
125if(ob_get_contents())
126  echo "Some data has already been output";
127if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
128  header('Content-Type: application/force-download');
129else
130  header('Content-Type: application/octet-stream');
131if(headers_sent())
132  echo "Some data has already been output to browser";
133
134header("Content-Disposition: attachment; filename=\"CTestConfig.cmake\"");
135header("Content-Transfer-Encoding: binary");
136header("Content-Length: ".strlen($ctestconfig));
137echo $ctestconfig;
138
139?>
140