<?
	include "../inc/functions.php";
	if(!$_SESSION['log_mobile']){
		header("Location: login.php");
	}

	if(isset($_GET['id'])){
			if(isset($_POST['submit'])){
				if($_POST['default']==1)$def=1;else $def=0;
			mysql_query("update taxes set name='".$_POST['name']."',value='".$_POST['value']."',`default`='".$def."' where id='".$_GET['id']."'")or die(mysql_error());
			$success=1;
		}
				$res=mysql_query("select * from taxes where id='".$_GET['id']."'")or die(mysql_error());
				$info=mysql_fetch_array($res);				
	}	
?>
<!DOCTYPE HTML>
<html>
    <head>
        <title>Payments - 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']){?>Taxes<?}else{?>Tax "<?=$info['name']?>"<?}?></h1>
           <a href="<?if(!$_GET['id']){?>index.php<?}else echo "taxes.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 taxes ..." data-filter-theme="d"data-theme="d" data-divider-theme="d">
			<?
				$res=mysql_query("select * from taxes where hidden='0'")or die(mysql_error());
					while($row=mysql_fetch_array($res)){
						$pos1 = stripos($row['value'],'%' );
							if ($pos1 !== false) {
								$tax="<b>".$row['value']."</b> of product price";
							}else{
								$tax="<b>".$row['value']."</b> ".$cfg['currency'];
							}
					
					?>
						<li><a href="taxes.php?id=<?=$row['id']?>" data-ajax="true"><?=$row['name']?> - <?=$tax?></a></li>
			<?}?>
			</ul>
		<?}else{
			if($success==1){
		?>
			<div class='message success'>
				<i class='icon-ok'></i>
				<p>The tax has been updated!</p>
			</div>
		<?}?>	
		<form action='' method='post' data-ajax="false">
                <ul data-role="listview">			
					<li data-role="fieldcontain">
                        <label for="name2b">Tax name:</label>
                        <input type="text" name="name" id="client_name" value="<?=$info['name']?>" data-clear-btn="true" placeholder="">
                    </li>					
					<li data-role="fieldcontain">
                        <label for="name2b">Amount:</label>
                        <input type="text" name="value" id="client_email" value="<?=$info['value']?>" data-clear-btn="true" placeholder="">
                    </li>					
					<li data-role="fieldcontain">
                        <label for="name3b">Checked by default?</label>
                        <input type="checkbox" name="default" id="name3b" value='1' <?if($info['default']==1)echo "checked"?>>
                    </li>											
	                    <li>
                        <fieldset class="ui-grid-a">
                                <div class="ui-block-a"><button type="submit" name='submit'>Update</button></div>
                        </fieldset>
                    </li>				
			</ul>
			</form>			
		<?}?>				
		</div><!--/content-primary -->		
		

        </div>

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