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::global_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::global_get('ui');
42 $config= session::global_get('config');
44 /* Language setup */
45 $lang= $config->get_cfg_value("core","language");
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 $smarty->compile_dir= $config->get_cfg_value("core","templateCompileDirectory");
64 $smarty->assign("title", "GOsa - "._("Help browser"));
66 /* HELP management starts here ...
67 */
69 /* Generate helpobject */
70 if(session::global_is_set('helpobject')){
71 $helpobject = session::global_get('helpobject');
72 }else{
74 $plist = session::global_get('plist');
76 $helpobject['lang'] = $lang;
77 $helpobject['helpconf'] = array();
78 $helpobject['currentplug'] = "";
79 $helpobject['file'] = "index.html";
80 $helpobject['helpconf'] = $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::global_is_set('current_class_for_help') is true,
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(session::global_is_set('current_class_for_help')){
106 /* Create new XML parser with the path to the Xml file */
107 $xml = new parseXml("../doc/guide.xml");
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::global_get('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 == ""){
118 $smarty->assign("help_contents","<br><h2>"._("There is no help file 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 session::global_un_set('current_class_for_help');
123 exit();
124 }
126 /* Save filename */
127 $helpobject['file']= $str[(session::global_get('current_class_for_help'))]['FILE'];
129 /* Save path to the file */
130 $helpobject['currentplug'] = $helpdir;
132 /* Avoid displaying the same help every time */
133 if(isset($_GET['pg'])){
134 session::global_un_set('current_class_for_help');
135 }
137 }elseif(isset($_GET['plug'])){
138 /* This displays helpfiles depending on the current $_GET[plug] */
139 $ui= get_userinfo();
140 $tmp = new pluglist($config, $ui);
141 $path = $tmp->get_path($_GET['plug']);
142 $helpobject['currentplug'] = $path;
143 $helpobject['file'] = "index.html";
144 $helpdir = "../doc/core/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
145 if(empty($helpobject['currentplug'])){
146 $helpdir= "";
147 }
148 }
149 /* this Post var is set if another page is requested */
150 if(isset($_GET['pg'])){
152 if(preg_match("/\//",$_GET['pg'])){
153 $arr = explode("/", $_GET['pg']);
154 $helpobject['currentplug'] = "../doc/core/".$helpobject['lang']."/html/".$arr[0];
155 $helpdir = $helpobject['currentplug'];
156 $helpobject['file']= $arr[1];
157 }else{
158 /* PG should contain a filename */
159 $helpobject['file'] = $_GET['pg'];
162 /* If empty, force displaying the index */
163 if(empty($_GET['pg'])){
164 $helpobject['currentplug'] = "";
165 $helpobject['file'] = "index.html";
166 }
167 /* Create new helpdir (The path where the requested page is located)*/
168 $helpdir = "../doc/core/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
170 /* If helpdir is empty, force index */
171 if(empty($helpobject['currentplug'])){
172 $helpdir= "";
173 }
174 }
175 }
176 $helpdir.="/";
178 /* Save current settings */
179 session::global_set('helpobject',$helpobject);
181 /*
182 * Display management
183 */
185 $files = array();
186 $f = opendir($helpdir);
187 while($file = readdir($f)){
188 $files[$file]=$file;
189 }
191 /* Some replacements */
192 $backwardlink = "<a href=\"?pg=%s\" class=\"maintitlebar\">
193 <img src='images/back.png' class=\"center\" align=\"middle\" alt=\""._("previous")."\" border=\"0\">
194 </a>";
196 $forwardlink = "<a href=\"?pg=%s\" class=\"maintitlebar\">
197 <img src='images/forward.png' class=\"center\" align=\"middle\" alt=\""._("next")."\" border=\"0\">
198 </a>";
201 $back = $for ="";
202 if($helpobject['file'] == "index.html"){
203 $back = " ";
204 $for = sprintf($forwardlink, $prefix."1".$suffix);
205 }else{
206 $current = preg_replace("/^".$prefix."/","",$helpobject['file']);
207 $current = preg_replace("/\.html$/","",$current);
209 if(isset($files[$prefix.($current+1).$suffix])) {
210 $for = sprintf($forwardlink, $prefix.($current+1).$suffix);
211 }
212 if(isset($files[$prefix.($current-1).$suffix])) {
213 $back = sprintf($backwardlink, $prefix.($current-1).$suffix);
214 }
215 if(($current-1) == 0){
216 $back = sprintf($backwardlink, "index.html");
217 }
218 }
221 /* If there is no helpdir or file defined, display the index */
222 if(isset($_POST['search'])){
223 $helpdir = "../doc/core/".$helpobject['lang']."/html/";
224 /* read all available directories */
225 $index = readfiles($helpdir,$prefix,$suffix,false,false);
226 $smarty->assign("help_contents",((searchlist($index,search($index,$_POST['search_string']),10))));
227 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
229 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
230 $display= ( $header.$smarty->fetch(get_template_path('help.tpl')));
231 echo $display;
232 }elseif(((empty($helpdir)))||($helpdir=="/")){
233 /* Generate Index and display it */
234 $smarty->assign("help_contents",genIndex());
235 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
237 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
238 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
239 echo $display;
241 }elseif((is_dir($helpdir))&&($fp = opendir($helpdir))){
243 /* Readfile gets the content of the requested file,
244 * parse it, rework links images and so on */
245 $index = readfiles($helpdir,$prefix,$suffix,false,$helpobject['file']);
247 $lastresults = session::global_get('lastresults');
249 /* if this page is result from a search, mark the search strings */
250 if(isset($_GET['mark'])){
251 $matches = $lastresults[preg_replace("/^.*\//i","",$helpobject['currentplug'])][$helpobject['file']];
252 $index[$helpobject['file']]['content'] = markup_page($index[$helpobject['file']]['content'],$matches);
253 }
255 /* Display the help contents */
256 $smarty->assign("help_contents",$index[$helpobject['file']]['content']);
257 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
259 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
260 $smarty->assign("backward",$back);
261 $smarty->assign("forward" ,$for);
262 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
263 echo $display;
265 }else{
267 /* There was a file requested which actually doesn't exists */
268 $smarty->assign("help_contents","<h2>".sprintf(_("Help directory '%s' is not accessible, can't read any help files."),$helpdir))."</h2><br>";
269 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
270 $display= ( $header.$smarty->fetch(get_template_path('help.tpl')));
271 echo $display;
272 }
273 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
274 ?>