The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User Creation Permission
#3
What makes this a little tricky is that user levels are not "levels" as in one is higher than another. Personally, if I were doing this, I would create the permission levels and then go into the database into the permissions level and give some space (like 5 or 10 between them) in case you ever have to add more levels. Do this BEFORE you start assigning all these permissions to pages. I would do

10 – CSR
20 – System Administrator (full access)
30 – Log Access
40 – User Management
50 – Manager

Then, the trick is going to be to go into the figuring out the HIGHEST level of permissions that a user has access to by their own user id (which is expressed as $user->data()->id).

I had a few minutes so I typed out the code (including var_dumps so you can see what each query is bringing back) and a drop down box at the bottom showing you the permission names (but still recording the ids). If you are writing your own thing to create new users I STRONGLY recommend you check out the code that does this on the backend in admin_users.php to see the other things that have to happen when you create a new user.
Here is the code on hastebin (which is probably easier to read)
http://hastebin.com/ricacecoja.xml
Code:
<?php
//get a list of the highest permission level your logged in user has...
Code:
$highestPermQ = $db->query("SELECT * FROM user_permission_matches WHERE user_id = ? ORDER BY permission_id DESC",array($user->data()->id));
Code:
$highestPerm = $highestPermQ->first();
Code:
dump($highestPerm);

//now you need to figure out what permissions they can use for their dropdown box or whatever.

Code:
$highest = $highestPerm->permission_id;
Code:
dump($highest); //This SHOULD give you the highest permission level they have
Code:
$availableQ = $db->query("SELECT * FROM permissions WHERE id !=2 AND id < ?",array($highest));
Code:
$available = $availableQ->results();
Code:
dump($available); //should show all ids below the one listed above but NOT admin (2)
Code:
?>

Code:
<div class="form-group">
Code:
<label for="gen_loc">Available user levels</label>
Code:
<select class="form-control" name="available" id="available" value=""required>
Code:
<?php foreach($available as $a){ ?>
Code:
<option value="<?=$a->id?>"><?=$a->name?></option>
Code:
<?php } ?></select>
Code:
</div>
  Reply


Messages In This Thread
User Creation Permission - by Brandin - 10-30-2016, 05:47 PM
User Creation Permission - by plb - 10-31-2016, 06:21 AM
User Creation Permission - by mudmin - 10-31-2016, 12:11 PM
User Creation Permission - by Brandin - 10-31-2016, 01:21 PM
User Creation Permission - by mudmin - 10-31-2016, 01:29 PM
User Creation Permission - by Brandin - 10-31-2016, 01:32 PM
User Creation Permission - by mudmin - 10-31-2016, 01:37 PM
User Creation Permission - by mudmin - 10-31-2016, 01:40 PM
User Creation Permission - by Brandin - 10-31-2016, 02:20 PM
User Creation Permission - by dan - 10-31-2016, 02:23 PM
User Creation Permission - by plb - 10-31-2016, 03:23 PM
User Creation Permission - by Brandin - 10-31-2016, 03:24 PM
User Creation Permission - by dan - 10-31-2016, 04:07 PM
User Creation Permission - by Brandin - 10-31-2016, 04:20 PM
User Creation Permission - by mudmin - 10-31-2016, 04:36 PM
User Creation Permission - by Brandin - 10-31-2016, 04:46 PM
User Creation Permission - by mudmin - 10-31-2016, 04:51 PM
User Creation Permission - by Brandin - 10-31-2016, 08:12 PM
User Creation Permission - by dan - 10-31-2016, 08:28 PM
User Creation Permission - by Brandin - 10-31-2016, 08:31 PM
User Creation Permission - by Brandin - 11-01-2016, 12:17 AM
User Creation Permission - by mudmin - 11-01-2016, 12:37 AM
User Creation Permission - by Brandin - 11-01-2016, 12:53 AM
User Creation Permission - by mudmin - 11-01-2016, 12:58 AM
User Creation Permission - by Brandin - 11-01-2016, 01:03 AM
User Creation Permission - by mudmin - 11-01-2016, 01:24 AM
User Creation Permission - by Brandin - 11-01-2016, 03:12 AM
User Creation Permission - by mudmin - 11-01-2016, 11:21 AM
User Creation Permission - by Brandin - 11-01-2016, 05:56 PM
User Creation Permission - by Brandin - 11-01-2016, 06:07 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)