===================================================================
--- include/screens.inc.php	(revision 10407)
+++ include/screens.inc.php	(working copy)
@@ -506,14 +506,18 @@
 			if($resourceid > 0){
 				$result = DBselect('SELECT DISTINCT g.graphid,g.name,n.name as node_name, h.host'.
 						' FROM graphs g '.
-							' LEFT JOIN graphs_items gi ON g.graphid=gi.graphid '.
-							' LEFT JOIN items i ON gi.itemid=i.itemid '.
-							' LEFT JOIN hosts h ON h.hostid=i.hostid '.
+							' JOIN graphs_items gi ON g.graphid=gi.graphid '.
+							' JOIN items i ON gi.itemid=i.itemid '.
+							' JOIN hosts h ON h.hostid=i.hostid '.
 							' LEFT JOIN nodes n ON n.nodeid='.DBid2nodeid('g.graphid').
 						' WHERE g.graphid='.$resourceid);
 
 				while($row=DBfetch($result)){
+					$row['name'] = get_header_substitude_macros($row['name'], $row['graphid']);
+
 					$row['node_name'] = isset($row['node_name']) ? '('.$row['node_name'].') ' : '';
+
+
 					$caption = $row['node_name'].$row['host'].':'.$row['name'];
 					$id = $resourceid;
 				}
Index: include/graphs.inc.php
===================================================================
--- include/graphs.inc.php	(revision 10407)
+++ include/graphs.inc.php	(working copy)
@@ -1,4 +1,4 @@
-<?php
+<?php                                 
 /*
 ** ZABBIX
 ** Copyright (C) 2000-2005 SIA Zabbix
@@ -1071,8 +1071,85 @@
 	return prepare_url($gurl);
 	}
 
+	
 /*
  * Function:
+ *              get_header_substitude_macros
+ *
+ * Description:
+ *     Replace macros hosts and global levels in string by graphid
+ *
+ * Author:
+ *     DotNeft
+ *
+ * Comments
+ *
+ */
+	function get_header_substitude_macros($str, $graphid) {
+            if (!zbx_strstr($str, '{$'))
+                return $str;
+
+	    $hosts = CHost::get(array('graphids' => $graphid));
+
+	    // replace in string macros names
+	    foreach($hosts as $hostid => $host){
+		$macros = CUserMacro::get(array('extendoutput' => 0, 'hostids' => $host['hostid']));
+
+            	foreach($macros as $macroid => $macro){
+		    $str = str_replace($macro['macro'], $macro['value'], $str);
+		    
+		    if (!zbx_strstr($str, '{$'))
+            		return $str;
+		}
+    
+            }
+
+	    // trying get templateid by hostid
+            $options = array(
+			'output' => API_OUTPUT_EXTEND,
+                       'select_templates' => API_OUTPUT_EXTEND,
+			'graphids' => $graphid
+	                );
+
+	    $templated_graphs = CGraph::get($options);
+
+	    foreach ($templated_graphs as $templated_graphid => $templated_graph) {
+                $options = array(
+                    	    'select_templates' => 1,
+			    'graphids' => $templated_graph['templateid']
+                    	    );
+
+	        $templates = CTemplate::get($options);
+            
+		foreach($templates as $templateid => $template){
+		    // replace in string macros names
+            	    $macros = CUserMacro::get(array('extendoutput' => 0, 'hostids' => $template['hostid']));
+
+            	    foreach($macros as $macroid => $macro){
+                	$str = str_replace($macro['macro'], $macro['value'], $str);
+
+                	if (!zbx_strstr($str, '{$'))
+                    	    return $str;
+            	    }
+
+		}
+	    }
+
+	    // getting globalmacro
+            $macros = CUserMacro::get(array('extendoutput' => 0, 'globalmacro' => 1));
+
+	    // replace in string macros names
+            foreach($macros as $macroid => $macro){
+                $str = str_replace($macro['macro'], $macro['value'], $str);
+
+                if (!zbx_strstr($str, '{$'))
+                    return $str;
+            }
+
+        return $str;
+	}
+/*
+ * Function:
  *		make_array_from_graphid
  *
  * Description:
Index: popup.php
===================================================================
--- popup.php	(revision 10407)
+++ popup.php	(working copy)
@@ -1064,6 +1064,8 @@
 			$row['node_name'] = get_node_name_by_elid($row['graphid'], null, ': ');
 			$name = $row['node_name'].$row['host'].':'.$row['name'];
 
+			$row['name'] = get_header_substitude_macros($row['name'], $row['graphid']);
+
 			$description = new CLink($row['name'],'#');
 			if(isset($_REQUEST['reference']) && ($_REQUEST['reference'] =='dashboard')){
 				$action = get_window_opener($dstfrm, $dstfld1, $srcfld2).
Index: chart2.php
===================================================================
--- chart2.php	(revision 10407)
+++ chart2.php	(working copy)
@@ -72,6 +72,9 @@
 	if(id2nodeid($db_data['graphid']) != get_current_nodeid()){
 		$chart_header = get_node_name_by_elid($db_data['graphid'], true, ': ');
 	}
+
+	$db_data['name'] = get_header_substitude_macros($db_data['name'], $db_data['graphid']);
+
 	$chart_header.= $host['host'].': '.$db_data['name'];
 
 
Index: charts.php
===================================================================
--- charts.php	(revision 10407)
+++ charts.php	(working copy)
@@ -170,6 +170,9 @@
 		}
 
 		$db_data = reset($db_data);
+
+		$db_data['name'] = get_header_substitude_macros($db_data['name'], $_REQUEST['graphid']);
+
 		array_push($h1, $db_data['name']);
 	}
 	else{
@@ -217,6 +220,8 @@
 	$db_graphs = CGraph::get($options);
 	order_result($db_graphs, 'name');
 	foreach($db_graphs as $num => $db_graph){
+		$db_graph['name'] = get_header_substitude_macros($db_graph['name'], $db_graph['graphid']);
+
 		$cmbGraphs->addItem($db_graph['graphid'], get_node_name_by_elid($db_graph['graphid'], null, ': ').$db_graph['name']);
 	}
 
Index: graphs.php
===================================================================
--- graphs.php	(revision 10407)
+++ graphs.php	(working copy)
@@ -570,6 +570,8 @@
 				$host_list = implode(', ', $host_list);
 			}
 
+			$graph['name'] = get_header_substitude_macros($graph['name'], $graphid);
+
 			$name = array();
 			if($graph['templateid'] != 0){
 				$real_hosts = get_realhosts_by_graphid($graph['templateid']);
