Version: 3.7.4, by Xanlamin
Developer Last Online: Apr 2015
Category: Miscellaneous Hacks -
Version: 3.7.x
Rating:
Released: 08-08-2008
Last Update: 11-22-2008
Installs: 511
DB Changes Uses Plugins Auto-Templates
Re-useable Code Code Changes Additional Files
No support by the author.
A lot of you have been waiting for this forever to work 100% with 3.7 due to the new profile tabs...Well wait no longer, here is the new revises version of HacNho's YAAS (Yet Another Awards System).
DESCRIPTION:
This is a Medals/Awards system. Admin can give members awards, and award icons will be displayed in member's profile, posts, as well as in a award list.
FEATURES: In AdminCP
- Can Create/Edit/Delete/Reorder categories/sub-categories in ACP (with category name and description)
- Can Create/Edit/Delete awards in ACP (with Award Name, Description, Icon URL, Image URL)
- Can Move one (or all) award(s) from one category to another
- Can set some awards un-classified (not displayed for public)
- Can re-order awards in awards showcase
+ Issue awards to members, based on username or userid, with Issue Reason
+ Remove awards from members
In ModCP
+ Issue awards to members, based on username or userid, with Issue Reason
+ Remove awards from members
Front page
- Display awards list in with: Award Name, Description, Icon, Image, and Members who get each award.
- Display awards showcase in profile, with Award information, Issue time and reason
- Display award icons in postbit (showthread, showpost, announcement, private)
CHANGES/MODIFICATION:
- Tables to add: 3 (award, award_user, award_cat)
- Files to add: 4 (/awards.php, /award_request.php, /admincp/award.php, /admincp/award_cat.php)
DIFFICULTY:
Easy
Time: about 5 minutes
Installer is included (1 product XML)
CREDIT:
Idea has been carried on by many people, here are some:
- Lesane for original Award hack for vB2, eventhough I've never use his hack
- AnimeWebby for Awards/ Medals/ Cards Hack [vB3], which I write new code based on his.
- Mac ycl6 for phpBB Medal System for phpBB forum
- Dr Erwin Loh for FORM TO THREAD/ FORUM/ PM/ EMAIL hack
- Cypher for helping with the tabs in 3.7
- liwo for re-writing plugins
- and all others for supports and ideas
bug with the drop down in the settings... Sorting: Awards Listings always reverts to "Issue Time-Newest First" so if you don't notice, and change a different setting, it changes your sort order back to newest first.
On another note, I've also got the award system plugged into the permissions now and when an award is given to a user a scheduled task runs and checks for new awards and assigns them to a usergroup based on the award. There is also a script that checks for removed awards and will remove the relevant usergroup too.
Can you let us know how to do it?
Im trying to have a way for the mods to change a user from groups based on one award.
Can you let us know how to do it?
Im trying to have a way for the mods to change a user from groups based on one award.
Sure. A few things to note. Firstly, this assumes you have a reasonable knowledge of php as they are manual files. Secondly, you need to work out what awards (specifically their ID's) need to belong to what group (again you need to know the ID's)
All the groups are set in the arrays at the top. The first column (value) in the array is the award ID. The second column (value) is the usergroup that you want to assign this award to.
The reason there are two arrays is because we have one particular award that we want to assign to two separate usergroups. This may not apply to you, if it doesn't then you can remove $arr2 and comment out the while loop.
Here is the code. I called it award2group.php and placed it in the modules folder of the forum.
PHP Code:
<?php
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db))
{
exit;
}
// ########################### SET VARIABLES ##############################
$i = 1;
while ($i <= 2)
{
if ($i == 1)
{
$arr = $arr1;
}
else
{
$arr = $arr2;
}
foreach ($arr as $awardval => $aw2gr)
{
// check for award and update secondary usergroup if required
$giveawards = $vbulletin->db->query_read("
SELECT aw.award_id, us.userid, us.membergroupids
FROM " . TABLE_PREFIX . "award_user as aw
LEFT OUTER JOIN " . TABLE_PREFIX . "user AS us ON us.userid = aw.userid AND (aw.award_id = $awardval)
WHERE FIND_IN_SET($aw2gr, us.membergroupids) = 0
");
if ($vbulletin->db->num_rows($giveawards) > 0)
{
while ($giveawardsrow = $vbulletin->db->fetch_array($giveawards))
{ // for each award, check to see if they are a member of the relevant group and update accordingly
$userdm =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$userinfo = fetch_userinfo($giveawardsrow['userid']);
$userdm->set_existing($userinfo);
$membergroupids = $userdm->fetch_field('membergroupids');
if ($membergroupids != "")
{
// Explode to an array
$mbrgrp_array = explode(",", $membergroupids);
// Add remove/add group to array
$mbrgrp_array[] = $aw2gr;
// Make it a comma seperated string again
$membergroupids = implode(",", $mbrgrp_array);
}
else
{
$membergroupids = $aw2gr;
}
$userdm->set('membergroupids', $membergroupids);
$userdm->pre_save();
if (count($userdm->errors))
{
for ($i = 0; $i < count($userdm->errors); $i++)
{
echo "ERROR{$i}:{$userdm->errors[$i]}\n";
}
}
else
{
// If everything is OK
$userdm->save();
unset($mbrgrp_array);
}
}
$vbulletin->db->free_result($giveawardsrow);
}
}
$i++;
}
That will assign anyone who has an award to the relevant usergroup. NOTE: It will assign the group as a SECONDARY group only. It will not change or replace the users primary group membership.
Now for the removing part. If a user has an award taken away, you will need a script to remove that user from the assigned usergroup. This is handled in this script which I called delaward2group.php and placed in the same folder as the above.
You may notice that the arrays at the top of each file matches. This is so it only removes groups that have been assigned by awards. The array could be put in a separate php file and included into the two scripts so you only have one list to maintain but that all depends on your coding method.
PHP Code:
<?php
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db))
{
exit;
}
// ########################### SET VARIABLES ##############################
$i = 1;
while ($i <= 2)
{
if ($i == 1)
{
$arr = $arr1;
}
else
{
$arr = $arr2;
}
foreach ($arr as $awardval => $aw2gr)
{
// need to get the keys from the array to use as an or in the query. This will make sure that a user that has one award that belongs to a multi award group does not get removed
$awardkeys = array_keys($arr, $aw2gr);
$keycount = count($awardkeys);
if ($keycount == 1)
{ // single key then there only needs to be one value for the query
$awardor = $awardkeys[0];
}
else
{
for ($ac = 0; $ac < $keycount; $ac++)
{ // more than one key then the query OR needs to be constructed here
if ($ac < $keycount - 1)
{
$awardor .= $awardkeys[$ac] . " OR aw.award_id = ";
}
else
{
$awardor .= $awardkeys[$ac];
}
}
}
unset($awardkeys, $ac);
// check for groups that no longer have the award and remove them from the secondary user group
$delawards = $vbulletin->db->query_read("
SELECT DISTINCT us.userid, us.membergroupids
FROM " . TABLE_PREFIX . "user AS us
WHERE NOT EXISTS (
SELECT aw.userid, aw.award_id
FROM " . TABLE_PREFIX . "award_user AS aw
WHERE (aw.award_id = $awardor) AND us.userid = aw.userid) AND FIND_IN_SET($aw2gr, us.membergroupids) <> 0
");
unset($awardor); // unset the OR query here or it'll continue to add to it on the next loop
if ($vbulletin->db->num_rows($delawards) > 0)
{
while ($delawardsrow = $vbulletin->db->fetch_array($delawards))
{ // remove group from users that no longer have the award
$userdm =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$userinfo = fetch_userinfo($delawardsrow['userid']);
$userdm->set_existing($userinfo);
$membergroupids = $userdm->fetch_field('membergroupids');
if ($membergroupids != "")
{
// Explode to an array
$mbrgrp_array = explode(",", $membergroupids);
// Add remove/add group to array
$key = array_search($aw2gr, $mbrgrp_array);
unset($mbrgrp_array[$key]);
// Make it a comma seperated string again
$membergroupids = implode(",", $mbrgrp_array);
}
$userdm->set('membergroupids', $membergroupids);
$userdm->pre_save();
if (count($userdm->errors))
{
for ($i = 0; $i < count($userdm->errors); $i++)
{
echo "ERROR{$i}:{$userdm->errors[$i]}\n";
}
}
else
{
// If everything is OK
$userdm->save();
unset($mbrgrp_array);
}
}
$vbulletin->db->free_result($delawardsrow);
}
}
$i++;
}
All you need to do now is setup two scheduled tasks to call the two scripts. I have the award2group.php running every hour and the delaward2group.php running every 12 hours. You can choose a schedule to suit your particular needs.
A really useful facility would be the ability to have some awards awarded automatically - e.g based on time since regitation - or if your a member of a certain group (I know you can become a member because of an award I'm after the opposite )