<?php
global $gdb;

$grid = new \grid( 'pp_backups' );
$grid -> gdb_opt      = $gdb;
$grid -> src          = $this -> backups;
$grid -> debug        = true;
$grid -> order        = [ 'column' => 'name', 'type' => 'DESC' ];
$grid -> columns_view = [
                          [ 
                            'name' => 'Lp.',
                            'th' => [ 'class' => 'g-lp' ],
                            'td' => [ 'class' => 'g-center' ],
                            'autoincrement' => true 
                          ],
                          [
                            'name'  => 'Nazwa',
                            'db'    => 'name',
                            'sort'  => true,
                            'php'   => 'echo "<a href=\'/../backups/[name]\' target=\'_blank\'>[name]</a>";'
                          ],
                          [ 
                            'name' => 'Usuń', 
                            'action' => [ 'type' => 'delete', 'url' => '/admin/backups/backup_delete/name=[name]' ], 
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
                            'td' => [ 'class' => 'g-center' ]
                          ]
                        ];
$grid -> buttons      = [
                          [ 
                            'label' => 'Utwórz kopie zapasową', 
                            'url'   => '#', 
                            'icon'  => 'fa-plus-circle',
                            'class' => 'confirm btn btn-success btn-sm mr5"'
                          ],
                          [ 
                            'label' => 'Pobierz plik restore.php', 
                            'url'   => '/admin/backups/download_restore_file/', 
                            'icon'  => 'fa-download',
                            'class' => 'btn btn-system btn-sm mr5"'
                          ]
                        ];
echo $grid -> draw();
?>
<script>
  $(document).ready(function ()
  {
    $('body').on('click', '.confirm', function ()
    {
      $.prompt('Na pewno chcesz utworzyć kopię zapasową ?',
      {
        title: 'Potwierdź utworzenie',
        submit: function (e, v, m, f)
        {
          if ( v === true)
            document.location.href = '/admin/backups/backup_save/';
        },
        buttons: {
          'tak': true, 'nie': false
        },
        focus: 1
      });
    });
  });
</script>  