/
core_helper_API.php
363 lines (340 loc) · 11.1 KB
/
core_helper_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
<?
# Mantis - a php based bugtracking system
# Copyright (C) 2000, 2001 Kenzaburo Ito - kenito@300baud.org
# This program is distributed under the terms and conditions of the GPL
# See the files README and LICENSE for details
###########################################################################
# Helper API
###########################################################################
# These are miscellaneous functions to help the package
### --------------------
### Returns the specified field value of the specified bug
function get_bug_field( $p_field_name, $p_bug_id ) {
global $g_string_cookie_val,
$g_mantis_bug_table;
### get info
$query = "SELECT $p_field_name
FROM $g_mantis_bug_table
WHERE id='$p_bug_id'";
$result = db_query( $query );
return db_result( $result, 0 );
}
### --------------------
# checks to see if the category is a duplicate
# we do it this way because each different project can have the same category names
function is_duplicate_category( $p_category, $p_project_id ) {
global $g_mantis_project_category_table;
$query = "SELECT COUNT(*)
FROM $g_mantis_project_category_table
WHERE project_id='$p_project_id' AND
category='$p_category'";
$result = db_query( $query );
$category_count = db_result( $result, 0, 0 );
if ( $category_count > 0 ) {
return true;
} else {
return false;
}
}
### --------------------
# checks to see if the version is a duplicate
# we do it this way because each different project can have the same category names
function is_duplicate_version( $p_version, $p_project_id ) {
global $g_mantis_project_version_table;
$query = "SELECT COUNT(*)
FROM $g_mantis_project_version_table
WHERE project_id='$p_project_id' AND
version='$p_version'";
$result = db_query( $query );
$version_count = db_result( $result, 0, 0 );
if ( $version_count > 0 ) {
return true;
} else {
return false;
}
}
### --------------------
# converts a 1 value to X
# converts a 0 value to a space
function trans_bool( $p_num ) {
if ( $p_num==0 ) {
return " ";
} else {
return "X";
}
}
### --------------------
# check to see if bug exists
# if it doesn't exist then redirect to the main page
# otherwise let execution continue undisturbed
function check_bug_exists( $p_bug_id ) {
global $g_mantis_bug_table, $g_main_page;
$query = "SELECT *
FROM $g_mantis_bug_table
WHERE id='$p_bug_id'";
$result = db_query( $query );
if ( db_num_rows( $result )==0 ) {
print_header_redirect( $g_main_page );
}
}
### --------------------
# check to see if bugnote exists
# if it doesn't exist then redirect to the main page
# otherwise let execution continue undisturbed
function check_bugnote_exists( $p_bugnote_id ) {
global $g_mantis_bugnote_table, $g_main_page;
$query = "SELECT *
FROM $g_mantis_bugnote_table
WHERE id='$p_bugnote_id'";
$result = db_query( $query );
if ( db_num_rows( $result )==0 ) {
print_header_redirect( $g_main_page );
}
}
### --------------------
# check to see if user exists
# if it doesn't exist then redirect to the main page
# otherwise let execution continue undisturbed
function check_user_exists( $p_user_id ) {
global $g_mantis_user_table, $g_main_page;
$query = "SELECT *
FROM $g_mantis_user_table
WHERE id='$p_user_id'";
$result = db_query( $query );
if ( db_num_rows( $result )==0 ) {
print_header_redirect( $g_main_page );
}
}
### --------------------
# check to see if project exists by id
# if it doesn't exist then redirect to the main page
# otherwise let execution continue undisturbed
function check_project_exists( $p_project_id ) {
global $g_mantis_project_table, $g_main_page;
$query = "SELECT COUNT(*)
FROM $g_mantis_project_table
WHERE id='$p_project_id'";
$result = db_query( $query );
if ( db_result( $result, 0, 0 )==0 ) {
print_header_redirect( $g_main_page );
}
}
### --------------------
# check to see if project exists by name
# if it doesn't exist then redirect to the main page
# otherwise let execution continue undisturbed
function is_duplicate_project( $p_name ) {
global $g_mantis_project_table;
$query = "SELECT COUNT(*)
FROM $g_mantis_project_table
WHERE name='$p_name'";
$result = db_query( $query );
if ( db_result( $result, 0, 0 )==0 ) {
return false;
} else {
return true;
}
}
### --------------------
# retrieve the number of open assigned bugs to a user in a project
function get_assigned_open_bug_count( $p_project_id, $p_cookie_str ) {
global $g_mantis_bug_table, $g_mantis_user_table;
$query = "SELECT id
FROM $g_mantis_user_table
WHERE cookie_string='$p_cookie_str'";
$result = db_query( $query );
$t_id = db_result( $result );
$t_res = RESOLVED;
$t_clo = CLOSED;
$query = "SELECT COUNT(*)
FROM $g_mantis_bug_table
WHERE project_id='$p_project_id' AND
status<>'$t_res' AND status<>'$t_clo' AND
handler_id='$t_id'";
$result = db_query( $query );
return db_result( $result, 0, 0 );
}
### --------------------
# retrieve the number of open reported bugs by a user in a project
function get_reported_open_bug_count( $p_project_id, $p_cookie_str ) {
global $g_mantis_bug_table, $g_mantis_user_table;
$query = "SELECT id
FROM $g_mantis_user_table
WHERE cookie_string='$p_cookie_str'";
$result = db_query( $query );
$t_id = db_result( $result );
$t_res = RESOLVED;
$t_clo = CLOSED;
$query = "SELECT COUNT(*)
FROM $g_mantis_bug_table
WHERE project_id='$p_project_id' AND
status<>'$t_res' AND status<>'$t_clo' AND
reporter_id='$t_id'";
$result = db_query( $query );
return db_result( $result, 0, 0 );
}
### --------------------
# process the $p_string and convert bugs in this format #123 to a html link
function process_bug_link( $p_string ) {
global $g_view_bug_page, $g_view_bug_advanced_page;
if ( get_current_user_pref_field( "advanced_view" )==1 ) {
return preg_replace("/#([0-9]+)/",
"<a href=\"$g_view_bug_advanced_page?f_id=\\1\">#\\1</a>",
$p_string);
} else {
return preg_replace("/#([0-9]+)/",
"<a href=\"$g_view_bug_page?f_id=\\1\">#\\1</a>",
$p_string);
}
}
### --------------------
# process the $p_string and convert bugs in this format #123 to a plain text link
function process_bug_link_email( $p_string ) {
global $g_view_bug_page, $g_view_bug_advanced_page;
if ( get_current_user_pref_field( "advanced_view" )==1 ) {
return preg_replace("/#([0-9]+)/",
"http://$g_view_bug_advanced_page?f_id=\\1",
$p_string);
} else {
return preg_replace("/#([0-9]+)/",
"http://$g_view_bug_page?f_id=\\1",
$p_string);
}
}
### --------------------
# alternate color function
function alternate_colors( $p_num, $p_color1, $p_color2 ) {
if ( $p_num % 2 == 1) {
return $p_color1;
} else {
return $p_color2;
}
}
### --------------------
# Get the default project of a user
function get_default_project( $p_user_id ) {
global $g_mantis_user_pref_table;
$query = "SELECT default_project
FROM $g_mantis_user_pref_table
WHERE user_id='$p_user_id'";
$result = db_query( $query );
return db_result( $result, 0, 0 );
}
### --------------------
# Get the string associated with the $p_enum value
function get_enum_to_string( $p_enum_string, $p_num ) {
$t_arr = explode( ",", $p_enum_string );
$enum_count = count( $t_arr );
for ($i=0;$i<$enum_count;$i++) {
$t_s = explode( ":", $t_arr[$i] );
if ( $t_s[0] == $p_num ) {
return $t_s[1];
}
}
return "";
}
### --------------------
# Breaks up an enum string into num:value elements
function explode_enum_string( $p_enum_string ) {
return explode( ",", $p_enum_string );
}
### --------------------
# Given one num:value pair it will return both in an array
# num will be first (element 0) value second (element 1)
function explode_enum_arr( $p_enum_elem ) {
return explode( ":", $p_enum_elem );
}
### --------------------
# Given a enum string and num, return the appriate string @@@ localize for display
function get_enum_element( $p_enum_string, $p_val ) {
$arr = explode_enum_string( $p_enum_string );
for ( $i=0;$i<count( $arr );$i++ ) {
$elem_arr = explode_enum_arr( $arr[$i] );
if ( $elem_arr[0]==$p_val ) {
return $elem_arr[1];
}
}
return "@null@";
}
### --------------------
### Returns the number of bugntoes for the given bug_id
function get_bugnote_count( $p_id ) {
global $g_mantis_bugnote_table;
$query = "SELECT COUNT(*)
FROM $g_mantis_bugnote_table
WHERE bug_id ='$p_id'";
$result = db_query( $query );
return db_result( $result, 0 );
}
### --------------------
# Returns the name of the project
function get_project_name( $p_project_id ) {
global $g_mantis_project_table;
$query = "SELECT name
FROM $g_mantis_project_table
WHERE id='$p_project_id'";
$result = db_query( $query );
return db_result( $result, 0, 0 );
}
# --------------------
# Some proxies strip out HTTP_REFERER.
# This function helps determine which pages to redirect to
# based on site and user preference.
function get_view_redirect_url( $p_bug_id ) {
global $HTTP_REFERER, $g_show_view, $g_view_bug_page, $g_view_bug_advanced_page;
if ( ( !isset( $HTTP_REFERER ) ) || ( empty( $HTTP_REFERER )) ) {
switch ( $g_show_view ) {
case 0: if ( 1 == get_current_user_pref_field( "advanced_view" ) ) {
return $g_view_bug_page."?f_id=".$p_bug_id;
} else {
return $g_view_bug_advanced_page."?f_id=".$p_bug_id;
}
case 1: return $g_view_bug_page."?f_id=".$p_bug_id;
case 2: return $g_view_bug_advanced_page."?f_id=".$p_bug_id;
default:return $g_view_bug_page."?f_id=".$p_bug_id;
}
} else {
return $HTTP_REFERER;
}
}
# --------------------
# Some proxies strip out HTTP_REFERER.
# This function helps determine which pages to redirect to
# based on site and user preference.
function get_update_redirect_url( $p_bug_id ) {
global $g_show_view, $g_view_bug_page, $g_view_bug_advanced_page;
switch ( $g_show_view ) {
case 0: if ( 1 == get_current_user_pref_field( "advanced_view" ) ) {
return $g_view_bug_page."?f_id=".$p_bug_id;
} else {
return $g_view_bug_advanced_page."?f_id=".$p_bug_id;
}
case 1: return $g_view_bug_page."?f_id=".$p_bug_id;
case 2: return $g_view_bug_advanced_page."?f_id=".$p_bug_id;
default:return $g_view_bug_page."?f_id=".$p_bug_id;
}
}
# --------------------
# Some proxies strip out HTTP_REFERER.
# This function helps determine which pages to redirect to
# based on site and user preference.
function get_report_redirect_url() {
global $HTTP_REFERER, $g_show_report, $g_report_bug_page, $g_report_bug_advanced_page;
if ( ( !isset( $HTTP_REFERER ) ) || ( empty( $HTTP_REFERER )) ) {
switch( $g_show_report ) {
case 0: if ( 1 == get_current_user_pref_field( "advanced_report" ) ) {
return $g_report_bug_advanced_page;
} else {
return $g_report_bug_page;
}
case 1: return $g_report_bug_page;
case 2: return $g_report_bug_advanced_page;
default:return $g_report_bug_page;
}
} else {
return $HTTP_REFERER;
}
}
# --------------------
# END
?>