<?php
$title = $l = "Смена языка";
require (CORE."head.php");
if (isset($_POST['cfms']))
{
if (!isset($_POST['language']) || stripcslashes(htmlspecialchars($_POST['language'])) == NULL || !is_dir(CORE.'languages/'.stripcslashes(htmlspecialchars($_POST['language']))) || stripcslashes(htmlspecialchars($_POST['language'])) == '.' || stripcslashes(htmlspecialchars($_POST['language'])) == '..')
{
$error = 'Выберите язык!';
}
if (!isset($error))
{
if (isset($user['id']))
{
DB :: $pdo -> query("UPDATE `users` SET `language` = '".stripcslashes(htmlspecialchars($_POST['language']))."' WHERE `id` = '".$user['id']."' LIMIT 1");
} else {
$_SESSION['language'] = stripcslashes(htmlspecialchars($_POST['language']));
}
system :: redirect("Язык сайта успешно изменен.", "/language/");
}
}
if (isset($error))
{
system :: show($error);
}
?>
<div class="app-block">
<div class="list">
<form class="post-add" method="post" data-noajax action="/language/">
<?
$ln_dir = opendir(CORE.'languages');
while($lan_dir = readdir($ln_dir))
{
if (is_dir(CORE.'languages/'.$lan_dir) && $lan_dir!='.' && $lan_dir!='..')
{
$ln_config = parse_ini_file(CORE.'languages/'.$lan_dir.'/config.ini');
if (is_file("".$_SERVER['DOCUMENT_ROOT']."/template/languages_img/".$lan_dir.".gif"))
{
$ln_img = 'background-image: url(/template/languages_img/'.$lan_dir.'.gif); ';
}
else if (is_file("".$_SERVER['DOCUMENT_ROOT']."/template/languages_img/".$lan_dir.".png"))
{
$ln_img = 'background-image: url(/template/languages_img/'.$lan_dir.'.png); ';
}
else if (is_file("".$_SERVER['DOCUMENT_ROOT']."/template/languages_img/".$lan_dir.".jpg"))
{
$ln_img = 'background-image: url(/template/languages_img/'.$lan_dir.'.jpg); ';
} else {
$ln_img = '';
}
?>
<label style="display: block; padding: 0 10px; cursor: pointer;">
<input name="language" value="<?echo $lan_dir;?>"<?echo "".($language==$lan_dir?" checked='checked'":null)."";?> type="radio">
<span style="<?echo $ln_img;?>display: inline-block; margin-left: 10px; padding-left: 30px; height: 42px; line-height: 42px; background-repeat: no-repeat; background-position: 0; background-size: 24px 18px; color: #426a87; font-weight: 700;">
<?echo $ln_config['name'];?>
</span>
</label>
<?
}
}
?>
<div class="_center" style="margin-top: 3px;">
<input class="main-btn _w-100" name="cfms" value="Сохранить" type="submit">
</div>
</form>
</div>
<?
require (CORE."foot.php");
?>