|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @package phpBB3
|
|
|
4c79b5 |
* @version $Id: functions_profile_fields.php 9127 2008-11-26 19:58:35Z acydburn $
|
|
|
4c79b5 |
* @copyright (c) 2005 phpBB Group
|
|
|
4c79b5 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* @ignore
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
if (!defined('IN_PHPBB'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
exit;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Custom Profile Fields
|
|
|
4c79b5 |
* @package phpBB3
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
class custom_profile
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var $profile_types = array(FIELD_INT => 'int', FIELD_STRING => 'string', FIELD_TEXT => 'text', FIELD_BOOL => 'bool', FIELD_DROPDOWN => 'dropdown', FIELD_DATE => 'date');
|
|
|
4c79b5 |
var $profile_cache = array();
|
|
|
4c79b5 |
var $options_lang = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Assign editable fields to template, mode can be profile (for profile change) or register (for registration)
|
|
|
4c79b5 |
* Called by ucp_profile and ucp_register
|
|
|
4c79b5 |
* @access public
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function generate_profile_fields($mode, $lang_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $template, $auth;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_where = '';
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'register':
|
|
|
4c79b5 |
// If the field is required we show it on the registration page and do not show hidden fields
|
|
|
4c79b5 |
$sql_where .= ' AND f.field_show_on_reg = 1 AND f.field_no_view = 0';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'profile':
|
|
|
4c79b5 |
// Show hidden fields to moderators/admins
|
|
|
4c79b5 |
if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_where .= ' AND f.field_show_profile = 1';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
default:
|
|
|
4c79b5 |
trigger_error('Wrong profile mode specified', E_USER_ERROR);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT l.*, f.*
|
|
|
4c79b5 |
FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f
|
|
|
4c79b5 |
WHERE f.field_active = 1
|
|
|
4c79b5 |
$sql_where
|
|
|
4c79b5 |
AND l.lang_id = $lang_id
|
|
|
4c79b5 |
AND l.field_id = f.field_id
|
|
|
4c79b5 |
ORDER BY f.field_order";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Return templated field
|
|
|
4c79b5 |
$tpl_snippet = $this->process_field_row('change', $row);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Some types are multivalue, we can't give them a field_id as we would not know which to pick
|
|
|
4c79b5 |
$type = (int) $row['field_type'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_block_vars('profile_fields', array(
|
|
|
4c79b5 |
'LANG_NAME' => $row['lang_name'],
|
|
|
4c79b5 |
'LANG_EXPLAIN' => $row['lang_explain'],
|
|
|
4c79b5 |
'FIELD' => $tpl_snippet,
|
|
|
4c79b5 |
'FIELD_ID' => ($type == FIELD_DATE || ($type == FIELD_BOOL && $row['field_length'] == '1')) ? '' : 'pf_' . $row['field_ident'],
|
|
|
4c79b5 |
'S_REQUIRED' => ($row['field_required']) ? true : false)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Validate entered profile field data
|
|
|
4c79b5 |
* @access public
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function validate_profile_field($field_type, &$field_value, $field_data)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($field_type)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case FIELD_INT:
|
|
|
4c79b5 |
case FIELD_DROPDOWN:
|
|
|
4c79b5 |
$field_value = (int) $field_value;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case FIELD_BOOL:
|
|
|
4c79b5 |
$field_value = (bool) $field_value;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($field_type)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case FIELD_DATE:
|
|
|
4c79b5 |
$field_validate = explode('-', $field_value);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$day = (isset($field_validate[0])) ? (int) $field_validate[0] : 0;
|
|
|
4c79b5 |
$month = (isset($field_validate[1])) ? (int) $field_validate[1] : 0;
|
|
|
4c79b5 |
$year = (isset($field_validate[2])) ? (int) $field_validate[2] : 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ((!$day || !$month || !$year) && !$field_data['field_required'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ((!$day || !$month || !$year) && $field_data['field_required'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return 'FIELD_REQUIRED';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return 'FIELD_INVALID_DATE';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (checkdate($month, $day, $year) === false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return 'FIELD_INVALID_DATE';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case FIELD_BOOL:
|
|
|
4c79b5 |
if (!$field_value && $field_data['field_required'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return 'FIELD_REQUIRED';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case FIELD_INT:
|
|
|
4c79b5 |
if (empty($field_value) && !$field_data['field_required'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($field_value < $field_data['field_minlen'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return 'FIELD_TOO_SMALL';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($field_value > $field_data['field_maxlen'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return 'FIELD_TOO_LARGE';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case FIELD_DROPDOWN:
|
|
|
4c79b5 |
if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return 'FIELD_REQUIRED';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case FIELD_STRING:
|
|
|
4c79b5 |
case FIELD_TEXT:
|
|
|
4c79b5 |
if (empty($field_value) && !$field_data['field_required'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (empty($field_value) && $field_data['field_required'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return 'FIELD_REQUIRED';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return 'FIELD_TOO_SHORT';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($field_data['field_maxlen'] && utf8_strlen($field_value) > $field_data['field_maxlen'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return 'FIELD_TOO_LONG';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$field_validate = ($field_type == FIELD_STRING) ? $field_value : bbcode_nl2br($field_value);
|
|
|
4c79b5 |
if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return 'FIELD_INVALID_CHARS';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Build profile cache, used for display
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function build_cache()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $user, $auth;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->profile_cache = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Display hidden/no_view fields for admin/moderator
|
|
|
4c79b5 |
$sql = 'SELECT l.*, f.*
|
|
|
4c79b5 |
FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
|
|
|
4c79b5 |
WHERE l.lang_id = ' . $user->get_iso_lang_id() . '
|
|
|
4c79b5 |
AND f.field_active = 1 ' .
|
|
|
4c79b5 |
((!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) ? ' AND f.field_hide = 0 ' : '') . '
|
|
|
4c79b5 |
AND f.field_no_view = 0
|
|
|
4c79b5 |
AND l.field_id = f.field_id
|
|
|
4c79b5 |
ORDER BY f.field_order';
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->profile_cache[$row['field_ident']] = $row;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get language entries for options and store them here for later use
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function get_option_lang($field_id, $lang_id, $field_type, $preview)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($preview)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$lang_options = (!is_array($this->vars['lang_options'])) ? explode("\n", $this->vars['lang_options']) : $this->vars['lang_options'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($lang_options as $num => $var)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->options_lang[$field_id][$lang_id][($num + 1)] = $var;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT option_id, lang_value
|
|
|
4c79b5 |
FROM ' . PROFILE_FIELDS_LANG_TABLE . "
|
|
|
4c79b5 |
WHERE field_id = $field_id
|
|
|
4c79b5 |
AND lang_id = $lang_id
|
|
|
4c79b5 |
AND field_type = $field_type
|
|
|
4c79b5 |
ORDER BY option_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->options_lang[$field_id][$lang_id][($row['option_id'] + 1)] = $row['lang_value'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Submit profile field
|
|
|
4c79b5 |
* @access public
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $auth, $db, $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_where = '';
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'register':
|
|
|
4c79b5 |
// If the field is required we show it on the registration page and do not show hidden fields
|
|
|
4c79b5 |
$sql_where .= ' AND f.field_show_on_reg = 1 AND f.field_no_view = 0';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'profile':
|
|
|
4c79b5 |
// Show hidden fields to moderators/admins
|
|
|
4c79b5 |
if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_where .= ' AND f.field_show_profile = 1';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
default:
|
|
|
4c79b5 |
trigger_error('Wrong profile mode specified', E_USER_ERROR);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT l.*, f.*
|
|
|
4c79b5 |
FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f
|
|
|
4c79b5 |
WHERE l.lang_id = $lang_id
|
|
|
4c79b5 |
AND f.field_active = 1
|
|
|
4c79b5 |
$sql_where
|
|
|
4c79b5 |
AND l.field_id = f.field_id
|
|
|
4c79b5 |
ORDER BY f.field_order";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cp_data['pf_' . $row['field_ident']] = $this->get_profile_field($row);
|
|
|
4c79b5 |
$check_value = $cp_data['pf_' . $row['field_ident']];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (($cp_result = $this->validate_profile_field($row['field_type'], $check_value, $row)) !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// If not and only showing common error messages, use this one
|
|
|
4c79b5 |
$error = '';
|
|
|
4c79b5 |
switch ($cp_result)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'FIELD_INVALID_DATE':
|
|
|
4c79b5 |
case 'FIELD_REQUIRED':
|
|
|
4c79b5 |
$error = sprintf($user->lang[$cp_result], $row['lang_name']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'FIELD_TOO_SHORT':
|
|
|
4c79b5 |
case 'FIELD_TOO_SMALL':
|
|
|
4c79b5 |
$error = sprintf($user->lang[$cp_result], $row['lang_name'], $row['field_minlen']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'FIELD_TOO_LONG':
|
|
|
4c79b5 |
case 'FIELD_TOO_LARGE':
|
|
|
4c79b5 |
$error = sprintf($user->lang[$cp_result], $row['lang_name'], $row['field_maxlen']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'FIELD_INVALID_CHARS':
|
|
|
4c79b5 |
switch ($row['field_validation'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case '[0-9]+':
|
|
|
4c79b5 |
$error = sprintf($user->lang[$cp_result . '_NUMBERS_ONLY'], $row['lang_name']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case '[\w]+':
|
|
|
4c79b5 |
$error = sprintf($user->lang[$cp_result . '_ALPHA_ONLY'], $row['lang_name']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case '[\w_\+\. \-\[\]]+':
|
|
|
4c79b5 |
$error = sprintf($user->lang[$cp_result . '_SPACERS_ONLY'], $row['lang_name']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($error != '')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cp_error[] = $error;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled)
|
|
|
4c79b5 |
* 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
|
|
|
4c79b5 |
* @access public
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode == 'grab')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!is_array($user_id))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$user_id = array($user_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!sizeof($this->profile_cache))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->build_cache();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!sizeof($user_id))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return array();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . PROFILE_FIELDS_DATA_TABLE . '
|
|
|
4c79b5 |
WHERE ' . $db->sql_in_set('user_id', array_map('intval', $user_id));
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$field_data = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$field_data[$row['user_id']] = $row;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$user_fields = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Go through the fields in correct order
|
|
|
4c79b5 |
foreach (array_keys($this->profile_cache) as $used_ident)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($field_data as $user_id => $row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
|
|
|
4c79b5 |
$user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $user_fields;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($mode == 'show')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// $profile_row == $user_fields[$row['user_id']];
|
|
|
4c79b5 |
$tpl_fields = array();
|
|
|
4c79b5 |
$tpl_fields['row'] = $tpl_fields['blockrow'] = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($profile_row as $ident => $ident_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$value = $this->get_profile_value($ident_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($value === NULL)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$tpl_fields['row'] += array(
|
|
|
4c79b5 |
'PROFILE_' . strtoupper($ident) . '_VALUE' => $value,
|
|
|
4c79b5 |
'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'],
|
|
|
4c79b5 |
'PROFILE_' . strtoupper($ident) . '_NAME' => $ident_ary['data']['lang_name'],
|
|
|
4c79b5 |
'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $ident_ary['data']['lang_explain'],
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'S_PROFILE_' . strtoupper($ident) => true
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$tpl_fields['blockrow'][] = array(
|
|
|
4c79b5 |
'PROFILE_FIELD_VALUE' => $value,
|
|
|
4c79b5 |
'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'],
|
|
|
4c79b5 |
'PROFILE_FIELD_NAME' => $ident_ary['data']['lang_name'],
|
|
|
4c79b5 |
'PROFILE_FIELD_EXPLAIN' => $ident_ary['data']['lang_explain'],
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'S_PROFILE_' . strtoupper($ident) => true
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $tpl_fields;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error('Wrong mode for custom profile', E_USER_ERROR);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get Profile Value for display
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function get_profile_value($ident_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$value = $ident_ary['value'];
|
|
|
4c79b5 |
$field_type = $ident_ary['data']['field_type'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($this->profile_types[$field_type])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'int':
|
|
|
4c79b5 |
if ($value == '')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return NULL;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
return (int) $value;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'string':
|
|
|
4c79b5 |
case 'text':
|
|
|
4c79b5 |
if (!$value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return NULL;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$value = make_clickable($value);
|
|
|
4c79b5 |
$value = censor_text($value);
|
|
|
4c79b5 |
$value = bbcode_nl2br($value);
|
|
|
4c79b5 |
return $value;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// case 'datetime':
|
|
|
4c79b5 |
case 'date':
|
|
|
4c79b5 |
$date = explode('-', $value);
|
|
|
4c79b5 |
$day = (isset($date[0])) ? (int) $date[0] : 0;
|
|
|
4c79b5 |
$month = (isset($date[1])) ? (int) $date[1] : 0;
|
|
|
4c79b5 |
$year = (isset($date[2])) ? (int) $date[2] : 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$day && !$month && !$year)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return NULL;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($day && $month && $year)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user;
|
|
|
4c79b5 |
// 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
|
|
|
4c79b5 |
return $user->format_date(gmmktime(0, 0, 0, $month, $day, $year) + $user->timezone + $user->dst, $user->lang['DATE_FORMAT'], true);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $value;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'dropdown':
|
|
|
4c79b5 |
$field_id = $ident_ary['data']['field_id'];
|
|
|
4c79b5 |
$lang_id = $ident_ary['data']['lang_id'];
|
|
|
4c79b5 |
if (!isset($this->options_lang[$field_id][$lang_id]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($value == $ident_ary['data']['field_novalue'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return NULL;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$value = (int) $value;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// User not having a value assigned
|
|
|
4c79b5 |
if (!isset($this->options_lang[$field_id][$lang_id][$value]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return NULL;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $this->options_lang[$field_id][$lang_id][$value];
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'bool':
|
|
|
4c79b5 |
$field_id = $ident_ary['data']['field_id'];
|
|
|
4c79b5 |
$lang_id = $ident_ary['data']['lang_id'];
|
|
|
4c79b5 |
if (!isset($this->options_lang[$field_id][$lang_id]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->get_option_lang($field_id, $lang_id, FIELD_BOOL, false);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($ident_ary['data']['field_length'] == 1)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return (isset($this->options_lang[$field_id][$lang_id][(int) $value])) ? $this->options_lang[$field_id][$lang_id][(int) $value] : NULL;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (!$value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return NULL;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $this->options_lang[$field_id][$lang_id][(int) ($value) + 1];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
default:
|
|
|
4c79b5 |
trigger_error('Unknown profile type', E_USER_ERROR);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get field value for registration/profile
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function get_var($field_validation, &$profile_row, $default_value, $preview)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
|
|
|
4c79b5 |
$user_ident = $profile_row['field_ident'];
|
|
|
4c79b5 |
// checkbox - only testing for isset
|
|
|
4c79b5 |
if ($profile_row['field_type'] == FIELD_BOOL && $profile_row['field_length'] == 2)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$value = (isset($_REQUEST[$profile_row['field_ident']])) ? true : ((!isset($user->profile_fields[$user_ident]) || $preview) ? $default_value : $user->profile_fields[$user_ident]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($profile_row['field_type'] == FIELD_INT)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (isset($_REQUEST[$profile_row['field_ident']]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$value = ($_REQUEST[$profile_row['field_ident']] === '') ? NULL : request_var($profile_row['field_ident'], $default_value);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!$preview && isset($user->profile_fields[$user_ident]) && is_null($user->profile_fields[$user_ident]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$value = NULL;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (!isset($user->profile_fields[$user_ident]) || $preview)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$value = $default_value;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$value = $user->profile_fields[$user_ident];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return (is_null($value)) ? '' : (int) $value;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$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]);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (gettype($value) == 'string')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$value = utf8_normalize_nfc($value);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($field_validation)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'int':
|
|
|
4c79b5 |
return (int) $value;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $value;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Process int-type
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function generate_int($profile_row, $preview = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $template;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row['field_value'] = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
|
|
|
4c79b5 |
$template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Process date-type
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function generate_date($profile_row, $preview = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user, $template;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
|
|
|
4c79b5 |
$user_ident = $profile_row['field_ident'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$now = getdate();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!isset($_REQUEST[$profile_row['field_ident'] . '_day']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($profile_row['field_default_value'] == 'now')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
list($day, $month, $year) = explode('-', ((!isset($user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $user->profile_fields[$user_ident]));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($preview && $profile_row['field_default_value'] == 'now')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
|
|
|
4c79b5 |
list($day, $month, $year) = explode('-', ((!isset($user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $user->profile_fields[$user_ident]));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$day = request_var($profile_row['field_ident'] . '_day', 0);
|
|
|
4c79b5 |
$month = request_var($profile_row['field_ident'] . '_month', 0);
|
|
|
4c79b5 |
$year = request_var($profile_row['field_ident'] . '_year', 0);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row['s_day_options'] = '<option value="0"' . ((!$day) ? ' selected="selected"' : '') . '>--</option>';
|
|
|
4c79b5 |
for ($i = 1; $i < 32; $i++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$profile_row['s_day_options'] .= '<option value="' . $i . '"' . (($i == $day) ? ' selected="selected"' : '') . ">$i</option>";
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row['s_month_options'] = '<option value="0"' . ((!$month) ? ' selected="selected"' : '') . '>--</option>';
|
|
|
4c79b5 |
for ($i = 1; $i < 13; $i++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$profile_row['s_month_options'] .= '<option value="' . $i . '"' . (($i == $month) ? ' selected="selected"' : '') . ">$i</option>";
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row['s_year_options'] = '<option value="0"' . ((!$year) ? ' selected="selected"' : '') . '>--</option>';
|
|
|
4c79b5 |
for ($i = $now['year'] - 100; $i <= $now['year'] + 100; $i++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$profile_row['s_year_options'] .= '<option value="' . $i . '"' . (($i == $year) ? ' selected="selected"' : '') . ">$i</option>";
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($now);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row['field_value'] = 0;
|
|
|
4c79b5 |
$template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Process bool-type
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function generate_bool($profile_row, $preview = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $template;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row['field_value'] = $value;
|
|
|
4c79b5 |
$template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($profile_row['field_length'] == 1)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
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']]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template->assign_block_vars('bool.options', array(
|
|
|
4c79b5 |
'OPTION_ID' => $option_id,
|
|
|
4c79b5 |
'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '',
|
|
|
4c79b5 |
'VALUE' => $option_value)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Process string-type
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function generate_string($profile_row, $preview = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $template;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview);
|
|
|
4c79b5 |
$template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Process text-type
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function generate_text($profile_row, $preview = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $template;
|
|
|
4c79b5 |
global $user, $phpEx, $phpbb_root_path;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$field_length = explode('|', $profile_row['field_length']);
|
|
|
4c79b5 |
$profile_row['field_rows'] = $field_length[0];
|
|
|
4c79b5 |
$profile_row['field_cols'] = $field_length[1];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview);
|
|
|
4c79b5 |
$template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Process dropdown-type
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function generate_dropdown($profile_row, $preview = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user, $template;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
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']]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row['field_value'] = $value;
|
|
|
4c79b5 |
$template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template->assign_block_vars('dropdown.options', array(
|
|
|
4c79b5 |
'OPTION_ID' => $option_id,
|
|
|
4c79b5 |
'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '',
|
|
|
4c79b5 |
'VALUE' => $option_value)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Return Templated value/field. Possible values for $mode are:
|
|
|
4c79b5 |
* change == user is able to set/enter profile values; preview == just show the value
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function process_field_row($mode, $profile_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $template;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$preview = ($mode == 'preview') ? true : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// set template filename
|
|
|
4c79b5 |
$template->set_filenames(array(
|
|
|
4c79b5 |
'cp_body' => 'custom_profile_fields.html')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// empty previously filled blockvars
|
|
|
4c79b5 |
foreach ($this->profile_types as $field_case => $field_type)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template->destroy_block_vars($field_type);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Assign template variables
|
|
|
4c79b5 |
$type_func = 'generate_' . $this->profile_types[$profile_row['field_type']];
|
|
|
4c79b5 |
$this->$type_func($profile_row, $preview);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Return templated data
|
|
|
4c79b5 |
return $template->assign_display('cp_body');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Build Array for user insertion into custom profile fields table
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function build_insert_sql_array($cp_data)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $user, $auth;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_not_in = array();
|
|
|
4c79b5 |
foreach ($cp_data as $key => $null)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_not_in[] = (strncmp($key, 'pf_', 3) === 0) ? substr($key, 3) : $key;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT f.field_type, f.field_ident, f.field_default_value, l.lang_default_value
|
|
|
4c79b5 |
FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
|
|
|
4c79b5 |
WHERE l.lang_id = ' . $user->get_iso_lang_id() . '
|
|
|
4c79b5 |
' . ((sizeof($sql_not_in)) ? ' AND ' . $db->sql_in_set('f.field_ident', $sql_not_in, true) : '') . '
|
|
|
4c79b5 |
AND l.field_id = f.field_id';
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($row['field_default_value'] == 'now' && $row['field_type'] == FIELD_DATE)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$now = getdate();
|
|
|
4c79b5 |
$row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cp_data['pf_' . $row['field_ident']] = (in_array($row['field_type'], array(FIELD_TEXT, FIELD_STRING))) ? $row['lang_default_value'] : $row['field_default_value'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $cp_data;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get profile field value on submit
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function get_profile_field($profile_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $phpEx;
|
|
|
4c79b5 |
global $config;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$var_name = 'pf_' . $profile_row['field_ident'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($profile_row['field_type'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case FIELD_DATE:
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!isset($_REQUEST[$var_name . '_day']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($profile_row['field_default_value'] == 'now')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$now = getdate();
|
|
|
4c79b5 |
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
list($day, $month, $year) = explode('-', $profile_row['field_default_value']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$day = request_var($var_name . '_day', 0);
|
|
|
4c79b5 |
$month = request_var($var_name . '_month', 0);
|
|
|
4c79b5 |
$year = request_var($var_name . '_year', 0);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$var = sprintf('%2d-%2d-%4d', $day, $month, $year);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case FIELD_BOOL:
|
|
|
4c79b5 |
// Checkbox
|
|
|
4c79b5 |
if ($profile_row['field_length'] == 2)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$var = (isset($_REQUEST[$var_name])) ? 1 : 0;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$var = request_var($var_name, (int) $profile_row['field_default_value']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case FIELD_STRING:
|
|
|
4c79b5 |
case FIELD_TEXT:
|
|
|
4c79b5 |
$var = utf8_normalize_nfc(request_var($var_name, (string) $profile_row['field_default_value'], true));
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case FIELD_INT:
|
|
|
4c79b5 |
if (isset($_REQUEST[$var_name]) && $_REQUEST[$var_name] === '')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$var = NULL;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$var = request_var($var_name, (int) $profile_row['field_default_value']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case FIELD_DROPDOWN:
|
|
|
4c79b5 |
$var = request_var($var_name, (int) $profile_row['field_default_value']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
default:
|
|
|
4c79b5 |
$var = request_var($var_name, $profile_row['field_default_value']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $var;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Custom Profile Fields ACP
|
|
|
4c79b5 |
* @package phpBB3
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
class custom_profile_admin extends custom_profile
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var $vars = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Return possible validation options
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function validate_options()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$validate_ary = array('CHARS_ANY' => '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$validate_options = '';
|
|
|
4c79b5 |
foreach ($validate_ary as $lang => $value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$selected = ($this->vars['field_validation'] == $value) ? ' selected="selected"' : '';
|
|
|
4c79b5 |
$validate_options .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$lang] . '</option>';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $validate_options;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get string options for second step in ACP
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function get_string_options()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$options = array(
|
|
|
4c79b5 |
0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'),
|
|
|
4c79b5 |
1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'),
|
|
|
4c79b5 |
2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'),
|
|
|
4c79b5 |
3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $options;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get text options for second step in ACP
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function get_text_options()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$options = array(
|
|
|
4c79b5 |
0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input name="rows" size="5" value="' . $this->vars['rows'] . '" /> ' . $user->lang['ROWS'] . '<input name="columns" size="5" value="' . $this->vars['columns'] . '" /> ' . $user->lang['COLUMNS'] . ' <input type="hidden" name="field_length" value="' . $this->vars['field_length'] . '" />'),
|
|
|
4c79b5 |
1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="10" value="' . $this->vars['field_minlen'] . '" />'),
|
|
|
4c79b5 |
2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="10" value="' . $this->vars['field_maxlen'] . '" />'),
|
|
|
4c79b5 |
3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $options;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get int options for second step in ACP
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function get_int_options()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$options = array(
|
|
|
4c79b5 |
0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'),
|
|
|
4c79b5 |
1 => array('TITLE' => $user->lang['MIN_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'),
|
|
|
4c79b5 |
2 => array('TITLE' => $user->lang['MAX_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'),
|
|
|
4c79b5 |
3 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => '<input type="post" name="field_default_value" value="' . $this->vars['field_default_value'] . '" />')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $options;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get bool options for second step in ACP
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function get_bool_options()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user, $config, $lang_defs;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$default_lang_id = $lang_defs['iso'][$config['default_lang']];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row = array(
|
|
|
4c79b5 |
'var_name' => 'field_default_value',
|
|
|
4c79b5 |
'field_id' => 1,
|
|
|
4c79b5 |
'lang_name' => $this->vars['lang_name'],
|
|
|
4c79b5 |
'lang_explain' => $this->vars['lang_explain'],
|
|
|
4c79b5 |
'lang_id' => $default_lang_id,
|
|
|
4c79b5 |
'field_default_value' => $this->vars['field_default_value'],
|
|
|
4c79b5 |
'field_ident' => 'field_default_value',
|
|
|
4c79b5 |
'field_type' => FIELD_BOOL,
|
|
|
4c79b5 |
'field_length' => $this->vars['field_length'],
|
|
|
4c79b5 |
'lang_options' => $this->vars['lang_options']
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$options = array(
|
|
|
4c79b5 |
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>'),
|
|
|
4c79b5 |
1 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row))
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $options;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get dropdown options for second step in ACP
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function get_dropdown_options()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user, $config, $lang_defs;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$default_lang_id = $lang_defs['iso'][$config['default_lang']];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row[0] = array(
|
|
|
4c79b5 |
'var_name' => 'field_default_value',
|
|
|
4c79b5 |
'field_id' => 1,
|
|
|
4c79b5 |
'lang_name' => $this->vars['lang_name'],
|
|
|
4c79b5 |
'lang_explain' => $this->vars['lang_explain'],
|
|
|
4c79b5 |
'lang_id' => $default_lang_id,
|
|
|
4c79b5 |
'field_default_value' => $this->vars['field_default_value'],
|
|
|
4c79b5 |
'field_ident' => 'field_default_value',
|
|
|
4c79b5 |
'field_type' => FIELD_DROPDOWN,
|
|
|
4c79b5 |
'lang_options' => $this->vars['lang_options']
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row[1] = $profile_row[0];
|
|
|
4c79b5 |
$profile_row[1]['var_name'] = 'field_novalue';
|
|
|
4c79b5 |
$profile_row[1]['field_ident'] = 'field_novalue';
|
|
|
4c79b5 |
$profile_row[1]['field_default_value'] = $this->vars['field_novalue'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$options = array(
|
|
|
4c79b5 |
0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row[0])),
|
|
|
4c79b5 |
1 => array('TITLE' => $user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->process_field_row('preview', $profile_row[1]))
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $options;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get date options for second step in ACP
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function get_date_options()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user, $config, $lang_defs;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$default_lang_id = $lang_defs['iso'][$config['default_lang']];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$profile_row = array(
|
|
|
4c79b5 |
'var_name' => 'field_default_value',
|
|
|
4c79b5 |
'lang_name' => $this->vars['lang_name'],
|
|
|
4c79b5 |
'lang_explain' => $this->vars['lang_explain'],
|
|
|
4c79b5 |
'lang_id' => $default_lang_id,
|
|
|
4c79b5 |
'field_default_value' => $this->vars['field_default_value'],
|
|
|
4c79b5 |
'field_ident' => 'field_default_value',
|
|
|
4c79b5 |
'field_type' => FIELD_DATE,
|
|
|
4c79b5 |
'field_length' => $this->vars['field_length']
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$always_now = request_var('always_now', -1);
|
|
|
4c79b5 |
if ($always_now == -1)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$s_checked = ($this->vars['field_default_value'] == 'now') ? true : false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$s_checked = ($always_now) ? true : false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$options = array(
|
|
|
4c79b5 |
0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)),
|
|
|
4c79b5 |
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>'),
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $options;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|