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 var $profile_types = array(FIELD_INT => 'int', FIELD_STRING => 'string', FIELD_TEXT => 'text', FIELD_BOOL => 'bool', FIELD_DROPDOWN => 'dropdown', FIELD_DATE => 'date');
26 var $profile_cache = array();
27 var $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 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
43 $sql_where .= ' AND f.field_show_on_reg = 1';
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_show_profile = 1';
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 function validate_profile_field($field_type, &$field_value, $field_data)
96 $field_validate = explode('-', $field_value);
98 $day = (isset($field_validate[0])) ? (int) $field_validate[0] : 0;
99 $month = (isset($field_validate[1])) ? (int) $field_validate[1] : 0;
100 $year = (isset($field_validate[2])) ? (int) $field_validate[2] : 0;
102 if ((!$day || !$month || !$year) && !$field_data['field_required'])
107 if ((!$day || !$month || !$year) && $field_data['field_required'])
109 return 'FIELD_REQUIRED';
112 if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50)
114 return 'FIELD_INVALID_DATE';
117 if (checkdate($month, $day, $year) === false)
119 return 'FIELD_INVALID_DATE';
124 $field_value = (bool) $field_value;
126 if (!$field_value && $field_data['field_required'])
128 return 'FIELD_REQUIRED';
133 if (trim($field_value) === '' && !$field_data['field_required'])
138 $field_value = (int) $field_value;
140 if ($field_value < $field_data['field_minlen'])
142 return 'FIELD_TOO_SMALL';
144 else if ($field_value > $field_data['field_maxlen'])
146 return 'FIELD_TOO_LARGE';
151 $field_value = (int) $field_value;
153 // retrieve option lang data if necessary
154 if (!isset($this->options_lang[$field_data['field_id']]) || !isset($this->options_lang[$field_data['field_id']][$field_data['lang_id']]) || !sizeof($this->options_lang[$file_data['field_id']][$field_data['lang_id']]))
156 $this->get_option_lang($field_data['field_id'], $field_data['lang_id'], FIELD_DROPDOWN, false);
159 if (!isset($this->options_lang[$field_data['field_id']][$field_data['lang_id']][$field_value]))
161 return 'FIELD_INVALID_VALUE';
164 if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
166 return 'FIELD_REQUIRED';
172 if (trim($field_value) === '' && !$field_data['field_required'])
176 else if (trim($field_value) === '' && $field_data['field_required'])
178 return 'FIELD_REQUIRED';
181 if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen'])
183 return 'FIELD_TOO_SHORT';
185 else if ($field_data['field_maxlen'] && utf8_strlen($field_value) > $field_data['field_maxlen'])
187 return 'FIELD_TOO_LONG';
190 if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*')
192 $field_validate = ($field_type == FIELD_STRING) ? $field_value : bbcode_nl2br($field_value);
193 if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate))
195 return 'FIELD_INVALID_CHARS';
205 * Build profile cache, used for display
208 function build_cache()
210 global $db, $user, $auth;
212 $this->profile_cache = array();
214 // Display hidden/no_view fields for admin/moderator
215 $sql = 'SELECT l.*, f.*
216 FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
217 WHERE l.lang_id = ' . $user->get_iso_lang_id() . '
218 AND f.field_active = 1 ' .
219 ((!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) ? ' AND f.field_hide = 0 ' : '') . '
220 AND f.field_no_view = 0
221 AND l.field_id = f.field_id
222 ORDER BY f.field_order';
223 $result = $db->sql_query($sql);
225 while ($row = $db->sql_fetchrow($result))
227 $this->profile_cache[$row['field_ident']] = $row;
229 $db->sql_freeresult($result);
233 * Get language entries for options and store them here for later use
235 function get_option_lang($field_id, $lang_id, $field_type, $preview)
241 $lang_options = (!is_array($this->vars['lang_options'])) ? explode("\n", $this->vars['lang_options']) : $this->vars['lang_options'];
243 foreach ($lang_options as $num => $var)
245 $this->options_lang[$field_id][$lang_id][($num + 1)] = $var;
250 $sql = 'SELECT option_id, lang_value
251 FROM ' . PROFILE_FIELDS_LANG_TABLE . "
252 WHERE field_id = $field_id
253 AND lang_id = $lang_id
254 AND field_type = $field_type
256 $result = $db->sql_query($sql);
258 while ($row = $db->sql_fetchrow($result))
260 $this->options_lang[$field_id][$lang_id][($row['option_id'] + 1)] = $row['lang_value'];
262 $db->sql_freeresult($result);
267 * Submit profile field for validation
270 function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error)
272 global $auth, $db, $user;
278 // If the field is required we show it on the registration page
279 $sql_where .= ' AND f.field_show_on_reg = 1';
283 // Show hidden fields to moderators/admins
284 if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
286 $sql_where .= ' AND f.field_show_profile = 1';
291 trigger_error('Wrong profile mode specified', E_USER_ERROR);
295 $sql = 'SELECT l.*, f.*
296 FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f
297 WHERE l.lang_id = $lang_id
298 AND f.field_active = 1
300 AND l.field_id = f.field_id
301 ORDER BY f.field_order";
302 $result = $db->sql_query($sql);
304 while ($row = $db->sql_fetchrow($result))
306 $cp_data['pf_' . $row['field_ident']] = $this->get_profile_field($row);
307 $check_value = $cp_data['pf_' . $row['field_ident']];
309 if (($cp_result = $this->validate_profile_field($row['field_type'], $check_value, $row)) !== false)
311 // If not and only showing common error messages, use this one
315 case 'FIELD_INVALID_DATE':
316 case 'FIELD_INVALID_VALUE':
317 case 'FIELD_REQUIRED':
318 $error = sprintf($user->lang[$cp_result], $row['lang_name']);
321 case 'FIELD_TOO_SHORT':
322 case 'FIELD_TOO_SMALL':
323 $error = sprintf($user->lang[$cp_result], $row['lang_name'], $row['field_minlen']);
326 case 'FIELD_TOO_LONG':
327 case 'FIELD_TOO_LARGE':
328 $error = sprintf($user->lang[$cp_result], $row['lang_name'], $row['field_maxlen']);
331 case 'FIELD_INVALID_CHARS':
332 switch ($row['field_validation'])
335 $error = sprintf($user->lang[$cp_result . '_NUMBERS_ONLY'], $row['lang_name']);
339 $error = sprintf($user->lang[$cp_result . '_ALPHA_ONLY'], $row['lang_name']);
342 case '[\w_\+\. \-\[\]]+':
343 $error = sprintf($user->lang[$cp_result . '_SPACERS_ONLY'], $row['lang_name']);
351 $cp_error[] = $error;
355 $db->sql_freeresult($result);
359 * Update profile field data directly
361 function update_profile_field_data($user_id, &$cp_data)
365 if (!sizeof($cp_data))
370 switch ($db->sql_layer)
375 $right_delim = $left_delim = '"';
389 $right_delim = $left_delim = '`';
393 // use new array for the UPDATE; changes in the key do not affect the original array
394 $cp_data_sql = array();
395 foreach ($cp_data as $key => $value)
397 // Firebird is case sensitive with delimiter
398 $cp_data_sql[$left_delim . (($db->sql_layer == 'firebird' || $db->sql_layer == 'oracle') ? strtoupper($key) : $key) . $right_delim] = $value;
401 $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
402 SET ' . $db->sql_build_array('UPDATE', $cp_data_sql) . "
403 WHERE user_id = $user_id";
404 $db->sql_query($sql);
406 if (!$db->sql_affectedrows())
408 $cp_data_sql['user_id'] = (int) $user_id;
410 $db->sql_return_on_error(true);
412 $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data_sql);
413 $db->sql_query($sql);
415 $db->sql_return_on_error(false);
420 * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled)
421 * 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
424 function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false)
430 if (!is_array($user_id))
432 $user_id = array($user_id);
435 if (!sizeof($this->profile_cache))
437 $this->build_cache();
440 if (!sizeof($user_id))
446 FROM ' . PROFILE_FIELDS_DATA_TABLE . '
447 WHERE ' . $db->sql_in_set('user_id', array_map('intval', $user_id));
448 $result = $db->sql_query($sql);
450 $field_data = array();
451 while ($row = $db->sql_fetchrow($result))
453 $field_data[$row['user_id']] = $row;
455 $db->sql_freeresult($result);
457 $user_fields = array();
459 // Go through the fields in correct order
460 foreach (array_keys($this->profile_cache) as $used_ident)
462 foreach ($field_data as $user_id => $row)
464 $user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
465 $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];
471 else if ($mode == 'show')
473 // $profile_row == $user_fields[$row['user_id']];
474 $tpl_fields = array();
475 $tpl_fields['row'] = $tpl_fields['blockrow'] = array();
477 foreach ($profile_row as $ident => $ident_ary)
479 $value = $this->get_profile_value($ident_ary);
486 $tpl_fields['row'] += array(
487 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value,
488 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'],
489 'PROFILE_' . strtoupper($ident) . '_NAME' => $ident_ary['data']['lang_name'],
490 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $ident_ary['data']['lang_explain'],
492 'S_PROFILE_' . strtoupper($ident) => true
495 $tpl_fields['blockrow'][] = array(
496 'PROFILE_FIELD_VALUE' => $value,
497 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'],
498 'PROFILE_FIELD_NAME' => $ident_ary['data']['lang_name'],
499 'PROFILE_FIELD_EXPLAIN' => $ident_ary['data']['lang_explain'],
501 'S_PROFILE_' . strtoupper($ident) => true
509 trigger_error('Wrong mode for custom profile', E_USER_ERROR);
514 * Get Profile Value for display
516 function get_profile_value($ident_ary)
518 $value = $ident_ary['value'];
519 $field_type = $ident_ary['data']['field_type'];
521 switch ($this->profile_types[$field_type])
538 $value = make_clickable($value);
539 $value = censor_text($value);
540 $value = bbcode_nl2br($value);
546 $date = explode('-', $value);
547 $day = (isset($date[0])) ? (int) $date[0] : 0;
548 $month = (isset($date[1])) ? (int) $date[1] : 0;
549 $year = (isset($date[2])) ? (int) $date[2] : 0;
551 if (!$day && !$month && !$year)
555 else if ($day && $month && $year)
558 // Date should display as the same date for every user regardless of timezone, so remove offset
559 // to compensate for the offset added by user::format_date()
560 return $user->format_date(gmmktime(0, 0, 0, $month, $day, $year) - ($user->timezone + $user->dst), $user->lang['DATE_FORMAT'], true);
567 $field_id = $ident_ary['data']['field_id'];
568 $lang_id = $ident_ary['data']['lang_id'];
569 if (!isset($this->options_lang[$field_id][$lang_id]))
571 $this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false);
574 if ($value == $ident_ary['data']['field_novalue'])
579 $value = (int) $value;
581 // User not having a value assigned
582 if (!isset($this->options_lang[$field_id][$lang_id][$value]))
587 return $this->options_lang[$field_id][$lang_id][$value];
591 $field_id = $ident_ary['data']['field_id'];
592 $lang_id = $ident_ary['data']['lang_id'];
593 if (!isset($this->options_lang[$field_id][$lang_id]))
595 $this->get_option_lang($field_id, $lang_id, FIELD_BOOL, false);
598 if ($ident_ary['data']['field_length'] == 1)
600 return (isset($this->options_lang[$field_id][$lang_id][(int) $value])) ? $this->options_lang[$field_id][$lang_id][(int) $value] : NULL;
608 return $this->options_lang[$field_id][$lang_id][(int) ($value) + 1];
613 trigger_error('Unknown profile type', E_USER_ERROR);
619 * Get field value for registration/profile
622 function get_var($field_validation, &$profile_row, $default_value, $preview)
626 $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
627 $user_ident = $profile_row['field_ident'];
628 // checkbox - only testing for isset
629 if ($profile_row['field_type'] == FIELD_BOOL && $profile_row['field_length'] == 2)
631 $value = (isset($_REQUEST[$profile_row['field_ident']])) ? true : ((!isset($user->profile_fields[$user_ident]) || $preview) ? $default_value : $user->profile_fields[$user_ident]);
633 else if ($profile_row['field_type'] == FIELD_INT)
635 if (isset($_REQUEST[$profile_row['field_ident']]))
637 $value = ($_REQUEST[$profile_row['field_ident']] === '') ? NULL : request_var($profile_row['field_ident'], $default_value);
641 if (!$preview && array_key_exists($user_ident, $user->profile_fields) && is_null($user->profile_fields[$user_ident]))
645 else if (!isset($user->profile_fields[$user_ident]) || $preview)
647 $value = $default_value;
651 $value = $user->profile_fields[$user_ident];
655 return (is_null($value) || $value === '') ? '' : (int) $value;
659 $value = (isset($_REQUEST[$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]);
661 if (gettype($value) == 'string')
663 $value = utf8_normalize_nfc($value);
667 switch ($field_validation)
681 function generate_int($profile_row, $preview = false)
685 $profile_row['field_value'] = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
686 $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
693 function generate_date($profile_row, $preview = false)
695 global $user, $template;
697 $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
698 $user_ident = $profile_row['field_ident'];
702 if (!isset($_REQUEST[$profile_row['field_ident'] . '_day']))
704 if ($profile_row['field_default_value'] == 'now')
706 $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
708 list($day, $month, $year) = explode('-', ((!isset($user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $user->profile_fields[$user_ident]));
712 if ($preview && $profile_row['field_default_value'] == 'now')
714 $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
715 list($day, $month, $year) = explode('-', ((!isset($user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $user->profile_fields[$user_ident]));
719 $day = request_var($profile_row['field_ident'] . '_day', 0);
720 $month = request_var($profile_row['field_ident'] . '_month', 0);
721 $year = request_var($profile_row['field_ident'] . '_year', 0);
725 $profile_row['s_day_options'] = '<option value="0"' . ((!$day) ? ' selected="selected"' : '') . '>--</option>';
726 for ($i = 1; $i < 32; $i++)
728 $profile_row['s_day_options'] .= '<option value="' . $i . '"' . (($i == $day) ? ' selected="selected"' : '') . ">$i</option>";
731 $profile_row['s_month_options'] = '<option value="0"' . ((!$month) ? ' selected="selected"' : '') . '>--</option>';
732 for ($i = 1; $i < 13; $i++)
734 $profile_row['s_month_options'] .= '<option value="' . $i . '"' . (($i == $month) ? ' selected="selected"' : '') . ">$i</option>";
737 $profile_row['s_year_options'] = '<option value="0"' . ((!$year) ? ' selected="selected"' : '') . '>--</option>';
738 for ($i = $now['year'] - 100; $i <= $now['year'] + 100; $i++)
740 $profile_row['s_year_options'] .= '<option value="' . $i . '"' . (($i == $year) ? ' selected="selected"' : '') . ">$i</option>";
744 $profile_row['field_value'] = 0;
745 $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
752 function generate_bool($profile_row, $preview = false)
756 $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
758 $profile_row['field_value'] = $value;
759 $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
761 if ($profile_row['field_length'] == 1)
763 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']]))
765 $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview);
768 foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
770 $template->assign_block_vars('bool.options', array(
771 'OPTION_ID' => $option_id,
772 'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '',
773 'VALUE' => $option_value)
780 * Process string-type
783 function generate_string($profile_row, $preview = false)
787 $profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview);
788 $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
795 function generate_text($profile_row, $preview = false)
798 global $user, $phpEx, $phpbb_root_path;
800 $field_length = explode('|', $profile_row['field_length']);
801 $profile_row['field_rows'] = $field_length[0];
802 $profile_row['field_cols'] = $field_length[1];
804 $profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview);
805 $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
809 * Process dropdown-type
812 function generate_dropdown($profile_row, $preview = false)
814 global $user, $template;
816 $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
818 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']]))
820 $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview);
823 $profile_row['field_value'] = $value;
824 $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
826 foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
828 $template->assign_block_vars('dropdown.options', array(
829 'OPTION_ID' => $option_id,
830 'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '',
831 'VALUE' => $option_value)
837 * Return Templated value/field. Possible values for $mode are:
838 * change == user is able to set/enter profile values; preview == just show the value
841 function process_field_row($mode, $profile_row)
845 $preview = ($mode == 'preview') ? true : false;
847 // set template filename
848 $template->set_filenames(array(
849 'cp_body' => 'custom_profile_fields.html')
852 // empty previously filled blockvars
853 foreach ($this->profile_types as $field_case => $field_type)
855 $template->destroy_block_vars($field_type);
858 // Assign template variables
859 $type_func = 'generate_' . $this->profile_types[$profile_row['field_type']];
860 $this->$type_func($profile_row, $preview);
862 // Return templated data
863 return $template->assign_display('cp_body');
867 * Build Array for user insertion into custom profile fields table
869 function build_insert_sql_array($cp_data)
871 global $db, $user, $auth;
873 $sql_not_in = array();
874 foreach ($cp_data as $key => $null)
876 $sql_not_in[] = (strncmp($key, 'pf_', 3) === 0) ? substr($key, 3) : $key;
879 $sql = 'SELECT f.field_type, f.field_ident, f.field_default_value, l.lang_default_value
880 FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
881 WHERE l.lang_id = ' . $user->get_iso_lang_id() . '
882 ' . ((sizeof($sql_not_in)) ? ' AND ' . $db->sql_in_set('f.field_ident', $sql_not_in, true) : '') . '
883 AND l.field_id = f.field_id';
884 $result = $db->sql_query($sql);
886 while ($row = $db->sql_fetchrow($result))
888 if ($row['field_default_value'] == 'now' && $row['field_type'] == FIELD_DATE)
891 $row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
893 else if ($row['field_default_value'] === '' && $row['field_type'] == FIELD_INT)
895 // We cannot insert an empty string into an integer column.
896 $row['field_default_value'] = NULL;
899 $cp_data['pf_' . $row['field_ident']] = (in_array($row['field_type'], array(FIELD_TEXT, FIELD_STRING))) ? $row['lang_default_value'] : $row['field_default_value'];
901 $db->sql_freeresult($result);
907 * Get profile field value on submit
910 function get_profile_field($profile_row)
912 global $phpbb_root_path, $phpEx;
915 $var_name = 'pf_' . $profile_row['field_ident'];
917 switch ($profile_row['field_type'])
921 if (!isset($_REQUEST[$var_name . '_day']))
923 if ($profile_row['field_default_value'] == 'now')
926 $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
928 list($day, $month, $year) = explode('-', $profile_row['field_default_value']);
932 $day = request_var($var_name . '_day', 0);
933 $month = request_var($var_name . '_month', 0);
934 $year = request_var($var_name . '_year', 0);
937 $var = sprintf('%2d-%2d-%4d', $day, $month, $year);
942 if ($profile_row['field_length'] == 2)
944 $var = (isset($_REQUEST[$var_name])) ? 1 : 0;
948 $var = request_var($var_name, (int) $profile_row['field_default_value']);
954 $var = utf8_normalize_nfc(request_var($var_name, (string) $profile_row['field_default_value'], true));
958 if (isset($_REQUEST[$var_name]) && $_REQUEST[$var_name] === '')
964 $var = request_var($var_name, (int) $profile_row['field_default_value']);
969 $var = request_var($var_name, (int) $profile_row['field_default_value']);
973 $var = request_var($var_name, $profile_row['field_default_value']);
982 * Custom Profile Fields ACP
985 class custom_profile_admin extends custom_profile
990 * Return possible validation options
992 function validate_options()
996 $validate_ary = array('CHARS_ANY' => '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+');
998 $validate_options = '';
999 foreach ($validate_ary as $lang => $value)
1001 $selected = ($this->vars['field_validation'] == $value) ? ' selected="selected"' : '';
1002 $validate_options .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$lang] . '</option>';
1005 return $validate_options;
1009 * Get string options for second step in ACP
1011 function get_string_options()
1016 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'),
1017 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'),
1018 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'),
1019 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>')
1026 * Get text options for second step in ACP
1028 function get_text_options()
1033 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'] . '" />'),
1034 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="10" value="' . $this->vars['field_minlen'] . '" />'),
1035 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="10" value="' . $this->vars['field_maxlen'] . '" />'),
1036 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>')
1043 * Get int options for second step in ACP
1045 function get_int_options()
1050 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'),
1051 1 => array('TITLE' => $user->lang['MIN_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'),
1052 2 => array('TITLE' => $user->lang['MAX_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'),
1053 3 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => '<input type="post" name="field_default_value" value="' . $this->vars['field_default_value'] . '" />')
1060 * Get bool options for second step in ACP
1062 function get_bool_options()
1064 global $user, $config, $lang_defs;
1066 $default_lang_id = $lang_defs['iso'][$config['default_lang']];
1068 $profile_row = array(
1069 'var_name' => 'field_default_value',
1071 'lang_name' => $this->vars['lang_name'],
1072 'lang_explain' => $this->vars['lang_explain'],
1073 'lang_id' => $default_lang_id,
1074 'field_default_value' => $this->vars['field_default_value'],
1075 'field_ident' => 'field_default_value',
1076 'field_type' => FIELD_BOOL,
1077 'field_length' => $this->vars['field_length'],
1078 'lang_options' => $this->vars['lang_options']
1082 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>'),
1083 1 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row))
1090 * Get dropdown options for second step in ACP
1092 function get_dropdown_options()
1094 global $user, $config, $lang_defs;
1096 $default_lang_id = $lang_defs['iso'][$config['default_lang']];
1098 $profile_row[0] = array(
1099 'var_name' => 'field_default_value',
1101 'lang_name' => $this->vars['lang_name'],
1102 'lang_explain' => $this->vars['lang_explain'],
1103 'lang_id' => $default_lang_id,
1104 'field_default_value' => $this->vars['field_default_value'],
1105 'field_ident' => 'field_default_value',
1106 'field_type' => FIELD_DROPDOWN,
1107 'lang_options' => $this->vars['lang_options']
1110 $profile_row[1] = $profile_row[0];
1111 $profile_row[1]['var_name'] = 'field_novalue';
1112 $profile_row[1]['field_ident'] = 'field_novalue';
1113 $profile_row[1]['field_default_value'] = $this->vars['field_novalue'];
1116 0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row[0])),
1117 1 => array('TITLE' => $user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->process_field_row('preview', $profile_row[1]))
1124 * Get date options for second step in ACP
1126 function get_date_options()
1128 global $user, $config, $lang_defs;
1130 $default_lang_id = $lang_defs['iso'][$config['default_lang']];
1132 $profile_row = array(
1133 'var_name' => 'field_default_value',
1134 'lang_name' => $this->vars['lang_name'],
1135 'lang_explain' => $this->vars['lang_explain'],
1136 'lang_id' => $default_lang_id,
1137 'field_default_value' => $this->vars['field_default_value'],
1138 'field_ident' => 'field_default_value',
1139 'field_type' => FIELD_DATE,
1140 'field_length' => $this->vars['field_length']
1143 $always_now = request_var('always_now', -1);
1144 if ($always_now == -1)
1146 $s_checked = ($this->vars['field_default_value'] == 'now') ? true : false;
1150 $s_checked = ($always_now) ? true : false;
1154 0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)),
1155 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>'),