Index: domain.info
===================================================================
--- domain.info	(revision 3051)
+++ domain.info	(working copy)
@@ -1,4 +1,5 @@
 ;  $Id: domain.info,v 1.2 2007/10/04 01:35:28 agentken Exp $
+core = 6.x
 name = Domain Access
 description = A subdomain-based access control system
 package = Domain Access
\ No newline at end of file
Index: domain.install
===================================================================
--- domain.install	(revision 3051)
+++ domain.install	(working copy)
@@ -10,35 +10,56 @@
  * Implements hook_install()
  */
 function domain_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      db_query("CREATE TABLE {domain} (
-        domain_id int(11) NOT NULL AUTO_INCREMENT,
-        subdomain varchar(40) NOT NULL default '',
-        sitename varchar(80) NOT NULL default '',
-        scheme varchar(8) NOT NULL default 'http',
-        valid varchar(1) NOT NULL default 1,        
-        PRIMARY KEY  (domain_id),
-        KEY subdomain (subdomain)
-        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
-      break;
-    case 'pgsql':
-      db_query("CREATE TABLE {domain} (
-        domain_id serial,
-        subdomain varchar(40) NOT NULL default '',
-        sitename varchar(80) NOT NULL default '',
-        scheme varchar(8) NOT NULL default 'http',   
-        valid varchar(1) NOT NULL default 1,                
-        PRIMARY KEY (domain_id)
-        )");   
-      db_query("CREATE INDEX {domain}_subdomain_idx ON {domain} (subdomain)");
-      break;
-  } 
   // Create the 'all' realm for Domain Access.
+  drupal_install_schema('domain'); 
   db_query("INSERT INTO {node_access} VALUES (0, 0, 'domain_all', 1, 0, 0)");    
 }
 
+function domain_schema () {
+  $schema['domain'] = array(
+    'description' => t('The table defining domains'),
+    'fields' => array(
+      'domain_id' => array(
+	    'description' => t('the domain id'),
+	    'type' => 'serial',
+	    'not null' => TRUE,
+      ),
+      'subdomain' => array(
+	    'description' => t('the name of the subdomain'),
+	    'type' => 'varchar',
+	    'length' => 40,
+	    'not null' => TRUE,
+      ),
+      'sitename' => array(
+	    'description' => t('the name of the site'),
+	    'type' => 'varchar',
+	    'length' => 80,
+	    'not null' => TRUE,
+      ),
+      'scheme' => array(
+	    'description' => t('????'),
+	    'type' => 'varchar',
+	    'length' => 8,
+	    'not null' => TRUE,
+	    'default' => 'http',
+      ),
+      'valid' => array(
+	    'description' => t('????'),
+	    'type' => 'varchar',
+	    'length' => 1,
+	    'not null' => TRUE,
+	    'default' => '1',
+      ),
+    ),
+    'primary key' => array('domain_id'),
+    'indexes' => array(
+	  'subdomain' => array('subdomain'),
+    ),
+  );
+  
+  return $schema;
+}
+
 /**
  * Implements hook_uninstall()
  */
Index: domain.module
===================================================================
--- domain.module	(revision 3051)
+++ domain.module	(working copy)
@@ -60,73 +60,60 @@
  *
  * @ingroup drupal
  */
-function domain_menu($may_cache) {
+function domain_menu() {
   $items = array();
   $admin = user_access('administer domains');
-  if ($may_cache) {
-    $items[] = array(
-      'title' => t('Domain access'),
-      'path' => 'admin/build/domain',
-      'access' => $admin,
-      'callback' => 'domain_admin',
-      'callback arguments' => array('configure'),
-      'description' => t('Settings for the Domain Access module.')
-    );    
-    $items[] = array(
-      'title' => t('Settings'),
-      'path' => 'admin/build/domain/settings',
-      'access' => $admin,
-      'type' => MENU_DEFAULT_LOCAL_TASK,
-      'callback' => 'domain_admin',
-      'callback arguments' => array('configure'),
-      'weight' => -10
-    );     
-    $items[] = array(
-      'title' => t('Domain list'),
-      'path' => 'admin/build/domain/view',
-      'access' => $admin,
-      'type' => MENU_LOCAL_TASK,      
-      'callback' => 'domain_admin',
-      'callback arguments' => array('view'),
-      'weight' => -8
-    );    
-    $items[] = array(
-      'title' => t('Create domain record'),
-      'path' => 'admin/build/domain/create',
-      'access' => $admin,
-      'type' => MENU_LOCAL_TASK,
-      'callback' => 'domain_admin',
-      'callback arguments' => array('create'),
-      'weight' => -4      
-    );    
-    $items[] = array(
-      'title' => t('Node settings'),
-      'path' => 'admin/build/domain/advanced',
-      'access' => $admin,
-      'type' => MENU_LOCAL_TASK,
-      'callback' => 'domain_admin',
-      'callback arguments' => array('advanced'),
-      'weight' => -2
-    );         
-  }  
-  else {    
-    $items[] = array(
-      'title' => t('Edit domain record'),
-      'path' => 'admin/build/domain/edit',
-      'access' => $admin,
-      'type' => MENU_CALLBACK,
-      'callback' => 'domain_admin',
-      'callback arguments' => array('edit', arg(4))      
-    );  
-    $items[] = array(
-      'title' => t('Delete domain record'),
-      'path' => 'admin/build/domain/delete',
-      'access' => $admin,
-      'type' => MENU_CALLBACK,
-      'callback' => 'domain_admin',
-      'callback arguments' => array('delete', arg(4))      
-    );    
-  }
+  $items['admin/build/domain'] = array(
+    'title' => t('Domain access'),
+    'access argumemts' => array('administer domains'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('domain_configure_form'),
+    'description' => t('Settings for the Domain Access module.'),
+    'file' => 'domain_admin.inc',
+  );    
+  $items['admin/build/domain/settings'] = array(
+    'title' => t('Settings'),
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'file' => 'domain_admin.inc',
+    'weight' => -10
+  );     
+  $items['admin/build/domain/view'] = array(
+    'title' => t('Domain list'),
+    'type' => MENU_LOCAL_TASK,      
+    'page callback' => 'domain_view',
+    'file' => 'domain_admin.inc',
+    'weight' => -8,
+  );    
+  $items['admin/build/domain/create'] = array(
+    'title' => t('Create domain record'),
+    'type' => MENU_LOCAL_TASK,
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('domain_create_form'),
+    'file' => 'domain_admin.inc',
+    'weight' => -4      
+  );    
+  $items['admin/build/domain/advanced'] = array(
+    'title' => t('Node settings'),
+    'type' => MENU_LOCAL_TASK,
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('domain_advanced_form'),
+    'file' => 'domain_admin.inc',
+    'weight' => -2
+  );             
+  $items['admin/build/domain/edit'] = array(
+    'title' => t('Edit domain record'),
+    'type' => MENU_CALLBACK,
+    'page callback' => 'drupal_get_form',
+    'file' => 'domain_admin.inc',
+    'page arguments' => array('domain_edit_form',4),      
+  );  
+  $items['admin/build/domain/delete'] = array(
+    'title' => t('Delete domain record'),
+    'type' => MENU_CALLBACK,
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('domain_delete_form',4),
+    'file' => 'domain_admin.inc',      
+  );    
   return $items;
 }
 
@@ -311,11 +298,11 @@
  *
  * @ingroup domain
  */
-function domain_admin($action, $id = NULL) {
+/*function domain_admin($action, $id = NULL) {
   include_once('domain_admin.inc');
   $func = 'domain_'. $action;
   return $func($id);
-}
+}*/
 
 /**
  * Runs a lookup against the {domain} table.  One of the two values must be present
@@ -495,10 +482,11 @@
   global $base_url;
   $_url = parse_url($base_url);
   // We need a trailing slash at the end of the path
-  if (substr($_url['path'], -1) != '/') {
-    $_url['path'] .= '/';
+  if (isset($_url['path']) && substr($_url['path'], -1) != '/') {
+    $_url['path'] .= $_url['path'].'/';
   }
-  $path = $domain['scheme'] .'://'. $domain['subdomain'] . $_url['path'];
+  $url = isset($_url['path'])?$_url['path']:'';
+  $path = $domain['scheme'] .'://'. $domain['subdomain'].$url ;
   return $path;
 }
 
@@ -868,7 +856,7 @@
  *
  * @ingroup node
  */
-function domain_form_alter($form_id, &$form) {
+function domain_form_alter(&$form, $form_state, $form_id) {
   // If SEO is turned on, then form actions need to be absolute paths
   // to the currently active domain.  See http://drupal.org/node/196217.
   $seo = variable_get('domain_seo', 0);
Index: domain_admin.inc
===================================================================
--- domain_admin.inc	(revision 3051)
+++ domain_admin.inc	(working copy)
@@ -72,6 +72,7 @@
     $row[] = $actions;
     $rows[] = $row;
   }
+  menu_rebuild();
   if (!empty($rows)) {
     $output .= theme_table($header, $rows);
     $output .= theme('pager', NULL, 24, 0); 
@@ -83,25 +84,15 @@
 }
 
 /**
- * Module settings and behaviors.
+ * FormsAPI for configuring the domain module.
  *
- * @ingroup domain 
+ * @ingroup domain
  */
-function domain_configure() {
+function domain_configure_form() {
   // Ensure that the default grant is present.
   domain_enable();
   module_invoke_all('domaininstall');
-  // Return the configuration form.
-  return drupal_get_form('domain_configure_form');
-}
-
-/**
- * FormsAPI for configuring the domain module.
- *
- * @ingroup domain
- */
-function domain_configure_form($user_submitted = FALSE) {
-  $form = array();
+  
   $form['domain'] = array(
     '#type' => 'fieldset',
     '#title' => t('Default domain settings'),
@@ -241,15 +232,6 @@
 }
 
 /**
- * Create a new domain record
- *
- * @ingroup domain
- */
-function domain_create() {
-  return drupal_get_form('domain_create_form');
-}
-
-/**
  * FormsAPI for creating domain records.
  *
  * @param $arguments
@@ -262,8 +244,8 @@
  *
  * @ingroup domain
  */
-function domain_create_form($arguments = array()) { 
-  $form = array();
+function domain_create_form($edit,$arguments = array()) { 
+ 
   // The $arguments arrray allows other modules to pass values to change the bahavior
   // of submit and validate functions.
   if (!empty($arguments)) {
@@ -315,15 +297,15 @@
  *
  * @ingroup domain
  */
-function domain_create_form_validate($form_id, $form_values) {
+function domain_create_form_validate($form, &$form_state) {
   // TODO: Make this a proper regex?
-  $subdomain = strtolower(urlencode($form_values['subdomain']));
+  $subdomain = strtolower(urlencode($form_state['values']['subdomain']));
   $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE subdomain = '%s'", $subdomain));
   if ($check) {
     form_set_error('subdomain', t('The subdomain value must be unique.'));
   }
   $check = NULL;
-  $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE sitename = '%s'", $form_values['sitename']));
+  $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE sitename = '%s'", $form_state['values']['sitename']));
   if ($check) {
     form_set_error('sitename', t('The site name value must be unique.'));
   }  
@@ -334,35 +316,19 @@
  *
  * @ingroup domain 
  */
-function domain_create_form_submit($form_id, $form_values) {
-  db_query("INSERT INTO {domain} (subdomain, sitename, scheme, valid) VALUES ('%s', '%s', '%s', %d)", $form_values['subdomain'], $form_values['sitename'], $form_values['scheme'], $form_values['valid']);
+function domain_create_form_submit($form, &$form_state) {
+  db_query("INSERT INTO {domain} (subdomain, sitename, scheme, valid) VALUES ('%s', '%s', '%s', %d)", $form_state['values']['subdomain'], $form_state['values']['sitename'], $form_state['values']['scheme'], $form_state['values']['valid']);
   // Let other modules act.
-  $domain = domain_lookup(NULL, $form_values['subdomain']);
-  module_invoke_all('domainupdate', 'create', $domain, $form_values);
+  $domain = domain_lookup(NULL, $form_state['values']['subdomain']);
+  module_invoke_all('domainupdate', 'create', $domain, $form_state['values']);
   // The user_submitted flag is needed for Domain User.
-  if (!$form_values['domain_arguments']['user_submitted']) { 
+  if (! isset($form_state['values']['domain_arguments']['user_submitted'])) { 
     drupal_set_message(t('Domain record created.'));
     drupal_goto('admin/build/domain/view');
   }  
 }
 
 /**
- * Edit an existing domain record
- * 
- * @param $domain_id
- *  The unique id for this domain, taken from {domain}.
- *
- * @ingroup domain
- */
-function domain_edit($domain_id) {
-  $domain = domain_lookup($domain_id);
-  // We must do this from the default domain, in case the URL does not resolve.
-  $default = domain_default();
-  domain_goto($default);  
-  return drupal_get_form('domain_edit_form', $domain);
-}
-
-/**
  * FormsAPI for editing a domain record
  *
  * @param $domain
@@ -370,8 +336,13 @@
  *
  * @ingroup domain 
  */
-function domain_edit_form($domain) { 
-  $form = array();
+function domain_edit_form($edit,$domain_id) { 
+  
+  $domain = domain_lookup($domain_id);
+  // We must do this from the default domain, in case the URL does not resolve.
+  $default = domain_default();
+  domain_goto($default);  
+  
   $form['domain'] = array(
     '#type' => 'fieldset',
     '#title' => t('Edit domain record'),
@@ -421,14 +392,14 @@
  *
  * @ingroup domain 
  */
-function domain_edit_form_validate($form_id, $form_values) {
+function domain_edit_form_validate($form, &$form_state) {
   // TODO: Make this a proper regex
-  $subdomain = strtolower(urlencode($form_values['subdomain']));
-  $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE subdomain = '%s' AND domain_id != %d", $subdomain, $form_values['domain_id']));
+  $subdomain = strtolower(urlencode($form_state['values']['subdomain']));
+  $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE subdomain = '%s' AND domain_id != %d", $subdomain, $form_state['values']['domain_id']));
   if ($check) {
     form_set_error('subdomain', t('The subdomain value must be unique.'));
   }
-  $check2 = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE sitename = '%s' AND domain_id != %d", $form_values['sitename'], $form_values['domain_id']));
+  $check2 = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE sitename = '%s' AND domain_id != %d", $form_state['values']['sitename'], $form_state['values']['domain_id']));
   if ($check2) {
     form_set_error('sitename', t('The site name value must be unique.'));
   }  
@@ -439,29 +410,16 @@
  *
  * @ingroup domain 
  */
-function domain_edit_form_submit($form_id, $form_values) {
-  db_query("UPDATE {domain} SET subdomain = '%s', sitename = '%s', scheme = '%s', valid = %d WHERE domain_id = %d", $form_values['subdomain'], $form_values['sitename'], $form_values['scheme'], $form_values['valid'], $form_values['domain_id']);
+function domain_edit_form_submit($form, &$form_state) {
+  db_query("UPDATE {domain} SET subdomain = '%s', sitename = '%s', scheme = '%s', valid = %d WHERE domain_id = %d", $form_state['values']['subdomain'], $form_state['values']['sitename'], $form_state['values']['scheme'], $form_state['values']['valid'], $form_state['values']['domain_id']);
   // Let other modules act.
-  $domain = domain_lookup($form_values['domain_id']);
-  module_invoke_all('domainupdate', 'update', $domain, $form_values);
+  $domain = domain_lookup($form_state['values']['domain_id']);
+  module_invoke_all('domainupdate', 'update', $domain, $form_state['values']);
   drupal_set_message(t('Domain record updated.'));
   drupal_goto('admin/build/domain/view');  
 }
 
 /**
- * Delete a domain record.
- * 
- * @param $domain_id
- *  The unique id for this domain, taken from {domain}. 
- *
- * @ingroup domain 
- */
-function domain_delete($domain_id) {
-  $domain = domain_lookup($domain_id);
-  return drupal_get_form('domain_delete_form', $domain);
-}
-
-/**
  * FormsAPI
  *
  * @param $domain
@@ -469,8 +427,8 @@
  *
  * @ingroup domain 
  */
-function domain_delete_form($domain) { 
-  $form = array(); 
+function domain_delete_form($edit,$domain_id) { 
+  $domain = domain_lookup($domain_id);
   $form['domain_id'] = array('#type' => 'value', '#value' => $domain['domain_id']);  
   $form['domain'] = array('#value' => t('<p>Are you sure you wish to delete the domain record for <b>%domain</b>?</p>', array('%domain' => $domain['subdomain'])));
   $form['cancel'] = array('#value' => '<p>'. l(t('Cancel action'), 'admin/build/domain') .'<br />');
@@ -483,12 +441,12 @@
  *
  * @ingroup domain 
  */
-function domain_delete_form_submit($form_id, $form_values) {
+function domain_delete_form_submit($form, &$form_state) {
   // Run the lookup before we delete the row!
-  $domain = domain_lookup($form_values['domain_id']);
-  db_query("DELETE FROM {domain} WHERE domain_id = %d", $form_values['domain_id']);
+  $domain = domain_lookup($form_state['values']['domain_id']);
+  db_query("DELETE FROM {domain} WHERE domain_id = %d", $form_state['values']['domain_id']);
   // Let other modules act.
-  module_invoke_all('domainupdate', 'delete', $domain, $form_values);
+  module_invoke_all('domainupdate', 'delete', $domain, $form_state['values']);
   drupal_set_message(t('Domain record deleted.'));
   // Remove domain-specific entries from the {node_access} table and clear the cache.
   db_query("DELETE FROM {node_access} WHERE realm = 'domain_id' AND gid = %d", $domain['domain_id']);
@@ -505,16 +463,6 @@
 }
 
 /**
- * Advanced node-type settings
- *
- * @ingroup domain 
- */
-function domain_advanced() {
-  $node_types = node_get_types('names');
-  return drupal_get_form('domain_advanced_form', $node_types);  
-}
-
-/**
  * FormsAPI
  *
  * @param $node_types
@@ -522,8 +470,8 @@
  *
  * @ingroup domain 
  */
-function domain_advanced_form($node_types) {
-  $form = array();
+function domain_advanced_form() {
+  $node_types = node_get_types('names');
   // Some editors will not have full node editing permissions.  This allows us
   // to give selected permissions for nodes within the editor's domain.
   if (variable_get('domain_editors', DOMAIN_EDITOR_RULE) == 1) {
