--- ras/devel2/modules/referral.module	2006-02-22 01:24:09.000000000 +0100
+++ ras/devel/modules/referral.module	2006-03-24 21:21:50.000000000 +0100
@@ -31,40 +31,40 @@
 
 function referral_menu($may_cache) {
   $items = array();
-
-  $items[] = array(
-    'path'     => 'referral',
-    'callback' => 'referral_get',
-    'access'   => true,
-    'type'     => MENU_CALLBACK);
-
-  $items[] = array(
-    'path'     => 'referral/view',
-    'callback' => 'referral_view',
-    'access'   => user_access(REFERRAL_PERM_USE),
-    'type'     => MENU_CALLBACK);
-
-  $items[] = array(
-    'path'     => 'admin/logs/referral',
-    'title'    => t('summary'),
-    'callback' => 'referral_admin_view_summary',
-    'access'   => user_access(REFERRAL_PERM_ADMIN),
-    'type'     => MENU_NORMAL_ITEM);
-  
-  $items[] = array(
-    'path'     => 'admin/logs/referral/summary',
-    'title'    => t('summary'),
-    'callback' => 'referral_admin_view_summary',
-    'access'   => user_access(REFERRAL_PERM_ADMIN),
-    'type'     => MENU_NORMAL_ITEM);
+  if ($may_cache) {
+    $items[] = array(
+      'path'     => 'referral',
+      'callback' => 'referral_get',
+      'access'   => true,
+      'type'     => MENU_CALLBACK);
   
-  $items[] = array(
-    'path'     => 'admin/logs/referral/details',
-    'title'    => t('details'),
-    'callback' => 'referral_admin_view_details',
-    'access'   => user_access(REFERRAL_PERM_ADMIN),
-    'type'     => MENU_NORMAL_ITEM);
+    $items[] = array(
+      'path'     => 'referral/view',
+      'callback' => 'referral_view',
+      'access'   => user_access(REFERRAL_PERM_USE),
+      'type'     => MENU_CALLBACK);
   
+    $items[] = array(
+      'path'     => 'admin/logs/referral',
+      'title'    => t('user referral'),
+      'callback' => 'referral_admin_view_summary',
+      'access'   => user_access(REFERRAL_PERM_ADMIN),
+      'type'     => MENU_NORMAL_ITEM);
+    
+    $items[] = array(
+      'path'     => 'admin/logs/referral/summary',
+      'title'    => t('summary'),
+      'callback' => 'referral_admin_view_summary',
+      'access'   => user_access(REFERRAL_PERM_ADMIN),
+      'type'     => MENU_NORMAL_ITEM);
+    
+    $items[] = array(
+      'path'     => 'admin/logs/referral/details',
+      'title'    => t('details'),
+      'callback' => 'referral_admin_view_details',
+      'access'   => user_access(REFERRAL_PERM_ADMIN),
+      'type'     => MENU_NORMAL_ITEM);
+  }  
   return $items;
 }
 
@@ -75,8 +75,9 @@
     // User has not logged in, or registered yet
     $uid = _ref2uid(arg(1));
     if ($uid) {
+      $account = (object)array('uid' => $uid);
       // A referring User ID is set 
-      if (is_numeric($uid)) {
+      if (is_numeric($uid) && user_access(REFERRAL_PERM_USE, $account)) {
         // And it is numeric
         // Set the session variable
         $_SESSION[REFERRAL_UID]      = $uid;
@@ -137,8 +138,10 @@
   global $user, $base_url;
   switch ($op) {
     case 'insert':
-      // The user is being created, save the complete referral data
-      _referral_user_save($arg_user->uid);
+      if (arg(1) == 'register') {
+        // The user is being created, save the complete referral data
+        _referral_user_save($arg_user->uid);
+      }
       break;
 
     case 'view':
@@ -159,7 +162,7 @@
       if ($referrals) {
         return array('Referrals' => $referrals);
       }
-	    break;
+	  break;
   }
 }
 
@@ -182,7 +185,6 @@
 }
 
 function referral_block_content() {
-  //$header = array(t('User'), t('#'));
   $header = array();
   $sql = 'SELECT r.referral_uid, u.name, COUNT(*) AS num_referrals
     FROM {referral} r INNER JOIN {users} u ON u.uid = r.referral_uid 
@@ -196,7 +198,7 @@
     );
   }
   if (!$rows) {
-    $rows[] = array(array('data' => t('No data.'), 'colspan' => '4'));
+    $rows[] = array(t('No data.'));
   }
   return theme('table', $header, $rows);
 }
@@ -244,13 +246,12 @@
     FROM {referral} r INNER JOIN {users} u USING(uid)' . tablesort_sql($header);
   $result = pager_query($sql, REFERRAL_PAGE_COUNT);
   while ($data = db_fetch_object($result)) {
-    $referer = check_plain(_referral_column_width($data->http_referer));
     $rows[] = array(
-      array('data' => $data->referral_uid),
+      array('data' => check_plain($data->referral_uid)),
       array('data' => l($data->name, "user/$data->uid")),
       array('data' => format_date($data->created, 'custom', REFERRAL_DATE_FORMAT)),
       array('data' => l($data->host, "http://whois.sc/$data->host")),
-      array('data' => l($referer, $data->http_referer)),
+      array('data' => l(_referral_column_width($data->http_referer), $data->http_referer)),
     );
   }
   if (!$rows) {
