Code

Unified Error message display
[gosa.git] / html / helpviewer.php
index ceaa5161ead20f62c4345907b85909f8f55ffa6a..4e031663283feb4827216e9dc25e08185f6fc0ce 100644 (file)
 require_once ("../include/php_setup.inc");
 require_once ("functions.inc");
 require_once ("functions_helpviewer.inc");
+header("Content-type: text/html; charset=UTF-8");
 
 session_start ();
 error_reporting(E_ALL);
 
-/* Logged in? Simple security check */
-if (!isset($_SESSION['ui'])){
-  gosa_log ("Error: helpviewer.php called without session");
-  echo "<b>"._("Help is not available if you are not logged in.")."</b>";
-  exit;
-}
-
-/* Set template compile directory */
-$config= $_SESSION['config'];
-if (isset ($config->data['MAIN']['COMPILE'])){
-  $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
-} else {
-  $smarty->compile_dir= '/var/spool/gosa/';
-}
-
 /* Language setup */
 if ($config->data['MAIN']['LANG'] == ""){
   $lang= get_browser_language();
@@ -61,6 +47,22 @@ bindtextdomain($domain, "$BASE_DIR/locale");
 textdomain($domain);
 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
 
+
+/* Logged in? Simple security check */
+if (!isset($_SESSION['ui'])){
+  gosa_log ("Error: helpviewer.php called without session");
+  echo "<b>"._("Help is not available if you are not logged in.")."</b>";
+  exit;
+}
+
+/* Set template compile directory */
+$config= $_SESSION['config'];
+if (isset ($config->data['MAIN']['COMPILE'])){
+  $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
+} else {
+  $smarty->compile_dir= '/var/spool/gosa/';
+}
+
 /* Get plugin list */
 $plist= $_SESSION['plist'];
 
@@ -70,7 +72,6 @@ My PART ^^
 ##################
  */
 
-set_error_handler("myone");
 $helpdir                      = HELP_BASEDIR."/en/manual_gosa_en/"; // Folder to use for help files
 $defaultpage                  = "index.html";                       // alternative file, shown on error, or on first call
 $prefix                       = "node";                             // Prefix of the generated help files 
@@ -78,33 +79,48 @@ $suffix                       = ".html";                            // Suffix of
 $maxresults                   = 10;                                 // max number of results shown in result list
 $minwordlength                = 3;                                  // Word less than 3 chars will be dropped in search
 $allowed_chars_in_searchword  = "'[^a-z0-9 %_-]'i";                 // Remove all chars that would disturb our search like < or > ...
-$pre_mark                     = "<b><u><i>" ;                       // Sign words with this
-$suf_mark                     = "</i></u></b>";                     //  and this
+$pre_mark                     = "<span style=\"background-color: #FFFC35;\">" ;                       // Sign words with this
+$suf_mark                     = "</span>";                          //  and this
+$backwardlink                 = "<a href=\"?pg=%s\"  class=\"maintitlebar\">
+                                  <img src='images/back.png' align=\"middle\" alt=\""._("previous")."\" border=\"0\">
+                                 </a>";
 
-// Only for testing delete this if everything works fine
-function myone($par1,$par2,$par3,$par3)
-{
-  print "<br>Seite : ".$par1."<br>Name : ".$par2."<br>Seite : ".$par3."<br>Zeile : ".$par3;
-}
+$forwardlink                 = "<a href=\"?pg=%s\"  class=\"maintitlebar\">
+                                  <img src='images/forward.png' align=\"middle\" alt=\""._("next")."\" border=\"0\">
+                                 </a>";
 
 /* Define which tags musst be delete, header, navigation, banner */
 $replacements=array();
 $replacements['from']=array("@<!DOC.*<BODY >@si",
-                            "@<DIV[^>]*?>.*?DIV>@si",
-                            "'<code.*code>'",
-                            "/<HR>/",
-                            "@<ADDRESS[^>]*?>.*?ADDRESS>@si",
-                            "@<\/BODY[^>]*?>.*?HTML>@si",
-                            "'<TABLE.*>'",
-                            "/<H1 ALIGN=\"CENTER\">/");
+    "/border=\".*\"/i",
+    "'<code.*code>'",
+//    "/alt=\".*\"/i",
+    "/<HR>/",
+    "@<ADDRESS[^>]*?>.*?ADDRESS>@si",
+    "@<\/BODY[^>]*?>.*?HTML>@si",
+    "'<TABLE.*>'",
+    "/src.*icons/i",
+    "/src=\"/i",
+    "/<H1 ALIGN=\"CENTER\">/",
+ /* picture replacements */
+ //  "",
+    );
+
+
 $replacements['to']=array("",
-                          "",
-                          "",
-                          "",
-                          "",
-                          "",
-                          "<table border=1 cellspacing=0 bgcolor=\"#E0E0E0\" width=\"95%\" align=\"center\" cellpadding=\"3\">",
-                          "<H1>");
+    " border=\"0\" ",
+    "",
+  //  "",
+    "",
+    "",
+    "",
+    "<table border=1 cellspacing=0 bgcolor=\"#E0E0E0\" width=\"95%\" align=\"center\" cellpadding=\"3\">",
+    "src=\"",
+    "src=\"images/",
+    "<H1>",
+ /* picture replacements */
+//    "",
+  );
 
 
 /* Default pages */
@@ -115,116 +131,158 @@ $forward  ="node1.html";
 /*
    Here it begins, the real function, above only definitions
  */
-/* We prepare to search, all Document for the given keyword */
-if(isset($_POST['search'])){
 
-  /* Get Keyword */
-  $keyword = $_POST['search_string'];  
+if(!file_exists(HELP_BASEDIR."/en/manual_gosa_en/")){
+  /* prevent php warning missing value ... or so*/
+  $smarty->assign("backward","");
+  $smarty->assign("index"   ,"");
+  $smarty->assign("forward" ,"");
+  $smarty->assign("search_string","");
+  $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/"));
+
+  /* Output html ...*/
+  $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
+  $display= $header.$smarty->fetch(get_template_path('help.tpl'));
+  echo $display;
 
-  /* Save Keyword to be able to show last searched word in template */
-  $_SESSION['search_string']= $keyword;
+}else{  
 
-  /* Read all files with contents*/
-  /*               |Folder="/var/ww...", 
-                   |        |Fileprefix="node"
-                   |        |       |Filesuffix=".html"
-                   |        |       |       |WithoutContent=false(This means : read content)
-                   |        |       |       |     |Singlepage=false(Means read all, if w want to read single, specify its filename)"*/
-  $arr = readfiles($helpdir,$prefix,$suffix,false,$singlepage=false);
+  /* We prepare to search, all Document for the given keyword */
+  if(isset($_POST['search'])){
 
-  /* Create Searchresult for our Keyword(s) */
-  $res = search($arr,$keyword); 
+    /* Get Keyword */
+    $keyword = $_POST['search_string'];  
 
-  /* Tell smarty which pages to use for backward forwa.. */
-  $smarty->assign("backward",$backward);
-  $smarty->assign("index"   ,$index);
-  $smarty->assign("forward" ,$forward);
+    /* Save Keyword to be able to show last searched word in template */
+    $_SESSION['search_string']= $keyword;
 
-  /* Tell smarty the Keyword, to show it in the input field again */
-  $smarty->assign("search_string",$keyword);
+    /* Read all files with contents*/
+    /*               |Folder="/var/ww...", 
+                     |        |Fileprefix="node"
+                     |        |       |Filesuffix=".html"
+                     |        |       |       |WithoutContent=false(This means : read content)
+                     |        |       |       |     |Singlepage=false(Means read all, if w want to read single, specify its filename)"*/
+    $arr = readfiles($helpdir,$prefix,$suffix,false,$singlepage=false);
 
-  /* Create result list */
-  $smarty->assign("help_contents",searchlist($arr,$res,$maxresults));
+    /* Create Searchresult for our Keyword(s) */
+    $res = search($arr,$keyword); 
 
-  /* Output html ...*/
-  $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
-  $display= $header.$smarty->fetch(get_template_path('help.tpl'));
-  echo $display;
+    /* Tell smarty which pages to use for backward forwa.. */
+    $smarty->assign("backward","");
+    $smarty->assign("index"   ,$index);
+    $smarty->assign("forward" ,"");
 
-  /*
-     Don't search, only show selected page
-   */
-}else{
+    /* Tell smarty the Keyword, to show it in the input field again */
+    $smarty->assign("search_string",$keyword);
 
-  /* present last searched word(s)*/
-  if(!isset($_SESSION['search_string'])){
-    $_SESSION['search_string']="";
-  }
-    
+    /* Create result list */
+    $smarty->assign("help_contents",searchlist($arr,$res,$maxresults));
 
-  $smarty->assign("search_string",$_SESSION['search_string']);
+    /* show some errors */
+    if (isset($_SESSION['errors'])){
+      $smarty->assign("errors", $_SESSION['errors']);
+    }
+    if ($error_collector != ""){
+      $smarty->assign("php_errors", $error_collector."</div>");
+    } else {
+      $smarty->assign("php_errors", "");
+    }
 
-  /* Read all files, prepare to serach */
-  $helppages = readfiles($helpdir,$prefix,$suffix,true);
+    /* Output html ...*/
+    $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
+    $display= $header.$smarty->fetch(get_template_path('help.tpl'));
+    echo $display;
 
-  /* Get transmitted page */
-  if(isset($_GET['pg'])){
-    $page = $_GET['pg'];
+    /*
+       Don't search, only show selected page
+     */
   }else{
-    $page = $defaultpage;
-  }
 
-  /* test if this page exists, in our array of files */
-  if((!isset($helppages[$page]))&&($page!=$defaultpage))
-  {
-    //print "Requested helppage is unknown, redirekted to index"; // For debugging only
-    $page = $defaultpage;
-  }
+    /* present last searched word(s)*/
+    if(!isset($_SESSION['search_string'])){
+      $_SESSION['search_string']="";
+    }
+
 
-  /* Check forward backward, funtionality*/
-  if($page != $defaultpage)
-  {
-    /* Extract Number of node page */
-    $number = str_replace($prefix,"",str_replace($suffix,"",$page));
+    $smarty->assign("search_string",$_SESSION['search_string']);
 
-    /* Check if we can switch forward and/or backward*/ 
-    $bck = $prefix.($number-1).$suffix;
-    $fck = $prefix.($number+1).$suffix;
+    /* Read all files, prepare to serach */
+    $helppages = readfiles($helpdir,$prefix,$suffix,true);
 
-    /* backward page exists ?, so allow it*/
-    if((isset($helppages[$bck]))) {
-      $backward = $bck;
+    /* Get transmitted page */
+    if(isset($_GET['pg'])){
+      $page = $_GET['pg'];
+    }else{
+      $page = $defaultpage;
+    }
+    
+    /* test if this page exists, in our array of files */
+    if((!isset($helppages[$page]))&&($page!=$defaultpage))
+    {
+      //print "Requested helppage is unknown, redirekted to index"; // For debugging only
+      $page = $defaultpage;
     }
 
-    /* forward exists ?*/
-    if((isset($helppages[$fck])))  {
+    /* Check forward backward, funtionality*/
+    if($page != $defaultpage)
+    {
+      /* Extract Number of node page */
+      $number = str_replace($prefix,"",str_replace($suffix,"",$page));
+
+      /* Check if we can switch forward and/or backward*/ 
+      $bck = $prefix.($number-1).$suffix;
+      $fck = $prefix.($number+1).$suffix;
+
+      /* backward page exists ?, so allow it*/
+      if((isset($helppages[$bck]))) {
+        $backward = $bck;
+      }
+
       $forward  = $fck;
     }
-  }
 
-  $help_contents=readfiles($helpdir,$prefix,$suffix,false,$page);
+    $help_contents=readfiles($helpdir,$prefix,$suffix,false,$page);
 
-  /* Mark last searched words */
-  if(isset($_GET['mark'])){
-    $marks = ($_SESSION['lastresults']) ; 
-    $help_contents = markup_page($help_contents[$page]['content'],$marks[$page]);
-    $help_contents=remove_unwanted_tags($help_contents,$replacements);  
-  }else{
-    $help_contents=remove_unwanted_tags($help_contents[$page]['content'],$replacements);
-  }
+    /* Mark last searched words */
+    if(isset($_GET['mark'])){
+      $marks = ($_SESSION['lastresults']) ; 
+      $help_contents = markup_page($help_contents[$page]['content'],$marks[$page]);
+      $help_contents=$help_contents;  
+    }else{
+      $help_contents=$help_contents[$page]['content'];
+    }
 
-  $smarty->assign("help_contents",$help_contents);
+    $smarty->assign("help_contents",$help_contents);
 
-  /* Define our own navigation pages */
-  $smarty->assign("backward",$backward);
-  $smarty->assign("index"   ,$index);
-  $smarty->assign("forward" ,$forward);
+    /* Define our own navigation pages */
+    if($page == $defaultpage){
+      $smarty->assign("backward","");
+    }else{
+      $smarty->assign("backward",sprintf($backwardlink,$backward));
+    }
+    $smarty->assign("index"   ,$index);
+  
+    if(!(isset($helppages[$forward]))){
+      $smarty->assign("forward","");
+    }else{
+      $smarty->assign("forward",sprintf($forwardlink,$forward));
+    }
 
-  /* Fill page */
-  $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
-  $display= $header.$smarty->fetch(get_template_path('help.tpl'));
-  echo $display;
-}
+    /* show some errors */
+    if (isset($_SESSION['errors'])){
+      $smarty->assign("errors", $_SESSION['errors']);
+    }
+    if ($error_collector != ""){
+      $smarty->assign("php_errors", $error_collector."</div>");
+    } else {
+      $smarty->assign("php_errors", "");
+    }
 
+    /* Fill page */
+    $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
+    $display= $header.$smarty->fetch(get_template_path('help.tpl'));
+    echo $display;
+  }
+}
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>