822a1063 |
1 | <?php |
2 | |
3 | /** |
4 | * help.php - Displays help page. |
5 | * |
6 | * Prints a very simple page and includes |
7 | * page content or a string from elsewhere. |
68396ed9 |
8 | * Usually this will appear in a popup |
822a1063 |
9 | * See {@link helpbutton()} in {@link lib/moodlelib.php} |
10 | * |
11 | * @author Martin Dougiamas |
12 | * @version $Id$ |
13 | * @package moodlecore |
14 | */ |
68396ed9 |
15 | |
822a1063 |
16 | |
17 | require_once('config.php'); |
18 | |
496d0644 |
19 | $file = optional_param('file', '', PARAM_PATH); |
fc64d5cf |
20 | $text = optional_param('text', 'No text to display', PARAM_CLEAN); |
b1c9e099 |
21 | $module = optional_param('module', 'moodle', PARAM_ALPHAEXT); |
c0518193 |
22 | $forcelang = optional_param('forcelang', '', PARAM_ALPHAEXT); |
65cf9fc3 |
23 | |
aa635c47 |
24 | print_header(); |
5c0ee23c |
25 | |
822a1063 |
26 | print_simple_box_start('center', '96%'); |
d6f73f53 |
27 | |
aa635c47 |
28 | $helpfound = false; |
c0518193 |
29 | if (empty($forcelang)) { |
30 | $langs = array(current_language(), get_string('parentlanguage'), 'en_utf8'); // Fallback |
31 | } else { |
32 | $langs = array($forcelang); |
33 | } |
aa635c47 |
34 | if (!empty($file)) { |
aa635c47 |
35 | foreach ($langs as $lang) { |
36 | if (empty($lang)) { |
37 | continue; |
38 | } |
822a1063 |
39 | if ($module == 'moodle') { |
9214c224 |
40 | if ($lang == 'en_utf8') { |
41 | $filepath = $CFG->dirroot .'/lang/'. $lang .'/help/'. $file; |
42 | } else { |
43 | $filepath = $CFG->dataroot .'/lang/'. $lang .'/help/'. $file; |
44 | } |
70442fe3 |
45 | } else { |
9214c224 |
46 | if ($lang == 'en_utf8') { |
47 | $filepath = $CFG->dirroot .'/lang/'. $lang .'/help/'. $module .'/'. $file; |
48 | } else { |
49 | $filepath = $CFG->dataroot .'/lang/'. $lang .'/help/'. $module .'/'. $file; |
f3447313 |
50 | if (!file_exists($filepath)) { |
51 | $filepath = $CFG->dirroot .'/lang/en_utf8/help/'. $module .'/'. $file; |
52 | } |
9214c224 |
53 | } |
68396ed9 |
54 | if (!file_exists($filepath)) { |
f3447313 |
55 | $filepath = $CFG->dirroot.'/mod/'.$module.'/lang/'. $lang .'/help/'. $module .'/'. $file; |
68396ed9 |
56 | } |
70442fe3 |
57 | } |
68396ed9 |
58 | |
508d4a0d |
59 | if (file_exists($filepath) and is_file($filepath) and is_readable($filepath)) { |
aa635c47 |
60 | $helpfound = true; |
508d4a0d |
61 | @include($filepath); // The actual helpfile |
1517c0aa |
62 | |
822a1063 |
63 | if ($module == 'moodle' and ($file == 'index.html' or $file == 'mods.html')) { |
1517c0aa |
64 | // include file for each module |
65 | |
822a1063 |
66 | if (!$modules = get_records('modules', 'visible', 1)) { |
67 | error('No modules found!!'); // Should never happen |
1517c0aa |
68 | } |
69 | |
70 | foreach ($modules as $mod) { |
822a1063 |
71 | $strmodulename = get_string('modulename', $mod->name); |
1517c0aa |
72 | $modulebyname[$strmodulename] = $mod; |
73 | } |
74 | ksort($modulebyname); |
75 | |
76 | foreach ($modulebyname as $mod) { |
77 | foreach ($langs as $lang) { |
78 | if (empty($lang)) { |
79 | continue; |
80 | } |
9214c224 |
81 | if ($lang == 'en_utf8') { |
82 | $filepath = $CFG->dirroot .'/lang/'. $lang .'/help/'. $mod->name .'/'. $file; |
83 | } else { |
84 | $filepath = $CFG->dataroot .'/lang/'. $lang .'/help/'. $mod->name .'/'. $file; |
85 | } |
1517c0aa |
86 | |
822a1063 |
87 | if (file_exists($filepath)) { |
6da4b261 |
88 | echo '<hr size="1" />'; |
822a1063 |
89 | include($filepath); // The actual helpfile |
6da4b261 |
90 | break; |
91 | } |
92 | } |
93 | } |
94 | } |
95 | |
1c2999bc |
96 | // Some horrible hardcoded stuff follows, should be delegated to modules to handle |
97 | |
822a1063 |
98 | if ($module == 'moodle' and ($file == 'resource/types.html')) { // RESOURCES |
99 | require_once($CFG->dirroot .'/mod/resource/lib.php'); |
6da4b261 |
100 | $typelist = resource_get_resource_types(); |
101 | $typelist['label'] = get_string('resourcetypelabel', 'resource'); |
102 | |
103 | foreach ($typelist as $type => $name) { |
104 | foreach ($langs as $lang) { |
105 | if (empty($lang)) { |
106 | continue; |
107 | } |
9214c224 |
108 | if ($lang == 'en_utf8') { |
109 | $filepath = $CFG->dirroot .'/lang/'. $lang .'/help/resource/type/'. $type .'.html'; |
110 | } else { |
111 | $filepath = $CFG->dataroot .'/lang/'. $lang .'/help/resource/type/'. $type .'.html'; |
112 | } |
822a1063 |
113 | if (file_exists($filepath)) { |
6da4b261 |
114 | echo '<hr size="1" />'; |
822a1063 |
115 | include($filepath); // The actual helpfile |
1517c0aa |
116 | break; |
117 | } |
118 | } |
119 | } |
120 | } |
1c2999bc |
121 | if ($module == 'moodle' and ($file == 'assignment/types.html')) { // ASSIGNMENTS |
122 | require_once($CFG->dirroot .'/mod/assignment/lib.php'); |
123 | $typelist = assignment_types(); |
124 | |
125 | foreach ($typelist as $type => $name) { |
126 | echo '<p><b>'.$name.'</b></p>'; |
127 | echo get_string('help'.$type, 'assignment'); |
128 | echo '<hr size="1" />'; |
129 | } |
130 | } |
aa635c47 |
131 | break; |
70442fe3 |
132 | } |
65cf9fc3 |
133 | } |
134 | } else { |
fc64d5cf |
135 | echo '<p>'.s($text).'</p>'; // This param was already cleaned |
aa635c47 |
136 | $helpfound = true; |
137 | } |
138 | |
d6f73f53 |
139 | print_simple_box_end(); |
140 | |
aa635c47 |
141 | if (!$helpfound) { |
6db49806 |
142 | //$file = clean_text($file); // Keep it clean! |
822a1063 |
143 | notify('Help file "'. $file .'" could not be found!'); |
65cf9fc3 |
144 | } |
e5dfd0f3 |
145 | |
146 | close_window_button(); |
95b50076 |
147 | |
6bc21ecf |
148 | echo '<p align="center"><a href="help.php?file=index.html">'. get_string('helpindex') .'</a></p>'; |
8634bc27 |
149 | |
150 | $CFG->docroot = ''; // We don't want a doc link here |
151 | |
6bc21ecf |
152 | print_footer('none'); |
ed5ab9f7 |
153 | ?> |