Code

images shown correct
[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     "@<DIV[^>]*?>.*?DIV>@si",
98     "'<code.*code>'",
99 //    "/alt=\".*\"/i",
100     "/<HR>/",
101     "@<ADDRESS[^>]*?>.*?ADDRESS>@si",
102     "@<\/BODY[^>]*?>.*?HTML>@si",
103     "'<TABLE.*>'",
104     "/src.*icons/i",
105     "/src=\"/i",
106     "/<H1 ALIGN=\"CENTER\">/",
107  /* picture replacements */
108  //  "",
109     );
112 $replacements['to']=array("",
113     " border=\"0\" ",
114     "",
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     }
221     
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);
267   
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   }
290 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
291 ?>