protected function doAction() { $sortField = $this->getInput('sort', CProfile::get('web.scripts.php.sort', 'name')); $sortOrder = $this->getInput('sortorder', CProfile::get('web.scripts.php.sortorder', ZBX_SORT_UP)); CProfile::update('web.scripts.php.sort', $sortField, PROFILE_TYPE_STR); CProfile::update('web.scripts.php.sortorder', $sortOrder, PROFILE_TYPE_STR); $config = select_config(); $data = ['uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, 'sortorder' => $sortOrder]; // list of scripts $data['scripts'] = API::Script()->get(['output' => ['scriptid', 'name', 'command', 'host_access', 'usrgrpid', 'groupid', 'type', 'execute_on'], 'editable' => true, 'limit' => $config['search_limit'] + 1]); // sorting & paging order_result($data['scripts'], $sortField, $sortOrder); $url = (new CUrl('zabbix.php'))->setArgument('action', 'script.list'); $data['paging'] = getPagingLine($data['scripts'], $sortOrder, $url); // find script host group name and user group name. set to '' if all host/user groups used. $usrgrpids = []; $groupids = []; foreach ($data['scripts'] as &$script) { $script['userGroupName'] = null; // all user groups $script['hostGroupName'] = null; // all host groups if ($script['usrgrpid'] != 0) { $usrgrpids[] = $script['usrgrpid']; } if ($script['groupid'] != 0) { $groupids[] = $script['groupid']; } } unset($script); if ($usrgrpids) { $userGroups = API::UserGroup()->get(['output' => ['name'], 'usrgrpids' => $usrgrpids, 'preservekeys' => true]); foreach ($data['scripts'] as &$script) { if ($script['usrgrpid'] != 0 && array_key_exists($script['usrgrpid'], $userGroups)) { $script['userGroupName'] = $userGroups[$script['usrgrpid']]['name']; } unset($script['usrgrpid']); } unset($script); } if ($groupids) { $hostGroups = API::HostGroup()->get(['output' => ['name'], 'groupids' => $groupids, 'preservekeys' => true]); foreach ($data['scripts'] as &$script) { if ($script['groupid'] != 0 && array_key_exists($script['groupid'], $hostGroups)) { $script['hostGroupName'] = $hostGroups[$script['groupid']]['name']; } unset($script['groupid']); } unset($script); } $response = new CControllerResponseData($data); $response->setTitle(_('Configuration of scripts')); $this->setResponse($response); }
protected function doAction() { // default values $data = ['sid' => $this->getUserSID(), 'scriptid' => 0, 'name' => '', 'type' => ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT, 'execute_on' => ZBX_SCRIPT_EXECUTE_ON_AGENT, 'command' => '', 'commandipmi' => '', 'description' => '', 'usrgrpid' => 0, 'groupid' => 0, 'host_access' => 0, 'confirmation' => '', 'enable_confirmation' => 0, 'hgstype' => 0]; // get values from the dabatase if ($this->hasInput('scriptid')) { $scripts = API::Script()->get(['output' => ['scriptid', 'name', 'type', 'execute_on', 'command', 'description', 'usrgrpid', 'groupid', 'host_access', 'confirmation'], 'scriptids' => $this->getInput('scriptid')]); $script = $scripts[0]; $data['scriptid'] = $script['scriptid']; $data['name'] = $script['name']; $data['type'] = $script['type']; $data['execute_on'] = $script['execute_on']; $data['command'] = $script['type'] == ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT ? $script['command'] : ''; $data['commandipmi'] = $script['type'] == ZBX_SCRIPT_TYPE_IPMI ? $script['command'] : ''; $data['description'] = $script['description']; $data['usrgrpid'] = $script['usrgrpid']; $data['groupid'] = $script['groupid']; $data['host_access'] = $script['host_access']; $data['confirmation'] = $script['confirmation']; $data['enable_confirmation'] = $script['confirmation'] !== ''; $data['hgstype'] = $script['groupid'] != 0 ? 1 : 0; } // overwrite with input variables $this->getInputs($data, ['name', 'type', 'execute_on', 'command', 'commandipmi', 'description', 'usrgrpid', 'groupid', 'host_access', 'confirmation', 'enable_confirmation', 'hgstype']); // get host group if ($data['groupid'] == 0) { $data['hostgroup'] = null; } else { $hostgroups = API::HostGroup()->get(['groupids' => [$data['groupid']], 'output' => ['groupid', 'name']]); $hostgroup = $hostgroups[0]; $data['hostgroup'][] = ['id' => $hostgroup['groupid'], 'name' => $hostgroup['name']]; } // get list of user groups $usergroups = API::UserGroup()->get(['output' => ['usrgrpid', 'name']]); order_result($usergroups, 'name'); $data['usergroups'] = $usergroups; $response = new CControllerResponseData($data); $response->setTitle(_('Configuration of scripts')); $this->setResponse($response); }
$data['userid'] = $userId; $data['form'] = getRequest('form'); $data['form_refresh'] = getRequest('form_refresh', 0); $data['autologout'] = getRequest('autologout'); // render view $usersView = new CView('administration.users.edit', $data); $usersView->render(); $usersView->show(); } else { $sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'alias')); $sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP)); CProfile::update('web.' . $page['file'] . '.sort', $sortField, PROFILE_TYPE_STR); CProfile::update('web.' . $page['file'] . '.sortorder', $sortOrder, PROFILE_TYPE_STR); $data = array('config' => $config, 'sort' => $sortField, 'sortorder' => $sortOrder); // get user groups $data['userGroups'] = API::UserGroup()->get(array('output' => API_OUTPUT_EXTEND)); order_result($data['userGroups'], 'name'); // get users $data['users'] = API::User()->get(array('usrgrpids' => $_REQUEST['filter_usrgrpid'] > 0 ? $_REQUEST['filter_usrgrpid'] : null, 'output' => API_OUTPUT_EXTEND, 'selectUsrgrps' => API_OUTPUT_EXTEND, 'getAccess' => 1, 'limit' => $config['search_limit'] + 1)); // sorting & paging order_result($data['users'], $sortField, $sortOrder); $data['paging'] = getPagingLine($data['users'], $sortOrder); // set default lastaccess time to 0 foreach ($data['users'] as $user) { $data['usersSessions'][$user['userid']] = array('lastaccess' => 0); } $dbSessions = DBselect('SELECT s.userid,MAX(s.lastaccess) AS lastaccess,s.status' . ' FROM sessions s' . ' WHERE ' . dbConditionInt('s.userid', zbx_objectValues($data['users'], 'userid')) . ' GROUP BY s.userid,s.status'); while ($session = DBfetch($dbSessions)) { if ($data['usersSessions'][$session['userid']]['lastaccess'] < $session['lastaccess']) { $data['usersSessions'][$session['userid']] = $session; }
$sqlFrom = ''; $sqlWhere = whereDbNode('u.userid'); } $data['users'] = DBfetchArray(DBselect('SELECT DISTINCT u.userid,u.alias,u.name,u.surname' . ' FROM users u' . $sqlFrom . $sqlWhere)); order_result($data['users'], 'alias'); // get user groups $data['usergroups'] = DBfetchArray(DBselect('SELECT ug.usrgrpid,ug.name' . ' FROM usrgrp ug' . whereDbNode('usrgrpid'))); order_result($data['usergroups'], 'name'); // render view $userGroupsView = new CView('administration.usergroups.edit', $data); $userGroupsView->render(); $userGroupsView->show(); } else { $data = array('displayNodes' => is_array(get_current_nodeid())); $sortfield = getPageSortField('name'); $data['usergroups'] = API::UserGroup()->get(array('output' => API_OUTPUT_EXTEND, 'selectUsers' => API_OUTPUT_EXTEND, 'sortfield' => $sortfield, 'limit' => $config['search_limit'] + 1)); // sorting & paging order_result($data['usergroups'], $sortfield, getPageSortOrder()); $data['paging'] = getPagingLine($data['usergroups'], array('usrgrpid')); // nodes if ($data['displayNodes']) { foreach ($data['usergroups'] as &$userGroup) { $userGroup['nodename'] = get_node_name_by_elid($userGroup['usrgrpid'], true); } unset($userGroup); } // render view $userGroupsView = new CView('administration.usergroups.list', $data); $userGroupsView->render(); $userGroupsView->show(); }
} foreach (getRequest('userGroups', []) as $user_group) { $user_groupids[$user_group['usrgrpid']] = $user_group['usrgrpid']; } } else { // Map owner. $userids[$sysmap['userid']] = $sysmap['userid']; foreach ($sysmap['users'] as $user) { $userids[$user['userid']] = $user['userid']; } foreach ($sysmap['userGroups'] as $user_group) { $user_groupids[$user_group['usrgrpid']] = $user_group['usrgrpid']; } } $data['users'] = API::User()->get(['output' => ['userid', 'alias', 'name', 'surname'], 'userids' => $userids, 'preservekeys' => true]); $data['user_groups'] = API::UserGroup()->get(['output' => ['usrgrpid', 'name'], 'usrgrpids' => $user_groupids, 'preservekeys' => true]); if (!hasRequest('sysmapid') || hasRequest('form_refresh')) { $data['sysmap'] = ['sysmapid' => getRequest('sysmapid'), 'name' => getRequest('name', ''), 'width' => getRequest('width', 800), 'height' => getRequest('height', 600), 'backgroundid' => getRequest('backgroundid', 0), 'iconmapid' => getRequest('iconmapid', 0), 'label_format' => getRequest('label_format', 0), 'label_type_host' => getRequest('label_type_host', 2), 'label_type_hostgroup' => getRequest('label_type_hostgroup', 2), 'label_type_trigger' => getRequest('label_type_trigger', 2), 'label_type_map' => getRequest('label_type_map', 2), 'label_type_image' => getRequest('label_type_image', 2), 'label_string_host' => getRequest('label_string_host', ''), 'label_string_hostgroup' => getRequest('label_string_hostgroup', ''), 'label_string_trigger' => getRequest('label_string_trigger', ''), 'label_string_map' => getRequest('label_string_map', ''), 'label_string_image' => getRequest('label_string_image', ''), 'label_type' => getRequest('label_type', 0), 'label_location' => getRequest('label_location', 0), 'highlight' => getRequest('highlight', 0), 'markelements' => getRequest('markelements', 0), 'expandproblem' => getRequest('expandproblem', 0), 'show_unack' => getRequest('show_unack', 0), 'severity_min' => getRequest('severity_min', TRIGGER_SEVERITY_NOT_CLASSIFIED), 'urls' => getRequest('urls', []), 'userid' => getRequest('userid', hasRequest('form_refresh') ? '' : $current_userid), 'private' => getRequest('private', PRIVATE_SHARING), 'users' => getRequest('users', []), 'userGroups' => getRequest('userGroups', [])]; } else { $data['sysmap'] = $sysmap; } $data['current_user_userid'] = $current_userid; $data['form_refresh'] = getRequest('form_refresh'); // config $data['config'] = select_config(); // advanced labels $data['labelTypes'] = sysmapElementLabel(); $data['labelTypesLimited'] = $data['labelTypes']; unset($data['labelTypesLimited'][MAP_LABEL_TYPE_IP]); $data['labelTypesImage'] = $data['labelTypesLimited']; unset($data['labelTypesImage'][MAP_LABEL_TYPE_STATUS]);
public function validateOperations($operations) { $operations = zbx_toArray($operations); foreach ($operations as $operation) { if ((isset($operation['esc_step_from']) || isset($operation['esc_step_to'])) && !isset($operation['esc_step_from'], $operation['esc_step_to'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('esc_step_from and esc_step_to must be set together.')); } if (isset($operation['esc_step_from'], $operation['esc_step_to'])) { if ($operation['esc_step_from'] < 1 || $operation['esc_step_to'] < 0) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action operation escalation step values.')); } if ($operation['esc_step_from'] > $operation['esc_step_to'] && $operation['esc_step_to'] != 0) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action operation escalation step values.')); } } if (isset($operation['esc_period'])) { if (isset($operation['esc_period']) && $operation['esc_period'] != 0 && $operation['esc_period'] < SEC_PER_MIN) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action operation step duration.')); } } $hostIdsAll = $hostGroupIdsAll = $useridsAll = $userGroupidsAll = array(); switch ($operation['operationtype']) { case OPERATION_TYPE_MESSAGE: $userids = isset($operation['opmessage_usr']) ? zbx_objectValues($operation['opmessage_usr'], 'userid') : array(); $usergroupids = isset($operation['opmessage_grp']) ? zbx_objectValues($operation['opmessage_grp'], 'usrgrpid') : array(); if (empty($userids) && empty($usergroupids)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('No recipients for action operation message.')); } $useridsAll = array_merge($useridsAll, $userids); $userGroupidsAll = array_merge($userGroupidsAll, $usergroupids); break; case OPERATION_TYPE_COMMAND: if (!isset($operation['opcommand']['type'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('No command type specified for action operation.')); } if ((!isset($operation['opcommand']['command']) || zbx_empty(trim($operation['opcommand']['command']))) && $operation['opcommand']['type'] != ZBX_SCRIPT_TYPE_GLOBAL_SCRIPT) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('No command specified for action operation.')); } switch ($operation['opcommand']['type']) { case ZBX_SCRIPT_TYPE_IPMI: break; case ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT: if (!isset($operation['opcommand']['execute_on'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('No execution target specified for action operation command "%s".', $operation['opcommand']['command'])); } break; case ZBX_SCRIPT_TYPE_SSH: if (!isset($operation['opcommand']['authtype']) || zbx_empty($operation['opcommand']['authtype'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('No authentication type specified for action operation command "%s".', $operation['opcommand']['command'])); } if (!isset($operation['opcommand']['username']) || zbx_empty($operation['opcommand']['username'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('No authentication user name specified for action operation command "%s".', $operation['opcommand']['command'])); } if ($operation['opcommand']['authtype'] == ITEM_AUTHTYPE_PUBLICKEY) { if (!isset($operation['opcommand']['publickey']) || zbx_empty($operation['opcommand']['publickey'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('No public key file specified for action operation command "%s".', $operation['opcommand']['command'])); } if (!isset($operation['opcommand']['privatekey']) || zbx_empty($operation['opcommand']['privatekey'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('No private key file specified for action operation command "%s".', $operation['opcommand']['command'])); } } break; case ZBX_SCRIPT_TYPE_TELNET: if (!isset($operation['opcommand']['username']) || zbx_empty($operation['opcommand']['username'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('No authentication user name specified for action operation command "%s".', $operation['opcommand']['command'])); } break; case ZBX_SCRIPT_TYPE_GLOBAL_SCRIPT: if (!isset($operation['opcommand']['scriptid']) || zbx_empty($operation['opcommand']['scriptid'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('No script specified for action operation command.')); } $scripts = API::Script()->get(array('output' => array('scriptid', 'name'), 'scriptids' => $operation['opcommand']['scriptid'], 'preservekeys' => true)); if (!isset($scripts[$operation['opcommand']['scriptid']])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Specified script does not exist or you do not have rights on it for action operation command.')); } break; default: self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action operation command type.')); } if (isset($operation['opcommand']['port']) && !zbx_empty($operation['opcommand']['port'])) { if (zbx_ctype_digit($operation['opcommand']['port'])) { if ($operation['opcommand']['port'] > 65535 || $operation['opcommand']['port'] < 1) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect action operation port "%s".', $operation['opcommand']['port'])); } } elseif (!preg_match('/^' . ZBX_PREG_EXPRESSION_USER_MACROS . '$/', $operation['opcommand']['port'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect action operation port "%s".', $operation['opcommand']['port'])); } } $groupids = array(); if (isset($operation['opcommand_grp'])) { $groupids = zbx_objectValues($operation['opcommand_grp'], 'groupid'); } $hostids = array(); $withoutCurrent = true; if (isset($operation['opcommand_hst'])) { foreach ($operation['opcommand_hst'] as $hstCommand) { if ($hstCommand['hostid'] == 0) { $withoutCurrent = false; } else { $hostids[$hstCommand['hostid']] = $hstCommand['hostid']; } } } if (empty($groupids) && empty($hostids) && $withoutCurrent) { if ($operation['opcommand']['type'] == ZBX_SCRIPT_TYPE_GLOBAL_SCRIPT) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('You did not specify targets for action operation global script "%s".', $scripts[$operation['opcommand']['scriptid']]['name'])); } else { self::exception(ZBX_API_ERROR_PARAMETERS, _s('You did not specify targets for action operation command "%s".', $operation['opcommand']['command'])); } } $hostIdsAll = array_merge($hostIdsAll, $hostids); $hostGroupIdsAll = array_merge($hostGroupIdsAll, $groupids); break; case OPERATION_TYPE_GROUP_ADD: case OPERATION_TYPE_GROUP_REMOVE: $groupids = isset($operation['opgroup']) ? zbx_objectValues($operation['opgroup'], 'groupid') : array(); if (empty($groupids)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Operation has no group to operate.')); } $hostGroupIdsAll = array_merge($hostGroupIdsAll, $groupids); break; case OPERATION_TYPE_TEMPLATE_ADD: case OPERATION_TYPE_TEMPLATE_REMOVE: $templateids = isset($operation['optemplate']) ? zbx_objectValues($operation['optemplate'], 'templateid') : array(); if (empty($templateids)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Operation has no template to operate.')); } $hostIdsAll = array_merge($hostIdsAll, $templateids); break; case OPERATION_TYPE_HOST_ADD: case OPERATION_TYPE_HOST_REMOVE: case OPERATION_TYPE_HOST_ENABLE: case OPERATION_TYPE_HOST_DISABLE: break; default: self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action operation type.')); } } if (!API::HostGroup()->isWritable($hostGroupIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action operation host group. Host group does not exist or you have no access to this host group.')); } if (!API::Host()->isWritable($hostIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action operation host. Host does not exist or you have no access to this host.')); } if (!API::User()->isReadable($useridsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action operation user. User does not exist or you have no access to this user.')); } if (!API::UserGroup()->isReadable($userGroupidsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action operation user group. User group does not exist or you have no access to this user group.')); } return true; }
$this->data['new_operation']['opmessage']['message'] = ''; } } if (!isset($this->data['new_operation']['opmessage']['default_msg'])) { $this->data['new_operation']['opmessage']['default_msg'] = 0; } $usrgrpList = (new CTable())->setAttribute('style', 'width: 100%;')->setHeader([_('User group'), _('Action')]); $addUsrgrpBtn = (new CButton(null, _('Add')))->onClick('return PopUp("popup.php?dstfrm=action.edit&srctbl=usrgrp&srcfld1=usrgrpid&srcfld2=name&multiselect=1")')->addClass(ZBX_STYLE_BTN_LINK); $usrgrpList->addRow((new CRow((new CCol($addUsrgrpBtn))->setColSpan(2)))->setId('opmsgUsrgrpListFooter')); $userList = (new CTable())->setAttribute('style', 'width: 100%;')->setHeader([_('User'), _('Action')]); $addUserBtn = (new CButton(null, _('Add')))->onClick('return PopUp("popup.php?dstfrm=action.edit&srctbl=users&srcfld1=userid&srcfld2=fullname&multiselect=1")')->addClass(ZBX_STYLE_BTN_LINK); $userList->addRow((new CRow((new CCol($addUserBtn))->setColSpan(2)))->setId('opmsgUserListFooter')); // add participations $usrgrpids = isset($this->data['new_operation']['opmessage_grp']) ? zbx_objectValues($this->data['new_operation']['opmessage_grp'], 'usrgrpid') : []; $userids = isset($this->data['new_operation']['opmessage_usr']) ? zbx_objectValues($this->data['new_operation']['opmessage_usr'], 'userid') : []; $usrgrps = API::UserGroup()->get(['usrgrpids' => $usrgrpids, 'output' => ['name']]); order_result($usrgrps, 'name'); $users = API::User()->get(['userids' => $userids, 'output' => ['userid', 'alias', 'name', 'surname']]); order_result($users, 'alias'); foreach ($users as &$user) { $user['id'] = $user['userid']; $user['name'] = getUserFullname($user); } unset($user); $jsInsert = 'addPopupValues(' . zbx_jsvalue(['object' => 'usrgrpid', 'values' => $usrgrps]) . ');'; $jsInsert .= 'addPopupValues(' . zbx_jsvalue(['object' => 'userid', 'values' => $users]) . ');'; zbx_add_post_js($jsInsert); $new_operation_formlist->addRow(_('Send to User groups'), (new CDiv($usrgrpList))->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)->setAttribute('style', 'min-width: ' . ZBX_TEXTAREA_STANDARD_WIDTH . 'px;'))->addRow(_('Send to Users'), (new CDiv($userList))->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)->setAttribute('style', 'min-width: ' . ZBX_TEXTAREA_STANDARD_WIDTH . 'px;')); $mediaTypeComboBox = (new CComboBox('new_operation[opmessage][mediatypeid]', $this->data['new_operation']['opmessage']['mediatypeid']))->addItem(0, '- ' . _('All') . ' -'); $dbMediaTypes = DBfetchArray(DBselect('SELECT mt.mediatypeid,mt.description FROM media_type mt')); order_result($dbMediaTypes, 'description');
function getUserFormData($userid, $isProfile = false) { $config = select_config(); $data = array('is_profile' => $isProfile); if (isset($userid)) { $users = API::User()->get(array('userids' => $userid, 'output' => API_OUTPUT_EXTEND)); $user = reset($users); } if (isset($userid) && (!isset($_REQUEST['form_refresh']) || isset($_REQUEST['register']))) { $data['alias'] = $user['alias']; $data['name'] = $user['name']; $data['surname'] = $user['surname']; $data['password1'] = null; $data['password2'] = null; $data['url'] = $user['url']; $data['autologin'] = $user['autologin']; $data['autologout'] = $user['autologout']; $data['lang'] = $user['lang']; $data['theme'] = $user['theme']; $data['refresh'] = $user['refresh']; $data['rows_per_page'] = $user['rows_per_page']; $data['user_type'] = $user['type']; $data['messages'] = getMessageSettings(); $userGroups = API::UserGroup()->get(array('userids' => $userid, 'output' => array('usrgrpid'))); $userGroup = zbx_objectValues($userGroups, 'usrgrpid'); $data['user_groups'] = zbx_toHash($userGroup); $data['user_medias'] = array(); $dbMedia = DBselect('SELECT m.mediaid,m.mediatypeid,m.period,m.sendto,m.severity,m.active' . ' FROM media m' . ' WHERE m.userid=' . zbx_dbstr($userid)); while ($dbMedium = DBfetch($dbMedia)) { $data['user_medias'][] = $dbMedium; } if ($data['autologout'] > 0) { $_REQUEST['autologout'] = $data['autologout']; } } else { $data['alias'] = getRequest('alias', ''); $data['name'] = getRequest('name', ''); $data['surname'] = getRequest('surname', ''); $data['password1'] = getRequest('password1', ''); $data['password2'] = getRequest('password2', ''); $data['url'] = getRequest('url', ''); $data['autologin'] = getRequest('autologin', 0); $data['autologout'] = getRequest('autologout', 900); $data['lang'] = getRequest('lang', 'en_gb'); $data['theme'] = getRequest('theme', THEME_DEFAULT); $data['refresh'] = getRequest('refresh', 30); $data['rows_per_page'] = getRequest('rows_per_page', 50); $data['user_type'] = getRequest('user_type', USER_TYPE_ZABBIX_USER); $data['user_groups'] = getRequest('user_groups', array()); $data['change_password'] = getRequest('change_password'); $data['user_medias'] = getRequest('user_medias', array()); // set messages $data['messages'] = getRequest('messages', array()); if (!isset($data['messages']['enabled'])) { $data['messages']['enabled'] = 0; } if (!isset($data['messages']['sounds.recovery'])) { $data['messages']['sounds.recovery'] = 'alarm_ok.wav'; } if (!isset($data['messages']['triggers.recovery'])) { $data['messages']['triggers.recovery'] = 0; } if (!isset($data['messages']['triggers.severities'])) { $data['messages']['triggers.severities'] = array(); } $data['messages'] = array_merge(getMessageSettings(), $data['messages']); } // authentication type if ($data['user_groups']) { $data['auth_type'] = getGroupAuthenticationType($data['user_groups'], GROUP_GUI_ACCESS_INTERNAL); } else { $data['auth_type'] = $userid === null ? $config['authentication_type'] : getUserAuthenticationType($userid, GROUP_GUI_ACCESS_INTERNAL); } // set autologout if ($data['autologin'] || !isset($data['autologout'])) { $data['autologout'] = 0; } // set media types if (!empty($data['user_medias'])) { $mediaTypeDescriptions = array(); $dbMediaTypes = DBselect('SELECT mt.mediatypeid,mt.description FROM media_type mt WHERE ' . dbConditionInt('mt.mediatypeid', zbx_objectValues($data['user_medias'], 'mediatypeid'))); while ($dbMediaType = DBfetch($dbMediaTypes)) { $mediaTypeDescriptions[$dbMediaType['mediatypeid']] = $dbMediaType['description']; } foreach ($data['user_medias'] as &$media) { $media['description'] = $mediaTypeDescriptions[$media['mediatypeid']]; } unset($media); CArrayHelper::sort($data['user_medias'], array('description', 'sendto')); } // set user rights if (!$data['is_profile']) { $data['groups'] = API::UserGroup()->get(array('usrgrpids' => $data['user_groups'], 'output' => array('usrgrpid', 'name'))); order_result($data['groups'], 'name'); $group_ids = array_values($data['user_groups']); if (count($group_ids) == 0) { $group_ids = array(-1); } $db_rights = DBselect('SELECT r.* FROM rights r WHERE ' . dbConditionInt('r.groupid', $group_ids)); // deny beat all, read-write beat read $tmp_permitions = array(); while ($db_right = DBfetch($db_rights)) { if (isset($tmp_permitions[$db_right['id']]) && $tmp_permitions[$db_right['id']] != PERM_DENY) { $tmp_permitions[$db_right['id']] = $db_right['permission'] == PERM_DENY ? PERM_DENY : max($tmp_permitions[$db_right['id']], $db_right['permission']); } else { $tmp_permitions[$db_right['id']] = $db_right['permission']; } } $data['user_rights'] = array(); foreach ($tmp_permitions as $id => $permition) { array_push($data['user_rights'], array('id' => $id, 'permission' => $permition)); } } return $data; }
$data['userid'] = $userId; $data['form'] = getRequest('form'); $data['form_refresh'] = getRequest('form_refresh', 0); $data['autologout'] = getRequest('autologout'); // render view $usersView = new CView('administration.users.edit', $data); $usersView->render(); $usersView->show(); } else { $sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'alias')); $sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP)); CProfile::update('web.' . $page['file'] . '.sort', $sortField, PROFILE_TYPE_STR); CProfile::update('web.' . $page['file'] . '.sortorder', $sortOrder, PROFILE_TYPE_STR); $data = ['config' => $config, 'sort' => $sortField, 'sortorder' => $sortOrder]; // get user groups $data['userGroups'] = API::UserGroup()->get(['output' => API_OUTPUT_EXTEND]); order_result($data['userGroups'], 'name'); // get users $data['users'] = API::User()->get(['usrgrpids' => $_REQUEST['filter_usrgrpid'] > 0 ? $_REQUEST['filter_usrgrpid'] : null, 'output' => API_OUTPUT_EXTEND, 'selectUsrgrps' => API_OUTPUT_EXTEND, 'getAccess' => 1, 'limit' => $config['search_limit'] + 1]); // sorting & paging order_result($data['users'], $sortField, $sortOrder); $data['paging'] = getPagingLine($data['users'], $sortOrder, new CUrl('users.php')); // set default lastaccess time to 0 foreach ($data['users'] as $user) { $data['usersSessions'][$user['userid']] = ['lastaccess' => 0]; } $dbSessions = DBselect('SELECT s.userid,MAX(s.lastaccess) AS lastaccess,s.status' . ' FROM sessions s' . ' WHERE ' . dbConditionInt('s.userid', zbx_objectValues($data['users'], 'userid')) . ' GROUP BY s.userid,s.status'); while ($session = DBfetch($dbSessions)) { if ($data['usersSessions'][$session['userid']]['lastaccess'] < $session['lastaccess']) { $data['usersSessions'][$session['userid']] = $session; }
$data['selected_usrgrp'] = get_request('selusrgrp', 0); // sort group rights order_result($data['group_rights'], 'name'); // get users $sql_from = ''; $sql_where = ''; if ($data['selected_usrgrp'] > 0) { $sql_from = ', users_groups g '; $sql_where = ' AND u.userid=g.userid AND g.usrgrpid=' . $data['selected_usrgrp']; } $sql = 'SELECT DISTINCT u.userid,u.alias ' . ' FROM users u ' . $sql_from . ' WHERE ' . dbConditionInt('u.userid', $data['group_users']) . ' OR (' . DBin_node('u.userid') . $sql_where . ' ) ORDER BY u.alias'; $data['users'] = DBfetchArray(DBselect($sql)); // get user groups $data['usergroups'] = DBfetchArray(DBselect('SELECT ug.usrgrpid,ug.name FROM usrgrp ug WHERE ' . DBin_node('usrgrpid') . ' ORDER BY ug.name')); // render view $userGroupsView = new CView('administration.usergroups.edit', $data); $userGroupsView->render(); $userGroupsView->show(); } else { $sortfield = getPageSortField('name'); $sortorder = getPageSortOrder(); $options = array('output' => API_OUTPUT_EXTEND, 'selectUsers' => API_OUTPUT_EXTEND, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'limit' => $config['search_limit'] + 1); $data['usergroups'] = API::UserGroup()->get($options); order_result($data['usergroups'], $sortfield, $sortorder); $data['paging'] = getPagingLine($data['usergroups']); // render view $userGroupsView = new CView('administration.usergroups.list', $data); $userGroupsView->render(); $userGroupsView->show(); } require_once dirname(__FILE__) . '/include/page_footer.php';
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $userids = zbx_objectValues($result, 'userid'); // adding usergroups if (!is_null($options['selectUsrgrps']) && str_in_array($options['selectUsrgrps'], array(API_OUTPUT_REFER, API_OUTPUT_EXTEND))) { foreach ($result as &$user) { $user['usrgrps'] = array(); } unset($user); $usrgrps = API::UserGroup()->get(array('output' => $options['selectUsrgrps'], 'userids' => $userids, 'preservekeys' => true)); foreach ($usrgrps as $usrgrp) { $uusers = $usrgrp['users']; unset($usrgrp['users']); $usrgrps = $this->unsetExtraFields('usrgrp', $usrgrps, $options['selectUsrgrps']); foreach ($uusers as $user) { $result[$user['userid']]['usrgrps'][] = $usrgrp; } } } // adding medias if (!is_null($options['selectMedias']) && str_in_array($options['selectMedias'], array(API_OUTPUT_REFER, API_OUTPUT_EXTEND))) { foreach ($result as &$user) { $user['medias'] = array(); } unset($user); $userMedias = API::UserMedia()->get(array('output' => $options['selectMedias'], 'userids' => $userids, 'preservekeys' => true)); $userMedias = $this->unsetExtraFields('media', $userMedias, $options['selectMedias']); foreach ($userMedias as $mediaid => $media) { $result[$media['userid']]['medias'][] = $media; } } // adding media types if (!is_null($options['selectMediatypes'])) { foreach ($result as &$user) { $user['mediatypes'] = array(); } unset($user); $mediatypes = API::Mediatype()->get(array('output' => $options['selectMediatypes'], 'userids' => $userids, 'selectUsers' => API_OUTPUT_REFER, 'preservekeys' => true)); foreach ($mediatypes as $mediatype) { $users = $mediatype['users']; unset($mediatype['users']); $mediatype = $this->unsetExtraFields('media_type', $mediatype, $options['selectMediatypes']); foreach ($users as $user) { if (!empty($result[$user['userid']])) { $result[$user['userid']]['mediatypes'][] = $mediatype; } } } } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $sysmapIds = array_keys($result); // adding elements if ($options['selectSelements'] !== null && $options['selectSelements'] != API_OUTPUT_COUNT) { $selements = API::getApiService()->select('sysmaps_elements', ['output' => $this->outputExtend($options['selectSelements'], ['selementid', 'sysmapid']), 'filter' => ['sysmapid' => $sysmapIds], 'preservekeys' => true]); $relation_map = $this->createRelationMap($selements, 'sysmapid', 'selementid'); // add selement URLs if ($this->outputIsRequested('urls', $options['selectSelements'])) { foreach ($selements as &$selement) { $selement['urls'] = []; } unset($selement); if (!is_null($options['expandUrls'])) { $dbMapUrls = DBselect('SELECT su.sysmapurlid,su.sysmapid,su.name,su.url,su.elementtype' . ' FROM sysmap_url su' . ' WHERE ' . dbConditionInt('su.sysmapid', $sysmapIds)); while ($mapUrl = DBfetch($dbMapUrls)) { foreach ($selements as $snum => $selement) { if (bccomp($selement['sysmapid'], $mapUrl['sysmapid']) == 0 && ($selement['elementtype'] == $mapUrl['elementtype'] && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP || $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS && $mapUrl['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST)) { $selements[$snum]['urls'][] = $this->expandUrlMacro($mapUrl, $selement); } } } } $dbSelementUrls = DBselect('SELECT seu.sysmapelementurlid,seu.selementid,seu.name,seu.url' . ' FROM sysmap_element_url seu' . ' WHERE ' . dbConditionInt('seu.selementid', array_keys($selements))); while ($selementUrl = DBfetch($dbSelementUrls)) { $selements[$selementUrl['selementid']]['urls'][] = is_null($options['expandUrls']) ? $selementUrl : $this->expandUrlMacro($selementUrl, $selements[$selementUrl['selementid']]); } } $selements = $this->unsetExtraFields($selements, ['sysmapid', 'selementid'], $options['selectSelements']); $result = $relation_map->mapMany($result, $selements, 'selements'); } // adding icon maps if ($options['selectIconMap'] !== null && $options['selectIconMap'] != API_OUTPUT_COUNT) { $iconMaps = API::getApiService()->select($this->tableName(), ['output' => ['sysmapid', 'iconmapid'], 'filter' => ['sysmapid' => $sysmapIds]]); $relation_map = $this->createRelationMap($iconMaps, 'sysmapid', 'iconmapid'); $iconMaps = API::IconMap()->get(['output' => $this->outputExtend($options['selectIconMap'], ['iconmapid']), 'iconmapids' => zbx_objectValues($iconMaps, 'iconmapid'), 'preservekeys' => true]); $iconMaps = $this->unsetExtraFields($iconMaps, ['iconmapid'], $options['selectIconMap']); $result = $relation_map->mapOne($result, $iconMaps, 'iconmap'); } // adding links if ($options['selectLinks'] !== null && $options['selectLinks'] != API_OUTPUT_COUNT) { $links = API::getApiService()->select('sysmaps_links', ['output' => $this->outputExtend($options['selectLinks'], ['sysmapid', 'linkid']), 'filter' => ['sysmapid' => $sysmapIds], 'preservekeys' => true]); $relation_map = $this->createRelationMap($links, 'sysmapid', 'linkid'); // add link triggers if ($this->outputIsRequested('linktriggers', $options['selectLinks'])) { $linkTriggers = DBFetchArrayAssoc(DBselect('SELECT DISTINCT slt.*' . ' FROM sysmaps_link_triggers slt' . ' WHERE ' . dbConditionInt('slt.linkid', $relation_map->getRelatedIds())), 'linktriggerid'); $linkTriggerRelationMap = $this->createRelationMap($linkTriggers, 'linkid', 'linktriggerid'); $links = $linkTriggerRelationMap->mapMany($links, $linkTriggers, 'linktriggers'); } $links = $this->unsetExtraFields($links, ['sysmapid', 'linkid'], $options['selectLinks']); $result = $relation_map->mapMany($result, $links, 'links'); } // adding urls if ($options['selectUrls'] !== null && $options['selectUrls'] != API_OUTPUT_COUNT) { $links = API::getApiService()->select('sysmap_url', ['output' => $this->outputExtend($options['selectUrls'], ['sysmapid', 'sysmapurlid']), 'filter' => ['sysmapid' => $sysmapIds], 'preservekeys' => true]); $relation_map = $this->createRelationMap($links, 'sysmapid', 'sysmapurlid'); $links = $this->unsetExtraFields($links, ['sysmapid', 'sysmapurlid'], $options['selectUrls']); $result = $relation_map->mapMany($result, $links, 'urls'); } // Adding user shares. if ($options['selectUsers'] !== null && $options['selectUsers'] != API_OUTPUT_COUNT) { $relation_map = $this->createRelationMap($result, 'sysmapid', 'userid', 'sysmap_user'); // Get all allowed users. $related_users = API::User()->get(['output' => ['userid'], 'userids' => $relation_map->getRelatedIds(), 'preservekeys' => true]); $related_userids = zbx_objectValues($related_users, 'userid'); if ($related_userids) { $users = API::getApiService()->select('sysmap_user', ['output' => $this->outputExtend($options['selectUsers'], ['sysmapid', 'userid']), 'filter' => ['sysmapid' => $sysmapIds, 'userid' => $related_userids], 'preservekeys' => true]); $relation_map = $this->createRelationMap($users, 'sysmapid', 'sysmapuserid'); $users = $this->unsetExtraFields($users, ['sysmapuserid', 'userid', 'permission'], $options['selectUsers']); foreach ($users as &$user) { unset($user['sysmapid']); } unset($user); $result = $relation_map->mapMany($result, $users, 'users'); } else { foreach ($result as &$row) { $row['users'] = []; } unset($row); } } // Adding user group shares. if ($options['selectUserGroups'] !== null && $options['selectUserGroups'] != API_OUTPUT_COUNT) { $relation_map = $this->createRelationMap($result, 'sysmapid', 'usrgrpid', 'sysmap_usrgrp'); // Get all allowed groups. $related_groups = API::UserGroup()->get(['output' => ['usrgrpid'], 'usrgrpids' => $relation_map->getRelatedIds(), 'preservekeys' => true]); $related_groupids = zbx_objectValues($related_groups, 'usrgrpid'); if ($related_groupids) { $user_groups = API::getApiService()->select('sysmap_usrgrp', ['output' => $this->outputExtend($options['selectUserGroups'], ['sysmapid', 'usrgrpid']), 'filter' => ['sysmapid' => $sysmapIds, 'usrgrpid' => $related_groupids], 'preservekeys' => true]); $relation_map = $this->createRelationMap($user_groups, 'sysmapid', 'sysmapusrgrpid'); $user_groups = $this->unsetExtraFields($user_groups, ['sysmapusrgrpid', 'usrgrpid', 'permission'], $options['selectUserGroups']); foreach ($user_groups as &$user_group) { unset($user_group['sysmapid']); } unset($user_group); $result = $relation_map->mapMany($result, $user_groups, 'userGroups'); } else { foreach ($result as &$row) { $row['userGroups'] = []; } unset($row); } } return $result; }
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; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $screenIds = array_keys($result); // adding ScreenItems if ($options['selectScreenItems'] !== null && $options['selectScreenItems'] != API_OUTPUT_COUNT) { $screenItems = API::getApiService()->select('screens_items', ['output' => $this->outputExtend($options['selectScreenItems'], ['screenid', 'screenitemid']), 'filter' => ['screenid' => $screenIds], 'preservekeys' => true]); $relation_map = $this->createRelationMap($screenItems, 'screenid', 'screenitemid'); $screenItems = $this->unsetExtraFields($screenItems, ['screenid', 'screenitemid'], $options['selectScreenItems']); $result = $relation_map->mapMany($result, $screenItems, 'screenitems'); } // Adding user shares. if ($options['selectUsers'] !== null && $options['selectUsers'] != API_OUTPUT_COUNT) { $relation_map = $this->createRelationMap($result, 'screenid', 'userid', 'screen_user'); // Get all allowed users. $related_users = API::User()->get(['output' => ['userid'], 'userids' => $relation_map->getRelatedIds(), 'preservekeys' => true]); $related_userids = zbx_objectValues($related_users, 'userid'); if ($related_userids) { $users = API::getApiService()->select('screen_user', ['output' => $this->outputExtend($options['selectUsers'], ['screenid', 'userid']), 'filter' => ['screenid' => $screenIds, 'userid' => $related_userids], 'preservekeys' => true]); $relation_map = $this->createRelationMap($users, 'screenid', 'screenuserid'); $users = $this->unsetExtraFields($users, ['screenuserid', 'userid', 'permission'], $options['selectUsers']); foreach ($users as &$user) { unset($user['screenid']); } unset($user); $result = $relation_map->mapMany($result, $users, 'users'); } else { foreach ($result as &$row) { $row['users'] = []; } unset($row); } } // Adding user group shares. if ($options['selectUserGroups'] !== null && $options['selectUserGroups'] != API_OUTPUT_COUNT) { $relation_map = $this->createRelationMap($result, 'screenid', 'usrgrpid', 'screen_usrgrp'); // Get all allowed groups. $related_groups = API::UserGroup()->get(['output' => ['usrgrpid'], 'usrgrpids' => $relation_map->getRelatedIds(), 'preservekeys' => true]); $related_groupids = zbx_objectValues($related_groups, 'usrgrpid'); if ($related_groupids) { $user_groups = API::getApiService()->select('screen_usrgrp', ['output' => $this->outputExtend($options['selectUserGroups'], ['screenid', 'usrgrpid']), 'filter' => ['screenid' => $screenIds, 'usrgrpid' => $related_groupids], 'preservekeys' => true]); $relation_map = $this->createRelationMap($user_groups, 'screenid', 'screenusrgrpid'); $user_groups = $this->unsetExtraFields($user_groups, ['screenusrgrpid', 'usrgrpid', 'permission'], $options['selectUserGroups']); foreach ($user_groups as &$user_group) { unset($user_group['screenid']); } unset($user_group); $result = $relation_map->mapMany($result, $user_groups, 'userGroups'); } else { foreach ($result as &$row) { $row['userGroups'] = []; } unset($row); } } return $result; }
/** * Check if user can be appended to group. * * @param string $userId * @param string $userGroupId * * @return bool */ function granted2move_user($userId, $userGroupId) { $group = API::UserGroup()->get(array('usrgrpids' => $userGroupId, 'output' => API_OUTPUT_EXTEND)); $group = reset($group); if ($group['gui_access'] == GROUP_GUI_ACCESS_DISABLED || $group['users_status'] == GROUP_STATUS_DISABLED) { return bccomp(CWebUser::$data['userid'], $userId) != 0; } return true; }
/** * Generates array with HTML items representing operation with description * * @param int $type short or long description, use const. SHORT_DESCRIPTION and LONG_DESCRIPTION * @param array $data * @param int $data['operationtype'] type of operation: OPERATION_TYPE_MESSAGE, OPERATION_TYPE_COMMAND, ... * @param int $data['opmessage']['mediatypeid'] type id of message media * @param bool $data['opmessage']['default_msg'] should default message be used * @param bool $data['opmessage']['operationid'] if true $data['operationid'] will be used to retrieve default messages from DB * @param string $data['opmessage']['subject'] subject of message * @param string $data['opmessage']['message'] message it self * @param array $data['opmessage_usr'] list of user ids if OPERATION_TYPE_MESSAGE * @param array $data['opmessage_grp'] list of group ids if OPERATION_TYPE_MESSAGE * @param array $data['opcommand_grp'] list of group ids if OPERATION_TYPE_COMMAND * @param array $data['opcommand_hst'] list of host ids if OPERATION_TYPE_COMMAND * @param array $data['opgroup'] list of group ids if OPERATION_TYPE_GROUP_ADD or OPERATION_TYPE_GROUP_REMOVE * @param array $data['optemplate'] list of template ids if OPERATION_TYPE_TEMPLATE_ADD or OPERATION_TYPE_TEMPLATE_REMOVE * @param int $data['operationid'] id of operation * @param int $data['opcommand']['type'] type of command: ZBX_SCRIPT_TYPE_IPMI, ZBX_SCRIPT_TYPE_SSH, ... * @param string $data['opcommand']['command'] actual command * @param int $data['opcommand']['scriptid'] script id used if $data['opcommand']['type'] is ZBX_SCRIPT_TYPE_GLOBAL_SCRIPT * * @return array */ function get_operation_descr($type, $data) { $result = array(); if ($type == SHORT_DESCRIPTION) { switch ($data['operationtype']) { case OPERATION_TYPE_MESSAGE: $mediaTypes = API::Mediatype()->get(array('mediatypeids' => $data['opmessage']['mediatypeid'], 'output' => array('description'))); if (empty($mediaTypes)) { $mediatype = _('all media'); } else { $mediatype = reset($mediaTypes); $mediatype = $mediatype['description']; } if (!empty($data['opmessage_usr'])) { $users = API::User()->get(array('userids' => zbx_objectValues($data['opmessage_usr'], 'userid'), 'output' => array('userid', 'alias', 'name', 'surname'))); order_result($users, 'alias'); foreach ($users as $user) { $fullnames[] = getUserFullname($user); } $result[] = bold(_('Send message to users') . NAME_DELIMITER); $result[] = array(implode(', ', $fullnames), SPACE, _('via'), SPACE, $mediatype); $result[] = BR(); } if (!empty($data['opmessage_grp'])) { $usrgrps = API::UserGroup()->get(array('usrgrpids' => zbx_objectValues($data['opmessage_grp'], 'usrgrpid'), 'output' => API_OUTPUT_EXTEND)); order_result($usrgrps, 'name'); $result[] = bold(_('Send message to user groups') . NAME_DELIMITER); $result[] = array(implode(', ', zbx_objectValues($usrgrps, 'name')), SPACE, _('via'), SPACE, $mediatype); $result[] = BR(); } break; case OPERATION_TYPE_COMMAND: if (!isset($data['opcommand_grp'])) { $data['opcommand_grp'] = array(); } if (!isset($data['opcommand_hst'])) { $data['opcommand_hst'] = array(); } $hosts = API::Host()->get(array('hostids' => zbx_objectValues($data['opcommand_hst'], 'hostid'), 'output' => array('hostid', 'name'))); foreach ($data['opcommand_hst'] as $cmd) { if ($cmd['hostid'] != 0) { continue; } $result[] = array(bold(_('Run remote commands on current host')), BR()); break; } if (!empty($hosts)) { order_result($hosts, 'name'); $result[] = bold(_('Run remote commands on hosts') . NAME_DELIMITER); $result[] = array(implode(', ', zbx_objectValues($hosts, 'name')), BR()); } $groups = API::HostGroup()->get(array('groupids' => zbx_objectValues($data['opcommand_grp'], 'groupid'), 'output' => array('groupid', 'name'))); if (!empty($groups)) { order_result($groups, 'name'); $result[] = bold(_('Run remote commands on host groups') . NAME_DELIMITER); $result[] = array(implode(', ', zbx_objectValues($groups, 'name')), BR()); } break; case OPERATION_TYPE_HOST_ADD: $result[] = array(bold(_('Add host')), BR()); break; case OPERATION_TYPE_HOST_REMOVE: $result[] = array(bold(_('Remove host')), BR()); break; case OPERATION_TYPE_HOST_ENABLE: $result[] = array(bold(_('Enable host')), BR()); break; case OPERATION_TYPE_HOST_DISABLE: $result[] = array(bold(_('Disable host')), BR()); break; case OPERATION_TYPE_GROUP_ADD: case OPERATION_TYPE_GROUP_REMOVE: if (!isset($data['opgroup'])) { $data['opgroup'] = array(); } $groups = API::HostGroup()->get(array('groupids' => zbx_objectValues($data['opgroup'], 'groupid'), 'output' => array('groupid', 'name'))); if (!empty($groups)) { order_result($groups, 'name'); if (OPERATION_TYPE_GROUP_ADD == $data['operationtype']) { $result[] = bold(_('Add to host groups') . NAME_DELIMITER); } else { $result[] = bold(_('Remove from host groups') . NAME_DELIMITER); } $result[] = array(implode(', ', zbx_objectValues($groups, 'name')), BR()); } break; case OPERATION_TYPE_TEMPLATE_ADD: case OPERATION_TYPE_TEMPLATE_REMOVE: if (!isset($data['optemplate'])) { $data['optemplate'] = array(); } $templates = API::Template()->get(array('templateids' => zbx_objectValues($data['optemplate'], 'templateid'), 'output' => array('hostid', 'name'))); if (!empty($templates)) { order_result($templates, 'name'); if (OPERATION_TYPE_TEMPLATE_ADD == $data['operationtype']) { $result[] = bold(_('Link to templates') . NAME_DELIMITER); } else { $result[] = bold(_('Unlink from templates') . NAME_DELIMITER); } $result[] = array(implode(', ', zbx_objectValues($templates, 'name')), BR()); } break; default: } } else { switch ($data['operationtype']) { case OPERATION_TYPE_MESSAGE: if (isset($data['opmessage']['default_msg']) && !empty($data['opmessage']['default_msg'])) { if (isset($_REQUEST['def_shortdata']) && isset($_REQUEST['def_longdata'])) { $result[] = array(bold(_('Subject') . NAME_DELIMITER), BR(), zbx_nl2br($_REQUEST['def_shortdata'])); $result[] = array(bold(_('Message') . NAME_DELIMITER), BR(), zbx_nl2br($_REQUEST['def_longdata'])); } elseif (isset($data['opmessage']['operationid'])) { $sql = 'SELECT a.def_shortdata,a.def_longdata ' . ' FROM actions a,operations o ' . ' WHERE a.actionid=o.actionid ' . ' AND o.operationid=' . zbx_dbstr($data['operationid']); if ($rows = DBfetch(DBselect($sql, 1))) { $result[] = array(bold(_('Subject') . NAME_DELIMITER), BR(), zbx_nl2br($rows['def_shortdata'])); $result[] = array(bold(_('Message') . NAME_DELIMITER), BR(), zbx_nl2br($rows['def_longdata'])); } } } else { $result[] = array(bold(_('Subject') . NAME_DELIMITER), BR(), zbx_nl2br($data['opmessage']['subject'])); $result[] = array(bold(_('Message') . NAME_DELIMITER), BR(), zbx_nl2br($data['opmessage']['message'])); } break; case OPERATION_TYPE_COMMAND: switch ($data['opcommand']['type']) { case ZBX_SCRIPT_TYPE_IPMI: $result[] = array(bold(_('Run IPMI command') . NAME_DELIMITER), BR(), italic(zbx_nl2br($data['opcommand']['command']))); break; case ZBX_SCRIPT_TYPE_SSH: $result[] = array(bold(_('Run SSH commands') . NAME_DELIMITER), BR(), italic(zbx_nl2br($data['opcommand']['command']))); break; case ZBX_SCRIPT_TYPE_TELNET: $result[] = array(bold(_('Run TELNET commands') . NAME_DELIMITER), BR(), italic(zbx_nl2br($data['opcommand']['command']))); break; case ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT: if ($data['opcommand']['execute_on'] == ZBX_SCRIPT_EXECUTE_ON_AGENT) { $result[] = array(bold(_('Run custom commands on Zabbix agent') . NAME_DELIMITER), BR(), italic(zbx_nl2br($data['opcommand']['command']))); } else { $result[] = array(bold(_('Run custom commands on Zabbix server') . NAME_DELIMITER), BR(), italic(zbx_nl2br($data['opcommand']['command']))); } break; case ZBX_SCRIPT_TYPE_GLOBAL_SCRIPT: $userScripts = API::Script()->get(array('scriptids' => $data['opcommand']['scriptid'], 'output' => API_OUTPUT_EXTEND)); $userScript = reset($userScripts); $result[] = array(bold(_('Run global script') . NAME_DELIMITER), italic($userScript['name'])); break; default: $result[] = array(bold(_('Run commands') . NAME_DELIMITER), BR(), italic(zbx_nl2br($data['opcommand']['command']))); } break; default: } } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $userIds = zbx_objectValues($result, 'userid'); // adding usergroups if ($options['selectUsrgrps'] !== null && $options['selectUsrgrps'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'userid', 'usrgrpid', 'users_groups'); $dbUserGroups = API::UserGroup()->get(array('output' => $options['selectUsrgrps'], 'usrgrpids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); $result = $relationMap->mapMany($result, $dbUserGroups, 'usrgrps'); } // adding medias if ($options['selectMedias'] !== null && $options['selectMedias'] != API_OUTPUT_COUNT) { $userMedias = API::UserMedia()->get(array('output' => $this->outputExtend('media', array('userid', 'mediaid'), $options['selectMedias']), 'userids' => $userIds, 'preservekeys' => true)); $relationMap = $this->createRelationMap($userMedias, 'userid', 'mediaid'); $userMedias = $this->unsetExtraFields($userMedias, array('userid', 'mediaid'), $options['selectMedias']); $result = $relationMap->mapMany($result, $userMedias, 'medias'); } // adding media types if ($options['selectMediatypes'] !== null && $options['selectMediatypes'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'userid', 'mediatypeid', 'media'); $mediaTypes = API::Mediatype()->get(array('output' => $options['selectMediatypes'], 'mediatypeids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); $result = $relationMap->mapMany($result, $mediaTypes, 'mediatypes'); } return $result; }
// render view $scriptView->render(); $scriptView->show(); } else { $sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'name')); $sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP)); CProfile::update('web.' . $page['file'] . '.sort', $sortField, PROFILE_TYPE_STR); CProfile::update('web.' . $page['file'] . '.sortorder', $sortOrder, PROFILE_TYPE_STR); $data = array('sort' => $sortField, 'sortorder' => $sortOrder); // list of scripts $data['scripts'] = API::Script()->get(array('output' => array('scriptid', 'name', 'command', 'host_access', 'usrgrpid', 'groupid', 'type', 'execute_on'), 'editable' => true, 'selectGroups' => API_OUTPUT_EXTEND)); // find script host group name and user group name. set to '' if all host/user groups used. foreach ($data['scripts'] as $key => $script) { $scriptId = $script['scriptid']; if ($script['usrgrpid'] > 0) { $userGroup = API::UserGroup()->get(array('usrgrpids' => $script['usrgrpid'], 'output' => API_OUTPUT_EXTEND)); $userGroup = reset($userGroup); $data['scripts'][$key]['userGroupName'] = $userGroup['name']; } else { $data['scripts'][$key]['userGroupName'] = ''; // all user groups } if ($script['groupid'] > 0) { $group = array_pop($script['groups']); $data['scripts'][$key]['hostGroupName'] = $group['name']; } else { $data['scripts'][$key]['hostGroupName'] = ''; // all host groups } } // sorting & paging
insert_js_function('addValues'); insert_js_function('addValue'); /* * User group */ if ($srctbl == 'usrgrp') { $form = new CForm(); $form->setName('usrgrpform'); $form->setAttribute('id', 'usrgrps'); $table = new CTableInfo(_('No user groups found.')); $table->setHeader(array($multiselect ? new CCheckBox('all_usrgrps', null, "javascript: checkAll('" . $form->getName() . "', 'all_usrgrps', 'usrgrps');") : null, _('Name'))); $options = array('nodeids' => $nodeId, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true); if (!is_null($writeonly)) { $options['editable'] = true; } $userGroups = API::UserGroup()->get($options); order_result($userGroups, 'name'); foreach ($userGroups as $userGroup) { $name = new CSpan($userGroup['name'], 'link'); $name->attr('id', 'spanid' . $userGroup['usrgrpid']); if ($multiselect) { $js_action = "javascript: addValue(" . zbx_jsvalue($reference) . ', ' . zbx_jsvalue($userGroup['usrgrpid']) . ');'; } else { $values = array($dstfld1 => $userGroup[$srcfld1], $dstfld2 => $userGroup[$srcfld2]); $js_action = 'javascript: addValues(' . zbx_jsvalue($dstfrm) . ', ' . zbx_jsvalue($values) . '); close_window(); return false;'; } $name->setAttribute('onclick', $js_action . ' jQuery(this).removeAttr("onclick");'); $table->addRow(array($multiselect ? new CCheckBox('usrgrps[' . $userGroup['usrgrpid'] . ']', null, null, $userGroup['usrgrpid']) : null, $name)); } if ($multiselect) { $button = new CButton('select', _('Select'), "javascript: addSelectedValues('usrgrps', " . zbx_jsvalue($reference) . ');');
$usrgrpList->attr('style', 'min-width: 310px;'); $usrgrpList->setAttribute('id', 'opmsgUsrgrpList'); $addUsrgrpBtn = new CButton('add', _('Add'), 'return PopUp("popup.php?dstfrm=action.edit&srctbl=usrgrp&srcfld1=usrgrpid&srcfld2=name&multiselect=1", 450, 450)', 'link_menu'); $addUsrgrpBtn->attr('id', 'addusrgrpbtn'); $usrgrpList->addRow(new CRow(new CCol($addUsrgrpBtn, null, 2), null, 'opmsgUsrgrpListFooter')); $userList = new CTable(null, 'formElementTable'); $userList->setHeader(array(_('User'), _('Action'))); $userList->attr('style', 'min-width: 310px;'); $userList->setAttribute('id', 'opmsgUserList'); $addUserBtn = new CButton('add', _('Add'), 'return PopUp("popup.php?dstfrm=action.edit&srctbl=users&srcfld1=userid&srcfld2=fullname&multiselect=1", 450, 450)', 'link_menu'); $addUserBtn->attr('id', 'adduserbtn'); $userList->addRow(new CRow(new CCol($addUserBtn, null, 2), null, 'opmsgUserListFooter')); // add participations $usrgrpids = isset($this->data['new_operation']['opmessage_grp']) ? zbx_objectValues($this->data['new_operation']['opmessage_grp'], 'usrgrpid') : array(); $userids = isset($this->data['new_operation']['opmessage_usr']) ? zbx_objectValues($this->data['new_operation']['opmessage_usr'], 'userid') : array(); $usrgrps = API::UserGroup()->get(array('usrgrpids' => $usrgrpids, 'output' => array('name'))); order_result($usrgrps, 'name'); $users = API::User()->get(array('userids' => $userids, 'output' => array('alias', 'name', 'surname'))); order_result($users, 'alias'); foreach ($users as &$user) { $user['fullname'] = getUserFullname($user); } unset($user); $jsInsert = 'addPopupValues(' . zbx_jsvalue(array('object' => 'usrgrpid', 'values' => $usrgrps)) . ');'; $jsInsert .= 'addPopupValues(' . zbx_jsvalue(array('object' => 'userid', 'values' => $users)) . ');'; zbx_add_post_js($jsInsert); $newOperationsTable->addRow(array(_('Send to User groups'), new CDiv($usrgrpList, 'objectgroup inlineblock border_dotted ui-corner-all'))); $newOperationsTable->addRow(array(_('Send to Users'), new CDiv($userList, 'objectgroup inlineblock border_dotted ui-corner-all'))); $mediaTypeComboBox = new CComboBox('new_operation[opmessage][mediatypeid]', $this->data['new_operation']['opmessage']['mediatypeid']); $mediaTypeComboBox->addItem(0, '- ' . _('All') . ' -'); $dbMediaTypes = DBfetchArray(DBselect('SELECT mt.mediatypeid,mt.description' . ' FROM media_type mt' . whereDbNode('mt.mediatypeid')));
/** * Gathers media types, user groups, users, host groups, hosts and templates for actions and their operations, and * returns the HTML representation of action operation values according to action operation type. * * @param array $actions array of actions * @param array $action['operations'] array of action operations * * @return array returns an array of actions operation descriptions */ function getActionOperationDescriptions(array $actions) { $result = []; $mediaTypeIds = []; $userIds = []; $usrGrpIds = []; $hostIds = []; $groupids = []; $templateids = []; foreach ($actions as $i => $action) { $result[$i] = []; foreach ($action['operations'] as $j => $operation) { $result[$i][$j] = []; switch ($operation['operationtype']) { case OPERATION_TYPE_MESSAGE: $mediaTypeId = $operation['opmessage']['mediatypeid']; if ($mediaTypeId != 0) { $mediaTypeIds[$mediaTypeId] = $mediaTypeId; } if (isset($operation['opmessage_usr']) && $operation['opmessage_usr']) { foreach ($operation['opmessage_usr'] as $users) { $userIds[$users['userid']] = $users['userid']; } } if (isset($operation['opmessage_grp']) && $operation['opmessage_grp']) { foreach ($operation['opmessage_grp'] as $userGroups) { $usrGrpIds[$userGroups['usrgrpid']] = $userGroups['usrgrpid']; } } break; case OPERATION_TYPE_COMMAND: if (isset($operation['opcommand_hst']) && $operation['opcommand_hst']) { foreach ($operation['opcommand_hst'] as $host) { if ($host['hostid'] != 0) { $hostIds[$host['hostid']] = $host['hostid']; } } } if (isset($operation['opcommand_grp']) && $operation['opcommand_grp']) { foreach ($operation['opcommand_grp'] as $hostGroup) { $groupids[$hostGroup['groupid']] = true; } } break; case OPERATION_TYPE_GROUP_ADD: case OPERATION_TYPE_GROUP_REMOVE: foreach ($operation['groupids'] as $groupid) { $groupids[$groupid] = true; } break; case OPERATION_TYPE_TEMPLATE_ADD: case OPERATION_TYPE_TEMPLATE_REMOVE: foreach ($operation['templateids'] as $templateid) { $templateids[$templateid] = true; } break; } } } $mediaTypes = []; $users = []; $userGroups = []; $hosts = []; $hostGroups = []; $templates = []; if ($mediaTypeIds) { $mediaTypes = API::Mediatype()->get(['output' => ['description'], 'mediatypeids' => $mediaTypeIds, 'preservekeys' => true]); } if ($userIds) { $fullnames = []; $users = API::User()->get(['output' => ['userid', 'alias', 'name', 'surname'], 'userids' => $userIds]); foreach ($users as $user) { $fullnames[$user['userid']] = getUserFullname($user); } } if ($usrGrpIds) { $userGroups = API::UserGroup()->get(['output' => ['name'], 'usrgrpids' => $usrGrpIds, 'preservekeys' => true]); } if ($hostIds) { $hosts = API::Host()->get(['output' => ['name'], 'hostids' => $hostIds, 'preservekeys' => true]); } if ($groupids) { $hostGroups = API::HostGroup()->get(['output' => ['name'], 'groupids' => array_keys($groupids), 'preservekeys' => true]); } if ($templateids) { $templates = API::Template()->get(['output' => ['name'], 'templateids' => array_keys($templateids), 'preservekeys' => true]); } // format the HTML ouput foreach ($actions as $i => $action) { foreach ($action['operations'] as $j => $operation) { switch ($operation['operationtype']) { case OPERATION_TYPE_MESSAGE: $mediaType = _('all media'); $mediaTypeId = $operation['opmessage']['mediatypeid']; if ($mediaTypeId != 0 && isset($mediaTypes[$mediaTypeId])) { $mediaType = $mediaTypes[$mediaTypeId]['description']; } if (isset($operation['opmessage_usr']) && $operation['opmessage_usr']) { $userNamesList = []; foreach ($operation['opmessage_usr'] as $user) { if (isset($fullnames[$user['userid']])) { $userNamesList[] = $fullnames[$user['userid']]; } } order_result($userNamesList); $result[$i][$j][] = bold(_('Send message to users') . ': '); $result[$i][$j][] = [implode(', ', $userNamesList), SPACE, _('via'), SPACE, $mediaType]; $result[$i][$j][] = BR(); } if (isset($operation['opmessage_grp']) && $operation['opmessage_grp']) { $userGroupsList = []; foreach ($operation['opmessage_grp'] as $userGroup) { if (isset($userGroups[$userGroup['usrgrpid']])) { $userGroupsList[] = $userGroups[$userGroup['usrgrpid']]['name']; } } order_result($userGroupsList); $result[$i][$j][] = bold(_('Send message to user groups') . ': '); $result[$i][$j][] = [implode(', ', $userGroupsList), SPACE, _('via'), SPACE, $mediaType]; $result[$i][$j][] = BR(); } break; case OPERATION_TYPE_COMMAND: if (isset($operation['opcommand_hst']) && $operation['opcommand_hst']) { $hostList = []; foreach ($operation['opcommand_hst'] as $host) { if ($host['hostid'] == 0) { $result[$i][$j][] = [bold(_('Run remote commands on current host')), BR()]; } elseif (isset($hosts[$host['hostid']])) { $hostList[] = $hosts[$host['hostid']]['name']; } } if ($hostList) { order_result($hostList); $result[$i][$j][] = bold(_('Run remote commands on hosts') . ': '); $result[$i][$j][] = [implode(', ', $hostList), BR()]; } } if (isset($operation['opcommand_grp']) && $operation['opcommand_grp']) { $hostGroupList = []; foreach ($operation['opcommand_grp'] as $hostGroup) { if (isset($hostGroups[$hostGroup['groupid']])) { $hostGroupList[] = $hostGroups[$hostGroup['groupid']]['name']; } } order_result($hostGroupList); $result[$i][$j][] = bold(_('Run remote commands on host groups') . ': '); $result[$i][$j][] = [implode(', ', $hostGroupList), BR()]; } break; case OPERATION_TYPE_HOST_ADD: $result[$i][$j][] = [bold(_('Add host')), BR()]; break; case OPERATION_TYPE_HOST_REMOVE: $result[$i][$j][] = [bold(_('Remove host')), BR()]; break; case OPERATION_TYPE_HOST_ENABLE: $result[$i][$j][] = [bold(_('Enable host')), BR()]; break; case OPERATION_TYPE_HOST_DISABLE: $result[$i][$j][] = [bold(_('Disable host')), BR()]; break; case OPERATION_TYPE_GROUP_ADD: case OPERATION_TYPE_GROUP_REMOVE: $hostGroupList = []; foreach ($operation['groupids'] as $groupid) { if (array_key_exists($groupid, $hostGroups)) { $hostGroupList[] = $hostGroups[$groupid]['name']; } } order_result($hostGroupList); if ($operation['operationtype'] == OPERATION_TYPE_GROUP_ADD) { $result[$i][$j][] = bold(_('Add to host groups') . ': '); } else { $result[$i][$j][] = bold(_('Remove from host groups') . ': '); } $result[$i][$j][] = [implode(', ', $hostGroupList), BR()]; break; case OPERATION_TYPE_TEMPLATE_ADD: case OPERATION_TYPE_TEMPLATE_REMOVE: $templateList = []; foreach ($operation['templateids'] as $templateid) { if (array_key_exists($templateid, $templates)) { $templateList[] = $templates[$templateid]['name']; } } order_result($templateList); if ($operation['operationtype'] == OPERATION_TYPE_TEMPLATE_ADD) { $result[$i][$j][] = bold(_('Link to templates') . ': '); } else { $result[$i][$j][] = bold(_('Unlink from templates') . ': '); } $result[$i][$j][] = [implode(', ', $templateList), BR()]; break; case OPERATION_TYPE_HOST_INVENTORY: $host_inventory_modes = getHostInventoryModes(); $result[$i][$j][] = bold(operation_type2str(OPERATION_TYPE_HOST_INVENTORY) . ': '); $result[$i][$j][] = [$host_inventory_modes[$operation['opinventory']['inventory_mode']], BR()]; break; } } } return $result; }