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