/
TorX
/
rasp
Обзор
Документация
Войти
/
TorX
/
rasp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
admin/export.php
126 строк
5 KB
tormovies
Rewrite the app as plain PHP so it runs on shared hosting without Node.
06 авг 2026, 00:17
06 авг 2026, 00:17
b4b9ea6
Код
Авторство
О чём код?
<?php declare(strict_types=1); require_once __DIR__ . '/../includes/auth.php'; require_once __DIR__ . '/../includes/queries.php'; require_once __DIR__ . '/../includes/layout.php'; require_admin(); $pitch = $_GET['pitch'] ?? 'all'; if (!in_array($pitch, ['all', 'with', 'without'], true)) { $pitch = 'all'; } $from = trim((string) ($_GET['from'] ?? '')); $to = trim((string) ($_GET['to'] ?? '')); $importResult = null; if (request_method() === 'POST') { $action = post_string('action'); if ($action === 'import') { $text = (string) ($_POST['text'] ?? ''); $defaultPitch = isset($_POST['default_has_pitch']); $importResult = import_schedule_text($text, $defaultPitch); if ($importResult['created'] > 0 || $importResult['artists_created'] > 0) { flash_set( 'ok', sprintf( 'Импорт: создано %d, пропущено %d, артистов %d', $importResult['created'], $importResult['skipped'], $importResult['artists_created'] ) ); } elseif (!$importResult['errors']) { flash_set('ok', 'Нечего импортировать'); } } elseif ($action === 'download') { $pitch = post_string('pitch', 'all'); $from = post_string('from'); $to = post_string('to'); $rows = list_releases($from !== '' ? $from : null, $to !== '' ? $to : null, $pitch); $text = export_text($rows); header('Content-Type: text/plain; charset=utf-8'); header('Content-Disposition: attachment; filename="raspisanie-export.txt"'); echo $text; exit; } } $exportRows = list_releases($from !== '' ? $from : null, $to !== '' ? $to : null, $pitch); $exportPreview = export_text($exportRows); render_header('Импорт / экспорт', true); ?> <div class="row"> <div> <h1>Импорт / экспорт</h1> <p class="muted">Строка: <code>дата - артист - название - жанр - автор - лейбл - тип - питчинг|без</code></p> </div> </div> <div class="stack" style="margin-top:1.25rem"> <section class="panel stack"> <h2>Экспорт</h2> <form method="get" class="form"> <div class="actions" style="flex-wrap:wrap"> <label class="block" style="margin:0"> <span>С</span> <input class="field" type="date" name="from" value="<?= e($from) ?>"> </label> <label class="block" style="margin:0"> <span>По</span> <input class="field" type="date" name="to" value="<?= e($to) ?>"> </label> <label class="block" style="margin:0"> <span>Питчинг</span> <select class="field" name="pitch"> <option value="all"<?= $pitch === 'all' ? ' selected' : '' ?>>Все</option> <option value="with"<?= $pitch === 'with' ? ' selected' : '' ?>>С питчингом</option> <option value="without"<?= $pitch === 'without' ? ' selected' : '' ?>>Без питчинга</option> </select> </label> <button class="btn btn-secondary" type="submit">Показать</button> </div> </form> <form method="post" class="actions"> <input type="hidden" name="action" value="download"> <input type="hidden" name="from" value="<?= e($from) ?>"> <input type="hidden" name="to" value="<?= e($to) ?>"> <input type="hidden" name="pitch" value="<?= e($pitch) ?>"> <button class="btn btn-primary" type="submit">Скачать .txt</button> <button class="btn btn-secondary" type="button" onclick="navigator.clipboard.writeText(document.getElementById('admin-export').innerText)">Копировать</button> </form> <pre class="export" id="admin-export"><?= $exportPreview !== '' ? e($exportPreview) : 'Нет строк для фильтра.' ?></pre> </section> <section class="panel stack"> <h2>Импорт</h2> <p class="muted">Дубликаты (артист + название + дата) пропускаются. Короткие строки из 5 полей тоже ок.</p> <form method="post" class="form"> <input type="hidden" name="action" value="import"> <label class="block"> <span>Текст</span> <textarea class="field" name="text" rows="12" placeholder="05.08.2026 - Artist - Title - Genre - Author - Label - single - питчинг"></textarea> </label> <label class="check"> <input type="checkbox" name="default_has_pitch" value="1" checked> <span>Если в строке нет питчинга — считать «есть питчинг»</span> </label> <button class="btn btn-primary" type="submit">Импортировать</button> </form> <?php if (is_array($importResult) && $importResult['errors']): ?> <div class="flash flash-error"> <strong>Ошибки строк:</strong> <ul style="margin:.5rem 0 0;padding-left:1.2rem"> <?php foreach ($importResult['errors'] as $err): ?> <li>#<?= (int) $err['line'] ?>: <?= e($err['error']) ?> — <code><?= e($err['text']) ?></code></li> <?php endforeach; ?> </ul> </div> <?php endif; ?> </section> </div> <?php render_footer();