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