function drawMapLinkLabels(&$im, $map, $mapInfo, $resolveMacros = true) { global $colors; $links = $map['links']; $selements = $map['selements']; foreach ($links as $link) { if (empty($link['label'])) { continue; } $selement1 = $selements[$link['selementid1']]; list($x1, $y1) = get_icon_center_by_selement($selement1, $mapInfo[$link['selementid1']], $map); $selement2 = $selements[$link['selementid2']]; list($x2, $y2) = get_icon_center_by_selement($selement2, $mapInfo[$link['selementid2']], $map); if (isset($selement1['elementsubtype']) && $selement1['elementsubtype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) { if ($selement1['areatype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) { $w = $selement1['width']; $h = $selement1['height']; } else { $w = $map['width']; $h = $map['height']; } list($x1, $y1) = calculateMapAreaLinkCoord($x1, $y1, $w, $h, $x2, $y2); } if (isset($selement2['elementsubtype']) && $selement2['elementsubtype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) { if ($selement2['areatype'] == SYSMAP_ELEMENT_AREA_TYPE_CUSTOM) { $w = $selement2['width']; $h = $selement2['height']; } else { $w = $map['width']; $h = $map['height']; } list($x2, $y2) = calculateMapAreaLinkCoord($x2, $y2, $w, $h, $x1, $y1); } $drawtype = $link['drawtype']; $color = convertColor($im, $link['color']); $linktriggers = $link['linktriggers']; order_result($linktriggers, 'triggerid'); if (!empty($linktriggers)) { $max_severity = 0; $triggers = array(); foreach ($linktriggers as $link_trigger) { if ($link_trigger['triggerid'] == 0) { continue; } $id = $link_trigger['linktriggerid']; $triggers[$id] = zbx_array_merge($link_trigger, get_trigger_by_triggerid($link_trigger['triggerid'])); if ($triggers[$id]['status'] == TRIGGER_STATUS_ENABLED && $triggers[$id]['value'] == TRIGGER_VALUE_TRUE) { if ($triggers[$id]['priority'] >= $max_severity) { $drawtype = $triggers[$id]['drawtype']; $color = convertColor($im, $triggers[$id]['color']); $max_severity = $triggers[$id]['priority']; } } } } $label = $link['label']; $label = str_replace("\r", '', $label); $strings = explode("\n", $label); $box_width = 0; $box_height = 0; foreach ($strings as $snum => $str) { $strings[$snum] = $resolveMacros ? CMacrosResolverHelper::resolveMapLabelMacros($str) : $str; } foreach ($strings as $str) { $dims = imageTextSize(8, 0, $str); $box_width = $box_width > $dims['width'] ? $box_width : $dims['width']; $box_height += $dims['height'] + 2; } $boxX_left = round(($x1 + $x2) / 2 - $box_width / 2 - 6); $boxX_right = round(($x1 + $x2) / 2 + $box_width / 2 + 6); $boxY_top = round(($y1 + $y2) / 2 - $box_height / 2 - 4); $boxY_bottom = round(($y1 + $y2) / 2 + $box_height / 2 + 2); switch ($drawtype) { case MAP_LINK_DRAWTYPE_DASHED_LINE: case MAP_LINK_DRAWTYPE_DOT: dashedRectangle($im, $boxX_left, $boxY_top, $boxX_right, $boxY_bottom, $color); break; case MAP_LINK_DRAWTYPE_BOLD_LINE: imagerectangle($im, $boxX_left - 1, $boxY_top - 1, $boxX_right + 1, $boxY_bottom + 1, $color); // break; is not ne // break; is not ne case MAP_LINK_DRAWTYPE_LINE: default: imagerectangle($im, $boxX_left, $boxY_top, $boxX_right, $boxY_bottom, $color); } imagefilledrectangle($im, $boxX_left + 1, $boxY_top + 1, $boxX_right - 1, $boxY_bottom - 1, $colors['White']); $increasey = 4; foreach ($strings as $str) { $dims = imageTextSize(8, 0, $str); $labelx = ($x1 + $x2) / 2 - $dims['width'] / 2; $labely = $boxY_top + $increasey; imagetext($im, 8, 0, $labelx, $labely + $dims['height'], $colors['Black'], $str); $increasey += $dims['height'] + 2; } } }
function drawMapLinkLabels(&$im, &$map, &$map_info) { global $colors; $links = $map['links']; $selements = $map['selements']; foreach ($links as $lnum => $link) { if (empty($link)) { continue; } if (empty($link['label'])) { continue; } $selement = $selements[$link['selementid1']]; list($x1, $y1) = get_icon_center_by_selement($selement, $map_info[$link['selementid1']]); $selement = $selements[$link['selementid2']]; list($x2, $y2) = get_icon_center_by_selement($selement, $map_info[$link['selementid2']]); $drawtype = $link['drawtype']; $color = convertColor($im, $link['color']); $linktriggers = $link['linktriggers']; order_result($linktriggers, 'triggerid'); if (!empty($linktriggers)) { $max_severity = 0; $options = array(); $options['nopermissions'] = 1; $options['extendoutput'] = 1; $options['triggerids'] = array(); $triggers = array(); foreach ($linktriggers as $lt_num => $link_trigger) { if ($link_trigger['triggerid'] == 0) { continue; } $id = $link_trigger['linktriggerid']; $triggers[$id] = zbx_array_merge($link_trigger, get_trigger_by_triggerid($link_trigger['triggerid'])); if ($triggers[$id]['status'] == TRIGGER_STATUS_ENABLED && $triggers[$id]['value'] == TRIGGER_VALUE_TRUE) { if ($triggers[$id]['priority'] >= $max_severity) { $drawtype = $triggers[$id]['drawtype']; $color = convertColor($im, $triggers[$id]['color']); $max_severity = $triggers[$id]['priority']; } } } } $label = $link['label']; $label = str_replace("\r", '', $label); $strings = explode("\n", $label); $box_width = 0; $box_height = 0; foreach ($strings as $snum => $str) { $strings[$snum] = resolveMapLabelMacros($str); } foreach ($strings as $snum => $str) { $dims = imageTextSize(8, 0, $str); $box_width = $box_width > $dims['width'] ? $box_width : $dims['width']; $box_height += $dims['height'] + 2; } $boxX_left = round(($x1 + $x2) / 2 - $box_width / 2 - 6); $boxX_right = round(($x1 + $x2) / 2 + $box_width / 2 + 6); $boxY_top = round(($y1 + $y2) / 2 - $box_height / 2 - 4); $boxY_bottom = round(($y1 + $y2) / 2 + $box_height / 2 + 2); switch ($drawtype) { case MAP_LINK_DRAWTYPE_DASHED_LINE: case MAP_LINK_DRAWTYPE_DOT: dashedrectangle($im, $boxX_left, $boxY_top, $boxX_right, $boxY_bottom, $color); break; case MAP_LINK_DRAWTYPE_BOLD_LINE: imagerectangle($im, $boxX_left - 1, $boxY_top - 1, $boxX_right + 1, $boxY_bottom + 1, $color); case MAP_LINK_DRAWTYPE_LINE: default: imagerectangle($im, $boxX_left, $boxY_top, $boxX_right, $boxY_bottom, $color); } imagefilledrectangle($im, $boxX_left + 1, $boxY_top + 1, $boxX_right - 1, $boxY_bottom - 1, $colors['White']); $increasey = 4; foreach ($strings as $snum => $str) { $dims = imageTextSize(8, 0, $str); $labelx = ($x1 + $x2) / 2 - $dims['width'] / 2; $labely = $boxY_top + $increasey; imagetext($im, 8, 0, $labelx, $labely + $dims['height'], $colors['Black'], $str); $increasey += $dims['height'] + 2; } } }