ILIAS  Release_4_2_x_branch Revision 61807
 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", "a"));
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", "iim", "marker"),
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  "qimg", "qordul", "qordli", "qimgd", "qetitem", "qetcorr", "qover"),
252  "page" => array("page_frame", "page_cont", "page_title", "page_fn", "page",
253  "page_tnav", "page_bnav", "page_lnav", "page_rnav", "page_lnavlink", "page_rnavlink",
254  "page_lnavimage", "page_rnavimage"),
255  "glo" => array("glo_overlay", "glo_ovtitle", "glo_ovclink", "glo_ovuglink", "glo_ovuglistlink"),
256  "sco" => array("sco_title", "sco_keyw", "sco_desc", "sco_desct", "sco_obj", "sco_objt", "sco_fmess"),
257  "rte" => array("rte_menu", "rte_mlink", "rte_tree", "rte_node", "rte_tlink","rte_status",
258  "rte_tul", "rte_tli", "rte_texp", "rte_tclink", "rte_drag")
259  );
260 
261  // these types are expandable, i.e. the user can define new style classes
262  public static $expandable_types = array (
263  "text_block", "section", "media_cont", "table", "table_cell", "flist_li", "table_caption",
264  "list_o", "list_u",
265  "va_cntr", "va_icntr", "va_ihead", "va_icont",
266  "ha_cntr", "ha_icntr", "ha_ihead", "ha_icont"
267  );
268 
269  // these types can be hidden in the content editor
270  public static $hideable_types = array (
271  "table", "table_cell"
272  );
273 
274  // tag that are used by style types
275  public static $assigned_tags = array (
276  "text_block" => "div",
277  "heading1" => "h1",
278  "heading2" => "h2",
279  "heading3" => "h3",
280  "text_inline" => "span",
281  "section" => "div",
282  "link" => "a",
283  "table" => "table",
284  "table_cell" => "td",
285  "table_caption" => "caption",
286  "media_cont" => "table",
287  "media_caption" => "div",
288  "iim" => "div",
289  "marker" => "a",
290  "glo_overlay" => "div",
291  "glo_ovtitle" => "h1",
292  "glo_ovclink" => "a",
293  "glo_ovuglink" => "a",
294  "glo_ovuglistlink" => "a",
295  "sco_title" => "div",
296  "sco_keyw" => "div",
297  "sco_desc" => "div",
298  "sco_obj" => "div",
299  "sco_desct" => "div",
300  "sco_objt" => "div",
301  "sco_fmess" => "div",
302  "rte_menu" => "div",
303  "rte_mlink" => "a",
304  "rte_tree" => "div",
305  "rte_tclink" => "a",
306  "rte_drag" => "div",
307  "rte_node" => "div",
308  "rte_status" => "div",
309  "rte_tlink" => "a",
310  "rte_tul" => "div",
311  "rte_tli" => "div",
312  "rte_texp" => "a",
313  "list_o" => "ol",
314  "list_u" => "ul",
315  "list_item" => "li",
316  "flist_cont" => "div",
317  "flist_head" => "div",
318  "flist" => "ul",
319  "flist_li" => "li",
320  "flist_a" => "a",
321  "question" => "div",
322  "qtitle" => "div",
323  "qanswer" => "div",
324  "qimg" => "img",
325  "qimgd" => "a",
326  "qordul" => "ul",
327  "qordli" => "li",
328  "qetitem" => "a",
329  "qetcorr" => "span",
330  "qinput" => "input",
331  "qlinput" => "textarea",
332  "qsubmit" => "input",
333  "qfeedr" => "div",
334  "qfeedw" => "div",
335  "qover" => "div",
336  "page_frame" => "table",
337  "page_cont" => "table",
338  "page_fn" => "div",
339  "page" => "div",
340  "page_tnav" => "div",
341  "page_bnav" => "div",
342  "page_lnav" => "div",
343  "page_rnav" => "div",
344  "page_lnavlink" => "a",
345  "page_rnavlink" => "a",
346  "page_lnavimage" => "img",
347  "page_rnavimage" => "img",
348  "page_title" => "h1",
349  "va_cntr" => "div",
350  "va_icntr" => "div",
351  "va_icont" => "div",
352  "va_ihead" => "div",
353  "ha_cntr" => "div",
354  "ha_icntr" => "div",
355  "ha_icont" => "div",
356  "ha_ihead" => "div"
357  );
358 
359  // pseudo classes
360  public static $pseudo_classes =
361  array ("a" => array("hover"), "div" => array("hover"), "img" => array("hover"));
362 
363  // core styles these styles MUST exists -> see also basic_style/style.xml
364  public static $core_styles = array(
365  array("type" => "text_block", "class" => "Standard"),
366  array("type" => "text_block", "class" => "List"),
367  array("type" => "text_block", "class" => "TableContent"),
368  array("type" => "heading1", "class" => "Headline1"),
369  array("type" => "heading2", "class" => "Headline2"),
370  array("type" => "heading3", "class" => "Headline3"),
371  array("type" => "text_inline", "class" => "Comment"),
372  array("type" => "text_inline", "class" => "Emph"),
373  array("type" => "text_inline", "class" => "Quotation"),
374  array("type" => "text_inline", "class" => "Strong"),
375  array("type" => "text_inline", "class" => "Accent"),
376  array("type" => "text_inline", "class" => "Important"),
377  array("type" => "link", "class" => "IntLink"),
378  array("type" => "link", "class" => "ExtLink"),
379  array("type" => "link", "class" => "FootnoteLink"),
380  array("type" => "link", "class" => "FileLink"),
381  array("type" => "link", "class" => "GlossaryLink"),
382  array("type" => "media_cont", "class" => "MediaContainer"),
383  array("type" => "table", "class" => "StandardTable"),
384  array("type" => "media_caption", "class" => "MediaCaption"),
385  array("type" => "iim", "class" => "ContentPopup"),
386  array("type" => "marker", "class" => "Marker"),
387  array("type" => "page_frame", "class" => "PageFrame"),
388  array("type" => "page_cont", "class" => "PageContainer"),
389  array("type" => "page", "class" => "Page"),
390  array("type" => "page_tnav", "class" => "TopNavigation"),
391  array("type" => "page_bnav", "class" => "BottomNavigation"),
392  array("type" => "page_lnav", "class" => "LeftNavigation"),
393  array("type" => "page_rnav", "class" => "RightNavigation"),
394  array("type" => "page_lnavlink", "class" => "LeftNavigationLink"),
395  array("type" => "page_rnavlink", "class" => "RightNavigationLink"),
396  array("type" => "page_lnavimage", "class" => "LeftNavigationImage"),
397  array("type" => "page_rnavimage", "class" => "RightNavigationImage"),
398  array("type" => "page_fn", "class" => "Footnote"),
399  array("type" => "page_title", "class" => "PageTitle"),
400  array("type" => "glo_overlay", "class" => "GlossaryOverlay"),
401  array("type" => "glo_ovtitle", "class" => "GlossaryOvTitle"),
402  array("type" => "glo_ovclink", "class" => "GlossaryOvCloseLink"),
403  array("type" => "glo_ovuglink", "class" => "GlossaryOvUnitGloLink"),
404  array("type" => "glo_ovuglistlink", "class" => "GlossaryOvUGListLink"),
405  array("type" => "sco_title", "class" => "Title"),
406  array("type" => "sco_desc", "class" => "Description"),
407  array("type" => "sco_desct", "class" => "DescriptionTop"),
408  array("type" => "sco_keyw", "class" => "Keywords"),
409  array("type" => "sco_obj", "class" => "Objective"),
410  array("type" => "sco_objt", "class" => "ObjectiveTop"),
411  array("type" => "sco_fmess", "class" => "FinalMessage"),
412  array("type" => "rte_menu", "class" => "RTEMenu"),
413  array("type" => "rte_menu", "class" => "RTELogo"),
414  array("type" => "rte_menu", "class" => "RTELinkBar"),
415  array("type" => "rte_mlink", "class" => "RTELink"),
416  array("type" => "rte_mlink", "class" => "RTELinkDisabled"),
417  array("type" => "rte_tree", "class" => "RTETree"),
418  array("type" => "rte_node", "class" => "RTECourse"),
419  array("type" => "rte_node", "class" => "RTEChapter"),
420  array("type" => "rte_node", "class" => "RTESco"),
421  array("type" => "rte_node", "class" => "RTEAsset"),
422  array("type" => "rte_node", "class" => "RTECourseDisabled"),
423  array("type" => "rte_node", "class" => "RTEChapterDisabled"),
424  array("type" => "rte_node", "class" => "RTEScoDisabled"),
425  array("type" => "rte_node", "class" => "RTEAssetDisabled"),
426  array("type" => "rte_status", "class" => "RTEAsset"),
427  array("type" => "rte_status", "class" => "RTECompleted"),
428  array("type" => "rte_status", "class" => "RTENotAttempted"),
429  array("type" => "rte_status", "class" => "RTERunning"),
430  array("type" => "rte_status", "class" => "RTEIncomplete"),
431  array("type" => "rte_status", "class" => "RTEPassed"),
432  array("type" => "rte_status", "class" => "RTEFailed"),
433  array("type" => "rte_status", "class" => "RTEBrowsed"),
434  array("type" => "rte_tlink", "class" => "RTETreeLink"),
435  array("type" => "rte_tlink", "class" => "RTETreeLinkDisabled"),
436  array("type" => "rte_tlink", "class" => "RTETreeCurrent"),
437  array("type" => "rte_tul", "class" => "RTETreeList"),
438  array("type" => "rte_tli", "class" => "RTETreeItem"),
439  array("type" => "rte_texp", "class" => "RTETreeExpanded"),
440  array("type" => "rte_texp", "class" => "RTETreeCollapsed"),
441  array("type" => "rte_tree", "class" => "RTETreeControl"),
442  array("type" => "rte_tclink", "class" => "RTETreeControlLink"),
443  array("type" => "rte_drag", "class" => "RTEDragBar"),
444  array("type" => "list_o", "class" => "NumberedList"),
445  array("type" => "list_u", "class" => "BulletedList"),
446  array("type" => "list_item", "class" => "StandardListItem"),
447  array("type" => "question", "class" => "Standard"),
448  array("type" => "question", "class" => "SingleChoice"),
449  array("type" => "question", "class" => "MultipleChoice"),
450  array("type" => "question", "class" => "TextQuestion"),
451  array("type" => "question", "class" => "OrderingQuestion"),
452  array("type" => "question", "class" => "MatchingQuestion"),
453  array("type" => "question", "class" => "ImagemapQuestion"),
454  array("type" => "question", "class" => "ErrorText"),
455  array("type" => "question", "class" => "TextSubset"),
456  array("type" => "question", "class" => "ClozeTest"),
457  array("type" => "qtitle", "class" => "Title"),
458  array("type" => "qanswer", "class" => "Answer"),
459  array("type" => "qimg", "class" => "QuestionImage"),
460  array("type" => "qimgd", "class" => "ImageDetailsLink"),
461  array("type" => "qordul", "class" => "OrderList"),
462  array("type" => "qordli", "class" => "OrderListItem"),
463  array("type" => "qordul", "class" => "OrderListHorizontal"),
464  array("type" => "qordli", "class" => "OrderListItemHorizontal"),
465  array("type" => "qetitem", "class" => "ErrorTextItem"),
466  array("type" => "qetitem", "class" => "ErrorTextSelected"),
467  array("type" => "qetcorr", "class" => "ErrorTextCorrected"),
468  array("type" => "qinput", "class" => "TextInput"),
469  array("type" => "qlinput", "class" => "LongTextInput"),
470  array("type" => "qsubmit", "class" => "Submit"),
471  array("type" => "qfeedr", "class" => "FeedbackRight"),
472  array("type" => "qfeedw", "class" => "FeedbackWrong"),
473  array("type" => "qover", "class" => "Correct"),
474  array("type" => "qover", "class" => "Inorrect"),
475  array("type" => "qover", "class" => "StatusMessage"),
476  array("type" => "qover", "class" => "WrongAnswersMessage"),
477  array("type" => "flist_cont", "class" => "FileListContainer"),
478  array("type" => "flist_head", "class" => "FileListHeading"),
479  array("type" => "flist", "class" => "FileList"),
480  array("type" => "flist_li", "class" => "FileListItem"),
481  array("type" => "flist_a", "class" => "FileListItemLink")
482  );
483 
484  public static $templates = array(
485  "table" => array(
486  "table" => "table",
487  "caption" => "table_caption",
488  "row_head" => "table_cell",
489  "row_foot" => "table_cell",
490  "col_head" => "table_cell",
491  "col_foot" => "table_cell",
492  "odd_row" => "table_cell",
493  "even_row" => "table_cell",
494  "odd_col" => "table_cell",
495  "even_col" => "table_cell"),
496  "vaccordion" => array(
497  "va_cntr" => "va_cntr",
498  "va_icntr" => "va_icntr",
499  "va_ihead" => "va_ihead",
500  "va_icont" => "va_icont"
501  ),
502  "haccordion" => array(
503  "ha_cntr" => "ha_cntr",
504  "ha_icntr" => "ha_icntr",
505  "ha_ihead" => "ha_ihead",
506  "ha_icont" => "ha_icont"
507  )
508  );
509 
510  // basic style xml file, image directory and dom
511  protected static $basic_style_file = "./Services/Style/basic_style/style.xml";
512  protected static $basic_style_image_dir = "./Services/Style/basic_style/images";
513  protected static $basic_style_dom;
514 
521  function ilObjStyleSheet($a_id = 0, $a_call_by_reference = false)
522  {
523  $this->type = "sty";
524  $this->style = array();
525  if($a_call_by_reference)
526  {
527  $this->ilias->raiseError("Can't instantiate style object via reference id.",$this->ilias->error_obj->FATAL);
528  }
529 
530  parent::ilObject($a_id, false);
531  }
532 
536  function setRefId()
537  {
538  $this->ilias->raiseError("Operation ilObjStyleSheet::setRefId() not allowed.",$this->ilias->error_obj->FATAL);
539  }
540 
544  function getRefId()
545  {
546  return "";
547  //$this->ilias->raiseError("Operation ilObjStyleSheet::getRefId() not allowed.",$this->ilias->error_obj->FATAL);
548  }
549 
553  function putInTree()
554  {
555  $this->ilias->raiseError("Operation ilObjStyleSheet::putInTree() not allowed.",$this->ilias->error_obj->FATAL);
556  }
557 
561  function createReference()
562  {
563  $this->ilias->raiseError("Operation ilObjStyleSheet::createReference() not allowed.",$this->ilias->error_obj->FATAL);
564  }
565 
569  function setUpToDate($a_up_to_date = true)
570  {
571  $this->up_to_date = $a_up_to_date;
572  }
573 
577  function getUpToDate()
578  {
579  return $this->up_to_date;
580  }
581 
585  function setScope($a_scope)
586  {
587  $this->scope = $a_scope;
588  }
589 
593  function getScope()
594  {
595  return $this->scope;
596  }
597 
601  function _writeUpToDate($a_id, $a_up_to_date)
602  {
603  global $ilDB;
604 
605  $q = "UPDATE style_data SET uptodate = ".
606  $ilDB->quote((int) $a_up_to_date, "integer").
607  " WHERE id = ".$ilDB->quote($a_id, "integer");
608  $ilDB->manipulate($q);
609  }
610 
614  function _lookupUpToDate($a_id)
615  {
616  global $ilDB;
617 
618  $q = "SELECT uptodate FROM style_data ".
619  " WHERE id = ".$ilDB->quote($a_id, "integer");
620  $res = $ilDB->query($q);
621  $sty = $ilDB->fetchAssoc($res);
622 
623  return (boolean) $sty["uptodate"];
624  }
625 
629  function _writeStandard($a_id, $a_std)
630  {
631  global $ilDB;
632 
633  $q = "UPDATE style_data SET standard = ".
634  $ilDB->quote((int) $a_std, "integer").
635  " WHERE id = ".$ilDB->quote($a_id, "integer");
636  $ilDB->manipulate($q);
637  }
638 
642  function _writeScope($a_id, $a_scope)
643  {
644  global $ilDB;
645 
646  $q = "UPDATE style_data SET category = ".
647  $ilDB->quote((int) $a_scope, "integer").
648  " WHERE id = ".$ilDB->quote($a_id, "integer");
649  $ilDB->manipulate($q);
650  }
651 
655  function _lookupStandard($a_id)
656  {
657  global $ilDB;
658 
659  $q = "SELECT * FROM style_data ".
660  " WHERE id = ".$ilDB->quote($a_id, "integer");
661  $res = $ilDB->query($q);
662  $sty = $ilDB->fetchAssoc($res);
663 
664  return (boolean) $sty["standard"];
665  }
666 
670  function _writeActive($a_id, $a_active)
671  {
672  global $ilDB;
673 
674  $q = "UPDATE style_data SET active = ".
675  $ilDB->quote((int) $a_active, "integer").
676  " WHERE id = ".$ilDB->quote($a_id, "integer");
677  $ilDB->manipulate($q);
678  }
679 
683  function _lookupActive($a_id)
684  {
685  global $ilDB;
686 
687  $q = "SELECT * FROM style_data ".
688  " WHERE id = ".$ilDB->quote($a_id, "integer");
689  $res = $ilDB->query($q);
690  $sty = $ilDB->fetchAssoc($res);
691 
692  return (boolean) $sty["active"];
693  }
694 
698  function _getStandardStyles($a_exclude_default_style = false,
699  $a_include_deactivated = false, $a_scope = 0)
700  {
701  global $ilDB, $ilias, $tree;
702 
703  $default_style = $ilias->getSetting("default_content_style_id");
704 
705  $and_str = "";
706  if (!$a_include_deactivated)
707  {
708  $and_str = " AND active = 1";
709  }
710 
711  $q = "SELECT * FROM style_data ".
712  " WHERE standard = 1".$and_str;
713  $res = $ilDB->query($q);
714  $styles = array();
715  while($sty = $ilDB->fetchAssoc($res))
716  {
717  if (!$a_exclude_default_style || $default_style != $sty["id"])
718  {
719  // check scope
720  if ($a_scope > 0 && $sty["category"] > 0)
721  {
722  if ($tree->isInTree($sty["category"]) &&
723  $tree->isInTree($a_scope))
724  {
725  $path = $tree->getPathId($a_scope);
726  if (!in_array($sty["category"], $path))
727  {
728  continue;
729  }
730  }
731  }
732  $styles[$sty["id"]] = ilObject::_lookupTitle($sty["id"]);
733  }
734  }
735 
736  return $styles;
737  }
738 
739 
745  {
746  global $ilAccess, $ilDB;
747 
748  $clonable_styles = array();
749 
750  $q = "SELECT * FROM style_data";
751  $style_set = $ilDB->query($q);
752  while($style_rec = $ilDB->fetchAssoc($style_set))
753  {
754  $clonable = false;
755  if ($style_rec["standard"] == 1)
756  {
757  if ($style_rec["active"] == 1)
758  {
759  $clonable = true;
760  }
761  }
762  else
763  {
764  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
765  $obj_ids = ilObjContentObject::_lookupContObjIdByStyleId($style_rec["id"]);
766  foreach($obj_ids as $id)
767  {
768  $ref = ilObject::_getAllReferences($id);
769  foreach($ref as $ref_id)
770  {
771  if ($ilAccess->checkAccess("write", "", $ref_id))
772  {
773  $clonable = true;
774  }
775  }
776  }
777  }
778  if ($clonable)
779  {
780  $clonable_styles[$style_rec["id"]] =
781  ilObject::_lookupTitle($style_rec["id"]);
782  }
783  }
784  return $clonable_styles;
785  }
786 
790  function assignMetaData(&$a_meta_data)
791  {
792  $this->meta_data =& $a_meta_data;
793  }
794 
798  static function _getBasicStyleDom()
799  {
800  global $ilBench;
801 
802  if (!is_object(self::$basic_style_dom))
803  {
804  self::$basic_style_dom = new DOMDocument();
805  self::$basic_style_dom->load(self::$basic_style_file);
806  }
807 
808  return self::$basic_style_dom;
809  }
810 
814  function &getMetaData()
815  {
816  return $this->meta_data;
817  }
818 
822  function create($a_from_style = 0, $a_import_mode = false)
823  {
824  global $ilDB;
825 
826  parent::create();
827 
828  if ($a_from_style == 0)
829  {
830  if (!$a_import_mode)
831  {
832  // copy styles from basic style
833  $this->createFromXMLFile(self::$basic_style_file, true);
834 
835  // copy images from basic style
836  $this->createImagesDirectory();
837  ilUtil::rCopy(self::$basic_style_image_dir,
838  $this->getImagesDirectory());
839  }
840  }
841  else
842  {
843  // get style parameter records
844  $def = array();
845  $q = "SELECT * FROM style_parameter WHERE style_id = ".
846  $ilDB->quote($a_from_style, "integer");
847  $par_set = $ilDB->query($q);
848  while($par_rec = $ilDB->fetchAssoc($par_set))
849  {
850  $def[] = array("tag" => $par_rec["tag"], "class" => $par_rec["class"],
851  "parameter" => $par_rec["parameter"], "value" => $par_rec["value"],
852  "type" => $par_rec["type"]);
853  }
854 
855  // get style characteristics records
856  $chars = array();
857  $q = "SELECT * FROM style_char WHERE style_id = ".
858  $ilDB->quote($a_from_style, "integer");
859  $par_set = $ilDB->query($q);
860  while($par_rec = $ilDB->fetchAssoc($par_set))
861  {
862  $chars[] = array("type" => $par_rec["type"], "characteristic" => $par_rec["characteristic"]);
863  }
864 
865  // default style settings
866  foreach ($def as $sty)
867  {
868  $id = $ilDB->nextId("style_parameter");
869  $q = "INSERT INTO style_parameter (id, style_id, tag, class, parameter, value, type) VALUES ".
870  "(".
871  $ilDB->quote($id, "integer").",".
872  $ilDB->quote($this->getId(), "integer").",".
873  $ilDB->quote($sty["tag"], "text").",".
874  $ilDB->quote($sty["class"], "text").",".
875  $ilDB->quote($sty["parameter"], "text").",".
876  $ilDB->quote($sty["value"], "text").",".
877  $ilDB->quote($sty["type"], "text").")";
878  $ilDB->manipulate($q);
879  }
880 
881  // insert style characteristics
882  foreach ($chars as $char)
883  {
884  $q = "INSERT INTO style_char (style_id, type, characteristic) VALUES ".
885  "(".$ilDB->quote($this->getId(), "integer").",".
886  $ilDB->quote($char["type"], "text").",".
887  $ilDB->quote($char["characteristic"], "text").")";
888  $ilDB->manipulate($q);
889  }
890 
891  // add style_data record
892  $q = "INSERT INTO style_data (id, uptodate, category) VALUES ".
893  "(".$ilDB->quote($this->getId(), "integer").", 0,".
894  $ilDB->quote((int) $this->getScope(), "integer").")";
895  $ilDB->manipulate($q);
896 
897  // copy images
898  $from_style = new ilObjStyleSheet($a_from_style);
899  $this->createImagesDirectory();
900  ilUtil::rCopy($from_style->getImagesDirectory(),
901  $this->getImagesDirectory());
902 
903  // copy colors
904  $colors = $from_style->getColors();
905  foreach ($colors as $c)
906  {
907  $this->addColor($c["name"], $c["code"]);
908  }
909 
910  // copy templates
912  foreach ($tcts as $tct => $v)
913  {
914  $templates = $from_style->getTemplates($tct);
915  foreach ($templates as $t)
916  {
917  $this->addTemplate($tct, $t["name"], $t["classes"]);
918  }
919  }
920 
921  }
922 
923  $this->read();
924  if (!$a_import_mode)
925  {
926  $this->writeCSSFile();
927  }
928  }
929 
933  function deleteCharacteristic($a_type, $a_tag, $a_class)
934  {
935  global $ilDB;
936 
937  // check, if characteristic is not a core style
939  if (empty($core_styles[$a_type.".".$a_tag.".".$a_class]))
940  {
941  // delete characteristic record
942  $st = $ilDB->manipulateF(
943  "DELETE FROM style_char WHERE style_id = %s AND type = %s AND characteristic = %s",
944  array("integer", "text", "text"),
945  array($this->getId(), $a_type, $a_class));
946 
947  // delete parameter records
948  $st = $ilDB->manipulateF("DELETE FROM style_parameter WHERE style_id = %s AND tag = %s AND type = %s AND class = %s",
949  array("integer", "text", "text", "text"),
950  array($this->getId(), $a_tag, $a_type, $a_class));
951  }
952 
953  $this->setUpToDate(false);
954  $this->_writeUpToDate($this->getId(), false);
955  }
956 
960  function characteristicExists($a_char, $a_style_type)
961  {
962  global $ilDB;
963 
964  $set = $ilDB->queryF(
965  "SELECT style_id FROM style_char WHERE style_id = %s AND characteristic = %s AND type = %s",
966  array("integer", "text", "text"),
967  array($this->getId(), $a_char, $a_style_type));
968  if ($rec = $ilDB->fetchAssoc($set))
969  {
970  return true;
971  }
972  return false;
973  }
974 
978  function addCharacteristic($a_type, $a_char, $a_hidden = false)
979  {
980  global $ilDB;
981 
982  // delete characteristic record
983  $ilDB->manipulateF("INSERT INTO style_char (style_id, type, characteristic, hide)".
984  " VALUES (%s,%s,%s,%s) ",
985  array("integer", "text", "text", "integer"),
986  array($this->getId(), $a_type, $a_char, $a_hidden));
987 
988  $this->setUpToDate(false);
989  $this->_writeUpToDate($this->getId(), false);
990  }
991 
998  function copyCharacteristic($a_from_style_id,
999  $a_from_type, $a_from_char, $a_to_char)
1000  {
1001  global $ilDB;
1002 
1003  if (!$this->characteristicExists($a_to_char, $a_from_type))
1004  {
1005  $this->addCharacteristic($a_from_type, $a_to_char);
1006  }
1007  $this->deleteStyleParOfChar($a_from_type, $a_to_char);
1008 
1009  $from_style = new ilObjStyleSheet($a_from_style_id);
1010 
1011  $pars = $from_style->getParametersOfClass($a_from_type, $a_from_char);
1012 
1013  $colors = array();
1014  foreach ($pars as $p => $v)
1015  {
1016  if (substr($v, 0, 1) == "!")
1017  {
1018  $colors[] = substr($v, 1);
1019  }
1020  $this->replaceStylePar(ilObjStyleSheet::_determineTag($a_from_type),
1021  $a_to_char, $p, $v, $a_from_type);
1022  }
1023 
1024  // copy colors
1025  foreach ($colors as $c)
1026  {
1027  if (!$this->colorExists($c))
1028  {
1029  $this->addColor($c, $from_style->getColorCodeForName($c));
1030  }
1031  }
1032  }
1033 
1037  function getCharacteristics($a_type = "", $a_no_hidden = false)
1038  {
1039  $chars = array();
1040 
1041  if ($a_type == "")
1042  {
1043  $chars = $this->chars;
1044  }
1045  if (is_array($this->chars_by_type[$a_type]))
1046  {
1047  $chars = $this->chars_by_type[$a_type];
1048  }
1049 
1050  if ($a_no_hidden)
1051  {
1052  foreach ($chars as $k => $char)
1053  {
1054  if ($a_type == "" && $this->hidden_chars[$char["type"].":".$char["class"]])
1055  {
1056  unset($chars[$k]);
1057  }
1058  else if ($this->hidden_chars[$a_type.":".$char])
1059  {
1060  unset($chars[$k]);
1061  }
1062  }
1063  }
1064 
1065  return $chars;
1066  }
1067 
1071  function setCharacteristics($a_chars)
1072  {
1073  $this->chars = $a_chars;
1074  // $this->chars_by_type[$a_type];
1075  }
1076 
1080  function saveHideStatus($a_type, $a_char, $a_hide)
1081  {
1082  global $ilDB;
1083 
1084  $ilDB->manipulate("UPDATE style_char SET ".
1085  " hide = ".$ilDB->quote((int) $a_hide, "integer").
1086  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1087  " type = ".$ilDB->quote($a_type, "text")." AND ".
1088  " characteristic = ".$ilDB->quote($a_char, "text")
1089  );
1090  }
1091 
1095  function getHideStatus($a_type, $a_char)
1096  {
1097  global $ilDB;
1098 
1099  $set = $ilDB->query("SELECT hide FROM style_char ".
1100  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1101  " type = ".$ilDB->quote($a_type, "text")." AND ".
1102  " characteristic = ".$ilDB->quote($a_char, "text")
1103  );
1104  $rec = $ilDB->fetchAssoc($set);
1105 
1106  return $rec["hide"];
1107  }
1108 
1115  function ilClone()
1116  {
1117  global $log, $lng;
1118 
1119  $new_obj = new ilObjStyleSheet();
1120  $new_obj->setTitle($this->getTitle()." (".$lng->txt("sty_acopy").")");
1121  $new_obj->setType($this->getType());
1122  $new_obj->setDescription($this->getDescription());
1123  $new_obj->create($this->getId());
1124 
1125  $new_obj->writeStyleSetting("disable_auto_margins",
1126  $this->lookupStyleSetting("disable_auto_margins"));
1127 
1128  return $new_obj->getId();
1129  }
1130 
1134  function copyImagesToDir($a_target)
1135  {
1136  ilUtil::rCopy($this->getImagesDirectory(), $a_target);
1137  }
1138 
1146  function addParameter($a_tag, $a_par, $a_type)
1147  {
1148  global $ilDB;
1149 
1150  $avail_params = $this->getAvailableParameters();
1151  $tag = explode(".", $a_tag);
1152  $value = $avail_params[$a_par][0];
1153  $id = $ilDB->nextId("style_parameter");
1154  $q = "INSERT INTO style_parameter (id,style_id, type, tag, class, parameter, value) VALUES ".
1155  "(".
1156  $ilDB->quote($id, "integer").",".
1157  $ilDB->quote($this->getId(), "integer").",".
1158  $ilDB->quote($a_type, "text").",".
1159  $ilDB->quote($tag[0], "text").",".
1160  $ilDB->quote($tag[1], "text").",".
1161  $ilDB->quote($a_par, "text").",".
1162  $ilDB->quote($value, "text").")";
1163  $ilDB->manipulate($q);
1164  $this->read();
1165  $this->writeCSSFile();
1166  }
1167 
1173  {
1175  }
1176 
1181  static function _createImagesDirectory($a_style_id)
1182  {
1183  global $ilErr;
1184 
1185  $sty_data_dir = ilUtil::getWebspaceDir()."/sty";
1186  ilUtil::makeDir($sty_data_dir);
1187  if(!is_writable($sty_data_dir))
1188  {
1189  $ilErr->raiseError("Style data directory (".$sty_data_dir
1190  .") not writeable.", $ilErr->FATAL);
1191  }
1192 
1193  $style_dir = $sty_data_dir."/sty_".$a_style_id;
1194  ilUtil::makeDir($style_dir);
1195  if(!@is_dir($style_dir))
1196  {
1197  $ilErr->raiseError("Creation of style directory failed (".
1198  $style_dir.").",$ilErr->FATAL);
1199  }
1200 
1201  // create images subdirectory
1202  $im_dir = $style_dir."/images";
1203  ilUtil::makeDir($im_dir);
1204  if(!@is_dir($im_dir))
1205  {
1206  $ilErr->raiseError("Creation of Import Directory failed (".
1207  $im_dir.").", $ilErr->FATAL);
1208  }
1209 
1210  // create thumbnails directory
1211  $thumb_dir = $style_dir."/images/thumbnails";
1212  ilUtil::makeDir($thumb_dir);
1213  if(!@is_dir($thumb_dir))
1214  {
1215  $ilErr->raiseError("Creation of Import Directory failed (".
1216  $thumb_dir.").", $ilErr->FATAL);
1217  }
1218  }
1219 
1224  {
1226  }
1227 
1231  static function _getImagesDirectory($a_style_id)
1232  {
1233  return ilUtil::getWebspaceDir()."/sty/sty_".$a_style_id.
1234  "/images";
1235  }
1236 
1241  {
1242  return $this->getImagesDirectory().
1243  "/thumbnails";
1244  }
1245 
1249  function getImages()
1250  {
1251  $dir = $this->getImagesDirectory();
1252  $images = array();
1253  if (is_dir($dir))
1254  {
1255  $entries = ilUtil::getDir($dir);
1256  foreach($entries as $entry)
1257  {
1258  if (substr($entry["entry"],0,1) == ".")
1259  {
1260  continue;
1261  }
1262  if ($entry["type"] != "dir")
1263  {
1264  $images[] = $entry;
1265  }
1266  }
1267  }
1268 
1269  return $images;
1270  }
1271 
1275  function uploadImage($a_file)
1276  {
1277  $this->createImagesDirectory();
1278  @ilUtil::moveUploadedFile($a_file["tmp_name"], $a_file["name"],
1279  $this->getImagesDirectory()."/".$a_file["name"]);
1280  @ilUtil::resizeImage($this->getImagesDirectory()."/".$a_file["name"],
1281  $this->getThumbnailsDirectory()."/".$a_file["name"], 75, 75);
1282  }
1283 
1287  function deleteImage($a_file)
1288  {
1289  if (is_file($this->getImagesDirectory()."/".$a_file))
1290  {
1291  unlink($this->getImagesDirectory()."/".$a_file);
1292  }
1293  if (is_file($this->getThumbnailsDirectory()."/".$a_file))
1294  {
1295  unlink($this->getThumbnailsDirectory()."/".$a_file);
1296  }
1297  }
1298 
1304  function deleteParameter($a_id)
1305  {
1306  global $ilDB;
1307 
1308  $q = "DELETE FROM style_parameter WHERE id = ".
1309  $ilDB->quote($a_id, "integer");
1310  $ilDB->query($q);
1311  }
1312 
1321  function deleteStylePar($a_tag, $a_class, $a_par, $a_type)
1322  {
1323  global $ilDB;
1324 
1325  $q = "DELETE FROM style_parameter WHERE ".
1326  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1327  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1328  " class = ".$ilDB->quote($a_class, "text")." AND ".
1329  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1330  " parameter = ".$ilDB->quote($a_par, "text");
1331 
1332  $ilDB->manipulate($q);
1333  }
1334 
1343  function deleteStyleParOfChar($a_type, $a_class)
1344  {
1345  global $ilDB;
1346 
1347  $q = "DELETE FROM style_parameter WHERE ".
1348  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1349  " class = ".$ilDB->quote($a_class, "text")." AND ".
1350  " ".$ilDB->equals("type", $a_type, "text", true);
1351 
1352  $ilDB->manipulate($q);
1353  }
1354 
1355 
1359  function delete()
1360  {
1361  global $ilDB;
1362 
1363  // delete object
1364  parent::delete();
1365 
1366  // check whether this style is global default
1367  $def_style = $this->ilias->getSetting("default_content_style_id");
1368  if ($def_style == $this->getId())
1369  {
1370  $this->ilias->deleteSetting("default_content_style_id");
1371  }
1372 
1373  // check whether this style is global fixed
1374  $fixed_style = $this->ilias->getSetting("fixed_content_style_id");
1375  if ($fixed_style == $this->getId())
1376  {
1377  $this->ilias->deleteSetting("fixed_content_style_id");
1378  }
1379 
1380  // delete style parameter
1381  $q = "DELETE FROM style_parameter WHERE style_id = ".
1382  $ilDB->quote($this->getId(), "integer");
1383  $ilDB->manipulate($q);
1384 
1385  // delete style file
1386  $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
1387  if (is_file($css_file_name))
1388  {
1389  unlink($css_file_name);
1390  }
1391 
1392  // delete entries in learning modules
1393  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
1395 
1396  // delete style data record
1397  $q = "DELETE FROM style_data WHERE id = ".
1398  $ilDB->quote($this->getId(), "integer");
1399  $ilDB->manipulate($q);
1400 
1401  }
1402 
1403 
1407  function read()
1408  {
1409  global $ilDB;
1410 
1411  parent::read();
1412 
1413  $q = "SELECT * FROM style_parameter WHERE style_id = ".
1414  $ilDB->quote($this->getId(), "integer")." ORDER BY tag, class, type ";
1415  $style_set = $ilDB->query($q);
1416  $ctag = "";
1417  $cclass = "";
1418  $ctype = "";
1419  $this->style = array();
1420  while($style_rec = $ilDB->fetchAssoc($style_set))
1421  {
1422  if ($style_rec["tag"] != $ctag || $style_rec["class"] != $cclass
1423  || $style_rec["type"] != $ctype)
1424  {
1425  // add current tag array to style array
1426  if(is_array($tag))
1427  {
1428  $this->style[] = $tag;
1429  }
1430  $tag = array();
1431  }
1432  $ctag = $style_rec["tag"];
1433  $cclass = $style_rec["class"];
1434  $ctype = $style_rec["type"];
1435  $tag[] = $style_rec;
1436  $this->style_class[$ctype][$cclass][$style_rec["parameter"]] = $style_rec["value"];
1437  }
1438  if(is_array($tag))
1439  {
1440  $this->style[] = $tag;
1441  }
1442 //var_dump($this->style_class);
1443  $q = "SELECT * FROM style_data WHERE id = ".
1444  $ilDB->quote($this->getId(), "integer");
1445  $res = $ilDB->query($q);
1446  $sty = $ilDB->fetchAssoc($res);
1447  $this->setUpToDate((boolean) $sty["uptodate"]);
1448  $this->setScope($sty["category"]);
1449 
1450  // get style characteristics records
1451  $this->chars = array();
1452  $this->chars_by_type = array();
1453  $q = "SELECT * FROM style_char WHERE style_id = ".
1454  $ilDB->quote($this->getId(), "integer").
1455  " ORDER BY type ASC, characteristic ASC";
1456  $par_set = $ilDB->query($q);
1457  while($par_rec = $ilDB->fetchAssoc($par_set))
1458  {
1459  $this->chars[] = array("type" => $par_rec["type"], "class" => $par_rec["characteristic"], "hide" => $par_rec["hide"]);
1460  $this->chars_by_type[$par_rec["type"]][] = $par_rec["characteristic"];
1461  if ($par_rec["hide"])
1462  {
1463  $this->hidden_chars[$par_rec["type"].":".$par_rec["characteristic"]] = true;
1464  }
1465  }
1466  }
1467 
1471  function writeCSSFile($a_target_file = "", $a_image_dir = "")
1472  {
1473  $style = $this->getStyle();
1474 
1475  if ($a_target_file == "")
1476  {
1477  $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
1478  }
1479  else
1480  {
1481  $css_file_name = $a_target_file;
1482  }
1483  $css_file = fopen($css_file_name, "w");
1484 
1485  $page_background = "";
1486 
1487  foreach ($style as $tag)
1488  {
1489  fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]."\n");
1490  if ($tag[0]["tag"] == "td")
1491  {
1492  fwrite ($css_file, ",th".".ilc_".$tag[0]["type"]."_".$tag[0]["class"]."\n");
1493  }
1494  if (in_array($tag[0]["tag"], array("h1", "h2", "h3")))
1495  {
1496  fwrite ($css_file, ",div.ilc_text_block_".$tag[0]["class"]."\n");
1497  fwrite ($css_file, ",body.ilc_text_block_".$tag[0]["class"]."\n");
1498  }
1499  if ($tag[0]["type"] == "text_block")
1500  {
1501  fwrite ($css_file, ",body.ilc_text_block_".$tag[0]["class"]."\n");
1502  }
1503  fwrite ($css_file, "{\n");
1504 
1505  // collect table border attributes
1506  $t_border = array();
1507 
1508  foreach($tag as $par)
1509  {
1510  $cur_par = $par["parameter"];
1511  $cur_val = $par["value"];
1512 
1513  // replace named colors
1514  if (is_int(strpos($cur_par, "color")) && substr(trim($cur_val), 0, 1) == "!")
1515  {
1516  $cur_val = $this->getColorCodeForName(substr($cur_val, 1));
1517  }
1518 
1519  if ($tag[0]["type"] == "table" && is_int(strpos($par["parameter"], "border")))
1520  {
1521  $t_border[$cur_par] = $cur_val;
1522  }
1523 
1524  if (in_array($cur_par, array("background-image", "list-style-image")))
1525  {
1526  if (is_int(strpos($cur_val, "/"))) // external
1527  {
1528  $cur_val = "url(".$cur_val.")";
1529  }
1530  else // internal
1531  {
1532  if ($a_image_dir == "")
1533  {
1534  $cur_val = "url(../sty/sty_".$this->getId()."/images/".$cur_val.")";
1535  }
1536  else
1537  {
1538  $cur_val = "url(".$a_image_dir."/".$cur_val.")";
1539  }
1540  }
1541  }
1542 
1543  if ($cur_par == "opacity")
1544  {
1545  $cur_val = ((int) $cur_val) / 100;
1546  }
1547 
1548  fwrite ($css_file, "\t".$cur_par.": ".$cur_val.";\n");
1549 
1550  // IE6 fix for minimum height
1551  if ($cur_par == "min-height")
1552  {
1553  fwrite ($css_file, "\t"."height".": "."auto !important".";\n");
1554  fwrite ($css_file, "\t"."height".": ".$cur_val.";\n");
1555  }
1556 
1557  // opacity fix
1558  if ($cur_par == "opacity")
1559  {
1560  fwrite ($css_file, "\t".'-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity='.($cur_val * 100).')"'.";\n");
1561  fwrite ($css_file, "\t".'filter: alpha(opacity='.($cur_val * 100).')'.";\n");
1562  fwrite ($css_file, "\t".'-moz-opacity: '.$cur_val.";\n");
1563  }
1564 
1565  // save page background
1566  if ($tag[0]["tag"] == "div" && $tag[0]["class"] == "Page"
1567  && $cur_par == "background-color")
1568  {
1569  $page_background = $cur_val;
1570  }
1571  }
1572  fwrite ($css_file, "}\n");
1573  fwrite ($css_file, "\n");
1574 
1575  // use table border attributes for th td as well
1576 /* if ($tag[0]["type"] == "table")
1577  {
1578  if (count($t_border) > 0)
1579  {
1580  fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]." th,".
1581  $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]." td\n");
1582  fwrite ($css_file, "{\n");
1583  foreach ($t_border as $p => $v)
1584  {
1585 // fwrite ($css_file, "\t".$p.": ".$v.";\n");
1586  }
1587  fwrite ($css_file, "}\n");
1588  fwrite ($css_file, "\n");
1589  }
1590  }*/
1591  }
1592 
1593  if ($page_background != "")
1594  {
1595  fwrite ($css_file, "td.ilc_Page\n");
1596  fwrite ($css_file, "{\n");
1597  fwrite ($css_file, "\t"."background-color: ".$page_background.";\n");
1598  fwrite ($css_file, "}\n");
1599  }
1600  fclose($css_file);
1601 
1602  $this->setUpToDate(true);
1603  $this->_writeUpToDate($this->getId(), true);
1604  }
1605 
1612  static function getEffectiveContentStyleId($a_style_id, $a_type = "")
1613  {
1614  global $ilSetting;
1615 
1616  // check global fixed content style
1617  $fixed_style = $ilSetting->get("fixed_content_style_id");
1618  if ($fixed_style > 0)
1619  {
1620  $a_style_id = $fixed_style;
1621  }
1622 
1623  // check global default style
1624  if ($a_style_id <= 0)
1625  {
1626  $a_style_id = $ilSetting->get("default_content_style_id");
1627  }
1628 
1629  if ($a_style_id > 0 && ilObject::_lookupType($a_style_id) == "sty")
1630  {
1631  return $a_style_id;
1632  }
1633 
1634  return 0;
1635  }
1636 
1643  function getParametersOfClass($a_type, $a_class)
1644  {
1645  if (is_array($this->style_class[$a_type][$a_class]))
1646  {
1647  return $this->style_class[$a_type][$a_class];
1648  }
1649  return array();
1650  }
1651 
1657  function getContentStylePath($a_style_id)
1658  {
1659  global $ilias;
1660 
1661  $rand = rand(1,999999);
1662 
1663 
1664  // check global fixed content style
1665  $fixed_style = $ilias->getSetting("fixed_content_style_id");
1666  if ($fixed_style > 0)
1667  {
1668  $a_style_id = $fixed_style;
1669  }
1670 
1671  // check global default style
1672  if ($a_style_id <= 0)
1673  {
1674  $a_style_id = $ilias->getSetting("default_content_style_id");
1675  }
1676 
1677  if ($a_style_id > 0 && ilObject::_exists($a_style_id))
1678  {
1679  // check whether file is up to date
1680  if (!ilObjStyleSheet::_lookupUpToDate($a_style_id))
1681  {
1682  $style = new ilObjStyleSheet($a_style_id);
1683  $style->writeCSSFile();
1684  }
1685 
1686  return ilUtil::getWebspaceDir("output").
1687  "/css/style_".$a_style_id.".css?dummy=$rand";
1688  }
1689  else // todo: work this out
1690  {
1691  return "./Services/COPage/css/content.css";
1692  }
1693  }
1694 
1701  {
1702  return "./Services/COPage/css/print_content.css";
1703  }
1704 
1711  {
1712  return "./Services/COPage/css/syntaxhighlight.css";
1713  }
1714 
1721  {
1722  return "./Services/COPage/css/placeholder.css";
1723  }
1724 
1725  function update()
1726  {
1727  global $ilDB;
1728 
1729  parent::update();
1730  $this->read(); // this could be done better
1731  $this->writeCSSFile();
1732 
1733  $q = "UPDATE style_data ".
1734  "SET category = ".$ilDB->quote((int) $this->getScope(), "integer").
1735  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
1736  $ilDB->manipulate($q);
1737  }
1738 
1745  function updateStyleParameter($a_id, $a_value)
1746  {
1747  global $ilDB;
1748 
1749  $q = "UPDATE style_parameter SET VALUE = ".
1750  $ilDB->quote($a_value, "text")." WHERE id = ".
1751  $ilDB->quote($a_id, "integer");
1752  $style_set = $ilDB->manipulate($q);
1753  }
1754 
1759  function replaceStylePar($a_tag, $a_class, $a_par, $a_val, $a_type)
1760  {
1761  ilObjStyleSheet::_replaceStylePar($this->getId(), $a_tag, $a_class, $a_par, $a_val, $a_type);
1762  }
1763 
1764  function _replaceStylePar($style_id, $a_tag, $a_class, $a_par, $a_val, $a_type)
1765  {
1766  global $ilDB;
1767 
1768  $q = "SELECT * FROM style_parameter WHERE ".
1769  " style_id = ".$ilDB->quote($style_id, "integer")." AND ".
1770  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1771  " class = ".$ilDB->quote($a_class, "text")." AND ".
1772  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1773  " parameter = ".$ilDB->quote($a_par, "text");
1774 
1775  $set = $ilDB->query($q);
1776 
1777  if ($rec = $set->fetchRow())
1778  {
1779  $q = "UPDATE style_parameter SET ".
1780  " value = ".$ilDB->quote($a_val, "text")." WHERE ".
1781  " style_id = ".$ilDB->quote($style_id, "integer")." AND ".
1782  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1783  " class = ".$ilDB->quote($a_class, "text")." AND ".
1784  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1785  " parameter = ".$ilDB->quote($a_par, "text");
1786 
1787  $ilDB->manipulate($q);
1788  }
1789  else
1790  {
1791  $id = $ilDB->nextId("style_parameter");
1792  $q = "INSERT INTO style_parameter (id, value, style_id, tag, class, type, parameter) VALUES ".
1793  " (".
1794  $ilDB->quote($id, "integer").",".
1795  $ilDB->quote($a_val, "text").",".
1796  " ".$ilDB->quote($this->getId(), "integer").",".
1797  " ".$ilDB->quote($a_tag, "text").",".
1798  " ".$ilDB->quote($a_class, "text").",".
1799  " ".$ilDB->quote($a_type, "text").",".
1800  " ".$ilDB->quote($a_par, "text").")";
1801 
1802  $ilDB->manipulate($q);
1803  }
1804  }
1805 
1806 
1810  function getStyle()
1811  {
1812  return $this->style;
1813  }
1814 
1818  function setStyle($a_style)
1819  {
1820  $this->style = $a_style;
1821  }
1822 
1823 
1830  function handleXmlString($a_str)
1831  {
1832  return str_replace("&", "&amp;", $a_str);
1833  }
1834 
1838  function getXML()
1839  {
1840  $xml.= "<StyleSheet>\n";
1841 
1842  // title and description
1843  $xml.= "<Title>".$this->handleXmlString($this->getTitle())."</Title>";
1844  $xml.= "<Description>".$this->handleXmlString($this->getDescription())."</Description>\n";
1845 
1846  // style classes
1847  foreach($this->chars as $char)
1848  {
1849  $xml.= "<Style Tag=\"".ilObjStyleSheet::_determineTag($char["type"]).
1850  "\" Type=\"".$char["type"]."\" Class=\"".$char["class"]."\">\n";
1851  foreach($this->style as $style)
1852  {
1853  if ($style[0]["type"] == $char["type"] && $style[0]["class"] == $char["class"])
1854  {
1855  foreach($style as $tag)
1856  {
1857  $xml.="<StyleParameter Name=\"".$tag["parameter"]."\" Value=\"".$tag["value"]."\"/>\n";
1858  }
1859  }
1860  }
1861  $xml.= "</Style>\n";
1862  }
1863 
1864  // colors
1865  foreach($this->getColors() as $color)
1866  {
1867  $xml.="<StyleColor Name=\"".$color["name"]."\" Code=\"".$color["code"]."\"/>\n";
1868  }
1869 
1870  // templates
1872  foreach ($tcts as $tct => $v)
1873  {
1874  $ts = $this->getTemplates($tct);
1875 
1876  foreach ($ts as $t)
1877  {
1878  $xml.="<StyleTemplate Type=\"".$tct."\" Name=\"".$t["name"]."\">\n";
1879  foreach ($t["classes"] as $ct => $c)
1880  {
1881  if ($c != "")
1882  {
1883  $xml.="<StyleTemplateClass ClassType=\"".$ct."\" Class=\"".$c."\"/>\n";
1884  }
1885  }
1886  $xml.="</StyleTemplate>\n";
1887  }
1888  }
1889 
1890 
1891  $xml.= "</StyleSheet>";
1892 //echo "<pre>".htmlentities($xml)."</pre>"; exit;
1893  return $xml;
1894  }
1895 
1896 
1901  {
1902  $sty_data_dir = ilUtil::getDataDir()."/sty";
1903  ilUtil::makeDir($sty_data_dir);
1904  if(!is_writable($sty_data_dir))
1905  {
1906  $this->ilias->raiseError("Style data directory (".$sty_data_dir
1907  .") not writeable.",$this->ilias->error_obj->FATAL);
1908  }
1909 
1910  $style_dir = $sty_data_dir."/sty_".$this->getId();
1911  ilUtil::makeDir($style_dir);
1912  if(!@is_dir($style_dir))
1913  {
1914  $this->ilias->raiseError("Creation of style directory failed (".
1915  $style_dir.").",$this->ilias->error_obj->FATAL);
1916  }
1917 
1918  // create export subdirectory
1919  $ex_dir = $style_dir."/export";
1920  ilUtil::makeDir($ex_dir);
1921  if(!@is_dir($ex_dir))
1922  {
1923  $this->ilias->raiseError("Creation of Import Directory failed (".
1924  $ex_dir.").",$this->ilias->error_obj->FATAL);
1925  }
1926 
1927  return $ex_dir;
1928  }
1929 
1934  {
1935  $sty_data_dir = ilUtil::getDataDir()."/sty";
1936  $style_dir = $sty_data_dir."/sty_".$this->getId();
1937  // create export subdirectory
1938  $ex_dir = $style_dir."/export";
1939 
1940  if (is_dir($ex_dir))
1941  {
1942  ilUtil::delDir($ex_dir, true);
1943  }
1944  }
1945 
1946 
1951  {
1952  $ex_dir = $this->createExportDirectory();
1953  $ex_sub_dir = $ex_dir."/".$this->getExportSubDir();
1954  ilUtil::makeDir($ex_sub_dir);
1955  if(!is_writable($ex_sub_dir))
1956  {
1957  $this->ilias->raiseError("Style data directory (".$ex_sub_dir
1958  .") not writeable.",$this->ilias->error_obj->FATAL);
1959  }
1960  $ex_sub_images_dir = $ex_sub_dir."/images";
1961  ilUtil::makeDir($ex_sub_images_dir);
1962  if(!is_writable($ex_sub_images_dir))
1963  {
1964  $this->ilias->raiseError("Style data directory (".$ex_sub_images_dir
1965  .") not writeable.",$this->ilias->error_obj->FATAL);
1966  }
1967  }
1968 
1972  function setExportSubDir($a_dir)
1973  {
1974  $this->export_sub_dir = $a_dir;
1975  }
1976 
1980  function getExportSubDir()
1981  {
1982  if ($this->export_sub_dir == "")
1983  {
1984  return "sty_".$this->getId();
1985  }
1986  else
1987  {
1988  return $this->export_sub_dir;
1989  }
1990  }
1991 
1997  function export()
1998  {
1999  $this->cleanExportDirectory();
2000  $ex_dir = $this->createExportDirectory();
2001  $this->createExportSubDirectory();
2002  $this->exportXML($ex_dir."/".$this->getExportSubDir());
2003 //echo "-".$this->getImagesDirectory()."-".$ex_dir."/".$this->getExportSubDir()."/images"."-";
2005  $ex_dir."/".$this->getExportSubDir()."/images");
2006  if (is_file($ex_dir."/".$this->getExportSubDir().".zip"))
2007  {
2008  unlink($ex_dir."/".$this->getExportSubDir().".zip");
2009  }
2010  ilUtil::zip($ex_dir."/".$this->getExportSubDir(),
2011  $ex_dir."/".$this->getExportSubDir().".zip");
2012 
2013  return $ex_dir."/".$this->getExportSubDir().".zip";
2014  }
2015 
2019  function exportXML($a_dir)
2020  {
2021  $file = $a_dir."/style.xml";
2022 
2023  // open file
2024  if (!($fp = @fopen($file,"w")))
2025  {
2026  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2027  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2028  }
2029 
2030  // set file permissions
2031  chmod($file, 0770);
2032 
2033  // write xml data into the file
2034  fwrite($fp, $this->getXML());
2035 
2036  // close file
2037  fclose($fp);
2038 
2039  }
2040 
2045  {
2046  $sty_data_dir = ilUtil::getDataDir()."/sty";
2047  ilUtil::makeDir($sty_data_dir);
2048  if(!is_writable($sty_data_dir))
2049  {
2050  $this->ilias->raiseError("Style data directory (".$sty_data_dir
2051  .") not writeable.",$this->ilias->error_obj->FATAL);
2052  }
2053 
2054  $style_dir = $sty_data_dir."/sty_".$this->getId();
2055  ilUtil::makeDir($style_dir);
2056  if(!@is_dir($style_dir))
2057  {
2058  $this->ilias->raiseError("Creation of style directory failed (".
2059  $style_dir.").",$this->ilias->error_obj->FATAL);
2060  }
2061 
2062  // create import subdirectory
2063  $im_dir = $style_dir."/import";
2064  ilUtil::makeDir($im_dir);
2065  if(!@is_dir($im_dir))
2066  {
2067  $this->ilias->raiseError("Creation of Import Directory failed (".
2068  $im_dir.").",$this->ilias->error_obj->FATAL);
2069  }
2070 
2071  return $im_dir;
2072  }
2073 
2077  function import($a_file)
2078  {
2079  parent::create();
2080 
2081  $im_dir = $this->createImportDirectory();
2082 
2083  // handle uploaded files
2084  if (is_array($a_file))
2085  {
2086  ilUtil::moveUploadedFile($a_file["tmp_name"],
2087  $a_file["name"], $im_dir."/".$a_file["name"]);
2088  $file_name = $a_file["name"];
2089  }
2090  else // handle not directly uploaded files
2091  {
2092  $pi = pathinfo($a_file);
2093  $file_name = $pi["basename"];
2094  copy($a_file, $im_dir."/".$file_name);
2095  }
2096  $file = pathinfo($file_name);
2097 
2098  // unzip file
2099  if (strtolower($file["extension"] == "zip"))
2100  {
2101  ilUtil::unzip($im_dir."/".$file_name);
2102  $subdir = basename($file["basename"],".".$file["extension"]);
2103  if (!is_dir($im_dir."/".$subdir))
2104  {
2105  $subdir = "style"; // check style subdir
2106  }
2107  $xml_file = $im_dir."/".$subdir."/style.xml";
2108  }
2109  else // handle xml file directly (old style)
2110  {
2111  $xml_file = $im_dir."/".$file_name;
2112  }
2113 
2114  // load information from xml file
2115 //echo "-$xml_file-";
2116  $this->createFromXMLFile($xml_file, true);
2117 
2118  // copy images
2119  $this->createImagesDirectory();
2120  if (is_dir($im_dir."/".$subdir."/images"))
2121  {
2122  ilUtil::rCopy($im_dir."/".$subdir."/images",
2123  $this->getImagesDirectory());
2124  }
2125 
2127  $this->read();
2128  $this->writeCSSFile();
2129  }
2130 
2134  function createFromXMLFile($a_file, $a_skip_parent_create = false)
2135  {
2136  global $ilDB;
2137 
2138  $this->is_3_10_skin = false;
2139 
2140  if (!$a_skip_parent_create)
2141  {
2142  parent::create();
2143  }
2144  include_once("./Services/Style/classes/class.ilStyleImportParser.php");
2145  $importParser = new ilStyleImportParser($a_file, $this);
2146  $importParser->startParsing();
2147 
2148  // store style parameter
2149  foreach ($this->style as $style)
2150  {
2151  foreach($style as $tag)
2152  {
2153  $id = $ilDB->nextId("style_parameter");
2154  $q = "INSERT INTO style_parameter (id,style_id, tag, class, parameter, type, value) VALUES ".
2155  "(".
2156  $ilDB->quote($id, "integer").",".
2157  $ilDB->quote($this->getId(), "integer").",".
2158  $ilDB->quote($tag["tag"], "text").",".
2159  $ilDB->quote($tag["class"], "text").",".
2160  $ilDB->quote($tag["parameter"], "text").",".
2161  $ilDB->quote($tag["type"], "text").",".
2162  $ilDB->quote($tag["value"], "text").")";
2163 //echo "<br>-$q";
2164  $ilDB->manipulate($q);
2165  }
2166  }
2167 
2168  // store characteristics
2169  $this->is_3_10_skin = true;
2170  if (is_array($this->chars))
2171  {
2172  foreach ($this->chars as $char)
2173  {
2174  if ($char["type"] != "")
2175  {
2176  $s = substr($char["class"], strlen($char["class"]) - 6);
2177  if ($s != ":hover")
2178  {
2179  $q = "INSERT INTO style_char (style_id, type, characteristic) VALUES ".
2180  "(".$ilDB->quote($this->getId(), "integer").",".
2181  $ilDB->quote($char["type"], "text").",".
2182  $ilDB->quote($char["class"], "text").")";
2183  $ilDB->manipulate($q);
2184  $this->is_3_10_skin = false;
2185  }
2186  }
2187  }
2188  }
2189 
2190  // add style_data record
2191  $q = "INSERT INTO style_data (id, uptodate) VALUES ".
2192  "(".$ilDB->quote($this->getId(), "integer").", 0)";
2193  $ilDB->manipulate($q);
2194 
2195  $this->update();
2196  $this->read();
2197 
2198  if ($this->is_3_10_skin)
2199  {
2200  $this->do_3_10_Migration();
2201  }
2202  //$this->writeCSSFile();
2203  }
2204 
2209  {
2210  $groups = array();
2211 
2212  foreach (self::$parameter as $parameter => $props)
2213  {
2214  $groups[$props["group"]][] = $parameter;
2215  }
2216  return $groups;
2217  }
2218 
2219  static function _getStyleParameterInputType($par)
2220  {
2221  $input = self::$parameter[$par]["input"];
2222  return $input;
2223  }
2224 
2225  static function _getStyleParameterSubPar($par)
2226  {
2227  $subpar = self::$parameter[$par]["subpar"];
2228  return $subpar;
2229  }
2230 
2231  static function _getStyleParameters($a_tag = "")
2232  {
2233  if ($a_tag == "")
2234  {
2235  return self::$parameter;
2236  }
2237  $par = array();
2238  foreach (self::$parameter as $k => $v)
2239  {
2240  if (is_array(self::$filtered_groups[$v["group"]]) &&
2241  !in_array($a_tag, self::$filtered_groups[$v["group"]]))
2242  {
2243  continue;
2244  }
2245  $par[$k] = $v;
2246  }
2247  return $par;
2248  }
2249 
2250  static function _getFilteredGroups()
2251  {
2252  return self::$filtered_groups;
2253  }
2254 
2255  static function _getStyleParameterNumericUnits($a_no_percentage = false)
2256  {
2257  if ($a_no_percentage)
2258  {
2259  return self::$num_unit_no_perc;
2260  }
2261  return self::$num_unit;
2262  }
2263 
2264  static function _getStyleParameterValues($par)
2265  {
2266  return self::$parameter[$par]["values"];
2267  }
2268 
2269  /*static function _getStyleTypes()
2270  {
2271  return self::$style_types;
2272  }*/
2273 
2274  static function _getStyleSuperTypes()
2275  {
2276  return self::$style_super_types;
2277  }
2278 
2279  static function _isExpandable($a_type)
2280  {
2281  return in_array($a_type, self::$expandable_types);
2282  }
2283 
2284  static function _isHideable($a_type)
2285  {
2286  return in_array($a_type, self::$hideable_types);
2287  }
2288 
2289  static function _getStyleSuperTypeForType($a_type)
2290  {
2291  foreach (self::$style_super_types as $s => $t)
2292  {
2293  if (in_array($a_type, $t))
2294  {
2295  return $s;
2296  }
2297  if ($a_type == $s)
2298  {
2299  return $s;
2300  }
2301  }
2302  }
2303 
2307  static function _getCoreStyles()
2308  {
2309  $c_styles = array();
2310  foreach (self::$core_styles as $cstyle)
2311  {
2312  $c_styles[$cstyle["type"].".".ilObjStyleSheet::_determineTag($cstyle["type"]).".".$cstyle["class"]]
2313  = array("type" => $cstyle["type"],
2314  "tag" => ilObjStyleSheet::_determineTag($cstyle["type"]),
2315  "class" => $cstyle["class"]);
2316  }
2317  return $c_styles;
2318  }
2319 
2323  static function _getTemplateClassTypes($a_template_type = "")
2324  {
2325  if ($a_template_type == "")
2326  {
2327  return self::$templates;
2328  }
2329 
2330  return self::$templates[$a_template_type];
2331  }
2332 
2333 
2334  function _getPseudoClasses($tag)
2335  {
2336  return self::$pseudo_classes[$tag];
2337  }
2338 
2340  {
2341  return self::$templates[$t][$k];
2342  }
2343 
2344  static function _determineTag($a_type)
2345  {
2346  return self::$assigned_tags[$a_type];
2347  }
2348 
2352  static function getAvailableParameters()
2353  {
2354  $pars = array();
2355  foreach(self::$parameter as $p => $v)
2356  {
2357  $pars[$p] = $v["values"];
2358  }
2359 
2360  return $pars;
2361  }
2362 
2363 
2367  static function _addMissingStyleClassesToStyle($a_id)
2368  {
2369  $styles = array(array("id" => $a_id));
2371  }
2372 
2376  static function _addMissingStyleClassesToAllStyles($a_styles = "")
2377  {
2378  global $ilDB;
2379 
2380  if ($a_styles == "")
2381  {
2382  $styles = ilObject::_getObjectsDataForType("sty");
2383  }
2384  else
2385  {
2386  $styles = $a_styles;
2387  }
2390 
2391  // get all core image files
2392  $core_images = array();
2393  $core_dir = self::$basic_style_image_dir;
2394  if (is_dir($core_dir))
2395  {
2396  $dir = opendir($core_dir);
2397  while($file = readdir($dir))
2398  {
2399  if (substr($file, 0, 1) != "." && is_file($core_dir."/".$file))
2400  {
2401  $core_images[] = $file;
2402  }
2403  }
2404  }
2405 
2406  foreach ($styles as $style)
2407  {
2408  $id = $style["id"];
2409 
2410  foreach($core_styles as $cs)
2411  {
2412  // check, whether core style class exists
2413  $set = $ilDB->queryF("SELECT * FROM style_char WHERE style_id = %s ".
2414  "AND type = %s AND characteristic = %s",
2415  array("integer", "text", "text"),
2416  array($id, $cs["type"], $cs["class"]));
2417 
2418  // if not, add core style class
2419  if (!($rec = $ilDB->fetchAssoc($set)))
2420  {
2421  $ilDB->manipulateF(
2422  "INSERT INTO style_char (style_id, type, characteristic) ".
2423  " VALUES (%s,%s,%s) ",
2424  array("integer", "text", "text"),
2425  array($id, $cs["type"], $cs["class"]));
2426 
2427  $xpath = new DOMXPath($bdom);
2428  $par_nodes = $xpath->query("/StyleSheet/Style[@Tag = '".$cs["tag"]."' and @Type='".
2429  $cs["type"]."' and @Class='".$cs["class"]."']/StyleParameter");
2430  foreach ($par_nodes as $par_node)
2431  {
2432  // check whether style parameter exists
2433  $set = $ilDB->queryF("SELECT * FROM style_parameter WHERE style_id = %s ".
2434  "AND type = %s AND class = %s AND tag = %s AND parameter = %s",
2435  array("integer", "text", "text", "text", "text"),
2436  array($id, $cs["type"], $cs["class"],
2437  $cs["tag"], $par_node->getAttribute("Name")));
2438 
2439  // if not, create style parameter
2440  if (!($rec = $ilDB->fetchAssoc($set)))
2441  {
2442  $spid = $ilDB->nextId("style_parameter");
2443  $st = $ilDB->manipulateF("INSERT INTO style_parameter (id, style_id, type, class, tag, parameter, value) ".
2444  " VALUES (%s,%s,%s,%s,%s,%s,%s)",
2445  array("integer", "integer", "text", "text", "text", "text", "text"),
2446  array($spid, $id, $cs["type"], $cs["class"], $cs["tag"],
2447  $par_node->getAttribute("Name"), $par_node->getAttribute("Value")));
2448  }
2449  }
2450  }
2451  }
2452 
2453  // now check, whether some core image files are missing
2456  reset($core_images);
2457  foreach($core_images as $cim)
2458  {
2459  if (!is_file($imdir."/".$cim))
2460  {
2461  copy($core_dir."/".$cim, $imdir."/".$cim);
2462  }
2463  }
2464  }
2465  }
2466 
2467  //
2468  // Color management
2469  //
2470 
2475  {
2476  global $ilDB;
2477 
2478  $this->do_3_9_Migration($this->getId());
2479 
2480  //include_once("./Services/Migration/DBUpdate_1385/classes/class.ilStyleMigration.php");
2481  //ilStyleMigration::addMissingStyleCharacteristics($this->getId());
2482 
2483  $this->do_3_10_CharMigration($this->getId());
2484 
2485  // style_char: type for characteristic
2486  $st = $ilDB->prepareManip("UPDATE style_char SET type = ? WHERE characteristic = ?".
2487  " AND style_id = ? ", array("text", "text", "integer"));
2488  $ilDB->execute($st, array("media_cont", "Media", $this->getId()));
2489  $ilDB->execute($st, array("media_caption", "MediaCaption", $this->getId()));
2490  $ilDB->execute($st, array("page_fn", "Footnote", $this->getId()));
2491  $ilDB->execute($st, array("page_nav", "LMNavigation", $this->getId()));
2492  $ilDB->execute($st, array("page_title", "PageTitle", $this->getId()));
2493  $ilDB->execute($st, array("page_cont", "Page", $this->getId()));
2494 
2495  // style_parameter: type for class
2496  $st = $ilDB->prepareManip("UPDATE style_parameter SET type = ? WHERE class = ?".
2497  " AND style_id = ? ", array("text", "text", "integer"));
2498  $ilDB->execute($st, array("media_cont", "Media", $this->getId()));
2499  $ilDB->execute($st, array("media_caption", "MediaCaption", $this->getId()));
2500  $ilDB->execute($st, array("page_fn", "Footnote", $this->getId()));
2501  $ilDB->execute($st, array("page_nav", "LMNavigation", $this->getId()));
2502  $ilDB->execute($st, array("page_title", "PageTitle", $this->getId()));
2503  $ilDB->execute($st, array("table", "Page", $this->getId()));
2504 
2505  $st = $ilDB->prepareManip("UPDATE style_parameter SET tag = ? WHERE class = ?".
2506  " AND style_id = ? ", array("text", "text", "integer"));
2507  $ilDB->execute($st, array("div", "MediaCaption", $this->getId()));
2508 
2509  // style_char: characteristic for characteristic
2510  $st = $ilDB->prepareManip("UPDATE style_char SET characteristic = ? WHERE characteristic = ?".
2511  " AND style_id = ? ", array("text", "text", "integer"));
2512  $ilDB->execute($st, array("MediaContainer", "Media", $this->getId()));
2513  $ilDB->execute($st, array("PageContainer", "Page", $this->getId()));
2514 
2515  // style_parameter: class for class
2516  $st = $ilDB->prepareManip("UPDATE style_parameter SET class = ? WHERE class = ?".
2517  " AND style_id = ? ", array("text", "text", "integer"));
2518  $ilDB->execute($st, array("MediaContainer", "Media", $this->getId()));
2519  $ilDB->execute($st, array("PageContainer", "Page", $this->getId()));
2520 
2521  // force rewriting of container style
2522  $st = $ilDB->prepareManip("DELETE FROM style_char WHERE type = ?".
2523  " AND style_id = ? ", array("text", "integer"));
2524  $ilDB->execute($st, array("page_cont", $this->getId()));
2525  $st = $ilDB->prepareManip("DELETE FROM style_parameter WHERE type = ?".
2526  " AND style_id = ? ", array("text", "integer"));
2527  $ilDB->execute($st, array("page_cont", $this->getId()));
2528 
2529  }
2530 
2537  function do_3_10_CharMigration($a_id = "")
2538  {
2539  global $ilDB;
2540 
2541  $add_str = "";
2542  if ($a_id != "")
2543  {
2544  $add_str = " AND style_id = ".$ilDB->quote($a_id, "integer");
2545  }
2546 
2547  $set = $ilDB->query($q = "SELECT DISTINCT style_id, tag, class FROM style_parameter WHERE ".
2548  $ilDB->equals("type", "", "text", true)." ".$add_str);
2549 
2550  while ($rec = $ilDB->fetchAssoc($set))
2551  {
2552  // derive types from tag
2553  $types = array();
2554  switch ($rec["tag"])
2555  {
2556  case "div":
2557  case "p":
2558  if (in_array($rec["class"], array("Headline3", "Headline1",
2559  "Headline2", "TableContent", "List", "Standard", "Remark",
2560  "Additional", "Mnemonic", "Citation", "Example")))
2561  {
2562  $types[] = "text_block";
2563  }
2564  if (in_array($rec["class"], array("Block", "Remark",
2565  "Additional", "Mnemonic", "Example", "Excursus", "Special")))
2566  {
2567  $types[] = "section";
2568  }
2569  if (in_array($rec["class"], array("Page", "Footnote", "PageTitle", "LMNavigation")))
2570  {
2571  $types[] = "page";
2572  }
2573  break;
2574 
2575  case "td":
2576  $types[] = "table_cell";
2577  break;
2578 
2579  case "a":
2580  if (in_array($rec["class"], array("ExtLink", "IntLink", "FootnoteLink")))
2581  {
2582  $types[] = "link";
2583  }
2584  break;
2585 
2586  case "span":
2587  $types[] = "text_inline";
2588  break;
2589 
2590  case "table":
2591  $types[] = "table";
2592  break;
2593  }
2594 
2595  // check if style_char set exists
2596  foreach ($types as $t)
2597  {
2598  // check if second type already exists
2599  $set4 = $ilDB->queryF("SELECT * FROM style_char ".
2600  " WHERE style_id = %s AND type = %s AND characteristic = %s",
2601  array("integer", "text", "text"),
2602  array($rec["style_id"], $t, $rec["class"]));
2603  if ($rec4 = $ilDB->fetchAssoc($set4))
2604  {
2605  // ok
2606  }
2607  else
2608  {
2609 //echo "<br>1-".$rec["style_id"]."-".$t."-".$rec["class"]."-";
2610  $ilDB->manipulateF("INSERT INTO style_char ".
2611  " (style_id, type, characteristic) VALUES ".
2612  " (%s,%s,%s) ",
2613  array("integer", "text", "text"),
2614  array($rec["style_id"], $t, $rec["class"]));
2615  }
2616  }
2617 
2618  // update types
2619  if ($rec["type"] == "")
2620  {
2621  if (count($types) > 0)
2622  {
2623  $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
2624  " WHERE style_id = %s AND class = %s AND ".$ilDB->equals("type", "", "text", true),
2625  array("text", "integer", "text"),
2626  array($types[0], $rec["style_id"], $rec["class"]));
2627 //echo "<br>3-".$types[0]."-".$rec["style_id"]."-".$rec["class"]."-";
2628 
2629  // links extra handling
2630  if ($types[0] == "link")
2631  {
2632  $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
2633  " WHERE style_id = %s AND (class = %s OR class = %s) AND ".$ilDB->equals("type", "", "text", true),
2634  array("text", "integer", "text", "text"),
2635  array($types[0], $rec["style_id"], $rec["class"].":visited",
2636  $rec["class"].":hover"));
2637  }
2638  }
2639 
2640  if (count($types) == 2)
2641  {
2642  // select all records of first type and add second type
2643  // records if necessary.
2644  $set2 = $ilDB->queryF("SELECT * FROM style_parameter ".
2645  " WHERE style_id = %s AND class = %s AND type = %s",
2646  array("integer", "text", "text"),
2647  array($rec["style_id"], $rec["class"], $types[0]));
2648  while ($rec2 = $ilDB->fetchAssoc($set2))
2649  {
2650  // check if second type already exists
2651  $set3 = $ilDB->queryF("SELECT * FROM style_parameter ".
2652  " WHERE style_id = %s AND tag = %s AND class = %s AND type = %s AND parameter = %s",
2653  array("integer", "text", "text", "text", "text"),
2654  array($rec["style_id"], $rec["tag"], $rec["class"], $types[1], $rec["parameter"]));
2655  if ($rec3 = $ilDB->fetchAssoc($set3))
2656  {
2657  // ok
2658  }
2659  else
2660  {
2661  $nid = $ilDB->nextId("style_parameter");
2662  $ilDB->manipulateF("INSERT INTO style_parameter ".
2663  " (id, style_id, tag, class, parameter, value, type) VALUES ".
2664  " (%s, %s,%s,%s,%s,%s,%s) ",
2665  array("integer", "integer", "text", "text", "text", "text", "text"),
2666  array($nid, $rec2["style_id"], $rec2["tag"], $rec2["class"],
2667  $rec2["parameter"], $rec2["value"], $types[1]));
2668  }
2669  }
2670  }
2671  }
2672  }
2673  }
2674 
2678  function do_3_9_Migration($a_id)
2679  {
2680  global $ilDB;
2681 
2682  $classes = array("Example", "Additional", "Citation", "Mnemonic", "Remark");
2683  $pars = array("margin-top", "margin-bottom");
2684 
2685  foreach ($classes as $curr_class)
2686  {
2687  foreach ($pars as $curr_par)
2688  {
2689  $res2 = $ilDB->queryF("SELECT id FROM style_parameter WHERE style_id = %s".
2690  " AND tag = %s AND class= %s AND parameter = %s",
2691  array("integer", "text", "text", "text"),
2692  array($a_id, "p", $curr_class, $curr_par));
2693  if ($row2 = $ilDB->fetchAssoc($res2))
2694  {
2695  $ilDB->manipulateF("UPDATE style_parameter SET value= %s WHERE id = %s",
2696  array("text", "integer"),
2697  array("10px", $row2["id"]));
2698  }
2699  else
2700  {
2701  $nid = $ilDB->nextId("style_parameter");
2702  $ilDB->manipulateF("INSERT INTO style_parameter ".
2703  "(id, style_id, tag, class, parameter,value) VALUES (%s,%s,%s,%s,%s,%s)",
2704  array("integer", "integer", "text", "text", "text", "text"),
2705  array($nid, $a_id, "div", $curr_class, $curr_par, "10px"));
2706  }
2707  }
2708  }
2709 
2710  $ilDB->manipulateF("UPDATE style_parameter SET tag = %s WHERE tag = %s and style_id = %s",
2711  array("text", "text", "integer"),
2712  array("div", "p", $a_id));
2713 
2714  }
2715 
2716 
2720  function getColors()
2721  {
2722  global $ilDB;
2723 
2724  $set = $ilDB->query("SELECT * FROM style_color WHERE ".
2725  "style_id = ".$ilDB->quote($this->getId(), "integer")." ".
2726  "ORDER BY color_name");
2727 
2728  $colors = array();
2729  while ($rec = $ilDB->fetchAssoc($set))
2730  {
2731  $colors[] = array(
2732  "name" => $rec["color_name"],
2733  "code" => $rec["color_code"]
2734  );
2735  }
2736 
2737  return $colors;
2738  }
2739 
2743  function addColor($a_name, $a_code)
2744  {
2745  global $ilDB;
2746 
2747  $ilDB->manipulate("INSERT INTO style_color (style_id, color_name, color_code)".
2748  " VALUES (".
2749  $ilDB->quote($this->getId(), "integer").",".
2750  $ilDB->quote($a_name, "text").",".
2751  $ilDB->quote($a_code, "text").
2752  ")");
2753  }
2754 
2758  function updateColor($a_name, $a_new_name, $a_code)
2759  {
2760  global $ilDB;
2761 
2762  // todo: update names in parameters as well
2763 
2764  $ilDB->manipulate("UPDATE style_color SET ".
2765  "color_name = ".$ilDB->quote($a_new_name, "text").", ".
2766  "color_code = ".$ilDB->quote($a_code, "text").
2767  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
2768  " AND color_name = ".$ilDB->quote($a_name, "text"));
2769  ilObjStyleSheet::_writeUpToDate($this->getId(), false);
2770 
2771  // rename also the name in the style parameter values
2772  if ($a_name != $a_new_name)
2773  {
2774  $set = $ilDB->query("SELECT * FROM style_parameter ".
2775  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
2776  " AND (".
2777  " parameter = ".$ilDB->quote("background-color", "text"). " OR ".
2778  " parameter = ".$ilDB->quote("color", "text"). " OR ".
2779  " parameter = ".$ilDB->quote("border-color", "text"). " OR ".
2780  " parameter = ".$ilDB->quote("border-top-color", "text"). " OR ".
2781  " parameter = ".$ilDB->quote("border-bottom-color", "text"). " OR ".
2782  " parameter = ".$ilDB->quote("border-left-color", "text"). " OR ".
2783  " parameter = ".$ilDB->quote("border-right-color", "text").
2784  ")");
2785  while ($rec = $ilDB->fetchAssoc($set))
2786  {
2787  if ($rec["value"] == "!".$a_name ||
2788  is_int(strpos($rec["value"], "!".$a_name."(")))
2789  {
2790  // parameter is based on color -> rename it
2791  $this->replaceStylePar($rec["tag"], $rec["class"],
2792  $rec["parameter"], str_replace($a_name, $a_new_name, $rec["value"]), $rec["type"]);
2793  }
2794  }
2795  }
2796  }
2797 
2801  function removeColor($a_name)
2802  {
2803  global $ilDB;
2804 
2805  $ilDB->manipulate("DELETE FROM style_color WHERE ".
2806  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2807  " color_name = ".$ilDB->quote($a_name, "text"));
2808  }
2809 
2813  function colorExists($a_color_name)
2814  {
2815  global $ilDB;
2816 
2817  $set = $ilDB->query("SELECT * FROM style_color WHERE ".
2818  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2819  "color_name = ".$ilDB->quote($a_color_name, "text"));
2820  if ($rec = $ilDB->fetchAssoc($set))
2821  {
2822  return true;
2823  }
2824  return false;
2825  }
2826 
2830  function getColorCodeForName($a_name)
2831  {
2832  global $ilDB;
2833 
2834  $pos = strpos($a_name, "(");
2835  if ($pos > 0)
2836  {
2837  $a_i = substr($a_name, $pos + 1);
2838  $a_i = str_replace(")", "", $a_i);
2839  $a_name = substr($a_name, 0, $pos);
2840  }
2841 
2842  $set = $ilDB->query("SELECT color_code FROM style_color WHERE ".
2843  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2844  " color_name = ".$ilDB->quote($a_name, "text"));
2845  if ($rec = $ilDB->fetchAssoc($set))
2846  {
2847  if ($a_i == "")
2848  {
2849  return "#".$rec["color_code"];
2850  }
2851  else
2852  {
2853  return "#".ilObjStyleSheet::_getColorFlavor($rec["color_code"],
2854  (int) $a_i);
2855  }
2856  }
2857  }
2858 
2862  static function _getColorFlavor($a_rgb, $a_i)
2863  {
2864  $rgb = ilObjStyleSheet::_explodeRGB($a_rgb, true);
2865  $hls = ilObjStyleSheet::_RGBToHLS($rgb);
2866 
2867  if ($a_i > 0)
2868  {
2869  $hls["l"] = $hls["l"] + ((255 - $hls["l"]) * ($a_i / 100));
2870  }
2871  if ($a_i < 0)
2872  {
2873  $hls["l"] = $hls["l"] - (($hls["l"]) * (-$a_i / 100));
2874  }
2875 
2876  $rgb = ilObjStyleSheet::_HLSToRGB($hls);
2877 
2878  foreach ($rgb as $k => $v)
2879  {
2880  $rgb[$k] = str_pad(dechex($v), 2, "0", STR_PAD_LEFT);
2881  }
2882 
2883  return $rgb["r"].$rgb["g"].$rgb["b"];
2884  }
2885 
2889  static function _explodeRGB($a_rgb, $as_dec = false)
2890  {
2891  $r["r"] = substr($a_rgb, 0, 2);
2892  $r["g"] = substr($a_rgb, 2, 2);
2893  $r["b"] = substr($a_rgb, 4, 2);
2894 
2895  if ($as_dec)
2896  {
2897  $r["r"] = (int) hexdec($r["r"]);
2898  $r["g"] = (int) hexdec($r["g"]);
2899  $r["b"] = (int) hexdec($r["b"]);
2900  }
2901 
2902  return $r;
2903  }
2904 
2908  static function _RGBToHLS($a_rgb)
2909  {
2910  $r = $a_rgb["r"] / 255;
2911  $g = $a_rgb["g"] / 255;
2912  $b = $a_rgb["b"] / 255;
2913 
2914  // max / min
2915  $max = max($r,$g,$b);
2916  $min = min($r,$g,$b);
2917 
2918  //lightness
2919  $l = ($max + $min) / 2;
2920 
2921  if ($max == $min)
2922  {
2923  $s = 0;
2924  $h = 0;
2925  }
2926  else
2927  {
2928  if ($l < 0.5)
2929  {
2930  $s = ($max - $min) / ($max + $min);
2931  }
2932  else
2933  {
2934  $s = ($max - $min) / (2.0 - $max - $min);
2935  }
2936 
2937  if ($r == $max)
2938  {
2939  $h = ($g - $b) / ($max - $min);
2940  }
2941  else if ($g == $max)
2942  {
2943  $h = 2.0 + ($b - $r) / ($max - $min);
2944  }
2945  else if ($b == $max)
2946  {
2947  $h = 4.0 + ($r - $g) / ($max - $min);
2948  }
2949  }
2950 
2951  $hls["h"] = round(($h / 6) * 255);
2952  $hls["l"] = round($l * 255);
2953  $hls["s"] = round($s * 255);
2954 
2955  return $hls;
2956  }
2957 
2961  static function _HLSToRGB($a_hls)
2962  {
2963  $h = $a_hls["h"] / 255;
2964  $l = $a_hls["l"] / 255;
2965  $s = $a_hls["s"] / 255;
2966 
2967  $rgb["r"] = $rgb["g"] = $rgb["b"] = 0;
2968 
2969  // If S=0, define R, G, and B all to L
2970  if ($s == 0)
2971  {
2972  $rgb["r"] = $rgb["g"] = $rgb["b"] = $l;
2973  }
2974  else
2975  {
2976 
2977  if ($l < 0.5)
2978  {
2979  $temp2 = $l * (1.0 + $s);
2980  }
2981  else
2982  {
2983  $temp2 = $l + $s - $l * $s;
2984  }
2985 
2986  $temp1 = 2.0 * $l - $temp2;
2987 
2988 
2989  # For each of R, G, B, compute another temporary value, temp3, as follows:
2990  foreach ($rgb as $k => $v)
2991  {
2992  switch ($k)
2993  {
2994  case "r":
2995  $temp3 = $h + 1.0 / 3.0;
2996  break;
2997 
2998  case "g":
2999  $temp3 = $h;
3000  break;
3001 
3002  case "b":
3003  $temp3 = $h - 1.0/3.0;
3004  break;
3005  }
3006  if ($temp3 < 0)
3007  {
3008  $temp3 = $temp3 + 1.0;
3009  }
3010  if ($temp3 > 1)
3011  {
3012  $temp3 = $temp3 - 1.0;
3013  }
3014 
3015  if (6.0 * $temp3 < 1)
3016  {
3017  $rgb[$k] = $temp1 + ($temp2 - $temp1) * 6.0 * $temp3;
3018  }
3019  else if (2.0 * $temp3 < 1)
3020  {
3021  $rgb[$k] = $temp2;
3022  }
3023  else if (3.0 * $temp3 < 2)
3024  {
3025  $rgb[$k] = $temp1 + ($temp2 - $temp1) * ((2.0/3.0) - $temp3) * 6.0;
3026  }
3027  else
3028  {
3029  $rgb[$k] = $temp1;
3030  }
3031  }
3032  }
3033 
3034  $rgb["r"] = round($rgb["r"] * 255);
3035  $rgb["g"] = round($rgb["g"] * 255);
3036  $rgb["b"] = round($rgb["b"] * 255);
3037 
3038  return $rgb;
3039  }
3040 
3041  //
3042  // Table template management
3043  //
3044 
3048  function getTemplates($a_type)
3049  {
3050  global $ilDB;
3051 
3052  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3053  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3054  "temp_type = ".$ilDB->quote($a_type, "text")." ".
3055  "ORDER BY name");
3056 
3057  $templates = array();
3058  while ($rec = $ilDB->fetchAssoc($set))
3059  {
3060  $rec["classes"] = $this->getTemplateClasses($rec["id"]);
3061  $templates[] = $rec;
3062  }
3063 
3064  return $templates;
3065  }
3066 
3070  function getTemplateClasses($a_tid)
3071  {
3072  global $ilDB;
3073  $set = $ilDB->query("SELECT * FROM style_template_class WHERE ".
3074  "template_id = ".$ilDB->quote($a_tid, "integer"));
3075 
3076  $class = array();
3077  while ($rec = $ilDB->fetchAssoc($set))
3078  {
3079  $key = $rec["class_type"];
3080  $class[$key] = $rec["class"];
3081  }
3082 
3083  return $class;
3084  }
3085 
3086 
3090  function addTemplate($a_type, $a_name, $a_classes)
3091  {
3092  global $ilDB;
3093 
3094  $tid = $ilDB->nextId("style_template");
3095  $ilDB->manipulate($q = "INSERT INTO style_template ".
3096  "(id, style_id, name, temp_type)".
3097  " VALUES (".
3098  $ilDB->quote($tid, "integer").",".
3099  $ilDB->quote($this->getId(), "integer").",".
3100  $ilDB->quote($a_name, "text").",".
3101  $ilDB->quote($a_type, "text").
3102  ")");
3103 
3104  foreach ($a_classes as $t => $c)
3105  {
3106  $ilDB->manipulate($q = "INSERT INTO style_template_class ".
3107  "(template_id, class_type, class)".
3108  " VALUES (".
3109  $ilDB->quote($tid, "integer").",".
3110  $ilDB->quote($t, "text").",".
3111  $ilDB->quote($c, "text").
3112  ")");
3113  }
3114 
3115  include_once("./Services/Style/classes/class.ilObjStyleSheetGUI.php");
3116  $this->writeTemplatePreview($tid,
3117  ilObjStyleSheetGUI::_getTemplatePreview($this, $a_type, $tid, true));
3118 
3119  return $tid;
3120  }
3121 
3125  function updateTemplate($a_t_id, $a_name, $a_classes)
3126  {
3127  global $ilDB;
3128 
3129  $ilDB->manipulate("UPDATE style_template SET ".
3130  "name = ".$ilDB->quote($a_name, "text").
3131  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3132 
3133  $ilDB->manipulate("DELETE FROM style_template_class WHERE ".
3134  "template_id = ".$ilDB->quote($a_t_id, "integer")
3135  );
3136  foreach ($a_classes as $t => $c)
3137  {
3138  $ilDB->manipulate($q = "INSERT INTO style_template_class ".
3139  "(template_id, class_type, class)".
3140  " VALUES (".
3141  $ilDB->quote($a_t_id, "integer").",".
3142  $ilDB->quote($t, "text").",".
3143  $ilDB->quote($c, "text").
3144  ")");
3145  }
3146 
3147  }
3148 
3152  function templateExists($a_template_name)
3153  {
3154  global $ilDB;
3155 
3156  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3157  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3158  "name = ".$ilDB->quote($a_template_name, "text"));
3159  if ($rec = $ilDB->fetchAssoc($set))
3160  {
3161  return true;
3162  }
3163  return false;
3164  }
3165 
3169  function getTemplate($a_t_id)
3170  {
3171  global $ilDB;
3172 
3173  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3174  "style_id = ".$ilDB->quote($this->getId(), "integer")." ".
3175  " AND id = ".$ilDB->quote($a_t_id, "integer"));
3176 
3177  if ($rec = $ilDB->fetchAssoc($set))
3178  {
3179  $rec["classes"] = $this->getTemplateClasses($rec["id"]);
3180 
3181  $template = $rec;
3182  return $template;
3183  }
3184  return array();
3185  }
3186 
3190  function lookupTemplateName($a_t_id)
3191  {
3192  global $ilDB;
3193 
3194  $set = $ilDB->query("SELECT name FROM style_template WHERE ".
3195  " id = ".$ilDB->quote($a_t_id, "integer"));
3196 
3197  if ($rec = $ilDB->fetchAssoc($set))
3198  {
3199  return $rec["name"];
3200  }
3201 
3202  return false;
3203  }
3204 
3208  function getTemplateXML()
3209  {
3210  global $ilDB;
3211 
3212  $tag = "<StyleTemplates>";
3213 
3214  $ttypes = array("table", "vaccordion", "haccordion");
3215 
3216  foreach ($ttypes as $ttype)
3217  {
3218  $ts = $this->getTemplates($ttype);
3219 
3220  foreach($ts as $t)
3221  {
3223  /*$atts = array("table" => "TableClass",
3224  "caption" => "CaptionClass",
3225  "row_head" => "RowHeadClass",
3226  "row_foot" => "RowFootClass",
3227  "col_head" => "ColHeadClass",
3228  "col_foot" => "ColFootClass",
3229  "odd_row" => "OddRowClass",
3230  "even_row" => "EvenRowClass",
3231  "odd_col" => "OddColClass",
3232  "even_col" => "EvenColClass");*/
3233  $c = $t["classes"];
3234 
3235  $tag.= '<StyleTemplate Name="'.$t["name"].'">';
3236 
3237  foreach ($atts as $type => $t)
3238  {
3239  if ($c[$type] != "")
3240  {
3241  $tag.= '<StyleClass Type="'.$type.'" Value="'.$c[$type].'" />';
3242  }
3243  }
3244 
3245  $tag.= "</StyleTemplate>";
3246  }
3247  }
3248 
3249  $tag.= "</StyleTemplates>";
3250 
3251 //echo htmlentities($tag);
3252  return $tag;
3253  }
3254 
3258  function writeTemplatePreview($a_t_id, $a_preview_html)
3259  {
3260  global $ilDB;
3261  $a_preview_html = str_replace(' width=""', "", $a_preview_html);
3262  $a_preview_html = str_replace(' valign="top"', "", $a_preview_html);
3263  $a_preview_html = str_replace('<div class="ilc_text_block_TableContent">', "<div>", $a_preview_html);
3264 //echo "1-".strlen($a_preview_html)."-";
3265 //echo htmlentities($a_preview_html);
3266  if (strlen($a_preview_html) > 4000)
3267  {
3268 //echo "2";
3269  $a_preview_html = "";
3270  }
3271  $ilDB->manipulate("UPDATE style_template SET ".
3272  "preview = ".$ilDB->quote($a_preview_html, "text").
3273  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3274  }
3275 
3279  function lookupTemplatePreview($a_t_id)
3280  {
3281  global $ilDB;
3282 
3283  $set = $ilDB->query("SELECT preview FROM style_template ".
3284  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3285  if ($rec = $ilDB->fetchAssoc($set))
3286  {
3287  return $rec["preview"];
3288  }
3289 
3290  return "";
3291  }
3292 
3296  static function _lookupTemplateIdByName($a_style_id, $a_name)
3297  {
3298  global $ilDB;
3299 
3300  $set = $ilDB->query("SELECT id FROM style_template ".
3301  " WHERE style_id = ".$ilDB->quote($a_style_id, "integer").
3302  " AND name = ".$ilDB->quote($a_name, "text"));
3303  if ($rec = $ilDB->fetchAssoc($set))
3304  {
3305  return $rec["id"];
3306  }
3307 
3308  return false;
3309  }
3310 
3314  function removeTemplate($a_t_id)
3315  {
3316  global $ilDB;
3317 
3318  $ilDB->manipulate("DELETE FROM style_template WHERE ".
3319  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3320  " id = ".$ilDB->quote($a_t_id, "integer"));
3321 
3322  $ilDB->manipulate("DELETE FROM style_template_class WHERE ".
3323  "template_id = ".$ilDB->quote($a_t_id, "integer")
3324  );
3325 
3326  }
3327 
3331  function writeStyleSetting($a_name, $a_value)
3332  {
3333  global $ilDB;
3334 
3335  $ilDB->manipulate("DELETE FROM style_setting WHERE ".
3336  " style_id = ".$ilDB->quote($this->getId(), "integer").
3337  " AND name = ".$ilDB->quote($a_name, "text")
3338  );
3339 
3340  $ilDB->manipulate("INSERT INTO style_setting ".
3341  "(style_id, name, value) VALUES (".
3342  $ilDB->quote($this->getId(), "integer").",".
3343  $ilDB->quote($a_name, "text").",".
3344  $ilDB->quote($a_value, "text").
3345  ")");
3346  }
3347 
3351  function lookupStyleSetting($a_name)
3352  {
3353  global $ilDB;
3354 
3355  $set = $ilDB->query("SELECT value FROM style_setting ".
3356  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
3357  " AND name = ".$ilDB->quote($a_name, "text")
3358  );
3359  $rec = $ilDB->fetchAssoc($set);
3360 
3361  return $rec["value"];
3362  }
3363 
3367  static function writeStyleUsage($a_obj_id, $a_style_id)
3368  {
3369  global $ilDB;
3370 
3371  $ilDB->replace("style_usage", array(
3372  "obj_id" => array("integer", (int) $a_obj_id)),
3373  array(
3374  "style_id" => array("integer", (int) $a_style_id))
3375  );
3376  }
3377 
3381  static function lookupObjectStyle($a_obj_id)
3382  {
3383  global $ilDB;
3384 
3385  $set = $ilDB->query("SELECT style_id FROM style_usage ".
3386  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")
3387  );
3388  $rec = $ilDB->fetchAssoc($set);
3389 
3390  return (int) $rec["style_id"];
3391  }
3392 
3393 
3394 }
3395 ?>