Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

acp_forums.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 67.92 KiB


 0001  <?php
 0002  /**
 0003  *
 0004  * This file is part of the phpBB Forum Software package.
 0005  *
 0006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 0007  * @license GNU General Public License, version 2 (GPL-2.0)
 0008  *
 0009  * For full copyright and license information, please see
 0010  * the docs/CREDITS.txt file.
 0011  *
 0012  */
 0013   
 0014  /**
 0015  * @ignore
 0016  */
 0017  if (!defined('IN_PHPBB'))
 0018  {
 0019      exit;
 0020  }
 0021   
 0022  class acp_forums
 0023  {
 0024      var $u_action;
 0025      var $parent_id = 0;
 0026   
 0027      function main($id, $mode)
 0028      {
 0029          global $db, $user, $auth, $template, $cache, $request, $phpbb_dispatcher;
 0030          global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
 0031   
 0032          $user->add_lang('acp/forums');
 0033          $this->tpl_name = 'acp_forums';
 0034          $this->page_title = 'ACP_MANAGE_FORUMS';
 0035   
 0036          $form_key = 'acp_forums';
 0037          add_form_key($form_key);
 0038   
 0039          $action        = request_var('action', '');
 0040          $update        = (isset($_POST['update'])) ? true : false;
 0041          $forum_id    = request_var('f', 0);
 0042   
 0043          $this->parent_id    = request_var('parent_id', 0);
 0044          $forum_data = $errors = array();
 0045          if ($update && !check_form_key($form_key))
 0046          {
 0047              $update = false;
 0048              $errors[] = $user->lang['FORM_INVALID'];
 0049          }
 0050   
 0051          // Check additional permissions
 0052          switch ($action)
 0053          {
 0054              case 'progress_bar':
 0055                  $start = request_var('start', 0);
 0056                  $total = request_var('total', 0);
 0057   
 0058                  $this->display_progress_bar($start, $total);
 0059              break;
 0060   
 0061              case 'delete':
 0062   
 0063                  if (!$auth->acl_get('a_forumdel'))
 0064                  {
 0065                      trigger_error($user->lang['NO_PERMISSION_FORUM_DELETE'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
 0066                  }
 0067   
 0068              break;
 0069   
 0070              case 'add':
 0071   
 0072                  if (!$auth->acl_get('a_forumadd'))
 0073                  {
 0074                      trigger_error($user->lang['NO_PERMISSION_FORUM_ADD'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
 0075                  }
 0076   
 0077              break;
 0078          }
 0079   
 0080          // Major routines
 0081          if ($update)
 0082          {
 0083              switch ($action)
 0084              {
 0085                  case 'delete':
 0086                      $action_subforums    = request_var('action_subforums', '');
 0087                      $subforums_to_id    = request_var('subforums_to_id', 0);
 0088                      $action_posts        = request_var('action_posts', '');
 0089                      $posts_to_id        = request_var('posts_to_id', 0);
 0090   
 0091                      $errors = $this->delete_forum($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
 0092   
 0093                      if (sizeof($errors))
 0094                      {
 0095                          break;
 0096                      }
 0097   
 0098                      $auth->acl_clear_prefetch();
 0099                      $cache->destroy('sql', FORUMS_TABLE);
 0100   
 0101                      trigger_error($user->lang['FORUM_DELETED'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
 0102   
 0103                  break;
 0104   
 0105                  case 'edit':
 0106                      $forum_data = array(
 0107                          'forum_id'        =>    $forum_id
 0108                      );
 0109   
 0110                  // No break here
 0111   
 0112                  case 'add':
 0113   
 0114                      $forum_data += array(
 0115                          'parent_id'                => request_var('forum_parent_id', $this->parent_id),
 0116                          'forum_type'            => request_var('forum_type', FORUM_POST),
 0117                          'type_action'            => request_var('type_action', ''),
 0118                          'forum_status'            => request_var('forum_status', ITEM_UNLOCKED),
 0119                          'forum_parents'            => '',
 0120                          'forum_name'            => utf8_normalize_nfc(request_var('forum_name', '', true)),
 0121                          'forum_link'            => request_var('forum_link', ''),
 0122                          'forum_link_track'        => request_var('forum_link_track', false),
 0123                          'forum_desc'            => utf8_normalize_nfc(request_var('forum_desc', '', true)),
 0124                          'forum_desc_uid'        => '',
 0125                          'forum_desc_options'    => 7,
 0126                          'forum_desc_bitfield'    => '',
 0127                          'forum_rules'            => utf8_normalize_nfc(request_var('forum_rules', '', true)),
 0128                          'forum_rules_uid'        => '',
 0129                          'forum_rules_options'    => 7,
 0130                          'forum_rules_bitfield'    => '',
 0131                          'forum_rules_link'        => request_var('forum_rules_link', ''),
 0132                          'forum_image'            => request_var('forum_image', ''),
 0133                          'forum_style'            => request_var('forum_style', 0),
 0134                          'display_subforum_list'    => request_var('display_subforum_list', false),
 0135                          'display_on_index'        => request_var('display_on_index', false),
 0136                          'forum_topics_per_page'    => request_var('topics_per_page', 0),
 0137                          'enable_indexing'        => request_var('enable_indexing', true),
 0138                          'enable_icons'            => request_var('enable_icons', false),
 0139                          'enable_prune'            => request_var('enable_prune', false),
 0140                          'enable_post_review'    => request_var('enable_post_review', true),
 0141                          'enable_quick_reply'    => request_var('enable_quick_reply', false),
 0142                          'enable_shadow_prune'        => request_var('enable_shadow_prune', false),
 0143                          'prune_days'            => request_var('prune_days', 7),
 0144                          'prune_viewed'            => request_var('prune_viewed', 7),
 0145                          'prune_freq'            => request_var('prune_freq', 1),
 0146                          'prune_old_polls'        => request_var('prune_old_polls', false),
 0147                          'prune_announce'        => request_var('prune_announce', false),
 0148                          'prune_sticky'            => request_var('prune_sticky', false),
 0149                          'prune_shadow_days'        => request_var('prune_shadow_days', 7),
 0150                          'prune_shadow_freq'        => request_var('prune_shadow_freq', 1),
 0151                          'forum_password'        => request_var('forum_password', '', true),
 0152                          'forum_password_confirm'=> request_var('forum_password_confirm', '', true),
 0153                          'forum_password_unset'    => request_var('forum_password_unset', false),
 0154                      );
 0155   
 0156                      /**
 0157                      * Request forum data and operate on it (parse texts, etc.)
 0158                      *
 0159                      * @event core.acp_manage_forums_request_data
 0160                      * @var    string    action        Type of the action: add|edit
 0161                      * @var    array    forum_data    Array with new forum data
 0162                      * @since 3.1.0-a1
 0163                      */
 0164                      $vars = array('action', 'forum_data');
 0165                      extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_request_data', compact($vars)));
 0166   
 0167                      // On add, add empty forum_options... else do not consider it (not updating it)
 0168                      if ($action == 'add')
 0169                      {
 0170                          $forum_data['forum_options'] = 0;
 0171                      }
 0172   
 0173                      // Use link_display_on_index setting if forum type is link
 0174                      if ($forum_data['forum_type'] == FORUM_LINK)
 0175                      {
 0176                          $forum_data['display_on_index'] = request_var('link_display_on_index', false);
 0177                      }
 0178   
 0179                      // Linked forums and categories are not able to be locked...
 0180                      if ($forum_data['forum_type'] == FORUM_LINK || $forum_data['forum_type'] == FORUM_CAT)
 0181                      {
 0182                          $forum_data['forum_status'] = ITEM_UNLOCKED;
 0183                      }
 0184   
 0185                      $forum_data['show_active'] = ($forum_data['forum_type'] == FORUM_POST) ? request_var('display_recent', true) : request_var('display_active', false);
 0186   
 0187                      // Get data for forum rules if specified...
 0188                      if ($forum_data['forum_rules'])
 0189                      {
 0190                          generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], request_var('rules_parse_bbcode', false), request_var('rules_parse_urls', false), request_var('rules_parse_smilies', false));
 0191                      }
 0192   
 0193                      // Get data for forum description if specified
 0194                      if ($forum_data['forum_desc'])
 0195                      {
 0196                          generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], request_var('desc_parse_bbcode', false), request_var('desc_parse_urls', false), request_var('desc_parse_smilies', false));
 0197                      }
 0198   
 0199                      $errors = $this->update_forum_data($forum_data);
 0200   
 0201                      if (!sizeof($errors))
 0202                      {
 0203                          $forum_perm_from = request_var('forum_perm_from', 0);
 0204                          $cache->destroy('sql', FORUMS_TABLE);
 0205   
 0206                          $copied_permissions = false;
 0207                          // Copy permissions?
 0208                          if ($forum_perm_from && $forum_perm_from != $forum_data['forum_id'] &&
 0209                              ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))))
 0210                          {
 0211                              copy_forum_permissions($forum_perm_from, $forum_data['forum_id'], ($action == 'edit') ? true : false);
 0212                              phpbb_cache_moderators($db, $cache, $auth);
 0213                              $copied_permissions = true;
 0214                          }
 0215  /* Commented out because of questionable UI workflow - re-visit for 3.0.7
 0216                          else if (!$this->parent_id && $action != 'edit' && $auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))
 0217                          {
 0218                              $this->copy_permission_page($forum_data);
 0219                              return;
 0220                          }
 0221  */
 0222                          $auth->acl_clear_prefetch();
 0223   
 0224                          $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_data['forum_id'];
 0225   
 0226                          $message = ($action == 'add') ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED'];
 0227   
 0228                          // redirect directly to permission settings screen if authed
 0229                          if ($action == 'add' && !$copied_permissions && $auth->acl_get('a_fauth'))
 0230                          {
 0231                              $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
 0232   
 0233                              meta_refresh(4, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url));
 0234                          }
 0235   
 0236                          trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
 0237                      }
 0238   
 0239                  break;
 0240              }
 0241          }
 0242   
 0243          switch ($action)
 0244          {
 0245              case 'move_up':
 0246              case 'move_down':
 0247   
 0248                  if (!$forum_id)
 0249                  {
 0250                      trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
 0251                  }
 0252   
 0253                  $sql = 'SELECT *
 0254                      FROM ' . FORUMS_TABLE . "
 0255                      WHERE forum_id = $forum_id";
 0256                  $result = $db->sql_query($sql);
 0257                  $row = $db->sql_fetchrow($result);
 0258                  $db->sql_freeresult($result);
 0259   
 0260                  if (!$row)
 0261                  {
 0262                      trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
 0263                  }
 0264   
 0265                  $move_forum_name = $this->move_forum_by($row, $action, 1);
 0266   
 0267                  if ($move_forum_name !== false)
 0268                  {
 0269                      add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name);
 0270                      $cache->destroy('sql', FORUMS_TABLE);
 0271                  }
 0272   
 0273                  if ($request->is_ajax())
 0274                  {
 0275                      $json_response = new \phpbb\json_response;
 0276                      $json_response->send(array('success' => ($move_forum_name !== false)));
 0277                  }
 0278   
 0279              break;
 0280   
 0281              case 'sync':
 0282                  if (!$forum_id)
 0283                  {
 0284                      trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
 0285                  }
 0286   
 0287                  @set_time_limit(0);
 0288   
 0289                  $sql = 'SELECT forum_name, (forum_topics_approved + forum_topics_unapproved + forum_topics_softdeleted) AS total_topics
 0290                      FROM ' . FORUMS_TABLE . "
 0291                      WHERE forum_id = $forum_id";
 0292                  $result = $db->sql_query($sql);
 0293                  $row = $db->sql_fetchrow($result);
 0294                  $db->sql_freeresult($result);
 0295   
 0296                  if (!$row)
 0297                  {
 0298                      trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
 0299                  }
 0300   
 0301                  if ($row['total_topics'])
 0302                  {
 0303                      $sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id
 0304                          FROM ' . TOPICS_TABLE . '
 0305                          WHERE forum_id = ' . $forum_id;
 0306                      $result = $db->sql_query($sql);
 0307                      $row2 = $db->sql_fetchrow($result);
 0308                      $db->sql_freeresult($result);
 0309   
 0310                      // Typecast to int if there is no data available
 0311                      $row2['min_topic_id'] = (int) $row2['min_topic_id'];
 0312                      $row2['max_topic_id'] = (int) $row2['max_topic_id'];
 0313   
 0314                      $start = request_var('start', $row2['min_topic_id']);
 0315   
 0316                      $batch_size = 2000;
 0317                      $end = $start + $batch_size;
 0318   
 0319                      // Sync all topics in batch mode...
 0320                      sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true);
 0321   
 0322                      if ($end < $row2['max_topic_id'])
 0323                      {
 0324                          // We really need to find a way of showing statistics... no progress here
 0325                          $sql = 'SELECT COUNT(topic_id) as num_topics
 0326                              FROM ' . TOPICS_TABLE . '
 0327                              WHERE forum_id = ' . $forum_id . '
 0328                                  AND topic_id BETWEEN ' . $start . ' AND ' . $end;
 0329                          $result = $db->sql_query($sql);
 0330                          $topics_done = request_var('topics_done', 0) + (int) $db->sql_fetchfield('num_topics');
 0331                          $db->sql_freeresult($result);
 0332   
 0333                          $start += $batch_size;
 0334   
 0335                          $url = $this->u_action . "&amp;parent_id={$this->parent_id}&amp;f=$forum_id&amp;action=sync&amp;start=$start&amp;topics_done=$topics_done&amp;total={$row['total_topics']}";
 0336   
 0337                          meta_refresh(0, $url);
 0338   
 0339                          $template->assign_vars(array(
 0340                              'U_PROGRESS_BAR'        => $this->u_action . "&amp;action=progress_bar&amp;start=$topics_done&amp;total={$row['total_topics']}",
 0341                              'UA_PROGRESS_BAR'        => addslashes($this->u_action . "&amp;action=progress_bar&amp;start=$topics_done&amp;total={$row['total_topics']}"),
 0342                              'S_CONTINUE_SYNC'        => true,
 0343                              'L_PROGRESS_EXPLAIN'    => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['total_topics']))
 0344                          );
 0345   
 0346                          return;
 0347                      }
 0348                  }
 0349   
 0350                  $url = $this->u_action . "&amp;parent_id={$this->parent_id}&amp;f=$forum_id&amp;action=sync_forum";
 0351                  meta_refresh(0, $url);
 0352   
 0353                  $template->assign_vars(array(
 0354                      'U_PROGRESS_BAR'        => $this->u_action . '&amp;action=progress_bar',
 0355                      'UA_PROGRESS_BAR'        => addslashes($this->u_action . '&amp;action=progress_bar'),
 0356                      'S_CONTINUE_SYNC'        => true,
 0357                      'L_PROGRESS_EXPLAIN'    => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['total_topics']))
 0358                  );
 0359   
 0360                  return;
 0361   
 0362              break;
 0363   
 0364              case 'sync_forum':
 0365   
 0366                  $sql = 'SELECT forum_name, forum_type
 0367                      FROM ' . FORUMS_TABLE . "
 0368                      WHERE forum_id = $forum_id";
 0369                  $result = $db->sql_query($sql);
 0370                  $row = $db->sql_fetchrow($result);
 0371                  $db->sql_freeresult($result);
 0372   
 0373                  if (!$row)
 0374                  {
 0375                      trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
 0376                  }
 0377   
 0378                  sync('forum', 'forum_id', $forum_id, false, true);
 0379   
 0380                  add_log('admin', 'LOG_FORUM_SYNC', $row['forum_name']);
 0381                  $cache->destroy('sql', FORUMS_TABLE);
 0382   
 0383                  $template->assign_var('L_FORUM_RESYNCED', sprintf($user->lang['FORUM_RESYNCED'], $row['forum_name']));
 0384   
 0385              break;
 0386   
 0387              case 'add':
 0388              case 'edit':
 0389   
 0390                  if ($update)
 0391                  {
 0392                      $forum_data['forum_flags'] = 0;
 0393                      $forum_data['forum_flags'] += (request_var('forum_link_track', false)) ? FORUM_FLAG_LINK_TRACK : 0;
 0394                      $forum_data['forum_flags'] += (request_var('prune_old_polls', false)) ? FORUM_FLAG_PRUNE_POLL : 0;
 0395                      $forum_data['forum_flags'] += (request_var('prune_announce', false)) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
 0396                      $forum_data['forum_flags'] += (request_var('prune_sticky', false)) ? FORUM_FLAG_PRUNE_STICKY : 0;
 0397                      $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
 0398                      $forum_data['forum_flags'] += (request_var('enable_post_review', true)) ? FORUM_FLAG_POST_REVIEW : 0;
 0399                      $forum_data['forum_flags'] += (request_var('enable_quick_reply', false)) ? FORUM_FLAG_QUICK_REPLY : 0;
 0400                  }
 0401   
 0402                  // Initialise $row, so we always have it in the event
 0403                  $row = array();
 0404   
 0405                  // Show form to create/modify a forum
 0406                  if ($action == 'edit')
 0407                  {
 0408                      $this->page_title = 'EDIT_FORUM';
 0409                      $row = $this->get_forum_info($forum_id);
 0410                      $old_forum_type = $row['forum_type'];
 0411   
 0412                      if (!$update)
 0413                      {
 0414                          $forum_data = $row;
 0415                      }
 0416                      else
 0417                      {
 0418                          $forum_data['left_id'] = $row['left_id'];
 0419                          $forum_data['right_id'] = $row['right_id'];
 0420                      }
 0421   
 0422                      // Make sure no direct child forums are able to be selected as parents.
 0423                      $exclude_forums = array();
 0424                      foreach (get_forum_branch($forum_id, 'children') as $row)
 0425                      {
 0426                          $exclude_forums[] = $row['forum_id'];
 0427                      }
 0428   
 0429                      $parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false);
 0430   
 0431                      $forum_data['forum_password_confirm'] = $forum_data['forum_password'];
 0432                  }
 0433                  else
 0434                  {
 0435                      $this->page_title = 'CREATE_FORUM';
 0436   
 0437                      $forum_id = $this->parent_id;
 0438                      $parents_list = make_forum_select($this->parent_id, false, false, false, false);
 0439   
 0440                      // Fill forum data with default values
 0441                      if (!$update)
 0442                      {
 0443                          $forum_data = array(
 0444                              'parent_id'                => $this->parent_id,
 0445                              'forum_type'            => FORUM_POST,
 0446                              'forum_status'            => ITEM_UNLOCKED,
 0447                              'forum_name'            => utf8_normalize_nfc(request_var('forum_name', '', true)),
 0448                              'forum_link'            => '',
 0449                              'forum_link_track'        => false,
 0450                              'forum_desc'            => '',
 0451                              'forum_rules'            => '',
 0452                              'forum_rules_link'        => '',
 0453                              'forum_image'            => '',
 0454                              'forum_style'            => 0,
 0455                              'display_subforum_list'    => true,
 0456                              'display_on_index'        => false,
 0457                              'forum_topics_per_page'    => 0,
 0458                              'enable_indexing'        => true,
 0459                              'enable_icons'            => false,
 0460                              'enable_prune'            => false,
 0461                              'prune_days'            => 7,
 0462                              'prune_viewed'            => 7,
 0463                              'prune_freq'            => 1,
 0464                              'enable_shadow_prune'        => false,
 0465                              'prune_shadow_days'        => 7,
 0466                              'prune_shadow_freq'        => 1,
 0467                              'forum_flags'            => FORUM_FLAG_POST_REVIEW + FORUM_FLAG_ACTIVE_TOPICS,
 0468                              'forum_options'            => 0,
 0469                              'forum_password'        => '',
 0470                              'forum_password_confirm'=> '',
 0471                          );
 0472                      }
 0473                  }
 0474   
 0475                  /**
 0476                  * Initialise data before we display the add/edit form
 0477                  *
 0478                  * @event core.acp_manage_forums_initialise_data
 0479                  * @var    string    action        Type of the action: add|edit
 0480                  * @var    bool    update        Do we display the form only
 0481                  *                            or did the user press submit
 0482                  * @var    int        forum_id    When editing: the forum id,
 0483                  *                            when creating: the parent forum id
 0484                  * @var    array    row            Array with current forum data
 0485                  *                            empty when creating new forum
 0486                  * @var    array    forum_data    Array with new forum data
 0487                  * @var    string    parents_list    List of parent options
 0488                  * @since 3.1.0-a1
 0489                  */
 0490                  $vars = array('action', 'update', 'forum_id', 'row', 'forum_data', 'parents_list');
 0491                  extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_initialise_data', compact($vars)));
 0492   
 0493                  $forum_rules_data = array(
 0494                      'text'            => $forum_data['forum_rules'],
 0495                      'allow_bbcode'    => true,
 0496                      'allow_smilies'    => true,
 0497                      'allow_urls'    => true
 0498                  );
 0499   
 0500                  $forum_desc_data = array(
 0501                      'text'            => $forum_data['forum_desc'],
 0502                      'allow_bbcode'    => true,
 0503                      'allow_smilies'    => true,
 0504                      'allow_urls'    => true
 0505                  );
 0506   
 0507                  $forum_rules_preview = '';
 0508   
 0509                  // Parse rules if specified
 0510                  if ($forum_data['forum_rules'])
 0511                  {
 0512                      if (!isset($forum_data['forum_rules_uid']))
 0513                      {
 0514                          // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
 0515                          $forum_data['forum_rules_uid'] = '';
 0516                          $forum_data['forum_rules_bitfield'] = '';
 0517                          $forum_data['forum_rules_options'] = 0;
 0518   
 0519                          generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], request_var('rules_allow_bbcode', false), request_var('rules_allow_urls', false), request_var('rules_allow_smilies', false));
 0520                      }
 0521   
 0522                      // Generate preview content
 0523                      $forum_rules_preview = generate_text_for_display($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options']);
 0524   
 0525                      // decode...
 0526                      $forum_rules_data = generate_text_for_edit($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_options']);
 0527                  }
 0528   
 0529                  // Parse desciption if specified
 0530                  if ($forum_data['forum_desc'])
 0531                  {
 0532                      if (!isset($forum_data['forum_desc_uid']))
 0533                      {
 0534                          // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
 0535                          $forum_data['forum_desc_uid'] = '';
 0536                          $forum_data['forum_desc_bitfield'] = '';
 0537                          $forum_data['forum_desc_options'] = 0;
 0538   
 0539                          generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], request_var('desc_allow_bbcode', false), request_var('desc_allow_urls', false), request_var('desc_allow_smilies', false));
 0540                      }
 0541   
 0542                      // decode...
 0543                      $forum_desc_data = generate_text_for_edit($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_options']);
 0544                  }
 0545   
 0546                  $forum_type_options = '';
 0547                  $forum_type_ary = array(FORUM_CAT => 'CAT', FORUM_POST => 'FORUM', FORUM_LINK => 'LINK');
 0548   
 0549                  foreach ($forum_type_ary as $value => $lang)
 0550                  {
 0551                      $forum_type_options .= '<option value="' . $value . '"' . (($value == $forum_data['forum_type']) ? ' selected="selected"' : '') . '>' . $user->lang['TYPE_' . $lang] . '</option>';
 0552                  }
 0553   
 0554                  $styles_list = style_select($forum_data['forum_style'], true);
 0555   
 0556                  $statuslist = '<option value="' . ITEM_UNLOCKED . '"' . (($forum_data['forum_status'] == ITEM_UNLOCKED) ? ' selected="selected"' : '') . '>' . $user->lang['UNLOCKED'] . '</option><option value="' . ITEM_LOCKED . '"' . (($forum_data['forum_status'] == ITEM_LOCKED) ? ' selected="selected"' : '') . '>' . $user->lang['LOCKED'] . '</option>';
 0557   
 0558                  $sql = 'SELECT forum_id
 0559                      FROM ' . FORUMS_TABLE . '
 0560                      WHERE forum_type = ' . FORUM_POST . "
 0561                          AND forum_id <> $forum_id";
 0562                  $result = $db->sql_query_limit($sql, 1);
 0563   
 0564                  $postable_forum_exists = false;
 0565                  if ($db->sql_fetchrow($result))
 0566                  {
 0567                      $postable_forum_exists = true;
 0568                  }
 0569                  $db->sql_freeresult($result);
 0570   
 0571                  // Subforum move options
 0572                  if ($action == 'edit' && $forum_data['forum_type'] == FORUM_CAT)
 0573                  {
 0574                      $subforums_id = array();
 0575                      $subforums = get_forum_branch($forum_id, 'children');
 0576   
 0577                      foreach ($subforums as $row)
 0578                      {
 0579                          $subforums_id[] = $row['forum_id'];
 0580                      }
 0581   
 0582                      $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
 0583   
 0584                      if ($postable_forum_exists)
 0585                      {
 0586                          $template->assign_vars(array(
 0587                              'S_MOVE_FORUM_OPTIONS'        => make_forum_select($forum_data['parent_id'], $subforums_id)) // , false, true, false???
 0588                          );
 0589                      }
 0590   
 0591                      $template->assign_vars(array(
 0592                          'S_HAS_SUBFORUMS'        => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
 0593                          'S_FORUMS_LIST'            => $forums_list)
 0594                      );
 0595                  }
 0596                  else if ($postable_forum_exists)
 0597                  {
 0598                      $template->assign_vars(array(
 0599                          'S_MOVE_FORUM_OPTIONS'        => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))
 0600                      );
 0601                  }
 0602   
 0603                  $s_show_display_on_index = false;
 0604   
 0605                  if ($forum_data['parent_id'] > 0)
 0606                  {
 0607                      // if this forum is a subforum put the "display on index" checkbox
 0608                      if ($parent_info = $this->get_forum_info($forum_data['parent_id']))
 0609                      {
 0610                          if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT)
 0611                          {
 0612                              $s_show_display_on_index = true;
 0613                          }
 0614                      }
 0615                  }
 0616   
 0617                  if (strlen($forum_data['forum_password']) == 32)
 0618                  {
 0619                      $errors[] = $user->lang['FORUM_PASSWORD_OLD'];
 0620                  }
 0621   
 0622                  $template_data = array(
 0623                      'S_EDIT_FORUM'        => true,
 0624                      'S_ERROR'            => (sizeof($errors)) ? true : false,
 0625                      'S_PARENT_ID'        => $this->parent_id,
 0626                      'S_FORUM_PARENT_ID'    => $forum_data['parent_id'],
 0627                      'S_ADD_ACTION'        => ($action == 'add') ? true : false,
 0628   
 0629                      'U_BACK'        => $this->u_action . '&amp;parent_id=' . $this->parent_id,
 0630                      'U_EDIT_ACTION'    => $this->u_action . "&amp;parent_id={$this->parent_id}&amp;action=$action&amp;f=$forum_id",
 0631   
 0632                      'L_COPY_PERMISSIONS_EXPLAIN'    => $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'],
 0633                      'L_TITLE'                        => $user->lang[$this->page_title],
 0634                      'ERROR_MSG'                        => (sizeof($errors)) ? implode('<br />', $errors) : '',
 0635   
 0636                      'FORUM_NAME'                => $forum_data['forum_name'],
 0637                      'FORUM_DATA_LINK'            => $forum_data['forum_link'],
 0638                      'FORUM_IMAGE'                => $forum_data['forum_image'],
 0639                      'FORUM_IMAGE_SRC'            => ($forum_data['forum_image']) ? $phpbb_root_path . $forum_data['forum_image'] : '',
 0640                      'FORUM_POST'                => FORUM_POST,
 0641                      'FORUM_LINK'                => FORUM_LINK,
 0642                      'FORUM_CAT'                    => FORUM_CAT,
 0643                      'PRUNE_FREQ'                => $forum_data['prune_freq'],
 0644                      'PRUNE_DAYS'                => $forum_data['prune_days'],
 0645                      'PRUNE_VIEWED'                => $forum_data['prune_viewed'],
 0646                      'PRUNE_SHADOW_FREQ'            => $forum_data['prune_shadow_freq'],
 0647                      'PRUNE_SHADOW_DAYS'            => $forum_data['prune_shadow_days'],
 0648                      'TOPICS_PER_PAGE'            => $forum_data['forum_topics_per_page'],
 0649                      'FORUM_RULES_LINK'            => $forum_data['forum_rules_link'],
 0650                      'FORUM_RULES'                => $forum_data['forum_rules'],
 0651                      'FORUM_RULES_PREVIEW'        => $forum_rules_preview,
 0652                      'FORUM_RULES_PLAIN'            => $forum_rules_data['text'],
 0653                      'S_BBCODE_CHECKED'            => ($forum_rules_data['allow_bbcode']) ? true : false,
 0654                      'S_SMILIES_CHECKED'            => ($forum_rules_data['allow_smilies']) ? true : false,
 0655                      'S_URLS_CHECKED'            => ($forum_rules_data['allow_urls']) ? true : false,
 0656                      'S_FORUM_PASSWORD_SET'        => (empty($forum_data['forum_password'])) ? false : true,
 0657   
 0658                      'FORUM_DESC'                => $forum_desc_data['text'],
 0659                      'S_DESC_BBCODE_CHECKED'        => ($forum_desc_data['allow_bbcode']) ? true : false,
 0660                      'S_DESC_SMILIES_CHECKED'    => ($forum_desc_data['allow_smilies']) ? true : false,
 0661                      'S_DESC_URLS_CHECKED'        => ($forum_desc_data['allow_urls']) ? true : false,
 0662   
 0663                      'S_FORUM_TYPE_OPTIONS'        => $forum_type_options,
 0664                      'S_STATUS_OPTIONS'            => $statuslist,
 0665                      'S_PARENT_OPTIONS'            => $parents_list,
 0666                      'S_STYLES_OPTIONS'            => $styles_list,
 0667                      'S_FORUM_OPTIONS'            => make_forum_select(($action == 'add') ? $forum_data['parent_id'] : false, ($action == 'edit') ? $forum_data['forum_id'] : false, false, false, false),
 0668                      'S_SHOW_DISPLAY_ON_INDEX'    => $s_show_display_on_index,
 0669                      'S_FORUM_POST'                => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
 0670                      'S_FORUM_ORIG_POST'            => (isset($old_forum_type) && $old_forum_type == FORUM_POST) ? true : false,
 0671                      'S_FORUM_ORIG_CAT'            => (isset($old_forum_type) && $old_forum_type == FORUM_CAT) ? true : false,
 0672                      'S_FORUM_ORIG_LINK'            => (isset($old_forum_type) && $old_forum_type == FORUM_LINK) ? true : false,
 0673                      'S_FORUM_LINK'                => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
 0674                      'S_FORUM_CAT'                => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
 0675                      'S_ENABLE_INDEXING'            => ($forum_data['enable_indexing']) ? true : false,
 0676                      'S_TOPIC_ICONS'                => ($forum_data['enable_icons']) ? true : false,
 0677                      'S_DISPLAY_SUBFORUM_LIST'    => ($forum_data['display_subforum_list']) ? true : false,
 0678                      'S_DISPLAY_ON_INDEX'        => ($forum_data['display_on_index']) ? true : false,
 0679                      'S_PRUNE_ENABLE'            => ($forum_data['enable_prune']) ? true : false,
 0680                      'S_PRUNE_SHADOW_ENABLE'            => ($forum_data['enable_shadow_prune']) ? true : false,
 0681                      'S_FORUM_LINK_TRACK'        => ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? true : false,
 0682                      'S_PRUNE_OLD_POLLS'            => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL) ? true : false,
 0683                      'S_PRUNE_ANNOUNCE'            => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE) ? true : false,
 0684                      'S_PRUNE_STICKY'            => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_STICKY) ? true : false,
 0685                      'S_DISPLAY_ACTIVE_TOPICS'    => ($forum_data['forum_type'] == FORUM_POST) ? ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) : true,
 0686                      'S_ENABLE_ACTIVE_TOPICS'    => ($forum_data['forum_type'] == FORUM_CAT) ? ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) : false,
 0687                      'S_ENABLE_POST_REVIEW'        => ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,
 0688                      'S_ENABLE_QUICK_REPLY'        => ($forum_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) ? true : false,
 0689                      'S_CAN_COPY_PERMISSIONS'    => ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))) ? true : false,
 0690                  );
 0691   
 0692                  /**
 0693                  * Modify forum template data before we display the form
 0694                  *
 0695                  * @event core.acp_manage_forums_display_form
 0696                  * @var    string    action        Type of the action: add|edit
 0697                  * @var    bool    update        Do we display the form only
 0698                  *                            or did the user press submit
 0699                  * @var    int        forum_id    When editing: the forum id,
 0700                  *                            when creating: the parent forum id
 0701                  * @var    array    row            Array with current forum data
 0702                  *                            empty when creating new forum
 0703                  * @var    array    forum_data    Array with new forum data
 0704                  * @var    string    parents_list    List of parent options
 0705                  * @var    array    errors        Array of errors, if you add errors
 0706                  *                    ensure to update the template variables
 0707                  *                    S_ERROR and ERROR_MSG to display it
 0708                  * @var    array    template_data    Array with new forum data
 0709                  * @since 3.1.0-a1
 0710                  */
 0711                  $vars = array(
 0712                      'action',
 0713                      'update',
 0714                      'forum_id',
 0715                      'row',
 0716                      'forum_data',
 0717                      'parents_list',
 0718                      'errors',
 0719                      'template_data',
 0720                  );
 0721                  extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_display_form', compact($vars)));
 0722   
 0723                  $template->assign_vars($template_data);
 0724   
 0725                  return;
 0726   
 0727              break;
 0728   
 0729              case 'delete':
 0730   
 0731                  if (!$forum_id)
 0732                  {
 0733                      trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
 0734                  }
 0735   
 0736                  $forum_data = $this->get_forum_info($forum_id);
 0737   
 0738                  $subforums_id = array();
 0739                  $subforums = get_forum_branch($forum_id, 'children');
 0740   
 0741                  foreach ($subforums as $row)
 0742                  {
 0743                      $subforums_id[] = $row['forum_id'];
 0744                  }
 0745   
 0746                  $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
 0747   
 0748                  $sql = 'SELECT forum_id
 0749                      FROM ' . FORUMS_TABLE . '
 0750                      WHERE forum_type = ' . FORUM_POST . "
 0751                          AND forum_id <> $forum_id";
 0752                  $result = $db->sql_query_limit($sql, 1);
 0753   
 0754                  if ($db->sql_fetchrow($result))
 0755                  {
 0756                      $template->assign_vars(array(
 0757                          'S_MOVE_FORUM_OPTIONS'        => make_forum_select($forum_data['parent_id'], $subforums_id, false, true)) // , false, true, false???
 0758                      );
 0759                  }
 0760                  $db->sql_freeresult($result);
 0761   
 0762                  $parent_id = ($this->parent_id == $forum_id) ? 0 : $this->parent_id;
 0763   
 0764                  $template->assign_vars(array(
 0765                      'S_DELETE_FORUM'        => true,
 0766                      'U_ACTION'                => $this->u_action . "&amp;parent_id={$parent_id}&amp;action=delete&amp;f=$forum_id",
 0767                      'U_BACK'                => $this->u_action . '&amp;parent_id=' . $this->parent_id,
 0768   
 0769                      'FORUM_NAME'            => $forum_data['forum_name'],
 0770                      'S_FORUM_POST'            => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
 0771                      'S_FORUM_LINK'            => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
 0772                      'S_HAS_SUBFORUMS'        => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
 0773                      'S_FORUMS_LIST'            => $forums_list,
 0774                      'S_ERROR'                => (sizeof($errors)) ? true : false,
 0775                      'ERROR_MSG'                => (sizeof($errors)) ? implode('<br />', $errors) : '')
 0776                  );
 0777   
 0778                  return;
 0779              break;
 0780   
 0781              case 'copy_perm':
 0782                  $forum_perm_from = request_var('forum_perm_from', 0);
 0783   
 0784                  // Copy permissions?
 0785                  if (!empty($forum_perm_from) && $forum_perm_from != $forum_id)
 0786                  {
 0787                      copy_forum_permissions($forum_perm_from, $forum_id, true);
 0788                      phpbb_cache_moderators($db, $cache, $auth);
 0789                      $auth->acl_clear_prefetch();
 0790                      $cache->destroy('sql', FORUMS_TABLE);
 0791   
 0792                      $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_id;
 0793   
 0794                      $message = $user->lang['FORUM_UPDATED'];
 0795   
 0796                      // Redirect to permissions
 0797                      if ($auth->acl_get('a_fauth'))
 0798                      {
 0799                          $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
 0800                      }
 0801   
 0802                      trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
 0803                  }
 0804   
 0805              break;
 0806          }
 0807   
 0808          // Default management page
 0809          if (!$this->parent_id)
 0810          {
 0811              $navigation = $user->lang['FORUM_INDEX'];
 0812          }
 0813          else
 0814          {
 0815              $navigation = '<a href="' . $this->u_action . '">' . $user->lang['FORUM_INDEX'] . '</a>';
 0816   
 0817              $forums_nav = get_forum_branch($this->parent_id, 'parents', 'descending');
 0818              foreach ($forums_nav as $row)
 0819              {
 0820                  if ($row['forum_id'] == $this->parent_id)
 0821                  {
 0822                      $navigation .= ' -&gt; ' . $row['forum_name'];
 0823                  }
 0824                  else
 0825                  {
 0826                      $navigation .= ' -&gt; <a href="' . $this->u_action . '&amp;parent_id=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>';
 0827                  }
 0828              }
 0829          }
 0830   
 0831          // Jumpbox
 0832          $forum_box = make_forum_select($this->parent_id, false, false, false, false); //make_forum_select($this->parent_id);
 0833   
 0834          if ($action == 'sync' || $action == 'sync_forum')
 0835          {
 0836              $template->assign_var('S_RESYNCED', true);
 0837          }
 0838   
 0839          $sql = 'SELECT *
 0840              FROM ' . FORUMS_TABLE . "
 0841              WHERE parent_id = $this->parent_id
 0842              ORDER BY left_id";
 0843          $result = $db->sql_query($sql);
 0844   
 0845          if ($row = $db->sql_fetchrow($result))
 0846          {
 0847              do
 0848              {
 0849                  $forum_type = $row['forum_type'];
 0850   
 0851                  if ($row['forum_status'] == ITEM_LOCKED)
 0852                  {
 0853                      $folder_image = '<img src="images/icon_folder_lock.gif" alt="' . $user->lang['LOCKED'] . '" />';
 0854                  }
 0855                  else
 0856                  {
 0857                      switch ($forum_type)
 0858                      {
 0859                          case FORUM_LINK:
 0860                              $folder_image = '<img src="images/icon_folder_link.gif" alt="' . $user->lang['LINK'] . '" />';
 0861                          break;
 0862   
 0863                          default:
 0864                              $folder_image = ($row['left_id'] + 1 != $row['right_id']) ? '<img src="images/icon_subfolder.gif" alt="' . $user->lang['SUBFORUM'] . '" />' : '<img src="images/icon_folder.gif" alt="' . $user->lang['FOLDER'] . '" />';
 0865                          break;
 0866                      }
 0867                  }
 0868   
 0869                  $url = $this->u_action . "&amp;parent_id=$this->parent_id&amp;f={$row['forum_id']}";
 0870   
 0871                  $template->assign_block_vars('forums', array(
 0872                      'FOLDER_IMAGE'        => $folder_image,
 0873                      'FORUM_IMAGE'        => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '',
 0874                      'FORUM_IMAGE_SRC'    => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
 0875                      'FORUM_NAME'        => $row['forum_name'],
 0876                      'FORUM_DESCRIPTION'    => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
 0877                      'FORUM_TOPICS'        => $row['forum_topics_approved'],
 0878                      'FORUM_POSTS'        => $row['forum_posts_approved'],
 0879   
 0880                      'S_FORUM_LINK'        => ($forum_type == FORUM_LINK) ? true : false,
 0881                      'S_FORUM_POST'        => ($forum_type == FORUM_POST) ? true : false,
 0882   
 0883                      'U_FORUM'            => $this->u_action . '&amp;parent_id=' . $row['forum_id'],
 0884                      'U_MOVE_UP'            => $url . '&amp;action=move_up',
 0885                      'U_MOVE_DOWN'        => $url . '&amp;action=move_down',
 0886                      'U_EDIT'            => $url . '&amp;action=edit',
 0887                      'U_DELETE'            => $url . '&amp;action=delete',
 0888                      'U_SYNC'            => $url . '&amp;action=sync')
 0889                  );
 0890              }
 0891              while ($row = $db->sql_fetchrow($result));
 0892          }
 0893          else if ($this->parent_id)
 0894          {
 0895              $row = $this->get_forum_info($this->parent_id);
 0896   
 0897              $url = $this->u_action . '&amp;parent_id=' . $this->parent_id . '&amp;f=' . $row['forum_id'];
 0898   
 0899              $template->assign_vars(array(
 0900                  'S_NO_FORUMS'        => true,
 0901   
 0902                  'U_EDIT'            => $url . '&amp;action=edit',
 0903                  'U_DELETE'            => $url . '&amp;action=delete',
 0904                  'U_SYNC'            => $url . '&amp;action=sync')
 0905              );
 0906          }
 0907          $db->sql_freeresult($result);
 0908   
 0909          $template->assign_vars(array(
 0910              'ERROR_MSG'        => (sizeof($errors)) ? implode('<br />', $errors) : '',
 0911              'NAVIGATION'    => $navigation,
 0912              'FORUM_BOX'        => $forum_box,
 0913              'U_SEL_ACTION'    => $this->u_action,
 0914              'U_ACTION'        => $this->u_action . '&amp;parent_id=' . $this->parent_id,
 0915   
 0916              'U_PROGRESS_BAR'    => $this->u_action . '&amp;action=progress_bar',
 0917              'UA_PROGRESS_BAR'    => addslashes($this->u_action . '&amp;action=progress_bar'),
 0918          ));
 0919      }
 0920   
 0921      /**
 0922      * Get forum details
 0923      */
 0924      function get_forum_info($forum_id)
 0925      {
 0926          global $db;
 0927   
 0928          $sql = 'SELECT *
 0929              FROM ' . FORUMS_TABLE . "
 0930              WHERE forum_id = $forum_id";
 0931          $result = $db->sql_query($sql);
 0932          $row = $db->sql_fetchrow($result);
 0933          $db->sql_freeresult($result);
 0934   
 0935          if (!$row)
 0936          {
 0937              trigger_error("Forum #$forum_id does not exist", E_USER_ERROR);
 0938          }
 0939   
 0940          return $row;
 0941      }
 0942   
 0943      /**
 0944      * Update forum data
 0945      */
 0946      function update_forum_data(&$forum_data)
 0947      {
 0948          global $db, $user, $cache, $phpbb_root_path, $phpbb_container, $phpbb_dispatcher;
 0949   
 0950          $errors = array();
 0951   
 0952          /**
 0953          * Validate the forum data before we create/update the forum
 0954          *
 0955          * @event core.acp_manage_forums_validate_data
 0956          * @var    array    forum_data    Array with new forum data
 0957          * @var    array    errors        Array of errors, should be strings and not
 0958          *                            language key.
 0959          * @since 3.1.0-a1
 0960          */
 0961          $vars = array('forum_data', 'errors');
 0962          extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_validate_data', compact($vars)));
 0963   
 0964          if ($forum_data['forum_name'] == '')
 0965          {
 0966              $errors[] = $user->lang['FORUM_NAME_EMPTY'];
 0967          }
 0968   
 0969          if (utf8_strlen($forum_data['forum_desc']) > 4000)
 0970          {
 0971              $errors[] = $user->lang['FORUM_DESC_TOO_LONG'];
 0972          }
 0973   
 0974          if (utf8_strlen($forum_data['forum_rules']) > 4000)
 0975          {
 0976              $errors[] = $user->lang['FORUM_RULES_TOO_LONG'];
 0977          }
 0978   
 0979          if ($forum_data['forum_password'] || $forum_data['forum_password_confirm'])
 0980          {
 0981              if ($forum_data['forum_password'] != $forum_data['forum_password_confirm'])
 0982              {
 0983                  $forum_data['forum_password'] = $forum_data['forum_password_confirm'] = '';
 0984                  $errors[] = $user->lang['FORUM_PASSWORD_MISMATCH'];
 0985              }
 0986          }
 0987   
 0988          if ($forum_data['prune_days'] < 0 || $forum_data['prune_viewed'] < 0 || $forum_data['prune_freq'] < 0)
 0989          {
 0990              $forum_data['prune_days'] = $forum_data['prune_viewed'] = $forum_data['prune_freq'] = 0;
 0991              $errors[] = $user->lang['FORUM_DATA_NEGATIVE'];
 0992          }
 0993   
 0994          $range_test_ary = array(
 0995              array('lang' => 'FORUM_TOPICS_PAGE', 'value' => $forum_data['forum_topics_per_page'], 'column_type' => 'TINT:0'),
 0996          );
 0997   
 0998          if (!empty($forum_data['forum_image']) && !file_exists($phpbb_root_path . $forum_data['forum_image']))
 0999          {
 1000              $errors[] = $user->lang['FORUM_IMAGE_NO_EXIST'];
 1001          }
 1002   
 1003          validate_range($range_test_ary, $errors);
 1004   
 1005          // Set forum flags
 1006          // 1 = link tracking
 1007          // 2 = prune old polls
 1008          // 4 = prune announcements
 1009          // 8 = prune stickies
 1010          // 16 = show active topics
 1011          // 32 = enable post review
 1012          $forum_data['forum_flags'] = 0;
 1013          $forum_data['forum_flags'] += ($forum_data['forum_link_track']) ? FORUM_FLAG_LINK_TRACK : 0;
 1014          $forum_data['forum_flags'] += ($forum_data['prune_old_polls']) ? FORUM_FLAG_PRUNE_POLL : 0;
 1015          $forum_data['forum_flags'] += ($forum_data['prune_announce']) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
 1016          $forum_data['forum_flags'] += ($forum_data['prune_sticky']) ? FORUM_FLAG_PRUNE_STICKY : 0;
 1017          $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
 1018          $forum_data['forum_flags'] += ($forum_data['enable_post_review']) ? FORUM_FLAG_POST_REVIEW : 0;
 1019          $forum_data['forum_flags'] += ($forum_data['enable_quick_reply']) ? FORUM_FLAG_QUICK_REPLY : 0;
 1020   
 1021          // Unset data that are not database fields
 1022          $forum_data_sql = $forum_data;
 1023   
 1024          unset($forum_data_sql['forum_link_track']);
 1025          unset($forum_data_sql['prune_old_polls']);
 1026          unset($forum_data_sql['prune_announce']);
 1027          unset($forum_data_sql['prune_sticky']);
 1028          unset($forum_data_sql['show_active']);
 1029          unset($forum_data_sql['enable_post_review']);
 1030          unset($forum_data_sql['enable_quick_reply']);
 1031          unset($forum_data_sql['forum_password_confirm']);
 1032   
 1033          // What are we going to do tonight Brain? The same thing we do everynight,
 1034          // try to take over the world ... or decide whether to continue update
 1035          // and if so, whether it's a new forum/cat/link or an existing one
 1036          if (sizeof($errors))
 1037          {
 1038              return $errors;
 1039          }
 1040   
 1041          // As we don't know the old password, it's kinda tricky to detect changes
 1042          if ($forum_data_sql['forum_password_unset'])
 1043          {
 1044              $forum_data_sql['forum_password'] = '';
 1045          }
 1046          else if (empty($forum_data_sql['forum_password']))
 1047          {
 1048              unset($forum_data_sql['forum_password']);
 1049          }
 1050          else
 1051          {
 1052              // Instantiate passwords manager
 1053              $passwords_manager = $phpbb_container->get('passwords.manager');
 1054   
 1055              $forum_data_sql['forum_password'] = $passwords_manager->hash($forum_data_sql['forum_password']);
 1056          }
 1057          unset($forum_data_sql['forum_password_unset']);
 1058   
 1059          /**
 1060          * Remove invalid values from forum_data_sql that should not be updated
 1061          *
 1062          * @event core.acp_manage_forums_update_data_before
 1063          * @var    array    forum_data        Array with forum data
 1064          * @var    array    forum_data_sql    Array with data we are going to update
 1065          *                        If forum_data_sql[forum_id] is set, we update
 1066          *                        that forum, otherwise a new one is created.
 1067          * @since 3.1.0-a1
 1068          */
 1069          $vars = array('forum_data', 'forum_data_sql');
 1070          extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_update_data_before', compact($vars)));
 1071   
 1072          $is_new_forum = !isset($forum_data_sql['forum_id']);
 1073   
 1074          if ($is_new_forum)
 1075          {
 1076              // no forum_id means we're creating a new forum
 1077              unset($forum_data_sql['type_action']);
 1078   
 1079              if ($forum_data_sql['parent_id'])
 1080              {
 1081                  $sql = 'SELECT left_id, right_id, forum_type
 1082                      FROM ' . FORUMS_TABLE . '
 1083                      WHERE forum_id = ' . $forum_data_sql['parent_id'];
 1084                  $result = $db->sql_query($sql);
 1085                  $row = $db->sql_fetchrow($result);
 1086                  $db->sql_freeresult($result);
 1087   
 1088                  if (!$row)
 1089                  {
 1090                      trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
 1091                  }
 1092   
 1093                  if ($row['forum_type'] == FORUM_LINK)
 1094                  {
 1095                      $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
 1096                      return $errors;
 1097                  }
 1098   
 1099                  $sql = 'UPDATE ' . FORUMS_TABLE . '
 1100                      SET left_id = left_id + 2, right_id = right_id + 2
 1101                      WHERE left_id > ' . $row['right_id'];
 1102                  $db->sql_query($sql);
 1103   
 1104                  $sql = 'UPDATE ' . FORUMS_TABLE . '
 1105                      SET right_id = right_id + 2
 1106                      WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
 1107                  $db->sql_query($sql);
 1108   
 1109                  $forum_data_sql['left_id'] = $row['right_id'];
 1110                  $forum_data_sql['right_id'] = $row['right_id'] + 1;
 1111              }
 1112              else
 1113              {
 1114                  $sql = 'SELECT MAX(right_id) AS right_id
 1115                      FROM ' . FORUMS_TABLE;
 1116                  $result = $db->sql_query($sql);
 1117                  $row = $db->sql_fetchrow($result);
 1118                  $db->sql_freeresult($result);
 1119   
 1120                  $forum_data_sql['left_id'] = $row['right_id'] + 1;
 1121                  $forum_data_sql['right_id'] = $row['right_id'] + 2;
 1122              }
 1123   
 1124              $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data_sql);
 1125              $db->sql_query($sql);
 1126   
 1127              $forum_data['forum_id'] = $db->sql_nextid();
 1128   
 1129              add_log('admin', 'LOG_FORUM_ADD', $forum_data['forum_name']);
 1130          }
 1131          else
 1132          {
 1133              $row = $this->get_forum_info($forum_data_sql['forum_id']);
 1134   
 1135              if ($row['forum_type'] == FORUM_POST && $row['forum_type'] != $forum_data_sql['forum_type'])
 1136              {
 1137                  // Has subforums and want to change into a link?
 1138                  if ($row['right_id'] - $row['left_id'] > 1 && $forum_data_sql['forum_type'] == FORUM_LINK)
 1139                  {
 1140                      $errors[] = $user->lang['FORUM_WITH_SUBFORUMS_NOT_TO_LINK'];
 1141                      return $errors;
 1142                  }
 1143   
 1144                  // we're turning a postable forum into a non-postable forum
 1145                  if ($forum_data_sql['type_action'] == 'move')
 1146                  {
 1147                      $to_forum_id = request_var('to_forum_id', 0);
 1148   
 1149                      if ($to_forum_id)
 1150                      {
 1151                          $errors = $this->move_forum_content($forum_data_sql['forum_id'], $to_forum_id);
 1152                      }
 1153                      else
 1154                      {
 1155                          return array($user->lang['NO_DESTINATION_FORUM']);
 1156                      }
 1157                  }
 1158                  else if ($forum_data_sql['type_action'] == 'delete')
 1159                  {
 1160                      $errors = $this->delete_forum_content($forum_data_sql['forum_id']);
 1161                  }
 1162                  else
 1163                  {
 1164                      return array($user->lang['NO_FORUM_ACTION']);
 1165                  }
 1166   
 1167                  $forum_data_sql['forum_posts_approved'] = $forum_data_sql['forum_posts_unapproved'] = $forum_data_sql['forum_posts_softdeleted'] = $forum_data_sql['forum_topics_approved'] = $forum_data_sql['forum_topics_unapproved'] = $forum_data_sql['forum_topics_softdeleted'] = 0;
 1168                  $forum_data_sql['forum_last_post_id'] = $forum_data_sql['forum_last_poster_id'] = $forum_data_sql['forum_last_post_time'] = 0;
 1169                  $forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = '';
 1170              }
 1171              else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_LINK)
 1172              {
 1173                  // Has subforums?
 1174                  if ($row['right_id'] - $row['left_id'] > 1)
 1175                  {
 1176                      // We are turning a category into a link - but need to decide what to do with the subforums.
 1177                      $action_subforums = request_var('action_subforums', '');
 1178                      $subforums_to_id = request_var('subforums_to_id', 0);
 1179   
 1180                      if ($action_subforums == 'delete')
 1181                      {
 1182                          $rows = get_forum_branch($row['forum_id'], 'children', 'descending', false);
 1183   
 1184                          foreach ($rows as $_row)
 1185                          {
 1186                              // Do not remove the forum id we are about to change. ;)
 1187                              if ($_row['forum_id'] == $row['forum_id'])
 1188                              {
 1189                                  continue;
 1190                              }
 1191   
 1192                              $forum_ids[] = $_row['forum_id'];
 1193                              $errors = array_merge($errors, $this->delete_forum_content($_row['forum_id']));
 1194                          }
 1195   
 1196                          if (sizeof($errors))
 1197                          {
 1198                              return $errors;
 1199                          }
 1200   
 1201                          if (sizeof($forum_ids))
 1202                          {
 1203                              $sql = 'DELETE FROM ' . FORUMS_TABLE . '
 1204                                  WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
 1205                              $db->sql_query($sql);
 1206   
 1207                              $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
 1208                                  WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
 1209                              $db->sql_query($sql);
 1210   
 1211                              $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
 1212                                  WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
 1213                              $db->sql_query($sql);
 1214   
 1215                              // Delete forum ids from extension groups table
 1216                              $sql = 'SELECT group_id, allowed_forums
 1217                                  FROM ' . EXTENSION_GROUPS_TABLE;
 1218                              $result = $db->sql_query($sql);
 1219   
 1220                              while ($_row = $db->sql_fetchrow($result))
 1221                              {
 1222                                  if (!$_row['allowed_forums'])
 1223                                  {
 1224                                      continue;
 1225                                  }
 1226   
 1227                                  $allowed_forums = unserialize(trim($_row['allowed_forums']));
 1228                                  $allowed_forums = array_diff($allowed_forums, $forum_ids);
 1229   
 1230                                  $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
 1231                                      SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
 1232                                      WHERE group_id = {$_row['group_id']}";
 1233                                  $db->sql_query($sql);
 1234                              }
 1235                              $db->sql_freeresult($result);
 1236   
 1237                              $cache->destroy('_extensions');
 1238                          }
 1239                      }
 1240                      else if ($action_subforums == 'move')
 1241                      {
 1242                          if (!$subforums_to_id)
 1243                          {
 1244                              return array($user->lang['NO_DESTINATION_FORUM']);
 1245                          }
 1246   
 1247                          $sql = 'SELECT forum_name
 1248                              FROM ' . FORUMS_TABLE . '
 1249                              WHERE forum_id = ' . $subforums_to_id;
 1250                          $result = $db->sql_query($sql);
 1251                          $_row = $db->sql_fetchrow($result);
 1252                          $db->sql_freeresult($result);
 1253   
 1254                          if (!$_row)
 1255                          {
 1256                              return array($user->lang['NO_FORUM']);
 1257                          }
 1258   
 1259                          $subforums_to_name = $_row['forum_name'];
 1260   
 1261                          $sql = 'SELECT forum_id
 1262                              FROM ' . FORUMS_TABLE . "
 1263                              WHERE parent_id = {$row['forum_id']}";
 1264                          $result = $db->sql_query($sql);
 1265   
 1266                          while ($_row = $db->sql_fetchrow($result))
 1267                          {
 1268                              $this->move_forum($_row['forum_id'], $subforums_to_id);
 1269                          }
 1270                          $db->sql_freeresult($result);
 1271   
 1272                          $sql = 'UPDATE ' . FORUMS_TABLE . "
 1273                              SET parent_id = $subforums_to_id
 1274                              WHERE parent_id = {$row['forum_id']}";
 1275                          $db->sql_query($sql);
 1276                      }
 1277   
 1278                      // Adjust the left/right id
 1279                      $sql = 'UPDATE ' . FORUMS_TABLE . '
 1280                          SET right_id = left_id + 1
 1281                          WHERE forum_id = ' . $row['forum_id'];
 1282                      $db->sql_query($sql);
 1283                  }
 1284              }
 1285              else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_POST)
 1286              {
 1287                  // Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum)
 1288                  $forum_data_sql['forum_posts_approved'] = 0;
 1289                  $forum_data_sql['forum_posts_unapproved'] = 0;
 1290                  $forum_data_sql['forum_posts_softdeleted'] = 0;
 1291                  $forum_data_sql['forum_topics_approved'] = 0;
 1292                  $forum_data_sql['forum_topics_unapproved'] = 0;
 1293                  $forum_data_sql['forum_topics_softdeleted'] = 0;
 1294                  $forum_data_sql['forum_last_post_id'] = 0;
 1295                  $forum_data_sql['forum_last_post_subject'] = '';
 1296                  $forum_data_sql['forum_last_post_time'] = 0;
 1297                  $forum_data_sql['forum_last_poster_id'] = 0;
 1298                  $forum_data_sql['forum_last_poster_name'] = '';
 1299                  $forum_data_sql['forum_last_poster_colour'] = '';
 1300              }
 1301   
 1302              if (sizeof($errors))
 1303              {
 1304                  return $errors;
 1305              }
 1306   
 1307              if ($row['parent_id'] != $forum_data_sql['parent_id'])
 1308              {
 1309                  if ($row['forum_id'] != $forum_data_sql['parent_id'])
 1310                  {
 1311                      $errors = $this->move_forum($forum_data_sql['forum_id'], $forum_data_sql['parent_id']);
 1312                  }
 1313                  else
 1314                  {
 1315                      $forum_data_sql['parent_id'] = $row['parent_id'];
 1316                  }
 1317              }
 1318   
 1319              if (sizeof($errors))
 1320              {
 1321                  return $errors;
 1322              }
 1323   
 1324              unset($forum_data_sql['type_action']);
 1325   
 1326              if ($row['forum_name'] != $forum_data_sql['forum_name'])
 1327              {
 1328                  // the forum name has changed, clear the parents list of all forums (for safety)
 1329                  $sql = 'UPDATE ' . FORUMS_TABLE . "
 1330                      SET forum_parents = ''";
 1331                  $db->sql_query($sql);
 1332              }
 1333   
 1334              // Setting the forum id to the forum id is not really received well by some dbs. ;)
 1335              $forum_id = $forum_data_sql['forum_id'];
 1336              unset($forum_data_sql['forum_id']);
 1337   
 1338              $sql = 'UPDATE ' . FORUMS_TABLE . '
 1339                  SET ' . $db->sql_build_array('UPDATE', $forum_data_sql) . '
 1340                  WHERE forum_id = ' . $forum_id;
 1341              $db->sql_query($sql);
 1342   
 1343              // Add it back
 1344              $forum_data['forum_id'] = $forum_id;
 1345   
 1346              add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']);
 1347          }
 1348   
 1349          /**
 1350          * Event after a forum was updated or created
 1351          *
 1352          * @event core.acp_manage_forums_update_data_after
 1353          * @var    array    forum_data        Array with forum data
 1354          * @var    array    forum_data_sql    Array with data we updated
 1355          * @var    bool    is_new_forum    Did we create a forum or update one
 1356          *                                If you want to overwrite this value,
 1357          *                                ensure to set forum_data_sql[forum_id]
 1358          * @var    array    errors        Array of errors, should be strings and not
 1359          *                            language key.
 1360          * @since 3.1.0-a1
 1361          */
 1362          $vars = array('forum_data', 'forum_data_sql', 'is_new_forum', 'errors');
 1363          extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_update_data_after', compact($vars)));
 1364   
 1365          return $errors;
 1366      }
 1367   
 1368      /**
 1369      * Move forum
 1370      */
 1371      function move_forum($from_id, $to_id)
 1372      {
 1373          global $db, $user, $phpbb_dispatcher;
 1374   
 1375          $to_data = $moved_ids = $errors = array();
 1376   
 1377          // Check if we want to move to a parent with link type
 1378          if ($to_id > 0)
 1379          {
 1380              $to_data = $this->get_forum_info($to_id);
 1381   
 1382              if ($to_data['forum_type'] == FORUM_LINK)
 1383              {
 1384                  $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
 1385              }
 1386          }
 1387   
 1388          /**
 1389          * Event when we move all children of one forum to another
 1390          *
 1391          * This event may be triggered, when a forum is deleted
 1392          *
 1393          * @event core.acp_manage_forums_move_children
 1394          * @var    int        from_id        If of the current parent forum
 1395          * @var    int        to_id        If of the new parent forum
 1396          * @var    array    errors        Array of errors, should be strings and not
 1397          *                            language key.
 1398          * @since 3.1.0-a1
 1399          */
 1400          $vars = array('from_id', 'to_id', 'errors');
 1401          extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_move_children', compact($vars)));
 1402   
 1403          // Return if there were errors
 1404          if (!empty($errors))
 1405          {
 1406              return $errors;
 1407          }
 1408   
 1409          $moved_forums = get_forum_branch($from_id, 'children', 'descending');
 1410          $from_data = $moved_forums[0];
 1411          $diff = sizeof($moved_forums) * 2;
 1412   
 1413          $moved_ids = array();
 1414          for ($i = 0; $i < sizeof($moved_forums); ++$i)
 1415          {
 1416              $moved_ids[] = $moved_forums[$i]['forum_id'];
 1417          }
 1418   
 1419          // Resync parents
 1420          $sql = 'UPDATE ' . FORUMS_TABLE . "
 1421              SET right_id = right_id - $diff, forum_parents = ''
 1422              WHERE left_id < " . $from_data['right_id'] . "
 1423                  AND right_id > " . $from_data['right_id'];
 1424          $db->sql_query($sql);
 1425   
 1426          // Resync righthand side of tree
 1427          $sql = 'UPDATE ' . FORUMS_TABLE . "
 1428              SET left_id = left_id - $diff, right_id = right_id - $diff, forum_parents = ''
 1429              WHERE left_id > " . $from_data['right_id'];
 1430          $db->sql_query($sql);
 1431   
 1432          if ($to_id > 0)
 1433          {
 1434              // Retrieve $to_data again, it may have been changed...
 1435              $to_data = $this->get_forum_info($to_id);
 1436   
 1437              // Resync new parents
 1438              $sql = 'UPDATE ' . FORUMS_TABLE . "
 1439                  SET right_id = right_id + $diff, forum_parents = ''
 1440                  WHERE " . $to_data['right_id'] . ' BETWEEN left_id AND right_id
 1441                      AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
 1442              $db->sql_query($sql);
 1443   
 1444              // Resync the righthand side of the tree
 1445              $sql = 'UPDATE ' . FORUMS_TABLE . "
 1446                  SET left_id = left_id + $diff, right_id = right_id + $diff, forum_parents = ''
 1447                  WHERE left_id > " . $to_data['right_id'] . '
 1448                      AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
 1449              $db->sql_query($sql);
 1450   
 1451              // Resync moved branch
 1452              $to_data['right_id'] += $diff;
 1453   
 1454              if ($to_data['right_id'] > $from_data['right_id'])
 1455              {
 1456                  $diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1);
 1457              }
 1458              else
 1459              {
 1460                  $diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1);
 1461              }
 1462          }
 1463          else
 1464          {
 1465              $sql = 'SELECT MAX(right_id) AS right_id
 1466                  FROM ' . FORUMS_TABLE . '
 1467                  WHERE ' . $db->sql_in_set('forum_id', $moved_ids, true);
 1468              $result = $db->sql_query($sql);
 1469              $row = $db->sql_fetchrow($result);
 1470              $db->sql_freeresult($result);
 1471   
 1472              $diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1);
 1473          }
 1474   
 1475          $sql = 'UPDATE ' . FORUMS_TABLE . "
 1476              SET left_id = left_id $diff, right_id = right_id $diff, forum_parents = ''
 1477              WHERE " . $db->sql_in_set('forum_id', $moved_ids);
 1478          $db->sql_query($sql);
 1479   
 1480          return $errors;
 1481      }
 1482   
 1483      /**
 1484      * Move forum content from one to another forum
 1485      */
 1486      function move_forum_content($from_id, $to_id, $sync = true)
 1487      {
 1488          global $db, $phpbb_dispatcher;
 1489   
 1490          $errors = array();
 1491   
 1492          /**
 1493          * Event when we move content from one forum to another
 1494          *
 1495          * @event core.acp_manage_forums_move_content
 1496          * @var    int        from_id        If of the current parent forum
 1497          * @var    int        to_id        If of the new parent forum
 1498          * @var    bool    sync        Shall we sync the "to"-forum's data
 1499          * @var    array    errors        Array of errors, should be strings and not
 1500          *                            language key. If this array is not empty,
 1501          *                            The content will not be moved.
 1502          * @since 3.1.0-a1
 1503          */
 1504          $vars = array('from_id', 'to_id', 'sync', 'errors');
 1505          extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_move_content', compact($vars)));
 1506   
 1507          // Return if there were errors
 1508          if (!empty($errors))
 1509          {
 1510              return $errors;
 1511          }
 1512   
 1513          $table_ary = array(LOG_TABLE, POSTS_TABLE, TOPICS_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
 1514   
 1515          foreach ($table_ary as $table)
 1516          {
 1517              $sql = "UPDATE $table
 1518                  SET forum_id = $to_id
 1519                  WHERE forum_id = $from_id";
 1520              $db->sql_query($sql);
 1521          }
 1522          unset($table_ary);
 1523   
 1524          $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, MODERATOR_CACHE_TABLE);
 1525   
 1526          foreach ($table_ary as $table)
 1527          {
 1528              $sql = "DELETE FROM $table
 1529                  WHERE forum_id = $from_id";
 1530              $db->sql_query($sql);
 1531          }
 1532   
 1533          if ($sync)
 1534          {
 1535              // Delete ghost topics that link back to the same forum then resync counters
 1536              sync('topic_moved');
 1537              sync('forum', 'forum_id', $to_id, false, true);
 1538          }
 1539   
 1540          return array();
 1541      }
 1542   
 1543      /**
 1544      * Remove complete forum
 1545      */
 1546      function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0)
 1547      {
 1548          global $db, $user, $cache;
 1549   
 1550          $forum_data = $this->get_forum_info($forum_id);
 1551   
 1552          $errors = array();
 1553          $log_action_posts = $log_action_forums = $posts_to_name = $subforums_to_name = '';
 1554          $forum_ids = array($forum_id);
 1555   
 1556          if ($action_posts == 'delete')
 1557          {
 1558              $log_action_posts = 'POSTS';
 1559              $errors = array_merge($errors, $this->delete_forum_content($forum_id));
 1560          }
 1561          else if ($action_posts == 'move')
 1562          {
 1563              if (!$posts_to_id)
 1564              {
 1565                  $errors[] = $user->lang['NO_DESTINATION_FORUM'];
 1566              }
 1567              else
 1568              {
 1569                  $log_action_posts = 'MOVE_POSTS';
 1570   
 1571                  $sql = 'SELECT forum_name
 1572                      FROM ' . FORUMS_TABLE . '
 1573                      WHERE forum_id = ' . $posts_to_id;
 1574                  $result = $db->sql_query($sql);
 1575                  $row = $db->sql_fetchrow($result);
 1576                  $db->sql_freeresult($result);
 1577   
 1578                  if (!$row)
 1579                  {
 1580                      $errors[] = $user->lang['NO_FORUM'];
 1581                  }
 1582                  else
 1583                  {
 1584                      $posts_to_name = $row['forum_name'];
 1585                      $errors = array_merge($errors, $this->move_forum_content($forum_id, $posts_to_id));
 1586                  }
 1587              }
 1588          }
 1589   
 1590          if (sizeof($errors))
 1591          {
 1592              return $errors;
 1593          }
 1594   
 1595          if ($action_subforums == 'delete')
 1596          {
 1597              $log_action_forums = 'FORUMS';
 1598              $rows = get_forum_branch($forum_id, 'children', 'descending', false);
 1599   
 1600              foreach ($rows as $row)
 1601              {
 1602                  $forum_ids[] = $row['forum_id'];
 1603                  $errors = array_merge($errors, $this->delete_forum_content($row['forum_id']));
 1604              }
 1605   
 1606              if (sizeof($errors))
 1607              {
 1608                  return $errors;
 1609              }
 1610   
 1611              $diff = sizeof($forum_ids) * 2;
 1612   
 1613              $sql = 'DELETE FROM ' . FORUMS_TABLE . '
 1614                  WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
 1615              $db->sql_query($sql);
 1616   
 1617              $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
 1618                  WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
 1619              $db->sql_query($sql);
 1620   
 1621              $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
 1622                  WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
 1623              $db->sql_query($sql);
 1624          }
 1625          else if ($action_subforums == 'move')
 1626          {
 1627              if (!$subforums_to_id)
 1628              {
 1629                  $errors[] = $user->lang['NO_DESTINATION_FORUM'];
 1630              }
 1631              else
 1632              {
 1633                  $log_action_forums = 'MOVE_FORUMS';
 1634   
 1635                  $sql = 'SELECT forum_name
 1636                      FROM ' . FORUMS_TABLE . '
 1637                      WHERE forum_id = ' . $subforums_to_id;
 1638                  $result = $db->sql_query($sql);
 1639                  $row = $db->sql_fetchrow($result);
 1640                  $db->sql_freeresult($result);
 1641   
 1642                  if (!$row)
 1643                  {
 1644                      $errors[] = $user->lang['NO_FORUM'];
 1645                  }
 1646                  else
 1647                  {
 1648                      $subforums_to_name = $row['forum_name'];
 1649   
 1650                      $sql = 'SELECT forum_id
 1651                          FROM ' . FORUMS_TABLE . "
 1652                          WHERE parent_id = $forum_id";
 1653                      $result = $db->sql_query($sql);
 1654   
 1655                      while ($row = $db->sql_fetchrow($result))
 1656                      {
 1657                          $this->move_forum($row['forum_id'], $subforums_to_id);
 1658                      }
 1659                      $db->sql_freeresult($result);
 1660   
 1661                      // Grab new forum data for correct tree updating later
 1662                      $forum_data = $this->get_forum_info($forum_id);
 1663   
 1664                      $sql = 'UPDATE ' . FORUMS_TABLE . "
 1665                          SET parent_id = $subforums_to_id
 1666                          WHERE parent_id = $forum_id";
 1667                      $db->sql_query($sql);
 1668   
 1669                      $diff = 2;
 1670                      $sql = 'DELETE FROM ' . FORUMS_TABLE . "
 1671                          WHERE forum_id = $forum_id";
 1672                      $db->sql_query($sql);
 1673   
 1674                      $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
 1675                          WHERE forum_id = $forum_id";
 1676                      $db->sql_query($sql);
 1677   
 1678                      $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
 1679                          WHERE forum_id = $forum_id";
 1680                      $db->sql_query($sql);
 1681                  }
 1682              }
 1683   
 1684              if (sizeof($errors))
 1685              {
 1686                  return $errors;
 1687              }
 1688          }
 1689          else
 1690          {
 1691              $diff = 2;
 1692              $sql = 'DELETE FROM ' . FORUMS_TABLE . "
 1693                  WHERE forum_id = $forum_id";
 1694              $db->sql_query($sql);
 1695   
 1696              $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
 1697                  WHERE forum_id = $forum_id";
 1698              $db->sql_query($sql);
 1699   
 1700              $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
 1701                  WHERE forum_id = $forum_id";
 1702              $db->sql_query($sql);
 1703          }
 1704   
 1705          // Resync tree
 1706          $sql = 'UPDATE ' . FORUMS_TABLE . "
 1707              SET right_id = right_id - $diff
 1708              WHERE left_id < {$forum_data['right_id']} AND right_id > {$forum_data['right_id']}";
 1709          $db->sql_query($sql);
 1710   
 1711          $sql = 'UPDATE ' . FORUMS_TABLE . "
 1712              SET left_id = left_id - $diff, right_id = right_id - $diff
 1713              WHERE left_id > {$forum_data['right_id']}";
 1714          $db->sql_query($sql);
 1715   
 1716          // Delete forum ids from extension groups table
 1717          $sql = 'SELECT group_id, allowed_forums
 1718              FROM ' . EXTENSION_GROUPS_TABLE;
 1719          $result = $db->sql_query($sql);
 1720   
 1721          while ($row = $db->sql_fetchrow($result))
 1722          {
 1723              if (!$row['allowed_forums'])
 1724              {
 1725                  continue;
 1726              }
 1727   
 1728              $allowed_forums = unserialize(trim($row['allowed_forums']));
 1729              $allowed_forums = array_diff($allowed_forums, $forum_ids);
 1730   
 1731              $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
 1732                  SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
 1733                  WHERE group_id = {$row['group_id']}";
 1734              $db->sql_query($sql);
 1735          }
 1736          $db->sql_freeresult($result);
 1737   
 1738          $cache->destroy('_extensions');
 1739   
 1740          $log_action = implode('_', array($log_action_posts, $log_action_forums));
 1741   
 1742          switch ($log_action)
 1743          {
 1744              case 'MOVE_POSTS_MOVE_FORUMS':
 1745                  add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_MOVE_FORUMS', $posts_to_name, $subforums_to_name, $forum_data['forum_name']);
 1746              break;
 1747   
 1748              case 'MOVE_POSTS_FORUMS':
 1749                  add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_FORUMS', $posts_to_name, $forum_data['forum_name']);
 1750              break;
 1751   
 1752              case 'POSTS_MOVE_FORUMS':
 1753                  add_log('admin', 'LOG_FORUM_DEL_POSTS_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
 1754              break;
 1755   
 1756              case '_MOVE_FORUMS':
 1757                  add_log('admin', 'LOG_FORUM_DEL_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
 1758              break;
 1759   
 1760              case 'MOVE_POSTS_':
 1761                  add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS', $posts_to_name, $forum_data['forum_name']);
 1762              break;
 1763   
 1764              case 'POSTS_FORUMS':
 1765                  add_log('admin', 'LOG_FORUM_DEL_POSTS_FORUMS', $forum_data['forum_name']);
 1766              break;
 1767   
 1768              case '_FORUMS':
 1769                  add_log('admin', 'LOG_FORUM_DEL_FORUMS', $forum_data['forum_name']);
 1770              break;
 1771   
 1772              case 'POSTS_':
 1773                  add_log('admin', 'LOG_FORUM_DEL_POSTS', $forum_data['forum_name']);
 1774              break;
 1775   
 1776              default:
 1777                  add_log('admin', 'LOG_FORUM_DEL_FORUM', $forum_data['forum_name']);
 1778              break;
 1779          }
 1780   
 1781          return $errors;
 1782      }
 1783   
 1784      /**
 1785      * Delete forum content
 1786      */
 1787      function delete_forum_content($forum_id)
 1788      {
 1789          global $db, $config, $phpbb_root_path, $phpEx;
 1790   
 1791          include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 1792   
 1793          $db->sql_transaction('begin');
 1794   
 1795          // Select then delete all attachments
 1796          $sql = 'SELECT a.topic_id
 1797              FROM ' . POSTS_TABLE . ' p, ' . ATTACHMENTS_TABLE . " a
 1798              WHERE p.forum_id = $forum_id
 1799                  AND a.in_message = 0
 1800                  AND a.topic_id = p.topic_id";
 1801          $result = $db->sql_query($sql);
 1802   
 1803          $topic_ids = array();
 1804          while ($row = $db->sql_fetchrow($result))
 1805          {
 1806              $topic_ids[] = $row['topic_id'];
 1807          }
 1808          $db->sql_freeresult($result);
 1809   
 1810          delete_attachments('topic', $topic_ids, false);
 1811   
 1812          // Delete shadow topics pointing to topics in this forum
 1813          delete_topic_shadows($forum_id);
 1814   
 1815          // Before we remove anything we make sure we are able to adjust the post counts later. ;)
 1816          $sql = 'SELECT poster_id
 1817              FROM ' . POSTS_TABLE . '
 1818              WHERE forum_id = ' . $forum_id . '
 1819                  AND post_postcount = 1
 1820                  AND post_visibility = ' . ITEM_APPROVED;
 1821          $result = $db->sql_query($sql);
 1822   
 1823          $post_counts = array();
 1824          while ($row = $db->sql_fetchrow($result))
 1825          {
 1826              $post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1;
 1827          }
 1828          $db->sql_freeresult($result);
 1829   
 1830          switch ($db->get_sql_layer())
 1831          {
 1832              case 'mysql4':
 1833              case 'mysqli':
 1834   
 1835                  // Delete everything else and thank MySQL for offering multi-table deletion
 1836                  $tables_ary = array(
 1837                      SEARCH_WORDMATCH_TABLE    => 'post_id',
 1838                      REPORTS_TABLE            => 'post_id',
 1839                      WARNINGS_TABLE            => 'post_id',
 1840                      BOOKMARKS_TABLE            => 'topic_id',
 1841                      TOPICS_WATCH_TABLE        => 'topic_id',
 1842                      TOPICS_POSTED_TABLE        => 'topic_id',
 1843                      POLL_OPTIONS_TABLE        => 'topic_id',
 1844                      POLL_VOTES_TABLE        => 'topic_id',
 1845                  );
 1846   
 1847                  $sql = 'DELETE ' . POSTS_TABLE;
 1848                  $sql_using = "\nFROM " . POSTS_TABLE;
 1849                  $sql_where = "\nWHERE " . POSTS_TABLE . ".forum_id = $forum_id\n";
 1850   
 1851                  foreach ($tables_ary as $table => $field)
 1852                  {
 1853                      $sql .= ", $table ";
 1854                      $sql_using .= ", $table ";
 1855                      $sql_where .= "\nAND $table.$field = " . POSTS_TABLE . ".$field";
 1856                  }
 1857   
 1858                  $db->sql_query($sql . $sql_using . $sql_where);
 1859   
 1860              break;
 1861   
 1862              default:
 1863   
 1864                  // Delete everything else and curse your DB for not offering multi-table deletion
 1865                  $tables_ary = array(
 1866                      'post_id'    =>    array(
 1867                          SEARCH_WORDMATCH_TABLE,
 1868                          REPORTS_TABLE,
 1869                          WARNINGS_TABLE,
 1870                      ),
 1871   
 1872                      'topic_id'    =>    array(
 1873                          BOOKMARKS_TABLE,
 1874                          TOPICS_WATCH_TABLE,
 1875                          TOPICS_POSTED_TABLE,
 1876                          POLL_OPTIONS_TABLE,
 1877                          POLL_VOTES_TABLE,
 1878                      )
 1879                  );
 1880   
 1881                  // Amount of rows we select and delete in one iteration.
 1882                  $batch_size = 500;
 1883   
 1884                  foreach ($tables_ary as $field => $tables)
 1885                  {
 1886                      $start = 0;
 1887   
 1888                      do
 1889                      {
 1890                          $sql = "SELECT $field
 1891                              FROM " . POSTS_TABLE . '
 1892                              WHERE forum_id = ' . $forum_id;
 1893                          $result = $db->sql_query_limit($sql, $batch_size, $start);
 1894   
 1895                          $ids = array();
 1896                          while ($row = $db->sql_fetchrow($result))
 1897                          {
 1898                              $ids[] = $row[$field];
 1899                          }
 1900                          $db->sql_freeresult($result);
 1901   
 1902                          if (sizeof($ids))
 1903                          {
 1904                              $start += sizeof($ids);
 1905   
 1906                              foreach ($tables as $table)
 1907                              {
 1908                                  $db->sql_query("DELETE FROM $table WHERE " . $db->sql_in_set($field, $ids));
 1909                              }
 1910                          }
 1911                      }
 1912                      while (sizeof($ids) == $batch_size);
 1913                  }
 1914                  unset($ids);
 1915   
 1916              break;
 1917          }
 1918   
 1919          $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, LOG_TABLE, MODERATOR_CACHE_TABLE, POSTS_TABLE, TOPICS_TABLE, TOPICS_TRACK_TABLE);
 1920   
 1921          foreach ($table_ary as $table)
 1922          {
 1923              $db->sql_query("DELETE FROM $table WHERE forum_id = $forum_id");
 1924          }
 1925   
 1926          // Set forum ids to 0
 1927          $table_ary = array(DRAFTS_TABLE);
 1928   
 1929          foreach ($table_ary as $table)
 1930          {
 1931              $db->sql_query("UPDATE $table SET forum_id = 0 WHERE forum_id = $forum_id");
 1932          }
 1933   
 1934          // Adjust users post counts
 1935          if (sizeof($post_counts))
 1936          {
 1937              foreach ($post_counts as $poster_id => $substract)
 1938              {
 1939                  $sql = 'UPDATE ' . USERS_TABLE . '
 1940                      SET user_posts = 0
 1941                      WHERE user_id = ' . $poster_id . '
 1942                      AND user_posts < ' . $substract;
 1943                  $db->sql_query($sql);
 1944   
 1945                  $sql = 'UPDATE ' . USERS_TABLE . '
 1946                      SET user_posts = user_posts - ' . $substract . '
 1947                      WHERE user_id = ' . $poster_id . '
 1948                      AND user_posts >= ' . $substract;
 1949                  $db->sql_query($sql);
 1950              }
 1951          }
 1952   
 1953          $db->sql_transaction('commit');
 1954   
 1955          // Make sure the overall post/topic count is correct...
 1956          $sql = 'SELECT COUNT(post_id) AS stat
 1957              FROM ' . POSTS_TABLE . '
 1958              WHERE post_visibility = ' . ITEM_APPROVED;
 1959          $result = $db->sql_query($sql);
 1960          $row = $db->sql_fetchrow($result);
 1961          $db->sql_freeresult($result);
 1962   
 1963          set_config('num_posts', (int) $row['stat'], true);
 1964   
 1965          $sql = 'SELECT COUNT(topic_id) AS stat
 1966              FROM ' . TOPICS_TABLE . '
 1967              WHERE topic_visibility = ' . ITEM_APPROVED;
 1968          $result = $db->sql_query($sql);
 1969          $row = $db->sql_fetchrow($result);
 1970          $db->sql_freeresult($result);
 1971   
 1972          set_config('num_topics', (int) $row['stat'], true);
 1973   
 1974          $sql = 'SELECT COUNT(attach_id) as stat
 1975              FROM ' . ATTACHMENTS_TABLE;
 1976          $result = $db->sql_query($sql);
 1977          $row = $db->sql_fetchrow($result);
 1978          $db->sql_freeresult($result);
 1979   
 1980          set_config('num_files', (int) $row['stat'], true);
 1981   
 1982          $sql = 'SELECT SUM(filesize) as stat
 1983              FROM ' . ATTACHMENTS_TABLE;
 1984          $result = $db->sql_query($sql);
 1985          $row = $db->sql_fetchrow($result);
 1986          $db->sql_freeresult($result);
 1987   
 1988          set_config('upload_dir_size', (float) $row['stat'], true);
 1989   
 1990          return array();
 1991      }
 1992   
 1993      /**
 1994      * Move forum position by $steps up/down
 1995      */
 1996      function move_forum_by($forum_row, $action = 'move_up', $steps = 1)
 1997      {
 1998          global $db;
 1999   
 2000          /**
 2001          * Fetch all the siblings between the module's current spot
 2002          * and where we want to move it to. If there are less than $steps
 2003          * siblings between the current spot and the target then the
 2004          * module will move as far as possible
 2005          */
 2006          $sql = 'SELECT forum_id, forum_name, left_id, right_id
 2007              FROM ' . FORUMS_TABLE . "
 2008              WHERE parent_id = {$forum_row['parent_id']}
 2009                  AND " . (($action == 'move_up') ? "right_id < {$forum_row['right_id']} ORDER BY right_id DESC" : "left_id > {$forum_row['left_id']} ORDER BY left_id ASC");
 2010          $result = $db->sql_query_limit($sql, $steps);
 2011   
 2012          $target = array();
 2013          while ($row = $db->sql_fetchrow($result))
 2014          {
 2015              $target = $row;
 2016          }
 2017          $db->sql_freeresult($result);
 2018   
 2019          if (!sizeof($target))
 2020          {
 2021              // The forum is already on top or bottom
 2022              return false;
 2023          }
 2024   
 2025          /**
 2026          * $left_id and $right_id define the scope of the nodes that are affected by the move.
 2027          * $diff_up and $diff_down are the values to substract or add to each node's left_id
 2028          * and right_id in order to move them up or down.
 2029          * $move_up_left and $move_up_right define the scope of the nodes that are moving
 2030          * up. Other nodes in the scope of ($left_id, $right_id) are considered to move down.
 2031          */
 2032          if ($action == 'move_up')
 2033          {
 2034              $left_id = $target['left_id'];
 2035              $right_id = $forum_row['right_id'];
 2036   
 2037              $diff_up = $forum_row['left_id'] - $target['left_id'];
 2038              $diff_down = $forum_row['right_id'] + 1 - $forum_row['left_id'];
 2039   
 2040              $move_up_left = $forum_row['left_id'];
 2041              $move_up_right = $forum_row['right_id'];
 2042          }
 2043          else
 2044          {
 2045              $left_id = $forum_row['left_id'];
 2046              $right_id = $target['right_id'];
 2047   
 2048              $diff_up = $forum_row['right_id'] + 1 - $forum_row['left_id'];
 2049              $diff_down = $target['right_id'] - $forum_row['right_id'];
 2050   
 2051              $move_up_left = $forum_row['right_id'] + 1;
 2052              $move_up_right = $target['right_id'];
 2053          }
 2054   
 2055          // Now do the dirty job
 2056          $sql = 'UPDATE ' . FORUMS_TABLE . "
 2057              SET left_id = left_id + CASE
 2058                  WHEN left_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
 2059                  ELSE {$diff_down}
 2060              END,
 2061              right_id = right_id + CASE
 2062                  WHEN right_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
 2063                  ELSE {$diff_down}
 2064              END,
 2065              forum_parents = ''
 2066              WHERE
 2067                  left_id BETWEEN {$left_id} AND {$right_id}
 2068                  AND right_id BETWEEN {$left_id} AND {$right_id}";
 2069          $db->sql_query($sql);
 2070   
 2071          return $target['forum_name'];
 2072      }
 2073   
 2074      /**
 2075      * Display progress bar for syncinc forums
 2076      */
 2077      function display_progress_bar($start, $total)
 2078      {
 2079          global $template, $user;
 2080   
 2081          adm_page_header($user->lang['SYNC_IN_PROGRESS']);
 2082   
 2083          $template->set_filenames(array(
 2084              'body'    => 'progress_bar.html')
 2085          );
 2086   
 2087          $template->assign_vars(array(
 2088              'L_PROGRESS'            => $user->lang['SYNC_IN_PROGRESS'],
 2089              'L_PROGRESS_EXPLAIN'    => ($start && $total) ? sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $start, $total) : $user->lang['SYNC_IN_PROGRESS'])
 2090          );
 2091   
 2092          adm_page_footer();
 2093      }
 2094   
 2095      /**
 2096      * Display copy permission page
 2097      * Not used at the moment - we will have a look at it for 3.0.7
 2098      */
 2099      function copy_permission_page($forum_data)
 2100      {
 2101          global $phpEx, $phpbb_admin_path, $template, $user;
 2102   
 2103          $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_data['forum_id'];
 2104          $action = append_sid($this->u_action . "&amp;parent_id={$this->parent_id}&amp;f={$forum_data['forum_id']}&amp;action=copy_perm");
 2105   
 2106          $l_acl = sprintf($user->lang['COPY_TO_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
 2107   
 2108          $this->tpl_name = 'acp_forums_copy_perm';
 2109   
 2110          $template->assign_vars(array(
 2111              'U_ACL'                => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url),
 2112              'L_ACL_LINK'        => $l_acl,
 2113              'L_BACK_LINK'        => adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id),
 2114              'S_COPY_ACTION'        => $action,
 2115              'S_FORUM_OPTIONS'    => make_forum_select($forum_data['parent_id'], $forum_data['forum_id'], false, false, false),
 2116          ));
 2117      }
 2118   
 2119  }
 2120