/
cfdef_standard.php
434 lines (394 loc) · 15.6 KB
/
cfdef_standard.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
<?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/>.
*
* @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
* @package MantisBT
*/
$g_custom_field_type_definition[CUSTOM_FIELD_TYPE_STRING] = array (
'#display_possible_values' => true,
'#display_valid_regexp' => true,
'#display_length_min' => true,
'#display_length_max' => true,
'#display_default_value' => true,
'#function_return_distinct_values' => null,
'#function_value_to_database' => null,
'#function_database_to_value' => null,
'#function_print_input' => 'cfdef_input_textbox',
'#function_string_value' => null,
'#function_string_value_for_email' => null,
);
$g_custom_field_type_definition[CUSTOM_FIELD_TYPE_TEXTAREA] = array (
'#display_possible_values' => true,
'#display_valid_regexp' => true,
'#display_length_min' => true,
'#display_length_max' => true,
'#display_default_value' => true,
'#function_return_distinct_values' => null,
'#function_value_to_database' => null,
'#function_database_to_value' => null,
'#function_print_input' => 'cfdef_input_textarea',
'#function_string_value' => null,
'#function_string_value_for_email' => null,
);
$g_custom_field_type_definition[CUSTOM_FIELD_TYPE_NUMERIC] = array (
'#display_possible_values' => true,
'#display_valid_regexp' => true,
'#display_length_min' => true,
'#display_length_max' => true,
'#display_default_value' => true,
'#function_return_distinct_values' => null,
'#function_value_to_database' => null,
'#function_database_to_value' => null,
'#function_print_input' => 'cfdef_input_textbox',
'#function_string_value' => null,
'#function_string_value_for_email' => null,
);
$g_custom_field_type_definition[CUSTOM_FIELD_TYPE_FLOAT] = array (
'#display_possible_values' => true,
'#display_valid_regexp' => true,
'#display_length_min' => true,
'#display_length_max' => true,
'#display_default_value' => true,
'#function_return_distinct_values' => null,
'#function_value_to_database' => null,
'#function_database_to_value' => null,
'#function_print_input' => 'cfdef_input_textbox',
'#function_string_value' => null,
'#function_string_value_for_email' => null,
);
$g_custom_field_type_definition[CUSTOM_FIELD_TYPE_ENUM] = array (
'#display_possible_values' => true,
'#display_valid_regexp' => true,
'#display_length_min' => true,
'#display_length_max' => true,
'#display_default_value' => true,
'#function_return_distinct_values' => 'cfdef_prepare_list_distinct_values',
'#function_value_to_database' => null,
'#function_database_to_value' => null,
'#function_print_input' => 'cfdef_input_list',
'#function_string_value' => 'cfdef_prepare_list_value',
'#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email',
);
$g_custom_field_type_definition[CUSTOM_FIELD_TYPE_EMAIL] = array (
'#display_possible_values' => true,
'#display_valid_regexp' => true,
'#display_length_min' => true,
'#display_length_max' => true,
'#display_default_value' => true,
'#function_return_distinct_values' => null,
'#function_value_to_database' => null,
'#function_database_to_value' => null,
'#function_print_input' => 'cfdef_input_textbox',
'#function_string_value' => 'cfdef_prepare_email_value',
'#function_string_value_for_email' => 'cfdef_prepare_email_value_for_email',
);
$g_custom_field_type_definition[CUSTOM_FIELD_TYPE_CHECKBOX] = array (
'#display_possible_values' => true,
'#display_valid_regexp' => true,
'#display_length_min' => true,
'#display_length_max' => true,
'#display_default_value' => true,
'#function_return_distinct_values' => 'cfdef_prepare_list_distinct_values',
'#function_value_to_database' => 'cfdef_prepare_list_value_to_database',
'#function_database_to_value' => 'cfdef_prepare_list_database_to_value',
'#function_print_input' => 'cfdef_input_checkbox',
'#function_string_value' => 'cfdef_prepare_list_value',
'#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email',
);
$g_custom_field_type_definition[CUSTOM_FIELD_TYPE_RADIO] = array (
'#display_possible_values' => true,
'#display_valid_regexp' => false,
'#display_length_min' => false,
'#display_length_max' => false,
'#display_default_value' => true,
'#function_return_distinct_values' => 'cfdef_prepare_list_distinct_values',
'#function_value_to_database' => null,
'#function_database_to_value' => null,
'#function_print_input' => 'cfdef_input_radio',
'#function_string_value' => 'cfdef_prepare_list_value',
'#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email',
);
$g_custom_field_type_definition[CUSTOM_FIELD_TYPE_LIST] = array (
'#display_possible_values' => true,
'#display_valid_regexp' => true,
'#display_length_min' => true,
'#display_length_max' => true,
'#display_default_value' => true,
'#function_return_distinct_values' => 'cfdef_prepare_list_distinct_values',
'#function_value_to_database' => null,
'#function_database_to_value' => null,
'#function_print_input' => 'cfdef_input_list',
'#function_string_value' => 'cfdef_prepare_list_value',
'#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email',
);
$g_custom_field_type_definition[CUSTOM_FIELD_TYPE_MULTILIST] = array (
'#display_possible_values' => true,
'#display_valid_regexp' => true,
'#display_length_min' => true,
'#display_length_max' => true,
'#display_default_value' => true,
'#function_return_distinct_values' => 'cfdef_prepare_list_distinct_values',
'#function_value_to_database' => 'cfdef_prepare_list_value_to_database',
'#function_database_to_value' => 'cfdef_prepare_list_database_to_value',
'#function_print_input' => 'cfdef_input_list',
'#function_string_value' => 'cfdef_prepare_list_value',
'#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email',
);
$g_custom_field_type_definition[CUSTOM_FIELD_TYPE_DATE] = array (
'#display_possible_values' => true,
'#display_valid_regexp' => true,
'#display_length_min' => true,
'#display_length_max' => true,
'#display_default_value' => true,
'#function_return_distinct_values' => null,
'#function_value_to_database' => null,
'#function_database_to_value' => null,
'#function_default_to_value' => 'cfdef_prepare_date_default',
'#function_print_input' => 'cfdef_input_date',
'#function_string_value' => 'cfdef_prepare_date_value',
'#function_string_value_for_email' => 'cfdef_prepare_date_value_for_email',
);
/**
* Prepare List Value for database storage
* @param string $p_value Value.
* @return string
*/
function cfdef_prepare_list_database_to_value( $p_value ) {
return rtrim( ltrim( $p_value, '|' ), '|' );
}
/**
* Prepare List Value for email
* @param string $p_value Value.
* @return string
*/
function cfdef_prepare_list_value_for_email( $p_value ) {
# strip start and end markers before converting markers to commas
return str_replace( '|', ', ', utf8_substr( str_replace( '||', '|', '|' . $p_value . '|' ), 1, -1 ) );
}
/**
* Format email address for email
* @param string $p_value Value.
* @return string
*/
function cfdef_prepare_email_value_for_email( $p_value ) {
return 'mailto:' . $p_value;
}
/**
* format date value for email
* @param integer $p_value Value.
* @return string
*/
function cfdef_prepare_date_value_for_email( $p_value ) {
if( $p_value != null ) {
return date( config_get( 'short_date_format' ), $p_value ) ;
}
}
/**
* Translates the default date value entered by the creator of the custom
* field into a date value. For example, translate '=tomorrow' to tomorrow's
* date.
* @param string $p_value The default date string.
* @return string The calculated default date value if $p_value starts with '=', otherwise, returns $p_value.
*/
function cfdef_prepare_date_default( $p_value ) {
if( is_blank( $p_value ) ) {
return '';
}
$t_value = trim( $p_value );
$t_value_length = utf8_strlen( $t_value );
# We are expanding {tomorrow}, {yesterday}, {+3 days}, {-7 days}, {next week}
# See strtotime() for more details about supported formats.
if( $t_value_length >= 3 && $t_value[0] == '{' && $t_value[$t_value_length - 1] == '}' ) {
$t_value = utf8_substr( $t_value, 1, $t_value_length - 2 );
$t_value = @strtotime( $t_value );
# Different versions of PHP return different values in case of error.
if( $t_value == -1 || $t_value === false ) {
return '';
}
}
return $t_value;
}
/**
* string_custom_field_value
* @param string $p_value Value.
* @return string
*/
function cfdef_prepare_list_value( $p_value ) {
# strip start and end markers before converting markers to commas
return string_display_line( str_replace( '|', ', ', utf8_substr( str_replace( '||', '|', '|' . $p_value . '|' ), 1, -1 ) ) );
}
/**
* Prepare email value
* @param string $p_value Email address.
* @return string
*/
function cfdef_prepare_email_value( $p_value ) {
return '<a href="mailto:' . string_attribute( $p_value ) . '">' . string_display_line( $p_value ) . '</a>';
}
/**
* Prepare date value
* @param integer $p_value Date timestamp.
* @return string
*/
function cfdef_prepare_date_value( $p_value ) {
if( $p_value != null ) {
return date( config_get( 'short_date_format' ), $p_value );
}
}
/**
* print_custom_field_input
* @param array $p_field_def Custom field definition.
* @param mixed $p_custom_field_value Custom field value.
* @return void
*/
function cfdef_input_list( array $p_field_def, $p_custom_field_value ) {
$t_values = explode( '|', custom_field_prepare_possible_values( $p_field_def['possible_values'] ) );
$t_list_size = $t_possible_values_count = count( $t_values );
if( $t_possible_values_count > 5 ) {
$t_list_size = 5;
}
if( $p_field_def['type'] == CUSTOM_FIELD_TYPE_ENUM ) {
$t_list_size = 0; # for enums the size is 0
}
if( $p_field_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST ) {
echo '<select ' . helper_get_tab_index() . ' id="custom_field_' . $p_field_def['id'] . '" name="custom_field_' . $p_field_def['id'] . '[]" size="' . $t_list_size . '" multiple="multiple">';
} else {
echo '<select ' . helper_get_tab_index() . ' id="custom_field_' . $p_field_def['id'] . '" name="custom_field_' . $p_field_def['id'] . '" size="' . $t_list_size . '">';
}
$t_selected_values = explode( '|', $p_custom_field_value );
foreach( $t_values as $t_option ) {
if( in_array( $t_option, $t_selected_values, true ) ) {
echo '<option value="' . string_attribute( $t_option ) . '" selected="selected"> ' . string_display_line( $t_option ) . '</option>';
} else {
echo '<option value="' . string_attribute( $t_option ) . '">' . string_display_line( $t_option ) . '</option>';
}
}
echo '</select>';
}
/**
* print_custom_field_input
* @param array $p_field_def Custom field definition.
* @param mixed $p_custom_field_value Custom field value.
* @return void
*/
function cfdef_input_checkbox( array $p_field_def, $p_custom_field_value ) {
$t_values = explode( '|', custom_field_prepare_possible_values( $p_field_def['possible_values'] ) );
$t_checked_values = explode( '|', $p_custom_field_value );
for( $i = 0; $i < count( $t_values ); $i++ ) {
$t_input_id = 'custom_field_' . $p_field_def['id'] . '_value_' . $i;
$t_input_name = 'custom_field_' . $p_field_def['id'] . '[]';
echo '<label for="' . $t_input_id . '">' . "\n";
echo '<input class="ace" id="' . $t_input_id . '" ' . helper_get_tab_index() . ' type="checkbox" name="' . $t_input_name . '" value="' . string_attribute( $t_values[$i] ) . '"';
check_checked( $t_checked_values, $t_values[$i] );
echo " />\n";
echo '<span class="lbl"> ' . string_display_line( $t_values[$i] ) . '</label>' . "\n";
echo '</label>    ' . "\n";
}
}
/**
* print_custom_field_input
* @param array $p_field_def Custom field definition.
* @param mixed $p_custom_field_value Custom field value.
* @return void
*/
function cfdef_input_radio( array $p_field_def, $p_custom_field_value ) {
$t_values = explode( '|', custom_field_prepare_possible_values( $p_field_def['possible_values'] ) );
$t_len = strlen( $p_custom_field_value );
if( $t_len >= 2 && ( $p_custom_field_value[0] == '|' ) && ( $p_custom_field_value[$t_len-1] == '|' ) ) {
$t_checked_value = substr( $p_custom_field_value, 1, $t_len - 2 );
} else {
$t_checked_value = $p_custom_field_value;
}
for( $i = 0; $i < count( $t_values ); $i++ ) {
$t_input_id = 'custom_field_' . $p_field_def['id'] . '_value_' . $i;
$t_input_name = 'custom_field_' . $p_field_def['id'];
echo '<label for="' . $t_input_id . '">';
echo '<input class="ace" id="' . $t_input_id . '" ' . helper_get_tab_index() . ' type="radio" name="' . $t_input_name . '" value="' . string_attribute( $t_values[$i] ) . '"';
check_checked( $t_checked_value, $t_values[$i] );
echo " />\n";
echo '<span class="lbl"> ' . string_display_line( $t_values[$i] ) . '</span>' . "\n";
echo '</label>    ' . "\n";
}
}
/**
* print_custom_field_input
* @param array $p_field_def Custom field definition.
* @param mixed $p_custom_field_value Custom field value.
* @return void
*/
function cfdef_input_textbox( array $p_field_def, $p_custom_field_value ) {
echo '<input ' . helper_get_tab_index() . ' type="text" id="custom_field_' . $p_field_def['id'] . '" name="custom_field_' . $p_field_def['id'] . '" size="80"';
if( 0 < $p_field_def['length_max'] ) {
echo ' maxlength="' . $p_field_def['length_max'] . '"';
} else {
echo ' maxlength="255"';
}
echo ' value="' . string_attribute( $p_custom_field_value ) .'"></input>';
}
/**
* print_custom_field_input
* @param array $p_field_def Custom field definition.
* @param mixed $p_custom_field_value Custom field value.
* @return void
*/
function cfdef_input_textarea( array $p_field_def, $p_custom_field_value ) {
echo '<textarea class="form-control" ' . helper_get_tab_index() . ' id="custom_field_' . $p_field_def['id'] . '" name="custom_field_' . $p_field_def['id'] . '"';
echo ' cols="70" rows="8">' . $p_custom_field_value .'</textarea>';
}
/**
* Prints the controls for the date selector.
*
* @param string $p_field_def The custom field definition.
* @param string $p_custom_field_value The custom field value to print.
* @return void
*/
function cfdef_input_date( $p_field_def, $p_custom_field_value ) {
print_date_selection_set( 'custom_field_' . $p_field_def['id'], config_get( 'short_date_format' ), $p_custom_field_value, false, true );
}
/**
* value to database
* @param string $p_value Value.
* @return string
*/
function cfdef_prepare_list_value_to_database( $p_value ) {
if( '' == $p_value ) {
return '';
} else {
return '|' . $p_value . '|';
}
}
/**
* Prepare possible values for option list
* @param array $p_field_def Custom field definition.
* @return array|boolean
*/
function cfdef_prepare_list_distinct_values( array $p_field_def ) {
$t_query = 'SELECT possible_values FROM {custom_field} WHERE id=' . db_param();
$t_result = db_query( $t_query, array( $p_field_def['id'] ) );
$t_row = db_fetch_array( $t_result );
if( !$t_row ) {
return false;
}
$t_possible_values = custom_field_prepare_possible_values( $t_row['possible_values'] );
$t_values_arr = explode( '|', $t_possible_values );
$t_return_arr = array();
foreach( $t_values_arr as $t_option ) {
array_push( $t_return_arr, $t_option );
}
return $t_return_arr;
}