a9a26825ae6019ab772c90d81d645e91b24a4890
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");
27 session_start ();
28 error_reporting(E_ALL);
30 /* Logged in? Simple security check */
31 if (!isset($_SESSION['ui'])){
32 gosa_log ("Error: helpviewer.php called without session");
33 echo "<b>"._("Help is not available if you are not logged in.")."</b>";
34 exit;
35 }
37 /* Set template compile directory */
38 $config= $_SESSION['config'];
39 if (isset ($config->data['MAIN']['COMPILE'])){
40 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
41 } else {
42 $smarty->compile_dir= '/var/spool/gosa/';
43 }
45 /* Language setup */
46 if ($config->data['MAIN']['LANG'] == ""){
47 $lang= get_browser_language();
48 } else {
49 $lang= $config->data['MAIN']['LANG'];
50 }
51 $lang.=".UTF-8";
52 putenv("LANGUAGE=");
53 putenv("LANG=$lang");
54 setlocale(LC_ALL, $lang);
55 $GLOBALS['t_language']= $lang;
56 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
58 /* Set the text domain as 'messages' */
59 $domain = 'messages';
60 bindtextdomain($domain, "$BASE_DIR/locale");
61 textdomain($domain);
62 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
64 /* Get plugin list */
65 $plist= $_SESSION['plist'];
67 /*
68 ##################
69 My PART ^^
70 ##################
71 */
73 set_error_handler("myone");
74 $helpdir = HELP_BASEDIR."/en/manual_gosa_en/"; // Folder to use for help files
75 $defaultpage = "index.html"; // alternative file, shown on error, or on first call
76 $prefix = "node"; // Prefix of the generated help files
77 $suffix = ".html"; // Suffix of the generated helpfiles
78 $maxresults = 10; // max number of results shown in result list
79 $minwordlength = 3; // Word less than 3 chars will be dropped in search
80 $allowed_chars_in_searchword = "'[^a-z0-9 %_-]'i"; // Remove all chars that would disturb our search like < or > ...
81 $pre_mark = "<b><u><i>" ; // Sign words with this
82 $suf_mark = "</i></u></b>"; // and this
84 // Only for testing delete this if everything works fine
85 function myone($par1,$par2,$par3,$par3)
86 {
87 print "<br>Seite : ".$par1."<br>Name : ".$par2."<br>Seite : ".$par3."<br>Zeile : ".$par3;
88 }
91 /* Define which tags musst be delete, header, navigation, banner */
92 $replacements=array();
93 $replacements['from']=array("@<!DOC.*<BODY >@si",
94 "@<DIV[^>]*?>.*?DIV>@si",
95 "'<code.*code>'",
96 "/<HR>/",
97 "@<ADDRESS[^>]*?>.*?ADDRESS>@si",
98 "@<\/BODY[^>]*?>.*?HTML>@si",
99 "'<TABLE.*>'",
100 "/<H1 ALIGN=\"CENTER\">/");
101 $replacements['to']=array("",
102 "",
103 "",
104 "",
105 "",
106 "",
107 "<table border=1 cellspacing=0 bgcolor=\"#E0E0E0\" width=\"95%\" align=\"center\" cellpadding=\"3\">",
108 "<H1>");
111 /* Default pages */
112 $backward =$defaultpage;
113 $index =$defaultpage;
114 $forward ="node1.html";
116 /*
117 Here it begins, the real function, above only definitions
118 */
120 if(!file_exists(HELP_BASEDIR."/en/manual_gosa_en/")){
121 /* prevent php warning missing value ... or so*/
122 $smarty->assign("backward","");
123 $smarty->assign("index" ,"");
124 $smarty->assign("forward" ,"");
125 $smarty->assign("search_string","");
126 $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/"));
128 /* Output html ...*/
129 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
130 $display= $header.$smarty->fetch(get_template_path('help.tpl'));
131 echo $display;
134 }else{
136 /* We prepare to search, all Document for the given keyword */
137 if(isset($_POST['search'])){
139 /* Get Keyword */
140 $keyword = $_POST['search_string'];
142 /* Save Keyword to be able to show last searched word in template */
143 $_SESSION['search_string']= $keyword;
145 /* Read all files with contents*/
146 /* |Folder="/var/ww...",
147 | |Fileprefix="node"
148 | | |Filesuffix=".html"
149 | | | |WithoutContent=false(This means : read content)
150 | | | | |Singlepage=false(Means read all, if w want to read single, specify its filename)"*/
151 $arr = readfiles($helpdir,$prefix,$suffix,false,$singlepage=false);
153 /* Create Searchresult for our Keyword(s) */
154 $res = search($arr,$keyword);
156 /* Tell smarty which pages to use for backward forwa.. */
157 $smarty->assign("backward",$backward);
158 $smarty->assign("index" ,$index);
159 $smarty->assign("forward" ,$forward);
161 /* Tell smarty the Keyword, to show it in the input field again */
162 $smarty->assign("search_string",$keyword);
164 /* Create result list */
165 $smarty->assign("help_contents",searchlist($arr,$res,$maxresults));
167 /* Output html ...*/
168 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
169 $display= $header.$smarty->fetch(get_template_path('help.tpl'));
170 echo $display;
172 /*
173 Don't search, only show selected page
174 */
175 }else{
177 /* present last searched word(s)*/
178 if(!isset($_SESSION['search_string'])){
179 $_SESSION['search_string']="";
180 }
183 $smarty->assign("search_string",$_SESSION['search_string']);
185 /* Read all files, prepare to serach */
186 $helppages = readfiles($helpdir,$prefix,$suffix,true);
188 /* Get transmitted page */
189 if(isset($_GET['pg'])){
190 $page = $_GET['pg'];
191 }else{
192 $page = $defaultpage;
193 }
195 /* test if this page exists, in our array of files */
196 if((!isset($helppages[$page]))&&($page!=$defaultpage))
197 {
198 //print "Requested helppage is unknown, redirekted to index"; // For debugging only
199 $page = $defaultpage;
200 }
202 /* Check forward backward, funtionality*/
203 if($page != $defaultpage)
204 {
205 /* Extract Number of node page */
206 $number = str_replace($prefix,"",str_replace($suffix,"",$page));
208 /* Check if we can switch forward and/or backward*/
209 $bck = $prefix.($number-1).$suffix;
210 $fck = $prefix.($number+1).$suffix;
212 /* backward page exists ?, so allow it*/
213 if((isset($helppages[$bck]))) {
214 $backward = $bck;
215 }
217 /* forward exists ?*/
218 if((isset($helppages[$fck]))) {
219 $forward = $fck;
220 }
221 }
223 $help_contents=readfiles($helpdir,$prefix,$suffix,false,$page);
225 /* Mark last searched words */
226 if(isset($_GET['mark'])){
227 $marks = ($_SESSION['lastresults']) ;
228 $help_contents = markup_page($help_contents[$page]['content'],$marks[$page]);
229 $help_contents=remove_unwanted_tags($help_contents,$replacements);
230 }else{
231 $help_contents=remove_unwanted_tags($help_contents[$page]['content'],$replacements);
232 }
234 $smarty->assign("help_contents",$help_contents);
236 /* Define our own navigation pages */
237 $smarty->assign("backward",$backward);
238 $smarty->assign("index" ,$index);
239 $smarty->assign("forward" ,$forward);
241 /* Fill page */
242 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
243 $display= $header.$smarty->fetch(get_template_path('help.tpl'));
244 echo $display;
245 }
246 }
247 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
248 ?>