Well...I tried... hehe
I dislike VERY much editing the standard files SMF and/or TP. So that is something I *really* REALLY tries to keep at a bare minimum. So far I've only edited index.html (added two lines)
To make a custom memberslist I thought I'd try to duplicate then edit the standard one;
Here's what I tried to do:
* edit index.html and add a new action called afkmlist
* copied the file Sources\Memberlist.php to Sources\AFKMemberlist.php
* copied the file Themes\Default\Memberlist.template.php to Themes\Default\AFKMemberlist.template.php
* edited the two AFK.... files to remove some of the fields in the "standard" memberslisting, and to change some of them to fields I've added to the smf_members table in the database.
And...well...it didnt go all that well ;D
Whenever I try:
..../index.php?action=afkmlist
I get a message saying:
QuoteAn Error Has Occurred!
Unable to load the 'main' template.
Back
So, I think I'd better go back to Plan B. Which is to code my custom memberslist in a php article. Only problem is that my knowledge seems to be a bit too limited.
I got this code from Rasyr:
global $context, $db_prefix;
$request = db_query("SELECT memberName, rank_aok, rank_aoe3 FROM {$db_prefix}members where rank_aok != 0 or rank_aoe3 != 0 ORDER BY memberName", __FILE__, __LINE__);
if (mysql_num_rows($request) > 0)
{
while($row = mysql_fetch_assoc($request)){
$context['myCode'][] = array(
'memberName' => $row['memberName'],
'rank_aok' => $row['rank_aok'],
'rank_aoe3' => $row['rank_aoe3'],
);
}
mysql_free_result($request);
}
echo '<table border="1" cellspacing="0" cellpadding="5" align="center">';
echo '<tr bgcolor="#b0c4de"><td><b>Member Nick</b></td><td><b>AOK Rank</b></td><td><b>AOE3 Rank</b></td></tr>';
foreach ($context['myCode'] as $myMember)
{
echo'<tr><td>'. $myMember['memberName'] .'</td><td>'. $myMember['rank_aok'] .'</td><td>'. $myMember['rank_aoe3'] .'</td></tr>';
}
echo '</table>'; This code selects three fields (two of them custom) from the smf_members table, and displays them sorted according to the sql. And I do believe this is something I can build on - but what I dont know how to do is to make it so that whenever the users click on any of the column-headings it'll sort after that heading (much like the standard mlist does) I did try to figure out how they did it in the Memberlist.php and the following template file, but alas.. :///
So...anyone able to take the code above and add functionality so that one can click the column-headings and it'll sort (desc/asc) after those headings ??
Look in the root directory, at the index.php file. In that file there is a large list of "actions". You have to make sure that you added your new "actions" to that file as well.
For ideas on adding items to the memberlist, I would suggest that you take a look at this Mod --> http://mods.simplemachines.org/index.php?mod=229
And read the associated thread about it --> http://www.simplemachines.org/community/index.php?topic=58832.0
Specifically where I was trying to add an extra column.
One of my many tasks still to do is to reimplement this Mod (with the modifications noted in that thread) on my forums.
Yes, I did add the action. I did write that as my first step in the post above, alltho it might have been a bit unclear, sorry.
I had two plans. Both plans had the main goal of minimizing the changing of the standard-files. I really would like to avoid this, this includes avoiding adding a mod.
Plan A was as I wrote in my first post, try to duplicate the Memberlist.php and the Memberlist.template.php and the only edit in standard-files would be the addition of the "afkmlist"-action. But since I got this error-message I think I'd better move on to:
Plan B - Which is to code my custom memberslist in a php article. But as mentioned; my php-knowledge seems to be a bit too limited to edit the php I got for that rankings-page to make the column-headings "clickable" so that it'll sort on those column-headings.
When you made a copy of the Source file and changed its name, did you remember to change the names of the functions inside? You would have to change the names of the $context variables where the information is stored when it pulls it out of the DB (in both files). Perhaps there is some conflict there.
Well...hehe. Thats it!!!! :)
I had:
// Show a listing of the registered members.
function Memberlist()
Changed it to:
// Show a listing of the registered members.
function AFKMemberlist()
It gets displayed now. Not excactly how I wanted it but very close.
I do have a couple of things to sort out tho. Such as:
- linking up to a picture of the members (name/path to image saved in the database)
- changing some of the column-headings (i cant seem to find where this is done)
- either fixing so that the "Search for members" works (it will now only partly bring my custom layout)
or remove it entirely
So...back to php it is...and thanks for that tip. I had no idea I was this close !! :)
Column headings...
Look in your new version of the Sources Memberlist.php (whatever you renamed it to) for the section that begins like:
// Set up the columns...
$context['columns'] = array(
'isOnline' => array(
'label' => $txt['online8'],
'width' => '20'
),
'realName' => array(
'label' => $txt[35]
),
'emailAddress' => array(
'label' => $txt[307],
'width' => '25'
),
'websiteUrl' => array(
'label' => $txt[96],
'width' => '25'
),
'ICQ' => array(
'label' => $txt[513],
'width' => '25'
),
That is what sets up your columns...
To do the sorting thing like the current Memberlist has, look further down in the same file and find this section:
// List out the different sorting methods...
$sort_methods = array(
'isOnline' => array(
'down' => '(ISNULL(lo.logTime)' . (!allowedTo('moderate_forum') ? ' OR NOT mem.showOnline' : '') . ') ASC, realName ASC',
'up' => '(ISNULL(lo.logTime)' . (!allowedTo('moderate_forum') ? ' OR NOT mem.showOnline' : '') . ') DESC, realName DESC'
),
'realName' => array(
'down' => 'mem.realName ASC',
'up' => 'mem.realName DESC'
),
'emailAddress' => array(
'down' => (allowedTo('moderate_forum') || empty($modSettings['allow_hideEmail'])) ? 'mem.emailAddress ASC' : 'mem.hideEmail ASC, mem.emailAddress ASC',
'up' => (allowedTo('moderate_forum') || empty($modSettings['allow_hideEmail'])) ? 'mem.emailAddress DESC' : 'mem.hideEmail DESC, mem.emailAddress DESC'
),
That is where it sets it up to sort by ascending or descending....
I did some editing in that section ("// Set up the columns..."). But I'm not excactly sure what the different things mean ://
Here's the whole section after edits:
// Set up the columns...
$context['columns'] = array(
'isOnline' => array(
'label' => $txt['online8'],
'width' => '20'
),
'memberName' => array(
'label' => $txt[35]
),
'afk_picture' => array(
'label' => $txt[255]
),
'location' => array(
'label' => 'Location'
),
'ICQ' => array(
'label' => $txt[513],
'width' => '25'
),
'rank_aok' => array(
'label' => 'AOK Rank'
),
'rank_aoe3' => array(
'label' => 'AOE3 Rank'
),
'ID_GROUP' => array(
'label' => $txt[87]
),
'registered' => array(
'label' => $txt[233]
)
);
So - as you can see I've added three new fields (afk_picture, rank_aok and rank_aoe3) rest of them are standard member-fields, allthough not in the excact same order as the original Memberlist.php
I PM'd you the url to the current version where you can see that the column-headings is a bit weird. Ie, there's no heading-text for "afk_picture" nor any content, and for some reason it wont fetch the data stored in neither "rank_aok" nor "rank_aoe3" ..doh
Edit:
The weird thing is that the Memberlist.php never seem to actually fetch the values from the database in any "clean" sql-code...only thing I find is this:
// Select the members from the database.
$request = db_query("
SELECT mem.ID_MEMBER
FROM {$db_prefix}members AS mem
LEFT JOIN {$db_prefix}log_online AS lo ON (lo.ID_MEMBER = mem.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))
WHERE mem.is_activated = 1
ORDER BY " . $sort_methods[$_REQUEST['sort']][$context['sort_direction']] . "
LIMIT $_REQUEST[start], $modSettings[defaultMaxMembers]", __FILE__, __LINE__);
And here it'll select only the ID_MEMBER... I would assume that I'd have to add my custom fields somewhere ??
Missing Picture name - looks like it cannot find the $txt[255] string that it is looking for.
Column name wierdness for other two columns - try $txt['AOK Rank'] and see if that makes a difference.
Memberdata is actually gotten in the Load.php file. Look there. You may have to copy that function, and then adjust it accordingly - best to copy it to the bottom of the file most likely and make your adjustments there.
However, this has to be called from someplace. So, check the other functions in load.php as well, and also check the index.php file in the forum root, to see if you can trace where the information is being called (if you can search multiple files, try doing a search in the whole of the forum pages to see where it might be getting called from.
Note: loadMemberData() is called at the bottom of the MemberList.php file... So that is likely where you will need to make the change as to what function is being called once you make a new version of that function for yourself.
You're absolutely correct; "$txt[255]" it was.
Looks nice now. Only thing it needs now is custom-data values hehe :)
After you tips I see that not only am I beginning to actually READ php code !!! :) , but more to the point for this excact problem I see that I in my AFKMemberlist.php have the:
"loadMemberData($members);" (near bottom and inside the "function printMemberListRows($request)" )
If I'm reading this script correctly it will call the funtion loadMemberData sending in a "array" of all the ID_MEMBER rows in this array using the $members variable. Now, inside Load.php I do find the function and I see that it can take 3 variables and will default the two last ones if none is given:
function loadMemberData($users, $is_name = false, $set = 'normal')
So, $members (array with all the ID_MEMBER) from my AFKMemberlist.php will be sent into the $users and $is_name will default to false and $set will default to 'normal'.
Piece of cake eh ? ;) (that is...if im reading this right..hehe)
So, as mentioned, the function loadMemberData is defined in load.php. Thing is...it gets called "all over the place" (from atleast 8 different scripts). As mentioned I want to reduce the editing of the original files to a bare minimum, to avoid editing load.php - would it be possible somehow to copy the loadMemberData function (and rename it, and edit it) into some of "my" scripts ?
That'll be one of these:
- sources/AFKMemberlist.php
- themes/default/AFKMemberlist.template.php
You could likely copy it to the bottom of your AFKMemberlist.php source file, but I am not sure if it would work there. It wouldn't hurt to give it a try though... ;D
aha...
so in a php u can have:
function A()
blabla
function B
function B()
moreblabla
and A will call and excecute B ?
Anyways, In my AFKMemberlist.php I changed the :
// Load all the members for display.
AFKloadMemberData($members);
to
// Load all the members for display.
AFKloadMemberData($members);
and added my version of that function with this change:
if ($set == 'normal')
{
$select_columns = "
IFNULL(lo.logTime, 0) AS isOnline, IFNULL(a.ID_ATTACH, 0) AS ID_ATTACH, a.filename, a.attachmentType,
mem.rank_aok, mem.rank_aoe3,
mem.signature, mem.personalText, mem.location, mem.gender, mem.avatar, mem.ID_MEMBER, mem.memberName,
mem.realName, mem.emailAddress, mem.hideEmail, mem.dateRegistered, mem.websiteTitle, mem.websiteUrl,
mem.birthdate, mem.memberIP, mem.ICQ, mem.AIM, mem.YIM, mem.MSN, mem.posts, mem.lastLogin,
mem.karmaGood, mem.ID_POST_GROUP, mem.karmaBad, mem.lngfile, mem.ID_GROUP, mem.timeOffset, mem.showOnline,
mem.buddy_list, mg.onlineColor AS member_group_color, IFNULL(mg.groupName, '') AS member_group,
pg.onlineColor AS post_group_color, IFNULL(pg.groupName, '') AS post_group,
IF(mem.ID_GROUP = 0 OR mg.stars = '', pg.stars, mg.stars) AS stars" . (!empty($modSettings['titlesEnable']) ? ',
mem.usertitle' : '');
$select_tables = "
LEFT JOIN {$db_prefix}log_online AS lo ON (lo.ID_MEMBER = mem.ID_MEMBER)
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = mem.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS pg ON (pg.ID_GROUP = mem.ID_POST_GROUP)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = mem.ID_GROUP)";
}
notice the extra line with the two custom fields.
But...hmm...no values gets displayed in that url I pm'd you... hmmmm
I am a very big newb when it comes to SQL, especially things as complex as that one seems to be (I have no idea at all about JOINs), so I am about at the end of the help that I can give.
Well, Im pretty good with SQL and i believe this SQL code is just fine.
You see I've added:
mem.rank_aok, mem.rank_aoe3,
the phrase "mem" is just an alias for smf_members and the "rank_aok" and "rank_aoe3" is two of the custom columns (I've later added "mem.afk_picture" but that didnt help either)
So...I've come to conclude that its either:
-------------------------------------------
1) the order of the fields is imperative
or
2) adding the function like that is problematic (I get no errors tho)
or
3) for some odd reason the if/else clause: "if ($set == 'normal')" doesnt "gets filled"
or
4) something we've overlooked..... ;D
-------------------------------------------
I also found this one:
http://www.simplemachines.org/community/index.php?topic=22260.msg177889#msg177889
Its in french tho, but it seems we're on the right track.
The problem is if the order of the fields is important. I'm not sure how to verify that :(
The SQL is now:
Quote
if ($set == 'normal')
{
$select_columns = "
IFNULL(lo.logTime, 0) AS isOnline, IFNULL(a.ID_ATTACH, 0) AS ID_ATTACH, a.filename, a.attachmentType,
mem.rank_aok, mem.rank_aoe3, mem.afk_picture, mem.signature, mem.personalText, mem.location, mem.gender, mem.avatar, mem.ID_MEMBER, mem.memberName,
mem.realName, mem.emailAddress, mem.hideEmail, mem.dateRegistered, mem.websiteTitle, mem.websiteUrl,
mem.birthdate, mem.memberIP, mem.ICQ, mem.AIM, mem.YIM, mem.MSN, mem.posts, mem.lastLogin,
mem.karmaGood, mem.ID_POST_GROUP, mem.karmaBad, mem.lngfile, mem.ID_GROUP, mem.timeOffset, mem.showOnline,
mem.buddy_list, mg.onlineColor AS member_group_color, IFNULL(mg.groupName, '') AS member_group,
pg.onlineColor AS post_group_color, IFNULL(pg.groupName, '') AS post_group,
IF(mem.ID_GROUP = 0 OR mg.stars = '', pg.stars, mg.stars) AS stars" . (!empty($modSettings['titlesEnable']) ? ',
mem.usertitle' : '');
$select_tables = "
LEFT JOIN {$db_prefix}log_online AS lo ON (lo.ID_MEMBER = mem.ID_MEMBER)
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = mem.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS pg ON (pg.ID_GROUP = mem.ID_POST_GROUP)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = mem.ID_GROUP)";
}
Getting this to work would be awesome, opens up for "modding" without modding anything else than index.html !!!
My suggestion would be to study what the function is actually doing. Then, as Bloc suggested to me for something or other that I was trying to do, strip it down to the bare essentials of what you need. You know what you want it in. You have both a simple (what I wrote gave you) and a complex (the SMF Memberlist) example of various ways of doing this.
Since you are making a custom mod, then don't worry too much about creating an extra page or two.
Sit down and decide what you need to get what you want, and then design it to grab the information that you need, and only the information you need.
That SQL call is far beyond my skills at the moment, so I am not sure how much help I am going to be from this point.
Yeah, you're probably right. It'll take soooo much longer tho. On the bright-side I'll prolly learn LOTS !!! :)
Thanks for your help Rasyr!!
hmmm...I had another look at this one:
http://www.simplemachines.org/community/index.php?topic=22260.msg177889#msg177889
and...well..take a look at the third "recherche:" and "remplace avec:" (both code blocks start with "// Select the members from the database.")
I cant seem to find this anywhere in my files !!?? Is this due to me running:
SMF 1.1 RC1.
Oxygen / TinyPortal v.0.75 by Bloc
??
Your version of TinyPortal will have nothing to do with it, however, your version of SMF most likely does have something to do with it.
The date on that post you linked to is Dec 25, 2004. That, IIRC, was before 1.1 RC1 was released, and is most likely for either 1.05 or the 1.1 Beta3 version.
Ah, that explains it. So I've actually got a newer version !!! weeeeeeee ;)