Code

Div deletion fixed
[gosa.git] / html / helpviewer.php
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 $helpdir                      = HELP_BASEDIR."/en/manual_gosa_en/"; // Folder to use for help files
74 $defaultpage                  = "index.html";                       // alternative file, shown on error, or on first call
75 $prefix                       = "node";                             // Prefix of the generated help files 
76 $suffix                       = ".html";                            // Suffix of the generated helpfiles
77 $maxresults                   = 10;                                 // max number of results shown in result list
78 $minwordlength                = 3;                                  // Word less than 3 chars will be dropped in search
79 $allowed_chars_in_searchword  = "'[^a-z0-9 %_-]'i";                 // Remove all chars that would disturb our search like < or > ...
80 $pre_mark                     = "<span style=\"background-color: #FFFC35;\">" ;                       // Sign words with this
81 $suf_mark                     = "</span>";                          //  and this
82 $backwardlink                 = "<a href=\"?pg=%s\"  class=\"maintitlebar\">
83                                   <img src='images/back.png' align=\"middle\" alt=\""._("previous")."\" border=\"0\">
84                                  </a>";
86 $forwardlink                 = "<a href=\"?pg=%s\"  class=\"maintitlebar\">
87                                   <img src='images/forward.png' align=\"middle\" alt=\""._("next")."\" border=\"0\">
88                                  </a>";
90 $error_collector= "";
91 set_error_handler('gosaRaiseError');
93 /* Define which tags musst be delete, header, navigation, banner */
94 $replacements=array();
95 $replacements['from']=array("@<!DOC.*<BODY >@si",
96     "/border=\".*\"/i",
97     "'<code.*code>'",
98 //    "/alt=\".*\"/i",
99     "/<HR>/",
100     "@<ADDRESS[^>]*?>.*?ADDRESS>@si",
101     "@<\/BODY[^>]*?>.*?HTML>@si",
102     "'<TABLE.*>'",
103     "/src.*icons/i",
104     "/src=\"/i",
105     "/<H1 ALIGN=\"CENTER\">/",
106  /* picture replacements */
107  //  "",
108     );
111 $replacements['to']=array("",
112     " border=\"0\" ",
113     "",
114   //  "",
115     "",
116     "",
117     "",
118     "<table border=1 cellspacing=0 bgcolor=\"#E0E0E0\" width=\"95%\" align=\"center\" cellpadding=\"3\">",
119     "src=\"",
120     "src=\"images/",
121     "<H1>",
122  /* picture replacements */
123 //    "",
124   );
127 /* Default pages */
128 $backward =$defaultpage;
129 $index    =$defaultpage;
130 $forward  ="node1.html";
132 /*
133    Here it begins, the real function, above only definitions
134  */
136 if(!file_exists(HELP_BASEDIR."/en/manual_gosa_en/")){
137   /* prevent php warning missing value ... or so*/
138   $smarty->assign("backward","");
139   $smarty->assign("index"   ,"");
140   $smarty->assign("forward" ,"");
141   $smarty->assign("search_string","");
142   $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/"));
144   /* Output html ...*/
145   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
146   $display= $header.$smarty->fetch(get_template_path('help.tpl'));
147   echo $display;
149 }else{  
151   /* We prepare to search, all Document for the given keyword */
152   if(isset($_POST['search'])){
154     /* Get Keyword */
155     $keyword = $_POST['search_string'];  
157     /* Save Keyword to be able to show last searched word in template */
158     $_SESSION['search_string']= $keyword;
160     /* Read all files with contents*/
161     /*               |Folder="/var/ww...", 
162                      |        |Fileprefix="node"
163                      |        |       |Filesuffix=".html"
164                      |        |       |       |WithoutContent=false(This means : read content)
165                      |        |       |       |     |Singlepage=false(Means read all, if w want to read single, specify its filename)"*/
166     $arr = readfiles($helpdir,$prefix,$suffix,false,$singlepage=false);
168     /* Create Searchresult for our Keyword(s) */
169     $res = search($arr,$keyword); 
171     /* Tell smarty which pages to use for backward forwa.. */
172     $smarty->assign("backward","");
173     $smarty->assign("index"   ,$index);
174     $smarty->assign("forward" ,"");
176     /* Tell smarty the Keyword, to show it in the input field again */
177     $smarty->assign("search_string",$keyword);
179     /* Create result list */
180     $smarty->assign("help_contents",searchlist($arr,$res,$maxresults));
182     /* show some errors */
183     if (isset($_SESSION['errors'])){
184       $smarty->assign("errors", $_SESSION['errors']);
185     }
186     if ($error_collector != ""){
187       $smarty->assign("php_errors", $error_collector."</div>");
188     } else {
189       $smarty->assign("php_errors", "");
190     }
192     /* Output html ...*/
193     $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
194     $display= $header.$smarty->fetch(get_template_path('help.tpl'));
195     echo $display;
197     /*
198        Don't search, only show selected page
199      */
200   }else{
202     /* present last searched word(s)*/
203     if(!isset($_SESSION['search_string'])){
204       $_SESSION['search_string']="";
205     }
208     $smarty->assign("search_string",$_SESSION['search_string']);
210     /* Read all files, prepare to serach */
211     $helppages = readfiles($helpdir,$prefix,$suffix,true);
213     /* Get transmitted page */
214     if(isset($_GET['pg'])){
215       $page = $_GET['pg'];
216     }else{
217       $page = $defaultpage;
218     }
219     
220     /* test if this page exists, in our array of files */
221     if((!isset($helppages[$page]))&&($page!=$defaultpage))
222     {
223       //print "Requested helppage is unknown, redirekted to index"; // For debugging only
224       $page = $defaultpage;
225     }
227     /* Check forward backward, funtionality*/
228     if($page != $defaultpage)
229     {
230       /* Extract Number of node page */
231       $number = str_replace($prefix,"",str_replace($suffix,"",$page));
233       /* Check if we can switch forward and/or backward*/ 
234       $bck = $prefix.($number-1).$suffix;
235       $fck = $prefix.($number+1).$suffix;
237       /* backward page exists ?, so allow it*/
238       if((isset($helppages[$bck]))) {
239         $backward = $bck;
240       }
242       $forward  = $fck;
243     }
245     $help_contents=readfiles($helpdir,$prefix,$suffix,false,$page);
247     /* Mark last searched words */
248     if(isset($_GET['mark'])){
249       $marks = ($_SESSION['lastresults']) ; 
250       $help_contents = markup_page($help_contents[$page]['content'],$marks[$page]);
251       $help_contents=$help_contents;  
252     }else{
253       $help_contents=$help_contents[$page]['content'];
254     }
256     $smarty->assign("help_contents",$help_contents);
258     /* Define our own navigation pages */
259     if($page == $defaultpage){
260       $smarty->assign("backward","");
261     }else{
262       $smarty->assign("backward",sprintf($backwardlink,$backward));
263     }
264     $smarty->assign("index"   ,$index);
265   
266     if(!(isset($helppages[$forward]))){
267       $smarty->assign("forward","");
268     }else{
269       $smarty->assign("forward",sprintf($forwardlink,$forward));
270     }
272     /* show some errors */
273     if (isset($_SESSION['errors'])){
274       $smarty->assign("errors", $_SESSION['errors']);
275     }
276     if ($error_collector != ""){
277       $smarty->assign("php_errors", $error_collector."</div>");
278     } else {
279       $smarty->assign("php_errors", "");
280     }
282     /* Fill page */
283     $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
284     $display= $header.$smarty->fetch(get_template_path('help.tpl'));
285     echo $display;
286   }
288 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
289 ?>