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