function spa_usergroups_usergroup_main()
{
    global $spPaths;
    $usergroups = spa_get_usergroups_all(null);
    if ($usergroups) {
        ?>
			<table class="wp-list-table widefat">
				<tr>
					<th style="text-align:center;width:13%" scope="col"><?php 
        spa_etext('ID');
        ?>
</th>
					<th scope="col"><?php 
        spa_etext('Name');
        ?>
</th>
					<th style="text-align:center;width:8%" scope="col"><?php 
        spa_etext('Moderator');
        ?>
</th>
				</tr>
			</table>
<?php 
        foreach ($usergroups as $usergroup) {
            # display the current usergroup information in table format
            ?>
			<table id="usergrouprow-<?php 
            echo $usergroup->usergroup_id;
            ?>
" class="wp-list-table widefat">
				<tr>
					<td style="width:13%;text-align:center;padding:10px 0;" class='row-title BGhighLight'><?php 
            echo $usergroup->usergroup_id;
            ?>
					<br>
<?php 
            if ($usergroup->usergroup_badge) {
                echo "<img src='" . SF_STORE_URL . '/' . $spPaths['ranks'] . '/' . $usergroup->usergroup_badge . "' alt='' style='max-width:80%;' />";
            }
            ?>
					</td>

					<td><span class='row-title'><strong><?php 
            echo sp_filter_title_display($usergroup->usergroup_name);
            ?>
</strong></span><span><br /><?php 
            echo sp_filter_title_display($usergroup->usergroup_desc);
            ?>
</span>

<?php 
            sp_display_item_stats(SFMEMBERSHIPS, 'usergroup_id', $usergroup->usergroup_id, spa_text('Members'));
            ?>
					</td>
					<td style="width:8%;text-align:center;padding:10px 0;" class='row-title'><?php 
            if ($usergroup->usergroup_is_moderator == 1) {
                echo spa_etext("Yes");
            } else {
                echo spa_etext("No");
            }
            ?>
</td>
				</tr>

				<tr>
					<td class='smallLabel'><?php 
            spa_etext('Manage Group');
            ?>
</td>
					<td colspan="2" style="padding:0 0 0 3px;text-align:left;">
<?php 
            $base = SFHOMEURL . 'index.php?sp_ahah=usergroups-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah');
            $target = "usergroup-{$usergroup->usergroup_id}";
            $image = SFADMINIMAGES;
            ?>
						<input type="button" class="button-secondary" value="<?php 
            echo spa_text('Edit User Group');
            ?>
" onclick="spjLoadForm('editusergroup', '<?php 
            echo $base;
            ?>
', '<?php 
            echo $target;
            ?>
', '<?php 
            echo $image;
            ?>
', '<?php 
            echo $usergroup->usergroup_id;
            ?>
');" />
						<input type="button" class="button-secondary" value="<?php 
            echo spa_text('Delete User Group');
            ?>
" onclick="spjLoadForm('delusergroup', '<?php 
            echo $base;
            ?>
', '<?php 
            echo $target;
            ?>
', '<?php 
            echo $image;
            ?>
', '<?php 
            echo $usergroup->usergroup_id;
            ?>
');" />

						<?php 
            sp_paint_usergroup_tip($usergroup->usergroup_id, sp_filter_title_display($usergroup->usergroup_name));
            ?>

					</td>
				</tr>

				<tr class="sfinline-form"> <!-- This row will hold ahah forms for the current user group -->
				  	<td colspan="3" style="padding:0 10px 0 0;">
						<div id="usergroup-<?php 
            echo $usergroup->usergroup_id;
            ?>
">
						</div>
					</td>
				</tr>
				<tr class="sfsubtable sfugrouptable">
					<td class='smallLabel'><?php 
            spa_etext('Manage Users');
            ?>
</td>
					<td colspan="2" style="padding:0 0 0 3px;text-align:left;">
<?php 
            $site = SFHOMEURL . 'index.php?sp_ahah=usergroups&amp;sfnonce=' . wp_create_nonce('forum-ahah') . "&amp;ug={$usergroup->usergroup_id}";
            $gif = SFCOMMONIMAGES . 'working.gif';
            $text = esc_js(spa_text('Show/Hide'));
            ?>
						<input type="button" id="show<?php 
            echo $usergroup->usergroup_id;
            ?>
" class="button-secondary" value="<?php 
            echo $text;
            ?>
" onclick="spjShowMemberList('<?php 
            echo $site;
            ?>
', '<?php 
            echo $gif;
            ?>
', '<?php 
            echo $usergroup->usergroup_id;
            ?>
');" />
<?php 
            $base = SFHOMEURL . 'index.php?sp_ahah=usergroups-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah');
            $target = "members-{$usergroup->usergroup_id}";
            $image = SFADMINIMAGES;
            ?>
						<input type="button" id="add<?php 
            echo $usergroup->usergroup_id;
            ?>
" class="button-secondary" value="<?php 
            spa_etext('Add New');
            ?>
" onclick="spjLoadForm('addmembers', '<?php 
            echo $base;
            ?>
', '<?php 
            echo $target;
            ?>
', '<?php 
            echo $image;
            ?>
', '<?php 
            echo $usergroup->usergroup_id;
            ?>
'); " />
						<input type="button" id="remove<?php 
            echo $usergroup->usergroup_id;
            ?>
" class="button-secondary" value="<?php 
            spa_etext('Move/Delete');
            ?>
" onclick="spjLoadForm('delmembers', '<?php 
            echo $base;
            ?>
', '<?php 
            echo $target;
            ?>
', '<?php 
            echo $image;
            ?>
', '<?php 
            echo $usergroup->usergroup_id;
            ?>
'); " />
					</td>
				</tr>
				<tr class="sfinline-form"> <!-- This row will hold hidden forms for the current user group membership-->
				  	<td colspan="3" style="padding: 0 10px 0 0;">
                        <div id="members-<?php 
            echo $usergroup->usergroup_id;
            ?>
"></div>
					</td>
				</tr>
			</table>
<?php 
        }
    } else {
        echo '<div class="sfempty">&nbsp;&nbsp;&nbsp;&nbsp;' . spa_text('There are no User Groups defined') . '</div>';
    }
    ?>
    <div class="sfform-panel-spacer"></div>
	<table class="sfmaintable" style="padding:0;border-spacing:0;border-collapse:separate;">
		<tr>
			<th style="text-align:left;padding:10px 20px;" scope="col"><?php 
    spa_etext('Members Not Belonging To Any Usergroup');
    ?>
</th>
		</tr>
		<tr class="sfsubtable sfugrouptable">
			<td style="padding:10px 20px;">
<?php 
    $site = SFHOMEURL . 'index.php?sp_ahah=usergroups&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;ug=0';
    $gif = SFCOMMONIMAGES . 'working.gif';
    $text = esc_js(spa_text('Show/Hide Members with No Memberships'));
    ?>
				<input type="button" id="show-0" class="button-secondary" value="<?php 
    echo $text;
    ?>
" onclick="spjShowMemberList('<?php 
    echo $site;
    ?>
', '<?php 
    echo $gif;
    ?>
', '0');" />
			</td>
		</tr>
		<tr class="sfinline-form"> <!-- This row will hold hidden forms for the current user group membership-->
		  	<td>
                <div id="members-0"></div>
			</td>
		</tr>
	</table>
<?php 
}
function spa_paint_group_forums($groupid, $parent, $parentname, $level)
{
    $space = '<img class="subArrow" src="' . SFADMINIMAGES . 'sp_SubforumLevel.png" alt="" />';
    $forums = spa_get_group_forums_by_parent($groupid, $parent);
    $noMembers = array();
    if ($forums) {
        $noMembers = spa_forums_check_memberships($forums);
        foreach ($forums as $forum) {
            $subforum = $forum->parent;
            $haschild = '';
            if ($forum->children) {
                $childlist = array(unserialize($forum->children));
                if (count($childlist) > 0) {
                    $haschild = $childlist;
                }
            }
            if (empty($forum->forum_icon)) {
                $icon = SPTHEMEICONSURL . 'sp_ForumIcon.png';
            } else {
                $icon = esc_url(SFCUSTOMURL . $forum->forum_icon);
                if (!file_exists(SFCUSTOMDIR . $forum->forum_icon)) {
                    $icon = SPTHEMEICONSURL . 'sp_ForumIcon.png';
                }
            }
            $rowClass = in_array($forum->forum_id, $noMembers) ? ' class="spWarningBG"' : '';
            ?>
			<tr id="forumrow-<?php 
            echo $forum->forum_id;
            ?>
" <?php 
            echo $rowClass;
            ?>
> <!-- display forum information for each forum -->
			<td style="text-align:center;width:2%"><?php 
            echo $forum->forum_id;
            ?>
</td>

			<td style="text-align:center;padding:8px 0px;width:5%"><?php 
            echo '<img src="' . $icon . '" alt="" title="' . spa_text('Current forum icon') . '" />';
            ?>

<?php 
            if ($haschild) {
                ?>
					<br /><img class="parentArrow" src="<?php 
                echo SFADMINIMAGES . 'sp_HasChild.png';
                ?>
" alt="" title="<?php 
                spa_etext('Parent Forum');
                ?>
" />
<?php 
            }
            ?>
			</td>

			<td>
				<div class="sp-half-row-left">
					<?php 
            if ($forum->forum_status) {
                echo '<img class="sfalignright" src="' . SFADMINIMAGES . 'sp_LockedBig.png" alt="" />';
            }
            if ($subforum) {
                ?>
						<?php 
                if ($forum->forum_disabled) {
                    echo '<img class="sfalignright" src="' . SFADMINIMAGES . 'sp_NoWrite.png" alt="" title="' . spa_text('Subforum is disabled') . '" /> ';
                }
                ?>
						<?php 
                echo str_repeat($space, $level - 1);
                ?>
						<img class="subArrow" src="<?php 
                echo SFADMINIMAGES . 'sp_Subforum.png';
                ?>
" alt="" title="<?php 
                spa_etext('Subforum');
                ?>
" />
						<div class='row-title'><strong><?php 
                echo sp_filter_title_display($forum->forum_name);
                ?>
</strong></div><div>(<?php 
                echo spa_text('Subforum of') . ': ' . $parentname . ')';
                ?>
</div><div><?php 
                echo sp_filter_text_display($forum->forum_desc);
                ?>
</div>
                    <?php 
            } else {
                ?>
						<?php 
                if ($forum->forum_disabled) {
                    echo '<img class="sfalignright" src="' . SFADMINIMAGES . 'sp_NoWrite.png" alt="" title="' . spa_text('Forum is disabled') . '" /> ';
                }
                ?>
						<div class='row-title'><strong><?php 
                echo sp_filter_title_display($forum->forum_name);
                ?>
</strong></div><div><?php 
                echo sp_filter_text_display($forum->forum_desc);
                ?>
</div>
                    <?php 
            }
            if (in_array($forum->forum_id, $noMembers)) {
                echo '<p><b>' . spa_text('Warning - There are no usergroups with members that have permission to use this forum') . '</b></p>';
            }
            sp_display_item_stats(SFTOPICS, 'forum_id', $forum->forum_id, spa_text('Topics'));
            echo ' | ';
            sp_display_item_stats(SFPOSTS, 'forum_id', $forum->forum_id, spa_text('Posts'));
            ?>
				</div>
				<div class="sp-half-row-right">
<?php 
            $base = SFHOMEURL . 'index.php?sp_ahah=forums-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah');
            $target = "forum-{$forum->forum_id}";
            $image = SFADMINIMAGES;
            ?>
					<input id="sfreloadpb<?php 
            echo $forum->forum_id;
            ?>
" type="button" class="button-secondary" value="<?php 
            echo sp_splice(spa_text('Forum Permissions'), 0);
            ?>
" onclick="spjLoadForm('forumperm', '<?php 
            echo $base;
            ?>
', '<?php 
            echo $target;
            ?>
', '<?php 
            echo $image;
            ?>
', '<?php 
            echo $forum->forum_id;
            ?>
');" />
					<input type="button" class="button-secondary" value="<?php 
            echo sp_splice(spa_text('Edit Forum'), 0);
            ?>
" onclick="spjLoadForm('editforum', '<?php 
            echo $base;
            ?>
', '<?php 
            echo $target;
            ?>
', '<?php 
            echo $image;
            ?>
', '<?php 
            echo $forum->forum_id;
            ?>
');" />
					<input type="button" class="button-secondary" value="<?php 
            echo sp_splice(spa_text('Delete Forum'), 0);
            ?>
" onclick="spjLoadForm('deleteforum', '<?php 
            echo $base;
            ?>
', '<?php 
            echo $target;
            ?>
', '<?php 
            echo $image;
            ?>
', '<?php 
            echo $forum->forum_id;
            ?>
');" />
        	    	<?php 
            if ($forum->forum_disabled) {
                ?>
						<input type="button" class="button-secondary" value="<?php 
                echo sp_splice(spa_text('Enable Forum'), 0);
                ?>
" onclick="spjLoadForm('enableforum', '<?php 
                echo $base;
                ?>
', '<?php 
                echo $target;
                ?>
', '<?php 
                echo $image;
                ?>
', '<?php 
                echo $forum->forum_id;
                ?>
');" />
		            <?php 
            } else {
                ?>
        		        <input type="button" class="button-secondary" value="<?php 
                echo sp_splice(spa_text('Disable Forum'), 0);
                ?>
" onclick="spjLoadForm('disableforum', '<?php 
                echo $base;
                ?>
', '<?php 
                echo $target;
                ?>
', '<?php 
                echo $image;
                ?>
', '<?php 
                echo $forum->forum_id;
                ?>
');" />
		            <?php 
            }
            ?>
	        	</div>
			</td>
			</tr>

			<tr class="sfinline-form">  <!-- This row will hold ahah forms for the current forum -->
    			<td colspan="3" style="padding: 0 10px 0 0;border-bottom:1px solid #dddddd">
                    <div id="forum-<?php 
            echo $forum->forum_id;
            ?>
"></div>
    			</td>
			</tr>
<?php 
            if ($haschild) {
                $newlevel = $level + 1;
                spa_paint_group_forums($groupid, $forum->forum_id, $forum->forum_name, $newlevel);
            }
        }
    }
}
function spa_special_rankings_form($rankings)
{
    global $tab, $spPaths;
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfaddspecialrank', 'sfreloadfr');
    });
</script>
<?php 
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=components-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=specialranks&amp;action=newrank';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" name="sfaddspecialrank" id="sfaddspecialrank">
<?php 
    echo sp_create_nonce('special-rank-new');
    spa_paint_open_tab(spa_text('Components') . ' - ' . spa_text('Special Forum Ranks'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Special Forum Ranks'), true, 'special-ranks');
    spa_paint_input(spa_text('New Special Rank Name'), 'specialrank', '', false, true);
    echo '<input type="submit" class="button-primary" id="addspecialrank" name="addspecialrank" value="' . spa_text('Add Special Rank') . '" />';
    spa_paint_close_fieldset();
    do_action('sph_components_add_rank_panel');
    spa_paint_close_panel();
    spa_paint_close_container();
    echo '<div class="sfform-panel-spacer"></div>';
    spa_paint_close_tab();
    echo '</form>';
    # display rankings info
    if ($rankings) {
        spa_paint_open_nohead_tab(true);
        spa_paint_open_panel();
        ?>
		<table class="wp-list-table widefat">
			<tr>
				<th style="width:50%"><strong><?php 
        spa_etext('Special Rank Name');
        ?>
</strong></th>
				<th style="width:50%"><strong><?php 
        spa_etext('Special Rank Badge');
        ?>
</strong></th>
			</tr>
		</table>
<?php 
        foreach ($rankings as $rank) {
            ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfspecialrankupdate<?php 
            echo $rank['meta_id'];
            ?>
', '');
    });
</script>
<?php 
            $ahahURL = SFHOMEURL . 'index.php?sp_ahah=components-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=specialranks&amp;action=updaterank&amp;id=' . $rank['meta_id'];
            $delsite = SFHOMEURL . 'index.php?sp_ahah=components&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=del_specialrank&amp;key=' . $rank['meta_id'];
            ?>
			<form action="<?php 
            echo $ahahURL;
            ?>
" method="post" id="sfspecialrankupdate<?php 
            echo $rank['meta_id'];
            ?>
" name="sfspecialrankupdate<?php 
            echo $rank['meta_id'];
            ?>
">
<?php 
            echo sp_create_nonce('special-rank-update');
            ?>
			<table class="wp-list-table widefat" id="srank<?php 
            echo $rank['meta_id'];
            ?>
">
				<tr>
					<td style="overflow:hidden;width:50%">
						<input type="hidden" name="<?php 
            echo 'currentname[' . $rank['meta_id'] . ']';
            ?>
" value="<?php 
            echo $rank['meta_key'];
            ?>
" />
						<input type="text" class="wp-core-ui" size="16" tabindex="<?php 
            echo $tab;
            ?>
" name="<?php 
            echo 'specialrankdesc[' . $rank['meta_id'] . ']';
            ?>
" value="<?php 
            echo $rank['meta_key'];
            ?>
" />
						<br />
<?php 
            $thisRank = $rank['meta_key'];
            sp_display_item_stats(SFSPECIALRANKS, 'special_rank', "'{$thisRank}'", spa_text('Members in Rank'));
            ?>
					</td>
					<td style="overflow:hidden;width:50%">
						<?php 
            spa_select_icon_dropdown('specialrankbadge[' . $rank['meta_id'] . ']', spa_text('Select Badge'), SF_STORE_DIR . '/' . $spPaths['ranks'] . '/', $rank['meta_value']['badge'], true, 105);
            ?>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<div class="sp-half-row-left">
							<input type="submit" class="button-primary" style="vertical-align:top;" id="updatespecialrank.<?php 
            echo $rank['meta_id'];
            ?>
" name="updatespecialrank.<?php 
            echo $rank['meta_id'];
            ?>
" value="<?php 
            spa_etext('Update Rank');
            ?>
" />
							<img style="vertical-align:top;" onclick="spjDelRow('<?php 
            echo $delsite;
            ?>
', 'srank<?php 
            echo $rank['meta_id'];
            ?>
');" src="<?php 
            echo SFCOMMONIMAGES;
            ?>
delete.png" title="<?php 
            spa_etext('Delete Special Rank');
            ?>
" alt="" />
<?php 
            $loc = '#sfrankshow-' . $rank['meta_id'];
            $site = SFHOMEURL . 'index.php?sp_ahah=components&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=show&amp;key=' . $rank['meta_id'];
            $gif = SFCOMMONIMAGES . 'working.gif';
            $text = esc_js(spa_text('Show/Hide Members'));
            ?>
							<input type="button" id="show<?php 
            echo $rank['meta_id'];
            ?>
" class="button-secondary" value="<?php 
            echo $text;
            ?>
" onclick="spjToggleRow('<?php 
            echo $loc;
            ?>
');spjShowMemberList('<?php 
            echo $site;
            ?>
', '<?php 
            echo $gif;
            ?>
', '<?php 
            echo $rank['meta_id'];
            ?>
');" />

						</div>

						<div class="sp-half-row-right">
<?php 
            $base = SFHOMEURL . 'index.php?sp_ahah=components-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah');
            $target = 'members-' . $rank['meta_id'];
            $image = SFADMINIMAGES;
            ?>
							<input type="button" id="remove<?php 
            echo $rank['meta_id'];
            ?>
" class="button-secondary button-jump-left" value="<?php 
            spa_etext('Remove Members');
            ?>
" onclick="jQuery('<?php 
            echo $loc;
            ?>
').show();spjLoadForm('delmembers', '<?php 
            echo $base;
            ?>
', '<?php 
            echo $target;
            ?>
', '<?php 
            echo $image;
            ?>
', '<?php 
            echo $rank['meta_id'];
            ?>
', 'open'); " />
							<input type="button" id="add<?php 
            echo $rank['meta_id'];
            ?>
" class="button-secondary button-jump-left" value="<?php 
            spa_etext('Add Members');
            ?>
" onclick="jQuery('<?php 
            echo $loc;
            ?>
').show();spjLoadForm('addmembers', '<?php 
            echo $base;
            ?>
', '<?php 
            echo $target;
            ?>
', '<?php 
            echo $image;
            ?>
', '<?php 
            echo $rank['meta_id'];
            ?>
', 'open'); " />

						</div>
					</td>
				</tr>

				<tr id="sfrankshow-<?php 
            echo $rank['meta_id'];
            ?>
">
					<td colspan="2">
					<div id="members-<?php 
            echo $rank['meta_id'];
            ?>
"></div>
					</td>
				</tr>
			</table>
			</form>
<?php 
        }
        spa_paint_close_panel();
        spa_paint_close_container();
        echo '<div class="sfform-panel-spacer"></div>';
        spa_paint_close_tab();
    }
}