Register
phpBB.com Wiki · Home Projects Help

root / branches / phpBB-3_0_0 / phpBB / includes / acp / acp_forums.php

1
<?php
2
/**
3
*
4
* @package acp
5
* @version $Id: acp_forums.php 8898 2008-09-19 17:07:13Z acydburn $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8
*
9
*/
10
11
/**
12
* @ignore
13
*/
14
if (!defined('IN_PHPBB'))
15
{
16
	exit;
17
}
18
19
/**
20
* @package acp
21
*/
22
class acp_forums
23
{
24
	var $u_action;
25
	var $parent_id = 0;
26
27
	function main($id, $mode)
28
	{
29
		global $db, $user, $auth, $template, $cache;
30
		global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
31
32
		$user->add_lang('acp/forums');
33
		$this->tpl_name = 'acp_forums';
34
		$this->page_title = 'ACP_MANAGE_FORUMS';
35
36
		$form_key = 'acp_forums';
37
		add_form_key($form_key);
38
39
		$action		= request_var('action', '');
40
		$update		= (isset($_POST['update'])) ? true : false;
41
		$forum_id	= request_var('f', 0);
42
43
		$this->parent_id	= request_var('parent_id', 0);
44
		$forum_data = $errors = array();
45
		if ($update && !check_form_key($form_key))
46
		{
47
			$update = false;
48
			$errors[] = $user->lang['FORM_INVALID'];
49
		}
50
51
		// Check additional permissions
52
		switch ($action)
53
		{
54
			case 'progress_bar':
55
				$start = request_var('start', 0);
56
				$total = request_var('total', 0);
57
58
				$this->display_progress_bar($start, $total);
59
				exit;
60
			break;
61
62
			case 'delete':
63
64
				if (!$auth->acl_get('a_forumdel'))
65
				{
66
					trigger_error($user->lang['NO_PERMISSION_FORUM_DELETE'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
67
				}
68
69
			break;
70
71
			case 'add':
72
73
				if (!$auth->acl_get('a_forumadd'))
74
				{
75
					trigger_error($user->lang['NO_PERMISSION_FORUM_ADD'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
76
				}
77
78
			break;
79
		}
80
81
		// Major routines
82
		if ($update)
83
		{
84
			switch ($action)
85
			{
86
				case 'delete':
87
					$action_subforums	= request_var('action_subforums', '');
88
					$subforums_to_id	= request_var('subforums_to_id', 0);
89
					$action_posts		= request_var('action_posts', '');
90
					$posts_to_id		= request_var('posts_to_id', 0);
91
92
					$errors = $this->delete_forum($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
93
94
					if (sizeof($errors))
95
					{
96
						break;
97
					}
98
99
					$auth->acl_clear_prefetch();
100
					$cache->destroy('sql', FORUMS_TABLE);
101
102
					trigger_error($user->lang['FORUM_DELETED'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
103
104
				break;
105
106
				case 'edit':
107
					$forum_data = array(
108
						'forum_id'		=>	$forum_id
109
					);
110
111
				// No break here
112
113
				case 'add':
114
115
					$forum_data += array(
116
						'parent_id'				=> request_var('forum_parent_id', $this->parent_id),
117
						'forum_type'			=> request_var('forum_type', FORUM_POST),
118
						'type_action'			=> request_var('type_action', ''),
119
						'forum_status'			=> request_var('forum_status', ITEM_UNLOCKED),
120
						'forum_parents'			=> '',
121
						'forum_name'			=> utf8_normalize_nfc(request_var('forum_name', '', true)),
122
						'forum_link'			=> request_var('forum_link', ''),
123
						'forum_link_track'		=> request_var('forum_link_track', false),
124
						'forum_desc'			=> utf8_normalize_nfc(request_var('forum_desc', '', true)),
125
						'forum_desc_uid'		=> '',
126
						'forum_desc_options'	=> 7,
127
						'forum_desc_bitfield'	=> '',
128
						'forum_rules'			=> utf8_normalize_nfc(request_var('forum_rules', '', true)),
129
						'forum_rules_uid'		=> '',
130
						'forum_rules_options'	=> 7,
131
						'forum_rules_bitfield'	=> '',
132
						'forum_rules_link'		=> request_var('forum_rules_link', ''),
133
						'forum_image'			=> request_var('forum_image', ''),
134
						'forum_style'			=> request_var('forum_style', 0),
135
						'display_subforum_list'	=> request_var('display_subforum_list', false),
136
						'display_on_index'		=> request_var('display_on_index', false),
137
						'forum_topics_per_page'	=> request_var('topics_per_page', 0),
138
						'enable_indexing'		=> request_var('enable_indexing', true),
139
						'enable_icons'			=> request_var('enable_icons', false),
140
						'enable_prune'			=> request_var('enable_prune', false),
141
						'enable_post_review'	=> request_var('enable_post_review', true),
142
						'prune_days'			=> request_var('prune_days', 7),
143
						'prune_viewed'			=> request_var('prune_viewed', 7),
144
						'prune_freq'			=> request_var('prune_freq', 1),
145
						'prune_old_polls'		=> request_var('prune_old_polls', false),
146
						'prune_announce'		=> request_var('prune_announce', false),
147
						'prune_sticky'			=> request_var('prune_sticky', false),
148
						'forum_password'		=> request_var('forum_password', '', true),
149
						'forum_password_confirm'=> request_var('forum_password_confirm', '', true),
150
						'forum_password_unset'	=> request_var('forum_password_unset', false),
151
					);
152
153
					// Use link_display_on_index setting if forum type is link
154
					if ($forum_data['forum_type'] == FORUM_LINK)
155
					{
156
						$forum_data['display_on_index'] = request_var('link_display_on_index', false);
157
					}
158
159
					// Linked forums and categories are not able to be locked...
160
					if ($forum_data['forum_type'] == FORUM_LINK || $forum_data['forum_type'] == FORUM_CAT)
161
					{
162
						$forum_data['forum_status'] = ITEM_UNLOCKED;
163
					}
164
165
					$forum_data['show_active'] = ($forum_data['forum_type'] == FORUM_POST) ? request_var('display_recent', false) : request_var('display_active', false);
166
167
					// Get data for forum rules if specified...
168
					if ($forum_data['forum_rules'])
169
					{
170
						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));
171
					}
172
173
					// Get data for forum description if specified
174
					if ($forum_data['forum_desc'])
175
					{
176
						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));
177
					}
178
179
					$errors = $this->update_forum_data($forum_data);
180
181
					if (!sizeof($errors))
182
					{
183
						$forum_perm_from = request_var('forum_perm_from', 0);
184
185
						// Copy permissions?
186
						if ($forum_perm_from && !empty($forum_perm_from) && $forum_perm_from != $forum_data['forum_id'] &&
187
							(($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'))))
188
						{
189
							// if we edit a forum delete current permissions first
190
							if ($action == 'edit')
191
							{
192
								$sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
193
									WHERE forum_id = ' . (int) $forum_data['forum_id'];
194
								$db->sql_query($sql);
195
196
								$sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
197
									WHERE forum_id = ' . (int) $forum_data['forum_id'];
198
								$db->sql_query($sql);
199
							}
200
201
							// From the mysql documentation:
202
							// Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
203
							// Due to this we stay on the safe side if we do the insertion "the manual way"
204
205
							// Copy permisisons from/to the acl users table (only forum_id gets changed)
206
							$sql = 'SELECT user_id, auth_option_id, auth_role_id, auth_setting
207
								FROM ' . ACL_USERS_TABLE . '
208
								WHERE forum_id = ' . $forum_perm_from;
209
							$result = $db->sql_query($sql);
210
211
							$users_sql_ary = array();
212
							while ($row = $db->sql_fetchrow($result))
213
							{
214
								$users_sql_ary[] = array(
215
									'user_id'			=> (int) $row['user_id'],
216
									'forum_id'			=> (int) $forum_data['forum_id'],
217
									'auth_option_id'	=> (int) $row['auth_option_id'],
218
									'auth_role_id'		=> (int) $row['auth_role_id'],
219
									'auth_setting'		=> (int) $row['auth_setting']
220
								);
221
							}
222
							$db->sql_freeresult($result);
223
224
							// Copy permisisons from/to the acl groups table (only forum_id gets changed)
225
							$sql = 'SELECT group_id, auth_option_id, auth_role_id, auth_setting
226
								FROM ' . ACL_GROUPS_TABLE . '
227
								WHERE forum_id = ' . $forum_perm_from;
228
							$result = $db->sql_query($sql);
229
230
							$groups_sql_ary = array();
231
							while ($row = $db->sql_fetchrow($result))
232
							{
233
								$groups_sql_ary[] = array(
234
									'group_id'			=> (int) $row['group_id'],
235
									'forum_id'			=> (int) $forum_data['forum_id'],
236
									'auth_option_id'	=> (int) $row['auth_option_id'],
237
									'auth_role_id'		=> (int) $row['auth_role_id'],
238
									'auth_setting'		=> (int) $row['auth_setting']
239
								);
240
							}
241
							$db->sql_freeresult($result);
242
243
							// Now insert the data
244
							$db->sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary);
245
							$db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
246
							cache_moderators();
247
						}
248
249
						$auth->acl_clear_prefetch();
250
						$cache->destroy('sql', FORUMS_TABLE);
251
252
						$acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_data['forum_id'];
253
254
						$message = ($action == 'add') ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED'];
255
256
						// Redirect to permissions
257
						if ($auth->acl_get('a_fauth'))
258
						{
259
							$message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
260
						}
261
262
						// redirect directly to permission settings screen if authed
263
						if ($action == 'add' && !$forum_perm_from && $auth->acl_get('a_fauth'))
264
						{
265
							meta_refresh(4, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url));
266
						}
267
268
						trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
269
					}
270
271
				break;
272
			}
273
		}
274
275
		switch ($action)
276
		{
277
			case 'move_up':
278
			case 'move_down':
279
280
				if (!$forum_id)
281
				{
282
					trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
283
				}
284
285
				$sql = 'SELECT *
286
					FROM ' . FORUMS_TABLE . "
287
					WHERE forum_id = $forum_id";
288
				$result = $db->sql_query($sql);
289
				$row = $db->sql_fetchrow($result);
290
				$db->sql_freeresult($result);
291
292
				if (!$row)
293
				{
294
					trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
295
				}
296
297
				$move_forum_name = $this->move_forum_by($row, $action, 1);
298
299
				if ($move_forum_name !== false)
300
				{
301
					add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name);
302
					$cache->destroy('sql', FORUMS_TABLE);
303
				}
304
305
			break;
306
307
			case 'sync':
308
				if (!$forum_id)
309
				{
310
					trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
311
				}
312
313
				@set_time_limit(0);
314
315
				$sql = 'SELECT forum_name, forum_topics_real
316
					FROM ' . FORUMS_TABLE . "
317
					WHERE forum_id = $forum_id";
318
				$result = $db->sql_query($sql);
319
				$row = $db->sql_fetchrow($result);
320
				$db->sql_freeresult($result);
321
322
				if (!$row)
323
				{
324
					trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
325
				}
326
327
				if ($row['forum_topics_real'])
328
				{
329
					$sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id
330
						FROM ' . TOPICS_TABLE . '
331
						WHERE forum_id = ' . $forum_id;
332
					$result = $db->sql_query($sql);
333
					$row2 = $db->sql_fetchrow($result);
334
					$db->sql_freeresult($result);
335
336
					// Typecast to int if there is no data available
337
					$row2['min_topic_id'] = (int) $row2['min_topic_id'];
338
					$row2['max_topic_id'] = (int) $row2['max_topic_id'];
339
340
					$start = request_var('start', $row2['min_topic_id']);
341
342
					$batch_size = 2000;
343
					$end = $start + $batch_size;
344
345
					// Sync all topics in batch mode...
346
					sync('topic_approved', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false);
347
					sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true);
348
349
					if ($end < $row2['max_topic_id'])
350
					{
351
						// We really need to find a way of showing statistics... no progress here
352
						$sql = 'SELECT COUNT(topic_id) as num_topics
353
							FROM ' . TOPICS_TABLE . '
354
							WHERE forum_id = ' . $forum_id . '
355
								AND topic_id BETWEEN ' . $start . ' AND ' . $end;
356
						$result = $db->sql_query($sql);
357
						$topics_done = request_var('topics_done', 0) + (int) $db->sql_fetchfield('num_topics');
358
						$db->sql_freeresult($result);
359
360
						$start += $batch_size;
361
362
						$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['forum_topics_real']}";
363
364
						meta_refresh(0, $url);
365
366
						$template->assign_vars(array(
367
							'U_PROGRESS_BAR'		=> $this->u_action . "&amp;action=progress_bar&amp;start=$topics_done&amp;total={$row['forum_topics_real']}",
368
							'UA_PROGRESS_BAR'		=> addslashes($this->u_action . "&amp;action=progress_bar&amp;start=$topics_done&amp;total={$row['forum_topics_real']}"),
369
							'S_CONTINUE_SYNC'		=> true,
370
							'L_PROGRESS_EXPLAIN'	=> sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['forum_topics_real']))
371
						);
372
373
						return;
374
					}
375
				}
376
377
				$url = $this->u_action . "&amp;parent_id={$this->parent_id}&amp;f=$forum_id&amp;action=sync_forum";
378
				meta_refresh(0, $url);
379
380
				$template->assign_vars(array(
381
					'U_PROGRESS_BAR'		=> $this->u_action . '&amp;action=progress_bar',
382
					'UA_PROGRESS_BAR'		=> addslashes($this->u_action . '&amp;action=progress_bar'),
383
					'S_CONTINUE_SYNC'		=> true,
384
					'L_PROGRESS_EXPLAIN'	=> sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['forum_topics_real']))
385
				);
386
387
				return;
388
389
			break;
390
391
			case 'sync_forum':
392
393
				$sql = 'SELECT forum_name, forum_type
394
					FROM ' . FORUMS_TABLE . "
395
					WHERE forum_id = $forum_id";
396
				$result = $db->sql_query($sql);
397
				$row = $db->sql_fetchrow($result);
398
				$db->sql_freeresult($result);
399
400
				if (!$row)
401
				{
402
					trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
403
				}
404
405
				sync('forum', 'forum_id', $forum_id, false, true);
406
407
				add_log('admin', 'LOG_FORUM_SYNC', $row['forum_name']);
408
				$cache->destroy('sql', FORUMS_TABLE);
409
410
				$template->assign_var('L_FORUM_RESYNCED', sprintf($user->lang['FORUM_RESYNCED'], $row['forum_name']));
411
412
			break;
413
414
			case 'add':
415
			case 'edit':
416
417
				if ($update)
418
				{
419
					$forum_data['forum_flags'] = 0;
420
					$forum_data['forum_flags'] += (request_var('forum_link_track', false)) ? FORUM_FLAG_LINK_TRACK : 0;
421
					$forum_data['forum_flags'] += (request_var('prune_old_polls', false)) ? FORUM_FLAG_PRUNE_POLL : 0;
422
					$forum_data['forum_flags'] += (request_var('prune_announce', false)) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
423
					$forum_data['forum_flags'] += (request_var('prune_sticky', false)) ? FORUM_FLAG_PRUNE_STICKY : 0;
424
					$forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
425
					$forum_data['forum_flags'] += (request_var('enable_post_review', true)) ? FORUM_FLAG_POST_REVIEW : 0;
426
				}
427
428
				// Show form to create/modify a forum
429
				if ($action == 'edit')
430
				{
431
					$this->page_title = 'EDIT_FORUM';
432
					$row = $this->get_forum_info($forum_id);
433
					$old_forum_type = $row['forum_type'];
434
435
					if (!$update)
436
					{
437
						$forum_data = $row;
438
					}
439
					else
440
					{
441
						$forum_data['left_id'] = $row['left_id'];
442
						$forum_data['right_id'] = $row['right_id'];
443
					}
444
445
					// Make sure no direct child forums are able to be selected as parents.
446
					$exclude_forums = array();
447
					foreach (get_forum_branch($forum_id, 'children') as $row)
448
					{
449
						$exclude_forums[] = $row['forum_id'];
450
					}
451
452
					$parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false);
453
454
					$forum_data['forum_password_confirm'] = $forum_data['forum_password'];
455
				}
456
				else
457
				{
458
					$this->page_title = 'CREATE_FORUM';
459
460
					$forum_id = $this->parent_id;
461
					$parents_list = make_forum_select($this->parent_id, false, false, false, false);
462
463
					// Fill forum data with default values
464
					if (!$update)
465
					{
466
						$forum_data = array(
467
							'parent_id'				=> $this->parent_id,
468
							'forum_type'			=> FORUM_POST,
469
							'forum_status'			=> ITEM_UNLOCKED,
470
							'forum_name'			=> utf8_normalize_nfc(request_var('forum_name', '', true)),
471
							'forum_link'			=> '',
472
							'forum_link_track'		=> false,
473
							'forum_desc'			=> '',
474
							'forum_rules'			=> '',
475
							'forum_rules_link'		=> '',
476
							'forum_image'			=> '',
477
							'forum_style'			=> 0,
478
							'display_subforum_list'	=> true,
479
							'display_on_index'		=> false,
480
							'forum_topics_per_page'	=> 0,
481
							'enable_indexing'		=> true,
482
							'enable_icons'			=> false,
483
							'enable_prune'			=> false,
484
							'prune_days'			=> 7,
485
							'prune_viewed'			=> 7,
486
							'prune_freq'			=> 1,
487
							'forum_flags'			=> FORUM_FLAG_POST_REVIEW,
488
							'forum_password'		=> '',
489
							'forum_password_confirm'=> '',
490
						);
491
					}
492
				}
493
494
				$forum_rules_data = array(
495
					'text'			=> $forum_data['forum_rules'],
496
					'allow_bbcode'	=> true,
497
					'allow_smilies'	=> true,
498
					'allow_urls'	=> true
499
				);
500
501
				$forum_desc_data = array(
502
					'text'			=> $forum_data['forum_desc'],
503
					'allow_bbcode'	=> true,
504
					'allow_smilies'	=> true,
505
					'allow_urls'	=> true
506
				);
507
508
				$forum_rules_preview = '';
509
510
				// Parse rules if specified
511
				if ($forum_data['forum_rules'])
512
				{
513
					if (!isset($forum_data['forum_rules_uid']))
514
					{
515
						// Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
516
						$forum_data['forum_rules_uid'] = '';
517
						$forum_data['forum_rules_bitfield'] = '';
518
						$forum_data['forum_rules_options'] = 0;
519
520
						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));
521
					}
522
523
					// Generate preview content
524
					$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']);
525
526
					// decode...
527
					$forum_rules_data = generate_text_for_edit($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_options']);
528
				}
529
530
				// Parse desciption if specified
531
				if ($forum_data['forum_desc'])
532
				{
533
					if (!isset($forum_data['forum_desc_uid']))
534
					{
535
						// Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
536
						$forum_data['forum_desc_uid'] = '';
537
						$forum_data['forum_desc_bitfield'] = '';
538
						$forum_data['forum_desc_options'] = 0;
539
540
						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));
541
					}
542
543
					// decode...
544
					$forum_desc_data = generate_text_for_edit($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_options']);
545
				}
546
547
				$forum_type_options = '';
548
				$forum_type_ary = array(FORUM_CAT => 'CAT', FORUM_POST => 'FORUM', FORUM_LINK => 'LINK');
549
550
				foreach ($forum_type_ary as $value => $lang)
551
				{
552
					$forum_type_options .= '<option value="' . $value . '"' . (($value == $forum_data['forum_type']) ? ' selected="selected"' : '') . '>' . $user->lang['TYPE_' . $lang] . '</option>';
553
				}
554
555
				$styles_list = style_select($forum_data['forum_style'], true);
556
557
				$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>';
558
559
				$sql = 'SELECT forum_id
560
					FROM ' . FORUMS_TABLE . '
561
					WHERE forum_type = ' . FORUM_POST . "
562
						AND forum_id <> $forum_id";
563
				$result = $db->sql_query($sql);
564
565
				if ($db->sql_fetchrow($result))
566
				{
567
					$template->assign_vars(array(
568
						'S_MOVE_FORUM_OPTIONS'		=> make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))
569
					);
570
				}
571
				$db->sql_freeresult($result);
572
573
				// Subforum move options
574
				if ($action == 'edit' && $forum_data['forum_type'] == FORUM_CAT)
575
				{
576
					$subforums_id = array();
577
					$subforums = get_forum_branch($forum_id, 'children');
578
579
					foreach ($subforums as $row)
580
					{
581
						$subforums_id[] = $row['forum_id'];
582
					}
583
584
					$forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
585
586
					$sql = 'SELECT forum_id
587
						FROM ' . FORUMS_TABLE . '
588
						WHERE forum_type = ' . FORUM_POST . "
589
							AND forum_id <> $forum_id";
590
					$result = $db->sql_query($sql);
591
592
					if ($db->sql_fetchrow($result))
593
					{
594
						$template->assign_vars(array(
595
							'S_MOVE_FORUM_OPTIONS'		=> make_forum_select($forum_data['parent_id'], $subforums_id)) // , false, true, false???
596
						);
597
					}
598
					$db->sql_freeresult($result);
599
600
					$template->assign_vars(array(
601
						'S_HAS_SUBFORUMS'		=> ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
602
						'S_FORUMS_LIST'			=> $forums_list)
603
					);
604
				}
605
606
				$s_show_display_on_index = false;
607
608
				if ($forum_data['parent_id'] > 0)
609
				{
610
					// if this forum is a subforum put the "display on index" checkbox
611
					if ($parent_info = $this->get_forum_info($forum_data['parent_id']))
612
					{
613
						if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT)
614
						{
615
							$s_show_display_on_index = true;
616
						}
617
					}
618
				}
619
620
				if (strlen($forum_data['forum_password']) == 32)
621
				{
622
					$errors[] = $user->lang['FORUM_PASSWORD_OLD'];
623
				}
624
625
				$template->assign_vars(array(
626
					'S_EDIT_FORUM'		=> true,
627
					'S_ERROR'			=> (sizeof($errors)) ? true : false,
628
					'S_PARENT_ID'		=> $this->parent_id,
629
					'S_FORUM_PARENT_ID'	=> $forum_data['parent_id'],
630
					'S_ADD_ACTION'		=> ($action == 'add') ? true : false,
631
632
					'U_BACK'		=> $this->u_action . '&amp;parent_id=' . $this->parent_id,
633
					'U_EDIT_ACTION'	=> $this->u_action . "&amp;parent_id={$this->parent_id}&amp;action=$action&amp;f=$forum_id",
634
635
					'L_COPY_PERMISSIONS_EXPLAIN'	=> $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'],
636
					'L_TITLE'						=> $user->lang[$this->page_title],
637
					'ERROR_MSG'						=> (sizeof($errors)) ? implode('<br />', $errors) : '',
638
639
					'FORUM_NAME'				=> $forum_data['forum_name'],
640
					'FORUM_DATA_LINK'			=> $forum_data['forum_link'],
641
					'FORUM_IMAGE'				=> $forum_data['forum_image'],
642
					'FORUM_IMAGE_SRC'			=> ($forum_data['forum_image']) ? $phpbb_root_path . $forum_data['forum_image'] : '',
643
					'FORUM_POST'				=> FORUM_POST,
644
					'FORUM_LINK'				=> FORUM_LINK,
645
					'FORUM_CAT'					=> FORUM_CAT,
646
					'PRUNE_FREQ'				=> $forum_data['prune_freq'],
647
					'PRUNE_DAYS'				=> $forum_data['prune_days'],
648
					'PRUNE_VIEWED'				=> $forum_data['prune_viewed'],
649
					'TOPICS_PER_PAGE'			=> $forum_data['forum_topics_per_page'],
650
					'FORUM_RULES_LINK'			=> $forum_data['forum_rules_link'],
651
					'FORUM_RULES'				=> $forum_data['forum_rules'],
652
					'FORUM_RULES_PREVIEW'		=> $forum_rules_preview,
653
					'FORUM_RULES_PLAIN'			=> $forum_rules_data['text'],
654
					'S_BBCODE_CHECKED'			=> ($forum_rules_data['allow_bbcode']) ? true : false,
655
					'S_SMILIES_CHECKED'			=> ($forum_rules_data['allow_smilies']) ? true : false,
656
					'S_URLS_CHECKED'			=> ($forum_rules_data['allow_urls']) ? true : false,
657
					'S_FORUM_PASSWORD_SET'		=> (empty($forum_data['forum_password'])) ? false : true,
658
659
					'FORUM_DESC'				=> $forum_desc_data['text'],
660
					'S_DESC_BBCODE_CHECKED'		=> ($forum_desc_data['allow_bbcode']) ? true : false,
661
					'S_DESC_SMILIES_CHECKED'	=> ($forum_desc_data['allow_smilies']) ? true : false,
662
					'S_DESC_URLS_CHECKED'		=> ($forum_desc_data['allow_urls']) ? true : false,
663
664
					'S_FORUM_TYPE_OPTIONS'		=> $forum_type_options,
665
					'S_STATUS_OPTIONS'			=> $statuslist,
666
					'S_PARENT_OPTIONS'			=> $parents_list,
667
					'S_STYLES_OPTIONS'			=> $styles_list,
668
					'S_FORUM_OPTIONS'			=> make_forum_select(($action == 'add') ? $forum_data['parent_id'] : false, ($action == 'edit') ? $forum_data['forum_id'] : false, false, false, false),
669
					'S_SHOW_DISPLAY_ON_INDEX'	=> $s_show_display_on_index,
670
					'S_FORUM_POST'				=> ($forum_data['forum_type'] == FORUM_POST) ? true : false,
671
					'S_FORUM_ORIG_POST'			=> (isset($old_forum_type) && $old_forum_type == FORUM_POST) ? true : false,
672
					'S_FORUM_ORIG_CAT'			=> (isset($old_forum_type) && $old_forum_type == FORUM_CAT) ? true : false,
673
					'S_FORUM_ORIG_LINK'			=> (isset($old_forum_type) && $old_forum_type == FORUM_LINK) ? true : false,
674
					'S_FORUM_LINK'				=> ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
675
					'S_FORUM_CAT'				=> ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
676
					'S_ENABLE_INDEXING'			=> ($forum_data['enable_indexing']) ? true : false,
677
					'S_TOPIC_ICONS'				=> ($forum_data['enable_icons']) ? true : false,
678
					'S_DISPLAY_SUBFORUM_LIST'	=> ($forum_data['display_subforum_list']) ? true : false,
679
					'S_DISPLAY_ON_INDEX'		=> ($forum_data['display_on_index']) ? true : false,
680
					'S_PRUNE_ENABLE'			=> ($forum_data['enable_prune']) ? true : false,
681
					'S_FORUM_LINK_TRACK'		=> ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? true : false,
682
					'S_PRUNE_OLD_POLLS'			=> ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL) ? true : false,
683
					'S_PRUNE_ANNOUNCE'			=> ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE) ? true : false,
684
					'S_PRUNE_STICKY'			=> ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_STICKY) ? true : false,
685
					'S_DISPLAY_ACTIVE_TOPICS'	=> ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) ? true : false,
686
					'S_ENABLE_POST_REVIEW'		=> ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,
687
					'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,
688
				));
689
690
				return;
691
692
			break;
693
694
			case 'delete':
695
696
				if (!$forum_id)
697
				{
698
					trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
699
				}
700
701
				$forum_data = $this->get_forum_info($forum_id);
702
703
				$subforums_id = array();
704
				$subforums = get_forum_branch($forum_id, 'children');
705
706
				foreach ($subforums as $row)
707
				{
708
					$subforums_id[] = $row['forum_id'];
709
				}
710
711
				$forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
712
713
				$sql = 'SELECT forum_id
714
					FROM ' . FORUMS_TABLE . '
715
					WHERE forum_type = ' . FORUM_POST . "
716
						AND forum_id <> $forum_id";
717
				$result = $db->sql_query($sql);
718
719
				if ($db->sql_fetchrow($result))
720
				{
721
					$template->assign_vars(array(
722
						'S_MOVE_FORUM_OPTIONS'		=> make_forum_select($forum_data['parent_id'], $subforums_id, false, true)) // , false, true, false???
723
					);
724
				}
725
				$db->sql_freeresult($result);
726
727
				$parent_id = ($this->parent_id == $forum_id) ? 0 : $this->parent_id;
728
729
				$template->assign_vars(array(
730
					'S_DELETE_FORUM'		=> true,
731
					'U_ACTION'				=> $this->u_action . "&amp;parent_id={$parent_id}&amp;action=delete&amp;f=$forum_id",
732
					'U_BACK'				=> $this->u_action . '&amp;parent_id=' . $this->parent_id,
733
734
					'FORUM_NAME'			=> $forum_data['forum_name'],
735
					'S_FORUM_POST'			=> ($forum_data['forum_type'] == FORUM_POST) ? true : false,
736
					'S_FORUM_LINK'			=> ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
737
					'S_HAS_SUBFORUMS'		=> ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
738
					'S_FORUMS_LIST'			=> $forums_list,
739
					'S_ERROR'				=> (sizeof($errors)) ? true : false,
740
					'ERROR_MSG'				=> (sizeof($errors)) ? implode('<br />', $errors) : '')
741
				);
742
743
				return;
744
			break;
745
		}
746
747
		// Default management page
748
		if (!$this->parent_id)
749
		{
750
			$navigation = $user->lang['FORUM_INDEX'];
751
		}
752
		else
753
		{
754
			$navigation = '<a href="' . $this->u_action . '">' . $user->lang['FORUM_INDEX'] . '</a>';
755
756
			$forums_nav = get_forum_branch($this->parent_id, 'parents', 'descending');
757
			foreach ($forums_nav as $row)
758
			{
759
				if ($row['forum_id'] == $this->parent_id)
760
				{
761
					$navigation .= ' -&gt; ' . $row['forum_name'];
762
				}
763
				else
764
				{
765
					$navigation .= ' -&gt; <a href="' . $this->u_action . '&amp;parent_id=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>';
766
				}
767
			}
768
		}
769
770
		// Jumpbox
771
		$forum_box = make_forum_select($this->parent_id, false, false, false, false); //make_forum_select($this->parent_id);
772
773
		if ($action == 'sync' || $action == 'sync_forum')
774
		{
775
			$template->assign_var('S_RESYNCED', true);
776
		}
777
778
		$sql = 'SELECT *
779
			FROM ' . FORUMS_TABLE . "
780
			WHERE parent_id = $this->parent_id
781
			ORDER BY left_id";
782
		$result = $db->sql_query($sql);
783
784
		if ($row = $db->sql_fetchrow($result))
785
		{
786
			do
787
			{
788
				$forum_type = $row['forum_type'];
789
790
				if ($row['forum_status'] == ITEM_LOCKED)
791
				{
792
					$folder_image = '<img src="images/icon_folder_lock.gif" alt="' . $user->lang['LOCKED'] . '" />';
793
				}
794
				else
795
				{
796
					switch ($forum_type)
797
					{
798
						case FORUM_LINK:
799
							$folder_image = '<img src="images/icon_folder_link.gif" alt="' . $user->lang['LINK'] . '" />';
800
						break;
801
802
						default:
803
							$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'] . '" />';
804
						break;
805
					}
806
				}
807
808
				$url = $this->u_action . "&amp;parent_id=$this->parent_id&amp;f={$row['forum_id']}";
809
810
				$forum_title = ($forum_type != FORUM_LINK) ? '<a href="' . $this->u_action . '&amp;parent_id=' . $row['forum_id'] . '">' : '';
811
				$forum_title .= $row['forum_name'];
812
				$forum_title .= ($forum_type != FORUM_LINK) ? '</a>' : '';
813
814
				$template->assign_block_vars('forums', array(
815
					'FOLDER_IMAGE'		=> $folder_image,
816
					'FORUM_IMAGE'		=> ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '',
817
					'FORUM_IMAGE_SRC'	=> ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
818
					'FORUM_NAME'		=> $row['forum_name'],
819
					'FORUM_DESCRIPTION'	=> generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
820
					'FORUM_TOPICS'		=> $row['forum_topics'],
821
					'FORUM_POSTS'		=> $row['forum_posts'],
822
823
					'S_FORUM_LINK'		=> ($forum_type == FORUM_LINK) ? true : false,
824
					'S_FORUM_POST'		=> ($forum_type == FORUM_POST) ? true : false,
825
826
					'U_FORUM'			=> $this->u_action . '&amp;parent_id=' . $row['forum_id'],
827
					'U_MOVE_UP'			=> $url . '&amp;action=move_up',
828
					'U_MOVE_DOWN'		=> $url . '&amp;action=move_down',
829
					'U_EDIT'			=> $url . '&amp;action=edit',
830
					'U_DELETE'			=> $url . '&amp;action=delete',
831
					'U_SYNC'			=> $url . '&amp;action=sync')
832
				);
833
			}
834
			while ($row = $db->sql_fetchrow($result));
835
		}
836
		else if ($this->parent_id)
837
		{
838
			$row = $this->get_forum_info($this->parent_id);
839
840
			$url = $this->u_action . '&amp;parent_id=' . $this->parent_id . '&amp;f=' . $row['forum_id'];
841
842
			$template->assign_vars(array(
843
				'S_NO_FORUMS'		=> true,
844
845
				'U_EDIT'			=> $url . '&amp;action=edit',
846
				'U_DELETE'			=> $url . '&amp;action=delete',
847
				'U_SYNC'			=> $url . '&amp;action=sync')
848
			);
849
		}
850
		$db->sql_freeresult($result);