本文整理汇总了PHP中API::Image方法的典型用法代码示例。如果您正苦于以下问题:PHP API::Image方法的具体用法?PHP API::Image怎么用?PHP API::Image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::Image方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getImageByIdent
function getImageByIdent($ident)
{
zbx_value2array($ident);
if (!isset($ident['name'])) {
return 0;
}
static $images;
if (is_null($images)) {
$images = array();
$dbImages = API::Image()->get(array('output' => array('imageid', 'name'), 'nodeids' => get_current_nodeid(true)));
foreach ($dbImages as $image) {
if (!isset($images[$image['name']])) {
$images[$image['name']] = array();
}
$nodeName = get_node_name_by_elid($image['imageid'], true);
if (!is_null($nodeName)) {
$images[$image['name']][$nodeName] = $image;
} else {
$images[$image['name']][] = $image;
}
}
}
$ident['name'] = trim($ident['name'], ' ');
if (!isset($images[$ident['name']])) {
return 0;
}
$searchedImages = $images[$ident['name']];
if (!isset($ident['node'])) {
return reset($searchedImages);
} elseif (isset($searchedImages[$ident['node']])) {
return $searchedImages[$ident['node']];
} else {
return 0;
}
}
示例2: getImageByIdent
function getImageByIdent($ident)
{
zbx_value2array($ident);
if (!isset($ident['name'])) {
return 0;
}
static $images;
if ($images === null) {
$images = array();
$dbImages = API::Image()->get(array('output' => array('imageid', 'name')));
foreach ($dbImages as $image) {
if (!isset($images[$image['name']])) {
$images[$image['name']] = array();
}
$images[$image['name']][] = $image;
}
}
$ident['name'] = trim($ident['name'], ' ');
return isset($images[$ident['name']]) ? reset($images[$ident['name']]) : 0;
}
示例3: validateMappings
/**
* Checks icon maps.
* @throws APIException
* @param $iconMaps
* @param bool $mustExist if icon map should be checked against having at least one mapping
* @return void
*/
protected function validateMappings($iconMaps, $mustExist = true)
{
$inventoryFields = getHostInventories();
$imageids = API::Image()->get(['output' => ['imageid'], 'preservekeys' => true, 'filter' => ['imagetype' => IMAGE_TYPE_ICON]]);
foreach ($iconMaps as $iconMap) {
if (isset($iconMap['mappings']) && empty($iconMap['mappings'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map "%s" must have at least one mapping.', $iconMap['name']));
} elseif (!isset($iconMap['mappings'])) {
if ($mustExist) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map "%s" must have at least one mapping.', $iconMap['name']));
} else {
continue;
}
}
$uniqField = [];
foreach ($iconMap['mappings'] as $mapping) {
if (!isset($mapping['expression'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Required field "expression" is missing in icon mapping.'));
} elseif (!isset($mapping['inventory_link'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Required field "inventory_link" is missing in icon mapping.'));
} elseif (!isset($mapping['iconid'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Required field "iconid" is missing in icon mapping.'));
} elseif (!isset($inventoryFields[$mapping['inventory_link']])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map "%1$s" has mapping with incorrect inventory link "%2$s".', $iconMap['name'], $mapping['inventory_link']));
} elseif (!isset($imageids[$mapping['iconid']])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map "%1$s" has mapping with incorrect iconid "%2$s".', $iconMap['name'], $mapping['iconid']));
}
try {
CGlobalRegexp::isValid($mapping['expression']);
} catch (Exception $e) {
switch ($e->getCode()) {
case CGlobalRegexp::ERROR_REGEXP_EMPTY:
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map "%s" cannot have mapping with empty expression.', $iconMap['name']));
break;
case CGlobalRegexp::ERROR_REGEXP_NOT_EXISTS:
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map "%s" cannot have mapping with global expression that does not exist.', $iconMap['name']));
break;
default:
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map "%s" has incorrect expression.', $iconMap['name']));
}
}
if (isset($uniqField[$mapping['inventory_link'] . $mapping['expression']])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon mapping entry "%1$s" against "%2$s" already exists.', $mapping['expression'], $inventoryFields[$mapping['inventory_link']]['title']));
}
$uniqField[$mapping['inventory_link'] . $mapping['expression']] = true;
}
}
}
示例4: parseMap
public static function parseMap($rules)
{
$importMaps = self::XMLtoArray(self::$xml);
if (!isset($importMaps['zabbix_export'])) {
$importMaps['zabbix_export'] = $importMaps;
}
if (CWebUser::$data['type'] == USER_TYPE_SUPER_ADMIN && isset($importMaps['zabbix_export']['images'])) {
$images = $importMaps['zabbix_export']['images'];
$images_to_add = array();
$images_to_update = array();
foreach ($images as $image) {
if (API::Image()->exists($image)) {
if ($image['imagetype'] == IMAGE_TYPE_ICON && !empty($rules['images']['updateExisting']) || $image['imagetype'] == IMAGE_TYPE_BACKGROUND && !empty($rules['images']['updateExisting'])) {
$options = array('filter' => array('name' => $image['name']), 'output' => array('imageid'));
$imgs = API::Image()->get($options);
$img = reset($imgs);
$image['imageid'] = $img['imageid'];
// image will be decoded in class.image.php
$image['image'] = $image['encodedImage'];
unset($image['encodedImage']);
$images_to_update[] = $image;
}
} else {
if ($image['imagetype'] == IMAGE_TYPE_ICON && !empty($rules['images']['createMissing']) || $image['imagetype'] == IMAGE_TYPE_BACKGROUND && !empty($rules['images']['createMissing'])) {
// No need to decode_base64
$image['image'] = $image['encodedImage'];
unset($image['encodedImage']);
$images_to_add[] = $image;
}
}
}
if (!empty($images_to_add)) {
$result = API::Image()->create($images_to_add);
if (!$result) {
throw new Exception(_('Cannot add image.'));
}
}
if (!empty($images_to_update)) {
$result = API::Image()->update($images_to_update);
if (!$result) {
throw new Exception(_('Cannot update image.'));
}
}
}
if (!isset($importMaps['zabbix_export']['sysmaps'])) {
return true;
}
$importMaps = $importMaps['zabbix_export']['sysmaps'];
foreach ($importMaps as $mnum => &$sysmap) {
unset($sysmap['sysmapid']);
$exists = API::Map()->exists(array('name' => $sysmap['name']));
if (!isset($sysmap['label_format'])) {
$sysmap['label_format'] = SYSMAP_LABEL_ADVANCED_OFF;
}
if ($exists && !empty($rules['maps']['updateExisting'])) {
$db_maps = API::Map()->getObjects(array('name' => $sysmap['name']));
if (empty($db_maps)) {
throw new Exception(_s('No permissions for map "%1$s".', $sysmap['name']));
}
$db_map = reset($db_maps);
$sysmap['sysmapid'] = $db_map['sysmapid'];
} else {
if ($exists || empty($rules['maps']['createMissing'])) {
info(_s('Map "%1$s" skipped - user rule.', $sysmap['name']));
unset($importMaps[$mnum]);
continue;
// break if not update updateExisting
}
}
if (isset($sysmap['backgroundid'])) {
$image = getImageByIdent($sysmap['backgroundid']);
if (!$image) {
error(_s('Cannot find background image "%1$s" used in map "%2$s".', $sysmap['backgroundid']['name'], $sysmap['name']));
$sysmap['backgroundid'] = 0;
} else {
$sysmap['backgroundid'] = $image['imageid'];
}
} else {
$sysmap['backgroundid'] = 0;
}
if (!isset($sysmap['selements'])) {
$sysmap['selements'] = array();
} else {
$sysmap['selements'] = array_values($sysmap['selements']);
}
if (!isset($sysmap['links'])) {
$sysmap['links'] = array();
} else {
$sysmap['links'] = array_values($sysmap['links']);
}
foreach ($sysmap['selements'] as &$selement) {
$nodeCaption = isset($selement['elementid']['node']) ? $selement['elementid']['node'] . ':' : '';
if (!isset($selement['elementid'])) {
$selement['elementid'] = 0;
}
switch ($selement['elementtype']) {
case SYSMAP_ELEMENT_TYPE_MAP:
$db_sysmaps = API::Map()->getObjects($selement['elementid']);
if (empty($db_sysmaps)) {
$error = _s('Cannot find map "%1$s" used in exported map "%2$s".', $nodeCaption . $selement['elementid']['name'], $sysmap['name']);
//.........这里部分代码省略.........
示例5: CWidget
}
$imageWidget = new CWidget();
$imageWidget->addPageHeader(_('CONFIGURATION OF IMAGES'), $form);
$data = array('form' => get_request('form'), 'displayNodes' => is_array(get_current_nodeid()), 'widget' => &$imageWidget);
if (!empty($data['form'])) {
if (isset($_REQUEST['imageid'])) {
$data['imageid'] = $_REQUEST['imageid'];
$data['imagename'] = $dbImage['name'];
$data['imagetype'] = $dbImage['imagetype'];
} else {
$data['imageid'] = null;
$data['imagename'] = get_request('name', '');
$data['imagetype'] = get_request('imagetype', 1);
}
$imageForm = new CView('administration.general.image.edit', $data);
} else {
$data['imagetype'] = get_request('imagetype', IMAGE_TYPE_ICON);
$data['images'] = API::Image()->get(array('filter' => array('imagetype' => $data['imagetype']), 'output' => array('imageid', 'imagetype', 'name')));
order_result($data['images'], 'name');
// nodes
if ($data['displayNodes']) {
foreach ($data['images'] as &$image) {
$image['nodename'] = get_node_name_by_elid($image['imageid'], true) . NAME_DELIMITER;
}
unset($image);
}
$imageForm = new CView('administration.general.image.list', $data);
}
$imageWidget->addItem($imageForm->render());
$imageWidget->show();
require_once dirname(__FILE__) . '/include/page_footer.php';
示例6: getImagesReferences
/**
* Get images references by image ids.
*
* @param array $imageIds
*
* @return array
*/
protected function getImagesReferences(array $imageIds)
{
$idents = array();
$images = API::Image()->get(array('imageids' => $imageIds, 'output' => API_OUTPUT_EXTEND, 'nodeids' => get_current_nodeid(true), 'preservekeys' => true));
foreach ($images as $id => $image) {
$idents[$id] = array('name' => $image['name']);
}
return $idents;
}
示例7: CComboBox
}
/*
* Display
*/
$generalComboBox = new CComboBox('configDropDown', 'adm.iconmapping.php', 'redirect(this.options[this.selectedIndex].value);');
$generalComboBox->addItems(array('adm.gui.php' => _('GUI'), 'adm.housekeeper.php' => _('Housekeeping'), 'adm.images.php' => _('Images'), 'adm.iconmapping.php' => _('Icon mapping'), 'adm.regexps.php' => _('Regular expressions'), 'adm.macros.php' => _('Macros'), 'adm.valuemapping.php' => _('Value mapping'), 'adm.workingtime.php' => _('Working time'), 'adm.triggerseverities.php' => _('Trigger severities'), 'adm.triggerdisplayoptions.php' => _('Trigger displaying options'), 'adm.other.php' => _('Other')));
$iconMapForm = new CForm();
$iconMapForm->cleanItems();
$iconMapForm->addItem($generalComboBox);
if (!isset($_REQUEST['form'])) {
$iconMapForm->addItem(new CSubmit('form', _('Create icon map')));
}
$iconMapWidget = new CWidget();
$iconMapWidget->addPageHeader(_('CONFIGURATION OF ICON MAPPING'), $iconMapForm);
$data = array('form_refresh' => get_request('form_refresh', 0), 'iconmapid' => get_request('iconmapid'), 'iconList' => array(), 'inventoryList' => array(), 'displayNodes' => is_array(get_current_nodeid()));
$iconList = API::Image()->get(array('filter' => array('imagetype' => IMAGE_TYPE_ICON), 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true));
order_result($iconList, 'name');
foreach ($iconList as $icon) {
$data['iconList'][$icon['imageid']] = $icon['name'];
}
$inventoryFields = getHostInventories();
foreach ($inventoryFields as $field) {
$data['inventoryList'][$field['nr']] = $field['title'];
}
if (isset($_REQUEST['form'])) {
if ($data['form_refresh'] || $_REQUEST['form'] === 'clone') {
$data['iconmap'] = get_request('iconmap');
} elseif (isset($_REQUEST['iconmapid'])) {
$data['iconmap'] = reset($iconMap);
} else {
$firstIcon = reset($iconList);
示例8: array
if (isset($_REQUEST['form'])) {
if (!isset($_REQUEST['sysmapid']) || isset($_REQUEST['form_refresh'])) {
$data = array('sysmap' => array('sysmapid' => getRequest('sysmapid'), 'name' => get_request('name', ''), 'width' => get_request('width', 800), 'height' => get_request('height', 600), 'backgroundid' => get_request('backgroundid', 0), 'iconmapid' => get_request('iconmapid', 0), 'label_format' => get_request('label_format', 0), 'label_type_host' => get_request('label_type_host', 2), 'label_type_hostgroup' => get_request('label_type_hostgroup', 2), 'label_type_trigger' => get_request('label_type_trigger', 2), 'label_type_map' => get_request('label_type_map', 2), 'label_type_image' => get_request('label_type_image', 2), 'label_string_host' => get_request('label_string_host', ''), 'label_string_hostgroup' => get_request('label_string_hostgroup', ''), 'label_string_trigger' => get_request('label_string_trigger', ''), 'label_string_map' => get_request('label_string_map', ''), 'label_string_image' => get_request('label_string_image', ''), 'label_type' => get_request('label_type', 0), 'label_location' => get_request('label_location', 0), 'highlight' => get_request('highlight', 0), 'markelements' => get_request('markelements', 0), 'expandproblem' => get_request('expandproblem', 0), 'show_unack' => get_request('show_unack', 0), 'severity_min' => get_request('severity_min', TRIGGER_SEVERITY_NOT_CLASSIFIED), 'urls' => get_request('urls', array())));
} else {
$data = array('sysmap' => $sysmap);
}
// config
$data['config'] = select_config();
// advanced labels
$data['labelTypes'] = sysmapElementLabel();
$data['labelTypesLimited'] = $data['labelTypes'];
unset($data['labelTypesLimited'][MAP_LABEL_TYPE_IP]);
$data['labelTypesImage'] = $data['labelTypesLimited'];
unset($data['labelTypesImage'][MAP_LABEL_TYPE_STATUS]);
// images
$data['images'] = API::Image()->get(array('output' => array('imageid', 'name'), 'filter' => array('imagetype' => IMAGE_TYPE_BACKGROUND)));
order_result($data['images'], 'name');
foreach ($data['images'] as $num => $image) {
$data['images'][$num]['name'] = get_node_name_by_elid($image['imageid'], null, NAME_DELIMITER) . $image['name'];
}
// icon maps
$data['iconMaps'] = API::IconMap()->get(array('output' => array('iconmapid', 'name'), 'preservekeys' => true));
order_result($data['iconMaps'], 'name');
// render view
$mapView = new CView('configuration.sysmap.edit', $data);
$mapView->render();
$mapView->show();
} else {
$data = array();
// get maps
$sortField = getPageSortField('name');
示例9: dirname
require_once dirname(__FILE__) . '/include/maps.inc.php';
$page['file'] = 'imgstore.php';
$page['type'] = detect_page_type(PAGE_TYPE_IMAGE);
require_once dirname(__FILE__) . '/include/page_header.php';
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields = array('css' => array(T_ZBX_INT, O_OPT, P_SYS, null, null), 'imageid' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'iconid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), 'width' => array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(1, 2000), null), 'height' => array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(1, 2000), null));
check_fields($fields);
$resize = false;
if (isset($_REQUEST['width']) || isset($_REQUEST['height'])) {
$resize = true;
$width = get_request('width', 0);
$height = get_request('height', 0);
}
if (isset($_REQUEST['css'])) {
$css = 'div.sysmap_iconid_0 {' . ' height: 50px;' . ' width: 50px;' . ' background-image: url("images/general/no_icon.png"); }' . "\n";
$images = API::Image()->get(array('filter' => array('imagetype' => IMAGE_TYPE_ICON), 'output' => API_OUTPUT_EXTEND, 'select_image' => 1));
foreach ($images as $image) {
$image['image'] = base64_decode($image['image']);
$ico = imagecreatefromstring($image['image']);
if ($resize) {
$ico = imageThumb($ico, $width, $height);
}
$w = imagesx($ico);
$h = imagesy($ico);
$css .= 'div.sysmap_iconid_' . $image['imageid'] . '{' . ' height: ' . $h . 'px;' . ' width: ' . $w . 'px;' . ' background: url("imgstore.php?iconid=' . $image['imageid'] . '&width=' . $w . '&height=' . $h . '") no-repeat center center;}' . "\n";
}
echo $css;
} elseif (isset($_REQUEST['iconid'])) {
$iconid = get_request('iconid', 0);
if ($iconid > 0) {
$image = get_image_by_imageid($iconid);
示例10: getRequest
$data['sysmap'] = ['sysmapid' => getRequest('sysmapid'), 'name' => getRequest('name', ''), 'width' => getRequest('width', 800), 'height' => getRequest('height', 600), 'backgroundid' => getRequest('backgroundid', 0), 'iconmapid' => getRequest('iconmapid', 0), 'label_format' => getRequest('label_format', 0), 'label_type_host' => getRequest('label_type_host', 2), 'label_type_hostgroup' => getRequest('label_type_hostgroup', 2), 'label_type_trigger' => getRequest('label_type_trigger', 2), 'label_type_map' => getRequest('label_type_map', 2), 'label_type_image' => getRequest('label_type_image', 2), 'label_string_host' => getRequest('label_string_host', ''), 'label_string_hostgroup' => getRequest('label_string_hostgroup', ''), 'label_string_trigger' => getRequest('label_string_trigger', ''), 'label_string_map' => getRequest('label_string_map', ''), 'label_string_image' => getRequest('label_string_image', ''), 'label_type' => getRequest('label_type', 0), 'label_location' => getRequest('label_location', 0), 'highlight' => getRequest('highlight', 0), 'markelements' => getRequest('markelements', 0), 'expandproblem' => getRequest('expandproblem', 0), 'show_unack' => getRequest('show_unack', 0), 'severity_min' => getRequest('severity_min', TRIGGER_SEVERITY_NOT_CLASSIFIED), 'urls' => getRequest('urls', []), 'userid' => getRequest('userid', hasRequest('form_refresh') ? '' : $current_userid), 'private' => getRequest('private', PRIVATE_SHARING), 'users' => getRequest('users', []), 'userGroups' => getRequest('userGroups', [])];
} else {
$data['sysmap'] = $sysmap;
}
$data['current_user_userid'] = $current_userid;
$data['form_refresh'] = getRequest('form_refresh');
// config
$data['config'] = select_config();
// advanced labels
$data['labelTypes'] = sysmapElementLabel();
$data['labelTypesLimited'] = $data['labelTypes'];
unset($data['labelTypesLimited'][MAP_LABEL_TYPE_IP]);
$data['labelTypesImage'] = $data['labelTypesLimited'];
unset($data['labelTypesImage'][MAP_LABEL_TYPE_STATUS]);
// images
$data['images'] = API::Image()->get(['output' => ['imageid', 'name'], 'filter' => ['imagetype' => IMAGE_TYPE_BACKGROUND]]);
order_result($data['images'], 'name');
// icon maps
$data['iconMaps'] = API::IconMap()->get(['output' => ['iconmapid', 'name'], 'preservekeys' => true]);
order_result($data['iconMaps'], 'name');
// render view
$mapView = new CView('monitoring.sysmap.edit', $data);
$mapView->render();
$mapView->show();
} else {
CProfile::delete('web.maps.sysmapid');
$sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'name'));
$sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP));
CProfile::update('web.' . $page['file'] . '.sort', $sortField, PROFILE_TYPE_STR);
CProfile::update('web.' . $page['file'] . '.sortorder', $sortOrder, PROFILE_TYPE_STR);
if (hasRequest('filter_set')) {
示例11: processImages
/**
* Import images.
*
* @throws Exception
*/
protected function processImages()
{
$allImages = $this->getFormattedImages();
if (empty($allImages)) {
return;
}
$imagesToUpdate = array();
$allImages = zbx_toHash($allImages, 'name');
$dbImages = DBselect('SELECT i.imageid,i.name FROM images i WHERE ' . dbConditionString('i.name', array_keys($allImages)));
while ($dbImage = DBfetch($dbImages)) {
$dbImage['image'] = $allImages[$dbImage['name']]['image'];
$imagesToUpdate[] = $dbImage;
unset($allImages[$dbImage['name']]);
}
if ($this->options['images']['createMissing']) {
API::Image()->create(array_values($allImages));
}
if ($this->options['images']['updateExisting']) {
API::Image()->update($imagesToUpdate);
}
}
示例12: getImagesReferences
/**
* Get images references by image ids.
*
* @param array $imageIds
*
* @return array
*/
protected function getImagesReferences(array $imageIds)
{
$ids = array();
$images = API::Image()->get(array('output' => array('imageid', 'name'), 'imageids' => $imageIds, 'preservekeys' => true));
foreach ($images as $id => $image) {
$ids[$id] = array('name' => $image['name']);
}
return $ids;
}
示例13: parseMap
public static function parseMap($rules)
{
$importMaps = self::XMLtoArray(self::$xml);
if (!isset($importMaps['zabbix_export'])) {
$importMaps['zabbix_export'] = $importMaps;
}
if (CWebUser::$data['type'] == USER_TYPE_SUPER_ADMIN && isset($importMaps['zabbix_export']['images'])) {
$allImages = $importMaps['zabbix_export']['images'];
$allImages = zbx_toHash($allImages, 'name');
$dbImages = API::Image()->get(array('output' => array('imageid', 'name'), 'filter' => array('name' => zbx_objectValues($allImages, 'name'))));
$dbImages = zbx_toHash($dbImages, 'name');
$imagesToCreate = array();
$imagesToUpdate = array();
foreach ($allImages as $imageName => $image) {
if (isset($dbImages[$imageName])) {
$image['imageid'] = $dbImages[$imageName]['imageid'];
$image['image'] = $image['encodedImage'];
unset($image['encodedImage'], $image['imagetype']);
$imagesToUpdate[] = $image;
} else {
$image['image'] = $image['encodedImage'];
unset($image['encodedImage']);
$imagesToCreate[] = $image;
}
}
if ($rules['images']['createMissing'] && $imagesToCreate) {
API::Image()->create($imagesToCreate);
}
if ($rules['images']['updateExisting'] && $imagesToUpdate) {
API::Image()->update($imagesToUpdate);
}
}
if (!isset($importMaps['zabbix_export']['sysmaps'])) {
return true;
}
$importMaps = $importMaps['zabbix_export']['sysmaps'];
foreach ($importMaps as $mnum => &$sysmap) {
unset($sysmap['sysmapid']);
if (!isset($sysmap['label_format'])) {
$sysmap['label_format'] = SYSMAP_LABEL_ADVANCED_OFF;
}
$mapExists = API::Map()->get(array('output' => array('sysmapid'), 'filter' => array('name' => $sysmap['name']), 'nopermissions' => true, 'limit' => 1));
if ($mapExists && $rules['maps']['updateExisting']) {
$db_maps = API::Map()->get(array('filter' => array('name' => $sysmap['name']), 'output' => array('sysmapid')));
if (empty($db_maps)) {
throw new Exception(_s('No permissions for map "%1$s".', $sysmap['name']));
}
$db_map = reset($db_maps);
$sysmap['sysmapid'] = $db_map['sysmapid'];
} elseif ($mapExists || !$rules['maps']['createMissing']) {
info(_s('Map "%1$s" skipped - user rule.', $sysmap['name']));
unset($importMaps[$mnum]);
continue;
}
if (isset($sysmap['backgroundid'])) {
$image = getImageByIdent($sysmap['backgroundid']);
if (!$image) {
error(_s('Cannot find background image "%1$s" used in map "%2$s".', $sysmap['backgroundid']['name'], $sysmap['name']));
$sysmap['backgroundid'] = 0;
} else {
$sysmap['backgroundid'] = $image['imageid'];
}
} else {
$sysmap['backgroundid'] = 0;
}
if (!isset($sysmap['selements'])) {
$sysmap['selements'] = array();
} else {
$sysmap['selements'] = array_values($sysmap['selements']);
}
if (!isset($sysmap['links'])) {
$sysmap['links'] = array();
} else {
$sysmap['links'] = array_values($sysmap['links']);
}
foreach ($sysmap['selements'] as &$selement) {
if (!isset($selement['elementid'])) {
$selement['elementid'] = 0;
}
switch ($selement['elementtype']) {
case SYSMAP_ELEMENT_TYPE_MAP:
$db_sysmaps = API::Map()->get(array('filter' => array($selement['elementid']), 'output' => array('sysmapid')));
if (empty($db_sysmaps)) {
$error = _s('Cannot find map "%1$s" used in exported map "%2$s".', $selement['elementid']['name'], $sysmap['name']);
throw new Exception($error);
}
$tmp = reset($db_sysmaps);
$selement['elementid'] = $tmp['sysmapid'];
break;
case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
$db_hostgroups = API::HostGroup()->get(array('filter' => array($selement['elementid']), 'output' => array('groupid')));
if (empty($db_hostgroups)) {
$error = _s('Cannot find group "%1$s" used in map "%2$s".', $selement['elementid']['name'], $sysmap['name']);
throw new Exception($error);
}
$tmp = reset($db_hostgroups);
$selement['elementid'] = $tmp['groupid'];
break;
case SYSMAP_ELEMENT_TYPE_HOST:
$db_hosts = API::Host()->get(array('filter' => array($selement['elementid']), 'output' => array('hostid')));
//.........这里部分代码省略.........
示例14: CComboBox
}
/*
* Display
*/
$generalComboBox = new CComboBox('configDropDown', 'adm.iconmapping.php', 'redirect(this.options[this.selectedIndex].value);');
$generalComboBox->addItems(array('adm.gui.php' => _('GUI'), 'adm.housekeeper.php' => _('Housekeeping'), 'adm.images.php' => _('Images'), 'adm.iconmapping.php' => _('Icon mapping'), 'adm.regexps.php' => _('Regular expressions'), 'adm.macros.php' => _('Macros'), 'adm.valuemapping.php' => _('Value mapping'), 'adm.workingtime.php' => _('Working time'), 'adm.triggerseverities.php' => _('Trigger severities'), 'adm.triggerdisplayoptions.php' => _('Trigger displaying options'), 'adm.other.php' => _('Other')));
$iconMapForm = new CForm();
$iconMapForm->cleanItems();
$iconMapForm->addItem($generalComboBox);
if (!isset($_REQUEST['form'])) {
$iconMapForm->addItem(new CSubmit('form', _('Create icon map')));
}
$iconMapWidget = new CWidget();
$iconMapWidget->addPageHeader(_('CONFIGURATION OF ICON MAPPING'), $iconMapForm);
$data = array('form_refresh' => get_request('form_refresh', 0), 'iconmapid' => get_request('iconmapid'), 'iconList' => array(), 'inventoryList' => array(), 'displayNodes' => is_array(get_current_nodeid()));
$iconList = API::Image()->get(array('output' => array('imageid', 'name'), 'filter' => array('imagetype' => IMAGE_TYPE_ICON), 'preservekeys' => true));
order_result($iconList, 'name');
foreach ($iconList as $icon) {
$data['iconList'][$icon['imageid']] = $icon['name'];
}
$inventoryFields = getHostInventories();
foreach ($inventoryFields as $field) {
$data['inventoryList'][$field['nr']] = $field['title'];
}
if (isset($_REQUEST['form'])) {
if ($data['form_refresh'] || $_REQUEST['form'] === 'clone') {
$data['iconmap'] = get_request('iconmap');
} elseif (isset($_REQUEST['iconmapid'])) {
$data['iconmap'] = reset($iconMap);
} else {
$firstIcon = reset($iconList);
示例15: elseif
}
} elseif (hasRequest('delete')) {
$result = API::IconMap()->delete([getRequest('iconmapid')]);
if ($result) {
unset($_REQUEST['form']);
}
show_messages($result, _('Icon map deleted'), _('Cannot delete icon map'));
} elseif (isset($_REQUEST['clone'])) {
unset($_REQUEST['iconmapid']);
$_REQUEST['form'] = 'clone';
}
/*
* Display
*/
$data = ['iconmapid' => getRequest('iconmapid'), 'iconList' => [], 'inventoryList' => []];
$iconList = API::Image()->get(['output' => ['imageid', 'name'], 'filter' => ['imagetype' => IMAGE_TYPE_ICON], 'preservekeys' => true]);
order_result($iconList, 'name');
foreach ($iconList as $icon) {
$data['iconList'][$icon['imageid']] = $icon['name'];
}
$inventoryFields = getHostInventories();
foreach ($inventoryFields as $field) {
$data['inventoryList'][$field['nr']] = $field['title'];
}
if (isset($_REQUEST['form'])) {
if (hasRequest('form_refresh') || $_REQUEST['form'] === 'clone') {
$data['iconmap'] = getRequest('iconmap');
} elseif (isset($_REQUEST['iconmapid'])) {
$data['iconmap'] = reset($iconMap);
} else {
$firstIcon = reset($iconList);