<div class="col-lg-12 col-md-12 col-sm-12">
	<form method="POST" name="form_event" id="formedit" enctype="multipart/form-data">
		<div class="row" style="margin-top:15px;">
			<div class="col-lg-9 col-xs-8">
				<h1><a href="javascript: ;" onclick="history.go(-2)"><i class="fa fa-fw fa-angle-double-left" aria-hidden="true" title="Вернуться к списку"></i></a> 
				<?php if(isset($_GET['new'])) {?>Добавление <span class="hidden-xs">события</span><?php } ?>
				<?php if(isset($_GET['edit'])) {?>Редактирование <span class="hidden-xs">события</span><?php } ?>
				</h1>
			</div>
			<div class="col-lg-3 col-xs-4">
				<div class="btn-group btn-fixed" style="float:right;">
					<?php if(isset($_GET['new'])) {?>
					<button type="submit" name="eventAdd" class="btn btn-md btn-info" style="color:#fff;"><span class="hidden-lg hidden-md hidden-sm"><i class="fa fa-fw fa-plus" aria-hidden="true"></i></span><span class="hidden-xs">Добавить</span></button>
					<?php } ?>
					<?php if(isset($_GET['edit'])) {?>
					<a href="/<?php echo $folder; ?>/events/?view=<?php echo $eventId; ?>" class="btn btn-md btn-default"><span class="hidden-lg hidden-md hidden-sm"><i class="fa fa-fw fa-eye" aria-hidden="true"></i></span><span class="hidden-xs">Просмотр</span></a>
					<button type="submit" name="eventEdit" class="btn btn-md btn-info" style="color:#fff;"><span class="hidden-lg hidden-md hidden-sm"><i class="fa fa-fw fa-save" aria-hidden="true"></i></span><span class="hidden-xs">Сохранить</span></button>
					<?php } ?>
				</div>
			</div>	
		</div>
	

		<div class="row" style="margin-top:15px;">
			<div class="form-group col-lg-6">
				<div class="input-group">
					<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" name="inputName" value="<?php if(isset($eventName)){echo $eventName;} ?>" placeholder="Название события" maxlength="150" required>
				</div>
				<input type="text" class="hidden" name="inputId" value="<?php if(isset($eventId)){echo $eventId;} ?>"/>
			</div>
			<div class="form-group col-lg-3">
				<div class="input-group date-pick" style="position:relative;">
					<span class="input-group-addon" title="Дата события"><i class="fa fa-fw fa-calendar" aria-hidden="true"></i></span>
					<input type="text" class="form-control dateE" name="inputDate" placeholder="ГГГГ-ММ-ДД" value="<?php if(isset($eventDate)){echo $eventDate;}?>" autocomplete="off" 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-history" aria-hidden="true"></i></span>
					<select class="form-control" name="selectRepeat">
						<option value="none">--- пусто ---</option>
						<option value="day">Каждый день</option>
						<option value="month">Каждый месяц</option>
						<option value="year">Каждый год</option>
					</select>
				</div>
			</div>
			<div class="form-group col-lg-12 editor-form" style="width: 100%!important;">
				<textarea class="form-control" name="inputComment" id="inputComment" rows="10" placeholder="Комментарий к задаче"><?php if(isset($eventComment)){echo $eventComment;}?></textarea>
			</div>
			<div class="form-group col-lg-3">
				<div class="input-group">
					<span class="input-group-addon" title="Важность события"><i class="fa fa-fw fa-exclamation-triangle" aria-hidden="true"></i></span>
					<select class="form-control" name="selectPriority">
						<option value="none">--- пусто ---</option>
						<option value="high">Высокая</option>
						<option value="medium">Средняя</option>
						<option value="low">Низкая</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">
						<option value="">--- пусто ---</option>
						<?
							$dom = new DOMDocument;
							$dom->load(ROOT . '/crmdata/database/users.xml');
							$xpath = new DOMXPath($dom);
							$users = $xpath->query('/users/user');
							if($GroupCheck == 'guest' or $GroupCheck == 'user'){
								$curentUserSurName		= $auth->getUserSurName();
								$curentUserName 		= mb_substr($auth->getUserName(), 0, 1,'utf-8').'.';
								echo '<option value="'.$LoginCheck.'">'.$curentUserName.' '.$curentUserSurName.'</option>';
							} else{
								foreach ($users as $user) {
									$UserSurName 	= $user->getElementsByTagName("usersurname")->item(0)->nodeValue;
									$UserName 		= mb_substr($user->getElementsByTagName("username")->item(0)->nodeValue, 0, 1,'utf-8').'.';
									$UserLogin 		= $user->getAttribute('login');
									echo '<option value="'.$UserLogin.'">'.$UserName.' '.$UserSurName.'</option>';
								}
							}
						?>
					</select>
				</div>
			</div>
			<div class="form-group col-lg-6">
				<div class="input-group">
					<span class="input-group-addon" title="Клиент"><i class="fa fa-fw fa-address-book" aria-hidden="true"></i></span>
					<select class="form-control" name="selectClient" id="selectClient" <?php if ($GroupCheck == 'user') { echo 'disabled'; } ?> >
						<option value="">--- пусто ---</option>
						<?
							if ($GroupCheck != 'user') {
								$dom = new DOMDocument;
								$dom->load(ROOT . '/crmdata/database/clients.xml');
								$xpath = new DOMXPath($dom);
								$clients = $xpath->query('/clients/client');
								foreach ($clients as $client) {
									$ClientName 	= $client->getElementsByTagName("clientname")->item(0)->nodeValue;
									$ClientID 		= $client->getAttribute('id');
									echo '<option value="'.$ClientID.'">'.$ClientName.'</option>';
								}
							}
						?>
					</select>
				</div>
			</div>
		</div>
	</form>
</div>

<script type="text/javascript">
	$(document).ready(function() {
		function sorted(id){
			for(var c=document.getElementById(id),b=c.options,a=0;a<b.length;)
			if(b[a+1]&&b[a].text>b[a+1].text){c.insertBefore(b[a+1],b[a]);a=a>=1?a-1:a+1}else a++;
			b[0].selected=true; 
		};
		sorted("selectClient");
		sorted("selectUser");
		<?php if(isset($_GET['edit'])) {?>
		$('form[name=form_event] select[name=selectClient]').val('<?php echo $eventClient;?>');
		$('form[name=form_event] select[name=selectPriority]').val('<?php echo $eventPriority;?>');
		$('form[name=form_event] select[name=selectRepeat]').val('<?php echo $eventRepeat;?>');
		$('form[name=form_event] select[name=selectUser]').val('<?php echo $eventUser;?>');
		$('form[name=form_event] input[name=inputDate]').val('<?php echo $eventDateYear;?>-<?php echo $eventDateMonth;?>-<?php echo $eventDateDay;?>');
		<?php } ?>
	});
</script>
