function spa_setup_permissions()
{
    # Create default role data
    # NOTE that the auths do not use action names like this, but its pretty unreadable the way its stored
    # so use action names here for readability and maintainability. we will convert the actions to auths before storing
    $actions = array();
    $actions['Can view forum'] = 0;
    $actions['Can view forum lists only'] = 0;
    $actions['Can view forum and topic lists only'] = 0;
    $actions['Can view forum and topic lists only'] = 0;
    $actions['Can view admin posts'] = 0;
    $actions['Can view only own posts and admin/mod posts'] = 0;
    $actions['Can start new topics'] = 0;
    $actions['Can reply to topics'] = 0;
    $actions['Can reply to topics'] = 0;
    $actions['Can only reply to own topics'] = 0;
    $actions['Can bypass wait time between posts'] = 0;
    $actions['Can edit own topic titles'] = 0;
    $actions['Can pin topics'] = 0;
    $actions['Can move topics'] = 0;
    $actions['Can move posts'] = 0;
    $actions['Can lock topics'] = 0;
    $actions['Can delete topics'] = 0;
    $actions['Can edit own posts forever'] = 0;
    $actions['Can edit own posts until reply'] = 0;
    $actions['Can edit any posts'] = 0;
    $actions['Can delete own posts'] = 0;
    $actions['Can delete any post'] = 0;
    $actions['Can pin posts'] = 0;
    $actions['Can reassign posts'] = 0;
    $actions['Can view users email addresses'] = 0;
    $actions['Can view members profiles'] = 0;
    $actions['Can view members lists'] = 0;
    $actions['Can sort most recent posts'] = 0;
    $actions['Can bypass math question'] = 0;
    $actions['Can bypass post moderation'] = 0;
    $actions['Can bypass post moderation once'] = 0;
    $actions['Can use signatures'] = 0;
    $actions['Can upload avatars'] = 0;
    $actions['Can use spoilers'] = 0;
    $actions['Can view links'] = 0;
    $actions['Can moderate pending posts'] = 0;
    $actions['Can create links'] = 0;
    $role_name = 'No Access';
    $role_desc = 'Permission with no access to any Forum features';
    $new_actions = spa_convert_action_to_auth($actions);
    spa_create_role_row($role_name, $role_desc, serialize($new_actions));
    $actions = array();
    $actions['Can view forum'] = 1;
    $actions['Can view forum lists only'] = 0;
    $actions['Can view forum and topic lists only'] = 0;
    $actions['Can view admin posts'] = 1;
    $actions['Can view only own posts and admin/mod posts'] = 0;
    $actions['Can start new topics'] = 0;
    $actions['Can reply to topics'] = 0;
    $actions['Can only reply to own topics'] = 0;
    $actions['Can bypass wait time between posts'] = 0;
    $actions['Can edit own topic titles'] = 0;
    $actions['Can edit any topic titles'] = 0;
    $actions['Can pin topics'] = 0;
    $actions['Can move topics'] = 0;
    $actions['Can move posts'] = 0;
    $actions['Can lock topics'] = 0;
    $actions['Can delete topics'] = 0;
    $actions['Can edit own posts forever'] = 0;
    $actions['Can edit own posts until reply'] = 0;
    $actions['Can edit any posts'] = 0;
    $actions['Can delete own posts'] = 0;
    $actions['Can delete any post'] = 0;
    $actions['Can pin posts'] = 0;
    $actions['Can reassign posts'] = 0;
    $actions['Can view users email addresses'] = 0;
    $actions['Can view members profiles'] = 0;
    $actions['Can view members lists'] = 0;
    $actions['Can sort most recent posts'] = 0;
    $actions['Can bypass math question'] = 0;
    $actions['Can bypass post moderation'] = 0;
    $actions['Can bypass post moderation once'] = 0;
    $actions['Can use signatures'] = 0;
    $actions['Can upload avatars'] = 0;
    $actions['Can use spoilers'] = 1;
    $actions['Can view links'] = 1;
    $actions['Can moderate pending posts'] = 0;
    $actions['Can create links'] = 0;
    $role_name = 'Read Only Access';
    $role_desc = 'Permission with access to only view the Forum';
    $new_actions = spa_convert_action_to_auth($actions);
    spa_create_role_row($role_name, $role_desc, serialize($new_actions));
    $actions = array();
    $actions['Can view forum'] = 1;
    $actions['Can view forum lists only'] = 0;
    $actions['Can view forum and topic lists only'] = 0;
    $actions['Can view admin posts'] = 1;
    $actions['Can view only own posts and admin/mod posts'] = 0;
    $actions['Can start new topics'] = 1;
    $actions['Can reply to topics'] = 1;
    $actions['Can only reply to own topics'] = 0;
    $actions['Can bypass wait time between posts'] = 0;
    $actions['Can edit own topic titles'] = 0;
    $actions['Can edit any topic titles'] = 0;
    $actions['Can pin topics'] = 0;
    $actions['Can move topics'] = 0;
    $actions['Can move posts'] = 0;
    $actions['Can lock topics'] = 0;
    $actions['Can delete topics'] = 0;
    $actions['Can edit own posts forever'] = 0;
    $actions['Can edit own posts until reply'] = 0;
    $actions['Can edit any posts'] = 0;
    $actions['Can delete own posts'] = 0;
    $actions['Can delete any post'] = 0;
    $actions['Can pin posts'] = 0;
    $actions['Can reassign posts'] = 0;
    $actions['Can view users email addresses'] = 0;
    $actions['Can view members profiles'] = 1;
    $actions['Can view members lists'] = 1;
    $actions['Can sort most recent posts'] = 0;
    $actions['Can bypass math question'] = 0;
    $actions['Can bypass post moderation'] = 0;
    $actions['Can bypass post moderation once'] = 0;
    $actions['Can use signatures'] = 0;
    $actions['Can upload avatars'] = 1;
    $actions['Can use spoilers'] = 1;
    $actions['Can view links'] = 1;
    $actions['Can moderate pending posts'] = 0;
    $actions['Can create links'] = 1;
    $role_name = 'Limited Access';
    $role_desc = 'Permission with access to reply and start topics but with limited features';
    $new_actions = spa_convert_action_to_auth($actions);
    spa_create_role_row($role_name, $role_desc, serialize($new_actions));
    $actions = array();
    $actions['Can view forum'] = 1;
    $actions['Can view forum lists only'] = 0;
    $actions['Can view forum and topic lists only'] = 0;
    $actions['Can view admin posts'] = 1;
    $actions['Can view only own posts and admin/mod posts'] = 0;
    $actions['Can start new topics'] = 1;
    $actions['Can reply to topics'] = 1;
    $actions['Can only reply to own topics'] = 0;
    $actions['Can bypass wait time between posts'] = 0;
    $actions['Can edit own topic titles'] = 0;
    $actions['Can edit any topic titles'] = 0;
    $actions['Can pin topics'] = 0;
    $actions['Can move topics'] = 0;
    $actions['Can move posts'] = 0;
    $actions['Can lock topics'] = 0;
    $actions['Can delete topics'] = 0;
    $actions['Can edit own posts forever'] = 0;
    $actions['Can edit own posts until reply'] = 1;
    $actions['Can edit any posts'] = 0;
    $actions['Can delete own posts'] = 0;
    $actions['Can delete any post'] = 0;
    $actions['Can pin posts'] = 0;
    $actions['Can reassign posts'] = 0;
    $actions['Can view users email addresses'] = 0;
    $actions['Can view members profiles'] = 1;
    $actions['Can view members lists'] = 1;
    $actions['Can sort most recent posts'] = 0;
    $actions['Can bypass math question'] = 0;
    $actions['Can bypass post moderation'] = 1;
    $actions['Can bypass post moderation once'] = 1;
    $actions['Can use signatures'] = 1;
    $actions['Can upload avatars'] = 1;
    $actions['Can use spoilers'] = 1;
    $actions['Can view links'] = 1;
    $actions['Can moderate pending posts'] = 0;
    $actions['Can create links'] = 1;
    $role_name = 'Standard Access';
    $role_desc = 'Permission with access to reply and start topics with advanced features such as signatures';
    $new_actions = spa_convert_action_to_auth($actions);
    spa_create_role_row($role_name, $role_desc, serialize($new_actions));
    $actions = array();
    $actions['Can view forum'] = 1;
    $actions['Can view forum lists only'] = 0;
    $actions['Can view forum and topic lists only'] = 0;
    $actions['Can view admin posts'] = 1;
    $actions['Can view only own posts and admin/mod posts'] = 0;
    $actions['Can start new topics'] = 1;
    $actions['Can reply to topics'] = 1;
    $actions['Can only reply to own topics'] = 0;
    $actions['Can bypass wait time between posts'] = 1;
    $actions['Can edit own topic titles'] = 1;
    $actions['Can edit any topic titles'] = 0;
    $actions['Can pin topics'] = 0;
    $actions['Can move topics'] = 0;
    $actions['Can move posts'] = 0;
    $actions['Can lock topics'] = 0;
    $actions['Can delete topics'] = 0;
    $actions['Can edit own posts forever'] = 1;
    $actions['Can edit own posts until reply'] = 1;
    $actions['Can edit any posts'] = 0;
    $actions['Can delete own posts'] = 0;
    $actions['Can delete any post'] = 0;
    $actions['Can pin posts'] = 0;
    $actions['Can reassign posts'] = 0;
    $actions['Can view users email addresses'] = 0;
    $actions['Can view members profiles'] = 1;
    $actions['Can view members lists'] = 1;
    $actions['Can sort most recent posts'] = 0;
    $actions['Can bypass math question'] = 1;
    $actions['Can bypass post moderation'] = 1;
    $actions['Can bypass post moderation once'] = 1;
    $actions['Can use signatures'] = 1;
    $actions['Can upload avatars'] = 1;
    $actions['Can use spoilers'] = 1;
    $actions['Can view links'] = 1;
    $actions['Can moderate pending posts'] = 0;
    $actions['Can create links'] = 1;
    $role_name = 'Full Access';
    $role_desc = 'Permission with Standard Access features and math question bypass';
    $new_actions = spa_convert_action_to_auth($actions);
    spa_create_role_row($role_name, $role_desc, serialize($new_actions));
    $actions = array();
    $actions['Can view forum'] = 1;
    $actions['Can view forum lists only'] = 0;
    $actions['Can view forum and topic lists only'] = 0;
    $actions['Can view admin posts'] = 1;
    $actions['Can view only own posts and admin/mod posts'] = 0;
    $actions['Can start new topics'] = 1;
    $actions['Can reply to topics'] = 1;
    $actions['Can only reply to own topics'] = 0;
    $actions['Can bypass wait time between posts'] = 1;
    $actions['Can edit any topic titles'] = 1;
    $actions['Can edit own topic titles'] = 1;
    $actions['Can pin topics'] = 1;
    $actions['Can move topics'] = 1;
    $actions['Can move posts'] = 1;
    $actions['Can lock topics'] = 1;
    $actions['Can delete topics'] = 1;
    $actions['Can edit own posts forever'] = 1;
    $actions['Can edit own posts until reply'] = 1;
    $actions['Can edit any posts'] = 1;
    $actions['Can delete own posts'] = 0;
    $actions['Can delete any post'] = 1;
    $actions['Can pin posts'] = 1;
    $actions['Can reassign posts'] = 1;
    $actions['Can view users email addresses'] = 1;
    $actions['Can view members profiles'] = 1;
    $actions['Can view members lists'] = 1;
    $actions['Can sort most recent posts'] = 1;
    $actions['Can bypass math question'] = 1;
    $actions['Can bypass post moderation'] = 1;
    $actions['Can bypass post moderation once'] = 1;
    $actions['Can use signatures'] = 1;
    $actions['Can upload avatars'] = 1;
    $actions['Can use spoilers'] = 1;
    $actions['Can view links'] = 1;
    $actions['Can moderate pending posts'] = 1;
    $actions['Can create links'] = 1;
    $role_name = 'Moderator Access';
    $role_desc = 'Permission with access to all Forum features';
    $new_actions = spa_convert_action_to_auth($actions);
    spa_create_role_row($role_name, $role_desc, serialize($new_actions));
}
function sp_convert_perms_to_auths()
{
    if (!spdb_column_exists(SFMEMBERS, 'auths')) {
        spdb_query('ALTER TABLE ' . SFMEMBERS . ' ADD (auths longtext)');
    }
    spdb_query('ALTER TABLE ' . SFROLES . ' CHANGE role_actions role_auths longtext');
    # populate with existing permissions
    spa_setup_auths();
    # now we need to convert existing roles
    $roles = spdb_table(SFROLES);
    if ($roles) {
        foreach ($roles as $role) {
            $actions = unserialize($role->role_auths);
            if ($actions) {
                $new_actions = spa_convert_action_to_auth($actions);
                spdb_query('UPDATE ' . SFROLES . " SET role_auths='" . serialize($new_actions) . "' WHERE role_id={$role->role_id}");
            }
        }
    }
}
function spa_setup_permissions()
{
    # Create default role data
    # NOTE that the auths do not use action names like this, but its pretty unreadable the way its stored
    # so use action names here for readability and maintainability. we will convert the actions to auths before storing
    $actions = array();
    $actions['Can view forum'] = 0;
    $actions['Can view a list of forums only'] = 0;
    $actions['Can view a list of forums and list of topics only'] = 0;
    $actions['Can view posts by an administrator'] = 0;
    $actions['Can view only own posts and admin/mod posts'] = 0;
    $actions['Can view email and IP addresses of members'] = 0;
    $actions['Can view profiles of members'] = 0;
    $actions['Can view the members lists'] = 0;
    $actions['Can view links within posts'] = 0;
    $actions['Can start new topics in a forum'] = 0;
    $actions['Can reply to existing topics in a forum'] = 0;
    $actions['Can only reply to own topics'] = 0;
    $actions['Can bypass wait time between posts'] = 0;
    $actions['Can use spoilers in posts'] = 0;
    $actions['Can attach a signature to posts'] = 0;
    $actions['Can create links in posts'] = 0;
    $actions['Can use smileys in posts'] = 0;
    $actions['Can use iframes in posts'] = 0;
    $actions['Can edit own topic titles'] = 0;
    $actions['Can edit any topic title'] = 0;
    $actions['Can edit own posts for time period'] = 0;
    $actions['Can edit own posts forever'] = 0;
    $actions['Can edit own posts until there has been a reply'] = 0;
    $actions['Can edit any post'] = 0;
    $actions['Can delete topics in forum'] = 0;
    $actions['Can delete own posts'] = 0;
    $actions['Can delete any post'] = 0;
    $actions['Can bypass the math question'] = 0;
    $actions['Can bypass all post moderation'] = 0;
    $actions['Can bypass first post moderation'] = 0;
    $actions['Can moderate pending posts'] = 0;
    $actions['Can pin topics in a forum'] = 0;
    $actions['Can move topics from a forum'] = 0;
    $actions['Can move posts from a topic'] = 0;
    $actions['Can lock topics in a forum'] = 0;
    $actions['Can pin posts within a topic'] = 0;
    $actions['Can reassign posts to a different user'] = 0;
    $actions['Can upload avatars'] = 0;
    $role_name = 'No Access';
    $role_desc = 'Permission with no access to any Forum features';
    $new_actions = spa_convert_action_to_auth($actions);
    spa_create_role_row($role_name, $role_desc, serialize($new_actions));
    $actions = array();
    $actions['Can view forum'] = 1;
    $actions['Can view a list of forums only'] = 0;
    $actions['Can view a list of forums and list of topics only'] = 0;
    $actions['Can view posts by an administrator'] = 1;
    $actions['Can view only own posts and admin/mod posts'] = 0;
    $actions['Can view email and IP addresses of members'] = 0;
    $actions['Can view profiles of members'] = 0;
    $actions['Can view the members lists'] = 0;
    $actions['Can view links within posts'] = 1;
    $actions['Can start new topics in a forum'] = 0;
    $actions['Can reply to existing topics in a forum'] = 0;
    $actions['Can only reply to own topics'] = 0;
    $actions['Can bypass wait time between posts'] = 0;
    $actions['Can use spoilers in posts'] = 1;
    $actions['Can attach a signature to posts'] = 0;
    $actions['Can create links in posts'] = 0;
    $actions['Can use smileys in posts'] = 0;
    $actions['Can use iframes in posts'] = 0;
    $actions['Can edit own topic titles'] = 0;
    $actions['Can edit any topic title'] = 0;
    $actions['Can edit own posts for time period'] = 0;
    $actions['Can edit own posts forever'] = 0;
    $actions['Can edit own posts until there has been a reply'] = 0;
    $actions['Can edit any post'] = 0;
    $actions['Can delete topics in forum'] = 0;
    $actions['Can delete own posts'] = 0;
    $actions['Can delete any post'] = 0;
    $actions['Can bypass the math question'] = 0;
    $actions['Can bypass all post moderation'] = 0;
    $actions['Can bypass first post moderation'] = 0;
    $actions['Can moderate pending posts'] = 0;
    $actions['Can pin topics in a forum'] = 0;
    $actions['Can move topics from a forum'] = 0;
    $actions['Can move posts from a topic'] = 0;
    $actions['Can lock topics in a forum'] = 0;
    $actions['Can pin posts within a topic'] = 0;
    $actions['Can reassign posts to a different user'] = 0;
    $actions['Can upload avatars'] = 0;
    $role_name = 'Read Only Access';
    $role_desc = 'Permission with access to only view the Forum';
    $new_actions = spa_convert_action_to_auth($actions);
    spa_create_role_row($role_name, $role_desc, serialize($new_actions));
    $actions = array();
    $actions['Can view forum'] = 1;
    $actions['Can view a list of forums only'] = 0;
    $actions['Can view a list of forums and list of topics only'] = 0;
    $actions['Can view posts by an administrator'] = 1;
    $actions['Can view only own posts and admin/mod posts'] = 0;
    $actions['Can view email and IP addresses of members'] = 0;
    $actions['Can view profiles of members'] = 1;
    $actions['Can view the members lists'] = 1;
    $actions['Can view links within posts'] = 1;
    $actions['Can start new topics in a forum'] = 1;
    $actions['Can reply to existing topics in a forum'] = 1;
    $actions['Can only reply to own topics'] = 0;
    $actions['Can bypass wait time between posts'] = 0;
    $actions['Can use spoilers in posts'] = 1;
    $actions['Can attach a signature to posts'] = 0;
    $actions['Can create links in posts'] = 1;
    $actions['Can use smileys in posts'] = 1;
    $actions['Can use iframes in posts'] = 0;
    $actions['Can edit own topic titles'] = 0;
    $actions['Can edit any topic title'] = 0;
    $actions['Can edit own posts for time period'] = 0;
    $actions['Can edit own posts forever'] = 0;
    $actions['Can edit own posts until there has been a reply'] = 0;
    $actions['Can edit any post'] = 0;
    $actions['Can delete topics in forum'] = 0;
    $actions['Can delete own posts'] = 0;
    $actions['Can delete any post'] = 0;
    $actions['Can bypass the math question'] = 0;
    $actions['Can bypass all post moderation'] = 0;
    $actions['Can bypass first post moderation'] = 0;
    $actions['Can moderate pending posts'] = 0;
    $actions['Can pin topics in a forum'] = 0;
    $actions['Can move topics from a forum'] = 0;
    $actions['Can move posts from a topic'] = 0;
    $actions['Can lock topics in a forum'] = 0;
    $actions['Can pin posts within a topic'] = 0;
    $actions['Can reassign posts to a different user'] = 0;
    $actions['Can upload avatars'] = 1;
    $role_name = 'Limited Access';
    $role_desc = 'Permission with access to reply and start topics but with limited features';
    $new_actions = spa_convert_action_to_auth($actions);
    spa_create_role_row($role_name, $role_desc, serialize($new_actions));
    $actions = array();
    $actions['Can view forum'] = 1;
    $actions['Can view a list of forums only'] = 0;
    $actions['Can view a list of forums and list of topics only'] = 0;
    $actions['Can view posts by an administrator'] = 1;
    $actions['Can view only own posts and admin/mod posts'] = 0;
    $actions['Can view email and IP addresses of members'] = 0;
    $actions['Can view profiles of members'] = 1;
    $actions['Can view the members lists'] = 1;
    $actions['Can view links within posts'] = 1;
    $actions['Can start new topics in a forum'] = 1;
    $actions['Can reply to existing topics in a forum'] = 1;
    $actions['Can only reply to own topics'] = 0;
    $actions['Can bypass wait time between posts'] = 0;
    $actions['Can use spoilers in posts'] = 1;
    $actions['Can attach a signature to posts'] = 1;
    $actions['Can create links in posts'] = 1;
    $actions['Can use smileys in posts'] = 1;
    $actions['Can use iframes in posts'] = 0;
    $actions['Can edit own topic titles'] = 0;
    $actions['Can edit any topic title'] = 0;
    $actions['Can edit own posts for time period'] = 0;
    $actions['Can edit own posts forever'] = 0;
    $actions['Can edit own posts until there has been a reply'] = 1;
    $actions['Can edit any post'] = 0;
    $actions['Can delete topics in forum'] = 0;
    $actions['Can delete own posts'] = 0;
    $actions['Can delete any post'] = 0;
    $actions['Can bypass the math question'] = 0;
    $actions['Can bypass all post moderation'] = 1;
    $actions['Can bypass first post moderation'] = 1;
    $actions['Can moderate pending posts'] = 0;
    $actions['Can pin topics in a forum'] = 0;
    $actions['Can move topics from a forum'] = 0;
    $actions['Can move posts from a topic'] = 0;
    $actions['Can lock topics in a forum'] = 0;
    $actions['Can pin posts within a topic'] = 0;
    $actions['Can reassign posts to a different user'] = 0;
    $actions['Can upload avatars'] = 1;
    $role_name = 'Standard Access';
    $role_desc = 'Permission with access to reply and start topics with advanced features such as signatures';
    $new_actions = spa_convert_action_to_auth($actions);
    spa_create_role_row($role_name, $role_desc, serialize($new_actions));
    $actions = array();
    $actions['Can view forum'] = 1;
    $actions['Can view a list of forums only'] = 0;
    $actions['Can view a list of forums and list of topics only'] = 0;
    $actions['Can view posts by an administrator'] = 1;
    $actions['Can view only own posts and admin/mod posts'] = 0;
    $actions['Can view email and IP addresses of members'] = 0;
    $actions['Can view profiles of members'] = 1;
    $actions['Can view the members lists'] = 1;
    $actions['Can view links within posts'] = 1;
    $actions['Can start new topics in a forum'] = 1;
    $actions['Can reply to existing topics in a forum'] = 1;
    $actions['Can only reply to own topics'] = 0;
    $actions['Can bypass wait time between posts'] = 1;
    $actions['Can use spoilers in posts'] = 1;
    $actions['Can attach a signature to posts'] = 1;
    $actions['Can create links in posts'] = 1;
    $actions['Can use smileys in posts'] = 1;
    $actions['Can use iframes in posts'] = 0;
    $actions['Can edit own topic titles'] = 1;
    $actions['Can edit any topic title'] = 0;
    $actions['Can edit own posts for time period'] = 0;
    $actions['Can edit own posts forever'] = 1;
    $actions['Can edit own posts until there has been a reply'] = 1;
    $actions['Can edit any post'] = 0;
    $actions['Can delete topics in forum'] = 0;
    $actions['Can delete own posts'] = 0;
    $actions['Can delete any post'] = 0;
    $actions['Can bypass the math question'] = 1;
    $actions['Can bypass all post moderation'] = 1;
    $actions['Can bypass first post moderation'] = 1;
    $actions['Can moderate pending posts'] = 0;
    $actions['Can pin topics in a forum'] = 0;
    $actions['Can move topics from a forum'] = 0;
    $actions['Can move posts from a topic'] = 0;
    $actions['Can lock topics in a forum'] = 0;
    $actions['Can pin posts within a topic'] = 0;
    $actions['Can reassign posts to a different user'] = 0;
    $actions['Can upload avatars'] = 1;
    $role_name = 'Full Access';
    $role_desc = 'Permission with Standard Access features and math question bypass';
    $new_actions = spa_convert_action_to_auth($actions);
    spa_create_role_row($role_name, $role_desc, serialize($new_actions));
    //==>
    $actions = array();
    $actions['Can view forum'] = 1;
    $actions['Can view a list of forums only'] = 0;
    $actions['Can view a list of forums and list of topics only'] = 0;
    $actions['Can view posts by an administrator'] = 1;
    $actions['Can view only own posts and admin/mod posts'] = 0;
    $actions['Can view email and IP addresses of members'] = 1;
    $actions['Can view profiles of members'] = 1;
    $actions['Can view the members lists'] = 1;
    $actions['Can view links within posts'] = 1;
    $actions['Can start new topics in a forum'] = 1;
    $actions['Can reply to existing topics in a forum'] = 1;
    $actions['Can only reply to own topics'] = 0;
    $actions['Can bypass wait time between posts'] = 1;
    $actions['Can use spoilers in posts'] = 1;
    $actions['Can attach a signature to posts'] = 1;
    $actions['Can create links in posts'] = 1;
    $actions['Can use smileys in posts'] = 1;
    $actions['Can use iframes in posts'] = 0;
    $actions['Can edit own topic titles'] = 1;
    $actions['Can edit any topic title'] = 1;
    $actions['Can edit own posts for time period'] = 0;
    $actions['Can edit own posts forever'] = 1;
    $actions['Can edit own posts until there has been a reply'] = 1;
    $actions['Can edit any post'] = 1;
    $actions['Can delete topics in forum'] = 1;
    $actions['Can delete own posts'] = 0;
    $actions['Can delete any post'] = 1;
    $actions['Can bypass the math question'] = 1;
    $actions['Can bypass all post moderation'] = 1;
    $actions['Can bypass first post moderation'] = 1;
    $actions['Can moderate pending posts'] = 1;
    $actions['Can pin topics in a forum'] = 1;
    $actions['Can move topics from a forum'] = 1;
    $actions['Can move posts from a topic'] = 1;
    $actions['Can lock topics in a forum'] = 1;
    $actions['Can pin posts within a topic'] = 1;
    $actions['Can reassign posts to a different user'] = 1;
    $actions['Can upload avatars'] = 1;
    $role_name = 'Moderator Access';
    $role_desc = 'Permission with access to all Forum features';
    $new_actions = spa_convert_action_to_auth($actions);
    spa_create_role_row($role_name, $role_desc, serialize($new_actions));
}
function sp_convert_perms_to_auths()
{
    if (!spdb_column_exists(SFMEMBERS, 'auths')) {
        spdb_query('ALTER TABLE ' . SFMEMBERS . ' ADD (auths longtext)');
    }
    spdb_query('ALTER TABLE ' . SFROLES . ' CHANGE role_actions role_auths longtext');
    # populate with existing permissions
    sp_add_auth('view_forum', esc_sql(spa_text_noesc('Can view a forum')), 1, 0, 0);
    sp_add_auth('view_forum_lists', esc_sql(spa_text_noesc('Can view a list of forums only')), 1, 0, 0);
    sp_add_auth('view_forum_topic_lists', esc_sql(spa_text_noesc('Can view a list of forums and list of topics only')), 1, 0, 0);
    sp_add_auth('view_admin_posts', esc_sql(spa_text_noesc('Can view posts by an administrator')), 1, 0, 0);
    sp_add_auth('start_topics', esc_sql(spa_text_noesc('Can start new topics in a forum')), 1, 0, 0);
    sp_add_auth('reply_topics', esc_sql(spa_text_noesc('Can reply to existing topics in a forum')), 1, 0, 0);
    sp_add_auth('edit_own_topic_titles', esc_sql(spa_text_noesc('Can edit own topic titles')), 1, 0, 0);
    sp_add_auth('edit_any_topic_titles', esc_sql(spa_text_noesc('Can edit any topic title')), 1, 0, 0);
    sp_add_auth('pin_topics', esc_sql(spa_text_noesc('Can pin topics in a forum')), 1, 0, 0);
    sp_add_auth('move_topics', esc_sql(spa_text_noesc('Can move topics from a forum')), 1, 0, 0);
    sp_add_auth('move_posts', esc_sql(spa_text_noesc('Can move posts from a topic')), 1, 0, 0);
    sp_add_auth('lock_topics', esc_sql(spa_text_noesc('Can lock topics in a forum')), 1, 0, 0);
    sp_add_auth('delete_topics', esc_sql(spa_text_noesc('Can delete topics in forum')), 1, 0, 0);
    sp_add_auth('edit_own_posts_forever', esc_sql(spa_text_noesc('Can edit own posts forever')), 1, 0, 0);
    sp_add_auth('edit_own_posts_reply', esc_sql(spa_text_noesc('Can edit own posts until there has been a reply')), 1, 0, 0);
    sp_add_auth('edit_any_post', esc_sql(spa_text_noesc('Can edit any post')), 1, 0, 0);
    sp_add_auth('delete_own_posts', esc_sql(spa_text_noesc('Can delete own posts')), 1, 0, 0);
    sp_add_auth('delete_any_post', esc_sql(spa_text_noesc('Can delete any post')), 1, 0, 0);
    sp_add_auth('pin_posts', esc_sql(spa_text_noesc('Can pin posts within a topic')), 1, 0, 0);
    sp_add_auth('reassign_posts', esc_sql(spa_text_noesc('Can reassign posts to a different user')), 1, 0, 0);
    sp_add_auth('view_email', esc_sql(spa_text_noesc('Can view email and IP addresses of members')), 1, 0, 0);
    sp_add_auth('view_profiles', esc_sql(spa_text_noesc('Can view profiles of members')), 1, 0, 0);
    sp_add_auth('view_members_list', esc_sql(spa_text_noesc('Can view the members lists')), 1, 0, 0);
    sp_add_auth('report_posts', esc_sql(spa_text_noesc('Can report a post to administrators')), 1, 0, 0);
    sp_add_auth('bypass_math_question', esc_sql(spa_text_noesc('Can bypass the math question')), 1, 0, 0);
    sp_add_auth('bypass_moderation', esc_sql(spa_text_noesc('Can bypass all post moderation')), 1, 0, 0);
    sp_add_auth('bypass_moderation_once', esc_sql(spa_text_noesc('Can bypass first post moderation')), 1, 0, 0);
    sp_add_auth('moderate_posts', esc_sql(spa_text_noesc('Can moderate pending posts')), 1, 0, 0);
    sp_add_auth('use_spoilers', esc_sql(spa_text_noesc('Can use spoilers in posts')), 1, 0, 0);
    sp_add_auth('view_links', esc_sql(spa_text_noesc('Can view links within posts')), 1, 0, 0);
    sp_add_auth('upload_images', esc_sql(spa_text_noesc('Can upload images in posts')), 1, 1, 0);
    sp_add_auth('upload_media', esc_sql(spa_text_noesc('Can upload media in posts')), 1, 1, 0);
    sp_add_auth('upload_files', esc_sql(spa_text_noesc('Can upload other files in posts')), 1, 1, 0);
    sp_add_auth('use_signatures', esc_sql(spa_text_noesc('Can attach a signature to posts')), 1, 1, 0);
    sp_add_auth('upload_signatures', esc_sql(spa_text_noesc('Can upload signature images')), 1, 1, 0);
    sp_add_auth('upload_avatars', esc_sql(spa_text_noesc('Can upload avatars')), 1, 1, 1);
    sp_add_auth('subscribe', esc_sql(spa_text_noesc('Can subscribe to topics within a forum')), 0, 1, 0);
    sp_add_auth('watch', esc_sql(spa_text_noesc('Can watch topics within a forum')), 0, 1, 0);
    sp_add_auth('change_topic_status', esc_sql(spa_text_noesc('Can change the status of a topic')), 1, 1, 0);
    sp_add_auth('rate_posts', esc_sql(spa_text_noesc('Can rate a post')), 0, 1, 0);
    sp_add_auth('use_pm', esc_sql(spa_text_noesc('Can use the private messaging system')), 0, 1, 1);
    # now we need to convert existing roles
    $roles = spdb_table(SFROLES);
    if ($roles) {
        foreach ($roles as $role) {
            $actions = unserialize($role->role_auths);
            if ($actions) {
                $new_actions = spa_convert_action_to_auth($actions);
                spdb_query('UPDATE ' . SFROLES . " SET role_auths='" . serialize($new_actions) . "' WHERE role_id={$role->role_id}");
            }
        }
    }
}