help.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /**
  3. * help.php
  4. *
  5. * Displays help for the user
  6. *
  7. * @copyright &copy; 1999-2007 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id$
  10. * @package squirrelmail
  11. */
  12. /** This is the help page */
  13. define('PAGE_NAME', 'help');
  14. /**
  15. * Include the SquirrelMail initialization file.
  16. */
  17. require('../include/init.php');
  18. displayPageHeader($color);
  19. $helpdir[0] = 'basic.hlp';
  20. $helpdir[1] = 'main_folder.hlp';
  21. $helpdir[2] = 'read_mail.hlp';
  22. $helpdir[3] = 'compose.hlp';
  23. $helpdir[4] = 'addresses.hlp';
  24. $helpdir[5] = 'folders.hlp';
  25. $helpdir[6] = 'options.hlp';
  26. $helpdir[7] = 'search.hlp';
  27. $helpdir[8] = 'FAQ.hlp';
  28. /****************[ HELP FUNCTIONS ]********************/
  29. /**
  30. * parses through and gets the information from the different documents.
  31. * this returns one section at a time. You must keep track of the position
  32. * so that it knows where to start to look for the next section.
  33. */
  34. function get_info($doc, $pos) {
  35. $ary = array(0,0,0);
  36. $cntdoc = count($doc);
  37. for ($n=$pos; $n < $cntdoc; $n++) {
  38. if (trim(strtolower($doc[$n])) == '<chapter>'
  39. || trim(strtolower($doc[$n])) == '<section>') {
  40. for ($n++; $n < $cntdoc
  41. && (trim(strtolower($doc[$n])) != '</section>')
  42. && (trim(strtolower($doc[$n])) != '</chapter>'); $n++) {
  43. if (trim(strtolower($doc[$n])) == '<title>') {
  44. $n++;
  45. $ary[0] = trim($doc[$n]);
  46. }
  47. if (trim(strtolower($doc[$n])) == '<description>') {
  48. $ary[1] = '';
  49. for ($n++;$n < $cntdoc
  50. && (trim(strtolower($doc[$n])) != '</description>');
  51. $n++) {
  52. $ary[1] .= $doc[$n];
  53. }
  54. }
  55. if (trim(strtolower($doc[$n])) == '<summary>') {
  56. $ary[2] = '';
  57. for ($n++; $n < $cntdoc
  58. && (trim(strtolower($doc[$n])) != '</summary>');
  59. $n++) {
  60. $ary[2] .= $doc[$n];
  61. }
  62. }
  63. }
  64. if (isset($ary)) {
  65. $ary[3] = $n;
  66. } else {
  67. $ary[0] = _("ERROR: Help files are not in the right format!");
  68. $ary[1] = $ary[0];
  69. $ary[2] = $ary[0];
  70. }
  71. return( $ary );
  72. } else if (!trim(strtolower($doc[$n]))) {
  73. $ary[0] = '';
  74. $ary[1] = '';
  75. $ary[2] = '';
  76. $ary[3] = $n;
  77. }
  78. }
  79. $ary[0] = _("ERROR: Help files are not in the right format!");
  80. $ary[1] = $ary[0];
  81. $ary[2] = $ary[0];
  82. $ary[3] = $n;
  83. return( $ary );
  84. }
  85. /**************[ END HELP FUNCTIONS ]******************/
  86. do_hook('help_top', $null);
  87. if (!isset($squirrelmail_language)) {
  88. $squirrelmail_language = 'en_US';
  89. }
  90. if (file_exists("../help/$squirrelmail_language")) {
  91. $user_language = $squirrelmail_language;
  92. } else if (file_exists('../help/en_US')) {
  93. error_box(_("Help is not available in the selected language. It will be displayed in English instead."));
  94. echo '<br />';
  95. $user_language = 'en_US';
  96. } else {
  97. error_box( _("Help is not available. Please contact your system administrator for assistance."));
  98. echo '</td></tr></table>';
  99. // Display footer (closes HTML tags) and stop script execution.
  100. $oTemplate->display('footer.tpl');
  101. exit;
  102. }
  103. /* take the chapternumber from the GET-vars,
  104. * else see if we can get a relevant chapter from the referer */
  105. $chapter = 0;
  106. if ( sqgetGlobalVar('chapter', $temp, SQ_GET) ) {
  107. $chapter = (int) $temp;
  108. } elseif ( sqgetGlobalVar('HTTP_REFERER', $temp, SQ_SERVER) ) {
  109. $ref = strtolower($temp);
  110. $contexts = array ( 'src/compose' => 4, 'src/addr' => 5,
  111. 'src/folders' => 6, 'src/options' => 7, 'src/right_main' => 2,
  112. 'src/read_body' => 3, 'src/search' => 8 );
  113. foreach($contexts as $path => $chap) {
  114. if(strpos($ref, $path)) {
  115. $chapter = $chap;
  116. break;
  117. }
  118. }
  119. }
  120. if ( $chapter == 0 || !isset( $helpdir[$chapter-1] ) ) {
  121. // Initialise the needed variables.
  122. $toc = array();
  123. // Get the chapter numbers, title and decriptions.
  124. for ($i=0, $cnt = count($helpdir); $i < $cnt; $i++) {
  125. if (file_exists("../help/$user_language/$helpdir[$i]")) {
  126. // First try the selected language.
  127. $doc = file("../help/$user_language/$helpdir[$i]");
  128. $help_info = get_info($doc, 0);
  129. $toc[] = array($i+1, $help_info[0], $help_info[2]);
  130. } elseif (file_exists("../help/en_US/$helpdir[$i]")) {
  131. // If the selected language can't be found, try English.
  132. $doc = file("../help/en_US/$helpdir[$i]");
  133. $help_info = get_info($doc, 0);
  134. $toc[] = array($i+1, $help_info[0],
  135. _("This chapter is not available in the selected language. It will be displayed in English instead.") .
  136. '<br />' . $help_info[2]);
  137. } else {
  138. // If English can't be found, the chapter went MIA.
  139. $toc[] = array($i+1, _("This chapter is missing"),
  140. sprintf(_("For some reason, chapter %s is not available."), $i+1));
  141. }
  142. }
  143. // Provide hook for external help scripts.
  144. do_hook('help_chapter', $null);
  145. $new_toc = array();
  146. foreach ($toc as $ch) {
  147. $a = array();
  148. $a['Chapter'] = $ch[0];
  149. $a['Title'] = $ch[1];
  150. $a['Summary'] = trim($ch[2]);
  151. $new_toc[] = $a;
  152. }
  153. $oTemplate->assign('toc', $new_toc);
  154. $oTemplate->display('help_toc.tpl');
  155. } else {
  156. // Initialise the needed variables.
  157. $display_chapter = TRUE;
  158. // Get the chapter.
  159. if (file_exists("../help/$user_language/" . $helpdir[$chapter-1])) {
  160. // First try the selected language.
  161. $doc = file("../help/$user_language/" . $helpdir[$chapter-1]);
  162. } elseif (file_exists("../help/en_US/" . $helpdir[$chapter-1])) {
  163. // If the selected language can't be found, try English.
  164. $doc = file("../help/en_US/" . $helpdir[$chapter-1]);
  165. error_box(_("This chapter is not available in the selected language. It will be displayed in English instead."));
  166. echo '<br />';
  167. } else {
  168. // If English can't be found, the chapter went MIA.
  169. $display_chapter = FALSE;
  170. }
  171. // Write the chapter.
  172. if ($display_chapter) {
  173. // If there is a valid chapter, display it.
  174. $help_info = get_info($doc, 0);
  175. $ch = array();
  176. $ch['Chapter'] = $chapter;
  177. $ch['Title'] = $help_info[0];
  178. $ch['Summary'] = isset($help_info[1]) && $help_info[1] ? trim($help_info[1]) : $help_info[2];
  179. $ch['Sections'] = array();
  180. $section = 0;
  181. for ($n = $help_info[3], $cnt = count($doc); $n < $cnt; $n++) {
  182. $section++;
  183. $help_info = get_info($doc, $n);
  184. $n = $help_info[3];
  185. $a = array();
  186. $a['SectionNumber'] = $section;
  187. $a['SectionTitle'] = $help_info[0];
  188. $a['SectionText'] = isset($help_info[1]) ? trim($help_info[1]) : '';;
  189. $ch['Sections'][] = $a;
  190. }
  191. $oTemplate->assign('chapter_number', $chapter);
  192. $oTemplate->assign('chapter_count', count($helpdir));
  193. $oTemplate->assign('chapter_title', $ch['Title']);
  194. $oTemplate->assign('chapter_summary', $ch['Summary']);
  195. $oTemplate->assign('sections', $ch['Sections']);
  196. $oTemplate->assign('error_msg', NULL);
  197. } else {
  198. // If the help file went MIA, trigger an error message.
  199. $oTemplate->assign('chapter_number', $chapter);
  200. $oTemplate->assign('chapter_count', count($helpdir));
  201. $oTemplate->assign('chapter_title', '');
  202. $oTemplate->assign('chapter_summary', '');
  203. $oTemplate->assign('sections', array());
  204. $oTemplate->assign('error_msg', sprintf(_("For some reason, chapter %s is not available."), $chapter));
  205. }
  206. $oTemplate->display('help_chapter.tpl');
  207. }
  208. do_hook('help_bottom', $null);
  209. $oTemplate->display('footer.tpl');