<?php
/* Smarty version 4.5.6, created on 2025-12-22 19:26:08
  from '/var/www/html/tivi/panel/templates/devices/clone.tpl' */

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


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


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

<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl, "layout.tpl");
}
/* {block "content"} */
class Block_53553075169498d407fb817_32143051 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_53553075169498d407fb817_32143051',
  ),
);
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.count.php','function'=>'smarty_modifier_count',),));
?>

<div class="container-fluid">
    <div class="row justify-content-center">
        <div class="col-lg-8">
            <!-- Header -->
            <div class="d-flex justify-content-between align-items-center mb-4">
                <div>
                    <h4 class="mb-1">Sklonuj urządzenie</h4>
                    <p class="text-muted mb-0">Utwórz kopię urządzenia wraz z playlistami</p>
                </div>
                <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/devices" class="btn btn-outline-secondary">
                    <i class="bi bi-arrow-left me-1"></i>Powrót
                </a>
            </div>

            <div class="row">
                <!-- Źródło -->
                <div class="col-md-5">
                    <div class="card mb-4">
                        <div class="card-header">
                            <h6 class="mb-0"><i class="bi bi-device-hdd me-2"></i>Urządzenie źródłowe</h6>
                        </div>
                        <div class="card-body">
                            <table class="table table-sm mb-0">
                                <tr>
                                    <th class="text-muted" style="width: 40%">Nazwa:</th>
                                    <td><strong><?php echo (($tmp = $_smarty_tpl->tpl_vars['sourceDevice']->value['name'] ?? null)===null||$tmp==='' ? 'Brak nazwy' ?? null : $tmp);?>
</strong></td>
                                </tr>
                                <tr>
                                    <th class="text-muted">MAC:</th>
                                    <td><code><?php echo $_smarty_tpl->tpl_vars['sourceDevice']->value['mac'];?>
</code></td>
                                </tr>
                                <tr>
                                    <th class="text-muted">Kod:</th>
                                    <td><code><?php echo $_smarty_tpl->tpl_vars['sourceDevice']->value['code'];?>
</code></td>
                                </tr>
                                <tr>
                                    <th class="text-muted">Właściciel:</th>
                                    <td><?php echo $_smarty_tpl->tpl_vars['sourceDevice']->value['username'];?>
</td>
                                </tr>
                                <tr>
                                    <th class="text-muted">Playlisty:</th>
                                    <td><span class="badge bg-primary"><?php echo smarty_modifier_count($_smarty_tpl->tpl_vars['sourcePlaylists']->value);?>
</span></td>
                                </tr>
                            </table>
                        </div>
                    </div>

                    <!-- Lista playlist do sklonowania -->
                    <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['sourcePlaylists']->value) > 0) {?>
                    <div class="card">
                        <div class="card-header">
                            <h6 class="mb-0"><i class="bi bi-list-ul me-2"></i>Playlisty do skopiowania</h6>
                        </div>
                        <div class="card-body p-0">
                            <ul class="list-group list-group-flush">
                                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['sourcePlaylists']->value, 'playlist');
$_smarty_tpl->tpl_vars['playlist']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['playlist']->value) {
$_smarty_tpl->tpl_vars['playlist']->do_else = false;
?>
                                <li class="list-group-item d-flex justify-content-between align-items-center">
                                    <span>
                                        <?php if ($_smarty_tpl->tpl_vars['playlist']->value['type'] == 'xtream') {?>
                                        <i class="bi bi-broadcast text-primary me-2"></i>
                                        <?php } elseif ($_smarty_tpl->tpl_vars['playlist']->value['type'] == 'm3u') {?>
                                        <i class="bi bi-link-45deg text-success me-2"></i>
                                        <?php } else { ?>
                                        <i class="bi bi-hdd-network text-warning me-2"></i>
                                        <?php }?>
                                        <?php echo $_smarty_tpl->tpl_vars['playlist']->value['name'];?>

                                    </span>
                                    <span class="badge bg-secondary"><?php echo $_smarty_tpl->tpl_vars['playlist']->value['type'];?>
</span>
                                </li>
                                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                            </ul>
                        </div>
                    </div>
                    <?php }?>
                </div>

                <!-- Strzałka -->
                <div class="col-md-2 d-flex align-items-center justify-content-center">
                    <i class="bi bi-arrow-right-circle text-primary" style="font-size: 2.5rem;"></i>
                </div>

                <!-- Formularz nowego urządzenia -->
                <div class="col-md-5">
                    <div class="card">
                        <div class="card-header">
                            <h6 class="mb-0"><i class="bi bi-plus-circle me-2"></i>Nowe urządzenie</h6>
                        </div>
                        <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" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/devices/clone?id=<?php echo $_smarty_tpl->tpl_vars['sourceDevice']->value['id'];?>
">
                                <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">

                                <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>
                                <div class="mb-3">
                                    <label class="form-label">Właściciel <span class="text-danger">*</span></label>
                                    <select name="user_id" class="form-select" required>
                                        <?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 (((($tmp = $_smarty_tpl->tpl_vars['data']->value['user_id'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['currentUser']->value['id'] ?? null : $tmp)) == $_smarty_tpl->tpl_vars['user']->value['id']) {?>selected<?php }?>
                                                data-limit="<?php if ($_smarty_tpl->tpl_vars['user']->value['role'] == 'reseller') {
echo $_smarty_tpl->tpl_vars['user']->value['max_devices'];
} elseif ($_smarty_tpl->tpl_vars['user']->value['role'] == 'admin') {?>999999<?php } else {
echo $_smarty_tpl->tpl_vars['user']->value['device_limit'];
}?>"
                                                data-count="<?php if ($_smarty_tpl->tpl_vars['user']->value['role'] == 'reseller') {
echo $_smarty_tpl->tpl_vars['user']->value['devices_count']+$_smarty_tpl->tpl_vars['user']->value['devices_allocated'];
} else {
echo $_smarty_tpl->tpl_vars['user']->value['devices_count'];
}?>">
                                            <?php echo $_smarty_tpl->tpl_vars['user']->value['username'];?>

                                            <?php if ($_smarty_tpl->tpl_vars['user']->value['role'] == 'reseller') {?>
                                                (<?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'];?>
 urządzeń)
                                            <?php } elseif ($_smarty_tpl->tpl_vars['user']->value['role'] != 'admin') {?>
                                                (<?php echo $_smarty_tpl->tpl_vars['user']->value['devices_count'];?>
/<?php echo $_smarty_tpl->tpl_vars['user']->value['device_limit'];?>
 urządzeń)
                                            <?php }?>
                                        </option>
                                        <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                                    </select>
                                </div>
                                <?php }?>

                                <div class="mb-3">
                                    <label class="form-label">Nazwa urządzenia</label>
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="bi bi-tag"></i></span>
                                        <input type="text" 
                                               name="name" 
                                               class="form-control" 
                                               value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['name'] ?? null)===null||$tmp==='' ? ((string)$_smarty_tpl->tpl_vars['sourceDevice']->value['name'])." (kopia)" ?? null : $tmp);?>
"
                                               placeholder="np. TV Salon">
                                    </div>
                                </div>

                                <div class="mb-3">
                                    <label class="form-label">Adres MAC <span class="text-danger">*</span></label>
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="bi bi-ethernet"></i></span>
                                        <input type="text" 
                                               name="mac" 
                                               class="form-control" 
                                               value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['mac'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"
                                               placeholder="00:1A:2B:3C:4D:5E"
                                               required>
                                    </div>
                                    <small class="text-muted">Format: XX:XX:XX:XX:XX:XX</small>
                                </div>

                                <div class="mb-4">
                                    <label class="form-label">Kod dostępu <span class="text-danger">*</span></label>
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="bi bi-key"></i></span>
                                        <input type="text" 
                                               name="code" 
                                               class="form-control" 
                                               value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['code'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"
                                               minlength="3"
                                               required>
                                    </div>
                                    <small class="text-muted">Kod wyświetlany na urządzeniu</small>
                                </div>

                                <div class="alert alert-info mb-4">
                                    <i class="bi bi-info-circle me-2"></i>
                                    <strong><?php echo smarty_modifier_count($_smarty_tpl->tpl_vars['sourcePlaylists']->value);?>
</strong> playlist zostanie skopiowanych do nowego urządzenia.
                                </div>

                                <div class="d-grid">
                                    <button type="submit" class="btn btn-primary btn-lg">
                                        <i class="bi bi-copy me-2"></i>Sklonuj urządzenie
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
}
}
/* {/block "content"} */
/* {block "scripts"} */
class Block_145323167669498d40815a38_15066017 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'scripts' => 
  array (
    0 => 'Block_145323167669498d40815a38_15066017',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>

<?php echo '<script'; ?>
>
// Formatowanie MAC address
document.querySelector('input[name="mac"]')?.addEventListener('input', function(e) {
    let value = e.target.value.replace(/[^0-9A-Fa-f]/g, '').toUpperCase();
    let formatted = '';
    for (let i = 0; i < value.length && i < 12; i++) {
        if (i > 0 && i % 2 === 0) formatted += ':';
        formatted += value[i];
    }
    e.target.value = formatted;
});

<?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>
// Sprawdź limit przy zmianie użytkownika
document.querySelector('select[name="user_id"]')?.addEventListener('change', function() {
    const selected = this.options[this.selectedIndex];
    const limit = parseInt(selected.dataset.limit);
    const count = parseInt(selected.dataset.count);
    
    if (count >= limit) {
        alert('Wybrany użytkownik osiągnął limit urządzeń!');
    }
});
<?php }
echo '</script'; ?>
>
<?php
}
}
/* {/block "scripts"} */
}
