<?php 
	require_once('./functions/crm_settings.php');
	$pageTitle 	= 'Поиск по задачам';
	require_once(ROOT . 'templates/header.php'); 
	if( isset( $_GET['status'] ) ) {
		if( $_GET['status'] == 'inwork' ) {$getStatus 	= 'В работе ';} else {$getStatus 	= 'Выполнено ';}
	}
	if( isset( $_GET['deal'] ) and $_GET['deal'] !='' ) {
		$dom = new DOMDocument;
		$dom->load($baseD);
		$xpath = new DOMXPath($dom);
		$deals = $xpath->query('/deals/deal');
		foreach ($deals as $deal) {
			$getDealNumber 	= $xpath->query('/deals/deal[@id="'. $_GET['deal'] .'"]')->item(0)->getElementsByTagName("dealnumber")->item(0)->nodeValue;
			$getDealClient	= $xpath->query('/deals/deal[@id="'. $_GET['deal'] .'"]')->item(0)->getAttribute("client");
			$doс = new DOMDocument;
			$doс->load($baseC);
			$xpathc = new DOMXPath($doс);
			$clients = $xpathc->query('/clients/client[@id="'. $getDealClient .'"]');
			foreach ($clients as $client) {
				$ClientName 	= $client->getElementsByTagName("clientname")->item(0)->nodeValue;
			}
		}
		$getDeal 	= 'Сделка ' . $getDealNumber . ' - ' . $ClientName;
	}
	if( isset( $_GET['user'] ) and $_GET['user'] !='' ) {
		$dom = new DOMDocument;
		$dom->load($baseU);
		$xpath = new DOMXPath($dom);
		$users = $xpath->query('/users/user');
		foreach ($users as $user) {
			$getUserName = $xpath->query('/users/user[@login="'. $_GET['user'] .'"]')->item(0)->getElementsByTagName("username")->item(0)->nodeValue;
			$getUserSurName = $xpath->query('/users/user[@login="'. $_GET['user'] .'"]')->item(0)->getElementsByTagName("usersurname")->item(0)->nodeValue;
		}
		$getUser 	= $getUserSurName . ' ' . $getUserName . '';
	}
	$pageTitleBack 	= 'Поиск <i class="fa fa-fw fa-angle-right" aria-hidden="true"></i> ' . $getStatus . $getUser . $getDeal;
	require_once(ROOT . 'templates/main-menu.php');
	require_once(ROOT . 'modules/tasks/list-tasks.php'); 
?>
<div class="container<?php global $designView; echo $designView; ?>">
	<div class="row">
		<div class="col-lg-12">
			<h1><a href="javascript: ;" onclick="history.go(-1)"><i class="fa fa-fw fa-angle-double-left" aria-hidden="true" title="Вернуться к списку"></i></a> <?php echo $pageTitleBack; ?> <span class="list-num"><i class="fa fa-fw fa-angle-double-down" aria-hidden="true"></i> <?php echo $countTaskStatusInWork; ?></span></h1>
			<div class="table-responsive">
				<table id="all-tasks-search" class="table table-hover all-tasks tasks-inwork">
					<thead> 
						<tr> 
							<th width="6%"></th> 
							<th>Наименование</th> 
							<th width="6%" title="Процент выполнения"><i class="fa fa-line-chart" aria-hidden="true"></i></th> 
							<th width="15%" data-sorter="shortDate" data-date-format="yyyymmdd">Добавление</th>
							<th width="15%" data-sorter="shortDate" data-date-format="yyyymmdd">Завершение</th>
							<th width="6%"></th>
							<th width="6%"></th>
						</tr> 
					</thead> 
					<tbody>
						<?php require_once(ROOT . 'modules/tasks/list-tasks-m.php'); ?>
					</tbody>
				</table>
			</div>
			<?php require_once(ROOT . 'templates/table-pager.php'); ?>
		</div>
	</div>
</div>
<?
	require_once(ROOT . 'templates/modal-wind.php');
	require_once(ROOT . 'templates/footer.php'); 
?>
	</body>
</html>