Пример #1
0
/**
 * Draw antialiased line
 *
 * @param resource  $image  image reference
 * @param int       $x1     first x coordinate
 * @param int       $y1     first y coordinate
 * @param int       $x2     second x coordinate
 * @param int       $y2     second y coordinate
 * @param int       $color  line color
 * @param int       $style  line style, one of LINE_TYPE_NORMAL (default), LINE_TYPE_BOLD (bold line)
 */
function zbx_imagealine($image, $x1, $y1, $x2, $y2, $color, $style = LINE_TYPE_NORMAL)
{
    $x1 = round($x1);
    $y1 = round($y1);
    $x2 = round($x2);
    $y2 = round($y2);
    if ($x1 == $x2 && $y1 == $y2) {
        imagesetpixel($image, $x1, $y1, $color);
        return;
    }
    // Get foreground line color
    $lc = imagecolorsforindex($image, $color);
    $lc = array($lc['red'], $lc['green'], $lc['blue']);
    $dx = $x2 - $x1;
    $dy = $y2 - $y1;
    if (abs($dx) > abs($dy)) {
        if ($dx < 0) {
            zbx_swap($x1, $x2);
            $y1 = $y2;
        }
        for ($x = $x1, $y = $y1; $x <= $x2; $x++, $y = $y1 + ($x - $x1) * $dy / $dx) {
            $yint = floor($y);
            $yfrac = $y - $yint;
            if (LINE_TYPE_BOLD == $style) {
                $bc = imagecolorsforindex($image, imagecolorat($image, $x, $yint - 1));
                $bc = array($bc['red'], $bc['green'], $bc['blue']);
                imagesetpixel($image, $x, $yint - 1, zbx_colormix($image, $lc, $bc, $yfrac));
                $bc = imagecolorsforindex($image, imagecolorat($image, $x, $yint + 1));
                $bc = array($bc['red'], $bc['green'], $bc['blue']);
                imagesetpixel($image, $x, $yint + 1, zbx_colormix($image, $lc, $bc, 1 - $yfrac));
                imagesetpixel($image, $x, $yint, $color);
            } else {
                $bc = imagecolorsforindex($image, imagecolorat($image, $x, $yint));
                $bc = array($bc['red'], $bc['green'], $bc['blue']);
                imagesetpixel($image, $x, $yint, zbx_colormix($image, $lc, $bc, $yfrac));
                $bc = imagecolorsforindex($image, imagecolorat($image, $x, $yint + 1));
                $bc = array($bc['red'], $bc['green'], $bc['blue']);
                imagesetpixel($image, $x, $yint + 1, zbx_colormix($image, $lc, $bc, 1 - $yfrac));
            }
        }
    } else {
        if ($dy < 0) {
            zbx_swap($y1, $y2);
            $x1 = $x2;
        }
        for ($y = $y1, $x = $x1; $y <= $y2; $y++, $x = $x1 + ($y - $y1) * $dx / $dy) {
            $xint = floor($x);
            $xfrac = $x - $xint;
            if (LINE_TYPE_BOLD == $style) {
                $bc = imagecolorsforindex($image, imagecolorat($image, $xint - 1, $y));
                $bc = array($bc['red'], $bc['green'], $bc['blue']);
                imagesetpixel($image, $xint - 1, $y, zbx_colormix($image, $lc, $bc, $xfrac));
                $bc = imagecolorsforindex($image, imagecolorat($image, $xint + 1, $y));
                $bc = array($bc['red'], $bc['green'], $bc['blue']);
                imagesetpixel($image, $xint + 1, $y, zbx_colormix($image, $lc, $bc, 1 - $xfrac));
                imagesetpixel($image, $xint, $y, $color);
            } else {
                $bc = imagecolorsforindex($image, imagecolorat($image, $xint, $y));
                $bc = array($bc['red'], $bc['green'], $bc['blue']);
                imagesetpixel($image, $xint, $y, zbx_colormix($image, $lc, $bc, $xfrac));
                $bc = imagecolorsforindex($image, imagecolorat($image, $xint + 1, $y));
                $bc = array($bc['red'], $bc['green'], $bc['blue']);
                imagesetpixel($image, $xint + 1, $y, zbx_colormix($image, $lc, $bc, 1 - $xfrac));
            }
        }
    }
}
Пример #2
0
        $_REQUEST['hostgroupid'] = 0;
    }
}
if (!hasRequest('filter_rst')) {
    $_REQUEST['filter_groupid'] = getRequest('filter_groupid', CProfile::get('web.avail_report.' . $availabilityReportMode . '.groupid', 0));
    $_REQUEST['filter_hostid'] = getRequest('filter_hostid', CProfile::get('web.avail_report.' . $availabilityReportMode . '.hostid', 0));
    $_REQUEST['filter_timesince'] = getRequest('filter_timesince', CProfile::get('web.avail_report.' . $availabilityReportMode . '.timesince', 0));
    $_REQUEST['filter_timetill'] = getRequest('filter_timetill', CProfile::get('web.avail_report.' . $availabilityReportMode . '.timetill', 0));
}
CProfile::update('web.avail_report.' . $availabilityReportMode . '.groupid', getRequest('filter_groupid', 0), PROFILE_TYPE_ID);
CProfile::update('web.avail_report.' . $availabilityReportMode . '.timesince', getRequest('filter_timesince', 0), PROFILE_TYPE_STR);
CProfile::update('web.avail_report.' . $availabilityReportMode . '.timetill', getRequest('filter_timetill', 0), PROFILE_TYPE_STR);
CProfile::update('web.avail_report.' . $availabilityReportMode . '.hostid', getRequest('filter_hostid', 0), PROFILE_TYPE_ID);
$config = select_config();
if ($_REQUEST['filter_timetill'] > 0 && $_REQUEST['filter_timesince'] > $_REQUEST['filter_timetill']) {
    zbx_swap($_REQUEST['filter_timesince'], $_REQUEST['filter_timetill']);
}
$_REQUEST['filter_timesince'] = zbxDateToTime($_REQUEST['filter_timesince'] ? $_REQUEST['filter_timesince'] : date(TIMESTAMP_FORMAT_ZERO_TIME, time() - SEC_PER_DAY));
$_REQUEST['filter_timetill'] = zbxDateToTime($_REQUEST['filter_timetill'] ? $_REQUEST['filter_timetill'] : date(TIMESTAMP_FORMAT_ZERO_TIME, time()));
/*
 * Header
 */
$triggerData = isset($_REQUEST['triggerid']) ? API::Trigger()->get(array('triggerids' => $_REQUEST['triggerid'], 'output' => API_OUTPUT_EXTEND, 'selectHosts' => API_OUTPUT_EXTEND, 'expandDescription' => true)) : null;
$reportWidget = new CWidget();
$reportWidget->addPageHeader(_('AVAILABILITY REPORT'));
if ($triggerData) {
    $triggerData = reset($triggerData);
    $host = reset($triggerData['hosts']);
    $triggerData['hostid'] = $host['hostid'];
    $triggerData['hostname'] = $host['name'];
    $reportWidget->addHeader(array(new CLink($triggerData['hostname'], '?filter_groupid=' . $_REQUEST['filter_groupid']), NAME_DELIMITER, $triggerData['description']), SPACE);
 /**
  * Format map links.
  *
  * @param array $links			Map links
  * @param array $selements		Map elements
  *
  * @return array
  */
 protected function formatMapLinks(array $links, array $selements)
 {
     $result = [];
     // Get array where key is selementid and value is sort position.
     $flipped_selements = [];
     $selements = array_values($selements);
     foreach ($selements as $key => $item) {
         if (array_key_exists('selementid', $item)) {
             $flipped_selements[$item['selementid']] = $key;
         }
     }
     foreach ($links as &$link) {
         $link['selementpos1'] = $flipped_selements[$link['selementid1']];
         $link['selementpos2'] = $flipped_selements[$link['selementid2']];
         // Sort selements positons asc.
         if ($link['selementpos2'] < $link['selementpos1']) {
             zbx_swap($link['selementpos1'], $link['selementpos2']);
         }
     }
     unset($link);
     CArrayHelper::sort($links, ['selementpos1', 'selementpos2']);
     foreach ($links as $link) {
         $result[] = ['drawtype' => $link['drawtype'], 'color' => $link['color'], 'label' => $link['label'], 'selementid1' => $link['selementid1'], 'selementid2' => $link['selementid2'], 'linktriggers' => $this->formatMapLinkTriggers($link['linktriggers'])];
     }
     return $result;
 }