diff -r e3d7322305bf -r 5e1f1e916419 punbb/admin/categories.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/punbb/admin/categories.php Sat Apr 05 23:56:45 2008 -0400 @@ -0,0 +1,414 @@ + $_ ) +{ + $$key =& $GLOBALS[$key]; +} + +($hook = get_hook('acg_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 new category +if (isset($_POST['add_cat'])) +{ + $new_cat_name = trim($_POST['new_cat_name']); + if ($new_cat_name == '') + message($lang_admin['Must name category']); + + ($hook = get_hook('acg_add_cat_form_submitted')) ? eval($hook) : null; + + $query = array( + 'INSERT' => 'cat_name', + 'INTO' => 'categories', + 'VALUES' => '\''.$pun_db->escape($new_cat_name).'\'' + ); + + ($hook = get_hook('acg_qr_add_category')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + + pun_redirect(pun_link($pun_url['admin_categories']), $lang_admin['Category added'].' '.$lang_admin['Redirect']); +} + + +// Delete a category +else if (isset($_POST['del_cat']) || isset($_POST['del_cat_comply'])) +{ + $cat_to_delete = intval($_POST['cat_to_delete']); + if ($cat_to_delete < 1) + message($lang_common['Bad request']); + + // User pressed the cancel button + if (isset($_POST['del_cat_cancel'])) + pun_redirect(pun_link($pun_url['admin_categories']), $lang_admin['Cancel redirect']); + + ($hook = get_hook('acg_del_cat_form_submitted')) ? eval($hook) : null; + + if (isset($_POST['del_cat_comply'])) // Delete a category with all forums and posts + { + @set_time_limit(0); + + $query = array( + 'SELECT' => 'f.id', + 'FROM' => 'forums AS f', + 'WHERE' => 'cat_id='.$cat_to_delete + ); + + ($hook = get_hook('acg_qr_get_forums_to_delete')) ? eval($hook) : null; + $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); + $num_forums = $pun_db->num_rows($result); + + for ($i = 0; $i < $num_forums; ++$i) + { + $cur_forum = $pun_db->result($result, $i); + + // Prune all posts and topics + prune($cur_forum, 1, -1); + + // Delete the forum + $query = array( + 'DELETE' => 'forums', + 'WHERE' => 'id='.$cur_forum + ); + + ($hook = get_hook('acg_qr_delete_forum')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + } + + delete_orphans(); + + // Delete the category + $query = array( + 'DELETE' => 'categories', + 'WHERE' => 'id='.$cat_to_delete + ); + + ($hook = get_hook('acg_qr_delete_category')) ? 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_categories']), $lang_admin['Category deleted'].' '.$lang_admin['Redirect']); + } + else // If the user hasn't comfirmed the delete + { + $query = array( + 'SELECT' => 'c.cat_name', + 'FROM' => 'categories AS c', + 'WHERE' => 'c.id='.$cat_to_delete + ); + + ($hook = get_hook('acg_qr_get_category_name')) ? eval($hook) : null; + $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); + $cat_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['Categories'], pun_link($pun_url['admin_categories'])), + $lang_admin['Delete category'] + ); + + ($hook = get_hook('acg_del_cat_pre_header_load')) ? eval($hook) : null; + + define('PUN_PAGE_SECTION', 'start'); + define('PUN_PAGE', 'admin-categories'); + require PUN_ROOT.'header.php'; + +?> +
+ + + + +
+

{ }

+
+ +
+
+

+
+
+

+
+
+ +
+ + +
+
+
+ +
+ 'c.id, c.cat_name, c.disp_position', + 'FROM' => 'categories AS c', + 'ORDER BY' => 'c.id' + ); + + ($hook = get_hook('acg_qr_get_categories')) ? eval($hook) : null; + $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); + while ($cur_cat = $pun_db->fetch_assoc($result)) + { + // If these aren't set, we're looking at a category that was added after + // the admin started editing: we don't want to mess with it + if (isset($cat_name[$cur_cat['id']]) && isset($cat_order[$cur_cat['id']])) + { + if ($cat_name[$cur_cat['id']] == '') + message($lang_admin['Must enter category']); + + if ($cat_order[$cur_cat['id']] < 0) + message($lang_admin['Must be integer']); + + // We only want to update if we changed anything + if ($cur_cat['cat_name'] != $cat_name[$cur_cat['id']] || $cur_cat['disp_position'] != $cat_order[$cur_cat['id']]) + { + $query = array( + 'UPDATE' => 'categories', + 'SET' => 'cat_name=\''.$pun_db->escape($cat_name[$cur_cat['id']]).'\', disp_position='.$cat_order[$cur_cat['id']], + 'WHERE' => 'id='.$cur_cat['id'] + ); + + ($hook = get_hook('acg_qr_update_category')) ? 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_categories']), $lang_admin['Categories updated'].' '.$lang_admin['Redirect']); +} + + +// Generate an array with all categories +$query = array( + 'SELECT' => 'c.id, c.cat_name, c.disp_position', + 'FROM' => 'categories AS c', + 'ORDER BY' => 'c.disp_position' +); + +($hook = get_hook('acg_qr_get_categories2')) ? eval($hook) : null; +$result = $pun_db->query_build($query) or error(__FILE__, __LINE__); +$num_cats = $pun_db->num_rows($result); + +for ($i = 0; $i < $num_cats; ++$i) + $cat_list[] = $pun_db->fetch_row($result); + +// Setup the form +$pun_page['fld_count'] = $pun_page['set_count'] = $pun_page['part_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'])), + $lang_admin['Categories'] +); + +($hook = get_hook('acg_cat_header_load')) ? eval($hook) : null; + +define('PUN_PAGE_SECTION', 'start'); +define('PUN_PAGE', 'admin-categories'); +require PUN_ROOT.'header.php'; + +?> +
+ + + + +
+

{ }

+
+ +
+
+

'.$lang_admin['Add category'].'') ?>

+
+
+

'.strtolower($lang_admin['Forums']).'') ?>

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

'.$lang_admin['Delete category'].'') ?>

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

'.$lang_admin['Edit categories'].'') ?>

+
+
+ + + +
+ : +
+
+ +
+ +
+ +
+ +
+
+
+ + +
+