--- /usr/share/zabbix/include/views/common.macros.php.orig	2013-10-12 15:51:49.000000000 +0200
+++ /usr/share/zabbix/include/views/common.macros.php	2013-11-03 21:13:47.000000000 +0100
@@ -22,7 +22,7 @@
 
 $macrosTable = new CTable(SPACE, 'formElementTable');
 $macrosTable->setAttribute('id', 'tbl_macros');
-$macrosTable->addRow(array(_('Macro'), SPACE, _('Value'), SPACE));
+$macrosTable->addRow(array(_('Macro'), SPACE, _('Host value'), SPACE));
 
 // fields
 $macros = array_values($this->data['macros']);
@@ -45,9 +45,49 @@
 
 	$row = array($text1, $span, $text2, $deleteButtonCell);
 	$macrosTable->addRow($row, 'form_row');
+	$host_macro_values[$macro['macro']] = $macro['value'];
+}
+
+if (!empty($this->data['macros_overview'])) {
+	$macrosOverviewTable = new CTable(SPACE, 'formElementTable');
+	$macrosOverviewTable->addRow(array(_('Macro'), SPACE, _('Global value'), SPACE, _('Template value')));
+
+	foreach ($this->data['macros_overview'] as $macro => $value) {
+		$text1 = new CTextBox(null, $macro, 21, 'yes', 255);
+		$text2 = new CTextBox(null, $value['global_value'], 21, 'yes', 255);
+		$text2->setAttribute('placeholder', '-');
+		$text3 = new CTextBox(null, $value['template_value'], 21, 'yes', 255);
+		$text3->setAttribute('placeholder', '-');
+		if (array_key_exists($macro, $host_macro_values)) {
+			$text1->setAttribute('title', _('Host macro').SPACE.RARR.SPACE.$host_macro_values[$macro]);
+			$text1->setAttribute('style','text-decoration:line-through');
+			$text2->setAttribute('placeholder', SPACE);
+			$text2->setAttribute('style','text-decoration:line-through');
+			$text2->setAttribute('title', _('Host macro').SPACE.RARR.SPACE.$host_macro_values[$macro]);
+			$text3->setAttribute('placeholder', SPACE);
+			$text3->setAttribute('style','text-decoration:line-through');
+			$text3->setAttribute('title', _('Host macro').SPACE.RARR.SPACE.$host_macro_values[$macro]);
+		}
+		if (!is_null($value['template_name'])) {
+			$templateLink = new CLink($value['template_name'], 'templates.php?form=update&templateid='.$value['template_id']);
+			$text3 = array($text3, ' &larr; ', $templateLink);
+		}
+		$span1 = new CSpan(RARR);
+		$span1->addStyle('vertical-align:top;');
+
+		$row = array($text1, $span1, $text2, $span1, $text3);
+		$macrosOverviewTable->addRow($row, 'form_row');
+	}
 }
 
 // buttons
+$macroViewRadioButton = array(
+        new CRadioButton('macro_view', 'host', null, 'macro_view_radio_host', true),
+        new CLabel(_('Host macros'), 'macro_view_radio_host'),
+        new CRadioButton('macro_view', 'inherited', null, 'macro_view_radio_inherited', false),
+        new CLabel(_('Inherited macros'), 'macro_view_radio_inherited')
+);
+
 $addButton = new CButton('macro_add', _('Add'), null, 'link_menu');
 
 $buttonColumn = new CCol($addButton);
@@ -61,6 +101,10 @@
 
 // form list
 $macrosFormList = new CFormList('macrosFormList');
-$macrosFormList->addRow($macrosTable);
+if (isset($macrosOverviewTable)) {
+	$macrosFormList->addRow(new CDiv($macroViewRadioButton, 'jqueryinputset'));
+	$macrosFormList->addRow(null, $macrosOverviewTable, true, 'macros_inherited');
+}
+$macrosFormList->addRow(null, $macrosTable, false, 'macros_host');
 
 return $macrosFormList;
--- /usr/share/zabbix/include/func.inc.php.orig	2013-10-15 11:25:56.000000000 +0200
+++ /usr/share/zabbix/include/func.inc.php	2013-10-29 17:23:38.000000000 +0100
@@ -1878,3 +1878,30 @@
 
 	return $str;
 }
+
+function get_macros_recursively($hostids) {
+	$macros = API::UserMacro()->get(array(
+		'hostids' => $hostids,
+		'output' => API_OUTPUT_EXTEND
+	));
+	$macros = order_macros($macros, 'hostid', ZBX_SORT_DOWN);
+
+	$templates = API::Template()->get(array(
+		'templateids' => $hostids,
+		'selectParentTemplates' => array('templateid'),
+		'output' => API_OUTPUT_SHORTEN
+	));
+	$templates = zbx_toHash($templates, 'templateid');
+
+	foreach ($templates as $template) {
+		$parents = isset($template['parentTemplates'])?$template['parentTemplates']:array();
+		foreach($parents as $parent) $parentids[] = $parent['templateid'];
+	}
+
+	if (!isset($parentids) || is_null($parentids)) {
+		return $macros;
+	} else {
+		$parent_macros = get_macros_recursively($parentids);
+		return array_merge($parent_macros, $macros);
+	}
+}
--- /usr/share/zabbix/include/views/configuration.template.edit.php.orig	2013-10-12 15:51:49.000000000 +0200
+++ /usr/share/zabbix/include/views/configuration.template.edit.php	2013-11-03 21:16:06.000000000 +0100
@@ -49,10 +49,45 @@
 
 	$frm_title .= SPACE.' ['.$dbTemplate['name'].']';
 
-	$original_templates = array();
+	$original_templates = $templateids = $macros_overview = array();
 	foreach ($dbTemplate['parentTemplates'] as $tnum => $tpl) {
 		$original_templates[$tpl['templateid']] = $tpl['name'];
+		$templateids[] = $tpl['templateid'];
+	}
+
+	$global_macros = API::UserMacro()->get(array(
+		'globalmacro' => true,
+		'output' => API_OUTPUT_EXTEND
+	));
+
+	foreach ($global_macros as $macro) {
+		$macros_overview[$macro['macro']]['global_value'] = $macro['value'];
+	}
+
+	$template_macros = get_macros_recursively($templateids);
+	$hostids = array();
+	foreach ($template_macros as $macro) $hostids[] = $macro['hostid'];
+
+	$macro_hosts = API::Host()->get(array(
+		'hostids' => array_unique($hostids),
+		'templated_hosts' => true,
+		'output' => array('name')
+	));
+	$macro_hosts = zbx_toHash($macro_hosts, 'hostid');
+
+	foreach ($template_macros as $macro) {
+		$macros_overview[$macro['macro']]['template_id'] = $macro['hostid'];
+		$macros_overview[$macro['macro']]['template_value'] = $macro['value'];
+		$macros_overview[$macro['macro']]['template_name'] = $macro_hosts[$macro['hostid']]['name'];
+	}
+
+	foreach ($macros_overview as $macro => $values) {
+		if (!array_key_exists('global_value', $values)) $values['global_value'] = null;
+		if (!array_key_exists('template_value', $values)) $values['template_value'] = null;
+		if (!array_key_exists('template_name', $values)) $values['template_name'] = null;
+		$macros_overview[$macro] = $values;
 	}
+	ksort($macros_overview);
 }
 else {
 	$original_templates = array();
@@ -422,7 +457,8 @@
 	$macros = array(array('macro' => '', 'value' => ''));
 }
 $macrosView = new CView('common.macros', array(
-	'macros' => $macros
+	'macros' => $macros,
+	'macros_overview' => $macros_overview
 ));
 $divTabs->addTab('macroTab', _('Macros'), $macrosView->render());
 
--- /usr/share/zabbix/include/views/configuration.host.edit.php.orig	2013-10-12 15:51:49.000000000 +0200
+++ /usr/share/zabbix/include/views/configuration.host.edit.php	2013-11-03 20:22:36.000000000 +0100
@@ -73,6 +73,45 @@
 	$original_templates = $dbHost['parentTemplates'];
 	$original_templates = zbx_toHash($original_templates, 'templateid');
 
+	$global_macros = API::UserMacro()->get(array(
+		'globalmacro' => true,
+		'output' => API_OUTPUT_EXTEND
+	));
+
+	$macros_overview = $templateids = array();
+	foreach ($global_macros as $macro) {
+		$macros_overview[$macro['macro']]['global_value'] = $macro['value'];
+	}
+
+	foreach ($original_templates as $tnum => $tpl) {
+		$templateids[] = $tpl['templateid'];
+	}
+
+	$template_macros = get_macros_recursively($templateids);
+	$hostids = array();
+	foreach ($template_macros as $macro) $hostids[] = $macro['hostid'];
+
+	$macro_hosts = API::Host()->get(array(
+		'hostids' => array_unique($hostids),
+		'templated_hosts' => true,
+		'output' => array('name')
+	));
+	$macro_hosts = zbx_toHash($macro_hosts, 'hostid');
+
+	foreach ($template_macros as $macro) {
+		$macros_overview[$macro['macro']]['template_id'] = $macro['hostid'];
+		$macros_overview[$macro['macro']]['template_value'] = $macro['value'];
+		$macros_overview[$macro['macro']]['template_name'] = $macro_hosts[$macro['hostid']]['name'];
+	}
+
+	foreach ($macros_overview as $macro => $values) {
+		if (!array_key_exists('global_value', $values)) $values['global_value'] = null;
+		if (!array_key_exists('template_value', $values)) $values['template_value'] = null;
+		if (!array_key_exists('template_name', $values)) $values['template_name'] = null;
+		$macros_overview[$macro] = $values;
+	}
+	ksort($macros_overview);
+
 	if (isset($_REQUEST['mainInterfaces'][INTERFACE_TYPE_AGENT])) {
 		$mainAgentId = $_REQUEST['mainInterfaces'][INTERFACE_TYPE_AGENT];
 		$interfaces[$mainAgentId]['main'] = '1';
@@ -550,7 +589,8 @@
 }
 
 $macrosView = new CView('common.macros', array(
-	'macros' => $macros
+	'macros' => $macros,
+	'macros_overview' => $macros_overview
 ));
 $divTabs->addTab('macroTab', _('Macros'), $macrosView->render());
 
--- /usr/share/zabbix/include/views/js/configuration.host.edit.macros.js.php.orig	2013-10-12 15:51:49.000000000 +0200
+++ /usr/share/zabbix/include/views/js/configuration.host.edit.macros.js.php	2013-11-03 16:08:45.000000000 +0100
@@ -26,4 +26,26 @@
 		}
 		$('userMacroFooter').insert({'before' : tpl.evaluate(userMacro)});
 	}
+	jQuery(document).ready(function() {
+		'use strict';
+
+		// radio button of macro views was clicked
+		jQuery('div.jqueryinputset input[name=macro_view]').click(function() {
+			// action depending on which button was clicked
+			var macroFields = jQuery('#macrosFormList:input');
+
+			switch (jQuery(this).val()) {
+				case '<?php echo "host"; ?>':
+					macroFields.prop('disabled', true);
+					jQuery('#macros_host').show();
+					jQuery('#macros_inherited').hide();
+					break;
+				case '<?php echo "inherited"; ?>':
+					macroFields.prop('disabled', false);
+					jQuery('#macros_host').hide();
+					jQuery('#macros_inherited').show();
+					break;
+			}
+		});
+	});
 </script>
--- /usr/share/zabbix/include/views/js/configuration.host.edit.js.php.orig	2013-10-12 15:51:49.000000000 +0200
+++ /usr/share/zabbix/include/views/js/configuration.host.edit.js.php	2013-11-03 15:46:56.000000000 +0100
@@ -386,6 +386,24 @@
 					break;
 			}
 		});
+		// radio button of macro views was clicked
+		jQuery('div.jqueryinputset input[name=macro_view]').click(function() {
+			// action depending on which button was clicked
+			var macroFields = jQuery('#macrosFormList:input');
+
+			switch (jQuery(this).val()) {
+				case '<?php echo "host"; ?>':
+					macroFields.prop('disabled', true);
+					jQuery('#macros_host').show();
+					jQuery('#macros_inherited').hide();
+					break;
+				case '<?php echo "inherited"; ?>':
+					macroFields.prop('disabled', false);
+					jQuery('#macros_host').hide();
+					jQuery('#macros_inherited').show();
+					break;
+			}
+		});
 		jQuery('#name').focus();
 
 
