本文整理汇总了PHP中group_user_attributes函数的典型用法代码示例。如果您正苦于以下问题:PHP group_user_attributes函数的具体用法?PHP group_user_attributes怎么用?PHP group_user_attributes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了group_user_attributes函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_notifications
public function test_notifications()
{
global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_log;
include_once $phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx;
include_once $phpbb_root_path . 'includes/functions_user.' . $phpEx;
include_once $phpbb_root_path . 'includes/functions_content.' . $phpEx;
set_config(false, false, false, $this->config);
$this->container->set('groupposition.legend', new \phpbb\groupposition\legend($this->db, $this->user));
$this->container->set('groupposition.teampage', new \phpbb\groupposition\teampage($this->db, $this->user, $this->cache->get_driver()));
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$phpbb_log = new \phpbb\log\null();
// Now on to the actual test
$group_id = false;
group_create($group_id, GROUP_OPEN, 'test', 'test group', array());
// Add user 2 as group leader
group_user_add($group_id, 2, false, false, false, true, false);
// Add user 3 as pending
group_user_add($group_id, 3, false, false, false, false, true);
$this->assert_notifications(array(array('item_id' => 3, 'item_parent_id' => $group_id, 'user_id' => 2, 'notification_read' => 0, 'notification_data' => array('group_name' => 'test'))), array('user_id' => 2));
// Approve user 3 joining the group
group_user_attributes('approve', $group_id, array(3));
// user 3 pending notification should have been deleted
$this->assert_notifications(array(), array('user_id' => 2));
$this->assert_notifications(array(array('item_id' => $group_id, 'user_id' => 3, 'notification_read' => 0, 'notification_data' => array('group_name' => 'test'))), array('user_id' => 3));
}
示例2: test_group_user_attributes
/**
* @dataProvider group_user_attributes_data
*/
public function test_group_user_attributes($description, $user_id, $group_id, $group_row, $expected)
{
global $auth, $cache, $db, $phpbb_dispatcher, $user, $phpbb_container, $phpbb_log, $phpbb_root_path, $phpEx;
$user = new phpbb_mock_user();
$user->ip = '';
$cache = new phpbb_mock_cache();
$db = $this->new_dbal();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$auth = $this->getMock('\\phpbb\\auth\\auth');
$auth->expects($this->any())->method('acl_clear_prefetch');
$cache_driver = new \phpbb\cache\driver\dummy();
$phpbb_container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$phpbb_container->expects($this->any())->method('get')->with('cache.driver')->will($this->returnValue($cache_driver));
$phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
group_user_attributes('default', $group_id, array($user_id), false, 'group_name', $group_row);
$sql = 'SELECT user_avatar, user_rank
FROM ' . USERS_TABLE . '
WHERE user_id = ' . $user_id;
$result = $db->sql_query($sql);
$this->assertEquals(array($expected), $db->sql_fetchrowset($result));
$db->sql_freeresult($result);
}
示例3: main
//.........这里部分代码省略.........
$s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
}
if (!isset($sk_sql[$sort_key])) {
$sort_key = 'a';
}
$order_by = $sk_sql[$sort_key] . ' ' . ($sort_dir == 'a' ? 'ASC' : 'DESC');
$sql = 'SELECT COUNT(attach_id) as num_attachments
FROM ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\tWHERE poster_id = {$user_id}\n\t\t\t\t\t\tAND is_orphan = 0";
$result = $db->sql_query_limit($sql, 1);
$num_attachments = (int) $db->sql_fetchfield('num_attachments');
$db->sql_freeresult($result);
$sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
FROM ' . ATTACHMENTS_TABLE . ' a
LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id
AND a.in_message = 0)
LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id
AND a.in_message = 1)
WHERE a.poster_id = ' . $user_id . "\n\t\t\t\t\t\tAND a.is_orphan = 0\n\t\t\t\t\tORDER BY {$order_by}";
$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
while ($row = $db->sql_fetchrow($result)) {
if ($row['in_message']) {
$view_topic = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&p={$row['post_msg_id']}");
} else {
$view_topic = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row['topic_id']}&p={$row['post_msg_id']}") . '#p' . $row['post_msg_id'];
}
$template->assign_block_vars('attach', array('REAL_FILENAME' => $row['real_filename'], 'COMMENT' => nl2br($row['attach_comment']), 'EXTENSION' => $row['extension'], 'SIZE' => get_formatted_filesize($row['filesize']), 'DOWNLOAD_COUNT' => $row['download_count'], 'POST_TIME' => $user->format_date($row['filetime']), 'TOPIC_TITLE' => $row['in_message'] ? $row['message_title'] : $row['topic_title'], 'ATTACH_ID' => $row['attach_id'], 'POST_ID' => $row['post_msg_id'], 'TOPIC_ID' => $row['topic_id'], 'S_IN_MESSAGE' => $row['in_message'], 'U_DOWNLOAD' => append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'mode=view&id=' . $row['attach_id']), 'U_VIEW_TOPIC' => $view_topic));
}
$db->sql_freeresult($result);
$base_url = $this->u_action . "&u={$user_id}&sk={$sort_key}&sd={$sort_dir}";
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start);
$template->assign_vars(array('S_ATTACHMENTS' => true, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir));
break;
case 'groups':
if (!function_exists('group_user_attributes')) {
include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
}
$user->add_lang(array('groups', 'acp/groups'));
$group_id = $request->variable('g', 0);
if ($group_id) {
// Check the founder only entry for this group to make sure everything is well
$sql = 'SELECT group_founder_manage
FROM ' . GROUPS_TABLE . '
WHERE group_id = ' . $group_id;
$result = $db->sql_query($sql);
$founder_manage = (int) $db->sql_fetchfield('group_founder_manage');
$db->sql_freeresult($result);
if ($user->data['user_type'] != USER_FOUNDER && $founder_manage) {
trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
}
}
switch ($action) {
case 'demote':
case 'promote':
case 'default':
if (!$group_id) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
}
group_user_attributes($action, $group_id, $user_id);
if ($action == 'default') {
$user_row['group_id'] = $group_id;
}
break;
case 'delete':
if (confirm_box(true)) {
if (!$group_id) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
示例4: main
function main($id, $mode)
{
global $config, $db, $user, $auth, $template, $cache;
global $phpbb_root_path, $phpbb_admin_path, $phpEx;
global $request, $phpbb_container, $phpbb_dispatcher;
$user->add_lang('acp/groups');
$this->tpl_name = 'acp_groups';
$this->page_title = 'ACP_GROUPS_MANAGE';
$form_key = 'acp_groups';
add_form_key($form_key);
if ($mode == 'position') {
$this->manage_position();
return;
}
if (!function_exists('group_user_attributes')) {
include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
}
// Check and set some common vars
$action = isset($_POST['add']) ? 'add' : (isset($_POST['addusers']) ? 'addusers' : $request->variable('action', ''));
$group_id = $request->variable('g', 0);
$mark_ary = $request->variable('mark', array(0));
$name_ary = $request->variable('usernames', '', true);
$leader = $request->variable('leader', 0);
$default = $request->variable('default', 0);
$start = $request->variable('start', 0);
$update = isset($_POST['update']) ? true : false;
/** @var \phpbb\group\helper $group_helper */
$group_helper = $phpbb_container->get('group_helper');
// Clear some vars
$group_row = array();
// Grab basic data for group, if group_id is set and exists
if ($group_id) {
$sql = 'SELECT g.*, t.teampage_position AS group_teampage
FROM ' . GROUPS_TABLE . ' g
LEFT JOIN ' . TEAMPAGE_TABLE . ' t
ON (t.group_id = g.group_id)
WHERE g.group_id = ' . $group_id;
$result = $db->sql_query($sql);
$group_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$group_row) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
}
// Check if the user is allowed to manage this group if set to founder only.
if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage']) {
trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
}
}
// Which page?
switch ($action) {
case 'approve':
case 'demote':
case 'promote':
if (!check_form_key($form_key)) {
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
if (!$group_id) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
}
// Approve, demote or promote
$group_name = $group_helper->get_name($group_row['group_name']);
$error = group_user_attributes($action, $group_id, $mark_ary, false, $group_name);
if (!$error) {
switch ($action) {
case 'demote':
$message = 'GROUP_MODS_DEMOTED';
break;
case 'promote':
$message = 'GROUP_MODS_PROMOTED';
break;
case 'approve':
$message = 'USERS_APPROVED';
break;
}
trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id));
} else {
trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING);
}
break;
case 'default':
if (!$group_id) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
} else {
if (empty($mark_ary)) {
trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING);
}
}
if (confirm_box(true)) {
$group_name = $group_helper->get_name($group_row['group_name']);
group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id));
} else {
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action)));
}
break;
case 'set_default_on_all':
if (confirm_box(true)) {
$group_name = $group_helper->get_name($group_row['group_name']);
$start = 0;
do {
//.........这里部分代码省略.........
示例5: main
//.........这里部分代码省略.........
}
$order_by = $sk_sql[$sort_key] . ' ' . ($sort_dir == 'a' ? 'ASC' : 'DESC');
$sql = 'SELECT COUNT(attach_id) as num_attachments
FROM ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\tWHERE poster_id = {$user_id}";
$result = $db->sql_query_limit($sql, 1);
$num_attachments = (int) $db->sql_fetchfield('num_attachments');
$db->sql_freeresult($result);
$sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
FROM ' . ATTACHMENTS_TABLE . ' a
LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id
AND a.in_message = 0)
LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id
AND a.in_message = 1)
WHERE a.poster_id = ' . $user_id . "\n\t\t\t\t\tORDER BY {$order_by}";
$result = $db->sql_query_limit($sql, $config['posts_per_page'], $start);
while ($row = $db->sql_fetchrow($result)) {
if ($row['in_message']) {
$view_topic = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&p={$row['post_msg_id']}");
} else {
$view_topic = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row['topic_id']}&p={$row['post_msg_id']}#{$row['post_msg_id']}");
}
$template->assign_block_vars('attach', array('REAL_FILENAME' => $row['real_filename'], 'COMMENT' => nl2br($row['comment']), 'EXTENSION' => $row['extension'], 'SIZE' => $row['filesize'] >= 1048576 ? ($row['filesize'] >> 20) . ' ' . $user->lang['MB'] : ($row['filesize'] >= 1024 ? ($row['filesize'] >> 10) . ' ' . $user->lang['KB'] : $row['filesize'] . ' ' . $user->lang['BYTES']), 'DOWNLOAD_COUNT' => $row['download_count'], 'POST_TIME' => $user->format_date($row['filetime']), 'TOPIC_TITLE' => $row['in_message'] ? $row['message_title'] : $row['topic_title'], 'ATTACH_ID' => $row['attach_id'], 'POST_ID' => $row['post_msg_id'], 'TOPIC_ID' => $row['topic_id'], 'S_IN_MESSAGE' => $row['in_message'], 'U_DOWNLOAD' => append_sid("{$phpbb_root_path}download.{$phpEx}", 'id=' . $row['attach_id']), 'U_VIEW_TOPIC' => $view_topic));
}
$db->sql_freeresult($result);
$template->assign_vars(array('S_ATTACHMENTS' => true, 'S_ON_PAGE' => on_page($num_attachments, $config['topics_per_page'], $start), 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'PAGINATION' => generate_pagination($this->u_action . "&sk={$sort_key}&sd={$sort_dir}", $num_attachments, $config['topics_per_page'], $start, true)));
break;
case 'groups':
$user->add_lang(array('groups', 'acp/groups'));
$group_id = request_var('g', 0);
switch ($action) {
case 'demote':
case 'promote':
case 'default':
group_user_attributes($action, $group_id, $user_id);
if ($action == 'default') {
$user_row['group_id'] = $group_id;
}
break;
case 'delete':
if (confirm_box(true)) {
if (!$group_id) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id));
}
if ($error = group_user_del($group_id, $user_id)) {
trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&u=' . $user_id));
}
$error = array();
} else {
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'g' => $group_id)));
}
break;
}
// Add user to group?
if ($submit) {
if (!$group_id) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id));
}
// Add user/s to group
if ($error = group_user_add($group_id, $user_id)) {
trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&u=' . $user_id));
}
$error = array();
}
$sql = 'SELECT ug.*, g.*
FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.user_id = {$user_id}\n\t\t\t\t\t\tAND g.group_id = ug.group_id\n\t\t\t\t\tORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name";
$result = $db->sql_query($sql);
示例6: main
function main($id, $mode)
{
global $config, $phpbb_root_path, $phpEx;
global $db, $user, $auth, $cache, $template;
$user->add_lang('groups');
$return_page = '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '">', '</a>');
$mark_ary = request_var('mark', array(0));
$submit = !empty($_POST['submit']) ? true : false;
$delete = !empty($_POST['delete']) ? true : false;
$error = $data = array();
switch ($mode) {
case 'membership':
$this->page_title = 'UCP_USERGROUPS_MEMBER';
if ($submit || isset($_POST['change_default'])) {
$action = isset($_POST['change_default']) ? 'change_default' : request_var('action', '');
$group_id = $action == 'change_default' ? request_var('default', 0) : request_var('selected', 0);
if (!$group_id) {
trigger_error('NO_GROUP_SELECTED');
}
$sql = 'SELECT group_id, group_name, group_type
FROM ' . GROUPS_TABLE . "\n\t\t\t\t\t\tWHERE group_id IN ({$group_id}, {$user->data['group_id']})";
$result = $db->sql_query($sql);
$group_row = array();
while ($row = $db->sql_fetchrow($result)) {
$row['group_name'] = $row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
$group_row[$row['group_id']] = $row;
}
$db->sql_freeresult($result);
if (!sizeof($group_row)) {
trigger_error('GROUP_NOT_EXIST');
}
switch ($action) {
case 'change_default':
// User already having this group set as default?
if ($group_id == $user->data['group_id']) {
trigger_error($user->lang['ALREADY_DEFAULT_GROUP'] . $return_page);
}
if (!$auth->acl_get('u_chggrp')) {
trigger_error($user->lang['NOT_AUTHORISED'] . $return_page);
}
// User needs to be member of the group in order to make it default
if (!group_memberships($group_id, $user->data['user_id'], true)) {
trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
}
if (confirm_box(true)) {
group_user_attributes('default', $group_id, $user->data['user_id']);
add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_CHANGE', sprintf($user->lang['USER_GROUP_CHANGE'], $group_row[$user->data['group_id']]['group_name'], $group_row[$group_id]['group_name']));
meta_refresh(3, $this->u_action);
trigger_error($user->lang['CHANGED_DEFAULT_GROUP'] . $return_page);
} else {
$s_hidden_fields = array('default' => $group_id, 'change_default' => true);
confirm_box(false, sprintf($user->lang['GROUP_CHANGE_DEFAULT'], $group_row[$group_id]['group_name']), build_hidden_fields($s_hidden_fields));
}
break;
case 'resign':
// User tries to resign from default group but is not allowed to change it?
if ($group_id == $user->data['group_id'] && !$auth->acl_get('u_chggrp')) {
trigger_error($user->lang['NOT_RESIGN_FROM_DEFAULT_GROUP'] . $return_page);
}
if (!($row = group_memberships($group_id, $user->data['user_id']))) {
trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
}
list(, $row) = each($row);
$sql = 'SELECT group_type
FROM ' . GROUPS_TABLE . '
WHERE group_id = ' . $group_id;
$result = $db->sql_query($sql);
$group_type = (int) $db->sql_fetchfield('group_type');
$db->sql_freeresult($result);
if ($group_type != GROUP_OPEN && $group_type != GROUP_FREE) {
trigger_error($user->lang['CANNOT_RESIGN_GROUP'] . $return_page);
}
if (confirm_box(true)) {
group_user_del($group_id, $user->data['user_id']);
add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_RESIGN', $group_row[$group_id]['group_name']);
meta_refresh(3, $this->u_action);
trigger_error($user->lang[$row['user_pending'] ? 'GROUP_RESIGNED_PENDING' : 'GROUP_RESIGNED_MEMBERSHIP'] . $return_page);
} else {
$s_hidden_fields = array('selected' => $group_id, 'action' => 'resign', 'submit' => true);
confirm_box(false, $row['user_pending'] ? 'GROUP_RESIGN_PENDING' : 'GROUP_RESIGN_MEMBERSHIP', build_hidden_fields($s_hidden_fields));
}
break;
case 'join':
$sql = 'SELECT ug.*, u.username, u.username_clean, u.user_email
FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u
WHERE ug.user_id = u.user_id
AND ug.group_id = ' . $group_id . '
AND ug.user_id = ' . $user->data['user_id'];
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row) {
if ($row['user_pending']) {
trigger_error($user->lang['ALREADY_IN_GROUP_PENDING'] . $return_page);
}
trigger_error($user->lang['ALREADY_IN_GROUP'] . $return_page);
}
// Check permission to join (open group or request)
if ($group_row[$group_id]['group_type'] != GROUP_OPEN && $group_row[$group_id]['group_type'] != GROUP_FREE) {
trigger_error($user->lang['CANNOT_JOIN_GROUP'] . $return_page);
//.........这里部分代码省略.........
示例7: group_user_add
/**
* Add user(s) to group
*
* @return mixed false if no errors occurred, else the user lang string for the relevant error, for example 'NO_USER'
*/
function group_user_add($group_id, $user_id_ary = false, $username_ary = false, $group_name = false, $default = false, $leader = 0, $pending = 0, $group_attributes = false)
{
global $db, $auth, $phpbb_container;
// We need both username and user_id info
$result = user_get_id_name($user_id_ary, $username_ary);
if (!sizeof($user_id_ary) || $result !== false) {
return 'NO_USER';
}
// Remove users who are already members of this group
$sql = 'SELECT user_id, group_leader
FROM ' . USER_GROUP_TABLE . '
WHERE ' . $db->sql_in_set('user_id', $user_id_ary) . "\n\t\t\tAND group_id = {$group_id}";
$result = $db->sql_query($sql);
$add_id_ary = $update_id_ary = array();
while ($row = $db->sql_fetchrow($result)) {
$add_id_ary[] = (int) $row['user_id'];
if ($leader && !$row['group_leader']) {
$update_id_ary[] = (int) $row['user_id'];
}
}
$db->sql_freeresult($result);
// Do all the users exist in this group?
$add_id_ary = array_diff($user_id_ary, $add_id_ary);
// If we have no users
if (!sizeof($add_id_ary) && !sizeof($update_id_ary)) {
return 'GROUP_USERS_EXIST';
}
$db->sql_transaction('begin');
// Insert the new users
if (sizeof($add_id_ary)) {
$sql_ary = array();
foreach ($add_id_ary as $user_id) {
$sql_ary[] = array('user_id' => (int) $user_id, 'group_id' => (int) $group_id, 'group_leader' => (int) $leader, 'user_pending' => (int) $pending);
}
$db->sql_multi_insert(USER_GROUP_TABLE, $sql_ary);
}
if (sizeof($update_id_ary)) {
$sql = 'UPDATE ' . USER_GROUP_TABLE . '
SET group_leader = 1
WHERE ' . $db->sql_in_set('user_id', $update_id_ary) . "\n\t\t\t\tAND group_id = {$group_id}";
$db->sql_query($sql);
}
if ($default) {
group_user_attributes('default', $group_id, $user_id_ary, false, $group_name, $group_attributes);
}
$db->sql_transaction('commit');
// Clear permissions cache of relevant users
$auth->acl_clear_prefetch($user_id_ary);
if (!$group_name) {
$group_name = get_group_name($group_id);
}
$log = $leader ? 'LOG_MODS_ADDED' : ($pending ? 'LOG_USERS_PENDING' : 'LOG_USERS_ADDED');
add_log('admin', $log, $group_name, implode(', ', $username_ary));
group_update_listings($group_id);
if ($pending) {
$phpbb_notifications = $phpbb_container->get('notification_manager');
foreach ($add_id_ary as $user_id) {
$phpbb_notifications->add_notifications('notification.type.group_request', array('group_id' => $group_id, 'user_id' => $user_id, 'group_name' => $group_name));
}
}
// Return false - no error
return false;
}
示例8: main
//.........这里部分代码省略.........
$user->add_lang(array('groups', 'acp/groups'));
$group_id = request_var('g', 0);
if ($group_id)
{
// Check the founder only entry for this group to make sure everything is well
$sql = 'SELECT group_founder_manage
FROM ' . GROUPS_TABLE . '
WHERE group_id = ' . $group_id;
$result = $db->sql_query($sql);
$founder_manage = (int) $db->sql_fetchfield('group_founder_manage');
$db->sql_freeresult($result);
if ($user->data['user_type'] != USER_FOUNDER && $founder_manage)
{
trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
}
}
else
{
$founder_manage = 0;
}
switch ($action)
{
case 'demote':
case 'promote':
case 'default':
if (!$group_id)
{
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
}
group_user_attributes($action, $group_id, $user_id);
if ($action == 'default')
{
$user_row['group_id'] = $group_id;
}
break;
case 'delete':
if (confirm_box(true))
{
if (!$group_id)
{
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
}
if ($error = group_user_del($group_id, $user_id))
{
trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
}
$error = array();
}
else
{
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
'u' => $user_id,
'i' => $id,
'mode' => $mode,
'action' => $action,
'g' => $group_id))
);
示例9: main
function main($id, $mode)
{
global $config, $db, $user, $auth, $template, $cache;
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
$user->add_lang('acp/groups');
$this->tpl_name = 'acp_groups';
$this->page_title = 'ACP_GROUPS_MANAGE';
include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
// Check and set some common vars
$action = isset($_POST['add']) ? 'add' : (isset($_POST['addusers']) ? 'addusers' : request_var('action', ''));
$group_id = request_var('g', 0);
$mark_ary = request_var('mark', array(0));
$name_ary = request_var('usernames', '');
$leader = request_var('leader', 0);
$default = request_var('default', 0);
$start = request_var('start', 0);
$update = isset($_POST['update']) ? true : false;
// Clear some vars
$can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && is_writeable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false;
$group_row = array();
// Grab basic data for group, if group_id is set and exists
if ($group_id) {
$sql = 'SELECT *
FROM ' . GROUPS_TABLE . " \n\t\t\t\tWHERE group_id = {$group_id}";
$result = $db->sql_query($sql);
$group_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$group_row) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action));
}
}
// Which page?
switch ($action) {
case 'approve':
case 'demote':
case 'promote':
if (!$group_id) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action));
}
// Approve, demote or promote
group_user_attributes($action, $group_id, $mark_ary, false, $group_id ? $group_row['group_name'] : false);
switch ($action) {
case 'demote':
$message = 'GROUP_MODS_DEMOTED';
break;
case 'promote':
$message = 'GROUP_MODS_PROMOTED';
break;
case 'approve':
$message = 'USERS_APPROVED';
break;
}
trigger_error($user->lang[$message] . adm_back_link($this->u_action));
break;
case 'default':
if (!$group_id) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action));
}
if (confirm_box(true)) {
if (!sizeof($mark_ary)) {
$start = 0;
do {
$sql = 'SELECT user_id
FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id} \n\t\t\t\t\t\t\t\tORDER BY user_id";
$result = $db->sql_query_limit($sql, 200, $start);
$mark_ary = array();
if ($row = $db->sql_fetchrow($result)) {
do {
$mark_ary[] = $row['user_id'];
} while ($row = $db->sql_fetchrow($result));
group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row);
$start = sizeof($mark_ary) < 200 ? 0 : $start + 200;
} else {
$start = 0;
}
$db->sql_freeresult($result);
} while ($start);
} else {
group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row);
}
trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action));
} else {
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action)));
}
break;
case 'deleteusers':
case 'delete':
if (confirm_box(true)) {
if (!$group_id) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action));
}
$error = '';
switch ($action) {
case 'delete':
if (!$auth->acl_get('a_groupdel')) {
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action));
}
$error = group_delete($group_id, $group_row['group_name']);
break;
case 'deleteusers':
//.........这里部分代码省略.........
示例10: main
function main($id, $mode)
{
global $config, $phpbb_root_path, $phpEx, $phpbb_admin_path;
global $db, $user, $auth, $cache, $template;
global $request, $phpbb_container, $phpbb_log;
$user->add_lang('groups');
$return_page = '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '">', '</a>');
$mark_ary = $request->variable('mark', array(0));
$submit = $request->variable('submit', false, false, \phpbb\request\request_interface::POST);
$delete = $request->variable('delete', false, false, \phpbb\request\request_interface::POST);
$error = $data = array();
/** @var \phpbb\group\helper $group_helper */
$group_helper = $phpbb_container->get('group_helper');
switch ($mode) {
case 'membership':
$this->page_title = 'UCP_USERGROUPS_MEMBER';
if ($submit || isset($_POST['change_default'])) {
$action = isset($_POST['change_default']) ? 'change_default' : $request->variable('action', '');
$group_id = $action == 'change_default' ? $request->variable('default', 0) : $request->variable('selected', 0);
if (!$group_id) {
trigger_error('NO_GROUP_SELECTED');
}
$sql = 'SELECT group_id, group_name, group_type
FROM ' . GROUPS_TABLE . "\n\t\t\t\t\t\tWHERE group_id IN ({$group_id}, {$user->data['group_id']})";
$result = $db->sql_query($sql);
$group_row = array();
while ($row = $db->sql_fetchrow($result)) {
$row['group_name'] = $group_helper->get_name($row['group_name']);
$group_row[$row['group_id']] = $row;
}
$db->sql_freeresult($result);
if (!sizeof($group_row)) {
trigger_error('GROUP_NOT_EXIST');
}
switch ($action) {
case 'change_default':
// User already having this group set as default?
if ($group_id == $user->data['group_id']) {
trigger_error($user->lang['ALREADY_DEFAULT_GROUP'] . $return_page);
}
if (!$auth->acl_get('u_chggrp')) {
trigger_error($user->lang['NOT_AUTHORISED'] . $return_page);
}
// User needs to be member of the group in order to make it default
if (!group_memberships($group_id, $user->data['user_id'], true)) {
trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
}
if (confirm_box(true)) {
group_user_attributes('default', $group_id, $user->data['user_id']);
$phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_GROUP_CHANGE', false, array('reportee_id' => $user->data['user_id'], sprintf($user->lang['USER_GROUP_CHANGE'], $group_row[$user->data['group_id']]['group_name'], $group_row[$group_id]['group_name'])));
meta_refresh(3, $this->u_action);
trigger_error($user->lang['CHANGED_DEFAULT_GROUP'] . $return_page);
} else {
$s_hidden_fields = array('default' => $group_id, 'change_default' => true);
confirm_box(false, sprintf($user->lang['GROUP_CHANGE_DEFAULT'], $group_row[$group_id]['group_name']), build_hidden_fields($s_hidden_fields));
}
break;
case 'resign':
// User tries to resign from default group but is not allowed to change it?
if ($group_id == $user->data['group_id'] && !$auth->acl_get('u_chggrp')) {
trigger_error($user->lang['NOT_RESIGN_FROM_DEFAULT_GROUP'] . $return_page);
}
if (!($row = group_memberships($group_id, $user->data['user_id']))) {
trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
}
list(, $row) = each($row);
$sql = 'SELECT group_type
FROM ' . GROUPS_TABLE . '
WHERE group_id = ' . $group_id;
$result = $db->sql_query($sql);
$group_type = (int) $db->sql_fetchfield('group_type');
$db->sql_freeresult($result);
if ($group_type != GROUP_OPEN && $group_type != GROUP_FREE) {
trigger_error($user->lang['CANNOT_RESIGN_GROUP'] . $return_page);
}
if (confirm_box(true)) {
group_user_del($group_id, $user->data['user_id']);
$phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_GROUP_RESIGN', false, array('reportee_id' => $user->data['user_id'], $group_row[$group_id]['group_name']));
meta_refresh(3, $this->u_action);
trigger_error($user->lang[$row['user_pending'] ? 'GROUP_RESIGNED_PENDING' : 'GROUP_RESIGNED_MEMBERSHIP'] . $return_page);
} else {
$s_hidden_fields = array('selected' => $group_id, 'action' => 'resign', 'submit' => true);
confirm_box(false, $row['user_pending'] ? 'GROUP_RESIGN_PENDING' : 'GROUP_RESIGN_MEMBERSHIP', build_hidden_fields($s_hidden_fields));
}
break;
case 'join':
$sql = 'SELECT ug.*, u.username, u.username_clean, u.user_email
FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u
WHERE ug.user_id = u.user_id
AND ug.group_id = ' . $group_id . '
AND ug.user_id = ' . $user->data['user_id'];
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row) {
if ($row['user_pending']) {
trigger_error($user->lang['ALREADY_IN_GROUP_PENDING'] . $return_page);
}
trigger_error($user->lang['ALREADY_IN_GROUP'] . $return_page);
}
//.........这里部分代码省略.........
示例11: main
function main($id, $mode)
{
global $config, $db, $user, $auth, $template, $cache;
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
$user->add_lang('acp/groups');
$this->tpl_name = 'acp_groups';
$this->page_title = 'ACP_GROUPS_MANAGE';
$form_key = 'acp_groups';
add_form_key($form_key);
include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
// Check and set some common vars
$action = isset($_POST['add']) ? 'add' : (isset($_POST['addusers']) ? 'addusers' : request_var('action', ''));
$group_id = request_var('g', 0);
$mark_ary = request_var('mark', array(0));
$name_ary = request_var('usernames', '', true);
$leader = request_var('leader', 0);
$default = request_var('default', 0);
$start = request_var('start', 0);
$update = isset($_POST['update']) ? true : false;
// Clear some vars
$can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false;
$group_row = array();
// Grab basic data for group, if group_id is set and exists
if ($group_id) {
$sql = 'SELECT *
FROM ' . GROUPS_TABLE . "\n\t\t\t\tWHERE group_id = {$group_id}";
$result = $db->sql_query($sql);
$group_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$group_row) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
}
// Check if the user is allowed to manage this group if set to founder only.
if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage']) {
trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
}
}
// Which page?
switch ($action) {
case 'approve':
case 'demote':
case 'promote':
if (!$group_id) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
}
// Approve, demote or promote
$group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
$error = group_user_attributes($action, $group_id, $mark_ary, false, $group_name);
if (!$error) {
switch ($action) {
case 'demote':
$message = 'GROUP_MODS_DEMOTED';
break;
case 'promote':
$message = 'GROUP_MODS_PROMOTED';
break;
case 'approve':
$message = 'USERS_APPROVED';
break;
}
trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id));
} else {
trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING);
}
break;
case 'default':
if (!$group_id) {
trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
}
if (confirm_box(true)) {
$group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
if (!sizeof($mark_ary)) {
$start = 0;
do {
$sql = 'SELECT user_id
FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\t\t\tORDER BY user_id";
$result = $db->sql_query_limit($sql, 200, $start);
$mark_ary = array();
if ($row = $db->sql_fetchrow($result)) {
do {
$mark_ary[] = $row['user_id'];
} while ($row = $db->sql_fetchrow($result));
group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
$start = sizeof($mark_ary) < 200 ? 0 : $start + 200;
} else {
$start = 0;
}
$db->sql_freeresult($result);
} while ($start);
} else {
group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
}
trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id));
} else {
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action)));
}
break;
case 'deleteusers':
case 'delete':
if (!$group_id) {
//.........这里部分代码省略.........
示例12: add_users_to_group
/**
* {@inheritdoc}
*/
public function add_users_to_group($user_id_ary, $group_rule_data)
{
// Set this variable for readability in the code below
$group_id = $group_rule_data['autogroups_group_id'];
// Add user(s) to the group
group_user_add($group_id, $user_id_ary);
// Send notification
if ($group_rule_data['autogroups_notify']) {
$this->helper->send_notifications('group_added', $user_id_ary, $group_id);
}
// Set group as default?
if ($group_rule_data['autogroups_default']) {
// Make sure user_id_ary is an array
$user_id_ary = $this->helper->prepare_users_for_query($user_id_ary);
// Get array of users exempt from default group switching
$default_exempt_users = $this->helper->get_default_exempt_users();
// Remove any exempt users from our main user array
if (sizeof($default_exempt_users)) {
$user_id_ary = array_diff($user_id_ary, $default_exempt_users);
}
// Set the current group as default for non-exempt users
group_user_attributes('default', $group_id, $user_id_ary);
}
}
示例13: group_user_add
/**
* Add user(s) to group
*
* @return mixed false if no errors occurred, else the user lang string for the relevant error, for example 'NO_USER'
*/
function group_user_add($group_id, $user_id_ary = false, $username_ary = false, $group_name = false, $default = false, $leader = 0, $pending = 0, $group_attributes = false)
{
global $db, $auth, $user, $phpbb_container, $phpbb_log, $phpbb_dispatcher;
// We need both username and user_id info
$result = user_get_id_name($user_id_ary, $username_ary);
if (!sizeof($user_id_ary) || $result !== false) {
return 'NO_USER';
}
// Remove users who are already members of this group
$sql = 'SELECT user_id, group_leader
FROM ' . USER_GROUP_TABLE . '
WHERE ' . $db->sql_in_set('user_id', $user_id_ary) . "\n\t\t\tAND group_id = {$group_id}";
$result = $db->sql_query($sql);
$add_id_ary = $update_id_ary = array();
while ($row = $db->sql_fetchrow($result)) {
$add_id_ary[] = (int) $row['user_id'];
if ($leader && !$row['group_leader']) {
$update_id_ary[] = (int) $row['user_id'];
}
}
$db->sql_freeresult($result);
// Do all the users exist in this group?
$add_id_ary = array_diff($user_id_ary, $add_id_ary);
// If we have no users
if (!sizeof($add_id_ary) && !sizeof($update_id_ary)) {
return 'GROUP_USERS_EXIST';
}
$db->sql_transaction('begin');
// Insert the new users
if (sizeof($add_id_ary)) {
$sql_ary = array();
foreach ($add_id_ary as $user_id) {
$sql_ary[] = array('user_id' => (int) $user_id, 'group_id' => (int) $group_id, 'group_leader' => (int) $leader, 'user_pending' => (int) $pending);
}
$db->sql_multi_insert(USER_GROUP_TABLE, $sql_ary);
}
if (sizeof($update_id_ary)) {
$sql = 'UPDATE ' . USER_GROUP_TABLE . '
SET group_leader = 1
WHERE ' . $db->sql_in_set('user_id', $update_id_ary) . "\n\t\t\t\tAND group_id = {$group_id}";
$db->sql_query($sql);
}
if ($default) {
group_user_attributes('default', $group_id, $user_id_ary, false, $group_name, $group_attributes);
}
$db->sql_transaction('commit');
// Clear permissions cache of relevant users
$auth->acl_clear_prefetch($user_id_ary);
/**
* Event after users are added to a group
*
* @event core.group_add_user_after
* @var int group_id ID of the group to which users are added
* @var string group_name Name of the group
* @var array user_id_ary IDs of the users which are added
* @var array username_ary names of the users which are added
* @var int pending Pending setting, 1 if user(s) added are pending
* @since 3.1.7-RC1
*/
$vars = array('group_id', 'group_name', 'user_id_ary', 'username_ary', 'pending');
extract($phpbb_dispatcher->trigger_event('core.group_add_user_after', compact($vars)));
if (!$group_name) {
$group_name = get_group_name($group_id);
}
$log = $leader ? 'LOG_MODS_ADDED' : ($pending ? 'LOG_USERS_PENDING' : 'LOG_USERS_ADDED');
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, $log, false, array($group_name, implode(', ', $username_ary)));
group_update_listings($group_id);
if ($pending) {
/* @var $phpbb_notifications \phpbb\notification\manager */
$phpbb_notifications = $phpbb_container->get('notification_manager');
foreach ($add_id_ary as $user_id) {
$phpbb_notifications->add_notifications('notification.type.group_request', array('group_id' => $group_id, 'user_id' => $user_id, 'group_name' => $group_name));
}
}
// Return false - no error
return false;
}