Exemple #1
0
 /**
  * Bulk User Role Change
  *
  * @param string $from name of role to move from
  * @param string $to name of role to move to
  * @return bool
  */
 public function bulkRoleChange($h, $from = '', $to = '')
 {
     if (!$from || !$to) {
         return false;
     }
     // check $from and $to exist
     $unique_roles = $this->getUniqueRoles($h);
     if (!in_array($from, $unique_roles)) {
         return false;
     }
     if (!in_array($to, $unique_roles)) {
         return false;
     }
     $sql = "SELECT user_id FROM " . TABLE_USERS . " WHERE user_role = %s";
     $items = $h->db->get_results($h->db->prepare($sql, $from));
     if ($items) {
         // Change role and permissions for each user being moved
         foreach ($items as $item) {
             $user = new UserAuth();
             $user->getUser($h, $item->user_id);
             $user->role = $to;
             $new_perms = $user->getDefaultPermissions($h, $user->role);
             $user->setAllPermissions($new_perms);
             $user->updateUserBasic($h);
         }
     }
     return true;
 }