6 * Displays help for the user
8 * @copyright 1999-2010 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
14 /** This is the help page */
15 define('PAGE_NAME', 'help');
18 * Include the SquirrelMail initialization file.
20 require('../include/init.php');
22 displayPageHeader($color);
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';
34 /****************[ HELP FUNCTIONS ]********************/
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.
42 function get_info($doc, $pos) {
45 $cntdoc = count($doc);
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>') {
55 $ary[0] = trim($doc[$n]);
57 if (trim(strtolower($doc[$n])) == '<description>') {
59 for ($n++
;$n < $cntdoc
60 && (trim(strtolower($doc[$n])) != '</description>');
65 if (trim(strtolower($doc[$n])) == '<summary>') {
67 for ($n++
; $n < $cntdoc
68 && (trim(strtolower($doc[$n])) != '</summary>');
77 $ary[0] = _("ERROR: Help files are not in the right format!");
82 } else if (!trim(strtolower($doc[$n]))) {
89 $ary[0] = _("ERROR: Help files are not in the right format!");
96 /**************[ END HELP FUNCTIONS ]******************/
98 do_hook('help_top', $null);
100 if (!isset($squirrelmail_language)) {
101 $squirrelmail_language = 'en_US';
104 if (file_exists("../help/$squirrelmail_language")) {
105 $user_language = $squirrelmail_language;
106 } else if (file_exists('../help/en_US')) {
107 error_box(_("Help is not available in the selected language. It will be displayed in English instead."));
109 $user_language = 'en_US';
111 error_box( _("Help is not available. Please contact your system administrator for assistance."));
112 echo '</td></tr></table>';
113 // Display footer (closes HTML tags) and stop script execution.
114 $oTemplate->display('footer.tpl');
119 /* take the chapternumber from the GET-vars,
120 * else see if we can get a relevant chapter from the referer */
123 if ( sqgetGlobalVar('chapter', $temp, SQ_GET
) ) {
124 $chapter = (int) $temp;
125 } elseif ( sqgetGlobalVar('HTTP_REFERER', $temp, SQ_SERVER
) ) {
126 $ref = strtolower($temp);
128 $contexts = array ( 'src/compose' => 4, 'src/addr' => 5,
129 'src/folders' => 6, 'src/options' => 7, 'src/right_main' => 2,
130 'src/read_body' => 3, 'src/search' => 8 );
132 foreach($contexts as $path => $chap) {
133 if(strpos($ref, $path)) {
140 if ( $chapter == 0 ||
!isset( $helpdir[$chapter-1] ) ) {
141 // Initialise the needed variables.
144 // Get the chapter numbers, title and decriptions.
145 for ($i=0, $cnt = count($helpdir); $i < $cnt; $i++
) {
146 if (file_exists("../help/$user_language/$helpdir[$i]")) {
147 // First try the selected language.
148 $doc = file("../help/$user_language/$helpdir[$i]");
149 $help_info = get_info($doc, 0);
150 $toc[] = array($i+
1, $help_info[0], $help_info[2]);
151 } elseif (file_exists("../help/en_US/$helpdir[$i]")) {
152 // If the selected language can't be found, try English.
153 $doc = file("../help/en_US/$helpdir[$i]");
154 $help_info = get_info($doc, 0);
155 $toc[] = array($i+
1, $help_info[0],
156 _("This chapter is not available in the selected language. It will be displayed in English instead.") .
157 '<br />' . $help_info[2]);
159 // If English can't be found, the chapter went MIA.
160 $toc[] = array($i+
1, _("This chapter is missing"),
161 sprintf(_("For some reason, chapter %s is not available."), $i+
1));
165 // Provide hook for external help scripts.
166 do_hook('help_chapter', $null);
169 foreach ($toc as $ch) {
171 $a['Chapter'] = $ch[0];
172 $a['Title'] = $ch[1];
173 $a['Summary'] = trim($ch[2]);
177 $oTemplate->assign('toc', $new_toc);
179 $oTemplate->display('help_toc.tpl');
181 // Initialise the needed variables.
182 $display_chapter = TRUE;
185 if (file_exists("../help/$user_language/" . $helpdir[$chapter-1])) {
186 // First try the selected language.
187 $doc = file("../help/$user_language/" . $helpdir[$chapter-1]);
188 } elseif (file_exists("../help/en_US/" . $helpdir[$chapter-1])) {
189 // If the selected language can't be found, try English.
190 $doc = file("../help/en_US/" . $helpdir[$chapter-1]);
191 error_box(_("This chapter is not available in the selected language. It will be displayed in English instead."));
194 // If English can't be found, the chapter went MIA.
195 $display_chapter = FALSE;
198 // Write the chapter.
199 if ($display_chapter) {
200 // If there is a valid chapter, display it.
201 $help_info = get_info($doc, 0);
203 $ch['Chapter'] = $chapter;
204 $ch['Title'] = $help_info[0];
205 $ch['Summary'] = isset($help_info[1]) && $help_info[1] ?
trim($help_info[1]) : $help_info[2];
206 $ch['Sections'] = array();
208 for ($n = $help_info[3], $cnt = count($doc); $n < $cnt; $n++
) {
210 $help_info = get_info($doc, $n);
214 $a['SectionNumber'] = $section;
215 $a['SectionTitle'] = $help_info[0];
216 $a['SectionText'] = isset($help_info[1]) ?
trim($help_info[1]) : '';;
218 $ch['Sections'][] = $a;
221 $oTemplate->assign('chapter_number', $chapter);
222 $oTemplate->assign('chapter_count', count($helpdir));
223 $oTemplate->assign('chapter_title', $ch['Title']);
224 $oTemplate->assign('chapter_summary', $ch['Summary']);
225 $oTemplate->assign('sections', $ch['Sections']);
226 $oTemplate->assign('error_msg', NULL);
228 // If the help file went MIA, trigger an error message.
229 $oTemplate->assign('chapter_number', $chapter);
230 $oTemplate->assign('chapter_count', count($helpdir));
231 $oTemplate->assign('chapter_title', '');
232 $oTemplate->assign('chapter_summary', '');
233 $oTemplate->assign('sections', array());
234 $oTemplate->assign('error_msg', sprintf(_("For some reason, chapter %s is not available."), $chapter));
237 $oTemplate->display('help_chapter.tpl');
240 do_hook('help_bottom', $null);
242 $oTemplate->display('footer.tpl');