<?php
/* Smarty version 4.5.6, created on 2025-12-20 23:35:17
  from '/var/www/html/tivi/panel/templates/admin/cron.tpl' */

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '4.5.6',
  'unifunc' => 'content_694724a5044ef7_14580996',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    '47cfeae5ea6a0dca1212f8c3b58a6a97c9e6cc91' => 
    array (
      0 => '/var/www/html/tivi/panel/templates/admin/cron.tpl',
      1 => 1766269625,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
  ),
),false)) {
function content_694724a5044ef7_14580996 (Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_loadInheritance();
$_smarty_tpl->inheritance->init($_smarty_tpl, true);
?>


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


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

<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl, "layout.tpl");
}
/* {block "content"} */
class Block_421044609694724a503ac54_35560579 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_421044609694724a503ac54_35560579',
  ),
);
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="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="mb-1">Harmonogram zadań</h4>
            <p class="text-muted mb-0">Zarządzaj automatycznymi zadaniami systemu</p>
        </div>
        <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#jobModal" onclick="resetJobForm()">
            <i class="bi bi-plus-lg me-1"></i>Dodaj zadanie
        </button>
    </div>

    <!-- Status crona -->
    <div class="card mb-4">
        <div class="card-body">
            <div class="row align-items-center">
                <div class="col-md-8">
                    <h6 class="mb-2">Status systemowego crona</h6>
                    <div class="d-flex gap-4">
                        <span>
                            <?php if ($_smarty_tpl->tpl_vars['cronStatus']->value['installed']) {?>
                            <i class="bi bi-check-circle text-success me-1"></i>Zainstalowany
                            <?php } else { ?>
                            <i class="bi bi-x-circle text-danger me-1"></i>Niezainstalowany
                            <?php }?>
                        </span>
                        <span>
                            <?php if ($_smarty_tpl->tpl_vars['cronStatus']->value['running']) {?>
                            <i class="bi bi-check-circle text-success me-1"></i>Uruchomiony
                            <?php } else { ?>
                            <i class="bi bi-x-circle text-danger me-1"></i>Zatrzymany
                            <?php }?>
                        </span>
                        <span>
                            <?php if ($_smarty_tpl->tpl_vars['cronStatus']->value['entry_exists']) {?>
                            <i class="bi bi-check-circle text-success me-1"></i>Wpis w crontab
                            <?php } else { ?>
                            <i class="bi bi-x-circle text-warning me-1"></i>Brak wpisu w crontab
                            <?php }?>
                        </span>
                    </div>
                </div>
                <div class="col-md-4 text-end">
                    <?php if (!$_smarty_tpl->tpl_vars['cronStatus']->value['entry_exists']) {?>
                    <div class="alert alert-warning mb-0 text-start small">
                        <strong>Dodaj do crontab:</strong><br>
                        <code>* * * * * php <?php echo (($tmp = (defined('BASE_PATH') ? constant('BASE_PATH') : null) ?? null)===null||$tmp==='' ? '/var/www/html' ?? null : $tmp);?>
/cron.php</code>
                    </div>
                    <?php }?>
                </div>
            </div>
        </div>
    </div>

    <!-- Lista zadań -->
    <div class="card">
        <div class="card-header">
            <h5 class="card-title mb-0"><i class="bi bi-list-check me-2"></i>Zadania</h5>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead>
                        <tr>
                            <th>Nazwa</th>
                            <th>Typ</th>
                            <th>Harmonogram</th>
                            <th>Ostatnie uruchomienie</th>
                            <th>Status</th>
                            <th class="text-end">Akcje</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['jobs']->value, 'job');
$_smarty_tpl->tpl_vars['job']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['job']->value) {
$_smarty_tpl->tpl_vars['job']->do_else = false;
?>
                        <tr>
                            <td><strong><?php echo $_smarty_tpl->tpl_vars['job']->value['name'];?>
</strong></td>
                            <td>
                                <span class="badge bg-secondary">
                                    <?php echo (($tmp = $_smarty_tpl->tpl_vars['availableJobs']->value[$_smarty_tpl->tpl_vars['job']->value['type']]['name'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['job']->value['type'] ?? null : $tmp);?>

                                </span>
                            </td>
                            <td><code><?php echo $_smarty_tpl->tpl_vars['job']->value['schedule'];?>
</code></td>
                            <td>
                                <?php if ($_smarty_tpl->tpl_vars['job']->value['last_run']) {?>
                                <?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['job']->value['last_run'],"%d.%m.%Y %H:%M");?>

                                <?php } else { ?>
                                <span class="text-muted">Nigdy</span>
                                <?php }?>
                            </td>
                            <td>
                                <?php if ($_smarty_tpl->tpl_vars['job']->value['enabled']) {?>
                                <span class="badge bg-success">Aktywne</span>
                                <?php } else { ?>
                                <span class="badge bg-secondary">Wyłączone</span>
                                <?php }?>
                            </td>
                            <td class="text-end">
                                <form method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/cron/run" class="d-inline">
                                    <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                                    <input type="hidden" name="job_id" value="<?php echo $_smarty_tpl->tpl_vars['job']->value['id'];?>
">
                                    <button type="submit" class="btn btn-sm btn-outline-success" title="Uruchom teraz">
                                        <i class="bi bi-play"></i>
                                    </button>
                                </form>
                                <button type="button" class="btn btn-sm btn-outline-primary" title="Edytuj" 
                                        onclick="editJob(<?php echo htmlspecialchars((string)json_encode($_smarty_tpl->tpl_vars['job']->value), ENT_QUOTES, 'UTF-8', true);?>
)">
                                    <i class="bi bi-pencil"></i>
                                </button>
                                <form method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/cron/delete" class="d-inline">
                                    <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                                    <input type="hidden" name="job_id" value="<?php echo $_smarty_tpl->tpl_vars['job']->value['id'];?>
">
                                    <button type="submit" class="btn btn-sm btn-outline-danger" title="Usuń" 
                                            onclick="return confirm('Usunąć to zadanie?')">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                </form>
                            </td>
                        </tr>
                        <?php
}
if ($_smarty_tpl->tpl_vars['job']->do_else) {
?>
                        <tr>
                            <td colspan="6" class="text-center py-5 text-muted">
                                <i class="bi bi-calendar-x fs-1 d-block mb-3"></i>
                                Brak zaplanowanych zadań
                            </td>
                        </tr>
                        <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- Dostępne typy zadań -->
    <div class="card mt-4">
        <div class="card-header">
            <h5 class="card-title mb-0"><i class="bi bi-puzzle me-2"></i>Dostępne typy zadań</h5>
        </div>
        <div class="card-body">
            <div class="row">
                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['availableJobs']->value, 'jobType', false, 'key');
$_smarty_tpl->tpl_vars['jobType']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['key']->value => $_smarty_tpl->tpl_vars['jobType']->value) {
$_smarty_tpl->tpl_vars['jobType']->do_else = false;
?>
                <div class="col-md-4 mb-3">
                    <div class="border rounded p-3 h-100">
                        <h6 class="mb-1"><?php echo $_smarty_tpl->tpl_vars['jobType']->value['name'];?>
</h6>
                        <small class="text-muted"><?php echo $_smarty_tpl->tpl_vars['jobType']->value['description'];?>
</small>
                        <div class="mt-2">
                            <code class="small"><?php echo $_smarty_tpl->tpl_vars['key']->value;?>
</code>
                        </div>
                    </div>
                </div>
                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
            </div>
        </div>
    </div>
</div>

<!-- Modal dodawania/edycji zadania -->
<div class="modal fade" id="jobModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/cron/save">
                <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                <input type="hidden" name="job_id" id="jobId" value="">
                
                <div class="modal-header">
                    <h5 class="modal-title" id="jobModalTitle">Nowe zadanie</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <div class="mb-3">
                        <label class="form-label">Nazwa zadania</label>
                        <input type="text" name="name" id="jobName" class="form-control" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Typ zadania</label>
                        <select name="type" id="jobType" class="form-select" required>
                            <option value="">Wybierz...</option>
                            <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['availableJobs']->value, 'jobType', false, 'key');
$_smarty_tpl->tpl_vars['jobType']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['key']->value => $_smarty_tpl->tpl_vars['jobType']->value) {
$_smarty_tpl->tpl_vars['jobType']->do_else = false;
?>
                            <option value="<?php echo $_smarty_tpl->tpl_vars['key']->value;?>
"><?php echo $_smarty_tpl->tpl_vars['jobType']->value['name'];?>
</option>
                            <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                        </select>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Harmonogram (cron)</label>
                        <input type="text" name="schedule" id="jobSchedule" class="form-control" placeholder="*/5 * * * *" required>
                        <small class="text-muted">
                            Przykłady: <code>* * * * *</code> (co minutę), 
                            <code>0 * * * *</code> (co godzinę), 
                            <code>0 0 * * *</code> (codziennie o północy)
                        </small>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" name="enabled" id="jobEnabled" class="form-check-input" value="1" checked>
                        <label class="form-check-label" for="jobEnabled">Zadanie aktywne</label>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Anuluj</button>
                    <button type="submit" class="btn btn-primary">Zapisz</button>
                </div>
            </form>
        </div>
    </div>
</div>
<?php
}
}
/* {/block "content"} */
/* {block "scripts"} */
class Block_123102171694724a5044778_95204929 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'scripts' => 
  array (
    0 => 'Block_123102171694724a5044778_95204929',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>

<?php echo '<script'; ?>
>
function resetJobForm() {
    document.getElementById('jobModalTitle').textContent = 'Nowe zadanie';
    document.getElementById('jobId').value = '';
    document.getElementById('jobName').value = '';
    document.getElementById('jobType').value = '';
    document.getElementById('jobSchedule').value = '';
    document.getElementById('jobEnabled').checked = true;
}

function editJob(job) {
    document.getElementById('jobModalTitle').textContent = 'Edytuj zadanie';
    document.getElementById('jobId').value = job.id;
    document.getElementById('jobName').value = job.name;
    document.getElementById('jobType').value = job.type;
    document.getElementById('jobSchedule').value = job.schedule;
    document.getElementById('jobEnabled').checked = job.enabled;
    
    new bootstrap.Modal(document.getElementById('jobModal')).show();
}
<?php echo '</script'; ?>
>
<?php
}
}
/* {/block "scripts"} */
}
