<?php
/* Smarty version 4.5.6, created on 2026-01-24 18:20:42
  from '/var/www/html/tivi/panel/templates/devices/list.tpl' */

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '4.5.6',
  'unifunc' => 'content_6974ff6a5f4d07_21738542',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    '5a8c45b42b731407c670caca89713483a6ece9f7' => 
    array (
      0 => '/var/www/html/tivi/panel/templates/devices/list.tpl',
      1 => 1769260007,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
  ),
),false)) {
function content_6974ff6a5f4d07_21738542 (Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_loadInheritance();
$_smarty_tpl->inheritance->init($_smarty_tpl, true);
?>


<?php 
$_smarty_tpl->inheritance->instanceBlock($_smarty_tpl, 'Block_6165019586974ff6a5dbe97_27732765', "content");
?>


<?php 
$_smarty_tpl->inheritance->instanceBlock($_smarty_tpl, 'Block_3412843666974ff6a5f4580_13941803', "scripts");
?>

<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl, "layout.tpl");
}
/* {block "content"} */
class Block_6165019586974ff6a5dbe97_27732765 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_6165019586974ff6a5dbe97_27732765',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_checkPlugins(array(0=>array('file'=>'/var/www/html/tivi/vendor/smarty/smarty/libs/plugins/modifier.date_format.php','function'=>'smarty_modifier_date_format',),));
?>

<div class="container-fluid">
    <!-- Header -->
    <div class="d-flex flex-wrap justify-content-between align-items-center mb-4">
        <div>
            <h4 class="mb-1">Urządzenia</h4>
            <p class="text-muted mb-0">
                <?php if (!$_smarty_tpl->tpl_vars['isAdmin']->value && !$_smarty_tpl->tpl_vars['isReseller']->value) {?>
                Twoje urządzenia: <?php echo $_smarty_tpl->tpl_vars['currentDevicesCount']->value;?>
/<?php echo $_smarty_tpl->tpl_vars['deviceLimit']->value;?>

                <?php } elseif ($_smarty_tpl->tpl_vars['filterUserId']->value == 'all') {?>
                Wszystkie urządzenia
                <?php } elseif ($_smarty_tpl->tpl_vars['filterUserId']->value && $_smarty_tpl->tpl_vars['filterUserId']->value != '') {?>
                Urządzenia użytkownika
                <?php } else { ?>
                Twoje urządzenia
                <?php }?>
            </p>
        </div>
        <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value || $_smarty_tpl->tpl_vars['isReseller']->value || $_smarty_tpl->tpl_vars['currentDevicesCount']->value < $_smarty_tpl->tpl_vars['deviceLimit']->value) {?>
        <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/devices/add<?php if ($_smarty_tpl->tpl_vars['filterUserId']->value && $_smarty_tpl->tpl_vars['filterUserId']->value != 'all') {?>?user_id=<?php echo $_smarty_tpl->tpl_vars['filterUserId']->value;
}?>" class="btn btn-primary">
            <i class="bi bi-plus-lg me-1"></i>Dodaj urządzenie
        </a>
        <?php }?>
    </div>

    <!-- Filters -->
    <div class="card mb-4">
        <div class="card-body">
            <form method="get" class="row g-3 align-items-end" id="filterForm">
                <div class="col-md-4">
                    <label class="form-label small text-muted">Szukaj</label>
                    <div class="input-group">
                        <span class="input-group-text"><i class="bi bi-search"></i></span>
                        <input type="text" name="search" class="form-control" placeholder="MAC, kod, nazwa..." value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['search']->value ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
">
                    </div>
                </div>
                
                <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value || $_smarty_tpl->tpl_vars['isReseller']->value) {?>
                <div class="col-md-4">
                    <label class="form-label small text-muted">Użytkownik</label>
                    <select name="user_id" class="form-select auto-submit">
                        <option value="">-- Moje --</option>
                        <option value="all" <?php if ($_smarty_tpl->tpl_vars['filterUserId']->value == 'all') {?>selected<?php }?>>Wszyscy</option>
                        <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['users']->value, 'user');
$_smarty_tpl->tpl_vars['user']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['user']->value) {
$_smarty_tpl->tpl_vars['user']->do_else = false;
?>
                        <option value="<?php echo $_smarty_tpl->tpl_vars['user']->value['id'];?>
" <?php if ($_smarty_tpl->tpl_vars['filterUserId']->value == $_smarty_tpl->tpl_vars['user']->value['id']) {?>selected<?php }?>><?php echo $_smarty_tpl->tpl_vars['user']->value['username'];?>
</option>
                        <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                    </select>
                </div>
                <?php }?>
                
                <div class="col-md-2">
                    <button type="submit" class="btn btn-secondary w-100">
                        <i class="bi bi-filter me-1"></i>Filtruj
                    </button>
                </div>
                
                <?php if ($_smarty_tpl->tpl_vars['search']->value || $_smarty_tpl->tpl_vars['filterUserId']->value) {?>
                <div class="col-auto">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/devices" class="btn btn-outline-secondary">
                        <i class="bi bi-x-lg"></i>
                    </a>
                </div>
                <?php }?>
            </form>
        </div>
    </div>

    <!-- Devices Table -->
    <div class="card">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead>
                        <tr>
                            <th>Nazwa</th>
                            <th>MAC</th>
                            <th>Kod</th>
                            <?php if (($_smarty_tpl->tpl_vars['isAdmin']->value || $_smarty_tpl->tpl_vars['isReseller']->value) && $_smarty_tpl->tpl_vars['filterUserId']->value == 'all') {?><th>Użytkownik</th><?php }?>
                            <th>Playlisty</th>
                            <th>Notatki</th>
                            <th>Status</th>
                            <th>Utworzony</th>
                            <th class="text-end">Akcje</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['devices']->value, 'device');
$_smarty_tpl->tpl_vars['device']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['device']->value) {
$_smarty_tpl->tpl_vars['device']->do_else = false;
?>
                        <tr>
                            <td>
                                <strong><?php echo (($tmp = $_smarty_tpl->tpl_vars['device']->value['name'] ?? null)===null||$tmp==='' ? 'Bez nazwy' ?? null : $tmp);?>
</strong>
                            </td>
                            <td><code class="user-select-all"><?php echo $_smarty_tpl->tpl_vars['device']->value['mac'];?>
</code></td>
                            <td><code class="user-select-all"><?php echo $_smarty_tpl->tpl_vars['device']->value['code'];?>
</code></td>
                            <?php if (($_smarty_tpl->tpl_vars['isAdmin']->value || $_smarty_tpl->tpl_vars['isReseller']->value) && $_smarty_tpl->tpl_vars['filterUserId']->value == 'all') {?>
                            <td>
                                <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/devices?user_id=<?php echo $_smarty_tpl->tpl_vars['device']->value['user_id'];?>
"><?php echo $_smarty_tpl->tpl_vars['device']->value['username'];?>
</a>
                            </td>
                            <?php }?>
                            <td>
                                <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/playlists?device_id=<?php echo $_smarty_tpl->tpl_vars['device']->value['id'];?>
" class="badge bg-info text-decoration-none">
                                    <?php echo $_smarty_tpl->tpl_vars['device']->value['playlists_count'];?>
 playlist
                                </a>
                            </td>
                            <td>
                                <span class="badge bg-secondary notes-badge" 
                                      style="cursor:pointer;"
                                      data-entity-type="device" 
                                      data-entity-id="<?php echo $_smarty_tpl->tpl_vars['device']->value['id'];?>
"
                                      onclick="NotesManager.open('device', <?php echo $_smarty_tpl->tpl_vars['device']->value['id'];?>
, '<?php echo strtr((string)(($tmp = $_smarty_tpl->tpl_vars['device']->value['name'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['device']->value['mac'] ?? null : $tmp), array("\\" => "\\\\", "'" => "\\'", "\"" => "\\\"", "\r" => "\\r", 
                       "\n" => "\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S",
                       "`" => "\\`", "\${" => "\\\$\{"));?>
')"
                                      title="Pokaż notatki">
                                    <i class="bi bi-sticky"></i> <span class="notes-count"><?php echo (($tmp = $_smarty_tpl->tpl_vars['device']->value['notes_count'] ?? null)===null||$tmp==='' ? 0 ?? null : $tmp);?>
</span>
                                </span>
                            </td>
                            <td>
                                <?php if ($_smarty_tpl->tpl_vars['device']->value['is_blocked']) {?>
                                <span class="badge bg-danger"><i class="bi bi-shield-x me-1"></i>Zablokowane</span>
                                <?php } else { ?>
                                <span class="badge bg-success"><i class="bi bi-check-circle me-1"></i>Aktywne</span>
                                <?php }?>
                            </td>
                            <td><?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['device']->value['created_at'],"%d.%m.%Y");?>
</td>
                            <td class="text-end">
                                <div class="btn-group">
                                    <button type="button" class="btn btn-sm btn-outline-secondary" 
                                            title="Dodaj notatkę"
                                            onclick="NotesManager.quickAdd('device', <?php echo $_smarty_tpl->tpl_vars['device']->value['id'];?>
, '<?php echo strtr((string)(($tmp = $_smarty_tpl->tpl_vars['device']->value['name'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['device']->value['mac'] ?? null : $tmp), array("\\" => "\\\\", "'" => "\\'", "\"" => "\\\"", "\r" => "\\r", 
                       "\n" => "\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S",
                       "`" => "\\`", "\${" => "\\\$\{"));?>
')">
                                        <i class="bi bi-sticky"></i>
                                    </button>
                                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/playlists/add?device_id=<?php echo $_smarty_tpl->tpl_vars['device']->value['id'];?>
" class="btn btn-sm btn-outline-success" title="Dodaj playlistę">
                                        <i class="bi bi-plus-lg"></i>
                                    </a>
                                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/playlists?device_id=<?php echo $_smarty_tpl->tpl_vars['device']->value['id'];?>
" class="btn btn-sm btn-outline-info" title="Playlisty">
                                        <i class="bi bi-list-ul"></i>
                                    </a>
                                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/settings/device?id=<?php echo $_smarty_tpl->tpl_vars['device']->value['id'];?>
" class="btn btn-sm btn-outline-secondary" title="Ustawienia">
                                        <i class="bi bi-sliders"></i>
                                    </a>
                                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/devices/edit?id=<?php echo $_smarty_tpl->tpl_vars['device']->value['id'];?>
" class="btn btn-sm btn-outline-primary" title="Edytuj">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                    <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>
                                    <button type="button" class="btn btn-sm btn-outline-warning toggle-block-btn" 
                                            title="<?php if ($_smarty_tpl->tpl_vars['device']->value['is_blocked']) {?>Odblokuj<?php } else { ?>Zablokuj<?php }?>"
                                            data-id="<?php echo $_smarty_tpl->tpl_vars['device']->value['id'];?>
"
                                            data-name="<?php echo (($tmp = $_smarty_tpl->tpl_vars['device']->value['name'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['device']->value['mac'] ?? null : $tmp);?>
"
                                            data-blocked="<?php echo $_smarty_tpl->tpl_vars['device']->value['is_blocked'];?>
">
                                        <i class="bi bi-<?php if ($_smarty_tpl->tpl_vars['device']->value['is_blocked']) {?>unlock<?php } else { ?>lock<?php }?>"></i>
                                    </button>
                                    <?php }?>
                                    <button type="button" class="btn btn-sm btn-outline-danger delete-device-btn" 
                                            title="Usuń"
                                            data-id="<?php echo $_smarty_tpl->tpl_vars['device']->value['id'];?>
"
                                            data-name="<?php echo (($tmp = $_smarty_tpl->tpl_vars['device']->value['name'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['device']->value['mac'] ?? null : $tmp);?>
">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                        <?php
}
if ($_smarty_tpl->tpl_vars['device']->do_else) {
?>
                        <tr>
                            <td colspan="<?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>9<?php } else { ?>8<?php }?>" class="text-center py-5">>
                                <div class="text-muted mb-3">
                                    <i class="bi bi-tv" style="font-size: 3rem;"></i>
                                </div>
                                <p class="mb-3">Brak urządzeń</p>
                                <?php if (!$_smarty_tpl->tpl_vars['isAdmin']->value && $_smarty_tpl->tpl_vars['currentDevicesCount']->value < $_smarty_tpl->tpl_vars['deviceLimit']->value) {?>
                                <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/devices/add" class="btn btn-primary">
                                    <i class="bi bi-plus-lg me-1"></i>Dodaj pierwsze urządzenie
                                </a>
                                <?php }?>
                            </td>
                        </tr>
                        <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                    </tbody>
                </table>
            </div>
        </div>

        <?php if ($_smarty_tpl->tpl_vars['pagination']->value['total_pages'] > 1) {?>
        <div class="card-footer">
            <nav>
                                <?php $_smarty_tpl->_assignInScope('paginationParams', '');?>
                <?php if ($_smarty_tpl->tpl_vars['filterUserId']->value) {
$_smarty_tpl->_assignInScope('paginationParams', ((string)$_smarty_tpl->tpl_vars['paginationParams']->value)."&user_id=".((string)$_smarty_tpl->tpl_vars['filterUserId']->value));
}?>
                <?php if ($_smarty_tpl->tpl_vars['search']->value) {
ob_start();
echo rawurlencode((string)$_smarty_tpl->tpl_vars['search']->value);
$_prefixVariable1=ob_get_clean();
$_smarty_tpl->_assignInScope('paginationParams', ((string)$_smarty_tpl->tpl_vars['paginationParams']->value)."&search=".$_prefixVariable1);
}?>
                
                <ul class="pagination pagination-sm mb-0 justify-content-center">
                    <li class="page-item<?php if (!$_smarty_tpl->tpl_vars['pagination']->value['has_prev']) {?> disabled<?php }?>">
                        <a class="page-link" href="?page=<?php echo $_smarty_tpl->tpl_vars['pagination']->value['current_page']-1;
echo $_smarty_tpl->tpl_vars['paginationParams']->value;?>
">
                            <i class="bi bi-chevron-left"></i>
                        </a>
                    </li>
                    <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['pagination']->value['pages'], 'page');
$_smarty_tpl->tpl_vars['page']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['page']->value) {
$_smarty_tpl->tpl_vars['page']->do_else = false;
?>
                        <?php if ($_smarty_tpl->tpl_vars['page']->value === '...') {?>
                        <li class="page-item disabled"><span class="page-link">...</span></li>
                        <?php } else { ?>
                        <li class="page-item<?php if ($_smarty_tpl->tpl_vars['page']->value == $_smarty_tpl->tpl_vars['pagination']->value['current_page']) {?> active<?php }?>">
                            <a class="page-link" href="?page=<?php echo $_smarty_tpl->tpl_vars['page']->value;
echo $_smarty_tpl->tpl_vars['paginationParams']->value;?>
"><?php echo $_smarty_tpl->tpl_vars['page']->value;?>
</a>
                        </li>
                        <?php }?>
                    <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                    <li class="page-item<?php if (!$_smarty_tpl->tpl_vars['pagination']->value['has_next']) {?> disabled<?php }?>">
                        <a class="page-link" href="?page=<?php echo $_smarty_tpl->tpl_vars['pagination']->value['current_page']+1;
echo $_smarty_tpl->tpl_vars['paginationParams']->value;?>
">
                            <i class="bi bi-chevron-right"></i>
                        </a>
                    </li>
                </ul>
            </nav>
        </div>
        <?php }?>
    </div>
</div>

<!-- Hidden forms -->
<form id="deleteDeviceForm" method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/devices/delete" style="display:none;">
    <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
    <input type="hidden" name="id" id="deleteDeviceId">
</form>
<form id="toggleBlockForm" method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/devices/toggle-block" style="display:none;">
    <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
    <input type="hidden" name="id" id="toggleBlockId">
</form>
<?php
}
}
/* {/block "content"} */
/* {block "scripts"} */
class Block_3412843666974ff6a5f4580_13941803 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'scripts' => 
  array (
    0 => 'Block_3412843666974ff6a5f4580_13941803',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>


<?php echo '<script'; ?>
>
(function() {
    var swalConfig = {
        background: '#1a1d21',
        color: '#e1e1e1',
        confirmButtonColor: '#0d6efd',
        cancelButtonColor: '#6c757d'
    };

    // Delete device
    document.querySelectorAll('.delete-device-btn').forEach(function(btn) {
        btn.addEventListener('click', function() {
            var id = this.dataset.id;
            var name = this.dataset.name;

            Swal.fire({
                title: 'Potwierdź usunięcie',
                html: 'Czy na pewno chcesz usunąć urządzenie <strong>"' + name + '"</strong>?<br><br><span class="text-danger"><i class="bi bi-exclamation-triangle me-1"></i>Ta operacja usunie również wszystkie playlisty tego urządzenia!</span>',
                icon: 'warning',
                showCancelButton: true,
                confirmButtonText: 'Usuń',
                cancelButtonText: 'Anuluj',
                confirmButtonColor: '#dc3545',
                background: swalConfig.background,
                color: swalConfig.color
            }).then(function(result) {
                if (result.isConfirmed) {
                    document.getElementById('deleteDeviceId').value = id;
                    document.getElementById('deleteDeviceForm').submit();
                }
            });
        });
    });

    // Toggle block
    document.querySelectorAll('.toggle-block-btn').forEach(function(btn) {
        btn.addEventListener('click', function() {
            var id = this.dataset.id;
            var name = this.dataset.name;
            var isBlocked = this.dataset.blocked === '1';
            var actionText = isBlocked ? 'odblokować' : 'zablokować';

            Swal.fire({
                title: (isBlocked ? 'Odblokowanie' : 'Blokowanie') + ' urządzenia',
                html: 'Czy na pewno chcesz ' + actionText + ' urządzenie <strong>"' + name + '"</strong>?',
                icon: 'question',
                showCancelButton: true,
                confirmButtonText: isBlocked ? 'Odblokuj' : 'Zablokuj',
                cancelButtonText: 'Anuluj',
                confirmButtonColor: isBlocked ? '#198754' : '#ffc107',
                background: swalConfig.background,
                color: swalConfig.color
            }).then(function(result) {
                if (result.isConfirmed) {
                    document.getElementById('toggleBlockId').value = id;
                    document.getElementById('toggleBlockForm').submit();
                }
            });
        });
    });
    
    // Auto-submit przy zmianie filtrów
    document.querySelectorAll('.auto-submit').forEach(function(el) {
        el.addEventListener('change', function() {
            document.getElementById('filterForm').submit();
        });
    });
})();
<?php echo '</script'; ?>
>

<?php
}
}
/* {/block "scripts"} */
}
