ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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;
67
72
73 public function __construct($wsp_access_handler = null, $wsp_node_id = null)
74 {
75 global $DIC;
76
77 $this->tpl = $DIC['tpl'];
78 $this->ctrl = $DIC['ilCtrl'];
79 $this->lng = $DIC['lng'];
80 $this->user = $DIC['ilUser'];
81 $this->error = $DIC['ilErr'];
82 $this->rbacsystem = $DIC['rbacsystem'];
83 $this->rbacreview = $DIC['rbacreview'];
84 $this->tree = $DIC['tree'];
85 $this->cache = $DIC['ilObjDataCache'];
86
87 // personal workspace
88 $this->wsp_access_handler = $wsp_access_handler;
89 $this->wsp_node_id = $wsp_node_id;
90
91 $this->ctrl->saveParameter($this, "mobj_id");
92 $this->ctrl->saveParameter($this, "ref");
93
94 include_once "Services/Mail/classes/class.ilMail.php";
95 $mail = new ilMail($this->user->getId());
96 $this->mailing_allowed = $this->rbacsystem->checkAccess('internal_mail', $mail->getMailObjectReferenceId());
97
98 $this->umail = new ilFormatMail($this->user->getId());
99 }
100
101 public function executeCommand()
102 {
103 $forward_class = $this->ctrl->getNextClass($this);
104 switch($forward_class)
105 {
106 case 'ilbuddysystemgui':
107 if(!ilBuddySystem::getInstance()->isEnabled())
108 {
109 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
110 }
111
112 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemGUI.php';
113 $this->ctrl->saveParameter($this, 'search_grp');
114 $this->ctrl->setReturn($this, 'showMembers');
115 $this->ctrl->forwardCommand(new ilBuddySystemGUI());
116 break;
117
118 default:
119 if (!($cmd = $this->ctrl->getCmd()))
120 {
121 $cmd = "showMyGroups";
122 }
123
124 $this->$cmd();
125 break;
126 }
127 return true;
128 }
129
130 function mail()
131 {
132 if ($_GET["view"] == "mygroups")
133 {
134 $ids = ((int) $_GET['search_grp']) ? array((int)$_GET['search_grp']) : $_POST['search_grp'];
135 if ($ids)
136 {
137 $this->mailGroups();
138 }
139 else
140 {
141 ilUtil::sendInfo($this->lng->txt("mail_select_group"));
142 $this->showMyGroups();
143 }
144 }
145 else if ($_GET["view"] == "grp_members")
146 {
147 $ids = ((int) $_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
148 if ($ids)
149 {
150 $this->mailMembers();
151 }
152 else
153 {
154 ilUtil::sendInfo($this->lng->txt("mail_select_one_entry"));
155 $this->showMembers();
156 }
157 }
158 else
159 {
160 $this->showMyGroups();
161 }
162 }
163
164 function mailGroups()
165 {
166 $members = array();
167
168 if (!is_array($old_mail_data = $this->umail->getSavedData()))
169 {
170 $this->umail->savePostData(
171 $this->user->getId(),
172 array(),
173 "",
174 "",
175 "",
176 "",
177 "",
178 "",
179 "",
180 ""
181 );
182 }
183
184 require_once './Services/Object/classes/class.ilObject.php';
185 require_once 'Services/Mail/classes/Address/Type/class.ilMailRoleAddressType.php';
186
187 $ids = ((int) $_GET['search_grp']) ? array((int)$_GET['search_grp']) : $_POST['search_grp'];
188 foreach ($ids as $grp_id)
189 {
190 $ref_ids = ilObject::_getAllReferences($grp_id);
191 foreach ($ref_ids as $ref_id)
192 {
193 $roles = $this->rbacreview->getAssignableChildRoles($ref_id);
194 foreach ($roles as $role)
195 {
196 if (substr($role['title'], 0, 14) == 'il_grp_member_' ||
197 substr($role['title'], 0, 13) == 'il_grp_admin_')
198 {
199 if(isset($old_mail_data['rcp_to']) &&
200 trim($old_mail_data['rcp_to']) != '')
201 {
202 $rcpt = ilMailRoleAddressType::getRoleMailboxAddress($role['obj_id']);
203 if(!$this->umail->existsRecipient($rcpt, $old_mail_data['rcp_to']))
204 {
205 array_push($members, $rcpt);
206 }
207 }
208 else
209 {
210 array_push($members, ilMailRoleAddressType::getRoleMailboxAddress($role['obj_id']));
211 }
212 }
213 }
214 }
215 }
216
217 if(count($members))
218 $mail_data = $this->umail->appendSearchResult($members, 'to');
219 else
220 $mail_data = $this->umail->getSavedData();
221
222 $this->umail->savePostData(
223 $mail_data["user_id"],
224 $mail_data["attachments"],
225 $mail_data["rcp_to"],
226 $mail_data["rcp_cc"],
227 $mail_data["rcp_bcc"],
228 $mail_data["m_type"],
229 $mail_data["m_email"],
230 $mail_data["m_subject"],
231 $mail_data["m_message"],
232 $mail_data["use_placeholders"],
233 $mail_data['tpl_ctx_id'],
234 $mail_data['tpl_ctx_params']
235 );
236
237 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
238 }
239
240 function mailMembers()
241 {
242 $members = array();
243
244 if (!is_array($this->umail->getSavedData()))
245 {
246 $this->umail->savePostData(
247 $this->user->getId(),
248 array(),
249 "",
250 "",
251 "",
252 "",
253 "",
254 "",
255 "",
256 ""
257 );
258 }
259
260 $ids = ((int) $_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
261
262 foreach ($ids as $member)
263 {
264 $login = ilObjUser::_lookupLogin($member);
265 array_push($members, $login);
266 }
267 $mail_data = $this->umail->appendSearchResult($members,"to");
268
269 $this->umail->savePostData(
270 $mail_data["user_id"],
271 $mail_data["attachments"],
272 $mail_data["rcp_to"],
273 $mail_data["rcp_cc"],
274 $mail_data["rcp_bcc"],
275 $mail_data["m_type"],
276 $mail_data["m_email"],
277 $mail_data["m_subject"],
278 $mail_data["m_message"],
279 $mail_data["use_placeholders"],
280 $mail_data['tpl_ctx_id'],
281 $mail_data['tpl_ctx_params']
282 );
283
284 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
285 }
286
290 function cancel()
291 {
292 if ($_GET["view"] == "mygroups" &&
293 $_GET["ref"] == "mail")
294 {
295 $this->ctrl->returnToParent($this);
296 }
297 else
298 {
299 $this->showMyGroups();
300 }
301 }
302
306 public function showMyGroups()
307 {
308 include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
309
310 $this->tpl->setTitle($this->lng->txt('mail_addressbook'));
311
312 $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
313
314 $_GET['view'] = 'mygroups';
315
316 $this->lng->loadLanguageModule('crs');
317
318 $this->ctrl->setParameter($this, 'view', 'mygroups');
319
320 include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
321 $table = new ilMailSearchCoursesTableGUI($this, 'grp', $_GET["ref"]);
322 $table->setId('search_grps_tbl');
323 $grp_ids = ilGroupParticipants::_getMembershipByType($this->user->getId(), 'grp');
324
325 $counter = 0;
326 $tableData = array();
327 if (is_array($grp_ids) &&
328 count($grp_ids) > 0)
329 {
330 $num_groups_hidden_members = 0;
331 include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
332 foreach($grp_ids as $grp_id)
333 {
337 $oTmpGrp = ilObjectFactory::getInstanceByObjId($grp_id);
338
339 $hasUntrashedReferences = ilObject::_hasUntrashedReference($grp_id);
340 $showMemberListEnabled = (boolean)$oTmpGrp->getShowMembers();
341 $ref_ids = array_keys(ilObject::_getAllReferences($grp_id));
342 $isPrivilegedUser = $this->rbacsystem->checkAccess('write', $ref_ids[0]);
343
344 if($hasUntrashedReferences && ($showMemberListEnabled || $isPrivilegedUser))
345 {
346 $oGroupParticipants = ilGroupParticipants::_getInstanceByObjId($grp_id);
347 $grp_members = $oGroupParticipants->getParticipants();
348
349 foreach ($grp_members as $key => $member)
350 {
351 $tmp_usr = new ilObjUser($member);
352
353 if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
354 {
355 unset($grp_members[$key]);
356 }
357 }
358 unset($tmp_usr);
359
360 $hiddenMembers = false;
361 if((int)$oTmpGrp->getShowMembers() == $oTmpGrp->SHOW_MEMBERS_DISABLED)
362 {
363 ++$num_groups_hidden_members;
364 $hiddenMembers = true;
365 }
366 unset($oTmpGrp);
367
368 $ref_ids = ilObject::_getAllReferences($grp_id);
369 $ref_id = current($ref_ids);
370 $path_arr = $this->tree->getPathFull($ref_id, $this->tree->getRootId());
371 $path_counter = 0;
372 $path = '';
373 foreach($path_arr as $data)
374 {
375 if($path_counter++)
376 {
377 $path .= " -> ";
378 }
379 $path .= $data['title'];
380 }
381 $path = $this->lng->txt('path').': '.$path;
382
383 $current_selection_list = new ilAdvancedSelectionListGUI();
384 $current_selection_list->setListTitle($this->lng->txt("actions"));
385 $current_selection_list->setId("act_".$counter);
386
387 $this->ctrl->setParameter($this, 'search_grp', $grp_id);
388 $this->ctrl->setParameter($this, 'view', 'mygroups');
389
390 if($_GET["ref"] == "mail")
391 {
392 if ($this->mailing_allowed)
393 $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
394 }
395 else if($_GET["ref"] == "wsp")
396 {
397 $current_selection_list->addItem($this->lng->txt("wsp_share_with_members"), '', $this->ctrl->getLinkTarget($this, "share"));
398 }
399 $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
400
401 $this->ctrl->clearParameters($this);
402
403 $rowData = array
404 (
405 'CRS_ID' => $grp_id,
406 'CRS_NAME' => $this->cache->lookupTitle($grp_id),
407 'CRS_NO_MEMBERS' => count($grp_members),
408 'CRS_PATH' => $path,
409 'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML(),
410 "hidden_members" => $hiddenMembers
411 );
412 $counter++;
413 $tableData[] = $rowData;
414 }
415 }
416 if($num_groups_hidden_members > 0)
417 {
418 $searchTpl->setCurrentBlock('caption_block');
419 $searchTpl->setVariable('TXT_LIST_MEMBERS_NOT_AVAILABLE', $this->lng->txt('mail_crs_list_members_not_available'));
420 $searchTpl->parseCurrentBlock();
421 }
422 }
423 $table->setData($tableData);
424 if($counter > 0)
425 {
426 $this->tpl->setVariable('TXT_MARKED_ENTRIES', $this->lng->txt('marked_entries'));
427 }
428
429 $searchTpl->setVariable('TABLE', $table->getHTML());
430 $this->tpl->setContent($searchTpl->get());
431
432 if($_GET["ref"] != "wsp")
433 {
434 $this->tpl->show();
435 }
436 }
437
441 public function showMembers()
442 {
443 if ($_GET["search_grp"] != "")
444 {
445 $_POST["search_grp"] = explode(",", $_GET["search_grp"]);
446 }
447
448 if (!is_array($_POST["search_grp"]) ||
449 count($_POST["search_grp"]) == 0)
450 {
451 ilUtil::sendInfo($this->lng->txt("mail_select_group"));
452 $this->showMyGroups();
453 }
454 else
455 {
456 $this->tpl->setTitle($this->lng->txt("mail_addressbook"));
457 include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
458 $context = $_GET["ref"] ? $_GET["ref"] : "mail";
459 $table = new ilMailSearchCoursesMembersTableGUI($this, 'grp', $context);
460 $this->lng->loadLanguageModule('crs');
461
462 $tableData = array();
463 $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
464
465 foreach($_POST["search_grp"] as $grp_id)
466 {
467 $ref_ids = ilObject::_getAllReferences($grp_id);
468 $ref_id = current($ref_ids);
469
470 if (is_object($group_obj = ilObjectFactory::getInstanceByRefId($ref_id,false)))
471 {
472 $grp_members = $group_obj->getGroupMemberData($group_obj->getGroupMemberIds());
473
474 foreach($grp_members as $member)
475 {
476 $tmp_usr = new ilObjUser($member['id']);
477 if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
478 {
479 unset($tmp_usr);
480 continue;
481 }
482 unset($tmp_usr);
483
484 $fullname = "";
485 if(in_array(ilObjUser::_lookupPref($member['id'], 'public_profile'), array("g", 'y')))
486 $fullname = $member['lastname'].', '.$member['firstname'];
487
488 $rowData = array(
489 'members_id' => $member["id"],
490 'members_login' => $member["login"],
491 'members_name' => $fullname,
492 'members_crs_grp' => $group_obj->getTitle(),
493 'search_grp' => $grp_id,
494 );
495
496 if('mail' == $context && ilBuddySystem::getInstance()->isEnabled())
497 {
498 $relation = ilBuddyList::getInstanceByGlobalUser()->getRelationByUserId($member['id']);
499 $state_name = ilStr::convertUpperCamelCaseToUnderscoreCase($relation->getState()->getName());
500 $rowData['status'] = '';
501 if($member['id'] != $this->user->getId())
502 {
503 if($relation->isOwnedByRequest())
504 {
505 $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_a');
506 }
507 else
508 {
509 $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_p');
510 }
511 }
512 }
513
514 $tableData[] = $rowData;
515 }
516 }
517 }
518 $table->setData($tableData);
519 if (count($tableData))
520 {
521 $searchTpl->setVariable("TXT_MARKED_ENTRIES", $this->lng->txt("marked_entries"));
522 }
523 $searchTpl->setVariable('TABLE', $table->getHTML());
524 $this->tpl->setContent($searchTpl->get());
525
526 if($_GET["ref"] != "wsp")
527 {
528 $this->tpl->show();
529 }
530 }
531 }
532
533 function share()
534 {
535 if ($_GET["view"] == "mygroups")
536 {
537 $ids = $_REQUEST["search_grp"];
538 if (sizeof($ids))
539 {
540 $this->addPermission($ids);
541 }
542 else
543 {
544 ilUtil::sendInfo($this->lng->txt("mail_select_course"));
545 $this->showMyGroups();
546 }
547 }
548 else if ($_GET["view"] == "grp_members")
549 {
550 $ids = $_REQUEST["search_members"];
551 if (sizeof($ids))
552 {
553 $this->addPermission($ids);
554 }
555 else
556 {
557 ilUtil::sendInfo($this->lng->txt("mail_select_one_entry"));
558 $this->showMembers();
559 }
560 }
561 else
562 {
563 $this->showMyGroups();
564 }
565 }
566
567 protected function addPermission($a_obj_ids)
568 {
569 if(!is_array($a_obj_ids))
570 {
571 $a_obj_ids = array($a_obj_ids);
572 }
573
574 $existing = $this->wsp_access_handler->getPermissions($this->wsp_node_id);
575 $added = false;
576 foreach($a_obj_ids as $object_id)
577 {
578 if(!in_array($object_id, $existing))
579 {
580 $added = $this->wsp_access_handler->addPermission($this->wsp_node_id, $object_id);
581 }
582 }
583
584 if($added)
585 {
586 ilUtil::sendSuccess($this->lng->txt("wsp_share_success"), true);
587 }
588 $this->ctrl->redirectByClass("ilworkspaceaccessgui", "share");
589 }
590}
user()
Definition: user.php:4
$path
Definition: aliased.php:25
$_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.
__construct($wsp_access_handler=null, $wsp_node_id=null)
This class handles base functions for mail handling.
static _lookupPref($a_usr_id, $a_keyword)
static _lookupLogin($a_user_id)
lookup login
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 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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static redirect($a_script)
http redirect to other script
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$counter
$cmd
Definition: sahs_server.php:35
$ref_id
Definition: sahs_server.php:39
global $DIC