ILIAS  eassessment Revision 61809
 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  array_push($members, $rcpt);
141 
142  unset($rcpt);
143  }
144  else
145  {
146  array_push($members, $rbacreview->getRoleMailboxAddress($role['obj_id']));
147  }
148  }
149  }
150  }
151  }
152 
153  if(count($members))
154  $mail_data = $this->umail->appendSearchResult($members, 'to');
155  else
156  $mail_data = $this->umail->getSavedData();
157 
158  $this->umail->savePostData(
159  $mail_data["user_id"],
160  $mail_data["attachments"],
161  $mail_data["rcp_to"],
162  $mail_data["rcp_cc"],
163  $mail_data["rcp_bcc"],
164  $mail_data["m_type"],
165  $mail_data["m_email"],
166  $mail_data["m_subject"],
167  $mail_data["m_message"],
168  $mail_data["use_placeholders"]
169  );
170 
171  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
172  }
173 
174  function mailMembers()
175  {
176  $members = array();
177 
178  if (!is_array($this->umail->getSavedData()))
179  {
180  $this->umail->savePostData(
181  $ilUser->getId(),
182  array(),
183  "",
184  "",
185  "",
186  "",
187  "",
188  "",
189  "",
190  ""
191  );
192  }
193 
194  $ids = ((int) $_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
195 
196  foreach ($ids as $member)
197  {
198  $login = ilObjUser::_lookupLogin($member);
199  array_push($members, $login);
200  }
201  $mail_data = $this->umail->appendSearchResult($members,"to");
202 
203  $this->umail->savePostData(
204  $mail_data["user_id"],
205  $mail_data["attachments"],
206  $mail_data["rcp_to"],
207  $mail_data["rcp_cc"],
208  $mail_data["rcp_bcc"],
209  $mail_data["m_type"],
210  $mail_data["m_email"],
211  $mail_data["m_subject"],
212  $mail_data["m_message"],
213  $mail_data["use_placeholders"]
214  );
215 
216  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
217  }
218 
222  public function adoptMembers()
223  {
224  global $lng;
225 
226  $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
227 
228  if ($ids )
229  {
230  $members = array();
231 
232  foreach ($ids as $member)
233  {
234  $login = ilObjUser::_lookupLogin($member);
235 
236  if (!$this->abook->checkEntry($login))
237  {
238  $name = ilObjUser::_lookupName($member);
239  $email = '';
240  if(ilObjUser::_lookupPref((int)$member, 'public_email') == 'y')
241  {
242  $email = ilObjUser::_lookupEmail($member);
243  }
244  $this->abook->addEntry(
245  $login,
246  $name["firstname"],
247  $name["lastname"],
248  $email
249  );
250  }
251  }
252  ilUtil::sendInfo($lng->txt("mail_members_added_addressbook"));
253  }
254  else
255  {
256  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
257  }
258 
259  $this->showMembers();
260  }
261 
265  function cancel()
266  {
267  if ($_GET["view"] == "mygroups" &&
268  $_GET["ref"] == "mail")
269  {
270  $this->ctrl->returnToParent($this);
271  }
272  else
273  {
274  $this->showMyGroups();
275  }
276  }
277 
281  public function showMyGroups()
282  {
283  global $lng, $ilUser, $ilObjDataCache, $tree;
284 
285  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
286 
287  $this->tpl->setVariable('HEADER', $this->lng->txt('mail'));
288 
289  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
290 
291  $_GET['view'] = 'mygroups';
292 
293  $lng->loadLanguageModule('crs');
294 
295  $this->ctrl->setParameter($this, 'view', 'mygroups');
296 
297  include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
298  $table = new ilMailSearchCoursesTableGUI($this, 'grp');
299  $table->setId('search_grps_tbl');
300  $grp_ids = ilGroupParticipants::_getMembershipByType($ilUser->getId(), 'grp');
301 
302  $counter = 0;
303  $tableData = array();
304  if (is_array($grp_ids) &&
305  count($grp_ids) > 0)
306  {
307 
308  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
309  foreach($grp_ids as $grp_id)
310  {
312  {
313  $oGroupParticipants = ilGroupParticipants::_getInstanceByObjId($grp_id);
314  $grp_members = $oGroupParticipants->getParticipants();
315 
316  foreach ($grp_members as $key => $member)
317  {
318  $tmp_usr = new ilObjUser($member);
319 
320  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
321  {
322  unset($grp_members[$key]);
323  }
324  }
325  unset($tmp_usr);
326 
327  $ref_ids = ilObject::_getAllReferences($grp_id);
328  $ref_id = current($ref_ids);
329  $path_arr = $tree->getPathFull($ref_id, $tree->getRootId());
330  $path_counter = 0;
331  $path = '';
332  foreach($path_arr as $data)
333  {
334  if($path_counter++)
335  {
336  $path .= " -> ";
337  }
338  $path .= $data['title'];
339  }
340  $path = $this->lng->txt('path').': '.$path;
341 
342  $current_selection_list = new ilAdvancedSelectionListGUI();
343  $current_selection_list->setListTitle($this->lng->txt("actions"));
344  $current_selection_list->setId("act_".$counter);
345 
346  $this->ctrl->setParameter($this, 'search_grp', $grp_id);
347  $this->ctrl->setParameter($this, 'view', 'mygroups');
348 
349  if ($this->mailing_allowed)
350  $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
351  $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
352 
353  $this->ctrl->clearParameters($this);
354 
355  $rowData = array
356  (
357  'CRS_ID' => $grp_id,
358  'CRS_NAME' => $ilObjDataCache->lookupTitle($grp_id),
359  'CRS_NO_MEMBERS' => count($grp_members),
360  'CRS_PATH' => $path,
361  'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML()
362  );
363  $counter++;
364  $tableData[] = $rowData;
365  }
366  }
367  }
368  $table->setData($tableData);
369  if($counter > 0)
370  {
371  $this->tpl->setVariable('TXT_MARKED_ENTRIES',$lng->txt('marked_entries'));
372  }
373 
374  $searchTpl->setVariable('TABLE', $table->getHtml());
375  $this->tpl->setContent($searchTpl->get());
376  $this->tpl->show();
377  }
378 
382  public function showMembers()
383  {
384  global $lng, $ilUser;
385 
386  if ($_GET["search_grp"] != "")
387  {
388  $_POST["search_grp"] = explode(",", $_GET["search_grp"]);
389  }
390 
391  if (!is_array($_POST["search_grp"]) ||
392  count($_POST["search_grp"]) == 0)
393  {
394  ilUtil::sendInfo($lng->txt("mail_select_group"));
395  $this->showMyGroups();
396  }
397  else
398  {
399  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
400  include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
401  $table = new ilMailSearchCoursesMembersTableGUI($this, 'grp');
402  $table->setId('show_grps_mmbrs_tbl');
403  $lng->loadLanguageModule('crs');
404 
405  $counter = 0;
406  $tableData = array();
407  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
408 
409  foreach($_POST["search_grp"] as $grp_id)
410  {
411  $ref_ids = ilObject::_getAllReferences($grp_id);
412  $ref_id = current($ref_ids);
413 
414  if (is_object($group_obj = ilObjectFactory::getInstanceByRefId($ref_id,false)))
415  {
416  $grp_members = $group_obj->getGroupMemberData($group_obj->getGroupMemberIds());
417 
418  foreach($grp_members as $member)
419  {
420  $tmp_usr = new ilObjUser($member['id']);
421  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
422  {
423  unset($tmp_usr);
424  continue;
425  }
426  unset($tmp_usr);
427 
428  $fullname = "";
429  if(in_array(ilObjUser::_lookupPref($member['id'], 'public_profile'), array("g", 'y')))
430  $fullname = $member['lastname'].', '.$member['firstname'];
431 
432  $rowData = array(
433  'MEMBERS_ID' => $member["id"],
434  'MEMBERS_LOGIN' => $member["login"],
435  'MEMBERS_NAME' => $fullname,
436  'MEMBERS_CRS_GRP' => $group_obj->getTitle(),
437  'MEMBERS_IN_ADDRESSBOOK' => $this->abook->checkEntryByLogin($member["login"]) ? $lng->txt("yes") : $lng->txt("no"),
438  'search_grp' => $grp_id
439  );
440  $tableData[] = $rowData;
441  }
442  }
443  }
444  $table->setData($tableData);
445  if (count($tableData))
446  {
447  //$table->addCommandButton('mail', $lng->txt("grp_mem_send_mail"));
448  //$table->addCommandButton('adoptMembers', $lng->txt("mail_into_addressbook"));
449  $searchTpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
450  }
451  $searchTpl->setVariable('TABLE', $table->getHtml());
452  $this->tpl->setContent($searchTpl->get());
453  $this->tpl->show();
454  }
455  }
456 
457 }
458 
459 ?>