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