Having spent most of my Sunday trying to figure out just HOW NOT to display the Link to Add a Record, I can now thank Carol (again) for leading the way. The database I am building allows only one record per user; having the ADD a RECORD option on a User's screen is confusing for users who have already added to the database. What I wanted was this:
- Get the userid (my key field) for the current user
- determine if the Userid exists in the database
If it does, a record exists for that user, therefore, do not display the ADD A RECORD option.
If it does not, there is no record for that user, therefore, display the ADD A RECORD option.
Below is my clunky code. That part of it that isn't clunky belongs to Carol.
If anyone happens to have nothing better to do and notices something odd, please let me know. Yes I have tested this and it appears to work...but stuff like this always seems to bite me in the behind.
Thank you!
sub html_permissions_menu {
# --------------------------------------------------------
# Controls Display of Add, View, Modify, Delete
# Checks if Record already exists for user and conditionally prints Add
# If *Record does not exist OR User is Admin* AND user has permission to ADD
# print ADD.
# If Record does exist, ADD is not displayed.
%rec = &get_record($db_userid); # Get the record
# Use of unless
# If the database key - in this case the Userid - already exists, OR user is an Admin
# AND User has Add permissions, display Link to ADD Record
unless (($rec{$db_key} or ($per_admin)) and ($per_add)) {
print qq! | <A HREF="$db_script_link_url&add_form=1">Add My Resume</A> | !;
return;
}
# If not Admin AND user has permission to modify own records
# Print Update if User has Modify Permission and Print Delete if User has Delete Permission
if (!$per_admin && $auth_modify_own) {
print qq!| <A HREF="$db_script_link_url&modify_form=1&$db_key=*">Update My Resume</A>|<BR>! if ($per_mod);
print qq!| <A HREF="$db_script_link_url&delete_form=1&$db_key=*">Delete My Resume</A>|<BR>! if ($per_del);
}
# Must be an Admin so allow Delete if User has Delete Permissions
# allow Modify if User has Modify Permission
else {
print qq!| <A HREF="$db_script_link_url&delete_search=1">Delete</A> ! if ($per_del);
print qq!| <A HREF="$db_script_link_url&modify_search=1">Modify</A> ! if ($per_mod);
}
# If not Admin AND user has View Permission
# Print View
if (!$per_admin && $auth_view_own) {
print qq!| <A HREF="$db_script_link_url&view_records=1&$db_key=*">View My Resume</A> ! if ($per_view);
}
else {
print qq!| <A HREF="$db_script_link_url&view_search=1">Search Resumes</A> ! if ($per_view);
print qq!| <A HREF="$db_script_link_url&view_records=1&$db_key=*">List All Resumes</A>|<BR> ! if ($per_view);
}
}
Valerie
http://www.ad-ink.com
- Get the userid (my key field) for the current user
- determine if the Userid exists in the database
If it does, a record exists for that user, therefore, do not display the ADD A RECORD option.
If it does not, there is no record for that user, therefore, display the ADD A RECORD option.
Below is my clunky code. That part of it that isn't clunky belongs to Carol.
If anyone happens to have nothing better to do and notices something odd, please let me know. Yes I have tested this and it appears to work...but stuff like this always seems to bite me in the behind.
Thank you!
sub html_permissions_menu {
# --------------------------------------------------------
# Controls Display of Add, View, Modify, Delete
# Checks if Record already exists for user and conditionally prints Add
# If *Record does not exist OR User is Admin* AND user has permission to ADD
# print ADD.
# If Record does exist, ADD is not displayed.
%rec = &get_record($db_userid); # Get the record
# Use of unless
# If the database key - in this case the Userid - already exists, OR user is an Admin
# AND User has Add permissions, display Link to ADD Record
unless (($rec{$db_key} or ($per_admin)) and ($per_add)) {
print qq! | <A HREF="$db_script_link_url&add_form=1">Add My Resume</A> | !;
return;
}
# If not Admin AND user has permission to modify own records
# Print Update if User has Modify Permission and Print Delete if User has Delete Permission
if (!$per_admin && $auth_modify_own) {
print qq!| <A HREF="$db_script_link_url&modify_form=1&$db_key=*">Update My Resume</A>|<BR>! if ($per_mod);
print qq!| <A HREF="$db_script_link_url&delete_form=1&$db_key=*">Delete My Resume</A>|<BR>! if ($per_del);
}
# Must be an Admin so allow Delete if User has Delete Permissions
# allow Modify if User has Modify Permission
else {
print qq!| <A HREF="$db_script_link_url&delete_search=1">Delete</A> ! if ($per_del);
print qq!| <A HREF="$db_script_link_url&modify_search=1">Modify</A> ! if ($per_mod);
}
# If not Admin AND user has View Permission
# Print View
if (!$per_admin && $auth_view_own) {
print qq!| <A HREF="$db_script_link_url&view_records=1&$db_key=*">View My Resume</A> ! if ($per_view);
}
else {
print qq!| <A HREF="$db_script_link_url&view_search=1">Search Resumes</A> ! if ($per_view);
print qq!| <A HREF="$db_script_link_url&view_records=1&$db_key=*">List All Resumes</A>|<BR> ! if ($per_view);
}
}
Valerie
http://www.ad-ink.com