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