This topic is locked
[SOLVED]

  Disable edit field for some users

3/1/2012 2:27:16 PM
PHPRunner General questions
I
igiacchi author

Dear Sirs,

I searched around the forums for hours but have not found the solution to my problem.
Environment:

PHPRunner: ver. 6.0 + Mobile module

Database: MYSQL
I have a table from which users access to manage the program.

I would like that the user group "user" that don't have the 'admin' privileges, can edit their registration data such as email, password and note but only see his User Name without editing it.
It would be possible to put the username field read-only but visible when they try to edit the data.
Questo non deve accadere se è l'utente admin che cerca di modificare i suoi dati.

I found some solutions for different problems but unfortunately I'm not very capable using Java and I'm in trouble.
Thanks to all

C
copper21 3/1/2012

In the events area go to Edit Page of the users table. Select "Javascript Onload Event"
Put this code in it:
//Set username field to read-only
var ctrl = Runner.getControl(pageid, 'username');
ctrl.setDisabled();
This will disable the username field on the edit page of the user table. Where I have username is the name of your username field.
Brian

C
cgphp 3/1/2012

To make the field readonly, not disabled, use the following code:

var ctrl = Runner.getControl(pageid, 'username');

ctrl.makeReadonly();
I
igiacchi author 3/1/2012



To make the field readonly, not disabled, use the following code:

var ctrl = Runner.getControl(pageid, 'username');

ctrl.makeReadonly();



Many tnx to all, but I can't do this only for one user I need to this for all user and not for admin I have create the group field where I have admin and user inside.

So all users cannot modify the record user, but all admins can do it.

This forum it is very good guys many thanks for all again.

C
copper21 3/2/2012

Ivano,
What I would do then is make a view of the users table...one for admin and one for users and restrict access to each others table through permissions. This is assuming you have set up dynamic permissions.
So for example the original users table can be used for your admins to access and don't put the JavaScript in that table's edit event. Then I would creat a view of the users table and use that one for non-admins and set the JavaScript event in that view(table).
In your dynamic permissions admin area, let the admins have access to the original table and allow the non-admins, default group, access to the new user view table.
When the admins log in they will only see their user table and when non-admins log in, they will only see the user view. you might also have to set up table permissions on the security tab.
Hope this helps.
Brian

C
cgphp 3/2/2012

In the "Before display" event of the edit page, enter the following code:

if($values['group_field_name'] == 'user')

{

$attr = $xt->fetchVar("username_editcontrol");

$attr = str_replace(">"," READONLY=READONLY>",$attr);

$xt->assign("username_editcontrol",$attr);

}
I
igiacchi author 3/2/2012

CLOSED



In the "Before display" event of the edit page, enter the following code:

if($values['group_field_name'] == 'user')

{

$attr = $xt->fetchVar("username_editcontrol");

$attr = str_replace(">"," READONLY=READONLY>",$attr);

$xt->assign("username_editcontrol",$attr);

}



Hi Cristian, many many thanks for your help, I put this code inside 'Before display' and RUN! Very Well
// Place event code here.
if($values['GroupID'] == "user")

{

$attr = $xt->fetchVar("User_editcontrol");

$attr = str_replace(">"," READONLY=READONLY>",$attr);

$xt->assign("User_editcontrol",$attr);
}

// Use "Add Action" button to add code snippets.