<?
foreach ($clients as $client) {
	$ClientId 		= $client->getAttribute('id');
	$ClientType 	= $client->getAttribute('type');
	$ClientPriority = $client->getAttribute('priority');
	$ClientPhoto	= $client->getElementsByTagName("clientphoto")->item(0)->nodeValue;
	$ClientName 	= $client->getElementsByTagName("clientname")->item(0)->nodeValue;
	$ClientAgent 	= $client->getElementsByTagName("clientagent")->item(0)->nodeValue;
	$ClientPhoneW 	= $client->getElementsByTagName("clientphonew")->item(0)->nodeValue;
	$ClientPhone 	= $client->getElementsByTagName("clientphone")->item(0)->nodeValue;
	$ClientSite 	= $client->getElementsByTagName("clientsite")->item(0)->nodeValue;
	$ClientEmail 	= $client->getElementsByTagName("clientemail")->item(0)->nodeValue;
	$ClientStart 	= $client->getElementsByTagName("clientstart")->item(0)->nodeValue;
	$ClientAdress 	= $client->getElementsByTagName("clientadress")->item(0)->nodeValue;
	$ClientFined 	= $client->getElementsByTagName("clientfined")->item(0)->nodeValue;
	if(is_object($client->getElementsByTagName("clientdeals")->item(0))){
		$ClientDeals 	= $client->getElementsByTagName("clientdeals")->item(0)->nodeValue;
	} else {
		$ClientDeals 	= 0;
	}
	if(is_object($client->getElementsByTagName("clientdebt")->item(0))){
		$ClientDebt 	= $client->getElementsByTagName("clientdebt")->item(0)->nodeValue;
	} else {
		$ClientDebt 	= 0;
	}
	$UIP 			= $client->getElementsByTagName("uip")->item(0)->nodeValue;
	$ClientIn 		= mb_substr($ClientName, 0, 1,'utf-8');
?>
<tr id="<?php echo $ClientId; ?>" type="<?php echo $ClientType; ?>" priority="<?php echo $ClientPriority; ?>">
	<td>
		<a href="/<?php echo $folder; ?>/clients/?view=<?php echo $ClientId; ?>">
			<?php 
			if($ClientPhoneW == '' OR $ClientEmail == ''){
				echo '<div class="user-photo empty" style="background:#d4db59;background-image:none!important;"><i class="fa fa-fw fa-exclamation-circle" aria-hidden="true" title="Не указаны контакты"></i></div>';
			}elseif(file_exists('./crmdata/upload/_client-photo/' . $ClientPhoto) and $ClientPhoto != ''){
				echo '<div class="user-photo satur50" style="background:url(\'./crmdata/upload/_client-photo/' . $ClientPhoto . '?'.rand(1,1000).'\') center center;"></div>';
			} else {echo '<div class="user-photo empty satur50" style="background:' . get_color2($ClientIn) .';">' . $ClientIn . '</div>';}
			?>
		</a>
	</td>
	<td>
		<a href="/<?php echo $folder; ?>/clients/?view=<?php echo $ClientId; ?>"><?php echo $ClientName;?></a>
		<?php if(glob('./crmdata/upload/'.$ClientId.'/*')){ echo '<i class="fa fa-fw fa-cloud-download" aria-hidden="true" title="Прикреплен файл"></i>';} ?>
		<small class="d-block">
			<i class="fa fa-fw fa-phone" aria-hidden="true"></i> <?php if ($ClientPhoneW != '') {echo '<span class="ClientPhoneW">' . $ClientPhoneW . '</span>';} elseif($ClientPhone != '') {echo ', <span class="ClientPhone">' . $ClientPhone . '</span>';} else {echo 'телефон не указан';} ?>
			<div class="clear"></div>
			<i class="fa fa-fw fa-envelope" aria-hidden="true"></i> <?php if ($ClientEmail != '') { echo '<span class="ClientEmail">' . $ClientEmail . '</span>'; } else { echo 'E-mail не указан'; } ?>
			<?php if ($UIP != '' and $GroupCheck == 'admin') { ?><div class="clear"></div><span class="clr_red" title="IP пользователя, изменившего материал"><i class="fa fa-fw fa-lock" aria-hidden="true"></i> <?php echo $UIP; ?></span><?php } ?>
		</small>
	</td>
	<td class="countPrice" style="text-align:right!important">
		<b title="Сумма сделок">
		<?php 
		if(isset($ClientDeals) AND $ClientDeals !='0'){
			echo conv_price( $ClientDeals , 'long' , '<i class="fa fa-sm fa-rub"></i>');
		} else {
			echo conv_price( count_deals_price_summ('', 'price', $ClientId, '', '') , 'long' , '<i class="fa fa-sm fa-rub"></i>');
		}
		?>
		</b>
	</td>
	<td class="countPrice" style="text-align:right!important">
		<b class="clr_vlow" title="Сумма долга">
		<?php 
		if(isset($ClientDeals) AND $ClientDeals !='0'){
			echo conv_price( $ClientDebt , 'long' , '<i class="fa fa-sm fa-rub"></i>');
		} else {
			echo conv_price( count_deals_debt_summ('', $ClientId, '', '') , 'long' , '<i class="fa fa-sm fa-rub"></i>');
		}
		?>
		</b>
	</td>
	<td>
		<div class="rem_days_body" >
			<div class="txt"><?php echo $ClientStart; ?></div>
		</div>
	</td>
	<td>
		<a href="/<?php echo $folder.'/clients/?edit='.$ClientId; ?>" class="btn btn-sm btn-link" title="Редактировать"><i class="fa fa-fw fa-pencil" aria-hidden="true"></i></a>
	</td>
	<td>
		<form method="POST">
			<button class="btn btn-sm btn-link" type="submit" name="clientDelete" onclick="return confirm('Удалить клиента # <?php echo $ClientName; ?>?')" title="Удалить"><i class="fa fa-fw fa-times" aria-hidden="true"></i></button>
			<input type="text" class="hidden" name="clientDelId" value="<?php echo $ClientId; ?>" />
		</form>
	</td>
</tr>
<?php } ?>