Advertisement
AlexWebDevelop

Untitled

Apr 9th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php
  2.  
  3. /* SQL connection */
  4. $pdo = new PDO(/* SQL connection parameters */);
  5.  
  6. /* RBAC class */
  7. $rbac = new RBAC($pdo);
  8.  
  9. /* Read the role id from the request string (you should also sanitize it) */
  10. $role_id = $_REQUEST['role_id'];
  11.  
  12. /* Array with a list of possible role permission IDs. This list can be created in different ways, either statically (from a configuration file, for example) or dynamically from a database */
  13. $permission_list = array('1', '2', '3', /* ... */);
  14.  
  15. /* Now, for each permission we look for the checkbox value */
  16. foreach ($permission_list as $permission)
  17. {
  18.     /* Check if a request string exists */
  19.     if (array_key_exists('checkbox_' . $permission, $_REQUEST))
  20.     {
  21.         /* Check its value: if is 1 set the permission, otherwise remove it */
  22.         $permission_set = $_REQUEST['checkbox_' . $permission];
  23.        
  24.         if ($permission_set == '1')
  25.         {
  26.             $rbac->addRolePermission($role_id, $permission);
  27.         }
  28.         else
  29.         {
  30.             $rbac->deleteRolePermission($role_id, $permission);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement