ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilChatroomAdminViewGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
5require_once 'Modules/Chatroom/classes/class.ilChatroomFormFactory.php';
6require_once 'Modules/Chatroom/classes/class.ilChatroomAdmin.php';
7require_once 'Modules/Chatroom/classes/class.ilChatroomConfigFileHandler.php';
8
17{
18 const CHATROOM_README_PATH = '/Modules/Chatroom/README.md';
19
23 protected $commonSettings;
24
28 protected $ilTpl;
29
35 {
36 global $DIC;
37
38 parent::__construct($gui);
39 $this->commonSettings = new ilSetting('common');
40 $this->ilTpl = $DIC->ui()->mainTemplate();
41 }
42
46 public function executeDefault($method)
47 {
48 $this->ilCtrl->redirect($this->gui, 'view-clientsettings');
49 }
50
54 public function saveSettings()
55 {
56 $this->redirectIfNoPermission('write');
57
59 $form = $factory->getGeneralSettingsForm();
60
61 if (!$form->checkInput()) {
62 $form->setValuesByPost();
63 $this->serversettings($form);
64 return;
65 }
66
67 $settings = array(
68 'protocol' => $form->getInput('protocol'),
69 'port' => $form->getInput('port'),
70 'address' => $form->getInput('address'),
71 'cert' => $form->getInput('cert'),
72 'key' => $form->getInput('key'),
73 'dhparam' => $form->getInput('dhparam'),
74 'log' => $form->getInput('log'),
75 'error_log' => $form->getInput('error_log'),
76 'log_level' => $form->getInput('log_level'),
77 'ilias_proxy' => $form->getInput('ilias_proxy'),
78 'ilias_url' => $form->getInput('ilias_url'),
79 'client_proxy' => $form->getInput('client_proxy'),
80 'client_url' => $form->getInput('client_url'),
81 'sub_directory' => $form->getInput('sub_directory'),
82 'deletion_mode' => $form->getInput('deletion_mode'),
83 'deletion_unit' => $form->getInput('deletion_unit'),
84 'deletion_value' => $form->getInput('deletion_value'),
85 'deletion_time' => $form->getInput('deletion_time'),
86 );
87
88 $adminSettings = new ilChatroomAdmin($this->gui->object->getId());
89 $adminSettings->saveGeneralSettings((object) $settings);
90
91 $fileHandler = new ilChatroomConfigFileHandler();
92 $fileHandler->createServerConfigFile($settings);
93
94 ilUtil::sendSuccess($this->ilLng->txt('settings_has_been_saved'), true);
95 $this->ilCtrl->redirect($this->gui, 'view-serversettings');
96 }
97
102 public function serversettings(ilPropertyFormGUI $form = null)
103 {
104 $this->redirectIfNoPermission('read');
105
106 $this->defaultActions();
107 $this->gui->switchToVisibleMode();
108
109 $adminSettings = new ilChatroomAdmin($this->gui->object->getId());
110 $serverSettings = $adminSettings->loadGeneralSettings();
111
112 if ($form === null) {
114 $form = $factory->getGeneralSettingsForm();
115 $form->setValuesByArray($serverSettings);
116 }
117
118 $this->checkServerConnection($serverSettings);
119
120 $form->setTitle($this->ilLng->txt('chatserver_settings_title'));
121 if (ilChatroom::checkUserPermissions('write', $this->gui->ref_id, false)) {
122 $form->addCommandButton('view-saveSettings', $this->ilLng->txt('save'));
123 }
124 $form->setFormAction($this->ilCtrl->getFormAction($this->gui, 'view-saveSettings'));
125
126 $settingsTpl = $this->createSettingTemplate($form);
127 $this->ilTpl->setVariable('ADM_CONTENT', $settingsTpl->get());
128 }
129
133 private function defaultActions()
134 {
135 $chatSettings = new ilSetting('chatroom');
136 if ($chatSettings->get('chat_enabled', false)) {
137 $this->forcePublicRoom();
138 }
139 }
140
144 public function forcePublicRoom()
145 {
147 if (!$ref_id) {
148 $this->createPublicRoom();
149 return;
150 }
151
152 $instance = ilObjectFactory::getInstanceByRefId($ref_id, false);
153 if (!$instance) {
154 $this->createPublicRoom();
155 return;
156 }
157
158 $obj_id = ilObject::_lookupObjId($ref_id);
159 if (!$obj_id) {
160 $this->createPublicRoom();
161 return;
162 }
163
164 if (!ilObject::_hasUntrashedReference($obj_id)) {
165 $this->createPublicRoom();
166 return;
167 }
168
169 require_once 'Modules/Chatroom/classes/class.ilChatroomInstaller.php';
170 ilChatroomInstaller::ensureCorrectPublicChatroomTreeLocation($ref_id);
171 }
172
176 public function createPublicRoom()
177 {
178 require_once 'Modules/Chatroom/classes/class.ilChatroomInstaller.php';
179 ilChatroomInstaller::createDefaultPublicRoom(true);
180 ilUtil::sendSuccess($this->ilLng->txt('public_chat_created'), true);
181 }
182
187 protected function checkServerConnection(array $serverSettings)
188 {
189 require_once 'Modules/Chatroom/classes/class.ilChatroomServerConnector.php';
190
191 if (
192 $serverSettings['port'] &&
193 $serverSettings['address'] &&
195 ) {
196 ilUtil::sendInfo($this->ilLng->txt('chat_cannot_connect_to_server'));
197 }
198 }
199
205 {
206 $furtherInformation = sprintf($this->ilLng->txt('server_further_information'), $this->getReadmePath());
207 $serverTpl = new ilTemplate('tpl.chatroom_serversettings.html', true, true, 'Modules/Chatroom');
208 $serverTpl->setVariable('VAL_SERVERSETTINGS_FORM', $form->getHTML());
209 $serverTpl->setVariable('LBL_SERVERSETTINGS_FURTHER_INFORMATION', $furtherInformation);
210
211 return $serverTpl;
212 }
213
218 protected function getReadmePath()
219 {
221 }
222
226 public function saveClientSettings()
227 {
228 $this->redirectIfNoPermission('write');
229
231 $form = $factory->getClientSettingsForm();
232
233 if (!$form->checkInput()) {
234 $form->setValuesByPost();
235 $this->clientsettings($form);
236 return;
237 }
238
239 $settings = array(
240 'name' => (string) $form->getInput('client_name'),
241 'enable_osd' => (boolean) $form->getInput('enable_osd'),
242 'enable_osc' => (boolean) $form->getInput('enable_osc'),
243 'osd_intervall' => (int) $form->getInput('osd_intervall'),
244 'chat_enabled' => ((boolean) $form->getInput('chat_enabled')),
245 'enable_smilies' => (boolean) $form->getInput('enable_smilies'),
246 'play_invitation_sound' => (boolean) $form->getInput('play_invitation_sound'),
247 'auth' => $form->getInput('auth')
248 );
249
250 if (!$settings['chat_enabled']) {
251 $settings['enable_osc'] = false;
252 }
253
254 $notificationSettings = new ilSetting('notifications');
255 $notificationSettings->set('osd_polling_intervall', (int) $form->getInput('osd_intervall'));
256 $notificationSettings->set('enable_osd', (boolean) $form->getInput('enable_osd'));
257
258 $chatSettings = new ilSetting('chatroom');
259 $chatSettings->set('chat_enabled', $settings['chat_enabled']);
260 $chatSettings->set('enable_osc', $settings['enable_osc']);
261 $chatSettings->set('play_invitation_sound', (boolean) $form->getInput('play_invitation_sound'));
262
263 $adminSettings = new ilChatroomAdmin($this->gui->object->getId());
264 $adminSettings->saveClientSettings((object) $settings);
265
266 $fileHandler = new ilChatroomConfigFileHandler();
267 $fileHandler->createClientConfigFile($settings);
268
269 ilUtil::sendSuccess($this->ilLng->txt('settings_has_been_saved'), true);
270 $this->ilCtrl->redirect($this->gui, 'view-clientsettings');
271 }
272
276 public function clientsettings(ilPropertyFormGUI $form = null)
277 {
278 $this->redirectIfNoPermission('read');
279
280 $this->defaultActions();
281 $this->gui->switchToVisibleMode();
282
283 $adminSettings = new ilChatroomAdmin($this->gui->object->getId());
284 $serverSettings = $adminSettings->loadGeneralSettings();
285
286 if ($form === null) {
287 $clientSettings = $adminSettings->loadClientSettings();
289 $form = $factory->getClientSettingsForm();
290 $form->setValuesByArray($clientSettings);
291 }
292
293 $this->checkServerConnection($serverSettings);
294
295 $form->setTitle($this->ilLng->txt('general_settings_title'));
296 if (ilChatroom::checkUserPermissions('write', $this->gui->ref_id, false)) {
297 $form->addCommandButton('view-saveClientSettings', $this->ilLng->txt('save'));
298 }
299 $form->setFormAction($this->ilCtrl->getFormAction($this->gui, 'view-saveClientSettings'));
300
301 $settingsTpl = $this->createSettingTemplate($form);
302 $this->ilTpl->setVariable('ADM_CONTENT', $settingsTpl->get());
303 }
304}
$factory
Definition: metadata.php:43
An exception for terminatinating execution or to throw for unit testing.
Class ilChatroomAdminViewGUI.
saveSettings()
Saves settings fetched from $_POST.
__construct(ilChatroomObjectGUI $gui)
Constructor.
serversettings(ilPropertyFormGUI $form=null)
Prepares view form and displays it.
createPublicRoom()
Creates a public chatroom.
checkServerConnection(array $serverSettings)
Checks for server connection.
saveClientSettings()
Saves client settings fetched from $_POST.
clientsettings(ilPropertyFormGUI $form=null)
getReadmePath()
Get the path to the README.txt file.
createSettingTemplate(ilPropertyFormGUI $form)
Class ilChatroomAdmin.
Class ilChatroomFormFactory.
Class ilChatroomGUIHandler.
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
static checkServerConnection($use_cache=true)
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
This class provides processing control methods.
getFormAction( $a_gui_obj, $a_fallback_cmd="", $a_anchor="", $a_asynch=false, $xml_style=true)
Get form action url for gui class object.
redirect($a_gui_obj, $a_cmd="", $a_anchor="", $a_asynch=false)
Redirect to another command.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjId($a_id)
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
This class represents a property form user interface.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
static _getHttpPath()
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7