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


PHP str_in_array函数代码示例

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


在下文中一共展示了str_in_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addItem

 public function addItem($value, $caption = '', $selected = null, $enabled = 'yes')
 {
     if ($value instanceof CComboItem || $value instanceof COptGroup) {
         parent::addItem($value);
     } else {
         $title = false;
         // if caption is too long ( > 44 symbols), we add new class - 'selectShorten',
         // so that the select box would not stretch
         if (zbx_strlen($caption) > 44 && !$this->hasClass('selectShorten')) {
             $this->setAttribute('class', $this->getAttribute('class') . ' selectShorten');
             $title = true;
         }
         if (is_null($selected)) {
             $selected = 'no';
             if (is_array($this->value)) {
                 if (str_in_array($value, $this->value)) {
                     $selected = 'yes';
                 }
             } elseif (strcmp($value, $this->value) == 0) {
                 $selected = 'yes';
             }
         } else {
             $selected = 'yes';
         }
         $citem = new CComboItem($value, $caption, $selected, $enabled);
         if ($title) {
             $citem->setTitle($caption);
         }
         parent::addItem($citem);
     }
 }
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:31,代码来源:class.ccombobox.php

示例2: addItem

 public function addItem($value, $caption = '', $selected = null, $enabled = true, $class = null)
 {
     if ($value instanceof CComboItem || $value instanceof COptGroup) {
         parent::addItem($value);
     } else {
         if (is_null($selected)) {
             $selected = 'no';
             if (is_array($this->value)) {
                 if (str_in_array($value, $this->value)) {
                     $selected = 'yes';
                 }
             } elseif (strcmp($value, $this->value) == 0) {
                 $selected = 'yes';
             }
         } else {
             $selected = 'yes';
         }
         $citem = new CComboItem($value, $caption, $selected, $enabled);
         if ($class !== null) {
             $citem->addClass($class);
         }
         parent::addItem($citem);
     }
     return $this;
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:25,代码来源:CComboBox.php

示例3: addItem

 public function addItem($value, $caption = '', $selected = null, $enabled = 'yes', $class = null)
 {
     if (is_null($selected)) {
         if (is_array($this->value)) {
             if (str_in_array($value, $this->value)) {
                 $this->value_exist = 1;
             }
         } elseif (strcmp($value, $this->value) == 0) {
             $this->value_exist = 1;
         }
     }
     parent::addItem($value, $caption, $selected, $enabled, $class);
 }
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:13,代码来源:CEditableComboBox.php

示例4: addItem

 public function addItem($value, $caption, $selected = null, $enabled = 'yes')
 {
     if (is_null($selected)) {
         if (is_array($this->value)) {
             if (str_in_array($value, $this->value)) {
                 $selected = 1;
             }
         } else {
             if (strcmp($value, $this->value) == 0) {
                 $selected = 1;
             }
         }
     }
     if (is_bool($selected) && $selected || is_int($selected) && $selected != 0 || is_string($selected) && ($selected == 'yes' || $selected == 'selected' || $selected == 'on')) {
         $this->lbox->addItem($value, $caption, null, $enabled);
         $this->form->addVar($this->varname . '[' . $value . ']', $value);
     } else {
         $this->rbox->addItem($value, $caption, null, $enabled);
     }
 }
开发者ID:rennhak,项目名称:zabbix,代码行数:20,代码来源:class.ctweenbox.php

示例5: addItem

 public function addItem($value, $caption = '', $selected = NULL, $enabled = 'yes')
 {
     //			if($enabled=='no') return;	/* disable item method 1 */
     if (strtolower(get_class($value)) == 'ccomboitem') {
         parent::addItem($value);
     } else {
         if (is_null($selected)) {
             $selected = 'no';
             if (is_array($this->value)) {
                 if (str_in_array($value, $this->value)) {
                     $selected = 'yes';
                 }
             } else {
                 if (strcmp($value, $this->value) == 0) {
                     $selected = 'yes';
                 }
             }
         }
         parent::addItem(new CComboItem($value, $caption, $selected, $enabled));
     }
 }
开发者ID:rennhak,项目名称:zabbix,代码行数:21,代码来源:class.ccombobox.php

示例6: addItem

 public function addItem($value, $caption = '', $selected = NULL, $enabled = 'yes')
 {
     //			if($enabled=='no') return;	/* disable item method 1 */
     if (is_object($value) && zbx_strtolower(get_class($value)) == 'ccomboitem') {
         parent::addItem($value);
     } else {
         if (zbx_strlen($caption) > 44) {
             $this->setAttribute('class', 'select selectShorten');
         }
         if (is_null($selected)) {
             $selected = 'no';
             if (is_array($this->value)) {
                 if (str_in_array($value, $this->value)) {
                     $selected = 'yes';
                 }
             } else {
                 if (strcmp($value, $this->value) == 0) {
                     $selected = 'yes';
                 }
             }
         }
         parent::addItem(new CComboItem($value, $caption, $selected, $enabled));
     }
 }
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:24,代码来源:class.ccombobox.php

示例7: get


//.........这里部分代码省略.........
                 }
                 // druleids
                 if (isset($dservice['druleid']) && is_null($options['selectDRules'])) {
                     if (!isset($result[$dservice['dserviceid']]['drules'])) {
                         $result[$dservice['dserviceid']]['drules'] = array();
                     }
                     $result[$dservice['dserviceid']]['drules'][] = array('druleid' => $dservice['druleid']);
                 }
                 // dhostids
                 if (isset($dservice['dhostid']) && is_null($options['selectDHosts'])) {
                     if (!isset($result[$dservice['dserviceid']]['dhosts'])) {
                         $result[$dservice['dserviceid']]['dhosts'] = array();
                     }
                     $result[$dservice['dserviceid']]['dhosts'][] = array('dhostid' => $dservice['dhostid']);
                 }
                 // dcheckids
                 if (isset($dservice['dcheckid']) && is_null($options['selectDChecks'])) {
                     if (!isset($result[$dservice['dserviceid']]['dchecks'])) {
                         $result[$dservice['dserviceid']]['dchecks'] = array();
                     }
                     $result[$dservice['dserviceid']]['dchecks'][] = array('dcheckid' => $dservice['dcheckid']);
                 }
                 $result[$dservice['dserviceid']] += $dservice;
             }
         }
     }
     if (!is_null($options['countOutput'])) {
         return $result;
     }
     // Adding Objects
     // select_drules
     if (!is_null($options['selectDRules'])) {
         $objParams = array('nodeids' => $nodeids, 'dserviceids' => $dserviceids, 'preservekeys' => 1);
         if (is_array($options['selectDRules']) || str_in_array($options['selectDRules'], $subselectsAllowedOutputs)) {
             $objParams['output'] = $options['selectDRules'];
             $drules = API::DRule()->get($objParams);
             if (!is_null($options['limitSelects'])) {
                 order_result($drules, 'name');
             }
             foreach ($drules as $druleid => $drule) {
                 unset($drules[$druleid]['dservices']);
                 $count = array();
                 foreach ($drule['dservices'] as $dnum => $dservice) {
                     if (!is_null($options['limitSelects'])) {
                         if (!isset($count[$dservice['dserviceid']])) {
                             $count[$dservice['dserviceid']] = 0;
                         }
                         $count[$dservice['dserviceid']]++;
                         if ($count[$dservice['dserviceid']] > $options['limitSelects']) {
                             continue;
                         }
                     }
                     $result[$dservice['dserviceid']]['drules'][] =& $drules[$druleid];
                 }
             }
         } elseif (API_OUTPUT_COUNT == $options['selectDRules']) {
             $objParams['countOutput'] = 1;
             $objParams['groupCount'] = 1;
             $drules = API::DRule()->get($objParams);
             $drules = zbx_toHash($drules, 'dserviceid');
             foreach ($result as $dserviceid => $dservice) {
                 if (isset($drules[$dserviceid])) {
                     $result[$dserviceid]['drules'] = $drules[$dserviceid]['rowscount'];
                 } else {
                     $result[$dserviceid]['drules'] = 0;
                 }
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:67,代码来源:CDService.php

示例8: get


//.........这里部分代码省略.........
     }
     // time_till
     if (!is_null($options['time_till'])) {
         $sql_parts['select']['clock'] = 'h.clock';
         $sql_parts['where']['clock_till'] = 'h.clock<=' . $options['time_till'];
     }
     // filter
     if (is_array($options['filter'])) {
         zbx_db_filter($sql_parts['from']['history'], $options, $sql_parts);
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search($sql_parts['from']['history'], $options, $sql_parts);
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         unset($sql_parts['select']['clock']);
         $sql_parts['select']['history'] = 'h.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sql_parts['select'] = array('count(DISTINCT h.hostid) as rowscount');
         //groupCount
         if (!is_null($options['groupCount'])) {
             foreach ($sql_parts['group'] as $key => $fields) {
                 $sql_parts['select'][$key] = $fields;
             }
         }
     }
     // groupOutput
     $groupOutput = false;
     if (!is_null($options['groupOutput'])) {
         if (str_in_array('h.' . $options['groupOutput'], $sql_parts['select']) || str_in_array('h.*', $sql_parts['select'])) {
             $groupOutput = true;
         }
     }
     // order
     // restrict not allowed columns for sorting
     $options['sortfield'] = str_in_array($options['sortfield'], $sort_columns) ? $options['sortfield'] : '';
     if (!zbx_empty($options['sortfield'])) {
         $sortorder = $options['sortorder'] == ZBX_SORT_DOWN ? ZBX_SORT_DOWN : ZBX_SORT_UP;
         if ($options['sortfield'] == 'clock') {
             $sql_parts['order']['itemid'] = 'h.itemid ' . $sortorder;
         }
         $sql_parts['order'][$options['sortfield']] = 'h.' . $options['sortfield'] . ' ' . $sortorder;
         if (!str_in_array('h.' . $options['sortfield'], $sql_parts['select']) && !str_in_array('h.*', $sql_parts['select'])) {
             $sql_parts['select'][$options['sortfield']] = 'h.' . $options['sortfield'];
         }
     }
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sql_parts['limit'] = $options['limit'];
     }
     //---------------
     $itemids = array();
     $triggerids = array();
     $sql_parts['select'] = array_unique($sql_parts['select']);
     $sql_parts['from'] = array_unique($sql_parts['from']);
     $sql_parts['where'] = array_unique($sql_parts['where']);
     $sql_parts['order'] = array_unique($sql_parts['order']);
     $sql_select = '';
     $sql_from = '';
     $sql_where = '';
     $sql_order = '';
     if (!empty($sql_parts['select'])) {
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:67,代码来源:class.chistory.php

示例9: applyQuerySortField

 /**
  * Adds a specific property from the 'sortfield' parameter to the $sqlParts array.
  *
  * @param string $sortfield
  * @param string $sortorder
  * @param string $alias
  * @param array  $sqlParts
  *
  * @return array
  */
 protected function applyQuerySortField($sortfield, $sortorder, $alias, array $sqlParts)
 {
     // add sort field to select if distinct is used
     if (count($sqlParts['from']) > 1 && !str_in_array($alias . '.' . $sortfield, $sqlParts['select']) && !str_in_array($alias . '.*', $sqlParts['select'])) {
         $sqlParts['select'][$sortfield] = $alias . '.' . $sortfield;
     }
     $sqlParts['order'][$alias . '.' . $sortfield] = $alias . '.' . $sortfield . $sortorder;
     return $sqlParts;
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:19,代码来源:CApiService.php

示例10: add_host_profile_ext

function add_host_profile_ext($hostid, $ext_host_profiles = array())
{
    $ext_profiles_fields = array('device_alias', 'device_type', 'device_chassis', 'device_os', 'device_os_short', 'device_hw_arch', 'device_serial', 'device_model', 'device_tag', 'device_vendor', 'device_contract', 'device_who', 'device_status', 'device_app_01', 'device_app_02', 'device_app_03', 'device_app_04', 'device_app_05', 'device_url_1', 'device_url_2', 'device_url_3', 'device_networks', 'device_notes', 'device_hardware', 'device_software', 'ip_subnet_mask', 'ip_router', 'ip_macaddress', 'oob_ip', 'oob_subnet_mask', 'oob_router', 'date_hw_buy', 'date_hw_install', 'date_hw_expiry', 'date_hw_decomm', 'site_street_1', 'site_street_2', 'site_street_3', 'site_city', 'site_state', 'site_country', 'site_zip', 'site_rack', 'site_notes', 'poc_1_name', 'poc_1_email', 'poc_1_phone_1', 'poc_1_phone_2', 'poc_1_cell', 'poc_1_screen', 'poc_1_notes', 'poc_2_name', 'poc_2_email', 'poc_2_phone_1', 'poc_2_phone_2', 'poc_2_cell', 'poc_2_screen', 'poc_2_notes');
    $result = DBselect('SELECT * FROM hosts_profiles_ext WHERE hostid=' . $hostid);
    if (DBfetch($result)) {
        error(S_HOST_PROFILE . SPACE . S_ALREADY_EXISTS);
        return false;
    }
    $sql = 'INSERT INTO hosts_profiles_ext (hostid,';
    $values = ' VALUES (' . $hostid . ',';
    foreach ($ext_host_profiles as $field => $value) {
        if (str_in_array($field, $ext_profiles_fields)) {
            $sql .= $field . ',';
            $values .= zbx_dbstr($value) . ',';
        }
    }
    $sql = rtrim($sql, ',') . ')';
    $values = rtrim($values, ',') . ')';
    $result = DBexecute($sql . $values);
    return $result;
}
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:21,代码来源:hosts.inc.php

示例11: DBend

            $result = API::Itemprototype()->update($item);
        } else {
            $result = API::Itemprototype()->create($item);
        }
    }
    $result = DBend($result);
    if (hasRequest('add')) {
        show_messages($result, _('Item prototype added'), _('Cannot add item prototype'));
    } else {
        show_messages($result, _('Item prototype updated'), _('Cannot update item prototype'));
    }
    if ($result) {
        unset($_REQUEST['itemid'], $_REQUEST['form']);
        uncheckTableRows(getRequest('parent_discoveryid'));
    }
} elseif (hasRequest('action') && str_in_array(getRequest('action'), ['itemprototype.massenable', 'itemprototype.massdisable']) && hasRequest('group_itemid')) {
    $groupItemId = getRequest('group_itemid');
    $enable = getRequest('action') == 'itemprototype.massenable';
    DBstart();
    $result = $enable ? activate_item($groupItemId) : disable_item($groupItemId);
    $result = DBend($result);
    $updated = count($groupItemId);
    $messageSuccess = $enable ? _n('Item prototype enabled', 'Item prototypes enabled', $updated) : _n('Item prototype disabled', 'Item prototypes disabled', $updated);
    $messageFailed = $enable ? _n('Cannot enable item prototype', 'Cannot enable item prototypes', $updated) : _n('Cannot disable item prototype', 'Cannot disable item prototypes', $updated);
    if ($result) {
        uncheckTableRows(getRequest('parent_discoveryid'));
    }
    show_messages($result, $messageSuccess, $messageFailed);
} elseif (hasRequest('action') && getRequest('action') == 'itemprototype.massdelete' && hasRequest('group_itemid')) {
    DBstart();
    $result = API::Itemprototype()->delete(getRequest('group_itemid'));
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:31,代码来源:disc_prototypes.php

示例12: get


//.........这里部分代码省略.........
     $sqlParts['group'] = array_unique($sqlParts['group']);
     $sqlParts['order'] = array_unique($sqlParts['order']);
     $sqlSelect = '';
     $sqlFrom = '';
     $sqlWhere = '';
     $sqlGroup = '';
     $sqlOrder = '';
     if (!empty($sqlParts['select'])) {
         $sqlSelect .= implode(',', $sqlParts['select']);
     }
     if (!empty($sqlParts['from'])) {
         $sqlFrom .= implode(',', $sqlParts['from']);
     }
     if (!empty($sqlParts['where'])) {
         $sqlWhere .= ' AND ' . implode(' AND ', $sqlParts['where']);
     }
     if (!empty($sqlParts['group'])) {
         $sqlWhere .= ' GROUP BY ' . implode(',', $sqlParts['group']);
     }
     if (!empty($sqlParts['order'])) {
         $sqlOrder .= ' ORDER BY ' . implode(',', $sqlParts['order']);
     }
     $sqlLimit = $sqlParts['limit'];
     $sql = 'SELECT ' . zbx_db_distinct($sqlParts) . ' ' . $sqlSelect . ' FROM ' . $sqlFrom . ' WHERE ' . DBin_node('a.applicationid', $nodeids) . $sqlWhere . $sqlGroup . $sqlOrder;
     $res = DBselect($sql, $sqlLimit);
     while ($application = DBfetch($res)) {
         if (!is_null($options['countOutput'])) {
             if (!is_null($options['groupCount'])) {
                 $result[] = $application;
             } else {
                 $result = $application['rowscount'];
             }
         } else {
             $applicationids[$application['applicationid']] = $application['applicationid'];
             if ($options['output'] == API_OUTPUT_SHORTEN) {
                 $result[$application['applicationid']] = array('applicationid' => $application['applicationid']);
             } else {
                 if (!isset($result[$application['applicationid']])) {
                     $result[$application['applicationid']] = array();
                 }
                 if (!is_null($options['selectHosts']) && !isset($result[$application['applicationid']]['hosts'])) {
                     $result[$application['applicationid']]['hosts'] = array();
                 }
                 if (!is_null($options['selectItems']) && !isset($result[$application['applicationid']]['items'])) {
                     $result[$application['applicationid']]['items'] = array();
                 }
                 // hostids
                 if (isset($application['hostid']) && is_null($options['selectHosts'])) {
                     if (!isset($result[$application['applicationid']]['hosts'])) {
                         $result[$application['applicationid']]['hosts'] = array();
                     }
                     $result[$application['applicationid']]['hosts'][] = array('hostid' => $application['hostid']);
                 }
                 // itemids
                 if (isset($application['itemid']) && is_null($options['selectItems'])) {
                     if (!isset($result[$application['applicationid']]['items'])) {
                         $result[$application['applicationid']]['items'] = array();
                     }
                     $result[$application['applicationid']]['items'][] = array('itemid' => $application['itemid']);
                     unset($application['itemid']);
                 }
                 $result[$application['applicationid']] += $application;
             }
         }
     }
     if (!is_null($options['countOutput'])) {
         return $result;
     }
     // adding objects
     // adding hosts
     if ($options['selectHosts'] !== null && (is_array($options['selectHosts']) || str_in_array($options['selectHosts'], $subselectsAllowedOutputs))) {
         $objParams = array('output' => $options['selectHosts'], 'applicationids' => $applicationids, 'nopermissions' => 1, 'templated_hosts' => true, 'preservekeys' => 1);
         $hosts = API::Host()->get($objParams);
         foreach ($hosts as $hostid => $host) {
             $iapplications = $host['applications'];
             unset($host['applications']);
             foreach ($iapplications as $application) {
                 $result[$application['applicationid']]['hosts'][] = $host;
             }
         }
     }
     // adding objects
     // adding items
     if (!is_null($options['selectItems']) && str_in_array($options['selectItems'], $subselectsAllowedOutputs)) {
         $objParams = array('output' => $options['selectItems'], 'applicationids' => $applicationids, 'nopermissions' => true, 'preservekeys' => true);
         $items = API::Item()->get($objParams);
         foreach ($items as $itemid => $item) {
             $iapplications = $item['applications'];
             unset($item['applications']);
             foreach ($iapplications as $application) {
                 $result[$application['applicationid']]['items'][] = $item;
             }
         }
     }
     // removing keys (hash -> array)
     if (is_null($options['preservekeys'])) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CApplication.php

示例13: DBend

            $result = API::DiscoveryRule()->update($newItem);
            $result = DBend($result);
        } else {
            $result = API::DiscoveryRule()->create([$newItem]);
        }
    }
    if (hasRequest('add')) {
        show_messages($result, _('Discovery rule created'), _('Cannot add discovery rule'));
    } else {
        show_messages($result, _('Discovery rule updated'), _('Cannot update discovery rule'));
    }
    if ($result) {
        unset($_REQUEST['itemid'], $_REQUEST['form']);
        uncheckTableRows(getRequest('hostid'));
    }
} elseif (hasRequest('action') && str_in_array(getRequest('action'), ['discoveryrule.massenable', 'discoveryrule.massdisable']) && hasRequest('g_hostdruleid')) {
    $groupHostDiscoveryRuleId = getRequest('g_hostdruleid');
    $enable = getRequest('action') == 'discoveryrule.massenable';
    DBstart();
    $result = $enable ? activate_item($groupHostDiscoveryRuleId) : disable_item($groupHostDiscoveryRuleId);
    $result = DBend($result);
    if ($result) {
        uncheckTableRows(getRequest('hostid'));
    }
    $updated = count($groupHostDiscoveryRuleId);
    $messageSuccess = $enable ? _n('Discovery rule enabled', 'Discovery rules enabled', $updated) : _n('Discovery rule disabled', 'Discovery rules disabled', $updated);
    $messageFailed = $enable ? _n('Cannot enable discovery rule', 'Cannot enable discovery rules', $updated) : _n('Cannot disable discovery rule', 'Cannot disable discovery rules', $updated);
    show_messages($result, $messageSuccess, $messageFailed);
} elseif (hasRequest('action') && getRequest('action') == 'discoveryrule.massdelete' && hasRequest('g_hostdruleid')) {
    $result = API::DiscoveryRule()->delete(getRequest('g_hostdruleid'));
    if ($result) {
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:31,代码来源:host_discovery.php

示例14: checkInput


//.........这里部分代码省略.........
             $item['delay_flex'] = '';
         }
         if ($fullItem['value_type'] == ITEM_VALUE_TYPE_STR) {
             $item['delta'] = 0;
         }
         if ($fullItem['value_type'] != ITEM_VALUE_TYPE_UINT64) {
             $item['data_type'] = 0;
         }
         // check if the item requires an interface
         $itemInterfaceType = itemTypeInterface($fullItem['type']);
         if ($itemInterfaceType !== false && $host['status'] != HOST_STATUS_TEMPLATE) {
             if (!$fullItem['interfaceid']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No interface found.'));
             } elseif (!isset($interfaces[$fullItem['interfaceid']]) || bccomp($interfaces[$fullItem['interfaceid']]['hostid'], $fullItem['hostid']) != 0) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Item uses host interface from non-parent host.'));
             } elseif ($itemInterfaceType !== INTERFACE_TYPE_ANY && $interfaces[$fullItem['interfaceid']]['type'] != $itemInterfaceType) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Item uses incorrect interface type.'));
             }
         } else {
             $item['interfaceid'] = 0;
         }
         // item key
         if ($fullItem['type'] == ITEM_TYPE_DB_MONITOR && strcmp($fullItem['key_'], ZBX_DEFAULT_KEY_DB_MONITOR) == 0 || $fullItem['type'] == ITEM_TYPE_SSH && strcmp($fullItem['key_'], ZBX_DEFAULT_KEY_SSH) == 0 || $fullItem['type'] == ITEM_TYPE_TELNET && strcmp($fullItem['key_'], ZBX_DEFAULT_KEY_TELNET) == 0 || $fullItem['type'] == ITEM_TYPE_JMX && strcmp($fullItem['key_'], ZBX_DEFAULT_KEY_JMX) == 0) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Check the key, please. Default example was passed.'));
         }
         // key
         $itemKey = new CItemKey($fullItem['key_']);
         if (!$itemKey->isValid()) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _params($this->getErrorMsg(self::ERROR_INVALID_KEY), array($fullItem['key_'], $fullItem['name'], $host['name'], $itemKey->getError())));
         }
         // parameters
         if ($fullItem['type'] == ITEM_TYPE_AGGREGATE) {
             $params = $itemKey->getParameters();
             if (!str_in_array($itemKey->getKeyId(), array('grpmax', 'grpmin', 'grpsum', 'grpavg')) || count($params) != 4 || !str_in_array($params[2], array('last', 'min', 'max', 'avg', 'sum', 'count'))) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Key "%1$s" does not match <grpmax|grpmin|grpsum|grpavg>["Host group(s)", "Item key",' . ' "<last|min|max|avg|sum|count>", "parameter"].', $itemKey->getKeyId()));
             }
         }
         // type of information
         if ($fullItem['type'] == ITEM_TYPE_AGGREGATE && $fullItem['value_type'] != ITEM_VALUE_TYPE_FLOAT && $fullItem['value_type'] != ITEM_VALUE_TYPE_UINT64) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Type of information must be "Numeric (float)" for aggregate items.'));
         }
         // log
         if ($fullItem['value_type'] != ITEM_VALUE_TYPE_LOG && str_in_array($itemKey->getKeyId(), array('log', 'logrt', 'eventlog'))) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Type of information must be "Log" for log key.'));
         }
         // update interval
         if ($fullItem['type'] != ITEM_TYPE_TRAPPER && $fullItem['type'] != ITEM_TYPE_SNMPTRAP) {
             $res = calculateItemNextcheck(0, $fullItem['type'], $fullItem['delay'], $fullItem['delay_flex'], time());
             if ($res == ZBX_JAN_2038) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Item will not be refreshed. Please enter a correct update interval.'));
             }
         }
         // ssh, telnet
         if ($fullItem['type'] == ITEM_TYPE_SSH || $fullItem['type'] == ITEM_TYPE_TELNET) {
             if (zbx_empty($fullItem['username'])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No authentication user name specified.'));
             }
             if ($fullItem['type'] == ITEM_TYPE_SSH && $fullItem['authtype'] == ITEM_AUTHTYPE_PUBLICKEY) {
                 if (zbx_empty($fullItem['publickey'])) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No public key file specified.'));
                 }
                 if (zbx_empty($fullItem['privatekey'])) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No private key file specified.'));
                 }
             }
         }
开发者ID:hujingguang,项目名称:work,代码行数:67,代码来源:CItemGeneral.php

示例15: DBfetch

/**
 * Returns the next data set from a DB resource or false if there are no more results.
 *
 * @param resource $cursor
 * @param bool $convertNulls	convert all null values to string zeroes
 *
 * @return array|bool
 */
function DBfetch($cursor, $convertNulls = true)
{
    global $DB;
    $result = false;
    if (!isset($DB['DB']) || empty($DB['DB']) || is_bool($cursor)) {
        return $result;
    }
    switch ($DB['TYPE']) {
        case ZBX_DB_MYSQL:
            $result = mysqli_fetch_assoc($cursor);
            if (!$result) {
                mysqli_free_result($cursor);
            }
            break;
        case ZBX_DB_POSTGRESQL:
            if (!($result = pg_fetch_assoc($cursor))) {
                pg_free_result($cursor);
            }
            break;
        case ZBX_DB_ORACLE:
            if ($row = oci_fetch_assoc($cursor)) {
                $result = array();
                foreach ($row as $key => $value) {
                    $field_type = strtolower(oci_field_type($cursor, $key));
                    // Oracle does not support NULL values for string fields, so if the string is empty, it will return NULL
                    // convert it to an empty string to be consistent with other databases
                    $value = str_in_array($field_type, array('varchar', 'varchar2', 'blob', 'clob')) && is_null($value) ? '' : $value;
                    if (is_object($value) && strpos($field_type, 'lob') !== false) {
                        $value = $value->load();
                    }
                    $result[strtolower($key)] = $value;
                }
            }
            break;
        case ZBX_DB_DB2:
            if (!($result = db2_fetch_assoc($cursor))) {
                db2_free_result($cursor);
            } else {
                // cast all of the values to string to be consistent with other DB drivers: all of them return
                // only strings.
                foreach ($result as &$value) {
                    if ($value !== null) {
                        $value = (string) $value;
                    }
                }
                unset($value);
            }
            break;
        case ZBX_DB_SQLITE3:
            if ($DB['TRANSACTIONS'] == 0) {
                lock_sqlite3_access();
            }
            if (!($result = $cursor->fetchArray(SQLITE3_ASSOC))) {
                unset($cursor);
            } else {
                // cast all of the values to string to be consistent with other DB drivers: all of them return
                // only strings.
                foreach ($result as &$value) {
                    $value = (string) $value;
                }
                unset($value);
            }
            if ($DB['TRANSACTIONS'] == 0) {
                unlock_sqlite3_access();
            }
            break;
    }
    if ($result) {
        if ($convertNulls) {
            foreach ($result as $key => $val) {
                if (is_null($val)) {
                    $result[$key] = '0';
                }
            }
        }
        return $result;
    }
    return false;
}
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:87,代码来源:db.inc.php


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