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