<?
include "inc/functions.php";
if(!$_SESSION['logged']){
	header("Location: login/");
}
	$meniu='clients';
	
	$res		=	mysql_query("SELECT * FROM `invoices` group by client_name,client_email");
	$count		=	mysql_num_rows($res);
	$pagination	=	smart_pagination(1,$count,25,'da')
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
	<title>Client List | Pro Invoice Maker</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script language="javascript" type="text/javascript" src="js/jquery-1.9.1.js"></script>
	<script language="javascript" type="text/javascript" src="js/script.js"></script>
	<script language="javascript" type="text/javascript" src="js/jquery-ui-1.10.3.custom.min.js"></script>
	<link href="favicon.ico" rel="shortcut icon"/>	
	<link rel="stylesheet" media="screen" href="style/style.css" /> 
	<link rel="stylesheet" media="screen" href="style/hot-sneaks/jquery-ui-1.10.3.custom.min.css" />
	<link href="favicon.ico" rel="shortcut icon"/>		
 </head>
 <body>
	<div id='container'>
	<?include "inc/header.php"?>
		<div class='title'>Clients</div>
		<div id='content'>
		<script type='text/javascript'>
			setfiltru=function(id,page){
			$('#page').val(page);
				$.ajax({
				   type: "POST",
				   url: "inc/clients.php",
				   data: "page="+$('#page').val(),
				   success: function(msg){
						$('#ajaxreturn').html(msg);
				   }
				 });
			}
		</script>		
		<br>
		<input type='hidden' class='filter' id='page' name='page' value='1'>
		<div id='ajaxreturn'>
			<table width='100%' cellspacing='0' cellpadding='0'>
				<tr style='background:#003b8c; color:#fff;'>
					<td class='tdhead' width='20'>ID</td>
					<td class='tdhead' width='200'>Name</td>
					<td class='tdhead'>Email</td>
					<td class='tdhead' width='30'>Phone</td>
					<td class='tdhead' width='130'>Location</td>
					<td class='tdhead' width='60'>Invoices</td>
				</tr>
				<?
					$i=1;
		$res=mysql_query("SELECT * FROM `invoices` group by client_name,client_email limit 0,25")or die(mysql_error());
		$cnt=mysql_num_rows($res);
		$i=1;
			while($row=mysql_fetch_array($res)){
			$row['client_address']=preg_replace("/\r/", '',preg_replace("/\n/", '\n', $row['client_address']));
			$res2=mysql_query("select * from `invoices` where client_name='".mysql_real_escape_string($row['client_name'])."' and  client_email='".mysql_real_escape_string($row['client_email'])."'")or die(mysql_error());
						?>
					<tr style='height:22px; cursor:pointer;' onclick="top.location='client.php?client_name=<?=urlencode($row['client_name'])?>&client_email=<?=urlencode($row['client_email'])?>'" onmouseover="$(this).css('background','#efffd0')" onmouseout="$(this).css('background','#fff')">
						<td class='tdhead2'><?=$i?></td>
						<td class='tdhead2'><?=strip_tags($row['client_name'])?></td>
						<td class='tdhead2'><?=$row['client_email']?></td>
						<td class='tdhead2'><?=$row['client_phone']?></td>
						<td class='tdhead2'><?=$row['client_location']?></td>
						<td class='tdhead2' align='right' style='border-right:1px solid #e6e6e6;'><?=mysql_num_rows($res2)?></td>
					</tr>	
						<?$i++;}
						if(mysql_num_rows($res)==0){
							echo "<tr><td class='tdhead2' style='border-right:1px solid #e6e6e6; text-align:center;' colspan='8'>No Clients Found</td></tr>";
						}
						?>
			</table>
			<div class='pagination'><?=$pagination?></div>
		</div>	
			<br>
		</div>
	</div>
	<?include "inc/footer.php"?>
 </body>
 </html>