本文整理汇总了PHP中API::UserGroup方法的典型用法代码示例。如果您正苦于以下问题:PHP API::UserGroup方法的具体用法?PHP API::UserGroup怎么用?PHP API::UserGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::UserGroup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doAction
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);
}
示例2: doAction
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);
}
示例3: getRequest
$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;
}
示例4: whereDbNode
$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();
}
示例5: foreach
}
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]);
示例6: validateOperations
//.........这里部分代码省略.........
}
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;
}
示例7: CTable
$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');
示例8: getUserFormData
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
//.........这里部分代码省略.........
示例9: getRequest
$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;
}
示例10: get_request
$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';
示例11: addRelatedObjects
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;
}
示例12: addRelatedObjects
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'] = [];
//.........这里部分代码省略.........
示例13: update_slideshow
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);
//.........这里部分代码省略.........
示例14: addRelatedObjects
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;
}
示例15: granted2move_user
/**
* 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;
}