ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMailSearchGroupsGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once './Services/User/classes/class.ilObjUser.php';
6require_once 'Services/Mail/classes/class.ilMailbox.php';
7require_once 'Services/Mail/classes/class.ilFormatMail.php';
8require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystem.php';
9
17{
21 protected $tpl;
22
26 protected $ctrl;
27
31 protected $lng;
32
36 protected $user;
37
41 protected $error;
42
46 protected $rbacsystem;
47
51 protected $rbacreview;
52
56 protected $tree;
57
61 protected $cache;
62
66 protected $umail;
68 protected $rerfinery;
69
74
75 public function __construct($wsp_access_handler = null, $wsp_node_id = null)
76 {
77 global $DIC;
78
79 $this->tpl = $DIC['tpl'];
80 $this->ctrl = $DIC['ilCtrl'];
81 $this->lng = $DIC['lng'];
82 $this->user = $DIC['ilUser'];
83 $this->error = $DIC['ilErr'];
84 $this->rbacsystem = $DIC['rbacsystem'];
85 $this->rbacreview = $DIC['rbacreview'];
86 $this->tree = $DIC['tree'];
87 $this->cache = $DIC['ilObjDataCache'];
88 $this->refinery = $DIC->refinery();
89
90 // personal workspace
91 $this->wsp_access_handler = $wsp_access_handler;
92 $this->wsp_node_id = $wsp_node_id;
93
94 $this->ctrl->saveParameter($this, "mobj_id");
95 $this->ctrl->saveParameter($this, "ref");
96
97 include_once "Services/Mail/classes/class.ilMail.php";
98 $mail = new ilMail($this->user->getId());
99 $this->mailing_allowed = $this->rbacsystem->checkAccess('internal_mail', $mail->getMailObjectReferenceId());
100
101 $this->umail = new ilFormatMail($this->user->getId());
102 }
103
104 private function getContext() : string
105 {
106 $context = 'mail';
107 if (isset($_GET['ref'])) {
108 $always = $context;
109 $context = $this->refinery->byTrying([
110 $this->refinery->kindlyTo()->string(),
111 $this->refinery->custom()->transformation(static function ($value) use ($always) {
112 return $always;
113 }),
114 ])->transform($_GET['ref']);
115 }
116
117 return $context;
118 }
119
120 public function executeCommand()
121 {
122 $forward_class = $this->ctrl->getNextClass($this);
123 switch ($forward_class) {
124 case 'ilbuddysystemgui':
125 if (!ilBuddySystem::getInstance()->isEnabled()) {
126 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
127 }
128
129 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemGUI.php';
130 $this->ctrl->saveParameter($this, 'search_grp');
131 $this->ctrl->setReturn($this, 'showMembers');
132 $this->ctrl->forwardCommand(new ilBuddySystemGUI());
133 break;
134
135 default:
136 if (!($cmd = $this->ctrl->getCmd())) {
137 $cmd = "showMyGroups";
138 }
139
140 $this->$cmd();
141 break;
142 }
143 return true;
144 }
145
146 public function mail()
147 {
148 if ($_GET["view"] == "mygroups") {
149 $ids = ((int) $_GET['search_grp']) ? array((int) $_GET['search_grp']) : $_POST['search_grp'];
150 if ($ids) {
151 $this->mailGroups();
152 } else {
153 ilUtil::sendInfo($this->lng->txt("mail_select_group"));
154 $this->showMyGroups();
155 }
156 } elseif ($_GET["view"] == "grp_members") {
157 $ids = ((int) $_GET['search_members']) ? array((int) $_GET['search_members']) : $_POST['search_members'];
158 if ($ids) {
159 $this->mailMembers();
160 } else {
161 ilUtil::sendInfo($this->lng->txt("mail_select_one_entry"));
162 $this->showMembers();
163 }
164 } else {
165 $this->showMyGroups();
166 }
167 }
168
169 public function mailGroups()
170 {
171 $members = array();
172
173 if (!is_array($old_mail_data = $this->umail->getSavedData())) {
174 $this->umail->savePostData(
175 $this->user->getId(),
176 array(),
177 "",
178 "",
179 "",
180 "",
181 "",
182 "",
183 "",
184 ""
185 );
186 }
187
188 require_once './Services/Object/classes/class.ilObject.php';
189 require_once 'Services/Mail/classes/Address/Type/class.ilMailRoleAddressType.php';
190
191 $ids = ((int) $_GET['search_grp']) ? array((int) $_GET['search_grp']) : $_POST['search_grp'];
192 foreach ($ids as $grp_id) {
193 $ref_ids = ilObject::_getAllReferences($grp_id);
194 foreach ($ref_ids as $ref_id) {
195 $can_send_mails = ilParticipants::canSendMailToMembers(
196 (int) $ref_id,
197 $this->user->getId(),
199 );
200 if (!$can_send_mails) {
201 continue;
202 }
203
204 $roles = $this->rbacreview->getAssignableChildRoles($ref_id);
205 foreach ($roles as $role) {
206 if (substr($role['title'], 0, 14) == 'il_grp_member_' ||
207 substr($role['title'], 0, 13) == 'il_grp_admin_') {
208 if (isset($old_mail_data['rcp_to']) &&
209 trim($old_mail_data['rcp_to']) != '') {
210 $rcpt = (new \ilRoleMailboxAddress($role['obj_id']))->value();
211 if (!$this->umail->existsRecipient($rcpt, (string) $old_mail_data['rcp_to'])) {
212 array_push($members, $rcpt);
213 }
214 } else {
215 array_push($members, (new \ilRoleMailboxAddress($role['obj_id']))->value());
216 }
217 }
218 }
219 }
220 }
221
222 if (count($members)) {
223 $mail_data = $this->umail->appendSearchResult($members, 'to');
224 } else {
225 $mail_data = $this->umail->getSavedData();
226 }
227
228 $this->umail->savePostData(
229 $mail_data["user_id"],
230 $mail_data["attachments"],
231 $mail_data["rcp_to"],
232 $mail_data["rcp_cc"],
233 $mail_data["rcp_bcc"],
234 $mail_data["m_email"],
235 $mail_data["m_subject"],
236 $mail_data["m_message"],
237 $mail_data["use_placeholders"],
238 $mail_data['tpl_ctx_id'],
239 $mail_data['tpl_ctx_params']
240 );
241
242 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
243 }
244
245 public function mailMembers()
246 {
247 $members = array();
248
249 if (!is_array($this->umail->getSavedData())) {
250 $this->umail->savePostData(
251 $this->user->getId(),
252 array(),
253 "",
254 "",
255 "",
256 "",
257 "",
258 "",
259 "",
260 ""
261 );
262 }
263
264 $ids = ((int) $_GET['search_members']) ? array((int) $_GET['search_members']) : $_POST['search_members'];
265
266 foreach ($ids as $member) {
268 array_push($members, $login);
269 }
270 $mail_data = $this->umail->appendSearchResult($members, "to");
271
272 $this->umail->savePostData(
273 $mail_data["user_id"],
274 $mail_data["attachments"],
275 $mail_data["rcp_to"],
276 $mail_data["rcp_cc"],
277 $mail_data["rcp_bcc"],
278 $mail_data["m_email"],
279 $mail_data["m_subject"],
280 $mail_data["m_message"],
281 $mail_data["use_placeholders"],
282 $mail_data['tpl_ctx_id'],
283 $mail_data['tpl_ctx_params']
284 );
285
286 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
287 }
288
292 public function cancel()
293 {
294 if ($_GET["view"] == "mygroups" &&
295 $_GET["ref"] == "mail") {
296 $this->ctrl->returnToParent($this);
297 } else {
298 $this->showMyGroups();
299 }
300 }
301
305 public function showMyGroups()
306 {
307 include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
308
309 $this->tpl->setTitle($this->lng->txt('mail_addressbook'));
310
311 $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
312
313 $_GET['view'] = 'mygroups';
314
315 $this->lng->loadLanguageModule('crs');
316
317 $this->ctrl->setParameter($this, 'view', 'mygroups');
318
319 include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
320 $table = new ilMailSearchCoursesTableGUI($this, 'grp', $this->getContext());
321 $table->setId('search_grps_tbl');
322 $grp_ids = ilGroupParticipants::_getMembershipByType($this->user->getId(), 'grp');
323
324 $counter = 0;
325 $tableData = array();
326 if (is_array($grp_ids) &&
327 count($grp_ids) > 0) {
328 $num_groups_hidden_members = 0;
329 include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
330 foreach ($grp_ids as $grp_id) {
334 $oTmpGrp = ilObjectFactory::getInstanceByObjId($grp_id);
335
336 $hasUntrashedReferences = ilObject::_hasUntrashedReference($grp_id);
337 $showMemberListEnabled = (boolean) $oTmpGrp->getShowMembers();
338 $ref_ids = array_keys(ilObject::_getAllReferences($grp_id));
339 $isPrivilegedUser = $this->rbacsystem->checkAccess('write', $ref_ids[0]);
340 $oTmpGrp->setRefId($ref_ids[0]);
341
342 $can_send_mails = ilParticipants::canSendMailToMembers(
343 $oTmpGrp,
344 $this->user->getId(),
346 );
347
348 if ($hasUntrashedReferences && ($showMemberListEnabled || $can_send_mails || $isPrivilegedUser)) {
349 $oGroupParticipants = ilGroupParticipants::_getInstanceByObjId($grp_id);
350 $grp_members = $oGroupParticipants->getParticipants();
351
352 foreach ($grp_members as $key => $member) {
353 $is_active = ilObjUser::_lookupActive($member);
354 if (!$is_active) {
355 unset($grp_members[$key]);
356 }
357 }
358
359 $hiddenMembers = false;
360 if ((int) $oTmpGrp->getShowMembers() == $oTmpGrp->SHOW_MEMBERS_DISABLED) {
361 ++$num_groups_hidden_members;
362 $hiddenMembers = true;
363 }
364 unset($oTmpGrp);
365
366 $ref_ids = ilObject::_getAllReferences($grp_id);
367 $ref_id = current($ref_ids);
368 $path_arr = $this->tree->getPathFull($ref_id, $this->tree->getRootId());
369 $path_counter = 0;
370 $path = '';
371 foreach ($path_arr as $data) {
372 if ($path_counter++) {
373 $path .= " -> ";
374 }
375 $path .= $data['title'];
376 }
377 $path = $this->lng->txt('path') . ': ' . $path;
378
379 $current_selection_list = new ilAdvancedSelectionListGUI();
380 $current_selection_list->setListTitle($this->lng->txt("actions"));
381 $current_selection_list->setId("act_" . $counter);
382
383 $this->ctrl->setParameter($this, 'search_grp', $grp_id);
384 $this->ctrl->setParameter($this, 'view', 'mygroups');
385
386 if ($this->getContext() === 'mail') {
387 if ($this->mailing_allowed && $can_send_mails) {
388 $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
389 }
390 } elseif ($this->getContext() === 'wsp') {
391 $current_selection_list->addItem($this->lng->txt("wsp_share_with_members"), '', $this->ctrl->getLinkTarget($this, "share"));
392 }
393 $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
394
395 $this->ctrl->clearParameters($this);
396
397 $rowData = array(
398 'CRS_ID' => $grp_id,
399 'CRS_NAME' => $this->cache->lookupTitle($grp_id),
400 'CRS_NO_MEMBERS' => count($grp_members),
401 'CRS_PATH' => $path,
402 'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML(),
403 "hidden_members" => $hiddenMembers,
404 "can_send_mails" => $can_send_mails,
405 );
406 $counter++;
407 $tableData[] = $rowData;
408 }
409 }
410 if ($num_groups_hidden_members > 0) {
411 $searchTpl->setCurrentBlock('caption_block');
412 $searchTpl->setVariable('TXT_LIST_MEMBERS_NOT_AVAILABLE', $this->lng->txt('mail_crs_list_members_not_available'));
413 $searchTpl->parseCurrentBlock();
414 }
415 }
416 $table->setData($tableData);
417 if ($counter > 0) {
418 $this->tpl->setVariable('TXT_MARKED_ENTRIES', $this->lng->txt('marked_entries'));
419 }
420
421 $searchTpl->setVariable('TABLE', $table->getHTML());
422 $this->tpl->setContent($searchTpl->get());
423
424 if ($_GET["ref"] != "wsp") {
425 $this->tpl->printToStdout();
426 }
427 }
428
432 public function showMembers()
433 {
434 if ($_GET["search_grp"] != "") {
435 $_POST["search_grp"] = explode(",", $_GET["search_grp"]);
436 }
437
438 if (!is_array($_POST["search_grp"]) ||
439 count($_POST["search_grp"]) == 0) {
440 ilUtil::sendInfo($this->lng->txt("mail_select_group"));
441 $this->showMyGroups();
442 } else {
443 $this->tpl->setTitle($this->lng->txt("mail_addressbook"));
444 include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
445 $context = $_GET["ref"] ? $_GET["ref"] : "mail";
446 $table = new ilMailSearchCoursesMembersTableGUI($this, 'grp', $context, $_POST["search_grp"]);
447 $this->lng->loadLanguageModule('crs');
448
449 $tableData = array();
450 $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
451
452 foreach ($_POST["search_grp"] as $grp_id) {
453 $ref_ids = ilObject::_getAllReferences($grp_id);
454 $ref_id = current($ref_ids);
455
456 if (is_object($group_obj = ilObjectFactory::getInstanceByRefId($ref_id, false))) {
457 $grp_members = $group_obj->getGroupMemberData($group_obj->getGroupMemberIds());
458
459 foreach ($grp_members as $member) {
460 $tmp_usr = new ilObjUser($member['id']);
461 if (!$tmp_usr->getActive()) {
462 continue;
463 }
464
465 $fullname = "";
466 if (in_array(ilObjUser::_lookupPref($member['id'], 'public_profile'), array("g", 'y'))) {
467 $fullname = $member['lastname'] . ', ' . $member['firstname'];
468 }
469
470 $rowData = array(
471 'members_id' => $member["id"],
472 'members_login' => $member["login"],
473 'members_name' => $fullname,
474 'members_crs_grp' => $group_obj->getTitle(),
475 'search_grp' => $grp_id,
476 );
477
478 if ('mail' == $context && ilBuddySystem::getInstance()->isEnabled()) {
479 $relation = ilBuddyList::getInstanceByGlobalUser()->getRelationByUserId($member['id']);
480 $state_name = ilStr::convertUpperCamelCaseToUnderscoreCase($relation->getState()->getName());
481 $rowData['status'] = '';
482 if ($member['id'] != $this->user->getId()) {
483 if ($relation->isOwnedByActor()) {
484 $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_a');
485 } else {
486 $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_p');
487 }
488 }
489 }
490
491 $tableData[] = $rowData;
492 }
493 }
494 }
495 $table->setData($tableData);
496 if (count($tableData)) {
497 $searchTpl->setVariable("TXT_MARKED_ENTRIES", $this->lng->txt("marked_entries"));
498 }
499 $searchTpl->setVariable('TABLE', $table->getHTML());
500 $this->tpl->setContent($searchTpl->get());
501
502 if ($_GET["ref"] != "wsp") {
503 $this->tpl->printToStdout();
504 }
505 }
506 }
507
508 public function share()
509 {
510 if ($_GET["view"] == "mygroups") {
511 $ids = $_REQUEST["search_grp"];
512 if (!is_array($ids) && $ids !== "") {
513 $ids = [$ids];
514 }
515 if (is_array($ids) && count($ids)) {
516 $this->addPermission($ids);
517 } else {
518 ilUtil::sendInfo($this->lng->txt("mail_select_group"));
519 $this->showMyGroups();
520 }
521 } elseif ($_GET["view"] == "grp_members") {
522 $ids = $_REQUEST["search_members"];
523 if (is_array($ids) && count($ids)) {
524 $this->addPermission($ids);
525 } else {
526 ilUtil::sendInfo($this->lng->txt("mail_select_one_entry"));
527 $this->showMembers();
528 }
529 } else {
530 $this->showMyGroups();
531 }
532 }
533
534 protected function addPermission($a_obj_ids)
535 {
536 if (!is_array($a_obj_ids)) {
537 $a_obj_ids = array($a_obj_ids);
538 }
539
540 $existing = $this->wsp_access_handler->getPermissions($this->wsp_node_id);
541 $added = false;
542 foreach ($a_obj_ids as $object_id) {
543 if (!in_array($object_id, $existing)) {
544 $added = $this->wsp_access_handler->addPermission($this->wsp_node_id, $object_id);
545 }
546 }
547
548 if ($added) {
549 ilUtil::sendSuccess($this->lng->txt("wsp_share_success"), true);
550 }
551 $this->ctrl->redirectByClass("ilworkspaceaccessgui", "share");
552 }
553}
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
User interface class for advanced drop-down selection lists.
static getInstanceByGlobalUser()
Class ilBuddySystemGUI.
Class UserMail this class handles user mails.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable.
__construct($wsp_access_handler=null, $wsp_node_id=null)
static _lookupPref($a_usr_id, $a_keyword)
static _lookupLogin($a_user_id)
lookup login
static _lookupActive($a_usr_id)
Check user account active.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _getAllReferences($a_id)
get all reference ids of object
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
static canSendMailToMembers( $ref_id_or_instance, ?int $usr_id=null, ?int $mail_obj_ref_id=null)
This method was introduced as a band-aid fix for #22764.
Class ilRoleMailboxAddress.
static convertUpperCamelCaseToUnderscoreCase($value)
Convert a value given in camel case conversion to underscore case conversion (e.g.
special template class to simplify handling of ITX/PEAR
static redirect($a_script)
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$login
Definition: cron.php:13
global $DIC
Definition: goto.php:24
$data
Definition: storeScorm.php:23
$context
Definition: webdav.php:26