<div class="btn-group btn-group-justified" style="margin-bottom: 20px;">
	<?php if(file_exists($baseT) and file_exists($fileT)){ ?>
	<a href="/<?php echo $folder; ?>/tasks/?new" class="btn btn-md btn-info add-task" style="color:#fff;">Задача</a>
	<?php } ?>
	<?php if(file_exists($baseLT) and file_exists($fileLT)){ ?>
	<a href="/<?php echo $folder; ?>/letters/?new" class="btn btn-md btn-default add-letter">Письмо</a>
	<?php } ?>
</div>

<?php if(file_exists($baseLT) and file_exists($fileLT)){ ?>
<div class="panel panel-default">
	<div class="panel-body">
		<ul class="filter-list">
			<li><a href="/<?php echo $folder; ?>/letters"><i class="fa fa-fw fa-envelope-open"></i> Все письма<b></a><span class="filter-list-num"><?php echo count_letters('all');?></span></b></li>
			<li><a href="/<?php echo $folder; ?>/letters/?folder=inbox"><i class="fa fa-fw fa-envelope-open-o"></i> Входящие<b></a><span class="filter-list-num"><?php echo count_letters('inbox');?></span></b></li>
			<li><a href="/<?php echo $folder; ?>/letters/?folder=notread"><i class="fa fa-fw fa-envelope-o"></i> Непрочитанные<b></a><span class="filter-list-num"><?php echo count_letters('notread');?></span></b></li>
			<li><a href="/<?php echo $folder; ?>/letters/?folder=outbox"><i class="fa fa-fw fa-envelope"></i> Отправленные<b></a><span class="filter-list-num"><?php echo count_letters('outbox');?></span></b></li>
			<hr/>
			<li><a href="/<?php echo $folder; ?>/letters/?folder=important"><i class="fa fa-fw fa-exclamation-triangle"></i> Важные<b></a><span class="filter-list-num"><?php echo count_letters('important');?></span></b></li>
		</ul>
	</div>
</div>
<?php } ?>

<?php if(file_exists($fileN)){ ?>
<a href="/<?php echo $folder; ?>/notes/?new-note" class="btn btn-md btn-default btn-block add-note" style="margin-bottom: 20px;">Добавить заметку</a>
<?php } ?>


	
	
	<?php if (file_exists($baseD) AND file_exists($fileD) OR file_exists($baseT) AND file_exists($fileT) OR file_exists($baseU) AND file_exists($fileU) OR file_exists($baseD) AND file_exists($fileD) OR file_exists($baseC) AND file_exists($fileC)) { ?>
		<?php if ($GroupCheck != 'guest') { ?>
		
		
			<?php if (file_exists($baseE) AND file_exists($fileE)) { ?>
			<div class="panel panel-info">
				<div class="panel-heading">
					<h3 class="panel-title"><i class="fa fa-fw fa-calendar"></i> Ближайшие события</h3>
				</div>
				<div class="panel-body" style="padding:5px 15px;">
					<ul class="filter-list events">
					<?
					$date_today = date("Y-m-d");
					$date_day = date('Y-m-d',strtotime($date_today . "+7 days"));
					$dom = new DOMDocument;
					$dom->load($baseE);
					$xpath = new DOMXPath($dom);
					$events = $xpath->query('/events/event');
					foreach ($events as $event) {
						$eventId 		= $event->getAttribute('id');
						$eventPriority 	= $event->getAttribute('priority');
						$eventName		= $event->getElementsByTagName("name")->item(0)->nodeValue;
						$eventDateYear	= $event->getElementsByTagName("dateyear")->item(0)->nodeValue;
						$eventDateMonth	= $event->getElementsByTagName("datemonth")->item(0)->nodeValue;
						$eventDateDay	= $event->getElementsByTagName("dateday")->item(0)->nodeValue;
						if($eventDateYear 	!= ''){ $eventDateYear 	= $eventDateYear; 	} else { $eventDateYear 	= date("Y"); }
						if($eventDateMonth 	!= ''){ $eventDateMonth = $eventDateMonth; 	} else { $eventDateMonth 	= date("m"); $eventDateYear 	= date("Y"); }
						if($eventDateDay 	!= ''){ $eventDateDay 	= $eventDateDay;	} else { $eventDateDay 		= date("d"); $eventDateMonth 	= date("m"); $eventDateYear 	= date("Y"); }
						$eventDate		= $eventDateYear . '-' . $eventDateMonth . '-' . $eventDateDay;
						if ($eventDate >= $date_today AND $eventDate < $date_day){
							echo '<li style="margin:10px 0px;" title="'.$eventName.'"><a href="/' . $folder . '/events/?view=' . $eventId . '"><div><i class="fa fa fa-bookmark clr_'. $eventPriority .'"></i> '.$eventDate.'<b><span class="filter-list-num">'; if(floatval(timediff($date_today, $eventDate)) == '0'){echo '<span class="clr_high">Сегодня</span>';} elseif(floatval(timediff($date_today, $eventDate)) == '1'){echo '<span class="clr_high">Завтра</span>';} else {echo floatval(timediff($date_today, $eventDate)) . ' дн.';} echo'</span></b></div>'; if(strlen($eventName) > '40'){echo mb_substr($eventName, 0, 28,'utf-8').'...';} else {echo $eventName;} echo'</a></li>';
						}
					}
					?>
					</ul>
				</div>
			</div>
			<?php } ?>
			
		<div class="filters">
			<?php if(file_exists($baseT) and file_exists($fileT)){ ?>
			<div class="panel panel-default">
				<div class="panel-heading">
					<h3 class="panel-title"><i class="fa fa-fw fa-clock-o"></i> Время выполнения задачи</h3>
				</div>
				<div class="panel-body centered">
				<?php if(timeinwork($LoginCheck) > 0 ){ ?>
					<div class="chart-container" style="z-index:1;position: relative; height:10vh; width:100%;">
						<canvas id="TaskTime"></canvas>
					</div>	
					<script>
						var ctxtasktime = document.getElementById("TaskTime").getContext('2d');
						var TaskTime = new Chart(ctxtasktime, {
							type: 'horizontalBar',
							data: {
								datasets: [{
									data: ["<?php echo round(timeinwork($LoginCheck) / multi_count_task('all', 'done', $LoginCheck, 'all', 'all', 'all'),0);?>", "<?php echo round(timeinwork('all')/multi_count_task('all', 'done', 'all', 'all', 'all', 'all'),0);?>", 0],
									backgroundColor:[
												"rgba(122,178,98, 0.25)",
												"rgba(64, 73, 91, 0.25)"
												],
									borderColor:[
												"rgba(122,178,98, 1.0)",
												"rgba(64, 73, 91, 1.0)"
												],
									borderWidth: 2
								}],
								labels: ["Личное время, дн.", "Общее время, дн."]
							},
							options: {
								responsive: true,
								maintainAspectRatio: false,
								legend: {
									display: false
								},
								title: {
									display: false
								},
								animation: {
									animateScale: true,
									animateRotate: true
								}
							}
						});
					</script>
				<? } else { echo 'Нет данных';} ?>
				<hr/>
				<?php 
				if(timeinwork('all') > 0){
					echo 'Производительность: ' . performancePercent($LoginCheck) . '%';
				} else {
					echo 'Производительность: 0%';
				}
				?>
				</div>
			</div>
			<?php } ?>
		</div>
		<?php } else { ?>
		<div class="panel panel-default">
			<div class="panel-body" style="text-align:justify;">
				<h4 class="centered">Уважаемый пользователь</h4>
				<small>В связи с тем что Вы были определены в группу "<?php echo $nCRMgrguest; ?>" интерфейс CRM системы работает в режиме ограниченного функционала.</small><br/><br/>
				<small>Вы можете просматривать и завершать задачи, делегированные Вам, а также добавлять себе новые задачи самостоятельно.</small>
			</div>
		</div>
		<?php } ?>
		
	<?php } ?>
