################################################################# # Database Definition Variables # ################################################################# $db{"breed"} = 0; $db{"group"} = 1; $db{"club_name"} = 2; $db{"club_contact"} = 3; $db{"club_address"} = 4; $db{"club_city"} = 5; $db{"club_state"} = 6; $db{"club_zip"} = 7; $db{"club_url"} = 8; $db{"club_email"} = 9; $db{"links"} = 10; $db{"image"} = 11; $db{"pronounce"} = 12; $db{"bark"} = 13; $db{"descrip"} = 14; $db{"pros"} = 15; $db{"cons"} = 16; $db{"health"} = 17; $db{"fun"} = 18; $db{"history"} = 19; $db{"modification_time"}= 20; $db{"who_modified"} = 21; $db{"group_modified"} = 22; $db{"db_id"} = 23; $index_of_db_id_number = 23; $index_of_who_modified = 21; $index_of_group_who_modified = 22; $index_of_modification_time = 20; $index_of_field_to_be_sorted_by = "0"; # Information for different types of fields # additional important fields $index_for_email = 9; $index_of_multi_link_field = 10; $index_of_webpage = 8; $index_of_image = 11; @index_of_files = (12, 13); @index_of_uploads = ("image", "pronounce", "bark"); $index_for_menu = 0; @db_user_definable_field_order = ("breed", "group", "club_name", "club_contact", "club_address", "club_city", "club_state", "club_zip", "club_url", "club_email", "links", "image", "pronounce", "bark", "descrip", "pros", "cons", "health", "fun", "history"); @db_display_fields = ("Dog Breed", "Dog Group", "Dog Club Name", "Contact", "Address", "City", "State", "Zip", "Webpage", "Email", "Additional Links", "Picture", "Bark (sound)", "Pronunciation (sound)", "Description", "Pros (what we like about this breed)", "Cons(things to watch out for)", "Health & Genetics", "Fun things to do", "History & Uses"); @db_index_for_display = ($db{"breed"}, $db{"group"}, $db{"club_name"}, $db{"club_contact"}, $db{"club_address"}, $db{"club_city"}, $db{"club_state"}, $db{"club_zip"}, $db{"club_url"}, $db{"club_email"}, $db{"links"}, $db{"image"}, $db{"pronounce"}, $db{"bark"}, $db{"descrip"}, $db{"pros"}, $db{"cons"}, $db{"health"}, $db{"fun"}, $db{"history"}); @db_query_criteria = ("breed|0|=|string", "group|1|=|string", "club_name|2|=|string", "club_contact|3|=|string", "club_address|4|=|string", "club_city|5|=|string", "club_state|6|=|string", "club_zip|7|=|string", "club_url|8|=|string", "club_email|9|=|string", "pronounce|14|=|string", "pros|15|=|string", "cons|16|=|string", "health|17|=|string", "fun|18|=|string", "history|18|=|string"); ######################################################################### # Authentication Variables # ######################################################################### $should_i_authenticate = "yes"; $auth_lib = "./Library"; $auth_server = "off"; $auth_cgi = "off"; $auth_user_file = "./Users/default.users"; $auth_alt_user_file = ""; $auth_default_group = "user"; $auth_add_register = "on"; $auth_allow_register = "on"; $auth_email_register = "off"; $auth_admin_from_address = "you\@yourdomain.com"; $auth_admin_email_address = "you\@yourdomain.com"; $auth_session_length = 1; $auth_session_dir = "./Session_files"; $auth_register_message = "Thanks, you may now logon with your new username and password."; $auth_allow_search = "off"; $auth_generate_password = "off"; $auth_check_duplicates = "on"; $auth_password_message = "Thanks for applying to our site, your password is"; @auth_extra_fields = ("auth_first_name", "auth_last_name", "auth_email"); @auth_extra_desc = ("First Name", "Last Name", "Email"); ################################################################# # Miscellaneous Variables # ################################################################# $site_title = "CARE Pet Database"; $bgcolor="#ffffff"; $data_file_path = "./Data_files/pet_info.data"; $max_rows_returned = "300"; $current_century = "20"; $this_script_url = "db_manager.cgi"; $location_of_counter_file = "./Data_files/pet_info.counter"; $location_of_log_file = "./Data_files/pet_info.log"; $location_of_lock_file = "./Data_files/pet_info.lock"; $upload_dir = "./files"; ################################################################# # Generic Header Subroutine # ################################################################# sub generic_header { local ($title) = @_; print qq~ $site_title - $title ~; } ################################################################# # Generic Form Header Subroutine # ################################################################# sub generic_form_header { #
~; } ################################################################# # Generic Form Footer Subroutine # ################################################################# sub generic_form_footer { print qq~
~; } ################################################################# # Display Frontpoage Subroutine # ################################################################# sub display_frontpage { print qq~
Please choose a database management function from the buttons below.

~; # # # # print qq~

~; } ################################################################# # Print Database Subroutine # ################################################################# sub print_db { &generic_header("All Information"); foreach $row (@database_rows) { print ""; @fields = split (/\|/, $row); foreach $index (@db_index_for_display) { $fields[$index] =~ s/~p~/\|/g; # $fields[$index] =~ s/~nl~/\n/g; $fields[$index] =~ s/~nl~~nl~/

/g; $fields[$index] =~ s/~nl~/
/g; if ($index != $index_for_email) { print qq~

\n ~; } } # End of foreach $index (@db_index_for_display) print ""; print "
@db_display_fields[$index] $fields[$index]-

"; } print ""; } ################################################################# # Print Menu Subroutine # ################################################################# sub print_menu { local ($frame) = @_; &generic_header("All Entries"); print "

Click on the Dog who's information you would like to modify

"; print "
"; # get names and id's of database entries for ($i=0; $i<=$#database_rows;$i++) { @fields = split(/\|/,$database_rows[$i]); if ($frame =~ /y/i) { print ""; } else { if ($i==0) { print "
\n"; } elsif ($i== ( int $#database_rows/2)) { print "\n" } print ""; } print "$fields[$index_for_menu]
\n"; } if (($frame =~ /[^y]/i) || ($frame =~ /^$/)) { print "
"; } # add item button print qq~
~; print "
"; } sub bad_file { print "can't find file $data_file_path"; } ################################################################# # Add Item Form Subroutine # ################################################################# sub add_form_header { print qq~

Add an Entry to the Database

~; } sub add_modify_data_entry_form { print qq~
Dog breed
Dog class
Image
file extension
Pronunciation (sound file)
file extension
Bark (sound file)
file extension
Dog club
Contact
Address
City
State
Zip
club web address
Club email
Additional links
Descriptions
Pros
(Things we like about this breed)
Cons
(things to be aware of about this breed)
Health (& Genetic) Considerations
Fun Things to Do
Breed History
~; } sub add_form_footer { print qq~

~; } ################################################################# # Modify Search Form Subroutine # ################################################################# sub modify_search_form { &generic_header("Search for an Item to Modify"); &generic_form_header; print qq~

Search the Database for Item to Modify

~; &display_generic_search_form; print qq~

~; &generic_form_footer; } ################################################################# # Delete Search Form Subroutine # ################################################################# sub delete_search_form { &generic_header("Search for an Item to Delete"); &generic_form_header; print qq~

Search the Database for Item to Delete

~; &display_generic_search_form; print qq~

~; &generic_form_footer; } ################################################################# # View Database Form Subroutine # ################################################################# sub view_database_form { &generic_header("Search the Database"); &generic_form_header; print qq~

Search the Database

~; &display_generic_search_form; print qq~

~; &generic_form_footer; } ################################################################# # Display Generic Search Form Subroutine # ################################################################# sub display_generic_search_form { print qq~

Keyword Searching
In the following text fields, you may search the database according to keywords. You can also use the exact match and case sensitive boxes to modify your search
Breed
Dog Group
~; } ################################################################# # search_results_single Subroutine # ################################################################# sub search_results_single { # Notice that in this subroutine we have access to the # $total_row_count hits variable if we want to display it. if ($form_data{'search_and_display_for_deletion_button'} ne "") { print "Item to Delete\n"; } elsif ($form_data{'search_and_display_for_modification_button'} ne "") { print "Item to Modify\n"; } else { print "$site_title Information

\n"; } print ""; # Basically, we will display a simple HTML table to show # all of the rows which satisfied the search criteria # entered by the user. # # The idea is this. We will go through the @database_rows # (which was given to us by db-lib.pl and contains all of # the hits) one element at a time and convert the pipe # delimited database row into an HTML row. foreach $row (@database_rows) { @fields = split (/\|/, $row); # Of course, we will only actually display fields which we # have defined as displayable in @db_index_for_display and # we will be careful to convert all pipe sybmbols and new # lines from our db representation values into their # original forms. if ($form_data{'search_and_display_for_modification_button'} ne "") { print qq~ ~; } if ($form_data{'search_and_display_for_deletion_button'} ne "") { print qq~ ~; } foreach $index (@db_index_for_display) { $fields[$index] =~ s/~p~/\|/g; $fields[$index] =~ s/~nl~/
\n/g; } # Also, we will check to see if the current field being # displayed happens to be an email field. If so, we will # make it a clickable mailto link. # # Notice that you would use the exact same method for # making a clickable URL. } print qq~
@db_display_fields[0] $fields[0]
@db_display_fields[1] $fields[1]
@db_display_fields[11]

file extension
@db_display_fields[12] $fields[12]

file extension
@db_display_fields[13] $fields[13]

file extension
@db_display_fields[2] $fields[2]
@db_display_fields[3] $fields[3]
@db_display_fields[4] $fields[4]
@db_display_fields[5] $fields[5]
@db_display_fields[6] $fields[6]
@db_display_fields[7] $fields[7]
@db_display_fields[8] $fields[8]
@db_display_fields[9] $fields[9]
@db_display_fields[10] $fields[10]
@db_display_fields[14] $fields[14]
@db_display_fields[15] $fields[15]
@db_display_fields[16] $fields[16]
@db_display_fields[17] $fields[17]
@db_display_fields[18] $fields[18]
@db_display_fields[19] $fields[19]
~; } ################################################################# # search_results_single_footer Subroutine # ################################################################# sub search_results_single_footer { print qq~

~; # In this subroutine we can include just a little bit of # logic in order to create a "See more hits button" # # The besic logic is that they either 1) still have more # than the $max_rows_returned hits to see, 2) have only 1 # more hit to see, 3) have less than $max_rows_returned # but more than 1 hit to see, or 4) have no hits left to # see. # # These cases are handled in three if tests (the 4th case, # in which there are no more hits to see just defaults to # the tags since no submit button need be # created.) if ($form_data{'search_and_display_for_deletion_button'} ne "") { print qq~

~; } if ($form_data{'search_and_display_for_modification_button'} ne "") { print qq~

~; } print qq~ ~; &generic_form_footer; } ################################################################# # search_results_body Subroutine # ################################################################# sub search_results_body { # Notice that in this subroutine we have access to the # $total_row_count hits variable if we want to display it. if ($total_row_count > $max_rows_returned) { print qq~ Your search turned up $total_row_count hits, but I am designed to only show you $max_rows_returned at a time. I suggest you narrow your search criteria a bit.

~; } else { print qq~ Your search turned up $total_row_count hits.

~; } # We next need to display the table header. Make sure # that in the case of modify and delete we add a colmun so # that the user can select items to be modified or # deleted. print qq~ ~; if ($form_data{'search_and_display_for_deletion_button'} ne "") { print "\n"; } elsif ($form_data{'search_and_display_for_modification_button'} ne "") { print "\n"; } foreach $header (@db_display_fields) { print "\n"; } print ""; # Basically, we will display a simple HTML table to show # all of the rows which satisfied the search criteria # entered by the user. # # The idea is this. We will go through the @database_rows # (which was given to us by db-lib.pl and contains all of # the hits) one element at a time and convert the pipe # delimited database row into an HTML row. foreach $row (@database_rows) { @fields = split (/\|/, $row); if ($form_data{'search_and_display_for_modification_button'} ne "") { print qq~ ~; } if ($form_data{'search_and_display_for_deletion_button'} ne "") { print qq~ ~; } # Of course, we will only actually display fields which we # have defined as displayable in @db_index_for_display and # we will be careful to convert all pipe sybmbols and new # lines from our db representation values into their # original forms. foreach $index (@db_index_for_display) { $fields[$index] =~ s/~p~/\|/g; $fields[$index] =~ s/~nl~/\n/g; # Also, we will check to see if the current field being # displayed happens to be an email field. If so, we will # make it a clickable mailto link. # # Notice that you would use the exact same method for # making a clickable URL. if ($index == $index_for_email) { if ($fields[$index] ne "") { print qq~ \n ~; } else { print qq~ ~; } } elsif ($index == $index_of_webpage) { if ($fields[$index] ne "") { print qq~ ~; } else { print qq~ ~; } } elsif ($index == $index_of_image) { if ($fields[$index] ne "") { print qq~ ~; } else { print qq~ ~; } } # elsif ($index == is in @index_of_files elsif (($index == $index_of_files[0]) || ($index == $index_of_files[1])) { if ($fields[$index] ne "") { print qq~ ~; } else { print qq~ ~; } } elsif ($index == $index_of_multi_link_field) { print ""; } else { if ($fields[$index] ne "") { print qq~ ~; } else { print qq~ ~; } } } # End of foreach $index (@db_index_for_display) print ""; } print "
Select Items to DeleteSelect Item to Modify$header
$fields[$index].$fields[$index].. $upload_dir/$fields[$index]."; @links = split (/,/, $fields[$index]); foreach $link (@links) { print "$link "; } print "$fields[$index].
"; } ################################################################# # search_results_footer Subroutine # ################################################################# sub search_results_footer { print qq~

~; # In this subroutine we can include just a little bit of # logic in order to create a "See more hits button" # # The besic logic is that they either 1) still have more # than the $max_rows_returned hits to see, 2) have only 1 # more hit to see, 3) have less than $max_rows_returned # but more than 1 hit to see, or 4) have no hits left to # see. # # These cases are handled in three if tests (the 4th case, # in which there are no more hits to see just defaults to # the tags since no submit button need be # created.) if ($form_data{'search_and_display_for_deletion_button'} ne "") { print qq~

~; } if ($form_data{'search_and_display_for_modification_button'} ne "") { &add_modify_data_entry_form; print qq~

~; } print qq~ ~; &generic_form_footer; } ################################################################# # search_and_display Subroutines # ################################################################# sub search_and_display_db_for_view { &generic_header("View"); &generic_form_header; &search_and_display_db; } sub search_and_display_for_modification { &generic_header("Modify"); &generic_form_header; &search_and_display_db; } sub search_and_display_for_deletion { &generic_header("Delete"); &generic_form_header; &search_and_display_db; } ################################################################# # Message Subroutines # ################################################################# sub no_hits_message { print qq~

I am sorry, but it appears that there were no records in the database that matched your search criteria, please try again.
~; } sub successful_addition_message { &generic_header("Success: Your Item has been added to the Database"); print qq~
Your Item has been successfully added!

~; &display_frontpage; &generic_form_footer; } sub successful_deletion_message { &generic_header("Success: Your Item has been Deleted from the Database"); print qq~
Your Item has been successfully deleted!

~; &display_frontpage; &generic_form_footer; } sub successful_modification_message { &generic_header("Success: Your Item has been modified in the Database"); print qq~
Your Item has been successfully modified!

~; &display_frontpage; &generic_form_footer; } sub unsuccessful_modification_message { &generic_header("Success: Your Item has been modified in the Database"); print qq~ I am sorry but you are only allowed to modify items added by you or those within your group. ~; } sub no_item_submitted_for_modification { &generic_header("Error: Your Item has not been modified"); print qq~ I am sorry but I was unable to modify the database because you did not select an item to modify. Would you please hit the back button and make sure that you use the radio button or checkbox to choose an item to modify or delete? Thank you. ~; }