6fae266d4474d2ba7f7af13ff19ab0d19b7c9087
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 | E_STRICT);
27 restore_error_handler();
28 header("Content-type: text/html; charset=UTF-8");
30 session_start();
32 /* If no config object is found in the session, abort help */
33 if (!session::is_set('config')){
34 new log("security","all/all","",array(),"Help viewer called without session") ;
35 header ("Location: index.php");
36 exit;
37 }
39 $ui= session::get('ui');
40 $config= session::get('config');
42 /* Language setup */
43 if ($config->data['MAIN']['LANG'] == ""){
44 $lang= get_browser_language();
45 } else {
46 $lang= $config->data['MAIN']['LANG'];
47 }
49 $lang.=".UTF-8";
51 putenv("LANGUAGE=");
52 putenv("LANG=$lang");
53 setlocale(LC_ALL, $lang);
54 $GLOBALS['t_language']= $lang;
55 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
57 $domain = 'messages';
58 bindtextdomain($domain, "$BASE_DIR/locale");
59 textdomain($domain);
60 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
62 $config= session::get('config');
63 if (isset ($config->data['MAIN']['COMPILE'])){
64 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
65 } else {
66 $smarty->compile_dir= '/var/spool/gosa/';
67 }
68 $smarty->assign("title", "GOsa - "._("Help browser"));
70 /* HELP management starts here ...
71 */
73 /* Generate helpobject */
74 if(session::is_set('helpobject')){
75 $helpobject = session::get('helpobject');
76 }else{
78 $plist = session::get('plist');
80 $helpobject['lang'] = $lang;
81 $helpobject['helpconf'] = array();
82 $helpobject['currentplug'] = "";
83 $helpobject['file'] = "index.html";
84 $helpobject['helpconf'] = $plist->gen_headlines();
85 }
87 $lang = $lang[0].$lang[1];
89 $helpobject['lang'] = $lang;
90 $defaultpage = "index.html"; // alternative file, shown on error, or on first call
91 $prefix = "node"; // Prefix of the generated help files
92 $suffix = ".html"; // Suffix of the generated helpfiles
93 $maxresults = 10; // max number of results shown in result list
94 $minwordlength = 3; // Word less than 3 chars will be dropped in search
95 $allowed_chars_in_searchword = "'[^a-z0-9 %_-]'i"; // Remove all chars that would disturb our search like < or > ...
97 /* Default pages */
98 $backward =$defaultpage;
99 $index =$defaultpage;
100 $forward ="node1.html";
102 $helpdir ="";
103 /* Every class which is called within a tab, stores its name in the Session.
104 * If session::is_set('current_class_for_help') is true,
105 * get the helpfile specified in the xml file and display it.
106 * Unset this Session entry, to avoid displaying it again.
107 */
108 if(session::is_set('current_class_for_help')){
110 /* Create new XML parser with the path to the Xml file */
111 $xml = new parseXml("../doc/guide.xml");
113 /* Generate help array */
114 $str = $xml->parse();
116 /* __LANG__ is used as placeholder for the used language*/
117 $helpdir= @preg_replace("/__LANG__/i",$lang,$str[(session::get('current_class_for_help'))]['PATH']);
119 /* If there is no entry in the xml file for this class, display an error message */
120 if($helpdir == ""){
122 $smarty->assign("help_contents","<br><h2>"._("There is no helpfile specified for this class"))."</h2>";
123 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
124 $display= ( $header.$smarty->fetch(get_template_path('help.tpl')));
125 echo $display;
126 session::un_set('current_class_for_help');
127 exit();
128 }
130 /* Save filename */
131 $helpobject['file']= $str[(session::get('current_class_for_help'))]['FILE'];
133 /* Save path to the file */
134 $helpobject['currentplug'] = $helpdir;
136 /* Avoid displaying the same help every time */
137 if(isset($_GET['pg'])){
138 session::un_set('current_class_for_help');
139 }
141 }elseif(isset($_GET['plug'])){
142 /* This displays helpfiles depending on the current $_GET[plug] */
143 $tmp = new pluglist(session::get('config'),get_userinfo());
144 $path = $tmp->get_path($_GET['plug']);
145 $helpobject['currentplug'] = $path;
146 $helpobject['file'] = "index.html";
147 $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
148 if(empty($helpobject['currentplug'])){
149 $helpdir= "";
150 }
151 }
152 /* this Post var is set if another page is requested */
153 if(isset($_GET['pg'])){
155 if(preg_match("/\//",$_GET['pg'])){
156 $arr = split("\/",$_GET['pg']);
157 $helpobject['currentplug'] = "../doc/guide/user/".$helpobject['lang']."/html/".$arr[0];
158 $helpdir = $helpobject['currentplug'];
159 $helpobject['file']= $arr[1];
160 }else{
161 /* PG should contain a filename */
162 $helpobject['file'] = $_GET['pg'];
165 /* If empty, force displaying the index */
166 if(empty($_GET['pg'])){
167 $helpobject['currentplug'] = "";
168 $helpobject['file'] = "index.html";
169 }
170 /* Create new helpdir (The path where the requested page is located)*/
171 $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
173 /* If helpdir is empty, force index */
174 if(empty($helpobject['currentplug'])){
175 $helpdir= "";
176 }
177 }
178 }
179 $helpdir.="/";
181 /* Save current settings */
182 session::set('helpobject',$helpobject);
184 /*
185 * Display management
186 */
188 $files = array();
189 $f = opendir($helpdir);
190 while($file = readdir($f)){
191 $files[$file]=$file;
192 }
194 /* Some replacements */
195 $backwardlink = "<a href=\"?pg=%s\" class=\"maintitlebar\">
196 <img src='images/back.png' class=\"center\" align=\"middle\" alt=\""._("previous")."\" border=\"0\">
197 </a>";
199 $forwardlink = "<a href=\"?pg=%s\" class=\"maintitlebar\">
200 <img src='images/forward.png' class=\"center\" align=\"middle\" alt=\""._("next")."\" border=\"0\">
201 </a>";
204 $back = $for ="";
205 if($helpobject['file'] == "index.html"){
206 $back = " ";
207 $for = sprintf($forwardlink, $prefix."1".$suffix);
208 }else{
209 $current = preg_replace("/^".$prefix."/","",$helpobject['file']);
210 $current = preg_replace("/\.html$/","",$current);
212 if(isset($files[$prefix.($current+1).$suffix])) {
213 $for = sprintf($forwardlink, $prefix.($current+1).$suffix);
214 }
215 if(isset($files[$prefix.($current-1).$suffix])) {
216 $back = sprintf($backwardlink, $prefix.($current-1).$suffix);
217 }
218 if(($current-1) == 0){
219 $back = sprintf($backwardlink, "index.html");
220 }
221 }
224 /* If there is no helpdir or file defined, display the index */
225 if(isset($_POST['search'])){
226 $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/";
227 /* read all available directories */
228 $index = readfiles($helpdir,$prefix,$suffix,false,false);
229 $smarty->assign("help_contents",((searchlist($index,search($index,$_POST['search_string']),10))));
230 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
232 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
233 $display= ( $header.$smarty->fetch(get_template_path('help.tpl')));
234 echo $display;
235 }elseif(((empty($helpdir)))||($helpdir=="/")){
236 /* Generate Index and display it */
237 $smarty->assign("help_contents",genIndex());
238 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
240 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
241 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
242 echo $display;
244 }elseif((is_dir($helpdir))&&($fp = opendir($helpdir))){
246 /* Readfile gets the content of the requested file,
247 * parse it, rework links images and so on */
248 $index = readfiles($helpdir,$prefix,$suffix,false,$helpobject['file']);
250 $lastresults = session::get('lastresults');
252 /* if this page is result from a search, mark the search strings */
253 if(isset($_GET['mark'])){
254 $matches = $lastresults[preg_replace("/^.*\//i","",$helpobject['currentplug'])][$helpobject['file']];
255 $index[$helpobject['file']]['content'] = markup_page($index[$helpobject['file']]['content'],$matches);
256 }
258 /* Display the help contents */
259 $smarty->assign("help_contents",$index[$helpobject['file']]['content']);
260 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
262 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
263 $smarty->assign("backward",$back);
264 $smarty->assign("forward" ,$for);
265 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
266 echo $display;
268 }else{
270 /* There was a file requested which actually doesn't exists */
271 $smarty->assign("help_contents","<h2>".sprintf(_("Helpdir '%s' is not accessible, can't read any helpfiles."),$helpdir))."</h2><br>";
272 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
273 $display= ( $header.$smarty->fetch(get_template_path('help.tpl')));
274 echo $display;
275 }
276 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
277 ?>