--- sql.php.orig	2009-05-01 06:12:36.000000000 -0400
+++ sql.php	2009-11-17 17:37:41.000000000 -0500
@@ -3,7 +3,7 @@
  * Horde_Share_sql:: provides the sql backend for the horde share
  * driver.
  *
- * $Horde: framework/Share/Share/sql.php,v 1.1.2.56 2009/04/20 21:04:35 jan Exp $
+ * $Horde: framework/Share/Share/sql.php,v 1.1.2.57 2009/08/12 13:52:00 jan Exp $
  *
  * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
  *
@@ -669,33 +669,37 @@
             $where .= 's.share_owner = ' . $this->_write_db->quote($userid);
 
             // (name == perm_creator and val & $perm)
-            $where .= ' OR (' . Horde_SQL::buildClause($this->_db, 's.perm_creator', '&', $perm) . ')';
+//            $where .= ' OR (' . Horde_SQL::buildClause($this->_db, 's.perm_creator', '&', $perm) . ')';
+// IVT hack: group viewable
+$where .= ' OR s.share_id IN(SELECT share_id FROM ' . $this->_table . '_groups WHERE group_uid IN (SELECT group_uid FROM horde_groups_members WHERE user_uid=\'' . $userid . '\') AND perm & ' . $perm . ' <> 0)';
 
             // (name == perm_creator and val & $perm)
-            $where .= ' OR (' . Horde_SQL::buildClause($this->_db, 's.perm_default',  '&', $perm) . ')';
+//            $where .= ' OR (' . Horde_SQL::buildClause($this->_db, 's.perm_default',  '&', $perm) . ')';
+// IVT hack: user assigned viewable
+$where .= ' OR s.share_id IN(SELECT s.share_id FROM '. $this->_table . ' s WHERE s.share_id IN (SELECT share_id FROM kronolith_shares_users WHERE user_uid=\'' . $userid . '\' AND perm & ' . $perm . ' <> 0))';
 
             // (name == perm_users and key == $userid and val & $perm)
-            $query .= ' LEFT JOIN ' . $this->_table . '_users AS u ON u.share_id = s.share_id';
-            $where .= ' OR ( u.user_uid = ' .  $this->_write_db->quote($userid)
-                . ' AND (' . Horde_SQL::buildClause($this->_db, 'u.perm', '&', $perm) . '))';
+//            $query .= ' LEFT JOIN ' . $this->_table . '_users AS u ON u.share_id = s.share_id';
+//            $where .= ' OR ( u.user_uid = ' .  $this->_write_db->quote($userid)
+//                . ' AND (' . Horde_SQL::buildClause($this->_db, 'u.perm', '&', $perm) . '))';
 
             // If the user has any group memberships, check for those also.
-            require_once 'Horde/Group.php';
-            $group = &Group::singleton();
-            $groups = $group->getGroupMemberships($userid, true);
-            if (!is_a($groups, 'PEAR_Error') && $groups) {
-                // (name == perm_groups and key in ($groups) and val & $perm)
-                $ids = array_keys($groups);
-                $group_ids = array();
-                foreach ($ids as $id) {
-                    $group_ids[] = $this->_db->quote($id);
-                }
-                $query .= ' LEFT JOIN ' . $this->_table . '_groups AS g ON g.share_id = s.share_id';
-                $where .= ' OR (g.group_uid IN (' . implode(',', $group_ids) . ')'
-                    . ' AND (' . Horde_SQL::buildClause($this->_db, 'g.perm', '&', $perm) . '))';
-            } elseif (is_a($groups, 'PEAR_Error')) {
-                Horde::logMessage($groups, __FILE__, __LINE__, PEAR_LOG_ERR);
-            }
+//            require_once 'Horde/Group.php';
+//            $group = &Group::singleton();
+//            $groups = $group->getGroupMemberships($userid, true);
+//            if (!is_a($groups, 'PEAR_Error') && $groups) {
+//                // (name == perm_groups and key in ($groups) and val & $perm)
+//                $ids = array_keys($groups);
+//               $group_ids = array();
+//                foreach ($ids as $id) {
+//                    $group_ids[] = $this->_db->quote($id);
+//                }
+//                $query .= ' LEFT JOIN ' . $this->_table . '_groups AS g ON g.share_id = s.share_id';
+//                $where .= ' OR (g.group_uid IN (' . implode(',', $group_ids) . ')'
+//                    . ' AND (' . Horde_SQL::buildClause($this->_db, 'g.perm', '&', $perm) . '))';
+//            } elseif (is_a($groups, 'PEAR_Error')) {
+//                Horde::logMessage($groups, __FILE__, __LINE__, PEAR_LOG_ERR);
+//            }
         } else {
             $where = '(' . Horde_SQL::buildClause($this->_db, 's.perm_guest', '&', $perm) . ')';
         }
@@ -751,7 +755,7 @@
         require_once 'MDB2.php';
         $params = $this->_params;
         unset($params['charset']);
-        $this->_write_db = MDB2::factory($params);
+        $this->_write_db = &MDB2::factory($params);
         if (is_a($this->_write_db, 'PEAR_Error')) {
             Horde::fatal($this->_write_db, __FILE__, __LINE__);
         }