ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
5 require_once './Services/User/classes/class.ilObjUser.php';
6 require_once 'Services/Mail/classes/class.ilMailbox.php';
7 require_once 'Services/Mail/classes/class.ilFormatMail.php';
8 require_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 
71  protected $mailing_allowed;
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  case 'ilbuddysystemgui':
106  if (!ilBuddySystem::getInstance()->isEnabled()) {
107  $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
108  }
109 
110  require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemGUI.php';
111  $this->ctrl->saveParameter($this, 'search_grp');
112  $this->ctrl->setReturn($this, 'showMembers');
113  $this->ctrl->forwardCommand(new ilBuddySystemGUI());
114  break;
115 
116  default:
117  if (!($cmd = $this->ctrl->getCmd())) {
118  $cmd = "showMyGroups";
119  }
120 
121  $this->$cmd();
122  break;
123  }
124  return true;
125  }
126 
127  public function mail()
128  {
129  if ($_GET["view"] == "mygroups") {
130  $ids = ((int) $_GET['search_grp']) ? array((int) $_GET['search_grp']) : $_POST['search_grp'];
131  if ($ids) {
132  $this->mailGroups();
133  } else {
134  ilUtil::sendInfo($this->lng->txt("mail_select_group"));
135  $this->showMyGroups();
136  }
137  } elseif ($_GET["view"] == "grp_members") {
138  $ids = ((int) $_GET['search_members']) ? array((int) $_GET['search_members']) : $_POST['search_members'];
139  if ($ids) {
140  $this->mailMembers();
141  } else {
142  ilUtil::sendInfo($this->lng->txt("mail_select_one_entry"));
143  $this->showMembers();
144  }
145  } else {
146  $this->showMyGroups();
147  }
148  }
149 
150  public function mailGroups()
151  {
152  $members = array();
153 
154  if (!is_array($old_mail_data = $this->umail->getSavedData())) {
155  $this->umail->savePostData(
156  $this->user->getId(),
157  array(),
158  "",
159  "",
160  "",
161  "",
162  "",
163  "",
164  "",
165  ""
166  );
167  }
168 
169  require_once './Services/Object/classes/class.ilObject.php';
170  require_once 'Services/Mail/classes/Address/Type/class.ilMailRoleAddressType.php';
171 
172  $ids = ((int) $_GET['search_grp']) ? array((int) $_GET['search_grp']) : $_POST['search_grp'];
173  foreach ($ids as $grp_id) {
174  $ref_ids = ilObject::_getAllReferences($grp_id);
175  foreach ($ref_ids as $ref_id) {
176  $roles = $this->rbacreview->getAssignableChildRoles($ref_id);
177  foreach ($roles as $role) {
178  if (substr($role['title'], 0, 14) == 'il_grp_member_' ||
179  substr($role['title'], 0, 13) == 'il_grp_admin_') {
180  if (isset($old_mail_data['rcp_to']) &&
181  trim($old_mail_data['rcp_to']) != '') {
182  $rcpt = (new \ilRoleMailboxAddress($role['obj_id']))->value();
183  if (!$this->umail->existsRecipient($rcpt, (string) $old_mail_data['rcp_to'])) {
184  array_push($members, $rcpt);
185  }
186  } else {
187  array_push($members, (new \ilRoleMailboxAddress($role['obj_id']))->value());
188  }
189  }
190  }
191  }
192  }
193 
194  if (count($members)) {
195  $mail_data = $this->umail->appendSearchResult($members, 'to');
196  } else {
197  $mail_data = $this->umail->getSavedData();
198  }
199 
200  $this->umail->savePostData(
201  $mail_data["user_id"],
202  $mail_data["attachments"],
203  $mail_data["rcp_to"],
204  $mail_data["rcp_cc"],
205  $mail_data["rcp_bcc"],
206  $mail_data["m_type"],
207  $mail_data["m_email"],
208  $mail_data["m_subject"],
209  $mail_data["m_message"],
210  $mail_data["use_placeholders"],
211  $mail_data['tpl_ctx_id'],
212  $mail_data['tpl_ctx_params']
213  );
214 
215  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
216  }
217 
218  public function mailMembers()
219  {
220  $members = array();
221 
222  if (!is_array($this->umail->getSavedData())) {
223  $this->umail->savePostData(
224  $this->user->getId(),
225  array(),
226  "",
227  "",
228  "",
229  "",
230  "",
231  "",
232  "",
233  ""
234  );
235  }
236 
237  $ids = ((int) $_GET['search_members']) ? array((int) $_GET['search_members']) : $_POST['search_members'];
238 
239  foreach ($ids as $member) {
240  $login = ilObjUser::_lookupLogin($member);
241  array_push($members, $login);
242  }
243  $mail_data = $this->umail->appendSearchResult($members, "to");
244 
245  $this->umail->savePostData(
246  $mail_data["user_id"],
247  $mail_data["attachments"],
248  $mail_data["rcp_to"],
249  $mail_data["rcp_cc"],
250  $mail_data["rcp_bcc"],
251  $mail_data["m_type"],
252  $mail_data["m_email"],
253  $mail_data["m_subject"],
254  $mail_data["m_message"],
255  $mail_data["use_placeholders"],
256  $mail_data['tpl_ctx_id'],
257  $mail_data['tpl_ctx_params']
258  );
259 
260  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
261  }
262 
266  public function cancel()
267  {
268  if ($_GET["view"] == "mygroups" &&
269  $_GET["ref"] == "mail") {
270  $this->ctrl->returnToParent($this);
271  } else {
272  $this->showMyGroups();
273  }
274  }
275 
279  public function showMyGroups()
280  {
281  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
282 
283  $this->tpl->setTitle($this->lng->txt('mail_addressbook'));
284 
285  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
286 
287  $_GET['view'] = 'mygroups';
288 
289  $this->lng->loadLanguageModule('crs');
290 
291  $this->ctrl->setParameter($this, 'view', 'mygroups');
292 
293  include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
294  $table = new ilMailSearchCoursesTableGUI($this, 'grp', $_GET["ref"]);
295  $table->setId('search_grps_tbl');
296  $grp_ids = ilGroupParticipants::_getMembershipByType($this->user->getId(), 'grp');
297 
298  $counter = 0;
299  $tableData = array();
300  if (is_array($grp_ids) &&
301  count($grp_ids) > 0) {
302  $num_groups_hidden_members = 0;
303  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
304  foreach ($grp_ids as $grp_id) {
308  $oTmpGrp = ilObjectFactory::getInstanceByObjId($grp_id);
309 
310  $hasUntrashedReferences = ilObject::_hasUntrashedReference($grp_id);
311  $showMemberListEnabled = (boolean) $oTmpGrp->getShowMembers();
312  $ref_ids = array_keys(ilObject::_getAllReferences($grp_id));
313  $isPrivilegedUser = $this->rbacsystem->checkAccess('write', $ref_ids[0]);
314 
315  if ($hasUntrashedReferences && ($showMemberListEnabled || $isPrivilegedUser)) {
316  $oGroupParticipants = ilGroupParticipants::_getInstanceByObjId($grp_id);
317  $grp_members = $oGroupParticipants->getParticipants();
318 
319  foreach ($grp_members as $key => $member) {
320  $tmp_usr = new ilObjUser($member);
321 
322  if (!$tmp_usr->getActive()) {
323  unset($grp_members[$key]);
324  }
325  }
326 
327  $hiddenMembers = false;
328  if ((int) $oTmpGrp->getShowMembers() == $oTmpGrp->SHOW_MEMBERS_DISABLED) {
329  ++$num_groups_hidden_members;
330  $hiddenMembers = true;
331  }
332  unset($oTmpGrp);
333 
334  $ref_ids = ilObject::_getAllReferences($grp_id);
335  $ref_id = current($ref_ids);
336  $path_arr = $this->tree->getPathFull($ref_id, $this->tree->getRootId());
337  $path_counter = 0;
338  $path = '';
339  foreach ($path_arr as $data) {
340  if ($path_counter++) {
341  $path .= " -> ";
342  }
343  $path .= $data['title'];
344  }
345  $path = $this->lng->txt('path') . ': ' . $path;
346 
347  $current_selection_list = new ilAdvancedSelectionListGUI();
348  $current_selection_list->setListTitle($this->lng->txt("actions"));
349  $current_selection_list->setId("act_" . $counter);
350 
351  $this->ctrl->setParameter($this, 'search_grp', $grp_id);
352  $this->ctrl->setParameter($this, 'view', 'mygroups');
353 
354  if ($_GET["ref"] == "mail") {
355  if ($this->mailing_allowed) {
356  $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
357  }
358  } elseif ($_GET["ref"] == "wsp") {
359  $current_selection_list->addItem($this->lng->txt("wsp_share_with_members"), '', $this->ctrl->getLinkTarget($this, "share"));
360  }
361  $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
362 
363  $this->ctrl->clearParameters($this);
364 
365  $rowData = array(
366  'CRS_ID' => $grp_id,
367  'CRS_NAME' => $this->cache->lookupTitle($grp_id),
368  'CRS_NO_MEMBERS' => count($grp_members),
369  'CRS_PATH' => $path,
370  'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML(),
371  "hidden_members" => $hiddenMembers
372  );
373  $counter++;
374  $tableData[] = $rowData;
375  }
376  }
377  if ($num_groups_hidden_members > 0) {
378  $searchTpl->setCurrentBlock('caption_block');
379  $searchTpl->setVariable('TXT_LIST_MEMBERS_NOT_AVAILABLE', $this->lng->txt('mail_crs_list_members_not_available'));
380  $searchTpl->parseCurrentBlock();
381  }
382  }
383  $table->setData($tableData);
384  if ($counter > 0) {
385  $this->tpl->setVariable('TXT_MARKED_ENTRIES', $this->lng->txt('marked_entries'));
386  }
387 
388  $searchTpl->setVariable('TABLE', $table->getHTML());
389  $this->tpl->setContent($searchTpl->get());
390 
391  if ($_GET["ref"] != "wsp") {
392  $this->tpl->show();
393  }
394  }
395 
399  public function showMembers()
400  {
401  if ($_GET["search_grp"] != "") {
402  $_POST["search_grp"] = explode(",", $_GET["search_grp"]);
403  }
404 
405  if (!is_array($_POST["search_grp"]) ||
406  count($_POST["search_grp"]) == 0) {
407  ilUtil::sendInfo($this->lng->txt("mail_select_group"));
408  $this->showMyGroups();
409  } else {
410  $this->tpl->setTitle($this->lng->txt("mail_addressbook"));
411  include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
412  $context = $_GET["ref"] ? $_GET["ref"] : "mail";
413  $table = new ilMailSearchCoursesMembersTableGUI($this, 'grp', $context, $_POST["search_grp"]);
414  $this->lng->loadLanguageModule('crs');
415 
416  $tableData = array();
417  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
418 
419  foreach ($_POST["search_grp"] as $grp_id) {
420  $ref_ids = ilObject::_getAllReferences($grp_id);
421  $ref_id = current($ref_ids);
422 
423  if (is_object($group_obj = ilObjectFactory::getInstanceByRefId($ref_id, false))) {
424  $grp_members = $group_obj->getGroupMemberData($group_obj->getGroupMemberIds());
425 
426  foreach ($grp_members as $member) {
427  $tmp_usr = new ilObjUser($member['id']);
428  if (!$tmp_usr->getActive()) {
429  continue;
430  }
431 
432  $fullname = "";
433  if (in_array(ilObjUser::_lookupPref($member['id'], 'public_profile'), array("g", 'y'))) {
434  $fullname = $member['lastname'] . ', ' . $member['firstname'];
435  }
436 
437  $rowData = array(
438  'members_id' => $member["id"],
439  'members_login' => $member["login"],
440  'members_name' => $fullname,
441  'members_crs_grp' => $group_obj->getTitle(),
442  'search_grp' => $grp_id,
443  );
444 
445  if ('mail' == $context && ilBuddySystem::getInstance()->isEnabled()) {
446  $relation = ilBuddyList::getInstanceByGlobalUser()->getRelationByUserId($member['id']);
447  $state_name = ilStr::convertUpperCamelCaseToUnderscoreCase($relation->getState()->getName());
448  $rowData['status'] = '';
449  if ($member['id'] != $this->user->getId()) {
450  if ($relation->isOwnedByRequest()) {
451  $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_a');
452  } else {
453  $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_p');
454  }
455  }
456  }
457 
458  $tableData[] = $rowData;
459  }
460  }
461  }
462  $table->setData($tableData);
463  if (count($tableData)) {
464  $searchTpl->setVariable("TXT_MARKED_ENTRIES", $this->lng->txt("marked_entries"));
465  }
466  $searchTpl->setVariable('TABLE', $table->getHTML());
467  $this->tpl->setContent($searchTpl->get());
468 
469  if ($_GET["ref"] != "wsp") {
470  $this->tpl->show();
471  }
472  }
473  }
474 
475  public function share()
476  {
477  if ($_GET["view"] == "mygroups") {
478  $ids = $_REQUEST["search_grp"];
479  if (sizeof($ids)) {
480  $this->addPermission($ids);
481  } else {
482  ilUtil::sendInfo($this->lng->txt("mail_select_course"));
483  $this->showMyGroups();
484  }
485  } elseif ($_GET["view"] == "grp_members") {
486  $ids = $_REQUEST["search_members"];
487  if (sizeof($ids)) {
488  $this->addPermission($ids);
489  } else {
490  ilUtil::sendInfo($this->lng->txt("mail_select_one_entry"));
491  $this->showMembers();
492  }
493  } else {
494  $this->showMyGroups();
495  }
496  }
497 
498  protected function addPermission($a_obj_ids)
499  {
500  if (!is_array($a_obj_ids)) {
501  $a_obj_ids = array($a_obj_ids);
502  }
503 
504  $existing = $this->wsp_access_handler->getPermissions($this->wsp_node_id);
505  $added = false;
506  foreach ($a_obj_ids as $object_id) {
507  if (!in_array($object_id, $existing)) {
508  $added = $this->wsp_access_handler->addPermission($this->wsp_node_id, $object_id);
509  }
510  }
511 
512  if ($added) {
513  ilUtil::sendSuccess($this->lng->txt("wsp_share_success"), true);
514  }
515  $this->ctrl->redirectByClass("ilworkspaceaccessgui", "share");
516  }
517 }
static _lookupLogin($a_user_id)
lookup login
$path
Definition: aliased.php:25
Class ilBuddySystemGUI.
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
static convertUpperCamelCaseToUnderscoreCase($value)
Convert a value given in camel case conversion to underscore case conversion (e.g.
$context
Definition: webdav.php:25
static getInstanceByGlobalUser()
global $DIC
Definition: saml.php:7
$_GET["client_id"]
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
Class ilRoleMailboxAddress.
user()
Definition: user.php:4
static _getAllReferences($a_id)
get all reference ids of object
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Class UserMail this class handles user mails.
showMembers()
Show course members.
special template class to simplify handling of ITX/PEAR
__construct($wsp_access_handler=null, $wsp_node_id=null)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
User interface class for advanced drop-down selection lists.
static _lookupPref($a_usr_id, $a_keyword)
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
$login
Definition: cron.php:13
if(empty($password)) $table
Definition: pwgen.php:24
static redirect($a_script)
$key
Definition: croninfo.php:18
$_POST["username"]
$data
Definition: bench.php:6