function deleteCategories($categories, $moveBoardsTo = null) { global $sourcedir, $smcFunc, $cat_tree; require_once $sourcedir . '/Subs-Boards.php'; getBoardTree(); // With no category set to move the boards to, delete them all. if ($moveBoardsTo === null) { $request = $smcFunc['db_query']('', ' SELECT id_board FROM {db_prefix}boards WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories)); $boards_inside = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $boards_inside[] = $row['id_board']; } $smcFunc['db_free_result']($request); if (!empty($boards_inside)) { deleteBoards($boards_inside, null); } } elseif (in_array($moveBoardsTo, $categories)) { trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR); } else { $smcFunc['db_query']('', ' UPDATE {db_prefix}boards SET id_cat = {int:new_parent_cat} WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories, 'new_parent_cat' => $moveBoardsTo)); } // Noone will ever be able to collapse these categories anymore. $smcFunc['db_query']('', ' DELETE FROM {db_prefix}collapsed_categories WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories)); // Do the deletion of the category itself $smcFunc['db_query']('', ' DELETE FROM {db_prefix}categories WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories)); // Log what we've done. foreach ($categories as $category) { logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin'); } // Get all boards back into the right order. reorderBoards(); }
function EditBoard2() { global $txt, $db_prefix, $sourcedir, $modSettings; checkSession(); require_once $sourcedir . '/Subs-Boards.php'; $_POST['boardid'] = (int) $_POST['boardid']; // Mode: modify aka. don't delete. if (isset($_POST['edit']) || isset($_POST['add'])) { $boardOptions = array(); // Move this board to a new category? if (!empty($_POST['new_cat'])) { $boardOptions['move_to'] = 'bottom'; $boardOptions['target_category'] = (int) $_POST['new_cat']; } elseif (!empty($_POST['placement']) && !empty($_POST['board_order'])) { if (!in_array($_POST['placement'], array('before', 'after', 'child'))) { fatal_lang_error('mangled_post', false); } $boardOptions['move_to'] = $_POST['placement']; $boardOptions['target_board'] = (int) $_POST['board_order']; } // Checkboxes.... $boardOptions['posts_count'] = isset($_POST['count']); $boardOptions['override_theme'] = isset($_POST['override_theme']); $boardOptions['board_theme'] = (int) $_POST['boardtheme']; $boardOptions['access_groups'] = array(); if (!empty($_POST['groups'])) { foreach ($_POST['groups'] as $group) { $boardOptions['access_groups'][] = (int) $group; } } // Change '1 & 2' to '1 & 2', but not '&' to '&'... $boardOptions['board_name'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&$1', $_POST['board_name']); $boardOptions['board_description'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&$1', $_POST['desc']); // With permission_enable_by_board disabled you can set some predefined permissions. if (empty($modSettings['permission_enable_by_board'])) { $boardOptions['permission_mode'] = (int) $_POST['permission_mode']; $boardOptions['inherit_permissions'] = false; } $boardOptions['moderator_string'] = $_POST['moderators']; // Create a new board... if (isset($_POST['add'])) { // New boards by default go to the bottom of the category. if (empty($_POST['new_cat'])) { $boardOptions['target_category'] = (int) $_POST['cur_cat']; } if (!isset($boardOptions['move_to'])) { $boardOptions['move_to'] = 'bottom'; } createBoard($boardOptions); } else { modifyBoard($_POST['boardid'], $boardOptions); } } elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) { EditBoard(); return; } elseif (isset($_POST['delete'])) { // First off - check if we are moving all the current child boards first - before we start deleting! if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) { if (empty($_POST['board_to'])) { fatal_error($txt['mboards_delete_board_error']); } deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']); } else { deleteBoards(array($_POST['boardid']), 0); } } redirectexit('action=manageboards'); }
/** * Remove one or more categories. * general function to delete one or more categories. * allows to move all boards in the categories to a different category before deleting them. * if moveBoardsTo is set to null, all boards inside the given categories will be deleted. * deletes all information that's associated with the given categories. * updates the statistics to reflect the new situation. * * @param int[] $categories * @param integer|null $moveBoardsTo = null */ function deleteCategories($categories, $moveBoardsTo = null) { global $cat_tree; $db = database(); require_once SUBSDIR . '/Boards.subs.php'; getBoardTree(); call_integration_hook('integrate_delete_category', array($categories, &$moveBoardsTo)); // With no category set to move the boards to, delete them all. if ($moveBoardsTo === null) { $boards_inside = array_keys(fetchBoardsInfo(array('categories' => $categories))); if (!empty($boards_inside)) { deleteBoards($boards_inside, null); } } elseif (in_array($moveBoardsTo, $categories)) { trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR); } else { $db->query('', ' UPDATE {db_prefix}boards SET id_cat = {int:new_parent_cat} WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories, 'new_parent_cat' => $moveBoardsTo)); } // No one will ever be able to collapse these categories anymore. $db->query('', ' DELETE FROM {db_prefix}collapsed_categories WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories)); // Do the deletion of the category itself $db->query('', ' DELETE FROM {db_prefix}categories WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories)); // Log what we've done. foreach ($categories as $category) { logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin'); } // Get all boards back into the right order. reorderBoards(); }
/** * Make changes to/delete a board. * (function for handling a submitted form saving the board.) * It also handles deletion of a board. * Called by ?action=admin;area=manageboards;sa=board2 * Redirects to ?action=admin;area=manageboards. * It requires manage_boards permission. */ function EditBoard2() { global $txt, $sourcedir, $modSettings, $smcFunc, $context; $_POST['boardid'] = (int) $_POST['boardid']; checkSession(); validateToken('admin-be-' . $_REQUEST['boardid']); require_once $sourcedir . '/Subs-Boards.php'; // Mode: modify aka. don't delete. if (isset($_POST['edit']) || isset($_POST['add'])) { $boardOptions = array(); // Move this board to a new category? if (!empty($_POST['new_cat'])) { $boardOptions['move_to'] = 'bottom'; $boardOptions['target_category'] = (int) $_POST['new_cat']; } elseif (!empty($_POST['placement']) && !empty($_POST['board_order'])) { if (!in_array($_POST['placement'], array('before', 'after', 'child'))) { fatal_lang_error('mangled_post', false); } $boardOptions['move_to'] = $_POST['placement']; $boardOptions['target_board'] = (int) $_POST['board_order']; } // Checkboxes.... $boardOptions['posts_count'] = isset($_POST['count']); $boardOptions['override_theme'] = isset($_POST['override_theme']); $boardOptions['board_theme'] = (int) $_POST['boardtheme']; $boardOptions['access_groups'] = array(); $boardOptions['deny_groups'] = array(); if (!empty($_POST['groups'])) { foreach ($_POST['groups'] as $group => $action) { if ($action == 'allow') { $boardOptions['access_groups'][] = (int) $group; } elseif ($action == 'deny') { $boardOptions['deny_groups'][] = (int) $group; } } } if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) { fatal_lang_error('too_many_groups', false); } // Change '1 & 2' to '1 & 2', but not '&' to '&'... $boardOptions['board_name'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&$1', $_POST['board_name']); $boardOptions['board_description'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&$1', $_POST['desc']); $boardOptions['moderator_string'] = $_POST['moderators']; if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list'])) { $moderators = array(); foreach ($_POST['moderator_list'] as $moderator) { $moderators[(int) $moderator] = (int) $moderator; } $boardOptions['moderators'] = $moderators; } // Are they doing redirection? $boardOptions['redirect'] = !empty($_POST['redirect_enable']) && isset($_POST['redirect_address']) && trim($_POST['redirect_address']) != '' ? trim($_POST['redirect_address']) : ''; // Profiles... $boardOptions['profile'] = $_POST['profile']; $boardOptions['inherit_permissions'] = $_POST['profile'] == -1; // We need to know what used to be case in terms of redirection. if (!empty($_POST['boardid'])) { $request = $smcFunc['db_query']('', ' SELECT redirect, num_posts FROM {db_prefix}boards WHERE id_board = {int:current_board}', array('current_board' => $_POST['boardid'])); list($oldRedirect, $numPosts) = $smcFunc['db_fetch_row']($request); $smcFunc['db_free_result']($request); // If we're turning redirection on check the board doesn't have posts in it - if it does don't make it a redirection board. if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) { unset($boardOptions['redirect']); } elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) { $boardOptions['num_posts'] = 0; } elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) { $boardOptions['num_posts'] = 0; } } // Create a new board... if (isset($_POST['add'])) { // New boards by default go to the bottom of the category. if (empty($_POST['new_cat'])) { $boardOptions['target_category'] = (int) $_POST['cur_cat']; } if (!isset($boardOptions['move_to'])) { $boardOptions['move_to'] = 'bottom'; } createBoard($boardOptions); } else { modifyBoard($_POST['boardid'], $boardOptions); } } elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) { EditBoard(); return; } elseif (isset($_POST['delete'])) { // First off - check if we are moving all the current child boards first - before we start deleting! if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) { if (empty($_POST['board_to'])) { fatal_lang_error('mboards_delete_board_error'); } deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']); } else { deleteBoards(array($_POST['boardid']), 0); } } if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') { redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']); } else { redirectexit('action=admin;area=manageboards'); } }
function deleteCategories($categories, $moveBoardsTo = null) { global $db_prefix; // With no category set to move the boards to, delete them all. if ($moveBoardsTo === null) { $request = db_query("\n\t\t\tSELECT ID_BOARD\n\t\t\tFROM {$db_prefix}boards\n\t\t\tWHERE ID_CAT IN (" . implode(', ', $categories) . ')', __FILE__, __LINE__); $boards_inside = array(); while ($row = mysql_fetch_assoc($request)) { $boards_inside[] = $row['ID_BOARD']; } mysql_free_result($request); if (!empty($boards_inside)) { deleteBoards($boards_inside, null); } } elseif (in_array($moveBoardsTo, $categories)) { trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR); } else { db_query("\n\t\t\tUPDATE {$db_prefix}boards\n\t\t\tSET ID_CAT = {$moveBoardsTo}\n\t\t\tWHERE ID_CAT IN (" . implode(', ', $categories) . ')', __FILE__, __LINE__); } // Noone will ever be able to collapse these categories anymore. db_query("\n\t\tDELETE FROM {$db_prefix}collapsed_categories\n\t\tWHERE ID_CAT IN (" . implode(', ', $categories) . ")", __FILE__, __LINE__); // Do the deletion of the category itself db_query("\n\t\tDELETE FROM {$db_prefix}categories\n\t\tWHERE ID_CAT IN (" . implode(', ', $categories) . ")\n\t\tLIMIT 1", __FILE__, __LINE__); // Get all boards back into the right order. reorderBoards(); }