<?
foreach ($users as $user) {
	$UserId 			= $user->getAttribute('id');
	$Login 				= $user->getAttribute('login');
	$UserPhoto			= $user->getElementsByTagName("userphoto")->item(0)->nodeValue;
	$Password 			= $user->getAttribute('password');
	$UserName			= $user->getElementsByTagName("username")->item(0)->nodeValue;
	$UserSurName		= $user->getElementsByTagName("usersurname")->item(0)->nodeValue;
	$UserSurNameSM		= mb_substr($user->getElementsByTagName("usersurname")->item(0)->nodeValue, 0, 1,'utf-8').'.';
	$Group 				= $user->getAttribute('group');
	$UserPosition		= $user->getElementsByTagName("userposition")->item(0)->nodeValue;
	$UserEmail			= $user->getElementsByTagName("useremail")->item(0)->nodeValue;
	$UserPhoneW 		= $user->getElementsByTagName("userphonew")->item(0)->nodeValue;
	$UserPhone 			= $user->getElementsByTagName("userphone")->item(0)->nodeValue;
	$UserSocial 		= $user->getElementsByTagName("usersocial")->item(0)->nodeValue;
	$UIP 				= $user->getElementsByTagName("uip")->item(0)->nodeValue;
	$Uinitials 			= mb_substr($UserSurName, 0, 1,'utf-8') . mb_substr($UserName, 0, 1,'utf-8');
	
	$UserRating 		= performancePercent($Login);

	$doc = new DOMDocument;
	$doc->load($baseL);
	$xpath = new DOMXPath($doc);
	$logs = $xpath->query('/logs/log[login="'.$Login.'"]');
	if($logs->length > 0){
		foreach ($logs as $log) {
			$LogsTime = $log->getElementsByTagName("sessiontime")->item(0)->nodeValue;
		}
	} else {
		$LogsTime = '-';
	}
?>
<tr id="<?php echo $UserId; ?>" login="<?php echo $Login; ?>" group="<?php echo $Group; ?>">
	<td>
		<a href="/<?php echo $folder; ?>/users/?view=<?php echo $UserId; ?>" class="info-user" title="<?php echo $Login;?>">
			<?php 
			if(file_exists('./crmdata/upload/_user-photo/' . $UserPhoto) and $UserPhoto != ''){
				echo '<div class="user-photo satur50" style="background:url(\'./crmdata/upload/_user-photo/' . $UserPhoto . '?'.rand(1,1000).'        \') center center;"></div>';
			} else {echo '<div class="user-photo empty satur50" style="background:' . get_color2($Uinitials) . ';">' . $Uinitials . '</div>';}
			?>
		</a>
	</td>
	<td>
		<a href="/<?php echo $folder; ?>/users/?view=<?php echo $UserId; ?>"><?php echo $UserSurName; ?> <?php echo $UserName; ?></a>
		<?php if(glob('./crmdata/upload/'.$UserId.'/*')){ 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 ($UserPhoneW != '') {echo '<span class="UserPhoneW">' . $UserPhoneW . '</span>';} elseif($UserPhone != '') {echo ', <span class="UserPhone">' . $UserPhone . '</span>';} else {echo 'телефон не указан';} ?>
			<div class="clear"></div>
			<i class="fa fa-fw fa-envelope" aria-hidden="true"></i> <?php if ($UserEmail != '') {echo '<span class="UserEmail">' . $UserEmail . '</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><?php if (file_exists($fileLT) AND $LoginCheck != $Login) { ?><a class="btn btn-sm btn-link" href="/<?php echo $folder; ?>/letters/?new&user=<?php echo $Login; ?>" title="Написать письмо"><i class="fa fa-fw fa-envelope-o" aria-hidden="true"></i></a><?php } ?></td>
	<td style="position:relative;">
		<div class="persent-bar" title="Производительность">
			<div class="persent-bar-body" style="height:<?php echo $UserRating;?>%;max-height:100%;"></div>
			<div class="persent-bar-text"><?php echo $UserRating;?>%</div>
		</div>
	</td>
	<td>
		<div class="rem_days_body" >
			<div class="txt"><?php if($LogsTime != '-'){echo '<span class="UserLastEnter">' . date("Y-m-d H:i",strtotime($LogsTime)) . '</span>';} else {echo '<span class="UserLastEnter">- нет -</span>';} ?></div>
		</div>
	</td>
	<td>
		<?php 
		if ($GroupCheck == 'admin' or $GroupCheck == 'manager' and $Group != 'admin') {
			echo '<a href="/' . $folder.'/users/?edit='.$UserId . '" class="btn btn-sm btn-link" title="Редактировать"><i class="fa fa-fw fa-pencil" aria-hidden="true"></i></a>';
		} elseif($LoginCheck == $Login and $GroupCheck == 'guest' or $LoginCheck == $Login and $GroupCheck == 'user') {
			echo '<a href="/' . $folder.'/users/?edit='.$UserId . '" class="btn btn-sm btn-link" title="Редактировать"><i class="fa fa-fw fa-pencil" aria-hidden="true"></i></a>';
		} else {
			echo '<a href="#" class="btn btn-sm btn-link btn-disabled"><i class="fa fa-fw fa-pencil" aria-hidden="true"></i></a>';
		}
		?>
	</td>
	<td>
		<?
		if ($LoginCheck != $Login and $GroupCheck != 'guest' and $GroupCheck != 'user') {
			if ($GroupCheck == 'admin' or $GroupCheck == 'manager' and $Group != 'admin') {
		?>
		<form method="POST">
			<button class="btn btn-sm btn-link" type="submit" name="userDelete" onclick="return confirm('Удалить сотрудника # <?php echo $UserName; ?>?')" title="Удалить"><i class="fa fa-fw fa-times" aria-hidden="true"></i></button>
			<input type="text" class="hidden" name="userDelId" value="<?php echo $UserId; ?>" />
		</form>
		<?php 
			} else {echo '<a href="#" class="btn btn-sm btn-link btn-disabled"><i class="fa fa-fw fa-times" aria-hidden="true"></i></a>';}
		} else {
			echo '<a href="#" class="btn btn-sm btn-link btn-disabled"><i class="fa fa-fw fa-times" aria-hidden="true"></i></a>';
		}
		?>
	</td>
</tr>
<?php } ?>