ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjStyleSheet.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
25 require_once "./classes/class.ilObject.php";
26 
36 {
37  var $style;
38 
39 
46  function ilObjStyleSheet($a_id = 0, $a_call_by_reference = false)
47  {
48  $this->type = "sty";
49  $this->style = array();
50  if($a_call_by_reference)
51  {
52  $this->ilias->raiseError("Can't instantiate style object via reference id.",$this->ilias->error_obj->FATAL);
53  }
54 
55  parent::ilObject($a_id, false);
56  }
57 
58  function setRefId()
59  {
60  $this->ilias->raiseError("Operation ilObjStyleSheet::setRefId() not allowed.",$this->ilias->error_obj->FATAL);
61  }
62 
63  function getRefId()
64  {
65  return "";
66  //$this->ilias->raiseError("Operation ilObjStyleSheet::getRefId() not allowed.",$this->ilias->error_obj->FATAL);
67  }
68 
69  function putInTree()
70  {
71  $this->ilias->raiseError("Operation ilObjStyleSheet::putInTree() not allowed.",$this->ilias->error_obj->FATAL);
72  }
73 
74  function createReference()
75  {
76  $this->ilias->raiseError("Operation ilObjStyleSheet::createReference() not allowed.",$this->ilias->error_obj->FATAL);
77  }
78 
79  function setUpToDate($a_up_to_date = true)
80  {
81  $this->up_to_date = $a_up_to_date;
82  }
83 
84  function getUpToDate()
85  {
86  return $this->up_to_date;
87  }
88 
89  function setScope($a_scope)
90  {
91  $this->scope = $a_scope;
92  }
93 
94  function getScope()
95  {
96  return $this->scope;
97  }
98 
99  function _writeUpToDate($a_id, $a_up_to_date)
100  {
101  global $ilDB;
102 
103  $q = "UPDATE style_data SET uptodate = ".$ilDB->quote((int) $a_up_to_date).
104  " WHERE id = ".$ilDB->quote($a_id);
105  $ilDB->query($q);
106  }
107 
111  function _lookupUpToDate($a_id)
112  {
113  global $ilDB;
114 
115  $q = "SELECT * FROM style_data ".
116  " WHERE id = ".$ilDB->quote($a_id);
117  $res = $ilDB->query($q);
118  $sty = $res->fetchRow(DB_FETCHMODE_ASSOC);
119 
120  return (boolean) $sty["uptodate"];
121  }
122 
126  function _writeStandard($a_id, $a_std)
127  {
128  global $ilDB;
129 
130  $q = "UPDATE style_data SET standard = ".$ilDB->quote((int) $a_std).
131  " WHERE id = ".$ilDB->quote($a_id);
132  $ilDB->query($q);
133  }
134 
138  function _writeScope($a_id, $a_scope)
139  {
140  global $ilDB;
141 
142  $q = "UPDATE style_data SET category = ".$ilDB->quote((int) $a_scope).
143  " WHERE id = ".$ilDB->quote($a_id);
144  $ilDB->query($q);
145  }
146 
150  function _lookupStandard($a_id)
151  {
152  global $ilDB;
153 
154  $q = "SELECT * FROM style_data ".
155  " WHERE id = ".$ilDB->quote($a_id);
156  $res = $ilDB->query($q);
157  $sty = $res->fetchRow(DB_FETCHMODE_ASSOC);
158 
159  return (boolean) $sty["standard"];
160  }
161 
165  function _writeActive($a_id, $a_active)
166  {
167  global $ilDB;
168 
169  $q = "UPDATE style_data SET active = ".$ilDB->quote((int) $a_active).
170  " WHERE id = ".$ilDB->quote($a_id);
171  $ilDB->query($q);
172  }
173 
177  function _lookupActive($a_id)
178  {
179  global $ilDB;
180 
181  $q = "SELECT * FROM style_data ".
182  " WHERE id = ".$ilDB->quote($a_id);
183  $res = $ilDB->query($q);
184  $sty = $res->fetchRow(DB_FETCHMODE_ASSOC);
185 
186  return (boolean) $sty["active"];
187  }
188 
192  function _getStandardStyles($a_exclude_default_style = false,
193  $a_include_deactivated = false, $a_scope = 0)
194  {
195  global $ilDB, $ilias, $tree;
196 
197  $default_style = $ilias->getSetting("default_content_style_id");
198 
199  $and_str = "";
200  if (!$a_include_deactivated)
201  {
202  $and_str = " AND active = 1";
203  }
204 
205  $q = "SELECT * FROM style_data ".
206  " WHERE standard = 1".$and_str;
207  $res = $ilDB->query($q);
208  $styles = array();
209  while($sty = $res->fetchRow(DB_FETCHMODE_ASSOC))
210  {
211  if (!$a_exclude_default_style || $default_style != $sty["id"])
212  {
213  // check scope
214  if ($a_scope > 0 && $sty["category"] > 0)
215  {
216  if ($tree->isInTree($sty["category"]) &&
217  $tree->isInTree($a_scope))
218  {
219  $path = $tree->getPathId($a_scope);
220  if (!in_array($sty["category"], $path))
221  {
222  continue;
223  }
224  }
225  }
226  $styles[$sty["id"]] = ilObject::_lookupTitle($sty["id"]);
227  }
228  }
229 
230  return $styles;
231  }
232 
233 
240  {
241  global $ilAccess, $ilDB;
242 
243  $clonable_styles = array();
244 
245  $q = "SELECT * FROM style_data, object_data ".
246  " WHERE object_data.obj_id = style_data.id ";
247  $style_set = $ilDB->query($q);
248  while($style_rec = $style_set->fetchRow(DB_FETCHMODE_ASSOC))
249  {
250  $clonable = false;
251  if ($style_rec["standard"] == 1)
252  {
253  if ($style_rec["active"] == 1)
254  {
255  $clonable = true;
256  }
257  }
258  else
259  {
260  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
261  $obj_ids = ilObjContentObject::_lookupContObjIdByStyleId($style_rec["id"]);
262  foreach($obj_ids as $id)
263  {
264  $ref = ilObject::_getAllReferences($id);
265  foreach($ref as $ref_id)
266  {
267  if ($ilAccess->checkAccess("write", "", $ref_id))
268  {
269  $clonable = true;
270  }
271  }
272  }
273  }
274  if ($clonable)
275  {
276  $clonable_styles[$style_rec["id"]] =
277  $style_rec["title"];
278  }
279  }
280  return $clonable_styles;
281  }
282 
286  function assignMetaData(&$a_meta_data)
287  {
288  $this->meta_data =& $a_meta_data;
289  }
290 
294  function &getMetaData()
295  {
296  return $this->meta_data;
297  }
298 
299  function create($a_from_style = 0)
300  {
301  global $ilDB;
302 
303  parent::create();
304 
305  if ($a_from_style == 0)
306  {
307  $def = array(
308  array("tag" => "div", "class" => "PageTitle", "parameter" => "margin-top" ,"value" => "5px"),
309  array("tag" => "div", "class" => "PageTitle", "parameter" => "margin-bottom" ,"value" => "20px"),
310  array("tag" => "div", "class" => "PageTitle", "parameter" => "font-size" ,"value" => "140%"),
311  array("tag" => "div", "class" => "PageTitle", "parameter" => "padding-bottom" ,"value" => "3px"),
312  array("tag" => "div", "class" => "PageTitle", "parameter" => "border-bottom-width" ,"value" => "1px"),
313  array("tag" => "div", "class" => "PageTitle", "parameter" => "border-bottom-style" ,"value" => "solid"),
314  array("tag" => "div", "class" => "PageTitle", "parameter" => "border-color" ,"value" => "#000000"),
315 
316  array("tag" => "span", "class" => "Strong", "parameter" => "font-weight" ,"value" => "bold"),
317  array("tag" => "span", "class" => "Emph", "parameter" => "font-style" ,"value" => "italic"),
318  array("tag" => "span", "class" => "Comment", "parameter" => "color" ,"value" => "green"),
319  array("tag" => "span", "class" => "Quotation", "parameter" => "color" ,"value" => "brown"),
320  array("tag" => "span", "class" => "Quotation", "parameter" => "font-style" ,"value" => "italic"),
321 
322  array("tag" => "a", "class" => "FootnoteLink", "parameter" => "color" ,"value" => "blue"),
323  array("tag" => "a", "class" => "FootnoteLink", "parameter" => "font-weight" ,"value" => "normal"),
324  array("tag" => "a", "class" => "FootnoteLink:hover", "parameter" => "color" ,"value" => "#000000"),
325  array("tag" => "div", "class" => "Footnote", "parameter" => "margin-top" ,"value" => "5px"),
326  array("tag" => "div", "class" => "Footnote", "parameter" => "margin-bottom" ,"value" => "5px"),
327  array("tag" => "div", "class" => "Footnote", "parameter" => "font-style" ,"value" => "italic"),
328 
329  array("tag" => "a", "class" => "IntLink", "parameter" => "color" ,"value" => "blue"),
330  array("tag" => "a", "class" => "IntLink:visited", "parameter" => "color" ,"value" => "blue"),
331  array("tag" => "a", "class" => "IntLink", "parameter" => "font-weight" ,"value" => "normal"),
332  array("tag" => "a", "class" => "IntLink", "parameter" => "text-decoration" ,"value" => "underline"),
333  array("tag" => "a", "class" => "IntLink:hover", "parameter" => "color" ,"value" => "#000000"),
334 
335  array("tag" => "a", "class" => "ExtLink", "parameter" => "color" ,"value" => "blue"),
336  array("tag" => "a", "class" => "ExtLink:visited", "parameter" => "color" ,"value" => "blue"),
337  array("tag" => "a", "class" => "ExtLink", "parameter" => "font-weight" ,"value" => "normal"),
338  array("tag" => "a", "class" => "ExtLink", "parameter" => "text-decoration" ,"value" => "underline"),
339  array("tag" => "a", "class" => "ExtLink:hover", "parameter" => "color" ,"value" => "#000000"),
340 
341  array("tag" => "div", "class" => "LMNavigation", "parameter" => "background-color" ,"value" => "#EEEEEE"),
342  array("tag" => "div", "class" => "LMNavigation", "parameter" => "border-style" ,"value" => "outset"),
343  array("tag" => "div", "class" => "LMNavigation", "parameter" => "border-color" ,"value" => "#EEEEEE"),
344  array("tag" => "div", "class" => "LMNavigation", "parameter" => "border-width" ,"value" => "1px"),
345  array("tag" => "div", "class" => "Page", "parameter" => "background-color" ,"value" => "#FFFFFF"),
346  array("tag" => "div", "class" => "Page", "parameter" => "padding" ,"value" => "0px"),
347  array("tag" => "div", "class" => "Page", "parameter" => "margin" ,"value" => "0px"),
348  array("tag" => "td", "class" => "Cell1", "parameter" => "background-color" ,"value" => "#FFCCCC"),
349  array("tag" => "td", "class" => "Cell2", "parameter" => "background-color" ,"value" => "#CCCCFF"),
350  array("tag" => "td", "class" => "Cell3", "parameter" => "background-color" ,"value" => "#CCFFCC"),
351  array("tag" => "td", "class" => "Cell4", "parameter" => "background-color" ,"value" => "#FFFFCC"),
352 
353  array("tag" => "div", "class" => "Standard", "parameter" => "margin-top" ,"value" => "10px"),
354  array("tag" => "div", "class" => "Standard", "parameter" => "margin-bottom" ,"value" => "10px"),
355 
356  array("tag" => "div", "class" => "List", "parameter" => "margin-top" ,"value" => "3px"),
357  array("tag" => "div", "class" => "List", "parameter" => "margin-bottom" ,"value" => "3px"),
358 
359  array("tag" => "div", "class" => "Headline1", "parameter" => "margin-top" ,"value" => "20px"),
360  array("tag" => "div", "class" => "Headline1", "parameter" => "margin-bottom" ,"value" => "10px"),
361  array("tag" => "div", "class" => "Headline1", "parameter" => "font-size" ,"value" => "140%"),
362 
363  array("tag" => "div", "class" => "Headline2", "parameter" => "margin-top" ,"value" => "20px"),
364  array("tag" => "div", "class" => "Headline2", "parameter" => "margin-bottom" ,"value" => "10px"),
365  array("tag" => "div", "class" => "Headline2", "parameter" => "font-size" ,"value" => "130%"),
366 
367  array("tag" => "div", "class" => "Headline3", "parameter" => "margin-top" ,"value" => "20px"),
368  array("tag" => "div", "class" => "Headline3", "parameter" => "margin-bottom" ,"value" => "10px"),
369  array("tag" => "div", "class" => "Headline3", "parameter" => "font-size" ,"value" => "120%"),
370 
371  array("tag" => "div", "class" => "Example", "parameter" => "padding-left" ,"value" => "20px"),
372  array("tag" => "div", "class" => "Example", "parameter" => "border-left-width" ,"value" => "3px"),
373  array("tag" => "div", "class" => "Example", "parameter" => "border-left-style" ,"value" => "solid"),
374  array("tag" => "div", "class" => "Example", "parameter" => "border-left-color" ,"value" => "blue"),
375  array("tag" => "div", "class" => "Example", "parameter" => "margin-top" ,"value" => "10px"),
376  array("tag" => "div", "class" => "Example", "parameter" => "margin-bottom" ,"value" => "10px"),
377 
378  array("tag" => "div", "class" => "Citation", "parameter" => "color" ,"value" => "brown"),
379  array("tag" => "div", "class" => "Citation", "parameter" => "font-style" ,"value" => "italic"),
380  array("tag" => "div", "class" => "Citation", "parameter" => "margin-top" ,"value" => "10px"),
381  array("tag" => "div", "class" => "Citation", "parameter" => "margin-bottom" ,"value" => "10px"),
382 
383  array("tag" => "div", "class" => "Mnemonic", "parameter" => "margin-left" ,"value" => "20px"),
384  array("tag" => "div", "class" => "Mnemonic", "parameter" => "margin-right" ,"value" => "20px"),
385  array("tag" => "div", "class" => "Mnemonic", "parameter" => "padding" ,"value" => "10px"),
386  array("tag" => "div", "class" => "Mnemonic", "parameter" => "border-width" ,"value" => "2px"),
387  array("tag" => "div", "class" => "Mnemonic", "parameter" => "border-style" ,"value" => "solid"),
388  array("tag" => "div", "class" => "Mnemonic", "parameter" => "border-color" ,"value" => "red"),
389  array("tag" => "div", "class" => "Mnemonic", "parameter" => "margin-top" ,"value" => "10px"),
390  array("tag" => "div", "class" => "Mnemonic", "parameter" => "margin-bottom" ,"value" => "10px"),
391 
392  array("tag" => "div", "class" => "Additional", "parameter" => "padding" ,"value" => "10px"),
393  array("tag" => "div", "class" => "Additional", "parameter" => "border-width" ,"value" => "1px"),
394  array("tag" => "div", "class" => "Additional", "parameter" => "border-style" ,"value" => "solid"),
395  array("tag" => "div", "class" => "Additional", "parameter" => "border-color" ,"value" => "blue"),
396  array("tag" => "div", "class" => "Additional", "parameter" => "margin-top" ,"value" => "10px"),
397  array("tag" => "div", "class" => "Additional", "parameter" => "margin-bottom" ,"value" => "10px"),
398 
399  array("tag" => "div", "class" => "Remark", "parameter" => "padding" ,"value" => "10px"),
400  array("tag" => "div", "class" => "Remark", "parameter" => "border-width" ,"value" => "1px"),
401  array("tag" => "div", "class" => "Remark", "parameter" => "border-style" ,"value" => "solid"),
402  array("tag" => "div", "class" => "Remark", "parameter" => "border-color" ,"value" => "#909090"),
403  array("tag" => "div", "class" => "Remark", "parameter" => "background-color" ,"value" => "#D0D0D0"),
404  array("tag" => "div", "class" => "Remark", "parameter" => "text-align" ,"value" => "center"),
405  array("tag" => "div", "class" => "Remark", "parameter" => "margin-top" ,"value" => "10px"),
406  array("tag" => "div", "class" => "Remark", "parameter" => "margin-bottom" ,"value" => "10px"),
407 
408  array("tag" => "div", "class" => "Block", "parameter" => "padding-left" ,"value" => "10px"),
409  array("tag" => "div", "class" => "Block", "parameter" => "padding-right" ,"value" => "10px"),
410  array("tag" => "div", "class" => "Block", "parameter" => "padding-top" ,"value" => "5px"),
411  array("tag" => "div", "class" => "Block", "parameter" => "padding-bottom" ,"value" => "5px"),
412  array("tag" => "div", "class" => "Block", "parameter" => "border-width" ,"value" => "1px"),
413  array("tag" => "div", "class" => "Block", "parameter" => "border-style" ,"value" => "solid"),
414  array("tag" => "div", "class" => "Block", "parameter" => "border-color" ,"value" => "#A0A0A0"),
415  array("tag" => "div", "class" => "Block", "parameter" => "background-color" ,"value" => "#FFFFFF"),
416  array("tag" => "div", "class" => "Block", "parameter" => "margin-top" ,"value" => "10px"),
417  array("tag" => "div", "class" => "Block", "parameter" => "margin-bottom" ,"value" => "10px"),
418 
419  array("tag" => "div", "class" => "Special", "parameter" => "padding-left" ,"value" => "10px"),
420  array("tag" => "div", "class" => "Special", "parameter" => "padding-right" ,"value" => "10px"),
421  array("tag" => "div", "class" => "Special", "parameter" => "padding-top" ,"value" => "5px"),
422  array("tag" => "div", "class" => "Special", "parameter" => "padding-bottom" ,"value" => "5px"),
423  array("tag" => "div", "class" => "Special", "parameter" => "border-width" ,"value" => "1px"),
424  array("tag" => "div", "class" => "Special", "parameter" => "border-style" ,"value" => "solid"),
425  array("tag" => "div", "class" => "Special", "parameter" => "border-color" ,"value" => "#A0A0A0"),
426  array("tag" => "div", "class" => "Special", "parameter" => "background-color" ,"value" => "#FFF7F7"),
427  array("tag" => "div", "class" => "Special", "parameter" => "margin-top" ,"value" => "10px"),
428  array("tag" => "div", "class" => "Special", "parameter" => "margin-bottom" ,"value" => "10px"),
429 
430  array("tag" => "div", "class" => "Excursus", "parameter" => "padding-left" ,"value" => "10px"),
431  array("tag" => "div", "class" => "Excursus", "parameter" => "padding-right" ,"value" => "10px"),
432  array("tag" => "div", "class" => "Excursus", "parameter" => "padding-top" ,"value" => "5px"),
433  array("tag" => "div", "class" => "Excursus", "parameter" => "padding-bottom" ,"value" => "5px"),
434  array("tag" => "div", "class" => "Excursus", "parameter" => "border-width" ,"value" => "1px"),
435  array("tag" => "div", "class" => "Excursus", "parameter" => "border-style" ,"value" => "solid"),
436  array("tag" => "div", "class" => "Excursus", "parameter" => "border-color" ,"value" => "#A0A0A0"),
437  array("tag" => "div", "class" => "Excursus", "parameter" => "background-color" ,"value" => "#F7FFF7"),
438  array("tag" => "div", "class" => "Excursus", "parameter" => "margin-top" ,"value" => "10px"),
439  array("tag" => "div", "class" => "Excursus", "parameter" => "margin-bottom" ,"value" => "10px"),
440 
441  array("tag" => "div", "class" => "TableContent", "parameter" => "margin-left" ,"value" => "0px"),
442  array("tag" => "div", "class" => "TableContent", "parameter" => "margin-right" ,"value" => "0px"),
443  array("tag" => "div", "class" => "TableContent", "parameter" => "margin-top" ,"value" => "0px"),
444  array("tag" => "div", "class" => "TableContent", "parameter" => "margin-bottom" ,"value" => "0px"),
445  array("tag" => "div", "class" => "TableContent", "parameter" => "padding-left" ,"value" => "0px"),
446  array("tag" => "div", "class" => "TableContent", "parameter" => "padding-right" ,"value" => "0px"),
447  array("tag" => "div", "class" => "TableContent", "parameter" => "padding-top" ,"value" => "0px"),
448  array("tag" => "div", "class" => "TableContent", "parameter" => "padding-bottom" ,"value" => "0px"),
449 
450  array("tag" => "table", "class" => "Media", "parameter" => "background-color" ,"value" => "#F5F5F5"),
451  array("tag" => "table", "class" => "Media", "parameter" => "padding" ,"value" => "0px"),
452  array("tag" => "table", "class" => "Media", "parameter" => "margin" ,"value" => "10px"),
453 
454  array("tag" => "td", "class" => "MediaCaption", "parameter" => "padding" ,"value" => "5px")
455  );
456  }
457  else
458  {
459  $def = array();
460  $q = "SELECT * FROM style_parameter WHERE style_id = ".$ilDB->quote($a_from_style);
461  $par_set = $ilDB->query($q);
462  while($par_rec = $par_set->fetchRow(DB_FETCHMODE_ASSOC))
463  {
464  $def[] = array("tag" => $par_rec["tag"], "class" => $par_rec["class"],
465  "parameter" => $par_rec["parameter"] ,"value" => $par_rec["value"]);
466  }
467  }
468 
469  // default style settings
470  foreach ($def as $sty)
471  {
472  $q = "INSERT INTO style_parameter (style_id, tag, class, parameter, value) VALUES ".
473  "(".$ilDB->quote($this->getId()).",".
474  $ilDB->quote($sty["tag"]).",".
475  $ilDB->quote($sty["class"]).",".
476  $ilDB->quote($sty["parameter"]).",".
477  $ilDB->quote($sty["value"]).")";
478  $ilDB->query($q);
479  }
480 
481  // add style_data record
482  $q = "INSERT INTO style_data (id, uptodate, category) VALUES ".
483  "(".$ilDB->quote($this->getId()).", 0,".
484  $ilDB->quote($this->getScope()).")";
485  $ilDB->query($q);
486 
487  $this->read();
488  $this->writeCSSFile();
489  }
490 
497  function ilClone()
498  {
499  global $log;
500 
501  $new_obj = new ilObjStyleSheet();
502  $new_obj->setTitle($this->getTitle());
503  $new_obj->setType($this->getType());
504  $new_obj->setDescription($this->getDescription());
505  $new_obj->create($this->getId());
506 
507  return $new_obj->getId();
508  }
509 
510 
517  function addParameter($a_tag, $a_par)
518  {
519  global $ilDB;
520 
521  $avail_params = $this->getAvailableParameters();
522  $tag = explode(".", $a_tag);
523  $value = $avail_params[$a_par][0];
524  $q = "INSERT INTO style_parameter (style_id, tag, class, parameter, value) VALUES ".
525  "(".$ilDB->quote($this->getId()).",".$ilDB->quote($tag[0]).",".
526  $ilDB->quote($tag[1]).
527  ",".$ilDB->quote($a_par).",".$ilDB->quote($value).")";
528  $this->ilias->db->query($q);
529  $this->read();
530  $this->writeCSSFile();
531  }
532 
538  function deleteParameter($a_id)
539  {
540  global $ilDB;
541 
542  $q = "DELETE FROM style_parameter WHERE id = ".$ilDB->quote($a_id);
543  $this->ilias->db->query($q);
544  }
545 
550  function deleteStylePar($a_tag, $a_class, $a_par)
551  {
552  global $ilDB;
553 
554  $q = "DELETE FROM style_parameter WHERE ".
555  " style_id = ".$ilDB->quote($this->getId())." AND ".
556  " tag = ".$ilDB->quote($a_tag)." AND ".
557  " class = ".$ilDB->quote($a_class)." AND ".
558  " parameter = ".$ilDB->quote($a_par);
559 
560  $this->ilias->db->query($q);
561  }
562 
566  function delete()
567  {
568  global $ilDB;
569 
570  // delete object
571  parent::delete();
572 
573  // check whether this style is global default
574  $def_style = $this->ilias->getSetting("default_content_style_id");
575  if ($def_style == $this->getId())
576  {
577  $this->ilias->deleteSetting("default_content_style_id");
578  }
579 
580  // check whether this style is global fixed
581  $fixed_style = $this->ilias->getSetting("fixed_content_style_id");
582  if ($fixed_style == $this->getId())
583  {
584  $this->ilias->deleteSetting("fixed_content_style_id");
585  }
586 
587  // delete style parameter
588  $q = "DELETE FROM style_parameter WHERE style_id = ".$ilDB->quote($this->getId());
589  $ilDB->query($q);
590 
591  // delete style file
592  $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
593  if (is_file($css_file_name))
594  {
595  unlink($css_file_name);
596  }
597 
598  // delete entries in learning modules
599  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
601 
602  // delete style data record
603  $q = "DELETE FROM style_data WHERE id = ".$ilDB->quote($this->getId());
604  $ilDB->query($q);
605 
606  }
607 
608 
612  function read()
613  {
614  global $ilDB;
615 
616  parent::read();
617 
618  $q = "SELECT * FROM style_parameter WHERE style_id = ".
619  $ilDB->quote($this->getId())." ORDER BY tag, class ";
620  $style_set = $this->ilias->db->query($q);
621  $ctag = "";
622  $cclass = "";
623  $this->style = array();
624  while($style_rec = $style_set->fetchRow(DB_FETCHMODE_ASSOC))
625  {
626  if ($style_rec["tag"] != $ctag || $style_rec["class"] != $cclass)
627  {
628  // add current tag array to style array
629  if(is_array($tag))
630  {
631  $this->style[] = $tag;
632  }
633  $tag = array();
634  }
635  $ctag = $style_rec["tag"];
636  $cclass = $style_rec["class"];
637  $tag[] = $style_rec;
638  }
639  if(is_array($tag))
640  {
641  $this->style[] = $tag;
642  }
643 
644  $q = "SELECT * FROM style_data WHERE id = ".$ilDB->quote($this->getId());
645  $res = $ilDB->query($q);
646  $sty = $res->fetchRow(DB_FETCHMODE_ASSOC);
647  $this->setUpToDate((boolean) $sty["uptodate"]);
648  $this->setScope($sty["category"]);
649 
650  }
651 
655  function writeCSSFile($a_target_file = "")
656  {
657  $style = $this->getStyle();
658 
659  if ($a_target_file == "")
660  {
661  $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
662  }
663  else
664  {
665  $css_file_name = $a_target_file;
666  }
667  $css_file = fopen($css_file_name, "w");
668 
669  $page_background = "";
670 
671  foreach ($style as $tag)
672  {
673  fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["class"]."\n");
674  fwrite ($css_file, "{\n");
675 
676  foreach($tag as $par)
677  {
678  fwrite ($css_file, "\t".$par["parameter"].": ".$par["value"].";\n");
679 
680  // save page background
681  if ($tag[0]["tag"] == "div" && $tag[0]["class"] == "Page"
682  && $par["parameter"] == "background-color")
683  {
684  $page_background = $par["value"];
685  }
686  }
687  fwrite ($css_file, "}\n");
688  fwrite ($css_file, "\n");
689  }
690 
691  if ($page_background != "")
692  {
693  fwrite ($css_file, "td.ilc_Page\n");
694  fwrite ($css_file, "{\n");
695  fwrite ($css_file, "\t"."background-color: ".$page_background.";\n");
696  fwrite ($css_file, "}\n");
697  }
698  fclose($css_file);
699 
700  $this->setUpToDate(true);
701  $this->_writeUpToDate($this->getId(), true);
702  }
703 
704 
710  function getContentStylePath($a_style_id)
711  {
712  global $ilias;
713 
714  $rand = rand(1,999999);
715 
716 
717  // check global fixed content style
718  $fixed_style = $ilias->getSetting("fixed_content_style_id");
719  if ($fixed_style > 0)
720  {
721  $a_style_id = $fixed_style;
722  }
723 
724  // check global default style
725  if ($a_style_id <= 0)
726  {
727  $a_style_id = $ilias->getSetting("default_content_style_id");
728  }
729 
730  if ($a_style_id > 0 && ilObject::_exists($a_style_id))
731  {
732  // check whether file is up to date
733  if (!ilObjStyleSheet::_lookupUpToDate($a_style_id))
734  {
735  $style = new ilObjStyleSheet($a_style_id);
736  $style->writeCSSFile();
737  }
738 
739  return ilUtil::getWebspaceDir("output").
740  "/css/style_".$a_style_id.".css?dummy=$rand";
741  }
742  else // todo: work this out
743  {
744  return "./Services/COPage/css/content.css";
745  }
746  }
747 
754  {
755  return "./Services/COPage/css/print_content.css";
756  }
757 
764  {
765  return "./Services/COPage/css/syntaxhighlight.css";
766  }
767 
768  function update()
769  {
770  global $ilDB;
771 
772  parent::update();
773  $this->read(); // this could be done better
774  $this->writeCSSFile();
775 
776  $q = "UPDATE style_data ".
777  "SET category = ".$ilDB->quote($this->getScope());
778  $ilDB->query($q);
779  }
780 
787  function updateStyleParameter($a_id, $a_value)
788  {
789  global $ilDB;
790 
791  $q = "UPDATE style_parameter SET VALUE=".
792  $ilDB->quote($a_value)." WHERE id = ".
793  $ilDB->quote($a_id);
794  $style_set = $this->ilias->db->query($q);
795  }
796 
801  function replaceStylePar($a_tag, $a_class, $a_par, $a_val)
802  {
803  global $ilDB;
804 
805  $q = "SELECT * FROM style_parameter WHERE ".
806  " style_id = ".$ilDB->quote($this->getId())." AND ".
807  " tag = ".$ilDB->quote($a_tag)." AND ".
808  " class = ".$ilDB->quote($a_class)." AND ".
809  " parameter = ".$ilDB->quote($a_par);
810 
811  $set = $ilDB->query($q);
812 
813  if ($rec = $set->fetchRow())
814  {
815  $q = "UPDATE style_parameter SET ".
816  " value = ".$ilDB->quote($a_val)." WHERE ".
817  " style_id = ".$ilDB->quote($this->getId())." AND ".
818  " tag = ".$ilDB->quote($a_tag)." AND ".
819  " class = ".$ilDB->quote($a_class)." AND ".
820  " parameter = ".$ilDB->quote($a_par);
821 
822  $ilDB->query($q);
823  }
824  else
825  {
826  $q = "INSERT INTO style_parameter (value, style_id, tag, class, parameter) VALUES ".
827  " (".$ilDB->quote($a_val).",".
828  " ".$ilDB->quote($this->getId()).",".
829  " ".$ilDB->quote($a_tag).",".
830  " ".$ilDB->quote($a_class).",".
831  " ".$ilDB->quote($a_par).")";
832 
833  $ilDB->query($q);
834  }
835  }
836 
837 
841  function getStyle()
842  {
843  return $this->style;
844  }
845 
849  function setStyle($a_style)
850  {
851  $this->style = $a_style;
852  }
853 
854 
858  function getXML()
859  {
860  $xml.= "<StyleSheet>";
861  $xml.= "<Title>".$this->getTitle()."</Title>";
862  $xml.= "<Description>".$this->getDescription()."</Description>";
863  foreach($this->style as $style)
864  {
865  $xml.= "<Style Tag=\"".$style[0]["tag"]."\" Class=\"".$style[0]["class"]."\">";
866  foreach($style as $tag)
867  {
868  $xml.="<StyleParameter Name=\"".$tag["parameter"]."\" Value=\"".$tag["value"]."\"/>";
869  }
870  $xml.= "</Style>";
871  }
872  $xml.= "</StyleSheet>";
873 
874  return $xml;
875  }
876 
877 
881  function exportXML($a_dir)
882  {
883  $file = $a_dir."/style.xml";
884 
885  // open file
886  if (!($fp = @fopen($file,"w")))
887  {
888  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
889  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
890  }
891 
892  // set file permissions
893  chmod($file, 0770);
894 
895  // write xml data into the file
896  fwrite($fp, $this->getXML());
897 
898  // close file
899  fclose($fp);
900 
901  }
902 
906  function createFromXMLFile($a_file)
907  {
908  global $ilDB;
909 
910  parent::create();
911  include_once("./Services/Style/classes/class.ilStyleImportParser.php");
912  $importParser = new ilStyleImportParser($a_file, $this);
913  $importParser->startParsing();
914 
915  // store style parameter
916  foreach ($this->style as $style)
917  {
918  foreach($style as $tag)
919  {
920  $q = "INSERT INTO style_parameter (style_id, tag, class, parameter, value) VALUES ".
921  "(".$ilDB->quote($this->getId()).",".
922  $ilDB->quote($tag["tag"]).",".
923  $ilDB->quote($tag["class"]).
924  ",".$ilDB->quote($tag["parameter"]).",".
925  $ilDB->quote($tag["value"]).")";
926  $this->ilias->db->query($q);
927  }
928  }
929 
930  // add style_data record
931  $q = "INSERT INTO style_data (id, uptodate) VALUES ".
932  "(".$ilDB->quote($this->getId()).", 0)";
933  $ilDB->query($q);
934 
935  $this->update();
936  $this->read();
937  $this->writeCSSFile();
938  }
939 
943  function getAvailableTags()
944  {
945  $tags = array("a.FootnoteLink", "a.FootnoteLink:hover", "a.IntLink", "a.IntLink:hover",
946  "a.IntLink:visited", "a.IntLink:active",
947  "a.ExtLink", "a.ExtLink:hover", "a.ExtLink:visited", "a.ExtLink:active",
948  "div.Footnote", "div.LMNavigation", "div.Page", "div.PageTitle", "span.Comment",
949  "span.Emph", "span.Quotation", "span.Strong",
950  "td.Cell1", "td.Cell2", "td.Cell3", "td.Cell4",
951  "div.Standard", "div.List", "div.Headline1", "div.Headline2", "div.Headline3",
952  "div.Example", "div.Citation", "div.Mnemonic", "div.Additional", "div.Remark",
953  "div.Block", "div.Special", "div.Excursus",
954  "div.TableContent",
955  "table.Media", "td.MediaCaption");
956 
957  return $tags;
958  }
959 
961  {
962  $pars = array(
963  "font-family" => array(),
964  "font-style" => array("italic", "oblique", "normal"),
965  "font-variant" => array("small-caps", "normal"),
966  "font-weight" => array("bold", "normal", "bolder", "lighter"),
967  "font-stretch" => array("wider", "narrower", "condensed", "semi-condensed",
968  "extra-condensed", "ultra-condensed", "expanded", "semi-expanded",
969  "extra-expanded", "ultra-expanded", "normal"),
970  "font-size" => array(),
971  "word-spacing" => array(),
972  "letter-spacing" => array(),
973  "text-decoration" => array("underline", "overline", "line-through", "blink", "none"),
974  "text-transform" => array("capitalize", "uppercase", "lowercase", "none"),
975  "color" => array(),
976 
977  "text-indent" => array(),
978  "line-height" => array(),
979  "vertical-align" => array("top", "middle", "bottom", "baseline", "sub", "super",
980  "text-top", "text-bottom"),
981  "text-align" => array("left", "center", "right", "justify"),
982  "white-space" => array("normal", "pre", "nowrap"),
983 
984  "margin" => array(),
985  "margin-top" => array(),
986  "margin-bottom" => array(),
987  "margin-left" => array(),
988  "margin-right" => array(),
989 
990  "padding" => array(),
991  "padding-top" => array(),
992  "padding-bottom" => array(),
993  "padding-left" => array(),
994  "padding-right" => array(),
995 
996  "border-width" => array(),
997  "border-top-width" => array(),
998  "border-bottom-width" => array(),
999  "border-left-width" => array(),
1000  "border-right-width" => array(),
1001 
1002  "border-color" => array(),
1003  "border-top-color" => array(),
1004  "border-bottom-color" => array(),
1005  "border-left-color" => array(),
1006  "border-right-color" => array(),
1007 
1008  "border-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
1009  "groove", "ridge", "inset", "outset"),
1010  "border-top-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
1011  "groove", "ridge", "inset", "outset"),
1012  "border-bottom-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
1013  "groove", "ridge", "inset", "outset"),
1014  "border-left-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
1015  "groove", "ridge", "inset", "outset"),
1016  "border-right-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
1017  "groove", "ridge", "inset", "outset"),
1018 
1019  "background-color" => array(),
1020  "background-image" => array(),
1021  "background-repeat" => array("repeat", "repeat-x", "repeat-y", "no-repeat"),
1022  "background-attachment" => array("fixed", "scroll"),
1023  "background-position" => array("top", "center", "middle", "bottom", "left", "right"),
1024 
1025  "cursor" => array("auto", "default", "crosshair", "pointer", "move",
1026  "n-resize", "ne-resize", "e-resize", "se-resize", "s-resize", "sw-resize",
1027  "w-resize", "nw-resize", "text", "wait", "help"),
1028  "clear" => array ("non","left","right","both")
1029  );
1030 
1031  return $pars;
1032  }
1033 
1034 } // END class.ilObjStyleSheet
1035 ?>