19declare(strict_types=1);
28 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();
59 $this->
tabs = $DIC->tabs();
65 $this->
ctrl->saveParameter($this,
'mobj_id');
66 $this->
ctrl->saveParameter($this,
'ref');
68 $this->
lng->loadLanguageModule(
'mail');
74 'handleMailingListActions',
75 'handleMailingListMemberActions',
86 return $this->
http->wrapper()->query()->retrieve(
89 $this->refinery->kindlyTo()->int(),
90 $this->refinery->always(
92 $this->
http->wrapper()->query()->retrieve(
93 'contact_mailinglist_list_ml_ids',
94 $this->refinery->byTrying([
95 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()),
96 $this->refinery->always([0])
111 !$this->mlists->hasAny()
114 $this->
error->raiseError($this->
lng->txt(
'msg_no_perm_read'), $this->error->MESSAGE);
117 $cmd = $this->
ctrl->getCmd();
118 if ($cmd ===
null || $cmd ===
'' || !method_exists($this, $cmd .
'Command')) {
119 $cmd =
'showMailingLists';
121 $verified_command = $cmd .
'Command';
123 $this->$verified_command();
130 $action = $this->
http->wrapper()->query()->retrieve(
131 'contact_mailinglist_members_action',
133 $this->refinery->kindlyTo()->string(),
134 $this->refinery->always(
'')
139 default => $this->
ctrl->redirect($this,
'showMailingLists'),
145 $action = $this->
http->wrapper()->query()->retrieve(
146 'contact_mailinglist_list_action',
148 $this->refinery->kindlyTo()->string(),
149 $this->refinery->always(
'')
157 default => $this->
ctrl->redirect($this,
'showMailingLists'),
166 if ($this->
http->wrapper()->query()->has(
'ml_id')) {
168 $this->
http->wrapper()->query()->retrieve(
'ml_id', $this->
refinery->kindlyTo()->int())
170 } elseif ($this->
http->wrapper()->post()->has(
'ml_id')) {
171 $ml_ids = $this->
http->wrapper()->post()->retrieve(
173 $this->
refinery->kindlyTo()->listOf(
174 $this->refinery->kindlyTo()->int()
178 $ml_ids = $this->
http->wrapper()->query()->retrieve(
179 'contact_mailinglist_list_ml_ids',
181 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
182 $this->refinery->always([])
187 return array_filter($ml_ids);
193 if ($ml_ids === []) {
194 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_entry'));
199 if ((
string) current($ml_ids) ===
'ALL_OBJECTS') {
200 $entries = $this->mlists->getAll();
202 $entries = $this->mlists->getSelected(
203 array_map(intval(...), $ml_ids)
209 $c_gui->setFormAction($this->
ctrl->getFormAction($this,
'performDelete'));
210 $c_gui->setHeaderText($this->
lng->txt(
'mail_sure_delete_entry'));
211 $c_gui->setCancel($this->
lng->txt(
'cancel'),
'showMailingLists');
212 $c_gui->setConfirm($this->
lng->txt(
'confirm'),
'performDelete');
214 foreach ($entries as $entry) {
215 $c_gui->addItem(
'ml_id[]', (
string) $entry->getId(), $entry->getTitle());
218 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
219 $this->tpl->setContent($c_gui->getHTML());
220 $this->tpl->printToStdout();
225 if ($this->
http->wrapper()->post()->has(
'ml_id')) {
226 $ml_ids = array_filter(
227 $this->
http->wrapper()->post()->retrieve(
229 $this->refinery->kindlyTo()->listOf(
230 $this->refinery->kindlyTo()->int()
236 foreach ($ml_ids as
$id) {
237 if ($this->mlists->isOwner(
$id, $this->user->getId())) {
238 $this->mlists->get(
$id)->delete();
244 $this->tpl->setOnScreenMessage(
245 $this->tpl::MESSAGE_TYPE_SUCCESS,
246 $this->
lng->txt(
'mail_deleted_entry'),
251 $this->tpl->setOnScreenMessage(
252 $this->tpl::MESSAGE_TYPE_FAILURE,
253 $this->
lng->txt(
'mail_delete_error'),
258 $this->
ctrl->redirect($this,
'showMailingLists');
265 $mailing_allowed = $this->rbacsystem->checkAccess(
'internal_mail', $mail->getMailObjectReferenceId());
267 if (!$mailing_allowed) {
268 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->
lng->txt(
'no_permission'));
273 if ($ml_ids === []) {
274 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->
lng->txt(
'mail_select_one_entry'));
279 if ((
string) current($ml_ids) ===
'ALL_OBJECTS') {
280 $entries = $this->mlists->getAll();
282 foreach ($entries as $entry) {
283 $ml_ids[] = $entry->getId();
286 $ml_ids = array_map(intval(...), $ml_ids);
289 $mail_data = $this->umail->retrieveFromStage();
291 foreach ($ml_ids as
$id) {
292 if ($this->mlists->isOwner(
$id, $this->user->getId()) &&
293 !$this->umail->existsRecipient(
'#il_ml_' .
$id, (
string) $mail_data[
'rcp_to'])) {
294 $lists[
'#il_ml_' .
$id] =
'#il_ml_' .
$id;
299 $mail_data = $this->umail->appendSearchResult(array_values($lists),
'to');
300 $this->umail->persistToStage(
301 (
int) $mail_data[
'user_id'],
302 $mail_data[
'attachments'],
303 $mail_data[
'rcp_to'],
304 $mail_data[
'rcp_cc'],
305 $mail_data[
'rcp_bcc'],
306 $mail_data[
'm_subject'],
307 $mail_data[
'm_message'],
308 $mail_data[
'use_placeholders'],
309 $mail_data[
'tpl_ctx_id'],
310 $mail_data[
'tpl_ctx_params']
322 $this->ui_factory->button()->standard(
323 $this->lng->txt(
'create'),
324 $this->ctrl->getLinkTarget($this,
'showForm')
335 $tbl->setMailingAllowed($this->rbacsystem->checkAccess(
'internal_mail', $mail->getMailObjectReferenceId()));
337 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
338 $this->tpl->setContent($this->ui_renderer->render($tbl->getComponent()));
339 $this->tpl->printToStdout();
344 if ($this->
http->wrapper()->query()->has(
'ref') &&
345 $this->http->wrapper()->query()->retrieve(
'ref', $this->refinery->kindlyTo()->string()) ===
'mail') {
346 $this->
ctrl->returnToParent($this);
354 if ($this->mlists->getCurrentMailingList() && $this->mlists->getCurrentMailingList()->getId()) {
355 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->user->getId())) {
356 $this->
error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
359 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
363 $form = $this->
form->withRequest($this->
http->request());
365 if (!$form->getError()) {
367 $this->mlists->getCurrentMailingList()->setTitle(
370 $this->mlists->getCurrentMailingList()->setDescription(
374 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
375 if ($this->mlists->getCurrentMailingList()->getId() > 0) {
376 $this->mlists->getCurrentMailingList()->setChangedate(date(
'Y-m-d H:i:s'));
377 $this->mlists->getCurrentMailingList()->update();
378 $this->
ctrl->redirect($this,
'showMailingLists');
380 $this->mlists->getCurrentMailingList()->setCreatedate(date(
'Y-m-d H:i:s'));
381 $this->mlists->getCurrentMailingList()->insert();
383 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
384 $this->
ctrl->redirect($this,
'showMembersList');
388 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
389 $this->tpl->setContent($this->ui_renderer->render([
390 'mailing_lists' =>
$form
392 $this->tpl->printToStdout();
397 $title = $this->ui_factory
401 $this->
lng->txt(
'title')
405 $this->mlists->getCurrentMailingList() ? $this->mlists->getCurrentMailingList()->getTitle() :
''
408 $description = $this->ui_factory
412 $this->
lng->txt(
'description')
415 $this->mlists->getCurrentMailingList() ? $this->mlists->getCurrentMailingList()->getDescription() :
''
418 $this->
form = $this->ui_factory->input()->container()->form()->standard(
419 $this->
ctrl->getFormAction($this,
'saveForm'),
422 'description' => $description
429 if ($this->mlists->getCurrentMailingList() && $this->mlists->getCurrentMailingList()->getId()) {
430 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->user->getId())) {
431 $this->
error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
434 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
438 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
439 $this->tpl->setContent($this->ui_renderer->render([
440 'mailing_lists' => $this->form
442 $this->tpl->printToStdout();
447 if (!$this->mlists->getCurrentMailingList() || $this->mlists->getCurrentMailingList()->getId() === 0) {
452 $this->
tabs->clearTargets();
453 $this->
tabs->setBackTarget(
454 $this->
lng->txt(
'back'),
455 $this->ctrl->getLinkTarget($this,
'showMailingLists')
458 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
460 $available_usr_ids = array_diff(
468 static function (array $entry):
int {
469 return $entry[
'usr_id'];
471 $this->mlists->getCurrentMailingList()->getAssignedEntries()
475 if ($available_usr_ids !== []) {
477 $this->ui_factory->button()->standard(
478 $this->lng->txt(
'add'),
479 $this->ctrl->getLinkTarget($this,
'showAssignmentForm')
485 $this->mlists->getCurrentMailingList(),
492 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
493 $this->tpl->setContent($this->ui_renderer->render($tbl->getComponent()));
494 $this->tpl->printToStdout();
499 $requested_record_ids = $this->
http->wrapper()->query()->retrieve(
500 'contact_mailinglist_members_entry_ids',
502 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
503 $this->refinery->always([])
507 if ($requested_record_ids === []) {
508 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_entry'));
513 if ((
string) current($requested_record_ids) ===
'ALL_OBJECTS') {
514 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
515 $requested_record_ids = [];
516 foreach ($assigned_entries as $entry) {
517 $requested_record_ids[] = $entry[
'a_id'];
520 $requested_record_ids = array_map(intval(...), $requested_record_ids);
524 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
525 $c_gui->setFormAction($this->
ctrl->getFormAction($this,
'performDeleteMembers'));
526 $c_gui->setHeaderText($this->
lng->txt(
'mail_sure_remove_user'));
527 $c_gui->setCancel($this->
lng->txt(
'cancel'),
'showMembersList');
528 $c_gui->setConfirm($this->
lng->txt(
'confirm'),
'performDeleteMembers');
530 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
531 $usr_ids = array_map(
static fn(array $entry):
int => $entry[
'usr_id'], $assigned_entries);
534 foreach ($assigned_entries as $entry) {
535 if (in_array($entry[
'a_id'], $requested_record_ids,
true)) {
536 $c_gui->addItem(
'a_id[]', (
string) $entry[
'a_id'], $names[$entry[
'usr_id']]);
540 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
541 $this->tpl->setContent($c_gui->getHTML());
542 $this->tpl->printToStdout();
547 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->user->getId())) {
548 $this->
error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
551 if ($this->
http->wrapper()->post()->has(
'a_id') &&
552 ($requested_entry_ids = $this->http->wrapper()->post()->retrieve(
554 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
556 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
557 foreach ($requested_entry_ids as
$id) {
558 if (isset($assigned_entries[
$id])) {
559 $this->mlists->getCurrentMailingList()->deleteEntry(
$id);
562 $this->tpl->setOnScreenMessage(
563 $this->tpl::MESSAGE_TYPE_SUCCESS,
564 $this->
lng->txt(
'mail_success_removed_user'),
568 $this->tpl->setOnScreenMessage(
569 $this->tpl::MESSAGE_TYPE_FAILURE,
570 $this->
lng->txt(
'mail_delete_error'),
575 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
576 $this->
ctrl->redirect($this,
'showMembersList');
579 private function getAssignmentForm(): ?StandardForm
585 array_keys($relations->toArray()),
598 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
599 foreach ($assigned_entries as $assigned_entry) {
600 if (array_key_exists($assigned_entry[
'usr_id'], $options)) {
601 unset($options[$assigned_entry[
'usr_id']]);
605 if (count($options) > 0) {
606 $user_select = $this->ui_factory->input()->field()->select(
607 $this->
lng->txt(
'mail_entry_of_contacts'),
611 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
612 $form = $this->ui_factory->input()->container()->form()->standard(
613 $this->
ctrl->getFormAction($this,
'saveAssignmentForm'),
614 [
'usr_id' => $user_select]
620 if (count($relations) > 0) {
621 $this->tpl->setOnScreenMessage(
622 $this->tpl::MESSAGE_TYPE_INFO,
623 $this->
lng->txt(
'mail_mailing_lists_all_contact_entries_assigned'),
627 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
628 $this->
ctrl->redirect($this,
'showMembersList');
631 $this->tpl->setOnScreenMessage(
632 $this->tpl::MESSAGE_TYPE_INFO,
633 $this->
lng->txt(
'mail_mailing_lists_no_contact_entries'),
637 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
638 $this->
ctrl->redirect($this,
'showMembersList');
643 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->user->getId())) {
644 $this->
error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
647 $form = $this->getAssignmentForm();
654 if ($form->getError()) {
662 $this->
refinery->kindlyTo()->int()->transform(
$data[
'usr_id'])
665 $this->mlists->getCurrentMailingList()->assignUser(
666 $this->
refinery->kindlyTo()->int()->transform(
$data[
'usr_id'])
668 $this->tpl->setOnScreenMessage(
669 $this->tpl::MESSAGE_TYPE_SUCCESS,
670 $this->
lng->txt(
'saved_successfully'),
674 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
675 $this->
ctrl->redirect($this,
'showMembersList');
683 if (!$this->mlists->getCurrentMailingList() || $this->mlists->getCurrentMailingList()->getId() === 0) {
688 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->user->getId())) {
689 $this->
error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
692 if (!
$form instanceof StandardForm) {
693 $form = $this->getAssignmentForm();
696 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
697 $this->tpl->setContent($this->ui_renderer->render(
$form));
698 $this->tpl->printToStdout();
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static getInstanceByGlobalUser(?ilObjUser $user=null)
Class ilBuddySystemRelation.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Error Handling & global info handling.
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
performDeleteMembersCommand()
readonly ILIAS HTTP GlobalHttpState $http
readonly ilCtrlInterface $ctrl
readonly ILIAS UI Renderer $ui_renderer
readonly ilRbacSystem $rbacsystem
getSafePostCommands()
This method must return a list of safe POST commands.
readonly ilErrorHandling $error
handleMailingListActionsCommand()
readonly ilFormatMail $umail
readonly ilGlobalTemplateInterface $tpl
readonly ilMailingLists $mlists
saveAssignmentFormCommand()
readonly ilToolbarGUI $toolbar
getMailingListIdsFromRequest()
readonly ILIAS UI Factory $ui_factory
handleMailingListMemberActionsCommand()
showMailingListsCommand()
showAssignmentFormCommand(?StandardForm $form=null)
readonly Refinery $refinery
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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=null)
Default behaviour is:
static redirect(string $a_script)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd, string $submit_caption="")