forked from Kitware/CDash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manageSubproject.php
215 lines (183 loc) · 5.72 KB
/
manageSubproject.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/*=========================================================================
Program: CDash - Cross-Platform Dashboard System
Module: $Id$
Language: PHP
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
include("cdash/config.php");
require_once("cdash/pdo.php");
include_once("cdash/common.php");
include('login.php');
include('cdash/version.php');
include_once("models/project.php");
include_once("models/subproject.php");
include_once("models/user.php");
if ($session_OK)
{
@$db = pdo_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS");
pdo_select_db("$CDASH_DB_NAME",$db);
$userid = $_SESSION['cdash']['loginid'];
// Checks
if(!isset($userid) || !is_numeric($userid))
{
echo "Not a valid userid!";
return;
}
$xml = begin_XML_for_XSLT();
$xml .= "<backurl>user.php</backurl>";
$xml .= "<title>CDash - Manage Subproject</title>";
$xml .= "<menutitle>CDash</menutitle>";
$xml .= "<menusubtitle>Subprojects</menusubtitle>";
@$projectid = $_GET["projectid"];
if ($projectid != NULL)
{
$projectid = pdo_real_escape_numeric($projectid);
}
$Project = new Project;
// If the projectid is not set and there is only one project we go directly to the page
if(isset($edit) && !isset($projectid))
{
$projectids = $Project->GetIds();
if(count($projectids)==1)
{
$projectid = $projectids[0];
}
}
if(!isset($projectid))
{
$projectid = -1;
}
$User = new User;
$User->Id = $userid;
$Project->Id = $projectid;
$role = $Project->GetUserRole($userid);
if($User->IsAdmin()===FALSE && $role<=1)
{
echo "You don't have the permissions to access this page";
return;
}
$sql = "SELECT id,name FROM project";
if($User->IsAdmin() == false)
{
$sql .= " WHERE id IN (SELECT projectid AS id FROM user2project WHERE userid='$userid' AND role>0)";
}
$projects = pdo_query($sql);
while($project_array = pdo_fetch_array($projects))
{
$xml .= "<availableproject>";
$xml .= add_XML_value("id",$project_array['id']);
$xml .= add_XML_value("name",$project_array['name']);
if($project_array['id']==$projectid)
{
$xml .= add_XML_value("selected","1");
}
$xml .= "</availableproject>";
}
$Subproject = new Subproject();
$Subproject->SetProjectId($projectid);
// If submit has been pressed
@$addSubproject = $_POST["addSubproject"];
if(isset($addSubproject))
{
$Subproject->Name = htmlspecialchars(pdo_real_escape_string($_POST["newsubproject"]));
$Subproject->Save();
}
// If delete is requested
if(isset($_GET["delete"]))
{
$Subproject->Id = pdo_real_escape_numeric($_GET["delete"]);
$Subproject->Delete();
}
// If we should remove a dependency
if(isset($_GET["removeDependency"]))
{
$Subproject->Id = pdo_real_escape_numeric($_GET["dependency"]);
$Subproject->RemoveDependency(pdo_real_escape_numeric($_GET["removeDependency"]));
}
// If we should add a dependency
if(isset($_POST["addDependency"]))
{
$Subproject->Id = pdo_real_escape_numeric($_POST["dependencyid"]);
$Subproject->AddDependency($_POST["dependency_selection_".$Subproject->Id]);
}
// If we should mark a subproject as core or non-core
// (These are only called via AJAX, so we exit once they have been processed)
if(isset($_GET["core"]))
{
$Subproject->Id = pdo_real_escape_numeric($_GET["subprojectid"]);
if ($Subproject->SetCore($_GET["core"]))
{
echo "Success";
}
else
{
echo "Failure";
}
exit;
}
/** We start generating the XML here */
// List the available project
if($projectid>=0)
{
$xml .= "<project>";
$xml .= add_XML_value("id",$Project->Id);
$xml .= add_XML_value("name_encoded",urlencode($Project->GetName()));
if($projectid>0)
{
$xml .= add_XML_value("name",$Project->GetName());
$subprojectids = $Project->GetSubProjects();
$subprojs = array(); # array to store all subprojects
foreach($subprojectids as $subprojectid)
{
$SubProject = new SubProject();
$SubProject->Id = $subprojectid;
$subprojs[$subprojectid] = $SubProject;
}
foreach($subprojectids as $subprojectid)
{
$SubProject = $subprojs[$subprojectid];
$xml .= "<subproject>";
$xml .= add_XML_value("id",$subprojectid);
$xml .= add_XML_value("name",$SubProject->GetName());
$xml .= add_XML_value("core",$SubProject->GetCore());
$dependencies = $SubProject->GetDependencies();
foreach($dependencies as $dependency)
{
$Dependency = $subprojs[$dependency];
$xml .= "<dependency>";
$xml .= add_XML_value("id",$dependency);
$xml .= add_XML_value("name",$Dependency->GetName());
$xml .= "</dependency>";
}
foreach($subprojectids as $dependency)
{
if($dependency == $subprojectid
|| in_array($dependency,$dependencies)
)
{
continue;
}
$Dependency = $subprojs[$dependency];
$xml .= "<availabledependency>";
$xml .= add_XML_value("id",$dependency);
$xml .= add_XML_value("name",$Dependency->GetName());
$xml .= "</availabledependency>";
}
$xml .= "</subproject>";
}
} // end projectid > 0
$xml .= add_XML_value("id",$Project->Id);
$xml .= "</project>";
}
$xml .= "</cdash>";
// Now doing the xslt transition
generate_XSLT($xml,"manageSubproject");
} // end session OK
?>