Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: ***Teh GodFather*** on August 12, 2007, 10:16:55 PM

Title: Disable gender change
Post by: ***Teh GodFather*** on August 12, 2007, 10:16:55 PM
Where is option for gender changing?
I want to make possible only for admin to change members gender..
Title: Re: Disable gender change
Post by: karlbenson on August 12, 2007, 10:21:18 PM
As far as I'm aware there isnt.
You'll probably need to request it as a mod.
Title: Re: Disable gender change
Post by: ***Teh GodFather*** on August 12, 2007, 10:28:37 PM
There must be some code which controls this...
Title: Re: Disable gender change
Post by: karlbenson on August 12, 2007, 10:30:53 PM
There isnt a setting to enable/disable it because if smf had a setting for every little option, it would become very bloated.
It would be best as a mod because very few smf sites use the 'gender information'.

You'd probably have to modify the profile.template.php to not show the profile gender field unless your an admin.
Title: Re: Disable gender change
Post by: ***Teh GodFather*** on August 12, 2007, 10:33:45 PM
I know that, but i cant find what to change, i cant see that code...
Title: Re: Disable gender change
Post by: karlbenson on August 12, 2007, 10:40:18 PM
around like 1412 of profile.template.php


<select name="gender" size="1">
<option value="0"></option>
<option value="1"', ($context['member']['gender']['name'] == 'm' ? ' selected="selected"' : ''), '>', $txt[238], '</option>
<option value="2"', ($context['member']['gender']['name'] == 'f' ? ' selected="selected"' : ''), '>', $txt[239], '</option>
</select>
Title: Re: Disable gender change
Post by: ***Teh GodFather*** on August 12, 2007, 10:48:15 PM
And to change with what to allow only admins to change it?
Title: Re: Disable gender change
Post by: karlbenson on August 12, 2007, 10:58:01 PM
Ok, I've just tested this on a clean install.
The gender options only show up if the user browsing is an admin OR if the user doesnt have a gender already set. (once they set a gender it will disappear)

(you will need to perform this modification on any themes which have custom Profile.template.php's

FIND (1409 - 1420 in clean install) in Profile.template.php

<tr>
<td width="40%"><b>', $txt[231], ': </b></td>
<td>
<select name="gender" size="1">
<option value="0"></option>
<option value="1"', ($context['member']['gender']['name'] == 'm' ? ' selected="selected"' : ''), '>', $txt[238], '</option>
<option value="2"', ($context['member']['gender']['name'] == 'f' ? ' selected="selected"' : ''), '>', $txt[239], '</option>
</select>
</td>
</tr><tr>
<td colspan="2"><hr width="100%" size="1" class="hrcolor" /></td>
</tr>';


REPLACE WITH


';
// SHOW GENDER ONLY IF NOT SET OR USER VIEWING PROFILE IS ADMIN
if($context['user']['is_admin'] || empty($context['member']['gender']['name'])) {
echo ' <tr>
<td width="40%"><b>', $txt[231], ': </b></td>
<td>

<select name="gender" size="1">
<option value="0"></option>
<option value="1"', ($context['member']['gender']['name'] == 'm' ? ' selected="selected"' : ''), '>', $txt[238], '</option>
<option value="2"', ($context['member']['gender']['name'] == 'f' ? ' selected="selected"' : ''), '>', $txt[239], '</option>
</select>
</td>
</tr>
';
}
echo '
<tr>
<td colspan="2"><hr width="100%" size="1" class="hrcolor" /></td>
</tr>';
Title: Re: Disable gender change
Post by: ***Teh GodFather*** on August 13, 2007, 01:26:48 PM
Dont work...
All members can change...
Title: Re: Disable gender change
Post by: Kirby on August 13, 2007, 01:31:59 PM
In that code, change

if($context['user']['is_admin'] || empty($context['member']['gender']['name']))

to

if($context['user']['is_admin'])

if you ONLY want admins to add or change it....

or

if($context['user']['is_admin'] || $context['member']['gender']['name'] == '')

if you want members to set it but only admins can CHANGE it after...

Keep in mind, however, that somebody smart can use an extension for their browser to alter the post data and add in a gender field. You might want to look into a mod into Profile.php itself to protect from this.
Title: Re: Disable gender change
Post by: ***Teh GodFather*** on August 13, 2007, 01:47:37 PM
Quote from: Kirby on August 13, 2007, 01:31:59 PM
You might want to look into a mod into Profile.php itself to protect from this.

I dont understand what you mean with this...
Title: Re: Disable gender change
Post by: Kirby on August 13, 2007, 01:53:50 PM
Here, look for (Profile.php):

'gender' => array(
'name' => empty($_POST['gender']) ? '' : ($_POST['gender'] == 2 ? 'f' : 'm')
),

Replace with:

'gender' => array(
'name' => ($context['user']['is_admin'] || empty($user_profile[$_REQUEST['userID']]['gender']) ? (empty($_POST['gender']) ? '' : ($_POST['gender'] == 2 ? 'f' : 'm')) : '')
),

This will give you an additional layer of security.