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