<?php
/* Smarty version 4.5.6, created on 2025-12-24 19:06:18
  from '/var/www/html/tivi/panel/templates/users/form.tpl' */

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


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


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

<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl, "layout.tpl");
}
/* {block "content"} */
class Block_1506506774694c2b9a9a6290_34054640 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_1506506774694c2b9a9a6290_34054640',
  ),
);
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">
    <div class="row justify-content-center">
        <div class="col-lg-6">
            <!-- Header -->
            <div class="d-flex align-items-center mb-4">
                <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/users" class="btn btn-outline-secondary me-3">
                    <i class="bi bi-arrow-left"></i>
                </a>
                <div>
                    <h4 class="mb-1"><?php echo $_smarty_tpl->tpl_vars['pageTitle']->value;?>
</h4>
                    <p class="text-muted mb-0">
                        <?php if ($_smarty_tpl->tpl_vars['isEdit']->value) {?>Edytuj dane użytkownika<?php } else { ?>Utwórz nowe konto użytkownika<?php }?>
                    </p>
                </div>
            </div>

                        <?php if ($_smarty_tpl->tpl_vars['isReseller']->value && $_smarty_tpl->tpl_vars['availableLimits']->value) {?>
            <div class="alert alert-info mb-4">
                <i class="bi bi-info-circle me-2"></i>
                <strong>Dostępne limity:</strong>
                Użytkownicy: <?php echo $_smarty_tpl->tpl_vars['availableLimits']->value['users'];?>
, 
                Urządzenia: <?php echo $_smarty_tpl->tpl_vars['availableLimits']->value['devices'];?>
, 
                Playlisty: <?php echo $_smarty_tpl->tpl_vars['availableLimits']->value['playlists'];?>

            </div>
            <?php }?>

            <!-- Form Card -->
            <div class="card">
                <div class="card-body">
                    <?php if ((($tmp = $_smarty_tpl->tpl_vars['error']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp)) {?>
                    <div class="alert alert-danger">
                        <i class="bi bi-exclamation-circle me-2"></i><?php echo $_smarty_tpl->tpl_vars['error']->value;?>

                    </div>
                    <?php }?>

                    <form method="post" autocomplete="off">
                        <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                        
                        <div class="mb-3">
                            <label class="form-label">Nazwa użytkownika <span class="text-danger">*</span></label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-person"></i></span>
                                <?php if ($_smarty_tpl->tpl_vars['isEdit']->value) {?>
                                <input type="text" 
                                       name="new_account_login" 
                                       id="newAccountLogin"
                                       class="form-control" 
                                       value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['username'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"
                                       autocomplete="off"
                                       data-lpignore="true"
                                       data-form-type="other"
                                       readonly>
                                <?php } else { ?>
                                <input type="text" 
                                       name="new_account_login" 
                                       id="newAccountLogin"
                                       class="form-control" 
                                       value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['username'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"
                                       pattern="[a-zA-Z0-9_-]+"
                                       minlength="3"
                                       autocomplete="off"
                                       data-lpignore="true"
                                       data-form-type="other"
                                       required>
                                <?php }?>
                            </div>
                            <small class="text-muted">Tylko litery, cyfry, _ i - (min. 3 znaki)</small>
                        </div>

                        <?php if (!$_smarty_tpl->tpl_vars['isEdit']->value) {?>
                        <div class="mb-3">
                            <label class="form-label">Hasło <span class="text-danger">*</span></label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-lock"></i></span>
                                <input type="text" 
                                       name="new_account_secret" 
                                       id="newAccountSecret"
                                       class="form-control" 
                                       minlength="6"
                                       autocomplete="off"
                                       data-lpignore="true"
                                       data-form-type="other"
                                       required>
                                <button type="button" class="btn btn-outline-secondary" id="generatePasswordBtn" title="Generuj hasło">
                                    <i class="bi bi-magic"></i>
                                </button>
                            </div>
                            <small class="text-muted">Minimum 6 znaków</small>
                        </div>
                        <?php } else { ?>
                        <div class="mb-3">
                            <label class="form-label">Nowe hasło <span class="text-muted">(opcjonalne)</span></label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-lock"></i></span>
                                <input type="text" 
                                       name="new_account_secret" 
                                       id="newAccountSecret"
                                       class="form-control" 
                                       autocomplete="off"
                                       data-lpignore="true"
                                       data-form-type="other"
                                       placeholder="Pozostaw puste aby nie zmieniać">
                                <button type="button" class="btn btn-outline-secondary" id="generatePasswordBtn" title="Generuj hasło">
                                    <i class="bi bi-magic"></i>
                                </button>
                            </div>
                            <small class="text-muted">Wypełnij tylko jeśli chcesz zmienić hasło (min. 6 znaków)</small>
                        </div>
                        <?php }?>

                                                <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>
                        <div class="mb-3">
                            <label class="form-label">Rola</label>
                            <select name="role" class="form-select" id="roleSelect">
                                <option value="user" <?php if (((($tmp = $_smarty_tpl->tpl_vars['data']->value['role'] ?? null)===null||$tmp==='' ? 'user' ?? null : $tmp)) == 'user') {?>selected<?php }?>>Użytkownik</option>
                                <option value="reseller" <?php if (((($tmp = $_smarty_tpl->tpl_vars['data']->value['role'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp)) == 'reseller') {?>selected<?php }?>>Reseller</option>
                                <option value="admin" <?php if (((($tmp = $_smarty_tpl->tpl_vars['data']->value['role'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp)) == 'admin') {?>selected<?php }?>>Administrator</option>
                            </select>
                        </div>

                                                <div class="mb-3" id="parentIdGroup">
                            <label class="form-label">Przypisz do resellera</label>
                            <select name="parent_id" class="form-select">
                                <option value="">-- Bezpośrednio do admina --</option>
                                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['resellers']->value, 'reseller');
$_smarty_tpl->tpl_vars['reseller']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['reseller']->value) {
$_smarty_tpl->tpl_vars['reseller']->do_else = false;
?>
                                <option value="<?php echo $_smarty_tpl->tpl_vars['reseller']->value['id'];?>
" <?php if (((($tmp = $_smarty_tpl->tpl_vars['data']->value['parent_id'] ?? null)===null||$tmp==='' ? 0 ?? null : $tmp)) == $_smarty_tpl->tpl_vars['reseller']->value['id']) {?>selected<?php }?>>
                                    <?php echo $_smarty_tpl->tpl_vars['reseller']->value['username'];?>
 (użytk: <?php echo $_smarty_tpl->tpl_vars['reseller']->value['users_count'];?>
/<?php echo $_smarty_tpl->tpl_vars['reseller']->value['max_users'];?>
)
                                </option>
                                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                            </select>
                            <small class="text-muted">Opcjonalne - możesz przypisać użytkownika do resellera</small>
                        </div>
                        <?php }?>

                                                <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>
                        <div id="resellerLimitsGroup" style="display: none;">
                            <hr>
                            <h6 class="text-muted mb-3"><i class="bi bi-sliders me-2"></i>Pula resellera (do rozdysponowania)</h6>
                            
                            <div class="row">
                                <div class="col-md-4 mb-3">
                                    <label class="form-label">Max użytkowników</label>
                                    <input type="number" 
                                           name="max_users" 
                                           id="maxUsers"
                                           class="form-control" 
                                           value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['max_users'] ?? null)===null||$tmp==='' ? 10 ?? null : $tmp);?>
"
                                           min="0"
                                           max="9999"
                                           disabled>
                                    <small class="text-muted">Ilu userów może stworzyć</small>
                                </div>
                                <div class="col-md-4 mb-3">
                                    <label class="form-label">Pula urządzeń</label>
                                    <input type="number" 
                                           name="max_devices" 
                                           id="maxDevices"
                                           class="form-control" 
                                           value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['max_devices'] ?? null)===null||$tmp==='' ? 50 ?? null : $tmp);?>
"
                                           min="1"
                                           max="99999"
                                           disabled>
                                    <small class="text-muted">Własne + do rozdania</small>
                                </div>
                                <div class="col-md-4 mb-3">
                                    <label class="form-label">Pula playlist</label>
                                    <input type="number" 
                                           name="max_playlists" 
                                           id="maxPlaylists"
                                           class="form-control" 
                                           value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['max_playlists'] ?? null)===null||$tmp==='' ? 200 ?? null : $tmp);?>
"
                                           min="1"
                                           max="99999"
                                           disabled>
                                    <small class="text-muted">Własne + do rozdania</small>
                                </div>
                            </div>
                            <hr>
                        </div>
                        <?php }?>

                                                <div class="row" id="userLimitsGroup" style="<?php if ((($tmp = $_smarty_tpl->tpl_vars['data']->value['role'] ?? null)===null||$tmp==='' ? 'user' ?? null : $tmp) != 'user') {?>display:none<?php } else { ?>display:flex<?php }?>">
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Limit urządzeń</label>
                                <div class="input-group">
                                    <span class="input-group-text"><i class="bi bi-tv"></i></span>
                                    <input type="number" 
                                           name="device_limit" 
                                           class="form-control" 
                                           value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['device_limit'] ?? null)===null||$tmp==='' ? 3 ?? null : $tmp);?>
"
                                           min="1"
                                           max="<?php if ($_smarty_tpl->tpl_vars['availableLimits']->value) {
echo $_smarty_tpl->tpl_vars['availableLimits']->value['devices'];
} else { ?>999<?php }?>">
                                </div>
                                <?php if ($_smarty_tpl->tpl_vars['availableLimits']->value) {?>
                                <small class="text-muted">Dostępne: <?php echo $_smarty_tpl->tpl_vars['availableLimits']->value['devices'];?>
</small>
                                <?php }?>
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Limit playlist</label>
                                <div class="input-group">
                                    <span class="input-group-text"><i class="bi bi-list-ul"></i></span>
                                    <input type="number" 
                                           name="playlist_limit" 
                                           class="form-control" 
                                           value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['playlist_limit'] ?? null)===null||$tmp==='' ? 100 ?? null : $tmp);?>
"
                                           min="1"
                                           max="<?php if ($_smarty_tpl->tpl_vars['availableLimits']->value) {
echo $_smarty_tpl->tpl_vars['availableLimits']->value['playlists'];
} else { ?>9999<?php }?>">
                                </div>
                                <?php if ($_smarty_tpl->tpl_vars['availableLimits']->value) {?>
                                <small class="text-muted">Dostępne: <?php echo $_smarty_tpl->tpl_vars['availableLimits']->value['playlists'];?>
</small>
                                <?php }?>
                            </div>
                        </div>

                        <?php if ($_smarty_tpl->tpl_vars['isEdit']->value) {?>
                        <div class="mb-4">
                            <div class="form-check form-switch">
                                <input type="checkbox" 
                                       name="is_active" 
                                       id="is_active" 
                                       class="form-check-input"
                                       value="1"
                                       <?php if ((($tmp = $_smarty_tpl->tpl_vars['data']->value['is_active'] ?? null)===null||$tmp==='' ? 1 ?? null : $tmp)) {?>checked<?php }?>>
                                <label class="form-check-label" for="is_active">Konto aktywne</label>
                            </div>
                        </div>
                        <?php } else { ?>
                        <div class="mb-4">
                            <label class="form-label">Uwagi <span class="text-muted">(opcjonalne)</span></label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-sticky"></i></span>
                                <textarea name="initial_note" 
                                          class="form-control" 
                                          rows="2" 
                                          placeholder="Notatka dodana przy tworzeniu użytkownika..."><?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['initial_note'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
</textarea>
                            </div>
                            <small class="text-muted">Zostanie zapisana jako notatka do tego użytkownika</small>
                        </div>
                        <?php }?>

                        <div class="d-flex gap-2">
                            <button type="submit" class="btn btn-primary">
                                <i class="bi bi-check-lg me-1"></i>
                                <?php if ($_smarty_tpl->tpl_vars['isEdit']->value) {?>Zapisz zmiany<?php } else { ?>Utwórz użytkownika<?php }?>
                            </button>
                            <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/users" class="btn btn-secondary">Anuluj</a>
                        </div>
                    </form>
                </div>
            </div>

            <?php if ($_smarty_tpl->tpl_vars['isEdit']->value) {?>
            <!-- Info Card -->
            <div class="card mt-4">
                <div class="card-header">
                    <h6 class="mb-0"><i class="bi bi-info-circle me-2"></i>Informacje</h6>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-6">
                            <small class="text-muted d-block">Utworzony</small>
                            <span><?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['data']->value['created_at'],"%d.%m.%Y %H:%M");?>
</span>
                        </div>
                        <div class="col-6">
                            <small class="text-muted d-block">Ostatnia aktualizacja</small>
                            <span><?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['data']->value['updated_at'],"%d.%m.%Y %H:%M");?>
</span>
                        </div>
                        <div class="col-6 mt-3">
                            <small class="text-muted d-block">Ostatnie logowanie</small>
                            <span>
                                <?php if ($_smarty_tpl->tpl_vars['data']->value['last_login']) {?>
                                <?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['data']->value['last_login'],"%d.%m.%Y %H:%M");?>

                                <?php } else { ?>
                                Nigdy
                                <?php }?>
                            </span>
                        </div>
                        <div class="col-6 mt-3">
                            <small class="text-muted d-block">Liczba urządzeń</small>
                            <span><?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['devices_count'] ?? null)===null||$tmp==='' ? 0 ?? null : $tmp);?>
</span>
                        </div>
                        <?php if ($_smarty_tpl->tpl_vars['data']->value['parent_username']) {?>
                        <div class="col-6 mt-3">
                            <small class="text-muted d-block">Przypisany do</small>
                            <span><?php echo $_smarty_tpl->tpl_vars['data']->value['parent_username'];?>
</span>
                        </div>
                        <?php }?>
                    </div>
                </div>
            </div>
            
                        <?php if (($_smarty_tpl->tpl_vars['isAdmin']->value || $_smarty_tpl->tpl_vars['isReseller']->value) && $_smarty_tpl->tpl_vars['data']->value['id'] != $_smarty_tpl->tpl_vars['currentUser']->value['id']) {?>
            <div class="mt-4">
                <?php $_smarty_tpl->_subTemplateRender("file:partials/entity_notes.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array('entityType'=>"user",'entityId'=>$_smarty_tpl->tpl_vars['data']->value['id']), 0, false);
?>
            </div>
            <?php }?>
            <?php }?>
        </div>
    </div>
</div>
<?php
}
}
/* {/block "content"} */
/* {block "scripts"} */
class Block_1465900705694c2b9a9b9292_30740728 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'scripts' => 
  array (
    0 => 'Block_1465900705694c2b9a9b9292_30740728',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>

<?php echo '<script'; ?>
>
// Generator haseł
(function() {
    var passwordSettings = <?php echo (($tmp = $_smarty_tpl->tpl_vars['passwordSettings']->value ?? null)===null||$tmp==='' ? '{"length":12,"lowercase":true,"uppercase":true,"numbers":true,"symbols":false}' ?? null : $tmp);?>
;
    var generateBtn = document.getElementById('generatePasswordBtn');
    var passwordField = document.getElementById('newAccountSecret');
    
    function generatePassword() {
        var chars = '';
        var required = [];
        
        if (passwordSettings.lowercase) {
            var lowercase = 'abcdefghijklmnopqrstuvwxyz';
            chars += lowercase;
            required.push(lowercase.charAt(Math.floor(Math.random() * lowercase.length)));
        }
        
        if (passwordSettings.uppercase) {
            var uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            chars += uppercase;
            required.push(uppercase.charAt(Math.floor(Math.random() * uppercase.length)));
        }
        
        if (passwordSettings.numbers) {
            var numbers = '0123456789';
            chars += numbers;
            required.push(numbers.charAt(Math.floor(Math.random() * numbers.length)));
        }
        
        if (passwordSettings.symbols) {
            var symbols = '!@#$%^&*()_+-=[]{}|;:,.<>?';
            chars += symbols;
            required.push(symbols.charAt(Math.floor(Math.random() * symbols.length)));
        }
        
        if (!chars) {
            chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        }
        
        var password = required.join('');
        var length = passwordSettings.length || 12;
        
        while (password.length < length) {
            password += chars.charAt(Math.floor(Math.random() * chars.length));
        }
        
        // Shuffle
        password = password.split('').sort(function() { return 0.5 - Math.random(); }).join('');
        
        return password;
    }
    
    if (generateBtn && passwordField) {
        generateBtn.addEventListener('click', function() {
            passwordField.value = generatePassword();
            passwordField.select();
        });
    }
})();

<?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>
// Role switcher dla admina
(function() {
    var roleSelect = document.getElementById('roleSelect');
    var resellerLimitsGroup = document.getElementById('resellerLimitsGroup');
    var parentIdGroup = document.getElementById('parentIdGroup');
    var userLimitsGroup = document.getElementById('userLimitsGroup');
    var maxUsers = document.getElementById('maxUsers');
    var maxDevices = document.getElementById('maxDevices');
    var maxPlaylists = document.getElementById('maxPlaylists');

    function updateFormFields() {
        var role = roleSelect.value;
        
        if (role === 'reseller') {
            resellerLimitsGroup.style.display = 'block';
            parentIdGroup.style.display = 'none';
            userLimitsGroup.style.display = 'none';
            // Włącz pola resellera
            if (maxUsers) maxUsers.disabled = false;
            if (maxDevices) maxDevices.disabled = false;
            if (maxPlaylists) maxPlaylists.disabled = false;
        } else if (role === 'admin') {
            resellerLimitsGroup.style.display = 'none';
            parentIdGroup.style.display = 'none';
            userLimitsGroup.style.display = 'none';
            // Wyłącz pola resellera
            if (maxUsers) maxUsers.disabled = true;
            if (maxDevices) maxDevices.disabled = true;
            if (maxPlaylists) maxPlaylists.disabled = true;
        } else {
            resellerLimitsGroup.style.display = 'none';
            parentIdGroup.style.display = 'block';
            userLimitsGroup.style.display = 'flex';
            // Wyłącz pola resellera
            if (maxUsers) maxUsers.disabled = true;
            if (maxDevices) maxDevices.disabled = true;
            if (maxPlaylists) maxPlaylists.disabled = true;
        }
    }

    if (roleSelect) {
        roleSelect.addEventListener('change', updateFormFields);
        updateFormFields();
    }
})();
<?php }
echo '</script'; ?>
>
<?php
}
}
/* {/block "scripts"} */
}
