Updated from stable
[moodle.git] / help.php
blob1701b5c03d9d0119e26a8a52cd9101c1a93f5bb4
1 <?php
3 /**
4 * help.php - Displays help page.
6 * Prints a very simple page and includes
7 * page content or a string from elsewhere.
8 * Usually this will appear in a popup
9 * See {@link helpbutton()} in {@link lib/moodlelib.php}
11 * @author Martin Dougiamas
12 * @version $Id$
13 * @package moodlecore
17 require_once('config.php');
19 optional_variable($file, '');
20 optional_variable($text, 'No text to display');
21 optional_variable($module, 'moodle');
23 print_header();
25 if (detect_munged_arguments($module .'/'. $file)) {
26 error('Filenames contain illegal characters!');
29 print_simple_box_start('center', '96%');
31 $helpfound = false;
32 $langs = array(current_language(), get_string('parentlanguage'), 'en'); // Fallback
34 if (!empty($file)) {
35 foreach ($langs as $lang) {
36 if (empty($lang)) {
37 continue;
39 if ($module == 'moodle') {
40 $filepath = $CFG->dirroot .'/lang/'. $lang .'/help/'. $file;
41 } else {
42 $filepath = $CFG->dirroot .'/lang/'. $lang .'/help/'. $module .'/'. $file;
43 if (!file_exists($filepath)) {
44 $filepath = $CFG->dirroot.'/mod/'.$module.'/lang/'. $lang .'/help/'. $module .'/'. $file;
48 if (file_exists($filepath)) {
49 $helpfound = true;
50 include($filepath); // The actual helpfile
52 if ($module == 'moodle' and ($file == 'index.html' or $file == 'mods.html')) {
53 // include file for each module
55 if (!$modules = get_records('modules', 'visible', 1)) {
56 error('No modules found!!'); // Should never happen
59 foreach ($modules as $mod) {
60 $strmodulename = get_string('modulename', $mod->name);
61 $modulebyname[$strmodulename] = $mod;
63 ksort($modulebyname);
65 foreach ($modulebyname as $mod) {
66 foreach ($langs as $lang) {
67 if (empty($lang)) {
68 continue;
70 $filepath = $CFG->dirroot .'/lang/'. $lang .'/help/'. $mod->name .'/'. $file;
72 if (file_exists($filepath)) {
73 echo '<hr size="1" />';
74 include($filepath); // The actual helpfile
75 break;
81 // Some horrible hardcoded stuff follows, should be delegated to modules to handle
83 if ($module == 'moodle' and ($file == 'resource/types.html')) { // RESOURCES
84 require_once($CFG->dirroot .'/mod/resource/lib.php');
85 $typelist = resource_get_resource_types();
86 $typelist['label'] = get_string('resourcetypelabel', 'resource');
88 foreach ($typelist as $type => $name) {
89 foreach ($langs as $lang) {
90 if (empty($lang)) {
91 continue;
93 $filepath = $CFG->dirroot .'/lang/'. $lang .'/help/resource/type/'. $type .'.html';
94 if (file_exists($filepath)) {
95 echo '<hr size="1" />';
96 include($filepath); // The actual helpfile
97 break;
102 if ($module == 'moodle' and ($file == 'assignment/types.html')) { // ASSIGNMENTS
103 require_once($CFG->dirroot .'/mod/assignment/lib.php');
104 $typelist = assignment_types();
106 foreach ($typelist as $type => $name) {
107 echo '<p><b>'.$name.'</b></p>';
108 echo get_string('help'.$type, 'assignment');
109 echo '<hr size="1" />';
112 break;
115 } else {
116 echo '<p>';
117 echo clean_text($text);
118 echo '</p>';
119 $helpfound = true;
122 print_simple_box_end();
124 if (!$helpfound) {
125 $file = clean_text($file); // Keep it clean!
126 notify('Help file "'. $file .'" could not be found!');
129 close_window_button();
131 echo '<p align="center"><a href="help.php?file=index.html">'. get_string('helpindex') .'</a></p>';
132 print_footer('none');