<?php
if( $a == 'list' ){
	if( isset( $_POST['sOption'] ) ){
		if( !isset( $_POST['aEnabledLangs'] ) ) $_POST['aEnabledLangs'] = Array( );
		$aSave = Array( 'enabled_langs' => json_encode( array_keys( $_POST['aEnabledLangs'], 1 ) ) );
		saveVariables( $aSave, DB_CONFIG );
		saveVariables( $_POST, DB_CONFIG_LANG );
		header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $aActions['f'] . '-list&sOption=save' );
		exit;
	}
	if( isset( $sOption ) ) $content.= $oTpl->parse( 'message_done.tpl' );
	$aYesNo = Array( '0' => $lang['no'], '1' => $lang['yes'] );
	$aLanguages = throwLanguages( );
	$aEnabledLangs = json_decode( htmlspecialchars_decode( $config['enabled_langs'] ) );
	if( $aEnabledLangs == null ) $aEnabledLangs = Array( );
	$oTpl->assign( 'aYesNo', $aYesNo );
	$oTpl->assign( 'aLanguages', $aLanguages );
	$oTpl->assign( 'aEnabledLangs', $aEnabledLangs );
	$content.= $oTpl->parse( 'lang_list.tpl' );
} elseif( $a == 'delete' && isset( $_GET['sLanguage'] ) && !empty( $_GET['sLanguage'] ) ){
	deleteLanguage( $_GET['sLanguage'] );
	header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $aActions['f'] . '-list&sOption=del' );
	exit;
} elseif( $a == 'form' ){
	if( isset( $_POST['sOption'] ) ){
		addLanguage( $_POST['language'], $_POST['language_from'] );
		header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $aActions['f'] . '-list&sOption=save' );
		exit;
	}
	if( isset( $sOption ) ) $content.= $oTpl->parse( 'message_done.tpl' );
	$content.= $oTpl->parse( 'lang_form.tpl' );
} elseif( $a == 'translations' && isset( $_GET['sLanguage'] ) && !empty( $_GET['sLanguage'] ) ){
	if( isset( $_POST['sOption'] ) ){
		saveVariables( $_POST, DIR_LANG . $_GET['sLanguage'] . '.php', 'lang' );
		header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $p . '&sOption=save&sLanguage=' . $_GET['sLanguage'] );
		exit;
	}
	if( isset( $sOption ) ) $content.= $oTpl->parse( 'message_done.tpl' );
	$aLangVariables = throwLangVariables( $_GET['sLanguage'] );
	$oTpl->assign( 'aLangVariables', $aLangVariables );
	$oTpl->assign( 'sTranslatedLanguage', $_GET['sLanguage'] );
	$content.= $oTpl->parse( 'lang_translations.tpl' );
}
?>