<?php
ob_start();
if(!(is_readable(realpath(dirname(__FILE__)).'/include/includesroutines.inc'))) {
	die('Error - Could not open or read file '.realpath(dirname(__FILE__)).'/include/includesroutines.inc');
} else {
	include_once(realpath(dirname(__FILE__)).'/include/includesroutines.inc');
}

if ( getSetting('portal','useRights',0) == 0){
	header("Location: ".getCurPageURLWO()."/businessmodel.php");
	ob_end_flush();
	exit;
}

checkUserAndRedirectToLogin();
RedirectToModelAnonymous();

$cn = db_connect();
$usr_arr = GetUserIDs();
?>
<!doctype html>
<html>
<head>
	<title><?php echo renderTitle();?></title>
	<? 
	renderCommonMeta(renderTitle()); 
	renderCommonCSS(); 
	?>
</head>
<body>
	<?php renderModalHourGlassDiv();?>
	<div id="container">
	<?php renderLoginBlock();?>
	<div id="main" role="main" class="ui-layout-center">
	<?php renderMainMenu(); ?>
		<div id="content" class="ui-layout-center">
		<section class="box-front front-menu clearfix">
<?php
	$u_ids = GetUserIDs();
	if (isset($_REQUEST['save']) && $_REQUEST['save'] == 1) {
		db_saveUserDataByID($cn, $u_ids[0],
			(isset($_REQUEST['user_idlanguageinterface']) ? $_REQUEST['user_idlanguageinterface'] : '' ) ,
			(isset($_REQUEST['user_idlanguagecontent']) ? $_REQUEST['user_idlanguagecontent'] : '' ) ,
			(isset($_REQUEST['user_notification_answer']) ? 1 : 0),
			(isset($_REQUEST['user_notification_allallow']) ? 1 : 0));

		if (isset($_REQUEST['user_idlanguageinterface']) && isset($_REQUEST['user_idlanguagecontent']) ) {
			$userlang = db_getLanguageShortByID($cn, $_REQUEST['user_idlanguageinterface'],true);
			$contlang = db_getLanguageShortByID($cn, $_REQUEST['user_idlanguagecontent']);
			$_SESSION['user_idlanguageinterface'] = $userlang;
			$_SESSION['user_idlanguagecontent'] = $contlang;
			header("Location: ".getCurPageURLWO()."/personalsettings.php?lang=".$userlang);
			ob_end_flush();
			exit;
		}
	}
	$us_arr = db_getUserDataByID($cn, $u_ids[0]);
	$ln_arr = db_getLanguagesTranslate($cn, db_getLanguageID($cn, getLanguage(), -1));
	$ln_arr_native = db_getLanguagesNative($cn, $_SESSION['allowLanguages']);
?>

<form id="personalsettings" method="post">
<?php if ( is_array($ln_arr) && sizeof($ln_arr) > 0 ) { ?>
<h2><?php getResource("field.languages");?></h2>
<div style="padding: 0px 0px 0px 20px;">
<table width="100%">
<tr>
<td width="5%" valign="middle"  style="vertical-align:middle"><h3><nobr><?php getResource("field.language.interface");?>&nbsp;&nbsp;</h3></nobr></td>
<td width="95%" valign="middle"  style="vertical-align:middle"><h3><select id="user_idlanguageinterface" name="user_idlanguageinterface" class="languages-box-select" >
<?php
	foreach ($ln_arr_native as $value){
		if ($us_arr['user_idlanguageinterface'] == $value['idlanguage']) {
			echo '<option value="'.$value['idlanguage'].'" selected="selected">'.$value['lang_name'].'</option>';
		} else {
			echo '<option value="'.$value['idlanguage'].'">'.$value['lang_name'].'</option>';
		}
	}
?>
</select>
</h3>
</td>
</tr>
<tr>
<td  valign="middle"  style="vertical-align:middle"><nobr><h3><?php getResource("field.language.data");?>&nbsp;&nbsp;</h3></nobr></td>
<td  valign="middle"  style="vertical-align:middle"><h3><select id="user_idlanguagecontent" name="user_idlanguagecontent" class="languages-box-select">
<?php
	foreach ($ln_arr as $value){
		if ($us_arr['user_idlanguagecontent'] == $value['idlanguage']) {
			echo '<option value="'.$value['idlanguage'].'" selected="selected">'.$value['lang_name'].'</option>';
		} else {
			echo '<option value="'.$value['idlanguage'].'">'.$value['lang_name'].'</option>';
		}
	}
?>
</select>
</h3>
</td>
</tr>
</table>
</div>
<br/>
<?php } ?>
<br/>
<h2><?php getResource("field.notifications");?></h2>
<div style="padding: 0px 0px 0px 20px;">
<h3><input type="checkbox" id="user_notification_allallow" name="user_notification_allallow" value="user_notification_allallow" <?php ($us_arr['user_notification_allallow'] == 1 ? print('checked') : print(''))?>>
<nobr><?php getResource("field.user_notification_allallow");?></nobr></h3>
<h3 style="margin-left: 20px;"><input disabled="disabled" type="checkbox" id="user_notification_answer" name="user_notification_answer" value="user_notification_answer" <?php ($us_arr['user_notification_answer'] == '1' ? print('checked') : print(''))?>>
<nobr><?php getResource("field.user_notification_answer");?></nobr></h3>
</div>

<br/>
<br/>
<span><button class="btn-top btn-top-text" title="<?php getResource("button.Save.hint");?>"><span><i class="fa fa-floppy-o" aria-hidden="true"></i> <?php getResource("button.Save");?></span></button></span>
<br/>
<br/>
<input id="hidepanel" type="hidden" name="save" value="1">
</form>
</section>
</div>
<?php renderFooterTemplate(); ?>
</body>
<script src="js/libs/jquery.layout.js"></script>
<script src="js/script.js"></script>
<script>
	var _GUrl = '<? echo getCurPageURLWO()."/service/getlanguages.php"; ?>';	
	$(function() {
		//62124
		enablecheCkboxes();
		$("#user_notification_allallow").click(enablecheCkboxes);
	});

	function enablecheCkboxes() {
		if($("#user_notification_allallow").attr("checked") != 'checked') { 
			$("#user_notification_answer").removeAttr("disabled");
		} else {
			$("#user_notification_answer").attr("disabled", true);
		}
	}	
</script>

<?php
	if(!(is_readable(realpath(dirname(__FILE__)).'/templates/languagesbox.template'))) {
		die('Error - Could not open or read file '.realpath(dirname(__FILE__)).'/templates/languagesbox.template');
	} else {
		include_once(realpath(dirname(__FILE__)).'/templates/languagesbox.template');
	}
?>

</html>
<?php
unset($u_ids);
unset($ln_arr);
unset($us_arr);

db_disconnect($cn);
ob_end_flush();
?>