e222c290 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * help.php |
5 | * |
35586184 |
6 | * Displays help for the user |
7 | * |
77a1e3d1 |
8 | * @copyright 1999-2022 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 | |
ebd2391c |
14 | /** This is the help page */ |
15 | define('PAGE_NAME', 'help'); |
16 | |
30967a1e |
17 | /** |
202bcbcc |
18 | * Include the SquirrelMail initialization file. |
30967a1e |
19 | */ |
202bcbcc |
20 | require('../include/init.php'); |
390372b4 |
21 | |
876fdb60 |
22 | displayPageHeader($color); |
cd08020d |
23 | |
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'; |
33 | |
34 | /****************[ HELP FUNCTIONS ]********************/ |
390372b4 |
35 | |
cd08020d |
36 | /** |
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. |
40 | */ |
41 | |
42 | function get_info($doc, $pos) { |
143c7a82 |
43 | $ary = array(0,0,0); |
7ea33e5b |
44 | |
45 | $cntdoc = count($doc); |
46 | |
47 | for ($n=$pos; $n < $cntdoc; $n++) { |
cd08020d |
48 | if (trim(strtolower($doc[$n])) == '<chapter>' |
49 | || trim(strtolower($doc[$n])) == '<section>') { |
91e0dccc |
50 | for ($n++; $n < $cntdoc |
51 | && (trim(strtolower($doc[$n])) != '</section>') |
cd08020d |
52 | && (trim(strtolower($doc[$n])) != '</chapter>'); $n++) { |
53 | if (trim(strtolower($doc[$n])) == '<title>') { |
54 | $n++; |
55 | $ary[0] = trim($doc[$n]); |
56 | } |
57 | if (trim(strtolower($doc[$n])) == '<description>') { |
58 | $ary[1] = ''; |
91e0dccc |
59 | for ($n++;$n < $cntdoc |
cd08020d |
60 | && (trim(strtolower($doc[$n])) != '</description>'); |
61 | $n++) { |
62 | $ary[1] .= $doc[$n]; |
63 | } |
64 | } |
65 | if (trim(strtolower($doc[$n])) == '<summary>') { |
66 | $ary[2] = ''; |
91e0dccc |
67 | for ($n++; $n < $cntdoc |
68 | && (trim(strtolower($doc[$n])) != '</summary>'); |
cd08020d |
69 | $n++) { |
70 | $ary[2] .= $doc[$n]; |
71 | } |
72 | } |
2d367c68 |
73 | } |
1863670d |
74 | if (isset($ary)) { |
cd08020d |
75 | $ary[3] = $n; |
390372b4 |
76 | } else { |
0120b304 |
77 | $ary[0] = _("ERROR: Help files are not in the right format!"); |
78 | $ary[1] = $ary[0]; |
79 | $ary[2] = $ary[0]; |
2d367c68 |
80 | } |
134e4174 |
81 | return( $ary ); |
143c7a82 |
82 | } else if (!trim(strtolower($doc[$n]))) { |
134e4174 |
83 | $ary[0] = ''; |
84 | $ary[1] = ''; |
85 | $ary[2] = ''; |
86 | $ary[3] = $n; |
87 | } |
cd08020d |
88 | } |
0120b304 |
89 | $ary[0] = _("ERROR: Help files are not in the right format!"); |
90 | $ary[1] = $ary[0]; |
143c7a82 |
91 | $ary[2] = $ary[0]; |
92 | $ary[3] = $n; |
0120b304 |
93 | return( $ary ); |
cd08020d |
94 | } |
2d367c68 |
95 | |
cd08020d |
96 | /**************[ END HELP FUNCTIONS ]******************/ |
390372b4 |
97 | |
6e515418 |
98 | do_hook('help_top', $null); |
3530b83b |
99 | |
cd08020d |
100 | if (!isset($squirrelmail_language)) { |
e5916f84 |
101 | $squirrelmail_language = 'en_US'; |
cd08020d |
102 | } |
103 | |
cd08020d |
104 | if (file_exists("../help/$squirrelmail_language")) { |
cd08020d |
105 | $user_language = $squirrelmail_language; |
e5916f84 |
106 | } else if (file_exists('../help/en_US')) { |
1b858d86 |
107 | error_box(_("Help is not available in the selected language. It will be displayed in English instead.")); |
386c7b54 |
108 | echo '<br />'; |
e5916f84 |
109 | $user_language = 'en_US'; |
cd08020d |
110 | } else { |
1b858d86 |
111 | error_box( _("Help is not available. Please contact your system administrator for assistance.")); |
1ce76674 |
112 | echo '</td></tr></table>'; |
113 | // Display footer (closes HTML tags) and stop script execution. |
1b858d86 |
114 | $oTemplate->display('footer.tpl'); |
1ce76674 |
115 | exit; |
cd08020d |
116 | } |
117 | |
7ea33e5b |
118 | |
119 | /* take the chapternumber from the GET-vars, |
120 | * else see if we can get a relevant chapter from the referer */ |
121 | $chapter = 0; |
122 | |
1e12d1ff |
123 | if ( sqgetGlobalVar('chapter', $temp, SQ_GET) ) { |
124 | $chapter = (int) $temp; |
125 | } elseif ( sqgetGlobalVar('HTTP_REFERER', $temp, SQ_SERVER) ) { |
126 | $ref = strtolower($temp); |
7ea33e5b |
127 | |
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 ); |
131 | |
132 | foreach($contexts as $path => $chap) { |
133 | if(strpos($ref, $path)) { |
134 | $chapter = $chap; |
135 | break; |
136 | } |
cd08020d |
137 | } |
7ea33e5b |
138 | } |
139 | |
140 | if ( $chapter == 0 || !isset( $helpdir[$chapter-1] ) ) { |
386c7b54 |
141 | // Initialise the needed variables. |
142 | $toc = array(); |
143 | |
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]); |
158 | } else { |
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)); |
162 | } |
163 | } |
164 | |
386c7b54 |
165 | // Provide hook for external help scripts. |
6e515418 |
166 | do_hook('help_chapter', $null); |
95acecda |
167 | |
168 | $new_toc = array(); |
169 | foreach ($toc as $ch) { |
170 | $a = array(); |
171 | $a['Chapter'] = $ch[0]; |
172 | $a['Title'] = $ch[1]; |
173 | $a['Summary'] = trim($ch[2]); |
174 | $new_toc[] = $a; |
175 | } |
176 | |
177 | $oTemplate->assign('toc', $new_toc); |
178 | |
179 | $oTemplate->display('help_toc.tpl'); |
7ea33e5b |
180 | } else { |
386c7b54 |
181 | // Initialise the needed variables. |
182 | $display_chapter = TRUE; |
183 | |
184 | // Get the chapter. |
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]); |
e7c3f032 |
191 | error_box(_("This chapter is not available in the selected language. It will be displayed in English instead.")); |
386c7b54 |
192 | echo '<br />'; |
193 | } else { |
194 | // If English can't be found, the chapter went MIA. |
195 | $display_chapter = FALSE; |
196 | } |
197 | |
386c7b54 |
198 | // Write the chapter. |
199 | if ($display_chapter) { |
200 | // If there is a valid chapter, display it. |
201 | $help_info = get_info($doc, 0); |
95acecda |
202 | $ch = array(); |
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(); |
386c7b54 |
207 | $section = 0; |
208 | for ($n = $help_info[3], $cnt = count($doc); $n < $cnt; $n++) { |
209 | $section++; |
210 | $help_info = get_info($doc, $n); |
386c7b54 |
211 | $n = $help_info[3]; |
7ea33e5b |
212 | |
95acecda |
213 | $a = array(); |
214 | $a['SectionNumber'] = $section; |
215 | $a['SectionTitle'] = $help_info[0]; |
216 | $a['SectionText'] = isset($help_info[1]) ? trim($help_info[1]) : '';; |
217 | |
218 | $ch['Sections'][] = $a; |
219 | } |
220 | |
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); |
386c7b54 |
227 | } else { |
95acecda |
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)); |
386c7b54 |
235 | } |
95acecda |
236 | |
237 | $oTemplate->display('help_chapter.tpl'); |
cd08020d |
238 | } |
7ea33e5b |
239 | |
6e515418 |
240 | do_hook('help_bottom', $null); |
3530b83b |
241 | |
5c4ff7bf |
242 | $oTemplate->display('footer.tpl'); |