<?php
/* $Id: step_1.inc.php,v 1.12 2003/11/18 20:36:35 k-fish Exp $ */
if(!defined("SETUP_RUNNING")) die('Use index.php for running setup!');

include("../include/mSelectBox.class.php");

/* get languages from the lang files in setup */
$dir = opendir(ROOTPATH.'/'.SETUP_DIR."/lang/");
while (($fn = readdir($dir)) !== false) {
    if(strstr($fn, '.lang')){
	$fh = fopen(ROOTPATH.'/'.SETUP_DIR . "/lang/".$fn, "r");
	$l = fgets($fh, 1024);
	fclose($fh);
	$la = explode(':', trim(substr($l, 1)));
	$_SESSION["SETUP"]['languages'][$la[2].';'.$la[1]] = $la[0];
    }
}
closedir($dir);
asort($_SESSION["SETUP"]['languages']);
$smarty->assign('languages', $_SESSION["SETUP"]['languages']);

/* check posted data in case of refresh */
if (isset($_POST["lang_charset"])) {
    $lc = explode(";", $_POST["lang_charset"]);
    $_SESSION["SETUP"]["lang"] = $lc[0];
    $_SESSION["SETUP"]["charset"] = $lc[1];
}

/* see if the user regional settings matches something we know */
if (isset($_SESSION["SETUP"]["lang"]) and isset($_SESSION["SETUP"]["charset"])) {
    $lang = $_SESSION["SETUP"]["lang"].";".$_SESSION["SETUP"]["charset"];
}
else {
    foreach(array_keys($_SESSION["SETUP"]['languages']) as $lang){
	if (stristr($_SERVER["HTTP_ACCEPT_LANGUAGE"], substr($lang,0,strpos($lang,';')))!==false){
	    break;
	}
    }
}
$smarty->assign("setlang", $lang);

$smarty->append("subnav", array(0=>"refresh",1=>Lang::getLanguageString("refresh"),2=>1));
?>