4f75306fc1a4b1399ff72a055decba34164f8014
[squirrelmail.git] / src / help.php
1 <?php
2
3 /**
4 * help.php
5 *
6 * Displays help for the user
7 *
8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /**
15 * Include the SquirrelMail initialization file.
16 */
17 require('../include/init.php');
18
19 displayPageHeader($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 ]********************/
32
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
39 function get_info($doc, $pos) {
40 $ary = array(0,0,0);
41
42 $cntdoc = count($doc);
43
44 for ($n=$pos; $n < $cntdoc; $n++) {
45 if (trim(strtolower($doc[$n])) == '<chapter>'
46 || trim(strtolower($doc[$n])) == '<section>') {
47 for ($n++; $n < $cntdoc
48 && (trim(strtolower($doc[$n])) != '</section>')
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] = '';
56 for ($n++;$n < $cntdoc
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] = '';
64 for ($n++; $n < $cntdoc
65 && (trim(strtolower($doc[$n])) != '</summary>');
66 $n++) {
67 $ary[2] .= $doc[$n];
68 }
69 }
70 }
71 if (isset($ary)) {
72 $ary[3] = $n;
73 } else {
74 $ary[0] = _("ERROR: Help files are not in the right format!");
75 $ary[1] = $ary[0];
76 $ary[2] = $ary[0];
77 }
78 return( $ary );
79 } else if (!trim(strtolower($doc[$n]))) {
80 $ary[0] = '';
81 $ary[1] = '';
82 $ary[2] = '';
83 $ary[3] = $n;
84 }
85 }
86 $ary[0] = _("ERROR: Help files are not in the right format!");
87 $ary[1] = $ary[0];
88 $ary[2] = $ary[0];
89 $ary[3] = $n;
90 return( $ary );
91 }
92
93 /**************[ END HELP FUNCTIONS ]******************/
94
95 echo html_tag( 'table',
96 html_tag( 'tr',
97 html_tag( 'td','<div style="text-align: center;"><b>' . _("Help") .'</b></div>', 'center', $color[0] )
98 ) ,
99 'center', '', 'width="95%" cellpadding="1" cellspacing="2" border="0"' );
100
101 do_hook('help_top');
102
103 echo html_tag( 'table', '', 'center', '', 'width="90%" cellpadding="0" cellspacing="10" border="0"' ) .
104 html_tag( 'tr' ) .
105 html_tag( 'td' );
106
107 if (!isset($squirrelmail_language)) {
108 $squirrelmail_language = 'en_US';
109 }
110
111 if (file_exists("../help/$squirrelmail_language")) {
112 $user_language = $squirrelmail_language;
113 } else if (file_exists('../help/en_US')) {
114 error_box(_("Help is not available in the selected language. It will be displayed in English instead."));
115 echo '<br />';
116 $user_language = 'en_US';
117 } else {
118 error_box( _("Help is not available. Please contact your system administrator for assistance."));
119 // display footer (closes html tags) and stop script execution
120 $oTemplate->display('footer.tpl');
121 exit();
122 }
123
124
125 /* take the chapternumber from the GET-vars,
126 * else see if we can get a relevant chapter from the referer */
127 $chapter = 0;
128
129 if ( sqgetGlobalVar('chapter', $temp, SQ_GET) ) {
130 $chapter = (int) $temp;
131 } elseif ( sqgetGlobalVar('HTTP_REFERER', $temp, SQ_SERVER) ) {
132 $ref = strtolower($temp);
133
134 $contexts = array ( 'src/compose' => 4, 'src/addr' => 5,
135 'src/folders' => 6, 'src/options' => 7, 'src/right_main' => 2,
136 'src/read_body' => 3, 'src/search' => 8 );
137
138 foreach($contexts as $path => $chap) {
139 if(strpos($ref, $path)) {
140 $chapter = $chap;
141 break;
142 }
143 }
144 }
145
146 if ( $chapter == 0 || !isset( $helpdir[$chapter-1] ) ) {
147 // Initialise the needed variables.
148 $toc = array();
149
150 // Get the chapter numbers, title and decriptions.
151 for ($i=0, $cnt = count($helpdir); $i < $cnt; $i++) {
152 if (file_exists("../help/$user_language/$helpdir[$i]")) {
153 // First try the selected language.
154 $doc = file("../help/$user_language/$helpdir[$i]");
155 $help_info = get_info($doc, 0);
156 $toc[] = array($i+1, $help_info[0], $help_info[2]);
157 } elseif (file_exists("../help/en_US/$helpdir[$i]")) {
158 // If the selected language can't be found, try English.
159 $doc = file("../help/en_US/$helpdir[$i]");
160 $help_info = get_info($doc, 0);
161 $toc[] = array($i+1, $help_info[0],
162 _("This chapter is not available in the selected language. It will be displayed in English instead.") .
163 '<br />' . $help_info[2]);
164 } else {
165 // If English can't be found, the chapter went MIA.
166 $toc[] = array($i+1, _("This chapter is missing"),
167 sprintf(_("For some reason, chapter %s is not available."), $i+1));
168 }
169 }
170
171 // Write the TOC header
172 echo html_tag( 'table', '', 'center', '', 'cellpadding="0" cellspacing="0" border="0"' ) .
173 html_tag( 'tr' ) .
174 html_tag( 'td' ) .
175 '<div style="text-align: center;"><b>' . _("Table of Contents") . '</b></div><br />';
176 echo html_tag( 'ol' );
177
178 // Write the TOC chapters.
179 for ($i=0, $cnt = count($toc); $i < $cnt; $i++) {
180 echo '<li><a href="../src/help.php?chapter=' . $toc[$i][0]. '">' .
181 $toc[$i][1] . '</a>' . html_tag( 'ul', $toc[$i][2] );
182 }
183
184 // Provide hook for external help scripts.
185 do_hook('help_chapter');
186
187 // Write the TOC footer.
188 echo '</ol></td></tr></table>';
189 } else {
190 // Initialise the needed variables.
191 $display_chapter = TRUE;
192
193 // Get the chapter.
194 if (file_exists("../help/$user_language/" . $helpdir[$chapter-1])) {
195 // First try the selected language.
196 $doc = file("../help/$user_language/" . $helpdir[$chapter-1]);
197 } elseif (file_exists("../help/en_US/" . $helpdir[$chapter-1])) {
198 // If the selected language can't be found, try English.
199 $doc = file("../help/en_US/" . $helpdir[$chapter-1]);
200 error_box(_("This chapter in not available in the selected language. It will be displayed in English instead."));
201 echo '<br />';
202 } else {
203 // If English can't be found, the chapter went MIA.
204 $display_chapter = FALSE;
205 }
206
207 // Write the chpater header.
208 echo '<div style="text-align: center;"><small>';
209 if ($chapter <= 1){
210 echo '<font color="' . $color[9] . '">' . _("Previous")
211 . '</font> | ';
212 } else {
213 echo '<a href="../src/help.php?chapter=' . ($chapter-1)
214 . '">' . _("Previous") . '</a> | ';
215 }
216 echo '<a href="../src/help.php">' . _("Table of Contents") . '</a>';
217 if ($chapter >= count($helpdir)){
218 echo ' | <font color="' . $color[9] . '">' . _("Next") . '</font>';
219 } else {
220 echo ' | <a href="../src/help.php?chapter=' . ($chapter+1)
221 . '">' . _("Next") . '</a>';
222 }
223 echo '</small></div><br />';
224
225 // Write the chapter.
226 if ($display_chapter) {
227 // If there is a valid chapter, display it.
228 $help_info = get_info($doc, 0);
229 echo '<font size="5"><b>' . $chapter . ' - ' . $help_info[0]
230 . '</b></font><br /><br />';
231
232 if (isset($help_info[1]) && $help_info[1]) {
233 echo $help_info[1];
234 } else {
235 echo html_tag( 'p', $help_info[2], 'left' );
236 }
237
238 $section = 0;
239 for ($n = $help_info[3], $cnt = count($doc); $n < $cnt; $n++) {
240 $section++;
241 $help_info = get_info($doc, $n);
242 echo "<b>$chapter.$section - $help_info[0]</b>" .
243 html_tag( 'ul', $help_info[1] );
244 $n = $help_info[3];
245 }
246
247 echo '<br /><div style="text-align: center;"><a href="#pagetop">' . _("Top") . '</a></div>';
248 } else {
249 // If the help file went MIA, display an error message.
250 error_box(sprintf(_("For some reason, chapter %s is not available."), $chapter));
251 }
252 }
253
254 do_hook('help_bottom');
255
256 echo html_tag( 'tr',
257 html_tag( 'td', '&nbsp;', 'left', $color[0] )
258 );
259
260 ?>
261 </table>
262 <?php
263 $oTemplate->display('footer.tpl');
264 ?>