#!/usr/bin/perl

#
# print header stuff
#
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body background=\"nevada.gif\">\n";
#
#define stuff to grab data entered on form
#
require TripodCGI;
use CGI;
$cgi = new CGI;
#
# get the information they entered on the form
#
$name=$cgi->param('name');
$phone=$cgi->param('phone');
$ext=$cgi->param('ext');
$comments=$cgi->param('comments');
$errors=0;
if ($name =~ /^ *$/ ) {
print "<b>ERROR</b><p>you must enter a name<p>";
$errors++;
}
if ($phone =~ /^ *$/ ) {
print "<b>ERROR</b><p>you must enter a phone number<p>";
$errors++;
}
else {
$krud=$phone;
#$krud=~s/-//g;
#$krud=~s/ //g;
#$krud=~s/[()]//g;
#$krud=~s/\.//g;
$krud=~s/[^a-zA-Z0-9]//g;
$lkrud=length($krud);
#print "length phone =$lkrud<p>";
if ($lkrud < 7 ) {
print "<b>ERROR</b><p>your phone number must have at least 7 digits<p>";
$errors++;
}
}
if ($errors > 0 ) {
exit;
}
@comment_lines=split('\n',$comments);
#print "comments =$#comment_lines<p>";
#
#open the file so we can write to the end of it
#
open(ALL,">>phone_join_copwatch.txt") or cant_do();
#
#lock the file so only ONE person can write to it
#
flock(ALL,LOCK_EX);
# and, in case someone appended
# while we were waiting...
seek(ALL, 0, 2);
&get_the_stinking_time;
#
#write the name, phone, and extension on seperate lines
#
print ALL "xxx $zdate\n";
print ALL "xxx $name\n";
print ALL "xxx $phone\n";
print ALL "xxx $ext\n";
#
#write each comment out on a seperate line
#
foreach $x (@comment_lines) {
chomp($x);
print ALL "xxx $x\n";
}
#
#write a blank line at the end of each entry
#
print ALL "\n";
#
#unlock the file
#
flock(ALL,LOCK_UN);
#
#close the file
#
close(ALL);
print "You have been added to the COPWATCH phone list<br>";
exit;
sub cant_do {
print "<h2>ERROR!!! Somethings Screwed up</h2>";
print "Can't open our output file";
exit;
}
sub get_the_stinking_time {
$zdate=time();
($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9)=localtime($zdate);
$dm=$t5;
$dd=$t4;
$dy=$t6;
$dy-=100;
$dm++;
if ($dm < 10 ) {
$dm="0".$dm;
}
if ($dd < 10 ) {
$dd="0".$dd;
}
if ($dy < 10 ) {
$dy="0".$dy;
}
$ts=$t1;
$tm=$t2;
$th=$t3;
if ($ts < 10 ) {
$ts="0".$ts;
}
if ($tm < 10 ) {
$tm="0".$tm;
}
if ($th < 10 ) {
$th="0".$th;
}
$zdate=$dm."/".$dd."/".$dy." ".$th.":".$tm.":".$ts
}