ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilContactGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Mail/classes/class.ilFormatMail.php';
5require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystem.php';
6
16{
19
20 private $tpl = null;
21 public $ctrl = null;
22 private $lng = null;
23 private $tabs_gui = null;
24
28 private $umail;
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->lng->loadLanguageModule('buddysystem');
43 }
44
45 public function executeCommand()
46 {
51 global $ilUser, $ilErr;
52
53 $this->showSubTabs();
54
55 $forward_class = $this->ctrl->getNextClass($this);
56
57 // delete all stored maildata
58 $this->umail->savePostData($ilUser->getId(), array(), '', '', '', '', '', '', '', '');
59
60 switch($forward_class)
61 {
62 case 'ilmailformgui':
63 include_once 'Services/Mail/classes/class.ilMailFormGUI.php';
64 $this->ctrl->forwardCommand(new ilMailFormGUI());
65 break;
66
67 case 'ilmailsearchcoursesgui':
68 include_once 'Services/Contact/classes/class.ilMailSearchCoursesGUI.php';
69
70 $this->activateTab('mail_my_courses');
71
72 $this->ctrl->setReturn($this, "showContacts");
73 $this->ctrl->forwardCommand(new ilMailSearchCoursesGUI());
74 break;
75
76 case 'ilmailsearchgroupsgui':
77 include_once 'Services/Contact/classes/class.ilMailSearchGroupsGUI.php';
78
79 $this->activateTab('mail_my_groups');
80
81 $this->ctrl->setReturn($this, "showContacts");
82 $this->ctrl->forwardCommand(new ilMailSearchGroupsGUI());
83 break;
84
85 case 'ilmailinglistsgui':
86 if(!ilBuddySystem::getInstance()->isEnabled())
87 {
88 $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
89 }
90
91 include_once 'Services/Contact/classes/class.ilMailingListsGUI.php';
92
93 $this->activateTab('mail_my_mailing_lists');
94
95 $this->ctrl->setReturn($this, "showContacts");
96 $this->ctrl->forwardCommand(new ilMailingListsGUI());
97 break;
98
99 case 'ilusersgallerygui':
100 if(!ilBuddySystem::getInstance()->isEnabled())
101 {
102 $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
103 }
104
105 $this->tabs_gui->activateSubTab('buddy_view_gallery');
106 $this->activateTab('my_contacts');
107 require_once 'Services/User/classes/class.ilUsersGalleryUsers.php';
108 require_once 'Services/User/classes/class.ilUsersGalleryGUI.php';
109 $this->ctrl->forwardCommand(new ilUsersGalleryGUI(new ilUsersGalleryUsers()));
110 $this->tpl->show();
111 break;
112
113 case 'ilpublicuserprofilegui':
114 require_once 'Services/User/classes/class.ilPublicUserProfileGUI.php';
115 $profile_gui = new ilPublicUserProfileGUI(ilUtil::stripSlashes($_GET['user']));
116 $profile_gui->setBackUrl($this->ctrl->getLinkTarget($this, 'showContacts'));
117 $this->ctrl->forwardCommand($profile_gui);
118 $this->tpl->show();
119 break;
120
121 default:
122 $this->activateTab('mail_my_entries');
123
124 if (!($cmd = $this->ctrl->getCmd()))
125 {
126 if(ilBuddySystem::getInstance()->isEnabled())
127 {
128 $cmd = 'showContacts';
129 }
130 else
131 {
132 $this->ctrl->redirectByClass('ilmailsearchcoursesgui');
133 }
134 }
135
136 $this->$cmd();
137 break;
138 }
139 return true;
140 }
141
145 private function showSubTabs()
146 {
151 global $ilHelp, $ilToolbar;
152
153 if($this->tabs_gui->hasTabs())
154 {
155 if(ilBuddySystem::getInstance()->isEnabled())
156 {
157 $this->tabs_gui->addSubTab('my_contacts', $this->lng->txt('my_contacts'), $this->ctrl->getLinkTarget($this));
158
159 if(in_array(strtolower($this->ctrl->getCmdClass()), array_map('strtolower', array('ilUsersGalleryGUI', get_class($this)))))
160 {
161 require_once 'Services/Form/classes/class.ilSelectInputGUI.php';
162 $view_selection = new ilSelectInputGUI('', 'contacts_view');
163 $view_selection->setOptions(array(
164 self::CONTACTS_VIEW_TABLE => $this->lng->txt('buddy_view_table'),
165 self::CONTACTS_VIEW_GALLERY => $this->lng->txt('buddy_view_gallery')
166 ));
167 $view_selection->setValue(
168 strtolower($this->ctrl->getCmdClass()) == 'ilusersgallerygui' ? self::CONTACTS_VIEW_GALLERY : self::CONTACTS_VIEW_TABLE
169 );
170 $ilToolbar->addInputItem($view_selection);
171
172 require_once 'Services/UIComponent/Button/classes/class.ilSubmitButton.php';
173 $contact_view_btn = ilSubmitButton::getInstance();
174 $contact_view_btn->setCaption('submit');
175 $contact_view_btn->setCommand('changeContactsView');
176 $ilToolbar->addButtonInstance($contact_view_btn);
177 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, 'changeContactsView'));
178 }
179
180 $this->tabs_gui->addSubTab('mail_my_mailing_lists', $this->lng->txt('mail_my_mailing_lists'), $this->ctrl->getLinkTargetByClass('ilmailinglistsgui'));
181 }
182
183 $this->tabs_gui->addSubTab('mail_my_courses', $this->lng->txt('mail_my_courses'), $this->ctrl->getLinkTargetByClass('ilmailsearchcoursesgui'));
184 $this->tabs_gui->addSubTab('mail_my_groups', $this->lng->txt('mail_my_groups'), $this->ctrl->getLinkTargetByClass('ilmailsearchgroupsgui'));
185 $this->has_sub_tabs = true;
186 }
187 else
188 {
189 $ilHelp->setScreenIdComponent("contacts");
190
191 if(ilBuddySystem::getInstance()->isEnabled())
192 {
193 $this->tabs_gui->addTab('my_contacts', $this->lng->txt('my_contacts'), $this->ctrl->getLinkTarget($this));
194
195 if(in_array(strtolower($this->ctrl->getCmdClass()), array_map('strtolower', array('ilUsersGalleryGUI', get_class($this)))))
196 {
197 $this->tabs_gui->addSubTab('buddy_view_table', $this->lng->txt('buddy_view_table'), $this->ctrl->getLinkTarget($this));
198 $this->tabs_gui->addSubTab('buddy_view_gallery', $this->lng->txt('buddy_view_gallery'), $this->ctrl->getLinkTargetByClass('ilUsersGalleryGUI'));
199 }
200
201 $this->tabs_gui->addTab('mail_my_mailing_lists', $this->lng->txt('mail_my_mailing_lists'), $this->ctrl->getLinkTargetByClass('ilmailinglistsgui'));
202 }
203
204 $this->tabs_gui->addTab('mail_my_courses', $this->lng->txt('mail_my_courses'), $this->ctrl->getLinkTargetByClass('ilmailsearchcoursesgui'));
205 $this->tabs_gui->addTab('mail_my_groups', $this->lng->txt('mail_my_groups'), $this->ctrl->getLinkTargetByClass('ilmailsearchgroupsgui'));
206 }
207 }
208
209 function activateTab($a_id)
210 {
211 if($this->has_sub_tabs)
212 {
213 $this->tabs_gui->activateSubTab($a_id);
214 }
215 else
216 {
217 $this->tabs_gui->activateTab($a_id);
218 }
219 }
220
224 protected function changeContactsView()
225 {
229 global $ilErr;
230
231 if(!ilBuddySystem::getInstance()->isEnabled())
232 {
233 $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
234 }
235
236 if(isset($_POST['contacts_view']))
237 {
238 switch($_POST['contacts_view'])
239 {
241 $this->ctrl->redirectByClass('ilUsersGalleryGUI');
242 break;
243
245 $this->ctrl->redirect($this);
246 break;
247 }
248 }
249
250 $this->ctrl->redirect($this);
251 }
252
256 protected function applyContactsTableFilter()
257 {
261 global $ilErr;
262
263 if(!ilBuddySystem::getInstance()->isEnabled())
264 {
265 $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
266 }
267
268 require_once 'Services/Contact/BuddySystem/classes/tables/class.ilBuddySystemRelationsTableGUI.php';
269 $table = new ilBuddySystemRelationsTableGUI($this, 'showContacts');
270
271 $table->resetOffset();
272 $table->writeFilterToSession();
273
274 $this->showContacts();
275 }
276
280 protected function resetContactsTableFilter()
281 {
285 global $ilErr;
286
287 if(!ilBuddySystem::getInstance()->isEnabled())
288 {
289 $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
290 }
291
292 require_once 'Services/Contact/BuddySystem/classes/tables/class.ilBuddySystemRelationsTableGUI.php';
293 $table = new ilBuddySystemRelationsTableGUI($this, 'showContacts');
294
295 $table->resetOffset();
296 $table->resetFilter();
297
298 $this->showContacts();
299 }
300
304 protected function showContacts()
305 {
309 global $ilErr;
310
311 if(!ilBuddySystem::getInstance()->isEnabled())
312 {
313 $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
314 }
315
316 $this->tabs_gui->activateSubTab('buddy_view_table');
317 $this->activateTab('my_contacts');
318
319 require_once 'Services/Contact/BuddySystem/classes/tables/class.ilBuddySystemRelationsTableGUI.php';
320 $table = new ilBuddySystemRelationsTableGUI($this, 'showContacts');
321 $table->populate();
322 $this->tpl->setContent($table->getHTML());
323 $this->tpl->show();
324 }
325
329 protected function mailToUsers()
330 {
336 global $rbacsystem, $ilErr, $ilUser;
337
338 if(!$rbacsystem->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId()))
339 {
340 $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
341 }
342
343 if(!isset($_POST['usr_id']) || !is_array($_POST['usr_id']) || 0 == count($_POST['usr_id']))
344 {
345 ilUtil::sendInfo($this->lng->txt('mail_select_one_entry'));
346 $this->showContacts();
347 return true;
348 }
349
350 $usr_ids = (array)$_POST['usr_id'];
351
352 $mail_data = $this->umail->getSavedData();
353 if(!is_array($mail_data))
354 {
355 $this->umail->savePostData($ilUser->getId(), array(), '', '', '', '', '', '', '', '');
356 }
357
358 $logins = array();
359 foreach($usr_ids as $usr_id)
360 {
361 $logins[] = ilObjUser::_lookupLogin($usr_id);
362 }
363 $logins = array_filter($logins);
364
365 if(count($logins) > 0)
366 {
367 $mail_data = $this->umail->appendSearchResult($logins, 'to');
368 $this->umail->savePostData(
369 $mail_data['user_id'],
370 $mail_data['attachments'],
371 $mail_data['rcp_to'],
372 $mail_data['rcp_cc'],
373 $mail_data['rcp_bcc'],
374 $mail_data['m_type'],
375 $mail_data['m_email'],
376 $mail_data['m_subject'],
377 $mail_data['m_message'],
378 $mail_data['use_placeholders'],
379 $mail_data['tpl_ctx_id'],
380 $mail_data['tpl_ctx_params']
381 );
382 }
383
384 ilUtil::redirect('ilias.php?baseClass=ilMailGUI&type=search_res');
385 }
386
391 public function submitInvitation()
392 {
398 global $ilUser, $ilCtrl, $lng;
399
400 if(!isset($_POST['usr_id']) || !strlen($_POST['usr_id']))
401 {
402 ilUtil::sendInfo($lng->txt('select_one'), true);
403 $ilCtrl->redirect($this);
404 }
405
406 if(!$_POST['room_id'])
407 {
408 ilUtil::sendInfo($lng->txt('select_one'));
409 $_POST['usr_id'] = explode(',', $_POST['usr_id']);
410 $this->inviteToChat();
411 return;
412 }
413
414 // get selected users (comma seperated user id list)
415 $usr_ids = explode(',', $_POST['usr_id']);
416
417 // get selected chatroom from POST-String, format: "room_id , scope"
418 $room_ids = explode(',', $_POST['room_id']);
419 $room_id = (int)$room_ids[0];
420 $scope = 0;
421
422 if(count($room_ids) > 0)
423 {
424 $scope = (int)$room_ids[1];
425 }
426
427 include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
428
429 $room = ilChatroom::byRoomId((int)$room_id, true);
430 $no_access = array();
431 $no_login = array();
432 $valid_users = array();
433 $valid_user_to_login_map = array();
434
435 foreach($usr_ids as $usr_id)
436 {
437 $login = ilObjUser::_lookupLogin($usr_id);
438 if(!strlen($login))
439 {
440 $no_login[$usr_id] = $usr_id;
441 continue;
442 }
443
444 $ref_id = $room->getRefIdByRoomId($room_id);
445
446 if(
447 !ilChatroom::checkPermissionsOfUser($usr_id, 'read', $ref_id) ||
448 $room->isUserBanned($usr_id)
449 )
450 {
451 $no_access[$usr_id] = $login;
452 }
453 else
454 {
455 $valid_users[$usr_id] = $usr_id;
456 $valid_user_to_login_map[$usr_id] = $login;
457 }
458 }
459
460 if(count($no_access) || count($no_login))
461 {
462 $message = '';
463
464 if(count($no_access) > 0)
465 {
466 $message .= $lng->txt('chat_users_without_permission') . ':<br>';
467 $list = '';
468
469 foreach($no_access as $usr_id => $login)
470 {
471 $list .= '<li>' . $login . '</li>';
472 }
473
474 $message .= '<ul>';
475 $message .= $list;
476 $message .= '</ul>';
477 }
478
479 if(count($no_login))
480 {
481 $message .= $lng->txt('chat_users_without_login') . ':<br>';
482 $list = '';
483
484 foreach($no_login as $usr_id)
485 {
486 $list .= '<li>' . $usr_id . '</li>';
487 }
488
489 $message .= '<ul>';
490 $message .= $list;
491 $message .= '</ul>';
492 }
493
494 ilUtil::sendFailure($message);
495 $_POST['usr_id'] = $usr_ids;
496 $this->inviteToChat();
497 return;
498 }
499
500 $ref_id = $room->getRefIdByRoomId($room_id);
501
502 require_once 'Services/Link/classes/class.ilLink.php';
503 if($scope)
504 {
505 $url = ilLink::_getStaticLink($ref_id, 'chtr', true, '_'.$scope);
506 }
507 else
508 {
510 }
511 $link = '<p><a target="chatframe" href="' . $url . '" title="' . $lng->txt('goto_invitation_chat') . '">' .$lng->txt('goto_invitation_chat') . '</a></p>';
512
513 $userlist = array();
514 foreach($valid_users as $id)
515 {
516 $room->inviteUserToPrivateRoom($id, $scope);
517 $room->sendInvitationNotification(
518 null, $ilUser->getId(), $id, (int)$scope, $url
519 );
520 $userlist[] = '<li>'.$valid_user_to_login_map[$id].'</li>';
521 }
522
523 if($userlist)
524 {
525 ilUtil::sendSuccess($lng->txt('chat_users_have_been_invited') . '<ul>'.implode('', $userlist).'</ul>' . $link, true);
526 }
527
528 $ilCtrl->redirect($this);
529 }
530
534 protected function inviteToChat()
535 {
542 global $ilUser, $lng, $ilCtrl, $tpl;
543
544 $this->tabs_gui->activateSubTab('buddy_view_table');
545 $this->activateTab('my_contacts');
546
547 $lng->loadLanguageModule('chatroom');
548
549 if(!isset($_POST['usr_id']) || !is_array($_POST['usr_id']) || 0 == count($_POST['usr_id']))
550 {
551 ilUtil::sendInfo($lng->txt('select_one'), true);
552 $ilCtrl->redirect($this);
553 }
554 $usr_ids = $_POST['usr_id'];
555
556 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
557
558 $ilChatroom = new ilChatroom();
559 $chat_rooms = $ilChatroom->getAllRooms($ilUser->getId());
560 $subrooms = array();
561
562 foreach($chat_rooms as $room_id => $title)
563 {
564 $subrooms[] = $ilChatroom->getPrivateSubRooms($room_id, $ilUser->getId());
565 }
566
567 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
568
569 $form = new ilPropertyFormGUI();
570 $form->setTitle($lng->txt('mail_invite_users_to_chat'));
571
572 $psel = new ilSelectInputGUI($lng->txt('chat_select_room'), 'room_id');
573 $options = array();
574
575 foreach($chat_rooms as $room_id => $room)
576 {
577 $ref_id = $room_id;
578
579 if($ilChatroom->isUserBanned($ilUser->getId()))
580 {
581 continue;
582 }
583
584 $options[$ref_id] = $room;
585
586 foreach($subrooms as $subroom)
587 {
588 foreach($subroom as $sub_id => $parent_id)
589 {
590 if($parent_id == $ref_id)
591 {
592 $title = ilChatroom::lookupPrivateRoomTitle($sub_id);
593 $options[$ref_id . ',' . $sub_id] = '+&nbsp;' . $title;
594 }
595 }
596 }
597 }
598
599 $psel->setOptions($options);
600 $form->addItem($psel);
601 $phidden = new ilHiddenInputGUI('usr_id');
602 $phidden->setValue(implode(',', $usr_ids));
603 $form->addItem($phidden);
604 $form->addCommandButton('submitInvitation', $this->lng->txt('submit'));
605 $form->addCommandButton('showContacts', $this->lng->txt('cancel'));
606 $form->setFormAction($ilCtrl->getFormAction($this, 'showContacts'));
607
608 $tpl->setTitle($lng->txt('mail_invite_users_to_chat'));
609 $tpl->setContent($form->getHtml());
610 $tpl->show();
611 }
612}
$_GET["client_id"]
Class ilChatroom.
static lookupPrivateRoomTitle($proom_id)
static checkPermissionsOfUser($usr_id, $permissions, $ref_id)
Checks user permissions in question for a given user id in relation to a given ref_id.
static byRoomId($room_id, $initObject=false)
Returns ilChatroom by given $room_id.
Class UserMail this class handles user mails.
This class represents a hidden form property in a property form.
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable.
static _lookupLogin($a_user_id)
lookup login
This class represents a property form user interface.
GUI class for public user profile presentation.
This class represents a selection list property in a property form.
static getInstance()
Factory.
@ilCtrl_Calls ilUsersGalleryGUI: ilPublicUserProfileGUI @ilCtrl_isCalledBy ilUsersGalleryGUI: ilObjCo...
Class ilUsersGalleryUsers.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static redirect($a_script)
http redirect to other script
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$_POST['username']
Definition: cron.php:12
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
$ref_id
Definition: sahs_server.php:39
$url
Definition: shib_logout.php:72
if(!is_array($argv)) $options
global $ilUser
Definition: imgupload.php:15