当前位置: 首页>>代码示例>>PHP>>正文


PHP getUserGroupsByUserId函数代码示例

本文整理汇总了PHP中getUserGroupsByUserId函数的典型用法代码示例。如果您正苦于以下问题:PHP getUserGroupsByUserId函数的具体用法?PHP getUserGroupsByUserId怎么用?PHP getUserGroupsByUserId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getUserGroupsByUserId函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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['screenitemids']);
     }
     // templateids
     if (!is_null($options['templateids'])) {
         zbx_value2array($options['templateids']);
         if (isset($options['hostids']) && !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']);
         // collecting template chain
         $templatesChain = array();
         $linkedTemplateids = $options['hostids'];
         $childTemplateids = $options['hostids'];
         while (is_null($options['noInheritance']) && !empty($childTemplateids)) {
             $sql = 'SELECT ht.*' . ' FROM hosts_templates ht' . ' WHERE ' . dbConditionInt('hostid', $childTemplateids);
             $dbTemplates = DBselect($sql);
             $childTemplateids = array();
             while ($link = DBfetch($dbTemplates)) {
                 $childTemplateids[$link['templateid']] = $link['templateid'];
                 $linkedTemplateids[$link['templateid']] = $link['templateid'];
                 createParentToChildRelation($templatesChain, $link, 'templateid', 'hostid');
             }
         }
         if ($options['output'] != API_OUTPUT_EXTEND) {
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CTemplateScreen.php

示例10: get

 /**
  * Get screen data.
  *
  * @param array  $options
  * @param array  $options['nodeids']		Node IDs
  * @param bool   $options['with_items']		only with items
  * @param bool   $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
  */
 public function get($options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     $userid = self::$userData['userid'];
     $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_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;
             $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)>' . PERM_DENY . ' AND MAX(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['screenitemids']);
     }
     // templateids
     if (!is_null($options['templateids'])) {
         zbx_value2array($options['templateids']);
         if (isset($options['hostids']) && !is_null($options['hostids'])) {
             zbx_value2array($options['hostids']);
             $options['hostids'] = array_merge($options['hostids'], $options['templateids']);
         } else {
             $options['hostids'] = $options['templateids'];
         }
     }
     // hostids
     $templatesChain = array();
     if (!is_null($options['hostids'])) {
         zbx_value2array($options['hostids']);
         // collecting template chain
         $linkedTemplateids = $options['hostids'];
         $childTemplateids = $options['hostids'];
         while (is_null($options['noInheritance']) && !empty($childTemplateids)) {
             $sql = 'SELECT ht.*' . ' FROM hosts_templates ht' . ' WHERE ' . dbConditionInt('hostid', $childTemplateids);
             $dbTemplates = DBselect($sql);
             $childTemplateids = array();
             while ($link = DBfetch($dbTemplates)) {
                 $childTemplateids[$link['templateid']] = $link['templateid'];
                 $linkedTemplateids[$link['templateid']] = $link['templateid'];
                 createParentToChildRelation($templatesChain, $link, 'templateid', 'hostid');
             }
         }
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['templateid'] = 's.templateid';
         }
         $sqlParts['where']['templateid'] = dbConditionInt('s.templateid', $linkedTemplateids);
     }
     // filter
     if (is_array($options['filter'])) {
         $this->dbFilter('screens s', $options, $sqlParts);
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search('screens s', $options, $sqlParts);
     }
     // limit
//.........这里部分代码省略.........
开发者ID:itnihao,项目名称:zatree-2.2,代码行数:101,代码来源:CTemplateScreen.php

示例11: 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 boolean $options['status']
  * @param boolean $options['editable']
  * @param boolean $options['count']
  * @param string $options['pattern']
  * @param int $options['limit']
  * @param string $options['order']
  * @return array|int item data as array or false if error
  */
 public function get(array $options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     $userid = self::$userData['userid'];
     // allowed columns for sorting
     $sortColumns = array('maintenanceid', 'name', 'maintenance_type');
     $sqlParts = array('select' => array('maintenance' => 'm.maintenanceid'), 'from' => array('maintenances' => 'maintenances m'), 'where' => array(), 'group' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, '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_REFER, '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 = array();
     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_ONLY;
         $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)<' . $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)<' . $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);
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // groupids
     if (!is_null($options['groupids'])) {
         $options['selectGroups'] = 1;
     }
     // hostids
     if (!is_null($options['hostids'])) {
         $options['selectHosts'] = 1;
     }
     // maintenanceids
     if (!is_null($options['maintenanceids'])) {
         zbx_value2array($options['maintenanceids']);
         $sqlParts['where'][] = dbConditionInt('m.maintenanceid', $options['maintenanceids']);
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sqlParts['select']['maintenance'] = 'm.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sqlParts['select'] = array('COUNT(DISTINCT m.maintenanceid) AS rowscount');
         // groupCount
         if (!is_null($options['groupCount'])) {
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CMaintenance.php

示例12: applyQueryFilterOptions

 protected function applyQueryFilterOptions($tableName, $tableAlias, array $options, array $sqlParts)
 {
     $sqlParts = parent::applyQueryFilterOptions($tableName, $tableAlias, $options, $sqlParts);
     // do not return host prototypes from discovered hosts
     $sqlParts['from'][] = 'host_discovery hd';
     $sqlParts['from'][] = 'items i';
     $sqlParts['from'][] = 'hosts ph';
     $sqlParts['where'][] = $this->fieldId('hostid') . '=hd.hostid';
     $sqlParts['where'][] = 'hd.parent_itemid=i.itemid';
     $sqlParts['where'][] = 'i.hostid=ph.hostid';
     $sqlParts['where'][] = 'ph.flags=' . ZBX_FLAG_DISCOVERY_NORMAL;
     if (CWebUser::getType() != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
         $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
         $sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM ' . 'host_discovery hd,items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', getUserGroupsByUserId(self::$userData['userid'])) . ' WHERE h.hostid=hd.hostid' . ' AND hd.parent_itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ' AND MAX(r.permission)>=' . zbx_dbstr($permission) . ')';
     }
     // discoveryids
     if ($options['discoveryids'] !== null) {
         $sqlParts['where'][] = dbConditionInt('hd.parent_itemid', (array) $options['discoveryids']);
         if ($options['groupCount'] !== null) {
             $sqlParts['group']['hd'] = 'hd.parent_itemid';
         }
     }
     // inherited
     if ($options['inherited'] !== null) {
         $sqlParts['where'][] = $options['inherited'] ? 'h.templateid IS NOT NULL' : 'h.templateid IS NULL';
     }
     return $sqlParts;
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:28,代码来源:CHostPrototype.php

示例13: addPermissionFilter

 /**
  * Add permission filter SQL query part
  *
  * @param array $sqlParts
  *
  * @return string
  */
 protected function addPermissionFilter($sqlParts)
 {
     $userid = self::$userData['userid'];
     $userGroups = getUserGroupsByUserId($userid);
     $sqlParts['where'][] = '(EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE s.triggerid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY f.triggerid' . ' HAVING MIN(r.permission)>=' . PERM_READ_ONLY . ')' . ' OR s.triggerid IS NULL)';
     return $sqlParts;
 }
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:14,代码来源:CService.php

示例14: get

 /**
  * Get actions data
  *
  * @param array $options
  * @param array $options['itemids']
  * @param array $options['hostids']
  * @param array $options['groupids']
  * @param array $options['actionids']
  * @param array $options['applicationids']
  * @param array $options['status']
  * @param array $options['editable']
  * @param array $options['extendoutput']
  * @param array $options['count']
  * @param array $options['pattern']
  * @param array $options['limit']
  * @param array $options['order']
  *
  * @return array|int item 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('actions' => 'a.actionid'), 'from' => array('actions' => 'actions a'), 'where' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'groupids' => null, 'hostids' => null, 'actionids' => null, 'triggerids' => null, 'mediatypeids' => null, 'usrgrpids' => null, 'userids' => null, 'scriptids' => null, 'nopermissions' => null, 'editable' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectConditions' => null, 'selectOperations' => 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']) {
         // conditions are checked here by sql, operations after, by api queries
         $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
         $userGroups = getUserGroupsByUserId($userid);
         // condition hostgroup
         $sqlParts['where'][] = 'NOT EXISTS (' . 'SELECT NULL' . ' FROM conditions cc' . ' LEFT JOIN rights r' . ' ON r.id=' . zbx_dbcast_2bigint('cc.value') . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE a.actionid=cc.actionid' . ' AND cc.conditiontype=' . CONDITION_TYPE_HOST_GROUP . ' GROUP BY cc.value' . ' HAVING MIN(r.permission) IS NULL' . ' OR MIN(r.permission)=' . PERM_DENY . ' OR MAX(r.permission)<' . $permission . ')';
         // condition host or template
         $sqlParts['where'][] = 'NOT EXISTS (' . 'SELECT NULL' . ' FROM conditions cc,hosts_groups hgg' . ' LEFT JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE a.actionid=cc.actionid' . ' AND ' . zbx_dbcast_2bigint('cc.value') . '=hgg.hostid' . ' AND cc.conditiontype IN (' . CONDITION_TYPE_HOST . ',' . CONDITION_TYPE_TEMPLATE . ')' . ' GROUP BY cc.value' . ' HAVING MIN(r.permission) IS NULL' . ' OR MIN(r.permission)=' . PERM_DENY . ' OR MAX(r.permission)<' . $permission . ')';
         // condition trigger
         $sqlParts['where'][] = 'NOT EXISTS (' . 'SELECT NULL' . ' FROM conditions cc,functions f,items i,hosts_groups hgg' . ' LEFT JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE a.actionid=cc.actionid' . ' AND ' . zbx_dbcast_2bigint('cc.value') . '=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' AND cc.conditiontype=' . CONDITION_TYPE_TRIGGER . ' GROUP BY cc.value' . ' HAVING MIN(r.permission) IS NULL' . ' OR MIN(r.permission)=' . PERM_DENY . ' OR MAX(r.permission)<' . $permission . ')';
     }
     // actionids
     if (!is_null($options['actionids'])) {
         zbx_value2array($options['actionids']);
         $sqlParts['select']['actionid'] = 'a.actionid';
         $sqlParts['where'][] = dbConditionInt('a.actionid', $options['actionids']);
     }
     // groupids
     if (!is_null($options['groupids'])) {
         zbx_value2array($options['groupids']);
         $sqlParts['select']['groupids'] = 'cg.value';
         $sqlParts['from']['conditions_groups'] = 'conditions cg';
         $sqlParts['where'][] = dbConditionString('cg.value', $options['groupids']);
         $sqlParts['where']['ctg'] = 'cg.conditiontype=' . CONDITION_TYPE_HOST_GROUP;
         $sqlParts['where']['acg'] = 'a.actionid=cg.actionid';
     }
     // hostids
     if (!is_null($options['hostids'])) {
         zbx_value2array($options['hostids']);
         $sqlParts['select']['hostids'] = 'ch.value';
         $sqlParts['from']['conditions_hosts'] = 'conditions ch';
         $sqlParts['where'][] = dbConditionString('ch.value', $options['hostids']);
         $sqlParts['where']['cth'] = 'ch.conditiontype=' . CONDITION_TYPE_HOST;
         $sqlParts['where']['ach'] = 'a.actionid=ch.actionid';
     }
     // triggerids
     if (!is_null($options['triggerids'])) {
         zbx_value2array($options['triggerids']);
         $sqlParts['select']['triggerids'] = 'ct.value';
         $sqlParts['from']['conditions_triggers'] = 'conditions ct';
         $sqlParts['where'][] = dbConditionString('ct.value', $options['triggerids']);
         $sqlParts['where']['ctt'] = 'ct.conditiontype=' . CONDITION_TYPE_TRIGGER;
         $sqlParts['where']['act'] = 'a.actionid=ct.actionid';
     }
     // mediatypeids
     if (!is_null($options['mediatypeids'])) {
         zbx_value2array($options['mediatypeids']);
         $sqlParts['select']['mediatypeid'] = 'om.mediatypeid';
         $sqlParts['from']['opmessage'] = 'opmessage om';
         $sqlParts['from']['operations_media'] = 'operations omed';
         $sqlParts['where'][] = dbConditionInt('om.mediatypeid', $options['mediatypeids']);
         $sqlParts['where']['aomed'] = 'a.actionid=omed.actionid';
         $sqlParts['where']['oom'] = 'omed.operationid=om.operationid';
     }
     // operation messages
     // usrgrpids
     if (!is_null($options['usrgrpids'])) {
         zbx_value2array($options['usrgrpids']);
         $sqlParts['select']['usrgrpid'] = 'omg.usrgrpid';
         $sqlParts['from']['opmessage_grp'] = 'opmessage_grp omg';
         $sqlParts['from']['operations_usergroups'] = 'operations oug';
         $sqlParts['where'][] = dbConditionInt('omg.usrgrpid', $options['usrgrpids']);
         $sqlParts['where']['aoug'] = 'a.actionid=oug.actionid';
         $sqlParts['where']['oomg'] = 'oug.operationid=omg.operationid';
     }
     // userids
     if (!is_null($options['userids'])) {
         zbx_value2array($options['userids']);
         $sqlParts['select']['userid'] = 'omu.userid';
         $sqlParts['from']['opmessage_usr'] = 'opmessage_usr omu';
         $sqlParts['from']['operations_users'] = 'operations ou';
         $sqlParts['where'][] = dbConditionInt('omu.userid', $options['userids']);
//.........这里部分代码省略.........
开发者ID:itnihao,项目名称:zatree-2.2,代码行数:101,代码来源:CAction.php

示例15: get

 /**
  * Get host groups.
  *
  * @param array $params
  *
  * @return array
  */
 public function get($params)
 {
     $result = array();
     $userType = self::$userData['type'];
     $userid = self::$userData['userid'];
     // allowed columns for sorting
     $sortColumns = array('groupid', 'name');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     $sqlParts = array('select' => array('groups' => 'g.groupid'), 'from' => array('groups' => 'groups g'), 'where' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'groupids' => null, 'hostids' => null, 'templateids' => null, 'graphids' => null, 'triggerids' => null, 'maintenanceids' => null, 'monitored_hosts' => null, 'templated_hosts' => null, 'real_hosts' => null, 'not_proxy_hosts' => null, 'with_hosts_and_templates' => null, 'with_items' => null, 'with_simple_graph_items' => null, 'with_monitored_items' => null, 'with_historical_items' => null, 'with_triggers' => null, 'with_monitored_triggers' => null, 'with_httptests' => null, 'with_monitored_httptests' => null, 'with_graphs' => null, 'with_applications' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectHosts' => null, 'selectTemplates' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null, 'limitSelects' => null);
     $options = zbx_array_merge($defOptions, $params);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['groups']);
         $dbTable = DB::getSchema('groups');
         $sqlParts['select']['groupid'] = 'g.groupid';
         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 rights r' . ' WHERE g.groupid=r.id' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' GROUP BY r.id' . ' HAVING MIN(r.permission)>=' . $permission . ')';
     }
     // groupids
     if (!is_null($options['groupids'])) {
         zbx_value2array($options['groupids']);
         $sqlParts['where']['groupid'] = dbConditionInt('g.groupid', $options['groupids']);
     }
     // 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'] = 'hg.hostid';
         }
         $sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
         $sqlParts['where'][] = dbConditionInt('hg.hostid', $options['hostids']);
         $sqlParts['where']['hgg'] = 'hg.groupid=g.groupid';
     }
     // triggerids
     if (!is_null($options['triggerids'])) {
         zbx_value2array($options['triggerids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['triggerid'] = 'f.triggerid';
         }
         $sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
         $sqlParts['from']['functions'] = 'functions f';
         $sqlParts['from']['items'] = 'items i';
         $sqlParts['where'][] = dbConditionInt('f.triggerid', $options['triggerids']);
         $sqlParts['where']['fi'] = 'f.itemid=i.itemid';
         $sqlParts['where']['hgi'] = 'hg.hostid=i.hostid';
         $sqlParts['where']['hgg'] = 'hg.groupid=g.groupid';
     }
     // graphids
     if (!is_null($options['graphids'])) {
         zbx_value2array($options['graphids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['graphid'] = 'gi.graphid';
         }
         $sqlParts['from']['gi'] = 'graphs_items gi';
         $sqlParts['from']['i'] = 'items i';
         $sqlParts['from']['hg'] = 'hosts_groups hg';
         $sqlParts['where'][] = dbConditionInt('gi.graphid', $options['graphids']);
         $sqlParts['where']['hgg'] = 'hg.groupid=g.groupid';
         $sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
         $sqlParts['where']['hgi'] = 'hg.hostid=i.hostid';
     }
     // maintenanceids
     if (!is_null($options['maintenanceids'])) {
         zbx_value2array($options['maintenanceids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['maintenanceid'] = 'mg.maintenanceid';
         }
         $sqlParts['from']['maintenances_groups'] = 'maintenances_groups mg';
         $sqlParts['where'][] = dbConditionInt('mg.maintenanceid', $options['maintenanceids']);
         $sqlParts['where']['hmh'] = 'g.groupid=mg.groupid';
     }
     // monitored_hosts, real_hosts, templated_hosts, not_proxy_hosts, with_hosts_and_templates
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CHostGroup.php


注:本文中的getUserGroupsByUserId函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。