punbb/admin/forums.php
changeset 6 5e1f1e916419
child 9 a932ce8c4827
equal deleted inserted replaced
5:e3d7322305bf 6:5e1f1e916419
       
     1 <?php
       
     2 /***********************************************************************
       
     3 
       
     4   Copyright (C) 2002-2008  PunBB.org
       
     5 
       
     6   This file is part of PunBB.
       
     7 
       
     8   PunBB is free software; you can redistribute it and/or modify it
       
     9   under the terms of the GNU General Public License as published
       
    10   by the Free Software Foundation; either version 2 of the License,
       
    11   or (at your option) any later version.
       
    12 
       
    13   PunBB is distributed in the hope that it will be useful, but
       
    14   WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16   GNU General Public License for more details.
       
    17 
       
    18   You should have received a copy of the GNU General Public License
       
    19   along with this program; if not, write to the Free Software
       
    20   Foundation, Inc., 59 Temple Place, Suite 330, Boston,
       
    21   MA  02111-1307  USA
       
    22 
       
    23 ************************************************************************/
       
    24 
       
    25 
       
    26 // if (!defined('PUN_ROOT'))
       
    27 // 	define('PUN_ROOT', '../');
       
    28 // require PUN_ROOT.'include/common.php';
       
    29 require PUN_ROOT.'include/common_admin.php';
       
    30 
       
    31 // import globals (I really hope this isn't dangerous)
       
    32 foreach ( $GLOBALS as $key => $_ )
       
    33 {
       
    34   $$key =& $GLOBALS[$key];
       
    35 }
       
    36 
       
    37 ($hook = get_hook('afo_start')) ? eval($hook) : null;
       
    38 
       
    39 if ($session->user_level < USER_LEVEL_ADMIN)
       
    40 	message($lang_common['No permission']);
       
    41 
       
    42 // Load the admin.php language file
       
    43 require PUN_ROOT.'lang/'.$pun_user['language'].'/admin.php';
       
    44 $GLOBALS['lang_admin'] = $lang_admin;
       
    45 
       
    46 
       
    47 // Add a "default" forum
       
    48 if (isset($_POST['add_forum']))
       
    49 {
       
    50 	$add_to_cat = intval($_POST['add_to_cat']);
       
    51 	if ($add_to_cat < 1)
       
    52 		message($lang_common['Bad request']);
       
    53 
       
    54 	$forum_name = trim($_POST['forum_name']);
       
    55 	$position = intval($_POST['position']);
       
    56 
       
    57 	($hook = get_hook('afo_add_forum_form_submitted')) ? eval($hook) : null;
       
    58 
       
    59 	if ($forum_name == '')
       
    60 		message($lang_admin['Must enter forum message']);
       
    61 
       
    62 	$query = array(
       
    63 		'INSERT'	=> 'forum_name, disp_position, cat_id',
       
    64 		'INTO'		=> 'forums',
       
    65 		'VALUES'	=> '\''.$pun_db->escape($forum_name).'\', '.$position.', '.$add_to_cat
       
    66 	);
       
    67 
       
    68 	($hook = get_hook('afo_qr_add_forum')) ? eval($hook) : null;
       
    69 	$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
    70 
       
    71 	// Regenerate the quickjump cache
       
    72 	require_once PUN_ROOT.'include/cache.php';
       
    73 	generate_quickjump_cache();
       
    74 
       
    75 	pun_redirect(pun_link($pun_url['admin_forums']), $lang_admin['Forum added'].' '.$lang_admin['Redirect']);
       
    76 }
       
    77 
       
    78 
       
    79 // Delete a forum
       
    80 else if (isset($_GET['del_forum']))
       
    81 {
       
    82 	$forum_to_delete = intval($_GET['del_forum']);
       
    83 	if ($forum_to_delete < 1)
       
    84 		message($lang_common['Bad request']);
       
    85 
       
    86 	// User pressed the cancel button
       
    87 	if (isset($_POST['del_forum_cancel']))
       
    88 		pun_redirect(pun_link($pun_url['admin_forums']), $lang_admin['Cancel redirect']);
       
    89 
       
    90 	($hook = get_hook('afo_del_forum_form_submitted')) ? eval($hook) : null;
       
    91 
       
    92 	if (isset($_POST['del_forum_comply']))	// Delete a forum with all posts
       
    93 	{
       
    94 		@set_time_limit(0);
       
    95 
       
    96 		// Prune all posts and topics
       
    97 		prune($forum_to_delete, 1, -1);
       
    98 
       
    99 		delete_orphans();
       
   100 
       
   101 		// Delete the forum and any forum specific group permissions
       
   102 		$query = array(
       
   103 			'DELETE'	=> 'forums',
       
   104 			'WHERE'		=> 'id='.$forum_to_delete
       
   105 		);
       
   106 
       
   107 		($hook = get_hook('afo_qr_delete_forum')) ? eval($hook) : null;
       
   108 		$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   109 
       
   110 		$query = array(
       
   111 			'DELETE'	=> 'forum_perms',
       
   112 			'WHERE'		=> 'forum_id='.$forum_to_delete
       
   113 		);
       
   114 
       
   115 		($hook = get_hook('afo_qr_delete_forum_perms')) ? eval($hook) : null;
       
   116 		$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   117 
       
   118 		// Regenerate the quickjump cache
       
   119 		require_once PUN_ROOT.'include/cache.php';
       
   120 		generate_quickjump_cache();
       
   121 
       
   122 		pun_redirect(pun_link($pun_url['admin_forums']), $lang_admin['Forum deleted'].' '.$lang_admin['Redirect']);
       
   123 	}
       
   124 	else	// If the user hasn't confirmed the delete
       
   125 	{
       
   126 		$query = array(
       
   127 			'SELECT'	=> 'f.forum_name',
       
   128 			'FROM'		=> 'forums AS f',
       
   129 			'WHERE'		=> 'f.id='.$forum_to_delete
       
   130 		);
       
   131 
       
   132 		($hook = get_hook('afo_qr_get_forum_name')) ? eval($hook) : null;
       
   133 		$result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   134 		$forum_name = $pun_db->result($result);
       
   135 
       
   136 
       
   137 		// Setup breadcrumbs
       
   138 		$pun_page['crumbs'] = array(
       
   139 			array($pun_config['o_board_title'], pun_link($pun_url['index'])),
       
   140 			array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])),
       
   141 			array($lang_admin['Forums'], pun_link($pun_url['admin_forums'])),
       
   142 			$lang_admin['Delete forum']
       
   143 		);
       
   144 
       
   145 		($hook = get_hook('afo_del_forum_pre_header_load')) ? eval($hook) : null;
       
   146 
       
   147 		define('PUN_PAGE_SECTION', 'start');
       
   148 		define('PUN_PAGE', 'admin-forums');
       
   149 		require PUN_ROOT.'header.php';
       
   150 
       
   151 ?>
       
   152 <div id="pun-main" class="main sectioned admin">
       
   153 
       
   154 <?php echo generate_admin_menu(); ?>
       
   155 
       
   156 	<div class="main-head">
       
   157 		<h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1>
       
   158 	</div>
       
   159 
       
   160 	<div class="main-content frm">
       
   161 		<div class="frm-head">
       
   162 			<h2><span><?php printf($lang_admin['Confirm delete forum'], htmlspecialchars($forum_name)) ?></span></h2>
       
   163 		</div>
       
   164 		<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_forums']) ?>&amp;del_forum=<?php echo $forum_id ?>">
       
   165 			<div class="hidden">
       
   166 				<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_forums']).'&del_forum='.$forum_id) ?>" />
       
   167 			</div>
       
   168 			<div class="frm-info">
       
   169 				<p class="warn"><?php echo $lang_admin['Delete forum warning'] ?></p>
       
   170 			</div>
       
   171 			<div class="frm-buttons">
       
   172 				<span class="submit"><input type="submit" name="del_forum_comply" value="<?php echo $lang_admin['Delete'] ?>" /></span>
       
   173 				<span class="cancel"><input type="submit" name="del_forum_cancel" value="<?php echo $lang_admin['Cancel'] ?>" /></span>
       
   174 			</div>
       
   175 		</form>
       
   176 	</div>
       
   177 
       
   178 </div>
       
   179 <?php
       
   180 
       
   181 		require PUN_ROOT.'footer.php';
       
   182 	}
       
   183 }
       
   184 
       
   185 
       
   186 // Update forum positions
       
   187 else if (isset($_POST['update_positions']))
       
   188 {
       
   189 	$positions = array_map('intval', $_POST['position']);
       
   190 
       
   191 	($hook = get_hook('afo_update_positions_form_submitted')) ? eval($hook) : null;
       
   192 
       
   193 	$query = array(
       
   194 		'SELECT'	=> 'f.id, f.disp_position',
       
   195 		'FROM'		=> 'categories AS c',
       
   196 		'JOINS'		=> array(
       
   197 			array(
       
   198 				'INNER JOIN'	=> 'forums AS f',
       
   199 				'ON'			=> 'c.id=f.cat_id'
       
   200 			)
       
   201 		),
       
   202 		'ORDER BY'	=> 'c.disp_position, c.id, f.disp_position'
       
   203 	);
       
   204 
       
   205 	($hook = get_hook('afo_qr_get_forums')) ? eval($hook) : null;
       
   206 	$result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   207 	while ($cur_forum = $pun_db->fetch_assoc($result))
       
   208 	{
       
   209 		// If these aren't set, we're looking at a forum that was added after
       
   210 		// the admin started editing: we don't want to mess with it
       
   211 		if (isset($positions[$cur_forum['id']]))
       
   212 		{
       
   213 			$new_disp_position = $positions[$cur_forum['id']];
       
   214 
       
   215 			if ($new_disp_position < 0)
       
   216 				message($lang_admin['Must be integer']);
       
   217 
       
   218 			// We only want to update if we changed the position
       
   219 			if ($cur_forum['disp_position'] != $new_disp_position)
       
   220 			{
       
   221 				$query = array(
       
   222 					'UPDATE'	=> 'forums',
       
   223 					'SET'		=> 'disp_position='.$new_disp_position,
       
   224 					'WHERE'		=> 'id='.$cur_forum['id']
       
   225 				);
       
   226 
       
   227 				($hook = get_hook('afo_qr_update_forum_position')) ? eval($hook) : null;
       
   228 				$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   229 			}
       
   230 		}
       
   231 	}
       
   232 
       
   233 	// Regenerate the quickjump cache
       
   234 	require_once PUN_ROOT.'include/cache.php';
       
   235 	generate_quickjump_cache();
       
   236 
       
   237 	pun_redirect(pun_link($pun_url['admin_forums']), $lang_admin['Forums updated'].' '.$lang_admin['Redirect']);
       
   238 }
       
   239 
       
   240 
       
   241 else if (isset($_GET['edit_forum']))
       
   242 {
       
   243 	$forum_id = intval($_GET['edit_forum']);
       
   244 	if ($forum_id < 1)
       
   245 		message($lang_common['Bad request']);
       
   246 
       
   247 	// Update group permissions for $forum_id
       
   248 	if (isset($_POST['save']))
       
   249 	{
       
   250 		($hook = get_hook('afo_save_forum_form_submitted')) ? eval($hook) : null;
       
   251 
       
   252 		// Start with the forum details
       
   253 		$forum_name = trim($_POST['forum_name']);
       
   254 		$forum_desc = pun_linebreaks(trim($_POST['forum_desc']));
       
   255 		$cat_id = intval($_POST['cat_id']);
       
   256 		$sort_by = intval($_POST['sort_by']);
       
   257 		$redirect_url = isset($_POST['redirect_url']) ? trim($_POST['redirect_url']) : null;
       
   258 
       
   259 		if ($forum_name == '')
       
   260 			message($lang_admin['Must enter forum message']);
       
   261 
       
   262 		if ($cat_id < 1)
       
   263 			message($lang_common['Bad request']);
       
   264 
       
   265 		$forum_desc = ($forum_desc != '') ? '\''.$pun_db->escape($forum_desc).'\'' : 'NULL';
       
   266 		$redirect_url = ($redirect_url != '') ? '\''.$pun_db->escape($redirect_url).'\'' : 'NULL';
       
   267 
       
   268 		$query = array(
       
   269 			'UPDATE'	=> 'forums',
       
   270 			'SET'		=> 'forum_name=\''.$pun_db->escape($forum_name).'\', forum_desc='.$forum_desc.', redirect_url='.$redirect_url.', sort_by='.$sort_by.', cat_id='.$cat_id,
       
   271 			'WHERE'		=> 'id='.$forum_id
       
   272 		);
       
   273 
       
   274 		($hook = get_hook('afo_qr_update_forum')) ? eval($hook) : null;
       
   275 		$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   276 
       
   277 		// Now let's deal with the permissions
       
   278 		if (isset($_POST['read_forum_old']))
       
   279 		{
       
   280 			$query = array(
       
   281 				'SELECT'	=> 'g.g_id, g.g_read_board, g.g_post_replies, g.g_post_topics',
       
   282 				'FROM'		=> 'groups AS g',
       
   283 				'WHERE'		=> 'g_id!='.PUN_ADMIN
       
   284 			);
       
   285 
       
   286 			($hook = get_hook('afo_qr_get_groups')) ? eval($hook) : null;
       
   287 			$result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   288 			while ($cur_group = $pun_db->fetch_assoc($result))
       
   289 			{
       
   290 				$read_forum_new = ($cur_group['g_read_board'] == '1') ? isset($_POST['read_forum_new'][$cur_group['g_id']]) ? '1' : '0' : intval($_POST['read_forum_old'][$cur_group['g_id']]);
       
   291 				$post_replies_new = isset($_POST['post_replies_new'][$cur_group['g_id']]) ? '1' : '0';
       
   292 				$post_topics_new = isset($_POST['post_topics_new'][$cur_group['g_id']]) ? '1' : '0';
       
   293 
       
   294 				// Check if the new settings differ from the old
       
   295 				if ($read_forum_new != $_POST['read_forum_old'][$cur_group['g_id']] || $post_replies_new != $_POST['post_replies_old'][$cur_group['g_id']] || $post_topics_new != $_POST['post_topics_old'][$cur_group['g_id']])
       
   296 				{
       
   297 					// If the new settings are identical to the default settings for this group, delete its row in forum_perms
       
   298 					if ($read_forum_new == '1' && $post_replies_new == $cur_group['g_post_replies'] && $post_topics_new == $cur_group['g_post_topics'])
       
   299 					{
       
   300 						$query = array(
       
   301 							'DELETE'	=> 'forum_perms',
       
   302 							'WHERE'		=> 'group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id
       
   303 						);
       
   304 
       
   305 						($hook = get_hook('afo_qr_delete_group_forum_perms')) ? eval($hook) : null;
       
   306 						$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   307 					}
       
   308 					else
       
   309 					{
       
   310 						// Run an UPDATE and see if it affected a row, if not, INSERT
       
   311 						$query = array(
       
   312 							'UPDATE'	=> 'forum_perms',
       
   313 							'SET'		=> 'read_forum='.$read_forum_new.', post_replies='.$post_replies_new.', post_topics='.$post_topics_new,
       
   314 							'WHERE'		=> 'group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id
       
   315 						);
       
   316 
       
   317 						($hook = get_hook('afo_qr_update_forum_perms')) ? eval($hook) : null;
       
   318 						$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   319 						if (!$pun_db->affected_rows())
       
   320 						{
       
   321 							$query = array(
       
   322 								'INSERT'	=> 'group_id, forum_id, read_forum, post_replies, post_topics',
       
   323 								'INTO'		=> 'forum_perms',
       
   324 								'VALUES'	=> $cur_group['g_id'].', '.$forum_id.', '.$read_forum_new.', '.$post_replies_new.', '.$post_topics_new
       
   325 							);
       
   326 
       
   327 							($hook = get_hook('afo_qr_add_forum_perms')) ? eval($hook) : null;
       
   328 							$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   329 						}
       
   330 					}
       
   331 				}
       
   332 			}
       
   333 		}
       
   334 
       
   335 		// Regenerate the quickjump cache
       
   336 		require_once PUN_ROOT.'include/cache.php';
       
   337 		generate_quickjump_cache();
       
   338 
       
   339 		pun_redirect(pun_link($pun_url['admin_forums']), $lang_admin['Forum updated'].' '.$lang_admin['Redirect']);
       
   340 	}
       
   341 	else if (isset($_POST['revert_perms']))
       
   342 	{
       
   343 		($hook = get_hook('afo_revert_perms_form_submitted')) ? eval($hook) : null;
       
   344 
       
   345 		$query = array(
       
   346 			'DELETE'	=> 'forum_perms',
       
   347 			'WHERE'		=> 'forum_id='.$forum_id
       
   348 		);
       
   349 
       
   350 		($hook = get_hook('afo_qr_delete_forum_perms')) ? eval($hook) : null;
       
   351 		$pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   352 
       
   353 		// Regenerate the quickjump cache
       
   354 		require_once PUN_ROOT.'include/cache.php';
       
   355 		generate_quickjump_cache();
       
   356 
       
   357 		pun_redirect(pun_link($pun_url['admin_forums']).'&edit_forum='.$forum_id, $lang_admin['Permissions reverted'].' '.$lang_admin['Redirect']);
       
   358 	}
       
   359 
       
   360 	// Fetch forum info
       
   361 	$query = array(
       
   362 		'SELECT'	=> 'f.id, f.forum_name, f.forum_desc, f.redirect_url, f.num_topics, f.sort_by, f.cat_id',
       
   363 		'FROM'		=> 'forums AS f',
       
   364 		'WHERE'		=> 'id='.$forum_id
       
   365 	);
       
   366 
       
   367 	($hook = get_hook('afo_qr_get_forum_details')) ? eval($hook) : null;
       
   368 	$result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   369 	if (!$pun_db->num_rows($result))
       
   370 		message($lang_common['Bad request']);
       
   371 
       
   372 	$cur_forum = $pun_db->fetch_assoc($result);
       
   373 
       
   374 	$pun_page['form_info'] = array();
       
   375 	if ($cur_forum['redirect_url'])
       
   376 		$pun_page['form_info'][] = '<li><span>'.$lang_admin['Forum perms info 2'].'</span></li>';
       
   377 
       
   378 	$pun_page['form_info'][] = '<li><span>'.$lang_admin['Forum perms info 1'].'</span></li>';
       
   379 	$pun_page['form_info'][] = '<li><span>'.$lang_admin['Forum perms info 3'].'</span></li>';
       
   380 	$pun_page['form_info'][] = '<li><span>'. sprintf($lang_admin['Group key'], '<a href="'.pun_link($pun_url['admin_groups']).'">'.$lang_admin['User groups'].'</a>').'</span></li>';
       
   381 
       
   382 	// Setup the form
       
   383 	$pun_page['part_count'] = $pun_page['set_count'] = $pun_page['fld_count'] = 0;
       
   384 
       
   385 	// Setup breadcrumbs
       
   386 	$pun_page['crumbs'] = array(
       
   387 		array($pun_config['o_board_title'], pun_link($pun_url['index'])),
       
   388 		array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])),
       
   389 		array($lang_admin['Forums'], pun_link($pun_url['admin_forums'])),
       
   390 		$lang_admin['Edit forum']
       
   391 	);
       
   392 
       
   393 	($hook = get_hook('afo_edit_forum_pre_header_load')) ? eval($hook) : null;
       
   394 
       
   395 	define('PUN_PAGE_SECTION', 'start');
       
   396 	define('PUN_PAGE', 'admin-forums');
       
   397 	require PUN_ROOT.'header.php';
       
   398 
       
   399 ?>
       
   400 <div id="pun-main" class="main sectioned admin">
       
   401 
       
   402 <?php echo generate_admin_menu(); ?>
       
   403 
       
   404 	<div class="main-head">
       
   405 		<h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1>
       
   406 	</div>
       
   407 
       
   408 	<form method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_forums']) ?>&amp;edit_forum=<?php echo $forum_id ?>">
       
   409 
       
   410 	<div class="main-content frm parted">
       
   411 		<div class="hidden">
       
   412 			<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_forums']).'&edit_forum='.$forum_id) ?>" />
       
   413 		</div>
       
   414 		<div class="frm-head">
       
   415 			<h2><span><?php echo $lang_admin['Edit forum head'] ?></span></h2>
       
   416 		</div>
       
   417 		<div class="frm-form">
       
   418 <?php ($hook = get_hook('afo_edit_forum_pre_details_part')) ? eval($hook) : null; ?>
       
   419 			<div class="frm-part part<?php echo ++ $pun_page['part_count'] ?>">
       
   420 				<h3><span><?php printf($lang_admin['Edit details head'], $pun_page['part_count']) ?></span></h3>
       
   421 				<fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>">
       
   422 					<legend class="frm-legend"><strong><?php echo $lang_admin['Edit forum details legend'] ?></strong></legend>
       
   423 					<div class="frm-fld text">
       
   424 						<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
       
   425 							<span class="fld-label"><?php echo $lang_admin['Forum name'] ?></span><br />
       
   426 							<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="forum_name" size="35" maxlength="80" value="<?php echo htmlspecialchars($cur_forum['forum_name']) ?>" /></span>
       
   427 						</label>
       
   428 					</div>
       
   429 					<div class="frm-fld text textarea">
       
   430 						<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
       
   431 							<span class="fld-label"><?php echo $lang_admin['Forum description'] ?></span><br />
       
   432 							<span class="fld-input"><textarea id="fld<?php echo $pun_page['fld_count'] ?>" name="forum_desc" rows="3" cols="50"><?php echo htmlspecialchars($cur_forum['forum_desc']) ?></textarea></span>
       
   433 							<span class="fld-help"><?php echo $lang_admin['Forum description help'] ?></span>
       
   434 						</label>
       
   435 					</div>
       
   436 					<div class="frm-fld select">
       
   437 						<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
       
   438 							<span class="fld-label"><?php echo $lang_admin['Category assignment'] ?></span><br />
       
   439 							<span class="fld-input"><select id="fld<?php echo $pun_page['fld_count'] ?>" name="cat_id">
       
   440 <?php
       
   441 
       
   442 	$query = array(
       
   443 		'SELECT'	=> 'c.id, c.cat_name',
       
   444 		'FROM'		=> 'categories AS c',
       
   445 		'ORDER BY'	=> 'c.disp_position'
       
   446 	);
       
   447 
       
   448 	($hook = get_hook('afo_qr_get_categories')) ? eval($hook) : null;
       
   449 	$result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   450 	while ($cur_cat = $pun_db->fetch_assoc($result))
       
   451 	{
       
   452 		$selected = ($cur_cat['id'] == $cur_forum['cat_id']) ? ' selected="selected"' : '';
       
   453 		echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_cat['id'].'"'.$selected.'>'.htmlspecialchars($cur_cat['cat_name']).'</option>'."\n";
       
   454 	}
       
   455 
       
   456 ?>
       
   457 								</select></span>
       
   458 						</label>
       
   459 					</div>
       
   460 					<div class="frm-fld select">
       
   461 						<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
       
   462 							<span class="fld-label"><?php echo $lang_admin['Sort topics by'] ?></span><br />
       
   463 							<span class="fld-input"><select id="fld<?php echo $pun_page['fld_count'] ?>" name="sort_by">
       
   464 									<option value="0"<?php if ($cur_forum['sort_by'] == '0') echo ' selected="selected"' ?>><?php echo $lang_admin['Sort last post'] ?></option>
       
   465 									<option value="1"<?php if ($cur_forum['sort_by'] == '1') echo ' selected="selected"' ?>><?php echo $lang_admin['Sort topic start'] ?></option>
       
   466 							</select></span>
       
   467 						</label>
       
   468 					</div>
       
   469 					<div class="frm-fld text">
       
   470 						<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
       
   471 							<span class="fld-label"><?php echo $lang_admin['Redirect URL'] ?></span><br />
       
   472 							<span class="fld-input"><?php echo ($cur_forum['num_topics']) ? '<input type="text" id="fld'.$pun_page['fld_count'].'" name="redirect_url" size="45" maxlength="100" value="Only available in empty forums" disabled="disabled" />' : '<input type="text" id="fld'.$pun_page['fld_count'].'" name="redirect_url" size="45" maxlength="100" value="'.htmlspecialchars($cur_forum['redirect_url']).'" />'; ?></span>
       
   473 						</label>
       
   474 					</div>
       
   475 <?php ($hook = get_hook('afo_edit_forum_details_end')) ? eval($hook) : null; ?>
       
   476 				</fieldset>
       
   477 			</div>
       
   478 <?php
       
   479 
       
   480 // Reset fieldset counter
       
   481 $pun_page['set_count'] = 0;
       
   482 
       
   483 ($hook = get_hook('afo_edit_forum_pre_permissions_part')) ? eval($hook) : null;
       
   484 
       
   485 ?>
       
   486 			<div class="frm-part part<?php echo ++ $pun_page['part_count'] ?>">
       
   487 				<h3><span><?php printf($lang_admin['Edit permissions head'], $pun_page['part_count']) ?></span></h3>
       
   488 				<div class="frm-info">
       
   489 					<ul>
       
   490 						<?php echo implode("\n\t\t\t\t\t", $pun_page['form_info'])."\n" ?>
       
   491 					</ul>
       
   492 				</div>
       
   493 				<fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>">
       
   494 					<legend class="frm-legend"><strong><?php echo $lang_admin['Edit forum perms legend'] ?></strong></legend>
       
   495 <?php
       
   496 
       
   497 	$i = 2;
       
   498 
       
   499 	$query = array(
       
   500 		'SELECT'	=> 'g.g_id, g.g_title, g.g_read_board, g.g_post_replies, g.g_post_topics, fp.read_forum, fp.post_replies, fp.post_topics',
       
   501 		'FROM'		=> 'groups AS g',
       
   502 		'JOINS'		=> array(
       
   503 			array(
       
   504 				'LEFT JOIN'		=> 'forum_perms AS fp',
       
   505 				'ON'			=> 'g.g_id=fp.group_id AND fp.forum_id='.$forum_id
       
   506 			)
       
   507 		),
       
   508 		'WHERE'		=> 'g.g_id!='.PUN_ADMIN,
       
   509 		'ORDER BY'	=> 'g.g_id'
       
   510 	);
       
   511 
       
   512 	($hook = get_hook('afo_qr_get_forum_perms')) ? eval($hook) : null;
       
   513 	$result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   514 	while ($cur_perm = $pun_db->fetch_assoc($result))
       
   515 	{
       
   516 		$read_forum = ($cur_perm['read_forum'] != '0') ? true : false;
       
   517 		$post_replies = (($cur_perm['g_post_replies'] == '0' && $cur_perm['post_replies'] == '1') || ($cur_perm['g_post_replies'] == '1' && $cur_perm['post_replies'] != '0')) ? true : false;
       
   518 		$post_topics = (($cur_perm['g_post_topics'] == '0' && $cur_perm['post_topics'] == '1') || ($cur_perm['g_post_topics'] == '1' && $cur_perm['post_topics'] != '0')) ? true : false;
       
   519 
       
   520 		// Determine if the current sittings differ from the default or not
       
   521 		$read_forum_def = ($cur_perm['read_forum'] == '0') ? false : true;
       
   522 		$post_replies_def = (($post_replies && $cur_perm['g_post_replies'] == '0') || (!$post_replies && ($cur_perm['g_post_replies'] == '' || $cur_perm['g_post_replies'] == '1'))) ? false : true;
       
   523 		$post_topics_def = (($post_topics && $cur_perm['g_post_topics'] == '0') || (!$post_topics && ($cur_perm['g_post_topics'] == '' || $cur_perm['g_post_topics'] == '1'))) ? false : true;
       
   524 
       
   525 ?>
       
   526 					<fieldset class="frm-group">
       
   527 						<legend><span><?php echo htmlspecialchars($cur_perm['g_title']) ?></span></legend>
       
   528 						<div class="radbox frm-choice">
       
   529 							<input type="hidden" name="read_forum_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($read_forum) ? '1' : '0'; ?>" />
       
   530 							<label for="fld<?php echo ++$pun_page['fld_count'] ?>"<?php if (!$read_forum_def) echo ' class="warn"' ?>><input type="checkbox" id="fld<?php echo $pun_page['fld_count'] ?>" name="read_forum_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php if ($read_forum) echo ' checked="checked"'; echo ($cur_perm['g_read_board'] == '0') ? ' disabled="disabled"' : ''; ?> /> <?php echo $lang_admin['Read forum'] ?> <?php if (!$read_forum_def) echo $lang_admin['Not default']  ?></label>
       
   531 							<input type="hidden" name="post_replies_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($post_replies) ? '1' : '0'; ?>" />
       
   532 							<label for="fld<?php echo ++$pun_page['fld_count'] ?>"<?php if (!$post_replies_def) echo ' class="warn"'; ?>><input type="checkbox" id="fld<?php echo $pun_page['fld_count'] ?>" name="post_replies_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php if ($post_replies) echo ' checked="checked"'; echo ($cur_forum['redirect_url'] != '') ? ' disabled="disabled"' : ''; ?> /> <?php echo $lang_admin['Post replies'] ?> <?php if (!$post_replies_def) echo $lang_admin['Not default'] ?></label>
       
   533 							<input type="hidden" name="post_topics_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($post_topics) ? '1' : '0'; ?>" />
       
   534 							<label for="fld<?php echo ++$pun_page['fld_count'] ?>"<?php if (!$post_topics_def) echo ' class="warn"'; ?>><input type="checkbox" id="fld<?php echo $pun_page['fld_count'] ?>" name="post_topics_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php if ($post_topics) echo ' checked="checked"'; echo ($cur_forum['redirect_url'] != '') ? ' disabled="disabled"' : ''; ?> /> <?php echo $lang_admin['Post topics'] ?> <?php if (!$post_topics_def) echo $lang_admin['Not default'] ?></label>
       
   535 <?php ($hook = get_hook('afo_edit_forum_new_permission')) ? eval($hook) : null; ?>
       
   536 						</div>
       
   537 					</fieldset>
       
   538 <?php
       
   539 
       
   540 		++$i;
       
   541 	}
       
   542 
       
   543 ?>
       
   544 					<p class="frm-fld link"><span class="fld-label"><?php echo $lang_admin['Administrators'] ?></span> <span class="fld-input"><?php echo $lang_admin['Admin full perms'] ?></span></p>
       
   545 <?php ($hook = get_hook('afo_edit_forum_permissions_end')) ? eval($hook) : null; ?>
       
   546 				</fieldset>
       
   547 			</div>
       
   548 			<div class="frm-buttons">
       
   549 				<span class="submit"><input type="submit" name="save" value="<?php echo $lang_admin['Save changes'] ?>" /></span>
       
   550 				<span class="submit"><input type="submit" name="revert_perms" value="<?php echo $lang_admin['Restore defaults'] ?>" /></span>
       
   551 			</div>
       
   552 		</div>
       
   553 	</div>
       
   554 	</form>
       
   555 
       
   556 </div>
       
   557 
       
   558 <?php
       
   559 
       
   560 	require PUN_ROOT.'footer.php';
       
   561 }
       
   562 
       
   563 // Setup the form
       
   564 $pun_page['fld_count'] = $pun_page['set_count'] = 0;
       
   565 
       
   566 // Setup breadcrumbs
       
   567 $pun_page['crumbs'] = array(
       
   568 	array($pun_config['o_board_title'], pun_link($pun_url['index'])),
       
   569 	array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])),
       
   570 	$lang_admin['Forums']
       
   571 );
       
   572 
       
   573 ($hook = get_hook('afo_pre_header_load')) ? eval($hook) : null;
       
   574 
       
   575 define('PUN_PAGE_SECTION', 'start');
       
   576 define('PUN_PAGE', 'admin-forums');
       
   577 require PUN_ROOT.'header.php';
       
   578 
       
   579 ?>
       
   580 <div id="pun-main" class="main sectioned admin">
       
   581 
       
   582 <?php echo generate_admin_menu(); ?>
       
   583 
       
   584 	<div class="main-head">
       
   585 		<h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1>
       
   586 	</div>
       
   587 
       
   588 	<div class="main-content frm">
       
   589 		<div class="frm-head">
       
   590 			<h2><span><?php echo $lang_admin['Add forum head'] ?></span></h2>
       
   591 		</div>
       
   592 		<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_forums']) ?>&amp;action=adddel">
       
   593 			<div class="hidden">
       
   594 				<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_forums']).'&action=adddel') ?>" />
       
   595 			</div>
       
   596 			<fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>">
       
   597 				<legend class="frm-legend"><strong><?php echo $lang_admin['Add forum legend'] ?></strong></legend>
       
   598 				<div class="frm-fld text">
       
   599 					<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
       
   600 						<span class="fld-label"><?php echo $lang_admin['Forum name'] ?></span><br />
       
   601 						<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="forum_name" size="35" maxlength="80" /></span>
       
   602 					</label>
       
   603 				</div>
       
   604 				<div class="frm-fld text">
       
   605 					<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
       
   606 						<span class="fld-label"><?php echo $lang_admin['Position'] ?></span><br />
       
   607 						<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="position" size="3" maxlength="3" /></span>
       
   608 						<span class="fld-extra"><?php echo $lang_admin['Forum position help'] ?></span>
       
   609 					</label>
       
   610 				</div>
       
   611 				<div class="frm-fld select">
       
   612 					<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
       
   613 						<span class="fld-label"><?php echo $lang_admin['Add to category'] ?></span><br />
       
   614 						<span class="fld-input"><select id="fld<?php echo $pun_page['fld_count'] ?>" name="add_to_cat">
       
   615 <?php
       
   616 
       
   617 	$query = array(
       
   618 		'SELECT'	=> 'c.id, c.cat_name',
       
   619 		'FROM'		=> 'categories AS c',
       
   620 		'ORDER BY'	=> 'c.disp_position'
       
   621 	);
       
   622 
       
   623 	($hook = get_hook('afo_qr_get_categories2')) ? eval($hook) : null;
       
   624 	$result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   625 	while ($cur_cat = $pun_db->fetch_assoc($result))
       
   626 		echo "\t\t\t\t\t\t\t".'<option value="'.$cur_cat['id'].'">'.htmlspecialchars($cur_cat['cat_name']).'</option>'."\n";
       
   627 
       
   628 ?>
       
   629 						</select></span>
       
   630 					</label>
       
   631 				</div>
       
   632 <?php ($hook = get_hook('afo_add_forum_fieldset_end')) ? eval($hook) : null; ?>
       
   633 			</fieldset>
       
   634 			<div class="frm-buttons">
       
   635 				<span class="submit"><input type="submit" class="button" name="add_forum" value=" <?php echo $lang_admin['Add forum'] ?> " /></span>
       
   636 			</div>
       
   637 		</form>
       
   638 	</div>
       
   639 
       
   640 <?php
       
   641 
       
   642 // Display all the categories and forums
       
   643 $query = array(
       
   644 	'SELECT'	=> 'c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.disp_position',
       
   645 	'FROM'		=> 'categories AS c',
       
   646 	'JOINS'		=> array(
       
   647 		array(
       
   648 			'INNER JOIN'	=> 'forums AS f',
       
   649 			'ON'			=> 'c.id=f.cat_id'
       
   650 		)
       
   651 	),
       
   652 	'ORDER BY'	=> 'c.disp_position, c.id, f.disp_position'
       
   653 );
       
   654 
       
   655 ($hook = get_hook('afo_qr_get_cats_and_forums')) ? eval($hook) : null;
       
   656 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
       
   657 
       
   658 if ($pun_db->num_rows($result))
       
   659 {
       
   660 	// Reset fieldset counter
       
   661 	$pun_page['set_count'] = 0;
       
   662 
       
   663 ?>
       
   664 	<div class="main-content frm">
       
   665 		<div class="frm-head">
       
   666 			<h2><span><?php echo $lang_admin['Edit forums head'] ?></span></h2>
       
   667 		</div>
       
   668 		<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_forums']) ?>&amp;action=edit">
       
   669 			<div class="hidden">
       
   670 				<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_forums']).'&action=edit') ?>" />
       
   671 			</div>
       
   672 
       
   673 <?php
       
   674 
       
   675 	$cur_category = 0;
       
   676 	$i = 2;
       
   677 
       
   678 	while ($cur_forum = $pun_db->fetch_assoc($result))
       
   679 	{
       
   680 		if ($cur_forum['cid'] != $cur_category)	// A new category since last iteration?
       
   681 		{
       
   682 			if ($i > 2) echo "\t\t\t".'</fieldset>'."\n";
       
   683 
       
   684 ?>
       
   685 			<fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>">
       
   686 				<legend class="frm-legend"><strong><?php echo htmlspecialchars($cur_forum['cat_name']) ?></strong></legend>
       
   687 				<h3 class="frm-fld link">
       
   688 					<span class="fld-label"><?php echo $lang_admin['Category'] ?></span>
       
   689 					<span class="fld-input">[ <?php echo htmlspecialchars($cur_forum['cat_name']) ?> ]</span>
       
   690 				</h3>
       
   691 <?php
       
   692 
       
   693 			$cur_category = $cur_forum['cid'];
       
   694 		}
       
   695 
       
   696 ?>
       
   697 				<div class="frm-fld text twin">
       
   698 					<span class="fld-label"><a href="<?php echo pun_link($pun_url['admin_forums']) ?>&amp;edit_forum=<?php echo $cur_forum['fid'] ?>"><span><?php echo $lang_admin['Edit'].'<span> '.htmlspecialchars($cur_forum['forum_name']).' </span></span>' ?></a><br /> <a href="<?php echo pun_link($pun_url['admin_forums']) ?>&amp;del_forum=<?php echo $cur_forum['fid'] ?>"><span><?php echo $lang_admin['Delete'].'<span> '.htmlspecialchars($cur_forum['forum_name']).'</span></span>' ?></a></span><br />
       
   699 					<label for="fld<?php echo ++$pun_page['fld_count'] ?>" class="twin2">
       
   700 						<span class="fld-label"><?php echo $lang_admin['Position'] ?></span><br />
       
   701 						<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="position[<?php echo $cur_forum['fid'] ?>]" size="3" maxlength="3" value="<?php echo $cur_forum['disp_position'] ?>" /></span>
       
   702 						<small class="extra"><?php echo htmlspecialchars($cur_forum['forum_name']) ?></span>
       
   703 					</label>
       
   704 				</div>
       
   705 <?php
       
   706 
       
   707 		++$i;
       
   708 	}
       
   709 
       
   710 ?>
       
   711 			</fieldset>
       
   712 			<div class="frm-buttons">
       
   713 				<span class="submit"><input type="submit" class="button" name="update_positions" value="<?php echo $lang_admin['Update positions'] ?>" /></span>
       
   714 			</div>
       
   715 		</form>
       
   716 <?php
       
   717 
       
   718 }
       
   719 
       
   720 ?>
       
   721 	</div>
       
   722 
       
   723 </div>
       
   724 <?php
       
   725 
       
   726 require PUN_ROOT.'footer.php';