xref: /webtrees/resources/views/admin/media.phtml (revision 6f59525087dd4ee1d17c7375524d95ace7942861)
1<?php
2
3use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
4use Fisharebest\Webtrees\Http\RequestHandlers\ManageMediaAction;
5use Fisharebest\Webtrees\Http\RequestHandlers\ManageMediaData;
6use Fisharebest\Webtrees\I18N;
7use Fisharebest\Webtrees\View;
8use Illuminate\Support\Collection;
9
10/**
11 * @var string                   $data_folder
12 * @var string                   $files
13 * @var string                   $media_folder
14 * @var Collection<string>       $media_folders
15 * @var array<int|string,string> $media_types
16 * @var string                   $subfolders
17 * @var string                   $title
18 */
19?>
20
21<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), $title]]) ?>
22
23<h1><?= $title ?></h1>
24
25<form method="post" action="<?= e(route(ManageMediaAction::class)) ?>" id="admin-media-form">
26    <?= csrf_field() ?>
27
28    <table class="table table-bordered table-sm">
29        <thead>
30            <tr>
31                <th><?= I18N::translate('Media files') ?></th>
32                <th><?= I18N::translate('Media folders') ?></th>
33            </tr>
34        </thead>
35        <tbody>
36            <tr>
37                <td>
38                    <label>
39                        <input type="radio" name="files" value="local" <?= $files === 'local' ? 'checked' : '' ?>>
40                        <?= /* I18N: “Local files” are stored on this computer */ I18N::translate('Local files') ?>
41                    </label>
42                    <br>
43                    <label>
44                        <input type="radio" name="files" value="external" <?= $files === 'external' ? 'checked' : '' ?>>
45                        <?= /* I18N: “External files” are stored on other computers */ I18N::translate('External files') ?>
46                    </label>
47                    <br>
48                    <label>
49                        <input type="radio" name="files" value="unused" <?= $files === 'unused' ? 'checked' : '' ?>>
50                        <?= I18N::translate('Unused files') ?>
51                    </label>
52                </td>
53                <td>
54                    <?php if ($files === 'local' || $files === 'unused') : ?>
55                        <div class="input-group mb-2" dir="ltr">
56                            <div class="input-group-text"><?= e($data_folder) ?></div>
57
58                            <?php if ($media_folders->count() > 1) : ?>
59                                <?= view('components/select', ['name' => 'media_folder', 'selected' => $media_folder, 'options' => $media_folders]) ?>
60                            <?php else : ?>
61                                <input aria-label="<?= I18N::translate('Media folder') ?>"
62                                       type="text" class="form-control" name="media_folder" value="<?= e($media_folder) ?>" readonly>
63                            <?php endif ?>
64                        </div>
65
66                        <label>
67                            <input type="radio" name="subfolders" value="include" <?= $subfolders === 'include' ? 'checked' : '' ?>>
68                            <?= I18N::translate('Include subfolders') ?>
69                        </label>
70                        <br>
71                        <label>
72                            <input type="radio" name="subfolders" value="exclude" <?= $subfolders === 'exclude' ? ' checked' : '' ?>>
73                            <?= I18N::translate('Exclude subfolders') ?>
74                        </label>
75
76                    <?php elseif ($files === 'external') : ?>
77                        <?= I18N::translate('External media files have a URL instead of a filename.') ?>
78                        <input type="hidden" name="media_folder" value="<?= e($media_folder) ?>">
79
80                    <?php endif ?>
81                </td>
82            </tr>
83        </tbody>
84    </table>
85</form>
86<br>
87<br>
88
89<table
90    class="table table-bordered table-sm datatables d-none"
91    <?= view('lists/datatables-attributes') ?>
92    data-ajax="<?= e(route(ManageMediaData::class, ['files' => $files, 'media_folder' => $media_folder, 'subfolders' => $subfolders])) ?>"
93    data-server-side="true"
94>
95    <thead>
96        <tr>
97            <th>
98                <?= I18N::translate('Media file') ?>
99            </th>
100
101            <th data-sortable="false">
102                <?= I18N::translate('Media') ?>
103            </th>
104
105            <th data-sortable="<?= $files === 'unused' ? 'false' : 'true' ?>">
106                <?= I18N::translate('Media object') ?>
107            </th>
108        </tr>
109    </thead>
110</table>
111<?= view('modals/create-media-from-file', ['media_types' => $media_types]) ?>
112
113<?php View::push('javascript') ?>
114<script>
115    $("#admin-media-form input, #admin-media-form select").change(function () {
116        $("#admin-media-form").submit();
117    });
118</script>
119<?php View::endpush() ?>
120