<?php echo $header; ?>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<?php if ($success) { ?>
<div class="success"><?php echo $success; ?></div>
<?php } ?>
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
  <div class="heading">
    <h1 style="background-image: url('view/image/affiliate.png');"><?php echo $heading_title; ?></h1>
<!-- 
	<div class="buttons">
       <a onclick="$('form').attr('action', '<?php echo $approve; ?>'); $('form').submit();" class="button"><span><?php echo $text_UpdatePayment_InP; ?></span></a>
       <a onclick="$('form').attr('action', '<?php echo $updatepaid; ?>'); $('form').submit();" class="button"><span><?php echo $text_UpdatePayment_CMP; ?></span></a>
       <a onclick="$('form').attr('action', '<?php echo $generatefile; ?>'); $('form').submit();" class="button"><span><?php echo $text_GenMasPayFile; ?></span></a> 
    </div>
-->
  </div>
  <div class="content">
    <form action="" method="post" enctype="multipart/form-data" id="form">
      <table class="list">
        <thead>
          <tr>
            <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
            <td class="left"><?php if ($sort == 'name') { ?>
              <a href="<?php echo $sort_name; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_name; ?></a>
              <?php } else { ?>
              <a href="<?php echo $sort_name; ?>"><?php echo $column_name; ?></a>
              <?php } ?></td>
            <td class="left"><?php if ($sort == 'c.email') { ?>
              <a href="<?php echo $sort_email; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_email; ?></a>
              <?php } else { ?>
              <a href="<?php echo $sort_email; ?>"><?php echo $column_email; ?></a>
              <?php } ?></td>
            <td class="left"><?php if ($sort == 'affiliate_group') { ?>
              <a href="<?php echo $sort_affiliate_group; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_affiliate_group; ?></a>
              <?php } else { ?>
              <a href="<?php echo $sort_affiliate_group; ?>"><?php echo $column_affiliate_group; ?></a>
              <?php } ?></td>         
                   
            <td class="left"><?php if ($sort == 'c.status') { ?>
              <a href="<?php echo $sort_paidstatus; ?>" class="<?php echo strtolower($order); ?>"><?php echo $text_Payment_Status; ?></a>
              <?php } else { ?>
              <a href="<?php echo $sort_paidstatus; ?>"><?php echo $text_Payment_Status; ?></a>
              <?php } ?></td>
              
            <td class="left"><?php if ($sort == 'aa.Sale_Total') { ?>
              <a href="<?php echo $sort_approved; ?>" class="<?php echo strtolower($order); ?>"><?php echo $text_Payment_Details; ?></a>
              <?php } else { ?>
              <a href="<?php echo $sort_approved; ?>"><?php echo $text_Payment_Details; ?></a>
              <?php } ?></td>              
            <td class="left"><?php if ($sort == 'c.date_added') { ?>
              <a href="<?php echo $sort_date_added; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_date_added; ?></a>
              <?php } else { ?>
              <a href="<?php echo $sort_date_added; ?>"><?php echo $column_date_added; ?></a>
              <?php } ?></td>
            <td class="right"><?php echo $column_action; ?></td>
          </tr>
        </thead>
        <tbody>
          <tr class="filter">
            <td></td>
            <td><input type="text" name="filter_name" value="<?php echo $filter_name; ?>" /></td>
            <td><input type="text" name="filter_email" value="<?php echo $filter_email; ?>" /></td>
            
            <td><select name="filter_affiliate_group_id">
                <option value="*"></option>
                <?php foreach ($affiliate_groups as $affiliate_group) { ?>
                <?php if ($affiliate_group['affiliate_group_id'] == $filter_affiliate_group_id) { ?>
                <option value="<?php echo $affiliate_group['affiliate_group_id']; ?>" selected="selected"><?php echo $affiliate_group['name']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $affiliate_group['affiliate_group_id']; ?>"><?php echo $affiliate_group['name']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
              
            <td><select name="filter_status">              
                <option value="*" ></option>                
                <?php if ($filter_status == 1 ) { ?>
                     <option value="1" selected="selected"><?php echo $text_Paid; ?></option>
                <?php } else { ?>
                     <option value="1"><?php echo $text_Paid; ?></option>
                <?php } ?>   
                <?php if ($filter_status == 2) { ?>
                     <option value="2" selected="selected"><?php echo $text_InProcess; ?></option>
                <?php } else { ?>
                     <option value="2"><?php echo $text_InProcess; ?></option>
                <?php } ?>                                
                <?php if (!is_null($filter_status) && !$filter_status) { ?>                
                    <option value="0" selected="selected"><?php echo $text_NotPaid; ?></option>
                <?php } else { ?>
                    <option value="0"><?php echo $text_NotPaid; ?></option>
                <?php } ?>
              </select>
            </td>
                          
            <td><select name="filter_approved">              
                <option value="*"></option>
                <?php if ($filter_approved == 1 ) { ?>
                     <option value="1" selected="selected"><?php echo "="; ?></option>
                <?php } else { ?>
                     <option value="1"><?php echo "="; ?></option>
                <?php } ?>   

                <?php if ($filter_approved == 2) { ?>
                     <option value="2" selected="selected"><?php echo "<"; ?></option>
                <?php } else { ?>
                     <option value="2"><?php echo "<"; ?></option>
                <?php } ?>                                
                <?php if (!is_null($filter_approved) && !$filter_approved) { ?>                
                    <option value="0" selected="selected"><?php echo ">"; ?></option>
                <?php } else { ?>
                    <option value="0"><?php echo ">"; ?></option>
                <?php } ?>
              </select>
              <input type="text" name="filter_payment" value="<?php $filter_payment; ?>" size="12" />
            </td>

              </td>              
            <td><input type="text" name="filter_date_added" value="<?php echo $filter_date_added; ?>" size="12" id="date" /></td>
            <td align="right"><a onclick="filter();" class="button"><span><?php echo $button_filter; ?></span></a></td>
          </tr>
          <?php if ($affiliates) { ?>
          <?php foreach ($affiliates as $affiliate) { ?>
          <tr>
            <td style="text-align: center;">
               <?php if ($affiliate['payment_status']!=1) { ?>
                   <?php if ($affiliate['selected']) { ?>
                      <input type="checkbox"  name="selected[]" value="<?php echo $affiliate['affiliate_id']; ?>" checked="checked" />
                   <?php } else { ?>
                      <input type="checkbox" name="selected[]" value="<?php echo $affiliate['affiliate_id']; ?>" />
                   <?php } ?>
               <?php } ?>
            </td>            
            <td class="left"><?php echo $affiliate['name']; ?></td>
            <td class="left"><?php echo $affiliate['email']; ?></td>
            <td class="left"><?php echo $affiliate['affiliate_group']; ?></td>
            <td class="left">
            <?php 
                  switch ($affiliate['payment_status']) 
                  {
                      case 0:
                          echo $text_NotPaid;
                          break;
                      case 1:
                          echo $text_Paid;
                          break;
                      case 2:
                          echo $text_InProcess;
                          break;
                  }
            ?>
            </td>
            <td class="left"><?php echo $affiliate['Sale_Total']; ?></td>
            <td class="left"><?php echo $affiliate['date_added']; ?></td>
            <td class="right"><?php foreach ($affiliate['action'] as $action) { ?>
              [ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
              <?php } ?></td>
          </tr>
          <?php } ?>
          <?php } else { ?>
          <tr>
            <td class="center" colspan="8"><?php echo $text_no_results; ?></td>
          </tr>
          <?php } ?>
        </tbody>
      </table>
    </form>
    <div class="pagination"><?php echo $pagination; ?></div>
  </div>
</div>
<script type="text/javascript"><!--
function filter() {
	url = 'index.php?route=affiliate/affiliatepayment&token=<?php echo $token; ?>';
	
	var filter_name = $('input[name=\'filter_name\']').attr('value');
	
	if (filter_name) {
		url += '&filter_name=' + encodeURIComponent(filter_name);
	}
	
	var filter_email = $('input[name=\'filter_email\']').attr('value');
	
	if (filter_email) {
		url += '&filter_email=' + encodeURIComponent(filter_email);
	}
	
	var filter_affiliate_group_id = $('select[name=\'filter_affiliate_group_id\']').attr('value');
	
	if (filter_affiliate_group_id != '*') {
		url += '&filter_affiliate_group_id=' + encodeURIComponent(filter_affiliate_group_id);
	}	
	
	var filter_status = $('select[name=\'filter_status\']').attr('value');
	
	if (filter_status != '*') {
		url += '&filter_status=' + encodeURIComponent(filter_status); 
	}	
	
	var filter_approved = $('select[name=\'filter_approved\']').attr('value');
	
	if (filter_approved != '*') {
		url += '&filter_approved=' + encodeURIComponent(filter_approved);
	}	
	var filter_payment = $('input[name=\'filter_payment\']').attr('value');

	if (filter_payment) {
		url += '&filter_payment=' + encodeURIComponent(filter_payment);
	}	
	var filter_date_added = $('input[name=\'filter_date_added\']').attr('value');
	
	if (filter_date_added) {
		url += '&filter_date_added=' + encodeURIComponent(filter_date_added);
	}
	
	location = url;
}
//--></script>
<script type="text/javascript" src="view/javascript/jquery/ui/ui.datepicker.js"></script>
<script type="text/javascript"><!--
$(document).ready(function() {
	$('#date').datepicker({dateFormat: 'yy-mm-dd'});
});
//--></script>
<?php echo $footer; ?>