Gossamer Forum
Home : Products : DBMan : Installation :

Mutually exclusive Add and Modify+Delete

Quote Reply
Mutually exclusive Add and Modify+Delete
Hello girls and boys,

Using the userid field, I'm allowing only one record by user. So I would like, in the html.pl's sub html_footer part, to display Add but not Modify and Delete if no record exist for the logged user. And, of course, I would like to display Modify and Delete but not Add, if the user has already created one record.

Please share any idea about how to implement that procedure.

Thanks in advance and greetings from SwitzerLANd !
Quote Reply
Re: Mutually exclusive Add and Modify+Delete In reply to
The only way I can think of doing it is to change the permissions once a record is added. Start out with permissions to view and add and then, probably in either the add_record subroutine of db.cgi or the html_add_success subroutine of html.pl, add a routine to change the permissions to view, modify and delete. (I would probably opt for html_add_success, since I don't like changing db.cgi any more than I have to.)

For what you would need to add, look in db.cgi -- sub admin_display.

You'll probably also want to alter the Modify and Delete links so that the user's record automatically comes up when they click the link. But you also probably already thought of that. Smile



------------------
JPD
Quote Reply
Re: Mutually exclusive Add and Modify+Delete In reply to
Thank you again for your inputs !

I had already implemented the suggestion of your last paragraph and it is very great.

Before to change the permissions as you suggested, I was thinking that a simpler way should exists. In fact each user can have only one or zero owned record. What is the fastest/shortest code to check if one specific userid owns any record ?

Thanks in advance for any help !
Quote Reply
Re: Mutually exclusive Add and Modify+Delete In reply to
I lied before. I do know of another way to do what you want to do, but I think changing permissions is better than the other option.

What I did was to do the "get_record" at the beginning of the home page. If I didn't get anything returned, the user was immediately sent to the "add" form. The menu at the bottom of the add form just has "logoff" on it (or "view", too, if they can view other people's records). That's added manually to the html_add_form, rather than using the html_footer subroutine.

Then you can either take out the "Add" part of html_footer or you can require $per_admin for it, if you want to be able to add records yourself.

The only negative thing about this is that it does the search every time the user goes to the home page. It could slow things down a bit if you had a lot of records.

The reason I did it this way is that there are some other reasons I couldn't change permissions for the user. (Multiple databases connected to one password file.) If I was only using one database, I would probably opt for changing permissions.



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