ILIAS  Release_3_10_x_branch Revision 61812
 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/Mail/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  public function __construct()
45  {
46  global $tpl, $ilCtrl, $lng, $ilUser;
47 
48  $this->tpl = $tpl;
49  $this->ctrl = $ilCtrl;
50  $this->lng = $lng;
51 
52  $this->ctrl->saveParameter($this, "mobj_id");
53 
54  $this->umail = new ilFormatMail($ilUser->getId());
55  $this->abook = new ilAddressbook($ilUser->getId());
56  }
57 
58  public function executeCommand()
59  {
60  $forward_class = $this->ctrl->getNextClass($this);
61  switch($forward_class)
62  {
63  default:
64  if (!($cmd = $this->ctrl->getCmd()))
65  {
66  $cmd = "showMyGroups";
67  }
68 
69  $this->$cmd();
70  break;
71  }
72  return true;
73  }
74 
75  function mail()
76  {
77  global $ilUser, $lng;
78 
79  if ($_GET["view"] == "mygroups")
80  {
81  if (is_array($_POST["search_grp"]))
82  {
83  $this->mailGroups();
84  }
85  else
86  {
87  ilUtil::sendInfo($lng->txt("mail_select_group"));
88  $this->showMyGroups();
89  }
90  }
91  else if ($_GET["view"] == "grp_members")
92  {
93  if (is_array($_POST["search_members"]))
94  {
95  $this->mailMembers();
96  }
97  else
98  {
99  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
100  $this->showMembers();
101  }
102  }
103  else
104  {
105  $this->showMyGroups();
106  }
107  }
108 
109  function mailGroups()
110  {
111  global $ilUser, $lng, $rbacreview;
112 
113  $members = array();
114 
115  if (!is_array($old_mail_data = $this->umail->getSavedData()))
116  {
117  $this->umail->savePostData(
118  $ilUser->getId(),
119  array(),
120  "",
121  "",
122  "",
123  "",
124  "",
125  "",
126  "",
127  ""
128  );
129  }
130 
131  require_once 'classes/class.ilObject.php';
132  foreach ($_POST["search_grp"] as $grp_id)
133  {
134  $ref_ids = ilObject::_getAllReferences($grp_id);
135  foreach ($ref_ids as $ref_id)
136  {
137  $roles = $rbacreview->getAssignableChildRoles($ref_id);
138  foreach ($roles as $role)
139  {
140  if (substr($role['title'], 0, 14) == 'il_grp_member_' ||
141  substr($role['title'], 0, 13) == 'il_grp_admin_')
142  {
143  if(isset($old_mail_data['rcp_to']) &&
144  trim($old_mail_data['rcp_to']) != '')
145  {
146  $rcpt = $rbacreview->getRoleMailboxAddress($role['obj_id']);
147 
148  if(!$this->umail->doesRecipientStillExists($rcpt, $old_mail_data['rcp_to']))
149  array_push($members, $rcpt);
150 
151  unset($rcpt);
152  }
153  else
154  {
155  array_push($members, $rbacreview->getRoleMailboxAddress($role['obj_id']));
156  }
157  }
158  }
159  }
160  }
161 
162  if(count($members))
163  $mail_data = $this->umail->appendSearchResult($members, 'to');
164  else
165  $mail_data = $this->umail->getSavedData();
166 
167  $this->umail->savePostData(
168  $mail_data["user_id"],
169  $mail_data["attachments"],
170  $mail_data["rcp_to"],
171  $mail_data["rcp_cc"],
172  $mail_data["rcp_bcc"],
173  $mail_data["m_type"],
174  $mail_data["m_email"],
175  $mail_data["m_subject"],
176  $mail_data["m_message"],
177  $mail_data["use_placeholders"]
178  );
179 
180  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
181  }
182 
183  function mailMembers()
184  {
185  $members = array();
186 
187  if (!is_array($this->umail->getSavedData()))
188  {
189  $this->umail->savePostData(
190  $ilUser->getId(),
191  array(),
192  "",
193  "",
194  "",
195  "",
196  "",
197  "",
198  "",
199  ""
200  );
201  }
202 
203  foreach ($_POST["search_members"] as $member)
204  {
205  $login = ilObjUser::_lookupLogin($member);
206  array_push($members, $login);
207  }
208  $mail_data = $this->umail->appendSearchResult($members,"to");
209 
210  $this->umail->savePostData(
211  $mail_data["user_id"],
212  $mail_data["attachments"],
213  $mail_data["rcp_to"],
214  $mail_data["rcp_cc"],
215  $mail_data["rcp_bcc"],
216  $mail_data["m_type"],
217  $mail_data["m_email"],
218  $mail_data["m_subject"],
219  $mail_data["m_message"],
220  $mail_data["use_placeholders"]
221  );
222 
223  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
224  }
225 
229  public function adoptMembers()
230  {
231  global $lng;
232 
233  if (is_array($_POST["search_members"]))
234  {
235  $members = array();
236 
237  foreach ($_POST["search_members"] as $member)
238  {
239  $login = ilObjUser::_lookupLogin($member);
240 
241  if (!$this->abook->checkEntry($login))
242  {
243  $name = ilObjUser::_lookupName($member);
244  $email = '';
245  if(ilObjUser::_lookupPref((int)$member, 'public_email') == 'y')
246  {
247  $email = ilObjUser::_lookupEmail($member);
248  }
249  $this->abook->addEntry(
250  $login,
251  $name["firstname"],
252  $name["lastname"],
253  $email
254  );
255  }
256  }
257  ilUtil::sendInfo($lng->txt("mail_members_added_addressbook"));
258  }
259  else
260  {
261  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
262  }
263 
264  $this->showMembers();
265  }
266 
270  function cancel()
271  {
272  if ($_GET["view"] == "mygroups" &&
273  $_GET["ref"] == "mail")
274  {
275  $this->ctrl->returnToParent($this);
276  }
277  else
278  {
279  $this->showMyGroups();
280  }
281  }
282 
286  public function showMyGroups()
287  {
288  global $lng, $ilUser, $ilObjDataCache, $tree;
289 
290  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail_addressbook_search.html', 'Services/Mail');
291  $this->tpl->setVariable('HEADER', $this->lng->txt('mail'));
292 
293  $_GET['view'] = 'mygroups';
294 
295  $this->ctrl->setParameter($this, 'view', 'mygroups');
296  if ($_GET['ref'] != '') $this->ctrl->setParameter($this, 'ref', $_GET['ref']);
297  if (is_array($_POST['search_grp'])) $this->ctrl->setParameter($this, 'search_grp', implode(',', $_POST['search_grp']));
298  $this->tpl->setVariable('ACTION', $this->ctrl->getFormAction($this));
299  $this->ctrl->clearParameters($this);
300 
301  $lng->loadLanguageModule('crs');
302 
303  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
304  $grp_ids = ilGroupParticipants::_getMembershipByType($ilUser->getId(), 'grp');
305 
306  $counter = 0;
307  if (is_array($grp_ids) &&
308  count($grp_ids) > 0)
309  {
310  $this->tpl->setVariable('GRP_TXT_GROUPS',$lng->txt('mail_my_groups'));
311  $this->tpl->setVariable('GRP_TXT_GROUPS_PATHS',$lng->txt('path'));
312  $this->tpl->setVariable('GRP_TXT_NO_MEMBERS',$lng->txt('grp_count_members'));
313 
314  foreach($grp_ids as $grp_id)
315  {
317  {
318  $oGroupParticipants = ilGroupParticipants::_getInstanceByObjId($grp_id);
319  $grp_members = $oGroupParticipants->getParticipants();
320 
321  foreach ($grp_members as $key => $member)
322  {
323  $tmp_usr = new ilObjUser($member);
324 
325  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
326  {
327  unset($grp_members[$key]);
328  }
329  }
330  unset($tmp_usr);
331 
332  $ref_ids = ilObject::_getAllReferences($grp_id);
333  $ref_id = current($ref_ids);
334  $path_arr = $tree->getPathFull($ref_id, $tree->getRootId());
335  $path_counter = 0;
336  $path = '';
337  foreach($path_arr as $data)
338  {
339  if($path_counter++)
340  {
341  $path .= " -> ";
342  }
343  $path .= $data['title'];
344  }
345  $path = $this->lng->txt('path').': '.$path;
346 
347  $this->tpl->setCurrentBlock('loop_grp');
348  $this->tpl->setVariable('LOOP_GRP_CSSROW', ++$counter % 2 ? 'tblrow1' : 'tblrow2');
349  $this->tpl->setVariable('LOOP_GRP_ID', $grp_id);
350  $this->tpl->setVariable('LOOP_GRP_NAME', $ilObjDataCache->lookupTitle($grp_id));
351  $this->tpl->setVariable('LOOP_GRP_NO_MEMBERS', count($grp_members));
352  $this->tpl->setVariable('LOOP_GRP_PATH', $path);
353  $this->tpl->parseCurrentBlock();
354  }
355  }
356 
357  if((int)$counter)
358  {
359  $this->tpl->setVariable('BUTTON_MAIL', $lng->txt('mail_members'));
360  $this->tpl->setVariable('BUTTON_LIST', $lng->txt('mail_list_members'));
361  }
362  }
363 
364  if($counter == 0)
365  {
366  $this->tpl->setCurrentBlock('grp_not_found');
367  $this->tpl->setVariable('TXT_GRP_NOT_FOUND', $lng->txt('mail_search_groups_not_found'));
368  $this->tpl->parseCurrentBlock();
369 
370  $this->tpl->touchBlock('entries_not_found');
371  }
372  else
373  {
374  $this->tpl->setVariable('TXT_MARKED_ENTRIES',$lng->txt('marked_entries'));
375  }
376 
377  if($_GET['ref'] == 'mail') $this->tpl->setVariable('BUTTON_CANCEL', $lng->txt('cancel'));
378 
379  $this->tpl->show();
380  }
381 
385  public function showMembers()
386  {
387  global $lng, $ilUser;
388 
389  if ($_GET["search_grp"] != "")
390  {
391  $_POST["search_grp"] = explode(",", $_GET["search_grp"]);
392  }
393 
394  if (!is_array($_POST["search_grp"]) ||
395  count($_POST["search_grp"]) == 0)
396  {
397  ilUtil::sendInfo($lng->txt("mail_select_group"));
398  $this->showMyGroups();
399  }
400  else
401  {
402  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook_search.html", "Services/Mail");
403  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
404 
405  $this->ctrl->setParameter($this, "view", "grp_members");
406  if ($_GET["ref"] != "") $this->ctrl->setParameter($this, "ref", $_GET["ref"]);
407  if (is_array($_POST["search_grp"])) $this->ctrl->setParameter($this, "search_grp", implode(",", $_POST["search_grp"]));
408  $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this));
409  $this->ctrl->clearParameters($this);
410 
411  $lng->loadLanguageModule('crs');
412 
413  $this->tpl->setCurrentBlock("members_group");
414  $this->tpl->setVariable("MEMBERS_TXT_GROUP",$lng->txt("obj_grp"));
415  $this->tpl->parseCurrentBlock();
416  $this->tpl->setVariable("MEMBERS_TXT_LOGIN",$lng->txt("login"));
417  $this->tpl->setVariable("MEMBERS_TXT_NAME",$lng->txt("name"));
418  $this->tpl->setVariable("MEMBERS_TXT_IN_ADDRESSBOOK",$lng->txt("mail_in_addressbook"));
419 
420  $counter = 0;
421  foreach($_POST["search_grp"] as $grp_id)
422  {
423  $ref_ids = ilObject::_getAllReferences($grp_id);
424  $ref_id = current($ref_ids);
425 
426  if (is_object($group_obj = ilObjectFactory::getInstanceByRefId($ref_id,false)))
427  {
428  $grp_members = $group_obj->getGroupMemberData($group_obj->getGroupMemberIds());
429 
430  foreach($grp_members as $member)
431  {
432  $tmp_usr = new ilObjUser($member["id"]);
433  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
434  {
435  unset($tmp_usr);
436  continue;
437  }
438  unset($tmp_usr);
439 
440  $this->tpl->setCurrentBlock("loop_members");
441  $this->tpl->setVariable("LOOP_MEMBERS_CSSROW",++$counter%2 ? 'tblrow1' : 'tblrow2');
442  $this->tpl->setVariable("LOOP_MEMBERS_ID",$member["id"]);
443  $this->tpl->setVariable("LOOP_MEMBERS_LOGIN",$member["login"]);
444  if(ilObjUser::_lookupPref($member['id'], 'public_profile') == 'y')
445  {
446  $this->tpl->setVariable('LOOP_MEMBERS_NAME', $member['lastname'].', '.$member['firstname']);
447  }
448  $this->tpl->setVariable("LOOP_MEMBERS_CRS_GRP",$group_obj->getTitle());
449  $this->tpl->setVariable("LOOP_MEMBERS_IN_ADDRESSBOOK", $this->abook->checkEntryByLogin($member["login"]) ? $lng->txt("yes") : $lng->txt("no"));
450  $this->tpl->parseCurrentBlock();
451  }
452  }
453  }
454 
455  if ($counter == 0)
456  {
457  $this->tpl->setCurrentBlock("members_not_found");
458  $this->tpl->setVariable("TXT_MEMBERS_NOT_FOUND",$lng->txt("mail_search_members_not_found"));
459  $this->tpl->parseCurrentBlock();
460 
461  $this->tpl->touchBlock("entries_not_found");
462  }
463  else
464  {
465  $this->tpl->setVariable("BUTTON_MAIL",$lng->txt("grp_mem_send_mail"));
466  $this->tpl->setVariable("BUTTON_ADOPT",$lng->txt("mail_into_addressbook"));
467 
468  $this->tpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
469  }
470 
471  $this->tpl->setVariable("BUTTON_CANCEL",$lng->txt("cancel"));
472 
473  $this->tpl->show();
474  }
475  }
476 
477 }
478 
479 ?>