ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjStyleSheet.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 
5 require_once "./classes/class.ilObject.php";
6 
16 {
17  var $style;
18 
19  public static $num_unit = array("px", "em", "ex", "%", "pt", "pc", "in", "mm", "cm");
20  public static $num_unit_no_perc = array("px", "em", "ex", "pt", "pc", "in", "mm", "cm");
21 
22  // css parameters and their attribute values, input type and group
23  public static $parameter = array(
24  "font-size" => array(
25  "values" => array("xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large", "smaller", "larger"),
26  "input" => "fontsize",
27  "group" => "text"),
28  "font-family" => array(
29  "values" => array(),
30  "input" => "text",
31  "group" => "text"),
32  "font-style" => array(
33  "values" => array("italic", "oblique", "normal"),
34  "input" => "select",
35  "group" => "text"),
36  "font-weight" => array(
37  "values" => array("bold", "normal", "bolder", "lighter"),
38  "input" => "select",
39  "group" => "text"),
40  "font-variant" => array(
41  "values" => array("small-caps", "normal"),
42  "input" => "select",
43  "group" => "text"),
44  "word-spacing" => array(
45  "values" => array(),
46  "input" => "numeric_no_perc",
47  "group" => "text"),
48  "letter-spacing" => array(
49  "values" => array(),
50  "input" => "numeric_no_perc",
51  "group" => "text"),
52  "text-decoration" => array(
53  "values" => array("underline", "overline", "line-through", "blink", "none"),
54  "input" => "select",
55  "group" => "text"),
56  "text-transform" => array(
57  "values" => array("capitalize", "uppercase", "lowercase", "none"),
58  "input" => "select",
59  "group" => "text"),
60  "color" => array(
61  "values" => array(),
62  "input" => "color",
63  "group" => "text"),
64  "text-indent" => array(
65  "values" => array(),
66  "input" => "numeric",
67  "group" => "text"),
68  "line-height" => array(
69  "values" => array(),
70  "input" => "numeric",
71  "group" => "text"),
72  "vertical-align" => array(
73  "values" => array("top", "middle", "bottom", "baseline", "sub", "super",
74  "text-top", "text-bottom"),
75  "input" => "select",
76  "group" => "text"),
77  "text-align" => array(
78  "values" => array("left", "center", "right", "justify"),
79  "input" => "select",
80  "group" => "text"),
81  "white-space" => array(
82  "values" => array("normal", "pre", "nowrap"),
83  "input" => "select",
84  "group" => "text"),
85  "margin" => array(
86  "values" => array(),
87  "input" => "trbl_numeric",
88  "subpar" => array("margin", "margin-top", "margin-right",
89  "margin-bottom", "margin-left"),
90  "group" => "margin_and_padding"),
91  "padding" => array(
92  "values" => array(),
93  "input" => "trbl_numeric",
94  "subpar" => array("padding", "padding-top", "padding-right",
95  "padding-bottom", "padding-left"),
96  "group" => "margin_and_padding"),
97  "border-width" => array(
98  "values" => array("thin", "medium", "thick"),
99  "input" => "border_width",
100  "subpar" => array("border-width", "border-top-width", "border-right-width",
101  "border-bottom-width", "border-left-width"),
102  "group" => "border"),
103  "border-color" => array(
104  "values" => array(),
105  "input" => "trbl_color",
106  "subpar" => array("border-color", "border-top-color", "border-right-color",
107  "border-bottom-color", "border-left-color"),
108  "group" => "border"),
109  "border-style" => array(
110  "values" => array("none", "hidden", "dotted", "dashed", "solid", "double",
111  "groove", "ridge", "inset", "outset"),
112  "input" => "border_style",
113  "subpar" => array("border-style", "border-top-style", "border-right-style",
114  "border-bottom-style", "border-left-style"),
115  "group" => "border"),
116 
117  "background-color" => array(
118  "values" => array(),
119  "input" => "color",
120  "group" => "background"),
121  "background-image" => array(
122  "values" => array(),
123  "input" => "background_image",
124  "group" => "background"),
125  "background-repeat" => array(
126  "values" => array("repeat", "repeat-x", "repeat-y", "no-repeat"),
127  "input" => "select",
128  "group" => "background"),
129  "background-attachment" => array(
130  "values" => array("fixed", "scroll"),
131  "input" => "select",
132  "group" => "background"),
133  "background-position" => array(
134  "values" => array("horizontal" => array("left", "center", "right"),
135  "vertical" => array("top", "center", "bottom")),
136  "input" => "background_position",
137  "group" => "background"),
138 
139  "position" => array(
140  "values" => array("absolute", "fixed", "relative", "static"),
141  "input" => "select",
142  "group" => "positioning"),
143  "top" => array(
144  "values" => array(),
145  "input" => "numeric",
146  "group" => "positioning"),
147  "bottom" => array(
148  "values" => array(),
149  "input" => "numeric",
150  "group" => "positioning"),
151  "left" => array(
152  "values" => array(),
153  "input" => "numeric",
154  "group" => "positioning"),
155  "right" => array(
156  "values" => array(),
157  "input" => "numeric",
158  "group" => "positioning"),
159  "width" => array(
160  "values" => array(),
161  "input" => "numeric",
162  "group" => "positioning"),
163  "height" => array(
164  "values" => array(),
165  "input" => "numeric",
166  "group" => "positioning"),
167  "min-height" => array(
168  "values" => array(),
169  "input" => "numeric",
170  "group" => "positioning"),
171  "float" => array(
172  "values" => array("left", "right", "none"),
173  "input" => "select",
174  "group" => "positioning"),
175  "overflow" => array(
176  "values" => array("visible", "hidden", "scroll", "auto"),
177  "input" => "select",
178  "group" => "positioning"),
179 
180  "opacity" => array(
181  "values" => array(),
182  "input" => "percentage",
183  "group" => "special"),
184  "cursor" => array(
185  "values" => array("auto", "default", "crosshair", "pointer", "move",
186  "n-resize", "ne-resize", "e-resize", "se-resize", "s-resize", "sw-resize",
187  "w-resize", "nw-resize", "text", "wait", "help"),
188  "input" => "select",
189  "group" => "special"),
190  "clear" => array(
191  "values" => array ("both","left","right","none"),
192  "input" => "select",
193  "group" => "special"),
194 
195  "list-style-type.ol" => array(
196  "values" => array ("decimal","lower-roman","upper-roman",
197  "lower-alpha", "upper-alpha", "lower-greek", "hebrew",
198  "decimal-leading-zero", "cjk-ideographic", "hiragana",
199  "katakana", "hiragana-iroha", "katakana-iroha", "none"),
200  "input" => "select",
201  "group" => "ol"),
202  "list-style-type.ul" => array(
203  "values" => array ("disc","circle","square",
204  "none"),
205  "input" => "select",
206  "group" => "ul"),
207  "list-style-image.ul" => array(
208  "values" => array(),
209  "input" => "background_image",
210  "group" => "ul"),
211  "list-style-position.ol" => array(
212  "values" => array ("inside","outside"),
213  "input" => "select",
214  "group" => "ol"),
215  "list-style-position.ul" => array(
216  "values" => array ("inside","outside"),
217  "input" => "select",
218  "group" => "ul"
219  ),
220  "border-collapse" => array(
221  "values" => array ("collapse","separate"),
222  "input" => "select",
223  "group" => "table"
224  ),
225  "caption-side" => array(
226  "values" => array ("top","bottom","left","right"),
227  "input" => "select",
228  "group" => "table"
229  )
230  );
231 
232  // filter groups of properties that should only be
233  // displayed with matching tag (group -> tags)
234  public static $filtered_groups =
235  array("ol" => array("ol"), "ul" => array("ul"),
236  "table" => array("table"), "positioning" => array("h1", "h2", "h3", "div", "img", "table"));
237 
238  // style types and their super type
239  public static $style_super_types = array(
240  "text_block" => array("text_block", "heading1", "heading2", "heading3"),
241  "text_inline" => array("text_inline"),
242  "section" => array("section"),
243  "link" => array("link"),
244  "table" => array("table", "table_cell", "table_caption"),
245  "list" => array("list_o", "list_u", "list_item"),
246  "flist" => array("flist_cont", "flist_head", "flist", "flist_li", "flist_a"),
247  "media" => array("media_cont", "media_caption"),
248  "tabs" => array("va_cntr", "va_icntr", "va_ihead", "va_icont",
249  "ha_cntr", "ha_icntr", "ha_ihead", "ha_icont"),
250  "question" => array("question", "qtitle", "qanswer", "qinput", "qlinput", "qsubmit", "qfeedr", "qfeedw"),
251  "page" => array("page_frame", "page_cont", "page_title", "page_fn",
252  "page_tnav", "page_bnav", "page_lnav", "page_rnav", "page_lnavlink", "page_rnavlink",
253  "page_lnavimage", "page_rnavimage"),
254  "glo" => array("glo_overlay", "glo_ovtitle", "glo_ovclink", "glo_ovuglink", "glo_ovuglistlink"),
255  "sco" => array("sco_title", "sco_keyw", "sco_desc", "sco_desct", "sco_obj", "sco_objt")
256  );
257 
258  // these types are expandable, i.e. the user can define new style classes
259  public static $expandable_types = array (
260  "text_block", "section", "media_cont", "table", "table_cell", "flist_li", "table_caption",
261  "list_o", "list_u",
262  "va_cntr", "va_icntr", "va_ihead", "va_icont",
263  "ha_cntr", "ha_icntr", "ha_ihead", "ha_icont"
264  );
265 
266  // these types can be hidden in the content editor
267  public static $hideable_types = array (
268  "table", "table_cell"
269  );
270 
271  // tag that are used by style types
272  public static $assigned_tags = array (
273  "text_block" => "div",
274  "heading1" => "h1",
275  "heading2" => "h2",
276  "heading3" => "h3",
277  "text_inline" => "span",
278  "section" => "div",
279  "link" => "a",
280  "table" => "table",
281  "table_cell" => "td",
282  "table_caption" => "caption",
283  "media_cont" => "table",
284  "media_caption" => "div",
285  "glo_overlay" => "div",
286  "glo_ovtitle" => "h1",
287  "glo_ovclink" => "a",
288  "glo_ovuglink" => "a",
289  "glo_ovuglistlink" => "a",
290  "sco_title" => "div",
291  "sco_keyw" => "div",
292  "sco_desc" => "div",
293  "sco_obj" => "div",
294  "sco_desct" => "div",
295  "sco_objt" => "div",
296  "list_o" => "ol",
297  "list_u" => "ul",
298  "list_item" => "li",
299  "flist_cont" => "div",
300  "flist_head" => "div",
301  "flist" => "ul",
302  "flist_li" => "li",
303  "flist_a" => "a",
304  "question" => "div",
305  "qtitle" => "div",
306  "qanswer" => "div",
307  "qinput" => "input",
308  "qlinput" => "textarea",
309  "qsubmit" => "input",
310  "qfeedr" => "div",
311  "qfeedw" => "div",
312  "page_frame" => "table",
313  "page_cont" => "table",
314  "page_fn" => "div",
315  "page_tnav" => "div",
316  "page_bnav" => "div",
317  "page_lnav" => "div",
318  "page_rnav" => "div",
319  "page_lnavlink" => "a",
320  "page_rnavlink" => "a",
321  "page_lnavimage" => "img",
322  "page_rnavimage" => "img",
323  "page_title" => "h1",
324  "va_cntr" => "div",
325  "va_icntr" => "div",
326  "va_icont" => "div",
327  "va_ihead" => "div",
328  "ha_cntr" => "div",
329  "ha_icntr" => "div",
330  "ha_icont" => "div",
331  "ha_ihead" => "div"
332  );
333 
334  // pseudo classes
335  public static $pseudo_classes =
336  array ("a" => array("hover"), "div" => array("hover"), "img" => array("hover"));
337 
338  // core styles these styles MUST exists -> see also basic_style/style.xml
339  public static $core_styles = array(
340  array("type" => "text_block", "class" => "Standard"),
341  array("type" => "text_block", "class" => "List"),
342  array("type" => "text_block", "class" => "TableContent"),
343  array("type" => "heading1", "class" => "Headline1"),
344  array("type" => "heading2", "class" => "Headline2"),
345  array("type" => "heading3", "class" => "Headline3"),
346  array("type" => "text_inline", "class" => "Comment"),
347  array("type" => "text_inline", "class" => "Emph"),
348  array("type" => "text_inline", "class" => "Quotation"),
349  array("type" => "text_inline", "class" => "Strong"),
350  array("type" => "text_inline", "class" => "Accent"),
351  array("type" => "text_inline", "class" => "Important"),
352  array("type" => "link", "class" => "IntLink"),
353  array("type" => "link", "class" => "ExtLink"),
354  array("type" => "link", "class" => "FootnoteLink"),
355  array("type" => "link", "class" => "FileLink"),
356  array("type" => "link", "class" => "GlossaryLink"),
357  array("type" => "media_cont", "class" => "MediaContainer"),
358  array("type" => "table", "class" => "StandardTable"),
359  array("type" => "media_caption", "class" => "MediaCaption"),
360  array("type" => "page_frame", "class" => "PageFrame"),
361  array("type" => "page_cont", "class" => "PageContainer"),
362  array("type" => "page_tnav", "class" => "TopNavigation"),
363  array("type" => "page_bnav", "class" => "BottomNavigation"),
364  array("type" => "page_lnav", "class" => "LeftNavigation"),
365  array("type" => "page_rnav", "class" => "RightNavigation"),
366  array("type" => "page_lnavlink", "class" => "LeftNavigationLink"),
367  array("type" => "page_rnavlink", "class" => "RightNavigationLink"),
368  array("type" => "page_lnavimage", "class" => "LeftNavigationImage"),
369  array("type" => "page_rnavimage", "class" => "RightNavigationImage"),
370  array("type" => "page_fn", "class" => "Footnote"),
371  array("type" => "page_title", "class" => "PageTitle"),
372  array("type" => "glo_overlay", "class" => "GlossaryOverlay"),
373  array("type" => "glo_ovtitle", "class" => "GlossaryOvTitle"),
374  array("type" => "glo_ovclink", "class" => "GlossaryOvCloseLink"),
375  array("type" => "glo_ovuglink", "class" => "GlossaryOvUnitGloLink"),
376  array("type" => "glo_ovuglistlink", "class" => "GlossaryOvUGListLink"),
377  array("type" => "sco_title", "class" => "Title"),
378  array("type" => "sco_desc", "class" => "Description"),
379  array("type" => "sco_desct", "class" => "DescriptionTop"),
380  array("type" => "sco_keyw", "class" => "Keywords"),
381  array("type" => "sco_obj", "class" => "Objective"),
382  array("type" => "sco_objt", "class" => "ObjectiveTop"),
383  array("type" => "list_o", "class" => "NumberedList"),
384  array("type" => "list_u", "class" => "BulletedList"),
385  array("type" => "list_item", "class" => "StandardListItem"),
386  array("type" => "question", "class" => "Standard"),
387  array("type" => "question", "class" => "SingleChoice"),
388  array("type" => "question", "class" => "MultipleChoice"),
389  array("type" => "question", "class" => "TextQuestion"),
390  array("type" => "question", "class" => "OrderingQuestion"),
391  array("type" => "question", "class" => "MatchingQuestion"),
392  array("type" => "question", "class" => "ImagemapQuestion"),
393  array("type" => "question", "class" => "ClozeTest"),
394  array("type" => "qtitle", "class" => "Title"),
395  array("type" => "qanswer", "class" => "Answer"),
396  array("type" => "qinput", "class" => "TextInput"),
397  array("type" => "qlinput", "class" => "LongTextInput"),
398  array("type" => "qsubmit", "class" => "Submit"),
399  array("type" => "qfeedr", "class" => "FeedbackRight"),
400  array("type" => "qfeedw", "class" => "FeedbackWrong"),
401  array("type" => "flist_cont", "class" => "FileListContainer"),
402  array("type" => "flist_head", "class" => "FileListHeading"),
403  array("type" => "flist", "class" => "FileList"),
404  array("type" => "flist_li", "class" => "FileListItem"),
405  array("type" => "flist_a", "class" => "FileListItemLink")
406  );
407 
408  public static $templates = array(
409  "table" => array(
410  "table" => "table",
411  "caption" => "table_caption",
412  "row_head" => "table_cell",
413  "row_foot" => "table_cell",
414  "col_head" => "table_cell",
415  "col_foot" => "table_cell",
416  "odd_row" => "table_cell",
417  "even_row" => "table_cell",
418  "odd_col" => "table_cell",
419  "even_col" => "table_cell"),
420  "vaccordion" => array(
421  "va_cntr" => "va_cntr",
422  "va_icntr" => "va_icntr",
423  "va_ihead" => "va_ihead",
424  "va_icont" => "va_icont"
425  ),
426  "haccordion" => array(
427  "ha_cntr" => "ha_cntr",
428  "ha_icntr" => "ha_icntr",
429  "ha_ihead" => "ha_ihead",
430  "ha_icont" => "ha_icont"
431  )
432  );
433 
434  // basic style xml file, image directory and dom
435  protected static $basic_style_file = "./Services/Style/basic_style/style.xml";
436  protected static $basic_style_image_dir = "./Services/Style/basic_style/images";
437  protected static $basic_style_dom;
438 
445  function ilObjStyleSheet($a_id = 0, $a_call_by_reference = false)
446  {
447  $this->type = "sty";
448  $this->style = array();
449  if($a_call_by_reference)
450  {
451  $this->ilias->raiseError("Can't instantiate style object via reference id.",$this->ilias->error_obj->FATAL);
452  }
453 
454  parent::ilObject($a_id, false);
455  }
456 
460  function setRefId()
461  {
462  $this->ilias->raiseError("Operation ilObjStyleSheet::setRefId() not allowed.",$this->ilias->error_obj->FATAL);
463  }
464 
468  function getRefId()
469  {
470  return "";
471  //$this->ilias->raiseError("Operation ilObjStyleSheet::getRefId() not allowed.",$this->ilias->error_obj->FATAL);
472  }
473 
477  function putInTree()
478  {
479  $this->ilias->raiseError("Operation ilObjStyleSheet::putInTree() not allowed.",$this->ilias->error_obj->FATAL);
480  }
481 
485  function createReference()
486  {
487  $this->ilias->raiseError("Operation ilObjStyleSheet::createReference() not allowed.",$this->ilias->error_obj->FATAL);
488  }
489 
493  function setUpToDate($a_up_to_date = true)
494  {
495  $this->up_to_date = $a_up_to_date;
496  }
497 
501  function getUpToDate()
502  {
503  return $this->up_to_date;
504  }
505 
509  function setScope($a_scope)
510  {
511  $this->scope = $a_scope;
512  }
513 
517  function getScope()
518  {
519  return $this->scope;
520  }
521 
525  function _writeUpToDate($a_id, $a_up_to_date)
526  {
527  global $ilDB;
528 
529  $q = "UPDATE style_data SET uptodate = ".
530  $ilDB->quote((int) $a_up_to_date, "integer").
531  " WHERE id = ".$ilDB->quote($a_id, "integer");
532  $ilDB->manipulate($q);
533  }
534 
538  function _lookupUpToDate($a_id)
539  {
540  global $ilDB;
541 
542  $q = "SELECT uptodate FROM style_data ".
543  " WHERE id = ".$ilDB->quote($a_id, "integer");
544  $res = $ilDB->query($q);
545  $sty = $ilDB->fetchAssoc($res);
546 
547  return (boolean) $sty["uptodate"];
548  }
549 
553  function _writeStandard($a_id, $a_std)
554  {
555  global $ilDB;
556 
557  $q = "UPDATE style_data SET standard = ".
558  $ilDB->quote((int) $a_std, "integer").
559  " WHERE id = ".$ilDB->quote($a_id, "integer");
560  $ilDB->manipulate($q);
561  }
562 
566  function _writeScope($a_id, $a_scope)
567  {
568  global $ilDB;
569 
570  $q = "UPDATE style_data SET category = ".
571  $ilDB->quote((int) $a_scope, "integer").
572  " WHERE id = ".$ilDB->quote($a_id, "integer");
573  $ilDB->manipulate($q);
574  }
575 
579  function _lookupStandard($a_id)
580  {
581  global $ilDB;
582 
583  $q = "SELECT * FROM style_data ".
584  " WHERE id = ".$ilDB->quote($a_id, "integer");
585  $res = $ilDB->query($q);
586  $sty = $ilDB->fetchAssoc($res);
587 
588  return (boolean) $sty["standard"];
589  }
590 
594  function _writeActive($a_id, $a_active)
595  {
596  global $ilDB;
597 
598  $q = "UPDATE style_data SET active = ".
599  $ilDB->quote((int) $a_active, "integer").
600  " WHERE id = ".$ilDB->quote($a_id, "integer");
601  $ilDB->manipulate($q);
602  }
603 
607  function _lookupActive($a_id)
608  {
609  global $ilDB;
610 
611  $q = "SELECT * FROM style_data ".
612  " WHERE id = ".$ilDB->quote($a_id, "integer");
613  $res = $ilDB->query($q);
614  $sty = $ilDB->fetchAssoc($res);
615 
616  return (boolean) $sty["active"];
617  }
618 
622  function _getStandardStyles($a_exclude_default_style = false,
623  $a_include_deactivated = false, $a_scope = 0)
624  {
625  global $ilDB, $ilias, $tree;
626 
627  $default_style = $ilias->getSetting("default_content_style_id");
628 
629  $and_str = "";
630  if (!$a_include_deactivated)
631  {
632  $and_str = " AND active = 1";
633  }
634 
635  $q = "SELECT * FROM style_data ".
636  " WHERE standard = 1".$and_str;
637  $res = $ilDB->query($q);
638  $styles = array();
639  while($sty = $ilDB->fetchAssoc($res))
640  {
641  if (!$a_exclude_default_style || $default_style != $sty["id"])
642  {
643  // check scope
644  if ($a_scope > 0 && $sty["category"] > 0)
645  {
646  if ($tree->isInTree($sty["category"]) &&
647  $tree->isInTree($a_scope))
648  {
649  $path = $tree->getPathId($a_scope);
650  if (!in_array($sty["category"], $path))
651  {
652  continue;
653  }
654  }
655  }
656  $styles[$sty["id"]] = ilObject::_lookupTitle($sty["id"]);
657  }
658  }
659 
660  return $styles;
661  }
662 
663 
669  {
670  global $ilAccess, $ilDB;
671 
672  $clonable_styles = array();
673 
674  $q = "SELECT * FROM style_data";
675  $style_set = $ilDB->query($q);
676  while($style_rec = $ilDB->fetchAssoc($style_set))
677  {
678  $clonable = false;
679  if ($style_rec["standard"] == 1)
680  {
681  if ($style_rec["active"] == 1)
682  {
683  $clonable = true;
684  }
685  }
686  else
687  {
688  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
689  $obj_ids = ilObjContentObject::_lookupContObjIdByStyleId($style_rec["id"]);
690  foreach($obj_ids as $id)
691  {
692  $ref = ilObject::_getAllReferences($id);
693  foreach($ref as $ref_id)
694  {
695  if ($ilAccess->checkAccess("write", "", $ref_id))
696  {
697  $clonable = true;
698  }
699  }
700  }
701  }
702  if ($clonable)
703  {
704  $clonable_styles[$style_rec["id"]] =
705  ilObject::_lookupTitle($style_rec["id"]);
706  }
707  }
708  return $clonable_styles;
709  }
710 
714  function assignMetaData(&$a_meta_data)
715  {
716  $this->meta_data =& $a_meta_data;
717  }
718 
722  static function _getBasicStyleDom()
723  {
724  global $ilBench;
725 
726  if (!is_object(self::$basic_style_dom))
727  {
728  self::$basic_style_dom = new DOMDocument();
729  self::$basic_style_dom->load(self::$basic_style_file);
730  }
731 
732  return self::$basic_style_dom;
733  }
734 
738  function &getMetaData()
739  {
740  return $this->meta_data;
741  }
742 
746  function create($a_from_style = 0, $a_import_mode = false)
747  {
748  global $ilDB;
749 
750  parent::create();
751 
752  if ($a_from_style == 0)
753  {
754  if (!$a_import_mode)
755  {
756  // copy styles from basic style
757  $this->createFromXMLFile(self::$basic_style_file, true);
758 
759  // copy images from basic style
760  $this->createImagesDirectory();
761  ilUtil::rCopy(self::$basic_style_image_dir,
762  $this->getImagesDirectory());
763  }
764  }
765  else
766  {
767  // get style parameter records
768  $def = array();
769  $q = "SELECT * FROM style_parameter WHERE style_id = ".
770  $ilDB->quote($a_from_style, "integer");
771  $par_set = $ilDB->query($q);
772  while($par_rec = $ilDB->fetchAssoc($par_set))
773  {
774  $def[] = array("tag" => $par_rec["tag"], "class" => $par_rec["class"],
775  "parameter" => $par_rec["parameter"], "value" => $par_rec["value"],
776  "type" => $par_rec["type"]);
777  }
778 
779  // get style characteristics records
780  $chars = array();
781  $q = "SELECT * FROM style_char WHERE style_id = ".
782  $ilDB->quote($a_from_style, "integer");
783  $par_set = $ilDB->query($q);
784  while($par_rec = $ilDB->fetchAssoc($par_set))
785  {
786  $chars[] = array("type" => $par_rec["type"], "characteristic" => $par_rec["characteristic"]);
787  }
788 
789  // default style settings
790  foreach ($def as $sty)
791  {
792  $id = $ilDB->nextId("style_parameter");
793  $q = "INSERT INTO style_parameter (id, style_id, tag, class, parameter, value, type) VALUES ".
794  "(".
795  $ilDB->quote($id, "integer").",".
796  $ilDB->quote($this->getId(), "integer").",".
797  $ilDB->quote($sty["tag"], "text").",".
798  $ilDB->quote($sty["class"], "text").",".
799  $ilDB->quote($sty["parameter"], "text").",".
800  $ilDB->quote($sty["value"], "text").",".
801  $ilDB->quote($sty["type"], "text").")";
802  $ilDB->manipulate($q);
803  }
804 
805  // insert style characteristics
806  foreach ($chars as $char)
807  {
808  $q = "INSERT INTO style_char (style_id, type, characteristic) VALUES ".
809  "(".$ilDB->quote($this->getId(), "integer").",".
810  $ilDB->quote($char["type"], "text").",".
811  $ilDB->quote($char["characteristic"], "text").")";
812  $ilDB->manipulate($q);
813  }
814 
815  // add style_data record
816  $q = "INSERT INTO style_data (id, uptodate, category) VALUES ".
817  "(".$ilDB->quote($this->getId(), "integer").", 0,".
818  $ilDB->quote((int) $this->getScope(), "integer").")";
819  $ilDB->manipulate($q);
820 
821  // copy images
822  $from_style = new ilObjStyleSheet($a_from_style);
823  $this->createImagesDirectory();
824  ilUtil::rCopy($from_style->getImagesDirectory(),
825  $this->getImagesDirectory());
826 
827  // copy colors
828  $colors = $from_style->getColors();
829  foreach ($colors as $c)
830  {
831  $this->addColor($c["name"], $c["code"]);
832  }
833 
834  // copy templates
836  foreach ($tcts as $tct => $v)
837  {
838  $templates = $from_style->getTemplates($tct);
839  foreach ($templates as $t)
840  {
841  $this->addTemplate($tct, $t["name"], $t["classes"]);
842  }
843  }
844 
845  }
846 
847  $this->read();
848  if (!$a_import_mode)
849  {
850  $this->writeCSSFile();
851  }
852  }
853 
857  function deleteCharacteristic($a_type, $a_tag, $a_class)
858  {
859  global $ilDB;
860 
861  // check, if characteristic is not a core style
863  if (empty($core_styles[$a_type.".".$a_tag.".".$a_class]))
864  {
865  // delete characteristic record
866  $st = $ilDB->manipulateF(
867  "DELETE FROM style_char WHERE style_id = %s AND type = %s AND characteristic = %s",
868  array("integer", "text", "text"),
869  array($this->getId(), $a_type, $a_class));
870 
871  // delete parameter records
872  $st = $ilDB->manipulateF("DELETE FROM style_parameter WHERE style_id = %s AND tag = %s AND type = %s AND class = %s",
873  array("integer", "text", "text", "text"),
874  array($this->getId(), $a_tag, $a_type, $a_class));
875  }
876 
877  $this->setUpToDate(false);
878  $this->_writeUpToDate($this->getId(), false);
879  }
880 
884  function characteristicExists($a_char, $a_style_type)
885  {
886  global $ilDB;
887 
888  $set = $ilDB->queryF(
889  "SELECT style_id FROM style_char WHERE style_id = %s AND characteristic = %s AND type = %s",
890  array("integer", "text", "text"),
891  array($this->getId(), $a_char, $a_style_type));
892  if ($rec = $ilDB->fetchAssoc($set))
893  {
894  return true;
895  }
896  return false;
897  }
898 
902  function addCharacteristic($a_type, $a_char, $a_hidden = false)
903  {
904  global $ilDB;
905 
906  // delete characteristic record
907  $ilDB->manipulateF("INSERT INTO style_char (style_id, type, characteristic, hide)".
908  " VALUES (%s,%s,%s,%s) ",
909  array("integer", "text", "text", "integer"),
910  array($this->getId(), $a_type, $a_char, $a_hidden));
911 
912  $this->setUpToDate(false);
913  $this->_writeUpToDate($this->getId(), false);
914  }
915 
922  function copyCharacteristic($a_from_style_id,
923  $a_from_type, $a_from_char, $a_to_char)
924  {
925  global $ilDB;
926 
927  if (!$this->characteristicExists($a_to_char, $a_from_type))
928  {
929  $this->addCharacteristic($a_from_type, $a_to_char);
930  }
931  $this->deleteStyleParOfChar($a_from_type, $a_to_char);
932 
933  $from_style = new ilObjStyleSheet($a_from_style_id);
934 
935  $pars = $from_style->getParametersOfClass($a_from_type, $a_from_char);
936 
937  $colors = array();
938  foreach ($pars as $p => $v)
939  {
940  if (substr($v, 0, 1) == "!")
941  {
942  $colors[] = substr($v, 1);
943  }
944  $this->replaceStylePar(ilObjStyleSheet::_determineTag($a_from_type),
945  $a_to_char, $p, $v, $a_from_type);
946  }
947 
948  // copy colors
949  foreach ($colors as $c)
950  {
951  if (!$this->colorExists($c))
952  {
953  $this->addColor($c, $from_style->getColorCodeForName($c));
954  }
955  }
956  }
957 
961  function getCharacteristics($a_type = "", $a_no_hidden = false)
962  {
963  $chars = array();
964 
965  if ($a_type == "")
966  {
967  $chars = $this->chars;
968  }
969  if (is_array($this->chars_by_type[$a_type]))
970  {
971  $chars = $this->chars_by_type[$a_type];
972  }
973 
974  if ($a_no_hidden)
975  {
976  foreach ($chars as $k => $char)
977  {
978  if ($a_type == "" && $this->hidden_chars[$char["type"].":".$char["class"]])
979  {
980  unset($chars[$k]);
981  }
982  else if ($this->hidden_chars[$a_type.":".$char])
983  {
984  unset($chars[$k]);
985  }
986  }
987  }
988 
989  return $chars;
990  }
991 
995  function setCharacteristics($a_chars)
996  {
997  $this->chars = $a_chars;
998  // $this->chars_by_type[$a_type];
999  }
1000 
1004  function saveHideStatus($a_type, $a_char, $a_hide)
1005  {
1006  global $ilDB;
1007 
1008  $ilDB->manipulate("UPDATE style_char SET ".
1009  " hide = ".$ilDB->quote((int) $a_hide, "integer").
1010  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1011  " type = ".$ilDB->quote($a_type, "text")." AND ".
1012  " characteristic = ".$ilDB->quote($a_char, "text")
1013  );
1014  }
1015 
1019  function getHideStatus($a_type, $a_char)
1020  {
1021  global $ilDB;
1022 
1023  $set = $ilDB->query("SELECT hide FROM style_char ".
1024  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1025  " type = ".$ilDB->quote($a_type, "text")." AND ".
1026  " characteristic = ".$ilDB->quote($a_char, "text")
1027  );
1028  $rec = $ilDB->fetchAssoc($set);
1029 
1030  return $rec["hide"];
1031  }
1032 
1039  function ilClone()
1040  {
1041  global $log, $lng;
1042 
1043  $new_obj = new ilObjStyleSheet();
1044  $new_obj->setTitle($this->getTitle()." (".$lng->txt("sty_acopy").")");
1045  $new_obj->setType($this->getType());
1046  $new_obj->setDescription($this->getDescription());
1047  $new_obj->create($this->getId());
1048 
1049  return $new_obj->getId();
1050  }
1051 
1055  function copyImagesToDir($a_target)
1056  {
1057  ilUtil::rCopy($this->getImagesDirectory(), $a_target);
1058  }
1059 
1067  function addParameter($a_tag, $a_par, $a_type)
1068  {
1069  global $ilDB;
1070 
1071  $avail_params = $this->getAvailableParameters();
1072  $tag = explode(".", $a_tag);
1073  $value = $avail_params[$a_par][0];
1074  $id = $ilDB->nextId("style_parameter");
1075  $q = "INSERT INTO style_parameter (id,style_id, type, tag, class, parameter, value) VALUES ".
1076  "(".
1077  $ilDB->quote($id, "integer").",".
1078  $ilDB->quote($this->getId(), "integer").",".
1079  $ilDB->quote($a_type, "text").",".
1080  $ilDB->quote($tag[0], "text").",".
1081  $ilDB->quote($tag[1], "text").",".
1082  $ilDB->quote($a_par, "text").",".
1083  $ilDB->quote($value, "text").")";
1084  $ilDB->manipulate($q);
1085  $this->read();
1086  $this->writeCSSFile();
1087  }
1088 
1094  {
1096  }
1097 
1102  static function _createImagesDirectory($a_style_id)
1103  {
1104  global $ilErr;
1105 
1106  $sty_data_dir = ilUtil::getWebspaceDir()."/sty";
1107  ilUtil::makeDir($sty_data_dir);
1108  if(!is_writable($sty_data_dir))
1109  {
1110  $ilErr->raiseError("Style data directory (".$sty_data_dir
1111  .") not writeable.", $ilErr->FATAL);
1112  }
1113 
1114  $style_dir = $sty_data_dir."/sty_".$a_style_id;
1115  ilUtil::makeDir($style_dir);
1116  if(!@is_dir($style_dir))
1117  {
1118  $ilErr->raiseError("Creation of style directory failed (".
1119  $style_dir.").",$ilErr->FATAL);
1120  }
1121 
1122  // create images subdirectory
1123  $im_dir = $style_dir."/images";
1124  ilUtil::makeDir($im_dir);
1125  if(!@is_dir($im_dir))
1126  {
1127  $ilErr->raiseError("Creation of Import Directory failed (".
1128  $im_dir.").", $ilErr->FATAL);
1129  }
1130 
1131  // create thumbnails directory
1132  $thumb_dir = $style_dir."/images/thumbnails";
1133  ilUtil::makeDir($thumb_dir);
1134  if(!@is_dir($thumb_dir))
1135  {
1136  $ilErr->raiseError("Creation of Import Directory failed (".
1137  $thumb_dir.").", $ilErr->FATAL);
1138  }
1139  }
1140 
1145  {
1147  }
1148 
1152  static function _getImagesDirectory($a_style_id)
1153  {
1154  return ilUtil::getWebspaceDir()."/sty/sty_".$a_style_id.
1155  "/images";
1156  }
1157 
1162  {
1163  return $this->getImagesDirectory().
1164  "/thumbnails";
1165  }
1166 
1170  function getImages()
1171  {
1172  $dir = $this->getImagesDirectory();
1173  $images = array();
1174  if (is_dir($dir))
1175  {
1176  $entries = ilUtil::getDir($dir);
1177  foreach($entries as $entry)
1178  {
1179  if (substr($entry["entry"],0,1) == ".")
1180  {
1181  continue;
1182  }
1183  if ($entry["type"] != "dir")
1184  {
1185  $images[] = $entry;
1186  }
1187  }
1188  }
1189 
1190  return $images;
1191  }
1192 
1196  function uploadImage($a_file)
1197  {
1198  $this->createImagesDirectory();
1199  @ilUtil::moveUploadedFile($a_file["tmp_name"], $a_file["name"],
1200  $this->getImagesDirectory()."/".$a_file["name"]);
1201  @ilUtil::resizeImage($this->getImagesDirectory()."/".$a_file["name"],
1202  $this->getThumbnailsDirectory()."/".$a_file["name"], 75, 75);
1203  }
1204 
1208  function deleteImage($a_file)
1209  {
1210  if (is_file($this->getImagesDirectory()."/".$a_file))
1211  {
1212  unlink($this->getImagesDirectory()."/".$a_file);
1213  }
1214  if (is_file($this->getThumbnailsDirectory()."/".$a_file))
1215  {
1216  unlink($this->getThumbnailsDirectory()."/".$a_file);
1217  }
1218  }
1219 
1225  function deleteParameter($a_id)
1226  {
1227  global $ilDB;
1228 
1229  $q = "DELETE FROM style_parameter WHERE id = ".
1230  $ilDB->quote($a_id, "integer");
1231  $ilDB->query($q);
1232  }
1233 
1242  function deleteStylePar($a_tag, $a_class, $a_par, $a_type)
1243  {
1244  global $ilDB;
1245 
1246  $q = "DELETE FROM style_parameter WHERE ".
1247  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1248  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1249  " class = ".$ilDB->quote($a_class, "text")." AND ".
1250  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1251  " parameter = ".$ilDB->quote($a_par, "text");
1252 
1253  $ilDB->manipulate($q);
1254  }
1255 
1264  function deleteStyleParOfChar($a_type, $a_class)
1265  {
1266  global $ilDB;
1267 
1268  $q = "DELETE FROM style_parameter WHERE ".
1269  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1270  " class = ".$ilDB->quote($a_class, "text")." AND ".
1271  " ".$ilDB->equals("type", $a_type, "text", true);
1272 
1273  $ilDB->manipulate($q);
1274  }
1275 
1276 
1280  function delete()
1281  {
1282  global $ilDB;
1283 
1284  // delete object
1285  parent::delete();
1286 
1287  // check whether this style is global default
1288  $def_style = $this->ilias->getSetting("default_content_style_id");
1289  if ($def_style == $this->getId())
1290  {
1291  $this->ilias->deleteSetting("default_content_style_id");
1292  }
1293 
1294  // check whether this style is global fixed
1295  $fixed_style = $this->ilias->getSetting("fixed_content_style_id");
1296  if ($fixed_style == $this->getId())
1297  {
1298  $this->ilias->deleteSetting("fixed_content_style_id");
1299  }
1300 
1301  // delete style parameter
1302  $q = "DELETE FROM style_parameter WHERE style_id = ".
1303  $ilDB->quote($this->getId(), "integer");
1304  $ilDB->manipulate($q);
1305 
1306  // delete style file
1307  $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
1308  if (is_file($css_file_name))
1309  {
1310  unlink($css_file_name);
1311  }
1312 
1313  // delete entries in learning modules
1314  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
1316 
1317  // delete style data record
1318  $q = "DELETE FROM style_data WHERE id = ".
1319  $ilDB->quote($this->getId(), "integer");
1320  $ilDB->manipulate($q);
1321 
1322  }
1323 
1324 
1328  function read()
1329  {
1330  global $ilDB;
1331 
1332  parent::read();
1333 
1334  $q = "SELECT * FROM style_parameter WHERE style_id = ".
1335  $ilDB->quote($this->getId(), "integer")." ORDER BY tag, class, type ";
1336  $style_set = $ilDB->query($q);
1337  $ctag = "";
1338  $cclass = "";
1339  $ctype = "";
1340  $this->style = array();
1341  while($style_rec = $ilDB->fetchAssoc($style_set))
1342  {
1343  if ($style_rec["tag"] != $ctag || $style_rec["class"] != $cclass
1344  || $style_rec["type"] != $ctype)
1345  {
1346  // add current tag array to style array
1347  if(is_array($tag))
1348  {
1349  $this->style[] = $tag;
1350  }
1351  $tag = array();
1352  }
1353  $ctag = $style_rec["tag"];
1354  $cclass = $style_rec["class"];
1355  $ctype = $style_rec["type"];
1356  $tag[] = $style_rec;
1357  $this->style_class[$ctype][$cclass][$style_rec["parameter"]] = $style_rec["value"];
1358  }
1359  if(is_array($tag))
1360  {
1361  $this->style[] = $tag;
1362  }
1363 //var_dump($this->style_class);
1364  $q = "SELECT * FROM style_data WHERE id = ".
1365  $ilDB->quote($this->getId(), "integer");
1366  $res = $ilDB->query($q);
1367  $sty = $ilDB->fetchAssoc($res);
1368  $this->setUpToDate((boolean) $sty["uptodate"]);
1369  $this->setScope($sty["category"]);
1370 
1371  // get style characteristics records
1372  $this->chars = array();
1373  $this->chars_by_type = array();
1374  $q = "SELECT * FROM style_char WHERE style_id = ".
1375  $ilDB->quote($this->getId(), "integer").
1376  " ORDER BY type ASC, characteristic ASC";
1377  $par_set = $ilDB->query($q);
1378  while($par_rec = $ilDB->fetchAssoc($par_set))
1379  {
1380  $this->chars[] = array("type" => $par_rec["type"], "class" => $par_rec["characteristic"], "hide" => $par_rec["hide"]);
1381  $this->chars_by_type[$par_rec["type"]][] = $par_rec["characteristic"];
1382  if ($par_rec["hide"])
1383  {
1384  $this->hidden_chars[$par_rec["type"].":".$par_rec["characteristic"]] = true;
1385  }
1386  }
1387  }
1388 
1392  function writeCSSFile($a_target_file = "", $a_image_dir = "")
1393  {
1394  $style = $this->getStyle();
1395 
1396  if ($a_target_file == "")
1397  {
1398  $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
1399  }
1400  else
1401  {
1402  $css_file_name = $a_target_file;
1403  }
1404  $css_file = fopen($css_file_name, "w");
1405 
1406  $page_background = "";
1407 
1408  foreach ($style as $tag)
1409  {
1410  fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]."\n");
1411  if ($tag[0]["tag"] = "td")
1412  {
1413  fwrite ($css_file, ",th".".ilc_".$tag[0]["type"]."_".$tag[0]["class"]."\n");
1414  }
1415  fwrite ($css_file, "{\n");
1416 
1417  // collect table border attributes
1418  $t_border = array();
1419 
1420  foreach($tag as $par)
1421  {
1422  $cur_par = $par["parameter"];
1423  $cur_val = $par["value"];
1424 
1425  // replace named colors
1426  if (is_int(strpos($cur_par, "color")) && substr(trim($cur_val), 0, 1) == "!")
1427  {
1428  $cur_val = $this->getColorCodeForName(substr($cur_val, 1));
1429  }
1430 
1431  if ($tag[0]["type"] == "table" && is_int(strpos($par["parameter"], "border")))
1432  {
1433  $t_border[$cur_par] = $cur_val;
1434  }
1435 
1436  if (in_array($cur_par, array("background-image", "list-style-image")))
1437  {
1438  if (is_int(strpos($cur_val, "/"))) // external
1439  {
1440  $cur_val = "url(".$cur_val.")";
1441  }
1442  else // internal
1443  {
1444  if ($a_image_dir == "")
1445  {
1446  $cur_val = "url(../sty/sty_".$this->getId()."/images/".$cur_val.")";
1447  }
1448  else
1449  {
1450  $cur_val = "url(".$a_image_dir."/".$cur_val.")";
1451  }
1452  }
1453  }
1454 
1455  if ($cur_par == "opacity")
1456  {
1457  $cur_val = ((int) $cur_val) / 100;
1458  }
1459 
1460  fwrite ($css_file, "\t".$cur_par.": ".$cur_val.";\n");
1461 
1462  // IE6 fix for minimum height
1463  if ($cur_par == "min-height")
1464  {
1465  fwrite ($css_file, "\t"."height".": "."auto !important".";\n");
1466  fwrite ($css_file, "\t"."height".": ".$cur_val.";\n");
1467  }
1468 
1469  // opacity fix
1470  if ($cur_par == "opacity")
1471  {
1472  fwrite ($css_file, "\t".'-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity='.($cur_val * 100).')"'.";\n");
1473  fwrite ($css_file, "\t".'filter: alpha(opacity='.($cur_val * 100).')'.";\n");
1474  fwrite ($css_file, "\t".'-moz-opacity: '.$cur_val.";\n");
1475  }
1476 
1477  // save page background
1478  if ($tag[0]["tag"] == "div" && $tag[0]["class"] == "Page"
1479  && $cur_par == "background-color")
1480  {
1481  $page_background = $cur_val;
1482  }
1483  }
1484  fwrite ($css_file, "}\n");
1485  fwrite ($css_file, "\n");
1486 
1487  // use table border attributes for th td as well
1488 /* if ($tag[0]["type"] == "table")
1489  {
1490  if (count($t_border) > 0)
1491  {
1492  fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]." th,".
1493  $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]." td\n");
1494  fwrite ($css_file, "{\n");
1495  foreach ($t_border as $p => $v)
1496  {
1497 // fwrite ($css_file, "\t".$p.": ".$v.";\n");
1498  }
1499  fwrite ($css_file, "}\n");
1500  fwrite ($css_file, "\n");
1501  }
1502  }*/
1503  }
1504 
1505  if ($page_background != "")
1506  {
1507  fwrite ($css_file, "td.ilc_Page\n");
1508  fwrite ($css_file, "{\n");
1509  fwrite ($css_file, "\t"."background-color: ".$page_background.";\n");
1510  fwrite ($css_file, "}\n");
1511  }
1512  fclose($css_file);
1513 
1514  $this->setUpToDate(true);
1515  $this->_writeUpToDate($this->getId(), true);
1516  }
1517 
1524  static function getEffectiveContentStyleId($a_style_id, $a_type = "")
1525  {
1526  global $ilSetting;
1527 
1528  // check global fixed content style
1529  $fixed_style = $ilSetting->get("fixed_content_style_id");
1530  if ($fixed_style > 0)
1531  {
1532  $a_style_id = $fixed_style;
1533  }
1534 
1535  // check global default style
1536  if ($a_style_id <= 0)
1537  {
1538  $a_style_id = $ilSetting->get("default_content_style_id");
1539  }
1540 
1541  if ($a_style_id > 0 && ilObject::_lookupType($a_style_id) == "sty")
1542  {
1543  return $a_style_id;
1544  }
1545 
1546  return 0;
1547  }
1548 
1555  function getParametersOfClass($a_type, $a_class)
1556  {
1557  if (is_array($this->style_class[$a_type][$a_class]))
1558  {
1559  return $this->style_class[$a_type][$a_class];
1560  }
1561  return array();
1562  }
1563 
1569  function getContentStylePath($a_style_id)
1570  {
1571  global $ilias;
1572 
1573  $rand = rand(1,999999);
1574 
1575 
1576  // check global fixed content style
1577  $fixed_style = $ilias->getSetting("fixed_content_style_id");
1578  if ($fixed_style > 0)
1579  {
1580  $a_style_id = $fixed_style;
1581  }
1582 
1583  // check global default style
1584  if ($a_style_id <= 0)
1585  {
1586  $a_style_id = $ilias->getSetting("default_content_style_id");
1587  }
1588 
1589  if ($a_style_id > 0 && ilObject::_exists($a_style_id))
1590  {
1591  // check whether file is up to date
1592  if (!ilObjStyleSheet::_lookupUpToDate($a_style_id))
1593  {
1594  $style = new ilObjStyleSheet($a_style_id);
1595  $style->writeCSSFile();
1596  }
1597 
1598  return ilUtil::getWebspaceDir("output").
1599  "/css/style_".$a_style_id.".css?dummy=$rand";
1600  }
1601  else // todo: work this out
1602  {
1603  return "./Services/COPage/css/content.css";
1604  }
1605  }
1606 
1613  {
1614  return "./Services/COPage/css/print_content.css";
1615  }
1616 
1623  {
1624  return "./Services/COPage/css/syntaxhighlight.css";
1625  }
1626 
1633  {
1634  return "./Services/COPage/css/placeholder.css";
1635  }
1636 
1637  function update()
1638  {
1639  global $ilDB;
1640 
1641  parent::update();
1642  $this->read(); // this could be done better
1643  $this->writeCSSFile();
1644 
1645  $q = "UPDATE style_data ".
1646  "SET category = ".$ilDB->quote((int) $this->getScope(), "integer").
1647  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
1648  $ilDB->manipulate($q);
1649  }
1650 
1657  function updateStyleParameter($a_id, $a_value)
1658  {
1659  global $ilDB;
1660 
1661  $q = "UPDATE style_parameter SET VALUE = ".
1662  $ilDB->quote($a_value, "text")." WHERE id = ".
1663  $ilDB->quote($a_id, "integer");
1664  $style_set = $ilDB->manipulate($q);
1665  }
1666 
1671  function replaceStylePar($a_tag, $a_class, $a_par, $a_val, $a_type)
1672  {
1673  ilObjStyleSheet::_replaceStylePar($this->getId(), $a_tag, $a_class, $a_par, $a_val, $a_type);
1674  }
1675 
1676  function _replaceStylePar($style_id, $a_tag, $a_class, $a_par, $a_val, $a_type)
1677  {
1678  global $ilDB;
1679 
1680  $q = "SELECT * FROM style_parameter WHERE ".
1681  " style_id = ".$ilDB->quote($style_id, "integer")." AND ".
1682  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1683  " class = ".$ilDB->quote($a_class, "text")." AND ".
1684  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1685  " parameter = ".$ilDB->quote($a_par, "text");
1686 
1687  $set = $ilDB->query($q);
1688 
1689  if ($rec = $set->fetchRow())
1690  {
1691  $q = "UPDATE style_parameter SET ".
1692  " value = ".$ilDB->quote($a_val, "text")." WHERE ".
1693  " style_id = ".$ilDB->quote($style_id, "integer")." AND ".
1694  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1695  " class = ".$ilDB->quote($a_class, "text")." AND ".
1696  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1697  " parameter = ".$ilDB->quote($a_par, "text");
1698 
1699  $ilDB->manipulate($q);
1700  }
1701  else
1702  {
1703  $id = $ilDB->nextId("style_parameter");
1704  $q = "INSERT INTO style_parameter (id, value, style_id, tag, class, type, parameter) VALUES ".
1705  " (".
1706  $ilDB->quote($id, "integer").",".
1707  $ilDB->quote($a_val, "text").",".
1708  " ".$ilDB->quote($this->getId(), "integer").",".
1709  " ".$ilDB->quote($a_tag, "text").",".
1710  " ".$ilDB->quote($a_class, "text").",".
1711  " ".$ilDB->quote($a_type, "text").",".
1712  " ".$ilDB->quote($a_par, "text").")";
1713 
1714  $ilDB->manipulate($q);
1715  }
1716  }
1717 
1718 
1722  function getStyle()
1723  {
1724  return $this->style;
1725  }
1726 
1730  function setStyle($a_style)
1731  {
1732  $this->style = $a_style;
1733  }
1734 
1735 
1742  function handleXmlString($a_str)
1743  {
1744  return str_replace("&", "&amp;", $a_str);
1745  }
1746 
1750  function getXML()
1751  {
1752  $xml.= "<StyleSheet>\n";
1753 
1754  // title and description
1755  $xml.= "<Title>".$this->handleXmlString($this->getTitle())."</Title>";
1756  $xml.= "<Description>".$this->handleXmlString($this->getDescription())."</Description>\n";
1757 
1758  // style classes
1759  foreach($this->chars as $char)
1760  {
1761  $xml.= "<Style Tag=\"".ilObjStyleSheet::_determineTag($char["type"]).
1762  "\" Type=\"".$char["type"]."\" Class=\"".$char["class"]."\">\n";
1763  foreach($this->style as $style)
1764  {
1765  if ($style[0]["type"] == $char["type"] && $style[0]["class"] == $char["class"])
1766  {
1767  foreach($style as $tag)
1768  {
1769  $xml.="<StyleParameter Name=\"".$tag["parameter"]."\" Value=\"".$tag["value"]."\"/>\n";
1770  }
1771  }
1772  }
1773  $xml.= "</Style>\n";
1774  }
1775 
1776  // colors
1777  foreach($this->getColors() as $color)
1778  {
1779  $xml.="<StyleColor Name=\"".$color["name"]."\" Code=\"".$color["code"]."\"/>\n";
1780  }
1781 
1782  // templates
1784  foreach ($tcts as $tct => $v)
1785  {
1786  $ts = $this->getTemplates($tct);
1787 
1788  foreach ($ts as $t)
1789  {
1790  $xml.="<StyleTemplate Type=\"".$tct."\" Name=\"".$t["name"]."\">\n";
1791  foreach ($t["classes"] as $ct => $c)
1792  {
1793  if ($c != "")
1794  {
1795  $xml.="<StyleTemplateClass ClassType=\"".$ct."\" Class=\"".$c."\"/>\n";
1796  }
1797  }
1798  $xml.="</StyleTemplate>\n";
1799  }
1800  }
1801 
1802 
1803  $xml.= "</StyleSheet>";
1804 //echo "<pre>".htmlentities($xml)."</pre>"; exit;
1805  return $xml;
1806  }
1807 
1808 
1813  {
1814  $sty_data_dir = ilUtil::getDataDir()."/sty";
1815  ilUtil::makeDir($sty_data_dir);
1816  if(!is_writable($sty_data_dir))
1817  {
1818  $this->ilias->raiseError("Style data directory (".$sty_data_dir
1819  .") not writeable.",$this->ilias->error_obj->FATAL);
1820  }
1821 
1822  $style_dir = $sty_data_dir."/sty_".$this->getId();
1823  ilUtil::makeDir($style_dir);
1824  if(!@is_dir($style_dir))
1825  {
1826  $this->ilias->raiseError("Creation of style directory failed (".
1827  $style_dir.").",$this->ilias->error_obj->FATAL);
1828  }
1829 
1830  // create export subdirectory
1831  $ex_dir = $style_dir."/export";
1832  ilUtil::makeDir($ex_dir);
1833  if(!@is_dir($ex_dir))
1834  {
1835  $this->ilias->raiseError("Creation of Import Directory failed (".
1836  $ex_dir.").",$this->ilias->error_obj->FATAL);
1837  }
1838 
1839  return $ex_dir;
1840  }
1841 
1846  {
1847  $sty_data_dir = ilUtil::getDataDir()."/sty";
1848  $style_dir = $sty_data_dir."/sty_".$this->getId();
1849  // create export subdirectory
1850  $ex_dir = $style_dir."/export";
1851 
1852  if (is_dir($ex_dir))
1853  {
1854  ilUtil::delDir($ex_dir, true);
1855  }
1856  }
1857 
1858 
1863  {
1864  $ex_dir = $this->createExportDirectory();
1865  $ex_sub_dir = $ex_dir."/".$this->getExportSubDir();
1866  ilUtil::makeDir($ex_sub_dir);
1867  if(!is_writable($ex_sub_dir))
1868  {
1869  $this->ilias->raiseError("Style data directory (".$ex_sub_dir
1870  .") not writeable.",$this->ilias->error_obj->FATAL);
1871  }
1872  $ex_sub_images_dir = $ex_sub_dir."/images";
1873  ilUtil::makeDir($ex_sub_images_dir);
1874  if(!is_writable($ex_sub_images_dir))
1875  {
1876  $this->ilias->raiseError("Style data directory (".$ex_sub_images_dir
1877  .") not writeable.",$this->ilias->error_obj->FATAL);
1878  }
1879  }
1880 
1884  function setExportSubDir($a_dir)
1885  {
1886  $this->export_sub_dir = $a_dir;
1887  }
1888 
1892  function getExportSubDir()
1893  {
1894  if ($this->export_sub_dir == "")
1895  {
1896  return "sty_".$this->getId();
1897  }
1898  else
1899  {
1900  return $this->export_sub_dir;
1901  }
1902  }
1903 
1909  function export()
1910  {
1911  $this->cleanExportDirectory();
1912  $ex_dir = $this->createExportDirectory();
1913  $this->createExportSubDirectory();
1914  $this->exportXML($ex_dir."/".$this->getExportSubDir());
1915 //echo "-".$this->getImagesDirectory()."-".$ex_dir."/".$this->getExportSubDir()."/images"."-";
1917  $ex_dir."/".$this->getExportSubDir()."/images");
1918  if (is_file($ex_dir."/".$this->getExportSubDir().".zip"))
1919  {
1920  unlink($ex_dir."/".$this->getExportSubDir().".zip");
1921  }
1922  ilUtil::zip($ex_dir."/".$this->getExportSubDir(),
1923  $ex_dir."/".$this->getExportSubDir().".zip");
1924 
1925  return $ex_dir."/".$this->getExportSubDir().".zip";
1926  }
1927 
1931  function exportXML($a_dir)
1932  {
1933  $file = $a_dir."/style.xml";
1934 
1935  // open file
1936  if (!($fp = @fopen($file,"w")))
1937  {
1938  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
1939  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
1940  }
1941 
1942  // set file permissions
1943  chmod($file, 0770);
1944 
1945  // write xml data into the file
1946  fwrite($fp, $this->getXML());
1947 
1948  // close file
1949  fclose($fp);
1950 
1951  }
1952 
1957  {
1958  $sty_data_dir = ilUtil::getDataDir()."/sty";
1959  ilUtil::makeDir($sty_data_dir);
1960  if(!is_writable($sty_data_dir))
1961  {
1962  $this->ilias->raiseError("Style data directory (".$sty_data_dir
1963  .") not writeable.",$this->ilias->error_obj->FATAL);
1964  }
1965 
1966  $style_dir = $sty_data_dir."/sty_".$this->getId();
1967  ilUtil::makeDir($style_dir);
1968  if(!@is_dir($style_dir))
1969  {
1970  $this->ilias->raiseError("Creation of style directory failed (".
1971  $style_dir.").",$this->ilias->error_obj->FATAL);
1972  }
1973 
1974  // create import subdirectory
1975  $im_dir = $style_dir."/import";
1976  ilUtil::makeDir($im_dir);
1977  if(!@is_dir($im_dir))
1978  {
1979  $this->ilias->raiseError("Creation of Import Directory failed (".
1980  $im_dir.").",$this->ilias->error_obj->FATAL);
1981  }
1982 
1983  return $im_dir;
1984  }
1985 
1989  function import($a_file)
1990  {
1991  parent::create();
1992 
1993  $im_dir = $this->createImportDirectory();
1994 
1995  // handle uploaded files
1996  if (is_array($a_file))
1997  {
1998  ilUtil::moveUploadedFile($a_file["tmp_name"],
1999  $a_file["name"], $im_dir."/".$a_file["name"]);
2000  $file_name = $a_file["name"];
2001  }
2002  else // handle not directly uploaded files
2003  {
2004  $pi = pathinfo($a_file);
2005  $file_name = $pi["basename"];
2006  copy($a_file, $im_dir."/".$file_name);
2007  }
2008  $file = pathinfo($file_name);
2009 
2010  // unzip file
2011  if (strtolower($file["extension"] == "zip"))
2012  {
2013  ilUtil::unzip($im_dir."/".$file_name);
2014  $subdir = basename($file["basename"],".".$file["extension"]);
2015  if (!is_dir($im_dir."/".$subdir))
2016  {
2017  $subdir = "style"; // check style subdir
2018  }
2019  $xml_file = $im_dir."/".$subdir."/style.xml";
2020  }
2021  else // handle xml file directly (old style)
2022  {
2023  $xml_file = $im_dir."/".$file_name;
2024  }
2025 
2026  // load information from xml file
2027 //echo "-$xml_file-";
2028  $this->createFromXMLFile($xml_file, true);
2029 
2030  // copy images
2031  $this->createImagesDirectory();
2032  if (is_dir($im_dir."/".$subdir."/images"))
2033  {
2034  ilUtil::rCopy($im_dir."/".$subdir."/images",
2035  $this->getImagesDirectory());
2036  }
2037 
2039  $this->read();
2040  $this->writeCSSFile();
2041  }
2042 
2046  function createFromXMLFile($a_file, $a_skip_parent_create = false)
2047  {
2048  global $ilDB;
2049 
2050  $this->is_3_10_skin = false;
2051 
2052  if (!$a_skip_parent_create)
2053  {
2054  parent::create();
2055  }
2056  include_once("./Services/Style/classes/class.ilStyleImportParser.php");
2057  $importParser = new ilStyleImportParser($a_file, $this);
2058  $importParser->startParsing();
2059 
2060  // store style parameter
2061  foreach ($this->style as $style)
2062  {
2063  foreach($style as $tag)
2064  {
2065  $id = $ilDB->nextId("style_parameter");
2066  $q = "INSERT INTO style_parameter (id,style_id, tag, class, parameter, type, value) VALUES ".
2067  "(".
2068  $ilDB->quote($id, "integer").",".
2069  $ilDB->quote($this->getId(), "integer").",".
2070  $ilDB->quote($tag["tag"], "text").",".
2071  $ilDB->quote($tag["class"], "text").",".
2072  $ilDB->quote($tag["parameter"], "text").",".
2073  $ilDB->quote($tag["type"], "text").",".
2074  $ilDB->quote($tag["value"], "text").")";
2075 //echo "<br>-$q";
2076  $ilDB->manipulate($q);
2077  }
2078  }
2079 
2080  // store characteristics
2081  $this->is_3_10_skin = true;
2082  if (is_array($this->chars))
2083  {
2084  foreach ($this->chars as $char)
2085  {
2086  if ($char["type"] != "")
2087  {
2088  $q = "INSERT INTO style_char (style_id, type, characteristic) VALUES ".
2089  "(".$ilDB->quote($this->getId(), "integer").",".
2090  $ilDB->quote($char["type"], "text").",".
2091  $ilDB->quote($char["class"], "text").")";
2092  $ilDB->manipulate($q);
2093  $this->is_3_10_skin = false;
2094  }
2095  }
2096  }
2097 
2098  // add style_data record
2099  $q = "INSERT INTO style_data (id, uptodate) VALUES ".
2100  "(".$ilDB->quote($this->getId(), "integer").", 0)";
2101  $ilDB->manipulate($q);
2102 
2103  $this->update();
2104  $this->read();
2105 
2106  if ($this->is_3_10_skin)
2107  {
2108  $this->do_3_10_Migration();
2109  }
2110  //$this->writeCSSFile();
2111  }
2112 
2117  {
2118  $groups = array();
2119 
2120  foreach (self::$parameter as $parameter => $props)
2121  {
2122  $groups[$props["group"]][] = $parameter;
2123  }
2124  return $groups;
2125  }
2126 
2127  static function _getStyleParameterInputType($par)
2128  {
2129  $input = self::$parameter[$par]["input"];
2130  return $input;
2131  }
2132 
2133  static function _getStyleParameterSubPar($par)
2134  {
2135  $subpar = self::$parameter[$par]["subpar"];
2136  return $subpar;
2137  }
2138 
2139  static function _getStyleParameters($a_tag = "")
2140  {
2141  if ($a_tag == "")
2142  {
2143  return self::$parameter;
2144  }
2145  $par = array();
2146  foreach (self::$parameter as $k => $v)
2147  {
2148  if (is_array(self::$filtered_groups[$v["group"]]) &&
2149  !in_array($a_tag, self::$filtered_groups[$v["group"]]))
2150  {
2151  continue;
2152  }
2153  $par[$k] = $v;
2154  }
2155  return $par;
2156  }
2157 
2158  static function _getFilteredGroups()
2159  {
2160  return self::$filtered_groups;
2161  }
2162 
2163  static function _getStyleParameterNumericUnits($a_no_percentage = false)
2164  {
2165  if ($a_no_percentage)
2166  {
2167  return self::$num_unit_no_perc;
2168  }
2169  return self::$num_unit;
2170  }
2171 
2172  static function _getStyleParameterValues($par)
2173  {
2174  return self::$parameter[$par]["values"];
2175  }
2176 
2177  /*static function _getStyleTypes()
2178  {
2179  return self::$style_types;
2180  }*/
2181 
2182  static function _getStyleSuperTypes()
2183  {
2184  return self::$style_super_types;
2185  }
2186 
2187  static function _isExpandable($a_type)
2188  {
2189  return in_array($a_type, self::$expandable_types);
2190  }
2191 
2192  static function _isHideable($a_type)
2193  {
2194  return in_array($a_type, self::$hideable_types);
2195  }
2196 
2197  static function _getStyleSuperTypeForType($a_type)
2198  {
2199  foreach (self::$style_super_types as $s => $t)
2200  {
2201  if (in_array($a_type, $t))
2202  {
2203  return $s;
2204  }
2205  if ($a_type == $s)
2206  {
2207  return $s;
2208  }
2209  }
2210  }
2211 
2215  static function _getCoreStyles()
2216  {
2217  $c_styles = array();
2218  foreach (self::$core_styles as $cstyle)
2219  {
2220  $c_styles[$cstyle["type"].".".ilObjStyleSheet::_determineTag($cstyle["type"]).".".$cstyle["class"]]
2221  = array("type" => $cstyle["type"],
2222  "tag" => ilObjStyleSheet::_determineTag($cstyle["type"]),
2223  "class" => $cstyle["class"]);
2224  }
2225  return $c_styles;
2226  }
2227 
2231  static function _getTemplateClassTypes($a_template_type = "")
2232  {
2233  if ($a_template_type == "")
2234  {
2235  return self::$templates;
2236  }
2237 
2238  return self::$templates[$a_template_type];
2239  }
2240 
2241 
2242  function _getPseudoClasses($tag)
2243  {
2244  return self::$pseudo_classes[$tag];
2245  }
2246 
2248  {
2249  return self::$templates[$t][$k];
2250  }
2251 
2252  static function _determineTag($a_type)
2253  {
2254  return self::$assigned_tags[$a_type];
2255  }
2256 
2260  static function getAvailableParameters()
2261  {
2262  $pars = array();
2263  foreach(self::$parameter as $p => $v)
2264  {
2265  $pars[$p] = $v["values"];
2266  }
2267 
2268  return $pars;
2269  }
2270 
2271 
2275  static function _addMissingStyleClassesToStyle($a_id)
2276  {
2277  $styles = array(array("id" => $a_id));
2279  }
2280 
2284  static function _addMissingStyleClassesToAllStyles($a_styles = "")
2285  {
2286  global $ilDB;
2287 
2288  if ($a_styles == "")
2289  {
2290  $styles = ilObject::_getObjectsDataForType("sty");
2291  }
2292  else
2293  {
2294  $styles = $a_styles;
2295  }
2298 
2299  // get all core image files
2300  $core_images = array();
2301  $core_dir = self::$basic_style_image_dir;
2302  if (is_dir($core_dir))
2303  {
2304  $dir = opendir($core_dir);
2305  while($file = readdir($dir))
2306  {
2307  if (substr($file, 0, 1) != "." && is_file($core_dir."/".$file))
2308  {
2309  $core_images[] = $file;
2310  }
2311  }
2312  }
2313 
2314  foreach ($styles as $style)
2315  {
2316  $id = $style["id"];
2317 
2318  foreach($core_styles as $cs)
2319  {
2320  // check, whether core style class exists
2321  $set = $ilDB->queryF("SELECT * FROM style_char WHERE style_id = %s ".
2322  "AND type = %s AND characteristic = %s",
2323  array("integer", "text", "text"),
2324  array($id, $cs["type"], $cs["class"]));
2325 
2326  // if not, add core style class
2327  if (!($rec = $ilDB->fetchAssoc($set)))
2328  {
2329  $ilDB->manipulateF(
2330  "INSERT INTO style_char (style_id, type, characteristic) ".
2331  " VALUES (%s,%s,%s) ",
2332  array("integer", "text", "text"),
2333  array($id, $cs["type"], $cs["class"]));
2334 
2335  $xpath = new DOMXPath($bdom);
2336  $par_nodes = $xpath->query("/StyleSheet/Style[@Tag = '".$cs["tag"]."' and @Type='".
2337  $cs["type"]."' and @Class='".$cs["class"]."']/StyleParameter");
2338  foreach ($par_nodes as $par_node)
2339  {
2340  // check whether style parameter exists
2341  $set = $ilDB->queryF("SELECT * FROM style_parameter WHERE style_id = %s ".
2342  "AND type = %s AND class = %s AND tag = %s AND parameter = %s",
2343  array("integer", "text", "text", "text", "text"),
2344  array($id, $cs["type"], $cs["class"],
2345  $cs["tag"], $par_node->getAttribute("Name")));
2346 
2347  // if not, create style parameter
2348  if (!($rec = $ilDB->fetchAssoc($set)))
2349  {
2350  $spid = $ilDB->nextId("style_parameter");
2351  $st = $ilDB->manipulateF("INSERT INTO style_parameter (id, style_id, type, class, tag, parameter, value) ".
2352  " VALUES (%s,%s,%s,%s,%s,%s,%s)",
2353  array("integer", "integer", "text", "text", "text", "text", "text"),
2354  array($spid, $id, $cs["type"], $cs["class"], $cs["tag"],
2355  $par_node->getAttribute("Name"), $par_node->getAttribute("Value")));
2356  }
2357  }
2358  }
2359  }
2360 
2361  // now check, whether some core image files are missing
2364  reset($core_images);
2365  foreach($core_images as $cim)
2366  {
2367  if (!is_file($imdir."/".$cim))
2368  {
2369  copy($core_dir."/".$cim, $imdir."/".$cim);
2370  }
2371  }
2372  }
2373  }
2374 
2375  //
2376  // Color management
2377  //
2378 
2383  {
2384  global $ilDB;
2385 
2386  $this->do_3_9_Migration($this->getId());
2387 
2388  //include_once("./Services/Migration/DBUpdate_1385/classes/class.ilStyleMigration.php");
2389  //ilStyleMigration::addMissingStyleCharacteristics($this->getId());
2390 
2391  $this->do_3_10_CharMigration($this->getId());
2392 
2393  // style_char: type for characteristic
2394  $st = $ilDB->prepareManip("UPDATE style_char SET type = ? WHERE characteristic = ?".
2395  " AND style_id = ? ", array("text", "text", "integer"));
2396  $ilDB->execute($st, array("media_cont", "Media", $this->getId()));
2397  $ilDB->execute($st, array("media_caption", "MediaCaption", $this->getId()));
2398  $ilDB->execute($st, array("page_fn", "Footnote", $this->getId()));
2399  $ilDB->execute($st, array("page_nav", "LMNavigation", $this->getId()));
2400  $ilDB->execute($st, array("page_title", "PageTitle", $this->getId()));
2401  $ilDB->execute($st, array("page_cont", "Page", $this->getId()));
2402 
2403  // style_parameter: type for class
2404  $st = $ilDB->prepareManip("UPDATE style_parameter SET type = ? WHERE class = ?".
2405  " AND style_id = ? ", array("text", "text", "integer"));
2406  $ilDB->execute($st, array("media_cont", "Media", $this->getId()));
2407  $ilDB->execute($st, array("media_caption", "MediaCaption", $this->getId()));
2408  $ilDB->execute($st, array("page_fn", "Footnote", $this->getId()));
2409  $ilDB->execute($st, array("page_nav", "LMNavigation", $this->getId()));
2410  $ilDB->execute($st, array("page_title", "PageTitle", $this->getId()));
2411  $ilDB->execute($st, array("table", "Page", $this->getId()));
2412 
2413  $st = $ilDB->prepareManip("UPDATE style_parameter SET tag = ? WHERE class = ?".
2414  " AND style_id = ? ", array("text", "text", "integer"));
2415  $ilDB->execute($st, array("div", "MediaCaption", $this->getId()));
2416 
2417  // style_char: characteristic for characteristic
2418  $st = $ilDB->prepareManip("UPDATE style_char SET characteristic = ? WHERE characteristic = ?".
2419  " AND style_id = ? ", array("text", "text", "integer"));
2420  $ilDB->execute($st, array("MediaContainer", "Media", $this->getId()));
2421  $ilDB->execute($st, array("PageContainer", "Page", $this->getId()));
2422 
2423  // style_parameter: class for class
2424  $st = $ilDB->prepareManip("UPDATE style_parameter SET class = ? WHERE class = ?".
2425  " AND style_id = ? ", array("text", "text", "integer"));
2426  $ilDB->execute($st, array("MediaContainer", "Media", $this->getId()));
2427  $ilDB->execute($st, array("PageContainer", "Page", $this->getId()));
2428 
2429  // force rewriting of container style
2430  $st = $ilDB->prepareManip("DELETE FROM style_char WHERE type = ?".
2431  " AND style_id = ? ", array("text", "integer"));
2432  $ilDB->execute($st, array("page_cont", $this->getId()));
2433  $st = $ilDB->prepareManip("DELETE FROM style_parameter WHERE type = ?".
2434  " AND style_id = ? ", array("text", "integer"));
2435  $ilDB->execute($st, array("page_cont", $this->getId()));
2436 
2437  }
2438 
2445  function do_3_10_CharMigration($a_id = "")
2446  {
2447  global $ilDB;
2448 
2449  $add_str = "";
2450  if ($a_id != "")
2451  {
2452  $add_str = " AND style_id = ".$ilDB->quote($a_id, "integer");
2453  }
2454 
2455  $set = $ilDB->query($q = "SELECT DISTINCT style_id, tag, class FROM style_parameter WHERE ".
2456  $ilDB->equals("type", "", "text", true)." ".$add_str);
2457 
2458  while ($rec = $ilDB->fetchAssoc($set))
2459  {
2460  // derive types from tag
2461  $types = array();
2462  switch ($rec["tag"])
2463  {
2464  case "div":
2465  case "p":
2466  if (in_array($rec["class"], array("Headline3", "Headline1",
2467  "Headline2", "TableContent", "List", "Standard", "Remark",
2468  "Additional", "Mnemonic", "Citation", "Example")))
2469  {
2470  $types[] = "text_block";
2471  }
2472  if (in_array($rec["class"], array("Block", "Remark",
2473  "Additional", "Mnemonic", "Example", "Excursus", "Special")))
2474  {
2475  $types[] = "section";
2476  }
2477  if (in_array($rec["class"], array("Page", "Footnote", "PageTitle", "LMNavigation")))
2478  {
2479  $types[] = "page";
2480  }
2481  break;
2482 
2483  case "td":
2484  $types[] = "table_cell";
2485  break;
2486 
2487  case "a":
2488  if (in_array($rec["class"], array("ExtLink", "IntLink", "FootnoteLink")))
2489  {
2490  $types[] = "link";
2491  }
2492  break;
2493 
2494  case "span":
2495  $types[] = "text_inline";
2496  break;
2497 
2498  case "table":
2499  $types[] = "table";
2500  break;
2501  }
2502 
2503  // check if style_char set exists
2504  foreach ($types as $t)
2505  {
2506  // check if second type already exists
2507  $set4 = $ilDB->queryF("SELECT * FROM style_char ".
2508  " WHERE style_id = %s AND type = %s AND characteristic = %s",
2509  array("integer", "text", "text"),
2510  array($rec["style_id"], $t, $rec["class"]));
2511  if ($rec4 = $ilDB->fetchAssoc($set4))
2512  {
2513  // ok
2514  }
2515  else
2516  {
2517 //echo "<br>1-".$rec["style_id"]."-".$t."-".$rec["class"]."-";
2518  $ilDB->manipulateF("INSERT INTO style_char ".
2519  " (style_id, type, characteristic) VALUES ".
2520  " (%s,%s,%s) ",
2521  array("integer", "text", "text"),
2522  array($rec["style_id"], $t, $rec["class"]));
2523  }
2524  }
2525 
2526  // update types
2527  if ($rec["type"] == "")
2528  {
2529  if (count($types) > 0)
2530  {
2531  $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
2532  " WHERE style_id = %s AND class = %s AND ".$ilDB->equals("type", "", "text", true),
2533  array("text", "integer", "text"),
2534  array($types[0], $rec["style_id"], $rec["class"]));
2535 //echo "<br>3-".$types[0]."-".$rec["style_id"]."-".$rec["class"]."-";
2536 
2537  // links extra handling
2538  if ($types[0] == "link")
2539  {
2540  $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
2541  " WHERE style_id = %s AND (class = %s OR class = %s) AND ".$ilDB->equals("type", "", "text", true),
2542  array("text", "integer", "text", "text"),
2543  array($types[0], $rec["style_id"], $rec["class"].":visited",
2544  $rec["class"].":hover"));
2545  }
2546  }
2547 
2548  if (count($types) == 2)
2549  {
2550  // select all records of first type and add second type
2551  // records if necessary.
2552  $set2 = $ilDB->queryF("SELECT * FROM style_parameter ".
2553  " WHERE style_id = %s AND class = %s AND type = %s",
2554  array("integer", "text", "text"),
2555  array($rec["style_id"], $rec["class"], $types[0]));
2556  while ($rec2 = $ilDB->fetchAssoc($set2))
2557  {
2558  // check if second type already exists
2559  $set3 = $ilDB->queryF("SELECT * FROM style_parameter ".
2560  " WHERE style_id = %s AND tag = %s AND class = %s AND type = %s AND parameter = %s",
2561  array("integer", "text", "text", "text", "text"),
2562  array($rec["style_id"], $rec["tag"], $rec["class"], $types[1], $rec["parameter"]));
2563  if ($rec3 = $ilDB->fetchAssoc($set3))
2564  {
2565  // ok
2566  }
2567  else
2568  {
2569  $nid = $ilDB->nextId("style_parameter");
2570  $ilDB->manipulateF("INSERT INTO style_parameter ".
2571  " (id, style_id, tag, class, parameter, value, type) VALUES ".
2572  " (%s, %s,%s,%s,%s,%s,%s) ",
2573  array("integer", "integer", "text", "text", "text", "text", "text"),
2574  array($nid, $rec2["style_id"], $rec2["tag"], $rec2["class"],
2575  $rec2["parameter"], $rec2["value"], $types[1]));
2576  }
2577  }
2578  }
2579  }
2580  }
2581  }
2582 
2586  function do_3_9_Migration($a_id)
2587  {
2588  global $ilDB;
2589 
2590  $classes = array("Example", "Additional", "Citation", "Mnemonic", "Remark");
2591  $pars = array("margin-top", "margin-bottom");
2592 
2593  foreach ($classes as $curr_class)
2594  {
2595  foreach ($pars as $curr_par)
2596  {
2597  $res2 = $ilDB->queryF("SELECT id FROM style_parameter WHERE style_id = %s".
2598  " AND tag = %s AND class= %s AND parameter = %s",
2599  array("integer", "text", "text", "text"),
2600  array($a_id, "p", $curr_class, $curr_par));
2601  if ($row2 = $ilDB->fetchAssoc($res2))
2602  {
2603  $ilDB->manipulateF("UPDATE style_parameter SET value= %s WHERE id = %s",
2604  array("text", "integer"),
2605  array("10px", $row2["id"]));
2606  }
2607  else
2608  {
2609  $nid = $ilDB->nextId("style_parameter");
2610  $ilDB->manipulateF("INSERT INTO style_parameter ".
2611  "(id, style_id, tag, class, parameter,value) VALUES (%s,%s,%s,%s,%s,%s)",
2612  array("integer", "integer", "text", "text", "text", "text"),
2613  array($nid, $a_id, "div", $curr_class, $curr_par, "10px"));
2614  }
2615  }
2616  }
2617 
2618  $ilDB->manipulateF("UPDATE style_parameter SET tag = %s WHERE tag = %s and style_id = %s",
2619  array("text", "text", "integer"),
2620  array("div", "p", $a_id));
2621 
2622  }
2623 
2624 
2628  function getColors()
2629  {
2630  global $ilDB;
2631 
2632  $set = $ilDB->query("SELECT * FROM style_color WHERE ".
2633  "style_id = ".$ilDB->quote($this->getId(), "integer")." ".
2634  "ORDER BY color_name");
2635 
2636  $colors = array();
2637  while ($rec = $ilDB->fetchAssoc($set))
2638  {
2639  $colors[] = array(
2640  "name" => $rec["color_name"],
2641  "code" => $rec["color_code"]
2642  );
2643  }
2644 
2645  return $colors;
2646  }
2647 
2651  function addColor($a_name, $a_code)
2652  {
2653  global $ilDB;
2654 
2655  $ilDB->manipulate("INSERT INTO style_color (style_id, color_name, color_code)".
2656  " VALUES (".
2657  $ilDB->quote($this->getId(), "integer").",".
2658  $ilDB->quote($a_name, "text").",".
2659  $ilDB->quote($a_code, "text").
2660  ")");
2661  }
2662 
2666  function updateColor($a_name, $a_new_name, $a_code)
2667  {
2668  global $ilDB;
2669 
2670  // todo: update names in parameters as well
2671 
2672  $ilDB->manipulate("UPDATE style_color SET ".
2673  "color_name = ".$ilDB->quote($a_new_name, "text").", ".
2674  "color_code = ".$ilDB->quote($a_code, "text").
2675  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
2676  " AND color_name = ".$ilDB->quote($a_name, "text"));
2677  ilObjStyleSheet::_writeUpToDate($this->getId(), false);
2678 
2679  // rename also the name in the style parameter values
2680  if ($a_name != $a_new_name)
2681  {
2682  $set = $ilDB->query("SELECT * FROM style_parameter ".
2683  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
2684  " AND (".
2685  " parameter = ".$ilDB->quote("background-color", "text"). " OR ".
2686  " parameter = ".$ilDB->quote("color", "text"). " OR ".
2687  " parameter = ".$ilDB->quote("border-color", "text"). " OR ".
2688  " parameter = ".$ilDB->quote("border-top-color", "text"). " OR ".
2689  " parameter = ".$ilDB->quote("border-bottom-color", "text"). " OR ".
2690  " parameter = ".$ilDB->quote("border-left-color", "text"). " OR ".
2691  " parameter = ".$ilDB->quote("border-right-color", "text").
2692  ")");
2693  while ($rec = $ilDB->fetchAssoc($set))
2694  {
2695  if ($rec["value"] == "!".$a_name ||
2696  is_int(strpos($rec["value"], "!".$a_name."(")))
2697  {
2698  // parameter is based on color -> rename it
2699  $this->replaceStylePar($rec["tag"], $rec["class"],
2700  $rec["parameter"], str_replace($a_name, $a_new_name, $rec["value"]), $rec["type"]);
2701  }
2702  }
2703  }
2704  }
2705 
2709  function removeColor($a_name)
2710  {
2711  global $ilDB;
2712 
2713  $ilDB->manipulate("DELETE FROM style_color WHERE ".
2714  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2715  " color_name = ".$ilDB->quote($a_name, "text"));
2716  }
2717 
2721  function colorExists($a_color_name)
2722  {
2723  global $ilDB;
2724 
2725  $set = $ilDB->query("SELECT * FROM style_color WHERE ".
2726  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2727  "color_name = ".$ilDB->quote($a_color_name, "text"));
2728  if ($rec = $ilDB->fetchAssoc($set))
2729  {
2730  return true;
2731  }
2732  return false;
2733  }
2734 
2738  function getColorCodeForName($a_name)
2739  {
2740  global $ilDB;
2741 
2742  $pos = strpos($a_name, "(");
2743  if ($pos > 0)
2744  {
2745  $a_i = substr($a_name, $pos + 1);
2746  $a_i = str_replace(")", "", $a_i);
2747  $a_name = substr($a_name, 0, $pos);
2748  }
2749 
2750  $set = $ilDB->query("SELECT color_code FROM style_color WHERE ".
2751  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2752  " color_name = ".$ilDB->quote($a_name, "text"));
2753  if ($rec = $ilDB->fetchAssoc($set))
2754  {
2755  if ($a_i == "")
2756  {
2757  return "#".$rec["color_code"];
2758  }
2759  else
2760  {
2761  return "#".ilObjStyleSheet::_getColorFlavor($rec["color_code"],
2762  (int) $a_i);
2763  }
2764  }
2765  }
2766 
2770  static function _getColorFlavor($a_rgb, $a_i)
2771  {
2772  $rgb = ilObjStyleSheet::_explodeRGB($a_rgb, true);
2773  $hls = ilObjStyleSheet::_RGBToHLS($rgb);
2774 
2775  if ($a_i > 0)
2776  {
2777  $hls["l"] = $hls["l"] + ((255 - $hls["l"]) * ($a_i / 100));
2778  }
2779  if ($a_i < 0)
2780  {
2781  $hls["l"] = $hls["l"] - (($hls["l"]) * (-$a_i / 100));
2782  }
2783 
2784  $rgb = ilObjStyleSheet::_HLSToRGB($hls);
2785 
2786  foreach ($rgb as $k => $v)
2787  {
2788  $rgb[$k] = str_pad(dechex($v), 2, "0", STR_PAD_LEFT);
2789  }
2790 
2791  return $rgb["r"].$rgb["g"].$rgb["b"];
2792  }
2793 
2797  static function _explodeRGB($a_rgb, $as_dec = false)
2798  {
2799  $r["r"] = substr($a_rgb, 0, 2);
2800  $r["g"] = substr($a_rgb, 2, 2);
2801  $r["b"] = substr($a_rgb, 4, 2);
2802 
2803  if ($as_dec)
2804  {
2805  $r["r"] = (int) hexdec($r["r"]);
2806  $r["g"] = (int) hexdec($r["g"]);
2807  $r["b"] = (int) hexdec($r["b"]);
2808  }
2809 
2810  return $r;
2811  }
2812 
2816  static function _RGBToHLS($a_rgb)
2817  {
2818  $r = $a_rgb["r"] / 255;
2819  $g = $a_rgb["g"] / 255;
2820  $b = $a_rgb["b"] / 255;
2821 
2822  // max / min
2823  $max = max($r,$g,$b);
2824  $min = min($r,$g,$b);
2825 
2826  //lightness
2827  $l = ($max + $min) / 2;
2828 
2829  if ($max == $min)
2830  {
2831  $s = 0;
2832  $h = 0;
2833  }
2834  else
2835  {
2836  if ($l < 0.5)
2837  {
2838  $s = ($max - $min) / ($max + $min);
2839  }
2840  else
2841  {
2842  $s = ($max - $min) / (2.0 - $max - $min);
2843  }
2844 
2845  if ($r == $max)
2846  {
2847  $h = ($g - $b) / ($max - $min);
2848  }
2849  else if ($g == $max)
2850  {
2851  $h = 2.0 + ($b - $r) / ($max - $min);
2852  }
2853  else if ($b == $max)
2854  {
2855  $h = 4.0 + ($r - $g) / ($max - $min);
2856  }
2857  }
2858 
2859  $hls["h"] = round(($h / 6) * 255);
2860  $hls["l"] = round($l * 255);
2861  $hls["s"] = round($s * 255);
2862 
2863  return $hls;
2864  }
2865 
2869  static function _HLSToRGB($a_hls)
2870  {
2871  $h = $a_hls["h"] / 255;
2872  $l = $a_hls["l"] / 255;
2873  $s = $a_hls["s"] / 255;
2874 
2875  $rgb["r"] = $rgb["g"] = $rgb["b"] = 0;
2876 
2877  // If S=0, define R, G, and B all to L
2878  if ($s == 0)
2879  {
2880  $rgb["r"] = $rgb["g"] = $rgb["b"] = $l;
2881  }
2882  else
2883  {
2884 
2885  if ($l < 0.5)
2886  {
2887  $temp2 = $l * (1.0 + $s);
2888  }
2889  else
2890  {
2891  $temp2 = $l + $s - $l * $s;
2892  }
2893 
2894  $temp1 = 2.0 * $l - $temp2;
2895 
2896 
2897  # For each of R, G, B, compute another temporary value, temp3, as follows:
2898  foreach ($rgb as $k => $v)
2899  {
2900  switch ($k)
2901  {
2902  case "r":
2903  $temp3 = $h + 1.0 / 3.0;
2904  break;
2905 
2906  case "g":
2907  $temp3 = $h;
2908  break;
2909 
2910  case "b":
2911  $temp3 = $h - 1.0/3.0;
2912  break;
2913  }
2914  if ($temp3 < 0)
2915  {
2916  $temp3 = $temp3 + 1.0;
2917  }
2918  if ($temp3 > 1)
2919  {
2920  $temp3 = $temp3 - 1.0;
2921  }
2922 
2923  if (6.0 * $temp3 < 1)
2924  {
2925  $rgb[$k] = $temp1 + ($temp2 - $temp1) * 6.0 * $temp3;
2926  }
2927  else if (2.0 * $temp3 < 1)
2928  {
2929  $rgb[$k] = $temp2;
2930  }
2931  else if (3.0 * $temp3 < 2)
2932  {
2933  $rgb[$k] = $temp1 + ($temp2 - $temp1) * ((2.0/3.0) - $temp3) * 6.0;
2934  }
2935  else
2936  {
2937  $rgb[$k] = $temp1;
2938  }
2939  }
2940  }
2941 
2942  $rgb["r"] = round($rgb["r"] * 255);
2943  $rgb["g"] = round($rgb["g"] * 255);
2944  $rgb["b"] = round($rgb["b"] * 255);
2945 
2946  return $rgb;
2947  }
2948 
2949  //
2950  // Table template management
2951  //
2952 
2956  function getTemplates($a_type)
2957  {
2958  global $ilDB;
2959 
2960  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
2961  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2962  "temp_type = ".$ilDB->quote($a_type, "text")." ".
2963  "ORDER BY name");
2964 
2965  $templates = array();
2966  while ($rec = $ilDB->fetchAssoc($set))
2967  {
2968  $rec["classes"] = $this->getTemplateClasses($rec["id"]);
2969  $templates[] = $rec;
2970  }
2971 
2972  return $templates;
2973  }
2974 
2978  function getTemplateClasses($a_tid)
2979  {
2980  global $ilDB;
2981  $set = $ilDB->query("SELECT * FROM style_template_class WHERE ".
2982  "template_id = ".$ilDB->quote($a_tid, "integer"));
2983 
2984  $class = array();
2985  while ($rec = $ilDB->fetchAssoc($set))
2986  {
2987  $key = $rec["class_type"];
2988  $class[$key] = $rec["class"];
2989  }
2990 
2991  return $class;
2992  }
2993 
2994 
2998  function addTemplate($a_type, $a_name, $a_classes)
2999  {
3000  global $ilDB;
3001 
3002  $tid = $ilDB->nextId("style_template");
3003  $ilDB->manipulate($q = "INSERT INTO style_template ".
3004  "(id, style_id, name, temp_type)".
3005  " VALUES (".
3006  $ilDB->quote($tid, "integer").",".
3007  $ilDB->quote($this->getId(), "integer").",".
3008  $ilDB->quote($a_name, "text").",".
3009  $ilDB->quote($a_type, "text").
3010  ")");
3011 
3012  foreach ($a_classes as $t => $c)
3013  {
3014  $ilDB->manipulate($q = "INSERT INTO style_template_class ".
3015  "(template_id, class_type, class)".
3016  " VALUES (".
3017  $ilDB->quote($tid, "integer").",".
3018  $ilDB->quote($t, "text").",".
3019  $ilDB->quote($c, "text").
3020  ")");
3021  }
3022 
3023  include_once("./Services/Style/classes/class.ilObjStyleSheetGUI.php");
3024  $this->writeTemplatePreview($tid,
3025  ilObjStyleSheetGUI::_getTemplatePreview($this, $a_type, $tid, true));
3026 
3027  return $tid;
3028  }
3029 
3033  function updateTemplate($a_t_id, $a_name, $a_classes)
3034  {
3035  global $ilDB;
3036 
3037  $ilDB->manipulate("UPDATE style_template SET ".
3038  "name = ".$ilDB->quote($a_name, "text").
3039  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3040 
3041  $ilDB->manipulate("DELETE FROM style_template_class WHERE ".
3042  "template_id = ".$ilDB->quote($a_t_id, "integer")
3043  );
3044  foreach ($a_classes as $t => $c)
3045  {
3046  $ilDB->manipulate($q = "INSERT INTO style_template_class ".
3047  "(template_id, class_type, class)".
3048  " VALUES (".
3049  $ilDB->quote($a_t_id, "integer").",".
3050  $ilDB->quote($t, "text").",".
3051  $ilDB->quote($c, "text").
3052  ")");
3053  }
3054 
3055  }
3056 
3060  function templateExists($a_template_name)
3061  {
3062  global $ilDB;
3063 
3064  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3065  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3066  "name = ".$ilDB->quote($a_template_name, "text"));
3067  if ($rec = $ilDB->fetchAssoc($set))
3068  {
3069  return true;
3070  }
3071  return false;
3072  }
3073 
3077  function getTemplate($a_t_id)
3078  {
3079  global $ilDB;
3080 
3081  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3082  "style_id = ".$ilDB->quote($this->getId(), "integer")." ".
3083  " AND id = ".$ilDB->quote($a_t_id, "integer"));
3084 
3085  if ($rec = $ilDB->fetchAssoc($set))
3086  {
3087  $rec["classes"] = $this->getTemplateClasses($rec["id"]);
3088 
3089  $template = $rec;
3090  return $template;
3091  }
3092  return array();
3093  }
3094 
3098  function lookupTemplateName($a_t_id)
3099  {
3100  global $ilDB;
3101 
3102  $set = $ilDB->query("SELECT name FROM style_template WHERE ".
3103  " id = ".$ilDB->quote($a_t_id, "integer"));
3104 
3105  if ($rec = $ilDB->fetchAssoc($set))
3106  {
3107  return $rec["name"];
3108  }
3109 
3110  return false;
3111  }
3112 
3116  function getTemplateXML()
3117  {
3118  global $ilDB;
3119 
3120  $tag = "<StyleTemplates>";
3121 
3122  $ttypes = array("table", "vaccordion", "haccordion");
3123 
3124  foreach ($ttypes as $ttype)
3125  {
3126  $ts = $this->getTemplates($ttype);
3127 
3128  foreach($ts as $t)
3129  {
3131  /*$atts = array("table" => "TableClass",
3132  "caption" => "CaptionClass",
3133  "row_head" => "RowHeadClass",
3134  "row_foot" => "RowFootClass",
3135  "col_head" => "ColHeadClass",
3136  "col_foot" => "ColFootClass",
3137  "odd_row" => "OddRowClass",
3138  "even_row" => "EvenRowClass",
3139  "odd_col" => "OddColClass",
3140  "even_col" => "EvenColClass");*/
3141  $c = $t["classes"];
3142 
3143  $tag.= '<StyleTemplate Name="'.$t["name"].'">';
3144 
3145  foreach ($atts as $type => $t)
3146  {
3147  if ($c[$type] != "")
3148  {
3149  $tag.= '<StyleClass Type="'.$type.'" Value="'.$c[$type].'" />';
3150  }
3151  }
3152 
3153  $tag.= "</StyleTemplate>";
3154  }
3155  }
3156 
3157  $tag.= "</StyleTemplates>";
3158 
3159 //echo htmlentities($tag);
3160  return $tag;
3161  }
3162 
3166  function writeTemplatePreview($a_t_id, $a_preview_html)
3167  {
3168  global $ilDB;
3169  $a_preview_html = str_replace(' width=""', "", $a_preview_html);
3170  $a_preview_html = str_replace(' valign="top"', "", $a_preview_html);
3171  $a_preview_html = str_replace('<div class="ilc_text_block_TableContent">', "<div>", $a_preview_html);
3172 //echo "1-".strlen($a_preview_html)."-";
3173 //echo htmlentities($a_preview_html);
3174  if (strlen($a_preview_html) > 4000)
3175  {
3176 //echo "2";
3177  $a_preview_html = "";
3178  }
3179  $ilDB->manipulate("UPDATE style_template SET ".
3180  "preview = ".$ilDB->quote($a_preview_html, "text").
3181  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3182  }
3183 
3187  function lookupTemplatePreview($a_t_id)
3188  {
3189  global $ilDB;
3190 
3191  $set = $ilDB->query("SELECT preview FROM style_template ".
3192  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3193  if ($rec = $ilDB->fetchAssoc($set))
3194  {
3195  return $rec["preview"];
3196  }
3197 
3198  return "";
3199  }
3200 
3204  static function _lookupTemplateIdByName($a_style_id, $a_name)
3205  {
3206  global $ilDB;
3207 
3208  $set = $ilDB->query("SELECT id FROM style_template ".
3209  " WHERE style_id = ".$ilDB->quote($a_style_id, "integer").
3210  " AND name = ".$ilDB->quote($a_name, "text"));
3211  if ($rec = $ilDB->fetchAssoc($set))
3212  {
3213  return $rec["id"];
3214  }
3215 
3216  return false;
3217  }
3218 
3222  function removeTemplate($a_t_id)
3223  {
3224  global $ilDB;
3225 
3226  $ilDB->manipulate("DELETE FROM style_template WHERE ".
3227  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3228  " id = ".$ilDB->quote($a_t_id, "integer"));
3229 
3230  $ilDB->manipulate("DELETE FROM style_template_class WHERE ".
3231  "template_id = ".$ilDB->quote($a_t_id, "integer")
3232  );
3233 
3234  }
3235 
3239  function writeStyleSetting($a_name, $a_value)
3240  {
3241  global $ilDB;
3242 
3243  $ilDB->manipulate("DELETE FROM style_setting WHERE ".
3244  " style_id = ".$ilDB->quote($this->getId(), "integer").
3245  " AND name = ".$ilDB->quote($a_name, "text")
3246  );
3247 
3248  $ilDB->manipulate("INSERT INTO style_setting ".
3249  "(style_id, name, value) VALUES (".
3250  $ilDB->quote($this->getId(), "integer").",".
3251  $ilDB->quote($a_name, "text").",".
3252  $ilDB->quote($a_value, "text").
3253  ")");
3254  }
3255 
3259  function lookupStyleSetting($a_name)
3260  {
3261  global $ilDB;
3262 
3263  $set = $ilDB->query("SELECT value FROM style_setting ".
3264  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
3265  " AND name = ".$ilDB->quote($a_name, "text")
3266  );
3267  $rec = $ilDB->fetchAssoc($set);
3268 
3269  return $rec["value"];
3270  }
3271 
3275  static function writeStyleUsage($a_obj_id, $a_style_id)
3276  {
3277  global $ilDB;
3278 
3279  $ilDB->replace("style_usage", array(
3280  "obj_id" => array("integer", (int) $a_obj_id)),
3281  array(
3282  "style_id" => array("integer", (int) $a_style_id))
3283  );
3284  }
3285 
3289  static function lookupObjectStyle($a_obj_id)
3290  {
3291  global $ilDB;
3292 
3293  $set = $ilDB->query("SELECT style_id FROM style_usage ".
3294  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")
3295  );
3296  $rec = $ilDB->fetchAssoc($set);
3297 
3298  return (int) $rec["style_id"];
3299  }
3300 
3301 
3302 }
3303 ?>