ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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/BuddySystem/classes/class.ilBuddySystem.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  }
49 
50  public function executeCommand()
51  {
55  global $ilErr;
56 
57  $forward_class = $this->ctrl->getNextClass($this);
58  switch($forward_class)
59  {
60  case 'ilbuddysystemgui':
61  if(!ilBuddySystem::getInstance()->isEnabled())
62  {
63  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
64  }
65 
66  require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemGUI.php';
67  $this->ctrl->saveParameter($this, 'search_grp');
68  $this->ctrl->setReturn($this, 'showMembers');
69  $this->ctrl->forwardCommand(new ilBuddySystemGUI());
70  break;
71 
72  default:
73  if (!($cmd = $this->ctrl->getCmd()))
74  {
75  $cmd = "showMyGroups";
76  }
77 
78  $this->$cmd();
79  break;
80  }
81  return true;
82  }
83 
84  function mail()
85  {
86  global $lng;
87 
88  if ($_GET["view"] == "mygroups")
89  {
90  $ids = ((int) $_GET['search_grp']) ? array((int)$_GET['search_grp']) : $_POST['search_grp'];
91  if ($ids)
92  {
93  $this->mailGroups();
94  }
95  else
96  {
97  ilUtil::sendInfo($lng->txt("mail_select_group"));
98  $this->showMyGroups();
99  }
100  }
101  else if ($_GET["view"] == "grp_members")
102  {
103  $ids = ((int) $_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
104  if ($ids)
105  {
106  $this->mailMembers();
107  }
108  else
109  {
110  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
111  $this->showMembers();
112  }
113  }
114  else
115  {
116  $this->showMyGroups();
117  }
118  }
119 
120  function mailGroups()
121  {
122  global $ilUser, $rbacreview;
123 
124  $members = array();
125 
126  if (!is_array($old_mail_data = $this->umail->getSavedData()))
127  {
128  $this->umail->savePostData(
129  $ilUser->getId(),
130  array(),
131  "",
132  "",
133  "",
134  "",
135  "",
136  "",
137  "",
138  ""
139  );
140  }
141 
142  require_once './Services/Object/classes/class.ilObject.php';
143  $ids = ((int) $_GET['search_grp']) ? array((int)$_GET['search_grp']) : $_POST['search_grp'];
144  foreach ($ids as $grp_id)
145  {
146  $ref_ids = ilObject::_getAllReferences($grp_id);
147  foreach ($ref_ids as $ref_id)
148  {
149  $roles = $rbacreview->getAssignableChildRoles($ref_id);
150  foreach ($roles as $role)
151  {
152  if (substr($role['title'], 0, 14) == 'il_grp_member_' ||
153  substr($role['title'], 0, 13) == 'il_grp_admin_')
154  {
155  if(isset($old_mail_data['rcp_to']) &&
156  trim($old_mail_data['rcp_to']) != '')
157  {
158  $rcpt = $rbacreview->getRoleMailboxAddress($role['obj_id']);
159  if(!$this->umail->doesRecipientStillExists($rcpt, $old_mail_data['rcp_to']))
160  {
161  array_push($members, $rcpt);
162  }
163  }
164  else
165  {
166  array_push($members, $rbacreview->getRoleMailboxAddress($role['obj_id']));
167  }
168  }
169  }
170  }
171  }
172 
173  if(count($members))
174  $mail_data = $this->umail->appendSearchResult($members, 'to');
175  else
176  $mail_data = $this->umail->getSavedData();
177 
178  $this->umail->savePostData(
179  $mail_data["user_id"],
180  $mail_data["attachments"],
181  $mail_data["rcp_to"],
182  $mail_data["rcp_cc"],
183  $mail_data["rcp_bcc"],
184  $mail_data["m_type"],
185  $mail_data["m_email"],
186  $mail_data["m_subject"],
187  $mail_data["m_message"],
188  $mail_data["use_placeholders"],
189  $mail_data['tpl_ctx_id'],
190  $mail_data['tpl_ctx_params']
191  );
192 
193  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
194  }
195 
196  function mailMembers()
197  {
198  global $ilUser;
199 
200  $members = array();
201 
202  if (!is_array($this->umail->getSavedData()))
203  {
204  $this->umail->savePostData(
205  $ilUser->getId(),
206  array(),
207  "",
208  "",
209  "",
210  "",
211  "",
212  "",
213  "",
214  ""
215  );
216  }
217 
218  $ids = ((int) $_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
219 
220  foreach ($ids as $member)
221  {
222  $login = ilObjUser::_lookupLogin($member);
223  array_push($members, $login);
224  }
225  $mail_data = $this->umail->appendSearchResult($members,"to");
226 
227  $this->umail->savePostData(
228  $mail_data["user_id"],
229  $mail_data["attachments"],
230  $mail_data["rcp_to"],
231  $mail_data["rcp_cc"],
232  $mail_data["rcp_bcc"],
233  $mail_data["m_type"],
234  $mail_data["m_email"],
235  $mail_data["m_subject"],
236  $mail_data["m_message"],
237  $mail_data["use_placeholders"],
238  $mail_data['tpl_ctx_id'],
239  $mail_data['tpl_ctx_params']
240  );
241 
242  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
243  }
244 
248  public function adoptMembers()
249  {
250  global $lng;
251 
252  $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
253 
254  if ($ids )
255  {
256  foreach ($ids as $member)
257  {
258  $login = ilObjUser::_lookupLogin($member);
259 
260  if (!$this->abook->checkEntry($login))
261  {
262  $name = ilObjUser::_lookupName($member);
263  $email = '';
264  if(ilObjUser::_lookupPref((int)$member, 'public_email') == 'y')
265  {
266  $email = ilObjUser::_lookupEmail($member);
267  }
268  $this->abook->addEntry(
269  $login,
270  $name["firstname"],
271  $name["lastname"],
272  $email
273  );
274  }
275  }
276  ilUtil::sendInfo($lng->txt("mail_members_added_addressbook"));
277  }
278  else
279  {
280  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
281  }
282 
283  $this->showMembers();
284  }
285 
289  function cancel()
290  {
291  if ($_GET["view"] == "mygroups" &&
292  $_GET["ref"] == "mail")
293  {
294  $this->ctrl->returnToParent($this);
295  }
296  else
297  {
298  $this->showMyGroups();
299  }
300  }
301 
305  public function showMyGroups()
306  {
307  global $lng, $ilUser, $ilObjDataCache, $tree;
308 
309  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
310 
311  $this->tpl->setTitle($this->lng->txt('mail_addressbook'));
312 
313  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
314 
315  $_GET['view'] = 'mygroups';
316 
317  $lng->loadLanguageModule('crs');
318 
319  $this->ctrl->setParameter($this, 'view', 'mygroups');
320 
321  include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
322  $table = new ilMailSearchCoursesTableGUI($this, 'grp', $_GET["ref"]);
323  $table->setId('search_grps_tbl');
324  $grp_ids = ilGroupParticipants::_getMembershipByType($ilUser->getId(), 'grp');
325 
326  $counter = 0;
327  $tableData = array();
328  if (is_array($grp_ids) &&
329  count($grp_ids) > 0)
330  {
331 
332  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
333  foreach($grp_ids as $grp_id)
334  {
336  {
337  $oGroupParticipants = ilGroupParticipants::_getInstanceByObjId($grp_id);
338  $grp_members = $oGroupParticipants->getParticipants();
339 
340  foreach ($grp_members as $key => $member)
341  {
342  $tmp_usr = new ilObjUser($member);
343 
344  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
345  {
346  unset($grp_members[$key]);
347  }
348  }
349  unset($tmp_usr);
350 
351  $ref_ids = ilObject::_getAllReferences($grp_id);
352  $ref_id = current($ref_ids);
353  $path_arr = $tree->getPathFull($ref_id, $tree->getRootId());
354  $path_counter = 0;
355  $path = '';
356  foreach($path_arr as $data)
357  {
358  if($path_counter++)
359  {
360  $path .= " -> ";
361  }
362  $path .= $data['title'];
363  }
364  $path = $this->lng->txt('path').': '.$path;
365 
366  $current_selection_list = new ilAdvancedSelectionListGUI();
367  $current_selection_list->setListTitle($this->lng->txt("actions"));
368  $current_selection_list->setId("act_".$counter);
369 
370  $this->ctrl->setParameter($this, 'search_grp', $grp_id);
371  $this->ctrl->setParameter($this, 'view', 'mygroups');
372 
373  if($_GET["ref"] == "mail")
374  {
375  if ($this->mailing_allowed)
376  $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
377  }
378  else if($_GET["ref"] == "wsp")
379  {
380  $current_selection_list->addItem($this->lng->txt("wsp_share_with_members"), '', $this->ctrl->getLinkTarget($this, "share"));
381  }
382  $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
383 
384  $this->ctrl->clearParameters($this);
385 
386  $rowData = array
387  (
388  'CRS_ID' => $grp_id,
389  'CRS_NAME' => $ilObjDataCache->lookupTitle($grp_id),
390  'CRS_NO_MEMBERS' => count($grp_members),
391  'CRS_PATH' => $path,
392  'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML()
393  );
394  $counter++;
395  $tableData[] = $rowData;
396  }
397  }
398  }
399  $table->setData($tableData);
400  if($counter > 0)
401  {
402  $this->tpl->setVariable('TXT_MARKED_ENTRIES',$lng->txt('marked_entries'));
403  }
404 
405  $searchTpl->setVariable('TABLE', $table->getHtml());
406  $this->tpl->setContent($searchTpl->get());
407 
408  if($_GET["ref"] != "wsp")
409  {
410  $this->tpl->show();
411  }
412  }
413 
417  public function showMembers()
418  {
423  global $lng, $ilUser;
424 
425  if ($_GET["search_grp"] != "")
426  {
427  $_POST["search_grp"] = explode(",", $_GET["search_grp"]);
428  }
429 
430  if (!is_array($_POST["search_grp"]) ||
431  count($_POST["search_grp"]) == 0)
432  {
433  ilUtil::sendInfo($lng->txt("mail_select_group"));
434  $this->showMyGroups();
435  }
436  else
437  {
438  $this->tpl->setTitle($this->lng->txt("mail_addressbook"));
439  include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
440  $context = $_GET["ref"] ? $_GET["ref"] : "mail";
441  $table = new ilMailSearchCoursesMembersTableGUI($this, 'grp', $context);
442  $lng->loadLanguageModule('crs');
443 
444  $tableData = array();
445  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
446 
447  foreach($_POST["search_grp"] as $grp_id)
448  {
449  $ref_ids = ilObject::_getAllReferences($grp_id);
450  $ref_id = current($ref_ids);
451 
452  if (is_object($group_obj = ilObjectFactory::getInstanceByRefId($ref_id,false)))
453  {
454  $grp_members = $group_obj->getGroupMemberData($group_obj->getGroupMemberIds());
455 
456  foreach($grp_members as $member)
457  {
458  $tmp_usr = new ilObjUser($member['id']);
459  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
460  {
461  unset($tmp_usr);
462  continue;
463  }
464  unset($tmp_usr);
465 
466  $fullname = "";
467  if(in_array(ilObjUser::_lookupPref($member['id'], 'public_profile'), array("g", 'y')))
468  $fullname = $member['lastname'].', '.$member['firstname'];
469 
470  $rowData = array(
471  'members_id' => $member["id"],
472  'members_login' => $member["login"],
473  'members_name' => $fullname,
474  'members_crs_grp' => $group_obj->getTitle(),
475  'search_grp' => $grp_id,
476  );
477 
478  if('mail' == $context && ilBuddySystem::getInstance()->isEnabled())
479  {
480  $relation = ilBuddyList::getInstanceByGlobalUser()->getRelationByUserId($member['id']);
481  $state_name = ilStr::convertUpperCamelCaseToUnderscoreCase($relation->getState()->getName());
482  $rowData['status'] = '';
483  if($member['id'] != $ilUser->getId())
484  {
485  if($relation->isOwnedByRequest())
486  {
487  $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_a');
488  }
489  else
490  {
491  $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_p');
492  }
493  }
494  }
495 
496  $tableData[] = $rowData;
497  }
498  }
499  }
500  $table->setData($tableData);
501  if (count($tableData))
502  {
503  $searchTpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
504  }
505  $searchTpl->setVariable('TABLE', $table->getHtml());
506  $this->tpl->setContent($searchTpl->get());
507 
508  if($_GET["ref"] != "wsp")
509  {
510  $this->tpl->show();
511  }
512  }
513  }
514 
515  function share()
516  {
517  global $lng;
518 
519  if ($_GET["view"] == "mygroups")
520  {
521  $ids = $_REQUEST["search_grp"];
522  if (sizeof($ids))
523  {
524  $this->addPermission($ids);
525  }
526  else
527  {
528  ilUtil::sendInfo($lng->txt("mail_select_course"));
529  $this->showMyGroups();
530  }
531  }
532  else if ($_GET["view"] == "grp_members")
533  {
534  $ids = $_REQUEST["search_members"];
535  if (sizeof($ids))
536  {
537  $this->addPermission($ids);
538  }
539  else
540  {
541  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
542  $this->showMembers();
543  }
544  }
545  else
546  {
547  $this->showMyGroups();
548  }
549  }
550 
551  protected function addPermission($a_obj_ids)
552  {
553  if(!is_array($a_obj_ids))
554  {
555  $a_obj_ids = array($a_obj_ids);
556  }
557 
558  $existing = $this->wsp_access_handler->getPermissions($this->wsp_node_id);
559  $added = false;
560  foreach($a_obj_ids as $object_id)
561  {
562  if(!in_array($object_id, $existing))
563  {
564  $added = $this->wsp_access_handler->addPermission($this->wsp_node_id, $object_id);
565  }
566  }
567 
568  if($added)
569  {
570  ilUtil::sendSuccess($this->lng->txt("wsp_share_success"), true);
571  }
572  $this->ctrl->redirectByClass("ilworkspaceaccessgui", "share");
573  }
574 }
575 
576 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
Class ilBuddySystemGUI.
static convertUpperCamelCaseToUnderscoreCase($value)
Convert a value given in camel case conversion to underscore case conversion (e.g.
$_POST['username']
Definition: cron.php:12
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
$_SESSION["AccountId"]
$_GET["client_id"]
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
$cmd
Definition: sahs_server.php:35
_lookupPref($a_usr_id, $a_keyword)
static _getAllReferences($a_id)
get all reference ids of object
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Class UserMail this class handles user mails.
$data
Class Mail this class handles base functions for mail handling.
special template class to simplify handling of ITX/PEAR
__construct($wsp_access_handler=null, $wsp_node_id=null)
_lookupEmail($a_user_id)
Lookup email.
adoptMembers()
Take over course members to addressbook.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
User interface class for advanced drop-down selection lists.
_hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
global $ilUser
Definition: imgupload.php:15
$ref_id
Definition: sahs_server.php:39
$path
Definition: index.php:22
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
static redirect($a_script)
http redirect to other script
showMyGroups()
Show user&#39;s courses.