#!/usr/bin/perl # Copyright 2001-2009 Leslie Richardson # This file is part of Open Admin for Schools. # Open Admin for Schools is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. my %lex = ('Group Email' => 'Group Email', 'Grade' => 'Grade', 'Homeroom' => 'Homeroom', 'Main' => 'Main', 'Blank=All' => 'Blank=All', 'Select' => 'Select', 'Values' => 'Values', 'Group' => 'Group', 'Parent 1' => 'Parent 1', 'Parent 2' => 'Parent 2', 'Separate with Spaces' => 'Separate with Spaces', 'Subject' => 'Subject', 'Message' => 'Message', 'Continue' => 'Continue', 'Student' => 'Student', 'Checked' => 'Checked', 'Email Sent' => 'Email Sent', 'Error' => 'Error', 'Email' => 'Email', ); my $self = 'emailgroup.pl'; # Configured Values my $mailercommand = '/usr/sbin/sendmail -t'; # Also change comments line ~260 my $noreplyName = 'OpenAdmin Messaging System'; my $noreplyEmail = 'no-reply@yoursite.net'; use CGI; use DBI; # calc current date my @tim = localtime(time); my $year = @tim[5] + 1900; my $month = @tim[4] + 1; my $day = @tim[3]; my $currdate = "$year-$month-$day"; eval require "../etc/admin.conf"; if ( $@ ) { print $lex{Error}. " :$@
\n"; die $lex{Error}. " :$@
\n"; } my $q = new CGI; print $q->header( -charset, $charset ); my %arr = $q->Vars; my $checked = $arr{checked}; delete $arr{checked}; my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); $dbh->{mysql_enable_utf8} = 1; # Show page Header print "$doctype\n". $lex{'Group Email'}. "\n"; print "\n"; print "$chartype\n\n"; print "[ ". $lex{Main}. " ]\n"; print "

". $lex{'Group Email'}. "

\n"; if ( not $arr{page} ) { showStartPage(); } elsif ( $arr{page} == 1 ) { # Select Students, Parents to receive email. delete $arr{page}; selectRecipients(); } elsif ( $arr{page} == 2 ) { # post the Mail delete $arr{page}; postEmail(); } elsif ( $arr{page} == 3 ) { # Write Emails to File or System. } #---------------- sub showStartPage { #---------------- # Setup the form and start of table. print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
". $lex{Group}. "\n"; print "\n"; print "
". $lex{Values}. "\n"; print "
\n"; print $lex{'Separate with Spaces'}. q{, }. $lex{'Blank=All'}. "
". $lex{Select}. "\n"; print " "; print $lex{Student}. q{ }. $lex{Email}. "
\n"; print " "; print $lex{'Parent 1'}. q{ }. $lex{Email}. "
\n"; print " "; print $lex{'Parent 2'}. q{ }. $lex{Email}. "
\n"; print "
". $lex{Checked}. "?\n"; print "
"; print ""; print "
\n"; print "\n"; exit; } #------------------- sub selectRecipients { # Choose students/parents to email to and put in message #------------------- # foreach my $key (keys %arr) { print "K:$key V:$arr{$key}
\n"; } # Get passed group values my @group = split /\s/, $arr{groupValue}; # split into array based on spaces delete $arr{groupValue}; #print "Group", @group, "
\n"; my $groupType; if ( $arr{groupType} eq $lex{Grade} ) { $groupType = 'grade'; } else { $groupType = 'homeroom'; } delete $arr{groupType}; # Select students, sorted by lastname, firstname, my $select; if ( @group ) { $select = 'where '; my $first = 1; foreach my $value ( @group ) { $value = $dbh->quote( $value ); if ( not $first ) { $select .= ' or '; } $select .= "$groupType = $value "; $first = 0; } } if ($select) { print "Select: $select
\n"; } my $sth = $dbh->prepare("select lastname, firstname, studnum, email, par1_email, par2_email from student $select order by lastname, firstname"); $sth->execute; if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; } # Setup the form and start of table. print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; # Loop through the students while ( my ($lastname, $firstname, $studnum, $email, $par1_email, $par2_email ) = $sth->fetchrow ) { print "\n"; } # Print Submit Row print "\n"; print "
". $lex{Subject}; print "
". $lex{Message}; print "
$lastname, $firstname ($studnum)\n"; if ( $email and $arr{selStudent} ) { print $lex{Student}; print " $email  | "; } if ( $par1_email and $arr{selPar1} ) { print $lex{'Parent 1'}; print " "; print "$par1_email  | "; } if ( $par2_email and $arr{selPar2} ) { print $lex{'Parent 2'}; print ""; print "$par2_email  | "; } print "
"; print "
\n
\n"; exit; } #------------ sub postEmail { #------------ delete $arr{page}; # value not needed. my $subject = $arr{subject}; delete $arr{subject}; my $message = $arr{message}; delete $arr{message}; my %duplicates = (); print "
\n
\n"; print "

". $lex{'Email Sent'}. "

\n"; # For testing/demonstration purposes only... # system("mv emailtest $downloaddir"); # print "

"; # print "Email Demonstration File (text format)

\n"; print "

[ ". $lex{Main}. " ]

\n"; print "\n"; exit; } # End of postMail