<?php 
	require_once(ROOT . 'modules/users/list-vacations.php'); 
	
	if(!isset($_GET['new'])){$moreinfo = '1';}
	
	if(isset($_GET["id"]) AND $_GET["id"] != ''){
		$pageTitle 	= 'Заявление №' . $_GET["id"];
	} elseif(isset($_GET["new"])) {
		$pageTitle 	= 'Добавление нового заявления';
	} else {
		$pageTitle 	= 'График отпусков за '. $sel_year . ' год';
	}
		
	require_once(ROOT . 'templates/header.php'); 
	
	
	
	require_once(ROOT . 'templates/main-menu.php');
	
	$dom = new DOMDocument;
	$dom->load($baseU);
	$xpath = new DOMXPath($dom);
?>
<div class="container<?php global $designView; echo $designView; ?>">
	<div class="row">
	
		<?php if(isset($_GET["new"])){ ?>
		<div class="col-lg-12">
			<div class="row">
				<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12">
					<h1 style="margin-bottom:23px;"><?php echo $pageTitle; ?></h1>
				</div>
				<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
					<?php require_once(ROOT . 'templates/side-block.php'); ?>
				</div>
			</div>
			<form method="POST">
				<div class="row">
					<div class="form-group col-lg-6">
						<div class="input-group">
							<span class="input-group-addon"><i class="fa fa-fw fa-list-ul" aria-hidden="true"></i></span>
							<select class="form-control" name="selectType" onchange="vac_comm();">
								<option value="vac-1">Основной оплачиваемый отпуск</option>
								<option value="vac-2">Отпуск без сохранения заработной платы</option>
								<option value="vac-3">Отпуск по беременности и родам</option>
								<option value="vac-4">Отпуск по уходу за ребенком</option>
								<option value="vac-5">Учебный отпуск</option>
								<option value="vac-6">Отпуск в счет переработок</option>
							</select>
						</div>
					</div>
					<div class="form-group col-lg-3">
						<div class="input-group">
							<span class="input-group-addon" title="Сотрудник"><i class="fa fa-fw fa-user" aria-hidden="true"></i></span>
							<select class="form-control" name="selectUser" id="selectUser">
								<?php if (isset($Login) AND $LoginCheck == $Login or $GroupCheck != 'user') { ?><option value="">--- пусто ---</option><?php } ?>
								<?
									$users = $xpath->query('/users/user');
									if($GroupCheck == 'guest' OR $GroupCheck == 'user'){
										echo '<option value="'.$LoginCheck.'">'.get_user_name_login($LoginCheck, '').'</option>';
									}else{
										foreach ($users as $user) {
											$UserLogin 		= $user->getAttribute('login');
											echo '<option value="'.$UserLogin.'">'.get_user_name_login($UserLogin, '').'</option>';
										}
									}
								?>
							</select>
						</div>
					</div>
					<div class="form-group col-lg-3">
						<div class="input-group">
							<span class="input-group-addon" title="Согласовант"><i class="fa fa-fw fa-user-o" aria-hidden="true"></i></span>
							<select class="form-control" name="selectAgreed" id="selectAgreed">
								<?php if (isset($Login) AND $LoginCheck == $Login or $GroupCheck != 'user') { ?><option value="">--- пусто ---</option><?php } ?>
								<?
									$agreed = $xpath->query('/users/user[@group="manager"]');
									foreach ($agreed as $user) {
										$UserLogin 		= $user->getAttribute('login');
										echo '<option value="'.$UserLogin.'">'.get_user_name_login($UserLogin, '').'</option>';
									}
								?>
							</select>
						</div>
					</div>
					<div class="form-group col-lg-3">
						<div class="input-group date-pick" style="position:relative;margin-bottom:15px;width:auto;">
							<span class="input-group-addon" title="Дата добавления"><i class="fa fa-fw fa-calendar-plus-o" aria-hidden="true"></i></span>
							<input type="text" class="form-control dateS" name="inputDateStart" placeholder="ГГГГ-ММ-ДД" value="<?php echo date("Y-m-d"); ?>" required />
						</div>
					</div>
					<div class="form-group col-lg-3">
						<div class="input-group">
							<span class="input-group-addon" title="Период отпуска"><i class="fa fa-fw fa-calendar" aria-hidden="true"></i> Период ( дни )</span>
							<input type="number" class="form-control" name="inputPeriod" min="1" max="28" inputmode="numeric" value="14" required />
						</div>
					</div>
					<div class="form-group col-lg-3">
						<div class="input-group">
							<span class="input-group-addon" title="Комментарий"><i class="fa fa-fw fa-commenting" aria-hidden="true"></i></span>
							<input type="text" class="form-control" name="inputComm" value="" placeholder="Комментарий">
						</div>
					</div>
					<div class="form-group col-lg-3">
						<div class="btn-group btn-group-justified"  style="width:100%;margin:0px 0px 15px 0px;">
							<button type="submit" name="AddVacation" style="width:100%;" class="btn btn-success" style="color:#fff;">Добавить</button>
						</div>
					</div>
				</div>
			</form>
		</div>
		<?php } else { ?>
		<div class="col-lg-3 col-lg-push-9 col-md-4 col-md-push-8 col-sm-12">
			<?php require_once(ROOT . 'templates/side-block.php'); ?>
		</div>
		<div class="col-lg-9 col-lg-pull-3 col-md-8 col-md-pull-4 col-sm-12">
			<h1 style="margin-bottom:23px;"><?php echo $pageTitle; ?> <?php if(!isset($_GET["new"])){ ?><span class="list-num"><i class="fa fa-fw fa-angle-double-down" aria-hidden="true"></i> <?php echo $countvacation; ?><? } ?></span></h1>
			<?php require_once(ROOT . 'templates/search-form.php'); ?>
			<?php require_once(ROOT . 'modules/users/list-vacations-m.php'); ?>
			<?php require_once(ROOT . 'templates/table-pager.php'); ?>
		</div>
		<?php } ?>
	</div>

	<div class="row"  style="margin-top:35px;">
		<div class="col-lg-12">
			<h1>План-график отпусков сотрудников</h1>
			<div class="row">
				<div class="col-lg-12 col-md-12 col-sm-12">
					<?php require_once(ROOT . 'modules/users/func-timeline.php'); ?>
				</div>
			</div>
		</div>
	</div>
		
		
</div>
<script type="text/javascript">
	function vac_comm(){
		var vac_type = $('form select[name=selectType] option:selected').text();
		$('form input[name=inputComm]').val(vac_type);
	}
	$(document).ready(function() {
		vac_comm();
	});
</script>
<?
	require_once(ROOT . 'templates/modal-wind.php');
	require_once(ROOT . 'templates/footer.php');
?>
	</body>
</html>