ILIAS  Release_4_4_x_branch Revision 61816
 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->activateTab('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->activateTab('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->activateTab('mail_my_mailing_lists');
84 
85  $this->ctrl->setReturn($this, "showAddressbook");
86  $this->ctrl->forwardCommand(new ilMailingListsGUI());
87  break;
88 
89  default:
90  $this->activateTab('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  {
147  global $lng, $ilSetting;
148 
149  $autoupdate = (int)$_POST['auto_update'];
150  if(!$ilSetting->get('cron_upd_adrbook', 0))
151  {
152  $autoupdate = 0;
153  }
154 
155  if($this->checkInput($_GET['addr_id']))
156  {
157  if(!isset($_POST['login']) || !strlen($_POST['login']))
158  {
159  $autoupdate = 0;
160  }
161 
162  if($_GET['addr_id'])
163  {
164  $this->abook->updateEntry(ilUtil::stripSlashes($_GET['addr_id']),
165  ilUtil::stripSlashes($_POST['login']),
166  ilUtil::stripSlashes($_POST['firstname']),
167  ilUtil::stripSlashes($_POST['lastname']),
168  ilUtil::stripSlashes($_POST['email']),
169  $autoupdate
170  );
171  ilUtil::sendInfo($lng->txt('mail_entry_changed'));
172  }
173  else
174  {
175  $this->abook->addEntry(ilUtil::stripSlashes($_POST['login']),
176  ilUtil::stripSlashes($_POST['firstname']),
177  ilUtil::stripSlashes($_POST['lastname']),
178  ilUtil::stripSlashes($_POST['email']),
179  $autoupdate
180  );
181  ilUtil::sendInfo($lng->txt('mail_entry_added'));
182  }
183 
184  unset($_SESSION['addr_search']);
185 
186  $this->showAddressbook();
187  }
188  else
189  {
190  $this->showAddressForm();
191  }
192 
193  return true;
194  }
195 
199  function confirmDelete()
200  {
201  global $lng;
202 
203  $addr_ids = ((int)$_GET['addr_id']) ? array((int)$_GET['addr_id']) : $_POST['addr_id'];
204 
205  if (!$addr_ids)
206  {
207  ilUtil::sendInfo($this->lng->txt('mail_select_one_entry'));
208  $this->showAddressbook();
209  return true;
210  }
211 
212  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
213  $c_gui = new ilConfirmationGUI();
214 
215  // set confirm/cancel commands
216  $c_gui->setFormAction($this->ctrl->getFormAction($this, "performDelete"));
217  $c_gui->setHeaderText($this->lng->txt("mail_sure_delete_entry"));
218  $c_gui->setCancel($this->lng->txt("cancel"), "showAddressbook");
219  $c_gui->setConfirm($this->lng->txt("confirm"), "performDelete");
220 
221  // add items to delete
222  foreach($addr_ids as $addr_id)
223  {
224  $entry = $this->abook->getEntry($addr_id);
225  $c_gui->addItem("addr_id[]", $addr_id, $entry["login"] ? $entry["login"] : $entry["email"]);
226  }
227 
228  $this->tpl->setTitle($this->lng->txt("mail_addressbook"));
229  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook.html", "Services/Contact");
230  $this->tpl->setVariable('DELETE_CONFIRMATION', $c_gui->getHTML());
231 
232  $this->tpl->show();
233 
234  return true;
235  }
236 
240  function performDelete()
241  {
242  global $lng;
243 
244  if (is_array($_POST['addr_id']))
245  {
246  if ($this->abook->deleteEntries($_POST['addr_id']))
247  {
248  ilUtil::sendInfo($lng->txt("mail_deleted_entry"));
249  }
250  else
251  {
252  ilUtil::sendInfo($lng->txt("mail_delete_error"));
253  }
254  }
255  else
256  {
257  ilUtil::sendInfo($lng->txt("mail_delete_error"));
258  }
259 
260  $this->showAddressbook();
261 
262  return true;
263  }
264 
268  function cancel()
269  {
270  $this->showAddressbook();
271  }
272 
273  public function showAddressForm()
274  {
279  global $lng, $ilSetting;
280 
281  $this->tpl->setTitle($this->lng->txt("mail_addressbook"));
282  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook_form.html", "Services/Contact");
283 
284  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
285  $form = new ilPropertyFormGUI();
286  $form->setTitle($_GET['addr_id'] ? $lng->txt("mail_edit_entry") : $lng->txt("mail_new_entry"));
287 
288  if ($_GET['addr_id'])
289  {
290  $this->ctrl->setParameter($this, 'addr_id', $_GET['addr_id']);
291  }
292 
293  $entry = $this->abook->getEntry($_GET['addr_id']);
294  $form->setFormAction($this->ctrl->getFormAction($this, "saveEntry"));
295 
296  $login = new ilTextInputGUI($this->lng->txt("username"), "login");
297  $login->setValue(isset($_POST['login']) ? ilUtil::prepareFormOutput($_POST['login'], true) : ilUtil::prepareFormOutput($entry['login']));
298  $form->addItem($login);
299 
300  if($ilSetting->get('cron_upd_adrbook', 0))
301  {
302  $formItem = new ilCheckboxInputGUI('', 'auto_update');
303  $formItem->setChecked(isset($_POST['auto_update']) ? ilUtil::prepareFormOutput($_POST['auto_update'], true) : ilUtil::prepareFormOutput($entry['auto_update']));
304  $formItem->setInfo($this->lng->txt('cron_update_addressbook'));
305 
306  $login->addSubItem($formItem);
307  }
308 
309  $formItem = new ilTextInputGUI($this->lng->txt("firstname"), "firstname");
310  $formItem->setValue(isset($_POST['firstname']) ? ilUtil::prepareFormOutput($_POST['firstname'], true) : ilUtil::prepareFormOutput($entry['firstname']));
311  $form->addItem($formItem);
312 
313  $formItem = new ilTextInputGUI($this->lng->txt("lastname"), "lastname");
314  $formItem->setValue(isset($_POST['lastname']) ? ilUtil::prepareFormOutput($_POST['lastname'], true) : ilUtil::prepareFormOutput($entry['lastname']));
315  $form->addItem($formItem);
316 
317  $formItem = new ilTextInputGUI($this->lng->txt("email"), "email");
318  $formItem->setValue(isset($_POST['email']) ? ilUtil::prepareFormOutput($_POST['email'], true) : ilUtil::prepareFormOutput($entry['email']));
319  $form->addItem($formItem);
320 
321  $form->addCommandButton('saveEntry',$this->lng->txt('save'));
322  $form->addCommandButton('cancel',$this->lng->txt('cancel'));
323 
324  $this->tpl->setVariable('FORM', $form->getHTML());
325 
326  $this->tpl->show();
327 
328  return true;
329  }
330 
331  public function mailToUsers()
332  {
333  global $ilUser;
334 
335  if ($_GET['addr_id'] && is_array($_GET['addr_id']))
336  $addr_ids = $_GET['addr_id'];
337  else if ((int)$_GET['addr_id'])
338  $addr_ids = array((int)$_GET['addr_id']);
339  else if ($_POST['addr_id'] && is_array($_POST['addr_id']))
340  $addr_ids = $_POST['addr_id'];
341  else if ((int)$_POST['addr_id'])
342  $addr_ids = array((int)$_POST['addr_id']);
343 
344 // $addr_ids = ((int)$_GET['addr_id']) ? array((int)$_GET['addr_id']) : $_POST['addr_id'];
345 
346  if (!$addr_ids)
347  {
348  ilUtil::sendInfo($this->lng->txt('mail_select_one_entry'));
349  $this->showAddressbook();
350  return true;
351  }
352 
353  $mail_data = $this->umail->getSavedData();
354  if(!is_array($mail_data))
355  {
356  $this->umail->savePostData($ilUser->getId(), array(), '', '', '', '', '', '', '', '');
357  }
358 
359  $members = array();
360  foreach ($addr_ids as $addr_id)
361  {
362  $entry = $this->abook->getEntry($addr_id);
363 
364  if(strlen($entry['login']) && !$this->umail->doesRecipientStillExists($entry['login'], $mail_data['rcp_to'])) {
365  $members[] = $entry['login'];
366  } else if(strlen($entry['email']) && !$this->umail->doesRecipientStillExists($entry['email'], $mail_data['rcp_to'])) {
367  $members[] = $entry['email'];
368  }
369  }
370 
371  if(count($members))
372  {
373  $mail_data = $this->umail->appendSearchResult($members, 'to');
374  $this->umail->savePostData(
375  $mail_data['user_id'],
376  $mail_data['attachments'],
377  $mail_data['rcp_to'],
378  $mail_data['rcp_cc'],
379  $mail_data['rcp_bcc'],
380  $mail_data['m_type'],
381  $mail_data['m_email'],
382  $mail_data['m_subject'],
383  $mail_data['m_message'],
384  $mail_data['use_placeholders']
385  );
386  }
387 
388  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
389  }
390 
391  public function search()
392  {
393  $_SESSION['addr_search'] = $_POST['search_qry'];
394 
395  $this->showAddressbook();
396 
397  return true;
398  }
399 
403  public function showAddressbook()
404  {
411  global $rbacsystem, $lng, $ilCtrl, $ilSetting;
412 
413  $this->tpl->setTitle($this->lng->txt("mail_addressbook"));
414  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook.html", "Services/Contact");
415 
416  // check if current user may send mails
417  include_once "Services/Mail/classes/class.ilMail.php";
418  $mail = new ilMail($_SESSION["AccountId"]);
419  $mailing_allowed = $rbacsystem->checkAccess('internal_mail',$mail->getMailObjectReferenceId());
420 
421  // searchbox
422  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
423  $searchform = new ilPropertyFormGUI();
424  $searchform->setFormAction($this->ctrl->getFormAction($this, "saveEntry"));
425 
426  $dsDataLink = $ilCtrl->getLinkTarget($this, 'lookupAddressbookAsync', '', true, false);
427  $inp = new ilTextInputGUI($this->lng->txt('search_for'), 'search_qry');
428  $inp->setDataSource($dsDataLink);
429 
430  $searchform->addItem($inp);
431  $searchform->addCommandButton('search', $this->lng->txt("send"));
432  $this->tpl->setVariable('SEARCHFORM', $searchform->getHtml());
433 
434 
435  $this->tpl->setVariable('ACTION', $this->ctrl->getFormAction($this, "saveEntry"));
436  $this->tpl->setVariable("TXT_SEARCH_FOR",$this->lng->txt("search_for"));
437  $this->tpl->setVariable("BUTTON_SEARCH",$this->lng->txt("send"));
438 
439  if (strlen(trim($_SESSION["addr_search"])) > 0)
440  {
441  $this->tpl->setVariable("VALUE_SEARCH_FOR", ilUtil::prepareFormOutput(trim($_SESSION["addr_search"]), true));
442  }
443 
444  $tbl = new ilAddressbookTableGUI($this);
445  $tbl->setTitle($lng->txt("mail_addr_entries"));
446  $tbl->setRowTemplate("tpl.mail_addressbook_row.html", "Services/Contact");
447 
448  $tbl->setDefaultOrderField('login');
449 
450  $width = '20%';
451  if($ilSetting->get('cron_upd_adrbook', 0))
452  {
453  $width = '16.6%';
454  }
455 
456  $result = array();
457  $this->abook->setSearchQuery($_SESSION['addr_search']);
458  $entries = $this->abook->getEntries();
459  $tbl->addColumn('', 'check', '1px', true);
460  $tbl->addColumn($this->lng->txt('login'), 'login', $width);
461  $tbl->addColumn($this->lng->txt('firstname'), 'firstname', $width);
462  $tbl->addColumn($this->lng->txt('lastname'), 'lastname', $width);
463  $tbl->addColumn($this->lng->txt('email'), 'email', $width);
464  if($ilSetting->get('cron_upd_adrbook', 0))
465  {
466  $tbl->addColumn($this->lng->txt('auto_update'), '', $width);
467  }
468  $tbl->addColumn($this->lng->txt('actions'), '', '20%');
469 
470  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
471 
472  if (count($entries))
473  {
474  $tbl->enable('select_all');
475  $tbl->setSelectAllCheckbox('addr_id');
476 
477  $chatSettings = new ilSetting('chatroom');
478  $chat_active = $chatSettings->get("chat_enabled", false);
479 
480  $counter = 0;
481 
482  foreach ($entries as $entry)
483  {
484  $result[$counter]['check'] = ilUtil::formCheckbox(0, 'addr_id[]', $entry["addr_id"]);
485 
486  $this->ctrl->setParameter($this, 'addr_id', $entry['addr_id']);
487 
488  $result[$counter]['login'] = '';
489  if($entry["login"] != "")
490  {
491  if($mailing_allowed)
492  {
493  $result[$counter]['login_linked_link'] = $this->ctrl->getLinkTarget($this, 'mailToUsers');
494  $result[$counter]['login'] = $result[$counter]['login_linked_login'] = $entry["login"];
495  }
496  else
497  {
498  $result[$counter]['login'] = $result[$counter]['login_unliked'] = $entry["login"];
499  }
500  }
501 
502  $result[$counter]['firstname'] = $entry["firstname"];
503  $result[$counter]['lastname'] = $entry["lastname"];
504 
505  if($_GET["baseClass"] == "ilMailGUI" && $rbacsystem->checkAccess("smtp_mail", $this->umail->getMailObjectReferenceId()))
506  {
507  $result[$counter]['email'] = $result[$counter]['email_linked_email'] = $entry["email"];
508  $result[$counter]['email_linked_link'] = $this->ctrl->getLinkTarget($this, "mailToUsers");
509  }
510  else
511  {
512  $result[$counter]['email'] = $result[$counter]['email_unlinked'] = $entry["email"];
513  }
514 
515  $current_selection_list = new ilAdvancedSelectionListGUI();
516  $current_selection_list->setListTitle($this->lng->txt("actions"));
517  $current_selection_list->setId("act_".$counter);
518 
519  $current_selection_list->addItem($this->lng->txt("edit"), '', $this->ctrl->getLinkTarget($this, "showAddressForm"));
520 
521  if ($mailing_allowed)
522  $current_selection_list->addItem($this->lng->txt("send_mail_to"), '', $this->ctrl->getLinkTarget($this, "mailToUsers"));
523 
524  $current_selection_list->addItem($this->lng->txt("delete"), '', $this->ctrl->getLinkTarget($this, "confirmDelete"));
525 
526  if ($chat_active)
527  $current_selection_list->addItem($this->lng->txt("invite_to_chat"), '', $this->ctrl->getLinkTarget($this, "inviteToChat"));
528 
529  $this->ctrl->clearParameters($this);
530 
531  if($ilSetting->get('cron_upd_adrbook', 0))
532  {
533  $result[$counter]['auto_update'] = $entry['auto_update'] ? $lng->txt('yes') : $lng->txt('no');
534  }
535 
536  $result[$counter]['COMMAND_SELECTION_LIST'] = $current_selection_list->getHTML();
537  ++$counter;
538  }
539 
540  if ($mailing_allowed)
541  $tbl->addMultiCommand('mailToUsers', $this->lng->txt('send_mail_to'));
542 
543  $tbl->addMultiCommand('confirmDelete', $this->lng->txt('delete'));
544 
545  if ($chat_active)
546  $tbl->addMultiCommand('inviteToChat', $this->lng->txt('invite_to_chat'));
547  }
548  else
549  {
550  $tbl->disable('header');
551  $tbl->disable('footer');
552 
553  $tbl->setNoEntriesText($this->lng->txt('mail_search_no'));
554  }
555 
556  $tbl->setData($result);
557 
558  $tbl->addCommandButton('showAddressForm', $this->lng->txt('add'));
559 
560  $this->tpl->setVariable('TABLE', $tbl->getHTML());
561 
562  $this->tpl->show();
563 
564  unset($_SESSION['addr_search']);
565 
566  return true;
567  }
568 
569 
573  public function inviteToChat()
574  {
581  global $ilUser, $lng, $ilCtrl, $tpl;
582 
583  $lng->loadLanguageModule('chatroom');
584 
585  $addr_ids = ((int)$_GET['addr_id']) ? array((int)$_GET['addr_id']) : $_POST['addr_id'];
586 
587  if(!$addr_ids)
588  {
589  ilUtil::sendFailure($lng->txt('select_one'), true);
590  $ilCtrl->redirect($this, 'showAddressbook');
591  }
592 
593  $no_login = array();
594 
595  foreach($addr_ids as $id)
596  {
597  $entry = $this->abook->getEntry($id);
598  if(!$entry['login'])
599  {
600  $no_login[] = $id;
601  }
602  }
603 
604  if(count($no_login))
605  {
606  $message = $lng->txt('chat_users_without_login') . ':<br>';
607  $list = '';
608 
609  foreach($no_login as $e)
610  {
611  $list .= '<li>' . $this->abook->entryToString($e) . '</li>';
612  }
613 
614  $message .= '<ul>';
615  $message .= $list;
616  $message .= '</ul>';
617 
618  ilUtil::sendFailure($message, true);
619  $ilCtrl->redirect($this, 'showAddressbook');
620  }
621 
622  include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
623 
624  $ilChatroom = new ilChatroom();
625  $chat_rooms = $ilChatroom->getAllRooms($ilUser->getId());
626  $subrooms = array();
627 
628  foreach($chat_rooms as $room_id => $title)
629  {
630  $subrooms[] = $ilChatroom->getPrivateSubRooms($room_id, $ilUser->getId());
631  }
632 
633  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
634 
635  $form = new ilPropertyFormGUI();
636  $form->setTitle($lng->txt('mail_invite_users_to_chat'));
637 
638  $psel = new ilSelectInputGUI($lng->txt('chat_select_room'), 'room_id');
639  $options = array();
640 
641  foreach($chat_rooms as $room_id => $room)
642  {
643  $ref_id = $room_id;
644 
645  if($ilChatroom->isUserBanned($ilUser->getId()))
646  {
647  continue;
648  }
649 
650  $options[$ref_id] = $room;
651 
652  foreach($subrooms as $subroom)
653  {
654  foreach($subroom as $sub_id => $parent_id)
655  {
656  if($parent_id == $ref_id)
657  {
658  $title = ilChatroom::lookupPrivateRoomTitle($sub_id);
659  $options[$ref_id . ',' . $sub_id] = '+&nbsp;' . $title;
660  }
661  }
662  }
663  }
664 
665  $psel->setOptions($options);
666  $form->addItem($psel);
667  $phidden = new ilHiddenInputGUI('addr_ids');
668  $phidden->setValue(implode(',', $addr_ids));
669  $form->addItem($phidden);
670  $form->addCommandButton('submitInvitation', $this->lng->txt('submit'));
671  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
672  $form->setFormAction($ilCtrl->getFormAction($this));
673 
674  $tpl->setTitle($lng->txt('mail_invite_users_to_chat'));
675  $tpl->setContent($form->getHtml());
676  $tpl->show();
677  }
678 
683  public function submitInvitation()
684  {
690  global $ilUser, $ilCtrl, $lng;
691 
692  if(!$_POST['addr_ids'])
693  {
694  ilUtil::sendFailure($lng->txt('select_one'), true);
695  $ilCtrl->redirect($this, 'showAddressbook');
696  }
697 
698  if(!$_POST['room_id'])
699  {
700  ilUtil::sendFailure($lng->txt('select_one'));
701  $_POST['addr_id'] = explode(',', $_POST['addr_ids']);
702  $this->inviteToChat();
703  return;
704  }
705 
706  // get selected users (comma seperated user id list)
707  $ids = explode(',', $_POST['addr_ids']);
708 
709  // get selected chatroom from POST-String, format: "room_id , scope"
710  $room_ids = explode(',', $_POST['room_id']);
711  $room_id = (int)$room_ids[0];
712  $scope = 0;
713 
714  if(count($room_ids) > 0)
715  {
716  $scope = (int)$room_ids[1];
717  }
718 
719  include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
720 
721  $room = ilChatroom::byRoomId((int)$room_id, true);
722  $no_access = array();
723  $no_login = array();
724  $valid_users = array();
725  $valid_user_to_login_map = array();
726 
727  foreach($ids as $id)
728  {
729  $entry = $this->abook->getEntry($id);
730 
731  if($entry['login'])
732  {
733  $user_id = $ilUser->getUserIdByLogin($entry['login']);
734  if(!$user_id)
735  {
736  $no_login[] = $id;
737  continue;
738  }
739  $ref_id = $room->getRefIdByRoomId($room_id);
740 
741  if
742  (
743  !ilChatroom::checkPermissionsOfUser($user_id, 'read', $ref_id) ||
744  $room->isUserBanned($user_id)
745  )
746  {
747  $no_access[] = $id;
748  }
749  else
750  {
751  $valid_users[] = $user_id;
752  $valid_user_to_login_map[$user_id] = $entry['login'];
753  }
754  }
755  else
756  {
757  $no_login[] = $id;
758  }
759  }
760 
761  if(count($no_access) || count($no_login))
762  {
763  $message = '';
764 
765  if(count($no_access))
766  {
767  $message .= $lng->txt('chat_users_without_permission') . ':<br>';
768  $list = '';
769 
770  foreach($no_access as $e)
771  {
772  $list .= '<li>' . $this->abook->entryToString($e) . '</li>';
773  }
774 
775  $message .= '<ul>';
776  $message .= $list;
777  $message .= '</ul>';
778  }
779 
780  if(count($no_login))
781  {
782  $message .= $lng->txt('chat_users_without_login') . ':<br>';
783  $list = '';
784 
785  foreach($no_login as $e)
786  {
787  $list .= '<li>' . $this->abook->entryToString($e) . '</li>';
788  }
789 
790  $message .= '<ul>';
791  $message .= $list;
792  $message .= '</ul>';
793  }
794 
795  ilUtil::sendFailure($message);
796  $_POST['addr_id'] = $ids;
797  $this->inviteToChat();
798  return;
799  }
800 
801  $ref_id = $room->getRefIdByRoomId($room_id);
802 
803  $url = '';
804  include_once 'Services/Link/classes/class.ilLink.php';
805  if($scope)
806  {
807  $url = ilLink::_getStaticLink($ref_id, 'chta', true, '_'.$scope);
808  }
809  else
810  {
811  $url = ilLink::_getStaticLink($ref_id, 'chta');
812  }
813  $link = '<p><a target="chatframe" href="' . $url . '" title="' . $lng->txt('goto_invitation_chat') . '">' .$lng->txt('goto_invitation_chat') . '</a></p>';
814 
815  $userlist = array();
816  foreach($valid_users as $id)
817  {
818  $room->inviteUserToPrivateRoom($id, $scope);
819  $room->sendInvitationNotification(
820  null, $ilUser->getId(), $id, (int)$scope, $url
821  );
822  $userlist[] = '<li>'.$valid_user_to_login_map[$id].'</li>';
823  }
824 
825  if($userlist)
826  {
827  ilUtil::sendSuccess($lng->txt('chat_users_have_been_invited') . '<ul>'.implode('', $userlist).'</ul>' . $link, true);
828  }
829  $ilCtrl->redirect($this, 'showAddressbook');
830  }
831 
832  public function lookupAddressbookAsync()
833  {
834  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
835  include_once 'Services/Contact/classes/class.ilMailAddressbook.php';
836 
837  $search = "%" . $_REQUEST["term"] . "%";
838  $result = array();
839 
840  if( !$search )
841  {
843  exit;
844  }
845 
846  $mailAdrBookObj = new ilMailAddressbook;
847  $result = $mailAdrBookObj->getAddressbookAsync($search);
848 
850  exit;
851  }
852 
853  function showSubTabs()
854  {
855  global $ilHelp;
856 
857  if($this->tabs_gui->hasTabs())
858  {
859  $this->tabs_gui->addSubTab('mail_my_entries', $this->lng->txt('mail_my_entries'), $this->ctrl->getLinkTarget($this));
860  $this->tabs_gui->addSubTab('mail_my_mailing_lists', $this->lng->txt('mail_my_mailing_lists'), $this->ctrl->getLinkTargetByClass('ilmailinglistsgui'));
861  $this->tabs_gui->addSubTab('mail_my_courses', $this->lng->txt('mail_my_courses'), $this->ctrl->getLinkTargetByClass('ilmailsearchcoursesgui'));
862  $this->tabs_gui->addSubTab('mail_my_groups', $this->lng->txt('mail_my_groups'), $this->ctrl->getLinkTargetByClass('ilmailsearchgroupsgui'));
863  $this->has_sub_tabs = true;
864  }
865  else
866  {
867  $ilHelp->setScreenIdComponent("contacts");
868 
869  $this->tabs_gui->addTab('mail_my_entries', $this->lng->txt('mail_my_entries'), $this->ctrl->getLinkTarget($this));
870  $this->tabs_gui->addTab('mail_my_mailing_lists', $this->lng->txt('mail_my_mailing_lists'), $this->ctrl->getLinkTargetByClass('ilmailinglistsgui'));
871  $this->tabs_gui->addTab('mail_my_courses', $this->lng->txt('mail_my_courses'), $this->ctrl->getLinkTargetByClass('ilmailsearchcoursesgui'));
872  $this->tabs_gui->addTab('mail_my_groups', $this->lng->txt('mail_my_groups'), $this->ctrl->getLinkTargetByClass('ilmailsearchgroupsgui'));
873  }
874  }
875 
876  function activateTab($a_id)
877  {
878  if($this->has_sub_tabs)
879  {
880  $this->tabs_gui->activateSubTab($a_id);
881  }
882  else
883  {
884  $this->tabs_gui->activateTab($a_id);
885  }
886  }
887 }
888 ?>