Random Drupal 7 Cheat Sheet Notes - Drupal show roles and Profile Data

Base Mold Pour 3 of 4

Random Drupal 7 Cheat Sheet Notes - Drupal show roles and Profile Data

/* List a user's roles */

foreach($user->roles as $role) {
print "Role: ".$role." ";
}

/* Check if user is in role *>

if (in_array('Web Manager', $user->roles)) {$display ="on";}


global $user;
$uid = user_load($user->uid);
$profile = profile2_load_by_user($uid, 'main');
$full_name = " ";
$full_name = $profile->field_profile_full_name;
if (isset($full_name['und'][0]['value'])) {
echo $profile->field_profile_full_name['und'][0]['value'];
} else {
print '<div class=messages--error>WARNING: We do not appear to have your Full Name on file. Please update your contact details to include this information. Thank You.</div>' ;
}


/* Logging out of Cosign / Drupal - EAT COOKIES */

global $user;

 watchdog('user', 'Session closed for %name.', array('%name' => $user->name));

  // Eat the cookies
  foreach($_COOKIE AS $key => $value)
  {
    setcookie($key,$value,1);
    unset($_COOKIE[$key]);
  }

  // Destroy the current session:
  session_destroy();
  $_SESSION = array();

  // Only variables can be passed by reference workaround.
  $null = NULL;
  user_module_invoke('logout', $null, $user);

  // Load the anonymous user
  $user = drupal_anonymous_user();

header('Cache-Control: no-cache');
header('Expires: -1');
$query_string = $_SERVER['QUERY_STRING'];
$service_name = $_SERVER['COSIGN_SERVICE'];
$central = "https:// COSIGN SEVER /logout/logout.cgi";

setcookie($service_name, "null", time()-3600, '/', "", 1 );
setcookie("logoutcookie",logout, time()+110);
setcookie("browseropen","open");
header( "Location: $central?$query_string" );