[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

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

   1  <?php
   2  /** 
   3  *
   4  * @package ucp
   5  * @version $Id: ucp_main.php,v 1.77 2006/11/12 14:29:32 naderman Exp $
   6  * @copyright (c) 2005 phpBB Group 
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
   8  *
   9  */
  10  
  11  /**
  12  * ucp_main
  13  * UCP Front Panel
  14  * @package ucp
  15  */
  16  class ucp_main
  17  {
  18      var $p_master;
  19      var $u_action;
  20      
  21  	function ucp_main(&$p_master)
  22      {
  23          $this->p_master = &$p_master;
  24      }
  25  
  26  	function main($id, $mode)
  27      {
  28          global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
  29  
  30          switch ($mode)
  31          {
  32              case 'front':
  33  
  34                  $user->add_lang('memberlist');
  35  
  36                  $sql_from = TOPICS_TABLE . ' t ';
  37                  $sql_select = '';
  38  
  39                  if ($config['load_db_track'])
  40                  {
  41                      $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id 
  42                          AND tp.user_id = ' . $user->data['user_id'] . ')';
  43                      $sql_select .= ', tp.topic_posted';
  44                  }
  45  
  46                  if ($config['load_db_lastread'])
  47                  {
  48                      $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id
  49                          AND tt.user_id = ' . $user->data['user_id'] . ')';
  50                      $sql_select .= ', tt.mark_time';
  51                  }
  52  
  53                  $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
  54                  $folder = 'global_read';
  55                  $folder_new = 'global_unread';
  56  
  57                  // Get cleaned up list... return only those forums not having the f_read permission
  58                  $forum_ary = $auth->acl_getf('!f_read', true);
  59                  $forum_ary = array_unique(array_keys($forum_ary));
  60  
  61                  // Determine first forum the user is able to read into - for global announcement link
  62                  $sql = 'SELECT forum_id 
  63                      FROM ' . FORUMS_TABLE . '
  64                      WHERE forum_type = ' . FORUM_POST;
  65      
  66                  if (sizeof($forum_ary))
  67                  {
  68                      $sql .= ' AND ' . $db->sql_in_set('forum_id', $forum_ary, true);
  69                  }
  70                  $result = $db->sql_query_limit($sql, 1);
  71                  $g_forum_id = (int) $db->sql_fetchfield('forum_id');
  72                  $db->sql_freeresult($result);
  73  
  74                  $sql = "SELECT t.* $sql_select 
  75                      FROM $sql_from
  76                      WHERE t.forum_id = 0
  77                          AND t.topic_type = " . POST_GLOBAL . '
  78                      ORDER BY t.topic_last_post_time DESC';
  79  
  80                  $topic_list = $rowset = array();
  81                  // If the user can't see any forums, he can't read any posts because fid of 0 is invalid
  82                  if ($g_forum_id)
  83                  {
  84                      $result = $db->sql_query($sql);
  85  
  86                      while ($row = $db->sql_fetchrow($result))
  87                      {
  88                          $topic_list[] = $row['topic_id'];
  89                          $rowset[$row['topic_id']] = $row;
  90                      }
  91                      $db->sql_freeresult($result);
  92                  }
  93  
  94                  $topic_tracking_info = array();
  95                  if ($config['load_db_lastread'])
  96                  {
  97                      $topic_tracking_info = get_topic_tracking(0, $topic_list, $rowset, false, $topic_list);
  98                  }
  99                  else
 100                  {
 101                      $topic_tracking_info = get_complete_topic_tracking(0, $topic_list, $topic_list);
 102                  }
 103  
 104                  foreach ($topic_list as $topic_id)
 105                  {
 106                      $row = &$rowset[$topic_id];
 107  
 108                      $forum_id = $row['forum_id'];
 109                      $topic_id = $row['topic_id'];
 110  
 111                      $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
 112  
 113                      $folder_img = ($unread_topic) ? $folder_new : $folder;
 114                      $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
 115  
 116                      if ($row['topic_status'] == ITEM_LOCKED)
 117                      {
 118                          $folder_img .= '_locked';
 119                      }
 120  
 121                      // Posted image?
 122                      if (!empty($row['topic_posted']) && $row['topic_posted'])
 123                      {
 124                          $folder_img .= '_mine';
 125                      }
 126  
 127                      $template->assign_block_vars('topicrow', array(
 128                          'FORUM_ID'            => $forum_id,
 129                          'TOPIC_ID'            => $topic_id,
 130                          'LAST_POST_SUBJECT'    => $row['topic_last_post_subject'],
 131                          'LAST_POST_TIME'    => $user->format_date($row['topic_last_post_time']),
 132                          'LAST_POST_AUTHOR'    => ($row['topic_last_poster_id'] == ANONYMOUS) ? (($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] . ' ' : $user->lang['GUEST'] . ' ') : $row['topic_last_poster_name'],
 133                          'LAST_POST_AUTHOR_COLOUR'    => ($row['topic_last_poster_colour']) ? '#' . $row['topic_last_poster_colour'] : '',
 134                          'TOPIC_TITLE'        => censor_text($row['topic_title']),
 135                          'TOPIC_TYPE'        => $topic_type,
 136  
 137                          'LAST_POST_IMG'            => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
 138                          'NEWEST_POST_IMG'        => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
 139                          'TOPIC_FOLDER_IMG'        => $user->img($folder_img, $folder_alt),
 140                          'TOPIC_FOLDER_IMG_SRC'    => $user->img($folder_img, $folder_alt, false, '', 'src'),
 141                          'ATTACH_ICON_IMG'        => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', '') : '',
 142  
 143                          'S_USER_POSTED'        => (!empty($row['topic_posted']) && $row['topic_posted']) ? true : false,
 144                          'S_UNREAD'            => $unread_topic,
 145  
 146                          'U_LAST_POST'            => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$g_forum_id&amp;t=$topic_id&amp;p=" . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
 147                          'U_LAST_POST_AUTHOR'    => ($row['topic_last_poster_id'] != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u='  . $row['topic_last_poster_id']) : '',
 148                          'U_NEWEST_POST'            => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$g_forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
 149                          'U_VIEW_TOPIC'            => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$g_forum_id&amp;t=$topic_id"))
 150                      );
 151                  }
 152  
 153                  if ($config['load_user_activity'])
 154                  {
 155                      if (!function_exists('display_user_activity'))
 156                      {
 157                          include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 158                      }
 159                      display_user_activity($user->data);
 160                  }
 161  
 162                  // Do the relevant calculations 
 163                  $memberdays = max(1, round((time() - $user->data['user_regdate']) / 86400));
 164                  $posts_per_day = $user->data['user_posts'] / $memberdays;
 165                  $percentage = ($config['num_posts']) ? min(100, ($user->data['user_posts'] / $config['num_posts']) * 100) : 0;
 166  
 167                  $template->assign_vars(array(
 168                      'USER_COLOR'        => (!empty($user->data['user_colour'])) ? $user->data['user_colour'] : '', 
 169                      'JOINED'            => $user->format_date($user->data['user_regdate']),
 170                      'VISITED'            => (empty($last_visit)) ? ' - ' : $user->format_date($last_visit),
 171                      'WARNINGS'            => ($user->data['user_warnings']) ? $user->data['user_warnings'] : 0,
 172                      'POSTS'                => ($user->data['user_posts']) ? $user->data['user_posts'] : 0,
 173                      'POSTS_DAY'            => sprintf($user->lang['POST_DAY'], $posts_per_day),
 174                      'POSTS_PCT'            => sprintf($user->lang['POST_PCT'], $percentage),
 175  
 176                      'OCCUPATION'    => (!empty($row['user_occ'])) ? $row['user_occ'] : '',
 177                      'INTERESTS'        => (!empty($row['user_interests'])) ? $row['user_interests'] : '',
 178  
 179  //                    'S_GROUP_OPTIONS'    => $group_options, 
 180  
 181                      'U_SEARCH_USER'        => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user->data['user_id'] . '&amp;sr=posts') : '')
 182                  );
 183              break;
 184  
 185              case 'subscribed':
 186  
 187                  include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 188  
 189                  $user->add_lang('viewforum');
 190  
 191                  $unwatch = (isset($_POST['unwatch'])) ? true : false;
 192  
 193                  if ($unwatch)
 194                  {
 195                      $forums = (isset($_POST['f'])) ? array_map('intval', array_keys($_POST['f'])) : array();
 196                      $topics = (isset($_POST['t'])) ? array_map('intval', array_keys($_POST['t'])) : array();
 197  
 198                      if (sizeof($forums) || sizeof($topics))
 199                      {
 200                          $l_unwatch = '';
 201                          if (sizeof($forums))
 202                          {
 203                              $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . '
 204                                  WHERE ' . $db->sql_in_set('forum_id', $forums) . '
 205                                      AND user_id = ' . $user->data['user_id'];
 206                              $db->sql_query($sql);
 207  
 208                              $l_unwatch .= '_FORUMS';
 209                          }
 210  
 211                          if (sizeof($topics))
 212                          {
 213                              $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
 214                                  WHERE ' . $db->sql_in_set('topic_id', $topics) . '
 215                                      AND user_id = ' . $user->data['user_id'];
 216                              $db->sql_query($sql);
 217  
 218                              $l_unwatch .= '_TOPICS';
 219                          }
 220  
 221                          $message = $user->lang['UNWATCHED' . $l_unwatch] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=subscribed") . '">', '</a>');
 222  
 223                          meta_refresh(3, append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=subscribed"));
 224                          trigger_error($message);
 225                      }
 226                  }
 227  
 228                  $sql_array = array(
 229                      'SELECT'    => 'f.*',
 230  
 231                      'FROM'        => array(
 232                          FORUMS_WATCH_TABLE    => 'fw',
 233                          FORUMS_TABLE        => 'f'
 234                      ),
 235  
 236                      'WHERE'        => 'fw.user_id = ' . $user->data['user_id'] . ' 
 237                          AND f.forum_id = fw.forum_id',
 238  
 239                      'ORDER_BY'    => 'left_id'
 240                  );
 241  
 242                  if ($config['load_db_lastread'])
 243                  {
 244                      $sql_array['LEFT_JOIN'] = array(
 245                          array(
 246                              'FROM'    => array(FORUMS_TRACK_TABLE => 'ft'),
 247                              'ON'    => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
 248                          )
 249                      );
 250  
 251                      $sql_array['SELECT'] .= ', ft.mark_time ';
 252                  }
 253                  else
 254                  {
 255                      $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
 256                      $tracking_topics = ($tracking_topics) ? unserialize($tracking_topics) : array();
 257                  }
 258  
 259                  $sql = $db->sql_build_query('SELECT', $sql_array);
 260                  $result = $db->sql_query($sql);
 261  
 262                  while ($row = $db->sql_fetchrow($result))
 263                  {
 264                      $forum_id = $row['forum_id'];
 265  
 266                      if ($config['load_db_lastread'])
 267                      {
 268                          $forum_check = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
 269                      }
 270                      else
 271                      {
 272                          $forum_check = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
 273                      }
 274  
 275                      $unread_forum = ($row['forum_last_post_time'] > $forum_check) ? true : false;
 276  
 277                      // Which folder should we display?
 278                      if ($row['forum_status'] == ITEM_LOCKED)
 279                      {
 280                          $folder_image = ($unread_forum) ? 'forum_unread_locked' : 'forum_read_locked';
 281                          $folder_alt = 'FORUM_LOCKED';
 282                      }
 283                      else
 284                      {
 285                          $folder_image = ($unread_forum) ? 'forum_unread' : 'forum_read';
 286                          $folder_alt = ($unread_forum) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
 287                      }
 288  
 289                      // Create last post link information, if appropriate
 290                      if ($row['forum_last_post_id'])
 291                      {
 292                          $last_post_time = $user->format_date($row['forum_last_post_time']);
 293  
 294                          $last_poster = ($row['forum_last_poster_name'] != '') ? $row['forum_last_poster_name'] : $user->lang['GUEST'];
 295                          $last_poster_colour = ($row['forum_last_poster_colour']) ? '#' . $row['forum_last_poster_colour'] : '';
 296                          $last_poster_url = ($row['forum_last_poster_id'] == ANONYMOUS) ? '' : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u='  . $row['forum_last_poster_id']);
 297  
 298                          $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;p=" . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
 299                      }
 300                      else
 301                      {
 302                          $last_post_time = $last_poster = $last_poster_url = $last_post_url = '';
 303                      }
 304  
 305                      $template->assign_block_vars('forumrow', array(
 306                          'FORUM_ID'                => $forum_id, 
 307                          'FORUM_FOLDER_IMG'        => $user->img($folder_image, $folder_alt),
 308                          'FORUM_FOLDER_IMG_SRC'    => $user->img($folder_image, $folder_alt, false, '', 'src'),
 309                          'FORUM_IMAGE'            => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
 310                          'FORUM_IMAGE_SRC'        => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
 311                          'FORUM_NAME'            => $row['forum_name'],
 312                          'LAST_POST_IMG'            => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
 313                          'LAST_POST_SUBJECT'        => $row['forum_last_post_subject'],
 314                          'LAST_POST_TIME'        => $last_post_time,
 315                          'LAST_POST_AUTHOR'        => $last_poster,
 316                          'LAST_POST_AUTHOR_COLOUR' => $last_poster_colour,
 317  
 318                          'U_LAST_POST_AUTHOR'    => $last_poster_url, 
 319                          'U_LAST_POST'            => $last_post_url, 
 320                          'U_VIEWFORUM'            => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
 321                      );
 322                  }
 323                  $db->sql_freeresult($result);
 324  
 325                  // Subscribed Topics
 326                  $start = request_var('start', 0);
 327      
 328                  $sql = 'SELECT COUNT(topic_id) as topics_count
 329                      FROM ' . TOPICS_WATCH_TABLE . '
 330                      WHERE user_id = ' . $user->data['user_id'];
 331                  $result = $db->sql_query($sql);
 332                  $topics_count = (int) $db->sql_fetchfield('topics_count');
 333                  $db->sql_freeresult($result);
 334  
 335                  if ($topics_count)
 336                  {
 337                      $template->assign_vars(array(
 338                          'PAGINATION'    => generate_pagination($this->u_action, $topics_count, $config['topics_per_page'], $start),
 339                          'PAGE_NUMBER'    => on_page($topics_count, $config['topics_per_page'], $start),
 340                          'TOTAL_TOPICS'    => ($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count))
 341                      );
 342                  }
 343  
 344                  $sql_array = array(
 345                      'SELECT'    => 't.*',
 346  
 347                      'FROM'        => array(
 348                          TOPICS_WATCH_TABLE    => 'tw',
 349                          TOPICS_TABLE        => 't'
 350                      ),
 351  
 352                      'WHERE'        => 'tw.user_id = ' . $user->data['user_id'] . '
 353                          AND t.topic_id = tw.topic_id',
 354  
 355                      'ORDER_BY'    => 't.topic_last_post_time DESC'
 356                  );
 357  
 358                  if ($config['load_db_lastread'])
 359                  {
 360                      $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']);
 361                      $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']);
 362                      $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time';
 363                  }
 364  
 365                  if ($config['load_db_track'])
 366                  {
 367                      $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']);
 368                      $sql_array['SELECT'] .= ', tp.topic_posted';
 369                  }
 370  
 371                  $sql = $db->sql_build_query('SELECT', $sql_array);
 372                  $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
 373  
 374                  $topic_list = $topic_forum_list = $global_announce_list = $rowset = array();
 375                  while ($row = $db->sql_fetchrow($result))
 376                  {
 377                      $topic_list[] = $row['topic_id'];
 378                      $rowset[$row['topic_id']] = $row;
 379  
 380                      $topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread']) ? $row['forum_mark_time'] : 0;
 381                      $topic_forum_list[$row['forum_id']]['topics'][] = $row['topic_id'];
 382  
 383                      if ($row['topic_type'] == POST_GLOBAL)
 384                      {
 385                          $global_announce_list[] = $row['topic_id'];
 386                      }
 387                  }
 388                  $db->sql_freeresult($result);
 389  
 390                  $topic_tracking_info = array();
 391                  if ($config['load_db_lastread'])
 392                  {
 393                      foreach ($topic_forum_list as $f_id => $topic_row)
 394                      {
 395                          $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), ($f_id == 0) ? $global_announce_list : false);
 396                      }
 397                  }
 398                  else
 399                  {
 400                      foreach ($topic_forum_list as $f_id => $topic_row)
 401                      {
 402                          $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], $global_announce_list);
 403                      }
 404                  }
 405  
 406                  foreach ($topic_list as $topic_id)
 407                  {
 408                      $row = &$rowset[$topic_id];
 409  
 410                      $forum_id = $row['forum_id'];
 411                      $topic_id = $row['topic_id'];
 412  
 413                      $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
 414  
 415                      // Replies
 416                      $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
 417  
 418                      if ($row['topic_status'] == ITEM_MOVED)
 419                      {
 420                          $topic_id = $row['topic_moved_id'];
 421                      }
 422  
 423                      // Get folder img, topic status/type related informations
 424                      $folder_img = $folder_alt = $topic_type = '';
 425                      topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
 426                      
 427                      $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id");
 428                      
 429                      // Send vars to template
 430                      $template->assign_block_vars('topicrow', array(
 431                          'FORUM_ID'                    => $forum_id,
 432                          'TOPIC_ID'                    => $topic_id,
 433                          'TOPIC_AUTHOR'                => ($row['topic_first_poster_name']) ? $row['topic_first_poster_name'] : $user->lang['GUEST'],
 434                          'TOPIC_AUTHOR_COLOUR'        => ($row['topic_first_poster_colour']) ? '#' . $row['topic_first_poster_colour'] : '',
 435                          'FIRST_POST_TIME'            => $user->format_date($row['topic_time']),
 436                          'LAST_POST_SUBJECT'            => $row['topic_last_post_subject'],
 437                          'LAST_POST_TIME'            => $user->format_date($row['topic_last_post_time']),
 438                          'LAST_VIEW_TIME'            => $user->format_date($row['topic_last_view_time']),
 439                          'LAST_POST_AUTHOR'            => ($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] : $user->lang['GUEST'],
 440                          'LAST_POST_AUTHOR_COLOUR'    => ($row['topic_last_poster_colour']) ? '#' . $row['topic_last_poster_colour'] : '',
 441  
 442                          'PAGINATION'        => topic_generate_pagination($replies, append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . "&amp;t=$topic_id")),
 443                          'REPLIES'            => $replies,
 444                          'VIEWS'                => $row['topic_views'],
 445                          'TOPIC_TITLE'        => censor_text($row['topic_title']),
 446                          'TOPIC_TYPE'        => $topic_type,
 447  
 448                          'LAST_POST_IMG'            => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
 449                          'NEWEST_POST_IMG'        => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
 450                          'TOPIC_FOLDER_IMG'        => $user->img($folder_img, $folder_alt),
 451                          'TOPIC_FOLDER_IMG_SRC'    => $user->img($folder_img, $folder_alt, false, '', 'src'),
 452                          'TOPIC_ICON_IMG'        => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
 453                          'TOPIC_ICON_IMG_WIDTH'    => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
 454                          'TOPIC_ICON_IMG_HEIGHT'    => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
 455                          'ATTACH_ICON_IMG'        => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
 456  
 457                          'S_TOPIC_TYPE'            => $row['topic_type'],
 458                          'S_USER_POSTED'            => (!empty($row['topic_posted'])) ? true : false,
 459                          'S_UNREAD_TOPIC'        => $unread_topic,
 460  
 461                          'U_NEWEST_POST'            => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
 462                          'U_LAST_POST'            => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'],
 463                          'U_LAST_POST_AUTHOR'    => ($row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['topic_last_poster_id']) : '',
 464                          'U_TOPIC_AUTHOR'        => ($row['topic_poster'] != ANONYMOUS && $row['topic_poster']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['topic_poster']) : '',
 465                          'U_VIEW_TOPIC'            => $view_topic_url)
 466                      );
 467                  }
 468  
 469              break;
 470  
 471              case 'bookmarks':
 472  
 473                  if (!$config['allow_bookmarks'])
 474                  {
 475                      $template->assign_vars(array(
 476                          'S_NO_DISPLAY_BOOKMARKS'    => true)
 477                      );
 478                      break;
 479                  }
 480  
 481                  include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 482  
 483                  $user->add_lang('viewforum');
 484  
 485                  $move_up = request_var('move_up', 0);
 486                  $move_down = request_var('move_down', 0);
 487  
 488                  $sql = 'SELECT MAX(order_id) as max_order_id
 489                      FROM ' . BOOKMARKS_TABLE . '
 490                      WHERE user_id = ' . $user->data['user_id'];
 491                  $result = $db->sql_query($sql);
 492                  $max_order_id = (int) $db->sql_fetchfield('max_order_id');
 493                  $db->sql_freeresult($result);
 494  
 495                  if ($move_up || $move_down)
 496                  {
 497                      if (($move_up && $move_up != 1) || ($move_down && $move_down != $max_order_id))
 498                      {
 499                          $order = ($move_up) ? $move_up : $move_down;
 500                          $order_total = $order * 2 + (($move_up) ? -1 : 1);
 501          
 502                          $sql = 'UPDATE ' . BOOKMARKS_TABLE . "
 503                              SET order_id = $order_total - order_id
 504                              WHERE order_id IN ($order, " . (($move_up) ? $order - 1 : $order + 1) . ')
 505                                  AND user_id = ' . $user->data['user_id'];
 506                          $db->sql_query($sql);
 507                      }
 508                  }
 509  
 510                  if (isset($_POST['unbookmark']))
 511                  {
 512                      $s_hidden_fields = array('unbookmark' => 1);
 513                      $topics = (isset($_POST['t'])) ? array_map('intval', array_keys($_POST['t'])) : array();
 514                      $url = $this->u_action;
 515  
 516                      if (!sizeof($topics))
 517                      {
 518                          trigger_error('NO_BOOKMARKS_SELECTED');
 519                      }
 520  
 521                      foreach ($topics as $topic_id)
 522                      {
 523                          $s_hidden_fields['t'][$topic_id] = 1;
 524                      }
 525  
 526                      if (confirm_box(true))
 527                      {
 528                          $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . '
 529                              WHERE user_id = ' . $user->data['user_id'] . '
 530                                  AND ' . $db->sql_in_set('topic_id', $topics);
 531                          $db->sql_query($sql);
 532  
 533                          // Re-Order bookmarks (possible with one query? This query massaker is not really acceptable...)
 534                          $sql = 'SELECT topic_id FROM ' . BOOKMARKS_TABLE . '
 535                              WHERE user_id = ' . $user->data['user_id'] . '
 536                              ORDER BY order_id ASC';
 537                          $result = $db->sql_query($sql);
 538  
 539                          $i = 1;
 540                          while ($row = $db->sql_fetchrow($result))
 541                          {
 542                              $sql = 'UPDATE ' . BOOKMARKS_TABLE . "
 543                                  SET order_id = $i
 544                                  WHERE topic_id = {$row['topic_id']}
 545                                      AND user_id = {$user->data['user_id']}";
 546                              $db->sql_query($sql);
 547  
 548                              $i++;
 549                          }
 550                          $db->sql_freeresult($result);
 551  
 552                          meta_refresh(3, $url);
 553                          $message = $user->lang['BOOKMARKS_REMOVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>');
 554                          trigger_error($message);
 555                      }
 556                      else
 557                      {
 558                          confirm_box(false, 'REMOVE_SELECTED_BOOKMARKS', build_hidden_fields($s_hidden_fields));
 559                      }
 560                  }
 561  
 562                  // We grab deleted topics here too...
 563                  // NOTE: At the moment bookmarks are not removed with topics, might be useful later (not really sure how though. :D)
 564                  // But since bookmarks are sensible to the user, they should not be deleted without notice.
 565                  $sql = 'SELECT b.order_id, b.topic_id as b_topic_id, t.*, f.forum_name
 566                      FROM ' . BOOKMARKS_TABLE . ' b
 567                          LEFT JOIN ' . TOPICS_TABLE . ' t ON (b.topic_id = t.topic_id)
 568                          LEFT JOIN ' . FORUMS_TABLE . ' f ON (t.forum_id = f.forum_id)
 569                      WHERE b.user_id = ' . $user->data['user_id'] . '
 570                      ORDER BY b.order_id ASC';
 571                  $result = $db->sql_query($sql);
 572  
 573                  while ($row = $db->sql_fetchrow($result))
 574                  {
 575                      $forum_id = $row['forum_id'];
 576                      $topic_id = $row['b_topic_id'];
 577  
 578                      $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
 579  
 580                      // Get folder img, topic status/type related informations
 581                      $folder_img = $folder_alt = $topic_type = '';
 582                      $unread_topic = false;
 583  
 584                      topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
 585                      $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id");
 586  
 587                      $template->assign_block_vars('topicrow', array(
 588                          'FORUM_ID'            => $forum_id,
 589                          'TOPIC_ID'            => $topic_id,
 590                          'TOPIC_TITLE'        => censor_text($row['topic_title']),
 591                          'TOPIC_TYPE'        => $topic_type,
 592                          'FORUM_NAME'        => $row['forum_name'],
 593  
 594                          'S_DELETED_TOPIC'    => (!$row['topic_id']) ? true : false,
 595                          'S_GLOBAL_TOPIC'    => (!$forum_id) ? true : false,
 596  
 597                          'TOPIC_AUTHOR'                => ($row['topic_first_poster_name']) ? $row['topic_first_poster_name'] : $user->lang['GUEST'],
 598                          'TOPIC_AUTHOR_COLOUR'        => ($row['topic_first_poster_colour']) ? '#' . $row['topic_first_poster_colour'] : '',
 599                          'FIRST_POST_TIME'            => $user->format_date($row['topic_time']),
 600                          'LAST_POST_SUBJECT'            => $row['topic_last_post_subject'],
 601                          'LAST_POST_TIME'            => $user->format_date($row['topic_last_post_time']),
 602                          'LAST_VIEW_TIME'            => $user->format_date($row['topic_last_view_time']),
 603                          'LAST_POST_AUTHOR'            => ($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] : $user->lang['GUEST'],
 604                          'LAST_POST_AUTHOR_COLOUR'    => ($row['topic_last_poster_colour']) ? '#' . $row['topic_last_poster_colour'] : '',
 605  
 606                          'PAGINATION'        => topic_generate_pagination($replies, append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . "&amp;t=$topic_id")),
 607                          'POSTED_AT'            => $user->format_date($row['topic_time']),
 608  
 609                          'TOPIC_FOLDER_IMG'        => $user->img($folder_img, $folder_alt),
 610                          'TOPIC_FOLDER_IMG_SRC'    => $user->img($folder_img, $folder_alt, false, '', 'src'),
 611                          'ATTACH_ICON_IMG'        => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', '') : '',
 612                          'LAST_POST_IMG'            => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
 613  
 614                          'U_LAST_POST'            => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'],
 615                          'U_LAST_POST_AUTHOR'    => ($row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['topic_last_poster_id']) : '',
 616                          'U_TOPIC_AUTHOR'        => ($row['topic_poster'] != ANONYMOUS && $row['topic_poster']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['topic_poster']) : '',
 617                          'U_VIEW_TOPIC'            => $view_topic_url,
 618                          'U_VIEW_FORUM'            => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
 619                          'U_MOVE_UP'                => ($row['order_id'] != 1) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=main&amp;mode=bookmarks&amp;move_up=' . $row['order_id']) : '',
 620                          'U_MOVE_DOWN'            => ($row['order_id'] != $max_order_id) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=main&amp;mode=bookmarks&amp;move_down=' . $row['order_id']) : '')
 621                      );
 622                  }
 623  
 624              break;
 625  
 626              case 'drafts':
 627  
 628                  $pm_drafts = ($this->p_master->p_name == 'pm') ? true : false;
 629                  $template->assign_var('S_SHOW_DRAFTS', true);
 630  
 631                  $user->add_lang('posting');
 632  
 633                  $edit        = (isset($_REQUEST['edit'])) ? true : false;
 634                  $submit        = (isset($_POST['submit'])) ? true : false;
 635                  $draft_id    = ($edit) ? intval($_REQUEST['edit']) : 0;
 636                  $delete        = (isset($_POST['delete'])) ? true : false;
 637  
 638                  $s_hidden_fields = ($edit) ? '<input type="hidden" name="edit" value="' . $draft_id . '" />' : '';
 639                  $draft_subject = $draft_message = '';
 640  
 641                  if ($delete)
 642                  {
 643                      $drafts = (!empty($_POST['d'])) ? array_map('intval', array_keys($_POST['d'])) : array();
 644  
 645                      if (sizeof($drafts))
 646                      {
 647                          $sql = 'DELETE FROM ' . DRAFTS_TABLE . '
 648                              WHERE ' . $db->sql_in_set('draft_id', $drafts) . '
 649                                  AND user_id = ' . $user->data['user_id'];
 650                          $db->sql_query($sql);
 651  
 652                          $message = $user->lang['DRAFTS_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
 653  
 654                          meta_refresh(3, $this->u_action);
 655                          trigger_error($message);
 656                      }
 657  
 658                      unset($drafts);
 659                  }
 660  
 661                  if ($submit && $edit)
 662                  {
 663                      $draft_subject = request_var('subject', '', true);
 664                      $draft_message = request_var('message', '', true);
 665                      
 666                      utf8_normalize_nfc(array(&$draft_subject, &$draft_message));
 667  
 668                      if ($draft_message && $draft_subject)
 669                      {
 670                          $draft_row = array(
 671                              'draft_subject' => $draft_subject,
 672                              'draft_message' => $draft_message
 673                          );
 674  
 675                          $sql = 'UPDATE ' . DRAFTS_TABLE . ' 
 676                              SET ' . $db->sql_build_array('UPDATE', $draft_row) . " 
 677                              WHERE draft_id = $draft_id
 678                                  AND user_id = " . $user->data['user_id'];
 679                          $db->sql_query($sql);
 680  
 681                          $message = $user->lang['DRAFT_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
 682  
 683                          meta_refresh(3, $this->u_action);
 684                          trigger_error($message);
 685                      }
 686                      else
 687                      {
 688                          $template->assign_var('ERROR', ($draft_message == '') ? $user->lang['EMPTY_DRAFT'] : (($draft_subject == '') ? $user->lang['EMPTY_DRAFT_TITLE'] : ''));
 689                      }
 690                  }
 691  
 692                  if (!$pm_drafts)
 693                  {
 694                      $sql = 'SELECT d.*, f.forum_name
 695                          FROM ' . DRAFTS_TABLE . ' d, ' . FORUMS_TABLE . ' f
 696                          WHERE d.user_id = ' . $user->data['user_id'] . ' ' .
 697                              (($edit) ? "AND d.draft_id = $draft_id" : '') . '
 698                              AND f.forum_id = d.forum_id
 699                          ORDER BY d.save_time DESC';
 700                  }
 701                  else
 702                  {
 703                      $sql = 'SELECT * FROM ' . DRAFTS_TABLE . '
 704                          WHERE user_id = ' . $user->data['user_id'] . ' ' .
 705                              (($edit) ? "AND draft_id = $draft_id" : '') . '
 706                              AND forum_id = 0 
 707                              AND topic_id = 0
 708                          ORDER BY save_time DESC';
 709                  }
 710                  $result = $db->sql_query($sql);
 711  
 712                  $draftrows = $topic_ids = array();
 713  
 714                  while ($row = $db->sql_fetchrow($result))
 715                  {
 716                      if ($row['topic_id'])
 717                      {
 718                          $topic_ids[] = (int) $row['topic_id'];
 719                      }
 720                      $draftrows[] = $row;
 721                  }
 722                  $db->sql_freeresult($result);
 723  
 724                  if (sizeof($topic_ids))
 725                  {
 726                      $sql = 'SELECT topic_id, forum_id, topic_title
 727                          FROM ' . TOPICS_TABLE . '
 728                          WHERE ' . $db->sql_in_set('topic_id', array_unique($topic_ids));
 729                      $result = $db->sql_query($sql);
 730  
 731                      while ($row = $db->sql_fetchrow($result))
 732                      {
 733                          $topic_rows[$row['topic_id']] = $row;
 734                      }
 735                      $db->sql_freeresult($result);
 736                  }
 737                  unset($topic_ids);
 738  
 739                  $template->assign_var('S_EDIT_DRAFT', $edit);
 740  
 741                  $row_count = 0;
 742                  foreach ($draftrows as $draft)
 743                  {
 744                      $link_topic = $link_forum = $link_pm = false;
 745                      $insert_url = $view_url = $title = '';
 746  
 747                      if (isset($topic_rows[$draft['topic_id']]) && $auth->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id']))
 748                      {
 749                          $link_topic = true;
 750                          $view_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&amp;t=' . $draft['topic_id']);
 751                          $title = $topic_rows[$draft['topic_id']]['topic_title'];
 752  
 753                          $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&amp;t=' . $draft['topic_id'] . '&amp;mode=reply&amp;d=' . $draft['draft_id']);
 754                      }
 755                      else if ($auth->acl_get('f_read', $draft['forum_id']))
 756                      {
 757                          $link_forum = true;
 758                          $view_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $draft['forum_id']);
 759                          $title = $draft['forum_name'];
 760  
 761                          $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $draft['forum_id'] . '&amp;mode=post&amp;d=' . $draft['draft_id']);
 762                      }
 763                      else if ($pm_drafts)
 764                      {
 765                          $link_pm = true;
 766                          $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=compose&amp;d=" . $draft['draft_id']);
 767                      }
 768  
 769                      $template_row = array(
 770                          'DATE'            => $user->format_date($draft['save_time']),
 771                          'DRAFT_MESSAGE'    => ($submit) ? $draft_message : $draft['draft_message'],
 772                          'DRAFT_SUBJECT'    => ($submit) ? $draft_subject : $draft['draft_subject'],
 773                          'TITLE'            => $title,
 774  
 775                          'DRAFT_ID'    => $draft['draft_id'],
 776                          'FORUM_ID'    => $draft['forum_id'],
 777                          'TOPIC_ID'    => $draft['topic_id'],
 778  
 779                          'U_VIEW'        => $view_url,
 780                          'U_VIEW_EDIT'    => $this->u_action . '&amp;edit=' . $draft['draft_id'],
 781                          'U_INSERT'        => $insert_url,
 782  
 783                          'S_LINK_TOPIC'        => $link_topic,
 784                          'S_LINK_FORUM'        => $link_forum,
 785                          'S_LINK_PM'            => $link_pm,
 786                          'S_HIDDEN_FIELDS'    => $s_hidden_fields
 787                      );
 788                      $row_count++;
 789  
 790                      ($edit) ? $template->assign_vars($template_row) : $template->assign_block_vars('draftrow', $template_row);
 791                  }
 792  
 793                  if (!$edit)
 794                  {
 795                      $template->assign_var('S_DRAFT_ROWS', $row_count);
 796                  }
 797  
 798              break;
 799          }
 800  
 801  
 802          $template->assign_vars(array( 
 803              'L_TITLE'            => $user->lang['UCP_MAIN_' . strtoupper($mode)],
 804  
 805              'S_DISPLAY_MARK_ALL'    => ($mode == 'watched' || ($mode == 'drafts' && !isset($_GET['edit']))) ? true : false, 
 806              'S_HIDDEN_FIELDS'        => (isset($s_hidden_fields)) ? $s_hidden_fields : '',
 807              'S_UCP_ACTION'            => $this->u_action)
 808          );
 809  
 810          // Set desired template
 811          $this->tpl_name = 'ucp_main_' . $mode;
 812          $this->page_title = 'UCP_MAIN_' . strtoupper($mode);
 813      }
 814  }
 815  
 816  ?>


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6