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 /* Define which tags musst be delete, header, navigation, banner */
93 $replacements=array();
94 $replacements['from']=array("@<!DOC.*<BODY >@si",
95 "/border=\".*\"/i",
96 "'<code.*code>'",
97 // "/alt=\".*\"/i",
98 "/<HR>/",
99 "@<ADDRESS[^>]*?>.*?ADDRESS>@si",
100 "@<\/BODY[^>]*?>.*?HTML>@si",
101 "'<TABLE.*>'",
102 "/src.*icons/i",
103 "/src=\"/i",
104 "/<H1 ALIGN=\"CENTER\">/",
105 /* picture replacements */
106 // "",
107 );
110 $replacements['to']=array("",
111 " border=\"0\" ",
112 "",
113 // "",
114 "",
115 "",
116 "",
117 "<table border=1 cellspacing=0 bgcolor=\"#E0E0E0\" width=\"95%\" align=\"center\" cellpadding=\"3\" summary=\"\">",
118 "src=\"",
119 "src=\"images/",
120 "<H1>",
121 /* picture replacements */
122 // "",
123 );
126 /* Default pages */
127 $backward =$defaultpage;
128 $index =$defaultpage;
129 $forward ="node1.html";
131 /*
132 Here it begins, the real function, above only definitions
133 */
135 if(!file_exists(HELP_BASEDIR."/en/manual_gosa_en/")){
136 /* prevent php warning missing value ... or so*/
137 $smarty->assign("backward","");
138 $smarty->assign("index" ,"");
139 $smarty->assign("forward" ,"");
140 $smarty->assign("search_string","");
141 $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/"));
143 /* Output html ...*/
144 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
145 $display= $header.$smarty->fetch(get_template_path('help.tpl'));
146 echo $display;
148 }else{
150 /* We prepare to search, all Document for the given keyword */
151 if(isset($_POST['search'])){
153 /* Get Keyword */
154 $keyword = $_POST['search_string'];
156 /* Save Keyword to be able to show last searched word in template */
157 $_SESSION['search_string']= $keyword;
159 /* Read all files with contents*/
160 /* |Folder="/var/ww...",
161 | |Fileprefix="node"
162 | | |Filesuffix=".html"
163 | | | |WithoutContent=false(This means : read content)
164 | | | | |Singlepage=false(Means read all, if w want to read single, specify its filename)"*/
165 $arr = readfiles($helpdir,$prefix,$suffix,false,$singlepage=false);
167 /* Create Searchresult for our Keyword(s) */
168 $res = search($arr,$keyword);
170 /* Tell smarty which pages to use for backward forwa.. */
171 $smarty->assign("backward","");
172 $smarty->assign("index" ,$index);
173 $smarty->assign("forward" ,"");
175 /* Tell smarty the Keyword, to show it in the input field again */
176 $smarty->assign("search_string",$keyword);
178 /* Create result list */
179 $smarty->assign("help_contents",searchlist($arr,$res,$maxresults));
181 /* show some errors */
182 if (isset($_SESSION['errors'])){
183 $smarty->assign("errors", $_SESSION['errors']);
184 }
185 if ($error_collector != ""){
186 $smarty->assign("php_errors", $error_collector."</div>");
187 } else {
188 $smarty->assign("php_errors", "");
189 }
191 /* Output html ...*/
192 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
193 $display= $header.$smarty->fetch(get_template_path('help.tpl'));
194 echo $display;
196 /*
197 Don't search, only show selected page
198 */
199 }else{
201 /* present last searched word(s)*/
202 if(!isset($_SESSION['search_string'])){
203 $_SESSION['search_string']="";
204 }
207 $smarty->assign("search_string",$_SESSION['search_string']);
209 /* Read all files, prepare to serach */
210 $helppages = readfiles($helpdir,$prefix,$suffix,true);
212 /* Get transmitted page */
213 if(isset($_GET['pg'])){
214 $page = $_GET['pg'];
215 }else{
216 $page = $defaultpage;
217 }
219 /* test if this page exists, in our array of files */
220 if((!isset($helppages[$page]))&&($page!=$defaultpage))
221 {
222 //print "Requested helppage is unknown, redirekted to index"; // For debugging only
223 $page = $defaultpage;
224 }
226 /* Check forward backward, funtionality*/
227 if($page != $defaultpage)
228 {
229 /* Extract Number of node page */
230 $number = str_replace($prefix,"",str_replace($suffix,"",$page));
232 /* Check if we can switch forward and/or backward*/
233 $bck = $prefix.($number-1).$suffix;
234 $fck = $prefix.($number+1).$suffix;
236 /* backward page exists ?, so allow it*/
237 if((isset($helppages[$bck]))) {
238 $backward = $bck;
239 }
241 $forward = $fck;
242 }
244 $help_contents=readfiles($helpdir,$prefix,$suffix,false,$page);
246 /* Mark last searched words */
247 if(isset($_GET['mark'])){
248 $marks = ($_SESSION['lastresults']) ;
249 $help_contents = markup_page($help_contents[$page]['content'],$marks[$page]);
250 $help_contents=$help_contents;
251 }else{
252 $help_contents=$help_contents[$page]['content'];
253 }
255 $smarty->assign("help_contents",$help_contents);
257 /* Define our own navigation pages */
258 if($page == $defaultpage){
259 $smarty->assign("backward","");
260 }else{
261 $smarty->assign("backward",sprintf($backwardlink,$backward));
262 }
263 $smarty->assign("index" ,$index);
265 if(!(isset($helppages[$forward]))){
266 $smarty->assign("forward","");
267 }else{
268 $smarty->assign("forward",sprintf($forwardlink,$forward));
269 }
271 /* show some errors */
272 if (isset($_SESSION['errors'])){
273 $smarty->assign("errors", $_SESSION['errors']);
274 }
275 if ($error_collector != ""){
276 $smarty->assign("php_errors", $error_collector."</div>");
277 } else {
278 $smarty->assign("php_errors", "");
279 }
281 /* Fill page */
282 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
283 $display= $header.$smarty->fetch(get_template_path('help.tpl'));
284 echo $display;
285 }
286 }
287 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
288 ?>