-
Notifications
You must be signed in to change notification settings - Fork 28
/
tasks.php
2023 lines (1827 loc) · 68.8 KB
/
tasks.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
$relPath = 'pinc/';
include_once($relPath.'base.inc');
include_once($relPath.'theme.inc');
include_once($relPath.'user_is.inc');
include_once($relPath.'send_mail.inc');
include_once($relPath.'forum_interface.inc');
include_once($relPath.'Settings.inc');
include_once($relPath.'User.inc');
include_once($relPath.'links.inc'); // private_message_link()
include_once($relPath.'metarefresh.inc');
require_login();
$tasks_url = $code_url . "/" . basename(__FILE__);
$user = User::load_current();
$requester_u_id = $user->u_id;
$now_sse = time();
// The current time, expressed as Seconds Since the (Unix) Epoch.
// ---------------------------------------------------------
// Convert old-style GET requests into new-style,
// in case people have them in bookmarks/links.
if (isset($_GET['f']) && !isset($_GET['action'])) {
$f_map = [
'newtask' => 'show_creation_form',
'detail' => 'show',
'notifyme' => 'notify_me',
'unnotifyme' => 'unnotify_me',
];
$f = get_enumerated_param($_GET, 'f', null, array_keys($f_map));
$_REQUEST['action'] = $_GET['action'] = $f_map[$f];
unset($_GET['f']);
unset($_REQUEST['f']);
}
// If we got here with a generic query param, if it's numeric assume its
// a task ID, otherwise a summary search
if (isset($_GET['q'])) {
if (is_numeric($_GET['q'])) {
$_REQUEST['task_id'] = $_GET['task_id'] = $_GET['q'];
} else {
$_REQUEST['search_text'] = $_GET['search_text'] = $_GET['q'];
$_REQUEST['action'] = $_GET['action'] = 'search';
}
}
if (isset($_GET['tid']) && !isset($_GET['task_id'])) {
$_REQUEST['task_id'] = $_GET['task_id'] = $_GET['tid'];
unset($_GET['tid']);
unset($_REQUEST['tid']);
}
if (isset($_GET['search_text']) && !isset($_GET['action'])) {
$_REQUEST['action'] = $_GET['action'] = 'search';
}
// ---------------------------------------------------------
$request_method = $_SERVER['REQUEST_METHOD'];
if ($request_method == 'GET') {
$valid_actions = [
'show_creation_form',
'show',
'notify_me',
'unnotify_me',
'search',
'list_open',
'notify_new',
'unnotify_new',
'edit_comment',
];
$action = get_enumerated_param($_GET, 'action', null, $valid_actions, true);
} elseif ($request_method == 'POST') {
$valid_actions = [
'create',
'show_editing_form',
'edit',
'add_comment',
'add_related_task',
'add_related_topic',
'add_metoo',
'remove_related_task',
'remove_related_topic',
'close',
'reopen',
'search',
'save_edit_comment',
];
$action = get_enumerated_param($_POST, 'action', null, $valid_actions);
} else {
die("unexpected REQUEST_METHOD: '$request_method'");
}
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// This section sets up all the "pick from a list" properties of a task.
$tasks_array = [
1 => "Bug Report",
2 => "Feature Request",
3 => "Support Request",
4 => "Site Administrator Request",
];
$severity_array = [
1 => "Catastrophic",
2 => "Critical",
3 => "Major",
4 => "Normal",
5 => "Minor",
6 => "Trivial",
7 => "Enhancement",
];
$priority_array = [
1 => "Very High",
2 => "High",
3 => "Medium",
4 => "Low",
5 => "Very Low",
];
$categories_array = [
1 => "None",
2 => "Documentation",
3 => "Entrance",
4 => "Log in/out",
5 => "New Member",
6 => "Proofreading Interface",
7 => "Activity Hub",
8 => "Post-Processing",
9 => "Preferences",
10 => "Pre-Processing",
11 => "Project Page",
12 => "Project Lists",
13 => "Project Manager",
14 => "Site wide",
15 => "Statistics, Page Counts",
16 => "Translation",
17 => "Task Center",
18 => "Smooth Reading",
19 => "OCR Pool",
20 => "HTML Pool",
21 => "Forums, Private Messages",
22 => "WordCheck",
23 => "Project Search",
24 => "Mentoring",
25 => "My Projects",
26 => "Page Details, Diffs",
27 => "Quizzes",
28 => "Rounds",
29 => "Release Queues",
30 => "Teams",
31 => "Project Notifications",
32 => "Format Preview",
99 => "Other",
];
asort($categories_array);
$tasks_status_array = [
1 => "New",
2 => "Accepted",
14 => "Closed",
15 => "Reopened",
16 => "Researching",
18 => "In Progress",
];
asort($tasks_status_array);
$os_array = [
0 => "All",
1 => "Windows 3.1",
2 => "Windows 95",
3 => "Windows 98",
4 => "Windows ME",
5 => "Windows 2000",
6 => "Windows NT",
7 => "Windows XP",
8 => "Mac System 7",
9 => "Mac System 7.5",
10 => "Mac System 7.6.1",
11 => "Mac System 8.0",
12 => "Mac System 8.5",
13 => "Mac System 8.6",
14 => "Mac System 9.x",
15 => "Mac OS X / macOS",
16 => "Linux",
17 => "BSDI",
18 => "FreeBSD",
19 => "NetBSD",
20 => "OpenBSD",
21 => "BeOS",
22 => "HP-UX",
23 => "IRIX",
24 => "Neutrino",
25 => "OpenVMS",
26 => "OS/2",
27 => "OSF/1",
28 => "Solaris",
29 => "SunOS",
30 => "Windows 2003",
31 => "Windows Vista",
32 => "Windows 7",
33 => "Windows 8",
34 => "Windows 10",
35 => "iOS",
36 => "iPadOS",
37 => "Android",
99 => "Other",
];
natcasesort($os_array);
$browser_array = [
0 => "All",
1 => "Internet Explorer 6.x",
2 => "Netscape 6.x",
3 => "Internet Explorer 5.x",
4 => "Netscape 7.x",
5 => "Netscape 3.x",
6 => "Netscape 4.x",
7 => "Opera",
8 => "Netscape 5.x",
9 => "Internet Explorer 4.x",
10 => "Lynx",
11 => "Avant Browser",
12 => "Netscape 2.x",
13 => "Slimbrowser",
14 => "Interarchy",
15 => "Straw",
16 => "MSN TV",
17 => "Mozilla 1.4",
18 => "Mozilla 1.5",
19 => "Mozilla 1.6",
20 => "Mozilla Firefox 0.6",
22 => "Mozilla Firefox 0.7",
23 => "Mozilla 1.1",
24 => "Mozilla 1.2",
25 => "Mozilla 1.3",
26 => "Safari",
27 => "Galeon",
28 => "Konquerer",
29 => "Internet Explorer 3.x",
30 => "Mozilla 1.7",
31 => "Mozilla 1.8",
32 => "Mozilla Firefox 0.8",
33 => "Mozilla Firefox 0.9",
34 => "Opera 6.x",
35 => "Opera 7.x",
36 => "Mozilla Firefox 1.0",
37 => "Mozilla Camino 0.7",
38 => "Mozilla Camino 0.8.x",
39 => "Opera 8.x",
40 => "Opera 9.x",
41 => "Mozilla Firefox 1.5.x",
42 => "Internet Explorer 7.x",
43 => "Mozilla Camino 1.x",
44 => "Safari 2.x",
45 => "Mozilla Firefox 2.x",
46 => "Mozilla Firefox 3.x",
47 => "Safari 3.x",
48 => "Internet Explorer 8.x",
49 => "Safari 4.x",
50 => "Opera 10.x",
51 => "Microsoft Edge",
52 => "Chrome / Chromium",
99 => "Other",
];
asort($browser_array);
$tasks_close_array = [
1 => "Not a Bug",
2 => "Won't Fix",
3 => "Won't Implement",
4 => "Works for Me",
5 => "Duplicate",
6 => "Deferred",
7 => "Fixed",
8 => "Implemented",
9 => "Resolved",
];
asort($tasks_close_array);
$percent_complete_array = [
0 => "0%",
10 => "10%",
20 => "20%",
30 => "30%",
40 => "40%",
50 => "50%",
60 => "60%",
70 => "70%",
80 => "80%",
90 => "90%",
100 => "100%",
];
$task_assignees_array = [];
$taskcenter_managers = array_unique(array_merge(
Settings::get_users_with_setting('sitemanager', 'yes'),
Settings::get_users_with_setting('task_center_mgr', 'yes')
));
foreach ($taskcenter_managers as $taskcenter_manager) {
$user = new User($taskcenter_manager);
$task_assignees_array[$user->u_id] = $taskcenter_manager;
}
natcasesort($task_assignees_array);
$task_assignees_array = [0 => 'Unassigned'] + $task_assignees_array;
// -----------------------------------------------------------------------------
$SearchParams_choices = [
'task_status' => [998 => _('All Tasks'), 999 => _('All Open Tasks')] + $tasks_status_array,
'task_type' => [999 => _('All Task Types')] + $tasks_array,
'task_severity' => [999 => _('All Severities')] + $severity_array,
'task_priority' => [999 => _('All Priorities')] + $priority_array,
'task_assignee' => [999 => _('All Developers')] + $task_assignees_array,
'task_category' => [999 => _('All Categories')] + $categories_array,
];
// XXX Re task_assignee, there's a long-standing bug involving
// a sitemanager/task_center_mgr whose u_id happens to be 999.
// However, there's a fairly low chance of it ever being triggered.
/**
* For each of the search parameters, echo its control (HTML markup),
* initializing it with any (valid) value that the current request
* has supplied for the parameter.
*/
function SearchParams_echo_controls(): void
{
global $SearchParams_choices, $tasks_url;
if (isset($_REQUEST['search_text']) && !empty($_REQUEST['search_text'])) {
$st = $_REQUEST['search_text'];
$search_text = attr_safe($st);
} else {
$search_text = "";
}
echo "<form action='$tasks_url' method='get'>";
echo "<table class='themed'>\n";
echo "<tr><th>" . _("Search") . "</th>\n";
echo "<td>";
echo "<input type='hidden' name='action' value='search'>\n";
echo "<input type='text' value='$search_text' name='search_text' style='width: 20em'>\n";
foreach ($SearchParams_choices as $param_name => $choices) {
$value = (int) get_enumerated_param($_REQUEST, $param_name, '999', array_keys($choices));
echo dropdown_select($param_name, $value, $choices);
}
echo "<input type='submit' value='" . attr_safe(_("Search")) . "'></td>\n";
echo "</tr>\n";
echo "</table></form><br>\n";
}
/**
* Return a SQL condition that expresses the restriction on tasks
* implied by the values (if any) supplied for the search parameters
* by the current request.
*/
function SearchParams_get_sql_condition(array $request_params): string
{
global $testing, $SearchParams_choices;
$condition = "1";
if (isset($request_params['search_text'])) {
$search_text = normalize_whitespace($request_params['search_text']);
if ($testing) {
echo_html_comment("\$request_params['search_text'] = $search_text");
}
$condition .= sprintf(" AND
(
POSITION('%1\$s' IN task_summary)
OR
POSITION('%1\$s' IN task_details)
)
", DPDatabase::escape($search_text));
}
// ------
foreach ($SearchParams_choices as $param_name => $choices) {
$value = get_enumerated_param($request_params, $param_name, null, array_keys($choices), true);
if ($param_name == 'task_status') {
if (is_null($value) || $value == 999) {
$param_condition = "$param_name >= 0 AND date_closed = 0";
} elseif ($value == 998) {
$param_condition = "$param_name >= 0";
} else {
$param_condition = "$param_name = $value";
}
} else {
if (is_null($value) || $value == 999) {
$param_condition = "$param_name >= 0";
} else {
$param_condition = "$param_name = $value";
}
}
$condition .= "\n AND $param_condition";
}
return $condition;
}
/**
* Return a string (suitable for use in the 'query string' portion of a URL)
* that represents (and possibly just reiterates) the values (if any)
* supplied for the search parameters by the current request.
*/
function SearchParams_get_url_query_string(): string
{
global $SearchParams_choices;
if (isset($_REQUEST['search_text'])) {
$t = "action=search&search_text=" . urlencode($_REQUEST['search_text']);
foreach ($SearchParams_choices as $param_name => $choices) {
$value = get_enumerated_param($_REQUEST, $param_name, '999', array_keys($choices));
$t .= "&{$param_name}={$value}";
}
$t .= "&";
} else {
$t = "";
}
return $t;
}
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
function make_default_task_object(): object
{
global $tasks_array;
global $categories_array;
global $tasks_status_array;
global $severity_array;
global $priority_array;
global $os_array;
global $browser_array;
global $percent_complete_array;
$task = new stdClass();
$task->task_severity = get_property_key("Normal", $severity_array);
$task->task_priority = get_property_key("Medium", $priority_array);
$task->task_type = get_property_key("Bug Report", $tasks_array);
$task->task_category = get_property_key("None", $categories_array);
$task->task_status = get_property_key("New", $tasks_status_array);
$task->task_os = get_property_key("All", $os_array);
$task->task_browser = get_property_key("All", $browser_array);
$task->task_assignee = 0;
$task->task_summary = "";
$task->task_details = "";
$task->percent_complete = get_property_key("0%", $percent_complete_array);
$task->opened_by = "";
$task->task_id = 0;
return $task;
}
function create_task_from_form_submission(array $formsub): ?string
{
global $tasks_array;
global $categories_array;
global $tasks_status_array;
global $task_assignees_array;
global $severity_array;
global $priority_array;
global $os_array;
global $browser_array;
global $now_sse;
global $requester_u_id;
global $site_abbreviation;
$task_summary = trim($formsub['task_summary'] ?? '');
$task_details = trim($formsub['task_details'] ?? '');
if (empty($task_summary) || empty($task_details)) {
return _("You must supply a Task Summary and Task Details.");
}
assert(!isset($formsub['task_id']));
// Create a new task.
$newt_type = (int) get_enumerated_param($formsub, 'task_type', null, array_keys($tasks_array));
$newt_category = (int) get_enumerated_param($formsub, 'task_category', null, array_keys($categories_array));
$newt_status = (int) get_enumerated_param($formsub, 'task_status', null, array_keys($tasks_status_array));
$newt_assignee = (int) get_enumerated_param($formsub, 'task_assignee', null, array_keys($task_assignees_array));
$newt_severity = (int) get_enumerated_param($formsub, 'task_severity', null, array_keys($severity_array));
$newt_priority = (int) get_enumerated_param($formsub, 'task_priority', null, array_keys($priority_array));
$newt_os = (int) get_enumerated_param($formsub, 'task_os', null, array_keys($os_array));
$newt_browser = (int) get_enumerated_param($formsub, 'task_browser', null, array_keys($browser_array));
// Validate the assignee, skipping the case where it is 0 (Unassigned).
if ($newt_assignee != 0) {
$task_assignee_user = User::load_from_uid($newt_assignee);
}
$sql_query = sprintf(
"
INSERT INTO tasks
SET
task_summary = '%s',
task_type = %d,
task_category = %d,
task_status = %d,
task_assignee = %d,
task_severity = %d,
task_priority = %d,
task_os = %d,
task_browser = %d,
task_details = '%s',
date_opened = %d,
opened_by = %d,
date_edited = %d,
edited_by = %d,
percent_complete = 0,
related_postings = '%s'
",
DPDatabase::escape($task_summary),
$newt_type,
$newt_category,
$newt_status,
$newt_assignee,
$newt_severity,
$newt_priority,
$newt_os,
$newt_browser,
DPDatabase::escape($task_details),
$now_sse,
$requester_u_id,
$now_sse,
$requester_u_id,
DPDatabase::escape(encode_array([]))
);
DPDatabase::query($sql_query);
$task_id = mysqli_insert_id(DPDatabase::get_connection());
global $pguser;
NotificationMail($task_id, "", true);
// Nobody could have subscribed to this particular task yet,
// so the msg will only go to those with taskctr_notice = 'all' or 'notify_new'.
// If $newt_assignee is 0, there is no user assigned so no notification
// to send out.
if ($newt_assignee != 0) {
global $tasks_url, $code_url;
send_mail(
$task_assignee_user->email,
"$site_abbreviation Task Center: Task #$task_id has been assigned to you",
$task_assignee_user->username . ", you have been assigned task #$task_id. Please visit this task at $tasks_url?action=show&task_id=$task_id.\n\nIf you do not want to accept this task please edit the task and change the assignee to 'Unassigned'."
);
}
// Subscribe the current user to this task for notification
$userSettings = & Settings::get_Settings($pguser);
$userSettings->add_value('taskctr_notice', $task_id);
return null;
}
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// This is the point at which the script starts to produce output.
if (!isset($_REQUEST['task_id'])) {
// Default 'action' when no task is specified:
if (is_null($action)) {
$action = 'list_open';
}
switch ($action) {
case 'show_creation_form':
// Open a form to specify the properties of a new task.
TaskHeader("New Task");
// The user wants to create a task.
// Initialize the form with default values.
$task = make_default_task_object();
TaskForm($task);
break;
case 'search':
// The user clicked a column-header-link in a listing of tasks
// (or followed a bookmark of such a link).
$header = _("Task Search");
if (!empty($_REQUEST['search_text'])) {
$header .= ": " . $_REQUEST['search_text'];
}
TaskHeader($header);
echo "<h1 style='margin-top: 0;'>" . _("Task Center") . "</h1>";
SearchParams_echo_controls();
search_and_list_tasks($_REQUEST);
break;
case 'list_open':
// The user just entered the Task Center
// (e.g., by clicking the "Report a Bug" link).
TaskHeader(_("All Open Tasks"), true);
echo "<h1 style='margin-top: 0;'>" . _("Task Center") . "</h1>";
SearchParams_echo_controls();
list_all_open_tasks();
break;
case 'create':
// The user is supplying values for the properties of a new task.
$errmsg = create_task_from_form_submission($_POST);
if ($errmsg) {
ShowError($errmsg, true);
break;
} else {
// If we successfully create the task, we should reload
// the page to clear the POST data and make sure that
// reloading does not lead to duplicated tasks.
metarefresh(0, $tasks_url);
}
// no break, metarefresh exits
case 'notify_new':
$userSettings = & Settings::get_Settings($pguser);
$userSettings->add_value('taskctr_notice', 'notify_new');
metarefresh(0, $tasks_url);
// no break, metarefresh exits
case 'unnotify_new':
$userSettings = & Settings::get_Settings($pguser);
$userSettings->remove_value('taskctr_notice', 'notify_new');
metarefresh(0, $tasks_url);
}
} else {
handle_action_on_a_specified_task();
}
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
function handle_action_on_a_specified_task(): void
{
global $pguser, $requester_u_id;
global $now_sse;
global $action, $tasks_url;
// data array
global $tasks_status_array;
global $tasks_array;
global $categories_array;
global $task_assignees_array;
global $severity_array;
global $priority_array;
global $os_array;
global $browser_array;
global $percent_complete_array;
global $tasks_close_array;
// Default 'action' when a task is specified:
if (is_null($action)) {
$action = 'show';
}
$task_id = get_integer_param($_REQUEST, 'task_id', null, 1, null);
// Fetch the state of the specified task
// before any requested changes.
$pre_task = load_task($task_id, false);
if (!$pre_task) {
ShowError(sprintf(_("Task #%d was not found."), $task_id));
return;
}
if ($action == 'notify_me') {
$userSettings = & Settings::get_Settings($pguser);
$userSettings->add_value('taskctr_notice', $task_id);
// metarefresh with default action (=show) so that reloading page will not repeat action
metarefresh(0, "$tasks_url?task_id=$task_id");
} elseif ($action == 'unnotify_me') {
$userSettings = & Settings::get_Settings($pguser);
$userSettings->remove_value('taskctr_notice', $task_id);
metarefresh(0, "$tasks_url?task_id=$task_id");
}
if ($action == 'show' || $action == 'edit_comment') {
TaskHeader(title_string_for_task($pre_task));
TaskDetails($task_id, $action);
} elseif ($action == 'show_editing_form') {
TaskHeader(title_string_for_task($pre_task));
if (user_is_a_sitemanager() || user_is_taskcenter_mgr() || $pre_task->opened_by == $requester_u_id && empty($pre_task->closed_reason)) {
// The user wants to edit an existing task.
// Initialize the form with the current values of the task's properties.
TaskForm($pre_task);
} else {
ShowError(_("You do not have permission to edit this task."), true);
}
} elseif ($action == 'reopen') {
NotificationMail($task_id, "$pguser reopened this task.");
$sql = sprintf(
"
UPDATE tasks
SET
task_status = %d,
edited_by = %d,
date_edited = %d,
date_closed = 0,
closed_by = 0,
closed_reason = 0
WHERE task_id = %d
",
get_property_key("Reopened", $tasks_status_array),
$requester_u_id,
$now_sse,
$task_id
);
DPDatabase::query($sql);
metarefresh(0, "$tasks_url?task_id=$task_id");
} elseif ($action == 'edit') {
$task_summary = trim($_POST['task_summary'] ?? '');
$task_details = trim($_POST['task_details'] ?? '');
// The user is supplying values for the properties of a pre-existing task.
if (empty($task_summary) || empty($task_details)) {
ShowError(_("You must supply a Task Summary and Task Details."), true);
} else {
// Update a pre-existing task.
NotificationMail($task_id, "$pguser edited this task.");
$edit_type = (int) get_enumerated_param($_POST, 'task_type', null, array_keys($tasks_array));
$edit_category = (int) get_enumerated_param($_POST, 'task_category', null, array_keys($categories_array));
$edit_status = (int) get_enumerated_param($_POST, 'task_status', null, array_keys($tasks_status_array));
$edit_assignee = (int) get_enumerated_param($_POST, 'task_assignee', null, array_keys($task_assignees_array));
$edit_severity = (int) get_enumerated_param($_POST, 'task_severity', null, array_keys($severity_array));
$edit_priority = (int) get_enumerated_param($_POST, 'task_priority', null, array_keys($priority_array));
$edit_os = (int) get_enumerated_param($_POST, 'task_os', null, array_keys($os_array));
$edit_browser = (int) get_enumerated_param($_POST, 'task_browser', null, array_keys($browser_array));
$edit_percent = (int) get_enumerated_param($_POST, 'percent_complete', null, array_keys($percent_complete_array));
$sql = sprintf(
"
UPDATE tasks
SET
task_summary = '%s',
task_type = %d,
task_category = %d,
task_status = %d,
task_assignee = %d,
task_severity = %d,
task_priority = %d,
task_os = %d,
task_browser = %d,
task_details = '%s',
date_edited = %d,
edited_by = %d,
percent_complete = %d
WHERE task_id = %d
",
DPDatabase::escape($task_summary),
$edit_type,
$edit_category,
$edit_status,
$edit_assignee,
$edit_severity,
$edit_priority,
$edit_os,
$edit_browser,
DPDatabase::escape($task_details),
$now_sse,
$requester_u_id,
$edit_percent,
$task_id
);
DPDatabase::query($sql);
metarefresh(0, "$tasks_url?task_id=$task_id");
}
} elseif ($action == 'close') {
if (user_is_a_sitemanager() || user_is_taskcenter_mgr()) {
$tc_reason = (int) get_enumerated_param($_POST, 'closed_reason', null, array_keys($tasks_close_array));
NotificationMail(
$task_id,
"$pguser closed this task.\nThe reason for closing was: " . $tasks_close_array[$tc_reason] . "."
);
$sql = sprintf(
"
UPDATE tasks
SET
percent_complete = %d,
task_status = %d,
date_closed = %d,
closed_by = %d,
closed_reason = %d,
date_edited = %d,
edited_by = %d
WHERE task_id = %d
",
get_property_key("100%", $percent_complete_array),
get_property_key("Closed", $tasks_status_array),
$now_sse,
$requester_u_id,
$tc_reason,
$now_sse,
$requester_u_id,
$task_id
);
DPDatabase::query($sql);
metarefresh(0, $tasks_url);
} else {
ShowError(_("You do not have permission to close tasks."), true);
return;
}
} elseif ($action == 'add_comment') {
$comment = trim($_POST['task_comment'] ?? '');
if ($comment) {
NotificationMail($task_id, "$pguser commented:\n\n$comment");
$sql = sprintf(
"
INSERT INTO tasks_comments (task_id, u_id, comment_date, comment)
VALUES (%d, %d, %d, '%s')
",
$task_id,
$requester_u_id,
$now_sse,
DPDatabase::escape($comment)
);
DPDatabase::query($sql);
$sql = sprintf(
"
UPDATE tasks
SET date_edited = %d, edited_by = %d
WHERE task_id = %d
",
$now_sse,
$requester_u_id,
$task_id
);
DPDatabase::query($sql);
// subscribe the user to the task for notifications
$userSettings = & Settings::get_Settings($pguser);
$userSettings->add_value('taskctr_notice', $task_id);
// After posting the comment, we should reload as to clear POST data
// and avoid comments being posted multiple times.
$comment_id = create_anchor_for_comment($requester_u_id, $now_sse);
metarefresh(0, "$tasks_url?action=show&task_id=$task_id#$comment_id");
} else {
ShowError(_("You must supply a comment before clicking Add Comment."), true);
return;
}
} elseif ($action == 'add_related_task') {
$related_task_id = get_integer_param($_POST, 'related_task', null, 1, null);
process_related_task($pre_task, 'add', $related_task_id);
} elseif ($action == 'remove_related_task') {
$related_task_id = get_integer_param($_POST, 'related_task', null, 1, null);
process_related_task($pre_task, 'remove', $related_task_id);
} elseif ($action == 'add_related_topic') {
$related_posting_topic = get_integer_param($_POST, 'related_posting', null, 1, null);
process_related_topic($pre_task, 'add', $related_posting_topic);
} elseif ($action == 'remove_related_topic') {
$related_posting_topic = get_integer_param($_POST, 'related_posting', null, 1, null);
process_related_topic($pre_task, 'remove', $related_posting_topic);
} elseif ($action == 'add_metoo') {
$vote_os = (int) get_enumerated_param($_POST, 'metoo_os', null, array_keys($os_array));
$vote_browser = (int) get_enumerated_param($_POST, 'metoo_browser', null, array_keys($browser_array));
// Do not insert two votes for the same user
$meTooCount = get_me_too_count($task_id, $requester_u_id);
if ($meTooCount == 0) {
$sql = sprintf(
"
INSERT INTO tasks_votes (task_id, u_id, vote_os, vote_browser)
VALUES (%d, %d, %d, %d)
",
$task_id,
$requester_u_id,
$vote_os,
$vote_browser
);
DPDatabase::query($sql);
}
// Redirect back to show task page to clear POST data
metarefresh(0, "$tasks_url?action=show&task_id=$task_id");
} elseif ($action == 'save_edit_comment') {
$comment_id = $_POST['comment_id'] ?? "";
$comment = trim($_POST['task_comment'] ?? '');
[$u_id, $comment_date] = explode('_', $comment_id, 2);
if (($u_id === $requester_u_id && $now_sse - $comment_date <= 86400) || user_is_a_sitemanager()) {
$sql = sprintf(
"
UPDATE tasks_comments SET comment='%s'
WHERE task_id = %d AND u_id = %d AND comment_date = %d
",
DPDatabase::escape($comment),
$task_id,
$u_id,
$comment_date
);
DPDatabase::query($sql);
metarefresh(0, "$tasks_url?action=show&task_id=$task_id#$comment_id");
}
} else {
die("shouldn't be able to reach here");
}
}
/**
* Add or remove a related task to the current task.
*/
function process_related_task(object $pre_task, string $action, int $related_task_id): void
{
global $pguser, $tasks_url;
assert($action == 'add' || $action == 'remove');
if ($related_task_id < 1) {
ShowError(_("You must supply a valid related task ID."), true);
return;
}
$adding = ($action == 'add');
$pre_task_id = $pre_task->task_id;
$related_task_exists = load_task($related_task_id) != null;
$task_already_present = in_array($related_task_id, load_related_tasks($pre_task_id));
if (!$related_task_exists || $related_task_id == $pre_task_id || $task_already_present == $adding) {
ShowError(_("You must supply a valid related task ID."), true);
return;
}
if ($adding) {
insert_related_task($pre_task_id, $related_task_id);
} else {
remove_related_task($pre_task_id, $related_task_id);
}
if ($adding) {
NotificationMail($pre_task_id, "$pguser added related task $related_task_id.");
} else {
NotificationMail($pre_task_id, "$pguser removed related task $related_task_id.");
}
metarefresh(0, "$tasks_url?task_id=$pre_task_id");
}
/**
* Add or remove a related topic (forum thread) to the current task.
*/
function process_related_topic(object $pre_task, string $action, int $related_topic_id): void
{
global $pguser, $tasks_url;
assert($action == 'add' || $action == 'remove');
if ($related_topic_id < 1) {
ShowError(_("You must supply a valid related topic ID."), true);
return;
}
$adding = ($action == 'add');
$pre_task_id = $pre_task->task_id;
$related_topics = decode_array($pre_task->related_postings);
$topic_already_present = in_array($related_topic_id, $related_topics);
$topic_details = get_topic_details($related_topic_id);
if ($adding && ($topic_already_present ||
!does_topic_exist($related_topic_id) ||
!$topic_details['forum_name'])) {
ShowError(_("You must supply a valid related topic ID."), true);
return;
}
if ($adding) {
array_push($related_topics, $related_topic_id);
} else {
unset($related_topics[array_search($related_topic_id, $related_topics)]);
}
$sql = sprintf(
"
UPDATE tasks
SET related_postings = '%s'
WHERE task_id = %d
",
DPDatabase::escape(encode_array($related_topics)),
$pre_task_id
);
DPDatabase::query($sql);
if ($adding) {
NotificationMail($pre_task_id, "$pguser added related topic $related_topic_id.");
} else {
NotificationMail($pre_task_id, "$pguser removed related topic $related_topic_id.");
}
metarefresh(0, "$tasks_url?task_id=$pre_task_id");
}
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
/** @param array<string, string> $array */
function dropdown_select(string $field_name, string $current_value, array $array): string
{
$return = "<select size='1' name='$field_name' ID='$field_name'>\n";
foreach ($array as $key => $val) {
$return .= "<option value='" . attr_safe($key) . "'";
if ($current_value == $key) {
$return .= " SELECTED";
}
$return .= ">" . html_safe($val) . "</option>\n";
}
$return .= "</select>\n";
return $return;