Skip to content

Instantly share code, notes, and snippets.

@Repflez
Last active December 18, 2015 22:08
Show Gist options
  • Save Repflez/5851863 to your computer and use it in GitHub Desktop.
Save Repflez/5851863 to your computer and use it in GitHub Desktop.
ABXD User Badge Manager
<?php
cell2(actionLinkTag(__('Manage User Badges'), 'userbadges'));
<?php
// AcmlmBoard XD Plugin - User badges management tool
// Access: administrators only
// Based on ipbans.php
$title = __('User Badges Manager');
assertForbidden('editUserBadges');
if($loguser['powerlevel'] < 3)
kill(__('You\'re not an administrator. There is nothing for you here.'));
$crumbs = new PipeMenu();
$crumbs->add(new PipeMenuLinkEntry(__('Admin'), 'admin'));
$crumbs->add(new PipeMenuLinkEntry(__('User Badges Manager'), 'userbadges'));
makeBreadcrumbs($crumbs);
if($_POST['action'] == __('Add'))
{
if($_POST['color'] == -1 || empty($_POST['userid']) || empty($_POST['name']))
{
kill(__('Please review your settings before adding a user badge.'));
}
else
{
query('insert into {badges} values ({0}, {1}, {2})',
(int)$_POST['userid'], $_POST['name'], (int)$_POST['color']);
alert(__('Added.'), __('Notice'));
}
}
elseif($_GET['action'] == 'delete')
{
query('delete from {badges} where owner = {0} and name = {1}',
(int)$_GET['userid'], $_GET['name']);
alert(__('Removed.'), __('Notice'));
}
elseif($_GET['action'] == 'deleteall')
{
query('delete from {badges} where owner = {0}',
(int)$_GET['userid']);
alert(__('Removed all badges of the user.'), __('Notice'));
}
elseif($_GET['action'] == 'newbadge')
{
$userID = 'value="'.((int)$_GET['userid']).'"';
}
// Fetch badges
$qBadge = 'SELECT owner, {badges}.name, color, {users}.name username, {users}.sex sex, {users}.powerlevel powerlevel FROM {badges} JOIN {users} where owner = id';
$rBadge = query($qBadge);
$badgeList = '';
while($badges = Fetch($rBadge))
{
$cellClass = ($cellClass+1) % 2;
$colors = array(__('Bronze'),__('Silver'),__('Gold'),__('Platinum'));
$badgeList .= '
<tr class="cell$cellClass">
<td>
<a href="'.actionLink('profile', $badges['owner']).'">'.$badges['username'].'</a>
</td>
<td>
'.$badges['name'].'
</td>
<td>
'.$colors[$badges['color']].'
</td>
<td>
<a href="'.actionLink('userbadges', '', 'userid='.$badges['owner'].'&name='.$badges['name'].'&action=delete').'">&#x2718;</a>
</td>
</tr>
';
}
echo '
<table class="outline margin width50">
<tr class="header1">
<th>'.__('Badge Owner').'</th>
<th>'.__('Badge Name').'</th>
<th>'.__('Badge Type').'</th>
<th>&nbsp;</th>
</tr>
'.$badgeList.'
</table>
<form action="'.actionLink('userbadges').'" method="post">
<table class="outline margin width50">
<tr class="header1">
<th colspan="2">
'.__('Add').'
</th>
</tr>
<tr>
<td class="cell2">
'.__('User ID').'
</td>
<td class="cell0">
<input type="text" name="userid" style="width: 15%;" maxlength="4" '.$userID.'/>
</td>
</tr>
<tr>
<td class="cell2">
'.__('Name').'
</td>
<td class="cell1">
<input type="text" name="name" style="width: 98%;" maxlength="15" />
</td>
</tr>
<tr>
<td class="cell2">
'.__('Type').'
</td>
<td class="cell1">
<select name="color">
<option value="-1">'.__('Select').'</option>
<option value="0">'.__('Bronze').'</option>
<option value="1">'.__('Silver').'</option>
<option value="2">'.__('Gold').'</option>
<option value="3">'.__('Platinum').'</option>
</select>
</td>
</tr>
<tr class="cell2">
<td></td>
<td>
<input type="submit" name="action" value="'.__('Add').'" />
</td>
</tr>
</table>
</form>
';
name=User Badge Manager
description=Allows to issue custom badges to users.
author=Repflez
<?php
if($loguser['powerlevel'] > 3){
echo '
<table class="outline margin" style="margin-top:1.5em;">
<tr class="header0">
<th colspan="2">' . __('Badge Manager Panel') . '</th>
</tr>
<tr>
<td class="cell0" align="center">
<a href="' . actionLink('userbadges', '', 'userid=' . $id . '&action=newbadge') . '">' . __('Add a new badge for this user') . '</a>
&nbsp;&mdash;&nbsp;
<a href="' . actionLink('userbadges', '', 'userid=' . $id . '&action=deleteall') . '">' . __('Delete all badges of this user') . '</a>
</td>
</tr>
</table>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment