xref: /webtrees/resources/views/modules/user-messages/user-messages.phtml (revision 6dbfdb0c27cfefb7a183c5539ae7948df08837ee)
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<object> $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('&lt;select&gt;') ?></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-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    <?= csrf_field() ?>
57
58    <?php if ($messages->isNotEmpty()): ?>
59        <div class="table-responsive">
60            <table class="table-sm w-100">
61                <tr>
62                    <th class="wt-page-options-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="wt-page-options-label"><?= I18N::translate('Subject') ?></th>
71                    <th class="wt-page-options-label"><?= I18N::translate('Date sent') ?></th>
72                    <th class="wt-page-options-label"><?= I18N::translate('Email address') ?></th>
73                </tr>
74
75                <?php foreach ($messages as $message): ?>
76                    <tr>
77                        <td class="wt-page-options-value center">
78                            <input type="checkbox" name="message_id[]" value="<?= $message->message_id ?>" id="cb_message<?= $message->message_id ?>">
79                        </td>
80
81                        <td class="wt-page-options-value">
82                            <a href="#message<?= $message->message_id ?>" data-bs-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="wt-page-options-value">
91                            <?= view('components/datetime', ['timestamp' => $message->created]) ?>
92                        </td>
93
94                        <td class="wt-page-options-value">
95                            <?php $user = $user_service->findByIdentifier($message->sender) ?>
96
97                            <?php if ($user instanceof User): ?>
98                                <bdi><?= e($user->realName()) ?></bdi> - <bdi><?= $user->email() ?></bdi>
99                            <?php else: ?>
100                                <a href="mailto:<?= e($message->sender) ?>"><?= e($message->sender) ?></a>
101                            <?php endif ?>
102                        </td>
103                    </tr>
104
105                    <tr>
106                        <td class="wt-page-options-value" colspan="4">
107                            <div id="message<?= $message->message_id ?>" class="collapse">
108                                <div dir="auto" style="white-space: pre-wrap;">
109                                    <?= Registry::markdownFactory()->autolink($message->body) ?>
110                                </div>
111                                <br>
112
113                                <?php
114                                /* I18N: When replying to an email, the subject becomes “RE: subject” */
115                                if (!str_starts_with($message->subject, I18N::translate('RE: '))) {
116                                    $message->subject = I18N::translate('RE: ') . $message->subject;
117                                }
118
119                                // If this user still exists, show a reply link.
120                                if ($user instanceof User) {
121                                    $reply_url = route(MessagePage::class, [
122                                        'subject' => $message->subject,
123                                        'to'      => $user->userName(),
124                                        'tree'    => $tree->name(),
125                                        'url'     => route(UserPage::class, ['tree' => $tree->name()]),
126                                    ]);
127                                    ?>
128
129                                    <a class="btn btn-primary" href="<?= e($reply_url) ?>"
130                                       title="<?= I18N::translate('Reply') ?>">
131                                        <?= I18N::translate('Reply') ?>
132                                    </a>
133                                <?php } ?>
134                                <button type="button" class="btn btn-danger"
135                                        data-wt-confirm="<?= I18N::translate('Are you sure you want to delete this message? It cannot be retrieved later.') ?>"
136                                        onclick="if (confirm(this.dataset.confirm)) {$('#messageform :checkbox').prop('checked', false); $('#cb_message<?= $message->message_id ?>').prop('checked', true); document.messageform.submit();}">
137                                    <?= I18N::translate('Delete') ?>
138                                </button>
139                            </div>
140                        </td>
141                    </tr>
142                <?php endforeach ?>
143            </table>
144        </div>
145        <p>
146            <button type="submit"><?= I18N::translate('Delete selected messages') ?></button>
147        </p>
148    <?php endif ?>
149</form>
150