Small fix to tassium code, if you chomp something it can never match
[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');
390372b4 20
cd08020d 21displayPageHeader($color, 'None' );
22
23$helpdir[0] = 'basic.hlp';
24$helpdir[1] = 'main_folder.hlp';
25$helpdir[2] = 'read_mail.hlp';
26$helpdir[3] = 'compose.hlp';
27$helpdir[4] = 'addresses.hlp';
28$helpdir[5] = 'folders.hlp';
29$helpdir[6] = 'options.hlp';
30$helpdir[7] = 'search.hlp';
31$helpdir[8] = 'FAQ.hlp';
32
33/****************[ HELP FUNCTIONS ]********************/
390372b4 34
cd08020d 35/**
36 * parses through and gets the information from the different documents.
37 * this returns one section at a time. You must keep track of the position
38 * so that it knows where to start to look for the next section.
39 */
40
41function get_info($doc, $pos) {
143c7a82 42 $ary = array(0,0,0);
7ea33e5b 43
44 $cntdoc = count($doc);
45
46 for ($n=$pos; $n < $cntdoc; $n++) {
cd08020d 47 if (trim(strtolower($doc[$n])) == '<chapter>'
48 || trim(strtolower($doc[$n])) == '<section>') {
7ea33e5b 49 for ($n++; $n < $cntdoc
cd08020d 50 && (trim(strtolower($doc[$n])) != '</section>')
51 && (trim(strtolower($doc[$n])) != '</chapter>'); $n++) {
52 if (trim(strtolower($doc[$n])) == '<title>') {
53 $n++;
54 $ary[0] = trim($doc[$n]);
55 }
56 if (trim(strtolower($doc[$n])) == '<description>') {
57 $ary[1] = '';
7ea33e5b 58 for ($n++;$n < $cntdoc
cd08020d 59 && (trim(strtolower($doc[$n])) != '</description>');
60 $n++) {
61 $ary[1] .= $doc[$n];
62 }
63 }
64 if (trim(strtolower($doc[$n])) == '<summary>') {
65 $ary[2] = '';
7ea33e5b 66 for ($n++; $n < $cntdoc
cd08020d 67 && (trim(strtolower($doc[$n])) != '</summary>');
68 $n++) {
69 $ary[2] .= $doc[$n];
70 }
71 }
2d367c68 72 }
1863670d 73 if (isset($ary)) {
cd08020d 74 $ary[3] = $n;
390372b4 75 } else {
0120b304 76 $ary[0] = _("ERROR: Help files are not in the right format!");
77 $ary[1] = $ary[0];
78 $ary[2] = $ary[0];
2d367c68 79 }
0120b304 80 return( $ary );
143c7a82 81 } else if (!trim(strtolower($doc[$n]))) {
82 $ary[0] = '';
83 $ary[1] = '';
84 $ary[2] = '';
85 $ary[3] = $n;
86 }
cd08020d 87 }
0120b304 88 $ary[0] = _("ERROR: Help files are not in the right format!");
89 $ary[1] = $ary[0];
143c7a82 90 $ary[2] = $ary[0];
91 $ary[3] = $n;
0120b304 92 return( $ary );
cd08020d 93}
2d367c68 94
cd08020d 95/**************[ END HELP FUNCTIONS ]******************/
390372b4 96
390372b4 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
7ea33e5b 104do_hook('help_top');
3530b83b 105
106echo html_tag( 'table', '', 'center', '', 'width="90%" cellpadding="0" cellspacing="10" border="0"' ) .
107 html_tag( 'tr' ) .
108 html_tag( 'td' );
109
cd08020d 110if (!isset($squirrelmail_language)) {
e5916f84 111 $squirrelmail_language = 'en_US';
cd08020d 112}
113
cd08020d 114if (file_exists("../help/$squirrelmail_language")) {
cd08020d 115 $user_language = $squirrelmail_language;
e5916f84 116} else if (file_exists('../help/en_US')) {
cd08020d 117 echo "<center><font color=\"$color[2]\">";
118 printf (_("The help has not been translated to %s. It will be displayed in English instead."), $languages[$squirrelmail_language]['NAME']);
119 echo '</font></center><br>';
e5916f84 120 $user_language = 'en_US';
cd08020d 121} else {
7ea33e5b 122 error_box( _("Some or all of the help documents are not present!"), $color );
cd08020d 123 exit;
124}
125
7ea33e5b 126
127/* take the chapternumber from the GET-vars,
128 * else see if we can get a relevant chapter from the referer */
129$chapter = 0;
130
131if ( isset( $_GET['chapter'] ) )
132{
133 $chapter = intval( $_GET['chapter']);
134}
135elseif (isset($_SERVER['HTTP_REFERER']))
136{
137 $ref = strtolower($_SERVER['HTTP_REFERER']);
138
139 $contexts = array ( 'src/compose' => 4, 'src/addr' => 5,
140 'src/folders' => 6, 'src/options' => 7, 'src/right_main' => 2,
141 'src/read_body' => 3, 'src/search' => 8 );
142
143 foreach($contexts as $path => $chap) {
144 if(strpos($ref, $path)) {
145 $chapter = $chap;
146 break;
147 }
cd08020d 148 }
7ea33e5b 149}
150
151if ( $chapter == 0 || !isset( $helpdir[$chapter-1] ) ) {
152 echo html_tag( 'table', '', 'center', '', 'cellpadding="0" cellspacing="0" border="0"' );
153 html_tag( 'tr' ) .
154 html_tag( 'td' ) .
155 '<b><center>' . _("Table of Contents") . '</center></b><br>';
156 do_hook('help_chapter');
157 echo html_tag( 'ol' );
158 for ($i=0, $cnt = count($helpdir); $i < $cnt; $i++) {
159 $doc = file("../help/$user_language/$helpdir[$i]");
160 $help_info = get_info($doc, 0);
161 echo '<li><a href="../src/help.php?chapter=' . ($i+1)
162 . '">' . $help_info[0] . '</a>' .
163 html_tag( 'ul', $help_info[2] );
164 }
165 echo '</ol></td></tr></table>';
166} else {
167 $doc = file("../help/$user_language/" . $helpdir[$chapter-1]);
168 $help_info = get_info($doc, 0);
169 echo '<small><center>';
170 if ($chapter <= 1){
171 echo '<font color="' . $color[9] . '">' . _("Previous")
172 . '</font> | ';
173 } else {
174 echo '<a href="../src/help.php?chapter=' . ($chapter-1)
175 . '">' . _("Previous") . '</a> | ';
176 }
177 echo '<a href="../src/help.php">' . _("Table of Contents") . '</a>';
178 if ($chapter >= count($helpdir)){
179 echo ' | <font color="' . $color[9] . '">' . _("Next") . '</font>';
0120b304 180 } else {
7ea33e5b 181 echo ' | <a href="../src/help.php?chapter=' . ($chapter+1)
182 . '">' . _("Next") . '</a>';
cd08020d 183 }
7ea33e5b 184 echo '</center></small><br>';
cd08020d 185
7ea33e5b 186 echo '<font size="5"><b>' . $chapter . ' - ' . $help_info[0]
187 . '</b></font><br><br>';
188
189 if (isset($help_info[1]) && $help_info[1]) {
190 echo $help_info[1];
cd08020d 191 } else {
7ea33e5b 192 echo html_tag( 'p', $help_info[2], 'left' );
193 }
cd08020d 194
7ea33e5b 195 $section = 0;
196 for ($n = $help_info[3], $cnt = count($doc); $n < $cnt; $n++) {
197 $section++;
198 $help_info = get_info($doc, $n);
199 echo "<b>$chapter.$section - $help_info[0]</b>" .
200 html_tag( 'ul', $help_info[1] );
201 $n = $help_info[3];
cd08020d 202 }
7ea33e5b 203
204 echo '<br><center><a href="#pagetop">' . _("Top") . '</a></center>';
cd08020d 205}
7ea33e5b 206
cd08020d 207do_hook('help_bottom');
3530b83b 208
209echo html_tag( 'tr',
210 html_tag( 'td', '&nbsp;', 'left', $color[0] )
211 ).
212 '</table></body></html>';
e222c290 213?>