ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
23 protected $tpl;
24
28 protected $ctrl;
29
33 protected $lng;
34
38 protected $tabs_gui;
39
43 protected $help;
44
48 protected $toolbar;
49
53 protected $umail;
54
58 protected $user;
59
63 protected $error;
64
68 protected $rbacsystem;
69
73 protected $has_sub_tabs = false;
74
78 public function __construct()
79 {
80 global $DIC;
81
82 $this->tpl = $DIC['tpl'];
83 $this->ctrl = $DIC['ilCtrl'];
84 $this->lng = $DIC['lng'];
85 $this->tabs_gui = $DIC['ilTabs'];
86 $this->help = $DIC['ilHelp'];
87 $this->toolbar = $DIC['ilToolbar'];
88 $this->user = $DIC['ilUser'];
89 $this->error = $DIC['ilErr'];
90 $this->rbacsystem = $DIC['rbacsystem'];
91
92 $this->ctrl->saveParameter($this, "mobj_id");
93
94 $this->umail = new ilFormatMail($this->user->getId());
95 $this->lng->loadLanguageModule('buddysystem');
96 }
97
98 public function executeCommand()
99 {
100 $this->showSubTabs();
101
102 $forward_class = $this->ctrl->getNextClass($this);
103
104 // delete all stored maildata
105 $this->umail->savePostData($this->user->getId(), array(), '', '', '', '', '', '', '', '');
106
107 switch($forward_class)
108 {
109 case 'ilmailformgui':
110 include_once 'Services/Mail/classes/class.ilMailFormGUI.php';
111 $this->ctrl->forwardCommand(new ilMailFormGUI());
112 break;
113
114 case 'ilmailsearchcoursesgui':
115 include_once 'Services/Contact/classes/class.ilMailSearchCoursesGUI.php';
116
117 $this->activateTab('mail_my_courses');
118
119 $this->ctrl->setReturn($this, "showContacts");
120 $this->ctrl->forwardCommand(new ilMailSearchCoursesGUI());
121 break;
122
123 case 'ilmailsearchgroupsgui':
124 include_once 'Services/Contact/classes/class.ilMailSearchGroupsGUI.php';
125
126 $this->activateTab('mail_my_groups');
127
128 $this->ctrl->setReturn($this, "showContacts");
129 $this->ctrl->forwardCommand(new ilMailSearchGroupsGUI());
130 break;
131
132 case 'ilmailinglistsgui':
133 if(!ilBuddySystem::getInstance()->isEnabled())
134 {
135 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
136 }
137
138 include_once 'Services/Contact/classes/class.ilMailingListsGUI.php';
139
140 $this->activateTab('mail_my_mailing_lists');
141
142 $this->ctrl->setReturn($this, "showContacts");
143 $this->ctrl->forwardCommand(new ilMailingListsGUI());
144 break;
145
146 case 'ilusersgallerygui':
147 if(!ilBuddySystem::getInstance()->isEnabled())
148 {
149 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
150 }
151
152 $this->tabs_gui->activateSubTab('buddy_view_gallery');
153 $this->activateTab('my_contacts');
154 require_once 'Services/User/classes/class.ilUsersGalleryUsers.php';
155 require_once 'Services/User/classes/class.ilUsersGalleryGUI.php';
156 $this->ctrl->forwardCommand(new ilUsersGalleryGUI(new ilUsersGalleryUsers()));
157 $this->tpl->show();
158 break;
159
160 case 'ilpublicuserprofilegui':
161 require_once 'Services/User/classes/class.ilPublicUserProfileGUI.php';
162 $profile_gui = new ilPublicUserProfileGUI(ilUtil::stripSlashes($_GET['user']));
163 $profile_gui->setBackUrl($this->ctrl->getLinkTarget($this, 'showContacts'));
164 $this->ctrl->forwardCommand($profile_gui);
165 $this->tpl->show();
166 break;
167
168 default:
169 $this->activateTab('mail_my_entries');
170
171 if (!($cmd = $this->ctrl->getCmd()))
172 {
173 if(ilBuddySystem::getInstance()->isEnabled())
174 {
175 $cmd = 'showContacts';
176 }
177 else
178 {
179 $this->ctrl->redirectByClass('ilmailsearchcoursesgui');
180 }
181 }
182
183 $this->$cmd();
184 break;
185 }
186 return true;
187 }
188
192 private function showSubTabs()
193 {
194 if($this->tabs_gui->hasTabs())
195 {
196 if(ilBuddySystem::getInstance()->isEnabled())
197 {
198 $this->tabs_gui->addSubTab('my_contacts', $this->lng->txt('my_contacts'), $this->ctrl->getLinkTarget($this));
199
200 if(in_array(strtolower($this->ctrl->getCmdClass()), array_map('strtolower', array('ilUsersGalleryGUI', get_class($this)))))
201 {
202 require_once 'Services/Form/classes/class.ilSelectInputGUI.php';
203 $view_selection = new ilSelectInputGUI('', 'contacts_view');
204 $view_selection->setOptions(array(
205 self::CONTACTS_VIEW_TABLE => $this->lng->txt('buddy_view_table'),
206 self::CONTACTS_VIEW_GALLERY => $this->lng->txt('buddy_view_gallery')
207 ));
208 $view_selection->setValue(
209 strtolower($this->ctrl->getCmdClass()) == 'ilusersgallerygui' ? self::CONTACTS_VIEW_GALLERY : self::CONTACTS_VIEW_TABLE
210 );
211 $this->toolbar->addInputItem($view_selection);
212
213 require_once 'Services/UIComponent/Button/classes/class.ilSubmitButton.php';
214 $contact_view_btn = ilSubmitButton::getInstance();
215 $contact_view_btn->setCaption('submit');
216 $contact_view_btn->setCommand('changeContactsView');
217 $this->toolbar->addButtonInstance($contact_view_btn);
218 $this->toolbar->setFormAction($this->ctrl->getFormAction($this, 'changeContactsView'));
219 }
220
221 $this->tabs_gui->addSubTab('mail_my_mailing_lists', $this->lng->txt('mail_my_mailing_lists'), $this->ctrl->getLinkTargetByClass('ilmailinglistsgui'));
222 }
223
224 $this->tabs_gui->addSubTab('mail_my_courses', $this->lng->txt('mail_my_courses'), $this->ctrl->getLinkTargetByClass('ilmailsearchcoursesgui'));
225 $this->tabs_gui->addSubTab('mail_my_groups', $this->lng->txt('mail_my_groups'), $this->ctrl->getLinkTargetByClass('ilmailsearchgroupsgui'));
226 $this->has_sub_tabs = true;
227 }
228 else
229 {
230 $this->help->setScreenIdComponent('contacts');
231
232 if(ilBuddySystem::getInstance()->isEnabled())
233 {
234 $this->tabs_gui->addTab('my_contacts', $this->lng->txt('my_contacts'), $this->ctrl->getLinkTarget($this));
235
236 if(in_array(strtolower($this->ctrl->getCmdClass()), array_map('strtolower', array('ilUsersGalleryGUI', get_class($this)))))
237 {
238 $this->tabs_gui->addSubTab('buddy_view_table', $this->lng->txt('buddy_view_table'), $this->ctrl->getLinkTarget($this));
239 $this->tabs_gui->addSubTab('buddy_view_gallery', $this->lng->txt('buddy_view_gallery'), $this->ctrl->getLinkTargetByClass('ilUsersGalleryGUI'));
240 }
241
242 $this->tabs_gui->addTab('mail_my_mailing_lists', $this->lng->txt('mail_my_mailing_lists'), $this->ctrl->getLinkTargetByClass('ilmailinglistsgui'));
243 }
244
245 $this->tabs_gui->addTab('mail_my_courses', $this->lng->txt('mail_my_courses'), $this->ctrl->getLinkTargetByClass('ilmailsearchcoursesgui'));
246 $this->tabs_gui->addTab('mail_my_groups', $this->lng->txt('mail_my_groups'), $this->ctrl->getLinkTargetByClass('ilmailsearchgroupsgui'));
247 }
248 }
249
253 protected function activateTab($a_id)
254 {
255 if($this->has_sub_tabs)
256 {
257 $this->tabs_gui->activateSubTab($a_id);
258 }
259 else
260 {
261 $this->tabs_gui->activateTab($a_id);
262 }
263 }
264
268 protected function changeContactsView()
269 {
270 if(!ilBuddySystem::getInstance()->isEnabled())
271 {
272 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
273 }
274
275 if(isset($_POST['contacts_view']))
276 {
277 switch($_POST['contacts_view'])
278 {
280 $this->ctrl->redirectByClass('ilUsersGalleryGUI');
281 break;
282
284 $this->ctrl->redirect($this);
285 break;
286 }
287 }
288
289 $this->ctrl->redirect($this);
290 }
291
295 protected function applyContactsTableFilter()
296 {
297 if(!ilBuddySystem::getInstance()->isEnabled())
298 {
299 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
300 }
301
302 require_once 'Services/Contact/BuddySystem/classes/tables/class.ilBuddySystemRelationsTableGUI.php';
303 $table = new ilBuddySystemRelationsTableGUI($this, 'showContacts');
304
305 $table->resetOffset();
306 $table->writeFilterToSession();
307
308 $this->showContacts();
309 }
310
314 protected function resetContactsTableFilter()
315 {
316 if(!ilBuddySystem::getInstance()->isEnabled())
317 {
318 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
319 }
320
321 require_once 'Services/Contact/BuddySystem/classes/tables/class.ilBuddySystemRelationsTableGUI.php';
322 $table = new ilBuddySystemRelationsTableGUI($this, 'showContacts');
323
324 $table->resetOffset();
325 $table->resetFilter();
326
327 $this->showContacts();
328 }
329
333 protected function showContacts()
334 {
335 if(!ilBuddySystem::getInstance()->isEnabled())
336 {
337 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
338 }
339
340 $this->tabs_gui->activateSubTab('buddy_view_table');
341 $this->activateTab('my_contacts');
342
343 require_once 'Services/Contact/BuddySystem/classes/tables/class.ilBuddySystemRelationsTableGUI.php';
344 $table = new ilBuddySystemRelationsTableGUI($this, 'showContacts');
345 $table->populate();
346 $this->tpl->setContent($table->getHTML());
347 $this->tpl->show();
348 }
349
353 protected function mailToUsers()
354 {
355 if(!$this->rbacsystem->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId()))
356 {
357 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
358 }
359
360 if(!isset($_POST['usr_id']) || !is_array($_POST['usr_id']) || 0 == count($_POST['usr_id']))
361 {
362 ilUtil::sendInfo($this->lng->txt('mail_select_one_entry'));
363 $this->showContacts();
364 return true;
365 }
366
367 $usr_ids = (array)$_POST['usr_id'];
368
369 $mail_data = $this->umail->getSavedData();
370 if(!is_array($mail_data))
371 {
372 $this->umail->savePostData($this->user->getId(), array(), '', '', '', '', '', '', '', '');
373 }
374
375 $logins = array();
376 foreach($usr_ids as $usr_id)
377 {
378 $logins[] = ilObjUser::_lookupLogin($usr_id);
379 }
380 $logins = array_filter($logins);
381
382 if(count($logins) > 0)
383 {
384 $mail_data = $this->umail->appendSearchResult($logins, 'to');
385 $this->umail->savePostData(
386 $mail_data['user_id'],
387 $mail_data['attachments'],
388 $mail_data['rcp_to'],
389 $mail_data['rcp_cc'],
390 $mail_data['rcp_bcc'],
391 $mail_data['m_type'],
392 $mail_data['m_email'],
393 $mail_data['m_subject'],
394 $mail_data['m_message'],
395 $mail_data['use_placeholders'],
396 $mail_data['tpl_ctx_id'],
397 $mail_data['tpl_ctx_params']
398 );
399 }
400
401 ilUtil::redirect('ilias.php?baseClass=ilMailGUI&type=search_res');
402 }
403
408 public function submitInvitation()
409 {
410 if(!isset($_POST['usr_id']) || !strlen($_POST['usr_id']))
411 {
412 ilUtil::sendInfo($this->lng->txt('select_one'), true);
413 $this->ctrl->redirect($this);
414 }
415
416 if(!$_POST['room_id'])
417 {
418 ilUtil::sendInfo($this->lng->txt('select_one'));
419 $_POST['usr_id'] = explode(',', $_POST['usr_id']);
420 $this->inviteToChat();
421 return;
422 }
423
424 // get selected users (comma seperated user id list)
425 $usr_ids = explode(',', $_POST['usr_id']);
426
427 // get selected chatroom from POST-String, format: "room_id , scope"
428 $room_ids = explode(',', $_POST['room_id']);
429 $room_id = (int)$room_ids[0];
430 $scope = 0;
431
432 if(count($room_ids) > 0)
433 {
434 $scope = (int)$room_ids[1];
435 }
436
437 include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
438
439 $room = ilChatroom::byRoomId((int)$room_id, true);
440 $no_access = array();
441 $no_login = array();
442 $valid_users = array();
443 $valid_user_to_login_map = array();
444
445 foreach($usr_ids as $usr_id)
446 {
447 $login = ilObjUser::_lookupLogin($usr_id);
448 if(!strlen($login))
449 {
450 $no_login[$usr_id] = $usr_id;
451 continue;
452 }
453
454 $ref_id = $room->getRefIdByRoomId($room_id);
455
456 if(
457 !ilChatroom::checkPermissionsOfUser($usr_id, 'read', $ref_id) ||
458 $room->isUserBanned($usr_id)
459 )
460 {
461 $no_access[$usr_id] = $login;
462 }
463 else
464 {
465 $valid_users[$usr_id] = $usr_id;
466 $valid_user_to_login_map[$usr_id] = $login;
467 }
468 }
469
470 if(count($no_access) || count($no_login))
471 {
472 $message = '';
473
474 if(count($no_access) > 0)
475 {
476 $message .= $this->lng->txt('chat_users_without_permission') . ':<br>';
477 $list = '';
478
479 foreach($no_access as $usr_id => $login)
480 {
481 $list .= '<li>' . $login . '</li>';
482 }
483
484 $message .= '<ul>';
485 $message .= $list;
486 $message .= '</ul>';
487 }
488
489 if(count($no_login))
490 {
491 $message .= $this->lng->txt('chat_users_without_login') . ':<br>';
492 $list = '';
493
494 foreach($no_login as $usr_id)
495 {
496 $list .= '<li>' . $usr_id . '</li>';
497 }
498
499 $message .= '<ul>';
500 $message .= $list;
501 $message .= '</ul>';
502 }
503
504 ilUtil::sendFailure($message);
505 $_POST['usr_id'] = $usr_ids;
506 $this->inviteToChat();
507 return;
508 }
509
510 $ref_id = $room->getRefIdByRoomId($room_id);
511
512 require_once 'Services/Link/classes/class.ilLink.php';
513 if($scope)
514 {
515 $url = ilLink::_getStaticLink($ref_id, 'chtr', true, '_'.$scope);
516 }
517 else
518 {
520 }
521 $link = '<p><a target="chatframe" href="' . $url . '" title="' . $this->lng->txt('goto_invitation_chat') . '">' .$this->lng->txt('goto_invitation_chat') . '</a></p>';
522
523 $userlist = array();
524 foreach($valid_users as $id)
525 {
526 $room->inviteUserToPrivateRoom($id, $scope);
527 $room->sendInvitationNotification(
528 null, $this->user->getId(), $id, (int)$scope, $url
529 );
530 $userlist[] = '<li>'.$valid_user_to_login_map[$id].'</li>';
531 }
532
533 if($userlist)
534 {
535 ilUtil::sendSuccess($this->lng->txt('chat_users_have_been_invited') . '<ul>'.implode('', $userlist).'</ul>' . $link, true);
536 }
537
538 $this->ctrl->redirect($this);
539 }
540
544 protected function inviteToChat()
545 {
546 $this->tabs_gui->activateSubTab('buddy_view_table');
547 $this->activateTab('my_contacts');
548
549 $this->lng->loadLanguageModule('chatroom');
550
551 if(!isset($_POST['usr_id']) || !is_array($_POST['usr_id']) || 0 == count($_POST['usr_id']))
552 {
553 ilUtil::sendInfo($this->lng->txt('select_one'), true);
554 $this->ctrl->redirect($this);
555 }
556 $usr_ids = $_POST['usr_id'];
557
558 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
559
560 $ilChatroom = new ilChatroom();
561 $chat_rooms = $ilChatroom->getAllRooms($this->user->getId());
562 $subrooms = array();
563
564 foreach($chat_rooms as $room_id => $title)
565 {
566 $subrooms[] = $ilChatroom->getPrivateSubRooms($room_id, $this->user->getId());
567 }
568
569 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
570
571 $form = new ilPropertyFormGUI();
572 $form->setTitle($this->lng->txt('mail_invite_users_to_chat'));
573
574 $psel = new ilSelectInputGUI($this->lng->txt('chat_select_room'), 'room_id');
575 $options = array();
576
577 foreach($chat_rooms as $room_id => $room)
578 {
579 $ref_id = $room_id;
580
581 if($ilChatroom->isUserBanned($this->user->getId()))
582 {
583 continue;
584 }
585
586 $options[$ref_id] = $room;
587
588 foreach($subrooms as $subroom)
589 {
590 foreach($subroom as $sub_id => $parent_id)
591 {
592 if($parent_id == $ref_id)
593 {
595 $options[$ref_id . ',' . $sub_id] = '+&nbsp;' . $title;
596 }
597 }
598 }
599 }
600
601 $psel->setOptions($options);
602 $form->addItem($psel);
603 $phidden = new ilHiddenInputGUI('usr_id');
604 $phidden->setValue(implode(',', $usr_ids));
605 $form->addItem($phidden);
606 $form->addCommandButton('submitInvitation', $this->lng->txt('submit'));
607 $form->addCommandButton('showContacts', $this->lng->txt('cancel'));
608 $form->setFormAction($this->ctrl->getFormAction($this, 'showContacts'));
609
610 $this->tpl->setTitle($this->lng->txt('mail_invite_users_to_chat'));
611 $this->tpl->setContent($form->getHTML());
612 $this->tpl->show();
613 }
614}
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
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 @global ilDBInterface $ilDB.
inviteToChat()
Send chat invitations to selected Users.
__construct()
ilContactGUI constructor.
changeContactsView()
This method is used to switch the contacts view between gallery and table in the mail system.
submitInvitation()
Last step of chat invitations check access for every selected user and send invitation.
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: ilCours...
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.
$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 $DIC