<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004-2010 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts VistaCart                     |
// +----------------------------------------------------------------------+
// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |
// +----------------------------------------------------------------------+
?>
<?php echo $javascript->link('jquery.js'); ?>
<?php echo $javascript->link('hint.js'); ?>
<script language="JavaScript" type="text/JavaScript">
function clickSearch()
{
	document.frmUsers.submit();
}
function getsrch(){
	var w = document.getElementById("cmbSearchType").selectedIndex;
	var sp = document.getElementById("cmbSearchType").options[w].value;
	if(sp == 'type'){
		document.getElementById("cmbsrch").innerHTML = '<select name="txtSearch" id="txtSearch" class="box2_admin"><option value="Perc">Percentage</option><option value="Amt">Amount</option></select>';
	}else{
		document.getElementById("cmbsrch").innerHTML = '<input type="text" name="txtSearch" maxlength="50" value="<?php echo(htmlentities($txtSearch)); ?>" class="box2_admin">';
	}
}
</script>
<div align="center" class="subheading">
              <div align="left">Promo Codes
			  <a href="#" class="tooltip" title="<strong><u>Promotional Codes</u></strong><br>
									Promo code is a type of coupon that merchants offer. Customers can easily get discounts by entering prom code at checkout. " onclick="return false;">
			 <?php echo $html->image('/img/hint.png', array('border' => 0, 'text-decoration' => 'none'));?>	
			 </a>	
			 </div>
            </div>
            <br />
           <?php if($session->check('Message.flash')) { ?><div id="okbox"><font color="#446423"><?php $session->flash(); ?></font></div><?php } ?>
			<div align="left" id="item_details_admin">
				<!--Search area start -->					
					<form action="<?php echo $sitebase.$sitefolder.'/'.$this->params["controller"];?>" method="get" name="frmUsers">
					<div>	
    				<div style="float:left">
					<select id="cmbSearchType" name="cmbSearchType" onBlur="javascript:getsrch();" class="box2_admin">
					<option value="code"  <?php if($cmbSearchType == "code" || $cmbSearchType == ""){ echo("selected"); } ?>>Promo code</option>
					<option value="amt"  <?php if($cmbSearchType == "amt"){ echo("selected"); } ?>>Gift amount</option>
					<option value="type"  <?php if($cmbSearchType == "type"){ echo("selected"); } ?>>Gift type</option>
				   </select>
				   <label id="cmbsrch"><input type="text" name="txtSearch" maxlength="50" value="<?php echo(htmlentities($txtSearch)); ?>"  class="box2_admin" > </label>
				   </div>
				   <div>				   
				   <a style="cursor:pointer" onClick="javascript:clickSearch();"><?php echo $html->image('/img/search_bttn.gif');?></a>
				   </div>
	              </div>			           				
                  </form>	
                  <br />		
				  <!--Search area end -->		
				  
           
				 <br /><br />	
				 <label  class="btn_style-org" style="width:180px "><strong><?php echo $html->link('Add New Promocode','/coupons/add');?> >></strong></label>
				 <?php if(count($coupons) > 0) { ?>
				 <label  class="btn_style-org"><strong><?php echo $html->link('Export to csv','/coupons/pcodecsv');?> >></strong></label>
				 <label  class="btn_style-org"><strong><?php echo $html->link('Export to xls','/coupons/pcodexls');?> >></strong></label>
				 <?php } ?>
				 <div class="clear"></div>
				 <br /><br />		
				

              <!--items display area start -->		
				  <div align="center" id="items_display_area_admin">
						<form name="customlist" method="post" action="/vistacart/customfieldvalues/edit">
						   <div id="list_admin_top">
                                                       <div class="list9" style="width: 20px;"><strong>#</strong></div>
                                                       <div class="listp1" style="width: 80px;"><strong><?php echo $paginator->sort('Code', 'Coupon.code'); ?></strong></div>
											<div class="listp2"><strong><?php echo $paginator->sort('Based on', 'Coupon.type'); ?></strong></div>	
											<div class="listp3"><strong><?php echo $paginator->sort('Gift value', 'Coupon.giftvalue'); ?></strong></div>	
											<div class="listp4"><strong><?php echo $paginator->sort('Minimum amount', 'Coupon.minamt'); ?></strong></div>	
											<div class="listp5"><strong><?php echo $paginator->sort('Start Date', 'Coupon.from'); ?></strong></div>	
											<div class="listp5"><strong><?php echo $paginator->sort('End Date', 'Coupon.to'); ?></strong></div>	
											<div class="listp6"><strong><?php echo $paginator->sort('Description', 'Coupon.descr'); ?></strong></div>	
											<div class="listp7"><strong>Options</strong></div>										
											<div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
							</div>

								<?php
								if(!empty($passedarg) && !isset($passedarg["page"]))								
									$cnt=1;
									else if(!empty($passedarg) && $passedarg["page"]==1)
									$cnt=1;
									else
									$cnt=((($passedarg["page"]-1)*($passedarg["limit"]))+1);
					  if(!empty($coupons)){
					foreach ($coupons as $coupon){?>   
										<div id="list_admin">
														<div class="list9" style="width: 20px;"><?php echo $cnt++;?></div>
														<div class="listp1" style="width: 80px;">
														<?php  echo Sanitize::html($coupon['Coupon']['code']); ?>
														</div>
														
														<div class="listp2">
														<?php if( $coupon['Coupon']['type'] == "Amt"){ echo "Amount"; }else{ echo "Percentage"; } ?>
														</div> 
														
														<div class="listp3">
														<?php  echo Sanitize::html($coupon['Coupon']['giftvalue']); ?>
														</div>                                        
														<div class="listp4">
														<?php  echo Sanitize::html($coupon['Coupon']['minamt']); ?>
														</div> 
														<div class="listp5">
														<?php $dt	= strtotime($coupon['Coupon']['from_date']); 
														echo date("m-d-Y",$dt );?>
														</div> 
														<div class="listp5">
														<?php $dt	= strtotime($coupon['Coupon']['to_date']); 
														echo date("m-d-Y",$dt );?>
														</div> 
														<div class="listp6">
														<?php 
														$descr=$coupon['Coupon']['descr'];
														if(strlen($descr)>20)
														$descr=substr($descr, 0, 20)."...";
														else
														$descr=$descr; ?>	
														<a href="#" class="tooltip" title="<?php echo $coupon['Coupon']['descr']; ?>" style="text-decoration:none;" onclick="return false;">
														<?php echo Sanitize::html($descr); ?>
														</a>
														</div> 
														<div class="listp7">
														<?php echo $html->link('Edit', 
				"/coupons/edit/".$coupon['Coupon']['id'])." / ".$html->link('Delete', 
				"/coupons/delete/".$coupon['Coupon']['id'],null,'Are you sure you want to delete this Coupon Code'); ?>
														</div> 
														<div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
										</div>
							 <?php 		
							 } ?>
							   <div id="admin_bottom">	
														<div>&nbsp;</div>
														<div>
														<?php 
									  if($cmbSearchType <> '' &&  $txtSearch <> ''){
									   $paginator->options(array('url'=>array_merge(array('cmbSearchType'=>$cmbSearchType,
									   'txtSearch'=>$txtSearch),$this->passedArgs))); }  ?>
														 <?php echo $paginator->numbers(); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $paginator->counter(); ?>	   </div>
														<div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
												  </div>			
							 <?php } else { ?>
									  <div id="admin_bottom">									
														
														<div>&nbsp;</div>
														<div><strong>Sorry no promo codes found !</strong></div>
														<div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
										</div>			     
							 <?php } ?>
							 
							 </div>							
 <div align="left" class="float_clear1"></div>
</div>
 <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div> 