6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
20 * Custom Profile Fields
25 public static $profile_types = array(FIELD_INT
=> 'int', FIELD_STRING
=> 'string', FIELD_TEXT
=> 'text', FIELD_BOOL
=> 'bool', FIELD_DROPDOWN
=> 'dropdown', FIELD_DATE
=> 'date');
26 private $profile_cache = array();
27 private $options_lang = array();
30 * Assign editable fields to template, mode can be profile (for profile change) or register (for registration)
31 * Called by ucp_profile and ucp_register
34 public function generate_profile_fields($mode, $lang_id)
36 global $db, $template, $auth;
42 // If the field is required we show it on the registration page and do not show hidden fields
43 $sql_where .= ' AND (f.field_show_on_reg = 1 OR f.field_required = 1) AND f.field_hide = 0';
47 // Show hidden fields to moderators/admins
48 if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
50 $sql_where .= ' AND f.field_hide = 0';
55 trigger_error('Wrong profile mode specified', E_USER_ERROR
);
59 $sql = 'SELECT l.*, f.*
60 FROM ' . PROFILE_LANG_TABLE
. ' l, ' . PROFILE_FIELDS_TABLE
. " f
61 WHERE f.field_active = 1
63 AND l.lang_id = $lang_id
64 AND l.field_id = f.field_id
65 ORDER BY f.field_order";
66 $result = $db->sql_query($sql);
68 while ($row = $db->sql_fetchrow($result))
70 // Return templated field
71 $tpl_snippet = $this->process_field_row('change', $row);
73 // Some types are multivalue, we can't give them a field_id as we would not know which to pick
74 $type = (int) $row['field_type'];
76 $template->assign_block_vars('profile_fields', array(
77 'LANG_NAME' => $row['lang_name'],
78 'LANG_EXPLAIN' => $row['lang_explain'],
79 'FIELD' => $tpl_snippet,
80 'FIELD_ID' => ($type == FIELD_DATE ||
($type == FIELD_BOOL
&& $row['field_length'] == '1')) ?
'' : 'pf_' . $row['field_ident'],
81 'S_REQUIRED' => ($row['field_required']) ?
true : false)
84 $db->sql_freeresult($result);
88 * Validate entered profile field data
91 public function validate_profile_field($field_type, &$field_value, $field_data)
97 $field_value = (int) $field_value;
101 $field_value = (bool) $field_value;
108 $field_validate = explode('-', $field_value);
110 $day = (isset($field_validate[0])) ?
(int) $field_validate[0] : 0;
111 $month = (isset($field_validate[1])) ?
(int) $field_validate[1] : 0;
112 $year = (isset($field_validate[2])) ?
(int) $field_validate[2] : 0;
114 if ((!$day ||
!$month ||
!$year) && !$field_data['field_required'])
119 if ((!$day ||
!$month ||
!$year) && $field_data['field_required'])
121 return 'FIELD_REQUIRED';
124 if ($day < 0 ||
$day > 31 ||
$month < 0 ||
$month > 12 ||
($year < 1901 && $year > 0) ||
$year > gmdate('Y', time()) +
50)
126 return 'FIELD_INVALID_DATE';
129 if (checkdate($month, $day, $year) === false)
131 return 'FIELD_INVALID_DATE';
136 if (!$field_value && $field_data['field_required'])
138 return 'FIELD_REQUIRED';
143 if (empty($field_value) && !$field_data['field_required'])
148 if ($field_value < $field_data['field_minlen'])
150 return 'FIELD_TOO_SMALL';
152 else if ($field_value > $field_data['field_maxlen'])
154 return 'FIELD_TOO_LARGE';
159 if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
161 return 'FIELD_REQUIRED';
167 if (empty($field_value) && !$field_data['field_required'])
171 else if (empty($field_value) && $field_data['field_required'])
173 return 'FIELD_REQUIRED';
176 if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen'])
178 return 'FIELD_TOO_SHORT';
180 else if ($field_data['field_maxlen'] && utf8_strlen($field_value) > $field_data['field_maxlen'])
182 return 'FIELD_TOO_LONG';
185 if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*')
187 $field_validate = ($field_type == FIELD_STRING
) ?
$field_value : bbcode_nl2br($field_value);
188 if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate))
190 return 'FIELD_INVALID_CHARS';
200 * Build profile cache, used for display
203 private function build_cache()
205 global $db, $user, $auth;
207 $this->profile_cache
= array();
209 // Display hidden/no_view fields for admin/moderator
210 $sql = 'SELECT l.*, f.*
211 FROM ' . PROFILE_LANG_TABLE
. ' l, ' . PROFILE_FIELDS_TABLE
. ' f
212 WHERE l.lang_id = ' . $user->get_iso_lang_id() . '
213 AND f.field_active = 1 ' .
214 ((!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) ?
' AND f.field_hide = 0 ' : '') . '
215 AND f.field_no_view = 0
216 AND l.field_id = f.field_id
217 ORDER BY f.field_order';
218 $result = $db->sql_query($sql);
220 while ($row = $db->sql_fetchrow($result))
222 $this->profile_cache
[$row['field_ident']] = $row;
224 $db->sql_freeresult($result);
228 * Get language entries for options and store them here for later use
230 private function get_option_lang($field_id, $lang_id, $field_type, $preview)
236 $lang_options = (!is_array($this->vars
['lang_options'])) ?
explode("\n", $this->vars
['lang_options']) : $this->vars
['lang_options'];
238 // @todo: ref optimize
239 foreach ($lang_options as $num => $var)
241 $this->options_lang
[$field_id][$lang_id][($num +
1)] = $var;
246 $sql = 'SELECT option_id, lang_value
247 FROM ' . PROFILE_FIELDS_LANG_TABLE
. "
248 WHERE field_id = $field_id
249 AND lang_id = $lang_id
250 AND field_type = $field_type
252 $result = $db->sql_query($sql);
254 // @todo: ref optimize
255 while ($row = $db->sql_fetchrow($result))
257 $this->options_lang
[$field_id][$lang_id][($row['option_id'] +
1)] = $row['lang_value'];
259 $db->sql_freeresult($result);
264 * Submit profile field
267 public function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error)
269 global $auth, $db, $user;
275 // If the field is required we show it on the registration page and do not show hidden fields
276 $sql_where .= ' AND (f.field_show_on_reg = 1 OR f.field_required = 1) AND f.field_hide = 0';
280 // Show hidden fields to moderators/admins
281 if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
283 $sql_where .= ' AND f.field_hide = 0';
288 trigger_error('Wrong profile mode specified', E_USER_ERROR
);
292 $sql = 'SELECT l.*, f.*
293 FROM ' . PROFILE_LANG_TABLE
. ' l, ' . PROFILE_FIELDS_TABLE
. " f
294 WHERE l.lang_id = $lang_id
295 AND f.field_active = 1
297 AND l.field_id = f.field_id
298 ORDER BY f.field_order";
299 $result = $db->sql_query($sql);
301 while ($row = $db->sql_fetchrow($result))
303 $cp_data['pf_' . $row['field_ident']] = $this->get_profile_field($row);
304 $check_value = $cp_data['pf_' . $row['field_ident']];
306 if (($cp_result = $this->validate_profile_field($row['field_type'], $check_value, $row)) !== false)
308 // If not and only showing common error messages, use this one
312 case 'FIELD_INVALID_DATE':
313 case 'FIELD_REQUIRED':
314 $error = sprintf($user->lang
[$cp_result], $row['lang_name']);
317 case 'FIELD_TOO_SHORT':
318 case 'FIELD_TOO_SMALL':
319 $error = sprintf($user->lang
[$cp_result], $row['lang_name'], $row['field_minlen']);
322 case 'FIELD_TOO_LONG':
323 case 'FIELD_TOO_LARGE':
324 $error = sprintf($user->lang
[$cp_result], $row['lang_name'], $row['field_maxlen']);
327 case 'FIELD_INVALID_CHARS':
328 switch ($row['field_validation'])
331 $error = sprintf($user->lang
[$cp_result . '_NUMBERS_ONLY'], $row['lang_name']);
335 $error = sprintf($user->lang
[$cp_result . '_ALPHA_ONLY'], $row['lang_name']);
338 case '[\w_\+\. \-\[\]]+':
339 $error = sprintf($user->lang
[$cp_result . '_SPACERS_ONLY'], $row['lang_name']);
347 $cp_error[] = $error;
351 $db->sql_freeresult($result);
355 * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled)
356 * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template
359 public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false)
365 if (!is_array($user_id))
367 $user_id = array($user_id);
370 if (!sizeof($this->profile_cache
))
372 $this->build_cache();
375 if (!sizeof($user_id))
381 FROM ' . PROFILE_FIELDS_DATA_TABLE
. '
382 WHERE ' . $db->sql_in_set('user_id', array_map('intval', $user_id));
383 $result = $db->sql_query($sql);
385 $field_data = array();
386 while ($row = $db->sql_fetchrow($result))
388 $field_data[$row['user_id']] = $row;
390 $db->sql_freeresult($result);
392 $user_fields = array();
394 // Go through the fields in correct order
395 foreach (array_keys($this->profile_cache
) as $used_ident)
397 foreach ($field_data as $user_id => $row)
399 $user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
400 $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache
[$used_ident];
406 else if ($mode == 'show')
408 // $profile_row == $user_fields[$row['user_id']];
409 $tpl_fields = array();
410 $tpl_fields['row'] = $tpl_fields['blockrow'] = array();
412 foreach ($profile_row as $ident => $ident_ary)
414 $value = $this->get_profile_value($ident_ary);
421 $tpl_fields['row'] +
= array(
422 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value,
423 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'],
424 'PROFILE_' . strtoupper($ident) . '_NAME' => $ident_ary['data']['lang_name'],
425 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $ident_ary['data']['lang_explain'],
427 'S_PROFILE_' . strtoupper($ident) => true
430 $tpl_fields['blockrow'][] = array(
431 'PROFILE_FIELD_VALUE' => $value,
432 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'],
433 'PROFILE_FIELD_NAME' => $ident_ary['data']['lang_name'],
434 'PROFILE_FIELD_EXPLAIN' => $ident_ary['data']['lang_explain'],
436 'S_PROFILE_' . strtoupper($ident) => true
444 trigger_error('Wrong mode for custom profile', E_USER_ERROR
);
449 * Get Profile Value for display
451 private function get_profile_value($ident_ary)
453 $value = $ident_ary['value'];
454 $field_type = $ident_ary['data']['field_type'];
456 switch (self
::$profile_types[$field_type])
473 $value = make_clickable($value);
474 $value = censor_text($value);
475 $value = bbcode_nl2br($value);
481 $date = explode('-', $value);
482 $day = (isset($date[0])) ?
(int) $date[0] : 0;
483 $month = (isset($date[1])) ?
(int) $date[1] : 0;
484 $year = (isset($date[2])) ?
(int) $date[2] : 0;
486 if (!$day && !$month && !$year)
490 else if ($day && $month && $year)
493 // d/m/y 00:00 GMT isn't necessarily on the same d/m/y in the user's timezone, so add the timezone seconds
494 return $user->format_date(gmmktime(0, 0, 0, $month, $day, $year) +
$user->timezone +
$user->dst
, $user->lang
['DATE_FORMAT'], true);
501 $field_id = $ident_ary['data']['field_id'];
502 $lang_id = $ident_ary['data']['lang_id'];
503 if (!isset($this->options_lang
[$field_id][$lang_id]))
505 $this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN
, false);
508 if ($value == $ident_ary['data']['field_novalue'])
513 $value = (int) $value;
515 // User not having a value assigned
516 if (!isset($this->options_lang
[$field_id][$lang_id][$value]))
521 return $this->options_lang
[$field_id][$lang_id][$value];
525 $field_id = $ident_ary['data']['field_id'];
526 $lang_id = $ident_ary['data']['lang_id'];
527 if (!isset($this->options_lang
[$field_id][$lang_id]))
529 $this->get_option_lang($field_id, $lang_id, FIELD_BOOL
, false);
532 if ($ident_ary['data']['field_length'] == 1)
534 return (isset($this->options_lang
[$field_id][$lang_id][(int) $value])) ?
$this->options_lang
[$field_id][$lang_id][(int) $value] : NULL;
542 return $this->options_lang
[$field_id][$lang_id][(int) ($value) +
1];
547 trigger_error('Unknown profile type', E_USER_ERROR
);
553 * Get field value for registration/profile
556 private function get_var($field_validation, &$profile_row, $default_value, $preview)
560 $profile_row['field_ident'] = (isset($profile_row['var_name'])) ?
$profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
561 $user_ident = $profile_row['field_ident'];
562 // checkbox - only testing for isset
563 if ($profile_row['field_type'] == FIELD_BOOL
&& $profile_row['field_length'] == 2)
565 $value = (phpbb_request
::is_set($profile_row['field_ident'])) ?
true : ((!isset($user->profile_fields
[$user_ident]) ||
$preview) ?
$default_value : $user->profile_fields
[$user_ident]);
567 else if ($profile_row['field_type'] == FIELD_INT
)
569 if (phpbb_request
::is_set($profile_row['field_ident']))
571 $value = (request_var($profile_row['field_ident'], '') === '') ?
null : request_var($profile_row['field_ident'], $default_value);
575 if (!$preview && isset($user->profile_fields
[$user_ident]) && is_null($user->profile_fields
[$user_ident]))
579 else if (!isset($user->profile_fields
[$user_ident]) ||
$preview)
581 $value = $default_value;
585 $value = $user->profile_fields
[$user_ident];
589 return (is_null($value)) ?
'' : (int) $value;
593 $value = (phpbb_request
::is_set($profile_row['field_ident'])) ?
request_var($profile_row['field_ident'], $default_value, true) : ((!isset($user->profile_fields
[$user_ident]) ||
$preview) ?
$default_value : $user->profile_fields
[$user_ident]);
595 if (gettype($value) == 'string')
597 $value = utf8_normalize_nfc($value);
601 switch ($field_validation)
615 private function generate_int($profile_row, $preview = false)
619 $profile_row['field_value'] = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
620 $template->assign_block_vars(self
::$profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER
));
627 private function generate_date($profile_row, $preview = false)
629 global $user, $template;
631 $profile_row['field_ident'] = (isset($profile_row['var_name'])) ?
$profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
632 $user_ident = $profile_row['field_ident'];
636 if (!phpbb_request
::is_set($profile_row['field_ident'] . '_day'))
638 if ($profile_row['field_default_value'] == 'now')
640 $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
642 list($day, $month, $year) = explode('-', ((!isset($user->profile_fields
[$user_ident]) ||
$preview) ?
$profile_row['field_default_value'] : $user->profile_fields
[$user_ident]));
646 if ($preview && $profile_row['field_default_value'] == 'now')
648 $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
649 list($day, $month, $year) = explode('-', ((!isset($user->profile_fields
[$user_ident]) ||
$preview) ?
$profile_row['field_default_value'] : $user->profile_fields
[$user_ident]));
653 $day = request_var($profile_row['field_ident'] . '_day', 0);
654 $month = request_var($profile_row['field_ident'] . '_month', 0);
655 $year = request_var($profile_row['field_ident'] . '_year', 0);
659 $profile_row['s_day_options'] = '<option value="0"' . ((!$day) ?
' selected="selected"' : '') . '>--</option>';
660 for ($i = 1; $i < 32; $i++
)
662 $profile_row['s_day_options'] .= '<option value="' . $i . '"' . (($i == $day) ?
' selected="selected"' : '') . ">$i</option>";
665 $profile_row['s_month_options'] = '<option value="0"' . ((!$month) ?
' selected="selected"' : '') . '>--</option>';
666 for ($i = 1; $i < 13; $i++
)
668 $profile_row['s_month_options'] .= '<option value="' . $i . '"' . (($i == $month) ?
' selected="selected"' : '') . ">$i</option>";
671 $profile_row['s_year_options'] = '<option value="0"' . ((!$year) ?
' selected="selected"' : '') . '>--</option>';
672 for ($i = $now['year'] - 100; $i <= $now['year'] +
100; $i++
)
674 $profile_row['s_year_options'] .= '<option value="' . $i . '"' . (($i == $year) ?
' selected="selected"' : '') . ">$i</option>";
678 $profile_row['field_value'] = 0;
679 $template->assign_block_vars(self
::$profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER
));
686 private function generate_bool($profile_row, $preview = false)
690 $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
692 $profile_row['field_value'] = $value;
693 $template->assign_block_vars(self
::$profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER
));
695 if ($profile_row['field_length'] == 1)
697 if (!isset($this->options_lang
[$profile_row['field_id']][$profile_row['lang_id']]) ||
!sizeof($this->options_lang
[$profile_row['field_id']][$profile_row['lang_id']]))
699 $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL
, $preview);
702 foreach ($this->options_lang
[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
704 $template->assign_block_vars('bool.options', array(
705 'OPTION_ID' => $option_id,
706 'CHECKED' => ($value == $option_id) ?
' checked="checked"' : '',
707 'VALUE' => $option_value)
714 * Process string-type
717 private function generate_string($profile_row, $preview = false)
721 $profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview);
722 $template->assign_block_vars(self
::$profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER
));
729 private function generate_text($profile_row, $preview = false)
731 global $template, $user;
733 $field_length = explode('|', $profile_row['field_length']);
734 $profile_row['field_rows'] = $field_length[0];
735 $profile_row['field_cols'] = $field_length[1];
737 $profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview);
738 $template->assign_block_vars(self
::$profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER
));
742 * Process dropdown-type
745 private function generate_dropdown($profile_row, $preview = false)
747 global $user, $template;
749 $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
751 if (!isset($this->options_lang
[$profile_row['field_id']]) ||
!isset($this->options_lang
[$profile_row['field_id']][$profile_row['lang_id']]) ||
!sizeof($this->options_lang
[$profile_row['field_id']][$profile_row['lang_id']]))
753 $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN
, $preview);
756 $profile_row['field_value'] = $value;
757 $template->assign_block_vars(self
::$profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER
));
759 foreach ($this->options_lang
[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
761 $template->assign_block_vars('dropdown.options', array(
762 'OPTION_ID' => $option_id,
763 'SELECTED' => ($value == $option_id) ?
' selected="selected"' : '',
764 'VALUE' => $option_value)
770 * Return Templated value/field. Possible values for $mode are:
771 * change == user is able to set/enter profile values; preview == just show the value
774 private function process_field_row($mode, $profile_row)
778 $preview = ($mode == 'preview') ?
true : false;
780 // set template filename
781 $template->set_filenames(array(
782 'cp_body' => 'custom_profile_fields.html')
785 // empty previously filled blockvars
786 foreach (self
::$profile_types as $field_case => $field_type)
788 $template->destroy_block_vars($field_type);
791 // Assign template variables
792 $type_func = 'generate_' . self
::$profile_types[$profile_row['field_type']];
793 $this->$type_func($profile_row, $preview);
795 // Return templated data
796 return $template->assign_display('cp_body');
800 * Build Array for user insertion into custom profile fields table
802 public static function build_insert_sql_array($cp_data)
804 global $db, $user, $auth;
806 $sql_not_in = array();
807 foreach ($cp_data as $key => $null)
809 $sql_not_in[] = (strncmp($key, 'pf_', 3) === 0) ?
substr($key, 3) : $key;
812 $sql = 'SELECT f.field_type, f.field_ident, f.field_default_value, l.lang_default_value
813 FROM ' . PROFILE_LANG_TABLE
. ' l, ' . PROFILE_FIELDS_TABLE
. ' f
814 WHERE l.lang_id = ' . $user->get_iso_lang_id() . '
815 ' . ((sizeof($sql_not_in)) ?
' AND ' . $db->sql_in_set('f.field_ident', $sql_not_in, true) : '') . '
816 AND l.field_id = f.field_id';
817 $result = $db->sql_query($sql);
819 while ($row = $db->sql_fetchrow($result))
821 if ($row['field_default_value'] == 'now' && $row['field_type'] == FIELD_DATE
)
824 $row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
827 $cp_data['pf_' . $row['field_ident']] = (in_array($row['field_type'], array(FIELD_TEXT
, FIELD_STRING
))) ?
$row['lang_default_value'] : $row['field_default_value'];
829 $db->sql_freeresult($result);
835 * Get profile field value on submit
838 private function get_profile_field($profile_row)
840 $var_name = 'pf_' . $profile_row['field_ident'];
842 switch ($profile_row['field_type'])
846 if (!phpbb_request
::is_set($var_name . '_day'))
848 if ($profile_row['field_default_value'] == 'now')
851 $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
853 list($day, $month, $year) = explode('-', $profile_row['field_default_value']);
857 $day = request_var($var_name . '_day', 0);
858 $month = request_var($var_name . '_month', 0);
859 $year = request_var($var_name . '_year', 0);
862 $var = sprintf('%2d-%2d-%4d', $day, $month, $year);
867 if ($profile_row['field_length'] == 2)
869 $var = phpbb_request
::is_set($var_name) ?
1 : 0;
873 $var = request_var($var_name, (int) $profile_row['field_default_value']);
879 $var = utf8_normalize_nfc(request_var($var_name, (string) $profile_row['field_default_value'], true));
883 if (phpbb_request
::is_set($var_name) && request_var($var_name, '') === '')
889 $var = request_var($var_name, (int) $profile_row['field_default_value']);
894 $var = request_var($var_name, (int) $profile_row['field_default_value']);
898 $var = request_var($var_name, $profile_row['field_default_value']);
907 * Custom Profile Fields ACP
910 class custom_profile_admin
extends custom_profile
912 public $vars = array();
915 * Return possible validation options
917 public function validate_options()
921 $validate_ary = array('CHARS_ANY' => '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+');
923 $validate_options = '';
924 foreach ($validate_ary as $lang => $value)
926 $selected = ($this->vars
['field_validation'] == $value) ?
' selected="selected"' : '';
927 $validate_options .= '<option value="' . $value . '"' . $selected . '>' . $user->lang
[$lang] . '</option>';
930 return $validate_options;
934 * Get string options for second step in ACP
936 public function get_string_options()
941 0 => array('TITLE' => $user->lang
['FIELD_LENGTH'], 'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars
['field_length'] . '" />'),
942 1 => array('TITLE' => $user->lang
['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars
['field_minlen'] . '" />'),
943 2 => array('TITLE' => $user->lang
['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars
['field_maxlen'] . '" />'),
944 3 => array('TITLE' => $user->lang
['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>')
951 * Get text options for second step in ACP
953 public function get_text_options()
958 0 => array('TITLE' => $user->lang
['FIELD_LENGTH'], 'FIELD' => '<input name="rows" size="5" value="' . $this->vars
['rows'] . '" /> ' . $user->lang
['ROWS'] . '</dd><dd><input name="columns" size="5" value="' . $this->vars
['columns'] . '" /> ' . $user->lang
['COLUMNS'] . ' <input type="hidden" name="field_length" value="' . $this->vars
['field_length'] . '" />'),
959 1 => array('TITLE' => $user->lang
['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="10" value="' . $this->vars
['field_minlen'] . '" />'),
960 2 => array('TITLE' => $user->lang
['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="10" value="' . $this->vars
['field_maxlen'] . '" />'),
961 3 => array('TITLE' => $user->lang
['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>')
968 * Get int options for second step in ACP
970 public function get_int_options()
975 0 => array('TITLE' => $user->lang
['FIELD_LENGTH'], 'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars
['field_length'] . '" />'),
976 1 => array('TITLE' => $user->lang
['MIN_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars
['field_minlen'] . '" />'),
977 2 => array('TITLE' => $user->lang
['MAX_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars
['field_maxlen'] . '" />'),
978 3 => array('TITLE' => $user->lang
['DEFAULT_VALUE'], 'FIELD' => '<input type="post" name="field_default_value" value="' . $this->vars
['field_default_value'] . '" />')
985 * Get bool options for second step in ACP
987 public function get_bool_options()
989 global $user, $lang_defs;
991 $default_lang_id = $lang_defs['iso'][phpbb
::$config['default_lang']];
993 $profile_row = array(
994 'var_name' => 'field_default_value',
996 'lang_name' => $this->vars
['lang_name'],
997 'lang_explain' => $this->vars
['lang_explain'],
998 'lang_id' => $default_lang_id,
999 'field_default_value' => $this->vars
['field_default_value'],
1000 'field_ident' => 'field_default_value',
1001 'field_type' => FIELD_BOOL
,
1002 'field_length' => $this->vars
['field_length'],
1003 'lang_options' => $this->vars
['lang_options']
1007 0 => array('TITLE' => $user->lang
['FIELD_TYPE'], 'EXPLAIN' => $user->lang
['BOOL_TYPE_EXPLAIN'], 'FIELD' => '<label><input type="radio" class="radio" name="field_length" value="1"' . (($this->vars
['field_length'] == 1) ?
' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $user->lang
['RADIO_BUTTONS'] . '</label><label><input type="radio" class="radio" name="field_length" value="2"' . (($this->vars
['field_length'] == 2) ?
' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $user->lang
['CHECKBOX'] . '</label>'),
1008 1 => array('TITLE' => $user->lang
['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row))
1015 * Get dropdown options for second step in ACP
1017 public function get_dropdown_options()
1019 global $user, $lang_defs;
1021 $default_lang_id = $lang_defs['iso'][phpbb
::$config['default_lang']];
1023 $profile_row[0] = array(
1024 'var_name' => 'field_default_value',
1026 'lang_name' => $this->vars
['lang_name'],
1027 'lang_explain' => $this->vars
['lang_explain'],
1028 'lang_id' => $default_lang_id,
1029 'field_default_value' => $this->vars
['field_default_value'],
1030 'field_ident' => 'field_default_value',
1031 'field_type' => FIELD_DROPDOWN
,
1032 'lang_options' => $this->vars
['lang_options']
1035 $profile_row[1] = $profile_row[0];
1036 $profile_row[1]['var_name'] = 'field_novalue';
1037 $profile_row[1]['field_ident'] = 'field_novalue';
1038 $profile_row[1]['field_default_value'] = $this->vars
['field_novalue'];
1041 0 => array('TITLE' => $user->lang
['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row[0])),
1042 1 => array('TITLE' => $user->lang
['NO_VALUE_OPTION'], 'EXPLAIN' => $user->lang
['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->process_field_row('preview', $profile_row[1]))
1049 * Get date options for second step in ACP
1051 public function get_date_options()
1053 global $user, $lang_defs;
1055 $default_lang_id = $lang_defs['iso'][phpbb
::$config['default_lang']];
1057 $profile_row = array(
1058 'var_name' => 'field_default_value',
1059 'lang_name' => $this->vars
['lang_name'],
1060 'lang_explain' => $this->vars
['lang_explain'],
1061 'lang_id' => $default_lang_id,
1062 'field_default_value' => $this->vars
['field_default_value'],
1063 'field_ident' => 'field_default_value',
1064 'field_type' => FIELD_DATE
,
1065 'field_length' => $this->vars
['field_length']
1068 $always_now = request_var('always_now', -1);
1069 if ($always_now == -1)
1071 $s_checked = ($this->vars
['field_default_value'] == 'now') ?
true : false;
1075 $s_checked = ($always_now) ?
true : false;
1079 0 => array('TITLE' => $user->lang
['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)),
1080 1 => array('TITLE' => $user->lang
['ALWAYS_TODAY'], 'FIELD' => '<label><input type="radio" class="radio" name="always_now" value="1"' . (($s_checked) ?
' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $user->lang
['YES'] . '</label><label><input type="radio" class="radio" name="always_now" value="0"' . ((!$s_checked) ?
' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $user->lang
['NO'] . '</label>'),