includes/functions_profile_fields.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/functions_profile_fields.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,1162 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package phpBB3
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2005 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +* @ignore
    1.16 +*/
    1.17 +if (!defined('IN_PHPBB'))
    1.18 +{
    1.19 +	exit;
    1.20 +}
    1.21 +
    1.22 +/**
    1.23 +* Custom Profile Fields
    1.24 +* @package phpBB3
    1.25 +*/
    1.26 +class custom_profile
    1.27 +{
    1.28 +	var $profile_types = array(FIELD_INT => 'int', FIELD_STRING => 'string', FIELD_TEXT => 'text', FIELD_BOOL => 'bool', FIELD_DROPDOWN => 'dropdown', FIELD_DATE => 'date');
    1.29 +	var $profile_cache = array();
    1.30 +	var $options_lang = array();
    1.31 +
    1.32 +	/**
    1.33 +	* Assign editable fields to template, mode can be profile (for profile change) or register (for registration)
    1.34 +	* Called by ucp_profile and ucp_register
    1.35 +	* @access public
    1.36 +	*/
    1.37 +	function generate_profile_fields($mode, $lang_id)
    1.38 +	{
    1.39 +		global $db, $template, $auth;
    1.40 +
    1.41 +		$sql_where = '';
    1.42 +		switch ($mode)
    1.43 +		{
    1.44 +			case 'register':
    1.45 +				// If the field is required we show it on the registration page
    1.46 +				$sql_where .= ' AND f.field_show_on_reg = 1';
    1.47 +			break;
    1.48 +
    1.49 +			case 'profile':
    1.50 +				// Show hidden fields to moderators/admins
    1.51 +				if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
    1.52 +				{
    1.53 +					$sql_where .= ' AND f.field_show_profile = 1';
    1.54 +				}
    1.55 +			break;
    1.56 +
    1.57 +			default:
    1.58 +				trigger_error('Wrong profile mode specified', E_USER_ERROR);
    1.59 +			break;
    1.60 +		}
    1.61 +
    1.62 +		$sql = 'SELECT l.*, f.*
    1.63 +			FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f
    1.64 +			WHERE f.field_active = 1
    1.65 +				$sql_where
    1.66 +				AND l.lang_id = $lang_id
    1.67 +				AND l.field_id = f.field_id
    1.68 +			ORDER BY f.field_order";
    1.69 +		$result = $db->sql_query($sql);
    1.70 +
    1.71 +		while ($row = $db->sql_fetchrow($result))
    1.72 +		{
    1.73 +			// Return templated field
    1.74 +			$tpl_snippet = $this->process_field_row('change', $row);
    1.75 +
    1.76 +			// Some types are multivalue, we can't give them a field_id as we would not know which to pick
    1.77 +			$type = (int) $row['field_type'];
    1.78 +
    1.79 +			$template->assign_block_vars('profile_fields', array(
    1.80 +				'LANG_NAME'		=> $row['lang_name'],
    1.81 +				'LANG_EXPLAIN'	=> $row['lang_explain'],
    1.82 +				'FIELD'			=> $tpl_snippet,
    1.83 +				'FIELD_ID'		=> ($type == FIELD_DATE || ($type == FIELD_BOOL && $row['field_length'] == '1')) ? '' : 'pf_' . $row['field_ident'],
    1.84 +				'S_REQUIRED'	=> ($row['field_required']) ? true : false)
    1.85 +			);
    1.86 +		}
    1.87 +		$db->sql_freeresult($result);
    1.88 +	}
    1.89 +
    1.90 +	/**
    1.91 +	* Validate entered profile field data
    1.92 +	* @access public
    1.93 +	*/
    1.94 +	function validate_profile_field($field_type, &$field_value, $field_data)
    1.95 +	{
    1.96 +		switch ($field_type)
    1.97 +		{
    1.98 +			case FIELD_DATE:
    1.99 +				$field_validate = explode('-', $field_value);
   1.100 +
   1.101 +				$day = (isset($field_validate[0])) ? (int) $field_validate[0] : 0;
   1.102 +				$month = (isset($field_validate[1])) ? (int) $field_validate[1] : 0;
   1.103 +				$year = (isset($field_validate[2])) ? (int) $field_validate[2] : 0;
   1.104 +
   1.105 +				if ((!$day || !$month || !$year) && !$field_data['field_required'])
   1.106 +				{
   1.107 +					return false;
   1.108 +				}
   1.109 +
   1.110 +				if ((!$day || !$month || !$year) && $field_data['field_required'])
   1.111 +				{
   1.112 +					return 'FIELD_REQUIRED';
   1.113 +				}
   1.114 +
   1.115 +				if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50)
   1.116 +				{
   1.117 +					return 'FIELD_INVALID_DATE';
   1.118 +				}
   1.119 +
   1.120 +				if (checkdate($month, $day, $year) === false)
   1.121 +				{
   1.122 +					return 'FIELD_INVALID_DATE';
   1.123 +				}
   1.124 +			break;
   1.125 +
   1.126 +			case FIELD_BOOL:
   1.127 +				$field_value = (bool) $field_value;
   1.128 +			
   1.129 +				if (!$field_value && $field_data['field_required'])
   1.130 +				{
   1.131 +					return 'FIELD_REQUIRED';
   1.132 +				}
   1.133 +			break;
   1.134 +
   1.135 +			case FIELD_INT:
   1.136 +				if (trim($field_value) === '' && !$field_data['field_required'])
   1.137 +				{
   1.138 +					return false;
   1.139 +				}
   1.140 +				
   1.141 +				$field_value = (int) $field_value;
   1.142 +
   1.143 +				if ($field_value < $field_data['field_minlen'])
   1.144 +				{
   1.145 +					return 'FIELD_TOO_SMALL';
   1.146 +				}
   1.147 +				else if ($field_value > $field_data['field_maxlen'])
   1.148 +				{
   1.149 +					return 'FIELD_TOO_LARGE';
   1.150 +				}
   1.151 +			break;
   1.152 +
   1.153 +			case FIELD_DROPDOWN:
   1.154 +				$field_value = (int) $field_value;
   1.155 +
   1.156 +				// retrieve option lang data if necessary
   1.157 +				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']]))
   1.158 +				{
   1.159 +					$this->get_option_lang($field_data['field_id'], $field_data['lang_id'], FIELD_DROPDOWN, false);
   1.160 +				}
   1.161 +
   1.162 +				if (!isset($this->options_lang[$field_data['field_id']][$field_data['lang_id']][$field_value]))
   1.163 +				{
   1.164 +					return 'FIELD_INVALID_VALUE';
   1.165 +				}
   1.166 +
   1.167 +				if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
   1.168 +				{
   1.169 +					return 'FIELD_REQUIRED';
   1.170 +				}
   1.171 +			break;
   1.172 +
   1.173 +			case FIELD_STRING:
   1.174 +			case FIELD_TEXT:
   1.175 +				if (trim($field_value) === '' && !$field_data['field_required'])
   1.176 +				{
   1.177 +					return false;
   1.178 +				}
   1.179 +				else if (trim($field_value) === '' && $field_data['field_required'])
   1.180 +				{
   1.181 +					return 'FIELD_REQUIRED';
   1.182 +				}
   1.183 +
   1.184 +				if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen'])
   1.185 +				{
   1.186 +					return 'FIELD_TOO_SHORT';
   1.187 +				}
   1.188 +				else if ($field_data['field_maxlen'] && utf8_strlen($field_value) > $field_data['field_maxlen'])
   1.189 +				{
   1.190 +					return 'FIELD_TOO_LONG';
   1.191 +				}
   1.192 +
   1.193 +				if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*')
   1.194 +				{
   1.195 +					$field_validate = ($field_type == FIELD_STRING) ? $field_value : bbcode_nl2br($field_value);
   1.196 +					if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate))
   1.197 +					{
   1.198 +						return 'FIELD_INVALID_CHARS';
   1.199 +					}
   1.200 +				}
   1.201 +			break;
   1.202 +		}
   1.203 +
   1.204 +		return false;
   1.205 +	}
   1.206 +
   1.207 +	/**
   1.208 +	* Build profile cache, used for display
   1.209 +	* @access private
   1.210 +	*/
   1.211 +	function build_cache()
   1.212 +	{
   1.213 +		global $db, $user, $auth;
   1.214 +
   1.215 +		$this->profile_cache = array();
   1.216 +
   1.217 +		// Display hidden/no_view fields for admin/moderator
   1.218 +		$sql = 'SELECT l.*, f.*
   1.219 +			FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
   1.220 +			WHERE l.lang_id = ' . $user->get_iso_lang_id() . '
   1.221 +				AND f.field_active = 1 ' .
   1.222 +				((!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) ? '	AND f.field_hide = 0 ' : '') . '
   1.223 +				AND f.field_no_view = 0
   1.224 +				AND l.field_id = f.field_id
   1.225 +			ORDER BY f.field_order';
   1.226 +		$result = $db->sql_query($sql);
   1.227 +
   1.228 +		while ($row = $db->sql_fetchrow($result))
   1.229 +		{
   1.230 +			$this->profile_cache[$row['field_ident']] = $row;
   1.231 +		}
   1.232 +		$db->sql_freeresult($result);
   1.233 +	}
   1.234 +
   1.235 +	/**
   1.236 +	* Get language entries for options and store them here for later use
   1.237 +	*/
   1.238 +	function get_option_lang($field_id, $lang_id, $field_type, $preview)
   1.239 +	{
   1.240 +		global $db;
   1.241 +
   1.242 +		if ($preview)
   1.243 +		{
   1.244 +			$lang_options = (!is_array($this->vars['lang_options'])) ? explode("\n", $this->vars['lang_options']) : $this->vars['lang_options'];
   1.245 +
   1.246 +			foreach ($lang_options as $num => $var)
   1.247 +			{
   1.248 +				$this->options_lang[$field_id][$lang_id][($num + 1)] = $var;
   1.249 +			}
   1.250 +		}
   1.251 +		else
   1.252 +		{
   1.253 +			$sql = 'SELECT option_id, lang_value
   1.254 +				FROM ' . PROFILE_FIELDS_LANG_TABLE . "
   1.255 +					WHERE field_id = $field_id
   1.256 +					AND lang_id = $lang_id
   1.257 +					AND field_type = $field_type
   1.258 +				ORDER BY option_id";
   1.259 +			$result = $db->sql_query($sql);
   1.260 +
   1.261 +			while ($row = $db->sql_fetchrow($result))
   1.262 +			{
   1.263 +				$this->options_lang[$field_id][$lang_id][($row['option_id'] + 1)] = $row['lang_value'];
   1.264 +			}
   1.265 +			$db->sql_freeresult($result);
   1.266 +		}
   1.267 +	}
   1.268 +
   1.269 +	/**
   1.270 +	* Submit profile field for validation
   1.271 +	* @access public
   1.272 +	*/
   1.273 +	function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error)
   1.274 +	{
   1.275 +		global $auth, $db, $user;
   1.276 +
   1.277 +		$sql_where = '';
   1.278 +		switch ($mode)
   1.279 +		{
   1.280 +			case 'register':
   1.281 +				// If the field is required we show it on the registration page
   1.282 +				$sql_where .= ' AND f.field_show_on_reg = 1';
   1.283 +			break;
   1.284 +
   1.285 +			case 'profile':
   1.286 +				// Show hidden fields to moderators/admins
   1.287 +				if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
   1.288 +				{
   1.289 +					$sql_where .= ' AND f.field_show_profile = 1';
   1.290 +				}
   1.291 +			break;
   1.292 +
   1.293 +			default:
   1.294 +				trigger_error('Wrong profile mode specified', E_USER_ERROR);
   1.295 +			break;
   1.296 +		}
   1.297 +
   1.298 +		$sql = 'SELECT l.*, f.*
   1.299 +			FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f
   1.300 +			WHERE l.lang_id = $lang_id
   1.301 +				AND f.field_active = 1
   1.302 +				$sql_where
   1.303 +				AND l.field_id = f.field_id
   1.304 +			ORDER BY f.field_order";
   1.305 +		$result = $db->sql_query($sql);
   1.306 +
   1.307 +		while ($row = $db->sql_fetchrow($result))
   1.308 +		{
   1.309 +			$cp_data['pf_' . $row['field_ident']] = $this->get_profile_field($row);
   1.310 +			$check_value = $cp_data['pf_' . $row['field_ident']];
   1.311 +
   1.312 +			if (($cp_result = $this->validate_profile_field($row['field_type'], $check_value, $row)) !== false)
   1.313 +			{
   1.314 +				// If not and only showing common error messages, use this one
   1.315 +				$error = '';
   1.316 +				switch ($cp_result)
   1.317 +				{
   1.318 +					case 'FIELD_INVALID_DATE':
   1.319 +					case 'FIELD_INVALID_VALUE':
   1.320 +					case 'FIELD_REQUIRED':
   1.321 +						$error = sprintf($user->lang[$cp_result], $row['lang_name']);
   1.322 +					break;
   1.323 +
   1.324 +					case 'FIELD_TOO_SHORT':
   1.325 +					case 'FIELD_TOO_SMALL':
   1.326 +						$error = sprintf($user->lang[$cp_result], $row['lang_name'], $row['field_minlen']);
   1.327 +					break;
   1.328 +
   1.329 +					case 'FIELD_TOO_LONG':
   1.330 +					case 'FIELD_TOO_LARGE':
   1.331 +						$error = sprintf($user->lang[$cp_result], $row['lang_name'], $row['field_maxlen']);
   1.332 +					break;
   1.333 +
   1.334 +					case 'FIELD_INVALID_CHARS':
   1.335 +						switch ($row['field_validation'])
   1.336 +						{
   1.337 +							case '[0-9]+':
   1.338 +								$error = sprintf($user->lang[$cp_result . '_NUMBERS_ONLY'], $row['lang_name']);
   1.339 +							break;
   1.340 +
   1.341 +							case '[\w]+':
   1.342 +								$error = sprintf($user->lang[$cp_result . '_ALPHA_ONLY'], $row['lang_name']);
   1.343 +							break;
   1.344 +
   1.345 +							case '[\w_\+\. \-\[\]]+':
   1.346 +								$error = sprintf($user->lang[$cp_result . '_SPACERS_ONLY'], $row['lang_name']);
   1.347 +							break;
   1.348 +						}
   1.349 +					break;
   1.350 +				}
   1.351 +
   1.352 +				if ($error != '')
   1.353 +				{
   1.354 +					$cp_error[] = $error;
   1.355 +				}
   1.356 +			}
   1.357 +		}
   1.358 +		$db->sql_freeresult($result);
   1.359 +	}
   1.360 +
   1.361 +	/**
   1.362 +	* Update profile field data directly
   1.363 +	*/
   1.364 +	function update_profile_field_data($user_id, &$cp_data)
   1.365 +	{
   1.366 +		global $db;
   1.367 +
   1.368 +		if (!sizeof($cp_data))
   1.369 +		{
   1.370 +			return;
   1.371 +		}
   1.372 +
   1.373 +		switch ($db->sql_layer)
   1.374 +		{
   1.375 +			case 'oracle':
   1.376 +			case 'firebird':
   1.377 +			case 'postgres':
   1.378 +				$right_delim = $left_delim = '"';
   1.379 +			break;
   1.380 +
   1.381 +			case 'sqlite':
   1.382 +			case 'mssql':
   1.383 +			case 'mssql_odbc':
   1.384 +			case 'mssqlnative':
   1.385 +				$right_delim = ']';
   1.386 +				$left_delim = '[';
   1.387 +			break;
   1.388 +
   1.389 +			case 'mysql':
   1.390 +			case 'mysql4':
   1.391 +			case 'mysqli':
   1.392 +				$right_delim = $left_delim = '`';
   1.393 +			break;
   1.394 +		}
   1.395 +
   1.396 +		// use new array for the UPDATE; changes in the key do not affect the original array
   1.397 +		$cp_data_sql = array();
   1.398 +		foreach ($cp_data as $key => $value)
   1.399 +		{
   1.400 +			// Firebird is case sensitive with delimiter
   1.401 +			$cp_data_sql[$left_delim . (($db->sql_layer == 'firebird' || $db->sql_layer == 'oracle') ? strtoupper($key) : $key) . $right_delim] = $value;
   1.402 +		}
   1.403 +
   1.404 +		$sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
   1.405 +			SET ' . $db->sql_build_array('UPDATE', $cp_data_sql) . "
   1.406 +			WHERE user_id = $user_id";
   1.407 +		$db->sql_query($sql);
   1.408 +
   1.409 +		if (!$db->sql_affectedrows())
   1.410 +		{
   1.411 +			$cp_data_sql['user_id'] = (int) $user_id;
   1.412 +
   1.413 +			$db->sql_return_on_error(true);
   1.414 +
   1.415 +			$sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data_sql);
   1.416 +			$db->sql_query($sql);
   1.417 +
   1.418 +			$db->sql_return_on_error(false);
   1.419 +		}
   1.420 +	}
   1.421 +
   1.422 +	/**
   1.423 +	* Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled)
   1.424 +	* 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
   1.425 +	* @access public
   1.426 +	*/
   1.427 +	function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false)
   1.428 +	{
   1.429 +		global $db;
   1.430 +
   1.431 +		if ($mode == 'grab')
   1.432 +		{
   1.433 +			if (!is_array($user_id))
   1.434 +			{
   1.435 +				$user_id = array($user_id);
   1.436 +			}
   1.437 +
   1.438 +			if (!sizeof($this->profile_cache))
   1.439 +			{
   1.440 +				$this->build_cache();
   1.441 +			}
   1.442 +
   1.443 +			if (!sizeof($user_id))
   1.444 +			{
   1.445 +				return array();
   1.446 +			}
   1.447 +
   1.448 +			$sql = 'SELECT *
   1.449 +				FROM ' . PROFILE_FIELDS_DATA_TABLE . '
   1.450 +				WHERE ' . $db->sql_in_set('user_id', array_map('intval', $user_id));
   1.451 +			$result = $db->sql_query($sql);
   1.452 +
   1.453 +			$field_data = array();
   1.454 +			while ($row = $db->sql_fetchrow($result))
   1.455 +			{
   1.456 +				$field_data[$row['user_id']] = $row;
   1.457 +			}
   1.458 +			$db->sql_freeresult($result);
   1.459 +
   1.460 +			$user_fields = array();
   1.461 +
   1.462 +			// Go through the fields in correct order
   1.463 +			foreach (array_keys($this->profile_cache) as $used_ident)
   1.464 +			{
   1.465 +				foreach ($field_data as $user_id => $row)
   1.466 +				{
   1.467 +					$user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
   1.468 +					$user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];
   1.469 +				}
   1.470 +			}
   1.471 +
   1.472 +			return $user_fields;
   1.473 +		}
   1.474 +		else if ($mode == 'show')
   1.475 +		{
   1.476 +			// $profile_row == $user_fields[$row['user_id']];
   1.477 +			$tpl_fields = array();
   1.478 +			$tpl_fields['row'] = $tpl_fields['blockrow'] = array();
   1.479 +
   1.480 +			foreach ($profile_row as $ident => $ident_ary)
   1.481 +			{
   1.482 +				$value = $this->get_profile_value($ident_ary);
   1.483 +
   1.484 +				if ($value === NULL)
   1.485 +				{
   1.486 +					continue;
   1.487 +				}
   1.488 +
   1.489 +				$tpl_fields['row'] += array(
   1.490 +					'PROFILE_' . strtoupper($ident) . '_VALUE'	=> $value,
   1.491 +					'PROFILE_' . strtoupper($ident) . '_TYPE'	=> $ident_ary['data']['field_type'],
   1.492 +					'PROFILE_' . strtoupper($ident) . '_NAME'	=> $ident_ary['data']['lang_name'],
   1.493 +					'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $ident_ary['data']['lang_explain'],
   1.494 +
   1.495 +					'S_PROFILE_' . strtoupper($ident)			=> true
   1.496 +				);
   1.497 +
   1.498 +				$tpl_fields['blockrow'][] = array(
   1.499 +					'PROFILE_FIELD_VALUE'	=> $value,
   1.500 +					'PROFILE_FIELD_TYPE'	=> $ident_ary['data']['field_type'],
   1.501 +					'PROFILE_FIELD_NAME'	=> $ident_ary['data']['lang_name'],
   1.502 +					'PROFILE_FIELD_EXPLAIN'	=> $ident_ary['data']['lang_explain'],
   1.503 +
   1.504 +					'S_PROFILE_' . strtoupper($ident)		=> true
   1.505 +				);
   1.506 +			}
   1.507 +
   1.508 +			return $tpl_fields;
   1.509 +		}
   1.510 +		else
   1.511 +		{
   1.512 +			trigger_error('Wrong mode for custom profile', E_USER_ERROR);
   1.513 +		}
   1.514 +	}
   1.515 +
   1.516 +	/**
   1.517 +	* Get Profile Value for display
   1.518 +	*/
   1.519 +	function get_profile_value($ident_ary)
   1.520 +	{
   1.521 +		$value = $ident_ary['value'];
   1.522 +		$field_type = $ident_ary['data']['field_type'];
   1.523 +
   1.524 +		switch ($this->profile_types[$field_type])
   1.525 +		{
   1.526 +			case 'int':
   1.527 +				if ($value === '')
   1.528 +				{
   1.529 +					return NULL;
   1.530 +				}
   1.531 +				return (int) $value;
   1.532 +			break;
   1.533 +
   1.534 +			case 'string':
   1.535 +			case 'text':
   1.536 +				if (!$value)
   1.537 +				{
   1.538 +					return NULL;
   1.539 +				}
   1.540 +
   1.541 +				$value = make_clickable($value);
   1.542 +				$value = censor_text($value);
   1.543 +				$value = bbcode_nl2br($value);
   1.544 +				return $value;
   1.545 +			break;
   1.546 +
   1.547 +			// case 'datetime':
   1.548 +			case 'date':
   1.549 +				$date = explode('-', $value);
   1.550 +				$day = (isset($date[0])) ? (int) $date[0] : 0;
   1.551 +				$month = (isset($date[1])) ? (int) $date[1] : 0;
   1.552 +				$year = (isset($date[2])) ? (int) $date[2] : 0;
   1.553 +
   1.554 +				if (!$day && !$month && !$year)
   1.555 +				{
   1.556 +					return NULL;
   1.557 +				}
   1.558 +				else if ($day && $month && $year)
   1.559 +				{
   1.560 +					global $user;
   1.561 +					// Date should display as the same date for every user regardless of timezone, so remove offset
   1.562 +					// to compensate for the offset added by user::format_date()
   1.563 +					return $user->format_date(gmmktime(0, 0, 0, $month, $day, $year) - ($user->timezone + $user->dst), $user->lang['DATE_FORMAT'], true);
   1.564 +				}
   1.565 +
   1.566 +				return $value;
   1.567 +			break;
   1.568 +
   1.569 +			case 'dropdown':
   1.570 +				$field_id = $ident_ary['data']['field_id'];
   1.571 +				$lang_id = $ident_ary['data']['lang_id'];
   1.572 +				if (!isset($this->options_lang[$field_id][$lang_id]))
   1.573 +				{
   1.574 +					$this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false);
   1.575 +				}
   1.576 +
   1.577 +				if ($value == $ident_ary['data']['field_novalue'])
   1.578 +				{
   1.579 +					return NULL;
   1.580 +				}
   1.581 +
   1.582 +				$value = (int) $value;
   1.583 +
   1.584 +				// User not having a value assigned
   1.585 +				if (!isset($this->options_lang[$field_id][$lang_id][$value]))
   1.586 +				{
   1.587 +					return NULL;
   1.588 +				}
   1.589 +
   1.590 +				return $this->options_lang[$field_id][$lang_id][$value];
   1.591 +			break;
   1.592 +
   1.593 +			case 'bool':
   1.594 +				$field_id = $ident_ary['data']['field_id'];
   1.595 +				$lang_id = $ident_ary['data']['lang_id'];
   1.596 +				if (!isset($this->options_lang[$field_id][$lang_id]))
   1.597 +				{
   1.598 +					$this->get_option_lang($field_id, $lang_id, FIELD_BOOL, false);
   1.599 +				}
   1.600 +
   1.601 +				if ($ident_ary['data']['field_length'] == 1)
   1.602 +				{
   1.603 +					return (isset($this->options_lang[$field_id][$lang_id][(int) $value])) ? $this->options_lang[$field_id][$lang_id][(int) $value] : NULL;
   1.604 +				}
   1.605 +				else if (!$value)
   1.606 +				{
   1.607 +					return NULL;
   1.608 +				}
   1.609 +				else
   1.610 +				{
   1.611 +					return $this->options_lang[$field_id][$lang_id][(int) ($value) + 1];
   1.612 +				}
   1.613 +			break;
   1.614 +
   1.615 +			default:
   1.616 +				trigger_error('Unknown profile type', E_USER_ERROR);
   1.617 +			break;
   1.618 +		}
   1.619 +	}
   1.620 +
   1.621 +	/**
   1.622 +	* Get field value for registration/profile
   1.623 +	* @access private
   1.624 +	*/
   1.625 +	function get_var($field_validation, &$profile_row, $default_value, $preview)
   1.626 +	{
   1.627 +		global $user;
   1.628 +
   1.629 +		$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
   1.630 +		$user_ident = $profile_row['field_ident'];
   1.631 +		// checkbox - only testing for isset
   1.632 +		if ($profile_row['field_type'] == FIELD_BOOL && $profile_row['field_length'] == 2)
   1.633 +		{
   1.634 +			$value = (isset($_REQUEST[$profile_row['field_ident']])) ? true : ((!isset($user->profile_fields[$user_ident]) || $preview) ? $default_value : $user->profile_fields[$user_ident]);
   1.635 +		}
   1.636 +		else if ($profile_row['field_type'] == FIELD_INT)
   1.637 +		{
   1.638 +			if (isset($_REQUEST[$profile_row['field_ident']]))
   1.639 +			{
   1.640 +				$value = ($_REQUEST[$profile_row['field_ident']] === '') ? NULL : request_var($profile_row['field_ident'], $default_value);
   1.641 +			}
   1.642 +			else
   1.643 +			{
   1.644 +				if (!$preview && array_key_exists($user_ident, $user->profile_fields) && is_null($user->profile_fields[$user_ident]))
   1.645 +				{
   1.646 +					$value = NULL;
   1.647 +				}
   1.648 +				else if (!isset($user->profile_fields[$user_ident]) || $preview)
   1.649 +				{
   1.650 +					$value = $default_value;
   1.651 +				}
   1.652 +				else
   1.653 +				{
   1.654 +					$value = $user->profile_fields[$user_ident];
   1.655 +				}
   1.656 +			}
   1.657 +
   1.658 +			return (is_null($value) || $value === '') ? '' : (int) $value;
   1.659 +		}
   1.660 +		else
   1.661 +		{
   1.662 +			$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]);
   1.663 +
   1.664 +			if (gettype($value) == 'string')
   1.665 +			{
   1.666 +				$value = utf8_normalize_nfc($value);
   1.667 +			}
   1.668 +		}
   1.669 +
   1.670 +		switch ($field_validation)
   1.671 +		{
   1.672 +			case 'int':
   1.673 +				return (int) $value;
   1.674 +			break;
   1.675 +		}
   1.676 +
   1.677 +		return $value;
   1.678 +	}
   1.679 +
   1.680 +	/**
   1.681 +	* Process int-type
   1.682 +	* @access private
   1.683 +	*/
   1.684 +	function generate_int($profile_row, $preview = false)
   1.685 +	{
   1.686 +		global $template;
   1.687 +
   1.688 +		$profile_row['field_value'] = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
   1.689 +		$template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
   1.690 +	}
   1.691 +
   1.692 +	/**
   1.693 +	* Process date-type
   1.694 +	* @access private
   1.695 +	*/
   1.696 +	function generate_date($profile_row, $preview = false)
   1.697 +	{
   1.698 +		global $user, $template;
   1.699 +
   1.700 +		$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
   1.701 +		$user_ident = $profile_row['field_ident'];
   1.702 +
   1.703 +		$now = getdate();
   1.704 +
   1.705 +		if (!isset($_REQUEST[$profile_row['field_ident'] . '_day']))
   1.706 +		{
   1.707 +			if ($profile_row['field_default_value'] == 'now')
   1.708 +			{
   1.709 +				$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
   1.710 +			}
   1.711 +			list($day, $month, $year) = explode('-', ((!isset($user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $user->profile_fields[$user_ident]));
   1.712 +		}
   1.713 +		else
   1.714 +		{
   1.715 +			if ($preview && $profile_row['field_default_value'] == 'now')
   1.716 +			{
   1.717 +				$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
   1.718 +				list($day, $month, $year) = explode('-', ((!isset($user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $user->profile_fields[$user_ident]));
   1.719 +			}
   1.720 +			else
   1.721 +			{
   1.722 +				$day = request_var($profile_row['field_ident'] . '_day', 0);
   1.723 +				$month = request_var($profile_row['field_ident'] . '_month', 0);
   1.724 +				$year = request_var($profile_row['field_ident'] . '_year', 0);
   1.725 +			}
   1.726 +		}
   1.727 +
   1.728 +		$profile_row['s_day_options'] = '<option value="0"' . ((!$day) ? ' selected="selected"' : '') . '>--</option>';
   1.729 +		for ($i = 1; $i < 32; $i++)
   1.730 +		{
   1.731 +			$profile_row['s_day_options'] .= '<option value="' . $i . '"' . (($i == $day) ? ' selected="selected"' : '') . ">$i</option>";
   1.732 +		}
   1.733 +
   1.734 +		$profile_row['s_month_options'] = '<option value="0"' . ((!$month) ? ' selected="selected"' : '') . '>--</option>';
   1.735 +		for ($i = 1; $i < 13; $i++)
   1.736 +		{
   1.737 +			$profile_row['s_month_options'] .= '<option value="' . $i . '"' . (($i == $month) ? ' selected="selected"' : '') . ">$i</option>";
   1.738 +		}
   1.739 +
   1.740 +		$profile_row['s_year_options'] = '<option value="0"' . ((!$year) ? ' selected="selected"' : '') . '>--</option>';
   1.741 +		for ($i = $now['year'] - 100; $i <= $now['year'] + 100; $i++)
   1.742 +		{
   1.743 +			$profile_row['s_year_options'] .= '<option value="' . $i . '"' . (($i == $year) ? ' selected="selected"' : '') . ">$i</option>";
   1.744 +		}
   1.745 +		unset($now);
   1.746 +
   1.747 +		$profile_row['field_value'] = 0;
   1.748 +		$template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
   1.749 +	}
   1.750 +
   1.751 +	/**
   1.752 +	* Process bool-type
   1.753 +	* @access private
   1.754 +	*/
   1.755 +	function generate_bool($profile_row, $preview = false)
   1.756 +	{
   1.757 +		global $template;
   1.758 +
   1.759 +		$value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
   1.760 +
   1.761 +		$profile_row['field_value'] = $value;
   1.762 +		$template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
   1.763 +
   1.764 +		if ($profile_row['field_length'] == 1)
   1.765 +		{
   1.766 +			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']]))
   1.767 +			{
   1.768 +				$this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview);
   1.769 +			}
   1.770 +
   1.771 +			foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
   1.772 +			{
   1.773 +				$template->assign_block_vars('bool.options', array(
   1.774 +					'OPTION_ID'	=> $option_id,
   1.775 +					'CHECKED'	=> ($value == $option_id) ? ' checked="checked"' : '',
   1.776 +					'VALUE'		=> $option_value)
   1.777 +				);
   1.778 +			}
   1.779 +		}
   1.780 +	}
   1.781 +
   1.782 +	/**
   1.783 +	* Process string-type
   1.784 +	* @access private
   1.785 +	*/
   1.786 +	function generate_string($profile_row, $preview = false)
   1.787 +	{
   1.788 +		global $template;
   1.789 +
   1.790 +		$profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview);
   1.791 +		$template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
   1.792 +	}
   1.793 +
   1.794 +	/**
   1.795 +	* Process text-type
   1.796 +	* @access private
   1.797 +	*/
   1.798 +	function generate_text($profile_row, $preview = false)
   1.799 +	{
   1.800 +		global $template;
   1.801 +		global $user, $phpEx, $phpbb_root_path;
   1.802 +
   1.803 +		$field_length = explode('|', $profile_row['field_length']);
   1.804 +		$profile_row['field_rows'] = $field_length[0];
   1.805 +		$profile_row['field_cols'] = $field_length[1];
   1.806 +
   1.807 +		$profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview);
   1.808 +		$template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
   1.809 +	}
   1.810 +
   1.811 +	/**
   1.812 +	* Process dropdown-type
   1.813 +	* @access private
   1.814 +	*/
   1.815 +	function generate_dropdown($profile_row, $preview = false)
   1.816 +	{
   1.817 +		global $user, $template;
   1.818 +
   1.819 +		$value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
   1.820 +
   1.821 +		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']]))
   1.822 +		{
   1.823 +			$this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview);
   1.824 +		}
   1.825 +
   1.826 +		$profile_row['field_value'] = $value;
   1.827 +		$template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
   1.828 +
   1.829 +		foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
   1.830 +		{
   1.831 +			$template->assign_block_vars('dropdown.options', array(
   1.832 +				'OPTION_ID'	=> $option_id,
   1.833 +				'SELECTED'	=> ($value == $option_id) ? ' selected="selected"' : '',
   1.834 +				'VALUE'		=> $option_value)
   1.835 +			);
   1.836 +		}
   1.837 +	}
   1.838 +
   1.839 +	/**
   1.840 +	* Return Templated value/field. Possible values for $mode are:
   1.841 +	* change == user is able to set/enter profile values; preview == just show the value
   1.842 +	* @access private
   1.843 +	*/
   1.844 +	function process_field_row($mode, $profile_row)
   1.845 +	{
   1.846 +		global $template;
   1.847 +
   1.848 +		$preview = ($mode == 'preview') ? true : false;
   1.849 +
   1.850 +		// set template filename
   1.851 +		$template->set_filenames(array(
   1.852 +			'cp_body'		=> 'custom_profile_fields.html')
   1.853 +		);
   1.854 +
   1.855 +		// empty previously filled blockvars
   1.856 +		foreach ($this->profile_types as $field_case => $field_type)
   1.857 +		{
   1.858 +			$template->destroy_block_vars($field_type);
   1.859 +		}
   1.860 +
   1.861 +		// Assign template variables
   1.862 +		$type_func = 'generate_' . $this->profile_types[$profile_row['field_type']];
   1.863 +		$this->$type_func($profile_row, $preview);
   1.864 +
   1.865 +		// Return templated data
   1.866 +		return $template->assign_display('cp_body');
   1.867 +	}
   1.868 +
   1.869 +	/**
   1.870 +	* Build Array for user insertion into custom profile fields table
   1.871 +	*/
   1.872 +	function build_insert_sql_array($cp_data)
   1.873 +	{
   1.874 +		global $db, $user, $auth;
   1.875 +
   1.876 +		$sql_not_in = array();
   1.877 +		foreach ($cp_data as $key => $null)
   1.878 +		{
   1.879 +			$sql_not_in[] = (strncmp($key, 'pf_', 3) === 0) ? substr($key, 3) : $key;
   1.880 +		}
   1.881 +
   1.882 +		$sql = 'SELECT f.field_type, f.field_ident, f.field_default_value, l.lang_default_value
   1.883 +			FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
   1.884 +			WHERE l.lang_id = ' . $user->get_iso_lang_id() . '
   1.885 +				' . ((sizeof($sql_not_in)) ? ' AND ' . $db->sql_in_set('f.field_ident', $sql_not_in, true) : '') . '
   1.886 +				AND l.field_id = f.field_id';
   1.887 +		$result = $db->sql_query($sql);
   1.888 +
   1.889 +		while ($row = $db->sql_fetchrow($result))
   1.890 +		{
   1.891 +			if ($row['field_default_value'] == 'now' && $row['field_type'] == FIELD_DATE)
   1.892 +			{
   1.893 +				$now = getdate();
   1.894 +				$row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
   1.895 +			}
   1.896 +			else if ($row['field_default_value'] === '' && $row['field_type'] == FIELD_INT)
   1.897 +			{
   1.898 +				// We cannot insert an empty string into an integer column.
   1.899 +				$row['field_default_value'] = NULL;
   1.900 +			}
   1.901 +
   1.902 +			$cp_data['pf_' . $row['field_ident']] = (in_array($row['field_type'], array(FIELD_TEXT, FIELD_STRING))) ? $row['lang_default_value'] : $row['field_default_value'];
   1.903 +		}
   1.904 +		$db->sql_freeresult($result);
   1.905 +
   1.906 +		return $cp_data;
   1.907 +	}
   1.908 +
   1.909 +	/**
   1.910 +	* Get profile field value on submit
   1.911 +	* @access private
   1.912 +	*/
   1.913 +	function get_profile_field($profile_row)
   1.914 +	{
   1.915 +		global $phpbb_root_path, $phpEx;
   1.916 +		global $config;
   1.917 +
   1.918 +		$var_name = 'pf_' . $profile_row['field_ident'];
   1.919 +
   1.920 +		switch ($profile_row['field_type'])
   1.921 +		{
   1.922 +			case FIELD_DATE:
   1.923 +
   1.924 +				if (!isset($_REQUEST[$var_name . '_day']))
   1.925 +				{
   1.926 +					if ($profile_row['field_default_value'] == 'now')
   1.927 +					{
   1.928 +						$now = getdate();
   1.929 +						$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
   1.930 +					}
   1.931 +					list($day, $month, $year) = explode('-', $profile_row['field_default_value']);
   1.932 +				}
   1.933 +				else
   1.934 +				{
   1.935 +					$day = request_var($var_name . '_day', 0);
   1.936 +					$month = request_var($var_name . '_month', 0);
   1.937 +					$year = request_var($var_name . '_year', 0);
   1.938 +				}
   1.939 +
   1.940 +				$var = sprintf('%2d-%2d-%4d', $day, $month, $year);
   1.941 +			break;
   1.942 +
   1.943 +			case FIELD_BOOL:
   1.944 +				// Checkbox
   1.945 +				if ($profile_row['field_length'] == 2)
   1.946 +				{
   1.947 +					$var = (isset($_REQUEST[$var_name])) ? 1 : 0;
   1.948 +				}
   1.949 +				else
   1.950 +				{
   1.951 +					$var = request_var($var_name, (int) $profile_row['field_default_value']);
   1.952 +				}
   1.953 +			break;
   1.954 +
   1.955 +			case FIELD_STRING:
   1.956 +			case FIELD_TEXT:
   1.957 +				$var = utf8_normalize_nfc(request_var($var_name, (string) $profile_row['field_default_value'], true));
   1.958 +			break;
   1.959 +
   1.960 +			case FIELD_INT:
   1.961 +				if (isset($_REQUEST[$var_name]) && $_REQUEST[$var_name] === '')
   1.962 +				{
   1.963 +					$var = NULL;
   1.964 +				}
   1.965 +				else
   1.966 +				{
   1.967 +					$var = request_var($var_name, (int) $profile_row['field_default_value']);
   1.968 +				}
   1.969 +			break;
   1.970 +
   1.971 +			case FIELD_DROPDOWN:
   1.972 +				$var = request_var($var_name, (int) $profile_row['field_default_value']);
   1.973 +			break;
   1.974 +
   1.975 +			default:
   1.976 +				$var = request_var($var_name, $profile_row['field_default_value']);
   1.977 +			break;
   1.978 +		}
   1.979 +
   1.980 +		return $var;
   1.981 +	}
   1.982 +}
   1.983 +
   1.984 +/**
   1.985 +* Custom Profile Fields ACP
   1.986 +* @package phpBB3
   1.987 +*/
   1.988 +class custom_profile_admin extends custom_profile
   1.989 +{
   1.990 +	var $vars = array();
   1.991 +
   1.992 +	/**
   1.993 +	* Return possible validation options
   1.994 +	*/
   1.995 +	function validate_options()
   1.996 +	{
   1.997 +		global $user;
   1.998 +
   1.999 +		$validate_ary = array('CHARS_ANY' => '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+');
  1.1000 +
  1.1001 +		$validate_options = '';
  1.1002 +		foreach ($validate_ary as $lang => $value)
  1.1003 +		{
  1.1004 +			$selected = ($this->vars['field_validation'] == $value) ? ' selected="selected"' : '';
  1.1005 +			$validate_options .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$lang] . '</option>';
  1.1006 +		}
  1.1007 +
  1.1008 +		return $validate_options;
  1.1009 +	}
  1.1010 +
  1.1011 +	/**
  1.1012 +	* Get string options for second step in ACP
  1.1013 +	*/
  1.1014 +	function get_string_options()
  1.1015 +	{
  1.1016 +		global $user;
  1.1017 +
  1.1018 +		$options = array(
  1.1019 +			0 => array('TITLE' => $user->lang['FIELD_LENGTH'],		'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'),
  1.1020 +			1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'],	'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'),
  1.1021 +			2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'],	'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'),
  1.1022 +			3 => array('TITLE' => $user->lang['FIELD_VALIDATION'],	'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>')
  1.1023 +		);
  1.1024 +
  1.1025 +		return $options;
  1.1026 +	}
  1.1027 +
  1.1028 +	/**
  1.1029 +	* Get text options for second step in ACP
  1.1030 +	*/
  1.1031 +	function get_text_options()
  1.1032 +	{
  1.1033 +		global $user;
  1.1034 +
  1.1035 +		$options = array(
  1.1036 +			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'] . '" />'),
  1.1037 +			1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'],	'FIELD' => '<input type="text" name="field_minlen" size="10" value="' . $this->vars['field_minlen'] . '" />'),
  1.1038 +			2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'],	'FIELD' => '<input type="text" name="field_maxlen" size="10" value="' . $this->vars['field_maxlen'] . '" />'),
  1.1039 +			3 => array('TITLE' => $user->lang['FIELD_VALIDATION'],	'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>')
  1.1040 +		);
  1.1041 +
  1.1042 +		return $options;
  1.1043 +	}
  1.1044 +
  1.1045 +	/**
  1.1046 +	* Get int options for second step in ACP
  1.1047 +	*/
  1.1048 +	function get_int_options()
  1.1049 +	{
  1.1050 +		global $user;
  1.1051 +
  1.1052 +		$options = array(
  1.1053 +			0 => array('TITLE' => $user->lang['FIELD_LENGTH'],		'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'),
  1.1054 +			1 => array('TITLE' => $user->lang['MIN_FIELD_NUMBER'],	'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'),
  1.1055 +			2 => array('TITLE' => $user->lang['MAX_FIELD_NUMBER'],	'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'),
  1.1056 +			3 => array('TITLE' => $user->lang['DEFAULT_VALUE'],		'FIELD' => '<input type="post" name="field_default_value" value="' . $this->vars['field_default_value'] . '" />')
  1.1057 +		);
  1.1058 +
  1.1059 +		return $options;
  1.1060 +	}
  1.1061 +
  1.1062 +	/**
  1.1063 +	* Get bool options for second step in ACP
  1.1064 +	*/
  1.1065 +	function get_bool_options()
  1.1066 +	{
  1.1067 +		global $user, $config, $lang_defs;
  1.1068 +
  1.1069 +		$default_lang_id = $lang_defs['iso'][$config['default_lang']];
  1.1070 +
  1.1071 +		$profile_row = array(
  1.1072 +			'var_name'				=> 'field_default_value',
  1.1073 +			'field_id'				=> 1,
  1.1074 +			'lang_name'				=> $this->vars['lang_name'],
  1.1075 +			'lang_explain'			=> $this->vars['lang_explain'],
  1.1076 +			'lang_id'				=> $default_lang_id,
  1.1077 +			'field_default_value'	=> $this->vars['field_default_value'],
  1.1078 +			'field_ident'			=> 'field_default_value',
  1.1079 +			'field_type'			=> FIELD_BOOL,
  1.1080 +			'field_length'			=> $this->vars['field_length'],
  1.1081 +			'lang_options'			=> $this->vars['lang_options']
  1.1082 +		);
  1.1083 +
  1.1084 +		$options = array(
  1.1085 +			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>'),
  1.1086 +			1 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row))
  1.1087 +		);
  1.1088 +
  1.1089 +		return $options;
  1.1090 +	}
  1.1091 +
  1.1092 +	/**
  1.1093 +	* Get dropdown options for second step in ACP
  1.1094 +	*/
  1.1095 +	function get_dropdown_options()
  1.1096 +	{
  1.1097 +		global $user, $config, $lang_defs;
  1.1098 +
  1.1099 +		$default_lang_id = $lang_defs['iso'][$config['default_lang']];
  1.1100 +
  1.1101 +		$profile_row[0] = array(
  1.1102 +			'var_name'				=> 'field_default_value',
  1.1103 +			'field_id'				=> 1,
  1.1104 +			'lang_name'				=> $this->vars['lang_name'],
  1.1105 +			'lang_explain'			=> $this->vars['lang_explain'],
  1.1106 +			'lang_id'				=> $default_lang_id,
  1.1107 +			'field_default_value'	=> $this->vars['field_default_value'],
  1.1108 +			'field_ident'			=> 'field_default_value',
  1.1109 +			'field_type'			=> FIELD_DROPDOWN,
  1.1110 +			'lang_options'			=> $this->vars['lang_options']
  1.1111 +		);
  1.1112 +
  1.1113 +		$profile_row[1] = $profile_row[0];
  1.1114 +		$profile_row[1]['var_name'] = 'field_novalue';
  1.1115 +		$profile_row[1]['field_ident'] = 'field_novalue';
  1.1116 +		$profile_row[1]['field_default_value']	= $this->vars['field_novalue'];
  1.1117 +
  1.1118 +		$options = array(
  1.1119 +			0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row[0])),
  1.1120 +			1 => array('TITLE' => $user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->process_field_row('preview', $profile_row[1]))
  1.1121 +		);
  1.1122 +
  1.1123 +		return $options;
  1.1124 +	}
  1.1125 +
  1.1126 +	/**
  1.1127 +	* Get date options for second step in ACP
  1.1128 +	*/
  1.1129 +	function get_date_options()
  1.1130 +	{
  1.1131 +		global $user, $config, $lang_defs;
  1.1132 +
  1.1133 +		$default_lang_id = $lang_defs['iso'][$config['default_lang']];
  1.1134 +
  1.1135 +		$profile_row = array(
  1.1136 +			'var_name'				=> 'field_default_value',
  1.1137 +			'lang_name'				=> $this->vars['lang_name'],
  1.1138 +			'lang_explain'			=> $this->vars['lang_explain'],
  1.1139 +			'lang_id'				=> $default_lang_id,
  1.1140 +			'field_default_value'	=> $this->vars['field_default_value'],
  1.1141 +			'field_ident'			=> 'field_default_value',
  1.1142 +			'field_type'			=> FIELD_DATE,
  1.1143 +			'field_length'			=> $this->vars['field_length']
  1.1144 +		);
  1.1145 +
  1.1146 +		$always_now = request_var('always_now', -1);
  1.1147 +		if ($always_now == -1)
  1.1148 +		{
  1.1149 +			$s_checked = ($this->vars['field_default_value'] == 'now') ? true : false;
  1.1150 +		}
  1.1151 +		else
  1.1152 +		{
  1.1153 +			$s_checked = ($always_now) ? true : false;
  1.1154 +		}
  1.1155 +
  1.1156 +		$options = array(
  1.1157 +			0 => array('TITLE' => $user->lang['DEFAULT_VALUE'],	'FIELD' => $this->process_field_row('preview', $profile_row)),
  1.1158 +			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>'),
  1.1159 +		);
  1.1160 +
  1.1161 +		return $options;
  1.1162 +	}
  1.1163 +}
  1.1164 +
  1.1165 +?>
  1.1166 \ No newline at end of file