<?
foreach($offers as $offer) {
	$DealId 	= $offer->getAttribute('id');
	$Type 		= $offer->getAttribute('type');
	$Client 	= $offer->getAttribute('client');
	if(is_object($offer->getElementsByTagName("subject")->item(0))){
		$Subject 	= $offer->getElementsByTagName("subject")->item(0)->nodeValue;
	}
	$DealNumber = $offer->getElementsByTagName("num")->item(0)->nodeValue;
	$Price 		= floatval($offer->getElementsByTagName("price")->item(0)->nodeValue);
	if(is_object($offer->getElementsByTagName("subject")->item(0))){
		$Comment 	= $offer->getElementsByTagName("comment")->item(0)->nodeValue;
	}
	if(is_object($offer->getElementsByTagName("subject")->item(0))){
		$CommentSm 	= mb_substr(strip_tags($Comment), 0, 30, 'UTF-8') . '...';
	}
	$DateStart 	= $offer->getElementsByTagName("dates")->item(0)->nodeValue;
	$DateEnd 	= $offer->getElementsByTagName("datee")->item(0)->nodeValue;
	$UIP 		= $offer->getElementsByTagName("uip")->item(0)->nodeValue;
?>
<tr class="<?php if ($Price >= '500001') {echo 'vhigh';} elseif ($Price < '500000' and $Price >= '250000') {echo 'high';} elseif ($Price < '250000' and $Price >= '100000') {echo 'medium';} elseif ($Price < '100000' and $Price >= '25000') {echo 'low';} elseif ($Price < '25000' and $Price >= '5000') {echo 'vlow';} else {echo 'none';} ?>" id="<?php echo $DealId; ?>" type="<?php echo $Type; ?>">
	<td>
		<?
		if ($Type == 'deal-c') {
			echo '<button class="btn btn-sm btn-link info-deal"><i class="fa fa-fw fa-briefcase" aria-hidden="true" title="Информация о сделке"></i></button>';
		} elseif ($Type == 'deal-a') {
		?>
		<form method="POST">
			<button class="btn btn-sm btn-link" type="submit" name="DealDone" onclick="return confirm('Завершить сделку <?php echo $DealNumber; ?>')" title="Завершить сделку"><i class="fa fa-fw fa-handshake-o" aria-hidden="true"></i></button>
			<input type="text" class="hidden" name="DealDoneId" value="<?php echo $DealId; ?>" />
		</form>
		<?
		} else {
		?>
		<form method="POST">
			<button class="btn btn-sm btn-link" type="submit" name="DealActive" onclick="return confirm('Добавить сделку <?php echo $DealNumber; ?>')" title="Перевести в сделку"><i class="fa fa-fw fa-file-text-o" aria-hidden="true"></i></button>
			<input type="text" class="hidden" name="DealActiveId" value="<?php echo $DealId; ?>" />
		</form>
		<?php } ?>
	</td>
	<td>
		<a href="<?php echo '/' . $folder.'/deals/?view='.$DealId; ?>"><?php if ($Type == 'deal-a' or $Type == 'deal-c') {echo $nCRMdeals . ' <span class="DealNumber">' . $DealNumber . '</span>';} else {echo $nCRMoffers . ' <span class="DealNumber">' . $DealNumber . '</span>';} ?></a>
		<?php if(glob('./upload/'.$DealId.'/*')){ echo '<i class="fa fa-fw fa-cloud-download" aria-hidden="true" title="Прикреплен файл"></i>';} ?>
		<small class="d-block">
			<i class="fa fa-fw fa-address-book" aria-hidden="true"></i> <?php if ($clients->length > 0) {echo '<a href="/' . $folder . '/clients/?view='.$Client.'" class="DealClient">' . get_client_name($Client) . '</a>';} else {echo 'Нет клиента';} ?>
			<div class="clear"></div>
			<i class="fa fa-fw fa-info-circle DealComment" aria-hidden="true"></i> <?php if ($Subject != ''){echo $Subject;}elseif($Comment != '') {echo $CommentSm;} else {echo 'Нет комментария';} ?>
			<?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 style="text-align:right!important;">
		<b class="DealPrice"><?php echo conv_price( $Price , 'long' , '<i class="fa fa-sm fa-rub" aria-hidden="true" style="font-size:0.9em;"></i>'); ?></b>
	</td>
	<td>
		<div class="rem_days_body" >
			<div class="txt"><?php echo $DateStart; ?></div>
		</div>
	</td>
	<td>
		<a href="<?php echo '/' . $folder.'/deals/?edit='.$DealId; ?>" class="btn btn-sm btn-link edit-deal" 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="DealDelete" onclick="return confirm('Удалить КП <?php echo $DealNumber; ?>?')" title="Удалить"><i class="fa fa-fw fa-times" aria-hidden="true"></i></button>
			<input type="text" class="hidden" name="DealDelId" value="<?php echo $DealId; ?>" />
		</form>
	</td>
</tr>
<?php } ?>