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 */
22 /* Basic setup, remove eventually registered sessions */
23 require_once ("../include/php_setup.inc");
24 require_once ("functions.inc");
25 require_once ("functions_helpviewer.inc");
26 header("Content-type: text/html; charset=UTF-8");
28 session_start ();
29 error_reporting(E_ALL);
31 /* Language setup */
32 if ($config->data['MAIN']['LANG'] == ""){
33 $lang= get_browser_language();
34 } else {
35 $lang= $config->data['MAIN']['LANG'];
36 }
37 $lang.=".UTF-8";
38 putenv("LANGUAGE=");
39 putenv("LANG=$lang");
40 setlocale(LC_ALL, $lang);
41 $GLOBALS['t_language']= $lang;
42 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
44 /* Set the text domain as 'messages' */
45 $domain = 'messages';
46 bindtextdomain($domain, "$BASE_DIR/locale");
47 textdomain($domain);
48 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
51 /* Logged in? Simple security check */
52 if (!isset($_SESSION['ui'])){
53 gosa_log ("Error: helpviewer.php called without session");
54 echo "<b>"._("Help is not available if you are not logged in.")."</b>";
55 exit;
56 }
58 /* Set template compile directory */
59 $config= $_SESSION['config'];
60 if (isset ($config->data['MAIN']['COMPILE'])){
61 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
62 } else {
63 $smarty->compile_dir= '/var/spool/gosa/';
64 }
66 /* Get plugin list */
67 $plist= $_SESSION['plist'];
69 /*
70 ##################
71 My PART ^^
72 ##################
73 */
75 $helpdir = HELP_BASEDIR."/en/manual_gosa_en/"; // Folder to use for help files
76 $defaultpage = "index.html"; // alternative file, shown on error, or on first call
77 $prefix = "node"; // Prefix of the generated help files
78 $suffix = ".html"; // Suffix of the generated helpfiles
79 $maxresults = 10; // max number of results shown in result list
80 $minwordlength = 3; // Word less than 3 chars will be dropped in search
81 $allowed_chars_in_searchword = "'[^a-z0-9 %_-]'i"; // Remove all chars that would disturb our search like < or > ...
82 $pre_mark = "<span style=\"background-color: #FFFC35;\">" ; // Sign words with this
83 $suf_mark = "</span>"; // and this
84 $backwardlink = "<a href=\"?pg=%s\" class=\"maintitlebar\">
85 <img src='images/back.png' align=\"middle\" alt=\""._("previous")."\" border=\"0\">
86 </a>";
88 $forwardlink = "<a href=\"?pg=%s\" class=\"maintitlebar\">
89 <img src='images/forward.png' align=\"middle\" alt=\""._("next")."\" border=\"0\">
90 </a>";
92 $error_collector= "";
93 set_error_handler('gosaRaiseError');
95 /* Define which tags musst be delete, header, navigation, banner */
96 $replacements=array();
97 $replacements['from']=array("@<!DOC.*<BODY >@si",
98 "/border=\".*\"/i",
99 "'<code.*code>'",
100 // "/alt=\".*\"/i",
101 "/<HR>/",
102 "@<ADDRESS[^>]*?>.*?ADDRESS>@si",
103 "@<\/BODY[^>]*?>.*?HTML>@si",
104 "'<TABLE.*>'",
105 "/src.*icons/i",
106 "/src=\"/i",
107 "/<H1 ALIGN=\"CENTER\">/",
108 /* picture replacements */
109 // "",
110 );
113 $replacements['to']=array("",
114 " border=\"0\" ",
115 "",
116 // "",
117 "",
118 "",
119 "",
120 "<table border=1 cellspacing=0 bgcolor=\"#E0E0E0\" width=\"95%\" align=\"center\" cellpadding=\"3\">",
121 "src=\"",
122 "src=\"images/",
123 "<H1>",
124 /* picture replacements */
125 // "",
126 );
129 /* Default pages */
130 $backward =$defaultpage;
131 $index =$defaultpage;
132 $forward ="node1.html";
134 /*
135 Here it begins, the real function, above only definitions
136 */
138 if(!file_exists(HELP_BASEDIR."/en/manual_gosa_en/")){
139 /* prevent php warning missing value ... or so*/
140 $smarty->assign("backward","");
141 $smarty->assign("index" ,"");
142 $smarty->assign("forward" ,"");
143 $smarty->assign("search_string","");
144 $smarty->assign("help_contents","<br>".sprintf(_("Can't read any helpfiles from ' %s ', possibly there is no help available."),HELP_BASEDIR."/en/manual_gosa_en/"));
146 /* Output html ...*/
147 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
148 $display= $header.$smarty->fetch(get_template_path('help.tpl'));
149 echo $display;
151 }else{
153 /* We prepare to search, all Document for the given keyword */
154 if(isset($_POST['search'])){
156 /* Get Keyword */
157 $keyword = $_POST['search_string'];
159 /* Save Keyword to be able to show last searched word in template */
160 $_SESSION['search_string']= $keyword;
162 /* Read all files with contents*/
163 /* |Folder="/var/ww...",
164 | |Fileprefix="node"
165 | | |Filesuffix=".html"
166 | | | |WithoutContent=false(This means : read content)
167 | | | | |Singlepage=false(Means read all, if w want to read single, specify its filename)"*/
168 $arr = readfiles($helpdir,$prefix,$suffix,false,$singlepage=false);
170 /* Create Searchresult for our Keyword(s) */
171 $res = search($arr,$keyword);
173 /* Tell smarty which pages to use for backward forwa.. */
174 $smarty->assign("backward","");
175 $smarty->assign("index" ,$index);
176 $smarty->assign("forward" ,"");
178 /* Tell smarty the Keyword, to show it in the input field again */
179 $smarty->assign("search_string",$keyword);
181 /* Create result list */
182 $smarty->assign("help_contents",searchlist($arr,$res,$maxresults));
184 /* show some errors */
185 if (isset($_SESSION['errors'])){
186 $smarty->assign("errors", $_SESSION['errors']);
187 }
188 if ($error_collector != ""){
189 $smarty->assign("php_errors", $error_collector."</div>");
190 } else {
191 $smarty->assign("php_errors", "");
192 }
194 /* Output html ...*/
195 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
196 $display= $header.$smarty->fetch(get_template_path('help.tpl'));
197 echo $display;
199 /*
200 Don't search, only show selected page
201 */
202 }else{
204 /* present last searched word(s)*/
205 if(!isset($_SESSION['search_string'])){
206 $_SESSION['search_string']="";
207 }
210 $smarty->assign("search_string",$_SESSION['search_string']);
212 /* Read all files, prepare to serach */
213 $helppages = readfiles($helpdir,$prefix,$suffix,true);
215 /* Get transmitted page */
216 if(isset($_GET['pg'])){
217 $page = $_GET['pg'];
218 }else{
219 $page = $defaultpage;
220 }
222 /* test if this page exists, in our array of files */
223 if((!isset($helppages[$page]))&&($page!=$defaultpage))
224 {
225 //print "Requested helppage is unknown, redirekted to index"; // For debugging only
226 $page = $defaultpage;
227 }
229 /* Check forward backward, funtionality*/
230 if($page != $defaultpage)
231 {
232 /* Extract Number of node page */
233 $number = str_replace($prefix,"",str_replace($suffix,"",$page));
235 /* Check if we can switch forward and/or backward*/
236 $bck = $prefix.($number-1).$suffix;
237 $fck = $prefix.($number+1).$suffix;
239 /* backward page exists ?, so allow it*/
240 if((isset($helppages[$bck]))) {
241 $backward = $bck;
242 }
244 $forward = $fck;
245 }
247 $help_contents=readfiles($helpdir,$prefix,$suffix,false,$page);
249 /* Mark last searched words */
250 if(isset($_GET['mark'])){
251 $marks = ($_SESSION['lastresults']) ;
252 $help_contents = markup_page($help_contents[$page]['content'],$marks[$page]);
253 $help_contents=$help_contents;
254 }else{
255 $help_contents=$help_contents[$page]['content'];
256 }
258 $smarty->assign("help_contents",$help_contents);
260 /* Define our own navigation pages */
261 if($page == $defaultpage){
262 $smarty->assign("backward","");
263 }else{
264 $smarty->assign("backward",sprintf($backwardlink,$backward));
265 }
266 $smarty->assign("index" ,$index);
268 if(!(isset($helppages[$forward]))){
269 $smarty->assign("forward","");
270 }else{
271 $smarty->assign("forward",sprintf($forwardlink,$forward));
272 }
274 /* show some errors */
275 if (isset($_SESSION['errors'])){
276 $smarty->assign("errors", $_SESSION['errors']);
277 }
278 if ($error_collector != ""){
279 $smarty->assign("php_errors", $error_collector."</div>");
280 } else {
281 $smarty->assign("php_errors", "");
282 }
284 /* Fill page */
285 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
286 $display= $header.$smarty->fetch(get_template_path('help.tpl'));
287 echo $display;
288 }
289 }
290 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
291 ?>