##################################################################### # Limit the number of records a user can add # Multiple records per user # Limit total number of records # # by JPDeni # Created 12-July-2000 ##################################################################### # # This mod will allow you to either have the same limit per user or # a different limit. If you want to change the number of records a # user can add, go to the "Admin" link and enter the new number in # the "Add" field. # In default.cfg, you must have a field for the userid. Be sure to # set the $auth_user_field variable to the number of the userid field. # If you are going to allow user's to sign up for accounts online, # change the @auth_signup_permissions to indicate the default number # of records a user can add: #--------------------------- # Permissions a new signup should get. @auth_signup_permissions = (1,5,1,1,0); #--------------------------- # The above would allow new users to add 5 records. # Also, you should be sure to set $auth_modify_own = 1; # in your .cfg file. ###### # In db.cgi, sub add_record, after ###### &auth_logging("added record: $in{$db_key}") if ($auth_logging); ###### # add ###### unless ($per_admin) { my $username_q = $DBH->quote($db_userid); $query = qq! SELECT * FROM $db_table_user WHERE username = $username_q !; my $sth = $DBH->prepare($query); $sth->execute(); if ($sth->rows) { $query = qq! UPDATE $db_table_user SET per_add='0' WHERE username = $username_q !; $rc = $DBH->do($query); $rc ? ($message = "User: $in{'username'} updated.") : ($message = "Error updating user: $in{'username'}. Reason: $DBI::errstr"); } else { $message = "Error, user $username_q not found!"; } $sth->finish; } ###### # In sub delete_records, change ###### if ($in{$key} eq "delete") { $delete_list{$key} = 1; $rec_to_delete = 1; } ###### # to ###### if ($in{$key} eq "delete") { $delete_list{$key} = 1; $rec_to_delete = 1; unless ($per_admin) { ++$user_count; } } ###### # Also in sub delete_records, after ###### &auth_logging("deleted records: $succstr") if ($auth_logging); ###### # add ###### my $username_q = $DBH->quote($db_userid); $query = qq! SELECT * FROM $db_table_user WHERE username = $username_q !; my $sth = $DBH->prepare($query); $sth->execute(); if ($sth->rows) { $query = qq! UPDATE $db_table_user SET per_add='1' WHERE username = $username_q !; $rc = $DBH->do($query); $rc ? ($message = "User: $in{'username'} updated.") : ($message = "Error updating user: $in{'username'}. Reason: $DBI::errstr"); } else { $message = "Error, user $username_q not found!"; } $sth->finish; } ###### # In sub admin_display, change ###### ###### NOTE: I have not tested this since I don't allow users to delete records, ###### but by looking at it, I'm thinking it should work without any problems. :-) if ($in{'inquire'} and ($in{'username'} eq $data[0])) { $user_list .= qq~\n~; $perm = qq| View Add Delete Modify Admin |; $password = $data[1]; } else { $user_list .= qq~\n~; } } $user_list .= ""; # Build the permissions list if we haven't inquired in someone. if (!$perm) { $perm = qq| View Add Delete Modify Admin |; } &html_admin_display ($message, $user_list, $password, $perm); } ###### # to ###### ###### Change the "$data[3]" to match your "per_add" field if it is different if ($in{'inquire'} and ($in{'username'} eq $data[0])) { $user_list .= qq~\n~; $perm = qq| View Add Delete Modify Admin |; $password = $data[1]; } else { $user_list .= qq~\n~; } } $user_list .= ""; # Build the permissions list if we haven't inquired in someone. if (!$perm) { $perm = qq| View Add Delete Modify Admin |; } &html_admin_display ($message, $user_list, $password, $perm); }