ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
54 public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
55 {
60 global $lng, $ilDB;
61
62 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
63
64 $this->lng->loadLanguageModule('tos');
65
66 $this->factory = new ilTermsOfServiceTableDataProviderFactory();
67 $this->factory->setLanguageAdapter($lng);
68 $this->factory->setDatabaseAdapter($ilDB);
69 }
70
74 public function getType()
75 {
76 return 'tos';
77 }
78
82 public function executeCommand()
83 {
84 $next_class = $this->ctrl->getNextClass($this);
85 $cmd = $this->ctrl->getCmd();
86 $this->prepareOutput();
87
88 switch($next_class)
89 {
90 case 'ilpermissiongui':
91 $this->tabs_gui->setTabActive('perm_settings');
92 require_once 'Services/AccessControl/classes/class.ilPermissionGUI.php';
93 $perm_gui = new ilPermissionGUI($this);
94 $this->ctrl->forwardCommand($perm_gui);
95 break;
96
97 default:
98 if($cmd == '' || $cmd == 'view')
99 {
100 $cmd = 'settings';
101 }
102 $this->$cmd();
103 break;
104 }
105 }
106
110 public function getAdminTabs(ilTabsGUI $tabs_gui)
111 {
115 global $rbacsystem;
116
117 if($rbacsystem->checkAccess('read', $this->object->getRefId()))
118 {
119 $tabs_gui->addTarget('settings', $this->ctrl->getLinkTarget($this, 'settings'), array('saveSettings', 'settings', '', 'view'), '', '');
120 }
121
122 if($rbacsystem->checkAccess('read', $this->object->getRefId()))
123 {
124 $tabs_gui->addTarget('tos_agreement_by_lng', $this->ctrl->getLinkTarget($this, 'showAgreementByLanguage'), array('reset', 'confirmReset', 'showAgreementByLanguage', 'resetAgreementByLanguageFilter', 'applyAgreementByLanguageFilter'), '', '');
125 }
126
127 if($rbacsystem->checkAccess('read', $this->object->getRefId()) &&
128 $rbacsystem->checkAccess('read', USER_FOLDER_ID)
129 )
130 {
131 $tabs_gui->addTarget('tos_acceptance_history', $this->ctrl->getLinkTarget($this, 'showAcceptanceHistory'), array('showAcceptanceHistory', 'resetAcceptanceHistoryFilter', 'applyAcceptanceHistoryFilter'), '', '');
132 }
133
134 if($rbacsystem->checkAccess('edit_permission', $this->object->getRefId()))
135 {
136 $tabs_gui->addTarget('perm_settings', $this->ctrl->getLinkTargetByClass(array(get_class($this), 'ilpermissiongui'), 'perm'), array('perm', 'info', 'owner'), 'ilpermissiongui');
137 }
138 }
139
143 protected function initSettingsForm()
144 {
145 if(null == $this->form)
146 {
147 $this->form = new ilPropertyFormGUI();
148 $this->form->setTitle($this->lng->txt('tos_tos_settings'));
149 $this->form->setFormAction($this->ctrl->getFormAction($this, 'saveSettings'));
150
151 $status = new ilCheckboxInputGUI($this->lng->txt('tos_status_enable'), 'tos_status');
152 $status->setInfo($this->lng->txt('tos_status_desc'));
153 $this->form->addItem($status);
154
155 $this->form->addCommandButton('saveSettings', $this->lng->txt('save'));
156 }
157 }
158
162 protected function saveSettings()
163 {
168 global $rbacsystem, $ilErr;
169
170 if(!$rbacsystem->checkAccess('write', $this->object->getRefId()))
171 {
172 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
173 }
174
176 $list = $provider->getList(array(), array());
177
178 $has_documents = false;
179 foreach($list['items'] as $item)
180 {
181 if($item['agreement_document'])
182 {
183 $has_documents = true;
184 break;
185 }
186 }
187
188 $this->initSettingsForm();
189 if($this->form->checkInput())
190 {
191 if($has_documents || !(int)$this->form->getInput('tos_status'))
192 {
193 $this->object->saveStatus((int)$this->form->getInput('tos_status'));
194 ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
195 }
196 }
197
198 if(
199 !$has_documents &&
200 (int)$this->form->getInput('tos_status') &&
201 !$this->object->getStatus()
202 )
203 {
204 $_POST['tos_status'] = 0;
205 ilUtil::sendFailure($this->lng->txt('tos_no_documents_exist_cant_save'));
206 }
207
208 $this->settings(false);
209 }
210
214 protected function settings($init_from_database = true)
215 {
221 global $rbacsystem, $ilErr, $tpl;
222
223 if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
224 {
225 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
226 }
227
228 $this->showMissingDocuments();
229
230 $this->initSettingsForm();
231 if($init_from_database)
232 {
233 $this->form->setValuesByArray(array(
234 'tos_status' => $this->object->getStatus()
235 ));
236 }
237 else
238 {
239 $this->form->setValuesByPost();
240 }
241
242 $tpl->setContent($this->form->getHtml());
243 }
244
248 protected function confirmReset()
249 {
255 global $rbacsystem, $ilErr, $tpl;
256
257 if(!$rbacsystem->checkAccess('write', $this->object->getRefId()))
258 {
259 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
260 }
261
262 $confirmation = new ilConfirmationGUI();
263 $confirmation->setFormAction($this->ctrl->getFormAction($this, 'confirmReset'));
264 $confirmation->setConfirm($this->lng->txt('confirm'), 'reset');
265 $confirmation->setCancel($this->lng->txt('cancel'), 'showAgreementByLanguage');
266 $confirmation->setHeaderText($this->lng->txt('tos_sure_reset_tos'));
267
268 $tpl->setContent($confirmation->getHtml());
269 }
270
274 protected function reset()
275 {
282 global $rbacsystem, $ilErr, $ilLog, $ilUser;
283
284 if(!$rbacsystem->checkAccess('write', $this->object->getRefId()))
285 {
286 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
287 }
288
289 $this->object->resetAll();
290 $ilLog->write(__METHOD__ . ': Terms of service reset by ' . $ilUser->getId() . ' [' . $ilUser->getLogin() . ']');
291 ilUtil::sendSuccess($this->lng->txt('tos_reset_successfull'));
292
293 $this->showAgreementByLanguage();
294 }
295
299 protected function showAgreementByLanguage()
300 {
307 global $rbacsystem, $ilErr, $tpl, $ilToolbar;
308
309 if(!$rbacsystem->checkAccess('read', $this->object->getRefId()))
310 {
311 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
312 }
313
314 $this->lng->loadLanguageModule('meta');
315
316 if($rbacsystem->checkAccess('write', $this->object->getRefId()))
317 {
318 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, 'settings'));
319 $ilToolbar->addFormButton($this->lng->txt('tos_reset_tos_for_all_users'), 'confirmReset');
320 }
321
322 $this->showLastResetDate();
323
324 $table = new ilTermsOfServiceAgreementByLanguageTableGUI($this, 'showAgreementByLanguage');
325 $table->setProvider($this->factory->getByContext(ilTermsOfServiceTableDataProviderFactory::CONTEXT_AGRREMENT_BY_LANGUAGE));
326 $table->populate();
327
328 $tpl->setContent($table->getHtml());
329 }
330
334 protected function showLastResetDate()
335 {
339 global $ilToolbar;
340
341 if($this->object->getLastResetDate() && $this->object->getLastResetDate()->get(IL_CAL_UNIX) != 0)
342 {
345 $ilToolbar->addText(sprintf($this->lng->txt('tos_last_reset_date'), ilDatePresentation::formatDate($this->object->getLastResetDate())));
347 }
348 }
349
353 protected function showMissingDocuments()
354 {
355 if(!$this->object->getStatus())
356 {
357 return;
358 }
359
361 $list = $provider->getList(array(), array());
362
363 $has_documents = false;
364 foreach($list['items'] as $item)
365 {
366 if($item['agreement_document'])
367 {
368 $has_documents = true;
369 break;
370 }
371 }
372
373 if(!$has_documents)
374 {
375 ilUtil::sendInfo($this->lng->txt('tos_no_documents_exist'));
376 }
377 }
378
383 {
384 $table = new ilTermsOfServiceAgreementByLanguageTableGUI($this, 'showAgreementByLanguage');
385 $table->resetOffset();
386 $table->writeFilterToSession();
387
388 $this->showAgreementByLanguage();
389 }
390
395 {
396 $table = new ilTermsOfServiceAgreementByLanguageTableGUI($this, 'showAgreementByLanguage');
397 $table->resetOffset();
398 $table->resetFilter();
399
400 $this->showAgreementByLanguage();
401 }
402
406 protected function getAgreementTextByFilenameAsynch()
407 {
411 global $rbacsystem;
412
413 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceJsonResponse.php';
414 $response = new ilTermsOfServiceJsonResponse();
415
416 if(!isset($_GET['agreement_document']) || !strlen($_GET['agreement_document']) || !$rbacsystem->checkAccess('read', $this->object->getRefId()))
417 {
419 echo $response;
420 }
421
422 $file = realpath(strip_tags(rawurldecode(ilUtil::stripOnlySlashes($_GET['agreement_document']))));
423 if(preg_match('/Customizing[\/\\\](global[\/\\\]agreement|clients[\/\\\]' . CLIENT_ID . '[\/\\\]agreement)[\/\\\]agreement_([a-z]{2})\.html$/', $file))
424 {
425 $content = file_get_contents($file);
426 if(strip_tags($content) === $content)
427 {
428 $content = '';
429 $lines = file($file);
430 foreach($lines as $line)
431 {
432 $content .= nl2br(trim($line));
433 }
434 }
435 $response->setBody($content);
436 }
437 else
438 {
440 }
441
442 echo $response;
443 }
444
448 protected function showAcceptanceHistory()
449 {
455 global $rbacsystem, $ilErr, $tpl;
456
457 if(!$rbacsystem->checkAccess('read', '', $this->object->getRefId()) ||
458 !$rbacsystem->checkAccess('read', '', USER_FOLDER_ID)
459 )
460 {
461 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
462 }
463
464 $this->lng->loadLanguageModule('meta');
465
466 $table = new ilTermsOfServiceAcceptanceHistoryTableGUI($this, 'showAcceptanceHistory');
467 $table->setProvider($this->factory->getByContext(ilTermsOfServiceTableDataProviderFactory::CONTEXT_ACCEPTANCE_HISTORY));
468 $table->populate();
469
470 $tpl->setContent($table->getHtml());
471 }
472
476 protected function getAcceptedContentAsynch()
477 {
478 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceJsonResponse.php';
479 $response = new ilTermsOfServiceJsonResponse();
480
481 if(!isset($_GET['tosv_id']))
482 {
484 echo $response;
485 }
486
488 $response->setBody($entity->getText());
489
490 echo $response;
491 }
492
496 protected function addUserAutoComplete()
497 {
501 global $rbacsystem;
502
503 if(!$rbacsystem->checkAccess('read', '', $this->object->getRefId()) ||
504 !$rbacsystem->checkAccess('read', '', USER_FOLDER_ID)
505 )
506 {
507 echo json_encode(array());
508 exit();
509 }
510
511 include_once 'Services/User/classes/class.ilUserAutoComplete.php';
512 $auto = new ilUserAutoComplete();
513 $auto->setSearchFields(array('login', 'firstname', 'lastname', 'email'));
514 $auto->enableFieldSearchableCheck(false);
515 $auto->setMoreLinkAvailable(true);
516
517 if(($_REQUEST['fetchall']))
518 {
519 $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
520 }
521
522 echo $auto->getList($_REQUEST['term']);
523 exit();
524 }
525
529 protected function applyAcceptanceHistoryFilter()
530 {
531 $table = new ilTermsOfServiceAcceptanceHistoryTableGUI($this, 'showAcceptanceHistory');
532 $table->resetOffset();
533 $table->writeFilterToSession();
534
535 $this->showAcceptanceHistory();
536 }
537
541 protected function resetAcceptanceHistoryFilter()
542 {
543 $table = new ilTermsOfServiceAcceptanceHistoryTableGUI($this, 'showAcceptanceHistory');
544 $table->resetOffset();
545 $table->resetFilter();
546
547 $this->showAcceptanceHistory();
548 }
549}
print $file
$_GET["client_id"]
const IL_CAL_UNIX
const USER_FOLDER_ID
Class ilObjUserFolder.
This class represents a checkbox property in a property form.
Confirmation screen class.
static setUseRelativeDates($a_status)
set use relative dates
static formatDate(ilDateTime $date)
Format a date @access public.
static useRelativeDates()
check if relative dates are used
getType()
Functions that must be overwritten.
New implementation of ilObjectGUI.
__construct($a_id=0, $a_id_type=self::REPOSITORY_NODE_ID, $a_parent_node_id=0)
Constructor.
prepareOutput()
prepare output
getAdminTabs(&$tabs_gui)
administration tabs show only permissions and trash folder
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
Tabs GUI.
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.
$_POST['username']
Definition: cron.php:12
exit
Definition: login.php:54
$cmd
Definition: sahs_server.php:35
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
global $ilDB
global $ilUser
Definition: imgupload.php:15