Make a field readonly depending on usertype

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
bernierei
User
Posts: 19

Make a field readonly depending on usertype

Post 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?


mobhar
User
Posts: 11660

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


bernierei
User
Posts: 19

Post 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


mobhar
User
Posts: 11660

Post 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.


bernierei
User
Posts: 19

Post 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!


mobhar
User
Posts: 11660

Post 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

Post Reply