Code

0f0c168056de74dfed575d2165427495deae466c
[gosa.git] / html / helpviewer.php
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier, Fabian Hickert
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 /* Include classes and configs */
22 @require_once ("../include/php_setup.inc");
23 @require_once ("functions.inc");
24 @require_once ("functions_helpviewer.inc");
26 error_reporting(0);
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();
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   if(isset($_GET['pg'])){
129     unset($_SESSION['current_class_for_help']);
130   }
132 }elseif(isset($_GET['plug'])){
133   /* This displays helpfiles depending on the current $_GET[plug] */
134   $tmp                          = new pluglist($_SESSION['config'],NULL);
135   $path                         = $tmp->get_path($_GET['plug']);
136   $helpobject['currentplug']    = $path;
137   $helpobject['file']           = "index.html";
138   $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
139   if(empty($helpobject['currentplug'])){
140     $helpdir= "";
141   }
143 /* this Post var is set if another page is requested */
144 if(isset($_GET['pg'])){
145  
146   if(preg_match("/\//",$_GET['pg'])){
147     $arr = split("\/",$_GET['pg']);
148     $helpobject['currentplug'] = "../doc/guide/user/".$helpobject['lang']."/html/".$arr[0];
149     $helpdir = $helpobject['currentplug'];
150     $helpobject['file']= $arr[1];
151   }else{
152     /* PG should contain a filename */
153     $helpobject['file'] = $_GET['pg'];
156     /* If empty, force displaying the index */
157     if(empty($_GET['pg'])){
158       $helpobject['currentplug']  = "";
159       $helpobject['file'] = "index.html";
160     }
161     /* Create new helpdir (The path where the requested page is located)*/
162     $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
164     /* If helpdir is empty, force index */
165     if(empty($helpobject['currentplug'])){
166       $helpdir= "";
167     }
168   }
171 $helpdir.="/";
173 /* Save current settings */
174 $_SESSION['helpobject'] = $helpobject;
176 /* 
177  * Display management 
178  */
180 /* If there is no helpdir or file defined, display the index */
181 if(isset($_POST['search'])){
182   $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/";
183   /* read all available directories */
184   $index = readfiles($helpdir,$prefix,$suffix,false,false);
185   $smarty->assign("help_contents",((searchlist($index,search($index,$_POST['search_string']),10))));
186   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
188   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
189   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
190   echo $display;
191 }elseif(((empty($helpdir)))||($helpdir=="/")){
192   /* Generate Index and display it */
193   $smarty->assign("help_contents",genIndex());
194   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
196   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
197   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
198   echo $display;
200 }elseif((is_dir($helpdir))&&($fp = opendir($helpdir))){
201   
202   /* Readfile gets the content of the requested file, 
203    * parse it, rework links images and so on */
204   $index = readfiles($helpdir,$prefix,$suffix,false,$helpobject['file']);
206   /* if this page is result from a search, mark the search strings */
207   if(isset($_GET['mark'])){
208     $matches = $_SESSION['lastresults'][preg_replace("/^.*\//i","",$helpobject['currentplug'])][$helpobject['file']];
209     $index[$helpobject['file']]['content']   = markup_page($index[$helpobject['file']]['content'],$matches);
210   }
212   /* Display the help contents */
213   $smarty->assign("help_contents",$index[$helpobject['file']]['content']);
214   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
215   
216   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
217   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
218   echo $display;
220 }else{
221   
222   /* There was a file requested which actually doesn't exists */
223   $smarty->assign("help_contents","<h2>".sprintf(_("Helpdir '%s' is not accessible, can't read any helpfiles."),$helpdir))."</h2><br>";
224   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
225   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
226   echo $display;
228 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
229 ?>