#!/usr/bin/perl -w use strict; use warnings; use DBI; use CGI; use CGI::Carp qw(fatalsToBrowser); my $q = new CGI; print $q->header; print $q->start_html(-title=>'Search The Grand Rapids Web Site'); print $q->comment('By Joseph Harnish'); print <param('type'))){ # if the type is set it will enter here if($q->param('type') eq 'new'){ #if the type was set to new it will create a blank form } elsif ($q->param('type') eq 'add'){ #if the type is add a db connection will be created to the database and the #form will be entered into the database. my $dbh = DBI->connect("DBI:Oracle:host=172.16.21.16;sid=nlab", 'xxxxx', 'xxxxx') or die "Connecting : $DBI::errstr\n"; my $ii = 0; my $partialstring = ""; my $keywordfound = 0; my $policynumber = $q->param('id'); my $DATE_CR = $q->param('dated'); my $ISSUEDBY = $q->param('issuedby'); my $newsubject = $q->param('subject'); my $newpurpose = $q->param('purpose'); my $newpolicy = $q->param('policy'); my $username = $q->remote_user(); if (!defined($newsubject)){ #do error stuff here } if (!defined($newpurpose)){ #do error stuff here } if (!defined($newpolicy)){ #do error stuff here } $newpolicy =~ s/\n/
/g; $newpolicy =~ s/\'/'/g; $newpurpose =~ s/\'/'/g; $newsubject =~ s/\'/'/g; print "$DATE_CR"; print " $ISSUEDBY"; print " $policynumber"; $dbh->do("Insert into City_Policies (ID, DATE_CREATED, ISSEDBY, SUBJECT) values ('$policynumber', '$DATE_CR', '$ISSUEDBY', '$newsubject')") or print "I died"; $dbh->do("Update City_Policies set PURPOSE='$newpurpose' where ID='$policynumber'") or die "Error with PURPOSE"; for ($ii = 0; $ii< ((length($newpolicy))/4000); $ii++){ my $testnum = ((length($newpolicy)) - ($ii * 4000)); if ($testnum < 4000) { $partialstring = substr($newpolicy, (($ii) * 4000)); } else { $partialstring = substr($newpolicy, (($ii) * 4000), 4000); } print $partialstring; $dbh->do("Update City_Policies set POLICY" . ($ii+1) . "='$partialstring' where ID='$policynumber'") or die "Error in Policy \n $newpolicy which has a size of ". length($partialstring) ." instead of 4000"; $partialstring = ""; } $dbh->disconnect; } elsif ($q->param('type') eq 'del'){ # if the param is delete then I come here my $dbh = DBI->connect("DBI:Oracle:host=172.16.21.16;sid=nlab", 'xxxx', 'xxxxx') or die "Connecting : $DBI::errstr\n"; my $idnum = $q->param('id'); $dbh->do("Delete from City_policies where ID='$idnum'"); $dbh->disconnect; } }else { #if the type param was not set I enter here my $IDNUM = $q->param("ID"); my $POLICY1 = ""; my $DATE_CR = ""; my $POLICY2 = ""; my $POLICY3 = ""; my $POLICY4 = ""; my $POLICY5 = ""; my $POLICY6 = ""; my $ISSUEDBY = ""; my $SUBJECT =""; my $PURPOSE = ""; my $dbh = DBI->connect("DBI:Oracle:host=172.16.21.16;sid=nlab", 'xxxx', 'xxxxx') or die "Connecting : $DBI::errstr\n"; my $sth = $dbh->prepare("Select ID, ISSEDBY, DATE_CREATED, SUBJECT, PURPOSE, POLICY1, POLICY2, POLICY3, POLICY4, POLICY5, POLICY6 from city_policies where ID='$IDNUM'") or die "Error in prepare"; $sth->execute or die "Error in excute"; ($IDNUM, $ISSUEDBY, $DATE_CR, $SUBJECT, $PURPOSE, $POLICY1, $POLICY2, $POLICY3, $POLICY4, $POLICY5, $POLICY6) = $sth->fetchrow_array; $POLICY1 =~s/
/\n/g; $POLICY2 =~s/
/\n/g; $POLICY3 =~s/
/\n/g; $POLICY4 =~s/
/\n/g; $POLICY5 =~s/
/\n/g; $POLICY6 =~s/
/\n/g; $POLICY1 =~s/
/\n/g; $POLICY2 =~s/
/\n/g; $POLICY3 =~s/
/\n/g; $POLICY4 =~s/
/\n/g; $POLICY5 =~s/
/\n/g; $POLICY6 =~s/
/\n/g; $sth->finish; $dbh->disconnect; print <## [Wed Nov 29 10:08:22 2000] G:\Inetpub\wwwroot\adminpolicy.pl: (in cleanup) Can't call method "FETCH" on an undefined value at c:/Perl/site/lib/Win32/TieRegistry.pm line 1486 during global destruction.