";
while ($in{$modContactTitle} =~ /[\s]+$/)
{
chop($in{$modContactTitle});
}
if (length ($in{$modContactTitle}) < 2)
{
print" Title
must be at least 2 characters";
print " ";
$error = ++$error;
}
elsif ($in{$modContactTitle} !~ /^[A-Za-z0-9\s\-]+$/)
{
print" Title
$in{$modContactTitle} invalid - can only contain letters, numbers, spaces and hyphens";
print " ";
$error = ++$error;
}
while ($in{$modContactDeskPH1} =~ /[\s]+$/)
{
chop($in{$modContactDeskPH1});
}
while ($in{$modContactDeskPH2} =~ /[\s]+$/)
{
chop($in{$modContactDeskPH2});
}
while ($in{$modContactDeskPH3} =~ /[\s]+$/)
{
chop($in{$modContactDeskPH3});
}
if ((length($in{$modContactDeskPH1}) > 0)
or (length($in{$modContactDeskPH2}) > 0)
or (length($in{$modContactDeskPH3}) > 0 ))
{
if (length($in{$modContactDeskPH1}) < 2)
{
print" Desk PH Number Part One
$in{$modContactDeskPH1} must be at least 2 digits";
print " ";
$error = ++$error;
}
elsif ($in{$modContactDeskPH1}!~ /^[0-9]+$/)
{
print" Desk PH Number Part One
$in{$modContactDeskPH1} invalid - can only contain numbers";
print " ";
$error = ++$error;
}
if (length($in{$modContactDeskPH2}) < 2)
{
print" Desk PH Number Part Two
$in{$modContactDeskPH2} must be at least 2 digits";
print " ";
$error = ++$error;
}
elsif ($in{$modContactDeskPH2}!~ /^[0-9]+$/)
{
print" Desk PH Number Part Two
$in{$modContactDeskPH2} invalid - can only contain numbers";
print " ";
$error = ++$error;
}
if (length($in{$modContactDeskPH3}) < 5)
{
print" Desk PH Number Part Three
$in{$modContactDeskPH3} must be at least 5 digits";
print " ";
$error = ++$error;
}
elsif ($in{$modContactDeskPH3}!~ /^[0-9]+$/)
{
print" Desk PH Number Part Three
$in{$modContactDeskPH3} invalid - can only contain numbers";
print " ";
$error = ++$error;
}
}
while ($in{$modContactMobile} =~ /[\s]+$/)
{
chop($in{$modContactMobile});
}
if (length($in{$modContactMobile}) > 0)
{
if (length($in{$modContactMobile}) < 8)
{
print" Mobile Phone Number
must be at least 8 digits";
print " ";
$error = ++$error;
}
elsif ( $in{$modContactMobile} !~ /^[0-9\s]+$/)
{
print" Mobile Phone Number
$in{$modContactMobile} invalid - can only contain numbers and spaces";
print " ";
$error = ++$error;
}
}
while ($in{$modContactPagerSPName} =~ /[\s]+$/)
{
chop($in{$modContactPagerSPName});
}
while ($in{$modContactPagerSP} =~ /[\s]+$/)
{
chop($in{$modContactPagerSP});
}
if ((length($in{$modContactPagerSPName}) > 0)
or (length($in{$modContactPagerSP}) > 0))
{
if (length($in{$modContactPagerSPName}) < 3)
{
print" Pager Service Name
$in{$modContactPagerSPName} must be at least 3 characters";
print " ";
$error = ++$error;
}
elsif ($in{$modContactPagerSPName} !~ /^[A-Za-z]+$/)
{
print" Pager Service Name
$in{$modContactPagerSPName} invalid - can only contain letters";
print " ";
$error = ++$error;
}
if (length($in{$modContactPagerSP}) < 5)
{
print" Pager Service Number
$in{$modContactPagerSP} must be at least 5 digits";
print " ";
$error = ++$error;
}
elsif ($in{$modContactPagerSP}!~ /^[0-9]+$/)
{
print" Pager Service Number
$in{$modContactPagerSP} invalid - can only contain numbers";
print " ";
$error = ++$error;
}
}
while ($in{$modContactFax1} =~ /[\s]+$/)
{
chop($in{$modContactFax1});
}
while ($in{$modContactFax2} =~ /[\s]+$/)
{
chop($in{$modContactFax2});
}
while ($in{$modContactFax3} =~ /[\s]+$/)
{
chop($in{$modContactFax3});
}
if ((length($in{$modContactFax1}) > 0)
or (length($in{$modContactFax2}) > 0)
or (length($in{$modContactFax3}) > 0 ))
{
if (length($in{$modContactFax1}) < 2)
{
print" Fax Number Part One
$in{$modContactFax1} must be at least 2 digits";
print " ";
$error = ++$error;
}
elsif ($in{$modContactFax1}!~ /^[0-9]+$/)
{
print" Fax Number Part One
$in{$modContactFax1} invalid - can only contain numbers";
print " ";
$error = ++$error;
}
if (length($in{$modContactFax2}) < 2)
{
print" Fax Part Number Two
$in{$modContactFax2} must be at least 2 digits";
print " ";
$error = ++$error;
}
elsif ($in{$modContactFax2}!~ /^[0-9]+$/)
{
print" Fax Part Number Two
$in{$modContactFax2} invalid - can only contain numbers";
print " ";
$error = ++$error;
}
if (length($in{$modContactFax3}) < 5)
{
print" Fax Part Number Three
$in{$modContactFax3} must be at least 5 digits";
print " ";
$error = ++$error;
}
elsif ($in{$modContactFax3}!~ /^[0-9]+$/)
{
print" Fax Part Number Three
$in{$modContactFax3} invalid - can only contain numbers";
print " ";
$error = ++$error;
}
}
while ($in{$modContactEmail} =~ /[\s]+$/)
{
chop($in{$modContactEmail});
}
if (length($in{$modContactEmail}) > 0)
{
if (length($in{$modContactEmail}) < 7)
{
print" Email Address
must be at least 7 characters";
print " ";
$error = ++$error;
}
elsif ($in{$modContactEmail} !~ /^[a-zA-Z0-9\-\.\_]*[a-zA-Z0-9\-\.\_]\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
{
print" Email Address
$in{$modContactEmail} invalid - please check format (e.g.: joe\@email.com.au)";
print " ";
$error = ++$error;
}
}
while ($in{$modContactPager} =~ /[\s]+$/)
{
chop($in{$modContactPager});
}
if (length($in{$modContactPager}) > 0)
{
if (length($in{$modContactPager}) < 5)
{
print" Pager Number
must be at least 5 digits";
print " ";
$error = ++$error;
}
elsif ($in{$modContactPager} !~ /^[0-9]+$/)
{
print" Pager Number
$in{$modContactPager} invalid - can only contain numbers";
print " ";
$error = ++$error;
}
}
if (($modContactDeskPH eq "") && ($modContactFax eq "")
&& ($in{$modContactMobile} eq "") && ($in{$modContactEmail} eq "")
&& ($in{$modContactPager} eq ""))
{
print" Contact
must include at least 1";
print " ";
$error = ++$error;
}
if ($error > 0)
{
print " ";
}
else
{
my $dbh = DBI->connect("DBI:Sybase:CRAP", "sa", ""); #connects to
$sth4 = $dbh->prepare(qq{
SELECT NSS.dbo.SITE.SITE_#, SITE_NAME
FROM NSS.dbo.SITE, NSS.dbo.SITE_CONTACT, NSS.dbo.CONTACT
WHERE NSS.dbo.SITE.SITE_# = NSS.dbo.SITE_CONTACT.SITE_#
AND NSS.dbo.CONTACT.CONTACT_# = NSS.dbo.SITE_CONTACT.CONTACT_#
AND NSS.dbo.CONTACT.CONTACT_# = $in{$modContactNumber}
}) or die "Can't prepare SQL statement: $DBI::errstr\n";
$sth4->execute
or die "Can't execute: $DBI::errstr\n";
my ($newSiteNumber, $newSiteName);
$sth4->bind_columns (\$newSiteNumber, \$newSiteName);
@array = (split " ", $sites);
print $array[1];
if ($array[1] == 7)
{
print "matches ";
}
else
{
print "doesn't match ";
}
#my %sites_list;
#@sites_list {split(" ", $sites)} = (); # hash slice for quicker lookup
#while ($sth4->fetch()) {
# if (exists $sites_list{$newSiteNumber}) {
# print $newSiteNumber;
# print "modify!";
#} else {
# print $newSiteNumber;
# print "delete!";
#}
#}
$sth5 = $dbh->prepare(qq{
select SITE_#, SITE_NAME
FROM NSS.dbo.SITE
WHERE SITE_# NOT IN
(select NSS.dbo.SITE.SITE_#
FROM NSS.dbo.SITE, NSS.dbo.SITE_CONTACT, NSS.dbo.CONTACT
WHERE NSS.dbo.SITE.SITE_# = NSS.dbo.SITE_CONTACT.SITE_#
AND NSS.dbo.CONTACT.CONTACT_# = NSS.dbo.SITE_CONTACT.CONTACT_#
AND NSS.dbo.CONTACT.CONTACT_# = $in{$modContactNumber})
}) or die "Can't prepare SQL statement: $DBI::errstr\n";
$sth5->execute
or die "Can't execute: $DBI::errstr\n";
my ($siteNumber, $siteName);
$sth5->bind_columns (undef, \$siteNumber, \$siteName);
$sth3 = $dbh->prepare(qq{
select CONTACT_FNAME, CONTACT_LNAME
from NSS.dbo.CONTACT
WHERE CONTACT_# = $in{$modContactNumber}
}) or die "Can't prepare SQL statement: $DBI::errstr\n";
$sth3->execute
or die "Can't execute: $DBI::errstr\n";
my ( $oldContactFName, $oldContactLName);
$sth3->bind_columns (undef, \$oldContactFName, \$oldContactLName);
while ( @row3 = $sth3->fetchrow() ) {}
$sth = $dbh->prepare(qq{
UPDATE NSS.dbo.CONTACT SET
CONTACT_TITLE = "$in{$modContactTitle}",
CONTACT_DESKPH# = "$in{$modContactDeskPH1}-$in{$modContactDeskPH2}-$in{$modContactDeskPH3}",
CONTACT_MOBILE# = "$in{$modContactMobile}",
CONTACT_PAGER# = "$in{$modContactPager}",
CONTACT_PAGER_SP = "$in{$modContactPagerSPName}-$in{$modContactPagerSP}",
CONTACT_FAX# = "$in{$modContactFax1}-$in{$modContactFax2}-$in{$modContactFax3}",
CONTACT_EMAIL = "$in{$modContactEmail}"
WHERE CONTACT_# = $in{$modContactNumber}
}) or die "Prepare of UPDATE: ", $dbh->errstr, "\n";
$sth->execute or die "Execute of UPDATE: ", $dbh->errstr, "\n";
#$sth2 = $dbh->prepare(qq{
# UPDATE NSS.dbo.SITE_CONTACT SET
# SITE_# = $in{$modSite}
#
# WHERE CONTACT_# = $in{$modContactNumber}
# }) or die "Prepare of UPDATE: ", $dbh->errstr, "\n";
# $sth2->execute or die "Execute of UPDATE: ", $dbh->errstr, "\n";
print <<"EOF";
Contact ModifiedContact $oldContactFName $oldContactLName has been modified
EOF
}