#!/usr/bin/perl ################################################################### # CyberCalendar v1.8 # # Mail and reminder handling script # Copyright 1999, 2000, 2001 Shawn Ewald # ################################################################### # License: # # ----------------------------------------------------------------# # This program 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. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # ################################################################### # For the full text of the GNU General Public License, go to: # # http://www.gnu.org/copyleft/gpl.html # ################################################################### # Script Modules use vars qw($config $db $http_in $optionform); use CyberCalendar::Application; use strict; ################################################################### # Begin Script $optionform = CyberCalendar::Application->new(); $optionform->init(); $config = $CyberCalendar::Application::config; $db = $CyberCalendar::Application::db; $http_in = $CyberCalendar::Application::http_in; my $result_string_start = qq(); my $result_string_end = qq(
<< Return to Event Options
); options_view(); sub options_view { my $error_string = qq( Cannot process request. Request not understood.

<< Return to Calendar); if (!exists $http_in->{FormAction}) { $optionform->my_error("no", $error_string); } else { if ($http_in->{FormAction} =~ /SendMail/) { options_sendmail(); } # if elsif ($http_in->{FormAction} =~ /Reminder/) { options_reminder(); } # elsif else { my_error("no", $error_string); } # else } # else } # endsub options_view sub options_sendmail { my $mail = {}; if ($http_in->{to_email} !~ /.+@(.+)\.(\w\w)/o or $http_in->{from_email} !~ /.+@(.+)\.(\w\w)/o) { my_error("no", "$result_string_start You must fill out BOTH the From field and the To field in the mail form.
$result_string_end\n"); } # if else { my $query = qq(SELECT * from $http_in->{Calendar} WHERE dateid = ? AND repeatid = ?); $db->query($query, CyberCalendar::Application::http2dateid(), $http_in->{Repeatid}); my $rows = $db->rowcount; if ($rows == 0) { my_error("no", "$result_string_start Event not found.
$result_string_end\n"); } # if else { my $event = $db->result("hashref"); my $cal = CyberCalendar::Calendar->new(); my $util = CyberCalendar::Util->new(); if ($config->{attach_vcal} == 1) { my %vcevent = %{ $event }; $vcevent{dateid} = $cal->vcal_date($vcevent{dateid}, $vcevent{starttime}); if ($vcevent{enddate} ne '0000-00-00' or $vcevent{enddate} != 0) { $vcevent{enddate} = $cal->vcal_date($vcevent{enddate}, $vcevent{starttime}); } # if else { $vcevent{enddate} = $vcevent{dateid}; } # else $vcevent{Calendar} = $http_in->{Calendar}; $vcevent{DateID} = $http_in->{DateID}; $vcevent{Repeatid} = $http_in->{Repeatid}; $mail->{attach_type} = 'text/x-vcalendar'; $mail->{attach_disposition} = 'attachment'; $mail->{attach} = $util->vcal($config, \%vcevent); $mail->{attach_filename} = 'event.vcs'; } # if $event = CyberCalendar::Application::process_event($event, $cal); $mail->{Type} = 'TEXT'; $mail->{Type} = 'text/html' if $http_in->{html_mail} eq "yes"; $mail->{to} = $http_in->{to_email}; $mail->{from} = $http_in->{from_email}; $mail->{reply} = $http_in->{from_email}; $mail->{subject} = "Event: $event->{subject}"; $mail->{msg} = sendmail_format_message($event); $mail->{note} = $http_in->{note}; my $send_method = $config->{smtp_server}; $send_method = 'sendmail' if $config->{use_sendmail} == 1; $util->sendmail($send_method, $mail); $http_in->{View} = "Message"; $http_in->{Message} = qq(

$result_string_start Mail sent successsfully.

$result_string_end
\n); $optionform->show_page(); } # else } # else $db->finish; } # endsub options_sendmail sub sendmail_format_message { my $msg = ''; if (exists $http_in->{html_mail} and $http_in->{html_mail} = "yes") { $_[0]->{url} = CyberCalendar::Application::fix_event_url($_[0]->{url}); $http_in->{note} =~ s/\n/
/g; my $event = CyberCalendar::Application::event_long($_[0], $config); $msg = <<"HTMLMSG"; $config->{mail_message_title}: $_[0]->{subject}
$http_in->{note}
____________________________________________
$config->{mail_message_title}:

$http_in->{from_email} has sent you this
message about the following event...
____________________________________________

$event

Calendar: $config->{calendar_name}
HTMLMSG } # if else { $_[0]->{desctext} =~ s/(
|
)/\n/g; $msg = <<"TEXTMSG"; $http_in->{note} ____________________________________________ $config->{mail_message_title}: $http_in->{from_email} has sent you this message about the following event... ____________________________________________ Event: $_[0]->{subject} Date: $_[0]->{datetext} Time: $_[0]->{starttime} Location: $_[0]->{location} Category: $_[0]->{category} Contact: $_[0]->{email} Website: $_[0]->{url} $_[0]->{desctext} ____________________________________________ Calendar: $config->{calendar_name} ($config->{calendar_homepage}$config->{cal_url}?Calendar=$http_in->{Calendar}) Event URL: $config->{calendar_homepage}$config->{cal_url}?Calendar=$http_in->{Calendar}&View=Event&DateID=$http_in->{DateID}&Repeatid=$http_in->{Repeatid} TEXTMSG } # else return $msg; } # endsub sendmail_format_message sub options_reminder { my ($m, $d, $y) = split("/", $http_in->{DateID}); my $dateid = sprintf("%04d\-%02d\-%02d", ($y, $m, $d)); my $today = sprintf("%04d\-%02d\-%02d", @{ $CyberCalendar::Calendar::todaysdate }); my $cal = CyberCalendar::Calendar->new(); my $delta = $cal->delta_days(@{ $CyberCalendar::Calendar::todaysdate }, ($y, $m, $d)); if ($delta <= 0) { my_error("no", "$result_string_start Reminder not saved

The event has either already passed or is happening today.
$result_string_end\n"); $optionform->my_exit(); } # if if ($http_in->{to_email} !~ /.+@(.+)\.(\w\w)/o) { my_error("no", "$result_string_start You must enter your e-mail address AND select when you wish to receive your event reminder.
$result_string_end\n"); } # if else { my $html_mail = 'no'; $html_mail = 'yes' if $http_in->{html_mail} eq "yes"; my $cal = CyberCalendar::Calendar->new(); my ($y, $m, $d) = split("-", $dateid); ($y, $m, $d) = $cal->minus_days($http_in->{when}, ($y, $m, $d)); my $remindid = sprintf("%04d\-%02d\-%02d", ($y, $m, $d)); my $query = "INSERT INTO reminders (calendar, remindid, dateid, repeatid, email, html) VALUES(?, ?, ?, ?, ?, ?)"; $db->query($query, $http_in->{Calendar}, $remindid, $dateid, $http_in->{Repeatid}, $http_in->{to_email}, $html_mail); $db->finish; $http_in->{View} = "Message"; $http_in->{Message} = qq(
$result_string_start Your reminder has been saved.

$result_string_end
\n); $optionform->show_page(); } # else } # endsub options_reminder sub my_error { CyberCalendar::Application::my_error($_[0], $_[1]); } # endsub my_error $optionform->my_exit();