=== modified file 'modules/og_content_type_admin/og_content_type_admin.module'
--- modules/og_content_type_admin/og_content_type_admin.module	2009-08-17 12:15:06 +0000
+++ modules/og_content_type_admin/og_content_type_admin.module	2009-08-21 11:23:42 +0000
@@ -68,15 +68,6 @@
 } // function og_content_type_admin_help()
 
 /**
- * Implementation of hook_init().
- */
-function og_content_type_admin_init() {
-  menu_router_build(TRUE);
-  node_types_rebuild();	
-}
-
-
-/**
  * Implementation of hook_perm
  *
  * Valid permissions for this module
@@ -246,7 +237,7 @@
   $form_values = $form_state['values']; 
   if ($form_values['op'] == t('Add group')) {
     $all_groups = og_all_groups_options();
-    db_query("INSERT INTO {og_content_type_admin} (gid, name) VALUES (%d, '%s')", $form_values['group'], $all_groups[$form_values['group']]);
+    db_query("INSERT INTO {og_content_type_admin} (gid, name, types_allowed, types_active) VALUES (%d, '%s', '', '')", $form_values['group'], $all_groups[$form_values['group']]);
     drupal_set_message(t('The group has been added.'));
   }
   $form_state['redirect'] = 'admin/og/og_content_types';
@@ -758,14 +749,18 @@
  */
 function og_content_type_admin_menu_alter(&$callbacks) {
   global $user;
-  $post_type = arg(2); 
-  // First: Deny access to all content types and handle all create content pages.
+  // First: Replace access callback to all content types and handle all create content pages.
   $types = node_get_types();
   foreach ($types as $type) {
   	$type = $type->type; 
   	$node_type = isset($type) ? str_replace('_', '-', $type) : NULL; 
     $type_path = "node/add/$node_type"; 
-    $callbacks[$type_path]['access callback'] = FALSE;
+    $old_callback = $callbacks[$type_path]['access callback'];
+    $old_args = $callbacks[$type_path]['access arguments'];
+    array_unshift($old_args, $old_callback);
+    array_unshift($old_args, 2); // we need to get node type for our own processing
+    $callbacks[$type_path]['access callback'] = 'og_content_type_admin_menu_access';
+    $callbacks[$type_path]['access arguments'] = $old_args; // pass original callback and its arguments as parameters
     $callbacks[$type_path]['page callback'] = 'og_content_type_admin_node_add';
   } 
   /*TODO: Would something like the below work above ? 
@@ -773,36 +768,40 @@
    *$callbacks[]['page callback'] = 'og_content_type_admin_node_add';
    */
   $callbacks['node/add']['page callback'] = 'og_content_type_admin_node_add'; 
-  // Second: Allow access to add a particlar type of group content 
-  if (is_array($_GET[gids])) {  
-    $gid = $_GET[gids][0]; 
+  node_types_rebuild(); // moved from init function. Do we really need it?
+}
+
+/**
+ * mnode/add access callback override. If gid is present check og_content_type access rights. Otherwise pass processing to original function
+ */
+function og_content_type_admin_menu_access() {
+  $args = func_get_args();
+  $type = array_shift($args);
+  $original_callback = array_shift($args);
+  
+  // First: Allow access to add a particlar type of group content 
+  if (is_array($_GET['gids'])) {  
+    $gid = $_GET['gids'][0]; 
     $sql = "SELECT octa.types_active, octa.types_allowed FROM {og_content_type_admin} octa WHERE octa.gid = %d";
-      //if we're keeping track of this group, get it's active types, otherwise, get the defaults
-      $types = db_fetch_object(db_query($sql, $node->nid)); // TODO: Should this be $gid ?
-      if (!count($types->types_active)) {  
-        $types = db_fetch_object(db_query($sql, 0));
-      } 
-      $activated_types = unserialize($types->types_active); 
-      foreach ($activated_types as $type => $value) {
-         $node_type = isset($type) ? str_replace('_', '-', $type) : NULL; 
-         if ($node_type == $post_type) {
-           $type_path = "node/add/$node_type"; 
-           $callbacks[$type_path]['access callback'] = TRUE;
-         }	
-      }	
-  }  
-  // Third: Allow access to site wide content ..  
-  //TODO: Shouldn't this be in a an else block
-  $sql = "SELECT octa.types_active FROM {og_content_type_admin} octa WHERE octa.gid = -1";  
-  $types = db_fetch_object(db_query($sql));
-  $activated_types = unserialize($types->types_active);     
-  foreach ($activated_types as $type => $value) { 
-  	$node_type = isset($type) ? str_replace('_', '-', $type) : NULL; 
-    $type_path = "node/add/$node_type";
-    if ($activated_types[$type] && node_access('create', $type)) {  
-       $callbacks[$type_path]['access callback'] = TRUE;	
-    }
-  } 
+    //if we're keeping track of this group, get it's active types, otherwise, get the defaults
+    $types = db_fetch_object(db_query($sql, $gid)); // TODO: Should this be $gid ?
+    if (!$types) {  
+      $types = db_fetch_object(db_query($sql, 0));
+    } 
+    $active_types = unserialize($types->types_active);
+    if ($active_types[$type] && call_user_func_array($original_callback, $args)) {
+      return TRUE;
+    }	
+  }
+  else { // do normal processing plus 'allowed' check
+    $sql = "SELECT octa.types_allowed FROM {og_content_type_admin} octa WHERE octa.gid = -1";  
+    $types = db_fetch_object(db_query($sql));
+    $allowed_types = unserialize($types->types_allowed);     
+    if ($allowed_types[$type] && call_user_func_array($original_callback, $args)) {  
+      return TRUE;
+    }   
+  }
+  return FALSE;
 }
 

