69 |
72 |
70 // Prune all posts and topics |
73 // Prune all posts and topics |
71 prune($forum_id, 1, -1); |
74 prune($forum_id, 1, -1); |
72 |
75 |
73 // Locate any "orphaned redirect topics" and delete them |
76 // Locate any "orphaned redirect topics" and delete them |
74 $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()); |
77 $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()); |
75 $num_orphans = $db->num_rows($result); |
78 $num_orphans = $pun_db->num_rows($result); |
76 |
79 |
77 if ($num_orphans) |
80 if ($num_orphans) |
78 { |
81 { |
79 for ($i = 0; $i < $num_orphans; ++$i) |
82 for ($i = 0; $i < $num_orphans; ++$i) |
80 $orphans[] = $db->result($result, $i); |
83 $orphans[] = $pun_db->result($result, $i); |
81 |
84 |
82 $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error()); |
85 $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()); |
83 } |
86 } |
84 |
87 |
85 // Delete the forum and any forum specific group permissions |
88 // Delete the forum and any forum specific group permissions |
86 $db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to delete forum', __FILE__, __LINE__, $db->error()); |
89 $pun_db->query('DELETE FROM '.$pun_db->prefix.'forums WHERE id='.$forum_id) or error('Unable to delete forum', __FILE__, __LINE__, $pun_db->error()); |
87 $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error()); |
90 $pun_db->query('DELETE FROM '.$pun_db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $pun_db->error()); |
88 |
91 |
89 // Regenerate the quickjump cache |
92 // Regenerate the quickjump cache |
90 require_once PUN_ROOT.'include/cache.php'; |
93 require_once PUN_ROOT.'include/cache.php'; |
91 generate_quickjump_cache(); |
94 generate_quickjump_cache(); |
92 |
95 |
93 redirect('admin_forums.php', 'Forum deleted. Redirecting …'); |
96 pun_redirect('admin_forums.php', 'Forum deleted. Redirecting …'); |
94 } |
97 } |
95 else // If the user hasn't confirmed the delete |
98 else // If the user hasn't confirmed the delete |
96 { |
99 { |
97 $result = $db->query('SELECT forum_name FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error()); |
100 $result = $pun_db->query('SELECT forum_name FROM '.$pun_db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $pun_db->error()); |
98 $forum_name = pun_htmlspecialchars($db->result($result)); |
101 $forum_name = pun_htmlspecialchars($pun_db->result($result)); |
99 |
102 |
100 |
103 |
101 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Forums'; |
104 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Forums'; |
102 require PUN_ROOT.'header.php'; |
105 require PUN_ROOT.'header.php'; |
103 |
106 |
173 message('You must enter a forum name.'); |
176 message('You must enter a forum name.'); |
174 |
177 |
175 if ($cat_id < 1) |
178 if ($cat_id < 1) |
176 message($lang_common['Bad request']); |
179 message($lang_common['Bad request']); |
177 |
180 |
178 $forum_desc = ($forum_desc != '') ? '\''.$db->escape($forum_desc).'\'' : 'NULL'; |
181 $forum_desc = ($forum_desc != '') ? '\''.$pun_db->escape($forum_desc).'\'' : 'NULL'; |
179 $redirect_url = ($redirect_url != '') ? '\''.$db->escape($redirect_url).'\'' : 'NULL'; |
182 $redirect_url = ($redirect_url != '') ? '\''.$pun_db->escape($redirect_url).'\'' : 'NULL'; |
180 |
183 |
181 $db->query('UPDATE '.$db->prefix.'forums SET forum_name=\''.$db->escape($forum_name).'\', forum_desc='.$forum_desc.', redirect_url='.$redirect_url.', sort_by='.$sort_by.', cat_id='.$cat_id.' WHERE id='.$forum_id) or error('Unable to update forum', __FILE__, __LINE__, $db->error()); |
184 $pun_db->query('UPDATE '.$pun_db->prefix.'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) or error('Unable to update forum', __FILE__, __LINE__, $pun_db->error()); |
182 |
185 |
183 // Now let's deal with the permissions |
186 // Now let's deal with the permissions |
184 if (isset($_POST['read_forum_old'])) |
187 if (isset($_POST['read_forum_old'])) |
185 { |
188 { |
186 $result = $db->query('SELECT g_id, g_read_board, g_post_replies, g_post_topics FROM '.$db->prefix.'groups WHERE g_id!='.PUN_ADMIN) or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error()); |
189 $result = $pun_db->query('SELECT g_id, g_read_board, g_post_replies, g_post_topics FROM '.$pun_db->prefix.'groups WHERE g_id!='.PUN_ADMIN) or error('Unable to fetch user group list', __FILE__, __LINE__, $pun_db->error()); |
187 while ($cur_group = $db->fetch_assoc($result)) |
190 while ($cur_group = $pun_db->fetch_assoc($result)) |
188 { |
191 { |
189 $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']]); |
192 $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']]); |
190 $post_replies_new = isset($_POST['post_replies_new'][$cur_group['g_id']]) ? '1' : '0'; |
193 $post_replies_new = isset($_POST['post_replies_new'][$cur_group['g_id']]) ? '1' : '0'; |
191 $post_topics_new = isset($_POST['post_topics_new'][$cur_group['g_id']]) ? '1' : '0'; |
194 $post_topics_new = isset($_POST['post_topics_new'][$cur_group['g_id']]) ? '1' : '0'; |
192 |
195 |
193 // Check if the new settings differ from the old |
196 // Check if the new settings differ from the old |
194 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']]) |
197 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']]) |
195 { |
198 { |
196 // If the new settings are identical to the default settings for this group, delete it's row in forum_perms |
199 // If the new settings are identical to the default settings for this group, delete it's row in forum_perms |
197 if ($read_forum_new == '1' && $post_replies_new == $cur_group['g_post_replies'] && $post_topics_new == $cur_group['g_post_topics']) |
200 if ($read_forum_new == '1' && $post_replies_new == $cur_group['g_post_replies'] && $post_topics_new == $cur_group['g_post_topics']) |
198 $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error()); |
201 $pun_db->query('DELETE FROM '.$pun_db->prefix.'forum_perms WHERE group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $pun_db->error()); |
199 else |
202 else |
200 { |
203 { |
201 // Run an UPDATE and see if it affected a row, if not, INSERT |
204 // Run an UPDATE and see if it affected a row, if not, INSERT |
202 $db->query('UPDATE '.$db->prefix.'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) or error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error()); |
205 $pun_db->query('UPDATE '.$pun_db->prefix.'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) or error('Unable to insert group forum permissions', __FILE__, __LINE__, $pun_db->error()); |
203 if (!$db->affected_rows()) |
206 if (!$pun_db->affected_rows()) |
204 $db->query('INSERT INTO '.$db->prefix.'forum_perms (group_id, forum_id, read_forum, post_replies, post_topics) VALUES('.$cur_group['g_id'].', '.$forum_id.', '.$read_forum_new.', '.$post_replies_new.', '.$post_topics_new.')') or error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error()); |
207 $pun_db->query('INSERT INTO '.$pun_db->prefix.'forum_perms (group_id, forum_id, read_forum, post_replies, post_topics) VALUES('.$cur_group['g_id'].', '.$forum_id.', '.$read_forum_new.', '.$post_replies_new.', '.$post_topics_new.')') or error('Unable to insert group forum permissions', __FILE__, __LINE__, $pun_db->error()); |
205 } |
208 } |
206 } |
209 } |
207 } |
210 } |
208 } |
211 } |
209 |
212 |
210 // Regenerate the quickjump cache |
213 // Regenerate the quickjump cache |
211 require_once PUN_ROOT.'include/cache.php'; |
214 require_once PUN_ROOT.'include/cache.php'; |
212 generate_quickjump_cache(); |
215 generate_quickjump_cache(); |
213 |
216 |
214 redirect('admin_forums.php', 'Forum updated. Redirecting …'); |
217 pun_redirect('admin_forums.php', 'Forum updated. Redirecting …'); |
215 } |
218 } |
216 else if (isset($_POST['revert_perms'])) |
219 else if (isset($_POST['revert_perms'])) |
217 { |
220 { |
218 confirm_referrer('admin_forums.php'); |
221 confirm_referrer('admin_forums.php'); |
219 |
222 |
220 $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error()); |
223 $pun_db->query('DELETE FROM '.$pun_db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $pun_db->error()); |
221 |
224 |
222 // Regenerate the quickjump cache |
225 // Regenerate the quickjump cache |
223 require_once PUN_ROOT.'include/cache.php'; |
226 require_once PUN_ROOT.'include/cache.php'; |
224 generate_quickjump_cache(); |
227 generate_quickjump_cache(); |
225 |
228 |
226 redirect('admin_forums.php?edit_forum='.$forum_id, 'Permissions reverted to defaults. Redirecting …'); |
229 pun_redirect('admin_forums.php?edit_forum='.$forum_id, 'Permissions reverted to defaults. Redirecting …'); |
227 } |
230 } |
228 |
231 |
229 |
232 |
230 // Fetch forum info |
233 // Fetch forum info |
231 $result = $db->query('SELECT id, forum_name, forum_desc, redirect_url, num_topics, sort_by, cat_id FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error()); |
234 $result = $pun_db->query('SELECT id, forum_name, forum_desc, redirect_url, num_topics, sort_by, cat_id FROM '.$pun_db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $pun_db->error()); |
232 if (!$db->num_rows($result)) |
235 if (!$pun_db->num_rows($result)) |
233 message($lang_common['Bad request']); |
236 message($lang_common['Bad request']); |
234 |
237 |
235 $cur_forum = $db->fetch_assoc($result); |
238 $cur_forum = $pun_db->fetch_assoc($result); |
236 |
239 |
237 |
240 |
238 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Forums'; |
241 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Forums'; |
239 require PUN_ROOT.'header.php'; |
242 require PUN_ROOT.'header.php'; |
240 |
243 |