[ic] Automated Backorder System/Username change - SOURCE

Russ Mann interchange-users@lists.akopia.com
Mon Jul 2 23:59:00 2001


This is a multi-part message in MIME format.

------=_NextPart_000_0026_01C10342.6B9C8830
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

changelogin.html and changelogindone.html are both needed to change the
login username.

stock-alert.html and stock-alert-added.html are necessary for the backorder
system.
backorder_automation_script.pl is the cronned script for the backorder
system.  I couldn't figure out a better way to handle that.

I know some of this code isn't the most efficient in the world, and if
anyone makes any of this stuff work better, or faster, or anything, please
email a copy to me.

Thanks,

Russ
tech@khouse.org

------=_NextPart_000_0026_01C10342.6B9C8830
Content-Type: text/html;
	name="changelogindone.html"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="changelogindone.html"

[comment]=0A=
ui_template: Yes=0A=
ui_template_name: leftonly=0A=
[/comment]=0A=
[set page_title]__COMPANY__ -- Shipping Address Added[/set]=0A=
[set page_banner]Shipping Address Added[/set]=0A=
@_LEFTONLY_TOP_@=0A=
=0A=
<!-- BEGIN CONTENT -->=0A=
<hr noshade color=3D"#000000">=0A=
<center><font face=3D"Arial" size=3D"4">Change Login =
Email</font></center>=0A=
<hr noshade color=3D"#000000">=0A=
<p align=3D"left">=0A=
[flag type=3Dwrite tables=3D"userdb ship_addresses transactions =
orderline"]=0A=
[perl tables=3D"userdb ship_addresses transactions orderline"]=0A=
my @tables =3D (=0A=
		"userdb",=0A=
		"ship_addresses",=0A=
		"transactions",=0A=
		"orderline"=0A=
		);=0A=
my $sql_req =3D '';=0A=
$login_email =3D "$Values->{login_email}";=0A=
$old_username =3D "$Session->{username}";=0A=
=0A=
if ($login_email =3D~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||=0A=
  $login_email !~ =
/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)=0A=
{=0A=
$Scratch->{'update_ok'} =3D 0;=0A=
return "<b>$login_email</b> is not a valid email address.  No update =
possible.";=0A=
}=0A=
if ($login_email eq $old_username) {=0A=
$Scratch->{'update_ok'} =3D 0;=0A=
return <<EOP;=0A=
<b>$login_email</b> is the same as <b>$old_username</b>.  No update =
possible.=0A=
EOP=0A=
} =0A=
if ($Db{userdb}->record_exists($login_email)) {=0A=
$Scratch->{'update_ok'} =3D 0;=0A=
return <<EOP;=0A=
<b>$login_email</b> is already in use.  If you have more than one =
account with us, =0A=
please email <a href=3D"[area help/contact]"><b>Customer Service</b></a> =
to get this resolved.=0A=
EOP=0A=
}=0A=
=0A=
#$login_email =3D $Tag->filter('sql',$login_email);=0A=
#$old_username =3D $Tag->filter('sql',$old_username);=0A=
=0A=
foreach $table(@tables) {=0A=
$sql_req =3D "UPDATE $table SET username =3D '$login_email' WHERE =
username =3D '$old_username'";=0A=
$Db{$table}->query("$sql_req");=0A=
}=0A=
$Scratch->{'update_ok'} =3D 1;=0A=
=0A=
return <<EOP;=0A=
Your login email address has been changed to <b>$login_email</b>.  You =
will need to =0A=
<a href=3D"[area login]"><b>Login</b></a> again with your new address.=0A=
EOP=0A=
[/perl]=0A=
=0A=
[if scratch update_ok]=0A=
<!--=0A=
[userdb logout]=0A=
-->=0A=
[else]=0A=
<p>=0A=
<a href=3D"[area changelogin]"><font size=3D"2"><b><font =
__FFACE__>BACK</font></b></font></a>=0A=
</p>=0A=
[/else]=0A=
[/if]=0A=
<!-- END CONTENT -->=0A=
@_LEFTONLY_BOTTOM_@=0A=

------=_NextPart_000_0026_01C10342.6B9C8830
Content-Type: text/html;
	name="changelogin.html"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="changelogin.html"

[comment]=0A=
ui_template: Yes=0A=
ui_template_name: leftonly=0A=
[/comment]=0A=
=0A=
[set component_after][/set]=0A=
[set members_only]1[/set]=0A=
[set page_banner]Shipping Addresses[/set]=0A=
[set component_hsize]3[/set]=0A=
[set hbanner][/set]=0A=
[set component_before][/set]=0A=
[set hpromo_type]specials[/set]=0A=
[set page_title]__COMPANY__ - Change Login Email[/set]=0A=
@_LEFTONLY_TOP_@=0A=
=0A=
<!-- BEGIN CONTENT -->=0A=
<hr noshade color=3D"#000000">=0A=
<center><font face=3D"Arial" size=3D"4">Change Login =
Email</font></center>=0A=
<hr noshade color=3D"#000000">=0A=
<p align=3D"left">=0A=
This form is used to change your login email address.  There are some =
reasons to do=0A=
this, and some reasons not to.  Someone should explain those.  Pax.=0A=
<br>=0A=
Your current login email address is: <b>[data session username]</b>.=0A=
<br>=0A=
<form action=3D"[process-target]" method=3D"post">=0A=
<input type=3D"hidden" name=3D"mv_todo" value=3D"return">=0A=
<input type=3D"hidden" name=3D"mv_nextpage" value=3D"changelogindone">=0A=
<table width=3D"450" border=3D"1" cellspacing=3D"0" cellpadding=3D"3" =
bordercolor=3D"#000000">=0A=
<tr><td align=3D"right">=0A=
<b><font __FFACE__ size=3D"1">New Login Email Address</font></b>=0A=
</td><td>=0A=
<input type=3D"text" name=3D"login_email" value=3D"[data session =
username]" size=3D"40">=0A=
</td></tr>=0A=
</table>=0A=
<p>=0A=
<input type=3D"submit" value=3D"Change Login Email Address">=0A=
</form>=0A=
=0A=
<!-- END CONTENT -->=0A=
=0A=
@_LEFTONLY_BOTTOM_@=0A=

------=_NextPart_000_0026_01C10342.6B9C8830
Content-Type: application/octet-stream;
	name="backorder_automation_script.pl"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="backorder_automation_script.pl"

#!/usr/bin/perl=0A=
use Mysql;=0A=
use Date::Manip;=0A=
=0A=
$host =3D 'localhost';=0A=
$database =3D 'database';=0A=
$user =3D 'sqluser';=0A=
$password =3D 'sqlpassword';=0A=
$table =3D 'stock_alert';=0A=
$mailprog =3D "/usr/sbin/sendmail -t";=0A=
=0A=
$dbh =3D Mysql->connect($host, $database, $user, $password);=0A=
$dbh->selectdb($database);=0A=
=0A=
$sql =3D "SELECT * FROM $table";=0A=
$sth =3D $dbh->query($sql);=0A=
$lines =3D $sth->numrows;=0A=
for ($ng =3D 0 ;$ng < $lines ;$ng++) {=0A=
$sth->dataseek($ng);=0A=
%row =3D $sth->fetchhash;=0A=
@hi =3D keys %row;=0A=
foreach $hi(@hi) {=0A=
		$$hi =3D $row{$hi};=0A=
		$$hi =3D~ s/'/\\'/g;=0A=
		}=0A=
$email =3D~ s/\@/\\\@/g;=0A=
if (!&is_backordered("$sku")) {=0A=
&mail_user("$sku","$email","$fname","$lname","$description","$author","$p=
rice","$date");=0A=
push (@delete_uids, $uid);=0A=
}=0A=
}=0A=
=0A=
foreach $d_uid (@delete_uids) {=0A=
$sql =3D "DELETE FROM $table WHERE uid =3D '$d_uid'";=0A=
$sth_del =3D $dbh->query($sql);=0A=
}=0A=
=0A=
sub is_backordered {=0A=
$sku =3D $_[0];=0A=
if (!$backorder_hash{$sku}) {=0A=
	if (!$quantity_hash{$sku}) {=0A=
my $sql_bo =3D "SELECT quantity FROM inventory WHERE sku =3D '$sku'";=0A=
my $sth_bo =3D $dbh->query($sql_bo);=0A=
$sth_bo->dataseek(0);=0A=
my $row_bo =3D $sth_bo->fetchrow;=0A=
$quantity_hash{$sku} =3D $row_bo;=0A=
		if ($quantity_hash{$sku} < 1) { =0A=
$backorder_hash{$sku} =3D "YES"; =0A=
		} else {=0A=
$backorder_hash{$sku} =3D "NO";=0A=
		}=0A=
	}=0A=
}=0A=
my $yesno;=0A=
if ($backorder_hash{$sku} eq "NO") {=0A=
$yesno =3D 0;=0A=
} else {=0A=
$yesno =3D 1;=0A=
}=0A=
=0A=
return ($yesno);=0A=
}=0A=
=0A=
sub mail_user {=0A=
my ($sku, $email, $fname, $lname, $description, $author, $price, $date) =
=3D @_;=0A=
my $url =3D "http://store.khouse.org/store/catalog/" . $sku . =
".html?;;BOSYS";=0A=
=0A=
open  (MAIL, "|$mailprog $email") || die "Can't open $mailprog $_";=0A=
print MAIL "To: $email\n";=0A=
print MAIL "From: webmaster\@khouse.org\n";=0A=
print MAIL "Subject: $description is now In Stock!\n\n";=0A=
print MAIL <<MAIL_TEXT__;=0A=
Hello $fname $lname,=0A=
=0A=
On $date you specified to be notified when =0A=
=0A=
"$description"=0A=
by $author =0A=
=0A=
came in stock.  Today this title became available.  =0A=
The price is: $price=0A=
=0A=
You can find this product here:=0A=
=0A=
$url=0A=
=0A=
Thank you and God Bless,=0A=
=0A=
Koinonia House Backorder Robot=0A=
=0A=
MAIL_TEXT__=0A=
=0A=
close(MAIL);=0A=
}=0A=

------=_NextPart_000_0026_01C10342.6B9C8830
Content-Type: text/html;
	name="stock-alert.html"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="stock-alert.html"

[comment]=0A=
ui_template: Yes=0A=
ui_template_name: leftonly=0A=
[/comment]=0A=
=0A=
[set component_after][/set]=0A=
[set members_only]0[/set]=0A=
[set page_banner]Stock Alerting[/set]=0A=
[set component_hsize]2[/set]=0A=
[set hbanner][/set]=0A=
[set component_before][/set]=0A=
[set hpromo_type]specials[/set]=0A=
[set page_title]__COMPANY__ -- Stock Alerting[/set]=0A=
@_LEFTONLY_TOP_@=0A=
=0A=
<!-- BEGIN CONTENT -->=0A=
[if session arg]=0A=
[seti code][data session arg][/seti]=0A=
[/if]=0A=
=0A=
[if value form_errors]=0A=
<table cellpadding=3D"8" border=3D"0">=0A=
<tbody>=0A=
<tr><td align=3Dleft valign=3Dtop><font __FFACE__ size=3D"2" =
color=3D"red">=0A=
<b>[value form_errors] [value name=3Dform_errors set=3D""]</b></font>=0A=
<br><br>=0A=
<font __FFACE__ size=3D"2">=0A=
Please try your request again.=0A=
</font></td></tr>=0A=
</tbody>=0A=
</table>=0A=
<p>=0A=
[/if]=0A=
=0A=
[seti bo_display][data table=3Dproducts column=3Ddisplay key=3D'[scratch =
code]'][/seti]=0A=
[seti bo_description][data table=3Dproducts column=3Ddescription =
key=3D'[scratch code]'][/seti]=0A=
[seti bo_author][data table=3Dproducts column=3Dauthor key=3D'[scratch =
code]'][/seti]=0A=
[seti bo_price][data table=3Dproducts column=3Dprice key=3D'[scratch =
code]'][/seti]=0A=
<table border=3D"0" cellspacing=3D"0" cellpadding=3D"3" align=3D"left">=0A=
<tr><td valign=3D"top" align=3D"center"> =0A=
[page href=3D"[scratch code]" send=3D1]<img src=3D"/thumbnails/[scratch =
bo_display]" border=3D"0" align=3D"left">=0A=
<big>[scratch bo_description]</big></a><br>=0A=
by [scratch bo_author]=0A=
<br><b>[currency][scratch bo_price][/currency]</b>=0A=
</td></tr>=0A=
<tr><td valign=3D"top">=0A=
<p><font __FFACE__ size=3D"2" color=3D"#000000">=0A=
Please complete the form below and we will contact you once the item you =
have selected becomes=0A=
available. This is a complementary feature and you are not in any way =
obligated to purchase=0A=
the item.=0A=
</font></p>						=0A=
</td>			=0A=
</tr>=0A=
<tr>=0A=
<td valign=3D"top" colspan=3D"3">=0A=
<p><font __FFACE__ size=3D"2" color=3D"#2163BD">=0A=
You may also pre-order the item. When the item becomes available, you =
will be=0A=
notified via email and the order will be shipped the same day.=0A=
<br>=0A=
<a href=3D"[area href=3Dorder arg=3D"[scratch code]"]">Click Here To =
Preorder</a>=0A=
</font></p>						=0A=
</td>			=0A=
</tr>=0A=
<tr><td>&nbsp;</td></tr>			  =0A=
<tr> =0A=
<td colspan=3D"3">=0A=
<table width=3D"350" border=3D"1" cellspacing=3D"0" cellpadding=3D"0" =
bordercolorlight=3D"#000000" bordercolordark=3D"#000000">=0A=
<tr> =0A=
<td> =0A=
<table width=3D"400" border=3D"0" cellspacing=3D"0" cellpadding=3D"0" =
align=3D"center">=0A=
<tr> =0A=
<td bgcolor=3D"#2163BD"><font __FFACE__><b><font size=3D"1" =
color=3D"#FFFFFF">Contact Information</font></b></font></td>=0A=
<td bgcolor=3D"#2163BD"><i><font __FFACE__ size=3D"1" =
color=3D"#FFFFFF">&nbsp;</font></i></td>=0A=
<td bgcolor=3D"#2163BD">&nbsp;</td>=0A=
<td bgcolor=3D"#2163BD">&nbsp;</td>=0A=
</tr>=0A=
[set check_alert_form]=0A=
[if !value email]=0A=
form_errors=3DWe must have an email address in order to notify you.=0A=
mv_nextpage=3D@@MV_PAGE@@=0A=
[else]=0A=
mv_nextpage=3Dstock-alert-added=0A=
[/else]=0A=
[/if]=0A=
[/set]=0A=
[set send-alert]1[/set]=0A=
<form action=3D"[process-target]" method=3D"post">=0A=
<input type=3D"hidden" name=3D"mv_todo" value=3D"return">=0A=
<input type=3D"hidden" name=3D"mv_check" value=3D"check_alert_form">=0A=
<tr><td> =0A=
<div align=3D"right"><font __FFACE__ size=3D"1">[error name=3Dfname =
std_label=3D"First Name" required=3D1]</font></div>=0A=
</td><td> =0A=
<div align=3D"left"><b><font __FFACE__ size=3D"1"> =0A=
<input type=3D"text" name=3D"fname" value=3D"[value fname]" size=3D"20" =
maxlength=3D"20">=0A=
</font></b></div>=0A=
</td>=0A=
<td><div align=3D"right"><font __FFACE__ size=3D"1">[error name=3Dlname =
std_label=3DLast required=3D1]</font></div></td>=0A=
<td align=3D"left">=0A=
<input type=3D"text" name=3D"lname" value=3D"[value lname]" size=3D"20">=0A=
</td></tr><tr><td>=0A=
<div align=3D"right"><font __FFACE__ size=3D"1">[error name=3Demail =
std_label=3D"Email Address" required=3D1]</font></div>=0A=
</td><td colspan=3D"3">=0A=
<b><font __FFACE__ size=3D"1"> =0A=
<input type=3D"text" name=3D"email" value=3D"[value email]" size=3D"51">=0A=
</font></b></td>=0A=
</tr>=0A=
</table>=0A=
</td>=0A=
</tr>=0A=
</table>=0A=
<p>=0A=
<input type=3D"hidden" name=3D"bo_sku" value=3D"[scratch code]">=0A=
<input type=3D"hidden" name=3D"bo_description" value=3D"[scratch =
bo_description]">=0A=
<input type=3D"hidden" name=3D"bo_author" value=3D"[scratch bo_author]">=0A=
<input type=3D"hidden" name=3D"bo_price" value=3D"[scratch bo_price]">=0A=
<input type=3D"submit" value=3D"Submit Request">=0A=
</form>=0A=
=0A=
</td>=0A=
</tr>=0A=
</table>=0A=
=0A=
=0A=
<!-- END CONTENT -->=0A=
=0A=
@_LEFTONLY_BOTTOM_@=0A=

------=_NextPart_000_0026_01C10342.6B9C8830
Content-Type: text/html;
	name="stock-alert-added.html"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="stock-alert-added.html"

[comment]=0A=
ui_template: Yes=0A=
ui_template_name: leftonly=0A=
[/comment]=0A=
=0A=
[set component_after][/set]=0A=
[set members_only]0[/set]=0A=
[set page_banner]Stock Alerting[/set]=0A=
[set component_hsize]2[/set]=0A=
[set hbanner][/set]=0A=
[set component_before][/set]=0A=
[set hpromo_type]specials[/set]=0A=
[set page_title]__COMPANY__ - Stock Alerting[/set]=0A=
@_LEFTONLY_TOP_@=0A=
=0A=
<!-- BEGIN CONTENT -->=0A=
[if session arg]=0A=
[seti code][data session arg][/seti]=0A=
[/if]=0A=
[seti bo_time][tag time]%Y-%m-%d[/tag][/seti]=0A=
[flag type=3Dwrite tables=3D"stock_alert"]=0A=
[perl tables=3D"stock_alert"]=0A=
=0A=
$sql_req =3D "=0A=
INSERT INTO stock_alert SET=0A=
sku =3D '$Values->{bo_sku}',=0A=
price =3D '". $Tag->filter('sql', $Values->{bo_price})."',=0A=
description =3D '". $Tag->filter('sql', $Values->{bo_description})."',=0A=
author =3D '". $Tag->filter('sql', $Values->{bo_author})."',=0A=
fname =3D '". $Tag->filter('sql', $Values->{fname})."',=0A=
lname =3D '". $Tag->filter('sql', $Values->{lname})."',=0A=
email =3D '". $Tag->filter('sql', $Values->{email})."',=0A=
date =3D '$Scratch->{bo_time}'=0A=
";=0A=
$Db{stock_alert}->query("$sql_req");=0A=
return;=0A=
[/perl]=0A=
=0A=
<table cellpadding=3D"8" border=3D"0">=0A=
<tbody>=0A=
<tr><td align=3D"left" valign=3D"top"><font __FFACE__ size=3D"2">=0A=
<b>Your request has been sent sucessfully.</b></font>=0A=
<br><br>=0A=
<font __FFACE__ size=3D"2">=0A=
We will contact you once your selected item becomes available.<br><br>=0A=
Thank you for your interest in our products.=0A=
</font><p>=0A=
Back to <a href=3D"[area href=3D"[scratch code]"]">[value =
bo_description]</a>=0A=
</p></td></tr>=0A=
</tbody>=0A=
</table>=0A=
<p>=0A=
	=0A=
=0A=
[set name=3Dalert_added interpolate=3D1]=0A=
=0A=
[comment] SEND REPORT OF NEW ALERT ENTRY [/comment]=0A=
=0A=
[email=0A=
to=3D"[value email]"=0A=
subject=3D"__COMPANY__ - Stock Alert Request"=0A=
from=3D"__COMPANY__ <__EMAIL_INFO__>"=0A=
reply=3D"__COMPANY__ <__EMAIL_INFO__>"]=0A=
=0A=
Hello and thank you for your interest in __COMPANY__ products.=0A=
=0A=
We have received your in-stock alert notification and we will contact you=0A=
once the selected item becomes available.=0A=
=0A=
This a confirmation of your request submission.=0A=
=0A=
         Name: [value fname] [value lname]=0A=
        Email: [value email]=0A=
=0A=
        Title: [value bo_description]=0A=
       Author: [value bo_author]=0A=
Current Price: [currency][value bo_price][/currency]=0A=
=0A=
You can find this product here:=0A=
=0A=
http://store.khouse.org/store/catalog/[value bo_sku].html?;;BOSYS=0A=
=0A=
Thank you and God Bless,=0A=
=0A=
Koinonia House Backorder Robot=0A=
=0A=
[/email]=0A=
[email=0A=
to=3D"__COMPANY__ <webmaster@khouse.org>"=0A=
subject=3D"__COMPANY__ - Stock Alert Request"=0A=
from=3D"[value email]"=0A=
reply=3D"[value email]"]=0A=
=0A=
Hello and thank you for your interest in __COMPANY__ products.=0A=
=0A=
We have received your in-stock alert notification and we will contact you=0A=
once the selected item becomes available.=0A=
=0A=
This a confirmation of your request submission.=0A=
=0A=
         Name: [value fname] [value lname]=0A=
        Email: [value email]=0A=
=0A=
        Title: [value bo_description]=0A=
       Author: [value bo_author]=0A=
Current Price: [currency][value bo_price][/currency]=0A=
=0A=
You can find this product here:=0A=
=0A=
http://store.khouse.org/store/catalog/$sku.html?;;BOSYS=0A=
=0A=
Thank you and God Bless,=0A=
=0A=
Koinonia House Backorder Robot=0A=
=0A=
[/email]=0A=
[/set]=0A=
=0A=
<!-- END CONTENT -->=0A=
=0A=
@_LEFTONLY_BOTTOM_@=0A=

------=_NextPart_000_0026_01C10342.6B9C8830--