• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilObjStyleSheet.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00025 require_once "classes/class.ilObject.php";
00026 
00035 class ilObjStyleSheet extends ilObject
00036 {
00037         var $style;
00038 
00039 
00046         function ilObjStyleSheet($a_id = 0, $a_call_by_reference = false)
00047         {
00048                 $this->type = "sty";
00049                 $this->style = array();
00050                 if($a_call_by_reference)
00051                 {
00052                         $this->ilias->raiseError("Can't instantiate style object via reference id.",$this->ilias->error_obj->FATAL);
00053                 }
00054 
00055                 parent::ilObject($a_id, false);
00056         }
00057 
00058         function setRefId()
00059         {
00060                 $this->ilias->raiseError("Operation ilObjStyleSheet::setRefId() not allowed.",$this->ilias->error_obj->FATAL);
00061         }
00062 
00063         function getRefId()
00064         {
00065                 return "";
00066                 //$this->ilias->raiseError("Operation ilObjStyleSheet::getRefId() not allowed.",$this->ilias->error_obj->FATAL);
00067         }
00068 
00069         function putInTree()
00070         {
00071                 $this->ilias->raiseError("Operation ilObjStyleSheet::putInTree() not allowed.",$this->ilias->error_obj->FATAL);
00072         }
00073 
00074         function createReference()
00075         {
00076                 $this->ilias->raiseError("Operation ilObjStyleSheet::createReference() not allowed.",$this->ilias->error_obj->FATAL);
00077         }
00078 
00079         function setUpToDate($a_up_to_date = true)
00080         {
00081                 $this->up_to_date = $a_up_to_date;
00082         }
00083         
00084         function getUpToDate()
00085         {
00086                 return $this->up_to_date;
00087         }
00088 
00089         function setScope($a_scope)
00090         {
00091                 $this->scope = $a_scope;
00092         }
00093         
00094         function getScope()
00095         {
00096                 return $this->scope;
00097         }
00098 
00099         function _writeUpToDate($a_id, $a_up_to_date)
00100         {
00101                 global $ilDB;
00102 
00103                 $q = "UPDATE style_data SET uptodate = ".$ilDB->quote((int) $a_up_to_date).
00104                         " WHERE id = ".$ilDB->quote($a_id);
00105                 $ilDB->query($q);
00106         }
00107 
00111         function _lookupUpToDate($a_id)
00112         {
00113                 global $ilDB;
00114                 
00115                 $q = "SELECT * FROM style_data ".
00116                         " WHERE id = ".$ilDB->quote($a_id);
00117                 $res = $ilDB->query($q);
00118                 $sty = $res->fetchRow(DB_FETCHMODE_ASSOC);
00119                 
00120                 return (boolean) $sty["uptodate"];
00121         }
00122 
00126         function _writeStandard($a_id, $a_std)
00127         {
00128                 global $ilDB;
00129 
00130                 $q = "UPDATE style_data SET standard = ".$ilDB->quote((int) $a_std).
00131                         " WHERE id = ".$ilDB->quote($a_id);
00132                 $ilDB->query($q);
00133         }
00134 
00138         function _writeScope($a_id, $a_scope)
00139         {
00140                 global $ilDB;
00141 
00142                 $q = "UPDATE style_data SET category = ".$ilDB->quote((int) $a_scope).
00143                         " WHERE id = ".$ilDB->quote($a_id);
00144                 $ilDB->query($q);
00145         }
00146 
00150         function _lookupStandard($a_id)
00151         {
00152                 global $ilDB;
00153                 
00154                 $q = "SELECT * FROM style_data ".
00155                         " WHERE id = ".$ilDB->quote($a_id);
00156                 $res = $ilDB->query($q);
00157                 $sty = $res->fetchRow(DB_FETCHMODE_ASSOC);
00158                 
00159                 return (boolean) $sty["standard"];
00160         }
00161 
00165         function _writeActive($a_id, $a_active)
00166         {
00167                 global $ilDB;
00168 
00169                 $q = "UPDATE style_data SET active = ".$ilDB->quote((int) $a_active).
00170                         " WHERE id = ".$ilDB->quote($a_id);
00171                 $ilDB->query($q);
00172         }
00173 
00177         function _lookupActive($a_id)
00178         {
00179                 global $ilDB;
00180                 
00181                 $q = "SELECT * FROM style_data ".
00182                         " WHERE id = ".$ilDB->quote($a_id);
00183                 $res = $ilDB->query($q);
00184                 $sty = $res->fetchRow(DB_FETCHMODE_ASSOC);
00185                 
00186                 return (boolean) $sty["active"];
00187         }
00188 
00192         function _getStandardStyles($a_exclude_default_style = false,
00193                 $a_include_deactivated = false, $a_scope = 0)
00194         {
00195                 global $ilDB, $ilias, $tree;
00196                 
00197                 $default_style = $ilias->getSetting("default_content_style_id");
00198                 
00199                 $and_str = "";
00200                 if (!$a_include_deactivated)
00201                 {
00202                         $and_str = " AND active = 1";
00203                 }
00204                 
00205                 $q = "SELECT * FROM style_data ".
00206                         " WHERE standard = 1".$and_str;
00207                 $res = $ilDB->query($q);
00208                 $styles = array();
00209                 while($sty = $res->fetchRow(DB_FETCHMODE_ASSOC))
00210                 {
00211                         if (!$a_exclude_default_style || $default_style != $sty["id"])
00212                         {
00213                                 // check scope
00214                                 if ($a_scope > 0 && $sty["category"] > 0)
00215                                 {
00216                                         if ($tree->isInTree($sty["category"]) &&
00217                                                 $tree->isInTree($a_scope))
00218                                         {
00219                                                 $path = $tree->getPathId($a_scope);
00220                                                 if (!in_array($sty["category"], $path))
00221                                                 {
00222                                                         continue;
00223                                                 }
00224                                         }
00225                                 }
00226                                 $styles[$sty["id"]] = ilObject::_lookupTitle($sty["id"]);
00227                         }
00228                 }
00229                 
00230                 return $styles;
00231         }
00232         
00233         
00239         function _getClonableContentStyles()
00240         {
00241                 global $ilAccess, $ilDB;
00242                 
00243                 $clonable_styles = array();
00244                 
00245                 $q = "SELECT * FROM style_data, object_data ".
00246                         " WHERE object_data.obj_id = style_data.id ";
00247                 $style_set = $ilDB->query($q);
00248                 while($style_rec = $style_set->fetchRow(DB_FETCHMODE_ASSOC))
00249                 {
00250                         $clonable = false;
00251                         if ($style_rec["standard"] == 1)
00252                         {
00253                                 if ($style_rec["active"] == 1)
00254                                 {
00255                                         $clonable = true;
00256                                 }
00257                         }
00258                         else
00259                         {
00260                                 include_once("content/classes/class.ilObjContentObject.php");
00261                                 $obj_ids = ilObjContentObject::_lookupContObjIdByStyleId($style_rec["id"]);
00262                                 foreach($obj_ids as $id)
00263                                 {
00264                                         $ref = ilObject::_getAllReferences($id);
00265                                         foreach($ref as $ref_id)
00266                                         {
00267                                                 if ($ilAccess->checkAccess("write", "", $ref_id))
00268                                                 {
00269                                                         $clonable = true;
00270                                                 }
00271                                         }
00272                                 }
00273                         }
00274                         if ($clonable)
00275                         {
00276                                 $clonable_styles[$style_rec["id"]] =
00277                                         $style_rec["title"];
00278                         }
00279                 }
00280                 return $clonable_styles;
00281         }
00282 
00286         function assignMetaData(&$a_meta_data)
00287         {
00288                 $this->meta_data =& $a_meta_data;
00289         }
00290 
00294         function &getMetaData()
00295         {
00296                 return $this->meta_data;
00297         }
00298 
00299         function create($a_from_style = 0)
00300         {
00301                 global $ilDB;
00302                 
00303                 parent::create();
00304 
00305                 if ($a_from_style == 0)
00306                 {
00307                         $def = array(
00308                                 array("tag" => "div", "class" => "PageTitle", "parameter" => "margin-top" ,"value" => "5px"),
00309                                 array("tag" => "div", "class" => "PageTitle", "parameter" => "margin-bottom" ,"value" => "20px"),
00310                                 array("tag" => "div", "class" => "PageTitle", "parameter" => "font-size" ,"value" => "140%"),
00311                                 array("tag" => "div", "class" => "PageTitle", "parameter" => "padding-bottom" ,"value" => "3px"),
00312                                 array("tag" => "div", "class" => "PageTitle", "parameter" => "border-bottom-width" ,"value" => "1px"),
00313                                 array("tag" => "div", "class" => "PageTitle", "parameter" => "border-bottom-style" ,"value" => "solid"),
00314                                 array("tag" => "div", "class" => "PageTitle", "parameter" => "border-color" ,"value" => "#000000"),
00315         
00316                                 array("tag" => "span", "class" => "Strong", "parameter" => "font-weight" ,"value" => "bold"),
00317                                 array("tag" => "span", "class" => "Emph", "parameter" => "font-style" ,"value" => "italic"),
00318                                 array("tag" => "span", "class" => "Comment", "parameter" => "color" ,"value" => "green"),
00319                                 array("tag" => "span", "class" => "Quotation", "parameter" => "color" ,"value" => "brown"),
00320                                 array("tag" => "span", "class" => "Quotation", "parameter" => "font-style" ,"value" => "italic"),
00321         
00322                                 array("tag" => "a", "class" => "FootnoteLink", "parameter" => "color" ,"value" => "blue"),
00323                                 array("tag" => "a", "class" => "FootnoteLink", "parameter" => "font-weight" ,"value" => "normal"),
00324                                 array("tag" => "a", "class" => "FootnoteLink:hover", "parameter" => "color" ,"value" => "#000000"),
00325                                 array("tag" => "div", "class" => "Footnote", "parameter" => "margin-top" ,"value" => "5px"),
00326                                 array("tag" => "div", "class" => "Footnote", "parameter" => "margin-bottom" ,"value" => "5px"),
00327                                 array("tag" => "div", "class" => "Footnote", "parameter" => "font-style" ,"value" => "italic"),
00328         
00329                                 array("tag" => "a", "class" => "IntLink", "parameter" => "color" ,"value" => "blue"),
00330                                 array("tag" => "a", "class" => "IntLink:visited", "parameter" => "color" ,"value" => "blue"),
00331                                 array("tag" => "a", "class" => "IntLink", "parameter" => "font-weight" ,"value" => "normal"),
00332                                 array("tag" => "a", "class" => "IntLink", "parameter" => "text-decoration" ,"value" => "underline"),
00333                                 array("tag" => "a", "class" => "IntLink:hover", "parameter" => "color" ,"value" => "#000000"),
00334         
00335                                 array("tag" => "a", "class" => "ExtLink", "parameter" => "color" ,"value" => "blue"),
00336                                 array("tag" => "a", "class" => "ExtLink:visited", "parameter" => "color" ,"value" => "blue"),
00337                                 array("tag" => "a", "class" => "ExtLink", "parameter" => "font-weight" ,"value" => "normal"),
00338                                 array("tag" => "a", "class" => "ExtLink", "parameter" => "text-decoration" ,"value" => "underline"),
00339                                 array("tag" => "a", "class" => "ExtLink:hover", "parameter" => "color" ,"value" => "#000000"),
00340         
00341                                 array("tag" => "div", "class" => "LMNavigation", "parameter" => "background-color" ,"value" => "#EEEEEE"),
00342                                 array("tag" => "div", "class" => "LMNavigation", "parameter" => "border-style" ,"value" => "outset"),
00343                                 array("tag" => "div", "class" => "LMNavigation", "parameter" => "border-color" ,"value" => "#EEEEEE"),
00344                                 array("tag" => "div", "class" => "LMNavigation", "parameter" => "border-width" ,"value" => "1px"),
00345                                 array("tag" => "div", "class" => "Page", "parameter" => "background-color" ,"value" => "#FFFFFF"),
00346                                 array("tag" => "div", "class" => "Page", "parameter" => "padding" ,"value" => "0px"),
00347                                 array("tag" => "div", "class" => "Page", "parameter" => "margin" ,"value" => "0px"),
00348                                 array("tag" => "td", "class" => "Cell1", "parameter" => "background-color" ,"value" => "#FFCCCC"),
00349                                 array("tag" => "td", "class" => "Cell2", "parameter" => "background-color" ,"value" => "#CCCCFF"),
00350                                 array("tag" => "td", "class" => "Cell3", "parameter" => "background-color" ,"value" => "#CCFFCC"),
00351                                 array("tag" => "td", "class" => "Cell4", "parameter" => "background-color" ,"value" => "#FFFFCC"),
00352         
00353                                 array("tag" => "p", "class" => "Standard", "parameter" => "margin-top" ,"value" => "10px"),
00354                                 array("tag" => "p", "class" => "Standard", "parameter" => "margin-bottom" ,"value" => "10px"),
00355         
00356                                 array("tag" => "p", "class" => "List", "parameter" => "margin-top" ,"value" => "3px"),
00357                                 array("tag" => "p", "class" => "List", "parameter" => "margin-bottom" ,"value" => "3px"),
00358         
00359                                 array("tag" => "p", "class" => "Headline1", "parameter" => "margin-top" ,"value" => "20px"),
00360                                 array("tag" => "p", "class" => "Headline1", "parameter" => "margin-bottom" ,"value" => "10px"),
00361                                 array("tag" => "p", "class" => "Headline1", "parameter" => "font-size" ,"value" => "140%"),
00362         
00363                                 array("tag" => "p", "class" => "Headline2", "parameter" => "margin-top" ,"value" => "20px"),
00364                                 array("tag" => "p", "class" => "Headline2", "parameter" => "margin-bottom" ,"value" => "10px"),
00365                                 array("tag" => "p", "class" => "Headline2", "parameter" => "font-size" ,"value" => "130%"),
00366         
00367                                 array("tag" => "p", "class" => "Headline3", "parameter" => "margin-top" ,"value" => "20px"),
00368                                 array("tag" => "p", "class" => "Headline3", "parameter" => "margin-bottom" ,"value" => "10px"),
00369                                 array("tag" => "p", "class" => "Headline3", "parameter" => "font-size" ,"value" => "120%"),
00370         
00371                                 array("tag" => "p", "class" => "Example", "parameter" => "padding-left" ,"value" => "20px"),
00372                                 array("tag" => "p", "class" => "Example", "parameter" => "border-left" ,"value" => "3px"),
00373                                 array("tag" => "p", "class" => "Example", "parameter" => "border-left-style" ,"value" => "solid"),
00374                                 array("tag" => "p", "class" => "Example", "parameter" => "border-left-color" ,"value" => "blue"),
00375         
00376                                 array("tag" => "p", "class" => "Citation", "parameter" => "color" ,"value" => "brown"),
00377                                 array("tag" => "p", "class" => "Citation", "parameter" => "font-style" ,"value" => "italic"),
00378         
00379                                 array("tag" => "p", "class" => "Mnemonic", "parameter" => "margin-left" ,"value" => "20px"),
00380                                 array("tag" => "p", "class" => "Mnemonic", "parameter" => "margin-right" ,"value" => "20px"),
00381                                 array("tag" => "p", "class" => "Mnemonic", "parameter" => "color" ,"value" => "red"),
00382                                 array("tag" => "p", "class" => "Mnemonic", "parameter" => "padding" ,"value" => "10px"),
00383                                 array("tag" => "p", "class" => "Mnemonic", "parameter" => "border" ,"value" => "1px"),
00384                                 array("tag" => "p", "class" => "Mnemonic", "parameter" => "border-style" ,"value" => "solid"),
00385                                 array("tag" => "p", "class" => "Mnemonic", "parameter" => "border-color" ,"value" => "red"),
00386         
00387                                 array("tag" => "p", "class" => "Additional", "parameter" => "padding" ,"value" => "10px"),
00388                                 array("tag" => "p", "class" => "Additional", "parameter" => "border" ,"value" => "1px"),
00389                                 array("tag" => "p", "class" => "Additional", "parameter" => "border-style" ,"value" => "solid"),
00390                                 array("tag" => "p", "class" => "Additional", "parameter" => "border-color" ,"value" => "blue"),
00391         
00392                                 array("tag" => "p", "class" => "Remark", "parameter" => "padding" ,"value" => "10px"),
00393                                 array("tag" => "p", "class" => "Remark", "parameter" => "border" ,"value" => "1px"),
00394                                 array("tag" => "p", "class" => "Remark", "parameter" => "border-style" ,"value" => "solid"),
00395                                 array("tag" => "p", "class" => "Remark", "parameter" => "border-color" ,"value" => "#909090"),
00396                                 array("tag" => "p", "class" => "Remark", "parameter" => "background-color" ,"value" => "#D0D0D0"),
00397                                 array("tag" => "p", "class" => "Remark", "parameter" => "text-align" ,"value" => "right"),
00398         
00399                                 array("tag" => "p", "class" => "TableContent", "parameter" => "margin-left" ,"value" => "0px"),
00400                                 array("tag" => "p", "class" => "TableContent", "parameter" => "margin-right" ,"value" => "0px"),
00401                                 array("tag" => "p", "class" => "TableContent", "parameter" => "margin-top" ,"value" => "0px"),
00402                                 array("tag" => "p", "class" => "TableContent", "parameter" => "margin-bottom" ,"value" => "0px"),
00403                                 array("tag" => "p", "class" => "TableContent", "parameter" => "padding-left" ,"value" => "0px"),
00404                                 array("tag" => "p", "class" => "TableContent", "parameter" => "padding-right" ,"value" => "0px"),
00405                                 array("tag" => "p", "class" => "TableContent", "parameter" => "padding-top" ,"value" => "0px"),
00406                                 array("tag" => "p", "class" => "TableContent", "parameter" => "padding-bottom" ,"value" => "0px"),
00407         
00408                                 array("tag" => "table", "class" => "Media", "parameter" => "background-color" ,"value" => "#F5F5F5"),
00409                                 array("tag" => "table", "class" => "Media", "parameter" => "padding" ,"value" => "0px"),
00410                                 array("tag" => "table", "class" => "Media", "parameter" => "margin" ,"value" => "10px"),
00411         
00412                                 array("tag" => "td", "class" => "MediaCaption", "parameter" => "padding" ,"value" => "5px")
00413                         );
00414                 }
00415                 else
00416                 {
00417                         $def = array();
00418                         $q = "SELECT * FROM style_parameter WHERE style_id = ".$ilDB->quote($a_from_style);
00419                         $par_set = $ilDB->query($q);
00420                         while($par_rec = $par_set->fetchRow(DB_FETCHMODE_ASSOC))
00421                         {
00422                                 $def[] = array("tag" => $par_rec["tag"], "class" => $par_rec["class"],
00423                                         "parameter" => $par_rec["parameter"] ,"value" => $par_rec["value"]);
00424                         }
00425                 }
00426 
00427                 // default style settings
00428                 foreach ($def as $sty)
00429                 {
00430                         $q = "INSERT INTO style_parameter (style_id, tag, class, parameter, value) VALUES ".
00431                                 "('".$this->getId()."','".$sty["tag"]."','".$sty["class"].
00432                                 "','".$sty["parameter"]."','".$sty["value"]."')";
00433                         $ilDB->query($q);
00434                 }
00435                 
00436                 // add style_data record
00437                 $q = "INSERT INTO style_data (id, uptodate, category) VALUES ".
00438                         "(".$ilDB->quote($this->getId()).", 0,".
00439                         $ilDB->quote($this->getScope()).")";
00440                 $ilDB->query($q);
00441 
00442                 $this->read();
00443                 $this->writeCSSFile();
00444         }
00445         
00452         function ilClone()
00453         {
00454                 global $log;
00455                 
00456                 $new_obj = new ilObjStyleSheet();
00457                 $new_obj->setTitle($this->getTitle());
00458                 $new_obj->setType($this->getType());
00459                 $new_obj->setDescription($this->getDescription());
00460                 $new_obj->create($this->getId());
00461                 
00462                 return $new_obj->getId();
00463         }
00464 
00465 
00472         function addParameter($a_tag, $a_par)
00473         {
00474                 $avail_params = $this->getAvailableParameters();
00475                 $tag = explode(".", $a_tag);
00476                 $value = $avail_params[$a_par][0];
00477                 $q = "INSERT INTO style_parameter (style_id, tag, class, parameter, value) VALUES ".
00478                         "('".$this->getId()."','".$tag[0]."','".$tag[1].
00479                         "','".$a_par."','".$value."')";
00480                 $this->ilias->db->query($q);
00481                 $this->read();
00482                 $this->writeCSSFile();
00483         }
00484 
00490         function deleteParameter($a_id)
00491         {
00492                 $q = "DELETE FROM style_parameter WHERE id = '".$a_id."'";
00493                 $this->ilias->db->query($q);
00494         }
00495 
00500         function deleteStylePar($a_tag, $a_class, $a_par)
00501         {
00502                 global $ilDB;
00503                 
00504                 $q = "DELETE FROM style_parameter WHERE ".
00505                         " style_id = ".$ilDB->quote($this->getId())." AND ".
00506                         " tag = ".$ilDB->quote($a_tag)." AND ".
00507                         " class = ".$ilDB->quote($a_class)." AND ".
00508                         " parameter = ".$ilDB->quote($a_par);
00509 
00510                 $this->ilias->db->query($q);
00511         }
00512 
00516         function delete()
00517         {
00518                 global $ilDB;
00519                 
00520                 // delete object
00521                 parent::delete();
00522                 
00523                 // check whether this style is global default
00524                 $def_style = $this->ilias->getSetting("default_content_style_id");              
00525                 if ($def_style == $this->getId())
00526                 {
00527                         $this->ilias->deleteSetting("default_content_style_id");
00528                 }
00529 
00530                 // check whether this style is global fixed
00531                 $fixed_style = $this->ilias->getSetting("fixed_content_style_id");              
00532                 if ($fixed_style == $this->getId())
00533                 {
00534                         $this->ilias->deleteSetting("fixed_content_style_id");
00535                 }
00536 
00537                 // delete style parameter
00538                 $q = "DELETE FROM style_parameter WHERE style_id = ".$ilDB->quote($this->getId());
00539                 $ilDB->query($q);
00540                 
00541                 // delete style file
00542                 $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
00543                 if (is_file($css_file_name))
00544                 {
00545                         unlink($css_file_name);
00546                 }
00547                 
00548                 // delete entries in learning modules
00549                 include_once("content/classes/class.ilObjContentObject.php");
00550                 ilObjContentObject::_deleteStyleAssignments($this->getId());
00551                 
00552                 // delete style data record
00553                 $q = "DELETE FROM style_data WHERE id = ".$ilDB->quote($this->getId());
00554                 $ilDB->query($q);
00555 
00556         }
00557 
00558 
00562         function read()
00563         {
00564                 global $ilDB;
00565                 
00566                 parent::read();
00567 
00568                 $q = "SELECT * FROM style_parameter WHERE style_id = '".$this->getId()."' ORDER BY tag, class ";
00569                 $style_set = $this->ilias->db->query($q);
00570                 $ctag = "";
00571                 $cclass = "";
00572                 $this->style = array();
00573                 while($style_rec = $style_set->fetchRow(DB_FETCHMODE_ASSOC))
00574                 {
00575                         if ($style_rec["tag"] != $ctag || $style_rec["class"] != $cclass)
00576                         {
00577                                 // add current tag array to style array
00578                                 if(is_array($tag))
00579                                 {
00580                                         $this->style[] = $tag;
00581                                 }
00582                                 $tag = array();
00583                         }
00584                         $ctag = $style_rec["tag"];
00585                         $cclass = $style_rec["class"];
00586                         $tag[] = $style_rec;
00587                 }
00588                 if(is_array($tag))
00589                 {
00590                         $this->style[] = $tag;
00591                 }
00592                 
00593                 $q = "SELECT * FROM style_data WHERE id = ".$ilDB->quote($this->getId());
00594                 $res = $ilDB->query($q);
00595                 $sty = $res->fetchRow(DB_FETCHMODE_ASSOC);
00596                 $this->setUpToDate((boolean) $sty["uptodate"]);
00597                 $this->setScope($sty["category"]);
00598                 
00599         }
00600 
00604         function writeCSSFile($a_target_file = "")
00605         {
00606                 $style = $this->getStyle();
00607 
00608                 if ($a_target_file == "")
00609                 {
00610                         $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
00611                 }
00612                 else
00613                 {
00614                         $css_file_name = $a_target_file;
00615                 }
00616                 $css_file = fopen($css_file_name, "w");
00617                 
00618                 $page_background = "";
00619 
00620                 foreach ($style as $tag)
00621                 {
00622                         fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["class"]."\n");
00623                         fwrite ($css_file, "{\n");
00624 
00625                         foreach($tag as $par)
00626                         {
00627                                 fwrite ($css_file, "\t".$par["parameter"].": ".$par["value"].";\n");
00628                                 
00629                                 // save page background
00630                                 if ($tag[0]["tag"] == "div" && $tag[0]["class"] == "Page"
00631                                         && $par["parameter"] == "background-color")
00632                                 {
00633                                         $page_background = $par["value"];
00634                                 }
00635                         }
00636                         fwrite ($css_file, "}\n");
00637                         fwrite ($css_file, "\n");
00638                 }
00639                 
00640                 if ($page_background != "")
00641                 {
00642                         fwrite ($css_file, "td.ilc_Page\n");
00643                         fwrite ($css_file, "{\n");
00644                         fwrite ($css_file, "\t"."background-color: ".$page_background.";\n");
00645                         fwrite ($css_file, "}\n");
00646                 }
00647                 fclose($css_file);
00648                 
00649                 $this->setUpToDate(true);
00650                 $this->_writeUpToDate($this->getId(), true);
00651         }
00652 
00653 
00659         function getContentStylePath($a_style_id)
00660         {
00661                 global $ilias;
00662                 
00663                 $rand = rand(1,999999);
00664                 
00665                 
00666                 // check global fixed content style
00667                 $fixed_style = $ilias->getSetting("fixed_content_style_id");
00668                 if ($fixed_style > 0)
00669                 {
00670                         $a_style_id = $fixed_style;
00671                 }
00672 
00673                 // check global default style
00674                 if ($a_style_id <= 0)
00675                 {
00676                         $a_style_id = $ilias->getSetting("default_content_style_id");
00677                 }
00678 
00679                 if ($a_style_id > 0 && ilObject::_exists($a_style_id))
00680                 {
00681                         // check whether file is up to date
00682                         if (!ilObjStyleSheet::_lookupUpToDate($a_style_id))
00683                         {
00684                                 $style = new ilObjStyleSheet($a_style_id);
00685                                 $style->writeCSSFile();
00686                         }
00687                         
00688                         return ilUtil::getWebspaceDir("output").
00689                                 "/css/style_".$a_style_id.".css?dummy=$rand";
00690                 }
00691                 else            // todo: work this out
00692                 {
00693                         if (defined("ILIAS_MODULE"))
00694                         {
00695                                 return "../content/content.css";
00696                         }
00697                         else
00698                         {
00699                                 return "./content/content.css";
00700                         }
00701                 }
00702         }
00703 
00709         function getContentPrintStyle()
00710         {
00711                 if (defined("ILIAS_MODULE"))
00712                 {
00713                         return "../content/print_content.css";
00714                 }
00715                 else
00716                 {
00717                         return "./content/print_content.css";
00718                 }
00719         }
00720 
00726         function getSyntaxStylePath()
00727         {
00728                 if (defined("ILIAS_MODULE"))
00729                 {
00730                         return "../content/syntaxhighlight.css";
00731                 }
00732                 else
00733                 {
00734                         return "./content/syntaxhighlight.css";
00735                 }
00736         }
00737 
00738         function update()
00739         {
00740                 global $ilDB;
00741                 
00742                 parent::update();
00743                 $this->read();                          // this could be done better
00744                 $this->writeCSSFile();
00745                 
00746                 $q = "UPDATE style_data ".
00747                         "SET category = ".$ilDB->quote($this->getScope());
00748                 $ilDB->query($q);
00749         }
00750 
00757         function updateStyleParameter($a_id, $a_value)
00758         {
00759                 $q = "UPDATE style_parameter SET VALUE='".$a_value."' WHERE id = '".$a_id."'";
00760                 $style_set = $this->ilias->db->query($q);
00761         }
00762         
00767         function replaceStylePar($a_tag, $a_class, $a_par, $a_val)
00768         {
00769                 global $ilDB;
00770                 
00771                 $q = "SELECT * FROM style_parameter WHERE ".
00772                         " style_id = ".$ilDB->quote($this->getId())." AND ".
00773                         " tag = ".$ilDB->quote($a_tag)." AND ".
00774                         " class = ".$ilDB->quote($a_class)." AND ".
00775                         " parameter = ".$ilDB->quote($a_par);
00776                 
00777                 $set = $ilDB->query($q);
00778                 
00779                 if ($rec = $set->fetchRow())
00780                 {
00781                         $q = "UPDATE style_parameter SET ".
00782                                 " value = ".$ilDB->quote($a_val)." WHERE ".
00783                                 " style_id = ".$ilDB->quote($this->getId())." AND ".
00784                                 " tag = ".$ilDB->quote($a_tag)." AND ".
00785                                 " class = ".$ilDB->quote($a_class)." AND ".
00786                                 " parameter = ".$ilDB->quote($a_par);
00787 
00788                         $ilDB->query($q);
00789                 }
00790                 else
00791                 {
00792                         $q = "INSERT INTO style_parameter (value, style_id, tag,  class, parameter) VALUES ".
00793                                 " (".$ilDB->quote($a_val).",".
00794                                 " ".$ilDB->quote($this->getId()).",".
00795                                 " ".$ilDB->quote($a_tag).",".
00796                                 " ".$ilDB->quote($a_class).",".
00797                                 " ".$ilDB->quote($a_par).")";
00798 
00799                         $ilDB->query($q);
00800                 }
00801         }
00802 
00803 
00807         function getStyle()
00808         {
00809                 return $this->style;
00810         }
00811         
00815         function setStyle($a_style)
00816         {
00817                 $this->style = $a_style;
00818         }
00819         
00820         
00824         function getXML()
00825         {
00826                 $xml.= "<StyleSheet>";
00827                 $xml.= "<Title>".$this->getTitle()."</Title>";
00828                 $xml.= "<Description>".$this->getDescription()."</Description>";
00829                 foreach($this->style as $style)
00830                 {
00831                         $xml.= "<Style Tag=\"".$style[0]["tag"]."\" Class=\"".$style[0]["class"]."\">";
00832                         foreach($style as $tag)
00833                         {
00834                                 $xml.="<StyleParameter Name=\"".$tag["parameter"]."\" Value=\"".$tag["value"]."\"/>";
00835                         }
00836                         $xml.= "</Style>";
00837                 }
00838                 $xml.= "</StyleSheet>";
00839                 
00840                 return $xml;
00841         }
00842         
00843         
00847         function exportXML($a_dir)
00848         {
00849                 $file = $a_dir."/style.xml";
00850                 
00851                 // open file
00852                 if (!($fp = @fopen($file,"w")))
00853                 {
00854                         die ("<b>Error</b>: Could not open \"".$file."\" for writing".
00855                                         " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
00856                 }
00857                 
00858                 // set file permissions
00859                 chmod($file, 0770);
00860                 
00861                 // write xml data into the file
00862                 fwrite($fp, $this->getXML());
00863                 
00864                 // close file
00865                 fclose($fp);
00866 
00867         }
00868 
00872         function createFromXMLFile($a_file)
00873         {
00874                 global $ilDB;
00875                 
00876                 parent::create();               
00877                 include_once("classes/class.ilStyleImportParser.php");
00878                 $importParser = new ilStyleImportParser($a_file, $this);
00879                 $importParser->startParsing();
00880                 
00881                 // store style parameter
00882                 foreach ($this->style as $style)
00883                 {
00884                         foreach($style as $tag)
00885                         {
00886                                 $q = "INSERT INTO style_parameter (style_id, tag, class, parameter, value) VALUES ".
00887                                         "('".$this->getId()."','".$tag["tag"]."','".$tag["class"].
00888                                         "','".$tag["parameter"]."','".$tag["value"]."')";
00889                                 $this->ilias->db->query($q);
00890                         }
00891                 }
00892                 
00893                 // add style_data record
00894                 $q = "INSERT INTO style_data (id, uptodate) VALUES ".
00895                         "(".$ilDB->quote($this->getId()).", 0)";
00896                 $ilDB->query($q);
00897                 
00898                 $this->update();
00899                 $this->read();
00900                 $this->writeCSSFile();
00901         }
00902         
00906         function getAvailableTags()
00907         {
00908                 $tags = array("a.FootnoteLink", "a.FootnoteLink:hover", "a.IntLink", "a.IntLink:hover",
00909                         "a.IntLink:visited", "a.IntLink:active",
00910                         "a.ExtLink", "a.ExtLink:hover", "a.ExtLink:visited", "a.ExtLink:active",
00911                         "div.Footnote", "div.LMNavigation", "div.Page", "div.PageTitle", "span.Comment",
00912                         "span.Emph", "span.Quotation", "span.Strong",
00913                         "td.Cell1", "td.Cell2", "td.Cell3", "td.Cell4",
00914                         "p.Standard", "p.List", "p.Headline1", "p.Headline2", "p.Headline3",
00915                         "p.Example", "p.Citation", "p.Mnemonic", "p.Additional", "p.Remark",
00916                         "p.TableContent",
00917                         "table.Media", "td.MediaCaption");
00918 
00919                 return $tags;
00920         }
00921 
00922         function getAvailableParameters()
00923         {
00924                 $pars = array(
00925                         "font-family" => array(),
00926                         "font-style" => array("italic", "oblique", "normal"),
00927                         "font-variant" => array("small-caps", "normal"),
00928                         "font-weight" => array("bold", "normal", "bolder", "lighter"),
00929                         "font-stretch" => array("wider", "narrower", "condensed", "semi-condensed",
00930                                         "extra-condensed", "ultra-condensed", "expanded", "semi-expanded",
00931                                         "extra-expanded", "ultra-expanded", "normal"),
00932                         "font-size" => array(),
00933                         "word-spacing" => array(),
00934                         "letter-spacing" => array(),
00935                         "text-decoration" => array("underline", "overline", "line-through", "blink", "none"),
00936                         "text-transform" => array("capitalize", "uppercase", "lowercase", "none"),
00937                         "color" => array(),
00938 
00939                         "text-indent" => array(),
00940                         "line-height" => array(),
00941                         "vertical-align" => array("top", "middle", "bottom", "baseline", "sub", "super",
00942                                 "text-top", "text-bottom"),
00943                         "text-align" => array("left", "center", "right", "justify"),
00944                         "white-space" => array("normal", "pre", "nowrap"),
00945 
00946                         "margin" => array(),
00947                         "margin-top" => array(),
00948                         "margin-bottom" => array(),
00949                         "margin-left" => array(),
00950                         "margin-right" => array(),
00951 
00952                         "padding" => array(),
00953                         "padding-top" => array(),
00954                         "padding-bottom" => array(),
00955                         "padding-left" => array(),
00956                         "padding-right" => array(),
00957 
00958                         "border-width" => array(),
00959                         "border-width-top" => array(),
00960                         "border-width-bottom" => array(),
00961                         "border-width-left" => array(),
00962                         "border-width-right" => array(),
00963 
00964                         "border-color" => array(),
00965                         "border-top-color" => array(),
00966                         "border-bottom-color" => array(),
00967                         "border-left-color" => array(),
00968                         "border-right-color" => array(),
00969 
00970                         "border-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00971                                 "groove", "ridge", "inset", "outset"),
00972                         "border-top-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00973                                 "groove", "ridge", "inset", "outset"),
00974                         "border-bottom-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00975                                 "groove", "ridge", "inset", "outset"),
00976                         "border-left-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00977                                 "groove", "ridge", "inset", "outset"),
00978                         "border-right-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00979                                 "groove", "ridge", "inset", "outset"),
00980 
00981                         "background-color" => array(),
00982                         "background-image" => array(),
00983                         "background-repeat" => array("repeat", "repeat-x", "repeat-y", "no-repeat"),
00984                         "background-attachment" => array("fixed", "scroll"),
00985                         "background-position" => array("top", "center", "middle", "bottom", "left", "right"),
00986 
00987                         "cursor" => array("auto", "default", "crosshair", "pointer", "move",
00988                                 "n-resize", "ne-resize", "e-resize", "se-resize", "s-resize", "sw-resize",
00989                                 "w-resize", "nw-resize", "text", "wait", "help"),
00990                         "clear" => array ("non","left","right","both")
00991                 );
00992 
00993                 return $pars;
00994         }
00995 
00996 } // END class.ilObjStyleSheet
00997 ?>

Generated on Fri Dec 13 2013 13:52:08 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1