#!/usr/bin/perl -w # # Membership list email/admin program # use strict; use DBI; my $statusStr = ""; my $address; my $subject; my $username=""; my $password=""; my $database=""; my $server="localhost"; my $size; my @lines; my $newstext; my $temphtml=""; my $template; my $defaulttitle="New web site"; my $defaultmsg="Dear Sir/Madam,\n\nThis is a one-off message to let you know about a new web site."; my $dbh = DBI->connect("DBI:mysql:$database:$server",$username,$password); &readList(); # get membership list # # Send a newsletter to all of the members # if (($input{"sendNewsletter"}) & ($input{"AllMembers"} eq "Yes")) { # $address = "mmilner\@actis.co.uk"; # for testing purposes $address = "admin\@somwhere.net"; # for testing purposes $subject=$input{"newsTitle"}; $newstext=$input{"newsText"}; # &sendMail(); } # # Send a newsletter to the (selected) members # if ($input{"NewsletterConfirm"}) { $address = "admin\@somwhere.net"; # for testing purposes $subject=$input{"title"}; $newstext=$input{"text"}; &sendMailtoSelected(); } # # Add a new user to the database # if ($input{"AddUser"} eq "1") { my $query="insert into bsmailinglist (user_name,user_type,centre_name,centre_number,email,member,last_mailed,optout,fore_name,middle_names,sur_name) values (?,?,?,?,?,?,?,?,?,?,?)"; my $sth = $dbh->prepare($query); $size = $sth->execute($input{'username'},$input{'usertype'},$input{'centre'},$input{'centrenum'},$input{'email'},$input{'member'},$input{'lastmailed'},$input{'optout'},$input{'forename'},$input{'midname'},$input{'surname'}); } # # Edit a users details # if ($input{"EditUser"} eq "1") { my $query="update bsmailinglist set user_name=?,user_type=?,centre_name=?,centre_number=?,email=?,member=?,last_mailed=?,optout=?,fore_name=?,middle_names=?,sur_name=? where id=$input{'recid'}"; my $sth = $dbh->prepare($query); $size = $sth->execute($input{'username'},$input{'usertype'},$input{'centre'},$input{'centrenum'},$input{'email'},$input{'member'},$input{'lastmailed'},$input{'optout'},$input{'forename'},$input{'midname'},$input{'surname'}); my $row = $sth->fetchrow_hashref(); } # # Delete a user from the database # if ($input{"DeleteUser"} eq "1") { my $query="delete from bsmailinglist where id=$input{'recid'}"; my $sth = $dbh->prepare($query); $size = $sth->execute(); } my $font = qq^^; #print "Content-type: text/plain\n\ntest\n"; # desperate debugging only! # # now build the forms to be displayed # $template = < BSOL Administration Page $font

BSOL Administration Page

$statusStr

EOFHTML &readList(); # get latest membership list if (($input{"sendNewsletter"}) & ($input{"AllMembers"} eq "No")) { # email selected members? my $recno=0; $template .= qq^

List of users:

\n^; $template .= qq^
${font}

Choose users to send the message to:

\n^; $template .= qq^

Title: $input{"newsTitle"}

\n^; $template .= qq^Message:

\n\n^; my $query="select * from bsmailinglist where optout != 'y' order by user_name"; my $sth = $dbh->prepare($query); $size = $sth->execute(); $template .= qq^\n^; while (my $row = $sth->fetchrow_hashref()) { $recno++; if ($$row{'centre_name'} eq "my test centre") { $template .= qq^\n^; } elsif ($$row{'member'} eq "y") { $template .= qq^\n^; } else { $template .= qq^\n^; } } $template .= qq^
$fontUser details$fontEmail?
$fontId: $$row{'id'}, User: $$row{'user_name'}, Centre: $$row{'centre_name'},
Email: $$row{'email'}, member=$$row{'member'}, last emailed: $$row{'last_mailed'}
$fontId: $$row{'id'}, User: $$row{'user_name'}, Centre: $$row{'centre_name'},
Email: $$row{'email'}, member=$$row{'member'}, last emailed: $$row{'last_mailed'}
$fontId: $$row{'id'}, User: $$row{'user_name'}, Centre: $$row{'centre_name'},
Email: $$row{'email'}, member=$$row{'member'}, last emailed: $$row{'last_mailed'}

\n

Back\n^; $sth = undef; $dbh->disconnect; # # Add a user - display form # } elsif ($input{"Add"} eq "Add") { $template .= <Add user details

Forename:
Middle names:
Surname:
Login name:
User type:
Centre name:
Centre number:
Email address:
Has the user opted out of receiving emails? (y or n)
Is the user a member? (y or n)

Date last emailed: (yyyy/mm/dd)

Back

EOFHTML # # Edit a user - display form # } elsif ($input{"Edit"} eq "Edit") { my $query="select * from bsmailinglist where id=$input{'member'}"; my $sth = $dbh->prepare($query); $size = $sth->execute(); my $row = $sth->fetchrow_hashref(); $template .= <Amend user details

Forename:
Middle names:
Surname:
Login name:
User type:
Centre name:
Centre number:
Email address:
Has the user opted out of receiving emails? (y or n)
Is the user a member? (y or n)

Date last emailed: (yyyy/mm/dd)

Back

EOFHTML $sth = undef; $dbh->disconnect; # # Delete a user - display confirmation form # } elsif ($input{"Delete"} eq "Delete") { my $query="select * from bsmailinglist where id=$input{'member'}"; my $sth = $dbh->prepare($query); $size = $sth->execute(); my $row = $sth->fetchrow_hashref(); $template .= <Delete a user

User name:
Centre name:

Back

EOFHTML $sth = undef; $dbh->disconnect; # # Send email to selected user. (Display initial form.) # } elsif ($input{"mail"}) { my $query="select * from bsmailinglist where id=$input{'member'}"; my $sth = $dbh->prepare($query); $size = $sth->execute(); my $row = $sth->fetchrow_hashref(); $template .= <Send email to selected user

Name: $$row{'user_name'} ($$row{'fore_name'} $$row{'middle_names'} $$row{'sur_name'}) Centre: $$row{'centre_name'}
Email: $$row{'email'} Has the user opted out of receiving emails? $$row{'optout'}
Date last emailed: $$row{'last_mailed'}
Confirm you wish to send this person an email:

Subject line:

Newsletter text:

Back

EOFHTML $sth = undef; $dbh->disconnect; # # Send email to selected user. (Display formmail form.) # } elsif ($input{"SendEmailviaFormmail"}) { # update last emailed field my $query="select * from bsmailinglist where id=$input{'recid1'}"; my $sth = $dbh->prepare($query); $size = $sth->execute(); my $row = $sth->fetchrow_hashref(); # get current date/time my $cdate; my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdist) = localtime(time); $cdate=($year+1900) . "/" . $mon . "/" . $mday; $query="update bsmailinglist set last_mailed=? where id=$input{'recid1'}"; $sth = $dbh->prepare($query); $sth->execute($cdate); $sth = undef; $dbh->disconnect; $template .= <Send email to selected user

SQL/Date:- $query , $cdate

Info to send formmail:-

From: BSOL Administrator
To: $input{"user1"} ($input{"email1"})
Subject: $input{"newsTitle"}
Message: $input{"newsText"}

Back

EOFHTML # # ============ initial display of form =============== # } else { my $recno; $template .= qq^

List of existing users

\n^; $template .= qq^
${font}Choose member:


\n^; } unless (($input{"sendNewsletter"}) | ($input{"NewsletterConfirm"}) | ($input{"SendEmailviaFormmail"})) { $template .= <Send email to users

Use this form to compose a message to send to all users who have opted to receive them.

Email all users?

(Note: If you select no a list of users will be displayed to select from.)

Subject line:

Newsletter text:

EOFHTML } $template .= < EOFHTML print $template; exit(0); sub Error_Page { # Prints out a page with an error message on # Params: # message - the error message to display my $error_message = shift; print < Error Script Error:-
$error_message
Back EOF exit(0); } # # get all contents of list for display in forms # sub readList { my $query="select * from bsmailinglist order by user_name;"; my $sth = $dbh->prepare($query); $size = $sth->execute(); $temphtml=""; while (my $row = $sth->fetchrow_hashref()) { $temphtml .=qq^\n^; } } # # send ALL of the members an email # #sub sendMail { # my $from_address = "ecs.dudley.newell\@oldham.gov.uk"; # my $recno; # for ($recno=0;$recno<$size;$recno++) { # for ($recno=0;$recno<2;$recno++) { testing only # ($Img1, $URL1, $forename, $surname, $email, $notify) = split(/\t/,$lines[$recno]); # Only send an email if the member wants one # if ($notify =~ "y") { # open MAIL, '|/usr/lib/sendmail -t 2>&1 >>mail.log'; # print MAIL <&1 >>mail.log'; # print MAIL <