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