<?php
global $gdb;

$grid = new \grid( 'pp_shop_coupon' );
$grid -> gdb_opt      = $gdb;
$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' ] ] ],
                            [ 'name' => 'Użyty', 'db' => 'used', 'type' => 'select', 'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ] ],
                            [ 'name' => 'Wysłany', 'db' => 'send', 'type' => 'select', 'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ] ]
                        ];
$grid -> columns_view = [
                          [
                            'name' => 'Lp.',
                            'th' => [ 'class' => 'g-lp' ],
                            'td' => [ 'class' => 'g-center' ],
                            'autoincrement' => true
                          ], [
                            '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' => 'Użyto X razy',
                            'db' => 'used_count',
                            'td' => [ 'class' => 'g-center' ],
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ],
                          ], [
                            'name' => 'Nazwa',
                            'db' => 'name',
                            'sort' => true,
                            'php' => 'echo "<a href=\'/admin/shop_coupon/coupon_edit/id=[id]\'>[name]</a>";'
                          ], [
                            'name' => 'Typ kuponu',
                            'db' => 'type',
                            'replace' => [ 'array' => [ 1 => 'Rabat procentowy na koszyk' ] ]
                          ], [
                            'name' => 'Wartość',
                            'db' => 'amount',
                            'php' => 'if ( [type] == 1 ) echo "[amount]%";'
                          ], [
                            'name' => 'Kupon jednorazowy',
                            'db' => 'one_time',
                            'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ],
                            'td' => [ 'class' => 'g-center' ],
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ]
                          ], [
                            'name' => 'Wysłany',
                            'db' => 'send',
                            'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ],
                            'td' => [ 'class' => 'g-center' ],
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ]
                          ], [
                            'name' => 'Użyty',
                            'db' => 'used',
                            'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ],
                            'td' => [ 'class' => 'g-center' ],
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ]
                          ], [
                            'name' => 'Data użycia',
                            'db' => 'date_used',
                            'td' => [ 'class' => 'g-center' ],
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ]
                          ], [
                            'name' => 'Edytuj',
                            'action' => [ 'type' => 'edit', 'url' => '/admin/shop_coupon/coupon_edit/id=[id]' ],
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
                            'td' => [ 'class' => 'g-center' ]
                          ], [
                            'name' => 'Usuń',
                            'action' => [ 'type' => 'delete', 'url' => '/admin/shop_coupon/coupon_delete/id=[id]' ],
                            'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
                            'td' => [ 'class' => 'g-center' ]
                          ]
                        ];
$grid -> buttons = [
                    [
                      'label' => 'Dodaj kupon',
                      'url'   => '/admin/shop_coupon/coupon_edit/',
                      'icon'  => 'fa-plus-circle',
                      'class' => 'btn-success'
                    ]
                  ];
echo $grid -> draw();