ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMailSearchCoursesGUI.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;
67
73 protected $rerfinery;
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 // check if current user may send mails
95 include_once "Services/Mail/classes/class.ilMail.php";
96 $mail = new ilMail($this->user->getId());
97 $this->mailing_allowed = $this->rbacsystem->checkAccess('internal_mail', $mail->getMailObjectReferenceId());
98
99 $this->ctrl->saveParameter($this, "mobj_id");
100 $this->ctrl->saveParameter($this, "ref");
101
102 $this->umail = new ilFormatMail($this->user->getId());
103 }
104
105 private function getContext() : string
106 {
107 $context = 'mail';
108 if (isset($_GET['ref'])) {
109 $always = $context;
110 $context = $this->refinery->byTrying([
111 $this->refinery->kindlyTo()->string(),
112 $this->refinery->custom()->transformation(static function ($value) use ($always) {
113 return $always;
114 }),
115 ])->transform($_GET['ref']);
116 }
117
118 return $context;
119 }
120
121 public function executeCommand()
122 {
123 $forward_class = $this->ctrl->getNextClass($this);
124 switch ($forward_class) {
125 case 'ilbuddysystemgui':
126 if (!ilBuddySystem::getInstance()->isEnabled()) {
127 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
128 }
129
130 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemGUI.php';
131 $this->ctrl->saveParameter($this, 'search_crs');
132 $this->ctrl->setReturn($this, 'showMembers');
133 $this->ctrl->forwardCommand(new ilBuddySystemGUI());
134 break;
135
136 default:
137 if (!($cmd = $this->ctrl->getCmd())) {
138 $cmd = "showMyCourses";
139 }
140
141 $this->$cmd();
142 break;
143 }
144 return true;
145 }
146
147 public function mail()
148 {
149 if ($_GET["view"] == "mycourses") {
150 $ids = ((int) $_GET['search_crs']) ? array((int) $_GET['search_crs']) : $_POST['search_crs'];
151
152 if ($ids) {
153 $this->mailCourses();
154 } else {
155 ilUtil::sendInfo($this->lng->txt("mail_select_course"));
156 $this->showMyCourses();
157 }
158 } elseif ($_GET["view"] == "crs_members") {
159 $ids = ((int) $_GET['search_members']) ? array((int) $_GET['search_members']) : $_POST['search_members'];
160 if ($ids) {
161 $this->mailMembers();
162 } else {
163 ilUtil::sendInfo($this->lng->txt("mail_select_one_entry"));
164 $this->showMembers();
165 }
166 } else {
167 $this->showMyCourses();
168 }
169 }
170
171 public function mailCourses()
172 {
173 $members = array();
174
175 if (!is_array($old_mail_data = $this->umail->getSavedData())) {
176 $this->umail->savePostData(
177 $this->user->getId(),
178 array(),
179 "",
180 "",
181 "",
182 "",
183 "",
184 "",
185 "",
186 ""
187 );
188 }
189
190 require_once './Services/Object/classes/class.ilObject.php';
191 require_once 'Services/Mail/classes/Address/Type/class.ilMailRoleAddressType.php';
192 $ids = ((int) $_GET['search_crs']) ? array((int) $_GET['search_crs']) : $_POST['search_crs'];
193
194 foreach ($ids as $crs_id) {
195 $ref_ids = ilObject::_getAllReferences($crs_id);
196
197 foreach ($ref_ids as $ref_id) {
198 $roles = $this->rbacreview->getAssignableChildRoles($ref_id);
199 $can_send_mails = ilParticipants::canSendMailToMembers(
200 (int) $ref_id,
201 $this->user->getId(),
203 );
204 if (!$can_send_mails) {
205 continue;
206 }
207
208 foreach ($roles as $role) {
209 if (substr($role['title'], 0, 14) == 'il_crs_member_' ||
210 substr($role['title'], 0, 13) == 'il_crs_tutor_' ||
211 substr($role['title'], 0, 13) == 'il_crs_admin_') {
212 if (isset($old_mail_data['rcp_to']) &&
213 trim($old_mail_data['rcp_to']) != '') {
214 $rcpt = (new \ilRoleMailboxAddress($role['obj_id']))->value();
215 if (!$this->umail->existsRecipient($rcpt, (string) $old_mail_data['rcp_to'])) {
216 array_push($members, $rcpt);
217 }
218 } else {
219 array_push($members, (new \ilRoleMailboxAddress($role['obj_id']))->value());
220 }
221 }
222 }
223 }
224 }
225
226 if (count($members)) {
227 $mail_data = $this->umail->appendSearchResult($members, 'to');
228 } else {
229 $mail_data = $this->umail->getSavedData();
230 }
231
232 $this->umail->savePostData(
233 $mail_data["user_id"],
234 $mail_data["attachments"],
235 $mail_data["rcp_to"],
236 $mail_data["rcp_cc"],
237 $mail_data["rcp_bcc"],
238 $mail_data["m_email"],
239 $mail_data["m_subject"],
240 $mail_data["m_message"],
241 $mail_data["use_placeholders"],
242 $mail_data['tpl_ctx_id'],
243 $mail_data['tpl_ctx_params']
244 );
245
246 #$this->ctrl->returnToParent($this);
247 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
248 }
249
250 public function mailMembers()
251 {
252 $members = array();
253
254 if (!is_array($this->umail->getSavedData())) {
255 $this->umail->savePostData(
256 $this->user->getId(),
257 array(),
258 "",
259 "",
260 "",
261 "",
262 "",
263 "",
264 "",
265 ""
266 );
267 }
268
269 $ids = ((int) $_GET['search_members']) ? array((int) $_GET['search_members']) : $_POST['search_members'];
270
271 foreach ($ids as $member) {
273 array_push($members, $login);
274 }
275 $mail_data = $this->umail->appendSearchResult($members, "to");
276
277 $this->umail->savePostData(
278 $mail_data["user_id"],
279 $mail_data["attachments"],
280 $mail_data["rcp_to"],
281 $mail_data["rcp_cc"],
282 $mail_data["rcp_bcc"],
283 $mail_data["m_email"],
284 $mail_data["m_subject"],
285 $mail_data["m_message"],
286 $mail_data["use_placeholders"],
287 $mail_data['tpl_ctx_id'],
288 $mail_data['tpl_ctx_params']
289 );
290
291 #$this->ctrl->returnToParent($this);
292 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
293 }
294
298 public function cancel()
299 {
300 if ($_GET["view"] == "mycourses" &&
301 $_GET["ref"] == "mail") {
302 $this->ctrl->returnToParent($this);
303 } else {
304 $this->showMyCourses();
305 }
306 }
307
311 public function showMyCourses()
312 {
313 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
314
315 $this->tpl->setTitle($this->lng->txt('mail_addressbook'));
316
317 $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
318
319 $_GET['view'] = 'mycourses';
320
321 $this->lng->loadLanguageModule('crs');
322
323 include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
324 $table = new ilMailSearchCoursesTableGUI($this, "crs", $this->getContext());
325 $table->setId('search_crs_tbl');
326 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
327 $crs_ids = ilCourseParticipants::_getMembershipByType($this->user->getId(), 'crs');
328 $counter = 0;
329 $tableData = array();
330 if (is_array($crs_ids) && count($crs_ids) > 0) {
331 $num_courses_hidden_members = 0;
332 include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
333 foreach ($crs_ids as $crs_id) {
337 $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
338
339 $isOffline = !$oTmpCrs->isActivated();
340 $hasUntrashedReferences = ilObject::_hasUntrashedReference($crs_id);
341 $showMemberListEnabled = (boolean) $oTmpCrs->getShowMembers();
342 $ref_ids = array_keys(ilObject::_getAllReferences($crs_id));
343 $isPrivilegedUser = $this->rbacsystem->checkAccess('write', $ref_ids[0]);
344 $oTmpCrs->setRefId($ref_ids[0]);
345
346 $can_send_mails = ilParticipants::canSendMailToMembers(
347 $oTmpCrs,
348 $this->user->getId(),
350 );
351
352 if ($hasUntrashedReferences &&
353 ((!$isOffline && ($showMemberListEnabled || $can_send_mails)) || $isPrivilegedUser)) {
354 $oCrsParticipants = ilCourseParticipants::_getInstanceByObjId($crs_id);
355 $crs_members = $oCrsParticipants->getParticipants();
356
357 foreach ($crs_members as $key => $member) {
358 $is_active = ilObjUser::_lookupActive($member);
359 if (!$is_active) {
360 unset($crs_members[$key]);
361 }
362 }
363
364 $hiddenMembers = false;
365 if ((int) $oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED) {
366 ++$num_courses_hidden_members;
367 $hiddenMembers = true;
368 }
369 unset($oTmpCrs);
370
371 $ref_ids = ilObject::_getAllReferences($crs_id);
372 $ref_id = current($ref_ids);
373 $path_arr = $this->tree->getPathFull($ref_id, $this->tree->getRootId());
374 $path_counter = 0;
375 $path = '';
376 foreach ($path_arr as $data) {
377 if ($path_counter++) {
378 $path .= " -> ";
379 }
380 $path .= $data['title'];
381 }
382 $path = $this->lng->txt('path') . ': ' . $path;
383
384 $current_selection_list = new ilAdvancedSelectionListGUI();
385 $current_selection_list->setListTitle($this->lng->txt("actions"));
386 $current_selection_list->setId("act_" . $counter);
387
388 $this->ctrl->setParameter($this, 'search_crs', $crs_id);
389 $this->ctrl->setParameter($this, 'view', 'mycourses');
390
391 if ($this->getContext() === 'mail') {
392 if ($this->mailing_allowed && $can_send_mails) {
393 $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
394 }
395 } elseif ($this->getContext() === 'wsp') {
396 $current_selection_list->addItem($this->lng->txt("wsp_share_with_members"), '', $this->ctrl->getLinkTarget($this, "share"));
397 }
398 $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
399
400 $this->ctrl->clearParameters($this);
401
402 $rowData = array(
403 "CRS_ID" => $crs_id,
404 "CRS_NAME" => $this->cache->lookupTitle($crs_id),
405 "CRS_NO_MEMBERS" => count($crs_members),
406 "CRS_PATH" => $path,
407 'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML(),
408 "hidden_members" => $hiddenMembers,
409 "can_send_mails" => $can_send_mails,
410 );
411 $counter++;
412 $tableData[] = $rowData;
413 }
414 }
415
416 if ($num_courses_hidden_members > 0) {
417 $searchTpl->setCurrentBlock('caption_block');
418 $searchTpl->setVariable('TXT_LIST_MEMBERS_NOT_AVAILABLE', $this->lng->txt('mail_crs_list_members_not_available'));
419 $searchTpl->parseCurrentBlock();
420 }
421 }
422
423 $searchTpl->setVariable('TXT_MARKED_ENTRIES', $this->lng->txt('marked_entries'));
424
425 $table->setData($tableData);
426 if ($_GET['ref'] == 'mail') {
427 $this->tpl->setVariable('BUTTON_CANCEL', $this->lng->txt('cancel'));
428 }
429
430 $searchTpl->setVariable('TABLE', $table->getHtml());
431 $this->tpl->setContent($searchTpl->get());
432
433 if ($_GET["ref"] != "wsp") {
434 $this->tpl->printToStdout();
435 }
436 }
437
441 public function showMembers()
442 {
443 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
444
445 if ($_GET["search_crs"] != "") {
446 $_POST["search_crs"] = explode(",", $_GET["search_crs"]);
447 $_GET["search_crs"] = "";
448 } elseif ($_SESSION["search_crs"] != "") {
449 $_POST["search_crs"] = explode(",", $_SESSION["search_crs"]);
450 $_SESSION["search_crs"] = "";
451 }
452
453 if (is_array($_POST['search_crs'])) {
454 $_POST['search_crs'] = array_filter(array_map('intval', $_POST['search_crs']));
455 }
456
457 if (!is_array($_POST["search_crs"]) ||
458 count($_POST["search_crs"]) == 0) {
459 ilUtil::sendInfo($this->lng->txt("mail_select_course"));
460 $this->showMyCourses();
461 } else {
462 foreach ($_POST['search_crs'] as $crs_id) {
463 $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
464 if ($oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED) {
465 unset($_POST['search_crs']);
466 ilUtil::sendInfo($this->lng->txt('mail_crs_list_members_not_available_for_at_least_one_crs'));
467 return $this->showMyCourses();
468 }
469 unset($oTmpCrs);
470 }
471
472 $this->tpl->setTitle($this->lng->txt("mail_addressbook"));
473
474 $this->ctrl->setParameter($this, "view", "crs_members");
475 if ($_GET["ref"] != "") {
476 $this->ctrl->setParameter($this, "ref", $_GET["ref"]);
477 }
478 if (is_array($_POST["search_crs"])) {
479 $this->ctrl->setParameter($this, "search_crs", implode(",", $_POST["search_crs"]));
480 }
481 $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this));
482 $this->ctrl->clearParameters($this);
483
484 $this->lng->loadLanguageModule('crs');
485 include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
486 $context = $_GET["ref"] ? $_GET["ref"] : "mail";
487 $table = new ilMailSearchCoursesMembersTableGUI($this, 'crs', $context, $_POST["search_crs"]);
488 $tableData = array();
489 $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
490 foreach ($_POST["search_crs"] as $crs_id) {
491 $members_obj = ilCourseParticipants::_getinstanceByObjId($crs_id);
492 $tmp_members = $members_obj->getParticipants();
493 $course_members = ilUtil::_sortIds($tmp_members, 'usr_data', 'lastname', 'usr_id');
494
495 foreach ($course_members as $member) {
496 $tmp_usr = new ilObjUser($member);
497 if (!$tmp_usr->getActive()) {
498 continue;
499 }
500
501 $name = ilObjUser::_lookupName($member);
503
504 $fullname = "";
505 if (in_array(ilObjUser::_lookupPref($member, 'public_profile'), array("g", 'y'))) {
506 $fullname = $name['lastname'] . ', ' . $name['firstname'];
507 }
508
509 $rowData = array(
510 'members_id' => $member,
511 'members_login' => $login,
512 'members_name' => $fullname,
513 'members_crs_grp' => $this->cache->lookupTitle($crs_id),
514 'search_crs' => $crs_id
515 );
516
517 if ('mail' == $context && ilBuddySystem::getInstance()->isEnabled()) {
518 $relation = ilBuddyList::getInstanceByGlobalUser()->getRelationByUserId($member);
519 $state_name = ilStr::convertUpperCamelCaseToUnderscoreCase($relation->getState()->getName());
520 $rowData['status'] = '';
521 if ($member != $this->user->getId()) {
522 if ($relation->isOwnedByActor()) {
523 $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_a');
524 } else {
525 $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_p');
526 }
527 }
528 }
529
530 $tableData[] = $rowData;
531 }
532 }
533 $table->setData($tableData);
534
535 if (count($tableData)) {
536 $searchTpl->setVariable("TXT_MARKED_ENTRIES", $this->lng->txt("marked_entries"));
537 }
538
539 $searchTpl->setVariable('TABLE', $table->getHtml());
540 $this->tpl->setContent($searchTpl->get());
541
542 if ($_GET["ref"] != "wsp") {
543 $this->tpl->printToStdout();
544 }
545 }
546 }
547
548 public function share()
549 {
550 if ($_GET["view"] == "mycourses") {
551 $ids = $_REQUEST["search_crs"];
552 if (!is_array($ids) && $ids !== "") {
553 $ids = [$ids];
554 }
555 if (is_array($ids) && sizeof($ids)) {
556 $this->addPermission($ids);
557 } else {
558 ilUtil::sendInfo($this->lng->txt("mail_select_course"));
559 $this->showMyCourses();
560 }
561 } elseif ($_GET["view"] == "crs_members") {
562 $ids = $_REQUEST["search_members"];
563 if (is_array($ids) && sizeof($ids)) {
564 $this->addPermission($ids);
565 } else {
566 ilUtil::sendInfo($this->lng->txt("mail_select_one_entry"));
567 $this->showMembers();
568 }
569 } else {
570 $this->showMyCourses();
571 }
572 }
573
574 protected function addPermission($a_obj_ids)
575 {
576 if (!is_array($a_obj_ids)) {
577 $a_obj_ids = array($a_obj_ids);
578 }
579
580 $existing = $this->wsp_access_handler->getPermissions($this->wsp_node_id);
581 $added = false;
582 foreach ($a_obj_ids as $object_id) {
583 if (!in_array($object_id, $existing)) {
584 $added = $this->wsp_access_handler->addPermission($this->wsp_node_id, $object_id);
585 }
586 }
587
588 if ($added) {
589 ilUtil::sendSuccess($this->lng->txt("wsp_share_success"), true);
590 }
591 $this->ctrl->redirectByClass("ilworkspaceaccessgui", "share");
592 }
593}
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
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.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Class UserMail this class handles user mails.
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 _lookupName($a_user_id)
lookup user name
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 _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 _sortIds($a_ids, $a_table, $a_field, $a_id_name)
Function that sorts ids by a given table field using WHERE IN E.g: __sort(array(6,...
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
if($format !==null) $name
Definition: metadata.php:230
$data
Definition: storeScorm.php:23
$context
Definition: webdav.php:26