ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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/classes/class.ilAddressbook.php';
9 
17 {
18  private $tpl = null;
19  private $ctrl = null;
20  private $lng = null;
21 
22  private $umail = null;
23  private $abook = null;
24 
25  protected $mailing_allowed;
26 
27  public function __construct($wsp_access_handler = null, $wsp_node_id = null)
28  {
29  global $tpl, $ilCtrl, $lng, $ilUser, $rbacsystem;
30 
31  $this->tpl = $tpl;
32  $this->ctrl = $ilCtrl;
33  $this->lng = $lng;
34 
35  // personal workspace
36  $this->wsp_access_handler = $wsp_access_handler;
37  $this->wsp_node_id = $wsp_node_id;
38 
39  $this->ctrl->saveParameter($this, "mobj_id");
40  $this->ctrl->saveParameter($this, "ref");
41 
42  // check if current user may send mails
43  include_once "Services/Mail/classes/class.ilMail.php";
44  $mail = new ilMail($_SESSION["AccountId"]);
45  $this->mailing_allowed = $rbacsystem->checkAccess('internal_mail',$mail->getMailObjectReferenceId());
46 
47  $this->umail = new ilFormatMail($ilUser->getId());
48  $this->abook = new ilAddressbook($ilUser->getId());
49  }
50 
51  public function executeCommand()
52  {
53  $forward_class = $this->ctrl->getNextClass($this);
54  switch($forward_class)
55  {
56  default:
57  if (!($cmd = $this->ctrl->getCmd()))
58  {
59  $cmd = "showMyGroups";
60  }
61 
62  $this->$cmd();
63  break;
64  }
65  return true;
66  }
67 
68  function mail()
69  {
70  global $lng;
71 
72  if ($_GET["view"] == "mygroups")
73  {
74  $ids = ((int) $_GET['search_grp']) ? array((int)$_GET['search_grp']) : $_POST['search_grp'];
75  if ($ids)
76  {
77  $this->mailGroups();
78  }
79  else
80  {
81  ilUtil::sendInfo($lng->txt("mail_select_group"));
82  $this->showMyGroups();
83  }
84  }
85  else if ($_GET["view"] == "grp_members")
86  {
87  $ids = ((int) $_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
88  if ($ids)
89  {
90  $this->mailMembers();
91  }
92  else
93  {
94  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
95  $this->showMembers();
96  }
97  }
98  else
99  {
100  $this->showMyGroups();
101  }
102  }
103 
104  function mailGroups()
105  {
106  global $ilUser, $rbacreview;
107 
108  $members = array();
109 
110  if (!is_array($old_mail_data = $this->umail->getSavedData()))
111  {
112  $this->umail->savePostData(
113  $ilUser->getId(),
114  array(),
115  "",
116  "",
117  "",
118  "",
119  "",
120  "",
121  "",
122  ""
123  );
124  }
125 
126  require_once './Services/Object/classes/class.ilObject.php';
127  $ids = ((int) $_GET['search_grp']) ? array((int)$_GET['search_grp']) : $_POST['search_grp'];
128  foreach ($ids as $grp_id)
129  {
130  $ref_ids = ilObject::_getAllReferences($grp_id);
131  foreach ($ref_ids as $ref_id)
132  {
133  $roles = $rbacreview->getAssignableChildRoles($ref_id);
134  foreach ($roles as $role)
135  {
136  if (substr($role['title'], 0, 14) == 'il_grp_member_' ||
137  substr($role['title'], 0, 13) == 'il_grp_admin_')
138  {
139  if(isset($old_mail_data['rcp_to']) &&
140  trim($old_mail_data['rcp_to']) != '')
141  {
142  $rcpt = $rbacreview->getRoleMailboxAddress($role['obj_id']);
143  if(!$this->umail->doesRecipientStillExists($rcpt, $old_mail_data['rcp_to']))
144  {
145  array_push($members, $rcpt);
146  }
147  }
148  else
149  {
150  array_push($members, $rbacreview->getRoleMailboxAddress($role['obj_id']));
151  }
152  }
153  }
154  }
155  }
156 
157  if(count($members))
158  $mail_data = $this->umail->appendSearchResult($members, 'to');
159  else
160  $mail_data = $this->umail->getSavedData();
161 
162  $this->umail->savePostData(
163  $mail_data["user_id"],
164  $mail_data["attachments"],
165  $mail_data["rcp_to"],
166  $mail_data["rcp_cc"],
167  $mail_data["rcp_bcc"],
168  $mail_data["m_type"],
169  $mail_data["m_email"],
170  $mail_data["m_subject"],
171  $mail_data["m_message"],
172  $mail_data["use_placeholders"]
173  );
174 
175  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
176  }
177 
178  function mailMembers()
179  {
180  global $ilUser;
181 
182  $members = array();
183 
184  if (!is_array($this->umail->getSavedData()))
185  {
186  $this->umail->savePostData(
187  $ilUser->getId(),
188  array(),
189  "",
190  "",
191  "",
192  "",
193  "",
194  "",
195  "",
196  ""
197  );
198  }
199 
200  $ids = ((int) $_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
201 
202  foreach ($ids as $member)
203  {
204  $login = ilObjUser::_lookupLogin($member);
205  array_push($members, $login);
206  }
207  $mail_data = $this->umail->appendSearchResult($members,"to");
208 
209  $this->umail->savePostData(
210  $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_type"],
216  $mail_data["m_email"],
217  $mail_data["m_subject"],
218  $mail_data["m_message"],
219  $mail_data["use_placeholders"]
220  );
221 
222  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
223  }
224 
228  public function adoptMembers()
229  {
230  global $lng;
231 
232  $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
233 
234  if ($ids )
235  {
236  foreach ($ids as $member)
237  {
238  $login = ilObjUser::_lookupLogin($member);
239 
240  if (!$this->abook->checkEntry($login))
241  {
242  $name = ilObjUser::_lookupName($member);
243  $email = '';
244  if(ilObjUser::_lookupPref((int)$member, 'public_email') == 'y')
245  {
246  $email = ilObjUser::_lookupEmail($member);
247  }
248  $this->abook->addEntry(
249  $login,
250  $name["firstname"],
251  $name["lastname"],
252  $email
253  );
254  }
255  }
256  ilUtil::sendInfo($lng->txt("mail_members_added_addressbook"));
257  }
258  else
259  {
260  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
261  }
262 
263  $this->showMembers();
264  }
265 
269  function cancel()
270  {
271  if ($_GET["view"] == "mygroups" &&
272  $_GET["ref"] == "mail")
273  {
274  $this->ctrl->returnToParent($this);
275  }
276  else
277  {
278  $this->showMyGroups();
279  }
280  }
281 
285  public function showMyGroups()
286  {
287  global $lng, $ilUser, $ilObjDataCache, $tree;
288 
289  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
290 
291  $this->tpl->setTitle($this->lng->txt('mail_addressbook'));
292 
293  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
294 
295  $_GET['view'] = 'mygroups';
296 
297  $lng->loadLanguageModule('crs');
298 
299  $this->ctrl->setParameter($this, 'view', 'mygroups');
300 
301  include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
302  $table = new ilMailSearchCoursesTableGUI($this, 'grp', $_GET["ref"]);
303  $table->setId('search_grps_tbl');
304  $grp_ids = ilGroupParticipants::_getMembershipByType($ilUser->getId(), 'grp');
305 
306  $counter = 0;
307  $tableData = array();
308  if (is_array($grp_ids) &&
309  count($grp_ids) > 0)
310  {
311 
312  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
313  foreach($grp_ids as $grp_id)
314  {
316  {
317  $oGroupParticipants = ilGroupParticipants::_getInstanceByObjId($grp_id);
318  $grp_members = $oGroupParticipants->getParticipants();
319 
320  foreach ($grp_members as $key => $member)
321  {
322  $tmp_usr = new ilObjUser($member);
323 
324  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
325  {
326  unset($grp_members[$key]);
327  }
328  }
329  unset($tmp_usr);
330 
331  $ref_ids = ilObject::_getAllReferences($grp_id);
332  $ref_id = current($ref_ids);
333  $path_arr = $tree->getPathFull($ref_id, $tree->getRootId());
334  $path_counter = 0;
335  $path = '';
336  foreach($path_arr as $data)
337  {
338  if($path_counter++)
339  {
340  $path .= " -> ";
341  }
342  $path .= $data['title'];
343  }
344  $path = $this->lng->txt('path').': '.$path;
345 
346  $current_selection_list = new ilAdvancedSelectionListGUI();
347  $current_selection_list->setListTitle($this->lng->txt("actions"));
348  $current_selection_list->setId("act_".$counter);
349 
350  $this->ctrl->setParameter($this, 'search_grp', $grp_id);
351  $this->ctrl->setParameter($this, 'view', 'mygroups');
352 
353  if($_GET["ref"] == "mail")
354  {
355  if ($this->mailing_allowed)
356  $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
357  }
358  else if($_GET["ref"] == "wsp")
359  {
360  $current_selection_list->addItem($this->lng->txt("wsp_share_with_members"), '', $this->ctrl->getLinkTarget($this, "share"));
361  }
362  $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
363 
364  $this->ctrl->clearParameters($this);
365 
366  $rowData = array
367  (
368  'CRS_ID' => $grp_id,
369  'CRS_NAME' => $ilObjDataCache->lookupTitle($grp_id),
370  'CRS_NO_MEMBERS' => count($grp_members),
371  'CRS_PATH' => $path,
372  'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML()
373  );
374  $counter++;
375  $tableData[] = $rowData;
376  }
377  }
378  }
379  $table->setData($tableData);
380  if($counter > 0)
381  {
382  $this->tpl->setVariable('TXT_MARKED_ENTRIES',$lng->txt('marked_entries'));
383  }
384 
385  $searchTpl->setVariable('TABLE', $table->getHtml());
386  $this->tpl->setContent($searchTpl->get());
387 
388  if($_GET["ref"] != "wsp")
389  {
390  $this->tpl->show();
391  }
392  }
393 
397  public function showMembers()
398  {
399  global $lng;
400 
401  if ($_GET["search_grp"] != "")
402  {
403  $_POST["search_grp"] = explode(",", $_GET["search_grp"]);
404  }
405 
406  if (!is_array($_POST["search_grp"]) ||
407  count($_POST["search_grp"]) == 0)
408  {
409  ilUtil::sendInfo($lng->txt("mail_select_group"));
410  $this->showMyGroups();
411  }
412  else
413  {
414  $this->tpl->setTitle($this->lng->txt("mail_addressbook"));
415  include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
416  $context = $_GET["ref"] ? $_GET["ref"] : "mail";
417  $table = new ilMailSearchCoursesMembersTableGUI($this, 'grp', $context);
418  $table->setId('show_grps_mmbrs_tbl');
419  $lng->loadLanguageModule('crs');
420 
421  $tableData = array();
422  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
423 
424  foreach($_POST["search_grp"] as $grp_id)
425  {
426  $ref_ids = ilObject::_getAllReferences($grp_id);
427  $ref_id = current($ref_ids);
428 
429  if (is_object($group_obj = ilObjectFactory::getInstanceByRefId($ref_id,false)))
430  {
431  $grp_members = $group_obj->getGroupMemberData($group_obj->getGroupMemberIds());
432 
433  foreach($grp_members as $member)
434  {
435  $tmp_usr = new ilObjUser($member['id']);
436  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
437  {
438  unset($tmp_usr);
439  continue;
440  }
441  unset($tmp_usr);
442 
443  $fullname = "";
444  if(in_array(ilObjUser::_lookupPref($member['id'], 'public_profile'), array("g", 'y')))
445  $fullname = $member['lastname'].', '.$member['firstname'];
446 
447  $rowData = array(
448  'members_id' => $member["id"],
449  'members_login' => $member["login"],
450  'members_name' => $fullname,
451  'members_crs_grp' => $group_obj->getTitle(),
452  'members_in_addressbook' => $this->abook->checkEntryByLogin($member["login"]) ? $lng->txt("yes") : $lng->txt("no"),
453  'search_grp' => $grp_id
454  );
455  $tableData[] = $rowData;
456  }
457  }
458  }
459  $table->setData($tableData);
460  if (count($tableData))
461  {
462  $searchTpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
463  }
464  $searchTpl->setVariable('TABLE', $table->getHtml());
465  $this->tpl->setContent($searchTpl->get());
466 
467  if($_GET["ref"] != "wsp")
468  {
469  $this->tpl->show();
470  }
471  }
472  }
473 
474  function share()
475  {
476  global $lng;
477 
478  if ($_GET["view"] == "mygroups")
479  {
480  $ids = $_REQUEST["search_grp"];
481  if (sizeof($ids))
482  {
483  $this->addPermission($ids);
484  }
485  else
486  {
487  ilUtil::sendInfo($lng->txt("mail_select_course"));
488  $this->showMyGroups();
489  }
490  }
491  else if ($_GET["view"] == "grp_members")
492  {
493  $ids = $_REQUEST["search_members"];
494  if (sizeof($ids))
495  {
496  $this->addPermission($ids);
497  }
498  else
499  {
500  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
501  $this->showMembers();
502  }
503  }
504  else
505  {
506  $this->showMyGroups();
507  }
508  }
509 
510  protected function addPermission($a_obj_ids)
511  {
512  if(!is_array($a_obj_ids))
513  {
514  $a_obj_ids = array($a_obj_ids);
515  }
516 
517  $existing = $this->wsp_access_handler->getPermissions($this->wsp_node_id);
518  $added = false;
519  foreach($a_obj_ids as $object_id)
520  {
521  if(!in_array($object_id, $existing))
522  {
523  $added = $this->wsp_access_handler->addPermission($this->wsp_node_id, $object_id);
524  }
525  }
526 
527  if($added)
528  {
529  ilUtil::sendSuccess($this->lng->txt("wsp_share_success"), true);
530  }
531  $this->ctrl->redirectByClass("ilworkspaceaccessgui", "share");
532  }
533 }
534 
535 ?>