Code

Moved language definition up...
[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 /* Language setup */
31 if ($config->data['MAIN']['LANG'] == ""){
32   $lang= get_browser_language();
33 } else {
34   $lang= $config->data['MAIN']['LANG'];
35 }
36 $lang.=".UTF-8";
37 putenv("LANGUAGE=");
38 putenv("LANG=$lang");
39 setlocale(LC_ALL, $lang);
40 $GLOBALS['t_language']= $lang;
41 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
43 /* Set the text domain as 'messages' */
44 $domain = 'messages';
45 bindtextdomain($domain, "$BASE_DIR/locale");
46 textdomain($domain);
47 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
50 /* Logged in? Simple security check */
51 if (!isset($_SESSION['ui'])){
52   gosa_log ("Error: helpviewer.php called without session");
53   echo "<b>"._("Help is not available if you are not logged in.")."</b>";
54   exit;
55 }
57 /* Set template compile directory */
58 $config= $_SESSION['config'];
59 if (isset ($config->data['MAIN']['COMPILE'])){
60   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
61 } else {
62   $smarty->compile_dir= '/var/spool/gosa/';
63 }
65 /* Get plugin list */
66 $plist= $_SESSION['plist'];
68 /*
69 ##################
70 My PART ^^
71 ##################
72  */
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                     = "<span style=\"background-color: #FFFC35;\">" ;                       // Sign words with this
82 $suf_mark                     = "</span>";                          //  and this
83 $backwardlink                 = "<a href=\"?pg=%s\"  class=\"maintitlebar\">
84                                   <img src='images/back.png' align=\"middle\" alt=\""._("previous")."\" border=\"0\">
85                                  </a>";
87 $forwardlink                 = "<a href=\"?pg=%s\"  class=\"maintitlebar\">
88                                   <img src='images/forward.png' align=\"middle\" alt=\""._("next")."\" border=\"0\">
89                                  </a>";
91 $error_collector= "";
92 set_error_handler('gosaRaiseError');
94 /* Define which tags musst be delete, header, navigation, banner */
95 $replacements=array();
96 $replacements['from']=array("@<!DOC.*<BODY >@si",
97     "/border=\".*\"/i",
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     "<table border=1 cellspacing=0 bgcolor=\"#E0E0E0\" width=\"95%\" align=\"center\" cellpadding=\"3\">",
120     "src=\"",
121     "src=\"images/",
122     "<H1>",
123  /* picture replacements */
124 //    "",
125   );
128 /* Default pages */
129 $backward =$defaultpage;
130 $index    =$defaultpage;
131 $forward  ="node1.html";
133 /*
134    Here it begins, the real function, above only definitions
135  */
137 if(!file_exists(HELP_BASEDIR."/en/manual_gosa_en/")){
138   /* prevent php warning missing value ... or so*/
139   $smarty->assign("backward","");
140   $smarty->assign("index"   ,"");
141   $smarty->assign("forward" ,"");
142   $smarty->assign("search_string","");
143   $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/"));
145   /* Output html ...*/
146   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
147   $display= $header.$smarty->fetch(get_template_path('help.tpl'));
148   echo $display;
150 }else{  
152   /* We prepare to search, all Document for the given keyword */
153   if(isset($_POST['search'])){
155     /* Get Keyword */
156     $keyword = $_POST['search_string'];  
158     /* Save Keyword to be able to show last searched word in template */
159     $_SESSION['search_string']= $keyword;
161     /* Read all files with contents*/
162     /*               |Folder="/var/ww...", 
163                      |        |Fileprefix="node"
164                      |        |       |Filesuffix=".html"
165                      |        |       |       |WithoutContent=false(This means : read content)
166                      |        |       |       |     |Singlepage=false(Means read all, if w want to read single, specify its filename)"*/
167     $arr = readfiles($helpdir,$prefix,$suffix,false,$singlepage=false);
169     /* Create Searchresult for our Keyword(s) */
170     $res = search($arr,$keyword); 
172     /* Tell smarty which pages to use for backward forwa.. */
173     $smarty->assign("backward","");
174     $smarty->assign("index"   ,$index);
175     $smarty->assign("forward" ,"");
177     /* Tell smarty the Keyword, to show it in the input field again */
178     $smarty->assign("search_string",$keyword);
180     /* Create result list */
181     $smarty->assign("help_contents",searchlist($arr,$res,$maxresults));
183     /* show some errors */
184     if (isset($_SESSION['errors'])){
185       $smarty->assign("errors", $_SESSION['errors']);
186     }
187     if ($error_collector != ""){
188       $smarty->assign("php_errors", $error_collector."</div>");
189     } else {
190       $smarty->assign("php_errors", "");
191     }
193     /* Output html ...*/
194     $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
195     $display= $header.$smarty->fetch(get_template_path('help.tpl'));
196     echo $display;
198     /*
199        Don't search, only show selected page
200      */
201   }else{
203     /* present last searched word(s)*/
204     if(!isset($_SESSION['search_string'])){
205       $_SESSION['search_string']="";
206     }
209     $smarty->assign("search_string",$_SESSION['search_string']);
211     /* Read all files, prepare to serach */
212     $helppages = readfiles($helpdir,$prefix,$suffix,true);
214     /* Get transmitted page */
215     if(isset($_GET['pg'])){
216       $page = $_GET['pg'];
217     }else{
218       $page = $defaultpage;
219     }
220     
221     /* test if this page exists, in our array of files */
222     if((!isset($helppages[$page]))&&($page!=$defaultpage))
223     {
224       //print "Requested helppage is unknown, redirekted to index"; // For debugging only
225       $page = $defaultpage;
226     }
228     /* Check forward backward, funtionality*/
229     if($page != $defaultpage)
230     {
231       /* Extract Number of node page */
232       $number = str_replace($prefix,"",str_replace($suffix,"",$page));
234       /* Check if we can switch forward and/or backward*/ 
235       $bck = $prefix.($number-1).$suffix;
236       $fck = $prefix.($number+1).$suffix;
238       /* backward page exists ?, so allow it*/
239       if((isset($helppages[$bck]))) {
240         $backward = $bck;
241       }
243       $forward  = $fck;
244     }
246     $help_contents=readfiles($helpdir,$prefix,$suffix,false,$page);
248     /* Mark last searched words */
249     if(isset($_GET['mark'])){
250       $marks = ($_SESSION['lastresults']) ; 
251       $help_contents = markup_page($help_contents[$page]['content'],$marks[$page]);
252       $help_contents=$help_contents;  
253     }else{
254       $help_contents=$help_contents[$page]['content'];
255     }
257     $smarty->assign("help_contents",$help_contents);
259     /* Define our own navigation pages */
260     if($page == $defaultpage){
261       $smarty->assign("backward","");
262     }else{
263       $smarty->assign("backward",sprintf($backwardlink,$backward));
264     }
265     $smarty->assign("index"   ,$index);
266   
267     if(!(isset($helppages[$forward]))){
268       $smarty->assign("forward","");
269     }else{
270       $smarty->assign("forward",sprintf($forwardlink,$forward));
271     }
273     /* show some errors */
274     if (isset($_SESSION['errors'])){
275       $smarty->assign("errors", $_SESSION['errors']);
276     }
277     if ($error_collector != ""){
278       $smarty->assign("php_errors", $error_collector."</div>");
279     } else {
280       $smarty->assign("php_errors", "");
281     }
283     /* Fill page */
284     $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
285     $display= $header.$smarty->fetch(get_template_path('help.tpl'));
286     echo $display;
287   }
289 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
290 ?>