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