ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjStyleSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Services/Object/classes/class.ilObjectGUI.php";
5 include_once("./Services/Style/classes/class.ilPageLayout.php");
6 
18 {
19  //page_layout editing
20  var $peditor_active = false;
21  var $pg_id = null;
22 
26  function ilObjStyleSettingsGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output = true)
27  {
28  global $lng,$ilCtrl;
29 
30  $this->type = "stys";
31 
32  $cmd = $ilCtrl->getCmd();
33 
34  if ($cmd == "editPg") {
35  $this->peditor_active = true;
36  }
37 
38  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output);
39 
40  $lng->loadLanguageModule("style");
41  }
42 
46  function &executeCommand()
47  {
48  $next_class = $this->ctrl->getNextClass($this);
49  $cmd = $this->ctrl->getCmd();
50 
51  if ($next_class == "ilpagelayoutgui" || $cmd =="createPg") {
52  $this->peditor_active =true;
53  }
54 
55  $this->prepareOutput();
56 
57  switch($next_class)
58  {
59  case 'ilpermissiongui':
60  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
61  $perm_gui =& new ilPermissionGUI($this);
62  $ret =& $this->ctrl->forwardCommand($perm_gui);
63  break;
64 
65  case 'ilpagelayoutgui':
66  include_once("./Services/Style/classes/class.ilPageLayoutGUI.php");
67  $this->tpl->getStandardTemplate();
68  $this->ctrl->setReturn($this, "edit");
69  if ($this->pg_id!=null) {
70  $layout_gui =& new ilPageLayoutGUI($this->type,$this->pg_id);
71  } else {
72  $layout_gui =& new ilPageLayoutGUI($this->type,$_GET["obj_id"]);
73  }
74  $layout_gui->setTabs();
75  $layout_gui->setEditPreview(true);
76  $this->ctrl->saveParameter($this, "obj_id");
77  $ret =& $this->ctrl->forwardCommand($layout_gui);
78  $this->tpl->setContent($ret);
79  break;
80 
81  default:
82  if ($cmd == "" || $cmd == "view")
83  {
84  $cmd = "editSystemStyles";
85  }
86  $cmd .= "Object";
87  $this->$cmd();
88 
89  break;
90  }
91  return true;
92  }
93 
97  function saveObject()
98  {
99  global $rbacadmin;
100 
101  // create and insert forum in objecttree
102  $newObj = parent::saveObject();
103 
104  // put here object specific stuff
105 
106  // always send a message
107  ilUtil::sendInfo($this->lng->txt("object_added"),true);
108 
109  ilUtil::redirect($this->getReturnLocation("save",$this->ctrl->getLinkTarget($this,"","",false,false)));
110  }
111 
116  {
117  global $rbacsystem, $ilias, $tpl, $ilToolbar, $ilCtrl, $lng;
118 
119  if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
120  {
121  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
122  }
123 
124  // this may not be cool, if styles are organised as (independent) Service
125  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
126  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
127 
128  $from_styles = $to_styles = $data = array();
129  $styles = $this->object->getStyles();
130 
131  foreach($styles as $style)
132  {
133  $style["active"] = ilObjStyleSheet::_lookupActive($style["id"]);
134  $style["lm_nr"] = ilObjContentObject::_getNrOfAssignedLMs($style["id"]);
135  $data[$style["title"].":".$style["id"]]
136  = $style;
137  if ($style["lm_nr"] > 0)
138  {
139  $from_styles[$style["id"]] = $style["title"];
140  }
141  if ($style["active"] > 0)
142  {
143  $to_styles[$style["id"]] = $style["title"];
144  }
145  }
146 
147  // number of individual styles
148  if ($fixed_style <= 0)
149  {
150  $data[-1] =
151  array("title" => $this->lng->txt("sty_individual_styles"),
152  "id" => 0, "lm_nr" => ilObjContentObject::_getNrLMsIndividualStyles());
153  $from_styles[-1] = $this->lng->txt("sty_individual_styles");
154  }
155 
156  // number of default style (fallback default style)
157  if ($default_style <= 0 && $fixed_style <= 0)
158  {
159  $data[0] =
160  array("title" => $this->lng->txt("sty_default_style"),
161  "id" => 0, "lm_nr" => ilObjContentObject::_getNrLMsNoStyle());
162  $from_styles[0] = $this->lng->txt("sty_default_style");
163  $to_styles[0] = $this->lng->txt("sty_default_style");
164  }
165 
166  if ($rbacsystem->checkAccess("write",$this->object->getRefId()))
167  {
168  $ilToolbar->addButton($lng->txt("sty_add_content_style"),
169  $ilCtrl->getLinkTarget($this, "createStyle"));
170  $ilToolbar->addSeparator();
171  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
172 
173  // from styles selector
174  $si = new ilSelectInputGUI($lng->txt("sty_move_lm_styles").": ".$lng->txt("sty_from"), "from_style");
175  $si->setOptions($from_styles);
176  $ilToolbar->addInputItem($si, true);
177 
178  // from styles selector
179  $si = new ilSelectInputGUI($lng->txt("sty_to"), "to_style");
180  $si->setOptions($to_styles);
181  $ilToolbar->addInputItem($si, true);
182  $ilToolbar->addFormButton($lng->txt("sty_move_style"), "moveLMStyles");
183 
184  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
185  }
186 
187  include_once("./Services/Style/classes/class.ilContentStylesTableGUI.php");
188  $table = new ilContentStylesTableGUI($this, "editContentStyles", $data, $this->object);
189  $tpl->setContent($table->getHTML());
190 
191  }
192 
197  {
198  if ($_POST["from_style"] == -1)
199  {
201  return;
202  }
203 
204  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
205  ilObjContentObject::_moveLMStyles($_POST["from_style"], $_POST["to_style"]);
206  $this->ctrl->redirect($this, "editContentStyles");
207  }
208 
209 
214  {
215  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
216  ilObjContentObject::_moveLMStyles(-1, $_GET["to_style"]);
217  $this->ctrl->redirect($this, "editContentStyles");
218  }
219 
224  {
225  global $ilCtrl, $tpl, $lng;
226 
227  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
228 
229  $ilCtrl->setParameter($this, "to_style", $_POST["to_style"]);
230 
231  $cgui = new ilConfirmationGUI();
232  $cgui->setFormAction($ilCtrl->getFormAction($this));
233  $cgui->setHeaderText($lng->txt("sty_confirm_del_ind_styles").": ".
234  sprintf($this->lng->txt("sty_confirm_del_ind_styles_desc"),
235  ilObject::_lookupTitle($_POST["to_style"])));
236  $cgui->setCancel($lng->txt("cancel"), "editContentStyles");
237  $cgui->setConfirm($lng->txt("ok"), "moveIndividualStyles");
238  $tpl->setContent($cgui->getHTML());
239  }
240 
245  {
246  global $rbacsystem, $ilias, $styleDefinition, $ilToolbar, $ilCtrl, $lng, $tpl;
247 
248  if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
249  {
250  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
251  }
252 
253  // toolbar
254 
255  // default skin/style
256  if ($rbacsystem->checkAccess("write",$this->object->getRefId()))
257  {
258  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
259 
260  $options = array();
261  foreach (ilStyleDefinition::getAllSkinStyles() as $st)
262  {
263  $options[$st["id"]] = $st["title"];
264  }
265 
266  // from styles selector
267  $si = new ilSelectInputGUI($lng->txt("sty_move_user_styles").": ".$lng->txt("sty_from"), "from_style");
268  $si->setOptions($options + array("other" => $lng->txt("other")));
269  $ilToolbar->addInputItem($si, true);
270 
271  // from styles selector
272  $si = new ilSelectInputGUI($lng->txt("sty_to"), "to_style");
273  $si->setOptions($options);
274  $ilToolbar->addInputItem($si, true);
275  $ilToolbar->addFormButton($lng->txt("sty_move_style"), "moveUserStyles");
276 
277  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
278  }
279 
280  include_once("./Services/Style/classes/class.ilSystemStylesTableGUI.php");
281  $tab = new ilSystemStylesTableGUI($this, "editSystemStyles");
282  $tpl->setContent($tab->getHTML());
283 
284  }
285 
286 
291  {
292  global $styleDefinition, $ilCtrl;
293 
294  // check if one style is activated
295  if (count($_POST["st_act"]) < 1)
296  {
297  $this->ilias->raiseError($this->lng->txt("at_least_one_style"), $this->ilias->error_obj->MESSAGE);
298  }
299 
300  //set default skin and style
301  if ($_POST["default_skin_style"] != "")
302  {
303  $sknst = explode(":", $_POST["default_skin_style"]);
304 
305  if ($this->ilias->ini->readVariable("layout","style") != $sknst[1] ||
306  $this->ilias->ini->readVariable("layout","skin") != $sknst[0])
307  {
308  $this->ilias->ini->setVariable("layout","skin", $sknst[0]);
309  $this->ilias->ini->setVariable("layout","style",$sknst[1]);
310  }
311  $this->ilias->ini->write();
312  }
313 
314  // check if a style should be deactivated, that still has
315  // a user assigned to
316  $all_styles = ilStyleDefinition::getAllSkinStyles();
317  foreach ($all_styles as $st)
318  {
319  if (!isset($_POST["st_act"][$st["id"]]))
320  {
321  if (ilObjUser::_getNumberOfUsersForStyle($st["template_id"], $st["style_id"]) > 1)
322  {
323  $this->ilias->raiseError($this->lng->txt("cant_deactivate_if_users_assigned"), $this->ilias->error_obj->MESSAGE);
324  }
325  else
326  {
327  ilObjStyleSettings::_deactivateStyle($st["template_id"], $st["style_id"]);
328  }
329  }
330  else
331  {
332  ilObjStyleSettings::_activateStyle($st["template_id"], $st["style_id"]);
333  }
334  }
335 
336  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
337  $ilCtrl->redirect($this , "editSystemStyles");
338  }
339 
347  {
348  global $ilCtrl, $lng;
349 
350  $to = explode(":", $_POST["to_style"]);
351 
352  if ($_POST["from_style"] != "other")
353  {
354  $from = explode(":", $_POST["from_style"]);
355  ilObjUser::_moveUsersToStyle($from[0],$from[1],$to[0],$to[1]);
356  }
357  else
358  {
359  // get all user assigned styles
360  $all_user_styles = ilObjUser::_getAllUserAssignedStyles();
361 
362  // move users that are not assigned to
363  // currently existing style
364  foreach($all_user_styles as $style)
365  {
366  if (!in_array($style, $all_styles))
367  {
368  $style_arr = explode(":", $style);
369  ilObjUser::_moveUsersToStyle($style_arr[0],$style_arr[1],$to[0],$to[1]);
370  }
371  }
372  }
373 
374  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
375  $ilCtrl->redirect($this , "editSystemStyles");
376  }
377 
378 
379 
385  function deleteStyleObject($a_error = false)
386  {
387  if (!isset($_POST["id"]))
388  {
389  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
390  }
391 
392  // display confirmation message
393  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
394  $cgui = new ilConfirmationGUI();
395  $cgui->setFormAction($this->ctrl->getFormAction($this));
396  $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
397  $cgui->setCancel($this->lng->txt("cancel"), "cancelDelete");
398  $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDelete");
399 
400  foreach ($_POST["id"] as $id)
401  {
402  $caption = ilUtil::getImageTagByType("sty", $this->tpl->tplPath).
403  " ".ilObject::_lookupTitle($id);
404 
405  $cgui->addItem("id[]", $id, $caption);
406  }
407 
408  $this->tpl->setContent($cgui->getHTML());
409  }
410 
411 
416  {
417  global $ilias;
418 
419  foreach($_POST["id"] as $id)
420  {
421  $this->object->removeStyle($id);
422  $style_obj =& $ilias->obj_factory->getInstanceByObjId($id);
423  $style_obj->delete();
424  }
425  $this->object->update();
426 
427  ilUtil::redirect($this->getReturnLocation("delete",
428  $this->ctrl->getLinkTarget($this,"editContentStyles","",false,false)));
429  }
430 
431 
436  {
437  global $ilSetting, $lng;
438 
439  if ($_GET["id"] > 0)
440  {
441  $ilSetting->delete("fixed_content_style_id");
442  $def_style = $ilSetting->get("default_content_style_id");
443 
444  if ($def_style != $_GET["id"])
445  {
446  $ilSetting->set("default_content_style_id", (int) $_GET["id"]);
447  }
448  else
449  {
450  $ilSetting->delete("default_content_style_id");
451  }
452  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
453  }
454  ilUtil::redirect($this->ctrl->getLinkTarget($this, "editContentStyles", "", false, false));
455  }
456 
461  {
462  global $ilSetting, $lng;
463 
464  if ($_GET["id"] > 0)
465  {
466  $ilSetting->delete("default_content_style_id");
467  $fixed_style = $ilSetting->get("fixed_content_style_id");
468  if ($fixed_style == (int) $_GET["id"])
469  {
470  $ilSetting->delete("fixed_content_style_id");
471  }
472  else
473  {
474  $ilSetting->set("fixed_content_style_id", (int) $_GET["id"]);
475  }
476  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
477  }
478  ilUtil::redirect($this->ctrl->getLinkTarget($this, "editContentStyles", "", false, false));
479  }
480 
481 
486  {
487  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
488  $styles = $this->object->getStyles();
489  foreach($styles as $style)
490  {
491  if ($_POST["std_".$style["id"]] == 1)
492  {
493  ilObjStyleSheet::_writeActive((int) $style["id"], 1);
494  }
495  else
496  {
497  ilObjStyleSheet::_writeActive((int) $style["id"], 0);
498  }
499  }
500  ilUtil::redirect($this->ctrl->getLinkTarget($this, "editContentStyles", "", false, false));
501  }
502 
509  function showActions($with_subobjects = false)
510  {
511 
512  // delete
513  $this->tpl->setCurrentBlock("tbl_action_btn");
514  $this->tpl->setVariable("BTN_NAME", "deleteStyle");
515  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
516  $this->tpl->parseCurrentBlock();
517 
518  // set global default
519  $this->tpl->setCurrentBlock("tbl_action_btn");
520  $this->tpl->setVariable("BTN_NAME", "toggleGlobalDefault");
521  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalDefault"));
522  $this->tpl->parseCurrentBlock();
523 
524  // set global default
525  $this->tpl->setCurrentBlock("tbl_action_btn");
526  $this->tpl->setVariable("BTN_NAME", "toggleGlobalFixed");
527  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalFixed"));
528  $this->tpl->parseCurrentBlock();
529 
530  // set global default
531  $this->tpl->setCurrentBlock("tbl_action_btn");
532  $this->tpl->setVariable("BTN_NAME", "setScope");
533  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("sty_set_scope"));
534  $this->tpl->parseCurrentBlock();
535 
536  // save active styles
537  $this->tpl->setCurrentBlock("tbl_action_btn");
538  $this->tpl->setVariable("BTN_NAME", "saveActiveStyles");
539  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("sty_save_active_styles"));
540  $this->tpl->parseCurrentBlock();
541 
542  if ($with_subobjects === true)
543  {
544  $this->showPossibleSubObjects();
545  }
546 
547  $this->tpl->setCurrentBlock("tbl_action_row");
548  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.png"));
549  $this->tpl->parseCurrentBlock();
550  }
551 
558  {
559  ilUtil::sendInfo($this->lng->txt("msg_cancel"),true);
560  $this->ctrl->redirect($this, "editContentStyles");
561 
562  }
563 
564  function setScopeObject()
565  {
566  if ($_GET["id"] > 0)
567  {
568  include_once ("./Services/Style/classes/class.ilStyleScopeExplorer.php");
569  $exp = new ilStyleScopeExplorer("ilias.php?baseClass=ilRepositoryGUI&amp;cmd=goto");
570  $exp->setExpandTarget("ilias.php?baseClass=ilRepositoryGUI&amp;cmd=showTree");
571  $exp->setTargetGet("ref_id");
572  $exp->setFilterMode(IL_FM_POSITIVE);
573  $exp->forceExpandAll(true, false);
574  $exp->addFilter("root");
575  $exp->addFilter("cat");
576 
577  if ($_GET["expand"] == "")
578  {
579  $expanded = $this->tree->readRootId();
580  }
581  else
582  {
583  $expanded = $_GET["expand"];
584  }
585 
586  $exp->setExpand($expanded);
587 
588  // build html-output
589  $exp->setOutput(0);
590  $output = $exp->getOutput();
591  }
592 
593  $this->tpl->setVariable("ADM_CONTENT", $output);
594  }
595 
599  function saveScopeObject()
600  {
601  global $ilias;
602 
603  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
604  if ($_GET["cat"] == 0)
605  {
606  $_GET["cat"] == "";
607  }
608  ilObjStyleSheet::_writeScope($_GET["style_id"], $_GET["cat"]);
609 
610  ilUtil::redirect($this->ctrl->getLinkTarget($this, "editContentStyles", "", false, false));
611  }
612 
613 
618  {
619  global $tpl, $lng, $ilCtrl, $ilTabs, $ilToolbar, $rbacsystem;
620 
621  $ilTabs->setTabActive('page_layouts');
622 
623  // show toolbar, if write permission is given
624  if ($rbacsystem->checkAccess("write",$this->object->getRefId()))
625  {
626  $ilToolbar->addButton($lng->txt("sty_add_pgl"),
627  $ilCtrl->getLinkTarget($this, "addPageLayout"));
628  $ilToolbar->addButton($lng->txt("sty_import_page_layout"),
629  $ilCtrl->getLinkTarget($this, "importPageLayoutForm"));
630  }
631 
632  $oa_tpl = new ilTemplate("tpl.stys_pglayout.html", true, true, "Services/Style");
633 
634  include_once("./Services/Style/classes/class.ilPageLayoutTableGUI.php");
635  $pglayout_table = new ilPageLayoutTableGUI($this, "viewPageLayouts");
636  $oa_tpl->setVariable("PGLAYOUT_TABLE", $pglayout_table->getHTML());
637  $tpl->setContent($oa_tpl->get());
638 
639  }
640 
641 
642  function activateObject($a_activate=true){
643  if (!isset($_POST["pglayout"]))
644  {
645  ilUtil::sendInfo($this->lng->txt("no_checkbox"),true);
646  } else {
647  ilUtil::sendSuccess($this->lng->txt("sty_opt_saved"),true);
648  foreach ($_POST["pglayout"] as $item)
649  {
650  $pg_layout = new ilPageLayout($item);
651  $pg_layout->activate($a_activate);
652  }
653  }
654  $this->ctrl->redirect($this, "viewPageLayouts");
655  }
656 
657  function deactivateObject(){
658  $this->activateObject(false);
659  }
660 
661 
662 
666  function deletePglObject()
667  {
668  global $ilTabs;
669 
670  if(!isset($_POST["pglayout"]))
671  {
672  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
673  }
674 
675  $ilTabs->setTabActive('page_layouts');
676  unset($this->data);
677 
678  // display confirmation message
679  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
680  $cgui = new ilConfirmationGUI();
681  $cgui->setFormAction($this->ctrl->getFormAction($this));
682  $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
683  $cgui->setCancel($this->lng->txt("cancel"), "cancelDeletePg");
684  $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDeletePg");
685 
686  foreach($_POST["pglayout"] as $id)
687  {
688  $pg_obj = new ilPageLayout($id);
689  $pg_obj->readObject();
690 
691  $caption = ilUtil::getImageTagByType("stys", $this->tpl->tplPath).
692  " ".$pg_obj->getTitle();
693 
694  $cgui->addItem("pglayout[]", $id, $caption);
695  }
696 
697  $this->tpl->setContent($cgui->getHTML());
698  }
699 
704  {
705  ilUtil::sendInfo($this->lng->txt("msg_cancel"),true);
706  $this->ctrl->redirect($this, "viewPageLayouts");
707  }
708 
713  {
714  foreach ($_POST["pglayout"] as $id)
715  {
716  $pg_obj = new ilPageLayout($id);
717  $pg_obj->delete();
718  }
719 
720  $this->ctrl->redirect($this, "viewPageLayouts");
721  }
722 
723  function addPageLayoutObject($a_form = null)
724  {
725  global $ilTabs;
726 
727  $ilTabs->setTabActive('page_layouts');
728 
729  if(!$a_form)
730  {
731  $a_form = $this->initAddPageLayoutForm();
732  }
733 
734  $this->tpl->setContent($a_form->getHTML());
735  }
736 
738  {
739  global $lng, $ilCtrl;
740 
741  $lng->loadLanguageModule("content");
742 
743  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
744  $form_gui = new ilPropertyFormGUI();
745  $form_gui->setFormAction($ilCtrl->getFormAction($this));
746  $form_gui->setTitle($lng->txt("sty_create_pgl"));
747 
748  $title_input = new ilTextInputGUI($lng->txt("title"),"pgl_title");
749  $title_input->setSize(50);
750  $title_input->setMaxLength(128);
751  $title_input->setValue($this->layout_object->title);
752  $title_input->setTitle($lng->txt("title"));
753  $title_input->setRequired(true);
754 
755  $desc_input = new ilTextAreaInputGUI($lng->txt("description"),"pgl_desc");
756  $desc_input->setValue($this->layout_object->description);
757  $desc_input->setRows(3);
758  $desc_input->setCols(37);
759 
760  // special page?
761  $options = array(
762  "0" => $lng->txt("cont_layout_template"),
763  "1" => $lng->txt("cont_special_page"),
764  );
765  $si = new ilSelectInputGUI($this->lng->txt("type"), "special_page");
766  $si->setOptions($options);
767 
768  // modules
769  $mods = new ilCheckboxGroupInputGUI($this->lng->txt("modules"), "module");
770  // $mods->setRequired(true);
771  foreach(ilPageLayout::getAvailableModules() as $mod_id => $mod_caption)
772  {
773  $mod = new ilCheckboxOption($mod_caption, $mod_id);
774  $mods->addOption($mod);
775  }
776 
777  $ttype_input = new ilSelectInputGUI($lng->txt("sty_based_on"), "pgl_template");
778 
779  $arr_templates = ilPageLayout::getLayouts();
780  $arr_templates1 = ilPageLayout::getLayouts(false, true);
781  foreach ($arr_templates1 as $v)
782  {
783  $arr_templates[] = $v;
784  }
785 
786  $options = array();
787  $options['-1'] = $lng->txt("none");
788 
789  foreach ($arr_templates as $templ) {
790  $templ->readObject();
791  $key = $templ->getId();
792  $value = $templ->getTitle();
793  $options[$key] = $value;
794  }
795 
796  $ttype_input->setOptions($options);
797  $ttype_input->setValue(-1);
798  $ttype_input->setRequired(true);
799 
800  $desc_input->setTitle($lng->txt("description"));
801  $desc_input->setRequired(false);
802 
803  $form_gui->addItem($title_input);
804  $form_gui->addItem($desc_input);
805  $form_gui->addItem($si);
806  $form_gui->addItem($mods);
807  $form_gui->addItem($ttype_input);
808 
809 
810  $form_gui->addCommandButton("createPg", $lng->txt("save"));
811  $form_gui->addCommandButton("cancelCreate", $lng->txt("cancel"));
812 
813  return $form_gui;
814  }
815 
816 
817  function createPgObject()
818  {
819  global $ilCtrl;
820 
821  $form_gui = $this->initAddPageLayoutForm();
822  if(!$form_gui->checkInput())
823  {
824  $form_gui->setValuesByPost();
825  return $this->addPageLayoutObject($form_gui);
826  }
827 
828  //create Page-Layout-Object first
829  $pg_object = new ilPageLayout();
830  $pg_object->setTitle($form_gui->getInput('pgl_title'));
831  $pg_object->setDescription($form_gui->getInput('pgl_desc'));
832  $pg_object->setSpecialPage($form_gui->getInput('special_page'));
833  $pg_object->setModules($form_gui->getInput('module'));
834  $pg_object->update();
835 
836  include_once("./Services/Style/classes/class.ilPageLayoutPage.php");
837 
838  //create Page
839  if(!is_object($pg_content))
840  {
841  $this->pg_content = new ilPageLayoutPage();
842  }
843 
844  $this->pg_content->setId($pg_object->getId());
845 
846  $tmpl = $form_gui->getInput('pgl_template');
847  if ($tmpl != "-1")
848  {
849  $layout_obj = new ilPageLayout($tmpl);
850  $this->pg_content->setXMLContent($layout_obj->getXMLContent());
851  $this->pg_content->create(false);
852  }
853  else
854  {
855  $this->pg_content->create(false);
856  }
857 
858  $ilCtrl->setParameterByClass("ilpagelayoutgui", "obj_id", $pg_object->getId());
859  $ilCtrl->redirectByClass("ilpagelayoutgui", "edit");
860  }
861 
862  function cancelCreateObject() {
863  $this->viewPageLayoutsObject();
864  }
865 
866  function editPgObject()
867  {
868  global $ilCtrl, $rbacsystem;
869 
870  if (!$rbacsystem->checkAccess("write",$this->object->getRefId()))
871  {
872  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
873  }
874 
875  $ilCtrl->setCmdClass("ilpagelayoutgui");
876  $ilCtrl->setCmd("edit");
877  $this->executeCommand();
878  }
879 
880 
881  function setTabs()
882  {
883  echo "settings_setTabs";
884  }
885 
886  function getAdminTabs(&$tabs_gui)
887  {
888  $this->getTabs($tabs_gui);
889  }
890 
896  function getTabs(&$tabs_gui)
897  {
898  global $rbacsystem, $lng, $ilTabs;
899 
900  if ($this->peditor_active) {
901  $tabs_gui->setBackTarget($this->lng->txt("page_layouts"),
902  $this->ctrl->getLinkTarget($this, "viewPageLayouts"));
903  }
904 
905  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()) && !$this->peditor_active)
906  {
907  $tabs_gui->addTarget("system_styles",
908  $this->ctrl->getLinkTarget($this, "editSystemStyles"), array("editSystemStyles", "", "view"), "", "");
909 
910  $tabs_gui->addTarget("content_styles",
911  $this->ctrl->getLinkTarget($this, "editContentStyles"), "editContentStyles", "", "");
912 
913  $tabs_gui->addTarget("page_layouts",
914  $this->ctrl->getLinkTarget($this, "viewPageLayouts"), "viewPageLayouts", "", "");
915 
916  }
917 
918 
919  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()) && !$this->peditor_active)
920  {
921  $tabs_gui->addTarget("perm_settings",
922  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
923  }
924  }
925 
929  function createStyleObject()
930  {
931  global $ilCtrl;
932 
933  $ilCtrl->setParameter($this, "new_type", "sty");
934  $ilCtrl->redirect($this, "create");
935  }
936 
941  {
942  global $lng, $ilCtrl;
943 
944  include_once("./Services/Style/classes/class.ilPageLayout.php");
945 
946  if (is_array($_POST["type"]))
947  {
948  foreach($_POST["type"] as $id => $t)
949  {
950  if ($id > 0)
951  {
952  $l = new ilPageLayout($id);
953  $l->readObject();
954  $l->setSpecialPage($t);
955  if(is_array($_POST["module"][$id]))
956  {
957  $l->setModules(array_keys($_POST["module"][$id]));
958  }
959  else
960  {
961  $l->setModules();
962  }
963  $l->update();
964  }
965  }
966 
967  ilUtil::sendSuccess($lng->txt("msg_obj_modified"));
968  }
969 
970  $ilCtrl->redirect($this, "viewPageLayouts");
971  }
972 
973 
978  {
979  include_once("./Services/Export/classes/class.ilExport.php");
980  $exp = new ilExport();
981 
982  $tmpdir = ilUtil::ilTempnam();
983  ilUtil::makeDir($tmpdir);
984 
985  $succ = $exp->exportEntity("pgtp", (int) $_GET["layout_id"], "4.2.0",
986  "Services/COPage", "Title", $tmpdir);
987 
988  if ($succ["success"])
989  {
990  ilUtil::deliverFile($succ["directory"]."/".$succ["file"], $succ["file"],
991  "", false, false, false);
992  }
993  if (is_file($succ["directory"]."/".$succ["file"]))
994  {
995  unlink($succ["directory"]."/".$succ["file"]);
996  }
997  if (is_dir($succ["directory"]))
998  {
999  unlink($succ["directory"]);
1000  }
1001  }
1002 
1007  {
1008  global $tpl, $ilTabs;
1009 
1010  $ilTabs->setTabActive('page_layouts');
1011  $form = $this->initPageLayoutImportForm();
1012  $tpl->setContent($form->getHTML());
1013  }
1014 
1018  public function initPageLayoutImportForm()
1019  {
1020  global $lng, $ilCtrl;
1021 
1022  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1023  $form = new ilPropertyFormGUI();
1024 
1025  // template file
1026  $fi = new ilFileInputGUI($lng->txt("file"), "file");
1027  $fi->setSuffixes(array("zip"));
1028  $fi->setRequired(true);
1029  $form->addItem($fi);
1030 
1031  $form->addCommandButton("importPageLayout", $lng->txt("import"));
1032  $form->addCommandButton("viewPageLayouts", $lng->txt("cancel"));
1033 
1034  $form->setTitle($lng->txt("sty_import_page_layout"));
1035  $form->setFormAction($ilCtrl->getFormAction($this));
1036 
1037  return $form;
1038  }
1039 
1043  public function importPageLayoutObject()
1044  {
1045  global $tpl, $lng, $ilCtrl, $ilTabs;
1046 
1047  $form = $this->initPageLayoutImportForm();
1048  if ($form->checkInput())
1049  {
1050  include_once("./Services/Style/classes/class.ilPageLayout.php");
1051  $pg = ilPageLayout::import($_FILES["file"]["name"], $_FILES["file"]["tmp_name"]);
1052  if ($pg > 0)
1053  {
1054  ilUtil::sendSuccess($lng->txt("sty_imported_layout"), true);
1055  }
1056  $ilCtrl->redirect($this, "viewPageLayouts");
1057  }
1058  else
1059  {
1060  $ilTabs->setTabActive('page_layouts');
1061  $form->setValuesByPost();
1062  $tpl->setContent($form->getHtml());
1063  }
1064  }
1065 
1073  {
1074  global $ilToolbar, $ilCtrl, $tpl, $lng, $rbacsystem;
1075 
1076  $ilCtrl->setParameter($this, "style_id", urlencode($_GET["style_id"]));
1077 
1078  if (!$rbacsystem->checkAccess("write", $this->object->getRefId()))
1079  {
1080  return;
1081  }
1082 
1083  $all_styles = ilStyleDefinition::getAllSkinStyles();
1084  $sel_style = $all_styles[$_GET["style_id"]];
1085 
1086  $options = array();
1087  if (is_array($sel_style["substyle"]))
1088  {
1089  foreach ($sel_style["substyle"] as $subst)
1090  {
1091  $options[$subst["id"]] = $subst["name"];
1092  }
1093  }
1094 
1095  // substyle
1096  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1097  $si = new ilSelectInputGUI($this->lng->txt("sty_substyle"), "substyle");
1098  $si->setOptions($options);
1099  $ilToolbar->addInputItem($si, true);
1100 
1101  $ilToolbar->addFormButton($lng->txt("sty_add_assignment"), "addStyleCatAssignment");
1102  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
1103 
1104  include_once("./Services/Style/classes/class.ilSysStyleCatAssignmentTableGUI.php");
1105  $tab = new ilSysStyleCatAssignmentTableGUI($this, "assignStylesToCats");
1106 
1107  $tpl->setContent($tab->getHTML());
1108  }
1109 
1110 
1118  {
1119  global $ilCtrl, $ilTabs, $lng, $tree, $tpl, $rbacsystem;
1120 
1121  if (!$rbacsystem->checkAccess("write", $this->object->getRefId()))
1122  {
1123  return;
1124  }
1125 
1126  $ilCtrl->setParameter($this, "style_id", urlencode($_GET["style_id"]));
1127  $ilCtrl->setParameter($this, "substyle", urlencode($_REQUEST["substyle"]));
1128 
1129  include_once 'Services/Search/classes/class.ilSearchRootSelector.php';
1130  $exp = new ilSearchRootSelector(
1131  $ilCtrl->getLinkTarget($this,'addStyleCatAssignment'));
1132  $exp->setExpand($_GET["search_root_expand"] ? $_GET["search_root_expand"] : $tree->readRootId());
1133  $exp->setExpandTarget($ilCtrl->getLinkTarget($this,'addStyleCatAssignment'));
1134  $exp->setTargetClass(get_class($this));
1135  $exp->setCmd('saveStyleCatAssignment');
1136  $exp->setClickableTypes(array("cat"));
1137 
1138  // build html-output
1139  $exp->setOutput(0);
1140  $tpl->setContent($exp->getOutput());
1141  }
1142 
1143 
1151  {
1152  global $lng, $ilCtrl, $rbacsystem;
1153 
1154  if (!$rbacsystem->checkAccess("write", $this->object->getRefId()))
1155  {
1156  return;
1157  }
1158 
1159  $ilCtrl->setParameter($this, "style_id", urlencode($_GET["style_id"]));
1160 
1161  $style_arr = explode(":", $_GET["style_id"]);
1162  ilStyleDefinition::writeSystemStyleCategoryAssignment($style_arr[0], $style_arr[1],
1163  $_GET["substyle"], $_GET["root_id"]);
1164  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1165 
1166  $ilCtrl->redirect($this, "assignStylesToCats");
1167  }
1168 
1173  {
1174  global $ilCtrl, $lng, $rbacsystem;
1175 
1176  if (!$rbacsystem->checkAccess("write", $this->object->getRefId()))
1177  {
1178  return;
1179  }
1180 
1181  $ilCtrl->setParameter($this, "style_id", urlencode($_GET["style_id"]));
1182  $style_arr = explode(":", $_GET["style_id"]);
1183  if (is_array($_POST["id"]))
1184  {
1185  foreach ($_POST["id"] as $id)
1186  {
1187  $id_arr = explode(":", $id);
1188  ilStyleDefinition::deleteSystemStyleCategoryAssignment($style_arr[0], $style_arr[1],
1189  $id_arr[0], $id_arr[1]);
1190  }
1191  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1192  }
1193 
1194  $ilCtrl->redirect($this, "assignStylesToCats");
1195  }
1196 
1197 }
1198 ?>