News:

SMF 2.1.6 has been released! Take it for a spin! Read more.

Main Menu

Member Awards (2.0 Compatible!)

Started by Spuds, September 18, 2006, 03:14:03 PM

Previous topic - Next topic

spence_noodle

 ;D Fantastic mod.

Just installed it to a theme I'm using. To other members, all you need to do is edit the install.xml file.

Please make sure you backup the files you are about to edit.

Look for the lines:

  • <file name="$themedir/index.template.php">
  • <file name="$themedir/Profile.template.php">
  • <file name="$themedir/Display.template.php">
  • <file name="$themedir/languages/Modifications.english.php">

And change them too:

  • <file name="Themes/yourtheme/index.template.php">
  • <file name="Themes/yourtheme/Profile.template.php">
  • <file name="Themes/yourtheme/Display.template.php">
  • <file name="Themes/yourtheme/languages/Modifications.english.php">

Then save to a .zip file and login as admin, go to packages, click on Download New Packages and upload and install.

The award link will apear at the bottom of your menu.

Hope this has helped,

spence

littleone

Quote from: spence_noodle on November 29, 2006, 04:59:36 PM
;D Fantastic mod.

Just installed it to a theme I'm using. To other members, all you need to do is edit the install.xml file.

Please make sure you backup the files you are about to edit.

Look for the lines:

  • <file name="$themedir/index.template.php">
  • <file name="$themedir/Profile.template.php">
  • <file name="$themedir/Display.template.php">
  • <file name="$themedir/languages/Modifications.english.php">

And change them too:

  • <file name="Themes/yourtheme/index.template.php">
  • <file name="Themes/yourtheme/Profile.template.php">
  • <file name="Themes/yourtheme/Display.template.php">
  • <file name="Themes/yourtheme/languages/Modifications.english.php">

Then save to a .zip file and login as admin, go to packages, click on Download New Packages and upload and install.

The award link will apear at the bottom of your menu.

Hope this has helped,

spence

Generally this would work, but not all themes use the same coding as the default them.  So the install.xml file might be searching for one bit of code to modify or add after, but that code might not be the same in Custome theme and will do nothing but prompt errors.  Im sure it would work for the majority of custom themes with little problems, but I am sure the heavely customized mods would just be more headache than its worth.

EdwinK

#222
Out of about 500 members, I can only choose 10 or so to receive an award. Is there a way to add more usergroups so that I can select members from there.

(edit: It seems that this is a problem with converting from Invision to SMF. Not all membersgroups are ported :( )
|| foto-site ||

samurai-lupin

Hello Code Monkey!

I've tried installing this mod on my RC2 board and it worked fine but for the profile.template.php where I had to make some coe changes manually.

However when I try to add a new award I get the following error:

Fatal error: Call to undefined function: () in /hsphere/local/home/thunting/thunting.com/smf/Sources/ManageAwards.php on line 311

>:(

I'm quoting the specific file below

Any suggestiosn would be highly appreciated as I would really love to use this cool MOD. Thank you!

Sincerly,

Christian

<?php
/********************************************************************************
* ManageAwards.php                                                              *
* ----------------------------------------------------------------------------- *
* This file handles the admin side of Awards.                                   *
*********************************************************************************
* Software version:               1.0                                           *
* Software by:                    Juan "JayBachatero" Hernandez                 *
* Copyright (c) 2006 by:          Juan "JayBachatero" Hernandez                 *
* Contact:                        [email protected]                          *
* Website:                        JayBachatero.com                              *
* ============================================================================= *
* This mod is free software; you may redistribute it and/or modify it as long   *
* as you credit me for the original mod. This mod is distributed in the hope    *
* that it is and will be useful, but WITHOUT ANY WARRANTIES; without even any   *
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.      *
*                                                                               *
* All SMF copyrights are still in effect. Anything not mine is theirs. Enjoy!   *
* Some code found in here is copy written code by SMF, therefore it can not be  *
* redistributed without official consent from myself or SMF.                    *
********************************************************************************/

if (!defined('SMF'))
die ('Hacking attempt...');

/* This file handles adding new awards and giving them to the members

void Database tables
CREATE TABLE {$db_prefix}awards
(
ID_AWARD MEDIUMINT(5) NOT NULL AUTO_INCREMENT PRIMARY KEY,
awardName VARCHAR(80) NOT NULL,
gameName VARCHAR(80) NOT NULL,
timeAdded INT(10) UNSIGNED NOT NULL,
filename TINYTEXT NOT NULL,
width MEDIUMINT(8) UNSIGNED NOT NULL,
height MEDIUMINT(8) UNSIGNED NOT NULL
);
CREATE TABLE IF NOT EXISTS {$db_prefix}awards_members
(
ID_AWARD_MEMBER int(8) unsigned NOT NULL,
ID_AWARD BIGINT(10) UNSIGNED NOT NULL,
ID_MEMBER INT(8) UNSIGNED NOT NULL,
dateReceived DATE NOT NULL DEFAULT '0001-01-01'
favorite TINYINT(4) UNSIGNED NOT NULL DEFAULT 0,
UNIQUE KEY ID_AWARD_MEMBER (ID_AWARD_MEMBER),
KEY ID_AWARD (ID_AWARD)
);

void Awards
- Main function to handle subActions and tabs
- Requires manage_awards permission
- Uses Awards template and language

void AwardsMain
- Main page for the admin panel
- Loads the awards that have been added

void AwardsModify
- Sets up the $context['award'] var for the add/edit page.
- Load the content for the $context['award'] var for editing,
 if new mod empty default values.
- Calls AwardsSave to save the data

void AwardsSave
- If it's a new award it inserts a new rown if not it updated an existing one.
- Uses AwardsUpload for files upload.
- If a new award is uploaded for an existing mod, deletes the old award.

void AwardsUpload
- This file handles the uploading of awards.
- Uses $boarddir for the base path.
- Cleams file name by replacing spaces with "_"
- To prevent duplicate file; filenames have a random number prefixed

void AwardsDelete
- This function handles deleting an award.
- If the image exists delete it then delete the row from the database.
- Deletes any trace of the award in the {$db_prefix}awards_members table.

void AwardsAssign
- This is where you assign awards to members.  It is sone in steps
- Step 1
 - This is where you select the membergroups that you want to narrow the search for.
- Step 2
 - Select the award that you want to assign to members.  If you assigned the award from
   the main page that award will automatically be selected.
 - Select the members that you want to award.
 - Enter the date that the award was assigned on.
- Step 3
 - This is the step that handles the saving all the above data.
 - The date is formatted as year-month-day
 - Redirect back to the award.

void AwardsViewAssigned
- This is where you see the members that have been assigned a certain award.
- Unassign the award from certain members.

void AwardsSettings
- This is where you handle the settings for the mod
- pa_awardsDir is the directly in which the awards are saved.
- pa_columns and pa_rows is the amount of columns and rows so how in the admin page.
 If less than 1 it will be set to 4

*/

function Awards()
{
global $context, $scripturl, $txt;

// Check if they are allowed to be in here.
isAllowedTo('manage_awards');

// Load the adminIndex, template and language
adminIndex('awards_admin');
loadLanguage('ManageAwards');
loadTemplate('ManageAwards');

// Set up the subActions
$subActions = array(
'main' => 'AwardsMain',
'assign' => 'AwardsAssign',
'modify' => 'AwardsModify',
'delete' => 'AwardsDelete',
'edit' => 'AwardsModify',
'settings' => 'AwardsSettings',
'viewassigned' => 'AwardsViewAssigned',
);

// Load the subAction
$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'main';
$context['sub_action'] = $_REQUEST['sa'];

// Setup the tabs for the admin page.
$context['admin_tabs'] = array(
'title' => $txt['pa_title'],
'description' => $txt['pa_description'],
'tabs' => array(
'main' => array(
'title' => $txt['pa_main'],
'href' => $scripturl . '?action=awards',
),
'modify' => array(
'title' => isset($_REQUEST['modify'], $_REQUEST['award']) ? $txt['pa_edit'] : $txt['pa_add'],
'href' => $scripturl . '?action=awards;sa=modify',
),
'assign' => array(
'title' => $txt['pa_assign'],
'href' => $scripturl . '?action=awards;sa=assign',
),
'settings' => array(
'title' => $txt['pa_settings'],
'href' => $scripturl . '?action=awards;sa=settings',
'is_last' => true,
),
),
);

// Try to automatically select a tab.
if (isset($context['admin_tabs']['tabs'][$context['sub_action']]))
$context['admin_tabs']['tabs'][$context['sub_action']]['is_selected'] = true;
// Else select the main tab.
else
$context['admin_tabs']['tabs']['main']['is_selected'] = true;

// Now call the subAction
$subActions[$_REQUEST['sa']]();
}

function
AwardsMain()
{
global $context, $db_prefix, $scripturl, $modSettings, $txt;

// Count the number of items in the database for create index
$request = db_query("
SELECT COUNT(*)
FROM
{$db_prefix}awards", __FILE__, __LINE__);
list ($countAwards) = mysql_fetch_row($request);
mysql_free_result($request);

// Calculate the number of results to pull up.
$maxAwards = $modSettings['pa_columns'] * $modSettings['pa_rows'];

// Construct the page index
$context['page_index'] = constructPageIndex($scripturl . '?action=awards', $_REQUEST['start'], $countAwards, $maxAwards);
$context['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;

// Select the awards.
$selectAwards = db_query("
SELECT ID_AWARD, awardName, gameName, timeAdded, filename, width, height
FROM
{$db_prefix}awards
ORDER BY ID_AWARD DESC
LIMIT
$context[start], $maxAwards", __FILE__, __LINE__);

// Define $awards
$awards = array();

// Loop through the results.
while ($row = mysql_fetch_assoc($selectAwards))
{
$awards[] = array(
'id' => $row['ID_AWARD'],
'awardName' => $row['awardName'],
'gameName' => $row['gameName'],
'time' => timeformat($row['timeAdded']),
'filename' => $row['filename'],
'width' => $row['width'],
'height' => $row['height'],
'img' => dirname($scripturl) . '/' . (empty($modSettings['pa_awardsDir']) ? '' : $modSettings['pa_awardsDir'] . '/') . $row['filename'],
'edit' => $scripturl . '?action=awards;sa=modify;id=' . $row['ID_AWARD'],
'delete' => $scripturl . '?action=awards;sa=delete;id=' . $row['ID_AWARD'],
'assign' => $scripturl . '?action=awards;sa=assign;step=1;id=' . $row['ID_AWARD'],
'viewAssigned' => $scripturl . '?action=awards;sa=viewassigned;id=' . $row['ID_AWARD'],
);
}
mysql_free_result($selectAwards);

// Setup the context for the awards
$context['awards'] = $awards;

// Setup the title and template.
$context['page_title'] = $txt['pa_title'];
$context['sub_template'] = 'main';

}

function
AwardsModify()
{
global $context, $db_prefix, $scripturl, $txt, $modSettings, $settings;

// Check if awards is clean.
if (isset($_REQUEST['id']) && (is_array($_REQUEST['id']) || !is_numeric($_REQUEST['id'])))
fatal_lang_error('pa_error_no_id');

// Load the data for editing
if (isset($_REQUEST['id']) && $_REQUEST['id'] !== '0')
{
// Load single award ifo for editing.
$request = db_query("
SELECT ID_AWARD, awardName, gameName, timeAdded, filename, width, height
FROM
{$db_prefix}awards
WHERE ID_AWARD =
$_REQUEST[id]
LIMIT 1"
, __FILE__, __LINE__);
$row = mysql_fetch_assoc($request);

// Check if that award exists
if (count($row['ID_AWARD']) != 1)
fatal_lang_error('pa_error_no_award');

$context['editing'] = true;
$context['award'] = array(
'id' => $row['ID_AWARD'],
'awardName' => $row['awardName'],
'gameName' => $row['gameName'],
'time' => timeformat($row['timeAdded']),
'filename' => $row['filename'],
'width' => $row['width'],
'height' => $row['height'],
'img' => dirname($scripturl) . '/' . (empty($modSettings['pa_awardsDir']) ? '' : $modSettings['pa_awardsDir'] . '/') . $row['filename'],
);

// Free results
mysql_free_result($request);

// Set the title
$context['page_title'] = $txt['pa_title'] . ' - ' . $txt['pa_edit_award'];
}
else
{
// Setup place holders.
$context['editing'] = false;
$context['award'] = array(
'id' => 0,
'awardName' => '',
'gameName' => '',
'time' => '',
'filename' => '',
'width' => '',
'height' => '',
);

// Set the title
$context['page_title'] = $txt['pa_title'] . ' - ' . $txt['pa_add_award'];
}

// Check if they are saving the changes
if (isset($_POST['award_save']))
return AwardsSave();

// Load the sub-template and set the title
$context['sub_template'] = 'modify';

}

function
AwardsSave()
{
global $context, $db_prefix, $func, $txt;

// Before doing anything check the session
checkSession('post');

// Check if any of the values where left empty
if (empty($_REQUEST['awardName']))
fatal_lang_error('pa_error_empty_badge_name');
/*if (empty($_REQUEST['gameName']))
fatal_lang_error('pa_error_empty_game_name');*/
if (empty($_FILES['awardFile']['name']) && $_REQUEST['id'] == 0)
fatal_lang_error('pa_error_no_file');

// Clean the values
$_REQUEST['awardName'] = strtr($func['htmlspecialchars']($_REQUEST['awardName'], ENT_QUOTES), array("\r" => '', "\n" => '', "\t" => ''));
$_REQUEST['gameName'] = strtr($func['htmlspecialchars']($_REQUEST['gameName'], ENT_QUOTES), array("\r" => '', "\n" => '', "\t" => ''));
$timeAdded = time();

// Now to insert the data for this new award.
if ($_REQUEST['id'] == 0)
{
$addAward = db_query("
INSERT INTO
{$db_prefix}awards
(awardName, gameName, timeAdded)
VALUES
('
$_REQUEST[awardName]', '$_REQUEST[gameName]', $timeAdded)", __FILE__, __LINE__);

// Get the ID_AWARD
$ID_AWARD = db_insert_id();

// Now upload the file
if ($addAward === true && $_FILES['awardFile']['error'] === 0)
AwardsUpload($_FILES, $_REQUEST, $ID_AWARD);
}
else
{
// Set $ID_AWARD
$ID_AWARD = (int) $_REQUEST['id'];

// Edit the award
$editAward = db_query("
UPDATE
{$db_prefix}awards
SET
awardName = '
$_REQUEST[awardName]',
gameName = '
$_REQUEST[gameName]'
WHERE ID_AWARD =
$ID_AWARD", __FILE__, __LINE__);

// Are we uploading a new image for this award?
if (isset($_FILES['awardFile']) && $_FILES['awardFile']['error'] === 0 && $editAward === true)
{
// Lets make sure that we delete the file that we are supposed to and not something harmful
$request = db_query("
SELECT filename
FROM
{$db_prefix}awards
WHERE ID_AWARD =
$_REQUEST[id]", __FILE__, __LINE__);
list ($filename) = mysql_fetch_row($request);
mysql_free_result($request);

// Delete the file first.
if (file_exists($$boarddir . '/' . (empty($modSettings['pa_awardsDir']) ? '' : $modSettings['pa_awardsDir'] . '/') . $filename))
@unlink($boarddir . '/' . (empty($modSettings['pa_awardsDir']) ? '' : $modSettings['pa_awardsDir'] . '/') . $filename);

// Now add the new one.
AwardsUpload($_FILES, $_REQUEST, $ID_AWARD);
}
}

// Redirect back to the mod.
redirectexit('action=awards;sa=modify;id=' . $ID_AWARD);

}

function
AwardsUpload($_FILES, $_POST, $ID_AWARD)
{
global $context, $modSettings, $boarddir, $txt, $db_prefix;

// Check if $_FILE was set.
if (empty($_FILES['awardFile']) || !isset($ID_AWARD))
fatal_lang_error('ga_error_no_file');

// Lets try to CHMOD the awards dir.
if (!is_writable($boarddir . '/' . $modSettings['awardsDir']))
@chmod($boarddir . '/' . $modSettings['awardsDir'], 0777);

// Define $award
$award = $_FILES['awardFile'];

// Check if file was uploaded.
if ($award['error'] === 1 || $award['error'] === 2)
fatal_lang_error('ga_error_upload_size');
elseif ($award['error'] !== 0)
fatal_lang_error('ga_error_upload_failed');

// Check the extensions
$goodExtensions = array('jpg', 'jpeg', 'gif', 'png');
if (!in_array(strtolower(substr(strrchr($award['name'], '.'), 1)), $goodExtensions))
fatal_lang_error('pa_error_wrong_extension');

// Make sure they aren't trying to upload a nasty file.
$disabledFiles = array('con', 'com1', 'com2', 'com3', 'com4', 'prn', 'aux', 'lpt1', '.htaccess', 'index.php');
if (in_array(strtolower(basename($award['name'])), $disabledFiles))
fatal_lang_error('pa_error_wrong_extension');

// Get the width and height for the image
list ($award['width'], $award['height']) = getimagesize($award['tmp_name']);

/*To stop conflict between awards with the same name lets add a random
 number from 00000 to 99999 before the name and make the name be
 lowercased with spaces replaced with (_)*/
$clean_name = strtr($award['name'], 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy');
$clean_name = strtr($clean_name, array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u'));
$award['name'] = rand(00000, 99999) . '_' . strtolower(str_replace(' ', '_', $award['name']));

// Now move the file to the right directory
$tmpName = $award['tmp_name'];
$newName = $boarddir . '/' . (empty($modSettings['pa_awardsDir']) ? '' : $modSettings['pa_awardsDir'] . '/') . $award['name'];
move_uploaded_file($tmpName, $newName);

// Try to CHMOD the uploaded file
@chmod($newName, 0777);

// Cast to int.
$award['width'] = (int) $award['width'];
$award['height'] = (int) $award['height'];
$ID_AWARD = (int) $ID_AWARD;

// Now for the databse stuff.
$update = db_query("
UPDATE
{$db_prefix}awards
SET
filename = '
$award[name]',
width =
$award[width],
height =
$award[height]
WHERE ID_AWARD =
$ID_AWARD", __FILE__, __LINE__);

if ($update === true)
$uploadGood = true;
else
$uploadGood = false;

}

function
AwardsDelete()
{
global $db_prefix, $boarddir, $modSettings;

// Check if they are allowed to be here
if (allowedTo('manage_awards'))
{
// Check the session
checkSession('get');

// Cast $_REQUEST['id'] as int.
$_REQUEST['id'] = (int) $_REQUEST['id'];

// Select the file name to delete
$request = db_query("
SELECT filename
FROM
{$db_prefix}awards
WHERE ID_AWARD =
$_REQUEST[id]", __FILE__, __LINE__);
list($filename) = mysql_fetch_row($request);
mysql_free_result($request);

// Does that award even exists?
if (empty($filename))
fatal_lang_error('pa_error_no_award');

// Now delete the award from the hd
@unlink($boarddir . '/' . (empty($modSettings['pa_awardsDir']) ? '' : $modSettings['pa_awardsDir'] . '/') . $filename);

// Now delete the entry from the database.
db_query("
DELETE FROM
{$db_prefix}awards
WHERE ID_AWARD =
$_REQUEST[id]
LIMIT 1"
, __FILE__, __LINE__);

// Ok since this award doesn't exists any more lets remove it from the member
db_query("
DELETE FROM
{$db_prefix}awards_members
WHERE ID_AWARD =
$_REQUEST[id]", __FILE__, __LINE__);

// Redirect the exit
redirectexit('action=awards');
}
else
fatal_lang_error('pa_error_cant_delete');

}

function
AwardsAssign()
{
global $db_prefix, $context, $sourcedir, $modSettings, $txt;

// First step, select the memebrgroups
if (!isset($_REQUEST['step']) || $_REQUEST['step'] == 1)
{
$context['groups'] = array();
$postGroups = array();
$normalGroups = array();

// If we have post groups disabled then we need to give a "ungrouped members" option.
if (empty($modSettings['permission_enable_postgroups']))
{
$context['groups'][0] = array(
'id' => 0,
'name' => $txt['membergroups_members'],
'member_count' => 0,
);
$normalGroups[0] = 0;
}

// Get all the extra groups as well as Administrator and Global Moderator.
$request = db_query("
SELECT mg.ID_GROUP, mg.groupName, mg.minPosts
FROM
{$db_prefix}membergroups AS mg" . (empty($modSettings['permission_enable_postgroups']) ? "
WHERE mg.minPosts = -1"
: '') . "
GROUP BY mg.ID_GROUP
ORDER BY mg.minPosts, IF(mg.ID_GROUP < 4, mg.ID_GROUP, 4), mg.groupName"
, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
{
$context['groups'][$row['ID_GROUP']] = array(
'id' => $row['ID_GROUP'],
'name' => $row['groupName'],
'member_count' => 0,
);

if ($row['minPosts'] == -1)
$normalGroups[$row['ID_GROUP']] = $row['ID_GROUP'];
else
$postGroups[$row['ID_GROUP']] = $row['ID_GROUP'];
}
mysql_free_result($request);

// If we have post groups, let's count the number of members...
if (!empty($postGroups))
{
$query = db_query("
SELECT mem.ID_POST_GROUP AS ID_GROUP, COUNT(*) AS member_count
FROM
{$db_prefix}members AS mem
WHERE mem.ID_POST_GROUP IN ("
. implode(', ', $postGroups) . ")
GROUP BY mem.ID_POST_GROUP"
, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($query))
$context['groups'][$row['ID_GROUP']]['member_count'] += $row['member_count'];
mysql_free_result($query);
}

if (!empty($normalGroups))
{
// Find people who are members of this group...
$query = db_query("
SELECT ID_GROUP, COUNT(*) AS member_count
FROM
{$db_prefix}members
WHERE ID_GROUP IN ("
. implode(',', $normalGroups) . ")
GROUP BY ID_GROUP"
, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($query))
$context['groups'][$row['ID_GROUP']]['member_count'] += $row['member_count'];
mysql_free_result($query);

// Also do those who have it as an additional membergroup - this ones more yucky...
$query = db_query("
SELECT mg.ID_GROUP, COUNT(*) AS member_count
FROM (
{$db_prefix}membergroups AS mg, {$db_prefix}members AS mem)
WHERE mg.ID_GROUP IN ("
. implode(',', $normalGroups) . ")
AND mem.additionalGroups != ''
AND mem.ID_GROUP != mg.ID_GROUP
AND FIND_IN_SET(mg.ID_GROUP, mem.additionalGroups)
GROUP BY mg.ID_GROUP"
, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($query))
$context['groups'][$row['ID_GROUP']]['member_count'] += $row['member_count'];
mysql_free_result($query);
}

// Any moderators?
$request = db_query("
SELECT COUNT(DISTINCT ID_MEMBER) AS num_distinct_mods
FROM
{$db_prefix}moderators
LIMIT 1"
, __FILE__, __LINE__);
list ($context['groups'][3]['member_count']) = mysql_fetch_row($request);
mysql_free_result($request);

// step 1
$context['step'] = 1;

// Set the title
$context['page_title'] = $txt['pa_title'] . ' - ' . $txt['pa_mem_group'];
}
// Step 2: Load the awards and the name of the members for the selected membergroups.
elseif (isset($_REQUEST['step']) && $_REQUEST['step'] == 2)
{
// Make sure that they come form step 1
if (!isset($_POST['who']) || empty($_POST['who']))
fatal_lang_error('pa_error_no_who');

// Select the awards for the drop down.
$selectAwards = db_query("
SELECT ID_AWARD, awardName, filename
FROM
{$db_prefix}awards
ORDER BY awardName ASC"
, __FILE__, __LINE__);

$context['awards'] = array();
while ($row = mysql_fetch_assoc($selectAwards))
{
$context['awards'][$row['ID_AWARD']] = array(
'awardName' => $row['awardName'],
'filename' => $row['filename'],
);
}

// Free the above results
mysql_free_result($selectAwards);

// Clean who
foreach ($_POST['who'] as $k => $v)
$_POST['who'][$k] = (int) $v;

$context['members'] = array();

// Did they select moderators too?
if (!empty($_POST['who']) && in_array(3, $_POST['who']))
{
$request = db_query("
SELECT DISTINCT mem.ID_MEMBER, mem.realName
FROM (
{$db_prefix}members AS mem, {$db_prefix}moderators AS mods)
WHERE mem.ID_MEMBER = mods.ID_MEMBER"
, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
$context['members'][$row['ID_MEMBER']] = $row['realName'];

mysql_free_result($request);

unset($_POST['who'][3], $_POST['who'][3]);
}

// How about regular members?
if (!empty($_POST['who']) && in_array(0, $_POST['who']))
{
$request = db_query("
SELECT mem.ID_MEMBER, mem.realName
FROM
{$db_prefix}members AS mem
WHERE mem.ID_GROUP = 0"
, __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request))
$context['members'][$row['ID_MEMBER']] = $row['realName'];

mysql_free_result($request);

unset($_POST['who'][0], $_POST['who'][0]);
}

// Check if only regular members was selected
if (!empty($_POST['who']))
{
// Select the members.
$selectMembers = db_query("
SELECT ID_MEMBER, realName
FROM (
{$db_prefix}members AS mem, {$db_prefix}membergroups AS mg)
WHERE (mg.ID_GROUP = mem.ID_GROUP OR FIND_IN_SET(mg.ID_GROUP, mem.additionalGroups) OR mg.ID_GROUP = mem.ID_POST_GROUP)
AND mg.ID_GROUP IN ("
. implode(',', $_POST['who']) . ")
ORDER BY realName ASC"
, __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($selectMembers))
$context['members'][$row['ID_MEMBER']] = $row['realName'];
}

// Set the current step.
$context['step'] = 2;

// Set the title
$context['page_title'] = $txt['pa_title'] . ' - ' . $txt['pa_select_badge'];
}
// The last step.
elseif (isset($_REQUEST['step']) && $_REQUEST['step'] == 3)
{
// Make sure that they picked a award and members to assign it to...
if (!isset($_POST['member'], $_POST['award']))
fatal_lang_error('pa_error_no_members');

// Set a valid date, award.
$dateReceived = (int) $_POST['year'] . '-' . (int) $_POST['month'] . '-' . (int) $_POST['day'];
$_POST['award'] = (int) $_POST['award'];

// Define $values
$values = '';

// Prepare the values.
foreach ($_POST['member'] as $member)
$values .= "
("
. $_POST['award'] . '000' . $member . ", $_POST[award], $member, '$dateReceived'),";

// Inset the data
db_query("
INSERT IGNORE INTO
{$db_prefix}awards_members
(ID_AWARD_MEMBER, ID_AWARD, ID_MEMBER, dateReceived)
VALUES "
. substr($values, 0, -1), __FILE__, __LINE__);

// Redirect to show the memebrs with this award.
redirectexit('action=awards;sa=viewassigned;id=' . $_POST['award']);
}

$context['sub_template'] = 'assign';
}

function
AwardsViewAssigned()
{
global $context, $db_prefix, $scripturl, $modSettings, $txt;

// An award must be selected.
if (!isset($_REQUEST['id']))
fatal_lang_error('pa_error_no_award');

// Now load the info.
$membersSelect = db_query("
SELECT
mem.realName, am.ID_MEMBER, am.dateReceived
FROM
{$db_prefix}awards_members AS am
LEFT JOIN
{$db_prefix}members AS mem ON (mem.ID_MEMBER = am.ID_MEMBER)
WHERE am.ID_AWARD =
$_REQUEST[id]", __FILE__, __LINE__);

// Load the award info separatly
$awardSelect = db_query("
SELECT aw.ID_AWARD, aw.awardName, aw.gameName, aw.filename
FROM
{$db_prefix}awards AS aw
WHERE aw.ID_AWARD =
$_REQUEST[id]", __FILE__, __LINE__);

$assignedAward = array();

// Fetch the award info just once
$row = mysql_fetch_assoc($awardSelect);
$assignedAward = array(
'id' => $row['ID_AWARD'],
'awardName' => $row['awardName'],
'gameName' => $row['gameName'],
'filename' => $row['filename'],
'img' => dirname($scripturl) . '/' . (empty($modSettings['pa_awardsDir']) ? '' : $modSettings['pa_awardsDir'] . '/') . $row['filename'],
);
mysql_free_result($awardSelect);

// Check if ths award actually exists
if (empty($assignedAward['id']))
fatal_lang_error('pa_error_no_award');

$assignedMembers = array();
while ($row = mysql_fetch_assoc($membersSelect))
{
$assignedMembers[] = array(
'id' => $row['ID_MEMBER'],
'name' => $row['realName'],
'date' => $row['dateReceived'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>',
);
}
mysql_free_result($membersSelect);

// Remove the badge from these memebrs
if (isset($_POST['unassign']))
{
// Check the session.
checkSession('post');

// Make sure award is in
$_POST['id'] = (int) $_POST['id'];

// Delete the rows frm the database for the members selected.
db_query("
DELETE FROM
{$db_prefix}awards_members
WHERE ID_AWARD =
$_POST[id]
AND ID_MEMBER IN ("
. implode(', ', $_POST['member']) . ")", __FILE__, __LINE__);

// Redirect to the badges
redirectexit('action=awards;sa=viewassigned;id=' . $_POST['id']);
}

// Set the context values
$context['assignedAward'] = $assignedAward;
$context['assignedMembers'] = $assignedMembers;
$context['page_title'] = $txt['pa_title'] . ' - ' . $assignedAward['awardName'];
$context['sub_template'] = 'view_assigned';

}

function
AwardsSettings()
{
global $context, $modSettings, $txt, $boarddir, $func;

$context['sub_template'] = 'settings';
$context['page_title'] = $txt['pa_title'] . ' - ' . $txt['pa_settings'];

// Save the settings
if (isset($_POST['save_settings']))
{
// Check the session
checkSession('post');

// Strip any slashes from the badgesDir
$_POST['pa_awardsDir'] = str_replace(array('\\', '/'), '', $_POST['pa_awardsDir']);

// Try to create a new dir if it doesn't exists.
if (!is_dir($boarddir . '/' . $_POST['pa_awardsDir']) && trim($_POST['pa_awardsDir']) != '')
{
if (!mkdir($boarddir . '/' . $_POST['pa_awardsDir'], 0777))
$context['pa_mkdir_fail'] = true;
}

// Now save
updateSettings(array(
'pa_awardsDir' => $func['htmlspecialchars']($_POST['pa_awardsDir'], ENT_QUOTES),
'pa_columns' => isset($_POST['pa_columns']) && $_POST['pa_columns'] > 1 ? (int) $_POST['pa_columns'] : 4,
'pa_rows' => isset($_POST['pa_rows']) && $_POST['pa_rows'] > 1 ? (int) $_POST['pa_rows'] : 5,
'pa_favorites' => isset($_POST['pa_favorites']) ? 1 : 0,
));
}
}

?>

JayBachatero

* JayBachatero wonders if people check their SMF version before installing a mod ::).
This mod DOES NOT work with any version of SMF lower than 1.1 RC 3.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

golgofrinchian

Any hack or mod to allow the awards to be shown under/beside the avatar of the user? I made all my awards very tiny medals and want to have the medals showing below their avatar. Any mods out there that enable this?

like this:


Thanks!

JayBachatero

* JayBachatero points to a few pages back.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

golgofrinchian

Forgive my ignorance but I once again read through all 15 pages and dont see the code or the mod that enables this. I have your mod installed but It doesnt show the awards below the avatar. Thanks sorry for being a newb.

SMF Forum 1.1 (Release)
Tiny Portal 0.9.7
WOW-DKf TP Theme

http://www.warpiggy.com [nofollow]

JayBachatero

Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

golgofrinchian

Quote from: JayBachatero on October 01, 2006, 01:26:33 PM
Ok in Display.php find

mysql_free_result($request);
$posters = array_unique($posters);


Add after

// Load the members awards
$awards_request = db_query("
SELECT pab.filename, pam.ID_MEMBER
FROM {$db_prefix}awards_members AS pam
LEFT JOIN {$db_prefix}awards AS pab ON (pab.ID_AWARD = pam.ID_AWARD)
WHERE pam.ID_MEMBER IN (" . implode(', ', $posters) . ")
AND pam.favorite = 1
GROUP BY pam.ID_MEMBER", __FILE__, __LINE__);

$context['awards'] = array();
while ($row = mysql_fetch_assoc($awards_request))
$context['awards'][$row['ID_MEMBER']] = '<img src="' . dirname($scripturl) . '/' . (empty($modSettings['pa_awardsDir']) ? '' : $modSettings['pa_awardsDir'] . '/') . $row['filename'] . '" alt="' . $row['filename'] . '" />';

mysql_free_result($awards_request);



In Display.template.php find

// Show avatars, images, etc.?
if (!empty($settings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))
echo '
<div style="overflow: auto; width: 100%;">', $message['member']['avatar']['image'], '</div><br />';



Add after

// Show the fav award
if (isset($context['awards'][$message['member']['id']]))
echo '
<div style="overflow: auto; width: 100%;">', $context['awards'][$message['member']['id']], '</div><br />';



I didn't test this out so not sure if it's going to fully work.  It should work though.

The theme I am using does not have a display.php file. It does have a display.template.php file. I made the corrections both you and the previous poster showed and I get an error.

I am using 1.1


// Show avatars, images, etc.?


if (!empty($settings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))


echo '


<td nowrap="nowrap" align="left" style="padding: 18px 0px 10px 7px;">


', $message['member']['avatar']['image'], '</td>';


echo '





<td nowrap="nowrap" align="left" class="smalltext" style="padding: 18px 2px 10px 7px;">


<span class="member_name">', $message['member']['link'], '</span>';





if (!$message['member']['is_guest'])


{
            // Show the fav award
if (isset($context['awards'][$message['member']['id']]))
echo '
<div style="overflow: auto; width: 100%;">', $context['awards'][$message['member']['id']], '</div><br />';


// Show online and offline buttons?


if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest'])


echo '


', $context['can_send_pm'] ? '<a href="' . $message['member']['online']['href'] . '" title="' . $message['member']['online']['label'] . '">' : '', $settings['use_image_buttons'] ? '<img src="' . $message['member']['online']['image_href'] . '" alt="' . $message['member']['online']['text'] . '" border="0" align="middle" />' : $message['member']['online']['text'], $context['can_send_pm'] ? '</a>' : '', $settings['use_image_buttons'] ? ' ' : '', ' ';


Any tips?

TechnoDragon

Display.php is not a theme based file...it is in the sources directory.
Don't tell me to get into shape...I have a shape...It is round!


golgofrinchian

Thanks for thew quick replies, however I get this when I upload the files to the server:

An Error Has Occurred!
Unable to load the 'main' template.


The error is ONLY after I upload the Display.template.php file

No error at all when I install the Display.php. I am guessing that one is ok.

Here is my code from Display.template.php file on the current theme I am using:


// Show avatars, images, etc.?


if (!empty($settings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))


echo '


<div style="overflow: auto; width: 100%;">', $message['member']['avatar']['image'], '</div><br />';

            // here>>
            // Show the fav award
if (isset($context['awards'][$message['member']['id']]))
echo '
<div style="overflow: auto; width: 100%;">', $context['awards'][$message['member']['id']], '</div><br />';


// Show their personal text?



Any thoughts?

JayBachatero

Did you replace the Display.php with this?
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

golgofrinchian

No thats my Display.template.php file.

I did the Display.php the way you listed on the post up there^


TechnoDragon

What error are you receiving?
Don't tell me to get into shape...I have a shape...It is round!


golgofrinchian

An Error Has Occurred!
Unable to load the 'main' template.

JayBachatero

You were supposed to edit the template not replace the whole thing with that.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

golgofrinchian

/sigh I am just showing you what I added... I didn't replace the whole thing. I followed the directions ;D

I added those lines after the ones specified in the above listed post you wrote.^^^

TechnoDragon

generally...unable to load main template...means that either e file reference in the index file is missing or a file that is needed is missing...check to make sure that all of the files are in the right place.
Don't tell me to get into shape...I have a shape...It is round!


golgofrinchian

I took them out edited them, made backup, then put them back. Each one in order. There are only 2 files. I edited. And the names are different.

Im using 1.1 (release) and tiny Portal .0.9.7. I can see any forum post on the main page but when I actually go to the post (where the Display.template.php would take over) is when I get that error. To fix it I just upload the backup and its fine. So it must be Display.template.php and not Display.php, IMHO...


Advertisement: