Blame Identity/Webenv/phpBB/3.0.4/includes/ucp/ucp_prefs.php

ef5584
ef5584
/**
ef5584
*
ef5584
* @package ucp
ef5584
* @version $Id: ucp_prefs.php 8990 2008-10-09 15:41:19Z acydburn $
ef5584
* @copyright (c) 2005 phpBB Group
ef5584
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
ef5584
*
ef5584
*/
ef5584
ef5584
/**
ef5584
* @ignore
ef5584
*/
ef5584
if (!defined('IN_PHPBB'))
ef5584
{
ef5584
	exit;
ef5584
}
ef5584
ef5584
/**
ef5584
* ucp_prefs
ef5584
* Changing user preferences
ef5584
* @package ucp
ef5584
*/
ef5584
class ucp_prefs
ef5584
{
ef5584
	var $u_action;
ef5584
ef5584
	function main($id, $mode)
ef5584
	{
ef5584
		global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
ef5584
ef5584
		$submit = (isset($_POST['submit'])) ? true : false;
ef5584
		$error = $data = array();
ef5584
		$s_hidden_fields = '';
ef5584
ef5584
		switch ($mode)
ef5584
		{
ef5584
			case 'personal':
ef5584
				add_form_key('ucp_prefs_personal');
ef5584
				$data = array(
ef5584
					'notifymethod'	=> request_var('notifymethod', $user->data['user_notify_type']),
ef5584
					'dateformat'	=> request_var('dateformat', $user->data['user_dateformat'], true),
ef5584
					'lang'			=> basename(request_var('lang', $user->data['user_lang'])),
ef5584
					'style'			=> request_var('style', (int) $user->data['user_style']),
ef5584
					'tz'			=> request_var('tz', (float) $user->data['user_timezone']),
ef5584
ef5584
					'dst'			=> request_var('dst', (bool) $user->data['user_dst']),
ef5584
					'viewemail'		=> request_var('viewemail', (bool) $user->data['user_allow_viewemail']),
ef5584
					'massemail'		=> request_var('massemail', (bool) $user->data['user_allow_massemail']),
ef5584
					'hideonline'	=> request_var('hideonline', (bool) !$user->data['user_allow_viewonline']),
ef5584
					'notifypm'		=> request_var('notifypm', (bool) $user->data['user_notify_pm']),
ef5584
					'popuppm'		=> request_var('popuppm', (bool) $user->optionget('popuppm')),
ef5584
					'allowpm'		=> request_var('allowpm', (bool) $user->data['user_allow_pm']),
ef5584
				);
ef5584
ef5584
				if ($data['notifymethod'] == NOTIFY_IM && (!$config['jab_enable'] || !$user->data['user_jabber'] || !@extension_loaded('xml')))
ef5584
				{
ef5584
					// Jabber isnt enabled, or no jabber field filled in. Update the users table to be sure its correct.
ef5584
					$data['notifymethod'] = NOTIFY_BOTH;
ef5584
				}
ef5584
ef5584
				if ($submit)
ef5584
				{
ef5584
					$data['style'] = ($config['override_user_style']) ? $config['default_style'] : $data['style'];
ef5584
ef5584
					$error = validate_data($data, array(
ef5584
						'dateformat'	=> array('string', false, 1, 30),
ef5584
						'lang'			=> array('match', false, '#^[a-z0-9_\-]{2,}$#i'),
ef5584
						'tz'			=> array('num', false, -14, 14),
ef5584
					));
ef5584
ef5584
					if (!check_form_key('ucp_prefs_personal'))
ef5584
					{
ef5584
						$error[] = 'FORM_INVALID';
ef5584
					}
ef5584
ef5584
					if (!sizeof($error))
ef5584
					{
ef5584
						$user->optionset('popuppm', $data['popuppm']);
ef5584
ef5584
						$sql_ary = array(
ef5584
							'user_allow_pm'			=> $data['allowpm'],
ef5584
							'user_allow_viewemail'	=> $data['viewemail'],
ef5584
							'user_allow_massemail'	=> $data['massemail'],
ef5584
							'user_allow_viewonline'	=> ($auth->acl_get('u_hideonline')) ? !$data['hideonline'] : $user->data['user_allow_viewonline'],
ef5584
							'user_notify_type'		=> $data['notifymethod'],
ef5584
							'user_notify_pm'		=> $data['notifypm'],
ef5584
							'user_options'			=> $user->data['user_options'],
ef5584
ef5584
							'user_dst'				=> $data['dst'],
ef5584
							'user_dateformat'		=> $data['dateformat'],
ef5584
							'user_lang'				=> $data['lang'],
ef5584
							'user_timezone'			=> $data['tz'],
ef5584
							'user_style'			=> $data['style'],
ef5584
						);
ef5584
ef5584
						$sql = 'UPDATE ' . USERS_TABLE . '
ef5584
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
ef5584
							WHERE user_id = ' . $user->data['user_id'];
ef5584
						$db->sql_query($sql);
ef5584
ef5584
						meta_refresh(3, $this->u_action);
ef5584
						$message = $user->lang['PREFERENCES_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', '');
ef5584
						trigger_error($message);
ef5584
					}
ef5584
ef5584
					// Replace "error" strings with their real, localised form
ef5584
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
ef5584
				}
ef5584
ef5584
				$dateformat_options = '';
ef5584
ef5584
				foreach ($user->lang['dateformats'] as $format => $null)
ef5584
				{
ef5584
					$dateformat_options .= '<option value="' . $format . '"' . (($format == $data['dateformat']) ? ' selected="selected"' : '') . '>';
ef5584
					$dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
ef5584
					$dateformat_options .= '</option>';
ef5584
				}
ef5584
ef5584
				$s_custom = false;
ef5584
ef5584
				$dateformat_options .= '
ef5584
				if (!isset($user->lang['dateformats'][$data['dateformat']]))
ef5584
				{
ef5584
					$dateformat_options .= ' selected="selected"';
ef5584
					$s_custom = true;
ef5584
				}
ef5584
				$dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
ef5584
ef5584
				$template->assign_vars(array(
ef5584
					'ERROR'				=> (sizeof($error)) ? implode('
', $error) : '',
ef5584
ef5584
					'S_NOTIFY_EMAIL'	=> ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false,
ef5584
					'S_NOTIFY_IM'		=> ($data['notifymethod'] == NOTIFY_IM) ? true : false,
ef5584
					'S_NOTIFY_BOTH'		=> ($data['notifymethod'] == NOTIFY_BOTH) ? true : false,
ef5584
					'S_VIEW_EMAIL'		=> $data['viewemail'],
ef5584
					'S_MASS_EMAIL'		=> $data['massemail'],
ef5584
					'S_ALLOW_PM'		=> $data['allowpm'],
ef5584
					'S_HIDE_ONLINE'		=> $data['hideonline'],
ef5584
					'S_NOTIFY_PM'		=> $data['notifypm'],
ef5584
					'S_POPUP_PM'		=> $data['popuppm'],
ef5584
					'S_DST'				=> $data['dst'],
ef5584
ef5584
					'DATE_FORMAT'			=> $data['dateformat'],
ef5584
					'A_DATE_FORMAT'			=> addslashes($data['dateformat']),
ef5584
					'S_DATEFORMAT_OPTIONS'	=> $dateformat_options,
ef5584
					'S_CUSTOM_DATEFORMAT'	=> $s_custom,
ef5584
					'DEFAULT_DATEFORMAT'	=> $config['default_dateformat'],
ef5584
					'A_DEFAULT_DATEFORMAT'	=> addslashes($config['default_dateformat']),
ef5584
ef5584
					'S_LANG_OPTIONS'		=> language_select($data['lang']),
ef5584
					'S_STYLE_OPTIONS'		=> ($config['override_user_style']) ? '' : style_select($data['style']),
ef5584
					'S_TZ_OPTIONS'			=> tz_select($data['tz'], true),
ef5584
					'S_CAN_HIDE_ONLINE'		=> ($auth->acl_get('u_hideonline')) ? true : false,
ef5584
					'S_SELECT_NOTIFY'		=> ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')) ? true : false)
ef5584
				);
ef5584
ef5584
			break;
ef5584
ef5584
			case 'view':
ef5584
ef5584
				add_form_key('ucp_prefs_view');
ef5584
ef5584
				$data = array(
ef5584
					'topic_sk'		=> request_var('topic_sk', (!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't'),
ef5584
					'topic_sd'		=> request_var('topic_sd', (!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd'),
ef5584
					'topic_st'		=> request_var('topic_st', (!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0),
ef5584
ef5584
					'post_sk'		=> request_var('post_sk', (!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : 't'),
ef5584
					'post_sd'		=> request_var('post_sd', (!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : 'a'),
ef5584
					'post_st'		=> request_var('post_st', (!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : 0),
ef5584
ef5584
					'images'		=> request_var('images', (bool) $user->optionget('viewimg')),
ef5584
					'flash'			=> request_var('flash', (bool) $user->optionget('viewflash')),
ef5584
					'smilies'		=> request_var('smilies', (bool) $user->optionget('viewsmilies')),
ef5584
					'sigs'			=> request_var('sigs', (bool) $user->optionget('viewsigs')),
ef5584
					'avatars'		=> request_var('avatars', (bool) $user->optionget('viewavatars')),
ef5584
					'wordcensor'	=> request_var('wordcensor', (bool) $user->optionget('viewcensors')),
ef5584
				);
ef5584
ef5584
				if ($submit)
ef5584
				{
ef5584
					$error = validate_data($data, array(
ef5584
						'topic_sk'	=> array('string', false, 1, 1),
ef5584
						'topic_sd'	=> array('string', false, 1, 1),
ef5584
						'post_sk'	=> array('string', false, 1, 1),
ef5584
						'post_sd'	=> array('string', false, 1, 1),
ef5584
					));
ef5584
ef5584
					if (!check_form_key('ucp_prefs_view'))
ef5584
					{
ef5584
						$error[] = 'FORM_INVALID';
ef5584
					}
ef5584
ef5584
					if (!sizeof($error))
ef5584
					{
ef5584
						$user->optionset('viewimg', $data['images']);
ef5584
						$user->optionset('viewflash', $data['flash']);
ef5584
						$user->optionset('viewsmilies', $data['smilies']);
ef5584
						$user->optionset('viewsigs', $data['sigs']);
ef5584
						$user->optionset('viewavatars', $data['avatars']);
ef5584
ef5584
						if ($auth->acl_get('u_chgcensors'))
ef5584
						{
ef5584
							$user->optionset('viewcensors', $data['wordcensor']);
ef5584
						}
ef5584
ef5584
						$sql_ary = array(
ef5584
							'user_options'				=> $user->data['user_options'],
ef5584
							'user_topic_sortby_type'	=> $data['topic_sk'],
ef5584
							'user_post_sortby_type'		=> $data['post_sk'],
ef5584
							'user_topic_sortby_dir'		=> $data['topic_sd'],
ef5584
							'user_post_sortby_dir'		=> $data['post_sd'],
ef5584
ef5584
							'user_topic_show_days'	=> $data['topic_st'],
ef5584
							'user_post_show_days'	=> $data['post_st'],
ef5584
						);
ef5584
ef5584
						$sql = 'UPDATE ' . USERS_TABLE . '
ef5584
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
ef5584
							WHERE user_id = ' . $user->data['user_id'];
ef5584
						$db->sql_query($sql);
ef5584
ef5584
						meta_refresh(3, $this->u_action);
ef5584
						$message = $user->lang['PREFERENCES_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', '');
ef5584
						trigger_error($message);
ef5584
					}
ef5584
ef5584
					// Replace "error" strings with their real, localised form
ef5584
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
ef5584
				}
ef5584
ef5584
				$sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
ef5584
ef5584
				// Topic ordering options
ef5584
				$limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
ef5584
ef5584
				$sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
ef5584
				$sort_by_topic_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views');
ef5584
ef5584
				// Post ordering options
ef5584
				$limit_post_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
ef5584
ef5584
				$sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
ef5584
				$sort_by_post_sql = array('a' => 'u.username_clean', 't' => 'p.post_id', 's' => 'p.post_subject');
ef5584
ef5584
				$_options = array('topic', 'post');
ef5584
				foreach ($_options as $sort_option)
ef5584
				{
ef5584
					${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
ef5584
					foreach (${'limit_' . $sort_option . '_days'} as $day => $text)
ef5584
					{
ef5584
						$selected = ($data[$sort_option . '_st'] == $day) ? ' selected="selected"' : '';
ef5584
						${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
ef5584
					}
ef5584
					${'s_limit_' . $sort_option . '_days'} .= '</select>';
ef5584
ef5584
					${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
ef5584
					foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text)
ef5584
					{
ef5584
						$selected = ($data[$sort_option . '_sk'] == $key) ? ' selected="selected"' : '';
ef5584
						${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
ef5584
					}
ef5584
					${'s_sort_' . $sort_option . '_key'} .= '</select>';
ef5584
ef5584
					${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
ef5584
					foreach ($sort_dir_text as $key => $value)
ef5584
					{
ef5584
						$selected = ($data[$sort_option . '_sd'] == $key) ? ' selected="selected"' : '';
ef5584
						${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
ef5584
					}
ef5584
					${'s_sort_' . $sort_option . '_dir'} .= '</select>';
ef5584
				}
ef5584
ef5584
				$template->assign_vars(array(
ef5584
					'ERROR'				=> (sizeof($error)) ? implode('
', $error) : '',
ef5584
ef5584
					'S_IMAGES'			=> $data['images'],
ef5584
					'S_FLASH'			=> $data['flash'],
ef5584
					'S_SMILIES'			=> $data['smilies'],
ef5584
					'S_SIGS'			=> $data['sigs'],
ef5584
					'S_AVATARS'			=> $data['avatars'],
ef5584
					'S_DISABLE_CENSORS'	=> $data['wordcensor'],
ef5584
ef5584
					'S_CHANGE_CENSORS'		=> ($auth->acl_get('u_chgcensors')) ? true : false,
ef5584
ef5584
					'S_TOPIC_SORT_DAYS'		=> $s_limit_topic_days,
ef5584
					'S_TOPIC_SORT_KEY'		=> $s_sort_topic_key,
ef5584
					'S_TOPIC_SORT_DIR'		=> $s_sort_topic_dir,
ef5584
					'S_POST_SORT_DAYS'		=> $s_limit_post_days,
ef5584
					'S_POST_SORT_KEY'		=> $s_sort_post_key,
ef5584
					'S_POST_SORT_DIR'		=> $s_sort_post_dir)
ef5584
				);
ef5584
ef5584
			break;
ef5584
ef5584
			case 'post':
ef5584
ef5584
				$data = array(
ef5584
					'bbcode'	=> request_var('bbcode', $user->optionget('bbcode')),
ef5584
					'smilies'	=> request_var('smilies', $user->optionget('smilies')),
ef5584
					'sig'		=> request_var('sig', $user->optionget('attachsig')),
ef5584
					'notify'	=> request_var('notify', (bool) $user->data['user_notify']),
ef5584
				);
ef5584
				add_form_key('ucp_prefs_post');
ef5584
ef5584
				if ($submit)
ef5584
				{
ef5584
					if (check_form_key('ucp_prefs_post'))
ef5584
					{
ef5584
						$user->optionset('bbcode', $data['bbcode']);
ef5584
						$user->optionset('smilies', $data['smilies']);
ef5584
						$user->optionset('attachsig', $data['sig']);
ef5584
ef5584
						$sql_ary = array(
ef5584
							'user_options'	=> $user->data['user_options'],
ef5584
							'user_notify'	=> $data['notify'],
ef5584
						);
ef5584
ef5584
						$sql = 'UPDATE ' . USERS_TABLE . '
ef5584
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
ef5584
							WHERE user_id = ' . $user->data['user_id'];
ef5584
						$db->sql_query($sql);
ef5584
ef5584
						$msg = $user->lang['PREFERENCES_UPDATED'];
ef5584
					}
ef5584
					else
ef5584
					{
ef5584
						$msg = $user->lang['FORM_INVALID'];
ef5584
					}
ef5584
					meta_refresh(3, $this->u_action);
ef5584
					$message = $msg . '

' . sprintf($user->lang['RETURN_UCP'], '', '');
ef5584
					trigger_error($message);
ef5584
				}
ef5584
ef5584
				$template->assign_vars(array(
ef5584
					'S_BBCODE'	=> $data['bbcode'],
ef5584
					'S_SMILIES'	=> $data['smilies'],
ef5584
					'S_SIG'		=> $data['sig'],
ef5584
					'S_NOTIFY'	=> $data['notify'])
ef5584
				);
ef5584
			break;
ef5584
		}
ef5584
ef5584
		$template->assign_vars(array(
ef5584
			'L_TITLE'			=> $user->lang['UCP_PREFS_' . strtoupper($mode)],
ef5584
ef5584
			'S_HIDDEN_FIELDS'	=> $s_hidden_fields,
ef5584
			'S_UCP_ACTION'		=> $this->u_action)
ef5584
		);
ef5584
ef5584
		$this->tpl_name = 'ucp_prefs_' . $mode;
ef5584
		$this->page_title = 'UCP_PREFS_' . strtoupper($mode);
ef5584
	}
ef5584
}
ef5584
ef5584
?>