<?php if(!defined('PARENT')) { exit; }
$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_commissions`.`affid`) AS `affName`,
      (SELECT `name` FROM `" . DB_PREFIX . "products` WHERE `" . DB_PREFIX . "products`.`id` = `" . DB_PREFIX . "affiliates_commissions`.`product`) AS `productName`
      FROM `" . DB_PREFIX . "affiliates_commissions`
      WHERE (`en` = 'yes' AND `approved` = 'no')
      ORDER BY `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=commissions-add"><i class="fa fa-plus fa-fw"></i> <?php echo $msw_adm_commissions_manage2; ?></a></li>
            <?php
            if ($NR > 0) {
            ?>
            <li><a href="?p=commissions-search"><i class="fa fa-search fa-fw"></i> <?php echo $msw_adm_commissions_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_commissions_manage; ?> (<?php echo 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_commissions_manage7; ?></th>
                 <th data-sort="int"><?php echo $msw_adm_commissions_manage8; ?></th>
                 <th data-sort="float"><?php echo $msw_adm_commissions_manage9; ?></th>
                 <th data-sort="float"><?php echo $msw_adm_commissions_manage10; ?></th>
                 <th>&nbsp;</th>
               </tr>
             </thead>
             <tbody>
               <?php
               if ($NR > 0) {
                 while ($CM = $DB->db_object($Q)) {
                 ?>
                 <tr id="idr_<?php echo $CM->id; ?>">
                   <td><input type="checkbox" name="fm[id][]" value="<?php echo $CM->id; ?>" onclick="mswSCG('.managearea .table td','delb')"></td>
                   <td><b><?php echo mswSH($CM->affName); ?></b>
                   <span class="smalldata">
                     <?php echo mswSH($CM->productName); ?>
                   </span>
                   </td>
                   <td data-sort-value="<?php echo $CM->ts; ?>"><?php echo $DT->datedisplay($SETTINGS, $CM->ts); ?></td>
                   <td data-sort-value="<?php echo ($CM->saletotal > 0 ? $CM->saletotal : '0.00'); ?>"><?php echo mswCRFMT(mswFPCE($CM->saletotal, true), $SETTINGS); ?></td>
                   <td data-sort-value="<?php echo ($CM->commtotal > 0 ? $CM->commtotal : '0.00'); ?>"><?php echo mswCRFMT(mswFPCE($CM->commtotal, true), $SETTINGS); ?></td>
                   <td>
                     <a href="?p=commissions-add&amp;id=<?php echo $CM->id; ?>&amp;aid=<?php echo $CM->affid; ?>&amp;rdr=<?php echo $cmd; ?>" title="<?php echo mswSH($msw_common4); ?>"><span class="fa-stack"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-pencil fa-stack-1x fa-inverse"></i></span></a>
                   </td>
                 </tr>
                 <?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 btngroups">
        <div class="btn-group">
          <button type="button" class="btn btn-info dropdown-toggle disabled" id="delb" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <i class="fa fa-chevron-down fa-fw"></i> <?php echo $msw_adm_commissions_approve2; ?>
          </button>
          <ul class="dropdown-menu">
            <li><a href="#" onclick="mswAction('<?php echo $cmd; ?>','.managepanel','no','yes');return false"><i class="fa fa-check fa-fw"></i> <?php echo $msw_adm_commissions_approve; ?></a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#" onclick="mswAction('<?php echo $cmd; ?>-del','.managepanel','no','yes');return false"><i class="fa fa-times fa-fw"></i> <?php echo $msw_common3; ?></a></li>
          </ul>
        </div>
      </div>
      <?php
      }
      ?>
      </form>
    </div>