1 <?php
2 error_reporting(0);
3 /*
4 This code is part of GOsa (https://gosa.gonicus.de)
5 Copyright (C) 2003 Cajus Pollmeier, Fabian Hickert
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
22 /* Include classes and configs */
23 require_once ("../include/php_setup.inc");
24 require_once ("functions.inc");
25 require_once ("functions_helpviewer.inc");
27 header("Content-type: text/html; charset=UTF-8");
28 session_start();
30 /* If no config object is found in the session, abort help */
31 if (!isset($_SESSION['config'])){
32 gosa_log ("main.php called without session");
33 header ("Location: index.php");
34 exit;
35 }
37 /* Language setup */
38 if ($config->data['MAIN']['LANG'] == ""){
39 $lang= get_browser_language();
40 } else {
41 $lang= $config->data['MAIN']['LANG'];
42 }
44 $lang.=".UTF-8";
45 putenv("LANGUAGE=");
46 putenv("LANG=$lang");
47 setlocale(LC_ALL, $lang);
48 $GLOBALS['t_language']= $lang;
49 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
51 $domain = 'messages';
52 bindtextdomain($domain, "$BASE_DIR/locale");
53 textdomain($domain);
54 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
56 $config= $_SESSION['config'];
57 if (isset ($config->data['MAIN']['COMPILE'])){
58 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
59 } else {
60 $smarty->compile_dir= '/var/spool/gosa/';
61 }
65 /* HELP management starts here ...
66 */
69 /* Generate helpobject */
70 if(isset($_SESSION['helpobject'])){
71 $helpobject = $_SESSION['helpobject'];
72 }else{
73 $helpobject['lang'] = "en";
74 $helpobject['helpconf'] = array();
75 $helpobject['currentplug'] = "";
76 $helpobject['file'] = "index.html";
77 $helpobject['helpconf'] = $_SESSION['plist']->gen_headlines();
78 }
80 $lang = preg_replace("/_.*$/","",get_browser_language());
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";
95 /* Every class which is called within a tab, stores its name in the Session.
96 * If $_SESSION['current_class_for_help'] isset,
97 * get the helpfile specified in the xml file and display it.
98 * Unset this Session entry, to avoid displaying it again.
99 */
100 if(isset($_SESSION['current_class_for_help'])){
102 /* Create new XML parser with the path to the Xml file */
103 $xml = new parseXml("../doc/guide.xml");
105 /* Generate help array */
106 $str = $xml->parse();
108 /* __LANG__ is used as placeholder for the used language*/
109 $helpdir= preg_replace("/__LANG__/i",$lang,$str[($_SESSION['current_class_for_help'])]['PATH']);
111 /* If there is no entry in the xml file for this class, display an error message */
112 if($helpdir == ""){
114 $smarty->assign("help_contents","<br><h2>"._("There is no helpfile specified for this class."))."</h2>";
115 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
116 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
117 echo $display;
118 unset($_SESSION['current_class_for_help']);
119 exit();
120 }
122 /* Save filename */
123 $helpobject['file']= $str[($_SESSION['current_class_for_help'])]['FILE'];
125 /* Save path to the file */
126 $helpobject['currentplug'] = $helpdir;
128 /* Avoid displaying the same help every time */
129 unset($_SESSION['current_class_for_help']);
131 }elseif(isset($_GET['plug'])){
132 /* This displays helpfiles depending on the current $_GET[plug] */
133 $tmp = new pluglist($_SESSION['config'],NULL);
134 $path = $tmp->get_path($_GET['plug']);
135 $helpobject['currentplug'] = $path;
136 $helpobject['file'] = "index.html";
137 $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
138 if(empty($helpobject['currentplug'])){
139 $helpdir= "";
140 }
141 }
142 /* this Post var is set if another page is requested */
143 if(isset($_GET['pg'])){
145 if(preg_match("/\//",$_GET['pg'])){
146 $arr = split("\/",$_GET['pg']);
147 $helpobject['currentplug'] = "../doc/guide/user/".$helpobject['lang']."/html/".$arr[0];
148 $helpdir = $helpobject['currentplug'];
149 $helpobject['file']= $arr[1];
150 }else{
151 /* PG should contain a filename */
152 $helpobject['file'] = $_GET['pg'];
155 /* If empty, force displaying the index */
156 if(empty($_GET['pg'])){
157 $helpobject['currentplug'] = "";
158 $helpobject['file'] = "index.html";
159 }
160 /* Create new helpdir (The path where the requested page is located)*/
161 $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
163 /* If helpdir is empty, force index */
164 if(empty($helpobject['currentplug'])){
165 $helpdir= "";
166 }
167 }
168 }
170 $helpdir.="/";
172 /* Save current settings */
173 $_SESSION['helpobject'] = $helpobject;
175 /*
176 * Display management
177 */
179 /* If there is no helpdir or file defined, display the index */
180 if(isset($_POST['search'])){
181 $helpdir = "../doc/guide/user/".$helpobject['lang']."/html/";
182 /* read all available directories */
183 $index = readfiles($helpdir,$prefix,$suffix,false,false);
184 $smarty->assign("help_contents",((searchlist($index,search($index,$_POST['search_string']),10))));
185 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
187 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
188 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
189 echo $display;
190 }elseif(((empty($helpdir)))||($helpdir=="/")){
191 /* Generate Index and display it */
192 $smarty->assign("help_contents",genIndex());
193 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
195 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
196 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
197 echo $display;
199 }elseif((is_dir($helpdir))&&($fp = opendir($helpdir))){
201 /* Readfile gets the content of the requested file,
202 * parse it, rework links images and so on */
203 $index = readfiles($helpdir,$prefix,$suffix,false,$helpobject['file']);
205 /* if this page is result from a search, mark the search strings */
206 if(isset($_GET['mark'])){
207 $matches = $_SESSION['lastresults'][preg_replace("/^.*\//i","",$helpobject['currentplug'])][$helpobject['file']];
208 $index[$helpobject['file']]['content'] = markup_page($index[$helpobject['file']]['content'],$matches);
209 }
211 /* Display the help contents */
212 $smarty->assign("help_contents",$index[$helpobject['file']]['content']);
213 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
215 /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
216 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
217 echo $display;
219 }else{
221 /* There was a file requested which actually doesn't exists */
222 $smarty->assign("help_contents","<h2>".sprintf(_("Helpdir '%s' is not accessible, can't read any helpfiles."),$helpdir))."</h2><br>";
223 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
224 $display= utf8_encode( $header.$smarty->fetch(get_template_path('help.tpl')));
225 echo $display;
226 }
227 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
228 ?>