<?php
/* Smarty version 4.5.6, created on 2025-12-20 16:09:25
  from '/var/www/html/tivi/panel/templates/dns/index.tpl' */

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


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


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

<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl, "layout.tpl");
}
/* {block "content"} */
class Block_1987898766946bc25749058_87138220 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_1987898766946bc25749058_87138220',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>

<div class="container-fluid">
    <div class="row justify-content-center">
        <div class="col-lg-6">
            <!-- Header -->
            <div class="mb-4">
                <h4 class="mb-1">Zmiana DNS</h4>
                <p class="text-muted mb-0">Masowa zamiana adresów URL w playlistach</p>
            </div>

            <!-- Info Card -->
            <div class="alert alert-info mb-4">
                <i class="bi bi-info-circle me-2"></i>
                <strong>Jak to działa?</strong><br>
                Wpisz stary adres (lub jego część) oraz nowy adres. System znajdzie wszystkie playlisty zawierające stary adres i zamieni go na nowy.
                <br><small class="text-muted">Przykład: zamiana <code>stary.serwer.pl</code> na <code>nowy.serwer.pl</code></small>
            </div>

            <!-- Form Card -->
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">
                        <i class="bi bi-arrow-repeat me-2"></i>Zamiana adresów
                    </h5>
                </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;?>
/dns/replace" id="dnsForm">
                        <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">Zakres zmiany</label>
                            <select name="target_user" class="form-select" id="targetUser">
                                <option value="self" <?php if (((($tmp = $_smarty_tpl->tpl_vars['target_user']->value ?? null)===null||$tmp==='' ? 'self' ?? null : $tmp)) == 'self') {?>selected<?php }?>>Tylko moje playlisty</option>
                                <option value="all" <?php if (((($tmp = $_smarty_tpl->tpl_vars['target_user']->value ?? null)===null||$tmp==='' ? '' ?? null : $tmp)) == 'all') {?>selected<?php }?>>Wszyscy użytkownicy</option>
                                <optgroup label="Konkretny użytkownik">
                                    <?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['target_user']->value ?? null)===null||$tmp==='' ? '' ?? null : $tmp)) == $_smarty_tpl->tpl_vars['user']->value['id']) {?>selected<?php }?>>
                                        <?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'];?>
 urządzeń)
                                        <?php } else { ?>
                                            (<?php echo $_smarty_tpl->tpl_vars['user']->value['devices_count'];?>
 urządzeń)
                                        <?php }?>
                                    </option>
                                    <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                                </optgroup>
                            </select>
                            <small class="text-muted">Wybierz czyje playlisty mają być zaktualizowane</small>
                        </div>
                        <?php }?>

                        <div class="mb-3">
                            <label class="form-label">Stary adres <span class="text-danger">*</span></label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-link-45deg"></i></span>
                                <input type="text" 
                                       name="old_address" 
                                       class="form-control" 
                                       value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['old_address']->value ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"
                                       placeholder="np. stary.serwer.pl"
                                       required>
                            </div>
                            <small class="text-muted">Adres lub fragment adresu do wyszukania</small>
                        </div>

                        <div class="mb-4">
                            <label class="form-label">Nowy adres <span class="text-danger">*</span></label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-link"></i></span>
                                <input type="text" 
                                       name="new_address" 
                                       class="form-control" 
                                       value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['new_address']->value ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"
                                       placeholder="np. nowy.serwer.pl"
                                       required>
                            </div>
                            <small class="text-muted">Nowy adres, który zastąpi stary</small>
                        </div>

                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary btn-lg" id="submitBtn">
                                <i class="bi bi-arrow-repeat me-2"></i>Zamień adresy
                            </button>
                        </div>
                    </form>
                </div>
            </div>

            <!-- Info o polach -->
            <div class="card mt-4">
                <div class="card-header">
                    <h6 class="mb-0"><i class="bi bi-list-check me-2"></i>Pola objęte zamianą</h6>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-4">
                            <strong class="text-primary"><i class="bi bi-broadcast me-1"></i>Xtream</strong>
                            <ul class="small mb-0 mt-1">
                                <li>Host</li>
                            </ul>
                        </div>
                        <div class="col-md-4">
                            <strong class="text-success"><i class="bi bi-link-45deg me-1"></i>M3U</strong>
                            <ul class="small mb-0 mt-1">
                                <li>URL playlisty</li>
                                <li>EPG Link</li>
                            </ul>
                        </div>
                        <div class="col-md-4">
                            <strong class="text-warning"><i class="bi bi-hdd-network me-1"></i>Stalker</strong>
                            <ul class="small mb-0 mt-1">
                                <li>Server URL</li>
                                <li>Referrer URL</li>
                                <li>EPG Link</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
}
}
/* {/block "content"} */
/* {block "scripts"} */
class Block_792264026946bc2574fb39_35250235 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'scripts' => 
  array (
    0 => 'Block_792264026946bc2574fb39_35250235',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>

<?php echo '<script'; ?>
>

(function() {
    var STORAGE_KEY = 'dns_form_data';
    var oldAddrInput = document.querySelector('input[name="old_address"]');
    var newAddrInput = document.querySelector('input[name="new_address"]');
    var targetUserSelect = document.getElementById('targetUser');
    
    // Wczytaj zapisane dane z localStorage
    function loadSavedData() {
        try {
            var saved = localStorage.getItem(STORAGE_KEY);
            if (saved) {
                var data = JSON.parse(saved);
                
                // Wypełnij pola tylko jeśli są puste (nie nadpisuj wartości z serwera)
                if (oldAddrInput && !oldAddrInput.value && data.old_address) {
                    oldAddrInput.value = data.old_address;
                }
                if (newAddrInput && !newAddrInput.value && data.new_address) {
                    newAddrInput.value = data.new_address;
                }
                if (targetUserSelect && data.target_user) {
                    targetUserSelect.value = data.target_user;
                }
            }
        } catch (e) {
            console.error('Błąd wczytywania danych z localStorage:', e);
        }
    }
    
    // Zapisz dane do localStorage
    function saveData() {
        try {
            var data = {
                old_address: oldAddrInput ? oldAddrInput.value : '',
                new_address: newAddrInput ? newAddrInput.value : '',
                target_user: targetUserSelect ? targetUserSelect.value : 'self'
            };
            localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
        } catch (e) {
            console.error('Błąd zapisywania do localStorage:', e);
        }
    }
    
    // Wyczyść localStorage po udanym wysłaniu
    function clearSavedData() {
        try {
            localStorage.removeItem(STORAGE_KEY);
        } catch (e) {
            console.error('Błąd czyszczenia localStorage:', e);
        }
    }
    
    // Wczytaj dane przy starcie
    loadSavedData();
    
    // Zapisuj przy każdej zmianie
    if (oldAddrInput) {
        oldAddrInput.addEventListener('input', saveData);
    }
    if (newAddrInput) {
        newAddrInput.addEventListener('input', saveData);
    }
    if (targetUserSelect) {
        targetUserSelect.addEventListener('change', saveData);
    }
    
    // SweetAlert config
    var swalConfig = {
        background: '#1a1d21',
        color: '#e1e1e1',
        confirmButtonColor: '#0d6efd',
        cancelButtonColor: '#6c757d'
    };
    
    // Obsługa formularza
    document.getElementById('dnsForm').addEventListener('submit', function(e) {
        e.preventDefault();
        
        var oldAddr = oldAddrInput.value.trim();
        var newAddr = newAddrInput.value.trim();
        var form = this;
        
        if (oldAddr === newAddr) {
            Swal.fire({
                title: 'Błąd',
                text: 'Stary i nowy adres nie mogą być identyczne.',
                icon: 'error',
                background: swalConfig.background,
                color: swalConfig.color
            });
            return;
        }
        
        <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>
        
        var target = targetUserSelect.value;
        var confirmMsg = 'Czy na pewno chcesz zamienić adresy';
        var icon = 'question';
        
        if (target === 'all') {
            confirmMsg += ' we <strong>WSZYSTKICH</strong> playlistach wszystkich użytkowników?';
            icon = 'warning';
        } else if (target === 'self') {
            confirmMsg += ' w swoich playlistach?';
        } else {
            var userName = targetUserSelect.options[targetUserSelect.selectedIndex].text;
            confirmMsg += ' w playlistach użytkownika <strong>' + userName + '</strong>?';
        }
        
        Swal.fire({
            title: 'Potwierdź zmianę DNS',
            html: confirmMsg,
            icon: icon,
            showCancelButton: true,
            confirmButtonText: 'Zamień adresy',
            cancelButtonText: 'Anuluj',
            background: swalConfig.background,
            color: swalConfig.color,
            confirmButtonColor: swalConfig.confirmButtonColor,
            cancelButtonColor: swalConfig.cancelButtonColor
        }).then(function(result) {
            if (result.isConfirmed) {
                clearSavedData();
                document.getElementById('submitBtn').disabled = true;
                document.getElementById('submitBtn').innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Przetwarzanie...';
                form.submit();
            }
        });
        
        <?php } else { ?>
        
        clearSavedData();
        document.getElementById('submitBtn').disabled = true;
        document.getElementById('submitBtn').innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Przetwarzanie...';
        form.submit();
        
        <?php }?>
    
    });
})();

<?php echo '</script'; ?>
>
<?php
}
}
/* {/block "scripts"} */
}
