cvs diff: Diffing .
cvs diff: Diffing alias
cvs diff: Diffing client
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	13 May 2009 16:47:32 -0000
@@ -29,7 +29,6 @@
     $edit['hosting_client'] = NULL;
     break;
   case 'submit':
-    hosting_client_user_form_submit($edit, $user);
     break;
 
   case 'delete':
@@ -41,51 +40,81 @@
 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));
+    }
+
+    // this is a table because we'll have types for clients eventually
+    $header = array(t('Hosting client'));
+    $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) {
+
+  $clients = array();
+  if ($user->client_id) {
+    foreach($user->client_id as $client => $type) {
+      $clients[$client] = '';
+      $fields[$category]['name'][$client] = array('#type' => 'markup', '#value' => _hosting_node_link($client));
+    }
+  }
+  if (user_access('administer client users')) {
+    $fields[$category]['clients'] = array('#type' => 'checkboxes', '#options' => $clients);
+  }
+  
+  $fields[$category]['header'] = array('#type' => 'value', '#value' => array(array('data' => t('Hosting client'))));
+  
   if (user_access('administer client users')) {
-    $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,
-    );
-
-    return $fields;
+        '#type' => 'textfield',
+        '#title' => t('Client name'),
+        '#title' => t('Add new client'),
+        '#weight' => 2,
+        '#autocomplete_path' => 'hosting_client/autocomplete/client',
+        );
+  }
+  $fields[$category]['#theme'] = 'hosting_client_user_form';
+  return $fields;
+}
+
+function theme_hosting_client_user_form($form) {
+  foreach (element_children($form['name']) as $client) {
+    $row = array();
+    $row['data'][] = drupal_render($form['name'][$client]);
+    if (user_access('administer client users')) {
+      $row['data'][] = drupal_render($form['clients'][$client]);
+    }
+    $rows[] = $row;
   }
+  $output = drupal_render($form);
+  $output .= theme('table', $form['header']['#value'], $rows);
+  return $output;
 }
 
 function hosting_client_user_form_validate($edit) {
-  if (array_key_exists('hosting_client', $edit)) {
-    if (!$client = hosting_get_client($edit['hosting_client'])) {
-      form_set_error('hosting_client', 'Please fill in a valid client');
-    }
+  if (array_key_exists('hosting_client', $edit) && $edit['hosting_client'] && (!$client = hosting_get_client($edit['hosting_client']))) {
+    form_set_error('hosting_client', 'Please fill in a valid client');
   }
 }
 
 function hosting_client_user_form_submit($edit, $user) {
-  if (array_key_exists('hosting_client', $edit)) {
-    $client = hosting_get_client($edit['hosting_client']);
-    $query = db_query('UPDATE {hosting_client_user} SET client = %d WHERE user = %d', $client->nid, $user->uid);
-    if (!db_affected_rows()) {
-      $query = db_query('INSERT INTO {hosting_client_user} (client, user) VALUES (%d, %d)', $client->nid, $user->uid);
+  if (array_key_exists('clients', $edit)) {
+    foreach ($edit['clients'] as $client) {
+      $query = db_query('DELETE FROM {hosting_client_user} WHERE user = %d AND client = %d', $user->uid, $client);
     }
   }
+  if (array_key_exists('hosting_client', $edit) && $edit['hosting_client']) {
+    $client = hosting_get_client($edit['hosting_client']);
+    $query = db_query('INSERT INTO {hosting_client_user} (client, user, contact_type) VALUES (%d, %d, "%s")', $client->nid, $user->uid, '');
+  }
 }
 
-
-
 /**
  * Simple function to make sure we don't respond with grants when disabling
  * ourselves.
@@ -114,11 +143,12 @@
  */
 function hosting_node_grants($account, $op) {
   $account->client_id = hosting_get_client_from_user($account->uid);
-  if ($account->client_id) {
+  foreach($account->client_id as $client_id => $client_relations) {
     $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); 
       }
     }
     return $grants;
@@ -186,6 +216,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 -u -r1.8 hosting_client.install
--- client/hosting_client.install	17 Apr 2009 03:03:31 -0000	1.8
+++ client/hosting_client.install	13 May 2009 16:47:32 -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: client/hosting_client.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/hosting/client/hosting_client.module,v
retrieving revision 1.35
diff -u -u -r1.35 hosting_client.module
--- client/hosting_client.module	7 May 2009 16:24:36 -0000	1.35
+++ client/hosting_client.module	13 May 2009 16:47:32 -0000
@@ -202,7 +202,7 @@
   $pass = user_password();
   $user = new stdClass();
   $edit['name'] = $node->email;
-  $edit['hosting_client'] = $node->nid;
+  $edit['hosting_client'] = array($node->nid);
   $edit['mail'] = $node->email;
   $edit['pass'] = $pass;
   $edit['status'] = 1;
cvs diff: Diffing cron
cvs diff: Diffing db_server
cvs diff: Diffing dns_server
cvs diff: Diffing itk
cvs diff: Diffing migrate
cvs diff: Diffing package
cvs diff: Diffing platform
cvs diff: Diffing signup
cvs diff: Diffing site
Index: site/hosting_site.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/hosting/site/hosting_site.module,v
retrieving revision 1.100
diff -u -u -r1.100 hosting_site.module
--- site/hosting_site.module	9 May 2009 16:31:00 -0000	1.100
+++ site/hosting_site.module	13 May 2009 16:47:33 -0000
@@ -227,13 +227,21 @@
 
   # find the right client
   global $user;
-  $client_id = hosting_get_client_from_user($user->uid);
-  $client_id = ($client_id) ? $client_id : HOSTING_DEFAULT_CLIENT;
+  $client_ids = hosting_get_client_from_user($user->uid);
+  $clients = array();
+  foreach($client_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 == $client_id) {
+      $current_client_id = $client_id;
+    }
+  }
   // allow admins to override
   if ($node->client && user_access('administer site')) {
-    $client_id = $node->client;
+    $current_client_id = $node->client;
   }
-  $client = node_load($client_id);
+  $client = node_load($current_client_id);
 
   if ((!$node->client || $node->nid) && user_access('administer site')) {
     $form['client'] = array(
@@ -246,11 +254,12 @@
     );
   }
   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.'),
     );
   }
 
@@ -323,7 +332,8 @@
   return $form;
 }
 
-function hosting_site_validate(&$node) {
+function hosting_site_validate($node, &$form) {
+  global $user;
   $url = strtolower($node->title); // domain names are case-insensitive
   if (!_hosting_valid_fqdn($url)) {
     form_set_error('title', t("You have not specified a valid url for this site."));
@@ -332,8 +342,14 @@
   if (hosting_site_exists($url, $node->nid)) {
     form_set_error('title', t("The domain name you have specified is not unique."));
   }
-  if (!$node->new_client && !hosting_get_client($node->client)) {
-    form_set_error('client', t('Please fill in a valid client'));
+  if (!$node->new_client) {
+    $client = hosting_get_client($node->client);
+    if (!$node->client || !$client) {
+      form_set_error('client', t('Please fill in a valid client'));
+    }
+    if (!array_key_exists($client->nid, hosting_get_client_from_user($user->uid))) {
+      form_set_error('client', t('Access denied to client @client', array('@client' => $client)));
+    }
   }
   if (!array_key_exists($node->profile, hosting_get_profiles($node->platform))) {
     form_set_error('profile', t('Please fill in a valid profile'));
@@ -727,6 +743,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',
cvs diff: Diffing stats
cvs diff: Diffing task
cvs diff: Diffing web_server
