 <? global $config, $gdb, $mdb, $user;?>
<div class="panel panel-info panel-border top">
  <div class="panel-heading">
    <span class="panel-title">Lista klientów</span>
  </div>
  <div class="panel-body">
    <?
      $grid = new \grid( 'pro_rr_clients', 'reseller-clients' );
      $grid -> sql          = 'SELECT '
                                  . 'id, login, enabled, last_logged, type '
                                . 'FROM '
                                  . 'pro_rr_clients AS prc '
                                . '[where] '
                                . 'ORDER BY '
                                  . '[order_p1] [order_p2]';
      $grid -> sql_count    = 'SELECT '
                                  . 'COUNT(0) '
                                . 'FROM '
                                  . 'pro_rr_clients '
                                . '[where] ';
      $grid -> debug        = true;
      $grid -> gdb_opt      = $gdb;
      $grid -> search       = [
                                [ 'name' => 'Login', 'db' => 'login', 'type' => 'text' ]
                              ];
      $grid -> order        = [ 'column' => 'last_logged', 'type' => 'DESC' ];
      $grid -> columns_view = [
                                [ 
                                  'name' => 'Lp.',
                                  'th' => [ 'class' => 'g-lp' ],
                                  'td' => [ 'class' => 'g-center' ],
                                  'autoincrement' => true 
                                ],
                                [
                                  'name' => 'Ost. logowanie',
                                  'db' => 'last_logged',
                                  'th' => [ 'style' => 'width: 120px; text-align: center;' ],
                                  'td' => [ 'style' => 'text-align: center;' ],
                                  'date_mod' => 'Y-m-d H:i',
                                  'sort' => true
                                ],
                                [
                                  'name' => 'Login',
                                  'db' => 'login',
                                  'sort' => true
                                ],
                                [ 
                                  'name' => 'Typ',
                                  'th' => [ 'style' => 'width: 120px; text-align: center;' ],
                                  'td' => [ 'style' => 'text-align: center;' ],
                                  'db' => 'type',
                                  'replace' => [ 
                                                  'array' => [ 
                                                      0 => 'klient',
                                                      1 => 'reseller',
                                                      2 => 'pracownik'
                                                    ] 
                                                  ],
                                  'sort' => true
                                ],
                                [ 
                                  'name' => 'Aktywny',
                                  'th' => [ 'style' => 'width: 120px; text-align: center;' ],
                                  'td' => [ 'style' => 'text-align: center;' ],
                                  'db' => 'enabled',
                                  'replace' => [ 
                                                  'array' => [ 
                                                      0 => '<span class="text-danger">nie</span>',
                                                      1 => '<span class="text-primary">tak</span>'
                                                    ] 
                                                  ],
                                  'sort' => true
                                ],
                                [ 
                                  'name' => 'Akcja', 
                                  'action' => [ 'type' => 'edit', 'url' => '/?p=ranker_clients&rw=edit&id=[id]' ], 
                                  'th' => [ 'class' => 'g-center' ],
                                  'td' => [ 'class' => 'g-center', 'style' => 'width: 50px;' ]
                                ],
                                [ 
                                  'name' => 'Usuń', 
                                  'action' => [ 'type' => 'delete', 'url' => '/?p=ranker_clients&rw=del&id=[id]' ],
                                  'th' => [ 'class' => 'g-center' ], 
                                  'td' => [ 'class' => 'g-center', 'style' => 'width: 50px;' ]
                                ]
                              ];
      $grid -> buttons      = [
                                [
                                  'label' => 'Dodaj klienta',
                                  'class' => 'btn-success',
                                  'icon'  => 'fa-plus-circle mr5',
                                  'url'   => '/?p=ranker_clients&rw=add'
                                ]
                              ];
      $grid -> hide_columns = false;
      echo $grid -> draw();
    ?>
  </div>
</div>
<script type="text/javascript">
  $( document ).ready( function()
  {
    $( 'body' ).on( 'click', '#downloads-delete', function()
    {
      $.prompt( 'Na pewno chcesz usunąć pobrane linki?', { 
        title: 'Potwierdź?',
        submit: function(e,v,m,f) 
        { 
          if ( v === true )
            $( '#f-downloads-delete' ).submit();
        }, 
        buttons: { 
          'tak': true, 
          'nie': false 
        }, 
        focus: 0
      });
    });
  });
</script>