Gossamer Forum
Home : Products : DBMan : Customization :

Fields visible to Admin only

Quote Reply
Fields visible to Admin only
Heya JPD,

Is there a way I can make fields visible to Admin users only? I'm not using auto_form_generation and would like for some fields to be invisible and uneditable to all users that does not have Admin permissions.

Do I have to define seperate forms in my html.pl file? How do I call the admin form when Admin is logged in and the other one for the rest?

Hope you can help.


------------------
Safe swoops
Sangiro

http://www.dropzone.com/
Quote Reply
Re: Fields visible to Admin only In reply to
It's not hard at all to have fields that only the admin can see. The best way to explain it, though, is to give you a little example. Here's the basic form:

Code:
print qq|
<table>
<tr><td>ID:</td>
<td><input type="text" name="ID" value="$rec{'ID'}"></td>
<tr><td>Name:</td>
<td><input type="text" name="Name" value="$rec{'Name'}"></td>
<tr><td>Address:</td>
<td><input type="text" name="Address" value="$rec{'Address'}"></td>
<tr><td>City:</td>
<td><input type="text" name="City" value="$rec{'City'}"></td>
</table>|;

I want to make the ID field editable by the admin only, so I make the following changes:

Code:
print qq|
<table>|;
if ($per_admin) {
print qq|

<tr><td>ID:</td>
<td><input type="text" name="ID" value="$rec{'ID'}"></td>|;
}
else {
print qq|<input type="hidden" name="ID" value="$rec{'ID'}">|;
}
print qq|

<tr><td>Name:</td>
<td><input type="text" name="Name" value="$rec{'Name'}"></td>
<tr><td>Address:</td>
<td><input type="text" name="Address" value="$rec{'Address'}"></td>
<tr><td>City:</td>
<td><input type="text" name="City" value="$rec{'City'}"></td>
</table>|;

You need to make a hidden field for non-admin users so that the data won't be lost if they modify the record. (If only admins can modify, you can leave out the "else" part.)

The same goes for the display of the record:

Code:
print qq|
<table>
<tr><td>ID:</td>
<td>$rec{'ID'}</td>
<tr><td>Name:</td>
<td>$rec{'Name'}</td>
<tr><td>Address:</td>
<td>$rec{'Address'}</td>
<tr><td>City:</td>
<td>$rec{'City'}</td>
</table>|;

becomes

Code:
print qq|
<table>|;
if ($per_admin) {
print qq|

<tr><td>ID:</td>
<td>$rec{'ID'}</td>|;
}
print qq|

<tr><td>Name:</td>
<td>$rec{'Name'}</td>
<tr><td>Address:</td>
<td>$rec{'Address'}</td>
<tr><td>City:</td>
<td>$rec{'City'}</td>
</table>|;

Since there's no form involved, you don't have to make any allowances for non-admin users in the display.

Does this help?

------------------
JPD







[This message has been edited by JPDeni (edited May 24, 1999).]
Quote Reply
Re: Fields visible to Admin only In reply to
JPD,

It sure does! Looked at it and it makes perfect sense. I'll try it tomorrow. I'm off to bed now - btw you should be too!

Even if you're on PST like me, it's almost 1:30 am!

Sweet dreams!

------------------
Safe swoops
Sangiro

http://www.dropzone.com/
Quote Reply
Re: Fields visible to Admin only In reply to
 Smile


------------------
JPD