Index: CIconMap.php =================================================================== --- CIconMap.php (revision 31986) +++ CIconMap.php (working copy) @@ -55,6 +55,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('iconmapids', 'sysmapids'); + $sqlParts = array( 'select' => array('icon_map' => 'im.iconmapid'), 'from' => array('icon_map' => 'icon_map im'), @@ -87,6 +89,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { $dbTable = DB::getSchema('icon_map'); foreach ($options['output'] as $field) { Index: CGraphPrototype.php =================================================================== --- CGraphPrototype.php (revision 31986) +++ CGraphPrototype.php (working copy) @@ -52,6 +52,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM); + $mandatory_params = array('graphids', 'groupids', 'itemids', 'discoveryids'); + $sqlParts = array( 'select' => array('graphs' => 'g.graphid'), 'from' => array('graphs' => 'graphs g'), @@ -98,6 +100,18 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['hostids']) && !count($options['hostids']) && !count($options['templateids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['templateids']) && !count($options['templateids']) && !count($options['hostids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['graphs']); Index: CHostGroup.php =================================================================== --- CHostGroup.php (revision 31986) +++ CHostGroup.php (working copy) @@ -44,6 +44,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('groupids', 'graphids', 'triggerids', 'maintenanceids'); + $sqlParts = array( 'select' => array('groups' => 'g.groupid'), 'from' => array('groups' => 'groups g'), @@ -98,6 +100,18 @@ ); $options = zbx_array_merge($defOptions, $params); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['hostids']) && !count($options['hostids']) && !count($options['templateids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['templateids']) && !count($options['templateids']) && !count($options['hostids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['groups']); Index: CTemplateScreenItem.php =================================================================== --- CTemplateScreenItem.php (revision 31986) +++ CTemplateScreenItem.php (working copy) @@ -90,8 +90,13 @@ * @return array|boolean Host data as array or false if error */ public function get(array $options = array()) { + $mandatory_params = array('screenitemids', 'screenids', 'hostids'); $options = zbx_array_merge($this->getOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + // build and execute query $sql = $this->createSelectQuery($this->tableName(), $options); $res = DBselect($sql, $options['limit']); Index: CUserGroup.php =================================================================== --- CUserGroup.php (revision 31986) +++ CUserGroup.php (working copy) @@ -59,6 +59,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('usrgrpids', 'userids'); + $sqlParts = array( 'select' => array('usrgrp' => 'g.usrgrpid'), 'from' => array('usrgrp' => 'usrgrp g'), @@ -93,6 +95,10 @@ $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['usrgrp']); Index: CItem.php =================================================================== --- CItem.php (revision 31986) +++ CItem.php (working copy) @@ -56,6 +56,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM); + $mandatory_params = array('itemids', 'groupids', 'proxyids', 'interfaceids', 'graphids', 'triggerids', 'applicationids'); + $sqlParts = array( 'select' => array('items' => 'i.itemid'), 'from' => array('items' => 'items i'), @@ -112,6 +114,18 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['hostids']) && !count($options['hostids']) && !count($options['templateids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['templateids']) && !count($options['templateids']) && !count($options['hostids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['items']); Index: CGraph.php =================================================================== --- CGraph.php (revision 31986) +++ CGraph.php (working copy) @@ -56,6 +56,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM); + $mandatory_params = array('graphids', 'groupids', 'itemids'); + $sqlParts = array( 'select' => array('graphs' => 'g.graphid'), 'from' => array('graphs' => 'graphs g'), @@ -101,6 +103,19 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['hostids']) && !count($options['hostids']) && !count($options['templateids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['templateids']) && !count($options['templateids']) && !count($options['hostids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (is_array($options['output'])) { unset($sqlParts['select']['graphs']); Index: CApplication.php =================================================================== --- CApplication.php (revision 31986) +++ CApplication.php (working copy) @@ -52,6 +52,8 @@ $sortColumns = array('applicationid', 'name'); $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('applicationids', 'groupids', 'itemids'); + $sqlParts = array( 'select' => array('apps' => 'a.applicationid'), 'from' => array('applications' => 'applications a'), @@ -93,6 +95,18 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['hostids']) && !count($options['hostids']) && !count($options['templateids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['templateids']) && !count($options['templateids']) && !count($options['hostids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + // editable + PERMISSION CHECK if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) { $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY; Index: CDService.php =================================================================== --- CDService.php (revision 31986) +++ CDService.php (working copy) @@ -76,6 +76,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM); + $mandatory_params = array('dserviceids', 'dhostids', 'dcheckids', 'druleids'); + $sqlParts = array( 'select' => array('dservices' => 'ds.dserviceid'), 'from' => array('dservices' => 'dservices ds'), @@ -116,6 +118,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['dservices']); Index: CScript.php =================================================================== --- CScript.php (revision 31986) +++ CScript.php (working copy) @@ -54,6 +54,8 @@ // allowed columns for sorting $sortColumns = array('scriptid', 'name'); + $mandatory_params = array('scriptids', 'groupids', 'hostids', 'usrgrpids'); + $sqlParts = array( 'select' => array('scripts' => 's.scriptid'), 'from' => array('scripts s'), @@ -89,6 +91,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['scripts']); Index: CTemplate.php =================================================================== --- CTemplate.php (revision 31986) +++ CTemplate.php (working copy) @@ -46,6 +46,9 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('templateids', 'parentTemplateids', 'groupids', 'hostids', + 'graphids', 'itemids', 'triggerids'); + $sqlParts = array( 'select' => array('templates' => 'h.hostid'), 'from' => array('hosts' => 'hosts h'), @@ -99,6 +102,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['templates']); Index: CMap.php =================================================================== --- CMap.php (revision 31986) +++ CMap.php (working copy) @@ -66,6 +66,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('sysmapids'); + $sqlParts = array( 'select' => array('sysmaps' => 's.sysmapid'), 'from' => array('sysmaps' => 'sysmaps s'), @@ -100,6 +102,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['sysmaps']); Index: CUser.php =================================================================== --- CUser.php (revision 31986) +++ CUser.php (working copy) @@ -51,6 +51,8 @@ // allowed columns for sorting $sortColumns = array('userid', 'alias'); + $mandatory_params = array('userids', 'usrgrpids', 'mediaids', 'mediatypeids'); + $sqlParts = array( 'select' => array('users' => 'u.userid'), 'from' => array('users' => 'users u'), @@ -87,6 +89,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['users']); Index: CScreen.php =================================================================== --- CScreen.php (revision 31986) +++ CScreen.php (working copy) @@ -54,6 +54,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('screenids', 'screenitemids'); + $sqlParts = array( 'select' => array('screens' => 's.screenid'), 'from' => array('screens' => 'screens s'), @@ -88,6 +90,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['screens']); Index: CGraphItem.php =================================================================== --- CGraphItem.php (revision 31986) +++ CGraphItem.php (working copy) @@ -48,6 +48,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('graphids', 'itemids'); + $sqlParts = array( 'select' => array('gitems' => 'gi.gitemid'), 'from' => array('graphs_items' => 'graphs_items gi'), @@ -75,6 +77,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + // editable + PERMISSION CHECK if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) { $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY; Index: CEvent.php =================================================================== --- CEvent.php (revision 31986) +++ CEvent.php (working copy) @@ -59,6 +59,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('eventids', 'groupids', 'hostids'); + $sqlParts = array( 'select' => array($this->fieldId('eventid')), 'from' => array('events' => 'events e'), @@ -109,6 +111,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + // editable + PERMISSION CHECK if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) { if (is_null($options['source']) && is_null($options['object'])) { @@ -145,6 +151,10 @@ } } + if (!is_null($options['triggerids']) && !count($options['triggerids']) && $options['object'] == EVENT_OBJECT_TRIGGER) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + // nodeids $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid(); @@ -519,7 +529,7 @@ } // adding acknowledges - if (!is_null($options['select_acknowledges'])) { + if (!is_null($options['select_acknowledges']) && count($eventids)) { if (is_array($options['select_acknowledges']) || str_in_array($options['select_acknowledges'], $subselectsAllowedOutputs)) { $res = DBselect( 'SELECT a.*,u.alias'. Index: CDHost.php =================================================================== --- CDHost.php (revision 31986) +++ CDHost.php (working copy) @@ -76,6 +76,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM); + $mandatory_params = array('druleids', 'dhostids', 'dserviceids', 'groupids', 'hostids'); + $sqlParts = array( 'select' => array('dhosts' => 'dh.dhostid'), 'from' => array('dhosts' => 'dhosts dh'), @@ -117,6 +119,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['dhosts']); Index: CItemPrototype.php =================================================================== --- CItemPrototype.php (revision 31986) +++ CItemPrototype.php (working copy) @@ -41,6 +41,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM); + $mandatory_params = array('itemids', 'groupids', 'discoveryids', 'graphids', 'triggerids'); + $sqlParts = array( 'select' => array('items' => 'i.itemid'), 'from' => array('items' => 'items i'), @@ -88,6 +90,18 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['hostids']) && !count($options['hostids']) && !count($options['templateids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['templateids']) && !count($options['templateids']) && !count($options['hostids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['items']); Index: CMapElement.php =================================================================== --- CMapElement.php (revision 31986) +++ CMapElement.php (working copy) @@ -56,6 +56,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('sysmapids'); + $sqlParts = array( 'select' => array('sysmaps_elements' => 'se.selementid'), 'from' => array('sysmaps_elements' => 'sysmaps_elements se'), @@ -89,6 +91,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['sysmaps_elements']); Index: CTriggerPrototype.php =================================================================== --- CTriggerPrototype.php (revision 31986) +++ CTriggerPrototype.php (working copy) @@ -52,6 +52,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('triggerids', 'groupids', 'itemids', 'applicationids', 'discoveryids'); + $sqlParts = array( 'select' => array('triggers' => 't.triggerid'), 'from' => array('t' => 'triggers t'), @@ -107,6 +109,18 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['hostids']) && !count($options['hostids']) && !count($options['templateids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['templateids']) && !count($options['templateids']) && !count($options['hostids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['triggers']); Index: CScreenItem.php =================================================================== --- CScreenItem.php (revision 31986) +++ CScreenItem.php (working copy) @@ -88,8 +88,15 @@ * @return array|boolean Host data as array or false if error */ public function get(array $options = array()) { + + $mandatory_params = array('screenitemids', 'screenids'); + $options = zbx_array_merge($this->getOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + // build and execute query $sql = $this->createSelectQuery($this->tableName(), $options); $res = DBselect($sql, $options['limit']); Index: CHostInterface.php =================================================================== --- CHostInterface.php (revision 31986) +++ CHostInterface.php (working copy) @@ -60,6 +60,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM); + $mandatory_params = array('interfaceids', 'groupids', 'hostids', 'itemids', 'triggerids'); + $sqlParts = array( 'select' => array('interface' => 'hi.interfaceid'), 'from' => array('interface' => 'interface hi'), @@ -99,6 +101,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['interface']); Index: CDiscoveryRule.php =================================================================== --- CDiscoveryRule.php (revision 31986) +++ CDiscoveryRule.php (working copy) @@ -48,6 +48,9 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM); + $mandatory_params = array('groupids', 'itemids', 'interfaceids'); + + $sqlParts = array( 'select' => array('items' => 'i.itemid'), 'from' => array('items' => 'items i'), @@ -92,6 +95,18 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['hostids']) && !count($options['hostids']) && !count($options['templateids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['templateids']) && !count($options['templateids']) && !count($options['hostids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['items']); Index: CUserMacro.php =================================================================== --- CUserMacro.php (revision 31986) +++ CUserMacro.php (working copy) @@ -59,6 +59,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('hostmacroids', 'groupids', 'hostids', 'templateids'); + $sqlParts = array( 'select' => array('macros' => 'hm.hostmacroid'), 'from' => array('hostmacro hm'), @@ -105,6 +107,14 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!is_null($options['globalmacro']) && !is_null($options['globalmacroids']) && !count($options['globalmacroids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + // editable + PERMISSION CHECK if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) { if (!is_null($options['editable']) && !is_null($options['globalmacro'])) { Index: CHistory.php =================================================================== --- CHistory.php (revision 31986) +++ CHistory.php (working copy) @@ -55,6 +55,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('hostids', 'itemids'); + $sqlParts = array( 'select' => array('history' => 'h.itemid'), 'from' => array(), @@ -93,6 +95,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + switch ($options['history']) { case ITEM_VALUE_TYPE_LOG: $sqlParts['from']['history'] = 'history_log h'; Index: CTrigger.php =================================================================== --- CTrigger.php (revision 31986) +++ CTrigger.php (working copy) @@ -58,6 +58,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('triggerids', 'groupids', 'itemids', 'applicationids'); + $fieldsToUnset = array(); $sqlParts = array( @@ -124,6 +126,18 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['hostids']) && !count($options['hostids']) && !count($options['templateids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['templateids']) && !count($options['templateids']) && !count($options['hostids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['triggers']); Index: CDRule.php =================================================================== --- CDRule.php (revision 31986) +++ CDRule.php (working copy) @@ -49,6 +49,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('druleids', 'dhostids', 'dserviceids', 'dcheckids'); + $sqlParts = array( 'select' => array('drules' => 'dr.druleid'), 'from' => array('drules' => 'drules dr'), @@ -87,6 +89,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + // editable + PERMISSION CHECK if (USER_TYPE_SUPER_ADMIN == $userType) { } Index: CTemplateScreen.php =================================================================== --- CTemplateScreen.php (revision 31986) +++ CTemplateScreen.php (working copy) @@ -51,6 +51,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('screenids', 'screenitemids'); + $sqlParts = array( 'select' => array('screens' => 's.screenid, s.templateid'), 'from' => array('screens' => 'screens s'), @@ -88,6 +90,18 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['hostids']) && !count($options['hostids']) && !count($options['templateids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + + if (!is_null($options['templateids']) && !count($options['templateids']) && !count($options['hostids'])) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['screens']); Index: CWebCheck.php =================================================================== --- CWebCheck.php (revision 31986) +++ CWebCheck.php (working copy) @@ -43,6 +43,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('httptestids', 'applicationids', 'hostids'); + $sqlParts = array( 'select' => array('httptests' => 'ht.httptestid'), 'from' => array('httptest' => 'httptest ht'), @@ -78,6 +80,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + // editable + PERMISSION CHECK if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) { $permission = $options['editable']?PERM_READ_WRITE:PERM_READ_ONLY; Index: CHost.php =================================================================== --- CHost.php (revision 31986) +++ CHost.php (working copy) @@ -73,6 +73,10 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM); + $mandatory_params = array('hostids', 'groupids', 'proxyids', 'templateids', 'interfaceids', + 'itemids', 'triggerids', 'httptestids', 'graphids', 'applicationids', + 'dhostids', 'dserviceids', 'maintenanceids'); + $sqlParts = array( 'select' => array('hosts' => 'h.hostid'), 'from' => array('hosts' => 'hosts h'), @@ -145,6 +149,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['hosts']); Index: CUserMedia.php =================================================================== --- CUserMedia.php (revision 31986) +++ CUserMedia.php (working copy) @@ -59,6 +59,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('mediaids', 'mediatypeids', 'usrgrpids', 'userids'); + $sqlParts = array( 'select' => array('media' => 'm.mediaid'), 'from' => array('media' => 'media m'), @@ -93,6 +95,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['media']); Index: CProxy.php =================================================================== --- CProxy.php (revision 31986) +++ CProxy.php (working copy) @@ -51,6 +51,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('proxyids'); + $sqlParts = array( 'select' => array('hostid' => 'h.hostid'), 'from' => array('hosts' => 'hosts h'), @@ -84,6 +86,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['hosts']); Index: CMediatype.php =================================================================== --- CMediatype.php (revision 31986) +++ CMediatype.php (working copy) @@ -58,6 +58,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); + $mandatory_params = array('mediatypeids', 'mediaids', 'userids'); + $sqlParts = array( 'select' => array('media_type' => 'mt.mediatypeid'), 'from' => array('media_type' => 'media_type mt'), @@ -93,6 +95,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + // permission check if (USER_TYPE_SUPER_ADMIN == $userType) { } Index: CDCheck.php =================================================================== --- CDCheck.php (revision 31986) +++ CDCheck.php (working copy) @@ -43,6 +43,8 @@ // allowed output options for [ select_* ] params $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM); + $mandatory_params = array('dcheckids', 'druleids', 'dhostids', 'dserviceids'); + $sqlParts = array( 'select' => array('dchecks' => 'dc.dcheckid'), 'from' => array('dchecks' => 'dchecks dc'), @@ -82,6 +84,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + if (is_array($options['output'])) { unset($sqlParts['select']['dchecks']); Index: CMaintenance.php =================================================================== --- CMaintenance.php (revision 31986) +++ CMaintenance.php (working copy) @@ -58,6 +58,8 @@ // allowed columns for sorting $sortColumns = array('maintenanceid', 'name', 'maintenance_type'); + $mandatory_params = array('maintenanceids', 'groupids', 'itemids'); + $sqlParts = array( 'select' => array('maintenance' => 'm.maintenanceid'), 'from' => array('maintenances' => 'maintenances m'), @@ -96,6 +98,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + // editable + PERMISSION CHECK $maintenanceids = array(); if ($userType == USER_TYPE_SUPER_ADMIN || $options['nopermissions']) { Index: CImage.php =================================================================== --- CImage.php (revision 31986) +++ CImage.php (working copy) @@ -56,6 +56,8 @@ // allowed columns for sorting $sortColumns = array('imageid', 'name'); + $mandatory_params = array('imageids', 'sysmapids'); + $sqlParts = array( 'select' => array('images' => 'i.imageid'), 'from' => array('images' => 'images i'), @@ -87,6 +89,10 @@ ); $options = zbx_array_merge($defOptions, $options); + if (!zbx_CheckRequires($options, $mandatory_params)) { + return ($options['output'] == API_OUTPUT_COUNT) ? 0 : array(); + } + // editable + PERMISSION CHECK if (!is_null($options['editable']) && (self::$userData['type'] < USER_TYPE_ZABBIX_ADMIN)) { return $result; Index: include/func.inc.php =================================================================== --- include/func.inc.php (revision 31986) +++ include/func.inc.php (working copy) @@ -1863,3 +1863,14 @@ return $str; } + +function zbx_CheckRequires($options, $mandatory) { + + foreach ($options as $name => $value) { + if (in_array($name, $mandatory) && !is_null($value) && !count($value)) { + return false; + } + } + + return true; +}