ILIAS  Release_4_2_x_branch Revision 61807
 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 "./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  $this->prepareOutput();
56  switch($next_class)
57  {
58  default:
59  $cmd.= "Object";
60  $ret =& $this->$cmd();
61  break;
62  }
63 
64  return $ret;
65  }
66 
67  function viewObject()
68  {
69  $this->editObject();
70  }
71 
75  function createObject()
76  {
77  global $rbacsystem, $lng, $tpl;
78 
79  //$this->setTabs();
80 
81  $this->lng =& $lng;
82  //$this->ctrl->setParameter($this,'new_type',$this->type);
83  $this->getTemplateFile("create", "sty");
84 
85  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("sty_create_new_stylesheet"));
86 
87  $this->tpl->setVariable("TXT_STYLE_BY_IMPORT", $this->lng->txt("sty_import_stylesheet"));
88  $this->tpl->setVariable("TXT_STYLE_BY_COPY", $this->lng->txt("sty_copy_other_stylesheet"));
89  $this->tpl->setVariable("TXT_SELECT_FILE", $this->lng->txt("import_file"));
90  $this->tpl->setVariable("TXT_SOURCE", $this->lng->txt("sty_source"));
91  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
92  $this->tpl->setVariable("TXT_DESC", $this->lng->txt("description"));
93 
94  $this->ctrl->setParameter($this, "new_type", "sty");
95  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
96  $this->tpl->setVariable("TXT_SAVE", $this->lng->txt("save"));
97  $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
98  $this->tpl->setVariable("TXT_COPY", $this->lng->txt("copy"));
99  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
100  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
101 
102  // get all learning module styles
103  $clonable_styles = ilObjStyleSheet::_getClonableContentStyles();
104  $select = ilUtil::formSelect("", "source_style", $clonable_styles, false, true);
105  $this->tpl->setVariable("SOURCE_SELECT", $select);
106  }
107 
111  function includeCSS()
112  {
113  // set style sheet
114  $this->tpl->setCurrentBlock("ContentStyle");
115  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
116  $this->object->getContentStylePath($this->object->getId()));
117  $this->tpl->parseCurrentBlock();
118  }
119 
123  function editObject()
124  {
125  global $rbacsystem, $lng, $ilTabs, $ilCtrl, $ilToolbar, $tpl;
126 
127  $this->setSubTabs();
128 
129  $this->includeCSS();
130 
131  $ctpl = new ilTemplate("tpl.sty_classes.html", true, true, "Services/Style");
132 
133  // output characteristics
134  $chars = $this->object->getCharacteristics();
135 
136  $style_type = ($this->super_type != "")
137  ? $this->super_type
138  : "text_block";
139  $ilCtrl->setParameter($this, "style_type", $style_type);
140  $ilTabs->setSubTabActive("sty_".$style_type."_char");
141 
142  // workaround to include default rte styles
143  if ($this->super_type == "rte")
144  {
145  $tpl->addCss("Modules/Scorm2004/templates/default/player.css");
146  include_once("./Modules/Scorm2004/classes/ilSCORM13Player.php");
147  $tpl->addInlineCss(ilSCORM13Player::getInlineCss());
148  }
149 
150  // add new style?
151  $all_super_types = ilObjStyleSheet::_getStyleSuperTypes();
152  $subtypes = $all_super_types[$style_type];
153  $expandable = false;
154  foreach ($subtypes as $t)
155  {
157  {
158  $expandable = true;
159  }
160  }
161  if ($expandable && $rbacsystem->checkAccess("write", (int) $_GET["ref_id"]))
162  {
163  $ilToolbar->addButton($lng->txt("sty_add_characteristic"),
164  $ilCtrl->getLinkTarget($this, "addCharacteristicForm"));
165  }
166 
167  if ($_SESSION["sty_copy"] != "")
168  {
169  $style_cp = explode(":::", $_SESSION["sty_copy"]);
170  if ($style_cp[1] == $_GET["style_type"])
171  {
172  if ($expandable)
173  {
174  $ilToolbar->addSeparator();
175  }
176  $ilToolbar->addButton($lng->txt("sty_paste_style_classes"),
177  $ilCtrl->getLinkTarget($this, "pasteCharacteristicsOverview"));
178  }
179  }
180 
181  include_once("./Services/Style/classes/class.ilStyleTableGUI.php");
182  $table_gui = new ilStyleTableGUI($this, "edit", $chars, $style_type,
183  $this->object);
184 
185  $ctpl->setCurrentBlock("style_table");
186  $ctpl->setVariable("STYLE_TABLE", $table_gui->getHTML());
187  $ctpl->parseCurrentBlock();
188 
189  $this->tpl->setContent($ctpl->get());
190  }
191 
195  function propertiesObject()
196  {
197  global $rbacsystem, $lng, $ilToolbar;
198 
199  // set style sheet
200  $this->tpl->setCurrentBlock("ContentStyle");
201  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
202  $this->object->getContentStylePath($this->object->getId()));
203  $this->tpl->parseCurrentBlock();
204 
205  // export button
206  $ilToolbar->addButton($this->lng->txt("export"),
207  $this->ctrl->getLinkTarget($this, "exportStyle"));
208 
209  $this->initPropertiesForm();
210  $this->getPropertiesValues();
211  $this->tpl->setContent($this->form->getHTML());
212 
213  }
214 
219  public function getPropertiesValues()
220  {
221  $values = array();
222 
223  $values["style_title"] = $this->object->getTitle();
224  $values["style_description"] = $this->object->getDescription();
225  $values["disable_auto_margins"] = (int) $this->object->lookupStyleSetting("disable_auto_margins");
226 
227  $this->form->setValuesByArray($values);
228  }
229 
235  public function initPropertiesForm($a_mode = "edit")
236  {
237  global $lng, $rbacsystem;
238 
239  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
240  $this->form = new ilPropertyFormGUI();
241 
242  // title
243  $ti = new ilTextInputGUI($this->lng->txt("title"), "style_title");
244  $ti->setMaxLength(128);
245  $ti->setSize(40);
246  $ti->setRequired(true);
247  $this->form->addItem($ti);
248 
249  // description
250  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "style_description");
251  //$ta->setCols();
252  //$ta->setRows();
253  $this->form->addItem($ta);
254 
255  // disable automatic margins for left/right alignment
256  $cb = new ilCheckboxInputGUI($this->lng->txt("sty_disable_auto_margins"), "disable_auto_margins");
257  $cb->setInfo($this->lng->txt("sty_disable_auto_margins_info"));
258  $this->form->addItem($cb);
259 
260  // save and cancel commands
261 
262  if ($a_mode == "create")
263  {
264  $this->form->addCommandButton("save", $lng->txt("save"));
265  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
266  }
267  else
268  {
269  if ($rbacsystem->checkAccess("write", (int) $_GET["ref_id"]))
270  {
271  $this->form->addCommandButton("update", $lng->txt("save"));
272  }
273  }
274 
275  $this->form->setTitle($lng->txt("edit_stylesheet"));
276  $this->form->setFormAction($this->ctrl->getFormAction($this));
277 
278  }
279 
283  function updateObject()
284  {
285  global $lng, $ilCtrl, $tpl;
286 
287  $this->initPropertiesForm("edit");
288  if ($this->form->checkInput())
289  {
290  $this->object->setTitle($this->form->getInput("style_title"));
291  $this->object->setDescription($this->form->getInput("style_description"));
292  $this->object->writeStyleSetting("disable_auto_margins",
293  $this->form->getInput("disable_auto_margins"));
294  $this->object->update();
295  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
296  $ilCtrl->redirect($this, "properties");
297  }
298  else
299  {
300  $this->form->setValuesByPost();
301  $tpl->setContent($this->form->getHtml());
302  }
303  }
304 
309  {
310  global $ilCtrl;
311 
312  $cur = explode(".",$_GET["tag"]);
313  $cur_tag = $cur[0];
314  $cur_class = $cur[1];
315 
316  $this->initTagStyleForm("edit", $cur_tag);
317 
318  if ($this->form_gui->checkInput())
319  {
320  $this->saveTagStyle();
321  $ilCtrl->redirect($this, "editTagStyle");
322  }
323  else
324  {
325  $this->form_gui->setValuesByPost();
326  $this->outputTagStyleEditScreen();
327  }
328  }
329 
334  {
335  global $ilCtrl;
336 
337  $cur = explode(".",$_GET["tag"]);
338  $cur_tag = $cur[0];
339  $cur_class = $cur[1];
340 
341  $this->initTagStyleForm("edit", $cur_tag);
342  if ($this->form_gui->checkInput())
343  {
344  $this->saveTagStyle();
345  $ilCtrl->redirect($this, "edit");
346  }
347  else
348  {
349  $this->form_gui->setValuesByPost();
350  $this->outputTagStyleEditScreen();
351  }
352  }
353 
357  function saveTagStyle()
358  {
359  $cur = explode(".", $_GET["tag"]);
360  $cur_tag = $cur[0];
361  $cur_class = $cur[1];
362  $avail_pars = ilObjStyleSheet::_getStyleParameters($cur_tag);
363  foreach ($avail_pars as $par => $v)
364  {
365  $var = str_replace("-", "_", $par);
366  $basepar_arr = explode(".", $par);
367  $basepar = $basepar_arr[0];
368  if ($basepar_arr[1] != "" && $basepar_arr[1] != $cur_tag)
369  {
370  continue;
371  }
372 
373  switch ($v["input"])
374  {
375  case "fontsize":
376  case "numeric_no_perc":
377  case "numeric":
378  case "background_image":
379  $in = $this->form_gui->getItemByPostVar($basepar);
380 //echo "<br>-".$cur_tag."-".$cur_class."-".$basepar."-".$_GET["style_type"]."-";
381  $this->writeStylePar($cur_tag, $cur_class, $basepar, $in->getValue(), $_GET["style_type"]);
382  break;
383 
384  case "color":
385  $color = trim($_POST[$basepar]);
386  if ($color != "" && trim(substr($color,0,1) != "!"))
387  {
388  $color = "#".$color;
389  }
390  $this->writeStylePar($cur_tag, $cur_class, $basepar, $color, $_GET["style_type"]);
391  break;
392 
393  case "trbl_numeric":
394  case "border_width":
395  case "border_style":
396  $in = $this->form_gui->getItemByPostVar($basepar);
397  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][0], $in->getAllValue(), $_GET["style_type"]);
398  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][1], $in->getTopValue(), $_GET["style_type"]);
399  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][2], $in->getRightValue(), $_GET["style_type"]);
400  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][3], $in->getBottomValue(), $_GET["style_type"]);
401  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][4], $in->getLeftValue(), $_GET["style_type"]);
402  break;
403 
404  case "trbl_color":
405  $in = $this->form_gui->getItemByPostVar($basepar);
406  $tblr_p = array (0 => "getAllValue", 1 => "getTopValue", 2 => "getRightValue",
407  3 => "getBottomValue", 4 => "getLeftValue");
408  foreach ($tblr_p as $k => $func)
409  {
410  $val = trim($in->$func());
411  $val = (($in->getAcceptNamedColors() && substr($val, 0, 1) == "!")
412  || $val == "")
413  ? $val
414  : "#".$val;
415  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][$k], $val, $_GET["style_type"]);
416  }
417  /*$this->writeStylePar($cur_tag, $cur_class, $v["subpar"][0],
418  trim($in->getAllValue() != "") ? "#".$in->getAllValue() : "", $_GET["style_type"]);
419  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][1],
420  trim($in->getTopValue() != "") ? "#".$in->getTopValue() : "", $_GET["style_type"]);
421  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][2],
422  trim($in->getRightValue() != "") ? "#".$in->getRightValue() : "", $_GET["style_type"]);
423  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][3],
424  trim($in->getBottomValue() != "") ? "#".$in->getBottomValue() : "", $_GET["style_type"]);
425  $this->writeStylePar($cur_tag, $cur_class, $v["subpar"][4],
426  trim($in->getLeftValue() != "") ? "#".$in->getLeftValue() : "", $_GET["style_type"]);
427  */
428  break;
429 
430  case "background_position":
431  $in = $this->form_gui->getItemByPostVar($basepar);
432  $this->writeStylePar($cur_tag, $cur_class, $basepar, $in->getValue(), $_GET["style_type"]);
433  break;
434 
435  default:
436  $this->writeStylePar($cur_tag, $cur_class, $basepar, $_POST[$basepar], $_GET["style_type"]);
437  break;
438  }
439  }
440 
441  $this->object->update();
442  }
443 
444  function writeStylePar($cur_tag, $cur_class, $par, $value, $a_type)
445  {
446  if ($a_type == "")
447  {
448  return;
449  }
450 
451  if ($value != "")
452  {
453  $this->object->replaceStylePar($cur_tag, $cur_class, $par, $value, $a_type);
454  }
455  else
456  {
457  $this->object->deleteStylePar($cur_tag, $cur_class, $par, $a_type);
458  }
459  }
460 
466  {
467  global $tpl;
468 
469  // workaround to include default rte styles
470  //if (in_array($_GET["style_type"], array("rte_menu")))
471  if ($this->super_type == "rte")
472  {
473  $tpl->addCss("Modules/Scorm2004/templates/default/player.css");
474  include_once("./Modules/Scorm2004/classes/ilSCORM13Player.php");
475  $tpl->addInlineCss(ilSCORM13Player::getInlineCss());
476  }
477 
478  $cur = explode(".",$_GET["tag"]);
479  $cur_tag = $cur[0];
480  $cur_class = $cur[1];
481 
482  $this->initTagStyleForm("edit", $cur_tag);
483  $this->getValues();
484  $this->outputTagStyleEditScreen();
485  }
486 
491  {
492  global $tpl, $ilCtrl, $lng;
493 
494  // set style sheet
495  $tpl->setCurrentBlock("ContentStyle");
496  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
497  $this->object->getContentStylePath($this->object->getId()));
498 
499  $ts_tpl = new ilTemplate("tpl.style_tag_edit.html", true, true, "Services/Style");
500 
501  $cur = explode(".",$_GET["tag"]);
502  $cur_tag = $cur[0];
503  $cur_class = $cur[1];
504 
505  $ts_tpl->setVariable("EXAMPLE",
506  ilObjStyleSheetGUI::getStyleExampleHTML($_GET["style_type"], $cur_class));
507 
508  $ts_tpl->setVariable("FORM",
509  $this->form_gui->getHtml());
510 
511  $tpl->setTitle($cur_class." (".$lng->txt("sty_type_".$_GET["style_type"]).")");
512 
513  $tpl->setContent($ts_tpl->get());
514  }
515 
516 
522  public function initTagStyleForm($a_mode, $a_cur_tag)
523  {
524  global $lng;
525 
526  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
527  $this->form_gui = new ilPropertyFormGUI();
528 
529  $avail_pars = $this->object->getAvailableParameters();
530  $groups = $this->object->getStyleParameterGroups();
531 
532  // output select lists
533  foreach ($groups as $k => $group)
534  {
535  // filter groups of properties that should only be
536  // displayed with matching tag
537  $filtered_groups = ilObjStyleSheet::_getFilteredGroups();
538  if (is_array($filtered_groups[$k]) && !in_array($a_cur_tag, $filtered_groups[$k]))
539  {
540  continue;
541  }
542 
543  $sh = new ilFormSectionHeaderGUI();
544  $sh->setTitle($lng->txt("sty_".$k));
545  $this->form_gui->addItem($sh);
546 
547  foreach ($group as $par)
548  {
549  $basepar = explode(".", $par);
550  $basepar = $basepar[0];
551 
552  $var = str_replace("-", "_", $basepar);
553  $up_par = strtoupper($var);
554 
556  {
557  case "select":
558  $sel_input = new ilSelectInputGUI($lng->txt("sty_".$var), $basepar);
559  $options = array("" => "");
560  foreach ($avail_pars[$par] as $p)
561  {
562  $options[$p] = $p;
563  }
564  $sel_input->setOptions($options);
565  $this->form_gui->addItem($sel_input);
566  break;
567 
568  case "text":
569  $text_input = new ilTextInputGUI($lng->txt("sty_".$var), $basepar);
570  $text_input->setMaxLength(200);
571  $text_input->setSize(20);
572  $this->form_gui->addItem($text_input);
573  break;
574 
575  case "fontsize":
576  include_once("./Services/Style/classes/class.ilFontSizeInputGUI.php");
577  $fs_input = new ilFontSizeInputGUI($lng->txt("sty_".$var), $basepar);
578  $this->form_gui->addItem($fs_input);
579  break;
580 
581  case "numeric_no_perc":
582  case "numeric":
583  include_once("./Services/Style/classes/class.ilNumericStyleValueInputGUI.php");
584  $num_input = new ilNumericStyleValueInputGUI($lng->txt("sty_".$var), $basepar);
585  if (ilObjStyleSheet::_getStyleParameterInputType($par) == "numeric_no_perc")
586  {
587  $num_input->setAllowPercentage(false);
588  }
589  $this->form_gui->addItem($num_input);
590  break;
591 
592  case "percentage":
593  $per_input = new ilNumberInputGUI($lng->txt("sty_".$var), $basepar);
594  $per_input->setMinValue(0);
595  $per_input->setMaxValue(100);
596  $per_input->setMaxLength(3);
597  $per_input->setSize(3);
598  $this->form_gui->addItem($per_input);
599  break;
600 
601  case "color":
602  //include_once("./Services/Style/classes/class.ilNumericStyleValueInputGUI.php");
603  $col_input = new ilColorPickerInputGUI($lng->txt("sty_".$var), $basepar);
604  $col_input->setDefaultColor("");
605  $col_input->setAcceptNamedColors(true);
606  $this->form_gui->addItem($col_input);
607  break;
608 
609  case "trbl_numeric":
610  include_once("./Services/Style/classes/class.ilTRBLNumericStyleValueInputGUI.php");
611  $num_input = new ilTRBLNumericStyleValueInputGUI($lng->txt("sty_".$var), $basepar);
612  if (ilObjStyleSheet::_getStyleParameterInputType($par) == "trbl_numeric_no_perc")
613  {
614  $num_input->setAllowPercentage(false);
615  }
616  $this->form_gui->addItem($num_input);
617  break;
618 
619  case "border_width":
620  include_once("./Services/Style/classes/class.ilTRBLBorderWidthInputGUI.php");
621  $bw_input = new ilTRBLBorderWidthInputGUI($lng->txt("sty_".$var), $basepar);
622  $this->form_gui->addItem($bw_input);
623  break;
624 
625  case "border_style":
626  include_once("./Services/Style/classes/class.ilTRBLBorderStyleInputGUI.php");
627  $bw_input = new ilTRBLBorderStyleInputGUI($lng->txt("sty_".$var), $basepar);
628  $this->form_gui->addItem($bw_input);
629  break;
630 
631  case "trbl_color":
632  include_once("./Services/Style/classes/class.ilTRBLColorPickerInputGUI.php");
633  $col_input = new ilTRBLColorPickerInputGUI($lng->txt("sty_".$var), $basepar);
634  $col_input->setAcceptNamedColors(true);
635  $this->form_gui->addItem($col_input);
636  break;
637 
638  case "background_image":
639  include_once("./Services/Style/classes/class.ilBackgroundImageInputGUI.php");
640  $im_input = new ilBackgroundImageInputGUI($lng->txt("sty_".$var), $basepar);
641  $imgs = array();
642  foreach ($this->object->getImages() as $entry)
643  {
644  $imgs[] = $entry["entry"];
645  }
646  $im_input->setImages($imgs);
647  $this->form_gui->addItem($im_input);
648  break;
649 
650  case "background_position":
651  include_once("./Services/Style/classes/class.ilBackgroundPositionInputGUI.php");
652  $im_input = new ilBackgroundPositionInputGUI($lng->txt("sty_".$var), $basepar);
653  $this->form_gui->addItem($im_input);
654  break;
655  }
656  }
657  }
658 
659  // save and cancel commands
660  $this->form_gui->addCommandButton("updateTagStyle", $lng->txt("save_return"));
661  $this->form_gui->addCommandButton("refreshTagStyle", $lng->txt("save_refresh"));
662 
663 // $this->form_gui->setTitle($lng->txt("edit"));
664  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
665  }
666 
671  public function getValues()
672  {
673  $style = $this->object->getStyle();
674  $cur = explode(".",$_GET["tag"]);
675  $cur_tag = $cur[0];
676  $cur_class = $cur[1];
677  $cur_parameters = $this->extractParametersOfTag($cur_tag, $cur_class, $style, $_GET["style_type"]);
678 
679  $parameters = ilObjStyleSheet::_getStyleParameters();
680  foreach($parameters as $p => $v)
681  {
682  $filtered_groups = ilObjStyleSheet::_getFilteredGroups();
683  if (is_array($filtered_groups[$v["group"]]) && !in_array($cur_tag, $filtered_groups[$v["group"]]))
684  {
685  continue;
686  }
687  $p = explode(".", $p);
688  $p = $p[0];
689  $input = $this->form_gui->getItemByPostVar($p);
690  switch ($v["input"])
691  {
692  case "":
693  break;
694 
695  case "trbl_numeric":
696  case "border_width":
697  case "border_style":
698  case "trbl_color":
699  $input->setAllValue($cur_parameters[$v["subpar"][0]]);
700  $input->setTopValue($cur_parameters[$v["subpar"][1]]);
701  $input->setRightValue($cur_parameters[$v["subpar"][2]]);
702  $input->setBottomValue($cur_parameters[$v["subpar"][3]]);
703  $input->setLeftValue($cur_parameters[$v["subpar"][4]]);
704  break;
705 
706  default:
707  $input->setValue($cur_parameters[$p]);
708  break;
709  }
710  }
711  }
712 
716  function exportStyleObject()
717  {
718  $file = $this->object->export();
719 
720  ilUtil::deliverFile($file, "sty_".$this->object->getId().".zip");
721  }
722 
723  function extractParametersOfTag($a_tag, $a_class, $a_style, $a_type)
724  {
725  $parameters = array();
726  foreach($a_style as $tag)
727  {
728  foreach($tag as $par)
729  {
730  if ($par["tag"] == $a_tag && $par["class"] == $a_class
731  && $par["type"] == $a_type)
732  {
733  $parameters[$par["parameter"]] = $par["value"];
734  }
735  }
736  }
737  return $parameters;
738  }
739 
744  {
745  $this->object->addParameter($_POST["tag"], $_POST["parameter"]);
746  $this->editObject();
747  }
748 
752  function refreshObject()
753  {
754  //$class_name = "ilObjStyleSheet";
755  //require_once("classes/class.ilObjStyleSheet.php");
756  $this->object->setTitle($_POST["style_title"]);
757  $this->object->setDescription($_POST["style_description"]);
758 
759  foreach($_POST["styval"] as $id => $value)
760  {
761  $this->object->updateStyleParameter($id, $value);
762  }
763  $this->object->update();
764  $this->editObject();
765  }
766 
772  function deleteObject($a_error = false)
773  {
774  //$this->setTabs();
775 
776  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.confirm_deletion.html");
777 
778  if(!$a_error)
779  {
780  ilUtil::sendInfo($this->lng->txt("info_delete_sure"));
781  }
782 
783  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
784 
785  // BEGIN TABLE HEADER
786  $this->tpl->setCurrentBlock("table_header");
787  $this->tpl->setVariable("TEXT", $this->lng->txt("objects"));
788  $this->tpl->parseCurrentBlock();
789 
790  // END TABLE HEADER
791 
792  // BEGIN TABLE DATA
793  $counter = 0;
794 
795  $this->tpl->setCurrentBlock("table_row");
796  $this->tpl->setVariable("IMG_OBJ",ilUtil::getImagePath("icon_styf.gif"));
797  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
798  $this->tpl->setVariable("TEXT_CONTENT",ilObject::_lookupTitle($this->object->getId()));
799  $this->tpl->parseCurrentBlock();
800 
801  // END TABLE DATA
802 
803  // BEGIN OPERATION_BTN
804  $buttons = array("confirmedDelete" => $this->lng->txt("confirm"),
805  "cancelDelete" => $this->lng->txt("cancel"));
806  foreach ($buttons as $name => $value)
807  {
808  $this->tpl->setCurrentBlock("operation_btn");
809  $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
810  $this->tpl->setVariable("BTN_NAME",$name);
811  $this->tpl->setVariable("BTN_VALUE",$value);
812  $this->tpl->parseCurrentBlock();
813  }
814  }
815 
816 
821  {
822  $this->ctrl->returnToParent($this);
823  }
824 
829  {
830  global $ilias;
831 
832  $this->object->delete();
833 
834  $this->ctrl->returnToParent($this);
835  }
836 
841  {
842  if (is_array($_POST["sty_select"]))
843  {
844  foreach($_POST["sty_select"] as $id => $dummy)
845  {
846  $this->object->deleteParameter($id);
847  }
848  }
849  $this->object->read();
850  $this->object->writeCSSFile();
851  $this->editObject();
852  }
853 
857  function saveObject()
858  {
859 //echo "HH"; exit;
860  $class_name = "ilObjStyleSheet";
861  require_once("./Services/Style/classes/class.ilObjStyleSheet.php");
862  $newObj = new ilObjStyleSheet();
863  $newObj->setTitle("-");
864  $newObj->create();
865  $newObj->setTitle(ilUtil::stripSlashes($_POST["style_title"]));
866  $newObj->setDescription(ilUtil::stripSlashes($_POST["style_description"]));
867  $newObj->update();
868 
869  // assign style to style sheet folder,
870  // if parent is style sheet folder
871  if ($_GET["ref_id"] > 0)
872  {
873 
874  $fold =& ilObjectFactory::getInstanceByRefId($_GET["ref_id"]);
875  if ($fold->getType() == "stys")
876  {
877  $fold->addStyle($newObj->getId());
878  $fold->update();
879  ilObjStyleSheet::_writeStandard($newObj->getId(), "1");
880  $this->ctrl->redirectByClass("ilobjstylesettingsgui", "editContentStyles");
881  }
882  }
883 
884  return $newObj->getId();
885  }
886 
890  function copyStyleObject()
891  {
892  global $ilias;
893 
894  if ($_POST["source_style"] > 0)
895  $style_obj =& $ilias->obj_factory->getInstanceByObjId($_POST["source_style"]);
896  $new_id = $style_obj->ilClone();
897 
898  // assign style to style sheet folder,
899  // if parent is style sheet folder
900  if ($_GET["ref_id"] > 0)
901  {
902 
903  $fold =& ilObjectFactory::getInstanceByRefId($_GET["ref_id"]);
904  if ($fold->getType() == "stys")
905  {
906  $fold->addStyle($new_id);
907  $fold->update();
908  ilObjStyleSheet::_writeStandard($new_id, "1");
909  $this->ctrl->redirectByClass("ilobjstylesettingsgui", "editContentStyles");
910  }
911  }
912 
913  return $new_id;
914  }
915 
919  function importStyleObject()
920  {
921  // check file
922  $source = $_FILES["stylefile"]["tmp_name"];
923  if (($source == 'none') || (!$source))
924  {
925  $this->ilias->raiseError("No file selected!",$this->ilias->error_obj->MESSAGE);
926  }
927 
928  // check correct file type
929  $info = pathinfo($_FILES["stylefile"]["name"]);
930  if (strtolower($info["extension"]) != "zip" && strtolower($info["extension"]) != "xml")
931  {
932  $this->ilias->raiseError("File must be a zip or xml file!",$this->ilias->error_obj->MESSAGE);
933  }
934 
935  $class_name = "ilObjStyleSheet";
936  require_once("./Services/Style/classes/class.ilObjStyleSheet.php");
937  $newObj = new ilObjStyleSheet();
938  //$newObj->setTitle();
939  //$newObj->setDescription($_POST["style_description"]);
940  $newObj->import($_FILES["stylefile"]);
941  //$newObj->createFromXMLFile($_FILES["stylefile"]["tmp_name"]);
942 
943  // assign style to style sheet folder,
944  // if parent is style sheet folder
945  if ($_GET["ref_id"] > 0)
946  {
947 
948  $fold =& ilObjectFactory::getInstanceByRefId($_GET["ref_id"]);
949  if ($fold->getType() == "stys")
950  {
951  $fold->addStyle($newObj->getId());
952  $fold->update();
953  ilObjStyleSheet::_writeStandard($newObj->getId(), "1");
954  $this->ctrl->redirectByClass("ilobjstylesettingsgui", "editContentStyles");
955  }
956  }
957 
958  return $newObj->getId();
959  }
960 
964  function cancelObject()
965  {
966  global $lng;
967 
968  ilUtil::sendInfo($lng->txt("msg_cancel"), true);
969  $this->ctrl->returnToParent($this);
970  }
971 
975  function getAdminTabs(&$tabs_gui)
976  {
977  $this->getTabs($tabs_gui);
978  }
979 
983  function setTabs()
984  {
985  global $lng;
986 
987  $this->getTabs($this->tabs_gui);
988 
989  if (strtolower(get_class($this->object)) == "ilobjstylesheet")
990  {
991  $this->tpl->setVariable("HEADER", $this->object->getTitle());
992  }
993  else
994  {
995  $this->tpl->setVariable("HEADER", $lng->txt("create_stylesheet"));
996  }
997  }
998 
1004  function getTabs(&$tabs_gui)
1005  {
1006  global $lng, $ilCtrl, $ilTabs;
1007 
1008  if ($ilCtrl->getCmd() == "editTagStyle")
1009  {
1010  // back to upper context
1011  $tabs_gui->setBackTarget($lng->txt("back"),
1012  $ilCtrl->getLinkTarget($this, "edit"));
1013 
1014  $t = explode(".", $_GET["tag"]);
1015  $t2 = explode(":", $t[1]);
1016  $pc = $this->object->_getPseudoClasses($t[0]);
1017  if (is_array($pc) && count($pc) > 0)
1018  {
1019  // style classes
1020  $ilCtrl->setParameter($this, "tag", $t[0].".".$t2[0]);
1021  $tabs_gui->addTarget("sty_tag_normal",
1022  $this->ctrl->getLinkTarget($this, "editTagStyle"), array("editTagStyle", ""),
1023  get_class($this));
1024  if ($t2[1] == "")
1025  {
1026  $ilTabs->setTabActive("sty_tag_normal");
1027  }
1028 
1029  foreach ($pc as $p)
1030  {
1031  // style classes
1032  $ilCtrl->setParameter($this, "tag", $t[0].".".$t2[0].":".$p);
1033  $tabs_gui->addTarget("sty_tag_".$p,
1034  $this->ctrl->getLinkTarget($this, "editTagStyle"), array("editTagStyle", ""),
1035  get_class($this));
1036  if ($t2[1] == $p)
1037  {
1038  $ilTabs->setTabActive("sty_tag_".$p);
1039  }
1040  }
1041  $ilCtrl->setParameter($this, "tag", $_GET["tag"]);
1042  }
1043  }
1044  else
1045  {
1046  // back to upper context
1047  $tabs_gui->setBackTarget($lng->txt("back"),
1048  $this->ctrl->getLinkTarget($this, "returnToUpperContext"));
1049 
1050  // style classes
1051  $tabs_gui->addTarget("sty_style_chars",
1052  $this->ctrl->getLinkTarget($this, "edit"), array("edit", ""),
1053  get_class($this));
1054 
1055  // colors
1056  $tabs_gui->addTarget("sty_colors",
1057  $this->ctrl->getLinkTarget($this, "listColors"), "listColors",
1058  get_class($this));
1059 
1060  // images
1061  $tabs_gui->addTarget("sty_images",
1062  $this->ctrl->getLinkTarget($this, "listImages"), "listImages",
1063  get_class($this));
1064 
1065  // table templates
1066  $tabs_gui->addTarget("sty_templates",
1067  $this->ctrl->getLinkTarget($this, "listTemplates"), "listTemplates",
1068  get_class($this));
1069 
1070  // settings
1071  $tabs_gui->addTarget("settings",
1072  $this->ctrl->getLinkTarget($this, "properties"), "properties",
1073  get_class($this));
1074 
1075  // accordiontest
1076 /*
1077  $tabs_gui->addTarget("accordiontest",
1078  $this->ctrl->getLinkTarget($this, "accordiontest"), "accordiontest",
1079  get_class($this));*/
1080  }
1081 
1082  }
1083 
1089  function setSubTabs()
1090  {
1091  global $lng, $ilTabs, $ilCtrl;
1092 
1094 
1095  foreach ($types as $super_type => $types)
1096  {
1097  // text block characteristics
1098  $ilCtrl->setParameter($this, "style_type", $super_type);
1099  $ilTabs->addSubTabTarget("sty_".$super_type."_char",
1100  $this->ctrl->getLinkTarget($this, "edit"), array("edit", ""),
1101  get_class($this));
1102  }
1103 
1104  $ilCtrl->setParameter($this, "style_type", $_GET["style_type"]);
1105  }
1106 
1113  {
1114  global $lng, $ilTabs, $ilCtrl;
1115 
1117 
1118  foreach ($types as $t => $c)
1119  {
1120  $ilCtrl->setParameter($this, "temp_type", $t);
1121  $ilTabs->addSubTabTarget("sty_".$t."_templates",
1122  $this->ctrl->getLinkTarget($this, "listTemplates"), array("listTemplates", ""),
1123  get_class($this));
1124  }
1125 
1126  $ilCtrl->setParameter($this, "temp_type", $_GET["temp_type"]);
1127  }
1128 
1134  {
1135  global $ilLocator;
1136 
1137  if ($_GET["admin_mode"] == "settings") // system settings
1138  {
1139  $ilLocator->addItem($this->lng->txt("administration"),
1140  $this->ctrl->getLinkTargetByClass("iladministrationgui", "frameset"),
1141  ilFrameTargetInfo::_getFrame("MainContent"));
1142 
1143  $ilLocator->addItem(ilObject::_lookupTitle(
1144  ilObject::_lookupObjId($_GET["ref_id"])),
1145  $this->ctrl->getLinkTargetByClass("ilobjstylesettingsgui", "view"));
1146 
1147  if ($_GET["obj_id"] > 0)
1148  {
1149  $ilLocator->addItem($this->object->getTitle(),
1150  $this->ctrl->getLinkTarget($this, "edit"));
1151  }
1152  }
1153  else // repository administration
1154  {
1155  //?
1156  }
1157 
1158  }
1159 
1160  function showUpperIcon()
1161  {
1162  global $tree, $tpl, $objDefinition;
1163 
1164  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
1165  {
1166  $tpl->setUpperIcon(
1167  $this->ctrl->getLinkTargetByClass("ilobjstylesettingsgui",
1168  "editContentStyles"));
1169  }
1170  else
1171  {
1172  // ?
1173  }
1174  }
1175 
1179  function listImagesObject()
1180  {
1181  global $tpl, $ilToolbar, $ilCtrl, $lng, $rbacsystem;
1182 
1183  if ($rbacsystem->checkAccess("write", (int) $_GET["ref_id"]))
1184  {
1185  $ilToolbar->addButton($lng->txt("sty_add_image"),
1186  $ilCtrl->getLinkTarget($this, "addImage"));
1187  }
1188 
1189  include_once("./Services/Style/classes/class.ilStyleImageTableGUI.php");
1190  $table_gui = new ilStyleImageTableGUI($this, "listImages",
1191  $this->object);
1192  $tpl->setContent($table_gui->getHTML());
1193 
1194  }
1195 
1199  function addImageObject()
1200  {
1201  global $tpl;
1202 
1203  $this->initImageForm();
1204  $tpl->setContent($this->form_gui->getHTML());
1205  }
1206 
1211  {
1212  global $ilCtrl;
1213 
1214  $ilCtrl->redirect($this, "listImages");
1215  }
1216 
1221  {
1222  global $tpl, $ilCtrl;
1223 
1224  $this->initImageForm();
1225 
1226  if ($this->form_gui->checkInput())
1227  {
1228  $this->object->uploadImage($_FILES["image_file"]);
1229  $ilCtrl->redirect($this, "listImages");
1230  }
1231  else
1232  {
1233  //$this->form_gui->setImageFormValuesByPost();
1234  $tpl->setContent($this->form_gui->getHTML());
1235  }
1236 
1237  }
1238 
1242  function initImageForm()
1243  {
1244  global $lng, $ilCtrl;
1245 
1246  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1247  $this->form_gui = new ilPropertyFormGUI();
1248 
1249  $this->form_gui->setTitle($lng->txt("sty_add_image"));
1250 
1251  $file_input = new ilImageFileInputGUI($lng->txt("sty_image_file"), "image_file");
1252  $file_input->setRequired(true);
1253  $this->form_gui->addItem($file_input);
1254 
1255  $this->form_gui->addCommandButton("uploadImage", $lng->txt("upload"));
1256  $this->form_gui->addCommandButton("cancelUpload", $lng->txt("cancel"));
1257  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1258  }
1259 
1264  {
1265  global $ilCtrl;
1266 
1267  $images = $this->object->getImages();
1268 
1269  foreach ($images as $image)
1270  {
1271  if (is_array($_POST["file"]) && in_array($image["entry"], $_POST["file"]))
1272  {
1273  $this->object->deleteImage($image["entry"]);
1274  }
1275  }
1276  $ilCtrl->redirect($this, "listImages");
1277  }
1278 
1283  {
1284  global $ilCtrl, $tpl, $lng;
1285 
1286 //var_dump($_POST);
1287 
1288  if (!is_array($_POST["char"]) || count($_POST["char"]) == 0)
1289  {
1290  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
1291  $ilCtrl->redirect($this, "edit");
1292  }
1293  else
1294  {
1295  // check whether there are any core style classes included
1296  $core_styles = ilObjStyleSheet::_getCoreStyles();
1297  foreach ($_POST["char"] as $char)
1298  {
1299  if (!empty($core_styles[$char]))
1300  {
1301  $this->deleteCoreCharMessage();
1302  return;
1303  }
1304  }
1305 
1306  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1307  $cgui = new ilConfirmationGUI();
1308  $cgui->setFormAction($ilCtrl->getFormAction($this));
1309  $cgui->setHeaderText($lng->txt("sty_confirm_char_deletion"));
1310  $cgui->setCancel($lng->txt("cancel"), "cancelCharacteristicDeletion");
1311  $cgui->setConfirm($lng->txt("delete"), "deleteCharacteristic");
1312 
1313  foreach ($_POST["char"] as $char)
1314  {
1315  $char_comp = explode(".", $char);
1316  $cgui->addItem("char[]", $char, $char_comp[2]);
1317  }
1318 
1319  $tpl->setContent($cgui->getHTML());
1320  }
1321  }
1322 
1330  {
1331  global $ilCtrl, $tpl, $lng;
1332 
1333  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1334  $cgui = new ilConfirmationGUI();
1335  $cgui->setFormAction($ilCtrl->getFormAction($this));
1336 
1337 
1338  $core_styles = ilObjStyleSheet::_getCoreStyles();
1339  $cnt = 0;
1340  foreach ($_POST["char"] as $char)
1341  {
1342  if (!empty($core_styles[$char]))
1343  {
1344  $cnt++;
1345  $char_comp = explode(".", $char);
1346  $cgui->addItem("", "", $char_comp[2]);
1347  }
1348  else
1349  {
1350  $cgui->addHiddenItem("char[]", $char);
1351  }
1352  }
1353  $all_core_styles = ($cnt == count($_POST["char"]))
1354  ? true
1355  : false;
1356 
1357  if ($all_core_styles)
1358  {
1359  $cgui->setHeaderText($lng->txt("sty_all_styles_obligatory"));
1360  $cgui->setCancel($lng->txt("back"), "cancelCharacteristicDeletion");
1361  }
1362  else
1363  {
1364  $cgui->setHeaderText($lng->txt("sty_some_styles_obligatory_delete_rest"));
1365  $cgui->setCancel($lng->txt("cancel"), "cancelCharacteristicDeletion");
1366  $cgui->setConfirm($lng->txt("sty_delete_other_selected"), "deleteCharacteristicConfirmation");
1367  }
1368 
1369  $tpl->setContent($cgui->getHTML());
1370  }
1371 
1376  {
1377  global $ilCtrl, $lng;
1378 
1379  ilUtil::sendInfo($lng->txt("action_aborted"), true);
1380  $ilCtrl->redirect($this, "edit");
1381  }
1382 
1387  {
1388  global $ilCtrl;
1389 
1390  if (is_array($_POST["char"]))
1391  {
1392  foreach($_POST["char"] as $char)
1393  {
1394  $char_comp = explode(".", $char);
1395  $type = $char_comp[0];
1396  $tag = $char_comp[1];
1397  $class = $char_comp[2];
1398 
1399  $this->object->deleteCharacteristic($type, $tag, $class);
1400  }
1401  }
1402 
1403  $ilCtrl->redirect($this, "edit");
1404  }
1405 
1410  {
1411  global $tpl;
1412 
1413  $this->initCharacteristicForm("create");
1414  $tpl->setContent($this->form_gui->getHTML());
1415  }
1416 
1421  {
1422  global $ilCtrl, $tpl, $lng;
1423 
1424  $this->initCharacteristicForm("create");
1425 
1426  if ($this->form_gui->checkInput())
1427  {
1428  if ($this->object->characteristicExists($_POST["new_characteristic"], $_GET["style_type"]))
1429  {
1430  $char_input = $this->form_gui->getItemByPostVar("new_characteristic");
1431  $char_input->setAlert($lng->txt("sty_characteristic_already_exists"));
1432  }
1433  else
1434  {
1435  $this->object->addCharacteristic($_POST["type"], $_POST["new_characteristic"]);
1436  ilUtil::sendInfo($lng->txt("sty_added_characteristic"), true);
1437  $ilCtrl->setParameter($this, "tag",
1438  ilObjStyleSheet::_determineTag($_POST["type"]).".".$_POST["new_characteristic"]);
1439  $ilCtrl->setParameter($this, "style_type", $_POST["type"]);
1440  $ilCtrl->redirect($this, "editTagStyle");
1441  }
1442  }
1443  $this->form_gui->setValuesByPost();
1444  $tpl->setContent($this->form_gui->getHTML());
1445  }
1446 
1452  public function initCharacteristicForm($a_mode)
1453  {
1454  global $lng, $ilCtrl;
1455 
1456  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1457  $this->form_gui = new ilPropertyFormGUI();
1458 
1459  // title
1460  $txt_input = new ilRegExpInputGUI($lng->txt("title"), "new_characteristic");
1461  $txt_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
1462  $txt_input->setNoMatchMessage($lng->txt("sty_msg_characteristic_must_only_include")." A-Z, a-z, 1-9");
1463  $txt_input->setRequired(true);
1464  $this->form_gui->addItem($txt_input);
1465 
1466  // type
1467  $all_super_types = ilObjStyleSheet::_getStyleSuperTypes();
1468  $types = $all_super_types[$this->super_type];
1469  $exp_types = array();
1470  foreach($types as $t)
1471  {
1473  {
1474  $exp_types[$t] = $lng->txt("sty_type_".$t);
1475  }
1476  }
1477  if (count($exp_types) > 1)
1478  {
1479  $type_input = new ilSelectInputGUI($lng->txt("sty_type"), "type");
1480  $type_input->setOptions($exp_types);
1481  $type_input->setValue(key($exp_types));
1482  $this->form_gui->addItem($type_input);
1483  }
1484  else if (count($exp_types) == 1)
1485  {
1486  $hid_input = new ilHiddenInputGUI("type");
1487  $hid_input->setValue(key($exp_types));
1488  $this->form_gui->addItem($hid_input);
1489  }
1490 
1491  $this->form_gui->setTitle($lng->txt("sty_add_characteristic"));
1492  $this->form_gui->addCommandButton("saveCharacteristic", $lng->txt("save"));
1493  $this->form_gui->addCommandButton("edit", $lng->txt("cancel"));
1494  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1495  }
1496 
1500  static function getStyleExampleHTML($a_type, $a_class)
1501  {
1502  global $lng;
1503 
1504  $c = explode(":", $a_class);
1505  $a_class = $c[0];
1506 
1507  $ex_tpl = new ilTemplate("tpl.style_example.html", true, true, "Services/Style");
1508 
1509  $ex_tpl->setCurrentBlock("Example_".$a_type);
1510  $ex_tpl->setVariable("EX_CLASS", "ilc_".$a_type."_".$a_class);
1511  $ex_tpl->setVariable("EX_TEXT", "ABC abc 123");
1512  if (in_array($a_type, array("media_cont", "qimg")))
1513  {
1514  $ex_tpl->setVariable("IMG_MEDIA_DISABLED", ilUtil::getImagePath("media_disabled.gif"));
1515  }
1516  if (in_array($a_type, array("table", "table_caption")))
1517  {
1518  $ex_tpl->setVariable("TXT_CAPTION", $lng->txt("sty_caption"));
1519  }
1520  if (in_array($a_class, array("OrderListItemHorizontal", "OrderListHorizontal")))
1521  {
1522  $ex_tpl->setVariable("HOR", "Horizontal");
1523  }
1524  $ex_tpl->parseCurrentBlock();
1525 
1526  return $ex_tpl->get();
1527  }
1528 
1533  {
1534  global $ilCtrl, $lng;
1535 
1536  //var_dump($_POST);
1537 
1538  foreach ($_POST["all_chars"] as $char)
1539  {
1540  $ca = explode(".", $char);
1541  $this->object->saveHideStatus($ca[0], $ca[2],
1542  (is_array($_POST["hide"]) && in_array($char, $_POST["hide"])));
1543  }
1544 
1545  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
1546  $ilCtrl->redirect($this, "edit");
1547  }
1548 
1556  {
1557  global $ilCtrl, $lng;
1558 
1559  if (!is_array($_POST["char"]) || count($_POST["char"]) == 0)
1560  {
1561  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
1562  }
1563  else
1564  {
1565  $style_cp = implode("::", $_POST["char"]);
1566  $style_cp = $this->object->getId().":::".$_GET["style_type"].":::".$style_cp;
1567  $_SESSION["sty_copy"] = $style_cp;
1568  ilUtil::sendSuccess($lng->txt("sty_copied_please_select_target"), true);
1569  }
1570  $ilCtrl->redirect($this, "edit");
1571  }
1572 
1580  {
1581  global $tpl, $ilTabs;
1582 
1583  $ilTabs->clearTargets();
1584 
1585  include_once("./Services/Style/classes/class.ilPasteStyleCharacteristicTableGUI.php");
1586  $table = new ilPasteStyleCharacteristicTableGUI($this, "pasteCharacteristicsOverview");
1587 
1588  $tpl->setContent($table->getHTML());
1589  }
1590 
1598  {
1599  global $ilCtrl, $lng;
1600 
1601  if (is_array($_POST["title"]))
1602  {
1603  foreach ($_POST["title"] as $from_char => $to_title)
1604  {
1605  $fc = explode(".", $from_char);
1606 
1607  if ($_POST["conflict_action"][$from_char] == "overwrite" ||
1608  !$this->object->characteristicExists($to_title, $fc[0]))
1609  {
1610  $this->object->copyCharacteristic($_POST["from_style_id"],
1611  $fc[0], $fc[2], $to_title);
1612  }
1613  }
1614  ilObjStyleSheet::_writeUpToDate($this->object->getId(), false);
1615  unset($_SESSION["sty_copy"]);
1616  ilUtil::sendSuccess($lng->txt("sty_style_classes_copied"), true);
1617  }
1618 
1619  $ilCtrl->redirect($this, "edit");
1620  }
1621 
1622  //
1623  // Color management
1624  //
1625 
1629  function listColorsObject()
1630  {
1631  global $tpl, $rbacsystem, $ilToolbar, $ilCtrl;
1632 
1633  if ($rbacsystem->checkAccess("write", (int) $_GET["ref_id"]))
1634  {
1635  $ilToolbar->addButton($this->lng->txt("sty_add_color"),
1636  $ilCtrl->getLinkTarget($this, "addColor"));
1637  }
1638 
1639  include_once("./Services/Style/classes/class.ilStyleColorTableGUI.php");
1640  $table_gui = new ilStyleColorTableGUI($this, "listColors",
1641  $this->object);
1642  $tpl->setContent($table_gui->getHTML());
1643 
1644  }
1645 
1649  function addColorObject()
1650  {
1651  global $tpl;
1652 
1653  $this->initColorForm();
1654  $tpl->setContent($this->form_gui->getHTML());
1655  }
1656 
1660  function editColorObject()
1661  {
1662  global $tpl, $ilCtrl;
1663 
1664  $ilCtrl->setParameter($this, "c_name", $_GET["c_name"]);
1665  $this->initColorForm("edit");
1666  $this->getColorFormValues();
1667  $tpl->setContent($this->form_gui->getHTML());
1668  }
1669 
1670 
1674  function initColorForm($a_mode = "create")
1675  {
1676  global $lng, $ilCtrl;
1677 
1678  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1679  $this->form_gui = new ilPropertyFormGUI();
1680 
1681  $this->form_gui->setTitle($lng->txt("sty_add_color"));
1682 
1683  // name
1684  $name_input = new ilRegExpInputGUI($lng->txt("sty_color_name"), "color_name");
1685  $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
1686  $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include")." A-Z, a-z, 1-9");
1687  $name_input->setRequired(true);
1688  $name_input->setSize(15);
1689  $name_input->setMaxLength(15);
1690  $this->form_gui->addItem($name_input);
1691 
1692  // code
1693  $color_input = new ilColorPickerInputGUI($lng->txt("sty_color_code"), "color_code");
1694  $color_input->setRequired(true);
1695  $color_input->setDefaultColor("");
1696  $this->form_gui->addItem($color_input);
1697 
1698  if ($a_mode == "create")
1699  {
1700  $this->form_gui->addCommandButton("saveColor", $lng->txt("save"));
1701  $this->form_gui->addCommandButton("cancelColorSaving", $lng->txt("cancel"));
1702  }
1703  else
1704  {
1705  $this->form_gui->addCommandButton("updateColor", $lng->txt("save"));
1706  $this->form_gui->addCommandButton("cancelColorSaving", $lng->txt("cancel"));
1707  }
1708  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1709  }
1710 
1715  {
1716  if ($_GET["c_name"] != "")
1717  {
1718  $values["color_name"] = $_GET["c_name"];
1719  $values["color_code"] = $this->object->getColorCodeForName($_GET["c_name"]);
1720  $this->form_gui->setValuesByArray($values);
1721  }
1722  }
1723 
1728  {
1729  global $ilCtrl;
1730 
1731  $ilCtrl->redirect($this, "listColors");
1732  }
1733 
1737  function saveColorObject()
1738  {
1739  global $tpl, $ilCtrl, $lng;
1740 
1741  $this->initColorForm();
1742 
1743  if ($this->form_gui->checkInput())
1744  {
1745  if ($this->object->colorExists($_POST["color_name"]))
1746  {
1747  $col_input = $this->form_gui->getItemByPostVar("color_name");
1748  $col_input->setAlert($lng->txt("sty_color_already_exists"));
1749  }
1750  else
1751  {
1752  $this->object->addColor($_POST["color_name"],
1753  $_POST["color_code"]);
1754  $ilCtrl->redirect($this, "listColors");
1755  }
1756  }
1757  $this->form_gui->setValuesByPost();
1758  $tpl->setContent($this->form_gui->getHTML());
1759  }
1760 
1765  {
1766  global $tpl, $ilCtrl, $lng;
1767 
1768  $this->initColorForm("edit");
1769 
1770  if ($this->form_gui->checkInput())
1771  {
1772  if ($this->object->colorExists($_POST["color_name"]) &&
1773  $_POST["color_name"] != $_GET["c_name"])
1774  {
1775  $col_input = $this->form_gui->getItemByPostVar("color_name");
1776  $col_input->setAlert($lng->txt("sty_color_already_exists"));
1777  }
1778  else
1779  {
1780  $this->object->updateColor($_GET["c_name"], $_POST["color_name"],
1781  $_POST["color_code"]);
1782  $ilCtrl->redirect($this, "listColors");
1783  }
1784  }
1785  $ilCtrl->setParameter($this, "c_name", $_GET["c_name"]);
1786  $this->form_gui->setValuesByPost();
1787  $tpl->setContent($this->form_gui->getHTML());
1788  }
1789 
1794  {
1795  global $ilCtrl, $tpl, $lng;
1796 
1797  if (!is_array($_POST["color"]) || count($_POST["color"]) == 0)
1798  {
1799  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
1800  $ilCtrl->redirect($this, "listColors");
1801  }
1802  else
1803  {
1804  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1805  $cgui = new ilConfirmationGUI();
1806  $cgui->setFormAction($ilCtrl->getFormAction($this));
1807  $cgui->setHeaderText($lng->txt("sty_confirm_color_deletion"));
1808  $cgui->setCancel($lng->txt("cancel"), "cancelColorDeletion");
1809  $cgui->setConfirm($lng->txt("delete"), "deleteColor");
1810 
1811  foreach ($_POST["color"] as $c)
1812  {
1813  $cgui->addItem("color[]", ilUtil::prepareFormOutput($c), $c);
1814  }
1815 
1816  $tpl->setContent($cgui->getHTML());
1817  }
1818  }
1819 
1824  {
1825  global $ilCtrl;
1826 
1827  $ilCtrl->redirect($this, "listColors");
1828  }
1829 
1834  {
1835  global $ilCtrl;
1836 
1837  if (is_array($_POST["color"]))
1838  {
1839  foreach ($_POST["color"] as $c)
1840  {
1841  $this->object->removeColor($c);
1842  }
1843  }
1844 
1845  $ilCtrl->redirect($this, "listColors");
1846  }
1847 
1848  //
1849  // Templates management
1850  //
1851 
1856  {
1857  global $tpl, $ilTabs, $ilCtrl;
1858 
1859  $ctype = $_GET["temp_type"];
1860  if ($ctype == "")
1861  {
1862  $ctype = "table";
1863  $ilCtrl->setParameter($this, "temp_type", $ctype);
1864  $_GET["temp_type"] = $ctype;
1865  }
1866 
1867  $this->setTemplatesSubTabs();
1868  $ilTabs->setSubTabActive("sty_".$ctype."_templates");
1869 
1870  $this->includeCSS();
1871  include_once("./Services/Style/classes/class.ilTableTemplatesTableGUI.php");
1872  $table_gui = new ilTableTemplatesTableGUI($ctype, $this, "listTemplates",
1873  $this->object);
1874  $tpl->setContent($table_gui->getHTML());
1875 
1876  }
1877 
1882  {
1883  global $tpl;
1884 
1885  $this->initTemplateForm();
1886  $tpl->setContent($this->form_gui->getHTML());
1887  }
1888 
1893  {
1894  global $tpl, $ilCtrl;
1895 
1896  $ilCtrl->setParameter($this, "t_id", $_GET["t_id"]);
1897  $this->initTemplateForm("edit");
1898  $this->getTemplateFormValues();
1899 
1900  $this->displayTemplateEditForm();
1901  }
1902 
1906  function getTemplatePreview($a_type, $a_t_id, $a_small_mode = false)
1907  {
1908  return $this->_getTemplatePreview(
1909  $this->object, $a_type, $a_t_id, $a_small_mode);
1910  }
1911 
1915  function _getTemplatePreview($a_style, $a_type, $a_t_id, $a_small_mode = false)
1916  {
1917  global $lng, $tpl;
1918 
1919  $kr = $kc = 7;
1920  if ($a_small_mode)
1921  {
1922  $kr = 6;
1923  $kc = 5;
1924  }
1925 
1926  $ts = $a_style->getTemplate($a_t_id);
1927  $t = $ts["classes"];
1928 
1929  // preview
1930  if ($a_type == "table")
1931  {
1932  $p_content = '<PageContent><Table DataTable="y"';
1933  if ($t["row_head"] != "")
1934  {
1935  $p_content.= ' HeaderRows="1"';
1936  }
1937  if ($t["row_foot"] != "")
1938  {
1939  $p_content.= ' FooterRows="1"';
1940  }
1941  if ($t["col_head"] != "")
1942  {
1943  $p_content.= ' HeaderCols="1"';
1944  }
1945  if ($t["col_foot"] != "")
1946  {
1947  $p_content.= ' FooterCols="1"';
1948  }
1949  $p_content.= ' Template="'.$a_style->lookupTemplateName($a_t_id).'">';
1950  if (!$a_small_mode)
1951  {
1952  $p_content.= '<Caption>'.$lng->txt("sty_caption").'</Caption>';
1953  }
1954  for($i = 1; $i<=$kr; $i++)
1955  {
1956  $p_content.= '<TableRow>';
1957  for($j = 1; $j<=$kc; $j++)
1958  {
1959  if ($a_small_mode)
1960  {
1961  $cell = '&lt;div style="height:2px;"&gt;&lt;/div&gt;';
1962  }
1963  else
1964  {
1965  $cell = 'xxx';
1966  }
1967  $p_content.= '<TableData><PageContent><Paragraph Characteristic="TableContent">'.$cell.'</Paragraph></PageContent></TableData>';
1968  }
1969  $p_content.= '</TableRow>';
1970  }
1971  $p_content.= '</Table></PageContent>';
1972  }
1973 
1974  if ($a_type == "vaccordion" || $a_type == "haccordion")
1975  {
1976  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
1978 
1979  if ($a_small_mode)
1980  {
1981  $c = '&amp;nbsp;';
1982  $h = '&amp;nbsp;';
1983  }
1984  else
1985  {
1986  $c = 'xxx';
1987  $h = 'head';
1988  }
1989  if ($a_type == "vaccordion")
1990  {
1991  $p_content = '<PageContent><Tabs HorizontalAlign="Left" Type="VerticalAccordion" ';
1992  if ($a_small_mode)
1993  {
1994  $p_content.= ' ContentWidth="70"';
1995  }
1996  }
1997  else
1998  {
1999  $p_content = '<PageContent><Tabs Type="HorizontalAccordion"';
2000  if ($a_small_mode)
2001  {
2002  $p_content.= ' ContentHeight="40"';
2003  $p_content.= ' ContentWidth="70"';
2004  $c = '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;';
2005  }
2006  else
2007  {
2008  $p_content.= ' ContentHeight="40"';
2009  }
2010  }
2011  $p_content.= ' Template="'.$a_style->lookupTemplateName($a_t_id).'">';
2012  $p_content.= '<Tab><PageContent><Paragraph>'.$c.'</Paragraph></PageContent>';
2013  $p_content.= '<TabCaption>'.$h.'</TabCaption>';
2014  $p_content.= '</Tab>';
2015  $p_content.= '</Tabs></PageContent>';
2016  }
2017 //echo htmlentities($p_content);
2018  $txml = $a_style->getTemplateXML();
2019 //echo htmlentities($txml);
2020  $p_content.= $txml;
2021  include_once("./Services/COPage/classes/class.ilPCTableGUI.php");
2022  $r_content = ilPCTableGUI::_renderTable($p_content, "");
2023 
2024  return $r_content;
2025  }
2026 
2030  function initTemplateForm($a_mode = "create")
2031  {
2032  global $lng, $ilCtrl;
2033 
2034  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
2035  $this->form_gui = new ilPropertyFormGUI();
2036 
2037  if ($a_mode == "create")
2038  {
2039  $this->form_gui->setTitle($lng->txt("sty_add_template"));
2040  }
2041  else
2042  {
2043  $this->form_gui->setTitle($lng->txt("sty_edit_template"));
2044  }
2045 
2046  // name
2047  $name_input = new ilRegExpInputGUI($lng->txt("sty_template_name"), "name");
2048  $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
2049  $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include")." A-Z, a-z, 1-9");
2050  $name_input->setRequired(true);
2051  $name_input->setSize(30);
2052  $name_input->setMaxLength(30);
2053  $this->form_gui->addItem($name_input);
2054 
2055  // template style classes
2056  $scs = ilObjStyleSheet::_getTemplateClassTypes($_GET["temp_type"]);
2057  foreach ($scs as $sc => $st)
2058  {
2059  $sc_input = new ilSelectInputGUI($lng->txt("sty_".$sc."_class"), $sc."_class");
2060  $chars = $this->object->getCharacteristics($st);
2061  $options = array("" => "");
2062  foreach($chars as $char)
2063  {
2064  $options[$char] = $char;
2065  }
2066  $sc_input->setOptions($options);
2067  $this->form_gui->addItem($sc_input);
2068  }
2069 
2070  if ($a_mode == "create")
2071  {
2072  $this->form_gui->addCommandButton("saveTemplate", $lng->txt("save"));
2073  $this->form_gui->addCommandButton("cancelTemplateSaving", $lng->txt("cancel"));
2074  }
2075  else
2076  {
2077  $this->form_gui->addCommandButton("refreshTemplate", $lng->txt("save_refresh"));
2078  $this->form_gui->addCommandButton("updateTemplate", $lng->txt("save_return"));
2079  $this->form_gui->addCommandButton("cancelTemplateSaving", $lng->txt("cancel"));
2080  }
2081  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
2082  }
2083 
2088  {
2089  global $ilCtrl;
2090 
2091  $ilCtrl->redirect($this, "listTemplates");
2092  }
2093 
2094 
2099  {
2100  global $tpl, $ilCtrl, $lng;
2101 
2102  $this->initTemplateForm();
2103 
2104  if ($this->form_gui->checkInput())
2105  {
2106  if ($this->object->templateExists($_POST["name"]))
2107  {
2108  $name_input = $this->form_gui->getItemByPostVar("name");
2109  $name_input->setAlert($lng->txt("sty_table_template_already_exists"));
2110  }
2111  else
2112  {
2113  $classes = array();
2114  foreach (ilObjStyleSheet::_getTemplateClassTypes($_GET["temp_type"]) as $tct => $ct)
2115  {
2116  $classes[$tct] = $_POST[$tct."_class"];
2117  }
2118  $t_id = $this->object->addTemplate($_GET["temp_type"], $_POST["name"], $classes);
2119  $this->object->writeTemplatePreview($t_id,
2120  $this->getTemplatePreview($_GET["temp_type"], $t_id, true));
2121  $ilCtrl->redirect($this, "listTemplates");
2122  }
2123  }
2124  $this->form_gui->setValuesByPost();
2125  $tpl->setContent($this->form_gui->getHTML());
2126  }
2127 
2131  function updateTemplateObject($a_refresh = false)
2132  {
2133  global $tpl, $ilCtrl, $lng;
2134 
2135  $ilCtrl->setParameter($this, "t_id", $_GET["t_id"]);
2136  $this->initTemplateForm("edit");
2137 
2138  if ($this->form_gui->checkInput())
2139  {
2140  if ($this->object->templateExists($_POST["name"]) &&
2141  $_POST["name"] != ilObjStyleSheet::lookupTemplateName($_GET["t_id"]))
2142  {
2143  $name_input = $this->form_gui->getItemByPostVar("name");
2144  $name_input->setAlert($lng->txt("sty_template_already_exists"));
2145  }
2146  else
2147  {
2148  $classes = array();
2149  foreach (ilObjStyleSheet::_getTemplateClassTypes($_GET["temp_type"]) as $tct => $ct)
2150  {
2151  $classes[$tct] = $_POST[$tct."_class"];
2152  }
2153 
2154  $this->object->updateTemplate($_GET["t_id"],
2155  $_POST["name"], $classes);
2156  $this->object->writeTemplatePreview($_GET["t_id"],
2157  $this->getTemplatePreview($_GET["temp_type"], $_GET["t_id"], true));
2158  if(!$a_refresh)
2159  {
2160  $ilCtrl->redirect($this, "listTemplates");
2161  }
2162  }
2163  }
2164 
2165  $this->form_gui->setValuesByPost();
2166  $this->displayTemplateEditForm();
2167  }
2168 
2173  {
2174  global $tpl;
2175 
2176  $a_tpl = new ilTemplate("tpl.template_edit.html", true, true,
2177  "Services/Style");
2178  $this->includeCSS();
2179  $a_tpl->setVariable("FORM", $this->form_gui->getHTML());
2180  $a_tpl->setVariable("PREVIEW", $this->getTemplatePreview($_GET["temp_type"], $_GET["t_id"]));
2181  $tpl->setContent($a_tpl->get());
2182  }
2183 
2188  {
2189  $this->updateTemplateObject(true);
2190  }
2191 
2196  {
2197  if ($_GET["t_id"] > 0)
2198  {
2199  $t = $this->object->getTemplate($_GET["t_id"]);
2200 
2201  $values["name"] = $t["name"];
2202  $scs = ilObjStyleSheet::_getTemplateClassTypes($_GET["temp_type"]);
2203  foreach ($scs as $k => $type)
2204  {
2205  $values[$k."_class"] = $t["classes"][$k];
2206  }
2207  $this->form_gui->setValuesByArray($values);
2208  }
2209  }
2210 
2215  {
2216  global $ilCtrl, $tpl, $lng;
2217 
2218  if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0)
2219  {
2220  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
2221  $ilCtrl->redirect($this, "listTemplates");
2222  }
2223  else
2224  {
2225  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
2226  $cgui = new ilConfirmationGUI();
2227  $cgui->setFormAction($ilCtrl->getFormAction($this));
2228  $cgui->setHeaderText($lng->txt("sty_confirm_template_deletion"));
2229  $cgui->setCancel($lng->txt("cancel"), "cancelTemplateDeletion");
2230  $cgui->setConfirm($lng->txt("sty_del_template"), "deleteTemplate");
2231 
2232  foreach ($_POST["tid"] as $tid)
2233  {
2234  $classes = $this->object->getTemplateClasses($tid);
2235  $cl_str = "";
2236  $listed = array();
2237  foreach ($classes as $cl)
2238  {
2239  if ($cl != "" && !$listed[$cl])
2240  {
2241  $cl_str.= '<div>- '.
2242  $cl."</div>";
2243  $listed[$cl] = true;
2244  }
2245  }
2246  if ($cl_str != "")
2247  {
2248  $cl_str = '<div style="padding-left:30px;" class="small">'.
2249  "<div><i>".$lng->txt("sty_style_class")."</i></div>".$cl_str."</div>";
2250  }
2251  $cgui->addItem("tid[]", $tid, $this->object->lookupTemplateName($tid).$cl_str);
2252  }
2253 
2254  $cgui->addButton($lng->txt("sty_del_template_keep_classes"), "deleteTemplateKeepClasses");
2255 
2256  $tpl->setContent($cgui->getHTML());
2257  }
2258  }
2259 
2264  {
2265  global $ilCtrl;
2266 
2267  $ilCtrl->redirect($this, "listTemplates");
2268  }
2269 
2274  {
2275  global $ilCtrl;
2276 
2277  if (is_array($_POST["tid"]))
2278  {
2279  foreach ($_POST["tid"] as $tid)
2280  {
2281  $this->object->removeTemplate($tid);
2282  }
2283  }
2284 
2285  $ilCtrl->redirect($this, "listTemplates");
2286  }
2287 
2292  {
2293  global $ilCtrl;
2294 
2295  if (is_array($_POST["tid"]))
2296  {
2297  foreach ($_POST["tid"] as $tid)
2298  {
2299  $cls = $this->object->getTemplateClasses($tid);
2300  foreach ($cls as $k => $cls)
2301  {
2302  $ty = $this->object->determineTemplateStyleClassType($_GET["temp_type"], $k);
2303  $ta = ilObjStyleSheet::_determineTag($ty);
2304  $this->object->deleteCharacteristic($ty, $ta, $cls);
2305  }
2306  $this->object->removeTemplate($tid);
2307  }
2308  }
2309 
2310  $ilCtrl->redirect($this, "listTemplates");
2311  }
2312 
2317  {
2318  global $tpl;
2319 
2320  $this->initTemplateGenerationForm();
2321  $tpl->setContent($this->form_gui->getHTML());
2322  }
2323 
2328  {
2329  global $lng, $ilCtrl;
2330 
2331  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
2332  $this->form_gui = new ilPropertyFormGUI();
2333 
2334  $this->form_gui->setTitle($lng->txt("sty_generate_template"));
2335 
2336  // name
2337  $name_input = new ilRegExpInputGUI($lng->txt("sty_template_name"), "name");
2338  $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
2339  $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include")." A-Z, a-z, 1-9");
2340  $name_input->setRequired(true);
2341  $name_input->setSize(30);
2342  $name_input->setMaxLength(30);
2343  $this->form_gui->addItem($name_input);
2344 
2345  // basic layout
2346  $bl_input = new ilSelectInputGUI($lng->txt("sty_template_layout"), "layout");
2347  $options = array(
2348  "coloredZebra" => $lng->txt("sty_table_template_colored_zebra"),
2349  "bwZebra" => $lng->txt("sty_table_template_bw_zebra"),
2350  "noZebra" => $lng->txt("sty_table_template_no_zebra")
2351  );
2352  $bl_input->setOptions($options);
2353  $this->form_gui->addItem($bl_input);
2354 
2355  // top bottom padding
2356  include_once("./Services/Style/classes/class.ilNumericStyleValueInputGUI.php");
2357  $num_input = new ilNumericStyleValueInputGUI($lng->txt("sty_top_bottom_padding"), "tb_padding");
2358  $num_input->setAllowPercentage(false);
2359  $num_input->setValue("3px");
2360  $this->form_gui->addItem($num_input);
2361 
2362  // left right padding
2363  $num_input = new ilNumericStyleValueInputGUI($lng->txt("sty_left_right_padding"), "lr_padding");
2364  $num_input->setAllowPercentage(false);
2365  $num_input->setValue("10px");
2366  $this->form_gui->addItem($num_input);
2367 
2368  // base color
2369  $bc_input = new ilSelectInputGUI($lng->txt("sty_base_color"), "base_color");
2370  $cs = $this->object->getColors();
2371  $options = array();
2372  foreach ($cs as $c)
2373  {
2374  $options[$c["name"]] = $c["name"];
2375  }
2376  $bc_input->setOptions($options);
2377  $this->form_gui->addItem($bc_input);
2378 
2379  // Lightness Settings
2380  $lss = array("border" => 90, "header_text" => 70, "header_bg" => 0,
2381  "cell1_text" => -60, "cell1_bg" => 90, "cell2_text" => -60, "cell2_bg" => 75);
2382  foreach ($lss as $ls => $v)
2383  {
2384  $l_input = new ilNumberInputGUI($lng->txt("sty_lightness_".$ls), "lightness_".$ls);
2385  $l_input->setMaxValue(100);
2386  $l_input->setMinValue(-100);
2387  $l_input->setValue($v);
2388  $l_input->setSize(4);
2389  $l_input->setMaxLength(4);
2390  $this->form_gui->addItem($l_input);
2391  }
2392 
2393  $this->form_gui->addCommandButton("templateGeneration", $lng->txt("generate"));
2394  $this->form_gui->addCommandButton("cancelTemplateSaving", $lng->txt("cancel"));
2395  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
2396  }
2397 
2402  {
2403  global $tpl, $ilCtrl, $lng;
2404 
2405  $this->initTemplateGenerationForm();
2406 
2407  if ($this->form_gui->checkInput())
2408  {
2409  if ($this->object->templateExists($_POST["name"]))
2410  {
2411  $name_input = $this->form_gui->getItemByPostVar("name");
2412  $name_input->setAlert($lng->txt("sty_table_template_already_exists"));
2413  }
2414  else
2415  {
2416  // -> move to application class!
2417 
2418  // cell classes
2419  $cells = array("H" => "header", "C1" => "cell1", "C2" => "cell2");
2420  $tb_p = $this->form_gui->getItemByPostVar("tb_padding");
2421  $tb_padding = $tb_p->getValue();
2422  $lr_p = $this->form_gui->getItemByPostVar("lr_padding");
2423  $lr_padding = $lr_p->getValue();
2424  $cell_color = $_POST["base_color"];
2425 
2426  // use mid gray as cell color for bw zebra
2427  if ($_POST["layout"] == "bwZebra")
2428  {
2429  $cell_color = "MidGray";
2430  if (!$this->object->colorExists($cell_color))
2431  {
2432  $this->object->addColor($cell_color, "7F7F7F");
2433  }
2434  $this->object->updateColor($cell_color, $cell_color, "7F7F7F");
2435  }
2436 
2437  foreach ($cells as $k => $cell)
2438  {
2439  $cell_class[$k] = $_POST["name"].$k;
2440  if (!$this->object->characteristicExists($cell_class[$k], "table_cell"))
2441  {
2442  $this->object->addCharacteristic("table_cell", $cell_class[$k], true);
2443  }
2444  if ($_POST["layout"] == "bwZebra" && $k == "H")
2445  {
2446  $this->object->replaceStylePar("td", $cell_class[$k], "color",
2447  "!".$_POST["base_color"]."(".$_POST["lightness_".$cell."_text"].")", "table_cell");
2448  $this->object->replaceStylePar("td", $cell_class[$k], "background-color",
2449  "!".$_POST["base_color"]."(".$_POST["lightness_".$cell."_bg"].")", "table_cell");
2450  }
2451  else
2452  {
2453  $this->object->replaceStylePar("td", $cell_class[$k], "color",
2454  "!".$cell_color."(".$_POST["lightness_".$cell."_text"].")", "table_cell");
2455  $this->object->replaceStylePar("td", $cell_class[$k], "background-color",
2456  "!".$cell_color."(".$_POST["lightness_".$cell."_bg"].")", "table_cell");
2457  }
2458  $this->object->replaceStylePar("td", $cell_class[$k], "padding-top",
2459  $tb_padding, "table_cell");
2460  $this->object->replaceStylePar("td", $cell_class[$k], "padding-bottom",
2461  $tb_padding, "table_cell");
2462  $this->object->replaceStylePar("td", $cell_class[$k], "padding-left",
2463  $lr_padding, "table_cell");
2464  $this->object->replaceStylePar("td", $cell_class[$k], "padding-right",
2465  $lr_padding, "table_cell");
2466  $this->object->replaceStylePar("td", $cell_class[$k], "border-width",
2467  "1px", "table_cell");
2468  $this->object->replaceStylePar("td", $cell_class[$k], "border-style",
2469  "solid", "table_cell");
2470  $this->object->replaceStylePar("td", $cell_class[$k], "border-color",
2471  "!".$cell_color."(".$_POST["lightness_border"].")", "table_cell");
2472  $this->object->replaceStylePar("td", $cell_class[$k], "font-weight",
2473  "normal", "table_cell");
2474  }
2475 
2476  // table class
2477  $classes["table"] = $_POST["name"]."T";
2478  if (!$this->object->characteristicExists($classes["table"], "table"))
2479  {
2480  $this->object->addCharacteristic("table", $classes["table"], true);
2481  }
2482  $this->object->replaceStylePar("table", $classes["table"], "caption-side",
2483  "bottom", "table");
2484  $this->object->replaceStylePar("table", $classes["table"], "border-collapse",
2485  "collapse", "table");
2486  $this->object->replaceStylePar("table", $classes["table"], "margin-top",
2487  "5px", "table");
2488  $this->object->replaceStylePar("table", $classes["table"], "margin-bottom",
2489  "5px", "table");
2490  if ($_POST["layout"] == "bwZebra")
2491  {
2492  $this->object->replaceStylePar("table", $classes["table"], "border-bottom-color",
2493  "!".$_POST["base_color"], "table");
2494  $this->object->replaceStylePar("table", $classes["table"], "border-bottom-style",
2495  "solid", "table");
2496  $this->object->replaceStylePar("table", $classes["table"], "border-bottom-width",
2497  "3px", "table");
2498  $sb = array("left", "right", "top");
2499  foreach ($sb as $b)
2500  {
2501  $this->object->replaceStylePar("table", $classes["table"], "border-".$b."-width",
2502  "0px", "table");
2503  }
2504  }
2505 
2506  switch ($_POST["layout"])
2507  {
2508  case "coloredZebra":
2509  $classes["row_head"] = $cell_class["H"];
2510  $classes["odd_row"] = $cell_class["C1"];
2511  $classes["even_row"] = $cell_class["C2"];
2512  break;
2513 
2514  case "bwZebra":
2515  $classes["row_head"] = $cell_class["H"];
2516  $classes["odd_row"] = $cell_class["C1"];
2517  $classes["even_row"] = $cell_class["C2"];
2518  break;
2519 
2520  case "noZebra":
2521  $classes["row_head"] = $cell_class["H"];
2522  $classes["odd_row"] = $cell_class["C1"];
2523  $classes["even_row"] = $cell_class["C1"];
2524  $classes["col_head"] = $cell_class["C2"];
2525  break;
2526  }
2527 
2528 
2529  $t_id = $this->object->addTemplate($_GET["temp_type"],
2530  $_POST["name"], $classes);
2531  $this->object->writeTemplatePreview($t_id,
2532  $this->getTemplatePreview($_GET["temp_type"], $t_id, true));
2533  $ilCtrl->redirect($this, "listTemplates");
2534  }
2535  }
2536  $this->form_gui->setValuesByPost();
2537  $tpl->setContent($this->form_gui->getHTML());
2538  }
2539 
2541  {
2542  global $tpl;
2543 
2544  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
2545 
2546  $acc = new ilAccordionGUI();
2547  $acc->addItem("Header 1", str_repeat("bla bla bla bla bla bla", 30));
2548  $acc->addItem("Header 2", str_repeat("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xx x xx x xx", 30));
2549  $acc->setOrientation(ilAccordionGUI::HORIZONTAL);
2550 
2551  $ac2 = new ilAccordionGUI();
2552  $ac2->addItem("Header 1", str_repeat("bla bla bla bla bla bla", 30));
2553  $ac2->addItem("Header 2", $acc->getHTML());
2554  $ac2->setOrientation(ilAccordionGUI::VERTICAL);
2555 
2556  $tpl->setContent($ac2->getHTML());
2557  }
2558 
2563  {
2564  global $ilCtrl;
2565 
2566  if ($_GET["baseClass"] == "ilAdministrationGUI")
2567  {
2568  $ilCtrl->redirectByClass("ilobjstylesettingsgui", "editContentStyles");
2569  }
2570  $ilCtrl->returnToParent($this);
2571  }
2572 
2573 
2574 }
2575 ?>