19 declare(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');
73 return $this->
http->wrapper()->query()->retrieve(
76 $this->refinery->kindlyTo()->int(),
79 $this->
http->wrapper()->query()->retrieve(
80 'contact_mailinglist_list_ml_ids',
82 $this->refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->int()),
98 !$this->mlists->hasAny()
101 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_read'), $this->error->MESSAGE);
104 if (!($cmd = $this->
ctrl->getCmd())) {
105 $cmd =
'showMailingLists';
115 $action = $this->
http->wrapper()->query()->retrieve(
116 'contact_mailinglist_members_action',
118 $this->refinery->kindlyTo()->string(),
124 default => $this->
ctrl->redirect($this,
'showMailingLists'),
130 $action = $this->
http->wrapper()->query()->retrieve(
131 'contact_mailinglist_list_action',
133 $this->refinery->kindlyTo()->string(),
142 default => $this->
ctrl->redirect($this,
'showMailingLists'),
151 if ($this->
http->wrapper()->query()->has(
'ml_id')) {
153 $this->
http->wrapper()->query()->retrieve(
'ml_id', $this->
refinery->kindlyTo()->int())
155 } elseif ($this->
http->wrapper()->post()->has(
'ml_id')) {
156 $ml_ids = $this->
http->wrapper()->post()->retrieve(
158 $this->
refinery->kindlyTo()->listOf(
163 $ml_ids = $this->
http->wrapper()->query()->retrieve(
164 'contact_mailinglist_list_ml_ids',
166 $this->refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->string()),
172 return array_filter($ml_ids);
178 if ($ml_ids === []) {
179 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_entry'));
184 if ((
string) current($ml_ids) ===
'ALL_OBJECTS') {
185 $entries = $this->mlists->getAll();
187 $entries = $this->mlists->getSelected(
194 $c_gui->setFormAction($this->
ctrl->getFormAction($this,
'performDelete'));
195 $c_gui->setHeaderText($this->
lng->txt(
'mail_sure_delete_entry'));
196 $c_gui->setCancel($this->
lng->txt(
'cancel'),
'showMailingLists');
197 $c_gui->setConfirm($this->
lng->txt(
'confirm'),
'performDelete');
199 foreach ($entries as $entry) {
200 $c_gui->addItem(
'ml_id[]', (
string) $entry->getId(), $entry->getTitle());
203 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
204 $this->tpl->setContent($c_gui->getHTML());
205 $this->tpl->printToStdout();
212 if ($this->
http->wrapper()->post()->has(
'ml_id')) {
213 $ml_ids = array_filter(
214 $this->
http->wrapper()->post()->retrieve(
216 $this->
refinery->kindlyTo()->listOf(
223 foreach ($ml_ids as
$id) {
224 if ($this->mlists->isOwner($id, $this->user->getId())) {
225 $this->mlists->get($id)->delete();
230 if ($counter !== 0) {
231 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_deleted_entry'));
234 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_delete_error'));
246 $mailing_allowed = $this->rbacsystem->checkAccess(
'internal_mail', $mail->getMailObjectReferenceId());
248 if (!$mailing_allowed) {
249 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'no_permission'));
254 if ($ml_ids === []) {
255 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_entry'));
260 if ((
string) current($ml_ids) ===
'ALL_OBJECTS') {
261 $entries = $this->mlists->getAll();
263 foreach ($entries as $entry) {
264 $ml_ids[] = $entry->getId();
267 $ml_ids =
array_map(intval(...), $ml_ids);
270 $mail_data = $this->umail->retrieveFromStage();
272 foreach ($ml_ids as
$id) {
273 if ($this->mlists->isOwner($id, $this->user->getId()) &&
274 !$this->umail->existsRecipient(
'#il_ml_' . $id, (
string) $mail_data[
'rcp_to'])) {
275 $lists[
'#il_ml_' .
$id] =
'#il_ml_' .
$id;
280 $mail_data = $this->umail->appendSearchResult(array_values($lists),
'to');
281 $this->umail->persistToStage(
282 (
int) $mail_data[
'user_id'],
283 $mail_data[
'attachments'],
284 $mail_data[
'rcp_to'],
285 $mail_data[
'rcp_cc'],
286 $mail_data[
'rcp_bcc'],
287 $mail_data[
'm_subject'],
288 $mail_data[
'm_message'],
289 $mail_data[
'use_placeholders'],
290 $mail_data[
'tpl_ctx_id'],
291 $mail_data[
'tpl_ctx_params']
305 $this->ui_factory->button()->standard(
306 $this->
lng->txt(
'create'),
307 $this->
ctrl->getLinkTarget($this,
'showForm')
318 $tbl->setMailingAllowed($this->rbacsystem->checkAccess(
'internal_mail', $mail->getMailObjectReferenceId()));
320 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
321 $this->tpl->setContent($this->ui_renderer->render($tbl->getComponent()));
322 $this->tpl->printToStdout();
330 $this->
http->wrapper()->query()->has(
'ref') &&
331 $this->
http->wrapper()->query()->retrieve(
'ref', $this->
refinery->kindlyTo()->string()) ===
'mail') {
332 $this->
ctrl->returnToParent($this);
340 if ($this->mlists->getCurrentMailingList() && $this->mlists->getCurrentMailingList()->getId()) {
341 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
342 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
345 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
349 $form = $this->
form->withRequest($this->
http->request());
351 if (!$form->getError()) {
352 $data = $form->getData();
353 $this->mlists->getCurrentMailingList()->setTitle(
356 $this->mlists->getCurrentMailingList()->setDescription(
360 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
361 if ($this->mlists->getCurrentMailingList()->getId() > 0) {
362 $this->mlists->getCurrentMailingList()->setChangedate(date(
'Y-m-d H:i:s'));
363 $this->mlists->getCurrentMailingList()->update();
364 $this->
ctrl->redirect($this,
'showMailingLists');
366 $this->mlists->getCurrentMailingList()->setCreatedate(date(
'Y-m-d H:i:s'));
367 $this->mlists->getCurrentMailingList()->insert();
369 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
370 $this->
ctrl->redirect($this,
'showMembersList');
374 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
375 $this->tpl->setContent($this->ui_renderer->render([
376 'mailing_lists' => $form
378 $this->tpl->printToStdout();
383 $title = $this->ui_factory->input()->field()->text(
384 $this->
lng->txt(
'title')
387 ->withValue($this->mlists->getCurrentMailingList() ? $this->mlists->getCurrentMailingList()->getTitle() :
'');
389 $description = $this->ui_factory->input()->field()->textarea(
390 $this->
lng->txt(
'description')
393 $this->mlists->getCurrentMailingList() ? $this->mlists->getCurrentMailingList()->getDescription() :
'' 396 $this->
form = $this->ui_factory->input()->container()->form()->standard(
397 $this->
ctrl->getFormAction($this,
'saveForm'),
400 'description' => $description
407 if ($this->mlists->getCurrentMailingList() && $this->mlists->getCurrentMailingList()->getId()) {
408 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
409 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
412 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
416 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
417 $this->tpl->setContent($this->ui_renderer->render([
418 'mailing_lists' => $this->form
420 $this->tpl->printToStdout();
425 if (!$this->mlists->getCurrentMailingList() || $this->mlists->getCurrentMailingList()->getId() === 0) {
431 $this->
tabs->clearTargets();
432 $this->
tabs->setBackTarget(
433 $this->
lng->txt(
'back'),
434 $this->
ctrl->getLinkTarget($this,
'showMailingLists')
437 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
439 $available_usr_ids = array_diff(
447 static function (array $entry):
int {
448 return $entry[
'usr_id'];
450 $this->mlists->getCurrentMailingList()->getAssignedEntries()
454 if ($available_usr_ids !== []) {
456 $this->ui_factory->button()->standard(
457 $this->
lng->txt(
'add'),
458 $this->
ctrl->getLinkTarget($this,
'showAssignmentForm')
464 $this->mlists->getCurrentMailingList(),
471 $this->tpl->setTitle($this->lng->txt(
'mail_addressbook'));
472 $this->tpl->setContent($this->ui_renderer->render($tbl->getComponent()));
473 $this->tpl->printToStdout();
480 $requested_record_ids = $this->
http->wrapper()->query()->retrieve(
481 'contact_mailinglist_members_entry_ids',
483 $this->refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->string()),
488 if ($requested_record_ids === []) {
489 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_entry'));
495 if ((
string) current($requested_record_ids) ===
'ALL_OBJECTS') {
496 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
497 $requested_record_ids = [];
498 foreach ($assigned_entries as $entry) {
499 $requested_record_ids[] = $entry[
'a_id'];
502 $requested_record_ids =
array_map(intval(...), $requested_record_ids);
506 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
507 $c_gui->setFormAction($this->
ctrl->getFormAction($this,
'performDeleteMembers'));
508 $c_gui->setHeaderText($this->
lng->txt(
'mail_sure_remove_user'));
509 $c_gui->setCancel($this->
lng->txt(
'cancel'),
'showMembersList');
510 $c_gui->setConfirm($this->
lng->txt(
'confirm'),
'performDeleteMembers');
512 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
513 $usr_ids =
array_map(
static fn(array $entry):
int => $entry[
'usr_id'], $assigned_entries);
516 foreach ($assigned_entries as $entry) {
517 if (in_array($entry[
'a_id'], $requested_record_ids,
true)) {
518 $c_gui->addItem(
'a_id[]', (
string) $entry[
'a_id'], $names[$entry[
'usr_id']]);
522 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
523 $this->tpl->setContent($c_gui->getHTML());
524 $this->tpl->printToStdout();
531 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
532 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
536 $this->
http->wrapper()->post()->has(
'a_id') &&
537 ($requested_entry_ids = $this->
http->wrapper()->post()->retrieve(
542 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
543 foreach ($requested_entry_ids as
$id) {
544 if (isset($assigned_entries[$id])) {
545 $this->mlists->getCurrentMailingList()->deleteEntry($id);
548 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_success_removed_user'));
550 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_delete_error'));
561 $options[
''] = $this->
lng->txt(
'please_select');
565 array_keys($relations->toArray()),
575 $options[$relation->getBuddyUsrId()] = $names[$relation->getBuddyUsrId()];
578 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
579 foreach ($assigned_entries as $assigned_entry) {
580 if (array_key_exists($assigned_entry[
'usr_id'], $options)) {
581 unset($options[$assigned_entry[
'usr_id']]);
585 if (count($options) > 1) {
586 $user_select = $this->ui_factory->input()->field()->select(
587 $this->
lng->txt(
'mail_entry_of_contacts'),
592 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
593 $form = $this->ui_factory->input()->container()->form()->standard(
594 $this->
ctrl->getFormAction($this,
'saveAssignmentForm'),
595 [
'usr_id' => $user_select]
601 if (count($options) === 1 && count($relations) > 0) {
602 $this->tpl->setOnScreenMessage(
604 $this->
lng->txt(
'mail_mailing_lists_all_contact_entries_assigned'),
607 $this->
ctrl->redirect($this,
'showMembersList');
608 } elseif (count($relations) === 0) {
609 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_mailing_lists_no_contact_entries'),
true);
610 $this->
ctrl->redirect($this,
'showMembersList');
618 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
619 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
622 $form = $this->getAssignmentForm();
629 $form = $form->withRequest($this->
http->request());
630 if ($form->getError()) {
635 $data = $form->getData();
639 $this->
refinery->kindlyTo()->int()->transform(
$data[
'usr_id'])
642 $this->mlists->getCurrentMailingList()->assignUser(
643 $this->
refinery->kindlyTo()->int()->transform(
$data[
'usr_id'])
645 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
658 if (!$this->mlists->getCurrentMailingList() || $this->mlists->getCurrentMailingList()->getId() === 0) {
664 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
665 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
669 $this->
ctrl->redirect($this,
'showMembersList');
672 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
673 $this->tpl->setContent($this->ui_renderer->render($form));
674 $this->tpl->printToStdout();
showAssignmentForm(?StandardForm $form=null)
readonly Refinery $refinery
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readonly ilFormatMail $umail
getMailingListIdsFromRequest()
handleMailingListMemberActions()
readonly ILIAS UI Factory $ui_factory
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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
readonly ilGlobalTemplateInterface $tpl
static redirect(string $a_script)
form( $class_path, string $cmd, string $submit_caption="")
handleMailingListActions()
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
readonly ILIAS HTTP GlobalHttpState $http
readonly ilCtrlInterface $ctrl
readonly ilErrorHandling $error
readonly ILIAS UI Renderer $ui_renderer
static getInstanceByGlobalUser(?ilObjUser $user=null)