Index: hosting/client/hosting_client.install
===================================================================
RCS file: /cvs/drupal/contributions/modules/hosting/client/hosting_client.install,v
retrieving revision 1.12
diff -u -p -r1.12 hosting_client.install
--- hosting/client/hosting_client.install	24 Jun 2009 15:47:55 -0000	1.12
+++ hosting/client/hosting_client.install	28 Jul 2009 13:33:36 -0000
@@ -35,6 +35,12 @@ function hosting_client_schema() {
         'not null' => TRUE,
         'default' => '',
       ),
+      'quota' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
     ),
     'primary key' => array('vid'),
   );
Index: hosting/client/hosting_client.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/hosting/client/hosting_client.module,v
retrieving revision 1.50
diff -u -p -r1.50 hosting_client.module
--- hosting/client/hosting_client.module	21 Jul 2009 01:46:13 -0000	1.50
+++ hosting/client/hosting_client.module	28 Jul 2009 13:33:36 -0000
@@ -146,6 +146,15 @@ function hosting_client_form(&$node) {
     '#maxlength' => 100,
   );
 
+  $form['quota'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Quota'),
+    '#size' => 40,
+    '#default_value' => $node->quota,
+    '#maxlength' => 100,
+    '#description' => t('Enter 0 for unlimited quota'),
+  );
+
   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);
@@ -209,6 +218,13 @@ function hosting_client_validate(&$node)
   if (!valid_email_address($node->email)) {
     form_set_error('email', t("Email address invalid."));
   }
+  if (!is_numeric($node->quota)) {
+    form_set_error('quota', t("Quota figure invalid."));
+  }
+  $current_quota = db_result(db_query("SELECT COUNT(nid) FROM {hosting_site} WHERE client=%d", $node->nid));
+  if ($node->quota < $current_quota && $node->quota != "0") {
+    form_set_error('quota', t('The quota cannot be lower than the number of sites the client already has!'));
+  }
 }
 
 function hosting_client_set_title(&$node) {
@@ -234,8 +250,8 @@ function hosting_client_set_title(&$node
  * Implementation of hook_insert().
  */
 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);
+  db_query("INSERT INTO {hosting_client} (vid, nid, name, organization, email, quota) VALUES (%d, %d, '%s', '%s', '%s', '%d' )",
+    $node->vid, $node->nid, $node->client_name, $node->organization, $node->email, $node->quota);
   hosting_client_set_title($node);
   if (variable_get('hosting_client_register_user', FALSE) 
     && !user_load(array('mail' => $node->email))) {
@@ -309,8 +325,8 @@ function hosting_client_update($node) {
     hosting_client_insert($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);
+    db_query("UPDATE {hosting_client} SET nid=%d, name = '%s', organization = '%s', email='%s', quota='%d' WHERE vid=%d",
+              $node->nid, $node->client_name, $node->organization, $node->email, $node->quota, $node->vid);
   }
   hosting_client_set_title($node);  
   if ($node->users) {
@@ -339,7 +355,7 @@ function hosting_client_delete($node) {
  * Implementation of hook_load().
  */
 function hosting_client_load($node) {
-  $additions = db_fetch_object(db_query('SELECT name as client_name, organization, email FROM {hosting_client} WHERE vid = %d', $node->vid));
+  $additions = db_fetch_object(db_query('SELECT name as client_name, organization, email, quota FROM {hosting_client} WHERE vid = %d', $node->vid));
   return $additions;
 }
 
Index: hosting/site/hosting_site.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/hosting/site/hosting_site.module,v
retrieving revision 1.109
diff -u -p -r1.109 hosting_site.module
--- hosting/site/hosting_site.module	20 Jul 2009 15:13:57 -0000	1.109
+++ hosting/site/hosting_site.module	28 Jul 2009 13:33:36 -0000
@@ -374,6 +374,14 @@ function hosting_site_validate($node, &$
       form_set_error('client', t('Access denied to client @client', array('@client' => $client->title)));
     }
   }
+  // If we're adding a new site, not updating or deleting, make sure the client hasn't reached their quota of sites 
+  if (!$node->nid) {
+    $set_quota = db_result(db_query("SELECT quota FROM {hosting_client} WHERE nid=%d", $client->nid));
+    $current_quota = db_result(db_query("SELECT COUNT(nid) FROM {hosting_site} WHERE client=%d", $client->nid));
+    if ($current_quota == $set_quota && $current_quota != "0") {
+      form_set_error('client', t('This client has reached his or her maximum quota of sites'));
+    }
+  }  
   if (!array_key_exists($node->profile, hosting_get_profiles($node->platform))) {
     form_set_error('profile', t('Please fill in a valid profile'));
   }
