Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>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, ); /** /*Changed the code from here /*Pulled straight from acl_forums.php from line 973 to line 1002 /*Removed lines 980 -&gt; 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-&gt;sql_query($sql); $row = $db-&gt;sql_fetchrow($result); $db-&gt;sql_freeresult($result); $sql = 'UPDATE ' . FORUMS_TABLE . ' SET left_id = left_id + 2, right_id = right_id + 2 WHERE left_id &gt; ' . $row['right_id']; $db-&gt;sql_query($sql); $sql = 'UPDATE ' . FORUMS_TABLE . ' SET right_id = right_id + 2 WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id'; $db-&gt;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-&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(); print_r($response); return $response; } } </code></pre> <p><a href="/questions/tagged/phpbb" class="post-tag" title="show questions tagged 'phpbb'" rel="tag">phpbb</a><a href="/questions/tagged/phpbb3" class="post-tag" title="show questions tagged 'phpbb3'" rel="tag">phpbb3</a><a href="/questions/tagged/phpbb3.0.10" class="post-tag" title="show questions tagged 'phpbb3.0.10'" rel="tag">phpbb3.0.10</a><a href="/questions/tagged/php" class="post-tag" title="show questions tagged 'php'" rel="tag">php</a></p>
 

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