-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvw_tasks.php
More file actions
404 lines (361 loc) · 15.7 KB
/
Copy pathvw_tasks.php
File metadata and controls
404 lines (361 loc) · 15.7 KB
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<?php /* TASKS $Id: vw_tasks.php,v 1.2 2007/06/19 11:43:05 pedroix Exp $ */
GLOBAL $m, $a, $project_id, $f, $task_status, $min_view, $query_string, $durnTypes, $tpl;
GLOBAL $task_sort_item1, $task_sort_type1, $task_sort_order1;
GLOBAL $task_sort_item2, $task_sort_type2, $task_sort_order2;
GLOBAL $user_id, $dPconfig, $currentTabId, $currentTabName, $canEdit, $showEditCheckbox;
/* tasks.php
This file contains common task list rendering code used by
modules/tasks/index.php and modules/projects/vw_tasks.php
in
External used variables:
* $min_view: hide some elements when active (used in the vw_tasks.php)
* $project_id
* $f
* $query_string
*/
if (empty($query_string)) {
$query_string = "?m=$m&a=$a";
}
// Number of columns (used to calculate how many columns to span things through)
$cols = 13;
/****
// Let's figure out which tasks are selected
*/
global $tasks_opened;
global $tasks_closed;
$tasks_closed = array();
$tasks_opened = $AppUI->getState('tasks_opened');
if(!$tasks_opened){
$tasks_opened = array();
}
$q = new DBQuery();
$q->addQuery('task_id');
$q->addTable('tasks');
if ($project_id)
$q->addWhere('task_project='.$project_id);
$q->addWhere('task_dynamic=1');
$all_tasks = $q->loadList();
foreach ($all_tasks as $key => $open_task) {
$tasks_opened[] = $open_task['task_id'];
}
$task_id = intval( dPgetParam( $_GET, 'task_id', 0 ) );
$q = new DBQuery;
$pinned_only = intval( dPgetParam( $_GET, 'pinned', 0) );
if (isset($_GET['pin'])) {
$pin = intval( dPgetParam( $_GET, 'pin', 0 ) );
$msg = '';
// load the record data
if($pin) {
$q->addTable('user_task_pin');
$q->addInsert('user_id', $AppUI->user_id);
$q->addInsert('task_id', $task_id);
}
else {
$q->setDelete('user_task_pin');
$q->addWhere('user_id = ' . $AppUI->user_id);
$q->addWhere('task_id = ' . $task_id);
}
if ( !$q->exec() ) {
$AppUI->setMsg( 'ins/del err', UI_MSG_ERROR, true );
}
else {
$q->clear();
}
$AppUI->redirect('', -1);
}
else if($task_id > 0) {
$tasks_opened[] = $task_id;
}
$AppUI->savePlace();
if( ($open_task_id = dPGetParam($_GET, 'open_task_id', 0)) > 0
&& !in_array($_GET['open_task_id'], $tasks_opened)) {
$tasks_opened[] = $_GET['open_task_id'];
}
// Closing tasks needs also to be within tasks iteration in order to
// close down all child tasks
if(($close_task_id = dPGetParam($_GET, 'close_task_id', 0)) > 0) {
closeOpenedTask($close_task_id);
}
// We need to save tasks_opened until the end because some tasks are closed within tasks iteration
/// End of tasks_opened routine
$durnTypes = dPgetSysVal( 'TaskDurationType' );
$taskPriority = dPgetSysVal( 'TaskPriority' );
$task_project = $project_id;
$task_sort_item1 = dPgetParam( $_GET, 'task_sort_item1', '' );
$task_sort_type1 = dPgetParam( $_GET, 'task_sort_type1', '' );
$task_sort_item2 = dPgetParam( $_GET, 'task_sort_item2', '' );
$task_sort_type2 = dPgetParam( $_GET, 'task_sort_type2', '' );
$task_sort_order1 = intval( dPgetParam( $_GET, 'task_sort_order1', 0 ) );
$task_sort_order2 = intval( dPgetParam( $_GET, 'task_sort_order2', 0 ) );
if (isset($_POST['show_task_options'])) {
$AppUI->setState('TaskListShowIncomplete', dPgetParam($_POST, 'show_incomplete', 0));
}
$showIncomplete = $AppUI->getState('TaskListShowIncomplete', 0);
$project =& new CProject;
// $allowedProjects = $project->getAllowedRecords($AppUI->user_id, 'project_id, project_name');
$allowedProjects = $project->getAllowedSQL($AppUI->user_id);
$working_hours = ($dPconfig['daily_working_hours']?$dPconfig['daily_working_hours']:8);
$q->addQuery('project_id, project_color_identifier, project_name');
$q->addQuery('SUM(task_duration * task_percent_complete * IF(task_duration_type = 24, '.$working_hours
.', task_duration_type)) / SUM(task_duration * IF(task_duration_type = 24, '.$working_hours
.', task_duration_type)) AS project_percent_complete');
$q->addQuery('company_name');
$q->addTable('projects','pr');
$q->leftJoin('tasks', 't1', 'pr.project_id = t1.task_project');
$q->leftJoin('companies', 'c', 'company_id = project_company');
$q->addWhere('t1.task_id = t1.task_parent');
$q->addWhere('project_id='.$project_id);
if ( count($allowedProjects)) {
$q->addWhere($allowedProjects);
}
$q->addGroup('project_id');
$q->addOrder('project_name');
$psql = $q->prepare();
$q->addQuery('project_id, COUNT(t1.task_id) as total_tasks');
$psql2 = $q->prepare();
$q->clear();
$perms =& $AppUI->acl();
$projects = array();
if ($canViewTasks) {
$prc = db_exec( $psql );
echo db_error();
while ($row = db_fetch_assoc( $prc )) {
$projects[$row['project_id']] = $row;
}
$prc2 = db_exec( $psql2 );
echo db_error();
while ($row2 = db_fetch_assoc( $prc2 )) {
$projects[$row2["project_id"]] = ((!($projects[$row2["project_id"]]))?array():$projects[$row2["project_id"]]);
array_push($projects[$row2["project_id"]], $row2);
}
}
$q->addQuery('t.task_id, task_parent, task_name');
$q->addQuery('task_start_date, task_end_date, task_dynamic');
$q->addQuery('count(t.task_parent) as children');
$q->addQuery('task_pinned, pin.user_id as pin_user');
$q->addQuery('task_priority, task_percent_complete');
$q->addQuery('task_duration, task_duration_type');
$q->addQuery('task_project');
$q->addQuery('task_access, task_type');
$q->addQuery('task_description, task_owner, task_status');
$q->addQuery('usernames.user_username, usernames.user_id');
$q->addQuery('assignees.user_username as assignee_username');
$q->addQuery('count(distinct assignees.user_id) as assignee_count');
$q->addQuery('co.contact_first_name, co.contact_last_name');
$q->addQuery('task_milestone');
$q->addQuery('count(distinct f.file_task) as file_count');
$q->addQuery('tlog.task_log_problem');
$q->addQuery('evtq.queue_id');
$q->addTable('tasks','t');
$mods = $AppUI->getActiveModules();
if (!empty($mods['history']) && !getDenyRead('history')) {
$q->addQuery('MAX(history_date) as last_update');
$q->leftJoin('history', 'h', 'history_item = t.task_id AND history_table=\'tasks\'');
}
$q->leftJoin('projects', 'p', 'p.project_id = task_project');
$q->leftJoin('users', 'usernames', 'task_owner = usernames.user_id');
$q->leftJoin('user_tasks', 'ut', 'ut.task_id = t.task_id');
$q->leftJoin('users', 'assignees', 'assignees.user_id = ut.user_id');
$q->leftJoin('contacts', 'co', 'co.contact_id = usernames.user_contact');
$q->leftJoin('task_log', 'tlog', 'tlog.task_log_task = t.task_id AND tlog.task_log_problem > 0');
$q->leftJoin('files', 'f', 't.task_id = f.file_task');
$q->leftJoin('user_task_pin', 'pin', 't.task_id = pin.task_id AND pin.user_id = ' . $AppUI->user_id);
//$user_id = $user_id ? $user_id : $AppUI->user_id;
$q->leftJoin('event_queue', 'evtq', 't.task_id = evtq.queue_origin_id AND evtq.queue_module = "tasks"');
//if ($f != 'children') {
// $q->addWhere('tasks.task_id = task_parent');
//}
//if ($project_id) {
$q->addWhere('task_project = ' . $project_id);
//}
$allowedProjects = $project->getAllowedSQL($AppUI->user_id, 'task_project');
if (count($allowedProjects)) {
$q->addWhere($allowedProjects);
}
$obj =& new CTask;
$allowedTasks = $obj->getAllowedSQL($AppUI->user_id, 't.task_id');
if ( count($allowedTasks)) {
$q->addWhere($allowedTasks);
}
$q->addGroup('t.task_id');
$q->addOrder('project_id, task_start_date');
if ($canViewTasks) {
$tasks = $q->loadList();
}
// POST PROCESSING TASKS
foreach ($tasks as $row) {
//add information about assigned users into the page output
$q->clear();
$q->addQuery('ut.user_id, u.user_username');
$q->addQuery('contact_email, ut.perc_assignment, SUM(ut.perc_assignment) AS assign_extent');
$q->addQuery('contact_first_name, contact_last_name');
$q->addTable('user_tasks', 'ut');
$q->leftJoin('users', 'u', 'u.user_id = ut.user_id');
$q->leftJoin('contacts', 'c', 'u.user_contact = c.contact_id');
$q->addWhere('ut.task_id = ' . $row['task_id']);
$q->addGroup('ut.user_id');
$q->addOrder('perc_assignment desc, user_username');
$assigned_users = array ();
$row['task_assigned_users'] = $q->loadList();
$q->addQuery('count(*) as children');
$q->addTable('tasks');
$q->addWhere('task_parent = ' . $row['task_id']);
$q->addWhere('task_id <> task_parent');
$row['children'] = $q->loadResult();
$row['style'] = taskstyle_pd($row);
$row['canEdit'] = !getDenyEdit( 'tasks', $row['task_id'] );
$row['canViewLog'] = $perms->checkModuleItem('task_log', 'view', $row['task_id']);
$i = count($projects[$row['task_project']]['tasks']) + 1;
$row['task_number'] = $i;
$row['node_id'] = 'node_'.$i.'-' . $row['task_id'];
if (strpos($row['task_duration'], '.') && $row['task_duration_type'] == 1) {
$row['task_duration'] = floor($row['task_duration']) . ':'
. round(60 * ($row['task_duration'] - floor($row['task_duration'])));
}
//pull the final task row into array
$projects[$row['task_project']]['tasks'][] = $row;
}
$showEditCheckbox = isset($canEditTasks) && $canEditTasks;
$AppUI->setState('tasks_opened', $tasks_opened);
foreach($projects as $k => $p) {
global $done;
$done = array();
if ( $task_sort_item1 != '' ) {
if ( $task_sort_item2 != '' && $task_sort_item1 != $task_sort_item2 ) {
$p['tasks'] = array_csort($p['tasks'],
$task_sort_item1, $task_sort_order1, $task_sort_type1,
$task_sort_item2, $task_sort_order2, $task_sort_type2 );
}
else {
$p['tasks'] = array_csort($p['tasks'], $task_sort_item1, $task_sort_order1, $task_sort_type1 );
}
}
else {
/* we have to calculate the end_date via start_date+duration for
** end='0000-00-00 00:00:00' if array_csort function is not used
** as it is normally done in array_csort function in order to economise
** cpu time as we have to go through the array there anyway
*/
for ($j=0; $j < count($p['tasks']); $j++) {
if ( $p['tasks'][$j]['task_end_date'] == '0000-00-00 00:00:00' || $p['tasks'][$j]['task_end_date'] == NULL) {
$p['tasks'][$j]['task_end_date'] = calcEndByStartAndDuration($p['tasks'][$j]);
}
}
}
$p['tasks_count'] = count($p['tasks']);
$projects[$k] = $p;
}
$durnTypes = dPgetSysVal( 'TaskDurationType' );
$tempoTask = new CTask();
$userAlloc = $tempoTask->getAllocation('user_id');
?>
<form name='frm_tasks'>
<table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">
<tr>
<th width="10"> </th>
<th width="20"><?php echo $AppUI->_('Work');?></th>
<th align="center"><?php echo $AppUI->_('P'); ?></th>
<th align="center"><?php echo $AppUI->_('A'); ?></th>
<th align="center"><?php echo $AppUI->_('T'); ?></th>
<th align="center"><?php echo $AppUI->_('R'); ?></th>
<th align="center"><?php echo $AppUI->_('I'); ?></th>
<th align="center"><?php echo $AppUI->_('Log');?></th>
<th width="40%"><?php echo $AppUI->_('Task Name');?></th>
<?php if ($PROJDESIGN_CONFIG['show_task_descriptions']) { ?>
<th width="200"><?php echo $AppUI->_('Task Description');?></th>
<?php } ?>
<th nowrap="nowrap"><?php echo $AppUI->_('Task Owner');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Start');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Duration');?> </th>
<th nowrap="nowrap"><?php echo $AppUI->_('Finish');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Assigned Users')?></th>
<?php if ($showEditCheckbox) { echo '<th width="1"><input type="checkbox" onclick="mult_sel(this, \'selected_task_\', \'frm_tasks\')" name="multi_check"/></th>'; }?>
</tr>
<?php
reset( $projects );
foreach ($projects as $k => $p) {
$tnums = count( @$p['tasks'] );
// don't show project if it has no tasks
// patch 2.12.04, show project if it is the only project in view
if ($tnums > 0 || $project_id == $p['project_id']) {
//echo '<pre>'; print_r($p); echo '</pre>';
global $done;
$done = array();
if ( $task_sort_item1 != "" )
{
if ( $task_sort_item2 != "" && $task_sort_item1 != $task_sort_item2 )
$p['tasks'] = array_csort($p['tasks'], $task_sort_item1, $task_sort_order1, $task_sort_type1
, $task_sort_item2, $task_sort_order2, $task_sort_type2 );
else $p['tasks'] = array_csort($p['tasks'], $task_sort_item1, $task_sort_order1, $task_sort_type1 );
} else {
/* we have to calculate the end_date via start_date+duration for
** end='0000-00-00 00:00:00' if array_csort function is not used
** as it is normally done in array_csort function in order to economise
** cpu time as we have to go through the array there anyway
*/
for ($j=0; $j < count($p['tasks']); $j++) {
if ( $p['tasks'][$j]['task_end_date'] == '0000-00-00 00:00:00' ) {
$p['tasks'][$j]['task_end_date'] = calcEndByStartAndDuration($p['tasks'][$j]);
}
}
}
for ($i=0; $i < $tnums; $i++) {
$t = $p['tasks'][$i];
if ($t["task_parent"] == $t["task_id"]) {
$is_opened = in_array($t["task_id"], $tasks_opened);
showtask_pd( $t, 0, $is_opened );
if($is_opened || $t["task_dynamic"] == 0){
findchild_pd( $p['tasks'], $t["task_id"] );
}
}
if ($search_text) {
if (strpos($t['task_name'], $search_text) !== false || strpos($t['task_description'], $search_text) !== false)
showtask_pd($t, 1, false);
}
}
// check that any 'orphaned' user tasks are also display
for ($i=0; $i < $tnums; $i++) {
if ( !in_array( $p['tasks'][$i]["task_id"], $done ) ) {
if($p['tasks'][$i]["task_dynamic"] && in_array( $p['tasks'][$i]["task_parent"], $tasks_closed)) {
closeOpenedTask($p['tasks'][$i]["task_id"]);
}
if(in_array($p['tasks'][$i]["task_parent"], $tasks_opened)){
showtask_pd( $p['tasks'][$i], 1, false);
}
}
}
}
}
$AppUI->setState("tasks_opened", $tasks_opened);
?>
</table>
</form>
<table>
<tr>
<td><?php echo $AppUI->_('Key');?>:</td>
<th> P </th>
<td>=<?php echo $AppUI->_('Priority');?></td>
<th> A </th>
<td>=<?php echo $AppUI->_('Access');?></td>
<th> T </th>
<td>=<?php echo $AppUI->_('Type');?></td>
<th> R </th>
<td>=<?php echo $AppUI->_('Reminder');?></td>
<th> I </th>
<td>=<?php echo $AppUI->_('Inactive');?></td>
<td> </td>
<td style="border-style:solid;border-width:1px" bgcolor="#ffffff"> </td>
<td>=<?php echo $AppUI->_('Future Task');?></td>
<td> </td>
<td style="border-style:solid;border-width:1px" bgcolor="#e6eedd"> </td>
<td>=<?php echo $AppUI->_('Started and on time');?></td>
<td style="border-style:solid;border-width:1px" bgcolor="#ffeebb"> </td>
<td>=<?php echo $AppUI->_('Should have started');?></td>
<td> </td>
<td style="border-style:solid;border-width:1px" bgcolor="#CC6666"> </td>
<td>=<?php echo $AppUI->_('Overdue');?></td>
<td> </td>
<td style="border-style:solid;border-width:1px" bgcolor="#aaddaa"> </td>
<td>=<?php echo $AppUI->_('Done');?></td>
</tr>
</table>