Gossamer Forum
Home : Products : DBMan : Installation :

Help with modifications for Classified use.

(Page 1 of 2)
> >
Quote Reply
Help with modifications for Classified use.
I need some assistance with some mods I've made to dbman. I have setup the description field so that it actively counts the number of characters as they are being entered, through use of JavaScript code, and saves it in $rec{'CharLength'}. I have created a new database field in "default.cfg" called:

CharLength => [13, 'numer', 0, 500, 1, '', '']

The value is placed in that field when the user submits a new record.

I'm not really good with Perl, so here's where I need some help. I'd like to set this up as an Advertisement system, and I'm wanting to charge by the character (like 1 cent per char for instance).

I'd like to have a subroutine executed immediately following "Add a New Record" that will take the CharLength value from the "default.db" file and multiply it by an X Amount and also multiply it by X Number of days (also stored in a field in "default.db), then it'll prompt the user whether they want to accept the cost, or cancel the ad. If accepted, it will then store the computed $ value in an additional field in the current record in "default.db". (I have made the mod that will keep the record for X number of days before auto-deletion.) Then after the amount is computed, it will email the entire contents of the form including the total cost of the Ad.

Also, another item which I need help with. I have also created another field called "Validated" in default.cfg, which is a checkbox field (Yes|No). What I would like to do with that is by default have it so that it's not checked, and therefore the record cannot be viewed by anyone until "admin" modifies the record and checks "Yes" for Validated.

All your help is appreciated. I've learned a lot in the past week through reading up in this area. Keep up the good work!

Frank
Quote Reply
Re: Help with modifications for Classified use. In reply to
The Validate option has been discussed (although not in explicit detail per request of me because I want to learn more about Perl) in the DBMAN Discussion Forum. Also, you may try to post your Topics over in the DBMAN Discussion Forum since that is the Forum where mods are discussed.

To find the "Validate" option, use the search form in this BB in the DBMAN Discussion Forum.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Help with modifications for Classified use. In reply to
It's okay to leave the thread here. No point in duplicating the effort.

I have made a text file of the modification for validating records. I haven't made it real "pretty" yet, but you should be able to follow it. It's at http://www.jpdeni.com/...n/Mods/validate1.txt . The mod uses a radio field (not checkbox!) called Validated. It creates an "admin-only" link which displays all non-validated records and lets you select whether to validate or delete them. It also sends a "canned" email message to the owner of the record, whether the record is validated or deleted.

Please read over the modification before you install it, especially the comment lines (lines that start with a #). There's lots of information in there.

As for your other mod, it seems pretty complicated. I think we'll need to take it one step at a time.

Quote:
I'd like to have a subroutine executed immediately following "Add a New Record" that
will take the CharLength value from the "default.db" file and multiply it by an X Amount and also multiply it by X Number of days (also stored in a field in "default.db),

That's not too hard. What is the name of the field that holds the text of the ad?

Quote:
then it'll prompt the user whether they want to accept the cost, or cancel the ad.

This is a little more complex. I think you'd need to have something like a "preview" mod installed, so that it would do the calculations, but wouldn't actually add the record to the database until the user clicked a second submit button.

Quote:
If accepted, it will then store the computed $ value in an additional field in the current
record in "default.db".

Not a problem.

Quote:
(I have made the mod that will keep the record for X number of days before auto-deletion.)

Good! Smile

Quote:
Then after the amount is computed, it will email the entire contents of the form including the total cost of the Ad.

Easily done.

I think we can work together on this.


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





Quote Reply
Re: Help with modifications for Classified use. In reply to
Thanks for the info. I tried out the Validation subroutine, but it errors out when I run it. It looks like I'm missing a few subs- html_page_top, html_page_bottom, and html_record_long. I tried commenting them out, and it still didn't fix it.

Let me know if you have any ideas.

Thanks!
Frank
Quote Reply
Re: Help with modifications for Classified use. In reply to
I had forgotten that I had written that for someone who was using my "user-friendly" html.pl modification.

Hang on a bit and I'll stick the other code in there.


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





Quote Reply
Re: Help with modifications for Classified use. In reply to
Thanks for the info. I tried out the Validation subroutine, but it errors out when I run it. It looks like I'm missing a few subs- html_page_top, html_page_bottom, and html_record_long. I tried commenting them out, and it still didn't fix it.

Let me know if you have any ideas.

Thanks!
Frank
Quote Reply
Re: Help with modifications for Classified use. In reply to
I uploaded a new version of the validate mod to my server. Use the same link as above. The only things I changed were the html subroutines.


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





Quote Reply
Re: Help with modifications for Classified use. In reply to
Thanks a bunch for changing that so quickly! I went ahead and applied the change, and it's working for the most part, although there is something wrong with the Validation. When I reset all the records back to Unvalidated, it will show that I have X number of records to validate, which is normal. However, I can only validate X-1 number of records. So if I had 3 records, it will only let me modify 2. If there is only one new record, then I can't validate anything- There is always at least one record that can't validated. I also noticed it validates in descending order in the record ID. (e.g. Rec 13,12,9). Is there a way to change it in the order they were submitted, vs. newest to oldest order?

Also, if there is nothing to validate, it clears the screen and just sits there. Is there a way it can detect no new records to validate, and indicate such?

Thanks again! Your time is much appreciated.

Frank
Quote Reply
Re: Help with modifications for Classified use. In reply to
I don't think so. We'll have to start from scratch. Remove all the code you added -- except for the Validated field -- and post your html.pl file to a web-accessible directory (one where you would place html files). Rename the file to html_pl.txt. I'll see if I can figure out a validation routine that will work for you.

You do have everything working all right in your database now, right? You have your html_record_form and html_record exactly like you want them to be?


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





Quote Reply
Re: Help with modifications for Classified use. In reply to
Frank, I think I may have fixed the problem with the validate mod. Let me know if it is still causine problems.


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





Quote Reply
Re: Help with modifications for Classified use. In reply to
Very very very good! It works perfectly! Thank you so much for spending the time to fix that! Smile

As for the other request I had regarding the payment system. The description field name is just called "Description". Is that what you wanted to know?

I was thinking it would be even nicer if I could associate cost amounts with the number of days the ad is placed, rather than having one fixed amount.

Let me know what you can do to help...

Thanks again,
Frank

Quote Reply
Re: Help with modifications for Classified use. In reply to
Wonderful!! Smile

As for your other requests -- I think it would be best to take one step at a time.

The first thing is to set up the "preview" screen. Once we get that going, the user will be able to preview the ad to make sure it looks like they want it to and we can add the cost calculation to it.

In html_add_form, change

Code:
<INPUT TYPE="SUBMIT" NAME="add_record" VALUE="Add Record">

to

Code:
<INPUT TYPE="SUBMIT" NAME="preview_record" VALUE="Add Record">

Just below sub html_add_form, add the following new subroutine:

Code:
sub html_preview {
# --------------------------------------------------------
&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Record Preview</title>
</head>
<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Record Preview</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Record Added
</b></font></center><br>
<P><$font>This is how your ad will appear in the database. If you are satisfied with it, use the
"Add it!" button directly below the ad. Otherwise, make the changes in the form and use the
"Add Record" button below the form.</font>
<center>|;
&html_record(%in);
print qq|<center>
<form action="$db_script_url" method="POST" >
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<INPUT TYPE="SUBMIT" NAME="add_record" VALUE="Add It!"></center><HR>
|;
&html_record_form (%in);
print qq|
<p>
<INPUT TYPE="SUBMIT" NAME="preview_record" VALUE="Add Record">
<INPUT TYPE="RESET" VALUE="Reset Form">
</p></form></center>
|;

&html_footer;
print qq|
</td></tr>
</table>
</center>
</body>
</html>
|;
}

In db.cgi, sub main, in the midst of the other "elsif" statements, add

Code:
elsif ($in{'preview_record'}) { if ($per_add) { &preview_record; } else { &html_unauth; } }

Add the following new subroutine to db.cgi:

Code:
sub preview_record {
# --------------------------------------------------------

my ($status, $counter);
# Set the userid to the logged in user.
($auth_user_field >= 0) and ($in{$db_cols[$auth_user_field]} = $db_userid);

# First we validate the record to make sure the addition is ok.
$status = &validate_record;

# We keep checking for the next available key, or until we've tried 50 times
# after which we give up.
while ($status eq "duplicate key error" and $db_key_track) {
return "duplicate key error" if ($counter++ > 50);
$in{$db_key}++;
$status = &validate_record;
}
if ($status eq "ok") {
&html_preview;
}
else {
&html_add_failure($status);
}
}

Once this is working on your system, we'll start calculating the cost of the ad. I will need to know exactly how you want it calculated.

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





Quote Reply
Re: Help with modifications for Classified use. In reply to
Other than a couple of typos, it worked like a charm! Smile

As for the payment system: I would like to be able to associate a cost amount with the field that holds the X number of days the ad will run. So for instance, 3 days = $.03 per character, 7 days = $.02 per char, etc. Then multiply them all together to get a total amount. So the formula would be: Days x Cost/Char x # Chars in description field.
Then it will display another screen indicating the total cost, and if they accept it, it will email them back with the entire ad contents and the total cost. It will also store the cost in a field in their record.

Thanks again for all your help! It's much appreciated. Smile

Frank

Quote Reply
Re: Help with modifications for Classified use. In reply to
I'm not surprised about the typos. I'm terrible when it comes to them. Smile

A couple of other questions, just so I don't have to write double code.

Will there only be the two levels of "Cost per character", so that

if Days < 7 cost = .03
else cost = .02

Is that correct?

The other question is do you want to charge for spaces and punctuation? Would

the quick brown fox!

be 20 characters or 16? or maybe 17, if you wanted to charge for puncutation, but not spaces.


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





Quote Reply
Re: Help with modifications for Classified use. In reply to
I'd actually like to have 3,7,14,21,30,60,90
(7 levels)- all these are defined in a "Duration" radio field in the default.cfg.
Go ahead and put whatever cost value for those, and I'll substitute the correct amount later.

As for charging for punctutation and spaces, how hard would it be to have a On/Off switch for that? I'm thinking probably not charge for them, but I haven't really put much thought into that.

Right how I have a JavaScript that actively counts all the characters as they are being typed, and saves it in a CharLength field in my database. So in this particular situation, a subroutine would need to be created that would identify the # of all the spaces and punctuation and subtract that value from the CharLength value.

Frank
Quote Reply
Re: Help with modifications for Classified use. In reply to
DBMan can easily count the number of characters in a field with one command -- length($rec{'Description'}). That's really easier to use, especially if you think you might not want to charge for spaces and/or punctuation.

For the levels of "Cost/Char," it probably would be best to define an array in your .cfg file for the amounts. That way it's easier to change later on. Also it makes scripting really easy.

Define your array like this:
Code:
$cost_per_char[3] = .02;
$cost_per_char[7] = .01;
$cost_per_char[14] = .005;
$cost_per_char[21] = .0025;
$cost_per_char[30] = .001;
$cost_per_char[60] = .0005;
$cost_per_char[90] = .00025;

If you want to ignore spaces and characters, add the following to your .cfg file:

Code:
$ignore_space = 1;
$ignore_punc = 1; # also ignores spaces

In sub html_preview, right at the beginning, add

Code:
$ad = $in{'Description'};
if ($ignore_punc) {
$ad =~ s/\W//g;
}
elsif ($ignore_space) {
$ad =~ s/\s//g;
}
$ad_length = length($ad);
$in{'Cost'} = sprintf("%.2f",$ad_length * $cost_per_char[$in{'Days'}] * $in{'Days'});

In the place where you want to display the cost, use $in{'Cost'}, like

Code:
<P><$font>This is how your ad will appear in the database.
The total cost for this ad will be $in{'Cost'} and it will run for $in{'Days'}.

In order to keep people from being tricky, you should probably add the computation code to sub add_record in the db.cgi file, too. Put it before

$status = &validate_record;

I did test this on my home computer, and it seemed to work. Let me know if it works okay for you and then we'll get the emailing done.



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







[This message has been edited by JPDeni (edited August 30, 1999).]
Quote Reply
Re: Help with modifications for Classified use. In reply to
It worked perfectly! That should be exactly what I need. Here's a couple more small requests. If I wanted to charge for an attached photo, and add that to the amount for the description, how do I go about that?

Also, how do I implement a minimum charge? So for example, if they try and cram it all in the title field, and leave the description field blank.

Thanks again! Much appreciated. Smile

Frank
Quote Reply
Re: Help with modifications for Classified use. In reply to
Regarding the photo -- have you installed the file upload mod and do you know it's working? Or are you using another means of attaching a photo?

As for a minimum charge, you would change

Code:
$in{'Cost'} = sprintf("%.2f",$ad_length * $cost_per_char[$in{'Days'}] * $in{'Days'});

to

Code:
$in{'Cost'} = sprintf("%.2f",($ad_length * $cost_per_char[$in{'Days'}] * $in{'Days'}) + $minimum);

It probably would be best to define $minimum in your .cfg file.[/code]
------------------
JPD





Quote Reply
Re: Help with modifications for Classified use. In reply to
(The file upload mod is actually from my site. Smile )

The reason the upload feature is only available after a record is added is that it must be certain of the key value for the record.

I think I could work out something with a checkbox on the add form which, if checked, would send the user to the form to upload the file. After the upload it would go to the preview screen. If they didn't want to upload a file, they would go straight to the preview screen. Would that work for you?



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





Quote Reply
Re: Help with modifications for Classified use. In reply to
I'm using the upload mod from this site. The only problem I'm seeing is that it asks for the photo after the amount is calculated.

What I'm thinking needs to happen in this case is there is a checkbox in the preview section that says "attach photo to this record" or something of the like. If it's checked, it will execute the upload mod, otherwise it'll skip it. And if the upload of the photo is successful, it will add whatever amount to the total.

Frank
Quote Reply
Re: Help with modifications for Classified use. In reply to
That would work perfectly! Thank you! Smile

Frank
Quote Reply
Re: Help with modifications for Classified use. In reply to
I offered it to you and now I don't know how to do it. The problem is that the record isn't saved until after the preview, so there's no way to retrieve it after the file is uploaded. I hadn't thought about that before.

I'm going to have to think about this some more. I don't know if I can come up with a solution or not.


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





Quote Reply
Re: Help with modifications for Classified use. In reply to
Emailing the record is not a problem at all. Since I know you have installed the secure password lookup, I know you have the $mailprog and $admin_email variables already set.

In sub html_add_success, add

Code:
%rec = %in;
open (MAIL, "$mailprog") &#0124; &#0124; &cgierr("Can't start mail program");
print MAIL "To: $rec{'email'}\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $html_title Ad Confirmation\n\n";

# add whatever fields you want to from the record, using $rec{'fieldname'} variables.
# start each line with print MAIL, just like in the email message from the secure_password_lookup mod

close MAIL;

You can put this either at the very beginning or the very end of sub html_add_success.


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





Quote Reply
Re: Help with modifications for Classified use. In reply to
Sounds good. Maybe we can work this piece while you're thinking about it. After the users accepts the ad in the preview section, how can I set it up so it emails them back their entire ad, including the cost?

Thanks Smile
Frank
Quote Reply
Re: Help with modifications for Classified use. In reply to
I added that code to the end of html_add_sucess, but it's not sending out email. Any ideas?

Thanks,
Frank
> >