forked from Kitware/CDash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manageOverview.php
142 lines (122 loc) · 4.07 KB
/
manageOverview.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
<?php
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/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 Overview</title>";
$xml .= "<menutitle>CDash</menutitle>";
$xml .= "<menusubtitle>Overview</menusubtitle>";
@$projectid = $_GET["projectid"];
if ($projectid != NULL)
{
$projectid = pdo_real_escape_numeric($projectid);
}
// If the projectid is not set and there is only one project we go directly to the page
$Project = new Project;
if(!isset($projectid))
{
$projectids = $Project->GetIds();
if(count($projectids)==1)
{
$projectid = $projectids[0];
}
}
if(!isset($projectid))
{
echo "No projectid specified";
return;
}
$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;
}
// check if we are saving an overview layout
if (isset($_POST['saveLayout']))
{
$inputRows = json_decode($_POST['saveLayout'], true);
// remove old overview layout from this project
pdo_query(
"DELETE FROM overview_components WHERE projectid=" .
qnum(pdo_real_escape_numeric($projectid)));
add_last_sql_error("manageOverview::saveLayout::DELETE", $projectid);
if (count($inputRows) > 0)
{
// construct query to insert the new layout
$query = "INSERT INTO overview_components (projectid, buildgroupid, position, type) VALUES ";
foreach ($inputRows as $inputRow)
{
$query .= "(" .
qnum(pdo_real_escape_numeric($projectid)) . ", " .
qnum(pdo_real_escape_numeric($inputRow["buildgroupid"])) . ", " .
qnum(pdo_real_escape_numeric($inputRow["position"])) . ", " .
qnum(pdo_real_escape_string($inputRow["type"])) . "), ";
}
// remove the trailing comma and space, then insert our new values
$query = rtrim($query, ", ");
pdo_query($query);
add_last_sql_error("manageOverview::saveLayout::INSERT", $projectid);
}
// since this is called by AJAX, we don't need to render the page below.
exit(0);
}
// otherwise generate the .xml to render this page
$xml .= "<project>";
$xml .= add_XML_value("id",$Project->Id);
$xml .= add_XML_value("name",$Project->GetName());
$xml .= add_XML_value("name_encoded",urlencode($Project->GetName()));
$xml .= "</project>";
// Get the groups for this project
$query = "SELECT id, name FROM buildgroup WHERE projectid='$projectid'";
$buildgroup_rows = pdo_query($query);
add_last_sql_error("manageOverview::buildgroups", $projectid);
while($buildgroup_row = pdo_fetch_array($buildgroup_rows))
{
$xml .= "<buildgroup>";
$xml .= add_XML_value("id", $buildgroup_row["id"]);
$xml .= add_XML_value("name", $buildgroup_row["name"]);
$xml .= "</buildgroup>";
}
// Get the groups that are already included in the overview
$query =
"SELECT bg.id, bg.name, obg.type FROM overview_components AS obg
LEFT JOIN buildgroup AS bg ON (obg.buildgroupid = bg.id)
WHERE obg.projectid = " . qnum(pdo_real_escape_numeric($projectid)) . "
ORDER BY obg.position";
$overviewgroup_rows = pdo_query($query);
add_last_sql_error("manageOverview::overviewgroups", $projectid);
$xml .= "<overview>";
while($overviewgroup_row = pdo_fetch_array($overviewgroup_rows))
{
$xml_element_name = $overviewgroup_row["type"];
$xml .= "<$xml_element_name>";
$xml .= add_XML_value("id", $overviewgroup_row["id"]);
$xml .= add_XML_value("name", $overviewgroup_row["name"]);
$xml .= "</$xml_element_name>";
}
$xml .= "</overview>";
$xml .= "</cdash>";
// Now doing the xslt transition
generate_XSLT($xml,"manageOverview");
} // end session OK
?>