<?php

defined('MAXIMUS') or die ('Access denied selectlanguage MAXIMUS directly...');

	global $useflags, $currentlang;
	if ($useflags == 1) {
		$title = _SELECTLANGUAGE;
		$content = "<center><font class='content'>"._SELECTGUILANG."<br /><br />";
		$langdir = dir("language");
		while($func=$langdir->read()) {
			if(substr($func, 0, 5) == "lang-") {
				$menulist .= "$func ";
			}
		}
		closedir($langdir->handle);
		$menulist = explode(" ", $menulist);
		sort($menulist);
		for ($i=0; $i < sizeof($menulist); $i++) {
			if($menulist[$i]!="") {
				$tl = ereg_replace("lang-","",$menulist[$i]);
				$tl = ereg_replace(".php","",$tl);
				$altlang = ucfirst($tl);
				$content .= "<a href=\"index.php?newlang=".$tl."\"><img src=\"images/language/flag-".$tl.".png\" border='0' alt=\"$altlang\" title=\"$altlang\" hspace='3' vspace='3' /></a> ";
			}
		}
		$content .= '</font></center>';
		themesidebox($title, $content);
	} else {
		$title = _SELECTLANGUAGE;
		$content = "<center><font class='content'>"._SELECTGUILANG."<br /><br /></font>";
		$content .= "<form action='index.php' method='get'><select name='newlanguage' onChange='top.location.href=this.options[this.selectedIndex].value'>";
		$handle=opendir('language');
		while ($file = readdir($handle)) {
			if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
				$langFound = $matches[1];
				$languageslist .= "$langFound ";
			}
		}
		closedir($handle);
		$languageslist = explode(" ", $languageslist);
		sort($languageslist);
		for ($i=0; $i < sizeof($languageslist); $i++) {
			if($languageslist[$i]!="") {
				$content .= "<option value=\"index.php?newlang=$languageslist[$i]\" ";
				if($languageslist[$i]==$currentlang) $content .= ' selected';
				$content .= ">".ucfirst($languageslist[$i])."</option>\n";
			}
		}
		$content .= '</select></form></center>';
		themesidebox($title, $content);
	}