<?php
include("postget.php");
include_once("common.php");
checklevel(4,$_REQUEST['clientid']);
if ($config[56][1]==1){
	messagetop(_CHANGE_NOT_ALLOWED_IN_DEMO_MODE,'','index.php',0); 
}

global $isclient;
$isclient=0;


if ($config[56][1]==0){     // si no es demo
	////////////////////// cambiar el lenguaje ////////////////////////////////////////
	if ($newlang!=$langdefault AND $newlang!='')
	{
		$query="UPDATE hd_config SET valor='$newlang' WHERE variable='language'";
		if(mysql_query($query,$db_link)) {
			messagetop(_THE_CHANGES_WHERE_MADE_SUCCESSFULLY,'','preferences.php?option=1',1);
		}
	}

	///////////////////////////////////////////////////////////////////////////////////
	////////////////////// cambiar el theme    ////////////////////////////////////////
	if ($newtheme!=$themedefault AND $newtheme!='') {
		$query="UPDATE hd_config SET valor='$newtheme' WHERE variable='theme'";
		if(mysql_query($query,$db_link)) {
			messagetop(_THE_CHANGES_WHERE_MADE_SUCCESSFULLY,'','preferences.php?option=1',1);
		}
	}

	///////////////////////////////////////////////////////////////////////////////////
	$mensaje="";
}else{
	$mensaje= _CHANGE_NOT_ALLOWED_IN_DEMO_MODE;
}

//include("head_template.php");



function selectlanguage()
{
	global $langdefault, $content;
	$content = "<form action=\"preferences01.php?currentlang=$langdefault\" method=\"get\">"._SET_LANGUAGE_AS_DEFAULT.": ".tip(26)."<select name=\"newlanguage\" onChange=\"top.location.href=this.options[this.selectedIndex].value\">";
	
	$content .= "<option value=\"preferences01.php?newlang=autodetect\" ";
	if('autodetect'==$langdefault) $content .= " selected";
	$content .= ">**".ucfirst(_AUTODETECT)."**</option>";
	
	$result = mysql_query("SHOW COLUMNS FROM hd_languages");
	if (mysql_num_rows($result) > 0) {
		while ($row = mysql_fetch_assoc($result)) {
			if ($row[Field]<>'original'){
				$content .= "<option value=\"preferences01.php?newlang=$row[Field]\" ";
				if($row[Field]==$langdefault) $content .= " selected";
				$content .= ">".langname($row[Field])."</option>";
			}
		}
	}

	$content .= "</select></form>";
	return $content;
}



function selecttheme()
{
	global $themedefault, $content;
        
	$content = "<form action=\"preferences01.php?currentlang=$themedefault\" method=\"get\">"._SET_THEME_AS_DEFAULT.": ".tip(27)."<select name=\"newtheme\" onChange=\"top.location.href=this.options[this.selectedIndex].value\">";
	
	$content .= "<option value=\"preferences01.php?newtheme=light\" ";
	if('light'==$themedefault) $content .= " selected";
	$content .= ">Light</option>";
	
	$content .= "<option value=\"preferences01.php?newtheme=semilight\" ";
	if('semilight'==$themedefault) $content .= " selected";
	$content .= ">Semi-Light</option>";
	
//	$content .= "<option value=\"preferences01.php?newtheme=dark\" ";
//	if('dark'==$themedefault) $content .= " selected";
//	$content .= ">Dark</option>";
	

	$content .= "</select></form>";
	return $content;
}

?>

<table width="90%" cellspacing="6">
<tr>
<td valign="top">

<?php

$query="SELECT valor,ref FROM hd_config WHERE ref='3'";
$result=mysql_query($query,$db_link);
$row=mysql_fetch_row($result);
$langdefault=$row[0];

$query="SELECT valor,ref FROM hd_config WHERE ref='25'";
$result=mysql_query($query,$db_link);
$row=mysql_fetch_row($result);
$themedefault=$row[0];
$theme=$row[0];

echo '

<table width="98%" class="table table-bordered">
		<tr>
		<td align="center" width="100%">
';
echo '
		</td>
		</tr>
';

echo '
			<tr valign="top">
				<td>

';

echo "<br>";
selectlanguage($langdefault);
echo $content;
echo "<br>";

if (substr($license,0,4)=='FREE') {
	echo "<hr>";
	echo messagetopinthispage(lang('_AVAILABLE_ONLY_IN_THE_PREMIUM_VERSION'),'',2);
}

selecttheme($themedefault);
echo $content;

echo "<br><b>".$mensaje."</b>";
echo '
		</td>
		</tr>
		</table>
';



echo "</td></tr></table>";
?>
