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

classes/class.ilTemplate.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 
00034 class ilTemplate extends ilTemplateX
00035 {
00040         var $contenttype;
00045         var $vars;
00046 
00053         var $activeBlock;
00054 
00064         function ilTemplate($file,$flag1,$flag2,$in_module = false, $vars = "DEFAULT")
00065         {
00066                 global $ilias;
00067 
00068                 $this->activeBlock = "__global__";
00069                 $this->vars = array();
00070 
00071                 /*
00072                 if (strpos($file,"/") === false)
00073                 {
00074                         //$fname = $ilias->tplPath;
00075                         $base = "./";
00076                         if ($module != "")
00077                         {
00078                                 $base.= $module."/";
00079                         }
00080                         $base .= "templates/";
00081                         $fname = $base.$ilias->account->skin."/".basename($file);
00082                         if(!file_exists($fname))
00083                         {
00084                                 $fname .= $base."default/".basename($file);
00085                         }
00086                 }
00087                 else
00088                 {
00089                         $fname = $file;
00090                 }*/
00091                 $fname = $this->getTemplatePath($file, $in_module);
00092 
00093                 $this->tplName = basename($fname);
00094                 $this->tplPath = dirname($fname);
00095                 // set default content-type to text/html
00096                 $this->contenttype = "text/html";
00097                 if (!file_exists($fname))
00098                 {
00099                         $ilias->raiseError("template ".$fname." was not found.", $ilias->error_obj->FATAL);
00100                         return false;
00101                 }
00102 
00103                 //$this->IntegratedTemplateExtension(dirname($fname));
00104                 $this->callConstructor();
00105                 //$this->loadTemplatefile(basename($fname), $flag1, $flag2);
00106                 $this->loadTemplatefile($fname, $flag1, $flag2);
00107 
00108                 //add tplPath to replacevars
00109                 $this->vars["TPLPATH"] = $this->tplPath;
00110 
00111                 return true;
00112         }
00113 
00120         function get($part = "DEFAULT", $add_error_mess = false,
00121                 $handle_referer = false, $add_ilias_footer = false,
00122                 $add_standard_elements = false)
00123         {
00124                 if ($add_error_mess)
00125                 {
00126                         $this->addErrorMessage();
00127                 }
00128 
00129                 // set standard parts (tabs and title icon)
00130                 if($add_standard_elements)
00131                 {
00132                         $this->setContentStyle();
00133                         $this->fillMainMenu();
00134                         $this->fillTabs();
00135                         $this->fillHeaderIcon();
00136                 }
00137 
00138                 if ($add_ilias_footer)
00139                 {
00140                         $this->addILIASFooter();
00141                 }
00142 
00143                 if ($handle_referer)
00144                 {
00145                         $this->handleReferer();
00146                 }
00147 
00148                 if ($part == "DEFAULT")
00149                 {
00150                         return parent::get();
00151                 }
00152                 else
00153                 {
00154                         return parent::get($part);
00155                 }
00156 
00157         }
00158 
00159         function addErrorMessage()
00160         {
00161                 // ERROR HANDLER SETS $_GET["message"] IN CASE OF $error_obj->MESSAGE
00162                 if ($_SESSION["message"] || $_SESSION["info"])
00163                 {
00164                         if($this->blockExists("MESSAGE"))
00165                         {
00166                                 $this->addBlockFile("MESSAGE", "message", "tpl.message.html");
00167 #                       $this->setCurrentBlock("message");
00168 
00169                                 $this->setVariable("MSG", $_SESSION["message"]);
00170                                 $this->setVariable("INFO", $_SESSION["info"]);
00171 
00172                                 session_unregister("message");
00173                                 session_unregister("info");
00174 
00175 #                       $this->parseCurrentBlock();
00176                         }
00177                 }
00178         }
00179 
00186         function getContentType()
00187         {
00188                 return $this->contenttype;
00189         }
00190         
00201         function setContentType($a_content_type = "text/html")
00202         {
00203                 $this->contenttype = $a_content_type;
00204         }
00205         
00211         function show($part = "DEFAULT", $a_fill_tabs = true)
00212         {
00213                 global $ilias;
00214 //echo "-".ilUtil::getP3PLocation()."-";
00215                 //header('P3P: policyref="'.ilUtil::getP3PLocation().
00216                 //      '", CP="CURa ADMa DEVa TAIa PSAa PSDa IVAa IVDa OUR BUS IND UNI COM NAV INT CNT STA PRE"');
00217                 header('P3P: CP="CURa ADMa DEVa TAIa PSAa PSDa IVAa IVDa OUR BUS IND UNI COM NAV INT CNT STA PRE"');
00218                 header("Content-type: " . $this->getContentType() . "; charset=UTF-8");
00219 
00220                 $this->addErrorMessage();
00221                 
00222                 // display ILIAS footer
00223                 if ($part !== false)
00224                 {
00225                         $this->addILIASFooter();
00226                 }
00227 
00228                 // set standard parts (tabs and title icon)
00229                 if($a_fill_tabs)
00230                 {
00231                         $this->setContentStyle();
00232                         $this->fillMainMenu();
00233                         $this->fillTabs();
00234                         $this->fillHeaderIcon();
00235                 }
00236                 
00237                 if ($part == "DEFAULT" or is_bool($part))
00238                 {
00239                         parent::show();
00240                 }
00241                 else
00242                 {
00243                         parent::show($part);
00244                 }
00245                 
00246 
00247                 $this->handleReferer();
00248         }
00249 
00250         function fillTabs()
00251         {
00252                 global $ilias,$ilTabs;
00253                 
00254                 $this->setVariable("TABS",$ilTabs->getHTML());
00255                 $this->setVariable("SUB_TABS",$ilTabs->getSubTabHTML());
00256         }
00257         
00258         function setContentStyle()
00259         {
00260                 $this->setVariable("LOCATION_NEWCONTENT_STYLESHEET_TAG",
00261                         '<link rel="stylesheet" type="text/css" href="'.
00262                         ilUtil::getNewContentStyleSheetLocation()
00263                         .'" />');
00264         }
00265         
00266         function fillMainMenu()
00267         {
00268                 global $tpl, $ilMainMenu;
00269                 
00270                 //$ilMainMenu->setTemplate($tpl);
00271                 //$ilMainMenu->addMenuBlock("MAINMENU", "navigation");
00272                 //$ilMainMenu->setTemplateVars();
00273 //echo "-".htmlentities($ilMainMenu->getHTML())."-";
00274                 $tpl->setVariable("MAINMENU", $ilMainMenu->getHTML());
00275         }
00276         
00277         function fillHeaderIcon()
00278         {
00279                 if ($this->icon_path != "")
00280                 {
00281                         if ($this->icon_desc != "")
00282                         {
00283                                 $this->setCurrentBlock("header_image_desc");
00284                                 $this->setVariable("IMAGE_DESC", $this->icon_desc);
00285                                 $this->parseCurrentBlock();
00286                         }
00287                         $this->setCurrentBlock("header_image");
00288                         $this->setVariable("IMG_HEADER", $this->icon_path);
00289                         $this->parseCurrentBlock();
00290                 }
00291         }
00292         
00293         
00297         function addILIASFooter()
00298         {
00299                 global $ilias, $ilClientIniFile;
00300 
00301                 $this->addBlockFile("FOOTER", "footer", "tpl.footer.html");
00302                 $this->setVariable("ILIAS_VERSION", $ilias->getSetting("ilias_version"));
00303                 if (DEVMODE)
00304                 {
00305                         $mem_usage = "";
00306                         if(function_exists("memory_get_usage"))
00307                         {
00308                                 $mem_usage.=
00309                                         "<br /> Memory Usage: ".memory_get_usage()." Bytes";
00310                         }
00311                         if(function_exists("xdebug_peak_memory_usage"))
00312                         {
00313                                 $mem_usage.=
00314                                         "<br /> XDebug Peak Memory Usage: ".xdebug_peak_memory_usage()." Bytes";
00315                         }
00316                         if ($mem_usage != "")
00317                         {
00318                                 $this->setVariable("MEMORY_USAGE", $mem_usage);
00319                         }
00320 
00321                         $this->setVariable("SESS_INFO", "<br />maxlifetime: ".
00322                                 ini_get("session.gc_maxlifetime")." (".
00323                                 (ini_get("session.gc_maxlifetime")/60)."), id: ".session_id()."<br />".
00324                                 "timestamp: ".date("Y-m-d H:i:s", $_SESSION["_authsession"]["timestamp"]).
00325                                 ", idle: ".date("Y-m-d H:i:s", $_SESSION["_authsession"]["idle"]).
00326                                 "<br />expire: ".($exp = $ilClientIniFile->readVariable("session","expire")).
00327                                 " (".($exp/60)."), session ends at: ".
00328                                 date("Y-m-d H:i:s", $_SESSION["_authsession"]["idle"] + $exp));
00329                         
00330                         if (version_compare(PHP_VERSION,'5','>='))
00331                         {
00332                                 $this->setVariable("VALIDATION_LINKS",
00333                                         '<br /><a href="'.
00334                                         ilUtil::appendUrlParameterString($_SERVER["REQUEST_URI"], "do_dev_validate=xhtml").
00335                                         '">Validate</a> | <a href="'.
00336                                         ilUtil::appendUrlParameterString($_SERVER["REQUEST_URI"], "do_dev_validate=accessibility").
00337                                         '">Accessibility</a>');
00338                         }
00339                         if (!empty($_GET["do_dev_validate"]))
00340                         {
00341                                 require_once("Services/XHTMLValidator/classes/class.ilValidatorAdapter.php");
00342                                 $template2 = ilPHP::cloneObject($this);
00343 //echo "-".ilValidatorAdapter::validate($template2->get(), $_GET["do_dev_validate"])."-";
00344                                 $this->setCurrentBlock("xhtml_validation");
00345                                 $this->setVariable("VALIDATION",
00346                                         ilValidatorAdapter::validate($template2->get("DEFAULT",
00347                                         false, false, false, true), $_GET["do_dev_validate"]));
00348                                 $this->parseCurrentBlock();
00349                         }
00350                 }
00351         }
00352 
00353 
00358         function handleReferer()
00359         {
00360                 if (((substr(strrchr($_SERVER["PHP_SELF"],"/"),1) != "error.php")
00361                         && (substr(strrchr($_SERVER["PHP_SELF"],"/"),1) != "adm_menu.php")
00362                         && (substr(strrchr($_SERVER["PHP_SELF"],"/"),1) != "chat.php")))
00363                 {
00364                         $_SESSION["post_vars"] = $_POST;
00365 
00366                         // referer is modified if query string contains cmd=gateway and $_POST is not empty.
00367                         // this is a workaround to display formular again in case of error and if the referer points to another page
00368                         $url_parts = parse_url($_SERVER["REQUEST_URI"]);
00369 
00370                         if (preg_match("/cmd=gateway/",$url_parts["query"]) && (isset($_POST["cmd"]["create"])))
00371                         {
00372                                 foreach ($_POST as $key => $val)
00373                                 {
00374                                         if (is_array($val))
00375                                         {
00376                                                 $val = key($val);
00377                                         }
00378 
00379                                         $str .= "&".$key."=".$val;
00380                                 }
00381 
00382                                 $_SESSION["referer"] = preg_replace("/cmd=gateway/",substr($str,1),$_SERVER["REQUEST_URI"]);
00383                         }
00384                         else if (preg_match("/cmd=post/",$url_parts["query"]) && (isset($_POST["cmd"]["create"])))
00385                         {
00386                                 foreach ($_POST as $key => $val)
00387                                 {
00388                                         if (is_array($val))
00389                                         {
00390                                                 $val = key($val);
00391                                         }
00392 
00393                                         $str .= "&".$key."=".$val;
00394                                 }
00395 
00396                                 $_SESSION["referer"] = preg_replace("/cmd=post/",substr($str,1),$_SERVER["REQUEST_URI"]);
00397                         }
00398                         else
00399                         {
00400                                 $_SESSION["referer"] = $_SERVER["REQUEST_URI"];
00401                         }
00402 
00403                         unset($_SESSION["error_post_vars"]);
00404                 }
00405         }
00406 
00413         function blockExists($a_blockname)
00414         {
00415                 return $this->blockvariables["content"][$a_blockname] ? true : false;
00416         }
00417 
00418 
00425         function fillVars()
00426         {
00427                 $count = 0;
00428                 reset($this->vars);
00429 
00430                 while(list($key, $val) = each($this->vars))
00431                 {
00432                         if (is_array($this->blockvariables[$this->activeBlock]))
00433                         {
00434                                 if  (array_key_exists($key, $this->blockvariables[$this->activeBlock]))
00435                                 {
00436                                         $count++;
00437 
00438                                         $this->setVariable($key, $val);
00439                                 }
00440                         }
00441                 }
00442                 
00443                 return $count;
00444         }
00445         
00452         function setCurrentBlock ($part = "DEFAULT")
00453         {
00454                 $this->activeBlock = $part;
00455 
00456                 if ($part == "DEFAULT")
00457                 {
00458                         return parent::setCurrentBlock();
00459                 }
00460                 else
00461                 {
00462                         return parent::setCurrentBlock($part);
00463                 }
00464         }
00465 
00472         function touchBlock($block)
00473         {
00474                 $this->setCurrentBlock($block);
00475                 $count = $this->fillVars();
00476                 $this->parseCurrentBlock();
00477 
00478                 if ($count == 0)
00479                 {
00480                         parent::touchBlock($block);
00481                 }
00482         }
00483 
00490         function parseCurrentBlock($part = "DEFAULT")
00491         {
00492                 // Hier erst noch ein replace aufrufen
00493                 if ($part != "DEFAULT")
00494                 {
00495                         $tmp = $this->activeBlock;
00496                         $this->activeBlock = $part;
00497                 }
00498 
00499                 if ($part != "DEFAULT")
00500                 {
00501                         $this->activeBlock = $tmp;
00502                 }
00503 
00504                 $this->fillVars();
00505 
00506                 $this->activeBlock = "__global__";
00507 
00508                 if ($part == "DEFAULT")
00509                 {
00510                         return parent::parseCurrentBlock();
00511                 }
00512                 else
00513                 {
00514                         return parent::parseCurrentBlock($part);
00515                 }
00516         }
00517 
00528         function replaceFromDatabase(&$DB,$block,$conv,$select="default")
00529         {
00530                 $res = $DB->selectDbAll();
00531 
00532                 while ($DB->getDbNextElement($res))
00533                 {
00534                         $this->setCurrentBlock($block);
00535                         $result = array();
00536                         reset($conv);
00537 
00538                         while (list ($key,$val) = each ($conv))
00539                         {
00540                                 $result[$val]=$DB->element->data[$key];
00541                         }
00542 
00543                         if (($select != "default")
00544                                 && ($DB->element->data[$select["id"]]==$select["value"]
00545                                 || (strtolower($select["text"]) == "checked"
00546                                 && strpos( ",,".$select["value"].",," , ",".$DB->element->data[$select["id"]]."," )!=false)))
00547                         {
00548                                 $result[$select["field"]] = $select["text"];
00549                         }
00550 
00551                         $this->replace($result);
00552                         $this->parseCurrentBlock($block);
00553                 }
00554         }
00555 
00562         function prepareForFormular($vars)
00563         {
00564                 if (!is_array($vars))
00565                 {
00566                         return;
00567                 }
00568 
00569                 reset($vars);
00570 
00571                 while (list($i) = each($vars))
00572                 {
00573                         $vars[$i] = stripslashes($vars[$i]);
00574                         $vars[$i] = htmlspecialchars($vars[$i]);
00575                 }
00576 
00577                 return($vars);
00578         }
00579 
00584         function replace()
00585         {
00586                 reset($this->vars);
00587 
00588                 while(list($key, $val) = each($this->vars))
00589                 {
00590                         $this->setVariable($key, $val);
00591                 }
00592         }
00593 
00598         function replaceDefault()
00599         {
00600                 $this->replace($this->vars);
00601         }
00602 
00610         function checkTopic($a_block, $a_topic)
00611         {
00612                 return array_key_exists($a_topic, $this->blockvariables[$a_block]);
00613         }
00614 
00620         function includeNavigation()
00621         {
00622                 return $this->checkTopic("__global__", "NAVIGATION");
00623         }
00624 
00630         function includeTree()
00631         {
00632                 return $this->checkTopic("__global__", "TREE");
00633         }
00634 
00640         function fileExists($filename)
00641         {
00642                 return file_exists($this->tplPath."/".$filename);
00643         }
00644 
00645 
00655         function addBlockFile($var, $block, $tplname, $in_module = false)
00656         {
00657                 if (DEBUG)
00658                 {
00659                         echo "<br/>Template '".$this->tplPath."/".$tplname."'";
00660                 }
00661 
00662                 $tplfile = $this->getTemplatePath($tplname, $in_module);
00663                 if (file_exists($tplfile) == false)
00664                 {
00665                         echo "<br/>Template '".$tplfile."' doesn't exist! aborting...";
00666                         return false;
00667                 }
00668 
00669                 return parent::addBlockFile($var, $block, $tplfile);
00670         }
00671 
00680         function getTemplatePath($a_tplname, $a_in_module = false)
00681         {
00682                 global $ilias, $ilCtrl;
00683                 
00684                 // if baseClass functionality is used (ilias.php):
00685                 // get template directory from ilCtrl
00686                 if (!empty($_GET["baseClass"]) && $a_in_module === true)
00687                 {
00688                         $a_in_module = $ilCtrl->getModuleDir();
00689                 }
00690 
00691                 if (strpos($a_tplname,"/") === false)
00692                 {
00693                         //$fname = $ilias->tplPath;
00694                         $base = "./";
00695                         if ($a_in_module)
00696                         {
00697                                 if ($a_in_module === true)
00698                                 {
00699                                         $base.= ILIAS_MODULE."/";
00700                                 }
00701                                 else
00702                                 {
00703                                         $base.= $a_in_module."/";
00704                                 }
00705                         }
00706                         $base .= "templates/";
00707                         $fname = $base.$ilias->account->skin."/".basename($a_tplname);
00708                         //echo "looking for :$fname:<br>";
00709                         if(!file_exists($fname))
00710                         {
00711                                 $fname = $base."default/".basename($a_tplname);
00712                         }
00713                 }
00714                 else
00715                 {
00716                         $fname = $a_tplname;
00717                 }
00718                 return $fname;
00719         }
00720         
00721         function setHeaderPageTitle($a_title)
00722         {
00723                 $this->setVariable("PAGETITLE", $a_title);
00724         }
00725         
00726         function setStyleSheetLocation($a_stylesheet)
00727         {
00728                 $this->setVariable("LOCATION_STYLESHEET", $a_stylesheet);
00729         }
00730 
00731         function setNewContentStyleSheetLocation($a_stylesheet)
00732         {
00733                 $this->setVariable("LOCATION_NEWCONTENT_STYLESHEET", $a_stylesheet);
00734         }
00735 
00736         function getStandardTemplate()
00737         {
00738                 $this->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
00739                 $this->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
00740         }
00741         
00745         function setTitle($a_title)
00746         {
00747                 $this->setVariable("HEADER", $a_title);
00748         }
00749         
00753         function setTitleIcon($a_icon_path, $a_icon_desc = "")
00754         {
00755                 $this->icon_desc = $a_icon_desc;
00756                 $this->icon_path = $a_icon_path;
00757         }
00758         
00762         function setDescription($a_descr)
00763         {
00764                 $this->setVariable("H_DESCRIPTION", $a_descr);
00765         }
00766         
00770         function stopTitleFloating()
00771         {
00772                 $this->touchBlock("stop_floating");
00773         }
00774         
00778         function setContent($a_html)
00779         {
00780                 $this->setVariable("ADM_CONTENT", $a_html);
00781         }
00782         
00787         function setLocator()
00788         {
00789                 global $ilLocator;
00790                 
00791                 $this->addBlockFile("LOCATOR", "locator", "tpl.locator.html");
00792                 
00793                 $items = $ilLocator->getItems();
00794                 $first = true;
00795                 if (is_array($items))
00796                 {
00797                         //$this->touchBlock("locator_separator");
00798                         //$this->touchBlock("locator_item");
00799 
00800                         foreach($items as $item)
00801                         {
00802                                 if (!$first)
00803                                 {
00804                                         $this->touchBlock("locator_separator_prefix");
00805                                 }
00806                                 
00807                                 $this->setCurrentBlock("locator_item");
00808                                 if ($item["link"] != "")
00809                                 {
00810                                         $this->setVariable("LINK_ITEM", $item["link"]);
00811                                         if ($item["frame"] != "")
00812                                         {
00813                                                 $this->setVariable("LINK_TARGET", ' target="'.$item["frame"].'" ');
00814                                         }
00815                                         $this->setVariable("ITEM", $item["title"]);
00816                                 }
00817                                 else
00818                                 {
00819                                         $this->setVariable("PREFIX", $item["title"]);
00820                                 }
00821                                 $this->parseCurrentBlock();
00822                                 
00823                                 $first = false;
00824                         }
00825                 }
00826                 else
00827                 {
00828                         $this->setVariable("NOITEM", "&nbsp;");
00829                         $this->touchBlock("locator");
00830                 }
00831         }
00832         
00836         function setTabs($a_tabs_html)
00837         {
00838                 $this->setVariable("TABS", $a_tabs_html);
00839         }
00840 
00844         function setSubTabs($a_tabs_html)
00845         {
00846                 $this->setVariable("SUB_TABS", $a_tabs_html);
00847         }
00848         
00852         function setUpperIcon($a_link, $a_frame = "")
00853         {
00854                 global $lng;
00855 
00856                 if ($a_frame != "")
00857                 {
00858                         $this->setCurrentBlock("target_top");
00859                         $this->setVariable("TARGET_TOP", $a_frame);
00860                         $this->parseCurrentBlock();
00861                 }
00862 
00863                 $this->setVariable("ALT_TOP", $lng->txt("up"));
00864 
00865                 $this->setCurrentBlock("top");
00866                 $this->setVariable("LINK_TOP", $a_link);
00867                 $this->setVariable("IMG_TOP",ilUtil::getImagePath("ic_top.gif"));
00868                 $this->parseCurrentBlock();
00869         }
00870         
00876         function setTreeFlatIcon($a_link, $a_mode)
00877         {
00878                 global $lng;
00879                 
00880                 $this->setCurrentBlock("tree_mode");
00881                 $this->setVariable("LINK_MODE", $a_link);
00882                 $this->setVariable("IMG_TREE",ilUtil::getImagePath("ic_".$a_mode."view.gif"));
00883                 $this->setVariable("ALT_TREE",$lng->txt($a_mode."view"));
00884                 $this->setVariable("TARGET_TREE", ilFrameTargetInfo::_getFrame("MainContent"));
00885 //echo ":".ilFrameTargetInfo::_getFrame("MainContent").":";
00886                 $this->parseCurrentBlock();
00887         }
00888 
00889 
00890 }
00891 ?>

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