<?php
if(isset($_GET['delete'])){
	$database->setBareQuery("SELECT id FROM project WHERE parent = '".$_GET['delete']."'");
	
	$delete_ids = $database->loadResultArray(0);
	
	for($i = 0; $i < count($delete_ids); $i++):
	
		$database->query("DELETE FROM task WHERE project = '".$delete_ids[$i]."'");
	
	
	endfor;
	
	$database->query("DELETE FROM project WHERE parent = '".$_GET['delete']."'");
	
	$database->query("DELETE FROM client WHERE id='".$_GET['delete']."' LIMIT 1");
	
}

$database->setBareQuery("SELECT id, name FROM client ORDER BY name");

				$clientid = $database->loadResultArray(0);
		
				$clientname = $database->loadResultArray(1);
				
				?>

<h1>Klijenti</h1>
<div id="uvbody-content">
	<table id="table" cellspacing="0">
		<thead>
			<tr>
				<th scope="col" class="manage-title">Ime</th>
				<th scope="col" class="manage-action">Akcija</th>
			</tr>
		</thead>
		<tbody>
		<?php 
		for($i = 0; $i < count($clientid); $i++):
    		?>
    			<tr id="page-<?=$client?>">
    				<td><a href="admin.php?page=tools&action=client-edit&id=<?=$clientid[$i]?>"><?=$clientname[$i]?></a></td>
    				<td><a href="admin.php?page=tools&action=client-edit&id=<?=$clientid[$i]?>" class="edit">Edit</a> | <a href="admin.php?page=tools&action=client&delete=<?=$clientid[$i]?>" class="delete">Delete</a></td>
    			</tr>
    		<?php

		endfor;
		?>		
		</tbody>
		<tfoot>
			<tr>
				<th scope="col" class="manage-title">Ime</th>
				<th scope="col" class="manage-action">Akcija</th>
			</tr>
		</tfoot>
	</table>
</div>