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