--- ./patched_release/dbfm.module	2009-04-06 14:08:39.000000000 +0100
+++ dbfm.module	2009-04-06 14:10:41.000000000 +0100
@@ -4022,18 +4022,30 @@ function theme_dbfm_textarea_link($eleme
 
 // function to deal with inserting permissions to dbfm_perm table
 // calls insert_perms
-// function to deal with inserting permissions to dbfm_perm table
-// calls insert_perms
 //**** we may have to do something about sorting the arrays? and provide some error checking ******/////
 //function returns true if changes were made, otherwise false
 function dbfm_add_perms($readorwrite, $fid, $form_values = array()) {
   $changes = false;
-  
+
+  //NOW we could just check whether or not the organic groups module is installed BUT it could have been installed without any groups being
+  //configured - so
+  $groupsql = "SELECT nid, title FROM {node} WHERE type = '" . variable_get(dbfm_node_grp, "group") . "' ORDER BY title";
+  $queryResult = db_query($groupsql);
+  $numret = db_num_rows($queryResult);
+  if ($numret == 0) {
+    $nogroups = true;
+  }
+  else {
+    $nogroups = false;
+  }
+
   //are we checking read or write
   if ($readorwrite == 'read') {
     //compare the arrays before and after
     $diff1 = array_diff($form_values['rrole'], getpermarr($fid, ROLE_RO));
-    $diff2 = array_diff($form_values['rgroup'], getpermarr($fid, GROUP_RO));
+    if ($nogroups == FALSE) {
+      $diff2 = array_diff($form_values['rgroup'], getpermarr($fid, GROUP_RO));
+    }
 
     if (count($diff1) > 0) {
       //roles have changed
@@ -4045,26 +4057,29 @@ function dbfm_add_perms($readorwrite, $f
       }
       $changes = true;
     }
-    if (count($diff2) > 0) {
-      //groups have changed
-      // remove what was in the table, and update with new values
-      $delquery = sprintf("DELETE FROM {dbfm_perm} WHERE fid = %d AND rgaccess = %d", $fid, GROUP_RO);
-      $result = db_query($delquery);
-      foreach ( $form_values['rgroup'] as $wgroup) {
-        $perms_result = insert_perms( $fid, GROUP_RO, $wgroup );
+    if ($nogroups == FALSE) {
+      if (count($diff2) > 0) {
+        //groups have changed
+        // remove what was in the table, and update with new values
+        $delquery = sprintf("DELETE FROM {dbfm_perm} WHERE fid = %d AND rgaccess = %d", $fid, GROUP_RO);
+        $result = db_query($delquery);
+        foreach ( $form_values['rgroup'] as $wgroup) {
+          $perms_result = insert_perms( $fid, GROUP_RO, $wgroup );
+        }
+        $changes = true;
       }
-      $changes = true;
     }
   }
   else {
-  
     //this is the write permissions bit
     //compare the arrays before and after
     $diff1 = array_diff($form_values['wrole'], getpermarr($fid, ROLE_RW));
     $diff3 = array_diff(getpermarr($fid, ROLE_RW), $form_values['wrole']);
-    
-    $diff2 = array_diff($form_values['wgroup'], getpermarr($fid, GROUP_RW));
-    $diff4 = array_diff(getpermarr($fid, GROUP_RW), $form_values['wgroup']);
+
+    if ($nogroups == FALSE) {
+      $diff2 = array_diff($form_values['wgroup'], getpermarr($fid, GROUP_RW));
+      $diff4 = array_diff(getpermarr($fid, GROUP_RW), $form_values['wgroup']);
+    }
 
     if ((count($diff1) + count($diff3)) > 0) {
       //roles have changed
@@ -4076,15 +4091,18 @@ function dbfm_add_perms($readorwrite, $f
       }
       $changes = true;
     }
-    if ((count($diff2) + count($diff4)) > 0) {
-      //groups have changed
-      // remove what was in the table, and update with new values
-      $delquery = sprintf("DELETE FROM {dbfm_perm} WHERE fid = %d AND rgaccess = %d", $fid, GROUP_RW);
-      $result = db_query($delquery);
-      foreach ( $form_values['wgroup'] as $wgroup) {
-        $perms_result = insert_perms( $fid, GROUP_RW, $wgroup );
+
+    if ($nogroups == FALSE) {
+      if ((count($diff2) + count($diff4)) > 0) {
+        //groups have changed
+        // remove what was in the table, and update with new values
+        $delquery = sprintf("DELETE FROM {dbfm_perm} WHERE fid = %d AND rgaccess = %d", $fid, GROUP_RW);
+        $result = db_query($delquery);
+        foreach ( $form_values['wgroup'] as $wgroup) {
+          $perms_result = insert_perms( $fid, GROUP_RW, $wgroup );
+        }
+        $changes = true;
       }
-      $changes = true;
     }
   }
   return $changes;
