| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * help.php |
| 5 | * |
| 6 | * Displays help for the user |
| 7 | * |
| 8 | * @copyright © 1999-2006 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 | /** |
| 15 | * Include the SquirrelMail initialization file. |
| 16 | */ |
| 17 | require('../include/init.php'); |
| 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 | |
| 33 | /** |
| 34 | * parses through and gets the information from the different documents. |
| 35 | * this returns one section at a time. You must keep track of the position |
| 36 | * so that it knows where to start to look for the next section. |
| 37 | */ |
| 38 | |
| 39 | function get_info($doc, $pos) { |
| 40 | $ary = array(0,0,0); |
| 41 | |
| 42 | $cntdoc = count($doc); |
| 43 | |
| 44 | for ($n=$pos; $n < $cntdoc; $n++) { |
| 45 | if (trim(strtolower($doc[$n])) == '<chapter>' |
| 46 | || trim(strtolower($doc[$n])) == '<section>') { |
| 47 | for ($n++; $n < $cntdoc |
| 48 | && (trim(strtolower($doc[$n])) != '</section>') |
| 49 | && (trim(strtolower($doc[$n])) != '</chapter>'); $n++) { |
| 50 | if (trim(strtolower($doc[$n])) == '<title>') { |
| 51 | $n++; |
| 52 | $ary[0] = trim($doc[$n]); |
| 53 | } |
| 54 | if (trim(strtolower($doc[$n])) == '<description>') { |
| 55 | $ary[1] = ''; |
| 56 | for ($n++;$n < $cntdoc |
| 57 | && (trim(strtolower($doc[$n])) != '</description>'); |
| 58 | $n++) { |
| 59 | $ary[1] .= $doc[$n]; |
| 60 | } |
| 61 | } |
| 62 | if (trim(strtolower($doc[$n])) == '<summary>') { |
| 63 | $ary[2] = ''; |
| 64 | for ($n++; $n < $cntdoc |
| 65 | && (trim(strtolower($doc[$n])) != '</summary>'); |
| 66 | $n++) { |
| 67 | $ary[2] .= $doc[$n]; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | if (isset($ary)) { |
| 72 | $ary[3] = $n; |
| 73 | } else { |
| 74 | $ary[0] = _("ERROR: Help files are not in the right format!"); |
| 75 | $ary[1] = $ary[0]; |
| 76 | $ary[2] = $ary[0]; |
| 77 | } |
| 78 | return( $ary ); |
| 79 | } else if (!trim(strtolower($doc[$n]))) { |
| 80 | $ary[0] = ''; |
| 81 | $ary[1] = ''; |
| 82 | $ary[2] = ''; |
| 83 | $ary[3] = $n; |
| 84 | } |
| 85 | } |
| 86 | $ary[0] = _("ERROR: Help files are not in the right format!"); |
| 87 | $ary[1] = $ary[0]; |
| 88 | $ary[2] = $ary[0]; |
| 89 | $ary[3] = $n; |
| 90 | return( $ary ); |
| 91 | } |
| 92 | |
| 93 | /**************[ END HELP FUNCTIONS ]******************/ |
| 94 | |
| 95 | echo html_tag( 'table', |
| 96 | html_tag( 'tr', |
| 97 | html_tag( 'td','<div style="text-align: center;"><b>' . _("Help") .'</b></div>', 'center', $color[0] ) |
| 98 | ) , |
| 99 | 'center', '', 'width="95%" cellpadding="1" cellspacing="2" border="0"' ); |
| 100 | |
| 101 | do_hook('help_top'); |
| 102 | |
| 103 | echo html_tag( 'table', '', 'center', '', 'width="90%" cellpadding="0" cellspacing="10" border="0"' ) . |
| 104 | html_tag( 'tr' ) . |
| 105 | html_tag( 'td' ); |
| 106 | |
| 107 | if (!isset($squirrelmail_language)) { |
| 108 | $squirrelmail_language = 'en_US'; |
| 109 | } |
| 110 | |
| 111 | if (file_exists("../help/$squirrelmail_language")) { |
| 112 | $user_language = $squirrelmail_language; |
| 113 | } else if (file_exists('../help/en_US')) { |
| 114 | error_box(_("Help is not available in the selected language. It will be displayed in English instead.")); |
| 115 | echo '<br />'; |
| 116 | $user_language = 'en_US'; |
| 117 | } else { |
| 118 | error_box( _("Help is not available. Please contact your system administrator for assistance.")); |
| 119 | echo '</td></tr></table>'; |
| 120 | // Display footer (closes HTML tags) and stop script execution. |
| 121 | $oTemplate->display('footer.tpl'); |
| 122 | exit; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | /* take the chapternumber from the GET-vars, |
| 127 | * else see if we can get a relevant chapter from the referer */ |
| 128 | $chapter = 0; |
| 129 | |
| 130 | if ( sqgetGlobalVar('chapter', $temp, SQ_GET) ) { |
| 131 | $chapter = (int) $temp; |
| 132 | } elseif ( sqgetGlobalVar('HTTP_REFERER', $temp, SQ_SERVER) ) { |
| 133 | $ref = strtolower($temp); |
| 134 | |
| 135 | $contexts = array ( 'src/compose' => 4, 'src/addr' => 5, |
| 136 | 'src/folders' => 6, 'src/options' => 7, 'src/right_main' => 2, |
| 137 | 'src/read_body' => 3, 'src/search' => 8 ); |
| 138 | |
| 139 | foreach($contexts as $path => $chap) { |
| 140 | if(strpos($ref, $path)) { |
| 141 | $chapter = $chap; |
| 142 | break; |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if ( $chapter == 0 || !isset( $helpdir[$chapter-1] ) ) { |
| 148 | // Initialise the needed variables. |
| 149 | $toc = array(); |
| 150 | |
| 151 | // Get the chapter numbers, title and decriptions. |
| 152 | for ($i=0, $cnt = count($helpdir); $i < $cnt; $i++) { |
| 153 | if (file_exists("../help/$user_language/$helpdir[$i]")) { |
| 154 | // First try the selected language. |
| 155 | $doc = file("../help/$user_language/$helpdir[$i]"); |
| 156 | $help_info = get_info($doc, 0); |
| 157 | $toc[] = array($i+1, $help_info[0], $help_info[2]); |
| 158 | } elseif (file_exists("../help/en_US/$helpdir[$i]")) { |
| 159 | // If the selected language can't be found, try English. |
| 160 | $doc = file("../help/en_US/$helpdir[$i]"); |
| 161 | $help_info = get_info($doc, 0); |
| 162 | $toc[] = array($i+1, $help_info[0], |
| 163 | _("This chapter is not available in the selected language. It will be displayed in English instead.") . |
| 164 | '<br />' . $help_info[2]); |
| 165 | } else { |
| 166 | // If English can't be found, the chapter went MIA. |
| 167 | $toc[] = array($i+1, _("This chapter is missing"), |
| 168 | sprintf(_("For some reason, chapter %s is not available."), $i+1)); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | // Write the TOC header |
| 173 | echo html_tag( 'table', '', 'center', '', 'cellpadding="0" cellspacing="0" border="0"' ) . |
| 174 | html_tag( 'tr' ) . |
| 175 | html_tag( 'td' ) . |
| 176 | '<div style="text-align: center;"><b>' . _("Table of Contents") . '</b></div><br />'; |
| 177 | echo html_tag( 'ol' ); |
| 178 | |
| 179 | // Write the TOC chapters. |
| 180 | // FIXME: HTML code is not compliant. |
| 181 | for ($i=0, $cnt = count($toc); $i < $cnt; $i++) { |
| 182 | echo '<li><a href="../src/help.php?chapter=' . $toc[$i][0]. '">' . |
| 183 | $toc[$i][1] . '</a>' . html_tag( 'ul', $toc[$i][2] ); |
| 184 | } |
| 185 | |
| 186 | // Provide hook for external help scripts. |
| 187 | do_hook('help_chapter'); |
| 188 | |
| 189 | // Write the TOC footer. |
| 190 | echo '</ol></td></tr></table>'; |
| 191 | } else { |
| 192 | // Initialise the needed variables. |
| 193 | $display_chapter = TRUE; |
| 194 | |
| 195 | // Get the chapter. |
| 196 | if (file_exists("../help/$user_language/" . $helpdir[$chapter-1])) { |
| 197 | // First try the selected language. |
| 198 | $doc = file("../help/$user_language/" . $helpdir[$chapter-1]); |
| 199 | } elseif (file_exists("../help/en_US/" . $helpdir[$chapter-1])) { |
| 200 | // If the selected language can't be found, try English. |
| 201 | $doc = file("../help/en_US/" . $helpdir[$chapter-1]); |
| 202 | error_box(_("This chapter is not available in the selected language. It will be displayed in English instead.")); |
| 203 | echo '<br />'; |
| 204 | } else { |
| 205 | // If English can't be found, the chapter went MIA. |
| 206 | $display_chapter = FALSE; |
| 207 | } |
| 208 | |
| 209 | // Write the chpater header. |
| 210 | echo '<div style="text-align: center;"><small>'; |
| 211 | if ($chapter <= 1){ |
| 212 | echo '<font color="' . $color[9] . '">' . _("Previous") |
| 213 | . '</font> | '; |
| 214 | } else { |
| 215 | echo '<a href="../src/help.php?chapter=' . ($chapter-1) |
| 216 | . '">' . _("Previous") . '</a> | '; |
| 217 | } |
| 218 | echo '<a href="../src/help.php">' . _("Table of Contents") . '</a>'; |
| 219 | if ($chapter >= count($helpdir)){ |
| 220 | echo ' | <font color="' . $color[9] . '">' . _("Next") . '</font>'; |
| 221 | } else { |
| 222 | echo ' | <a href="../src/help.php?chapter=' . ($chapter+1) |
| 223 | . '">' . _("Next") . '</a>'; |
| 224 | } |
| 225 | echo '</small></div><br />'; |
| 226 | |
| 227 | // Write the chapter. |
| 228 | if ($display_chapter) { |
| 229 | // If there is a valid chapter, display it. |
| 230 | $help_info = get_info($doc, 0); |
| 231 | echo '<font size="5"><b>' . $chapter . ' - ' . $help_info[0] |
| 232 | . '</b></font><br /><br />'; |
| 233 | |
| 234 | if (isset($help_info[1]) && $help_info[1]) { |
| 235 | echo $help_info[1]; |
| 236 | } else { |
| 237 | echo html_tag( 'p', $help_info[2], 'left' ); |
| 238 | } |
| 239 | |
| 240 | $section = 0; |
| 241 | for ($n = $help_info[3], $cnt = count($doc); $n < $cnt; $n++) { |
| 242 | $section++; |
| 243 | $help_info = get_info($doc, $n); |
| 244 | echo "<b>$chapter.$section - $help_info[0]</b>" . |
| 245 | $help_info[1]; |
| 246 | $n = $help_info[3]; |
| 247 | } |
| 248 | |
| 249 | echo '<br /><div style="text-align: center;"><a href="#pagetop">' . _("Top") . '</a></div>'; |
| 250 | } else { |
| 251 | // If the help file went MIA, display an error message. |
| 252 | error_box(sprintf(_("For some reason, chapter %s is not available."), $chapter)); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | do_hook('help_bottom'); |
| 257 | |
| 258 | echo html_tag( 'tr', |
| 259 | html_tag( 'td', ' ', 'left', $color[0] ) |
| 260 | ); |
| 261 | |
| 262 | ?> |
| 263 | </table> |
| 264 | <?php |
| 265 | $oTemplate->display('footer.tpl'); |
| 266 | ?> |