Code

removed images.
[gosa.git] / gosa-core / html / helpviewer.php
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 /* Include classes and configs */
24 @require_once ("../include/php_setup.inc");
25 @require_once ("functions.inc");
26 @require_once ("functions_helpviewer.inc");
28 error_reporting(E_ALL | E_STRICT);
29 restore_error_handler();
30 header("Content-type: text/html; charset=UTF-8");
32 session::start();
34 /* If no config object is found in the session, abort help */
35 if (!session::is_set('config')){
36   new log("security","all/all","",array(),"Help viewer called without session") ;
37   header ("Location: index.php");
38   exit;
39 }
41 $ui= session::get('ui');
42 $config= session::get('config');
44 /* Language setup */
45 if ($config->data['MAIN']['LANG'] == ""){
46   $lang= get_browser_language();
47 } else {
48   $lang= $config->data['MAIN']['LANG'];
49 }
51 $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 $domain = 'messages';
60 bindtextdomain($domain, LOCALE_DIR);
61 textdomain($domain);
62 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
64 $config= session::get('config');
65 if (isset ($config->data['MAIN']['COMPILE'])){
66   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
67 } else {
68   $smarty->compile_dir= '/var/spool/gosa/';
69 }
70 $smarty->assign("title", "GOsa - "._("Help browser"));
72 /* HELP management starts here ...
73  */
75 /* Generate helpobject */
76 if(session::is_set('helpobject')){
77   $helpobject = session::get('helpobject');
78 }else{
80   $plist = session::get('plist');
82   $helpobject['lang']         = $lang; 
83   $helpobject['helpconf']     = array();  
84   $helpobject['currentplug']  = "";
85   $helpobject['file']         = "index.html";
86   $helpobject['helpconf']     = $plist->gen_headlines();
87 }
89 $lang = $lang[0].$lang[1];
91 $helpobject['lang']           = $lang;  
92 $defaultpage                  = "index.html";                       // alternative file, shown on error, or on first call
93 $prefix                       = "node";                             // Prefix of the generated help files 
94 $suffix                       = ".html";                            // Suffix of the generated helpfiles
95 $maxresults                   = 10;                                 // max number of results shown in result list
96 $minwordlength                = 3;                                  // Word less than 3 chars will be dropped in search
97 $allowed_chars_in_searchword  = "'[^a-z0-9 %_-]'i";                 // Remove all chars that would disturb our search like < or > ...
99 /* Default pages */
100 $backward =$defaultpage;
101 $index    =$defaultpage;
102 $forward  ="node1.html";
104 $helpdir ="";
105 /* Every class which is called within a tab, stores its name in the Session.
106  * If session::is_set('current_class_for_help') is true, 
107  *  get the helpfile specified in the xml file and display it.
108  * Unset this Session entry, to avoid displaying it again.
109  */
110 if(session::is_set('current_class_for_help')){
112   /* Create new XML parser with the path to the Xml file */
113   $xml = new parseXml("../doc/guide.xml");
114   
115   /* Generate help array */
116   $str = $xml->parse();
118   /* __LANG__ is used as placeholder for the used language*/
119   $helpdir= @preg_replace("/__LANG__/i",$lang,$str[(session::get('current_class_for_help'))]['PATH']);
121   /* If there is no entry in the xml file for this class, display an error message */
122   if($helpdir == ""){
123     
124     $smarty->assign("help_contents","<br><h2>"._("There is no helpfile specified for this class"))."</h2>";
125     $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
126     $display= (  $header.$smarty->fetch(get_template_path('help.tpl')));
127     echo $display;
128     session::un_set('current_class_for_help');
129     exit();  
130   }
131  
132   /* Save filename */
133   $helpobject['file']= $str[(session::get('current_class_for_help'))]['FILE'];
134   
135   /* Save path to the file */
136   $helpobject['currentplug']  = $helpdir;
137   
138   /* Avoid displaying the same help every time */
139   if(isset($_GET['pg'])){
140     session::un_set('current_class_for_help');
141   }
143 }elseif(isset($_GET['plug'])){
144   /* This displays helpfiles depending on the current $_GET[plug] */
145   $ui= get_userinfo();
146   $tmp                          = new pluglist(session::get('config'), $ui);
147   $path                         = $tmp->get_path($_GET['plug']);
148   $helpobject['currentplug']    = $path;
149   $helpobject['file']           = "index.html";
150   $helpdir = "../doc/core/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
151   if(empty($helpobject['currentplug'])){
152     $helpdir= "";
153   }
155 /* this Post var is set if another page is requested */
156 if(isset($_GET['pg'])){
157  
158   if(preg_match("/\//",$_GET['pg'])){
159     $arr = split("\/",$_GET['pg']);
160     $helpobject['currentplug'] = "../doc/core/".$helpobject['lang']."/html/".$arr[0];
161     $helpdir = $helpobject['currentplug'];
162     $helpobject['file']= $arr[1];
163   }else{
164     /* PG should contain a filename */
165     $helpobject['file'] = $_GET['pg'];
168     /* If empty, force displaying the index */
169     if(empty($_GET['pg'])){
170       $helpobject['currentplug']  = "";
171       $helpobject['file'] = "index.html";
172     }
173     /* Create new helpdir (The path where the requested page is located)*/
174     $helpdir = "../doc/core/".$helpobject['lang']."/html/".preg_replace("/^.*\//i","",$helpobject['currentplug']);
176     /* If helpdir is empty, force index */
177     if(empty($helpobject['currentplug'])){
178       $helpdir= "";
179     }
180   }
182 $helpdir.="/";
184 /* Save current settings */
185 session::set('helpobject',$helpobject);
187 /* 
188  * Display management 
189  */
191 $files = array();
192 $f = opendir($helpdir);
193 while($file = readdir($f)){
194   $files[$file]=$file;
197 /* Some replacements */
198 $backwardlink  = "<a href=\"?pg=%s\"  class=\"maintitlebar\">
199                   <img src='images/back.png' class=\"center\" align=\"middle\" alt=\""._("previous")."\" border=\"0\">
200                  </a>";
202 $forwardlink   = "<a href=\"?pg=%s\"  class=\"maintitlebar\">
203                   <img src='images/forward.png' class=\"center\" align=\"middle\" alt=\""._("next")."\" border=\"0\">
204                  </a>";
207 $back = $for  ="";
208 if($helpobject['file'] == "index.html"){
209   $back = "&nbsp;";
210   $for  = sprintf($forwardlink,   $prefix."1".$suffix);
211 }else{
212   $current = preg_replace("/^".$prefix."/","",$helpobject['file']);
213   $current = preg_replace("/\.html$/","",$current);
214  
215   if(isset($files[$prefix.($current+1).$suffix])) {
216     $for  = sprintf($forwardlink,    $prefix.($current+1).$suffix);
217   }
218   if(isset($files[$prefix.($current-1).$suffix])) {
219     $back = sprintf($backwardlink,   $prefix.($current-1).$suffix);
220   }
221   if(($current-1) == 0){
222     $back = sprintf($backwardlink,   "index.html");
223   }
227 /* If there is no helpdir or file defined, display the index */
228 if(isset($_POST['search'])){
229   $helpdir = "../doc/core/".$helpobject['lang']."/html/";
230   /* read all available directories */
231   $index = readfiles($helpdir,$prefix,$suffix,false,false);
232   $smarty->assign("help_contents",((searchlist($index,search($index,$_POST['search_string']),10))));
233   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
235   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
236   $display= (  $header.$smarty->fetch(get_template_path('help.tpl')));
237   echo $display;
238 }elseif(((empty($helpdir)))||($helpdir=="/")){
239   /* Generate Index and display it */
240   $smarty->assign("help_contents",genIndex());
241   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
243   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
244   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
245   echo $display;
247 }elseif((is_dir($helpdir))&&($fp = opendir($helpdir))){
248   
249   /* Readfile gets the content of the requested file, 
250    * parse it, rework links images and so on */
251   $index = readfiles($helpdir,$prefix,$suffix,false,$helpobject['file']);
253   $lastresults = session::get('lastresults');
255   /* if this page is result from a search, mark the search strings */
256   if(isset($_GET['mark'])){
257     $matches = $lastresults[preg_replace("/^.*\//i","",$helpobject['currentplug'])][$helpobject['file']];
258     $index[$helpobject['file']]['content']   = markup_page($index[$helpobject['file']]['content'],$matches);
259   }
261   /* Display the help contents */
262   $smarty->assign("help_contents",$index[$helpobject['file']]['content']);
263   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
264   
265   /* I don't know why, but we must use utf8_encode to avoid dispplay errors */
266   $smarty->assign("backward",$back);
267   $smarty->assign("forward" ,$for);
268   $display= utf8_encode(  $header.$smarty->fetch(get_template_path('help.tpl')));
269   echo $display;
271 }else{
272   
273   /* There was a file requested which actually doesn't exists */
274   $smarty->assign("help_contents","<h2>".sprintf(_("Helpdir '%s' is not accessible, can't read any helpfiles."),$helpdir))."</h2><br>";
275   $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
276   $display= (  $header.$smarty->fetch(get_template_path('help.tpl')));
277   echo $display;
279 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
280 ?>