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 -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	22 Apr 2009 23:16:56 -0000
@@ -11,6 +11,7 @@
   switch ($op) {
 
   case 'load':
+// faut avoir la liste, dans un array
     $user->client_id = hosting_get_client_from_user($user->uid);
     break;
 
@@ -41,29 +42,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 +109,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 +159,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;
   }
 }
@@ -187,5 +236,11 @@
 }
 
 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 -u -r1.8 hosting_client.install
--- client/hosting_client.install	17 Apr 2009 03:03:31 -0000	1.8
+++ client/hosting_client.install	22 Apr 2009 23:16:56 -0000
@@ -104,3 +104,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;
+}
