Gossamer Forum
Home : Products : DBMan : Discussions :

$per_mod on a record by record basis

Quote Reply
$per_mod on a record by record basis
Hi:

I am trying to let users modify their own records and it works (doesn't happen very often to me...but this works). However I have a litle problem.

I added a small (edit) (delete) link to each record so someone can modify it directly from the record. This lines display only if the user has modify rigths (or delete, using $per_mod and $per_del). By doing this I was expecting that this will display only on the records this user is able to modify but it shows on all records (regardless of weather or not they belong to that user).

I guess this is happening because $per_mod only checks if the user has modify rigths, and not modify rigths related to that particular record. Is there a way of doing something like this on a record by record basis? like $per_mod_only_if_it_is_your_record?

If this is not clear here is an example of my html.pl code:

print " <img border=0 src=$images_url/a_sep.gif><A HREF=$db_script_link_url&modify_form_record=1&modify=$rec{'ID'}><img border=0 src=$images_url/aedit.gif alt=Edit></a> " if ($per_mod);

Hope this is clear...Thanks!

Quote Reply
Re: $per_mod on a record by record basis In reply to
Reference from FAQ/Help under "Syntax":

Want only the owner of the record and those with admin permissions to see a field(s)

Use:
|;
if (($db_userid eq $rec{'UserID'}) || ($per_admin)) {
print qq| [The record information] |; <BR>
}
print qq|

So in your case try using:

|;
if (($db_userid eq $rec{'UserID'}) || ($per_admin)) {

print " <img border=0 src=$images_url/a_sep.gif>
<A HREF=$db_script_link_url&modify_form_record=1&modify=$rec{'ID'}><img border=0 src=$images_url/aedit.gif alt=Edit></a> " if ($per_mod);
}
print qq|

This would allow only the record holder and admin to view the links.

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: $per_mod on a record by record basis In reply to
Lois, check your syntax Wink

print qq| [The record information] |; <BR>

Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: $per_mod on a record by record basis In reply to
Thanks for the replys

I used the following code:

if (($db_userid eq $rec{'UserID'}) || ($per_mod)) {
print " <img border=0 src=$images_url/a_sep.gif><A HREF=$db_script_link_url&modify_form_record=1&modify=$rec{'ID'}><img border=0 src=$images_url/aedit.gif alt=Edit></a> " if ($per_mod);

}

Remember that I need to show the edit link only if they have modify rigths (or admin) so I changed the first line to per_mod. Still it doesnt work. I tried many variations of this code (not that I know very much..just trial and error) like removing the second per_mod but it still shows the links.

if I leave the first code you sent me (per_admin on the first line) it seems to work because my test user does not have admin rigths and it doesn't show the link. However the user has modify rigths over this item (because it was added by this user, so excluding everything but admin is not the idea). i'll keep trying a few other options, please let me know if you see where I am failing...

Quote Reply
Re: $per_mod on a record by record basis In reply to
Ok, I tried more and still it doesn't work..any ideas?

Quote Reply
Re: $per_mod on a record by record basis In reply to
I found a solution. If someone looks at this post some time from now, here it is).

the problem was pretty simple (finding the solution took me two days, but this is because I don't know about perl at all). Here is the code that works:

if (($db_userid eq $rec{'Userid'}) && ($per_del)) {
print qq! [record information] !;

The problem was that I need to check if a user owns the record AND (instead of OR, notice && instead of || ) if he has delete rigths...

Hope this prevents another newbie from spending two days for such task and Thanks for the help