<?php
/* Smarty version 4.5.6, created on 2025-12-22 20:25:51
  from '/var/www/html/tivi/panel/templates/users/list.tpl' */

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


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


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

<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl, "layout.tpl");
}
/* {block "content"} */
class Block_207846067369499b3f55da91_58347769 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_207846067369499b3f55da91_58347769',
  ),
);
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">Użytkownicy</h4>
            <p class="text-muted mb-0">
                <?php if ($_smarty_tpl->tpl_vars['isReseller']->value) {?>Zarządzaj swoimi użytkownikami<?php } else { ?>Zarządzaj użytkownikami systemu<?php }?>
            </p>
        </div>
        <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/users/add" class="btn btn-primary">
            <i class="bi bi-plus-lg me-1"></i>Dodaj użytkownika
        </a>
    </div>

        <?php if ($_smarty_tpl->tpl_vars['isReseller']->value && $_smarty_tpl->tpl_vars['resellerUsage']->value) {?>
    <div class="row mb-4">
        <div class="col-md-4">
            <div class="card bg-primary bg-opacity-10 border-primary">
                <div class="card-body py-3">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <small class="text-muted">Użytkownicy</small>
                            <h4 class="mb-0"><?php echo $_smarty_tpl->tpl_vars['resellerUsage']->value['users']['used'];?>
 / <?php echo $_smarty_tpl->tpl_vars['resellerUsage']->value['users']['max'];?>
</h4>
                        </div>
                        <i class="bi bi-people text-primary" style="font-size: 2rem;"></i>
                    </div>
                    <div class="progress mt-2" style="height: 5px;">
                        <div class="progress-bar bg-primary" style="width: <?php if ($_smarty_tpl->tpl_vars['resellerUsage']->value['users']['max'] > 0) {
echo round((float) ($_smarty_tpl->tpl_vars['resellerUsage']->value['users']['used']/$_smarty_tpl->tpl_vars['resellerUsage']->value['users']['max']*100), (int) 0, (int) 1);
} else { ?>0<?php }?>%"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card bg-success bg-opacity-10 border-success">
                <div class="card-body py-3">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <small class="text-muted">Urządzenia</small>
                            <h4 class="mb-0"><?php echo $_smarty_tpl->tpl_vars['resellerUsage']->value['devices']['used'];?>
 / <?php echo $_smarty_tpl->tpl_vars['resellerUsage']->value['devices']['max'];?>
</h4>
                            <small class="text-muted">
                                własne: <?php echo $_smarty_tpl->tpl_vars['resellerUsage']->value['devices']['own'];?>
, 
                                przydzielone: <?php echo $_smarty_tpl->tpl_vars['resellerUsage']->value['devices']['allocated'];?>

                                <br><span class="text-success">można dodać własnych: <?php echo $_smarty_tpl->tpl_vars['resellerUsage']->value['devices']['available_for_self'];?>
</span>
                            </small>
                        </div>
                        <i class="bi bi-tv text-success" style="font-size: 2rem;"></i>
                    </div>
                    <div class="progress mt-2" style="height: 5px;">
                        <div class="progress-bar bg-success" style="width: <?php if ($_smarty_tpl->tpl_vars['resellerUsage']->value['devices']['max'] > 0) {
echo round((float) ($_smarty_tpl->tpl_vars['resellerUsage']->value['devices']['used']/$_smarty_tpl->tpl_vars['resellerUsage']->value['devices']['max']*100), (int) 0, (int) 1);
} else { ?>0<?php }?>%"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card bg-info bg-opacity-10 border-info">
                <div class="card-body py-3">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <small class="text-muted">Playlisty</small>
                            <h4 class="mb-0"><?php echo $_smarty_tpl->tpl_vars['resellerUsage']->value['playlists']['used'];?>
 / <?php echo $_smarty_tpl->tpl_vars['resellerUsage']->value['playlists']['max'];?>
</h4>
                            <small class="text-muted">
                                własne: <?php echo $_smarty_tpl->tpl_vars['resellerUsage']->value['playlists']['own'];?>
, 
                                przydzielone: <?php echo $_smarty_tpl->tpl_vars['resellerUsage']->value['playlists']['allocated'];?>

                                <br><span class="text-info">można dodać własnych: <?php echo $_smarty_tpl->tpl_vars['resellerUsage']->value['playlists']['available_for_self'];?>
</span>
                            </small>
                        </div>
                        <i class="bi bi-list-ul text-info" style="font-size: 2rem;"></i>
                    </div>
                    <div class="progress mt-2" style="height: 5px;">
                        <div class="progress-bar bg-info" style="width: <?php if ($_smarty_tpl->tpl_vars['resellerUsage']->value['playlists']['max'] > 0) {
echo round((float) ($_smarty_tpl->tpl_vars['resellerUsage']->value['playlists']['used']/$_smarty_tpl->tpl_vars['resellerUsage']->value['playlists']['max']*100), (int) 0, (int) 1);
} else { ?>0<?php }?>%"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php }?>

    <!-- Filters -->
    <div class="card mb-4">
        <div class="card-body">
            <form method="get" class="row g-3">
                <div class="col-md-8">
                    <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="Szukaj użytkownika..." value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['search']->value ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
">
                    </div>
                </div>
                <div class="col-md-4">
                    <button type="submit" class="btn btn-secondary w-100">
                        <i class="bi bi-filter me-1"></i>Filtruj
                    </button>
                </div>
            </form>
        </div>
    </div>

    <!-- Users 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>ID</th>
                            <th>Użytkownik</th>
                            <th>Rola</th>
                            <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?><th>Reseller</th><?php }?>
                            <th>Urządzenia</th>
                            <th>Playlisty</th>
                            <th>Notatki</th>
                            <th>Status</th>
                            <th>Ostatnie logowanie</th>
                            <th class="text-end">Akcje</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?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;
?>
                        <tr>
                            <td><span class="text-muted">#<?php echo $_smarty_tpl->tpl_vars['user']->value['id'];?>
</span></td>
                            <td>
                                <strong><?php echo $_smarty_tpl->tpl_vars['user']->value['username'];?>
</strong>
                            </td>
                            <td>
                                <?php if ($_smarty_tpl->tpl_vars['user']->value['role'] == 'admin') {?>
                                <span class="badge bg-danger"><i class="bi bi-shield-check me-1"></i>Admin</span>
                                <?php } elseif ($_smarty_tpl->tpl_vars['user']->value['role'] == 'reseller') {?>
                                <span class="badge bg-primary"><i class="bi bi-shop me-1"></i>Reseller</span>
                                <?php } else { ?>
                                <span class="badge bg-secondary"><i class="bi bi-person me-1"></i>User</span>
                                <?php }?>
                            </td>
                            <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>
                            <td>
                                <?php if ($_smarty_tpl->tpl_vars['user']->value['parent_username']) {?>
                                <span class="text-muted"><?php echo $_smarty_tpl->tpl_vars['user']->value['parent_username'];?>
</span>
                                <?php } else { ?>
                                <span class="text-muted">-</span>
                                <?php }?>
                            </td>
                            <?php }?>
                            <td>
                                <?php if ($_smarty_tpl->tpl_vars['user']->value['role'] == 'admin') {?>
                                <span class="badge bg-secondary">∞</span>
                                <?php } elseif ($_smarty_tpl->tpl_vars['user']->value['role'] == 'reseller') {?>
                                                                <span class="badge bg-info" title="własne: <?php echo $_smarty_tpl->tpl_vars['user']->value['devices_count'];?>
, przydzielone: <?php echo $_smarty_tpl->tpl_vars['user']->value['devices_allocated'];?>
"><?php echo $_smarty_tpl->tpl_vars['user']->value['devices_count']+$_smarty_tpl->tpl_vars['user']->value['devices_allocated'];?>
/<?php echo $_smarty_tpl->tpl_vars['user']->value['max_devices'];?>
</span>
                                <?php } else { ?>
                                <span class="badge bg-info"><?php echo $_smarty_tpl->tpl_vars['user']->value['devices_count'];?>
/<?php echo $_smarty_tpl->tpl_vars['user']->value['device_limit'];?>
</span>
                                <?php }?>
                            </td>
                            <td>
                                <?php if ($_smarty_tpl->tpl_vars['user']->value['role'] == 'admin') {?>
                                <span class="badge bg-secondary">∞</span>
                                <?php } elseif ($_smarty_tpl->tpl_vars['user']->value['role'] == 'reseller') {?>
                                                                <span class="badge bg-info" title="własne: <?php echo $_smarty_tpl->tpl_vars['user']->value['playlists_count'];?>
, przydzielone: <?php echo $_smarty_tpl->tpl_vars['user']->value['playlists_allocated'];?>
"><?php echo $_smarty_tpl->tpl_vars['user']->value['playlists_count']+$_smarty_tpl->tpl_vars['user']->value['playlists_allocated'];?>
/<?php echo $_smarty_tpl->tpl_vars['user']->value['max_playlists'];?>
</span>
                                <?php } else { ?>
                                <span class="badge bg-info"><?php echo (($tmp = $_smarty_tpl->tpl_vars['user']->value['playlists_count'] ?? null)===null||$tmp==='' ? 0 ?? null : $tmp);?>
/<?php echo (($tmp = $_smarty_tpl->tpl_vars['user']->value['playlist_limit'] ?? null)===null||$tmp==='' ? 100 ?? null : $tmp);?>
</span>
                                <?php }?>
                            </td>
                            <td>
                                <span class="badge bg-secondary notes-badge" 
                                      style="cursor:pointer;"
                                      data-entity-type="user" 
                                      data-entity-id="<?php echo $_smarty_tpl->tpl_vars['user']->value['id'];?>
"
                                      onclick="NotesManager.open('user', <?php echo $_smarty_tpl->tpl_vars['user']->value['id'];?>
, '<?php echo strtr((string)$_smarty_tpl->tpl_vars['user']->value['username'], 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['user']->value['notes_count'] ?? null)===null||$tmp==='' ? 0 ?? null : $tmp);?>
</span>
                                </span>
                            </td>
                            <td>
                                <?php if ($_smarty_tpl->tpl_vars['user']->value['is_active']) {?>
                                <span class="badge bg-success">Aktywny</span>
                                <?php } else { ?>
                                <span class="badge bg-danger">Nieaktywny</span>
                                <?php }?>
                            </td>
                            <td>
                                <?php if ($_smarty_tpl->tpl_vars['user']->value['last_login']) {?>
                                <?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['user']->value['last_login'],"%d.%m.%Y %H:%M");?>

                                <?php } else { ?>
                                <span class="text-muted">Nigdy</span>
                                <?php }?>
                            </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('user', <?php echo $_smarty_tpl->tpl_vars['user']->value['id'];?>
, '<?php echo strtr((string)$_smarty_tpl->tpl_vars['user']->value['username'], 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;?>
/devices?user_id=<?php echo $_smarty_tpl->tpl_vars['user']->value['id'];?>
" class="btn btn-sm btn-outline-info" title="Urządzenia">
                                        <i class="bi bi-tv"></i>
                                    </a>
                                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/users/edit?id=<?php echo $_smarty_tpl->tpl_vars['user']->value['id'];?>
" class="btn btn-sm btn-outline-primary" title="Edytuj">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                    <button type="button" class="btn btn-sm btn-outline-warning reset-password-btn" 
                                            title="Reset hasła"
                                            data-id="<?php echo $_smarty_tpl->tpl_vars['user']->value['id'];?>
"
                                            data-username="<?php echo $_smarty_tpl->tpl_vars['user']->value['username'];?>
">
                                        <i class="bi bi-key"></i>
                                    </button>
                                    <?php if ($_smarty_tpl->tpl_vars['user']->value['id'] != $_smarty_tpl->tpl_vars['currentUser']->value['id']) {?>
                                    <button type="button" class="btn btn-sm btn-outline-danger delete-user-btn" 
                                            title="Usuń"
                                            data-id="<?php echo $_smarty_tpl->tpl_vars['user']->value['id'];?>
"
                                            data-username="<?php echo $_smarty_tpl->tpl_vars['user']->value['username'];?>
"
                                            data-role="<?php echo $_smarty_tpl->tpl_vars['user']->value['role'];?>
">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                    <?php }?>
                                </div>
                            </td>
                        </tr>
                        <?php
}
if ($_smarty_tpl->tpl_vars['user']->do_else) {
?>
                        <tr>
                            <td colspan="<?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>10<?php } else { ?>9<?php }?>" class="text-center py-5">
                                <div class="text-muted mb-3">
                                    <i class="bi bi-people" style="font-size: 3rem;"></i>
                                </div>
                                <p class="mb-0">Brak użytkowników</p>
                            </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>
                <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;
if ($_smarty_tpl->tpl_vars['search']->value) {?>&search=<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['search']->value, ENT_QUOTES, 'UTF-8', true);
}?>">
                            <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;
if ($_smarty_tpl->tpl_vars['search']->value) {?>&search=<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['search']->value, ENT_QUOTES, 'UTF-8', true);
}?>"><?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;
if ($_smarty_tpl->tpl_vars['search']->value) {?>&search=<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['search']->value, ENT_QUOTES, 'UTF-8', true);
}?>">
                            <i class="bi bi-chevron-right"></i>
                        </a>
                    </li>
                </ul>
            </nav>
        </div>
        <?php }?>
    </div>
</div>

<!-- Hidden forms -->
<form id="deleteUserForm" method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/users/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="deleteUserId">
</form>
<form id="resetPasswordForm" method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/users/reset-password" style="display:none;">
    <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
    <input type="hidden" name="id" id="resetUserId">
    <input type="hidden" name="new_password" id="resetPassword">
</form>
<?php
}
}
/* {/block "content"} */
/* {block "scripts"} */
class Block_499460369499b3f576ac3_76547200 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'scripts' => 
  array (
    0 => 'Block_499460369499b3f576ac3_76547200',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>


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

    // Delete user
    document.querySelectorAll('.delete-user-btn').forEach(function(btn) {
        btn.addEventListener('click', function() {
            var id = this.dataset.id;
            var username = this.dataset.username;
            var role = this.dataset.role;
            
            var warning = '';
            if (role === 'reseller') {
                warning = '<br><br><span class="text-warning"><i class="bi bi-exclamation-triangle me-1"></i>To jest reseller - zostaną usunięci również wszyscy jego użytkownicy!</span>';
            }

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

    // Reset password
    document.querySelectorAll('.reset-password-btn').forEach(function(btn) {
        btn.addEventListener('click', function() {
            var id = this.dataset.id;
            var username = this.dataset.username;

            Swal.fire({
                title: 'Reset hasła',
                html: '<p>Resetujesz hasło dla użytkownika: <strong>' + username + '</strong></p>' +
                    '<div class="mb-3 text-start">' +
                    '<label class="form-label">Nowe hasło</label>' +
                    '<input type="password" id="swal-password" class="form-control" minlength="6" placeholder="Minimum 6 znaków">' +
                    '</div>',
                icon: 'question',
                showCancelButton: true,
                confirmButtonText: 'Resetuj hasło',
                cancelButtonText: 'Anuluj',
                confirmButtonColor: '#ffc107',
                background: swalConfig.background,
                color: swalConfig.color,
                preConfirm: function() {
                    var password = document.getElementById('swal-password').value;
                    if (!password || password.length < 6) {
                        Swal.showValidationMessage('Hasło musi mieć minimum 6 znaków');
                        return false;
                    }
                    return password;
                }
            }).then(function(result) {
                if (result.isConfirmed) {
                    document.getElementById('resetUserId').value = id;
                    document.getElementById('resetPassword').value = result.value;
                    document.getElementById('resetPasswordForm').submit();
                }
            });
        });
    });
})();
<?php echo '</script'; ?>
>

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