24 |
24 |
25 |
25 |
26 // Tell header.php to use the admin template |
26 // Tell header.php to use the admin template |
27 define('PUN_ADMIN_CONSOLE', 1); |
27 define('PUN_ADMIN_CONSOLE', 1); |
28 |
28 |
29 define('PUN_ROOT', './'); |
29 //define('PUN_ROOT', './'); |
30 require PUN_ROOT.'include/common.php'; |
30 //require PUN_ROOT.'include/common.php'; |
|
31 |
|
32 global $pun_db, $pun_user, $pun_config, $lang_common; |
|
33 |
31 require PUN_ROOT.'include/common_admin.php'; |
34 require PUN_ROOT.'include/common_admin.php'; |
32 |
35 |
33 |
36 |
34 if ($pun_user['g_id'] > PUN_ADMIN) |
37 if ($pun_user['g_id'] < PUN_ADMIN) |
35 message($lang_common['No permission']); |
38 message($lang_common['No permission']); |
36 |
39 |
37 |
40 |
38 // Add a new category |
41 // Add a new category |
39 if (isset($_POST['add_cat'])) |
42 if (isset($_POST['add_cat'])) |
42 |
45 |
43 $new_cat_name = trim($_POST['new_cat_name']); |
46 $new_cat_name = trim($_POST['new_cat_name']); |
44 if ($new_cat_name == '') |
47 if ($new_cat_name == '') |
45 message('You must enter a name for the category.'); |
48 message('You must enter a name for the category.'); |
46 |
49 |
47 $db->query('INSERT INTO '.$db->prefix.'categories (cat_name) VALUES(\''.$db->escape($new_cat_name).'\')') or error('Unable to create category', __FILE__, __LINE__, $db->error()); |
50 $pun_db->query('INSERT INTO '.$pun_db->prefix.'categories (cat_name) VALUES(\''.$pun_db->escape($new_cat_name).'\')') or error('Unable to create category', __FILE__, __LINE__, $pun_db->error()); |
48 |
51 |
49 redirect('admin_categories.php', 'Category added. Redirecting …'); |
52 pun_redirect('admin_categories.php', 'Category added. Redirecting …'); |
50 } |
53 } |
51 |
54 |
52 |
55 |
53 // Delete a category |
56 // Delete a category |
54 else if (isset($_POST['del_cat']) || isset($_POST['del_cat_comply'])) |
57 else if (isset($_POST['del_cat']) || isset($_POST['del_cat_comply'])) |
61 |
64 |
62 if (isset($_POST['del_cat_comply'])) // Delete a category with all forums and posts |
65 if (isset($_POST['del_cat_comply'])) // Delete a category with all forums and posts |
63 { |
66 { |
64 @set_time_limit(0); |
67 @set_time_limit(0); |
65 |
68 |
66 $result = $db->query('SELECT id FROM '.$db->prefix.'forums WHERE cat_id='.$cat_to_delete) or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error()); |
69 $result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'forums WHERE cat_id='.$cat_to_delete) or error('Unable to fetch forum list', __FILE__, __LINE__, $pun_db->error()); |
67 $num_forums = $db->num_rows($result); |
70 $num_forums = $pun_db->num_rows($result); |
68 |
71 |
69 for ($i = 0; $i < $num_forums; ++$i) |
72 for ($i = 0; $i < $num_forums; ++$i) |
70 { |
73 { |
71 $cur_forum = $db->result($result, $i); |
74 $cur_forum = $pun_db->result($result, $i); |
72 |
75 |
73 // Prune all posts and topics |
76 // Prune all posts and topics |
74 prune($cur_forum, 1, -1); |
77 prune($cur_forum, 1, -1); |
75 |
78 |
76 // Delete the forum |
79 // Delete the forum |
77 $db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$cur_forum) or error('Unable to delete forum', __FILE__, __LINE__, $db->error()); |
80 $pun_db->query('DELETE FROM '.$pun_db->prefix.'forums WHERE id='.$cur_forum) or error('Unable to delete forum', __FILE__, __LINE__, $pun_db->error()); |
78 } |
81 } |
79 |
82 |
80 // Locate any "orphaned redirect topics" and delete them |
83 // Locate any "orphaned redirect topics" and delete them |
81 $result = $db->query('SELECT t1.id FROM '.$db->prefix.'topics AS t1 LEFT JOIN '.$db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error()); |
84 $result = $pun_db->query('SELECT t1.id FROM '.$pun_db->prefix.'topics AS t1 LEFT JOIN '.$pun_db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $pun_db->error()); |
82 $num_orphans = $db->num_rows($result); |
85 $num_orphans = $pun_db->num_rows($result); |
83 |
86 |
84 if ($num_orphans) |
87 if ($num_orphans) |
85 { |
88 { |
86 for ($i = 0; $i < $num_orphans; ++$i) |
89 for ($i = 0; $i < $num_orphans; ++$i) |
87 $orphans[] = $db->result($result, $i); |
90 $orphans[] = $pun_db->result($result, $i); |
88 |
91 |
89 $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error()); |
92 $pun_db->query('DELETE FROM '.$pun_db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $pun_db->error()); |
90 } |
93 } |
91 |
94 |
92 // Delete the category |
95 // Delete the category |
93 $db->query('DELETE FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to delete category', __FILE__, __LINE__, $db->error()); |
96 $pun_db->query('DELETE FROM '.$pun_db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to delete category', __FILE__, __LINE__, $pun_db->error()); |
94 |
97 |
95 // Regenerate the quickjump cache |
98 // Regenerate the quickjump cache |
96 require_once PUN_ROOT.'include/cache.php'; |
99 require_once PUN_ROOT.'include/cache.php'; |
97 generate_quickjump_cache(); |
100 generate_quickjump_cache(); |
98 |
101 |
99 redirect('admin_categories.php', 'Category deleted. Redirecting …'); |
102 pun_redirect('admin_categories.php', 'Category deleted. Redirecting …'); |
100 } |
103 } |
101 else // If the user hasn't comfirmed the delete |
104 else // If the user hasn't comfirmed the delete |
102 { |
105 { |
103 $result = $db->query('SELECT cat_name FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to fetch category info', __FILE__, __LINE__, $db->error()); |
106 $result = $pun_db->query('SELECT cat_name FROM '.$pun_db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to fetch category info', __FILE__, __LINE__, $pun_db->error()); |
104 $cat_name = $db->result($result); |
107 $cat_name = $pun_db->result($result); |
105 |
108 |
106 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Categories'; |
109 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Categories'; |
107 require PUN_ROOT.'header.php'; |
110 require PUN_ROOT.'header.php'; |
108 |
111 |
109 generate_admin_menu('categories'); |
112 generate_admin_menu('categories'); |
141 confirm_referrer('admin_categories.php'); |
144 confirm_referrer('admin_categories.php'); |
142 |
145 |
143 $cat_order = $_POST['cat_order']; |
146 $cat_order = $_POST['cat_order']; |
144 $cat_name = $_POST['cat_name']; |
147 $cat_name = $_POST['cat_name']; |
145 |
148 |
146 $result = $db->query('SELECT id, disp_position FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error()); |
149 $result = $pun_db->query('SELECT id, disp_position FROM '.$pun_db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $pun_db->error()); |
147 $num_cats = $db->num_rows($result); |
150 $num_cats = $pun_db->num_rows($result); |
148 |
151 |
149 for ($i = 0; $i < $num_cats; ++$i) |
152 for ($i = 0; $i < $num_cats; ++$i) |
150 { |
153 { |
151 if ($cat_name[$i] == '') |
154 if ($cat_name[$i] == '') |
152 message('You must enter a category name.'); |
155 message('You must enter a category name.'); |
153 |
156 |
154 if (!@preg_match('#^\d+$#', $cat_order[$i])) |
157 if (!@preg_match('#^\d+$#', $cat_order[$i])) |
155 message('Position must be an integer value.'); |
158 message('Position must be an integer value.'); |
156 |
159 |
157 list($cat_id, $position) = $db->fetch_row($result); |
160 list($cat_id, $position) = $pun_db->fetch_row($result); |
158 |
161 |
159 $db->query('UPDATE '.$db->prefix.'categories SET cat_name=\''.$db->escape($cat_name[$i]).'\', disp_position='.$cat_order[$i].' WHERE id='.$cat_id) or error('Unable to update category', __FILE__, __LINE__, $db->error()); |
162 $pun_db->query('UPDATE '.$pun_db->prefix.'categories SET cat_name=\''.$pun_db->escape($cat_name[$i]).'\', disp_position='.$cat_order[$i].' WHERE id='.$cat_id) or error('Unable to update category', __FILE__, __LINE__, $pun_db->error()); |
160 } |
163 } |
161 |
164 |
162 // Regenerate the quickjump cache |
165 // Regenerate the quickjump cache |
163 require_once PUN_ROOT.'include/cache.php'; |
166 require_once PUN_ROOT.'include/cache.php'; |
164 generate_quickjump_cache(); |
167 generate_quickjump_cache(); |
165 |
168 |
166 redirect('admin_categories.php', 'Categories updated. Redirecting …'); |
169 pun_redirect('admin_categories.php', 'Categories updated. Redirecting …'); |
167 } |
170 } |
168 |
171 |
169 |
172 |
170 // Generate an array with all categories |
173 // Generate an array with all categories |
171 $result = $db->query('SELECT id, cat_name, disp_position FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error()); |
174 $result = $pun_db->query('SELECT id, cat_name, disp_position FROM '.$pun_db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $pun_db->error()); |
172 $num_cats = $db->num_rows($result); |
175 $num_cats = $pun_db->num_rows($result); |
173 |
176 |
174 for ($i = 0; $i < $num_cats; ++$i) |
177 for ($i = 0; $i < $num_cats; ++$i) |
175 $cat_list[] = $db->fetch_row($result); |
178 $cat_list[] = $pun_db->fetch_row($result); |
176 |
179 |
177 |
180 |
178 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Categories'; |
181 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Categories'; |
179 require PUN_ROOT.'header.php'; |
182 require PUN_ROOT.'header.php'; |
180 |
183 |