<div class="col-lg-12 col-md-12 col-sm-12">
	<form method="POST" name="form_client" 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="ClientAdd" 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="/<? echo $folder; ?>/clients/?view=<? echo $ClientId; ?>" 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="ClientEdit" 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-address-book" aria-hidden="true"></i></span>
					<input type="text" class="form-control" name="inputName" value="<? if(isset($ClientName)){echo $ClientName;} ?>" placeholder="Имя" maxlength="150" required />
					<?php if(isset($_GET['edit'])) {?>
					<span class="input-group-btn">
						<?php if(isset($ClientPhoto) AND $ClientPhoto != ''){ ?> 
							<button type="submit" name="DelPhoto" class="btn btn-md btn-danger" style="color:#fff;" title="Удалить фото"><i class="fa fa-times"></i> Удалить фото</button>
						<?php } else { ?>
						<span class="btn btn-default btn-file" title="Выбрать фото | JPG | PNG | GIF">
							<i class="fa fa-camera fa-fw"></i> Выбрать фото
							<input type="file" name="inputFile">
							<select class="hide" name="file_type">
								<option value="1">Эскиз</option>
								<option value="2" selected>Оригинал</option>
							</select>
							<input class="hide" type="text" name="file_rotate" value=""/>
						</span>
						<?php } ?>
					</span>
					<?php } ?>
				</div>
				<input type="text" class="hide" name="inputPhoto" value="<? if(isset($ClientPhoto)){echo $ClientPhoto;} ?>"/>
				<input type="text" class="hidden" name="inputId" value="<? if(isset($ClientId)){echo $ClientId;} ?>">
			</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>
					<input type="text" class="form-control" name="inputAgent" placeholder="Представитель" value="<? if(isset($ClientAgent)){echo $ClientAgent;} ?>"maxlength="150">
				</div>
			</div>
			<div class="form-group col-lg-3 col-xs-6">
				<div class="input-group">
					<span class="input-group-addon" title="Тип клиента"><i class="fa fa-fw fa-address-book-o" aria-hidden="true"></i></span>
					<select class="form-control" name="selectType" required>
						<option value="FL">Физ. лицо</option>
						<option value="UL">Юр. лицо</option>
					</select>
				</div>
			</div>
			<div class="form-group col-lg-3 col-xs-6">
				<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" required>
						<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">
					<?php
					$doc = new DOMDocument;
					$doc->load(ROOT . '/crmdata/database/clients.xml');
					$xpathc = new DOMXPath($doc);
					$clients = $xpathc->query('/clients/client');
					$sourses_arr = array();
					$i = 0;
					foreach ($clients as $client) {
						$SourceName = $client->getElementsByTagName("clientfined")->item(0)->nodeValue;
						$countSource = count($xmlclient->xpath('/clients/client[clientfined="'.$SourceName.'"]'));
						$sourses_arr[$SourceName] =  $countSource;
						$i++;
					}
					$sources = $sourses_arr;
					?>
					<span class="input-group-addon" title="Откуда узнали"><i class="fa fa-fw fa-bullhorn" aria-hidden="true"></i></span>
					<input class="form-control" type="text" placeholder="Источник информации" value="" name="selectFined" list="all-source" required />
				</div>
				<datalist id="all-source">
					<?php foreach ($sources as $key => $value) {echo '<option value="' . $key . '">'.$value.'</option>';} ?>
				</datalist>
			</div>
			<div class="form-group col-lg-3">
				<div class="input-group date-pick" style="position:relative;">
					<span class="input-group-addon" style="cursor:pointer;" 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="<? if(isset($ClientStart)){echo $ClientStart;} else {echo date("Y-m-d");} ?>" required autocomplete="off" />
				</div>
			</div>
			<div class="form-group col-lg-3">
				<div class="input-group">
					<span class="input-group-addon" title="Телефон 1"><i class="fa fa-fw fa-phone" aria-hidden="true"></i></span>
					<input type="text" class="form-control" name="inputPhoneW" placeholder="Телефон 1" value="<? if(isset($ClientPhoneW)){echo $ClientPhoneW;} ?>maxlength="150" required>
				</div>
			</div>
			<div class="form-group col-lg-3">
				<div class="input-group">
					<span class="input-group-addon" title="Телефон 2"><i class="fa fa-fw fa-phone" aria-hidden="true"></i></span>
					<input type="text" class="form-control" name="inputPhone" placeholder="Телефон 2" value="<? if(isset($ClientPhone)){echo $ClientPhone;} ?>maxlength="150">
				</div>
			</div>
			<div class="form-group col-lg-3">
				<div class="input-group">
					<span class="input-group-addon" title="Е-mail клиента"><i class="fa fa-fw fa-envelope-o" aria-hidden="true"></i></span>
					<input type="email" class="form-control" name="inputEmail" placeholder="E-mail" value="<? if(isset($ClientEmail)){echo $ClientEmail;} ?>" maxlength="150">
				</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-globe" aria-hidden="true"></i></span>
					<input type="text" class="form-control" name="inputSite" placeholder="Веб-сайт" value="<? if(isset($ClientSite)){echo $ClientSite;} ?>" maxlength="150">
				</div>
			</div>
			<div class="form-group col-lg-12">
				<div class="input-group">
					<span class="input-group-addon" title="Адрес"><i class="fa fa-fw fa-map-marker" aria-hidden="true"></i></span>
					<input type="text" class="form-control" name="inputAdress" placeholder="Адрес" value="<? if(isset($$ClientAdress)){echo $ClientAdress;} ?>"maxlength="300">
				</div>
			</div>
		</div>
	</form>
	<small style="color:#aaa;">Допустимые форматы файлов: jpeg, png, gif. Максимальная ширина / высота изображения: 450px</small>
</div>
<? if(isset($_GET['edit'])) {?>
	<script type="text/javascript">
		$(document).ready(function() {
			$('form[name=form_client] select[name=selectType]').val('<? echo $ClientType;?>');
			$('form[name=form_client] select[name=selectPriority]').val('<? echo $ClientPriority;?>');
			$('form[name=form_client] input[name=selectFined]').val('<? echo $ClientFined;?>');
		});
	</script>
<? } ?>
<? if(isset($_GET['new'])) {?>
	<script type="text/javascript">
		$(document).ready(function() {
			<? if(isset($_GET['company']) OR isset($_GET['name'])) {?>
			<? if(isset($_GET['company']) AND $_GET['company'] != '') {?>
			$('form[name=form_client] input[name=inputName]').val('<? echo $_GET["company"];?>');
			$('form[name=form_client] input[name=inputAgent]').val('<? echo $_GET["name"] . ' ' . $_GET["sname"];?>');
			<? } else { ?>
			$('form[name=form_client] input[name=inputName]').val('<? echo $_GET["name"] . ' ' . $_GET["sname"];?>');
			<? } ?>
			<? } ?>
			$('form[name=form_client] input[name=selectFined]').val('<? if(isset($_GET["source"])){echo $_GET["source"];}?>');
			$('form[name=form_client] input[name=inputDateStart]').val('<? if(isset($_GET["date"])){echo $_GET["date"];}?>');
			$('form[name=form_client] input[name=inputPhoneW]').val('<? if(isset($_GET["phone"])){echo $_GET["phone"];}?>');
			$('form[name=form_client] input[name=inputEmail]').val('<? if(isset($_GET["mail"])){echo $_GET["mail"];}?>');
			$('form[name=form_client] input[name=inputSite]').val('<? if(isset($_GET["web"])){echo $_GET["web"];}?>');
			$('form[name=form_client] input[name=inputAdress]').val('<? if(isset($_GET["addr"])){echo $_GET["addr"];}?>');
		});
	</script>
<? } ?>