1<?php
2include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
3include_once("Services/Style/System/classes/class.ilSystemStyleSettings.php");
4include_once("Services/Style/System/classes/Overview/class.ilSystemStyleDeleteGUI.php");
5include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleMessageStack.php");
6include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
7include_once("Services/FileDelivery/classes/class.ilFileDelivery.php");
8include_once("Services/Style/System/classes/Overview/class.ilSystemStylesTableGUI.php");
9include_once("Services/Form/classes/class.ilSelectInputGUI.php");
10include_once("Services/Style/System/classes/class.ilStyleDefinition.php");
11include_once("Services/Style/System/classes/Utilities/class.ilSkinXML.php");
12include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
13include_once("Services/Object/exceptions/class.ilObjectException.php");
14
15/**
16 * @author            Alex Killing <alex.killing@gmx.de>
17 * @author            Timon Amstutz <timon.amstutz@ilub.unibe.ch>
18 * @version           $Id$*
19 */
20class ilSystemStyleOverviewGUI
21{
22    /**
23     * @var ilCtrl
24     */
25    protected $ctrl;
26
27    /**
28     * @var ilToolbarGUI
29     */
30    protected $toolbar;
31
32    /**
33     * @var ilLanguage
34     */
35    protected $lng;
36
37    /**
38     * @var ilTemplate
39     */
40    protected $tpl;
41
42    /**
43     * @var ILIAS\DI\Container
44     */
45    protected $DIC;
46
47    /**
48     * @var int
49     */
50    protected $ref_id;
51
52    /**
53     * @var bool
54     */
55    protected $read_only = true;
56
57    /**
58     * @var bool
59     */
60    protected $management_enabled = false;
61
62
63    /**
64     * Constructor
65     */
66    public function __construct($read_only, $management_enabled)
67    {
68        global $DIC;
69
70        $this->ilias = $DIC["ilias"];
71        $this->dic = $DIC;
72        $this->ctrl = $DIC->ctrl();
73        $this->toolbar = $DIC->toolbar();
74        $this->lng = $DIC->language();
75        $this->tpl = $DIC["tpl"];
76
77        $this->ref_id = (int) $_GET["ref_id"];
78
79        $this->setReadOnly($read_only);
80        $this->setManagementEnabled($management_enabled);
81    }
82
83    /**
84     * Execute command
85     */
86    public function executeCommand()
87    {
88        $cmd = $this->ctrl->getCmd();
89
90        if ($cmd == "") {
91            $cmd = $this->isReadOnly()?"view":"edit";
92        }
93
94
95        switch ($cmd) {
96            case "addSystemStyle":
97            case "addSubStyle":
98            case "saveNewSystemStyle":
99            case "saveNewSubStyle":
100            case "copyStyle":
101            case "importStyle":
102            case "deleteStyles":
103            case "deleteStyle":
104            case "confirmDelete":
105                if (!$this->isManagementEnabled()) {
106                    throw new ilObjectException($this->lng->txt("permission_denied"));
107                }
108                $this->$cmd();
109                return;
110            case "cancel":
111            case "edit":
112            case "export":
113            case "moveUserStyles":
114            case "saveStyleSettings":
115                if ($this->isReadOnly()) {
116                    throw new ilObjectException($this->lng->txt("permission_denied"));
117                }
118                $this->$cmd();
119                return;
120            case "view":
121                $this->$cmd();
122                return;
123
124        }
125    }
126
127    protected function view()
128    {
129        $table = new ilSystemStylesTableGUI($this, "edit", true);
130        $this->tpl->setContent($table->getHTML());
131    }
132
133    protected function cancel()
134    {
135        $this->edit();
136    }
137    /**
138     * Edit
139     */
140    public function edit()
141    {
142        if ($this->isManagementEnabled()) {
143            // Add Button for adding skins
144            $add_skin_btn = ilLinkButton::getInstance();
145            $add_skin_btn->setCaption($this->lng->txt("add_system_style"), false);
146            $add_skin_btn->setUrl($this->ctrl->getLinkTarget($this, 'addSystemStyle'));
147            $this->toolbar->addButtonInstance($add_skin_btn);
148
149            // Add Button for adding skins
150            $add_substyle_btn = ilLinkButton::getInstance();
151            $add_substyle_btn->setCaption($this->lng->txt("add_substyle"), false);
152            $add_substyle_btn->setUrl($this->ctrl->getLinkTarget($this, 'addSubStyle'));
153            if (count(ilStyleDefinition::getAllSkins()) == 1) {
154                $add_substyle_btn->setDisabled(true);
155            }
156            $this->toolbar->addButtonInstance($add_substyle_btn);
157
158            $this->toolbar->addSeparator();
159        }
160
161        // from styles selector
162        $si = new ilSelectInputGUI($this->lng->txt("sty_move_user_styles") . ": " . $this->lng->txt("sty_from"), "from_style");
163
164        $options = array();
165        foreach (ilStyleDefinition::getAllSkinStyles() as $id => $skin_style) {
166            if (!$skin_style['substyle_of']) {
167                $options[$id] = $skin_style['title'];
168            }
169        }
170        $si->setOptions($options + array("other" => $this->lng->txt("other")));
171
172        $this->toolbar->addInputItem($si, true);
173
174        // from styles selector
175        $si = new ilSelectInputGUI($this->lng->txt("sty_to"), "to_style");
176        $si->setOptions($options);
177        $this->toolbar->addInputItem($si, true);
178        // Add Button for adding skins
179        $move_skin_btn = ilSubmitButton::getInstance();
180        $move_skin_btn->setCaption($this->lng->txt("sty_move_style"), false);
181        $this->toolbar->addButtonInstance($move_skin_btn);
182        $this->toolbar->setFormAction($this->ctrl->getLinkTarget($this, 'moveUserStyles'));
183
184        $table = new ilSystemStylesTableGUI($this, "edit");
185        $table->addActions($this->isManagementEnabled());
186        $this->tpl->setContent($table->getHTML());
187    }
188
189    /**
190     * Move user styles
191     */
192    public function moveUserStyles()
193    {
194        $to = explode(":", $_POST["to_style"]);
195
196        if ($_POST["from_style"] == "other") {
197            // get all user assigned styles
198            $all_user_styles = ilObjUser::_getAllUserAssignedStyles();
199
200            // move users that are not assigned to
201            // currently existing style
202            foreach ($all_user_styles as $style) {
203                if (!ilStyleDefinition::styleExists($style)) {
204                    $style_arr = explode(":", $style);
205                    ilObjUser::_moveUsersToStyle($style_arr[0], $style_arr[1], $to[0], $to[1]);
206                }
207            }
208        } else {
209            $from = explode(":", $_POST["from_style"]);
210            ilObjUser::_moveUsersToStyle($from[0], $from[1], $to[0], $to[1]);
211        }
212
213        ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
214        $this->ctrl->redirect($this, "edit");
215    }
216
217
218    /**
219     * Save skin and style settings
220     */
221    public function saveStyleSettings()
222    {
223        $message_stack = new ilSystemStyleMessageStack();
224
225        if ($this->checkStyleSettings($message_stack)) {
226            $all_styles = ilStyleDefinition::getAllSkinStyles();
227            foreach ($all_styles as $st) {
228                if (!isset($_POST["st_act"][$st["id"]])) {
229                    ilSystemStyleSettings::_deactivateStyle($st["template_id"], $st["style_id"]);
230                } else {
231                    ilSystemStyleSettings::_activateStyle($st["template_id"], $st["style_id"]);
232                }
233            }
234
235            //set default skin and style
236            if ($_POST["default_skin_style"] != "") {
237                $sknst = explode(":", $_POST["default_skin_style"]);
238                ilSystemStyleSettings::setCurrentDefaultStyle($sknst[0], $sknst[1]);
239            }
240            $message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt("msg_obj_modified"), ilSystemStyleMessage::TYPE_SUCCESS));
241        }
242        $message_stack->sendMessages(true);
243        $this->ctrl->redirect($this, "edit");
244    }
245
246    /**
247     * @param ilSystemStyleMessageStack $message_stack
248     * @return bool
249     */
250    protected function checkStyleSettings(ilSystemStyleMessageStack $message_stack)
251    {
252        $passed = true;
253
254        if (count($_POST["st_act"]) < 1) {
255            $passed = false;
256            $message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt("at_least_one_style"), ilSystemStyleMessage::TYPE_ERROR));
257        }
258
259        if (!isset($_POST["st_act"][$_POST["default_skin_style"]])) {
260            $passed = false;
261            $message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt("cant_deactivate_default_style"), ilSystemStyleMessage::TYPE_ERROR));
262        }
263
264        // check if a style should be deactivated, that still has
265        // a user assigned to
266        $all_styles = ilStyleDefinition::getAllSkinStyles();
267
268        foreach ($all_styles as $st) {
269            if (!isset($_POST["st_act"][$st["id"]])) {
270                if (ilObjUser::_getNumberOfUsersForStyle($st["template_id"], $st["style_id"]) > 0) {
271                    $passed = false;
272                    $message_stack->addMessage(new ilSystemStyleMessage($st["style_name"] . ": " . $this->lng->txt("cant_deactivate_if_users_assigned"), ilSystemStyleMessage::TYPE_ERROR));
273                }
274            }
275        }
276        return $passed;
277    }
278
279
280    /**
281     * create
282     */
283    protected function addSystemStyle()
284    {
285        $this->addSystemStyleForms();
286    }
287
288
289    protected function saveNewSystemStyle()
290    {
291        $form = $this->createSystemStyleForm();
292
293        if ($form->checkInput()) {
294            $message_stack = new ilSystemStyleMessageStack();
295            if (ilStyleDefinition::skinExists($_POST["skin_id"])) {
296                ilUtil::sendFailure($this->lng->txt("skin_id_exists"));
297            } else {
298                try {
299                    $skin = new ilSkinXML($_POST["skin_id"], $_POST["skin_name"]);
300                    $style = new ilSkinStyleXML($_POST["style_id"], $_POST["style_name"]);
301                    $skin->addStyle($style);
302                    $container = new ilSystemStyleSkinContainer($skin);
303                    $container->create($message_stack);
304                    $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'skin_id', $skin->getId());
305                    $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'style_id', $style->getId());
306                    if ($message_stack->hasMessages()) {
307                        $message_stack->sendMessages(true);
308                    } else {
309                        ilUtil::sendSuccess($this->lng->txt("msg_sys_style_created"), true);
310                    }
311                    $this->ctrl->redirectByClass("ilSystemStyleSettingsGUI");
312                } catch (ilSystemStyleException $e) {
313                    $message_stack->addMessage(new ilSystemStyleMessage($e->getMessage(), ilSystemStyleMessage::TYPE_ERROR));
314                }
315            }
316            $message_stack->sendMessages();
317        }
318
319        // display only this form to correct input
320        $form->setValuesByPost();
321        $this->tpl->setContent($form->getHTML());
322    }
323
324    /**
325     * create
326     */
327    protected function addSystemStyleForms()
328    {
329        global $DIC;
330
331        $DIC->tabs()->clearTargets();
332        /**
333         * Since clearTargets also clears the help screen ids
334         */
335        $DIC->help()->setScreenIdComponent("sty");
336        $DIC->help()->setScreenId("system_styles");
337        $DIC->help()->setSubScreenId("create");
338
339        $forms = array();
340
341        $forms[] = $this->createSystemStyleForm();
342        $forms[] = $this->importSystemStyleForm();
343        $forms[] = $this->cloneSystemStyleForm();
344
345        $this->tpl->setContent($this->getCreationFormsHTML($forms));
346    }
347
348    /**
349     * @return ilPropertyFormGUI
350     */
351    protected function createSystemStyleForm()
352    {
353        $form = new ilPropertyFormGUI();
354        $form->setFormAction($this->ctrl->getFormAction($this));
355        $form->setTitle($this->lng->txt("sty_create_new_system_style"));
356
357        $ti = new ilTextInputGUI($this->lng->txt("skin_id"), "skin_id");
358        $ti->setInfo($this->lng->txt("skin_id_description"));
359        $ti->setMaxLength(128);
360        $ti->setSize(40);
361        $ti->setRequired(true);
362        $form->addItem($ti);
363
364        $ti = new ilTextInputGUI($this->lng->txt("skin_name"), "skin_name");
365        $ti->setInfo($this->lng->txt("skin_name_description"));
366        $ti->setMaxLength(128);
367        $ti->setSize(40);
368        $ti->setRequired(true);
369        $form->addItem($ti);
370
371        $ti = new ilTextInputGUI($this->lng->txt("style_id"), "style_id");
372        $ti->setInfo($this->lng->txt("style_id_description"));
373        $ti->setMaxLength(128);
374        $ti->setSize(40);
375        $ti->setRequired(true);
376        $form->addItem($ti);
377
378        $ti = new ilTextInputGUI($this->lng->txt("style_name"), "style_name");
379        $ti->setInfo($this->lng->txt("style_name_description"));
380        $ti->setMaxLength(128);
381        $ti->setSize(40);
382        $ti->setRequired(true);
383        $form->addItem($ti);
384
385        $form->addCommandButton("saveNewSystemStyle", $this->lng->txt("save"));
386        $form->addCommandButton("cancel", $this->lng->txt("cancel"));
387
388        return $form;
389    }
390
391    /**
392     * @return ilPropertyFormGUI
393     */
394    protected function importSystemStyleForm()
395    {
396        $form = new ilPropertyFormGUI();
397        $form->setFormAction($this->ctrl->getFormAction($this));
398        $form->setTitle($this->lng->txt("sty_import_system_style"));
399
400        // title
401        $file_input = new ilFileInputGUI($this->lng->txt("import_file"), "importfile");
402        $file_input->setRequired(true);
403        $file_input->setSuffixes(array("zip"));
404        $form->addItem($file_input);
405
406        $form->addCommandButton("importStyle", $this->lng->txt("import"));
407        $form->addCommandButton("cancel", $this->lng->txt("cancel"));
408
409        return $form;
410    }
411
412    /**
413     * @return ilPropertyFormGUI
414     */
415    protected function cloneSystemStyleForm()
416    {
417        $form = new ilPropertyFormGUI();
418        $form->setFormAction($this->ctrl->getFormAction($this));
419        $form->setTitle($this->lng->txt("sty_copy_other_system_style"));
420
421        // source
422        $ti = new ilSelectInputGUI($this->lng->txt("sty_source"), "source_style");
423        $ti->setRequired(true);
424        $styles = ilStyleDefinition::getAllSkinStyles();
425        $options = array();
426        foreach ($styles as $id => $style) {
427            $system_style_conf = new ilSystemStyleConfig();
428            if ($style["skin_id"] != $system_style_conf->getDefaultSkinId()) {
429                $options[$id] = $style['title'];
430            }
431        }
432        $ti->setOptions($options);
433
434        $form->addItem($ti);
435
436        $form->addCommandButton("copyStyle", $this->lng->txt("copy"));
437        $form->addCommandButton("cancel", $this->lng->txt("cancel"));
438
439        return $form;
440    }
441
442    /**
443     * @param array $a_forms
444     * @return string
445     */
446    protected function getCreationFormsHTML(array $a_forms)
447    {
448        include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
449
450        $acc = new ilAccordionGUI();
451        $acc->setBehaviour(ilAccordionGUI::FIRST_OPEN);
452        $cnt = 1;
453        foreach ($a_forms as $form_type => $cf) {
454            /**
455             * @var ilPropertyFormGUI $cf
456             */
457            $htpl = new ilTemplate("tpl.creation_acc_head.html", true, true, "Services/Object");
458
459            // using custom form titles (used for repository plugins)
460            $form_title = "";
461            if (method_exists($this, "getCreationFormTitle")) {
462                $form_title = $this->getCreationFormTitle($form_type);
463            }
464            if (!$form_title) {
465                $form_title = $cf->getTitle();
466            }
467
468            // move title from form to accordion
469            $htpl->setVariable("TITLE", $this->lng->txt("option") . " " . $cnt . ": " .
470                $form_title);
471            $cf->setTitle(null);
472            $cf->setTitleIcon(null);
473            $cf->setTableWidth("100%");
474
475            $acc->addItem($htpl->get(), $cf->getHTML());
476
477            $cnt++;
478        }
479
480        return "<div class='ilCreationFormSection'>" . $acc->getHTML() . "</div>";
481    }
482
483    protected function copyStyle()
484    {
485        $message_stack = new ilSystemStyleMessageStack();
486
487        $imploded_skin_style_id = explode(":", $_POST['source_style']);
488        $skin_id = $imploded_skin_style_id[0];
489        $style_id = $imploded_skin_style_id[1];
490
491        try {
492            $container = ilSystemStyleSkinContainer::generateFromId($skin_id, $message_stack);
493            $new_container = $container->copy();
494            $message_stack->prependMessage(new ilSystemStyleMessage($this->lng->txt("style_copied"), ilSystemStyleMessage::TYPE_SUCCESS));
495            $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'skin_id', $new_container->getSkin()->getId());
496            $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'style_id', $new_container->getSkin()->getStyle($style_id)->getId());
497        } catch (Exception $e) {
498            $message_stack->addMessage(new ilSystemStyleMessage($e->getMessage(), ilSystemStyleMessage::TYPE_ERROR));
499        }
500
501
502        $message_stack->sendMessages(true);
503        $this->ctrl->redirectByClass("ilSystemStyleSettingsGUI");
504    }
505
506    protected function deleteStyle()
507    {
508        $skin_id = $_GET["skin_id"];
509        $style_id = $_GET["style_id"];
510        $message_stack = new ilSystemStyleMessageStack();
511
512        if ($this->checkDeletable($skin_id, $style_id, $message_stack)) {
513            $delete_form_table = new ilSystemStyleDeleteGUI();
514            $container = ilSystemStyleSkinContainer::generateFromId($skin_id);
515            $delete_form_table->addStyle($container->getSkin(), $container->getSkin()->getStyle($style_id));
516            $this->tpl->setContent($delete_form_table->getDeleteStyleFormHTML());
517        } else {
518            $message_stack->prependMessage(new ilSystemStyleMessage($this->lng->txt("style_not_deleted"), ilSystemStyleMessage::TYPE_ERROR));
519            $message_stack->sendMessages(true);
520            $this->edit();
521        }
522    }
523    protected function deleteStyles()
524    {
525        $delete_form_table = new ilSystemStyleDeleteGUI();
526        $message_stack = new ilSystemStyleMessageStack();
527
528        $all_deletable = true;
529        foreach ($_POST['id'] as $skin_style_id) {
530            $imploded_skin_style_id = explode(":", $skin_style_id);
531            $skin_id = $imploded_skin_style_id[0];
532            $style_id = $imploded_skin_style_id[1];
533            if (!$this->checkDeletable($skin_id, $style_id, $message_stack)) {
534                $all_deletable = false;
535            }
536        }
537        if ($all_deletable) {
538            foreach ($_POST['id'] as $skin_style_id) {
539                $imploded_skin_style_id = explode(":", $skin_style_id);
540                $skin_id = $imploded_skin_style_id[0];
541                $style_id = $imploded_skin_style_id[1];
542                $container = ilSystemStyleSkinContainer::generateFromId($skin_id);
543                $delete_form_table->addStyle($container->getSkin(), $container->getSkin()->getStyle($style_id));
544            }
545            $this->tpl->setContent($delete_form_table->getDeleteStyleFormHTML());
546        } else {
547            $message_stack->prependMessage(new ilSystemStyleMessage($this->lng->txt("styles_not_deleted"), ilSystemStyleMessage::TYPE_ERROR));
548            $message_stack->sendMessages(true);
549            $this->edit();
550        }
551    }
552
553    /**
554     * @param $skin_id
555     * @param $style_id
556     * @param ilSystemStyleMessageStack $message_stack
557     * @return bool
558     * @throws ilSystemStyleException
559     */
560    protected function checkDeletable($skin_id, $style_id, ilSystemStyleMessageStack $message_stack)
561    {
562        $passed = true;
563        if (ilObjUser::_getNumberOfUsersForStyle($skin_id, $style_id) > 0) {
564            $message_stack->addMessage(new ilSystemStyleMessage($style_id . ": " . $this->lng->txt("cant_delete_if_users_assigned"), ilSystemStyleMessage::TYPE_ERROR));
565            $passed = false;
566        }
567        if (ilSystemStyleSettings::_lookupActivatedStyle($skin_id, $style_id) > 0) {
568            $message_stack->addMessage(new ilSystemStyleMessage($style_id . ": " . $this->lng->txt("cant_delete_activated_style"), ilSystemStyleMessage::TYPE_ERROR));
569            $passed = false;
570        }
571        if (ilSystemStyleSettings::getCurrentDefaultSkin() == $skin_id && ilSystemStyleSettings::getCurrentDefaultSkin() == $style_id) {
572            $message_stack->addMessage(new ilSystemStyleMessage($style_id . ": " . $this->lng->txt("cant_delete_default_style"), ilSystemStyleMessage::TYPE_ERROR));
573            $passed = false;
574        }
575
576        if (ilSystemStyleSkinContainer::generateFromId($skin_id)->getSkin()->getSubstylesOfStyle($style_id)) {
577            $message_stack->addMessage(new ilSystemStyleMessage($style_id . ": " . $this->lng->txt("cant_delete_style_with_substyles"), ilSystemStyleMessage::TYPE_ERROR));
578            $passed = false;
579        }
580        return $passed;
581    }
582
583    protected function confirmDelete()
584    {
585        $message_stack = new ilSystemStyleMessageStack();
586
587        foreach ($_POST as $key => $skin_style_id) {
588            if (is_string($skin_style_id) && strpos($key, 'style') !== false) {
589                try {
590                    $imploded_skin_style_id = explode(":", $skin_style_id);
591                    $container = ilSystemStyleSkinContainer::generateFromId($imploded_skin_style_id[0], $message_stack);
592                    $syle = $container->getSkin()->getStyle($imploded_skin_style_id[1]);
593                    $container->deleteStyle($syle);
594                    if (!$container->getSkin()->hasStyles()) {
595                        $container->delete();
596                    }
597                } catch (Exception $e) {
598                    $message_stack->addMessage(new ilSystemStyleMessage($e->getMessage(), ilSystemStyleMessage::TYPE_ERROR));
599                }
600            }
601        }
602        $message_stack->sendMessages(true);
603        $this->ctrl->redirect($this);
604    }
605
606    /**
607     *
608     */
609    protected function importStyle()
610    {
611        $form = $this->importSystemStyleForm();
612
613        if ($form->checkInput()) {
614            $message_stack = new ilSystemStyleMessageStack();
615            $imported_container = ilSystemStyleSkinContainer::import($_POST['importfile']['tmp_name'], $_POST['importfile']['name'], $message_stack);
616            $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'skin_id', $imported_container->getSkin()->getId());
617            $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'style_id', $imported_container->getSkin()->getDefaultStyle()->getId());
618            $message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt("style_imported") . " " . $imported_container->getSkinDirectory(), ilSystemStyleMessage::TYPE_SUCCESS));
619
620            $message_stack->sendMessages(true);
621            $this->ctrl->redirectByClass("ilSystemStyleSettingsGUI");
622        }
623
624        // display only this form to correct input
625        $form->setValuesByPost();
626        $this->tpl->setContent($form->getHTML());
627    }
628    protected function export()
629    {
630        $skin_id = $_GET["skin_id"];
631        $container = ilSystemStyleSkinContainer::generateFromId($skin_id);
632        try {
633            $container->export();
634        } catch (Exception $e) {
635            ilUtil::sendFailure($this->lng->txt("zip_export_failed") . " " . $e->getMessage());
636        }
637    }
638
639
640    /**
641     *
642     */
643    protected function addSubStyle()
644    {
645        global $DIC;
646
647        $DIC->tabs()->clearTargets();
648        /**
649         * Since clearTargets also clears the help screen ids
650         */
651        $DIC->help()->setScreenIdComponent("sty");
652        $DIC->help()->setScreenId("system_styles");
653        $DIC->help()->setSubScreenId("create_sub");
654
655        $form = $this->addSubStyleForms();
656
657        $this->tpl->setContent($form->getHTML());
658    }
659
660    /**
661     * @return ilPropertyFormGUI
662     */
663    protected function addSubStyleForms()
664    {
665        $form = new ilPropertyFormGUI();
666        $form->setFormAction($this->ctrl->getFormAction($this));
667        $form->setTitle($this->lng->txt("sty_create_new_system_sub_style"));
668
669
670        $ti = new ilTextInputGUI($this->lng->txt("sub_style_id"), "sub_style_id");
671        $ti->setInfo($this->lng->txt("sub_style_id_description"));
672        $ti->setMaxLength(128);
673        $ti->setSize(40);
674        $ti->setRequired(true);
675        $form->addItem($ti);
676
677        $ti = new ilTextInputGUI($this->lng->txt("sub_style_name"), "sub_style_name");
678        $ti->setInfo($this->lng->txt("sub_style_name_description"));
679        $ti->setMaxLength(128);
680        $ti->setSize(40);
681        $ti->setRequired(true);
682        $form->addItem($ti);
683
684        // source
685        $ti = new ilSelectInputGUI($this->lng->txt("parent"), "parent_style");
686        $ti->setRequired(true);
687        $ti->setInfo($this->lng->txt("sub_style_parent_style_description"));
688        $styles = ilStyleDefinition::getAllSkinStyles();
689        $options = array();
690        foreach ($styles as $id => $style) {
691            $system_style_conf = new ilSystemStyleConfig();
692            if ($style["skin_id"] != $system_style_conf->getDefaultSkinId() && !$style["substyle_of"]) {
693                $options[$id] = $style['title'];
694            }
695        }
696        $ti->setOptions($options);
697
698        $form->addItem($ti);
699        $form->addCommandButton("saveNewSubStyle", $this->lng->txt("save"));
700        $form->addCommandButton("cancel", $this->lng->txt("cancel"));
701
702        return $form;
703    }
704
705    protected function saveNewSubStyle()
706    {
707        $form = $this->addSubStyleForms();
708
709        if ($form->checkInput()) {
710            try {
711                $imploded_parent_skin_style_id = explode(":", $_POST['parent_style']);
712                $parent_skin_id = $imploded_parent_skin_style_id[0];
713                $parent_style_id = $imploded_parent_skin_style_id[1];
714
715                $container = ilSystemStyleSkinContainer::generateFromId($parent_skin_id);
716
717                if (array_key_exists($_POST['sub_style_id'], $container->getSkin()->getSubstylesOfStyle($parent_style_id))) {
718                    throw new ilSystemStyleException(ilSystemStyleException::SUBSTYLE_ASSIGNMENT_EXISTS, $_POST['sub_style_id']);
719                }
720
721                $sub_style_id = $_POST['sub_style_id'];
722
723                $style = new ilSkinStyleXML($_POST['sub_style_id'], $_POST['sub_style_name']);
724                $style->setSubstyleOf($parent_style_id);
725                $container->addStyle($style);
726
727                $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'skin_id', $parent_skin_id);
728                $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'style_id', $sub_style_id);
729                ilUtil::sendSuccess($this->lng->txt("msg_sub_style_created"), true);
730                $this->ctrl->redirectByClass("ilSystemStyleSettingsGUI");
731            } catch (ilSystemStyleException $e) {
732                ilUtil::sendFailure($e->getMessage(), true);
733            }
734        }
735
736        // display only this form to correct input
737        $form->setValuesByPost();
738        $this->tpl->setContent($form->getHTML());
739    }
740
741    /**
742     * @return boolean
743     */
744    public function isReadOnly()
745    {
746        return $this->read_only;
747    }
748
749    /**
750     * @param boolean $read_only
751     */
752    public function setReadOnly($read_only)
753    {
754        $this->read_only = $read_only;
755    }
756
757    /**
758     * @return boolean
759     */
760    public function isManagementEnabled()
761    {
762        return $this->management_enabled;
763    }
764
765    /**
766     * @param boolean $management_enabled
767     */
768    public function setManagementEnabled($management_enabled)
769    {
770        $this->management_enabled = $management_enabled;
771    }
772}
773