Index: domain.info
===================================================================
--- domain.info	(revision 3076)
+++ 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 3076)
+++ 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 3106)
+++ domain.module	(working copy)
@@ -60,73 +60,73 @@
  *
  * @ingroup drupal
  */
-function domain_menu($may_cache) {
+function domain_menu() {
   $items = array();
   $admin = user_access('administer domains');
-  if ($may_cache) {
-    $items[] = array(
-      'title' => t('Domains'),
-      '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('Domains'),
+    '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 +311,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 +495,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;
 }
 
@@ -550,7 +551,13 @@
       $node->editors = array();
       $node->domain_site = FALSE;
       $node->url = 'test';
-      $result = db_query("SELECT gid, realm, grant_view, grant_update, grant_delete FROM {node_access} WHERE nid = %d AND (realm = '%s' OR realm = '%s' OR realm = '%s')", $node->nid, 'domain_id', 'domain_site', 'domain_editor');
+      if(isset($node->nid)){
+      	$nid = $node->nid;
+      }
+      else{
+      	$nid = -1;
+      }
+      $result = db_query("SELECT gid, realm, grant_view, grant_update, grant_delete FROM {node_access} WHERE nid = %d AND (realm = '%s' OR realm = '%s' OR realm = '%s')", $nid, 'domain_id', 'domain_site', 'domain_editor');
       while ($data = db_fetch_object($result)) {
         // Transform the 0 to -1, since {node_access} is unsigned.
         ($data->gid == 0) ? $gid = -1 : $gid = $data->gid;
@@ -718,7 +725,7 @@
   $grants = array();
   
   // If the form is hidden, we are passed the 'domains_raw' variable.
-  if (is_array($node->domains_raw)) {
+  if (isset($node->domains_raw)&&is_array($node->domains_raw)) {
     $node->domains = array();
     foreach ($node->domains_raw as $value) {
       $node->domains[$value] = $value;
@@ -886,7 +893,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);
@@ -900,7 +907,7 @@
   }
 
   // Apply to all node editing forms, but make sure we are not on the CCK field configuration form.
-  if ($form['#id'] == 'node-form' && !$form['#node']->cck_dummy_node_form) {
+  if ($form['#id'] == 'node-form' && !isset($form['#node']->cck_dummy_node_form)) {
     global $_domain;
     // By default, the requesting domain is assigned.
     $default = array($_domain['domain_id']);
@@ -933,7 +940,7 @@
         '#title' => t('Send to all affiliates'),
         '#required' => FALSE,
         '#description' => t('Select if this content can be shown to all affiliates.  This setting will override the options below.'),
-        '#default_value' => ($form['#node']->nid) ? $form['#node']->domain_site : variable_get('domain_node_'. $form['#node']->type, $behavior),
+        '#default_value' => isset($form['#node']->nid) ? $form['#node']->domain_site : variable_get('domain_node_'. $form['#node']->type, $behavior),
       );    
       $form['domain']['domains'] = array(
         '#type' => 'checkboxes',
@@ -941,7 +948,7 @@
         '#options' => $options,
         '#required' => TRUE,
         '#description' => t('Select which affiliates can access this content.'),
-        '#default_value' => ($form['#node']->nid) ? $form['#node']->domains : $default,
+        '#default_value' => isset($form['#node']->nid) ? $form['#node']->domains : $default,
       );
     }
     else {
@@ -1075,5 +1082,9 @@
         cache_clear_all();
       }  
       break;
-  }  
-}  
\ No newline at end of file
+  }
+  menu_rebuild();
+  cache_clear_all('*', 'cache_page', TRUE);
+  // Also clear the menu cache.
+  cache_clear_all('*','cache_menu', TRUE);
+}  
Index: domain_admin.inc
===================================================================
--- domain_admin.inc	(revision 3106)
+++ domain_admin.inc	(working copy)
@@ -26,7 +26,7 @@
     array('data' => t('Id'), 'field' => 'd.domain_id'),
     array('data' => t('Domain'), 'field' => 'd.subdomain'),
     array('data' => t('Site name'), 'field' => 'd.sitename'),
-    array('data' => t('Status'), 'field' => 'd.valid'),
+    array('data' => t('Status'), 'field' => 'd.valid','colspan' => 3),
     array('data' => t('Scheme'), 'field' => 'd.scheme'), 
   );  
   // Get header elements from other modules
@@ -89,6 +89,7 @@
     $row[] = $actions;
     $rows[] = $row;
   }
+  
   if (!empty($rows)) {
     $output .= theme_table($header, $rows);
     $output .= theme('pager', NULL, 24, 0); 
@@ -100,25 +101,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'),
@@ -258,15 +249,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
@@ -279,8 +261,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)) {
@@ -332,15 +314,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.'));
   }  
@@ -351,35 +333,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
@@ -387,8 +353,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'),
@@ -438,14 +409,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.'));
   }  
@@ -456,29 +427,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
@@ -486,8 +444,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 />');
@@ -500,12 +458,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.'));
   // Some tortured logic to return to the root domain and the domain list.
   $default = domain_default();
@@ -518,16 +476,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
@@ -535,8 +483,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) {
