ILIAS  release_4-3 Revision
 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 
144  if(!$this->umail->doesRecipientStillExists($rcpt, $old_mail_data['rcp_to']))
145  // does not work if Pear is enabled and Mailbox Address contain special chars!!
146 // array_push($members, $rcpt);
147  // FIX for Mantis: 7523, 8061
148  array_push($members, '#'.$role['title']);
149 
150  unset($rcpt);
151  }
152  else
153  {
154  // does not work if Pear is enabled and Mailbox Address contain special chars!!
155 // array_push($members, $rbacreview->getRoleMailboxAddress($role['obj_id']));
156  // FIX for Mantis: 7523, 8061
157  array_push($members, '#'.$role['title']);
158  }
159  }
160  }
161  }
162  }
163 
164  if(count($members))
165  $mail_data = $this->umail->appendSearchResult($members, 'to');
166  else
167  $mail_data = $this->umail->getSavedData();
168 
169  $this->umail->savePostData(
170  $mail_data["user_id"],
171  $mail_data["attachments"],
172  $mail_data["rcp_to"],
173  $mail_data["rcp_cc"],
174  $mail_data["rcp_bcc"],
175  $mail_data["m_type"],
176  $mail_data["m_email"],
177  $mail_data["m_subject"],
178  $mail_data["m_message"],
179  $mail_data["use_placeholders"]
180  );
181 
182  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
183  }
184 
185  function mailMembers()
186  {
187  global $ilUser;
188 
189  $members = array();
190 
191  if (!is_array($this->umail->getSavedData()))
192  {
193  $this->umail->savePostData(
194  $ilUser->getId(),
195  array(),
196  "",
197  "",
198  "",
199  "",
200  "",
201  "",
202  "",
203  ""
204  );
205  }
206 
207  $ids = ((int) $_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
208 
209  foreach ($ids as $member)
210  {
211  $login = ilObjUser::_lookupLogin($member);
212  array_push($members, $login);
213  }
214  $mail_data = $this->umail->appendSearchResult($members,"to");
215 
216  $this->umail->savePostData(
217  $mail_data["user_id"],
218  $mail_data["attachments"],
219  $mail_data["rcp_to"],
220  $mail_data["rcp_cc"],
221  $mail_data["rcp_bcc"],
222  $mail_data["m_type"],
223  $mail_data["m_email"],
224  $mail_data["m_subject"],
225  $mail_data["m_message"],
226  $mail_data["use_placeholders"]
227  );
228 
229  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
230  }
231 
235  public function adoptMembers()
236  {
237  global $lng;
238 
239  $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
240 
241  if ($ids )
242  {
243  foreach ($ids as $member)
244  {
245  $login = ilObjUser::_lookupLogin($member);
246 
247  if (!$this->abook->checkEntry($login))
248  {
249  $name = ilObjUser::_lookupName($member);
250  $email = '';
251  if(ilObjUser::_lookupPref((int)$member, 'public_email') == 'y')
252  {
253  $email = ilObjUser::_lookupEmail($member);
254  }
255  $this->abook->addEntry(
256  $login,
257  $name["firstname"],
258  $name["lastname"],
259  $email
260  );
261  }
262  }
263  ilUtil::sendInfo($lng->txt("mail_members_added_addressbook"));
264  }
265  else
266  {
267  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
268  }
269 
270  $this->showMembers();
271  }
272 
276  function cancel()
277  {
278  if ($_GET["view"] == "mygroups" &&
279  $_GET["ref"] == "mail")
280  {
281  $this->ctrl->returnToParent($this);
282  }
283  else
284  {
285  $this->showMyGroups();
286  }
287  }
288 
292  public function showMyGroups()
293  {
294  global $lng, $ilUser, $ilObjDataCache, $tree;
295 
296  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
297 
298  $this->tpl->setTitle($this->lng->txt('mail_addressbook'));
299 
300  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
301 
302  $_GET['view'] = 'mygroups';
303 
304  $lng->loadLanguageModule('crs');
305 
306  $this->ctrl->setParameter($this, 'view', 'mygroups');
307 
308  include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
309  $table = new ilMailSearchCoursesTableGUI($this, 'grp', $_GET["ref"]);
310  $table->setId('search_grps_tbl');
311  $grp_ids = ilGroupParticipants::_getMembershipByType($ilUser->getId(), 'grp');
312 
313  $counter = 0;
314  $tableData = array();
315  if (is_array($grp_ids) &&
316  count($grp_ids) > 0)
317  {
318 
319  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
320  foreach($grp_ids as $grp_id)
321  {
323  {
324  $oGroupParticipants = ilGroupParticipants::_getInstanceByObjId($grp_id);
325  $grp_members = $oGroupParticipants->getParticipants();
326 
327  foreach ($grp_members as $key => $member)
328  {
329  $tmp_usr = new ilObjUser($member);
330 
331  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
332  {
333  unset($grp_members[$key]);
334  }
335  }
336  unset($tmp_usr);
337 
338  $ref_ids = ilObject::_getAllReferences($grp_id);
339  $ref_id = current($ref_ids);
340  $path_arr = $tree->getPathFull($ref_id, $tree->getRootId());
341  $path_counter = 0;
342  $path = '';
343  foreach($path_arr as $data)
344  {
345  if($path_counter++)
346  {
347  $path .= " -> ";
348  }
349  $path .= $data['title'];
350  }
351  $path = $this->lng->txt('path').': '.$path;
352 
353  $current_selection_list = new ilAdvancedSelectionListGUI();
354  $current_selection_list->setListTitle($this->lng->txt("actions"));
355  $current_selection_list->setId("act_".$counter);
356 
357  $this->ctrl->setParameter($this, 'search_grp', $grp_id);
358  $this->ctrl->setParameter($this, 'view', 'mygroups');
359 
360  if($_GET["ref"] == "mail")
361  {
362  if ($this->mailing_allowed)
363  $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
364  }
365  else if($_GET["ref"] == "wsp")
366  {
367  $current_selection_list->addItem($this->lng->txt("wsp_share_with_members"), '', $this->ctrl->getLinkTarget($this, "share"));
368  }
369  $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
370 
371  $this->ctrl->clearParameters($this);
372 
373  $rowData = array
374  (
375  'CRS_ID' => $grp_id,
376  'CRS_NAME' => $ilObjDataCache->lookupTitle($grp_id),
377  'CRS_NO_MEMBERS' => count($grp_members),
378  'CRS_PATH' => $path,
379  'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML()
380  );
381  $counter++;
382  $tableData[] = $rowData;
383  }
384  }
385  }
386  $table->setData($tableData);
387  if($counter > 0)
388  {
389  $this->tpl->setVariable('TXT_MARKED_ENTRIES',$lng->txt('marked_entries'));
390  }
391 
392  $searchTpl->setVariable('TABLE', $table->getHtml());
393  $this->tpl->setContent($searchTpl->get());
394 
395  if($_GET["ref"] != "wsp")
396  {
397  $this->tpl->show();
398  }
399  }
400 
404  public function showMembers()
405  {
406  global $lng;
407 
408  if ($_GET["search_grp"] != "")
409  {
410  $_POST["search_grp"] = explode(",", $_GET["search_grp"]);
411  }
412 
413  if (!is_array($_POST["search_grp"]) ||
414  count($_POST["search_grp"]) == 0)
415  {
416  ilUtil::sendInfo($lng->txt("mail_select_group"));
417  $this->showMyGroups();
418  }
419  else
420  {
421  $this->tpl->setTitle($this->lng->txt("mail_addressbook"));
422  include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
423  $context = $_GET["ref"] ? $_GET["ref"] : "mail";
424  $table = new ilMailSearchCoursesMembersTableGUI($this, 'grp', $context);
425  $table->setId('show_grps_mmbrs_tbl');
426  $lng->loadLanguageModule('crs');
427 
428  $tableData = array();
429  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
430 
431  foreach($_POST["search_grp"] as $grp_id)
432  {
433  $ref_ids = ilObject::_getAllReferences($grp_id);
434  $ref_id = current($ref_ids);
435 
436  if (is_object($group_obj = ilObjectFactory::getInstanceByRefId($ref_id,false)))
437  {
438  $grp_members = $group_obj->getGroupMemberData($group_obj->getGroupMemberIds());
439 
440  foreach($grp_members as $member)
441  {
442  $tmp_usr = new ilObjUser($member['id']);
443  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
444  {
445  unset($tmp_usr);
446  continue;
447  }
448  unset($tmp_usr);
449 
450  $fullname = "";
451  if(in_array(ilObjUser::_lookupPref($member['id'], 'public_profile'), array("g", 'y')))
452  $fullname = $member['lastname'].', '.$member['firstname'];
453 
454  $rowData = array(
455  'members_id' => $member["id"],
456  'members_login' => $member["login"],
457  'members_name' => $fullname,
458  'members_crs_grp' => $group_obj->getTitle(),
459  'members_in_addressbook' => $this->abook->checkEntryByLogin($member["login"]) ? $lng->txt("yes") : $lng->txt("no"),
460  'search_grp' => $grp_id
461  );
462  $tableData[] = $rowData;
463  }
464  }
465  }
466  $table->setData($tableData);
467  if (count($tableData))
468  {
469  $searchTpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
470  }
471  $searchTpl->setVariable('TABLE', $table->getHtml());
472  $this->tpl->setContent($searchTpl->get());
473 
474  if($_GET["ref"] != "wsp")
475  {
476  $this->tpl->show();
477  }
478  }
479  }
480 
481  function share()
482  {
483  global $lng;
484 
485  if ($_GET["view"] == "mygroups")
486  {
487  $ids = $_REQUEST["search_grp"];
488  if (sizeof($ids))
489  {
490  $this->addPermission($ids);
491  }
492  else
493  {
494  ilUtil::sendInfo($lng->txt("mail_select_course"));
495  $this->showMyGroups();
496  }
497  }
498  else if ($_GET["view"] == "grp_members")
499  {
500  $ids = $_REQUEST["search_members"];
501  if (sizeof($ids))
502  {
503  $this->addPermission($ids);
504  }
505  else
506  {
507  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
508  $this->showMembers();
509  }
510  }
511  else
512  {
513  $this->showMyGroups();
514  }
515  }
516 
517  protected function addPermission($a_obj_ids)
518  {
519  if(!is_array($a_obj_ids))
520  {
521  $a_obj_ids = array($a_obj_ids);
522  }
523 
524  $existing = $this->wsp_access_handler->getPermissions($this->wsp_node_id);
525  $added = false;
526  foreach($a_obj_ids as $object_id)
527  {
528  if(!in_array($object_id, $existing))
529  {
530  $added = $this->wsp_access_handler->addPermission($this->wsp_node_id, $object_id);
531  }
532  }
533 
534  if($added)
535  {
536  ilUtil::sendSuccess($this->lng->txt("wsp_share_success"), true);
537  }
538  $this->ctrl->redirectByClass("ilworkspaceaccessgui", "share");
539  }
540 }
541 
542 ?>