punbb/admin_ranks.php
author Dan
Wed, 11 Jul 2007 21:01:48 -0400
changeset 0 f9ffdbd96607
child 2 a8a21e1c7afa
permissions -rw-r--r--
Initial population
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     1
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     2
/***********************************************************************
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     3
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     4
  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     5
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     6
  This file is part of PunBB.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     7
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     8
  PunBB is free software; you can redistribute it and/or modify it
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     9
  under the terms of the GNU General Public License as published
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    10
  by the Free Software Foundation; either version 2 of the License,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    11
  or (at your option) any later version.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    12
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    13
  PunBB is distributed in the hope that it will be useful, but
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    14
  WITHOUT ANY WARRANTY; without even the implied warranty of
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    16
  GNU General Public License for more details.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    17
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    18
  You should have received a copy of the GNU General Public License
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    19
  along with this program; if not, write to the Free Software
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    20
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    21
  MA  02111-1307  USA
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    22
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    23
************************************************************************/
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    24
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    25
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    26
// Tell header.php to use the admin template
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    27
define('PUN_ADMIN_CONSOLE', 1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    28
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    29
define('PUN_ROOT', './');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    30
require PUN_ROOT.'include/common.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    31
require PUN_ROOT.'include/common_admin.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    32
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    33
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    34
if ($pun_user['g_id'] > PUN_ADMIN)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    35
	message($lang_common['No permission']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    36
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    37
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    38
// Add a rank
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    39
if (isset($_POST['add_rank']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    40
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    41
	confirm_referrer('admin_ranks.php');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    42
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    43
	$rank = trim($_POST['new_rank']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    44
	$min_posts = $_POST['new_min_posts'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    45
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    46
	if ($rank == '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    47
		message('You must enter a rank title.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    48
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    49
	if (!@preg_match('#^\d+$#', $min_posts))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    50
		message('Minimum posts must be a positive integer value.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    51
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    52
	// Make sure there isn't already a rank with the same min_posts value
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    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());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    54
	if ($db->num_rows($result))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    55
		message('There is already a rank with a minimun posts value of '.$min_posts.'.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    56
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    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());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    58
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    59
	// Regenerate the ranks cache
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    60
	require_once PUN_ROOT.'include/cache.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    61
	generate_ranks_cache();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    62
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    63
	redirect('admin_ranks.php', 'Rank added. Redirecting &hellip;');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    64
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    65
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    66
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    67
// Update a rank
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    68
else if (isset($_POST['update']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    69
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    70
	confirm_referrer('admin_ranks.php');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    71
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    72
	$id = intval(key($_POST['update']));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    73
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    74
	$rank = trim($_POST['rank'][$id]);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    75
	$min_posts = trim($_POST['min_posts'][$id]);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    76
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    77
	if ($rank == '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    78
		message('You must enter a rank title.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    79
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    80
	if (!@preg_match('#^\d+$#', $min_posts))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    81
		message('Minimum posts must be a positive integer value.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    82
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    83
	// Make sure there isn't already a rank with the same min_posts value
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    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());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    85
	if ($db->num_rows($result))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    86
		message('There is already a rank with a minimun posts value of '.$min_posts.'.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    87
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    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());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    89
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    90
	// Regenerate the ranks cache
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    91
	require_once PUN_ROOT.'include/cache.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    92
	generate_ranks_cache();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    93
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    94
	redirect('admin_ranks.php', 'Rank updated. Redirecting &hellip;');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    95
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    96
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    97
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    98
// Remove a rank
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    99
else if (isset($_POST['remove']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   100
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   101
	confirm_referrer('admin_ranks.php');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   102
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   103
	$id = intval(key($_POST['remove']));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   104
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   105
	$db->query('DELETE FROM '.$db->prefix.'ranks WHERE id='.$id) or error('Unable to delete rank', __FILE__, __LINE__, $db->error());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   106
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   107
	// Regenerate the ranks cache
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   108
	require_once PUN_ROOT.'include/cache.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   109
	generate_ranks_cache();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   110
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   111
	redirect('admin_ranks.php', 'Rank removed. Redirecting &hellip;');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   112
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   113
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   114
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   115
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Ranks';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   116
$focus_element = array('ranks', 'new_rank');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   117
require PUN_ROOT.'header.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   118
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   119
generate_admin_menu('ranks');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   120
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   121
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   122
	<div class="blockform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   123
		<h2><span>Ranks</span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   124
		<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   125
			<form id="ranks" method="post" action="admin_ranks.php?action=foo">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   126
				<div class="inform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   127
					<fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   128
						<legend>Add rank</legend>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   129
						<div class="infldset">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   130
							<p>Enter a rank and the minimum number of posts that a user has to have to aquire the rank. Different ranks cannot have the same value for minimum posts. If a title is set for a user, the title will be displayed instead of any rank. <strong>User ranks must be enabled in <a href="admin_options.php#ranks">Options</a> for this to have any effect.</strong></p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   131
							<table  cellspacing="0">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   132
							<thead>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   133
								<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   134
									<th class="tcl" scope="col">Rank&nbsp;title</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   135
									<th class="tc2" scope="col">Minimum&nbsp;posts</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   136
									<th class="hidehead" scope="col">Action</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   137
								</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   138
							</thead>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   139
							<tbody>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   140
								<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   141
									<td><input type="text" name="new_rank" size="24" maxlength="50" tabindex="1" /></td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   142
									<td><input type="text" name="new_min_posts" size="7" maxlength="7" tabindex="2" /></td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   143
									<td><input type="submit" name="add_rank" value=" Add " tabindex="3" /></td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   144
								</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   145
							</tbody>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   146
							</table>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   147
						</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   148
					</fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   149
				</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   150
				<div class="inform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   151
					<fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   152
						<legend>Edit/remove ranks</legend>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   153
						<div class="infldset">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   154
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   155
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   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());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   157
if ($db->num_rows($result))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   158
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   159
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   160
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   161
							<table  cellspacing="0">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   162
							<thead>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   163
								<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   164
									<th class="tcl" scope="col"><strong>Rank&nbsp;title</strong></th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   165
									<th class="tc2" scope="col"><strong>Minimum&nbsp;Posts</strong></th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   166
									<th class="hidehead" scope="col">Actions</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   167
								</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   168
							</thead>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   169
							<tbody>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   170
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   171
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   172
	while ($cur_rank = $db->fetch_assoc($result))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   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";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   174
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   175
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   176
							</tbody>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   177
							</table>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   178
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   179
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   180
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   181
else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   182
	echo "\t\t\t\t\t\t\t".'<p>No ranks in list.</p>'."\n";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   183
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   184
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   185
						</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   186
					</fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   187
				</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   188
			</form>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   189
		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   190
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   191
	<div class="clearer"></div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   192
</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   193
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   194
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   195
require PUN_ROOT.'footer.php';