punbb/admin_ranks.php
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
child 3 c0c445d4a13e
equal deleted inserted replaced
1:8f6143115bf5 2:a8a21e1c7afa
    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 rank
    41 // Add a rank
    39 if (isset($_POST['add_rank']))
    42 if (isset($_POST['add_rank']))
    48 
    51 
    49 	if (!@preg_match('#^\d+$#', $min_posts))
    52 	if (!@preg_match('#^\d+$#', $min_posts))
    50 		message('Minimum posts must be a positive integer value.');
    53 		message('Minimum posts must be a positive integer value.');
    51 
    54 
    52 	// Make sure there isn't already a rank with the same min_posts value
    55 	// Make sure there isn't already a rank with the same min_posts value
    53 	$result = $db->query('SELECT 1 FROM '.$db->prefix.'ranks WHERE min_posts='.$min_posts) or error('Unable to fetch rank info', __FILE__, __LINE__, $db->error());
    56 	$result = $pun_db->query('SELECT 1 FROM '.$pun_db->prefix.'ranks WHERE min_posts='.$min_posts) or error('Unable to fetch rank info', __FILE__, __LINE__, $pun_db->error());
    54 	if ($db->num_rows($result))
    57 	if ($pun_db->num_rows($result))
    55 		message('There is already a rank with a minimun posts value of '.$min_posts.'.');
    58 		message('There is already a rank with a minimun posts value of '.$min_posts.'.');
    56 
    59 
    57 	$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());
    60 	$pun_db->query('INSERT INTO '.$pun_db->prefix.'ranks (rank, min_posts) VALUES(\''.$pun_db->escape($rank).'\', '.$min_posts.')') or error('Unable to add rank', __FILE__, __LINE__, $pun_db->error());
    58 
    61 
    59 	// Regenerate the ranks cache
    62 	// Regenerate the ranks cache
    60 	require_once PUN_ROOT.'include/cache.php';
    63 	require_once PUN_ROOT.'include/cache.php';
    61 	generate_ranks_cache();
    64 	generate_ranks_cache();
    62 
    65 
    63 	redirect('admin_ranks.php', 'Rank added. Redirecting &hellip;');
    66 	pun_redirect('admin_ranks.php', 'Rank added. Redirecting &hellip;');
    64 }
    67 }
    65 
    68 
    66 
    69 
    67 // Update a rank
    70 // Update a rank
    68 else if (isset($_POST['update']))
    71 else if (isset($_POST['update']))
    79 
    82 
    80 	if (!@preg_match('#^\d+$#', $min_posts))
    83 	if (!@preg_match('#^\d+$#', $min_posts))
    81 		message('Minimum posts must be a positive integer value.');
    84 		message('Minimum posts must be a positive integer value.');
    82 
    85 
    83 	// Make sure there isn't already a rank with the same min_posts value
    86 	// Make sure there isn't already a rank with the same min_posts value
    84 	$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());
    87 	$result = $pun_db->query('SELECT 1 FROM '.$pun_db->prefix.'ranks WHERE id!='.$id.' AND min_posts='.$min_posts) or error('Unable to fetch rank info', __FILE__, __LINE__, $pun_db->error());
    85 	if ($db->num_rows($result))
    88 	if ($pun_db->num_rows($result))
    86 		message('There is already a rank with a minimun posts value of '.$min_posts.'.');
    89 		message('There is already a rank with a minimun posts value of '.$min_posts.'.');
    87 
    90 
    88 	$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());
    91 	$pun_db->query('UPDATE '.$pun_db->prefix.'ranks SET rank=\''.$pun_db->escape($rank).'\', min_posts='.$min_posts.' WHERE id='.$id) or error('Unable to update rank', __FILE__, __LINE__, $pun_db->error());
    89 
    92 
    90 	// Regenerate the ranks cache
    93 	// Regenerate the ranks cache
    91 	require_once PUN_ROOT.'include/cache.php';
    94 	require_once PUN_ROOT.'include/cache.php';
    92 	generate_ranks_cache();
    95 	generate_ranks_cache();
    93 
    96 
    94 	redirect('admin_ranks.php', 'Rank updated. Redirecting &hellip;');
    97 	pun_redirect('admin_ranks.php', 'Rank updated. Redirecting &hellip;');
    95 }
    98 }
    96 
    99 
    97 
   100 
    98 // Remove a rank
   101 // Remove a rank
    99 else if (isset($_POST['remove']))
   102 else if (isset($_POST['remove']))
   100 {
   103 {
   101 	confirm_referrer('admin_ranks.php');
   104 	confirm_referrer('admin_ranks.php');
   102 
   105 
   103 	$id = intval(key($_POST['remove']));
   106 	$id = intval(key($_POST['remove']));
   104 
   107 
   105 	$db->query('DELETE FROM '.$db->prefix.'ranks WHERE id='.$id) or error('Unable to delete rank', __FILE__, __LINE__, $db->error());
   108 	$pun_db->query('DELETE FROM '.$pun_db->prefix.'ranks WHERE id='.$id) or error('Unable to delete rank', __FILE__, __LINE__, $pun_db->error());
   106 
   109 
   107 	// Regenerate the ranks cache
   110 	// Regenerate the ranks cache
   108 	require_once PUN_ROOT.'include/cache.php';
   111 	require_once PUN_ROOT.'include/cache.php';
   109 	generate_ranks_cache();
   112 	generate_ranks_cache();
   110 
   113 
   111 	redirect('admin_ranks.php', 'Rank removed. Redirecting &hellip;');
   114 	pun_redirect('admin_ranks.php', 'Rank removed. Redirecting &hellip;');
   112 }
   115 }
   113 
   116 
   114 
   117 
   115 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Ranks';
   118 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Ranks';
   116 $focus_element = array('ranks', 'new_rank');
   119 $focus_element = array('ranks', 'new_rank');
   151 					<fieldset>
   154 					<fieldset>
   152 						<legend>Edit/remove ranks</legend>
   155 						<legend>Edit/remove ranks</legend>
   153 						<div class="infldset">
   156 						<div class="infldset">
   154 <?php
   157 <?php
   155 
   158 
   156 $result = $db->query('SELECT id, rank, min_posts FROM '.$db->prefix.'ranks ORDER BY min_posts') or error('Unable to fetch rank list', __FILE__, __LINE__, $db->error());
   159 $result = $pun_db->query('SELECT id, rank, min_posts FROM '.$pun_db->prefix.'ranks ORDER BY min_posts') or error('Unable to fetch rank list', __FILE__, __LINE__, $pun_db->error());
   157 if ($db->num_rows($result))
   160 if ($pun_db->num_rows($result))
   158 {
   161 {
   159 
   162 
   160 ?>
   163 ?>
   161 							<table  cellspacing="0">
   164 							<table  cellspacing="0">
   162 							<thead>
   165 							<thead>
   167 								</tr>
   170 								</tr>
   168 							</thead>
   171 							</thead>
   169 							<tbody>
   172 							<tbody>
   170 <?php
   173 <?php
   171 
   174 
   172 	while ($cur_rank = $db->fetch_assoc($result))
   175 	while ($cur_rank = $pun_db->fetch_assoc($result))
   173 		echo "\t\t\t\t\t\t\t\t".'<tr><td><input type="text" name="rank['.$cur_rank['id'].']" value="'.pun_htmlspecialchars($cur_rank['rank']).'" size="24" maxlength="50" /></td><td><input type="text" name="min_posts['.$cur_rank['id'].']" value="'.$cur_rank['min_posts'].'" size="7" maxlength="7" /></td><td><input type="submit" name="update['.$cur_rank['id'].']" value="Update" />&nbsp;<input type="submit" name="remove['.$cur_rank['id'].']" value="Remove" /></td></tr>'."\n";
   176 		echo "\t\t\t\t\t\t\t\t".'<tr><td><input type="text" name="rank['.$cur_rank['id'].']" value="'.pun_htmlspecialchars($cur_rank['rank']).'" size="24" maxlength="50" /></td><td><input type="text" name="min_posts['.$cur_rank['id'].']" value="'.$cur_rank['min_posts'].'" size="7" maxlength="7" /></td><td><input type="submit" name="update['.$cur_rank['id'].']" value="Update" />&nbsp;<input type="submit" name="remove['.$cur_rank['id'].']" value="Remove" /></td></tr>'."\n";
   174 
   177 
   175 ?>
   178 ?>
   176 							</tbody>
   179 							</tbody>
   177 							</table>
   180 							</table>