<style>
#lnav{border-right:1px solid #CCC; background:#f1f1f1; position:fixed; left:0; top:50px; bottom:0; width:200px}
#rcontent{ width:calc(100% - 220px); float:right;}
</style>
<script type="text/javascript">
$(document).ready(function(e) {
     //$.modaldialog.success('Success');
	var pageHeight = ($(document).height()-50)+"px";
	$('#lnav').css('height',pageHeight);
});
//使用优惠券
function douse(aid)
{
	$.ajax({
		url:'<?php echo site_url('coupon/doupdate');?>',
		type:'POST',
		data:{
			aid:aid,
			status:1,
			doact:'isuse'
		},
		beforeSend: function(){
			if(isNaN(parseInt(aid))){
				$.modaldialog.error('参数错误，必须为数字');
				return false;
			}
			if(! confirm('确定使用？')){
				return false;
			}
		},
		success: function(str){
			if(str=='ok')
			{
				$.modaldialog.success('修改成功,页面正在刷新...');	
				setTimeout(function() {
					history.go(0);
				}, 1500);
			}else{
				$.modaldialog.error(str);	
			}
		}
	});	
}

//删除优惠券
function dodel(aid){
	$.ajax({
		url:'<?php echo site_url('coupon/doupdate');?>',
		type:'POST',
		data:{
			aid:aid,
			doact:'delete'
		},
		beforeSend: function(){
			if(isNaN(parseInt(aid))){
				$.modaldialog.error('参数错误，必须为数字');
				return false;
			}
			if(! confirm('确定删除？')){
				return false;	
			}
			return true;
		},
		success: function(str){
			if(str=='ok')
			{
				$.modaldialog.success('删除成功,页面正在刷新...');	
				setTimeout(function() {
					history.go(0);
				}, 1500);

			}else{
				$.modaldialog.error(str);	
			}
		}
	});
}
</script>
<div class="row-fluid">
  <div class="span2" id="lnav">	
	<ul class="nav nav-list">
    	<li class="nav-header">促销模块</li>
        <?php foreach($menu as $mrs):?>
    	<li><a href="<?php echo site_url($mrs['url']) ?>"><?php echo $mrs['name'] ?></a></li>
        <?php endforeach; ?>
    </ul>
  </div>
	<?php if(isset($coupon)){ ?>
    <div class="span10" id="rcontent">
        <legend>生肖促销订单(共 <?php echo $sumOrders ?> 个订单)</legend>
        <form id="couponsearch" name="couponsearch" method="post" action="/info.php/coupon/search" class="navbar-form pull-left">
		  <div class="input-append">
			  <input type="text" class="input-xlarge" name="kwds" id="kwds" value="<?php if(isset($kwds)){echo $kwds; }?>" placeholder="search by email or full name">
              <input type="hidden" name="ctype" value="zodiac">
			  <button class="btn">Search</button>
		  </div>
		</form>
        <table class="table table-striped">
            <thead>
              <tr>
                  <th width="2%" align="center">#</th>
                  <th>姓名</th>
                  <th>Email</th>
                  <th>优惠代码</th>
                  <th>优惠价格</th>
                  <th>IP地址</th>
                  <th>提交时间</th>
                  <th>失效时间</th>
                  <th>状态</th>
                  <th>操作</th>
              </tr>
          </thead>
          <tbody>
          <?php
              $i=0;	 
              foreach($coupon as $rsc){
                  $i+=1; 
				  $str_statu = '';
				  if($rsc->is_use){
					  $str_statu .= ' 已使用 ';
				  }
				  $isvalid = (strtotime("now") - strtotime($rsc->invalid_date));
				  if(!$rsc->is_valid or $isvalid>0){
					  $str_statu .= ' 已失效 ';	  
				  }
          ?>
          <tr>
              <td width="2%" align="center"><?php echo ($i+$sumno)?></td>
              <td><?php echo $rsc->username ?></td>
              <td><?php echo $rsc->useremail ?></td>
              <td><?php echo $rsc->coupon_no ?></td>
              <td><?php echo '$'.(int)$rsc->price ?></td>
              <td><?php echo $rsc->userip ?></td>
              <td><?php echo date("Y-m-d",strtotime($rsc->addtime)) ?></td>
              <td><?php echo date("Y-m-d",strtotime($rsc->invalid_date)) ?></td>
              <td><?php $str_statu == '' ? $str_statu = '正常' : $str_statu; echo $str_statu; ?> </td>
              <td>
                  <a href="javascript:;" onClick="dodel('<?php echo $rsc->id ?>')">删除</a>
                  <?php if(!$rsc->is_use or $isvalid>0){ ?>
                      <a href="javascript:;" onClick="douse('<?php echo $rsc->id ?>')">使用</a>
                  <?php } ?>
              </td>
          </tr>
          <?php }//end of foreach ?>
          </tbody>
        </table>
        <div class="page"><?php echo $this->pagination->create_links();?></div>
    </div>
    <?php }//end of isset $coupon ?>
</div>