ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSystemStyleSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
3 include_once("Services/Style/System/classes/Utilities/class.ilSkinXML.php");
4 include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
5 include_once("Services/Style/System/classes/class.ilSystemStyleSettings.php");
6 include_once("Services/Style/System/classes/Exceptions/class.ilSystemStyleException.php");
7 include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleMessageStack.php");
8 include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleMessage.php");
9 include_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  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  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 
73  switch ($cmd)
74  {
75  case "deleteAssignments":
76  $assign_gui = new ilSubStyleAssignmentGUI($this);
77  $assign_gui->deleteAssignments($skin,$style);
78  break;
79  case "saveAssignment":
80  $assign_gui = new ilSubStyleAssignmentGUI($this);
81  $assign_gui->saveAssignment($skin,$style);
82  break;
83  case "addAssignment":
84  $assign_gui = new ilSubStyleAssignmentGUI($this);
85  $assign_gui->addAssignment($skin,$style);
86  break;
87  case "assignStyle":
88  $assign_gui = new ilSubStyleAssignmentGUI($this);
89  $assign_gui->assignStyle($skin,$style);
90  break;
91  case "save":
92  case "edit":
93  $this->$cmd();
94  break;
95  default:
96  $this->edit();
97  break;
98  }
99  }
100 
104  protected function setSubStyleSubTabs($active = "") {
105 
106  $this->tabs->addSubTab('edit', $this->lng->txt('settings'), $this->ctrl->getLinkTargetByClass('ilsystemstylesettingsgui'));
107  $this->tabs->addSubTab('assignStyle', $this->lng->txt('assignment'), $this->ctrl->getLinkTargetByClass('ilsystemstylesettingsgui',"assignStyle"));
108 
109  $this->tabs->activateSubTab($active);
110  }
111 
112  protected function edit(){
113  $form = $this->editSystemStyleForm();
114  $this->getPropertiesValues($form);
115  $this->tpl->setContent($form->getHTML());
116 
117  }
118 
122  function getPropertiesValues($form)
123  {
124  global $DIC;
125 
126  if(!$_GET["skin_id"]){
128  }
129  if(!$_GET["style_id"]){
131  }
132  $system_style_config = new ilSystemStyleConfig();
133  $skin = ilSkinXML::parseFromXML($system_style_config->getCustomizingSkinPath().$_GET["skin_id"]."/template.xml");
134  $style = $skin->getStyle($_GET["style_id"]);
135  $values["skin_id"] = $skin->getId();
136  $values["skin_name"] = $skin->getName();
137  $values["style_id"] = $style->getId();
138  $values["style_name"] = $style->getName();
139  $values["image_dir"] = $style->getImageDirectory();
140  $values["font_dir"] = $style->getFontDirectory();
141  $values["sound_dir"] = $style->getSoundDirectory();
142 
143 
144  if($style->isSubstyle()){
145  $values["parent_style"] = $style->getSubstyleOf();
146  }else{
147  $values["active"] = ilSystemStyleSettings::_lookupActivatedStyle($skin->getId(),$style->getId());
148  $is_personal_style = $DIC->user()->getPref("skin")==$skin->getId() && $DIC->user()->getPref("style") == $style->getId();
149  $values["personal"] = $is_personal_style;
150  $is_default_style = ilSystemStyleSettings::getCurrentDefaultSkin()==$skin->getId() && ilSystemStyleSettings::getCurrentDefaultStyle() == $style->getId();
151  $values["default"] = $is_default_style;
152  }
153 
154  $form->setValuesByArray($values);
155  }
156 
157 
158  protected function save(){
159  $form = $this->editSystemStyleForm();
160 
161  $message_stack = new ilSystemStyleMessageStack();
162  if ($form->checkInput())
163  {
164 
165  try{
166  $system_style_conf = new ilSystemStyleConfig();
167  $skin = ilSkinXML::parseFromXML($system_style_conf->getCustomizingSkinPath().$_GET["skin_id"]."/template.xml");
168  $style = $skin->getStyle($_GET["style_id"]);
169 
170  if($style->isSubstyle()){
171  $this->saveSubStyle($message_stack);
172  }else{
173  $this->saveStyle($message_stack);
174  }
175 
176  $message_stack->prependMessage(new ilSystemStyleMessage($this->lng->txt("msg_sys_style_update"),ilSystemStyleMessage::TYPE_SUCCESS));
177  $message_stack->sendMessages(true);
178  $this->ctrl->redirectByClass("ilSystemStyleSettingsGUI");
179  }catch(ilSystemStyleException $e){
180  ilUtil::sendFailure($e->getMessage(), true);
181  }
182  }else
183 
184  $message_stack->sendMessages();
185 
186  $form->setValuesByPost();
187  $this->tpl->setContent($form->getHTML());
188  }
189 
190 
195  protected function saveStyle(ilSystemStyleMessageStack $message_stack){
196  global $DIC;
197 
198  $container = ilSystemStyleSkinContainer::generateFromId($_GET['skin_id'],$message_stack);
199  $old_skin = clone $container->getSkin();
200  $old_style = clone $old_skin->getStyle($_GET["style_id"]);
201 
202  $new_skin = $container->getSkin();
203  $new_skin->setId($_POST["skin_id"]);
204  $new_skin->setName($_POST["skin_name"]);
205  $new_skin->getVersionStep($_POST['skin_version']);
206 
207  $new_style = $new_skin->getStyle($_GET["style_id"]);
208  $new_style->setId($_POST["style_id"]);
209  $new_style->setName($_POST["style_name"]);
210  $new_style->setCssFile($_POST["style_id"]);
211  $new_style->setImageDirectory($_POST["image_dir"]);
212  $new_style->setSoundDirectory($_POST["sound_dir"]);
213  $new_style->setFontDirectory($_POST["font_dir"]);
214 
215  $container->updateSkin($old_skin);
216  $container->updateStyle($new_style->getId(),$old_style);
217 
218 
219  if($_POST["active"] == 1){
220  ilSystemStyleSettings::_activateStyle($new_skin->getId(),$new_style->getId());
221  if($_POST["personal"]==1){
222  ilSystemStyleSettings::setCurrentUserPrefStyle($new_skin->getId(),$new_style->getId());
223  }
224  if($_POST["default"]==1){
225  ilSystemStyleSettings::setCurrentDefaultStyle($new_skin->getId(),$new_style->getId());
226  }
227  }else{
228  ilSystemStyleSettings::_deactivateStyle($new_skin->getId(),$new_style->getId());
229  $_POST["personal"] = 0;
230  $_POST["default"] = 0;
231  }
232 
233  $system_style_conf = new ilSystemStyleConfig();
234 
235  //If style has been unset as personal style
236  if(!$_POST["personal"] && $DIC->user()->getPref("skin") == $new_skin->getId()){
237  //Reset to default if possible, else change to delos
238  if(!$_POST["default"] ){
241  );
242  }else{
244  $system_style_conf->getDefaultSkinId(),$system_style_conf->getDefaultStyleId()
245  );
246  }
247  $message_stack->addMessage(new ilSystemStyleMessage(
248  $this->lng->txt("personal_style_set_to")." ".ilSystemStyleSettings::getCurrentUserPrefSkin().":".ilSystemStyleSettings::getCurrentUserPrefStyle(),
250  );
251  }
252  if(!$_POST["default"] && ilSystemStyleSettings::getCurrentDefaultSkin() == $new_skin->getId()){
254  $system_style_conf->getDefaultSkinId(),$system_style_conf->getDefaultStyleId()
255  );
256  $message_stack->addMessage(new ilSystemStyleMessage(
257  $this->lng->txt("default_style_set_to")." ".$system_style_conf->getDefaultSkinId().": ".$system_style_conf->getDefaultStyleId(),
259  );
260  }
261  $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI','skin_id',$new_skin->getId());
262  $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI','style_id',$new_style->getId());
263  }
264 
269  protected function saveSubStyle(ilSystemStyleMessageStack $message_stack){
270  $container = ilSystemStyleSkinContainer::generateFromId($_GET['skin_id'],$message_stack);
271  $skin = $container->getSkin();
272  $old_substyle = clone $skin->getStyle($_GET["style_id"]);
273 
274  $new_substyle = $skin->getStyle($_GET["style_id"]);
275  $new_substyle->setId($_POST["style_id"]);
276  $new_substyle->setName($_POST["style_name"]);
277  $new_substyle->setCssFile($_POST["style_id"]);
278  $new_substyle->setImageDirectory($_POST["image_dir"]);
279  $new_substyle->setSoundDirectory($_POST["sound_dir"]);
280  $new_substyle->setFontDirectory($_POST["font_dir"]);
281  $new_substyle->setSubstyleOf($old_substyle->getSubstyleOf());
282 
283  $container->updateSkin($skin);
284  $container->updateStyle($new_substyle->getId(),$old_substyle);
285 
286  $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI','skin_id',$skin->getId());
287  $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI','style_id',$new_substyle->getId());
288  }
289 
294  protected function editSystemStyleForm(){
295  $form = new ilPropertyFormGUI();
296  $system_style_conf = new ilSystemStyleConfig();
297 
298  $skin = ilSkinXML::parseFromXML($system_style_conf->getCustomizingSkinPath().$_GET["skin_id"]."/template.xml");
299  $style = $skin->getStyle($_GET["style_id"]);
300 
301  $form->setFormAction($this->ctrl->getFormActionByClass("ilsystemstylesettingsgui"));
302 
303 
304  if(!$style->isSubstyle()){
305  $form->setTitle($this->lng->txt("skin"));
306 
307  $ti = new ilTextInputGUI($this->lng->txt("skin_id"), "skin_id");
308  $ti->setMaxLength(128);
309  $ti->setSize(40);
310  $ti->setRequired(true);
311  $ti->setInfo($this->lng->txt("skin_id_description"));
312  $form->addItem($ti);
313 
314  $ti = new ilTextInputGUI($this->lng->txt("skin_name"), "skin_name");
315  $ti->setInfo($this->lng->txt("skin_name_description"));
316  $ti->setMaxLength(128);
317  $ti->setSize(40);
318  $ti->setRequired(true);
319  $form->addItem($ti);
320 
321  if($skin->isVersionChangeable()) {
322  $ti = new ilNonEditableValueGUI($this->lng->txt("skin_version"), "skin_version");
323  $ti->setInfo($this->lng->txt("skin_version_description"));
324  $ti->setValue($skin->getVersion());
325  $form->addItem($ti);
326  }
327 
329  $section->setTitle($this->lng->txt("style"));
330  $form->addItem($section);
331  }else{
332  $form->setTitle($this->lng->txt("sub_style"));
333  }
334 
335  $ti = new ilTextInputGUI($this->lng->txt("style_id"), "style_id");
336  $ti->setMaxLength(128);
337  $ti->setSize(40);
338  $ti->setRequired(true);
339  $ti->setInfo($this->lng->txt("style_id_description"));
340  $form->addItem($ti);
341 
342  $ti = new ilTextInputGUI($this->lng->txt("style_name"), "style_name");
343  $ti->setMaxLength(128);
344  $ti->setSize(40);
345  $ti->setRequired(true);
346  $ti->setInfo($this->lng->txt("style_name_description"));
347  $form->addItem($ti);
348 
349  $ti = new ilTextInputGUI($this->lng->txt("image_dir"), "image_dir");
350  $ti->setMaxLength(128);
351  $ti->setSize(40);
352  $ti->setInfo($this->lng->txt("image_dir_description"));
353  $form->addItem($ti);
354 
355  $ti = new ilTextInputGUI($this->lng->txt("font_dir"), "font_dir");
356  $ti->setMaxLength(128);
357  $ti->setSize(40);
358  $ti->setInfo($this->lng->txt("font_dir_description"));
359  $form->addItem($ti);
360 
361  $ti = new ilTextInputGUI($this->lng->txt("sound_dir"), "sound_dir");
362  $ti->setMaxLength(128);
363  $ti->setSize(40);
364  $ti->setInfo($this->lng->txt("sound_dir_description"));
365  $form->addItem($ti);
366 
367  if(!$style->isSubstyle()){
369  $section->setTitle($this->lng->txt("system_style_activation"));
370  $form->addItem($section);
371 
372  $active = new ilCheckboxInputGUI($this->lng->txt("system_style_activation"), "active");
373  $active->setInfo($this->lng->txt("system_style_activation_description"));
374 
375  $set_default = new ilCheckboxInputGUI($this->lng->txt("default"), "default");
376  $set_default->setInfo($this->lng->txt("system_style_default_description"));
377  $active->addSubItem($set_default);
378 
379  $set_personal = new ilCheckboxInputGUI($this->lng->txt("personal"), "personal");
380  $set_personal->setInfo($this->lng->txt("system_style_personal_description"));
381  $active->addSubItem($set_personal);
382 
383 
384  $form->addItem($active);
385  }
386 
387  $form->addCommandButton("save", $this->lng->txt("save"));
388  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
389 
390  return $form;
391  }
392 }
static _deactivateStyle($a_skin, $a_style)
deactivate system style
$style
Definition: example_012.php:70
This class represents a property form user interface.
static getCurrentUserPrefSkin()
Gets a users preferred skin by using the user object.
static getCurrentDefaultSkin()
Gets default Skin of the System.
$_GET["client_id"]
This class represents a section header in a property form.
static setCurrentDefaultStyle($skin_id, $style_id)
Sets the default style of the system.
static getCurrentUserPrefStyle()
Gets a users preferred style by using the user object.
setInfo($a_info)
Set Information Text.
$cmd
Definition: sahs_server.php:35
This class represents a checkbox property in a property form.
addMessage(ilSystemStyleMessage $message)
Add a message to be displayed by the stack.
static _lookupActivatedStyle($a_skin, $a_style)
lookup if a style is activated
setInfo($a_info)
Set Information Text.
$section
Definition: Utf8Test.php:83
This class represents a text property in a property form.
setMaxLength($a_maxlength)
Set Max Length.
Class for advanced editing exception handling in ILIAS.
static setCurrentUserPrefStyle($skin_id, $style_id)
Sets a users preferred system skin/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.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
ilSystemStyleConfig wraps all &#39;constants&#39; to ensure the testability of all classes using those &#39;const...
static _activateStyle($a_skin, $a_style)
activate system style
This class represents a non editable value in a property form.
Used to stack messages to be shown to the user.
global $DIC
getPropertiesValues($form)
Get values for edit properties form.
static getCurrentDefaultStyle()
Gets default style of the system.
saveStyle(ilSystemStyleMessageStack $message_stack)
saveSubStyle(ilSystemStyleMessageStack $message_stack)
$_POST["username"]