<?php
global $gdb;

$grid = new \grid( 'shop_producer' );
$grid -> gdb_opt  = $gdb;
$grid -> sql = 'SELECT *'
                . 'FROM ( '
                  . 'SELECT '
                    . 'id, name, status, img '
                  . 'FROM '
                    . 'pp_shop_producer '
                  . ') AS q1 '
              . 'WHERE '
                . '1=1 [where] '
              . 'ORDER BY '
                . '[order_p1] [order_p2]';
$grid -> sql_count = 'SELECT '
                      . 'COUNT(0) FROM ( '
                        . 'SELECT '
                          . 'id, name, status, img '
                        . 'FROM '
                          . 'pp_shop_producer '
                      . ') AS q1 '
                    . 'WHERE '
                      . '1=1 [where] ';
$grid -> debug        = true;
$grid -> order        = [ 'column' => 'name', 'type' => 'ASC' ];
$grid -> search       = [
                            [ 'name' => 'Nazwa', 'db' => 'name', 'type' => 'text' ],
                            [ 'name' => 'Aktywny', 'db' => 'status', 'type' => 'select', 'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ] ]
                        ];
$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=\'/admin/shop_producer/edit/id=[id]\'>[name]</a>";'
                          ], [
                            'name' => 'Logo',
                            'db' => 'img'
                          ], [
                            'name' => 'Aktywny',
                            'db' => 'status',
                            'replace' => [ 'array' => [ 0 => '<span style="color: #FF0000;">nie</span>', 1 => 'tak' ] ],
                            'td' => [ 'class' => 'g-center' ],
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ],
                            'sort' => true
                          ], [
                            'name' => 'Edytuj',
                            'action' => [ 'type' => 'edit', 'url' => '/admin/shop_producer/edit/id=[id]' ],
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
                            'td' => [ 'class' => 'g-center' ]
                          ], [
                            'name' => 'Usuń',
                            'action' => [ 'type' => 'delete', 'url' => '/admin/shop_producer/delete/id=[id]' ],
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
                            'td' => [ 'class' => 'g-center' ]
                          ]
                        ];
$grid -> buttons      = [
                          [
                            'label' => 'Dodaj producenta',
                            'url' => '/admin/shop_producer/edit/',
                            'icon' => 'fa-plus-circle',
                            'class' => 'btn-success'
                          ]
                        ];
echo $grid -> draw();