[DEV] Extra field in user information

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
Post Reply
User avatar
Rod
Registered User
Posts: 232
Joined: Sun Dec 02, 2001 7:29 pm
Location: my chair, beside desk, in lounge, upstairs, in house, close to Farnham, just South of London, UK ...
Contact:

[DEV] Extra field in user information

Post by Rod »

Klaus2000 requested how to add an extra field and I've also seen it requested in other places (before phpBB2 went final).

I've written this as a tutorial, in sections. Thats to try and make it easier to follow!

It's written to adda field for member no as that is the one which was requested but i've put the bits that need altering in red so it can easily be altered for different purposes of an extra field.

In the example the following is used:
FIELD-Name: member_no
FIELD-Size: around 10


This first bit does the following:
  1. Adds a new field to your database.
  2. Alters the registration screen and the editing profile screen to include the new field.
Note: I've used quote tags instead of code tags so i can put bits in red.

[edit]
THIS MOD IS RELEASED AS A REAL NAMES MOD. SEE http://www.phpbb.com/phpBB/viewtopic.php?t=15421
I HAVEN'T DELETED THE CODE BECAUSE IT EASILY SHOWS WHAT NEEDS TO BE CHANGED FOR OTHER FIELDS (IN RED)

[/edit]
#
#-----[ ACTION ]------------------------------------------
#
# You will need to add one new field into your users table in your SQL database.

SQL-query:
ALTER TABLE users ADD user_member_no VARCHAR (10)

## The member_no needs to be changed to the whatever you want to call the field.
##
## The (10) Specifies the field size so if you want 50 characters then
## change it to (50).
##
## If you have a table prefix then put it before users
## eg if default prefix then the above becomes:
## ALTER TABLE phpbb_users ADD user_member_no VARCHAR (50)
##



#
#----- [ OPEN ] -------------------------------------
# This first section modifies registration and profile to input
# the member number (or whatever the field is for)

phpBB2/includes/usercp_register.php

#
#----- [ FIND ] -------------------------------------
#

$sql = "UPDATE " . USERS_TABLE . "
SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) ."', user_icq = '" . str_replace("\'", "''", $icq) . "', user_website = '" . str_replace("\'", "''", $website) . "', user_occ = '" . str_replace("\'", "''", $occupation) . "', user_from = '" . str_replace("\'", "''", $location) . "', user_interests = '" . str_replace("\'", "''", $interests) . "', user_sig = '" . str_replace("\'", "''", $signature) . "', user_sig_bbcode_uid = '$signature_bbcode_uid', user_viewemail = $viewemail, user_aim = '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', user_yim = '" . str_replace("\'", "''", $yim) . "', user_msnm = '" . str_replace("\'", "''", $msn) . "', user_attachsig = $attachsig, user_allowsmile = $allowsmilies, user_allowhtml = $allowhtml, user_allowbbcode = $allowbbcode, user_allow_viewonline = $allowviewonline, user_notify = $notifyreply, user_notify_pm = $notifypm, user_popup_pm = $popuppm, user_timezone = $user_timezone, user_dateformat = '" . str_replace("\'", "''", $user_dateformat) . "', user_lang = '" . str_replace("\'", "''", $user_lang) . "', user_style = $user_style, user_active = $user_active, user_actkey = '" . str_replace("\'", "''", $user_actkey) . "'" . $avatar_sql . "

#
#----- [ REPLACE WITH ] -------------------------------------
#

$sql = "UPDATE " . USERS_TABLE . "
SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) ."', user_icq = '" . str_replace("\'", "''", $icq) . "', user_website = '" . str_replace("\'", "''", $website) . "', user_occ = '" . str_replace("\'", "''", $occupation) . "', user_from = '" . str_replace("\'", "''", $location) . "', user_interests = '" . str_replace("\'", "''", $interests) . "', user_sig = '" . str_replace("\'", "''", $signature) . "', user_sig_bbcode_uid = '$signature_bbcode_uid', user_viewemail = $viewemail, user_aim = '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', user_yim = '" . str_replace("\'", "''", $yim) . "', user_msnm = '" . str_replace("\'", "''", $msn) . "', user_attachsig = $attachsig, user_allowsmile = $allowsmilies, user_allowhtml = $allowhtml, user_allowbbcode = $allowbbcode, user_allow_viewonline = $allowviewonline, user_notify = $notifyreply, user_notify_pm = $notifypm, user_popup_pm = $popuppm, user_timezone = $user_timezone, user_dateformat = '" . str_replace("\'", "''", $user_dateformat) . "', user_lang = '" . str_replace("\'", "''", $user_lang) . "', user_style = $user_style, user_active = $user_active, user_actkey = '" . str_replace("\'", "''", $user_actkey) . "'" . $avatar_sql . ", user_member_no = '" . str_replace("\'", "''", $member_no) . "'


#
#----- [ FIND ] -------------------------------------
#

$sql = "INSERT INTO " . USERS_TABLE . " (user_id, username, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interests, user_sig, user_sig_bbcode_uid, user_avatar, user_avatar_type, user_viewemail, user_aim, user_yim, user_msnm, user_attachsig, user_allowsmile, user_allowhtml, user_allowbbcode, user_allow_viewonline, user_notify, user_notify_pm, user_popup_pm, user_timezone, user_dateformat, user_lang, user_style, user_level, user_allow_pm, user_active, user_actkey)
VALUES ($user_id, '" . str_replace("\'", "''", $username) . "', " . time() . ", '" . str_replace("\'", "''", $password) . "', '" . str_replace("\'", "''", $email) . "', '" . str_replace("\'", "''", $icq) . "', '" . str_replace("\'", "''", $website) . "', '" . str_replace("\'", "''", $occupation) . "', '" . str_replace("\'", "''", $location) . "', '" . str_replace("\'", "''", $interests) . "', '" . str_replace("\'", "''", $signature) . "', '$signature_bbcode_uid', $avatar_sql, $viewemail, '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', '" . str_replace("\'", "''", $yim) . "', '" . str_replace("\'", "''", $msn) . "', $attachsig, $allowsmilies, $allowhtml, $allowbbcode, $allowviewonline, $notifyreply, $notifypm, $popuppm, $user_timezone, '" . str_replace("\'", "''", $user_dateformat) . "', '" . str_replace("\'", "''", $user_lang) . "', $user_style, 0, 1, ";

#
#----- [ REPLACE WITH ] -------------------------------------
#

$sql = "INSERT INTO " . USERS_TABLE . " (user_id, username, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interests, user_sig, user_sig_bbcode_uid, user_avatar, user_avatar_type, user_viewemail, user_aim, user_yim, user_msnm, user_attachsig, user_allowsmile, user_allowhtml, user_allowbbcode, user_allow_viewonline, user_notify, user_notify_pm, user_popup_pm, user_timezone, user_dateformat, user_lang, user_style, user_level, user_allow_pm, user_member_no, user_active, user_actkey)
VALUES ($user_id, '" . str_replace("\'", "''", $username) . "', " . time() . ", '" . str_replace("\'", "''", $password) . "', '" . str_replace("\'", "''", $email) . "', '" . str_replace("\'", "''", $icq) . "', '" . str_replace("\'", "''", $website) . "', '" . str_replace("\'", "''", $occupation) . "', '" . str_replace("\'", "''", $location) . "', '" . str_replace("\'", "''", $interests) . "', '" . str_replace("\'", "''", $signature) . "', '$signature_bbcode_uid', $avatar_sql, $viewemail, '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', '" . str_replace("\'", "''", $yim) . "', '" . str_replace("\'", "''", $msn) . "', $attachsig, $allowsmilies, $allowhtml, $allowbbcode, $allowviewonline, $notifyreply, $notifypm, $popuppm, $user_timezone, '" . str_replace("\'", "''", $user_dateformat) . "', '" . str_replace("\'", "''", $user_lang) . "', $user_style, 0, 1, '$member_no', ";

#
#----- [ FIND ] -------------------------------------
#

$username = htmlspecialchars($userdata['username']);


#
#----- [ ADD AFTER ] -------------------------------------
#

$member_no = htmlspecialchars($userdata['user_member_no']);

#
#----- [ FIND ] -------------------------------------
#

display_avatar_gallery($mode, $avatar_category, $user_id, $email, $current_email, $coppa, $username, $email, $icq, $aim, $msn, $yim, $website, $location, $occupation, $interests, $signature, $viewemail, $notifypm, $popuppm, $notifyreply, $attachsig, $allowhtml, $allowbbcode, $allowsmilies, $allowviewonline, $user_style, $user_lang, $user_timezone, $user_dateformat);

#
#----- [ REPLACE WITH ] -------------------------------------
#

display_avatar_gallery($mode, $avatar_category, $user_id, $email, $current_email, $coppa, $username, $email, $icq, $aim, $msn, $yim, $website, $location, $occupation, $interests, $signature, $viewemail, $notifypm, $popuppm, $notifyreply, $attachsig, $allowhtml, $allowbbcode, $allowsmilies, $allowviewonline, $user_style, $user_lang, $user_timezone, $user_dateformat, $user_member_no);

#
#----- [ FIND ] -------------------------------------
#

$template->assign_vars(array(
'USERNAME' => $username,

#
#----- [ ADD AFTER ] -------------------------------------
#

'MEMBER_NO' => $member_no,

#
#----- [ FIND ] ----------------------------
#

'L_EMAIL_ADDRESS' => $lang['Email_address'],

#
#----- [ ADD AFTER ] -------------------------------------
#

'L_MEMBER_NO' => $lang['member_no'],

#
#----- END OF CHANGES TO usercp_register -------------------------------------
#

#
#----- We now need to change the language file -------------------------------------
#

#
#-----[ OPEN ]------------------------------------------
#
# Remember to do this for every language you support
# It needs translating!!!

phpBB2/language/lang_english/lang_main.php

#
#-----[ FIND ]------------------------------------------
#

//
// Errors (not related to a
// specific failure on a page)
//
$lang['Information'] = "Information";
$lang['Critical_Information'] = "Critical Information";

#
#-----[ ADD, BEFORE ]------------------------------------------
#

//
// Language variables for the new field in user profile
//

$lang['member_no'] = "Member No";

#
#----- Now we need to edit the profile template file so users can add it to their profile ----
#

#
#-----[ OPEN ]------------------------------------------
#
# Remember to do this for every template you support


phpBB2/templates/subSilver/profile_add_body.tpl

#
#-----[ FIND ]------------------------------------------
#

<tr>
<td class="row1"><span class="gen">{L_WEBSITE}:</span></td>
<td class="row2">
<input type="text" class="post"style="width: 200px" name="website" size="25" maxlength="255" value="{WEBSITE}" />
</td>
</tr>


#
#-----[ AFTER, ADD ]------------------------------------------
#
# Note: you want the 10 in maxlength="10" to be the same as the
# field size you specified when adding field to the database!
#

<tr>
<td class="row1"><span class="gen">{L_MEMBER_NO}: </span></td>
<td class="row2">
<input type="text" class="post"style="width: 200px" name="member_no" size="10" maxlength="10" value="{MEMBER_NO}" />
</td>
</tr>


#
#---------- OK, Users can now register with a member no and ---------------
#---------- edit profile to change their member no ------------------------
#


Now we need to view the member number (or whatever the field is) in a variety of places

The first one of these is in the users profile.
#
#--------- Now we need to view the member number (or whatever the field is) in a variety of places
#

#
#-----[ OPEN ]------------------------------------------
#
# This adds the member no ( or whatever the field is) into the users profile
#

phpBB2/includes/usercp_viewprofile.php

#
#-----[ FIND ]------------------------------------------
#

'INTERESTS' => ( $profiledata['user_interests'] ) ? $profiledata['user_interests'] : '&nbsp;',

#
#-----[ ADD AFTER ]------------------------------------------
#

'MEMBER_NO' => ( $member_no ) ? $member_no : '&nbsp;',

#
#-----[ FIND ]------------------------------------------
#

//
// Generate page
//

#
#-----[ BEFORE, ADD ]------------------------------------------
#

$member_no = $profiledata['user_member_no'];

#
#-----[ FIND ]------------------------------------------
#

'L_INTERESTS' => $lang['Interests'],

#
#-----[ ADD AFTER ]------------------------------------------
#

'L_MEMBER_NO' => $lang['member_no'],

#
#-----[ OPEN ]------------------------------------------
#
# Remember to do this for every template you support


phpBB2/templates/subSilver/profile_view_body.tpl

#
#-----[ FIND ]------------------------------------------
#
<tr>
<td valign="middle" align="right" nowrap="nowrap"><span class="gen">{L_JOINED}:&nbsp;</span></td>

#
#-----[ BEFORE, ADD ]----------------------------------------
#

<tr>
<td valign="middle" align="right" nowrap="nowrap"><span class="gen">{L_MEMBER_NO}:&nbsp;</span></td>
<td><b><span class="gen">{MEMBER_NO}</span></b></td>
</tr>

#
#------ Now the member no (or whatever the field is) can be seen in the users profile
#


The next place to view it is in the posts (in info under the avatar)
#
#-----[ OPEN ]------------------------------------------
#
# This inserts real names into the posts

phpBB2/viewtopic.php

#
#-----[ FIND ]------------------------------------------
#

$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid

#
#-----[ REPLACE WITH ]------------------------------------------
#

$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_member_no, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid

#
#-----[ FIND ]------------------------------------------
#

$poster = ( $poster_id == ANONYMOUS ) ? $lang['Guest'] : $postrow[$i]['username'];

#
#-----[ AFTER ADD ]------------------------------------------
#
#-------For real name only to be viewed by admins-------
#

$poster_member_no = ( $userdata['user_level'] == ADMIN ) && ( $postrow[$i]['user_member_no'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['member_no'] . ': ' . $postrow[$i]['user_member_no'] : '';

#
#-----[ OR ]------------------------------------------
#
#-------If you want the real name to be publically viewable-------
#

$poster_member_no = ( $postrow[$i]['user_member_no'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['member_no'] . ': ' . $postrow[$i]['user_member_no'] : '';


#
#-----[ FIND ]------------------------------------------
#

'POSTER_NAME' => $poster,

#
#-----[ AFTER ADD ]------------------------------------------
#

'POSTER_MEMBER_NO' => $poster_member_no,

#
#------ Now the member no (or whatever the field is) can be seen in the posts (under their avatar)
#



#
#-----[ OPEN ]------------------------------------------
#
# Remember to do this for every template you support

phpBB2/templates/subSilver/viewtopic_body.tpl

#
#-----[ FIND ]------------------------------------------
#

<td width="150" align="left" valign="top" class="{postrow.ROW_CLASS}"><span class="name"><a name="{postrow.U_POST_ID}"></a><b>{postrow.POSTER_NAME}</b></span><br /><span class="postdetails">{postrow.POSTER_RANK}<br />{postrow.RANK_IMAGE}{postrow.POSTER_AVATAR}<br /><br />{postrow.POSTER_JOINED}<br />{postrow.POSTER_POSTS}<br />{postrow.POSTER_FROM}</span><br /></td>

#
#-----[ REPLACE WITH ]------------------------------------------
#

<td width="150" align="left" valign="top" class="{postrow.ROW_CLASS}"><span class="name"><a name="{postrow.U_POST_ID}"></a><b>{postrow.POSTER_NAME}</b></span><br /><span class="postdetails">{postrow.POSTER_RANK}<br />{postrow.RANK_IMAGE}{postrow.POSTER_AVATAR}<br /><br />{postrow.POSTER_JOINED}<br />{postrow.POSTER_MEMBER_NO}<br />{postrow.POSTER_POSTS}<br />{postrow.POSTER_FROM}</span><br /></td>

#
#------ Now the member no (or whatever the field is) can be seen in the posts
#

[edit] THE BIT IN BLUE IS CHANGES FROM EARLIER CODE[/edit]
If anyone wants the field viewed in other placess (such as the memberlist then let me know.
Last edited by Rod on Mon Apr 29, 2002 9:22 pm, edited 2 times in total.
Rod [aka Kinger]
Dogs have owners, but cats have staff!

Mods
'Real Name' Mod here. Discussion here.
'Date/Time Last Visited' Mod here. Discussion here.
sunlord
Registered User
Posts: 66
Joined: Wed Jan 16, 2002 5:28 am

Post by sunlord »

Thank you!!! You just saved me alot of trouble ^_^
desean84
Registered User
Posts: 205
Joined: Thu Jan 03, 2002 8:53 am
Location: Singapore

Re: [DEV] Extra field in user information

Post by desean84 »

Rod wrote: If anyone wants the field viewed in other placess (such as the memberlist then let me know.


great mod!

also, how do i...
  • make it display in the memberlist
  • make it display in the usergroup control panel
  • make it display under the username in topic view (where the Rank title, "Joined:...", "Post:..." & "Location:..." is)
  • make it viewable only to the admins in the memberlist, topic view, usergroup control panel & profile view
  • (finally.. i know this could be tough...) make it viewable only to the respective group moderators in the memberlist, topic view, usergroup control panel & profile view. group moderators can only see their members' but not others.
User avatar
Rod
Registered User
Posts: 232
Joined: Sun Dec 02, 2001 7:29 pm
Location: my chair, beside desk, in lounge, upstairs, in house, close to Farnham, just South of London, UK ...
Contact:

Re: [DEV] Extra field in user information

Post by Rod »

desean84 wrote: great mod!

also, how do i...
  • make it display in the memberlist
  • make it display in the usergroup control panel
  • make it display under the username in topic view (where the Rank title, "Joined:...", "Post:..." & "Location:..." is)
  • make it viewable only to the admins in the memberlist, topic view, usergroup control panel & profile view
  • (finally.. i know this could be tough...) make it viewable only to the respective group moderators in the memberlist, topic view, usergroup control panel & profile view. group moderators can only see their members' but not others.


Most of these are fairly straightforward.

It should already be showing in Viewtopic - directly above the bit that says joined: xxxxx. That is done by the 3rd of the 3 sections in my post above.

To be viewable by admins only
For viewing profile find this bit in usercp_viewprofile.php:

Code: Select all

# 
#-----[ FIND ]------------------------------------------ 
# 

// 
// Generate page 
// 

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
# 

$member_no = $profiledata['user_member_no']; 
and instead of adding that add the following:

Code: Select all

if($userdata['user_level'] == ADMIN)
{
	$member_no = $profiledata['user_member_no'];
}
else
{
	$member_no = 'WITHELD';
}
I use the witheld but if you just want it blank then delet the WITHELD to just leave ''


For viewtopic page find this bit in viewtopic.php:

Code: Select all

# 
#-----[ FIND ]------------------------------------------ 
# 

$poster = ( $poster_id == ANONYMOUS ) ? $lang['Guest'] : $postrow[$i]['username']; 

# 
#-----[ AFTER ADD ]------------------------------------------ 
# 

$poster_member_no = $postrow[$i]['user_member_no']; 
and instead of adding that add

Code: Select all

if($userdata['user_level'] == ADMIN)
{
	$poster_member_no = $postrow[$i]['user_member_no'];
}
else
{
		$poster_member_no = '';
}
Again you can either leave it blank or use WITHELD or somthing similar!

You can probably recognise the way to make only admins view somthing by now! It's easy so long as you remember to do it in the php file (NOT any tpl files)

It's 3.30 in the morning hre so I need some sleep.

I'll post how to do the other boits tomorrow.
Rod [aka Kinger]
Dogs have owners, but cats have staff!

Mods
'Real Name' Mod here. Discussion here.
'Date/Time Last Visited' Mod here. Discussion here.
desean84
Registered User
Posts: 205
Joined: Thu Jan 03, 2002 8:53 am
Location: Singapore

Post by desean84 »

thanks... have a great sleep first... :P

i'm looking forward to the remaining parts... :wink:
User avatar
Rod
Registered User
Posts: 232
Joined: Sun Dec 02, 2001 7:29 pm
Location: my chair, beside desk, in lounge, upstairs, in house, close to Farnham, just South of London, UK ...
Contact:

View the field in memberlist

Post by Rod »

OK to view the field in the memberlist:

firstly you need to edit phpBB/memberlist.php:

Code: Select all

# # 
#-----[ OPEN ]------------------------------------------ 
#
#	This adds the real name into memberlist beside their username - only admins see it
#

phpBB2/memberlist.php

# 
#-----[ FIND ]------------------------------------------ 
#

$sql = "SELECT username, user_id, user_viewemail, user_posts, user_regdate, user_from, user_website, user_email, user_icq, user_aim, user_yim, user_msnm, user_avatar, user_avatar_type, user_allowavatar 

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#

$sql = "SELECT username, user_id, user_member_no, user_viewemail, user_posts, user_regdate, user_from, user_website, user_email, user_icq, user_aim, user_yim, user_msnm, user_avatar, user_avatar_type, user_allowavatar 

# 
#-----[ FIND ]------------------------------------------ 
#

		$username = $row['username'];

# 
#-----[ AFTER ADD ]------------------------------------------ 
#
#-------For real name only to be viewed by admins-------
#

	if($userdata['user_level'] == ADMIN)
{
	$member_no = $row['user_member_no'];
}
else
{
	$member_no = "";
}

# 
#-----[ OR ]------------------------------------------ 
#
#-------If you want the real name to be publically viewable-------
#

	$member_no = $row['user_member_no'];


# 
#-----[ FIND ]------------------------------------------ 
#

			'POSTS' => $posts,

# 
#-----[ AFTER ADD ]------------------------------------------ 
#

			'MEMBER_NO' => $member_no,

# 
#-----[ FIND ]------------------------------------------ 
#

	'L_POSTS' => $lang['Posts'], 

# 
#-----[ AFTER ADD ]------------------------------------------ 
#

	'L_MEMBER_NO' => $lang['member_no'],
Then you need to edit phpBB2/templates/******/memberlist_body.tpl for every template you support.

Code: Select all

# 
#-----[ OPEN ]------------------------------------------ 
#
# Remember to do this for every template you support

phpBB2/templates/subSilver/memberlist_body.tpl

# 
#-----[ FIND ]------------------------------------------ 
#

	  <th class="thTop" nowrap="nowrap">{L_USERNAME}</th>

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#

	  <th class="thTop" nowrap="nowrap">{L_MEMBER_NO}</th>


# 
#-----[ FIND ]------------------------------------------ 
#

	  <td class="{memberrow.ROW_CLASS}" align="center"><span class="gen"><a href="{memberrow.U_VIEWPROFILE}" class="gen">{memberrow.USERNAME}</a></span></td>

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#

	  <td class="{memberrow.ROW_CLASS}" align="center" valign="middle"><span class="gensmall">{memberrow.MEMBER_NO}</span></td>

# 
#-----[ FIND ]------------------------------------------ 
#

<td class="catbottom" colspan="8" height="28">&nbsp;</td>

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
# Here the colspan has been changed so it looks better,
# if other mods are installed you might neeed a higher colspan!

<td class="catbottom" colspan="9" height="28">&nbsp;</td>
REMEMBER TO CHANGE EVERY INSTANCE OF member_no and MEMBER_NO TO WHATEVER YOUR FIELD IS CALLED

[edited to add the chanfge to the colspan purely so it looks nicer!!]
Last edited by Rod on Sun Apr 14, 2002 11:34 am, edited 2 times in total.
Rod [aka Kinger]
Dogs have owners, but cats have staff!

Mods
'Real Name' Mod here. Discussion here.
'Date/Time Last Visited' Mod here. Discussion here.
User avatar
Rod
Registered User
Posts: 232
Joined: Sun Dec 02, 2001 7:29 pm
Location: my chair, beside desk, in lounge, upstairs, in house, close to Farnham, just South of London, UK ...
Contact:

Post by Rod »

Looking again at that you might not like the way it looks if you have the field set so only admins can see it as for anyone else it leaves an empty column in the memberlist.
Have a look at my test forum at www.ripleycc.com/test_forum

There is another way to do it if it's set to admin to view only.

On my main forums I use a real name which is only viewable by admins so I put it in brackets after the username.

Here's how I do it:
Instead of the alterations to memberlist_body shown above do this:

Code: Select all

# 
#-----[ OPEN ]------------------------------------------ 
#
# Remember to do this for every template you support

phpBB2/templates/subSilver/memberlist_body.tpl

# 
#-----[ FIND ]------------------------------------------ 
#

	  <td class="{memberrow.ROW_CLASS}" align="center"><span class="gen"><a href="{memberrow.U_VIEWPROFILE}" class="gen">{memberrow.USERNAME}</a></span></td>

# 
#-----[ REPLACE WiTH]------------------------------------------ 
#

	  <td class="{memberrow.ROW_CLASS}" align="center"><span class="gen"><a href="{memberrow.U_VIEWPROFILE}" class="gen">{memberrow.USERNAME}</a></span>&nbsp;&nbsp;&nbsp;<span class="gensmall"><i>{memberrow.MEMBER_NO}</i></span></td>
Rod [aka Kinger]
Dogs have owners, but cats have staff!

Mods
'Real Name' Mod here. Discussion here.
'Date/Time Last Visited' Mod here. Discussion here.
desean84
Registered User
Posts: 205
Joined: Thu Jan 03, 2002 8:53 am
Location: Singapore

Re: [DEV] Extra field in user information

Post by desean84 »

desean84 wrote: also, how do i...
  • (finally.. i know this could be tough...) make it viewable only to the respective group moderators in the memberlist, topic view, usergroup control panel & profile view. group moderators can only see their members' but not others.

wow! this is very comprehensive, thanks a lot!

makeing the field display in the usergroup control panel will be similar to the memberlist right?

what about setting permission for group moderators? is it possible?
User avatar
Rod
Registered User
Posts: 232
Joined: Sun Dec 02, 2001 7:29 pm
Location: my chair, beside desk, in lounge, upstairs, in house, close to Farnham, just South of London, UK ...
Contact:

Post by Rod »

Just made a change to how it's viewed in viewtopic

Put changed code (new) in blue in first post.

I've changed

Code: Select all

$poster_member_no = $postrow[$i]['user_member_no'];
To

Code: Select all

# 
#-----[ AFTER ADD ]------------------------------------------ 
#
#-------For real name only to be viewed by admins-------
#

	$poster_member_no = ( $userdata['user_level'] == ADMIN ) && ( $postrow[$i]['user_member_no'] && $postrow[$i]['user_id'] != ANONYMOUS )  ? $lang['member_no'] . ': ' . $postrow[$i]['user_member_no'] : '';

# 
#-----[ OR ]------------------------------------------ 
#
#-------If you want the real name to be publically viewable-------
#

	$poster_member_no = ( $postrow[$i]['user_member_no'] && $postrow[$i]['user_id'] != ANONYMOUS )  ? $lang['member_no'] . ': ' . $postrow[$i]['user_member_no'] : '';
#

It'lkl be better as it will now only show if there is somthing in the field!
Rod [aka Kinger]
Dogs have owners, but cats have staff!

Mods
'Real Name' Mod here. Discussion here.
'Date/Time Last Visited' Mod here. Discussion here.
User avatar
Rod
Registered User
Posts: 232
Joined: Sun Dec 02, 2001 7:29 pm
Location: my chair, beside desk, in lounge, upstairs, in house, close to Farnham, just South of London, UK ...
Contact:

Re: [DEV] Extra field in user information

Post by Rod »

desean84 wrote: wow! this is very comprehensive, thanks a lot!

makeing the field display in the usergroup control panel will be similar to the memberlist right?


Yes, I've not yet tried it but it's likely to be :

Change groupcp.php similar to memberlist.php
change groupcp_info_body.tpl similar to memberlist_body.tpl

Let me know if you have probs as I need to do this for my site anyway so will be doing it.
desean84 wrote:
desean84 wrote:also, how do i...
  • (finally.. i know this could be tough...) make it viewable only to the respective group moderators in the memberlist, topic view, usergroup control panel & profile view. group moderators can only see their members' but not others.

What about setting permission for group moderators? is it possible?

I'm looking into this andf will get back to you.
I'm onto this - will get back to you.
Rod [aka Kinger]
Dogs have owners, but cats have staff!

Mods
'Real Name' Mod here. Discussion here.
'Date/Time Last Visited' Mod here. Discussion here.
User avatar
Rod
Registered User
Posts: 232
Joined: Sun Dec 02, 2001 7:29 pm
Location: my chair, beside desk, in lounge, upstairs, in house, close to Farnham, just South of London, UK ...
Contact:

Post by Rod »

It's done VERY differently for the usergroups. I've worked it out but I'm still getting some errors so need to tidy things up.

[edit] OK I had a stupidity leak. I left out a , :oops:

But I still cannot make it only viewable by admin OR group mod.

The usual code for this doesn't seem to work! :cry:
Rod [aka Kinger]
Dogs have owners, but cats have staff!

Mods
'Real Name' Mod here. Discussion here.
'Date/Time Last Visited' Mod here. Discussion here.
User avatar
Klaus2000
Registered User
Posts: 67
Joined: Sat Apr 06, 2002 2:19 pm
Location: somewhere in nowhere in good old Germany ;-)
Contact:

Post by Klaus2000 »

Hello Rod,

looks great......phantastic work!
Saw it in your forum.
But I am still an newbie also about SQL and i didn´t manage to create the user_member_no in the table......
Rocketeer
Registered User
Posts: 108
Joined: Thu Sep 06, 2001 11:43 pm
Location: Coventry, UK
Contact:

Post by Rocketeer »

When you do the SQL query to add the member_no field, remember to inlcude the table prefix for your site, for example
ALTER TABLE phpBB_users ADD user_member_no VARCHAR (10)



Rod - would it be possible to tell us the code for putting the field in the Admin control panel, so that the site Admin could edit it? I'm thinking of doing an Admin editable only field for my users...
User avatar
Klaus2000
Registered User
Posts: 67
Joined: Sat Apr 06, 2002 2:19 pm
Location: somewhere in nowhere in good old Germany ;-)
Contact:

Post by Klaus2000 »

Ok - i did:

but there stands:

SQL-query : [Edit]
ALTER TABLE `db4711`.`phpbb_users` ADD `user_member_no` VARCHAR(10) NOT NULL;

Correct?
User avatar
Rod
Registered User
Posts: 232
Joined: Sun Dec 02, 2001 7:29 pm
Location: my chair, beside desk, in lounge, upstairs, in house, close to Farnham, just South of London, UK ...
Contact:

Post by Rod »

Rocketeer wrote: Rod - would it be possible to tell us the code for putting the field in the Admin control panel, so that the site Admin could edit it? I'm thinking of doing an Admin editable only field for my users...

OK the code for the admin section is here. It relies on the database having been altered and also on the bits put into the language file. If you want to have the field to be only changed by an admin then try not altering profile_add_body.tpl or usercp_profile.php. I've not tried this myself but it should still work.

Code: Select all

#
#----- [ OPEN ] -------------------------------------
#

phpBB2/admin/admin_users.php

#
#----- [ FIND ] -------------------------------------
#

			$sql = "UPDATE " . USERS_TABLE . "
					SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) . "', user_icq = '" . str_replace("\'", "''", $icq) . "', user_website = '" . str_replace("\'", "''", $website) . "', user_occ = '" . str_replace("\'", "''", $occupation) . "', user_from = '" . str_replace("\'", "''", $location) . "', user_interests = '" . str_replace("\'", "''", $interests) . "', user_sig = '" . str_replace("\'", "''", $signature) . "', user_viewemail = $viewemail, user_aim = '" . str_replace("\'", "''", $aim) . "', user_yim = '" . str_replace("\'", "''", $yim) . "', user_msnm = '" . str_replace("\'", "''", $msn) . "', user_attachsig = $attachsig, user_sig_bbcode_uid = '$signature_bbcode_uid', user_allowsmile = $allowsmilies, user_allowhtml = $allowhtml, user_allowavatar = $user_allowavatar, user_allowbbcode = $allowbbcode, user_allow_viewonline = $allowviewonline, user_notify = $notifyreply, user_allow_pm = $user_allowpm, user_notify_pm = $notifypm, user_popup_pm = $popuppm, user_lang = '" . str_replace("\'", "''", $user_lang) . "', user_style = $user_style, user_timezone = $user_timezone, user_dateformat = '" . str_replace("\'", "''", $user_dateformat) . "', user_active = $user_status, user_rank = $user_rank" . $avatar_sql . "


#
#----- [ REPLACE WITH ] -------------------------------------
#

$sql = "UPDATE " . USERS_TABLE . "
					SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) . "', user_icq = '" . str_replace("\'", "''", $icq) . "', user_website = '" . str_replace("\'", "''", $website) . "', user_occ = '" . str_replace("\'", "''", $occupation) . "', user_from = '" . str_replace("\'", "''", $location) . "', user_interests = '" . str_replace("\'", "''", $interests) . "', user_sig = '" . str_replace("\'", "''", $signature) . "', user_viewemail = $viewemail, user_aim = '" . str_replace("\'", "''", $aim) . "', user_yim = '" . str_replace("\'", "''", $yim) . "', user_msnm = '" . str_replace("\'", "''", $msn) . "', user_attachsig = $attachsig, user_sig_bbcode_uid = '$signature_bbcode_uid', user_allowsmile = $allowsmilies, user_allowhtml = $allowhtml, user_allowavatar = $user_allowavatar, user_allowbbcode = $allowbbcode, user_allow_viewonline = $allowviewonline, user_notify = $notifyreply, user_allow_pm = $user_allowpm, user_notify_pm = $notifypm, user_popup_pm = $popuppm, user_lang = '" . str_replace("\'", "''", $user_lang) . "', user_style = $user_style, user_timezone = $user_timezone, user_dateformat = '" . str_replace("\'", "''", $user_dateformat) . "', user_active = $user_status, user_rank = $user_rank" . $avatar_sql . ", user_member_no = '" . str_replace("\'", "''", $member_no) . "'


#
#----- [ FIND ] -------------------------------------
#

		$username = ( !empty($HTTP_POST_VARS['username']) ) ? trim(strip_tags( $HTTP_POST_VARS['username'] ) ) : '';


#
#----- [ ADD AFTER ] -------------------------------------
#

 		$member_no = ( !empty($HTTP_POST_VARS['member_no']) ) ? trim(strip_tags( $HTTP_POST_VARS['member_no'] ) ) : '';

#
#----- [ FIND ] -------------------------------------
#

		validate_optional_fields($icq, $aim, $msn, $yim, $website, $location, $occupation, $interests, $signature);

#
#----- [ RePLACE WITH ] -------------------------------------
#

		validate_optional_fields($icq, $aim, $msn, $yim, $website, $location, $occupation, $interests, $signature, $member_no);

#
#----- [ FIND ] -------------------------------------
#
#	There are 2 instances of this. Do it for both!

			$username = stripslashes($username);


#
#----- [ ADD AFTER ] -------------------------------------
#

			$member_no = stripslashes($member_no);

#
#----- [ FIND ] -------------------------------------
#

		$username = $this_userdata['username'];


#
#----- [ ADD AFTER ] -------------------------------------
#

		$member_no = $this_userdata['user_member_no'];


#
#----- [ FIND ] -------------------------------------
#


			$s_hidden_fields .= '<input type="hidden" name="username" value="' . str_replace("\"", """, $username) . '" />';

#
#----- [ ADD AFTER ] -------------------------------------
#

			$s_hidden_fields .= '<input type="hidden" name="member_no" value="' . str_replace("\"", """, $member_no) . '" />';

#
#----- [ FIND ] -------------------------------------
#

$template->assign_vars(array( 
      'USERNAME' => $username, 

#
#----- [ ADD AFTER ] -------------------------------------
#

      'MEMBER_NO' => $member_no, 


#
#----- [ FIND ] ----------------------------
#

		'L_EMAIL_ADDRESS' => $lang['Email_address'],

#
#----- [ ADD AFTER ] -------------------------------------
#

		'L_MEMBER_NO' => $lang['member_no'],

#
#----- END OF CHANGES TO admin_users.php -------------------------------------
#
	
# 
#-----[ OPEN ]------------------------------------------ 
#	This section puts the entry field into admin editing pofile.
#
# Remember to do this for every template you support

# I put it after the username because the one I'm using is for real names.
# You might prefer to put it later on.


phpBB2/templates/subSilver/admin/user_edit_body.tpl

# 
#-----[ FIND ]------------------------------------------ 
#

	<tr> 
	<td class="row1" width="38%"><span class="gen">{L_USERNAME}: *</span></td>
	<td class="row2"><input type="text" class="post" style="width:200px" name="username" size="25" maxlength="40" value="{USERNAME}" /></td>
	</tr>


# 
#-----[ AFTER ADD ]------------------------------------------ 
#
#

	<tr> 
	  <td class="row1"><span class="gen">{L_MEMBER_NO}: </span></td>
	  <td class="row2"> 
		<input type="text" class="post"style="width: 200px"  name="member_no" size="25" maxlength="50" value="{MEMBER_NO}" />
	  </td>
	</tr>
REMEMBER TO BACK UP ALL FILES BEFORE EDITING THEM!!!
Rod [aka Kinger]
Dogs have owners, but cats have staff!

Mods
'Real Name' Mod here. Discussion here.
'Date/Time Last Visited' Mod here. Discussion here.
Post Reply

Return to “[2.0.x] MODs in Development”