Code

- Update copyright
[gosa.git] / gosa-core / html / helpviewer.php
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (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  */
23 /* Include classes and configs */
24 @require_once ("../include/php_setup.inc");
25 @require_once ("functions.inc");
26 @require_once ("functions_helpviewer.inc");
28 error_reporting(E_ALL | E_STRICT);
29 restore_error_handler();
30 header("Content-type: text/html; charset=UTF-8");
32 session::start();
34 /* If no config object is found in the session, abort help */
35 if (!session::global_is_set('config')){
36   new log("security","all/all","",array(),"Help viewer called without session") ;
37   header ("Location: index.php");
38   exit;
39 }
41 $ui= session::global_get('ui');
42 $config= session::global_get('config');
44 /* Language setup */
45 $lang= $config->get_cfg_value("language");
46 if ($lang == ""){
47   $lang= get_browser_language();
48 }
50 $lang.=".UTF-8";
52 putenv("LANGUAGE=");
53 putenv("LANG=$lang");
54 setlocale(LC_ALL, $lang);
55 $GLOBALS['t_language']= $lang;
56 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
58 $domain = 'messages';
59 bindtextdomain($domain, LOCALE_DIR);
60 textdomain($domain);
61 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
63 $smarty->compile_dir= $config->get_cfg_value("compile", "/var/spool/gosa/");
64 $smarty->assign("title", "GOsa - "._("Help browser"));
66 /* HELP management starts here ...
67  */
69 /* Generate helpobject */
70 if(session::global_is_set('helpobject')){
71   $helpobject = session::global_get('helpobject');
72 }else{
74   $plist = session::global_get('plist');
76   $helpobject['lang']         = $lang; 
77   $helpobject['helpconf']     = array();  
78   $helpobject['currentplug']  = "";
79   $helpobject['file']         = "index.html";
80   $helpobject['helpconf']     = $plist->gen_headlines();
81 }
83 $lang = $lang[0].$lang[1];
85 $helpobject['lang']           = $lang;  
86 $defaultpage                  = "index.html";                       // alternative file, shown on error, or on first call
87 $prefix                       = "node";                             // Prefix of the generated help files 
88 $suffix                       = ".html";                            // Suffix of the generated helpfiles
89 $maxresults                   = 10;                                 // max number of results shown in result list
90 $minwordlength                = 3;                                  // Word less than 3 chars will be dropped in search
91 $allowed_chars_in_searchword  = "'[^a-z0-9 %_-]'i";                 // Remove all chars that would disturb our search like < or > ...
93 /* Default pages */
94 $backward =$defaultpage;
95 $index    =$defaultpage;
96 $forward  ="node1.html";
98 $helpdir ="";
99 /* Every class which is called within a tab, stores its name in the Session.
100  * If session::global_is_set('current_class_for_help') is true, 
101  *  get the helpfile specified in the xml file and display it.
102  * Unset this Session entry, to avoid displaying it again.
103  */
104 if(session::global_is_set('current_class_for_help')){
106   /* Create new XML parser with the path to the Xml file */
107   $xml = new parseXml("../doc/guide.xml");
108   
109   /* Generate help array */
110   $str = $xml->parse();
112   /* __LANG__ is used as placeholder for the used language*/
113   $helpdir= @preg_replace("/__LANG__/i",$lang,$str[(session::global_get('current_class_for_help'))]['PATH']);
115   /* If there is no entry in the xml file for this class, display an error message */
116   if($helpdir == ""){
117     
118     $smarty->assign("help_contents","<br><h2>"._("There is no helpfile specified for this class"))."</h2>";
119     $smarty->assign("iePngWorkaround", $config->get_cfg_value("iePngWorkaround","false" ) == "true");
120     $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
121     $display= (  $header.$smarty->fetch(get_template_path('help.tpl')));
122     echo $display;
123     session::global_un_set('current_class_for_help');
124     exit();  
125   }
126  
127   /* Save filename */
128   $helpobject['file']= $str[(session::global_get('current_class_for_help'))]['FILE'];
129   
130   /* Save path to the file */
131   $helpobject['currentplug']  = $helpdir;
132   
133   /* Avoid displaying the same help every time */
134   if(isset($_GET['pg'])){
135     session::global_un_set('current_class_for_help');
136   }
138 }elseif(isset($_GET['plug'])){
139   /* This displays helpfiles depending on the current $_GET[plug] */
140   $ui= get_userinfo();
141   $tmp                          = new pluglist($config, $ui);
142   $path                         = $tmp->get_path($_GET['plug']);
143   $helpobject['currentplug']    = $path;
144   $helpobject['file']           = "index.html";
145   $helpdir = "../doc/core/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
146   if(empty($helpobject['currentplug'])){
147     $helpdir= "";
148   }
150 /* this Post var is set if another page is requested */
151 if(isset($_GET['pg'])){
152  
153   if(preg_match("/\//",$_GET['pg'])){
154     $arr = explode("/", $_GET['pg']);
155     $helpobject['currentplug'] = "../doc/core/".$helpobject['lang']."/html/".$arr[0];
156     $helpdir = $helpobject['currentplug'];
157     $helpobject['file']= $arr[1];
158   }else{
159     /* PG should contain a filename */
160     $helpobject['file'] = $_GET['pg'];
163     /* If empty, force displaying the index */
164     if(empty($_GET['pg'])){
165       $helpobject['currentplug']  = "";
166       $helpobject['file'] = "index.html";
167     }
168     /* Create new helpdir (The path where the requested page is located)*/
169     $helpdir = "../doc/core/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
171     /* If helpdir is empty, force index */
172     if(empty($helpobject['currentplug'])){
173       $helpdir= "";
174     }
175   }
177 $helpdir.="/";
179 /* Save current settings */
180 session::global_set('helpobject',$helpobject);
182 /* 
183  * Display management 
184  */
186 $files = array();
187 $f = opendir($helpdir);
188 while($file = readdir($f)){
189   $files[$file]=$file;
192 /* Some replacements */
193 $backwardlink  = "<a href=\"?pg=%s\"  class=\"maintitlebar\">
194                   <img src='images/back.png' class=\"center\" align=\"middle\" alt=\""._("previous")."\" border=\"0\">
195                  </a>";
197 $forwardlink   = "<a href=\"?pg=%s\"  class=\"maintitlebar\">
198                   <img src='images/forward.png' class=\"center\" align=\"middle\" alt=\""._("next")."\" border=\"0\">
199                  </a>";
202 $back = $for  ="";
203 if($helpobject['file'] == "index.html"){
204   $back = "&nbsp;";
205   $for  = sprintf($forwardlink,   $prefix."1".$suffix);
206 }else{
207   $current = preg_replace("/^".$prefix."/","",$helpobject['file']);
208   $current = preg_replace("/\.html$/","",$current);
209  
210   if(isset($files[$prefix.($current+1).$suffix])) {
211     $for  = sprintf($forwardlink,    $prefix.($current+1).$suffix);
212   }
213   if(isset($files[$prefix.($current-1).$suffix])) {
214     $back = sprintf($backwardlink,   $prefix.($current-1).$suffix);
215   }
216   if(($current-1) == 0){
217     $back = sprintf($backwardlink,   "index.html");
218   }
222 /* If there is no helpdir or file defined, display the index */
223 if(isset($_POST['search'])){
224   $helpdir = "../doc/core/".$helpobject['lang']."/html/";
225   /* read all available directories */
226   $index = readfiles($helpdir,$prefix,$suffix,false,false);
227   $smarty->assign("help_contents",((searchlist($index,search($index,$_POST['search_string']),10))));
228   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
230   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
231   $display= (  $header.$smarty->fetch(get_template_path('help.tpl')));
232   echo $display;
233 }elseif(((empty($helpdir)))||($helpdir=="/")){
234   /* Generate Index and display it */
235   $smarty->assign("help_contents",genIndex());
236   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
238   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
239   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
240   echo $display;
242 }elseif((is_dir($helpdir))&&($fp = opendir($helpdir))){
243   
244   /* Readfile gets the content of the requested file, 
245    * parse it, rework links images and so on */
246   $index = readfiles($helpdir,$prefix,$suffix,false,$helpobject['file']);
248   $lastresults = session::global_get('lastresults');
250   /* if this page is result from a search, mark the search strings */
251   if(isset($_GET['mark'])){
252     $matches = $lastresults[preg_replace("/^.*\//i","",$helpobject['currentplug'])][$helpobject['file']];
253     $index[$helpobject['file']]['content']   = markup_page($index[$helpobject['file']]['content'],$matches);
254   }
256   /* Display the help contents */
257   $smarty->assign("help_contents",$index[$helpobject['file']]['content']);
258   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
259   
260   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
261   $smarty->assign("backward",$back);
262   $smarty->assign("forward" ,$for);
263   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
264   echo $display;
266 }else{
267   
268   /* There was a file requested which actually doesn't exists */
269   $smarty->assign("help_contents","<h2>".sprintf(_("Helpdir '%s' is not accessible, can't read any helpfiles."),$helpdir))."</h2><br>";
270   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
271   $display= (  $header.$smarty->fetch(get_template_path('help.tpl')));
272   echo $display;
274 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
275 ?>