Operation "foo_once".
[squirrelmail.git] / src / help.php
1 <?php
2 /**
3 ** help.php
4 **
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** Displays help for the user
9 **
10 ** $Id$
11 **/
12
13 require_once('../src/validate.php');
14 require_once('../functions/display_messages.php');
15 require_once('../functions/imap.php');
16 require_once('../functions/array.php');
17
18
19 displayPageHeader($color, "None");
20
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";
30
31 /****************[ HELP FUNCTIONS ]********************/
32 // parses through and gets the information from the different documents.
33 // this returns one section at a time. You must keep track of the position
34 // so that it knows where to start to look for the next section.
35
36 function get_info($doc, $pos) {
37 for ($n=$pos; $n < count($doc); $n++) {
38 if (trim(strtolower($doc[$n])) == "<chapter>" || trim(strtolower($doc[$n])) == "<section>") {
39 for ($n++;$n < count($doc) && (trim(strtolower($doc[$n])) != "</section>") && (trim(strtolower($doc[$n])) != "</chapter>"); $n++) {
40 if (trim(strtolower($doc[$n])) == "<title>") {
41 $n++;
42 $ary[0] = trim($doc[$n]);
43 }
44 if (trim(strtolower($doc[$n])) == "<description>") {
45 $ary[1] = "";
46 for ($n++;$n < count($doc) && (trim(strtolower($doc[$n])) != "</description>"); $n++) {
47 $ary[1] .= $doc[$n];
48 }
49 }
50 if (trim(strtolower($doc[$n])) == "<summary>") {
51 $ary[2] = "";
52 for ($n++;$n < count($doc) && (trim(strtolower($doc[$n])) != "</summary>"); $n++) {
53 $ary[2] .= $doc[$n];
54 }
55 }
56 }
57 if (isset($ary)) {
58 $ary[3] = $n;
59 return $ary;
60 } else {
61 $ary[0] = "ERROR: Help files are not in the right format!";
62 $ary[1] = "ERROR: Help files are not in the right format!";
63 $ary[2] = "ERROR: Help files are not in the right format!";
64 return $ary;
65 }
66 }
67 }
68 $ary[0] = "ERROR: Help files are not in the right format!";
69 $ary[1] = "ERROR: Help files are not in the right format!";
70 return $ary;
71 }
72
73 /**************[ END HELP FUNCTIONS ]******************/
74
75 ?>
76
77 <br>
78 <table width=95% align=center cellpadding=2 cellspacing=2 border=0>
79 <tr><td bgcolor="<?php echo $color[0] ?>">
80 <center><b><?php echo _("Help") ?></b></center>
81 </td></tr></table>
82
83 <?php do_hook("help_top") ?>
84
85 <table width=90% cellpadding=0 cellspacing=10 border=0 align=center><tr><td>
86 <?php
87 if ($HTTP_REFERER) {
88 $ref = strtolower($HTTP_REFERER);
89 if (strpos($ref, "src/compose"))
90 $context = "compose";
91 else if (strpos($ref, "src/addr"))
92 $context = "address";
93 else if (strpos($ref, "src/folders"))
94 $context = "folders";
95 else if (strpos($ref, "src/options"))
96 $context = "options";
97 else if (strpos($ref, "src/right_main"))
98 $context = "index";
99 else if (strpos($ref, "src/read_body"))
100 $context = "read";
101 else if (strpos($ref, "src/search"))
102 $context = "search";
103 }
104
105 if (!$squirrelmail_language)
106 $squirrelmail_language = "en";
107
108 if (file_exists("../help/$squirrelmail_language")) {
109 $help_exists = true;
110 $user_language = $squirrelmail_language;
111 } else if (file_exists("../help/en")) {
112 $help_exists = true;
113 echo "<center><font color=\"$color[2]\">";
114 printf (_("The help has not been translated to %s. It will be displayed in English instead."), $languages[$squirrelmail_language]["NAME"]);
115 echo "</font></center><br>";
116 $user_language = "en";
117 } else {
118 $help_exists = false;
119 echo "<br><center><font color=\"$color[2]\">";
120 echo _("Some or all of the help documents are not present!");
121 echo "</font></center>";
122 echo "</td></tr></table>";
123 exit;
124 }
125
126 if ($help_exists) {
127 if (! isset($context))
128 $context = '';
129 if ($context == "compose")
130 $chapter = 4;
131 else if ($context == "address")
132 $chapter = 5;
133 else if ($context == "folders")
134 $chapter = 6;
135 else if ($context == "options")
136 $chapter = 7;
137 else if ($context == "index")
138 $chapter = 2;
139 else if ($context == "read")
140 $chapter = 3;
141 else if ($context == "search")
142 $chapter = 8;
143
144 if (!isset($chapter)) {
145 echo "<table cellpadding=0 cellspacing=0 border=0 align=center><tr><td>\n";
146 echo "<b><center>" . _("Table of Contents") . "</center></b><br>";
147 do_hook("help_chapter");
148 echo "<ol>\n";
149 for ($i=0; $i < count($helpdir); $i++) {
150 $doc = file("../help/$user_language/$helpdir[$i]");
151 $help_info = get_info($doc, 0);
152 echo "<li><a href=\"../src/help.php?chapter=". ($i+1) ."\">$help_info[0]</a>\n";
153 echo "<ul>$help_info[2]</ul>";
154 }
155 echo "</ol>\n";
156 echo "</td></tr></table>\n";
157 } else {
158 $doc = file("../help/$user_language/".$helpdir[$chapter-1]);
159 $help_info = get_info($doc, 0);
160
161 echo "<small><center>";
162
163 if ($chapter <= 1) echo "<font color=\"$color[9]\">"._("Previous")."</font> | ";
164 else echo "<a href=\"../src/help.php?chapter=".($chapter-1)."\">"._("Previous")."</a> | ";
165 echo "<a href=\"../src/help.php\">"._("Table of Contents")."</a>";
166 if ($chapter >= count($helpdir)) echo " | <font color=\"$color[9]\">"._("Next")."</font>";
167 else echo " | <a href=\"../src/help.php?chapter=".($chapter+1)."\">"._("Next")."</a>\n";
168 echo "</center></small><br>\n";
169
170 echo "<font size=5><b>$chapter - $help_info[0]</b></font><br><br>\n";
171 if (isset($help_info[1]))
172 echo "$help_info[1]\n";
173 else
174 echo "<p>$help_info[2]</p>\n";
175
176 $section = 0;
177 for ($n = $help_info[3]; $n < count($doc); $n++) {
178 $section++;
179 $help_info = get_info($doc, $n);
180 echo "<b>$chapter.$section - $help_info[0]</b>";
181 echo "<ul>";
182 echo "$help_info[1]";
183 echo "</ul>";
184 $n = $help_info[3];
185 }
186
187 echo "<br><center><a href=\"#pagetop\">" . _("Top") . "</a></center>\n";
188 }
189 }
190 do_hook("help_bottom");
191 ?>
192 <tr><td bgcolor="<?php echo $color[0] ?>">&nbsp;</td></tr></table>
193 <td></tr></table>
194 </body></html>