<?
	include "../inc/functions.php";
	if(!$_SESSION['log_mobile']){
		header("Location: login.php");
	}
	
	$d = strtotime("00:00:00");
	$s = strtotime('+1 day', $d);
	
	if(isset($_GET['name'])){
				$res=mysql_query("select * from invoices where client_name='".$_GET['name']."'")or die(mysql_error());
				$info=mysql_fetch_array($res);
	}
	
?>
<!DOCTYPE HTML>
<html>
    <head>
        <title>Pro Invoice Maker 2.0</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <link rel="stylesheet" href="css/font-awesome.min.css" />
        <link rel="stylesheet" href="css/jquerymobile.css" />
        <link rel="stylesheet" href="css/jquerymobile.nativedroid.css" />
        <link rel="stylesheet" href="css/jquerymobile.nativedroid.light.css"  id='jQMnDTheme' />
        <link rel="stylesheet" href="css/jquerymobile.nativedroid.color.blue.css" id='jQMnDColor' />
		<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>


    </head>
    <body>
        
    <div data-role="page" data-theme='b'>


        <div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme='b'>
            <h1><?if(!$_GET['name']){?>Clients<?}else{?><?=$_GET['name']?><?}?></h1>
           <a href="<?if(!$_GET['name']){?>index.php<?}else echo "clients.php"?>" data-ajax="true"><i class='icon-arrow-circle-left'></i></a>
        </div>
        
        <div data-role="content">   

		<div class="content-primary">	
		<?if(!isset($_GET['name'])){?>
			<ul data-role="listview" data-filter="true" data-filter-placeholder="Search clients..." data-filter-theme="d"data-theme="d" data-divider-theme="d">
			<?
			$str="ABCDEFGHIJKLMNOPQRSTUVWXYZ#";
			$i=1;
			$z=0;
			for($i=0;$i<=strlen($str);$i++){
				$res=mysql_query("select distinct client_name from invoices where client_name like '".$str[$i]."%' order by client_name asc")or die(mysql_error());
				if(mysql_num_rows($res)){	
			?>
				<li data-role="list-divider"><?=$str[$i]?></li>
				<?
					while($row=mysql_fetch_array($res)){?>
						<li><a href="clients.php?name=<?=$row['client_name']?>" data-ajax="true"><?=$row['client_name']?></a></li>
			<?}}
			
			$z++;}?>
			</ul>
		<?}else{

		?>
		<div class='inset'>
			<h3><b>Name:</b><?=$info['client_name']?></h3>
			<h3><b>Email:</b><?=$info['client_email']?></h3>
			<h3><b>Phone:</b><?=$info['client_phone']?></h3>
			<h3><b>Addr:</b><?=$info['client_address']?></h3>
			<h3><b>Payment method:</b><?=$info['payment_method']?></h3>
			
			<h3><b>Total:</b><?=$info['total']?> <?=$info['currency']?></h3>
		<h1>Invoices</h1>
		</div>
			<ul data-role="listview" data-inset="false" data-icon="false" data-divider-theme="b">
			<?$res=mysql_query("select * from invoices where client_name='".$_GET['name']."'")or die(mysql_error());
				while($row=mysql_fetch_array($res)){?>
	            <li >
					<a href="invoices.php?id=<?=$row['id']?>" data-ajax="false">#<?=$row['invoice_no']?> from <?=date('d.m.Y',$row['date'])?> amount <?=$row['total']?> <?=$row['currency']?></a>
	            </li>
			<?}?>	
	         		
	        </ul>		
		<?}?>		
		</div><!--/content-primary -->		
		

        </div>

    </div>
    
    </body>
</html>
