<?
	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['id'])){
				$res=mysql_query("select * from invoices where id='".$_GET['id']."'")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['id']){?>Invoices<?}else{?>Invoice #<?=$info['invoice_no']?><?}?></h1>
           <a href="<?if(!$_GET['id']){?>index.php<?}else echo "invoices.php"?>" data-ajax="true"><i class='icon-arrow-circle-left'></i></a>
        </div>
        
        <div data-role="content">   

		<div class="content-primary">	
		<?if(!isset($_GET['id'])){?>
			<ul data-role="listview" data-filter="true" data-filter-placeholder="Search invoices..." data-filter-theme="d"data-theme="d" data-divider-theme="d">
			<?
			$i=1;
			$z=0;
			while($i<35){
				$res=mysql_query("select * from invoices where date>'".strtotime('-'.($z+1).' day', $s)."' and date<'".strtotime('-'.$z.' day', $s)." order by date desc '")or die(mysql_error());
				if(mysql_num_rows($res)){	
			?>
				<li data-role="list-divider"><?=date('d.m.Y',strtotime('-'.$z.' day', $s))?></li>
				<?
					while($row=mysql_fetch_array($res)){?>
						<li><a href="invoices.php?id=<?=$row['id']?>" data-ajax="true"><?=$row['client_name']?> <i class='icon-ellipsis-vertical'></i> <?=$row['client_email']?> <i class='icon-ellipsis-vertical'></i> <?=$row['total']?> <?=$row['currency']?> <i class='icon-ellipsis-vertical'></i> <?=date('H:i',$row['date'])?></a></li>
			<?}$i++;}
			
			$z++; if($z>150)$i=36;}?>
			</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>
		</div>
			<ul data-role="listview" data-inset="false" data-icon="false" data-divider-theme="b">
	            <li >
					<a href="../inc/invoicepdf.php?id=<?=encrypt($_GET['id']."-".md5($_GET['id']))?>" data-ajax="false"><i class='icon-file-text'></i> Download PDF</a>
	            </li>
	            <li >
					<a href="../inc/invoicehtml.php?id=<?=encrypt($_GET['id']."-".md5($_GET['id']))?>" target='_blank' data-ajax="false"><i class='icon-file-text'></i> View HTML</a>
	            </li>	         		
	        </ul>		
		<?}?>		
		</div><!--/content-primary -->		
		

        </div>

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