Adding more tests and fallbacks for errors in help pages.
[squirrelmail.git] / src / help.php
CommitLineData
e222c290 1<?php
895905c0 2
35586184 3/**
4 * help.php
5 *
35586184 6 * Displays help for the user
7 *
47ccfad4 8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 10 * @version $Id$
8f6f9ba5 11 * @package squirrelmail
35586184 12 */
13
30967a1e 14/**
202bcbcc 15 * Include the SquirrelMail initialization file.
30967a1e 16 */
202bcbcc 17require('../include/init.php');
390372b4 18
cd08020d 19displayPageHeader($color, 'None' );
20
21$helpdir[0] = 'basic.hlp';
22$helpdir[1] = 'main_folder.hlp';
23$helpdir[2] = 'read_mail.hlp';
24$helpdir[3] = 'compose.hlp';
25$helpdir[4] = 'addresses.hlp';
26$helpdir[5] = 'folders.hlp';
27$helpdir[6] = 'options.hlp';
28$helpdir[7] = 'search.hlp';
29$helpdir[8] = 'FAQ.hlp';
30
31/****************[ HELP FUNCTIONS ]********************/
390372b4 32
cd08020d 33/**
34 * parses through and gets the information from the different documents.
35 * this returns one section at a time. You must keep track of the position
36 * so that it knows where to start to look for the next section.
37 */
38
39function get_info($doc, $pos) {
143c7a82 40 $ary = array(0,0,0);
7ea33e5b 41
42 $cntdoc = count($doc);
43
44 for ($n=$pos; $n < $cntdoc; $n++) {
cd08020d 45 if (trim(strtolower($doc[$n])) == '<chapter>'
46 || trim(strtolower($doc[$n])) == '<section>') {
91e0dccc 47 for ($n++; $n < $cntdoc
48 && (trim(strtolower($doc[$n])) != '</section>')
cd08020d 49 && (trim(strtolower($doc[$n])) != '</chapter>'); $n++) {
50 if (trim(strtolower($doc[$n])) == '<title>') {
51 $n++;
52 $ary[0] = trim($doc[$n]);
53 }
54 if (trim(strtolower($doc[$n])) == '<description>') {
55 $ary[1] = '';
91e0dccc 56 for ($n++;$n < $cntdoc
cd08020d 57 && (trim(strtolower($doc[$n])) != '</description>');
58 $n++) {
59 $ary[1] .= $doc[$n];
60 }
61 }
62 if (trim(strtolower($doc[$n])) == '<summary>') {
63 $ary[2] = '';
91e0dccc 64 for ($n++; $n < $cntdoc
65 && (trim(strtolower($doc[$n])) != '</summary>');
cd08020d 66 $n++) {
67 $ary[2] .= $doc[$n];
68 }
69 }
2d367c68 70 }
1863670d 71 if (isset($ary)) {
cd08020d 72 $ary[3] = $n;
390372b4 73 } else {
0120b304 74 $ary[0] = _("ERROR: Help files are not in the right format!");
75 $ary[1] = $ary[0];
76 $ary[2] = $ary[0];
2d367c68 77 }
134e4174 78 return( $ary );
143c7a82 79 } else if (!trim(strtolower($doc[$n]))) {
134e4174 80 $ary[0] = '';
81 $ary[1] = '';
82 $ary[2] = '';
83 $ary[3] = $n;
84 }
cd08020d 85 }
0120b304 86 $ary[0] = _("ERROR: Help files are not in the right format!");
87 $ary[1] = $ary[0];
143c7a82 88 $ary[2] = $ary[0];
89 $ary[3] = $n;
0120b304 90 return( $ary );
cd08020d 91}
2d367c68 92
cd08020d 93/**************[ END HELP FUNCTIONS ]******************/
390372b4 94
6206f6c4 95echo html_tag( 'table',
3530b83b 96 html_tag( 'tr',
f265009a 97 html_tag( 'td','<div style="text-align: center;"><b>' . _("Help") .'</b></div>', 'center', $color[0] )
3530b83b 98 ) ,
6206f6c4 99 'center', '', 'width="95%" cellpadding="1" cellspacing="2" border="0"' );
3530b83b 100
7ea33e5b 101do_hook('help_top');
3530b83b 102
103echo html_tag( 'table', '', 'center', '', 'width="90%" cellpadding="0" cellspacing="10" border="0"' ) .
104 html_tag( 'tr' ) .
105 html_tag( 'td' );
106
cd08020d 107if (!isset($squirrelmail_language)) {
e5916f84 108 $squirrelmail_language = 'en_US';
cd08020d 109}
110
cd08020d 111if (file_exists("../help/$squirrelmail_language")) {
cd08020d 112 $user_language = $squirrelmail_language;
e5916f84 113} else if (file_exists('../help/en_US')) {
386c7b54 114 error_box(_("Help is not available in the selected language. It will be displayed in English instead."), $color);
115 echo '<br />';
e5916f84 116 $user_language = 'en_US';
cd08020d 117} else {
386c7b54 118 error_box( _("Help is not available. Please contact your system administrator for assistance."), $color );
cd08020d 119 exit;
120}
121
7ea33e5b 122
123/* take the chapternumber from the GET-vars,
124 * else see if we can get a relevant chapter from the referer */
125$chapter = 0;
126
1e12d1ff 127if ( sqgetGlobalVar('chapter', $temp, SQ_GET) ) {
128 $chapter = (int) $temp;
129} elseif ( sqgetGlobalVar('HTTP_REFERER', $temp, SQ_SERVER) ) {
130 $ref = strtolower($temp);
7ea33e5b 131
132 $contexts = array ( 'src/compose' => 4, 'src/addr' => 5,
133 'src/folders' => 6, 'src/options' => 7, 'src/right_main' => 2,
134 'src/read_body' => 3, 'src/search' => 8 );
135
136 foreach($contexts as $path => $chap) {
137 if(strpos($ref, $path)) {
138 $chapter = $chap;
139 break;
140 }
cd08020d 141 }
7ea33e5b 142}
143
144if ( $chapter == 0 || !isset( $helpdir[$chapter-1] ) ) {
386c7b54 145 // Initialise the needed variables.
146 $toc = array();
147
148 // Get the chapter numbers, title and decriptions.
149 for ($i=0, $cnt = count($helpdir); $i < $cnt; $i++) {
150 if (file_exists("../help/$user_language/$helpdir[$i]")) {
151 // First try the selected language.
152 $doc = file("../help/$user_language/$helpdir[$i]");
153 $help_info = get_info($doc, 0);
154 $toc[] = array($i+1, $help_info[0], $help_info[2]);
155 } elseif (file_exists("../help/en_US/$helpdir[$i]")) {
156 // If the selected language can't be found, try English.
157 $doc = file("../help/en_US/$helpdir[$i]");
158 $help_info = get_info($doc, 0);
159 $toc[] = array($i+1, $help_info[0],
160 _("This chapter is not available in the selected language. It will be displayed in English instead.") .
161 '<br />' . $help_info[2]);
162 } else {
163 // If English can't be found, the chapter went MIA.
164 $toc[] = array($i+1, _("This chapter is missing"),
165 sprintf(_("For some reason, chapter %s is not available."), $i+1));
166 }
167 }
168
169 // Write the TOC header
81c064ac 170 echo html_tag( 'table', '', 'center', '', 'cellpadding="0" cellspacing="0" border="0"' ) .
134e4174 171 html_tag( 'tr' ) .
172 html_tag( 'td' ) .
f265009a 173 '<div style="text-align: center;"><b>' . _("Table of Contents") . '</b></div><br />';
7ea33e5b 174 echo html_tag( 'ol' );
386c7b54 175
176 // Write the TOC chapters.
177 for ($i=0, $cnt = count($toc); $i < $cnt; $i++) {
178 echo '<li><a href="../src/help.php?chapter=' . $toc[$i][0]. '">' .
179 $toc[$i][1] . '</a>' . html_tag( 'ul', $toc[$i][2] );
7ea33e5b 180 }
386c7b54 181
182 // Provide hook for external help scripts.
6575fe45 183 do_hook('help_chapter');
386c7b54 184
185 // Write the TOC footer.
7ea33e5b 186 echo '</ol></td></tr></table>';
187} else {
386c7b54 188 // Initialise the needed variables.
189 $display_chapter = TRUE;
190
191 // Get the chapter.
192 if (file_exists("../help/$user_language/" . $helpdir[$chapter-1])) {
193 // First try the selected language.
194 $doc = file("../help/$user_language/" . $helpdir[$chapter-1]);
195 } elseif (file_exists("../help/en_US/" . $helpdir[$chapter-1])) {
196 // If the selected language can't be found, try English.
197 $doc = file("../help/en_US/" . $helpdir[$chapter-1]);
198 error_box(_("This chapter in not available in the selected language. It will be displayed in English instead."), $color);
199 echo '<br />';
200 } else {
201 // If English can't be found, the chapter went MIA.
202 $display_chapter = FALSE;
203 }
204
205 // Write the chpater header.
f265009a 206 echo '<div style="text-align: center;"><small>';
7ea33e5b 207 if ($chapter <= 1){
208 echo '<font color="' . $color[9] . '">' . _("Previous")
209 . '</font> | ';
210 } else {
211 echo '<a href="../src/help.php?chapter=' . ($chapter-1)
212 . '">' . _("Previous") . '</a> | ';
213 }
214 echo '<a href="../src/help.php">' . _("Table of Contents") . '</a>';
215 if ($chapter >= count($helpdir)){
216 echo ' | <font color="' . $color[9] . '">' . _("Next") . '</font>';
0120b304 217 } else {
7ea33e5b 218 echo ' | <a href="../src/help.php?chapter=' . ($chapter+1)
219 . '">' . _("Next") . '</a>';
cd08020d 220 }
f265009a 221 echo '</small></div><br />';
cd08020d 222
386c7b54 223 // Write the chapter.
224 if ($display_chapter) {
225 // If there is a valid chapter, display it.
226 $help_info = get_info($doc, 0);
227 echo '<font size="5"><b>' . $chapter . ' - ' . $help_info[0]
228 . '</b></font><br /><br />';
7ea33e5b 229
386c7b54 230 if (isset($help_info[1]) && $help_info[1]) {
231 echo $help_info[1];
232 } else {
233 echo html_tag( 'p', $help_info[2], 'left' );
234 }
91e0dccc 235
386c7b54 236 $section = 0;
237 for ($n = $help_info[3], $cnt = count($doc); $n < $cnt; $n++) {
238 $section++;
239 $help_info = get_info($doc, $n);
240 echo "<b>$chapter.$section - $help_info[0]</b>" .
241 html_tag( 'ul', $help_info[1] );
242 $n = $help_info[3];
243 }
7ea33e5b 244
386c7b54 245 echo '<br /><div style="text-align: center;"><a href="#pagetop">' . _("Top") . '</a></div>';
246 } else {
247 // If the help file went MIA, display an error message.
248 error_box(sprintf(_("For some reason, chapter %s is not available."), $chapter), $color);
249 }
cd08020d 250}
7ea33e5b 251
cd08020d 252do_hook('help_bottom');
3530b83b 253
254echo html_tag( 'tr',
255 html_tag( 'td', '&nbsp;', 'left', $color[0] )
134e4174 256 );
a2b193bc 257
134e4174 258?>
5c4ff7bf 259</table>
260<?php
261$oTemplate->display('footer.tpl');
262?>