title: phpBB3 - How to create and manage groups dynamically?
body: <p>I have a system in which users can register with my forum via the website using PHP. I now need the ability to assign them to groups when this happens... or in some cases create a new group and assign them to it.</p>
  
  <p>I've had a look around the phpBB files but cannot figure out which parts of the scripts are responsible for this work.</p>
  
  <p>Basically I need the following operations:</p>
  
  <ul>
  <li>Ability to dynamically create a group</li>
  <li>Ability to add user to a group</li>
  <li>Ability to set group permissions for a forum</li>
  </ul>
  
  <p>This all has to be dynamic as the system needs to be automated and not managed via the ACP.</p>
  
  <p>If anyone could point me in the right direction for these that would be great.</p>
  
  <hr>
  
  <p><strong>Solved - 13/03/2012</strong></p>
  
  <p>Here's the solution I came up with utlising <code>group_create()</code> from <code>includes/functions_user.php</code>.</p>
  
  <pre><code>$group_id = FALSE; // can be 0 as well
  $group_type = GROUP_HIDDEN;
  $group_name = "Tom's Group";
  $group_desc = "Users from Tom's Group";
  
  // just leave these as defaults
  $group_attributes = array(
      //'group_colour' =&gt; 0,
      //'group_rank' =&gt; 0, 
      //'group_avatar' =&gt; 0, 
      //'group_avatar_type' =&gt; 0,
      //'group_avatar_width' =&gt; 0,
      //'group_avatar_height' =&gt; 0,
      'group_legend' =&gt; 0,
  );
  
  $allow_desc_bbcode = TRUE;
  $allow_desc_urls = TRUE;
  $allow_desc_smilies = TRUE;
  
  $response = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies);
  </code></pre>
  
  <p>Note that if you set <code>$group_id</code> as an existing group in your database then it will modify that group.
  I also set <code>group_legend</code> as <code>0</code> because I don't want hidden groups to be seen on the forum. </p>