promote/demote users, started on rebuild

This commit is contained in:
Michael Save 2012-04-14 22:28:21 +10:00
parent 1437a121f7
commit 87281687ed
5 changed files with 136 additions and 13 deletions

View File

@ -143,7 +143,12 @@ function mod_page_ip($ip) {
}
if (isset($_POST['note'])) {
// TODO: permissions
if (hasPermission($config['mod']['create_notes'])) {
$query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
$query->bindValue(':ip', $ip);
$query->execute() or error(db_error($query));
$args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC);
}
markup($_POST['note']);
$query = prepare('INSERT INTO `ip_notes` VALUES (NULL, :ip, :mod, :time, :body)');
@ -194,20 +199,30 @@ function mod_page_ip($ip) {
$args['boards'] = $boards;
$query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
$query->bindValue(':ip', $ip);
$query->execute() or error(db_error($query));
$args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC);
$query = prepare("SELECT `ip_notes`.*, `username` FROM `ip_notes` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
$query->bindValue(':ip', $ip);
$query->execute() or error(db_error($query));
$args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC);
if (hasPermission($config['mod']['view_ban'])) {
$query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
$query->bindValue(':ip', $ip);
$query->execute() or error(db_error($query));
$args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC);
}
if (hasPermission($config['mod']['view_notes'])) {
$query = prepare("SELECT `ip_notes`.*, `username` FROM `ip_notes` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
$query->bindValue(':ip', $ip);
$query->execute() or error(db_error($query));
$args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC);
}
mod_page("IP: $ip", 'mod/view_ip.html', $args);
}
function mod_ban() {
global $config;
if (!hasPermission($config['mod']['ban']))
error($config['error']['noaccess']);
if (!isset($_POST['ip'], $_POST['reason'], $_POST['length'], $_POST['board'])) {
mod_page("New ban", 'mod/ban_form.html', array());
return;
@ -263,6 +278,19 @@ function mod_users() {
mod_page('Manage users', 'mod/users.html', $args);
}
function mod_user_promote($uid, $action) {
global $config;
if (!hasPermission($config['mod']['promoteusers']))
error($config['error']['noaccess']);
$query = prepare("UPDATE `mods` SET `type` = `type` " . ($action == 'promote' ? "+1 WHERE `type` < " . (int)ADMIN : "-1 WHERE `type` > " . (int)JANITOR) . " AND `id` = :id");
$query->bindValue(':id', $uid);
$query->execute() or error(db_error($query));
header('Location: ?/users', true, $config['redirect_http']);
}
function mod_new_pm($username) {
global $config, $mod;
@ -272,8 +300,16 @@ function mod_new_pm($username) {
$query = prepare("SELECT `id` FROM `mods` WHERE `username` = :username");
$query->bindValue(':username', $username);
$query->execute() or error(db_error($query));
if (!$id = $query->fetchColumn(0))
error($config['error']['404']);
if (!$id = $query->fetchColumn(0)) {
// Old style ?/PM: by user ID
$query = prepare("SELECT `username` FROM `mods` WHERE `id` = :username");
$query->bindValue(':username', $username);
$query->execute() or error(db_error($query));
if ($username = $query->fetchColumn(0))
header('Location: ?/new_PM/' . $username, true, $config['redirect_http']);
else
error($config['error']['404']);
}
if (isset($_POST['message'])) {
markup($_POST['message']);
@ -291,3 +327,12 @@ function mod_new_pm($username) {
mod_page("New PM for {$username}", 'mod/new_pm.html', array('username' => $username, 'id' => $id));
}
function mod_rebuild() {
global $config;
if (!hasPermission($config['mod']['rebuild']))
error($config['error']['noaccess']);
mod_page("Rebuild", 'mod/rebuild.html', array('boards' => listBoards()));
}

View File

@ -26,7 +26,7 @@ function load_twig() {
$loader->setPaths($config['dir']['template']);
$twig = new Twig_Environment($loader, array(
'autoescape' => false,
//'cache' => "{$config['dir']['template']}/cache",
'cache' => "{$config['dir']['template']}/cache",
'debug' => ($config['debug'] ? true : false),
));
$twig->addExtension(new Twig_Extensions_Extension_Tinyboard());

View File

@ -28,8 +28,11 @@ $pages = array(
'!^/log/(\d+)$!' => 'log', // modlog
'!^/users$!' => 'users', // manage users
'!^/users/(\d+)/(promote|demote)$!' => 'user_promote', // prmote/demote user
'!^/new_PM/([^/]+)$!' => 'new_pm', // create a new pm
'!^/rebuild$!' => 'rebuild', // rebuild static files
'!^/ban$!' => 'ban', // new ban
'!^/IP/([\w.:]+)$!' => 'ip', // view ip address
'!^/IP/([\w.:]+)/remove_note/(\d+)$!' => 'ip_remove_note', // remove note from ip address

View File

@ -0,0 +1,71 @@
<form style="width:200px;margin:auto" action="?/rebuild" method="post">
<ul id="rebuild">
<li style="margin-bottom:8px">
<input type="checkbox" name="rebuild_all" id="rebuild_all" onchange="toggleall(this.checked)">
<label for="rebuild_all"><strong>Toggle all</strong></label>
<script>
function toggleall(val) {
/* TODO: something more suitable for all browsers? */
var elements = document.getElementById('rebuild').querySelectorAll('input');
for (i in elements) {
elements[i].checked = val;
}
}
</script>
</li>
<li>
<input type="checkbox" name="rebuild_cache" id="rebuild_cache" checked>
<label for="rebuild_cache">Flush cache</label>
</li>
<li>
<input type="checkbox" name="rebuild_javascript" id="rebuild_javascript" checked>
<label for="rebuild_javascript">Rebuild Javascript</label>
</li>
<li>
<input type="checkbox" name="rebuild_index" id="rebuild_index" checked>
<label for="rebuild_index">Rebuild index pages</label>
</li>
<li>
<input type="checkbox" name="rebuild_thread" id="rebuild_thread" checked>
<label for="rebuild_thread">Rebuild thread pages</label>
</li>
<li>
<input type="checkbox" name="rebuild_themes" id="rebuild_themes" checked>
<label for="rebuild_themes">Rebuild themes</label>
</li>
<li>
<input type="checkbox" name="rebuild_posts" id="rebuild_posts">
<label for="rebuild_posts">Rebuild replies</label>
</li>
</ul>
<hr>
<ul id="boards">
<li style="margin-bottom:8px">
<input type="checkbox" name="boards_all" id="boards_all" onchange="toggleallboards(this.checked)" checked>
<label for="boards_all"><strong>All boards</strong></label>
<script>
function toggleallboards(val) {
/* TODO: something more suitable for all browsers? */
var elements = document.getElementById('boards').querySelectorAll('input');
for (i in elements) {
elements[i].checked = val;
}
}
</script>
</li>
{% for board in boards %}
<li>
<input type="checkbox" name="board_{{ board.uri }}" id="board-{{ board.uri }}" checked>
<label for="board-{{ board.uri }}">
{{ config.board_abbreviation|sprintf(board.uri) }} - {{ board.title }}
</label>
</li>
{% endfor %}
</ul>
<p style="text-align:center">
<input type="submit" value="Rebuild">
</p>
</form>

View File

@ -30,7 +30,11 @@
</td>
<td>
{% if mod|hasPermission(config.mod.modlog) %}
<span title="{{ user.action|e }}">{{ user.last|ago }}</span>
{% if user.last %}
<span title="{{ user.action|e }}">{{ user.last|ago }}</span>
{% else %}
<em>never</em>
{% endif %}
{% else %}
&ndash;
{% endif %}