<?php if(!defined('PARENT')) { exit; } ?>

    <div id="sparams"<?php echo (isset($_GET['sf']) ? ' style="display:none"' : ''); ?>>
      <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
          <ul class="nav nav-tabs">
            <li class="active"><a href="#one" data-toggle="tab"><i class="fa fa-bar-chart fa-fw"></i> <span class="hidden-xs"><?php echo $msw_adm_commissions_search2; ?></span></a></li>
            <li><a href="#two" data-toggle="tab"><i class="fa fa-cube fa-fw"></i> <span class="hidden-xs"><?php echo $msw_adm_commissions_search5; ?></span></a></li>
            <li><a href="#three" data-toggle="tab"><i class="fa fa-users fa-fw"></i> <span class="hidden-xs"><?php echo $msw_adm_commissions_search6; ?></span></a></li>
            <li><a href="#four" data-toggle="tab"><i class="fa fa-file-text-o fa-fw"></i> <span class="hidden-xs"><?php echo $msw_adm_commissions_search3; ?></span></a></li>
            <li><a href="#five" data-toggle="tab"><i class="fa fa-cog fa-fw"></i> <span class="hidden-xs"><?php echo $msw_adm_commissions_search4; ?></span></a></li>
          </ul>
        </div>
      </div>

      <form method="get" action="index.php">
      <div class="row formarea">
        <input type="hidden" name="p" value="<?php echo $cmd; ?>">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
          <div class="tab-content">
            <div class="tab-pane active in" id="one">
              <div class="panel panel-default">
                <div class="panel-body">
                  <div class="form-group">
                    <label><?php echo $msw_adm_commissions_search7; ?></label>
                    <input type="text" class="form-control" name="sf" value="<?php echo (isset($_GET['sf']) ? mswSH($_GET['sf']) : ''); ?>" onkeyup="mswFormat('decimal', this)">
                    <input type="text" class="form-control" name="st" value="<?php echo (isset($_GET['st']) ? mswSH($_GET['st']) : ''); ?>" style="margin-top:5px" onkeyup="mswFormat('decimal', this)">
                  </div>
                  <div class="form-group">
                    <label><?php echo $msw_adm_commissions_search8; ?></label>
                    <input type="text" class="form-control" name="cf" value="<?php echo (isset($_GET['cf']) ? mswSH($_GET['cf']) : ''); ?>" onkeyup="mswFormat('decimal', this)">
                    <input type="text" class="form-control" name="ct" value="<?php echo (isset($_GET['ct']) ? mswSH($_GET['ct']) : ''); ?>" style="margin-top:5px" onkeyup="mswFormat('decimal', this)">
                  </div>
                </div>
              </div>
            </div>
            <div class="tab-pane fade" id="two">
              <div class="panel panel-default">
                <div class="panel-body">
                  <div class="checkbox">
                    <label><input type="checkbox" value="all" onclick="mswSC('#two .boxes')"><i class="fa fa-list fa-fw"></i></label>
                  </div>
                  <div class="boxes">
                    <?php
                    $Q = $DB->db_query("SELECT `id`,`name` FROM `" . DB_PREFIX . "products` WHERE `en` = 'yes' ORDER BY `name`");
                    while ($P = $DB->db_object($Q)) {
                    ?>
                    <div class="checkbox">
                      <label><input type="checkbox" name="prod[]" value="<?php echo $P->id; ?>"<?php echo (isset($_GET['prod']) && in_array($P->id, $_GET['prod']) ? ' checked="checked"' : ''); ?>><?php echo mswCD($P->name); ?></label>
                    </div>
                    <?php
                    }
                    ?>
                  </div>
                </div>
              </div>
            </div>
            <div class="tab-pane fade" id="three">
              <div class="panel panel-default">
                <div class="panel-body">
                  <div class="checkbox">
                    <label><input type="checkbox" value="all" onclick="mswSC('#three .boxes')"><i class="fa fa-list fa-fw"></i></label>
                  </div>
                  <div class="boxes">
                    <?php
                    $Q = $DB->db_query("SELECT `id`,`fname`,`lname` FROM `" . DB_PREFIX . "affiliates` WHERE `en` = 'yes' AND `approved` = 'yes' ORDER BY `fname`,`lname`");
                    while ($A = $DB->db_object($Q)) {
                    ?>
                    <div class="checkbox">
                      <label><input type="checkbox" name="aff[]" value="<?php echo $A->id; ?>"<?php echo (isset($_GET['aff']) && in_array($A->id, $_GET['aff']) ? ' checked="checked"' : ''); ?>><?php echo mswCD($A->fname . ' ' . $A->lname); ?></label>
                    </div>
                    <?php
                    }
                    ?>
                  </div>
                </div>
              </div>
            </div>
            <div class="tab-pane fade" id="four">
              <div class="panel panel-default">
                <div class="panel-body">
                  <div class="form-group">
                    <label><?php echo $msw_adm_commissions_search9; ?></label>
                    <div class="form-group input-group" style="margin-bottom:5px">
                      <span class="input-group-addon"><i class="fa fa-calendar fa-fw"></i></span>
                      <input type="text" class="form-control mswdatepicker" name="tsf" value="<?php echo (isset($_GET['tsf']) ? mswSH($_GET['tsf']) : ''); ?>">
                    </div>
                    <div class="form-group input-group">
                      <span class="input-group-addon"><i class="fa fa-calendar fa-fw"></i></span>
                      <input type="text" class="form-control mswdatepicker" name="tst" value="<?php echo (isset($_GET['tst']) ? mswSH($_GET['tst']) : ''); ?>">
                    </div>
                  </div>
                  <div class="form-group">
                    <label><?php echo $msw_adm_commissions_search10; ?></label>
                    <input type="text" class="form-control" name="notes" value="<?php echo (isset($_GET['notes']) ? mswSH($_GET['notes']) : ''); ?>">
                  </div>
                </div>
              </div>
            </div>
            <div class="tab-pane fade" id="five">
              <div class="panel panel-default">
                <div class="panel-body">
                  <div class="form-group">
                    <label><?php echo $msw_adm_commissions_search11; ?></label>
                    <select name="sort" class="form-control">
                      <?php
                      foreach ($msw_adm_commissions_search_sort AS $k => $v) {
                      ?>
                      <option value="<?php echo $k; ?>"<?php echo (isset($_GET['sort']) && $_GET['sort'] == $k ? ' selected="selected"' : ''); ?>><?php echo $v; ?></option>
                      <?php
                      }
                      ?>
                    </select>
                  </div>
                  <div class="form-group">
                    <label><?php echo $msw_adm_commissions_search12; ?></label>
                    <input type="text" class="form-control" name="show" value="<?php echo (isset($_GET['show']) ? (int) $_GET['show'] : PER_PAGE); ?>">
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="act-button">
        <button type="submit" class="btn btn-success"><i class="fa fa-search fa-fw"></i> <span class="hidden-xs"><?php echo $msw_adm_commissions_search; ?></span></button>
      </div>
      </form>
    </div>

    <?php
    // Search results..
    ?>
    <div id="sresults"<?php echo (!isset($_GET['sf']) ? ' style="display:none"' : ''); ?>>
      <?php
      if (!empty($search_sql) && isset($_GET['sf'])) {
        $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`
              " . implode(mswNL(), $search_sql) . "
              ORDER BY $orderBy
              LIMIT $limit," . (defined('PER_PAGE_SET') ? PER_PAGE_SET : 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="#" onclick="mswNewSearch();return false"><i class="fa fa-search fa-fw"></i> <?php echo $msw_adm_commissions_search14; ?></a></li>
                <?php
                if ($NR > 0) {
                ?>
                <li><a href="#" onclick="mswExp('<?php echo (isset($_SERVER['QUERY_STRING']) ? '&amp;' . mswSH($_SERVER['QUERY_STRING']) : ''); ?>','commissions-export');return false"><i class="fa fa-save fa-fw"></i> <?php echo $msw_adm_commissions_search13; ?></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_search15; ?> (<?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)) {
                       include(PATH . 'content/list-screens/commissions-manage.php');
                     }
                   } else {
                     $colspan = 6;
                     include(PATH . 'content/no-data.php');
                   }
                   ?>
                 </tbody>
               </table>
             </div>
             <?php
             // Pagination..
             if ($NR > (defined('PER_PAGE_SET') ? PER_PAGE_SET : PER_PAGE)) {
               $PGS = new pages(array(
                 'count' => $NR,
                 'text' => $msw_pages,
                 'page' => $page,
                 'admin' => 'yes',
                 'flag' => '',
                 'limit' => (defined('PER_PAGE_SET') ? PER_PAGE_SET : 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('commissions-manage-del','.managepanel','no','yes')}"><i class="fa fa-times fa-fw"></i> <span class="hidden-xs"><?php echo $msw_common3; ?></span></button>
          </div>
          <?php
          }
          ?>
          </form>
        </div>
        <?php
      }
      ?>

    </div>