Gossamer Forum
Home : Products : DBMan : Installation :

Guidance

Quote Reply
Guidance
I've checked the archive's pretty thoroughly (I think !!) but I haven't seen anything similar to this question.

How could I allow a user, when modifying a record, to view what was previously in a text field, but not actually modify what was previously there...only add/append to the contents of the field...?


Quote Reply
Re: Guidance In reply to
You can't easily. You'd have to dig into modify_record in db.cgi and make sure that the information is appended and not overwritten. It wouldn't be straight forward for the novice perl user..

Cheers,

Alex
Quote Reply
Re: Guidance In reply to
Hmmm,....ok. I am kinda Unix oriented, I I notice some similarities in Perl. I figured that the changes would be somewhere between validate_record and modify_record.

I can do the display of the field contents in html.pl. So all you have to do is point me in the right direction....if it's not too much trouble.
Quote Reply
Re: Guidance In reply to
What you want to do is in modify_record right after:

if ($data[$db_key_pos] eq $in{$db_key}) {

add something like:

$in{$db_cols[1]} = $data[1];

assuming 1 is the field you don't want modified. What this does, is once the record is found that is going to be updated, copy the old contents into the new one ensuring that whatever the user enters is overwritten. You could add:

$in{$db_cols[1]} = $data[1] unless $per_admin;

So an admin could still update it.

Hope that helps,

Alex

Quote Reply
Re: Guidance In reply to
Ok Alex, what I was going to do to facilitate this field append is to

1. Display the field contents using $rec{'Field'} and

2. Use a TEXTAREA field to collect the input for the append with NAME="Field".

I am going to try the code you've given me, however you said that it will "copy the old contents into the new one ensuring that whatever the user enters is overwritten."
What I want to do is append, so shouldn't I be writing back what was originally there plus what I collected in the TEXTAREA field..?

I'll let you have the results later.
Quote Reply
Re: Guidance In reply to
Alex, I too would like to impliment this feature, in which new text can only be appended to the old text. And the old text can not be overwritten. Is that possible ?

I have used your above example, but it does not append the new text to the old, it overwrites everything.



[This message has been edited by Katana Man (edited January 10, 1999).]
Quote Reply
Re: Guidance In reply to
Alex, I know you are a busy man, but if you find the time, Pete and I would love to protect the original data, yet allow them to append new data. Any ideas ?
Quote Reply
Re: Guidance In reply to
Wouldn't Alex's solution work if you just changed the line

$in{$db_cols[1]} = $data[1];

to

$in{$db_cols[1]} = $data[1] . $in{$db_cols[1]};



------------------
JPD
Quote Reply
Re: Guidance In reply to
Genius, pure genius. It worked!

I love DBMan ! I always knew it was good, but now I see why. Thanks !
Quote Reply
Re: Guidance In reply to
Spoke too soon..hehe. It works, but everytime you modify the textarea, it doubles up on the text and appends the new stuff.

So what I did was make it so that the previous text appeared as html (and doesnt show up in the new textarea) so that they could not touch the old stuff.

So everything works good except for the line breaks. The new text that gets appended, is attached directly to the old text without a line break. Is there any way to add a line break to the end of the old text or to the begining of the new text?
Quote Reply
Re: Guidance In reply to
This mod seems to be quite useful. I would like to use this for my db as well. I was wondering if it would be possible for anyone who has successfully installed this mod to post what they did in a message so everyone can put it to use without confusion as moving from message to message for the mod can easily confuse someone.

Thanks again.


------------------
Jason
Extreme mtb
http://extreme.nas.net
Quote Reply
Re: Guidance In reply to
 
Quote:
So what I did was make it so that the previous text appeared as html (and doesnt
show up in the new textarea) so that they could not touch the old stuff.

That's the way to do it. Besides, there's no use tempting the users into trying to edit something they can't.

Quote:
Is there any way to add a line break to the end of the old text or to the begining of the new text?

Sure.

$in{$db_cols[1]} = $data[1] . "\n$in{$db_cols[1]}";

Be sure you convert line breaks to "<BR>"s when you show them in html_record.




------------------
JPD
Quote Reply
Re: Guidance In reply to
What you have seems okay. I would comment out those lines (add a # to the beginning of each line) and then upload it, just to be sure the problem is with the lines you gave us. There could be something else.

If it works when those lines are commented out, I'm not sure what to tell you. The syntax seems to be fine. Of course, I never use IE, so I'm not sure what its error messages really mean.


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





Quote Reply
Re: Guidance In reply to
Silly me....I saw it as soon as I checked the post. I left out a couple of ]'s.

I got it working, however I want to give the option to update a couple of fields on the update screen. Presently, if I update only one field, the script complains about the others being blank because they are marked as compulsory in default.cfg.

I do not want to lose the compulsory field functionality. How can I work around this ?

Also in conjunction with the modify-append function, I want the field which is appended to to have an indicator. In other words I want to be able to identify updates to the field easily. So what I have done is to give the append a little header like so :

$in{$db_cols[6]} = $data[6] . "\n\n<B><FONT COLOR=navy>**Updated by $db_userid on $date**</B></FONT>\n$in{$db_cols[6]}";
(even though Alex says you shouldn't really store HTML in the database !! )

Now I wouldn't want this header appended to the field if the field wasn't being updated.

How can I achieve both these objectives ?
Quote Reply
Re: Guidance In reply to
I think we can trick db.cg and get both things working at once.

In sub modify_record, before

$status = &validate_record;

add

($in{$db_cols[6]}) | | ($in{$db_cols[6]} = "empty");

for each of your fields that you want to have the new stuff appended to. UBB inserts a space between two | characters, so be sure there isn't a space in the middle of | |.

This will stick something into the fields so that validate_record won't kick you out for having an empty field.

Then, when you go to append the data, use

Code:
if ($in{$db_cols[6] eq "empty") {
$in{$db_cols[6] = $data[6];
}
else {
$in{$db_cols[6]} = $data[6] . "\n\n<B><FONT COLOR=navy>
**Updated by $db_userid on $date**</B></FONT>\n$in{$db_cols[6]}";
}

The only possible problem would be if the user updated the message by entering the word "empty," which is doubtful.


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







[This message has been edited by JPDeni (edited April 14, 1999).]
Quote Reply
Re: Guidance In reply to
Alex, JPDeni

I would like to implement this mod for a couple fields in my database.

I have done the mods to html.pl to display the contents of the fields and added the empty TEXTAREA for input to append to the contents of the field.

When I try to add the code suggested here, dbman fails in IE with a popup message "Internet Explorer cannot open the Internet Site blah blah blah. The operation completed successfully."

Here is the snippet of code I've added with the excerpt from modify_record :

chomp ($line);
@data = &split_decode($line);
($output .= "$line\n" and next LINE) if ($restricted and ($db_userid ne $data[$auth_user_field]));

if ($data[$db_key_pos] eq $in{$db_key}) {

# Here is where I've added the code
$in{db_cols[6]} = $data[6]."\n\n$in{db_cols[6]}";
$in{db_cols[7]} = $data[7]."\n\n$in{db_cols[7}";
$in{db_cols[8]} = $data[8]."\n\n$in{db_cols[8]}";
$in{db_cols[10]} = $data[10]."\n\n$in{db_cols10]}";

# This is where what I've added ends

# If we have userid's and this is not an admin, then we force the record to keep it's own
# userid.
if ($auth_user_field >= 0 and (!$per_admin or !$in{$db_cols[$auth_user_field]})) {
$in{$db_cols[$auth_user_field]} = $data[$auth_user_field];
}

$output .= &join_encode(%in);
$found = 1;
}


DBman works perfectly otherwise; what have I done wrong ?
Quote Reply
Re: Guidance In reply to
I will try this....Of course I can substitute "empty" for any other string which would be unlikely for the user to enter ..?

JPDeni, two other things;

The **Updated By $db_userid on $date** header works for the first field but it is not being added to the others. When I remove the HTML, it works OK. I would really like to draw attention to the header by changing the color but I think the script is stripping out HTML. How can I bypass that to add the header (with HTML) to the fields that I'm updating ?

Second, this append/update form is for regular users. I still want admin users to be able to change anything in a field. The append/update form is in a sub called html_record_form_noup. I would like to call the relevant form from sub html_modify_form_record depending on the user permissions. Something like :-

<$font>|;
if ($per_admin ) {
&html_record_form (%rec);
else {
&html_record_form_noup (%rec);
}
print qq|</font>

Please correct this syntax for me.
Quote Reply
Re: Guidance In reply to
JPDeni,

I have added your code as follows :-

if ($data[$db_key_pos] eq $in{$db_key}) {

if ($in{$db_cols[6] eq "emptyT") {
$in{$db_cols[6] = $data[6];
}
else {
$in{$db_cols[6]} = $data[6] . "\n\n**Updated by $db_userid on $date**\n$in{$db_cols[6]}";
}

# If we have userid's and this is not an admin, then we force the record to keep it's own
# userid.
if ($auth_user_field >= 0 and (!$per_admin or !$in{$db_cols[$auth_user_field]})) {
$in{$db_cols[$auth_user_field]} = $data[$auth_user_field];
}

however I'm getting browser errors again. The ($in{$db_cols[6]}) | | ($in{$db_cols[6]} = "empty"); adds OK ie. I dont get any errors, but once I add the append part it fails.....


(help...?)
Quote Reply
Re: Guidance In reply to
 
Code:
if ($in{$db_cols[6]} eq "empty") {
$in{$db_cols[6]} = $data[6];
}
else {
$in{$db_cols[6]} = $data[6] . "\n\n<B><FONT COLOR=navy>
**Updated by $db_userid on $date**</B></FONT>\n$in{$db_cols[6]}";
}

I left out a couple of closing }s on the "if" statement. Sorry 'bout that.


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





Quote Reply
Re: Guidance In reply to
Thanks JPDeni,

I just figured out the syntax errors too !!! I really appreciate all your help -- everything works, except one thing which I haven't tested yet; how will the changes to modify_record affect the regular modification, which is now the admin modification !!! I may have to copy the original modify_record to a new sub, huh.. ?
Quote Reply
Re: Guidance In reply to
You can make one modify_record work for both admin and users.

Code:
else {
unless ($per_admin) {
$in{$db_cols[6]} = $data[6] . "\n\n<B><FONT COLOR=navy>
**Updated by $db_userid on $date**</B></FONT>\n$in{$db_cols[6]}";
}
}

That should be enough to do it.

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





Quote Reply
Re: Guidance In reply to
JPDeni,

I've been mulling over this for the past few days. I haven't put it in 'cause I like to understand something before I do it. Now I understand the code (I think), but I have a few questions.

1. Should I just tack on the last piece of code after what I already have and turn the whole statement into

if ($in{$db_cols[6]} eq "empty") {
$in{$db_cols[6]} = $data[6];
}
else {
$in{$db_cols[6]} = $data[6] . "\n\n<B><FONT COLOR=navy>
**Updated by $db_userid on $date**</B></FONT>\n$in{$db_cols[6]}";
}
else {
unless ($per_admin) {
$in{$db_cols[6]} = $data[6] . "\n\n<B><FONT COLOR=navy>
**Updated by $db_userid on $date**</B></FONT>\n$in{$db_cols[6]}";
}
}

or what ..?

2. I am redirecting the user to two different modify forms depending on their permissions. Regular users see the original contents displayed as html with blank TEXTAREA fields to facilitate update, admin users get the standard sub with the field contents in the TEXTAREA fields.

In light of this could you explain how this code should work ?
Quote Reply
Re: Guidance In reply to
The last piece of code is an "instead of," not an "in addition to." Here's the whole thing:

Code:
if ($in{$db_cols[6]} eq "empty") {
$in{$db_cols[6]} = $data[6];
}
else {
unless ($per_admin) {
$in{$db_cols[6]} = $data[6] . "\n\n<B><FONT COLOR=navy>
**Updated by $db_userid on $date**</B></FONT>\n$in{$db_cols[6]}";
}
}

Quote:
Regular users see the original contents displayed as html with blank TEXTAREA fields to facilitate update, admin users get the standard sub with the field contents in the TEXTAREA fields.

There shouldn't be any problem with that.

I'm not really sure what to say, because I'm not sure what you're asking.


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





Quote Reply
Re: Guidance In reply to
Thanks JPDeni,

I understand now !! and yes, it works perfectly !!

Tell me one more thing; I saw somewhere someone was doing a multiple select list in DBman. Do you recall the thread, or can you show me how its done..?
Quote Reply
Re: Guidance In reply to
Probably the best discussion of multiple select fields is at http://www.gossamer-threads.com/scripts/forum/resources/Forum5/HTML/000730.html

I'm glad you got it to work the way you want to. Ain't it great?!?!?! Smile

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