Ronnie D. Jewell submitted this hack to the WebDB manager program. His
modification allows one the ability to modify several prices at one
time. With some slight modification one could also change any field
with this hack.
After your database is setup; changing prices is probably the most
common task used by managers. In the original version, one must search
for the record, click to indicate which record to modify, enter the new
field data, then submit changes. This is fine and works well. However,
what if one needs to modify the prices for an entire category or
database for that matter? I have modified Selena's wonderful database
manager program so managers could modify multiply prices with one click
of the button.
Most of the changes are in the database.setup file. Here is an
overview of what needs to be added and modified. First, we need a
"Modify Prices" button on the front page. This command will display the
generic search form, after search criteria is enterd, the user submits
the search and the Modify Price form is displayed. The user will make
price changes and submit the changes.
Here's how we do it.
Open your setup file and follow the steps below.
Step 1. In the section "Database Definition Variables" add the
following lines:
####### start cut #######
@price_display_fields = ("SKU Number",
"Description",
"Price
Enter new price"
);
@price_index_for_display = ($db{"product_id"},
$db{"description"},
$db{"price_r"} # set to match you price field
also defined in this section
);
######## end #######
This will display only the Model Number, Description and Price.. There
is no need to view he images or any other data since we are only
interested in price.
Step 2. In the "Display Frontpage Subroutine" add the following:
This simply displays the "Modify Prices" button on the frontpage
Step 3. Replace the "Modify Search Form Subroutine" with the following:
#################################################################
# Modify Search Form Subroutine #
#################################################################
sub modify_search_form
{
&generic_header("Search for an Item to Modify");
&generic_form_header;
print qq~
~; } 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~
| Select Items to Delete | \n"; } elsif ($form_data{'search_and_display_for_modification_button'} ne "") { print "Select Item to Modify | \n"; } ### rdj added for price modifications ###### elsif ($form_data{'search_and_display_for_price_button'} ne "") { foreach $header (@price_display_fields) { print "$header | \n"; } print "$fields[$index] | \n~; } elsif ($index == $index_for_price) { ## you may need to change the name of this input to match your price field value ## print qq~\n~; } else { print " | $fields[$index] | \n"; } } # End of foreach $index (@db_index_for_display) print ""; } print "
|---|
~; } ### add these lines ### if ($form_data{'search_and_display_for_price_button'} ne "") { print qq~
~;
}
### end add ###
Well thats the end of the modifications needed in the setup file.. Now
we will move on to the db_manager.cgi file.
Step 1. Add three elsif statements to the other 11 routines (about 1/3
the way down the script):
You should see these lines
elsif ($form_data{'submit_addition'} ne "")
{
&submit_addition;
exit;
}
#### add these three subroutines here ###
elsif ($form_data{'modify_price_button'} ne "")
{
&modify_search_form;
exit;
}
elsif ($form_data{'search_and_display_for_price_button'} ne "")
{
&search_and_display_for_modification;
exit;
}
elsif ($form_data{'submit_price_modification_button'} ne "")
{
&submit_new_price;
exit;
}
### end addition ####
Step 2. Add this subroutine between the submit_addition and
submit_modify subroutines:
#######################################################################
# Submit a price change #
# added by RDJ 11/28/98 #
#######################################################################
# The user might also be submitting a modification to the
# database.
sub submit_new_price
{
# The first thing we must do is make sure that they
# actually chose a database item to modify. If they did
# not, we better warn them and stop processing.
if ($form_data{'item_to_modify'} eq "")
{
&no_item_submitted_for_modification;
exit;
}
# If they did choose an item, we need to find that items
# so that we can modify it. To do so, we'll open the data
# file and read through it a line at a time. We'll then
# split up each line into its fields and compare the id
# number given to us by the suer against the id number of
# the current line. If it is not the same, we will add
# the entire line to a variable called $new_data (By the
# end of this, $new_data is going to hold the entire
# contents of our database).
@item_to_modify = &SplitParam($form_data{'item_to_modify'});
@new_price = &SplitParam($form_data{'price_r'});
$p = 0;
foreach $item (@item_to_modify)
{
open (DATABASE, "$data_file_path") || &file_open_error
("$data_file_path", "Modify item", __FILE__, __LINE__);
while (