Gossamer Forum
Home : Products : DBMan : Customization :

Automatic priority field update

Quote Reply
Automatic priority field update
I have a "Priority" field in the database containing number 1-n (n being number of records in db)

How can I allow a registered user (there's only 4 for this program) to change the Priority field of a record and have DBMan go through the database incrementing all Priority fields >= that number just set? Of course they will probably move the priorty down so it would have to decrement every Priorty field down to "n" also.

Any suggestions would be appreciated .............
Post deleted by barnefr In reply to
Quote Reply
Re: [barnefr] Automatic priority field update In reply to
Well, I was starting to feel neglected because no one attempted to answer my post, but then I noticed over 20 pages without replies. I hope someone will cruise over what I have so far & try to help.

So far I have:
1) a task program written with DBMan.
2) it has a priority field, priorities 1 to n (n = number of records).
3) only a couple users can update the priority and only when modifing the record.
4) the modify form has a hidden input field of savedPriority so I can compare to
the current priorty to see if there has been a change.
This all works fine but I can get multiple Priority 1's (that's bad).

The only thing left is a "repriortize" method & this is where I really need some help.
The method I wrote below, works to a point meaning my db contains the right number of
records and fields. They're just all empty after this method is called, like
||||||
||||||
||||||

Please look over what I have and let me know where I lost it. I call this method in sub modify_record right after &html_modify_success.
Called as &reprioritize($in{'Index'}, $in{'savedPriority'}, $in{'Priority'});

sub reprioritize {
# --------------------------------------------------------
# Reprioritize db when priority is changed
my ($this_key, $old_priority, $new_priority) = @_;
my (@lines);

if ($old_priority == $new_priority) { return; } # Don't need to do anything

my $direction = ($new_priority < $old_priority) ? "up" : "down";

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

open (DB, ">$db_file_name") or &cgierr("error in reprioritize write. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock (DB, 2); }
foreach (@lines) {
next if /^#/;
next if /^\s*$/;
chomp;

@values = &split_decode($line);

if ($values[$db_key_pos] = $this_key) { next; } # Don't modify this record

if ($direction eq "up") {
if (($values[5] < $oldPriority) && ($value[5] >= $new_priority)) {
$values[5] = $values[5] + 1;
}
}
elsif ($direction eq "down") {
if (($values[5] > $oldPriority) && ($value[5] <= $new_priority)) {
$values[5] = $values[5] - 1;
}
}

%tmp = &array_to_hash(0,@values);
$output = &join_encode(%tmp);
print DB $output;
}
close DB;
}

# Note: field 5 is the Priority field
Quote Reply
Re: [barnefr] Automatic priority field update In reply to
I'm not sure i know of anyone who has done something like you are trying to do.

Not sure if this would help but have you checked out this mod to see what it does?

Modify Multiple Fields
http://www.jpdeni.com/dbman/Mods/multmod.txt

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/