Gossamer Forum
Home : Products : DBMan : Installation :

Give users a limit number to add records

Quote Reply
Give users a limit number to add records
Mij autodelete works, but this is my next problem.
As the Admin I want to give a user a limit number for adding records, I think, by signing up, the default value is saving in the 'default.pass' file and when the user will add a record, first the 'max_add' variable have to be load, and by that value, the user will get his permission to add ... records, when the user adds succesfull, the 'max_add' number is counting down.
Is this possible, and how???
Quote Reply
Re: Give users a limit number to add records In reply to
I can write the modification for you, but I'll first need to know if you are using the password lookup modification or any other modification that changes the structure of the password file.

Also, since you are using the auto_delete feature, would that be a factor in the number of records a user can add? For example, if your limit to add records was 5 and I had added 5 records, when one of the records had been auto_deleted would I be able to add another one? (If so, this will make it very complicated.)

Finally, do you need to have the "Add" link not appear if a user has added the maximum number of records? Or would it be acceptable for the link to be there, but give an error if the user tried to add more records than the number to which he is entitled?

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





Quote Reply
Re: Give users a limit number to add records In reply to
Thanks in advance, the first answer is Yes, I use the password lookup mod, also, I made a possibility to sign up in the Main Menu (for default users, who want to have an account), for the second part, I think that has to be also Yes, because that suits very professional. If you be abel to look at a Dutch site whitch use a very good system for that part, look here, http://cgi5.wxs.nl/cgi-bin/aanbod/index.cgi?c=22 ,the part that called 'Advertentie Manager' is a good way to think aboud this mod. For last part of your question, I do not think, this is very important, if it is no big problem, I like it, otherwise it doesn't matter.
Quote Reply
Re: Give users a limit number to add records In reply to
I'm sorry, but I don't read Dutch. Smile

If you don't mind the "Add" link appearing even though a user can't add a record, this will make things much easier.

Add a line to your default.cfg file,

$db_maximum_records = 5;

(or whatever you want the maximum to be).

In db.cgi, sub validate_record, replace the beginning of the subroutine with the following:

Code:
my ($col, @input_err, $errstr, $err, $line, @lines, @data, $count);

if ($in{'add_record'}) { # don't need to worry about duplicate key if modifying
open (DB, "<$db_file_name") or &cgierr("error in validate_records. unable to open db file:
$db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
$count = 0;
LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_;
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $in{$db_key}) {
return "duplicate key error";
}
if ($data[$auth_user_field] eq $db_userid) {
++$count;
}
}
close DB;
if ($count >= $db_maximum_records) {
return "you have reached the maximum number of records allowed for each user";
}
}

Leave in the existing lines starting with

foreach $col (@db_cols) {



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







[This message has been edited by JPDeni (edited April 01, 1999).]
Quote Reply
Re: Give users a limit number to add records In reply to
Thanks, but I mean, that the 'max. number of adding records' variable have to be define by admin for a seperate registered user. When someone logs in and sign up for an account, and he will get the max. of 5 records to add, its good, but that number should be edited by the admin, when needed.
Quote Reply
Re: Give users a limit number to add records In reply to
Then I'm afraid it's too complex for me to tackle now. I would have to let it sit in the back of my brain for quite a while just to figure out where to make all of the changes.

Possibly someone else can think of a simpler way to do it.




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





Quote Reply
Re: Give users a limit number to add records In reply to
Ok, I did the mod, everything works, even the not adding function, complete with the error message, modifying records, all goes right, but when i will add a new record, it wil come in the db, but after the submit press, I get an 'Internal Server Error', and what I'll do, replace older db.cgi or whatever, the error stays. I don't know what to do now.

Here is my sub validate_record:

sub validate_record {
# --------------------------------------------------------
# Verifies that the information passed through the form and stored
# in %in matches a valid record. It checks first to see that if
# we are adding, that a duplicate ID key does not exist. It then
# checks to see that fields specified as not null are indeed not null,
# finally it checks against the reg expression given in the database
# definition.

my ($col, @input_err, $errstr, $err, $line, @lines, @data, $count);
if ($in{'add_record'}) { # don't need to worry about duplicate key if modifying
open (DB, "<$db_file_name") or &cgierr("error in validate_records. unable to open db file:
$db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
$count = 0;
LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_;
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $in{$db_key}) {
return "duplicate key error";
}
if ($data[$auth_user_field] eq $db_userid) {
++$count;
}
}
close DB;
if ($count >= $db_maximum_records) {
return "you have reached the maximum number of records allowed for each user";
}
}
foreach $col (@db_cols) {
if ($in{$col} =~ /^\s*$/) { # entry is null or only whitespace
($db_not_null{$col}) and # entry is not allowed to be null.
push(@input_err, "$col (Can not be left blank)"); # so let's add it as an error
}
else { # else entry is not null.
($db_valid_types{$col} && !($in{$col} =~ /$db_valid_types{$col}/)) and
push(@input_err, "$col (Invalid format)"); # but has failed validation.
}
(length($in{$col}) > $db_lengths{$col}) and
push (@input_err, "$col (Too long. Max length: $db_lengths{$col})");
if ($db_sort{$col} eq "date") {
push (@input_err, "$col (Invalid date format)") unless &date_to_unix($in{$col});
}
}

if ($#input_err+1 > 0) { # since there are errors, let's build
foreach $err (@input_err) { # a string listing the errors
$errstr .= "<li>$err"; # and return it.
}
return "<ul>$errstr</ul>";
}
else {
return "ok"; # no errors, return ok.
}
}
--------------------
Quote Reply
Re: Give users a limit number to add records In reply to
I don't understand. You say that it works, and then you say that it doesn't work. When exactly does it cause problems?

Your sub validate_record is just fine. No errors there at all.

Could you have changed something else that has an error?



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





Quote Reply
Re: Give users a limit number to add records In reply to
While I was sporting, I thought about it: the record came into the DB. But the mail, that a record is added I haven't received, that gives me the idea, to block the whole mailing-mod in html.pl add_succes sub. And Yes, the whole adding proces works correctly. Do you have an explaination for this, because my add_mail_mod does not work now.
Thank you very much.

Greetings,
Mart Kruijt.
Quote Reply
Re: Give users a limit number to add records In reply to
I don't know. I'd have to see the mailing mod.


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





Quote Reply
Re: Give users a limit number to add records In reply to
This has worked fine, before adding the max_add mod. (The words are in Dutch).
--------------------------------------------
sub html_add_success {
# --------------------------------------------------------
# The page that is returned upon a successful addition to
# the database. You should use &get_record and &html_record
# to verify that the record was inserted properly and to make
# updating easier.

open (MAIL, $mailprog) &#0124; &#0124; print "Can't start mail program";
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Record toegevoegd\n\n";
print MAIL "Er is een nieuw record toegevoegd!!\n";
print MAIL " \n";
print MAIL "Merk = $in{'Merk'}\n";
print MAIL "Type = $in{'Type'}\n";
print MAIL "Bouwjaar = $in{'Bouwjaar'}\n";
print MAIL "Brandstof = $in{'Brandstof'}\n";
print MAIL "Koetswerk = $in{'Koetswerk'}\n";
print MAIL "Vraagprijs = $in{'Vraagprijs'}n";
print MAIL "Email = $in{'Email'}\n";
close MAIL;

&html_print_headers;
Quote Reply
Re: Give users a limit number to add records In reply to
Sorry, JPD,
I think I solve the problem.
I've made a new Emailadress for somebody in my Email-alias on the server. There I change the Emailadress destination from the DB in, what I thought was good and after that never tried out. So , when DBman was running the email-mod, there was a 'user-unkown' failure, from whitch the programm not could figure with. I hope this is clear for you and I thank you again for your work is this.

Apologies,
Mart.
Quote Reply
Re: Give users a limit number to add records In reply to
I'm just glad you got it figured out. Smile


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





Quote Reply
Re: Give users a limit number to add records In reply to
But when you blocked the mail mod, html_add_success worked correctly?

Did it ever work right? When someone added a first record? A fifth?

Try changing

&#0124; &#0124; print "Can't start mail program";

to

&#0124; &#0124; &cgierr("Can't start mail program");

(This probably won't fix your problem, but it's a better way to catch errors in the mail program. I found it out the hard way. Smile )

This may soon get to the point where I'm going to need to log on myself and give it a try.

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





Quote Reply
Re: Give users a limit number to add records In reply to
JP

the mode you did with them max records has anyone got it to work on userid. Say I want one user to be able to enter 5 max but then another user enter 50. If anyone has got this type of mod let me know.

Thanks