ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjStyleSheetGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
16 require_once "./Services/Object/classes/class.ilObjectGUI.php";
17 require_once "./Services/Style/classes/class.ilObjStyleSheet.php";
18 
20 {
25 
30  function ilObjStyleSheetGUI($a_data,$a_id,$a_call_by_reference, $a_prep = true)
31  {
32  global $ilCtrl, $lng, $tpl;
33 
34  $this->ctrl =& $ilCtrl;
35  $this->lng =& $lng;
36  $this->lng->loadLanguageModule("style");
37  $ilCtrl->saveParameter($this, array("tag", "style_type", "temp_type"));
38  if ($_GET["style_type"] != "")
39  {
40  $this->super_type = ilObjStyleSheet::_getStyleSuperTypeForType($_GET["style_type"]);
41  }
42 
43  $this->type = "sty";
44  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference, false);
45  }
46 
50  function &executeCommand()
51  {
52  $next_class = $this->ctrl->getNextClass($this);
53  $cmd = $this->ctrl->getCmd("edit");
54 
55  // #9440/#9489: prepareOutput will fail if not set properly
56  if(!$this->object)
57  {
58  $this->setCreationMode(true);
59  }
60 
61  $this->prepareOutput();
62  switch($next_class)
63  {
64  default:
65  $cmd.= "Object";
66  $ret =& $this->$cmd();
67  break;
68  }
69 
70  return $ret;
71  }
72 
73  function viewObject()
74  {
75  $this->editObject();
76  }
77 
81  function createObject()
82  {
83  global $rbacsystem, $lng, $tpl, $ilHelp;
84 
85  $forms = array();
86 
87 
88  $ilHelp->setScreenIdComponent("sty");
89  $ilHelp->setDefaultScreenId(ilHelpGUI::ID_PART_SCREEN, "create");
90 
91  // --- create
92 
93  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
94  $form = new ilPropertyFormGUI();
95  $form->setFormAction($this->ctrl->getFormAction($this));
96  $form->setTitle($this->lng->txt("sty_create_new_stylesheet"));
97 
98  // title
99  $ti = new ilTextInputGUI($this->lng->txt("title"), "style_title");
100  $ti->setMaxLength(128);
101  $ti->setSize(40);
102  $ti->setRequired(true);
103  $form->addItem($ti);
104 
105  // description
106  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "style_description");
107  $ta->setCols(40);
108  $ta->setRows(2);
109  $form->addItem($ta);
110 
111  $form->addCommandButton("save", $this->lng->txt("save"));
112  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
113 
114  $forms[] = $form;
115 
116 
117  // --- import
118 
119  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
120  $form = new ilPropertyFormGUI();
121  $form->setFormAction($this->ctrl->getFormAction($this));
122  $form->setTitle($this->lng->txt("sty_import_stylesheet"));
123 
124  // title
125  $ti = new ilFileInputGUI($this->lng->txt("import_file"), "stylefile");
126  $ti->setRequired(true);
127  $form->addItem($ti);
128 
129  $form->addCommandButton("importStyle", $this->lng->txt("import"));
130  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
131 
132  $forms[] = $form;
133 
134 
135  // --- clone
136 
137  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
138  $form = new ilPropertyFormGUI();
139  $form->setFormAction($this->ctrl->getFormAction($this));
140  $form->setTitle($this->lng->txt("sty_copy_other_stylesheet"));
141 
142  // source
143  $ti = new ilSelectInputGUI($this->lng->txt("sty_source"), "source_style");
144  $ti->setRequired(true);
146  $form->addItem($ti);
147 
148  $form->addCommandButton("copyStyle", $this->lng->txt("copy"));
149  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
150 
151  $forms[] = $form;
152 
153 
154  $this->tpl->setContent($this->getCreationFormsHTML($forms));
155  }
156 
160  function includeCSS()
161  {
162  // set style sheet
163  $this->tpl->setCurrentBlock("ContentStyle");
164  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
165  $this->object->getContentStylePath($this->object->getId()));
166  $this->tpl->parseCurrentBlock();
167  }
168 
172  function editObject()
173  {
174  global $rbacsystem, $lng, $ilTabs, $ilCtrl, $ilToolbar, $tpl;
175 
176  $this->setSubTabs();
177 
178  $this->includeCSS();
179 
180  $ctpl = new ilTemplate("tpl.sty_classes.html", true, true, "Services/Style");
181 
182  // output characteristics
183  $chars = $this->object->getCharacteristics();
184 
185  $style_type = ($this->super_type != "")
186  ? $this->super_type
187  : "text_block";
188  $ilCtrl->setParameter($this, "style_type", $style_type);
189  $ilTabs->setSubTabActive("sty_".$style_type."_char");
190 
191  // workaround to include default rte styles
192  if ($this->super_type == "rte")
193  {
194  $tpl->addCss("Modules/Scorm2004/templates/default/player.css");
195  include_once("./Modules/Scorm2004/classes/ilSCORM13Player.php");
196  $tpl->addInlineCss(ilSCORM13Player::getInlineCss());
197  }
198 
199  // add new style?
200  $all_super_types = ilObjStyleSheet::_getStyleSuperTypes();
201  $subtypes = $all_super_types[$style_type];
202  $expandable = false;
203  foreach ($subtypes as $t)
204  {
206  {
207  $expandable = true;
208  }
209  }
210  if ($expandable && $rbacsystem->checkAccess("write", (int) $_GET["ref_id"]))
211  {
212  $ilToolbar->addButton($lng->txt("sty_add_characteristic"),
213  $ilCtrl->getLinkTarget($this, "addCharacteristicForm"));
214  }
215 
216  if ($_SESSION["sty_copy"] != "")
217  {
218  $style_cp = explode(":::", $_SESSION["sty_copy"]);
219  if ($style_cp[1] == $_GET["style_type"])
220  {
221  if ($expandable)
222  {
223  $ilToolbar->addSeparator();
224  }
225  $ilToolbar->addButton($lng->txt("sty_paste_style_classes"),
226  $ilCtrl->getLinkTarget($this, "pasteCharacteristicsOverview"));
227  }
228  }
229 
230  include_once("./Services/Style/classes/class.ilStyleTableGUI.php");
231  $table_gui = new ilStyleTableGUI($this, "edit", $chars, $style_type,
232  $this->object);
233 
234  $ctpl->setCurrentBlock("style_table");
235  $ctpl->setVariable("STYLE_TABLE", $table_gui->getHTML());
236  $ctpl->parseCurrentBlock();
237 
238  $this->tpl->setContent($ctpl->get());
239  }
240 
244  function propertiesObject()
245  {
246  global $rbacsystem, $lng, $ilToolbar;
247 
248  // set style sheet
249  $this->tpl->setCurrentBlock("ContentStyle");
250  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
251  $this->object->getContentStylePath($this->object->getId()));
252  $this->tpl->parseCurrentBlock();
253 
254  // export button
255  $ilToolbar->addButton($this->lng->txt("export"),
256  $this->ctrl->getLinkTarget($this, "exportStyle"));
257 
258  $this->initPropertiesForm();
259  $this->getPropertiesValues();
260  $this->tpl->setContent($this->form->getHTML());
261  }
262 
267  public function getPropertiesValues()
268  {
269  $values = array();
270 
271  $values["style_title"] = $this->object->getTitle();
272  $values["style_description"] = $this->object->getDescription();
273  $values["disable_auto_margins"] = (int) $this->object->lookupStyleSetting("disable_auto_margins");
274 
275  $this->form->setValuesByArray($values);
276  }
277 
283  public function initPropertiesForm($a_mode = "edit")
284  {
285  global $lng, $rbacsystem;
286 
287  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
288  $this->form = new ilPropertyFormGUI();
289 
290  // title
291  $ti = new ilTextInputGUI($this->lng->txt("title"), "style_title");
292  $ti->setMaxLength(128);
293  $ti->setSize(40);
294  $ti->setRequired(true);
295  $this->form->addItem($ti);
296 
297  // description
298  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "style_description");
299  //$ta->setCols();
300  //$ta->setRows();
301  $this->form->addItem($ta);
302 
303  // disable automatic margins for left/right alignment
304  $cb = new ilCheckboxInputGUI($this->lng->txt("sty_disable_auto_margins"), "disable_auto_margins");
305  $cb->setInfo($this->lng->txt("sty_disable_auto_margins_info"));
306  $this->form->addItem($cb);
307 
308  // save and cancel commands
309 
310  if ($a_mode == "create")
311  {
312  $this->form->addCommandButton("save", $lng->txt("save"));
313  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
314  }
315  else
316  {
317  if ($rbacsystem->checkAccess("write", (int) $_GET["ref_id"]))
318  {
319  $this->form->addCommandButton("update", $lng->txt("save"));
320  }
321  }
322 
323  $this->form->setTitle($lng->txt("edit_stylesheet"));
324  $this->form->setFormAction($this->ctrl->getFormAction($this));
325 
326  }
327 
331  function updateObject()
332  {
333  global $lng, $ilCtrl, $tpl;
334 
335  $this->initPropertiesForm("edit");
336  if ($this->form->checkInput())
337  {
338  $this->object->setTitle($this->form->getInput("style_title"));
339  $this->object->setDescription($this->form->getInput("style_description"));
340  $this->object->writeStyleSetting("disable_auto_margins",
341  $this->form->getInput("disable_auto_margins"));
342  $this->object->update();
343  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
344  $ilCtrl->redirect($this, "properties");
345  }
346  else
347  {
348  $this->form->setValuesByPost();
349  $tpl->setContent($this->form->getHtml());
350  }
351  }
352 
357  {
358  global $ilCtrl;
359 
360  $cur = explode(".",$_GET["tag"]);
361  $cur_tag = $cur[0];
362  $cur_class = $cur[1];
363 
364  $this->initTagStyleForm("edit", $cur_tag);
365 
366  if ($this->form_gui->checkInput())
367  {
368  $this->saveTagStyle();
369  $ilCtrl->redirect($this, "editTagStyle");
370  }
371  else
372  {
373  $this->form_gui->setValuesByPost();
374  $this->outputTagStyleEditScreen();
375  }
376  }
377 
382  {
383  global $ilCtrl;
384 
385  $cur = explode(".",$_GET["tag"]);
386  $cur_tag = $cur[0];
387  $cur_class = $cur[1];
388 
389  $this->initTagStyleForm("edit", $cur_tag);
390  if ($this->form_gui->checkInput())
391  {
392  $this->saveTagStyle();
393  $ilCtrl->redirect($this, "edit");
394  }
395  else
396  {
397  $this->form_gui->setValuesByPost();
398  $this->outputTagStyleEditScreen();
399  }
400  }
401 
405  function saveTagStyle()
406  {
407  $cur = explode(".", $_GET["tag"]);
408  $cur_tag = $cur[0];
409  $cur_class = $cur[1];
410  $avail_pars = ilObjStyleSheet::_getStyleParameters($cur_tag);
411  foreach ($avail_pars as $par => $v)
412  {
413  $var = str_replace("-", "_", $par);
414  $basepar_arr = explode(".", $par);
415  $basepar = $basepar_arr[0];
416  if ($basepar_arr[1] != "" && $basepar_arr[1] != $cur_tag)
417  {
418  continue;
419  }
420 
421  switch ($v["input"])
422  {
423  case "fontsize":
424  case "numeric_no_perc":
425  case "numeric":
426  case "background_image":
427  $in = $this->form_gui->getItemByPostVar($basepar);
428 //echo "<br>-".$cur_tag."-".$cur_class."-".$basepar."-".$_GET["style_type"]."-";
429  $this->writeStylePar($cur_tag, $cur_class, $basepar, $in->getValue(), $_GET["style_type"], (int) $_GET["mq_id"]);
430  break;
431 
432  case "color":
433  $color = trim($_POST[$basepar]);
434  if ($color != "" && trim(substr($color,0,1) != "!"))
435  {
436  $color = "#".$color;
437  }
438  $this->writeStylePar($cur_tag, $cur_class, $basepar, $color, $_GET["style_type"], (int) $_GET["mq_id"]);
439  break;
440 
441  case "trbl_numeric":
442  case "border_width":
443  case "border_style":
444  $in = $this->form_gui->getItemByPostVar($basepar);
445  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][0], $in->getAllValue(), $_GET["style_type"], (int) $_GET["mq_id"]);
446  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][1], $in->getTopValue(), $_GET["style_type"], (int) $_GET["mq_id"]);
447  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][2], $in->getRightValue(), $_GET["style_type"], (int) $_GET["mq_id"]);
448  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][3], $in->getBottomValue(), $_GET["style_type"], (int) $_GET["mq_id"]);
449  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][4], $in->getLeftValue(), $_GET["style_type"], (int) $_GET["mq_id"]);
450  break;
451 
452  case "trbl_color":
453  $in = $this->form_gui->getItemByPostVar($basepar);
454  $tblr_p = array (0 => "getAllValue", 1 => "getTopValue", 2 => "getRightValue",
455  3 => "getBottomValue", 4 => "getLeftValue");
456  foreach ($tblr_p as $k => $func)
457  {
458  $val = trim($in->$func());
459  $val = (($in->getAcceptNamedColors() && substr($val, 0, 1) == "!")
460  || $val == "")
461  ? $val
462  : "#".$val;
463  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][$k], $val, $_GET["style_type"], (int) $_GET["mq_id"]);
464  }
465  break;
466 
467  case "background_position":
468  $in = $this->form_gui->getItemByPostVar($basepar);
469  $this->writeStylePar($cur_tag, $cur_class, $basepar, $in->getValue(), $_GET["style_type"], (int) $_GET["mq_id"]);
470  break;
471 
472  default:
473  $this->writeStylePar($cur_tag, $cur_class, $basepar, $_POST[$basepar], $_GET["style_type"], (int) $_GET["mq_id"]);
474  break;
475  }
476  }
477 
478  // write custom parameter
479  $this->object->deleteCustomStylePars($cur_tag, $cur_class, $_GET["style_type"], (int) $_GET["mq_id"]);
480  if (is_array($_POST["custom_par"]))
481  {
482  foreach ($_POST["custom_par"] as $cpar)
483  {
484  $par_arr = explode(":", $cpar);
485  if (count($par_arr) == 2)
486  {
487  $par = trim($par_arr[0]);
488  $val = trim(str_replace(";", "", $par_arr[1]));
489  $this->writeStylePar($cur_tag, $cur_class, $par, $val, $_GET["style_type"], (int) $_GET["mq_id"], true);
490  }
491  }
492  }
493 
494  $this->object->update();
495  }
496 
497  function writeStylePar($cur_tag, $cur_class, $par, $value, $a_type, $a_mq_id, $a_custom = false)
498  {
499 // echo $_GET["mq_id"]."-";
500 // echo $a_mq_id."-"; exit;
501  if ($a_type == "")
502  {
503  return;
504  }
505 
506  if ($value != "")
507  {
508  $this->object->replaceStylePar($cur_tag, $cur_class, $par, $value, $a_type, $a_mq_id, $a_custom);
509  }
510  else
511  {
512  $this->object->deleteStylePar($cur_tag, $cur_class, $par, $a_type, $a_mq_id, $a_custom);
513  }
514  }
515 
521  {
522  global $tpl, $ilToolbar, $lng, $ilCtrl;
523 
524  // media query selector
525  $mqs = $this->object->getMediaQueries();
526  if (count($mqs) > 0)
527  {
528  //
529  $options = array(
530  "" => $lng->txt("sty_default"),
531  );
532  foreach ($mqs as $mq)
533  {
534  $options[$mq["id"]] = $mq["mquery"];
535  }
536  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
537  $si = new ilSelectInputGUI("@media", "mq_id");
538  $si->setOptions($options);
539  $si->setValue((int) $_GET["mq_id"]);
540  $ilToolbar->addInputItem($si, true);
541  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
542  $ilToolbar->addFormButton($lng->txt("sty_switch"), "switchMQuery");
543  }
544 
545  // workaround to include default rte styles
546  //if (in_array($_GET["style_type"], array("rte_menu")))
547  if ($this->super_type == "rte")
548  {
549  $tpl->addCss("Modules/Scorm2004/templates/default/player.css");
550  include_once("./Modules/Scorm2004/classes/ilSCORM13Player.php");
551  $tpl->addInlineCss(ilSCORM13Player::getInlineCss());
552  }
553 
554  $cur = explode(".",$_GET["tag"]);
555  $cur_tag = $cur[0];
556  $cur_class = $cur[1];
557 
558  $this->initTagStyleForm("edit", $cur_tag);
559  $this->getValues();
560  $this->outputTagStyleEditScreen();
561  }
562 
570  {
571  global $ilCtrl;
572 
573  $ilCtrl->setParameter($this, "mq_id", (int) $_POST["mq_id"]);
574  $ilCtrl->redirect($this, "editTagStyle");
575  }
576 
577 
582  {
583  global $tpl, $ilCtrl, $lng;
584 
585  // set style sheet
586  $tpl->setCurrentBlock("ContentStyle");
587  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
588  $this->object->getContentStylePath($this->object->getId()));
589 
590  $ts_tpl = new ilTemplate("tpl.style_tag_edit.html", true, true, "Services/Style");
591 
592  $cur = explode(".",$_GET["tag"]);
593  $cur_tag = $cur[0];
594  $cur_class = $cur[1];
595 
596  $ts_tpl->setVariable("EXAMPLE",
597  ilObjStyleSheetGUI::getStyleExampleHTML($_GET["style_type"], $cur_class));
598 
599  $ts_tpl->setVariable("FORM",
600  $this->form_gui->getHtml());
601 
602  $tpl->setTitle($cur_class." (".$lng->txt("sty_type_".$_GET["style_type"]).")");
603 
604  $tpl->setContent($ts_tpl->get());
605  }
606 
607 
613  public function initTagStyleForm($a_mode, $a_cur_tag)
614  {
615  global $lng, $ilCtrl;
616 
617  $ilCtrl->saveParameter($this, array("mq_id"));
618 
619  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
620  $this->form_gui = new ilPropertyFormGUI();
621 
622  $avail_pars = $this->object->getAvailableParameters();
623  $groups = $this->object->getStyleParameterGroups();
624 
625  // output select lists
626  foreach ($groups as $k => $group)
627  {
628  // filter groups of properties that should only be
629  // displayed with matching tag
630  $filtered_groups = ilObjStyleSheet::_getFilteredGroups();
631  if (is_array($filtered_groups[$k]) && !in_array($a_cur_tag, $filtered_groups[$k]))
632  {
633  continue;
634  }
635 
636  $sh = new ilFormSectionHeaderGUI();
637  $sh->setTitle($lng->txt("sty_".$k));
638  $this->form_gui->addItem($sh);
639 
640  foreach ($group as $par)
641  {
642  $basepar = explode(".", $par);
643  $basepar = $basepar[0];
644 
645  $var = str_replace("-", "_", $basepar);
646  $up_par = strtoupper($var);
647 
649  {
650  case "select":
651  $sel_input = new ilSelectInputGUI($lng->txt("sty_".$var), $basepar);
652  $options = array("" => "");
653  foreach ($avail_pars[$par] as $p)
654  {
655  $options[$p] = $p;
656  }
657  $sel_input->setOptions($options);
658  $this->form_gui->addItem($sel_input);
659  break;
660 
661  case "text":
662  $text_input = new ilTextInputGUI($lng->txt("sty_".$var), $basepar);
663  $text_input->setMaxLength(200);
664  $text_input->setSize(20);
665  $this->form_gui->addItem($text_input);
666  break;
667 
668  case "fontsize":
669  include_once("./Services/Style/classes/class.ilFontSizeInputGUI.php");
670  $fs_input = new ilFontSizeInputGUI($lng->txt("sty_".$var), $basepar);
671  $this->form_gui->addItem($fs_input);
672  break;
673 
674  case "numeric_no_perc":
675  case "numeric":
676  include_once("./Services/Style/classes/class.ilNumericStyleValueInputGUI.php");
677  $num_input = new ilNumericStyleValueInputGUI($lng->txt("sty_".$var), $basepar);
678  if (ilObjStyleSheet::_getStyleParameterInputType($par) == "numeric_no_perc")
679  {
680  $num_input->setAllowPercentage(false);
681  }
682  $this->form_gui->addItem($num_input);
683  break;
684 
685  case "percentage":
686  $per_input = new ilNumberInputGUI($lng->txt("sty_".$var), $basepar);
687  $per_input->setMinValue(0);
688  $per_input->setMaxValue(100);
689  $per_input->setMaxLength(3);
690  $per_input->setSize(3);
691  $this->form_gui->addItem($per_input);
692  break;
693 
694  case "color":
695  //include_once("./Services/Style/classes/class.ilNumericStyleValueInputGUI.php");
696  $col_input = new ilColorPickerInputGUI($lng->txt("sty_".$var), $basepar);
697  $col_input->setDefaultColor("");
698  $col_input->setAcceptNamedColors(true);
699  $this->form_gui->addItem($col_input);
700  break;
701 
702  case "trbl_numeric":
703  include_once("./Services/Style/classes/class.ilTRBLNumericStyleValueInputGUI.php");
704  $num_input = new ilTRBLNumericStyleValueInputGUI($lng->txt("sty_".$var), $basepar);
705  if (ilObjStyleSheet::_getStyleParameterInputType($par) == "trbl_numeric_no_perc")
706  {
707  $num_input->setAllowPercentage(false);
708  }
709  $this->form_gui->addItem($num_input);
710  break;
711 
712  case "border_width":
713  include_once("./Services/Style/classes/class.ilTRBLBorderWidthInputGUI.php");
714  $bw_input = new ilTRBLBorderWidthInputGUI($lng->txt("sty_".$var), $basepar);
715  $this->form_gui->addItem($bw_input);
716  break;
717 
718  case "border_style":
719  include_once("./Services/Style/classes/class.ilTRBLBorderStyleInputGUI.php");
720  $bw_input = new ilTRBLBorderStyleInputGUI($lng->txt("sty_".$var), $basepar);
721  $this->form_gui->addItem($bw_input);
722  break;
723 
724  case "trbl_color":
725  include_once("./Services/Style/classes/class.ilTRBLColorPickerInputGUI.php");
726  $col_input = new ilTRBLColorPickerInputGUI($lng->txt("sty_".$var), $basepar);
727  $col_input->setAcceptNamedColors(true);
728  $this->form_gui->addItem($col_input);
729  break;
730 
731  case "background_image":
732  include_once("./Services/Style/classes/class.ilBackgroundImageInputGUI.php");
733  $im_input = new ilBackgroundImageInputGUI($lng->txt("sty_".$var), $basepar);
734  $imgs = array();
735  foreach ($this->object->getImages() as $entry)
736  {
737  $imgs[] = $entry["entry"];
738  }
739  $im_input->setImages($imgs);
740  $this->form_gui->addItem($im_input);
741  break;
742 
743  case "background_position":
744  include_once("./Services/Style/classes/class.ilBackgroundPositionInputGUI.php");
745  $im_input = new ilBackgroundPositionInputGUI($lng->txt("sty_".$var), $basepar);
746  $this->form_gui->addItem($im_input);
747  break;
748  }
749  }
750  }
751 
752  // custom parameters
753  $sh = new ilFormSectionHeaderGUI();
754  $sh->setTitle($lng->txt("sty_custom"));
755  $this->form_gui->addItem($sh);
756 
757  // custom parameters
758  $ti = new ilTextInputGUI($this->lng->txt("sty_custom_par"), "custom_par");
759  $ti->setMaxLength(300);
760  $ti->setSize(80);
761  $ti->setMulti(true);
762  $ti->setInfo($this->lng->txt("sty_custom_par_info"));
763  $this->form_gui->addItem($ti);
764 
765 
766  // save and cancel commands
767  $this->form_gui->addCommandButton("updateTagStyle", $lng->txt("save_return"));
768  $this->form_gui->addCommandButton("refreshTagStyle", $lng->txt("save_refresh"));
769 
770 // $this->form_gui->setTitle($lng->txt("edit"));
771  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
772  }
773 
778  public function getValues()
779  {
780  $style = $this->object->getStyle();
781  $cur = explode(".",$_GET["tag"]);
782  $cur_tag = $cur[0];
783  $cur_class = $cur[1];
784  $cur_parameters = $this->extractParametersOfTag($cur_tag, $cur_class, $style, $_GET["style_type"],
785  (int) $_GET["mq_id"], false);
786  $parameters = ilObjStyleSheet::_getStyleParameters();
787  foreach($parameters as $p => $v)
788  {
789  $filtered_groups = ilObjStyleSheet::_getFilteredGroups();
790  if (is_array($filtered_groups[$v["group"]]) && !in_array($cur_tag, $filtered_groups[$v["group"]]))
791  {
792  continue;
793  }
794  $p = explode(".", $p);
795  $p = $p[0];
796  $input = $this->form_gui->getItemByPostVar($p);
797  switch ($v["input"])
798  {
799  case "":
800  break;
801 
802  case "trbl_numeric":
803  case "border_width":
804  case "border_style":
805  case "trbl_color":
806  $input->setAllValue($cur_parameters[$v["subpar"][0]]);
807  $input->setTopValue($cur_parameters[$v["subpar"][1]]);
808  $input->setRightValue($cur_parameters[$v["subpar"][2]]);
809  $input->setBottomValue($cur_parameters[$v["subpar"][3]]);
810  $input->setLeftValue($cur_parameters[$v["subpar"][4]]);
811  break;
812 
813  default:
814  $input->setValue($cur_parameters[$p]);
815  break;
816  }
817  }
818 
819  $cust_parameters = $this->extractParametersOfTag($cur_tag, $cur_class, $style, $_GET["style_type"],
820  (int) $_GET["mq_id"], true);
821  $vals = array();
822  foreach ($cust_parameters as $k => $c)
823  {
824  $vals[] = $k.": ".$c;
825  }
826  $input = $this->form_gui->getItemByPostVar("custom_par");
827  $input->setValue($vals);
828  }
829 
833  function exportStyleObject()
834  {
835  $file = $this->object->export();
836 
837  ilUtil::deliverFile($file, "sty_".$this->object->getId().".zip");
838  }
839 
840  function extractParametersOfTag($a_tag, $a_class, $a_style, $a_type, $a_mq_id = 0, $a_custom = false)
841  {
842  $parameters = array();
843  foreach($a_style as $tag)
844  {
845  foreach($tag as $par)
846  {
847  if ($par["tag"] == $a_tag && $par["class"] == $a_class
848  && $par["type"] == $a_type && (int) $a_mq_id == (int) $par["mq_id"]
849  && (int) $a_custom == (int) $par["custom"])
850  {
851  $parameters[$par["parameter"]] = $par["value"];
852  }
853  }
854  }
855  return $parameters;
856  }
857 
862  {
863  $this->object->addParameter($_POST["tag"], $_POST["parameter"]);
864  $this->editObject();
865  }
866 
870  function refreshObject()
871  {
872  $this->object->setTitle($_POST["style_title"]);
873  $this->object->setDescription($_POST["style_description"]);
874 
875  foreach($_POST["styval"] as $id => $value)
876  {
877  $this->object->updateStyleParameter($id, $value);
878  }
879  $this->object->update();
880  $this->editObject();
881  }
882 
888  function deleteObject($a_error = false)
889  {
890  //$this->setTabs();
891 
892  // display confirmation message
893  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
894  $cgui = new ilConfirmationGUI();
895  $cgui->setFormAction($this->ctrl->getFormAction($this));
896  $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
897  $cgui->setCancel($this->lng->txt("cancel"), "cancelDelete");
898  $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDelete");
899 
900  $caption = ilUtil::getImageTagByType("sty", $this->tpl->tplPath).
901  " ".ilObject::_lookupTitle($this->object->getId());
902 
903  $cgui->addItem("id[]", "", $caption);
904 
905  $this->tpl->setContent($cgui->getHTML());
906  }
907 
908 
913  {
914  $this->ctrl->returnToParent($this);
915  }
916 
921  {
922  global $ilias;
923 
924  $this->object->delete();
925 
926  $this->ctrl->returnToParent($this);
927  }
928 
933  {
934  if (is_array($_POST["sty_select"]))
935  {
936  foreach($_POST["sty_select"] as $id => $dummy)
937  {
938  $this->object->deleteParameter($id);
939  }
940  }
941  $this->object->read();
942  $this->object->writeCSSFile();
943  $this->editObject();
944  }
945 
949  function saveObject()
950  {
951  if(!trim($_POST["style_title"]))
952  {
953  $this->ctrl->redirect($this, "create");
954  }
955 
956 //echo "HH"; exit;
957  $class_name = "ilObjStyleSheet";
958  require_once("./Services/Style/classes/class.ilObjStyleSheet.php");
959  $newObj = new ilObjStyleSheet();
960  $newObj->setTitle("-");
961  $newObj->create();
962  $newObj->setTitle(ilUtil::stripSlashes($_POST["style_title"]));
963  $newObj->setDescription(ilUtil::stripSlashes($_POST["style_description"]));
964  $newObj->update();
965 
966  // assign style to style sheet folder,
967  // if parent is style sheet folder
968  if ($_GET["ref_id"] > 0)
969  {
970 
971  $fold =& ilObjectFactory::getInstanceByRefId($_GET["ref_id"]);
972  if ($fold->getType() == "stys")
973  {
974  $fold->addStyle($newObj->getId());
975  $fold->update();
976  ilObjStyleSheet::_writeStandard($newObj->getId(), "1");
977  $this->ctrl->redirectByClass("ilobjstylesettingsgui", "editContentStyles");
978  }
979  }
980 
981  return $newObj->getId();
982  }
983 
987  function copyStyleObject()
988  {
989  global $ilias;
990 
991  if ($_POST["source_style"] > 0)
992  $style_obj =& $ilias->obj_factory->getInstanceByObjId($_POST["source_style"]);
993  $new_id = $style_obj->ilClone();
994 
995  // assign style to style sheet folder,
996  // if parent is style sheet folder
997  if ($_GET["ref_id"] > 0)
998  {
999 
1000  $fold =& ilObjectFactory::getInstanceByRefId($_GET["ref_id"]);
1001  if ($fold->getType() == "stys")
1002  {
1003  $fold->addStyle($new_id);
1004  $fold->update();
1005  ilObjStyleSheet::_writeStandard($new_id, "1");
1006  $this->ctrl->redirectByClass("ilobjstylesettingsgui", "editContentStyles");
1007  }
1008  }
1009 
1010  return $new_id;
1011  }
1012 
1017  {
1018  // check file
1019  $source = $_FILES["stylefile"]["tmp_name"];
1020  if (($source == 'none') || (!$source))
1021  {
1022  $this->ilias->raiseError("No file selected!",$this->ilias->error_obj->MESSAGE);
1023  }
1024 
1025  // check correct file type
1026  $info = pathinfo($_FILES["stylefile"]["name"]);
1027  if (strtolower($info["extension"]) != "zip" && strtolower($info["extension"]) != "xml")
1028  {
1029  $this->ilias->raiseError("File must be a zip or xml file!",$this->ilias->error_obj->MESSAGE);
1030  }
1031 
1032  $class_name = "ilObjStyleSheet";
1033  require_once("./Services/Style/classes/class.ilObjStyleSheet.php");
1034  $newObj = new ilObjStyleSheet();
1035  //$newObj->setTitle();
1036  //$newObj->setDescription($_POST["style_description"]);
1037  $newObj->import($_FILES["stylefile"]);
1038  //$newObj->createFromXMLFile($_FILES["stylefile"]["tmp_name"]);
1039 
1040  // assign style to style sheet folder,
1041  // if parent is style sheet folder
1042  if ($_GET["ref_id"] > 0)
1043  {
1044 
1045  $fold =& ilObjectFactory::getInstanceByRefId($_GET["ref_id"]);
1046  if ($fold->getType() == "stys")
1047  {
1048  $fold->addStyle($newObj->getId());
1049  $fold->update();
1050  ilObjStyleSheet::_writeStandard($newObj->getId(), "1");
1051  $this->ctrl->redirectByClass("ilobjstylesettingsgui", "editContentStyles");
1052  }
1053  }
1054 
1055  return $newObj->getId();
1056  }
1057 
1061  function cancelObject()
1062  {
1063  global $lng;
1064 
1065  ilUtil::sendInfo($lng->txt("msg_cancel"), true);
1066  $this->ctrl->returnToParent($this);
1067  }
1068 
1072  function getAdminTabs(&$tabs_gui)
1073  {
1074  $this->getTabs($tabs_gui);
1075  }
1076 
1080  function setTabs()
1081  {
1082  global $lng;
1083 
1084  $this->getTabs($this->tabs_gui);
1085 
1086  if (strtolower(get_class($this->object)) == "ilobjstylesheet")
1087  {
1088  $this->tpl->setVariable("HEADER", $this->object->getTitle());
1089  }
1090  else
1091  {
1092  $this->tpl->setVariable("HEADER", $lng->txt("create_stylesheet"));
1093  }
1094  }
1095 
1101  function getTabs(&$tabs_gui)
1102  {
1103  global $lng, $ilCtrl, $ilTabs, $ilHelp;
1104 
1105  $ilHelp->setScreenIdComponent("sty");
1106 
1107  if ($ilCtrl->getCmd() == "editTagStyle")
1108  {
1109  // back to upper context
1110  $tabs_gui->setBackTarget($lng->txt("back"),
1111  $ilCtrl->getLinkTarget($this, "edit"));
1112 
1113  $t = explode(".", $_GET["tag"]);
1114  $t2 = explode(":", $t[1]);
1115  $pc = $this->object->_getPseudoClasses($t[0]);
1116  if (is_array($pc) && count($pc) > 0)
1117  {
1118  // style classes
1119  $ilCtrl->setParameter($this, "tag", $t[0].".".$t2[0]);
1120  $tabs_gui->addTarget("sty_tag_normal",
1121  $this->ctrl->getLinkTarget($this, "editTagStyle"), array("editTagStyle", ""),
1122  get_class($this));
1123  if ($t2[1] == "")
1124  {
1125  $ilTabs->setTabActive("sty_tag_normal");
1126  }
1127 
1128  foreach ($pc as $p)
1129  {
1130  // style classes
1131  $ilCtrl->setParameter($this, "tag", $t[0].".".$t2[0].":".$p);
1132  $tabs_gui->addTarget("sty_tag_".$p,
1133  $this->ctrl->getLinkTarget($this, "editTagStyle"), array("editTagStyle", ""),
1134  get_class($this));
1135  if ($t2[1] == $p)
1136  {
1137  $ilTabs->setTabActive("sty_tag_".$p);
1138  }
1139  }
1140  $ilCtrl->setParameter($this, "tag", $_GET["tag"]);
1141  }
1142  }
1143  else
1144  {
1145  // back to upper context
1146  $tabs_gui->setBackTarget($lng->txt("back"),
1147  $this->ctrl->getLinkTarget($this, "returnToUpperContext"));
1148 
1149  // style classes
1150  $tabs_gui->addTarget("sty_style_chars",
1151  $this->ctrl->getLinkTarget($this, "edit"), array("edit", ""),
1152  get_class($this));
1153 
1154  // colors
1155  $tabs_gui->addTarget("sty_colors",
1156  $this->ctrl->getLinkTarget($this, "listColors"), "listColors",
1157  get_class($this));
1158 
1159  // media queries
1160  $tabs_gui->addTarget("sty_media_queries",
1161  $this->ctrl->getLinkTarget($this, "listMediaQueries"), "listMediaQueries",
1162  get_class($this));
1163 
1164  // images
1165  $tabs_gui->addTarget("sty_images",
1166  $this->ctrl->getLinkTarget($this, "listImages"), "listImages",
1167  get_class($this));
1168 
1169  // table templates
1170  $tabs_gui->addTarget("sty_templates",
1171  $this->ctrl->getLinkTarget($this, "listTemplates"), "listTemplates",
1172  get_class($this));
1173 
1174  // settings
1175  $tabs_gui->addTarget("settings",
1176  $this->ctrl->getLinkTarget($this, "properties"), "properties",
1177  get_class($this));
1178 
1179  // accordiontest
1180 /*
1181  $tabs_gui->addTarget("accordiontest",
1182  $this->ctrl->getLinkTarget($this, "accordiontest"), "accordiontest",
1183  get_class($this));*/
1184  }
1185 
1186  }
1187 
1193  function setSubTabs()
1194  {
1195  global $lng, $ilTabs, $ilCtrl;
1196 
1198 
1199  foreach ($types as $super_type => $types)
1200  {
1201  // text block characteristics
1202  $ilCtrl->setParameter($this, "style_type", $super_type);
1203  $ilTabs->addSubTabTarget("sty_".$super_type."_char",
1204  $this->ctrl->getLinkTarget($this, "edit"), array("edit", ""),
1205  get_class($this));
1206  }
1207 
1208  $ilCtrl->setParameter($this, "style_type", $_GET["style_type"]);
1209  }
1210 
1217  {
1218  global $lng, $ilTabs, $ilCtrl;
1219 
1221 
1222  foreach ($types as $t => $c)
1223  {
1224  $ilCtrl->setParameter($this, "temp_type", $t);
1225  $ilTabs->addSubTabTarget("sty_".$t."_templates",
1226  $this->ctrl->getLinkTarget($this, "listTemplates"), array("listTemplates", ""),
1227  get_class($this));
1228  }
1229 
1230  $ilCtrl->setParameter($this, "temp_type", $_GET["temp_type"]);
1231  }
1232 
1238  {
1239  global $ilLocator;
1240 
1241  if ($_GET["admin_mode"] == "settings") // system settings
1242  {
1244 
1245  $ilLocator->addItem(ilObject::_lookupTitle(
1246  ilObject::_lookupObjId($_GET["ref_id"])),
1247  $this->ctrl->getLinkTargetByClass("ilobjstylesettingsgui", "view"));
1248 
1249  if ($_GET["obj_id"] > 0)
1250  {
1251  $ilLocator->addItem($this->object->getTitle(),
1252  $this->ctrl->getLinkTarget($this, "edit"));
1253  }
1254  }
1255  else // repository administration
1256  {
1257  //?
1258  }
1259 
1260  }
1261 
1262  function showUpperIcon()
1263  {
1264  global $tree, $tpl, $objDefinition;
1265 
1266  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
1267  {
1268  $tpl->setUpperIcon(
1269  $this->ctrl->getLinkTargetByClass("ilobjstylesettingsgui",
1270  "editContentStyles"));
1271  }
1272  else
1273  {
1274  // ?
1275  }
1276  }
1277 
1281  function listImagesObject()
1282  {
1283  global $tpl, $ilToolbar, $ilCtrl, $lng, $rbacsystem;
1284 
1285  if ($rbacsystem->checkAccess("write", (int) $_GET["ref_id"]))
1286  {
1287  $ilToolbar->addButton($lng->txt("sty_add_image"),
1288  $ilCtrl->getLinkTarget($this, "addImage"));
1289  }
1290 
1291  include_once("./Services/Style/classes/class.ilStyleImageTableGUI.php");
1292  $table_gui = new ilStyleImageTableGUI($this, "listImages",
1293  $this->object);
1294  $tpl->setContent($table_gui->getHTML());
1295 
1296  }
1297 
1301  function addImageObject()
1302  {
1303  global $tpl;
1304 
1305  $this->initImageForm();
1306  $tpl->setContent($this->form_gui->getHTML());
1307  }
1308 
1313  {
1314  global $ilCtrl;
1315 
1316  $ilCtrl->redirect($this, "listImages");
1317  }
1318 
1323  {
1324  global $tpl, $ilCtrl;
1325 
1326  $this->initImageForm();
1327 
1328  if ($this->form_gui->checkInput())
1329  {
1330  $this->object->uploadImage($_FILES["image_file"]);
1331  $ilCtrl->redirect($this, "listImages");
1332  }
1333  else
1334  {
1335  //$this->form_gui->setImageFormValuesByPost();
1336  $tpl->setContent($this->form_gui->getHTML());
1337  }
1338 
1339  }
1340 
1344  function initImageForm()
1345  {
1346  global $lng, $ilCtrl;
1347 
1348  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1349  $this->form_gui = new ilPropertyFormGUI();
1350 
1351  $this->form_gui->setTitle($lng->txt("sty_add_image"));
1352 
1353  $file_input = new ilImageFileInputGUI($lng->txt("sty_image_file"), "image_file");
1354  $file_input->setRequired(true);
1355  $this->form_gui->addItem($file_input);
1356 
1357  $this->form_gui->addCommandButton("uploadImage", $lng->txt("upload"));
1358  $this->form_gui->addCommandButton("cancelUpload", $lng->txt("cancel"));
1359  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1360  }
1361 
1366  {
1367  global $ilCtrl;
1368 
1369  $images = $this->object->getImages();
1370 
1371  foreach ($images as $image)
1372  {
1373  if (is_array($_POST["file"]) && in_array($image["entry"], $_POST["file"]))
1374  {
1375  $this->object->deleteImage($image["entry"]);
1376  }
1377  }
1378  $ilCtrl->redirect($this, "listImages");
1379  }
1380 
1385  {
1386  global $ilCtrl, $tpl, $lng;
1387 
1388 //var_dump($_POST);
1389 
1390  if (!is_array($_POST["char"]) || count($_POST["char"]) == 0)
1391  {
1392  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
1393  $ilCtrl->redirect($this, "edit");
1394  }
1395  else
1396  {
1397  // check whether there are any core style classes included
1398  $core_styles = ilObjStyleSheet::_getCoreStyles();
1399  foreach ($_POST["char"] as $char)
1400  {
1401  if (!empty($core_styles[$char]))
1402  {
1403  $this->deleteCoreCharMessage();
1404  return;
1405  }
1406  }
1407 
1408  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1409  $cgui = new ilConfirmationGUI();
1410  $cgui->setFormAction($ilCtrl->getFormAction($this));
1411  $cgui->setHeaderText($lng->txt("sty_confirm_char_deletion"));
1412  $cgui->setCancel($lng->txt("cancel"), "cancelCharacteristicDeletion");
1413  $cgui->setConfirm($lng->txt("delete"), "deleteCharacteristic");
1414 
1415  foreach ($_POST["char"] as $char)
1416  {
1417  $char_comp = explode(".", $char);
1418  $cgui->addItem("char[]", $char, $char_comp[2]);
1419  }
1420 
1421  $tpl->setContent($cgui->getHTML());
1422  }
1423  }
1424 
1432  {
1433  global $ilCtrl, $tpl, $lng;
1434 
1435  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1436  $cgui = new ilConfirmationGUI();
1437  $cgui->setFormAction($ilCtrl->getFormAction($this));
1438 
1439 
1440  $core_styles = ilObjStyleSheet::_getCoreStyles();
1441  $cnt = 0;
1442  foreach ($_POST["char"] as $char)
1443  {
1444  if (!empty($core_styles[$char]))
1445  {
1446  $cnt++;
1447  $char_comp = explode(".", $char);
1448  $cgui->addItem("", "", $char_comp[2]);
1449  }
1450  else
1451  {
1452  $cgui->addHiddenItem("char[]", $char);
1453  }
1454  }
1455  $all_core_styles = ($cnt == count($_POST["char"]))
1456  ? true
1457  : false;
1458 
1459  if ($all_core_styles)
1460  {
1461  $cgui->setHeaderText($lng->txt("sty_all_styles_obligatory"));
1462  $cgui->setCancel($lng->txt("back"), "cancelCharacteristicDeletion");
1463  }
1464  else
1465  {
1466  $cgui->setHeaderText($lng->txt("sty_some_styles_obligatory_delete_rest"));
1467  $cgui->setCancel($lng->txt("cancel"), "cancelCharacteristicDeletion");
1468  $cgui->setConfirm($lng->txt("sty_delete_other_selected"), "deleteCharacteristicConfirmation");
1469  }
1470 
1471  $tpl->setContent($cgui->getHTML());
1472  }
1473 
1478  {
1479  global $ilCtrl, $lng;
1480 
1481  ilUtil::sendInfo($lng->txt("action_aborted"), true);
1482  $ilCtrl->redirect($this, "edit");
1483  }
1484 
1489  {
1490  global $ilCtrl;
1491 
1492  if (is_array($_POST["char"]))
1493  {
1494  foreach($_POST["char"] as $char)
1495  {
1496  $char_comp = explode(".", $char);
1497  $type = $char_comp[0];
1498  $tag = $char_comp[1];
1499  $class = $char_comp[2];
1500 
1501  $this->object->deleteCharacteristic($type, $tag, $class);
1502  }
1503  }
1504 
1505  $ilCtrl->redirect($this, "edit");
1506  }
1507 
1512  {
1513  global $tpl;
1514 
1515  $this->initCharacteristicForm("create");
1516  $tpl->setContent($this->form_gui->getHTML());
1517  }
1518 
1523  {
1524  global $ilCtrl, $tpl, $lng;
1525 
1526  $this->initCharacteristicForm("create");
1527 
1528  if ($this->form_gui->checkInput())
1529  {
1530  if ($this->object->characteristicExists($_POST["new_characteristic"], $_GET["style_type"]))
1531  {
1532  $char_input = $this->form_gui->getItemByPostVar("new_characteristic");
1533  $char_input->setAlert($lng->txt("sty_characteristic_already_exists"));
1534  }
1535  else
1536  {
1537  $this->object->addCharacteristic($_POST["type"], $_POST["new_characteristic"]);
1538  ilUtil::sendInfo($lng->txt("sty_added_characteristic"), true);
1539  $ilCtrl->setParameter($this, "tag",
1540  ilObjStyleSheet::_determineTag($_POST["type"]).".".$_POST["new_characteristic"]);
1541  $ilCtrl->setParameter($this, "style_type", $_POST["type"]);
1542  $ilCtrl->redirect($this, "editTagStyle");
1543  }
1544  }
1545  $this->form_gui->setValuesByPost();
1546  $tpl->setContent($this->form_gui->getHTML());
1547  }
1548 
1554  public function initCharacteristicForm($a_mode)
1555  {
1556  global $lng, $ilCtrl;
1557 
1558  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1559  $this->form_gui = new ilPropertyFormGUI();
1560 
1561  // title
1562  $txt_input = new ilRegExpInputGUI($lng->txt("title"), "new_characteristic");
1563  $txt_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
1564  $txt_input->setNoMatchMessage($lng->txt("sty_msg_characteristic_must_only_include")." A-Z, a-z, 1-9");
1565  $txt_input->setRequired(true);
1566  $this->form_gui->addItem($txt_input);
1567 
1568  // type
1569  $all_super_types = ilObjStyleSheet::_getStyleSuperTypes();
1570  $types = $all_super_types[$this->super_type];
1571  $exp_types = array();
1572  foreach($types as $t)
1573  {
1575  {
1576  $exp_types[$t] = $lng->txt("sty_type_".$t);
1577  }
1578  }
1579  if (count($exp_types) > 1)
1580  {
1581  $type_input = new ilSelectInputGUI($lng->txt("sty_type"), "type");
1582  $type_input->setOptions($exp_types);
1583  $type_input->setValue(key($exp_types));
1584  $this->form_gui->addItem($type_input);
1585  }
1586  else if (count($exp_types) == 1)
1587  {
1588  $hid_input = new ilHiddenInputGUI("type");
1589  $hid_input->setValue(key($exp_types));
1590  $this->form_gui->addItem($hid_input);
1591  }
1592 
1593  $this->form_gui->setTitle($lng->txt("sty_add_characteristic"));
1594  $this->form_gui->addCommandButton("saveCharacteristic", $lng->txt("save"));
1595  $this->form_gui->addCommandButton("edit", $lng->txt("cancel"));
1596  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1597  }
1598 
1602  static function getStyleExampleHTML($a_type, $a_class)
1603  {
1604  global $lng;
1605 
1606  $c = explode(":", $a_class);
1607  $a_class = $c[0];
1608 
1609  $ex_tpl = new ilTemplate("tpl.style_example.html", true, true, "Services/Style");
1610 
1611  $ex_tpl->setCurrentBlock("Example_".$a_type);
1612  $ex_tpl->setVariable("EX_CLASS", "ilc_".$a_type."_".$a_class);
1613  $ex_tpl->setVariable("EX_TEXT", "ABC abc 123");
1614  if (in_array($a_type, array("media_cont", "qimg")))
1615  {
1616  //
1617  }
1618  if (in_array($a_type, array("table", "table_caption")))
1619  {
1620  $ex_tpl->setVariable("TXT_CAPTION", $lng->txt("sty_caption"));
1621  }
1622  if (in_array($a_class, array("OrderListItemHorizontal", "OrderListHorizontal")))
1623  {
1624  $ex_tpl->setVariable("HOR", "Horizontal");
1625  }
1626  $ex_tpl->parseCurrentBlock();
1627 
1628  return $ex_tpl->get();
1629  }
1630 
1635  {
1636  global $ilCtrl, $lng;
1637 
1638  //var_dump($_POST);
1639 
1640  foreach ($_POST["all_chars"] as $char)
1641  {
1642  $ca = explode(".", $char);
1643  $this->object->saveHideStatus($ca[0], $ca[2],
1644  (is_array($_POST["hide"]) && in_array($char, $_POST["hide"])));
1645  }
1646 
1647  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
1648  $ilCtrl->redirect($this, "edit");
1649  }
1650 
1658  {
1659  global $ilCtrl, $lng;
1660 
1661  if (!is_array($_POST["char"]) || count($_POST["char"]) == 0)
1662  {
1663  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
1664  }
1665  else
1666  {
1667  $style_cp = implode("::", $_POST["char"]);
1668  $style_cp = $this->object->getId().":::".$_GET["style_type"].":::".$style_cp;
1669  $_SESSION["sty_copy"] = $style_cp;
1670  ilUtil::sendSuccess($lng->txt("sty_copied_please_select_target"), true);
1671  }
1672  $ilCtrl->redirect($this, "edit");
1673  }
1674 
1682  {
1683  global $tpl, $ilTabs;
1684 
1685  $ilTabs->clearTargets();
1686 
1687  include_once("./Services/Style/classes/class.ilPasteStyleCharacteristicTableGUI.php");
1688  $table = new ilPasteStyleCharacteristicTableGUI($this, "pasteCharacteristicsOverview");
1689 
1690  $tpl->setContent($table->getHTML());
1691  }
1692 
1700  {
1701  global $ilCtrl, $lng;
1702 
1703  if (is_array($_POST["title"]))
1704  {
1705  foreach ($_POST["title"] as $from_char => $to_title)
1706  {
1707  $fc = explode(".", $from_char);
1708 
1709  if ($_POST["conflict_action"][$from_char] == "overwrite" ||
1710  !$this->object->characteristicExists($to_title, $fc[0]))
1711  {
1712  $this->object->copyCharacteristic($_POST["from_style_id"],
1713  $fc[0], $fc[2], $to_title);
1714  }
1715  }
1716  ilObjStyleSheet::_writeUpToDate($this->object->getId(), false);
1717  unset($_SESSION["sty_copy"]);
1718  ilUtil::sendSuccess($lng->txt("sty_style_classes_copied"), true);
1719  }
1720 
1721  $ilCtrl->redirect($this, "edit");
1722  }
1723 
1724  //
1725  // Color management
1726  //
1727 
1731  function listColorsObject()
1732  {
1733  global $tpl, $rbacsystem, $ilToolbar, $ilCtrl;
1734 
1735  if ($rbacsystem->checkAccess("write", (int) $_GET["ref_id"]))
1736  {
1737  $ilToolbar->addButton($this->lng->txt("sty_add_color"),
1738  $ilCtrl->getLinkTarget($this, "addColor"));
1739  }
1740 
1741  include_once("./Services/Style/classes/class.ilStyleColorTableGUI.php");
1742  $table_gui = new ilStyleColorTableGUI($this, "listColors",
1743  $this->object);
1744  $tpl->setContent($table_gui->getHTML());
1745 
1746  }
1747 
1751  function addColorObject()
1752  {
1753  global $tpl;
1754 
1755  $this->initColorForm();
1756  $tpl->setContent($this->form_gui->getHTML());
1757  }
1758 
1762  function editColorObject()
1763  {
1764  global $tpl, $ilCtrl;
1765 
1766  $ilCtrl->setParameter($this, "c_name", $_GET["c_name"]);
1767  $this->initColorForm("edit");
1768  $this->getColorFormValues();
1769  $tpl->setContent($this->form_gui->getHTML());
1770  }
1771 
1772 
1776  function initColorForm($a_mode = "create")
1777  {
1778  global $lng, $ilCtrl;
1779 
1780  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1781  $this->form_gui = new ilPropertyFormGUI();
1782 
1783  $this->form_gui->setTitle($lng->txt("sty_add_color"));
1784 
1785  // name
1786  $name_input = new ilRegExpInputGUI($lng->txt("sty_color_name"), "color_name");
1787  $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
1788  $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include")." A-Z, a-z, 1-9");
1789  $name_input->setRequired(true);
1790  $name_input->setSize(15);
1791  $name_input->setMaxLength(15);
1792  $this->form_gui->addItem($name_input);
1793 
1794  // code
1795  $color_input = new ilColorPickerInputGUI($lng->txt("sty_color_code"), "color_code");
1796  $color_input->setRequired(true);
1797  $color_input->setDefaultColor("");
1798  $this->form_gui->addItem($color_input);
1799 
1800  if ($a_mode == "create")
1801  {
1802  $this->form_gui->addCommandButton("saveColor", $lng->txt("save"));
1803  $this->form_gui->addCommandButton("cancelColorSaving", $lng->txt("cancel"));
1804  }
1805  else
1806  {
1807  $this->form_gui->addCommandButton("updateColor", $lng->txt("save"));
1808  $this->form_gui->addCommandButton("cancelColorSaving", $lng->txt("cancel"));
1809  }
1810  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1811  }
1812 
1817  {
1818  if ($_GET["c_name"] != "")
1819  {
1820  $values["color_name"] = $_GET["c_name"];
1821  $values["color_code"] = $this->object->getColorCodeForName($_GET["c_name"]);
1822  $this->form_gui->setValuesByArray($values);
1823  }
1824  }
1825 
1830  {
1831  global $ilCtrl;
1832 
1833  $ilCtrl->redirect($this, "listColors");
1834  }
1835 
1839  function saveColorObject()
1840  {
1841  global $tpl, $ilCtrl, $lng;
1842 
1843  $this->initColorForm();
1844 
1845  if ($this->form_gui->checkInput())
1846  {
1847  if ($this->object->colorExists($_POST["color_name"]))
1848  {
1849  $col_input = $this->form_gui->getItemByPostVar("color_name");
1850  $col_input->setAlert($lng->txt("sty_color_already_exists"));
1851  }
1852  else
1853  {
1854  $this->object->addColor($_POST["color_name"],
1855  $_POST["color_code"]);
1856  $ilCtrl->redirect($this, "listColors");
1857  }
1858  }
1859  $this->form_gui->setValuesByPost();
1860  $tpl->setContent($this->form_gui->getHTML());
1861  }
1862 
1867  {
1868  global $tpl, $ilCtrl, $lng;
1869 
1870  $this->initColorForm("edit");
1871 
1872  if ($this->form_gui->checkInput())
1873  {
1874  if ($this->object->colorExists($_POST["color_name"]) &&
1875  $_POST["color_name"] != $_GET["c_name"])
1876  {
1877  $col_input = $this->form_gui->getItemByPostVar("color_name");
1878  $col_input->setAlert($lng->txt("sty_color_already_exists"));
1879  }
1880  else
1881  {
1882  $this->object->updateColor($_GET["c_name"], $_POST["color_name"],
1883  $_POST["color_code"]);
1884  $ilCtrl->redirect($this, "listColors");
1885  }
1886  }
1887  $ilCtrl->setParameter($this, "c_name", $_GET["c_name"]);
1888  $this->form_gui->setValuesByPost();
1889  $tpl->setContent($this->form_gui->getHTML());
1890  }
1891 
1896  {
1897  global $ilCtrl, $tpl, $lng;
1898 
1899  if (!is_array($_POST["color"]) || count($_POST["color"]) == 0)
1900  {
1901  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
1902  $ilCtrl->redirect($this, "listColors");
1903  }
1904  else
1905  {
1906  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1907  $cgui = new ilConfirmationGUI();
1908  $cgui->setFormAction($ilCtrl->getFormAction($this));
1909  $cgui->setHeaderText($lng->txt("sty_confirm_color_deletion"));
1910  $cgui->setCancel($lng->txt("cancel"), "cancelColorDeletion");
1911  $cgui->setConfirm($lng->txt("delete"), "deleteColor");
1912 
1913  foreach ($_POST["color"] as $c)
1914  {
1915  $cgui->addItem("color[]", ilUtil::prepareFormOutput($c), $c);
1916  }
1917 
1918  $tpl->setContent($cgui->getHTML());
1919  }
1920  }
1921 
1926  {
1927  global $ilCtrl;
1928 
1929  $ilCtrl->redirect($this, "listColors");
1930  }
1931 
1936  {
1937  global $ilCtrl;
1938 
1939  if (is_array($_POST["color"]))
1940  {
1941  foreach ($_POST["color"] as $c)
1942  {
1943  $this->object->removeColor($c);
1944  }
1945  }
1946 
1947  $ilCtrl->redirect($this, "listColors");
1948  }
1949 
1950  //
1951  // Media query management
1952  //
1953 
1958  {
1959  global $tpl, $rbacsystem, $ilToolbar, $ilCtrl;
1960 
1961  if ($rbacsystem->checkAccess("write", (int) $_GET["ref_id"]))
1962  {
1963  $ilToolbar->addButton($this->lng->txt("sty_add_media_query"),
1964  $ilCtrl->getLinkTarget($this, "addMediaQuery"));
1965  }
1966 
1967  include_once("./Services/Style/classes/class.ilStyleMediaQueryTableGUI.php");
1968  $table_gui = new ilStyleMediaQueryTableGUI($this, "listMediaQueries",
1969  $this->object);
1970  $tpl->setContent($table_gui->getHTML());
1971  }
1972 
1977  {
1978  global $tpl;
1979 
1980  $this->initMediaQueryForm();
1981  $tpl->setContent($this->form_gui->getHTML());
1982  }
1983 
1988  {
1989  global $tpl, $ilCtrl;
1990 
1991  $ilCtrl->setParameter($this, "mq_id", $_GET["mq_id"]);
1992  $this->initMediaQueryForm("edit");
1993  $this->getMediaQueryFormValues();
1994  $tpl->setContent($this->form_gui->getHTML());
1995  }
1996 
1997 
2001  function initMediaQueryForm($a_mode = "create")
2002  {
2003  global $lng, $ilCtrl;
2004 
2005  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
2006  $this->form_gui = new ilPropertyFormGUI();
2007 
2008  $this->form_gui->setTitle($lng->txt("sty_add_media_query"));
2009 
2010  // media query
2011  $ti = new ilTextInputGUI("@media", "mquery");
2012  $ti->setMaxLength(2000);
2013  $this->form_gui->addItem($ti);
2014 
2015 
2016  if ($a_mode == "create")
2017  {
2018  $this->form_gui->addCommandButton("saveMediaQuery", $lng->txt("save"));
2019  $this->form_gui->addCommandButton("listMediaQueries", $lng->txt("cancel"));
2020  }
2021  else
2022  {
2023  $this->form_gui->addCommandButton("updateMediaQuery", $lng->txt("save"));
2024  $this->form_gui->addCommandButton("listMediaQueries", $lng->txt("cancel"));
2025  }
2026  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
2027  }
2028 
2033  {
2034  if ($_GET["mq_id"] != "")
2035  {
2036  foreach ($this->object->getMediaQueries() as $mq)
2037  {
2038  if ($mq["id"] == (int) $_GET["mq_id"])
2039  {
2040  $values["mquery"] = $mq["mquery"];
2041  }
2042  }
2043  $this->form_gui->setValuesByArray($values);
2044  }
2045  }
2046 
2051  {
2052  global $tpl, $ilCtrl, $lng;
2053 
2054  $this->initMediaQueryForm();
2055 
2056  if ($this->form_gui->checkInput())
2057  {
2058  $this->object->addMediaQuery($_POST["mquery"]);
2059  $ilCtrl->redirect($this, "listMediaQueries");
2060  }
2061  $this->form_gui->setValuesByPost();
2062  $tpl->setContent($this->form_gui->getHTML());
2063  }
2064 
2069  {
2070  global $tpl, $ilCtrl, $lng;
2071 
2072  $this->initMediaQueryForm("edit");
2073 
2074  if ($this->form_gui->checkInput())
2075  {
2076  $this->object->updateMediaQuery((int) $_GET["mq_id"], $_POST["mquery"]);
2077  $ilCtrl->redirect($this, "listMediaQueries");
2078  }
2079  $ilCtrl->setParameter($this, "mq_id", $_GET["mq_id"]);
2080  $this->form_gui->setValuesByPost();
2081  $tpl->setContent($this->form_gui->getHTML());
2082  }
2083 
2088  {
2089  global $ilCtrl, $tpl, $lng;
2090 
2091  if (!is_array($_POST["mq_id"]) || count($_POST["mq_id"]) == 0)
2092  {
2093  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
2094  $ilCtrl->redirect($this, "listMediaQueries");
2095  }
2096  else
2097  {
2098  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
2099  $cgui = new ilConfirmationGUI();
2100  $cgui->setFormAction($ilCtrl->getFormAction($this));
2101  $cgui->setHeaderText($lng->txt("sty_sure_del_mqueries"));
2102  $cgui->setCancel($lng->txt("cancel"), "listMediaQueries");
2103  $cgui->setConfirm($lng->txt("delete"), "deleteMediaQueries");
2104 
2105  foreach ($_POST["mq_id"] as $i)
2106  {
2107  $mq = $this->object->getMediaQueryForId($i);
2108  $cgui->addItem("mq_id[]", $i, $mq["mquery"]);
2109  }
2110 
2111  $tpl->setContent($cgui->getHTML());
2112  }
2113  }
2114 
2122  {
2123  global $ilCtrl, $rbacsystem;
2124 
2125  if ($rbacsystem->checkAccess("write", (int) $_GET["ref_id"]) && is_array($_POST["mq_id"]))
2126  {
2127  foreach ($_POST["mq_id"] as $id)
2128  {
2129  $this->object->deleteMediaQuery($id);
2130  }
2131  }
2132  $ilCtrl->redirect($this, "listMediaQueries");
2133  }
2134 
2142  {
2143  global $ilCtrl;
2144 
2145  if (is_array($_POST["order"]))
2146  {
2147  $this->object->saveMediaQueryOrder($_POST["order"]);
2148  }
2149  $ilCtrl->redirect($this, "listMediaQueries");
2150  }
2151 
2152 
2153  //
2154  // Templates management
2155  //
2156 
2161  {
2162  global $tpl, $ilTabs, $ilCtrl;
2163 
2164  $ctype = $_GET["temp_type"];
2165  if ($ctype == "")
2166  {
2167  $ctype = "table";
2168  $ilCtrl->setParameter($this, "temp_type", $ctype);
2169  $_GET["temp_type"] = $ctype;
2170  }
2171 
2172  $this->setTemplatesSubTabs();
2173  $ilTabs->setSubTabActive("sty_".$ctype."_templates");
2174 
2175  $this->includeCSS();
2176  include_once("./Services/Style/classes/class.ilTableTemplatesTableGUI.php");
2177  $table_gui = new ilTableTemplatesTableGUI($ctype, $this, "listTemplates",
2178  $this->object);
2179  $tpl->setContent($table_gui->getHTML());
2180 
2181  }
2182 
2187  {
2188  global $tpl;
2189 
2190  $this->initTemplateForm();
2191  $tpl->setContent($this->form_gui->getHTML());
2192  }
2193 
2198  {
2199  global $tpl, $ilCtrl;
2200 
2201  $ilCtrl->setParameter($this, "t_id", $_GET["t_id"]);
2202  $this->initTemplateForm("edit");
2203  $this->getTemplateFormValues();
2204 
2205  $this->displayTemplateEditForm();
2206  }
2207 
2211  function getTemplatePreview($a_type, $a_t_id, $a_small_mode = false)
2212  {
2213  return $this->_getTemplatePreview(
2214  $this->object, $a_type, $a_t_id, $a_small_mode);
2215  }
2216 
2220  function _getTemplatePreview($a_style, $a_type, $a_t_id, $a_small_mode = false)
2221  {
2222  global $lng, $tpl;
2223 
2224  $kr = $kc = 7;
2225  if ($a_small_mode)
2226  {
2227  $kr = 6;
2228  $kc = 5;
2229  }
2230 
2231  $ts = $a_style->getTemplate($a_t_id);
2232  $t = $ts["classes"];
2233 
2234  // preview
2235  if ($a_type == "table")
2236  {
2237  $p_content = '<PageContent><Table DataTable="y"';
2238  if ($t["row_head"] != "")
2239  {
2240  $p_content.= ' HeaderRows="1"';
2241  }
2242  if ($t["row_foot"] != "")
2243  {
2244  $p_content.= ' FooterRows="1"';
2245  }
2246  if ($t["col_head"] != "")
2247  {
2248  $p_content.= ' HeaderCols="1"';
2249  }
2250  if ($t["col_foot"] != "")
2251  {
2252  $p_content.= ' FooterCols="1"';
2253  }
2254  $p_content.= ' Template="'.$a_style->lookupTemplateName($a_t_id).'">';
2255  if (!$a_small_mode)
2256  {
2257  $p_content.= '<Caption>'.$lng->txt("sty_caption").'</Caption>';
2258  }
2259  for($i = 1; $i<=$kr; $i++)
2260  {
2261  $p_content.= '<TableRow>';
2262  for($j = 1; $j<=$kc; $j++)
2263  {
2264  if ($a_small_mode)
2265  {
2266  $cell = '&lt;div style="height:2px;"&gt;&lt;/div&gt;';
2267  }
2268  else
2269  {
2270  $cell = 'xxx';
2271  }
2272  $p_content.= '<TableData><PageContent><Paragraph Characteristic="TableContent">'.$cell.'</Paragraph></PageContent></TableData>';
2273  }
2274  $p_content.= '</TableRow>';
2275  }
2276  $p_content.= '</Table></PageContent>';
2277  }
2278 
2279  if ($a_type == "vaccordion" || $a_type == "haccordion")
2280  {
2281  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
2283 
2284  if ($a_small_mode)
2285  {
2286  $c = '&amp;nbsp;';
2287  $h = '&amp;nbsp;';
2288  }
2289  else
2290  {
2291  $c = 'xxx';
2292  $h = 'head';
2293  }
2294  if ($a_type == "vaccordion")
2295  {
2296  $p_content = '<PageContent><Tabs HorizontalAlign="Left" Type="VerticalAccordion" ';
2297  if ($a_small_mode)
2298  {
2299  $p_content.= ' ContentWidth="70"';
2300  }
2301  }
2302  else
2303  {
2304  $p_content = '<PageContent><Tabs Type="HorizontalAccordion"';
2305  if ($a_small_mode)
2306  {
2307  $p_content.= ' ContentHeight="40"';
2308  $p_content.= ' ContentWidth="70"';
2309  $c = '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;';
2310  }
2311  else
2312  {
2313  $p_content.= ' ContentHeight="40"';
2314  }
2315  }
2316  $p_content.= ' Template="'.$a_style->lookupTemplateName($a_t_id).'">';
2317  $p_content.= '<Tab><PageContent><Paragraph>'.$c.'</Paragraph></PageContent>';
2318  $p_content.= '<TabCaption>'.$h.'</TabCaption>';
2319  $p_content.= '</Tab>';
2320  $p_content.= '</Tabs></PageContent>';
2321  }
2322 //echo htmlentities($p_content);
2323  $txml = $a_style->getTemplateXML();
2324 //echo htmlentities($txml);
2325  $p_content.= $txml;
2326  include_once("./Services/COPage/classes/class.ilPCTableGUI.php");
2327  $r_content = ilPCTableGUI::_renderTable($p_content, "");
2328 
2329  return $r_content;
2330  }
2331 
2335  function initTemplateForm($a_mode = "create")
2336  {
2337  global $lng, $ilCtrl;
2338 
2339  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
2340  $this->form_gui = new ilPropertyFormGUI();
2341 
2342  if ($a_mode == "create")
2343  {
2344  $this->form_gui->setTitle($lng->txt("sty_add_template"));
2345  }
2346  else
2347  {
2348  $this->form_gui->setTitle($lng->txt("sty_edit_template"));
2349  }
2350 
2351  // name
2352  $name_input = new ilRegExpInputGUI($lng->txt("sty_template_name"), "name");
2353  $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
2354  $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include")." A-Z, a-z, 1-9");
2355  $name_input->setRequired(true);
2356  $name_input->setSize(30);
2357  $name_input->setMaxLength(30);
2358  $this->form_gui->addItem($name_input);
2359 
2360  // template style classes
2361  $scs = ilObjStyleSheet::_getTemplateClassTypes($_GET["temp_type"]);
2362  foreach ($scs as $sc => $st)
2363  {
2364  $sc_input = new ilSelectInputGUI($lng->txt("sty_".$sc."_class"), $sc."_class");
2365  $chars = $this->object->getCharacteristics($st);
2366  $options = array("" => "");
2367  foreach($chars as $char)
2368  {
2369  $options[$char] = $char;
2370  }
2371  $sc_input->setOptions($options);
2372  $this->form_gui->addItem($sc_input);
2373  }
2374 
2375  if ($a_mode == "create")
2376  {
2377  $this->form_gui->addCommandButton("saveTemplate", $lng->txt("save"));
2378  $this->form_gui->addCommandButton("cancelTemplateSaving", $lng->txt("cancel"));
2379  }
2380  else
2381  {
2382  $this->form_gui->addCommandButton("refreshTemplate", $lng->txt("save_refresh"));
2383  $this->form_gui->addCommandButton("updateTemplate", $lng->txt("save_return"));
2384  $this->form_gui->addCommandButton("cancelTemplateSaving", $lng->txt("cancel"));
2385  }
2386  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
2387  }
2388 
2393  {
2394  global $ilCtrl;
2395 
2396  $ilCtrl->redirect($this, "listTemplates");
2397  }
2398 
2399 
2404  {
2405  global $tpl, $ilCtrl, $lng;
2406 
2407  $this->initTemplateForm();
2408 
2409  if ($this->form_gui->checkInput())
2410  {
2411  if ($this->object->templateExists($_POST["name"]))
2412  {
2413  $name_input = $this->form_gui->getItemByPostVar("name");
2414  $name_input->setAlert($lng->txt("sty_table_template_already_exists"));
2415  }
2416  else
2417  {
2418  $classes = array();
2419  foreach (ilObjStyleSheet::_getTemplateClassTypes($_GET["temp_type"]) as $tct => $ct)
2420  {
2421  $classes[$tct] = $_POST[$tct."_class"];
2422  }
2423  $t_id = $this->object->addTemplate($_GET["temp_type"], $_POST["name"], $classes);
2424  $this->object->writeTemplatePreview($t_id,
2425  $this->getTemplatePreview($_GET["temp_type"], $t_id, true));
2426  $ilCtrl->redirect($this, "listTemplates");
2427  }
2428  }
2429  $this->form_gui->setValuesByPost();
2430  $tpl->setContent($this->form_gui->getHTML());
2431  }
2432 
2436  function updateTemplateObject($a_refresh = false)
2437  {
2438  global $tpl, $ilCtrl, $lng;
2439 
2440  $ilCtrl->setParameter($this, "t_id", $_GET["t_id"]);
2441  $this->initTemplateForm("edit");
2442 
2443  if ($this->form_gui->checkInput())
2444  {
2445  if ($this->object->templateExists($_POST["name"]) &&
2446  $_POST["name"] != ilObjStyleSheet::lookupTemplateName($_GET["t_id"]))
2447  {
2448  $name_input = $this->form_gui->getItemByPostVar("name");
2449  $name_input->setAlert($lng->txt("sty_template_already_exists"));
2450  }
2451  else
2452  {
2453  $classes = array();
2454  foreach (ilObjStyleSheet::_getTemplateClassTypes($_GET["temp_type"]) as $tct => $ct)
2455  {
2456  $classes[$tct] = $_POST[$tct."_class"];
2457  }
2458 
2459  $this->object->updateTemplate($_GET["t_id"],
2460  $_POST["name"], $classes);
2461  $this->object->writeTemplatePreview($_GET["t_id"],
2462  $this->getTemplatePreview($_GET["temp_type"], $_GET["t_id"], true));
2463  if(!$a_refresh)
2464  {
2465  $ilCtrl->redirect($this, "listTemplates");
2466  }
2467  }
2468  }
2469 
2470  $this->form_gui->setValuesByPost();
2471  $this->displayTemplateEditForm();
2472  }
2473 
2478  {
2479  global $tpl;
2480 
2481  $a_tpl = new ilTemplate("tpl.template_edit.html", true, true,
2482  "Services/Style");
2483  $this->includeCSS();
2484  $a_tpl->setVariable("FORM", $this->form_gui->getHTML());
2485  $a_tpl->setVariable("PREVIEW", $this->getTemplatePreview($_GET["temp_type"], $_GET["t_id"]));
2486  $tpl->setContent($a_tpl->get());
2487  }
2488 
2493  {
2494  $this->updateTemplateObject(true);
2495  }
2496 
2501  {
2502  if ($_GET["t_id"] > 0)
2503  {
2504  $t = $this->object->getTemplate($_GET["t_id"]);
2505 
2506  $values["name"] = $t["name"];
2507  $scs = ilObjStyleSheet::_getTemplateClassTypes($_GET["temp_type"]);
2508  foreach ($scs as $k => $type)
2509  {
2510  $values[$k."_class"] = $t["classes"][$k];
2511  }
2512  $this->form_gui->setValuesByArray($values);
2513  }
2514  }
2515 
2520  {
2521  global $ilCtrl, $tpl, $lng;
2522 
2523  if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0)
2524  {
2525  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
2526  $ilCtrl->redirect($this, "listTemplates");
2527  }
2528  else
2529  {
2530  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
2531  $cgui = new ilConfirmationGUI();
2532  $cgui->setFormAction($ilCtrl->getFormAction($this));
2533  $cgui->setHeaderText($lng->txt("sty_confirm_template_deletion"));
2534  $cgui->setCancel($lng->txt("cancel"), "cancelTemplateDeletion");
2535  $cgui->setConfirm($lng->txt("sty_del_template"), "deleteTemplate");
2536 
2537  foreach ($_POST["tid"] as $tid)
2538  {
2539  $classes = $this->object->getTemplateClasses($tid);
2540  $cl_str = "";
2541  $listed = array();
2542  foreach ($classes as $cl)
2543  {
2544  if ($cl != "" && !$listed[$cl])
2545  {
2546  $cl_str.= '<div>- '.
2547  $cl."</div>";
2548  $listed[$cl] = true;
2549  }
2550  }
2551  if ($cl_str != "")
2552  {
2553  $cl_str = '<div style="padding-left:30px;" class="small">'.
2554  "<div><i>".$lng->txt("sty_style_class")."</i></div>".$cl_str."</div>";
2555  }
2556  $cgui->addItem("tid[]", $tid, $this->object->lookupTemplateName($tid).$cl_str);
2557  }
2558 
2559  $cgui->addButton($lng->txt("sty_del_template_keep_classes"), "deleteTemplateKeepClasses");
2560 
2561  $tpl->setContent($cgui->getHTML());
2562  }
2563  }
2564 
2569  {
2570  global $ilCtrl;
2571 
2572  $ilCtrl->redirect($this, "listTemplates");
2573  }
2574 
2579  {
2580  global $ilCtrl;
2581 
2582  if (is_array($_POST["tid"]))
2583  {
2584  foreach ($_POST["tid"] as $tid)
2585  {
2586  $this->object->removeTemplate($tid);
2587  }
2588  }
2589 
2590  $ilCtrl->redirect($this, "listTemplates");
2591  }
2592 
2597  {
2598  global $ilCtrl;
2599 
2600  if (is_array($_POST["tid"]))
2601  {
2602  foreach ($_POST["tid"] as $tid)
2603  {
2604  $cls = $this->object->getTemplateClasses($tid);
2605  foreach ($cls as $k => $cls)
2606  {
2607  $ty = $this->object->determineTemplateStyleClassType($_GET["temp_type"], $k);
2608  $ta = ilObjStyleSheet::_determineTag($ty);
2609  $this->object->deleteCharacteristic($ty, $ta, $cls);
2610  }
2611  $this->object->removeTemplate($tid);
2612  }
2613  }
2614 
2615  $ilCtrl->redirect($this, "listTemplates");
2616  }
2617 
2622  {
2623  global $tpl;
2624 
2625  $this->initTemplateGenerationForm();
2626  $tpl->setContent($this->form_gui->getHTML());
2627  }
2628 
2633  {
2634  global $lng, $ilCtrl;
2635 
2636  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
2637  $this->form_gui = new ilPropertyFormGUI();
2638 
2639  $this->form_gui->setTitle($lng->txt("sty_generate_template"));
2640 
2641  // name
2642  $name_input = new ilRegExpInputGUI($lng->txt("sty_template_name"), "name");
2643  $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
2644  $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include")." A-Z, a-z, 1-9");
2645  $name_input->setRequired(true);
2646  $name_input->setSize(30);
2647  $name_input->setMaxLength(30);
2648  $this->form_gui->addItem($name_input);
2649 
2650  // basic layout
2651  $bl_input = new ilSelectInputGUI($lng->txt("sty_template_layout"), "layout");
2652  $options = array(
2653  "coloredZebra" => $lng->txt("sty_table_template_colored_zebra"),
2654  "bwZebra" => $lng->txt("sty_table_template_bw_zebra"),
2655  "noZebra" => $lng->txt("sty_table_template_no_zebra")
2656  );
2657  $bl_input->setOptions($options);
2658  $this->form_gui->addItem($bl_input);
2659 
2660  // top bottom padding
2661  include_once("./Services/Style/classes/class.ilNumericStyleValueInputGUI.php");
2662  $num_input = new ilNumericStyleValueInputGUI($lng->txt("sty_top_bottom_padding"), "tb_padding");
2663  $num_input->setAllowPercentage(false);
2664  $num_input->setValue("3px");
2665  $this->form_gui->addItem($num_input);
2666 
2667  // left right padding
2668  $num_input = new ilNumericStyleValueInputGUI($lng->txt("sty_left_right_padding"), "lr_padding");
2669  $num_input->setAllowPercentage(false);
2670  $num_input->setValue("10px");
2671  $this->form_gui->addItem($num_input);
2672 
2673  // base color
2674  $bc_input = new ilSelectInputGUI($lng->txt("sty_base_color"), "base_color");
2675  $cs = $this->object->getColors();
2676  $options = array();
2677  foreach ($cs as $c)
2678  {
2679  $options[$c["name"]] = $c["name"];
2680  }
2681  $bc_input->setOptions($options);
2682  $this->form_gui->addItem($bc_input);
2683 
2684  // Lightness Settings
2685  $lss = array("border" => 90, "header_text" => 70, "header_bg" => 0,
2686  "cell1_text" => -60, "cell1_bg" => 90, "cell2_text" => -60, "cell2_bg" => 75);
2687  foreach ($lss as $ls => $v)
2688  {
2689  $l_input = new ilNumberInputGUI($lng->txt("sty_lightness_".$ls), "lightness_".$ls);
2690  $l_input->setMaxValue(100);
2691  $l_input->setMinValue(-100);
2692  $l_input->setValue($v);
2693  $l_input->setSize(4);
2694  $l_input->setMaxLength(4);
2695  $this->form_gui->addItem($l_input);
2696  }
2697 
2698  $this->form_gui->addCommandButton("templateGeneration", $lng->txt("generate"));
2699  $this->form_gui->addCommandButton("cancelTemplateSaving", $lng->txt("cancel"));
2700  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
2701  }
2702 
2707  {
2708  global $tpl, $ilCtrl, $lng;
2709 
2710  $this->initTemplateGenerationForm();
2711 
2712  if ($this->form_gui->checkInput())
2713  {
2714  if ($this->object->templateExists($_POST["name"]))
2715  {
2716  $name_input = $this->form_gui->getItemByPostVar("name");
2717  $name_input->setAlert($lng->txt("sty_table_template_already_exists"));
2718  }
2719  else
2720  {
2721  // -> move to application class!
2722 
2723  // cell classes
2724  $cells = array("H" => "header", "C1" => "cell1", "C2" => "cell2");
2725  $tb_p = $this->form_gui->getItemByPostVar("tb_padding");
2726  $tb_padding = $tb_p->getValue();
2727  $lr_p = $this->form_gui->getItemByPostVar("lr_padding");
2728  $lr_padding = $lr_p->getValue();
2729  $cell_color = $_POST["base_color"];
2730 
2731  // use mid gray as cell color for bw zebra
2732  if ($_POST["layout"] == "bwZebra")
2733  {
2734  $cell_color = "MidGray";
2735  if (!$this->object->colorExists($cell_color))
2736  {
2737  $this->object->addColor($cell_color, "7F7F7F");
2738  }
2739  $this->object->updateColor($cell_color, $cell_color, "7F7F7F");
2740  }
2741 
2742  foreach ($cells as $k => $cell)
2743  {
2744  $cell_class[$k] = $_POST["name"].$k;
2745  if (!$this->object->characteristicExists($cell_class[$k], "table_cell"))
2746  {
2747  $this->object->addCharacteristic("table_cell", $cell_class[$k], true);
2748  }
2749  if ($_POST["layout"] == "bwZebra" && $k == "H")
2750  {
2751  $this->object->replaceStylePar("td", $cell_class[$k], "color",
2752  "!".$_POST["base_color"]."(".$_POST["lightness_".$cell."_text"].")", "table_cell");
2753  $this->object->replaceStylePar("td", $cell_class[$k], "background-color",
2754  "!".$_POST["base_color"]."(".$_POST["lightness_".$cell."_bg"].")", "table_cell");
2755  }
2756  else
2757  {
2758  $this->object->replaceStylePar("td", $cell_class[$k], "color",
2759  "!".$cell_color."(".$_POST["lightness_".$cell."_text"].")", "table_cell");
2760  $this->object->replaceStylePar("td", $cell_class[$k], "background-color",
2761  "!".$cell_color."(".$_POST["lightness_".$cell."_bg"].")", "table_cell");
2762  }
2763  $this->object->replaceStylePar("td", $cell_class[$k], "padding-top",
2764  $tb_padding, "table_cell");
2765  $this->object->replaceStylePar("td", $cell_class[$k], "padding-bottom",
2766  $tb_padding, "table_cell");
2767  $this->object->replaceStylePar("td", $cell_class[$k], "padding-left",
2768  $lr_padding, "table_cell");
2769  $this->object->replaceStylePar("td", $cell_class[$k], "padding-right",
2770  $lr_padding, "table_cell");
2771  $this->object->replaceStylePar("td", $cell_class[$k], "border-width",
2772  "1px", "table_cell");
2773  $this->object->replaceStylePar("td", $cell_class[$k], "border-style",
2774  "solid", "table_cell");
2775  $this->object->replaceStylePar("td", $cell_class[$k], "border-color",
2776  "!".$cell_color."(".$_POST["lightness_border"].")", "table_cell");
2777  $this->object->replaceStylePar("td", $cell_class[$k], "font-weight",
2778  "normal", "table_cell");
2779  }
2780 
2781  // table class
2782  $classes["table"] = $_POST["name"]."T";
2783  if (!$this->object->characteristicExists($classes["table"], "table"))
2784  {
2785  $this->object->addCharacteristic("table", $classes["table"], true);
2786  }
2787  $this->object->replaceStylePar("table", $classes["table"], "caption-side",
2788  "bottom", "table");
2789  $this->object->replaceStylePar("table", $classes["table"], "border-collapse",
2790  "collapse", "table");
2791  $this->object->replaceStylePar("table", $classes["table"], "margin-top",
2792  "5px", "table");
2793  $this->object->replaceStylePar("table", $classes["table"], "margin-bottom",
2794  "5px", "table");
2795  if ($_POST["layout"] == "bwZebra")
2796  {
2797  $this->object->replaceStylePar("table", $classes["table"], "border-bottom-color",
2798  "!".$_POST["base_color"], "table");
2799  $this->object->replaceStylePar("table", $classes["table"], "border-bottom-style",
2800  "solid", "table");
2801  $this->object->replaceStylePar("table", $classes["table"], "border-bottom-width",
2802  "3px", "table");
2803  $sb = array("left", "right", "top");
2804  foreach ($sb as $b)
2805  {
2806  $this->object->replaceStylePar("table", $classes["table"], "border-".$b."-width",
2807  "0px", "table");
2808  }
2809  }
2810 
2811  switch ($_POST["layout"])
2812  {
2813  case "coloredZebra":
2814  $classes["row_head"] = $cell_class["H"];
2815  $classes["odd_row"] = $cell_class["C1"];
2816  $classes["even_row"] = $cell_class["C2"];
2817  break;
2818 
2819  case "bwZebra":
2820  $classes["row_head"] = $cell_class["H"];
2821  $classes["odd_row"] = $cell_class["C1"];
2822  $classes["even_row"] = $cell_class["C2"];
2823  break;
2824 
2825  case "noZebra":
2826  $classes["row_head"] = $cell_class["H"];
2827  $classes["odd_row"] = $cell_class["C1"];
2828  $classes["even_row"] = $cell_class["C1"];
2829  $classes["col_head"] = $cell_class["C2"];
2830  break;
2831  }
2832 
2833 
2834  $t_id = $this->object->addTemplate($_GET["temp_type"],
2835  $_POST["name"], $classes);
2836  $this->object->writeTemplatePreview($t_id,
2837  $this->getTemplatePreview($_GET["temp_type"], $t_id, true));
2838  $ilCtrl->redirect($this, "listTemplates");
2839  }
2840  }
2841  $this->form_gui->setValuesByPost();
2842  $tpl->setContent($this->form_gui->getHTML());
2843  }
2844 
2846  {
2847  global $tpl;
2848 
2849  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
2850 
2851  $acc = new ilAccordionGUI();
2852  $acc->addItem("Header 1", str_repeat("bla bla bla bla bla bla", 30));
2853  $acc->addItem("Header 2", str_repeat("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xx x xx x xx", 30));
2854  $acc->setOrientation(ilAccordionGUI::HORIZONTAL);
2855 
2856  $ac2 = new ilAccordionGUI();
2857  $ac2->addItem("Header 1", str_repeat("bla bla bla bla bla bla", 30));
2858  $ac2->addItem("Header 2", $acc->getHTML());
2859  $ac2->setOrientation(ilAccordionGUI::VERTICAL);
2860 
2861  $tpl->setContent($ac2->getHTML());
2862  }
2863 
2868  {
2869  global $ilCtrl;
2870 
2871  if ($_GET["baseClass"] == "ilAdministrationGUI")
2872  {
2873  $ilCtrl->redirectByClass("ilobjstylesettingsgui", "editContentStyles");
2874  }
2875  $ilCtrl->returnToParent($this);
2876  }
2877 
2878 
2879 }
2880 ?>