diff --git a/client/hosting_client.install b/client/hosting_client.install
index 882370d..80e5016 100644
--- a/client/hosting_client.install
+++ b/client/hosting_client.install
@@ -62,6 +62,21 @@ function hosting_client_schema() {
     'primary key' => array('user', 'client'),
   );
 
+  $schema['hosting_client_platforms'] = array(
+      'fields' => array(
+      'nid' => array(
+      'type' => 'int',
+      'unsigned' => TRUE,
+      'not null' => TRUE,
+      'default' => 0,
+      ),
+      'platforms' => array(
+      'type' => 'longtext',
+      'size' => 'big',
+      ),
+    ),
+  );
+
   return $schema;
 }
 
@@ -169,3 +184,25 @@ function hosting_client_update_7() {
   return array();
 }
 
+function hosting_client_update_8() {
+  $ret = array();
+
+  $q = db_query("SELECT nid FROM {node} WHERE type = 'platform' AND status = '1';");
+  $platforms = array();
+  while ($result = db_fetch_array($q)) {
+    $platforms[] = $result['nid'];
+  }
+  $allowed_platforms = @implode(',', $platforms);
+
+  $ret[] = update_sql("CREATE TABLE {hosting_client_platforms} (nid INT, platforms LONGTEXT)");
+  $client_ids=array();
+  $result = db_query("SELECT nid from {hosting_client}");
+  while ($row = db_fetch_array($result)) {
+    $client_ids[] = $row['nid'];
+  }
+  foreach ($client_ids as $client_id) {
+    $result = db_query("INSERT INTO %s (nid, platforms) VALUES ('%d', '%s')", "hosting_client_platforms", $client_id, $allowed_platforms);
+  }
+  return $ret;
+}
+
diff --git a/client/hosting_client.module b/client/hosting_client.module
index 4cb26ae..e273e8b 100644
--- a/client/hosting_client.module
+++ b/client/hosting_client.module
@@ -109,6 +109,7 @@ function hosting_get_client_by_email($email) {
  */
 function hosting_client_form(&$node) {
   $type = node_get_types('type', $node);
+  $platforms = _hosting_get_platforms();
 
   $form['title'] = array('#type' => 'hidden', '#value' => $node->title);
 
@@ -147,6 +148,13 @@ function hosting_client_form(&$node) {
     '#maxlength' => 100,
   );
 
+  $form['platforms'] = array(
+    '#type' => 'checkboxes',
+    '#title' => 'Allowed platforms',
+    '#options' => $platforms,
+    '#default_value' => hosting_client_platforms_select($node),
+  );
+
   if ($node->nid) {
     // this should probably be factored out in a common function
     $q = db_query("SELECT u.uid, u.name FROM {hosting_client_user} h INNER JOIN {users} u ON u.uid = h.user WHERE h.client = %d", $node->nid);
@@ -237,6 +245,8 @@ function hosting_client_set_title(&$node) {
 function hosting_client_insert($node) {
   db_query("INSERT INTO {hosting_client} (vid, nid, name, organization, email) VALUES (%d, %d, '%s', '%s', '%s' )",
     $node->vid, $node->nid, $node->client_name, $node->organization, $node->email);
+  $allowed_platforms = hosting_client_platforms_choice($node);
+  $allowed_platforms_insert = hosting_client_platforms_insert($node);
   hosting_client_set_title($node);
   if (variable_get('hosting_client_register_user', FALSE) 
     && !user_load(array('mail' => $node->email))) {
@@ -312,6 +322,8 @@ function hosting_client_update($node) {
   else {
     db_query("UPDATE {hosting_client} SET nid=%d, name = '%s', organization = '%s', email='%s' WHERE vid=%d",
               $node->nid, $node->client_name, $node->organization, $node->email, $node->vid);
+    $allowed_platforms = hosting_client_platforms_choice($node);
+    $allowed_platforms_update = hosting_client_platforms_update($node);
   }
   hosting_client_set_title($node);  
   if ($node->users) {
@@ -401,6 +413,26 @@ function hosting_client_view($node, $teaser = FALSE, $page = FALSE) {
       '#suffix' => '</div>', 
       '#weight' => 11
     );
+    $q = db_query("SELECT platforms FROM {hosting_client_platforms} WHERE nid = %d", $node->nid);
+    $platforms = array();
+    while ($result = db_fetch_array($q)) {
+      $platforms['platforms'] = explode(',', $result['platforms']);
+    }
+    foreach ($platforms['platforms'] AS $platform) {
+      $q = db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {hosting_platform} p ON p.nid = n.nid WHERE p.nid = %d", $platform);
+      while ($result = db_fetch_array($q)) {
+        $p_rows[] = array(l($result['title'], 'node/' . $result['nid']));
+      }
+    }
+    $header = array(t('Allowed platforms'));
+    $node->content['platforms_view'] = array(
+      '#type' => 'item',
+      '#value' => theme('table', $header, $p_rows),
+      '#class' => 'client',
+      '#prefix' => '<div id="hosting-site-list">',
+      '#suffix' => '</div>',
+      '#weight' => 12
+    );
   }
   return $node;
 }
@@ -593,3 +625,93 @@ function hosting_client_autocomplete($type, $keyword) {
   exit();
 }
 
+/**
+ * Retrieve the selected allowed platforms for the client
+ */
+function hosting_client_platforms_choice($node) {
+  $element = $node->platforms;
+  foreach ($element as $key => $choice) {
+    if (isset($element[$key]) && $element[$key] != 0) {
+      $platform[] = $element[$key];
+    }
+  }
+  // The client has access to the default platform or else the Add Site form gets very unhappy
+  if ($platform && !in_array(HOSTING_DEFAULT_PLATFORM, $platform)) {
+    $allowed_platforms = @implode(',', $platform) . ',' . HOSTING_DEFAULT_PLATFORM;
+  }
+  else if (!$platform) {
+    $allowed_platforms = HOSTING_DEFAULT_PLATFORM;
+  }
+  else {
+    $allowed_platforms = @implode(',', $platform);
+  }
+  return $allowed_platforms;
+}
+
+/**
+ * Insert the selected allowed platforms into the database
+ */
+function hosting_client_platforms_insert($node) {
+  $allowed_platforms = hosting_client_platforms_choice($node);
+   $q = db_query("INSERT INTO {hosting_client_platforms} (nid, platforms) VALUES (%d, '%s')",
+    $node->nid, $allowed_platforms);
+  return $q;
+}
+
+/**
+ * Update the client's allowed platforms
+ */
+function hosting_client_platforms_update($node) {
+  $allowed_platforms = hosting_client_platforms_choice($node);
+  $q = db_query("UPDATE {hosting_client_platforms} SET platforms = '%s' WHERE nid = %d", $allowed_platforms, $node->nid);
+  return $q;
+}
+
+/**
+ * Select the list of allowed platforms from the database, explode them into an array
+ */
+function hosting_client_platforms_select($node) {
+  $q = db_query("SELECT platforms FROM {hosting_client_platforms} WHERE nid = %d", $node->nid);
+  while ($result = db_fetch_array($q)) {
+    $allowed_platforms = $result['platforms'];
+  }
+  $allowed_platforms = explode(',', $allowed_platforms);
+  return $allowed_platforms;
+}
+
+/**
+ * Select the list of allowed platforms from the database, but get the names as well
+ */
+function hosting_client_platforms_select_pretty($node) {
+  $return = array();
+  $allowed = hosting_client_platforms_select($node);
+  foreach ($allowed as $allowed_platform) {
+    $result = db_query("SELECT nid, title FROM {node} WHERE type='platform' AND status=1 AND nid = '%s'", $allowed_platform);
+    while($server = db_fetch_object($result)) {
+      $return[$server->nid] = $server->title;
+    }
+  }
+  return $return;
+}
+
+/**
+ * If the default hosting platform gets changed, force this platform to be allowed per client
+ */
+function hosting_client_platforms_default_update($node) {
+  $clients = array();
+  $platforms = array();
+  $q = db_query("SELECT nid, platforms FROM {hosting_client_platforms}");
+  while ($result = db_fetch_array($q)) {
+    $clients['nid'] =  $result['nid'];
+    $platforms['platforms'] = $result['platforms'];
+  }
+  foreach ($clients as $client) {
+    foreach ($platforms as $platform) {
+      $platform = explode(',', $platform);
+      if (!in_array($node->nid, $platform)) {
+        $platforms = @implode(',', $platform) . ',' . $node->nid;
+        $q = db_query("UPDATE {hosting_client_platforms} SET platforms = '%s' WHERE nid = %d", $platforms, $client);
+      }
+    }
+  }
+}
diff --git a/platform/hosting_platform.module b/platform/hosting_platform.module
index d4cefb4..4cf3e1a 100644
--- a/platform/hosting_platform.module
+++ b/platform/hosting_platform.module
@@ -136,6 +136,7 @@ function hosting_platform_form(&$node) {
  */
 function hosting_platform_insert($node) {
   if ($node->default_platform == 1) {
+    $update_default_platform = hosting_client_platforms_default_update($node);
     variable_set('hosting_default_platform', $node->nid);
   }
   hosting_add_task($node->nid, 'verify');
@@ -156,6 +157,7 @@ function hosting_platform_update($node) {
   }
   else {
     if ($node->default_platform == 1) {
+      $update_default_platform = hosting_client_platforms_default_update($node);
       variable_set('hosting_default_platform', $node->nid);
     }
     db_query("UPDATE {hosting_platform} SET publish_path = '%s', web_server = %d, verified = %d WHERE nid=%d",
diff --git a/site/hosting_site.module b/site/hosting_site.module
index 31d3b5f..356f6af 100644
--- a/site/hosting_site.module
+++ b/site/hosting_site.module
@@ -384,6 +384,11 @@ function hosting_site_validate($node, &$form) {
     if (!user_access('administer clients') && !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->title)));
     }
+    $platforms = db_result(db_query("SELECT platforms FROM {hosting_client_platforms} WHERE nid = %d", $client->nid));
+    $platforms = explode(",", $platforms);
+    if (!in_array($node->platform, $platforms)) {
+      form_set_error('client', t('This client cannot create a site on this platform'));
+    }
   }
   if (!array_key_exists($node->profile, hosting_get_profiles($node->platform))) {
     form_set_error('profile', t('Please fill in a valid profile'));
