# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /var/www/html/zabbix/branches/3.0/frontends
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: php/include/classes/api/CApiService.php
--- php/include/classes/api/CApiService.php Base (BASE)
+++ php/include/classes/api/CApiService.php Locally Modified (Based On LOCAL)
@@ -419,6 +419,18 @@
 	 */
 	protected function createSelectQueryFromParts(array $sqlParts) {
 		// build query
+		$sql_left_join = '';
+		if (array_key_exists('left_join', $sqlParts)) {
+			foreach ($sqlParts['left_join'] as $join) {
+				$sql_left_join .= ' LEFT JOIN '.$join['from'].' ON '.$join['on'];
+			}
+
+			// Moving a left table to the end.
+			$left_table = $sqlParts['from'][$sqlParts['left_table']];
+			unset($sqlParts['from'][$sqlParts['left_table']]);
+			$sqlParts['from'][$sqlParts['left_table']] = $left_table;
+		}
+
 		$sqlSelect = implode(',', array_unique($sqlParts['select']));
 		$sqlFrom = implode(',', array_unique($sqlParts['from']));
 		$sqlWhere = empty($sqlParts['where']) ? '' : ' WHERE '.implode(' AND ', array_unique($sqlParts['where']));
@@ -427,6 +439,7 @@
 
 		return 'SELECT '.zbx_db_distinct($sqlParts).' '.$sqlSelect.
 				' FROM '.$sqlFrom.
+				$sql_left_join.
 				$sqlWhere.
 				$sqlGroup.
 				$sqlOrder;
Index: php/include/classes/api/services/CGraph.php
--- php/include/classes/api/services/CGraph.php Base (BASE)
+++ php/include/classes/api/services/CGraph.php Locally Modified (Based On LOCAL)
@@ -103,23 +103,30 @@
 			$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
 			$userGroups = getUserGroupsByUserId(self::$userData['userid']);
 
-			// check permissions by graph items
-			$sqlParts['where'][] = 'NOT EXISTS ('.
-				'SELECT NULL'.
-				' FROM graphs_items gi,items i,hosts_groups hgg'.
+			// Check permissions by graph item represented host.
+			// Select unavailable graphs.
+			$sqlParts['left_join'][] = [
+				'from' => '('.
+					'SELECT gi.graphid'.
+					' FROM graphs_items gi, items i, hosts_groups hgg'.
 					' LEFT JOIN rights r'.
 						' ON r.id=hgg.groupid'.
 							' AND '.dbConditionInt('r.groupid', $userGroups).
-				' WHERE g.graphid=gi.graphid'.
-					' AND gi.itemid=i.itemid'.
+					' WHERE gi.itemid=i.itemid'.
 					' AND i.hostid=hgg.hostid'.
-				' GROUP BY i.hostid'.
+				' GROUP BY i.hostid, gi.graphid'.
 				' HAVING MAX(permission)<'.zbx_dbstr($permission).
 					' OR MIN(permission) IS NULL'.
 					' OR MIN(permission)='.PERM_DENY.
-				')';
+					') unavailable',
+				'on' => 'g.graphid= unavailable.graphid'
+			];
+
+			$sqlParts['left_table'] = 'graphs';
+			$sqlParts['where']['unavailable_is_NULL'] = 'unavailable.graphid IS NULL';
+
 			// check permissions by Y min item
-			$sqlParts['where'][] = 'NOT EXISTS ('.
+			$sqlParts['where'][] = '(g.ymin_itemid IS NULL OR NOT EXISTS ('.
 				'SELECT NULL'.
 				' FROM items i,hosts_groups hgg'.
 					' LEFT JOIN rights r'.
@@ -132,9 +139,9 @@
 				' HAVING MAX(permission)<'.zbx_dbstr($permission).
 					' OR MIN(permission) IS NULL'.
 					' OR MIN(permission)='.PERM_DENY.
-				')';
+				'))';
 			// check permissions by Y max item
-			$sqlParts['where'][] = 'NOT EXISTS ('.
+			$sqlParts['where'][] = '(g.ymax_itemid IS NULL OR NOT EXISTS ('.
 				'SELECT NULL'.
 				' FROM items i,hosts_groups hgg'.
 					' LEFT JOIN rights r'.
@@ -147,7 +154,7 @@
 				' HAVING MAX(permission)<'.zbx_dbstr($permission).
 					' OR MIN(permission) IS NULL'.
 					' OR MIN(permission)='.PERM_DENY.
-				')';
+				'))';
 		}
 
 		// groupids
@@ -222,7 +229,7 @@
 			$sqlParts['from']['items'] = 'items i';
 			$sqlParts['from']['hosts'] = 'hosts h';
 			$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
-			$sqlParts['where']['ggi'] = 'g.graphid=gi.graphid';
+			$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
 			$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
 
 			if ($options['templated']) {
