annotate mailout.pl @ 2:791e87929f83 default tip

Added tag RELENG_1_0 for changeset d95e74cd12f4
author darius@midget.dons.net.au
date Tue, 23 Oct 2007 10:07:21 +0930
parents d95e74cd12f4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
1 #!/usr/local/bin/perl
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
2
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
3 use DBI;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
4
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
5 $user = "";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
6 $passwd = "";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
7 $dbname = "scs";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
8
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
9 MAIN:
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
10 {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
11 # Work out the date 7 days ahead
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
12 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time + (24 * 60 * 60 * 7));
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
13
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
14 $mon += 1; #Months start from 0!!
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
15
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
16 $date = "$year-$mon-$mday";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
17
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
18 # Connect to the Database
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
19 $dbh = DBI->connect("dbi:Pg:dbname=$dbname", $user, $passwd) || bad_exit("Couldn\'t open DB - $sth->errstr");
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
20
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
21 # Prepare the select statement
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
22 $sth1 = $dbh->prepare("SELECT eventid, name, description, when, duration, cost, contact FROM events WHERE when > \'$date\' and when < (\'$date\'::datetime + \'24 hours\'::timespan)") || bad_exit("Prepare for description failed - $sth1->errstr");
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
23
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
24 # Execute it
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
25 $numrows1 = $sth1->execute || bad_exit("Execute for description failed - $sth1->errstr");
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
26
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
27 while (@array = $sth1->fetchrow_array) {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
28 $eventid = @array[0];
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
29 $name = @array[1];
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
30 $text = @array[2];
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
31 $when = @array[3];
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
32 $length = @array[4];
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
33 $cost = @array[5];
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
34 $contact = @array[6];
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
35
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
36 $mailtxt = sprintf("Hi,\nThis is an automated letter reminding you of an\nevent on %s.\nIt should go for about %s.\n\n%s\n\nIt will cost %s.\n\nIf you want more information contact\n%s.\n", $when, $length, $text, $cost, $contact);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
37
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
38 # Prepare the select statement
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
39 $sth2 = $dbh->prepare("SELECT mailto(\'$eventid\')") || bad_exit("Couldn\'t prepare ppl list - $sth->errstr");
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
40
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
41 $numrows2 = $sth2->execute || bad_exit("Couldn\'t execute ppl list - $sth->errstr");
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
42
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
43 while (@array = $sth2->fetchrow_array)
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
44 {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
45 print "Email this\n---\n$mailtxt\n---\nTo this person @array[0]\n";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
46 }
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
47
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
48 $sth2->finish || bad_exit("Couldn\'t finish for ppl list - $sth->errstr");
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
49 }
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
50
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
51 $sth1->finish || bad_exit("Couldn\'t finish for mailtxt - $sth->errstr");
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
52 }
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
53
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
54 sub bad_exit
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
55 {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
56 print "The following error occured - $_[0]";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
57
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
58 exit(0);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
59 }