1<?php 2 3use Fisharebest\Webtrees\Elements\SourceMediaType; 4use Fisharebest\Webtrees\Http\RequestHandlers\AutoCompleteFolder; 5use Fisharebest\Webtrees\I18N; 6use Fisharebest\Webtrees\MediaFile; 7use Fisharebest\Webtrees\Tree; 8 9/** 10 * @var string $max_upload_size 11 * @var MediaFile|null $media_file 12 * @var array<int|string,string> $media_types 13 * @var Tree $tree 14 * @var array<string,string> $unused_files 15 */ 16 17?> 18 19<div class="row <?= $media_file instanceof MediaFile ? 'd-none' : '' ?>"> 20 <label class="col-form-label col-sm-2" for="file-location"> 21 <?= I18N::translate('Media file') ?> 22 </label> 23 <div class="col-sm-10"> 24 <select class="form-select" id="file-location" name="file_location"> 25 <option value="upload"> 26 <?= I18N::translate('A file on your computer') ?> 27 </option> 28 <?php if (!empty($unused_files)) : ?> 29 <option value="unused"> 30 <?= I18N::translate('A file on the server') ?> 31 </option> 32 <?php endif ?> 33 <option value="url"> 34 <?= /* I18N: URL = web address */ I18N::translate('A URL') ?> 35 </option> 36 </select> 37 </div> 38</div> 39 40<div class="row file-location file-location-upload <?= $media_file instanceof MediaFile ? 'd-none' : '' ?>"> 41 <label class="col-form-label col-sm-2" for="file"> 42 <?= I18N::translate('A file on your computer') ?> 43 </label> 44 <div class="col-sm-10"> 45 <input class="form-control" id="file" name="file" type="file"> 46 <small class="text-muted"> 47 <?= I18N::translate('Maximum upload size: ') ?> 48 <?= $max_upload_size ?> 49 </small> 50 </div> 51</div> 52 53<div class="row file-location file-location-upload <?= $media_file instanceof MediaFile && $media_file->isExternal() ? 'd-none' : '' ?>"> 54 <label class="col-form-label col-sm-2" for="folder"> 55 <?= I18N::translate('Filename on server') ?> 56 </label> 57 <div class="col-sm-10"> 58 <div class="row"> 59 <div class="col-sm-6"> 60 <div class="form-check"> 61 <label class="form-check-label"> 62 <span class="input-group"> 63 <input class="form-check-input" type="radio" name="auto" value="0" checked> 64 <input class="form-control" id="folder" name="folder" placeholder="<?= I18N::translate('Folder') ?>" type="text" value="<?= e(dirname($media_file instanceof MediaFile ? $media_file->filename() : '') === '.' ? '' : dirname($media_file instanceof MediaFile ? $media_file->filename() : '')) ?>" data-wt-autocomplete-url="<?= e(route(AutoCompleteFolder::class, ['tree' => $tree->name()])) ?>" autocomplete="off"> 65 <span class="input-group-text">/</span> 66 </span> 67 </label> 68 </div> 69 </div> 70 <div class="col-sm-6"> 71 <input aria-label="<?= I18N::translate('Filename') ?>" class="form-control" name="new_file" type="text" placeholder="<?= I18N::translate('Same as uploaded file') ?>" value="<?= e(basename($media_file ? $media_file->filename() : '')) ?>"> 72 </div> 73 </div> 74 <div class="form-text"> 75 <?= I18N::translate('If you have a large number of media files, you can organize them into folders and subfolders.') ?> 76 </div> 77 <div class="form-check"> 78 <label class="form-check-label"> 79 <input class="form-check-input" type="radio" name="auto" value="1"> 80 <?= I18N::translate('Create a unique filename') ?> 81 </label> 82 </div> 83 </div> 84</div> 85 86<div class="row file-location file-location-unused d-none"> 87 <label class="col-form-label col-sm-2" for="unused"> 88 <?= I18N::translate('A file on the server') ?> 89 </label> 90 <div class="col-sm-10"> 91 <?= view('components/select', ['name' => 'unused', 'selected' => '', 'options' => $unused_files]) ?> 92 <small class="text-muted"> 93 </small> 94 </div> 95</div> 96 97<div class="row file-location file-location-url <?= $media_file && $media_file->isExternal() ? '' : 'd-none' ?>"> 98 <label class="col-form-label col-sm-2" for="remote"> 99 <?= I18N::translate('URL') ?> 100 </label> 101 <div class="col-sm-10"> 102 <input class="form-control" type="url" id="remote" name="remote" placeholder="https://www.example.com/photo.jpeg" value="<?= e($media_file && $media_file->isExternal() ? $media_file->filename() : '') ?>"> 103 </div> 104</div> 105 106<div class="row mb-3"> 107 <label class="col-form-label col-sm-2" for="title"> 108 <?= I18N::translate('Title') ?> 109 </label> 110 <div class="col-sm-10"> 111 <input class="form-control" id="title" name="title" type="text" value="<?= e($media_file ? $media_file->title() : '') ?>"> 112 </div> 113</div> 114 115<div class="row mb-3"> 116 <label class="col-form-label col-sm-2" for="type"> 117 <?= I18N::translate('Media type') ?> 118 </label> 119 <div class="col-sm-10"> 120 <?= (new SourceMediaType(''))->edit('type', 'type', $media_file ? $media_file->type() : '', $tree) ?> 121 </div> 122</div> 123 124<script> 125 webtrees.autocomplete('#folder'); 126 document.getElementById('file-location').addEventListener('change', function () { 127 document.querySelectorAll('.file-location').forEach((e) => e.classList.add('d-none')); 128 document.querySelectorAll('.file-location-' + this.value).forEach((e) => e.classList.remove('d-none')); 129 }); 130</script> 131