--- workspace.module.org	2008-08-07 03:49:45.000000000 +0100
+++ workspace.module	2009-03-06 10:34:11.000000000 +0000
@@ -100,8 +100,15 @@
  */
 function workspace_access($account, $module_enabled = TRUE) {
   global $user;
-  return user_access('access content')     // If you may not see content, you may not see workspaces.
-    && (user_access('view all workspaces') // Must either have permission to see all workspaces
+  // Let admin see $account
+  if ($user->uid == 1 && $account->uid > 1) {
+    return user_access('access content', $account)
+      && user_access('access workspace', $account)
+      &&  $module_enabled;
+  }
+  return user_access('access content', $user)     // If you may not see content, you may not see workspaces.
+    && user_access('access workspace', $user)     // Allowed to see own workspace
+    && (user_access('view all workspaces', $user) // Must either have permission to see all workspaces
         || (($user->uid == $account->uid)  // or must be your workspace
         && ($user->uid != 0)))             // and you must not be an anonymous user
     && $module_enabled;                    // If, e.g., comment module is disabled, remove comment local task.
@@ -112,6 +119,10 @@
  */
 function workspace_configure_access($account) {
   global $user;
+  if ($user->uid == 1 && $account->uid > 1) {
+    return user_access('administer workspaces', $account)
+      || user_access('administer own workspace', $account);
+  }
   return ($user->uid != 0)                          // May not be anonymous user.
     && user_access('administer workspaces')         // Must either have permission to administer all workspaces
     || ($user->uid == $account->uid                 // Or if this is your workspace
@@ -123,7 +134,7 @@
 * Implementation of hook_perm().
 */
 function workspace_perm() {
-  return array('administer own workspace', 'administer workspaces', 'view all workspaces');
+  return array('access workspace', 'administer own workspace', 'administer workspaces', 'view all workspaces');
 }
 
 /**
@@ -237,15 +248,16 @@
     $comments_enabled ? array('data' => t('Replies'), 'field' => 'comment_count') : array('data' => ''),
     array('data' => t('Operations'), 'colspan' => 2)
   );
+  $cols = 8;
   $result = pager_query(db_rewrite_sql($sql . tablesort_sql($header)), $max, 0, db_rewrite_sql($count_sql), $account->uid);
   $rows = workspace_build_rows($result, $account);
   $output = '';
   // Only add the content add form if the user is viewing his/her own workspace.
-  if ($user->uid == $account->uid) {
+  if ($user->uid == 1 || user_access('view all workspaces') || $user->uid == $account->uid) {
     $output = drupal_get_form('workspace_add_form');
   }
   
-  $output .= theme_workspace_list($header, $rows, $max);
+  $output .= theme_workspace_list($header, $rows, $max, $cols);
   return $output;
 }
 
@@ -273,9 +285,10 @@
     array('data' => t('Replies'), 'field' => 'comment_count'),
     array('data' => t('Operations'), 'colspan' => 2)
   );
+  $cols = 6;
   $result = pager_query($sql . tablesort_sql($header), $max, 0, $count_sql, $account->uid);
   $rows = workspace_build_rows($result, $account);
-  return theme_workspace_list($header, $rows, $max);
+  return theme_workspace_list($header, $rows, $max, $cols);
 }
 
 /**
@@ -369,6 +382,7 @@
  *   User object representing user whose workspace is being listed.
  */
 function workspace_list_files($account) {
+  global $user;
   drupal_set_title(t('Workspace: @name', array('@name' => $account->name)));
   $max = isset($user->workspaces) ? $user->workspaces['default']['maxfilenames'] : 50;
   $download = t('download');
@@ -380,7 +394,7 @@
     array('data' => t('Size'), 'field' => 'f.filesize'),
     array('data' => t('Operations')),
   );
-
+  $cols = 6;
   $sql = "SELECT u.nid, f.filemime, f.filename, f.filesize, f.timestamp, f.filepath
           FROM {files} f
           LEFT JOIN {upload} u ON f.fid = u.fid
@@ -397,7 +411,7 @@
     );
   }
 
-  return theme('workspace_list', $header, $rows, $max);
+  return theme('workspace_list', $header, $rows, $max, $cols);
 }
 
 /**
@@ -406,7 +420,7 @@
 function workspace_theme() {
   return array(
     'workspace_list' => array(
-      'arguments' => array('header' => array(), 'rows' => array(), $max = 50),
+      'arguments' => array('header' => array(), 'rows' => array(), $max = 50, $cols = 8),
     ),
   );  
 }
@@ -414,13 +428,13 @@
 /**
  * Theme the list of content. Turn the results into a table.
  */
-function theme_workspace_list($header, $rows, $max) {
+function theme_workspace_list($header, $rows, $max, $cols) {
   if ($rows) {
-    $pager = theme('pager', NULL, $max, 2);
+    $pager = theme('pager', NULL, $max);
     if (!empty($pager)) {
-      $rows[] = array(array('data' => $pager, 'colspan' => 3));
+      $rows[] = array(array('data' => $pager, 'colspan' => $cols));
     }
-    $output .= theme('table', $header, $rows);
+    $output = theme('table', $header, $rows);
   }
   else {
     $output = t('Your workspace is currently empty.');
@@ -489,6 +503,11 @@
       $options[$type] = $object->name;
     }
     if (isset($options[$node_type])) {
+      /* Start hack */
+      if (stristr($node_type,"_") > -1) {
+        $node_type = str_replace("_","-",$node_type);
+      }
+      /* End hack */
       drupal_goto('node/add/' . $node_type);
     }
   }
@@ -529,22 +548,19 @@
  */
 function workspace_user($op, &$edit, &$account) {
   global $user;
-  if ($op == 'view' && user_access('view all workspaces')) {
-    $allowed = FALSE;
-    foreach ($user->roles as $rid => $name) {
-      if (variable_get('workspace_user_profile_'. $rid, 0)) {
-        $allowed = TRUE;
-        break;
-      }
-    }
-    if ($allowed) {
+  if ($op == 'view') {
+    if( workspace_access($account)) {
       $variables['%username'] = $account->name;
       $link_title = variable_get('workspace_user_profile_link', t('View recent content'));
-      
-      $account->content['summary']['workspace'] = array(
-        '#type' => 'user_profile_item',
+      $link = l(strtr($link_title, $variables), 'workspace/'. $account->uid);
+      $account->content['workspace'] = array(
+        '#type' => 'user_profile_category',
         '#title' => variable_get('workspace_user_profile_title', t('Content')),
-        '#value' => l(strtr($link_title, $variables), 'workspace/'. $account->uid),
+        'link' => array(
+          '#value' => $link,
+          '#type' => 'user_profile_item',
+        ),
+        '#weight' => -10,
       );
     }
   }
