<?
$UserRating = performancePercent($Login);
?>
<div class="col-lg-12 col-md-12 col-sm-12">
	<h1><i class="fa fa-bookmark <?php if($Group == 'admin'){echo 'clr_high';}elseif($Group == 'manager'){echo 'clr_medium';}elseif($Group == 'user'){echo 'clr_vlow';}else{echo 'none';}?>" aria-hidden="true"></i> <?php echo $UserSurName . ' ' . $UserName; ?></h1>
	<div class="row">
		<div class="col-lg-3">
			<div class="row">
				<div class="col-lg-12 col-md-12 col-sm-12 col-xs-4">
					<?php 
					if(file_exists('./crmdata/upload/_user-photo/' . $UserPhoto) and $UserPhoto != ''){
						echo '<div class="big-photo" style="background:url(\'/'. $folder . '/crmdata/upload/_user-photo/' . $UserPhoto . '?'.rand(1,1000).'\') center center;"><img id="qrImage" src=""/></div>';
					} else {echo '<div class="big-photo empty satur50" style="background:' . get_color2($Uinitials) . ';">' . $Uinitials . '<img id="qrImage" src=""/></div>';}
					?>
					<script type="text/javascript">
						$(document).ready(function() {
							var startNode="BEGIN:VCARD"+"\n"+"VERSION:3.0"+"\n";
							var endNode="END:VCARD";
							startNode+="N:"+"<?php echo $UserSurName . ' ' . $UserName; ?>"+"\n";
							startNode+="EMAIL:"+"<?php echo $UserEmail; ?>"+"\n";
							startNode+="TEL:"+"<?php echo $UserPhoneW; ?>"+"\n";
							startNode+="TEL:"+"<?php echo $UserPhone; ?>"+"\n";
							startNode+=endNode;
							$("#qrImage").attr("src" , "https://chart.googleapis.com/chart?cht=qr&choe=UTF-8&chs=160x160&chl="+encodeURIComponent(startNode));
						});
					</script>
				</div>
				<div class="col-lg-12 col-md-12 col-sm-12 col-xs-8">
					<form method="POST" style="display:block;">
						<div class="input-group" style="width:100%;margin:0px 0px 10px 0px;">
							<span class="input-group-addon" style="width:50px;"><i class="fa fa-fw fa-qrcode" aria-hidden="true"></i></span>
							<div class="input-group-btn" style="width:calc(100% - 50px);"><a href="javascript: ;" style="width:100%;" onclick="$('#qrImage').toggle(0);" class="btn btn-default">QR <span class="hidden-xs">Визитная карточка</span><span class="hidden-lg hidden-md hidden-sm">Визитка</span></a></div>
						</div>
						<?php if ($LoginCheck != $Login) { ?>
						<div class="input-group" style="width:100%;margin:0px 0px 10px 0px;">
							<span class="input-group-addon" style="width:50px;"><i class="fa fa-fw fa-envelope" aria-hidden="true"></i></span>
							<div class="input-group-btn" style="width:calc(100% - 50px);"><a href="/<?php echo $folder; ?>/letters/?new&user=<?php echo $Login; ?>" style="width:100%;" class="btn btn-default"><span class="hidden-xs">Написать письмо</span><span class="hidden-lg hidden-md hidden-sm">Письмо</span></a></div>
						</div>
						<?php } ?>
						<div class="btn-group btn-group-justified" style="width:100%;margin:0px 0px 10px 0px;">
							<?php if ($GroupCheck == 'admin' or $GroupCheck == 'manager' and $Group != 'admin' or $LoginCheck == $Login) { ?>
							<a href="/<?php echo $folder; ?>/users/?edit=<?php echo $UserId; ?>" class="btn btn-default">Изменить</a>
							<?php } ?>
							<a href="javascript: ;" id="print" class="btn btn-default">На печать</a>
						</div>
					</form>
				</div>
			</div>
		</div>
		<div class="col-lg-9">
		
			<ul class="nav nav-tabs" id="admin-tabs">
				<li class="active"><a data-toggle="tab" href="#info">Информация</a></li>
				<? if ($Login == $LoginCheck or $GroupCheck == 'admin' or $GroupCheck == 'manager') { ?>
				<li><a data-toggle="tab" href="#tasks">Задачи (<?php echo count_task("user", $Login);?>)</a></li>
				<? } ?>
				<li><a data-toggle="tab" href="#vacations">Отпуск (<?php echo count_vacation("user", $Login);?>)</a></li>
				<li><a data-toggle="tab" href="#files">Файлы (<?php echo count_dir_files($_GET['view']); ?>)</a></li>
			</ul>
			
			<div class="tab-content" id="to_print">
				<div id="info" class="tab-pane fade in active">
					<img class="hide" src="/<?php echo $folder; ?>/crmdata/upload/_user-photo/<?php echo $UserPhoto; ?>" />
					<table class="table view_table_mobile" style="margin-bottom: 0px;">
						<tbody>
							<tr class="hide">
								<td>Имя пользователя:</td>
								<td><?php echo $UserSurName . ' ' . $UserName; ?></td>
							</tr>
							<tr>
								<td width="35%" style="border:none;"><i class="fa fa-fw fa-line-chart" aria-hidden="true"></i> Производительность:</td>
								<td style="border:none;">
									<div class="row">
										<div class="col-lg-8" style="height:auto;">
											<div class="progress_left">0%</div>
											<div id="progress"></div>
											<div class="progress_right">100%</div>
										</div>
									</div>
								</td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-user" aria-hidden="true"></i> Группа пользователя:</td>
								<td><?php if($Group == 'admin'){echo $nCRMgradmin;}elseif($Group == 'manager'){echo $nCRMgrmanager;}elseif($Group == 'user'){echo $nCRMgruser;}else{echo $nCRMgrguest;}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-graduation-cap" aria-hidden="true"></i> Должность:</td>
								<td><?php if($UserPosition != ''){echo $UserPosition;}else{echo 'Отсутствует';}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-phone" aria-hidden="true"></i> Основной телефон:</td>
								<td><?php if($UserPhoneW != ''){echo $UserPhoneW;}else{echo 'Нет данных';}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-phone" aria-hidden="true"></i> Доп. телефон:</td>
								<td><?php if($UserPhone != ''){echo $UserPhone;}else{echo 'Нет данных';}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-envelope-o" aria-hidden="true"></i> Контактный email:</td>
								<td><?php if($UserEmail != ''){echo $UserEmail;}else{echo 'Нет данных';}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-comment" aria-hidden="true"></i> Профиль соц.сети:</td>
								<td><?php if($UserSocial != ''){echo '<a href="' . $UserSocial . '" target="_blank">' . $UserSocial . '</a>';}else{echo 'Нет данных';}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-sign-in" aria-hidden="true"></i> Последнее посещение:</td>
								<td><?php if($LogsTime != ''){echo $LogsTime;}else{echo 'Нет данных';}?></td>
							</tr>
						</tbody>
					</table>
				</div>
				<div id="tasks" class="tab-pane fade">
					<div class="page_block" style="border:none;margin:0px 0px 20px 0px;">
						<div class="content" style="padding:0px;">
							<form method="POST">
								<div class="row">
									<div class="col-lg-5">
										<div class="input-group" style="width:100%;">
											<select style="width:30%;" class="form-control" name="selectType">
												<option value="task" selected>Задача</option>
												<option value="call">Звонок</option>
												<option value="mail">Письмо</option>
												<option value="visit">Встреча</option>
											</select>
											<input style="width:70%;" type="text" class="form-control" name="inputName" value="" placeholder="Название задачи" maxlength="150" required>
										</div>
									</div>
									<div class="col-lg-3">
										<div class="input-group">
											<span class="input-group-addon" style="padding:3px 12px!important;cursor:pointer;" title="Сделка"><i class="fa fa-fw fa-briefcase" aria-hidden="true"></i></span>
												<select class="form-control" name="selectDeal" id="selectDeal" <?php if ($GroupCheck == 'user') { echo 'disabled'; } ?> >
													<?
													$dom_d = new DOMDocument;
													$dom_d->load($baseD);
													$xpath_d = new DOMXPath($dom_d);
													$deals_a = $xpath_d->query('/deals/deal[@type="deal-a"]');
													$deals_c = $xpath_d->query('/deals/deal[@type="deal-c" and @id="'.$_GET['deal'].'"]');
													$deals_o = $xpath_d->query('/deals/deal[@type="offer" and @id="'.$_GET['deal'].'"]');
													?>
													<option value="">--- пусто ---</option>
													<optgroup label="Активные сделки">
													<?
													foreach ($deals_a as $deal) {
														$DealId 		= $deal->getAttribute('id');
														$DealNumber 	= $deal->getElementsByTagName("num")->item(0)->nodeValue;
														if(is_object($deal->getElementsByTagName("subject")->item(0))){
															$DealSubject 	= $deal->getElementsByTagName("subject")->item(0)->nodeValue;
														}
														$DealClient 	= $deal->getAttribute('client');
														$DealType 		= $deal->getAttribute('type');
														echo '<option value="'.$DealId.'">' . $nCRMdeals . ' '.$DealNumber.' - '.get_client_name($DealClient).' - "'.$DealSubject.'"</option>';
													}
													?>
													</optgroup> 
													<?php if($deals_c->length > 0){?>
													<optgroup label="Завершенные сделки">
													<?
													foreach ($deals_c as $deal) {
														$DealId 		= $deal->getAttribute('id');
														$DealNumber 	= $deal->getElementsByTagName("num")->item(0)->nodeValue;
														if(is_object($deal->getElementsByTagName("subject")->item(0))){
															$DealSubject 	= $deal->getElementsByTagName("subject")->item(0)->nodeValue;
														}
														$DealClient 	= $deal->getAttribute('client');
														$DealType 		= $deal->getAttribute('type');
														echo '<option value="'.$DealId.'">' . $nCRMoffers . ' '.$DealNumber.' - '.get_client_name($DealClient); if($DealSubject != ''){ echo ' - "'.$DealSubject.'"';} echo '</option>';
													}
													?>
													</optgroup>
													<?php } ?>
													<?php if($deals_o->length > 0){?>
													<optgroup label="Предложения">
													<?
													foreach ($deals_o as $deal) {
														$DealId 		= $deal->getAttribute('id');
														$DealNumber 	= $deal->getElementsByTagName("num")->item(0)->nodeValue;
														if(is_object($deal->getElementsByTagName("subject")->item(0))){
															$DealSubject 	= $deal->getElementsByTagName("subject")->item(0)->nodeValue;
														}
														$DealClient 	= $deal->getAttribute('client');
														$DealType 		= $deal->getAttribute('type');
														echo '<option value="'.$DealId.'">' . $nCRMoffers . ' '.$DealNumber.' - '.get_client_name($DealClient); if($DealSubject != ''){ echo ' - "'.$DealSubject.'"';} echo '</option>';
													}
													?>
													</optgroup>
													<?php } ?>
												</select>
										</div>
									</div>
									<div class="col-lg-3">
										<div class="input-group date-pick" style="position:relative;margin-bottom:15px;width:auto;">
											<span class="input-group-addon" style="padding:3px 12px!important;cursor:pointer;" title="Дата завершения"><i class="fa fa-fw fa-calendar-check-o" aria-hidden="true"></i></span>
											<input type="text" class="form-control dateE" name="inputDateEnd" placeholder="ГГГГ-ММ-ДД" value="" autocomplete="off" required />
										</div>
									</div>
									<div class="col-lg-1">
										<div class="btn-group btn-group-justified"  style="width:100%;margin-bottom:10px;">
											<button type="submit" name="TaskAdd" style="width:100%;" class="btn btn-primary" style="color:#fff;"><i class="fa fa-fw fa-plus"></i><span class="hidden-md hidden-lg"> Добавить задачу</span</button>
										</div>
									</div>
								</div>
							</form>
						</div>
					</div>
					<?php 
					$dom = new DOMDocument;
					$dom->load($baseT);
					$xpath = new DOMXPath($dom);
					$tasks = $xpath->query('/tasks/task[@deligated="'.$Login.'"]');
					?>
					<div class="table-responsive"> 
						<table id="informer-tasks" class="table table-hover all-tasks tasks-inwork" style="margin-bottom: 0px;">
							<thead> 
								<tr> 
									<th width="6%"></th> 
									<th width="52%">Наименование</th> 
									<th width="6%" title="Процент выполнения"><i class="fa fa-line-chart" aria-hidden="true"></i></th> 
									<th width="15%">Добавление</th>
									<th width="15%">Завершение</th>
									<th width="6%"></th>
								</tr> 
							</thead> 
							<tbody>
								<?php require_once(ROOT . 'modules/tasks/list-tasks-m-sm.php'); ?>
							</tbody>
						</table>
					</div>
					<?php if($tasks->length > 0){require_once(ROOT . 'templates/table-pager2.php');} ?>
				</div>
				<div id="vacations" class="tab-pane fade">
					<div class="page_block" style="border:none;margin-top:0px;">
						<div class="" style="padding:0px;">
							<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-6">
										<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">							<?
													echo '<option value="'.$Login.'">'.get_user_name_login($Login, '').'</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-exclamation-circle" 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>
					</div>
					<div class="vacations_list" style="padding-top:0px;">
						<?php require_once(ROOT . 'modules/users/list-vacations-m.php'); ?>
					</div>
				</div>
				<div id="files" class="tab-pane fade">
					<?php if(isset($_GET['view'])) { require_once(ROOT . 'functions/func-upload-file.php'); } ?>
				</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();
			// Ползунки
			$( "#progress" ).slider({
				animate: "slow",
				range: "min", 
				disabled: true,				
				step: 1,
				value: <?php echo $UserRating;?>,
				slide : function(event, ui) {    
					$(".ui-slider-handle").text(ui.value);
					$("input[name=NewPersent]").val(ui.value);				
				}
			});
			$('.ui-slider-handle').text($( "#progress" ).slider( "value"));    
		});
	</script>
</div>
