本文整理汇总了PHP中getUserGroupsByUserId函数的典型用法代码示例。如果您正苦于以下问题:PHP getUserGroupsByUserId函数的具体用法?PHP getUserGroupsByUserId怎么用?PHP getUserGroupsByUserId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getUserGroupsByUserId函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Get GraphItems data
*
* @param array $options
* @return array|boolean
*/
public function get($options = array())
{
$result = array();
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
$sqlParts = array('select' => array('gitems' => 'gi.gitemid'), 'from' => array('graphs_items' => 'graphs_items gi'), 'where' => array(), 'order' => array(), 'limit' => null);
$defOptions = array('graphids' => null, 'itemids' => null, 'type' => null, 'editable' => null, 'nopermissions' => null, 'selectGraphs' => null, 'output' => API_OUTPUT_EXTEND, 'expandData' => null, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
$options = zbx_array_merge($defOptions, $options);
$this->checkDeprecatedParam($options, 'expandData');
// editable + PERMISSION CHECK
if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
$userGroups = getUserGroupsByUserId($userid);
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE gi.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY i.itemid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ' AND MAX(r.permission)>=' . zbx_dbstr($permission) . ')';
}
// graphids
if (!is_null($options['graphids'])) {
zbx_value2array($options['graphids']);
$sqlParts['from']['graphs'] = 'graphs g';
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where'][] = dbConditionInt('g.graphid', $options['graphids']);
}
// itemids
if (!is_null($options['itemids'])) {
zbx_value2array($options['itemids']);
$sqlParts['where'][] = dbConditionInt('gi.itemid', $options['itemids']);
}
// type
if (!is_null($options['type'])) {
$sqlParts['where'][] = 'gi.type=' . zbx_dbstr($options['type']);
}
// limit
if (zbx_ctype_digit($options['limit']) && $options['limit']) {
$sqlParts['limit'] = $options['limit'];
}
$sqlParts = $this->applyQueryOutputOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
$sqlParts = $this->applyQuerySortOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
$dbRes = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
while ($gitem = DBfetch($dbRes)) {
if (!is_null($options['countOutput'])) {
$result = $gitem['rowscount'];
} else {
$result[$gitem['gitemid']] = $gitem;
}
}
if (!is_null($options['countOutput'])) {
return $result;
}
if ($result) {
$result = $this->addRelatedObjects($options, $result);
$result = $this->unsetExtraFields($result, array('graphid'), $options['output']);
}
// removing keys (hash -> array)
if (is_null($options['preservekeys'])) {
$result = zbx_cleanHashes($result);
}
return $result;
}
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:64,代码来源:CGraphItem.php
示例2: get
/**
* Get template data.
*
* @param array $options
*
* @return array
*/
public function get($options = array())
{
$result = array();
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
$sqlParts = array('select' => array('templates' => 'h.hostid'), 'from' => array('hosts' => 'hosts h'), 'where' => array('h.status=' . HOST_STATUS_TEMPLATE), 'group' => array(), 'order' => array(), 'limit' => null);
$defOptions = array('groupids' => null, 'templateids' => null, 'parentTemplateids' => null, 'hostids' => null, 'graphids' => null, 'itemids' => null, 'triggerids' => null, 'with_items' => null, 'with_triggers' => null, 'with_graphs' => null, 'with_httptests' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => '', 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_EXTEND, 'selectGroups' => null, 'selectHosts' => null, 'selectTemplates' => null, 'selectParentTemplates' => null, 'selectItems' => null, 'selectDiscoveries' => null, 'selectTriggers' => null, 'selectGraphs' => null, 'selectApplications' => null, 'selectMacros' => null, 'selectScreens' => null, 'selectHttpTests' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null, 'limitSelects' => null);
$options = zbx_array_merge($defOptions, $options);
// editable + PERMISSION CHECK
if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
$userGroups = getUserGroupsByUserId($userid);
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE h.hostid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ' AND MAX(r.permission)>=' . zbx_dbstr($permission) . ')';
}
// groupids
if (!is_null($options['groupids'])) {
zbx_value2array($options['groupids']);
$sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
$sqlParts['where'][] = dbConditionInt('hg.groupid', $options['groupids']);
$sqlParts['where']['hgh'] = 'hg.hostid=h.hostid';
if (!is_null($options['groupCount'])) {
$sqlParts['group']['hg'] = 'hg.groupid';
}
}
// templateids
if (!is_null($options['templateids'])) {
zbx_value2array($options['templateids']);
$sqlParts['where']['templateid'] = dbConditionInt('h.hostid', $options['templateids']);
}
// parentTemplateids
if (!is_null($options['parentTemplateids'])) {
zbx_value2array($options['parentTemplateids']);
$sqlParts['from']['hosts_templates'] = 'hosts_templates ht';
$sqlParts['where'][] = dbConditionInt('ht.templateid', $options['parentTemplateids']);
$sqlParts['where']['hht'] = 'h.hostid=ht.hostid';
if (!is_null($options['groupCount'])) {
$sqlParts['group']['templateid'] = 'ht.templateid';
}
}
// hostids
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$sqlParts['from']['hosts_templates'] = 'hosts_templates ht';
$sqlParts['where'][] = dbConditionInt('ht.hostid', $options['hostids']);
$sqlParts['where']['hht'] = 'h.hostid=ht.templateid';
if (!is_null($options['groupCount'])) {
$sqlParts['group']['ht'] = 'ht.hostid';
}
}
// itemids
if (!is_null($options['itemids'])) {
zbx_value2array($options['itemids']);
$sqlParts['from']['items'] = 'items i';
$sqlParts['where'][] = dbConditionInt('i.itemid', $options['itemids']);
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
}
// triggerids
if (!is_null($options['triggerids'])) {
zbx_value2array($options['triggerids']);
$sqlParts['from']['functions'] = 'functions f';
$sqlParts['from']['items'] = 'items i';
$sqlParts['where'][] = dbConditionInt('f.triggerid', $options['triggerids']);
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
$sqlParts['where']['fi'] = 'f.itemid=i.itemid';
}
// graphids
if (!is_null($options['graphids'])) {
zbx_value2array($options['graphids']);
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['items'] = 'items i';
$sqlParts['where'][] = dbConditionInt('gi.graphid', $options['graphids']);
$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
}
// with_items
if (!is_null($options['with_items'])) {
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM items i' . ' WHERE h.hostid=i.hostid' . ' AND i.flags IN (' . ZBX_FLAG_DISCOVERY_NORMAL . ',' . ZBX_FLAG_DISCOVERY_CREATED . ')' . ')';
}
// with_triggers
if (!is_null($options['with_triggers'])) {
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM items i,functions f,triggers t' . ' WHERE i.hostid=h.hostid' . ' AND i.itemid=f.itemid' . ' AND f.triggerid=t.triggerid' . ' AND t.flags IN (' . ZBX_FLAG_DISCOVERY_NORMAL . ',' . ZBX_FLAG_DISCOVERY_CREATED . ')' . ')';
}
// with_graphs
if (!is_null($options['with_graphs'])) {
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM items i,graphs_items gi,graphs g' . ' WHERE i.hostid=h.hostid' . ' AND i.itemid=gi.itemid' . ' AND gi.graphid=g.graphid' . ' AND g.flags IN (' . ZBX_FLAG_DISCOVERY_NORMAL . ',' . ZBX_FLAG_DISCOVERY_CREATED . ')' . ')';
}
// with_httptests
if (!empty($options['with_httptests'])) {
$sqlParts['where'][] = 'EXISTS (SELECT ht.httptestid FROM httptest ht WHERE ht.hostid=h.hostid)';
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('hosts h', $options, $sqlParts);
//.........这里部分代码省略.........
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:101,代码来源:CTemplate.php
示例3: get
/**
* Get Itemprototype data.
*/
public function get($options = array())
{
$result = array();
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
$sqlParts = array('select' => array('items' => 'i.itemid'), 'from' => array('items' => 'items i'), 'where' => array('i.flags=' . ZBX_FLAG_DISCOVERY_PROTOTYPE), 'group' => array(), 'order' => array(), 'limit' => null);
$defOptions = array('groupids' => null, 'templateids' => null, 'hostids' => null, 'itemids' => null, 'discoveryids' => null, 'graphids' => null, 'triggerids' => null, 'inherited' => null, 'templated' => null, 'monitored' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_EXTEND, 'selectHosts' => null, 'selectApplications' => null, 'selectTriggers' => null, 'selectGraphs' => null, 'selectDiscoveryRule' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null, 'limitSelects' => null);
$options = zbx_array_merge($defOptions, $options);
// editable + PERMISSION CHECK
if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
$userGroups = getUserGroupsByUserId($userid);
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE i.hostid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ' AND MAX(r.permission)>=' . zbx_dbstr($permission) . ')';
}
// templateids
if (!is_null($options['templateids'])) {
zbx_value2array($options['templateids']);
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$options['hostids'] = array_merge($options['hostids'], $options['templateids']);
} else {
$options['hostids'] = $options['templateids'];
}
}
// hostids
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$sqlParts['where']['hostid'] = dbConditionInt('i.hostid', $options['hostids']);
if (!is_null($options['groupCount'])) {
$sqlParts['group']['i'] = 'i.hostid';
}
}
// itemids
if (!is_null($options['itemids'])) {
zbx_value2array($options['itemids']);
$sqlParts['where']['itemid'] = dbConditionInt('i.itemid', $options['itemids']);
}
// discoveryids
if (!is_null($options['discoveryids'])) {
zbx_value2array($options['discoveryids']);
$sqlParts['from']['item_discovery'] = 'item_discovery id';
$sqlParts['where'][] = dbConditionInt('id.parent_itemid', $options['discoveryids']);
$sqlParts['where']['idi'] = 'i.itemid=id.itemid';
if (!is_null($options['groupCount'])) {
$sqlParts['group']['id'] = 'id.parent_itemid';
}
}
// triggerids
if (!is_null($options['triggerids'])) {
zbx_value2array($options['triggerids']);
$sqlParts['from']['functions'] = 'functions f';
$sqlParts['where'][] = dbConditionInt('f.triggerid', $options['triggerids']);
$sqlParts['where']['if'] = 'i.itemid=f.itemid';
}
// graphids
if (!is_null($options['graphids'])) {
zbx_value2array($options['graphids']);
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['where'][] = dbConditionInt('gi.graphid', $options['graphids']);
$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
}
// inherited
if (!is_null($options['inherited'])) {
if ($options['inherited']) {
$sqlParts['where'][] = 'i.templateid IS NOT NULL';
} else {
$sqlParts['where'][] = 'i.templateid IS NULL';
}
}
// templated
if (!is_null($options['templated'])) {
$sqlParts['from']['hosts'] = 'hosts h';
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
if ($options['templated']) {
$sqlParts['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE;
} else {
$sqlParts['where'][] = 'h.status<>' . HOST_STATUS_TEMPLATE;
}
}
// monitored
if (!is_null($options['monitored'])) {
$sqlParts['from']['hosts'] = 'hosts h';
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
if ($options['monitored']) {
$sqlParts['where'][] = 'h.status=' . HOST_STATUS_MONITORED;
$sqlParts['where'][] = 'i.status=' . ITEM_STATUS_ACTIVE;
} else {
$sqlParts['where'][] = '(h.status<>' . HOST_STATUS_MONITORED . ' OR i.status<>' . ITEM_STATUS_ACTIVE . ')';
}
}
// search
if (is_array($options['search'])) {
zbx_db_search('items i', $options, $sqlParts);
}
// --- FILTER ---
if (is_array($options['filter'])) {
$this->dbFilter('items i', $options, $sqlParts);
//.........这里部分代码省略.........
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:101,代码来源:CItemPrototype.php
示例4: get
/**
* Get GraphPrototype data
*
* @param array $options
* @return array
*/
public function get($options = array())
{
$result = array();
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
$sqlParts = array('select' => array('graphs' => 'g.graphid'), 'from' => array('graphs' => 'graphs g'), 'where' => array('g.flags=' . ZBX_FLAG_DISCOVERY_PROTOTYPE), 'group' => array(), 'order' => array(), 'limit' => null);
$defOptions = array('groupids' => null, 'templateids' => null, 'hostids' => null, 'graphids' => null, 'itemids' => null, 'discoveryids' => null, 'templated' => null, 'inherited' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_EXTEND, 'selectGroups' => null, 'selectTemplates' => null, 'selectHosts' => null, 'selectItems' => null, 'selectGraphItems' => null, 'selectDiscoveryRule' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
$options = zbx_array_merge($defOptions, $options);
// editable + PERMISSION CHECK
if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
$userGroups = getUserGroupsByUserId($userid);
// check permissions by graph items
$sqlParts['where'][] = 'NOT EXISTS (' . 'SELECT NULL' . ' FROM graphs_items gi,items i,hosts_groups hgg' . ' LEFT JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE g.graphid=gi.graphid' . ' AND gi.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY i.hostid' . ' HAVING MAX(permission)<' . zbx_dbstr($permission) . ' OR MIN(permission) IS NULL' . ' OR MIN(permission)=' . PERM_DENY . ')';
// check permissions by Y min item
$sqlParts['where'][] = 'NOT EXISTS (' . 'SELECT NULL' . ' FROM items i,hosts_groups hgg' . ' LEFT JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE g.ymin_type=' . GRAPH_YAXIS_TYPE_ITEM_VALUE . ' AND g.ymin_itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY i.hostid' . ' HAVING MAX(permission)<' . $permission . ' OR MIN(permission) IS NULL' . ' OR MIN(permission)=' . PERM_DENY . ')';
// check permissions by Y max item
$sqlParts['where'][] = 'NOT EXISTS (' . 'SELECT NULL' . ' FROM items i,hosts_groups hgg' . ' LEFT JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE g.ymax_type=' . GRAPH_YAXIS_TYPE_ITEM_VALUE . ' AND g.ymax_itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY i.hostid' . ' HAVING MAX(permission)<' . $permission . ' OR MIN(permission) IS NULL' . ' OR MIN(permission)=' . PERM_DENY . ')';
}
// groupids
if (!is_null($options['groupids'])) {
zbx_value2array($options['groupids']);
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['items'] = 'items i';
$sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
$sqlParts['where'][] = dbConditionInt('hg.groupid', $options['groupids']);
$sqlParts['where'][] = 'hg.hostid=i.hostid';
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
$sqlParts['where']['hgi'] = 'hg.hostid=i.hostid';
if (!is_null($options['groupCount'])) {
$sqlParts['group']['hg'] = 'hg.groupid';
}
}
// templateids
if (!is_null($options['templateids'])) {
zbx_value2array($options['templateids']);
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$options['hostids'] = array_merge($options['hostids'], $options['templateids']);
} else {
$options['hostids'] = $options['templateids'];
}
}
// hostids
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['items'] = 'items i';
$sqlParts['where'][] = dbConditionInt('i.hostid', $options['hostids']);
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
if (!is_null($options['groupCount'])) {
$sqlParts['group']['i'] = 'i.hostid';
}
}
// graphids
if (!is_null($options['graphids'])) {
zbx_value2array($options['graphids']);
$sqlParts['where'][] = dbConditionInt('g.graphid', $options['graphids']);
}
// itemids
if (!is_null($options['itemids'])) {
zbx_value2array($options['itemids']);
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where'][] = dbConditionInt('gi.itemid', $options['itemids']);
if (!is_null($options['groupCount'])) {
$sqlParts['group']['gi'] = 'gi.itemid';
}
}
// discoveryids
if (!is_null($options['discoveryids'])) {
zbx_value2array($options['discoveryids']);
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['item_discovery'] = 'item_discovery id';
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where']['giid'] = 'gi.itemid=id.itemid';
$sqlParts['where'][] = dbConditionInt('id.parent_itemid', $options['discoveryids']);
if (!is_null($options['groupCount'])) {
$sqlParts['group']['id'] = 'id.parent_itemid';
}
}
// templated
if (!is_null($options['templated'])) {
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['items'] = 'items i';
$sqlParts['from']['hosts'] = 'hosts h';
$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
$sqlParts['where']['ggi'] = 'g.graphid=gi.graphid';
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
if ($options['templated']) {
$sqlParts['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE;
} else {
//.........这里部分代码省略.........
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:101,代码来源:CGraphPrototype.php
示例5: get
/**
* Get GraphPrototype data
*
* @param array $options
* @return array
*/
public function get($options = array())
{
$result = array();
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
// allowed columns for sorting
$sortColumns = array('graphid', 'name', 'graphtype');
// allowed output options for [ select_* ] params
$subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM);
$sqlParts = array('select' => array('graphs' => 'g.graphid'), 'from' => array('graphs' => 'graphs g'), 'where' => array('g.flags=' . ZBX_FLAG_DISCOVERY_CHILD), 'group' => array(), 'order' => array(), 'limit' => null);
$defOptions = array('nodeids' => null, 'groupids' => null, 'templateids' => null, 'hostids' => null, 'graphids' => null, 'itemids' => null, 'discoveryids' => null, 'type' => null, 'templated' => null, 'inherited' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectGroups' => null, 'selectTemplates' => null, 'selectHosts' => null, 'selectItems' => null, 'selectGraphItems' => null, 'selectDiscoveryRule' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
$options = zbx_array_merge($defOptions, $options);
if (is_array($options['output'])) {
unset($sqlParts['select']['graphs']);
$dbTable = DB::getSchema('graphs');
foreach ($options['output'] as $field) {
if (isset($dbTable['fields'][$field])) {
$sqlParts['select'][$field] = 'g.' . $field;
}
}
$options['output'] = API_OUTPUT_CUSTOM;
}
// editable + PERMISSION CHECK
if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
$userGroups = getUserGroupsByUserId($userid);
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM graphs_items gi,items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE g.graphid=gi.graphid' . ' AND gi.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY gi.graphid' . ' HAVING MIN(r.permission)>=' . $permission . ')';
}
// nodeids
$nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
// groupids
if (!is_null($options['groupids'])) {
zbx_value2array($options['groupids']);
if ($options['output'] != API_OUTPUT_SHORTEN) {
$sqlParts['select']['groupid'] = 'hg.groupid';
}
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['items'] = 'items i';
$sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
$sqlParts['where'][] = dbConditionInt('hg.groupid', $options['groupids']);
$sqlParts['where'][] = 'hg.hostid=i.hostid';
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
$sqlParts['where']['hgi'] = 'hg.hostid=i.hostid';
if (!is_null($options['groupCount'])) {
$sqlParts['group']['hg'] = 'hg.groupid';
}
}
// templateids
if (!is_null($options['templateids'])) {
zbx_value2array($options['templateids']);
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$options['hostids'] = array_merge($options['hostids'], $options['templateids']);
} else {
$options['hostids'] = $options['templateids'];
}
}
// hostids
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
if ($options['output'] != API_OUTPUT_SHORTEN) {
$sqlParts['select']['hostid'] = 'i.hostid';
}
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['items'] = 'items i';
$sqlParts['where'][] = dbConditionInt('i.hostid', $options['hostids']);
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
if (!is_null($options['groupCount'])) {
$sqlParts['group']['i'] = 'i.hostid';
}
}
// graphids
if (!is_null($options['graphids'])) {
zbx_value2array($options['graphids']);
$sqlParts['where'][] = dbConditionInt('g.graphid', $options['graphids']);
}
// itemids
if (!is_null($options['itemids'])) {
zbx_value2array($options['itemids']);
if ($options['output'] != API_OUTPUT_SHORTEN) {
$sqlParts['select']['itemid'] = 'gi.itemid';
}
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where'][] = dbConditionInt('gi.itemid', $options['itemids']);
if (!is_null($options['groupCount'])) {
$sqlParts['group']['gi'] = 'gi.itemid';
}
}
// discoveryids
if (!is_null($options['discoveryids'])) {
zbx_value2array($options['discoveryids']);
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CGraphPrototype.php
示例6: get
/**
* Get maintenances data.
*
* @param array $options
* @param array $options['itemids']
* @param array $options['hostids']
* @param array $options['groupids']
* @param array $options['triggerids']
* @param array $options['maintenanceids']
* @param bool $options['status']
* @param bool $options['editable']
* @param bool $options['count']
* @param string $options['pattern']
* @param int $options['limit']
* @param string $options['order']
*
* @return array
*/
public function get(array $options = [])
{
$result = [];
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
$sqlParts = ['select' => ['maintenance' => 'm.maintenanceid'], 'from' => ['maintenances' => 'maintenances m'], 'where' => [], 'group' => [], 'order' => [], 'limit' => null];
$defOptions = ['groupids' => null, 'hostids' => null, 'maintenanceids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'filter' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_EXTEND, 'selectGroups' => null, 'selectHosts' => null, 'selectTimeperiods' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null];
$options = zbx_array_merge($defOptions, $options);
// editable + PERMISSION CHECK
$maintenanceids = [];
if ($userType == USER_TYPE_SUPER_ADMIN || $options['nopermissions']) {
if (!is_null($options['groupids']) || !is_null($options['hostids'])) {
if (!is_null($options['groupids'])) {
zbx_value2array($options['groupids']);
$res = DBselect('SELECT mmg.maintenanceid' . ' FROM maintenances_groups mmg' . ' WHERE ' . dbConditionInt('mmg.groupid', $options['groupids']));
while ($maintenance = DBfetch($res)) {
$maintenanceids[] = $maintenance['maintenanceid'];
}
}
$sql = 'SELECT mmh.maintenanceid' . ' FROM maintenances_hosts mmh,hosts_groups hg' . ' WHERE hg.hostid=mmh.hostid';
if (!is_null($options['groupids'])) {
zbx_value2array($options['groupids']);
$sql .= ' AND ' . dbConditionInt('hg.groupid', $options['groupids']);
}
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$sql .= ' AND ' . dbConditionInt('hg.hostid', $options['hostids']);
}
$res = DBselect($sql);
while ($maintenance = DBfetch($res)) {
$maintenanceids[] = $maintenance['maintenanceid'];
}
$sqlParts['where'][] = dbConditionInt('m.maintenanceid', $maintenanceids);
}
} else {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
$userGroups = getUserGroupsByUserId($userid);
$sql = 'SELECT m.maintenanceid' . ' FROM maintenances m' . ' WHERE NOT EXISTS (' . 'SELECT NULL' . ' FROM maintenances_hosts mh,hosts_groups hg' . ' LEFT JOIN rights r' . ' ON r.id=hg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE m.maintenanceid=mh.maintenanceid' . ' AND mh.hostid=hg.hostid' . ' GROUP by mh.hostid' . ' HAVING MIN(r.permission) IS NULL' . ' OR MIN(r.permission)=' . PERM_DENY . ' OR MAX(r.permission)<' . zbx_dbstr($permission) . ')' . ' AND NOT EXISTS (' . 'SELECT NULL' . ' FROM maintenances_groups mg' . ' LEFT JOIN rights r' . ' ON r.id=mg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE m.maintenanceid=mg.maintenanceid' . ' GROUP by mg.groupid' . ' HAVING MIN(r.permission) IS NULL' . ' OR MIN(r.permission)=' . PERM_DENY . ' OR MAX(r.permission)<' . zbx_dbstr($permission) . ')';
if (!is_null($options['groupids'])) {
zbx_value2array($options['groupids']);
$sql .= ' AND (' . 'EXISTS (' . 'SELECT NULL' . ' FROM maintenances_groups mg' . ' WHERE m.maintenanceid=mg.maintenanceid' . ' AND ' . dbConditionInt('mg.groupid', $options['groupids']) . ')' . ' OR EXISTS (' . 'SELECT NULL' . ' FROM maintenances_hosts mh,hosts_groups hg' . ' WHERE m.maintenanceid=mh.maintenanceid' . ' AND mh.hostid=hg.hostid' . ' AND ' . dbConditionInt('hg.groupid', $options['groupids']) . ')' . ')';
}
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$sql .= ' AND EXISTS (' . 'SELECT NULL' . ' FROM maintenances_hosts mh' . ' WHERE m.maintenanceid=mh.maintenanceid' . ' AND ' . dbConditionInt('mh.hostid', $options['hostids']) . ')';
}
if (!is_null($options['maintenanceids'])) {
zbx_value2array($options['maintenanceids']);
$sql .= ' AND ' . dbConditionInt('m.maintenanceid', $options['maintenanceids']);
}
$res = DBselect($sql);
while ($maintenance = DBfetch($res)) {
$maintenanceids[] = $maintenance['maintenanceid'];
}
$sqlParts['where'][] = dbConditionInt('m.maintenanceid', $maintenanceids);
}
// maintenanceids
if (!is_null($options['maintenanceids'])) {
zbx_value2array($options['maintenanceids']);
$sqlParts['where'][] = dbConditionInt('m.maintenanceid', $options['maintenanceids']);
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('maintenances m', $options, $sqlParts);
}
// search
if (is_array($options['search'])) {
zbx_db_search('maintenances m', $options, $sqlParts);
}
// limit
if (zbx_ctype_digit($options['limit']) && $options['limit']) {
$sqlParts['limit'] = $options['limit'];
}
$sqlParts = $this->applyQueryOutputOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
$sqlParts = $this->applyQuerySortOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
$res = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
while ($maintenance = DBfetch($res)) {
if (!is_null($options['countOutput'])) {
if (!is_null($options['groupCount'])) {
$result[] = $maintenance;
} else {
$result = $maintenance['rowscount'];
//.........这里部分代码省略.........
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:101,代码来源:CMaintenance.php
示例7: get
/**
* Get host data.
*
* @param array $options
* @param array $options['groupids'] HostGroup IDs
* @param array $options['hostids'] Host IDs
* @param boolean $options['monitored_hosts'] only monitored Hosts
* @param boolean $options['templated_hosts'] include templates in result
* @param boolean $options['with_items'] only with items
* @param boolean $options['with_monitored_items'] only with monitored items
* @param boolean $options['with_triggers'] only with triggers
* @param boolean $options['with_monitored_triggers'] only with monitored triggers
* @param boolean $options['with_httptests'] only with http tests
* @param boolean $options['with_monitored_httptests'] only with monitored http tests
* @param boolean $options['with_graphs'] only with graphs
* @param boolean $options['editable'] only with read-write permission. Ignored for SuperAdmins
* @param boolean $options['selectGroups'] select HostGroups
* @param boolean $options['selectItems'] select Items
* @param boolean $options['selectTriggers'] select Triggers
* @param boolean $options['selectGraphs'] select Graphs
* @param boolean $options['selectApplications'] select Applications
* @param boolean $options['selectMacros'] select Macros
* @param boolean|array $options['selectInventory'] select Inventory
* @param boolean $options['withInventory'] select only hosts with inventory
* @param int $options['count'] count Hosts, returned column name is rowscount
* @param string $options['pattern'] search hosts by pattern in Host name
* @param string $options['extendPattern'] search hosts by pattern in Host name, ip and DNS
* @param int $options['limit'] limit selection
* @param string $options['sortfield'] field to sort by
* @param string $options['sortorder'] sort order
*
* @return array|boolean Host data as array or false if error
*/
public function get($options = [])
{
$result = [];
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
$sqlParts = ['select' => ['hosts' => 'h.hostid'], 'from' => ['hosts' => 'hosts h'], 'where' => ['flags' => 'h.flags IN (' . ZBX_FLAG_DISCOVERY_NORMAL . ',' . ZBX_FLAG_DISCOVERY_CREATED . ')'], 'group' => [], 'order' => [], 'limit' => null];
$defOptions = ['groupids' => null, 'hostids' => null, 'proxyids' => null, 'templateids' => null, 'interfaceids' => null, 'itemids' => null, 'triggerids' => null, 'maintenanceids' => null, 'graphids' => null, 'applicationids' => null, 'dserviceids' => null, 'httptestids' => null, 'monitored_hosts' => null, 'templated_hosts' => null, 'proxy_hosts' => null, 'with_items' => null, 'with_monitored_items' => null, 'with_simple_graph_items' => null, 'with_triggers' => null, 'with_monitored_triggers' => null, 'with_httptests' => null, 'with_monitored_httptests' => null, 'with_graphs' => null, 'with_applications' => null, 'withInventory' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchInventory' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_EXTEND, 'selectGroups' => null, 'selectParentTemplates' => null, 'selectItems' => null, 'selectDiscoveries' => null, 'selectTriggers' => null, 'selectGraphs' => null, 'selectApplications' => null, 'selectMacros' => null, 'selectScreens' => null, 'selectInterfaces' => null, 'selectInventory' => null, 'selectHttpTests' => null, 'selectDiscoveryRule' => null, 'selectHostDiscovery' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null, 'limitSelects' => null];
$options = zbx_array_merge($defOptions, $options);
// editable + PERMISSION CHECK
if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
$userGroups = getUserGroupsByUserId($userid);
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE h.hostid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ' AND MAX(r.permission)>=' . zbx_dbstr($permission) . ')';
}
// hostids
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$sqlParts['where']['hostid'] = dbConditionInt('h.hostid', $options['hostids']);
}
// groupids
if (!is_null($options['groupids'])) {
zbx_value2array($options['groupids']);
$sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
$sqlParts['where'][] = dbConditionInt('hg.groupid', $options['groupids']);
$sqlParts['where']['hgh'] = 'hg.hostid=h.hostid';
if (!is_null($options['groupCount'])) {
$sqlParts['group']['groupid'] = 'hg.groupid';
}
}
// proxyids
if (!is_null($options['proxyids'])) {
zbx_value2array($options['proxyids']);
$sqlParts['where'][] = dbConditionInt('h.proxy_hostid', $options['proxyids']);
}
// templateids
if (!is_null($options['templateids'])) {
zbx_value2array($options['templateids']);
$sqlParts['from']['hosts_templates'] = 'hosts_templates ht';
$sqlParts['where'][] = dbConditionInt('ht.templateid', $options['templateids']);
$sqlParts['where']['hht'] = 'h.hostid=ht.hostid';
if (!is_null($options['groupCount'])) {
$sqlParts['group']['templateid'] = 'ht.templateid';
}
}
// interfaceids
if (!is_null($options['interfaceids'])) {
zbx_value2array($options['interfaceids']);
$sqlParts['from']['interface'] = 'interface hi';
$sqlParts['where'][] = dbConditionInt('hi.interfaceid', $options['interfaceids']);
$sqlParts['where']['hi'] = 'h.hostid=hi.hostid';
}
// itemids
if (!is_null($options['itemids'])) {
zbx_value2array($options['itemids']);
$sqlParts['from']['items'] = 'items i';
$sqlParts['where'][] = dbConditionInt('i.itemid', $options['itemids']);
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
}
// triggerids
if (!is_null($options['triggerids'])) {
zbx_value2array($options['triggerids']);
$sqlParts['from']['functions'] = 'functions f';
$sqlParts['from']['items'] = 'items i';
$sqlParts['where'][] = dbConditionInt('f.triggerid', $options['triggerids']);
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
$sqlParts['where']['fi'] = 'f.itemid=i.itemid';
}
//.........这里部分代码省略.........
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:101,代码来源:CHost.php
示例8: get
/**
* Get UserMacros data.
*
* @param array $options
* @param array $options['groupids'] usermacrosgroup ids
* @param array $options['hostids'] host ids
* @param array $options['hostmacroids'] host macros ids
* @param array $options['globalmacroids'] global macros ids
* @param array $options['templateids'] template ids
* @param boolean $options['globalmacro'] only global macros
* @param boolean $options['selectGroups'] select groups
* @param boolean $options['selectHosts'] select hosts
* @param boolean $options['selectTemplates'] select templates
*
* @return array|boolean UserMacros data as array or false if error
*/
public function get($options = array())
{
$result = array();
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
$sqlParts = array('select' => array('macros' => 'hm.hostmacroid'), 'from' => array('hostmacro hm'), 'where' => array(), 'order' => array(), 'limit' => null);
$sqlPartsGlobal = array('select' => array('macros' => 'gm.globalmacroid'), 'from' => array('globalmacro gm'), 'where' => array(), 'order' => array(), 'limit' => null);
$defOptions = array('groupids' => null, 'hostids' => null, 'hostmacroids' => null, 'globalmacroids' => null, 'templateids' => null, 'globalmacro' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_EXTEND, 'selectGroups' => null, 'selectHosts' => null, 'selectTemplates' => null, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
$options = zbx_array_merge($defOptions, $options);
// editable + PERMISSION CHECK
if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
if (!is_null($options['editable']) && !is_null($options['globalmacro'])) {
return array();
} else {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
$userGroups = getUserGroupsByUserId($userid);
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE hm.hostid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ' AND MAX(r.permission)>=' . zbx_dbstr($permission) . ')';
}
}
// global macro
if (!is_null($options['globalmacro'])) {
$options['groupids'] = null;
$options['hostmacroids'] = null;
$options['triggerids'] = null;
$options['hostids'] = null;
$options['itemids'] = null;
$options['selectGroups'] = null;
$options['selectTemplates'] = null;
$options['selectHosts'] = null;
}
// globalmacroids
if (!is_null($options['globalmacroids'])) {
zbx_value2array($options['globalmacroids']);
$sqlPartsGlobal['where'][] = dbConditionInt('gm.globalmacroid', $options['globalmacroids']);
}
// hostmacroids
if (!is_null($options['hostmacroids'])) {
zbx_value2array($options['hostmacroids']);
$sqlParts['where'][] = dbConditionInt('hm.hostmacroid', $options['hostmacroids']);
}
// groupids
if (!is_null($options['groupids'])) {
zbx_value2array($options['groupids']);
$sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
$sqlParts['where'][] = dbConditionInt('hg.groupid', $options['groupids']);
$sqlParts['where']['hgh'] = 'hg.hostid=hm.hostid';
}
// hostids
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$sqlParts['where'][] = dbConditionInt('hm.hostid', $options['hostids']);
}
// templateids
if (!is_null($options['templateids'])) {
zbx_value2array($options['templateids']);
$sqlParts['from']['macros_templates'] = 'hosts_templates ht';
$sqlParts['where'][] = dbConditionInt('ht.templateid', $options['templateids']);
$sqlParts['where']['hht'] = 'hm.hostid=ht.hostid';
}
// search
if (is_array($options['search'])) {
zbx_db_search('hostmacro hm', $options, $sqlParts);
zbx_db_search('globalmacro gm', $options, $sqlPartsGlobal);
}
// filter
if (is_array($options['filter'])) {
if (isset($options['filter']['macro'])) {
zbx_value2array($options['filter']['macro']);
$sqlParts['where'][] = dbConditionString('hm.macro', $options['filter']['macro']);
$sqlPartsGlobal['where'][] = dbConditionString('gm.macro', $options['filter']['macro']);
}
}
// sorting
$sqlParts = $this->applyQuerySortOptions('hostmacro', 'hm', $options, $sqlParts);
$sqlPartsGlobal = $this->applyQuerySortOptions('globalmacro', 'gm', $options, $sqlPartsGlobal);
// limit
if (zbx_ctype_digit($options['limit']) && $options['limit']) {
$sqlParts['limit'] = $options['limit'];
$sqlPartsGlobal['limit'] = $options['limit'];
}
// init GLOBALS
if (!is_null($options['globalmacro'])) {
$sqlPartsGlobal = $this->applyQueryOutputOptions('globalmacro', 'gm', $options, $sqlPartsGlobal);
$res = DBselect($this->createSelectQueryFromParts($sqlPartsGlobal), $sqlPartsGlobal['limit']);
//.........这里部分代码省略.........
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:101,代码来源:CUserMacro.php
示例9: get
/**
* Get Screen data
*
* @param array $options
* @param array $options['nodeids'] Node IDs
* @param boolean $options['with_items'] only with items
* @param boolean $options['editable'] only with read-write permission. Ignored for SuperAdmins
* @param int $options['count'] count Hosts, returned column name is rowscount
* @param string $options['pattern'] search hosts by pattern in host names
* @param int $options['limit'] limit selection
* @param string $options['order'] deprecated parameter (for now)
* @return array|boolean Host data as array or false if error
*/
public function get($options = array())
{
$result = array();
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
// allowed columns for sorting
$sortColumns = array('screenid', 'name');
// allowed output options for [ select_* ] params
$subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
$sqlParts = array('select' => array('screens' => 's.screenid,s.templateid'), 'from' => array('screens' => 'screens s'), 'where' => array('template' => 's.templateid IS NOT NULL'), 'order' => array(), 'group' => array(), 'limit' => null);
$defOptions = array('nodeids' => null, 'screenids' => null, 'screenitemids' => null, 'templateids' => null, 'hostids' => null, 'editable' => null, 'noInheritance' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectScreenItems' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
$options = zbx_array_merge($defOptions, $options);
if (is_array($options['output'])) {
unset($sqlParts['select']['screens']);
$dbTable = DB::getSchema('screens');
foreach ($options['output'] as $field) {
if (isset($dbTable['fields'][$field])) {
$sqlParts['select'][$field] = 's.' . $field;
}
}
$options['output'] = API_OUTPUT_CUSTOM;
}
if (!is_null($options['editable']) || is_null($options['hostids']) && is_null($options['templateids'])) {
$options['noInheritance'] = 1;
}
// editable + PERMISSION CHECK
if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
// TODO: think how we could combine templateids && hostids options
if (!is_null($options['templateids'])) {
unset($options['hostids']);
$options['templateids'] = API::Template()->get(array('templateids' => $options['templateids'], 'editable' => $options['editable'], 'preservekeys' => true));
$options['templateids'] = array_keys($options['templateids']);
} elseif (!is_null($options['hostids'])) {
$options['templateids'] = API::Host()->get(array('hostids' => $options['hostids'], 'editable' => $options['editable'], 'preservekeys' => true));
$options['templateids'] = array_keys($options['templateids']);
} else {
// TODO: get screen
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
$userGroups = getUserGroupsByUserId($userid);
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE s.templateid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>=' . $permission . ')';
}
}
// nodeids
$nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
// screenids
if (!is_null($options['screenids'])) {
zbx_value2array($options['screenids']);
$sqlParts['where'][] = dbConditionInt('s.screenid', $options['screenids']);
}
// screenitemids
if (!is_null($options['screenitemids'])) {
zbx_value2array($options['screenitemids']);
if ($options['output'] != API_OUTPUT_EXTEND) {
$sqlParts['select']['screenitemid'] = 'si.screenitemid';
}
$sqlParts['from']['screens_items'] = 'screens_items si';
$sqlParts['where']['ssi'] = 'si.screenid=s.screenid';
$sqlParts['where'][] = dbConditionInt('si.screenitemid', $options['scre
|
请发表评论