3 * help.php - Displays help page.
5 * Prints a very simple page and includes
6 * page content or a string from elsewhere.
7 * Usually this will appear in a popup
8 * See {@link helpbutton()} in {@link lib/moodlelib.php}
10 * @author Martin Dougiamas
14 require_once('config.php');
16 // Get URL parameters.
17 $file = optional_param('file', '', PARAM_PATH
);
18 $text = optional_param('text', 'No text to display', PARAM_CLEAN
);
19 $module = optional_param('module', 'moodle', PARAM_ALPHAEXT
);
20 $forcelang = optional_param('forcelang', '', PARAM_SAFEDIR
);
24 print_simple_box_start('center', '96%');
26 // We look for the help to display in lots of different places, and
27 // only display an error at the end if we can't find the help file
28 // anywhere. This variable tracks that.
32 // The help to display is from a help file.
34 // Get the list of parent languages.
35 if (empty($forcelang)) {
36 $langs = array(current_language(), get_string('parentlanguage'), 'en_utf8'); // Fallback
38 $langs = array($forcelang);
41 // Work through the possible languages, starting with the most specific.
42 foreach ($langs as $lang) {
47 // Work out which directory the help files live in.
48 if ($lang == 'en_utf8') {
49 $helpdir = $CFG->dirroot
;
51 $helpdir = $CFG->dataroot
;
53 $helpdir .= "/lang/$lang/help";
55 // Then which file in there we should be serving.
56 if ($module == 'moodle') {
57 $filepath = "$helpdir/$file";
59 $filepath = "$helpdir/$module/$file";
61 // If that does not exist, try a fallback into the module code folder.
62 if (!file_exists($filepath)) {
63 $filepath = "$CFG->dirroot/mod/$module/lang/$lang/help/$module/$file";
67 // Now, try to include the help text from this file, if we can.
68 if (file_exists_and_readable($filepath)) {
70 @include
($filepath); // The actual helpfile
72 // Now, we process some special cases.
73 if ($module == 'moodle' and ($file == 'index.html' or $file == 'mods.html')) {
74 include_help_for_each_module($file, $langs, $helpdir);
77 // The remaining horrible hardcoded special cases should be delegated to modules somehow.
78 if ($module == 'moodle' and ($file == 'resource/types.html')) { // RESOURCES
79 include_help_for_each_resource($file, $langs, $helpdir);
81 if ($module == 'moodle' and ($file == 'assignment/types.html')) { // ASSIGNMENTS
82 include_help_for_each_assignment_type();
85 // Having found some help, we break out of the loop over languages.
90 // The help to display was given as an argument to this function.
91 echo '<p>'.s($text).'</p>'; // This param was already cleaned
95 print_simple_box_end();
97 // Display an error if necessary.
99 notify('Help file "'. $file .'" could not be found!');
103 close_window_button();
104 echo '<p align="center"><a href="help.php?file=index.html">'. get_string('helpindex') .'</a></p>';
106 $CFG->docroot
= ''; // We don't want a doc link here
107 print_footer('none');
109 // Utility function =================================================================
111 function file_exists_and_readable($filepath) {
112 return file_exists($filepath) and is_file($filepath) and is_readable($filepath);
115 // Some functions for handling special cases ========================================
117 function include_help_for_each_module($file, $langs, $helpdir) {
120 if (!$modules = get_records('modules', 'visible', 1)) {
121 error('No modules found!!'); // Should never happen
124 foreach ($modules as $mod) {
125 $strmodulename = get_string('modulename', $mod->name
);
126 $modulebyname[$strmodulename] = $mod;
128 ksort($modulebyname);
130 foreach ($modulebyname as $mod) {
131 foreach ($langs as $lang) {
136 $filepath = "$helpdir/$mod->name/$file";
138 // If that does not exist, try a fallback into the module code folder.
139 if (!file_exists($filepath)) {
140 $filepath = "$CFG->dirroot/mod/$mod->name/lang/$lang/help/$mod->name/$file";
143 if (file_exists_and_readable($filepath)) {
144 echo '<hr size="1" />';
145 @include
($filepath); // The actual helpfile
146 break; // Out of loop over languages.
152 function include_help_for_each_resource($file, $langs, $helpdir) {
155 require_once($CFG->dirroot
.'/mod/resource/lib.php');
156 $typelist = resource_get_resource_types();
157 $typelist['label'] = get_string('resourcetypelabel', 'resource');
159 foreach ($typelist as $type => $name) {
160 foreach ($langs as $lang) {
165 $filepath = "$helpdir/resource/type/$type.html";
167 if (file_exists_and_readable($filepath)) {
168 echo '<hr size="1" />';
169 @include
($filepath); // The actual helpfile
170 break; // Out of loop over languages.
176 function include_help_for_each_assignment_type() {
179 require_once($CFG->dirroot
.'/mod/assignment/lib.php');
180 $typelist = assignment_types();
182 foreach ($typelist as $type => $name) {
183 echo '<p><b>'.$name.'</b></p>';
184 echo get_string('help'.$type, 'assignment');
185 echo '<hr size="1" />';