PDA

View Full Version : hacking memberlist file...Help please


btappan
08-02-2004, 11:16 PM
i needed to move one of my custom profile fields (which was "company name") to be the first column in the member list instead of the username being first. i did it using this:

http://www.vbulletin.com/forum/showthread.php?t=112058

.......now i need to have it sort alphabetically by this field as well...
can anyone help me do what Jake suggest and modify the memberlist.php file to sort by my "field 5" as well? I need this very badly for my site! thanks for your help

Andreas
08-02-2004, 11:45 PM
In memberlist.php FIND

switch ($sortfield)
{
case 'username':
$sqlsort = 'user.username';
break;


BELOW that ADD

case 'companyname':
$sqlsort = 'userfield.field5';
break;


Revert to the original versions of your memberlist and memberlist_resultsbit templates.

Set your Company Name field to NOT show up on members list

In template memberlist FIND

<td class="thead" align="$stylevar[left]" nowrap="nowrap"><a href="$sorturl&amp;order=ASC&amp;sort=username&amp;pp=$perpage&amp;ltr=$ ltr$usergrouplink">$vbphrase[username]</a> $sortarrow[username]</td>


ABOVE that ADD

<td class="thead" nowrap="nowrap"><a href="$sorturl&amp;order=ASC&amp;sort=companyname&amp;pp=$perpage&amp;lt r=$ltr$usergrouplink">Company Name</a> $sortarrow[companyname]</td>


In template memberlist_resultsbit FIND

<td class="alt1Active" align="$stylevar[left]" id="u$userinfo[userid]">
<a href="member.php?$session[sessionurl]u=$userinfo[userid]">$userinfo[musername]</a>
<if condition="$show['usertitlecol']"><div class="smallfont">$userinfo[usertitle]</div></if>
</td>


ABOVE that ADD

<td class="alt2Active">
$userinfo[field5]
</td>

btappan
08-03-2004, 12:35 AM
ahhh perfect. i'll be glad when i've learned enough to accomplish things like that on my own. one more quick question. can i make it defualt to be sorted by that field when a user first visits the member list link? as it stands now, it is still sorted by username by default.

thanks so much for your help and quick response!

Andreas
08-03-2004, 12:41 AM
Yes. In memberlist.php, just some lines below the place where you added the code there is

default:
$sqlsort = 'user.username';
$sortfield = 'username';


Replace that with

default:
$sqlsort = 'userfield.field5';
$sortfield = 'companyname';


(Untested as I was too lazy to test, but theoretically it should work ;))

btappan
08-03-2004, 12:58 AM
seems to have made no change :ermm: maybe something else?

Andreas
08-03-2004, 01:04 AM
Yeah, there is another default being set earlier in memberlist.php ;)

FIND

// set defaults and sensible values

if ($sortfield == '')
{
$sortfield = 'username';
}


Replace that with

// set defaults and sensible values

if ($sortfield == '')
{
$sortfield = 'companyname';
}

btappan
08-03-2004, 02:10 AM
Voila! :D all worky now! thanks so much for your persistent help....

btappan
09-05-2004, 08:39 PM
Hey KirbyDE, can you help Warhorse and I get the alpha search at the top of the memberlist page to sort by the added userfield, in this case, "company name" instead of by the username? It'd be greatly appreciated!

btappan
09-08-2004, 05:01 PM
anyone else care to help me with this?

Tbird66
12-12-2004, 07:08 AM
also looking for help getting the alpha search at the top of the memberlist page to sort by the added userfield.

any suggestions would be welcome!

Tbird66
12-16-2004, 04:21 AM
I had a functionality requirement similiar to btappan's, but I needed the custom field to only be visible to those users who had permissions to view private custom fields.

To accomplish this, I modified KirbyDE's hack. I'm reposting Kirby's hack with my modifications (I hope this is proper procedure - this is the first time I've posted code) - thanks KirbyDE!!

The following steps will set up your Member List to display the Company Name (user field 5 in this example) as the first column and sort by it if the user has permissions to see private custom fields (assuming that user field 5 is a private custom field of course ;) ), and display the default Member List if the user does not have permissions to see private custom fields.

In memberlist.php FIND
// set defaults and sensible values

if ($sortfield == '')
{
$sortfield = 'username';
}

REPLACE that WITH
// set defaults and sensible values

if ($sortfield == '')
{
if ($permissions['genericpermissions'] & CANSEEHIDDENCUSTOMFIELDS)
{
$sortfield = 'companyname';
}
else
{
$sortfield = 'username';
}
}

then FIND
switch ($sortfield)
{
case 'username':
$sqlsort = 'user.username';
break;

BELOW that ADD
case 'companyname':
$sqlsort = 'userfield.field5';
break;

Revert to the original versions of your memberlist and memberlist_resultsbit templates.

Set your Company Name field to NOT show up on members list

In template memberlist FIND
<td class="thead" align="$stylevar[left]" nowrap="nowrap"><a href="$sorturl&amp;order=ASC&amp;sort=username&amp;pp=$perpage&amp;ltr=$ ltr$usergrouplink">$vbphrase[username]</a> $sortarrow[username]</td>

ABOVE that ADD
<if condition="$permissions['genericpermissions'] & CANSEEHIDDENCUSTOMFIELDS">
<td class="thead" align="$stylevar[left]" nowrap="nowrap"><a href="$sorturl&amp;order=ASC&amp;sort=companyname&amp;pp=$perpage&amp;lt r=$ltr$usergrouplink">Company Name</a> $sortarrow[companyname]
</td></if>

In template memberlist_resultsbit FIND
<td class="alt1Active" align="$stylevar[left]" id="u$userinfo[userid]">
<a href="member.php?$session[sessionurl]u=$userinfo[userid]">$userinfo[musername]</a>
<if condition="$show['usertitlecol']"><div class="smallfont">$userinfo[usertitle]</div></if>
</td>

ABOVE that ADD
<if condition="$permissions['genericpermissions'] & CANSEEHIDDENCUSTOMFIELDS">
<td class="alt2Active" align="$stylevar[left]"> $userinfo[field5]
</td></if>

EDIT:
The following will allow the alpha search at the top of the memberlist page to sort by the added userfield.
In memberlist.php FIND
if ($ltr != '')
{
if ($ltr == '#')
{
$condition = "username NOT REGEXP(\"^[a-zA-Z]\")";
}
else
{
$ltr = chr(intval(ord($ltr)));
$condition = 'username LIKE("' . addslashes_like($ltr) . '%")';
}
}

REPLACE that WITH
if ($ltr != '')
{
if ($ltr == '#')
{
if (($sortfield == 'companyname') OR ($sortfield != 'username' AND ($permissions['genericpermissions'] & CANSEEHIDDENCUSTOMFIELDS)))
{
$condition = "field5 NOT REGEXP(\"^[a-zA-Z]\")";
}
else
{
$condition = "username NOT REGEXP(\"^[a-zA-Z]\")";
}
}
else
{
$ltr = chr(intval(ord($ltr)));

if (($sortfield == 'companyname') OR ($sortfield != 'username' AND ($permissions['genericpermissions'] & CANSEEHIDDENCUSTOMFIELDS)))
{
$condition = 'field5 LIKE("' . addslashes_like($ltr) . '%")';
}
else
{
$condition = 'username LIKE("' . addslashes_like($ltr) . '%")';
}
}
}

Tbird66
12-20-2004, 09:57 PM
I figured out how to get the alpha search at the top of the memberlist page to sort by the added userfield, check my previous post for the new code...

steven s
01-09-2005, 11:43 PM
On these same lines I want to sort by additional profile fields in the membership list.

I have one field named Membership Number and one membership renewal date.
Using phpMyAdmin I see 'vb3_profilefield'
If I browse profileid
id #5 is Membership Number and id#6 is Membership renewal.

How would I applyswitch ($sortfield)
{
case 'username':
$sqlsort = 'user.username';
break; to do what I want?