You are here

function mobile_tools_user in Mobile Tools 6

Same name and namespace in other branches
  1. 5 mobile_tools.module \mobile_tools_user()

Implementation of the user_load function to assure that the right role is being assigned to the user. This is the same actions as in the hook_init() method

File

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

Code

function mobile_tools_user($op, &$edit, &$account, $category = NULL) {
  if (variable_get('mobile_tools_enable_roles', 0)) {
    switch ($op) {
      case 'load':
        $user = $account;
        $roles = $user->roles;
        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') {
            unset($user->roles[$key]);
            $user->roles[$role->sibling['id']] = $role->sibling['name'];
          }
        }
        break;
    }
  }
}