fix for infinite loop when help files have trailing empty lines.
[squirrelmail.git] / src / help.php
CommitLineData
e222c290 1<?php
895905c0 2
35586184 3/**
4 * help.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Displays help for the user
10 *
11 * $Id$
12 */
13
86725763 14/* Path for SquirrelMail required files. */
15define('SM_PATH','../');
16
17/* SquirrelMail required files. */
08185f2a 18require_once(SM_PATH . 'include/validate.php');
86725763 19require_once(SM_PATH . 'functions/display_messages.php');
20require_once(SM_PATH . 'functions/imap.php');
21require_once(SM_PATH . 'functions/array.php');
390372b4 22
cd08020d 23displayPageHeader($color, 'None' );
24
25$helpdir[0] = 'basic.hlp';
26$helpdir[1] = 'main_folder.hlp';
27$helpdir[2] = 'read_mail.hlp';
28$helpdir[3] = 'compose.hlp';
29$helpdir[4] = 'addresses.hlp';
30$helpdir[5] = 'folders.hlp';
31$helpdir[6] = 'options.hlp';
32$helpdir[7] = 'search.hlp';
33$helpdir[8] = 'FAQ.hlp';
34
35/****************[ HELP FUNCTIONS ]********************/
390372b4 36
cd08020d 37/**
38 * parses through and gets the information from the different documents.
39 * this returns one section at a time. You must keep track of the position
40 * so that it knows where to start to look for the next section.
41 */
42
43function get_info($doc, $pos) {
143c7a82 44 $ary = array(0,0,0);
cd08020d 45 for ($n=$pos; $n < count($doc); $n++) {
46 if (trim(strtolower($doc[$n])) == '<chapter>'
47 || trim(strtolower($doc[$n])) == '<section>') {
48 for ($n++;$n < count($doc)
49 && (trim(strtolower($doc[$n])) != '</section>')
50 && (trim(strtolower($doc[$n])) != '</chapter>'); $n++) {
51 if (trim(strtolower($doc[$n])) == '<title>') {
52 $n++;
53 $ary[0] = trim($doc[$n]);
54 }
55 if (trim(strtolower($doc[$n])) == '<description>') {
56 $ary[1] = '';
57 for ($n++;$n < count($doc)
58 && (trim(strtolower($doc[$n])) != '</description>');
59 $n++) {
60 $ary[1] .= $doc[$n];
61 }
62 }
63 if (trim(strtolower($doc[$n])) == '<summary>') {
64 $ary[2] = '';
65 for ($n++; $n < count($doc)
66 && (trim(strtolower($doc[$n])) != '</summary>');
67 $n++) {
68 $ary[2] .= $doc[$n];
69 }
70 }
2d367c68 71 }
1863670d 72 if (isset($ary)) {
cd08020d 73 $ary[3] = $n;
390372b4 74 } else {
0120b304 75 $ary[0] = _("ERROR: Help files are not in the right format!");
76 $ary[1] = $ary[0];
77 $ary[2] = $ary[0];
2d367c68 78 }
0120b304 79 return( $ary );
143c7a82 80 } else if (!trim(strtolower($doc[$n]))) {
81 $ary[0] = '';
82 $ary[1] = '';
83 $ary[2] = '';
84 $ary[3] = $n;
85 }
cd08020d 86 }
0120b304 87 $ary[0] = _("ERROR: Help files are not in the right format!");
88 $ary[1] = $ary[0];
143c7a82 89 $ary[2] = $ary[0];
90 $ary[3] = $n;
0120b304 91 return( $ary );
cd08020d 92}
2d367c68 93
cd08020d 94/**************[ END HELP FUNCTIONS ]******************/
390372b4 95
390372b4 96
3530b83b 97
6206f6c4 98echo html_tag( 'table',
3530b83b 99 html_tag( 'tr',
100 html_tag( 'td','<center><b>' . _("Help") .'</b></center>', 'center', $color[0] )
101 ) ,
6206f6c4 102 'center', '', 'width="95%" cellpadding="1" cellspacing="2" border="0"' );
3530b83b 103
104do_hook("help_top");
105
106echo html_tag( 'table', '', 'center', '', 'width="90%" cellpadding="0" cellspacing="10" border="0"' ) .
107 html_tag( 'tr' ) .
108 html_tag( 'td' );
109
a32985a5 110if (isset($_SERVER['HTTP_REFERER'])) {
111 $ref = strtolower($_SERVER['HTTP_REFERER']);
cd08020d 112 if (strpos($ref, 'src/compose')){
113 $context = 'compose';
114 } else if (strpos($ref, 'src/addr')){
115 $context = 'address';
116 } else if (strpos($ref, 'src/folders')){
117 $context = 'folders';
118 } else if (strpos($ref, 'src/options')){
119 $context = 'options';
120 } else if (strpos($ref, 'src/right_main')){
121 $context = 'index';
122 } else if (strpos($ref, 'src/read_body')){
123 $context = 'read';
124 } else if (strpos($ref, 'src/search')){
125 $context = 'search';
126 }
127}
128
129if (!isset($squirrelmail_language)) {
e5916f84 130 $squirrelmail_language = 'en_US';
cd08020d 131}
132
cd08020d 133if (file_exists("../help/$squirrelmail_language")) {
134 $help_exists = true;
135 $user_language = $squirrelmail_language;
e5916f84 136} else if (file_exists('../help/en_US')) {
cd08020d 137 $help_exists = true;
138 echo "<center><font color=\"$color[2]\">";
139 printf (_("The help has not been translated to %s. It will be displayed in English instead."), $languages[$squirrelmail_language]['NAME']);
140 echo '</font></center><br>';
e5916f84 141 $user_language = 'en_US';
cd08020d 142} else {
143 $help_exists = false;
353616c4 144 echo "<br><center><font color=\"$color[2]\">" .
145 _("Some or all of the help documents are not present!").
146 '</font></center>'.
f91f8bd8 147 '</td></tr></table></body></html>';
cd08020d 148 /* this is really silly, because there may be some
149 * footers. What about them.
150 * TODO: Fix this so it's not just "exit".
151 */
152 exit;
153}
154
155if ($help_exists == true) {
156 if (!isset($context)){
157 $context = '';
158 }
159 if ($context == 'compose'){
160 $chapter = 4;
161 } else if ($context == 'address'){
162 $chapter = 5;
163 } else if ($context == 'folders'){
164 $chapter = 6;
165 } else if ($context == 'options'){
166 $chapter = 7;
167 } else if ($context == 'index'){
168 $chapter = 2;
169 } else if ($context == 'read'){
170 $chapter = 3;
171 } else if ($context == 'search'){
172 $chapter = 8;
0120b304 173 } else if ( isset( $_GET['chapter'] ) ) {
174 $chapter = intval( $_GET['chapter']);
175 } else {
176 $chapter = 0;
cd08020d 177 }
178
f91f8bd8 179 if ( $chapter == 0 || !isset( $helpdir[$chapter-1] ) ) {
3530b83b 180 echo html_tag( 'table', '', 'center', '', 'cellpadding="0" cellspacing="0" border="0"' );
181 html_tag( 'tr' ) .
182 html_tag( 'td' ) .
183 '<b><center>' . _("Table of Contents") . '</center></b><br>';
cd08020d 184 do_hook('help_chapter');
3530b83b 185 echo html_tag( 'ol' );
cd08020d 186 for ($i=0; $i < count($helpdir); $i++) {
390372b4 187 $doc = file("../help/$user_language/$helpdir[$i]");
188 $help_info = get_info($doc, 0);
353616c4 189 echo '<li><a href="../src/help.php?chapter=' . ($i+1)
3530b83b 190 . '">' . $help_info[0] . '</a>' .
191 html_tag( 'ul', $help_info[2] );
cd08020d 192 }
353616c4 193 echo '</ol></td></tr></table>';
cd08020d 194 } else {
195 $doc = file("../help/$user_language/" . $helpdir[$chapter-1]);
196 $help_info = get_info($doc, 0);
197 echo '<small><center>';
198 if ($chapter <= 1){
353616c4 199 echo '<font color="' . $color[9] . '">' . _("Previous")
cd08020d 200 . '</font> | ';
201 } else {
353616c4 202 echo '<a href="../src/help.php?chapter=' . ($chapter-1)
cd08020d 203 . '">' . _("Previous") . '</a> | ';
204 }
205 echo '<a href="../src/help.php">' . _("Table of Contents") . '</a>';
206 if ($chapter >= count($helpdir)){
a32985a5 207 echo ' | <font color="' . $color[9] . '">' . _("Next") . '</font>';
353616c4 208 } else {
cd08020d 209 echo ' | <a href="../src/help.php?chapter=' . ($chapter+1)
210 . '">' . _("Next") . '</a>';
211 }
212 echo '</center></small><br>';
213
214 echo '<font size="5"><b>' . $chapter . ' - ' . $help_info[0]
215 . '</b></font><br><br>';
216 if (isset($help_info[1])){
217 echo $help_info[1];
218 } else {
3530b83b 219 echo html_tag( 'p', $help_info[2], 'left' );
cd08020d 220 }
221
222 $section = 0;
223 for ($n = $help_info[3]; $n < count($doc); $n++) {
390372b4 224 $section++;
225 $help_info = get_info($doc, $n);
3530b83b 226 echo "<b>$chapter.$section - $help_info[0]</b>" .
227 html_tag( 'ul', $help_info[1] );
143c7a82 228 $n = $help_info[3];
cd08020d 229 }
390372b4 230
cd08020d 231 echo '<br><center><a href="#pagetop">' . _("Top") . '</a></center>';
232 }
233}
234do_hook('help_bottom');
3530b83b 235
236echo html_tag( 'tr',
237 html_tag( 'td', '&nbsp;', 'left', $color[0] )
238 ).
239 '</table></body></html>';
e222c290 240?>