Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a forum in phpBB3 from PHP and settings permissions
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>Here's my code (please note the phpBB include files have been loaded previously):</p> <pre><code>// $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' =&gt; $forum_name, ); // Forum info $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE ' . $db-&gt;sql_build_array('SELECT', $data); $result = $db-&gt;sql_query($sql); $forum_id = (int) $db-&gt;sql_fetchfield('forum_id'); $db-&gt;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' =&gt; $parent_id, 'left_id' =&gt; 0, 'right_id' =&gt; 0, 'forum_parents' =&gt; '', 'forum_name' =&gt; $data['forum_name'], 'forum_desc' =&gt; '', 'forum_desc_bitfield' =&gt; '', 'forum_desc_options' =&gt; 7, 'forum_desc_uid' =&gt; '', 'forum_link' =&gt; '', 'forum_password' =&gt; '', 'forum_style' =&gt; 0, 'forum_image' =&gt; '', 'forum_rules' =&gt; '', 'forum_rules_link' =&gt; '', 'forum_rules_bitfield' =&gt; '', 'forum_rules_options' =&gt; 7, 'forum_rules_uid' =&gt; '', 'forum_topics_per_page' =&gt; 0, 'forum_type' =&gt; 1, 'forum_status' =&gt; 0, 'forum_posts' =&gt; 0, 'forum_topics' =&gt; 0, 'forum_topics_real' =&gt; 0, 'forum_last_post_id' =&gt; 0, 'forum_last_poster_id' =&gt; 0, 'forum_last_post_subject' =&gt; '', 'forum_last_post_time' =&gt; 0, 'forum_last_poster_name' =&gt; '', 'forum_last_poster_colour' =&gt; '', 'forum_flags' =&gt; 32, 'display_on_index' =&gt; FALSE, 'enable_indexing' =&gt; TRUE, 'enable_icons' =&gt; FALSE, 'enable_prune' =&gt; FALSE, 'prune_next' =&gt; 0, 'prune_days' =&gt; 7, 'prune_viewed' =&gt; 7, 'prune_freq' =&gt; 1, ); $sql = 'SELECT MAX(right_id) AS right_id FROM ' . FORUMS_TABLE; $result = $db-&gt;sql_query($sql); $row = $db-&gt;sql_fetchrow($result); $db-&gt;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-&gt;sql_build_array('INSERT', $forum_data); $db-&gt;sql_query($sql); $forum_data['forum_id'] = $db-&gt;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-&gt;sql_query($sql); $users_sql_ary = array(); while ($row = $db-&gt;sql_fetchrow($result)) { $users_sql_ary[] = array( 'user_id' =&gt; (int) $row['user_id'], 'forum_id' =&gt; $forum_data['forum_id'], 'auth_option_id' =&gt; (int) $row['auth_option_id'], 'auth_role_id' =&gt; (int) $row['auth_role_id'], 'auth_setting' =&gt; (int) $row['auth_setting'] ); } $db-&gt;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-&gt;sql_query($sql); $groups_sql_ary = array(); while ($row = $db-&gt;sql_fetchrow($result)) { $groups_sql_ary[] = array( 'group_id' =&gt; (int) $row['group_id'], 'forum_id' =&gt; $forum_data['forum_id'], 'auth_option_id' =&gt; (int) $row['auth_option_id'], 'auth_role_id' =&gt; (int) $row['auth_role_id'], 'auth_setting' =&gt; (int) $row['auth_setting'] ); } $db-&gt;sql_freeresult($result); ////////////////////////////////// // INSERT NEW FORUM PERMISSIONS // ////////////////////////////////// $db-&gt;sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary); $db-&gt;sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary); $auth-&gt;acl_clear_prefetch(); return $response; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload