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";
37 $this->tabs_gui =& $ilTabs;
39 $this->ctrl->saveParameter($this,
"mobj_id");
50 $forward_class = $this->ctrl->getNextClass($this);
53 $this->umail->savePostData($ilUser->getId(), array(),
'',
'',
'',
'',
'',
'',
'',
'');
55 switch($forward_class)
58 include_once
'Services/Mail/classes/class.ilMailFormGUI.php';
62 case 'ilmailsearchcoursesgui':
63 include_once
'Services/Contact/classes/class.ilMailSearchCoursesGUI.php';
67 $this->ctrl->setReturn($this,
"showAddressbook");
71 case 'ilmailsearchgroupsgui':
72 include_once
'Services/Contact/classes/class.ilMailSearchGroupsGUI.php';
76 $this->ctrl->setReturn($this,
"showAddressbook");
80 case 'ilmailinglistsgui':
81 include_once
'Services/Contact/classes/class.ilMailingListsGUI.php';
85 $this->ctrl->setReturn($this,
"showAddressbook");
92 if (!(
$cmd = $this->ctrl->getCmd()))
94 $cmd =
"showAddressbook";
109 if (!strcmp(trim(
$_POST[
"login"]),
"") &&
110 !strcmp(trim(
$_POST[
"email"]),
""))
115 else if (
$_POST[
"login"] !=
"" &&
121 else if (
$_POST[
"email"] &&
129 (($this->existingEntry != $addr_id && $addr_id > 0) || !$addr_id))
135 return $error ?
false :
true;
141 public function saveEntry()
149 $autoupdate = (int)
$_POST[
'auto_update'];
150 if(!$ilSetting->get(
'cron_upd_adrbook', 0))
186 $this->showAddressbook();
190 $this->showAddressForm();
203 $addr_ids = ((int)
$_GET[
'addr_id']) ? array((
int)
$_GET[
'addr_id']) :
$_POST[
'addr_id'];
208 $this->showAddressbook();
212 include_once(
"Services/Utilities/classes/class.ilConfirmationGUI.php");
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");
222 foreach($addr_ids as $addr_id)
224 $entry = $this->abook->getEntry($addr_id);
225 $c_gui->addItem(
"addr_id[]", $addr_id, $entry[
"login"] ? $entry[
"login"] : $entry[
"email"]);
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());
244 if (is_array(
$_POST[
'addr_id']))
246 if ($this->abook->deleteEntries(
$_POST[
'addr_id']))
260 $this->showAddressbook();
270 $this->showAddressbook();
273 public function showAddressForm()
281 $this->tpl->setTitle($this->lng->txt(
"mail_addressbook"));
282 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.mail_addressbook_form.html",
"Services/Contact");
284 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
286 $form->setTitle(
$_GET[
'addr_id'] ? $lng->txt(
"mail_edit_entry") : $lng->txt(
"mail_new_entry"));
288 if (
$_GET[
'addr_id'])
290 $this->ctrl->setParameter($this,
'addr_id',
$_GET[
'addr_id']);
293 $entry = $this->abook->getEntry(
$_GET[
'addr_id']);
294 $form->setFormAction($this->ctrl->getFormAction($this,
"saveEntry"));
296 $login =
new ilTextInputGUI($this->lng->txt(
"username"),
"login");
298 $form->addItem($login);
300 if($ilSetting->get(
'cron_upd_adrbook', 0))
304 $formItem->setInfo($this->lng->txt(
'cron_update_addressbook'));
306 $login->addSubItem($formItem);
309 $formItem =
new ilTextInputGUI($this->lng->txt(
"firstname"),
"firstname");
311 $form->addItem($formItem);
313 $formItem =
new ilTextInputGUI($this->lng->txt(
"lastname"),
"lastname");
315 $form->addItem($formItem);
317 $formItem =
new ilTextInputGUI($this->lng->txt(
"email"),
"email");
319 $form->addItem($formItem);
321 $form->addCommandButton(
'saveEntry',$this->lng->txt(
'save'));
322 $form->addCommandButton(
'cancel',$this->lng->txt(
'cancel'));
324 $this->tpl->setVariable(
'FORM', $form->getHTML());
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']);
349 $this->showAddressbook();
353 $mail_data = $this->umail->getSavedData();
354 if(!is_array($mail_data))
356 $this->umail->savePostData($ilUser->getId(), array(),
'',
'',
'',
'',
'',
'',
'',
'');
360 foreach ($addr_ids as $addr_id)
362 $entry = $this->abook->getEntry($addr_id);
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'];
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']
395 $this->showAddressbook();
403 public function showAddressbook()
413 $this->tpl->setTitle($this->lng->txt(
"mail_addressbook"));
414 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.mail_addressbook.html",
"Services/Contact");
417 include_once
"Services/Mail/classes/class.ilMail.php";
419 $mailing_allowed = $rbacsystem->checkAccess(
'internal_mail',$mail->getMailObjectReferenceId());
422 include_once(
'./Services/Form/classes/class.ilPropertyFormGUI.php');
424 $searchform->setFormAction($this->ctrl->getFormAction($this,
"saveEntry"));
426 $dsDataLink = $ilCtrl->getLinkTarget($this,
'lookupAddressbookAsync',
'',
true,
false);
427 $inp =
new ilTextInputGUI($this->lng->txt(
'search_for'),
'search_qry');
430 $searchform->addItem($inp);
431 $searchform->addCommandButton(
'search', $this->lng->txt(
"send"));
432 $this->tpl->setVariable(
'SEARCHFORM', $searchform->getHtml());
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"));
439 if (strlen(trim(
$_SESSION[
"addr_search"])) > 0)
445 $tbl->setTitle($lng->txt(
"mail_addr_entries"));
446 $tbl->setRowTemplate(
"tpl.mail_addressbook_row.html",
"Services/Contact");
448 $tbl->setDefaultOrderField(
'login');
451 if($ilSetting->get(
'cron_upd_adrbook', 0))
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))
466 $tbl->addColumn($this->lng->txt(
'auto_update'),
'', $width);
468 $tbl->addColumn($this->lng->txt(
'actions'),
'',
'20%');
470 include_once(
"./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
474 $tbl->enable(
'select_all');
475 $tbl->setSelectAllCheckbox(
'addr_id');
477 $chatSettings =
new ilSetting(
'chatroom');
478 $chat_active = $chatSettings->get(
"chat_enabled",
false);
482 foreach ($entries as $entry)
486 $this->ctrl->setParameter($this,
'addr_id', $entry[
'addr_id']);
488 $result[$counter][
'login'] =
'';
489 if($entry[
"login"] !=
"")
493 $result[$counter][
'login_linked_link'] = $this->ctrl->getLinkTarget($this,
'mailToUsers');
494 $result[$counter][
'login'] =
$result[$counter][
'login_linked_login'] = $entry[
"login"];
498 $result[$counter][
'login'] =
$result[$counter][
'login_unliked'] = $entry[
"login"];
502 $result[$counter][
'firstname'] = $entry[
"firstname"];
503 $result[$counter][
'lastname'] = $entry[
"lastname"];
505 if(
$_GET[
"baseClass"] ==
"ilMailGUI" && $rbacsystem->checkAccess(
"smtp_mail", $this->umail->getMailObjectReferenceId()))
507 $result[$counter][
'email'] =
$result[$counter][
'email_linked_email'] = $entry[
"email"];
508 $result[$counter][
'email_linked_link'] = $this->ctrl->getLinkTarget($this,
"mailToUsers");
512 $result[$counter][
'email'] =
$result[$counter][
'email_unlinked'] = $entry[
"email"];
516 $current_selection_list->setListTitle($this->lng->txt(
"actions"));
517 $current_selection_list->setId(
"act_".$counter);
519 $current_selection_list->addItem($this->lng->txt(
"edit"),
'', $this->ctrl->getLinkTarget($this,
"showAddressForm"));
521 if ($mailing_allowed)
522 $current_selection_list->addItem($this->lng->txt(
"send_mail_to"),
'', $this->ctrl->getLinkTarget($this,
"mailToUsers"));
524 $current_selection_list->addItem($this->lng->txt(
"delete"),
'', $this->ctrl->getLinkTarget($this,
"confirmDelete"));
527 $current_selection_list->addItem($this->lng->txt(
"invite_to_chat"),
'', $this->ctrl->getLinkTarget($this,
"inviteToChat"));
529 $this->ctrl->clearParameters($this);
531 if($ilSetting->get(
'cron_upd_adrbook', 0))
533 $result[$counter][
'auto_update'] = $entry[
'auto_update'] ? $lng->txt(
'yes') : $lng->txt(
'no');
536 $result[$counter][
'COMMAND_SELECTION_LIST'] = $current_selection_list->getHTML();
540 if ($mailing_allowed)
541 $tbl->addMultiCommand(
'mailToUsers', $this->lng->txt(
'send_mail_to'));
543 $tbl->addMultiCommand(
'confirmDelete', $this->lng->txt(
'delete'));
546 $tbl->addMultiCommand(
'inviteToChat', $this->lng->txt(
'invite_to_chat'));
550 $tbl->disable(
'header');
551 $tbl->disable(
'footer');
553 $tbl->setNoEntriesText($this->lng->txt(
'mail_search_no'));
558 $tbl->addCommandButton(
'showAddressForm', $this->lng->txt(
'add'));
560 $this->tpl->setVariable(
'TABLE', $tbl->getHTML());
573 public function inviteToChat()
583 $lng->loadLanguageModule(
'chatroom');
585 $addr_ids = ((int)
$_GET[
'addr_id']) ? array((
int)
$_GET[
'addr_id']) :
$_POST[
'addr_id'];
590 $ilCtrl->redirect($this,
'showAddressbook');
595 foreach($addr_ids as $id)
597 $entry = $this->abook->getEntry($id);
606 $message = $lng->txt(
'chat_users_without_login') .
':<br>';
609 foreach($no_login as $e)
611 $list .=
'<li>' . $this->abook->entryToString($e) .
'</li>';
619 $ilCtrl->redirect($this,
'showAddressbook');
622 include_once
'Modules/Chatroom/classes/class.ilChatroom.php';
625 $chat_rooms = $ilChatroom->getAllRooms($ilUser->getId());
628 foreach($chat_rooms as $room_id => $title)
630 $subrooms[] = $ilChatroom->getPrivateSubRooms($room_id, $ilUser->getId());
633 include_once
'Services/Form/classes/class.ilPropertyFormGUI.php';
636 $form->setTitle($lng->txt(
'mail_invite_users_to_chat'));
641 foreach($chat_rooms as $room_id => $room)
645 if($ilChatroom->isUserBanned($ilUser->getId()))
652 foreach($subrooms as $subroom)
654 foreach($subroom as $sub_id => $parent_id)
659 $options[
$ref_id .
',' . $sub_id] =
'+ ' . $title;
666 $form->addItem($psel);
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));
674 $tpl->setTitle($lng->txt(
'mail_invite_users_to_chat'));
675 $tpl->setContent($form->getHtml());
683 public function submitInvitation()
695 $ilCtrl->redirect($this,
'showAddressbook');
701 $_POST[
'addr_id'] = explode(
',', $_POST[
'addr_ids']);
702 $this->inviteToChat();
707 $ids = explode(
',',
$_POST[
'addr_ids']);
710 $room_ids = explode(
',',
$_POST[
'room_id']);
711 $room_id = (int)$room_ids[0];
714 if(count($room_ids) > 0)
716 $scope = (int)$room_ids[1];
719 include_once
'Modules/Chatroom/classes/class.ilChatroom.php';
722 $no_access = array();
724 $valid_users = array();
725 $valid_user_to_login_map = array();
729 $entry = $this->abook->getEntry($id);
733 $user_id = $ilUser->getUserIdByLogin($entry[
'login']);
739 $ref_id = $room->getRefIdByRoomId($room_id);
744 $room->isUserBanned($user_id)
751 $valid_users[] = $user_id;
752 $valid_user_to_login_map[$user_id] = $entry[
'login'];
761 if(count($no_access) || count($no_login))
765 if(count($no_access))
767 $message .= $lng->txt(
'chat_users_without_permission') .
':<br>';
770 foreach($no_access as $e)
772 $list .=
'<li>' . $this->abook->entryToString($e) .
'</li>';
782 $message .= $lng->txt(
'chat_users_without_login') .
':<br>';
785 foreach($no_login as $e)
787 $list .=
'<li>' . $this->abook->entryToString($e) .
'</li>';
797 $this->inviteToChat();
801 $ref_id = $room->getRefIdByRoomId($room_id);
804 include_once
'Services/Link/classes/class.ilLink.php';
813 $link =
'<p><a target="chatframe" href="' . $url .
'" title="' . $lng->txt(
'goto_invitation_chat') .
'">' .$lng->txt(
'goto_invitation_chat') .
'</a></p>';
816 foreach($valid_users as $id)
818 $room->inviteUserToPrivateRoom($id, $scope);
819 $room->sendInvitationNotification(
820 null, $ilUser->getId(), $id, (int)$scope, $url
822 $userlist[] =
'<li>'.$valid_user_to_login_map[$id].
'</li>';
827 ilUtil::sendSuccess($lng->txt(
'chat_users_have_been_invited') .
'<ul>'.implode(
'', $userlist).
'</ul>' . $link,
true);
829 $ilCtrl->redirect($this,
'showAddressbook');
834 include_once
'Services/JSON/classes/class.ilJsonUtil.php';
835 include_once
'Services/Contact/classes/class.ilMailAddressbook.php';
847 $result = $mailAdrBookObj->getAddressbookAsync($search);
857 if($this->tabs_gui->hasTabs())
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;
867 $ilHelp->setScreenIdComponent(
"contacts");
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'));
878 if($this->has_sub_tabs)
880 $this->tabs_gui->activateSubTab($a_id);
884 $this->tabs_gui->activateTab($a_id);