Gossamer Forum
Home : Products : DBMan : Customization :

Modify Date in Search Results

Quote Reply
Modify Date in Search Results
Hello,

Here is one I hope perhaps we can look at: Is there a way to Modify all or part (via selection) of a user's records at once - Modifying ONLY the date field - updating it to today's date.

As an example: User "A" has 7 records annd wants the date modified on 4 of them - is there a quick way of doing this?

I have added $rec{'Date'} = &get_date(); in the html_modify_form_record which pulls up the current date when a user wants has selected a record to modify - I was hoping that perhaps there was a way to save steps, especially if only the date were to be modified.

Thanks,

Jim

Quote Reply
Re: Modify Date in Search Results In reply to
It would be possible. I'll see if I can work it out after I get through all the other questions for today.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Modify Date in Search Results In reply to
Didn't want to start a new thread - but if anyone has any thoughts to this challenge please let me know.

Thanks!

Jim

Quote Reply
Re: Modify Date in Search Results In reply to
I'm sorry. I completely forgot about this. Deepest apologies.

(But you did the right thing. Respond to the same thread and bring it to the top.)

I am going to need to ask you another question, though. Do you want users to select which ones to update while they're on the modify_form?

You can do this two ways. You can either have the current modify form, with an additional checkbox next to the fields or you can have a separate subroutine for this. The first option means a little less coding. Smile


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Modify Date in Search Results In reply to
The "easy" route: have the current modify form, with an additional checkbox next to the fields - it would be "ideal" to be able to check multiple records e.g say there are ten records - check the seven to update date only then click "modify these dates" -

Hope I am being clear and thanks for your help.

Jim


Quote Reply
Re: Modify Date in Search Results In reply to
Yep. I got it.

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>

add

<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">

add

<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; } }

add

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

Add a new subroutine to db.cgi:

Code:

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.");
return;
}

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.
}
I've checked this for syntax errors, but not in practice. It's really just a modification of sub delete_records, though, so it should work.


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Modify Date in Search Results In reply to
Worked Great! A couple of things worth mentioning:

I needed this for two of my sites - one with dbman, the other SQLdbman - could not get it to work with sql - got same cgi-error I have gotten with other mods - which states that it cannot connect to database.

If any one has any thoughts about this mod (or any other) when using the SQL version that would be appreciated - I have posted a couple of times on the sql forum but the traffic there is still pretty thin.

Thanks, JP, once again for all your time.

Jim

Quote Reply
Re: Modify Date in Search Results In reply to
I'm not sure how this would work in SQL. It definitely would not work there, since sub modify_dates accesses the .db file, which doesn't exist in DBMan-SQL.

One of these days I'm going to learn SQL. Smile

JPD
http://www.jpdeni.com/dbman/