f83bc0881be7755223cfd8f283d279ddc5ea5d07
[squirrelmail.git] / src / help.php
1 <?php
2
3 /**
4 * help.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
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
14 require_once('../src/validate.php');
15 require_once('../functions/display_messages.php');
16 require_once('../functions/imap.php');
17 require_once('../functions/array.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 for ($n=$pos; $n < count($doc); $n++) {
41 if (trim(strtolower($doc[$n])) == '<chapter>'
42 || trim(strtolower($doc[$n])) == '<section>') {
43 for ($n++;$n < count($doc)
44 && (trim(strtolower($doc[$n])) != '</section>')
45 && (trim(strtolower($doc[$n])) != '</chapter>'); $n++) {
46 if (trim(strtolower($doc[$n])) == '<title>') {
47 $n++;
48 $ary[0] = trim($doc[$n]);
49 }
50 if (trim(strtolower($doc[$n])) == '<description>') {
51 $ary[1] = '';
52 for ($n++;$n < count($doc)
53 && (trim(strtolower($doc[$n])) != '</description>');
54 $n++) {
55 $ary[1] .= $doc[$n];
56 }
57 }
58 if (trim(strtolower($doc[$n])) == '<summary>') {
59 $ary[2] = '';
60 for ($n++; $n < count($doc)
61 && (trim(strtolower($doc[$n])) != '</summary>');
62 $n++) {
63 $ary[2] .= $doc[$n];
64 }
65 }
66 }
67 if (isset($ary)) {
68 $ary[3] = $n;
69 return $ary;
70 } else {
71 $ary[0] = 'ERROR: Help files are not in the right format!';
72 $ary[1] = 'ERROR: Help files are not in the right format!';
73 $ary[2] = 'ERROR: Help files are not in the right format!';
74 return $ary;
75 }
76 }
77 }
78 $ary[0] = 'ERROR: Help files are not in the right format!';
79 $ary[1] = 'ERROR: Help files are not in the right format!';
80 return $ary;
81 }
82
83 /**************[ END HELP FUNCTIONS ]******************/
84
85
86
87 echo '<br>' .
88 html_tag( 'table',
89 html_tag( 'tr',
90 html_tag( 'td','<center><b>' . _("Help") .'</b></center>', 'center', $color[0] )
91 ) ,
92 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' );
93
94 do_hook("help_top");
95
96 echo html_tag( 'table', '', 'center', '', 'width="90%" cellpadding="0" cellspacing="10" border="0"' ) .
97 html_tag( 'tr' ) .
98 html_tag( 'td' );
99
100 if (isset($HTTP_REFERER)) {
101 $ref = strtolower($HTTP_REFERER);
102 if (strpos($ref, 'src/compose')){
103 $context = 'compose';
104 } else if (strpos($ref, 'src/addr')){
105 $context = 'address';
106 } else if (strpos($ref, 'src/folders')){
107 $context = 'folders';
108 } else if (strpos($ref, 'src/options')){
109 $context = 'options';
110 } else if (strpos($ref, 'src/right_main')){
111 $context = 'index';
112 } else if (strpos($ref, 'src/read_body')){
113 $context = 'read';
114 } else if (strpos($ref, 'src/search')){
115 $context = 'search';
116 }
117 }
118
119 if (!isset($squirrelmail_language)) {
120 $squirrelmail_language = 'en_US';
121 }
122
123 if (file_exists("../help/$squirrelmail_language")) {
124 $help_exists = true;
125 $user_language = $squirrelmail_language;
126 } else if (file_exists('../help/en_US')) {
127 $help_exists = true;
128 echo "<center><font color=\"$color[2]\">";
129 printf (_("The help has not been translated to %s. It will be displayed in English instead."), $languages[$squirrelmail_language]['NAME']);
130 echo '</font></center><br>';
131 $user_language = 'en_US';
132 } else {
133 $help_exists = false;
134 echo "<br><center><font color=\"$color[2]\">" .
135 _("Some or all of the help documents are not present!").
136 '</font></center>'.
137 '</td></tr></table>';
138 /* this is really silly, because there may be some
139 * footers. What about them.
140 * TODO: Fix this so it's not just "exit".
141 */
142 exit;
143 }
144
145 if ($help_exists == true) {
146 if (!isset($context)){
147 $context = '';
148 }
149 if ($context == 'compose'){
150 $chapter = 4;
151 } else if ($context == 'address'){
152 $chapter = 5;
153 } else if ($context == 'folders'){
154 $chapter = 6;
155 } else if ($context == 'options'){
156 $chapter = 7;
157 } else if ($context == 'index'){
158 $chapter = 2;
159 } else if ($context == 'read'){
160 $chapter = 3;
161 } else if ($context == 'search'){
162 $chapter = 8;
163 }
164
165 if (!isset($chapter)) {
166 echo html_tag( 'table', '', 'center', '', 'cellpadding="0" cellspacing="0" border="0"' );
167 html_tag( 'tr' ) .
168 html_tag( 'td' ) .
169 '<b><center>' . _("Table of Contents") . '</center></b><br>';
170 do_hook('help_chapter');
171 echo html_tag( 'ol' );
172 for ($i=0; $i < count($helpdir); $i++) {
173 $doc = file("../help/$user_language/$helpdir[$i]");
174 $help_info = get_info($doc, 0);
175 echo '<li><a href="../src/help.php?chapter=' . ($i+1)
176 . '">' . $help_info[0] . '</a>' .
177 html_tag( 'ul', $help_info[2] );
178 }
179 echo '</ol></td></tr></table>';
180 } else {
181 $doc = file("../help/$user_language/" . $helpdir[$chapter-1]);
182 $help_info = get_info($doc, 0);
183 echo '<small><center>';
184 if ($chapter <= 1){
185 echo '<font color="' . $color[9] . '">' . _("Previous")
186 . '</font> | ';
187 } else {
188 echo '<a href="../src/help.php?chapter=' . ($chapter-1)
189 . '">' . _("Previous") . '</a> | ';
190 }
191 echo '<a href="../src/help.php">' . _("Table of Contents") . '</a>';
192 if ($chapter >= count($helpdir)){
193 echo ' | <font color="$color[9]">' . _("Next") . '</font>';
194 } else {
195 echo ' | <a href="../src/help.php?chapter=' . ($chapter+1)
196 . '">' . _("Next") . '</a>';
197 }
198 echo '</center></small><br>';
199
200 echo '<font size="5"><b>' . $chapter . ' - ' . $help_info[0]
201 . '</b></font><br><br>';
202 if (isset($help_info[1])){
203 echo $help_info[1];
204 } else {
205 echo html_tag( 'p', $help_info[2], 'left' );
206 }
207
208 $section = 0;
209 for ($n = $help_info[3]; $n < count($doc); $n++) {
210 $section++;
211 $help_info = get_info($doc, $n);
212 echo "<b>$chapter.$section - $help_info[0]</b>" .
213 html_tag( 'ul', $help_info[1] );
214 $n = $help_info[3];
215 }
216
217 echo '<br><center><a href="#pagetop">' . _("Top") . '</a></center>';
218 }
219 }
220 do_hook('help_bottom');
221
222 echo html_tag( 'tr',
223 html_tag( 'td', '&nbsp;', 'left', $color[0] )
224 ).
225 '</table></body></html>';
226 ?>