6 * Displays help for the user
8 * @copyright © 1999-2007 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
15 * Include the SquirrelMail initialization file.
17 require('../include/init.php');
19 displayPageHeader($color);
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';
31 /****************[ HELP FUNCTIONS ]********************/
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.
39 function get_info($doc, $pos) {
42 $cntdoc = count($doc);
44 for ($n=$pos; $n < $cntdoc; $n++
) {
45 if (trim(strtolower($doc[$n])) == '<chapter>'
46 ||
trim(strtolower($doc[$n])) == '<section>') {
47 for ($n++
; $n < $cntdoc
48 && (trim(strtolower($doc[$n])) != '</section>')
49 && (trim(strtolower($doc[$n])) != '</chapter>'); $n++
) {
50 if (trim(strtolower($doc[$n])) == '<title>') {
52 $ary[0] = trim($doc[$n]);
54 if (trim(strtolower($doc[$n])) == '<description>') {
56 for ($n++
;$n < $cntdoc
57 && (trim(strtolower($doc[$n])) != '</description>');
62 if (trim(strtolower($doc[$n])) == '<summary>') {
64 for ($n++
; $n < $cntdoc
65 && (trim(strtolower($doc[$n])) != '</summary>');
74 $ary[0] = _("ERROR: Help files are not in the right format!");
79 } else if (!trim(strtolower($doc[$n]))) {
86 $ary[0] = _("ERROR: Help files are not in the right format!");
93 /**************[ END HELP FUNCTIONS ]******************/
95 do_hook('help_top', $null);
97 if (!isset($squirrelmail_language)) {
98 $squirrelmail_language = 'en_US';
101 if (file_exists("../help/$squirrelmail_language")) {
102 $user_language = $squirrelmail_language;
103 } else if (file_exists('../help/en_US')) {
104 error_box(_("Help is not available in the selected language. It will be displayed in English instead."));
106 $user_language = 'en_US';
108 error_box( _("Help is not available. Please contact your system administrator for assistance."));
109 echo '</td></tr></table>';
110 // Display footer (closes HTML tags) and stop script execution.
111 $oTemplate->display('footer.tpl');
116 /* take the chapternumber from the GET-vars,
117 * else see if we can get a relevant chapter from the referer */
120 if ( sqgetGlobalVar('chapter', $temp, SQ_GET
) ) {
121 $chapter = (int) $temp;
122 } elseif ( sqgetGlobalVar('HTTP_REFERER', $temp, SQ_SERVER
) ) {
123 $ref = strtolower($temp);
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 );
129 foreach($contexts as $path => $chap) {
130 if(strpos($ref, $path)) {
137 if ( $chapter == 0 ||
!isset( $helpdir[$chapter-1] ) ) {
138 // Initialise the needed variables.
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]);
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));
162 // Provide hook for external help scripts.
163 do_hook('help_chapter', $null);
166 foreach ($toc as $ch) {
168 $a['Chapter'] = $ch[0];
169 $a['Title'] = $ch[1];
170 $a['Summary'] = trim($ch[2]);
174 $oTemplate->assign('toc', $new_toc);
176 $oTemplate->display('help_toc.tpl');
178 // Initialise the needed variables.
179 $display_chapter = TRUE;
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]);
188 error_box(_("This chapter is not available in the selected language. It will be displayed in English instead."));
191 // If English can't be found, the chapter went MIA.
192 $display_chapter = FALSE;
195 // Write the chapter.
196 if ($display_chapter) {
197 // If there is a valid chapter, display it.
198 $help_info = get_info($doc, 0);
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();
205 for ($n = $help_info[3], $cnt = count($doc); $n < $cnt; $n++
) {
207 $help_info = get_info($doc, $n);
211 $a['SectionNumber'] = $section;
212 $a['SectionTitle'] = $help_info[0];
213 $a['SectionText'] = isset($help_info[1]) ?
trim($help_info[1]) : '';;
215 $ch['Sections'][] = $a;
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);
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));
234 $oTemplate->display('help_chapter.tpl');
237 do_hook('help_bottom', $null);
239 $oTemplate->display('footer.tpl');