LiveUser_Admin
[ class tree: LiveUser_Admin ] [ index: LiveUser_Admin ] [ all elements ]

Source for file UserRights.php

Documentation is available at UserRights.php

  1. <?php
  2. require_once 'index.php';
  3. echo '<h3>UserRights</h3>';
  4.  
  5. $users $admin->getUsers(array('container' => 'auth'));
  6. if ($users === false{
  7.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  8.     print_r($admin->getErrors());
  9.     exit;
  10. elseif (empty($users)) {
  11.     echo 'Run the <strong>User</strong> test first<br />';
  12.     exit;
  13. }
  14.  
  15. $rights $admin->perm->getRights();
  16. if ($rights === false{
  17.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  18.     print_r($admin->getErrors());
  19.     exit;
  20. elseif (empty($rights)) {
  21.     echo 'Run the <strong>Right</strong> test first<br />';
  22.     exit;
  23. }
  24.  
  25. for ($i = 1; $i < 30; $i++{
  26.     $user array_rand($users);
  27.     $right array_rand($rights);
  28.     $data = array(
  29.         'perm_user_id' => $users[$user]['perm_user_id'],
  30.         'right_id' => $rights[$right]['right_id'],
  31.         'right_level' => 1,
  32.     );
  33.     $granted $admin->perm->grantUserRight($data);
  34.  
  35.     if ($granted === false{
  36.         echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  37.         print_r($admin->getErrors());
  38.     else {
  39.         echo '<strong>' $users[$user]['name''</strong> was granted the right <strong>' $rights[$right]['right_id''</strong><br />';
  40.     }
  41.     unset($rights[$right]);
  42.     $rights array_values($rights);
  43. }
  44.  
  45. $user array_rand($users);
  46. $right array_rand($rights);
  47. $filters = array(
  48.     'perm_user_id' => $users[$user]['auth_user_id'],
  49.     'right_id' => $rights[$right]['right_id']
  50. );
  51. $revoked $admin->perm->revokeUserRight($filters);
  52.  
  53. if ($revoked === false{
  54.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  55.     print_r($admin->getErrors());
  56. else {
  57.     echo 'The right <strong>' $rights[$right]['right_id''</strong> has been revoked from <strong>' $users[$user]['name''</strong><br />';
  58. }
  59.  
  60. $user array_rand($users);
  61. $params = array(
  62.     'fields' => array(
  63.         'right_id'
  64.     ),
  65.     'filters' => array(
  66.         'perm_user_id' => $users[$user]['perm_user_id']
  67.     )
  68. );
  69.  
  70. $user_rights $admin->perm->getRights($params);
  71.  
  72. if ($user_rights === false{
  73.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  74. elseif (empty($user_rights)) {
  75.     echo 'No rights were found for perm user id <strong>' $users[$user]['perm_user_id''</strong><br />';
  76. else {
  77.     $right array_rand($user_rights);
  78.     $filters = array(
  79.         'perm_user_id' => $users[$user]['auth_user_id'],
  80.         'right_id' => $user_rights[$right]['right_id']
  81.     );
  82.     $data = array('right_level' => 3);
  83.  
  84.     $update $admin->perm->updateUserRight($data$filters);
  85.  
  86.     if ($update === false{
  87.         echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  88.         print_r($admin->getErrors());
  89.     else {
  90.         echo 'The right <strong>' $user_rights[$right]['right_id''</strong> has been updated to Level 3 for <strong>' $users[$user]['name''</strong><br />';
  91.         $params = array(
  92.             'filters' => array(
  93.                 'right_id' => $user_rights[$right]['right_id'],
  94.                 'perm_user_id' => $users[$user]['perm_user_id']
  95.             )
  96.         );
  97.         $result $admin->perm->getRights($params);
  98.  
  99.         if ($result === false{
  100.             echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  101.             print_r($admin->getErrors());
  102.         elseif (empty($result)) {
  103.             echo 'No result came from searching for right id <strong>' $user_rights[$right]['right_id''</strong>
  104.                   and perm user id <strong>' $users[$user]['perm_user_id''</strong><br />';
  105.         else {
  106.             Var_Dump::display($result);
  107.         }
  108.     }
  109. }
  110.  
  111. $user array_rand($users);
  112. $params = array(
  113.     'fields' => array(
  114.         'right_id',
  115.         'right_level'
  116.     ),
  117.     'filters' => array(
  118.         'perm_user_id' => $users[$user]['perm_user_id']
  119.     )
  120. );
  121. $singleRight $admin->perm->getRights($params);
  122.  
  123. if ($singleRight === false{
  124.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  125.     print_r($admin->getErrors());
  126. elseif (empty($singleRight)) {
  127.     echo 'No rights were found for perm user id <strong>' $users[$user]['perm_user_id''</strong><br />';
  128. else {
  129.     echo 'These are the user rights for <strong>' $users[$user]['perm_user_id''</strong>:<br />';
  130.     Var_Dump::display($singleRight);
  131.     echo '<br />';
  132. }
  133.  
  134. $params = array(
  135.     'fields' => array(
  136.         'right_id',
  137.         'right_level',
  138.         'perm_user_id',
  139.     ),
  140.     'with' => array(
  141.         'perm_user_id' => array(
  142.             'fields' => array(
  143.                 'perm_type',
  144.             ),
  145.         ),
  146.     ),
  147. );
  148.  
  149. $rights $admin->perm->getRights($params);
  150. if ($rights === false{
  151.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  152.     print_r($admin->getErrors());
  153. elseif (empty($rights)) {
  154.     echo 'No rights were found.<br />';
  155. else {
  156.     echo 'Here are all the rights:<br />';
  157.     Var_Dump::display($rights);
  158.     echo '<br />';
  159. }
  160. echo '<hr />';

Documentation generated on Mon, 11 Mar 2019 15:39:44 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.