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<stdClass> $messages 20 * @var Collection<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 <?= csrf_field() ?> 29 <input type="hidden" name="url" value="<?= e(route(UserPage::class, ['tree' => $tree->name()])) ?>"> 30 <label for="to"><?= I18N::translate('Send a message') ?></label> 31 32 <div class="input-group"> 33 <select class="form-control" id="to" name="to" required="required"> 34 <option value=""><?= I18N::translate('<select>') ?></option> 35 <?php foreach ($users as $user): ?> 36 <option value="<?= e($user->userName()) ?>"> 37 <?= e($user->realName()) ?> - <?= e($user->userName()) ?> 38 </option> 39 <?php endforeach ?> 40 </select> 41 42 <button type="submit" class="btn btn-primary"><?= I18N::translate('Send') ?></button> 43 </div> 44 <br><br> 45 </form> 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-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 <?= csrf_field() ?> 57 58 <?php if ($messages->isNotEmpty()): ?> 59 <div class="table-responsive"> 60 <table class="table table-sm w-100"> 61 <tr> 62 <th class="list_label"> 63 <?= I18N::translate('Delete') ?> 64 <br> 65 <a href="#" 66 onclick="$('#block-<?= $block_id ?> :checkbox').prop('checked', true); return false;"> 67 <?= I18N::translate('All') ?> 68 </a> 69 </th> 70 <th class="list_label"><?= I18N::translate('Subject') ?></th> 71 <th class="list_label"><?= I18N::translate('Date sent') ?></th> 72 <th class="list_label"><?= I18N::translate('Email address') ?></th> 73 </tr> 74 75 <?php foreach ($messages as $message): ?> 76 <tr> 77 <td class="list_value_wrap center"> 78 <input type="checkbox" name="message_id[]" value="<?= $message->message_id ?>" id="cb_message<?= $message->message_id ?>"> 79 </td> 80 81 <td class="list_value_wrap"> 82 <a href="#message<?= $message->message_id ?>" data-toggle="collapse" role="button" 83 aria-expanded="false" aria-controls="message<?= $message->message_id ?>"> 84 <?= view('icons/expand') ?> 85 <?= view('icons/collapse') ?> 86 <b dir="auto"><?= e($message->subject) ?></b> 87 </a> 88 </td> 89 90 <td class="list_value_wrap"> 91 <?= view('components/datetime', ['timestamp' => $message->created]) ?> 92 </td> 93 94 <td class="list_value_wrap"> 95 <?php $user = $user_service->findByIdentifier($message->sender) ?> 96 97 <?php if ($user instanceof User): ?> 98 <span dir="auto"><?= e($user->realName()) ?></span> - <span 99 dir="auto"><?= $user->email() ?></span> 100 <?php else: ?> 101 <a href="mailto:<?= e($message->sender) ?>"><?= e($message->sender) ?></a> 102 <?php endif ?> 103 </td> 104 </tr> 105 106 <tr> 107 <td class="list_value_wrap" colspan="4"> 108 <div id="message<?= $message->message_id ?>" class="collapse"> 109 <div dir="auto" style="white-space: pre-wrap;"> 110 <?= Registry::markdownFactory()->autolink()->convertToHtml($message->body) ?> 111 </div> 112 <br> 113 114 <?php 115 /* I18N: When replying to an email, the subject becomes “RE: subject” */ 116 if (!str_starts_with($message->subject, I18N::translate('RE: '))) { 117 $message->subject = I18N::translate('RE: ') . $message->subject; 118 } 119 120 // If this user still exists, show a reply link. 121 if ($user instanceof User) { 122 $reply_url = route(MessagePage::class, [ 123 'subject' => $message->subject, 124 'to' => $user->userName(), 125 'tree' => $tree->name(), 126 'url' => route(UserPage::class, ['tree' => $tree->name()]), 127 ]); 128 ?> 129 130 <a class="btn btn-primary" href="<?= e($reply_url) ?>" 131 title="<?= I18N::translate('Reply') ?>"> 132 <?= I18N::translate('Reply') ?> 133 </a> 134 <?php } ?> 135 <button type="button" class="btn btn-danger" 136 data-confirm="<?= I18N::translate('Are you sure you want to delete this message? It cannot be retrieved later.') ?>" 137 onclick="if (confirm(this.dataset.confirm)) {$('#messageform :checkbox').prop('checked', false); $('#cb_message<?= $message->message_id ?>').prop('checked', true); document.messageform.submit();}"> 138 <?= I18N::translate('Delete') ?> 139 </button> 140 </div> 141 </td> 142 </tr> 143 <?php endforeach ?> 144 </table> 145 </div> 146 <p> 147 <button type="submit"><?= I18N::translate('Delete selected messages') ?></button> 148 </p> 149 <?php endif ?> 150</form> 151