Adding template for error box.
[squirrelmail.git] / src / help.php
CommitLineData
e222c290 1<?php
895905c0 2
35586184 3/**
4 * help.php
5 *
35586184 6 * Displays help for the user
7 *
47ccfad4 8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 10 * @version $Id$
8f6f9ba5 11 * @package squirrelmail
35586184 12 */
13
30967a1e 14/**
15 * Path for SquirrelMail required files.
16 * @ignore
17 */
86725763 18define('SM_PATH','../');
19
20/* SquirrelMail required files. */
5c4ff7bf 21include_once(SM_PATH . 'include/validate.php');
8650e9e1 22require_once(SM_PATH . 'functions/global.php');
86725763 23require_once(SM_PATH . 'functions/display_messages.php');
390372b4 24
cd08020d 25displayPageHeader($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 ]********************/
390372b4 38
cd08020d 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
45function get_info($doc, $pos) {
143c7a82 46 $ary = array(0,0,0);
7ea33e5b 47
48 $cntdoc = count($doc);
49
50 for ($n=$pos; $n < $cntdoc; $n++) {
cd08020d 51 if (trim(strtolower($doc[$n])) == '<chapter>'
52 || trim(strtolower($doc[$n])) == '<section>') {
91e0dccc 53 for ($n++; $n < $cntdoc
54 && (trim(strtolower($doc[$n])) != '</section>')
cd08020d 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] = '';
91e0dccc 62 for ($n++;$n < $cntdoc
cd08020d 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] = '';
91e0dccc 70 for ($n++; $n < $cntdoc
71 && (trim(strtolower($doc[$n])) != '</summary>');
cd08020d 72 $n++) {
73 $ary[2] .= $doc[$n];
74 }
75 }
2d367c68 76 }
1863670d 77 if (isset($ary)) {
cd08020d 78 $ary[3] = $n;
390372b4 79 } else {
0120b304 80 $ary[0] = _("ERROR: Help files are not in the right format!");
81 $ary[1] = $ary[0];
82 $ary[2] = $ary[0];
2d367c68 83 }
134e4174 84 return( $ary );
143c7a82 85 } else if (!trim(strtolower($doc[$n]))) {
134e4174 86 $ary[0] = '';
87 $ary[1] = '';
88 $ary[2] = '';
89 $ary[3] = $n;
90 }
cd08020d 91 }
0120b304 92 $ary[0] = _("ERROR: Help files are not in the right format!");
93 $ary[1] = $ary[0];
143c7a82 94 $ary[2] = $ary[0];
95 $ary[3] = $n;
0120b304 96 return( $ary );
cd08020d 97}
2d367c68 98
cd08020d 99/**************[ END HELP FUNCTIONS ]******************/
390372b4 100
390372b4 101
6206f6c4 102echo html_tag( 'table',
3530b83b 103 html_tag( 'tr',
f265009a 104 html_tag( 'td','<div style="text-align: center;"><b>' . _("Help") .'</b></div>', 'center', $color[0] )
3530b83b 105 ) ,
6206f6c4 106 'center', '', 'width="95%" cellpadding="1" cellspacing="2" border="0"' );
3530b83b 107
7ea33e5b 108do_hook('help_top');
3530b83b 109
110echo html_tag( 'table', '', 'center', '', 'width="90%" cellpadding="0" cellspacing="10" border="0"' ) .
111 html_tag( 'tr' ) .
112 html_tag( 'td' );
113
cd08020d 114if (!isset($squirrelmail_language)) {
e5916f84 115 $squirrelmail_language = 'en_US';
cd08020d 116}
117
cd08020d 118if (file_exists("../help/$squirrelmail_language")) {
cd08020d 119 $user_language = $squirrelmail_language;
e5916f84 120} else if (file_exists('../help/en_US')) {
0e271f86 121 echo "<div style=\"text-align: center;\"><font color=\"$color[2]\">"
62d62203 122 ._("The help has not been translated to the selected language. It will be displayed in English instead.");
f265009a 123 echo '</font></div><br />';
e5916f84 124 $user_language = 'en_US';
cd08020d 125} else {
7ea33e5b 126 error_box( _("Some or all of the help documents are not present!"), $color );
cd08020d 127 exit;
128}
129
7ea33e5b 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
1e12d1ff 135if ( sqgetGlobalVar('chapter', $temp, SQ_GET) ) {
136 $chapter = (int) $temp;
137} elseif ( sqgetGlobalVar('HTTP_REFERER', $temp, SQ_SERVER) ) {
138 $ref = strtolower($temp);
7ea33e5b 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 }
cd08020d 149 }
7ea33e5b 150}
151
152if ( $chapter == 0 || !isset( $helpdir[$chapter-1] ) ) {
81c064ac 153 echo html_tag( 'table', '', 'center', '', 'cellpadding="0" cellspacing="0" border="0"' ) .
134e4174 154 html_tag( 'tr' ) .
155 html_tag( 'td' ) .
f265009a 156 '<div style="text-align: center;"><b>' . _("Table of Contents") . '</b></div><br />';
7ea33e5b 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 }
6575fe45 165 do_hook('help_chapter');
7ea33e5b 166 echo '</ol></td></tr></table>';
167} else {
168 $doc = file("../help/$user_language/" . $helpdir[$chapter-1]);
169 $help_info = get_info($doc, 0);
f265009a 170 echo '<div style="text-align: center;"><small>';
7ea33e5b 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>';
0120b304 181 } else {
7ea33e5b 182 echo ' | <a href="../src/help.php?chapter=' . ($chapter+1)
183 . '">' . _("Next") . '</a>';
cd08020d 184 }
f265009a 185 echo '</small></div><br />';
cd08020d 186
7ea33e5b 187 echo '<font size="5"><b>' . $chapter . ' - ' . $help_info[0]
39bfea8f 188 . '</b></font><br /><br />';
7ea33e5b 189
190 if (isset($help_info[1]) && $help_info[1]) {
191 echo $help_info[1];
cd08020d 192 } else {
7ea33e5b 193 echo html_tag( 'p', $help_info[2], 'left' );
194 }
91e0dccc 195
7ea33e5b 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] );
134e4174 202 $n = $help_info[3];
cd08020d 203 }
7ea33e5b 204
f265009a 205 echo '<br /><div style="text-align: center;"><a href="#pagetop">' . _("Top") . '</a></div>';
cd08020d 206}
7ea33e5b 207
cd08020d 208do_hook('help_bottom');
3530b83b 209
210echo html_tag( 'tr',
211 html_tag( 'td', '&nbsp;', 'left', $color[0] )
134e4174 212 );
a2b193bc 213
134e4174 214?>
5c4ff7bf 215</table>
216<?php
217$oTemplate->display('footer.tpl');
218?>