phpBB

Code Changes

File: includes/functions_profile_fields.php

  Unmodified   Added   Modified   Removed
Line 39Line 39
		switch ($mode)
{
case 'register':

		switch ($mode)
{
case 'register':

				// If the field is required we show it on the registration page and do not show hidden fields
$sql_where .= ' AND (f.field_show_on_reg = 1 OR f.field_required = 1) AND f.field_hide = 0';

				// If the field is required we show it on the registration page
$sql_where .= ' AND f.field_show_on_reg = 1';

			break;

case 'profile':
// Show hidden fields to moderators/admins
if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
{

			break;

case 'profile':
// Show hidden fields to moderators/admins
if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
{

					$sql_where .= ' AND f.field_hide = 0';

					$sql_where .= ' AND f.field_show_profile = 1';

				}
break;


				}
break;


Line 90Line 90
	*/
function validate_profile_field($field_type, &$field_value, $field_data)
{

	*/
function validate_profile_field($field_type, &$field_value, $field_data)
{

		switch ($field_type)
{
case FIELD_INT:
case FIELD_DROPDOWN:
$field_value = (int) $field_value;
break;

case FIELD_BOOL:
$field_value = (bool) $field_value;
break;
}


 
		switch ($field_type)
{
case FIELD_DATE:

		switch ($field_type)
{
case FIELD_DATE:

Line 133Line 121
			break;

case FIELD_BOOL:

			break;

case FIELD_BOOL:

 
				$field_value = (bool) $field_value;


				if (!$field_value && $field_data['field_required'])
{
return 'FIELD_REQUIRED';

				if (!$field_value && $field_data['field_required'])
{
return 'FIELD_REQUIRED';

Line 140Line 130
			break;

case FIELD_INT:

			break;

case FIELD_INT:

				if (empty($field_value) && !$field_data['field_required'])

				if (trim($field_value) === '' && !$field_data['field_required'])

				{
return false;
}

				{
return false;
}

 

$field_value = (int) $field_value;


if ($field_value < $field_data['field_minlen'])
{


if ($field_value < $field_data['field_minlen'])
{

Line 156Line 148
			break;

case FIELD_DROPDOWN:

			break;

case FIELD_DROPDOWN:

 
				$field_value = (int) $field_value;

// retrieve option lang data if necessary
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']]))
{
$this->get_option_lang($field_data['field_id'], $field_data['lang_id'], FIELD_DROPDOWN, false);
}

if (!isset($this->options_lang[$field_data['field_id']][$field_data['lang_id']][$field_value]))
{
return 'FIELD_INVALID_VALUE';
}


				if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
{
return 'FIELD_REQUIRED';

				if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
{
return 'FIELD_REQUIRED';

Line 164Line 169
			
case FIELD_STRING:
case FIELD_TEXT:

			
case FIELD_STRING:
case FIELD_TEXT:

				if (empty($field_value) && !$field_data['field_required'])

				if (trim($field_value) === '' && !$field_data['field_required'])

				{
return false;
}

				{
return false;
}

				else if (empty($field_value) && $field_data['field_required'])

				else if (trim($field_value) === '' && $field_data['field_required'])

				{
return 'FIELD_REQUIRED';
}

				{
return 'FIELD_REQUIRED';
}

Line 259Line 264
	}

/**

	}

/**

	* Submit profile field

	* Submit profile field for validation

	* @access public
*/
function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error)

	* @access public
*/
function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error)

Line 270Line 275
		switch ($mode)
{
case 'register':

		switch ($mode)
{
case 'register':

				// If the field is required we show it on the registration page and do not show hidden fields
$sql_where .= ' AND (f.field_show_on_reg = 1 OR f.field_required = 1) AND f.field_hide = 0';

				// If the field is required we show it on the registration page
$sql_where .= ' AND f.field_show_on_reg = 1';

			break;

case 'profile':
// Show hidden fields to moderators/admins
if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
{

			break;

case 'profile':
// Show hidden fields to moderators/admins
if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
{

					$sql_where .= ' AND f.field_hide = 0';

					$sql_where .= ' AND f.field_show_profile = 1';

				}
break;


				}
break;


Line 308Line 313
				switch ($cp_result)
{
case 'FIELD_INVALID_DATE':

				switch ($cp_result)
{
case 'FIELD_INVALID_DATE':

 
					case 'FIELD_INVALID_VALUE':

					case 'FIELD_REQUIRED':
$error = sprintf($user->lang[$cp_result], $row['lang_name']);
break;

					case 'FIELD_REQUIRED':
$error = sprintf($user->lang[$cp_result], $row['lang_name']);
break;

Line 347Line 353
			}
}
$db->sql_freeresult($result);

			}
}
$db->sql_freeresult($result);

 
	}

/**
* Update profile field data directly
*/
function update_profile_field_data($user_id, &$cp_data)
{
global $db;

if (!sizeof($cp_data))
{
return;
}

switch ($db->sql_layer)
{
case 'oracle':
case 'firebird':
case 'postgres':
$right_delim = $left_delim = '"';
break;

case 'sqlite':
case 'mssql':
case 'mssql_odbc':
case 'mssqlnative':
$right_delim = ']';
$left_delim = '[';
break;

case 'mysql':
case 'mysql4':
case 'mysqli':
$right_delim = $left_delim = '`';
break;
}

// use new array for the UPDATE; changes in the key do not affect the original array
$cp_data_sql = array();
foreach ($cp_data as $key => $value)
{
// Firebird is case sensitive with delimiter
$cp_data_sql[$left_delim . (($db->sql_layer == 'firebird' || $db->sql_layer == 'oracle') ? strtoupper($key) : $key) . $right_delim] = $value;
}

$sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $cp_data_sql) . "
WHERE user_id = $user_id";
$db->sql_query($sql);

if (!$db->sql_affectedrows())
{
$cp_data_sql['user_id'] = (int) $user_id;

$db->sql_return_on_error(true);

$sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data_sql);
$db->sql_query($sql);

$db->sql_return_on_error(false);
}

	}

/**

	}

/**

Line 388Line 455
			$db->sql_freeresult($result);

$user_fields = array();

			$db->sql_freeresult($result);

$user_fields = array();

 

$user_ids = $user_id;


// Go through the fields in correct order
foreach (array_keys($this->profile_cache) as $used_ident)


// Go through the fields in correct order
foreach (array_keys($this->profile_cache) as $used_ident)

Line 396Line 465
				{
$user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
$user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];

				{
$user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
$user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];

 
				}

foreach ($user_ids as $user_id)
{
if (!isset($user_fields[$user_id][$used_ident]) && $this->profile_cache[$used_ident]['field_show_novalue'])
{
$user_fields[$user_id][$used_ident]['value'] = '';
$user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];
}

				}
}


				}
}


Line 454Line 532
		switch ($this->profile_types[$field_type])
{
case 'int':

		switch ($this->profile_types[$field_type])
{
case 'int':

				if ($value == '')

				if (($value === '' || $value === null) && !$ident_ary['data']['field_show_novalue'])

				{
return NULL;
}

				{
return NULL;
}

Line 463Line 541

case 'string':
case 'text':


case 'string':
case 'text':

				if (!$value)

				if (!$value && !$ident_ary['data']['field_show_novalue'])

				{
return NULL;
}

				{
return NULL;
}

Line 481Line 559
				$month = (isset($date[1])) ? (int) $date[1] : 0;
$year = (isset($date[2])) ? (int) $date[2] : 0;


				$month = (isset($date[1])) ? (int) $date[1] : 0;
$year = (isset($date[2])) ? (int) $date[2] : 0;


				if (!$day && !$month && !$year)

				if (!$day && !$month && !$year && !$ident_ary['data']['field_show_novalue'])

				{
return NULL;
}
else if ($day && $month && $year)
{
global $user;

				{
return NULL;
}
else if ($day && $month && $year)
{
global $user;

					// 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
return $user->format_date(gmmktime(0, 0, 0, $month, $day, $year) + $user->timezone + $user->dst, $user->lang['DATE_FORMAT'], true);


					// Date should display as the same date for every user regardless of timezone, so remove offset
// to compensate for the offset added by user::format_date()
return $user->format_date(gmmktime(0, 0, 0, $month, $day, $year) - ($user->timezone + $user->dst), $user->lang['DATE_FORMAT'], true);

				}

return $value;

				}

return $value;

Line 503Line 582
					$this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false);
}


					$this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false);
}


				if ($value == $ident_ary['data']['field_novalue'])

				if ($value == $ident_ary['data']['field_novalue'] && !$ident_ary['data']['field_show_novalue'])

				{
return NULL;
}

				{
return NULL;
}

Line 512Line 591

// User not having a value assigned
if (!isset($this->options_lang[$field_id][$lang_id][$value]))


// User not having a value assigned
if (!isset($this->options_lang[$field_id][$lang_id][$value]))

 
				{
if ($ident_ary['data']['field_show_novalue'])
{
$value = $ident_ary['data']['field_novalue'];
}
else

				{
return NULL;

				{
return NULL;

 
					}

				}

return $this->options_lang[$field_id][$lang_id][$value];

				}

return $this->options_lang[$field_id][$lang_id][$value];

Line 525Line 611
				if (!isset($this->options_lang[$field_id][$lang_id]))
{
$this->get_option_lang($field_id, $lang_id, FIELD_BOOL, false);

				if (!isset($this->options_lang[$field_id][$lang_id]))
{
$this->get_option_lang($field_id, $lang_id, FIELD_BOOL, false);

 
				}

if (!$value && $ident_ary['data']['field_show_novalue'])
{
$value = $ident_ary['data']['field_default_value'];

				}

if ($ident_ary['data']['field_length'] == 1)

				}

if ($ident_ary['data']['field_length'] == 1)

Line 557Line 648

$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
$user_ident = $profile_row['field_ident'];


$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
$user_ident = $profile_row['field_ident'];

		// checkbox - only testing for isset

		// checkbox - set the value to "true" if it has been set to 1

		if ($profile_row['field_type'] == FIELD_BOOL && $profile_row['field_length'] == 2)
{

		if ($profile_row['field_type'] == FIELD_BOOL && $profile_row['field_length'] == 2)
{

			$value = (isset($_REQUEST[$profile_row['field_ident']])) ? true : ((!isset($user->profile_fields[$user_ident]) || $preview) ? $default_value : $user->profile_fields[$user_ident]);

			$value = (isset($_REQUEST[$profile_row['field_ident']]) && request_var($profile_row['field_ident'], $default_value) == 1) ? true : ((!isset($user->profile_fields[$user_ident]) || $preview) ? $default_value : $user->profile_fields[$user_ident]);

		}
else if ($profile_row['field_type'] == FIELD_INT)
{

		}
else if ($profile_row['field_type'] == FIELD_INT)
{

Line 570Line 661
			}
else
{

			}
else
{

				if (!$preview && isset($user->profile_fields[$user_ident]) && is_null($user->profile_fields[$user_ident]))

				if (!$preview && array_key_exists($user_ident, $user->profile_fields) && is_null($user->profile_fields[$user_ident]))

				{
$value = NULL;
}

				{
$value = NULL;
}

Line 584Line 675
				}
}


				}
}


			return (is_null($value)) ? '' : (int) $value;

			return (is_null($value) || $value === '') ? '' : (int) $value;

		}
else
{

		}
else
{

Line 821Line 912
			{
$now = getdate();
$row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);

			{
$now = getdate();
$row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);

 
			}
else if ($row['field_default_value'] === '' && $row['field_type'] == FIELD_INT)
{
// We cannot insert an empty string into an integer column.
$row['field_default_value'] = NULL;

			}

$cp_data['pf_' . $row['field_ident']] = (in_array($row['field_type'], array(FIELD_TEXT, FIELD_STRING))) ? $row['lang_default_value'] : $row['field_default_value'];

			}

$cp_data['pf_' . $row['field_ident']] = (in_array($row['field_type'], array(FIELD_TEXT, FIELD_STRING))) ? $row['lang_default_value'] : $row['field_default_value'];