forked from mantisbt/mantisbt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_api.php
1980 lines (1778 loc) · 67.4 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
# MantisBT - A PHP based bugtracking system
# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
/**
* Print API
*
* @package CoreAPI
* @subpackage PrintAPI
* @copyright Copyright 2000 - 2002 Kenzaburo Ito - [email protected]
* @copyright Copyright 2002 MantisBT Team - [email protected]
* @link http://www.mantisbt.org
*
* @uses access_api.php
* @uses authentication_api.php
* @uses bug_group_action_api.php
* @uses category_api.php
* @uses config_api.php
* @uses collapse_api.php
* @uses constant_inc.php
* @uses current_user_api.php
* @uses custom_field_api.php
* @uses database_api.php
* @uses email_api.php
* @uses error_api.php
* @uses file_api.php
* @uses form_api.php
* @uses helper_api.php
* @uses html_api.php
* @uses lang_api.php
* @uses last_visited_api.php
* @uses news_api.php
* @uses prepare_api.php
* @uses profile_api.php
* @uses project_api.php
* @uses project_hierarchy_api.php
* @uses string_api.php
* @uses tag_api.php
* @uses user_api.php
* @uses utility_api.php
* @uses version_api.php
*/
require_api( 'access_api.php' );
require_api( 'authentication_api.php' );
require_api( 'bug_group_action_api.php' );
require_api( 'category_api.php' );
require_api( 'config_api.php' );
require_api( 'collapse_api.php' );
require_api( 'constant_inc.php' );
require_api( 'current_user_api.php' );
require_api( 'custom_field_api.php' );
require_api( 'database_api.php' );
require_api( 'email_api.php' );
require_api( 'error_api.php' );
require_api( 'file_api.php' );
require_api( 'form_api.php' );
require_api( 'helper_api.php' );
require_api( 'html_api.php' );
require_api( 'lang_api.php' );
require_api( 'last_visited_api.php' );
require_api( 'news_api.php' );
require_api( 'prepare_api.php' );
require_api( 'profile_api.php' );
require_api( 'project_api.php' );
require_api( 'project_hierarchy_api.php' );
require_api( 'string_api.php' );
require_api( 'tag_api.php' );
require_api( 'user_api.php' );
require_api( 'utility_api.php' );
require_api( 'version_api.php' );
/**
* 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 return false and don't redirect.
* $p_sanitize - true/false - true in the case where the URL is extracted from GET/POST or untrusted source.
* This would be false if the URL is trusted (e.g. read from config_inc.php).
*
* @param string $p_url The page to redirect: has to be a relative path.
* @param boolean $p_die If true, stop the script after redirecting.
* @param boolean $p_sanitize Apply string_sanitize_url to passed URL.
* @param boolean $p_absolute Indicate if URL is absolute.
* @return boolean
*/
function print_header_redirect( $p_url, $p_die = true, $p_sanitize = false, $p_absolute = false ) {
if( ON == config_get_global( 'stop_on_errors' ) && error_handled() ) {
return false;
}
# validate the url as part of this site before continuing
if( $p_absolute ) {
if( $p_sanitize ) {
$t_url = string_sanitize_url( $p_url );
} else {
$t_url = $p_url;
}
} else {
if( $p_sanitize ) {
$t_url = string_sanitize_url( $p_url, true );
} else {
$t_url = config_get( 'path' ) . $p_url;
}
}
$t_url = string_prepare_header( $t_url );
# don't send more headers if they have already been sent
if( !headers_sent() ) {
header( 'Content-Type: text/html; charset=utf-8' );
header( "Location: $t_url" );
} else {
trigger_error( ERROR_PAGE_REDIRECTION, ERROR );
return false;
}
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
*
* @param integer $p_bug_id A bug identifier.
* @return void
*/
function print_header_redirect_view( $p_bug_id ) {
print_header_redirect( string_get_bug_view_url( $p_bug_id ) );
}
/**
* Get a view URL for the bug id based on the user's preference and
* call print_successful_redirect() with that URL
*
* @param integer $p_bug_id A bug identifier.
* @return void
*/
function print_successful_redirect_to_bug( $p_bug_id ) {
$t_url = string_get_bug_view_url( $p_bug_id, auth_get_current_user_id() );
print_successful_redirect( $t_url );
}
/**
* If the show query count is ON, print success and redirect after the configured system wait time.
* If the show query count is OFF, redirect right away.
*
* @param string $p_redirect_to URI to redirect to.
* @return void
*/
function print_successful_redirect( $p_redirect_to ) {
if( helper_log_to_page() ) {
html_page_top( null, $p_redirect_to );
echo '<br /><div class="center">';
echo lang_get( 'operation_successful' ) . '<br />';
print_bracket_link( $p_redirect_to, lang_get( 'proceed' ) );
echo '</div>';
html_page_bottom();
} else {
print_header_redirect( $p_redirect_to );
}
}
/**
* Print avatar image for the given user ID
*
* @param integer $p_user_id A user identifier.
* @param integer $p_size Image pixel size.
* @return void
*/
function print_avatar( $p_user_id, $p_size = 80 ) {
if( OFF === config_get( 'show_avatar' ) ) {
return;
}
if( !user_exists( $p_user_id ) ) {
return;
}
if( access_has_project_level( config_get( 'show_avatar_threshold' ), null, $p_user_id ) ) {
$t_avatar = user_get_avatar( $p_user_id, $p_size );
if( !empty( $t_avatar ) ) {
$t_avatar_url = htmlspecialchars( $t_avatar[0] );
$t_width = $t_avatar[1];
$t_height = $t_avatar[2];
echo '<a rel="nofollow" href="http://site.gravatar.com"><img class="avatar" src="' . $t_avatar_url . '" alt="User avatar" width="' . $t_width . '" height="' . $t_height . '" /></a>';
}
}
}
/**
* prints the name of the user given the id. also makes it an email link.
*
* @param integer $p_user_id A user identifier.
* @return void
*/
function print_user( $p_user_id ) {
echo prepare_user_name( $p_user_id );
}
/**
* same as echo get_user_name() but fills in the subject with the bug summary
*
* @param integer $p_user_id A user identifier.
* @param integer $p_bug_id A bug identifier.
* @return void
*/
function print_user_with_subject( $p_user_id, $p_bug_id ) {
if( NO_USER == $p_user_id ) {
return;
}
$t_username = user_get_name( $p_user_id );
if( user_exists( $p_user_id ) && user_get_field( $p_user_id, 'enabled' ) ) {
$t_email = user_get_email( $p_user_id );
print_email_link_with_subject( $t_email, $t_username, $p_bug_id );
} else {
echo '<span class="user" style="text-decoration: line-through">';
echo $t_username;
echo '</span>';
}
}
/**
* print out an email editing input
*
* @param string $p_field_name Name of input tag.
* @param string $p_email Email address.
* @return void
*/
function print_email_input( $p_field_name, $p_email ) {
echo '<input id="email-field" type="text" name="' . string_attribute( $p_field_name ) . '" size="32" maxlength="64" value="' . string_attribute( $p_email ) . '" />';
}
/**
* print out an email editing input
*
* @param string $p_field_name Name of input tag.
* @return void
*/
function print_captcha_input( $p_field_name ) {
echo '<input id="captcha-field" type="text" name="' . $p_field_name . '" size="6" maxlength="6" value="" />';
}
/**
* This populates an option list with the appropriate users by access level
* @todo from print_reporter_option_list
* @param integer $p_user_id A user identifier.
* @param integer $p_project_id A project identifier.
* @param integer $p_access An access level.
* @return void
*/
function print_user_option_list( $p_user_id, $p_project_id = null, $p_access = ANYBODY ) {
$t_current_user = auth_get_current_user_id();
if( null === $p_project_id ) {
$p_project_id = helper_get_current_project();
}
if( $p_project_id === ALL_PROJECTS ) {
$t_projects = user_get_accessible_projects( $t_current_user );
# Get list of users having access level for all accessible projects
$t_users = array();
foreach( $t_projects as $t_project_id ) {
$t_project_users_list = project_get_all_user_rows( $t_project_id, $p_access );
# Do a 'smart' merge of the project's user list, into an
# associative array (to remove duplicates)
# Use a while loop for better performance
$i = 0;
while( isset( $t_project_users_list[$i] ) ) {
$t_users[$t_project_users_list[$i]['id']] = $t_project_users_list[$i];
$i++;
}
unset( $t_project_users_list );
}
unset( $t_projects );
} else {
$t_users = project_get_all_user_rows( $p_project_id, $p_access );
}
$t_display = array();
$t_sort = array();
$t_show_realname = ( ON == config_get( 'show_realname' ) );
$t_sort_by_last_name = ( ON == config_get( 'sort_by_last_name' ) );
foreach( $t_users as $t_key => $t_user ) {
$t_user_name = string_attribute( $t_user['username'] );
$t_sort_name = utf8_strtolower( $t_user_name );
if( $t_show_realname && ( $t_user['realname'] <> '' ) ) {
$t_user_name = string_attribute( $t_user['realname'] );
if( $t_sort_by_last_name ) {
$t_sort_name_bits = explode( ' ', utf8_strtolower( $t_user_name ), 2 );
$t_sort_name = ( isset( $t_sort_name_bits[1] ) ? $t_sort_name_bits[1] . ', ' : '' ) . $t_sort_name_bits[0];
} else {
$t_sort_name = utf8_strtolower( $t_user_name );
}
}
$t_display[] = $t_user_name;
$t_sort[] = $t_sort_name;
}
array_multisort( $t_sort, SORT_ASC, SORT_STRING, $t_users, $t_display );
unset( $t_sort );
$t_count = count( $t_users );
for( $i = 0;$i < $t_count;$i++ ) {
$t_row = $t_users[$i];
echo '<option value="' . $t_row['id'] . '" ';
check_selected( $p_user_id, (int)$t_row['id'] );
echo '>' . $t_display[$i] . '</option>';
}
}
/**
* This populates the reporter option list with the appropriate users
*
* @todo ugly functions need to be refactored
* @todo This function really ought to print out all the users, I think.
* I just encountered a situation where a project used to be public and
* was made private, so now I can't filter on any of the reporters who
* actually reported the bugs at the time. Maybe we could get all user
* who are listed as the reporter in any bug? It would probably be a
* faster query actually.
* @param integer $p_user_id A user identifier.
* @param integer $p_project_id A project identifier.
* @return void
*/
function print_reporter_option_list( $p_user_id, $p_project_id = null ) {
print_user_option_list( $p_user_id, $p_project_id, config_get( 'report_bug_threshold' ) );
}
/**
* Print the entire form for attaching a tag to a bug.
* @param integer $p_bug_id A bug identifier.
* @param string $p_string Default contents of the input box.
* @return boolean
*/
function print_tag_attach_form( $p_bug_id, $p_string = '' ) {
?>
<small><?php echo sprintf( lang_get( 'tag_separate_by' ), config_get( 'tag_separator' ) )?></small>
<form method="post" action="tag_attach.php">
<?php echo form_security_field( 'tag_attach' )?>
<input type="hidden" name="bug_id" value="<?php echo $p_bug_id?>" />
<?php
print_tag_input( $p_bug_id, $p_string );
?>
<input type="submit" value="<?php echo lang_get( 'tag_attach' )?>" class="button" />
</form>
<?php
return true;
}
/**
* Print the separator comment, input box, and existing tag dropdown menu.
* @param integer $p_bug_id A bug identifier.
* @param string $p_string Default contents of the input box.
* @return void
*/
function print_tag_input( $p_bug_id = 0, $p_string = '' ) {
?>
<input type="hidden" id="tag_separator" value="<?php echo config_get( 'tag_separator' )?>" />
<input type="text" name="tag_string" id="tag_string" size="40" value="<?php echo string_attribute( $p_string )?>" />
<select <?php echo helper_get_tab_index()?> name="tag_select" id="tag_select">
<?php print_tag_option_list( $p_bug_id );?>
</select>
<?php
}
/**
* Print the drop-down combo-box of existing tags.
* When passed a bug ID, the option list will not contain any tags attached to the given bug.
* @param integer $p_bug_id A bug identifier.
* @return void
*/
function print_tag_option_list( $p_bug_id = 0 ) {
$t_rows = tag_get_candidates_for_bug( $p_bug_id );
echo '<option value="0">', string_html_specialchars( lang_get( 'tag_existing' ) ), '</option>';
foreach ( $t_rows as $t_row ) {
$t_string = $t_row['name'];
if( !empty( $t_row['description'] ) ) {
$t_string .= ' - ' . utf8_substr( $t_row['description'], 0, 20 );
}
echo '<option value="', $t_row['id'], '" title="', string_attribute( $t_row['name'] ), '">', string_attribute( $t_string ), '</option>';
}
}
/**
* Get current headlines and id prefix with v_
* @return void
*/
function print_news_item_option_list() {
$t_mantis_news_table = db_get_table( 'news' );
$t_project_id = helper_get_current_project();
$t_global = access_has_global_level( config_get_global( 'admin_site_threshold' ) );
if( $t_global ) {
$t_query = "SELECT id, headline, announcement, view_state
FROM $t_mantis_news_table
ORDER BY date_posted DESC";
} else {
$t_query = "SELECT id, headline, announcement, view_state
FROM $t_mantis_news_table
WHERE project_id=" . db_param() . "
ORDER BY date_posted DESC";
}
$t_result = db_query_bound( $t_query, ($t_global == true ? array() : array( $t_project_id ) ) );
$t_news_count = db_num_rows( $t_result );
for( $i = 0;$i < $t_news_count;$i++ ) {
$t_row = db_fetch_array( $t_result );
$t_headline = string_display( $t_row['headline'] );
$t_announcement = $t_row['announcement'];
$t_view_state = $t_row['view_state'];
$t_id = $t_row['id'];
$t_notes = array();
$t_note_string = '';
if( 1 == $t_announcement ) {
array_push( $t_notes, lang_get( 'announcement' ) );
}
if( VS_PRIVATE == $t_view_state ) {
array_push( $t_notes, lang_get( 'private' ) );
}
if( count( $t_notes ) > 0 ) {
$t_note_string = ' [' . implode( ' ', $t_notes ) . ']';
}
echo "<option value=\"$t_id\">$t_headline$t_note_string</option>";
}
}
/**
* Constructs the string for one news entry given the row retrieved from the news table.
*
* @param string $p_headline Headline of news article.
* @param string $p_body Body text of news article.
* @param integer $p_poster_id User ID of author.
* @param integer $p_view_state View State - either VS_PRIVATE or VS_PUBLIC.
* @param boolean $p_announcement Flagged if news should be an announcement.
* @param integer $p_date_posted Date associated with news entry.
* @return void
*/
function print_news_entry( $p_headline, $p_body, $p_poster_id, $p_view_state, $p_announcement, $p_date_posted ) {
$t_headline = string_display_links( $p_headline );
$t_body = string_display_links( $p_body );
$t_date_posted = date( config_get( 'normal_date_format' ), $p_date_posted );
if( VS_PRIVATE == $p_view_state ) {
$t_news_css = 'news-heading-private';
} else {
$t_news_css = 'news-heading-public';
} ?>
<div class="news-item">
<h3 class="<?php echo $t_news_css; ?>">
<span class="news-title"><?php echo $t_headline; ?></span>
<span class="news-date-posted"><?php echo $t_date_posted; ?></span>
<span class="news-author"><?php echo prepare_user_name( $p_poster_id ); ?></span><?php
if( 1 == $p_announcement ) { ?>
<span class="news-announcement"><?php echo lang_get( 'announcement' ); ?></span><?php
}
if( VS_PRIVATE == $p_view_state ) { ?>
<span class="news-private"><?php echo lang_get( 'private' ); ?></span><?php
} ?>
</h3>
<p class="news-body"><?php echo $t_body; ?></p>
</div><?php
}
/**
* print a news item given a row in the news table.
* @param array $p_news_row A news database result.
* @return void
*/
function print_news_entry_from_row( array $p_news_row ) {
$t_headline = $p_news_row['headline'];
$t_body = $p_news_row['body'];
$t_poster_id = $p_news_row['poster_id'];
$t_view_state = $p_news_row['view_state'];
$t_announcement = $p_news_row['announcement'];
$t_date_posted = $p_news_row['date_posted'];
print_news_entry( $t_headline, $t_body, $t_poster_id, $t_view_state, $t_announcement, $t_date_posted );
}
/**
* print a news item
*
* @param integer $p_news_id A news article identifier.
* @return void
*/
function print_news_string_by_news_id( $p_news_id ) {
$t_row = news_get_row( $p_news_id );
# only show VS_PRIVATE posts to configured threshold and above
if( ( VS_PRIVATE == $t_row['view_state'] ) && !access_has_project_level( config_get( 'private_news_threshold' ) ) ) {
return;
}
print_news_entry_from_row( $t_row );
}
/**
* Print User option list for assigned to field
* @param integer|string $p_user_id A user identifier.
* @param integer $p_project_id A project identifier.
* @param integer $p_threshold An access level.
* @return void
*/
function print_assign_to_option_list( $p_user_id = '', $p_project_id = null, $p_threshold = null ) {
if( null === $p_threshold ) {
$p_threshold = config_get( 'handle_bug_threshold' );
}
print_user_option_list( $p_user_id, $p_project_id, $p_threshold );
}
/**
* Print User option list for bugnote filter field
* @param integer|string $p_user_id A user identifier.
* @param integer $p_project_id A project identifier.
* @param integer $p_threshold An access level.
* @return void
*/
function print_note_option_list( $p_user_id = '', $p_project_id = null, $p_threshold = null ) {
if( null === $p_threshold ) {
$p_threshold = config_get( 'add_bugnote_threshold' );
}
print_user_option_list( $p_user_id, $p_project_id, $p_threshold );
}
/**
* List projects that the current user has access to.
*
* @param integer $p_project_id The current project id or null to use cookie.
* @param boolean $p_include_all_projects True: include "All Projects", otherwise false.
* @param integer|null $p_filter_project_id The id of a project to exclude or null.
* @param string|boolean $p_trace The current project trace, identifies the sub-project via a path from top to bottom.
* @param boolean $p_can_report_only If true, disables projects in which user can't report issues; defaults to false (all projects enabled).
* @return void
*/
function print_project_option_list( $p_project_id = null, $p_include_all_projects = true, $p_filter_project_id = null, $p_trace = false, $p_can_report_only = false ) {
$t_user_id = auth_get_current_user_id();
$t_project_ids = user_get_accessible_projects( $t_user_id );
$t_can_report = true;
project_cache_array_rows( $t_project_ids );
if( $p_include_all_projects && $p_filter_project_id !== ALL_PROJECTS ) {
echo '<option value="' . ALL_PROJECTS . '"';
if( $p_project_id !== null ) {
check_selected( $p_project_id, ALL_PROJECTS, false );
}
echo '>' . lang_get( 'all_projects' ) . '</option>' . "\n";
}
foreach( $t_project_ids as $t_id ) {
if( $p_can_report_only ) {
$t_report_bug_threshold = config_get( 'report_bug_threshold', null, $t_user_id, $t_id );
$t_can_report = access_has_project_level( $t_report_bug_threshold, $t_id, $t_user_id );
}
echo '<option value="' . $t_id . '"';
check_selected( $p_project_id, $t_id, false );
check_disabled( $t_id == $p_filter_project_id || !$t_can_report );
echo '>' . string_attribute( project_get_field( $t_id, 'name' ) ) . '</option>' . "\n";
print_subproject_option_list( $t_id, $p_project_id, $p_filter_project_id, $p_trace, $p_can_report_only );
}
}
/**
* List projects that the current user has access to
* @param integer $p_parent_id A parent project identifier.
* @param integer $p_project_id A project identifier.
* @param integer $p_filter_project_id A filter project identifier.
* @param boolean $p_trace Whether to trace parent projects.
* @param boolean $p_can_report_only If true, disables projects in which user can't report issues; defaults to false (all projects enabled).
* @param array $p_parents Array of parent projects.
* @return void
*/
function print_subproject_option_list( $p_parent_id, $p_project_id = null, $p_filter_project_id = null, $p_trace = false, $p_can_report_only = false, array $p_parents = array() ) {
array_push( $p_parents, $p_parent_id );
$t_user_id = auth_get_current_user_id();
$t_project_ids = user_get_accessible_subprojects( $t_user_id, $p_parent_id );
$t_can_report = true;
foreach( $t_project_ids as $t_id ) {
if( $p_can_report_only ) {
$t_report_bug_threshold = config_get( 'report_bug_threshold', null, $t_user_id, $t_id );
$t_can_report = access_has_project_level( $t_report_bug_threshold, $t_id, $t_user_id );
}
if( $p_trace ) {
$t_full_id = join( $p_parents, ";" ) . ';' . $t_id;
} else {
$t_full_id = $t_id;
}
echo '<option value="' . $t_full_id . '"';
check_selected( $p_project_id, $t_full_id, false );
check_disabled( $t_id == $p_filter_project_id || !$t_can_report );
echo '>'
. str_repeat( ' ', count( $p_parents ) )
. str_repeat( '»', count( $p_parents ) ) . ' '
. string_attribute( project_get_field( $t_id, 'name' ) )
. '</option>' . "\n";
print_subproject_option_list( $t_id, $p_project_id, $p_filter_project_id, $p_trace, $p_can_report_only, $p_parents );
}
}
/**
* prints the profiles given the user id
* @param integer $p_user_id A user identifier.
* @param string $p_select_id ID to mark as selected by default.
* @param array $p_profiles Array of profiles.
* @return void
*/
function print_profile_option_list( $p_user_id, $p_select_id = '', array $p_profiles = null ) {
if( '' === $p_select_id ) {
$p_select_id = profile_get_default( $p_user_id );
}
if( $p_profiles != null ) {
$t_profiles = $p_profiles;
} else {
$t_profiles = profile_get_all_for_user( $p_user_id );
}
print_profile_option_list_from_profiles( $t_profiles, $p_select_id );
}
/**
* prints the profiles used in a certain project
* @param integer $p_project_id A project identifier.
* @param string $p_select_id ID to mark as selected by default.
* @param array $p_profiles Array of profiles.
* @return void
*/
function print_profile_option_list_for_project( $p_project_id, $p_select_id = '', array $p_profiles = null ) {
if( '' === $p_select_id ) {
$p_select_id = profile_get_default( auth_get_current_user_id() );
}
if( $p_profiles != null ) {
$t_profiles = $p_profiles;
} else {
$t_profiles = profile_get_all_for_project( $p_project_id );
}
print_profile_option_list_from_profiles( $t_profiles, $p_select_id );
}
/**
* print the profile option list from profiles array
*
* @param array $p_profiles Array of Operating System Profiles (ID, platform, os, os_build).
* @param integer $p_select_id ID to mark as selected by default.
* @return void
*/
function print_profile_option_list_from_profiles( array $p_profiles, $p_select_id ) {
echo '<option value="">' . lang_get( 'select_option' ) . '</option>';
foreach( $p_profiles as $t_profile ) {
extract( $t_profile, EXTR_PREFIX_ALL, 'v' );
$t_platform = string_attribute( $t_profile['platform'] );
$t_os = string_attribute( $t_profile['os'] );
$t_os_build = string_attribute( $t_profile['os_build'] );
echo '<option value="' . $t_profile['id'] . '"';
if( $p_select_id !== false ) {
check_selected( $p_select_id, (int)$t_profile['id'] );
}
echo '>' . $t_platform . ' ' . $t_os . ' ' . $t_os_build . '</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
*
* @param integer $p_category_id A category identifier.
* @param integer $p_project_id A project identifier.
* @return void
*/
function print_category_option_list( $p_category_id = 0, $p_project_id = null ) {
if( null === $p_project_id ) {
$t_project_id = helper_get_current_project();
} else {
$t_project_id = $p_project_id;
}
if( config_get( 'allow_no_category' ) ) {
echo "<option value=\"0\"", check_selected( $p_category_id, 0 ), '>';
echo category_full_name( 0, false ), '</option>';
} else {
if( 0 == $p_category_id ) {
echo "<option value=\"0\"", check_selected( $p_category_id, 0 ), '>';
echo string_attribute( lang_get( 'select_option' ) ), '</option>';
}
}
$t_cat_arr = category_get_all_rows( $t_project_id, null, true );
foreach( $t_cat_arr as $t_category_row ) {
$t_category_id = (int)$t_category_row['id'];
echo "<option value=\"$t_category_id\"";
check_selected( $p_category_id, $t_category_id );
echo '>' . string_attribute( category_full_name( $t_category_id, $t_category_row['project_id'] != $t_project_id ) ) . '</option>';
}
}
/**
* Now that categories are identified by numerical ID, we need an old-style name
* based option list to keep existing filter functionality.
* @param string $p_category_name The selected category.
* @param integer|null $p_project_id A specific project or null.
* @return void
*/
function print_category_filter_option_list( $p_category_name = '', $p_project_id = null ) {
$t_cat_arr = category_get_filter_list( $p_project_id );
natcasesort( $t_cat_arr );
foreach( $t_cat_arr as $t_cat ) {
$t_name = string_attribute( $t_cat );
echo '<option value="' . $t_name . '"';
check_selected( $p_category_name, $t_cat );
echo '>' . $t_name . '</option>';
}
}
/**
* Print the option list for platforms accessible for the specified user.
* @param string $p_platform The current platform value.
* @param integer $p_user_id A user identifier.
* @return void
*/
function print_platform_option_list( $p_platform, $p_user_id = null ) {
$t_platforms_array = profile_get_field_all_for_user( 'platform', $p_user_id );
foreach( $t_platforms_array as $t_platform_unescaped ) {
$t_platform = string_attribute( $t_platform_unescaped );
echo '<option value="' . $t_platform . '"';
check_selected( $p_platform, $t_platform_unescaped );
echo '>' . $t_platform . '</option>';
}
}
/**
* Print the option list for OSes accessible for the specified user.
* @param string $p_os The current operating system value.
* @param integer $p_user_id A user identifier.
* @return void
*/
function print_os_option_list( $p_os, $p_user_id = null ) {
$t_os_array = profile_get_field_all_for_user( 'os', $p_user_id );
foreach( $t_os_array as $t_os_unescaped ) {
$t_os = string_attribute( $t_os_unescaped );
echo '<option value="' . $t_os . '"';
check_selected( $p_os, $t_os_unescaped );
echo '>' . $t_os . '</option>';
}
}
/**
* Print the option list for os_build accessible for the specified user.
* @param string $p_os_build The current operating system build value.
* @param integer $p_user_id A user identifier.
* @return void
*/
function print_os_build_option_list( $p_os_build, $p_user_id = null ) {
$t_os_build_array = profile_get_field_all_for_user( 'os_build', $p_user_id );
foreach( $t_os_build_array as $t_os_build_unescaped ) {
$t_os_build = string_attribute( $t_os_build_unescaped );
echo '<option value="' . $t_os_build . '"';
check_selected( $p_os_build, $t_os_build_unescaped );
echo '>' . $t_os_build . '</option>';
}
}
/**
* Print the option list for versions
* @param string $p_version The currently selected version.
* @param integer $p_project_id Project id, otherwise current project will be used.
* @param integer $p_released Null to get all, 1: only released, 0: only future versions.
* @param boolean $p_leading_blank Allow selection of no version.
* @param boolean $p_with_subs Whether to include sub-projects.
* @return void
*/
function print_version_option_list( $p_version = '', $p_project_id = null, $p_released = null, $p_leading_blank = true, $p_with_subs = false ) {
if( null === $p_project_id ) {
$c_project_id = helper_get_current_project();
} else {
$c_project_id = (int)$p_project_id;
}
if( $p_with_subs ) {
$t_versions = version_get_all_rows_with_subs( $c_project_id, $p_released, null );
} else {
$t_versions = version_get_all_rows( $c_project_id, $p_released, null );
}
# Ensure the selected version (if specified) is included in the list
# Note: Filter API specifies selected versions as an array
if( !is_array( $p_version ) ) {
if( !empty( $p_version ) ) {
$t_version_id = version_get_id( $p_version, $c_project_id );
if( $t_version_id !== false ) {
$t_versions[] = version_cache_row( $t_version_id );
}
}
}
if( $p_leading_blank ) {
echo '<option value=""></option>';
}
$t_listed = array();
$t_max_length = config_get( 'max_dropdown_length' );
$t_show_version_dates = access_has_project_level( config_get( 'show_version_dates_threshold' ) );
$t_short_date_format = config_get( 'short_date_format' );
foreach( $t_versions as $t_version ) {
# If the current version is obsolete, and current version not equal to $p_version,
# then skip it.
if( ( (int)$t_version['obsolete'] ) == 1 ) {
if( $t_version['version'] != $p_version ) {
continue;
}
}
$t_version_version = string_attribute( $t_version['version'] );
if( !in_array( $t_version_version, $t_listed, true ) ) {
$t_listed[] = $t_version_version;
echo '<option value="' . $t_version_version . '"';
check_selected( $p_version, $t_version['version'] );
$t_version_string = string_attribute( prepare_version_string( $c_project_id, $t_version['id'] ) );
echo '>', string_shorten( $t_version_string, $t_max_length ), '</option>';
}
}
}
/**
* print build option list
* @param string $p_build The current build value.
* @return void
*/
function print_build_option_list( $p_build = '' ) {
$t_bug_table = db_get_table( 'bug' );
$t_overall_build_arr = array();
$t_project_id = helper_get_current_project();
$t_project_where = helper_project_specific_where( $t_project_id );
# Get the "found in" build list
$t_query = "SELECT DISTINCT build
FROM $t_bug_table
WHERE $t_project_where
ORDER BY build DESC";
$t_result = db_query_bound( $t_query );
$t_option_count = db_num_rows( $t_result );
for( $i = 0;$i < $t_option_count;$i++ ) {
$t_row = db_fetch_array( $t_result );
$t_overall_build_arr[] = $t_row['build'];
}
$t_max_length = config_get( 'max_dropdown_length' );
foreach( $t_overall_build_arr as $t_build_unescaped ) {
$t_build = string_attribute( $t_build_unescaped );
echo "<option value=\"$t_build\"";
check_selected( $p_build, $t_build_unescaped );
echo ">" . string_shorten( $t_build, $t_max_length ) . "</option>";
}
}
/**
* select the proper enumeration values based on the input parameter
* @param string $p_enum_name Name of enumeration (eg: status).
* @param integer $p_val The current value.
* @return void
*/
function print_enum_string_option_list( $p_enum_name, $p_val = 0 ) {
$t_config_var_name = $p_enum_name . '_enum_string';
$t_config_var_value = config_get( $t_config_var_name );
$t_enum_values = MantisEnum::getValues( $t_config_var_value );
foreach ( $t_enum_values as $t_key ) {
$t_elem2 = get_enum_element( $p_enum_name, $t_key );
echo '<option value="' . $t_key . '"';
check_selected( (int)$p_val, $t_key );
echo '>' . string_html_specialchars( $t_elem2 ) . '</option>';
}
}
/**
* Select the proper enumeration values for status based on workflow
* or the input parameter if workflows are not used
* @param integer $p_user_auth A user identifier.
* @param integer $p_current_value The current value.
* @param boolean $p_show_current Whether to show the current status.
* @param boolean $p_add_close Whether to add close option.
* @param integer $p_project_id A project identifier.
* @return array
*/
function get_status_option_list( $p_user_auth = 0, $p_current_value = 0, $p_show_current = true, $p_add_close = false, $p_project_id = ALL_PROJECTS ) {
$t_config_var_value = config_get( 'status_enum_string', null, null, $p_project_id );
$t_enum_workflow = config_get( 'status_enum_workflow', null, null, $p_project_id );
if( count( $t_enum_workflow ) < 1 ) {
# workflow not defined, use default enumeration
$t_enum_values = MantisEnum::getValues( $t_config_var_value );
} else {
# workflow defined - find allowed states
if( isset( $t_enum_workflow[$p_current_value] ) ) {
$t_enum_values = MantisEnum::getValues( $t_enum_workflow[$p_current_value] );
} else {
# workflow was not set for this status, this shouldn't happen
# caller should be able to handle empty list
$t_enum_values = array();
}
}
$t_enum_list = array();
foreach ( $t_enum_values as $t_enum_value ) {
if( ( $p_show_current || $p_current_value != $t_enum_value )
&& access_compare_level( $p_user_auth, access_get_status_threshold( $t_enum_value, $p_project_id ) )
) {
$t_enum_list[$t_enum_value] = get_enum_element( 'status', $t_enum_value );
}
}
if( $p_show_current ) {
$t_enum_list[$p_current_value] = get_enum_element( 'status', $p_current_value );
}
if( $p_add_close && access_compare_level( $p_current_value, config_get( 'bug_resolved_status_threshold', null, null, $p_project_id ) ) ) {
$t_closed = config_get( 'bug_closed_status_threshold', null, null, $p_project_id );
if( $p_show_current || $p_current_value != $t_closed ) {
$t_enum_list[$t_closed] = get_enum_element( 'status', $t_closed );
}
}
return $t_enum_list;
}
/**
* print the status option list for the bug_update pages
* @param string $p_select_label The id/name html attribute of the select box.
* @param integer $p_current_value The current value.
* @param boolean $p_allow_close Whether to allow close.
* @param integer $p_project_id A project identifier.
* @return void
*/
function print_status_option_list( $p_select_label, $p_current_value = 0, $p_allow_close = false, $p_project_id = ALL_PROJECTS ) {
$t_current_auth = access_get_project_level( $p_project_id );
$t_enum_list = get_status_option_list( $t_current_auth, $p_current_value, true, $p_allow_close, $p_project_id );
if( count( $t_enum_list ) > 1 ) {
# resort the list into ascending order
ksort( $t_enum_list );
reset( $t_enum_list );
echo '<select ' . helper_get_tab_index() . ' id="' . $p_select_label . '" name="' . $p_select_label . '">';
foreach( $t_enum_list as $t_key => $t_val ) {
echo '<option value="' . $t_key . '"';
check_selected( $t_key, $p_current_value );
echo '>' . string_html_specialchars( $t_val ) . '</option>';
}
echo '</select>';
} else if( count( $t_enum_list ) == 1 ) {
echo array_pop( $t_enum_list );
} else {