function spa_usergroups_create_usergroup_form()
{
    global $spPaths;
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfusergroupnew', 'sfreloadub');
    });
</script>
<?php 
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=usergroups-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=newusergroup';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfusergroupnew" name="sfusergroupnew">
<?php 
    echo sp_create_nonce('forum-adminform_usergroupnew');
    spa_paint_open_tab(spa_text('User Groups') . ' - ' . spa_text('Create New User Group'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Edit User Group'), 'true', 'edit-user-group');
    spa_paint_input(spa_text('User Group Name'), 'usergroup_name', '', false, true);
    spa_paint_input(spa_text('User Group Description'), 'usergroup_desc', '', false, true);
    spa_paint_select_start(spa_text('Select Badge'), 'usergroup_badge', 'usergroup_badge');
    spa_select_icon_dropdown('usergroup_badge', spa_text('Select Badge'), SF_STORE_DIR . '/' . $spPaths['ranks'] . '/', '', false);
    spa_paint_select_end('<small>(' . spa_text('Upload badges on the Components - Forum Ranks admin panel') . ')</small>');
    spa_paint_checkbox(spa_text('Allow members to join usergroup'), 'usergroup_join', false, false, false, false, '<small>' . spa_text('(Indicates that members are allowed to choose to join this usergroup on their profile page)') . '</small>');
    spa_paint_checkbox(spa_text('Is moderator'), 'usergroup_is_moderator', false, false, false, false, '<small>' . spa_text('(Indicates that members of this usergroup are considered Moderators)') . '</small>');
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_usergroup_create_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 User Group');
    ?>
" />
		</div>
		</form>
	<?php 
    spa_paint_close_tab();
    ?>

	<div class="sfform-panel-spacer"></div>
<?php 
}
function spa_forums_global_perm_form()
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfnewglobalpermission', 'sfreloadfb');
    });
</script>
<?php 
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=globalperm';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfnewglobalpermission" name="sfnewglobalpermission">
<?php 
    echo sp_create_nonce('forum-adminform_globalpermissionnew');
    spa_paint_open_tab(spa_text('Forums') . ' - ' . spa_text('Add Global Permission Set'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Add a User Group Permission Set to All Forums'), 'true', 'add-a-user-group-permission-set-to-all-forums');
    spa_paint_select_start(spa_text('Select usergroup'), 'usergroup_id', '');
    spa_display_usergroup_select(false, 0, false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Select permission set'), 'role', '');
    spa_display_permission_select(false, 0, false);
    spa_paint_select_end();
    echo '<p>' . spa_text('Caution:  Any current permission sets for the selected usergroup for ANY forum may be overwritten') . '</p>';
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_forums_global_perm_panel');
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
		<input type="submit" class="button-primary" id="saveit" name="saveit" value="<?php 
    spa_etext('Add Global Permission');
    ?>
" />
		</div>
	</form>
	<?php 
    spa_paint_close_tab();
    ?>

	<div class="sfform-panel-spacer"></div>
<?php 
}
function spa_permissions_add_permission_form()
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfrolenew', 'sfreloadpb');
    });
</script>
<?php 
    # Get correct tooltips file
    $lang = spa_get_language_code();
    if (empty($lang)) {
        $lang = 'en';
    }
    $ttpath = SPHELP . 'admin/tooltips/admin-permissions-tips-' . $lang . '.php';
    if (file_exists($ttpath) == false) {
        $ttpath = SPHELP . 'admin/tooltips/admin-permissions-tips-en.php';
    }
    if (file_exists($ttpath)) {
        include_once $ttpath;
    }
    global $spGlobals;
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=permissions-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=addperm';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfrolenew" name="sfrolenew">
<?php 
    echo sp_create_nonce('forum-adminform_rolenew');
    spa_paint_open_tab(spa_text('Permissions') . " - " . spa_text('Add New Permission'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Add New Permission'), 'true', 'create-new-permission-set');
    spa_paint_input(spa_text('Permission Set Name'), "role_name", '', false, true);
    spa_paint_input(spa_text('Permission Set Description'), "role_desc", '', false, true);
    spa_paint_select_start(spa_text('Clone Existing Permission Set'), 'role', 'role');
    spa_display_permission_select('', false);
    spa_paint_select_end('<small>(' . spa_text('Select an existing Permission Set to Clone.  Any settings below will be ignored.') . ')</small>');
    ?>
					<br /><p><strong><?php 
    spa_etext('Permission Set Actions');
    ?>
:</strong></p>
<?php 
    echo '<p><img src="' . SFADMINIMAGES . 'sp_GuestPerm.png" alt="" style="width:16px;height:16px;vertical-align:top" />';
    echo '<small>&nbsp;' . spa_text('Note: Action settings displaying this icon will be ignored for Guest Users') . '</small>';
    echo '&nbsp;&nbsp;&nbsp;<img src="' . SFADMINIMAGES . 'sp_GlobalPerm.png" alt="" style="width:16px;height:16px;vertical-align:top" />';
    echo '<small>&nbsp;' . spa_text('Note: Action settings displaying this icon require enabling to use') . '</small>';
    echo '&nbsp;&nbsp;&nbsp;<img src="' . SFADMINIMAGES . 'sp_Warning.png" alt="" style="width:16px;height:16px;vertical-align:top" />';
    echo '<small>&nbsp;' . spa_text('Note: Action settings displaying this icon should be used with great care') . '</small></p>';
    sp_build_site_auths_cache();
    $sql = 'SELECT auth_id, auth_name, auth_cat, authcat_name, warning FROM ' . SFAUTHS . '
							JOIN ' . SFAUTHCATS . ' ON ' . SFAUTHS . '.auth_cat = ' . SFAUTHCATS . '.authcat_id
							WHERE active = 1
							ORDER BY auth_cat, auth_id';
    $authlist = spdb_select('set', $sql);
    $firstitem = true;
    $category = '';
    ?>
					<!-- OPEN OUTER CONTAINER DIV -->
					<div class="outershell" style="width: 100%;">
<?php 
    foreach ($authlist as $a) {
        if ($category != $a->authcat_name) {
            $category = $a->authcat_name;
            if (!$firstitem) {
                ?>
								<!-- CLOSE DOWN THE ENDS -->
								</table></div>
<?php 
            }
            ?>
							<!-- OPEN NEW INNER DIV -->
							<div class="innershell">
							<!-- NEW INNER DETAIL TABLE -->
							<table style="width:100%;border:0">
							<tr><td colspan="2" class="permhead"><?php 
            spa_etext($category);
            ?>
</td></tr>
<?php 
            $firstitem = false;
        }
        $auth_id = $a->auth_id;
        $auth_name = $a->auth_name;
        $authWarn = empty($a->warning) ? false : true;
        $warn = $authWarn ? " permwarning" : '';
        $tip = $authWarn ? " class='permwarning' title='" . esc_js(spa_text($a->warning)) . "'" : '';
        $button = 'b-' . $auth_id;
        if ($spGlobals['auths'][$auth_id]->ignored || $spGlobals['auths'][$auth_id]->enabling || $authWarn) {
            $span = '';
        } else {
            $span = ' colspan="2" ';
        }
        ?>
							<tr<?php 
        echo $tip;
        ?>
>
								<td class="permentry<?php 
        echo $warn;
        ?>
">

								<input type="checkbox" name="<?php 
        echo $button;
        ?>
" id="sf<?php 
        echo $button;
        ?>
"  />
								<label for="sf<?php 
        echo $button;
        ?>
" class="sflabel">
								<img style="text-align:top;float: right; border: 0pt none ; margin: -4px 5px 0px 3px; padding: 0;" class="" title="<?php 
        echo $tooltips[$auth_name];
        ?>
" src="<?php 
        echo SFADMINIMAGES;
        ?>
sp_Information.png" alt="" />
								<?php 
        spa_etext($spGlobals['auths'][$auth_id]->auth_desc);
        ?>
</label>
								<?php 
        if ($span == '') {
            ?>
									<td style="text-align:center;width:32px" class="permentry">
<?php 
        }
        if ($span == '') {
            if ($spGlobals['auths'][$auth_id]->enabling) {
                echo '<img src="' . SFADMINIMAGES . 'sp_GlobalPerm.png" alt="" style="width:16px;height:16px" title="' . spa_text('Requires Enabling') . '" />';
            }
            if ($spGlobals['auths'][$auth_id]->ignored) {
                echo '<img src="' . SFADMINIMAGES . 'sp_GuestPerm.png" alt="" style="width:16px;height:16px" title="' . spa_text('Ignored for Guests') . '" />';
            }
            if ($authWarn) {
                echo '<img src="' . SFADMINIMAGES . 'sp_Warning.png" alt="" style="width:16px;height:16px" title="' . spa_text('Use with Caution') . '" />';
            }
            echo '</td>';
        } else {
            ?>
								    </td><td class="permentry" style="width:32px"></td>
                                <?php 
        }
        ?>
							</tr>
                        <?php 
    }
    ?>
					<!-- END CONTAINER DIV -->
					</table></div><div class="clearboth"></div>
					</div>
<?php 
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_perm_add_perm_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 Permission');
    ?>
" />
	</div>
	<?php 
    spa_paint_close_tab();
    ?>
	</form>
	<div class="sfform-panel-spacer"></div>
<?php 
}
function spa_profiles_options_form()
{
    ?>
<script type="text/javascript">
	spjAjaxForm('sfoptionsform', '');
</script>
<?php 
    $sfoptions = spa_get_options_data();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=profiles-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=options';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfoptionsform" name="sfoptions">
	<?php 
    echo sp_create_nonce('forum-adminform_options');
    spa_paint_options_init();
    #== PROFILE OPTIONS Tab ============================================================
    spa_paint_open_tab(spa_text('Profiles') . ' - ' . spa_text('Profile Options'));
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Display Name Format'), true, 'display-name-format');
    spa_paint_checkbox(spa_text('Let member choose display name'), 'nameformat', $sfoptions['nameformat']);
    spa_paint_select_start(spa_text('Display name format if member cannot choose') . '<br />' . spa_text('(ignored if member allowed to choose)'), 'fixeddisplayformat', 'fixeddisplayformat');
    echo spa_display_name_format_options($sfoptions['fixeddisplayformat']);
    spa_paint_select_end();
    echo '<tr><td colspan="2"><br /><div class="sfoptionerror">';
    spa_etext('Warning: If you change the display name format, it may take some time on a large number of users to update them to the new format. Please be patient.');
    echo '</div><br />';
    echo '</td></tr>';
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Personal Photos'), true, 'personal-photos');
    spa_paint_input(spa_text('Maximum number of photos allowed'), 'photosmax', $sfoptions['photosmax'], false, false);
    spa_paint_input(spa_text('Maximum pixel width of photo display'), 'photoswidth', $sfoptions['photoswidth'], false, false);
    spa_paint_input(spa_text('Maximum pixel height of photo display'), 'photosheight', $sfoptions['photosheight'], false, false);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Signature Image Size'), true, 'sig-images');
    echo '<tr><td colspan="2">&nbsp;<u>' . spa_text('If you are allowing signature images (zero = not limited)') . ':</u></td></tr>';
    spa_paint_input(spa_text('Maximum signature width (pixels)'), 'sfsigwidth', $sfoptions['sfsigwidth']);
    spa_paint_input(spa_text('Maximum signature height (pixels)'), 'sfsigheight', $sfoptions['sfsigheight']);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('First Forum Visit'), true, 'first-forum-visit');
    spa_paint_checkbox(spa_text('Display profile form on login'), 'firstvisit', $sfoptions['firstvisit']);
    $show_password_fields = apply_filters('show_password_fields', true);
    if ($show_password_fields) {
        spa_paint_checkbox(spa_text('Force password change'), 'forcepw', $sfoptions['forcepw']);
    }
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_profiles_options_left_panel');
    spa_paint_tab_right_cell();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Display Profile Mode'), true, 'display-profile-mode');
    $values = array(spa_text('Popup window'), spa_text('Forum profile page'), spa_text('BuddyPress profile'), spa_text('WordPress author page'), spa_text('Other page'), spa_text('Mingle profile'));
    spa_paint_radiogroup(spa_text('Display profile information in'), 'displaymode', $values, $sfoptions['displaymode'], false, true);
    spa_paint_input(spa_text('URL for Other page'), 'displaypage', sp_filter_url_display($sfoptions['displaypage']), false, true);
    spa_paint_input(spa_text('Query String Variable Name'), 'displayquery', sp_filter_title_display($sfoptions['displayquery']), false, true);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Profile Entry Form Mode'), true, 'profile-entry-form-mode');
    $values = array(spa_text('Forum profile form'), spa_text('WordPress profile form'), spa_text('BuddyPress profile'), spa_text('Other form'), spa_text('Mingle profile'));
    spa_paint_radiogroup(spa_text('Enter profile information In'), 'formmode', $values, $sfoptions['formmode'], false, true);
    spa_paint_input(spa_text('URL for Other page'), 'formpage', sp_filter_url_display($sfoptions['formpage']), false, true);
    spa_paint_input(spa_text('Query string variable name'), 'formquery', sp_filter_title_display($sfoptions['formquery']), false, true);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Profile Overview Message'), true, 'profile-message');
    $submessage = spa_text('Text you enter here will be displayed to the User on their profile overview page');
    spa_paint_wide_textarea(spa_text('Profile overview message'), 'sfprofiletext', sp_filter_text_edit($sfoptions['sfprofiletext']), $submessage);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_profiles_options_right_panel');
    spa_paint_close_container();
    ?>
    	<div class="sfform-submit-bar">
    	   <input type="submit" class="button-primary" id="saveit" name="saveit" value="<?php 
    spa_etext('Update Profile Options');
    ?>
" />
    	</div>
	</form>
<?php 
    spa_paint_close_tab();
}
function spa_usergroups_edit_usergroup_form($usergroup_id)
{
    global $spPaths;
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	jQuery('#usergrouprow-<?php 
    echo $usergroup_id;
    ?>
').addClass('inForm');
    	spjAjaxForm('sfusergroupedit<?php 
    echo $usergroup_id;
    ?>
', 'sfreloadub');
    });
</script>
<?php 
    $usergroup = spa_get_usergroups_row($usergroup_id);
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=usergroups-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=editusergroup';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfusergroupedit<?php 
    echo $usergroup->usergroup_id;
    ?>
" name="sfusergroupedit<?php 
    echo $usergroup->usergroup_id;
    ?>
">
<?php 
    echo sp_create_nonce('forum-adminform_usergroupedit');
    spa_paint_open_tab(spa_text('User Groups') . ' - ' . spa_text('Manage User Groups'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Edit User Group'), 'true', 'edit-user-group');
    ?>
					<input type="hidden" name="usergroup_id" value="<?php 
    echo $usergroup->usergroup_id;
    ?>
" />
					<input type="hidden" name="ugroup_name" value="<?php 
    echo sp_filter_title_display($usergroup->usergroup_name);
    ?>
" />
					<input type="hidden" name="ugroup_desc" value="<?php 
    echo sp_filter_title_display($usergroup->usergroup_desc);
    ?>
" />
					<input type="hidden" name="ugroup_join" value="<?php 
    echo $usergroup->usergroup_join;
    ?>
" />
					<input type="hidden" name="ugroup_ismod" value="<?php 
    echo $usergroup->usergroup_is_moderator;
    ?>
" />
<?php 
    spa_paint_input(spa_text('User Group Name'), 'usergroup_name', sp_filter_title_display($usergroup->usergroup_name), false, true);
    spa_paint_input(spa_text('User Group Description'), 'usergroup_desc', sp_filter_title_display($usergroup->usergroup_desc), false, true);
    spa_paint_select_start(spa_text('Select Badge'), 'usergroup_badge', 'usergroup_badge');
    spa_select_icon_dropdown('usergroup_badge', spa_text('Select Badge'), SF_STORE_DIR . '/' . $spPaths['ranks'] . '/', $usergroup->usergroup_badge, false);
    spa_paint_select_end('<small>(' . spa_text('Upload badges on the Components - Forum Ranks admin panel') . ')</small>');
    spa_paint_checkbox(spa_text('Allow members to join usergroup'), 'usergroup_join', $usergroup->usergroup_join, false, false, false, '<small>' . spa_text('(Indicates that members are allowed to choose to join this usergroup on their profile page)') . '</small>');
    spa_paint_checkbox(spa_text('Is moderator'), 'usergroup_is_moderator', $usergroup->usergroup_is_moderator, false, false, false, '<small>' . spa_text('(Indicates that members of this usergroup are considered Moderators)') . '</small>');
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_usergroup_edit_panel');
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
		<input type="submit" class="button-primary" id="sfusergroupedit<?php 
    echo $usergroup->usergroup_id;
    ?>
" name="sfusergroupedit<?php 
    echo $usergroup->usergroup_id;
    ?>
" value="<?php 
    spa_etext('Update User Group');
    ?>
" />
		<input type="button" class="button-primary" onclick="javascript:jQuery('#usergroup-<?php 
    echo $usergroup->usergroup_id;
    ?>
').html('');jQuery('#usergrouprow-<?php 
    echo $usergroup_id;
    ?>
').removeClass('inForm');" id="sfusergroupedit<?php 
    echo $usergroup->usergroup_id;
    ?>
" name="editusergroupcancel<?php 
    echo $usergroup->usergroup_id;
    ?>
" value="<?php 
    spa_etext('Cancel');
    ?>
" />
		</div>
	</form>
	<?php 
    spa_paint_close_tab();
    ?>

	<div class="sfform-panel-spacer"></div>
<?php 
}
function spa_forums_edit_forum_form($forum_id)
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	jQuery('#forumrow-<?php 
    echo $forum_id;
    ?>
').addClass('inForm');
    	spjAjaxForm('sfforumedit<?php 
    echo $forum_id;
    ?>
', 'sfreloadfb');
    });
</script>
<?php 
    global $spPaths, $tab;
    $forum = spdb_table(SFFORUMS, "forum_id={$forum_id}", 'row');
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=editforum';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfforumedit<?php 
    echo $forum->forum_id;
    ?>
" name="sfforumedit<?php 
    echo $forum->forum_id;
    ?>
">
<?php 
    echo sp_create_nonce('forum-adminform_forumedit');
    spa_paint_open_tab(spa_text('Forums') . ' - ' . spa_text('Manage Groups and Forums'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Forum Details'), false);
    $subforum = $forum->parent ? true : false;
    echo "<input type='hidden' name='cgroup_id' value='{$forum->group_id}' />";
    echo "<input type='hidden' name='cparent' value='{$forum->parent}' />";
    echo "<input type='hidden' name='cchildren' value='{$forum->children}' />";
    if (!$subforum && empty($forum->children)) {
        $mess = sp_text('This is a top-level forum with no sub-forums and on this panel you can change the forum Group it is a member of. If changed it will be moved to the target Forum Group.');
    } elseif (!$subforum && !empty($forum->children)) {
        $mess = sp_text('This is a top level forum with designated sub-forums and on this panel you can change the forum Group it is a member of. If changed it will be moved, along with the sub-forums, to the target Forum Group.');
    } elseif ($subforum && empty($forum->children)) {
        $mess = sp_text('This is a sub-forum and on this panel you can change the forum parent it belongs to. If changed it will be moved to become a sub-forum of the target Forum.');
    } else {
        $mess = sp_text('This is a sub-forum and also a parent to other sub-forums and on this panel you can change the forum parent it belongs to. If changed it will be moved, along with the sub-forums, to the target Forum.');
    }
    echo '<div class="sfoptionerror spaceabove">';
    echo "<p><b>{$mess}</b></br>";
    echo sp_text('For more flexible Group/Forum ordering and sub-forum promotion and demotion, please use the drag and drop interface on the Order Groups and Forums admin panel from the Forums Menu - or the Order Forums panel at Group level.') . '</p>';
    echo '</div>';
    # Top level forum...
    $style = $subforum ? ' style="display:none"' : ' style="display:block"';
    echo "<div {$style}>";
    spa_paint_select_start(spa_text('The group this forum belongs to'), 'group_id', '');
    echo spa_create_group_select($forum->group_id);
    spa_paint_select_end();
    echo '</div>';
    # sub-forum...
    $style = $subforum ? ' style="display:block"' : ' style="display:none"';
    echo "<div {$style}>";
    spa_paint_select_start(spa_text('Parent forum this subforum belongs to'), 'parent', '');
    echo spa_create_forum_select($forum->parent);
    spa_paint_select_end();
    echo '</div>';
    spa_paint_input(spa_text('Forum name'), 'forum_name', sp_filter_title_display($forum->forum_name), false, true);
    echo '<input type="hidden" name="forum_id" value="' . $forum->forum_id . '" />';
    $target = 'cforum_slug';
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums&amp;sfnonce=' . wp_create_nonce('forum-ahah');
    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="cforum_slug" id="cforum_slug" value="' . esc_attr($forum->forum_slug) . '" onchange="spjSetForumSlug(this, \'' . $ahahURL . '\', \'' . $target . '\', \'edit\');" />';
    echo '<div class="clearboth"></div>';
    echo '</div>';
    $tab++;
    spa_paint_input(spa_text('Description'), 'forum_desc', sp_filter_text_edit($forum->forum_desc), false, true);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Forum Options'), false);
    $target = 'cforum_slug';
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums&amp;sfnonce=' . wp_create_nonce('forum-ahah');
    spa_paint_checkbox(spa_text('Locked'), 'forum_status', $forum->forum_status);
    spa_paint_checkbox(spa_text('Disable forum RSS feed so feed will not be generated'), 'forum_private', $forum->forum_rss_private);
    spa_paint_select_start(sprintf(spa_text('Featured Image for this forum %s(200px x 200px recommended)'), '<br>'), 'feature_image', '');
    spa_select_icon_dropdown('feature_image', spa_text('Select Feature Image'), SF_STORE_DIR . '/' . $spPaths['forum-images'] . '/', $forum->feature_image, false);
    spa_paint_select_end();
    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'] . '/', $forum->forum_icon, 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'] . '/', $forum->forum_icon_new, 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'] . '/', $forum->forum_icon_locked, 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'] . '/', $forum->topic_icon, 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'] . '/', $forum->topic_icon_new, 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'] . '/', $forum->topic_icon_locked, 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'] . '/', $forum->topic_icon_pinned, false);
    spa_paint_select_end();
    spa_paint_input(spa_text('Replacement external RSS URL') . '<br />' . spa_text('Default') . ': <strong>' . sp_build_url($forum->forum_slug, '', 0, 0, 0, 1) . '</strong>', 'forum_rss', sp_filter_url_display($forum->forum_rss), false, true);
    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', sp_filter_text_edit($forum->forum_message));
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Extended Forum Options'), false);
    # As added by plugins
    do_action('sph_forum_edit_forum_options', $forum);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
    		<input type="submit" class="button-primary" id="sfforumedit<?php 
    echo $forum->forum_id;
    ?>
" name="sfforumedit<?php 
    echo $forum->forum_id;
    ?>
" value="<?php 
    spa_etext('Update Forum');
    ?>
" />
    		<input type="button" class="button-primary" onclick="javascript:jQuery('#forum-<?php 
    echo $forum->forum_id;
    ?>
').html('');jQuery('#forumrow-<?php 
    echo $forum_id;
    ?>
').removeClass('inForm');" id="sfforumedit<?php 
    echo $forum->forum_id;
    ?>
" name="editforumcancel<?php 
    echo $forum->forum_id;
    ?>
" value="<?php 
    spa_etext('Cancel');
    ?>
" />
		</div>
	<?php 
    spa_paint_close_tab();
    ?>
	</form>
	<div class="sfform-panel-spacer"></div>
<?php 
}
function spa_integration_page_form()
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('wppageform', 'sfreloadpp');
    });
</script>
<?php 
    $sfoptions = spa_get_integration_page_data();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=integration-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=page';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="wppageform" name="wppage">
	<?php 
    echo sp_create_nonce('forum-adminform_integration');
    spa_paint_options_init();
    spa_paint_open_tab(spa_text('Integration') . ' - ' . spa_text('Page and Permalink'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('WP Forum Page Details'), true, 'forum-page-details');
    if ($sfoptions['sfpage'] == 0) {
        echo '<tr><td colspan="2"><div class="sfoptionerror">' . spa_text('ERROR: The page slug is either missing or incorrect. The forum will not display until this is corrected') . '</div></td></tr>';
    }
    spa_paint_select_start(spa_text('Select the WP Page to be used to display your forum'), 'slug', 'slug');
    echo spa_create_page_select($sfoptions['sfpage']);
    spa_paint_select_end();
    spa_paint_close_fieldset();
    if ($sfoptions['sfpage'] != 0) {
        $title = spdb_table(SFWPPOSTS, 'ID=' . $sfoptions['sfpage'], 'post_title');
        $template = spdb_table(SFWPPOSTMETA, "meta_key='_wp_page_template' AND post_id=" . $sfoptions['sfpage'], 'meta_value');
        spa_paint_open_fieldset(spa_text('Current WP Forum Page'), false);
        echo '<table class="form-table"><tr>';
        echo '<th>' . spa_text('Forum page ID') . '</th>';
        echo '<th>' . spa_text('Page title') . '</th>';
        echo '<th>' . spa_text('Page template') . '</th>';
        echo '</tr>';
        echo '<tr>';
        echo '<td class="sflabel">' . $sfoptions['sfpage'] . '</td>';
        echo '<td class="sflabel">' . $title . '</td>';
        echo '<td class="sflabel">' . $template . '</td>';
        echo '</tr></table>';
        spa_paint_close_fieldset();
        spa_paint_open_fieldset(spa_text('Update Forum Permalink'), true, 'forum-permalink');
        echo '<p class="sublabel">' . spa_text('Current permalink') . ':<br /></p><div class="subhead" id="adminupresult"><p>' . $sfoptions['sfpermalink'] . '</p></div><br />';
        spa_paint_update_permalink();
        spa_paint_close_fieldset();
    }
    spa_paint_close_panel();
    spa_paint_close_tab();
    spa_paint_spacer();
    spa_paint_open_tab(spa_text('Integration') . ' - ' . spa_text('WordPress and WordPress Theme'), false);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Integration Options'), true, 'integration-options');
    spa_paint_checkbox(spa_text('Filter WP list pages'), 'sfwplistpages', $sfoptions['sfwplistpages']);
    spa_paint_checkbox(spa_text('Load javascript in footer'), 'sfscriptfoot', $sfoptions['sfscriptfoot']);
    spa_paint_checkbox(spa_text('Force the strict use of the WP API'), 'sfuseob', $sfoptions['sfuseob']);
    spa_paint_checkbox(spa_text('Run the wptexturize formatting on post content'), 'spwptexturize', $sfoptions['spwptexturize']);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_tab_right_cell();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Theme Display Options'), true, 'theme-options');
    spa_paint_checkbox(spa_text('Limit forum display to within WP loop'), 'sfinloop', $sfoptions['sfinloop']);
    spa_paint_checkbox(spa_text('Allow multiple loading of forum content'), 'sfmultiplecontent', $sfoptions['sfmultiplecontent']);
    spa_paint_input(spa_text('Compensate (in pixels) for fixed WP theme header'), 'spheaderspace', $sfoptions['spheaderspace'], false, false);
    spa_paint_checkbox(spa_text('Bypass wp_head action complete requirement'), 'sfwpheadbypass', $sfoptions['sfwpheadbypass']);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_integration_panel');
    spa_paint_close_container();
    ?>
	<div class="sfform-submit-bar">
	<input type="submit" class="button-primary" id="saveit" name="saveit" value="<?php 
    spa_etext('Update WP Integration');
    ?>
" />
	</div>
<?php 
    spa_paint_close_tab();
    ?>
	</form>
<?php 
}
function spa_options_content_form()
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfcontentform', '');
    });
</script>
<?php 
    $sfoptions = spa_get_content_data();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=options-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=content';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfcontentform" name="sfcontent">
	<?php 
    echo sp_create_nonce('forum-adminform_content');
    spa_paint_options_init();
    #== POSTS Tab ============================================================
    spa_paint_open_tab(spa_text('Options') . ' - ' . spa_text('Content Settings'));
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Date/Time Formatting'), true, 'date-time-formatting');
    spa_paint_input(spa_text('Date display format'), 'sfdates', $sfoptions['sfdates']);
    spa_paint_input(spa_text('Time display format'), 'sftimes', $sfoptions['sftimes']);
    spa_paint_link('http://codex.wordpress.org/Formatting_Date_and_Time', spa_text('Date/Time help'));
    $tz = get_option('timezone_string');
    if (empty($tz)) {
        $tz = spa_text('Unknown');
    }
    echo '&nbsp;' . spa_text('Server timezone set to') . ': ' . $tz;
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Image Enlargement'), true, 'image-enlarging');
    spa_paint_checkbox(spa_text('Use popup image enlargement'), 'sfimgenlarge', $sfoptions['sfimgenlarge']);
    spa_paint_checkbox(spa_text('Constrain popup enlargement to current window size'), 'constrain', $sfoptions['constrain']);
    spa_paint_checkbox(spa_text('Always use image thumbnails'), 'process', $sfoptions['process']);
    spa_paint_input(spa_text('Thumbnail width of images in posts (Minimum 100px)'), 'sfthumbsize', $sfoptions['sfthumbsize']);
    spa_paint_select_start(spa_text('Default image style'), 'style', 'style');
    echo spa_create_imagestyle_select($sfoptions['style']);
    spa_paint_select_end();
    spa_paint_checkbox(spa_text('Force paragraph after an image to start new line'), 'forceclear', $sfoptions['forceclear']);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Smileys'), true, 'smileys');
    spa_paint_input(spa_text('Maximum smileys allowed in post (0 = unlimited)'), 'sfmaxsmileys', $sfoptions['sfmaxsmileys']);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Spam Posts'), true, 'spam-post');
    spa_paint_checkbox(spa_text('Refuse duplicate post made by member'), 'sfdupemember', $sfoptions['sfdupemember']);
    spa_paint_checkbox(spa_text('Refuse duplicate post made by guest'), 'sfdupeguest', $sfoptions['sfdupeguest']);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_options_content_left_panel');
    spa_paint_tab_right_cell();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Additional Filtering'), true, 'additional-filters');
    spa_paint_checkbox(spa_text('Filter out HTML pre tags'), 'sffilterpre', $sfoptions['sffilterpre']);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Post Links Filtering'), true, 'post-links-filtering');
    spa_paint_input(spa_text('Maximum links allowed in post (0 = unlimited)'), 'sfmaxlinks', $sfoptions['sfmaxlinks']);
    spa_paint_checkbox(spa_text('Add nofollow to links'), 'sfnofollow', $sfoptions['sfnofollow']);
    spa_paint_checkbox(spa_text('Open links in new tab/window'), 'sftarget', $sfoptions['sftarget']);
    spa_paint_input(spa_text('URL shortening limit (0 = not shortened)'), 'sfurlchars', $sfoptions['sfurlchars']);
    $submessage = spa_text("If post viewer doesn't have view links permission, this custom message will be displayed instead");
    spa_paint_textarea(spa_text('Hidden links custom message'), 'sfnolinksmsg', $sfoptions['sfnolinksmsg'], $submessage, 3);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Shortcodes Filtering'), true, 'shortcode-filters');
    spa_paint_checkbox(spa_text('Filter WP shortcodes (if disabled ALL WP shortcodes will be passed)'), 'sffiltershortcodes', $sfoptions['sffiltershortcodes']);
    $submessage = spa_text('Enter allowed WP shortcodes (if filtering enabled above) - one shortcode per line.');
    spa_paint_textarea(spa_text('Allowed WP shortcodes in posts'), 'sfshortcodes', $sfoptions['sfshortcodes'], $submessage, 3);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_options_content_right_panel');
    spa_paint_close_container();
    ?>
	<div class="sfform-submit-bar">
	<input type="submit" class="button-primary" id="saveit" name="saveit" value="<?php 
    spa_etext('Update Content Options');
    ?>
" />
	</div>
<?php 
    spa_paint_close_tab();
    ?>
	</form>
<?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_themes_mobile_form()
{
    global $spPaths;
    ?>
	<script type="text/javascript">
		jQuery(document).ready(function() {
		spjAjaxForm('sfmobiletheme', 'sfreloadmlist');
		});
	</script>
<?php 
    # get current theme
    $mobileTheme = sp_get_option('sp_mobile_theme');
    if (!isset($mobileTheme['active'])) {
        $mobileTheme['active'] = false;
    }
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=themes-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=mobile';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfmobiletheme" name="sfmobiletheme">
	<?php 
    echo sp_create_nonce('forum-adminform_themes');
    spa_paint_options_init();
    spa_paint_open_tab(spa_text('Mobile Theme Support') . ' - ' . spa_text('Mobile Theme'));
    spa_paint_open_panel();
    spa_paint_spacer();
    echo '<div class="sfoptionerror">';
    echo spa_text('Themes Folder') . ': <b>wp-content/' . $spPaths['themes'] . '</b>';
    echo '</div>';
    spa_paint_open_fieldset(spa_text('Mobile Support'), true, 'mobile-support');
    spa_paint_checkbox(spa_text('Enable mobile theme support'), 'active', $mobileTheme['active']);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_tab_right_cell();
    spa_paint_open_panel();
    if ($mobileTheme['active']) {
        require_once ABSPATH . 'wp-admin/includes/template.php';
        require_once ABSPATH . 'wp-admin/includes/theme.php';
        spa_paint_open_fieldset(spa_text('Mobile Display Options'), true, 'mobile-display');
        spa_paint_checkbox(spa_text('Use alternate WordPress template'), 'usetemplate', $mobileTheme['usetemplate']);
        spa_paint_select_start(spa_text('Alternate page template'), 'pagetemplate', 'pagetemplate');
        echo '<option value="page.php">' . spa_text('Default Template') . '</option>';
        page_template_dropdown($mobileTheme['pagetemplate']);
        spa_paint_select_end();
        spa_paint_checkbox(spa_text('Remove Page Title Completely'), 'notitle', $mobileTheme['notitle']);
        spa_paint_close_fieldset();
    }
    spa_paint_close_panel();
    do_action('sph_themes_mobile_option_panel');
    spa_paint_close_container();
    ?>
	<div class="sfform-submit-bar">
	<input type="submit" class="button-primary" id="saveit" name="saveit" value="<?php 
    spa_etext('Update Mobile Component');
    ?>
" />
	</div>
	<?php 
    spa_paint_close_tab();
    ?>
	</form>
	<div class="sfform-panel-spacer"></div>
<?php 
    if ($mobileTheme['active']) {
        # get themes
        $themes = sp_get_themes_list_data();
        # get update version info
        $xml = sp_load_version_xml();
        spa_paint_open_tab(spa_text('Available Themes') . ' - ' . spa_text('Select Simple:Press Mobile Theme'), true);
        spa_paint_open_panel();
        spa_paint_open_fieldset(spa_text('Mobile Theme Management'), true, 'themes');
        ?>
		<h3><?php 
        echo spa_text('Current Mobile Theme');
        ?>
</h3>
		<div class="theme-browser rendered">
		<div class="spThemeContainer">
		<div id="current-theme" class="spTheme">

		<h3 class="theme-name"><?php 
        echo $themes[$mobileTheme['theme']]['Name'];
        ?>
</h3>
		<img src="<?php 
        echo SPTHEMEBASEURL . $mobileTheme['theme'] . '/' . $themes[$mobileTheme['theme']]['Screenshot'];
        ?>
" alt="" />
		<h4>
		<?php 
        echo $themes[$mobileTheme['theme']]['Name'] . ' ' . $themes[$mobileTheme['theme']]['Version'] . ' ' . spa_text('by') . ' <a href="' . $themes[$mobileTheme['theme']]['AuthorURI'] . '" title="' . spa_text('Visit author homepage') . '">' . $themes[$mobileTheme['theme']]['Author'] . '</a>';
        ?>
		</h4>
<?php 
        if (!empty($mobileTheme['parent'])) {
            if (file_exists(SPTHEMEBASEDIR . $mobileTheme['parent'])) {
                echo '<p class="theme-parent">';
                echo spa_text('This theme is a child theme of ') . '<b>' . $mobileTheme['parent'] . '</b>';
                echo '</p>';
            } else {
                echo '<p class="theme-parent">';
                echo '<b>' . spa_text('The specified parent theme') . " '" . $mobileTheme['parent'] . "' " . spa_text('does not exist') . '</b> ';
                echo '</p>';
            }
        }
        ?>
		<p class="description" style="padding: 0;">
		<?php 
        echo $themes[$mobileTheme['theme']]['Description'];
        ?>
		</p>
<?php 
        $overlays = sp_get_overlays(SPTHEMEBASEDIR . $mobileTheme['theme'] . '/styles/overlays');
        # pull in parent overlays if child theme
        if (!empty($mobileTheme['parent'])) {
            $parent_overlays = sp_get_overlays(SPTHEMEBASEDIR . $mobileTheme['parent'] . '/styles/overlays');
            $overlays = array_merge($overlays, $parent_overlays);
        }
        if (!empty($overlays)) {
            ?>
			<script type="text/javascript">
				jQuery(document).ready(function() {
					jQuery('#sftheme-<?php 
            echo esc_js($mobileTheme['theme']);
            ?>
').ajaxForm({
						target: '#sfmsgspot',
						success: function() {
							jQuery('#sfreloadmlist').click();
							jQuery('#sfmsgspot').fadeIn();
							jQuery('#sfmsgspot').fadeOut(6000);
						}
					});
				});
			</script>
			<br>
<?php 
            $ahahURL = SFHOMEURL . 'index.php?sp_ahah=themes-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=mobile';
            echo '<form action="' . $ahahURL . '" method="post" id="sftheme-' . esc_attr($mobileTheme['theme']) . '" name="sftheme-' . esc_attr($mobileTheme['theme']) . '">';
            echo sp_create_nonce('forum-adminform_themes');
            echo '<input type="hidden" name="active" value="' . $mobileTheme['active'] . '" />';
            echo '<input type="hidden" name="theme" value="' . esc_attr($mobileTheme['theme']) . '" />';
            echo '<input type="hidden" name="style" value="' . esc_attr($themes[$mobileTheme['theme']]['Stylesheet']) . '" />';
            echo '<input type="hidden" name="parent" value="' . esc_attr($mobileTheme['parent']) . '" />';
            $theme_colors = empty($themes[$mobileTheme['theme']]['Colors']) ? '' : explode(',', $themes[$mobileTheme['theme']]['Colors']);
            echo '<input type="hidden" name="default-color" value="' . esc_attr($overlays[0]) . '" />';
            echo spa_text('Select Overlay') . ': ';
            echo '<select name="color-' . esc_attr($mobileTheme['theme']) . '">';
            foreach ($overlays as $overlay) {
                $overlay = trim($overlay);
                $selected = $mobileTheme['color'] == $overlay ? ' selected="selected" ' : '';
                echo '<option' . $selected . ' value="' . esc_attr($overlay) . '">' . esc_html($overlay) . '</option>';
            }
            echo '</select> ';
            echo ' <input type="submit" class="button-secondary action" id="saveit-cur" name="saveit-cur" value="' . spa_text('Update Overlay') . '" />';
            echo '</form>';
        }
        # any upgrade for this theme?  in multisite only main site can update
        if (is_main_site() && $xml) {
            foreach ($xml->themes->theme as $latest) {
                if ($themes[$mobileTheme['theme']]['Name'] == $latest->name) {
                    if (version_compare($latest->version, $themes[$mobileTheme['theme']]['Version'], '>') == 1) {
                        echo '<br />';
                        echo '<p style="padding: 0;">';
                        echo '<strong>' . spa_text('There is an update for the') . ' ' . $themes[$mobileTheme['theme']]['Name'] . ' ' . spa_text('theme') . '.</strong> ';
                        echo spa_text('Version') . ' ' . $latest->version . ' ' . spa_text('is available') . '. ';
                        echo spa_text('For details and to download please visit') . ' ' . SFPLUGHOME . ' ' . spa_text('or') . ' ' . spa_text('go to the') . ' ';
                        echo '<a href="' . self_admin_url('update-core.php') . '" title="" target="_parent">' . spa_text('WordPress updates page') . '</a>';
                        echo '</p>';
                    }
                    break;
                }
            }
        }
        ?>
		</div></div></div>

		<br class="clear" />

		<h3><?php 
        echo spa_text('Available Themes');
        ?>
</h3>
<?php 
        $numThemes = count($themes);
        if ($numThemes > 1) {
            ?>
			<div class="theme-browser rendered">
			<div class="spThemeContainer">
<?php 
            foreach ((array) $themes as $theme_file => $theme_data) {
                # skip cur theme
                if ($theme_file == $mobileTheme['theme']) {
                    continue;
                }
                $theme_desc = $theme_data['Description'];
                $theme_name = $theme_data['Name'];
                $theme_version = $theme_data['Version'];
                $theme_author = $theme_data['Author'];
                $theme_uri = $theme_data['AuthorURI'];
                $theme_style = $theme_data['Stylesheet'];
                $theme_image = SPTHEMEBASEURL . $theme_file . '/' . $theme_data['Screenshot'];
                $theme_overlays = sp_get_overlays(SPTHEMEBASEDIR . $theme_file . '/styles/overlays');
                # pull in parent overlays if child theme
                if (!empty($theme_data['Parent'])) {
                    $parent_overlays = sp_get_overlays(SPTHEMEBASEDIR . $theme_data['Parent'] . '/styles/overlays');
                    $theme_overlays = array_merge($theme_overlays, $parent_overlays);
                }
                ?>
				<div class="spTheme">
				<h3 class="theme-name"><?php 
                echo $theme_name;
                ?>
</h3>
				<img alt="" src="<?php 
                echo $theme_image;
                ?>
" />
				<h4>
				<?php 
                echo $theme_name . ' ' . $theme_version . ' ' . spa_text('by') . ' <a href="' . $theme_uri . '" title="' . spa_text('Visit author homepage') . '">' . $theme_author . '</a>';
                ?>
				</h4>
<?php 
                if (!empty($theme_data['Parent'])) {
                    if (file_exists(SPTHEMEBASEDIR . $theme_data['Parent'])) {
                        echo '<p class="theme-parent">';
                        echo spa_text('This theme is a child theme of ') . '<b>' . $theme_data['Parent'] . '</b>';
                        echo '</p>';
                    } else {
                        echo '<p class="theme-parent">';
                        echo '<b>' . spa_text('The specified parent theme') . " '" . $theme_data['Parent'] . "' " . spa_text('does not exist') . '</b> ';
                        echo '</p>';
                    }
                }
                ?>
				<p class="description" style="padding: 0;">
				<?php 
                echo $theme_desc;
                ?>
				</p>
				<br>
				<div class="action-links">
				<script type="text/javascript">
					jQuery(document).ready(function() {
						spjAjaxForm('sftheme-<?php 
                echo esc_js($theme_file);
                ?>
', 'sfreloadmlist');
					});
				</script>
				<?php 
                $ahahURL = SFHOMEURL . 'index.php?sp_ahah=themes-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=mobile';
                ?>
				<form action="<?php 
                echo $ahahURL;
                ?>
" method="post" id="sftheme-<?php 
                echo esc_attr($theme_file);
                ?>
" name="sftheme-<?php 
                echo esc_attr($theme_file);
                ?>
">
				<?php 
                echo sp_create_nonce('forum-adminform_themes');
                ?>
				<input type="hidden" name="active" value="<?php 
                echo $mobileTheme['active'];
                ?>
" />
				<input type="hidden" name="theme" value="<?php 
                echo esc_attr($theme_file);
                ?>
" />
				<input type="hidden" name="style" value="<?php 
                echo esc_attr($theme_style);
                ?>
" />
				<input type="hidden" name="parent" value="<?php 
                echo esc_attr($theme_data['Parent']);
                ?>
" />
				<?php 
                $defOverlay = !empty($theme_overlays) ? esc_attr($theme_overlays[0]) : 0;
                ?>
				<input type="hidden" name="default-color" value="<?php 
                echo esc_attr($defOverlay);
                ?>
" />
<?php 
                if ($theme_overlays) {
                    echo spa_text('Select Overlay') . ': ';
                    echo ' <select name="color-' . esc_attr($theme_file) . '" style="margin-bottom:5px;">';
                    foreach ($theme_overlays as $theme_overlay) {
                        $theme_overlay = trim($theme_overlay);
                        $selected = $theme_overlays[0] == $theme_overlay ? ' selected="selected" ' : '';
                        echo '<option' . $selected . ' value="' . esc_attr($theme_overlay) . '">' . esc_html($theme_overlay) . '</option>';
                    }
                    echo '</select> ';
                    echo '<div class="clearboth"></div>';
                }
                ?>
				<input type="submit" class="button-secondary action" id="saveit-<?php 
                echo esc_attr($theme_file);
                ?>
" name="saveit-<?php 
                echo esc_attr($theme_file);
                ?>
" value="<?php 
                echo spa_etext('Activate Mobile Theme');
                ?>
" />
				</form>
				</div>
<?php 
                # any upgrade for this theme?
                if ($xml) {
                    foreach ($xml->themes->theme as $latest) {
                        if ($theme_data['Name'] == $latest->name) {
                            if (version_compare($latest->version, $theme_data['Version'], '>') == 1) {
                                echo '<br />';
                                echo '<div class="plugin-update-tr"><div class="update-message" style="background-color:#fcf3ef;margin-left:10px;">';
                                echo '<strong>' . spa_text('There is an update for the') . ' ' . $theme_data['Name'] . ' ' . spa_text('theme') . '.</strong> ';
                                echo spa_text('Version') . ' ' . $latest->version . ' ' . spa_text('is available') . '. ';
                                echo spa_text('For details and to download please visit') . ' ' . SFPLUGHOME . ' ' . spa_text('or') . ' ' . spa_text('go to the') . ' ';
                                echo '<a href="' . self_admin_url('update-core.php') . '" title="" target="_parent">' . spa_text('WordPress updates page') . '</a>';
                                echo '</div></div>';
                            }
                            break;
                        }
                    }
                }
                echo '</div>';
            }
            echo '</div>';
            echo '</div>';
        } else {
            echo spa_text('No other available themes found');
        }
        do_action('sph_themes_mobile_list_panel');
        spa_paint_close_fieldset();
        spa_paint_close_panel();
        spa_paint_close_container();
        spa_paint_close_tab();
    }
}
function spa_usergroups_map_users()
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	jQuery('#sfmapsettingsform').ajaxForm({
    		target: '#sfmsgspot',
    		success: function() {
    			jQuery('#sfreloadmu').click();
    			jQuery('#sfmsgspot').fadeIn();
    			jQuery('#sfmsgspot').fadeOut(6000);
    		}
    	});
    	jQuery('#sfmapusersform').ajaxForm({
    		target: '#sfmsgspot',
    	});
    });
</script>
<?php 
    global $wp_roles;
    $sfoptions = spa_get_mapping_data();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=usergroups-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=mapsettings';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfmapsettingsform" name="sfmapsettingsform">
	<?php 
    echo sp_create_nonce('forum-adminform_mapusers');
    spa_paint_options_init();
    spa_paint_open_tab(spa_text('User Groups') . ' - ' . spa_text('User Mapping Settings'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('User Memberships'), true, 'user-memberships');
    echo '<tr><td colspan="2"><br /><div class="sfoptionerror">';
    spa_etext('Warning: Use caution when setting the single usergroup membership option below. It should primarily be used in conjunction with a membership plugin (such as Wishlist) where strict usergroup membership is required.  Please note that auto usergroup membership by WP role or by forum rank may conflict or overwrite any manual usergroup memberships (such as moderator) you may set if you have single usergroup membership set');
    echo '</div><br />';
    echo '</td></tr>';
    spa_paint_checkbox(spa_text('Users are limited to single usergroup membership'), 'sfsinglemembership', $sfoptions['sfsinglemembership']);
    echo '<tr><td colspan="2"><p class="subhead">' . spa_text('Default usergroup membership') . ':</p></td></tr>';
    spa_paint_select_start(spa_text('Default usergroup for guests'), 'sfguestsgroup', 'sfguestsgroup');
    echo spa_create_usergroup_select($sfoptions['sfguestsgroup']);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Default usergroup for new members'), 'sfdefgroup', 'sfdefgroup');
    echo spa_create_usergroup_select($sfoptions['sfdefgroup']);
    spa_paint_select_end();
    $roles = array_keys($wp_roles->role_names);
    if ($roles) {
        echo '<tr><td colspan="2"><p class="subhead">' . spa_text('Usergroup memberships based on WP role') . ':</p></td></tr>';
        $sfoptions['role'] = array();
        foreach ($roles as $index => $role) {
            $value = sp_get_sfmeta('default usergroup', $role);
            if ($value) {
                $group = $value[0]['meta_value'];
            } else {
                $group = $sfoptions['sfdefgroup'];
            }
            echo '<input type="hidden" class="sfhiddeninput" name="sfoldrole[' . $index . ']" value="' . $group . '" />';
            spa_paint_select_start(spa_text('Default usergroup for') . ' ' . $role, "sfrole[{$index}]", 'sfguestsgroup');
            echo spa_create_usergroup_select($group);
            spa_paint_select_end();
        }
    }
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_usergroups_mapping_settings_panel');
    spa_paint_close_container();
    ?>
	<div class="sfform-submit-bar">
	<input type="submit" class="button-primary" id="saveit" name="saveit" value="<?php 
    spa_etext('Update Mapping Settings');
    ?>
" />
	</div>
	</form>
	<?php 
    spa_paint_close_tab();
    ?>

	<div class="sfform-panel-spacer"></div>
<?php 
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=usergroups-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=mapusers';
    $uCount = spdb_count(SFMEMBERS);
    $url = SFHOMEURL . 'index.php?sp_ahah=usermapping&amp;sfnonce=' . wp_create_nonce('forum-ahah');
    $target = 'sfmsgspot';
    $smessage = esc_js(spa_text('Please Wait - Processing'));
    $emessage = $uCount . ' ' . esc_js(spa_text('Users mapped'));
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfmapusersform" name="sfmapusersform" onsubmit="spjBatch('sfmapusersform', '<?php 
    echo $url;
    ?>
', '<?php 
    echo $target;
    ?>
', '<?php 
    echo $smessage;
    ?>
', '<?php 
    echo $emessage;
    ?>
', 0, 500, <?php 
    echo $uCount;
    ?>
);">
<?php 
    echo sp_create_nonce('forum-adminform_mapusers');
    spa_paint_options_init();
    spa_paint_open_tab(spa_text('User Groups') . ' - ' . spa_text('Map Users'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Map Users'), true, 'map-users');
    echo '<tr><td colspan="2"><br /><div class="sfoptionerror">';
    spa_etext("Warning: Use caution when mapping users. This will adjust your user's memberships in User Groups. Choose the criteria and options carefully. The mapping cannot be undone except by remapping or manual process. Also, make sure you have saved your mapping settings above before mapping as they are two distinct actions.");
    echo '</div><br />';
    echo '</td></tr>';
    $values = array(spa_text('Add user membership based on WP role to existing memberships'), spa_text('Replace all user memberships with a single membership based on WP role'));
    spa_paint_radiogroup(spa_text('Select mapping criteria'), 'mapoption', $values, 2, false, true);
    spa_paint_checkbox(spa_text('Ignore current SP Moderators when mapping'), 'ignoremods', true);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_usergroups_map_users_panel');
    spa_paint_close_container();
    ?>
    	<div class="sfform-submit-bar">
        	<span><input type="submit" class="button-primary" id="saveit2" name="saveit2" value="<?php 
    spa_etext('Map Users');
    ?>
" /> <span class="button sfhidden" id='onFinish'></span></span>
        	<br />
        	<div class="pbar" id="progressbar"></div>
    	</div>
	</form>
<?php 
    spa_paint_close_tab();
}
function spa_integration_language_form()
{
    include_once SF_PLUGIN_DIR . '/admin/library/sp-languages.php';
    global $siteLang, $locale;
    # Get user language setting
    $siteLang = $locale;
    if (!empty($siteLang)) {
        $siteLang = substr($siteLang, 6);
        foreach ($langSets as $lKey => $lName) {
            if (strpos($siteLang, $lKey) != 0) {
                $siteLang = $lKey;
                break;
            }
        }
    }
    if (empty($siteLang) || $siteLang == 'en_US' || $siteLang == 'en-US' || $siteLang == 'en') {
        echo '<br /><div class="sfoptionerror">';
        spa_etext('Your site language setting is English/US and therefore no translation files are required for Simple:Press');
        echo '</div>';
        return;
    }
    # check we can download
    if (ini_get('allow_url_fopen') == false) {
        echo '<br /><div class="sfoptionerror">';
        spa_etext('Your server will not allow us to download the language files from Simple:Press');
        echo '</div>';
        return;
    }
    $userLang = array();
    $userLang['spLang'] = $siteLang;
    $userLang['spRTL'] = is_rtl();
    $formLang = '';
    $displayLang = '';
    spa_paint_open_tab(spa_text('Integration') . ' - ' . spa_text('Language Settings'));
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Language'), true, 'language-select');
    if (!empty($userLang) && array_key_exists($userLang['spLang'], $langSets)) {
        $formLang = $userLang['spLang'];
    } elseif (array_key_exists($siteLang, $langSets)) {
        $formLang = $siteLang;
    }
    if (!empty($formLang)) {
        foreach ($langSets as $lKey => $lName) {
            if ($formLang == $lKey) {
                $displayLang = $lName;
            }
        }
    }
    if (empty($formLang)) {
        echo '<br /><div class="sfoptionerror">';
        spa_etext('Your site language setting has not been recognised by Simple:Press. Please select the correct language from the available list');
        echo '</div>';
        spa_paint_select_start(spa_text('Your site language setting') . ' - <b>' . $formLang . '</b>', 'spLang', '');
        foreach ($langSets as $lKey => $lName) {
            $sel = $formLang == $lKey ? ' selected="selected" ' : '';
            echo '<option value="' . $lKey . '"' . $sel . '>' . $lName . '</option>';
        }
        spa_paint_select_end();
    } else {
        echo '<br /><div class="sfoptionerror">';
        echo spa_text('Your site language is set to') . ' <b>' . $formLang . ' - ' . $displayLang . '</b>';
        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>';
    # Now stop if we still do not know the language
    if (empty($userLang['spLang'])) {
        return;
    }
    # load up the XML file
    $c = wp_remote_get('http://simple-press.com/downloads/simple-press/simple-press.xml');
    if (is_wp_error($c) || wp_remote_retrieve_response_code($c) != 200) {
        echo '<p>' . spa_text('Unable to communicate with Simple Press server') . '</p>';
        return;
    }
    $l = new SimpleXMLElement($c['body']);
    if (empty($l)) {
        echo '<p>' . spa_text('Unable to communicate with Simple Press server') . '</p>';
        return;
    }
    # Core, theme and plugin lists and downloads
    $gif = SFCOMMONIMAGES . 'working.gif';
    $site = SFHOMEURL . 'index.php?sp_ahah=integration-langs&amp;sfnonce=' . wp_create_nonce('forum-ahah');
    $x = 0;
    spa_paint_open_tab(spa_text('Integration') . ' - ' . spa_text('Language Translations'), true);
    spa_paint_open_panel();
    echo '<br />';
    echo '&nbsp;&nbsp;<img src="' . SFADMINIMAGES . 'sp_Yes.png" title="' . spa_text('Translation file installed') . '" alt="" style="vertical-align: middle;" />&nbsp;&nbsp;' . spa_text('Translation file installed');
    echo '&nbsp;&nbsp;<img src="' . SFADMINIMAGES . 'sp_No.png" title="' . spa_text('No Translation file installed') . '" alt="" style="vertical-align: middle;" />&nbsp;&nbsp;' . spa_text('No Translation file installed');
    # Core - front and admin
    spa_paint_open_fieldset(spa_text('Core Simple:Press'), false);
    $item = $l->core;
    $version = $item->version;
    echo '<table class="wp-list-table widefat">';
    echo '<tr><td width="50%"><b>Core: Simple:Press ' . $version . '</b></td>';
    $thisItem = $site . '&amp;item=corefront&amp;version=' . str_replace('.', '', $version) . '&amp;langcode=' . $userLang['spLang'] . '&amp;textdom=sp';
    $target = 'spItem' . $x;
    $x++;
    echo '<td><span id="' . $target . '">';
    if (sp_check_for_mo('language-sp', 'sp', $thisItem, $target) ? $btext = spa_text('Get Latest') : ($btext = spa_text('Install'))) {
    }
    echo '&nbsp;&nbsp;';
    echo '<input type="button" class="logDetail button" value="' . $btext . '" onclick="spjLoadAhah(\'' . $thisItem . '\', \'' . $target . '\', \'' . $gif . '\');" /></span></td></tr>';
    echo '<tr class="alternate"><td width="50%"><b>Core: Administration ' . $version . '</b></td>';
    $thisItem = $site . '&amp;item=coreadmin&amp;version=' . str_replace('.', '', $version) . '&amp;langcode=' . $userLang['spLang'] . '&amp;textdom=spa';
    $target = 'spItem' . $x;
    $x++;
    echo '<td><span id="' . $target . '">';
    if (sp_check_for_mo('language-sp', 'spa', $thisItem, $target) ? $btext = spa_text('Get Latest') : ($btext = spa_text('Install'))) {
    }
    echo '&nbsp;&nbsp;';
    echo '<input type="button" class="logDetail button" value="' . $btext . '" onclick="spjLoadAhah(\'' . $thisItem . '\', \'' . $target . '\', \'' . $gif . '\');" /></span></td></tr>';
    echo '</table>';
    spa_paint_close_fieldset();
    # Themes in use
    spa_paint_open_fieldset(spa_text('Active Simple:Press Themes'), false);
    $list = $l->themes;
    $done = array();
    $class = 'alternate';
    echo '<table class="wp-list-table widefat">';
    $t = sp_get_option('sp_current_theme');
    $theme = $t['theme'];
    $done[] = $theme;
    $data = sp_get_xml_theme_entry($list, $theme);
    $class = $class == 'alternate' ? '' : 'alternate';
    $name = isset($data->name) ? $data->name : $theme;
    echo '<tr class="' . $class . '"><td width="50%"><b>' . $name . '</b></td>';
    if (isset($data->name)) {
        $thisItem = $site . '&amp;item=theme&amp;langcode=' . $userLang['spLang'] . '&amp;textdom=' . $data->lang . '&amp;name=' . $theme;
        $target = 'spItem' . $x;
        $x++;
        echo '<td><span id="' . $target . '">';
        if (sp_check_for_mo('language-sp-themes', $data->lang, $thisItem, $target) ? $btext = spa_text('Get Latest') : ($btext = spa_text('Install'))) {
        }
        echo '&nbsp;&nbsp;';
        echo '<input type="button" class="logDetail button" value="' . $btext . '" onclick="spjLoadAhah(\'' . $thisItem . '\', \'' . $target . '\', \'' . $gif . '\');" /></span></td></tr>';
    } else {
        echo '<td>' . spa_text('No Translation Project Exists') . '</td></tr>';
    }
    $t = sp_get_option('sp_tablet_theme');
    if ($t['active']) {
        $theme = $t['theme'];
        if (!in_array($theme, $done)) {
            $done[] = $theme;
            $data = sp_get_xml_theme_entry($list, $theme);
            $class = $class == 'alternate' ? '' : 'alternate';
            $name = isset($data->name) ? $data->name : $theme;
            echo '<tr class="' . $class . '"><td width="50%"><b>' . $name . '</b></td>';
            if (isset($data->name)) {
                $thisItem = $site . '&amp;item=theme&amp;langcode=' . $userLang['spLang'] . '&amp;textdom=' . $data->lang . '&amp;name=' . $theme;
                $target = 'spItem' . $x;
                $x++;
                echo '<td><span id="' . $target . '">';
                if (sp_check_for_mo('language-sp-themes', $data->lang, $thisItem, $target) ? $btext = spa_text('Get Latest') : ($btext = spa_text('Install'))) {
                }
                echo '&nbsp;&nbsp;';
                echo '<input type="button" class="logDetail button" value="' . $btext . '" onclick="spjLoadAhah(\'' . $thisItem . '\', \'' . $target . '\', \'' . $gif . '\');" /></span></td></tr>';
            } else {
                echo '<td>' . spa_text('No Translation Project Exists') . '</td></tr>';
            }
        }
    }
    $t = sp_get_option('sp_mobile_theme');
    if ($t['active']) {
        $theme = $t['theme'];
        if (!in_array($theme, $done)) {
            $done[] = $theme;
            $data = sp_get_xml_theme_entry($list, $theme);
            $class = $class == 'alternate' ? '' : 'alternate';
            $name = isset($data->name) ? $data->name : $theme;
            echo '<tr class="' . $class . '"><td width="50%"><b>' . $name . '</b></td>';
            if (isset($data->name)) {
                $thisItem = $site . '&amp;item=theme&amp;langcode=' . $userLang['spLang'] . '&amp;textdom=' . $data->lang . '&amp;name=' . $theme;
                $target = 'spItem' . $x;
                $x++;
                echo '<td><span id="' . $target . '">';
                if (sp_check_for_mo('language-sp-themes', $data->lang, $thisItem, $target) ? $btext = spa_text('Get Latest') : ($btext = spa_text('Install'))) {
                }
                echo '&nbsp;&nbsp;';
                echo '<input type="button" class="logDetail button" value="' . $btext . '" onclick="spjLoadAhah(\'' . $thisItem . '\', \'' . $target . '\', \'' . $gif . '\');" /></span></td></tr>';
            } else {
                echo '<td>' . spa_text('No Translation Project Exists') . '</td></tr>';
            }
        }
    }
    echo '</table>';
    spa_paint_close_fieldset();
    # Plugins if any
    $plugins = sp_get_option('sp_active_plugins');
    if ($plugins) {
        spa_paint_open_fieldset(spa_text('Active Simple:Press Plugins'), false);
        echo '<table class="wp-list-table widefat">';
        $list = $l->plugins;
        $class = 'alternate';
        foreach ($plugins as $plugin) {
            $name = explode('/', $plugin);
            $data = sp_get_xml_plugin_entry($list, $name[0]);
            $class = $class == 'alternate' ? '' : 'alternate';
            $plugname = isset($data->name) ? $data->name : $name[0];
            echo '<tr class="' . $class . '"><td width="50%"><b>' . $plugname . '</b></td>';
            if (isset($data->name)) {
                $thisItem = $site . '&amp;item=plugin&amp;langcode=' . $userLang['spLang'] . '&amp;textdom=' . $data->lang . '&amp;name=' . $name[0];
                $target = 'spItem' . $x;
                $x++;
                echo '<td><span id="' . $target . '">';
                if (sp_check_for_mo('language-sp-plugins', $data->lang, $thisItem, $target) ? $btext = spa_text('Get Latest') : ($btext = spa_text('Install'))) {
                }
                echo '&nbsp;&nbsp;';
                echo '<input type="button" class="logDetail button" value="' . $btext . '" onclick="spjLoadAhah(\'' . $thisItem . '\', \'' . $target . '\', \'' . $gif . '\');" /></span></td></tr>';
            } else {
                echo '<td>' . spa_text('No Translation Project Exists') . '</td></tr>';
            }
        }
        echo '</table>';
        spa_paint_close_fieldset();
    }
    spa_paint_close_panel();
    echo '<div class="sfform-panel-spacer"></div>';
    spa_paint_close_container();
    spa_paint_close_tab();
}
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 
}