-
Notifications
You must be signed in to change notification settings - Fork 123
/
cleanup_functions.php
4372 lines (3890 loc) · 157 KB
/
cleanup_functions.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
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if (!defined('W2P_BASE_DIR')) {
die('You should not access this file directly.');
}
/**
* This file exists in order to list individual functions which need to be
* cleaned up, reorganized or eliminated based on usage. Before you touch
* these, please ensure there are Unit Tests to validate that things work
* before and after.
*
*
* WARNING: The functions in this file are likely to move to other files as they
* are updated. Since this file is included within main_functions.php
* this shouldn't be a problem.
*/
/**
* There is an issue with international UTF characters, when stored in the
* database an accented letter actually takes up two letters per say in the
* field length, this is a problem with costcodes since they are limited in
* size so saving a costcode as REDACI�N would actually save REDACI� since the
* accent takes two characters, so lets unaccent them, other languages should
* add to the replacements array too...
*/
//
function cleanText($text) {
//This text file is not utf, its iso so we have to decode/encode
$text = utf8_decode($text);
$trade = array('�' => 'a', '�' => 'a', '�' => 'a', '�' => 'a', '�' => 'a', '�' => 'A', '�' => 'A', '�' => 'A', '�' => 'A', '�' => 'A', '�' => 'e', '�' => 'e', '�' => 'e', '�' => 'e', '�' => 'E', '�' => 'E', '�' => 'E', '�' => 'E', '�' => 'i', '�' => 'i', '�' => 'i', '�' => 'i', '�' => 'I', '�' => 'I', '�' => 'I', '�' => 'I', '�' => 'o', '�' => 'o', '�' => 'o', '�' => 'o', '�' => 'o', '�' => 'O', '�' => 'O', '�' => 'O', '�' => 'O', '�' => 'O', '�' => 'u', '�' => 'u', '�' => 'u', '�' => 'u', '�' => 'U', '�' => 'U', '�' => 'U', '�' => 'U', '�' => 'N', '�' => 'n');
$text = strtr($text, $trade);
$text = utf8_encode($text);
return $text;
}
function is_task_in_gantt_arr($task) {
global $gantt_arr;
$n = count($gantt_arr);
for ($x = 0; $x < $n; $x++) {
if ($gantt_arr[$x][0]['task_id'] == $task['task_id']) {
return true;
}
}
return false;
}
function notifyHR($address, $notUsed, $uaddress, $uusername, $logname, $notUsed2, $userid) {
global $AppUI;
$mail = new w2p_Utilities_Mail();
if ($mail->ValidEmail($address)) {
//TODO: why aren't we actually using this $email variable?
if ($mail->ValidEmail($AppUI->user_email)) {
$email = $AppUI->user_email;
} else {
$email = w2PgetConfig('admin_email');
}
$mail->To($address);
$emailManager = new w2p_Output_EmailManager($AppUI);
$body = $emailManager->notifyHR($uusername, $logname, $uaddress, $userid);
$mail->Subject('New External User Created');
$mail->Body($body);
$mail->Send();
}
}
function notifyNewUserCredentials($address, $username, $logname, $logpwd) {
global $AppUI;
$mail = new w2p_Utilities_Mail();
if ($mail->ValidEmail($address)) {
//TODO: why aren't we actually using this $email variable?
if ($mail->ValidEmail($AppUI->user_email)) {
$email = $AppUI->user_email;
} else {
$email = w2PgetConfig('admin_email');
}
$mail->To($address);
$emailManager = new w2p_Output_EmailManager($AppUI);
$body = $emailManager->notifyNewUserCredentials($username, $logname, $logpwd);
$mail->Subject('New Account Created - web2Project Project Management System');
$mail->Body($body);
$mail->Send();
}
}
function clean_value($str) {
$bad_values = array("'");
return str_replace($bad_values, '', $str);
}
function strUTF8Decode($text) {
if (extension_loaded('mbstring')) {
$encoding = mb_detect_encoding($text.' ');
}
if (function_exists('iconv')){
$text = mb_convert_encoding($text, 'UTF-8', $encoding);
//iconv($encoding, 'UTF-8', $text);
} elseif (function_exists('utf8_decode')) {
$text = utf8_decode($text);
}
// mb functions don't seam to work well here for some reason as the output gets corrupted.
// iconv is doing the job just fine though
return $text;
}
/**
* utility functions for the preparation of task data for GANTT PDF
*
* @todo some of these functions are not needed, need to trim this down
*
*/
// PYS : utf_8 decoding as suggested in Vbulletin #3987
function strEzPdf($text) {
if (function_exists('iconv') && function_exists('mb_detect_encoding')) {
$text = iconv(mb_detect_encoding($text." "), 'UTF-8', $text);
return $text;
} else {
return $text;
}
}
/**
* smart_slice : recursive function used to slice the task array whlie
* minimizing the potential number of task dependencies between two sub_arrays
* Each sub_array is LENGTH elements long maximum
* It is shorter if
* - either a dynamic task is between indices LENGTH-3 and LENGTH-1 : in this
* case, the milestone is EXCLUDED from the lower sub_array
* - or a milestone a MILESTONE is between indices LENGTH-2 and LENGTH-1 : in
* this case the milestone is INCLUDED in the lower sub_array
*/
function smart_slice( $arr, $showNoMilestones, $notUsed, $day_diff ) {
global $gtask_sliced;
$length = ($showNoMilestones) ? 26 : 25;
if ($day_diff < 90) {
$length = $length - 2;
} else if ($day_diff >=90 && $day_diff < 1096) {
$length = $length;
} else {
$length++;
}
if ( count($arr) > $length ) {
$found = 0 ;
for ( $i = $length-3 ; $i<$length ; $i++ ) {
if ( $arr[$i][0]['task_dynamic'] != 0 ) {
$found = $i ;
}
}
if ( !$found ) {
for ( $i = $length-1 ; $i > $length-3 ; $i-- ) {
if ( $arr[$i][0]['task_milestone'] != 0 ) {
$found = $i ;
}
}
if ( !$found ) {
if ( $arr[$length][0]['task_milestone'] == 0 ) {
$cut = $length ; // No specific task => standard cut
} else {
$cut = $length - 1 ; // No orphan milestone
}
} else {
$cut = $found + 1 ; // include found milestone in lower level array
}
} else {
$cut = $found ; //include found dynamic task in higher level array
}
$gtask_sliced[] = array_slice( $arr, 0, $cut );
} else {
$gtask_sliced[] = $arr ;
}
return $gtask_sliced ;
}
/**
*
* END OF GANTT PDF UTILITY FUNCTIONS
*
*/
/**
* This is a kludgy mess because of how the arraySelectTree function is used..
* it expects - nay, demands! - that the first element of the subarray is the
* id and the third is the parent id. In most cases, that is fine.. in this
* one we're using the existing ACL-respecting functions and it has additional
* fields in "improper" places.
*/
function temp_filterArrayForSelectTree($projectData) {
unset($projectData['project_id']);
unset($projectData['project_color_identifier']);
unset($projectData['project_name']);
unset($projectData['project_start_date']);
unset($projectData['project_end_date']);
unset($projectData['project_company']);
unset($projectData['project_parent']);
unset($projectData[1]);
unset($projectData[3]);
unset($projectData[4]);
unset($projectData[5]);
$projectData[6] = ($projectData[0] == $projectData[6]) ? '' : $projectData[6];
return array_values($projectData);
}
/**
* The includes/permissions.php file has been ported here because it held a
* group of public functions for permission checking. And that is so it stays
* on one place only. Permission flags used in the DB
*/
define('PERM_DENY', '0');
define('PERM_EDIT', '-1');
define('PERM_READ', '1');
define('PERM_ALL', '-1');
// TODO: getDeny* should return true/false instead of 1/0
function getReadableModule() {
$q = new w2p_Database_Query;
$q->addTable('modules');
$q->addQuery('mod_directory');
$q->addWhere('mod_active = 1');
$q->addOrder('mod_ui_order');
$modules = $q->loadColumn();
foreach ($modules as $mod) {
if (canAccess($mod)) {
return $mod;
}
}
return null;
}
/**
* This function is used to check permissions.
*/
function checkFlag($flag, $perm_type, $old_flag) {
if ($old_flag) {
return (($flag == PERM_DENY) || // permission denied
($perm_type == PERM_EDIT && $flag == PERM_READ) // we ask for editing, but are only allowed to read
) ? 0 : 1;
} else {
if ($perm_type == PERM_READ) {
return ($flag != PERM_DENY) ? 1 : 0;
} else {
// => $perm_type == PERM_EDIT
return ($flag == $perm_type) ? 1 : 0;
}
}
}
/**
* This function checks certain permissions for
* a given module and optionally an item_id.
*
* $perm_type can be PERM_READ or PERM_EDIT
*/
function isAllowed($perm_type, $mod, $item_id = 0) {
$invert = false;
switch ($perm_type) {
case PERM_READ:
$perm_type = 'view';
break;
case PERM_EDIT:
$perm_type = 'edit';
break;
case PERM_ALL:
$perm_type = 'edit';
break;
case PERM_DENY:
$perm_type = 'view';
$invert = true;
break;
}
$allowed = getPermission($mod, $perm_type, $item_id);
if ($invert) {
return !$allowed;
}
return $allowed;
}
function getPermission($mod, $perm, $item_id = 0) {
// First check if the module is readable, i.e. has view permission.
$perms = &$GLOBALS['AppUI']->acl();
$result = $perms->checkModule($mod, $perm);
// If we have access then we need to ensure we are not denied access to the particular
// item.
if ($result && $item_id) {
if ($perms->checkModuleItemDenied($mod, $perm, $item_id)) {
$result = false;
}
}
// If denied we need to check if we are allowed the task. This can be done
// a lot better in PHPGACL, but is here for compatibility.
if ($mod == 'tasks' && !$result && $item_id > 0) {
$q = new w2p_Database_Query;
$q->addTable('tasks');
$q->addQuery('task_project');
$q->addWhere('task_id = ' . (int)$item_id);
$project_id = $q->loadResult();
$result = getPermission('projects', $perm, $project_id);
}
return $result;
}
function canView($mod, $item_id = 0) {
return getPermission($mod, 'view', $item_id);
}
function canEdit($mod, $item_id = 0) {
return getPermission($mod, 'edit', $item_id);
}
function canAdd($mod, $item_id = 0) {
return getPermission($mod, 'add', $item_id);
}
function canDelete($mod, $item_id = 0) {
return getPermission($mod, 'delete', $item_id);
}
function canAccess($mod) {
return getPermission($mod, 'access');
}
function buildTaskTree($task_data, $depth = 0, $projTasks, $all_tasks, $parents, $task_parent, $task_id) {
$output = '';
$projTasks[$task_data['task_id']] = $task_data['task_name'];
$task_data['task_name'] = mb_strlen($task_data[1]) > 45 ? mb_substr($task_data['task_name'], 0, 45) . '...' : $task_data['task_name'];
$selected = $task_data['task_id'] == $task_parent ? ' selected="selected"' : '';
$output .= '<option value="' . $task_data['task_id'] . '"' . $selected . '>' . str_repeat(' ', $depth * 3) . w2PFormSafe($task_data['task_name']) . '</option>';
if (isset($parents[$task_data['task_id']])) {
foreach ($parents[$task_data['task_id']] as $child_task) {
if ($child_task != $task_id) {
$output .= buildTaskTree($all_tasks[$child_task], ($depth + 1), $projTasks, $all_tasks, $parents, $task_parent, $task_id);
}
}
}
return $output;
}
// from modules/tasks/addedit.php and modules/projectdesigners/vw_actions.php
function build_date_list(&$date_array, $row) {
global $project;
// if this task_dynamic is not tracked, set end date to proj start date
if (!in_array($row['task_dynamic'], CTask::$tracked_dynamics)) {
$date = new w2p_Utilities_Date($project->project_start_date);
} elseif ($row['task_milestone'] == 0) {
$date = new w2p_Utilities_Date($row['task_end_date']);
} else {
$date = new w2p_Utilities_Date($row['task_start_date']);
}
$sdate = $date->format('%d/%m/%Y');
$shour = $date->format('%H');
$smin = $date->format('%M');
$date_array[$row['task_id']] = array($row['task_name'], $sdate, $shour, $smin);
}
// from modules/tasks/ae_dates.php
function cal_work_day_conv($val) {
global $locale_char_set, $AppUI;
setlocale(LC_TIME, 'en');
$wk = Date_Calc::getCalendarWeek(null, null, null, '%a', LOCALE_FIRST_DAY);
setlocale(LC_ALL, $AppUI->user_lang);
$day_name = $AppUI->_($wk[($val - LOCALE_FIRST_DAY) % 7]);
$day_name = utf8_encode($day_name);
return htmlspecialchars($day_name, ENT_COMPAT, $locale_char_set);
}
// from modules/tasks/tasks.class.php
//This kludgy function echos children tasks as threads
function showtask(&$arr, $level = 0, $notUsed = true, $today_view = false) {
global $AppUI, $userAlloc, $showEditCheckbox;
global $m, $a, $history_active, $expanded;
$durnTypes = w2PgetSysVal('TaskDurationType');
//Check for Tasks Access
$tmpTask = new CTask();
$tmpTask->load($arr['task_id']);
$canAccess = $tmpTask->canAccess();
if (!$canAccess) {
return (false);
}
$htmlHelper = new w2p_Output_HTMLHelper($AppUI);
$htmlHelper->df .= ' ' . $AppUI->getPref('TIMEFORMAT');
$show_all_assignees = w2PgetConfig('show_all_task_assignees', false);
// prepare coloured highlight of task time information
$class = w2pFindTaskComplete($arr['task_start_date'], $arr['task_end_date'], $arr['task_percent_complete']);
$jsTaskId = 'project_' . $arr['task_project'] . '_level-' . $level . '-task_' . $arr['task_id'] . '_';
if ($expanded) {
$s = '<tr id="' . $jsTaskId . '" class="'.$class.'">';
} else {
$s = '<tr id="' . $jsTaskId . '" class="'.$class.'" ' . (($level > 0 && !($m == 'tasks' && $a == 'view')) ? 'style="display:none"' : '') . '>';
}
// edit icon
$s .= '<td class="data _edit">';
$canEdit = ($arr['task_represents_project']) ? false : true;
$canViewLog = true;
if ($canEdit) {
$s .= '<a href="?m=tasks&a=addedit&task_id=' . $arr['task_id'] . '">' . w2PshowImage('icons/pencil.gif', 12, 12) . '</a>' ;
}
$s .= '</td>';
// pinned
$pin_prefix = $arr['task_pinned'] ? '' : 'un';
$s .= ('<td class="data _pin"><a href="?m=tasks&pin=' . ($arr['task_pinned'] ? 0 : 1) . '&task_id=' . $arr['task_id'] . '">' . '<img src="' . w2PfindImage('icons/' . $pin_prefix . 'pin.gif') . '" border="0" alt="" />' . '</a></td>');
// New Log
if (isset($arr['task_log_problem']) && $arr['task_log_problem'] > 0) {
$s .= ('<td class="data"><a href="?m=tasks&a=view&task_id=' . $arr['task_id'] . '&tab=0&problem=1">' . w2PshowImage('icons/dialog-warning5.png', 16, 16, 'Problem', 'Problem!') . '</a></td>');
} elseif ($canViewLog && $arr['task_dynamic'] != 1 && 0 == $arr['task_represents_project']) {
$s .= ('<td class="data"><a href="?m=tasks&a=view&task_id=' . $arr['task_id'] . '&tab=1">' . w2PshowImage('edit_add.png') . '</a></td>');
} else {
$s .= '<td class="center">' . $AppUI->_('-') . '</td>';
}
// percent complete and priority
$s .= $htmlHelper->createCell('task_percent_complete', $arr['task_percent_complete']);
$s .= $htmlHelper->createCell('task_priority', $arr['task_priority']);
$s .= $htmlHelper->createCell('user_task_priority', $arr['user_task_priority']);
// dots
$s .= '<td style="width: ' . (($today_view) ? '50%' : '90%') . '" class="data _name">';
//level
if ($level == -1) {
$s .= '...';
}
for ($y = 0; $y < $level; $y++) {
if ($y + 1 == $level) {
$image = w2PfindImage('corner-dots.gif', $m);
} else {
$image = w2PfindImage('shim.gif', $m);
}
$s .= '<img src="' . $image . '" width="16" height="12" border="0" alt="" />';
}
if ($arr['task_description']) {
$s .= w2PtoolTip('Task Description', $arr['task_description'], true);
}
$open_link = '<a href="javascript: void(0);"><img onclick="expand_collapse(\'' . $jsTaskId . '\', \'tblProjects\',\'\',' . ($level + 1) . ');" id="' . $jsTaskId . '_collapse" src="' . w2PfindImage('icons/collapse.gif') . '" border="0" align="center" ' . (!$expanded ? 'style="display:none"' : '') . ' alt="" /><img onclick="expand_collapse(\'' . $jsTaskId . '\', \'tblProjects\',\'\',' . ($level + 1) . ');" id="' . $jsTaskId . '_expand" src="' . w2PfindImage('icons/expand.gif') . '" border="0" align="center" ' . ($expanded ? 'style="display:none"' : '') . ' alt="" /></a>';
if (isset($arr['task_nr_of_children']) && $arr['task_nr_of_children']) {
$is_parent = true;
} else {
$is_parent = false;
}
if ($arr['task_milestone'] > 0) {
$s .= ' <a href="./index.php?m=tasks&a=view&task_id=' . $arr['task_id'] . '" ><b>' . $arr['task_name'] . '</b></a> <img src="' . w2PfindImage('icons/milestone.gif') . '" border="0" alt="" /></td>';
} elseif ($arr['task_dynamic'] == '1' || $is_parent) {
if (!$today_view) {
$s .= $open_link;
}
if ($arr['task_dynamic'] == '1') {
$s .= ' <a href="./index.php?m=tasks&a=view&task_id=' . $arr['task_id'] . '" ><b><i>' . $arr['task_name'] . '</i></b></a>';
} else {
$s .= ' <a href="./index.php?m=tasks&a=view&task_id=' . $arr['task_id'] . '" >' . $arr['task_name'] . '</a>';
}
} else {
$s .= ' <a href="./index.php?m=tasks&a=view&task_id=' . $arr['task_id'] . '" >' . $arr['task_name'] . '</a>';
}
if ($arr['task_description']) {
$s .= w2PendTip();
}
$s .= '</td>';
if ($today_view) { // Show the project name
$s .= ('<td width="50%"><a href="./index.php?m=projects&a=view&project_id=' . $arr['task_project'] . '">' . '<div style="display:inline-block;padding: 2px 3px;background-color:#' . $arr['project_color_identifier'] . ';color:' . bestColor($arr['project_color_identifier']) . '">' . $arr['project_name'] . '</div>' . '</a></td>');
} else {
$s .= $htmlHelper->createCell('task_owner', $arr['owner']);
}
if (isset($arr['task_assigned_users']) && count($arr['task_assigned_users'])) {
$assigned_users = $arr['task_assigned_users'];
$a_u_tmp_array = array();
if ($show_all_assignees) {
$s .= '<td class="data">';
foreach ($assigned_users as $val) {
$a_u_tmp_array[] = ('<a href="?m=admin&a=viewuser&user_id=' . $val['user_id'] . '"' . 'title="' . (w2PgetConfig('check_overallocation') ? $AppUI->_('Extent of Assignment') . ':' . $userAlloc[$val['user_id']]['charge'] . '%; ' . $AppUI->_('Free Capacity') . ':' . $userAlloc[$val['user_id']]['freeCapacity'] . '%' : '') . '">' . $val['assignee'] . ' (' . $val['perc_assignment'] . '%)</a>');
}
$s .= join(', <br />', $a_u_tmp_array) . '</td>';
} else {
$s .= ('<td class="data">' . '<a href="?m=admin&a=viewuser&user_id=' . $assigned_users[0]['user_id'] . '" title="' . (w2PgetConfig('check_overallocation') ? $AppUI->_('Extent of Assignment') . ':' . $userAlloc[$assigned_users[0]['user_id']]['charge'] . '%; ' . $AppUI->_('Free Capacity') . ':' . $userAlloc[$assigned_users[0]['user_id']]['freeCapacity'] . '%' : '') . '">' . $assigned_users[0]['assignee'] . ' (' . $assigned_users[0]['perc_assignment'] . '%)</a>');
if ($arr['assignee_count'] > 1) {
$s .= (' <a href="javascript: void(0);" onclick="toggle_users(' . "'users_" . $arr['task_id'] . "'" . ');" title="' . join(', ', $a_u_tmp_array) . '">(+' . ($arr['assignee_count'] - 1) . ')</a>' . '<span style="display: none" id="users_' . $arr['task_id'] . '">');
$a_u_tmp_array[] = $assigned_users[0]['assignee'];
for ($i = 1, $i_cmp = count($assigned_users); $i < $i_cmp; $i++) {
$a_u_tmp_array[] = $assigned_users[$i]['assignee'];
$s .= ('<br /><a href="?m=admin&a=viewuser&user_id=' . $assigned_users[$i]['user_id'] . '" title="' . (w2PgetConfig('check_overallocation') ? $AppUI->_('Extent of Assignment') . ':' . $userAlloc[$assigned_users[$i]['user_id']]['charge'] . '%; ' . $AppUI->_('Free Capacity') . ':' . $userAlloc[$assigned_users[$i]['user_id']]['freeCapacity'] . '%' : '') . '">' . $assigned_users[$i]['assignee'] . ' (' . $assigned_users[$i]['perc_assignment'] . '%)</a>');
}
$s .= '</span>';
}
$s .= '</td>';
}
} elseif (!$today_view) {
// No users asigned to task
$s .= '<td class="data">-</td>';
}
// duration or milestone
$s .= $htmlHelper->createCell('task_start_datetime', $arr['task_start_date']);
$s .= $htmlHelper->createCell('task_duration', $arr['task_duration'] . ' ' . mb_substr($AppUI->_($durnTypes[$arr['task_duration_type']]), 0, 1));
$s .= $htmlHelper->createCell('task_end_datetime', $arr['task_end_date']);
if ($today_view) {
$s .= $htmlHelper->createCell('task_due_in', $arr['task_due_in']);
} elseif ($history_active) {
$s .= $htmlHelper->createCell('last_update', $arr['last_update']);
}
// Assignment checkbox
if ($showEditCheckbox) {
$s .= ('<td class="data">' . '<input type="checkbox" name="selected_task[' . $arr['task_id'] . ']" value="' . $arr['task_id'] . '"/></td>');
}
$s .= '</tr>'."\n";
return $s;
}
//This kludgy function echos children tasks as threads on project designer (_pd)
//TODO: modules/projectdesigner/projectdesigner.class.php
function showtask_pd(&$arr, $level = 0, $today_view = false) {
global $AppUI, $w2Pconfig, $done, $userAlloc, $showEditCheckbox;
global $task_access, $PROJDESIGN_CONFIG, $m, $expanded;
$durnTypes = w2PgetSysVal('TaskDurationType');
//Check for Tasks Access
$tmpTask = new CTask();
$tmpTask->load($arr['task_id']);
$canAccess = $tmpTask->canAccess();
if (!$canAccess) {
return (false);
}
$htmlHelper = new w2p_Output_HTMLHelper($AppUI);
$htmlHelper->df .= ' ' . $AppUI->getPref('TIMEFORMAT');
$htmlHelper->stageRowData($arr);
$types = w2Pgetsysval('TaskType');
$show_all_assignees = $w2Pconfig['show_all_task_assignees'] ? true : false;
$done[] = $arr['task_id'];
// prepare coloured highlight of task time information
$class = w2pFindTaskComplete($arr['task_start_date'], $arr['task_end_date'], $arr['task_percent_complete']);
$jsTaskId = 'task_proj_' . $arr['task_project'] . '_level-' . $level . '-task_' . $arr['task_id'] . '_';
if ($expanded) {
$s = '<tr id="' . $jsTaskId . '" class="'.$class.'" onclick="select_row(\'selected_task\', \'' . $arr['task_id'] . '\', \'frm_tasks\')">'; // edit icon
} else {
$s = '<tr id="' . $jsTaskId . '" class="'.$class.'" onclick="select_row(\'selected_task\', \'' . $arr['task_id'] . '\', \'frm_tasks\')" ' . ($level ? 'style="display:none"' : '') . '>'; // edit icon
}
$s .= '<td class="data _edit">';
$canEdit = ($arr['task_represents_project']) ? false : true;
if ($canEdit) {
$s .= '<a href="?m=tasks&a=addedit&task_id=' . $arr['task_id'] . '">' . w2PshowImage('icons/pencil.gif', 12, 12) . '</a>';
}
$s .= '</td>';
// percent complete and priority
$s .= $htmlHelper->createCell('task_percent_complete', $arr['task_percent_complete']);
$s .= $htmlHelper->createCell('task_priority', $arr['task_priority']);
$s .= $htmlHelper->createCell('user_task_priority', $arr['user_task_priority']);
// access
$s .= '<td class="data">';
$s .= mb_substr($task_access[$arr['task_access']], 0, 3);
$s .= '</td>';
// type
$s .= '<td class="data">';
$s .= mb_substr($types[$arr['task_type']], 0, 3);
$s .= '</td>';
// type
$s .= '<td class="data">';
$s .= $arr['queue_id'] ? 'Yes' : '';
$s .= '</td>';
// inactive
$s .= '<td class="data">';
$s .= $arr['task_status'] == '-1' ? 'Yes' : '';
$s .= '</td>';
// add log
$s .= '<td align="center" nowrap="nowrap">';
if ($arr['task_dynamic'] != 1 && 0 == $arr['task_represents_project']) {
$s .= '<a href="?m=tasks&a=view&tab=1&project_id=' . $arr['task_project'] . '&task_id=' . $arr['task_id'] . '">' . w2PtoolTip('tasks', 'add work log to this task') . w2PshowImage('edit_add.png') . w2PendTip() . '</a>';
}
$s .= '</td>';
// dots
$s .= '<td style="width: ' . (($today_view) ? '20%' : '50%') . '" class="data _name">';
for ($y = 0; $y < $level; $y++) {
if ($y + 1 == $level) {
$image = w2PfindImage('corner-dots.gif', $m);
} else {
$image = w2PfindImage('shim.gif', $m);
}
$s .= '<img src="' . $image . '" width="16" height="12" border="0" alt="" />';
}
// name link
if ($arr['task_description']) {
$s .= w2PtoolTip('Task Description', $arr['task_description'], true);
}
$jsTaskId = 'task_proj_' . $arr['task_project'] . '_level-' . $level . '-task_' . $arr['task_id'] . '_';
$open_link = '<a href="javascript: void(0);" onclick="selected_task_' . $arr['task_id'] . '.checked=true"><img onclick="expand_collapse(\'' . $jsTaskId . '\', \'tblProjects\',\'\',' . ($level + 1) . ');" id="' . $jsTaskId . '_collapse" src="' . w2PfindImage('icons/collapse.gif', $m) . '" border="0" align="center" ' . (!$expanded ? 'style="display:none"' : '') . ' alt="" /><img onclick="expand_collapse(\'' . $jsTaskId . '\', \'tblProjects\',\'\',' . ($level + 1) . ');" id="' . $jsTaskId . '_expand" src="' . w2PfindImage('icons/expand.gif', $m) . '" border="0" align="center" ' . ($expanded ? 'style="display:none"' : '') . ' alt="" /></a>';
$taskObj = new CTask;
$taskObj->load($arr['task_id']);
if (count($taskObj->getChildren())) {
$is_parent = true;
} else {
$is_parent = false;
}
if ($arr['task_milestone'] > 0) {
$s .= ' <a href="./index.php?m=tasks&a=view&task_id=' . $arr['task_id'] . '" ><b>' . $arr['task_name'] . '</b></a> <img src="' . w2PfindImage('icons/milestone.gif', $m) . '" border="0" alt="" /></td>';
} elseif ($arr['task_dynamic'] == '1' || $is_parent) {
$s .= $open_link;
if ($arr['task_dynamic'] == '1') {
$s .= ' <a href="./index.php?m=tasks&a=view&task_id=' . $arr['task_id'] . '" ><b><i>' . $arr['task_name'] . '</i></b></a></td>';
} else {
$s .= ' <a href="./index.php?m=tasks&a=view&task_id=' . $arr['task_id'] . '" >' . $arr['task_name'] . '</a></td>';
}
} else {
$s .= ' <a href="./index.php?m=tasks&a=view&task_id=' . $arr['task_id'] . '" >' . $arr['task_name'] . '</a></td>';
}
if ($arr['task_description']) {
$s .= w2PendTip();
}
// task description
if ($PROJDESIGN_CONFIG['show_task_descriptions']) {
$s .= '<td align="justified">' . $arr['task_description'] . '</td>';
}
// task owner
$s .= $htmlHelper->createCell('task_owner', $arr['contact_name']);
$s .= $htmlHelper->createCell('task_start_datetime', $arr['task_start_date']);
// duration or milestone
$s .= $htmlHelper->createCell('task_duration', $arr['task_duration'] . ' ' . mb_substr($AppUI->_($durnTypes[$arr['task_duration_type']]), 0, 1));
$s .= $htmlHelper->createCell('task_end_datetime', $arr['task_end_date']);
if (isset($arr['task_assigned_users']) && ($assigned_users = $arr['task_assigned_users'])) {
$a_u_tmp_array = array();
if ($show_all_assignees) {
$s .= '<td align="left">';
foreach ($assigned_users as $val) {
$aInfo = '<a href="?m=admin&a=viewuser&user_id=' . $val['user_id'] . '"';
$aInfo .= 'title="' . (w2PgetConfig('check_overallocation') ? $AppUI->_('Extent of Assignment') . ':' . $userAlloc[$val['user_id']]['charge'] . '%; ' . $AppUI->_('Free Capacity') . ':' . $userAlloc[$val['user_id']]['freeCapacity'] . '%' : '') . '">';
$aInfo .= $val['contact_name'] . ' (' . $val['perc_assignment'] . '%)</a>';
$a_u_tmp_array[] = $aInfo;
}
$s .= join(', ', $a_u_tmp_array);
$s .= '</td>';
} else {
$s .= '<td align="left" nowrap="nowrap">';
$s .= '<a href="?m=admin&a=viewuser&user_id=' . $assigned_users[0]['user_id'] . '"';
$s .= 'title="' . (w2PgetConfig('check_overallocation') ? $AppUI->_('Extent of Assignment') . ':' . $userAlloc[$assigned_users[0]['user_id']]['charge'] . '%; ' . $AppUI->_('Free Capacity') . ':' . $userAlloc[$assigned_users[0]['user_id']]['freeCapacity'] . '%' : '') . '">';
$s .= $assigned_users[0]['contact_name'] . ' (' . $assigned_users[0]['perc_assignment'] . '%)</a>';
if ($arr['assignee_count'] > 1) {
$id = $arr['task_id'];
$s .= '<a href="javascript: void(0);" onclick="toggle_users(\'users_' . $id . '\');" title="' . join(', ', $a_u_tmp_array) . '">(+' . ($arr['assignee_count'] - 1) . ')</a>';
$s .= '<span style="display: none" id="users_' . $id . '">';
$a_u_tmp_array[] = $assigned_users[0]['user_username'];
for ($i = 1, $i_cmp = count($assigned_users); $i < $i_cmp; $i++) {
$a_u_tmp_array[] = $assigned_users[$i]['user_username'];
$s .= '<br /><a href="?m=admin&a=viewuser&user_id=';
$s .= $assigned_users[$i]['user_id'] . '" title="' . (w2PgetConfig('check_overallocation') ? $AppUI->_('Extent of Assignment') . ':' . $userAlloc[$assigned_users[$i]['user_id']]['charge'] . '%; ' . $AppUI->_('Free Capacity') . ':' . $userAlloc[$assigned_users[$i]['user_id']]['freeCapacity'] . '%' : '') . '">';
$s .= $assigned_users[$i]['contact_name'] . ' (' . $assigned_users[$i]['perc_assignment'] . '%)</a>';
}
$s .= '</span>';
}
$s .= '</td>';
}
} else {
// No users asigned to task
$s .= '<td class="data">-</td>';
}
// Assignment checkbox
if ($showEditCheckbox && 0 == $arr['task_represents_project']) {
$s .= '<td class="data"><input type="checkbox" onclick="select_box(\'multi_check\', ' . $arr['task_id'] . ',\'project_' . $arr['task_project'] . '_level-' . $level . '-task_' . $arr['task_id'] . '_\',\'frm_tasks\')" onfocus="is_check=true;" onblur="is_check=false;" id="selected_task_' . $arr['task_id'] . '" name="selected_task" value="' . $arr['task_id'] . '"/></td>';
}
$s .= '</tr>';
return $s;
}
//TODO: modules/projectdesigner/projectdesigner.class.php
function showtask_pr(&$arr, $level = 0, $today_view = false) {
global $AppUI, $w2Pconfig, $done;
//Check for Tasks Access
$tmpTask = new CTask();
$tmpTask->load($arr['task_id']);
$canAccess = $tmpTask->canAccess();
if (!$canAccess) {
return (false);
}
$htmlHelper = new w2p_Output_HTMLHelper($AppUI);
$htmlHelper->df .= ' ' . $AppUI->getPref('TIMEFORMAT');
$done[] = $arr['task_id'];
$s = '<tr>';
// dots
$s .= '<td style="width: ' . (($today_view) ? '20%' : '50%') . '" class="data _name">';
for ($y = 0; $y < $level; $y++) {
if ($y + 1 == $level) {
$image = w2PfindImage('corner-dots.gif', $m);
} else {
$image = w2PfindImage('shim.gif', $m);
}
$s .= '<img src="' . $image . '" width="16" height="12" border="0" alt="" />';
}
// name link
$alt = mb_strlen($arr['task_description']) > 80 ? mb_substr($arr['task_description'], 0, 80) . '...' : $arr['task_description'];
// instead of the statement below
$alt = mb_str_replace('"', """, $alt);
$alt = mb_str_replace("\r", ' ', $alt);
$alt = mb_str_replace("\n", ' ', $alt);
$open_link = w2PshowImage('collapse.gif');
if ($arr['task_milestone'] > 0) {
$s .= ' <b>' . $arr["task_name"] . '</b><!--</a>--> <img src="' . w2PfindImage('icons/milestone.gif', $m) . '" border="0" alt="" />';
} elseif ($arr['task_dynamic'] == '1') {
$s .= $open_link;
$s .= '<strong>' . $arr['task_name'] . '</strong>';
} else {
$s .= $arr['task_name'];
}
$s .= '</td>';
$s .= $htmlHelper->createCell('task_percent_complete', $arr['task_percent_complete']);
$s .= $htmlHelper->createCell('task_start_date', $arr['task_start_date']);
$s .= $htmlHelper->createCell('task_end_date', $arr['task_end_date']);
$s .= $htmlHelper->createCell('last_update', $arr['last_update']);
$s .= '</tr>';
return $s;
}
/*
* gantt_arr [ project_id ] [ 0 ] is a task "object" : task['task_id'], task['task_access'], task['task_owner'], task['task_name'], task['project_name']
* task['task_start_date'], task['task_end_date'], task['task_percent_complete'], ['task_milestone']
* gantt_arr [ project_id ] [ 1 ] is the level
*
* project_id is "optional": a 0 value means we re not handling projects
*
* adds a bidimensional array:
* -1st level: composed of integer project_id
* -2nd level: composed of an array of two items: task "object", integer level
*/
function showgtask(&$a, $level = 0, $notUsed = 0) {
/* Add tasks to gantt chart */
global $gantt_arr;
if (!is_task_in_gantt_arr($a)) {
$gantt_arr[] = array($a, $level);
}
}
// from modules/tasks/tasks.class.php
function findchild(&$tarr, $parent, $level = 0) {
global $shown_tasks;
$level = $level + 1;
$n = count($tarr);
for ($x = 0; $x < $n; $x++) {
if ($tarr[$x]['task_parent'] == $parent && $tarr[$x]['task_parent'] != $tarr[$x]['task_id']) {
echo showtask($tarr[$x], $level, true);
$shown_tasks[$tarr[$x]['task_id']] = $tarr[$x]['task_id'];
findchild($tarr, $tarr[$x]['task_id'], $level);
}
}
}
function findchild_gantt(&$tarr, $parent, $level = 0) {
global $projects;
$level = $level + 1;
$n = count($tarr);
for ($x = 0; $x < $n; $x++) {
if ($tarr[$x]['task_parent'] == $parent && $tarr[$x]['task_parent'] != $tarr[$x]['task_id']) {
showgtask($tarr[$x], $level, $tarr[$x]['project_id']);
findchild_gantt($tarr, $tarr[$x]['task_id'], $tarr[$x]['project_id'], $level);
}
}
}
//TODO: modules/projectdesigner/projectdesigner.class.php
function findchild_pd(&$tarr, $parent, $level = 0) {
global $projects;
$level = $level + 1;
$n = count($tarr);
for ($x = 0; $x < $n; $x++) {
if ($tarr[$x]['task_parent'] == $parent && $tarr[$x]['task_parent'] != $tarr[$x]['task_id']) {
echo showtask_pd($tarr[$x], $level);
findchild_pd($tarr, $tarr[$x]['task_id'], $level);
}
}
}
// from modules/tasks/tasks.class.php
function array_csort() { //coded by Ichier2003
$args = func_get_args();
$marray = array_shift($args);
if (empty($marray)) {
return array();
}
$i = 0;
$msortline = 'return(array_multisort(';
$sortarr = array();
foreach ($args as $arg) {
$i++;
if (is_string($arg)) {
for ($j = 0, $j_cmp = count($marray); $j < $j_cmp; $j++) {
/* we have to calculate the end_date via start_date+duration for
** end='0000-00-00 00:00:00' before sorting, see mantis #1509:
** Task definition writes the following to the DB:
** A without start date: start = end = NULL
** B with start date and empty end date: start = startdate,
end = '0000-00-00 00:00:00'
** C start + end date: start= startdate, end = end date
** A the end_date for the middle task (B) is ('dynamically') calculated on display
** via start_date+duration, it may be that the order gets wrong due to the fact
** that sorting has taken place _before_.
*/
if ($marray[$j]['task_end_date'] == '0000-00-00 00:00:00') {
$marray[$j]['task_end_date'] = calcEndByStartAndDuration($marray[$j]);
}
// TODO: In some cases, $arg can be an empty string
// which will throw a notice. Don't want to touch it
// who knows what will break, it uses eval after all
// robertbasic, 2012-02-18
$sortarr[$i][] = $marray[$j][$arg];
}
} else {
$sortarr[$i] = $arg;
}
$msortline .= '$sortarr[' . $i . '],';
}
$msortline .= '$marray));';
eval($msortline);
return $marray;
}
// from modules/tasks/tasks.class.php
/*
** Calc End Date via Startdate + Duration
** @param array task A DB row from the earlier fetched tasklist
** @return string Return calculated end date in MySQL-TIMESTAMP format
*/
function calcEndByStartAndDuration($task) {
$end_date = new w2p_Utilities_Date($task['task_start_date']);
$end_date->addSeconds($task['task_duration'] * $task['task_duration_type'] * SEC_HOUR);
return $end_date->format(FMT_DATETIME_MYSQL);
}
// from modules/tasks/tasks.class.php
function sort_by_item_title($title, $item_name, $item_type, $a = '') {
global $AppUI, $project_id, $task_id, $m;
global $task_sort_item1, $task_sort_type1, $task_sort_order1;
global $task_sort_item2, $task_sort_type2, $task_sort_order2;
if ($task_sort_item2 == $item_name) {
$item_order = $task_sort_order2;
}
if ($task_sort_item1 == $item_name) {
$item_order = $task_sort_order1;
}
$s = '';
if (isset($item_order)) {
$show_icon = true;
} else {
$show_icon = false;
$item_order = SORT_DESC;
}
/* flip the sort order for the link */
$item_order = ($item_order == SORT_ASC) ? SORT_DESC : SORT_ASC;
if ($m == 'tasks') {
$s .= '<a href="./index.php?m=tasks' . (($task_id > 0) ? ('&a=view&task_id=' . $task_id) : $a);
} elseif ($m == 'calendar') {
$s .= '<a href="./index.php?m=calendar&a=day_view';
} else {
$s .= '<a href="./index.php?m=projects&bypass=1' . (($project_id > 0) ? ('&a=view&project_id=' . $project_id) : '');
}
$s .= '&task_sort_item1=' . $item_name;
$s .= '&task_sort_type1=' . $item_type;
$s .= '&task_sort_order1=' . $item_order;
if ($task_sort_item1 == $item_name) {
$s .= '&task_sort_item2=' . $task_sort_item2;
$s .= '&task_sort_type2=' . $task_sort_type2;
$s .= '&task_sort_order2=' . $task_sort_order2;
} else {
$s .= '&task_sort_item2=' . $task_sort_item1;
$s .= '&task_sort_type2=' . $task_sort_type1;
$s .= '&task_sort_order2=' . $task_sort_order1;
}
$s .= '" class="hdr">' . $AppUI->_($title);
if ($show_icon) {
$s .= ' <img src="' . w2PfindImage('arrow-' . (($item_order == SORT_ASC) ? 'up' : 'down') . '.gif') . '" border="0" alt="" />';
}
return $s.'</a>';
}
// from modules/tasks/tasksperuser_sub.php
function doChildren($list, $N, $id, $uid, $level, $maxlevels, $display_week_hours, $ss, $se) {
$tmp = '';
if ($maxlevels == -1 || $level < $maxlevels) {
for ($c = 0; $c < $N; $c++) {
$task = $list[$c];
if (($task->task_parent == $id) and isChildTask($task)) {
// we have a child, do we have the user as a member?
if (isMemberOfTask($list, $N, $uid, $task)) {
$tmp .= displayTask($list, $task, $level, $display_week_hours, $ss, $se, $uid);
$tmp .= doChildren($list, $N, $task->task_id, $uid, $level + 1, $maxlevels, $display_week_hours, $ss, $se);
}
}
}
}
return $tmp;
}
// from modules/reports/tasksperuser.php
function doChildren_r($list, $Lusers, $N, $id, $uid, $level, $maxlevels, $display_week_hours, $ss, $se, $log_all_projects = false) {
$tmp = "";
if ($maxlevels == -1 || $level < $maxlevels) {
for ($c = 0; $c < $N; $c++) {
$task = $list[$c];
if (($task->task_parent == $id) and isChildTask($task)) {
// we have a child, do we have the user as a member?
if (isMemberOfTask_r($list, $Lusers, $N, $uid, $task)) {
$tmp .= displayTask_r($list, $task, $level, $display_week_hours, $ss, $se, $log_all_projects, $uid);
$tmp .= doChildren_r($list, $Lusers, $N, $task->task_id, $uid, $level + 1, $maxlevels, $display_week_hours, $ss, $se, $log_all_projects);
}
}
}
}
return $tmp;
}
// from modules/tasks/tasksperuser_sub.php
function isMemberOfTask($notUsed, $notUsed2, $user_id, $task) {
global $user_assigned_tasks;
if (isset($user_assigned_tasks[$user_id])) {
if (in_array($task->task_id, $user_assigned_tasks[$user_id])) {
return true;
}
}
return false;
}
// from modules/reports/tasksperuser.php
function isMemberOfTask_r($list, $Lusers, $N, $user_id, $task) {
for ($i = 0; $i < $N && $list[$i]->task_id != $task->task_id; $i++)
;
$users = $Lusers[$i];
foreach ($users as $task_user_id => $notUsed) {
if ($task_user_id == $user_id) {
return true;
}
}
// check child tasks if any
for ($c = 0; $c < $N; $c++) {
$ntask = $list[$c];
if (($ntask->task_parent == $task->task_id) and isChildTask($ntask)) {
// we have a child task
if (isMemberOfTask_r($list, $Lusers, $N, $user_id, $ntask)) {
return true;
}
}
}
return false;
}
// from modules/tasks/tasksperuser_sub.php
function displayTask($list, $task, $level, $display_week_hours, $fromPeriod, $toPeriod, $user_id) {
global $AppUI, $durnTypes, $active_users, $zi, $projects;
//if the user has no permission to the project don't show the tasks
if (!(key_exists($task->task_project, $projects))) {