Code

renamed file, for fucntions helpviewer
[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  */
24 /* Basic setup, remove eventually registered sessions */
25 require_once ("../include/php_setup.inc");
26 require_once ("../include/functions.inc");
27 require_once ("../include/functions_helpviewer.inc");
28 session_start ();
29 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 }
38 /* Set template compile directory */
39 $config= $_SESSION['config'];
40 if (isset ($config->data['MAIN']['COMPILE'])){
41   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
42 } else {
43   $smarty->compile_dir= '/var/spool/gosa/';
44 }
46 /* Language setup */
47 if ($config->data['MAIN']['LANG'] == ""){
48   $lang= get_browser_language();
49 } else {
50   $lang= $config->data['MAIN']['LANG'];
51 }
52 $lang.=".UTF-8";
53 putenv("LANGUAGE=");
54 putenv("LANG=$lang");
55 setlocale(LC_ALL, $lang);
56 $GLOBALS['t_language']= $lang;
57 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
59 /* Set the text domain as 'messages' */
60 $domain = 'messages';
61 bindtextdomain($domain, "$BASE_DIR/locale");
62 textdomain($domain);
63 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
65 /* Get plugin list */
66 $plist= $_SESSION['plist'];
68 /*
69 ##################
70 My PART ^^
71 ##################
72  */
74 //set_error_handler("myone");
75 $helpdir                      = "../doc/guide/admin/en/manual_gosa_en/"; // Folder to use for help files
76 $defaultpage                  = "index.html";                            // alternative file, shown on error, or on first call
77 $prefix                       = "node";                                  // Prefix of the generated help files 
78 $suffix                       = ".html";                                 // Suffix of the generated helpfiles
79 $maxresults                   = 10;                                      // max number of results shown in result list
80 $minwordlength                = 3;                                       // Word less than 3 chars will be dropped in search
81 $allowed_chars_in_searchword  = "'[^a-z0-9 %_-]'i";                      // Remove all chars that would disturb our search like < or > ...
82 $pre_mark                     = "<b><u><i>" ;  // Sign words with this
83 $suf_mark                     = "</i></u></b>";                   //  and this
85 // Only for testing delete this if everything works fine
86 function myone($par1,$par2,$par3,$par3)
87 {
88   print "<br>Seite : ".$par1."<br>Name : ".$par2."<br>Seite : ".$par3."<br>Zeile : ".$par3;
89 }
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 $replacements['to']=array("",
101                           "",
102                           "",
103                           "",
104                           "",
105                           "",
106                           "<table border=1 cellspacing=0 bgcolor=\"#E0E0E0\" width=\"95%\" align=\"center\" cellpadding=\"3\">");
109 /* Default pages */
110 $backward =$defaultpage;
111 $index    =$defaultpage;
112 $forward  ="node1.html";
114 /*
115    Here it begins, the real function, above only definitions
116  */
117 /* We prepare to search, all Document for the given keyword */
118 if(isset($_POST['search'])){
120   /* Get Keyword */
121   $keyword = $_POST['search_string'];  
123   /* Save Keyword to be able to show last searched word in template */
124   $_SESSION['search_string']= $keyword;
126   /* Read all files with contents*/
127   /*               |Folder="/var/ww...", 
128                    |        |Fileprefix="node"
129                    |        |       |Filesuffix=".html"
130                    |        |       |       |WithoutContent=false(This means : read content)
131                    |        |       |       |     |Singlepage=false(Means read all, if w want to read single, specify its filename)"*/
132   $arr = readfiles($helpdir,$prefix,$suffix,false,$singlepage=false);
134   /* Create Searchresult for our Keyword(s) */
135   $res = search($arr,$keyword); 
137   /* Tell smarty which pages to use for backward forwa.. */
138   $smarty->assign("backward",$backward);
139   $smarty->assign("index"   ,$index);
140   $smarty->assign("forward" ,$forward);
142   /* Tell smarty the Keyword, to show it in the input field again */
143   $smarty->assign("search_string",$keyword);
145   /* Create result list */
146   $smarty->assign("help_contents",searchlist($arr,$res,$maxresults));
148   /* Output html ...*/
149   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
150   $display= $header.$smarty->fetch(get_template_path('help.tpl'));
151   echo $display;
153   /*
154      Don't search, only show selected page
155    */
156 }else{
158   /* present last searched word(s)*/
159   $smarty->assign("search_string",$_SESSION['search_string']);
161   /* Read all files, prepare to serach */
162   $helppages = readfiles("../doc/guide/admin/en/manual_gosa_en/",$prefix,$suffix,true);
164   /* Get transmitted page */
165   if(isset($_GET['pg'])){
166     $page = $_GET['pg'];
167   }
169   /* test if this page exists, in our array of files */
170   if((!isset($helppages[$page]))&&($page!=$defaultpage))
171   {
172     //print "Requested helppage is unknown, redirekted to index"; // For debugging only
173     $page = $defaultpage;
174   }
176   /* Check forward backward, funtionality*/
177   if($page != $defaultpage)
178   {
179     /* Extract Number of node page */
180     $number = str_replace($prefix,"",str_replace($suffix,"",$page));
182     /* Check if we can switch forward and/or backward*/ 
183     $bck = $prefix.($number-1).$suffix;
184     $fck = $prefix.($number+1).$suffix;
186     /* backward page exists ?, so allow it*/
187     if((isset($helppages[$bck]))) {
188       $backward = $bck;
189     }
191     /* forward exists ?*/
192     if((isset($helppages[$fck])))  {
193       $forward  = $fck;
194     }
195   }
197   $help_contents=readfiles($helpdir,$prefix,$suffix,false,$page);
199   /* Mark last searched words */
200   if(isset($_GET['mark'])){
201     $marks = ($_SESSION['lastresults']) ; 
202     $help_contents = markup_page($help_contents[$page]['content'],$marks[$page]);
203     $help_contents=remove_unwanted_tags($help_contents,$replacements);  
204   }else{
205     $help_contents=remove_unwanted_tags($help_contents[$page]['content'],$replacements);
206   }
208   $smarty->assign("help_contents",$help_contents);
210   /* Define our own navigation pages */
211   $smarty->assign("backward",$backward);
212   $smarty->assign("index"   ,$index);
213   $smarty->assign("forward" ,$forward);
215   /* Fill page */
216   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
217   $display= $header.$smarty->fetch(get_template_path('help.tpl'));
218   echo $display;
221 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
222 ?>