ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjAdvancedEditingGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
28 {
30  protected string $cgrp = "";
33 
34  public function __construct(
35  $a_data,
36  int $a_id,
37  bool $a_call_by_reference
38  ) {
40  global $DIC;
41 
42  $this->component_repository = $DIC["component.repository"];
43 
44  $this->type = "adve";
45  parent::__construct($a_data, $a_id, $a_call_by_reference, false);
46  $this->lng->loadLanguageModule('adve');
47  $this->lng->loadLanguageModule('meta');
48  $this->std_request = new StandardGUIRequest(
49  $DIC->http(),
51  );
52  }
53 
54  public function executeCommand(): void
55  {
56  if (!$this->rbac_system->checkAccess('read', $this->object->getRefId())) {
57  $mess = str_replace("%s", $this->object->getTitle(), $this->lng->txt("msg_no_perm_read_item"));
58  $this->ilias->raiseError($mess, $this->ilias->error_obj->WARNING);
59  }
60 
61  $next_class = $this->ctrl->getNextClass($this);
62  $cmd = $this->ctrl->getCmd();
63  $this->prepareOutput();
64 
65  switch ($next_class) {
66  case 'ilpermissiongui':
67  $perm_gui = new ilPermissionGUI($this);
68  $this->ctrl->forwardCommand($perm_gui);
69  break;
70 
71  default:
72  if ($cmd === null || $cmd === "" || $cmd === "view") {
73  $cmd = "showGeneralPageEditorSettings";
74  }
75  $cmd .= "Object";
76  $this->$cmd();
77 
78  break;
79  }
80  }
81 
82  public function saveObject(): void
83  {
84  $this->checkPermission("write");
85 
86  parent::saveObject();
87 
88  // always send a message
89  $this->tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
90  $this->ctrl->redirect($this);
91  }
92 
93  public function getAdminTabs(): void
94  {
95  $this->getTabs();
96  }
97 
98  public function addSubtabs(): void
99  {
100  if ($this->ctrl->getNextClass() !== "ilpermissiongui" &&
101  !in_array($this->ctrl->getCmd(), array(
102  "showPageEditorSettings",
103  "showGeneralPageEditorSettings",
104  "",
105  "view"
106  ), true)) {
107  $this->tabs_gui->addSubTabTarget(
108  "adve_general_settings",
109  $this->ctrl->getLinkTarget($this, "settings"),
110  array("settings", "saveSettings"),
111  "",
112  ""
113  );
114  $this->tabs_gui->addSubTabTarget(
115  "adve_assessment_settings",
116  $this->ctrl->getLinkTarget($this, "assessment"),
117  array("assessment", "saveAssessmentSettings"),
118  "",
119  ""
120  );
121  $this->tabs_gui->addSubTabTarget(
122  "adve_survey_settings",
123  $this->ctrl->getLinkTarget($this, "survey"),
124  array("survey", "saveSurveySettings"),
125  "",
126  ""
127  );
128  $this->tabs_gui->addSubTabTarget(
129  "adve_frm_post_settings",
130  $this->ctrl->getLinkTarget($this, "frmPost"),
131  array("frmPost", "saveFrmPostSettings"),
132  "",
133  ""
134  );
135  $this->tabs_gui->addSubTabTarget(
136  "adve_excass_settings",
137  $this->ctrl->getLinkTarget($this, "excass"),
138  array("excass", "saveExcAssSettings"),
139  "",
140  ""
141  );
142  }
143  }
144 
145  public function addPageEditorSettingsSubtabs(): void
146  {
147  $this->tabs_gui->addSubTabTarget(
148  "adve_pe_general",
149  $this->ctrl->getLinkTarget($this, "showGeneralPageEditorSettings"),
150  array("showGeneralPageEditorSettings", "", "view")
151  );
152 
154 
155  foreach ($grps as $g => $types) {
156  $this->ctrl->setParameter($this, "grp", $g);
157  $this->tabs_gui->addSubTabTarget(
158  "adve_grp_" . $g,
159  $this->ctrl->getLinkTarget($this, "showPageEditorSettings"),
160  array("showPageEditorSettings")
161  );
162  }
163  $this->ctrl->setParameter($this, "grp", $this->std_request->getGroup());
164  }
165 
166  protected function getTabs(): void
167  {
168  if ($this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
169  $this->tabs_gui->addTarget(
170  "adve_page_editor_settings",
171  $this->ctrl->getLinkTarget($this, "showGeneralPageEditorSettings"),
172  array("showPageEditorSettings", "","view")
173  );
174 
175  $this->tabs_gui->addTarget(
176  "adve_rte_settings",
177  $this->ctrl->getLinkTarget($this, "settings"),
178  array("settings","assessment", "survey", "frmPost", "excass"),
179  "",
180  ""
181  );
182  }
183 
184  if ($this->rbac_system->checkAccess('edit_permission', $this->object->getRefId())) {
185  $this->tabs_gui->addTarget(
186  "perm_settings",
187  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"),
188  array("perm","info","owner"),
189  'ilpermissiongui'
190  );
191  }
192  $this->addSubtabs();
193  }
194 
195  public function settingsObject(): void
196  {
197  $tpl = $this->tpl;
198  $form = $this->getTinyForm();
199  $tpl->setContent($form->getHTML());
200  }
201 
202  public function getTinyForm(): ilPropertyFormGUI
203  {
205  $form = new ilPropertyFormGUI();
206  $form->setFormAction($this->ctrl->getFormAction($this));
207  $form->setTitle($this->lng->txt("adve_activation"));
208  $cb = new ilCheckboxInputGUI($this->lng->txt("adve_use_tiny_mce"), "use_tiny");
209  if ($editor === "tinymce") {
210  $cb->setChecked(true);
211  }
212  $form->addItem($cb);
213  if ($this->checkPermissionBool("write")) {
214  $form->addCommandButton("saveSettings", $this->lng->txt("save"));
215  }
216 
217  return $form;
218  }
219 
220  public function saveSettingsObject(): void
221  {
222  $this->checkPermission("write");
223 
224  $form = $this->getTinyForm();
225  $form->checkInput();
226 
227  if ($form->getInput("use_tiny")) {
228  $this->object->setRichTextEditor("tinymce");
229  } else {
230  $this->object->setRichTextEditor("");
231  }
232  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
233 
234  $this->ctrl->redirect($this, 'settings');
235  }
236 
237  public function assessmentObject(): void
238  {
239  $form = $this->initTagsForm(
240  "assessment",
241  "saveAssessmentSettings",
242  "advanced_editing_assessment_settings"
243  );
244 
245  $this->tpl->setContent($form->getHTML());
246  }
247 
248  public function saveAssessmentSettingsObject(): void
249  {
250  $form = $this->initTagsForm(
251  "assessment",
252  "saveAssessmentSettings",
253  "advanced_editing_assessment_settings"
254  );
255  if (!$this->saveTags("assessment", "assessment", $form)) {
256  $form->setValuesByPost();
257  $this->tpl->setContent($form->getHTML());
258  }
259  }
260 
261  public function surveyObject(): void
262  {
263  $form = $this->initTagsForm(
264  "survey",
265  "saveSurveySettings",
266  "advanced_editing_survey_settings"
267  );
268 
269  $this->tpl->setContent($form->getHTML());
270  }
271 
272  public function saveSurveySettingsObject(): void
273  {
274  $form = $this->initTagsForm(
275  "survey",
276  "saveSurveySettings",
277  "advanced_editing_survey_settings"
278  );
279  if (!$this->saveTags("survey", "survey", $form)) {
280  $form->setValuesByPost();
281  $this->tpl->setContent($form->getHTML());
282  }
283  }
284 
285  public function frmPostObject(): void
286  {
287  $form = $this->initTagsForm(
288  "frm_post",
289  "saveFrmPostSettings",
290  "advanced_editing_frm_post_settings"
291  );
292 
293  $this->tpl->setContent($form->getHTML());
294  }
295 
296  public function saveFrmPostSettingsObject(): void
297  {
298  $form = $this->initTagsForm(
299  "frm_post",
300  "saveFrmPostSettings",
301  "advanced_editing_frm_post_settings"
302  );
303  if (!$this->saveTags("frm_post", "frmPost", $form)) {
304  $form->setValuesByPost();
305  $this->tpl->setContent($form->getHTML());
306  }
307  }
308 
309  public function excAssObject(): void
310  {
311  $form = $this->initTagsForm(
312  "exc_ass",
313  "saveExcAssSettings",
314  "advanced_editing_excass_settings"
315  );
316 
317  $this->tpl->setContent($form->getHTML());
318  }
319 
320  public function saveExcAssSettingsObject(): void
321  {
322  $form = $this->initTagsForm(
323  "exc_ass",
324  "saveExcAssSettings",
325  "advanced_editing_excass_settings"
326  );
327  if (!$this->saveTags("exc_ass", "excAss", $form)) {
328  $form->setValuesByPost();
329  $this->tpl->setContent($form->getHTML());
330  }
331  }
332 
333 
334  protected function initTagsForm(
335  string $a_id,
336  string $a_cmd,
337  string $a_title
338  ): ilPropertyFormGUI {
339  $form = new ilPropertyFormGUI();
340  $form->setFormAction($this->ctrl->getFormAction($this, $a_cmd));
341  $form->setTitle($this->lng->txt($a_title));
342 
343  $alltags = $this->object->getHTMLTags();
344  $alltags = array_combine($alltags, $alltags);
345 
346  $tags = new ilMultiSelectInputGUI($this->lng->txt("advanced_editing_allow_html_tags"), "html_tags");
347  $tags->setHeight(400);
348  $tags->enableSelectAll(true);
349  $tags->enableSelectedFirst(true);
350  $tags->setOptions($alltags);
351  $tags->setValue(ilObjAdvancedEditing::_getUsedHTMLTags($a_id));
352  $form->addItem($tags);
353 
354  if ($this->access->checkAccess("write", "", $this->object->getRefId())) {
355  $form->addCommandButton($a_cmd, $this->lng->txt("save"));
356  }
357 
358  return $form;
359  }
360 
361  protected function saveTags(
362  string $a_id,
363  string $a_cmd,
364  ilPropertyFormGUI $form
365  ): bool {
366  $this->checkPermission("write");
367  try {
368  if ($form->checkInput()) {
369  $html_tags = $form->getInput("html_tags");
370  // get rid of select all
371  if (array_key_exists(0, $html_tags) && (string) $html_tags[0] === '') {
372  unset($html_tags[0]);
373  }
374  $this->object->setUsedHTMLTags((array) $html_tags, $a_id);
375  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
376  } else {
377  return false;
378  }
380  $this->tpl->setOnScreenMessage('info', $e->getMessage(), true);
381  }
382  $this->ctrl->redirect($this, $a_cmd);
383  return true;
384  }
385 
386  public function showPageEditorSettingsObject(): void
387  {
389 
391 
392  $this->cgrp = $this->std_request->getGroup();
393  if ($this->cgrp === "") {
394  $this->cgrp = (string) key($grps);
395  }
396 
397  $this->ctrl->setParameter($this, "grp", $this->cgrp);
398  $this->tabs_gui->setSubTabActive("adve_grp_" . $this->cgrp);
399 
400  $this->initPageEditorForm();
401  $this->tpl->setContent($this->form->getHTML());
402  }
403 
404  public function initPageEditorForm(): void
405  {
406  $this->lng->loadLanguageModule("content");
407 
408  $this->form = new ilPropertyFormGUI();
409 
410  if ($this->cgrp === "test") {
411  $this->form->setTitle($this->lng->txt("adve_activation"));
412  $cb = new ilCheckboxInputGUI($this->lng->txt("advanced_editing_tst_editing"), "tst_page_edit");
413  $cb->setInfo($this->lng->txt("advanced_editing_tst_editing_desc"));
415  $cb->setChecked(true);
416  }
417  $this->form->addItem($cb);
418 
419  $sh = new ilFormSectionHeaderGUI();
420  $sh->setTitle($this->lng->txt("adve_text_content_features"));
421  $this->form->addItem($sh);
422  } elseif ($this->cgrp === "rep") {
423  $this->form->setTitle($this->lng->txt("adve_activation"));
424  $cb = new ilCheckboxInputGUI($this->lng->txt("advanced_editing_rep_page_editing"), "cat_page_edit");
425  $cb->setInfo($this->lng->txt("advanced_editing_rep_page_editing_desc"));
426  if ($this->settings->get("enable_cat_page_edit")) {
427  $cb->setChecked(true);
428  }
429  $this->form->addItem($cb);
430 
431  $sh = new ilFormSectionHeaderGUI();
432  $sh->setTitle($this->lng->txt("adve_text_content_features"));
433  $this->form->addItem($sh);
434  } else {
435  $this->form->setTitle($this->lng->txt("adve_text_content_features"));
436  }
437 
438 
440  foreach ($buttons as $b => $t) {
441  // command button activation
442  $cb = new ilCheckboxInputGUI(str_replace(":", "", $this->lng->txt("cont_text_" . $b)), "active_" . $b);
443  $cb->setChecked((bool) ilPageEditorSettings::lookupSetting($this->cgrp, "active_" . $b, true));
444  $this->form->addItem($cb);
445  }
446 
447  // save and cancel commands
448  if ($this->checkPermissionBool("write")) {
449  $this->form->addCommandButton("savePageEditorSettings", $this->lng->txt("save"));
450  }
451 
452  $this->form->setFormAction($this->ctrl->getFormAction($this));
453  }
454 
455  public function savePageEditorSettingsObject(): void
456  {
457  $lng = $this->lng;
458  $ilCtrl = $this->ctrl;
460 
461  $this->checkPermission("write");
462 
463  $this->initPageEditorForm();
464  if ($this->form->checkInput()) {
466  foreach ($buttons as $b => $t) {
468  $this->std_request->getGroup(),
469  "active_" . $b,
470  $this->form->getInput("active_" . $b)
471  );
472  }
473 
474  if ($this->std_request->getGroup() === "test") {
475  $ilSetting->set("enable_tst_page_edit", (string) $this->form->getInput("tst_page_edit"));
476  } elseif ($this->std_request->getGroup() === "rep") {
477  $ilSetting->set("enable_cat_page_edit", (string) $this->form->getInput("cat_page_edit"));
478  }
479 
480  $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
481  }
482 
483  $ilCtrl->setParameter($this, "grp", $this->std_request->getGroup());
484  $ilCtrl->redirect($this, "showPageEditorSettings");
485  }
486 
487  public function showGeneralPageEditorSettingsObject(): void
488  {
490  $this->tabs_gui->activateTab("adve_page_editor_settings");
491 
492  $form = $this->initGeneralPageSettingsForm();
493  $this->tpl->setContent($form->getHTML());
494  }
495 
497  {
498  $form = new ilPropertyFormGUI();
499 
500  $aset = new ilSetting("adve");
501 
502  // use physical character styles
503  $cb = new ilCheckboxInputGUI($this->lng->txt("adve_use_physical"), "use_physical");
504  $cb->setInfo($this->lng->txt("adve_use_physical_info"));
505  $cb->setChecked((bool) $aset->get("use_physical"));
506  $form->addItem($cb);
507 
508  // blocking mode
509  $cb = new ilCheckboxInputGUI($this->lng->txt("adve_blocking_mode"), "block_mode_act");
510  $cb->setChecked((bool) $aset->get("block_mode_minutes") > 0);
511  $form->addItem($cb);
512 
513  // number of minutes
514  $ni = new ilNumberInputGUI($this->lng->txt("adve_minutes"), "block_mode_minutes");
515  $ni->setMinValue(2);
516  $ni->setMaxLength(5);
517  $ni->setSize(5);
518  $ni->setRequired(true);
519  $ni->setInfo($this->lng->txt("adve_minutes_info"));
520  $ni->setValue($aset->get("block_mode_minutes"));
521  $cb->addSubItem($ni);
522 
523  // autosave
524  $as = new ilNumberInputGUI($this->lng->txt("adve_autosave"), "autosave");
525  $as->setSuffix($this->lng->txt("seconds"));
526  $as->setMaxLength(5);
527  $as->setSize(5);
528  $as->setInfo($this->lng->txt("adve_autosave_info"));
529  $as->setValue($aset->get("autosave"));
530  $form->addItem($as);
531 
532  // auto url linking
533  $cb = new ilCheckboxInputGUI($this->lng->txt("adve_auto_url_linking"), "auto_url_linking");
534  $cb->setChecked((bool) $aset->get("auto_url_linking"));
535  $cb->setInfo($this->lng->txt("adve_auto_url_linking_info"));
536  $form->addItem($cb);
537 
538  if ($this->checkPermissionBool("write")) {
539  $form->addCommandButton("saveGeneralPageSettings", $this->lng->txt("save"));
540  }
541 
542  // workaround for glossaries to force rewriting of short texts
544 
545 
546  $form->setTitle($this->lng->txt("adve_pe_general"));
547  $form->setFormAction($this->ctrl->getFormAction($this));
548 
549  return $form;
550  }
551 
559  protected function getPageObjectKeysWithOptionalHTML(): array
560  {
561  return ["lobj","copa","mep","blp","prtf","prtt","term","lm","qht","qpl","qfbg","qfbs","sahs","stys","cont","cstr","auth"];
562  }
563 
564  public function saveGeneralPageSettingsObject(): void
565  {
566  $this->checkPermission("write");
567 
568  $form = $this->initGeneralPageSettingsForm();
569  if ($form->checkInput()) {
570  $autosave = (int) $form->getInput("autosave");
571  $ok = true;
572 
573  // autosave must be greater 10, if activated
574  if ($autosave > 0 && $autosave < 10) {
575  $form->getItemByPostVar("autosave")->setAlert($this->lng->txt("adve_autosave_info_min_10"));
576  $ok = false;
577  }
578 
579  if ($ok) {
580  $aset = new ilSetting("adve");
581  $aset->set("use_physical", $form->getInput("use_physical"));
582  if ($form->getInput("block_mode_act")) {
583  $aset->set("block_mode_minutes", (string) (int) $form->getInput("block_mode_minutes"));
584  } else {
585  $aset->set("block_mode_minutes", 0);
586  }
587  $aset->set("auto_url_linking", $form->getInput("auto_url_linking"));
588 
589  $aset->set("autosave", $form->getInput("autosave"));
590 
591  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
592  $this->ctrl->redirect($this, "showGeneralPageEditorSettings");
593  }
594  }
595 
596  $form->setValuesByPost();
597  $this->tpl->setContent($form->getHTML());
598  }
599 }
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)
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)
prepareOutput(bool $show_sub_objects=true)
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...
__construct(VocabulariesInterface $vocabularies)
ilGlobalTemplateInterface $tpl
setContent(string $a_html)
Sets content for standard template.
setFormAction(string $a_formaction)
const ADDITIONAL_QUESTION_CONTENT_EDITING_MODE_PAGE_OBJECT_DISABLED
Class ilObjectGUI Basic methods of all Output classes.
ilComponentRepository $component_repository
header include for all ilias files.
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
form( $class_path, string $cmd, string $submit_caption="")
global $ilSetting
Definition: privfeed.php:18
initTagsForm(string $a_id, string $a_cmd, string $a_title)
Class ilObjAdvancedEditingGUI.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
ilSetting $settings
static setShortTextsDirtyGlobally()
Set short texts dirty (for all glossaries)
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.