Gossamer Forum
Home : Products : DBMan : Customization :

Permissions in modify form?

Quote Reply
Permissions in modify form?
I was wondering if it would be possible to have the permission checkboxes in the modify_form_record routine like it is in the admin display and if so, how would I go about doing that? I don't really want to use the build_checkbox_field because it shows 2 checkboxes for each permission and I'd rather have it just show the 1 like on the admin disply.
Any ideas?

I have a seperate member database set up where I do all of this, but I'm getting a lot of members and it takes forever for the admin display to load, so instead of having the select field, I just want to use the modify form to change permissions etc.
Thanks in advance for any ideas! Smile


DBMan SQL Version 1 mods available at:
http://dbmansqlmods.rainbowroomies.com
(Mods based on JPDeni's original mods.)
Quote Reply
Re: [shann123] Permissions in modify form? In reply to
At what point are you having to change permissions for the members?

Is you reason for needing the permission changed is to assign a member permission after they add a record?

Please explain more of what you are trying to accomplish.

I recently created a database where I needed to change permissions for members based on 3 added membership levels. I did this using an idea from other threads posted in the FAQ to have it set their permission based on a field after they add their member record. I'm wondering if this is similiar to what you need?

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Permissions in modify form? In reply to
I've also got 3 other permissions, one of those being a paid permission which allows paid members more features. That's the one that I need to change the most, but it'd still be nice to be able to remove all permissions for a PITA or something.
For adding records etc, I've got that set up so everything changes automatically.
Quote Reply
Re: [shann123] Permissions in modify form? In reply to
I figured it out! Well, at least this seems to work for the most part lol.

If I put this in the sub html_record_form:

if ($rec{'per_view'}) {print qq| View <input type="checkbox" name="per_view" value="" checked>|; }
if (!$rec{'per_view'}) {print qq| View <input type="checkbox" name="per_view" value="1">|; }

That seems to show that if they have permission, it's checked, if you modify the form without changing permissions, everything seems to stay the same, but if you uncheck a box, it changes the permissions to blank.

This seems to work fine, except for when you uncheck 1 permission, it changes them all to blank. I haven't figured that one out yet. Unsure
It's still faster to go back and re-add the permissions they should have rather than loading the whole list.. lol
Quote Reply
Re: [shann123] Permissions in modify form? In reply to
OK.. I take that back.. it doesn't work right. If you check one of the other permissions and modify, it removes the permissions for the other ones you had checked, but adds the permission to the one you did check. *sighs*

Last edited by:

shann123: Apr 16, 2005, 7:06 AM
Quote Reply
Re: [shann123] Permissions in modify form? In reply to
Mind you this is all new to me also, but I did get it working in mine.

What I did (according to other threads) was to make the changes in sub validate_records. Based on the type of account .. which is one of my permissions. But I think the solution I found may help you to see how you may need to use some conditional statements and actually rewrite the whole password line and not just change one setting. I could be totally wrong, but you could give it a shot :)

After:

$output .= &join_encode(%rec);

########## code to change permissions ############

if ($rec{'accounttype'} eq "Business") {
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@passlines = <PASS>;
close PASS;

open (PASS, ">$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
my $found = 0;
foreach $passline (@passlines) {
if ($passline =~ /^$rec{$db_cols[$auth_user_field]}:/) {
my $password = (split (/:/, $passline))[1];
print PASS "$rec{$db_cols[$auth_user_field]}:$password:1:1:1:1:0:1:0:0\n";
}
else {
print PASS $passline;
}
}
close PASS;
}


Then I have it also to check for $rec{'accounttype'} for the other 2 types and change the permissions accordingly.

Hope this helps to give you ideas :)

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Permissions in modify form? In reply to
I haven't had a chance to mess with this, but I'll give that a try when I do.. I think I see what you're doing with it. :-)
Thanks Lois!
Quote Reply
Re: [shann123] Permissions in modify form? In reply to
I got it figured out! I was on the right track before, but just had to make a change. Here's what I did and it works!

if ($rec{'per_view'}) {print qq| View <input type="checkbox" name="per_view" value="1" checked>|; }
elsif (!$rec{'per_view'}) {print qq| View <input type ="checkbox" name="per_view" value="1">|; }
if ($rec{'per_add'}) {print qq| Add <input type="checkbox" name="per_add" value="1" checked>|; }
elsif (!$rec{'per_add'}) {print qq| Add <input type="checkbox" name="per_add" value="1">|; }
if ($rec{'per_mod'}) {print qq| Modify <input type="checkbox" name="per_mod" value="1" checked>|; }
elsif (!$rec{'per_mod'}) {print qq| Modify <input type="checkbox" name="per_mod" value="1">|; }
if ($rec{'per_del'}) {print qq| Delete <input type="checkbox" name="per_del" value="1" checked>|; }
elsif (!$rec{'per_del'}) {print qq| Delete <input type="checkbox" name="per_del" value="1">|; }
if ($rec{'per_admin'}) {print qq| Admin <input type="checkbox" name="per_admin" value="1" checked>|; }
elsif (!$rec{'per_admin'}) {print qq| Admin <input type="checkbox" name="per_admin" value="1">|; }

I just had to make sure that the value was 1 on both, but just have checked when it was already checked. I didn't have to do anything in the db.cgi.. just on the html part of it. Smile
Quote Reply
Re: [shann123] Permissions in modify form? In reply to
You should be able to streamline that a little bit, if you're interested.

Code:
print qq| View <input type="checkbox" name="per_view" value="1"|;
if ($rec{'per_view'}) { print "checked"; }
print qq| >
Add <input type="checkbox" name="per_add" value="1"|;
if ($rec{'per_add'}) { print "checked"; }
print qq| >
Modify <input type="checkbox" name="per_mod" value="1"|;
if ($rec{'per_mod'}) {print "checked"; }
print qq| >
Delete <input type="checkbox" name="per_del" value="1"|;
if ($rec{'per_del'}) {print "checked"; }
print qq| >
Admin <input type="checkbox" name="per_admin" value="1"|;
if ($rec{'per_admin'}) {print "checked"; }
print ">";


You don't have to, of course, but it might be a little easier to read.

You will have to make changes in the db.cgi file in order to write them to the .pass file, though, unless you're keeping your permissions in the .db file.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Permissions in modify form? In reply to
Thanks for the suggestion JP.. that definately looks a lot better. I was just going for functionality, but might as well have it a little cleaner.. lol.
Next step I'm gonna try is making it so I can change passwords from there as well. I figure that's probably gonna have to be done in the db.cgi in the modify routine. More trial and error!
Thanks again. Smile