Gossamer Forum
Home : Products : DBMan SQL : Discussion :

"Owner" select field can only be changed to self

Quote Reply
"Owner" select field can only be changed to self
Hi I have a select field titled "Owner". When a user adds a record to the database the owner select field is automatically set to the userid of the record creator ( I have all of the userid's of users in the select field). Now if the user wants to change the owner field to someone else I want a error message to come up..something like..."you cannot transfer ownership to another user. A user can only transfer ownership to their self."

And if the the person modifying the record is setting the owner field to their self then everything should go through fine. Any ideas how I could do this?

Any ideas will be appreciated Cool
Reena
Quote Reply
Re: [Reena0330] "Owner" select field can only be changed to self In reply to
Hi,

Just simply find the sub modify_record in admin/Dbsql/Home.pm

and under the line (around line 608):

($userid eq $self->{user}->{'Username'}) or return $self->modify_form($self->_language('ERR_MODIFY_OWN')) ;

add the line:

($self->{cgi}->{$self->{cfg}->{'auth_user_field'}} eq $self->{user}->{Username}) or return $self->modify_form("you cannot transfer ownership to another user");

Cheers,

Jean
Gossamer Threads ,Inc.
Quote Reply
Re: [jean] "Owner" select field can only be changed to self In reply to
Hi Jean,

I added the code that you told me to:

Code:


my $userid = $result->{$self->{cfg}->{'auth_user_field'}};
($userid eq $self->{user}->{'Username'}) or return $self->modify_form($self->_language('ERR_MODIFY_OWN')) ;

($self->{cgi}->{$self->{cfg}->{'auth_user_field'}} eq $self->{user}->{Username}) or return
$self->modify_form("You cannot transfer ownership to another user");


}
if ($self->{db}->modify ($self->{cgi})) {
$self->auth_logging('modify record ') if ($self->{cfg}->{log_file});
return $self->modify_success;
}




but it didn't make any difference. I've set the auth_user_field to the field I titled 'owner'. Is there anything else that I need to do?
Reena

Last edited by:

Reena0330: Aug 12, 2002, 1:55 PM
Quote Reply
Re: [jean] "Owner" select field can only be changed to self In reply to
Hi Jean,

Here are the conditions for the "owner" field and when it can or cannot be modified:

- if "owner" field modified to "Username" then OKAY

- if "owner" field modified to anything other than "Username" then ERROR MESSAGE

- if "owner" field not modified and is set to something other than "Username" then okay.



I think the last case is the most complicated because if the "owner" field is not modified and is set to soething othe than the "Username" then an error message should NOT be displayed. But how can the database tell if the "owner" field has been modified or not? I tried the code that you gave me, but it didn't do anything. I was still able to transfer ownership to another user. Any help would be great Unsure
Reena
Quote Reply
Re: [Reena0330] "Owner" select field can only be changed to self In reply to
In this case, I think that you should hide the 'Owner' field ( you can change the properties at Admin - Tables - Properties ), so it won't be shown on the modify form.

TheStone.

B.

Last edited by:

TheStone: Aug 13, 2002, 3:50 PM
Quote Reply
Re: [TheStone] "Owner" select field can only be changed to self In reply to
Okay so this is what I did:

<%if Username eq 'rsmith' or owner eq 'rsmith%>
<OPTION value=abacio <%if owner eq 'rsmith'%>selected<%endif%>>rsmith<%endif%>

I did this for each select option. This way only the id of the user logged in and the id of the record owner will show up in the select box. Works great :)

Thanks for your help!
Reena