#!/usr/bin/perl
###############################################
##           Version 12.05.97                ##
###############################################
##   (c)1997 Daevid Vincent                  ##
## Unauthorized use of this code is strictly ##
## prohibited and subject to criminal        ##
## prosecution and or death                  ##
###############################################
##   Emails new CD's to list subscribers     ##
###############################################

## just change the two email addresses below.

############################################################################################################
############################################################################################################
# copy the ys_defaults.phtml file's settings into here.
############################################################################################################
############################################################################################################

## Perl requires that the @ be escaped by a \ character so be aware of that one...
$default_email_address		 = "daevid\@TheMatrix.com";  
$default_store_name			 = "Young Systems";
$default_site_url			 = "http://209.20.180.170/~youngsys";

$default_db_user_name         = "youngsys";
$default_db_password          = "andrea";
$default_db_name              = "cris_cddb";
$default_db_server_name       = "localhost";

############################################################################################################
############################################################################################################
# it's often good to spoof so that you don't get retards emailing you back questions to the wrong address
$default_spoofed_email_from	  = "Young Systems Server";
# change this to something like mystore-list\@mystore.com
$default_list_email	  		  = $default_email_address;  
############################################################################################################
############################################################################################################

use Mysql;
require 'ctime.pl';
require "./mail-lib.pl";

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$today = sprintf "%02d%02d%02d",$mday,++$mon,$year;

 $dbh = Mysql->Connect("localhost",$default_db_name,$default_db_user_name,$default_db_password) or die "ERROR $Mysql::db_errstr\n";

 $dbh->SelectDB($default_db_name);

#+------------+--------------------------------------+-------+--------+-------+-------+
#| upc        | artist_title                         | label | date   | price | cd_id |
#+------------+--------------------------------------+-------+--------+-------+-------+

 $sth = $dbh->Query ( "SELECT artist_title,date FROM CD_Table WHERE date like '$today' ORDER BY date,artist_title" )
 	or die "Error performing query on $default_db_name CD_Table: $Mysql::db_errstr\n";

$found = $sth->numrows;

if ($found) {
	$messagesubject = "$found CDs Added to ".$default_store_name." Database";
	$messagebody = "\n\n$found CDs Have been added to the ".$default_store_name." Database:\n";
	$messagebody .= $default_site_url."/query.phtml\n\n";

	 while (($date,$artist_title) = $sth->FetchRow) {
		$messagebody .= substr($date,2,2);
		$messagebody .= ".";
		$messagebody .= substr($date,4,2);
		$messagebody .= ".";
		$messagebody .= substr($date,0,2);
		$messagebody .= "  $cd_title ($artist_title)\n";
	 } # while FetchRow

	###&send_mail(FROM:,TO:,"$messagesubject","$messagebody");
	### Note: the FROM: name can be bogus if you so desire to "spoof" an email address.
	&send_mail($default_spoofed_email_from,$default_list_email,"$messagesubject","$messagebody");
} # if found 

exit 0;
