19 declare(strict_types=1);
29 private readonly \ILIAS\HTTP\GlobalHttpState
$http;
48 $this->tpl = $DIC->ui()->mainTemplate();
49 $this->
ctrl = $DIC[
'ilCtrl'];
50 $this->
lng = $DIC[
'lng'];
51 $this->rbacsystem = $DIC[
'rbacsystem'];
52 $this->
user = $DIC[
'ilUser'];
53 $this->error = $DIC[
'ilErr'];
54 $this->
toolbar = $DIC[
'ilToolbar'];
55 $this->
http = $DIC->http();
57 $this->ui_factory = $DIC->ui()->factory();
58 $this->ui_renderer = $DIC->ui()->renderer();
62 $this->mlists->setCurrentMailingList(
63 $this->
http->wrapper()->query()->has(
'ml_id')
64 ? $this->
http->wrapper()->query()->retrieve(
'ml_id', $this->
refinery->kindlyTo()->int())
68 $this->
ctrl->saveParameter($this,
'mobj_id');
69 $this->
ctrl->saveParameter($this,
'ref');
71 $this->
lng->loadLanguageModule(
'mail');
80 !$this->mlists->hasAny()
83 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_read'), $this->error->MESSAGE);
86 if (!($cmd = $this->
ctrl->getCmd())) {
87 $cmd =
'showMailingLists';
101 if ($this->
http->wrapper()->query()->has(
'ml_id')) {
103 $this->
http->wrapper()->query()->retrieve(
'ml_id', $this->
refinery->kindlyTo()->int())
105 } elseif ($this->
http->wrapper()->post()->has(
'ml_id')) {
106 $ml_ids = $this->
http->wrapper()->post()->retrieve(
108 $this->
refinery->kindlyTo()->listOf(
114 return array_filter($ml_ids);
120 if ($ml_ids === []) {
121 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_entry'));
128 $c_gui->setFormAction($this->
ctrl->getFormAction($this,
'performDelete'));
129 $c_gui->setHeaderText($this->
lng->txt(
'mail_sure_delete_entry'));
130 $c_gui->setCancel($this->
lng->txt(
'cancel'),
'showMailingLists');
131 $c_gui->setConfirm($this->
lng->txt(
'confirm'),
'performDelete');
133 $entries = $this->mlists->getSelected($ml_ids);
134 foreach ($entries as $entry) {
135 $c_gui->addItem(
'ml_id[]', (
string) $entry->getId(), $entry->getTitle());
138 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
139 $this->tpl->addBlockFile(
'ADM_CONTENT',
'adm_content',
'tpl.mail_mailing_lists_list.html',
'Services/Contact');
140 $this->tpl->setVariable(
'DELETE_CONFIRMATION', $c_gui->getHTML());
142 $this->tpl->printToStdout();
149 if ($this->
http->wrapper()->post()->has(
'ml_id')) {
150 $ml_ids = array_filter(
151 $this->
http->wrapper()->post()->retrieve(
153 $this->
refinery->kindlyTo()->listOf(
160 foreach ($ml_ids as
$id) {
161 if ($this->mlists->isOwner($id, $this->user->getId())) {
162 $this->mlists->get($id)->delete();
167 if ($counter !== 0) {
168 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_deleted_entry'));
171 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_delete_error'));
183 $mailing_allowed = $this->rbacsystem->checkAccess(
'internal_mail', $mail->getMailObjectReferenceId());
185 if (!$mailing_allowed) {
186 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'no_permission'));
191 if ($ml_ids === []) {
192 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_entry'));
197 $mail_data = $this->umail->retrieveFromStage();
199 foreach ($ml_ids as
$id) {
200 if ($this->mlists->isOwner($id, $this->user->getId()) &&
201 !$this->umail->existsRecipient(
'#il_ml_' . $id, (
string) $mail_data[
'rcp_to'])) {
202 $lists[
'#il_ml_' .
$id] =
'#il_ml_' .
$id;
207 $mail_data = $this->umail->appendSearchResult(array_values($lists),
'to');
208 $this->umail->persistToStage(
209 (
int) $mail_data[
'user_id'],
210 $mail_data[
'attachments'],
211 $mail_data[
'rcp_to'],
212 $mail_data[
'rcp_cc'],
213 $mail_data[
'rcp_bcc'],
214 $mail_data[
'm_subject'],
215 $mail_data[
'm_message'],
216 $mail_data[
'use_placeholders'],
217 $mail_data[
'tpl_ctx_id'],
218 $mail_data[
'tpl_ctx_params']
229 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
230 $this->tpl->addBlockFile(
'ADM_CONTENT',
'adm_content',
'tpl.mail_mailing_lists_list.html',
'Services/Contact');
234 $mailing_allowed = $this->rbacsystem->checkAccess(
'internal_mail', $mail->getMailObjectReferenceId());
238 $this->
toolbar->addComponent($this->ui_factory->button()->standard(
239 $this->
lng->txt(
'create'),
240 $this->
ctrl->getLinkTarget($this,
'showForm')
244 $entries = $this->mlists->getAll();
245 if ($entries !== []) {
246 $tbl->enable(
'select_all');
249 foreach ($entries as $entry) {
255 $result[$counter][
'title'] = $entry->getTitle() .
" [#il_ml_" . $entry->getId() .
"]";
256 $result[$counter][
'description'] = $entry->getDescription() ??
'';
257 $result[$counter][
'members'] = count($entry->getAssignedEntries());
259 $this->
ctrl->setParameter($this,
'ml_id', $entry->getId());
262 $buttons[] = $this->ui_factory
265 $this->
lng->txt(
'edit'),
266 $this->
ctrl->getLinkTarget($this,
'showForm')
268 $buttons[] = $this->ui_factory
271 $this->
lng->txt(
'members'),
272 $this->
ctrl->getLinkTarget($this,
'showMembersList')
274 if ($mailing_allowed) {
275 $buttons[] = $this->ui_factory
278 $this->
lng->txt(
'send_mail_to'),
279 $this->
ctrl->getLinkTarget($this,
'mailToList')
282 $buttons[] = $this->ui_factory
285 $this->
lng->txt(
'delete'),
286 $this->
ctrl->getLinkTarget($this,
'confirmDelete')
288 $this->
ctrl->setParameter($this,
'ml_id', null);
290 $drop_down = $this->ui_factory
293 ->withLabel($this->
lng->txt(
'actions'));
295 $result[$counter][
'COMMAND_SELECTION_LIST'] = $this->ui_renderer->render($drop_down);
299 if ($mailing_allowed) {
300 $tbl->addMultiCommand(
'mailToList', $this->
lng->txt(
'send_mail_to'));
302 $tbl->addMultiCommand(
'confirmDelete', $this->
lng->txt(
'delete'));
304 $tbl->disable(
'header');
305 $tbl->disable(
'footer');
308 $tbl->setData($result);
311 $this->
http->wrapper()->query()->has(
'ref') &&
312 $this->
http->wrapper()->query()->retrieve(
'ref', $this->
refinery->kindlyTo()->string()) ===
'mail') {
313 $tbl->addCommandButton(
'cancel', $this->
lng->txt(
'cancel'));
316 $this->tpl->setVariable(
'MAILING_LISTS', $tbl->getHTML());
317 $this->tpl->printToStdout();
324 $this->
http->wrapper()->query()->has(
'ref') &&
325 $this->
http->wrapper()->query()->retrieve(
'ref', $this->
refinery->kindlyTo()->string()) ===
'mail') {
326 $this->
ctrl->returnToParent($this);
334 if ($this->mlists->getCurrentMailingList() && $this->mlists->getCurrentMailingList()->getId()) {
335 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
336 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
339 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
345 if ($this->form_gui->checkInput()) {
346 $this->mlists->getCurrentMailingList()->setTitle(
347 $this->form_gui->getInput(
'title')
349 $this->mlists->getCurrentMailingList()->setDescription(
350 $this->form_gui->getInput(
'description')
353 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
354 if ($this->mlists->getCurrentMailingList()->getId() > 0) {
355 $this->mlists->getCurrentMailingList()->setChangedate(date(
'Y-m-d H:i:s'));
356 $this->mlists->getCurrentMailingList()->update();
357 $this->
ctrl->redirect($this,
'showMailingLists');
359 $this->mlists->getCurrentMailingList()->setCreatedate(date(
'Y-m-d H:i:s'));
360 $this->mlists->getCurrentMailingList()->insert();
362 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
363 $this->
ctrl->redirect($this,
'showMembersList');
367 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
368 $this->tpl->addBlockFile(
'ADM_CONTENT',
'adm_content',
'tpl.mail_mailing_lists_form.html',
'Services/Contact');
370 $this->form_gui->setValuesByPost();
372 $this->tpl->setVariable(
'FORM', $this->form_gui->getHTML());
373 $this->tpl->printToStdout();
379 $this->form_gui->setFormAction($this->
ctrl->getFormAction($this,
'saveForm'));
380 $this->form_gui->setTitle($this->
lng->txt(
'mail_mailing_list'));
382 $titleGui->setRequired(
true);
383 $this->form_gui->addItem($titleGui);
386 $descriptionGui->setRows(8);
387 $this->form_gui->addItem($descriptionGui);
388 $this->form_gui->addCommandButton(
'saveForm', $this->
lng->txt(
'save'));
389 $this->form_gui->addCommandButton(
'showMailingLists', $this->
lng->txt(
'cancel'));
394 $this->form_gui->setValuesByArray([
395 'title' => $this->mlists->getCurrentMailingList()->getTitle(),
396 'description' => $this->mlists->getCurrentMailingList()->getDescription() ??
'' 402 $this->form_gui->setValuesByArray([
410 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
411 $this->tpl->addBlockFile(
'ADM_CONTENT',
'adm_content',
'tpl.mail_mailing_lists_form.html',
'Services/Contact');
413 if ($this->mlists->getCurrentMailingList() && $this->mlists->getCurrentMailingList()->getId()) {
414 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
415 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
418 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
426 $this->tpl->setVariable(
'FORM', $this->form_gui->getHTML());
427 $this->tpl->printToStdout();
432 if ($this->mlists->getCurrentMailingList()->getId() === 0) {
437 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
439 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
440 $this->tpl->addBlockFile(
443 'tpl.mail_mailing_lists_members.html',
450 $availale_usr_ids = array_diff(
458 static function (array $entry):
int {
459 return $entry[
'usr_id'];
461 $this->mlists->getCurrentMailingList()->getAssignedEntries()
465 if ($availale_usr_ids !== []) {
466 $this->
toolbar->addComponent($this->ui_factory->button()->standard(
467 $this->
lng->txt(
'add'),
468 $this->
ctrl->getLinkTarget($this,
'showAssignmentForm')
472 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
473 if ($assigned_entries !== []) {
474 $tbl->enable(
'select_all');
475 $tbl->setSelectAllCheckbox(
'a_id');
478 foreach ($assigned_entries as $entry) {
479 $usr_ids[] = $entry[
'usr_id'];
485 foreach ($assigned_entries as $entry) {
487 $result[$counter][
'user'] = $names[$entry[
'usr_id']];
493 $tbl->disable(
'header');
494 $tbl->disable(
'footer');
496 $tbl->setNoEntriesText($this->
lng->txt(
'mail_search_no'));
499 $tbl->setData($result);
501 $this->tpl->setVariable(
'MEMBERS_LIST', $tbl->getHTML());
502 $this->tpl->printToStdout();
508 if (!$this->
http->wrapper()->post()->has(
'a_id')) {
509 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_entry'));
515 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
516 $c_gui->setFormAction($this->
ctrl->getFormAction($this,
'performDeleteMembers'));
517 $c_gui->setHeaderText($this->
lng->txt(
'mail_sure_remove_user'));
518 $c_gui->setCancel($this->
lng->txt(
'cancel'),
'showMembersList');
519 $c_gui->setConfirm($this->
lng->txt(
'confirm'),
'performDeleteMembers');
521 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
524 foreach ($assigned_entries as $entry) {
525 $usr_ids[] = $entry[
'usr_id'];
530 $requested_entry_ids = $this->
http->wrapper()->post()->retrieve(
535 foreach ($assigned_entries as $entry) {
536 if (in_array($entry[
'a_id'], $requested_entry_ids,
true)) {
537 $c_gui->addItem(
'a_id[]', (
string) $entry[
'a_id'], $names[$entry[
'usr_id']]);
541 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
542 $this->tpl->addBlockFile(
545 'tpl.mail_mailing_lists_members.html',
548 $this->tpl->setVariable(
'DELETE_CONFIRMATION', $c_gui->getHTML());
550 $this->tpl->printToStdout();
556 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
557 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
561 $this->
http->wrapper()->post()->has(
'a_id') &&
562 ($requested_entry_ids = $this->
http->wrapper()->post()->retrieve(
567 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
568 foreach ($requested_entry_ids as
$id) {
569 if (isset($assigned_entries[$id])) {
570 $this->mlists->getCurrentMailingList()->deleteEntry($id);
573 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_success_removed_user'));
575 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_delete_error'));
587 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
588 $form->setFormAction($this->
ctrl->getFormAction($this,
'saveAssignmentForm'));
589 $form->setTitle(sprintf($this->
lng->txt(
'mail_assign_entry_to_mailing_list'), $this->mlists->getCurrentMailingList()->getTitle()));
592 $options[
''] = $this->
lng->txt(
'please_select');
596 array_keys($relations->toArray()),
606 $options[$relation->getBuddyUsrId()] = $names[$relation->getBuddyUsrId()];
609 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
610 foreach ($assigned_entries as $assigned_entry) {
611 if (array_key_exists($assigned_entry[
'usr_id'], $options)) {
612 unset($options[$assigned_entry[
'usr_id']]);
616 if (count($options) > 1) {
619 $formItem->setOptions($options);
620 $form->addItem($formItem);
622 $form->addCommandButton(
'saveAssignmentForm', $this->
lng->txt(
'mail_assign_to_mailing_list'));
623 } elseif (count($options) === 1 && count($relations) > 0) {
624 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_mailing_lists_all_contact_entries_assigned'),
true);
625 $this->
ctrl->redirect($this,
'showMembersList');
626 } elseif (count($relations) === 0) {
627 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_mailing_lists_no_contact_entries'),
true);
628 $this->
ctrl->redirect($this,
'showMembersList');
630 $form->addCommandButton(
'showMembersList', $this->
lng->txt(
'cancel'));
638 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
639 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
642 $form = $this->getAssignmentForm();
643 if (!$form->checkInput()) {
644 $form->setValuesByPost();
651 $this->
http->wrapper()->post()->retrieve(
'usr_id', $this->
refinery->kindlyTo()->int())
654 $this->mlists->getCurrentMailingList()->assignUser(
655 $this->
http->wrapper()->post()->retrieve(
'usr_id', $this->
refinery->kindlyTo()->int())
657 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
669 if ($this->mlists->getCurrentMailingList()->getId() === 0) {
674 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
675 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
678 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
679 $this->tpl->addBlockFile(
682 'tpl.mail_mailing_lists_members_form.html',
687 $form = $this->getAssignmentForm();
690 $this->tpl->setVariable(
'FORM', $form->getHTML());
691 $this->tpl->printToStdout();
readonly Refinery $refinery
readonly ilFormatMail $umail
getMailingListIdsFromRequest()
readonly ILIAS UI Factory $ui_factory
final const MODE_TEMPORARY
readonly ilRbacSystem $rbacsystem
readonly ilMailingLists $mlists
static http()
Fetches the global http state from ILIAS.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path='ilpublicuserprofilegui')
Default behaviour is:
readonly ilToolbarGUI $toolbar
ilPropertyFormGUI $form_gui
readonly ilGlobalTemplateInterface $tpl
showAssignmentForm(?ilPropertyFormGUI $form=null)
static redirect(string $a_script)
static getInstanceByGlobalUser(ilObjUser $user=null)
Error Handling & global info handling.
This class represents a text area property in a property form.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
readonly ILIAS HTTP GlobalHttpState $http
readonly ilCtrlInterface $ctrl
addMultiCommand(string $a_cmd, string $a_text)
readonly ilErrorHandling $error
readonly ILIAS UI Renderer $ui_renderer