function spa_check_warnings()
{
    global $spGlobals;
    # not perfect but we can use this call tyo perform any minor
    # cleanups that may be necessary... so
    # drop any existing temp members table...
    spdb_query('DROP TABLE IF EXISTS sftempmembers');
    $mess = '';
    # check if sp core, plugins or themes update available
    $update = false;
    $update_msg = '';
    $up = get_site_transient('update_plugins');
    if (!empty($up->response)) {
        foreach ($up->response as $plugin) {
            if ($plugin->slug == 'simple-press') {
                $msg = apply_filters('sph_core_update_notice', spa_text('There is a Simple:Press core update available.'));
                if (!empty($msg)) {
                    $update = true;
                    $update_msg .= $msg . '<br />';
                }
                break;
            }
        }
    }
    $up = get_site_transient('sp_update_plugins');
    if (!empty($up)) {
        $msg = apply_filters('sph_plugins_update_notice', spa_text('There is one or more Simple:Press plugin updates available'));
        if (!empty($msg)) {
            $update = true;
            $update_msg .= $msg . '<br />';
        }
    }
    $up = get_site_transient('sp_update_themes');
    if (!empty($up)) {
        $msg = apply_filters('sph_themes_update_notice', spa_text('There is one or more Simple:Press theme updates available'));
        if (!empty($msg)) {
            $update = true;
            $update_msg .= $msg . '<br />';
        }
    }
    if ($update) {
        if (is_main_site()) {
            $mess .= apply_filters('sph_updates_notice', spa_message($update_msg . '<a href="' . self_admin_url('update-core.php') . '">' . spa_text('Click here to view any updates.') . '</a>'));
        } else {
            $mess .= apply_filters('sph_updates_notice', spa_message(spa_text('There are some Simple:Press updates avaialable. You may want to notify the network site admin.')));
        }
    }
    # output warning if no SPF admins are defined
    $a = $spGlobals['forum-admins'];
    if (empty($a)) {
        $mess .= spa_message(spa_text('Warning - There are no SPF admins defined!	 All WP admins now have SP backend access'), 'error');
    }
    # Check if	desktop, tablet and mobile themes are selected and available
    $cur = sp_get_option('sp_current_theme');
    if (empty($cur)) {
        $mess .= spa_message(spa_text('No main theme has been selected and SP will be unable to display correctly. Please select a theme from the Themes panel'), 'error');
    } else {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $cur['theme'] . '/styles/' . $cur['style']);
        $nooverlay = !empty($cur['color']) && !file_exists(SPTHEMEBASEDIR . $cur['theme'] . '/styles/overlays/' . $cur['color'] . '.php');
        $nopoverlay = !empty($cur['color']) && !empty($cur['parent']) && !file_exists(SPTHEMEBASEDIR . $cur['parent'] . '/styles/overlays/' . $cur['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the theme CSS file and/or color Overlay file from the selected theme is missing'), 'error');
        }
    }
    $mobile = sp_get_option('sp_mobile_theme');
    if (!empty($mobile) && $mobile['active']) {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $mobile['theme'] . '/styles/' . $mobile['style']);
        $nooverlay = !empty($mobile['color']) && !file_exists(SPTHEMEBASEDIR . $mobile['theme'] . '/styles/overlays/' . $mobile['color'] . '.php');
        $nopoverlay = !empty($mobile['color']) && !empty($mobile['parent']) && !file_exists(SPTHEMEBASEDIR . $mobile['parent'] . '/styles/overlays/' . $mobile['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the mobile theme CSS file and/or color Overlay file from the selected mobile theme is missing'), 'error');
        }
    }
    $tablet = sp_get_option('sp_tablet_theme');
    if (!empty($tablet) && $tablet['active']) {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $tablet['theme'] . '/styles/' . $tablet['style']);
        $nooverlay = !empty($tablet['color']) && !file_exists(SPTHEMEBASEDIR . $tablet['theme'] . '/styles/overlays/' . $tablet['color'] . '.php');
        $nopoverlay = !empty($tablet['color']) && !empty($tablet['parent']) && !file_exists(SPTHEMEBASEDIR . $tablet['parent'] . '/styles/overlays/' . $tablet['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the tablet theme CSS file and/or color Overlay file from the selected tablet theme is missing'), 'error');
        }
    }
    # check for missing default members user group
    $value = sp_get_sfmeta('default usergroup', 'sfmembers');
    $ugid = spdb_table(SFUSERGROUPS, "usergroup_id={$value[0]['meta_value']}", 'usergroup_id');
    if (empty($ugid)) {
        $mess .= spa_message(spa_text('Warning - The default user group for new members is undefined!	Please visit the SP usergroups admin page, map users to usergroups tab and set the default user group'), 'error');
    }
    # check for missing default guest user group
    $value = sp_get_sfmeta('default usergroup', 'sfguests');
    $ugid = spdb_table(SFUSERGROUPS, "usergroup_id={$value[0]['meta_value']}", 'usergroup_id');
    if (empty($ugid)) {
        $mess .= spa_message(spa_text('Warning - The default user group for guests is undefined!  Please visit the SP usergroups admin page, map users to usergroups tab and set the default user group'), 'error');
    }
    # check for unreachable forums because of permissions
    $done = 0;
    $usergroups = spdb_table(SFUSERGROUPS);
    if ($usergroups) {
        $has_members = false;
        foreach ($usergroups as $usergroup) {
            $members = spdb_table(SFMEMBERSHIPS, "usergroup_id={$usergroup->usergroup_id}", 'row', '', '1');
            if ($members || $usergroup->usergroup_id == $value[0]['meta_value']) {
                $has_members = true;
                break;
            }
        }
        if (!$has_members) {
            $mess .= spa_message(spa_text('Warning - There are no usergroups that have members!	All forums may only be visible to SP admins'), 'error');
            $done = 1;
        }
    } else {
        $mess .= spa_message(spa_text('Warning - There are no usergroups defined!  All forums may only be visible to SP admins'), 'error');
        $done = 1;
    }
    $roles = sp_get_all_roles();
    if (!$roles) {
        $mess .= spa_message(spa_text('Warning - There are no permission sets defined!  All forums may only be visible to SP admins'), 'error');
        $done = 1;
    }
    # check if compatible with wp super cache
    if (function_exists('wp_cache_edit_rejected')) {
        global $cache_rejected_uri;
        $slug = '/' . sp_get_option('sfslug') . '/';
        if (isset($cache_rejected_uri)) {
            $found = false;
            foreach ($cache_rejected_uri as $value) {
                if ($value == $slug) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                $string = spa_text('WP Super Cache is not properly configured to work with Simple:Press. Please visit your WP Super Cache settings page and in the accepted filenames & rejected URIs section for the pages not to be cached input field, add the following string');
                $string .= ':<br /><br />' . $slug . '<br /><br />';
                $string .= spa_text('Then, please clear your WP Super Cache cache to remove any cached Simple:Press pages');
                $mess .= spa_message($string, 'error');
            }
        }
    }
    if ($mess != '') {
        return $mess;
    }
}
function spa_display_permission_select($cur_perm = 0, $showSelect = true)
{
    ?>
	<?php 
    $roles = sp_get_all_roles();
    ?>
	<p><?php 
    spa_etext('Select permission set');
    ?>
:&nbsp;&nbsp;
	<?php 
    if ($showSelect) {
        ?>
		<select style="width:165px" class='sfacontrol' name='role'>
<?php 
    }
    $out = '';
    if ($cur_perm == 0) {
        $out = '<option value="-1">' . spa_text('Select permission set') . '</option>';
    }
    foreach ($roles as $role) {
        $selected = '';
        if ($cur_perm == $role->role_id) {
            $selected = 'selected = "selected" ';
        }
        $out .= '<option ' . $selected . 'value="' . $role->role_id . '">' . sp_filter_title_display($role->role_name) . '</option>' . "\n";
    }
    echo $out;
    if ($showSelect) {
        ?>
		</select></p>
<?php 
    }
}
function spa_forums_edit_group_form($group_id)
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	jQuery('#grouprow-<?php 
    echo $group_id;
    ?>
').addClass('inForm');
    	spjAjaxForm('sfgroupedit<?php 
    echo $group_id;
    ?>
', 'sfreloadfb');
    });
</script>
<?php 
    global $spPaths;
    $group = $group = spdb_table(SFGROUPS, "group_id={$group_id}", 'row');
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=editgroup';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfgroupedit<?php 
    echo $group->group_id;
    ?>
" name="sfgroupedit<?php 
    echo $group->group_id;
    ?>
">
<?php 
    echo sp_create_nonce('forum-adminform_groupedit');
    spa_paint_open_tab(spa_text('Forums') . ' - ' . spa_text('Manage Groups and Forums'), false);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Edit Group'), 'true', 'edit-forum-group');
    ?>
					<input type="hidden" name="group_id" value="<?php 
    echo $group->group_id;
    ?>
" />
					<input type="hidden" name="cgroup_name" value="<?php 
    echo sp_filter_title_display($group->group_name);
    ?>
" />
					<input type="hidden" name="cgroup_desc" value="<?php 
    echo sp_filter_text_edit($group->group_desc);
    ?>
" />
					<input type="hidden" name="cgroup_seq" value="<?php 
    echo $group->group_seq;
    ?>
" />
					<input type="hidden" name="cgroup_icon" value="<?php 
    echo esc_attr($group->group_icon);
    ?>
" />
					<input type="hidden" name="cgroup_rss" value="<?php 
    echo $group->group_rss;
    ?>
" />
					<input type="hidden" name="cgroup_message" value="<?php 
    echo sp_filter_text_edit($group->group_message);
    ?>
" />
<?php 
    spa_paint_input(spa_text('Group Name'), 'group_name', sp_filter_title_display($group->group_name), false, true);
    spa_paint_input(spa_text('Description'), 'group_desc', sp_filter_text_edit($group->group_desc), false, true);
    spa_paint_select_start(spa_text('Select Custom Icon'), 'group_icon', '');
    spa_select_icon_dropdown('group_icon', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', $group->group_icon, false);
    spa_paint_select_end();
    spa_paint_input(spa_text('Replacement external RSS URL') . '<br />' . spa_text('Default') . ': <strong>' . sp_get_sfqurl(sp_build_url('', '', 0, 0, 0, 1)) . 'group=' . $group->group_id . '</strong>', 'group_rss', sp_filter_url_display($group->group_rss), false, true);
    spa_paint_wide_textarea('Special group message to be displayed above forums', 'group_message', sp_filter_text_edit($group->group_message));
    do_action('sph_forums_edit_group_panel');
    spa_paint_close_fieldset();
    echo '<div class="sfoptionerror spaceabove">';
    echo sprintf(sp_text('To re-order your Groups, Forums and SubForums use the %s Order Groups and Forums %s option from the Forums Menu'), '<b>', '</b>');
    echo '</div>';
    spa_paint_close_panel();
    spa_paint_tab_right_cell();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Default User Group Permissions'), false);
    echo '<strong>' . spa_text('Set default usergroup permission sets for this group') . '</strong><br />';
    echo spa_text('Note - This will not will add or modify any current permissions. It is only a default setting for future forums created in this group.  Existing default usergroup settings will be shown in the drop down menus');
    # Permissions
    $usergroups = spa_get_usergroups_all();
    $roles = sp_get_all_roles();
    foreach ($usergroups as $usergroup) {
        echo '<input type="hidden" name="usergroup_id[]" value="' . $usergroup->usergroup_id . '" />';
        spa_paint_select_start(sp_filter_title_display($usergroup->usergroup_name), 'role[]', '');
        $defrole = spa_get_defpermissions_role($group->group_id, $usergroup->usergroup_id);
        if ($defrole == -1 || $defrole == '') {
            echo '<option value="-1">' . spa_text('Select permission set') . '</option>';
        }
        foreach ($roles as $role) {
            $selected = '';
            if ($defrole == $role->role_id) {
                $selected = 'selected="selected" ';
            }
            echo '<option ' . $selected . 'value="' . $role->role_id . '">' . sp_filter_title_display($role->role_name) . '</option>' . "\n";
        }
        spa_paint_select_end();
    }
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
		<input type="submit" class="button-primary" id="groupedit<?php 
    echo $group->group_id;
    ?>
" name="groupedit<?php 
    echo $group->group_id;
    ?>
" value="<?php 
    spa_etext('Update Group');
    ?>
" />
		<input type="button" class="button-primary" onclick="javascript:jQuery('#group-<?php 
    echo $group->group_id;
    ?>
').html('');jQuery('#grouprow-<?php 
    echo $group_id;
    ?>
').removeClass('inForm');" id="sfgroupedit<?php 
    echo $group->group_id;
    ?>
" name="groupeditcancel<?php 
    echo $group->group_id;
    ?>
" value="<?php 
    spa_etext('Cancel');
    ?>
" />
		</div>
	</form>

	<?php 
    spa_paint_close_tab();
    ?>

	<div class="sfform-panel-spacer"></div>
<?php 
}
function spa_forums_create_forum_form()
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfforumnew', 'sfreloadfb');
    });
</script>
<?php 
    global $spPaths, $tab;
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=createforum';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfforumnew" name="sfforumnew">
<?php 
    echo sp_create_nonce('forum-adminform_forumnew');
    spa_paint_open_tab(spa_text('Forums') . ' - ' . spa_text('Create New Forum'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Create New Forum'), 'true', 'create-new-forum');
    # check there are groups before proceeding
    if (spdb_count(SFGROUPS) == 0) {
        echo '<br /><div class="sfoptionerror">';
        spa_etext('There are no groups defined');
        echo '<br />' . spa_text('Create new group');
        echo '</div><br />';
        spa_paint_close_fieldset();
        spa_paint_close_panel();
        spa_paint_close_container();
        spa_paint_close_tab();
        echo '</form>';
        return;
    }
    # Select the forum type first
    echo "<div class='sp-form-row'>\n";
    echo "<div class='wp-core-ui sflabel sp-label-40'>" . spa_text('What type of forum are you creating') . ":</div>\n";
    echo "<div class='wp-core-ui sp-radio'>";
    echo '<input type="radio" name="forumtype" id="sfradio1" tabindex="' . $tab . '" value="1" checked="checked" onchange="spjSetForumOptions(\'forum\');" />' . "\n";
    echo '<label for="sfradio1" class="wp-core-ui">' . spa_text('Standard Forum') . '</label><br>' . "\n";
    $tab++;
    # check there are forums before offering subforum creation!
    if (spdb_count(SFFORUMS) != 0) {
        echo '<input type="radio" name="forumtype" id="sfradio2" tabindex="' . $tab . '" value="2" onchange="spjSetForumOptions(\'subforum\');" />' . "\n";
        echo '<label for="sfradio2" class="wp-core-ui">' . spa_text('Sub or child forum') . '</label>' . "\n";
        $tab++;
    }
    echo '</div><div class="clearboth"></div></div>';
    # Now display the two select box options
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums&amp;sfnonce=' . wp_create_nonce('forum-ahah');
    $target = 'fseq';
    echo '<div id="groupselect" style="display:block;">';
    echo "<div class='sp-form-row'>\n";
    echo "<div class='wp-core-ui sflabel sp-label-40'>" . spa_text('Select group new forum will belong to') . ":</div>\n";
    echo '<select class="wp-core-ui  sp-input-60" tabindex="' . $tab . '" name="group_id"  onchange="spjSetForumSequence();">';
    echo spa_create_group_select(0, 1);
    echo "</select>\n";
    echo '<div class="clearboth"></div>';
    echo '</div>';
    $tab++;
    echo '</div>';
    echo '<div id="forumselect" style="display:none;">';
    echo "<div class='sp-form-row'>\n";
    echo "<div class='wp-core-ui sflabel sp-label-40'>" . spa_text('Select forum new subforum will belong to') . ":</div>\n";
    echo '<select class="wp-core-ui  sp-input-60" tabindex="' . $tab . '" name="forum_id"  onchange="spjSetForumSequence();">';
    echo sp_render_group_forum_select(false, false, false, true);
    echo "</select>\n";
    echo '<div class="clearboth"></div>';
    echo '</div>';
    $tab++;
    echo '</div>';
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_close_container();
    echo '<div class="sfform-panel-spacer"></div>';
    spa_paint_close_tab();
    echo '<div class="sfform-panel-spacer"></div>';
    echo '<div class="sfhidden" id="block1">';
    spa_paint_open_nohead_tab(false);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Forum Details'), false);
    $target = 'thisforumslug';
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums&amp;sfnonce=' . wp_create_nonce('forum-ahah');
    # forum name and slug
    echo "<div class='sp-form-row'>";
    echo "<div class='wp-core-ui sflabel sp-label-40'>" . spa_text('Forum Name') . ':</div>';
    echo '<input type="text" class="wp-core-ui sp-input-60" tabindex="' . $tab . '" name="forum_name" value="" onchange="spjSetForumSlug(this, \'' . $ahahURL . '\', \'' . $target . '\', \'new\');" />';
    echo '<div class="clearboth"></div>';
    echo '</div>';
    $tab++;
    echo "<div class='sp-form-row'>\n";
    echo "<div class='wp-core-ui sflabel sp-label-40'>" . spa_text('Forum slug') . ":</div>";
    echo '<input type="text" class="wp-core-ui sp-input-60" tabindex="' . $tab . '" name="thisforumslug" id="thisforumslug" value="" disabled="disabled" onchange="spjSetForumSlug(this, \'' . $ahahURL . '\', \'' . $target . '\', \'new\');" />';
    echo '<div class="clearboth"></div>';
    echo '</div>';
    $tab++;
    spa_paint_input(spa_text('Description'), 'forum_desc', '', false, true);
    spa_paint_checkbox(spa_text('Locked'), 'forum_status', 0);
    spa_paint_checkbox(spa_text('Disable forum RSS feed so feed will not be generated'), 'forum_private', 0);
    echo '<div class="sfoptionerror spaceabove">';
    echo '<p><b>' . sp_text('Custom Icon Ordering') . '</b></br>';
    echo sp_text('When using custom forum or topic icons and multiple conditions exist, the following precedence is used:') . '</p>';
    echo sp_text('Locked') . '<br />';
    echo sp_text('Pinned') . '<br />';
    echo sp_text('Unread') . '<br />';
    echo sp_text('Custom') . '<br />';
    echo sp_text('Theme Default') . '<br />';
    echo '</div>';
    spa_paint_select_start(spa_text('Custom forum icon'), 'forum_icon', '');
    spa_select_icon_dropdown('forum_icon', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom forum icon when new posts'), 'forum_icon_new', '');
    spa_select_icon_dropdown('forum_icon_new', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom forum icon when locked'), 'forum_icon_locked', '');
    spa_select_icon_dropdown('forum_icon_locked', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom topic icon'), 'topic_icon', '');
    spa_select_icon_dropdown('topic_icon', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom topic icon when new posts'), 'topic_icon_new', '');
    spa_select_icon_dropdown('topic_icon_new', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom topic icon when locked'), 'topic_icon_locked', '');
    spa_select_icon_dropdown('topic_icon_locked', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom topic icon when pinned'), 'topic_icon_pinned', '');
    spa_select_icon_dropdown('topic_icon_pinned', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_input(spa_text('Custom meta keywords (SEO option must be enabled)'), 'forum_keywords', '', false, true);
    spa_paint_wide_textarea('Special forum message to be displayed above forums', 'forum_message', '');
    spa_paint_close_fieldset();
    echo '<div class="sfoptionerror spaceabove">';
    echo sprintf(sp_text('To re-order your Groups, Forums and SubForums use the %s Order Groups and Forums %s option from the Forums Menu'), '<b>', '</b>');
    echo '</div>';
    spa_paint_close_panel();
    spa_paint_tab_right_cell();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Extended Forum Options'), false);
    # As added by plugins
    do_action('sph_forum_create_forum_options');
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Add User Group Permissions'), false);
    echo '<div id="block2" class="sfhidden">';
    echo '<strong>' . spa_text('You can selectively set the permission sets for the forum below. If you want to use the default permissions for the selected group, then do not select anything') . '</strong>';
    # Permissions
    $usergroups = spa_get_usergroups_all();
    $roles = sp_get_all_roles();
    foreach ($usergroups as $usergroup) {
        echo '<input type="hidden" name="usergroup_id[]" value="' . $usergroup->usergroup_id . '" />';
        spa_paint_select_start(sp_filter_title_display($usergroup->usergroup_name), 'role[]', '');
        echo '<option value="-1">' . spa_text('Select permission set') . '</option>';
        foreach ($roles as $role) {
            echo '<option value="' . $role->role_id . '">' . sp_filter_title_display($role->role_name) . '</option>' . "\n";
        }
        spa_paint_select_end();
    }
    echo '</div>';
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
            <input type="submit" class="button-primary" id="saveit" name="saveit" value="<?php 
    spa_etext('Create New Forum');
    ?>
" />
		</div>
    	<?php 
    spa_paint_close_tab();
    ?>
        </div>
	</form>
	<div class="sfform-panel-spacer"></div>
<?php 
}
function spa_check_warnings()
{
    global $spGlobals;
    # not perfect but we can use this call tyo perform any minor
    # cleanups that may be necessary... so
    # drop any existing temp members table...
    spdb_query('DROP TABLE IF EXISTS sftempmembers');
    $mess = '';
    # check if sp core, plugins or themes update available
    $update = false;
    $update_msg = '';
    $up = get_site_transient('update_plugins');
    if (!empty($up->response)) {
        foreach ($up->response as $plugin) {
            if ($plugin->slug == 'simple-press') {
                $msg = apply_filters('sph_core_update_notice', spa_text('There is a Simple:Press core update available.'));
                if (!empty($msg)) {
                    $update = true;
                    $update_msg .= $msg . '<br />';
                }
                break;
            }
        }
    }
    $up = get_site_transient('sp_update_plugins');
    if (!empty($up)) {
        $msg = apply_filters('sph_plugins_update_notice', spa_text('There is one or more Simple:Press plugin updates available'));
        if (!empty($msg)) {
            $update = true;
            $update_msg .= $msg . '<br />';
        }
    }
    $up = get_site_transient('sp_update_themes');
    if (!empty($up)) {
        $msg = apply_filters('sph_themes_update_notice', spa_text('There is one or more Simple:Press theme updates available'));
        if (!empty($msg)) {
            $update = true;
            $update_msg .= $msg . '<br />';
        }
    }
    if ($update) {
        if (is_main_site()) {
            $mess .= apply_filters('sph_updates_notice', spa_message($update_msg . '<a href="' . self_admin_url('update-core.php') . '">' . spa_text('Click here to view any updates.') . '</a>'));
        } else {
            $mess .= apply_filters('sph_updates_notice', spa_message(spa_text('There are some Simple:Press updates avaialable. You may want to notify the network site admin.')));
        }
    }
    # output warning if no SPF admins are defined
    $a = $spGlobals['forum-admins'];
    if (empty($a)) {
        $mess .= spa_message(spa_text('Warning - There are no SPF admins defined!	 All WP admins now have SP backend access'), 'error');
    }
    # Check if	desktop, tablet and mobile themes are selected and available
    $cur = sp_get_option('sp_current_theme');
    if (empty($cur)) {
        $mess .= spa_message(spa_text('No main theme has been selected and SP will be unable to display correctly. Please select a theme from the Themes panel'), 'error');
    } else {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $cur['theme'] . '/styles/' . $cur['style']);
        $nooverlay = !empty($cur['color']) && !file_exists(SPTHEMEBASEDIR . $cur['theme'] . '/styles/overlays/' . $cur['color'] . '.php');
        $nopoverlay = !empty($cur['color']) && !empty($cur['parent']) && !file_exists(SPTHEMEBASEDIR . $cur['parent'] . '/styles/overlays/' . $cur['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the theme CSS file and/or color Overlay file from the selected theme is missing'), 'error');
        }
    }
    $mobile = sp_get_option('sp_mobile_theme');
    if (!empty($mobile) && $mobile['active']) {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $mobile['theme'] . '/styles/' . $mobile['style']);
        $nooverlay = !empty($mobile['color']) && !file_exists(SPTHEMEBASEDIR . $mobile['theme'] . '/styles/overlays/' . $mobile['color'] . '.php');
        $nopoverlay = !empty($mobile['color']) && !empty($mobile['parent']) && !file_exists(SPTHEMEBASEDIR . $mobile['parent'] . '/styles/overlays/' . $mobile['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the mobile theme CSS file and/or color Overlay file from the selected mobile theme is missing'), 'error');
        }
    }
    $tablet = sp_get_option('sp_tablet_theme');
    if (!empty($tablet) && $tablet['active']) {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $tablet['theme'] . '/styles/' . $tablet['style']);
        $nooverlay = !empty($tablet['color']) && !file_exists(SPTHEMEBASEDIR . $tablet['theme'] . '/styles/overlays/' . $tablet['color'] . '.php');
        $nopoverlay = !empty($tablet['color']) && !empty($tablet['parent']) && !file_exists(SPTHEMEBASEDIR . $tablet['parent'] . '/styles/overlays/' . $tablet['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the tablet theme CSS file and/or color Overlay file from the selected tablet theme is missing'), 'error');
        }
    }
    # check for missing default members user group
    $value = sp_get_sfmeta('default usergroup', 'sfmembers');
    $ugid = spdb_table(SFUSERGROUPS, "usergroup_id={$value[0]['meta_value']}", 'usergroup_id');
    if (empty($ugid)) {
        $mess .= spa_message(spa_text('Warning - The default user group for new members is undefined!	Please visit the SP usergroups admin page, map users to usergroups tab and set the default user group'), 'error');
    }
    # check for missing default guest user group
    $value = sp_get_sfmeta('default usergroup', 'sfguests');
    $ugid = spdb_table(SFUSERGROUPS, "usergroup_id={$value[0]['meta_value']}", 'usergroup_id');
    if (empty($ugid)) {
        $mess .= spa_message(spa_text('Warning - The default user group for guests is undefined!  Please visit the SP usergroups admin page, map users to usergroups tab and set the default user group'), 'error');
    }
    # check for unreachable forums because of permissions
    $usergroups = spdb_table(SFUSERGROUPS);
    if ($usergroups) {
        $has_members = false;
        foreach ($usergroups as $usergroup) {
            $members = spdb_table(SFMEMBERSHIPS, "usergroup_id={$usergroup->usergroup_id}", 'row', '', '1');
            if ($members || $usergroup->usergroup_id == $value[0]['meta_value']) {
                $has_members = true;
                break;
            }
        }
        if (!$has_members) {
            $mess .= spa_message(spa_text('Warning - There are no usergroups that have members!	All forums may only be visible to SP admins'), 'error');
        }
    } else {
        $mess .= spa_message(spa_text('Warning - There are no usergroups defined!  All forums may only be visible to SP admins'), 'error');
    }
    $roles = sp_get_all_roles();
    if (!$roles) {
        $mess .= spa_message(spa_text('Warning - There are no permission sets defined!  All forums may only be visible to SP admins'), 'error');
    }
    # check if compatible with wp super cache
    if (function_exists('wp_cache_edit_rejected')) {
        global $cache_rejected_uri;
        $slug = '/' . sp_get_option('sfslug') . '/';
        if (isset($cache_rejected_uri)) {
            $found = false;
            foreach ($cache_rejected_uri as $value) {
                if ($value == $slug) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                $string = spa_text('WP Super Cache is not properly configured to work with Simple:Press. Please visit your WP Super Cache settings page and in the accepted filenames & rejected URIs section for the pages not to be cached input field, add the following string');
                $string .= ':</p><p><em>' . $slug . '</em></p><p>';
                $string .= spa_text('Then, please clear your WP Super Cache cache to remove any cached Simple:Press pages');
                $string .= ':</p><p><em>' . spa_text('For more information please see this') . ' <a href="http://simple-press.com/documentation/codex/faq/troubleshooting/forum-displays-wrong-information/" target="_blank">' . spa_text('FAQ') . '</a></p><p>';
                $mess .= spa_message($string, 'error');
            }
        }
    }
    # check if compatible with w3 total cache (at leasst check for slug
    $f = WP_CONTENT_DIR . '/cache/config/master.php';
    if (file_exists($f) && is_readable($f)) {
        $c = file_get_contents($f);
        $c = substr($c, 13);
        $config = @unserialize($c);
        if (key_exists('pgcache.reject.uri', $config) && !empty($config['pgcache.reject.uri'])) {
            $found = false;
            $slug = '/' . sp_get_option('sfslug') . '/';
            foreach ($config['pgcache.reject.uri'] as $i) {
                if ($i == $slug) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                $string = spa_text('W3 Total Cache is not properly configured to work with Simple:Press. Please visit your W3 Total Cache settings page and in the accepted filenames & rejected URIs in ALL sections, add the following string');
                $string .= ':</p><p><em>' . $slug . '</em></p><p>';
                $string .= spa_text('Then, please clear your W3 Total Cache cache to remove any cached Simple:Press pages');
                $string .= ':</p><p><em>' . spa_text('For more information please see this') . ' <a href="http://simple-press.com/documentation/codex/faq/troubleshooting/forum-displays-wrong-information/" target="_blank">' . spa_text('FAQ') . '</a></p><p>';
                $mess .= spa_message($string, 'error');
            }
        }
    }
    # check for server-side UTC timezone
    $tz = get_option('timezone_string');
    if (empty($tz)) {
        $tz = 'UTC ' . get_option('gmt_offset');
        $string = spa_text('You have set your server to use a UTC timezone setting');
        $string .= ':</p><p><em>' . $tz . '</em></p><p>';
        $string .= spa_text('UTC can give unpredictable results on forum post time stamps. Please select the city setting nearest to you in the WordPress - Settings - General admin page');
        $string .= ':</p><p><em>' . spa_text('For more information please see this') . ' <a href="http://simple-press.com/documentation/codex/faq/troubleshooting/why-do-my-new-posts-show-as-posted-minus-seconds-ago/" target="_blank">' . spa_text('FAQ') . '</a></p><p>';
        $mess .= spa_message($string, 'error');
    }
    if ($mess != '') {
        return $mess;
    }
}
function spa_forums_create_group_form()
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfgroupnew', 'sfreloadfb');
    });
</script>
<?php 
    global $spPaths;
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=creategroup';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfgroupnew" name="sfgroupnew">
<?php 
    echo sp_create_nonce('forum-adminform_groupnew');
    spa_paint_open_tab(spa_text('Forums') . ' - ' . spa_text('Create New Group'), false);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Create New Group'), 'true', 'create-new-forum-group');
    spa_paint_input(spa_text('Group Name'), 'group_name', '', false, true);
    spa_paint_input(spa_text('Description'), 'group_desc', '', false, true);
    spa_paint_select_start(spa_text('Select Custom Icon'), 'group_icon', '');
    spa_select_icon_dropdown('group_icon', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_wide_textarea('Special group message to be displayed above forums', 'group_message', '');
    do_action('sph_forums_create_group_panel');
    spa_paint_close_fieldset();
    echo '<div class="sfoptionerror spaceabove">';
    echo sprintf(sp_text('To re-order your Groups, Forums and SubForums use the %s Order Groups and Forums %s option from the Forums Menu'), '<b>', '</b>');
    echo '</div>';
    spa_paint_close_panel();
    spa_paint_tab_right_cell();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Default User Group Permissions'), false);
    echo '<strong>' . spa_text('Set default usergroup permission sets for this group') . '</strong><br />';
    echo spa_text('Note - This will not add or modify any current permissions. It is only a default setting for future forums created in this group.');
    # Permissions
    $usergroups = spa_get_usergroups_all();
    $roles = sp_get_all_roles();
    foreach ($usergroups as $usergroup) {
        echo '<input type="hidden" name="usergroup_id[]" value="' . $usergroup->usergroup_id . '" />';
        spa_paint_select_start(sp_filter_title_display($usergroup->usergroup_name), 'role[]', '');
        echo '<option value="-1">' . spa_text('Select permission set') . '</option>';
        foreach ($roles as $role) {
            echo '<option value="' . $role->role_id . '">' . sp_filter_title_display($role->role_name) . '</option>' . "\n";
        }
        spa_paint_select_end();
    }
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
		<input type="submit" class="button-primary" id="saveit" name="saveit" value="<?php 
    spa_etext('Create New Group');
    ?>
" />
		</div>
		</form>

	<?php 
    spa_paint_close_tab();
    ?>

	<div class="sfform-panel-spacer"></div>
<?php 
}
function spa_permissions_permission_main()
{
    $roles = sp_get_all_roles();
    if ($roles) {
        # display the permission set roles in table format
        ?>
		<table class="wp-list-table widefat">
			<tr>
				<th style="text-align:center;" width="9%" scope="col"><?php 
        spa_etext('ID');
        ?>
</th>
				<th scope="col"><?php 
        spa_etext('Name');
        ?>
</th>
				<th scope="col"><?php 
        spa_etext('Name');
        ?>
</th>
			</tr>
		</table>
<?php 
        foreach ($roles as $role) {
            ?>
		<table id="rolerow-<?php 
            echo $role->role_id;
            ?>
" class="wp-list-table widefat">
			<tr>
				<td width="9%" class='row-title' align="center" style="padding:0px 0;"><?php 
            echo $role->role_id;
            ?>
</td>
				<td><span class='row-title'><strong><?php 
            echo sp_filter_title_display($role->role_name);
            ?>
</strong></span><span><br /><?php 
            echo sp_filter_title_display($role->role_desc);
            ?>
</span></td>
			</tr>

			<tr>
				<td class='smallLabel'><?php 
            spa_etext("Manage Permissions");
            ?>
</td>
				<td align="left" style="padding:0 0 0 3px;text-align:left;">
<?php 
            $base = SFHOMEURL . 'index.php?sp_ahah=permissions-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah');
            $target = 'perm-' . $role->role_id;
            $image = SFADMINIMAGES;
            ?>
					<input type="button" class="button-secondary" value="<?php 
            echo spa_text('Edit Permission');
            ?>
" onclick="spjLoadForm('editperm', '<?php 
            echo $base;
            ?>
', '<?php 
            echo $target;
            ?>
', '<?php 
            echo $image;
            ?>
', '<?php 
            echo $role->role_id;
            ?>
');" />
					<input type="button" class="button-secondary" value="<?php 
            echo spa_text('Delete Permission');
            ?>
" onclick="spjLoadForm('delperm', '<?php 
            echo $base;
            ?>
', '<?php 
            echo $target;
            ?>
', '<?php 
            echo $image;
            ?>
', '<?php 
            echo $role->role_id;
            ?>
');" />
				</td>
			</tr>
			<tr class="sfinline-form"> <!-- This row will hold ahah forms for the current permission set -->
			  	<td colspan="2" style="padding: 0 10px 0 0;">
					<div id="perm-<?php 
            echo $role->role_id;
            ?>
">
					</div>
				</td>
			</tr>
		</table>
<?php 
        }
        ?>
		<br />
<?php 
    } else {
        echo '<div class="sfempty">&nbsp;&nbsp;&nbsp;&nbsp;' . spa_text('There are no Permission Sets defined.') . '</div>';
    }
}