Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7645395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:55:51+00:00 2026-05-31T09:55:51+00:00

I have copied a function from phpBB so that I could make some slight

  • 0

I have copied a function from phpBB so that I could make some slight adjustments to the return object. It works fine, creates the group returns the ID of the group etc. The only problem is when it fails (in the instance the group name exists) I get the following error:

[phpBB Debug] PHP Notice: in file C:/.../phpbb_library.php on line 586: Undefined index: GROUP_NAME_TAKEN

Here’s my code.

Constructor:

class Phpbb_library
{
    protected $_user;

    // http://wiki.phpbb.com/Add_users

    /**
     * Constructor.
     */
    public function __construct()
    {
        // Set the variables scope
        global $phpbb_root_path, $phpEx, $user, $auth, $cache, $db, $config, $template, $table_prefix;

        define('IN_PHPBB', TRUE);
        define('FORUM_ROOT_PATH', Kohana::$config->load('global.FORUM_ABSOLUTE_PATH'));

        $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : FORUM_ROOT_PATH;
        $phpEx = substr(strrchr(__FILE__, '.'), 1);

        // Include needed files
        include($phpbb_root_path . 'common.' . $phpEx);
        include($phpbb_root_path . 'config.' . $phpEx);
        include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
        include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
        include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
        include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
        //include($phpbb_root_path . 'language/en/acp/groups.' . $phpEx);

        // Initialize phpBB user session
        $user->session_begin();
        $auth->acl($user->data);
        $user->setup();

        // Save user data into $_user variable
        $this->_user = $user;
    }

group_create() – Modification:

/**
 * Dynamically create a group and return group id or error.
 * Modified version of group_create from includes/functions_user.php
 *
 * @return array - array object containing group id or error message.
 */
function group_create_mod(&$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) . "
                        WHERE 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 . "
                        SET group_name = '" . $db->sql_escape($sql_ary['group_name']) . "'
                        WHERE 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);
    }

    // MOD: sort out return object
    if (sizeof($error))
    {
        return array(
                    "success" => FALSE,
                    "error" => $error,
        );
    }
    else
    {
        return array(
                    "success" => TRUE,
                    "group_id" => $group_id,
        );
    }

    //return (sizeof($error)) ? $error : false;
}

The error I receive comes from this line: $error[] = $user->lang[$err];

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:55:53+00:00Added an answer on May 31, 2026 at 9:55 am

    It looks like you’re just missing a language definition for GROUP_NAME_TAKEN.

    For example in (or whichever language file) language/en/acp/groups.php

     'GROUP_NAME_TAKEN'            => 'The group name you entered is already in use, please select an alternative.',
    

    Edit: try this to include the groups language file:

    $user->add_lang('acp/groups');
    

    Add it in your constructor right after the global line (so that $user exists).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a sub routine that I copied from CPAN. It works fine as
I have copied some files from project A to project B, both of which
I have some code copied from the fitness website: package fixtures; import static fitnesse.util.ListUtility.list;
I have some code I copied from an example and I am not certain
I just copied some code from an asp.net mvc 2 app which works. Now
I have copied zipped file from the playframework.org website and unzipped it at a
I have some 3rd party libraries and includes (I have copied them to the
I am processing some CSV file which i have copied in Bin folder of
I have this sample code for async operations (copied from the interwebs) public class
I have copied the code from the following example on the Apple Developer site.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.