#!/usr/bin/perl # # BECANADA - ISELL Classifieds Script # Website: http://www.becanada.com/isell/ # E-Mail : sales@becanada.com # Version 3.1 - Add on for Paid Ads Processing system. # Copyright Jan 2003 # # !!!!! WARNING !!!!!! # # # ! DO NOT MODIFY below this line, you will be in violation # of copyrights, and this program will cease to function. # # You may also cause harm to your data files, and server. # # ################################################################## # # Important Settings. # $worth=7; $paypal='txfooddude@internet-grocer.net'; $paypalurl='http://www.internet-grocer.net/cgi/classif/paypal.cgi'; $check2you='n/a'; $ID10="1"; $ID20="2"; $ID50="3"; # # Need product IDS from check2you for 3 links. # # credits are each 'worth' days each. print "Content-type: text/html\n\n"; print qq~

Credits to Extend your Ad

~; $fl="credits.txt"; open(FILE, $fl ) || print "I can't open that file\n"; @credit = ; close(FILE); read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } if ($FORM{'action'} eq "") { print qq~ Use Credits from account #:

Email Address:

To Use Credits - Click here:

To Purchase More Credits Instantly - Click here:

New User? To Setup a New Account - Click here:

~; } if ($FORM{'action'} eq "Setup New Account") { print qq~ Setup A New Account:

Please fill in the following fields to setup your account.

First Name:

Last Name:

E-Mail Address:


~; } if ($FORM{'action'} eq "Confirm New Account") { $fl2="credit-count.txt"; open(FILE, $fl2 ) || print "I can't open that file\n"; $id = ; close(FILE); open(HTML, ">>$fl") || print "I can't create that file\n"; print HTML "$id,$FORM{'firstname'},$FORM{'lastname'},$FORM{'email'},0,\n"; close(HTML); push(@credit,"$id,$FORM{'firstname'},$FORM{'lastname'},$FORM{'email'},0,\n"); $FORM{'accid'}=$id; $FORM{'approved'}=$id; $id++; open(HTML, ">$fl2") || print "I can't create that file\n"; print HTML "$id"; close(HTML); print "Account added...

Your ID Number is: $FORM{'accid'}
Your Email is: $FORM{'email'}

You can now purchase credits instantly...

"; $FORM{'action'} = "Purchase Credits"; } if ($FORM{'action'} eq "Purchase Credits") { $match=0; for ($i=0; $i<@credit ; $i++) { @words=split(/,/,@credit[$i]); if ($FORM{'approved'} eq @words[0] || $FORM{'accid'} eq @words[0] ) { print qq~

To Purchase Credits, click on ONE of the following buttons below - A new window will open.
Once your payment is accepted you will be able to use your credits immediately, close the payment window and click on 'Use' button at the top of the screen.

Use Paypal, Visa, Mastercard, American Express or Online E-Check.

Each "credit" is worth $worth days of ad[s] extension. Credits do not expire, and can be used on any ad or ads at our classifieds site at any time, instantly. If you currently have credits in your account [ $FORM{'accid'} ] , today's purchase will be ADDED to that balance.

Purchase 10 Credits only \$10 .
Purchase 20 Credits only \$15 [ save 25% ]
Purchase 50 Credits only \$25 [ save 50% ] !
~; $match=1; # Check2you members will have to enter ID# at end of purchase. # Add Paypal / Check to you links here. # exit; } } if ($match eq "0") { print qq~No match to ID.

To setup an account and purchase credits click this button:

~; } } # # Check database, if credits, approve and select update. # if ($FORM{'action'} eq "Use") { $match=0; for ($i=0; $i<@credit; $i++) { @words=split(/,/,@credit[$i]); if ($FORM{'accid'} eq @words[0] && $FORM{'email'} eq @words[3] ) { print qq~@words[0] , owned by @words[1] @words[2] @words[3] has @words[4] Credits.

Each credit is worth $worth days of ad extension.

~; $d=$worth; if (@words[4] > 0) { print qq~Extend you ad by [please select one]:

~; for ($x=1;$x<@words[4];$x++) { print qq~$d Days
~; $d=$d+$worth; if ($d>360) { last;} } print qq~

~; } else { print qq~You have no credits left, to purchase more instantly click the button below:

~; } $match=1; last; } } if ($match eq "0") { print qq~No match to ID # $FORM{'accid'} and email $FORM{'email'} .

To setup an account and purchase credits click this button:

~; exit; } print ""; } # # USe alloted credits, debit credits, update ads. # if ($FORM{'action'} eq "Use Credits" && $FORM{'approved'} ne "" ) { for ($i=0; $i<@credit ; $i++) { @words=split(/,/,@credit[$i]); if ($FORM{'approved'} eq @words[0]) { # # Now update ad in database HERE with new expiry date. # ($cg,$data,$singlead,$extra1) = split(/\|/,$ENV{'QUERY_STRING'}); $singlead =~s/[?]//g; # # Get -- , category, time string, email to confirm # open(FILE, "category.txt" ) || print "I can't open that file\n"; @cats = ; close(FILE); ($fl2,$nm,$dec) = split(/\|/,@cats[$data]); open(HTML,$fl2) || print "I can't access that file\n"; @count = ; close(HTML); print "Updating ad in $nm , $dec ... "; $dup="0"; for ($a=0; $a<@count; $a++) { @words2=split(/\|/,@count[$a]); @words2[12] =~s/\n//g; @words2[12] =~s/[?]//g; if ( (@words2[12] eq $singlead || @words2[12] eq ("hold" . $singlead )) && @words2[9] eq $extra1 ) { if (index(@words2[12],"hold") > -1 ) { @words2[12]=substr(@words2[12],4); } @words2[12]=@words2[12] + (86400 * ($FORM{'adlen'} * $worth) ) ; @words2[12]="?" . @words2[12]; chomp(@words2); @count[$a]=join("|",@words2) . "\n"; ; $dup="1"; $t=$worth * $FORM{'adlen'} ; print "

Your Ad is now live and expiry time has been extended by $t days.

"; last; } } if ($dup eq "1") { &get_file_lock("$fl2.lock"); open(FILE, ">$fl2") || print "I can't create that file\n"; print FILE @count ; close(FILE); &release_file_lock("$fl2.lock"); @words[4]=@words[4] - $FORM{'adlen'}; print qq~Credit[s] Debted today: $FORM{'adlen'} .

You have @words[4] credit[s] left.

~; @credit[$i]=join(",",@words) . "\n"; open(HTML, ">$fl") || print "I can't create that file\n"; print HTML @credit; close(HTML); print "

Ad Updated. \n"; } else { print "ad not found [you may have already updated it]."; } # # End update ad. # last; } } } # # Subs # sub get_file_lock { local ($lock_file) = @_; local ($endtime); $endtime = 500; $endtime = time + $endtime; while (-e $lock_file && time < $endtime) { sleep(1); } open(LOCK_FILE, ">$lock_file") || &file_open_error ("$lock_file", "Lock File Routine", __FILE__, __LINE__); } sub release_file_lock { local ($lock_file) = @_; close(LOCK_FILE); unlink($lock_file); }