/
print_api.php
1050 lines (957 loc) · 33.7 KB
/
print_api.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
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the files README and LICENSE for details
# --------------------------------------------------------
# $Id: print_api.php,v 1.24 2002-10-20 23:59:49 jfitzell Exp $
# --------------------------------------------------------
###########################################################################
# Basic Print API
#
# this file handles printing and string manipulation functions
###########################################################################
# --------------------
# Print the headers to cause the page to redirect to $p_url
# If $p_die is true (default), terminate the execution of the script
# immediately
# If we have handled any errors on this page and the 'stop_on_errors' config
# option is turned on, return false and don't redirect.
function print_header_redirect( $p_url, $p_die=true ) {
$t_use_iis = config_get( 'use_iis');
if ( ON == config_get( 'stop_on_errors' ) && error_handled() ) {
return false;
}
if ( OFF == $t_use_iis ) {
header( 'Status: 302' );
}
header( 'Content-Type: text/html' );
header( 'Pragma: no-cache' );
header( 'Expires: Fri, 01 Jan 1999 00:00:00 GMT' );
header( 'Cache-control: no-cache, no-cache="Set-Cookie", private' );
if ( ON == $t_use_iis ) {
header( "Refresh: 0;url=$p_url" );
} else {
header( "Location: $p_url" );
}
if ( $p_die ) {
die; # additional output can cause problems so let's just stop output here
}
return true;
}
# --------------------
# Print a redirect header to view a bug
function print_header_redirect_view( $p_bug_id ) {
print_header_redirect( string_get_bug_view_url( $p_bug_id ) );
}
# --------------------
# Print a redirect header to update a bug
function print_header_redirect_update( $p_bug_id ) {
print_header_redirect( string_get_bug_update_url( $p_bug_id ) );
}
# --------------------
# Print a redirect header to update a bug
function print_header_redirect_report() {
print_header_redirect( string_get_bug_report_url() );
}
# --------------------
# prints the name of the user given the id. also makes it an email link.
function print_user( $p_user_id ) {
$c_user_id = db_prepare_int( $p_user_id );
# invalid user
if ( '0000000' == $p_user_id ) {
return;
}
$query = "SELECT username, email
FROM " . config_get( 'mantis_user_table' ) . "
WHERE id='$c_user_id'";
$result = db_query( $query );
if ( db_num_rows( $result ) > 0 ) {
$t_username = db_result( $result, 0, 0 );
$t_email = db_result( $result, 0, 1 );
print_email_link( $t_email, $t_username );
} else {
echo lang_get ( 'user_no_longer_exists' );
}
}
# --------------------
# same as print_user() but fills in the subject with the bug summary
function print_user_with_subject( $p_user_id, $p_bug_id ) {
$c_user_id = db_prepare_int( $p_user_id );
if ( '0000000' == $p_user_id ) {
return;
}
$query = "SELECT username, email
FROM " . config_get( 'mantis_user_table' ) . "
WHERE id='$c_user_id'";
$result = db_query( $query );
if ( db_num_rows( $result ) > 0 ) {
$t_username = db_result( $result, 0, 0 );
$t_email = db_result( $result, 0, 1 );
print_email_link_with_subject( $t_email, $t_username, $p_bug_id );
} else {
echo lang_get( 'user_no_longer_exists' );
}
}
# --------------------
function print_duplicate_id( $p_duplicate_id ) {
if ( $p_duplicate_id != '0000000' ) {
echo string_get_bug_view_link( $p_duplicate_id );
}
}
# --------------------
# print out an email editing input
function print_email_input( $p_field_name, $p_email ) {
$t_limit_email_domain = config_get( 'limit_email_domain' );
if ( $t_limit_email_domain ) {
# remove the domain part
$p_email = eregi_replace( "@$t_limit_email_domain$", '', $p_email );
echo '<input type="text" name="'.$p_field_name.'" size="20" maxlength="64" value="'.$p_email.'" />@'.$t_limit_email_domain;
} else {
echo '<input type="text" name="'.$p_field_name.'" size="32" maxlength="64" value="'.$p_email.'" />';
}
}
###########################################################################
# Option List Printing API
###########################################################################
# --------------------
# sorts the array by the first element of the array element
# @@@ might not be used
function cmp( $p_var1, $p_var2 ) {
if ( $p_var1[0][0] == $p_var2[0][0] ) {
return 0;
}
if ( $p_var1[0][0] < $p_var2[0][0] ) {
return -1;
} else {
return 1;
}
}
# --------------------
# ugly functions need to be refactored
# This populates the reporter option list with the appropriate users
function print_reporter_option_list( $p_user_id ) {
global $g_mantis_user_table, $g_mantis_project_user_list_table,
$g_mantis_project_table, $g_project_cookie_val;
$t_adm = ADMINISTRATOR;
$t_rep = REPORTER;
$t_pub = PUBLIC;
$t_prv = PRIVATE;
$user_arr = array();
# checking if it's per project or all projects
# 0 is all projects
if ( '0000000' == $g_project_cookie_val ) {
$query = "SELECT DISTINCT u.id, u.username, u.email
FROM $g_mantis_user_table u,
$g_mantis_project_user_list_table l,
$g_mantis_project_table p
WHERE (p.view_state='$t_pub' AND
u.access_level>='$t_rep') OR
(l.access_level>='$t_rep' AND
l.user_id=u.id) OR
u.access_level>='$t_adm'
ORDER BY u.username";
$result = db_query( $query );
$user_count = db_num_rows( $result );
for ($i=0;$i<$user_count;$i++) {
$row = db_fetch_array( $result );
extract( $row, EXTR_PREFIX_ALL, 'v' );
$user_arr[$v_username] = array( $v_username, $v_id );
}
} else {
$temp_arr = array();
# grab the administrators
$query = "SELECT id, username
FROM $g_mantis_user_table
ORDER BY username";
$result = db_query( $query );
$user_count = db_num_rows( $result );
for ($i=0;$i<$user_count;$i++) {
$row = db_fetch_array( $result );
extract( $row, EXTR_PREFIX_ALL, 'v' );
$temp_arr[$v_username] = array( $v_username, $v_id );
}
foreach ( $temp_arr as $key => $val ) {
$v_id = $val[1];
$v_username = $val[0];
# always add all administrators
$t_access_level = user_get_field( $v_id, 'access_level' );
if ( ADMINISTRATOR == $t_access_level ) {
$user_arr[$v_username] = array( $v_username, $v_id );
continue;
}
# see if users belong
$t_project_view_state = project_get_field( $g_project_cookie_val, 'view_state' );
if ( PUBLIC == $t_project_view_state ) {
$query = "SELECT l.access_level
FROM $g_mantis_project_user_list_table l,
$g_mantis_project_table p
WHERE l.project_id='$g_project_cookie_val' AND
p.id=l.project_id AND
l.user_id='$v_id'";
$result = db_query( $query );
$count = db_num_rows( $result );
if ( $count > 0 ){
$t_access_level = db_result( $result );
}
if ( $t_access_level >= REPORTER ) {
$user_arr[$v_username] = array( $v_username, $v_id );
}
} else {
$query = "SELECT COUNT(*)
FROM $g_mantis_project_user_list_table l,
$g_mantis_project_table p
WHERE l.project_id='$g_project_cookie_val' AND
p.id=l.project_id AND
l.user_id='$v_id' AND
l.access_level>='$t_rep'";
$result = db_query( $query );
$count = db_result( $result, 0, 0 );
if ( $count > 0 ) {
$user_arr[$v_username] = array( $v_username, $v_id );
continue;
}
}
}
}
asort( $user_arr );
foreach ( $user_arr as $key => $val ) {
$v_id = $val[1];
$v_username = $val[0];
echo "<option value=\"$v_id\"";
check_selected( $v_id, $p_user_id );
echo ">$v_username</option>";
} # end foreach
}
# --------------------
function print_duplicate_id_option_list() {
$query = "SELECT id
FROM " . config_get ( 'mantis_bug_table' ) . "
ORDER BY id ASC";
$result = db_query( $query );
$duplicate_id_count = db_num_rows( $result );
PRINT '<option value="0000000"></option>';
for ($i=0;$i<$duplicate_id_count;$i++) {
$row = db_fetch_array( $result );
$t_duplicate_id = $row['id'];
PRINT "<option value=\"$t_duplicate_id\">".$t_duplicate_id."</option>";
}
}
# --------------------
# Get current headlines and id prefix with v_
function print_news_item_option_list() {
global $g_mantis_news_table, $g_project_cookie_val;
if ( access_level_check_greater_or_equal( ADMINISTRATOR ) ) {
$query = "SELECT id, headline, announcement, view_state
FROM $g_mantis_news_table
ORDER BY date_posted DESC";
} else {
$query = "SELECT id, headline, announcement, view_state
FROM $g_mantis_news_table
WHERE project_id='$g_project_cookie_val'
ORDER BY date_posted DESC";
}
$result = db_query( $query );
$news_count = db_num_rows( $result );
for ($i=0;$i<$news_count;$i++) {
$row = db_fetch_array( $result );
extract( $row, EXTR_PREFIX_ALL, 'v' );
$v_headline = string_display( $v_headline );
$t_notes = array();
$t_note_string = '';
if ( 1 == $v_announcement ) {
array_push( $t_notes, lang_get( 'announcement' ) );
}
if ( PRIVATE == $v_view_state ) {
array_push( $t_notes, lang_get( 'private' ) );
}
if ( sizeof( $t_notes ) > 0 ) {
$t_note_string = ' ['.implode( ' ', $t_notes ).']';
}
PRINT "<option value=\"$v_id\">$v_headline$t_note_string</option>";
}
}
# --------------------
# Used for update pages
function print_field_option_list( $p_list, $p_item='' ) {
global $g_mantis_bug_table;
$t_category_string = get_enum_string( $g_mantis_bug_table, $p_list );
$t_arr = explode_enum_string( $t_category_string );
$entry_count = count( $t_arr );
for ($i=0;$i<$entry_count;$i++) {
$t_s = str_replace( '\'', '', $t_arr[$i] );
echo "<option value=\"$t_s\"";
check_selected( $p_item, $t_s );
echo ">$t_s</option>";
} # end for
}
# --------------------
function print_assign_to_option_list( $p_user_id='' ) {
global $g_mantis_user_table, $g_mantis_project_table,
$g_mantis_project_user_list_table, $g_project_cookie_val,
$g_handle_bug_threshold;
$t_adm = ADMINISTRATOR;
$t_dev = $g_handle_bug_threshold;
$t_pub = PUBLIC;
$t_prv = PRIVATE;
$user_arr = array();
# checking if it's per project or all projects
# 0 is all projects
if ( '0000000' == $g_project_cookie_val ) {
$query = "SELECT DISTINCT u.id, u.username, u.email
FROM $g_mantis_user_table u,
$g_mantis_project_user_list_table l,
$g_mantis_project_table p
WHERE (p.view_state='$t_pub' AND
u.access_level>='$t_dev') OR
(l.access_level>='$t_dev' AND
l.user_id=u.id) OR
u.access_level>='$t_adm'
ORDER BY u.username";
$result = db_query( $query );
$user_count = db_num_rows( $result );
for ($i=0;$i<$user_count;$i++) {
$row = db_fetch_array( $result );
extract( $row, EXTR_PREFIX_ALL, 'v' );
$user_arr[$v_username] = array( $v_username, $v_id );
}
} else {
$temp_arr = array();
# grab the administrators
$query = "SELECT id, username
FROM $g_mantis_user_table
ORDER BY username";
$result = db_query( $query );
$user_count = db_num_rows( $result );
for ($i=0;$i<$user_count;$i++) {
$row = db_fetch_array( $result );
extract( $row, EXTR_PREFIX_ALL, 'v' );
$temp_arr[$v_username] = array( $v_username, $v_id );
}
foreach ( $temp_arr as $key => $val ) {
$v_id = $val[1];
$v_username = $val[0];
# always add all administrators
$t_access_level = user_get_field( $v_id, 'access_level' );
if ( ADMINISTRATOR == $t_access_level ) {
$user_arr[$v_username] = array( $v_username, $v_id );
continue;
}
# see if users belong
$t_project_view_state = project_get_field( $g_project_cookie_val, 'view_state' );
if ( PUBLIC == $t_project_view_state ) {
$query = "SELECT l.access_level
FROM $g_mantis_project_user_list_table l,
$g_mantis_project_table p
WHERE l.project_id='$g_project_cookie_val' AND
p.id=l.project_id AND
l.user_id='$v_id'";
$result = db_query( $query );
$count = db_num_rows( $result );
if ( $count > 0 ){
$t_access_level = db_result( $result );
}
if ( $t_access_level >= $t_dev ) {
$user_arr[$v_username] = array( $v_username, $v_id );
}
} else {
$query = "SELECT COUNT(*)
FROM $g_mantis_project_user_list_table l,
$g_mantis_project_table p
WHERE l.project_id='$g_project_cookie_val' AND
p.id=l.project_id AND
l.user_id='$v_id' AND
l.access_level>='$t_dev'";
$result = db_query( $query );
$count = db_result( $result, 0, 0 );
if ( $count > 0 ) {
$user_arr[$v_username] = array( $v_username, $v_id );
continue;
}
}
}
}
asort( $user_arr );
foreach ( $user_arr as $key => $val ) {
$v_id = $val[1];
$v_username = $val[0];
echo "<option value=\"$v_id\"";
check_selected( $v_id, $p_user_id );
echo ">$v_username</option>";
} # end foreach
}
# --------------------
# List projects that the current user has access to
function print_project_option_list( $p_project_id = null, $p_include_all_projects = true ) {
global $g_mantis_project_table, $g_mantis_project_user_list_table,
$g_project_cookie_val;
$t_user_id = current_user_get_field( 'id' );
$t_access_level = current_user_get_field( 'access_level' );
$t_pub = PUBLIC;
$t_prv = PRIVATE;
if ( ADMINISTRATOR == $t_access_level ) {
$query = "SELECT DISTINCT( p.id ), p.name
FROM $g_mantis_project_table p
WHERE p.enabled=1
ORDER BY p.name";
} else {
$query = "SELECT DISTINCT( p.id ), p.name
FROM $g_mantis_project_table p
LEFT JOIN $g_mantis_project_user_list_table u
ON p.id=u.project_id
WHERE p.enabled=1 AND
((p.view_state=$t_pub) OR
(p.view_state=$t_prv AND u.user_id=$t_user_id))
ORDER BY p.name";
}
$result = db_query( $query );
$project_count = db_num_rows( $result );
if ( $p_include_all_projects ) {
echo '<option value="0"';
check_selected( $p_project_id, 0 );
echo '>' . lang_get( 'all_projects' ) . '</option>';
}
for ($i=0;$i<$project_count;$i++) {
$row = db_fetch_array( $result );
extract( $row, EXTR_PREFIX_ALL, 'v' );
echo "<option value=\"$v_id\"";
check_selected( $p_project_id, $v_id );
echo ">$v_name</option>";
}
}
# --------------------
# prints the profiles given the user id
function print_profile_option_list( $p_user_id, $p_select_id='' ) {
global $g_mantis_user_profile_table, $g_mantis_user_pref_table;
$c_user_id = db_prepare_int( $p_user_id );
$query = "SELECT default_profile
FROM $g_mantis_user_pref_table
WHERE user_id='$c_user_id'";
$result = db_query( $query );
$v_default_profile = db_result( $result, 0, 0 );
# Get profiles
$query = "SELECT id, platform, os, os_build
FROM $g_mantis_user_profile_table
WHERE user_id='$c_user_id'
ORDER BY id";
$result = db_query( $query );
$profile_count = db_num_rows( $result );
PRINT '<option value=""></option>';
for ($i=0;$i<$profile_count;$i++) {
# prefix data with v_
$row = db_fetch_array( $result );
extract( $row, EXTR_PREFIX_ALL, 'v' );
$v_platform = string_display( $v_platform );
$v_os = string_display( $v_os );
$v_os_build = string_display( $v_os_build );
echo "<option value=\"$v_id\"";
check_selected( $v_id, $v_default_profile );
echo ">$v_platform $v_os $v_os_build</option>";
}
}
# --------------------
function print_news_project_option_list( $p_project_id ) {
global $g_mantis_project_table, $g_mantis_project_user_list_table,
$g_project_cookie;
if ( access_level_check_greater_or_equal( ADMINISTRATOR ) ) {
$query = "SELECT *
FROM $g_mantis_project_table
ORDER BY name";
} else {
$t_user_id = current_user_get_field( 'id' );
$query = "SELECT p.id, p.name
FROM $g_mantis_project_table p, $g_mantis_project_user_list_table m
WHERE p.id=m.project_id AND
m.user_id='$t_user_id' AND
p.enabled='1'";
}
$result = db_query( $query );
$project_count = db_num_rows( $result );
for ($i=0;$i<$project_count;$i++) {
$row = db_fetch_array( $result );
extract( $row, EXTR_PREFIX_ALL, 'v' );
echo "<option value=\"$v_id\"";
check_selected( $v_id, $p_project_id );
echo ">$v_name</option>";
} # end for
}
# --------------------
# Since categories can be orphaned we need to grab all unique instances of category
# We check in the project category table and in the bug table
# We put them all in one array and make sure the entries are unique
function print_category_option_list( $p_category='' ) {
global $g_mantis_bug_table, $g_mantis_project_category_table, $g_project_cookie_val;
# grab all categories in the project category table
$cat_arr = array();
$query = "SELECT DISTINCT( category ) as category
FROM $g_mantis_project_category_table
WHERE project_id='$g_project_cookie_val'
ORDER BY category";
$result = db_query( $query );
$category_count = db_num_rows( $result );
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$cat_arr[] = $row['category'];
}
sort( $cat_arr );
$cat_arr = array_unique( $cat_arr );
foreach( $cat_arr as $t_category ) {
echo "<option value=\"$t_category\"";
check_selected( $t_category, $p_category );
echo ">$t_category</option>";
}
}
# --------------------
# Since categories can be orphaned we need to grab all unique instances of category
# We check in the project category table and in the bug table
# We put them all in one array and make sure the entries are unique
function print_category_complete_option_list( $p_category='' ) {
global $g_mantis_bug_table, $g_mantis_project_category_table, $g_project_cookie_val;
# grab all categories in the project category table
$cat_arr = array();
$query = "SELECT DISTINCT( category ) as category
FROM $g_mantis_project_category_table
WHERE project_id='$g_project_cookie_val'
ORDER BY category";
$result = db_query( $query );
$category_count = db_num_rows( $result );
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$cat_arr[] = $row['category'];
}
# grab all categories in the bug table
$query = "SELECT DISTINCT( category ) as category
FROM $g_mantis_bug_table
WHERE project_id='$g_project_cookie_val'
ORDER BY category";
$result = db_query( $query );
$category_count = db_num_rows( $result );
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$cat_arr[] = $row['category'];
}
sort( $cat_arr );
$cat_arr = array_unique( $cat_arr );
foreach( $cat_arr as $t_category ) {
echo "<option value=\"$t_category\"";
check_selected( $t_category, $p_category );
echo ">$t_category</option>";
}
}
# --------------------
function print_category_option_listOLD( $p_category='' ) {
global $g_mantis_project_category_table, $g_project_cookie_val;
# @@@ not implemented yet
if ( '0000000' == $g_project_cookie_val ) {
$query = "SELECT category
FROM $g_mantis_project_category_table
WHERE project_id='$g_project_cookie_val'
ORDER BY category";
} else {
$query = "SELECT category
FROM $g_mantis_project_category_table
WHERE project_id='$g_project_cookie_val'
ORDER BY category";
}
$result = db_query( $query );
$category_count = db_num_rows( $result );
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$t_category = $row['category'];
echo "<option value=\"$t_category\"";
check_selected( $t_category, $p_category );
echo ">$t_category</option>";
}
}
# --------------------
function print_version_option_list( $p_version='' ) {
global $g_mantis_project_version_table, $g_project_cookie_val;
$query = "SELECT *
FROM $g_mantis_project_version_table
WHERE project_id='$g_project_cookie_val'
ORDER BY date_order DESC";
$result = db_query( $query );
$version_count = db_num_rows( $result );
for ($i=0;$i<$version_count;$i++) {
$row = db_fetch_array( $result );
$t_version = $row['version'];
echo "<option value=\"$t_version\"";
check_selected( $t_version, $p_version );
echo ">$t_version</option>";
}
}
# --------------------
# select the proper enum values based on the input parameter
# we use variable variables in order to achieve this
function print_enum_string_option_list( $p_enum_name, $p_val=0 ) {
$g_var = 'g_'.$p_enum_name.'_enum_string';
global $$g_var, $g_customize_attributes;
# custom attributes
if ($g_customize_attributes) {
# to be deleted when moving to manage_project_page.php
$f_project_id = '0000000';
# custom attributes insertion
attribute_insert( $p_enum_name, $f_project_id, 'global' );
}
$t_arr = explode_enum_string( $$g_var );
$enum_count = count( $t_arr );
for ($i=0;$i<$enum_count;$i++) {
$t_elem = explode_enum_arr( $t_arr[$i] );
$t_elem2 = get_enum_element( $p_enum_name, $t_elem[0] );
echo "<option value=\"$t_elem[0]\"";
check_selected( $t_elem[0], $p_val );
echo ">$t_elem2</option>";
} # end for
}
# --------------------
# prints the list of access levels exluding ADMINISTRATOR
# this is used when adding users to projects
function print_project_user_option_list( $p_val ) {
global $g_mantis_project_table, $g_access_levels_enum_string;
$t_arr = explode_enum_string( $g_access_levels_enum_string );
$enum_count = count( $t_arr );
for ($i=0;$i<$enum_count;$i++) {
$t_elem = explode_enum_arr( $t_arr[$i] );
if ( $t_elem[0] >= ADMINISTRATOR ) {
continue;
}
$t_access_level = get_enum_element( 'access_levels', $t_elem[0] );
echo "<option value=\"$t_elem[0]\"";
check_selected( $p_val, $t_elem[0] );
echo ">$t_access_level</option>";
} # end for
}
# --------------------
function print_language_option_list( $p_language ) {
global $g_language_choices_arr;
$t_arr = $g_language_choices_arr;
$enum_count = count( $t_arr );
for ($i=0;$i<$enum_count;$i++) {
echo "<option value=\"$t_arr[$i]\"";
check_selected( $t_arr[$i], $p_language );
echo ">$t_arr[$i]</option>";
} # end for
}
# --------------------
# @@@ preliminary support for multiple bug actions.
function print_all_bug_action_option_list() {
$commands = array( 'MOVE' => 'Move Bugs',
'ASSIGN' => 'Assign',
'CLOSE' => 'Close',
'DELETE' => 'Delete',
'RESOLVE' => 'Resolve',
'UP_PRIOR' => 'Update Priority',
'UP_STATUS' => 'Update Status' );
while (list ($key,$val) = each ($commands)) {
PRINT "<option value=\"".$key."\">".$val."</option>";
}
}
# --------------------
# list of users that are NOT in the specified project
# if no project is specified use the current project
function print_project_user_list_option_list( $p_project_id=0 ) {
global $g_mantis_project_user_list_table, $g_mantis_user_table,
$g_project_cookie_val;
if ( 0 == $p_project_id ) {
$p_project_id = $g_project_cookie_val;
}
$c_project_id = (integer)$p_project_id;
$t_adm = ADMINISTRATOR;
$query = "SELECT DISTINCT u.id, u.username
FROM $g_mantis_user_table u
LEFT JOIN $g_mantis_project_user_list_table p
ON p.user_id=u.id AND p.project_id='$c_project_id'
WHERE u.access_level<$t_adm AND
p.user_id IS NULL AND
u.access_level<'$t_adm'
ORDER BY u.username";
$result = db_query( $query );
$category_count = db_num_rows( $result );
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$t_username = $row['username'];
$t_user_id = $row['id'];
PRINT "<option value=\"$t_user_id\">$t_username</option>";
}
}
# --------------------
# list of projects that a user is NOT in
function print_project_user_list_option_list2( $p_user_id ) {
global $g_mantis_project_user_list_table, $g_mantis_project_table;
$c_user_id = db_prepare_int( $p_user_id );
$t_prv = PRIVATE;
$query = "SELECT DISTINCT p.id, p.name
FROM $g_mantis_project_table p
LEFT JOIN $g_mantis_project_user_list_table u
ON p.id=u.project_id AND u.user_id='$c_user_id'
WHERE p.enabled=1 AND
p.view_state='$t_prv' AND
u.user_id IS NULL
ORDER BY p.name";
$result = db_query( $query );
$category_count = db_num_rows( $result );
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$t_project_name = $row['name'];
$t_user_id = $row['id'];
PRINT "<option value=\"$t_user_id\">$t_project_name</option>";
}
}
# --------------------
# list of projects that a user is NOT in
function print_project_user_list( $p_user_id ) {
global $g_mantis_project_user_list_table, $g_mantis_project_table;
$c_user_id = db_prepare_int( $p_user_id );
$query = "SELECT DISTINCT p.id, p.name, p.view_state, u.access_level
FROM $g_mantis_project_table p
LEFT JOIN $g_mantis_project_user_list_table u
ON p.id=u.project_id
WHERE p.enabled=1 AND
u.user_id='$c_user_id'
ORDER BY p.name";
$result = db_query( $query );
$category_count = db_num_rows( $result );
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$t_project_id = $row['id'];
$t_project_name = $row['name'];
$t_view_state = $row['view_state'];
$t_access_level = $row['access_level'];
$t_access_level = get_enum_element( 'access_levels', $t_access_level );
$t_view_state = get_enum_element( 'project_view_state', $t_view_state );
PRINT $t_project_name.' ['.$t_access_level.'] ('.$t_view_state.') [<a class="small" href="manage_user_proj_delete.php?f_project_id='.$t_project_id.'&f_user_id='.$p_user_id.'">'. lang_get( 'remove_link' ).'</a>]<br />';
}
}
# --------------------
# color list printing options for custom status
function print_custom_status_color_list() {
global $g_custom_colors ;
while (list ($key,$val) = each ($g_custom_colors)) {
PRINT "<option value=\"".$key."\">".$val."</option>";
}
}
# --------------------
###########################################################################
# String printing API
###########################################################################
# --------------------
# prints a link to VIEW a bug given an ID
# account for the user preference and site override
function print_bug_link( $p_bug_id ) {
echo string_get_bug_view_link( $p_bug_id );
}
# --------------------
# prints a link to UPDATE a bug given an ID
# account for the user preference and site override
function print_bug_update_link( $p_bug_id ) {
echo string_get_bug_update_link( $p_bug_id );
}
# --------------------
# formats the priority given the status
# shows the priority in BOLD if the bug is NOT closed and is of significant priority
function print_formatted_priority_string( $p_status, $p_priority ) {
$t_pri_str = get_enum_element( 'priority', $p_priority );
if ( ( HIGH <= $p_priority ) &&
( CLOSED != $p_status ) ) {
echo "<span class=\"bold\">$t_pri_str</span>";
} else {
echo $t_pri_str;
}
}
# --------------------
# formats the severity given the status
# shows the severity in BOLD if the bug is NOT closed and is of significant severity
function print_formatted_severity_string( $p_status, $p_severity ) {
$t_sev_str = get_enum_element( 'severity', $p_severity );
if ( ( MAJOR <= $p_severity ) &&
( CLOSED != $p_status ) ) {
echo "<span class=\"bold\">$t_sev_str</span>";
} else {
echo $t_sev_str;
}
}
# --------------------
function print_project_category_string( $p_project_id ) {
global $g_mantis_project_category_table, $g_mantis_project_table;
$c_project_id = (integer)$p_project_id;
$query = "SELECT category
FROM $g_mantis_project_category_table
WHERE project_id='$c_project_id'
ORDER BY category";
$result = db_query( $query );
$category_count = db_num_rows( $result );
$t_string = '';
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$t_category = $row['category'];
if ( $i+1 < $category_count ) {
$t_string .= $t_category.', ';
} else {
$t_string .= $t_category;
}
}
return $t_string;
}
# --------------------
function print_project_version_string( $p_project_id ) {
global $g_mantis_project_version_table, $g_mantis_project_table;
$c_project_id = (integer)$p_project_id;
$query = "SELECT version
FROM $g_mantis_project_version_table
WHERE project_id='$c_project_id'";
$result = db_query( $query );
$version_count = db_num_rows( $result );
$t_string = '';
for ($i=0;$i<$version_count;$i++) {
$row = db_fetch_array( $result );
$t_version = $row['version'];
if ( $i+1 < $version_count ) {
$t_string .= $t_version.', ';
} else {
$t_string .= $t_version;
}
}
return $t_string;
}
# --------------------
###########################################################################
# Link Printing API
###########################################################################
# --------------------
function print_view_bug_sort_link( $p_string, $p_sort_field, $p_sort, $p_dir ) {
if ( $p_sort_field == $p_sort ) {
# we toggle between ASC and DESC if the user clicks the same sort order
if ( 'ASC' == $p_dir ) {
$p_dir = 'DESC';
} else {
$p_dir = 'ASC';
}
}
PRINT '<a href="view_all_set.php?f_sort='.$p_sort_field.'&f_dir='.$p_dir.'&f_type=2">'.$p_string.'</a>';
}
# --------------------
function print_view_bug_sort_link2( $p_string, $p_sort_field, $p_sort, $p_dir ) {
if ( $p_sort_field == $p_sort ) {
# We toggle between ASC and DESC if the user clicks the same sort order
if ( 'ASC' == $p_dir ) {
$p_dir = 'DESC';
} else {
$p_dir = 'ASC';
}
}
PRINT '<a href="view_all_set.php?f_sort='.$p_sort_field.'&f_dir='.$p_dir.'&f_type=2&f_print=1">'.$p_string.'</a>';
}
# --------------------
function print_manage_user_sort_link( $p_page, $p_string, $p_field, $p_dir, $p_sort_by, $p_hide=0 ) {
if ($p_sort_by == $p_field) { # If this is the selected field flip the order
if ($p_dir == 'ASC') {
$t_dir = 'DESC';
} else {
$t_dir = 'ASC';
}
} else { # Otherwise always start with ASCending
$t_dir = 'ASC';
}
PRINT '<a href="'.$p_page.'?f_sort='.$p_field.'&f_dir='.$t_dir.'&f_save=1&f_hide='.$p_hide.'">'.$p_string.'</a>';
}
# --------------------
function print_manage_project_sort_link( $p_page, $p_string, $p_field, $p_dir, $p_sort_by ) {
if ($p_sort_by == $p_field) { # If this is the selected field flip the order
if ($p_dir == 'ASC') {
$t_dir = 'DESC';
} else {
$t_dir = 'ASC';
}
} else { # Otherwise always start with ASCending
$t_dir = 'ASC';
}
PRINT '<a href="'.$p_page.'?f_sort='.$p_field.'&f_dir='.$t_dir.'">'.$p_string.'</a>';
}
# --------------------
# print the bracketed links used near the top
# if the $p_link is blank then the text is printed but no link is created
function print_bracket_link( $p_link, $p_url_text ) {
if (empty( $p_link )) {
PRINT "[ $p_url_text ]";
} else {
PRINT "[ <a href=\"$p_link\">$p_url_text</a> ]";
}
}
# --------------------
# print a list of page number links (eg [1 2 3])
function print_page_links( $p_page, $p_start, $p_end, $p_current ) {
$t_items = array();
for ( $i = $p_start ; $i <= $p_end ; $i++ ) {
if ( $i == $p_current ) {
array_push( $t_items, $i );
} else {
array_push( $t_items, "<a href=\"$p_page?f_page_number=$i\">$i</a>" );
}
}
echo '[ '.implode( ' ', $t_items ).' ]';
}
# --------------------
# print a mailto: href link
function print_email_link( $p_email, $p_text ) {
PRINT get_email_link($p_email,$p_text);
}
# --------------------
# return the mailto: href string link instead of printing it
function get_email_link( $p_email, $p_text ) {
global $g_show_user_email, $g_anonymous_account;
switch ( $g_show_user_email ) {
case NONE: return $p_text;
case ALL: return "<a href=\"mailto:$p_email\">$p_text</a>";
case NO_ANONYMOUS: if ( current_user_get_field( 'username' ) != $g_anonymous_account ) {
return "<a href=\"mailto:$p_email\">$p_text</a>";
} else {
return $p_text;
}
case ADMIN_ONLY: if ( ADMINISTRATOR == current_user_get_field( 'access_level' ) ) {