#!/usr/bin/perl
BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
use CGI qw( :standard );
use CGI::Carp qw(fatalsToBrowser);
use LWP::Simple qw($ua get);
use Date::Calc qw(:all);
use MIME::Lite;
use Mail::Sendmail;
use File::Copy;
use File::Basename;
require cfg ;
print header; # CGI.pm method
#-------------------------------------------------------------------------------
my @ARGV = split(/\&/, $ENV{'QUERY_STRING'});
my $e_id = $ARGV[0] ;
my ($q) = CGI -> new() ;
our $iaction = $q -> param('iaction') ;
our $iemail = $q -> param('iemail') ;
our $iotheremailaddress = $q -> param('iotheremailaddress') ;
our $imsg = $q -> param('imsg') ;
our $isubject = $q -> param('isubject') ;
our $iattach = $q -> upload('iattach') ;
$input{event_details} = $q -> param('event_details') ;
our $debug = 1 ;
#------------------------------------------------------------------------------------------
&today ;
&db_open_ro ;
$db_ignore_open_close = 1 ;
if ($iaction eq '') {
&read_db ;
&screen1 ;
}
if ($iaction eq 'send') {
&read_db ;
&send_email ;
&screen2 ;
}
$db_ignore_open_close = 0 ;
&db_close_conn ;
exit;
#------------------------------------------------------------------------------------------
sub read_db {
our $message = qq~~ ;
if ($iaction eq 'send') {
&create_event_email_table($e_id) ;
my %seen_email = () ; our $emails = qq~~ ;
foreach (split(",",$iotheremailaddress)) {
next if $seen_email{$_} ;
$seen_email{$_} = 1 ;
$emails .= qq~$_,~ ;
}
$emails .= qq~$iemail~ if not $seen_email{$iemail} and $iemail ;
chop $emails if $seen_email{$iemail} or not $iemail ;
our %operator_email = () ; our %operator_name = () ; our %operator_email_to_id = () ;
$seen_email{$db{users}{$db{event_quotes}{1}{user_id}}{email}} = 1;
foreach (sort {$db{users}{$a}{email} cmp $db{users}{$b}{email}} keys %{$db{users}}) {
$operator_name{$db{users}{$_}{email}} = $db{users}{$_}{name} ;
if (substr($db{users}{$_}{user_type},0,6) eq 'casual') {
$operator_email{$db{users}{$_}{email}} = 1 ;
$operator_email_to_id{$db{users}{$_}{email}} = $_ ;
}
}
} elsif ($iaction eq '') {
&db_min_ro('event_quotes','1,operator_ids,user_id,ref,date_from',"`id`='$e_id'",'','') ;
foreach (split(",",$db{event_quotes}{1}{operator_ids})) {
$selected{email_other}{$_} = 'SELECTED' ;
}
# $selected{email_other}{$userid} = 'SELECTED' ;
# &db_min_ro('users','id,email',"`user_type` LIKE 'casual%' OR `user_type` = 'schools_manager' OR `id` = '$userid'",'','') ;
&db_min_ro('users','id,email,user_type,name',"",'','') ; # `user_type` LIKE 'casual%' OR `id` = '$db{event_quotes}{1}{user_id}'
my %seen_email = () ;
$seen_email{$db{users}{$db{event_quotes}{1}{user_id}}{email}} = 1;
foreach (sort {$db{users}{$a}{email} cmp $db{users}{$b}{email}} keys %{$db{users}}) {
next if $seen_email{$db{users}{$_}{email}} ;
$seen_email{$db{users}{$_}{email}} = 1 ;
if (substr($db{users}{$_}{user_type},0,6) eq 'casual') {
$operator_email{$db{users}{$_}{email}} = 1 ;
$opts{email_other} .= qq~~ if $db{event_quotes}{1}{user_id} ne $_ ;
}
}
$message = qq~Good day
Please find attached event details.
~ ;
}
} #------------------------------------------------------------------------------------------
sub send_email {
&common_debug("\n iemail : $emails") ;
my $bcc = "$email_events{1};$email_events{2}" ;
if ($email{$userid}) { $bcc = $email{$userid} ; }
if ($username eq 'rory') { $bcc = $email_it_1 ; }
if ($username eq 'handre') { $bcc = $email_it_2 ; }
my $attachpath = "$pdfpath/event_details" ; $attachfile = "Event_Details-$e_id.pdf" ;
if (not -f "$attachpath/$attachfile" || not $input{event_details}) {
$attachpath = '' ; $attachfile = '' ;
}
$imsg =~ s/\n/
/g;
# my @email_adds = split(/\,/,$emails) ;
# my $email_adds = join(";",@email_adds) ;
# &common_debug("\n iemail : $emails") ;
# exit ;
# &common_send_smtp_mail('',$email_adds,'',$bcc,$isubject,$imsg,$table_message,1,'',$attachpath,$attachfile,'',$iattach) ;
# $imsg =~ s/:/<\/td>