Happy 2017
[squirrelmail.git] / src / help.php
1 <?php
2
3 /**
4 * help.php
5 *
6 * Displays help for the user
7 *
8 * @copyright 1999-2017 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /** This is the help page */
15 define('PAGE_NAME', 'help');
16
17 /**
18 * Include the SquirrelMail initialization file.
19 */
20 require('../include/init.php');
21
22 displayPageHeader($color);
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 ]********************/
35
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) {
43 $ary = array(0,0,0);
44
45 $cntdoc = count($doc);
46
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>') {
54 $n++;
55 $ary[0] = trim($doc[$n]);
56 }
57 if (trim(strtolower($doc[$n])) == '<description>') {
58 $ary[1] = '';
59 for ($n++;$n < $cntdoc
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] = '';
67 for ($n++; $n < $cntdoc
68 && (trim(strtolower($doc[$n])) != '</summary>');
69 $n++) {
70 $ary[2] .= $doc[$n];
71 }
72 }
73 }
74 if (isset($ary)) {
75 $ary[3] = $n;
76 } else {
77 $ary[0] = _("ERROR: Help files are not in the right format!");
78 $ary[1] = $ary[0];
79 $ary[2] = $ary[0];
80 }
81 return( $ary );
82 } else if (!trim(strtolower($doc[$n]))) {
83 $ary[0] = '';
84 $ary[1] = '';
85 $ary[2] = '';
86 $ary[3] = $n;
87 }
88 }
89 $ary[0] = _("ERROR: Help files are not in the right format!");
90 $ary[1] = $ary[0];
91 $ary[2] = $ary[0];
92 $ary[3] = $n;
93 return( $ary );
94 }
95
96 /**************[ END HELP FUNCTIONS ]******************/
97
98 do_hook('help_top', $null);
99
100 if (!isset($squirrelmail_language)) {
101 $squirrelmail_language = 'en_US';
102 }
103
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."));
108 echo '<br />';
109 $user_language = 'en_US';
110 } else {
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');
115 exit;
116 }
117
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
123 if ( sqgetGlobalVar('chapter', $temp, SQ_GET) ) {
124 $chapter = (int) $temp;
125 } elseif ( sqgetGlobalVar('HTTP_REFERER', $temp, SQ_SERVER) ) {
126 $ref = strtolower($temp);
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 }
137 }
138 }
139
140 if ( $chapter == 0 || !isset( $helpdir[$chapter-1] ) ) {
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
165 // Provide hook for external help scripts.
166 do_hook('help_chapter', $null);
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');
180 } else {
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]);
191 error_box(_("This chapter is not available in the selected language. It will be displayed in English instead."));
192 echo '<br />';
193 } else {
194 // If English can't be found, the chapter went MIA.
195 $display_chapter = FALSE;
196 }
197
198 // Write the chapter.
199 if ($display_chapter) {
200 // If there is a valid chapter, display it.
201 $help_info = get_info($doc, 0);
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();
207 $section = 0;
208 for ($n = $help_info[3], $cnt = count($doc); $n < $cnt; $n++) {
209 $section++;
210 $help_info = get_info($doc, $n);
211 $n = $help_info[3];
212
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);
227 } else {
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));
235 }
236
237 $oTemplate->display('help_chapter.tpl');
238 }
239
240 do_hook('help_bottom', $null);
241
242 $oTemplate->display('footer.tpl');