<?php if ( $aliases_arr[1] == 'timeline' ) {?>

	<div class="btn-group btn-group-justified" style="margin-bottom: 20px;">
		<a href="/<?php echo $folder; ?>/tasks/?new" class="btn btn-md btn-info add-task" style="color:#fff;">Добавить задачу</a>
		<a href="/<?php echo $folder; ?>/tasks-archive" class="btn btn-md btn-default">Архив задач</a>
	</div>  

<?php } ?>

<?php if ( $aliases_arr[1] == 'tasks' ) {?>
	<?php if ( isset($_GET['edit']) OR isset($_GET['new']) ) {?>
			<div class="panel panel-default" style="margin-top:15px;">
				<div class="panel-heading">
					<h3 class="panel-title"><i class="fa fa-fw fa-clipboard"></i> Шаблоны задач</h3>
				</div>
				<div class="panel-body">
					<?php if(count_templs($module) > 0){ ?>
					<div class="page_block2">
						<ul class="templs_list">
							<?php 
							$dom = new DOMDocument;
							$dom->load($baseTMPL);
							$xpath = new DOMXPath($dom);
							$templs = $xpath->query('/templs/templ[mod="'.$module.'"]');
							foreach ($templs as $templ) {
								$ID		= $templ->getAttribute('id');
								$Name 	= $templ->getElementsByTagName("name")->item(0)->nodeValue;
								$Mod 	= $templ->getElementsByTagName("mod")->item(0)->nodeValue;
								echo '<li id="templ_'.$ID.'">';
								if ($GroupCheck == 'admin' or $GroupCheck == 'manager') { echo '<i class="fa fa-times-circle clr_high" title="Удалить шаблон" onclick="del_templ('.$ID.');"></i>';}
								echo '<span onclick="get_templ('.$ID.');">'.$Name.'</span></li>';
							}
							?>
						</ul>
					</div>
					<?php } else { ?>
					<center>- нет шаблонов -</center>
					<?php } ?>
				</div>
			</div>
			<p style="line-height:15px;margin:5px 0 0;color:#999;text-align:justify;"><small>Для сохранения нового шаблона обязательно заполните: Название, Описание, включите "Сохранить как шаблон"<br/><br/>При сохранении шаблона задача не создается</small></p>
	<?php } else { ?>
	<div class="btn-group btn-group-justified" style="margin-bottom: 20px;">
		<a href="/<?php echo $folder; ?>/tasks/?new" class="btn btn-md btn-info add-task" style="color:#fff;">Добавить</a>
		<a href="/<?php echo $folder; ?>/tasks-archive" class="btn btn-md btn-default">Архив</a>
	</div>  
		
	<form method="POST" name="form_qtask" id="formedit" >
		<div class="input-group input-group-md" style="margin-bottom: 20px;">
			<input type="text" class="form-control" name="inputName" placeholder="Название задачи" value="" required>
			<div class="input-group-btn">
				<button class="btn btn-default" type="submit" name="QTaskAdd" title="Добавить быструю задачу"><i class="fa fa-plus" aria-hidden="true"></i></button>
			</div>
		</div>
	</form>
		
	<div class="filters">
		<form method="POST" id="filter-list">

			<div class="panel panel-default">
				<div class="panel-heading">
					<h3 class="panel-title"><i class="fa fa-fw fa-briefcase"></i> Фильтр по сделке</h3>
				</div>
				<div class="panel-body">
					<div class="input-group">
						<span class="input-group-addon">
							<input type="checkbox" name="checkDeal" id="checkDeal">
							<label for="checkDeal"><label>
						</span>
						<select id="select" class="form-control" name="selectDeal" id="selectDeal" disabled>
							<option value="0">-- сделка не указана --</option>
							<?php
							$dom = new DOMDocument;
							$dom->load($baseD);
							$xpath = new DOMXPath($dom);
							$deals = $xpath->query('/deals/deal');
							$countNoDeal = multi_count_task('', 'inwork', $radioUser, '', '', $radioPriority);
							foreach ($deals as $deal) {
								$DealId 		= $deal->getAttribute('id');
								$DealNumber 	= $deal->getElementsByTagName("num")->item(0)->nodeValue;
								$DealClient 	= $deal->getAttribute('client');
								$DealType 		= $deal->getAttribute('type');
								$countDeal 		= multi_count_task('', 'inwork', $radioUser, '', $DealId, $radioPriority);
								if($countDeal > 0) {
									echo '<option value="'.$DealId.'">'.get_deal_num($DealId). ' - ' .get_client_name($DealClient).' (' . $countDeal . ')</option>';
								}
							}
							if($countNoDeal > 0) {
								echo '<option value="">Сделка отсутствует (' . $countNoDeal . ')</option>';
							}
							?>
						</select>
					</div>
				</div>
			</div>

			<div class="panel panel-default">
				<div class="panel-heading">
					<h3 class="panel-title"><i class="fa fa-fw fa-user"></i> Фильтр по сотруднику</h3>
				</div>
				<div class="panel-body">
					<ul class="filter-list">
						<?php 
						$dom = new DOMDocument;
						$dom->load($baseU);
						$xpath = new DOMXPath($dom);
						$users = $xpath->query('/users/user');
						
						foreach ($users as $user) {
							$UserId 		= $user->getAttribute('id');
							$UserSurName 	= $user->getElementsByTagName("usersurname")->item(0)->nodeValue;
							$UserName 		= mb_substr($user->getElementsByTagName("username")->item(0)->nodeValue, 0, 1,'utf-8').'.';
							$UserLogin 		= $user->getAttribute('login');
							$countLogin 		= count($xmltask->xpath('/tasks/task[@status="inwork" and @deligated="'.$UserLogin.'"]'));
							if ($countLogin != '0') {
								echo '<li><input type="radio" name="radioUser" id="radioUser'.$UserLogin.'" value="'.$UserLogin.'"/><label for="radioUser'.$UserLogin.'">'.$UserName.' '.$UserSurName.'</label><b><span class="filter-list-num">'; echo $countLogin.'</span></b></li>';
							}
						}
						if($countNoLogin > 0){
							echo '<li><input type="radio" name="radioUser" id="radioUserNone" value=""/><label for="radioUserNone">Не делегировано</label><b><span class="filter-list-num">'; echo $countNoLogin.'</span></b></li>';
						}
						?>
					</ul>
				</div>
			</div>
			
			<div class="panel panel-default">
				<div class="panel-heading">
					<h3 class="panel-title"><i class="fa fa-fw fa-exclamation-triangle"></i> Фильтр по важности</h3>
				</div>
				<div class="panel-body">
					<ul class="filter-list">
						<li>
							<input type="radio" name="radioPriority" id="radioPriorityhigh" value="high"/>
							<label for="radioPriorityhigh"><i class="fa fa-fw fa-bookmark clr_high"></i> Высокая важность</label>
							<b><span class="filter-list-num">
								<?php echo multi_count_task('all', 'inwork', $selectUser, 'all', $selectDeal, 'high'); ?>
							</span></b>
						</li>
						<li>
							<input type="radio" name="radioPriority" id="radioPrioritymedium" value="medium"/>
							<label for="radioPrioritymedium"><i class="fa fa-fw fa-bookmark clr_medium"></i> Средняя важность</label>
							<b><span class="filter-list-num">
								<?php echo multi_count_task('all', 'inwork', $selectUser, 'all', $selectDeal, 'medium'); ?>
							</span></b>
						</li>
						<li>
							<input type="radio" name="radioPriority" id="radioPrioritylow" value="low"/>
							<label for="radioPrioritylow"><i class="fa fa-fw fa-bookmark clr_low"></i> Низкая важность</label>
							<b><span class="filter-list-num">
								<?php echo multi_count_task('all', 'inwork', $selectUser, 'all', $selectDeal, 'low'); ?>
							</span></b>
						</li>
						<li>
							<input type="radio" name="radioPriority" id="radioPrioritynone" value="none"/>
							<label for="radioPrioritynone"><i class="fa fa-fw fa-bookmark clr_none"></i> Важность отсутствует</label>
							<b><span class="filter-list-num">
								<?php echo multi_count_task('all', 'inwork', $selectUser, 'all', $selectDeal, 'none'); ?>
							</span></b>
						</li>
					</ul>
				</div>
			</div>
			
			<div class="btn-group btn-group-justified filter-buttons">
				<input type="submit" class="btn-filter btn btn-md btn-success" value="Фильтровать" name="TaskFilter" />
				<input type="submit" class="btn-freset btn btn-md btn-default" value="Сбросить" />
			</div>
			
		</form>
	</div>
	<?php } ?>
<?php } ?>

<?php if ( $aliases_arr[1] == 'tasks-archive' ) {?>

	<a href="javascript:;" onclick="$('.filters').attr('class','filters');$(this).hide();" class="btn btn-md btn-block btn-default hidden-lg hidden-md" style="margin-bottom:20px;"><i class="fa fa-fw fa-angle-double-down"></i> Отрыть меню фильтрации <i class="fa fa-fw fa-angle-double-down"></i></a>

	<div class="filters hidden-sm hidden-xs">
		<form method="POST" id="filter-list">
		
			<div class="panel panel-default">
				<div class="panel-heading">
					<h3 class="panel-title"><i class="fa fa-fw fa-briefcase"></i> Фильтр по сделке</h3>
				</div>
				<div class="panel-body">
					<div class="input-group">
						<span class="input-group-addon">
							<input type="checkbox" name="checkDeal" id="checkDeal">
							<label for="checkDeal"><label>
						</span>
						<select id="select" class="form-control" name="selectDeal" id="selectDeal" disabled>
							<option value="0">-- сделка не указана --</option>
							<?
							$dom = new DOMDocument;
							$dom->load($baseD);
							$xpath = new DOMXPath($dom);
							$deals = $xpath->query('/deals/deal');
							if(isset($_POST["radioUser"])){
								$countNoDeal = multi_count_task('', 'done', $_POST["radioUser"], '', '', $radioPriority);
							} else {
								$countNoDeal = multi_count_task('', 'done', '', '', '', $radioPriority);
							}
							foreach ($deals as $deal) {
								$DealId 		= $deal->getAttribute('id');
								$DealNumber 	= $deal->getElementsByTagName("num")->item(0)->nodeValue;
								$DealClient 	= $deal->getAttribute('client');
								$DealType 		= $deal->getAttribute('type');
								$countDeal 			= multi_count_task('', 'done', $radioUser, '', $DealId, $radioPriority);
								if($countDeal > 0) {
									echo '<option value="'.$DealId.'">'.get_deal_num($DealId). ' - ' .get_client_name($DealClient).' (' . $countDeal . ')</option>';
								}
							}
							if($countNoDeal > 0) {
								echo '<option value="">Сделка отсутствует (' . $countNoDeal . ')</option>';
							}
							?>
						</select>
					</div>
				</div>
			</div>

			<div class="panel panel-default">
				<div class="panel-heading">
					<h3 class="panel-title"><i class="fa fa-fw fa-user"></i> Фильтр по сотруднику</h3>
				</div>
				<div class="panel-body">
					<ul class="filter-list">
						<?php 
						$dom = new DOMDocument;
						$dom->load($baseU);
						$xpath = new DOMXPath($dom);
						$users = $xpath->query('/users/user');

						foreach ($users as $user) {
							$UserId 		= $user->getAttribute('id');
							$UserSurName 	= $user->getElementsByTagName("usersurname")->item(0)->nodeValue;
							$UserName 		= mb_substr($user->getElementsByTagName("username")->item(0)->nodeValue, 0, 1,'utf-8').'.';
							$UserLogin 		= $user->getAttribute('login');
							$countLogin 		= count($xmltask->xpath('/tasks/task[@status="done" and @deligated="'.$UserLogin.'"]'));
							if ($countLogin != '0') {
								echo '<li><input type="radio" name="radioUser" id="radioUser'.$UserLogin.'" value="'.$UserLogin.'"/><label for="radioUser'.$UserLogin.'">'.$UserName.' '.$UserSurName.'</label><b><span class="filter-list-num">'; echo $countLogin.'</span></b></li>';
							}
						}
						if($countNoLogin > 0){
							echo '<li><input type="radio" name="radioUser" id="radioUserNone" value=""/><label for="radioUserNone">Не делегировано</label><b><span class="filter-list-num">'; echo $countNoLogin.'</span></b></li>';
						}
						?>
					</ul>
				</div>
			</div>
			
			<div class="panel panel-default">
				<div class="panel-heading">
					<h3 class="panel-title"><i class="fa fa-fw fa-exclamation-triangle"></i> Фильтр по важности</h3>
				</div>
				<div class="panel-body">
					<ul class="filter-list">
						<li>
							<input type="radio" name="radioPriority" id="radioPriorityhigh" value="high"/>
							<label for="radioPriorityhigh"><i class="fa fa-fw fa-bookmark clr_high"></i> Высокая важность</label>
							<b><span class="filter-list-num">
								<?php echo multi_count_task('', 'done', $radioUser, '', $selectDeal, 'high'); ?>
							</span></b>
						</li>
						<li>
							<input type="radio" name="radioPriority" id="radioPrioritymedium" value="medium"/>
							<label for="radioPrioritymedium"><i class="fa fa-fw fa-bookmark clr_medium"></i> Средняя важность</label>
							<b><span class="filter-list-num">
								<?php echo multi_count_task('', 'done', $radioUser, '', $selectDeal, 'medium'); ?>
							</span></b>
						</li>
						<li>
							<input type="radio" name="radioPriority" id="radioPrioritylow" value="low"/>
							<label for="radioPrioritylow"><i class="fa fa-fw fa-bookmark clr_low"></i> Низкая важность</label>
							<b><span class="filter-list-num">
								<?php echo multi_count_task('', 'done', $radioUser, '', $selectDeal, 'low'); ?>
							</span></b>
						</li>
						<li>
							<input type="radio" name="radioPriority" id="radioPrioritynone" value="none"/>
							<label for="radioPrioritynone"><i class="fa fa-fw fa-bookmark clr_none"></i> Важность отсутствует</label>
							<b><span class="filter-list-num">
								<?php echo multi_count_task('', 'done', $radioUser, '', $selectDeal, 'none'); ?>
							</span></b>
						</li>
					</ul>
				</div>
			</div>
			
			<div class="btn-group btn-group-justified filter-buttons">
				<input type="submit" class="btn-filter btn btn-md btn-success" value="Фильтровать" name="TaskFilter" />
				<input type="submit" class="btn-freset btn btn-md btn-default" value="Сбросить" />
			</div>
			
		</form>
	</div>
	
<?php } ?>