public function hasTeamsAvailable()
 {
     return $this->getMaxTeams() ? TBGTeam::getTeamsCount() < $this->getMaxTeams() : true;
 }
 public function runAddTeam(TBGRequest $request)
 {
     try {
         $mode = $request->getParameter('mode');
         if ($team_name = $request->getParameter('team_name')) {
             if ($mode == 'clone') {
                 try {
                     $old_team = TBGContext::factory()->TBGTeam($request->getParameter('team_id'));
                 } catch (Exception $e) {
                 }
                 if (!$old_team instanceof TBGTeam) {
                     throw new Exception(TBGContext::getI18n()->__("You cannot clone this team"));
                 }
             }
             if (TBGTeam::doesTeamNameExist(trim($team_name))) {
                 throw new Exception(TBGContext::getI18n()->__("Please enter a team name that doesn't already exist"));
             }
             $team = new TBGTeam();
             $team->setName($team_name);
             $team->save();
             if ($mode == 'clone') {
                 if ($request->getParameter('clone_permissions')) {
                     TBGPermissionsTable::getTable()->cloneTeamPermissions($old_team->getID(), $team->getID());
                 }
                 if ($request->getParameter('clone_memberships')) {
                     TBGTeamMembersTable::getTable()->cloneTeamMemberships($old_team->getID(), $team->getID());
                 }
                 $message = TBGContext::getI18n()->__('The team was cloned');
             } else {
                 $message = TBGContext::getI18n()->__('The team was added');
             }
             return $this->renderJSON(array('failed' => false, 'message' => $message, 'content' => $this->getTemplateHTML('configuration/teambox', array('team' => $team)), 'total_count' => TBGTeam::getTeamsCount(), 'more_available' => TBGContext::getScope()->hasTeamsAvailable()));
         } else {
             throw new Exception(TBGContext::getI18n()->__('Please enter a team name'));
         }
     } catch (Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage()));
     }
 }
<?php

$tbg_response->setTitle(__('Configure users, teams and groups'));
$tbg_response->addJavascript('config/teamgroups_ajax.js');
$tbg_response->addJavascript('config/permissions.js');
$users_text = TBGContext::getScope()->getMaxUsers() ? __('Users (%num%/%max%)', array('%num%' => '<span id="current_user_num_count">' . TBGUser::getUsersCount() . '</span>', '%max%' => TBGContext::getScope()->getMaxUsers())) : __('Users');
$teams_text = TBGContext::getScope()->getMaxTeams() ? __('Teams (%num%/%max%)', array('%num%' => '<span id="current_team_num_count">' . TBGTeam::getTeamsCount() . '</span>', '%max%' => TBGContext::getScope()->getMaxTeams())) : __('Teams');
?>
<table style="table-layout: fixed; width: 100%" cellpadding=0 cellspacing=0>
	<tr>
		<?php 
include_component('leftmenu', array('selected_section' => 2));
?>
		<td valign="top">
			<div class="config_header" style="width: 750px;"><?php 
echo __('Configure users, teams and groups');
?>
</div>
			<div style="width: 750px; clear: both; height: 30px;" class="tab_menu">
				<ul id="usersteamsgroups_menu">
					<li id="tab_users" class="selected"><?php 
echo javascript_link_tag(image_tag('cfg_icon_users.png', array('style' => 'float: left; margin-right: 5px;')) . $users_text, array('onclick' => "switchSubmenuTab('tab_users', 'usersteamsgroups_menu');"));
?>
</li>
					<li id="tab_groups"><?php 
echo javascript_link_tag(image_tag('cfg_icon_teamgroups.png', array('style' => 'float: left; margin-right: 5px;')) . __('Groups'), array('onclick' => "switchSubmenuTab('tab_groups', 'usersteamsgroups_menu');"));
?>
</li>
					<li id="tab_teams"><?php 
echo javascript_link_tag(image_tag('cfg_icon_teamgroups.png', array('style' => 'float: left; margin-right: 5px;')) . $teams_text, array('onclick' => "switchSubmenuTab('tab_teams', 'usersteamsgroups_menu');"));
?>