ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjAdvancedEditingGUI.php
Go to the documentation of this file.
1 <?php
2 
17 
25 {
27  protected string $cgrp = "";
30 
31  public function __construct(
32  $a_data,
33  int $a_id,
34  bool $a_call_by_reference
35  ) {
37  global $DIC;
38 
39  $this->component_repository = $DIC["component.repository"];
40 
41  $this->type = "adve";
42  parent::__construct($a_data, $a_id, $a_call_by_reference, false);
43  $this->lng->loadLanguageModule('adve');
44  $this->lng->loadLanguageModule('meta');
45  $this->std_request = new StandardGUIRequest(
46  $DIC->http(),
48  );
49  }
50 
51  public function executeCommand(): void
52  {
53  if (!$this->rbac_system->checkAccess('read', $this->object->getRefId())) {
54  $mess = str_replace("%s", $this->object->getTitle(), $this->lng->txt("msg_no_perm_read_item"));
55  $this->ilias->raiseError($mess, $this->ilias->error_obj->WARNING);
56  }
57 
58  $next_class = $this->ctrl->getNextClass($this);
59  $cmd = $this->ctrl->getCmd();
60  $this->prepareOutput();
61 
62  switch ($next_class) {
63 
64  case 'ilpermissiongui':
65  $perm_gui = new ilPermissionGUI($this);
66  $this->ctrl->forwardCommand($perm_gui);
67  break;
68 
69  default:
70  if ($cmd === null || $cmd === "" || $cmd === "view") {
71  $cmd = "showGeneralPageEditorSettings";
72  }
73  $cmd .= "Object";
74  $this->$cmd();
75 
76  break;
77  }
78  }
79 
80  public function saveObject(): void
81  {
82  $this->checkPermission("write");
83 
84  parent::saveObject();
85 
86  // always send a message
87  $this->tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
88  $this->ctrl->redirect($this);
89  }
90 
91  public function getAdminTabs(): void
92  {
93  $this->getTabs();
94  }
95 
96  public function addSubtabs(): void
97  {
98  if ($this->ctrl->getNextClass() !== "ilpermissiongui" &&
99  !in_array($this->ctrl->getCmd(), array(
100  "showPageEditorSettings",
101  "showGeneralPageEditorSettings",
102  "showCharSelectorSettings",
103  "",
104  "view"
105  ), true)) {
106  $this->tabs_gui->addSubTabTarget(
107  "adve_general_settings",
108  $this->ctrl->getLinkTarget($this, "settings"),
109  array("settings", "saveSettings"),
110  "",
111  ""
112  );
113  $this->tabs_gui->addSubTabTarget(
114  "adve_assessment_settings",
115  $this->ctrl->getLinkTarget($this, "assessment"),
116  array("assessment", "saveAssessmentSettings"),
117  "",
118  ""
119  );
120  $this->tabs_gui->addSubTabTarget(
121  "adve_survey_settings",
122  $this->ctrl->getLinkTarget($this, "survey"),
123  array("survey", "saveSurveySettings"),
124  "",
125  ""
126  );
127  $this->tabs_gui->addSubTabTarget(
128  "adve_frm_post_settings",
129  $this->ctrl->getLinkTarget($this, "frmPost"),
130  array("frmPost", "saveFrmPostSettings"),
131  "",
132  ""
133  );
134  $this->tabs_gui->addSubTabTarget(
135  "adve_excass_settings",
136  $this->ctrl->getLinkTarget($this, "excass"),
137  array("excass", "saveExcAssSettings"),
138  "",
139  ""
140  );
141  }
142  }
143 
144  public function addPageEditorSettingsSubtabs(): void
145  {
146  $this->tabs_gui->addSubTabTarget(
147  "adve_pe_general",
148  $this->ctrl->getLinkTarget($this, "showGeneralPageEditorSettings"),
149  array("showGeneralPageEditorSettings", "", "view")
150  );
151 
153 
154  foreach ($grps as $g => $types) {
155  $this->ctrl->setParameter($this, "grp", $g);
156  $this->tabs_gui->addSubTabTarget(
157  "adve_grp_" . $g,
158  $this->ctrl->getLinkTarget($this, "showPageEditorSettings"),
159  array("showPageEditorSettings")
160  );
161  }
162  $this->ctrl->setParameter($this, "grp", $this->std_request->getGroup());
163  }
164 
165  protected function getTabs(): void
166  {
167  if ($this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
168  $this->tabs_gui->addTarget(
169  "adve_page_editor_settings",
170  $this->ctrl->getLinkTarget($this, "showGeneralPageEditorSettings"),
171  array("showPageEditorSettings", "","view")
172  );
173 
174  $this->tabs_gui->addTarget(
175  "adve_rte_settings",
176  $this->ctrl->getLinkTarget($this, "settings"),
177  array("settings","assessment", "survey", "frmPost", "excass"),
178  "",
179  ""
180  );
181 
182  $this->tabs_gui->addTarget(
183  "adve_char_selector_settings",
184  $this->ctrl->getLinkTarget($this, "showCharSelectorSettings"),
185  array("showCharSelectorSettings", "","view")
186  );
187  }
188 
189  if ($this->rbac_system->checkAccess('edit_permission', $this->object->getRefId())) {
190  $this->tabs_gui->addTarget(
191  "perm_settings",
192  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"),
193  array("perm","info","owner"),
194  'ilpermissiongui'
195  );
196  }
197  $this->addSubtabs();
198  }
199 
200  public function settingsObject(): void
201  {
202  $tpl = $this->tpl;
203  $form = $this->getTinyForm();
204  $tpl->setContent($form->getHTML());
205  }
206 
207  public function getTinyForm(): ilPropertyFormGUI
208  {
210  $form = new ilPropertyFormGUI();
211  $form->setFormAction($this->ctrl->getFormAction($this));
212  $form->setTitle($this->lng->txt("adve_activation"));
213  $cb = new ilCheckboxInputGUI($this->lng->txt("adve_use_tiny_mce"), "use_tiny");
214  if ($editor === "tinymce") {
215  $cb->setChecked(true);
216  }
217  $form->addItem($cb);
218  if ($this->checkPermissionBool("write")) {
219  $form->addCommandButton("saveSettings", $this->lng->txt("save"));
220  }
221 
222  return $form;
223  }
224 
225  public function saveSettingsObject(): void
226  {
227  $this->checkPermission("write");
228 
229  $form = $this->getTinyForm();
230  $form->checkInput();
231 
232  if ($form->getInput("use_tiny")) {
233  $this->object->setRichTextEditor("tinymce");
234  } else {
235  $this->object->setRichTextEditor("");
236  }
237  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
238 
239  $this->ctrl->redirect($this, 'settings');
240  }
241 
242  public function assessmentObject(): void
243  {
244  $form = $this->initTagsForm(
245  "assessment",
246  "saveAssessmentSettings",
247  "advanced_editing_assessment_settings"
248  );
249 
250  $this->tpl->setContent($form->getHTML());
251  }
252 
253  public function saveAssessmentSettingsObject(): void
254  {
255  $form = $this->initTagsForm(
256  "assessment",
257  "saveAssessmentSettings",
258  "advanced_editing_assessment_settings"
259  );
260  if (!$this->saveTags("assessment", "assessment", $form)) {
261  $form->setValuesByPost();
262  $this->tpl->setContent($form->getHTML());
263  }
264  }
265 
266  public function surveyObject(): void
267  {
268  $form = $this->initTagsForm(
269  "survey",
270  "saveSurveySettings",
271  "advanced_editing_survey_settings"
272  );
273 
274  $this->tpl->setContent($form->getHTML());
275  }
276 
277  public function saveSurveySettingsObject(): void
278  {
279  $form = $this->initTagsForm(
280  "survey",
281  "saveSurveySettings",
282  "advanced_editing_survey_settings"
283  );
284  if (!$this->saveTags("survey", "survey", $form)) {
285  $form->setValuesByPost();
286  $this->tpl->setContent($form->getHTML());
287  }
288  }
289 
290  public function frmPostObject(): void
291  {
292  $form = $this->initTagsForm(
293  "frm_post",
294  "saveFrmPostSettings",
295  "advanced_editing_frm_post_settings"
296  );
297 
298  $this->tpl->setContent($form->getHTML());
299  }
300 
301  public function saveFrmPostSettingsObject(): void
302  {
303  $form = $this->initTagsForm(
304  "frm_post",
305  "saveFrmPostSettings",
306  "advanced_editing_frm_post_settings"
307  );
308  if (!$this->saveTags("frm_post", "frmPost", $form)) {
309  $form->setValuesByPost();
310  $this->tpl->setContent($form->getHTML());
311  }
312  }
313 
314  public function excAssObject(): void
315  {
316  $form = $this->initTagsForm(
317  "exc_ass",
318  "saveExcAssSettings",
319  "advanced_editing_excass_settings"
320  );
321 
322  $this->tpl->setContent($form->getHTML());
323  }
324 
325  public function saveExcAssSettingsObject(): void
326  {
327  $form = $this->initTagsForm(
328  "exc_ass",
329  "saveExcAssSettings",
330  "advanced_editing_excass_settings"
331  );
332  if (!$this->saveTags("exc_ass", "excAss", $form)) {
333  $form->setValuesByPost();
334  $this->tpl->setContent($form->getHTML());
335  }
336  }
337 
338 
339  protected function initTagsForm(
340  string $a_id,
341  string $a_cmd,
342  string $a_title
343  ): ilPropertyFormGUI {
344  $form = new ilPropertyFormGUI();
345  $form->setFormAction($this->ctrl->getFormAction($this, $a_cmd));
346  $form->setTitle($this->lng->txt($a_title));
347 
348  $alltags = $this->object->getHTMLTags();
349  $alltags = array_combine($alltags, $alltags);
350 
351  $tags = new ilMultiSelectInputGUI($this->lng->txt("advanced_editing_allow_html_tags"), "html_tags");
352  $tags->setHeight(400);
353  $tags->enableSelectAll(true);
354  $tags->enableSelectedFirst(true);
355  $tags->setOptions($alltags);
356  $tags->setValue(ilObjAdvancedEditing::_getUsedHTMLTags($a_id));
357  $form->addItem($tags);
358 
359  if ($this->access->checkAccess("write", "", $this->object->getRefId())) {
360  $form->addCommandButton($a_cmd, $this->lng->txt("save"));
361  }
362 
363  return $form;
364  }
365 
366  protected function saveTags(
367  string $a_id,
368  string $a_cmd,
369  ilPropertyFormGUI $form
370  ): bool {
371  $this->checkPermission("write");
372  try {
373  if ($form->checkInput()) {
374  $html_tags = $form->getInput("html_tags");
375  // get rid of select all
376  if (array_key_exists(0, $html_tags) && (string) $html_tags[0] === '') {
377  unset($html_tags[0]);
378  }
379  $this->object->setUsedHTMLTags((array) $html_tags, $a_id);
380  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
381  } else {
382  return false;
383  }
385  $this->tpl->setOnScreenMessage('info', $e->getMessage(), true);
386  }
387  $this->ctrl->redirect($this, $a_cmd);
388  return true;
389  }
390 
391  public function showPageEditorSettingsObject(): void
392  {
394 
396 
397  $this->cgrp = $this->std_request->getGroup();
398  if ($this->cgrp === "") {
399  $this->cgrp = (string) key($grps);
400  }
401 
402  $this->ctrl->setParameter($this, "grp", $this->cgrp);
403  $this->tabs_gui->setSubTabActive("adve_grp_" . $this->cgrp);
404 
405  $this->initPageEditorForm();
406  $this->tpl->setContent($this->form->getHTML());
407  }
408 
409  public function initPageEditorForm(): void
410  {
411  $this->lng->loadLanguageModule("content");
412 
413  $this->form = new ilPropertyFormGUI();
414 
415  if ($this->cgrp === "test") {
416  $this->form->setTitle($this->lng->txt("adve_activation"));
417  $cb = new ilCheckboxInputGUI($this->lng->txt("advanced_editing_tst_editing"), "tst_page_edit");
418  $cb->setInfo($this->lng->txt("advanced_editing_tst_editing_desc"));
420  $cb->setChecked(true);
421  }
422  $this->form->addItem($cb);
423 
424  $sh = new ilFormSectionHeaderGUI();
425  $sh->setTitle($this->lng->txt("adve_text_content_features"));
426  $this->form->addItem($sh);
427  } elseif ($this->cgrp === "rep") {
428  $this->form->setTitle($this->lng->txt("adve_activation"));
429  $cb = new ilCheckboxInputGUI($this->lng->txt("advanced_editing_rep_page_editing"), "cat_page_edit");
430  $cb->setInfo($this->lng->txt("advanced_editing_rep_page_editing_desc"));
431  if ($this->settings->get("enable_cat_page_edit")) {
432  $cb->setChecked(true);
433  }
434  $this->form->addItem($cb);
435 
436  $sh = new ilFormSectionHeaderGUI();
437  $sh->setTitle($this->lng->txt("adve_text_content_features"));
438  $this->form->addItem($sh);
439  } else {
440  $this->form->setTitle($this->lng->txt("adve_text_content_features"));
441  }
442 
443 
445  foreach ($buttons as $b => $t) {
446  // command button activation
447  $cb = new ilCheckboxInputGUI(str_replace(":", "", $this->lng->txt("cont_text_" . $b)), "active_" . $b);
448  $cb->setChecked((bool) ilPageEditorSettings::lookupSetting($this->cgrp, "active_" . $b, true));
449  $this->form->addItem($cb);
450  }
451 
452  // save and cancel commands
453  if ($this->checkPermissionBool("write")) {
454  $this->form->addCommandButton("savePageEditorSettings", $this->lng->txt("save"));
455  }
456 
457  $this->form->setFormAction($this->ctrl->getFormAction($this));
458  }
459 
460  public function savePageEditorSettingsObject(): void
461  {
462  $lng = $this->lng;
463  $ilCtrl = $this->ctrl;
465 
466  $this->checkPermission("write");
467 
468  $this->initPageEditorForm();
469  if ($this->form->checkInput()) {
471  foreach ($buttons as $b => $t) {
473  $this->std_request->getGroup(),
474  "active_" . $b,
475  $this->form->getInput("active_" . $b)
476  );
477  }
478 
479  if ($this->std_request->getGroup() === "test") {
480  $ilSetting->set("enable_tst_page_edit", (string) $this->form->getInput("tst_page_edit"));
481  } elseif ($this->std_request->getGroup() === "rep") {
482  $ilSetting->set("enable_cat_page_edit", (string) $this->form->getInput("cat_page_edit"));
483  }
484 
485  $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
486  }
487 
488  $ilCtrl->setParameter($this, "grp", $this->std_request->getGroup());
489  $ilCtrl->redirect($this, "showPageEditorSettings");
490  }
491 
492  public function showGeneralPageEditorSettingsObject(): void
493  {
495  $this->tabs_gui->activateTab("adve_page_editor_settings");
496 
497  $form = $this->initGeneralPageSettingsForm();
498  $this->tpl->setContent($form->getHTML());
499  }
500 
502  {
503  $form = new ilPropertyFormGUI();
504 
505  $aset = new ilSetting("adve");
506 
507  // use physical character styles
508  $cb = new ilCheckboxInputGUI($this->lng->txt("adve_use_physical"), "use_physical");
509  $cb->setInfo($this->lng->txt("adve_use_physical_info"));
510  $cb->setChecked((bool) $aset->get("use_physical"));
511  $form->addItem($cb);
512 
513  // blocking mode
514  $cb = new ilCheckboxInputGUI($this->lng->txt("adve_blocking_mode"), "block_mode_act");
515  $cb->setChecked((bool) $aset->get("block_mode_minutes") > 0);
516  $form->addItem($cb);
517 
518  // number of minutes
519  $ni = new ilNumberInputGUI($this->lng->txt("adve_minutes"), "block_mode_minutes");
520  $ni->setMinValue(2);
521  $ni->setMaxLength(5);
522  $ni->setSize(5);
523  $ni->setRequired(true);
524  $ni->setInfo($this->lng->txt("adve_minutes_info"));
525  $ni->setValue($aset->get("block_mode_minutes"));
526  $cb->addSubItem($ni);
527 
528  // autosave
529  $as = new ilNumberInputGUI($this->lng->txt("adve_autosave"), "autosave");
530  $as->setSuffix($this->lng->txt("seconds"));
531  $as->setMaxLength(5);
532  $as->setSize(5);
533  $as->setInfo($this->lng->txt("adve_autosave_info"));
534  $as->setValue($aset->get("autosave"));
535  $form->addItem($as);
536 
537  // auto url linking
538  $cb = new ilCheckboxInputGUI($this->lng->txt("adve_auto_url_linking"), "auto_url_linking");
539  $cb->setChecked((bool) $aset->get("auto_url_linking"));
540  $cb->setInfo($this->lng->txt("adve_auto_url_linking_info"));
541  $form->addItem($cb);
542 
543  if ($this->checkPermissionBool("write")) {
544  $form->addCommandButton("saveGeneralPageSettings", $this->lng->txt("save"));
545  }
546 
547  // workaround for glossaries to force rewriting of short texts
549 
550 
551  $form->setTitle($this->lng->txt("adve_pe_general"));
552  $form->setFormAction($this->ctrl->getFormAction($this));
553 
554  return $form;
555  }
556 
564  protected function getPageObjectKeysWithOptionalHTML(): array
565  {
566  return ["lobj","copa","mep","blp","prtf","prtt","gdf","lm","qht","qpl","qfbg","qfbs","sahs","stys","cont","cstr","auth"];
567  }
568 
569  public function saveGeneralPageSettingsObject(): void
570  {
571  $this->checkPermission("write");
572 
573  $form = $this->initGeneralPageSettingsForm();
574  if ($form->checkInput()) {
575  $autosave = (int) $form->getInput("autosave");
576  $ok = true;
577 
578  // autosave must be greater 10, if activated
579  if ($autosave > 0 && $autosave < 10) {
580  $form->getItemByPostVar("autosave")->setAlert($this->lng->txt("adve_autosave_info_min_10"));
581  $ok = false;
582  }
583 
584  if ($ok) {
585  $aset = new ilSetting("adve");
586  $aset->set("use_physical", $form->getInput("use_physical"));
587  if ($form->getInput("block_mode_act")) {
588  $aset->set("block_mode_minutes", (string) (int) $form->getInput("block_mode_minutes"));
589  } else {
590  $aset->set("block_mode_minutes", 0);
591  }
592  $aset->set("auto_url_linking", $form->getInput("auto_url_linking"));
593 
594  $aset->set("autosave", $form->getInput("autosave"));
595 
596  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
597  $this->ctrl->redirect($this, "showGeneralPageEditorSettings");
598  }
599  }
600 
601  $form->setValuesByPost();
602  $this->tpl->setContent($form->getHTML());
603  }
604 
606  {
607  $form = new ilPropertyFormGUI();
608  $form->setTitle($this->lng->txt('settings'));
609  $form->setFormAction($this->ctrl->getFormAction($this));
610  if ($this->checkPermissionBool("write")) {
611  $form->addCommandButton("saveCharSelectorSettings", $this->lng->txt("save"));
612  }
613  $char_selector->addFormProperties($form);
614 
615  return $form;
616  }
617 
618 
622  public function showCharSelectorSettingsObject(): void
623  {
624  $this->tabs_gui->activateTab("adve_char_selector_settings");
625 
627  $char_selector->getConfig()->setAvailability((int) $this->settings->get('char_selector_availability'));
628  $char_selector->getConfig()->setDefinition((string) $this->settings->get('char_selector_definition'));
629  $form = $this->initCharSelectorSettingsForm($char_selector);
630  $char_selector->setFormValues($form);
631  $this->tpl->setContent($form->getHTML());
632  }
633 
634 
638  public function saveCharSelectorSettingsObject(): void
639  {
640  $this->checkPermission("write");
641 
643  $form = $this->initCharSelectorSettingsForm($char_selector);
644  if ($form->checkInput()) {
645  $char_selector->getFormValues($form);
646 
647  $this->settings->set('char_selector_availability', $char_selector->getConfig()->getAvailability());
648  $this->settings->set('char_selector_definition', $char_selector->getConfig()->getDefinition());
649 
650  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
651  $this->ctrl->redirect($this, "showCharSelectorSettings");
652  }
653  $form->setValuesByPost();
654  $this->tpl->setContent($form->getHTML());
655  }
656 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Readable part of repository interface to ilComponentDataDB.
saveTags(string $a_id, string $a_cmd, ilPropertyFormGUI $form)
setSuffix(string $a_value)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _getRichTextEditor()
Returns the identifier for the Rich Text Editor.
getItemByPostVar(string $a_post_var)
__construct($data, int $id=0, bool $call_by_reference=true, bool $prepare_output=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
prepareOutput(bool $show_sub_objects=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveCharSelectorSettingsObject()
Save the settings for the selector of unicode characters.
This class represents a checkbox property in a property form.
static getGroups()
Get all settings groups.
getPageObjectKeysWithOptionalHTML()
This limits the possibility to allow html for these page objects that supported the feature in the pa...
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupSetting(string $a_grp, string $a_name, string $a_default='0')
Lookup setting.
static writeSetting(string $a_grp, string $a_name, string $a_value)
Write Setting.
global $DIC
Definition: feed.php:28
ilLanguage $lng
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $tpl
setContent(string $a_html)
Sets content for standard template.
addFormProperties(ilPropertyFormGUI $a_form)
add the configuration elements to a property form
setFormAction(string $a_formaction)
const ADDITIONAL_QUESTION_CONTENT_EDITING_MODE_PAGE_OBJECT_DISABLED
This class represents a number property in a property form.
Class ilObjectGUI Basic methods of all Output classes.
static setShortTextsDirtyGlobally()
Set short texts dirty (for all glossaries)
ilComponentRepository $component_repository
showCharSelectorSettingsObject()
Show the settings for the selector of unicode characters.
header include for all ilias files.
form( $class_path, string $cmd)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
initCharSelectorSettingsForm(ilCharSelectorGUI $char_selector)
setMinValue(float $a_minvalue, bool $a_display_always=false)
global $ilSetting
Definition: privfeed.php:17
__construct(Container $dic, ilPlugin $plugin)
initTagsForm(string $a_id, string $a_cmd, string $a_title)
Class ilObjAdvancedEditingGUI.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
ilSetting $settings
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
static _getUsedHTMLTags(string $a_module="")
Returns an array of all allowed HTML tags for text editing.