Minor simplification.
[squirrelmail.git] / src / help.php
1 <?php
2
3 /**
4 * help.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Displays help for the user
10 *
11 * $Id$
12 */
13
14 /*****************************************************************/
15 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
16 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
17 /*** + Base level indent should begin at left margin, as ***/
18 /*** the require_once below looks. ***/
19 /*** + All identation should consist of four space blocks ***/
20 /*** + Tab characters are evil. ***/
21 /*** + all comments should use "slash-star ... star-slash" ***/
22 /*** style -- no pound characters, no slash-slash style ***/
23 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
24 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
25 /*** + Please use ' instead of ", when possible. Note " ***/
26 /*** should always be used in _( ) function calls. ***/
27 /*** Thank you for your help making the SM code more readable. ***/
28 /*****************************************************************/
29
30 require_once('../src/validate.php');
31 require_once('../functions/display_messages.php');
32 require_once('../functions/imap.php');
33 require_once('../functions/array.php');
34
35
36 displayPageHeader($color, 'None' );
37
38 $helpdir[0] = 'basic.hlp';
39 $helpdir[1] = 'main_folder.hlp';
40 $helpdir[2] = 'read_mail.hlp';
41 $helpdir[3] = 'compose.hlp';
42 $helpdir[4] = 'addresses.hlp';
43 $helpdir[5] = 'folders.hlp';
44 $helpdir[6] = 'options.hlp';
45 $helpdir[7] = 'search.hlp';
46 $helpdir[8] = 'FAQ.hlp';
47
48 /****************[ HELP FUNCTIONS ]********************/
49 // parses through and gets the information from the different documents.
50 // this returns one section at a time. You must keep track of the position
51 // so that it knows where to start to look for the next section.
52
53 function get_info($doc, $pos) {
54 for ($n=$pos; $n < count($doc); $n++) {
55 if (trim(strtolower($doc[$n])) == "<chapter>" || trim(strtolower($doc[$n])) == "<section>") {
56 for ($n++;$n < count($doc) && (trim(strtolower($doc[$n])) != "</section>") && (trim(strtolower($doc[$n])) != "</chapter>"); $n++) {
57 if (trim(strtolower($doc[$n])) == "<title>") {
58 $n++;
59 $ary[0] = trim($doc[$n]);
60 }
61 if (trim(strtolower($doc[$n])) == "<description>") {
62 $ary[1] = "";
63 for ($n++;$n < count($doc) && (trim(strtolower($doc[$n])) != "</description>"); $n++) {
64 $ary[1] .= $doc[$n];
65 }
66 }
67 if (trim(strtolower($doc[$n])) == "<summary>") {
68 $ary[2] = "";
69 for ($n++;$n < count($doc) && (trim(strtolower($doc[$n])) != "</summary>"); $n++) {
70 $ary[2] .= $doc[$n];
71 }
72 }
73 }
74 if (isset($ary)) {
75 $ary[3] = $n;
76 return $ary;
77 } else {
78 $ary[0] = "ERROR: Help files are not in the right format!";
79 $ary[1] = "ERROR: Help files are not in the right format!";
80 $ary[2] = "ERROR: Help files are not in the right format!";
81 return $ary;
82 }
83 }
84 }
85 $ary[0] = "ERROR: Help files are not in the right format!";
86 $ary[1] = "ERROR: Help files are not in the right format!";
87 return $ary;
88 }
89
90 /**************[ END HELP FUNCTIONS ]******************/
91
92 ?>
93
94 <br>
95 <table width=95% align=center cellpadding=2 cellspacing=2 border=0>
96 <tr><td bgcolor="<?php echo $color[0] ?>">
97 <center><b><?php echo _("Help") ?></b></center>
98 </td></tr></table>
99
100 <?php do_hook("help_top") ?>
101
102 <table width=90% cellpadding=0 cellspacing=10 border=0 align=center><tr><td>
103 <?php
104 if ($HTTP_REFERER) {
105 $ref = strtolower($HTTP_REFERER);
106 if (strpos($ref, "src/compose"))
107 $context = "compose";
108 else if (strpos($ref, "src/addr"))
109 $context = "address";
110 else if (strpos($ref, "src/folders"))
111 $context = "folders";
112 else if (strpos($ref, "src/options"))
113 $context = "options";
114 else if (strpos($ref, "src/right_main"))
115 $context = "index";
116 else if (strpos($ref, "src/read_body"))
117 $context = "read";
118 else if (strpos($ref, "src/search"))
119 $context = "search";
120 }
121
122 if (!$squirrelmail_language)
123 $squirrelmail_language = "en";
124 /**
125 * This harebrained solution is here because it produces the
126 * smallest patchfile.
127 * The real solution would be to either:
128 * a) move all locales into full-name locale names, like they
129 * really should be according to the ISO docs (e.g. en -> en_US,
130 * es -> es_ES, ru -> ru_RU), since it's standard to have a language
131 * name + undescore + country name.
132 * b) Provide a $languages['ru_RU']['HELPALIAS'] = 'ru';
133 *
134 * Konstantin Riabitsev
135 */
136 global $languages;
137 while (list($key, $val) = each($languages)){
138 if ($val['ALIAS'] == $squirrelmail_language){
139 $squirrelmail_language = $key;
140 break;
141 }
142 }
143
144
145 if (file_exists("../help/$squirrelmail_language")) {
146 $help_exists = true;
147 $user_language = $squirrelmail_language;
148 } else if (file_exists("../help/en")) {
149 $help_exists = true;
150 echo "<center><font color=\"$color[2]\">";
151 printf (_("The help has not been translated to %s. It will be displayed in English instead."), $languages[$squirrelmail_language]["NAME"]);
152 echo "</font></center><br>";
153 $user_language = "en";
154 } else {
155 $help_exists = false;
156 echo "<br><center><font color=\"$color[2]\">";
157 echo _("Some or all of the help documents are not present!");
158 echo "</font></center>";
159 echo "</td></tr></table>";
160 exit;
161 }
162
163 if ($help_exists) {
164 if (! isset($context))
165 $context = '';
166 if ($context == "compose")
167 $chapter = 4;
168 else if ($context == "address")
169 $chapter = 5;
170 else if ($context == "folders")
171 $chapter = 6;
172 else if ($context == "options")
173 $chapter = 7;
174 else if ($context == "index")
175 $chapter = 2;
176 else if ($context == "read")
177 $chapter = 3;
178 else if ($context == "search")
179 $chapter = 8;
180
181 if (!isset($chapter)) {
182 echo "<table cellpadding=0 cellspacing=0 border=0 align=center><tr><td>\n";
183 echo "<b><center>" . _("Table of Contents") . "</center></b><br>";
184 do_hook("help_chapter");
185 echo "<ol>\n";
186 for ($i=0; $i < count($helpdir); $i++) {
187 $doc = file("../help/$user_language/$helpdir[$i]");
188 $help_info = get_info($doc, 0);
189 echo "<li><a href=\"../src/help.php?chapter=". ($i+1) ."\">$help_info[0]</a>\n";
190 echo "<ul>$help_info[2]</ul>";
191 }
192 echo "</ol>\n";
193 echo "</td></tr></table>\n";
194 } else {
195 $doc = file("../help/$user_language/".$helpdir[$chapter-1]);
196 $help_info = get_info($doc, 0);
197
198 echo "<small><center>";
199
200 if ($chapter <= 1) echo "<font color=\"$color[9]\">"._("Previous")."</font> | ";
201 else echo "<a href=\"../src/help.php?chapter=".($chapter-1)."\">"._("Previous")."</a> | ";
202 echo "<a href=\"../src/help.php\">"._("Table of Contents")."</a>";
203 if ($chapter >= count($helpdir)) echo " | <font color=\"$color[9]\">"._("Next")."</font>";
204 else echo " | <a href=\"../src/help.php?chapter=".($chapter+1)."\">"._("Next")."</a>\n";
205 echo "</center></small><br>\n";
206
207 echo "<font size=5><b>$chapter - $help_info[0]</b></font><br><br>\n";
208 if (isset($help_info[1]))
209 echo "$help_info[1]\n";
210 else
211 echo "<p>$help_info[2]</p>\n";
212
213 $section = 0;
214 for ($n = $help_info[3]; $n < count($doc); $n++) {
215 $section++;
216 $help_info = get_info($doc, $n);
217 echo "<b>$chapter.$section - $help_info[0]</b>";
218 echo "<ul>";
219 echo "$help_info[1]";
220 echo "</ul>";
221 $n = $help_info[3];
222 }
223
224 echo "<br><center><a href=\"#pagetop\">" . _("Top") . "</a></center>\n";
225 }
226 }
227 do_hook("help_bottom");
228 ?>
229 <tr><td bgcolor="<?php echo $color[0] ?>">&nbsp;</td></tr></table>
230 <td></tr></table>
231 </body></html>