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