/**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $screen = API::Screen()->get(array('screenids' => $this->screenitem['resourceid'], 'output' => API_OUTPUT_EXTEND, 'selectScreenItems' => API_OUTPUT_EXTEND));
     $screen = reset($screen);
     $screenBuilder = new CScreenBuilder(array('isFlickerfree' => $this->isFlickerfree, 'mode' => $this->mode == SCREEN_MODE_EDIT || $this->mode == SCREEN_MODE_SLIDESHOW ? SCREEN_MODE_SLIDESHOW : SCREEN_MODE_PREVIEW, 'timestamp' => $this->timestamp, 'screen' => $screen, 'period' => $this->timeline['period'], 'stime' => $this->timeline['stimeNow'], 'profileIdx' => $this->profileIdx, 'updateProfile' => false));
     return $this->getOutput($screenBuilder->show(), true);
 }
 /**
  * Import screens.
  *
  * @param array $screens
  *
  * @return mixed
  */
 public function import(array $screens)
 {
     $screens = zbx_toHash($screens, 'name');
     $this->checkCircularScreenReferences($screens);
     do {
         $independentScreens = $this->getIndependentScreens($screens);
         $screensToCreate = array();
         $screensToUpdate = array();
         foreach ($independentScreens as $name) {
             $screen = $screens[$name];
             unset($screens[$name]);
             $screen = $this->resolveScreenReferences($screen);
             if ($screenId = $this->referencer->resolveScreen($screen['name'])) {
                 $screen['screenid'] = $screenId;
                 $screensToUpdate[] = $screen;
             } else {
                 $screensToCreate[] = $screen;
             }
         }
         if ($this->options['screens']['createMissing'] && $screensToCreate) {
             $newScreenIds = API::Screen()->create($screensToCreate);
             foreach ($screensToCreate as $num => $newScreen) {
                 $screenidId = $newScreenIds['screenids'][$num];
                 $this->referencer->addScreenRef($newScreen['name'], $screenidId);
             }
         }
         if ($this->options['screens']['updateExisting'] && $screensToUpdate) {
             API::Screen()->update($screensToUpdate);
         }
     } while (!empty($independentScreens));
     // if there are screens left in $screens, then they have unresolved references
     foreach ($screens as $screen) {
         $unresolvedReferences = array();
         foreach ($screen['screenitems'] as $screenItem) {
             if ($screenItem['resourcetype'] == SCREEN_RESOURCE_SCREEN && !$this->referencer->resolveScreen($screenItem['resource']['name'])) {
                 $unresolvedReferences[] = $screenItem['resource']['name'];
             }
         }
         $unresolvedReferences = array_unique($unresolvedReferences);
         throw new Exception(_n('Cannot import screen "%1$s": subscreen "%2$s" does not exist.', 'Cannot import screen "%1$s": subscreens "%2$s" do not exist.', $screen['name'], implode(', ', $unresolvedReferences), count($unresolvedReferences)));
     }
 }
Beispiel #3
0
 /**
  * Get screen data.
  *
  * @param array  $options
  * @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 = [])
 {
     $result = [];
     $user_data = self::$userData;
     $sql_parts = ['select' => ['screens' => 's.screenid'], 'from' => ['screens' => 'screens s'], 'where' => ['template' => 's.templateid IS NULL'], 'order' => [], 'group' => [], 'limit' => null];
     $defOptions = ['screenids' => null, 'userids' => null, 'screenitemids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_EXTEND, 'selectScreenItems' => null, 'selectUsers' => null, 'selectUserGroups' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null];
     $options = zbx_array_merge($defOptions, $options);
     if ($options['countOutput'] !== null) {
         $count_output = true;
         $options['output'] = ['screenid'];
         $options['countOutput'] = null;
         $options['limit'] = null;
     } else {
         $count_output = false;
     }
     // Editable + permission check.
     if ($user_data['type'] != USER_TYPE_SUPER_ADMIN && $user_data['type'] != USER_TYPE_ZABBIX_ADMIN && !$options['nopermissions']) {
         $public_screens = '';
         if ($options['editable']) {
             $permission = PERM_READ_WRITE;
         } else {
             $permission = PERM_READ;
             $public_screens = ' OR s.private=' . PUBLIC_SHARING;
         }
         $user_groups = getUserGroupsByUserId($user_data['userid']);
         $sql_parts['where'][] = '(EXISTS (' . 'SELECT NULL' . ' FROM screen_user su' . ' WHERE s.screenid=su.screenid' . ' AND su.userid=' . $user_data['userid'] . ' AND su.permission>=' . $permission . ')' . ' OR EXISTS (' . 'SELECT NULL' . ' FROM screen_usrgrp sg' . ' WHERE s.screenid=sg.screenid' . ' AND ' . dbConditionInt('sg.usrgrpid', $user_groups) . ' AND sg.permission>=' . $permission . ')' . ' OR s.userid=' . $user_data['userid'] . $public_screens . ')';
     }
     // screenids
     if (!is_null($options['screenids'])) {
         zbx_value2array($options['screenids']);
         $sql_parts['where'][] = dbConditionInt('s.screenid', $options['screenids']);
     }
     // userids
     if ($options['userids'] !== null) {
         zbx_value2array($options['userids']);
         $sql_parts['where'][] = dbConditionInt('s.userid', $options['userids']);
     }
     // screenitemids
     if (!is_null($options['screenitemids'])) {
         zbx_value2array($options['screenitemids']);
         $sql_parts['from']['screens_items'] = 'screens_items si';
         $sql_parts['where']['ssi'] = 'si.screenid=s.screenid';
         $sql_parts['where'][] = dbConditionInt('si.screenitemid', $options['screenitemids']);
     }
     // filter
     if (is_array($options['filter'])) {
         $this->dbFilter('screens s', $options, $sql_parts);
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search('screens s', $options, $sql_parts);
     }
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sql_parts['limit'] = $options['limit'];
     }
     $screenids = [];
     $sql_parts = $this->applyQueryOutputOptions($this->tableName(), $this->tableAlias(), $options, $sql_parts);
     $sql_parts = $this->applyQuerySortOptions($this->tableName(), $this->tableAlias(), $options, $sql_parts);
     $res = DBselect($this->createSelectQueryFromParts($sql_parts), $sql_parts['limit']);
     while ($screen = DBfetch($res)) {
         $screenids[$screen['screenid']] = true;
         $result[$screen['screenid']] = $screen;
     }
     // editable + PERMISSION CHECK
     if ($user_data['type'] != USER_TYPE_SUPER_ADMIN && !$options['nopermissions'] && $screenids) {
         $db_screen_items = DBselect('SELECT si.screenid,si.resourcetype,si.resourceid,si.style' . ' FROM screens_items si' . ' WHERE ' . dbConditionInt('si.screenid', array_keys($screenids)) . ' AND ' . dbConditionInt('si.resourcetype', [SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_TRIGGERS_INFO, SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW, SCREEN_RESOURCE_HOSTGROUP_TRIGGERS, SCREEN_RESOURCE_HOST_TRIGGERS, SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT, SCREEN_RESOURCE_CLOCK, SCREEN_RESOURCE_MAP, SCREEN_RESOURCE_SCREEN]) . ' AND si.resourceid<>0');
         $screens = [];
         while ($db_screen_item = DBfetch($db_screen_items)) {
             if (!array_key_exists($db_screen_item['screenid'], $screens)) {
                 $screens[$db_screen_item['screenid']] = ['groups' => [], 'hosts' => [], 'graphs' => [], 'items' => [], 'maps' => [], 'screens' => []];
             }
             switch ($db_screen_item['resourcetype']) {
                 case SCREEN_RESOURCE_HOSTS_INFO:
                 case SCREEN_RESOURCE_TRIGGERS_INFO:
                 case SCREEN_RESOURCE_TRIGGERS_OVERVIEW:
                 case SCREEN_RESOURCE_DATA_OVERVIEW:
                 case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
                     $screens[$db_screen_item['screenid']]['groups'][$db_screen_item['resourceid']] = true;
                     break;
                 case SCREEN_RESOURCE_HOST_TRIGGERS:
                     $screens[$db_screen_item['screenid']]['hosts'][$db_screen_item['resourceid']] = true;
                     break;
                 case SCREEN_RESOURCE_GRAPH:
                     $screens[$db_screen_item['screenid']]['graphs'][$db_screen_item['resourceid']] = true;
                     break;
                 case SCREEN_RESOURCE_SIMPLE_GRAPH:
                 case SCREEN_RESOURCE_PLAIN_TEXT:
                     $screens[$db_screen_item['screenid']]['items'][$db_screen_item['resourceid']] = true;
                     break;
                 case SCREEN_RESOURCE_CLOCK:
                     if ($db_screen_item['style'] == TIME_TYPE_HOST) {
                         $screens[$db_screen_item['screenid']]['items'][$db_screen_item['resourceid']] = true;
                     }
                     break;
                 case SCREEN_RESOURCE_MAP:
                     $screens[$db_screen_item['screenid']]['maps'][$db_screen_item['resourceid']] = true;
                     break;
                 case SCREEN_RESOURCE_SCREEN:
                     $screens[$db_screen_item['screenid']]['screens'][$db_screen_item['resourceid']] = true;
                     break;
             }
         }
         // groups
         $groups = [];
         foreach ($screens as $screenid => $resources) {
             foreach ($resources['groups'] as $groupid => $foo) {
                 $groups[$groupid][$screenid] = true;
             }
         }
         if ($groups) {
             $db_groups = API::HostGroup()->get(['output' => [], 'groupids' => array_keys($groups), 'preservekeys' => true]);
             foreach ($groups as $groupid => $resources) {
                 if (!array_key_exists($groupid, $db_groups)) {
                     foreach ($resources as $screenid => $foo) {
                         unset($screens[$screenid], $result[$screenid]);
                     }
                 }
             }
         }
         // hosts
         $hosts = [];
         foreach ($screens as $screenid => $resources) {
             foreach ($resources['hosts'] as $hostid => $foo) {
                 $hosts[$hostid][$screenid] = true;
             }
         }
         if ($hosts) {
             $db_hosts = API::Host()->get(['output' => [], 'hostids' => array_keys($hosts), 'preservekeys' => true]);
             foreach ($hosts as $hostid => $resources) {
                 if (!array_key_exists($hostid, $db_hosts)) {
                     foreach ($resources as $screenid => $foo) {
                         unset($screens[$screenid], $result[$screenid]);
                     }
                 }
             }
         }
         // graphs
         $graphs = [];
         foreach ($screens as $screenid => $resources) {
             foreach ($resources['graphs'] as $graphid => $foo) {
                 $graphs[$graphid][$screenid] = true;
             }
         }
         if ($graphs) {
             $db_graphs = API::Graph()->get(['output' => [], 'graphids' => array_keys($graphs), 'preservekeys' => true]);
             foreach ($graphs as $graphid => $resources) {
                 if (!array_key_exists($graphid, $db_graphs)) {
                     foreach ($resources as $screenid => $foo) {
                         unset($screens[$screenid], $result[$screenid]);
                     }
                 }
             }
         }
         // items
         $items = [];
         foreach ($screens as $screenid => $resources) {
             foreach ($resources['items'] as $itemid => $foo) {
                 $items[$itemid][$screenid] = true;
             }
         }
         if ($items) {
             $db_items = API::Item()->get(['output' => [], 'itemids' => array_keys($items), 'webitems' => true, 'preservekeys' => true]);
             foreach ($items as $itemid => $resources) {
                 if (!array_key_exists($itemid, $db_items)) {
                     foreach ($resources as $screenid => $foo) {
                         unset($screens[$screenid], $result[$screenid]);
                     }
                 }
             }
         }
         // maps
         $maps = [];
         foreach ($screens as $screenid => $resources) {
             foreach ($resources['maps'] as $sysmapid => $foo) {
                 $maps[$sysmapid][$screenid] = true;
             }
         }
         if ($maps) {
             $db_maps = API::Map()->get(['output' => [], 'sysmapids' => array_keys($maps), 'preservekeys' => true]);
             foreach ($maps as $sysmapid => $resources) {
                 if (!array_key_exists($sysmapid, $db_maps)) {
                     foreach ($resources as $screenid => $foo) {
                         unset($screens[$screenid], $result[$screenid]);
                     }
                 }
             }
         }
         // screens
         $_screens = [];
         foreach ($screens as $screenid => $resources) {
             foreach ($resources['screens'] as $_screenid => $foo) {
                 $_screens[$_screenid][$screenid] = true;
             }
         }
         if ($_screens) {
             $db_screens = API::Screen()->get(['output' => [], 'screenids' => array_keys($_screens), 'preservekeys' => true]);
             foreach ($_screens as $_screenid => $resources) {
                 if (!array_key_exists($_screenid, $db_screens)) {
                     foreach ($resources as $screenid => $foo) {
                         unset($screens[$screenid], $result[$screenid]);
                     }
                 }
             }
         }
     }
     if ($count_output) {
         if ($options['groupCount'] !== null) {
             return [['rowscount' => count($result)]];
         } else {
             return count($result);
         }
     }
     if ($result) {
         $result = $this->addRelatedObjects($options, $result);
     }
     // removing keys (hash -> array)
     if ($options['preservekeys'] === null) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
Beispiel #4
0
        }
    }
}
if ($page['type'] == PAGE_TYPE_JS || $page['type'] == PAGE_TYPE_HTML_BLOCK) {
    require_once dirname(__FILE__) . '/include/page_footer.php';
    exit;
}
/*
 * Display
 */
$data = array('fullscreen' => $_REQUEST['fullscreen'], 'period' => get_request('period'), 'stime' => get_request('stime'), 'elementid' => get_request('elementid', false), 'use_screen_name' => isset($_REQUEST['screenname']));
// if none is provided
if (empty($data['elementid']) && !$data['use_screen_name']) {
    // get element id saved in profile from the last visit
    $data['elementid'] = CProfile::get('web.screens.elementid', null);
}
$data['screens'] = API::Screen()->get(array('nodeids' => get_current_nodeid(), 'output' => array('screenid', 'name')));
// if screen name is provided it takes priority over elementid
if ($data['use_screen_name']) {
    $data['screens'] = zbx_toHash($data['screens'], 'name');
    $data['elementIdentifier'] = get_request('screenname');
} else {
    $data['screens'] = zbx_toHash($data['screens'], 'screenid');
    $data['elementIdentifier'] = $data['elementid'];
}
order_result($data['screens'], 'name');
// render view
$screenView = new CView('monitoring.screen', $data);
$screenView->render();
$screenView->show();
require_once dirname(__FILE__) . '/include/page_footer.php';
Beispiel #5
0
function update_slideshow($slideshowid, $name, $delay, $slides)
{
    // validate slides
    if (empty($slides)) {
        error(_('Slide show must contain slides.'));
        return false;
    }
    // validate screens
    $screenids = zbx_objectValues($slides, 'screenid');
    $screens = API::Screen()->get(array('screenids' => $screenids, 'output' => array('screenid')));
    $screens = ZBX_toHash($screens, 'screenid');
    foreach ($screenids as $screenid) {
        if (!isset($screens[$screenid])) {
            error(_('Incorrect screen provided for slide show.'));
            return false;
        }
    }
    // validate slide name
    $db_slideshow = DBfetch(DBselect('SELECT s.slideshowid' . ' FROM slideshows s' . ' WHERE s.name=' . zbx_dbstr($name) . ' AND s.slideshowid<>' . zbx_dbstr($slideshowid) . ' ' . andDbNode('s.slideshowid')));
    if (!empty($db_slideshow)) {
        error(_s('Slide show "%s" already exists.', $name));
        return false;
    }
    $db_slideshow = DBfetchArray(DBselect('SELECT * FROM slideshows WHERE slideshowid=' . zbx_dbstr($slideshowid)));
    $db_slideshow = $db_slideshow[0];
    $changed = false;
    $slideshow = array('name' => $name, 'delay' => $delay);
    foreach ($slideshow as $key => $val) {
        if ($db_slideshow[$key] != $val) {
            $changed = true;
            break;
        }
    }
    if ($changed) {
        if (!($result = DBexecute('UPDATE slideshows SET name=' . zbx_dbstr($name) . ',delay=' . zbx_dbstr($delay) . ' WHERE slideshowid=' . zbx_dbstr($slideshowid)))) {
            return false;
        }
    }
    // get slides
    $db_slides = DBfetchArrayAssoc(DBselect('SELECT s.* FROM slides s WHERE s.slideshowid=' . zbx_dbstr($slideshowid)), 'slideid');
    $slidesToDel = zbx_objectValues($db_slides, 'slideid');
    $slidesToDel = zbx_toHash($slidesToDel);
    $step = 0;
    foreach ($slides as $slide) {
        $slide['delay'] = $slide['delay'] ? $slide['delay'] : 0;
        if (isset($db_slides[$slide['slideid']])) {
            // update slide
            if ($db_slides[$slide['slideid']]['delay'] != $slide['delay'] || $db_slides[$slide['slideid']]['step'] != $step) {
                $result = DBexecute('UPDATE slides SET step=' . zbx_dbstr($step) . ', delay=' . zbx_dbstr($slide['delay']) . ' WHERE slideid=' . zbx_dbstr($slide['slideid']));
            } else {
                $result = true;
            }
            unset($slidesToDel[$slide['slideid']]);
        } else {
            $slideid = get_dbid('slides', 'slideid');
            $result = DBexecute('INSERT INTO slides (slideid,slideshowid,screenid,step,delay)' . ' VALUES (' . zbx_dbstr($slideid) . ',' . zbx_dbstr($slideshowid) . ',' . zbx_dbstr($slide['screenid']) . ',' . zbx_dbstr($step) . ',' . zbx_dbstr($slide['delay']) . ')');
        }
        $step++;
        if (!$result) {
            return false;
        }
    }
    // delete unnecessary slides
    if (!empty($slidesToDel)) {
        DBexecute('DELETE FROM slides WHERE slideid IN(' . implode(',', $slidesToDel) . ')');
    }
    return true;
}
Beispiel #6
0
if (hasRequest('elementid')) {
    $data['screen'] = get_slideshow_by_slideshowid(getRequest('elementid'), PERM_READ);
    if (!$data['screen']) {
        access_deny();
    }
} else {
    $data['screen'] = [];
}
/*
 * Actions
 */
if ((hasRequest('widgetRefresh') || hasRequest('widgetRefreshRate')) && $data['screen']) {
    $elementId = getRequest('elementid');
    $screen = getSlideshowScreens($elementId, getRequest('upd_counter'));
    // display screens
    $dbScreens = API::Screen()->get(['screenids' => $screen['screenid'], 'output' => API_OUTPUT_EXTEND, 'selectScreenItems' => API_OUTPUT_EXTEND]);
    if (!$dbScreens) {
        insert_js('alert("' . _('No permissions') . '");');
    } else {
        $dbScreen = reset($dbScreens);
        // get fresh widget data
        if (hasRequest('widgetRefresh')) {
            $screenBuilder = new CScreenBuilder(['screen' => $dbScreen, 'mode' => SCREEN_MODE_PREVIEW, 'profileIdx' => 'web.slides', 'profileIdx2' => $elementId, 'hostid' => getRequest('hostid'), 'period' => getRequest('period'), 'stime' => getRequest('stime')]);
            CScreenBuilder::insertScreenCleanJs();
            echo (new CDiv($screenBuilder->show()))->addClass(ZBX_STYLE_TABLE_FORMS_CONTAINER)->toString();
            CScreenBuilder::insertScreenStandardJs(['timeline' => $screenBuilder->timeline, 'profileIdx' => $screenBuilder->profileIdx]);
            insertPagePostJs();
        }
        // refresh rate
        if (hasRequest('widgetRefreshRate')) {
            $widgetRefreshRate = substr(getRequest('widgetRefreshRate'), 1);
Beispiel #7
0
 /**
  * Validates screen items.
  *
  * If the $dbScreenItems parameter is given, the screen items will be matched
  * against the ones given in $dbScreenItems. If a screen item is not present in
  * $dbScreenItems, a ZBX_API_ERROR_PERMISSIONS exception will be thrown.
  *
  * @throws APIException if a validation error occurred.
  *
  * @param array $screenItems
  * @param array $dbScreenItems
  */
 protected function checkInput(array $screenItems, array $dbScreenItems = array())
 {
     $hostGroupsIds = $hostIds = $graphIds = $itemIds = $mapIds = $screenIds = array();
     $screenItems = $this->extendFromObjects($screenItems, $dbScreenItems, array('resourcetype', 'resourceid'));
     foreach ($screenItems as $screenItem) {
         // check permissions
         if (isset($screenItem['screenitemid']) && !isset($dbScreenItems[$screenItem['screenitemid']])) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
         }
         if (!$this->isValidResourceType($screenItem['resourcetype'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect resource type provided for screen item.'));
         }
         if (!isset($screenItem['resourceid'])) {
             $screenItem['resourceid'] = null;
         }
         // check resource id
         switch ($screenItem['resourcetype']) {
             case SCREEN_RESOURCE_HOSTS_INFO:
             case SCREEN_RESOURCE_TRIGGERS_INFO:
             case SCREEN_RESOURCE_TRIGGERS_OVERVIEW:
             case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
             case SCREEN_RESOURCE_DATA_OVERVIEW:
                 if (in_array($screenItem['resourcetype'], array(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW))) {
                     if (!$screenItem['resourceid']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('No host group ID provided for screen element.'));
                     }
                 }
                 if ($screenItem['resourceid']) {
                     $hostGroupsIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 }
                 break;
             case SCREEN_RESOURCE_HOST_TRIGGERS:
                 if ($screenItem['resourceid']) {
                     $hostIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 }
                 break;
             case SCREEN_RESOURCE_GRAPH:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No graph ID provided for screen element.'));
                 }
                 $graphIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_SIMPLE_GRAPH:
             case SCREEN_RESOURCE_PLAIN_TEXT:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No item ID provided for screen element.'));
                 }
                 $itemIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_CLOCK:
                 if (isset($screenItem['style']) && $screenItem['style'] == TIME_TYPE_HOST) {
                     if (!$screenItem['resourceid']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('No item ID provided for screen element.'));
                     }
                     $itemIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 }
                 break;
             case SCREEN_RESOURCE_MAP:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No map ID provided for screen element.'));
                 }
                 $mapIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_SCREEN:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No screen ID provided for screen element.'));
                 }
                 $screenIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
         }
         // check url
         if ($screenItem['resourcetype'] == SCREEN_RESOURCE_URL) {
             if (!isset($screenItem['url']) || zbx_empty($screenItem['url'])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No URL provided for screen element.'));
             }
         }
         // check "Show lines"
         if (isset($screenItem['elements'])) {
             switch ($screenItem['resourcetype']) {
                 case SCREEN_RESOURCE_ACTIONS:
                 case SCREEN_RESOURCE_EVENTS:
                 case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
                 case SCREEN_RESOURCE_HOST_TRIGGERS:
                 case SCREEN_RESOURCE_PLAIN_TEXT:
                     if ($screenItem['elements'] < 1 || $screenItem['elements'] > 100) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect value "%1$s" for "%2$s" field: must be between %3$s and %4$s.', $screenItem['elements'], 'elements', 1, 100));
                     }
                     break;
             }
         }
     }
     // check host groups
     if ($hostGroupsIds) {
         $dbHostGroups = API::HostGroup()->get(array('groupids' => $hostGroupsIds, 'output' => array('groupid'), 'editable' => true, 'preservekeys' => true));
         foreach ($hostGroupsIds as $hostGroupsId) {
             if (!isset($dbHostGroups[$hostGroupsId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host group ID "%1$s" provided for screen element.', $hostGroupsId));
             }
         }
     }
     // check hosts
     if ($hostIds) {
         $dbHosts = API::Host()->get(array('hostids' => $hostIds, 'output' => array('hostid'), 'editable' => true, 'preservekeys' => true));
         foreach ($hostIds as $hostId) {
             if (!isset($dbHosts[$hostId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host ID "%1$s" provided for screen element.', $hostId));
             }
         }
     }
     // check graphs
     if ($graphIds) {
         $dbGraphs = API::Graph()->get(array('graphids' => $graphIds, 'output' => array('graphid'), 'editable' => true, 'preservekeys' => true));
         foreach ($graphIds as $graphId) {
             if (!isset($dbGraphs[$graphId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect graph ID "%1$s" provided for screen element.', $graphId));
             }
         }
     }
     // check items
     if ($itemIds) {
         $dbItems = API::Item()->get(array('itemids' => $itemIds, 'output' => array('itemid'), 'editable' => true, 'preservekeys' => true, 'webitems' => true));
         foreach ($itemIds as $itemId) {
             if (!isset($dbItems[$itemId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect item ID "%1$s" provided for screen element.', $itemId));
             }
         }
     }
     // check maps
     if ($mapIds) {
         $dbMaps = API::Map()->get(array('sysmapids' => $mapIds, 'output' => array('sysmapid'), 'editable' => true, 'preservekeys' => true));
         foreach ($mapIds as $mapId) {
             if (!isset($dbMaps[$mapId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect map ID "%1$s" provided for screen element.', $mapId));
             }
         }
     }
     // check screens
     if ($screenIds) {
         $dbScreens = API::Screen()->get(array('screenids' => $screenIds, 'output' => array('screenid'), 'editable' => true, 'preservekeys' => true));
         if (count($dbScreens) < count($screenIds)) {
             $dbTemplateScreens = API::TemplateScreen()->get(array('screenids' => $screenIds, 'output' => array('screenid'), 'editable' => true, 'preservekeys' => true));
             if ($dbTemplateScreens) {
                 $dbScreens = zbx_array_merge($dbScreens, $dbTemplateScreens);
             }
         }
         foreach ($screenIds as $screenId) {
             if (!isset($dbScreens[$screenId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect screen ID "%1$s" provided for screen element.', $screenId));
             }
         }
     }
 }
 /**
  * Prepare data for favourite screens menu popup.
  *
  * @return array
  */
 public static function getFavouriteScreens()
 {
     $screens = $slideshows = array();
     $favourites = CFavorite::get('web.favorite.screenids');
     if ($favourites) {
         $screenIds = $slideshowIds = array();
         foreach ($favourites as $favourite) {
             if ($favourite['source'] === 'screenid') {
                 $screenIds[$favourite['value']] = $favourite['value'];
             }
         }
         $dbScreens = API::Screen()->get(array('output' => array('screenid', 'name'), 'screenids' => $screenIds, 'preservekeys' => true));
         foreach ($favourites as $favourite) {
             $sourceId = $favourite['value'];
             if ($favourite['source'] === 'slideshowid') {
                 if (slideshow_accessible($sourceId, PERM_READ)) {
                     $dbSlideshow = get_slideshow_by_slideshowid($sourceId);
                     if ($dbSlideshow) {
                         $slideshows[] = array('id' => $dbSlideshow['slideshowid'], 'label' => $dbSlideshow['name']);
                     }
                 }
             } else {
                 if (isset($dbScreens[$sourceId])) {
                     $dbScreen = $dbScreens[$sourceId];
                     $screens[] = array('id' => $dbScreen['screenid'], 'label' => $dbScreen['name']);
                 }
             }
         }
     }
     return array('type' => 'favouriteScreens', 'screens' => $screens, 'slideshows' => $slideshows);
 }
    $data = [];
    if ($resourceId > 0) {
        $data = API::HostGroup()->get(['groupids' => $resourceId, 'output' => ['groupid', 'name'], 'editable' => true]);
        if ($data) {
            $data = reset($data);
        }
    }
    $screenFormList->addRow(_('Group'), (new CMultiSelect(['name' => 'resourceid', 'objectName' => 'hostGroup', 'objectOptions' => ['editable' => true], 'data' => $data ? [['id' => $data['groupid'], 'name' => $data['name']]] : null, 'selectedLimit' => 1, 'popup' => ['parameters' => 'srctbl=host_groups&dstfrm=' . $form->getName() . '&dstfld1=resourceid' . '&srcfld1=groupid']]))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH));
    $screenFormList->addRow(_('Application'), (new CTextBox('application', $application, false, 255))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH));
} elseif ($resourceType == SCREEN_RESOURCE_SCREEN) {
    $caption = '';
    $id = 0;
    if ($resourceId > 0) {
        $db_screens = DBselect('SELECT s.screenid,s.name FROM screens s WHERE s.screenid=' . zbx_dbstr($resourceId));
        while ($row = DBfetch($db_screens)) {
            $screen = API::Screen()->get(['screenids' => $row['screenid'], 'output' => ['screenid']]);
            if (empty($screen)) {
                continue;
            }
            if (check_screen_recursion($_REQUEST['screenid'], $row['screenid'])) {
                continue;
            }
            $caption = $row['name'];
            $id = $resourceId;
        }
    }
    $form->addVar('resourceid', $id);
    $screenFormList->addRow(_('Screen'), [(new CTextBox('caption', $caption, true))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CButton('select', _('Select')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('javascript: return PopUp("popup.php?srctbl=screens2&srcfld1=screenid&srcfld2=name' . '&dstfrm=' . $form->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&screenid=' . $_REQUEST['screenid'] . '");')]);
} elseif ($resourceType == SCREEN_RESOURCE_HOSTS_INFO || $resourceType == SCREEN_RESOURCE_TRIGGERS_INFO) {
    $data = [];
    if ($resourceId > 0) {
Beispiel #10
0
 /**
  * Validates screen items.
  *
  * If the $dbScreenItems parameter is given, the screen items will be matched
  * against the ones given in $dbScreenItems. If a screen item is not present in
  * $dbScreenItems, a ZBX_API_ERROR_PERMISSIONS exception will be thrown.
  *
  * @throws APIException if a validation error occurred.
  *
  * @param array $screenItems
  * @param array $dbScreenItems
  */
 protected function checkInput(array $screenItems, array $dbScreenItems = array())
 {
     $hostGroupsIds = array();
     $hostIds = array();
     $graphIds = array();
     $itemIds = array();
     $mapIds = array();
     $screenIds = array();
     $itemPrototypeIds = array();
     $graphPrototypeIds = array();
     $screenItems = $this->extendFromObjects($screenItems, $dbScreenItems, array('resourcetype'));
     $validStyles = array(SCREEN_RESOURCE_CLOCK => array(TIME_TYPE_LOCAL, TIME_TYPE_SERVER, TIME_TYPE_HOST), SCREEN_RESOURCE_DATA_OVERVIEW => array(STYLE_TOP, STYLE_LEFT), SCREEN_RESOURCE_TRIGGERS_OVERVIEW => array(STYLE_TOP, STYLE_LEFT), SCREEN_RESOURCE_HOSTS_INFO => array(STYLE_VERTICAL, STYLE_HORIZONTAL), SCREEN_RESOURCE_TRIGGERS_INFO => array(STYLE_VERTICAL, STYLE_HORIZONTAL));
     foreach ($screenItems as $screenItem) {
         // check permissions
         if (isset($screenItem['screenitemid']) && !isset($dbScreenItems[$screenItem['screenitemid']])) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
         }
         if (!$this->isValidResourceType($screenItem['resourcetype'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect resource type provided for screen item.'));
         }
         if (!isset($screenItem['resourceid'])) {
             $screenItem['resourceid'] = null;
         }
         // check resource id
         switch ($screenItem['resourcetype']) {
             case SCREEN_RESOURCE_HOSTS_INFO:
             case SCREEN_RESOURCE_TRIGGERS_INFO:
             case SCREEN_RESOURCE_TRIGGERS_OVERVIEW:
             case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
             case SCREEN_RESOURCE_DATA_OVERVIEW:
                 $overviewResources = array(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW);
                 if (in_array($screenItem['resourcetype'], $overviewResources)) {
                     if (!$screenItem['resourceid']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('No host group ID provided for screen element.'));
                     }
                 }
                 if ($screenItem['resourceid']) {
                     $hostGroupsIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 }
                 break;
             case SCREEN_RESOURCE_HOST_TRIGGERS:
                 if ($screenItem['resourceid']) {
                     $hostIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 }
                 break;
             case SCREEN_RESOURCE_GRAPH:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No graph ID provided for screen element.'));
                 }
                 $graphIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_LLD_GRAPH:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No graph prototype ID provided for screen element.'));
                 }
                 $graphPrototypeIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_LLD_SIMPLE_GRAPH:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No item prototype ID provided for screen element.'));
                 }
                 $itemPrototypeIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_SIMPLE_GRAPH:
             case SCREEN_RESOURCE_PLAIN_TEXT:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No item ID provided for screen element.'));
                 }
                 $itemIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_CLOCK:
                 if (isset($screenItem['style'])) {
                     if ($screenItem['style'] == TIME_TYPE_HOST) {
                         if (!$screenItem['resourceid']) {
                             self::exception(ZBX_API_ERROR_PARAMETERS, _('No item ID provided for screen element.'));
                         }
                         $itemIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                     } elseif ($screenItem['resourceid']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot set resource ID for screen element.'));
                     }
                 }
                 break;
             case SCREEN_RESOURCE_MAP:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No map ID provided for screen element.'));
                 }
                 $mapIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_SCREEN:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No screen ID provided for screen element.'));
                 }
                 $screenIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_ACTIONS:
             case SCREEN_RESOURCE_SERVER_INFO:
             case SCREEN_RESOURCE_SYSTEM_STATUS:
             case SCREEN_RESOURCE_URL:
                 if ($screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot set resource ID for screen element.'));
                 }
                 break;
         }
         // check url
         if ($screenItem['resourcetype'] == SCREEN_RESOURCE_URL) {
             if (!isset($screenItem['url']) || zbx_empty($screenItem['url'])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No URL provided for screen element.'));
             }
         }
         // check "Show lines"
         if (isset($screenItem['elements'])) {
             switch ($screenItem['resourcetype']) {
                 case SCREEN_RESOURCE_ACTIONS:
                 case SCREEN_RESOURCE_EVENTS:
                 case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
                 case SCREEN_RESOURCE_HOST_TRIGGERS:
                 case SCREEN_RESOURCE_PLAIN_TEXT:
                     if ($screenItem['elements'] < 1 || $screenItem['elements'] > 100) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect value "%1$s" for "%2$s" field: must be between %3$s and %4$s.', $screenItem['elements'], 'elements', 1, 100));
                     }
                     break;
             }
         }
         // check 'max_columns' parameter for LLD screen resources:
         // is set and valid for create method, and is valid for update method, if set
         $dbScreenItem = isset($screenItem['screenitemid']) ? $dbScreenItems[$screenItem['screenitemid']] : null;
         $lldResources = array(SCREEN_RESOURCE_LLD_GRAPH, SCREEN_RESOURCE_LLD_SIMPLE_GRAPH);
         if (in_array($screenItem['resourcetype'], $lldResources)) {
             $set = isset($screenItem['max_columns']);
             $valid = $set && $this->isValidMaxColumns($screenItem['max_columns']);
             $error = $dbScreenItem ? $set && !$valid : !$set || !$valid;
             if ($error) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect max columns provided for screen element.'));
             }
         }
         if (isset($validStyles[$screenItem['resourcetype']]) && !in_array($screenItem['style'], $validStyles[$screenItem['resourcetype']])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect style provided for screen element.'));
         }
     }
     // check host groups
     if ($hostGroupsIds) {
         $dbHostGroups = API::HostGroup()->get(array('output' => array('groupid'), 'groupids' => $hostGroupsIds, 'editable' => true, 'preservekeys' => true));
         foreach ($hostGroupsIds as $hostGroupsId) {
             if (!isset($dbHostGroups[$hostGroupsId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host group ID "%1$s" provided for screen element.', $hostGroupsId));
             }
         }
     }
     // check hosts
     if ($hostIds) {
         $dbHosts = API::Host()->get(array('output' => array('hostid'), 'hostids' => $hostIds, 'editable' => true, 'preservekeys' => true));
         foreach ($hostIds as $hostId) {
             if (!isset($dbHosts[$hostId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host ID "%1$s" provided for screen element.', $hostId));
             }
         }
     }
     // check graphs
     if ($graphIds) {
         $dbGraphs = API::Graph()->get(array('output' => array('graphid'), 'graphids' => $graphIds, 'editable' => true, 'preservekeys' => true));
         foreach ($graphIds as $graphId) {
             if (!isset($dbGraphs[$graphId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect graph ID "%1$s" provided for screen element.', $graphId));
             }
         }
     }
     // check graph prototypes
     if ($graphPrototypeIds) {
         $dbGraphPrototypes = API::GraphPrototype()->get(array('output' => array('graphid'), 'graphids' => $graphPrototypeIds, 'editable' => true, 'preservekeys' => true));
         foreach ($graphPrototypeIds as $graphPrototypeId) {
             if (!isset($dbGraphPrototypes[$graphPrototypeId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect graph prototype ID "%1$s" provided for screen element.', $graphPrototypeId));
             }
         }
     }
     // check items
     if ($itemIds) {
         $dbItems = API::Item()->get(array('output' => array('itemid'), 'itemids' => $itemIds, 'editable' => true, 'preservekeys' => true, 'webitems' => true));
         foreach ($itemIds as $itemId) {
             if (!isset($dbItems[$itemId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect item ID "%1$s" provided for screen element.', $itemId));
             }
         }
     }
     // check item prototypes
     if ($itemPrototypeIds) {
         $dbItemPrototypes = API::ItemPrototype()->get(array('output' => array('itemid'), 'itemids' => $itemPrototypeIds, 'editable' => true, 'preservekeys' => true));
         foreach ($itemPrototypeIds as $itemPrototypeId) {
             if (!isset($dbItemPrototypes[$itemPrototypeId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect item prototype ID "%1$s" provided for screen element.', $itemPrototypeId));
             }
         }
     }
     // check maps
     if ($mapIds) {
         $dbMaps = API::Map()->get(array('output' => array('sysmapid'), 'sysmapids' => $mapIds, 'editable' => true, 'preservekeys' => true));
         foreach ($mapIds as $mapId) {
             if (!isset($dbMaps[$mapId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect map ID "%1$s" provided for screen element.', $mapId));
             }
         }
     }
     // check screens
     if ($screenIds) {
         $dbScreens = API::Screen()->get(array('output' => array('screenid'), 'screenids' => $screenIds, 'editable' => true, 'preservekeys' => true));
         if (count($dbScreens) < count($screenIds)) {
             $dbTemplateScreens = API::TemplateScreen()->get(array('output' => array('screenid'), 'screenids' => $screenIds, 'editable' => true, 'preservekeys' => true));
             if ($dbTemplateScreens) {
                 $dbScreens = zbx_array_merge($dbScreens, $dbTemplateScreens);
             }
         }
         foreach ($screenIds as $screenId) {
             if (!isset($dbScreens[$screenId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect screen ID "%1$s" provided for screen element.', $screenId));
             }
         }
     }
 }
        $table->addRow($name);
    }
    if ($multiselect) {
        $button = new CButton('select', _('Select'), "javascript: addSelectedValues('screens', " . zbx_jsvalue($reference) . ');');
        $table->setFooter(new CCol($button, 'right'));
        insert_js('var popupReference = ' . zbx_jsvalue($screens, true) . ';');
    }
    zbx_add_post_js('chkbxRange.pageGoName = "screens";');
    $form->addItem($table);
    $form->show();
} elseif ($srctbl == 'screens2') {
    require_once dirname(__FILE__) . '/include/screens.inc.php';
    $table = new CTableInfo(_('No screens defined.'));
    $table->setHeader(_('Name'));
    $options = array('nodeids' => $nodeid, 'output' => API_OUTPUT_EXTEND);
    $screens = API::Screen()->get($options);
    order_result($screens, 'name');
    foreach ($screens as $row) {
        $row['node_name'] = get_node_name_by_elid($row['screenid'], true);
        if (check_screen_recursion($_REQUEST['screenid'], $row['screenid'])) {
            continue;
        }
        $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : '';
        $name = new CLink($row['name'], '#');
        $row['name'] = $row['node_name'] . $row['name'];
        $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
        $name->setAttribute('onclick', $action . ' close_window(); return false;');
        $table->addRow($name);
    }
    $table->show();
} elseif ($srctbl == 'overview') {
 /**
  * Select screen ids for previously added screen names.
  */
 protected function selectScreens()
 {
     if (!empty($this->screens)) {
         $this->screensRefs = [];
         $db_screens = API::Screen()->get(['filter' => ['name' => $this->screens], 'output' => ['screenid', 'name']]);
         foreach ($db_screens as $db_screen) {
             $this->screensRefs[$db_screen['name']] = $db_screen['screenid'];
         }
         $this->screens = [];
     }
 }
Beispiel #13
0
            $values = [$dstfld1 => $screen[$srcfld1], $dstfld2 => $screen[$srcfld2]];
            $js_action = 'javascript: addValues(' . zbx_jsvalue($dstfrm) . ', ' . zbx_jsvalue($values) . '); close_window(); return false;';
        }
        $name->onClick($js_action . ' jQuery(this).removeAttr("onclick");');
        $table->addRow([$multiselect ? new CCheckBox('screens[' . zbx_jsValue($screen[$srcfld1]) . ']', $screen['screenid']) : null, $name]);
    }
    if ($multiselect) {
        $table->setFooter(new CCol((new CButton('select', _('Select')))->onClick("javascript: addSelectedValues('screens', " . zbx_jsvalue($reference) . ');')));
        insert_js('var popupReference = ' . zbx_jsvalue($screens, true) . ';');
    }
    $form->addItem($table);
    $widget->addItem($form)->show();
} elseif ($srctbl == 'screens2') {
    require_once dirname(__FILE__) . '/include/screens.inc.php';
    $table = (new CTableInfo())->setHeader(_('Name'));
    $screens = API::Screen()->get(['output' => ['screenid', 'name'], 'editable' => $writeonly === null ? null : true]);
    order_result($screens, 'name');
    foreach ($screens as $screen) {
        if (check_screen_recursion($_REQUEST['screenid'], $screen['screenid'])) {
            continue;
        }
        $name = new CLink($screen['name'], 'javascript:void(0);');
        $action = get_window_opener($dstfrm, $dstfld1, $screen[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $screen[$srcfld2]) : '');
        $name->onClick($action . ' close_window(); return false;');
        $table->addRow($name);
    }
    $widget->addItem($table)->show();
} elseif ($srctbl === 'drules') {
    $table = (new CTableInfo())->setHeader(_('Name'));
    $dRules = API::DRule()->get(['output' => ['druleid', 'name']]);
    order_result($dRules, 'name');
Beispiel #14
0
 /**
  * Validates the input parameters for the delete() method.
  *
  * @param array $userids
  *
  * @throws APIException if the input is invalid.
  */
 protected function validateDelete(array $userids)
 {
     if (!$userids) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.'));
     }
     $this->checkPermissions($userids);
     $this->checkDeleteCurrentUser($userids);
     $this->checkDeleteInternal($userids);
     // Check if deleted users have a map.
     $user_maps = API::Map()->get(['output' => ['name', 'userid'], 'userids' => $userids]);
     if ($user_maps) {
         // Get first problem user and map.
         $user_map = reset($user_maps);
         $db_users = $this->get(['output' => ['alias'], 'userids' => [$user_map['userid']], 'limit' => 1]);
         // Get first problem user.
         $db_user = reset($db_users);
         self::exception(ZBX_API_ERROR_PARAMETERS, _s('User "%1$s" is map "%2$s" owner.', $db_user['alias'], $user_map['name']));
     }
     // Check if deleted users have a screen.
     $user_screens = API::Screen()->get(['output' => ['name', 'userid'], 'userids' => $userids]);
     if ($user_screens) {
         // Get first problem user and screen.
         $user_screen = reset($user_screens);
         $db_users = $this->get(['output' => ['alias'], 'userids' => [$user_screen['userid']], 'limit' => 1]);
         // Get first problem user.
         $db_user = reset($db_users);
         self::exception(ZBX_API_ERROR_PARAMETERS, _s('User "%1$s" is screen "%2$s" owner.', $db_user['alias'], $user_screen['name']));
     }
     // Check if deleted users have a slide show.
     $user_slideshow = DBfetch(DBselect('SELECT s.name,s.userid' . ' FROM slideshows s' . ' WHERE ' . dbConditionInt('s.userid', $userids)));
     if ($user_slideshow) {
         $db_users = $this->get(['output' => ['alias'], 'userids' => [$user_slideshow['userid']], 'limit' => 1]);
         // Get first problem user.
         $db_user = reset($db_users);
         self::exception(ZBX_API_ERROR_PARAMETERS, _s('User "%1$s" is slide show "%2$s" owner.', $db_user['alias'], $user_slideshow['name']));
     }
 }
Beispiel #15
0
function update_slideshow($data)
{
    $user_data = CWebUser::$data;
    // Validate slides.
    if (empty($data['slides'])) {
        error(_('Slide show must contain slides.'));
        return false;
    }
    // validate screens.
    $screenids = zbx_objectValues($data['slides'], 'screenid');
    $screens = API::Screen()->get(['output' => ['screenid'], 'screenids' => $screenids, 'preservekeys' => true]);
    foreach ($screenids as $screenid) {
        if (!array_key_exists($screenid, $screens)) {
            error(_('Incorrect screen provided for slide show.'));
            return false;
        }
    }
    // Validate slide name.
    $db_slideshow = DBfetch(DBselect('SELECT s.slideshowid' . ' FROM slideshows s' . ' WHERE s.name=' . zbx_dbstr($data['name']) . ' AND s.slideshowid<>' . zbx_dbstr($data['slideshowid'])));
    if ($db_slideshow) {
        error(_s('Slide show "%1$s" already exists.', $data['name']));
        return false;
    }
    // Validate slide show owner.
    if (array_key_exists('userid', $data)) {
        if ($data['userid'] === null || $data['userid'] === '') {
            error(_('Slide show owner cannot be empty.'));
            return false;
        } elseif ($data['userid'] != $user_data['userid'] && $user_data['type'] != USER_TYPE_SUPER_ADMIN && $user_data['type'] != USER_TYPE_ZABBIX_ADMIN) {
            error(_('Only administrators can set slide show owner.'));
            return false;
        }
    }
    $to_update = $data;
    unset($to_update['slideshowid'], $to_update['slides'], $to_update['users'], $to_update['userGroups']);
    DB::update('slideshows', ['values' => $to_update, 'where' => ['slideshowid' => $data['slideshowid']]]);
    // Read-only sharing validation.
    foreach ($data['users'] as $user) {
        if ($data['private'] == PUBLIC_SHARING && $user['permission'] == PERM_READ) {
            error(_s('Slide show "%1$s" is public and read-only sharing is disallowed.', $data['name']));
            return false;
        }
    }
    foreach ($data['userGroups'] as $user_group) {
        if ($data['private'] == PUBLIC_SHARING && $user_group['permission'] == PERM_READ) {
            error(_s('Slide show "%1$s" is public and read-only sharing is disallowed.', $data['name']));
            return false;
        }
    }
    $shared_userids_to_delete = [];
    $shared_users_to_update = [];
    $shared_users_to_add = [];
    $shared_user_groupids_to_delete = [];
    $shared_user_groups_to_update = [];
    $shared_user_groups_to_add = [];
    // Slide show user shares.
    $db_slideshow['users'] = DBfetchArray(DBselect('SELECT s.userid,s.permission,s.slideshowuserid' . ' FROM slideshow_user s' . ' WHERE s.slideshowid=' . zbx_dbstr(getRequest('slideshowid'))));
    $userids = [];
    foreach ($db_slideshow['users'] as $user) {
        $userids[] = $user['userid'];
    }
    $allowed_users = API::User()->get(['output' => ['userid'], 'userids' => $userids, 'preservekeys' => true]);
    foreach ($db_slideshow['users'] as $key => $user) {
        if (!array_key_exists($user['userid'], $allowed_users)) {
            unset($db_slideshow['users'][$key]);
        }
    }
    $user_shares_diff = zbx_array_diff($data['users'], $db_slideshow['users'], 'userid');
    foreach ($user_shares_diff['both'] as $update_user_share) {
        $shared_users_to_update[] = ['values' => $update_user_share, 'where' => ['userid' => $update_user_share['userid'], 'slideshowid' => $data['slideshowid']]];
    }
    foreach ($user_shares_diff['first'] as $new_shared_user) {
        $new_shared_user['slideshowid'] = $data['slideshowid'];
        $shared_users_to_add[] = $new_shared_user;
    }
    $shared_userids_to_delete = zbx_objectValues($user_shares_diff['second'], 'slideshowuserid');
    // Slide show user group shares.
    $db_slideshow['userGroups'] = DBfetchArray(DBselect('SELECT s.usrgrpid,s.permission,s.slideshowusrgrpid' . ' FROM slideshow_usrgrp s' . ' WHERE s.slideshowid=' . zbx_dbstr(getRequest('slideshowid'))));
    $usrgrpids = [];
    foreach ($db_slideshow['userGroups'] as $user_group) {
        $usrgrpids[] = $user_group['usrgrpid'];
    }
    $allowed_user_groups = API::UserGroup()->get(['output' => ['usrgrpid'], 'usrgrpids' => $usrgrpids, 'preservekeys' => true]);
    foreach ($db_slideshow['userGroups'] as $key => $user_group) {
        if (!array_key_exists($user_group['usrgrpid'], $allowed_user_groups)) {
            unset($db_slideshow['userGroups'][$key]);
        }
    }
    $user_group_shares_diff = zbx_array_diff($data['userGroups'], $db_slideshow['userGroups'], 'usrgrpid');
    foreach ($user_group_shares_diff['both'] as $update_user_share) {
        $shared_user_groups_to_update[] = ['values' => $update_user_share, 'where' => ['usrgrpid' => $update_user_share['usrgrpid'], 'slideshowid' => $data['slideshowid']]];
    }
    foreach ($user_group_shares_diff['first'] as $new_shared_user_group) {
        $new_shared_user_group['slideshowid'] = $data['slideshowid'];
        $shared_user_groups_to_add[] = $new_shared_user_group;
    }
    $shared_user_groupids_to_delete = zbx_objectValues($user_group_shares_diff['second'], 'slideshowusrgrpid');
    // User shares.
    DB::insert('slideshow_user', $shared_users_to_add);
    DB::update('slideshow_user', $shared_users_to_update);
    if ($shared_userids_to_delete) {
        DB::delete('slideshow_user', ['slideshowuserid' => $shared_userids_to_delete]);
    }
    // User group shares.
    DB::insert('slideshow_usrgrp', $shared_user_groups_to_add);
    DB::update('slideshow_usrgrp', $shared_user_groups_to_update);
    if ($shared_user_groupids_to_delete) {
        DB::delete('slideshow_usrgrp', ['slideshowusrgrpid' => $shared_user_groupids_to_delete]);
    }
    // get slides
    $db_slides = DBfetchArrayAssoc(DBselect('SELECT s.* FROM slides s WHERE s.slideshowid=' . zbx_dbstr($data['slideshowid'])), 'slideid');
    $slidesToDel = zbx_objectValues($db_slides, 'slideid');
    $slidesToDel = zbx_toHash($slidesToDel);
    $step = 0;
    foreach ($data['slides'] as $slide) {
        $slide['delay'] = $slide['delay'] ? $slide['delay'] : 0;
        if (isset($db_slides[$slide['slideid']])) {
            // update slide
            if ($db_slides[$slide['slideid']]['delay'] != $slide['delay'] || $db_slides[$slide['slideid']]['step'] != $step) {
                $result = DBexecute('UPDATE slides SET step=' . zbx_dbstr($step) . ', delay=' . zbx_dbstr($slide['delay']) . ' WHERE slideid=' . zbx_dbstr($slide['slideid']));
            } else {
                $result = true;
            }
            unset($slidesToDel[$slide['slideid']]);
        } else {
            $slideid = get_dbid('slides', 'slideid');
            $result = DBexecute('INSERT INTO slides (slideid,slideshowid,screenid,step,delay)' . ' VALUES (' . zbx_dbstr($slideid) . ',' . zbx_dbstr($data['slideshowid']) . ',' . zbx_dbstr($slide['screenid']) . ',' . zbx_dbstr($step) . ',' . zbx_dbstr($slide['delay']) . ')');
        }
        $step++;
        if (!$result) {
            return false;
        }
    }
    // delete unnecessary slides
    if (!empty($slidesToDel)) {
        DBexecute('DELETE FROM slides WHERE slideid IN(' . implode(',', $slidesToDel) . ')');
    }
    return true;
}
 /**
  * Get screens references by screen ids.
  *
  * @param array $screenIds
  *
  * @return array
  */
 protected function getScreensReferences(array $screenIds)
 {
     $idents = array();
     $screens = API::Screen()->get(array('screenids' => $screenIds, 'output' => API_OUTPUT_EXTEND, 'nodeids' => get_current_nodeid(true), 'preservekeys' => true));
     foreach ($screens as $id => $screen) {
         $idents[$id] = array('name' => $screen['name']);
     }
     return $idents;
 }
    if ($resourceId > 0) {
        $data = API::HostGroup()->get(array('groupids' => $resourceId, 'output' => array('groupid', 'name'), 'editable' => true));
        if ($data) {
            $data = reset($data);
            $data['prefix'] = get_node_name_by_elid($data['groupid'], true, NAME_DELIMITER);
        }
    }
    $screenFormList->addRow(_('Group'), new CMultiSelect(array('name' => 'resourceid', 'objectName' => 'hostGroup', 'objectOptions' => array('editable' => true), 'data' => $data ? array(array('id' => $data['groupid'], 'name' => $data['name'], 'prefix' => $data['prefix'])) : null, 'selectedLimit' => 1, 'popup' => array('parameters' => 'srctbl=host_groups&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid' . '&srcfld1=groupid&writeonly=1', 'width' => 450, 'height' => 450))));
    $screenFormList->addRow(_('Application'), new CTextBox('application', $application, ZBX_TEXTBOX_STANDARD_SIZE, false, 255));
} elseif ($resourceType == SCREEN_RESOURCE_SCREEN) {
    $caption = '';
    $id = 0;
    if ($resourceId > 0) {
        $db_screens = DBselect('SELECT DISTINCT n.name AS node_name,s.screenid,s.name' . ' FROM screens s' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('s.screenid') . ' WHERE s.screenid=' . zbx_dbstr($resourceId));
        while ($row = DBfetch($db_screens)) {
            $screen = API::Screen()->get(array('screenids' => $row['screenid'], 'output' => array('screenid')));
            if (empty($screen)) {
                continue;
            }
            if (check_screen_recursion($_REQUEST['screenid'], $row['screenid'])) {
                continue;
            }
            $row['node_name'] = !empty($row['node_name']) ? '(' . $row['node_name'] . ') ' : '';
            $caption = $row['node_name'] . $row['name'];
            $id = $resourceId;
        }
    }
    $screenFormList->addVar('resourceid', $id);
    $screenFormList->addRow(_('Parameter'), array(new CTextBox('caption', $caption, ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), new CButton('select', _('Select'), 'javascript: return PopUp("popup.php?srctbl=screens2&srcfld1=screenid&srcfld2=name' . '&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&writeonly=1&screenid=' . $_REQUEST['screenid'] . '", 800, 450);', 'formlist')));
} elseif ($resourceType == SCREEN_RESOURCE_HOSTS_INFO || $resourceType == SCREEN_RESOURCE_TRIGGERS_INFO) {
    $data = array();
 /**
  * Get screens references by screen ids.
  *
  * @param array $screenIds
  *
  * @return array
  */
 protected function getScreensReferences(array $screenIds)
 {
     $ids = [];
     $screens = API::Screen()->get(['screenids' => $screenIds, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true]);
     foreach ($screens as $id => $screen) {
         $ids[$id] = ['name' => $screen['name']];
     }
     return $ids;
 }
Beispiel #19
0
 public static function parseScreen($rules, $xml = null)
 {
     $xml = is_null($xml) ? self::$xml : $xml;
     $importScreens = self::XMLtoArray($xml);
     if (!isset($importScreens['zabbix_export']['screens'])) {
         return true;
     }
     $importScreens = $importScreens['zabbix_export']['screens'];
     $screens = array();
     foreach ($importScreens as $mnum => &$screen) {
         unset($screen['screenid']);
         $exists = API::Screen()->exists(array('name' => $screen['name']));
         if ($exists && !empty($rules['screens']['updateExisting'])) {
             $db_screens = API::Screen()->get(array('filter' => array('name' => $screen['name'])));
             if (empty($db_screens)) {
                 throw new Exception(_s('No permissions for screen "%1$s".', $screen['name']));
             }
             $db_screen = reset($db_screens);
             $screen['screenid'] = $db_screen['screenid'];
         } else {
             if ($exists || empty($rules['screens']['createMissing'])) {
                 info(_s('Screen "%1$s" skipped - user rule.', $screen['name']));
                 unset($importScreens[$mnum]);
                 continue;
                 // break if not update exist
             }
         }
         if (!isset($screen['screenitems'])) {
             $screen['screenitems'] = array();
         }
         foreach ($screen['screenitems'] as &$screenitem) {
             $nodeCaption = isset($screenitem['resourceid']['node']) ? $screenitem['resourceid']['node'] . ':' : '';
             if (!isset($screenitem['resourceid'])) {
                 $screenitem['resourceid'] = 0;
             }
             if (is_array($screenitem['resourceid'])) {
                 switch ($screenitem['resourcetype']) {
                     case SCREEN_RESOURCE_HOSTS_INFO:
                     case SCREEN_RESOURCE_TRIGGERS_INFO:
                     case SCREEN_RESOURCE_TRIGGERS_OVERVIEW:
                     case SCREEN_RESOURCE_DATA_OVERVIEW:
                     case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
                         if (is_array($screenitem['resourceid'])) {
                             $db_hostgroups = API::HostGroup()->getObjects($screenitem['resourceid']);
                             if (empty($db_hostgroups)) {
                                 $error = _s('Cannot find group "%1$s" used in screen "%2$s".', $nodeCaption . $screenitem['resourceid']['name'], $screen['name']);
                                 throw new Exception($error);
                             }
                             $tmp = reset($db_hostgroups);
                             $screenitem['resourceid'] = $tmp['groupid'];
                         }
                         break;
                     case SCREEN_RESOURCE_HOST_TRIGGERS:
                         $db_hosts = API::Host()->getObjects($screenitem['resourceid']);
                         if (empty($db_hosts)) {
                             $error = _s('Cannot find host "%1$s" used in screen "%2$s".', $nodeCaption . $screenitem['resourceid']['host'], $screen['name']);
                             throw new Exception($error);
                         }
                         $tmp = reset($db_hosts);
                         $screenitem['resourceid'] = $tmp['hostid'];
                         break;
                     case SCREEN_RESOURCE_GRAPH:
                         $db_graphs = API::Graph()->getObjects($screenitem['resourceid']);
                         if (empty($db_graphs)) {
                             $error = _s('Cannot find graph "%1$s" used in screen "%2$s".', $nodeCaption . $screenitem['resourceid']['host'] . NAME_DELIMITER . $screenitem['resourceid']['name'], $screen['name']);
                             throw new Exception($error);
                         }
                         $tmp = reset($db_graphs);
                         $screenitem['resourceid'] = $tmp['graphid'];
                         break;
                     case SCREEN_RESOURCE_SIMPLE_GRAPH:
                     case SCREEN_RESOURCE_PLAIN_TEXT:
                         $db_items = API::Item()->getObjects($screenitem['resourceid']);
                         if (empty($db_items)) {
                             $error = _s('Cannot find item "%1$s" used in screen "%2$s".', $nodeCaption . $screenitem['resourceid']['host'] . ':' . $screenitem['resourceid']['key_'], $screen['name']);
                             throw new Exception($error);
                         }
                         $tmp = reset($db_items);
                         $screenitem['resourceid'] = $tmp['itemid'];
                         break;
                     case SCREEN_RESOURCE_MAP:
                         $db_sysmaps = API::Map()->getObjects($screenitem['resourceid']);
                         if (empty($db_sysmaps)) {
                             $error = _s('Cannot find map "%1$s" used in screen "%2$s".', $nodeCaption . $screenitem['resourceid']['name'], $screen['name']);
                             throw new Exception($error);
                         }
                         $tmp = reset($db_sysmaps);
                         $screenitem['resourceid'] = $tmp['sysmapid'];
                         break;
                     case SCREEN_RESOURCE_SCREEN:
                         $db_screens = API::Screen()->get(array('screenids' => $screenitem['resourceid']));
                         if (empty($db_screens)) {
                             $error = _s('Cannot find screen "%1$s" used in screen "%2$s".', $nodeCaption . $screenitem['resourceid']['name'], $screen['name']);
                             throw new Exception($error);
                         }
                         $tmp = reset($db_screens);
                         $screenitem['resourceid'] = $tmp['screenid'];
                         break;
                     default:
                         $screenitem['resourceid'] = 0;
                         break;
                 }
             }
         }
         unset($screenitem);
         $screens[] = $screen;
     }
     unset($screen);
     $importScreens = $screens;
     foreach ($importScreens as $screen) {
         if (isset($screen['screenid'])) {
             API::Screen()->update($screen);
         } else {
             API::Screen()->create($screen);
         }
         if (isset($screen['screenid'])) {
             info(_s('Screen "%1$s" updated.', $screen['name']));
         } else {
             info(_s('Screen "%1$s" added.', $screen['name']));
         }
     }
 }
Beispiel #20
0
 /**
  * Get screen data.
  *
  * @param array  $options
  * @param array  $options['nodeids']		node IDs
  * @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'];
     $sqlParts = array('select' => array('screens' => 's.screenid'), 'from' => array('screens' => 'screens s'), 'where' => array('template' => 's.templateid IS NULL'), 'order' => array(), 'group' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'screenids' => null, 'screenitemids' => null, 'editable' => 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);
     // 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']);
     }
     // 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
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     $screenIds = array();
     $sqlParts = $this->applyQueryOutputOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
     $sqlParts = $this->applyQuerySortOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
     $sqlParts = $this->applyQueryNodeOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
     $res = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
     while ($screen = DBfetch($res)) {
         if ($options['countOutput'] !== null) {
             if ($options['groupCount'] !== null) {
                 $result[] = $screen;
             } else {
                 $result = $screen['rowscount'];
             }
         } else {
             $screenIds[$screen['screenid']] = $screen['screenid'];
             if (!isset($result[$screen['screenid']])) {
                 $result[$screen['screenid']] = array();
             }
             if (isset($screen['screenitemid']) && $options['selectScreenItems'] === null) {
                 if (!isset($result[$screen['screenid']]['screenitems'])) {
                     $result[$screen['screenid']]['screenitems'] = array();
                 }
                 $result[$screen['screenid']]['screenitems'][] = array('screenitemid' => $screen['screenitemid']);
                 unset($screen['screenitemid']);
             }
             $result[$screen['screenid']] += $screen;
         }
     }
     // editable + PERMISSION CHECK
     if ($userType == USER_TYPE_SUPER_ADMIN || $options['nopermissions']) {
     } elseif ($result) {
         $groupsToCheck = array();
         $hostsToCheck = array();
         $graphsToCheck = array();
         $itemsToCheck = array();
         $mapsToCheck = array();
         $screensToCheck = array();
         $screensItems = array();
         $dbScreenItems = DBselect('SELECT si.* FROM screens_items si WHERE ' . dbConditionInt('si.screenid', $screenIds));
         while ($screenItem = DBfetch($dbScreenItems)) {
             $screensItems[$screenItem['screenitemid']] = $screenItem;
             if ($screenItem['resourceid']) {
                 switch ($screenItem['resourcetype']) {
                     case SCREEN_RESOURCE_HOSTS_INFO:
                     case SCREEN_RESOURCE_TRIGGERS_INFO:
                     case SCREEN_RESOURCE_TRIGGERS_OVERVIEW:
                     case SCREEN_RESOURCE_DATA_OVERVIEW:
                     case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
                         $groupsToCheck[] = $screenItem['resourceid'];
                         break;
                     case SCREEN_RESOURCE_HOST_TRIGGERS:
                         $hostsToCheck[] = $screenItem['resourceid'];
                         break;
                     case SCREEN_RESOURCE_GRAPH:
                         $graphsToCheck[] = $screenItem['resourceid'];
                         break;
                     case SCREEN_RESOURCE_SIMPLE_GRAPH:
                     case SCREEN_RESOURCE_PLAIN_TEXT:
                         $itemsToCheck[] = $screenItem['resourceid'];
                         break;
                     case SCREEN_RESOURCE_MAP:
                         $mapsToCheck[] = $screenItem['resourceid'];
                         break;
                     case SCREEN_RESOURCE_SCREEN:
                         $screensToCheck[] = $screenItem['resourceid'];
                         break;
                 }
             }
         }
         $groupsToCheck = array_unique($groupsToCheck);
         $hostsToCheck = array_unique($hostsToCheck);
         $graphsToCheck = array_unique($graphsToCheck);
         $itemsToCheck = array_unique($itemsToCheck);
         $mapsToCheck = array_unique($mapsToCheck);
         $screensToCheck = array_unique($screensToCheck);
         // group
         $allowedGroups = API::HostGroup()->get(array('nodeids' => $options['nodeids'], 'groupids' => $groupsToCheck, 'editable' => $options['editable']));
         $allowedGroups = zbx_objectValues($allowedGroups, 'groupid');
         // host
         $allowedHosts = API::Host()->get(array('nodeids' => $options['nodeids'], 'hostids' => $hostsToCheck, 'editable' => $options['editable']));
         $allowedHosts = zbx_objectValues($allowedHosts, 'hostid');
         // graph
         $allowedGraphs = API::Graph()->get(array('nodeids' => $options['nodeids'], 'graphids' => $graphsToCheck, 'editable' => $options['editable']));
         $allowedGraphs = zbx_objectValues($allowedGraphs, 'graphid');
         // item
         $allowedItems = API::Item()->get(array('output' => array('itemid'), 'nodeids' => $options['nodeids'], 'itemids' => $itemsToCheck, 'webitems' => true, 'editable' => $options['editable']));
         $allowedItems = zbx_objectValues($allowedItems, 'itemid');
         // map
         $allowedMaps = API::Map()->get(array('nodeids' => $options['nodeids'], 'sysmapids' => $mapsToCheck, 'editable' => $options['editable']));
         $allowedMaps = zbx_objectValues($allowedMaps, 'sysmapid');
         // screen
         $allowedScreens = API::Screen()->get(array('nodeids' => $options['nodeids'], 'screenids' => $screensToCheck, 'editable' => $options['editable']));
         $allowedScreens = zbx_objectValues($allowedScreens, 'screenid');
         $restrGroups = array_diff($groupsToCheck, $allowedGroups);
         $restrHosts = array_diff($hostsToCheck, $allowedHosts);
         $restrGraphs = array_diff($graphsToCheck, $allowedGraphs);
         $restrItems = array_diff($itemsToCheck, $allowedItems);
         $restrMaps = array_diff($mapsToCheck, $allowedMaps);
         $restrScreens = array_diff($screensToCheck, $allowedScreens);
         // group
         foreach ($restrGroups as $resourceId) {
             foreach ($screensItems as $screenItemId => $screenItem) {
                 if (bccomp($screenItem['resourceid'], $resourceId) == 0 && uint_in_array($screenItem['resourcetype'], array(SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_TRIGGERS_INFO, SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW, SCREEN_RESOURCE_HOSTGROUP_TRIGGERS))) {
                     unset($result[$screenItem['screenid']], $screensItems[$screenItemId]);
                 }
             }
         }
         // host
         foreach ($restrHosts as $resourceId) {
             foreach ($screensItems as $screenItemId => $screenItem) {
                 if (bccomp($screenItem['resourceid'], $resourceId) == 0 && uint_in_array($screenItem['resourcetype'], array(SCREEN_RESOURCE_HOST_TRIGGERS))) {
                     unset($result[$screenItem['screenid']], $screensItems[$screenItemId]);
                 }
             }
         }
         // graph
         foreach ($restrGraphs as $resourceId) {
             foreach ($screensItems as $screenItemId => $screenItem) {
                 if (bccomp($screenItem['resourceid'], $resourceId) == 0 && $screenItem['resourcetype'] == SCREEN_RESOURCE_GRAPH) {
                     unset($result[$screenItem['screenid']], $screensItems[$screenItemId]);
                 }
             }
         }
         // item
         foreach ($restrItems as $resourceId) {
             foreach ($screensItems as $screenItemId => $screenItem) {
                 if (bccomp($screenItem['resourceid'], $resourceId) == 0 && uint_in_array($screenItem['resourcetype'], array(SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT))) {
                     unset($result[$screenItem['screenid']], $screensItems[$screenItemId]);
                 }
             }
         }
         // map
         foreach ($restrMaps as $resourceId) {
             foreach ($screensItems as $screenItemId => $screenItem) {
                 if (bccomp($screenItem['resourceid'], $resourceId) == 0 && $screenItem['resourcetype'] == SCREEN_RESOURCE_MAP) {
                     unset($result[$screenItem['screenid']], $screensItems[$screenItemId]);
                 }
             }
         }
         // screen
         foreach ($restrScreens as $resourceId) {
             foreach ($screensItems as $screenItemId => $screenItem) {
                 if (bccomp($screenItem['resourceid'], $resourceId) == 0 && $screenItem['resourcetype'] == SCREEN_RESOURCE_SCREEN) {
                     unset($result[$screenItem['screenid']], $screensItems[$screenItemId]);
                 }
             }
         }
     }
     if ($options['countOutput'] !== null) {
         return $result;
     }
     if ($result) {
         $result = $this->addRelatedObjects($options, $result);
     }
     // removing keys (hash -> array)
     if ($options['preservekeys'] === null) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
Beispiel #21
0
        CProfile::update('web.screens.timelinefixed', $_REQUEST['favid'], PROFILE_TYPE_INT);
    }
}
if ($page['type'] == PAGE_TYPE_JS || $page['type'] == PAGE_TYPE_HTML_BLOCK) {
    require_once dirname(__FILE__) . '/include/page_footer.php';
    exit;
}
/*
 * Display
 */
$data = array('fullscreen' => $_REQUEST['fullscreen'], 'period' => getRequest('period'), 'stime' => getRequest('stime'), 'elementid' => getRequest('elementid', false), 'use_screen_name' => isset($_REQUEST['screenname']));
// if none is provided
if (empty($data['elementid']) && !$data['use_screen_name']) {
    // get element id saved in profile from the last visit
    $data['elementid'] = CProfile::get('web.screens.elementid', null);
}
$data['screens'] = API::Screen()->get(array('output' => array('screenid', 'name')));
// if screen name is provided it takes priority over elementid
if ($data['use_screen_name']) {
    $data['screens'] = zbx_toHash($data['screens'], 'name');
    $data['elementIdentifier'] = getRequest('screenname');
} else {
    $data['screens'] = zbx_toHash($data['screens'], 'screenid');
    $data['elementIdentifier'] = $data['elementid'];
}
order_result($data['screens'], 'name');
// render view
$screenView = new CView('monitoring.screen', $data);
$screenView->render();
$screenView->show();
require_once dirname(__FILE__) . '/include/page_footer.php';
Beispiel #22
0
            } else {
                $data['slideshow']['userid'] = getRequest('userid');
            }
        } else {
            if ($db_slideshow) {
                $data['slideshow']['userid'] = $db_slideshow['userid'];
            } else {
                $data['slideshow']['userid'] = $current_userid;
            }
        }
    }
    $screenids = [];
    foreach ($data['slideshow']['slides'] as $slides) {
        $screenids[] = $slides['screenid'];
    }
    $data['slideshow']['screens'] = API::Screen()->get(['output' => ['screenid', 'name'], 'screenids' => $screenids, 'preservekeys' => true]);
    $data['current_user_userid'] = $current_userid;
    // Get slides without delay.
    $data['slides_without_delay'] = $data['slideshow']['slides'];
    foreach ($data['slides_without_delay'] as &$slide) {
        unset($slide['delay']);
    }
    unset($slide);
    // render view
    $slideshowView = new CView('monitoring.slideconf.edit', $data);
    $slideshowView->render();
    $slideshowView->show();
} else {
    CProfile::delete('web.slides.elementid');
    $sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'name'));
    $sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP));
 /**
  * Init screen data.
  *
  * @param array		$options
  * @param boolean	$options['isFlickerfree']
  * @param string	$options['pageFile']
  * @param int		$options['mode']
  * @param int		$options['timestamp']
  * @param int		$options['hostid']
  * @param int		$options['period']
  * @param int		$options['stime']
  * @param string	$options['profileIdx']
  * @param int		$options['profileIdx2']
  * @param boolean	$options['updateProfile']
  * @param array		$options['screen']
  */
 public function __construct(array $options = array())
 {
     $this->isFlickerfree = isset($options['isFlickerfree']) ? $options['isFlickerfree'] : true;
     $this->mode = isset($options['mode']) ? $options['mode'] : SCREEN_MODE_SLIDESHOW;
     $this->timestamp = !empty($options['timestamp']) ? $options['timestamp'] : time();
     $this->hostid = !empty($options['hostid']) ? $options['hostid'] : null;
     // get page file
     if (!empty($options['pageFile'])) {
         $this->pageFile = $options['pageFile'];
     } else {
         global $page;
         $this->pageFile = $page['file'];
     }
     // get screen
     if (!empty($options['screen'])) {
         $this->screen = $options['screen'];
     } elseif (!empty($options['screenid'])) {
         $this->screen = API::Screen()->get(array('screenids' => $options['screenid'], 'output' => API_OUTPUT_EXTEND, 'selectScreenItems' => API_OUTPUT_EXTEND, 'editable' => $this->mode == SCREEN_MODE_EDIT));
         if (!empty($this->screen)) {
             $this->screen = reset($this->screen);
         } else {
             access_deny();
         }
     }
     // calculate time
     $this->profileIdx = !empty($options['profileIdx']) ? $options['profileIdx'] : '';
     $this->profileIdx2 = !empty($options['profileIdx2']) ? $options['profileIdx2'] : null;
     $this->updateProfile = isset($options['updateProfile']) ? $options['updateProfile'] : true;
     $this->timeline = CScreenBase::calculateTime(array('profileIdx' => $this->profileIdx, 'profileIdx2' => $this->profileIdx2, 'updateProfile' => $this->updateProfile, 'period' => !empty($options['period']) ? $options['period'] : null, 'stime' => !empty($options['stime']) ? $options['stime'] : null));
 }
Beispiel #24
0
 /**
  * Validates the given screen items.
  *
  * If the $dbScreenItems parameter is given, the screen items will be matched
  * against the ones given in $dbScreenItems. If a screen item is not present in
  * $dbScreenItems, a ZBX_API_ERROR_PERMISSIONS exception will be thrown.
  *
  * @throws APIException if a validation error occurred.
  *
  * @param array $screenItems	An array of screen items to validate
  * @param array $dbScreenItems	An array of screen items $screenItems should be matched against
  */
 protected function checkInput(array $screenItems, array $dbScreenItems = array())
 {
     $hostgroups = array();
     $hosts = array();
     $graphs = array();
     $items = array();
     $maps = array();
     $screens = array();
     foreach ($screenItems as $screenItem) {
         // check if the item is editable
         if (!empty($screenItem['screenitemid']) && !isset($dbScreenItems[$screenItem['screenitemid']])) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
         }
         // check resource type
         if (!$this->isValidResourceType($screenItem['resourcetype'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect resource type provided for screen item.'));
         }
         // perform resource type specific validation
         // save the affected object ids to validate them later
         $hostGroupResourceTypes = array(SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_TRIGGERS_INFO, SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_HOSTGROUP_TRIGGERS, SCREEN_RESOURCE_DATA_OVERVIEW);
         if (in_array($screenItem['resourcetype'], $hostGroupResourceTypes)) {
             $resourceIdRequired = !in_array($screenItem['resourcetype'], array(SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_HOSTGROUP_TRIGGERS, SCREEN_RESOURCE_TRIGGERS_INFO));
             if (!$screenItem['resourceid'] && $resourceIdRequired) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No host group ID provided for screen element.'));
             } elseif ($screenItem['resourceid']) {
                 $hostgroups[] = $screenItem['resourceid'];
             }
         } elseif ($screenItem['resourcetype'] == SCREEN_RESOURCE_HOST_TRIGGERS && $screenItem['resourceid']) {
             $hosts[] = $screenItem['resourceid'];
         } elseif ($screenItem['resourcetype'] == SCREEN_RESOURCE_GRAPH) {
             if (!$screenItem['resourceid']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No graph ID provided for screen element.'));
             }
             $graphs[] = $screenItem['resourceid'];
         } elseif (in_array($screenItem['resourcetype'], array(SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT)) || $screenItem['resourcetype'] == SCREEN_RESOURCE_CLOCK && $screenItem['style'] == TIME_TYPE_HOST) {
             if (!$screenItem['resourceid']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No item ID provided for screen element.'));
             }
             $items[] = $screenItem['resourceid'];
         } elseif ($screenItem['resourcetype'] == SCREEN_RESOURCE_MAP) {
             if (!$screenItem['resourceid']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No map ID provided for screen element.'));
             }
             $maps[] = $screenItem['resourceid'];
         } elseif ($screenItem['resourcetype'] == SCREEN_RESOURCE_SCREEN) {
             if (!$screenItem['resourceid']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No screen ID provided for screen element.'));
             }
             $screens[] = $screenItem['resourceid'];
         } elseif ($screenItem['resourcetype'] == SCREEN_RESOURCE_URL) {
             if (!$screenItem['url']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No URL provided for screen element.'));
             }
         }
         // check fields specific to each resource type
         // check "Show lines" field
         switch ($screenItem['resourcetype']) {
             case SCREEN_RESOURCE_ACTIONS:
             case SCREEN_RESOURCE_EVENTS:
             case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
             case SCREEN_RESOURCE_HOST_TRIGGERS:
             case SCREEN_RESOURCE_PLAIN_TEXT:
                 if ($screenItem['elements'] < 1 || $screenItem['elements'] > 100) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect value "%1$s" for "%2$s" field: must be between %3$s and %4$s.', $screenItem['elements'], 'elements', 1, 100));
                 }
                 break;
         }
     }
     // check host groups
     if (!empty($hostgroups)) {
         $result = API::HostGroup()->get(array('groupids' => $hostgroups, 'output' => array('groupid'), 'preservekeys' => true));
         foreach ($hostgroups as $id) {
             if (!isset($result[$id])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host group ID "%s" provided for screen element.', $id));
             }
         }
     }
     // check hosts
     if ($hosts) {
         $result = API::Host()->get(array('hostids' => $hosts, 'output' => array('hostid'), 'preservekeys' => true));
         foreach ($hosts as $id) {
             if (!isset($result[$id])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host ID "%s" provided for screen element.', $id));
             }
         }
     }
     // check graphs
     if ($graphs) {
         $result = API::Graph()->get(array('graphids' => $graphs, 'output' => array('graphid'), 'preservekeys' => true));
         foreach ($graphs as $id) {
             if (!isset($result[$id])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect graph ID "%s" provided for screen element.', $id));
             }
         }
     }
     // check items
     if ($items) {
         $result = API::Item()->get(array('itemids' => $items, 'output' => array('itemid'), 'preservekeys' => true, 'webitems' => true));
         foreach ($items as $id) {
             if (!isset($result[$id])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect item ID "%s" provided for screen element.', $id));
             }
         }
     }
     // check maps
     if ($maps) {
         $result = API::Map()->get(array('sysmapids' => $maps, 'output' => array('sysmapid'), 'preservekeys' => true));
         foreach ($maps as $id) {
             if (!isset($result[$id])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect map ID "%s" provided for screen element.', $id));
             }
         }
     }
     // check screens
     if ($screens) {
         $result = API::Screen()->get(array('screenids' => $screens, 'output' => array('screenid'), 'preservekeys' => true));
         if (empty($result)) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect screen ID "%s" provided for screen element.', $id));
         }
     }
 }
Beispiel #25
0
        $data['name'] = get_request('name', '');
        $data['hsize'] = get_request('hsize', 1);
        $data['vsize'] = get_request('vsize', 1);
    }
    // render view
    $screenView = new CView('configuration.screen.edit', $data);
    $screenView->render();
    $screenView->show();
} else {
    $data = array('templateid' => get_request('templateid', null));
    $sortfield = getPageSortField('name');
    $options = array('editable' => true, 'output' => API_OUTPUT_EXTEND, 'templateids' => $data['templateid'], 'sortfield' => $sortfield, 'limit' => $config['search_limit']);
    if (!empty($data['templateid'])) {
        $data['screens'] = API::TemplateScreen()->get($options);
    } else {
        $data['screens'] = API::Screen()->get($options);
    }
    order_result($data['screens'], $sortfield, getPageSortOrder());
    // paging
    $data['paging'] = getPagingLine($data['screens'], array('screenid'), array('templateid' => get_request('templateid')));
    // nodes
    if ($data['displayNodes'] = is_array(get_current_nodeid())) {
        foreach ($data['screens'] as &$screen) {
            $screen['nodename'] = get_node_name_by_elid($screen['screenid'], true);
        }
        unset($screen);
    }
    // render view
    $screenView = new CView('configuration.screen.list', $data);
    $screenView->render();
    $screenView->show();
Beispiel #26
0
        }
        $table->addRow($name);
    }
    if ($multiselect) {
        $button = new CButton('select', _('Select'), "javascript: addSelectedValues('screens', " . zbx_jsvalue($reference) . ');');
        $table->setFooter(new CCol($button, 'right'));
        insert_js('var popupReference = ' . zbx_jsvalue($screens, true) . ';');
    }
    zbx_add_post_js('chkbxRange.pageGoName = "screens";');
    $form->addItem($table);
    $form->show();
} elseif ($srctbl == 'screens2') {
    require_once dirname(__FILE__) . '/include/screens.inc.php';
    $table = new CTableInfo(_('No screens found.'));
    $table->setHeader(_('Name'));
    $screens = API::Screen()->get(array('nodeids' => $nodeId, 'output' => array('screenid', 'name'), 'editable' => $writeonly === null ? null : true));
    order_result($screens, 'name');
    foreach ($screens as $screen) {
        if (check_screen_recursion($_REQUEST['screenid'], $screen['screenid'])) {
            continue;
        }
        $name = new CLink($screen['name'], '#');
        $action = get_window_opener($dstfrm, $dstfld1, $screen[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $screen[$srcfld2]) : '');
        $name->setAttribute('onclick', $action . ' close_window(); return false;');
        $table->addRow($name);
    }
    $table->show();
} elseif ($srctbl == 'drules') {
    $table = new CTableInfo(_('No discovery rules found.'));
    $table->setHeader(_('Name'));
    $result = DBselect('SELECT d.*' . ' FROM drules d' . whereDbNode('d.druleid', $nodeId));
     if ($resourceid > 0) {
         $groups = API::HostGroup()->get(array('groupids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'editable' => true));
         foreach ($groups as $group) {
             $caption = get_node_name_by_elid($group['groupid'], true, ':') . $group['name'];
             $id = $resourceid;
         }
     }
     $screenFormList->addVar('resourceid', $id);
     $screenFormList->addRow(_('Group'), array(new CTextBox('caption', $caption, ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), new CButton('select', _('Select'), 'javascript: return PopUp("popup.php?srctbl=overview&srcfld1=groupid&srcfld2=name' . '&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&writeonly=1", 800, 450);', 'formlist')));
 } elseif ($resourcetype == SCREEN_RESOURCE_SCREEN) {
     $caption = '';
     $id = 0;
     if ($resourceid > 0) {
         $db_screens = DBselect('SELECT DISTINCT n.name AS node_name,s.screenid,s.name' . ' FROM screens s' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('s.screenid') . ' WHERE s.screenid=' . zbx_dbstr($resourceid));
         while ($row = DBfetch($db_screens)) {
             $screen = API::Screen()->get(array('screenids' => $row['screenid'], 'output' => API_OUTPUT_SHORTEN));
             if (empty($screen)) {
                 continue;
             }
             if (check_screen_recursion($_REQUEST['screenid'], $row['screenid'])) {
                 continue;
             }
             $row['node_name'] = !empty($row['node_name']) ? '(' . $row['node_name'] . ') ' : '';
             $caption = $row['node_name'] . $row['name'];
             $id = $resourceid;
         }
     }
     $screenFormList->addVar('resourceid', $id);
     $screenFormList->addRow(_('Parameter'), array(new CTextBox('caption', $caption, ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), new CButton('select', _('Select'), 'javascript: return PopUp("popup.php?srctbl=screens2&srcfld1=screenid&srcfld2=name' . '&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&writeonly=1&screenid=' . $_REQUEST['screenid'] . '", 800, 450);', 'formlist')));
 } elseif ($resourcetype == SCREEN_RESOURCE_HOSTS_INFO || $resourcetype == SCREEN_RESOURCE_TRIGGERS_INFO) {
     $caption = '';
Beispiel #28
0
/**
 * Get favourite screens and slide shows data.
 *
 * @return array['screens']
 * @return array['slideshows']
 */
function getFavouriteScreensData()
{
    $screens = $slideshows = [];
    $favourites = CFavorite::get('web.favorite.screenids');
    if ($favourites) {
        $screenIds = $slideshowIds = [];
        foreach ($favourites as $favourite) {
            if ($favourite['source'] === 'screenid') {
                $screenIds[$favourite['value']] = $favourite['value'];
            }
        }
        $dbScreens = API::Screen()->get(['output' => ['screenid', 'name'], 'screenids' => $screenIds, 'preservekeys' => true]);
        foreach ($favourites as $favourite) {
            $sourceId = $favourite['value'];
            if ($favourite['source'] === 'slideshowid') {
                if (slideshow_accessible($sourceId, PERM_READ)) {
                    $dbSlideshow = get_slideshow_by_slideshowid($sourceId, PERM_READ);
                    if ($dbSlideshow) {
                        $slideshows[] = ['id' => $dbSlideshow['slideshowid'], 'label' => $dbSlideshow['name']];
                    }
                }
            } else {
                if (isset($dbScreens[$sourceId])) {
                    $dbScreen = $dbScreens[$sourceId];
                    $screens[] = ['id' => $dbScreen['screenid'], 'label' => $dbScreen['name']];
                }
            }
        }
    }
    return ['screens' => $screens, 'slideshows' => $slideshows];
}
Beispiel #29
0
function make_screen_submenu()
{
    $favScreens = array();
    $fav_screens = CFavorite::get('web.favorite.screenids');
    if (!$fav_screens) {
        return $favScreens;
    }
    $screenids = array();
    foreach ($fav_screens as $favorite) {
        if ('screenid' == $favorite['source']) {
            $screenids[$favorite['value']] = $favorite['value'];
        }
    }
    $options = array('screenids' => $screenids, 'output' => array('screenid', 'name'));
    $screens = API::Screen()->get($options);
    $screens = zbx_toHash($screens, 'screenid');
    foreach ($fav_screens as $favorite) {
        $source = $favorite['source'];
        $sourceid = $favorite['value'];
        if ('slideshowid' == $source) {
            if (!slideshow_accessible($sourceid, PERM_READ)) {
                continue;
            }
            if (!($slide = get_slideshow_by_slideshowid($sourceid))) {
                continue;
            }
            $slide_added = true;
            $favScreens[] = array('name' => $slide['name'], 'favobj' => 'slideshowid', 'favid' => $slide['slideshowid'], 'favaction' => 'remove');
        } else {
            if (!isset($screens[$sourceid])) {
                continue;
            }
            $screen = $screens[$sourceid];
            $screen_added = true;
            $favScreens[] = array('name' => $screen['name'], 'favobj' => 'screenid', 'favid' => $screen['screenid'], 'favaction' => 'remove');
        }
    }
    if (isset($screen_added)) {
        $favScreens[] = array('name' => _('Remove') . ' ' . _('All') . ' ' . _('Screens'), 'favobj' => 'screenid', 'favid' => 0, 'favaction' => 'remove');
    }
    if (isset($slide_added)) {
        $favScreens[] = array('name' => _('Remove') . ' ' . _('All') . ' ' . _('Slides'), 'favobj' => 'slideshowid', 'favid' => 0, 'favaction' => 'remove');
    }
    return $favScreens;
}
Beispiel #30
0
$data = ['fullscreen' => $_REQUEST['fullscreen'], 'period' => getRequest('period'), 'stime' => getRequest('stime')];
$options = ['output' => ['screenid', 'name']];
if (getRequest('elementid')) {
    $options['screenids'] = getRequest('elementid');
    CProfile::update('web.screens.elementid', getRequest('elementid'), PROFILE_TYPE_ID);
} elseif (hasRequest('screenname')) {
    $options['filter']['name'] = getRequest('screenname');
} elseif (CProfile::get('web.screens.elementid')) {
    $options['screenids'] = CProfile::get('web.screens.elementid');
} else {
    // Redirect to screen list.
    ob_end_clean();
    redirect('screenconf.php');
}
$screens = API::Screen()->get($options);
if (!$screens && (getRequest('elementid') || hasRequest('screenname'))) {
    access_deny();
} elseif (!$screens) {
    // Redirect to screen list.
    ob_end_clean();
    redirect('screenconf.php');
} else {
    $data['screen'] = reset($screens);
    $data['screen']['editable'] = (bool) API::Screen()->get(['output' => [], 'screenids' => [$data['screen']['screenid']], 'editable' => true]);
}
ob_end_flush();
// render view
$screenView = new CView('monitoring.screen', $data);
$screenView->render();
$screenView->show();
require_once dirname(__FILE__) . '/include/page_footer.php';