Page 1 of 1

Make a field readonly depending on usertype

Posted: Fri Feb 16, 2018 11:02 pm
by bernierei

I am trying to some fields of a table readonly for a default user but editable for another. My code goes:

function Page_Load() {
if (CurrentUserLevelID() = 0){
$jo->eqp_id->ReadOnly=TRUE;
}
}

where jo is the table and eqp_id is the field. I get this error if I click the edit button:

Fatal error: Can't use function return value in write context in C:\xampp\htdocs\JO\joedit.php on line 1150

can you guys enlighten me?


Re: Make a field readonly depending on usertype

Posted: Sat Feb 17, 2018 12:47 am
by mobhar

bernierei wrote:
if (CurrentUserLevelID() = 0){

should be:
if (CurrentUserLevel() == 0) {

bernierei wrote:
$jo->eqp_id->ReadOnly=TRUE;

should be:
$this->eqp_id->ReadOnly = TRUE;


Make a field readonly depending on usertype

Posted: Sat Feb 17, 2018 9:39 am
by bernierei

Thanks man. Did your advice but now, I am getting this error:

Fatal error: Uncaught Error: Call to undefined function CurrentUserLevelID() in C:\xampp\htdocs\JO\joedit.php:1113 Stack trace: #0 C:\xampp\htdocs\JO\joedit.php(311): cjo_edit->Page_Load() #1 C:\xampp\htdocs\JO\joedit.php(1187): cjo_edit->Page_Init() #2 {main} thrown in C:\xampp\htdocs\JO\joedit.php on line 1113


Re: Make a field readonly depending on usertype

Posted: Sat Feb 17, 2018 12:14 pm
by mobhar

I did not recommend you to use CurrentUserLevelID(). I recommended you to use CurrentUserLevel(). Please see again my reply above, and double check your code.


Re: Make a field readonly depending on usertype

Posted: Sat Feb 17, 2018 4:34 pm
by bernierei

Hey, thanks man. I somehow managed to make it work. It is just weird for me because I set the userlevels table with these values:

anonymous (-2), administrator (-1), default (0), it staff (1), mi sup (2), and mi mgr (3)

but what phpmaker shows when i echoed the CurrentUserID() is this:

administrator (-1), user (1), it staff (2), mi sup (6), and mi mgr (7)

Thanks again for the prompt response and for the help, mobhar!


Re: Make a field readonly depending on usertype

Posted: Sat Feb 17, 2018 5:09 pm
by mobhar

Please note that CurrentUserLevel() function is different with the CurrentUserID() function. The first one will return the current user level, and the second one will return the current user id.

User Level will secure your data at table level, and User ID will secure your data at record level.

For more info, please read:

  • Tutorial - Advanced Security - User ID Security
  • Tutorial - Advanced Security - Dynamic User Level Security