--- og_access.module	2008-05-26 16:03:35.000000000 +0200
+++ og_access.module-mio	2008-08-04 18:50:44.000000000 +0200
@@ -151,11 +151,39 @@
     $form['og_nodeapi']['#collapsible'] = TRUE;
     $form['og_nodeapi']['#collapsed'] = $selected_groups ? TRUE : FALSE;
   }
-
+  
+ 	 /* ACL INTEGRATION */
+  if (module_exists('acl')) {
+     // This is disabled when there is no node passed.
+     if (module_exists('acl'))
+     {
+	     $form['acl'] = array(
+	       '#type' => 'fieldset', 
+	       '#tree' => TRUE,
+	       '#title' => 'ACL - Access control list',
+	     );
+	     foreach (array('view', 'update', 'delete') as $op) {
+	      if (isset($node->nid)){
+	        $acl_id = acl_get_id_by_name('og_access', $op .'_'. $node->nid);
+	        if (!$acl_id) {
+	          // Create one:
+	          $acl_id = acl_create_new_acl('og_access', $op .'_'. $node->nid);
+	          acl_node_add_acl($node->nid, $acl_id, $op == 'view', $op == 'update', $op == 'delete');
+	        }
+	          $form['acl'][$op] = acl_edit_form($acl_id, 'Grant '. $op .' access');
+	        }
+	        else{
+	          // new node don't have acl_id
+	          $form['acl'][$op] = acl_edit_form('og_access_new_node', 'Grant '. $op .' access', TRUE);   
+	        }
+	       $form['acl'][$op]['#collapsed'] = !isset($_POST['acl'][$op]['add_button']) && !isset($_POST['acl'][$op]['delete_button']); 
+	     }
+     }
+  }
   }
-
 }
 
+
 /**
  * Implementation of hook_form_alter().
  */
@@ -172,6 +200,8 @@
   }
 }
 
+
+
 /**
  * Implementation of hook_node_grants().
  */
@@ -192,6 +222,17 @@
       }
     }
   }
+  
+  /* ACL CHECK */
+  if (module_exists('acl'))
+  {
+	  $grants_acl = acl_node_grants($account,$op);
+	  if (is_array($grants_acl))
+	  {
+	  	$grants = array_merge($grants, $grants_acl);
+	  }  
+  }
+  
   return isset($grants) ? $grants : array();
 }
 
@@ -199,6 +240,7 @@
  * Implementation of hook_node_access_records.
  */
 function og_access_node_access_records($node) {
+//	var_dump($node); die;
   // don't write records if the node type is omitted or node is a group
   if (og_is_omitted_type($node->type)) {
     return;
@@ -238,6 +280,7 @@
     // Applies to non group nodes.
     if ($node->og_public) {
       $grants[] = array('realm' => 'og_public', 'gid' => 0, 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0);
+      
     }
     
     foreach ($node->og_groups as $gid) {
@@ -246,12 +289,28 @@
       // Normal subscribers just get update operation if node type is a wiki type.
       $is_wiki = og_is_wiki_type($node->type);
       $grants[] = array('realm' => 'og_subscriber', 'gid' => $gid, 'grant_view' => 1, 'grant_update' => $is_wiki, 'grant_delete' => 0);
+      
+      //$grants[] = array('realm' => 'acl', 'gid' => 0, 'grant_view' => 1, 'grant_update' => $is_wiki, 'grant_delete' => 0);  
     }
+   
+  /* ACL INTEGRATION */
+  if (module_exists('acl'))
+  {
+	  foreach (array('view', 'update', 'delete') as $op) 
+	  {
+		if (isset($node->acl[$op])) 
+		{
+	  	     $grants[] = array('realm' => 'acl', 'gid' => $node->acl[$op]['acl_id'], 'grant_view' => 1, 'grant_update' => $is_wiki, 'grant_delete' => 0);  
+	    }
+	  }
+  }
+
   }
 
   return $grants;
 }
 
+
 /**
  * Implementation of hook_node_access_explain.
  */
@@ -264,3 +323,24 @@
     return t('Members of !group_n may view this node.', array('!group_n' => l($node->title, "node/$row->gid")));
   }
 }
+
+/* Save ACL (non so dove altro mettere queste funzioni)..*/
+function og_access_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL)
+{
+	switch($op){
+    case 'submit':
+    	if (module_exists('acl'))
+    	{
+	    	foreach (array('view', 'update', 'delete') as $op) 
+			{
+		   		if (isset($node->acl[$op])) 
+		   		{
+	      			acl_save_form($node->acl[$op]);
+	    		}
+	  		}
+    	}
+	}
+}
+
+	
+
