#!/usr/bin/perl ################################################################### # CyberCalendar v1.8 # # Public Event Submission Form # 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); use CyberCalendar::Application; use strict; ################################################################### my $submit = CyberCalendar::Application->new(); $submit->init(); $config = $CyberCalendar::Application::config; $db = $CyberCalendar::Application::db; $http_in = $CyberCalendar::Application::http_in; if ($config->{public_event_submit} != 1) { my_error("Sorry, public event submissions are not allowed for this calendar."); $submit->my_exit(); } if (!exists $http_in->{Add}) { add_form(); $http_in->{View} = 'Message'; $submit->show_page(); } # if else { process_submission(); } # else sub process_submission { validate(); $db->finish; my $string = ''; my $table = ''; my @chars = ( "A" .. "Z", "a" .. "z", 0 .. 9 ); my $repeatid = join("", @chars[ map { rand @chars } (1 .. 25) ]); if ($config->{public_direct_submit} == 1) { $table = $http_in->{Calendar}; my $email = $http_in->{sub_email}; $email =~ s/\@/ at /g; $email =~ s/\./ dot /g; $http_in->{desctext} .= qq(\n

Submitted by: $http_in->{sub_name} <$email>\n); my $query = "INSERT INTO $table (repeatid, dateid, enddate, event_day, event_month, event_year, subject, desctext, url, email, location, category, starttime, endtime) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $db->query($query, $repeatid, $http_in->{dateid}, $http_in->{enddate}, $http_in->{event_day}, $http_in->{event_month}, $http_in->{event_year}, $http_in->{subject}, $http_in->{desctext}, $http_in->{url}, $http_in->{email}, $http_in->{location}, $http_in->{Category}, $http_in->{starttime}, $http_in->{endtime}); $db->finish; } # if else { $table = 'submitted_events'; $string = 'It will be reviewed for approval by the calendar administrator.'; my $query = "INSERT INTO $table (calendar, sub_name, sub_email, repeatid, dateid, enddate, event_day, event_month, event_year, subject, desctext, url, email, location, category, starttime, endtime) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $db->query($query, $http_in->{Calendar}, $http_in->{sub_name}, $http_in->{sub_email}, $repeatid, $http_in->{dateid}, $http_in->{enddate}, $http_in->{event_day}, $http_in->{event_month}, $http_in->{event_year}, $http_in->{subject}, $http_in->{desctext}, $http_in->{url}, $http_in->{email}, $http_in->{location}, $http_in->{Category}, $http_in->{starttime}, $http_in->{endtime}); $db->finish; } # else $http_in->{View} = 'Message'; $http_in->{Message} = qq(

Your event has been submitted successfully. $string

<< Back

); $submit->show_page(); } # endsub process_submission sub validate { my %val = (sub_name => '', sub_email => '', event_month => 'NULL', event_day => 'NULL', event_year => 'NULL', subject => '', location => '', desctext => ''); my %errors = (sub_name => 'YOUR NAME', sub_email => 'YOUR EMAIL', event_month => 'A CORRECT DATE', event_day => 'A CORRECT DATE', event_year => 'A CORRECT DATE', subject => 'A SUBJECT', location => 'A LOCATION', desctext => 'DESCRIPTIVE TEXT'); if ($http_in->{sub_email} !~ /.+@(.+)\.(\w\w)/o) { my_error("You must enter $errors{sub_email} into the form."); $submit->my_exit(); } # if while (my($name, $value) = each(%val)) { if ($http_in->{$name} eq $value) { my_error("You must enter $errors{$name} into the form."); $submit->my_exit(); } # if } # while $http_in->{dateid} = "$http_in->{event_year}\-$http_in->{event_month}\-$http_in->{event_day}"; if ($http_in->{hour} eq 'NULL' or $http_in->{min} eq 'NULL' and !exists $http_in->{TBA}) { my_error("You must enter A TIME for your event."); $submit->my_exit(); } # if elsif (exists $http_in->{TBA}) { $http_in->{starttime} = '00:00:00'; } # elsif else { $http_in->{starttime} = sprintf("%02d:%02d:00", ($http_in->{hour}, $http_in->{min})); } # else $http_in->{enddate} = '0000-00-00'; if (exists $http_in->{end_month} and $http_in->{end_month} ne 'NULL' and exists $http_in->{end_day} and $http_in->{end_day} ne 'NULL' and exists $http_in->{end_year} and $http_in->{end_year} ne 'NULL') { $http_in->{enddate} = "$http_in->{end_year}\-$http_in->{end_month}\-$http_in->{end_day}"; } # if if ($http_in->{end_hour} == 0) { $http_in->{endtime} = '00:00:00'; } # if else { $http_in->{endtime} = sprintf("%02d:%02d:00", ($http_in->{end_hour}, $http_in->{end_min})); } # else if ($http_in->{Category} eq "NULL" and $http_in->{NewCategory} eq "") { my_error("You must enter A CATEGORY for your event.$http_in->{NewCategory}"); $submit->my_exit(); } # if if ($http_in->{NewCategory} ne "") { $http_in->{Category} = $http_in->{NewCategory}; } # if if ($http_in->{url} eq "" or $http_in->{url} eq "http://") { $http_in->{url} = "" } # if } # endsub validate sub add_form { $http_in->{Message} = <<"ADDFORMA";
Submit an Event
   YOUR NAME:
  
   YOUR E-MAIL:
  
 
   DATE:
  
   START TIME:
   To be announced.
 
   END TIME (optional):
  
   END DATE (optional):
  

   SUBJECT:
  
   LOCATION:
  
   CATEGORY:
   ADDFORMA my $query = "SELECT DISTINCT category from $http_in->{Calendar}"; $db->query($query); my $categories = {}; while (my $tmp = $db->result("hashref")) { my ($name, $value) = each(%{ $tmp }); $categories->{$value} = $value; } # while $db->finish; $http_in->{Message} .= qq(\n\n\n\n"; $http_in->{Message} .= <<"ADDFORMB";
   New Category:
   TEXT:
 
  
   WEBSITE (optional):
  
   E-MAIL CONTACT (optional):
  

ADDFORMB } sub my_error { CyberCalendar::Application::my_error('no', $_[0]); } # endsub my_error $submit->my_exit();