1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
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 */
21 /* Basic setup, remove eventually registered sessions */
22 require_once ("../include/php_setup.inc");
23 require_once ("../include/functions.inc");
25 session_start ();
26 error_reporting(E_ALL);
27 /* Logged in? Simple security check */
28 if (!isset($_SESSION['ui'])){
29 gosa_log ("Error: helpviewer.php called without session");
30 echo "<b>"._("Help is not available if you are not logged in.")."</b>";
31 exit;
32 }
35 /* Set template compile directory */
36 $config= $_SESSION['config'];
37 if (isset ($config->data['MAIN']['COMPILE'])){
38 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
39 } else {
40 $smarty->compile_dir= '/var/spool/gosa/';
41 }
43 /* Language setup */
44 if ($config->data['MAIN']['LANG'] == ""){
45 $lang= get_browser_language();
46 } else {
47 $lang= $config->data['MAIN']['LANG'];
48 }
49 $lang.=".UTF-8";
50 putenv("LANGUAGE=");
51 putenv("LANG=$lang");
52 setlocale(LC_ALL, $lang);
53 $GLOBALS['t_language']= $lang;
54 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
56 /* Set the text domain as 'messages' */
57 $domain = 'messages';
58 bindtextdomain($domain, "$BASE_DIR/locale");
59 textdomain($domain);
60 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
62 /* Get plugin list */
63 $plist= $_SESSION['plist'];
65 /*
66 ##################
67 My PART ^^
68 ##################
70 */
71 set_error_handler("myone");
73 $defaultpage = "index.html";
74 $prefix = "node";
75 $suffix = ".html";
77 function myone($par1,$par2,$par3,$par3)
78 {
79 print "<br>Seite : ".$par1."<br>Name : ".$par2."<br>Seite : ".$par3."<br>Zeile : ".$par3;
80 }
83 /* Define which tags musst be delete, header, navigation, banner */
84 $i=0;
85 $replacements=array();
86 $replacements['range'][$i]['from'] = "/<!DOC.*<BODY >/";
87 $replacements['range'][$i]['to'] = "";
88 $i++;
89 $replacements['range'][$i]['from'] = "@<DIV[^>]*?>.*?DIV>@si";
90 $replacements['range'][$i]['to'] = "";
91 $i++;
92 $replacements['range'][$i]['from'] = "/<HR>/";
93 $replacements['range'][$i]['to'] = "";
94 $i++;
95 $replacements['range'][$i]['from'] = "@<ADDRESS[^>]*?>.*?ADDRESS>@si";
96 $replacements['range'][$i]['to'] = "";
97 $i++;
98 $replacements['range'][$i]['from'] = "/<\/BODY.*>/";
99 $replacements['range'][$i]['to'] = "";
100 $i++;
102 /* Bsp . : Replace Table Head to our headline */
103 $replacements['range'][$i]['from'] = "@<TABLE[^>]*?>.*?>@si";
104 $replacements['range'][$i]['to'] = "<table border=0 cellspacing=1 bgcolor=\"#999999\" width=\"95%\" align=\"center\" >" ;
106 /* Default pages */
107 $backward ="index.html";
108 $index ="index.html";
109 $forward ="node1.html";
111 /* Read all files, prepare to serach */
112 $helppages = readfiles("../doc/guide/admin/en/manual_gosa_en/",$prefix,true,$suffix);
114 if(isset($_GET['pg'])){
115 $page = $_GET['pg'];
116 }
118 if(!isset($helppages[$page]))
119 {
120 print "Requested helppage is unknown, redirekted to index";
121 $page = $defaultpage;
122 }
124 /* Check forward backward, funtionality*/
125 if($page != $defaultpage)
126 {
127 /* Extract Number of node page */
128 $number = str_replace($prefix,"",str_replace($suffix,"",$page));
130 /* Check if we can switch forward and/or backward*/
131 $bck = $prefix.($number-1).$suffix;
132 $fck = $prefix.($number+1).$suffix;
134 /* backward page exists ?, so allow it*/
135 if((isset($helppages[$bck]))) {
136 $backward = $bck;
137 }
139 /* forward exists ?*/
140 if((isset($helppages[$fck]))) {
141 $forward = $fck;
142 }
143 }
145 //$help_contents=htmlentities(remove_unwanted_tags($helppages[$page]['content'],$replacements));
147 $help_contents=readfiles("../doc/guide/admin/en/manual_gosa_en/",$prefix,$suffix,false,$page);
148 $help_contents=remove_unwanted_tags($help_contents[$page]['content'],$replacements);
150 $smarty->assign("help_contents",$help_contents);
152 /* Define our own navigation pages */
153 $smarty->assign("backward",$backward);
154 $smarty->assign("index" ,$index);
155 $smarty->assign("forward" ,$forward);
157 /* Fill page */
158 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
159 $display= $header.$smarty->fetch(get_template_path('help.tpl'));
160 echo $display;
163 /* Reads all files in specified directory with contents an some inforations about the file */
164 function readfiles($basedir,$prefix,$suffix,$onlyIndex,$singlepage=false)
165 {
166 $str = array(); // Temporary variable
167 $cnt = 0; // Array index creation
168 $file = ""; // Contains Filename
170 $dir = opendir($basedir);
172 $str['global']['start'] = $cnt; // collect basic informations - Startpage
173 $str['global']['basedir'] = $basedir; // collect basic informations - Basedirectory
175 /* Startime for Benchmark */
176 $start = (time()+microtime());
177 if(!$singlepage) {
178 while (($file = readdir($dir)) !== false) {
179 if((stristr($file,".html"))&&($file!=".")&&($file!="..")){
180 $str[$file]=array();
181 $str[$file]['name'] = $file;
182 $str[$file]['size'] = filesize($basedir.$file);
183 if(!$onlyIndex){
184 $str[$file]['content']= linkwrapper(getcontents($basedir.$file),"");
185 }
186 $str[$file]['stat'] = stat($basedir.$file);
187 $cnt++;
188 }
189 }
190 }else{
191 $file = $singlepage;
192 $str[$file]=array();
193 $str[$file]['name'] = $file;
194 $str[$file]['size'] = filesize($basedir.$file);
195 if(!$onlyIndex){
196 $str[$file]['content']= linkwrapper(getcontents($basedir.$file),"");
197 }
198 $str[$file]['stat'] = stat($basedir.$file);
199 }
201 /* Create right order */
202 asort($str);
203 /* Endtime for Benchmark*/
204 $end = (time()+microtime());
205 $str['global']['cmptime'] = $end-$start;
206 $str['global']['numpages']= $cnt;
207 closedir($dir);
208 return($str);
209 }
211 /* Read filecontent */
212 function getcontents($file)
213 {
214 $str = "" ; // Temporary variable for file contents
215 $tmp = "" ; // Temporary varibale for partitial file contents
216 $fp = fopen($file,"r");
217 if($fp) {
218 while($tmp = fread($fp,512))
219 {
220 $str.= $tmp;
221 }
222 }else{
223 return(false);
224 }
225 return($str);
226 }
228 function remove_unwanted_tags($str,$replacements)
229 {
230 $str=str_replace("\n","||WasBr||",$str);
231 foreach($replacements['range'] as $var)
232 {
233 $str=preg_replace($var['from'],$var['to'],$str);
234 }
236 $str=str_replace("||WasBr||","\n",$str);
237 return($str);
238 }
240 /*Converts the all links to specified path, is needed to get simple navigation */
241 function linkwrapper($str,$link)
242 {
243 $str=str_replace("HREF=\"","href=\"".$link."?pg=",$str);
244 return($str);
245 }
247 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
248 ?>