PUN_ADMIN) message($lang_common['No permission']); // Add a new category if (isset($_POST['add_cat'])) { confirm_referrer('admin_categories.php'); $new_cat_name = trim($_POST['new_cat_name']); if ($new_cat_name == '') message('Vous devez saisir un nom pour la nouvelle catégorie.'); $db->query('INSERT INTO '.$db->prefix.'categories (cat_name) VALUES(\''.$db->escape($new_cat_name).'\')') or error('Impossible de créer la catégorie', __FILE__, __LINE__, $db->error()); redirect('admin_categories.php', 'Catégorie ajoutée. Redirection ...'); } // Delete a category else if (isset($_POST['del_cat']) || isset($_POST['del_cat_comply'])) { confirm_referrer('admin_categories.php'); $cat_to_delete = intval($_POST['cat_to_delete']); if ($cat_to_delete < 1) message($lang_common['Bad request']); if (isset($_POST['del_cat_comply'])) // Delete a category with all forums and posts { @set_time_limit(0); $result = $db->query('SELECT id FROM '.$db->prefix.'forums WHERE cat_id='.$cat_to_delete) or error('Impossible de retrouver la liste des forums', __FILE__, __LINE__, $db->error()); $num_forums = $db->num_rows($result); for ($i = 0; $i < $num_forums; ++$i) { $cur_forum = $db->result($result, $i); // Prune all posts and topics prune($cur_forum, 1, -1); // Delete the forum $db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$cur_forum) or error('Impossible de supprimer le forum', __FILE__, __LINE__, $db->error()); } // Locate any "orphaned redirect topics" and delete them $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('Impossible de retrouver les sujets de redirection', __FILE__, __LINE__, $db->error()); $num_orphans = $db->num_rows($result); if ($num_orphans) { for ($i = 0; $i < $num_orphans; ++$i) $orphans[] = $db->result($result, $i); $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Impossible de supprimer les sujets de redirection', __FILE__, __LINE__, $db->error()); } // Delete the category $db->query('DELETE FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Impossible de supprimer la catégorie', __FILE__, __LINE__, $db->error()); // Regenerate the quickjump cache require_once PUN_ROOT.'include/cache.php'; generate_quickjump_cache(); redirect('admin_categories.php', 'Catégorie supprimée. Redirection ...'); } else // If the user hasn't comfirmed the delete { $result = $db->query('SELECT cat_name FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Impossible de retrouver les informations de la catégorie', __FILE__, __LINE__, $db->error()); $cat_name = $db->result($result); $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Catégories'; require PUN_ROOT.'header.php'; generate_admin_menu('categories'); ?>