ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_once 'Services/Object/classes/class.ilObject2GUI.php';
5 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
6 require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
7 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceTableDataProviderFactory.php';
8 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceAgreementByLanguageTableGUI.php';
9 require_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  {
122  case 'ilpermissiongui':
123  $this->tabs_gui->setTabActive('perm_settings');
124  require_once 'Services/AccessControl/classes/class.ilPermissionGUI.php';
125  $perm_gui = new ilPermissionGUI($this);
126  $this->ctrl->forwardCommand($perm_gui);
127  break;
128 
129  default:
130  if($cmd == '' || $cmd == 'view')
131  {
132  $cmd = 'settings';
133  }
134  $this->$cmd();
135  break;
136  }
137  }
138 
142  public function getAdminTabs()
143  {
144  if($this->rbacsystem->checkAccess('read', $this->object->getRefId()))
145  {
146  $this->tabs_gui->addTarget('settings', $this->ctrl->getLinkTarget($this, 'settings'), array('saveSettings', 'settings', '', 'view'), '', '');
147  }
148 
149  if($this->rbacsystem->checkAccess('read', $this->object->getRefId()))
150  {
151  $this->tabs_gui->addTarget('tos_agreement_by_lng', $this->ctrl->getLinkTarget($this, 'showAgreementByLanguage'), array('reset', 'confirmReset', 'showAgreementByLanguage', 'resetAgreementByLanguageFilter', 'applyAgreementByLanguageFilter'), '', '');
152  }
153 
154  if($this->rbacsystem->checkAccess('read', $this->object->getRefId()) &&
155  $this->rbacsystem->checkAccess('read', USER_FOLDER_ID)
156  )
157  {
158  $this->tabs_gui->addTarget('tos_acceptance_history', $this->ctrl->getLinkTarget($this, 'showAcceptanceHistory'), array('showAcceptanceHistory', 'resetAcceptanceHistoryFilter', 'applyAcceptanceHistoryFilter'), '', '');
159  }
160 
161  if($this->rbacsystem->checkAccess('edit_permission', $this->object->getRefId()))
162  {
163  $this->tabs_gui->addTarget('perm_settings', $this->ctrl->getLinkTargetByClass(array(get_class($this), 'ilpermissiongui'), 'perm'), array('perm', 'info', 'owner'), 'ilpermissiongui');
164  }
165  }
166 
170  protected function initSettingsForm()
171  {
172  if(null == $this->form)
173  {
174  $this->form = new ilPropertyFormGUI();
175  $this->form->setTitle($this->lng->txt('tos_tos_settings'));
176  $this->form->setFormAction($this->ctrl->getFormAction($this, 'saveSettings'));
177 
178  $status = new ilCheckboxInputGUI($this->lng->txt('tos_status_enable'), 'tos_status');
179  $status->setInfo($this->lng->txt('tos_status_desc'));
180  $this->form->addItem($status);
181 
182  $this->form->addCommandButton('saveSettings', $this->lng->txt('save'));
183  }
184  }
185 
189  protected function saveSettings()
190  {
191  if(!$this->rbacsystem->checkAccess('write', $this->object->getRefId()))
192  {
193  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
194  }
195 
197  $list = $provider->getList(array(), array());
198 
199  $has_documents = false;
200  foreach($list['items'] as $item)
201  {
202  if($item['agreement_document'])
203  {
204  $has_documents = true;
205  break;
206  }
207  }
208 
209  $this->initSettingsForm();
210  if($this->form->checkInput())
211  {
212  if($has_documents || !(int)$this->form->getInput('tos_status'))
213  {
214  $this->object->saveStatus((int)$this->form->getInput('tos_status'));
215  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
216  }
217  }
218 
219  if(
220  !$has_documents &&
221  (int)$this->form->getInput('tos_status') &&
222  !$this->object->getStatus()
223  )
224  {
225  $_POST['tos_status'] = 0;
226  ilUtil::sendFailure($this->lng->txt('tos_no_documents_exist_cant_save'));
227  }
228 
229  $this->settings(false);
230  }
231 
235  protected function settings($init_from_database = true)
236  {
237  if(!$this->rbacsystem->checkAccess('read', $this->object->getRefId()))
238  {
239  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
240  }
241 
242  $this->showMissingDocuments();
243 
244  $this->initSettingsForm();
245  if($init_from_database)
246  {
247  $this->form->setValuesByArray(array(
248  'tos_status' => $this->object->getStatus()
249  ));
250  }
251  else
252  {
253  $this->form->setValuesByPost();
254  }
255 
256  $this->tpl->setContent($this->form->getHTML());
257  }
258 
262  protected function confirmReset()
263  {
264  if(!$this->rbacsystem->checkAccess('write', $this->object->getRefId()))
265  {
266  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
267  }
268 
269  $confirmation = new ilConfirmationGUI();
270  $confirmation->setFormAction($this->ctrl->getFormAction($this, 'confirmReset'));
271  $confirmation->setConfirm($this->lng->txt('confirm'), 'reset');
272  $confirmation->setCancel($this->lng->txt('cancel'), 'showAgreementByLanguage');
273  $confirmation->setHeaderText($this->lng->txt('tos_sure_reset_tos'));
274 
275  $this->tpl->setContent($confirmation->getHTML());
276  }
277 
281  protected function reset()
282  {
283  if(!$this->rbacsystem->checkAccess('write', $this->object->getRefId()))
284  {
285  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
286  }
287 
288  $this->object->resetAll();
289  $this->log->write(__METHOD__ . ': Terms of service reset by ' . $this->user->getId() . ' [' . $this->user->getLogin() . ']');
290  ilUtil::sendSuccess($this->lng->txt('tos_reset_successfull'));
291 
292  $this->showAgreementByLanguage();
293  }
294 
298  protected function showAgreementByLanguage()
299  {
300  if(!$this->rbacsystem->checkAccess('read', $this->object->getRefId()))
301  {
302  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
303  }
304 
305  $this->lng->loadLanguageModule('meta');
306 
307  if($this->rbacsystem->checkAccess('write', $this->object->getRefId()))
308  {
309  $this->toolbar->setFormAction($this->ctrl->getFormAction($this, 'settings'));
310  $this->toolbar->addFormButton($this->lng->txt('tos_reset_tos_for_all_users'), 'confirmReset');
311  }
312 
313  $this->showLastResetDate();
314 
315  $table = new ilTermsOfServiceAgreementByLanguageTableGUI($this, 'showAgreementByLanguage');
316  $table->setProvider($this->factory->getByContext(ilTermsOfServiceTableDataProviderFactory::CONTEXT_AGRREMENT_BY_LANGUAGE));
317  $table->populate();
318 
319  $this->tpl->setContent($table->getHTML());
320  }
321 
325  protected function showLastResetDate()
326  {
327  if($this->object->getLastResetDate() && $this->object->getLastResetDate()->get(IL_CAL_UNIX) != 0)
328  {
331  $this->toolbar->addText(sprintf($this->lng->txt('tos_last_reset_date'), ilDatePresentation::formatDate($this->object->getLastResetDate())));
333  }
334  }
335 
339  protected function showMissingDocuments()
340  {
341  if(!$this->object->getStatus())
342  {
343  return;
344  }
345 
347  $list = $provider->getList(array(), array());
348 
349  $has_documents = false;
350  foreach($list['items'] as $item)
351  {
352  if($item['agreement_document'])
353  {
354  $has_documents = true;
355  break;
356  }
357  }
358 
359  if(!$has_documents)
360  {
361  ilUtil::sendInfo($this->lng->txt('tos_no_documents_exist'));
362  }
363  }
364 
368  protected function applyAgreementByLanguageFilter()
369  {
370  $table = new ilTermsOfServiceAgreementByLanguageTableGUI($this, 'showAgreementByLanguage');
371  $table->resetOffset();
372  $table->writeFilterToSession();
373 
374  $this->showAgreementByLanguage();
375  }
376 
380  protected function resetAgreementByLanguageFilter()
381  {
382  $table = new ilTermsOfServiceAgreementByLanguageTableGUI($this, 'showAgreementByLanguage');
383  $table->resetOffset();
384  $table->resetFilter();
385 
386  $this->showAgreementByLanguage();
387  }
388 
392  protected function getAgreementTextByFilenameAsynch()
393  {
394  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceJsonResponse.php';
395  $response = new ilTermsOfServiceJsonResponse();
396 
397  if(
398  !isset($_GET['agreement_document']) ||
399  !strlen($_GET['agreement_document']) ||
400  !$this->rbacsystem->checkAccess('read', $this->object->getRefId()))
401  {
402  $response->setStatus(ilTermsOfServiceJsonResponse::STATUS_FAILURE);
403  echo $response;
404  }
405 
406  $file = realpath(strip_tags(rawurldecode(ilUtil::stripOnlySlashes($_GET['agreement_document']))));
407  if(preg_match('/Customizing[\/\\\](global[\/\\\]agreement|clients[\/\\\]' . CLIENT_ID . '[\/\\\]agreement)[\/\\\]agreement_([a-z]{2})\.html$/', $file))
408  {
409  $content = file_get_contents($file);
410  if(strip_tags($content) === $content)
411  {
412  $content = '';
413  $lines = file($file);
414  foreach($lines as $line)
415  {
416  $content .= nl2br(trim($line));
417  }
418  }
419  $response->setBody($content);
420  }
421  else
422  {
423  $response->setStatus(ilTermsOfServiceJsonResponse::STATUS_FAILURE);
424  }
425 
426  echo $response;
427  }
428 
432  protected function showAcceptanceHistory()
433  {
434  if(
435  !$this->rbacsystem->checkAccess('read', '', $this->object->getRefId()) ||
436  !$this->rbacsystem->checkAccess('read', '', USER_FOLDER_ID)
437  )
438  {
439  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
440  }
441 
442  $this->lng->loadLanguageModule('meta');
443 
444  $table = new ilTermsOfServiceAcceptanceHistoryTableGUI($this, 'showAcceptanceHistory');
445  $table->setProvider($this->factory->getByContext(ilTermsOfServiceTableDataProviderFactory::CONTEXT_ACCEPTANCE_HISTORY));
446  $table->populate();
447 
448  $this->tpl->setContent($table->getHTML());
449  }
450 
454  protected function getAcceptedContentAsynch()
455  {
456  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceJsonResponse.php';
457  $response = new ilTermsOfServiceJsonResponse();
458 
459  if(!isset($_GET['tosv_id']))
460  {
461  $response->setStatus(ilTermsOfServiceJsonResponse::STATUS_FAILURE);
462  echo $response;
463  }
464 
466  $response->setBody($entity->getText());
467 
468  echo $response;
469  }
470 
474  protected function addUserAutoComplete()
475  {
476  if(
477  !$this->rbacsystem->checkAccess('read', '', $this->object->getRefId()) ||
478  !$this->rbacsystem->checkAccess('read', '', USER_FOLDER_ID)
479  )
480  {
481  echo json_encode(array());
482  exit();
483  }
484 
485  include_once 'Services/User/classes/class.ilUserAutoComplete.php';
486  $auto = new ilUserAutoComplete();
487  $auto->setSearchFields(array('login', 'firstname', 'lastname', 'email'));
488  $auto->enableFieldSearchableCheck(false);
489  $auto->setMoreLinkAvailable(true);
490 
491  if(($_REQUEST['fetchall']))
492  {
493  $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
494  }
495 
496  echo $auto->getList($_REQUEST['term']);
497  exit();
498  }
499 
503  protected function applyAcceptanceHistoryFilter()
504  {
505  $table = new ilTermsOfServiceAcceptanceHistoryTableGUI($this, 'showAcceptanceHistory');
506  $table->resetOffset();
507  $table->writeFilterToSession();
508 
509  $this->showAcceptanceHistory();
510  }
511 
515  protected function resetAcceptanceHistoryFilter()
516  {
517  $table = new ilTermsOfServiceAcceptanceHistoryTableGUI($this, 'showAcceptanceHistory');
518  $table->resetOffset();
519  $table->resetFilter();
520 
521  $this->showAcceptanceHistory();
522  }
523 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents a property form user interface.
New implementation of ilObjectGUI.
$_GET["client_id"]
$cmd
Definition: sahs_server.php:35
This class represents a checkbox property in a property form.
static setUseRelativeDates($a_status)
set use relative dates
Let this class derive from a real http response class in future.
const IL_CAL_UNIX
user()
Definition: user.php:4
static useRelativeDates()
check if relative dates are used
Auto completion class for user lists.
static stripOnlySlashes($a_str)
strip slashes if magic qoutes is enabled
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
getType()
Functions that must be overwritten.
settings($init_from_database=true)
static formatDate(ilDateTime $date)
Format a date public.
addUserAutoComplete()
Show auto complete results.
Reload workbook from saved file
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Create new PHPExcel object
obj_idprivate
__construct($a_id=0, $a_id_type=self::REPOSITORY_NODE_ID, $a_parent_node_id=0)
Constructor.
prepareOutput($a_show_subobjects=true)
const USER_FOLDER_ID
Class ilObjUserFolder.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
global $DIC
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
$_POST["username"]
Confirmation screen class.