Index: client/hosting_client.access.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/hosting/client/hosting_client.access.inc,v
retrieving revision 1.7
diff -u -r1.7 hosting_client.access.inc
--- client/hosting_client.access.inc	17 Apr 2009 03:03:31 -0000	1.7
+++ client/hosting_client.access.inc	23 Apr 2009 18:58:14 -0000
@@ -41,29 +41,53 @@
 function hosting_client_user_view($user) {
   if ($user->client_id) {
 
-    $items['client'] = array(
-      'title' => t('Hosting client'),
-      'value' => _hosting_node_link($user->client_id),
-      'class' => 'client',
-    );
+    foreach($user->client_id as $client => $type) {
+      $rows[] = array(_hosting_node_link($client), implode(',', $type));
+    }
+
+    $header = array(t('Hosting client'), t('Contact type'));
+    $items['client_'. $client] = array(
+        'value' => theme('table', $header, $rows),
+        'class' => 'client',
+        );
 
-    return array(t('Client') => $items);
+    return array(t('Clients') => $items);
   }
 }
 
 function hosting_client_user_form($edit, $user, $category) {
+
+  if ($user->client_id) {
+     foreach($user->client_id as $client => $type) {
+      $fields[$category]['name'][$client] = array('#value' => _hosting_node_link($client));
+      $fields[$category]['checkboxes'][$client] = array('#value' => implode(',', $type));
+      $rows[] = array(_hosting_node_link($client), implode(',', $type));
+    }
+  }
+
+  $header = array(t('Hosting client'), t('Contact type'));
+  $fields[$category]['clients'] = array(
+    '#type' => 'item',
+    '#value' => theme('table', $header, $rows),
+    '#title' => t('Clients'),
+    '#weight' => 1,
+    );
+
   if (user_access('administer client users')) {
-    $client = hosting_get_client($user->client_id);
+    //$client = hosting_get_client($user->client_id);
     $fields[$category]['hosting_client'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Client'),
-      '#autocomplete_path' => 'hosting_client/autocomplete/client',
-      '#default_value' => $client->title,
-      '#weight' => 1,
-    );
+        '#type' => 'textfield',
+        '#title' => t('Add new client'),
+        '#autocomplete_path' => 'hosting_client/autocomplete/client',
+        '#weight' => 2,
+        );
+  }
+  return $fields;
+}
 
-    return $fields;
-  }
+function theme_hosting_client_user_form($form) {
+  $output = drupal_render($form);
+  return $output;
 }
 
 function hosting_client_user_form_validate($edit) {
@@ -84,6 +108,26 @@
   }
 }
 
+/////// not used yet - making the list of clients/users more generic
+function hosting_client_node_list($node) {
+  $fields = array();
+
+  if ($node->type == 'user') {
+    $list = $node->client_id;
+  } else { // 'client'
+    $list = $node->nid;
+  }
+
+  if ($list) {
+     foreach($list as $item => $type) {
+      $fields[$category]['name'][$item] = array('#value' => _hosting_node_link($item));
+      $fields[$category]['checkboxes'][$item] = array('#value' => implode(',', $type));
+    }
+  }
+
+  return $fields;
+}
+
 
 
 /**
@@ -114,13 +158,17 @@
  */
 function hosting_node_grants($account, $op) {
   $account->client_id = hosting_get_client_from_user($account->uid);
-  if ($account->client_id) {
+  //fb($account->client_id);
+  foreach($account->client_id as $client_id => $client_relations) {
+  //if ($account->client_id) {
     $types = array_merge(hosting_feature_node_types(), array('site', 'task', 'package', 'client')); 
     foreach ($types as $type) {
       if (user_access("$op $type")) {
-        $grants['hosting ' . $type] = array($account->client_id);
+        // TODO: restrict access to certain op-type based on the user relationship to this client - see content of $client_relations
+        $grants['hosting ' . $type] = array($client_id); 
       }
     }
+    //fb($grants);
     return $grants;
   }
 }
@@ -186,6 +234,15 @@
   }
 }
 
+/**
+ * Returns an associative array that provides the relationships a user has with different clients
+ */
 function hosting_get_client_from_user($uid) {
-  return db_result(db_query("SELECT client FROM {hosting_client_user} WHERE user=%d", $uid));
+  $clients = array();
+  if ($results = db_query("SELECT client, contact_type FROM {hosting_client_user} WHERE user=%d", $uid)) {
+    while ($result = db_fetch_array($results)) {
+      $clients[$result['client']] = explode(',', $result['contact_type']);
+    }
+  }
+  return $clients;
 }
Index: client/hosting_client.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/hosting/client/hosting_client.install,v
retrieving revision 1.8
diff -u -r1.8 hosting_client.install
--- client/hosting_client.install	17 Apr 2009 03:03:31 -0000	1.8
+++ client/hosting_client.install	23 Apr 2009 18:58:14 -0000
@@ -17,9 +17,10 @@
       db_query("CREATE TABLE {hosting_client_user} (
          user int(10) unsigned NOT NULL default '0',
          client int(10) unsigned NOT NULL default '0',
-         PRIMARY KEY (user)
+         contact_type longtext NOT NULL,
+         PRIMARY KEY (user, client)
        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
-      db_query("INSERT INTO {hosting_client_user} VALUES (1, 1)");
+      db_query("INSERT INTO {hosting_client_user} VALUES (1, 1, 'admin')");
       break;
    }
 
@@ -104,3 +105,14 @@
   node_access_rebuild();
   return $ret;
 }
+
+/**
+ * Make it possible to have many clients per user and keep track of the contact type (admin/tech/billing/etc.) between users and clients
+ */
+function hosting_client_update_6() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE {hosting_client_user} DROP PRIMARY KEY ADD PRIMARY KEY (user, client)"); 
+  $ret[] = update_sql("ALTER TABLE {hosting_client_user} ADD contact_type LONGTEXT NOT NULL");
+  node_access_rebuild();
+  return $ret;
+}
Index: site/hosting_site.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/hosting/site/hosting_site.module,v
retrieving revision 1.98
diff -u -r1.98 hosting_site.module
--- site/hosting_site.module	17 Apr 2009 19:57:46 -0000	1.98
+++ site/hosting_site.module	23 Apr 2009 18:58:14 -0000
@@ -230,9 +230,12 @@
     $client = node_load($node->client);
   } else {
     global $user;
-    $client_id = hosting_get_client_from_user($user->uid);
-    $client_id = ($client_id) ? $client_id : HOSTING_DEFAULT_CLIENT;
-    $client = node_load($client_id);
+    $clients_ids = hosting_get_client_from_user($user->uid);
+    foreach($clients_ids as $client_id => $client_permissions) {
+      $client_id = ($client_id) ? $client_id : HOSTING_DEFAULT_CLIENT;
+      $client = node_load($client_id);
+      $clients[$client->title] = $client->title;
+    }
   }
 
   if ((!$node->client || $node->nid) && user_access('administer site')) {
@@ -240,17 +243,18 @@
       '#type' => 'textfield',
       '#required' => TRUE,
       '#title' => t('Client'),
-      '#default_value' => $client->title,
+      '#default_value' => key($clients),
       '#description' => t('The client who this site belongs to.'),
       '#autocomplete_path' => 'hosting_client/autocomplete/client',
     );
   }
   else {
-    $form['client'] = array('#type' => 'hidden', '#value' => $client->title);
-    $form['info']['client'] = array(
-      '#type' => 'item',
+    $form['client'] = array(
+      '#type' => 'radios',
       '#title' => t('Client'),
-      '#value' => $client->title,
+      '#default_value' => key($clients),
+      '#options' => $clients,
+      '#description' => t('The client who this site belongs to.'),
     );
   }
 
@@ -732,6 +736,7 @@
 function _hosting_site_form_populate($element, $value, $value2 = null) {
   $form[$element] = call_user_func('_hosting_site_form_'. $element, $value, $value2);
 
+  $GLOBALS['devel_shutdown'] = FALSE;
   print drupal_to_js(
     array(
       'status' => 'TRUE',
