--- include/defines.inc.php.orig	2014-02-15 15:29:20.000000000 +0100
+++ include/defines.inc.php	2014-04-05 13:16:38.000000000 +0200
@@ -113,6 +113,7 @@
 
 define('ZBX_DROPDOWN_FIRST_NONE',	0);
 define('ZBX_DROPDOWN_FIRST_ALL',	1);
+define('ZBX_DROPDOWN_FIRST_NONEALL',	2);
 
 define('T_ZBX_STR',			0);
 define('T_ZBX_INT',			1);
@@ -871,7 +872,7 @@
 define('ZBX_TEXTAREA_STANDARD_ROWS',	7);
 
 // validation
-define('DB_ID',		"({}>=0&&bccomp('{}',\"10000000000000000000\")<0)&&");
+define('DB_ID',		"({}>=-1&&bccomp('{}',\"10000000000000000000\")<0)&&");
 define('NOT_EMPTY',	"({}!='')&&");
 define('NOT_ZERO',	"({}!=0)&&");
 define('NO_TRIM',	'NO_TRIM');
--- include/classes/class.cpagefilter.php.orig	2014-02-12 10:04:38.000000000 +0100
+++ include/classes/class.cpagefilter.php	2014-04-05 20:34:45.000000000 +0200
@@ -462,8 +462,10 @@
 		CProfile::update($this->_profileIdx['groups'], $groupid, PROFILE_TYPE_ID);
 		CProfile::update(self::GROUP_LATEST_IDX, $groupid, PROFILE_TYPE_ID);
 
-		$this->isSelected['groupsSelected'] = ($this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['groups'])) || $groupid > 0;
-		$this->isSelected['groupsAll'] = $this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['groups']) && $groupid == 0;
+		$this->isSelected['groupsSelected'] = ($this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['groups']) || $groupid > 0)
+			|| ($this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_NONEALL && !empty($this->data['groups']) && $groupid == -1);
+		$this->isSelected['groupsAll'] = $this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['groups']) && $groupid == 0
+			|| $this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_NONEALL && !empty($this->data['groups']) && $groupid == -1;
 		$this->ids['groupid'] = $groupid;
 	}
 
@@ -478,6 +480,11 @@
 	private function _initHosts($hostId, array $options) {
 		$this->data['hosts'] = array();
 
+                if (!$this->groupsSelected && $this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_NONEALL && $hostId > 0) {
+                        $this->groupid = -1;
+                        $this->groupsSelected = true;
+                }
+
 		if (isset($options['DDFirstLabel'])) {
 			$this->config['DDFirstLabels']['hosts'] = $options['DDFirstLabel'];
 
@@ -527,7 +534,8 @@
 			CProfile::update(self::HOST_LATEST_IDX, $hostId, PROFILE_TYPE_ID);
 		}
 
-		$this->isSelected['hostsSelected'] = (($this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['hosts'])) || $hostId > 0);
+		$this->isSelected['hostsSelected'] = ($this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['hosts'])) || $hostId > 0
+			|| $this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_NONEALL && $hostId != 0;
 		$this->isSelected['hostsAll'] = ($this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['hosts']) && $hostId == 0);
 		$this->ids['hostid'] = $hostId;
 	}
@@ -671,7 +679,8 @@
 		CProfile::update($this->_profileIdx['drules'], $druleid, PROFILE_TYPE_ID);
 		CProfile::update(self::DRULE_LATEST_IDX, $druleid, PROFILE_TYPE_ID);
 
-		$this->isSelected['drulesSelected'] = ($this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['drules'])) || $druleid > 0;
+		$this->isSelected['drulesSelected'] = ($this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['drules'])) || $druleid > 0
+			|| $this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_NONEALL && $druleid != 0;
 		$this->isSelected['drulesAll'] = $this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['drules']) && $druleid == 0;
 		$this->ids['druleid'] = $druleid;
 	}
@@ -887,7 +896,8 @@
 				$firstLabel = $this->config['DDFirstLabels'][$options['objectName']];
 			}
 			else {
-				$firstLabel = ($this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_NONE) ? _('not selected') : _('all');
+				if ($this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_NONEALL) $items = array(-1 => _('all')) + $items;
+				$firstLabel = ($this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL) ? _('all') : _('not selected');
 			}
 
 			if ($name == 'application') {
--- include/views/administration.general.gui.edit.php.orig	2014-02-12 10:04:38.000000000 +0100
+++ include/views/administration.general.gui.edit.php	2014-04-05 11:44:08.000000000 +0200
@@ -25,6 +25,7 @@
 
 $comboDdFirstEntry = new CComboBox('dropdown_first_entry', $this->data['config']['dropdown_first_entry']);
 $comboDdFirstEntry->addItem(ZBX_DROPDOWN_FIRST_NONE, _('None'));
+$comboDdFirstEntry->addItem(ZBX_DROPDOWN_FIRST_NONEALL, _('None / offer all'));
 $comboDdFirstEntry->addItem(ZBX_DROPDOWN_FIRST_ALL, _('All'));
 
 $guiTab = new CFormList('scriptsTab');
--- overview.php.orig	2014-02-12 10:04:39.000000000 +0100
+++ overview.php	2014-04-05 20:33:09.000000000 +0200
@@ -66,6 +66,9 @@
 CProfile::update('web.overview.type', $data['type'], PROFILE_TYPE_INT);
 
 $data['pageFilter'] = new CPageFilter(array(
+	'config' => array(
+		'deny_all' => 1
+	),
 	'groups' => array(
 		($data['type'] == SHOW_TRIGGERS ? 'with_monitored_triggers' : 'with_monitored_items') => true
 	),
--- httpmon.php.orig	2014-02-12 10:04:39.000000000 +0100
+++ httpmon.php	2014-04-05 18:54:25.000000000 +0200
@@ -40,10 +40,10 @@
 /*
  * Permissions
  */
-if (get_request('groupid') && !API::HostGroup()->isReadable(array($_REQUEST['groupid']))) {
+if (get_request('groupid') > 0 && !API::HostGroup()->isReadable(array($_REQUEST['groupid']))) {
 	access_deny();
 }
-if (get_request('hostid') && !API::Host()->isReadable(array($_REQUEST['hostid']))) {
+if (get_request('hostid') > 0 && !API::Host()->isReadable(array($_REQUEST['hostid']))) {
 	access_deny();
 }
 
@@ -65,7 +65,7 @@
 $_REQUEST['groupid'] = $pageFilter->groupid;
 $_REQUEST['hostid'] = $pageFilter->hostid;
 
-$displayNodes = (is_array(get_current_nodeid()) && $pageFilter->groupid == 0 && $pageFilter->hostid == 0);
+$displayNodes = (is_array(get_current_nodeid()) && $pageFilter->groupid < 1 && $pageFilter->hostid < 1);
 
 $r_form = new CForm('get');
 $r_form->addVar('fullscreen', $_REQUEST['fullscreen']);
@@ -84,7 +84,7 @@
 $table = new CTableInfo(_('No web scenarios found.'));
 $table->SetHeader(array(
 	$displayNodes ? _('Node') : null,
-	$_REQUEST['hostid'] == 0 ? make_sorting_header(_('Host'), 'hostname') : null,
+	$_REQUEST['hostid'] < 1 ? make_sorting_header(_('Host'), 'hostname') : null,
 	make_sorting_header(_('Name'), 'name'),
 	_('Number of steps'),
 	_('Last check'),
--- latest.php.orig	2014-03-30 18:05:58.000000000 +0200
+++ latest.php	2014-04-05 18:41:07.000000000 +0200
@@ -58,10 +58,10 @@
 /*
  * Permissions
  */
-if (getRequest('groupid') && !API::HostGroup()->isReadable(array($_REQUEST['groupid']))) {
+if (getRequest('groupid') > 0 && !API::HostGroup()->isReadable(array($_REQUEST['groupid']))) {
 	access_deny();
 }
-if (getRequest('hostid') && !API::Host()->isReadable(array($_REQUEST['hostid']))) {
+if (getRequest('hostid') > 0 && !API::Host()->isReadable(array($_REQUEST['hostid']))) {
 	access_deny();
 }
 
@@ -152,7 +152,7 @@
 $applications = $items = $hostScripts = array();
 
 // get hosts
-if ($_REQUEST['hostid']) {
+if ($_REQUEST['hostid'] > 0) {
 	$availableHostIds = array($_REQUEST['hostid']);
 }
 elseif ($pageFilter->hostsSelected) {
@@ -264,7 +264,7 @@
 			CArrayHelper::sort($applications, $sortFields);
 		}
 
-		if ($_REQUEST['hostid'] == 0) {
+		if ($_REQUEST['hostid'] < 1) {
 			// get host scripts
 			$hostScripts = API::Script()->getScriptsByHosts($hostIds);
 
@@ -324,7 +324,7 @@
 	$table->setHeader(array(
 		$link,
 		is_show_all_nodes() ? make_sorting_header(_('Node'), 'h.hostid') : null,
-		($_REQUEST['hostid'] == 0) ? $hostHeader : null,
+		($_REQUEST['hostid'] < 1) ? $hostHeader : null,
 		$itemHeader,
 		new CSpan(_('Interval')),
 		new CSpan(_('History')),
@@ -341,7 +341,7 @@
 	$table->setHeader(array(
 		$link,
 		is_show_all_nodes() ? $hostHeader : null,
-		($_REQUEST['hostid'] == 0) ? make_sorting_header(_('Host'), 'h.name') : null,
+		($_REQUEST['hostid'] < 1) ? make_sorting_header(_('Host'), 'h.name') : null,
 		$itemHeader,
 		$lastCheckHeader,
 		new CSpan(_('Last value')),
@@ -496,7 +496,7 @@
 
 	$hostName = null;
 
-	if ($_REQUEST['hostid'] == 0) {
+	if ($_REQUEST['hostid'] < 1) {
 		$hostName = new CSpan($host['name'],
 			'link_menu menu-host'.(($host['status'] == HOST_STATUS_NOT_MONITORED) ? ' not-monitored' : '')
 		);
@@ -662,7 +662,7 @@
 
 	$hostName = null;
 
-	if ($_REQUEST['hostid'] == 0) {
+	if ($_REQUEST['hostid'] < 1) {
 		$hostName = new CSpan($host['name'],
 			'link_menu menu-host'.(($host['status'] == HOST_STATUS_NOT_MONITORED) ? ' not-monitored' : '')
 		);
--- tr_status.php.orig	2014-02-12 10:04:40.000000000 +0100
+++ tr_status.php	2014-04-05 18:46:09.000000000 +0200
@@ -61,10 +61,10 @@
 /*
  * Permissions
  */
-if (get_request('groupid') && !API::HostGroup()->isReadable(array($_REQUEST['groupid']))) {
+if (get_request('groupid') > 0 && !API::HostGroup()->isReadable(array($_REQUEST['groupid']))) {
 	access_deny();
 }
-if (get_request('hostid') && !API::Host()->isReadable(array($_REQUEST['hostid']))) {
+if (get_request('hostid') > 0 && !API::Host()->isReadable(array($_REQUEST['hostid']))) {
 	access_deny();
 }
 
@@ -246,7 +246,7 @@
 /*
  * Display
  */
-$displayNodes = (is_show_all_nodes() && $pageFilter->groupid == 0 && $pageFilter->hostid == 0);
+$displayNodes = (is_show_all_nodes() && $pageFilter->groupid < 1 && $pageFilter->hostid < 1);
 
 $showTriggers = $_REQUEST['show_triggers'];
 $showEvents = $_REQUEST['show_events'];
--- events.php.orig	2014-02-12 10:04:39.000000000 +0100
+++ events.php	2014-04-05 18:51:07.000000000 +0200
@@ -85,10 +85,10 @@
 /*
  * Permissions
  */
-if (get_request('groupid') && !API::HostGroup()->isReadable(array($_REQUEST['groupid']))) {
+if (get_request('groupid') > 0 && !API::HostGroup()->isReadable(array($_REQUEST['groupid']))) {
 	access_deny();
 }
-if (get_request('hostid') && !API::Host()->isReadable(array($_REQUEST['hostid']))) {
+if (get_request('hostid') > 0 && !API::Host()->isReadable(array($_REQUEST['hostid']))) {
 	access_deny();
 }
 if (get_request('triggerid') && !API::Trigger()->isReadable(array($_REQUEST['triggerid']))) {
@@ -576,7 +576,7 @@
 		$table->setHeader(array(
 			_('Time'),
 			is_show_all_nodes() ? _('Node') : null,
-			($_REQUEST['hostid'] == 0) ? _('Host') : null,
+			($_REQUEST['hostid'] < 1) ? _('Host') : null,
 			_('Description'),
 			_('Status'),
 			_('Severity'),
@@ -589,7 +589,7 @@
 			$csvRows[] = array(
 				_('Time'),
 				is_show_all_nodes() ? _('Node') : null,
-				($_REQUEST['hostid'] == 0) ? _('Host') : null,
+				($_REQUEST['hostid'] < 1) ? _('Host') : null,
 				_('Description'),
 				_('Status'),
 				_('Severity'),
@@ -670,7 +670,7 @@
 			));
 
 			// fetch scripts for the host JS menu
-			if ($_REQUEST['hostid'] == 0) {
+			if ($_REQUEST['hostid'] < 1) {
 				$scripts = API::Script()->getScriptsByHosts($hostids);
 			}
 
@@ -728,7 +728,7 @@
 				// host JS menu link
 				$hostName = null;
 
-				if ($_REQUEST['hostid'] == 0) {
+				if ($_REQUEST['hostid'] < 1) {
 					$hostName = new CSpan($host['name'], 'link_menu');
 					$hostName->setMenuPopup(getMenuPopupHost($host, $scripts[$host['hostid']]));
 				}
@@ -755,7 +755,7 @@
 					$csvRows[] = array(
 						zbx_date2str(EVENTS_ACTION_TIME_FORMAT, $event['clock']),
 						is_show_all_nodes() ? get_node_name_by_elid($event['objectid']) : null,
-						($_REQUEST['hostid'] == 0) ? $host['name'] : null,
+						($_REQUEST['hostid'] < 1) ? $host['name'] : null,
 						$description,
 						trigger_value2str($event['value']),
 						getSeverityCaption($trigger['priority']),
--- charts.php.orig	2014-02-12 10:04:40.000000000 +0100
+++ charts.php	2014-04-05 18:57:27.000000000 +0200
@@ -56,10 +56,10 @@
 /*
  * Permissions
  */
-if (get_request('groupid') && !API::HostGroup()->isReadable(array($_REQUEST['groupid']))) {
+if (get_request('groupid') > 0 && !API::HostGroup()->isReadable(array($_REQUEST['groupid']))) {
 	access_deny();
 }
-if (get_request('hostid') && !API::Host()->isReadable(array($_REQUEST['hostid']))) {
+if (get_request('hostid') > 0 && !API::Host()->isReadable(array($_REQUEST['hostid']))) {
 	access_deny();
 }
 if (get_request('graphid')) {
--- discovery.php.orig	2014-02-12 10:04:39.000000000 +0100
+++ discovery.php	2014-04-05 19:05:19.000000000 +0200
@@ -39,7 +39,7 @@
 // check discovery for existing if defined druleid
 if ($druleid = get_request('druleid')) {
 	$dbDRule = API::DRule()->get(array(
-			'druleids' => $druleid,
+			'druleids' => ($druleid != -1 ? $drule : null),
 			'countOutput' => true
 	));
 	if (!$dbDRule) {
--- hostinventoriesoverview.php.orig	2014-02-12 10:04:39.000000000 +0100
+++ hostinventoriesoverview.php	2014-04-05 19:24:21.000000000 +0200
@@ -51,6 +51,9 @@
 }
 
 $options = array(
+	'config' => array(
+		'allow_all' => ($config['dropdown_first_entry'] == ZBX_DROPDOWN_FIRST_NONEALL?1:null)
+	),
 	'groups' => array(
 		'real_hosts' => 1,
 	),
--- templates.php.orig	2014-02-12 10:04:39.000000000 +0100
+++ templates.php	2014-04-05 20:44:17.000000000 +0200
@@ -406,6 +406,7 @@
 
 $pageFilter = new CPageFilter(array(
 	'config' => array(
+		'allow_all' => ($config['dropdown_first_entry'] == ZBX_DROPDOWN_FIRST_NONEALL?1:null),
 		'individual' => 1
 	),
 	'groups' => array(
--- hosts.php.orig	2014-02-12 10:04:39.000000000 +0100
+++ hosts.php	2014-04-05 19:18:37.000000000 +0200
@@ -634,6 +634,9 @@
 $hostsWidget = new CWidget();
 
 $pageFilter = new CPageFilter(array(
+	'config' => array(
+		'allow_all' => ($config['dropdown_first_entry'] == ZBX_DROPDOWN_FIRST_NONEALL?1:null)
+	),
 	'groups' => array(
 		'real_hosts' => true,
 		'editable' => true
--- maintenance.php.orig	2014-02-12 10:04:39.000000000 +0100
+++ maintenance.php	2014-04-05 19:20:12.000000000 +0200
@@ -376,6 +376,9 @@
 }
 
 $options = array(
+	'config' => array(
+		'allow_all' => ($config['dropdown_first_entry'] == ZBX_DROPDOWN_FIRST_NONEALL?1:null)
+	),
 	'groups' => array('editable' => 1),
 	'groupid' => get_request('groupid', null)
 );
--- applications.php.orig	2014-02-12 10:04:39.000000000 +0100
+++ applications.php	2014-04-08 21:22:00.000000000 +0200
@@ -245,6 +245,7 @@
 else {
 	$data = array(
 		'pageFilter' => new CPageFilter(array(
+			'config' => array('allow_all' => ($config['dropdown_first_entry'] == ZBX_DROPDOWN_FIRST_NONEALL?1:null)),
 			'groups' => array('editable' => true, 'with_hosts_and_templates' => true),
 			'hosts' => array('editable' => true, 'templated_hosts' => true),
 			'hostid' => get_request('hostid'),
--- hostinventories.php.orig	2014-02-12 10:04:39.000000000 +0100
+++ hostinventories.php	2014-04-08 21:37:22.000000000 +0200
@@ -129,6 +129,9 @@
 else{
 	$data['config'] = select_config();
 	$options = array(
+		'config' => array(
+			'allow_all' => ($config['dropdown_first_entry'] == ZBX_DROPDOWN_FIRST_NONEALL?1:null)
+		),
 		'groups' => array(
 			'real_hosts' => 1,
 		),
