#!/usr/local/bin/perl
@fields = (‘Contact’,’Email’,’Religous/Secular’,’Concern’,’Agency Name’,’Affiliated With’,’Last Verified’,’Primary Address’,
‘Address 2′,’City’,’State’,’Zip’,’HOURS’,’Phone’,’800-Phone’,’Fax’,’2Address’,
‘2Address2′,’2City’,’2State’,’2Zip’,’local’,’written info on request’
,’counselling referrals’,’Crisis Intervention’,’Professional Group’,’Support Group’,
‘Newsletter Fqy’,’COMMENTS’);
$save_database = ‘../save5.txt’;
$save_backup = ‘../save-backup.txt’;
$agency_name = 4;
use CGI;
$q = new CGI;
&print_header;
if ($q->param(‘Action’) eq ‘Modify Record’) {
&print_record ($q->param(‘agency_name’));
} elsif ($q->param(‘Action’) eq ‘New Record’) {
&new_record;
} elsif ($q->param(‘Action’) eq ‘Update Record’) {
&update_record;
&print_name_select;
} elsif ($q->param(‘Action’) eq ‘Delete Record’) {
&delete_record ($q->param(‘agency_name’));
&print_name_select;
} else {
&print_name_select;
}
&print_footer;
1;
sub delete_record {
# This procedure Deletes a single record.
local ($locator) = @_;
local ($searching) = 1;
if (-s “$save_database”) { `cp $save_database $save_backup`; }
open (INFILE, “<$save_database");
@lines =
close (INFILE);
open (OUTFILE, “>$save_database”);
$locator =~ s/(//g;
$locator =~ s/)//g;
foreach $line (@lines) {
$line2 = $line;
$line2 =~ s/(//g;
$line2 =~ s/)//g;
if ($line2 =~ /^[^t]*t[^t]*t[^t]*t[^t]*t$locatort/ && $searching) {
$searching = 0;
} else {
print OUTFILE $line;
}
}
}
sub update_record {
# This procedure only follows a session of print record.
# The data collected there is used to modify a single
# record in the data base.
local ($locator) = $q->param(‘locator’);
local ($searching) = 1;
if (-s “$save_database”) { `cp $save_database $save_backup`; }
open (INFILE, “<$save_database");
@records =
close (INFILE);
if ($locator eq “New_Record”) {
open (OUTFILE, “>>$save_database”);
foreach $f (@fields) {
$temp = $q->param(“$f”);
$temp =~ s/n//g;
$temp =~ s/cM//g;
$line .= $temp . “t”;
}
chop $line;
$line .= “n”;
print OUTFILE $line;
} else {
open (OUTFILE, “>$save_database”);
$locator =~ s/(//g;
$locator =~ s/)//g;
foreach $line (@records) {
$line2 = $line;
$line2 =~ s/(//g;
$line2 =~ s/)//g;
if ($line2 =~ /t$locatort/ && $searching) {
$line = ”;
foreach $f (@fields) {
$temp = $q->param(“$f”);
$temp =~ s/n//g;
$temp =~ s/cM//g;
$line .= $temp . “t”;
}
chop $line;
$line .= “n”;
$searching = 0;
}
print OUTFILE $line;
}
}
close (OUTFILE);
}
sub new_record {
print “