FIxed some bugs
[moodle.git] / help.php
blob3d5b8dbb300b6a47cd3d71f231a44d01d4080b75
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 $file = optional_param('file', '', PARAM_CLEAN);
20 $text = optional_param('text', 'No text to display', PARAM_CLEAN);
21 $module = optional_param('module', 'moodle', PARAM_ALPHAEXT);
22 $forcelang = optional_param('forcelang', '', PARAM_ALPHAEXT);
24 print_header();
26 if (detect_munged_arguments($module .'/'. $file)) {
27 error('Filenames contain illegal characters!');
30 print_simple_box_start('center', '96%');
32 $helpfound = false;
33 if (empty($forcelang)) {
34 $langs = array(current_language(), get_string('parentlanguage'), 'en_utf8'); // Fallback
35 } else {
36 $langs = array($forcelang);
38 if (!empty($file)) {
39 foreach ($langs as $lang) {
40 if (empty($lang)) {
41 continue;
43 if ($module == 'moodle') {
44 if ($lang == 'en_utf8') {
45 $filepath = $CFG->dirroot .'/lang/'. $lang .'/help/'. $file;
46 } else {
47 $filepath = $CFG->dataroot .'/lang/'. $lang .'/help/'. $file;
49 } else {
50 if ($lang == 'en_utf8') {
51 $filepath = $CFG->dirroot .'/lang/'. $lang .'/help/'. $module .'/'. $file;
52 } else {
53 $filepath = $CFG->dataroot .'/lang/'. $lang .'/help/'. $module .'/'. $file;
54 if (!file_exists($filepath)) {
55 $filepath = $CFG->dirroot .'/lang/en_utf8/help/'. $module .'/'. $file;
58 if (!file_exists($filepath)) {
59 $filepath = $CFG->dirroot.'/mod/'.$module.'/lang/'. $lang .'/help/'. $module .'/'. $file;
63 if (file_exists($filepath)) {
64 $helpfound = true;
65 include($filepath); // The actual helpfile
67 if ($module == 'moodle' and ($file == 'index.html' or $file == 'mods.html')) {
68 // include file for each module
70 if (!$modules = get_records('modules', 'visible', 1)) {
71 error('No modules found!!'); // Should never happen
74 foreach ($modules as $mod) {
75 $strmodulename = get_string('modulename', $mod->name);
76 $modulebyname[$strmodulename] = $mod;
78 ksort($modulebyname);
80 foreach ($modulebyname as $mod) {
81 foreach ($langs as $lang) {
82 if (empty($lang)) {
83 continue;
85 if ($lang == 'en_utf8') {
86 $filepath = $CFG->dirroot .'/lang/'. $lang .'/help/'. $mod->name .'/'. $file;
87 } else {
88 $filepath = $CFG->dataroot .'/lang/'. $lang .'/help/'. $mod->name .'/'. $file;
91 if (file_exists($filepath)) {
92 echo '<hr size="1" />';
93 include($filepath); // The actual helpfile
94 break;
100 // Some horrible hardcoded stuff follows, should be delegated to modules to handle
102 if ($module == 'moodle' and ($file == 'resource/types.html')) { // RESOURCES
103 require_once($CFG->dirroot .'/mod/resource/lib.php');
104 $typelist = resource_get_resource_types();
105 $typelist['label'] = get_string('resourcetypelabel', 'resource');
107 foreach ($typelist as $type => $name) {
108 foreach ($langs as $lang) {
109 if (empty($lang)) {
110 continue;
112 if ($lang == 'en_utf8') {
113 $filepath = $CFG->dirroot .'/lang/'. $lang .'/help/resource/type/'. $type .'.html';
114 } else {
115 $filepath = $CFG->dataroot .'/lang/'. $lang .'/help/resource/type/'. $type .'.html';
117 if (file_exists($filepath)) {
118 echo '<hr size="1" />';
119 include($filepath); // The actual helpfile
120 break;
125 if ($module == 'moodle' and ($file == 'assignment/types.html')) { // ASSIGNMENTS
126 require_once($CFG->dirroot .'/mod/assignment/lib.php');
127 $typelist = assignment_types();
129 foreach ($typelist as $type => $name) {
130 echo '<p><b>'.$name.'</b></p>';
131 echo get_string('help'.$type, 'assignment');
132 echo '<hr size="1" />';
135 break;
138 } else {
139 echo '<p>'.s($text).'</p>'; // This param was already cleaned
140 $helpfound = true;
143 print_simple_box_end();
145 if (!$helpfound) {
146 //$file = clean_text($file); // Keep it clean!
147 notify('Help file "'. $file .'" could not be found!');
150 close_window_button();
152 echo '<p align="center"><a href="help.php?file=index.html">'. get_string('helpindex') .'</a></p>';
154 $CFG->docroot = ''; // We don't want a doc link here
156 print_footer('none');