Code

updated helpviewer
[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 =  preg_replace("/_.*$/","",get_browser_language());
79 $helpobject['lang']           = $lang;  
80 $defaultpage                  = "index.html";                       // alternative file, shown on error, or on first call
81 $prefix                       = "node";                             // Prefix of the generated help files 
82 $suffix                       = ".html";                            // Suffix of the generated helpfiles
83 $maxresults                   = 10;                                 // max number of results shown in result list
84 $minwordlength                = 3;                                  // Word less than 3 chars will be dropped in search
85 $allowed_chars_in_searchword  = "'[^a-z0-9 %_-]'i";                 // Remove all chars that would disturb our search like < or > ...
87 /* Default pages */
88 $backward =$defaultpage;
89 $index    =$defaultpage;
90 $forward  ="node1.html";
93 /* Every class which is called within a tab, stores its name in the Session.
94  * If $_SESSION['current_class_for_help'] isset, 
95  *  get the helpfile specified in the xml file and display it.
96  * Unset this Session entry, to avoid displaying it again.
97  */
98 if(isset($_SESSION['current_class_for_help'])){
100   /* Create new XML parser with the path to the Xml file */
101   $xml = new parseXml("../doc/guide.xml");
102   
103   /* Generate help array */
104   $str = $xml->parse();
105   
106   /* __LANG__ is used as placeholder for the used language*/
107   $helpdir= preg_replace("/__LANG__/i",$lang,$str[($_SESSION['current_class_for_help'])]['PATH']);
109   /* If there is no entry in the xml file for this class, display an error message */
110   if($helpdir == ""){
111     
112     $smarty->assign("help_contents","<br><h2>"._("There is no helpfile specified for this class."))."</h2>";
113     $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
114     $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
115     echo $display;
116     unset($_SESSION['current_class_for_help']);
117     exit();  
118   }
119   
120   /* Save filename */
121   $helpobject['file']= $str[($_SESSION['current_class_for_help'])]['FILE'];
122   
123   /* Save path to the file */
124   $helpobject['currentplug']  = $helpdir;
125   
126   /* Avoid displaying the same help every time */
127   unset($_SESSION['current_class_for_help']);
129 }elseif(isset($_GET['plug'])){
130   /* This displays helpfiles depending on the current $_GET[plug] */
131   $tmp                          = new pluglist($_SESSION['config'],NULL);
132   $path                         = $tmp->get_path($_GET['plug']);
133   $helpobject['currentplug']    = $path;
134   $helpobject['file']           = "index.html";
135   $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
136   if(empty($helpobject['currentplug'])){
137     $helpdir= "";
138   }
140 /* this Post var is set if another page is requested */
141 if(isset($_GET['pg'])){
142  
143   if(preg_match("/\//",$_GET['pg'])){
144     $arr = split("\/",$_GET['pg']);
145     $helpobject['currentplug'] = "../doc/guide/user/".$helpobject['lang']."/html/".$arr[0];
146     $helpdir = $helpobject['currentplug'];
147     $helpobject['file']= $arr[1];
148   }else{
149     /* PG should contain a filename */
150     $helpobject['file'] = $_GET['pg'];
153     /* If empty, force displaying the index */
154     if(empty($_GET['pg'])){
155       $helpobject['currentplug']  = "";
156       $helpobject['file'] = "index.html";
157     }
158     /* Create new helpdir (The path where the requested page is located)*/
159     $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
161     /* If helpdir is empty, force index */
162     if(empty($helpobject['currentplug'])){
163       $helpdir= "";
164     }
165   }
168 $helpdir.="/";
170 /* Save current settings */
171 $_SESSION['helpobject'] = $helpobject;
173 /* 
174  * Display management 
175  */
177 /* If there is no helpdir or file defined, display the index */
178 if(isset($_POST['search'])){
179   $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/";
180   /* read all available directories */
181   $index = readfiles($helpdir,$prefix,$suffix,false,false);
182   $smarty->assign("help_contents",((searchlist($index,search($index,$_POST['search_string']),10))));
183   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
185   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
186   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
187   echo $display;
188 }elseif(((empty($helpdir)))||($helpdir=="/")){
189   /* Generate Index and display it */
190   $smarty->assign("help_contents",genIndex());
191   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
193   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
194   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
195   echo $display;
197 }elseif((is_dir($helpdir))&&($fp = opendir($helpdir))){
198   
199   /* Readfile gets the content of the requested file, 
200    * parse it, rework links images and so on */
201   $index = readfiles($helpdir,$prefix,$suffix,false,$helpobject['file']);
203   /* if this page is result from a search, mark the search strings */
204   if(isset($_GET['mark'])){
205     $matches = $_SESSION['lastresults'][preg_replace("/^.*\//i","",$helpobject['currentplug'])][$helpobject['file']];
206     $index[$helpobject['file']]['content']   = markup_page($index[$helpobject['file']]['content'],$matches);
207   }
209   /* Display the help contents */
210   $smarty->assign("help_contents",$index[$helpobject['file']]['content']);
211   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
212   
213   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
214   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
215   echo $display;
217 }else{
218   
219   /* There was a file requested which actually doesn't exists */
220   $smarty->assign("help_contents","<h2>".sprintf(_("Helpdir '%s' is not accessible, can't read any helpfiles."),$helpdir))."</h2><br>";
221   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
222   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
223   echo $display;
225 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
226 ?>