UBB.Dev
Posted By: whk Selectively hiding custom fields profile display - 01/16/2009 3:52 AM
This was posted on the UBB Central forum but probably better suited for this forum.

I'm making "Custom Field 1" the location where I will store the link to an external database record for the user who registers. I'd like to make it so this field is only visible by the individual user who is logged in, and Administrators. The record it links to has personal data that I don't want visible to the world or other users.

I found the file showprofile.tpl and deleted {$CUSTOM_FIELD_1} near the end of the script to prevent it from displaying as a temporary work around. Can somebody tell me what the code is so I can replace this:

{$CUSTOM_FIELD_1}
{$CUSTOM_FIELD_2}
{$CUSTOM_FIELD_3}
{$CUSTOM_FIELD_4}


with code that has this logic:

if (Administrator #or# Log in ID = Profile ID being viewed)
{$CUSTOM_FIELD_1}
end if
{$CUSTOM_FIELD_2}
{$CUSTOM_FIELD_3}
{$CUSTOM_FIELD_4}


I am not a programmer, but I do understand the logic. I don't know what the correct variable names are, or the proper syntax for conditionals.

Also - other than the showprofile.tpl file, is there anywhere else where anyone except that user or the administrator would have Custom Field 1 visibility? I'd like to modify those files too.

Ideally this could be a longer term UBB Thread change to the control panel so the fields can be checked as "private" or "public"

Thanks,
Bill
It would be the same code as found in the 'edit user' link that shows up in the profile.
Line #305 in showprofile.php gives the code for showing that link (which is called in the template as: {$useredit} ). If you need more assistance, just ask.
That works!

The showprofile.tpl code now reads:
{if $useredit}
{$CUSTOM_FIELD_1}
{/if}
{$CUSTOM_FIELD_2}
{$CUSTOM_FIELD_3}
{$CUSTOM_FIELD_4}
{$CUSTOM_FIELD_5}


Now where can I change the definition of $CUSTOM_FIELD_1 so it displays as a link instead of text when the profile is viewed? I want to leave it as text in the profile edit screen. This is just like the Homepage field attributes.

I tried
Your DB Link but the {$CUSTOM_FIELD_1} has both label & the URL info and does not provide the correct link.
Ok - I figured this out. I restored showprofile.tpl with the original file and instead modified /scripts/showprofile.inc.php

It isn't optimized because I don't know the syntax for different conditionals and brute forced it, but it works. It allows me to put a custom label and the URL to an external database record in CUSTOM_FIELD_1, and have that field visible only by the individual user, or any administrators. It shows up as a link like the homepage field.

Original Code
Code
	// Show the profile if it exists
$columns = 2;
if ($CheckUser) {

if ($Homepage) {
$Homepage = str_replace("http://","",$Homepage);
$Homepage = str_replace("https://","",$Homepage);
$Homepage = htmlspecialchars($Homepage);
$Homepage = "<a href=\"http://$Homepage\" target=\"new\">http://$Homepage</a>";
}

if ($config['CUSTOM_FIELD_1']) {
$CUSTOM_FIELD_1 = "
<tr><td valign='top'>
{$config['CUSTOM_FIELD_1']}:
</td><td valign='top'>
 $Extra2
</td></tr>
";
}

if ($config['CUSTOM_FIELD_2']) {

Modified Code
Code
	// Show the profile if it exists
$columns = 2;
if ($CheckUser) {

if ($Homepage) {
$Homepage = str_replace("http://","",$Homepage);
$Homepage = str_replace("https://","",$Homepage);
$Homepage = htmlspecialchars($Homepage);
$Homepage = "<a href=\"http://$Homepage\" target=\"new\">http://$Homepage</a>";
}

// If this is the user allow visibility of class database link
if ($User == $user['USER_ID']) {
if ($config['CUSTOM_FIELD_1']) {
$Extra1 = str_replace("http://","",$Extra1);
$Extra1 = str_replace("https://","",$Extra1);
$Extra1 = htmlspecialchars($Extra1);
$CUSTOM_FIELD_1 = "J/30 Record: <a href=\"http://$Extra1\" target=\"new\">http://$Extra1</a>";
}
}

// If this is the main admin user allow visibility of class database link
if ($user['USER_ID'] == $config['MAIN_ADMIN_ID']) {
if ($config['CUSTOM_FIELD_1']) {
$Extra1 = str_replace("http://","",$Extra1);
$Extra1 = str_replace("https://","",$Extra1);
$Extra1 = htmlspecialchars($Extra1);
$CUSTOM_FIELD_1 = "J/30 Record: <a href=\"http://$Extra1\" target=\"new\">http://$Extra1</a>";
}
}

// If this is the any other admin allow visibility of class database link
if (($user['USER_MEMBERSHIP_LEVEL'] == "Administrator") && $Userstatus != "Administrator") {
if ($config['CUSTOM_FIELD_1']) {
$Extra1 = str_replace("http://","",$Extra1);
$Extra1 = str_replace("https://","",$Extra1);
$Extra1 = htmlspecialchars($Extra1);
$CUSTOM_FIELD_1 = "J/30 Record: <a href=\"http://$Extra1\" target=\"new\">http://$Extra1</a>";
}
}

if ($config['CUSTOM_FIELD_2']) {
© UBB.Developers