1<?php 2 3declare(strict_types=1); 4 5use Fisharebest\Webtrees\Http\RequestHandlers\MessagePage; 6use Fisharebest\Webtrees\Http\RequestHandlers\MessageSelect; 7use Fisharebest\Webtrees\Http\RequestHandlers\UserPage; 8use Fisharebest\Webtrees\I18N; 9use Fisharebest\Webtrees\Module\ModuleInterface; 10use Fisharebest\Webtrees\Registry; 11use Fisharebest\Webtrees\Services\UserService; 12use Fisharebest\Webtrees\Tree; 13use Fisharebest\Webtrees\User; 14use Illuminate\Support\Collection; 15 16/** 17 * @var int $block_id 18 * @var string $context 19 * @var ModuleInterface $module 20 * @var Tree $tree 21 * @var Collection<int,object> $messages 22 * @var Collection<int,User> $users 23 * @var UserService $user_service 24 */ 25 26?> 27 28<?php if ($users->isNotEmpty()) : ?> 29 <form method="post" action="<?= e(route(MessageSelect::class, ['tree' => $tree->name()])) ?>"> 30 <input type="hidden" name="url" value="<?= e(route(UserPage::class, ['tree' => $tree->name()])) ?>"> 31 <label for="to"><?= I18N::translate('Send a message') ?></label> 32 33 <div class="input-group"> 34 <select class="form-select" id="to" name="to" required="required"> 35 <option value=""><?= I18N::translate('<select>') ?></option> 36 <?php foreach ($users as $user) : ?> 37 <option value="<?= e($user->userName()) ?>"> 38 <?= e($user->realName()) ?> - <?= e($user->userName()) ?> 39 </option> 40 <?php endforeach ?> 41 </select> 42 43 <button type="submit" class="btn btn-primary"><?= I18N::translate('Send') ?></button> 44 </div> 45 <?= csrf_field() ?> 46 </form> 47 <br><br> 48<?php endif ?> 49 50<form 51 method="post" 52 action="<?= e(route('module', ['action' => 'DeleteMessage', 'module' => $module->name(), 'context' => $context, 'tree' => $tree->name()])) ?>" 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 133 type="button" 134 class="btn btn-danger" 135 onclick="if (confirm('<?= I18N::translate('Are you sure you want to delete this message? It cannot be retrieved later.') ?>')) {$('#messageform :checkbox').prop('checked', false); $('#cb_message<?= $message->message_id ?>').prop('checked', true); document.messageform.submit();}" 136 > 137 <?= I18N::translate('Delete') ?> 138 </button> 139 </div> 140 </td> 141 </tr> 142 <?php endforeach ?> 143 </table> 144 </div> 145 <p> 146 <button 147 type="submit" 148 class="btn btn-primary" 149 data-wt-confirm="<?= I18N::translate('Are you sure you want to delete this message? It cannot be retrieved later.') ?>" 150 > 151 <?= I18N::translate('Delete selected messages') ?> 152 </button> 153 </p> 154 <?php endif ?> 155 156 <?= csrf_field() ?> 157</form> 158