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 7504255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:30:51+00:00 2026-05-29T21:30:51+00:00

I’m attempting to create a new forum on an existing forum. I can create

  • 0

I’m attempting to create a new forum on an existing forum. I can create the new forum quite easily and view it from the admin console. The problem is I need it to show up at the front end as well for users. This is done via permissions.

What I am attempting to do therefore is copy the permissions of the parent forum (which is public) to the forum I create. However the forum still doesn’t appear to be showing up on the public facing side.

Here’s my code (please note the phpBB include files have been loaded previously):

// $forum_name = name of the new forum
// $parent_id  = the forum which this is a child of

function create_forum($forum_name, $parent_id)
{   
    global $phpbb_root_path, $phpEx, $user, $auth, $cache, $db, $config, $template, $table_prefix;

    $response = array();
    $data = array(
       'forum_name' => $forum_name,
    );

    // Forum info
    $sql = 'SELECT forum_id
          FROM ' . FORUMS_TABLE . '
          WHERE ' . $db->sql_build_array('SELECT', $data);
    $result = $db->sql_query($sql);

    $forum_id = (int) $db->sql_fetchfield('forum_id');
    $db->sql_freeresult($result);

    if ($forum_id) 
    {
       $response['error'] = TRUE;
       $response['error_msg'] = 'FORUM_EXISTS';
       $response['forum_id'] = $forum_id;
    } 
    else 
    {
       $forum_data = array(
          'parent_id'   =>   $parent_id,
          'left_id'   =>   0,
          'right_id'   =>   0,
          'forum_parents'   =>   '',
          'forum_name'   =>   $data['forum_name'],
          'forum_desc'  =>   '',
          'forum_desc_bitfield'   =>   '',
          'forum_desc_options'   =>   7,
          'forum_desc_uid'   =>   '',
          'forum_link'   =>   '',
          'forum_password'   =>   '',
          'forum_style'   =>   0,
          'forum_image'   =>   '',
          'forum_rules'   =>   '',
          'forum_rules_link'   =>   '',
          'forum_rules_bitfield'   =>   '',
          'forum_rules_options'   =>   7,
          'forum_rules_uid'   =>   '',
          'forum_topics_per_page'   =>   0,
          'forum_type'   =>   1,
          'forum_status'   =>   0,
          'forum_posts'   =>   0,
          'forum_topics'   =>   0,
          'forum_topics_real'   =>   0,
          'forum_last_post_id'   =>   0,
          'forum_last_poster_id'   =>   0,
          'forum_last_post_subject'   =>   '',
          'forum_last_post_time'   =>   0,
          'forum_last_poster_name'   =>   '',
          'forum_last_poster_colour'   =>   '',
          'forum_flags'   =>   32,
          'display_on_index'   =>   FALSE,            
          'enable_indexing'   =>   TRUE,
          'enable_icons'   =>   FALSE,                
          'enable_prune'   =>   FALSE,
          'prune_next'   =>   0,
          'prune_days'   =>   7,                       
          'prune_viewed'   =>   7,                    
          'prune_freq'   =>   1,
       );

       $sql = 'SELECT MAX(right_id) AS right_id
                FROM ' . FORUMS_TABLE;
       $result = $db->sql_query($sql);
       $row = $db->sql_fetchrow($result);
       $db->sql_freeresult($result);

       $forum_data['left_id'] = $row['right_id'] + 1;
       $forum_data['right_id'] = $row['right_id'] + 2;

       // And as last, a insert query
       $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data);
       $db->sql_query($sql);

       $forum_data['forum_id'] = $db->sql_nextid();


       // successful result
       $response['error'] = FALSE;
       $response['error_msg'] = '';
       $response['forum_id'] = $forum_data['forum_id'];


       /* PERMISSIONS ----------------------------------------------- */

       // copy permissions from parent forum
       $forum_perm_from = $parent_id;

       ///////////////////////////
       // COPY USER PERMISSIONS //
       ///////////////////////////

       // Copy permisisons from/to the acl users table (only forum_id gets changed)
       $sql = 'SELECT user_id, auth_option_id, auth_role_id, auth_setting
          FROM ' . ACL_USERS_TABLE . '
          WHERE forum_id = ' . $forum_perm_from;
       $result = $db->sql_query($sql);

       $users_sql_ary = array();
       while ($row = $db->sql_fetchrow($result))
       {
          $users_sql_ary[] = array(
             'user_id'         => (int) $row['user_id'],
             'forum_id'         => $forum_data['forum_id'],
             'auth_option_id'   => (int) $row['auth_option_id'],
             'auth_role_id'      => (int) $row['auth_role_id'],
             'auth_setting'      => (int) $row['auth_setting']
          );
       }
       $db->sql_freeresult($result);

       ////////////////////////////
       // COPY GROUP PERMISSIONS //
       ////////////////////////////

       // Copy permisisons from/to the acl groups table (only forum_id gets changed)
       $sql = 'SELECT group_id, auth_option_id, auth_role_id, auth_setting
          FROM ' . ACL_GROUPS_TABLE . '
          WHERE forum_id = ' . $forum_perm_from;
       $result = $db->sql_query($sql);

       $groups_sql_ary = array();
       while ($row = $db->sql_fetchrow($result))
       {
          $groups_sql_ary[] = array(
             'group_id'         => (int) $row['group_id'],
             'forum_id'         => $forum_data['forum_id'],
             'auth_option_id'   => (int) $row['auth_option_id'],
             'auth_role_id'      => (int) $row['auth_role_id'],
             'auth_setting'      => (int) $row['auth_setting']
          );
       }
       $db->sql_freeresult($result);

       //////////////////////////////////
       // INSERT NEW FORUM PERMISSIONS //
       //////////////////////////////////

       $db->sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary);
       $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);

       $auth->acl_clear_prefetch(); 

       return $response;
    }
}
  • 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-29T21:30:53+00:00Added an answer on May 29, 2026 at 9:30 pm
    function create_forum($forum_name, $parent_id)
    {   
        global $phpbb_root_path, $phpEx, $user, $auth, $cache, $db, $config, $template, $table_prefix;
    
        $response = array();
        $data = array(
           'forum_name' => $forum_name,
        );
    
        // Forum info
        $sql = 'SELECT forum_id
              FROM ' . FORUMS_TABLE . '
              WHERE ' . $db->sql_build_array('SELECT', $data);
        $result = $db->sql_query($sql);
    
        $forum_id = (int) $db->sql_fetchfield('forum_id');
        $db->sql_freeresult($result);
    
        if ($forum_id) 
        {
           $response['error'] = TRUE;
           $response['error_msg'] = 'FORUM_EXISTS';
           $response['forum_id'] = $forum_id;
        } 
        else 
        {
           $forum_data = array(
              'parent_id'   =>   $parent_id,
              'left_id'   =>   0,
              'right_id'   =>   0,
              'forum_parents'   =>   '',
              'forum_name'   =>   $data['forum_name'],
              'forum_desc'  =>   '',
              'forum_desc_bitfield'   =>   '',
              'forum_desc_options'   =>   7,
              'forum_desc_uid'   =>   '',
              'forum_link'   =>   '',
              'forum_password'   =>   '',
              'forum_style'   =>   0,
              'forum_image'   =>   '',
              'forum_rules'   =>   '',
              'forum_rules_link'   =>   '',
              'forum_rules_bitfield'   =>   '',
              'forum_rules_options'   =>   7,
              'forum_rules_uid'   =>   '',
              'forum_topics_per_page'   =>   0,
              'forum_type'   =>   1,
              'forum_status'   =>   0,
              'forum_posts'   =>   0,
              'forum_topics'   =>   0,
              'forum_topics_real'   =>   0,
              'forum_last_post_id'   =>   0,
              'forum_last_poster_id'   =>   0,
              'forum_last_post_subject'   =>   '',
              'forum_last_post_time'   =>   0,
              'forum_last_poster_name'   =>   '',
              'forum_last_poster_colour'   =>   '',
              'forum_flags'   =>   32,
              'display_on_index'   =>   FALSE,            
              'enable_indexing'   =>   TRUE,
              'enable_icons'   =>   FALSE,                
              'enable_prune'   =>   FALSE,
              'prune_next'   =>   0,
              'prune_days'   =>   7,                       
              'prune_viewed'   =>   7,                    
              'prune_freq'   =>   1,
           );
                /**
                /*Changed the code from here    
                /*Pulled straight from acl_forums.php from line 973 to line 1002        
                /*Removed lines 980 -> 989
                /*Changed $forum_data_sql['parent_id']; line 975 to $parent_id
                /*Changed $forum_data_sql on lines 1001, 1002 to $forum_data    
                **/
    
                $sql = 'SELECT left_id, right_id, forum_type
                    FROM ' . FORUMS_TABLE . '
                    WHERE forum_id = ' . $parent_id;
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
    
                $sql = 'UPDATE ' . FORUMS_TABLE . '
                    SET left_id = left_id + 2, right_id = right_id + 2
                    WHERE left_id > ' . $row['right_id'];
                $db->sql_query($sql);
    
                $sql = 'UPDATE ' . FORUMS_TABLE . '
                    SET right_id = right_id + 2
                    WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
                $db->sql_query($sql);
    
                $forum_data['left_id'] = $row['right_id'];
                $forum_data['right_id'] = $row['right_id'] + 1;
    
           // And as last, a insert query
           $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data);
           $db->sql_query($sql);
    
           $forum_data['forum_id'] = $db->sql_nextid();
    
    
           // successful result
           $response['error'] = FALSE;
           $response['error_msg'] = '';
           $response['forum_id'] = $forum_data['forum_id'];
    
    
           /* PERMISSIONS ----------------------------------------------- */
    
           // copy permissions from parent forum
           $forum_perm_from = $parent_id;
    
           ///////////////////////////
           // COPY USER PERMISSIONS //
           ///////////////////////////
    
           // Copy permisisons from/to the acl users table (only forum_id gets changed)
           $sql = 'SELECT user_id, auth_option_id, auth_role_id, auth_setting
              FROM ' . ACL_USERS_TABLE . '
              WHERE forum_id = ' . $forum_perm_from;
           $result = $db->sql_query($sql);
    
           $users_sql_ary = array();
           while ($row = $db->sql_fetchrow($result))
           {
              $users_sql_ary[] = array(
                 'user_id'         => (int) $row['user_id'],
                 'forum_id'         => $forum_data['forum_id'],
                 'auth_option_id'   => (int) $row['auth_option_id'],
                 'auth_role_id'      => (int) $row['auth_role_id'],
                 'auth_setting'      => (int) $row['auth_setting']
              );
           }
           $db->sql_freeresult($result);
    
           ////////////////////////////
           // COPY GROUP PERMISSIONS //
           ////////////////////////////
    
           // Copy permisisons from/to the acl groups table (only forum_id gets changed)
           $sql = 'SELECT group_id, auth_option_id, auth_role_id, auth_setting
              FROM ' . ACL_GROUPS_TABLE . '
              WHERE forum_id = ' . $forum_perm_from;
           $result = $db->sql_query($sql);
    
           $groups_sql_ary = array();
           while ($row = $db->sql_fetchrow($result))
           {
              $groups_sql_ary[] = array(
                 'group_id'         => (int) $row['group_id'],
                 'forum_id'         => $forum_data['forum_id'],
                 'auth_option_id'   => (int) $row['auth_option_id'],
                 'auth_role_id'      => (int) $row['auth_role_id'],
                 'auth_setting'      => (int) $row['auth_setting']
              );
           }
           $db->sql_freeresult($result);
    
           //////////////////////////////////
           // INSERT NEW FORUM PERMISSIONS //
           //////////////////////////////////
    
           $db->sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary);
           $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
    
           $auth->acl_clear_prefetch(); 
            print_r($response);
           return $response;
        }
    }
    

    phpbbphpbb3phpbb3.0.10php

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I have a view passing on information from a database: def serve_article(request, id): served_article
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters

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.