<?php
//define this module's name and path
$mn = "odyssey_languages";
include("modules/modules.php");

/*
Available variables:
All system classes
All request variables
$p (the template path)
$mp (the module path)
$sufixID (id sufix for this module's divs)
*/

if($moduleParameters['moduleAlign'] && $moduleParameters['moduleHR']){ // there are system parameters...
$marginTop = ($moduleParameters['marginTop'] == "__EMPTY__" || empty($moduleParameters['marginTop'])) ? 0 : $moduleParameters['marginTop'];
$marginRight = ($moduleParameters['marginRight'] == "__EMPTY__" || empty($moduleParameters['marginRight'])) ? 0 : $moduleParameters['marginRight'];
$marginBottom = ($moduleParameters['marginBottom'] == "__EMPTY__" || empty($moduleParameters['marginBottom'])) ? 0 : $moduleParameters['marginBottom'];
$marginLeft = ($moduleParameters['marginLeft'] == "__EMPTY__" || empty($moduleParameters['marginLeft'])) ? 0 : $moduleParameters['marginLeft'];
$paddingTop = ($moduleParameters['paddingTop'] == "__EMPTY__" || empty($moduleParameters['paddingTop'])) ? 0 : $moduleParameters['paddingTop'];
$paddingRight = ($moduleParameters['paddingRight'] == "__EMPTY__" || empty($moduleParameters['paddingRight'])) ? 0 : $moduleParameters['paddingRight'];
$paddingBottom = ($moduleParameters['paddingBottom'] == "__EMPTY__" || empty($moduleParameters['paddingBottom'])) ? 0 : $moduleParameters['paddingBottom'];
$paddingLeft = ($moduleParameters['paddingLeft'] == "__EMPTY__" || empty($moduleParameters['paddingLeft'])) ? 0 : $moduleParameters['paddingLeft'];
$useModuleContainer = ($moduleParameters['useModuleContainer'] == "__EMPTY__" || empty($moduleParameters['useModuleContainer'])) ? 0 : (int)$moduleParameters['useModuleContainer'];
$widthInPixels = ($moduleParameters['widthInPixels'] == "__EMPTY__" || empty($moduleParameters['widthInPixels'])) ? null : (int)$moduleParameters['widthInPixels'];

if(empty($marginTop) && empty($marginRight) && empty($marginBottom) && empty($marginLeft)){
	$Mmargin = "0";
}else{
	$Mmargin = $marginTop." ".$marginRight." ".$marginBottom." ".$marginLeft." ";
}
if(empty($paddingTop) && empty($paddingRight) && empty($paddingBottom) && empty($paddingLeft)){
	$Mpadding = "0";
}else{
	$Mpadding = $paddingTop." ".$paddingRight." ".$paddingBottom." ".$paddingLeft." ";
}

$displayMode = $moduleParameters['displayMode'];
$containerClass = $moduleParameters['containerClass'];
$textSeperatorColor = $moduleParameters['textSeperatorColor'];
$textModeFontSize = str_replace("px", null, $moduleParameters['textModeFontSize']);
$cssContent = $moduleParameters['cssContent'];
$flagWidth = (!empty($moduleParameters['flagWidth'])) ? $moduleParameters['flagWidth'] : null;
$flagHeight = (!empty($moduleParameters['flagHeight'])) ? $moduleParameters['flagHeight'] : null;
$flagBorderColor = $moduleParameters['flagBorderColor'];
$selectHeight = 18 + (!empty($flagBorderColor) * 4);
$imageMarginBottom = 6 + (!empty($flagBorderColor) * 2);

$activeLanguages = $language->getActiveLanguages();
$numOfActiveLanguages = count($activeLanguages);
$flagsWidth = ($numOfActiveLanguages - 1) * 34;

if($useModuleContainer ){
?>
<div id="<?php echo $mn.$sufixID;?>" data-editable="editable" class="ody_language_selector">
<?php
}
?>
<style type="text/css">
#<?php echo $mn.$sufixID;?>{
	<?php 
	$alignRule = ($moduleParameters['moduleAlign'] == "center") ? "text-align" : "float";
	echo $alignRule.": ".$moduleParameters['moduleAlign'].";".PHP_EOL;
	?>
	margin : <?php echo $Mmargin;?>;
	padding : <?php echo $Mpadding;?>;
<?php 
if($displayMode != "list") { 
?>
	width3: <?php echo $flagsWidth;?>px; 
<?php 
}elseif(!empty($widthInPixels)){
	?>
	width: <?php echo $widthInPixels;?>px;
	<?php 
}	
if($moduleParameters['moduleHR'] == "top" || $moduleParameters['moduleHR'] == "bottom"){
?>
	border-<?php echo $moduleParameters['moduleHR'];?> : 1px solid black;
<?php 
}
?>
}
<?php
if(!empty($cssContent)){ // load custom css 
	echo $variables->restoreModuleValue($cssContent).PHP_EOL;
}
if(!empty($textSeperatorColor)){
?>
.languages li{
	border-left-color: #<?php echo $textSeperatorColor;?>;
}
<?php 
}
if(!empty($textModeFontSize)){
?>
.languages a{
	font-size: <?php echo $textModeFontSize;?>px;
}
<?php 
}
?>
#<?php echo $mn.$sufixID;?> img{
	display:inline;
	<?php
	if(!empty($flagBorderColor)){
	?>
	border:1px solid #<?php echo $flagBorderColor;?>;
	<?php 
}else{
	?>
	border: none;	
	<?php 
}
	?>
	margin-bottom: -<?php echo $imageMarginBottom;?>px;	
	padding:1px;
}
#<?php echo $mn.$sufixID;?> select{
	height: <?php echo $selectHeight;?>px;
	<?php
	if(!empty($flagBorderColor)){
	?>
	border:1px solid #<?php echo $flagBorderColor;?>;
	<?php 
}else{
	?>
	border: none;	
	<?php 
}
	?>
}
</style>
<?php 
}
if($displayMode == "text"){
?>
<ul<?php if(!empty($containerClass)) echo ' class="'.$containerClass.'"';?>>
<?php 
}
$language->displayLanguageMenu($displayMode, $flagWidth, $flagHeight);
if($displayMode == "text"){
?>
</ul>
<?php 
}
if($useModuleContainer ){
?>
</div>
<?php
}
?>
