ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjTermsOfServiceGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Object/classes/class.ilObject2GUI.php';
5require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
6require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
7require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceTableDataProviderFactory.php';
8require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceAgreementByLanguageTableGUI.php';
9require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceAcceptanceHistoryTableGUI.php';
10
18{
22 protected $form;
23
27 public $lng;
28
32 public $ctrl;
33
37 public $object;
38
42 public $tabs_gui;
43
47 public $factory;
48
52 protected $rbacsystem;
53
57 protected $error;
58
62 protected $toolbar;
63
67 protected $user;
68
72 protected $log;
73
79 public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
80 {
85 global $DIC;
86
87 $this->lng = $DIC['lng'];
88 $this->rbacsystem = $DIC['rbacsystem'];
89 $this->error = $DIC['ilErr'];
90 $this->log = $DIC['ilLog'];
91 $this->toolbar = $DIC['ilToolbar'];
92 $this->user = $DIC['ilUser'];
93
94 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
95
96 $this->lng->loadLanguageModule('tos');
97
98 $this->factory = new ilTermsOfServiceTableDataProviderFactory();
99 $this->factory->setLanguageAdapter($this->lng);
100 $this->factory->setDatabaseAdapter($DIC['ilDB']);
101 }
102
106 public function getType()
107 {
108 return 'tos';
109 }
110
114 public function executeCommand()
115 {
116 $next_class = $this->ctrl->getNextClass($this);
117 $cmd = $this->ctrl->getCmd();
118 $this->prepareOutput();
119
120 switch ($next_class) {
121 case 'ilpermissiongui':
122 $this->tabs_gui->setTabActive('perm_settings');
123 require_once 'Services/AccessControl/classes/class.ilPermissionGUI.php';
124 $perm_gui = new ilPermissionGUI($this);
125 $this->ctrl->forwardCommand($perm_gui);
126 break;
127
128 default:
129 if ($cmd == '' || $cmd == 'view') {
130 $cmd = 'settings';
131 }
132 $this->$cmd();
133 break;
134 }
135 }
136
140 public function getAdminTabs()
141 {
142 if ($this->rbacsystem->checkAccess('read', $this->object->getRefId())) {
143 $this->tabs_gui->addTarget('settings', $this->ctrl->getLinkTarget($this, 'settings'), array('saveSettings', 'settings', '', 'view'), '', '');
144 }
145
146 if ($this->rbacsystem->checkAccess('read', $this->object->getRefId())) {
147 $this->tabs_gui->addTarget('tos_agreement_by_lng', $this->ctrl->getLinkTarget($this, 'showAgreementByLanguage'), array('reset', 'confirmReset', 'showAgreementByLanguage', 'resetAgreementByLanguageFilter', 'applyAgreementByLanguageFilter'), '', '');
148 }
149
150 if ($this->rbacsystem->checkAccess('read', $this->object->getRefId()) &&
151 $this->rbacsystem->checkAccess('read', USER_FOLDER_ID)
152 ) {
153 $this->tabs_gui->addTarget('tos_acceptance_history', $this->ctrl->getLinkTarget($this, 'showAcceptanceHistory'), array('showAcceptanceHistory', 'resetAcceptanceHistoryFilter', 'applyAcceptanceHistoryFilter'), '', '');
154 }
155
156 if ($this->rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
157 $this->tabs_gui->addTarget('perm_settings', $this->ctrl->getLinkTargetByClass(array(get_class($this), 'ilpermissiongui'), 'perm'), array('perm', 'info', 'owner'), 'ilpermissiongui');
158 }
159 }
160
164 protected function initSettingsForm()
165 {
166 if (null == $this->form) {
167 $this->form = new ilPropertyFormGUI();
168 $this->form->setTitle($this->lng->txt('tos_tos_settings'));
169 $this->form->setFormAction($this->ctrl->getFormAction($this, 'saveSettings'));
170
171 $status = new ilCheckboxInputGUI($this->lng->txt('tos_status_enable'), 'tos_status');
172 $status->setInfo($this->lng->txt('tos_status_desc'));
173 $this->form->addItem($status);
174
175 $this->form->addCommandButton('saveSettings', $this->lng->txt('save'));
176 }
177 }
178
182 protected function saveSettings()
183 {
184 if (!$this->rbacsystem->checkAccess('write', $this->object->getRefId())) {
185 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
186 }
187
189 $list = $provider->getList(array(), array());
190
191 $has_documents = false;
192 foreach ($list['items'] as $item) {
193 if ($item['agreement_document']) {
194 $has_documents = true;
195 break;
196 }
197 }
198
199 $this->initSettingsForm();
200 if ($this->form->checkInput()) {
201 if ($has_documents || !(int) $this->form->getInput('tos_status')) {
202 $this->object->saveStatus((int) $this->form->getInput('tos_status'));
203 ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
204 }
205 }
206
207 if (
208 !$has_documents &&
209 (int) $this->form->getInput('tos_status') &&
210 !$this->object->getStatus()
211 ) {
212 $_POST['tos_status'] = 0;
213 ilUtil::sendFailure($this->lng->txt('tos_no_documents_exist_cant_save'));
214 }
215
216 $this->settings(false);
217 }
218
222 protected function settings($init_from_database = true)
223 {
224 if (!$this->rbacsystem->checkAccess('read', $this->object->getRefId())) {
225 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
226 }
227
228 $this->showMissingDocuments();
229
230 $this->initSettingsForm();
231 if ($init_from_database) {
232 $this->form->setValuesByArray(array(
233 'tos_status' => $this->object->getStatus()
234 ));
235 } else {
236 $this->form->setValuesByPost();
237 }
238
239 $this->tpl->setContent($this->form->getHTML());
240 }
241
245 protected function confirmReset()
246 {
247 if (!$this->rbacsystem->checkAccess('write', $this->object->getRefId())) {
248 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
249 }
250
251 $confirmation = new ilConfirmationGUI();
252 $confirmation->setFormAction($this->ctrl->getFormAction($this, 'confirmReset'));
253 $confirmation->setConfirm($this->lng->txt('confirm'), 'reset');
254 $confirmation->setCancel($this->lng->txt('cancel'), 'showAgreementByLanguage');
255 $confirmation->setHeaderText($this->lng->txt('tos_sure_reset_tos'));
256
257 $this->tpl->setContent($confirmation->getHTML());
258 }
259
263 protected function reset()
264 {
265 if (!$this->rbacsystem->checkAccess('write', $this->object->getRefId())) {
266 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
267 }
268
269 $this->object->resetAll();
270 $this->log->write(__METHOD__ . ': Terms of service reset by ' . $this->user->getId() . ' [' . $this->user->getLogin() . ']');
271 ilUtil::sendSuccess($this->lng->txt('tos_reset_successfull'));
272
274 }
275
279 protected function showAgreementByLanguage()
280 {
281 if (!$this->rbacsystem->checkAccess('read', $this->object->getRefId())) {
282 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
283 }
284
285 $this->lng->loadLanguageModule('meta');
286
287 if ($this->rbacsystem->checkAccess('write', $this->object->getRefId())) {
288 $this->toolbar->setFormAction($this->ctrl->getFormAction($this, 'settings'));
289 $this->toolbar->addFormButton($this->lng->txt('tos_reset_tos_for_all_users'), 'confirmReset');
290 }
291
292 $this->showLastResetDate();
293
294 $table = new ilTermsOfServiceAgreementByLanguageTableGUI($this, 'showAgreementByLanguage');
296 $table->populate();
297
298 $this->tpl->setContent($table->getHTML());
299 }
300
304 protected function showLastResetDate()
305 {
306 if ($this->object->getLastResetDate() && $this->object->getLastResetDate()->get(IL_CAL_UNIX) != 0) {
309 $this->toolbar->addText(sprintf($this->lng->txt('tos_last_reset_date'), ilDatePresentation::formatDate($this->object->getLastResetDate())));
311 }
312 }
313
317 protected function showMissingDocuments()
318 {
319 if (!$this->object->getStatus()) {
320 return;
321 }
322
324 $list = $provider->getList(array(), array());
325
326 $has_documents = false;
327 foreach ($list['items'] as $item) {
328 if ($item['agreement_document']) {
329 $has_documents = true;
330 break;
331 }
332 }
333
334 if (!$has_documents) {
335 ilUtil::sendInfo($this->lng->txt('tos_no_documents_exist'));
336 }
337 }
338
343 {
344 $table = new ilTermsOfServiceAgreementByLanguageTableGUI($this, 'showAgreementByLanguage');
345 $table->resetOffset();
346 $table->writeFilterToSession();
347
349 }
350
355 {
356 $table = new ilTermsOfServiceAgreementByLanguageTableGUI($this, 'showAgreementByLanguage');
357 $table->resetOffset();
358 $table->resetFilter();
359
361 }
362
367 {
368 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceJsonResponse.php';
370
371 if (
372 !isset($_GET['agreement_document']) ||
373 !strlen($_GET['agreement_document']) ||
374 !$this->rbacsystem->checkAccess('read', $this->object->getRefId())) {
376 echo $response;
377 }
378
379 $file = realpath(strip_tags(rawurldecode(ilUtil::stripOnlySlashes($_GET['agreement_document']))));
380 if (preg_match('/Customizing[\/\\\](global[\/\\\]agreement|clients[\/\\\]' . CLIENT_ID . '[\/\\\]agreement)[\/\\\]agreement_([a-z]{2})\.html$/', $file)) {
381 $content = file_get_contents($file);
382 if (strip_tags($content) === $content) {
383 $content = '';
384 $lines = file($file);
385 foreach ($lines as $line) {
386 $content .= nl2br(trim($line));
387 }
388 }
389 $response->setBody($content);
390 } else {
392 }
393
394 echo $response;
395 }
396
400 protected function showAcceptanceHistory()
401 {
402 if (
403 !$this->rbacsystem->checkAccess('read', '', $this->object->getRefId()) ||
404 !$this->rbacsystem->checkAccess('read', '', USER_FOLDER_ID)
405 ) {
406 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
407 }
408
409 $this->lng->loadLanguageModule('meta');
410
411 $table = new ilTermsOfServiceAcceptanceHistoryTableGUI($this, 'showAcceptanceHistory');
412 $table->setProvider($this->factory->getByContext(ilTermsOfServiceTableDataProviderFactory::CONTEXT_ACCEPTANCE_HISTORY));
413 $table->populate();
414
415 $this->tpl->setContent($table->getHTML());
416 }
417
421 protected function getAcceptedContentAsynch()
422 {
423 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceJsonResponse.php';
425
426 if (!isset($_GET['tosv_id'])) {
428 echo $response;
429 }
430
432 $response->setBody($entity->getText());
433
434 echo $response;
435 }
436
440 protected function addUserAutoComplete()
441 {
442 if (
443 !$this->rbacsystem->checkAccess('read', '', $this->object->getRefId()) ||
444 !$this->rbacsystem->checkAccess('read', '', USER_FOLDER_ID)
445 ) {
446 echo json_encode(array());
447 exit();
448 }
449
450 include_once 'Services/User/classes/class.ilUserAutoComplete.php';
451 $auto = new ilUserAutoComplete();
452 $auto->setSearchFields(array('login', 'firstname', 'lastname', 'email'));
453 $auto->enableFieldSearchableCheck(false);
454 $auto->setMoreLinkAvailable(true);
455
456 if (($_REQUEST['fetchall'])) {
457 $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
458 }
459
460 echo $auto->getList($_REQUEST['term']);
461 exit();
462 }
463
467 protected function applyAcceptanceHistoryFilter()
468 {
469 $table = new ilTermsOfServiceAcceptanceHistoryTableGUI($this, 'showAcceptanceHistory');
470 $table->resetOffset();
471 $table->writeFilterToSession();
472
473 $this->showAcceptanceHistory();
474 }
475
479 protected function resetAcceptanceHistoryFilter()
480 {
481 $table = new ilTermsOfServiceAcceptanceHistoryTableGUI($this, 'showAcceptanceHistory');
482 $table->resetOffset();
483 $table->resetFilter();
484
485 $this->showAcceptanceHistory();
486 }
487}
sprintf('%.4f', $callTime)
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
error($a_errmsg)
set error message @access public
const USER_FOLDER_ID
Class ilObjUserFolder.
This class represents a checkbox property in a property form.
Confirmation screen class.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
settings($init_from_database=true)
addUserAutoComplete()
Show auto complete results.
getType()
Functions that must be overwritten.
getAdminTabs()
administration tabs show only permissions and trash folder
New implementation of ilObjectGUI.
prepareOutput($a_show_subobjects=true)
prepare output
__construct($a_id=0, $a_id_type=self::REPOSITORY_NODE_ID, $a_parent_node_id=0)
Constructor.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
Let this class derive from a real http response class in future.
Auto completion class for user lists.
static stripOnlySlashes($a_str)
strip slashes if magic qoutes is enabled
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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.
$response
if(empty($password)) $table
Definition: pwgen.php:24
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
global $DIC
Definition: saml.php:7