Gender Permissions

Started by Xarcell, June 09, 2005, 09:39:57 PM

Previous topic - Next topic

Xarcell

I woud like to restrict certain boards by gender. I think is something that show be added.

Just an idea.

dtm.exe

Umm, sexist?  Just kidding :).  Are there like, boards for girls and guys?

-Dan The Man

Xarcell

Well, lets say you have an advice forum. So people want it to be gendar related by catagory only.

Some catagories are for all genders, while some should be restricted. You could do group premissions, but if you have alotta pep's joining, it's hard to keep up with.


Owdy

Whats the point?  You can change gender from profile easily. :)
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Xarcell


DaCoder53

Quote from: Owdy on June 10, 2005, 04:21:26 PM
Whats the point?  You can change gender from profile easily. :)

I'm also looking for an answer as to how to restrict board access by gender. As for the above, that's easily solved by:

a) Requiring the gender as part of the registration.

b) Removing the option to change it.

So, to reiterate:

How would you add such a permission on a board by board basis?  ???

DaCoder53

#6
Quote from: DaCoder53 on December 27, 2005, 05:09:00 PM
Quote from: Owdy on June 10, 2005, 04:21:26 PM
Whats the point?  You can change gender from profile easily. :)

I'm also looking for an answer as to how to restrict board access by gender. As for the above, that's easily solved by:

a) Requiring the gender as part of the registration.

b) Removing the option to change it.

So, to reiterate:

How would you add such a permission on a board by board basis?  ???


Well, as no one had any solutions or suggestions, I rolled my own.  ;D

This may not be the best way to do this but the mods seem to work so far in testing. All users are required to furnish their gender at registration and can not directly change their gender setting. (If they need to (ie: they entered the wrong one, they'll be required to provided proof of their gender via photo and a sign matching a code phrase sent to them when they make the request.)

So basically the methodology is to collect the gender at registration. When the user activates the account and all sorts of other settings are being updated, the code adds the appropriate additional membergroup ID to the user's record (which at this time has no additional membergroups set). Then, on boards that need a gender restriction, you just disallow the appropriate group. In theory, one could extend this along sexual orientation lines so that even finer granularity of boards would be possible if desired.

Comments on the code would be appreciated!

As mentioned elsewhere, adding Gender to the registration process is easy:

In Register.template.php change:

</tr><tr>
<td width="40%">
<b>', $txt[82], ':</b>
</td>
<td>
<input type="password" name="passwrd2" size="30" tabindex="', $context['tabindex']++, '" />
</td>
</tr>';


to:


</tr><tr>
<td width="40%">
<b>', $txt[82], ':</b>
</td>
<td>
<input type="password" name="passwrd2" size="30" tabindex="', $context['tabindex']++, '" />
</td>
</tr>
</tr><tr>
<td width="40%">
<b>Gender:</b>
</td>
<td>
<input type="radio" name="gender" value="1" checked="checked"/> Male<br />
<input type="radio" name="gender" value="2" /> Female<br />
</td>
</tr>';


Next set up two new membergroups, one for your male members, the other for your female members and note their IDs.

Now we'll have the user's additional membergroups initialized when they (or you) activate their account. (Obviously this mod does require some form of activation...)

In Register.php change:

// Validation complete - update the database!
updateMemberData($row['ID_MEMBER'], array('is_activated' => 1, 'validation_code' => '\'\''));



to the following, substituting the male and female group IDs appropriately:
(e.g.: If the male group ID is 10 replace {Male ID} with "'10'" including both sets of quotes.)

// Validation complete - update the database!
updateMemberData($row['ID_MEMBER'], array('is_activated' => 1, 'validation_code' => '\'\''));

if ($row['gender'] == 1)
{
updateMemberData($row['ID_MEMBER'], array('additionalGroups' => {Male ID}));
}
else
{
updateMemberData($row['ID_MEMBER'], array('additionalGroups' => {Female ID});
}



Now we make it so only the admin can change gender info:

In Profile.template.php change:

</tr><tr>
<td width="40%"><b>', $txt[227], ': </b></td>
<td><input type="text" name="location" size="50" value="', $context['member']['location'], '" /></td>
</tr>
<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>';


to

</tr><tr>
<td width="40%"><b>', $txt[227], ': </b></td>
<td><input type="text" name="location" size="50" value="', $context['member']['location'], '" /></td>
</tr>';
//this guy is an admin!
if ($context['user']['is_admin'])
{
echo '
<tr>
<td width="40%"><b>', $txt[231], ': </b></td>
<td>
<select name="gender" size="1">
<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>';


Enjoy!


DaCoder53

More or less, I need to do a fresh diff to get all the correct changes. Give a couple of days as I'm up to my neck in alligators right now...


DaCoder53

Ok, just ran a diff and all of it is the same except for Register.php

Changes to Register.php for 1.1rc2 for automatic gender membergroups
Line 318
Old:
SELECT ID_MEMBER, validation_code, memberName, realName, emailAddress, is_activated, passwd
New:
SELECT ID_MEMBER, validation_code, memberName, realName, emailAddress, is_activated, passwd, gender

Line 400
Old:
// Validation complete - update the database!
updateMemberData($row['ID_MEMBER'], array('is_activated' => 1, 'validation_code' => '\'\''));

New:
// Validation complete - update the database!
updateMemberData($row['ID_MEMBER'], array('is_activated' => 1, 'validation_code' => '\'\''));
// This is the code to put them in the appropriate gender membergroup change the values accordingly
if ($row['gender'] == 1)
{
updateMemberData($row['ID_MEMBER'], array('additionalGroups' => {MaleGroupID}));
}
else
{
updateMemberData($row['ID_MEMBER'], array('additionalGroups' => {FemaleGroupID}));
}



The key difference is in line 318, you have get the gender data or things just don't work right.  ;)

kadhumia_flo

thanks for the code... i made one for myself...

Well what it does,, i edited BoardIndex.template.php and made it that if boardid is the board id for the board for one gender only , dont show unless the person has a gender :D

if u want me to tellu how, just ask :)

DaCoder53

Quote from: kadhumia_flo on March 16, 2006, 03:27:59 PM
thanks for the code... i made one for myself...

Well what it does,, i edited BoardIndex.template.php and made it that if boardid is the board id for the board for one gender only , dont show unless the person has a gender :D

if u want me to tellu how, just ask :)

You're welcome! Even though I don't need it the way I have it set up, why don't you go ahead and post it in case someone else does?  :)

True Knight

Quote from: kadhumia_flo on March 16, 2006, 03:27:59 PM
thanks for the code... i made one for myself...

Well what it does,, i edited BoardIndex.template.php and made it that if boardid is the board id for the board for one gender only , dont show unless the person has a gender :D

if u want me to tellu how, just ask :)

Please tell...I'm asking!

kadhumia_flo

Hello.. This is no mod... and i think u shud test on a separate template first, preferbly on default duplicate

BoardIndex.template.php
Find
global $context, $settings, $options, $txt, $scripturl, $modSettings;

Add After

// Go to MYSQL Database, and see what gender the logged on member is using
$result = mysql_query("SELECT gender FROM backup_smf_members WHERE ID_MEMBER = {$context['user']['id']};");
if (!$result) {
   die('Invalid query: ' . mysql_error());
}
while ($row = mysql_fetch_assoc($result)) {
$gender=$row['gender']; }




Find:
foreach ($category['boards'] as $board){

Add After - 4 numbers to edit are (48, 48, 49, 49) <-- YOU SHOULD EDIT 4 OF THEM AT LEAST
$show=0;
// Dont show the board if it is one of the board ID's , except to the conditions
include('SSI.php');
// Admin will always see the board
if ($context['allow_admin']) $show=1;

// Gender 1 means Male , 2 means Female - in the example below, board 48 is restriced to Females, and board 49 to Males
if($board['id']==49 and $gender==2) $show=1;
if($board['id']==48 and $gender==1) $show=1;
// If the boards arent board 48 or 49 , just show it
if($board['id']==48|$board['id']==49) { } else { $show=1; }
if($show==1) {




Find:
echo '
</table>';
}
echo '
</div>';
}

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


Add Before
}


Mabey i forgot something.. SO PLEASE DO THIS ON A TEST THEME,,, if u dont know how to do this ASK........

anyway, enjoy it, and also some credit for Emacik

True Knight

I can find everything to edit, except for that last part. Adding the "{"

It appears my BoardIndexTemplate.php is a bit different or has been modified.

True Knight

Never mind...It works now!


waremock

How would I go about making a package for this mod?

kadhumia_flo

I would really like to make a package for my mod, but i dont know how to

Advertisement: