You are here

function mobile_tools_roles_boot in Mobile Tools 6

Same name and namespace in other branches
  1. 7.2 mobile_tools_roles/mobile_tools_roles.module \mobile_tools_roles_boot()
  2. 7.2 mobile_tools_roles/mobile_tools_roles.inc \mobile_tools_roles_boot()

Being called in the hook_init() implementation This function is in charge of changing the user role

1 call to mobile_tools_roles_boot()
mobile_tools_boot in ./mobile_tools.module
Implementation of hook_boot(). Hook boot is called for both anonymous users and logged in users

File

./mobile_tools_roles.inc, line 6
Contains the functionality to add mobile user roles

Code

function mobile_tools_roles_boot() {
  global $user;
  $roles = $user->roles;

  //count the number of mobile roles... must be bigger then 1
  $item = db_fetch_object(db_query("SELECT COUNT(*) as count FROM {mobile_tools_roles_relations}"));
  if ($item->count > 0) {
    foreach ($roles as $key => $value) {
      $role = mobile_tools_roles_info(array(
        'id' => $key,
      ));
      if ($role->type == 'desktop' && $role->has_sibling == 1 && ($_SESSION['mobile-tools-site-type'] == 'mobile' || $_SESSION['mobile-tools-mobile-device']['type'] == 'mobile' && variable_get('mobile-tools-theme-switch', FALSE) == 'mobile-tools-mobile-device')) {
        unset($user->roles[$key]);
        $user->roles[$role->sibling['id']] = $role->sibling['name'];
      }
    }
  }
}