Happy New Year
[squirrelmail.git] / src / help.php
index ca7987eb53a2a7fcbaffaa4b1c227663e00ad9de..4d6586072a5fe32efcd5040aaaeaaef9bf60538f 100644 (file)
@@ -3,27 +3,23 @@
 /**
  * help.php
  *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
  * Displays help for the user
  *
+ * @copyright 1999-2020 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
  */
 
+/** This is the help page */
+define('PAGE_NAME', 'help');
+
 /**
- * Path for SquirrelMail required files.
- * @ignore
+ * Include the SquirrelMail initialization file.
  */
-define('SM_PATH','../');
-
-/* SquirrelMail required files. */
-require_once(SM_PATH . 'include/validate.php');
-require_once(SM_PATH . 'functions/global.php');
-require_once(SM_PATH . 'functions/display_messages.php');
+require('../include/init.php');
 
-displayPageHeader($color, 'None' );
+displayPageHeader($color);
 
 $helpdir[0] = 'basic.hlp';
 $helpdir[1] = 'main_folder.hlp';
@@ -99,18 +95,7 @@ function get_info($doc, $pos) {
 
 /**************[ END HELP FUNCTIONS ]******************/
 
-
-echo html_tag( 'table',
-        html_tag( 'tr',
-            html_tag( 'td','<center><b>' . _("Help") .'</b></center>', 'center', $color[0] )
-        ) ,
-    'center', '', 'width="95%" cellpadding="1" cellspacing="2" border="0"' );
-
-do_hook('help_top');
-
-echo html_tag( 'table', '', 'center', '', 'width="90%" cellpadding="0" cellspacing="10" border="0"' ) .
-        html_tag( 'tr' ) .
-            html_tag( 'td' );
+do_hook('help_top', $null);
 
 if (!isset($squirrelmail_language)) {
     $squirrelmail_language = 'en_US';
@@ -119,12 +104,14 @@ if (!isset($squirrelmail_language)) {
 if (file_exists("../help/$squirrelmail_language")) {
     $user_language = $squirrelmail_language;
 } else if (file_exists('../help/en_US')) {
-    echo "<center><font color=\"$color[2]\">";
-    printf (_("The help has not been translated to %s. It will be displayed in English instead."), $languages[$squirrelmail_language]['NAME']);
-    echo '</font></center><br />';
+    error_box(_("Help is not available in the selected language. It will be displayed in English instead."));
+    echo '<br />';
     $user_language = 'en_US';
 } else {
-    error_box( _("Some or all of the help documents are not present!"), $color );
+    error_box( _("Help is not available. Please contact your system administrator for assistance."));
+    echo '</td></tr></table>';
+    // Display footer (closes HTML tags) and stop script execution.
+    $oTemplate->display('footer.tpl');
     exit;
 }
 
@@ -151,65 +138,105 @@ if ( sqgetGlobalVar('chapter', $temp, SQ_GET) ) {
 }
 
 if ( $chapter == 0 || !isset( $helpdir[$chapter-1] ) ) {
-    echo html_tag( 'table', '', 'center', '', 'cellpadding="0" cellspacing="0" border="0"' ) .
-         html_tag( 'tr' ) .
-         html_tag( 'td' ) .
-         '<b><center>' . _("Table of Contents") . '</center></b><br />';
-    echo html_tag( 'ol' );
+    // Initialise the needed variables.
+    $toc = array();
+
+    // Get the chapter numbers, title and decriptions.
     for ($i=0, $cnt = count($helpdir); $i < $cnt; $i++) {
-        $doc = file("../help/$user_language/$helpdir[$i]");
-        $help_info = get_info($doc, 0);
-        echo '<li><a href="../src/help.php?chapter=' . ($i+1)
-             . '">' . $help_info[0] . '</a>' .
-             html_tag( 'ul', $help_info[2] );
+        if (file_exists("../help/$user_language/$helpdir[$i]")) {
+            // First try the selected language.
+            $doc = file("../help/$user_language/$helpdir[$i]");
+            $help_info = get_info($doc, 0);
+            $toc[] = array($i+1, $help_info[0], $help_info[2]);
+        } elseif (file_exists("../help/en_US/$helpdir[$i]")) {
+            // If the selected language can't be found, try English.
+            $doc = file("../help/en_US/$helpdir[$i]");
+            $help_info = get_info($doc, 0);
+            $toc[] = array($i+1, $help_info[0],
+                    _("This chapter is not available in the selected language. It will be displayed in English instead.") .
+                    '<br />' . $help_info[2]);
+        } else {
+            // If English can't be found, the chapter went MIA.
+            $toc[] = array($i+1, _("This chapter is missing"),
+                    sprintf(_("For some reason, chapter %s is not available."), $i+1));
+        }
     }
-    do_hook('help_chapter');
-    echo '</ol></td></tr></table>';
-} else {
-    $doc = file("../help/$user_language/" . $helpdir[$chapter-1]);
-    $help_info = get_info($doc, 0);
-    echo '<small><center>';
-    if ($chapter <= 1){
-        echo '<font color="' . $color[9] . '">' . _("Previous")
-             . '</font> | ';
-    } else {
-        echo '<a href="../src/help.php?chapter=' . ($chapter-1)
-             . '">' . _("Previous") . '</a> | ';
+
+    // Provide hook for external help scripts.
+    do_hook('help_chapter', $null);
+    $new_toc = array();
+    foreach ($toc as $ch) {
+        $a = array();
+        $a['Chapter'] = $ch[0];
+        $a['Title'] = $ch[1];
+        $a['Summary'] = trim($ch[2]);
+        $new_toc[] = $a;
     }
-    echo '<a href="../src/help.php">' . _("Table of Contents") . '</a>';
-    if ($chapter >= count($helpdir)){
-        echo ' | <font color="' . $color[9] . '">' . _("Next") . '</font>';
+    
+    $oTemplate->assign('toc', $new_toc);
+    
+    $oTemplate->display('help_toc.tpl');
+} else {
+    // Initialise the needed variables.
+    $display_chapter = TRUE;
+
+    // Get the chapter.
+    if (file_exists("../help/$user_language/" . $helpdir[$chapter-1])) {
+        // First try the selected language.
+        $doc = file("../help/$user_language/" . $helpdir[$chapter-1]);
+    } elseif (file_exists("../help/en_US/" . $helpdir[$chapter-1])) {
+        // If the selected language can't be found, try English.
+        $doc = file("../help/en_US/" . $helpdir[$chapter-1]);
+        error_box(_("This chapter is not available in the selected language. It will be displayed in English instead."));
+        echo '<br />';
     } else {
-        echo ' | <a href="../src/help.php?chapter=' . ($chapter+1)
-             . '">' . _("Next") . '</a>';
+        // If English can't be found, the chapter went MIA.
+        $display_chapter = FALSE;
     }
-    echo '</center></small><br />';
 
-    echo '<font size="5"><b>' . $chapter . ' - ' . $help_info[0]
-         . '</b></font><br /><br />';
-
-    if (isset($help_info[1]) && $help_info[1]) {
-        echo $help_info[1];
+    // Write the chapter.
+    if ($display_chapter) {
+        // If there is a valid chapter, display it.
+        $help_info = get_info($doc, 0);
+        $ch = array();
+        $ch['Chapter'] = $chapter;
+        $ch['Title'] = $help_info[0];
+        $ch['Summary'] = isset($help_info[1]) && $help_info[1] ? trim($help_info[1]) : $help_info[2];
+        $ch['Sections'] = array();
+        $section = 0;
+        for ($n = $help_info[3], $cnt = count($doc); $n < $cnt; $n++) {
+            $section++;
+            $help_info = get_info($doc, $n);
+            $n = $help_info[3];
+
+            $a = array();
+            $a['SectionNumber'] = $section;
+            $a['SectionTitle'] = $help_info[0];
+            $a['SectionText'] = isset($help_info[1]) ? trim($help_info[1]) : '';;
+            
+            $ch['Sections'][] = $a;
+        }
+        
+        $oTemplate->assign('chapter_number', $chapter);
+        $oTemplate->assign('chapter_count', count($helpdir));
+        $oTemplate->assign('chapter_title', $ch['Title']);
+        $oTemplate->assign('chapter_summary', $ch['Summary']);
+        $oTemplate->assign('sections', $ch['Sections']);
+        $oTemplate->assign('error_msg', NULL);
     } else {
-        echo html_tag( 'p', $help_info[2], 'left' );
-    }
-
-    $section = 0;
-    for ($n = $help_info[3], $cnt = count($doc); $n < $cnt; $n++) {
-        $section++;
-        $help_info = get_info($doc, $n);
-        echo "<b>$chapter.$section - $help_info[0]</b>" .
-            html_tag( 'ul', $help_info[1] );
-        $n = $help_info[3];
+        // If the help file went MIA, trigger an error message.
+        $oTemplate->assign('chapter_number', $chapter);
+        $oTemplate->assign('chapter_count', count($helpdir));
+        $oTemplate->assign('chapter_title', '');
+        $oTemplate->assign('chapter_summary', '');
+        $oTemplate->assign('sections', array());
+        $oTemplate->assign('error_msg', sprintf(_("For some reason, chapter %s is not available."), $chapter));
     }
-
-    echo '<br /><center><a href="#pagetop">' . _("Top") . '</a></center>';
+    
+    $oTemplate->display('help_chapter.tpl');
 }
 
-do_hook('help_bottom');
+do_hook('help_bottom', $null);
 
-echo html_tag( 'tr',
-            html_tag( 'td', '&nbsp;', 'left', $color[0] )
-        );
-?>
-</table></body></html>
\ No newline at end of file
+$oTemplate->display('footer.tpl');