ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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_frm_post_settings",
123  $this->ctrl->getLinkTarget($this, "frmPost"),
124  array("frmPost", "saveFrmPostSettings"),
125  "",
126  ""
127  );
128  }
129  }
130 
131  public function addPageEditorSettingsSubtabs(): void
132  {
133  $this->tabs_gui->addSubTabTarget(
134  "adve_pe_general",
135  $this->ctrl->getLinkTarget($this, "showGeneralPageEditorSettings"),
136  array("showGeneralPageEditorSettings", "", "view")
137  );
138 
140 
141  foreach ($grps as $g => $types) {
142  $this->ctrl->setParameter($this, "grp", $g);
143  $this->tabs_gui->addSubTabTarget(
144  "adve_grp_" . $g,
145  $this->ctrl->getLinkTarget($this, "showPageEditorSettings"),
146  array("showPageEditorSettings")
147  );
148  }
149  $this->ctrl->setParameter($this, "grp", $this->std_request->getGroup());
150  }
151 
152  protected function getTabs(): void
153  {
154  if ($this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
155  $this->tabs_gui->addTarget(
156  "adve_page_editor_settings",
157  $this->ctrl->getLinkTarget($this, "showGeneralPageEditorSettings"),
158  array("showPageEditorSettings", "","view")
159  );
160 
161  $this->tabs_gui->addTarget(
162  "adve_rte_settings",
163  $this->ctrl->getLinkTarget($this, "settings"),
164  array("settings","assessment", "frmPost"),
165  "",
166  ""
167  );
168  }
169 
170  if ($this->rbac_system->checkAccess('edit_permission', $this->object->getRefId())) {
171  $this->tabs_gui->addTarget(
172  "perm_settings",
173  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"),
174  array("perm","info","owner"),
175  'ilpermissiongui'
176  );
177  }
178  $this->addSubtabs();
179  }
180 
181  public function settingsObject(): void
182  {
183  $tpl = $this->tpl;
184  $form = $this->getTinyForm();
185  $tpl->setContent($form->getHTML());
186  }
187 
188  public function getTinyForm(): ilPropertyFormGUI
189  {
191  $form = new ilPropertyFormGUI();
192  $form->setFormAction($this->ctrl->getFormAction($this));
193  $form->setTitle($this->lng->txt("adve_activation"));
194  $cb = new ilCheckboxInputGUI($this->lng->txt("adve_use_tiny_mce"), "use_tiny");
195  if ($editor === "tinymce") {
196  $cb->setChecked(true);
197  }
198  $form->addItem($cb);
199  if ($this->checkPermissionBool("write")) {
200  $form->addCommandButton("saveSettings", $this->lng->txt("save"));
201  }
202 
203  return $form;
204  }
205 
206  public function saveSettingsObject(): void
207  {
208  $this->checkPermission("write");
209 
210  $form = $this->getTinyForm();
211  $form->checkInput();
212 
213  if ($form->getInput("use_tiny")) {
214  $this->object->setRichTextEditor("tinymce");
215  } else {
216  $this->object->setRichTextEditor("");
217  }
218  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
219 
220  $this->ctrl->redirect($this, 'settings');
221  }
222 
223  public function assessmentObject(): void
224  {
225  $form = $this->initTagsForm(
226  "assessment",
227  "saveAssessmentSettings",
228  "advanced_editing_assessment_settings"
229  );
230 
231  $this->tpl->setContent($form->getHTML());
232  }
233 
234  public function saveAssessmentSettingsObject(): void
235  {
236  $form = $this->initTagsForm(
237  "assessment",
238  "saveAssessmentSettings",
239  "advanced_editing_assessment_settings"
240  );
241  if (!$this->saveTags("assessment", "assessment", $form)) {
242  $form->setValuesByPost();
243  $this->tpl->setContent($form->getHTML());
244  }
245  }
246 
247  public function frmPostObject(): void
248  {
249  $form = $this->initTagsForm(
250  "frm_post",
251  "saveFrmPostSettings",
252  "advanced_editing_frm_post_settings"
253  );
254 
255  $this->tpl->setContent($form->getHTML());
256  }
257 
258  public function saveFrmPostSettingsObject(): void
259  {
260  $form = $this->initTagsForm(
261  "frm_post",
262  "saveFrmPostSettings",
263  "advanced_editing_frm_post_settings"
264  );
265  if (!$this->saveTags("frm_post", "frmPost", $form)) {
266  $form->setValuesByPost();
267  $this->tpl->setContent($form->getHTML());
268  }
269  }
270 
271  protected function initTagsForm(
272  string $a_id,
273  string $a_cmd,
274  string $a_title
275  ): ilPropertyFormGUI {
276  $form = new ilPropertyFormGUI();
277  $form->setFormAction($this->ctrl->getFormAction($this, $a_cmd));
278  $form->setTitle($this->lng->txt($a_title));
279 
280  $alltags = $this->object->getHTMLTags();
281  $alltags = array_combine($alltags, $alltags);
282 
283  $tags = new ilMultiSelectInputGUI($this->lng->txt("advanced_editing_allow_html_tags"), "html_tags");
284  $tags->setHeight(400);
285  $tags->enableSelectAll(true);
286  $tags->enableSelectedFirst(true);
287  $tags->setOptions($alltags);
288  $tags->setValue(ilObjAdvancedEditing::_getUsedHTMLTags($a_id));
289  $form->addItem($tags);
290 
291  if ($this->access->checkAccess("write", "", $this->object->getRefId())) {
292  $form->addCommandButton($a_cmd, $this->lng->txt("save"));
293  }
294 
295  return $form;
296  }
297 
298  protected function saveTags(
299  string $a_id,
300  string $a_cmd,
301  ilPropertyFormGUI $form
302  ): bool {
303  $this->checkPermission("write");
304  try {
305  if ($form->checkInput()) {
306  $html_tags = $form->getInput("html_tags");
307  // get rid of select all
308  if (array_key_exists(0, $html_tags) && (string) $html_tags[0] === '') {
309  unset($html_tags[0]);
310  }
311  $this->object->setUsedHTMLTags((array) $html_tags, $a_id);
312  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
313  } else {
314  return false;
315  }
317  $this->tpl->setOnScreenMessage('info', $e->getMessage(), true);
318  }
319  $this->ctrl->redirect($this, $a_cmd);
320  return true;
321  }
322 
323  public function showPageEditorSettingsObject(): void
324  {
326 
328 
329  $this->cgrp = $this->std_request->getGroup();
330  if ($this->cgrp === "") {
331  $this->cgrp = (string) key($grps);
332  }
333 
334  $this->ctrl->setParameter($this, "grp", $this->cgrp);
335  $this->tabs_gui->setSubTabActive("adve_grp_" . $this->cgrp);
336 
337  $this->initPageEditorForm();
338  $this->tpl->setContent($this->form->getHTML());
339  }
340 
341  public function initPageEditorForm(): void
342  {
343  $this->lng->loadLanguageModule("content");
344 
345  $this->form = new ilPropertyFormGUI();
346 
347  if ($this->cgrp === "test") {
348  $this->form->setTitle($this->lng->txt("adve_activation"));
349  $cb = new ilCheckboxInputGUI($this->lng->txt("advanced_editing_tst_editing"), "tst_page_edit");
350  $cb->setInfo($this->lng->txt("advanced_editing_tst_editing_desc"));
352  $cb->setChecked(true);
353  }
354  $this->form->addItem($cb);
355 
356  $sh = new ilFormSectionHeaderGUI();
357  $sh->setTitle($this->lng->txt("adve_text_content_features"));
358  $this->form->addItem($sh);
359  } elseif ($this->cgrp === "rep") {
360  $this->form->setTitle($this->lng->txt("adve_activation"));
361  $cb = new ilCheckboxInputGUI($this->lng->txt("advanced_editing_rep_page_editing"), "cat_page_edit");
362  $cb->setInfo($this->lng->txt("advanced_editing_rep_page_editing_desc"));
363  if ($this->settings->get("enable_cat_page_edit")) {
364  $cb->setChecked(true);
365  }
366  $this->form->addItem($cb);
367 
368  $sh = new ilFormSectionHeaderGUI();
369  $sh->setTitle($this->lng->txt("adve_text_content_features"));
370  $this->form->addItem($sh);
371  } else {
372  $this->form->setTitle($this->lng->txt("adve_text_content_features"));
373  }
374 
375 
377  foreach ($buttons as $b => $t) {
378  // command button activation
379  $cb = new ilCheckboxInputGUI(str_replace(":", "", $this->lng->txt("cont_text_" . $b)), "active_" . $b);
380  $cb->setChecked((bool) ilPageEditorSettings::lookupSetting($this->cgrp, "active_" . $b, true));
381  $this->form->addItem($cb);
382  }
383 
384  // save and cancel commands
385  if ($this->checkPermissionBool("write")) {
386  $this->form->addCommandButton("savePageEditorSettings", $this->lng->txt("save"));
387  }
388 
389  $this->form->setFormAction($this->ctrl->getFormAction($this));
390  }
391 
392  public function savePageEditorSettingsObject(): void
393  {
394  $lng = $this->lng;
395  $ilCtrl = $this->ctrl;
397 
398  $this->checkPermission("write");
399 
400  $this->initPageEditorForm();
401  if ($this->form->checkInput()) {
403  foreach ($buttons as $b => $t) {
405  $this->std_request->getGroup(),
406  "active_" . $b,
407  $this->form->getInput("active_" . $b)
408  );
409  }
410 
411  if ($this->std_request->getGroup() === "test") {
412  $ilSetting->set("enable_tst_page_edit", (string) $this->form->getInput("tst_page_edit"));
413  } elseif ($this->std_request->getGroup() === "rep") {
414  $ilSetting->set("enable_cat_page_edit", (string) $this->form->getInput("cat_page_edit"));
415  }
416 
417  $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
418  }
419 
420  $ilCtrl->setParameter($this, "grp", $this->std_request->getGroup());
421  $ilCtrl->redirect($this, "showPageEditorSettings");
422  }
423 
424  public function showGeneralPageEditorSettingsObject(): void
425  {
427  $this->tabs_gui->activateTab("adve_page_editor_settings");
428 
429  $form = $this->initGeneralPageSettingsForm();
430  $this->tpl->setContent($form->getHTML());
431  }
432 
434  {
435  $form = new ilPropertyFormGUI();
436 
437  $aset = new ilSetting("adve");
438 
439  // use physical character styles
440  $cb = new ilCheckboxInputGUI($this->lng->txt("adve_use_physical"), "use_physical");
441  $cb->setInfo($this->lng->txt("adve_use_physical_info"));
442  $cb->setChecked((bool) $aset->get("use_physical"));
443  $form->addItem($cb);
444 
445  // blocking mode
446  $cb = new ilCheckboxInputGUI($this->lng->txt("adve_blocking_mode"), "block_mode_act");
447  $cb->setChecked((bool) $aset->get("block_mode_minutes") > 0);
448  $form->addItem($cb);
449 
450  // number of minutes
451  $ni = new ilNumberInputGUI($this->lng->txt("adve_minutes"), "block_mode_minutes");
452  $ni->setMinValue(2);
453  $ni->setMaxLength(5);
454  $ni->setSize(5);
455  $ni->setRequired(true);
456  $ni->setInfo($this->lng->txt("adve_minutes_info"));
457  $ni->setValue($aset->get("block_mode_minutes"));
458  $cb->addSubItem($ni);
459 
460  // autosave
461  $as = new ilNumberInputGUI($this->lng->txt("adve_autosave"), "autosave");
462  $as->setSuffix($this->lng->txt("seconds"));
463  $as->setMaxLength(5);
464  $as->setSize(5);
465  $as->setInfo($this->lng->txt("adve_autosave_info"));
466  $as->setValue($aset->get("autosave"));
467  $form->addItem($as);
468 
469  // auto url linking
470  $cb = new ilCheckboxInputGUI($this->lng->txt("adve_auto_url_linking"), "auto_url_linking");
471  $cb->setChecked((bool) $aset->get("auto_url_linking"));
472  $cb->setInfo($this->lng->txt("adve_auto_url_linking_info"));
473  $form->addItem($cb);
474 
475  if ($this->checkPermissionBool("write")) {
476  $form->addCommandButton("saveGeneralPageSettings", $this->lng->txt("save"));
477  }
478 
479  // workaround for glossaries to force rewriting of short texts
481 
482 
483  $form->setTitle($this->lng->txt("adve_pe_general"));
484  $form->setFormAction($this->ctrl->getFormAction($this));
485 
486  return $form;
487  }
488 
496  protected function getPageObjectKeysWithOptionalHTML(): array
497  {
498  return ["lobj","copa","mep","blp","prtf","prtt","term","lm","qht","qpl","qfbg","qfbs","sahs","stys","cont","cstr","auth"];
499  }
500 
501  public function saveGeneralPageSettingsObject(): void
502  {
503  $this->checkPermission("write");
504 
505  $form = $this->initGeneralPageSettingsForm();
506  if ($form->checkInput()) {
507  $autosave = (int) $form->getInput("autosave");
508  $ok = true;
509 
510  // autosave must be greater 10, if activated
511  if ($autosave > 0 && $autosave < 10) {
512  $form->getItemByPostVar("autosave")->setAlert($this->lng->txt("adve_autosave_info_min_10"));
513  $ok = false;
514  }
515 
516  if ($ok) {
517  $aset = new ilSetting("adve");
518  $aset->set("use_physical", $form->getInput("use_physical"));
519  if ($form->getInput("block_mode_act")) {
520  $aset->set("block_mode_minutes", (string) (int) $form->getInput("block_mode_minutes"));
521  } else {
522  $aset->set("block_mode_minutes", 0);
523  }
524  $aset->set("auto_url_linking", $form->getInput("auto_url_linking"));
525 
526  $aset->set("autosave", $form->getInput("autosave"));
527 
528  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
529  $this->ctrl->redirect($this, "showGeneralPageEditorSettings");
530  }
531  }
532 
533  $form->setValuesByPost();
534  $this->tpl->setContent($form->getHTML());
535  }
536 }
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)
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...
Refinery $refinery
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.
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.
setFormAction(string $a_formaction)
Class ilObjectGUI Basic methods of all Output classes.
ilComponentRepository $component_repository
global $DIC
Definition: shib_login.php:25
Class ilObjForumAdministration.
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="")
const ADDITIONAL_QUESTION_CONTENT_EDITING_MODE_PAGE_OBJECT_DISABLED
global $ilSetting
Definition: privfeed.php:32
__construct(Container $dic, ilPlugin $plugin)
initTagsForm(string $a_id, string $a_cmd, string $a_title)
Class ilObjAdvancedEditingGUI.
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.