ILIAS  Release_4_1_x_branch Revision 61804
 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()
28  {
29  global $tpl, $ilCtrl, $lng, $ilUser, $rbacsystem;
30 
31  $this->tpl = $tpl;
32  $this->ctrl = $ilCtrl;
33  $this->lng = $lng;
34 
35  $this->ctrl->saveParameter($this, "mobj_id");
36 
37  // check if current user may send mails
38  include_once "Services/Mail/classes/class.ilMail.php";
39  $mail = new ilMail($_SESSION["AccountId"]);
40  $this->mailing_allowed = $rbacsystem->checkAccess('mail_visible',$mail->getMailObjectReferenceId());
41 
42  $this->umail = new ilFormatMail($ilUser->getId());
43  $this->abook = new ilAddressbook($ilUser->getId());
44  }
45 
46  public function executeCommand()
47  {
48  $forward_class = $this->ctrl->getNextClass($this);
49  switch($forward_class)
50  {
51  default:
52  if (!($cmd = $this->ctrl->getCmd()))
53  {
54  $cmd = "showMyGroups";
55  }
56 
57  $this->$cmd();
58  break;
59  }
60  return true;
61  }
62 
63  function mail()
64  {
65  global $ilUser, $lng;
66 
67  if ($_GET["view"] == "mygroups")
68  {
69  $ids = ((int) $_GET['search_grp']) ? array((int)$_GET['search_grp']) : $_POST['search_grp'];
70  if ($ids)
71  {
72  $this->mailGroups();
73  }
74  else
75  {
76  ilUtil::sendInfo($lng->txt("mail_select_group"));
77  $this->showMyGroups();
78  }
79  }
80  else if ($_GET["view"] == "grp_members")
81  {
82  $ids = ((int) $_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
83  if ($ids)
84  {
85  $this->mailMembers();
86  }
87  else
88  {
89  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
90  $this->showMembers();
91  }
92  }
93  else
94  {
95  $this->showMyGroups();
96  }
97  }
98 
99  function mailGroups()
100  {
101  global $ilUser, $lng, $rbacreview;
102 
103  $members = array();
104 
105  if (!is_array($old_mail_data = $this->umail->getSavedData()))
106  {
107  $this->umail->savePostData(
108  $ilUser->getId(),
109  array(),
110  "",
111  "",
112  "",
113  "",
114  "",
115  "",
116  "",
117  ""
118  );
119  }
120 
121  require_once 'classes/class.ilObject.php';
122  $ids = ((int) $_GET['search_grp']) ? array((int)$_GET['search_grp']) : $_POST['search_grp'];
123  foreach ($ids as $grp_id)
124  {
125  $ref_ids = ilObject::_getAllReferences($grp_id);
126  foreach ($ref_ids as $ref_id)
127  {
128  $roles = $rbacreview->getAssignableChildRoles($ref_id);
129  foreach ($roles as $role)
130  {
131  if (substr($role['title'], 0, 14) == 'il_grp_member_' ||
132  substr($role['title'], 0, 13) == 'il_grp_admin_')
133  {
134  if(isset($old_mail_data['rcp_to']) &&
135  trim($old_mail_data['rcp_to']) != '')
136  {
137  $rcpt = $rbacreview->getRoleMailboxAddress($role['obj_id']);
138 
139  if(!$this->umail->doesRecipientStillExists($rcpt, $old_mail_data['rcp_to']))
140  // does not work if Pear is enabled and Mailbox Address contain special chars!!
141 // array_push($members, $rcpt);
142  // FIX for Mantis: 7523, 8061
143  array_push($members, '#'.$role['title']);
144 
145  unset($rcpt);
146  }
147  else
148  {
149  // does not work if Pear is enabled and Mailbox Address contain special chars!!
150 // array_push($members, $rbacreview->getRoleMailboxAddress($role['obj_id']));
151  // FIX for Mantis: 7523, 8061
152  array_push($members, '#'.$role['title']);
153  }
154  }
155  }
156  }
157  }
158 
159  if(count($members))
160  $mail_data = $this->umail->appendSearchResult($members, 'to');
161  else
162  $mail_data = $this->umail->getSavedData();
163 
164  $this->umail->savePostData(
165  $mail_data["user_id"],
166  $mail_data["attachments"],
167  $mail_data["rcp_to"],
168  $mail_data["rcp_cc"],
169  $mail_data["rcp_bcc"],
170  $mail_data["m_type"],
171  $mail_data["m_email"],
172  $mail_data["m_subject"],
173  $mail_data["m_message"],
174  $mail_data["use_placeholders"]
175  );
176 
177  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
178  }
179 
180  function mailMembers()
181  {
182  global $ilUser;
183 
184  $members = array();
185 
186  if (!is_array($this->umail->getSavedData()))
187  {
188  $this->umail->savePostData(
189  $ilUser->getId(),
190  array(),
191  "",
192  "",
193  "",
194  "",
195  "",
196  "",
197  "",
198  ""
199  );
200  }
201 
202  $ids = ((int) $_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
203 
204  foreach ($ids as $member)
205  {
206  $login = ilObjUser::_lookupLogin($member);
207  array_push($members, $login);
208  }
209  $mail_data = $this->umail->appendSearchResult($members,"to");
210 
211  $this->umail->savePostData(
212  $mail_data["user_id"],
213  $mail_data["attachments"],
214  $mail_data["rcp_to"],
215  $mail_data["rcp_cc"],
216  $mail_data["rcp_bcc"],
217  $mail_data["m_type"],
218  $mail_data["m_email"],
219  $mail_data["m_subject"],
220  $mail_data["m_message"],
221  $mail_data["use_placeholders"]
222  );
223 
224  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
225  }
226 
230  public function adoptMembers()
231  {
232  global $lng;
233 
234  $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
235 
236  if ($ids )
237  {
238  $members = array();
239 
240  foreach ($ids as $member)
241  {
242  $login = ilObjUser::_lookupLogin($member);
243 
244  if (!$this->abook->checkEntry($login))
245  {
246  $name = ilObjUser::_lookupName($member);
247  $email = '';
248  if(ilObjUser::_lookupPref((int)$member, 'public_email') == 'y')
249  {
250  $email = ilObjUser::_lookupEmail($member);
251  }
252  $this->abook->addEntry(
253  $login,
254  $name["firstname"],
255  $name["lastname"],
256  $email
257  );
258  }
259  }
260  ilUtil::sendInfo($lng->txt("mail_members_added_addressbook"));
261  }
262  else
263  {
264  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
265  }
266 
267  $this->showMembers();
268  }
269 
273  function cancel()
274  {
275  if ($_GET["view"] == "mygroups" &&
276  $_GET["ref"] == "mail")
277  {
278  $this->ctrl->returnToParent($this);
279  }
280  else
281  {
282  $this->showMyGroups();
283  }
284  }
285 
289  public function showMyGroups()
290  {
291  global $lng, $ilUser, $ilObjDataCache, $tree;
292 
293  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
294 
295  $this->tpl->setVariable('HEADER', $this->lng->txt('mail'));
296 
297  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
298 
299  $_GET['view'] = 'mygroups';
300 
301  $lng->loadLanguageModule('crs');
302 
303  $this->ctrl->setParameter($this, 'view', 'mygroups');
304 
305  include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
306  $table = new ilMailSearchCoursesTableGUI($this, 'grp');
307  $table->setId('search_grps_tbl');
308  $grp_ids = ilGroupParticipants::_getMembershipByType($ilUser->getId(), 'grp');
309 
310  $counter = 0;
311  $tableData = array();
312  if (is_array($grp_ids) &&
313  count($grp_ids) > 0)
314  {
315 
316  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
317  foreach($grp_ids as $grp_id)
318  {
320  {
321  $oGroupParticipants = ilGroupParticipants::_getInstanceByObjId($grp_id);
322  $grp_members = $oGroupParticipants->getParticipants();
323 
324  foreach ($grp_members as $key => $member)
325  {
326  $tmp_usr = new ilObjUser($member);
327 
328  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
329  {
330  unset($grp_members[$key]);
331  }
332  }
333  unset($tmp_usr);
334 
335  $ref_ids = ilObject::_getAllReferences($grp_id);
336  $ref_id = current($ref_ids);
337  $path_arr = $tree->getPathFull($ref_id, $tree->getRootId());
338  $path_counter = 0;
339  $path = '';
340  foreach($path_arr as $data)
341  {
342  if($path_counter++)
343  {
344  $path .= " -> ";
345  }
346  $path .= $data['title'];
347  }
348  $path = $this->lng->txt('path').': '.$path;
349 
350  $current_selection_list = new ilAdvancedSelectionListGUI();
351  $current_selection_list->setListTitle($this->lng->txt("actions"));
352  $current_selection_list->setId("act_".$counter);
353 
354  $this->ctrl->setParameter($this, 'search_grp', $grp_id);
355  $this->ctrl->setParameter($this, 'view', 'mygroups');
356 
357  if ($this->mailing_allowed)
358  $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
359  $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
360 
361  $this->ctrl->clearParameters($this);
362 
363  $rowData = array
364  (
365  'CRS_ID' => $grp_id,
366  'CRS_NAME' => $ilObjDataCache->lookupTitle($grp_id),
367  'CRS_NO_MEMBERS' => count($grp_members),
368  'CRS_PATH' => $path,
369  'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML()
370  );
371  $counter++;
372  $tableData[] = $rowData;
373  }
374  }
375  }
376  $table->setData($tableData);
377  if($counter > 0)
378  {
379  $this->tpl->setVariable('TXT_MARKED_ENTRIES',$lng->txt('marked_entries'));
380  }
381 
382  $searchTpl->setVariable('TABLE', $table->getHtml());
383  $this->tpl->setContent($searchTpl->get());
384  $this->tpl->show();
385  }
386 
390  public function showMembers()
391  {
392  global $lng, $ilUser;
393 
394  if ($_GET["search_grp"] != "")
395  {
396  $_POST["search_grp"] = explode(",", $_GET["search_grp"]);
397  }
398 
399  if (!is_array($_POST["search_grp"]) ||
400  count($_POST["search_grp"]) == 0)
401  {
402  ilUtil::sendInfo($lng->txt("mail_select_group"));
403  $this->showMyGroups();
404  }
405  else
406  {
407  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
408  include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
409  $table = new ilMailSearchCoursesMembersTableGUI($this, 'grp');
410  $table->setId('show_grps_mmbrs_tbl');
411  $lng->loadLanguageModule('crs');
412 
413  $counter = 0;
414  $tableData = array();
415  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
416 
417  foreach($_POST["search_grp"] as $grp_id)
418  {
419  $ref_ids = ilObject::_getAllReferences($grp_id);
420  $ref_id = current($ref_ids);
421 
422  if (is_object($group_obj = ilObjectFactory::getInstanceByRefId($ref_id,false)))
423  {
424  $grp_members = $group_obj->getGroupMemberData($group_obj->getGroupMemberIds());
425 
426  foreach($grp_members as $member)
427  {
428  $tmp_usr = new ilObjUser($member['id']);
429  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
430  {
431  unset($tmp_usr);
432  continue;
433  }
434  unset($tmp_usr);
435 
436  $fullname = "";
437  if(in_array(ilObjUser::_lookupPref($member['id'], 'public_profile'), array("g", 'y')))
438  $fullname = $member['lastname'].', '.$member['firstname'];
439 
440  $rowData = array(
441  'MEMBERS_ID' => $member["id"],
442  'MEMBERS_LOGIN' => $member["login"],
443  'MEMBERS_NAME' => $fullname,
444  'MEMBERS_CRS_GRP' => $group_obj->getTitle(),
445  'MEMBERS_IN_ADDRESSBOOK' => $this->abook->checkEntryByLogin($member["login"]) ? $lng->txt("yes") : $lng->txt("no"),
446  'search_grp' => $grp_id
447  );
448  $tableData[] = $rowData;
449  }
450  }
451  }
452  $table->setData($tableData);
453  if (count($tableData))
454  {
455  //$table->addCommandButton('mail', $lng->txt("grp_mem_send_mail"));
456  //$table->addCommandButton('adoptMembers', $lng->txt("mail_into_addressbook"));
457  $searchTpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
458  }
459  $searchTpl->setVariable('TABLE', $table->getHtml());
460  $this->tpl->setContent($searchTpl->get());
461  $this->tpl->show();
462  }
463  }
464 
465 }
466 
467 ?>