ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSystemStyleSettingsGUI.php
Go to the documentation of this file.
1<?php
2include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
3include_once("Services/Style/System/classes/Utilities/class.ilSkinXML.php");
4include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
5include_once("Services/Style/System/classes/class.ilSystemStyleSettings.php");
6include_once("Services/Style/System/classes/Exceptions/class.ilSystemStyleException.php");
7include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleMessageStack.php");
8include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleMessage.php");
9include_once("Services/Style/System/classes/Settings/class.ilSubStyleAssignmentGUI.php");
10
11
17{
18
22 protected $ctrl;
23
27 protected $lng;
28
32 protected $tpl;
33
37 protected $tabs;
38
42 public function __construct()
43 {
44 global $DIC;
45
46 $this->ctrl = $DIC->ctrl();
47 $this->lng = $DIC->language();
48 $this->tabs = $DIC->tabs();
49
50 $this->tpl = $DIC["tpl"];
51 }
52
53
57 public function executeCommand()
58 {
59 $cmd = $this->ctrl->getCmd() ? $this->ctrl->getCmd():"edit";
60 $system_style_conf = new ilSystemStyleConfig();
61 $skin = ilSkinXML::parseFromXML($system_style_conf->getCustomizingSkinPath() . $_GET["skin_id"] . "/template.xml");
62 $style = $skin->getStyle($_GET["style_id"]);
63
64 if ($style->isSubstyle()) {
65 if ($cmd == "edit"|| $cmd == "view") {
66 $this->setSubStyleSubTabs("edit");
67 } else {
68 $this->setSubStyleSubTabs("assignStyle");
69 }
70 }
71
72 switch ($cmd) {
73 case "deleteAssignments":
74 $assign_gui = new ilSubStyleAssignmentGUI($this);
75 $assign_gui->deleteAssignments($skin, $style);
76 break;
77 case "saveAssignment":
78 $assign_gui = new ilSubStyleAssignmentGUI($this);
79 $assign_gui->saveAssignment($skin, $style);
80 break;
81 case "addAssignment":
82 $assign_gui = new ilSubStyleAssignmentGUI($this);
83 $assign_gui->addAssignment($skin, $style);
84 break;
85 case "assignStyle":
86 $assign_gui = new ilSubStyleAssignmentGUI($this);
87 $assign_gui->assignStyle($skin, $style);
88 break;
89 case "save":
90 case "edit":
91 $this->$cmd();
92 break;
93 default:
94 $this->edit();
95 break;
96 }
97 }
98
102 protected function setSubStyleSubTabs($active = "")
103 {
104 $this->tabs->addSubTab('edit', $this->lng->txt('settings'), $this->ctrl->getLinkTargetByClass('ilsystemstylesettingsgui'));
105 $this->tabs->addSubTab('assignStyle', $this->lng->txt('assignment'), $this->ctrl->getLinkTargetByClass('ilsystemstylesettingsgui', "assignStyle"));
106
107 $this->tabs->activateSubTab($active);
108 }
109
110 protected function edit()
111 {
112 $form = $this->editSystemStyleForm();
114 $this->tpl->setContent($form->getHTML());
115 }
116
120 public function getPropertiesValues($form)
121 {
122 global $DIC;
123
124 if (!$_GET["skin_id"]) {
126 }
127 if (!$_GET["style_id"]) {
129 }
130 $system_style_config = new ilSystemStyleConfig();
131 $skin = ilSkinXML::parseFromXML($system_style_config->getCustomizingSkinPath() . $_GET["skin_id"] . "/template.xml");
132 $style = $skin->getStyle($_GET["style_id"]);
133 $values["skin_id"] = $skin->getId();
134 $values["skin_name"] = $skin->getName();
135 $values["style_id"] = $style->getId();
136 $values["style_name"] = $style->getName();
137 $values["image_dir"] = $style->getImageDirectory();
138 $values["font_dir"] = $style->getFontDirectory();
139 $values["sound_dir"] = $style->getSoundDirectory();
140
141
142 if ($style->isSubstyle()) {
143 $values["parent_style"] = $style->getSubstyleOf();
144 } else {
145 $values["active"] = ilSystemStyleSettings::_lookupActivatedStyle($skin->getId(), $style->getId());
146 $is_personal_style = $DIC->user()->getPref("skin")==$skin->getId() && $DIC->user()->getPref("style") == $style->getId();
147 $values["personal"] = $is_personal_style;
149 $values["default"] = $is_default_style;
150 }
151
152 $form->setValuesByArray($values);
153 }
154
155
156 protected function save()
157 {
158 $form = $this->editSystemStyleForm();
159
160 $message_stack = new ilSystemStyleMessageStack();
161 if ($form->checkInput()) {
162 try {
163 $system_style_conf = new ilSystemStyleConfig();
164 $skin = ilSkinXML::parseFromXML($system_style_conf->getCustomizingSkinPath() . $_GET["skin_id"] . "/template.xml");
165 $style = $skin->getStyle($_GET["style_id"]);
166
167 if ($style->isSubstyle()) {
168 $this->saveSubStyle($message_stack);
169 } else {
170 $this->saveStyle($message_stack);
171 }
172
173 $message_stack->prependMessage(new ilSystemStyleMessage($this->lng->txt("msg_sys_style_update"), ilSystemStyleMessage::TYPE_SUCCESS));
174 $message_stack->sendMessages(true);
175 $this->ctrl->redirectByClass("ilSystemStyleSettingsGUI");
176 } catch (ilSystemStyleException $e) {
177 ilUtil::sendFailure($e->getMessage(), true);
178 }
179 } else {
180 $message_stack->sendMessages();
181 }
182
183 $form->setValuesByPost();
184 $this->tpl->setContent($form->getHTML());
185 }
186
187
192 protected function saveStyle(ilSystemStyleMessageStack $message_stack)
193 {
194 global $DIC;
195
196 $container = ilSystemStyleSkinContainer::generateFromId($_GET['skin_id'], $message_stack);
197 $old_skin = clone $container->getSkin();
198 $old_style = clone $old_skin->getStyle($_GET["style_id"]);
199
200 $new_skin = $container->getSkin();
201 $new_skin->setId($_POST["skin_id"]);
202 $new_skin->setName($_POST["skin_name"]);
203 $new_skin->getVersionStep($_POST['skin_version']);
204
205 $new_style = $new_skin->getStyle($_GET["style_id"]);
206 $new_style->setId($_POST["style_id"]);
207 $new_style->setName($_POST["style_name"]);
208 $new_style->setCssFile($_POST["style_id"]);
209 $new_style->setImageDirectory($_POST["image_dir"]);
210 $new_style->setSoundDirectory($_POST["sound_dir"]);
211 $new_style->setFontDirectory($_POST["font_dir"]);
212
213 $container->updateSkin($old_skin);
214 $container->updateStyle($new_style->getId(), $old_style);
215
216
217 if ($_POST["active"] == 1) {
218 ilSystemStyleSettings::_activateStyle($new_skin->getId(), $new_style->getId());
219 if ($_POST["personal"]==1) {
220 ilSystemStyleSettings::setCurrentUserPrefStyle($new_skin->getId(), $new_style->getId());
221 }
222 if ($_POST["default"]==1) {
223 ilSystemStyleSettings::setCurrentDefaultStyle($new_skin->getId(), $new_style->getId());
224 }
225 } else {
226 ilSystemStyleSettings::_deactivateStyle($new_skin->getId(), $new_style->getId());
227 $_POST["personal"] = 0;
228 $_POST["default"] = 0;
229 }
230
231 $system_style_conf = new ilSystemStyleConfig();
232
233 //If style has been unset as personal style
234 if (!$_POST["personal"] && $DIC->user()->getPref("skin") == $new_skin->getId()) {
235 //Reset to default if possible, else change to delos
236 if (!$_POST["default"]) {
240 );
241 } else {
243 $system_style_conf->getDefaultSkinId(),
244 $system_style_conf->getDefaultStyleId()
245 );
246 }
247 $message_stack->addMessage(
249 $this->lng->txt("personal_style_set_to") . " " . ilSystemStyleSettings::getCurrentUserPrefSkin() . ":" . ilSystemStyleSettings::getCurrentUserPrefStyle(),
251 )
252 );
253 }
254 if (!$_POST["default"] && ilSystemStyleSettings::getCurrentDefaultSkin() == $new_skin->getId()) {
256 $system_style_conf->getDefaultSkinId(),
257 $system_style_conf->getDefaultStyleId()
258 );
259 $message_stack->addMessage(
261 $this->lng->txt("default_style_set_to") . " " . $system_style_conf->getDefaultSkinId() . ": " . $system_style_conf->getDefaultStyleId(),
263 )
264 );
265 }
266 $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'skin_id', $new_skin->getId());
267 $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'style_id', $new_style->getId());
268 }
269
274 protected function saveSubStyle(ilSystemStyleMessageStack $message_stack)
275 {
276 $container = ilSystemStyleSkinContainer::generateFromId($_GET['skin_id'], $message_stack);
277 $skin = $container->getSkin();
278 $old_substyle = clone $skin->getStyle($_GET["style_id"]);
279
280 if (array_key_exists($_POST['style_id'], $skin->getSubstylesOfStyle($old_substyle->getSubstyleOf()))) {
282 }
283
284 $new_substyle = $skin->getStyle($_GET["style_id"]);
285 $new_substyle->setId($_POST["style_id"]);
286 $new_substyle->setName($_POST["style_name"]);
287 $new_substyle->setCssFile($_POST["style_id"]);
288 $new_substyle->setImageDirectory($_POST["image_dir"]);
289 $new_substyle->setSoundDirectory($_POST["sound_dir"]);
290 $new_substyle->setFontDirectory($_POST["font_dir"]);
291 $new_substyle->setSubstyleOf($old_substyle->getSubstyleOf());
292
293 $container->updateSkin($skin);
294 $container->updateStyle($new_substyle->getId(), $old_substyle);
295
296 $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'skin_id', $skin->getId());
297 $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'style_id', $new_substyle->getId());
298 }
299
304 protected function editSystemStyleForm()
305 {
306 $form = new ilPropertyFormGUI();
307 $system_style_conf = new ilSystemStyleConfig();
308
309 $skin = ilSkinXML::parseFromXML($system_style_conf->getCustomizingSkinPath() . $_GET["skin_id"] . "/template.xml");
310 $style = $skin->getStyle($_GET["style_id"]);
311
312 $form->setFormAction($this->ctrl->getFormActionByClass("ilsystemstylesettingsgui"));
313
314
315 if (!$style->isSubstyle()) {
316 $form->setTitle($this->lng->txt("skin"));
317
318 $ti = new ilTextInputGUI($this->lng->txt("skin_id"), "skin_id");
319 $ti->setMaxLength(128);
320 $ti->setSize(40);
321 $ti->setRequired(true);
322 $ti->setInfo($this->lng->txt("skin_id_description"));
323 $form->addItem($ti);
324
325 $ti = new ilTextInputGUI($this->lng->txt("skin_name"), "skin_name");
326 $ti->setInfo($this->lng->txt("skin_name_description"));
327 $ti->setMaxLength(128);
328 $ti->setSize(40);
329 $ti->setRequired(true);
330 $form->addItem($ti);
331
332 if ($skin->isVersionChangeable()) {
333 $ti = new ilNonEditableValueGUI($this->lng->txt("skin_version"), "skin_version");
334 $ti->setInfo($this->lng->txt("skin_version_description"));
335 $ti->setValue($skin->getVersion());
336 $form->addItem($ti);
337 }
338
340 $section->setTitle($this->lng->txt("style"));
341 $form->addItem($section);
342 } else {
343 $form->setTitle($this->lng->txt("sub_style"));
344 }
345
346 $ti = new ilTextInputGUI($this->lng->txt("style_id"), "style_id");
347 $ti->setMaxLength(128);
348 $ti->setSize(40);
349 $ti->setRequired(true);
350 $ti->setInfo($this->lng->txt("style_id_description"));
351 $form->addItem($ti);
352
353 $ti = new ilTextInputGUI($this->lng->txt("style_name"), "style_name");
354 $ti->setMaxLength(128);
355 $ti->setSize(40);
356 $ti->setRequired(true);
357 $ti->setInfo($this->lng->txt("style_name_description"));
358 $form->addItem($ti);
359
360 $ti = new ilTextInputGUI($this->lng->txt("image_dir"), "image_dir");
361 $ti->setMaxLength(128);
362 $ti->setSize(40);
363 $ti->setInfo($this->lng->txt("image_dir_description"));
364 $form->addItem($ti);
365
366 $ti = new ilTextInputGUI($this->lng->txt("font_dir"), "font_dir");
367 $ti->setMaxLength(128);
368 $ti->setSize(40);
369 $ti->setInfo($this->lng->txt("font_dir_description"));
370 $form->addItem($ti);
371
372 $ti = new ilTextInputGUI($this->lng->txt("sound_dir"), "sound_dir");
373 $ti->setMaxLength(128);
374 $ti->setSize(40);
375 $ti->setInfo($this->lng->txt("sound_dir_description"));
376 $form->addItem($ti);
377
378 if (!$style->isSubstyle()) {
380 $section->setTitle($this->lng->txt("system_style_activation"));
381 $form->addItem($section);
382
383 $active = new ilCheckboxInputGUI($this->lng->txt("system_style_activation"), "active");
384 $active->setInfo($this->lng->txt("system_style_activation_description"));
385
386 $set_default = new ilCheckboxInputGUI($this->lng->txt("default"), "default");
387 $set_default->setInfo($this->lng->txt("system_style_default_description"));
388 $active->addSubItem($set_default);
389
390 $set_personal = new ilCheckboxInputGUI($this->lng->txt("personal"), "personal");
391 $set_personal->setInfo($this->lng->txt("system_style_personal_description"));
392 $active->addSubItem($set_personal);
393
394
395 $form->addItem($active);
396 }
397
398 $form->addCommandButton("save", $this->lng->txt("save"));
399 $form->addCommandButton("cancel", $this->lng->txt("cancel"));
400
401 return $form;
402 }
403}
$section
Definition: Utf8Test.php:83
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
This class represents a section header in a property form.
This class represents a non editable value in a property form.
This class represents a property form user interface.
ilSystemStyleConfig wraps all 'constants' to ensure the testability of all classes using those 'const...
Class for advanced editing exception handling in ILIAS.
Used to stack messages to be shown to the user.
addMessage(ilSystemStyleMessage $message)
Add a message to be displayed by the stack.
saveSubStyle(ilSystemStyleMessageStack $message_stack)
getPropertiesValues($form)
Get values for edit properties form.
saveStyle(ilSystemStyleMessageStack $message_stack)
static getCurrentDefaultStyle()
Gets default style of the system.
static getCurrentUserPrefSkin()
Gets a users preferred skin by using the user object.
static setCurrentDefaultStyle($skin_id, $style_id)
Sets the default style of the system.
static _activateStyle($a_skin, $a_style)
activate system style
static _deactivateStyle($a_skin, $a_style)
deactivate system style
static _lookupActivatedStyle($a_skin, $a_style)
lookup if a style is activated
static getCurrentDefaultSkin()
Gets default Skin of the System.
static setCurrentUserPrefStyle($skin_id, $style_id)
Sets a users preferred system skin/style by using the user object.
static getCurrentUserPrefStyle()
Gets a users preferred style by using the user object.
static generateFromId($skin_id, ilSystemStyleMessageStack $message_stack=null, ilSystemStyleConfig $system_styles_conf=null)
Generate the container class by parsing the corresponding XML.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$style
Definition: example_012.php:70
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$container
Definition: wac.php:13