<?php
	include('views/_header.tpl.php');
?>

<style>
	body { background:#f9f9f9; }
	.spacer { padding-top:45px; }
	#mmen { display:none; }
    .form-profile { padding:20px; }
    table { background:#fff; }
    p, td { font-weight:200; }
    table td { padding: 5px; } 
    
	.admintable td,
	.admintable th {
		padding: 10px;
		border: solid #eee 1px;
		text-align: center;
		font-size:17px;
	}
	
	.btn,
	.btn a,
	.btn a:active,
	.btn a:visited {
		background:#aaa; 
		color:#fff;
		border-radius: 50px;
		-moz-border-radius: 50px;
		-webkit-border-radius: 50px;
		font-size: 14px !important;
		font-weight: 300 !important;
		height: 30px !important;
		line-height: 30px !important;
		min-width: 60px;
		width:auto;
		padding: 5px 20px !important;
	}

	a.btn:hover {
		background:#006ab7;
	}	
	
	input.btn-small { 
		background:#aaa; 
		color:#fff;
		border-radius: 50px;
		-moz-border-radius: 50px;
		-webkit-border-radius: 50px;
		font-size: 12px !important;
		font-weight: 300 !important;
		height: 30px !important;
		min-width: 60px;
		width:auto;
		padding:0 15px;
	 }
	input.btn-small:hover { 
		background:#bbb;
	}
	
	input[type="submit"], .submit { border:0px; }
	input[type="submit"]:hover { background:#006ab7; }
	
	/* label, select, button, input[type="button"], input[type="reset"], input[type="submit"], input[type="radio"], input[type="checkbox"]	*/

	.btn-red {
		font-size: 14px; 
		border-radius: 50px;
		-moz-border-radius: 50px;
		-webkit-border-radius: 50px;
	}

	.btn-blue {
		background: #005493;
		border-radius: 50px;
		-moz-border-radius: 50px;
		-webkit-border-radius: 50px;
	}
	
	.delete-admin {
		background: #cd1000;
	}

	.adminred {
		background: #cd1000;
		color: #fff;
	}

	.nonadmin {
		background: #ddd;
		color: #aaa;
	}

	.pagination {
		list-style-type: none;
		padding: 10px 0;
		display: inline-flex;
		justify-content: space-between;
		box-sizing: border-box;
	}

	.pagination li {
		box-sizing: border-box;
		padding-right: 10px;
	}

	.pagination li a {
		box-sizing: border-box;
		background-color: #e2e6e6;
		padding: 8px;
		text-decoration: none;
		font-size: 12px;
		font-weight: bold;
		color: #616872;
		border-radius: 4px;
	}

	.pagination li a:hover {
		background-color: #d4dada;
	}

	.pagination .next a,
	.pagination .prev a {
		text-transform: uppercase;
		font-size: 12px;
	}

	.pagination .currentpage a {
		background-color: #518acb;
		color: #fff;
	}

	.pagination .currentpage a:hover {
		background-color: #518acb;
	}

	.searching {
		display: flex;
		flex-direction: row;
		margin: 10px 0px;
		justify-content: start;
		gap: 10px;
		align-items: center;
	}

	.search {
		padding: 10px;
	}

	.submit {
		background-color: #005493;
	}
	.ut-header{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}	
	
	.blockit, .blockithalf, .blockitlabel { float:left; display:inline-block; width: 200px; padding-right:10px; }
	.viewall { margin-left:15px; }
	
/* ######################################################### */
/*                        MOBILE STYLES                      */
/* ######################################################### */

/* Portrait tablet to landscape and desktop */
@media (min-width: 768px) and (max-width: 979px) {
        .form-profile {
            padding: 20px 0px;
            width: 85%;
        }        
}

/* Landscape phone to portrait tablet */
@media (max-width: 767px) {

}

/* Landscape phones and down */
@media (max-width: 586px) {
	.spacer { padding-top:55px; }
	.form-profile { padding-top:0px; }	
	.tablescroll { height: 500px; overflow-x:scroll; }
	.blockit { width:100%; display:block; background:none;  text-align:center; margin-bottom:10px; }
	.blockithalf { float:left; width:50%; display:inline-block; background:none; text-align:center; margin-bottom:10px; 
	-webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }	
	.right { padding-right:0px; }
	.viewall { margin-left:0px; }
}

/* Landscape phones and down */
@media (max-width: 480px) {
	.spacer { padding-top:15px; }
	.form-profile { padding-top:0px; }
	.tablescroll { height: 500px; overflow-x:scroll; }
	.blockit { width:100%; display:block; background:none; text-align:center; margin-bottom:10px; }	
	.blockithalf { float:left; width:50%; display:inline-block; background:none; text-align:center; margin-bottom:10px; 
	-webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
	.right { padding-right:0px; }
	.viewall { margin-left:0px; }
}    

@media (max-width: 320px) {
	.tablescroll { height: 300px; overflow-x:scroll; }
}    
</style>

<div class="form form-profile aif" style='width:auto'>

	<h1 style="text-align:center;">
		<a href="/admin/dash"><i class="fa fa-sliders" aria-hidden="true" style=""></i></a>&nbsp; Promo Codes
		<a href="/admin/promocodes"><img src="/static/client/scroll_hands.png" style="height:30px;" alt="<>" /></a>				
	</h1>     
		
	<div class="tablescroll" style="background:#fff;">
    <table class="admintable" style="width:100%; overflow:hidden;">
        <tr>
        	<th>ID</th>
            <th>Code</th>
            <th>Type</th>
            <th>Amt</th>
            <th>Allowed</th>
            <th>Claimed</th>
            <th>Client?</th>
            <th>Budgeted</th>
            <th>Spent</th>
            <th>Actions</th>
        </tr>
        <?php
        foreach ($promocodes as $pcode) {
        	if($pcode['type']==1){
        		$type = "Perc.";
        		$showdoll = "";
        		$showper = "%";
        		$class = "color:#000";
        		$amount = $pcode['amount'];
        	} else {
        		$type = "Flat";
        		$showdoll = "$";
        		$showper = "";
        		$class = "color:#16c11d";
        		$amount = number_format($pcode['amount'],2,'.',',');
        	}
        	if($pcode['client'] =="Z"){
        		$client = "-";
        	} else {
        		$client = $pcode['client'];
        	}
        	if($pcode['total_balance'] =="0"){
        		$total_balance = "-";
        	} else {
        		$total_balance = '$'.number_format($pcode['total_balance'],2,'.',',');
        	}     
        	if($pcode['total'] =="0"){
        		$total = "-";
        	} else {
        		$total= '$'.number_format($pcode['total'],0,'.',',');
        	}        	        	   	
            echo "<tr>
            <td style='padding:10px;'>{$pcode['id']}</td>
            <td style='padding:10px;'>{$pcode['code']}</td>
            <td style='padding:10px;'>{$type}</td>
            <td style='padding:10px; font-weight:600; {$class}'>{$showdoll}{$amount}{$showper}</td>
            <td style='padding:10px;'>{$pcode['allowed']}</td>            
            <td style='padding:10px;'>{$pcode['claimed']}</td>           
			<td style='padding:10px;'>{$client}</td>  
			<td style='padding:10px;'>{$total}</td>    
			<td style='padding:10px;'>{$total_balance}</td>
            <td style='padding:10px; min-width:175px; text-align:center;'><a href='/admin/?pcode&edit={$pcode['id']}'>edit</a> &nbsp; | &nbsp;
            <a href='/admin/?pcode&delete={$pcode['id']}' class='confirm' style='font-size:17px;'>delete</a></td></tr>";
        }
        ?>
    </table>
    </div>
    <div class="clear"></div>
    <br />
    <div style="margin:0px;">
        <a href='/admin/?pcode&add' class='btn btn-blue' style='width:auto; display:block;'>Add New</a>
    </div>
    <div class="clear"></div>
    <br />
    
    <div style="font-size:17px; line-height:27px; font-weight:300; text-align:center; color:#000;">
	    <span style="font-weight:600;">Type 1</span>: Percentage Discount, ie. 100%<br />
	    <span style="font-weight:600;">Type 2</span>: Flat Discount, ie. $25    	
    </div>
    <div class="clear"></div>
	<br /><br /><br /><br /><br /><br />

</div>

<style>
	.admintable td,
	.admintable th {
		padding: 3px;
		border: solid #eee 1px;
	}
</style>

<?php
	include 'views/_footer.tpl.php';
?>