1<?php 2 3use Fisharebest\Webtrees\Http\RequestHandlers\MessagePage; 4use Fisharebest\Webtrees\Http\RequestHandlers\MessageSelect; 5use Fisharebest\Webtrees\Http\RequestHandlers\UserPage; 6use Fisharebest\Webtrees\I18N; 7use Fisharebest\Webtrees\Module\ModuleInterface; 8use Fisharebest\Webtrees\Registry; 9use Fisharebest\Webtrees\Services\UserService; 10use Fisharebest\Webtrees\Tree; 11use Fisharebest\Webtrees\User; 12use Illuminate\Support\Collection; 13 14/** 15 * @var int $block_id 16 * @var string $context 17 * @var ModuleInterface $module 18 * @var Tree $tree 19 * @var Collection<int,object> $messages 20 * @var Collection<int,User> $users 21 * @var UserService $user_service 22 */ 23 24?> 25 26<?php if ($users->isNotEmpty()) : ?> 27 <form method="post" action="<?= e(route(MessageSelect::class, ['tree' => $tree->name()])) ?>"> 28 <input type="hidden" name="url" value="<?= e(route(UserPage::class, ['tree' => $tree->name()])) ?>"> 29 <label for="to"><?= I18N::translate('Send a message') ?></label> 30 31 <div class="input-group"> 32 <select class="form-select" id="to" name="to" required="required"> 33 <option value=""><?= I18N::translate('<select>') ?></option> 34 <?php foreach ($users as $user) : ?> 35 <option value="<?= e($user->userName()) ?>"> 36 <?= e($user->realName()) ?> - <?= e($user->userName()) ?> 37 </option> 38 <?php endforeach ?> 39 </select> 40 41 <button type="submit" class="btn btn-primary"><?= I18N::translate('Send') ?></button> 42 </div> 43 <?= csrf_field() ?> 44 </form> 45 <br><br> 46<?php endif ?> 47 48<form 49 method="post" 50 action="<?= e(route('module', ['action' => 'DeleteMessage', 'module' => $module->name(), 'context' => $context, 'tree' => $tree->name()])) ?>" 51 data-wt-confirm="<?= I18N::translate('Are you sure you want to delete this message? It cannot be retrieved later.') ?>" 52 onsubmit="return confirm(this.dataset.confirm);" 53 id="messageform" 54 name="messageform" 55> 56 <?php if ($messages->isNotEmpty()) : ?> 57 <div class="table-responsive"> 58 <table class="table-sm w-100"> 59 <tr> 60 <th class="wt-page-options-label"> 61 <?= I18N::translate('Delete') ?> 62 <br> 63 <a href="#" 64 onclick="$('#block-<?= $block_id ?> :checkbox').prop('checked', true); return false;"> 65 <?= I18N::translate('All') ?> 66 </a> 67 </th> 68 <th class="wt-page-options-label"><?= I18N::translate('Subject') ?></th> 69 <th class="wt-page-options-label"><?= I18N::translate('Date sent') ?></th> 70 <th class="wt-page-options-label"><?= I18N::translate('Email address') ?></th> 71 </tr> 72 73 <?php foreach ($messages as $message) : ?> 74 <tr> 75 <td class="wt-page-options-value center"> 76 <input type="checkbox" name="message_id[]" value="<?= $message->message_id ?>" id="cb_message<?= $message->message_id ?>"> 77 </td> 78 79 <td class="wt-page-options-value"> 80 <a href="#message<?= $message->message_id ?>" data-bs-toggle="collapse" role="button" 81 aria-expanded="false" aria-controls="message<?= $message->message_id ?>"> 82 <?= view('icons/expand') ?> 83 <?= view('icons/collapse') ?> 84 <b dir="auto"><?= e($message->subject) ?></b> 85 </a> 86 </td> 87 88 <td class="wt-page-options-value"> 89 <?= view('components/datetime', ['timestamp' => $message->created]) ?> 90 </td> 91 92 <td class="wt-page-options-value"> 93 <?php $user = $user_service->findByIdentifier($message->sender) ?> 94 95 <?php if ($user instanceof User) : ?> 96 <bdi><?= e($user->realName()) ?></bdi> - <bdi><?= $user->email() ?></bdi> 97 <?php else : ?> 98 <a href="mailto:<?= e($message->sender) ?>"><?= e($message->sender) ?></a> 99 <?php endif ?> 100 </td> 101 </tr> 102 103 <tr> 104 <td class="wt-page-options-value" colspan="4"> 105 <div id="message<?= $message->message_id ?>" class="collapse"> 106 <div dir="auto" style="white-space: pre-wrap;"> 107 <?= Registry::markdownFactory()->autolink($message->body) ?> 108 </div> 109 <br> 110 111 <?php 112 /* I18N: When replying to an email, the subject becomes “RE: subject” */ 113 if (!str_starts_with($message->subject, I18N::translate('RE: '))) { 114 $message->subject = I18N::translate('RE: ') . $message->subject; 115 } 116 117 // If this user still exists, show a reply link. 118 if ($user instanceof User) { 119 $reply_url = route(MessagePage::class, [ 120 'subject' => $message->subject, 121 'to' => $user->userName(), 122 'tree' => $tree->name(), 123 'url' => route(UserPage::class, ['tree' => $tree->name()]), 124 ]); 125 ?> 126 127 <a class="btn btn-primary" href="<?= e($reply_url) ?>" 128 title="<?= I18N::translate('Reply') ?>"> 129 <?= I18N::translate('Reply') ?> 130 </a> 131 <?php } ?> 132 <button type="button" class="btn btn-danger" 133 data-wt-confirm="<?= I18N::translate('Are you sure you want to delete this message? It cannot be retrieved later.') ?>" 134 onclick="if (confirm(this.dataset.confirm)) {$('#messageform :checkbox').prop('checked', false); $('#cb_message<?= $message->message_id ?>').prop('checked', true); document.messageform.submit();}"> 135 <?= I18N::translate('Delete') ?> 136 </button> 137 </div> 138 </td> 139 </tr> 140 <?php endforeach ?> 141 </table> 142 </div> 143 <p> 144 <button type="submit" class="btn btn-primary"><?= I18N::translate('Delete selected messages') ?></button> 145 </p> 146 <?php endif ?> 147 148 <?= csrf_field() ?> 149</form> 150