Gossamer Forum
Home : General : Perl Programming :

Send the next record in a database

Quote Reply
Send the next record in a database
I appreciate any help with this problem that I can get!

I have database that contains a list of key codes and that's all it contains.

What I would like to be able to do is this:
When a user requests a key code I would like to have them enter their name and email address and then be able to have a program that accesses the key code database and sends the first code in the database to the user. Then I would like it to delete that key code from the database so that the next user requesting a key code gets the next one in line.

Hope this makes sense. Can anyone tell me how I might do this?

Thanks!
Quote Reply
Re: [swk] Send the next record in a database In reply to
Just some thoughts... If you don't get anything worked out by next week I'll give you more details on how *I* would do it. Which may or may not be right.

Using dbman... see if there is an "autodelete" mod. Have all users be able to delete (permissions).
Sort db by Keycode (numerical order?).
See if there is a next record mod.

Users access db (by logging in or by url) enter their stuff (actually they are 'modifying' an existing record - but they don't know that) and click submit. Then modify_success sends an email to the address entered, and then deletes that record.

Not a big screaming deal, but I gotta jet for now.
TTFN
Quote Reply
Re: [swk] Send the next record in a database In reply to
Here's what I'd do...

I'm assuming this is not a "top-secret" type of thing and that your users aren't going to be hacking around wreaking mischief with the system.

1. Define your db fields as such:

Keycode
Name
email
status
Date or time or notes or something (I always throw in a couple of extra fields just for good measure)

2. Set user permissions to view & modify, you as admin would have all permissions.

The system would work like this:
You can upload a pre-filled file of keycodes (default.db) but be sure to include empty slots for all of your fields.

Example:
123-456789|||available|
567-891011|||available|

Or, you could add keycodes as you need to (or both)

3. Your users would log in and click a link (or be automatically taken) to a page that has the keycode and a place for them to enter their email address and name (this page is actually the modify_record page - but they don't know that). They enter their info and click "submit". This sets a hidden field that marks that keycode as "used" and keeps it from being displayed again. At this point they'd also receive an email with the keycode and perhaps you could have it send you one as well.


To do the above add the following to html_record_form (I'm assuming you will have some familiarity with the dbman script and can hack around and modify the html as well).
Code:
if ($in{'modify_form'}) {
print qq|<INPUT TYPE="hidden" NAME="status" VALUE="used">|;
} else {print qq|<INPUT TYPE="hidden" NAME="status" VALUE="available">|;}

Then customize your record layout for those getting keycodes (users)
Code:

if (($rec{'status'} eq "available") && ($in{'modify_form'})) {print qq|
<BR>$rec{'keycode'}
<BR>Enter your Name: <INPUT TYPE="text" NAME="name" VALUE="$rec{'name'}" SIZE="30" MAXLENGTH="100">
<BR>Enter your Email: <INPUT TYPE="text" NAME="email" VALUE="$rec{'email'}" SIZE="30" MAXLENGTH="100">
<BR>What ever other fields you want...
|;}


and don't forget to customize it for yourself to add keycodes
Code:
if($in{'add_form'}) {print qq|
<BR> Keycode: <INPUT TYPE="text" NAME="keycode" VALUE="$rec{'keycode'}" SIZE="30" MAXLENGTH="100">
<BR>Name: <INPUT TYPE="text" NAME="name" VALUE="$rec{'name'}" SIZE="30" MAXLENGTH="100">
<BR>Email: <INPUT TYPE="text" NAME="email" VALUE="$rec{'email'}" SIZE="30" MAXLENGTH="100">
<BR> etc, etc.
|;}

Then add the email script to html_modify_success:
Code:
open (MAIL, "|$mailprog -oi -t") or die;
print MAIL "To:$rec{'email'}\n";
print MAIL "From:admin\@yourdomain.com\n";
print MAIL "cc:admin\@yourdomain.com\n";
print MAIL "Subject: Keycode Requested\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-Type: text/html; charset=us-ascii\n";
print MAIL "Content-Transfer-Encoding: 7bit\n";

print MAIL qq|
<HTML><BODY>
You can put your message here and get fancy with html markup
<P> Your requested key code is $rec{'keycode'} blah blah blah
</BODY>
</HTML>
|;
close MAIL

You can then add something like status=available to the modify records link like this:
Code:
print qq!| <A HREF="$db_script_link_url&modify_form=1&status=available">Modify</A> ! if ($per_mod);

or you could have it do it automatically by adding the following under login_success
Code:
<META HTTP-EQUIV = REFRESH CONTENT = "0; URL=$db_script_link_url&modify_form=1&status=available">

of course you'd have to figure out someway to have the script pull up the next available record/keycode by using &ID=next or something in the link without the script freaking out and wanting you to search for records.

This is what I came up with off of the top of my head. I'm sure there are much better ways to do this, but play with it and see what works and what doesn't. I'll poke around in the FAQ and see if there is a "next record" mod or something.

Good Luck!