-
Notifications
You must be signed in to change notification settings - Fork 131
/
managemilestone.php
327 lines (288 loc) · 11.2 KB
/
managemilestone.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?php
require("./init.php");
// check if user is logged in
if (!isset($_SESSION["userid"])) {
$template->assign("loginerror", 0);
$template->display("login.tpl");
die();
}
$milestone = new milestone();
$action = getArrayVal($_GET, "action");
$mid = getArrayVal($_GET, "mid");
$mode = getArrayVal($_GET, "mode");
$template->assign("mode", $mode);
//Get data from $_POST and $_GET filtered and sanitized by htmlpurifier
$cleanGet = cleanArray($_GET);
$cleanPost = cleanArray($_POST);
$id = getArrayVal($_GET, "id");
$project = array();
$project['ID'] = $id;
$template->assign("project", $project);
// define the active tab in the project navigation
$classes = array("overview" => "overview", "msgs" => "msgs", "tasks" => "tasks", "miles" => "miles_active", "files" => "files", "users" => "users", "tracker" => "tracking");
$template->assign("classes", $classes);
// check if the user belongs to the current project. die if he does not.
if (!chkproject($userid, $id)) {
$errtxt = $langfile["notyourproject"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "$errtxt<br>$noperm");
$template->display("error.tpl");
die();
}
/*
* VIEW ROUTES
* These are routes that render HTML views to the browser
*/
if ($action == "add") {
if (!$userpermissions["milestones"]["add"]) {
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
$template->display("error.tpl");
die();
}
// Get start date from form
$start = getArrayVal($_POST, "start");
$milestone_id = $milestone->add($id, $cleanPost["name"], $cleanPost["desc"], $start, $cleanPost["end"], 1);
if ($milestone_id) {
$liste = (object)new tasklist();
//assign users to milestone
foreach($cleanPost["assigned"] as $assignee){
$milestone->assign($milestone_id, $assignee);
}
//create tasklists
foreach($cleanPost["tasklist"] as $tasklist){
$liste->add_liste($id, $tasklist, "", 0, $milestone_id);
}
echo "ok";
}
} elseif ($action == "editform") {
if (!$userpermissions["milestones"]["edit"]) {
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
$template->display("error.tpl");
die();
}
$projectObj = new project();
//get project info
$project = $projectObj->getProject($id);
// Get milestone info
$milestone = $milestone->getMilestone($mid);
$template->assign("title", $langfile["editmilestone"]);
$template->assign("projectname", $project["name"]);
$template->assign("milestone", $milestone);
$template->display("forms/editmilestone.tpl");
} elseif ($action == "edit") {
if (!$userpermissions["milestones"]["edit"]) {
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
$template->display("error.tpl");
die();
}
// Get milestone ID and start date from form
$mid = $cleanPost["mid"];
$start = $cleanPost["start"];
$end = $cleanPost["end"];
// Edit the milestone
$changeAllDueDates = $cleanPost["changeallduedates"];
if ($changeAllDueDates == "on") {
$milestoneData = $milestone->getMilestone($mid);
$endOffset = strtotime($end) - $milestoneData["end"];
$milestoneTasklist = $milestone->getMilestoneTasklists($mid);
$updStmt = $conn->prepare("UPDATE tasks SET `end`=? WHERE ID = ?");
foreach ($milestoneTasklist as $tasklist) {
foreach ($tasklist["tasks"] as $task) {
$newEnd = $task["end"] + $endOffset;
$upd = $updStmt->execute(array($newEnd, $task["ID"]));
}
}
}
// Edit the milestone
if ($milestone->edit($mid, $cleanPost["name"], $cleanPost["desc"], $start, $end)) {
$loc = $url . "managemilestone.php?action=showproject&id=$id&mode=edited";
header("Location: $loc");
} else {
$template->assign("editmilestone", 0);
}
} elseif ($action == "del") {
if (!$userpermissions["milestones"]["del"]) {
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
$template->display("error.tpl");
die();
}
// Delete the milestone
if ($milestone->del($mid)) {
echo "ok";
} else {
$template->assign("delmilestone", 0);
}
} elseif ($action == "open") {
$project = $_GET['project'];
if ($milestone->open($mid)) {
$loc = $url . "managemilestone.php?action=showproject&id=$id&mode=opened";
header("Location: $loc");
} else {
$template->assign("openmilestone", 0);
}
} elseif ($action == "close") {
// $project = $_GET['project'];
if ($milestone->close($mid)) {
// $loc = $url . "managemilestone.php?action=showproject&id=$id&mode=closed";
// header("Location: $loc");
echo "ok";
} else {
$template->assign("closemilestone", 0);
}
} elseif ($action == "assign") {
if ($milestone->assign($cleanPost["user"], $mid)) {
$template->assign("assignmilestone", 1);
$template->display("projectmilestones.tpl");
} else {
$template->assign("assignmilestone", 0);
}
} elseif ($action == "deassign") {
if ($milestone->deassign($cleanPost["user"], $mid)) {
$template->assign("deassignmilestone", 1);
$template->display("projectmilestones.tpl");
} else {
$template->assign("deassignmilestone", 0);
}
} elseif ($action == "showproject") {
if (!$userpermissions["milestones"]["view"]) {
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "$errtxt<br>$noperm");
$template->display("error.tpl");
die();
}
// Check if the current user belongs to the project
if (!chkproject($userid, $id)) {
$errtxt = $langfile["notyourproject"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "$errtxt<br>$noperm");
$template->display("error.tpl");
die();
}
$projectObj = new project();
$today = date("d");
// Get the project name
$project = $projectObj->getProject($id);
// Get number of assignable users
$project_members = $projectObj->getProjectMembers($id, $projectObj->countMembers($id));
$template->assign("assignable_users", $project_members);
$template->assign("title", $langfile["milestones"]);
$template->assign("projectname", $project["name"]);
$template->assign("project", $project);
$template->display("projectmilestones.tpl");
} elseif ($action == "mileslist") {
$stones = $milestone->getProjectMilestones($id);
if (!empty($stones)) {
$stones2 = $milestone->getTodayProjectMilestones($id);
}
if (!empty($stones2)) {
$stones = array_merge($stones, $stones2);
}
$template->assign("milestones", $stones);
$template->display("mileslist.tpl");
} elseif ($action == "showmilestone") {
$msid = $_GET['msid'];
$myproject = new project();
$pro = $myproject->getProject($id);
$projectname = $pro["name"];
$template->assign("projectname", $projectname);
$milestone = $milestone->getMilestone($msid);
$title = $langfile['milestone'];
$template->assign("title", $title);
$template->assign("project", $project);
$template->assign("milestone", $milestone);
$template->display("milestone.tpl");
}
/*
* DATA ROUTES
* These are routes that render JSON data structures
*/
elseif ($action == "projectMilestones") {
if (!$userpermissions["milestones"]["view"]) {
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "$errtxt<br>$noperm");
$template->display("error.tpl");
die();
}
// Check if the current user belongs to the project
if (!chkproject($userid, $id)) {
$errtxt = $langfile["notyourproject"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "$errtxt<br>$noperm");
$template->display("error.tpl");
die();
}
// Get projects milestones, and todays project milestones
$stones = $milestone->getProjectMilestones($id);
$stones2 = $milestone->getTodayProjectMilestones($id);
// Get closed milestones and milestones that are late
$donestones = $milestone->getDoneProjectMilestones($id);
if (empty($stones2)) {
$stones2 = array();
}
if (empty($stones)) {
$stones = array();
}
// merge the current milestones
$stones = array_merge($stones, $stones2);
$milestones["open"] = $stones;
$milestones["closed"] = $donestones;
$projectStones["items"] = $milestones;
$projectStones["count"] = count($stones);
echo json_encode($projectStones);
} elseif ($action == "lateProjectMilestones") {
if (!$userpermissions["milestones"]["view"]) {
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "$errtxt<br>$noperm");
$template->display("error.tpl");
die();
}
// Check if the current user belongs to the project
if (!chkproject($userid, $id)) {
$errtxt = $langfile["notyourproject"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "$errtxt<br>$noperm");
$template->display("error.tpl");
die();
}
//get late miletones
$latestones = $milestone->getLateProjectMilestones($id);
// Count late milestones
if (!empty($latestones)) {
$latestones = $milestone->formatdate($latestones);
}
$lateProjectStones["items"] = $latestones;
$lateProjectStones["count"] = count($latestones);
echo json_encode($lateProjectStones);
} elseif ($action == "upcomingProjectMilestones") {
if (!$userpermissions["milestones"]["view"]) {
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "$errtxt<br>$noperm");
$template->display("error.tpl");
die();
}
// Check if the current user belongs to the project
if (!chkproject($userid, $id)) {
$errtxt = $langfile["notyourproject"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "$errtxt<br>$noperm");
$template->display("error.tpl");
die();
}
// Get upcoming milestones, that is milestones with a start date in the future
$upcomingStones = $milestone->getUpcomingProjectMilestones($id);
$upcomingProjectStones["items"] = $upcomingStones;
$upcomingProjectStones["count"] = count($upcomingStones);
echo json_encode($upcomingProjectStones);
}