<style>
.PriorityBtn .btn {
	font-size:1.0em!important;
	width:20px!important;
	padding: 3px 0px;
	opacity: 0.7!important;
}
.PriorityBtn .btn:hover {
	opacity: 1.0!important;
}
</style>
<div class="col-lg-12 col-md-12 col-sm-12">
	<h1><i class="fa fa-bookmark <?php if($ClientPriority == 'high'){echo 'clr_high';}elseif($ClientPriority == 'medium'){echo 'clr_medium';}elseif($ClientPriority == 'low'){echo 'clr_low';}else{echo 'none';}?>" aria-hidden="true"></i> <?php echo $ClientName;?></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/_client-photo/' . $ClientPhoto) and $ClientPhoto != ''){
						echo '<div class="big-photo" style="background:url(\'/'. $folder . '/crmdata/upload/_client-photo/' . $ClientPhoto . '?'.rand(1,1000).'\') center center;"><img id="qrImage" src=""/></div>';
					} else {echo '<div class="big-photo empty satur50" style="background:' . get_color2($Сinitials) . ';">' . $Сinitials . '<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 if($ClientAgent != ''){echo $ClientAgent;} else {echo $ClientName;} ?>"+"\n";
							startNode+="EMAIL:"+"<?php echo $ClientEmail; ?>"+"\n";
							startNode+="ORG:"+"<?php if($ClientAgent != ''){echo $ClientName;} ?>"+"\n";
							startNode+="URL:"+"<?php echo $ClientSite; ?>"+"\n";
							startNode+="TEL:"+"<?php echo $ClientPhoneW; ?>"+"\n";
							startNode+="TEL:"+"<?php echo $ClientPhone; ?>"+"\n";
							startNode+="ADR:"+"<?php echo $ClientAdress; ?>"+"\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>
						<div class="btn-group btn-group-justified" style="width:100%;margin:0px 0px 10px 0px;">
							<?php if ($GroupCheck == 'admin' or $GroupCheck == 'manager') { ?>
							<a href="/<?php echo $folder; ?>/clients/?edit=<?php echo $ClientId; ?>" 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>
				<?php if (!strstr($nCRMdealaccess,$LoginCheck)) {} else { ?>
				<li><a data-toggle="tab" href="#deals">Сделки (<?php echo count_deal("client", $_GET["view"]);?>)</a></li>
				<?php } ?>
				<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/_client-photo/<?php echo $ClientPhoto; ?>" />
					<form method="POST">
					<table class="table view_table_mobile">
						<tbody>
							<tr class="hide">
								<td>Клиент:</td>
								<td><?php echo $ClientName; ?></td>
							</tr>
							<tr>
								<td width="35%" style="border:none;"><i class="fa fa-fw fa-user" aria-hidden="true"></i> Представитель:</td>
								<td style="border:none;"><?php if($ClientAgent != ''){echo $ClientAgent;}else{echo 'Отсутствует';}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-bookmark" aria-hidden="true"></i> Важность клиента:</td>
								<td><?php if($ClientPriority == 'high'){echo 'Высокая важность';}elseif($ClientPriority == 'medium'){echo 'Средняя важность';}elseif($ClientPriority == 'low'){echo 'Низкая важность';}else{echo 'Отсутствует';}?><?php if ($GroupCheck == 'admin' or $GroupCheck == 'manager') { ?> ( Изменить: <span class="PriorityBtn"><button class="btn btn-link" type="submit" name="ClientChangePrior" value="3" onclick="return confirm('Изменить на Высокую важность')" title="Изменить на Высокую важность"><i class="fa fa-bookmark clr_high" aria-hidden="true"></i></button><button class="btn btn-link" type="submit" name="ClientChangePrior" value="2" onclick="return confirm('Изменить на Среднюю важность')" title="Изменить на Среднюю важность"><i class="fa fa-bookmark clr_medium" aria-hidden="true"></i></button><button class="btn btn-link" type="submit" name="ClientChangePrior" value="1" onclick="return confirm('Изменить на Низкую важность')" title="Изменить на Низкую важность"><i class="fa fa-bookmark clr_low" aria-hidden="true"></i></button><button class="btn btn-link" type="submit" name="ClientChangePrior" value="0" onclick="return confirm('Изменить на Важность отсутствует')" title="Изменить на Важность отсутствует"><i class="fa fa-bookmark clr_none" aria-hidden="true"></i></button></span> )<?php } ?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-map-marker" aria-hidden="true"></i> Адрес:</td>
								<td><?php if($ClientAdress != ''){echo '<a target="_blank" href="https://yandex.ru/maps/2/saint-petersburg/?source=serp_navig&mode=search&text=' . $ClientAdress . '">' . $ClientAdress . '</a>';}else{echo '<i class="fa fa-exclamation-circle clr_medium" aria-hidden="true"></i> Нет данных';}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-phone" aria-hidden="true"></i> Рабочий телефон:</td>
								<td><?php if($ClientPhoneW != ''){echo $ClientPhoneW;}else{echo '<i class="fa fa-exclamation-circle clr_medium" aria-hidden="true"></i> Нет данных';}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-phone" aria-hidden="true"></i> Мобильный телефон:</td>
								<td><?php if($ClientPhone != ''){echo $ClientPhone;}else{echo '<i class="fa fa-exclamation-circle clr_medium" aria-hidden="true"></i> Нет данных';}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-envelope-o" aria-hidden="true"></i> Контактный email:</td>
								<td><?php if($ClientEmail != ''){echo $ClientEmail;}else{echo '<i class="fa fa-exclamation-circle clr_medium" aria-hidden="true"></i> Нет данных';}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-globe" aria-hidden="true"></i> Веб-сайт:</td>
								<td><?php if($ClientSite != ''){echo '<a href="' . $ClientSite . '" target="_blank">' . $ClientSite . '</a>';}else{echo '<i class="fa fa-exclamation-circle clr_medium" aria-hidden="true"></i> Нет данных';}?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-bullhorn" aria-hidden="true"></i> Откуда узнали:</td>
								<td><?php if($ClientFined != ''){echo $ClientFined;}else{echo '<i class="fa fa-exclamation-circle clr_medium" aria-hidden="true"></i> Нет данных';}?> / <?php if($ClientStart != ''){echo $ClientStart;}else{echo 'Нет данных';}?></td>
							</tr>
						</tbody>
					</table>
					</form>
					<?php if (!strstr($nCRMdealaccess,$LoginCheck)) {} else { ?>
					<table class="table view_table_mobile" style="margin-top:25px;margin-bottom: 0px;">
						<tbody>
							<tr>
								<td width="35%" style="border:none;"><i class="fa fa-fw fa-rub" aria-hidden="true"></i> Сумма сделок с клиентом:</td>
								<td style="border:none;"><?php echo conv_price( count_deals_price_summ('', 'price', $ClientId, '', '') , 'long' , '<i class="fa fa-sm fa-rub"></i>') ?> ( Долг по оплате: <b><?php echo conv_price( count_deals_debt_summ('', $ClientId, '', '') , 'long' , '<i class="fa fa-sm fa-rub"></i>');?></b> )</td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-rub" aria-hidden="true"></i> Сумма предложений клиенту:</td>
								<td><?php echo conv_price( count_deals_price('offer', 'price', $ClientId, '', '') , 'long' , '<i class="fa fa-sm fa-rub"></i>') ?></td>
							</tr>
							<tr>
								<td><i class="fa fa-fw fa-clock-o" aria-hidden="true"></i> Кол-во дней с последней сделки:</td>
								<td><?php echo days_last_deal($_GET['view']); ?> дн.</td>
							</tr>
						</tbody>
					</table>
					<?php } ?>
				</div>
				<?php if (!strstr($nCRMdealaccess,$LoginCheck)) {} else { ?>
				<div id="deals" class="tab-pane fade">
					<?php if (!strstr($nCRMdealaccess,$LoginCheck)) {} else { ?>
					<div class="page_block" style="border:none;margin:0px 0px 0px 0px;">
						<div class="content" style="padding:0px;">
							<form method="POST">
								<div class="row">
									<div class="form-group col-lg-4">
										<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="selectType" required>
												<option value="offer">Коммерческое предложение</option>
												<option value="deal-a">Активная сделка</option>
											</select>
										</div>
									</div>
									<div class="form-group col-lg-4">
										<div class="input-group template">
											<span class="input-group-addon" style="padding:3px 12px!important;cursor:pointer;" title="Метка"><i class="fa fa-fw fa-tag" aria-hidden="true"></i></span>
											<input list="all-dealstags" type="text" class="form-control" id="inputSubject" name="inputSubject" value="<?php if(isset($Subject)){echo $Subject;} ?>" placeholder="Метка сделки" maxlength="150" required>
											<datalist id="all-dealstags">
												<?php
												$dox = new DOMDocument;
												$dox->load($baseD);
												$xpathx = new DOMXPath($dox);
												$alltagsdeal = $xpathx->query('/deals/deal');
												$sourses_arr = array();
												$i = 0;
												foreach ($alltagsdeal as $deal) {
													if(is_object($deal->getElementsByTagName("subject")->item(0))){
														$listSourceName = $deal->getElementsByTagName("subject")->item(0)->nodeValue;
														$countSource = count($xmldeal->xpath('/deals/deal[subject="'.$listSourceName.'"]'));
														$sourses_arr[$listSourceName] =  $countSource;
														$i++;
													}
												}
												$sources = $sourses_arr;
												foreach ($sources as $key => $value){
													echo '<option value="' . $key . '"></option>';
												}
												//print_r($sourses_arr);
												?>
											</datalist>
										</div>
									</div>
									<div class="form-group 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-rub" aria-hidden="true"></i></span>
											<input type="text" class="form-control" name="inputPrice" placeholder="Сумма сделки" maxlength="150" value="<?php if(isset($Price)){echo $Price;} ?>" onkeyup="return checkdot(this);" onchange="return checkdot(this);" 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="DealAdd" 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 } ?>
					<?php 
					$dom = new DOMDocument;
					$dom->load($baseD);
					$xpath = new DOMXPath($dom);
					$deals = $xpath->query('/deals/deal[@client="'.$_GET["view"].'"]');
					 ?>
					<div class="table-responsive"> 
						<table id="informer-deals" class="table table-hover all-deals" style="margin-bottom: 0px;">
							<thead> 
								<tr> 
									<th width="6%"></th> 
									<th width="32%">Наименование</th>
									<th width="15%" style="text-align:right!important;">Сумма</th>
									<th width="6%" title="Рентабельность"><i class="fa fa-fw 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/deals/list-deals-m-sm.php'); ?>
							</tbody>
						</table>
					</div>
					<?php if($deals->length > 0){require_once(ROOT . 'templates/table-pager.php');} ?>
				</div>
				<?php } ?>
				<div id="files" class="tab-pane fade">
					<?php if(isset($_GET['view'])) { require_once(ROOT . 'functions/func-upload-file.php'); } ?>
				</div>
			</div>
		</div>
	</div>
</div>