################################################################# # Database Definition Variables # ################################################################# #Columns of database $db{"gen_name"} = 0; $db{"trade_name"} = 1; $db{"drug_class"} = 2; $db{"indications"} = 3; $db{"pharmacodynamics"} = 4; $db{"side_effects"} = 5; $db{"pharmacokinetics"} = 6; $db{"routes"} = 7; $db{"similar"} = 8; $db{"remarks"} = 9; $db{"email"} = 10; $db{"modification_time"}= 11; $db{"who_modified"} = 12; $db{"group_modified"} = 13; $db{"db_id"} = 14; #Where things are located $index_of_db_id_number = 14; $index_of_who_modified = 12; $index_of_group_who_modified = 13; $index_of_modification_time = 11; $index_for_email = 10; $index_of_field_to_be_sorted_by = "0"; #What can be edited by owners @db_user_definable_field_order = ("gen_name", "trade_name", "drug_class", "indications", "pharmacodynamics", "side_effects", "pharmacokinetics", "routes", "similar", "remarks", "email"); #these will become parameters which can contain multiple fields (ie. checkboxes), #they will become comma delimited. @multi_fields = ("side_effects", "routes"); #Move the addition fields to here @db_user_add_field_order = ( "", "", "", "", "", " CNS CV Derm Endo GI GU Hemo Immuno Musc/Skel None Resp Teratogenic Other", "", " inhalation intramuscular intrathecal intravenous oral subcutaneous topical", " ", "", ""); #Fields to be added by adders @db_add_fields = ("Generic Name", "Trade Name", "Drug Class", "Indications", "Pharmacodynamics", "Side Effects", "Pharmacokinetics", "Administration Routes", "Similar Drugs", "Remarks", "Email"); #What is viewed by viewers, headers @db_display_fields = ("Generic Name", "Trade Name", "Drug Class", "Indications", "Pharmacodynamics", "Side Effects", "Pharmacokinetics", "Administration Routes", "Similar Drugs", "Remarks", "Email"); #What is viewed by viewers, body @db_index_for_display = ($db{"gen_name"}, $db{"trade_name"}, $db{"drug_class"}, $db{"indications"}, $db{"pharmacodynamics"}, $db{"side_effects"}, $db{"pharmacokinetics"}, $db{"routes"}, $db{"similar"}, $db{"remarks"}, $db{"email"}); #possible searches of data @db_query_criteria = ("keywords|0,1,2,3,4,5,6,7,9|=|string", "gen_name|0|=|string", "trade_name|1|=|string", "drug_class|2|=|string", "indications|3|=|string", "pharmacodynamics|4|=|string", "side_effects|5|=|string", "pharmacokinetics|6|=|string", "pharmacokinetics|7|=|string", "routes|8|=|string", "similar|10|=|string", "remarks|11|=|string"); ######################################################################### # Authentication Variables # ######################################################################### $should_i_authenticate = "no"; $auth_lib = "./Library"; $auth_server = "off"; $auth_cgi = "on"; $auth_user_file = "./Users/drug.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 = "doyle\@cs.umn.edu"; $auth_admin_email_address = "doyle\@cs.umn.edu"; $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 # ################################################################# $data_file_path = "./Data_files/drug.data"; $max_rows_returned = "50"; $current_century = "20"; $this_script_url = "db_manager.cgi"; $location_of_counter_file = "./Data_files/drug.counter"; $location_of_log_file = "./Data_files/drug.log"; $location_of_lock_file = "./Data_files/drug.lock"; ##### Specifically for ISAP ##### $MOD_DATE='10/02/97'; # Date last modified $HOME = 'index.cgi'; # $SCRIPT_AUTHOR='Dave Doyle'; # $AUTHOR_EMAIL='doyle@cs.umn.edu '; # $QUESTIONS_NAME='Len Lichtblau'; # Contact person $QUESTIONS_ADDR='len@phcl.umn.edu'; # ################################################################# # Add to Log Subroutine # ################################################################# sub add_to_log { local ($drug_to_log) = @_; @time = localtime(time); $mon = $time[4]+1; $time = "$time[2]:$time[1]-$mon/$time[3]/$time[5]"; ($user, $access_string, $random) = split(/:/, $form_data{'session_key'}); open (LOG, ">>admin/drug_log") || die "$0: can\'t open drug_log: $!\n"; print LOG "$drug_to_log $access_string $time\n"; close(LOG); } ################################################################# # Generic Header Subroutine # ################################################################# sub generic_header { local ($title) = @_; print qq~ $title ~; } ################################################################# # Generic Form Header Subroutine # ################################################################# sub generic_form_header { print qq~
~; foreach $multi_field (@multi_fields) { print qq~ ~; } foreach $key (keys(%db)) { if ($form_data{$key} ne "") { print qq~ ~; } } if ($form_data{keywords} ne "") { print qq~ ~; } } ################################################################# # Generic Form Footer Subroutine # ################################################################# sub generic_form_footer { print qq~

--------
Script Author: $SCRIPT_AUTHOR
For Questions or Comments: $QUESTIONS_NAME
Script Last Updated: $MOD_DATE
~; } ################################################################# # Display Frontpage Subroutine # ################################################################# sub display_frontpage { print qq~

Please choose a database management function from the buttons below.

~; } ################################################################# # Add Subroutine header and footer # ################################################################# sub add_form_header { print qq~

Add an Entry to the Database

~; } sub add_form_footer { print qq~

~; } ################################################################# # Add Item Form Subroutine # ################################################################# sub add_modify_data_entry_form { print qq~
~; for ($i=0; $i<$#db_user_add_field_order; $i++) { print ""; print ""; print ""; print ""; } print qq~
$db_add_fields[$i]$db_user_add_field_order[$i]
~; } ################################################################# # search_and_display_for_modification Subroutine # ################################################################# sub search_and_display_for_modification { &generic_header("Modify Data"); &generic_form_header; &search_and_display_db; } ################################################################# # 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; } ################################################################# # search_and_display_for_deletion Subroutine # ################################################################# sub search_and_display_for_deletion { &generic_header("Delete Data"); &generic_form_header; &search_and_display_db; } ################################################################# # 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
Keywords

More Specific Searching
In the following fields, you can enter the word or words that would help find information about specific drugs.
Drug Name(s)
Similar Drug(s)

Sort by which field
~; } ################################################################# # search_and_display_db_for_view Subroutine # ################################################################# sub search_and_display_db_for_view { &generic_header("Records that Fit the Criteria"); &generic_form_header; &search_and_display_db; } ################################################################# # 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 "Expanded Drug 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. if ($form_data{'search_and_display_for_modification_button'} ne "") { print ""; } else { print ""; } if ($index == $index_for_email) { print qq~ \n ~; } else { print qq~ \n ~; } if ($form_data{'search_and_display_for_modification_button'} ne "") { print ""; } } # End of foreach $index (@db_index_for_display) } print "
@db_display_fields[$index]
@db_display_fields[$index]$fields[$index].
$fields[$index].
$db_user_add_field_order[$index]
"; } ################################################################# # 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_multi Subroutine # ################################################################# sub search_results_multi { # 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) { print qq~ \n~; } else { print qq~ \n~; } } # End of foreach $index (@db_index_for_display) print ""; } print "
Select Items to DeleteSelect Item to Modify$header
$fields[$index]$fields[$index].
"; } ################################################################# # search_results_multi_footer Subroutine # ################################################################# sub search_results_multi_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~

~; } &generic_form_footer; } ################################################################# # Messages 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("Error: Your item has not been modified"); print qq~ I am sorry but you are only allowed to modify items added by you or those within your group.~; &generic_form_footer; } 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.~; &generic_form_footer; }