Web DB Administrator

Search Database

Search in: Sort ascending on first field

Exact Match Search Within


Display Database Contents

Sort ascending on first field

Add to Database

- Name

- E-mail

- birthday


Delete Records

Delete where field is:


########################################################################## Search

Search Our Database

Search in: Sort ascending on first field

Exact Match Search Within

########################################################################## Add Record

Add To Our Database

- Name

- E-mail

- birthday

########################################################################## #! /usr/local/bin/perl # birthday_adm.pl use Fcntl ":flock"; if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $contents{$name} = $value; } } # database file $mydb = "/bdays/birthday_db.txt"; # temp database for manouvers $tempdb = "/bdays/birthday_tmp.txt"; print "Content-type: text/html\n\n"; # add to db if ($contents{'job'} eq "add") { @allfields = ($contents{'Name'},$contents{'E-mail'},$contents{'birthday'}); foreach $allf (@allfields){ #check to verify no pipes $indval = index($allf,"|"); if($indval > -1){ print "

Pipe in entry: $allf.

"; print "Pipes cannot be entered into database. Please change this entry."; exit; } } open(DB, ">>$mydb") || do {&open_not;}; flock(DB, LOCK_EX); print DB "$contents{'Name'}|$contents{'E-mail'}|$contents{'birthday'}\n"; flock(DB, LOCK_UN); close(DB); print <<"HTML"; Record Added

Thank you. Your information has been added to the database

HTML exit; } if ($contents{'job'} eq "search") { $kw = $contents{'keyword'}; $kw =~ s/^\s+//; $kw =~ s/\s+$//; # need some html first, to loop in table entries later print <<"HTML"; Search Database

Search results for "$contents{'keyword'}":

HTML open(DB, "$mydb") || do {&open_not;}; $counter = 0; while() { ($afld[0], $afld[1], $afld[2], $rmdr) = split(/\|/); chop($afld[2]); if ($contents{'srchtype'} eq "within") { if ($contents{'field'} eq "all") { if ($afld[0] =~/$kw/gi ||$afld[1] =~/$kw/gi ||$afld[2] =~/$kw/gi) { if ($contents{'search_sort'} eq "sort"){ $store_array[$counter] = "$afld[0]|$afld[1]|$afld[2]"; } else{ print ""; } $counter++; } } if ($contents{'field'} ne "all") { if ($afld[$contents{'field'}] =~ /$kw/gi) { if ($contents{'search_sort'} eq "sort"){ $store_array[$counter] = "$afld[0]|$afld[1]|$afld[2]"; } else{ print ""; } $counter++; } } } if ($contents{'srchtype'} eq "exact") { if ($contents{'field'} eq "all") { if ($afld[0] eq "$kw" ||$afld[1] eq "$kw" ||$afld[2] eq "$kw") { if ($contents{'search_sort'} eq "sort"){ $store_array[$counter] = "$afld[0]|$afld[1]|$afld[2]"; } else{ print ""; } $counter++; } } if ($contents{'field'} ne "all") { if ($afld[$contents{'field'}] eq "$kw") { if ($contents{'search_sort'} eq "sort"){ $store_array[$counter] = "$afld[0]|$afld[1]|$afld[2]"; } else{ print ""; } $counter++; } } } } close(DB); if ($contents{'search_sort'} eq "sort"){ if ($counter > 0){ @store_array = sort @store_array; foreach $star (@store_array){ @et = split(/\|/, $star); print ""; } } else{ print "No Matches Found"; } } elsif ($counter == 0) { print "No Matches Found"; } print <<"HTML";
NameE-mailbirthday
$afld[0]$afld[1]$afld[2]
$afld[0]$afld[1]$afld[2]
$afld[0]$afld[1]$afld[2]
$afld[0]$afld[1]$afld[2]
$et[0]$et[1]$et[2]


HTML exit; } if ($contents{'job'} eq "display") { print <<"HTML"; Display Database

birthday Database

HTML if ($contents{'sort_first'} eq "sort"){ open (DB, "$mydb") || do {&open_not;}; @file = ; close(DB); @file = sort @file; foreach $line (@file){ @entry = split(/\|/, $line); print ""; } } else{ open (DB, "$mydb") || do {&open_not;}; until (eof(DB)) { $line = ; @entry = split(/\|/, $line); print ""; } close(DB); } print <<"HTML";
NameE-mailbirthday
$entry[0]$entry[1]$entry[2]
$entry[0]$entry[1]$entry[2]


HTML exit; } if ($contents{'job'} eq "delete") { $kw = $contents{'keyword'}; $kw =~ s/^\s+//; $kw =~ s/\s+$//; $counter = 0; open(TEMP, ">>$tempdb") || do {&open_not;}; flock(TEMP, LOCK_EX); open(DB, $mydb) || do {&open_not;}; while () { $same = ""; ($afld[0], $afld[1], $afld[2], $rmdr) = split(/\|/); chop($afld[2]); if ($afld[$contents{'field'}] eq "$kw") { $counter++; $same = 1; } print TEMP $_ unless ($same == 1); } flock (DB, LOCK_EX); unlink($mydb); rename($tempdb, $mydb); flock (DB, LOCK_UN); flock (TEMP, LOCK_UN); close(TEMP); close(DB); print <<"HTML"; Deletion Report HTML if ($counter == 0) { print <<"HTML";

No Records Countained $kw

HTML } else { print <<"HTML";

birthday Database - Updated

$counter record(s) deleted!

HTML } print <<"HTML"; HTML exit; } sub open_not { print <<"HTML"; Access Error!

OOPS! Database could not be opened.

HTML exit; } ########################################################################## #! /usr/local/bin/perl # students_vis.pl use Fcntl ":flock"; if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $contents{$name} = $value; } } # database file $mydb = "/bdays/birthday_db.txt"; print "Content-type: text/html\n\n"; # add to db if ($contents{'job'} eq "add") { @allfields = ($contents{'Name'},$contents{'E-mail'},$contents{'birthday'}); foreach $allf (@allfields){ #check to verify no pipes $indval = index($allf,"|"); if($indval > -1){ print "

Pipe in entry: $allf.

"; print "Pipes cannot be entered into database. Please change this entry."; exit; } } open(DB, ">>$mydb") || do {&open_not;}; flock(DB, LOCK_EX); print DB "$contents{'Name'}|$contents{'E-mail'}|$contents{'birthday'}\n"; flock(DB, LOCK_UN); close(DB); print <<"HTML"; Record Added

Thank you. Your information has been added to the database

HTML exit; } if ($contents{'job'} eq "search") { $kw = $contents{'keyword'}; $kw =~ s/^\s+//; $kw =~ s/\s+$//; # need some html first, to loop in table entries later print <<"HTML"; Search Database

Search results for "$contents{'keyword'}":

HTML open(DB, "$mydb") || do {&open_not;}; $counter = 0; while() { ($afld[0], $afld[1], $afld[2], $rmdr) = split(/\|/); chop($afld[2]); if ($contents{'srchtype'} eq "within") { if ($contents{'field'} eq "all") { if ($afld[0] =~/$kw/gi ||$afld[1] =~/$kw/gi ||$afld[2] =~/$kw/gi) { if ($contents{'search_sort'} eq "sort"){ $store_array[$counter] = "$afld[0]|$afld[1]|$afld[2]"; } else{ print ""; } $counter++; } } if ($contents{'field'} ne "all") { if ($afld[$contents{'field'}] =~ /$kw/gi) { if ($contents{'search_sort'} eq "sort"){ $store_array[$counter] = "$afld[0]|$afld[1]|$afld[2]"; } else{ print ""; } $counter++; } } } if ($contents{'srchtype'} eq "exact") { if ($contents{'field'} eq "all") { if ($afld[0] eq "$kw" ||$afld[1] eq "$kw" ||$afld[2] eq "$kw") { if ($contents{'search_sort'} eq "sort"){ $store_array[$counter] = "$afld[0]|$afld[1]|$afld[2]"; } else{ print ""; } $counter++; } } if ($contents{'field'} ne "all") { if ($afld[$contents{'field'}] eq "$kw") { if ($contents{'search_sort'} eq "sort"){ $store_array[$counter] = "$afld[0]|$afld[1]|$afld[2]"; } else{ print ""; } $counter++; } } } } close(DB); if ($contents{'search_sort'} eq "sort"){ if ($counter > 0){ @store_array = sort @store_array; foreach $star (@store_array){ @et = split(/\|/, $star); print ""; } } else{ print "No Matches Found"; } } elsif ($counter == 0) { print "No Matches Found"; } print <<"HTML";
NameE-mailbirthday
$afld[0]$afld[1]$afld[2]
$afld[0]$afld[1]$afld[2]
$afld[0]$afld[1]$afld[2]
$afld[0]$afld[1]$afld[2]
$et[0]$et[1]$et[2]


HTML exit; } sub open_not { print <<"HTML"; Access Error!

OOPS! Database could not be opened.