1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 /* Include classes and configs */
24 @require_once ("../include/php_setup.inc");
25 @require_once ("functions.inc");
26 @require_once ("functions_helpviewer.inc");
28 error_reporting(E_ALL | E_STRICT);
29 restore_error_handler();
30 header("Content-type: text/html; charset=UTF-8");
32 session::start();
34 /* If no config object is found in the session, abort help */
35 if (!session::is_set('config')){
36 new log("security","all/all","",array(),"Help viewer called without session") ;
37 header ("Location: index.php");
38 exit;
39 }
41 $ui= session::get('ui');
42 $config= session::get('config');
44 /* Language setup */
45 $lang= $config->get_cfg_value("lang");
46 if ($lang == ""){
47 $lang= get_browser_language();
48 }
50 $lang.=".UTF-8";
52 putenv("LANGUAGE=");
53 putenv("LANG=$lang");
54 setlocale(LC_ALL, $lang);
55 $GLOBALS['t_language']= $lang;
56 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
58 $domain = 'messages';
59 bindtextdomain($domain, LOCALE_DIR);
60 textdomain($domain);
61 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
63 $config= session::get('config');
64 $smarty->compile_dir= $config->get_cfg_value("compile", "/var/spool/gosa/");
65 $smarty->assign("title", "GOsa - "._("Help browser"));
67 /* HELP management starts here ...
68 */
70 /* Generate helpobject */
71 if(session::is_set('helpobject')){
72 $helpobject = session::get('helpobject');
73 }else{
75 $plist = session::get('plist');
77 $helpobject['lang'] = $lang;
78 $helpobject['helpconf'] = array();
79 $helpobject['currentplug'] = "";
80 $helpobject['file'] = "index.html";
81 $helpobject['helpconf'] = $plist->gen_headlines();
82 }
84 $lang = $lang[0].$lang[1];
86 $helpobject['lang'] = $lang;
87 $defaultpage = "index.html"; // alternative file, shown on error, or on first call
88 $prefix = "node"; // Prefix of the generated help files
89 $suffix = ".html"; // Suffix of the generated helpfiles
90 $maxresults = 10; // max number of results shown in result list
91 $minwordlength = 3; // Word less than 3 chars will be dropped in search
92 $allowed_chars_in_searchword = "'[^a-z0-9 %_-]'i"; // Remove all chars that would disturb our search like < or > ...
94 /* Default pages */
95 $backward =$defaultpage;
96 $index =$defaultpage;
97 $forward ="node1.html";
99 $helpdir ="";
100 /* Every class which is called within a tab, stores its name in the Session.
101 * If session::is_set('current_class_for_help') is true,
102 * get the helpfile specified in the xml file and display it.
103 * Unset this Session entry, to avoid displaying it again.
104 */
105 if(session::is_set('current_class_for_help')){
107 /* Create new XML parser with the path to the Xml file */
108 $xml = new parseXml("../doc/guide.xml");
110 /* Generate help array */
111 $str = $xml->parse();
113 /* __LANG__ is used as placeholder for the used language*/
114 $helpdir= @preg_replace("/__LANG__/i",$lang,$str[(session::get('current_class_for_help'))]['PATH']);
116 /* If there is no entry in the xml file for this class, display an error message */
117 if($helpdir == ""){
119 $smarty->assign("help_contents","<br><h2>"._("There is no helpfile specified for this class"))."</h2>";
120 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
121 $display= ( $header.$smarty->fetch(get_template_path('help.tpl')));
122 echo $display;
123 session::un_set('current_class_for_help');
124 exit();
125 }
127 /* Save filename */
128 $helpobject['file']= $str[(session::get('current_class_for_help'))]['FILE'];
130 /* Save path to the file */
131 $helpobject['currentplug'] = $helpdir;
133 /* Avoid displaying the same help every time */
134 if(isset($_GET['pg'])){
135 session::un_set('current_class_for_help');
136 }
138 }elseif(isset($_GET['plug'])){
139 /* This displays helpfiles depending on the current $_GET[plug] */
140 $ui= get_userinfo();
141 $tmp = new pluglist(session::get('config'), $ui);
142 $path = $tmp->get_path($_GET['plug']);
143 $helpobject['currentplug'] = $path;
144 $helpobject['file'] = "index.html";
145 $helpdir = "../doc/core/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
146 if(empty($helpobject['currentplug'])){
147 $helpdir= "";
148 }
149 }
150 /* this Post var is set if another page is requested */
151 if(isset($_GET['pg'])){
153 if(preg_match("/\//",$_GET['pg'])){
154 $arr = split("\/",$_GET['pg']);
155 $helpobject['currentplug'] = "../doc/core/".$helpobject['lang']."/html/".$arr[0];
156 $helpdir = $helpobject['currentplug'];
157 $helpobject['file']= $arr[1];
158 }else{
159 /* PG should contain a filename */
160 $helpobject['file'] = $_GET['pg'];
163 /* If empty, force displaying the index */
164 if(empty($_GET['pg'])){
165 $helpobject['currentplug'] = "";
166 $helpobject['file'] = "index.html";
167 }
168 /* Create new helpdir (The path where the requested page is located)*/
169 $helpdir = "../doc/core/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
171 /* If helpdir is empty, force index */
172 if(empty($helpobject['currentplug'])){
173 $helpdir= "";
174 }
175 }
176 }
177 $helpdir.="/";
179 /* Save current settings */
180 session::set('helpobject',$helpobject);
182 /*
183 * Display management
184 */
186 $files = array();
187 $f = opendir($helpdir);
188 while($file = readdir($f)){
189 $files[$file]=$file;
190 }
192 /* Some replacements */
193 $backwardlink = "<a href=\"?pg=%s\" class=\"maintitlebar\">
194 <img src='images/back.png' class=\"center\" align=\"middle\" alt=\""._("previous")."\" border=\"0\">
195 </a>";
197 $forwardlink = "<a href=\"?pg=%s\" class=\"maintitlebar\">
198 <img src='images/forward.png' class=\"center\" align=\"middle\" alt=\""._("next")."\" border=\"0\">
199 </a>";
202 $back = $for ="";
203 if($helpobject['file'] == "index.html"){
204 $back = " ";
205 $for = sprintf($forwardlink, $prefix."1".$suffix);
206 }else{
207 $current = preg_replace("/^".$prefix."/","",$helpobject['file']);
208 $current = preg_replace("/\.html$/","",$current);
210 if(isset($files[$prefix.($current+1).$suffix])) {
211 $for = sprintf($forwardlink, $prefix.($current+1).$suffix);
212 }
213 if(isset($files[$prefix.($current-1).$suffix])) {
214 $back = sprintf($backwardlink, $prefix.($current-1).$suffix);
215 }
216 if(($current-1) == 0){
217 $back = sprintf($backwardlink, "index.html");
218 }
219 }
222 /* If there is no helpdir or file defined, display the index */
223 if(isset($_POST['search'])){
224 $helpdir = "../doc/core/".$helpobject['lang']."/html/";
225 /* read all available directories */
226 $index = readfiles($helpdir,$prefix,$suffix,false,false);
227 $smarty->assign("help_contents",((searchlist($index,search($index,$_POST['search_string']),10))));
228 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
230 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
231 $display= ( $header.$smarty->fetch(get_template_path('help.tpl')));
232 echo $display;
233 }elseif(((empty($helpdir)))||($helpdir=="/")){
234 /* Generate Index and display it */
235 $smarty->assign("help_contents",genIndex());
236 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
238 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
239 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
240 echo $display;
242 }elseif((is_dir($helpdir))&&($fp = opendir($helpdir))){
244 /* Readfile gets the content of the requested file,
245 * parse it, rework links images and so on */
246 $index = readfiles($helpdir,$prefix,$suffix,false,$helpobject['file']);
248 $lastresults = session::get('lastresults');
250 /* if this page is result from a search, mark the search strings */
251 if(isset($_GET['mark'])){
252 $matches = $lastresults[preg_replace("/^.*\//i","",$helpobject['currentplug'])][$helpobject['file']];
253 $index[$helpobject['file']]['content'] = markup_page($index[$helpobject['file']]['content'],$matches);
254 }
256 /* Display the help contents */
257 $smarty->assign("help_contents",$index[$helpobject['file']]['content']);
258 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
260 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
261 $smarty->assign("backward",$back);
262 $smarty->assign("forward" ,$for);
263 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
264 echo $display;
266 }else{
268 /* There was a file requested which actually doesn't exists */
269 $smarty->assign("help_contents","<h2>".sprintf(_("Helpdir '%s' is not accessible, can't read any helpfiles."),$helpdir))."</h2><br>";
270 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
271 $display= ( $header.$smarty->fetch(get_template_path('help.tpl')));
272 echo $display;
273 }
274 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
275 ?>