<?
if( isset( $_POST['search'] ) ) {
	$dom = new DOMDocument;
	$dom->load($baseU);
	$xpath = new DOMXPath($dom);
	$query	= mb_strtolower(rawurldecode($_POST['query']), 'UTF-8');
	$users	= $xpath->query('/users/user[contains(translate(., "ABCDEFGHJIKLMNOPQRSTUVWXYZАБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧШЩЭЮЯ", "abcdefghjiklmnopqrstuvwxyzабвгдеёжзиклмнопрстуфхцчшщэюя"),"'.$query.'")]');
	$countUser 	= count($xmluser->xpath('/users/user[contains(translate(., "ABCDEFGHJIKLMNOPQRSTUVWXYZАБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧШЩЭЮЯ", "abcdefghjiklmnopqrstuvwxyzабвгдеёжзиклмнопрстуфхцчшщэюя"),"'.$query.'")]'));
} elseif( isset( $_POST['UserFilter'] ) ) {
	/* Список - после фильтрации */
	if( isset( $_POST["radioGroup"] ) ) {
		$filterGroup = '@group="'.$_POST["radioGroup"].'"';
		echo '<script>$(function() {$("form#filter-list input[value*=\''.$_POST["radioGroup"].'\']").prop("checked", true);$(".filter-buttons").fadeIn("500");});</script>';
	} else {
		$filterGroup = '';
	}
	
	$dom = new DOMDocument;
	$dom->load($baseU);
	$xpath = new DOMXPath($dom);
	$users = $xpath->query('/users/user['.$filterGroup.']');
	$countUser 	= count($xmluser->xpath('/users/user['.$filterGroup.']'));
} else {
	/* Список - стандартный вид */
	$dom = new DOMDocument;
	$dom->load($baseU);
	$xpath = new DOMXPath($dom);
	$users = $xpath->query('/users/user');
	$countUser 	= count($xmluser->xpath('/users/user'));
}
if (file_exists($baseT) and file_exists($fileT)) {
	$xmltask = simplexml_load_file($baseT);
}
if( isset($_GET['edit']) and $_GET['edit'] != '' or isset($_GET['view']) and $_GET['view'] != '' ) {
	$dom = new DOMDocument;
	$dom->load($baseU);
	$xpath = new DOMXPath($dom);
	if(isset($_GET['edit']) AND $_GET['edit'] != '') {
		$users = $xpath->query('/users/user[@id="'.$_GET['edit'].'"]');
	}
	if(isset($_GET['view']) AND $_GET['view'] != '') {
		$users = $xpath->query('/users/user[@id="'.$_GET['view'].'"]');
	}
	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');
	}
	if( isset($_GET['view']) and $_GET['view'] != '' ) {
		$doc = new DOMDocument;
		$doc->load($baseL);
		$xpath = new DOMXPath($doc);
		$logs = $xpath->query('/logs/log[login="'.$Login.'"]');
		foreach ($logs as $log) {
				$LogsTime = $log->getElementsByTagName("sessiontime")->item(0)->nodeValue;
		}
		if (file_exists($baseT) and file_exists($fileT)) {
			$countUser1 			= count($xmltask->xpath('/tasks/task[@status="inwork" and @deligated="'.$Login.'"]'));
			$countUser2 			= count($xmltask->xpath('/tasks/task[@status="done" and @deligated="'.$Login.'"]'));
		}
	}
}
?>