/**
* Add or edit a group. If we're editing a group we only update user
* parameters such as rank, etc. if they are changed
*/
function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow_desc_bbcode = false, $allow_desc_urls = false, $allow_desc_smilies = false)
{
    global $phpbb_root_path, $config, $db, $user, $file_upload, $phpbb_container;
    $error = array();
    // Attributes which also affect the users table
    $user_attribute_ary = array('group_colour', 'group_rank', 'group_avatar', 'group_avatar_type', 'group_avatar_width', 'group_avatar_height');
    // Check data. Limit group name length.
    if (!utf8_strlen($name) || utf8_strlen($name) > 60) {
        $error[] = !utf8_strlen($name) ? $user->lang['GROUP_ERR_USERNAME'] : $user->lang['GROUP_ERR_USER_LONG'];
    }
    $err = group_validate_groupname($group_id, $name);
    if (!empty($err)) {
        $error[] = $user->lang[$err];
    }
    if (!in_array($type, array(GROUP_OPEN, GROUP_CLOSED, GROUP_HIDDEN, GROUP_SPECIAL, GROUP_FREE))) {
        $error[] = $user->lang['GROUP_ERR_TYPE'];
    }
    $group_teampage = !empty($group_attributes['group_teampage']);
    unset($group_attributes['group_teampage']);
    if (!sizeof($error)) {
        $current_legend = \phpbb\groupposition\legend::GROUP_DISABLED;
        $current_teampage = \phpbb\groupposition\teampage::GROUP_DISABLED;
        $legend = $phpbb_container->get('groupposition.legend');
        $teampage = $phpbb_container->get('groupposition.teampage');
        if ($group_id) {
            try {
                $current_legend = $legend->get_group_value($group_id);
                $current_teampage = $teampage->get_group_value($group_id);
            } catch (\phpbb\groupposition\exception $exception) {
                trigger_error($user->lang($exception->getMessage()));
            }
        }
        if (!empty($group_attributes['group_legend'])) {
            if ($group_id && $current_legend == \phpbb\groupposition\legend::GROUP_DISABLED || !$group_id) {
                // Old group currently not in the legend or new group, add at the end.
                $group_attributes['group_legend'] = 1 + $legend->get_group_count();
            } else {
                // Group stayes in the legend
                $group_attributes['group_legend'] = $current_legend;
            }
        } else {
            if ($group_id && $current_legend != \phpbb\groupposition\legend::GROUP_DISABLED) {
                // Group is removed from the legend
                try {
                    $legend->delete_group($group_id, true);
                } catch (\phpbb\groupposition\exception $exception) {
                    trigger_error($user->lang($exception->getMessage()));
                }
                $group_attributes['group_legend'] = \phpbb\groupposition\legend::GROUP_DISABLED;
            } else {
                $group_attributes['group_legend'] = \phpbb\groupposition\legend::GROUP_DISABLED;
            }
        }
        // Unset the objects, we don't need them anymore.
        unset($legend);
        $user_ary = array();
        $sql_ary = array('group_name' => (string) $name, 'group_desc' => (string) $desc, 'group_desc_uid' => '', 'group_desc_bitfield' => '', 'group_type' => (int) $type);
        // Parse description
        if ($desc) {
            generate_text_for_storage($sql_ary['group_desc'], $sql_ary['group_desc_uid'], $sql_ary['group_desc_bitfield'], $sql_ary['group_desc_options'], $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies);
        }
        if (sizeof($group_attributes)) {
            // Merge them with $sql_ary to properly update the group
            $sql_ary = array_merge($sql_ary, $group_attributes);
        }
        // Setting the log message before we set the group id (if group gets added)
        $log = $group_id ? 'LOG_GROUP_UPDATED' : 'LOG_GROUP_CREATED';
        $query = '';
        if ($group_id) {
            $sql = 'SELECT user_id
				FROM ' . USERS_TABLE . '
				WHERE group_id = ' . $group_id;
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $user_ary[] = $row['user_id'];
            }
            $db->sql_freeresult($result);
            if (isset($sql_ary['group_avatar'])) {
                remove_default_avatar($group_id, $user_ary);
            }
            if (isset($sql_ary['group_rank'])) {
                remove_default_rank($group_id, $user_ary);
            }
            $sql = 'UPDATE ' . GROUPS_TABLE . '
				SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\tWHERE group_id = {$group_id}";
            $db->sql_query($sql);
            // Since we may update the name too, we need to do this on other tables too...
            $sql = 'UPDATE ' . MODERATOR_CACHE_TABLE . "\n\t\t\t\tSET group_name = '" . $db->sql_escape($sql_ary['group_name']) . "'\n\t\t\t\tWHERE group_id = {$group_id}";
            $db->sql_query($sql);
            // One special case is the group skip auth setting. If this was changed we need to purge permissions for this group
            if (isset($group_attributes['group_skip_auth'])) {
                // Get users within this group...
                $sql = 'SELECT user_id
					FROM ' . USER_GROUP_TABLE . '
					WHERE group_id = ' . $group_id . '
						AND user_pending = 0';
                $result = $db->sql_query($sql);
                $user_id_ary = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $user_id_ary[] = $row['user_id'];
                }
                $db->sql_freeresult($result);
                if (!empty($user_id_ary)) {
                    global $auth;
                    // Clear permissions cache of relevant users
                    $auth->acl_clear_prefetch($user_id_ary);
                }
            }
        } else {
            $sql = 'INSERT INTO ' . GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
            $db->sql_query($sql);
        }
        // Remove the group from the teampage, only if unselected and we are editing a group,
        // which is currently displayed.
        if (!$group_teampage && $group_id && $current_teampage != \phpbb\groupposition\teampage::GROUP_DISABLED) {
            try {
                $teampage->delete_group($group_id);
            } catch (\phpbb\groupposition\exception $exception) {
                trigger_error($user->lang($exception->getMessage()));
            }
        }
        if (!$group_id) {
            $group_id = $db->sql_nextid();
            if (isset($sql_ary['group_avatar_type']) && $sql_ary['group_avatar_type'] == 'avatar.driver.upload') {
                group_correct_avatar($group_id, $sql_ary['group_avatar']);
            }
        }
        try {
            if ($group_teampage && $current_teampage == \phpbb\groupposition\teampage::GROUP_DISABLED) {
                $teampage->add_group($group_id);
            }
            if ($group_teampage) {
                if ($current_teampage == \phpbb\groupposition\teampage::GROUP_DISABLED) {
                    $teampage->add_group($group_id);
                }
            } else {
                if ($group_id && $current_teampage != \phpbb\groupposition\teampage::GROUP_DISABLED) {
                    $teampage->delete_group($group_id);
                }
            }
        } catch (\phpbb\groupposition\exception $exception) {
            trigger_error($user->lang($exception->getMessage()));
        }
        unset($teampage);
        // Set user attributes
        $sql_ary = array();
        if (sizeof($group_attributes)) {
            // Go through the user attributes array, check if a group attribute matches it and then set it. ;)
            foreach ($user_attribute_ary as $attribute) {
                if (!isset($group_attributes[$attribute])) {
                    continue;
                }
                // If we are about to set an avatar, we will not overwrite user avatars if no group avatar is set...
                if (strpos($attribute, 'group_avatar') === 0 && !$group_attributes[$attribute]) {
                    continue;
                }
                $sql_ary[$attribute] = $group_attributes[$attribute];
            }
        }
        if (sizeof($sql_ary) && sizeof($user_ary)) {
            group_set_user_default($group_id, $user_ary, $sql_ary);
        }
        $name = $type == GROUP_SPECIAL ? $user->lang['G_' . $name] : $name;
        add_log('admin', $log, $name);
        group_update_listings($group_id);
    }
    return sizeof($error) ? $error : false;
}
示例#2
0
/**
* Add or edit a group. If we're editing a group we only update user
* parameters such as rank, etc. if they are changed
*/
function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow_desc_bbcode = false, $allow_desc_urls = false, $allow_desc_smilies = false)
{
    global $phpbb_root_path, $config, $db, $user, $file_upload;
    $error = array();
    $attribute_ary = array('group_colour' => 'string', 'group_rank' => 'int', 'group_avatar' => 'string', 'group_avatar_type' => 'int', 'group_avatar_width' => 'int', 'group_avatar_height' => 'int', 'group_receive_pm' => 'int', 'group_legend' => 'int', 'group_message_limit' => 'int', 'group_max_recipients' => 'int', 'group_founder_manage' => 'int');
    // Those are group-only attributes
    $group_only_ary = array('group_receive_pm', 'group_legend', 'group_message_limit', 'group_max_recipients', 'group_founder_manage');
    // Check data. Limit group name length.
    if (!utf8_strlen($name) || utf8_strlen($name) > 60) {
        $error[] = !utf8_strlen($name) ? $user->lang['GROUP_ERR_USERNAME'] : $user->lang['GROUP_ERR_USER_LONG'];
    }
    $err = group_validate_groupname($group_id, $name);
    if (!empty($err)) {
        $error[] = $user->lang[$err];
    }
    if (!in_array($type, array(GROUP_OPEN, GROUP_CLOSED, GROUP_HIDDEN, GROUP_SPECIAL, GROUP_FREE))) {
        $error[] = $user->lang['GROUP_ERR_TYPE'];
    }
    if (!sizeof($error)) {
        $user_ary = array();
        $sql_ary = array('group_name' => (string) $name, 'group_desc' => (string) $desc, 'group_desc_uid' => '', 'group_desc_bitfield' => '', 'group_type' => (int) $type);
        // Parse description
        if ($desc) {
            generate_text_for_storage($sql_ary['group_desc'], $sql_ary['group_desc_uid'], $sql_ary['group_desc_bitfield'], $sql_ary['group_desc_options'], $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies);
        }
        if (sizeof($group_attributes)) {
            foreach ($attribute_ary as $attribute => $_type) {
                if (isset($group_attributes[$attribute])) {
                    settype($group_attributes[$attribute], $_type);
                    $sql_ary[$attribute] = $group_attributes[$attribute];
                }
            }
        }
        // Setting the log message before we set the group id (if group gets added)
        $log = $group_id ? 'LOG_GROUP_UPDATED' : 'LOG_GROUP_CREATED';
        $query = '';
        if ($group_id) {
            $sql = 'SELECT user_id
				FROM ' . USERS_TABLE . '
				WHERE group_id = ' . $group_id;
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $user_ary[] = $row['user_id'];
            }
            $db->sql_freeresult($result);
            if (isset($sql_ary['group_avatar']) && !$sql_ary['group_avatar']) {
                remove_default_avatar($group_id, $user_ary);
            }
            if (isset($sql_ary['group_rank']) && !$sql_ary['group_rank']) {
                remove_default_rank($group_id, $user_ary);
            }
            $sql = 'UPDATE ' . GROUPS_TABLE . '
				SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\tWHERE group_id = {$group_id}";
            $db->sql_query($sql);
            // Since we may update the name too, we need to do this on other tables too...
            $sql = 'UPDATE ' . MODERATOR_CACHE_TABLE . "\n\t\t\t\tSET group_name = '" . $db->sql_escape($sql_ary['group_name']) . "'\n\t\t\t\tWHERE group_id = {$group_id}";
            $db->sql_query($sql);
        } else {
            $sql = 'INSERT INTO ' . GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
            $db->sql_query($sql);
        }
        if (!$group_id) {
            $group_id = $db->sql_nextid();
            if (isset($sql_ary['group_avatar_type']) && $sql_ary['group_avatar_type'] == AVATAR_UPLOAD) {
                group_correct_avatar($group_id, $sql_ary['group_avatar']);
            }
        }
        // Set user attributes
        $sql_ary = array();
        if (sizeof($group_attributes)) {
            foreach ($attribute_ary as $attribute => $_type) {
                if (isset($group_attributes[$attribute]) && !in_array($attribute, $group_only_ary)) {
                    // If we are about to set an avatar, we will not overwrite user avatars if no group avatar is set...
                    if (strpos($attribute, 'group_avatar') === 0 && !$group_attributes[$attribute]) {
                        continue;
                    }
                    $sql_ary[$attribute] = $group_attributes[$attribute];
                }
            }
        }
        if (sizeof($sql_ary) && sizeof($user_ary)) {
            group_set_user_default($group_id, $user_ary, $sql_ary);
        }
        $name = $type == GROUP_SPECIAL ? $user->lang['G_' . $name] : $name;
        add_log('admin', $log, $name);
        group_update_listings($group_id);
    }
    return sizeof($error) ? $error : false;
}
示例#3
0
/**
* Add or edit a group. If we're editing a group we only update user
* parameters such as rank, etc. if they are changed
*/
function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow_desc_bbcode = false, $allow_desc_urls = false, $allow_desc_smilies = false)
{
    global $phpbb_root_path, $config, $db, $user, $file_upload;
    $error = array();
    // Attributes which also affect the users table
    $user_attribute_ary = array('group_colour', 'group_rank', 'group_avatar', 'group_avatar_type', 'group_avatar_width', 'group_avatar_height');
    // Check data. Limit group name length.
    if (!utf8_strlen($name) || utf8_strlen($name) > 60) {
        $error[] = !utf8_strlen($name) ? $user->lang['GROUP_ERR_USERNAME'] : $user->lang['GROUP_ERR_USER_LONG'];
    }
    $err = group_validate_groupname($group_id, $name);
    if (!empty($err)) {
        $error[] = $user->lang[$err];
    }
    if (!in_array($type, array(GROUP_OPEN, GROUP_CLOSED, GROUP_HIDDEN, GROUP_SPECIAL, GROUP_FREE))) {
        $error[] = $user->lang['GROUP_ERR_TYPE'];
    }
    if (!sizeof($error)) {
        $user_ary = array();
        $sql_ary = array('group_name' => (string) $name, 'group_desc' => (string) $desc, 'group_desc_uid' => '', 'group_desc_bitfield' => '', 'group_type' => (int) $type);
        // Parse description
        if ($desc) {
            generate_text_for_storage($sql_ary['group_desc'], $sql_ary['group_desc_uid'], $sql_ary['group_desc_bitfield'], $sql_ary['group_desc_options'], $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies);
        }
        if (sizeof($group_attributes)) {
            // Merge them with $sql_ary to properly update the group
            $sql_ary = array_merge($sql_ary, $group_attributes);
        }
        // Setting the log message before we set the group id (if group gets added)
        $log = $group_id ? 'LOG_GROUP_UPDATED' : 'LOG_GROUP_CREATED';
        $query = '';
        if ($group_id) {
            $sql = 'SELECT user_id
				FROM ' . USERS_TABLE . '
				WHERE group_id = ' . $group_id;
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $user_ary[] = $row['user_id'];
            }
            $db->sql_freeresult($result);
            if (isset($sql_ary['group_avatar']) && !$sql_ary['group_avatar']) {
                remove_default_avatar($group_id, $user_ary);
            }
            if (isset($sql_ary['group_rank']) && !$sql_ary['group_rank']) {
                remove_default_rank($group_id, $user_ary);
            }
            $sql = 'UPDATE ' . GROUPS_TABLE . '
				SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\tWHERE group_id = {$group_id}";
            $db->sql_query($sql);
            // Since we may update the name too, we need to do this on other tables too...
            $sql = 'UPDATE ' . MODERATOR_CACHE_TABLE . "\n\t\t\t\tSET group_name = '" . $db->sql_escape($sql_ary['group_name']) . "'\n\t\t\t\tWHERE group_id = {$group_id}";
            $db->sql_query($sql);
            // One special case is the group skip auth setting. If this was changed we need to purge permissions for this group
            if (isset($group_attributes['group_skip_auth'])) {
                // Get users within this group...
                $sql = 'SELECT user_id
					FROM ' . USER_GROUP_TABLE . '
					WHERE group_id = ' . $group_id . '
						AND user_pending = 0';
                $result = $db->sql_query($sql);
                $user_id_ary = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $user_id_ary[] = $row['user_id'];
                }
                $db->sql_freeresult($result);
                if (!empty($user_id_ary)) {
                    global $auth;
                    // Clear permissions cache of relevant users
                    $auth->acl_clear_prefetch($user_id_ary);
                }
            }
        } else {
            $sql = 'INSERT INTO ' . GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
            $db->sql_query($sql);
        }
        if (!$group_id) {
            $group_id = $db->sql_nextid();
            if (isset($sql_ary['group_avatar_type']) && $sql_ary['group_avatar_type'] == AVATAR_UPLOAD) {
                group_correct_avatar($group_id, $sql_ary['group_avatar']);
            }
        }
        // Set user attributes
        $sql_ary = array();
        if (sizeof($group_attributes)) {
            // Go through the user attributes array, check if a group attribute matches it and then set it. ;)
            foreach ($user_attribute_ary as $attribute) {
                if (!isset($group_attributes[$attribute])) {
                    continue;
                }
                // If we are about to set an avatar, we will not overwrite user avatars if no group avatar is set...
                if (strpos($attribute, 'group_avatar') === 0 && !$group_attributes[$attribute]) {
                    continue;
                }
                $sql_ary[$attribute] = $group_attributes[$attribute];
            }
        }
        if (sizeof($sql_ary) && sizeof($user_ary)) {
            group_set_user_default($group_id, $user_ary, $sql_ary);
        }
        $name = $type == GROUP_SPECIAL ? $user->lang['G_' . $name] : $name;
        add_log('admin', $log, $name);
        group_update_listings($group_id);
    }
    return sizeof($error) ? $error : false;
}