Code

Added error handler
[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                     = "<b><u><i>" ;                       // Sign words with this
81 $suf_mark                     = "</i></u></b>";                     //  and this
83 $error_collector= "";
84 set_error_handler('gosaRaiseError');
86 /* Define which tags musst be delete, header, navigation, banner */
87 $replacements=array();
88 $replacements['from']=array("@<!DOC.*<BODY >@si",
89     "@<DIV[^>]*?>.*?DIV>@si",
90     "'<code.*code>'",
91     "/<HR>/",
92     "@<ADDRESS[^>]*?>.*?ADDRESS>@si",
93     "@<\/BODY[^>]*?>.*?HTML>@si",
94     "'<TABLE.*>'",
95     "/<H1 ALIGN=\"CENTER\">/");
96 $replacements['to']=array("",
97     "",
98     "",
99     "",
100     "",
101     "",
102     "<table border=1 cellspacing=0 bgcolor=\"#E0E0E0\" width=\"95%\" align=\"center\" cellpadding=\"3\">",
103     "<H1>");
106 /* Default pages */
107 $backward =$defaultpage;
108 $index    =$defaultpage;
109 $forward  ="node1.html";
111 /*
112    Here it begins, the real function, above only definitions
113  */
115 if(!file_exists(HELP_BASEDIR."/en/manual_gosa_en/")){
116   /* prevent php warning missing value ... or so*/
117   $smarty->assign("backward","");
118   $smarty->assign("index"   ,"");
119   $smarty->assign("forward" ,"");
120   $smarty->assign("search_string","");
121   $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/"));
123   /* Output html ...*/
124   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
125   $display= $header.$smarty->fetch(get_template_path('help.tpl'));
126   echo $display;
128 }else{  
130   /* We prepare to search, all Document for the given keyword */
131   if(isset($_POST['search'])){
133     /* Get Keyword */
134     $keyword = $_POST['search_string'];  
136     /* Save Keyword to be able to show last searched word in template */
137     $_SESSION['search_string']= $keyword;
139     /* Read all files with contents*/
140     /*               |Folder="/var/ww...", 
141                      |        |Fileprefix="node"
142                      |        |       |Filesuffix=".html"
143                      |        |       |       |WithoutContent=false(This means : read content)
144                      |        |       |       |     |Singlepage=false(Means read all, if w want to read single, specify its filename)"*/
145     $arr = readfiles($helpdir,$prefix,$suffix,false,$singlepage=false);
147     /* Create Searchresult for our Keyword(s) */
148     $res = search($arr,$keyword); 
150     /* Tell smarty which pages to use for backward forwa.. */
151     $smarty->assign("backward",$backward);
152     $smarty->assign("index"   ,$index);
153     $smarty->assign("forward" ,$forward);
155     /* Tell smarty the Keyword, to show it in the input field again */
156     $smarty->assign("search_string",$keyword);
158     /* Create result list */
159     $smarty->assign("help_contents",searchlist($arr,$res,$maxresults));
161     /* show some errors */
162     if (isset($_SESSION['errors'])){
163       $smarty->assign("errors", $_SESSION['errors']);
164     }
165     if ($error_collector != ""){
166       $smarty->assign("php_errors", $error_collector."</div>");
167     } else {
168       $smarty->assign("php_errors", "");
169     }
171     /* Output html ...*/
172     $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
173     $display= $header.$smarty->fetch(get_template_path('help.tpl'));
174     echo $display;
176     /*
177        Don't search, only show selected page
178      */
179   }else{
181     /* present last searched word(s)*/
182     if(!isset($_SESSION['search_string'])){
183       $_SESSION['search_string']="";
184     }
187     $smarty->assign("search_string",$_SESSION['search_string']);
189     /* Read all files, prepare to serach */
190     $helppages = readfiles($helpdir,$prefix,$suffix,true);
192     /* Get transmitted page */
193     if(isset($_GET['pg'])){
194       $page = $_GET['pg'];
195     }else{
196       $page = $defaultpage;
197     }
199     /* test if this page exists, in our array of files */
200     if((!isset($helppages[$page]))&&($page!=$defaultpage))
201     {
202       //print "Requested helppage is unknown, redirekted to index"; // For debugging only
203       $page = $defaultpage;
204     }
206     /* Check forward backward, funtionality*/
207     if($page != $defaultpage)
208     {
209       /* Extract Number of node page */
210       $number = str_replace($prefix,"",str_replace($suffix,"",$page));
212       /* Check if we can switch forward and/or backward*/ 
213       $bck = $prefix.($number-1).$suffix;
214       $fck = $prefix.($number+1).$suffix;
216       /* backward page exists ?, so allow it*/
217       if((isset($helppages[$bck]))) {
218         $backward = $bck;
219       }
221       /* forward exists ?*/
222       if((isset($helppages[$fck])))  {
223         $forward  = $fck;
224       }
225     }
227     $help_contents=readfiles($helpdir,$prefix,$suffix,false,$page);
229     /* Mark last searched words */
230     if(isset($_GET['mark'])){
231       $marks = ($_SESSION['lastresults']) ; 
232       $help_contents = markup_page($help_contents[$page]['content'],$marks[$page]);
233       $help_contents=remove_unwanted_tags($help_contents,$replacements);  
234     }else{
235       $help_contents=remove_unwanted_tags($help_contents[$page]['content'],$replacements);
236     }
238     $smarty->assign("help_contents",$help_contents);
240     /* Define our own navigation pages */
241     $smarty->assign("backward",$backward);
242     $smarty->assign("index"   ,$index);
243     $smarty->assign("forward" ,$forward);
245     /* show some errors */
246     if (isset($_SESSION['errors'])){
247       $smarty->assign("errors", $_SESSION['errors']);
248     }
249     if ($error_collector != ""){
250       $smarty->assign("php_errors", $error_collector."</div>");
251     } else {
252       $smarty->assign("php_errors", "");
253     }
255     /* Fill page */
256     $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
257     $display= $header.$smarty->fetch(get_template_path('help.tpl'));
258     echo $display;
259   }
261 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
262 ?>