diff -r e3d7322305bf -r 5e1f1e916419 punbb/admin/forums.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/punbb/admin/forums.php Sat Apr 05 23:56:45 2008 -0400 @@ -0,0 +1,726 @@ + $_ ) +{ + $$key =& $GLOBALS[$key]; +} + +($hook = get_hook('afo_start')) ? eval($hook) : null; + +if ($session->user_level < USER_LEVEL_ADMIN) + message($lang_common['No permission']); + +// Load the admin.php language file +require PUN_ROOT.'lang/'.$pun_user['language'].'/admin.php'; +$GLOBALS['lang_admin'] = $lang_admin; + + +// Add a "default" forum +if (isset($_POST['add_forum'])) +{ + $add_to_cat = intval($_POST['add_to_cat']); + if ($add_to_cat < 1) + message($lang_common['Bad request']); + + $forum_name = trim($_POST['forum_name']); + $position = intval($_POST['position']); + + ($hook = get_hook('afo_add_forum_form_submitted')) ? eval($hook) : null; + + if ($forum_name == '') + message($lang_admin['Must enter forum message']); + + $query = array( + 'INSERT' => 'forum_name, disp_position, cat_id', + 'INTO' => 'forums', + 'VALUES' => '\''.$pun_db->escape($forum_name).'\', '.$position.', '.$add_to_cat + ); + + ($hook = get_hook('afo_qr_add_forum')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + + // Regenerate the quickjump cache + require_once PUN_ROOT.'include/cache.php'; + generate_quickjump_cache(); + + pun_redirect(pun_link($pun_url['admin_forums']), $lang_admin['Forum added'].' '.$lang_admin['Redirect']); +} + + +// Delete a forum +else if (isset($_GET['del_forum'])) +{ + $forum_to_delete = intval($_GET['del_forum']); + if ($forum_to_delete < 1) + message($lang_common['Bad request']); + + // User pressed the cancel button + if (isset($_POST['del_forum_cancel'])) + pun_redirect(pun_link($pun_url['admin_forums']), $lang_admin['Cancel redirect']); + + ($hook = get_hook('afo_del_forum_form_submitted')) ? eval($hook) : null; + + if (isset($_POST['del_forum_comply'])) // Delete a forum with all posts + { + @set_time_limit(0); + + // Prune all posts and topics + prune($forum_to_delete, 1, -1); + + delete_orphans(); + + // Delete the forum and any forum specific group permissions + $query = array( + 'DELETE' => 'forums', + 'WHERE' => 'id='.$forum_to_delete + ); + + ($hook = get_hook('afo_qr_delete_forum')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + + $query = array( + 'DELETE' => 'forum_perms', + 'WHERE' => 'forum_id='.$forum_to_delete + ); + + ($hook = get_hook('afo_qr_delete_forum_perms')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + + // Regenerate the quickjump cache + require_once PUN_ROOT.'include/cache.php'; + generate_quickjump_cache(); + + pun_redirect(pun_link($pun_url['admin_forums']), $lang_admin['Forum deleted'].' '.$lang_admin['Redirect']); + } + else // If the user hasn't confirmed the delete + { + $query = array( + 'SELECT' => 'f.forum_name', + 'FROM' => 'forums AS f', + 'WHERE' => 'f.id='.$forum_to_delete + ); + + ($hook = get_hook('afo_qr_get_forum_name')) ? eval($hook) : null; + $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); + $forum_name = $pun_db->result($result); + + + // Setup breadcrumbs + $pun_page['crumbs'] = array( + array($pun_config['o_board_title'], pun_link($pun_url['index'])), + array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])), + array($lang_admin['Forums'], pun_link($pun_url['admin_forums'])), + $lang_admin['Delete forum'] + ); + + ($hook = get_hook('afo_del_forum_pre_header_load')) ? eval($hook) : null; + + define('PUN_PAGE_SECTION', 'start'); + define('PUN_PAGE', 'admin-forums'); + require PUN_ROOT.'header.php'; + +?> +
+ + + +
+

{ }

+
+ +
+
+

+
+
+ +
+

+
+
+ + +
+
+
+ +
+ 'f.id, f.disp_position', + 'FROM' => 'categories AS c', + 'JOINS' => array( + array( + 'INNER JOIN' => 'forums AS f', + 'ON' => 'c.id=f.cat_id' + ) + ), + 'ORDER BY' => 'c.disp_position, c.id, f.disp_position' + ); + + ($hook = get_hook('afo_qr_get_forums')) ? eval($hook) : null; + $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); + while ($cur_forum = $pun_db->fetch_assoc($result)) + { + // If these aren't set, we're looking at a forum that was added after + // the admin started editing: we don't want to mess with it + if (isset($positions[$cur_forum['id']])) + { + $new_disp_position = $positions[$cur_forum['id']]; + + if ($new_disp_position < 0) + message($lang_admin['Must be integer']); + + // We only want to update if we changed the position + if ($cur_forum['disp_position'] != $new_disp_position) + { + $query = array( + 'UPDATE' => 'forums', + 'SET' => 'disp_position='.$new_disp_position, + 'WHERE' => 'id='.$cur_forum['id'] + ); + + ($hook = get_hook('afo_qr_update_forum_position')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + } + } + } + + // Regenerate the quickjump cache + require_once PUN_ROOT.'include/cache.php'; + generate_quickjump_cache(); + + pun_redirect(pun_link($pun_url['admin_forums']), $lang_admin['Forums updated'].' '.$lang_admin['Redirect']); +} + + +else if (isset($_GET['edit_forum'])) +{ + $forum_id = intval($_GET['edit_forum']); + if ($forum_id < 1) + message($lang_common['Bad request']); + + // Update group permissions for $forum_id + if (isset($_POST['save'])) + { + ($hook = get_hook('afo_save_forum_form_submitted')) ? eval($hook) : null; + + // Start with the forum details + $forum_name = trim($_POST['forum_name']); + $forum_desc = pun_linebreaks(trim($_POST['forum_desc'])); + $cat_id = intval($_POST['cat_id']); + $sort_by = intval($_POST['sort_by']); + $redirect_url = isset($_POST['redirect_url']) ? trim($_POST['redirect_url']) : null; + + if ($forum_name == '') + message($lang_admin['Must enter forum message']); + + if ($cat_id < 1) + message($lang_common['Bad request']); + + $forum_desc = ($forum_desc != '') ? '\''.$pun_db->escape($forum_desc).'\'' : 'NULL'; + $redirect_url = ($redirect_url != '') ? '\''.$pun_db->escape($redirect_url).'\'' : 'NULL'; + + $query = array( + 'UPDATE' => 'forums', + 'SET' => 'forum_name=\''.$pun_db->escape($forum_name).'\', forum_desc='.$forum_desc.', redirect_url='.$redirect_url.', sort_by='.$sort_by.', cat_id='.$cat_id, + 'WHERE' => 'id='.$forum_id + ); + + ($hook = get_hook('afo_qr_update_forum')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + + // Now let's deal with the permissions + if (isset($_POST['read_forum_old'])) + { + $query = array( + 'SELECT' => 'g.g_id, g.g_read_board, g.g_post_replies, g.g_post_topics', + 'FROM' => 'groups AS g', + 'WHERE' => 'g_id!='.PUN_ADMIN + ); + + ($hook = get_hook('afo_qr_get_groups')) ? eval($hook) : null; + $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); + while ($cur_group = $pun_db->fetch_assoc($result)) + { + $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']]); + $post_replies_new = isset($_POST['post_replies_new'][$cur_group['g_id']]) ? '1' : '0'; + $post_topics_new = isset($_POST['post_topics_new'][$cur_group['g_id']]) ? '1' : '0'; + + // Check if the new settings differ from the old + 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']]) + { + // If the new settings are identical to the default settings for this group, delete its row in forum_perms + if ($read_forum_new == '1' && $post_replies_new == $cur_group['g_post_replies'] && $post_topics_new == $cur_group['g_post_topics']) + { + $query = array( + 'DELETE' => 'forum_perms', + 'WHERE' => 'group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id + ); + + ($hook = get_hook('afo_qr_delete_group_forum_perms')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + } + else + { + // Run an UPDATE and see if it affected a row, if not, INSERT + $query = array( + 'UPDATE' => 'forum_perms', + 'SET' => 'read_forum='.$read_forum_new.', post_replies='.$post_replies_new.', post_topics='.$post_topics_new, + 'WHERE' => 'group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id + ); + + ($hook = get_hook('afo_qr_update_forum_perms')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + if (!$pun_db->affected_rows()) + { + $query = array( + 'INSERT' => 'group_id, forum_id, read_forum, post_replies, post_topics', + 'INTO' => 'forum_perms', + 'VALUES' => $cur_group['g_id'].', '.$forum_id.', '.$read_forum_new.', '.$post_replies_new.', '.$post_topics_new + ); + + ($hook = get_hook('afo_qr_add_forum_perms')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + } + } + } + } + } + + // Regenerate the quickjump cache + require_once PUN_ROOT.'include/cache.php'; + generate_quickjump_cache(); + + pun_redirect(pun_link($pun_url['admin_forums']), $lang_admin['Forum updated'].' '.$lang_admin['Redirect']); + } + else if (isset($_POST['revert_perms'])) + { + ($hook = get_hook('afo_revert_perms_form_submitted')) ? eval($hook) : null; + + $query = array( + 'DELETE' => 'forum_perms', + 'WHERE' => 'forum_id='.$forum_id + ); + + ($hook = get_hook('afo_qr_delete_forum_perms')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + + // Regenerate the quickjump cache + require_once PUN_ROOT.'include/cache.php'; + generate_quickjump_cache(); + + pun_redirect(pun_link($pun_url['admin_forums']).'&edit_forum='.$forum_id, $lang_admin['Permissions reverted'].' '.$lang_admin['Redirect']); + } + + // Fetch forum info + $query = array( + 'SELECT' => 'f.id, f.forum_name, f.forum_desc, f.redirect_url, f.num_topics, f.sort_by, f.cat_id', + 'FROM' => 'forums AS f', + 'WHERE' => 'id='.$forum_id + ); + + ($hook = get_hook('afo_qr_get_forum_details')) ? eval($hook) : null; + $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); + if (!$pun_db->num_rows($result)) + message($lang_common['Bad request']); + + $cur_forum = $pun_db->fetch_assoc($result); + + $pun_page['form_info'] = array(); + if ($cur_forum['redirect_url']) + $pun_page['form_info'][] = '
  • '.$lang_admin['Forum perms info 2'].'
  • '; + + $pun_page['form_info'][] = '
  • '.$lang_admin['Forum perms info 1'].'
  • '; + $pun_page['form_info'][] = '
  • '.$lang_admin['Forum perms info 3'].'
  • '; + $pun_page['form_info'][] = '
  • '. sprintf($lang_admin['Group key'], ''.$lang_admin['User groups'].'').'
  • '; + + // Setup the form + $pun_page['part_count'] = $pun_page['set_count'] = $pun_page['fld_count'] = 0; + + // Setup breadcrumbs + $pun_page['crumbs'] = array( + array($pun_config['o_board_title'], pun_link($pun_url['index'])), + array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])), + array($lang_admin['Forums'], pun_link($pun_url['admin_forums'])), + $lang_admin['Edit forum'] + ); + + ($hook = get_hook('afo_edit_forum_pre_header_load')) ? eval($hook) : null; + + define('PUN_PAGE_SECTION', 'start'); + define('PUN_PAGE', 'admin-forums'); + require PUN_ROOT.'header.php'; + +?> +
    + + + +
    +

    { }

    +
    + +
    + +
    + +
    +

    +
    +
    + +
    +

    +
    + +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    + +
    +
    + +
    +

    +
    +
      + +
    +
    +
    + + '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', + 'FROM' => 'groups AS g', + 'JOINS' => array( + array( + 'LEFT JOIN' => 'forum_perms AS fp', + 'ON' => 'g.g_id=fp.group_id AND fp.forum_id='.$forum_id + ) + ), + 'WHERE' => 'g.g_id!='.PUN_ADMIN, + 'ORDER BY' => 'g.g_id' + ); + + ($hook = get_hook('afo_qr_get_forum_perms')) ? eval($hook) : null; + $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); + while ($cur_perm = $pun_db->fetch_assoc($result)) + { + $read_forum = ($cur_perm['read_forum'] != '0') ? true : false; + $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; + $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; + + // Determine if the current sittings differ from the default or not + $read_forum_def = ($cur_perm['read_forum'] == '0') ? false : true; + $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; + $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; + +?> +
    + +
    + + + + + + + +
    +
    + + + +
    +
    +
    + + +
    +
    +
    +
    + +
    + + +
    + + + +
    +

    { }

    +
    + +
    +
    +

    +
    +
    + +
    + +
    + +
    +
    + +
    +
    + +
    + +
    +
    + +
    +
    +
    + + 'c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.disp_position', + 'FROM' => 'categories AS c', + 'JOINS' => array( + array( + 'INNER JOIN' => 'forums AS f', + 'ON' => 'c.id=f.cat_id' + ) + ), + 'ORDER BY' => 'c.disp_position, c.id, f.disp_position' +); + +($hook = get_hook('afo_qr_get_cats_and_forums')) ? eval($hook) : null; +$result = $pun_db->query_build($query) or error(__FILE__, __LINE__); + +if ($pun_db->num_rows($result)) +{ + // Reset fieldset counter + $pun_page['set_count'] = 0; + +?> +
    +
    +

    +
    +
    + + +fetch_assoc($result)) + { + if ($cur_forum['cid'] != $cur_category) // A new category since last iteration? + { + if ($i > 2) echo "\t\t\t".''."\n"; + +?> +
    + + + + + +
    +
    + +
    + + +
    + +
    +