ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilChatroomBanTask.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
5
15{
16
17 private $gui;
18
28 {
29 $this->gui = $gui;
30 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
31 }
32
38 public function show()
39 {
40 //global $lng, $ilCtrl;
41 global $ilCtrl;
42
43 include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
44
45 ilChatroom::checkUserPermissions( 'read', $this->gui->ref_id );
46
47 $this->gui->switchToVisibleMode();
48
49 require_once 'Modules/Chatroom/classes/class.ilBannedUsersTableGUI.php';
50
51 $table = new ilBannedUsersTableGUI( $this->gui, 'ban-show' );
52 $table->setFormAction( $ilCtrl->getFormAction( $this->gui, 'ban-show' ) );
53
54 $room = ilChatroom::byObjectId( $this->gui->object->getId() );
55
56 if( $room )
57 {
58 $table->setData( $room->getBannedUsers() );
59 }
60
61 $this->gui->tpl->setVariable( 'ADM_CONTENT', $table->getHTML() );
62 }
63
69 public function delete()
70 {
75 global $ilCtrl, $lng;
76
77 $users = $_REQUEST['banned_user_id'];
78
79 if( !is_array( $users ) )
80 {
81 ilUtil::sendInfo($lng->txt('no_checkbox'), true);
82 $ilCtrl->redirect( $this->gui, 'ban-show' );
83 }
84
85 $room = ilChatroom::byObjectId( $this->gui->object->getId() );
86 $room->unbanUser( $users );
87
88 $ilCtrl->redirect( $this->gui, 'ban-show' );
89 }
90
96 public function executeDefault($method)
97 {
98 $this->show();
99 }
100
106 public function active()
107 {
108 global $ilUser, $ilCtrl;
109
110 if ( !ilChatroom::checkUserPermissions( array('read', 'moderate') , $this->gui->ref_id ) )
111 {
112 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
113 $ilCtrl->redirectByClass("ilrepositorygui", "");
114 }
115
116 $room = ilChatroom::byObjectId($this->gui->object->getId());
117
118 if($room)
119 {
120 // if user is in scope
121 $scope = $room->getRoomId();
122
123 $chat_user = new ilChatroomUser($ilUser, $room);
124
125 $messageObject = $this->buildMessage(
127 $chat_user
128 );
129
130 $message = json_encode($messageObject);
131
132
133 $params = array(
134 'message' => $message,
135 'userToKick' => $_REQUEST['user']
136 );
137
138 $query = http_build_query($params);
139 $connector = $this->gui->getConnector();
140 $response = $connector->kick($scope, $query);
141 $responseObject = json_decode($response);
142
143 $room->banUser($_REQUEST['user']);
144
145 if($responseObject->success == true)
146 {
147 $room->addHistoryEntry($messageObject, '', 1);
148
149 $message = json_encode(array(
150 'type' => 'userjustkicked',
151 'user' => $params['userToKick'],
152 'sub' => 0
153 ));
154
155 $connector->sendMessage($room->getRoomId(), $message, array(
156 'public' => 1,
157 'sub' => 0
158 ));
159
160 // 2013-09-11: Should already been done by the chat server
161 $room->disconnectUser($params['userToKick']);
162 }
163 }
164 else
165 {
166 $response = json_encode(array(
167 'success' => false,
168 'reason' => 'unkown room'
169 ));
170 }
171
172 echo $response;
173 exit;
174 }
175
184 private function buildMessage($messageString, ilChatroomUser $user)
185 {
186 $data = new stdClass();
187
188 $data->user = $this->gui->object->getPersonalInformation( $user );
189 $data->userToKick = $messageString;
190 $data->timestamp = date( 'c' );
191 $data->type = 'kick';
192
193 return $data;
194 }
195
196}
197
198?>
Class ilBannedUsersTableGUI.
Class ilChatroomBanTask.
__construct(ilChatroomObjectGUI $gui)
Constructor.
show()
Displays banned users task.
buildMessage($messageString, ilChatroomUser $user)
Instantiates stdClass, sets $data->user and $data->userToKick using given $messageString and $chat_us...
active()
Kicks and bans user, fetched from $_REQUEST['user'] and adds history entry.
executeDefault($method)
Calls $this->show method.
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
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.
$data
$params
Definition: example_049.php:96
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:54
global $lng
Definition: privfeed.php:40
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
global $ilUser
Definition: imgupload.php:15