<?php
////////////////////////////////////////////////////////////////////////
// $Id: index.php,v 1.6 2005/08/07 12:09:15 claudiuc Exp $
//
// Description: 	i18n teams administration application - main
// Author:      	Claudiu Costin <claudiuc@i18n.kde.org
// New KDE Layout : Nicolas Ternisien <nicolas.ternisien@gmail.com>
// License:     	GPL
//
////////////////////////////////////////////////////////////////////////

//Header of the page
$page_title ="Translation Teams";

$showedit=false;

include_once("lib/config.php");
include_once("lib/functions.php");
include_once("stats/configuration.inc.php");
include_once("stats/stats-functions.inc.php");

include("header.inc");

openlog("i18n-teams",LOG_PID,LOG_LOCAL4);

$currdate = date("Y-m-d",mktime());
$GLOBALS["dbh"]=initdb(config("mysql_host"), config("mysql_user"), config("mysql_password"), config("mysql_database"));


if (array_key_exists("sort", $_GET))
	$sort=$_GET['sort'];
else
	$sort="";		

if ($sort=="isocode") {
	$query="SELECT teamcode,teamname,mailinglist,website FROM teaminfo where status=1 ORDER BY teamcode";
}
else {
	$query="SELECT teamcode,teamname,mailinglist,website FROM teaminfo where status=1 ORDER BY teamname";
}

$teamsarray=array();
if ($result=mysql_query($query, $GLOBALS["dbh"])) {
	while($row=mysql_fetch_array($result)) {
		$teamsarray[]=$row;;
	}
}

echo "


<p>
If the team of the language you are searching for is not here, please contact <a href='mailto:kde-i18n-doc@kde.org'>kde-i18n-doc@kde.org</a> to 
request more information on how to create a new team.
</p>

<form action='team-infos.php' method='get' id='changeteam'>
	<img src='../img/info.png' alt='Info' />
	<strong>Go to:</strong> " . team_selector("teamcode", "", get_teamnames(), "onchange='javascript:submit()'") . "
</form>

Sort by : 
<a href='" . $_SERVER['SCRIPT_NAME'] ."'>name</a> |
<a href='" . $_SERVER['SCRIPT_NAME'] ."?sort=isocode'>ISO code</a>

<div id='teamlist'>
";

echo render_teams_bar($teamsarray, $sort, $GLOBALS["dbh"]);

echo "
	</div>
	
	<p>
	To see the full list of ISO codes, please visit the <a href='http://www.loc.gov/standards/iso639-2/php/English_list.php'>Codes for the
	Representation of Names
	of Languages</a> page.
	</p>
	
";

//Footer of the page
include("footer.inc");

//
// render teams bar, rows oriented
//
function render_teams_bar($teams, $sort) {
	$colteam=3;
	
	$teamitem="";
	$cnt=1;
	$altcolor=0;
	$tdpercent= floor(100/$colteam);
	$trcolor="";

	//Header
	$teamitem="
		<table class='datalist'>
			<thead>
				<tr>
					<th>Team</th>
				</tr>
			</thead>
			<tbody>
	";
	
	foreach ($teams as $row) {
		$trcolor = ($trcolor=="odd") ? "even" : "odd";
		
		$teamitem.="<tr class='$trcolor'>";
		
		if ($sort=="isocode") {
			$teamname="
				".$row["teamcode"]."
							<span style='font-size:x-small;'>(".
								$row["teamname"].
							")</span>
			";		
		}
		else {
			$teamname="
				".$row["teamname"]."
							<span style='font-size:x-small;'>(".
								$row["teamcode"].
							")</span>
			";
		}
		
		$mailinglist=html_entity_decode($row['mailinglist'], ENT_QUOTES);
		if ($mailinglist==NULL)
			$mailinglist="<em>None</em>";
		
		$website=html_entity_decode($row['website'], ENT_QUOTES);
		if ($website==NULL)
			$website="<em>None</em>";

		$teamitem .="<td class='teamname'>
						<a href='team-infos.php?teamcode=".$row["teamcode"]."' title='Details...'>$teamname</a>
					</td>
		";
		
				
		
		$teamitem .="</tr>";

		$cnt++;
	}
	
	//Footer
	$teamitem.= "
			</tbody>
		</table>
	";
	
	
	return $teamitem;
}

?>
