19 declare(strict_types=1);
29 private \ILIAS\HTTP\GlobalHttpState
$http;
46 $this->tpl = $DIC->ui()->mainTemplate();
47 $this->
ctrl = $DIC[
'ilCtrl'];
48 $this->
lng = $DIC[
'lng'];
49 $this->rbacsystem = $DIC[
'rbacsystem'];
50 $this->
user = $DIC[
'ilUser'];
51 $this->error = $DIC[
'ilErr'];
52 $this->
toolbar = $DIC[
'ilToolbar'];
53 $this->
http = $DIC->http();
58 $this->mlists->setCurrentMailingList(
59 $this->
http->wrapper()->query()->has(
'ml_id')
60 ? $this->
http->wrapper()->query()->retrieve(
'ml_id', $this->
refinery->kindlyTo()->int())
64 $this->
ctrl->saveParameter($this,
'mobj_id');
65 $this->
ctrl->saveParameter($this,
'ref');
74 !$this->mlists->hasAny()
77 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_read'), $this->error->MESSAGE);
80 $forward_class = $this->
ctrl->getNextClass($this);
82 switch ($forward_class) {
84 if (!($cmd = $this->
ctrl->getCmd())) {
85 $cmd =
'showMailingLists';
102 if ($this->
http->wrapper()->query()->has(
'ml_id')) {
104 $this->
http->wrapper()->query()->retrieve(
'ml_id', $this->
refinery->kindlyTo()->int())
106 } elseif ($this->
http->wrapper()->post()->has(
'ml_id')) {
107 $ml_ids = $this->
http->wrapper()->post()->retrieve(
109 $this->
refinery->kindlyTo()->listOf(
115 return array_filter($ml_ids);
121 if ($ml_ids === []) {
122 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_entry'));
129 $c_gui->setFormAction($this->
ctrl->getFormAction($this,
'performDelete'));
130 $c_gui->setHeaderText($this->
lng->txt(
'mail_sure_delete_entry'));
131 $c_gui->setCancel($this->
lng->txt(
'cancel'),
'showMailingLists');
132 $c_gui->setConfirm($this->
lng->txt(
'confirm'),
'performDelete');
134 $entries = $this->mlists->getSelected($ml_ids);
135 foreach ($entries as $entry) {
136 $c_gui->addItem(
'ml_id[]', (
string) $entry->getId(), $entry->getTitle());
139 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
140 $this->tpl->addBlockFile(
'ADM_CONTENT',
'adm_content',
'tpl.mail_mailing_lists_list.html',
'Services/Contact');
141 $this->tpl->setVariable(
'DELETE_CONFIRMATION', $c_gui->getHTML());
143 $this->tpl->printToStdout();
150 if ($this->
http->wrapper()->post()->has(
'ml_id')) {
151 $ml_ids = array_filter(
152 $this->
http->wrapper()->post()->retrieve(
154 $this->
refinery->kindlyTo()->listOf(
161 foreach ($ml_ids as
$id) {
162 if ($this->mlists->isOwner($id, $this->user->getId())) {
163 $this->mlists->get($id)->delete();
169 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_deleted_entry'));
172 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_delete_error'));
184 $mailing_allowed = $this->rbacsystem->checkAccess(
'internal_mail', $mail->getMailObjectReferenceId());
186 if (!$mailing_allowed) {
187 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'no_permission'));
192 if ($ml_ids === []) {
193 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_entry'));
198 $mail_data = $this->umail->retrieveFromStage();
200 foreach ($ml_ids as
$id) {
201 if ($this->mlists->isOwner($id, $this->user->getId()) &&
202 !$this->umail->existsRecipient(
'#il_ml_' . $id, (
string) $mail_data[
'rcp_to'])) {
203 $lists[
'#il_ml_' .
$id] =
'#il_ml_' .
$id;
208 $mail_data = $this->umail->appendSearchResult(array_values($lists),
'to');
209 $this->umail->persistToStage(
210 (
int) $mail_data[
'user_id'],
211 $mail_data[
'attachments'],
212 $mail_data[
'rcp_to'],
213 $mail_data[
'rcp_cc'],
214 $mail_data[
'rcp_bcc'],
215 $mail_data[
'm_subject'],
216 $mail_data[
'm_message'],
217 $mail_data[
'use_placeholders'],
218 $mail_data[
'tpl_ctx_id'],
219 $mail_data[
'tpl_ctx_params']
230 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
231 $this->tpl->addBlockFile(
'ADM_CONTENT',
'adm_content',
'tpl.mail_mailing_lists_list.html',
'Services/Contact');
235 $mailing_allowed = $this->rbacsystem->checkAccess(
'internal_mail', $mail->getMailObjectReferenceId());
240 $create_btn->setCaption(
'create');
241 $create_btn->setUrl($this->
ctrl->getLinkTarget($this,
'showForm'));
242 $this->
toolbar->addButtonInstance($create_btn);
245 $entries = $this->mlists->getAll();
246 if (count($entries)) {
247 $tbl->enable(
'select_all');
250 foreach ($entries as $entry) {
256 $result[$counter][
'title'] = $entry->getTitle() .
" [#il_ml_" . $entry->getId() .
"]";
257 $result[$counter][
'description'] = $entry->getDescription() ??
'';
258 $result[$counter][
'members'] = count($entry->getAssignedEntries());
260 $this->
ctrl->setParameter($this,
'ml_id', $entry->getId());
263 $current_selection_list->setListTitle($this->
lng->txt(
"actions"));
264 $current_selection_list->setId(
"act_" . $counter);
266 $current_selection_list->addItem(
267 $this->
lng->txt(
"edit"),
269 $this->
ctrl->getLinkTarget($this,
"showForm")
271 $current_selection_list->addItem(
272 $this->
lng->txt(
"members"),
274 $this->
ctrl->getLinkTarget($this,
"showMembersList")
276 if ($mailing_allowed) {
277 $current_selection_list->addItem(
278 $this->
lng->txt(
"send_mail_to"),
280 $this->
ctrl->getLinkTarget($this,
"mailToList")
283 $current_selection_list->addItem(
284 $this->
lng->txt(
"delete"),
286 $this->
ctrl->getLinkTarget($this,
"confirmDelete")
289 $result[$counter][
'COMMAND_SELECTION_LIST'] = $current_selection_list->getHTML();
293 if ($mailing_allowed) {
294 $tbl->addMultiCommand(
'mailToList', $this->
lng->txt(
'send_mail_to'));
296 $tbl->addMultiCommand(
'confirmDelete', $this->
lng->txt(
'delete'));
298 $tbl->disable(
'header');
299 $tbl->disable(
'footer');
302 $tbl->setData($result);
305 $this->
http->wrapper()->query()->has(
'ref') &&
306 $this->
http->wrapper()->query()->retrieve(
'ref', $this->
refinery->kindlyTo()->string()) ===
'mail') {
307 $tbl->addCommandButton(
'cancel', $this->
lng->txt(
'cancel'));
310 $this->tpl->setVariable(
'MAILING_LISTS', $tbl->getHTML());
311 $this->tpl->printToStdout();
318 $this->
http->wrapper()->query()->has(
'ref') &&
319 $this->
http->wrapper()->query()->retrieve(
'ref', $this->
refinery->kindlyTo()->string()) ===
'mail') {
320 $this->
ctrl->returnToParent($this);
328 if ($this->mlists->getCurrentMailingList() && $this->mlists->getCurrentMailingList()->getId()) {
329 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
330 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
333 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
339 if ($this->form_gui->checkInput()) {
340 $this->mlists->getCurrentMailingList()->setTitle(
341 $this->form_gui->getInput(
'title')
343 $this->mlists->getCurrentMailingList()->setDescription(
344 $this->form_gui->getInput(
'description')
346 if ($this->mlists->getCurrentMailingList()->getId()) {
347 $this->mlists->getCurrentMailingList()->setChangedate(date(
'Y-m-d H:i:s'));
348 $this->mlists->getCurrentMailingList()->update();
350 $this->mlists->getCurrentMailingList()->setCreatedate(date(
'Y-m-d H:i:s'));
351 $this->mlists->getCurrentMailingList()->insert();
354 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
355 $this->
ctrl->redirect($this,
'showMailingLists');
358 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
359 $this->tpl->addBlockFile(
'ADM_CONTENT',
'adm_content',
'tpl.mail_mailing_lists_form.html',
'Services/Contact');
361 $this->form_gui->setValuesByPost();
363 $this->tpl->setVariable(
'FORM', $this->form_gui->getHTML());
364 $this->tpl->printToStdout();
367 private function initForm(
string $a_type =
'create'): void
371 $this->form_gui->setFormAction($this->
ctrl->getFormAction($this,
'saveForm'));
372 $this->form_gui->setTitle($this->
lng->txt(
'mail_mailing_list'));
375 $titleGui->setRequired(
true);
376 $this->form_gui->addItem($titleGui);
380 $descriptionGui->setRows(8);
381 $this->form_gui->addItem($descriptionGui);
383 $this->form_gui->addCommandButton(
'saveForm', $this->
lng->txt(
'save'));
384 $this->form_gui->addCommandButton(
'showMailingLists', $this->
lng->txt(
'cancel'));
389 $this->form_gui->setValuesByArray([
390 'title' => $this->mlists->getCurrentMailingList()->getTitle(),
391 'description' => $this->mlists->getCurrentMailingList()->getDescription() ??
'' 397 $this->form_gui->setValuesByArray([
405 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
406 $this->tpl->addBlockFile(
'ADM_CONTENT',
'adm_content',
'tpl.mail_mailing_lists_form.html',
'Services/Contact');
408 if ($this->mlists->getCurrentMailingList() && $this->mlists->getCurrentMailingList()->getId()) {
409 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
410 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
413 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
421 $this->tpl->setVariable(
'FORM', $this->form_gui->getHTML());
422 $this->tpl->printToStdout();
427 if (!$this->mlists->getCurrentMailingList()->getId()) {
432 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
434 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
435 $this->tpl->addBlockFile(
438 'tpl.mail_mailing_lists_members.html',
445 $availale_usr_ids = array_diff(
453 static function (array $entry):
int {
454 return $entry[
'usr_id'];
456 $this->mlists->getCurrentMailingList()->getAssignedEntries()
460 if (count($availale_usr_ids) > 0) {
462 $create_btn->setCaption(
'add');
463 $create_btn->setUrl($this->
ctrl->getLinkTarget($this,
'showAssignmentForm'));
464 $this->
toolbar->addButtonInstance($create_btn);
467 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
468 if (count($assigned_entries)) {
469 $tbl->enable(
'select_all');
470 $tbl->setSelectAllCheckbox(
'a_id');
473 foreach ($assigned_entries as $entry) {
474 $usr_ids[] = $entry[
'usr_id'];
480 foreach ($assigned_entries as $entry) {
482 $result[$counter][
'user'] = $names[$entry[
'usr_id']];
488 $tbl->disable(
'header');
489 $tbl->disable(
'footer');
491 $tbl->setNoEntriesText($this->
lng->txt(
'mail_search_no'));
494 $tbl->setData($result);
496 $this->tpl->setVariable(
'MEMBERS_LIST', $tbl->getHTML());
497 $this->tpl->printToStdout();
503 if (!$this->
http->wrapper()->post()->has(
'a_id')) {
504 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_entry'));
510 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
511 $c_gui->setFormAction($this->
ctrl->getFormAction($this,
'performDeleteMembers'));
512 $c_gui->setHeaderText($this->
lng->txt(
'mail_sure_delete_entry'));
513 $c_gui->setCancel($this->
lng->txt(
'cancel'),
'showMembersList');
514 $c_gui->setConfirm($this->
lng->txt(
'confirm'),
'performDeleteMembers');
516 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
519 foreach ($assigned_entries as $entry) {
520 $usr_ids[] = $entry[
'usr_id'];
525 $requested_entry_ids = $this->
http->wrapper()->post()->retrieve(
530 foreach ($assigned_entries as $entry) {
531 if (in_array($entry[
'a_id'], $requested_entry_ids,
true)) {
532 $c_gui->addItem(
'a_id[]', (
string) $entry[
'a_id'], $names[$entry[
'usr_id']]);
536 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
537 $this->tpl->addBlockFile(
540 'tpl.mail_mailing_lists_members.html',
543 $this->tpl->setVariable(
'DELETE_CONFIRMATION', $c_gui->getHTML());
545 $this->tpl->printToStdout();
551 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
552 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
556 $this->
http->wrapper()->post()->has(
'a_id') &&
557 ($requested_entry_ids = $this->
http->wrapper()->post()->retrieve(
562 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
563 foreach ($requested_entry_ids as
$id) {
564 if (isset($assigned_entries[$id])) {
565 $this->mlists->getCurrentMailingList()->deleteEntry($id);
568 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_deleted_entry'));
570 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_delete_error'));
582 $this->
ctrl->setParameter($this,
'ml_id', $this->mlists->getCurrentMailingList()->getId());
583 $form->setFormAction($this->
ctrl->getFormAction($this,
'saveAssignmentForm'));
584 $form->setTitle(sprintf($this->
lng->txt(
'mail_assign_entry_to_mailing_list'), $this->mlists->getCurrentMailingList()->getTitle()));
587 $options[
''] = $this->
lng->txt(
'please_select');
591 array_keys($relations->toArray()),
599 foreach ($relations as $relation) {
601 $options[$relation->getBuddyUsrId()] = $names[$relation->getBuddyUsrId()];
604 $assigned_entries = $this->mlists->getCurrentMailingList()->getAssignedEntries();
605 if (count($assigned_entries)) {
606 foreach ($assigned_entries as $assigned_entry) {
607 if (array_key_exists($assigned_entry[
'usr_id'], $options)) {
608 unset($options[$assigned_entry[
'usr_id']]);
613 if (count($options) > 1) {
615 $formItem->setRequired(
true);
616 $formItem->setOptions($options);
617 $form->addItem($formItem);
619 $form->addCommandButton(
'saveAssignmentForm', $this->
lng->txt(
'assign'));
620 } elseif (count($options) === 1 && count($relations) > 0) {
621 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_mailing_lists_all_contact_entries_assigned'),
true);
622 $this->
ctrl->redirect($this,
'showMembersList');
623 } elseif (count($relations) === 0) {
624 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_mailing_lists_no_contact_entries'),
true);
625 $this->
ctrl->redirect($this,
'showMembersList');
627 $form->addCommandButton(
'showMembersList', $this->
lng->txt(
'cancel'));
635 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
636 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
639 $form = $this->getAssignmentForm();
640 if (!$form->checkInput()) {
641 $form->setValuesByPost();
648 $this->
http->wrapper()->post()->retrieve(
'usr_id', $this->
refinery->kindlyTo()->int())
651 $this->mlists->getCurrentMailingList()->assignUser(
652 $this->
http->wrapper()->post()->retrieve(
'usr_id', $this->
refinery->kindlyTo()->int())
654 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
666 if (!$this->mlists->getCurrentMailingList()->getId()) {
671 if (!$this->mlists->isOwner($this->mlists->getCurrentMailingList()->getId(), $this->
user->getId())) {
672 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
675 $this->tpl->setTitle($this->
lng->txt(
'mail_addressbook'));
676 $this->tpl->addBlockFile(
679 'tpl.mail_mailing_lists_members_form.html',
684 $form = $this->getAssignmentForm();
687 $this->tpl->setVariable(
'FORM', $form->getHTML());
688 $this->tpl->printToStdout();
static getInstanceByGlobalUser()
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:
getMailingListIdsFromRequest()
ILIAS HTTP GlobalHttpState $http
static http()
Fetches the global http state from ILIAS.
ilPropertyFormGUI $form_gui
showAssignmentForm(?ilPropertyFormGUI $form=null)
static redirect(string $a_script)
Error Handling & global info handling uses PEAR error class.
This class represents a text area property in a property form.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
initForm(string $a_type='create')
ilGlobalTemplateInterface $tpl
addMultiCommand(string $a_cmd, string $a_text)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...