#!/usr/bin/env perl
#use CGI qw/:standard/;
use CGI;
sub checkaddr{
my($ip, $domain) = @_;
return undef unless (defined $ip);
my $lookupip = join('.',reverse split(/\./,$ip));
if (gethostbyname($lookupip.$domain)){
return $ip;
}
else {
return undef;
}
}
chop ($sys_name = `hostname`);
$PerlDir = "/var/www/html/goodfight/cgi-bin";
require "$PerlDir/www.pl";
require "$PerlDir/rew.pl";
require "/var/www/html/goodfight/churches/addcong.pl";
require "/var/www/html/goodfight/churches/add_to_db.pl";
$ScriptPath = "http://".$ENV{SERVER_NAME};
$ScriptPath .= $ENV{SCRIPT_NAME};
$q = new CGI;
#print $q->header, $q->start_html(-title=>"Debug run"); # print HTTP/1.0 header for debugging
#print "Path info is $ENV{'PATH_INFO'}\n";
if (0)
{
my(@values,$key);
print $q->h2("Here are the current settings in this form");
foreach $key ($q->param()) {
print "$key -> ";
@values = $q->param($key);
print join(", ",@values),"
\n";
}
}
if (0) {
open(LOG,"|/usr/lib/sendmail rew\@goodfight.com") ||
print "
Couldn't open logfile: $!
\n";
} else {
open(LOG,">/dev/null") ||
print $q->hr,"Couldn't open logfile: $!", $q->hr;
}
print LOG "Reply-to: www\@goodfight.com\nFrom: www\@goodfight.com\n";
print LOG "Subject: CoC OnLine congadd.cgi log on $sys_name\n\n";
&set_buffered(LOG);
# Get the current time
$The_Time = time();
if (1 ==1) {
print LOG "Enviro-dump for $$\n";
for(keys %ENV) {
print LOG "\t$_=$ENV{$_}\n";
}
print LOG "Finished Enviro-dump\n";
}
if ($q->param())
{
proc_cong_form();
} else {
show_cong_form();
}
exit 0;
sub show_cong_form {
print $q->header, $q->start_html(-title=>"Add Congregation Form");
print $q->startform(-action=>$q->self_url);
print LOG "In show_cong_form (f0)\n";
print $q->p($q->font({-size=>"+2", -color=>"red"},
"PLEASE NOTE: I'm sorry to put this in red ",
"and make it so large. But it's just ",
$q->em("incredible"), " to me how many people ",
"are just ", $q->em("not paying attention"), ". ",
"My intent is to ", $q->em($q->strong("only")),
" list congregations that describe themselves as ",
$q->strong($q->em(
$q->a({href=>"cons-NI.html", target=>"_cons_ni"},
"conservative and non-institutional.")))
));
print $q->font({-size=>"+2", -color=>"red"},
$q->em("Please"), " don't send me listings for ",
"congregations that you could not conceivably describe ",
"like this. At ", $q->em("least"), " read the ",
"description of what I'm trying to do if you're not sure."
);
print "";
print $q->hr;
print $q->checkbox(-name=>'CONS', -value=>'CONS-NI', -label=>'');
print "I am aware of what you mean by ";
print $q->strong($q->em(
$q->a({href=>"cons-NI.html", target=>"_cons_ni"},
"conservative and non-institutional")
));
print ", and to the best of my knowledge, this group would describe itself that way.\n";
print $q->hr;
print "Please enter the name of the congregation:", $q->br;
print $q->textfield( -name=>'CONG_NAME', -default=>"Church of Christ",
-size=>60);
print $q->p;
print "Enter the Street Address (building location):", $q->br;
print $q->textfield( -name=>'STREET_ADDRESS', -size=>60), $q->p;
print "If mail is delivered to a different address, enter it here:", $q->br;
print $q->textfield( -name=>'POSTAL_ADDRESS', -size=>60), $q->p;
print "City, State and Zip (you know the drill):", $q->br;
print "City: ", $q->textfield( -name=>"CITY", -size=>20), " ";
print "St: ", $q->textfield( -name=>"STATE", -size=>3, -maxlength=>2), " ";
print "Zip: ", $q->textfield( -name=>"ZIP", -size=>10), $q->br;
print $q->br, "If the building has a phone number, enter it here";
print $q->em("(Please don't forget the area code)"), ":", $q->br;
print "Ph: ", $q->textfield( -name=>"BLDG_PHONE", -size=>15), $q->p;
print "If the congregation has an email address, enter it:", $q->br;
print $q->textfield( -name=>"EMAIL", -size=>50), $q->p;
print "If the congregation has a web page, enter the URL here:", $q->br;
print $q->textfield( -name=>"WEB_PAGE", -size=>60), $q->p;
print "If this group has a regular preacher, enter his name below. ";
print "If there are more than one, please choose just one to list:";
print $q->br, $q->textfield( -name=>"PREACHER", -size=>60), $q->p;
print "If you wish to list a separate phone number (such as ";
print "a separate office number or his home #), list it here:", $q->br;
print "Ph: ", $q->textfield( -name=>"PREACHER_PHONE", -size=>15), $q->p;
print "If the preacher has an email address, please list it below:", $q->br;
print "Email Address (if any): ",
$q->textfield(-name=>"PREACHER_EMAIL", -size=>45),
$q->p;
print "If you would like a different person to be listed as the
email contact, please give their name and email address below. Note
that I only need one email contact for the group, so if you have more
than one, please pick the one most likely to respond to email the most
quickly:", $q->br;
print "Contact Name: ",
$q->textfield(-name=>"CONTACT_NAME", -size=>60), $q->br;
print "Ph: ", $q->textfield( -name=>"CONTACT_PHONE", -size=>15), $q->br;
print "Contact Email: ",
$q->textfield(-name=>"CONTACT_EMAIL", -size=>60), $q->p;
print "List the times of service below. I have picked pretty
common default values just to get you started (and maybe save time).
Naturally, if your meeting times or order are different, just change
the values. If you do not meet during the week, or do not have a
second service on Sunday, just blank those time fields, and those
times will not show up in your listing.", $q->p;
print $q->em("Use 24-hr format for times. For instance, 6pm would be '18:00', not '6' or '6:00'"), $q->p;
@meeting_times = ("Bible Study", "Worship");
print "Sunday A.M. ";
print $q->popup_menu(-name=>"Sun_AM_Type1", -values=>\@meeting_times,
-default=>"Bible Study");
print $q->textfield(-name=>"Sun_AM_Time1", -size=>8, -default=>"09:00"), $q->br;
print "Sunday A.M. ";
print $q->popup_menu(-name=>"Sun_AM_Type2", -values=>\@meeting_times,
-default=>"Worship");
print $q->textfield(-name=>"Sun_AM_Time2", -size=>8, -default=>"10:00"), $q->p;
print "Sunday P.M.: ", $q->textfield(-name=>"Sun_PM_Time", -size=>8, -default=>"18:00");
print $q->em("Clear this field if no Sunday p.m. service"), $q->p;
print "Midweek: ";
@meeting_times = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
print $q->popup_menu(-name=>'Midweek_Day', -values=>\@meeting_times,
-default=>"Wednesday");
print $q->textfield(-name=>"Midweek_Time", -size=>8, -default=>"19:00"), $q->p;
print "You can give directions to the building here, typically
from the closest major road or landmark:", $q->br;
print $q->textarea(-name=>"DIRECTIONS", -rows=>5, -columns=>60), $q->p;
print "If there's any other relevant information you'd like to
list, enter it here:", $q->br;
print $q->textarea(-name=>"OTHER_INFO", -rows=>5, -columns=>60);
print $q->p, $q->p;
print "Last, if there's any notes you'd like to pass to me, but not include
in the listing, please leave me a note about it here:", $q->br;
print $q->textarea(-name=>"NOTES", -rows=>5, -columns=>60), $q->p;
print "P.S. - If by some chance, this information is older than a few months, please enter the date it was last known to be valid. Just leave this blank if you don't know what I'm talking about.", $q->br;
print "Month (2 digits): ", $q->textfield(-name=>"Last_Updated_Month", -size=>2);
print " Day (2 digits): ", $q->textfield(-name=>"Last_Updated_Day", -size=>2);
print "Year (4 digits): ", $q->textfield(-name=>"Last_Updated_Year", -size=>4), $q->p;
print $q->p;
print $q->hr;
print $q->strong("Please"), " check all information ";
print $q->em($q->strong("carefully")), ", and then ";
print $q->submit(-value=>"Submit the Info");
print $q->endform, $q->end_html;
0;
}
sub proc_cong_form {
local(*FN);
# Do various and sundry elaborate checks for completeness and such
if (&verify_info($q)) {
&bad_form;
return 0;
}
# mail congregation info to moi
print LOG "+++++++++++++++++++++++++++++++++++\n";
print LOG "opening sendmail to moi\n";
open(FN,"|/usr/lib/sendmail rew\@goodfight.com") ||
print $q->header, $q->start_html("Error submitting form"), $q->hr,
$q->h2("Couldn't send cong info! Please contact ",
$q->a({href=>"mailto:rew\@goodfight.com"}, "Ryan"),
"and report the problem."),
$q->hr, $q->end_html;
print FN "Reply-to: www\@goodfight.com\nFrom: www\@goodfight.com\n";
print FN "Subject: (WWW - Cong) Add Congregation\n\n";
&set_buffered(FN);
($sec,$min,$hour,$mday,$mon,$year) = localtime($The_Time);
$sec=$sec; # make perl -W shut up
$year += 1900; # localtime returns years since 1900 - convert to 4-digit
$mon++; # 0-indexed coming out of localtime
if ($hour < 12) {
$ampm = "am";
} else {
$ampm = "pm";
}
if ($hour > 12) {
$hour -= 12;
}
if ($hour == 0) {
$hour = 12;
}
printf FN "New Congregation Listing request received at %d:%02d $ampm on %02d/%02d/%04d\n\n", $hour, $min, $mon, $mday, $year;
if ($q->param('CONS')) {
print FN "Conservative\n\n";
} else {
print FN "Not Conservative\n\n";
}
&second_page("Info Received",());
$final = "- ";
$final .= "param('WEB_PAGE')."\">" if $q->param('WEB_PAGE');
$final .= $q->param('CONG_NAME');
$final .= "" if $q->param('WEB_PAGE');
$final .= "\n";
$final .= "
- ".$q->param('STREET_ADDRESS')."\n"
if $q->param('STREET_ADDRESS');
$final .= "
- Mailing Address: ".$q->param('POSTAL_ADDRESS')."\n"
if $q->param('POSTAL_ADDRESS');
$final .= "
- ";
# $final .= join(' ', ucfirst lc split($q->param('CITY'))) .", ";
$final .= ucfirst lc $q->param('CITY').", ";
$final .= uc($q->param('STATE'))." ".$q->param('ZIP')."\n";
$final .= "
- ".format_phone($q->param('BLDG_PHONE'))."\n"
if $q->param('BLDG_PHONE');
$final .= "
- Email: ".$q->param('EMAIL')."\n"
if $q->param('EMAIL');
if ($q->param('PREACHER')) {
$final .= "
- Preacher: ".$q->param('PREACHER');
$final .= " (param('PREACHER_EMAIL')."\">".$q->param('PREACHER_EMAIL').")" if $q->param('PREACHER_EMAIL');
$final .= "\n";
}
$final .= "
- ".format_phone($q->param('PREACHER_PHONE'))."\n"
if $q->param('PREACHER_PHONE');
if ($q->param('CONTACT_NAME')) {
$final .= "
- Contact: ".$q->param('CONTACT_NAME');
$final .= " (param('CONTACT_EMAIL')."\">".$q->param('CONTACT_EMAIL').")" if $q->param('CONTACT_EMAIL');
$final .= "\n";
$final .= "
- ".format_phone($q->param('CONTACT_PHONE'))."\n"
if $q->param('CONTACT_PHONE');
}
$final .= "
\n";
# For service times, I don't want to check everything - if they've entered
# a Sunday A.M. Service, then let's go with it.
print LOG "Sun_AM is ".$q->param('Sun_AM_Time1'), $q->param('Sun_AM_Type1')."\n";
if ($q->param('Sun_AM_Time1')) {
$final .= "\n
- Schedule of Services:\n";
$final .= "
- Sunday\n";
$final .= "
- ".$q->param('Sun_AM_Type1')." -- ".$q->param('Sun_AM_Time1')."\n";
if ($q->param('Sun_AM_Time2')) {
$final .="
- ".$q->param('Sun_AM_Type2')." -- ".$q->param('Sun_AM_Time2')."\n";
}
if ($q->param('Sun_PM_Time')) {
$final .="
- Evening Worship -- ".$q->param('Sun_PM_Time')."\n";
}
if ($q->param('Midweek_Time')) {
$final .="
- ".$q->param('Midweek_Day')."\n";
$final .="
- Bible Study -- ".$q->param('Midweek_Time')."\n";
}
$final .="
\n";
}
$final .= "Directions: ".$q->param('DIRECTIONS')."\n"
if $q->param('DIRECTIONS');
$final .= "
Other Information: ".$q->param('OTHER_INFO')."\n"
if $q->param('OTHER_INFO');
if (length($q->param('Last_Updated_Month')))
{
$mon = $q->param('Last_Updated_Month');
}
if (length($q->param('Last_Updated_Day')))
{
$mday = $q->param('Last_Updated_Day');
}
if (length($q->param('Last_Updated_Year')))
{
$year = $q->param('Last_Updated_Year');
}
$final .= sprintf "
Last Updated: %02d/%02d/%04d\n", $mon, $mday, $year;
$final .= "
\n";
print $final;
print FN "\n=================== Connection Data ===================\n\n";
print FN "Congregation add request from ", $q->remote_host, "\n";
printf FN "Received on $sys_name at %02d:%02d on %02d/%02d/%04d\n",
$hour, $min, $mon, $mday, $year;
print FN "\n================= End Connection Data =================\n";
print FN $final;
close(FN);
print <Thanks for the information! The listing above is
roughly how it will appear in the regular pages when I update it.
Updates take from an hour to a week depending on my email
load.
ENDofDATA
$record_number = add_congregation();
print $q->p("Your request was # $record_number");
print $q->a({href=>"/churches/index.php"},
"Back to the CoC Online Listings");
print $q->p($q->font({-size=>"+1"},
$q->a({href=>"/churches/addcong.cgi"}, "Add another listing")
)
);
print $q->end_html;
0;
}