<head>
	<?php include ("Header.php"); ?>						
	
</head>
<body>
	<div id="mitte">
		<h1>Clientverwaltung</h1>
		<table border=1 bgcolor=white cellspacing=0 cellpadding=5>
				<tr>
					<th>Rechnername
					<th>Orga
					<th>Straße
					<th>Postleitzahl
					<th>Stadt
					<th>Besitzer
					<th>Geräteübersicht
				</tr>
				<tr>
				<?php
				$dbconn = pg_connect("host=127.0.0.1 port=8028 dbname=desktopcentral user=medc password=dk2310");
						$query1 = "SELECT Full_name FROM managedComputer WHERE Full_name != 'DKserv' ORDER BY Full_name";
						$result1 = pg_query($query1);
						
						while ($line = pg_fetch_array($result1, null, PGSQL_ASSOC)) {
							echo "<tr>";
							foreach ($line as $col_value) {
								echo "<td>$col_value";
							}
							$con=mysqli_connect("localhost","root","dk2310","cmdb6");
							mysqli_set_charset($con,"utf8");
							$sql = "SELECT functionalci.name AS Rechnername, organization.name AS Orga, location.address AS Adresse, location.postal_code AS PLZ, location.city as Stadt, contact.name AS Nachname, person.first_name AS Vorname FROM contact, lnkcontacttofunctionalci, physicaldevice, organization, location, functionalci, person WHERE location.org_id = organization.id AND functionalci.name = '$col_value' AND functionalci.id = physicaldevice.id AND physicaldevice.location_id = location.id AND lnkcontacttofunctionalci.functionalci_id = functionalci.id AND lnkcontacttofunctionalci.contact_id = contact.id AND person.id = contact.id;";
							$result = $con-> query($sql);
							
							if ($result-> num_rows > 0){
								while ($row = $result-> fetch_assoc()) {
								echo "<td>".$row["Orga"];
								echo "<td>".$row["Adresse"];
								echo "<td>".$row["PLZ"];
								echo "<td>".$row["Stadt"];
								echo "<td>".$row["Vorname"]." ".$row["Nachname"];
								$Rechnername = $row["Rechnername"];
								echo "<td><a href='http://klotzbach-it.de/reporting/client.php?client=$Rechnername'><button class='login'>Zum Client</button></a></td>";
								}
							}
							echo "<tr>";
						}
					?>
		</table>
		<br>
		
			
	</div>
</body>
	<?php include ("footer.php"); ?>