Index: modules/simple_access/simple_access.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simple_access/simple_access.module,v
retrieving revision 1.17.2.4
diff -u -r1.17.2.4 simple_access.module
--- modules/simple_access/simple_access.module	23 Jul 2006 12:35:20 -0000	1.17.2.4
+++ modules/simple_access/simple_access.module	17 Oct 2006 05:09:52 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: simple_access.module,v 1.17.2.4 2006/07/23 12:35:20 gordon Exp $
+// $Id: simple_access.module,v 1.17.2.3 2006/06/27 14:14:49 gordon Exp $
 
 
 /**
@@ -67,6 +67,7 @@
  */
 function simple_access_node_grants($account, $op) {
   $grants = array();
+
   switch ($op) {
     case 'view':
       if (user_access('access content', $account)) {
@@ -77,7 +78,8 @@
       if (isset($account->roles)) {
         $grants = array_merge( $grants, simple_access_groups_from_roles( array_keys($account->roles) ));
       }
-    return array('simple_access' => $grants);
+
+    return array('simple_access' => $grants, 'simple_access_owner' => array($account->uid) );
   }
 }
 
@@ -90,6 +92,7 @@
     case 'delete':
       // When a node is deleted, delete any relevant grants.
       db_query('DELETE FROM {node_access} WHERE nid = %d AND realm = \'simple_access\'', $node->nid);
+      db_query('DELETE FROM {node_access} WHERE nid = %d AND realm = \'simple_access_owner\'', $node->uid);
       break;
     case 'insert':
     case 'update':
@@ -98,6 +101,7 @@
       if (user_access('assign access to nodes')) {
         // Clear out any existing grants for the node. Don't worry, we'll set them again.
         db_query('DELETE FROM {node_access} WHERE nid = %d AND realm = \'simple_access\'', $node->nid);
+        db_query('DELETE FROM {node_access} WHERE nid = %d AND realm = \'simple_access_owner\'', $node->uid);
         $views = FALSE;
         // loop through simple_access arrays from page submission
         // $type is either 'view', 'update', or 'delete'
@@ -125,10 +129,16 @@
           $grants[0]['delete'] = 0;
         }
 
+
+
         // this next line is wrong! Where is $gid coming from?
         foreach($grants as $gid => $gidgrants) {
           db_query("INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, 'simple_access', %d, %d, %d)", $node->nid, $gid, $gidgrants['view'], $gidgrants['update'], $gidgrants['delete']);
         }
+
+        if ($views) {
+          db_query("INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, 'simple_access_owner', 1, 1, 1)", $node->nid, $node->uid);
+        }
       }
       else {
         // the user is not an administrator
@@ -193,7 +203,7 @@
       $count = count($variable) ? count($variable) : 1;
       $percent = 90/$count;
 
-      $options = simple_access_group_select(user_access('administer nodes'));
+      $options = simple_access_group_select(user_access('administer nodes')||variable_get('sa_showgroups',0));
 
       // this is the only stuff that changes for each
       // so we put it all in one place for easy editing
@@ -379,6 +389,7 @@
   drupal_set_title(t('Simple Access Settings'));
   if ($_POST['op'] == t('Save Options')) {
     variable_set('sa_display', array_keys($_POST['edit']['sa_display']));
+    variable_set('sa_showgroups', $_POST['edit']['sa_showgroups']);
     drupal_set_message(t('Options saved'));
   }
   $options = array(
@@ -394,6 +405,12 @@
     '#description' => t('Which options should appear on node add/edit pages for administrators? Select at least one.'),
     '#required' => TRUE
   );
+  $form['sa_showgroups'] = array(
+    '#type' => 'checkbox',
+    '#title' => 'Show groups even when user is not a member.',
+    '#default_value' => variable_get('sa_showgroups',0),
+    '#description' => 'User and selected groups will be able to view',
+    );
   $form['op'] = array(
     '#type' => 'submit',
     '#value' => t('Save Options')
@@ -563,7 +580,7 @@
 
 function simple_access_save_group($edit) {
   if (!$edit['gid']) {
-    $edit['gid'] = db_next_id('{simple_access_groups}_gid');
+    $edit['gid'] = db_next_id('{simple_access}_gid');
   }
   db_query('DELETE FROM {simple_access_roles} WHERE gid = %d', $edit['gid']);
   db_query('DELETE FROM {simple_access_groups} WHERE gid = %d', $edit['gid']);
@@ -588,7 +605,7 @@
 function simple_access_initialize($initialize = TRUE) {
   if ($initialize) {
     // delete universal view grant
-    db_query("DELETE FROM {node_access} WHERE nid = 0 AND realm = 'all'");
+    db_query('DELETE FROM {node_access} WHERE nid = 0 AND realm = "all"');
     // set all nodes to viewable
     db_query("INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) SELECT nid, 0, 'simple_access', 1, 0, 0 FROM {node}");
     variable_set('simple_access_active', TRUE);
@@ -596,9 +613,9 @@
   }
   else {
     // delete all simple_access stuff
-    db_query("DELETE FROM {node_access} WHERE realm = 'simple_access'");
+    db_query('DELETE FROM {node_access} WHERE realm = "simple_access"');
     // re-enable universal view grant
-    db_query("INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (0, 0, 'all', 1, 0, 0)");
+    db_query('INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (0, 0, "all", 1, 0, 0)');
     variable_set('simple_access_active', FALSE);
     drupal_set_message(t('The database has been re-configured. You should now visit %modules to disable the simple_access module itself.', array('%modules' => l('the modules page', 'admin/modules'))));
   }
@@ -615,18 +632,18 @@
     case 'edit' :
       drupal_set_title(t('Items With Edit Access Set'));
       $output = '<div>'.t('These nodes have been set as "additionally editable by" certain Simple Access <a href="$url">groups</a>. ', array('%url' => url('admin/access/simple_access'))).'</div><br />';
-      $sql = "SELECT DISTINCT n.title, na.nid FROM {node} n INNER JOIN {node_access} na ON n.nid = na.nid WHERE na.realm='simple_access' AND na.gid > 0 AND na.grant_update = 1";
+      $sql = 'SELECT DISTINCT n.title, na.nid FROM {node} n INNER JOIN {node_access} na ON n.nid = na.nid WHERE na.realm="simple_access" AND na.gid > 0 AND na.grant_update = 1';
       break;
     case 'delete' :
       drupal_set_title(t('Items With Delete Access Set'));
       $output = '<div>'.t('These nodes have been set as "additionally deletable by" certain Simple Access <a href="%url">groups</a>. ', array('%url' => url('admin/access/simple_access'))).'</div><br />';
-      $sql = "SELECT DISTINCT n.title, na.nid FROM {node} n INNER JOIN {node_access} na ON n.nid = na.nid WHERE na.realm='simple_access' AND na.gid > 0 AND na.grant_delete = 1";
+      $sql = 'SELECT DISTINCT n.title, na.nid FROM {node} n INNER JOIN {node_access} na ON n.nid = na.nid WHERE na.realm="simple_access" AND na.gid > 0 AND na.grant_delete = 1';
       break;
     case 'view' :
     default :
       drupal_set_title(t('Items With View Access Set'));
       $output = '<div>'.t('These nodes have been set as "only viewable by" certain Simple Access <a href="%url">groups</a>.', array('%url' => url('admin/access/simple_access'))).'</div><br />';
-      $sql = "SELECT DISTINCT n.title, na.nid FROM {node} n INNER JOIN {node_access} na ON n.nid = na.nid WHERE na.realm='simple_access' AND na.gid > 0 AND na.grant_view = 1";
+      $sql = 'SELECT DISTINCT n.title, na.nid FROM {node} n INNER JOIN {node_access} na ON n.nid = na.nid WHERE na.realm="simple_access" AND na.gid > 0 AND na.grant_view = 1';
       break;
   }
   $header = array(
