Code

Fixed Typo.
[gosa.git] / html / helpviewer.php
1 <?php
2 error_reporting(0);
3 /*
4    This code is part of GOsa (https://gosa.gonicus.de)
5    Copyright (C) 2003  Cajus Pollmeier, Fabian Hickert
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
22 /* Include classes and configs */
23 require_once ("../include/php_setup.inc");
24 require_once ("functions.inc");
25 require_once ("functions_helpviewer.inc");
27 header("Content-type: text/html; charset=UTF-8");
28 session_start();
30 /* If no config object is found in the session, abort help */
31 if (!isset($_SESSION['config'])){
32   gosa_log ("main.php called without session");
33   header ("Location: index.php");
34   exit;
35 }
37 /* Language setup */
38 if ($config->data['MAIN']['LANG'] == ""){
39   $lang= get_browser_language();
40 } else {
41   $lang= $config->data['MAIN']['LANG'];
42 }
44 $lang.=".UTF-8";
45 putenv("LANGUAGE=");
46 putenv("LANG=$lang");
47 setlocale(LC_ALL, $lang);
48 $GLOBALS['t_language']= $lang;
49 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
51 $domain = 'messages';
52 bindtextdomain($domain, "$BASE_DIR/locale");
53 textdomain($domain);
54 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
56 $config= $_SESSION['config'];
57 if (isset ($config->data['MAIN']['COMPILE'])){
58   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
59 } else {
60   $smarty->compile_dir= '/var/spool/gosa/';
61 }
63 /* HELP management starts here ...
64  */
66 /* Generate helpobject */
67 if(isset($_SESSION['helpobject'])){
68   $helpobject = $_SESSION['helpobject'];
69 }else{
70   $helpobject['lang']         = "en"; 
71   $helpobject['helpconf']     = array();  
72   $helpobject['currentplug']  = "";
73   $helpobject['file']         = "index.html";
74   $helpobject['helpconf']     = $_SESSION['plist']->gen_headlines();
75 }
77 $lang =  get_browser_language();
78 $lang = $lang[0].$lang[1];
80 $helpobject['lang']           = $lang;  
81 $defaultpage                  = "index.html";                       // alternative file, shown on error, or on first call
82 $prefix                       = "node";                             // Prefix of the generated help files 
83 $suffix                       = ".html";                            // Suffix of the generated helpfiles
84 $maxresults                   = 10;                                 // max number of results shown in result list
85 $minwordlength                = 3;                                  // Word less than 3 chars will be dropped in search
86 $allowed_chars_in_searchword  = "'[^a-z0-9 %_-]'i";                 // Remove all chars that would disturb our search like < or > ...
88 /* Default pages */
89 $backward =$defaultpage;
90 $index    =$defaultpage;
91 $forward  ="node1.html";
94 /* Every class which is called within a tab, stores its name in the Session.
95  * If $_SESSION['current_class_for_help'] isset, 
96  *  get the helpfile specified in the xml file and display it.
97  * Unset this Session entry, to avoid displaying it again.
98  */
99 if(isset($_SESSION['current_class_for_help'])){
101   /* Create new XML parser with the path to the Xml file */
102   $xml = new parseXml("../doc/guide.xml");
103   
104   /* Generate help array */
105   $str = $xml->parse();
106   
107   /* __LANG__ is used as placeholder for the used language*/
108   $helpdir= preg_replace("/__LANG__/i",$lang,$str[($_SESSION['current_class_for_help'])]['PATH']);
110   /* If there is no entry in the xml file for this class, display an error message */
111   if($helpdir == ""){
112     
113     $smarty->assign("help_contents","<br><h2>"._("There is no helpfile specified for this class."))."</h2>";
114     $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
115     $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
116     echo $display;
117     unset($_SESSION['current_class_for_help']);
118     exit();  
119   }
120   
121   /* Save filename */
122   $helpobject['file']= $str[($_SESSION['current_class_for_help'])]['FILE'];
123   
124   /* Save path to the file */
125   $helpobject['currentplug']  = $helpdir;
126   
127   /* Avoid displaying the same help every time */
128   unset($_SESSION['current_class_for_help']);
130 }elseif(isset($_GET['plug'])){
131   /* This displays helpfiles depending on the current $_GET[plug] */
132   $tmp                          = new pluglist($_SESSION['config'],NULL);
133   $path                         = $tmp->get_path($_GET['plug']);
134   $helpobject['currentplug']    = $path;
135   $helpobject['file']           = "index.html";
136   $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
137   if(empty($helpobject['currentplug'])){
138     $helpdir= "";
139   }
141 /* this Post var is set if another page is requested */
142 if(isset($_GET['pg'])){
143  
144   if(preg_match("/\//",$_GET['pg'])){
145     $arr = split("\/",$_GET['pg']);
146     $helpobject['currentplug'] = "../doc/guide/user/".$helpobject['lang']."/html/".$arr[0];
147     $helpdir = $helpobject['currentplug'];
148     $helpobject['file']= $arr[1];
149   }else{
150     /* PG should contain a filename */
151     $helpobject['file'] = $_GET['pg'];
154     /* If empty, force displaying the index */
155     if(empty($_GET['pg'])){
156       $helpobject['currentplug']  = "";
157       $helpobject['file'] = "index.html";
158     }
159     /* Create new helpdir (The path where the requested page is located)*/
160     $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
162     /* If helpdir is empty, force index */
163     if(empty($helpobject['currentplug'])){
164       $helpdir= "";
165     }
166   }
169 $helpdir.="/";
171 /* Save current settings */
172 $_SESSION['helpobject'] = $helpobject;
174 /* 
175  * Display management 
176  */
178 /* If there is no helpdir or file defined, display the index */
179 if(isset($_POST['search'])){
180   $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/";
181   /* read all available directories */
182   $index = readfiles($helpdir,$prefix,$suffix,false,false);
183   $smarty->assign("help_contents",((searchlist($index,search($index,$_POST['search_string']),10))));
184   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
186   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
187   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
188   echo $display;
189 }elseif(((empty($helpdir)))||($helpdir=="/")){
190   /* Generate Index and display it */
191   $smarty->assign("help_contents",genIndex());
192   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
194   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
195   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
196   echo $display;
198 }elseif((is_dir($helpdir))&&($fp = opendir($helpdir))){
199   
200   /* Readfile gets the content of the requested file, 
201    * parse it, rework links images and so on */
202   $index = readfiles($helpdir,$prefix,$suffix,false,$helpobject['file']);
204   /* if this page is result from a search, mark the search strings */
205   if(isset($_GET['mark'])){
206     $matches = $_SESSION['lastresults'][preg_replace("/^.*\//i","",$helpobject['currentplug'])][$helpobject['file']];
207     $index[$helpobject['file']]['content']   = markup_page($index[$helpobject['file']]['content'],$matches);
208   }
210   /* Display the help contents */
211   $smarty->assign("help_contents",$index[$helpobject['file']]['content']);
212   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
213   
214   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
215   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
216   echo $display;
218 }else{
219   
220   /* There was a file requested which actually doesn't exists */
221   $smarty->assign("help_contents","<h2>".sprintf(_("Helpdir '%s' is not accessible, can't read any helpfiles."),$helpdir))."</h2><br>";
222   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
223   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
224   echo $display;
226 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
227 ?>