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