Gossamer Forum
Home : Products : DBMan : Customization :

changes to validate record mod -- seeking help!

Quote Reply
changes to validate record mod -- seeking help!
Hi,

I've been using the validate record mod successfully for quite some time. Now I'm looking for a way to print validated records to a file at the time the record is validated. (I know there is a print to file when record added mod -- but that doesn't work for me. I need to do it in conjunction with the validate record mod).

Anyhoo...I've been looking at this for several weeks now and I think the place to modify is the end of the sub validate_records routine in db.cgi. Somewhere in here:

}
foreach $key (keys %delete_list) {
$delete_list{$key} ?
($delerrstr .= "$key,") :
($delsuccstr .= "$key,");
}
chop($delsuccstr);
chop($delerrstr);

foreach $key (keys %validate_list) {
$validate_list{$key} ?
($valerrstr .= "$key,") :
($valsuccstr .= "$key,");

Ideally I would like to make $valsuccstr into a small snippet of html/text that includes a few data fields in addition to the $key. Some thing like this:

($valsuccstr .= "$key, <br> $data item #1, <br>$data item #2, <br>etc, etc");

I can't figure out how to make data fields for each validated record accessable in this way. Is this an easy thing to do? Any help from a perl hero out there would so greatfully appreciated. I'm really in over my head here and I'm feeling all beat up.

Pirate


I hope this makes sense.
Thanks,
Michael
Quote Reply
Re: [Swaylock] changes to validate record mod -- seeking help! In reply to
I'm not a perl hero, but if I understand your question correctly, you have the assignment of $valsuccstr inside a foreach loop, with $key representing - I guess - a database record key, and you want to print some record data to a file.

my $validated_file = "here goes the name of the file you want to print to";
open (FILE, ">$validated_file") || &cgierr ("can't create or write to $validated_file: $!");
# this overwrites the file if it already exists!
# If you want to append, use ">>" instead of ">"

foreach $key (keys %validate_list) {
if ($validate_list{$key}) { $valerrstr .= "$key,"; }
else { $valsuccstr .= "$key,";
my %rec = &get_record($key);#assuming $key is a database key
print FILE "$key: $rec{'onefield'} - $rec{'anotherfield'} - $rec{'yetanotherfield'}\n";
} #end else
} # end foreach

close (FILE);

Untested, but should work.
Note that this also allows you to make further use of $valsuccstr in the script. I don't know the validate_record_mod, but if $valsuccstr will be used after this point, you'd better not fiddle with it for printing to the file.

hope this helped


kellner
Quote Reply
Re: [kellner] changes to validate record mod -- seeking help! In reply to
Kellner,

Thanks so much for your response.
I'm going to give that a try this weekend. I'll let you know how it goes.

Mike
Quote Reply
Re: [Swaylock] changes to validate record mod -- seeking help! In reply to
Kellner,

You are the man! It worked. So seldom in my endeavour of hacking do things happen so smoothly. Perhaps my two weeks of looking at that code helped. THANK YOU!

While I have you on the mic, hopefully you can take moment to explain some stuff to me (I totally understand if you don't wanna bother).

In this line of code you wrote:

my %rec = &get_record($key);#assuming $key is a database key

When the &get_record subroutine is run, what exactly is put into the hash %rec? Is it a key/value pair for each data field of a record?

Also, I don't really get what the bit of code in the foreach expression means:

foreach $key (keys %validate_list)

Perhaps I really don't understand what the %validate_list really means.
Here's some other bits of code in the validate_record subroutine
that preceed the foreach call above:

if ($in{$key} eq "validate") {
$validate_list{$key} = 1;

if ($validate_list{$data[$db_key_pos]}) {
$validate_list{$data[$db_key_pos]} = 0;

Anyway, at this point I my my black box working so understanding this any more is just icing for me.

Again, MANY thanks for your help with my problem. You are officially a perl hero in my book.

Mike
Quote Reply
Re: [Swaylock] changes to validate record mod -- seeking help! In reply to
Well, actually, I'm the woman rather than the man :-)

The idea behind the validate records mod seems to be this:

Check whether the query-string passed to the script contains name-value-pairs like
"123=validate", with "123" being a database key.
If so, assign "1" to "123".

if ($in{$key} eq "validate") {
$validate_list{$key} = 1;}

So now you have a hash %validate_list with database keys as hash keys,
and "1" as values.

These keys are then run through various tests, one of which is this:

if ($validate_list{$data[$db_key_pos]}) {
$validate_list{$data[$db_key_pos]} = 0;}

It checks whether there's actually a database key corresponding to the hash key
*in* the database. If so, the hash key is reassigned to "0".
At the end, the foreach loop runs through all keys of %validate_list.
If they have the value "1", the record is not counted as valid and stored in
$valerrstr; if they have the value "0", it is valid and stored in $valsuccstr.
"foreach $key (keys %validate_list)" uses the usual perl way to loop over keys
in a hash ("foreach (keys %validate_list)"), and additionally assigns each key
to $key.

You're right: %rec assigns the value of a record field to the field name taken
from the database definition, so you can use it for printing:
print "$rec{'fieldname'}";

cheers,






kellner
Quote Reply
Re: [kellner] changes to validate record mod -- seeking help! In reply to
Well, actually, I'm the woman rather than the man :-)

Ooops! Shocked

Don't I look archaic. Thanks for the explanation. I really makes alot of things clear.

Mike