Code

Updated focus
[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(E_ALL);
27 restore_error_handler();
28 header("Content-type: text/html; charset=UTF-8");
30 session_start();
31 $ui= $_SESSION["ui"];
32 $config= $_SESSION['config'];
34 /* If no config object is found in the session, abort help */
35 if (!isset($_SESSION['config'])){
36   gosa_log ("main.php called without session");
37   header ("Location: index.php");
38   exit;
39 }
41 /* Language setup */
42 if ($config->data['MAIN']['LANG'] == ""){
43   $lang= get_browser_language();
44 } else {
45   $lang= $config->data['MAIN']['LANG'];
46 }
48 $lang.=".UTF-8";
50 putenv("LANGUAGE=");
51 putenv("LANG=$lang");
52 setlocale(LC_ALL, $lang);
53 $GLOBALS['t_language']= $lang;
54 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
56 $domain = 'messages';
57 bindtextdomain($domain, "$BASE_DIR/locale");
58 textdomain($domain);
59 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
61 $config= $_SESSION['config'];
62 if (isset ($config->data['MAIN']['COMPILE'])){
63   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
64 } else {
65   $smarty->compile_dir= '/var/spool/gosa/';
66 }
67 $smarty->assign("title", "GOsa - "._("Help browser"));
69 /* HELP management starts here ...
70  */
72 /* Generate helpobject */
73 if(isset($_SESSION['helpobject'])){
74   $helpobject = $_SESSION['helpobject'];
75 }else{
76   $helpobject['lang']         = $lang; 
77   $helpobject['helpconf']     = array();  
78   $helpobject['currentplug']  = "";
79   $helpobject['file']         = "index.html";
80   $helpobject['helpconf']     = $_SESSION['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['current_class_for_help'] isset, 
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(isset($_SESSION['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['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     $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
120     $display= (  $header.$smarty->fetch(get_template_path('help.tpl')));
121     echo $display;
122     unset($_SESSION['current_class_for_help']);
123     exit();  
124   }
125  
126   /* Save filename */
127   $helpobject['file']= $str[($_SESSION['current_class_for_help'])]['FILE'];
128   
129   /* Save path to the file */
130   $helpobject['currentplug']  = $helpdir;
131   
132   /* Avoid displaying the same help every time */
133   if(isset($_GET['pg'])){
134     unset($_SESSION['current_class_for_help']);
135   }
137 }elseif(isset($_GET['plug'])){
138   /* This displays helpfiles depending on the current $_GET[plug] */
139   $tmp                          = new pluglist($_SESSION['config'],NULL);
140   $path                         = $tmp->get_path($_GET['plug']);
141   $helpobject['currentplug']    = $path;
142   $helpobject['file']           = "index.html";
143   $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
144   if(empty($helpobject['currentplug'])){
145     $helpdir= "";
146   }
148 /* this Post var is set if another page is requested */
149 if(isset($_GET['pg'])){
150  
151   if(preg_match("/\//",$_GET['pg'])){
152     $arr = split("\/",$_GET['pg']);
153     $helpobject['currentplug'] = "../doc/guide/user/".$helpobject['lang']."/html/".$arr[0];
154     $helpdir = $helpobject['currentplug'];
155     $helpobject['file']= $arr[1];
156   }else{
157     /* PG should contain a filename */
158     $helpobject['file'] = $_GET['pg'];
161     /* If empty, force displaying the index */
162     if(empty($_GET['pg'])){
163       $helpobject['currentplug']  = "";
164       $helpobject['file'] = "index.html";
165     }
166     /* Create new helpdir (The path where the requested page is located)*/
167     $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
169     /* If helpdir is empty, force index */
170     if(empty($helpobject['currentplug'])){
171       $helpdir= "";
172     }
173   }
175 $helpdir.="/";
177 /* Save current settings */
178 $_SESSION['helpobject'] = $helpobject;
180 /* 
181  * Display management 
182  */
184 $files = array();
185 $f = opendir($helpdir);
186 while($file = readdir($f)){
187   $files[$file]=$file;
190 /* Some replacements */
191 $backwardlink  = "<a href=\"?pg=%s\"  class=\"maintitlebar\">
192                   <img src='images/back.png' align=\"middle\" alt=\""._("previous")."\" border=\"0\">
193                  </a>";
195 $forwardlink   = "<a href=\"?pg=%s\"  class=\"maintitlebar\">
196                   <img src='images/forward.png' align=\"middle\" alt=\""._("next")."\" border=\"0\">
197                  </a>";
200 $back = $for  ="";
201 if($helpobject['file'] == "index.html"){
202   $back = "&nbsp;";
203   $for  = sprintf($forwardlink,   $prefix."1".$suffix);
204 }else{
205   $current = preg_replace("/^".$prefix."/","",$helpobject['file']);
206   $current = preg_replace("/\.html$/","",$current);
207  
208   if(isset($files[$prefix.($current+1).$suffix])) {
209     $for  = sprintf($forwardlink,    $prefix.($current+1).$suffix);
210   }
211   if(isset($files[$prefix.($current-1).$suffix])) {
212     $back = sprintf($backwardlink,   $prefix.($current-1).$suffix);
213   }
214   if(($current-1) == 0){
215     $back = sprintf($backwardlink,   "index.html");
216   }
220 /* If there is no helpdir or file defined, display the index */
221 if(isset($_POST['search'])){
222   $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/";
223   /* read all available directories */
224   $index = readfiles($helpdir,$prefix,$suffix,false,false);
225   $smarty->assign("help_contents",((searchlist($index,search($index,$_POST['search_string']),10))));
226   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
228   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
229   $display= (  $header.$smarty->fetch(get_template_path('help.tpl')));
230   echo $display;
231 }elseif(((empty($helpdir)))||($helpdir=="/")){
232   /* Generate Index and display it */
233   $smarty->assign("help_contents",genIndex());
234   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
236   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
237   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
238   echo $display;
240 }elseif((is_dir($helpdir))&&($fp = opendir($helpdir))){
241   
242   /* Readfile gets the content of the requested file, 
243    * parse it, rework links images and so on */
244   $index = readfiles($helpdir,$prefix,$suffix,false,$helpobject['file']);
246   /* if this page is result from a search, mark the search strings */
247   if(isset($_GET['mark'])){
248     $matches = $_SESSION['lastresults'][preg_replace("/^.*\//i","",$helpobject['currentplug'])][$helpobject['file']];
249     $index[$helpobject['file']]['content']   = markup_page($index[$helpobject['file']]['content'],$matches);
250   }
252   /* Display the help contents */
253   $smarty->assign("help_contents",$index[$helpobject['file']]['content']);
254   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
255   
256   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
257   $smarty->assign("backward",$back);
258   $smarty->assign("forward" ,$for);
259   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
260   echo $display;
262 }else{
263   
264   /* There was a file requested which actually doesn't exists */
265   $smarty->assign("help_contents","<h2>".sprintf(_("Helpdir '%s' is not accessible, can't read any helpfiles."),$helpdir))."</h2><br>";
266   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
267   $display= (  $header.$smarty->fetch(get_template_path('help.tpl')));
268   echo $display;
270 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
271 ?>