generalise folder_manip_dialog CSS into dialogbox CSS
[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 *
4b5049de 8 * @copyright &copy; 1999-2007 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/**
202bcbcc 15 * Include the SquirrelMail initialization file.
30967a1e 16 */
202bcbcc 17require('../include/init.php');
390372b4 18
cd08020d 19displayPageHeader($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 ]********************/
390372b4 32
cd08020d 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
39function get_info($doc, $pos) {
143c7a82 40 $ary = array(0,0,0);
7ea33e5b 41
42 $cntdoc = count($doc);
43
44 for ($n=$pos; $n < $cntdoc; $n++) {
cd08020d 45 if (trim(strtolower($doc[$n])) == '<chapter>'
46 || trim(strtolower($doc[$n])) == '<section>') {
91e0dccc 47 for ($n++; $n < $cntdoc
48 && (trim(strtolower($doc[$n])) != '</section>')
cd08020d 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] = '';
91e0dccc 56 for ($n++;$n < $cntdoc
cd08020d 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] = '';
91e0dccc 64 for ($n++; $n < $cntdoc
65 && (trim(strtolower($doc[$n])) != '</summary>');
cd08020d 66 $n++) {
67 $ary[2] .= $doc[$n];
68 }
69 }
2d367c68 70 }
1863670d 71 if (isset($ary)) {
cd08020d 72 $ary[3] = $n;
390372b4 73 } else {
0120b304 74 $ary[0] = _("ERROR: Help files are not in the right format!");
75 $ary[1] = $ary[0];
76 $ary[2] = $ary[0];
2d367c68 77 }
134e4174 78 return( $ary );
143c7a82 79 } else if (!trim(strtolower($doc[$n]))) {
134e4174 80 $ary[0] = '';
81 $ary[1] = '';
82 $ary[2] = '';
83 $ary[3] = $n;
84 }
cd08020d 85 }
0120b304 86 $ary[0] = _("ERROR: Help files are not in the right format!");
87 $ary[1] = $ary[0];
143c7a82 88 $ary[2] = $ary[0];
89 $ary[3] = $n;
0120b304 90 return( $ary );
cd08020d 91}
2d367c68 92
cd08020d 93/**************[ END HELP FUNCTIONS ]******************/
390372b4 94
6e515418 95do_hook('help_top', $null);
3530b83b 96
cd08020d 97if (!isset($squirrelmail_language)) {
e5916f84 98 $squirrelmail_language = 'en_US';
cd08020d 99}
100
cd08020d 101if (file_exists("../help/$squirrelmail_language")) {
cd08020d 102 $user_language = $squirrelmail_language;
e5916f84 103} else if (file_exists('../help/en_US')) {
1b858d86 104 error_box(_("Help is not available in the selected language. It will be displayed in English instead."));
386c7b54 105 echo '<br />';
e5916f84 106 $user_language = 'en_US';
cd08020d 107} else {
1b858d86 108 error_box( _("Help is not available. Please contact your system administrator for assistance."));
1ce76674 109 echo '</td></tr></table>';
110 // Display footer (closes HTML tags) and stop script execution.
1b858d86 111 $oTemplate->display('footer.tpl');
1ce76674 112 exit;
cd08020d 113}
114
7ea33e5b 115
116/* take the chapternumber from the GET-vars,
117 * else see if we can get a relevant chapter from the referer */
118$chapter = 0;
119
1e12d1ff 120if ( sqgetGlobalVar('chapter', $temp, SQ_GET) ) {
121 $chapter = (int) $temp;
122} elseif ( sqgetGlobalVar('HTTP_REFERER', $temp, SQ_SERVER) ) {
123 $ref = strtolower($temp);
7ea33e5b 124
125 $contexts = array ( 'src/compose' => 4, 'src/addr' => 5,
126 'src/folders' => 6, 'src/options' => 7, 'src/right_main' => 2,
127 'src/read_body' => 3, 'src/search' => 8 );
128
129 foreach($contexts as $path => $chap) {
130 if(strpos($ref, $path)) {
131 $chapter = $chap;
132 break;
133 }
cd08020d 134 }
7ea33e5b 135}
136
137if ( $chapter == 0 || !isset( $helpdir[$chapter-1] ) ) {
386c7b54 138 // Initialise the needed variables.
139 $toc = array();
140
141 // Get the chapter numbers, title and decriptions.
142 for ($i=0, $cnt = count($helpdir); $i < $cnt; $i++) {
143 if (file_exists("../help/$user_language/$helpdir[$i]")) {
144 // First try the selected language.
145 $doc = file("../help/$user_language/$helpdir[$i]");
146 $help_info = get_info($doc, 0);
147 $toc[] = array($i+1, $help_info[0], $help_info[2]);
148 } elseif (file_exists("../help/en_US/$helpdir[$i]")) {
149 // If the selected language can't be found, try English.
150 $doc = file("../help/en_US/$helpdir[$i]");
151 $help_info = get_info($doc, 0);
152 $toc[] = array($i+1, $help_info[0],
153 _("This chapter is not available in the selected language. It will be displayed in English instead.") .
154 '<br />' . $help_info[2]);
155 } else {
156 // If English can't be found, the chapter went MIA.
157 $toc[] = array($i+1, _("This chapter is missing"),
158 sprintf(_("For some reason, chapter %s is not available."), $i+1));
159 }
160 }
161
386c7b54 162 // Provide hook for external help scripts.
6e515418 163 do_hook('help_chapter', $null);
95acecda 164
165 $new_toc = array();
166 foreach ($toc as $ch) {
167 $a = array();
168 $a['Chapter'] = $ch[0];
169 $a['Title'] = $ch[1];
170 $a['Summary'] = trim($ch[2]);
171 $new_toc[] = $a;
172 }
173
174 $oTemplate->assign('toc', $new_toc);
175
176 $oTemplate->display('help_toc.tpl');
7ea33e5b 177} else {
386c7b54 178 // Initialise the needed variables.
179 $display_chapter = TRUE;
180
181 // Get the chapter.
182 if (file_exists("../help/$user_language/" . $helpdir[$chapter-1])) {
183 // First try the selected language.
184 $doc = file("../help/$user_language/" . $helpdir[$chapter-1]);
185 } elseif (file_exists("../help/en_US/" . $helpdir[$chapter-1])) {
186 // If the selected language can't be found, try English.
187 $doc = file("../help/en_US/" . $helpdir[$chapter-1]);
e7c3f032 188 error_box(_("This chapter is not available in the selected language. It will be displayed in English instead."));
386c7b54 189 echo '<br />';
190 } else {
191 // If English can't be found, the chapter went MIA.
192 $display_chapter = FALSE;
193 }
194
386c7b54 195 // Write the chapter.
196 if ($display_chapter) {
197 // If there is a valid chapter, display it.
198 $help_info = get_info($doc, 0);
95acecda 199 $ch = array();
200 $ch['Chapter'] = $chapter;
201 $ch['Title'] = $help_info[0];
202 $ch['Summary'] = isset($help_info[1]) && $help_info[1] ? trim($help_info[1]) : $help_info[2];
203 $ch['Sections'] = array();
386c7b54 204 $section = 0;
205 for ($n = $help_info[3], $cnt = count($doc); $n < $cnt; $n++) {
206 $section++;
207 $help_info = get_info($doc, $n);
386c7b54 208 $n = $help_info[3];
7ea33e5b 209
95acecda 210 $a = array();
211 $a['SectionNumber'] = $section;
212 $a['SectionTitle'] = $help_info[0];
213 $a['SectionText'] = isset($help_info[1]) ? trim($help_info[1]) : '';;
214
215 $ch['Sections'][] = $a;
216 }
217
218 $oTemplate->assign('chapter_number', $chapter);
219 $oTemplate->assign('chapter_count', count($helpdir));
220 $oTemplate->assign('chapter_title', $ch['Title']);
221 $oTemplate->assign('chapter_summary', $ch['Summary']);
222 $oTemplate->assign('sections', $ch['Sections']);
223 $oTemplate->assign('error_msg', NULL);
386c7b54 224 } else {
95acecda 225 // If the help file went MIA, trigger an error message.
226 $oTemplate->assign('chapter_number', $chapter);
227 $oTemplate->assign('chapter_count', count($helpdir));
228 $oTemplate->assign('chapter_title', '');
229 $oTemplate->assign('chapter_summary', '');
230 $oTemplate->assign('sections', array());
231 $oTemplate->assign('error_msg', sprintf(_("For some reason, chapter %s is not available."), $chapter));
386c7b54 232 }
95acecda 233
234 $oTemplate->display('help_chapter.tpl');
cd08020d 235}
7ea33e5b 236
6e515418 237do_hook('help_bottom', $null);
3530b83b 238
5c4ff7bf 239$oTemplate->display('footer.tpl');
6e515418 240?>