ILIAS  Release_4_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  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once './Services/User/classes/class.ilObjUser.php';
25 require_once 'Services/Mail/classes/class.ilMailbox.php';
26 require_once 'Services/Mail/classes/class.ilFormatMail.php';
27 require_once 'Services/Contact/classes/class.ilAddressbook.php';
28 
36 {
37  private $tpl = null;
38  private $ctrl = null;
39  private $lng = null;
40 
41  private $umail = null;
42  private $abook = null;
43 
44  protected $mailing_allowed;
45 
46  public function __construct()
47  {
48  global $tpl, $ilCtrl, $lng, $ilUser, $rbacsystem;
49 
50  $this->tpl = $tpl;
51  $this->ctrl = $ilCtrl;
52  $this->lng = $lng;
53 
54  $this->ctrl->saveParameter($this, "mobj_id");
55 
56  // check if current user may send mails
57  include_once "Services/Mail/classes/class.ilMail.php";
58  $mail = new ilMail($_SESSION["AccountId"]);
59  $this->mailing_allowed = $rbacsystem->checkAccess('mail_visible',$mail->getMailObjectReferenceId());
60 
61  $this->umail = new ilFormatMail($ilUser->getId());
62  $this->abook = new ilAddressbook($ilUser->getId());
63  }
64 
65  public function executeCommand()
66  {
67  $forward_class = $this->ctrl->getNextClass($this);
68  switch($forward_class)
69  {
70  default:
71  if (!($cmd = $this->ctrl->getCmd()))
72  {
73  $cmd = "showMyGroups";
74  }
75 
76  $this->$cmd();
77  break;
78  }
79  return true;
80  }
81 
82  function mail()
83  {
84  global $ilUser, $lng;
85 
86  if ($_GET["view"] == "mygroups")
87  {
88  $ids = ((int) $_GET['search_grp']) ? array((int)$_GET['search_grp']) : $_POST['search_grp'];
89  if ($ids)
90  {
91  $this->mailGroups();
92  }
93  else
94  {
95  ilUtil::sendInfo($lng->txt("mail_select_group"));
96  $this->showMyGroups();
97  }
98  }
99  else if ($_GET["view"] == "grp_members")
100  {
101  $ids = ((int) $_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
102  if ($ids)
103  {
104  $this->mailMembers();
105  }
106  else
107  {
108  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
109  $this->showMembers();
110  }
111  }
112  else
113  {
114  $this->showMyGroups();
115  }
116  }
117 
118  function mailGroups()
119  {
120  global $ilUser, $lng, $rbacreview;
121 
122  $members = array();
123 
124  if (!is_array($old_mail_data = $this->umail->getSavedData()))
125  {
126  $this->umail->savePostData(
127  $ilUser->getId(),
128  array(),
129  "",
130  "",
131  "",
132  "",
133  "",
134  "",
135  "",
136  ""
137  );
138  }
139 
140  require_once 'classes/class.ilObject.php';
141  $ids = ((int) $_GET['search_grp']) ? array((int)$_GET['search_grp']) : $_POST['search_grp'];
142  foreach ($ids as $grp_id)
143  {
144  $ref_ids = ilObject::_getAllReferences($grp_id);
145  foreach ($ref_ids as $ref_id)
146  {
147  $roles = $rbacreview->getAssignableChildRoles($ref_id);
148  foreach ($roles as $role)
149  {
150  if (substr($role['title'], 0, 14) == 'il_grp_member_' ||
151  substr($role['title'], 0, 13) == 'il_grp_admin_')
152  {
153  if(isset($old_mail_data['rcp_to']) &&
154  trim($old_mail_data['rcp_to']) != '')
155  {
156  $rcpt = $rbacreview->getRoleMailboxAddress($role['obj_id']);
157 
158  if(!$this->umail->doesRecipientStillExists($rcpt, $old_mail_data['rcp_to']))
159  array_push($members, $rcpt);
160 
161  unset($rcpt);
162  }
163  else
164  {
165  array_push($members, $rbacreview->getRoleMailboxAddress($role['obj_id']));
166  }
167  }
168  }
169  }
170  }
171 
172  if(count($members))
173  $mail_data = $this->umail->appendSearchResult($members, 'to');
174  else
175  $mail_data = $this->umail->getSavedData();
176 
177  $this->umail->savePostData(
178  $mail_data["user_id"],
179  $mail_data["attachments"],
180  $mail_data["rcp_to"],
181  $mail_data["rcp_cc"],
182  $mail_data["rcp_bcc"],
183  $mail_data["m_type"],
184  $mail_data["m_email"],
185  $mail_data["m_subject"],
186  $mail_data["m_message"],
187  $mail_data["use_placeholders"]
188  );
189 
190  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
191  }
192 
193  function mailMembers()
194  {
195  $members = array();
196 
197  if (!is_array($this->umail->getSavedData()))
198  {
199  $this->umail->savePostData(
200  $ilUser->getId(),
201  array(),
202  "",
203  "",
204  "",
205  "",
206  "",
207  "",
208  "",
209  ""
210  );
211  }
212 
213  $ids = ((int) $_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
214 
215  foreach ($ids as $member)
216  {
217  $login = ilObjUser::_lookupLogin($member);
218  array_push($members, $login);
219  }
220  $mail_data = $this->umail->appendSearchResult($members,"to");
221 
222  $this->umail->savePostData(
223  $mail_data["user_id"],
224  $mail_data["attachments"],
225  $mail_data["rcp_to"],
226  $mail_data["rcp_cc"],
227  $mail_data["rcp_bcc"],
228  $mail_data["m_type"],
229  $mail_data["m_email"],
230  $mail_data["m_subject"],
231  $mail_data["m_message"],
232  $mail_data["use_placeholders"]
233  );
234 
235  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
236  }
237 
241  public function adoptMembers()
242  {
243  global $lng;
244 
245  $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
246 
247  if ($ids )
248  {
249  $members = array();
250 
251  foreach ($ids as $member)
252  {
253  $login = ilObjUser::_lookupLogin($member);
254 
255  if (!$this->abook->checkEntry($login))
256  {
257  $name = ilObjUser::_lookupName($member);
258  $email = '';
259  if(ilObjUser::_lookupPref((int)$member, 'public_email') == 'y')
260  {
261  $email = ilObjUser::_lookupEmail($member);
262  }
263  $this->abook->addEntry(
264  $login,
265  $name["firstname"],
266  $name["lastname"],
267  $email
268  );
269  }
270  }
271  ilUtil::sendInfo($lng->txt("mail_members_added_addressbook"));
272  }
273  else
274  {
275  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
276  }
277 
278  $this->showMembers();
279  }
280 
284  function cancel()
285  {
286  if ($_GET["view"] == "mygroups" &&
287  $_GET["ref"] == "mail")
288  {
289  $this->ctrl->returnToParent($this);
290  }
291  else
292  {
293  $this->showMyGroups();
294  }
295  }
296 
300  public function showMyGroups()
301  {
302  global $lng, $ilUser, $ilObjDataCache, $tree;
303 
304  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
305 
306  $this->tpl->setVariable('HEADER', $this->lng->txt('mail'));
307 
308  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
309 
310  $_GET['view'] = 'mygroups';
311 
312  $lng->loadLanguageModule('crs');
313 
314  $this->ctrl->setParameter($this, 'view', 'mygroups');
315 
316  include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
317  $table = new ilMailSearchCoursesTableGUI($this, 'grp');
318  $table->setId('search_grps_tbl');
319  $grp_ids = ilGroupParticipants::_getMembershipByType($ilUser->getId(), 'grp');
320 
321  $counter = 0;
322  $tableData = array();
323  if (is_array($grp_ids) &&
324  count($grp_ids) > 0)
325  {
326 
327  include_once("./Services/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
328  foreach($grp_ids as $grp_id)
329  {
331  {
332  $oGroupParticipants = ilGroupParticipants::_getInstanceByObjId($grp_id);
333  $grp_members = $oGroupParticipants->getParticipants();
334 
335  foreach ($grp_members as $key => $member)
336  {
337  $tmp_usr = new ilObjUser($member);
338 
339  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
340  {
341  unset($grp_members[$key]);
342  }
343  }
344  unset($tmp_usr);
345 
346  $ref_ids = ilObject::_getAllReferences($grp_id);
347  $ref_id = current($ref_ids);
348  $path_arr = $tree->getPathFull($ref_id, $tree->getRootId());
349  $path_counter = 0;
350  $path = '';
351  foreach($path_arr as $data)
352  {
353  if($path_counter++)
354  {
355  $path .= " -> ";
356  }
357  $path .= $data['title'];
358  }
359  $path = $this->lng->txt('path').': '.$path;
360 
361  $current_selection_list = new ilAdvancedSelectionListGUI();
362  $current_selection_list->setListTitle($this->lng->txt("actions"));
363  $current_selection_list->setId("act_".$counter);
364 
365  $this->ctrl->setParameter($this, 'search_grp', $grp_id);
366  $this->ctrl->setParameter($this, 'view', 'mygroups');
367 
368  if ($this->mailing_allowed)
369  $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
370  $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
371 
372  $this->ctrl->clearParameters($this);
373 
374  $rowData = array
375  (
376  'CRS_ID' => $grp_id,
377  'CRS_NAME' => $ilObjDataCache->lookupTitle($grp_id),
378  'CRS_NO_MEMBERS' => count($grp_members),
379  'CRS_PATH' => $path,
380  'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML()
381  );
382  $counter++;
383  $tableData[] = $rowData;
384  }
385  }
386  }
387  $table->setData($tableData);
388  if($counter > 0)
389  {
390  $this->tpl->setVariable('TXT_MARKED_ENTRIES',$lng->txt('marked_entries'));
391  }
392 
393  $searchTpl->setVariable('TABLE', $table->getHtml());
394  $this->tpl->setContent($searchTpl->get());
395  $this->tpl->show();
396  }
397 
401  public function showMembers()
402  {
403  global $lng, $ilUser;
404 
405  if ($_GET["search_grp"] != "")
406  {
407  $_POST["search_grp"] = explode(",", $_GET["search_grp"]);
408  }
409 
410  if (!is_array($_POST["search_grp"]) ||
411  count($_POST["search_grp"]) == 0)
412  {
413  ilUtil::sendInfo($lng->txt("mail_select_group"));
414  $this->showMyGroups();
415  }
416  else
417  {
418  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
419  include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
420  $table = new ilMailSearchCoursesMembersTableGUI($this, 'grp');
421  $table->setId('show_grps_mmbrs_tbl');
422  $lng->loadLanguageModule('crs');
423 
424  $counter = 0;
425  $tableData = array();
426  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
427 
428  foreach($_POST["search_grp"] as $grp_id)
429  {
430  $ref_ids = ilObject::_getAllReferences($grp_id);
431  $ref_id = current($ref_ids);
432 
433  if (is_object($group_obj = ilObjectFactory::getInstanceByRefId($ref_id,false)))
434  {
435  $grp_members = $group_obj->getGroupMemberData($group_obj->getGroupMemberIds());
436 
437  foreach($grp_members as $member)
438  {
439  $tmp_usr = new ilObjUser($member['id']);
440  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
441  {
442  unset($tmp_usr);
443  continue;
444  }
445  unset($tmp_usr);
446 
447  $fullname = "";
448  if(in_array(ilObjUser::_lookupPref($member['id'], 'public_profile'), array("g", 'y')))
449  $fullname = $member['lastname'].', '.$member['firstname'];
450 
451  $rowData = array(
452  'MEMBERS_ID' => $member["id"],
453  'MEMBERS_LOGIN' => $member["login"],
454  'MEMBERS_NAME' => $fullname,
455  'MEMBERS_CRS_GRP' => $group_obj->getTitle(),
456  'MEMBERS_IN_ADDRESSBOOK' => $this->abook->checkEntryByLogin($member["login"]) ? $lng->txt("yes") : $lng->txt("no"),
457  'search_grp' => $grp_id
458  );
459  $tableData[] = $rowData;
460  }
461  }
462  }
463  $table->setData($tableData);
464  if (count($tableData))
465  {
466  //$table->addCommandButton('mail', $lng->txt("grp_mem_send_mail"));
467  //$table->addCommandButton('adoptMembers', $lng->txt("mail_into_addressbook"));
468  $searchTpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
469  }
470  $searchTpl->setVariable('TABLE', $table->getHtml());
471  $this->tpl->setContent($searchTpl->get());
472  $this->tpl->show();
473  }
474  }
475 
476 }
477 
478 ?>