Gossamer Forum
Home : Products : DBMan SQL : Discussion :

New Mod - Almost!

Quote Reply
New Mod - Almost!
I have a successful Mod - thanks to JPDeni - which enables a user to update DATES ONLY without going to each record by clicking check boxes.

Anyway, got it going find with non-sql but am very much struggling with SQL version (which I have license)

I am looking for assistance - I have tried a variety of changes (particulary in connection to mysql with no luck) Here is the non-sql MOD: (you can see / test in action at:http://www.jobboardindex.com/cgi-bin/dbman/db.cgi log-in test /test (hit "list all" after modify)

The MOD:

First, you're going to want to add instructions to the page to tell folks what to do.

Then, in the line that includes

<TD><INPUT TYPE=RADIO NAME="modify" VALUE="$tmp{$db_key}"></TD>


<TD><INPUT TYPE=CHECKBOX NAME="$tmp{$db_key}" VALUE="modify"></TD>

You can put this either before or after the radio field, depending on where you want the checkbox to appear.

At the end of the form, either before or after

<input type="SUBMIT" name="modify_form_record" value="Modify Record">


<input type="SUBMIT" name="modify_dates" value="Modify Dates">

You can, naturally, change the text to whatever you want.

Copy sub html_delete_success and sub html_delete_failure and rename them to sub html_modify_dates_success and sub html_modify_dates_failure. Make any changes you want to the text on the pages.

In db.cgi, sub main, after

elsif ($in{'modify_form'}) { if ($per_mod) { &html_modify_form; } else { &html_unauth; } }


elsif ($in{modify_dates'}) { if ($per_mod) { &modify_dates; } else { &html_unauth; } }

Add a new subroutine to db.cgi:

sub modify_dates {
# --------------------------------------------------------

my ($key, %mod_list, $rec_to_mod, @lines, $line, @data, $errstr, $succstr, $output,
$restricted, %mod_tmp);
$rec_to_mod = 0;
foreach $key (keys %in) { # Build a hash of keys to mod.
if ($in{$key} eq "modify") {
$mod_list{$key} = 1;
$rec_to_mod = 1;
if (!$rec_to_mod) {
&html_modify_dates_failure("no records specified.");

open (DB, "<$db_file_name") or
&cgierr("error in modify_dates. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;

($restricted = 1) if ($auth_modify_own and !$per_admin);

LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);
($output .= "$line\n" and next LINE) if ($restricted and ($db_userid ne $data[$auth_user_field]));

if ($mod_list{$data[$db_key_pos]}) {
$mod_list{$data[$db_key_pos]} = 0;
%mod_tmp = &array_to_hash(0,@data);
# Change the line below to match your field name
$mod_tmp{'Date'} = &get_date;
$output .= &join_encode(%mod_tmp);
else {
$output .= $line . "\n";

foreach $key (keys %mod_list) {
$mod_list{$key} ? # Check to see if any items weren't modified
($errstr .= "$key,") : # that should have been.
($succstr .= "$key,"); # For logging, we'll remember the one's we modified.
chop($succstr); # Remove trailing delimeter
chop($errstr); # Remove trailing delimeter

open (DB, ">$db_file_name") or
&cgierr("error in modify_dates. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
print DB $output;
close DB; # automatically removes file lock

&auth_logging("modified records: $succstr") if ($auth_logging);
$errstr ? # Do we have an error?
&html_modify_dates_failure($errstr) : # If so, then let's report go to the failure page,
&html_modify_dates_success($succstr); # else, everything went fine.