query('SELECT 1 FROM '.$db->prefix.'ranks WHERE min_posts='.$min_posts) or error('Unable to fetch rank info', __FILE__, __LINE__, $db->error()); if ($db->num_rows($result)) message(sprintf($lang_admin_ranks['Dupe min posts message'], $min_posts)); $db->query('INSERT INTO '.$db->prefix.'ranks (rank, min_posts) VALUES(\''.$db->escape($rank).'\', '.$min_posts.')') or error('Unable to add rank', __FILE__, __LINE__, $db->error()); // Regenerate the ranks cache if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) require PUN_ROOT.'include/cache.php'; generate_ranks_cache(); redirect('admin_ranks.php', $lang_admin_ranks['Rank added redirect']); } // Update a rank else if (isset($_POST['update'])) { confirm_referrer('admin_ranks.php'); $id = intval(key($_POST['update'])); $rank = pun_trim($_POST['rank'][$id]); $min_posts = trim($_POST['min_posts'][$id]); if ($rank == '') message($lang_admin_ranks['Must enter title message']); if ($min_posts == '' || preg_match('%[^0-9]%', $min_posts)) message($lang_admin_ranks['Must be integer message']); // Make sure there isn't already a rank with the same min_posts value $result = $db->query('SELECT 1 FROM '.$db->prefix.'ranks WHERE id!='.$id.' AND min_posts='.$min_posts) or error('Unable to fetch rank info', __FILE__, __LINE__, $db->error()); if ($db->num_rows($result)) message(sprintf($lang_admin_ranks['Dupe min posts message'], $min_posts)); $db->query('UPDATE '.$db->prefix.'ranks SET rank=\''.$db->escape($rank).'\', min_posts='.$min_posts.' WHERE id='.$id) or error('Unable to update rank', __FILE__, __LINE__, $db->error()); // Regenerate the ranks cache if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) require PUN_ROOT.'include/cache.php'; generate_ranks_cache(); redirect('admin_ranks.php', $lang_admin_ranks['Rank updated redirect']); } // Remove a rank else if (isset($_POST['remove'])) { confirm_referrer('admin_ranks.php'); $id = intval(key($_POST['remove'])); $db->query('DELETE FROM '.$db->prefix.'ranks WHERE id='.$id) or error('Unable to delete rank', __FILE__, __LINE__, $db->error()); // Regenerate the ranks cache if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) require PUN_ROOT.'include/cache.php'; generate_ranks_cache(); redirect('admin_ranks.php', $lang_admin_ranks['Rank removed redirect']); } $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Ranks']); $focus_element = array('ranks', 'new_rank'); define('PUN_ACTIVE_PAGE', 'admin'); require PUN_ROOT.'header.php'; generate_admin_menu('ranks'); ?>