News:

SMF 2.1.6 has been released! Take it for a spin! Read more.

Main Menu

"Edit Once" Profile Field

Started by Alex4108, March 13, 2012, 09:00:52 AM

Previous topic - Next topic

Alex4108

Hey SMF,

I wanted to see if it's possible, to make it so users can only edit a custom profile field once.
I operate a video game clan, and we have a ban list.  Due to the nature of some things, we wanted to keep the ban list restricted so you can only see your own bans. 

Our ban list page shows your bans based on a custom profile field you fill in.  The problem is, people can change the profile field to match somebody else's username or ID, and then boom, they see their own bans.

So again, I wanted to know if there's a way to "lock" a profile field after it's first edit.

Possible method
Near line 1336 of Profile.template.php

foreach ($context['custom_fields'] as $field)
{
if ($field['name'] == "lockedfield1" || $field['name'] == "lockedfield1" && $context['user']['is_admin'])
  // Allow Edit
elseif ($field['name'] == "lockedfield1" ||   $field['name'] == "lockedfield1" && !$context['user']['is_admin'])
// Just show it, no editing
else
// Show it, allow edit, it's not locked!
}


Would the above method be practical? 

Final Product
Profile.template.php
Near line 1366, replace the foreach loop with this:

foreach ($context['custom_fields'] as $field)
{
//var_dump($field);
// Locked fields name array
$lockedFields = array('STEAM ID', 'Minecraft Username', 'Teamspeak ID', 'APB: Reloaded Username (Colby)', 'APB: Reloaded Username (Joker)', 'AA3 Soldier Name', 'APB: Reloaded Car Number (Colby)', 'APB: Reloaded Car Number (Joker)');
if (in_array($field['name'], $lockedFields) && ($context['user']['is_admin']))
echo '
<dt>
<strong>', $field['name'], ': </strong><br />
<span class="smalltext">', $field['desc'], ($field['desc'] !== "") ? '<br /><font color="red">This is a <b>locked</b> field.  You can only edit it once!</font>' : '<font color="red">This is a <b>locked</b> field.  You can only edit it once!</font>' ,' </span>
</dt>
<dd>
', $field['input_html'], '
</dd>';
elseif (in_array($field['name'], $lockedFields) && ($context['user']['is_admin']))
echo '
<dt>
<strong>', $field['name'], ': </strong><br />
<span class="smalltext">', $field['desc'], '</span>
</dt>
<dd>
', $field['value'], '
</dd>';
else
echo '
<dt>
<strong>', $field['name'], ': </strong><br />
<span class="smalltext">', $field['desc'], (in_array($field['name']) && ($field['desc'] !== "")) ? '<font color="red">This is a <b>locked</b> field.  You can only edit it once!</font>' : '', '</span>
</dt>
<dd>
', $field['input_html'], '
</dd>';
}

Advertisement: