Index: include/graphs.inc.php
===================================================================
--- include/graphs.inc.php	(revision 56390)
+++ include/graphs.inc.php	(working copy)
@@ -215,21 +215,39 @@
 	if (!empty($itemTypes[ITEM_VALUE_TYPE_FLOAT]) || !empty($itemTypes[ITEM_VALUE_TYPE_UINT64])) {
 		$itemIdsNumeric = zbx_array_merge($itemTypes[ITEM_VALUE_TYPE_FLOAT], $itemTypes[ITEM_VALUE_TYPE_UINT64]);
 
-		$sql = 'SELECT MAX(i.history) AS history,MAX(i.trends) AS trends'.
-				' FROM items i'.
-				' WHERE '.dbConditionInt('i.itemid', $itemIdsNumeric);
-		if ($tableForNumeric = DBfetch(DBselect($sql))) {
-			// look for data in one of the tables
-			$sqlFromNum = ($tableForNumeric['history'] > $tableForNumeric['trends']) ? 'history' : 'trends';
+		$config = select_config();
+		if ($config['hk_history_global'] && $config['hk_trends_global']) {
+			$sqlFromNum = ($config['hk_history'] > $config['hk_trends']) ? 'history' : 'trends';
+			$result = time() - (SEC_PER_DAY * max($config['hk_history'], $config['hk_trends']));
+			print $result;
+		}
+		else {
+			$sql = 'SELECT MAX(i.history) AS history,MAX(i.trends) AS trends'.
+					' FROM items i'.
+					' WHERE '.dbConditionInt('i.itemid', $itemIdsNumeric);
+			if ($tableForNumeric = DBfetch(DBselect($sql))) {
+				// look for data in one of the tables
+				if ($config['hk_history_global']) {
+					$sqlFromNum = ($config['hk_history'] > $tableForNumeric['trends']) ? 'history' : 'trends';
+					$result = time() - (SEC_PER_DAY * max($config['hk_history'], $tableForNumeric['trends']));
+				}
+				elseif ($config['hk_trends_global']) {
+					$sqlFromNum = ($tableForNumeric['history'] > $config['hk_trends']) ? 'history' : 'trends';
+					$result = time() - (SEC_PER_DAY * max($config['hk_trends'], $tableForNumeric['history']));
+					
+				}
+				else {
+					$sqlFromNum = ($tableForNumeric['history'] > $tableForNumeric['trends']) ? 'history' : 'trends';
+					$result = time() - (SEC_PER_DAY * max($tableForNumeric['history'], $tableForNumeric['trends']));	
+				}
 
-			$result = time() - (SEC_PER_DAY * max($tableForNumeric['history'], $tableForNumeric['trends']));
-
-			/*
-			 * In case history storage exceeds the maximum time difference between current year and minimum 1970
-			 * (for example year 2014 - 200 years < year 1970), correct year to 1970 (unix time timestamp 0).
-			 */
-			if ($result < 0) {
-				$result = 0;
+				/*
+				* In case history storage exceeds the maximum time difference between current year and minimum 1970
+				* (for example year 2014 - 200 years < year 1970), correct year to 1970 (unix time timestamp 0).
+				*/
+				if ($result < 0) {
+					$result = 0;
+				}
 			}
 		}
 	}
Index: include/views/configuration.item.edit.php
===================================================================
--- include/views/configuration.item.edit.php	(revision 56390)
+++ include/views/configuration.item.edit.php	(working copy)
@@ -313,8 +313,8 @@
 
 $dataConfig = select_config();
 $keepHistory = array();
-$keepHistory[] =  new CNumericBox('history', $this->data['history'], 8);
 if ($dataConfig['hk_history_global'] && !$data['parent_discoveryid'] && !$data['is_template']) {
+	$keepHistory[] =  new CNumericBox('history', $this->data['history'], 8, true);
 	$keepHistory[] = ' '._x('Overridden by', 'item_form').' ';
 	if (CWebUser::getType() == USER_TYPE_SUPER_ADMIN) {
 		$link = new CLink(_x('global housekeeping settings', 'item_form'), 'adm.housekeeper.php');
@@ -326,11 +326,15 @@
 	}
 	$keepHistory[] = ' ('._n('%1$s day', '%1$s days', $dataConfig['hk_history']).')';
 }
+else {
+	$keepHistory[] =  new CNumericBox('history', $this->data['history'], 8);
+}
+
 $itemFormList->addRow(_('History storage period (in days)'), $keepHistory);
 
 $keepTrend = array();
-$keepTrend[] =  new CNumericBox('trends', $this->data['trends'], 8);
 if ($dataConfig['hk_trends_global'] && !$data['parent_discoveryid'] && !$data['is_template']) {
+	$keepTrend[] =  new CNumericBox('trends', $this->data['trends'], 8, true);
 	$keepTrend[] = ' '._x('Overridden by', 'item_form').' ';
 	if (CWebUser::getType() == USER_TYPE_SUPER_ADMIN) {
 		$link = new CLink(_x('global housekeeping settings', 'item_form'), 'adm.housekeeper.php');
@@ -342,7 +346,11 @@
 	}
 	$keepTrend[] = ' ('._n('%1$s day', '%1$s days', $dataConfig['hk_trends']).')';
 }
+else {
+	$keepTrend[] =  new CNumericBox('trends', $this->data['trends'], 8);
+}
 
+
 $itemFormList->addRow(_('Trend storage period (in days)'), $keepTrend, false, 'row_trends');
 $itemFormList->addRow(_('Log time format'),
 	new CTextBox('logtimefmt', $this->data['logtimefmt'], ZBX_TEXTBOX_SMALL_SIZE, $this->data['limited'], 64),

