#!/usr/local/bin/perl # Dilip Barman, http://www.cs.unc.edu/Courses/wwwp-f97/members/barman # Sep 22 1997 # # dbDeleteRecord2.pl.cgi: Now that my perl project described at # www.cs.unc.edu/Courses/wwwp-f97/members/barman/perlProjectProposal.html, # is finally working (yeah!!), I'm going to implement the functionality of # deleting a record. This perl cgi-bin script is called from dbRetrieve2.pl.cgi # when a user pushes a submit button with name equal to the title to be # deleted. This program reads $title from STDIN, opens the DB in RW mode, # retrieves the record with that title, and asks for a confirmation of deletion. # If yes, the record is deleted. require "/afs/cs.unc.edu/project/courses/190-25f97/programs/perl/lib/cgi-lib.pl"; # GLOBAL VARIABLES $FALSE = 0; $TRUE = 1; # $DBFILENAME = "../musicDatabase/musicDB2"; # name of DBM database file $DBFILENAME = "/afs/cs.unc.edu/project/courses/190-25f97/members/barman/musicDatabase/musicDB2"; $ROACCESS = "0555"; # Read-Only open: RWX, so U=101, G=101, O=101 $RWACCESS = "0777"; # Read-Write open: 111 111 111 # Remember to set AFS directory permissions so system:anyuser (a web # client, for example) has write privilege to this directory -- # fs setat ../musicDatabase system:anyuser write # * * * P R O C E S S U S E R I N P U T * * * &ReadParse(*input); # Store input as attrib-value keys in variable input # Now $input[0] looks like "AlbumTitle=Delete" $_ = $input[0]; @words = split(/=/, $_); $title = $words[0]; # A bit more logic - special characters are read as hex - # "Eagle's GHs" is read as "Eagle%27s GHs" $title =~ s/%([0-9][0-9])/pack("c", hex($1)) /ge; # This is a modification of "magic" from class. # Look for % followed by 2 digits. Convert and repeat. # * * * T O P L E V E L H T M L S T U F F * * * print &PrintHeader; print ""; print "\nDilip's Music Database: Confirm Record Deletion"; print "\n

Music Database: Confirm \"$title\" Deletion

"; # * * * D A T A B A S E L O G I C * * * # No real validation as we click on something that is in the database # Simply access the record, and ask for validation. If okay, # call simple program dbDeleteRecordDoIt2.pl.cgi to delete the record. # Open the file and look for the record with the given key dbmopen(%RECORDS, $DBFILENAME, $RWACCESS); $value = $RECORDS{$title}; # Get value of this record # Do slick parse as in dbRetrieve2 ($artist,$genre,$format,$time,$comments) = split (/~/, $value); print "\n

Confirm Delete \"$title\"

"; print "\n

Artist: $artist"; print "\n
Genre: $genre"; print "\n
Format: $format"; print "\n
Time: $time"; print "\n
Comments: $comments"; print "\n
Database record: \"$value\""; # Put the button here to confirm print "\n


"; print "\n"; print "\nor return to main screen"; dbmclose(%RECORDS); # * * * W R A P U P H T M L * * * print "\n
"; print "\n

Read"; print "\n"; print "\nproject proposal or system"; print "\n"; print "\nimplementation notes

"; print "\n

Return to Dilip's course "; print""; print "home page

"; print "\n
Background courtesy of "; print "\nMoyra's Web Jewels
"; # End HTML page print "\n ";