ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjStyleSheetGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
31 {
36  protected ilHelpGUI $help;
38  public string $cmd_update;
39  public string $cmd_new_par;
40  public string $cmd_delete;
41  protected bool $enable_write = false;
42  protected string $super_type;
48 
49 
50  public function __construct(
51  $a_data,
52  int $a_id,
53  bool $a_call_by_reference
54  ) {
55  global $DIC;
56 
57  parent::__construct($a_data, $a_id, $a_call_by_reference, false);
58 
59  $this->service = $DIC->contentStyle()
60  ->internal();
61  $this->gui_service = $this->service->gui();
62  $this->help = $this->gui_service->help();
63  $this->lng->loadLanguageModule("style");
64  $this->ctrl->saveParameter($this, array("tag", "style_type", "temp_type"));
65  $this->style_request = $DIC->contentStyle()
66  ->internal()
67  ->gui()
68  ->standardRequest();
69 
70  $this->super_type = "";
71  if ($this->style_request->getStyleType() != "") {
73  $this->style_request->getStyleType()
74  );
75  }
76  $this->type = "sty";
77 
78  $ref_id = (is_object($this->object))
79  ? $this->object->getRefId()
80  : 0;
81  $style_id = (is_object($this->object))
82  ? $this->object->getId()
83  : 0;
84 
85  $this->access_manager = $this->service->domain()->access(
86  $ref_id,
87  $this->user->getId()
88  );
89  $this->characteristic_manager = $this->service->domain()->characteristic(
90  $style_id,
91  $this->access_manager
92  );
93  $this->color_manager = $this->service->domain()->color(
94  $style_id,
95  $this->access_manager
96  );
97  $this->image_manager = $this->service->domain()->image(
98  $style_id,
99  $this->access_manager
100  );
101  }
102 
106  public function enableWrite(bool $a_write): void
107  {
108  $this->access_manager->enableWrite($a_write);
109  }
110 
111  public function executeCommand(): void
112  {
113  $tabs = $this->gui_service->tabs();
114  $ctrl = $this->gui_service->ctrl();
115 
116  $next_class = $ctrl->getNextClass($this);
117  $cmd = $ctrl->getCmd("edit");
118 
119  // #9440/#9489: prepareOutput will fail if not set properly
120  if (!$this->object || $cmd == "create") {
121  $this->setCreationMode();
122  }
123 
124  switch ($next_class) {
125  case "ilexportgui":
126  $this->prepareOutput();
127  $exp_gui = new ilExportGUI($this);
128  $exp_gui->addFormat("xml");
129  $ctrl->forwardCommand($exp_gui);
130  break;
131 
132  case "ilstylecharacteristicgui":
133  $this->prepareOutput();
134  $this->includeCSS();
135  $tabs->activateTab("sty_style_chars");
136  $gui = $this->gui_service->characteristic()->ilStyleCharacteristicGUI(
137  $this->getStyleSheet(),
138  $this->super_type,
139  $this->access_manager,
140  $this->characteristic_manager,
141  $this->image_manager
142  );
143  $ctrl->forwardCommand($gui);
144  break;
145 
146  case "ilcontentstyleimagegui":
147  $this->prepareOutput();
148  $this->includeCSS();
149  $tabs->activateTab("sty_images");
150  $gui = $this->gui_service->image()->ilContentStyleImageGUI(
151  $this->access_manager,
152  $this->image_manager
153  );
154  $ctrl->forwardCommand($gui);
155  break;
156 
157  default:
158  $this->prepareOutput();
159  $cmd .= "Object";
160  $this->$cmd();
161  break;
162  }
163  }
164 
165  protected function getStyleSheet(): ilObjStyleSheet
166  {
168  $obj = $this->object;
169  return $obj;
170  }
171 
172  public function viewObject(): void
173  {
174  $this->editObject();
175  }
176 
177  public function createObject(): void
178  {
179  $tpl = $this->gui_service->ui()->mainTemplate();
180 
181  $ilHelp = $this->help;
182 
183  $forms = array();
184 
185 
186  $ilHelp->setScreenIdComponent("sty");
187  $ilHelp->setDefaultScreenId(ilHelpGUI::ID_PART_SCREEN, "create");
188 
189  $forms[] = $this->getCreateForm();
190  $forms[] = $this->getImportForm();
191  $forms[] = $this->getCloneForm();
192 
193  $tpl->setContent($this->getCreationFormsHTML($forms));
194  }
195 
196  protected function getCreateForm(): ilPropertyFormGUI
197  {
198  $ctrl = $this->ctrl;
199  $form = new ilPropertyFormGUI();
200  $form->setFormAction($ctrl->getFormAction($this));
201  $form->setTitle($this->lng->txt("sty_create_new_stylesheet"));
202 
203  // title
204  $ti = new ilTextInputGUI($this->lng->txt("title"), "style_title");
205  $ti->setMaxLength(128);
206  $ti->setSize(40);
207  $ti->setRequired(true);
208  $form->addItem($ti);
209 
210  // description
211  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "style_description");
212  $ta->setCols(40);
213  $ta->setRows(2);
214  $form->addItem($ta);
215 
216  $form->addCommandButton("save", $this->lng->txt("save"));
217  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
218  return $form;
219  }
220 
221  protected function getImportForm(): ilPropertyFormGUI
222  {
223  $ctrl = $this->ctrl;
224  $form = new ilPropertyFormGUI();
225  $form->setFormAction($ctrl->getFormAction($this));
226  $form->setTitle($this->lng->txt("sty_import_stylesheet"));
227 
228  // title
229  $ti = new ilFileInputGUI($this->lng->txt("import_file"), "importfile");
230  $ti->setRequired(true);
231  $form->addItem($ti);
232 
233  $form->addCommandButton("importStyle", $this->lng->txt("import"));
234  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
235  return $form;
236  }
237 
238  protected function getCloneForm(): ilPropertyFormGUI
239  {
240  $ctrl = $this->ctrl;
241  $form = new ilPropertyFormGUI();
242  $form->setFormAction($ctrl->getFormAction($this));
243  $form->setTitle($this->lng->txt("sty_copy_other_stylesheet"));
244 
245  // source
246  $ti = new ilSelectInputGUI($this->lng->txt("sty_source"), "source_style");
247  $ti->setRequired(true);
249  $form->addItem($ti);
250 
251  $form->addCommandButton("copyStyle", $this->lng->txt("copy"));
252  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
253  return $form;
254  }
255 
256  public function includeCSS(): void
257  {
258  $tpl = $this->gui_service->ui()->mainTemplate();
260  }
261 
262 
266  public function editObject(): void
267  {
268  $ctrl = $this->gui_service->ctrl();
269  $ctrl->redirectByClass("ilStyleCharacteristicGUI", "listCharacteristics");
270  }
271 
272  public function propertiesObject(): void
273  {
274  $tpl = $this->gui_service->ui()->mainTemplate();
276 
277  $this->initPropertiesForm();
278  $this->getPropertiesValues();
279  $tpl->setContent($this->form->getHTML());
280  }
281 
285  public function getPropertiesValues(): void
286  {
287  $values = array();
288 
289  $values["style_title"] = $this->object->getTitle();
290  $values["style_description"] = $this->object->getDescription();
291  $values["disable_auto_margins"] = (int) $this->object->lookupStyleSetting("disable_auto_margins");
292 
293  $this->form->setValuesByArray($values);
294  }
295 
299  public function initPropertiesForm(
300  string $a_mode = "edit"
301  ): void {
302  $ctrl = $this->gui_service->ctrl();
303  $lng = $this->lng;
304 
305  $this->form = new ilPropertyFormGUI();
306 
307  // title
308  $ti = new ilTextInputGUI($this->lng->txt("title"), "style_title");
309  $ti->setMaxLength(128);
310  $ti->setSize(40);
311  $ti->setRequired(true);
312  $this->form->addItem($ti);
313 
314  // description
315  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "style_description");
316  //$ta->setCols();
317  //$ta->setRows();
318  $this->form->addItem($ta);
319 
320  // disable automatic margins for left/right alignment
321  $cb = new ilCheckboxInputGUI($this->lng->txt("sty_disable_auto_margins"), "disable_auto_margins");
322  $cb->setInfo($this->lng->txt("sty_disable_auto_margins_info"));
323  $this->form->addItem($cb);
324 
325  // save and cancel commands
326 
327  if ($a_mode == "create") {
328  $this->form->addCommandButton("save", $lng->txt("save"));
329  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
330  } else {
331  if ($this->access_manager->checkWrite()) {
332  $this->form->addCommandButton("update", $lng->txt("save"));
333  }
334  }
335 
336  $this->form->setTitle($lng->txt("edit_stylesheet"));
337  $this->form->setFormAction($ctrl->getFormAction($this));
338  }
339 
340  public function updateObject(): void
341  {
342  $lng = $this->lng;
343  $ctrl = $this->gui_service->ctrl();
344  $tpl = $this->gui_service->ui()->mainTemplate();
345 
346  $this->initPropertiesForm("edit");
347  if ($this->form->checkInput()) {
348  $this->object->setTitle($this->form->getInput("style_title"));
349  $this->object->setDescription($this->form->getInput("style_description"));
350  $this->object->writeStyleSetting(
351  "disable_auto_margins",
352  $this->form->getInput("disable_auto_margins")
353  );
354  $this->object->update();
355  $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
356  $ctrl->redirect($this, "properties");
357  } else {
358  $this->form->setValuesByPost();
359  $tpl->setContent($this->form->getHTML());
360  }
361  }
362 
363 
364  public function exportStyleObject(): void
365  {
366  $exp = new ilExport();
367  $r = $exp->exportObject($this->object->getType(), $this->object->getId());
368 
369  ilFileDelivery::deliverFileLegacy($r["directory"] . "/" . $r["file"], $r["file"], '', false, true);
370  }
371 
375  public function deleteObject($a_error = false): void
376  {
377  $tpl = $this->gui_service->ui()->mainTemplate();
378  $ctrl = $this->gui_service->ctrl();
379 
380  // display confirmation message
381  $cgui = new ilConfirmationGUI();
382  $cgui->setFormAction($ctrl->getFormAction($this));
383  $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
384  $cgui->setCancel($this->lng->txt("cancel"), "cancelDelete");
385  $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDelete");
386 
387  $caption = ilObject::_lookupTitle($this->object->getId());
388 
389  $cgui->addItem("id[]", "", $caption);
390 
391  $tpl->setContent($cgui->getHTML());
392  }
393 
394  public function cancelDeleteObject(): void
395  {
396  $this->gui_service->ctrl()->returnToParent($this);
397  }
398 
402  public function confirmedDeleteObject(): void
403  {
404  $this->object->delete();
405  $this->gui_service->ctrl()->returnToParent($this);
406  }
407 
408  public function saveObject(): void
409  {
410  $ctrl = $this->gui_service->ctrl();
411 
412  $form = $this->getCreateForm();
413  $form->checkInput();
414 
415  if (!trim($form->getInput("style_title"))) {
416  $ctrl->redirect($this, "create");
417  }
418 
419  // copy from default style or ... see #11330
420  $default_style = $this->settings->get("default_content_style_id");
421  if (ilObject::_lookupType((int) $default_style) == "sty") {
422  $style_obj = ilObjectFactory::getInstanceByObjId((int) $default_style);
423  $new_id = $style_obj->ilClone();
424  $newObj = new ilObjStyleSheet($new_id);
425  } else {
426  // ... import from basic zip file
427  $imp = new ilImport();
428  $style_id = $imp->importObject(
429  null,
431  "style.zip",
432  "sty",
433  "Services/Style",
434  true
435  );
436 
437  $newObj = new ilObjStyleSheet($style_id);
438  }
439 
440  $newObj->setTitle($form->getInput("style_title"));
441  $newObj->setDescription($form->getInput("style_description"));
442  $newObj->update();
443  $this->object = $newObj;
444 
446 
447  // assign style to style sheet folder,
448  // if parent is style sheet folder
449  if ($this->requested_ref_id > 0) {
450  $fold = ilObjectFactory::getInstanceByRefId($this->requested_ref_id);
451  if ($fold->getType() == "stys") {
452  $cont_style_settings = new ilContentStyleSettings();
453  $cont_style_settings->addStyle($newObj->getId());
454  $cont_style_settings->update();
455 
456  ilObjStyleSheet::_writeStandard($newObj->getId(), true);
457  $this->tpl->setOnScreenMessage("success", $this->lng->txt("object_added"), true);
458  $this->ctrl->setParameterByClass(self::class, "obj_id", (string) $newObj->getId());
459  $this->ctrl->redirectByClass(self::class, "");
460  }
461  }
462  }
463 
464  public function copyStyleObject(): int
465  {
466  $ctrl = $this->gui_service->ctrl();
467 
468  $form = $this->getCloneForm();
469  $form->checkInput();
470  $new_id = 0;
471 
472  if ($form->getInput("source_style") > 0) {
473  $style_obj = ilObjectFactory::getInstanceByObjId((int) $form->getInput("source_style"));
474  $new_id = $style_obj->ilClone();
475  }
476 
477  // assign style to style sheet folder,
478  // if parent is style sheet folder
479  if ($this->requested_ref_id > 0) {
480  $fold = ilObjectFactory::getInstanceByRefId($this->requested_ref_id);
481  if ($fold->getType() == "stys") {
482  $cont_style_settings = new ilContentStyleSettings();
483  $cont_style_settings->addStyle($new_id);
484  $cont_style_settings->update();
485  ilObjStyleSheet::_writeStandard($new_id, true);
486  $ctrl->returnToParent($this);
487  }
488  }
489  $this->object = new ilObjStyleSheet($new_id);
490 
491  return $new_id;
492  }
493 
497  public function importStyleObject(): int
498  {
499  $newObj = null;
500  // check file
501  $source = $_FILES["importfile"]["tmp_name"];
502  if (($source == 'none') || (!$source)) {
503  $this->ilias->raiseError("No file selected!", $this->ilias->error_obj->MESSAGE);
504  }
505 
506  // check correct file type
507  $info = pathinfo($_FILES["importfile"]["name"]);
508  if (strtolower($info["extension"]) != "zip" && strtolower($info["extension"]) != "xml") {
509  $this->ilias->raiseError("File must be a zip or xml file!", $this->ilias->error_obj->MESSAGE);
510  }
511 
512  // new import
513  $fname = explode("_", $_FILES["importfile"]["name"]);
514  if (strtolower($info["extension"]) == "zip" && $fname[4] == "sty") {
515  $imp = new ilImport();
516  $new_id = $imp->importObject(
517  null,
518  $_FILES["importfile"]["tmp_name"],
519  $_FILES["importfile"]["name"],
520  "sty"
521  );
522  if ($new_id > 0) {
523  $newObj = ilObjectFactory::getInstanceByObjId($new_id);
524  }
525  } else { // old import
526  $newObj = new ilObjStyleSheet();
527  $newObj->import($_FILES["importfile"]);
528  }
529 
530  // assign style to style sheet folder,
531  // if parent is style sheet folder
532  if ($this->requested_ref_id > 0) {
533  $fold = ilObjectFactory::getInstanceByRefId($this->requested_ref_id);
534  if ($fold->getType() == "stys") {
535  $cont_style_settings = new ilContentStyleSettings();
536  $cont_style_settings->addStyle($newObj->getId());
537  $cont_style_settings->update();
538  ilObjStyleSheet::_writeStandard($newObj->getId(), true);
539  $this->ctrl->returnToParent($this);
540  }
541  }
542  $this->object = $newObj;
543  return $newObj->getId();
544  }
545 
546 
547  public function cancelObject(): void
548  {
549  $lng = $this->lng;
550 
551  $this->tpl->setOnScreenMessage('info', $lng->txt("msg_cancel"), true);
552  $this->ctrl->returnToParent($this);
553  }
554 
555  public function getAdminTabs(): void
556  {
557  $this->getTabs();
558  }
559 
560  protected function getTabs(): void
561  {
562  $lng = $this->lng;
563  $ilHelp = $this->help;
564  $tabs = $this->gui_service->tabs();
565  $ilHelp->setScreenIdComponent("sty");
566  // back to upper context
567  $tabs->setBackTarget(
568  $lng->txt("back"),
569  $this->ctrl->getLinkTarget($this, "returnToUpperContext")
570  );
571 
572  // style classes
573  $tabs->addTarget(
574  "sty_style_chars",
575  $this->ctrl->getLinkTarget($this, "edit"),
576  array("edit", ""),
577  get_class($this)
578  );
579 
580  // colors
581  $tabs->addTarget(
582  "sty_colors",
583  $this->ctrl->getLinkTarget($this, "listColors"),
584  "listColors",
585  get_class($this)
586  );
587 
588  // images
589  $tabs->addTarget(
590  "sty_images",
591  $this->ctrl->getLinkTargetByClass("ilContentStyleImageGUI", ""),
592  "",
593  "ilContentStyleImageGUI"
594  );
595 
596  // media queries
597  $tabs->addTarget(
598  "sty_media_queries",
599  $this->ctrl->getLinkTarget($this, "listMediaQueries"),
600  "listMediaQueries",
601  get_class($this)
602  );
603 
604 
605  // table templates
606  $tabs->addTarget(
607  "sty_templates",
608  $this->ctrl->getLinkTarget($this, "listTemplates"),
609  "listTemplates",
610  get_class($this)
611  );
612 
613  // settings
614  $tabs->addTarget(
615  "settings",
616  $this->ctrl->getLinkTarget($this, "properties"),
617  "properties",
618  get_class($this)
619  );
620 
621  // export
622  $tabs->addTarget(
623  "export",
624  $this->ctrl->getLinkTargetByClass("ilexportgui", ""),
625  "",
626  "ilexportgui"
627  );
628  }
629 
630  public function setTemplatesSubTabs(): void
631  {
632  $ilTabs = $this->gui_service->tabs();
633  $ilCtrl = $this->ctrl;
634 
636 
637  foreach ($types as $t => $c) {
638  $ilCtrl->setParameter($this, "temp_type", $t);
639  $ilTabs->addSubTabTarget(
640  "sty_" . $t . "_templates",
641  $this->ctrl->getLinkTarget($this, "listTemplates"),
642  array("listTemplates", ""),
643  get_class($this)
644  );
645  }
646 
647  $ilCtrl->setParameter($this, "temp_type", $this->style_request->getTempType());
648  }
649 
654  protected function addAdminLocatorItems(bool $do_not_add_object = false): void
655  {
656  $ilLocator = $this->gui_service->locator();
657 
658  if ($this->style_request->getAdminMode() == "settings") { // system settings
659  parent::addAdminLocatorItems(true);
660 
661  $ilLocator->addItem(
662  $this->lng->txt("obj_stys"),
663  $this->ctrl->getLinkTargetByClass("ilobjstylesettingsgui", "")
664  );
665 
666  $ilLocator->addItem(
667  $this->lng->txt("content_styles"),
668  $this->ctrl->getLinkTargetByClass("ilcontentstylesettingsgui", "")
669  );
670 
671  if ($this->style_request->getObjId() > 0) {
672  $ilLocator->addItem(
673  $this->object->getTitle(),
674  $this->ctrl->getLinkTarget($this, "edit")
675  );
676  }
677  }
678  }
679 
683  public static function getStyleExampleHTML(
684  string $a_type,
685  string $a_class
686  ): string {
687  global $DIC;
688 
689  $lng = $DIC->language();
690 
691  $c = explode(":", $a_class);
692  $a_class = $c[0];
693 
694  $ex_tpl = new ilTemplate("tpl.style_example.html", true, true, "Services/Style/Content");
695 
696  if ($ex_tpl->blockExists("Example_" . $a_type)) {
697  $ex_tpl->setCurrentBlock("Example_" . $a_type);
698  } else {
699  $ex_tpl->setCurrentBlock("Example_default");
700  }
701  $ex_tpl->setVariable("EX_CLASS", "ilc_" . $a_type . "_" . $a_class);
702  $ex_tpl->setVariable("EX_TEXT", "ABC abc 123");
703  if (in_array($a_type, array("media_cont", "qimg"))) {
704  //
705  }
706  if (in_array($a_type, array("table", "table_caption"))) {
707  $ex_tpl->setVariable("TXT_CAPTION", $lng->txt("sty_caption"));
708  }
709  if (in_array($a_class, array("OrderListItemHorizontal", "OrderListHorizontal"))) {
710  $ex_tpl->setVariable("HOR", "Horizontal");
711  }
712  $ex_tpl->parseCurrentBlock();
713 
714  return $ex_tpl->get();
715  }
716 
717 
718  //
719  // Color management
720  //
721 
725  public function listColorsObject(): void
726  {
727  $tpl = $this->gui_service->ui()->mainTemplate();
728  $ilToolbar = $this->gui_service->toolbar();
729  $ilCtrl = $this->ctrl;
730 
731  if ($this->access_manager->checkWrite()) {
732  $ilToolbar->addButton(
733  $this->lng->txt("sty_add_color"),
734  $ilCtrl->getLinkTarget($this, "addColor")
735  );
736  }
737 
738  $table_gui = new ilStyleColorTableGUI(
739  $this,
740  "listColors",
741  $this->getStyleSheet(),
742  $this->access_manager
743  );
744  $tpl->setContent($table_gui->getHTML());
745  }
746 
747  public function addColorObject(): void
748  {
749  $tpl = $this->gui_service->ui()->mainTemplate();
750 
751  $this->initColorForm();
752  $tpl->setContent($this->form_gui->getHTML());
753  }
754 
755  public function editColorObject(): void
756  {
757  $tpl = $this->gui_service->ui()->mainTemplate();
758  $ilCtrl = $this->ctrl;
759 
760  $ilCtrl->setParameter($this, "c_name", $this->style_request->getColorName());
761  $this->initColorForm("edit");
762  $this->getColorFormValues();
763  $tpl->setContent($this->form_gui->getHTML());
764  }
765 
766 
767  public function initColorForm(
768  string $a_mode = "create"
769  ): void {
770  $lng = $this->lng;
771  $ilCtrl = $this->ctrl;
772 
773  $this->form_gui = new ilPropertyFormGUI();
774 
775  $this->form_gui->setTitle($lng->txt("sty_add_color"));
776 
777  // name
778  $name_input = new ilRegExpInputGUI($lng->txt("sty_color_name"), "color_name");
779  $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
780  $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include") . " A-Z, a-z, 1-9");
781  $name_input->setRequired(true);
782  $name_input->setSize(15);
783  $name_input->setMaxLength(15);
784  $this->form_gui->addItem($name_input);
785 
786  // code
787  $color_input = new ilColorPickerInputGUI($lng->txt("sty_color_code"), "color_code");
788  $color_input->setRequired(true);
789  $color_input->setDefaultColor("");
790  $this->form_gui->addItem($color_input);
791 
792  if ($a_mode == "create") {
793  $this->form_gui->addCommandButton("saveColor", $lng->txt("save"));
794  } else {
795  $this->form_gui->addCommandButton("updateColor", $lng->txt("save"));
796  }
797  $this->form_gui->addCommandButton("cancelColorSaving", $lng->txt("cancel"));
798  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
799  }
800 
804  public function getColorFormValues(): void
805  {
806  $c_name = $this->style_request->getColorName();
807  if ($c_name != "") {
808  $values["color_name"] = $c_name;
809  $values["color_code"] = $this->object->getColorCodeForName($c_name);
810  $this->form_gui->setValuesByArray($values);
811  }
812  }
813 
817  public function cancelColorSavingObject(): void
818  {
819  $ilCtrl = $this->ctrl;
820 
821  $ilCtrl->redirect($this, "listColors");
822  }
823 
827  public function saveColorObject(): void
828  {
829  $tpl = $this->gui_service->ui()->mainTemplate();
830  $ilCtrl = $this->ctrl;
831  $lng = $this->lng;
832 
833  $this->initColorForm();
834  if ($this->form_gui->checkInput()) {
835  if ($this->color_manager->colorExists($this->form_gui->getInput("color_name"))) {
836  $col_input = $this->form_gui->getItemByPostVar("color_name");
837  $col_input->setAlert($lng->txt("sty_color_already_exists"));
838  } else {
839  $this->color_manager->addColor(
840  $this->form_gui->getInput("color_name"),
841  $this->form_gui->getInput("color_code")
842  );
843  $ilCtrl->redirect($this, "listColors");
844  }
845  }
846  $this->form_gui->setValuesByPost();
847  $tpl->setContent($this->form_gui->getHTML());
848  }
849 
853  public function updateColorObject(): void
854  {
855  $tpl = $this->gui_service->ui()->mainTemplate();
856  $ilCtrl = $this->ctrl;
857  $lng = $this->lng;
858 
859  $c_name = $this->style_request->getColorName();
860  $ilCtrl->setParameter($this, "c_name", $c_name);
861  $this->initColorForm("edit");
862 
863  if ($this->form_gui->checkInput()) {
864  if ($this->color_manager->colorExists($this->form_gui->getInput("color_name")) &&
865  $this->form_gui->getInput("color_name") != $c_name) {
866  $col_input = $this->form_gui->getItemByPostVar("color_name");
867  $col_input->setAlert($lng->txt("sty_color_already_exists"));
868  } else {
869  $this->color_manager->updateColor(
870  $c_name,
871  $this->form_gui->getInput("color_name"),
872  $this->form_gui->getInput("color_code")
873  );
874  $ilCtrl->redirect($this, "listColors");
875  }
876  }
877  $this->form_gui->setValuesByPost();
878  $tpl->setContent($this->form_gui->getHTML());
879  }
880 
884  public function deleteColorConfirmationObject(): void
885  {
886  $ilCtrl = $this->ctrl;
887  $tpl = $this->gui_service->ui()->mainTemplate();
888  $lng = $this->lng;
889 
890  $colors = $this->style_request->getColors();
891  if (count($colors) == 0) {
892  $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
893  $ilCtrl->redirect($this, "listColors");
894  } else {
895  $cgui = new ilConfirmationGUI();
896  $cgui->setFormAction($ilCtrl->getFormAction($this));
897  $cgui->setHeaderText($lng->txt("sty_confirm_color_deletion"));
898  $cgui->setCancel($lng->txt("cancel"), "cancelColorDeletion");
899  $cgui->setConfirm($lng->txt("delete"), "deleteColor");
900 
901  foreach ($colors as $c) {
902  $cgui->addItem("color[]", ilLegacyFormElementsUtil::prepareFormOutput($c), $c);
903  }
904 
905  $tpl->setContent($cgui->getHTML());
906  }
907  }
908 
912  public function cancelColorDeletionObject(): void
913  {
914  $ilCtrl = $this->ctrl;
915  $ilCtrl->redirect($this, "listColors");
916  }
917 
918  public function deleteColorObject(): void
919  {
920  $ilCtrl = $this->ctrl;
921 
922  $colors = $this->style_request->getColors();
923  foreach ($colors as $c) {
924  $this->object->removeColor($c);
925  }
926 
927  $ilCtrl->redirect($this, "listColors");
928  }
929 
930  //
931  // Media query management
932  //
933 
934  public function listMediaQueriesObject(): void
935  {
936  $tpl = $this->gui_service->ui()->mainTemplate();
937  $ilToolbar = $this->gui_service->toolbar();
938  $ilCtrl = $this->ctrl;
939 
940  if ($this->access_manager->checkWrite()) {
941  $ilToolbar->addButton(
942  $this->lng->txt("sty_add_media_query"),
943  $ilCtrl->getLinkTarget($this, "addMediaQuery")
944  );
945  }
946 
947  $table_gui = new ilStyleMediaQueryTableGUI(
948  $this,
949  "listMediaQueries",
950  $this->getStyleSheet(),
951  $this->access_manager
952  );
953  $tpl->setContent($table_gui->getHTML());
954  }
955 
956  public function addMediaQueryObject(): void
957  {
958  $tpl = $this->gui_service->ui()->mainTemplate();
959 
960  $this->initMediaQueryForm();
961  $tpl->setContent($this->form_gui->getHTML());
962  }
963 
964  public function editMediaQueryObject(): void
965  {
966  $tpl = $this->gui_service->ui()->mainTemplate();
967  $ilCtrl = $this->ctrl;
968 
969  $ilCtrl->setParameter($this, "mq_id", $this->style_request->getMediaQueryId());
970  $this->initMediaQueryForm("edit");
971  $this->getMediaQueryFormValues();
972  $tpl->setContent($this->form_gui->getHTML());
973  }
974 
975 
979  public function initMediaQueryForm(
980  string $a_mode = "create"
981  ): void {
982  $lng = $this->lng;
983  $ilCtrl = $this->ctrl;
984 
985  $this->form_gui = new ilPropertyFormGUI();
986 
987  $this->form_gui->setTitle($lng->txt("sty_add_media_query"));
988 
989  // media query
990  $ti = new ilTextInputGUI("@media", "mquery");
991  $ti->setMaxLength(2000);
992  $ti->setInfo($lng->txt("sty_add_media_query_info"));
993  $this->form_gui->addItem($ti);
994 
995 
996  if ($a_mode == "create") {
997  $this->form_gui->addCommandButton("saveMediaQuery", $lng->txt("save"));
998  } else {
999  $this->form_gui->addCommandButton("updateMediaQuery", $lng->txt("save"));
1000  }
1001  $this->form_gui->addCommandButton("listMediaQueries", $lng->txt("cancel"));
1002  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1003  }
1004 
1008  public function getMediaQueryFormValues(): void
1009  {
1010  $values = [];
1011  if ($this->style_request->getMediaQueryId() > 0) {
1012  foreach ($this->object->getMediaQueries() as $mq) {
1013  if ($mq["id"] == $this->style_request->getMediaQueryId()) {
1014  $values["mquery"] = $mq["mquery"];
1015  }
1016  }
1017  $this->form_gui->setValuesByArray($values);
1018  }
1019  }
1020 
1024  public function saveMediaQueryObject(): void
1025  {
1026  $tpl = $this->gui_service->ui()->mainTemplate();
1027  $ilCtrl = $this->ctrl;
1028  $lng = $this->lng;
1029 
1030  $this->initMediaQueryForm();
1031 
1032  if ($this->form_gui->checkInput()) {
1033  $this->object->addMediaQuery($this->form_gui->getInput("mquery"));
1034  $ilCtrl->redirect($this, "listMediaQueries");
1035  }
1036  $this->form_gui->setValuesByPost();
1037  $tpl->setContent($this->form_gui->getHTML());
1038  }
1039 
1040  public function updateMediaQueryObject(): void
1041  {
1042  $tpl = $this->gui_service->ui()->mainTemplate();
1043  $ilCtrl = $this->ctrl;
1044 
1045  $this->initMediaQueryForm("edit");
1046 
1047  if ($this->form_gui->checkInput()) {
1048  $this->object->updateMediaQuery(
1049  $this->style_request->getMediaQueryId(),
1050  $this->form_gui->getInput("mquery")
1051  );
1052  $ilCtrl->redirect($this, "listMediaQueries");
1053  }
1054  $ilCtrl->setParameter($this, "mq_id", $this->style_request->getMediaQueryId());
1055  $this->form_gui->setValuesByPost();
1056  $tpl->setContent($this->form_gui->getHTML());
1057  }
1058 
1059  public function deleteMediaQueryConfirmationObject(): void
1060  {
1061  $ilCtrl = $this->ctrl;
1062  $tpl = $this->gui_service->ui()->mainTemplate();
1063  $lng = $this->lng;
1064 
1065  $mq_ids = $this->style_request->getMediaQueryIds();
1066  if (count($mq_ids) == 0) {
1067  $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
1068  $ilCtrl->redirect($this, "listMediaQueries");
1069  } else {
1070  $cgui = new ilConfirmationGUI();
1071  $cgui->setFormAction($ilCtrl->getFormAction($this));
1072  $cgui->setHeaderText($lng->txt("sty_sure_del_mqueries"));
1073  $cgui->setCancel($lng->txt("cancel"), "listMediaQueries");
1074  $cgui->setConfirm($lng->txt("delete"), "deleteMediaQueries");
1075 
1076  foreach ($mq_ids as $i) {
1077  $mq = $this->object->getMediaQueryForId($i);
1078  $cgui->addItem("mq_id[]", (string) $i, $mq["mquery"]);
1079  }
1080 
1081  $tpl->setContent($cgui->getHTML());
1082  }
1083  }
1084 
1085  public function deleteMediaQueriesObject(): void
1086  {
1087  $ilCtrl = $this->ctrl;
1088 
1089  $mq_ids = $this->style_request->getMediaQueryIds();
1090  if ($this->access_manager->checkWrite()) {
1091  foreach ($mq_ids as $id) {
1092  $this->object->deleteMediaQuery($id);
1093  }
1094  }
1095  $ilCtrl->redirect($this, "listMediaQueries");
1096  }
1097 
1098  public function saveMediaQueryOrderObject(): void
1099  {
1100  $ilCtrl = $this->ctrl;
1101 
1102  $order = $this->style_request->getOrder();
1103  if (count($order) > 0) {
1104  $this->getStyleSheet()->saveMediaQueryOrder($order);
1105  }
1106  $ilCtrl->redirect($this, "listMediaQueries");
1107  }
1108 
1109 
1110  //
1111  // Templates management
1112  //
1113 
1117  public function listTemplatesObject(): void
1118  {
1119  $tpl = $this->gui_service->ui()->mainTemplate();
1120  $ilTabs = $this->gui_service->tabs();
1121  $ilCtrl = $this->ctrl;
1122  $ilToolbar = $this->gui_service->toolbar();
1123 
1124  $ctype = $this->style_request->getTempType();
1125  if ($ctype == "") {
1126  $ctype = "table";
1127  }
1128 
1129  $this->setTemplatesSubTabs();
1130  $ilCtrl->setParameter($this, "temp_type", $ctype);
1131  $ilTabs->setSubTabActive("sty_" . $ctype . "_templates");
1132 
1133  // action commands
1134  if ($this->access_manager->checkWrite()) {
1135  if ($ctype == "table") {
1136  $ilToolbar->addButton(
1137  $this->lng->txt("sty_generate_template"),
1138  $ilCtrl->getLinkTarget($this, "generateTemplate")
1139  );
1140  }
1141  $ilToolbar->addButton(
1142  $this->lng->txt("sty_add_template"),
1143  $ilCtrl->getLinkTarget($this, "addTemplate")
1144  );
1145  }
1146 
1147 
1148 
1149  $this->includeCSS();
1150  $table_gui = new ilTableTemplatesTableGUI(
1151  $ctype,
1152  $this,
1153  "listTemplates",
1154  $this->getStyleSheet(),
1155  $this->access_manager
1156  );
1157  $tpl->setContent($table_gui->getHTML());
1158  }
1159 
1160  public function addTemplateObject(): void
1161  {
1162  $tpl = $this->gui_service->ui()->mainTemplate();
1163 
1164  $this->initTemplateForm();
1165  $tpl->setContent($this->form_gui->getHTML());
1166  }
1167 
1168  public function editTemplateObject(): void
1169  {
1170  $ilCtrl = $this->ctrl;
1171 
1172  $ilCtrl->setParameter(
1173  $this,
1174  "t_id",
1175  $this->style_request->getTemplateId()
1176  );
1177  $this->initTemplateForm("edit");
1178  $this->getTemplateFormValues();
1179 
1180  $this->displayTemplateEditForm();
1181  }
1182 
1183  public function getTemplatePreview(
1184  string $a_type,
1185  int $a_t_id,
1186  bool $a_small_mode = false
1187  ): string {
1188  return $this->_getTemplatePreview(
1189  $this->getStyleSheet(),
1190  $a_type,
1191  $a_t_id,
1192  $a_small_mode
1193  );
1194  }
1195 
1199  public static function _getTemplatePreview(
1200  ilObjStyleSheet $a_style,
1201  string $a_type,
1202  int $a_t_id,
1203  bool $a_small_mode = false
1204  ): string {
1205  global $DIC;
1206 
1207  $lng = $DIC->language();
1208  $p_content = "";
1209 
1210  $kr = $kc = 7;
1211  if ($a_small_mode) {
1212  $kr = 6;
1213  $kc = 5;
1214  }
1215 
1216  $ts = $a_style->getTemplate($a_t_id);
1217  $t = $ts["classes"];
1218 
1219  // preview
1220  if ($a_type == "table") {
1221  $p_content = '<PageContent><Table DataTable="y"';
1222  $t["row_head"] = $t["row_head"] ?? "";
1223  $t["row_foot"] = $t["row_foot"] ?? "";
1224  $t["col_head"] = $t["col_head"] ?? "";
1225  $t["col_foot"] = $t["col_foot"] ?? "";
1226  if ($t["row_head"] != "") {
1227  $p_content .= ' HeaderRows="1"';
1228  }
1229  if ($t["row_foot"] != "") {
1230  $p_content .= ' FooterRows="1"';
1231  }
1232  if ($t["col_head"] != "") {
1233  $p_content .= ' HeaderCols="1"';
1234  }
1235  if ($t["col_foot"] != "") {
1236  $p_content .= ' FooterCols="1"';
1237  }
1238  $p_content .= ' Template="' . $a_style->lookupTemplateName($a_t_id) . '">';
1239  if (!$a_small_mode) {
1240  $p_content .= '<Caption>' . $lng->txt("sty_caption") . '</Caption>';
1241  }
1242  for ($i = 1; $i <= $kr; $i++) {
1243  $p_content .= '<TableRow>';
1244  for ($j = 1; $j <= $kc; $j++) {
1245  if ($a_small_mode) {
1246  $cell = '&lt;div style="height:2px;"&gt;&lt;/div&gt;';
1247  } else {
1248  $cell = 'xxx';
1249  }
1250  $p_content .= '<TableData><PageContent><Paragraph Characteristic="TableContent">' . $cell . '</Paragraph></PageContent></TableData>';
1251  }
1252  $p_content .= '</TableRow>';
1253  }
1254  $p_content .= '</Table></PageContent>';
1255  }
1256 
1257  if ($a_type == "vaccordion" || $a_type == "haccordion" || $a_type == "carousel") {
1259 
1260  if ($a_small_mode) {
1261  $c = '&amp;nbsp;';
1262  $h = '&amp;nbsp;';
1263  } else {
1264  $c = 'xxx';
1265  $h = 'head';
1266  }
1267  if ($a_type == "vaccordion") {
1268  $p_content = '<PageContent><Tabs HorizontalAlign="Left" Type="VerticalAccordion" ';
1269  if ($a_small_mode) {
1270  $p_content .= ' ContentWidth="70"';
1271  }
1272  } elseif ($a_type == "haccordion") {
1273  $p_content = '<PageContent><Tabs Type="HorizontalAccordion"';
1274  $p_content .= ' ContentHeight="40"';
1275  if ($a_small_mode) {
1276  $p_content .= ' ContentWidth="70"';
1277  $c = '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;';
1278  }
1279  } elseif ($a_type == "carousel") {
1280  $p_content = '<PageContent><Tabs HorizontalAlign="Left" Type="Carousel" ';
1281  if ($a_small_mode) {
1282  $p_content .= ' ContentWidth="70"';
1283  }
1284  }
1285 
1286 
1287  $p_content .= ' Template="' . $a_style->lookupTemplateName($a_t_id) . '">';
1288  $p_content .= '<Tab><PageContent><Paragraph>' . $c . '</Paragraph></PageContent>';
1289  $p_content .= '<TabCaption>' . $h . '</TabCaption>';
1290  $p_content .= '</Tab>';
1291  $p_content .= '</Tabs></PageContent>';
1292  }
1293  //echo htmlentities($p_content);
1294  $txml = $a_style->getTemplateXML();
1295  //echo htmlentities($txml); exit;
1296  $p_content .= $txml;
1297  $r_content = ilPCTableGUI::_renderTable($p_content, "");
1298 
1299  // fix carousel template visibility
1300  if ($a_type == "carousel") {
1301  $r_content .= "<style>.owl-carousel{ display:block !important; }</style>";
1302  }
1303 
1304  //echo htmlentities($r_content); exit;
1305  return $r_content;
1306  }
1307 
1311  public function initTemplateForm(string $a_mode = "create"): void
1312  {
1313  $lng = $this->lng;
1314  $ilCtrl = $this->ctrl;
1315 
1316  $this->form_gui = new ilPropertyFormGUI();
1317 
1318  if ($a_mode == "create") {
1319  $this->form_gui->setTitle($lng->txt("sty_add_template"));
1320  } else {
1321  $this->form_gui->setTitle($lng->txt("sty_edit_template"));
1322  }
1323 
1324  // name
1325  $name_input = new ilRegExpInputGUI($lng->txt("sty_template_name"), "name");
1326  $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
1327  $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include") . " A-Z, a-z, 1-9");
1328  $name_input->setRequired(true);
1329  $name_input->setSize(30);
1330  $name_input->setMaxLength(30);
1331  $this->form_gui->addItem($name_input);
1332 
1333  // template style classes
1335  $this->style_request->getTempType()
1336  );
1337 
1338  foreach ($scs as $sc => $st) {
1339  $sc_input = new ilSelectInputGUI($lng->txt("sty_" . $sc . "_class"), $sc . "_class");
1340  $chars = $this->object->getCharacteristics($st);
1341  $options = array("" => "");
1342  foreach ($chars as $char) {
1343  $options[$char] = $char;
1344  }
1345  $sc_input->setOptions($options);
1346  $this->form_gui->addItem($sc_input);
1347  }
1348 
1349  if ($a_mode == "create") {
1350  $this->form_gui->addCommandButton("saveTemplate", $lng->txt("save"));
1351  } else {
1352  $this->form_gui->addCommandButton("refreshTemplate", $lng->txt("save_refresh"));
1353  $this->form_gui->addCommandButton("updateTemplate", $lng->txt("save_return"));
1354  }
1355  $this->form_gui->addCommandButton("cancelTemplateSaving", $lng->txt("cancel"));
1356  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1357  }
1358 
1362  public function cancelTemplateSavingObject(): void
1363  {
1364  $ilCtrl = $this->ctrl;
1365  $ilCtrl->redirect($this, "listTemplates");
1366  }
1367 
1368 
1372  public function saveTemplateObject(): void
1373  {
1374  $tpl = $this->gui_service->ui()->mainTemplate();
1375  $ilCtrl = $this->ctrl;
1376  $lng = $this->lng;
1377 
1378  $this->initTemplateForm();
1379  $temp_type = $this->style_request->getTempType();
1380 
1381  if ($this->form_gui->checkInput()) {
1382  if ($this->object->templateExists($this->form_gui->getInput("name"))) {
1383  $name_input = $this->form_gui->getItemByPostVar("name");
1384  $name_input->setAlert($lng->txt("sty_table_template_already_exists"));
1385  } else {
1386  $classes = array();
1387  foreach (ilObjStyleSheet::_getTemplateClassTypes($temp_type) as $tct => $ct) {
1388  $classes[$tct] = $this->form_gui->getInput($tct . "_class");
1389  }
1390  $t_id = $this->object->addTemplate(
1391  $temp_type,
1392  $this->form_gui->getInput("name"),
1393  $classes
1394  );
1395  $this->object->writeTemplatePreview(
1396  $t_id,
1397  $this->getTemplatePreview($temp_type, $t_id, true)
1398  );
1399  $ilCtrl->redirect($this, "listTemplates");
1400  }
1401  }
1402  $this->form_gui->setValuesByPost();
1403  $tpl->setContent($this->form_gui->getHTML());
1404  }
1405 
1406  public function updateTemplateObject(
1407  bool $a_refresh = false
1408  ): void {
1409  $ilCtrl = $this->ctrl;
1410  $lng = $this->lng;
1411 
1412  $ilCtrl->setParameter($this, "t_id", $this->style_request->getTemplateId());
1413  $this->initTemplateForm("edit");
1414  $temp_type = $this->style_request->getTempType();
1415 
1416  $t_id = $this->style_request->getTemplateId();
1417  if ($this->form_gui->checkInput()) {
1418  if ($this->object->templateExists($this->form_gui->getInput("name")) &&
1419  $this->form_gui->getInput("name") != ilObjStyleSheet::_lookupTemplateName($t_id)) {
1420  $name_input = $this->form_gui->getItemByPostVar("name");
1421  $name_input->setAlert($lng->txt("sty_template_already_exists"));
1422  } else {
1423  $classes = array();
1424  foreach (ilObjStyleSheet::_getTemplateClassTypes($temp_type) as $tct => $ct) {
1425  $classes[$tct] = $this->form_gui->getInput($tct . "_class");
1426  }
1427 
1428  $this->object->updateTemplate(
1429  $t_id,
1430  $this->form_gui->getInput("name"),
1431  $classes
1432  );
1433  $this->object->writeTemplatePreview(
1434  $t_id,
1435  $this->getTemplatePreview($temp_type, $t_id, true)
1436  );
1437  if (!$a_refresh) {
1438  $ilCtrl->redirect($this, "listTemplates");
1439  }
1440  }
1441  }
1442 
1443  $this->form_gui->setValuesByPost();
1444  $this->displayTemplateEditForm();
1445  }
1446 
1447  public function displayTemplateEditForm(): void
1448  {
1449  $tpl = $this->gui_service->ui()->mainTemplate();
1450 
1451  $a_tpl = new ilTemplate(
1452  "tpl.template_edit.html",
1453  true,
1454  true,
1455  "Services/Style/Content"
1456  );
1457  $this->includeCSS();
1458  $a_tpl->setVariable("FORM", $this->form_gui->getHTML());
1459  $a_tpl->setVariable("PREVIEW", $this->getTemplatePreview(
1460  $this->style_request->getTempType(),
1461  $this->style_request->getTemplateId()
1462  ));
1463  $tpl->setContent($a_tpl->get());
1464  }
1465 
1469  public function refreshTemplateObject(): void
1470  {
1471  $this->updateTemplateObject(true);
1472  }
1473 
1477  public function getTemplateFormValues(): void
1478  {
1479  $t_id = $this->style_request->getTemplateId();
1480  if ($t_id > 0) {
1481  $t = $this->object->getTemplate($t_id);
1482 
1483  $values["name"] = $t["name"];
1485  $this->style_request->getTempType()
1486  );
1487  foreach ($scs as $k => $type) {
1488  $values[$k . "_class"] = $t["classes"][$k] ?? "";
1489  }
1490  $this->form_gui->setValuesByArray($values);
1491  }
1492  }
1493 
1497  public function deleteTemplateConfirmationObject(): void
1498  {
1499  $ilCtrl = $this->ctrl;
1500  $tpl = $this->gui_service->ui()->mainTemplate();
1501  $lng = $this->lng;
1502 
1503  $tids = $this->style_request->getTemplateIds();
1504  if (count($tids) == 0) {
1505  $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
1506  $ilCtrl->redirect($this, "listTemplates");
1507  } else {
1508  $cgui = new ilConfirmationGUI();
1509  $cgui->setFormAction($ilCtrl->getFormAction($this));
1510  $cgui->setHeaderText($lng->txt("sty_confirm_template_deletion"));
1511  $cgui->setCancel($lng->txt("cancel"), "cancelTemplateDeletion");
1512  $cgui->setConfirm($lng->txt("sty_del_template"), "deleteTemplate");
1513 
1514  foreach ($tids as $tid) {
1515  $classes = $this->object->getTemplateClasses($tid);
1516  $cl_str = "";
1517  $listed = array();
1518  foreach ($classes as $cl) {
1519  if ($cl != "" && !($listed[$cl] ?? false)) {
1520  $cl_str .= '<div>- ' .
1521  $cl . "</div>";
1522  $listed[$cl] = true;
1523  }
1524  }
1525  if ($cl_str != "") {
1526  $cl_str = '<div style="padding-left:30px;" class="small">' .
1527  "<div><i>" . $lng->txt("sty_style_class") . "</i></div>" . $cl_str . "</div>";
1528  }
1529  $cgui->addItem("tid[]", (string) $tid, $this->object->lookupTemplateName($tid) . $cl_str);
1530  }
1531 
1532  $cgui->addButton($lng->txt("sty_del_template_keep_classes"), "deleteTemplateKeepClasses");
1533 
1534  $tpl->setContent($cgui->getHTML());
1535  }
1536  }
1537 
1541  public function cancelTemplateDeletionObject(): void
1542  {
1543  $ilCtrl = $this->ctrl;
1544 
1545  $ilCtrl->redirect($this, "listTemplates");
1546  }
1547 
1548  public function deleteTemplateKeepClassesObject(): void
1549  {
1550  $ilCtrl = $this->ctrl;
1551 
1552  $tids = $this->style_request->getTemplateIds();
1553  foreach ($tids as $tid) {
1554  $this->object->removeTemplate($tid);
1555  }
1556 
1557  $ilCtrl->redirect($this, "listTemplates");
1558  }
1559 
1566  public function deleteTemplateObject(): void
1567  {
1568  $ilCtrl = $this->ctrl;
1569 
1570  $tids = $this->style_request->getTemplateIds();
1571  foreach ($tids as $tid) {
1572  $cls = $this->object->getTemplateClasses($tid);
1573  foreach ($cls as $k => $cls2) {
1574  $ty = $this->object->determineTemplateStyleClassType(
1575  $this->style_request->getTempType(),
1576  $k
1577  );
1578  $this->characteristic_manager->deleteCharacteristic($ty, $cls2);
1579  }
1580  $this->object->removeTemplate($tid);
1581  }
1582 
1583  $ilCtrl->redirect($this, "listTemplates");
1584  }
1585 
1586  public function generateTemplateObject(): void
1587  {
1588  $tpl = $this->gui_service->ui()->mainTemplate();
1589 
1590  $this->initTemplateGenerationForm();
1591  $tpl->setContent($this->form_gui->getHTML());
1592  }
1593 
1597  public function initTemplateGenerationForm(): void
1598  {
1599  $lng = $this->lng;
1600  $ilCtrl = $this->ctrl;
1601 
1602  $this->form_gui = new ilPropertyFormGUI();
1603 
1604  $this->form_gui->setTitle($lng->txt("sty_generate_template"));
1605 
1606  // name
1607  $name_input = new ilRegExpInputGUI($lng->txt("sty_template_name"), "name");
1608  $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
1609  $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include") . " A-Z, a-z, 1-9");
1610  $name_input->setRequired(true);
1611  $name_input->setSize(30);
1612  $name_input->setMaxLength(30);
1613  $this->form_gui->addItem($name_input);
1614 
1615  // basic layout
1616  $bl_input = new ilSelectInputGUI($lng->txt("sty_template_layout"), "layout");
1617  $options = array(
1618  "coloredZebra" => $lng->txt("sty_table_template_colored_zebra"),
1619  "bwZebra" => $lng->txt("sty_table_template_bw_zebra"),
1620  "noZebra" => $lng->txt("sty_table_template_no_zebra")
1621  );
1622  $bl_input->setOptions($options);
1623  $this->form_gui->addItem($bl_input);
1624 
1625  // top bottom padding
1626  $num_input = new ilNumericStyleValueInputGUI($lng->txt("sty_top_bottom_padding"), "tb_padding");
1627  $num_input->setAllowPercentage(false);
1628  $num_input->setValue("3px");
1629  $this->form_gui->addItem($num_input);
1630 
1631  // left right padding
1632  $num_input = new ilNumericStyleValueInputGUI($lng->txt("sty_left_right_padding"), "lr_padding");
1633  $num_input->setAllowPercentage(false);
1634  $num_input->setValue("10px");
1635  $this->form_gui->addItem($num_input);
1636 
1637  // base color
1638  $bc_input = new ilSelectInputGUI($lng->txt("sty_base_color"), "base_color");
1639  $cs = $this->object->getColors();
1640  $options = array();
1641  foreach ($cs as $c) {
1642  $options[$c["name"]] = $c["name"];
1643  }
1644  $bc_input->setOptions($options);
1645  $this->form_gui->addItem($bc_input);
1646 
1647  // Lightness Settings
1648  $lss = array("border" => 90, "header_text" => 70, "header_bg" => 0,
1649  "cell1_text" => -60, "cell1_bg" => 90, "cell2_text" => -60, "cell2_bg" => 75);
1650  foreach ($lss as $ls => $v) {
1651  $l_input = new ilNumberInputGUI($lng->txt("sty_lightness_" . $ls), "lightness_" . $ls);
1652  $l_input->setMaxValue(100);
1653  $l_input->setMinValue(-100);
1654  $l_input->setValue((string) $v);
1655  $l_input->setSize(4);
1656  $l_input->setMaxLength(4);
1657  $this->form_gui->addItem($l_input);
1658  }
1659 
1660  $this->form_gui->addCommandButton("templateGeneration", $lng->txt("generate"));
1661  $this->form_gui->addCommandButton("cancelTemplateSaving", $lng->txt("cancel"));
1662  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1663  }
1664 
1668  public function templateGenerationObject(): void
1669  {
1670  $tpl = $this->gui_service->ui()->mainTemplate();
1671  $ilCtrl = $this->ctrl;
1672  $lng = $this->lng;
1673 
1674  $this->initTemplateGenerationForm();
1675 
1676  if ($this->form_gui->checkInput()) {
1677  if ($this->object->templateExists($this->form_gui->getInput("name"))) {
1678  $name_input = $this->form_gui->getItemByPostVar("name");
1679  $name_input->setAlert($lng->txt("sty_table_template_already_exists"));
1680  } else {
1681  // -> move to application class!
1682 
1683  // cell classes
1684  $cells = array("H" => "header", "C1" => "cell1", "C2" => "cell2");
1685  $tb_p = $this->form_gui->getItemByPostVar("tb_padding");
1686  $tb_padding = $tb_p->getValue();
1687  $lr_p = $this->form_gui->getItemByPostVar("lr_padding");
1688  $lr_padding = $lr_p->getValue();
1689  $cell_color = $this->form_gui->getInput("base_color");
1690 
1691  // use mid gray as cell color for bw zebra
1692  if ($this->form_gui->getInput("layout") == "bwZebra") {
1693  $cell_color = "MidGray";
1694  if (!$this->color_manager->colorExists($cell_color)) {
1695  $this->color_manager->addColor($cell_color, "7F7F7F");
1696  }
1697  $this->color_manager->updateColor($cell_color, $cell_color, "7F7F7F");
1698  }
1699 
1700  foreach ($cells as $k => $cell) {
1701  $cell_class[$k] = $this->form_gui->getInput("name") . $k;
1702  if (!$this->object->characteristicExists($cell_class[$k], "table_cell")) {
1703  $this->characteristic_manager->addCharacteristic("table_cell", $cell_class[$k], true);
1704  }
1705  if ($this->form_gui->getInput("layout") == "bwZebra" && $k == "H") {
1706  $this->characteristic_manager->replaceParameter(
1707  "td",
1708  $cell_class[$k],
1709  "color",
1710  "!" . $this->form_gui->getInput("base_color") . "(" . $this->form_gui->getInput("lightness_" . $cell . "_text") . ")",
1711  "table_cell"
1712  );
1713  $this->characteristic_manager->replaceParameter(
1714  "td",
1715  $cell_class[$k],
1716  "background-color",
1717  "!" . $this->form_gui->getInput("base_color") . "(" . $this->form_gui->getInput("lightness_" . $cell . "_bg") . ")",
1718  "table_cell"
1719  );
1720  } else {
1721  $this->characteristic_manager->replaceParameter(
1722  "td",
1723  $cell_class[$k],
1724  "color",
1725  "!" . $cell_color . "(" . $this->form_gui->getInput("lightness_" . $cell . "_text") . ")",
1726  "table_cell"
1727  );
1728  $this->characteristic_manager->replaceParameter(
1729  "td",
1730  $cell_class[$k],
1731  "background-color",
1732  "!" . $cell_color . "(" . $this->form_gui->getInput("lightness_" . $cell . "_bg") . ")",
1733  "table_cell"
1734  );
1735  }
1736  $this->characteristic_manager->replaceParameter(
1737  "td",
1738  $cell_class[$k],
1739  "padding-top",
1740  $tb_padding,
1741  "table_cell"
1742  );
1743  $this->characteristic_manager->replaceParameter(
1744  "td",
1745  $cell_class[$k],
1746  "padding-bottom",
1747  $tb_padding,
1748  "table_cell"
1749  );
1750  $this->characteristic_manager->replaceParameter(
1751  "td",
1752  $cell_class[$k],
1753  "padding-left",
1754  $lr_padding,
1755  "table_cell"
1756  );
1757  $this->characteristic_manager->replaceParameter(
1758  "td",
1759  $cell_class[$k],
1760  "padding-right",
1761  $lr_padding,
1762  "table_cell"
1763  );
1764  $this->characteristic_manager->replaceParameter(
1765  "td",
1766  $cell_class[$k],
1767  "border-width",
1768  "1px",
1769  "table_cell"
1770  );
1771  $this->characteristic_manager->replaceParameter(
1772  "td",
1773  $cell_class[$k],
1774  "border-style",
1775  "solid",
1776  "table_cell"
1777  );
1778  $this->characteristic_manager->replaceParameter(
1779  "td",
1780  $cell_class[$k],
1781  "border-color",
1782  "!" . $cell_color . "(" . $this->form_gui->getInput("lightness_border") . ")",
1783  "table_cell"
1784  );
1785  $this->characteristic_manager->replaceParameter(
1786  "td",
1787  $cell_class[$k],
1788  "font-weight",
1789  "normal",
1790  "table_cell"
1791  );
1792  }
1793 
1794  // table class
1795  $classes["table"] = $this->form_gui->getInput("name") . "T";
1796  if (!$this->object->characteristicExists($classes["table"], "table")) {
1797  $this->characteristic_manager->addCharacteristic("table", $classes["table"], true);
1798  }
1799  $this->characteristic_manager->replaceParameter(
1800  "table",
1801  $classes["table"],
1802  "caption-side",
1803  "bottom",
1804  "table"
1805  );
1806  $this->characteristic_manager->replaceParameter(
1807  "table",
1808  $classes["table"],
1809  "border-collapse",
1810  "collapse",
1811  "table"
1812  );
1813  $this->characteristic_manager->replaceParameter(
1814  "table",
1815  $classes["table"],
1816  "margin-top",
1817  "5px",
1818  "table"
1819  );
1820  $this->characteristic_manager->replaceParameter(
1821  "table",
1822  $classes["table"],
1823  "margin-bottom",
1824  "5px",
1825  "table"
1826  );
1827  if ($this->form_gui->getInput("layout") == "bwZebra") {
1828  $this->characteristic_manager->replaceParameter(
1829  "table",
1830  $classes["table"],
1831  "border-bottom-color",
1832  "!" . $this->form_gui->getInput("base_color"),
1833  "table"
1834  );
1835  $this->characteristic_manager->replaceParameter(
1836  "table",
1837  $classes["table"],
1838  "border-bottom-style",
1839  "solid",
1840  "table"
1841  );
1842  $this->characteristic_manager->replaceParameter(
1843  "table",
1844  $classes["table"],
1845  "border-bottom-width",
1846  "3px",
1847  "table"
1848  );
1849  $sb = array("left", "right", "top");
1850  foreach ($sb as $b) {
1851  $this->characteristic_manager->replaceParameter(
1852  "table",
1853  $classes["table"],
1854  "border-" . $b . "-width",
1855  "0px",
1856  "table"
1857  );
1858  }
1859  }
1860 
1861  switch ($this->form_gui->getInput("layout")) {
1862  case "bwZebra":
1863  case "coloredZebra":
1864  $classes["row_head"] = $cell_class["H"];
1865  $classes["odd_row"] = $cell_class["C1"];
1866  $classes["even_row"] = $cell_class["C2"];
1867  break;
1868 
1869  case "noZebra":
1870  $classes["row_head"] = $cell_class["H"];
1871  $classes["odd_row"] = $cell_class["C1"];
1872  $classes["even_row"] = $cell_class["C1"];
1873  $classes["col_head"] = $cell_class["C2"];
1874  break;
1875  }
1876 
1877 
1878  $t_id = $this->object->addTemplate(
1879  $this->style_request->getTempType(),
1880  $this->form_gui->getInput("name"),
1881  $classes
1882  );
1883  $this->object->writeTemplatePreview(
1884  $t_id,
1885  $this->getTemplatePreview(
1886  $this->style_request->getTempType(),
1887  $t_id,
1888  true
1889  )
1890  );
1891  $ilCtrl->redirect($this, "listTemplates");
1892  }
1893  }
1894  $this->form_gui->setValuesByPost();
1895  $tpl->setContent($this->form_gui->getHTML());
1896  }
1897 
1898  public function returnToUpperContextObject(): void
1899  {
1900  $ilCtrl = $this->ctrl;
1901  $ilCtrl->returnToParent($this);
1902  }
1903 }
Content StandardGUIRequest $style_request
cancelColorDeletionObject()
Cancel color deletion.
Content InternalService $service
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
Content ImageManager $image_manager
static _renderTable(string $content, string $a_mode="table_edit", string $a_submode="", ilPCTable $a_table_obj=null, bool $unmask=true, ilPageObject $page_object=null)
This class represents a selection list property in a property 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...
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
listColorsObject()
List colors of style.
refreshTemplateObject()
Refresh table template.
Content style internal ui factory.
getCmd(string $fallback_command=null)
prepareOutput(bool $show_sub_objects=true)
This class represents a file property in a property form.
addAdminLocatorItems(bool $do_not_add_object=false)
should be overwritten to add object specific items (repository items are preloaded) ...
Help GUI class.
initTemplateForm(string $a_mode="create")
Init table template form.
setPattern(string $pattern)
getCreationFormsHTML(array $forms)
Get HTML for creation forms (accordion)
getPropertiesValues()
Get current values for properties from.
confirmedDeleteObject()
delete selected style objects
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cancelTemplateDeletionObject()
Cancel table template deletion.
TableGUI class for style editor (image list)
Import class.
lookupTemplateName(int $a_t_id)
Lookup table template name for template ID.
Content ColorManager $color_manager
deleteTemplateConfirmationObject()
Delete table template confirmation.
setOptions(array $a_options)
Export.
static _getClonableContentStyles()
Get all clonable styles (active standard styles and individual learning module styles with write perm...
deleteColorConfirmationObject()
Delete color confirmation.
static _getTemplatePreview(ilObjStyleSheet $a_style, string $a_type, int $a_t_id, bool $a_small_mode=false)
Get table template preview.
static prepareFormOutput($a_str, bool $a_strip=false)
returnToParent(object $a_gui_obj, string $a_anchor=null)
static _writeStandard(int $a_id, bool $a_std)
Write standard flag.
static getStyleExampleHTML(string $a_type, string $a_class)
Get style example HTML.
enableWrite(bool $a_write)
Enable writing.
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-...
forwardCommand(object $a_gui_object)
ilObjectDefinition $obj_definition
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getStyleSuperTypeForType(string $a_type)
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
cancelColorSavingObject()
Cancel color saving.
setCreationMode(bool $mode=true)
If true, a creation screen is displayed the current [ref_id] does belong to the parent class The mode...
global $DIC
Definition: feed.php:28
Export User Interface Class.
ilLanguage $lng
Content InternalGUIService $gui_service
parses the objects.xml it handles the xml-description of all ilias objects
getNextClass($a_gui_class=null)
__construct( $a_data, int $a_id, bool $a_call_by_reference)
__construct(VocabulariesInterface $vocabularies)
Main business logic for content style images.
static addCss()
Add required css.
getTemplatePreview(string $a_type, int $a_t_id, bool $a_small_mode=false)
ilGlobalTemplateInterface $tpl
static _lookupTitle(int $obj_id)
setContent(string $a_html)
Sets content for standard template.
importStyleObject()
Import style sheet.
setFormAction(string $a_formaction)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMediaQueryFormValues()
Set values for media query editing.
setScreenIdComponent(string $a_comp)
getTemplateXML()
Get table template xml.
Class ilObjectGUI Basic methods of all Output classes.
initMediaQueryForm(string $a_mode="create")
Init media query form.
deleteTemplateObject()
Delete template.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Access StyleAccessManager $access_manager
header include for all ilias files.
Main business logic for characteristics.
saveTemplateObject()
Save table template.
editObject()
Edit -> List characteristics.
setRequired(bool $a_required)
templateGenerationObject()
Table template generation.
getColorFormValues()
Set values for color editing.
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
updateTemplateObject(bool $a_refresh=false)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
form( $class_path, string $cmd, string $submit_caption="")
static _lookupTemplateName(int $a_t_id)
Lookup table template name for template ID.
static _addMissingStyleClassesToStyle(int $a_id)
Add missing style classes to all styles.
saveMediaQueryObject()
Save media query.
initColorForm(string $a_mode="create")
Manages access to content style editing.
This class represents a text area property in a property form.
deleteObject($a_error=false)
display deletion confirmation screen
listTemplatesObject()
List templates.
cancelTemplateSavingObject()
Cancel color saving.
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
initPropertiesForm(string $a_mode="edit")
FORM: Init properties form.
static _lookupType(int $id, bool $reference=false)
static _getTemplateClassTypes(string $a_template_type="")
Get template class types.
initTemplateGenerationForm()
Init table template generation form.
getFormAction(object $a_gui_obj, string $a_fallback_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
const ID_PART_SCREEN
TableGUI class for style editor (image list)
getTemplateFormValues()
Set values for table template editing.
Content CharacteristicManager $characteristic_manager
addCss(string $a_css_file, string $media="screen")
Add a css file that should be included in the header.
$r