Gossamer Forum
Home : Products : DBMan : Customization :

Modify Multiple Records

Quote Reply
Modify Multiple Records
This was started in the Install & Config forum----

I reviewed the prior post for the Spreadsheet Style mod by JP Deni. This is indeed a very extensive mod. My requirement, I think, is not so complex, because only 1 field needs to be modifed in all of the records.

The field is for a comment to be made about each record in a group of records.

I have placed several predefined search links on the home page, which are OK. But the process of selecting , modifying, saving, and then REselecting for each record is quite tedious.

If multiple records could be checked to be modified (ideally up to all records in the search group), modified and then saved, this would be a good solution.

Thanks Again
Fred
Quote Reply
Re: Modify Multiple Records In reply to
Would the modification to the records be the same every time -- same text in the same field?


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





Quote Reply
Re: Modify Multiple Records In reply to
Unfortunately not JPDeni.

The same "Comment" field is always the only field modified, but the text has to be unique for each record.

Fred
Quote Reply
Re: Modify Multiple Records In reply to
Then you'll probably need to use the whole mod that I have in the other thread. (For reference, it's at http://www.gossamer-threads.com/...m12/HTML/000642.html .

You can probably get by without using all the code, though, if you are only modifying one field.

Before I go through this all again, I want to be sure of what you want. This is what I think you want:

You (as admin) click on a link that does a search and displays a form.

The form prints out the full text of each record, plus a text field for the field Comment.

You fill in the Comment fields and click the button and the records are modified.

Is this correct?

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





Quote Reply
Re: Modify Multiple Records In reply to
No, not quite JPD.

This db can be seen at
http://www.technologyconsultants.com/cgi-bin/DBM/db.cgi?

If you select predefined search Period 1, you get 18 records returned.

I would like the user to be able to select all or any of those returned records for modification.

The modify form will allow only the entry of a comment.

Each user can only view their own records, so the predefined search applies to that particular userid. Not admin.

If you log on you won't get the predefined search links. There are lots of records in here.

Thanks
Fred

[This message has been edited by Fred (edited September 30, 1999).]

[This message has been edited by Fred (edited September 30, 1999).]
Quote Reply
Re: Modify Multiple Records In reply to
Okay. I'll see if I can get to it tomorrow. I'm really tired today and I think the 'puter is going off real soon. Smile


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





Quote Reply
Re: Modify Multiple Records In reply to
I think this should work.

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_comments_form'}) { if ($per_mod) { &html_modify_comments_form; } else { &html_unauth; } }
elsif ($in{'modify_comments'}) { if ($per_mod) { &modify_mulitiple_comments; } else { &html_unauth; } }

Add the following subroutine to db.cgi:

Code:
sub modify_mulitiple_comments {
# --------------------------------------------------------
my ($key,%modify_list,$rec_to_modify,@lines,$line,@data,$output);

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};
}
}
$output .= &join_encode (%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_comments_result;
}

In your links for the predefined searches, add

Code:
&modify_comments_form=1

Add the following to html.pl:

Code:
sub html_modify_comments_form {
# --------------------------------------------------------

my ($status, @hits) = &query("mod");
my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits);
my (%tmp);

$page_title = "Modify Comments";
&html_page_top;

$submit_button = "Modify Comments";
$reset_button = "Reset Form";

if ($status ne "ok") { # There was an error searching!
print qq|<P><$font_error>Error: $status</FONT></P>|;
&html_footer;
&html_page_bottom;
}

else {
# < -- Start page text -- >
print qq|
<p><$font>
Modify the comment on each record you wish to change and click the checkbox by
that record. Then click the "Modify Comments" button:<br>
Your search returned <b>$db_total_hits</b> matches.</font>
|;
# < -- End page text -->

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

# Go through each hit and convert the array to hash and send to
# html_record for printing. Also add a checkbox with name=key and value=delete.

print "<P>";
for (0 .. $numhits - 1) {
%tmp = &array_to_hash($_, @hits);
print qq|<TABLE BORDER=0><TR><TD>
<INPUT TYPE=CHECKBOX NAME="$tmp{$db_key}" VALUE="modify"></TD><TD>|;
&html_record (%tmp);
print qq|</TD></TR><TR><TD> </TD><TD>
<input type=text name="$tmp{$db_key}-Comment" value="$tmp{'Comment'}" size="20"
maxlength="$db_lengths{'Comment'}"></td></tr>|;
foreach $column (@db_cols) {
unless ($column eq 'Comment') {
print qq|<input type="hidden" name="$tmp{$db_key}-$column" value="$tmp{$column}">|;
}
}
print qq|</TABLE>\n|;
}
print qq|
<p><center>
<INPUT TYPE="SUBMIT" name="modify_comments" VALUE="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form>
|;

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

&html_footer;
&html_page_bottom;
}
}

sub html_modify_comments_result {
# --------------------------------------------------------
# This page let's the user know that the records were successfully
# deleted.

$page_title = "Comments Modified";
&html_page_top;

# < -- Start page text -- >
print qq|
<$font>Your comments have been modified.</font></p>
|;
# < -- End page text -->

&html_footer;
&html_page_bottom;
}

(You did say you're using the "user-friendly" html.pl file, didn't you?)



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





Quote Reply
Re: Modify Multiple Records In reply to
JP Deni RULES!!

Thanks for the great code!

This is just what I was asking for in cut and paste. The only change I had to make was HTML, for a text box.

Thanks Again


Quote Reply
Re: Modify Multiple Records In reply to
Hi JP Deni,

I've been working with this great mod, and I need a little more of your help.

Line 9 of the new db.cgi sub routine "sub modify_multiple_comments" calls for "&html_modify_form_mult" in the event of an error. I created this in html.pl using the following

Code:
###################################################
#NEW Subroutine
sub html_modify_form_mult {
###################################################
# --------------------------------------------------------
# There was an error modifying the record. $message contains
# the reason why.

my ($message) = $_[0];

$page_title = "Unable to Modify Record";
&html_error_page_top;

# < -- Start page text -- >
print qq|
<$font>There were problems modifying the record:<BR>
<$error_color><B>$message</B></FONT>
<BR>Please Hit the "Back" button on your browser.
</font></p>
|;
# < -- End page text -->

&html_footer;
&html_page_bottom;
}

This would work ok, except that the new db.cgi subroutine also calls "&html_modify_comments_result" (confirm modification page)on line 42, which results in a page which combines both "&html_modify_form_mult" and "&html_modify_comments_result".

How can I stop the confirmation page "&html_modify_comments_result" from printing in the "error" situation that calls ("&html_modify_form_mult")

Fred

PS- I just found out that the error situation (if no record is checked to modify) will delete all records and leave the database as an empty file. Records should not be deleted by this routine


[This message has been edited by Fred (edited October 15, 1999).]
Quote Reply
Re: Modify Multiple Records In reply to
After

Code:
&html_modify_form_mult("You must mark at least one record to be modified.");

add

Code:
return;

That should fix both of your problems.


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





Quote Reply
Re: Modify Multiple Records In reply to
Thanks. Yes, that took care of it.

Now -

I've changed the above code in
sub html_modify_comments_form to create a text area, as follows
Code:
# Go through each hit and convert the array to hash and send to
# html_record for printing. Also add a checkbox with name=key and value=delete.
print "<P>";
for (0 .. $numhits - 1) {
%tmp = &array_to_hash($_, @hits);
print qq|<TABLE BORDER=0><TR><TD>
<INPUT TYPE=CHECKBOX NAME="$tmp{$db_key}" VALUE="modify" checked></TD><TD>|;
&html_record (%tmp);
print qq|</TD></TR><TR><TD> </TD><TD>
<TEXTAREA name="$tmp{$db_key}-Comment" ROWS="5" COLS="55" WRAP="VIRTUAL" maxlength="$db_lengths{'Comment'}">$tmp{'Comment'}</TEXTAREA></td></tr>|;
foreach $column (@db_cols) {
unless ($column eq 'Comment') {
print qq|<input type="hidden" name="$tmp{$db_key}-$column" value="$tmp{$column}">|;
}
}
print qq|</TABLE>\n|;

The comments field has a .cfg limitation of 255 characters, and I'd like to test and make sure it's not exceeded.

This little bit of script works for one text area name
Code:
<script>
<!--
function checkchars(cur){
//change max length to determine below
var maxlength=255
if (cur.chars.value.length>maxlength){
alert("This text exceeds the 255 character limit!")
return false
}
}
//-->
</script>

<form onsubmit="return checkchars(this)">
<strong>Comment must not exceed 255 characrtors in length:</strong><br><textarea rows="5" cols="55" name="comment"></textarea>
<br><input type="submit" value="SUBMIT">
</form>

but here there are, of course, multiple text area names.

I've tried a few different ways to get this working, but I can't.

The goal is to give some type of notice if the 255 character limitation is exceeded by the author of the comment (the user). Any ideas?
Wink


[This message has been edited by Fred (edited October 17, 1999).]
Quote Reply
Re: Modify Multiple Records In reply to
What you have there, if I understand correctly, is a Javascript application. I don't do Javascript.

What you can do is check them within the script. What are the names of the textareas?

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





Quote Reply
Re: Modify Multiple Records In reply to
Hi Carol!

The multiple text area's are named from the "modify multiple records mod" you designed. The names come from
Code:
<TEXTAREA name="$tmp{$db_key}-Comment" ROWS="5" COLS="55" WRAP="VIRTUAL" maxlength="$db_lengths{'Comment'}">$tmp{'Comment'}</TEXTAREA>

I was wondering if anyone has another suggestion on how to notify the user if they should exceed the number of permissable characters as set in .cfg, (in this case, 255).

I'm using a 5 X 55 text area, and I want to preserve the format of the text> I've added
Code:
#following 3 lines to preserve text format
foreach $column (@db_cols) {
$rec{$column} =~ s/\n/<BR>/g;
}
#end text format
to sub_html_record in an attempt to accomplish that.

Fred
Quote Reply
Re: Modify Multiple Records In reply to
I misunderstood. I thought you had changed it so there were multiple Comment fields within each record.

It probably would be best to do this with Javascript, but I just don't know how to do it. I've been playing with it for some time now and I haven't gotten anywhere. There are a couple of folks who hang around here who are really good with Javascript. It might be best to start a new thread with Javascript in the title so one of them can see it and might be able to help you.



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





Quote Reply
Re: Modify Multiple Records In reply to
You mention multiple comment fields in each of the records with the Modify Multiple record Mod. If this is do-able I would like to know how.

I've seen the mod you wrote at www.gossamer-threads.com/scripts/forum/resources/Forum5/HTML/001373.html which builds a select list from a different db.

I've tried the mod but haven't made it work in conjunction with the Modify Multiple record Mod.

I would like to integrate some select list fields into my app.
I'd create a second db and have each user enter several "comments". The user would be the record owner of their comments in db#2, and insert those comments into the records they own in db#1.

If these can be inserted into the first db by selecting a "comment number" field instead of the text comment itself (too big for a select list), that would be great! Select #12 from the list and get a text comment inserted.

I think the second db definition would look like
Code:
'ID' => [0, 'numer', 5, 5, 1, '', ''],
'Tea_Name' => [1, 'alpha', 20, 20,1, '', ''],
'Tea_Num' => [2, 'numer', 5, 5, 1, '', ''],
'CCNum' => [3, 'alpha', 10, 20,1, 'Period', ''],
'CComment' => [4, 'alpha', 50, 255,1, 'Comment', '']

and field 2 would be the record owner. Record owner is the same in both db's.
Fred


[This message has been edited by Fred (edited October 18, 1999).]
Quote Reply
Re: Modify Multiple Records In reply to
How many fields do you need to modify per record? What are their names?

No, you wouldn't be able to make the build select list from other db work with your multiple modify mod, since you are using textareas. What do you want to do?

Quote:
I'd create a second db and have each user enter several "comments". The user would be the record owner of their comments in db#2, and insert those comments into the records they own in db#1.

So you want to only have the comments the user "owns" to appear in the select field? That would take some doing.

Quote:
If these can be inserted into the first db by selecting a "comment number" field instead of the text comment itself (too big for a select list), that would be great! Select #12 from the list and get a text comment inserted.

How would the user know that #12 is the comment she wanted to insert?

This is really getting complicated!



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





Quote Reply
Re: Modify Multiple Records In reply to
I think that it's my explanation which is too complicated Smile
Fred

[This message has been edited by Fred (edited October 19, 1999).]
Quote Reply
Re: Modify Multiple Records In reply to
The complication is not in understanding what you want. The complication is in implementing what you want.

Just to outline the steps it would take (I'm thinking "out loud") --

To create the select list:
open the other database
get all the records
pull out the records that belong to the user
create a select list consisting of one of the fields
(Could this number be the key value of the second database or would everyone be able to have a "Comment #1"?)

(You now want to have multiple comment fields to be able to modify. Would the select list be the same for all of them?)

After the submit button is pushed -- for each record and for each comment field:
open the other database
look for the corresponding record
save the comment

Does this look about right?

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





Quote Reply
Re: Modify Multiple Records In reply to
Hi JPD,

Quote:
pull out the records that belong to the user
create a select list consisting of one of the fields
(Could this number be the key value of the second database or would everyone be able to have a "Comment #1"?)

The records that belong to the current user is correct, not db key record # "???".
Each user could have an entry named as "Comment#1" in the "SelectField1" field of the "Comments" DB.

Quote:
You now want to have multiple comment fields to be able to modify. Would the select list be the same for all of them?

The Select list could be the same for all of the Select Fields. Does that mean the fields of "Comments" DB would be something like

RecrodNumber, UserID, Comment_Name,SelectField_Text ?

or

RecrodNumber, UserID, Comment1_Name,SelectField1_Text, Comment2_Name,SelectField12_Text, Comment3_Name,SelectField13_Text .

Either is OK, but the first is desireable.

Quote:
After the submit button is pushed -- for each record and for each comment field

I'm still interested in keeping the Modify Multiple Records mod in place, rather than pushing submit for individual records.

Fred

[This message has been edited by Fred (edited October 19, 1999).]
Quote Reply
Re: Modify Multiple Records In reply to
 
Quote:
Each user could have an entry named as "Comment#1" in the "SelectField1" field of the "Comments" DB.
...
RecordNumber, UserID, Comment_Name,SelectField_Text

My suggestion would be

RecordNumber, UserID, Comment_Name, Comment_Text

and use the Comment_Name as the text of the select field.

Let me give you an example of what I think this would be:

I add some records to the comment db:

Comment_Name:Wow
Comment_Text:Wow! This is a mega-cool thing that everyone should have in their back yards.

Comment_Name: So-So
Comment_Text: It's okay, but I wouldn't pay more than a buck and a half for it.

Comment_Name: Icky
Comment_Text: This is really the pits. I don't know what idiot thought this up, but he should be staked out on an anthill with honey poured over his head.

Then I want to put my comments into the other database. I do my search and I get a select list that says:

Icky
So-So
Wow

(alphabetized)

I select "So-So" from the list, and the corresponding text is added to the main database.

Is this right?

Quote:
I'm still interested in keeping the Modify Multiple Records mod in place, rather than pushing submit for individual records.

I was unclear. The "for each record and for each comment field" refers to what needs to happen in the script. For each record that is submitted, and for each field, the script will need to open the comments.db file, search for the selected value and the userid so that it will know which of the comments to insert. (This still may not be clear. Suffice it to say that my intention is to maintain the multiple modify.)

I have a question. Every time the record is modified, the comment field(s) will be overwritten. The new comment will not be appended to the old comments. Is this what you want?

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





Quote Reply
Re: Modify Multiple Records In reply to
Yes JPD, that's reads just like it.

If a record is modified and "Wow" is chosen, that would be lost on a subsequent modification,(unless it were selected again at the time).

In the main "Report" DB:
Select_Field1, Select_Field2, and Select_Field3 are all built from all of the Comment_Name records where Report($db_userid) = Comment(UsereID).

Fred

[This message has been edited by Fred (edited October 22, 1999).]