ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailAddressbookGUI.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 require_once "Services/Contact/classes/class.ilAddressbookTableGUI.php";
10 
11 
21 {
22  private $tpl = null;
23  private $ctrl = null;
24  private $lng = null;
25  private $tabs_gui = null;
26 
27  private $umail = null;
28  private $abook = null;
29 
30  public function __construct()
31  {
32  global $tpl, $ilCtrl, $lng, $ilUser, $ilTabs;
33 
34  $this->tpl = $tpl;
35  $this->ctrl = $ilCtrl;
36  $this->lng = $lng;
37  $this->tabs_gui =& $ilTabs;
38 
39  $this->ctrl->saveParameter($this, "mobj_id");
40 
41  $this->umail = new ilFormatMail($ilUser->getId());
42  $this->abook = new ilAddressbook($ilUser->getId());
43  }
44 
45  public function executeCommand()
46  {
47  global $ilUser;
48  $this->showSubTabs();
49 
50  $forward_class = $this->ctrl->getNextClass($this);
51 
52  // delete all stored maildata
53  $this->umail->savePostData($ilUser->getId(), array(), '', '', '', '', '', '', '', '');
54 
55  switch($forward_class)
56  {
57  case 'ilmailformgui':
58  include_once 'Services/Mail/classes/class.ilMailFormGUI.php';
59  $this->ctrl->forwardCommand(new ilMailFormGUI());
60  break;
61 
62  case 'ilmailsearchcoursesgui':
63  include_once 'Services/Contact/classes/class.ilMailSearchCoursesGUI.php';
64 
65  $this->tabs_gui->setSubTabActive('mail_my_courses');
66 
67  $this->ctrl->setReturn($this, "showAddressbook");
68  $this->ctrl->forwardCommand(new ilMailSearchCoursesGUI());
69  break;
70 
71  case 'ilmailsearchgroupsgui':
72  include_once 'Services/Contact/classes/class.ilMailSearchGroupsGUI.php';
73 
74  $this->tabs_gui->setSubTabActive('mail_my_groups');
75 
76  $this->ctrl->setReturn($this, "showAddressbook");
77  $this->ctrl->forwardCommand(new ilMailSearchGroupsGUI());
78  break;
79 
80  case 'ilmailinglistsgui':
81  include_once 'Services/Contact/classes/class.ilMailingListsGUI.php';
82 
83  $this->tabs_gui->setSubTabActive('mail_my_mailing_lists');
84 
85  $this->ctrl->setReturn($this, "showAddressbook");
86  $this->ctrl->forwardCommand(new ilMailingListsGUI());
87  break;
88 
89  default:
90  $this->tabs_gui->setSubTabActive('mail_my_entries');
91 
92  if (!($cmd = $this->ctrl->getCmd()))
93  {
94  $cmd = "showAddressbook";
95  }
96 
97  $this->$cmd();
98  break;
99  }
100  return true;
101  }
102 
106  function checkInput($addr_id = 0)
107  {
108  // check if user login and e-mail-address are empty
109  if (!strcmp(trim($_POST["login"]), "") &&
110  !strcmp(trim($_POST["email"]), ""))
111  {
112  ilUtil::sendInfo($this->lng->txt("mail_enter_login_or_email_addr"));
113  $error = true;
114  }
115  else if ($_POST["login"] != "" &&
117  {
118  ilUtil::sendInfo($this->lng->txt("mail_enter_valid_login"));
119  $error = true;
120  }
121  else if ($_POST["email"] &&
122  !(ilUtil::is_email($_POST["email"])))
123  {
124  ilUtil::sendInfo($this->lng->txt("mail_enter_valid_email_addr"));
125  $error = true;
126  }
127 
128  if (($this->existingEntry = $this->abook->checkEntryByLogin(ilUtil::stripSlashes($_POST["login"]))) > 0 &&
129  (($this->existingEntry != $addr_id && $addr_id > 0) || !$addr_id))
130  {
131  ilUtil::sendInfo($this->lng->txt("mail_entry_exists"));
132  $error = true;
133  }
134 
135  return $error ? false : true;
136  }
137 
141  public function saveEntry()
142  {
143  global $lng;
144 
145  if ($this->checkInput($_GET["addr_id"]))
146  {
147  if ($_GET["addr_id"])
148  {
149  $this->abook->updateEntry(ilUtil::stripSlashes($_GET["addr_id"]),
150  ilUtil::stripSlashes($_POST["login"]),
151  ilUtil::stripSlashes($_POST["firstname"]),
152  ilUtil::stripSlashes($_POST["lastname"]),
153  ilUtil::stripSlashes($_POST["email"]));
154  ilUtil::sendInfo($lng->txt("mail_entry_changed"));
155  }
156  else
157  {
158  $this->abook->addEntry(ilUtil::stripSlashes($_POST["login"]),
159  ilUtil::stripSlashes($_POST["firstname"]),
160  ilUtil::stripSlashes($_POST["lastname"]),
161  ilUtil::stripSlashes($_POST["email"]));
162  ilUtil::sendInfo($lng->txt("mail_entry_added"));
163  }
164 
165  unset($_SESSION['addr_search']);
166 
167  $this->showAddressbook();
168  }
169  else
170  {
171  $this->showAddressForm();
172  }
173 
174  return true;
175  }
176 
180  function confirmDelete()
181  {
182  global $lng;
183 
184  $addr_ids = ((int)$_GET['addr_id']) ? array((int)$_GET['addr_id']) : $_POST['addr_id'];
185 
186  if (!$addr_ids)
187  {
188  ilUtil::sendInfo($this->lng->txt('mail_select_one_entry'));
189  $this->showAddressbook();
190  return true;
191  }
192 
193  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
194  $c_gui = new ilConfirmationGUI();
195 
196  // set confirm/cancel commands
197  $c_gui->setFormAction($this->ctrl->getFormAction($this, "performDelete"));
198  $c_gui->setHeaderText($this->lng->txt("mail_sure_delete_entry"));
199  $c_gui->setCancel($this->lng->txt("cancel"), "showAddressbook");
200  $c_gui->setConfirm($this->lng->txt("confirm"), "performDelete");
201 
202  // add items to delete
203  foreach($addr_ids as $addr_id)
204  {
205  $entry = $this->abook->getEntry($addr_id);
206  $c_gui->addItem("addr_id[]", $addr_id, $entry["login"] ? $entry["login"] : $entry["email"]);
207  }
208 
209  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
210  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook.html", "Services/Contact");
211  $this->tpl->setVariable('DELETE_CONFIRMATION', $c_gui->getHTML());
212 
213  $this->tpl->show();
214 
215  return true;
216  }
217 
221  function performDelete()
222  {
223  global $lng;
224 
225  if (is_array($_POST['addr_id']))
226  {
227  if ($this->abook->deleteEntries($_POST['addr_id']))
228  {
229  ilUtil::sendInfo($lng->txt("mail_deleted_entry"));
230  }
231  else
232  {
233  ilUtil::sendInfo($lng->txt("mail_delete_error"));
234  }
235  }
236  else
237  {
238  ilUtil::sendInfo($lng->txt("mail_delete_error"));
239  }
240 
241  $this->showAddressbook();
242 
243  return true;
244  }
245 
249  function cancel()
250  {
251  $this->showAddressbook();
252  }
253 
254  public function showAddressForm()
255  {
256  global $rbacsystem, $lng, $ilUser;
257 
258  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
259  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook_form.html", "Services/Contact");
260 
261  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
262  $form = new ilPropertyFormGUI();
263  $form->setTitle($_GET['addr_id'] ? $lng->txt("mail_edit_entry") : $lng->txt("mail_new_entry"));
264 
265  if ($_GET['addr_id'])
266  {
267  $this->ctrl->setParameter($this, 'addr_id', $_GET['addr_id']);
268  }
269 
270  $entry = $this->abook->getEntry($_GET['addr_id']);
271  $form->setFormAction($this->ctrl->getFormAction($this, "saveEntry"));
272 
273  $formItem = new ilTextInputGUI($this->lng->txt("username"), "login");
274  $formItem->setValue(isset($_POST['login']) ? ilUtil::prepareFormOutput($_POST['login'], true) : ilUtil::prepareFormOutput($entry['login']));
275  $form->addItem($formItem);
276 
277  $formItem = new ilTextInputGUI($this->lng->txt("firstname"), "firstname");
278  $formItem->setValue(isset($_POST['firstname']) ? ilUtil::prepareFormOutput($_POST['firstname'], true) : ilUtil::prepareFormOutput($entry['firstname']));
279  $form->addItem($formItem);
280 
281  $formItem = new ilTextInputGUI($this->lng->txt("lastname"), "lastname");
282  $formItem->setValue(isset($_POST['lastname']) ? ilUtil::prepareFormOutput($_POST['lastname'], true) : ilUtil::prepareFormOutput($entry['lastname']));
283  $form->addItem($formItem);
284 
285  $formItem = new ilTextInputGUI($this->lng->txt("email"), "email");
286  $formItem->setValue(isset($_POST['email']) ? ilUtil::prepareFormOutput($_POST['email'], true) : ilUtil::prepareFormOutput($entry['email']));
287  $form->addItem($formItem);
288 
289  $form->addCommandButton('saveEntry',$this->lng->txt('save'));
290  $form->addCommandButton('cancel',$this->lng->txt('cancel'));
291 
292  $this->tpl->setVariable('FORM', $form->getHTML());
293 
294  $this->tpl->show();
295 
296  return true;
297  }
298 
299  public function mailToUsers()
300  {
301  global $ilUser;
302 
303  if ($_GET['addr_id'] && is_array($_GET['addr_id']))
304  $addr_ids = $_GET['addr_id'];
305  else if ((int)$_GET['addr_id'])
306  $addr_ids = array((int)$_GET['addr_id']);
307  else if ($_POST['addr_id'] && is_array($_POST['addr_id']))
308  $addr_ids = $_POST['addr_id'];
309  else if ((int)$_POST['addr_id'])
310  $addr_ids = array((int)$_POST['addr_id']);
311 
312 // $addr_ids = ((int)$_GET['addr_id']) ? array((int)$_GET['addr_id']) : $_POST['addr_id'];
313 
314  if (!$addr_ids)
315  {
316  ilUtil::sendInfo($this->lng->txt('mail_select_one_entry'));
317  $this->showAddressbook();
318  return true;
319  }
320 
321  $mail_data = $this->umail->getSavedData();
322  if(!is_array($mail_data))
323  {
324  $this->umail->savePostData($ilUser->getId(), array(), '', '', '', '', '', '', '', '');
325  }
326 
327  $members = array();
328  foreach ($addr_ids as $addr_id)
329  {
330  $entry = $this->abook->getEntry($addr_id);
331 
332  if(strlen($entry['login']) && !$this->umail->doesRecipientStillExists($entry['login'], $mail_data['rcp_to'])) {
333  $members[] = $entry['login'];
334  } else if(strlen($entry['email']) && !$this->umail->doesRecipientStillExists($entry['email'], $mail_data['rcp_to'])) {
335  $members[] = $entry['email'];
336  }
337  }
338 
339  if(count($members))
340  {
341  $mail_data = $this->umail->appendSearchResult($members, 'to');
342  $this->umail->savePostData(
343  $mail_data['user_id'],
344  $mail_data['attachments'],
345  $mail_data['rcp_to'],
346  $mail_data['rcp_cc'],
347  $mail_data['rcp_bcc'],
348  $mail_data['m_type'],
349  $mail_data['m_email'],
350  $mail_data['m_subject'],
351  $mail_data['m_message'],
352  $mail_data['use_placeholders']
353  );
354  }
355 
356  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
357  }
358 
359  public function search()
360  {
361  $_SESSION['addr_search'] = $_POST['search_qry'];
362 
363  $this->showAddressbook();
364 
365  return true;
366  }
367 
371  public function showAddressbook()
372  {
373  global $rbacsystem, $lng, $ilUser, $ilCtrl, $ilias;
374 
375  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
376  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook.html", "Services/Contact");
377 
378  // check if current user may send mails
379  include_once "Services/Mail/classes/class.ilMail.php";
380  $mail = new ilMail($_SESSION["AccountId"]);
381  $mailing_allowed = $rbacsystem->checkAccess('mail_visible',$mail->getMailObjectReferenceId());
382 
383  // searchbox
384  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
385  include_once 'Services/YUI/classes/class.ilYuiUtil.php';
387  $searchform = new ilPropertyFormGUI();
388  $searchform->setFormAction($this->ctrl->getFormAction($this, "saveEntry"));
389 
390  //$dsSchema = array('response.results', 'login', 'firstname', 'lastname');
391  $dsSchema = array("resultsList" => 'response.results',
392  "fields" => array('login', 'firstname', 'lastname'));
393  $dsFormatCallback = 'formatAutoCompleteResults';
394  $dsDataLink = $ilCtrl->getLinkTarget($this, 'lookupAddressbookAsync', '', true, false);
395 
396  $inp = new ilTextInputGUI($this->lng->txt('search_for'), 'search_qry');
397  $inp->setDataSource($dsDataLink);
398  $inp->setDataSourceSchema($dsSchema);
399  $inp->setDataSourceResultFormat($dsFormatCallback);
400 
401  $searchform->addItem($inp);
402  $searchform->addCommandButton('search', $this->lng->txt("send"));
403  $this->tpl->setVariable('SEARCHFORM', $searchform->getHtml());
404 
405 
406  $this->tpl->setVariable('ACTION', $this->ctrl->getFormAction($this, "saveEntry"));
407  $this->tpl->setVariable("TXT_SEARCH_FOR",$this->lng->txt("search_for"));
408  $this->tpl->setVariable("BUTTON_SEARCH",$this->lng->txt("send"));
409 
410  if (strlen(trim($_SESSION["addr_search"])) > 0)
411  {
412  $this->tpl->setVariable("VALUE_SEARCH_FOR", ilUtil::prepareFormOutput(trim($_SESSION["addr_search"]), true));
413  }
414 
415  $tbl = new ilAddressbookTableGUI($this);
416  $tbl->setTitle($lng->txt("mail_addr_entries"));
417  $tbl->setRowTemplate("tpl.mail_addressbook_row.html", "Services/Contact");
418 
419  $tbl->setDefaultOrderField('login');
420 
421  $result = array();
422  $this->abook->setSearchQuery($_SESSION['addr_search']);
423  $entries = $this->abook->getEntries();
424 
425  $tbl->addColumn('', 'check', '10%', true);
426  $tbl->addColumn($this->lng->txt('login'), 'login', '20%');
427  $tbl->addColumn($this->lng->txt('firstname'), 'firstname', '20%');
428  $tbl->addColumn($this->lng->txt('lastname'), 'lastname', '20%');
429  $tbl->addColumn($this->lng->txt('email'), 'email', '20%');
430  $tbl->addColumn($this->lng->txt('actions'), '', '10%');
431 
432  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
433 
434  if (count($entries))
435  {
436  $tbl->enable('select_all');
437  $tbl->setSelectAllCheckbox('addr_id');
438 
439  // cache setting for iteration
440  $chat_active = $ilias->getSetting("chat_active");
441 
442  $counter = 0;
443  foreach ($entries as $entry)
444  {
445  $result[$counter]['check'] = ilUtil::formCheckbox(0, 'addr_id[]', $entry["addr_id"]);
446 
447  $this->ctrl->setParameter($this, 'addr_id', $entry['addr_id']);
448 
449  if ($entry["login"] != "")
450  {
451  if ($mailing_allowed)
452  {
453  $result[$counter]['login_linked_link'] = $this->ctrl->getLinkTarget($this, 'mailToUsers');
454  $result[$counter]['login_linked_login'] = $entry["login"];
455  }
456  else
457  $result[$counter]['login_unliked'] = $entry["login"];
458  }
459 
460  $result[$counter]['firstname'] = $entry["firstname"];
461  $result[$counter]['lastname'] = $entry["lastname"];
462 
463  if ($_GET["baseClass"] == "ilMailGUI" && $rbacsystem->checkAccess("smtp_mail", $this->umail->getMailObjectReferenceId()))
464  {
465  $result[$counter]['email_linked_email'] = $entry["email"];
466  $result[$counter]['email_linked_link'] = $this->ctrl->getLinkTarget($this, "mailToUsers");
467  }
468  else
469  $result[$counter]['email_unlinked'] = $entry["email"] ? $entry["email"] : "&nbsp;";
470 
471  $current_selection_list = new ilAdvancedSelectionListGUI();
472  $current_selection_list->setListTitle($this->lng->txt("actions"));
473  $current_selection_list->setId("act_".$counter);
474 
475  $current_selection_list->addItem($this->lng->txt("edit"), '', $this->ctrl->getLinkTarget($this, "showAddressForm"));
476 
477  if ($mailing_allowed)
478  $current_selection_list->addItem($this->lng->txt("send_mail_to"), '', $this->ctrl->getLinkTarget($this, "mailToUsers"));
479 
480  $current_selection_list->addItem($this->lng->txt("delete"), '', $this->ctrl->getLinkTarget($this, "confirmDelete"));
481 
482  if ($chat_active)
483  $current_selection_list->addItem($this->lng->txt("invite_to_chat"), '', $this->ctrl->getLinkTarget($this, "inviteToChat"));
484 
485  $this->ctrl->clearParameters($this);
486 
487  $result[$counter]['COMMAND_SELECTION_LIST'] = $current_selection_list->getHTML();
488  ++$counter;
489  }
490 
491  if ($mailing_allowed)
492  $tbl->addMultiCommand('mailToUsers', $this->lng->txt('send_mail_to'));
493 
494  $tbl->addMultiCommand('confirmDelete', $this->lng->txt('delete'));
495 
496  if ($chat_active)
497  $tbl->addMultiCommand('inviteToChat', $this->lng->txt('invite_to_chat'));
498  }
499  else
500  {
501  $tbl->disable('header');
502  $tbl->disable('footer');
503 
504  $tbl->setNoEntriesText($this->lng->txt('mail_search_no'));
505  }
506 
507  $tbl->setData($result);
508 
509  $tbl->addCommandButton('showAddressForm', $this->lng->txt('add'));
510 
511  $this->tpl->setVariable('TABLE', $tbl->getHTML());
512 
513  $this->tpl->show();
514 
515  unset($_SESSION['addr_search']);
516 
517  return true;
518  }
519 
520 
524  public function inviteToChat()
525  {
526  global $ilUser, $ilObjDataCache, $lng, $ilCtrl, $tpl;
527 
528  $addr_ids = ((int)$_GET['addr_id']) ? array((int)$_GET['addr_id']) : $_POST['addr_id'];
529 
530  // check if users has been selected
531  if (!$addr_ids)
532  {
533  ilUtil::sendInfo($lng->txt('chat_no_users_selected'), true);
534  ilUtil::redirect($ilCtrl->getLinkTarget($this, 'showAddressbook', '', false, false));
535  exit;
536  }
537 
538  // check for anonymous accounts
539 
540  // store userdata for users without ilias login
541  $no_login = array();
542 
543  foreach($addr_ids as $id)
544  {
545  $entry = $this->abook->getEntry($id);
546 
547  // if login-name available, user has a local account
548  if (!$entry['login'])
549  {
550  $no_login[] = $id;
551  }
552  }
553 
554  // error message for anonymous users
555  if (count($no_login))
556  {
557  $message .= $lng->txt('chat_users_without_login') . ':<br>';
558  $list = '';
559  foreach($no_login as $e)
560  {
561  $list .= '<li>'.$this->abook->entryToString($e).'</li>';
562  }
563  $message .= '<ul>';
564  $message .= $list;
565  $message .= '</ul>';
566  ilUtil::sendInfo($message);
567  $this->showAddressbook();
568  exit;
569  }
570 
571  // include chat classes
572  include_once 'Modules/Chat/classes/class.ilChatRoom.php';
573  include_once 'Modules/Chat/classes/class.ilObjChat.php';
574  include_once 'Modules/Chat/classes/class.ilObjChatGUI.php';
575  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
576 
577  // fetch rooms
578  $chat_rooms = ilChatRoom::getAllRooms();
579  $rooms = array();
580  foreach($chat_rooms as $room)
581  {
582  $rooms[] = $room;
583  $rooms[count($rooms)-1]["subrooms"] = ilChatRoom::getRoomsOfObject($ilObjDataCache->lookupObjId($room["ref_id"]), $ilUser->getId());
584  }
585 
586  // sort rooms by title
587  $titel = array();
588  foreach($rooms as $k => $v) {
589  $titel[$k] = strtolower($v['title']);
590  }
591  array_multisort($titel, SORT_STRING, $rooms);
592 
593  // buid room select form
594  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
595 
596  $form = new ilPropertyFormGUI();
597  $form->setTitle($lng->txt("mail_invite_users_to_chat"));
598  $psel = new ilSelectInputGUI($lng->txt("chat_select_room"), 'room_id');
599  $options = array();
600  foreach($rooms as $room)
601  {
602  $ref_id = $room['ref_id'];
603  if (ilChatBlockedUsers::_isBlocked($ilObjDataCache->lookupObjId($ref_id), $ilUser->getId()))
604  continue;
605 
606  $options[$ref_id] = $room['title'];
607  foreach($room['subrooms'] as $subroom)
608  {
609  if (ilChatRoom::_checkWriteAccess($ref_id, $subroom['room_id'], $ilUser->getId()))
610  $options[$ref_id.','.$subroom['room_id']] = '+&nbsp;'.$subroom['title'];
611  }
612  }
613  $psel->setOptions($options);
614  $form->addItem($psel);
615  $phidden = new ilHiddenInputGUI('addr_ids');
616  $phidden->setValue(join(',', $addr_ids));
617  $form->addItem($phidden);
618  $form->addCommandButton('submitInvitation',$this->lng->txt('submit'));
619  $form->addCommandButton('cancel',$this->lng->txt('cancel'));
620  $form->setFormAction($ilCtrl->getFormAction($this));
621 
622  // finish... show form
623  $tpl->setTitle($lng->txt('mail_invite_users_to_chat'));
624  $tpl->setContent($form->getHtml());
625  $tpl->show();
626  }
627 
632  public function submitInvitation()
633  {
634  global $ilObjDataCache, $ilUser,$ilCtrl, $rbacsystem, $lng, $ilias;
635 
636  if (!$_POST["addr_ids"])
637  {
638  ilUtil::sendInfo($lng->txt('chat_no_users_selected'), true);
639  $this->showAddressbook();
640  exit;
641  }
642 
643  if (!$_POST["room_id"])
644  {
645  ilUtil::sendInfo($lng->txt('chat_no_room_selected'), true);
646  $_POST['addr_id'] = explode(',', $_POST["addr_ids"]);
647  $this->showAddressbook();
648  exit;
649  }
650 
651  // get selected users (comma seperated user id list)
652  $ids = explode(',', $_POST["addr_ids"]);
653 
654  // get selected chat room from POST-String
655  // format: "ref_id , room_id"
656  $chat_ids = explode(',', $_POST['room_id']);
657  $chat_id = (int)$chat_ids[0];
658  // room_id is optional with default value 0
659  $room_id = 0;
660  if (count($chat_ids) > 0)
661  {
662  $room_id = (int)$chat_ids[1];
663  }
664 
665  // ready to check for room access
666 
667  // incldue chat room classes
668  include_once 'Modules/Chat/classes/class.ilChatRoom.php';
669  include_once 'Modules/Chat/classes/class.ilObjChat.php';
670  include_once 'Modules/Chat/classes/class.ilObjChatGUI.php';
671  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
672 
673  $obj_id = $ilObjDataCache->lookupObjId($chat_id);
674 
675  // initiate target room
676  $room = new ilChatRoom($chat_id);
677  $room->setRoomId((int)$room_id);
678 
679  // store userdata for users with no access
680  $no_access = array();
681 
682  // store userdata for users without ilias login
683  $no_login = array();
684 
685  // store usersids with access
686  $valid_users = array();
687 
688  foreach($ids as $id)
689  {
690  $entry = $this->abook->getEntry($id);
691 
692  // if login-name available, user has a local account
693  if ($entry['login'])
694  {
695  $user_id = $ilUser->getUserIdByLogin($entry['login']);
696  if (
697  !$rbacsystem->checkAccessOfUser($user_id, 'read', $chat_id)
698  || ilChatBlockedUsers::_isBlocked($obj_id, $user_id)
699  )
700  {
701  $no_access[] = $id;
702  }
703  else
704  {
705  $valid_users[] = $user_id;
706  }
707  }
708  // if no login could be found, user has no access
709  // so anonymous users cant be invitated
710  else
711  {
712  $no_login[] = $id;
713  }
714  }
715 
716  if (count($no_access) || count($no_login))
717  {
718  $message = "";
719  // error message for users without access permissions
720  if (count($no_access))
721  {
722  $message .= $lng->txt('chat_users_without_permission') . ':<br>';
723  $list = '';
724  foreach($no_access as $e)
725  {
726  $list .= '<li>'.$this->abook->entryToString($e).'</li>';
727  }
728  $message .= '<ul>';
729  $message .= $list;
730  $message .= '</ul>';
731  }
732 
733  // error message for anonymous users
734  if (count($no_login))
735  {
736  $message .= $lng->txt('chat_users_without_login') . ':<br>';
737  $list = '';
738  foreach($no_login as $e)
739  {
740  $list .= '<li>'.$this->abook->entryToString($e).'</li>';
741  }
742  $message .= '<ul>';
743  $message .= $list;
744  $message .= '</ul>';
745  }
746  ilUtil::sendInfo($message);
747  $_POST["addr_id"] = $ids;
748  $this->inviteToChat();
749  exit;
750  }
751 
752  // load chat handler for room
753  $chatObject = new ilObjChat($ref_id);
754  foreach($valid_users as $id)
755  {
756  $room->invite($id);
757  $chatObject->sendMessageForRoom($id, $room);
758  }
759  $link = '<p><a target="chatframe" href="ilias.php?baseClass=ilChatPresentationGUI&ref_id='.$chat_id.'&room_id='.$room_id.'">'.$lng->txt('goto_invitation_chat').'</a></p>';
760  ilUtil::sendInfo($lng->txt('chat_users_have_been_invited') . $userlist .$link, true);
761  $link = $ilCtrl->getLinkTarget($this, 'showAddressbook', '', false, false);
762  ilUtil::redirect($link);
763  }
764 
765  public function lookupAddressbookAsync()
766  {
767  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
768  include_once 'Services/Contact/classes/class.ilMailAddressbook.php';
769 
770  $search = "%" . $_REQUEST["query"] . "%";
771  $result = new stdClass();
772  $result->response = new stdClass();
773  $result->response->results = array();
774  if (!$search)
775  {
776  $result->response->total = 0;
778  exit;
779  }
780 
781  $mailAdrBookObj = new ilMailAddressbook;
782  $result = $mailAdrBookObj->getAddressbookAsync($search);
783 
785  exit;
786  }
787 
788  function showSubTabs()
789  {
790  $this->tabs_gui->addSubTabTarget('mail_my_entries', $this->ctrl->getLinkTarget($this));
791  $this->tabs_gui->addSubTabTarget('mail_my_mailing_lists', $this->ctrl->getLinkTargetByClass('ilmailinglistsgui'));
792  $this->tabs_gui->addSubTabTarget('mail_my_courses', $this->ctrl->getLinkTargetByClass('ilmailsearchcoursesgui'));
793  $this->tabs_gui->addSubTabTarget('mail_my_groups', $this->ctrl->getLinkTargetByClass('ilmailsearchgroupsgui'));
794  }
795 }
796 ?>