[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/includes/ucp/ -> ucp_prefs.php (source)

   1  <?php
   2  /**
   3  *
   4  * @package ucp
   5  * @version $Id$
   6  * @copyright (c) 2005 phpBB Group
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
   8  *
   9  */
  10  
  11  /**
  12  * @ignore
  13  */
  14  if (!defined('IN_PHPBB'))
  15  {
  16      exit;
  17  }
  18  
  19  /**
  20  * ucp_prefs
  21  * Changing user preferences
  22  * @package ucp
  23  */
  24  class ucp_prefs
  25  {
  26      var $u_action;
  27  
  28  	function main($id, $mode)
  29      {
  30          global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
  31  
  32          $submit = (isset($_POST['submit'])) ? true : false;
  33          $error = $data = array();
  34          $s_hidden_fields = '';
  35  
  36          switch ($mode)
  37          {
  38              case 'personal':
  39                  add_form_key('ucp_prefs_personal');
  40                  $data = array(
  41                      'notifymethod'    => request_var('notifymethod', $user->data['user_notify_type']),
  42                      'dateformat'    => request_var('dateformat', $user->data['user_dateformat'], true),
  43                      'lang'            => basename(request_var('lang', $user->data['user_lang'])),
  44                      'style'            => request_var('style', (int) $user->data['user_style']),
  45                      'tz'            => request_var('tz', (float) $user->data['user_timezone']),
  46  
  47                      'dst'            => request_var('dst', (bool) $user->data['user_dst']),
  48                      'viewemail'        => request_var('viewemail', (bool) $user->data['user_allow_viewemail']),
  49                      'massemail'        => request_var('massemail', (bool) $user->data['user_allow_massemail']),
  50                      'hideonline'    => request_var('hideonline', (bool) !$user->data['user_allow_viewonline']),
  51                      'notifypm'        => request_var('notifypm', (bool) $user->data['user_notify_pm']),
  52                      'popuppm'        => request_var('popuppm', (bool) $user->optionget('popuppm')),
  53                      'allowpm'        => request_var('allowpm', (bool) $user->data['user_allow_pm']),
  54                  );
  55  
  56                  if ($data['notifymethod'] == NOTIFY_IM && (!$config['jab_enable'] || !$user->data['user_jabber'] || !@extension_loaded('xml')))
  57                  {
  58                      // Jabber isnt enabled, or no jabber field filled in. Update the users table to be sure its correct.
  59                      $data['notifymethod'] = NOTIFY_BOTH;
  60                  }
  61  
  62                  if ($submit)
  63                  {
  64                      if ($config['override_user_style'])
  65                      {
  66                          $data['style'] = (int) $config['default_style'];
  67                      }
  68                      else if (!phpbb_style_is_active($data['style']))
  69                      {
  70                          $data['style'] = (int) $user->data['user_style'];
  71                      }
  72  
  73                      $error = validate_data($data, array(
  74                          'dateformat'    => array('string', false, 1, 30),
  75                          'lang'            => array('language_iso_name'),
  76                          'tz'            => array('num', false, -14, 14),
  77                      ));
  78  
  79                      if (!check_form_key('ucp_prefs_personal'))
  80                      {
  81                          $error[] = 'FORM_INVALID';
  82                      }
  83  
  84                      if (!sizeof($error))
  85                      {
  86                          $user->optionset('popuppm', $data['popuppm']);
  87  
  88                          $sql_ary = array(
  89                              'user_allow_pm'            => $data['allowpm'],
  90                              'user_allow_viewemail'    => $data['viewemail'],
  91                              'user_allow_massemail'    => $data['massemail'],
  92                              'user_allow_viewonline'    => ($auth->acl_get('u_hideonline')) ? !$data['hideonline'] : $user->data['user_allow_viewonline'],
  93                              'user_notify_type'        => $data['notifymethod'],
  94                              'user_notify_pm'        => $data['notifypm'],
  95                              'user_options'            => $user->data['user_options'],
  96  
  97                              'user_dst'                => $data['dst'],
  98                              'user_dateformat'        => $data['dateformat'],
  99                              'user_lang'                => $data['lang'],
 100                              'user_timezone'            => $data['tz'],
 101                              'user_style'            => $data['style'],
 102                          );
 103  
 104                          $sql = 'UPDATE ' . USERS_TABLE . '
 105                              SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
 106                              WHERE user_id = ' . $user->data['user_id'];
 107                          $db->sql_query($sql);
 108  
 109                          meta_refresh(3, $this->u_action);
 110                          $message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
 111                          trigger_error($message);
 112                      }
 113  
 114                      // Replace "error" strings with their real, localised form
 115                      $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
 116                  }
 117  
 118                  $dateformat_options = '';
 119  
 120                  foreach ($user->lang['dateformats'] as $format => $null)
 121                  {
 122                      $dateformat_options .= '<option value="' . $format . '"' . (($format == $data['dateformat']) ? ' selected="selected"' : '') . '>';
 123                      $dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
 124                      $dateformat_options .= '</option>';
 125                  }
 126  
 127                  $s_custom = false;
 128  
 129                  $dateformat_options .= '<option value="custom"';
 130                  if (!isset($user->lang['dateformats'][$data['dateformat']]))
 131                  {
 132                      $dateformat_options .= ' selected="selected"';
 133                      $s_custom = true;
 134                  }
 135                  $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
 136  
 137                  // check if there are any user-selectable languages
 138                  $sql = 'SELECT COUNT(lang_id) as languages_count
 139                                  FROM ' . LANG_TABLE;
 140                  $result = $db->sql_query($sql);
 141                  if ($db->sql_fetchfield('languages_count') > 1)
 142                  {
 143                      $s_more_languages = true;
 144                  }
 145                  else
 146                  {
 147                      $s_more_languages = false;
 148                  }
 149                  $db->sql_freeresult($result);
 150  
 151                  // check if there are any user-selectable styles
 152                  $sql = 'SELECT COUNT(style_id) as styles_count
 153                                  FROM ' . STYLES_TABLE . '
 154                                  WHERE style_active = 1';
 155                  $result = $db->sql_query($sql);
 156                  if ($db->sql_fetchfield('styles_count') > 1)
 157                  {
 158                      $s_more_styles = true;
 159                  }
 160                  else
 161                  {
 162                      $s_more_styles = false;
 163                  }
 164                  $db->sql_freeresult($result);
 165  
 166                  $template->assign_vars(array(
 167                      'ERROR'                => (sizeof($error)) ? implode('<br />', $error) : '',
 168  
 169                      'S_NOTIFY_EMAIL'    => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false,
 170                      'S_NOTIFY_IM'        => ($data['notifymethod'] == NOTIFY_IM) ? true : false,
 171                      'S_NOTIFY_BOTH'        => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false,
 172                      'S_VIEW_EMAIL'        => $data['viewemail'],
 173                      'S_MASS_EMAIL'        => $data['massemail'],
 174                      'S_ALLOW_PM'        => $data['allowpm'],
 175                      'S_HIDE_ONLINE'        => $data['hideonline'],
 176                      'S_NOTIFY_PM'        => $data['notifypm'],
 177                      'S_POPUP_PM'        => $data['popuppm'],
 178                      'S_DST'                => $data['dst'],
 179  
 180                      'DATE_FORMAT'            => $data['dateformat'],
 181                      'A_DATE_FORMAT'            => addslashes($data['dateformat']),
 182                      'S_DATEFORMAT_OPTIONS'    => $dateformat_options,
 183                      'S_CUSTOM_DATEFORMAT'    => $s_custom,
 184                      'DEFAULT_DATEFORMAT'    => $config['default_dateformat'],
 185                      'A_DEFAULT_DATEFORMAT'    => addslashes($config['default_dateformat']),
 186  
 187                      'S_MORE_LANGUAGES'    => $s_more_languages,
 188                      'S_MORE_STYLES'            => $s_more_styles,
 189  
 190                      'S_LANG_OPTIONS'        => language_select($data['lang']),
 191                      'S_STYLE_OPTIONS'        => ($config['override_user_style']) ? '' : style_select($data['style']),
 192                      'S_TZ_OPTIONS'            => tz_select($data['tz'], true),
 193                      'S_CAN_HIDE_ONLINE'        => ($auth->acl_get('u_hideonline')) ? true : false,
 194                      'S_SELECT_NOTIFY'        => ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')) ? true : false)
 195                  );
 196  
 197              break;
 198  
 199              case 'view':
 200  
 201                  add_form_key('ucp_prefs_view');
 202  
 203                  $data = array(
 204                      'topic_sk'        => request_var('topic_sk', (!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't'),
 205                      'topic_sd'        => request_var('topic_sd', (!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd'),
 206                      'topic_st'        => request_var('topic_st', (!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0),
 207  
 208                      'post_sk'        => request_var('post_sk', (!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : 't'),
 209                      'post_sd'        => request_var('post_sd', (!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : 'a'),
 210                      'post_st'        => request_var('post_st', (!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : 0),
 211  
 212                      'images'        => request_var('images', (bool) $user->optionget('viewimg')),
 213                      'flash'            => request_var('flash', (bool) $user->optionget('viewflash')),
 214                      'smilies'        => request_var('smilies', (bool) $user->optionget('viewsmilies')),
 215                      'sigs'            => request_var('sigs', (bool) $user->optionget('viewsigs')),
 216                      'avatars'        => request_var('avatars', (bool) $user->optionget('viewavatars')),
 217                      'wordcensor'    => request_var('wordcensor', (bool) $user->optionget('viewcensors')),
 218                  );
 219  
 220                  if ($submit)
 221                  {
 222                      $error = validate_data($data, array(
 223                          'topic_sk'    => array('string', false, 1, 1),
 224                          'topic_sd'    => array('string', false, 1, 1),
 225                          'post_sk'    => array('string', false, 1, 1),
 226                          'post_sd'    => array('string', false, 1, 1),
 227                      ));
 228  
 229                      if (!check_form_key('ucp_prefs_view'))
 230                      {
 231                          $error[] = 'FORM_INVALID';
 232                      }
 233  
 234                      if (!sizeof($error))
 235                      {
 236                          $user->optionset('viewimg', $data['images']);
 237                          $user->optionset('viewflash', $data['flash']);
 238                          $user->optionset('viewsmilies', $data['smilies']);
 239                          $user->optionset('viewsigs', $data['sigs']);
 240                          $user->optionset('viewavatars', $data['avatars']);
 241  
 242                          if ($auth->acl_get('u_chgcensors'))
 243                          {
 244                              $user->optionset('viewcensors', $data['wordcensor']);
 245                          }
 246  
 247                          $sql_ary = array(
 248                              'user_options'                => $user->data['user_options'],
 249                              'user_topic_sortby_type'    => $data['topic_sk'],
 250                              'user_post_sortby_type'        => $data['post_sk'],
 251                              'user_topic_sortby_dir'        => $data['topic_sd'],
 252                              'user_post_sortby_dir'        => $data['post_sd'],
 253  
 254                              'user_topic_show_days'    => $data['topic_st'],
 255                              'user_post_show_days'    => $data['post_st'],
 256                          );
 257  
 258                          $sql = 'UPDATE ' . USERS_TABLE . '
 259                              SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
 260                              WHERE user_id = ' . $user->data['user_id'];
 261                          $db->sql_query($sql);
 262  
 263                          meta_refresh(3, $this->u_action);
 264                          $message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
 265                          trigger_error($message);
 266                      }
 267  
 268                      // Replace "error" strings with their real, localised form
 269                      $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
 270                  }
 271  
 272                  $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
 273  
 274                  // Topic ordering options
 275                  $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']);
 276  
 277                  $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']);
 278                  $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');
 279  
 280                  // Post ordering options
 281                  $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']);
 282  
 283                  $sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
 284                  $sort_by_post_sql = array('a' => 'u.username_clean', 't' => 'p.post_id', 's' => 'p.post_subject');
 285  
 286                  $_options = array('topic', 'post');
 287                  foreach ($_options as $sort_option)
 288                  {
 289                      ${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
 290                      foreach (${'limit_' . $sort_option . '_days'} as $day => $text)
 291                      {
 292                          $selected = ($data[$sort_option . '_st'] == $day) ? ' selected="selected"' : '';
 293                          ${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
 294                      }
 295                      ${'s_limit_' . $sort_option . '_days'} .= '</select>';
 296  
 297                      ${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
 298                      foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text)
 299                      {
 300                          $selected = ($data[$sort_option . '_sk'] == $key) ? ' selected="selected"' : '';
 301                          ${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
 302                      }
 303                      ${'s_sort_' . $sort_option . '_key'} .= '</select>';
 304  
 305                      ${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
 306                      foreach ($sort_dir_text as $key => $value)
 307                      {
 308                          $selected = ($data[$sort_option . '_sd'] == $key) ? ' selected="selected"' : '';
 309                          ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
 310                      }
 311                      ${'s_sort_' . $sort_option . '_dir'} .= '</select>';
 312                  }
 313  
 314                  $template->assign_vars(array(
 315                      'ERROR'                => (sizeof($error)) ? implode('<br />', $error) : '',
 316  
 317                      'S_IMAGES'            => $data['images'],
 318                      'S_FLASH'            => $data['flash'],
 319                      'S_SMILIES'            => $data['smilies'],
 320                      'S_SIGS'            => $data['sigs'],
 321                      'S_AVATARS'            => $data['avatars'],
 322                      'S_DISABLE_CENSORS'    => $data['wordcensor'],
 323  
 324                      'S_CHANGE_CENSORS'        => ($auth->acl_get('u_chgcensors') && $config['allow_nocensors']) ? true : false,
 325  
 326                      'S_TOPIC_SORT_DAYS'        => $s_limit_topic_days,
 327                      'S_TOPIC_SORT_KEY'        => $s_sort_topic_key,
 328                      'S_TOPIC_SORT_DIR'        => $s_sort_topic_dir,
 329                      'S_POST_SORT_DAYS'        => $s_limit_post_days,
 330                      'S_POST_SORT_KEY'        => $s_sort_post_key,
 331                      'S_POST_SORT_DIR'        => $s_sort_post_dir)
 332                  );
 333  
 334              break;
 335  
 336              case 'post':
 337  
 338                  $data = array(
 339                      'bbcode'    => request_var('bbcode', $user->optionget('bbcode')),
 340                      'smilies'    => request_var('smilies', $user->optionget('smilies')),
 341                      'sig'        => request_var('sig', $user->optionget('attachsig')),
 342                      'notify'    => request_var('notify', (bool) $user->data['user_notify']),
 343                  );
 344                  add_form_key('ucp_prefs_post');
 345  
 346                  if ($submit)
 347                  {
 348                      if (check_form_key('ucp_prefs_post'))
 349                      {
 350                          $user->optionset('bbcode', $data['bbcode']);
 351                          $user->optionset('smilies', $data['smilies']);
 352                          $user->optionset('attachsig', $data['sig']);
 353  
 354                          $sql_ary = array(
 355                              'user_options'    => $user->data['user_options'],
 356                              'user_notify'    => $data['notify'],
 357                          );
 358  
 359                          $sql = 'UPDATE ' . USERS_TABLE . '
 360                              SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
 361                              WHERE user_id = ' . $user->data['user_id'];
 362                          $db->sql_query($sql);
 363  
 364                          $msg = $user->lang['PREFERENCES_UPDATED'];
 365                      }
 366                      else
 367                      {
 368                          $msg = $user->lang['FORM_INVALID'];
 369                      }
 370                      meta_refresh(3, $this->u_action);
 371                      $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
 372                      trigger_error($message);
 373                  }
 374  
 375                  $template->assign_vars(array(
 376                      'S_BBCODE'    => $data['bbcode'],
 377                      'S_SMILIES'    => $data['smilies'],
 378                      'S_SIG'        => $data['sig'],
 379                      'S_NOTIFY'    => $data['notify'])
 380                  );
 381              break;
 382          }
 383  
 384          $template->assign_vars(array(
 385              'L_TITLE'            => $user->lang['UCP_PREFS_' . strtoupper($mode)],
 386  
 387              'S_HIDDEN_FIELDS'    => $s_hidden_fields,
 388              'S_UCP_ACTION'        => $this->u_action)
 389          );
 390  
 391          $this->tpl_name = 'ucp_prefs_' . $mode;
 392          $this->page_title = 'UCP_PREFS_' . strtoupper($mode);
 393      }
 394  }
 395  
 396  ?>


Generated: Wed Oct 2 15:03:47 2013 Cross-referenced by PHPXref 0.7.1