<?php
defined( '_JEXEC' ) or die( 'Restricted access' );

class HTML_MLS_tournaments {
	function printFooter() {
		global $option, $mosConfig_absolute_path, $database;
		$versionTable = "#__" . substr($option,4) . "_version";
		$database->setQuery( "SELECT `version`,`date` FROM `".$versionTable."` LIMIT 1" );
		$database->loadObject($currentVersion);
		?>
		<table width="100%" border="0">
			<tr>
				<td height="20">&nbsp;</td>
			</tr>
			<tr>
				<td align="center" style="background-color: #F5F5F5; border: 1px solid #D5D5D5">
				<a href="http://www.mylansite.org/">myLANsite Tournaments Component for Joomla <?php echo $currentVersion->version;?></a> (com_mls_tournaments)<br>
				&copy; 2005 - 2010 Samuel Suter &lt;<a href="mailto:samuel.suter@mylansite.org">samuel.suter@mylansite.org</a>&gt;<br>
				This is Free Software released under the GNU/GPL License.
 				</td>
 			</tr>
 		</table>
 		<?php
 	}
 	
 	function showCategorySelect($categoryid = 0,$option,$act) {
		global $database;
		$database->setQuery( "SELECT `id`,`name` FROM `#__mls_tournaments_categories` ORDER BY `name` ASC" );
		$temp = $database->loadObjectList();
		$opt[] = mosHTML::makeOption( '0', JText::_('select_category') );
		foreach($temp as $tmp) {
			$opt[] = mosHTML::makeOption($tmp->id, $tmp->name);
		}
		
		$ret = mosHTML::selectList($opt, 'categoryid', ' class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $categoryid);
		
		return $ret;
	}
	function showEventSelect($eventid = 0,$option,$act) {
		global $database;
		$database->setQuery( "SELECT `id`,`name` FROM `#__mls_events` ORDER BY `name` ASC" );
		$temp = $database->loadObjectList();
		$opt[] = mosHTML::makeOption( '0', JText::_('select_event') );
		foreach($temp as $tmp) {
			$opt[] = mosHTML::makeOption($tmp->id, $tmp->name);
		}
		
		$ret = mosHTML::selectList($opt, 'eventid', ' class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $eventid);
		
		return $ret;
	}
	function showTournamentSelect($tournamentid = 0,$option,$act) {
		global $database;
		$database->setQuery("SELECT t.id,t.name,c.name AS `categoryname`, e.name AS `eventname`"
					."\n FROM `#__mls_tournaments` AS `t`"
					."\n INNER JOIN `#__mls_tournaments_categories` AS `c` ON c.id=t.categoryid"
					."\n INNER JOIN `#__mls_events` AS `e` ON e.id=t.eventid"
					."\nORDER BY e.name,c.name,t.name");
		$rows = $database->loadObjectList();
		$opt = array();
		$opt[] = mosHTML::makeOption('0',JText::_('select_tournament'));
		foreach($rows as $tmp) {
			$opt[] = mosHTML::makeOption($tmp->id,$tmp->eventname." &gt;&gt; ".$tmp->categoryname." &gt;&gt; ".$tmp->name);
		}
		
		$ret = mosHTML::selectList($opt, 'tournamentid_filter', ' class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $tournamentid);
		
		return $ret;
	}
	
	function showBracketSelect($bracket = '0',$option,$act) {
		global $database;
		
		$opt = array();
		$opt[] = mosHTML::makeOption('0',JText::_('select_bracket'));
		$opt[] = mosHTML::makeOption('w',JText::_('winner'));
		$opt[] = mosHTML::makeOption('l',JText::_('loser'));
		$opt[] = mosHTML::makeOption('c',JText::_('custom'));
		
		$ret = mosHTML::selectList($opt, 'bracket_filter', ' class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $bracket);
		
		return $ret;
	}
};

/** Leagues */
class HTML_MLS_tournaments_leagues {
	function listLeagues(&$rows, $option, $act) {
		global $mosConfig_live_site;
		?>
		
		<table class="adminheading">
		<tr>
			<th class="install">myLANsite Tournaments: <?php echo JText::_('leagues')?></th>
		</tr>
		</table>

		<script language="javascript" type="text/javascript">
		function submitbutton3(pressbutton) {
			var form = document.adminForm_dir;
	
			// do field validation
			if (form.userfile.value == ""){
				alert( "Please select a directory" );
			} else {
				form.submit();
			}
		}
		</script>
		<form enctype="multipart/form-data" action="index2.php" method="post" name="filename">
		<table class="adminform">
		<tr>
			<th><?php echo JText::_('upload_package_file')?></th>
		</tr>
		<tr>
			<td align="left">
			<?php echo JText::_('package_file')?>:
			<input class="text_area" name="userfile" type="file" size="70"/>
			<input class="button" type="submit" value="<?php echo JText::_('upload_file_install')?>" />
			</td>
		</tr>
		</table>
	
		<input type="hidden" name="task" value="uploadfile"/>
		<input type="hidden" name="option" value="<?php echo $option;?>"/>
		<input type="hidden" name="act" value="<?php echo $act;?>"/>
		<input type="hidden" name="MAXFILESIZE" value="99999" />
		</form>
		<br />
	
		<form enctype="multipart/form-data" action="index2.php" method="post" name="adminForm_dir">
		<table class="adminform">
		<tr>
			<th>
			<?php echo JText::_('install_from_directory')?>
			</th>
		</tr>
		<tr>
			<td align="left">
			<?php echo JText::_('install_directory')?>:&nbsp;
			<input type="text" name="userfile" class="text_area" size="65" value=""/>&nbsp;
			<input type="button" class="button" value="<?php echo JText::_('install')?>" onclick="submitbutton3()" />
			</td>
		</tr>
		</table>
	
		<input type="hidden" name="task" value="installfromdir" />
		<input type="hidden" name="option" value="<?php echo $option;?>"/>
		<input type="hidden" name="act" value="<?php echo $act;?>"/>
		</form>
		
		<br />
		<form action="index2.php" method="post" name="adminForm">
		<table class="adminheading">
			<tr>
				<th class="install"><?php echo JText::_('installed_leagues')?></th>
			</tr>
			</table>
		<table class="adminlist">
		<tr> 
			<th class="title"><?php echo JText::_('name')?></th>
			<th class="title"><?php echo JText::_('description')?></th>
			<th class="title"><?php echo JText::_('url')?></th>
			<th width="5%" align="center"><?php echo JText::_('logo')?></th>
			<th width="10%" align="left"><?php echo JText::_('author')?></th>
			<th width="5%" align="center"><?php echo JText::_('version')?></th>
			<th width="10%" align="center"><?php echo JText::_('date')?></th>
			<th width="15%" align="left"><?php echo JText::_('authorEmail')?></th>
			<th width="15%" align="left"><?php echo JText::_('authorUrl')?></th>
		</tr>
		<?php
		$k = 0;
		for ($i=0, $n=count($rows); $i < $n; $i++) {
			$row = $rows[$i];
			?>
			<tr class="<?php echo "row$k"; ?>"> 
				<td>
					<input type="radio" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id; ?>" onclick="isChecked(this.checked);" />
					<a href="index2.php?option=<?php echo $option; ?>&act=<?php echo $act; ?>&league=<?php echo $row->name; ?>&task=detail"><?php echo $row->name; ?></a>
				</td>
				<td align="left"><?php echo $row->description; ?></td>
				<td align="left"><a href="<?php echo $row->url; ?>" target="_new" alt="<?php echo $row->description; ?>"><?php echo $row->url; ?></a></td>
				<td align="center">
					<?php if($row->logo) { ?>
						<img border="0" src="<?php echo $mosConfig_live_site; ?>/administrator/components/com_mls_tournaments/leagues/<?php echo $row->name; ?>/<?php echo $row->logo; ?>" alt="<?php echo $row->description; ?>" />
					<?php } else { ?>
						&nbsp;
					<?php } ?>
				</td>
				<td align="left"><?php echo @$row->author != "" ? $row->author : "&nbsp;"; ?></td>
				<td align="center"><?php echo @$row->version != "" ? $row->version : "&nbsp;"; ?></td>
				<td align="center"><?php echo @$row->creationdate != "" ? $row->creationdate : "&nbsp;"; ?></td>
				<td><?php echo @$row->authorEmail != "" ? $row->authorEmail : "&nbsp;"; ?></td>
				<td><?php echo @$row->authorUrl != "" ? "<a href=\"" .(substr( $row->authorUrl, 0, 7) == 'http://' ? $row->authorUrl : 'http://'.$row->authorUrl). "\" target=\"_blank\">$row->authorUrl</a>" : "&nbsp;";?></td>
			</tr>
			<?php
			$k = 1 - $k;
		}
		?>
		</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
	
	function showInstallMessage( $message, $title, $url ) {
		global $PHP_SELF;
		?>
		<table class="adminheading">
		<tr>
			<th class="install">
			<?php echo $title; ?>
			</th>
		</tr>
		</table>

		<table class="adminform">
		<tr>
			<td align="left">
			<strong><?php echo $message; ?></strong>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
			[&nbsp;<a href="<?php echo $url;?>" style="font-size: 16px; font-weight: bold">Continue ...</a>&nbsp;]
			</td>
		</tr>
		</table>
		<?php
	}
}

/** Export */
class HTML_MLS_tournaments_export {
	function exportForm( $lists, $option, $act ) {
		?>
		<form action="index2.php" method="post" name="adminForm">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments: <?php echo JText::_('export')?></th>
		</tr>
		</table>
		<table width="100%">
		<tr>
			<td width="60%" valign="top">
				<form action="index2.php" method="post" name="adminForm">
				<table class="adminform">
					<tr>
						<th colspan="2"><?php echo JText::_('details'); ?></th>
					</tr>
					<tr> 
						<td width="20%" align="right" valign="top">1. <?php echo JText::_('event') ?>:</td>
						<td width="80%"><?php echo $lists["event"]; ?></td>
					</tr>
					<?php if(@$lists["league"]) { ?>
					<tr> 
						<td valign="top" valign="top">2. <?php echo JText::_('league') ?>:</td>
						<td><?php echo $lists["league"]; ?></td>
					</tr>
					<?php } ?>
					<?php if(@$lists["tournaments"]) { ?>
					<tr> 
						<td valign="top" valign="top">3. <?php echo JText::_('tournaments') ?>:</td>
						<td><?php echo $lists["tournaments"]; ?></td>
					</tr>
					<tr> 
						<td valign="top" valign="top"></td>
						<td><input type="submit" class="button" name="submit" value="<?php echo JText::_('export');?>" /></td>
					</tr>
					<?php } ?>
				</table>
				<input type="hidden" name="option" value="<?php echo $option; ?>" />
				<input type="hidden" name="act" value="<?php echo $act; ?>" />
				<input type="hidden" name="task" value="export_do" />
				</form>
			</td>
			<td width="40%" valign="top">
				&nbsp;
			</td>
		</tr>
		</table>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
};
	
/** Games */
class HTML_MLS_tournaments_games {
	function listGames(&$rows, $pageNav, $option, $act) {
		?>
		<form action="index2.php" method="post" name="adminForm">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments: <?php echo JText::_('games')?></th>
		</tr>
		</table>
		<table class="adminlist">
		<tr> 
			<th width="20"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" /></th>
			<th width="20"><?php echo JText::_('id')?></th>
			<th class="title"><?php echo JText::_('name')?></th>
			<th width="15%"><?php echo JText::_('num_tournaments')?></th>
			<th width="30%">&nbsp;</th>
		</tr>
		<?php
		$k = 0;
		for ($i=0, $n=count($rows); $i < $n; $i++) {
			$row = $rows[$i];
			?>
			<tr class="<?php echo "row$k"; ?>"> 
				<td>
					<input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id; ?>" onclick="isChecked(this.checked);" />
				</td>
				<td align="center"><?php echo $row->id; ?></td>
				<td><a href="#edit" onclick="return listItemTask('cb<?php echo $i;?>','edit')"><?php echo $row->name; ?></a></td>
				<td align="center"><?php echo $row->records; ?></td>
				<td>&nbsp;</td>
			</tr>
			<?php
			$k = 1 - $k;
		}
		?>
		</table>
		<?php echo $pageNav->getListFooter(); ?>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
	
	function editGame(&$row, $option, $act) {
		?>
		<form action="index2.php" method="POST" name="adminForm">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments: <?php echo $row->id ? JText::_('edit_game') : JText::_('add_game');?></th>
		</tr>
		</table>
		<table class="adminform">
			<tr> 
				<td width="20%" valign="top" align="right"><?php echo JText::_('name') ?>:</td>
				<td width="80%"><input class="text_area" type="text" name="name" size="50" maxlength="255" value="<?php echo $row->name; ?>" /></td>
			</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="task" value="" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
}

/** Servers */
class HTML_MLS_tournaments_servers {
	function listServers(&$rows, $pageNav, $option,$act) {
		?>
		<form action="index2.php" method="post" name="adminForm">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments: <?php echo JText::_('servers')?></th>
		</tr>
		</table>
		<table class="adminlist">
		<tr>
			<th width="5">#</td>
			<th width="20"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" /></th>
			<th width="20"><?php echo JText::_('id')?></th>
			<th class="title" width="140"><?php echo JText::_('name')?></th>
			<th class="title" width="140"><?php echo JText::_('description')?></th>
			<th class="title" width="140"><?php echo JText::_('game')?></th>
			<th width="80" align="center"><nobr><?php echo JText::_('num_matches')?></nobr></th>
			<th class="title"><?php echo JText::_('hostname')?></th>
			<th class="title"><?php echo JText::_('ip_address')?></th>
			<th class="title" width="80"><?php echo JText::_('port')?></th>
			<th width="10%" align="center"><?php echo JText::_('online')?></th>
			<th>&nbsp;</th>
		</tr>
		<?php
		$k = 0;
		for ($i=0, $n=count($rows); $i < $n; $i++) {
			$row = $rows[$i];
			
			$row->img = $row->online ? "tick.png" : "publish_x.png";
			?>
			<tr class="<?php echo "row$k"; ?>">
				<td align="center"><?php echo $i + 1 + $pageNav->limitstart; ?></td>
				<td width="20">
					<input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id; ?>" onclick="isChecked(this.checked);" />
				</td>
				<td align="center"><?php echo $row->id; ?></td>
				<td><a href="#edit" onclick="return listItemTask('cb<?php echo $i;?>','edit')"><?php echo $row->name; ?></a></td>
				<td><?php echo $row->description; ?></td>
				<td><?php echo $row->gamename; ?></td>
				<td align="center"><?php echo $row->records; ?></td>
				<td><?php echo $row->hostname; ?></td>
				<td><?php echo $row->ip; ?></td>
				<td><?php echo $row->port; ?></td>
				<td align="center"><a href="javascript: void(0);" onClick="return listItemTask('cb<?php echo $i;?>','check_online')"><img src="images/<?php echo $row->img;?>" width="12" height="12" border="0" alt="" /></a></td>
				<td>&nbsp;</td>
			</tr>
			<?php
			$k = 1 - $k;
		}
		?>
		</table>
		<?php echo $pageNav->getListFooter(); ?>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
	
	function editServer(&$row, $lists, $option, $act) {
		?>
		<form action="index2.php" method="POST" name="adminForm">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments: <?php echo $row->id ? JText::_('edit_server') : JText::_('add_server');?></th>
			</tr>
		</table>
		<table class="adminform">
			<tr> 
				<td width="20%" valign="top" align="right"><?php echo JText::_('name') ?>:</td>
				<td width="80%"><input class="text_area" type="text" name="name" size="50" maxlength="255" value="<?php echo $row->name; ?>" /></td>
			</tr>
			<tr> 
				<td valign="top" align="right"><?php echo JText::_('description') ?>:</td>
				<td><input class="text_area" type="text" name="description" size="50" maxlength="255" value="<?php echo $row->description; ?>" /></td>
			</tr>
			
			<tr> 
				<td valign="top" align="right"><?php echo JText::_('game') ?>:</td>
				<td><?php echo $lists["gameid"]; ?></td>
			</tr>
			<tr> 
				<td valign="top" align="right"><?php echo JText::_('hostname') ?>:</td>
				<td><input class="text_area" type="text" name="hostname" size="50" maxlength="255" value="<?php echo $row->hostname; ?>" /></td>
			</tr>
			<tr> 
				<td valign="top" align="right"><?php echo JText::_('ip_address') ?>:</td>
				<td><input class="text_area" type="text" name="ip" size="20" maxlength="20" value="<?php echo $row->ip; ?>" /></td>
			</tr>
			<tr> 
				<td valign="top" align="right"><?php echo JText::_('port') ?>:</td>
				<td><input class="text_area" type="text" name="port" size="10" maxlength="10" value="<?php echo $row->port; ?>" /></td>
			</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="task" value="" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
}

/** Categories */
class HTML_MLS_tournaments_categories {
	function listCategories(&$rows, $pageNav, $option, $act) {
		?>
		<form action="index2.php" method="post" name="adminForm">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments: <?php echo JText::_('tournament_categories')?></th>
		</tr>
		</table>
		<table class="adminlist">
		<tr> 
			<th width="20"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" /></th>
			<th width="20"><?php echo JText::_('id')?></th>
			<th class="title" class="title"><?php echo JText::_('name')?></th>
			<th width="15%"><?php echo JText::_('num_tournaments')?></th>
			<th width="10%"><?php echo JText::_('published')?></th>
			<th width="30%">&nbsp;</th>
		</tr>
		<?php
		$k = 0;
		for ($i=0, $n=count($rows); $i < $n; $i++) {
			$row = $rows[$i];
			$img_pub = $row->published ? 'tick.png' : 'publish_x.png';
			$task_pub = $row->published ? 'unpublish' : 'publish';
			?>
			<tr class="<?php echo "row$k"; ?>"> 
				<td align="center">
					<input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id; ?>" onclick="isChecked(this.checked);" />
				</td>
				<td align="center"><?php echo $row->id; ?></td>
				<td><a href="#edit" onclick="return listItemTask('cb<?php echo $i;?>','edit')"><?php echo $row->name; ?></a></td>
				<td align="center"><?php echo $row->records; ?></td>
				<td align="center"><a href="javascript: void(0);" onClick="return listItemTask('cb<?php echo $i;?>','<?php echo $task_pub;?>')"><img src="images/<?php echo $img_pub;?>" width="12" height="12" border="0" alt="<?php echo $task_pub;?>" /></a></td>
				<td>&nbsp;</td>
			</tr>
			<?php
			$k = 1 - $k;
		}
		?>
		</table>
		<?php echo $pageNav->getListFooter(); ?>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
	
	function editCategory(&$row, $lists, $option, $act) {
		?>
		<form action="index2.php" method="POST" name="adminForm">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments: <?php echo $row->id ? JText::_('edit_tournament_category') : JText::_('add_tournament_category');?></th>
			</tr>
		</table>
		<table class="adminform">
			<tr> 
				<td width="20%" valign="top" align="right"><?php echo JText::_('name') ?>:</td>
				<td width="80%"><input class="text_area" type="text" name="name" size="50" maxlength="255" value="<?php echo $row->name; ?>" /></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('published') ?>:</td>
				<td><?php echo $lists["published"]; ?></td>
			</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="task" value="" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
}

/** Tournaments */
class HTML_MLS_tournaments_tournaments {
	function listTournaments(&$rows, &$pageNav, $search, $category_select, $event_select, $option,$act) {
		?>
		<form action="index2.php" method="post" name="adminForm">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments</td>
			<td><?php echo JText::_('category')?>:</td>
			<td> <?php echo $category_select; ?></td>
			<td><?php echo JText::_('event')?>:</td>
			<td> <?php echo $event_select; ?></td>
			<td><?php echo JText::_('search'); ?>:</td>
			<td><input type="text" name="search" value="<?php echo $search;?>" class="text_area" onChange="document.adminForm.submit();" /></td>
		</tr>
		</table>
		<table class="adminlist">
		<tr> 
			<th width="5">#</th>
			<th width="20"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" /></th>
			<th class="title" width="200"><?php echo JText::_('name');?></th>
			<th class="title"><?php echo JText::_('game');?></th>
			<th class="title"><?php echo JText::_('category');?></th>
			<th class="title"><?php echo JText::_('event');?></th>
			<th align="center" width="80" nowrap="nowrap"><?php echo JText::_('num_participants');?></th>
			<th align="center" width="10%"><?php echo JText::_('started');?></th>
			<th align="center" width="10%"><?php echo JText::_('registration');?></th>
			<th align="center" width="10%"><?php echo JText::_('published');?></th>
		</tr>
		<?php
		$k = 0;
		
		for ($i=0, $n=count($rows); $i < $n; $i++) {
			$row = $rows[$i];
			$img_pub = $row->published ? 'tick.png' : 'publish_x.png';
			$task_pub = $row->published ? 'unpublish' : 'publish';
			$img_reg = $row->registration ? 'tick.png' : 'publish_x.png';
			$task_reg = $row->registration ? 'unregistration' : 'registration';
			$img_start = $row->started ? 'tick.png' : 'publish_x.png';
			$task_start = $row->started ? 'stop' : 'start';
			$row->participants = !$row->participants ? "0" : $row->participants;
			?>
			<tr class="<?php echo "row$k"; ?>">
				<td align="center"><?php echo $i + 1 + $pageNav->limitstart; ?></td>
				<td>
					<input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id; ?>" onclick="isChecked(this.checked);" />
				</td>
				<td><a href="#edit" onclick="return listItemTask('cb<?php echo $i;?>','edit')"><?php echo $row->name; ?></a></td>
				<td><?php echo $row->gamename; ?></td>
				<td><?php echo $row->categoryname; ?></td>
				<td><?php echo $row->eventname; ?></td>
				<td align="center">
					<a href="index2.php?option=com_mls_tournaments&act=participants&tournamentid_filter=<?php echo $row->id; ?>">
					<?php echo $row->participants; ?>/<?php echo $row->maxplayer; ?>
				</td>
				<td align="center"><a href="javascript: void(0);" onClick="return listItemTask('cb<?php echo $i;?>','<?php echo $task_start;?>')"><img src="images/<?php echo $img_start;?>" width="12" height="12" border="0" alt="" /></a></td>
				<td align="center"><a href="javascript: void(0);" onClick="return listItemTask('cb<?php echo $i;?>','<?php echo $task_reg;?>')"><img src="images/<?php echo $img_reg;?>" width="12" height="12" border="0" alt="" /></a></td>
				<td align="center"><a href="javascript: void(0);" onClick="return listItemTask('cb<?php echo $i;?>','<?php echo $task_pub;?>')"><img src="images/<?php echo $img_pub;?>" width="12" height="12" border="0" alt="" /></a></td>
			</tr>
			<?php
			$k = 1 - $k;
		}
		?>
		</table>
		<?php echo $pageNav->getListFooter(); ?>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
	
	function editTournament(&$row, $lists, $leaguesdata, $option, $act) {
		?>
		<script language="JavaScript">
		var lastDiv;
		function selectLeague(LEAGUE) {
			var leagueDiv, targetElement, mainDiv;
			leagueDiv = 'form_' + LEAGUE;
			
			if(LEAGUE != '') {
				targetElement = document.getElementById(leagueDiv);
				targetElement.style.display = "";
			}	
			
			if(lastDiv) {
				lastDiv.style.display = "none";
			}
			
			lastDiv = document.getElementById(leagueDiv);
		}
		</script>
		<form action="index2.php" method="POST" name="adminForm">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments: <?php echo $row->id ? JText::_('edit_tournament') : JText::_('add_tournament');?></th>
		</tr>
		</table>
		<table width="100%">
		<tr>
			<td width="60%" valign="top">
				<table class="adminform">
					<tr>
						<th colspan="2"><?php echo JText::_('details'); ?></th>
					</tr>
					<tr> 
						<td width="20%" valign="top" align="right"><?php echo JText::_('name') ?>:</td>
						<td width="80%"><input class="text_area" type="text" name="name" size="50" maxlength="255" value="<?php echo $row->name; ?>" /></td>
					</tr>
					<tr> 
						<td valign="top" align="right" valign="top"><?php echo JText::_('event') ?>:</td>
						<td><?php echo $lists["eventid"]; ?></td>
					</tr>
					<tr> 
						<td align="right" valign="top"><?php echo JText::_('league'); ?>:</td>
						<td><?php echo $lists["league"]; ?></td>
					</tr>
					<tr> 
						<td valign="top" valign="top" align="right" valign="top"><?php echo JText::_('category') ?>:</td>
						<td><?php echo $lists["categoryid"]; ?> <input class="text_area" type="text" name="newcategory" size="30" maxlength="255" value="<?php echo JText::_('add_category'); ?>..." onblur="if(this.value=='') { this.value='<?php echo JText::_('add_category'); ?>...'; document.adminForm.newcategory_check.checked = false; }" onfocus="if(this.value=='<?php echo JText::_('add_category'); ?>...') { this.value=''; document.adminForm.newcategory_check.checked = true; }" />
						<input type="checkbox" class="inputbox" name="newcategory_check" value="1" />
						</td>
					</tr>
					<tr> 
						<td valign="top" valign="top" align="right" valign="top"><?php echo JText::_('game') ?>:</td>
						<td><?php echo $lists["gameid"]; ?> <input class="text_area" type="text" name="newgame" size="30" maxlength="255" value="<?php echo JText::_('add_game'); ?>..." onblur="if(this.value=='') { this.value='<?php echo JText::_('add_game'); ?>...'; document.adminForm.newgame_check.checked = false; }" onfocus="if(this.value=='<?php echo JText::_('add_game'); ?>...') { this.value=''; document.adminForm.newgame_check.checked = true; }" />
						<input type="checkbox" class="inputbox" name="newgame_check" value="1" />
						</td>
					</tr>
					<tr> 
						<td valign="top" align="right"><?php echo JText::_('type') ?>:</td>
						<td><?php echo $lists["type"]; ?></td>
					</tr>
					<tr> 
						<td valign="top" align="right"><?php echo JText::_('mode') ?>:</td>
						<td><?php echo $lists["mode"]; ?></td>
					</tr>
					<tr> 
						<td valign="top" align="right"><?php echo JText::_('player') ?>:</td>
						<td><input class="text_area" type="text" name="player" size="10" maxlength="10" value="<?php echo $row->player; ?>" /></td>
					</tr>
					<tr> 
						<td valign="top" align="right"><?php echo JText::_('maxplayer') ?>:</td>
						<td><?php echo $lists["maxplayer"]; ?></td>
					</tr>
					<tr> 
						<td valign="top" align="right"><?php echo JText::_('rules_url') ?>:</td>
						<td><input class="text_area" type="text" name="rules_url" size="50" maxlength="255" value="<?php echo $row->rules_url; ?>" /></td>
					</tr>
				</table>
			</td>
			<td width="40%" valign="top">
				<table class="adminform">
				<tr>
					<th colspan="2"><?php echo JText::_('parameters'); ?></th>
				</tr>
				<tr> 
					<td valign="top"><?php echo JText::_('registration') ?>:</td>
					<td><?php echo $lists["registration"]; ?></td>
				</tr>
				<tr> 
					<td valign="top"><?php echo JText::_('started') ?>:</td>
					<td><?php echo $lists["started"]; ?></td>
				</tr>
				<tr> 
					<td valign="top"><?php echo JText::_('published') ?>:</td>
					<td><?php echo $lists["published"]; ?></td>
				</tr>
				</table>
				<br />
				<?php
				foreach($leaguesdata AS $leaguename => $data) {
					$function = "editTournament_".$leaguename;
					echo "<div id=\"form_".$leaguename."\" style=\"display: none;\">\n";
					$function ($row, $data);
					echo "<br />\n";
					echo "</div>\n";
				}
				?>
			</td>
		</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="task" value="" />
		</form>
		<script language="JavaScript">
		selectLeague('<?php echo $row->league;?>');
		</script>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
	
	function changeMatches($t, $lists, $matches, $option, $act ) {
		?>
		<script language="JavaScript">
		
		function swapTeams(listId) {
			targetList = document.getElementById(listId);
			var clan1 = targetList.options[0];
			var clan2 = targetList.options[1];
			
			targetList.options[0] = clan2;
			targetList.options[1] = clan1;
		}
		
		function insertTeam(trgListId) {
			availTeams = document.getElementById('availableTeams');
			targetList = document.getElementById(trgListId);
			if(availTeams.selectedIndex != -1) {
				srcOpt = availTeams.options[availTeams.selectedIndex];
			
				//only when a source option and a target list is defined
				
				if(targetList.length < 2) {
					//delete entry from availableTeams select
					document.getElementById('availableTeams').options[srcOpt.index] = null;
					
					//Create new entry in target list
					targetList.options[targetList.length] = new Option(srcOpt.text,srcOpt.value,false,false);
				}
			}
		}
		
		function selectAll(formName) {
			var myForm = document.forms["adminForm"];
			for(iCount = 0; iCount < myForm.length; iCount++) {
				type = document.forms["adminForm"].elements[iCount].type;
				if(type == 'select-multiple') {
					listLen = document.forms["adminForm"].elements[iCount].length;
					for(iCount2 = 0; iCount2 < listLen; iCount2++) {
						document.forms["adminForm"].elements[iCount].options[iCount2].selected = true;
					}
				}
			}
		}
		
		function removeAll(formName) {
			var myForm = document.forms["adminForm"];
			availTeams = document.getElementById('availableTeams');
			for(iCount = 0; iCount < myForm.length; iCount++) {
				type = document.forms["adminForm"].elements[iCount].type;
				if(type == 'select-multiple') {
					listLen = document.forms["adminForm"].elements[iCount].length;
					for(iCount2 = 0; iCount2 < listLen; iCount2++) {
						thisOpt = document.forms["adminForm"].elements[iCount].options[0];
						//Create new entry in availableTeams list
						availTeams.options[availTeams.length] = new Option(thisOpt.text,thisOpt.value,false,false);
						
						//delete this option
						document.forms["adminForm"].elements[iCount].options[0] = null;
					}
				}
			}
		}
		function removeOption(SELECTID) {
			//Load List and selected Option
			selectList = document.getElementById(SELECTID);
			if(selectList.selectedIndex != -1) {
				selectedOption = selectList.options[selectList.selectedIndex];
				selectList.options[selectList.selectedIndex]=null;
				
				teamSelect = document.getElementById('availableTeams');
				teamSelect.options[teamSelect.length] = new Option(selectedOption.text,selectedOption.value,false,false);
			}
		}
		</script>
		<form action="index2.php" method="POST" name="adminForm" onSubmit="javascript:selectAll(this.name);">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments: <?php echo JText::_('edit_matches');?></th>
		</tr>
		</table>
		<table width="100%" height="100%">
		<tr>
			<td width="20%" valign="top">
				<table class="adminform">
					<tr>
						<th colspan="2"><?php echo JText::_('unassigned_players'); ?></th>
					</tr>
					<td>
						<?php echo $lists["availableTeams"]; ?>
					</td>
				</table>
			</td>
			<td width="80%" valign="top">
				<table class="adminform">
					<tr>
						<th colspan="2"><?php echo JText::_('matches_in_first_round');?> (<span style="text-decoration: underline;" onClick="javascript:removeAll('adminForm');"><?php echo JText::_('remove_all_players');?></span>)</th>
					</tr>
					<tr>
						<td>
						<table><tr>
						<?php
						//Eight matches per column
						$columns = ceil(count($matches) / 8);
						for($c = 0; $c < $columns; $c++) {
							?>
							<td align="left" valign="top">
							<table>
							<?php
							for($i = 0; $i < 8; $i++) {
								$match =& $matches[$i + ($c * 8)];
								if($match->matchnr) {
								?>
								<tr>
									<td style="text-align: right;">
										<b>#<?php echo $match->matchnr; ?>:</b><br />
										(<span style="text-decoration: underline;" onClick="javascript:swapTeams('match<?php echo $match->id; ?>');"><?php echo JText::_('swap');?></span>)
									</td>
									<td>
										<select width="250" style="width: 250;" onClick="javascript:insertTeam('match<?php echo $match->id; ?>');" onDblClick="javascript:removeOption(this.id)" name="matches[<?php echo $match->id; ?>][]" id="match<?php echo $match->id; ?>" size="2" multiple>
											<?php if($match->player1_id) {?><option value="<?php echo $match->player1_id; ?>"><?php echo $match->player1_name; ?></option><?php } ?>
											<?php if($match->player2_id) {?><option value="<?php echo $match->player2_id; ?>"><?php echo $match->player2_name; ?></option><?php } ?>
										</select>
									</td>
								</tr>
								<?php
								}
							}
							?>
							</table>
							</td>
							<?php
						}
						?>
						</tr></table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="id" value="<?php echo $t->id; ?>" />
		<input type="hidden" name="task" value="" />
		</form>
		<?php
	}
	
	function startForm($t, $e, $lists, $exclusions, $option ) {
		?>
		<form action="index2.php" method="POST" name="adminForm">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments: <?php echo JText::_('start_tournament');?></th>
		</tr>
		</table>
		<table class="adminform">
			<tr> 
				<td width="15%" valign="top"><?php echo JText::_('select_servers') ?>:</td>
				<td width="45%" valign="top"><?php echo $lists["servers"]; ?></td>
				<td width="40%" valign="top">Select, which servers will be used for this tournament</td>
			</tr>
			<tr> 
				<td valign="top"><?php echo JText::_('start_time') ?>:</td>
				<td valign="top"><input type="text" class="inputbox" name="start_time" size="20" value="<?php echo date( "Y-m-d H:i:s", strtotime("+2 hours",strtotime($e->start)) );?>" /></td>
				<td valign="top">The event starts at <b><?php echo $e->start; ?></b> and ends at <b><?php echo $e->end; ?></b>. The default value you see on the left is 2 hours after the event has started.</td>
			</tr>
			<tr> 
				<td valign="top"><?php echo JText::_('match_time') ?>:</td>
				<td valign="top"><input type="text" class="inputbox" name="match_time" size="5" /></td>
				<td valign="top">Define, how long a match lasts (in minutes). Make sure you have a good estimate here, otherwise the tournament schedule will never be accurate.</td>
			</tr>
			<tr> 
				<td valign="top"><?php echo JText::_('excluded_times') ?>:</td>
				<td valign="top">
					<b>1:</b> <?php echo JText::_('from'); ?>: <input type="text" class="inputbox" name="exclude_from[0]" size="20" value="<?php echo $exclusions["from"][0]; ?>" />
					&nbsp;<?php echo JText::_('to'); ?>: <input type="text" class="inputbox" name="exclude_to[0]" size="20" value="<?php echo $exclusions["to"][1]; ?>" />
					<br />
					<b>2:</b> <?php echo JText::_('from'); ?>: <input type="text" class="inputbox" name="exclude_from[1]" size="20" value="<?php echo $exclusions["from"][1]; ?>" />
					&nbsp;<?php echo JText::_('to'); ?>: <input type="text" class="inputbox" name="exclude_to[1]" size="20" value="<?php echo $exclusions["to"][1]; ?>" />
					<br />
					<b>3:</b> <?php echo JText::_('from'); ?>: <input type="text" class="inputbox" name="exclude_from[2]" size="20" value="<?php echo $exclusions["from"][2]; ?>" />
					&nbsp;<?php echo JText::_('to'); ?>: <input type="text" class="inputbox" name="exclude_to[2]" size="20" value="<?php echo $exclusions["to"][2]; ?>" />
					<br />
					<b>4:</b> <?php echo JText::_('from'); ?>: <input type="text" class="inputbox" name="exclude_from[3]" size="20" value="<?php echo $exclusions["from"][3]; ?>" />
					&nbsp;<?php echo JText::_('to'); ?>: <input type="text" class="inputbox" name="exclude_to[3]" size="20" value="<?php echo $exclusions["to"][3]; ?>" />
					<br />
					<b>5:</b> <?php echo JText::_('from'); ?>: <input type="text" class="inputbox" name="exclude_from[4]" size="20" value="<?php echo $exclusions["from"][4]; ?>" />
					&nbsp;<?php echo JText::_('to'); ?>: <input type="text" class="inputbox" name="exclude_to[4]" size="20" value="<?php echo $exclusions["to"][4]; ?>" />
				</td>
				<td valign="top">You can exclude times from playing. Preferrably the nights, but this is totally up to you. The system automatically excluded the nights for you (10pm - 6am), but feel free to change the default values.</td>
			</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="start_calculate" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
};

/** Participants */
class HTML_MLS_tournaments_participants {
	function listParticipants(&$rows, &$pageNav, $search, $tournament_select, $option,$act) {
		?>
		<form action="index2.php" method="post" name="adminForm">
		<table class="adminheading">
		<tr>
			<th colspan="5">myLANsite Tournaments: <?php echo JText::_('tournament_participants'); ?></th>
		</tr>
		<tr>
			<td width="50%"></td>
			<td><?php echo JText::_('tournament')?>:</td>
			<td> <?php echo $tournament_select; ?></td>
			<td><?php echo JText::_('search'); ?>:</td>
			<td><input type="text" name="search" value="<?php echo $search;?>" class="text_area" onChange="document.adminForm.submit();" /></td>
		</tr>
		</table>
		<table class="adminlist">
		<tr>
			<th width="5">#</td>
			<th width="20"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" /></th>
			<th class="title" width="200"><?php echo JText::_('participant');?></th>
			<th class="title" width="200"><?php echo JText::_('event');?></th>
			<th class="title" width="100"><?php echo JText::_('category');?></th>
			<th class="title" width="140"><?php echo JText::_('tournament');?></th>
			<th align="center" width="40"><?php echo JText::_('type');?></th>
			<th>&nbsp;</th>
		</tr>
		<?php
		$k = 0;
		for ($i=0, $n=count($rows); $i < $n; $i++) {
			$row = $rows[$i];
			?>
			<tr class="<?php echo "row$k"; ?>">
				<td align="center"><?php echo $i + 1 + $pageNav->limitstart; ?></td>
				<td>
					<input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id; ?>" onclick="isChecked(this.checked);" />
				</td>
				<td><?php echo $row->type == 'C' ? JText::_('team') : JText::_('user'); ?>: <a href="#edit" onclick="return listItemTask('cb<?php echo $i;?>','edit')"><?php echo $row->participantname; ?></a></td>
				<td><?php echo $row->eventname; ?></td>
				<td><?php echo $row->categoryname; ?></td>
				<td><?php echo $row->tournamentname; ?></td>
				<td align="center"><?php echo $row->type == 'C' ? JText::_('clans') : JText::_('singleplayer'); ?></td>
				<td></td>
			</tr>
			<?php
			$k = 1 - $k;
		}
		?>
		</table>
		<?php echo $pageNav->getListFooter(); ?>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
	
	function editParticipants(&$row, $lists, $option, $act) {
		?>
		<form action="index2.php" method="POST" name="adminForm">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments: <?php echo $row->id ? JText::_('edit_tournament_participant') : JText::_('add_tournament_participant');?></td>
			</tr>
		</table>
		<table class="adminform">
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('tournament') ?>:</td>
				<td><?php echo $lists["tournamentid"]; ?></td>
			</tr>
			<tr> 
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr> 
				<td width="20%" align="right" valign="top"><?php echo JText::_('user') ?>:</td>
				<td width="80%"><?php echo $lists["userid"]; ?></td>
			</tr>
			<tr> 
				<td width="20%" align="right" valign="top">&nbsp;</td>
				<td width="80%"><?php echo JText::_('or'); ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('team') ?>:</td>
				<td><?php echo $lists["teamid"]; ?></td>
			</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="task" value="" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
}

/** Brackets */
class HTML_MLS_tournaments_brackets {
	function listBrackets(&$rows, &$pageNav, $search, $tournament_select, $bracket_select, $option,$act) {
		?>
		<form action="index2.php" method="post" name="adminForm">
		<table class="adminheading">
		<tr>
			<th colspan="7">myLANsite Tournaments: <?php echo JText::_('tournament_brackets'); ?></th>
		</tr>
		<tr>
			<td width="50%"></td>
			<td><?php echo JText::_('tournament')?>:</td>
			<td> <?php echo $tournament_select; ?></td>
			<td><?php echo JText::_('bracket')?>:</td>
			<td> <?php echo $bracket_select; ?></td>
			<td><?php echo JText::_('search'); ?>:</td>
			<td><input type="text" name="search" value="<?php echo $search;?>" class="text_area" onChange="document.adminForm.submit();" /></td>
		</tr>
		</table>
		<table class="adminlist">
		<tr>
			<th width="5">#</td>
			<th width="20"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" /></th>
			<th width="40"><?php echo JText::_('bracket');?></th>
			<th width="50"><?php echo JText::_('roundnr');?></th>
			<th width="50"><?php echo JText::_('matchnr');?></th>
			<th class="title"><?php echo JText::_('player_one');?></th>
			<th><?php echo JText::_('result_short');?></th>
			<th class="title"><?php echo JText::_('player_two');?></th>
			<th><?php echo JText::_('result_short');?></th>
			<th class="title"><?php echo JText::_('tournament');?></th>
			<th width="40"><?php echo JText::_('type');?></th>
			<th width="40"><?php echo JText::_('submit');?></th>
		</tr>
		<?php
		$k = 0;
		for ($i=0, $n=count($rows); $i < $n; $i++) {
			$row = $rows[$i];
			$img = $row->result_submit ? "tick.png" : "publish_x.png";
			$task = $row->result_submit ? "submit_results" : "submit_results";
			switch($row->bracket) {
				case "w":
					$row->bracket = JText::_('winner');
					break;
				case "l":
					$row->bracket = JText::_('loser');
					break;
				case "c":
					$row->bracket = JText::_('custom');
					break;
			}
			?>
			<tr class="<?php echo "row$k"; ?>">
				<td align="center"><?php echo $i + 1 + $pageNav->limitstart; ?></td>
				<td>
					<input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id; ?>" onclick="isChecked(this.checked);" />
				</td>
				<td align="center"><?php echo $row->bracket; ?></td>
				<td align="center"><?php echo $row->roundnr; ?></td>
				<td align="center"><?php echo $row->matchnr; ?></td>
				<td><a href="#edit" onclick="return listItemTask('cb<?php echo $i;?>','edit')"><?php echo $row->player1_name; ?></a></td>
				<td align="center"><?php echo $row->clan1_result; ?></td>
				<td><a href="#edit" onclick="return listItemTask('cb<?php echo $i;?>','edit')"><?php echo $row->player2_name; ?></a></td>
				<td align="center"><?php echo $row->clan2_result; ?></td>
				<td><?php echo $row->eventname; ?> &raquo; <?php echo $row->categoryname; ?> &raquo; <?php echo $row->tournamentname; ?></td>
				<td align="center"><?php echo $row->tournamenttype == 'C' ? JText::_('clans') : JText::_('singleplayer'); ?></td>
				<td align="center">
					<?php if($row->player1_name && $row->player2_name) {
						if(!$row->result_submit) { ?>
							<a href="javascript: void(0);" onClick="return listItemTask('cb<?php echo $i;?>','<?php echo $task;?>')">
							<img src="images/publish_x.png" width="12" height="12" border="0" alt="" />
							</a>
						<?php } else { ?>
							<img src="images/tick.png" width="12" height="12" border="0" alt="" />
						<?php }
					} ?>
				</td>
			</tr>
			<?php
			$k = 1 - $k;
		}
		?>
		</table>
		<?php echo $pageNav->getListFooter(); ?>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
	
	function editBrackets(&$row, $lists, $option, $act) {
		?>
		<form action="index2.php" method="POST" name="adminForm">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments: <?php echo $row->id ? JText::_('edit_tournament_brackets') : JText::_('add_tournament_brackets');?></th>
		</tr>
		</table>
		<table class="adminform">
			<tr> 
				<td width="20%" align="right" valign="top"><?php echo JText::_('tournament') ?>:</td>
				<td width="80%"><?php echo $lists["tournamentid"]; ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('bracket') ?>:</td>
				<td><?php echo $lists["bracket"]; ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('roundnr') ?>:</td>
				<td><input class="text_area" type="text" name="roundnr" size="5" maxlength="5" value="<?php echo $row->roundnr; ?>" /></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('matchnr') ?>:</td>
				<td><input class="text_area" type="text" name="matchnr" size="5" maxlength="5" value="<?php echo $row->matchnr; ?>" /></td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('server') ?>:</td>
				<td><?php echo $lists["serverid"]; ?></td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_one_result') ?>:</td>
				<td><input class="text_area" type="text" name="clan1_result" size="5" maxlength="5" value="<?php echo $row->clan1_result; ?>" /></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_two_result') ?>:</td>
				<td><input class="text_area" type="text" name="clan2_result" size="5" maxlength="5" value="<?php echo $row->clan2_result; ?>" /></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('result_submit') ?>:</td>
				<td><?php echo $lists["result_submit"]; ?></td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_one') ?>:</td>
				<td><?php echo $lists["clan1id"]; ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_one_checkin') ?>:</td>
				<td><?php echo $lists["clan1_checkin"]; ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_one_checkin_time') ?>:</td>
				<td><input class="text_area" type="text" name="clan1_checkin_time" size="50" maxlength="50" value="<?php echo $row->clan1_checkin_time; ?>" /></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_one_submit') ?>:</td>
				<td><?php echo $lists["clan1_submit"]; ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_one_result_temp1') ?>:</td>
				<td><input class="text_area" type="text" name="clan1_result_temp1" size="5" maxlength="5" value="<?php echo $row->clan1_result_temp1; ?>" /></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_two_result_temp1') ?>:</td>
				<td><input class="text_area" type="text" name="clan2_result_temp1" size="5" maxlength="5" value="<?php echo $row->clan2_result_temp1; ?>" /></td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_two') ?>:</td>
				<td><?php echo $lists["clan2id"]; ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_two_checkin') ?>:</td>
				<td><?php echo $lists["clan2_checkin"]; ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_two_checkin_time') ?>:</td>
				<td><input class="text_area" type="text" name="clan2_checkin_time" size="50" maxlength="50" value="<?php echo $row->clan2_checkin_time; ?>" /></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_two_submit') ?>:</td>
				<td><?php echo $lists["clan2_submit"]; ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_one_result_temp2') ?>:</td>
				<td><input class="text_area" type="text" name="clan1_result_temp2" size="5" maxlength="5" value="<?php echo $row->clan1_result_temp2; ?>" /></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_two_result_temp2') ?>:</td>
				<td><input class="text_area" type="text" name="clan2_result_temp2" size="5" maxlength="5" value="<?php echo $row->clan2_result_temp2; ?>" /></td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('playtime') ?>:</td>
				<td><input class="text_area" type="text" name="playtime" size="50" maxlength="50" value="<?php echo $row->playtime; ?>" /></td>
			</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="task" value="" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
	
	function submitResults(&$row, $option, $act) {
		switch($row->bracket) {
			case "w":
				$row->bracket = JText::_('winner');
				break;
			case "l":
				$row->bracket = JText::_('loser');
				break;
			case "c":
				$row->bracket = JText::_('custom');
				break;
		}
		?>
		<form action="index2.php" method="POST" name="adminForm">
		<table class="adminheading">
		<tr>
			<th>myLANsite Tournaments: <?php echo JText::_('submit_results');?></th>
		</tr>
		</table>
		<table class="adminform">
			<tr> 
				<td width="20%" align="right" valign="top"><?php echo JText::_('tournament') ?>:</td>
				<td width="80%"><?php echo $row->eventname; ?> &raquo; <?php echo $row->categoryname; ?> &raquo; <?php echo $row->tournamentname; ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('bracket') ?>:</td>
				<td><?php echo $row->bracket; ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('roundnr') ?>:</td>
				<td><?php echo $row->roundnr; ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('matchnr') ?>:</td>
				<td><?php echo $row->matchnr; ?></td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_one') ?>:</td>
				<td><?php echo $row->player1_name; ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_one_result') ?>:</td>
				<td><input class="inputbox" type="text" name="clan1_result" size="5" maxlength="5" value="<?php echo $row->clan1_result; ?>" /></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_two') ?>:</td>
				<td><?php echo $row->player2_name; ?></td>
			</tr>
			<tr> 
				<td align="right" valign="top"><?php echo JText::_('player_two_result') ?>:</td>
				<td><input class="inputbox" type="text" name="clan2_result" size="5" maxlength="5" value="<?php echo $row->clan2_result; ?>" /></td>
			</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="<?php echo $act; ?>" />
		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="task" value="" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
}

/** Configuration **/
class HTML_MLS_tournaments_config {
	function editConfig($confarr, $lists, $option, $act) {
		global $mosConfig_live_site;
		?>
		<form action="index2.php" method="POST" name="adminForm">
		<table cellpadding="1" cellspacing="1" border="0" width="100%">
		<tr>
			<td width="250"><table class="adminheading"><tr><th nowrap class="config">myLANsite Tournaments: <?php echo JText::_('configuration')?></th></tr></table></td>
			<td width="270">
				<span class="componentheading">mls_tournaments.config.php is :
				<?php echo is_writable( '../components/com_mls_tournaments/mls_tournaments.config.php' ) ? '<b><font color="green"> Writeable</font></b>' : '<b><font color="red"> Unwriteable</font></b>' ?>
				</span>
			</td>
		</tr>
		</table>
		<table class="adminform">
			<tr>
				<th colspan="2"><?php echo JText::_('settings'); ?></th>
			</tr>
			<tr>
				<td width="20%" valign="top" align="right"><?php echo JText::_('paid_register'); ?>:</td>
				<td width="80%"><?php echo $lists["paid_register"]; ?></td>
			</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="act" value="configuration" />
		<input type="hidden" name="task" value="" />
		</form>
		<?php
		HTML_MLS_tournaments::printFooter($option);
	}
};
?>
