inc/toolkit.inc.php
changeset 37 b785e54690ce
parent 32 0c2497c1ac01
child 47 ae140472d97c
--- a/inc/toolkit.inc.php	Mon Jul 02 23:01:18 2007 +0000
+++ b/inc/toolkit.inc.php	Tue Jul 10 21:24:06 2007 +0000
@@ -136,7 +136,20 @@
         WHERE 1";
         if((!level(5) || !$userid) && !level(10) && !level(5))
         {
-                $sqlq .= " AND zones.owner=".$_SESSION["userid"];
+		// First select the zones for which we have ownership on one or more records.
+		$query = 'SELECT records.domain_id FROM records, record_owners WHERE user_id = '.$_SESSION['userid'].' AND records.id = record_owners.record_id';
+		$result = $db->query($query);
+		$zones = array();
+		if (!PEAR::isError($result)) {
+			$zones = $result->fetchCol();
+		}
+	
+                $sqlq .= " AND (zones.owner=".$_SESSION["userid"];
+		if (count($zones) > 0) {
+			$sqlq .= ' OR zones.domain_id IN ('.implode(',', $zones).') '; 
+
+		}
+		$sqlq .= ')';
         }
         $sqlq .= " AND substring(domains.name,1,1) REGEXP '^".$letter."' LIMIT 1";
         $result = $db->query($sqlq);