Gossamer Forum
Home : Products : DBMan : Customization :

Modify Multiple Entries

(Page 1 of 2)
> >
Quote Reply
Modify Multiple Entries
I have searche the DBMan message boards and have not seen anything on this subject.. Is there any way to MOD to Modify "Multiple" entries at one time like in Links 2.0?

Thanks
Tracy
Quote Reply
Re: Modify Multiple Entries In reply to
How many fields are we talking about here? You need to be sure that, as with Links, there aren't too many fields.


------------------
JPD





Quote Reply
Re: Modify Multiple Entries In reply to
Thanks for the quick reply....!! Right now if you want to modify a record (By choosing Modify) you can only Modify one record at a time. In links 2.0 you can modify "Modify Multiple at Once:". Meaning if you wanted to modify all of the "Modem" records in the data base you can see and edit ALL of them at one time instead of having to do them one at a time...

I hope this is a little clearer..

Thanks

Tracy
Quote Reply
Re: Modify Multiple Entries In reply to
I believe you mean the "Validation" option in LINKS 2.0 allows you to "modify" multiple records?? The Modify option in LINKS 2.0 functions the same as the Modify option in DBMAN, which only allows you to modify one record at a time.

I think it could be done with some tweaking in the html_modify_form sub-routine in html.pl and the modify_record sub-routine in default.cgi. My initial reaction is that you could modify the modify_record sub-routine to reflect what delete_record (in default.cgi) does in terms of the checkboxes. But I am unsure of the exact codes that would allow this to occur.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Modify Multiple Entries In reply to
Tracy, how many fields are in your database? If you have 50 fields, you're not going to want to have a spreadsheet sort of form like is in Links. I'm trying to figure out the best way to set up your multiple modify form.



------------------
JPD





Quote Reply
Re: Modify Multiple Entries In reply to
Elliot,

If you goto your Link Manager interface and choose "Modify" A search comes up.... to search for the record you want to modify... Towards the bottom there is a box you can check ... It says "Modify Multiple at Once:"

This lets you Modify Multiple Records at one time..... instead of one at a time. This saves a lot of time if you are making the same change to many links within a specific category...

Thanks

Tracy
Quote Reply
Re: Modify Multiple Entries In reply to
JPDeni

I am trying to implement this for several databases... The most fields are about 20 max..

Thanks

Tracy
Quote Reply
Re: Modify Multiple Entries In reply to
Well, if you're going to use it for a number of databases, I guess the best thing would be to just do a spreadsheet. I'm assuming that only admin users would be doing the multiple modify anyway, so it doesn't matter how they look.

I'll have to go offline to work on this for a bit, as soon as I get caught up with the questions that are on the board right now.


------------------
JPD





Quote Reply
Re: Modify Multiple Entries In reply to
Sorry, Tracy. I missed that. I never need to modify batch records, so I don't use that option. But I am sure that Carol will be able to come up with a cool solution...she always does!

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Modify Multiple Entries In reply to
This thread is going to get very long very quickly. The multiple modify requires quite a bit of code to be added. I've set it up so that only admins will see the multiple modify and only if more than one record is returned from the modify search.

Please test this as soon as you can. I have checked it for syntax errors, but not for the actual functioning of the script.

There will be several posts here, since UBB seems to have a problem with editing long posts and I might make a mistake. Be sure that you have all the parts to the mod before you try this. In case you come along while I'm still writing, don't copy the code until you see the last post that says All done!. Then take all of the code between this post and the "All done" post.


Add the following subroutine to db.cgi

Code:
sub modify_record_mult {
# --------------------------------------------------------
# Modifies one or more records at a time.
#
my ($rec_to_modify, %modify_list);
my ($line, @lines, @data, $output, $succstr, $errstr);

$rec_to_modify = 0;
foreach $key (keys %in) { # Build a hash of keys to modify.
if ($in{$key} eq "modify") {
$modify_list{$key} = 1;
$rec_to_modify = 1;
}
}
if (!$rec_to_modify) {
&html_modify_form_mult("You must mark at least one record to be modified.");
}
else {
open (DB, "<$db_file_name") or &cgierr("error in delete_records. unable to open db file:
$db_file_name. Reason: $!");
@lines = <DB>;
close DB;

LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
(@data) = &split_decode($line);
if ($modify_list{$data[$db_key_pos]}) {
foreach $key (keys %in) {
if ($key =~ /^\Q$data[$db_key_pos]\E-(.*)$/) {
$rec{$1} = $in{$key};
}
}
$status = &validate_multiple_records (%rec);

if ($status eq "ok") {
$output .= &join_encode (%rec);
$succstr .= "$rec{$db_cols[0]} ";
}
else {
$output .= $line . "\n";
$errstr .= "Record: $rec{$db_cols[0]} - $status<br>";
}
undef %rec;
}
else {
$output .= $line . "\n";
}
}
open (DB, ">$db_file_name") or &cgierr("error in modify_mult_records. unable to open db file:
$db_file_name. Reason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
}
print DB $output;
close DB;

&html_modify_form_mult($errstr, $succstr);
}
}
Quote Reply
Re: Modify Multiple Entries In reply to
Add the following subroutine to db.cgi

Code:
sub build_record_form_spreadsheet {
# --------------------------------------------------------
# Builds a record form based on the config information.
#
my (%rec) = @_;
my ($output, $field);

foreach $field (@db_cols) {
if ($db_select_fields{$field}) {
$output .= "<td><nobr>" . &build_select_field_2($field, $rec{$field}, $rec{$db_key}) . "</nobr></td>";
}
elsif ($db_radio_fields{$field}) {
$output .= "<td><nobr>" . &build_radio_field_2($field, $rec{$field}, $rec{$db_key}) . "</nobr></td>";
}
elsif ($db_checkbox_fields{$field}) {
$output .= "<td><nobr>" . &build_checkbox_field_2 ($field, $rec{$field}, $rec{$db_key}, $rec{$db_key})
. "</nobr></td>";
}
elsif ($db_form_len{$field} =~ /(\d+)x(\d+)/) {
$output .= qq~<td><nobr><textarea name="$rec{$db_key}-$field" cols="20" rows="3">$rec{$field}</textarea>
</nobr></td>~;
}
else {
$output .= qq~<td><nobr><input type=text name="$rec{$db_key}-$field" value="$rec{$field}" size="20"
maxlength="$db_lengths{$field}"></nobr></td>~;
}
}
return $output;
}

[This message has been edited by JPDeni (edited August 04, 1999).]
Quote Reply
Re: Modify Multiple Entries In reply to
Add the following subroutines to db.cgi.

Code:
sub build_select_field_2 {
# --------------------------------------------------------
# Builds a SELECT field based on information found
# in the database definition for use in the multiple modify
# spreadsheet form. Parameters are the column to build,
# default value (optional) and the key value for the record.

my ($column, $value, $key) = @_;
my (@fields, $ouptut);

@fields = split (/\,/, $db_select_fields{$column});
if ($#fields == -1) {
$output = "error building select field: no select fields specified in config for field '$column'!";
}
else {
$output = qq|<SELECT NAME="$key-$column"><OPTION>---|;
foreach $field (@fields) {
$field eq $value ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";
}
return $output;
}
sub build_checkbox_field_2 {
# --------------------------------------------------------
# Builds a CHECKBOX field based on information found
# in the database definitionfor use in the multiple modify
# spreadsheet form. Parameters are the column to build,
# default value (optional) and the key value for the record.

my ($column, $values, $key) = @_;

if (!$db_checkbox_fields{$column}) {
return "error building checkboxes: no checkboxes specified in config for field '$column'";
}

my @names = split (/,/, $db_checkbox_fields{$column});
my @values = split (/\Q$db_delim\E/, $values);
my ($name, $output);

foreach $name (@names) {
(grep $_ eq $name, @values) ?
($output .= qq!<INPUT TYPE="CHECKBOX" NAME="$key-$column" VALUE="$name" CHECKED> $name\n!) :
($output .= qq!<INPUT TYPE="CHECKBOX" NAME="$key-$column" VALUE="$name"> $name\n!);
}
return $output;
}

sub build_radio_field_2 {
# --------------------------------------------------------
# Builds a RADIO Button field based on information found
# in the database definitionfor use in the multiple modify
# spreadsheet form. Parameters are the column to build,
# default value (optional) and the key value for the record.

my ($column, $value, $key) = @_;
my (@buttons, $button, $output);

@buttons = split (/,/, $db_radio_fields{$column});

if ($#buttons == -1) {
$output = "error building radio buttons: no radio fields specified in config for field '$column'!";
}
else {
foreach $button (@buttons) {
$value =~ /^\Q$button\E$/ ?
($output .= qq|<INPUT TYPE="RADIO" NAME="$key-$column" VALUE="$button" CHECKED> $button \n|) :
($output .= qq|<INPUT TYPE="RADIO" NAME="$key-$column" VALUE="$button"> $button \n|);
}
}
return $output;
}
Quote Reply
Re: Modify Multiple Entries In reply to
Add the following subroutine to db.cgi

Code:
sub validate_multiple_records {
# --------------------------------------------------------

my ($col, @input_err, $errstr, $err, $line, @lines, $id, @rest);
my (%record) = @_;

foreach $col (@db_cols) {
if ($record{$col} =~ /^\s*$/) { # entry is null or only whitespace
if ($db_not_null{$col}) { # entry is not allowed to be null.
push(@input_err, "$col (Missing)"); # so let's add it as an error
}
}
else { # else entry is not null.
if (defined($db_valid_types{$col}) && !($record{$col} =~ /$db_valid_types{$col}/)) {
push(@input_err, "$col (Invalid)"); # but has failed validation so add
} # it as an error.
if ($db_sort{$col} eq "date") {
push (@input_err, "$col (Invalid date format)") unless &date_to_unix($record{$col});
}
(length($record{$col}) > $db_lengths{$col}) and
push (@input_err, "$col (Too long. Max length: $db_lengths{$col})");
}
}
if ($#input_err+1 > 0) { # since there are errors, let's build
foreach $err (@input_err) { # a string listing the errors
$errstr .= "$err,"; # and return it.
}
chop $errstr;
return $errstr;
}
else {
return "ok"; # no errors, return ok.
}
}
Quote Reply
Re: Modify Multiple Entries In reply to
In db.cgi, sub main, after

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

add

Code:
elsif ($in{'modify_record_mult'}) { if ($per_admin) { &modify_record_mult; } else { &html_unauth; } }

In html.pl, sub html_modify_form, after

Code:
if (($numhits == 1) and !$in{'nh'}) { $in{'modify'} = $hits[$db_key_pos]; &html_modify_form_record(); return; }

add

Code:
if ($per_admin) { &html_modify_form_mult; return; }
Quote Reply
Re: Modify Multiple Entries In reply to
Add the following subroutine to html.pl

Code:
sub html_modify_form_mult {
# --------------------------------------------------------
# Allows modification of more then one record at a time.
#
my ($errstr, $succstr) = @_;

my ($status, @hits) = &query('mod');


my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits) = $db_max_hits;
$maxhits = $in{'mh'} if ($in{'mh'});

if ($numhits == 1) {
$in{'modify'} = $hits[0];
&html_modify_form_record();
return;
}

&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Modify Multiple Records.</title>
</head>

<body bgcolor="#DDDDDD">
<blockquote>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 valign=top>
<tr><td bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Modify Multiple Records</b>
</td></tr>
</table>
|;

if ($errstr) {
print qq|<font color=red><strong>$errstr</strong></font>|;
}
if ($succstr) {
print qq|The following records were successfully modified: <font color=red><strong>$succstr</strong></font>.|;
}
if ($status ne "ok") { # Error searching database!
print qq|<TR><TD><FONT COLOR="RED" SIZE=4>Error: $status</FONT></TD></TR>|;
}
else {
print qq| <P>
<p>Check which records you wish to modify and then press "Modify Records."
Your search returned <b>$db_total_hits</b> matches.</font>
|;
if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}
print qq|
<form action="$db_script_url" METHOD="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<TABLE BORDER=1>|;

# Print Column Headers
print "<tr><th>$db_key</th>";
foreach $col (@db_cols) {
print qq|<th>$col</th>|;
}
print "</tr>";

# Print Main Body.
for ($i = 0; $i < $numhits; $i++) {
%tmp = &array_to_hash ($i, @hits);
print qq|<TR><TD VALIGN=TOP><nobr>
<INPUT TYPE=CHECKBOX NAME="$tmp{$db_key}" VALUE="modify">$tmp{$db_key} </nobr></TD>
|;
print &build_record_form_spreadsheet (%tmp);
print "</TR>";
}
print "</table>";

print qq|
<P><INPUT TYPE="HIDDEN" NAME="modify_record_mult" VALUE="1">
<INPUT TYPE="SUBMIT" VALUE="Modify Record"> <INPUT TYPE="RESET" VALUE="Reset Form">
</FORM>
|;

if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}
}

&html_footer;
print qq|
</blockquote>
</body>
</html>
|;
}


------------------
JPD







[This message has been edited by JPDeni (edited August 06, 1999).]
Quote Reply
Re: Modify Multiple Entries In reply to
All done!

------------------
JPD





Quote Reply
Re: Modify Multiple Entries In reply to
Wow... Thats quick service! Do you have those modified scripts.... I did not have a lot of time to sort through them... If the changes are generic and not specific to my database I would be grateful if you could email them to me... I am very willing to pay you for your time...

Thanks

Tracy
Quote Reply
Re: Modify Multiple Entries In reply to
JPDeni
Also I forgot to tell you I am using the generated pages from DBMAn... Do I still need to modify the html.pl ??

Thanks to all

Tracy
Quote Reply
Re: Modify Multiple Entries In reply to
I do have a file for the modifications, but you can just copy right out of the forum if you want. I will send you the text file I wrote.

It is a generic modification that will work for any database. I wouldn't suggest using it on anything with more than about 20 fields, though.

Also, understand this is completely untested. I copied code from Links and DBMan and made some changes, but I haven't tested it except to be sure there weren't syntax errors. I would really like it if you would give it a try, using some sample data, to make sure it works like you want it to.

As for paying me, please contribute the amount you would like to give me to a children's charity in your area. You can either say it's from "JPDeni" or make it an anonymous gift.


------------------
JPD





Quote Reply
Re: Modify Multiple Entries In reply to
Yes. You still need to modify html.pl. Autogenerate won't have anything to do with this modification.


------------------
JPD





Quote Reply
Re: Modify Multiple Entries In reply to
In sub modify_record_mult, try changing

$status = &validate_multiple_records (%rec);

to

$status = "ok";

See what happens.

------------------
JPD





Quote Reply
Re: Modify Multiple Entries In reply to
I guess I'm going to need you to re-explain what you need to do as far as the relational database -- either that or post again in your original topic so I can find it and read what you wrote before. I can't keep much in my head for very long. Smile

Oh, there was a little thing I forgot to put in there. I'll edit the code, putting the new code in bold, and also tell you where it is.

In sub html_modify_form_mult, change

&build_record_form_spreadsheet (%tmp);

to

print &build_record_form_spreadsheet (%tmp);

Makes a little difference. Smile

I suppose you could remove the reference to sub validate_multiple_records and create your own "spreadsheet" form instead of having the script do it. You would still have to include all the fields in your form, though. The ones that you wouldn't be modifying could be hidden fields. I'll have to work with you on that to get the names correct for the fields.


------------------
JPD





Quote Reply
Re: Modify Multiple Entries In reply to
You are really nice! Thank you!

Yes, "print &build_record_form_spreadsheet (%tmp);" works! I can now see the field values in the html form generated by sub html_modify_form_mult BUT I kept on receiving the following error message when I clicked "modify record":

Record: p - Date (Invalid),Time (Invalid),Userid (Invalid),ID (Invalid),University (Invalid),ReferringClass (Invalid)
Record: qqq - Date (Invalid),Time (Invalid),Userid (Invalid),ID (Invalid),University (Invalid),ReferringClass (Invalid)

Error: no search terms specified

Any hints??

Quote Reply
Re: Modify Multiple Entries In reply to
Hi JPD
I am the guy who asked you about using DBMan for subjects to sign up experiments. Thank you for your previous reply. I am still thinking whether I should pursue relational database.

I got some hints to solve partially our problem from the discussion here.

I have about 10 experiment fields. I now have to manually "reuse" the experiment field every time by replacing the old experiment data fields (ie use to hold the data whether the subjects has ticked the checkbox for the experiments or not) with new ones. I I have to manually edit the default.db file.

I know a better solution is to use relational database design. But I have customized DBman to a point which is quite suitable to all our needs now except the "reuse" task.

I found that the your discussion here can help use do the "reuse" task. I just added the above codes into my program.

I encountered two problems:

1. After admin placed a wildcard * on any field on the modify search form. The sub build_record_form_spreadsheet does <b>not</b> generate any HTML output for the field data except the field names and the the record ID. Presently I have around 20 fields.

2. For our purpose(may be it's also of some general interests), we just want to the sub html_modify_form_mult to display the experiment data fields (check boxes) and 2 to 3 alphabetical fields. Then admin would just uncheck all the signup boxes for past experiments. How can we do that? I'm afraid that the sub validate_multiple records is to ensure all the fields are in the html output generated by the sub html_modify_form_mult.

I would really appreciate your help. Thank you very much.

P.S. If you have time and interested to look at it. Pls feel free to log on my database. I will e-mail to hall@drizzle.com the password for admin, the url for default.cfg, html.pl and db.cgi in a few minutes.
Quote Reply
Re: Modify Multiple Entries In reply to
Really thx a lot! Multiple records can be modified now. But there is an error message just after the successful message:
_______
The following records were successfully modified: peter mary .Error: no search terms specified
________

where peter and mary is the data for the FirstName field for the two records modified. But the same "peter mary" error message will show up no matter it's the LastName field or the phone field is changed.

Strange....


> >