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 $lang= get_browser_language();
43 putenv("LANGUAGE=");
44 putenv("LANG=$lang");
45 setlocale(LC_ALL, $lang);
46 $GLOBALS['t_language']= $lang;
47 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
49 $domain = 'messages';
50 bindtextdomain($domain, "$BASE_DIR/locale");
51 textdomain($domain);
52 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
54 $config= $_SESSION['config'];
55 if (isset ($config->data['MAIN']['COMPILE'])){
56 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
57 } else {
58 $smarty->compile_dir= '/var/spool/gosa/';
59 }
60 $smarty->assign("title", "GOsa - "._("Help browser"));
62 /* HELP management starts here ...
63 */
65 /* Generate helpobject */
66 if(isset($_SESSION['helpobject'])){
67 $helpobject = $_SESSION['helpobject'];
68 }else{
69 $helpobject['lang'] = $lang;
70 $helpobject['helpconf'] = array();
71 $helpobject['currentplug'] = "";
72 $helpobject['file'] = "index.html";
73 $helpobject['helpconf'] = $_SESSION['plist']->gen_headlines();
74 }
76 $lang = $lang[0].$lang[1];
78 $helpobject['lang'] = $lang;
79 $defaultpage = "index.html"; // alternative file, shown on error, or on first call
80 $prefix = "node"; // Prefix of the generated help files
81 $suffix = ".html"; // Suffix of the generated helpfiles
82 $maxresults = 10; // max number of results shown in result list
83 $minwordlength = 3; // Word less than 3 chars will be dropped in search
84 $allowed_chars_in_searchword = "'[^a-z0-9 %_-]'i"; // Remove all chars that would disturb our search like < or > ...
86 /* Default pages */
87 $backward =$defaultpage;
88 $index =$defaultpage;
89 $forward ="node1.html";
91 $helpdir ="";
92 /* Every class which is called within a tab, stores its name in the Session.
93 * If $_SESSION['current_class_for_help'] isset,
94 * get the helpfile specified in the xml file and display it.
95 * Unset this Session entry, to avoid displaying it again.
96 */
97 if(isset($_SESSION['current_class_for_help'])){
99 /* Create new XML parser with the path to the Xml file */
100 $xml = new parseXml("../doc/guide.xml");
102 /* Generate help array */
103 $str = $xml->parse();
105 /* __LANG__ is used as placeholder for the used language*/
106 $helpdir= @preg_replace("/__LANG__/i",$lang,$str[($_SESSION['current_class_for_help'])]['PATH']);
108 /* If there is no entry in the xml file for this class, display an error message */
109 if($helpdir == ""){
111 $smarty->assign("help_contents","<br><h2>"._("There is no helpfile specified for this class"))."</h2>";
112 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
113 $display= ( $header.$smarty->fetch(get_template_path('help.tpl')));
114 echo $display;
115 unset($_SESSION['current_class_for_help']);
116 exit();
117 }
119 /* Save filename */
120 $helpobject['file']= $str[($_SESSION['current_class_for_help'])]['FILE'];
122 /* Save path to the file */
123 $helpobject['currentplug'] = $helpdir;
125 /* Avoid displaying the same help every time */
126 if(isset($_GET['pg'])){
127 unset($_SESSION['current_class_for_help']);
128 }
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 }
140 }
141 /* this Post var is set if another page is requested */
142 if(isset($_GET['pg'])){
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 }
167 }
168 $helpdir.="/";
170 /* Save current settings */
171 $_SESSION['helpobject'] = $helpobject;
173 /*
174 * Display management
175 */
177 /* this raise a warning if the directory is not found */
179 $files = array();
180 $f = @opendir($helpdir);
181 while($file = @readdir($f)){
182 $files[$file]=$file;
183 }
185 /* Some replacements */
186 $backwardlink = "<a href=\"?pg=%s\" class=\"maintitlebar\">
187 <img src='images/back.png' align=\"middle\" alt=\""._("previous")."\" border=\"0\">
188 </a>";
190 $forwardlink = "<a href=\"?pg=%s\" class=\"maintitlebar\">
191 <img src='images/forward.png' align=\"middle\" alt=\""._("next")."\" border=\"0\">
192 </a>";
195 $back = $for ="";
196 if($helpobject['file'] == "index.html"){
197 $back = " ";
198 $for = sprintf($forwardlink, $prefix."1".$suffix);
199 }else{
200 $current = preg_replace("/^".$prefix."/","",$helpobject['file']);
201 $current = preg_replace("/\.html$/","",$current);
203 if(isset($files[$prefix.($current+1).$suffix])) {
204 $for = sprintf($forwardlink, $prefix.($current+1).$suffix);
205 }
206 if(isset($files[$prefix.($current-1).$suffix])) {
207 $back = sprintf($backwardlink, $prefix.($current-1).$suffix);
208 }
209 if(($current-1) == 0){
210 $back = sprintf($backwardlink, "index.html");
211 }
212 }
215 /* If there is no helpdir or file defined, display the index */
216 if(isset($_POST['search'])){
217 $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/";
218 /* read all available directories */
219 $index = readfiles($helpdir,$prefix,$suffix,false,false);
220 $smarty->assign("help_contents",((searchlist($index,search($index,$_POST['search_string']),10))));
221 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
223 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
224 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
225 echo $display;
226 }elseif(((empty($helpdir)))||($helpdir=="/")){
227 /* Generate Index and display it */
228 $smarty->assign("help_contents",genIndex());
229 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
231 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
232 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
233 echo $display;
235 }elseif((is_dir($helpdir))&&($fp = opendir($helpdir))){
237 /* Readfile gets the content of the requested file,
238 * parse it, rework links images and so on */
239 $index = readfiles($helpdir,$prefix,$suffix,false,$helpobject['file']);
241 /* if this page is result from a search, mark the search strings */
242 if(isset($_GET['mark'])){
243 $matches = $_SESSION['lastresults'][preg_replace("/^.*\//i","",$helpobject['currentplug'])][$helpobject['file']];
244 $index[$helpobject['file']]['content'] = markup_page($index[$helpobject['file']]['content'],$matches);
245 }
247 /* Display the help contents */
248 $smarty->assign("help_contents",$index[$helpobject['file']]['content']);
249 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
251 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
252 $smarty->assign("backward",$back);
253 $smarty->assign("forward" ,$for);
254 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
255 echo $display;
257 }else{
259 /* There was a file requested which actually doesn't exists */
260 $smarty->assign("help_contents","<h2>".sprintf(_("Helpdir '%s' is not accessible, can't read any helpfiles."),$helpdir))."</h2><br>";
261 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
262 $display= ( $header.$smarty->fetch(get_template_path('help.tpl')));
263 echo $display;
264 }
265 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
266 ?>