ILIAS  eassessment Revision 61809
 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 
440  $counter = 0;
441  foreach ($entries as $entry)
442  {
443  $result[$counter]['check'] = ilUtil::formCheckbox(0, 'addr_id[]', $entry["addr_id"]);
444 
445  $this->ctrl->setParameter($this, 'addr_id', $entry['addr_id']);
446 
447  if ($entry["login"] != "")
448  {
449  if ($mailing_allowed)
450  {
451  $result[$counter]['login_linked_link'] = $this->ctrl->getLinkTarget($this, 'mailToUsers');
452  $result[$counter]['login_linked_login'] = $entry["login"];
453  }
454  else
455  $result[$counter]['login_unliked'] = $entry["login"];
456  }
457 
458  $result[$counter]['firstname'] = $entry["firstname"];
459  $result[$counter]['lastname'] = $entry["lastname"];
460 
461  if ($_GET["baseClass"] == "ilMailGUI" && $rbacsystem->checkAccess("smtp_mail", $this->umail->getMailObjectReferenceId()))
462  {
463  $result[$counter]['email_linked_email'] = $entry["email"];
464  $result[$counter]['email_linked_link'] = $this->ctrl->getLinkTarget($this, "mailToUsers");
465  }
466  else
467  $result[$counter]['email_unlinked'] = $entry["email"] ? $entry["email"] : "&nbsp;";
468 
469  $current_selection_list = new ilAdvancedSelectionListGUI();
470  $current_selection_list->setListTitle($this->lng->txt("actions"));
471  $current_selection_list->setId("act_".$counter);
472 
473  $current_selection_list->addItem($this->lng->txt("edit"), '', $this->ctrl->getLinkTarget($this, "showAddressForm"));
474 
475  if ($mailing_allowed)
476  $current_selection_list->addItem($this->lng->txt("send_mail_to"), '', $this->ctrl->getLinkTarget($this, "mailToUsers"));
477 
478  $current_selection_list->addItem($this->lng->txt("delete"), '', $this->ctrl->getLinkTarget($this, "confirmDelete"));
479 
480  $this->ctrl->clearParameters($this);
481 
482  $result[$counter]['COMMAND_SELECTION_LIST'] = $current_selection_list->getHTML();
483  ++$counter;
484  }
485 
486  if ($mailing_allowed)
487  $tbl->addMultiCommand('mailToUsers', $this->lng->txt('send_mail_to'));
488 
489  $tbl->addMultiCommand('confirmDelete', $this->lng->txt('delete'));
490 
491  }
492  else
493  {
494  $tbl->disable('header');
495  $tbl->disable('footer');
496 
497  $tbl->setNoEntriesText($this->lng->txt('mail_search_no'));
498  }
499 
500  $tbl->setData($result);
501 
502  $tbl->addCommandButton('showAddressForm', $this->lng->txt('add'));
503 
504  $this->tpl->setVariable('TABLE', $tbl->getHTML());
505 
506  $this->tpl->show();
507 
508  unset($_SESSION['addr_search']);
509 
510  return true;
511  }
512 
513 
517  public function inviteToChat()
518  {
519  global $ilUser, $ilObjDataCache, $lng, $ilCtrl, $tpl;
520 
521  $addr_ids = ((int)$_GET['addr_id']) ? array((int)$_GET['addr_id']) : $_POST['addr_id'];
522 
523  // check if users has been selected
524  if (!$addr_ids)
525  {
526  ilUtil::sendInfo($lng->txt('chat_no_users_selected'), true);
527  ilUtil::redirect($ilCtrl->getLinkTarget($this, 'showAddressbook', '', false, false));
528  exit;
529  }
530 
531  // check for anonymous accounts
532 
533  // store userdata for users without ilias login
534  $no_login = array();
535 
536  foreach($addr_ids as $id)
537  {
538  $entry = $this->abook->getEntry($id);
539 
540  // if login-name available, user has a local account
541  if (!$entry['login'])
542  {
543  $no_login[] = $id;
544  }
545  }
546 
547  // error message for anonymous users
548  if (count($no_login))
549  {
550  $message .= $lng->txt('chat_users_without_login') . ':<br>';
551  $list = '';
552  foreach($no_login as $e)
553  {
554  $list .= '<li>'.$this->abook->entryToString($e).'</li>';
555  }
556  $message .= '<ul>';
557  $message .= $list;
558  $message .= '</ul>';
559  ilUtil::sendInfo($message);
560  $this->showAddressbook();
561  exit;
562  }
563 
564  // include chat classes
565  include_once 'Modules/Chat/classes/class.ilChatRoom.php';
566  include_once 'Modules/Chat/classes/class.ilObjChat.php';
567  include_once 'Modules/Chat/classes/class.ilObjChatGUI.php';
568  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
569 
570  // fetch rooms
571  $chat_rooms = ilChatRoom::getAllRooms();
572  $rooms = array();
573  foreach($chat_rooms as $room)
574  {
575  $rooms[] = $room;
576  $rooms[count($rooms)-1]["subrooms"] = ilChatRoom::getRoomsOfObject($ilObjDataCache->lookupObjId($room["ref_id"]), $ilUser->getId());
577  }
578 
579  // sort rooms by title
580  $titel = array();
581  foreach($rooms as $k => $v) {
582  $titel[$k] = strtolower($v['title']);
583  }
584  array_multisort($titel, SORT_STRING, $rooms);
585 
586  // buid room select form
587  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
588 
589  $form = new ilPropertyFormGUI();
590  $form->setTitle($lng->txt("mail_invite_users_to_chat"));
591  $psel = new ilSelectInputGUI($lng->txt("chat_select_room"), 'room_id');
592  $options = array();
593  foreach($rooms as $room)
594  {
595  $ref_id = $room['ref_id'];
596  if (ilChatBlockedUsers::_isBlocked($ilObjDataCache->lookupObjId($ref_id), $ilUser->getId()))
597  continue;
598 
599  $options[$ref_id] = $room['title'];
600  foreach($room['subrooms'] as $subroom)
601  {
602  if (ilChatRoom::_checkWriteAccess($ref_id, $subroom['room_id'], $ilUser->getId()))
603  $options[$ref_id.','.$subroom['room_id']] = '+&nbsp;'.$subroom['title'];
604  }
605  }
606  $psel->setOptions($options);
607  $form->addItem($psel);
608  $phidden = new ilHiddenInputGUI('addr_ids');
609  $phidden->setValue(join(',', $addr_ids));
610  $form->addItem($phidden);
611  $form->addCommandButton('submitInvitation',$this->lng->txt('submit'));
612  $form->addCommandButton('cancel',$this->lng->txt('cancel'));
613  $form->setFormAction($ilCtrl->getFormAction($this));
614 
615  // finish... show form
616  $tpl->setTitle($lng->txt('mail_invite_users_to_chat'));
617  $tpl->setContent($form->getHtml());
618  $tpl->show();
619  }
620 
625  public function submitInvitation()
626  {
627  global $ilObjDataCache, $ilUser,$ilCtrl, $rbacsystem, $lng, $ilias;
628 
629  if (!$_POST["addr_ids"])
630  {
631  ilUtil::sendInfo($lng->txt('chat_no_users_selected'), true);
632  $this->showAddressbook();
633  exit;
634  }
635 
636  if (!$_POST["room_id"])
637  {
638  ilUtil::sendInfo($lng->txt('chat_no_room_selected'), true);
639  $_POST['addr_id'] = explode(',', $_POST["addr_ids"]);
640  $this->showAddressbook();
641  exit;
642  }
643 
644  // get selected users (comma seperated user id list)
645  $ids = explode(',', $_POST["addr_ids"]);
646 
647  // get selected chat room from POST-String
648  // format: "ref_id , room_id"
649  $chat_ids = explode(',', $_POST['room_id']);
650  $chat_id = (int)$chat_ids[0];
651  // room_id is optional with default value 0
652  $room_id = 0;
653  if (count($chat_ids) > 0)
654  {
655  $room_id = (int)$chat_ids[1];
656  }
657 
658  // ready to check for room access
659 
660  // incldue chat room classes
661  include_once 'Modules/Chat/classes/class.ilChatRoom.php';
662  include_once 'Modules/Chat/classes/class.ilObjChat.php';
663  include_once 'Modules/Chat/classes/class.ilObjChatGUI.php';
664  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
665 
666  $obj_id = $ilObjDataCache->lookupObjId($chat_id);
667 
668  // initiate target room
669  $room = new ilChatRoom($chat_id);
670  $room->setRoomId((int)$room_id);
671 
672  // store userdata for users with no access
673  $no_access = array();
674 
675  // store userdata for users without ilias login
676  $no_login = array();
677 
678  // store usersids with access
679  $valid_users = array();
680 
681  foreach($ids as $id)
682  {
683  $entry = $this->abook->getEntry($id);
684 
685  // if login-name available, user has a local account
686  if ($entry['login'])
687  {
688  $user_id = $ilUser->getUserIdByLogin($entry['login']);
689  if (
690  !$rbacsystem->checkAccessOfUser($user_id, 'read', $chat_id)
691  || ilChatBlockedUsers::_isBlocked($obj_id, $user_id)
692  )
693  {
694  $no_access[] = $id;
695  }
696  else
697  {
698  $valid_users[] = $user_id;
699  }
700  }
701  // if no login could be found, user has no access
702  // so anonymous users cant be invitated
703  else
704  {
705  $no_login[] = $id;
706  }
707  }
708 
709  if (count($no_access) || count($no_login))
710  {
711  $message = "";
712  // error message for users without access permissions
713  if (count($no_access))
714  {
715  $message .= $lng->txt('chat_users_without_permission') . ':<br>';
716  $list = '';
717  foreach($no_access as $e)
718  {
719  $list .= '<li>'.$this->abook->entryToString($e).'</li>';
720  }
721  $message .= '<ul>';
722  $message .= $list;
723  $message .= '</ul>';
724  }
725 
726  // error message for anonymous users
727  if (count($no_login))
728  {
729  $message .= $lng->txt('chat_users_without_login') . ':<br>';
730  $list = '';
731  foreach($no_login as $e)
732  {
733  $list .= '<li>'.$this->abook->entryToString($e).'</li>';
734  }
735  $message .= '<ul>';
736  $message .= $list;
737  $message .= '</ul>';
738  }
739  ilUtil::sendInfo($message);
740  $_POST["addr_id"] = $ids;
741  $this->inviteToChat();
742  exit;
743  }
744 
745  // load chat handler for room
746  $chatObject = new ilObjChat($ref_id);
747  foreach($valid_users as $id)
748  {
749  $room->invite($id);
750  $chatObject->sendMessageForRoom($id, $room);
751  }
752  $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>';
753  ilUtil::sendInfo($lng->txt('chat_users_have_been_invited') . $userlist .$link, true);
754  $link = $ilCtrl->getLinkTarget($this, 'showAddressbook', '', false, false);
755  ilUtil::redirect($link);
756  }
757 
758  public function lookupAddressbookAsync()
759  {
760  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
761  include_once 'Services/Contact/classes/class.ilMailAddressbook.php';
762 
763  $search = "%" . $_REQUEST["query"] . "%";
764  $result = new stdClass();
765  $result->response = new stdClass();
766  $result->response->results = array();
767  if (!$search)
768  {
769  $result->response->total = 0;
770  echo ilJsonUtil::encode($result);
771  exit;
772  }
773 
774  $mailAdrBookObj = new ilMailAddressbook;
775  $result = $mailAdrBookObj->getAddressbookAsync($search);
776 
777  echo ilJsonUtil::encode($result);
778  exit;
779  }
780 
781  function showSubTabs()
782  {
783  $this->tabs_gui->addSubTabTarget('mail_my_entries', $this->ctrl->getLinkTarget($this));
784  $this->tabs_gui->addSubTabTarget('mail_my_mailing_lists', $this->ctrl->getLinkTargetByClass('ilmailinglistsgui'));
785  $this->tabs_gui->addSubTabTarget('mail_my_courses', $this->ctrl->getLinkTargetByClass('ilmailsearchcoursesgui'));
786  $this->tabs_gui->addSubTabTarget('mail_my_groups', $this->ctrl->getLinkTargetByClass('ilmailsearchgroupsgui'));
787  }
788 }
789 ?>