<?php


class SE_Layout {

	public static function getTitle() {
		$title = 'SE';

		$host = $_SERVER['SERVER_NAME'];
		if (substr($host, 0, 5) == 'biuro') {
			$host = substr($host, 6);
		}

		// TODO: add current table name

		$title = "{$host}-SE";

		return $title;
	}

	public static function gora() {
		Lib::loadClass('S');
	?><!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title><?php echo self::getTitle(); ?></title>
	<link rel="shortcut icon" type="image/x-icon" href="./favicon.png?v=0.1">
	<meta name="author" content="Piotr Labudda <piotrl86@gmail.com>" />
	<link rel="stylesheet" href="stuff/twitter-bootstrap/css/bootstrap.css" type="text/css" />
	<link rel="stylesheet" href="stuff/jquery.selectize/css/selectize.bootstrap2.css" type="text/css" />
	<link rel="stylesheet" href="stuff/bootstrap-datepicker/css/datepicker.css" type="text/css" />
	<link rel="stylesheet" href="stuff/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" type="text/css" />
	<link rel="stylesheet" href="stuff/main.css" type="text/css" />
	<script src="stuff/jquery-2.1.0.min.js"></script>
	<script src="stuff/jquery-plugins.js"></script>
	<script src="stuff/jquery.autosize.min.js"></script>
	<script src="stuff/twitter-bootstrap/js/bootstrap.min.js"></script>
	<script src="stuff/jquery.selectize/js/standalone/selectize.min.js"></script>
	<script src="stuff/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
	<script src="stuff/bootstrap-datepicker/js/locales/bootstrap-datepicker-pl.js"></script>
	<script src="stuff/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
	<script src="stuff/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker-pl.js"></script>
	<script src="stuff/notify.min.js"></script>
	<script src="stuff/jquery-ui-1.10.4.custom.min.js"></script>
	<script src="stuff/jquery.hotkeys.js"></script>
	<style type="text/css">
.typepsecial .selectize-input { width:366px; padding:4px 6px; }
.typepsecial .selectize-control::before {
	-moz-transition: opacity 0.2s;
	-webkit-transition: opacity 0.2s;
	transition: opacity 0.2s;
	content: ' ';
	z-index: 2;
	position: absolute;
	display: block;
	top: 12px;
	right: 34px;
	width: 16px;
	height: 16px;
	background: url(stuff/i/loading.gif);
	background-size: 16px 16px;
	opacity: 0;
}
.typepsecial .selectize-control.loading::before {
	opacity: 0.4;
}
.typepsecial .selectize-control.single .selectize-input {
	color: #333;
	text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
	background-color: #fff;
	background-image: none;
	background-repeat: none;
	border-color: #ccc;
	filter: none;
	-webkit-box-shadow: none;
	-moz-box-shadow: none;
	box-shadow: none;
}

	</style>
	<?php S::printTimeoutUpdateJs(); ?>
	<script>
jQuery(document).ready(function(){
	jQuery('.se_type-date').datepicker({
		format: "yyyy-mm-dd"
		, language: 'pl'
		, todayBtn: "linked"
	});
	jQuery('.se_type-datetime').parent().datetimepicker({
		language: 'pl'
		, format: 'yyyy-MM-dd hh:mm'
		, weekStart: 1
	//	, todayBtn: "linked"
	});
});

function ClearAllFind() {
	var ElementsObj=document.forms["FILTER_SEARCH"] ;
	var ElementsArr=ElementsObj.elements ;	

	for (var myprop in ElementsArr){

	     if(ElementsArr[myprop]) {
		if((ElementsArr[myprop].type=="text")||(ElementsArr[myprop].type=="select-one")){
			var MyEval="var My"+ElementsArr[myprop].name+"=document.getElementById('"+ElementsArr[myprop].name+"\');";
			eval(MyEval);
			var MyEval="My"+ElementsArr[myprop].name+".value=\"%\"";
			eval(MyEval);
		}
	     }
	}
}

function resetForm(n) {
	for (i = 0; i < n.form.elements.length; i++) {
		switch (n.form.elements[i].type.toLowerCase()){
			case 'text':
				n.form.elements[i].value='%';
				break;
			case 'select-one':
//				n.form.elements[i].options[0].selected = true;
//				break;
			case 'select-multiple':
				for (z = 0; z < n.form.elements[i].options.length; z++) {
					n.form.elements[i].options[z].selected = false;
					if (n.form.elements[i].options[z].hasAttribute('selected')) {
						n.form.elements[i].options[z].removeAttribute('selected');
					}
				}
				// select first element
				n.form.elements[i].options[0].selected = true;
				n.form.elements[i].options[0].setAttribute('selected', 'selected');
				break;
			default:
				
		}
	}
	return false;
}
	</script>

	<style type="text/css">
.hidden-dbg { display:none; color:silver; }
.show-hidden-dbg .hidden-dbg { display:inline; }
	</style>
<?php if (User::hasAccess('dbg')) : ?>
	<script>
jQuery(document).bind('keydown', 'alt+shift+`', function(){
	jQuery(document.body).addClass('show-hidden-dbg');
});
jQuery(document).bind('keyup', 'alt+shift+`', function(){
	jQuery(document.body).removeClass('show-hidden-dbg');
});
	</script>
<?php endif; ?>

</head><body>
		<?php
	}

	public static function dol() {
		$version = (file_exists(APP_PATH_ROOT . '/VERSION'))? file_get_contents(APP_PATH_ROOT . '/VERSION') : null;
		if ($version) {
			echo '<div style="border-top:1px solid #ddd;margin-top:10px;padding:0 30px;font-size:xx-small;color:#888;">version: '.$version.'</div>';
		}
		echo "\n</body></html>";
	}

	public static function menu() {
		if (!User::logged()) return;

		if (User::hasAccess('menu')) {
			Lib::loadClass('ProcesMenu');

			$procesMenu = ProcesMenu::getInstance();
			$procesMenu->show();

			if (!V::get('MENU_INIT', '', $_GET)) {
				Lib::loadClass('UserActivity');
				//echo UserActivity::showListInContainer();
			}

		}
		else {
			SE_Layout::loadTemplate('menuLevel6');
		}
	}

	public static function loadTemplate($tmplName, $data = array()) {
		if (is_array($data) && !empty($data)) {
			extract($data);
		}
		include APP_PATH_LIB . "/tmpl/{$tmplName}.php";
	}

	public static function hotKeyDBG($str) {
		if (User::hasAccess('dbg')) {
			echo '<span class="hidden-dbg">' . htmlspecialchars($str) . '</span>';
		}
	}

}
