<?php if(!defined('PARENT')) { exit; }
$SQL = (isset($AF->id) ? 'WHERE (`affid` = \'' . $AF->id . '\')' : '');
$Q  = $DB->db_query("SELECT SQL_CALC_FOUND_ROWS *,
      (SELECT CONCAT(`fname`,' ',`lname`) FROM `" . DB_PREFIX . "affiliates` WHERE `" . DB_PREFIX . "affiliates`.`id` = `" . DB_PREFIX . "affiliates_payments`.`affid`) AS `affName`
      FROM `" . DB_PREFIX . "affiliates_payments`
      $SQL
      ORDER BY `ts` DESC,`id` DESC
      LIMIT $limit," . PER_PAGE);
$NR = $DB->db_foundrows($Q);
?>

    <div class="row">
      <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-right">
        <div class="btn-group">
          <button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <i class="fa fa-chevron-down fa-fw"></i>
          </button>
          <ul class="dropdown-menu dropdown-menu-right">
            <li><a href="?p=payments-add<?php echo (isset($AF->id) ? '&amp;aid=' . $AF->id : ''); ?>"><i class="fa fa-plus fa-fw"></i> <?php echo $msw_adm_payments_manage2; ?></a></li>
            <?php
            if ($NR > 0) {
            ?>
            <li><a href="#" onclick="mswExp('<?php echo (isset($_GET['q']) && $_GET['q'] ? '&amp;q=' . urlencode(mswSH($_GET['q'])) : '') . (isset($AF->id) ? '&amp;id=' . $AF->id : ''); ?>','payments-export');return false"><i class="fa fa-save fa-fw"></i> <?php echo $msw_adm_payments_manage12; ?></a></li>
            <li><a href="?p=payments-search"><i class="fa fa-search fa-fw"></i> <?php echo $msw_adm_payments_manage6; ?></a></li>
            <?php
            }
            ?>
          </ul>
        </div>
      </div>
    </div>

    <div class="managepanel" style="margin-top:10px">
      <form method="post" action="?p=<?php echo $cmd; ?>">
      <div class="panel panel-default managearea">
        <div class="panel-heading">
          <?php echo $msw_adm_payments_manage . (isset($AF->id) ? ' (<span class="highlight notexttrans">' . mswSH($AF->fname . ' ' . $AF->lname) . '</span>, ' . mswNFM($NR) . ')' : ' (' . mswNFM($NR) . ')'); ?>
        </div>
        <div class="panel-body">
          <div class="table-responsive">
           <table class="table table-striped table-hover" id="sortTable">
             <thead>
               <tr>
                 <th class="text-center"><input type="checkbox" name="c" value="yes" onclick="mswSC('.managearea .table td','delb')"></th>
                 <th data-sort="string"><?php echo $msw_adm_payments_manage7; ?></th>
                 <th data-sort="int"><?php echo $msw_adm_payments_manage8; ?></th>
                 <th data-sort="float"><?php echo $msw_adm_payments_manage9; ?></th>
                 <th data-sort="string"><?php echo $msw_adm_payments_manage10; ?></th>
                 <th>&nbsp;</th>
               </tr>
             </thead>
             <tbody>
               <?php
               if ($NR > 0) {
                 while ($PY = $DB->db_object($Q)) {
                   include(PATH . 'content/list-screens/payments-manage.php');
                 }
               } else {
                 $colspan = 6;
                 include(PATH . 'content/no-data.php');
               }
               ?>
             </tbody>
           </table>
         </div>
         <?php
         // Pagination..
         if ($NR > PER_PAGE) {
           $PGS = new pages(array(
             'count' => $NR,
             'text' => $msw_pages,
             'page' => $page,
             'admin' => 'yes',
             'flag' => '',
             'limit' => PER_PAGE,
             's' => $SETTINGS
           ));
           echo $PGS->display();
         }
         ?>
        </div>
      </div>
      <?php
      if ($NR > 0) {
      ?>
      <div class="act-button">
        <div class="text-center delselected" id="delb_span" style="display:none"><span>0</span> <?php echo $msw_public_11_global[0]; ?></div>
        <button type="button" class="btn btn-danger disabled" id="delb" onclick="if(jQuery(this).attr('class')!='btn btn-danger disabled'){mswAction('<?php echo $cmd; ?>-del','.managepanel','no','yes')}"><i class="fa fa-times fa-fw"></i> <span class="hidden-xs"><?php echo $msw_common3; ?></span></button>
        <?php
        if (isset($AF->id)) {
        ?>
        <button type="button" class="btn btn-default left_20" onclick="mswWin('aff-manage')"><i class="fa fa-arrow-left fa-fw"></i> <span class="hidden-xs"><?php echo $msw_common6; ?></span></button>
        <?php
        }
        ?>
      </div>
      <?php
      } else {
        if (isset($AF->id)) {
        ?>
        <div class="act-button">
          <button type="button" class="btn btn-default" onclick="mswWin('aff-manage')"><i class="fa fa-arrow-left fa-fw"></i> <span class="hidden-xs"><?php echo $msw_common6; ?></span></button>
        </div>
        <?php
        }
      }
      ?>
      </form>
    </div>