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(0);
27 header("Content-type: text/html; charset=UTF-8");
29 session_start();
30 $ui= $_SESSION["ui"];
31 $config= $_SESSION['config'];
33 /* If no config object is found in the session, abort help */
34 if (!isset($_SESSION['config'])){
35 gosa_log ("main.php called without session");
36 header ("Location: index.php");
37 exit;
38 }
40 /* Language setup */
41 if ($config->data['MAIN']['LANG'] == ""){
42 $lang= get_browser_language();
43 } else {
44 $lang= $config->data['MAIN']['LANG'];
45 }
47 $lang.=".UTF-8";
49 putenv("LANGUAGE=");
50 putenv("LANG=$lang");
51 setlocale(LC_ALL, $lang);
52 $GLOBALS['t_language']= $lang;
53 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
55 $domain = 'messages';
56 bindtextdomain($domain, "$BASE_DIR/locale");
57 textdomain($domain);
58 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
60 $config= $_SESSION['config'];
61 if (isset ($config->data['MAIN']['COMPILE'])){
62 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
63 } else {
64 $smarty->compile_dir= '/var/spool/gosa/';
65 }
67 /* HELP management starts here ...
68 */
70 /* Generate helpobject */
71 if(isset($_SESSION['helpobject'])){
72 $helpobject = $_SESSION['helpobject'];
73 }else{
74 $helpobject['lang'] = $lang;
75 $helpobject['helpconf'] = array();
76 $helpobject['currentplug'] = "";
77 $helpobject['file'] = "index.html";
78 $helpobject['helpconf'] = $_SESSION['plist']->gen_headlines();
79 }
81 $lang = $lang[0].$lang[1];
83 $helpobject['lang'] = $lang;
84 $defaultpage = "index.html"; // alternative file, shown on error, or on first call
85 $prefix = "node"; // Prefix of the generated help files
86 $suffix = ".html"; // Suffix of the generated helpfiles
87 $maxresults = 10; // max number of results shown in result list
88 $minwordlength = 3; // Word less than 3 chars will be dropped in search
89 $allowed_chars_in_searchword = "'[^a-z0-9 %_-]'i"; // Remove all chars that would disturb our search like < or > ...
91 /* Default pages */
92 $backward =$defaultpage;
93 $index =$defaultpage;
94 $forward ="node1.html";
96 /* Every class which is called within a tab, stores its name in the Session.
97 * If $_SESSION['current_class_for_help'] isset,
98 * get the helpfile specified in the xml file and display it.
99 * Unset this Session entry, to avoid displaying it again.
100 */
101 if(isset($_SESSION['current_class_for_help'])){
103 /* Create new XML parser with the path to the Xml file */
104 $xml = new parseXml("../doc/guide.xml");
106 /* Generate help array */
107 $str = $xml->parse();
109 /* __LANG__ is used as placeholder for the used language*/
110 $helpdir= preg_replace("/__LANG__/i",$lang,$str[($_SESSION['current_class_for_help'])]['PATH']);
112 /* If there is no entry in the xml file for this class, display an error message */
113 if($helpdir == ""){
115 $smarty->assign("help_contents","<br><h2>"._("There is no helpfile specified for this class"))."</h2>";
116 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
117 $display= ( $header.$smarty->fetch(get_template_path('help.tpl')));
118 echo $display;
119 unset($_SESSION['current_class_for_help']);
120 exit();
121 }
123 /* Save filename */
124 $helpobject['file']= $str[($_SESSION['current_class_for_help'])]['FILE'];
126 /* Save path to the file */
127 $helpobject['currentplug'] = $helpdir;
129 /* Avoid displaying the same help every time */
130 if(isset($_GET['pg'])){
131 unset($_SESSION['current_class_for_help']);
132 }
134 }elseif(isset($_GET['plug'])){
135 /* This displays helpfiles depending on the current $_GET[plug] */
136 $tmp = new pluglist($_SESSION['config'],NULL);
137 $path = $tmp->get_path($_GET['plug']);
138 $helpobject['currentplug'] = $path;
139 $helpobject['file'] = "index.html";
140 $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
141 if(empty($helpobject['currentplug'])){
142 $helpdir= "";
143 }
144 }
145 /* this Post var is set if another page is requested */
146 if(isset($_GET['pg'])){
148 if(preg_match("/\//",$_GET['pg'])){
149 $arr = split("\/",$_GET['pg']);
150 $helpobject['currentplug'] = "../doc/guide/user/".$helpobject['lang']."/html/".$arr[0];
151 $helpdir = $helpobject['currentplug'];
152 $helpobject['file']= $arr[1];
153 }else{
154 /* PG should contain a filename */
155 $helpobject['file'] = $_GET['pg'];
158 /* If empty, force displaying the index */
159 if(empty($_GET['pg'])){
160 $helpobject['currentplug'] = "";
161 $helpobject['file'] = "index.html";
162 }
163 /* Create new helpdir (The path where the requested page is located)*/
164 $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
166 /* If helpdir is empty, force index */
167 if(empty($helpobject['currentplug'])){
168 $helpdir= "";
169 }
170 }
171 }
173 $helpdir.="/";
175 /* Save current settings */
176 $_SESSION['helpobject'] = $helpobject;
178 /*
179 * Display management
180 */
182 /* If there is no helpdir or file defined, display the index */
183 if(isset($_POST['search'])){
184 $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/";
185 /* read all available directories */
186 $index = readfiles($helpdir,$prefix,$suffix,false,false);
187 $smarty->assign("help_contents",((searchlist($index,search($index,$_POST['search_string']),10))));
188 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
190 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
191 $display= ( $header.$smarty->fetch(get_template_path('help.tpl')));
192 echo $display;
193 }elseif(((empty($helpdir)))||($helpdir=="/")){
194 /* Generate Index and display it */
195 $smarty->assign("help_contents",genIndex());
196 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
198 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
199 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
200 echo $display;
202 }elseif((is_dir($helpdir))&&($fp = opendir($helpdir))){
204 /* Readfile gets the content of the requested file,
205 * parse it, rework links images and so on */
206 $index = readfiles($helpdir,$prefix,$suffix,false,$helpobject['file']);
208 /* if this page is result from a search, mark the search strings */
209 if(isset($_GET['mark'])){
210 $matches = $_SESSION['lastresults'][preg_replace("/^.*\//i","",$helpobject['currentplug'])][$helpobject['file']];
211 $index[$helpobject['file']]['content'] = markup_page($index[$helpobject['file']]['content'],$matches);
212 }
214 /* Display the help contents */
215 $smarty->assign("help_contents",$index[$helpobject['file']]['content']);
216 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
218 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
219 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
220 echo $display;
222 }else{
224 /* There was a file requested which actually doesn't exists */
225 $smarty->assign("help_contents","<h2>".sprintf(_("Helpdir '%s' is not accessible, can't read any helpfiles."),$helpdir))."</h2><br>";
226 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
227 $display= ( $header.$smarty->fetch(get_template_path('help.tpl')));
228 echo $display;
229 }
230 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
231 ?>