Polished.
[moodle.git] / lib / weblib.php
CommitLineData
dcb1bd3c 1<?php // $Id$
f9903ed0 2
9fa49e22 3///////////////////////////////////////////////////////////////////////////
4// weblib.php - functions for web output
f9903ed0 5//
9fa49e22 6// Library of all general-purpose Moodle PHP functions and constants
7// that produce HTML output
f9903ed0 8//
9fa49e22 9///////////////////////////////////////////////////////////////////////////
10// //
11// NOTICE OF COPYRIGHT //
12// //
13// Moodle - Modular Object-Oriented Dynamic Learning Environment //
14// http://moodle.com //
15// //
16// Copyright (C) 2001-2003 Martin Dougiamas http://dougiamas.com //
17// //
18// This program is free software; you can redistribute it and/or modify //
19// it under the terms of the GNU General Public License as published by //
20// the Free Software Foundation; either version 2 of the License, or //
21// (at your option) any later version. //
22// //
23// This program is distributed in the hope that it will be useful, //
24// but WITHOUT ANY WARRANTY; without even the implied warranty of //
25// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
26// GNU General Public License for more details: //
27// //
28// http://www.gnu.org/copyleft/gpl.html //
29// //
30///////////////////////////////////////////////////////////////////////////
f9903ed0 31
0095d5cd 32/// Constants
33
c1d57101 34/// Define text formatting types ... eventually we can add Wiki, BBcode etc
b0ccd3fb 35define('FORMAT_MOODLE', '0'); // Does all sorts of transformations and filtering
36define('FORMAT_HTML', '1'); // Plain HTML (with some tags stripped)
37define('FORMAT_PLAIN', '2'); // Plain text (even tags are printed in full)
38define('FORMAT_WIKI', '3'); // Wiki-formatted text
39define('FORMAT_MARKDOWN', '4'); // Markdown-formatted text http://daringfireball.net/projects/markdown/
0095d5cd 40
39dda0fc 41$ALLOWED_TAGS =
b0ccd3fb 42'<p><br /><b><i><u><font><table><tbody><span><div><tr><td><th><ol><ul><dl><li><dt><dd><h1><h2><h3><h4><h5><h6><hr><img><a><strong><emphasis><em><sup><sub><address><cite><blockquote><pre><strike><embed><object><param><acronym><nolink><style><lang><tex><algebra><math><mi><mn><mo><mtext><mspace><ms><mrow><mfrac><msqrt><mroot><mstyle><merror><mpadded><mphantom><mfenced><msub><msup><msubsup><munder><mover><munderover><mmultiscripts><mtable><mtr><mtd><maligngroup><malignmark><maction><cn><ci><apply><reln><fn><interval><inverse><sep><condition><declare><lambda><compose><ident><quotient><exp><factorial><divide><max><min><minus><plus><power><rem><times><root><gcd><and><or><xor><not><implies><forall><exists><abs><conjugate><eq><neq><gt><lt><geq><leq><ln><log><int><diff><partialdiff><lowlimit><uplimit><bvar><degree><set><list><union><intersect><in><notin><subset><prsubset><notsubset><notprsubset><setdiff><sum><product><limit><tendsto><mean><sdev><variance><median><mode><moment><vector><matrix><matrixrow><determinant><transpose><selector><annotation><semantics><annotation-xml><tt><code>';
3fe3851d 43
44
0095d5cd 45/// Functions
46
3662bce5 47function s($var) {
c1d57101 48/// returns $var with HTML characters (like "<", ">", etc.) properly quoted,
f9903ed0 49
3662bce5 50 if (empty($var)) {
b0ccd3fb 51 return '';
3662bce5 52 }
7d8f674d 53 return htmlSpecialChars(stripslashes_safe($var));
f9903ed0 54}
55
3662bce5 56function p($var) {
c1d57101 57/// prints $var with HTML characters (like "<", ">", etc.) properly quoted,
f9903ed0 58
3662bce5 59 if (empty($var)) {
b0ccd3fb 60 echo '';
3662bce5 61 }
7d8f674d 62 echo htmlSpecialChars(stripslashes_safe($var));
f9903ed0 63}
64
b0ccd3fb 65function nvl(&$var, $default='') {
ab9f24ad 66/// if $var is undefined, return $default, otherwise return $var
8553b700 67
68 return isset($var) ? $var : $default;
69}
f9903ed0 70
71function strip_querystring($url) {
ab9f24ad 72/// takes a URL and returns it without the querystring portion
f9903ed0 73
b9b8ab69 74 if ($commapos = strpos($url, '?')) {
75 return substr($url, 0, $commapos);
76 } else {
77 return $url;
78 }
f9903ed0 79}
80
81function get_referer() {
ab9f24ad 82/// returns the URL of the HTTP_REFERER, less the querystring portion
f9903ed0 83
b0ccd3fb 84 return strip_querystring(nvl($_SERVER['HTTP_REFERER']));
f9903ed0 85}
86
c1d57101 87
f9903ed0 88function me() {
c1d57101 89/// returns the name of the current script, WITH the querystring portion.
eaa50dbc 90/// this function is necessary because PHP_SELF and REQUEST_URI and SCRIPT_NAME
c1d57101 91/// return different things depending on a lot of things like your OS, Web
ab9f24ad 92/// server, and the way PHP is compiled (ie. as a CGI, module, ISAPI, etc.)
f9903ed0 93
b0ccd3fb 94 if (!empty($_SERVER['REQUEST_URI'])) {
95 return $_SERVER['REQUEST_URI'];
c1d57101 96
b0ccd3fb 97 } else if (!empty($_SERVER['PHP_SELF'])) {
98 if (!empty($_SERVER['QUERY_STRING'])) {
99 return $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'];
fced815c 100 }
b0ccd3fb 101 return $_SERVER['PHP_SELF'];
c1d57101 102
b0ccd3fb 103 } else if (!empty($_SERVER['SCRIPT_NAME'])) {
104 if (!empty($_SERVER['QUERY_STRING'])) {
105 return $_SERVER['SCRIPT_NAME'] .'?'. $_SERVER['QUERY_STRING'];
fced815c 106 }
b0ccd3fb 107 return $_SERVER['SCRIPT_NAME'];
fced815c 108
b0ccd3fb 109 } else if (!empty($_SERVER['URL'])) { // May help IIS (not well tested)
110 if (!empty($_SERVER['QUERY_STRING'])) {
111 return $_SERVER['URL'] .'?'. $_SERVER['QUERY_STRING'];
16c4d82a 112 }
b0ccd3fb 113 return $_SERVER['URL'];
16c4d82a 114
b9b8ab69 115 } else {
b0ccd3fb 116 notify('Warning: Could not find any of these web server variables: $REQUEST_URI, $PHP_SELF, $SCRIPT_NAME or $URL');
bcdfe14e 117 return false;
7fbd6b1c 118 }
f9903ed0 119}
120
121
f9903ed0 122function qualified_me() {
ab9f24ad 123/// like me() but returns a full URL
f9903ed0 124
b0ccd3fb 125 if (!empty($_SERVER['SERVER_NAME'])) {
126 $hostname = $_SERVER['SERVER_NAME'];
127 } else if (!empty($_ENV['SERVER_NAME'])) {
128 $hostname = $_ENV['SERVER_NAME'];
129 } else if (!empty($_SERVER['HTTP_HOST'])) {
130 $hostname = $_SERVER['HTTP_HOST'];
131 } else if (!empty($_ENV['HTTP_HOST'])) {
132 $hostname = $_ENV['HTTP_HOST'];
39e018b3 133 } else {
b0ccd3fb 134 notify('Warning: could not find the name of this server!');
bcdfe14e 135 return false;
c1d57101 136 }
f77c261e 137 if (isset($_SERVER['HTTPS'])) {
138 $protocol = ($_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
139 } else if (isset($_SERVER['SERVER_PORT'])) { # Apache2 does not export $_SERVER['HTTPS']
140 $protocol = ($_SERVER['SERVER_PORT'] == '443') ? 'https://' : 'http://';
141 } else {
142 $protocol = 'http://';
143 }
f9903ed0 144
39e018b3 145 $url_prefix = $protocol.$hostname;
b9b8ab69 146 return $url_prefix . me();
f9903ed0 147}
148
149
b0ccd3fb 150function match_referer($goodreferer = '') {
a0deb5db 151/// returns true if the referer is the same as the goodreferer. If
ab9f24ad 152/// goodreferer is not specified, use qualified_me as the goodreferer
60f18531 153 global $CFG;
154
ae384ef1 155 if (empty($CFG->secureforms)) { // Don't bother checking referer
60f18531 156 return true;
157 }
f9903ed0 158
b0ccd3fb 159 if ($goodreferer == 'nomatch') { // Don't bother checking referer
a0deb5db 160 return true;
161 }
162
ab9f24ad 163 if (empty($goodreferer)) {
164 $goodreferer = qualified_me();
c1d57101 165 }
67b1b6c2 166
9d54c2fb 167 $referer = get_referer();
168
b0ccd3fb 169 return (($referer == $goodreferer) or ($referer == $CFG->wwwroot .'/'));
f9903ed0 170}
171
b0ccd3fb 172function data_submitted($url='') {
36b4f985 173/// Used on most forms in Moodle to check for data
174/// Returns the data as an object, if it's found.
607809b3 175/// This object can be used in foreach loops without
176/// casting because it's cast to (array) automatically
ab9f24ad 177///
178/// Checks that submitted POST data exists, and also
179/// checks the referer against the given url (it uses
36b4f985 180/// the current page if none was specified.
181
37208cd2 182 global $CFG;
183
607809b3 184 if (empty($_POST)) {
36b4f985 185 return false;
607809b3 186
36b4f985 187 } else {
188 if (match_referer($url)) {
607809b3 189 return (object)$_POST;
36b4f985 190 } else {
191 if ($CFG->debug > 10) {
b0ccd3fb 192 notice('The form did not come from this page! (referer = '. get_referer() .')');
36b4f985 193 }
194 return false;
195 }
196 }
197}
198
7d8f674d 199function stripslashes_safe($string) {
ab9f24ad 200/// stripslashes() removes ALL backslashes even from strings
7d8f674d 201/// so C:\temp becomes C:temp ... this isn't good.
ab9f24ad 202/// The following should work as a fairly safe replacement
7d8f674d 203/// to be called on quoted AND unquoted strings (to be sure)
204
205 $string = str_replace("\\'", "'", $string);
206 $string = str_replace('\\"', '"', $string);
47b30797 207 //$string = str_replace('\\\\', '\\', $string); // why?
7d8f674d 208 return $string;
209}
f9903ed0 210
4a5644e5 211
212function break_up_long_words($string, $maxsize=20, $cutchar=' ') {
ab9f24ad 213/// Given some normal text, this function will break up any
4a5644e5 214/// long words to a given size, by inserting the given character
215
5b07d990 216 if (in_array(current_language(), array('ja', 'zh_cn', 'zh_tw', 'zh_tw_utf8'))) { // Multibyte languages
217 return $string;
218 }
219
4a5644e5 220 $output = '';
221 $length = strlen($string);
222 $wordlength = 0;
223
224 for ($i=0; $i<$length; $i++) {
225 $char = $string[$i];
226 if ($char == ' ' or $char == "\t" or $char == "\n" or $char == "\r") {
227 $wordlength = 0;
228 } else {
229 $wordlength++;
230 if ($wordlength > $maxsize) {
231 $output .= $cutchar;
232 $wordlength = 0;
233 }
234 }
235 $output .= $char;
236 }
237 return $output;
238}
239
240
ce57cc79 241if (!function_exists('str_ireplace')) { /// Only exists in PHP 5
7ec2fc00 242 function str_ireplace($find, $replace, $string) {
72e4eac6 243 /// This does a search and replace, ignoring case
ce57cc79 244 /// This function is only used for versions of PHP older than version 5
245 /// which do not have a native version of this function.
246 /// Taken from the PHP manual, by bradhuizenga @ softhome.net
7ec2fc00 247
248 if (!is_array($find)) {
249 $find = array($find);
250 }
251
252 if(!is_array($replace)) {
253 if (!is_array($find)) {
254 $replace = array($replace);
255 } else {
256 // this will duplicate the string into an array the size of $find
257 $c = count($find);
258 $rString = $replace;
259 unset($replace);
260 for ($i = 0; $i < $c; $i++) {
261 $replace[$i] = $rString;
262 }
263 }
264 }
265
266 foreach ($find as $fKey => $fItem) {
267 $between = explode(strtolower($fItem),strtolower($string));
268 $pos = 0;
269 foreach($between as $bKey => $bItem) {
270 $between[$bKey] = substr($string,$pos,strlen($bItem));
271 $pos += strlen($bItem) + strlen($fItem);
272 }
273 $string = implode($replace[$fKey],$between);
72e4eac6 274 }
7ec2fc00 275 return ($string);
3fe3851d 276 }
3fe3851d 277}
278
ce57cc79 279if (!function_exists('stripos')) { /// Only exists in PHP 5
280 function stripos($haystack, $needle, $offset=0) {
281 /// This function is only used for versions of PHP older than version 5
282 /// which do not have a native version of this function.
283 /// Taken from the PHP manual, by dmarsh @ spscc.ctc.edu
284 return strpos(strtoupper($haystack), strtoupper($needle), $offset);
285 }
286}
287
f9903ed0 288function read_template($filename, &$var) {
c1d57101 289/// return a (big) string containing the contents of a template file with all
290/// the variables interpolated. all the variables must be in the $var[] array or
291/// object (whatever you decide to use).
292///
ab9f24ad 293/// WARNING: do not use this on big files!!
f9903ed0 294
b0ccd3fb 295 $temp = str_replace("\\", "\\\\", implode(file($filename), ''));
b9b8ab69 296 $temp = str_replace('"', '\"', $temp);
297 eval("\$template = \"$temp\";");
298 return $template;
f9903ed0 299}
300
301function checked(&$var, $set_value = 1, $unset_value = 0) {
c1d57101 302/// if variable is set, set it to the set_value otherwise set it to the
303/// unset_value. used to handle checkboxes when you are expecting them from
ab9f24ad 304/// a form
f9903ed0 305
b9b8ab69 306 if (empty($var)) {
307 $var = $unset_value;
308 } else {
309 $var = $set_value;
310 }
f9903ed0 311}
312
b0ccd3fb 313function frmchecked(&$var, $true_value = 'checked', $false_value = '') {
c1d57101 314/// prints the word "checked" if a variable is true, otherwise prints nothing,
ab9f24ad 315/// used for printing the word "checked" in a checkbox form input
f9903ed0 316
b9b8ab69 317 if ($var) {
318 echo $true_value;
319 } else {
320 echo $false_value;
321 }
f9903ed0 322}
323
324
b0ccd3fb 325function link_to_popup_window ($url, $name='popup', $linkname='click here',
326 $height=400, $width=500, $title='Popup window', $options='none', $return=false) {
ab9f24ad 327/// This will create a HTML link that will work on both
c1d57101 328/// Javascript and non-javascript browsers.
329/// Relies on the Javascript function openpopup in javascript.php
330/// $url must be relative to home page eg /mod/survey/stuff.php
f9903ed0 331
ff80e012 332 global $CFG;
333
b0ccd3fb 334 if ($options == 'none') {
335 $options = 'menubar=0,location=0,scrollbars,resizable,width='. $width .',height='. $height;
b48f834c 336 }
86aa7ccf 337 $fullscreen = 0;
f9903ed0 338
c80b7585 339 if (!(strpos($url,$CFG->wwwroot) === false)) { // some log url entries contain _SERVER[HTTP_REFERRER] in which case wwwroot is already there.
340 $url = substr($url,strlen($CFG->wwwroot)+1);
341 }
342
b0ccd3fb 343 $link = '<a target="'. $name .'" title="'. $title .'" href="'. $CFG->wwwroot . $url .'" '.
6ccf1c63 344 "onclick=\"return openpopup('$url', '$name', '$options', $fullscreen);\">$linkname</a>\n";
1f2eec7b 345 if ($return) {
346 return $link;
347 } else {
348 echo $link;
349 }
f9903ed0 350}
351
86aa7ccf 352
b0ccd3fb 353function button_to_popup_window ($url, $name='popup', $linkname='click here',
354 $height=400, $width=500, $title='Popup window', $options='none') {
ab9f24ad 355/// This will create a HTML link that will work on both
52f1b496 356/// Javascript and non-javascript browsers.
357/// Relies on the Javascript function openpopup in javascript.php
358/// $url must be relative to home page eg /mod/survey/stuff.php
359
360 global $CFG;
361
b0ccd3fb 362 if ($options == 'none') {
363 $options = 'menubar=0,location=0,scrollbars,resizable,width='. $width .',height='. $height;
52f1b496 364 }
365 $fullscreen = 0;
366
b0ccd3fb 367 echo '<input type="button" name="popupwindow" title="'. $title .'" value="'. $linkname .' ..." '.
ad954fc5 368 "onClick=\"return openpopup('$url', '$name', '$options', $fullscreen);\" />\n";
52f1b496 369}
370
371
f9903ed0 372function close_window_button() {
c1d57101 373/// Prints a simple button to close a window
374
b0ccd3fb 375 echo '<center>' . "\n";
376 echo '<script type="text/javascript">' . "\n";
377 echo '<!--' . "\n";
86aa7ccf 378 echo "document.write('<form>');\n";
66a51452 379 echo "document.write('<input type=\"button\" onClick=\"self.close();\" value=\"".get_string("closewindow")."\" />');\n";
86aa7ccf 380 echo "document.write('</form>');\n";
b0ccd3fb 381 echo '-->' . "\n";
382 echo '</script>' . "\n";
383 echo '<noscript>' . "\n";
384 echo '<a href="'. $_SERVER['HTTP_REFERER'] .'"><---</a>' . "\n";
385 echo '</noscript>' . "\n";
386 echo '</center>' . "\n";
f9903ed0 387}
388
389
b0ccd3fb 390function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false) {
c1d57101 391/// Given an array of value, creates a popup menu to be part of a form
392/// $options["value"]["label"]
ab9f24ad 393
b0ccd3fb 394 if ($nothing == 'choose') {
395 $nothing = get_string('choose') .'...';
618b22c5 396 }
397
f9903ed0 398 if ($script) {
b0ccd3fb 399 $javascript = 'onchange="'. $script .'"';
9c9f7d77 400 } else {
b0ccd3fb 401 $javascript = '';
f9903ed0 402 }
9c9f7d77 403
b0ccd3fb 404 $output = '<select name="'. $name .'" '. $javascript .'>' . "\n";
bda8d43a 405 if ($nothing) {
b0ccd3fb 406 $output .= ' <option value="'. $nothingvalue .'"'. "\n";
cec0a0fc 407 if ($nothingvalue === $selected) {
b0ccd3fb 408 $output .= ' selected="selected"';
bda8d43a 409 }
b0ccd3fb 410 $output .= '>'. $nothing .'</option>' . "\n";
873960de 411 }
607809b3 412 if (!empty($options)) {
413 foreach ($options as $value => $label) {
b0ccd3fb 414 $output .= ' <option value="'. $value .'"';
607809b3 415 if ($value == $selected) {
b0ccd3fb 416 $output .= ' selected="selected"';
607809b3 417 }
b0ccd3fb 418 if ($label === '') {
419 $output .= '>'. $value .'</option>' . "\n";
a20c1090 420 } else {
b0ccd3fb 421 $output .= '>'. $label .'</option>' . "\n";
607809b3 422 }
f9903ed0 423 }
424 }
b0ccd3fb 425 $output .= '</select>' . "\n";
08056730 426
427 if ($return) {
428 return $output;
429 } else {
430 echo $output;
431 }
ab9f24ad 432}
f9903ed0 433
b0ccd3fb 434function popup_form ($common, $options, $formname, $selected='', $nothing='choose', $help='', $helptext='', $return=false, $targetwindow='self') {
c1d57101 435/// Implements a complete little popup form
436/// $common = the URL up to the point of the variable that changes
437/// $options = A list of value-label pairs for the popup list
438/// $formname = name must be unique on the page
439/// $selected = the option that is already selected
440/// $nothing = The label for the "no choice" option
e5dfd0f3 441/// $help = The name of a help page if help is required
442/// $helptext = The name of the label for the help button
ab9f24ad 443/// $return = Boolean indicating whether the function should return the text
5b472756 444/// as a string or echo it directly to the page being rendered
f9903ed0 445
ab9f24ad 446// TODO:
447//
448// * Make sure it's W3C conformant (<form name=""> has to go for example)
449// * Code it in a way that doesn't require JS to be on. Example code:
450// $selector .= '<form method="get" action="" style="display: inline;"><span>';
451// $selector .= '<input type="hidden" name="var" value="value" />';
452// if(!empty($morevars)) {
453// $getarray = explode('&amp;', $morevars);
454// foreach($getarray as $thisvar) {
455// $selector .= '<input type="hidden" name="'.strtok($thisvar, '=').'" value="'.strtok('=').'" />';
456// }
457// }
458// $selector .= '<select name="" onchange="form.submit();">';
459// foreach($options as $id => $text) {
460// $selector .= "\n<option value='$id'";
461// if($option->id == $selected) {
462// $selector .= ' selected';
463// }
464// $selector .= '>'.$text."</option>\n";
465// }
466// $selector .= '</select>';
467// $selector .= '<noscript id="unique_id" style="display: inline;"> <input type="submit" value="'.get_string('somestring').'" /></noscript>';
468// $selector .= '<script type="text/javascript">'."\n<!--\n".'document.getElementById("unique_id").style.display = "none";'."\n<!--\n".'</script>';
469// $selector .= '</span></form>';
470//
471
0d0baabf 472 global $CFG;
87180677 473
6f9f3b69 474 if (empty($options)) {
475 return '';
476 }
0d0baabf 477
b0ccd3fb 478 if ($nothing == 'choose') {
479 $nothing = get_string('choose') .'...';
618b22c5 480 }
481
6ccf1c63 482 $startoutput = '<form action="" method="get" target="'.$CFG->framename.'" name="'.$formname.'">';
8f0cd6ef 483 $output = "<select name=\"popup\" onchange=\"$targetwindow.location=document.$formname.popup.options[document.$formname.popup.selectedIndex].value;\">\n";
f9903ed0 484
b0ccd3fb 485 if ($nothing != '') {
dfec7b01 486 $output .= " <option value=\"javascript:void(0)\">$nothing</option>\n";
f9903ed0 487 }
488
489 foreach ($options as $value => $label) {
b0ccd3fb 490 if (substr($label,0,2) == '--') {
491 $output .= ' <optgroup label="'. $label .'"></optgroup>'; // Plain labels
3326450b 492 continue;
d897cae4 493 } else {
b0ccd3fb 494 $output .= ' <option value="'. $common . $value .'"';
d897cae4 495 if ($value == $selected) {
6ccf1c63 496 $output .= ' selected="selected"';
d897cae4 497 }
f9903ed0 498 }
499 if ($label) {
b0ccd3fb 500 $output .= '>'. $label .'</option>' . "\n";
f9903ed0 501 } else {
b0ccd3fb 502 $output .= '>'. $value .'</option>' . "\n";
f9903ed0 503 }
504 }
b0ccd3fb 505 $output .= '</select>';
506 $output .= '</form>' . "\n";
d897cae4 507
1f2eec7b 508 if ($help) {
509 $button = helpbutton($help, $helptext, 'moodle', true, false, '', true);
510 } else {
511 $button = '';
512 }
513
d897cae4 514 if ($return) {
1f2eec7b 515 return $startoutput.$button.$output;
d897cae4 516 } else {
1f2eec7b 517 echo $startoutput.$button.$output;
d897cae4 518 }
f9903ed0 519}
520
521
522
523function formerr($error) {
c1d57101 524/// Prints some red text
f9903ed0 525 if (!empty($error)) {
b0ccd3fb 526 echo '<font color="#ff0000">'. $error .'</font>';
f9903ed0 527 }
528}
529
530
531function validate_email ($address) {
66a51452 532/// Validates an email to make sure it makes sense.
f9903ed0 533 return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
534 '@'.
535 '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
536 '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
537 $address));
538}
539
80035a89 540function detect_munged_arguments($string, $allowdots=1) {
541 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
6c8e8b5e 542 return true;
543 }
393c9b4f 544 if (ereg('[\|\`]', $string)) { // check for other bad characters
6c8e8b5e 545 return true;
546 }
f038d9a3 547 if (empty($string) or $string == '/') {
548 return true;
549 }
550
6c8e8b5e 551 return false;
552}
553
b0ccd3fb 554function get_slash_arguments($file='file.php') {
6ed3da1d 555/// Searches the current environment variables for some slash arguments
f9903ed0 556
eaa50dbc 557 if (!$string = me()) {
f9903ed0 558 return false;
559 }
eaa50dbc 560
6ed3da1d 561 $pathinfo = explode($file, $string);
ab9f24ad 562
bcdfe14e 563 if (!empty($pathinfo[1])) {
564 return $pathinfo[1];
6ed3da1d 565 } else {
566 return false;
567 }
568}
569
570function parse_slash_arguments($string, $i=0) {
571/// Extracts arguments from "/foo/bar/something"
572/// eg http://mysite.com/script.php/foo/bar/something
f9903ed0 573
6c8e8b5e 574 if (detect_munged_arguments($string)) {
780db230 575 return false;
576 }
b0ccd3fb 577 $args = explode('/', $string);
f9903ed0 578
579 if ($i) { // return just the required argument
580 return $args[$i];
581
582 } else { // return the whole array
583 array_shift($args); // get rid of the empty first one
584 return $args;
585 }
586}
587
0095d5cd 588function format_text_menu() {
c1d57101 589/// Just returns an array of formats suitable for a popup menu
b0ccd3fb 590 return array (FORMAT_MOODLE => get_string('formattext'),
591 FORMAT_HTML => get_string('formathtml'),
592 FORMAT_PLAIN => get_string('formatplain'),
593 FORMAT_WIKI => get_string('formatwiki'),
594 FORMAT_MARKDOWN => get_string('formatmarkdown'));
0095d5cd 595}
596
c4ae4fa1 597function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL ) {
ab9f24ad 598/// Given text in a variety of format codings, this function returns
c1d57101 599/// the text as safe HTML.
600///
601/// $text is raw text (originally from a user)
602/// $format is one of the format constants, defined above
0095d5cd 603
ab9f24ad 604 global $CFG, $course;
c4ae4fa1 605
f0aa2fed 606 if (!empty($CFG->cachetext)) {
607 $time = time() - $CFG->cachetext;
608 $md5key = md5($text);
45121ffb 609 if ($cacheitem = get_record_select('cache_text', "md5key = '$md5key' AND timemodified > '$time'")) {
f0aa2fed 610 return $cacheitem->formattedtext;
611 }
612 }
613
c4ae4fa1 614 if (empty($courseid)) {
8eaa4c61 615 if (!empty($course->id)) { // An ugly hack for better compatibility
c4ae4fa1 616 $courseid = $course->id;
617 }
618 }
a751a4e5 619
8eaa4c61 620 $CFG->currenttextiscacheable = true; // Default status - can be changed by any filter
621
0095d5cd 622 switch ($format) {
73f8658c 623 case FORMAT_HTML:
5f350e8f 624 replace_smilies($text);
9d40806d 625 if (!isset($options->noclean)) {
626 $text = clean_text($text, $format);
627 }
ed5bdd65 628 $text = filter_text($text, $courseid);
73f8658c 629 break;
630
6901fa79 631 case FORMAT_PLAIN:
632 $text = htmlentities($text);
ab892a4f 633 $text = rebuildnolinktag($text);
b0ccd3fb 634 $text = str_replace(' ', '&nbsp; ', $text);
6901fa79 635 $text = nl2br($text);
6901fa79 636 break;
637
d342c763 638 case FORMAT_WIKI:
963c3b55 639 $text = wiki_to_html($text,$courseid);
ab892a4f 640 $text = rebuildnolinktag($text);
9d40806d 641 if (!isset($options->noclean)) {
642 $text = clean_text($text, $format);
643 }
ed5bdd65 644 $text = filter_text($text, $courseid);
d342c763 645 break;
646
e7cdcd18 647 case FORMAT_MARKDOWN:
648 $text = markdown_to_html($text);
9d40806d 649 if (!isset($options->noclean)) {
650 $text = clean_text($text, $format);
651 }
7c3aa358 652 replace_smilies($text);
ed5bdd65 653 $text = filter_text($text, $courseid);
e7cdcd18 654 break;
655
73f8658c 656 default: // FORMAT_MOODLE or anything else
c9dda990 657 if (!isset($options->smiley)) {
658 $options->smiley=true;
659 }
660 if (!isset($options->para)) {
1a072208 661 $options->para=true;
c9dda990 662 }
b7a3d3b2 663 if (!isset($options->newlines)) {
664 $options->newlines=true;
665 }
666 $text = text_to_html($text, $options->smiley, $options->para, $options->newlines);
9d40806d 667 if (!isset($options->noclean)) {
668 $text = clean_text($text, $format);
669 }
ed5bdd65 670 $text = filter_text($text, $courseid);
0095d5cd 671 break;
0095d5cd 672 }
f0aa2fed 673
8eaa4c61 674 if (!empty($CFG->cachetext) and $CFG->currenttextiscacheable) {
f0aa2fed 675 $newrecord->md5key = $md5key;
676 $newrecord->formattedtext = addslashes($text);
677 $newrecord->timemodified = time();
9d40806d 678 @insert_record('cache_text', $newrecord);
f0aa2fed 679 }
680
681 return $text;
0095d5cd 682}
683
d342c763 684function format_text_email($text, $format) {
ab9f24ad 685/// Given text in a variety of format codings, this function returns
d342c763 686/// the text as plain text suitable for plain email.
687///
688/// $text is raw text (originally from a user)
689/// $format is one of the format constants, defined above
690
691 switch ($format) {
692
693 case FORMAT_PLAIN:
694 return $text;
695 break;
696
697 case FORMAT_WIKI:
698 $text = wiki_to_html($text);
5b472756 699 /// This expression turns links into something nice in a text format. (Russell Jungwirth)
700 /// From: http://php.net/manual/en/function.eregi-replace.php and simplified
76add072 701 $text = eregi_replace('(<a [^<]*href=["|\']?([^ "\']*)["|\']?[^>]*>([^<]*)</a>)','\\3 [ \\2 ]', $text);
7c55a29b 702 return strtr(strip_tags($text), array_flip(get_html_translation_table(HTML_ENTITIES)));
d342c763 703 break;
704
6ff45b59 705 case FORMAT_HTML:
706 return html_to_text($text);
707 break;
708
e7cdcd18 709 case FORMAT_MOODLE:
710 case FORMAT_MARKDOWN:
67ccec43 711 default:
76add072 712 $text = eregi_replace('(<a [^<]*href=["|\']?([^ "\']*)["|\']?[^>]*>([^<]*)</a>)','\\3 [ \\2 ]', $text);
7c55a29b 713 return strtr(strip_tags($text), array_flip(get_html_translation_table(HTML_ENTITIES)));
d342c763 714 break;
715 }
716}
0095d5cd 717
e67b9e31 718
c4ae4fa1 719function filter_text($text, $courseid=NULL) {
ab9f24ad 720/// Given some text in HTML format, this function will pass it
e67b9e31 721/// through any filters that have been defined in $CFG->textfilterx
ab9f24ad 722/// The variable defines a filepath to a file containing the
723/// filter function. The file must contain a variable called
e67b9e31 724/// $textfilter_function which contains the name of the function
c4ae4fa1 725/// with $courseid and $text parameters
e67b9e31 726
c4ae4fa1 727 global $CFG;
e67b9e31 728
d523d2ea 729 if (!empty($CFG->textfilters)) {
730 $textfilters = explode(',', $CFG->textfilters);
731 foreach ($textfilters as $textfilter) {
b0ccd3fb 732 if (is_readable($CFG->dirroot .'/'. $textfilter .'/filter.php')) {
733 include_once($CFG->dirroot .'/'. $textfilter .'/filter.php');
df1c4611 734 $functionname = basename($textfilter).'_filter';
735 if (function_exists($functionname)) {
736 $text = $functionname($courseid, $text);
737 }
d523d2ea 738 }
e67b9e31 739 }
740 }
d523d2ea 741
e67b9e31 742 return $text;
743}
744
745
3da47524 746function clean_text($text, $format=FORMAT_MOODLE) {
ab9f24ad 747/// Given raw text (eg typed in by a user), this function cleans it up
c1d57101 748/// and removes any nasty tags that could mess up Moodle pages.
b7a3cf49 749
fc120758 750 global $ALLOWED_TAGS;
3fe3851d 751
ab9f24ad 752 switch ($format) {
e7cdcd18 753 case FORMAT_PLAIN:
754 return $text;
755
756 default:
757
09cbeb40 758 /// Remove tags that are not allowed
3fe3851d 759 $text = strip_tags($text, $ALLOWED_TAGS);
e7cdcd18 760
5b472756 761 /// Remove script events
ab9f24ad 762 $text = eregi_replace("([^a-z])language([[:space:]]*)=", "\\1Xlanguage=", $text);
763 $text = eregi_replace("([^a-z])on([a-z]+)([[:space:]]*)=", "\\1Xon\\2=", $text);
6901fa79 764
67ccec43 765 /// Clean up embedded scripts and , using kses
3bd7ffec 766 $text = cleanAttributes($text);
e7cdcd18 767
6901fa79 768 return $text;
0095d5cd 769 }
b7a3cf49 770}
f9903ed0 771
e7cdcd18 772
3bd7ffec 773function cleanAttributes($str){
774/// This function takes a string and examines it for html tags.
775/// If tags are detected it passes the string to a helper function cleanAttributes2
776/// which checks for attributes and filters them for malicious content
67ccec43 777/// 17/08/2004 :: Eamon DOT Costello AT dcu DOT ie
3bd7ffec 778 $result = preg_replace(
779 '%(<[^>]*(>|$)|>)%me', #search for html tags
67ccec43 780 "cleanAttributes2('\\1')",
3bd7ffec 781 $str
67ccec43 782 );
3bd7ffec 783 return $result;
67ccec43 784}
785
3bd7ffec 786
3bd7ffec 787function cleanAttributes2($htmlTag){
788 /// This function takes a string with an html tag and strips out any unallowed
789 /// protocols e.g. javascript:
790 /// It calls ancillary functions in kses which are prefixed by kses
67ccec43 791 /// 17/08/2004 :: Eamon DOT Costello AT dcu DOT ie
3bd7ffec 792
793 global $CFG;
b0ccd3fb 794 require_once($CFG->libdir .'/kses.php');
3bd7ffec 795
796 $htmlTag = kses_stripslashes($htmlTag);
797 if (substr($htmlTag, 0, 1) != '<'){
798 return '&gt;'; //a single character ">" detected
799 }
800 if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $htmlTag, $matches)){
67ccec43 801 return ''; // It's seriously malformed
802 }
3bd7ffec 803 $slash = trim($matches[1]); //trailing xhtml slash
67ccec43 804 $elem = $matches[2]; //the element name
3bd7ffec 805 $attrlist = $matches[3]; // the list of attributes as a string
806
3df2c543 807 $allowed_protocols = array('http', 'https', 'ftp', 'news', 'mailto', 'teamspeak', 'gopher', 'color');
3bd7ffec 808 $attrArray = kses_hair($attrlist, $allowed_protocols) ;
809
67ccec43 810 $attStr = '';
3bd7ffec 811 foreach ($attrArray as $arreach)
812 {
ec51c7fb 813 $attStr .= ' '.strtolower($arreach['name']).'="'.$arreach['value'].'" ';
3bd7ffec 814 }
815 $xhtml_slash = '';
816 if (preg_match('%/\s*$%', $attrlist)){
67ccec43 817 $xhtml_slash = ' /';
3bd7ffec 818 }
b0ccd3fb 819 return '<'. $slash . $elem . $attStr . $xhtml_slash .'>';
3bd7ffec 820}
821
822
5f350e8f 823function replace_smilies(&$text) {
c1d57101 824/// Replaces all known smileys in the text with image equivalents
2ea9027b 825 global $CFG;
c1d57101 826
5b472756 827/// this builds the mapping array only once
617778f2 828 static $runonce = false;
69081931 829 static $e = array();
830 static $img = array();
617778f2 831 static $emoticons = array(
fbfc2675 832 ':-)' => 'smiley',
833 ':)' => 'smiley',
834 ':-D' => 'biggrin',
835 ';-)' => 'wink',
836 ':-/' => 'mixed',
837 'V-.' => 'thoughtful',
838 ':-P' => 'tongueout',
839 'B-)' => 'cool',
840 '^-)' => 'approve',
841 '8-)' => 'wideeyes',
842 ':o)' => 'clown',
843 ':-(' => 'sad',
844 ':(' => 'sad',
845 '8-.' => 'shy',
846 ':-I' => 'blush',
847 ':-X' => 'kiss',
848 '8-o' => 'surprise',
849 'P-|' => 'blackeye',
850 '8-[' => 'angry',
851 'xx-P' => 'dead',
852 '|-.' => 'sleepy',
853 '}-]' => 'evil',
2ea9027b 854 );
855
fbfc2675 856 if ($runonce == false) { /// After the first time this is not run again
617778f2 857 foreach ($emoticons as $emoticon => $image){
fbfc2675 858 $alttext = get_string($image, 'pix');
859
69081931 860 $e[] = $emoticon;
b0ccd3fb 861 $img[] = '<img alt="'. $alttext .'" width="15" height="15" src="'. $CFG->pixpath .'/s/'. $image.gif .'" />';
617778f2 862 }
863 $runonce = true;
c0f728ba 864 }
b7a3cf49 865
8dcd43f3 866 // Exclude from transformations all the code inside <script> tags
867 // Needed to solve Bug 1185. Thanks to jouse 2001 detecting it. :-)
868 // Based on code from glossary fiter by Williams Castillo.
869 // - Eloy
870
871 // Detect all the <script> zones to take out
872 $excludes = array();
873 preg_match_all('/<script language(.+?)<\/script>/is',$text,$list_of_excludes);
874
875 // Take out all the <script> zones from text
876 foreach (array_unique($list_of_excludes[0]) as $key=>$value) {
877 $excludes['<+'.$key.'+>'] = $value;
878 }
879 if ($excludes) {
880 $text = str_replace($excludes,array_keys($excludes),$text);
881 }
882
fbfc2675 883/// this is the meat of the code - this is run every time
5f350e8f 884 $text = str_replace($e, $img, $text);
8dcd43f3 885
886 // Recover all the <script> zones to text
887 if ($excludes) {
888 $text = str_replace(array_keys($excludes),$excludes,$text);
889 }
1a072208 890}
0095d5cd 891
b7a3d3b2 892function text_to_html($text, $smiley=true, $para=true, $newlines=true) {
c1d57101 893/// Given plain text, makes it into HTML as nicely as possible.
894/// May contain HTML tags already
f9903ed0 895
27326a3e 896 global $CFG;
897
c1d57101 898/// Remove any whitespace that may be between HTML tags
7b3be1b1 899 $text = eregi_replace(">([[:space:]]+)<", "><", $text);
900
c1d57101 901/// Remove any returns that precede or follow HTML tags
0eae8049 902 $text = eregi_replace("([\n\r])<", " <", $text);
903 $text = eregi_replace(">([\n\r])", "> ", $text);
7b3be1b1 904
5f350e8f 905 convert_urls_into_links($text);
f9903ed0 906
c1d57101 907/// Make returns into HTML newlines.
b7a3d3b2 908 if ($newlines) {
909 $text = nl2br($text);
910 }
f9903ed0 911
c1d57101 912/// Turn smileys into images.
d69cb7f4 913 if ($smiley) {
5f350e8f 914 replace_smilies($text);
d69cb7f4 915 }
f9903ed0 916
c1d57101 917/// Wrap the whole thing in a paragraph tag if required
909f539d 918 if ($para) {
b0ccd3fb 919 return '<p>'.$text.'</p>';
909f539d 920 } else {
921 return $text;
922 }
f9903ed0 923}
924
963c3b55 925function wiki_to_html($text,$courseid) {
01d79966 926/// Given Wiki formatted text, make it into XHTML using external function
963c3b55 927 global $CFG;
3e9ca9fb 928
b0ccd3fb 929 require_once($CFG->libdir .'/wiki.php');
3e9ca9fb 930
01d79966 931 $wiki = new Wiki;
963c3b55 932 return $wiki->format($text,$courseid);
3e9ca9fb 933}
934
e7cdcd18 935function markdown_to_html($text) {
936/// Given Markdown formatted text, make it into XHTML using external function
937 global $CFG;
938
b0ccd3fb 939 require_once($CFG->libdir .'/markdown.php');
e7cdcd18 940
941 return Markdown($text);
942}
943
6ff45b59 944function html_to_text($html) {
945/// Given HTML text, make it into plain text using external function
428aaa29 946 global $CFG;
6ff45b59 947
b0ccd3fb 948 require_once($CFG->libdir .'/html2text.php');
6ff45b59 949
950 return html2text($html);
951}
952
953
5f350e8f 954function convert_urls_into_links(&$text) {
955/// Given some text, it converts any URLs it finds into HTML links.
956
957/// Make lone URLs into links. eg http://moodle.com/
3405b212 958 $text = eregi_replace("([[:space:]]|^|\(|\[)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
88438a58 959 "\\1<a href=\"\\2://\\3\\4\" target=\"newpage\">\\2://\\3\\4</a>", $text);
5f350e8f 960
961/// eg www.moodle.com
ab9f24ad 962 $text = eregi_replace("([[:space:]]|^|\(|\[)www\.([^[:space:]]*)([[:alnum:]#?/&=])",
88438a58 963 "\\1<a href=\"http://www.\\2\\3\" target=\"newpage\">www.\\2\\3</a>", $text);
5f350e8f 964}
965
ab9f24ad 966function highlight($needle, $haystack, $case=0,
b0ccd3fb 967 $left_string='<span class="highlight">', $right_string='</span>') {
88438a58 968/// This function will highlight search words in a given string
969/// It cares about HTML and will not ruin links. It's best to use
970/// this function after performing any conversions to HTML.
971/// Function found here: http://forums.devshed.com/t67822/scdaa2d1c3d4bacb4671d075ad41f0854.html
972
69d51d3a 973 if (empty($needle)) {
974 return $haystack;
975 }
976
88438a58 977 $list_of_words = eregi_replace("[^-a-zA-Z0-9&']", " ", $needle);
b0ccd3fb 978 $list_array = explode(' ', $list_of_words);
88438a58 979 for ($i=0; $i<sizeof($list_array); $i++) {
980 if (strlen($list_array[$i]) == 1) {
b0ccd3fb 981 $list_array[$i] = '';
88438a58 982 }
983 }
b0ccd3fb 984 $list_of_words = implode(' ', $list_array);
88438a58 985 $list_of_words_cp = $list_of_words;
986 $final = array();
987 preg_match_all('/<(.+?)>/is',$haystack,$list_of_words);
988
989 foreach (array_unique($list_of_words[0]) as $key=>$value) {
990 $final['<|'.$key.'|>'] = $value;
991 }
992
993 $haystack = str_replace($final,array_keys($final),$haystack);
b0ccd3fb 994 $list_of_words_cp = eregi_replace(' +', '|', $list_of_words_cp);
88438a58 995
b0ccd3fb 996 if ($list_of_words_cp{0}=='|') {
997 $list_of_words_cp{0} = '';
88438a58 998 }
b0ccd3fb 999 if ($list_of_words_cp{strlen($list_of_words_cp)-1}=='|') {
1000 $list_of_words_cp{strlen($list_of_words_cp)-1}='';
88438a58 1001 }
b0ccd3fb 1002 $list_of_words_cp = '('. trim($list_of_words_cp) .')';
88438a58 1003
1004 if (!$case){
b0ccd3fb 1005 $haystack = eregi_replace($list_of_words_cp, $left_string ."\\1". $right_string, $haystack);
88438a58 1006 } else {
b0ccd3fb 1007 $haystack = ereg_replace($list_of_words_cp, $left_string ."\\1". $right_string, $haystack);
88438a58 1008 }
1009 $haystack = str_replace(array_keys($final),$final,$haystack);
1010
1011 return stripslashes($haystack);
1012}
1013
1014function highlightfast($needle, $haystack) {
c1d57101 1015/// This function will highlight instances of $needle in $haystack
ab9f24ad 1016/// It's faster that the above function and doesn't care about
88438a58 1017/// HTML or anything.
5af78ed2 1018
1019 $parts = explode(strtolower($needle), strtolower($haystack));
1020
1021 $pos = 0;
1022
1023 foreach ($parts as $key => $part) {
1024 $parts[$key] = substr($haystack, $pos, strlen($part));
1025 $pos += strlen($part);
1026
b0ccd3fb 1027 $parts[$key] .= '<span class="highlight">'.substr($haystack, $pos, strlen($needle)).'</span>';
5af78ed2 1028 $pos += strlen($needle);
ab9f24ad 1029 }
5af78ed2 1030
1031 return (join('', $parts));
1032}
1033
f9903ed0 1034
9fa49e22 1035/// STANDARD WEB PAGE PARTS ///////////////////////////////////////////////////
1036
b0ccd3fb 1037function print_header ($title='', $heading='', $navigation='', $focus='', $meta='',
1038 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='') {
9fa49e22 1039// $title - appears top of window
1040// $heading - appears top of page
1041// $navigation - premade navigation string
1042// $focus - indicates form element eg inputform.password
1043// $meta - meta tags in the header
1044// $cache - should this page be cacheable?
1045// $button - HTML code for a button (usually for module editing)
66a51452 1046// $menu - HTML code for a popup menu
1047// $usexml - use XML for this page
63f3cbbd 1048// $bodytags - this text will be included verbatim in the <body> tag (useful for onload() etc)
1049
e825f279 1050 global $USER, $CFG, $THEME, $SESSION;
9fa49e22 1051
b3153e4b 1052 global $course; // This is a bit of an ugly hack to be gotten rid of later
1053 if (!empty($course->lang)) {
1054 $CFG->courselang = $course->lang;
1055 }
1056
b0ccd3fb 1057 if (file_exists($CFG->dirroot .'/theme/'. $CFG->theme .'/styles.php')) {
9fa49e22 1058 $styles = $CFG->stylesheet;
1059 } else {
b0ccd3fb 1060 $styles = $CFG->wwwroot .'/theme/standard/styles.php';
9fa49e22 1061 }
1062
b0ccd3fb 1063 if ($navigation == 'home') {
9fa49e22 1064 $home = true;
b0ccd3fb 1065 $navigation = '';
9d378732 1066 } else {
1067 $home = false;
9fa49e22 1068 }
1069
b0ccd3fb 1070 if ($button == '') {
1071 $button = '&nbsp;';
9fa49e22 1072 }
1073
1074 if (!$menu and $navigation) {
8a33e371 1075 if (empty($CFG->loginhttps)) {
1076 $wwwroot = $CFG->wwwroot;
1077 } else {
1078 $wwwroot = str_replace('http','https',$CFG->wwwroot);
1079 }
9fa49e22 1080 if (isset($USER->id)) {
b0ccd3fb 1081 $menu = '<font size="2"><a target="'. $CFG->framename .'" href="'. $wwwroot .'/login/logout.php">'. get_string('logout') .'</a></font>';
9fa49e22 1082 } else {
b0ccd3fb 1083 $menu = '<font size="2"><a target="'. $CFG->framename .'" href="'. $wwwroot .'/login/index.php">'. get_string('login') .'</a></font>';
9fa49e22 1084 }
1085 }
67ccec43 1086
b4bac9b6 1087 if (isset($SESSION->justloggedin)) {
1088 unset($SESSION->justloggedin);
1089 if (!empty($CFG->displayloginfailures)) {
1090 if (!empty($USER->username) and !isguest()) {
1091 if ($count = count_login_failures($CFG->displayloginfailures, $USER->username, $USER->lastlogin)) {
1092 $menu .= '&nbsp;<font size="1">';
1093 if (empty($count->accounts)) {
1094 $menu .= get_string('failedloginattempts', '', $count);
1095 } else {
1096 $menu .= get_string('failedloginattemptsall', '', $count);
1097 }
1098 if (isadmin()) {
1099 $menu .= ' (<a href="'.$CFG->wwwroot.'/course/log.php'.
839f2456 1100 '?chooselog=1&amp;id=1&amp;modid=site_errors">'.get_string('logs').'</a>)';
b4bac9b6 1101 }
1102 $menu .= '</font>';
1103 }
1104 }
1105 }
1106 }
9fa49e22 1107
47037513 1108 // Add a stylesheet for the HTML editor
1109 $meta = "<style type=\"text/css\">@import url($CFG->wwwroot/lib/editor/htmlarea.css);</style>\n$meta\n";
1110
cec0a0fc 1111 if (!empty($CFG->unicode)) {
b0ccd3fb 1112 $encoding = 'utf-8';
a2fa19d8 1113 } else if (!empty($CFG->courselang)) {
b0ccd3fb 1114 $encoding = get_string('thischarset');
a2fa19d8 1115 moodle_setlocale();
1116 } else {
1117 if (!empty($SESSION->encoding)) {
1118 $encoding = $SESSION->encoding;
1119 } else {
b0ccd3fb 1120 $SESSION->encoding = $encoding = get_string('thischarset');
a2fa19d8 1121 }
9fa49e22 1122 }
b0ccd3fb 1123 $meta = '<meta http-equiv="content-type" content="text/html; charset='. $encoding .'" />'. "\n". $meta ."\n";
03fe48e7 1124 if (!$usexml) {
1125 @header('Content-type: text/html; charset='.$encoding);
1126 }
9fa49e22 1127
b0ccd3fb 1128 if ( get_string('thisdirection') == 'rtl' ) {
1129 $direction = ' dir="rtl"';
9fa49e22 1130 } else {
b0ccd3fb 1131 $direction = ' dir="ltr"';
9fa49e22 1132 }
ab9f24ad 1133
9fa49e22 1134 if (!$cache) { // Do everything we can to prevent clients and proxies caching
03fe48e7 1135 @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
1136 @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
1137 @header('Cache-Control: no-store, no-cache, must-revalidate');
1138 @header('Cache-Control: post-check=0, pre-check=0', false);
1139 @header('Pragma: no-cache');
1140
b0ccd3fb 1141 $meta .= "\n".'<meta http-equiv="pragma" content="no-cache" />';
1142 $meta .= "\n".'<meta http-equiv="expires" content="0" />';
66a51452 1143 }
1144
1145 if ($usexml) { // Added by Gustav Delius / Mad Alex for MathML output
8f0cd6ef 1146 // Modified by Julian Sedding
66a51452 1147 $currentlanguage = current_language();
8f0cd6ef 1148 $mathplayer = preg_match("/MathPlayer/i", $_SERVER['HTTP_USER_AGENT']);
1149 if(!$mathplayer) {
1150 header('Content-Type: application/xhtml+xml');
1151 }
b0ccd3fb 1152 echo '<?xml version="1.0" ?>'."\n";
66a51452 1153 if (!empty($CFG->xml_stylesheets)) {
b0ccd3fb 1154 $stylesheets = explode(';', $CFG->xml_stylesheets);
66a51452 1155 foreach ($stylesheets as $stylesheet) {
b0ccd3fb 1156 echo '<?xml-stylesheet type="text/xsl" href="'. $CFG->wwwroot .'/'. $stylesheet .'" ?>' . "\n";
66a51452 1157 }
1158 }
b0ccd3fb 1159 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1';
e4576482 1160 if (!empty($CFG->xml_doctype_extra)) {
b0ccd3fb 1161 echo ' plus '. $CFG->xml_doctype_extra;
e4576482 1162 }
b0ccd3fb 1163 echo '//' . strtoupper($currentlanguage) . '" "'. $CFG->xml_dtd .'">'."\n";
8f0cd6ef 1164 $direction = " xmlns=\"http://www.w3.org/1999/xhtml\"
1165 xmlns:math=\"http://www.w3.org/1998/Math/MathML\"
1166 xml:lang=\"en\"
1167 xmlns:xlink=\"http://www.w3.org/1999/xlink\"
1168 $direction";
1169 if($mathplayer) {
1170 $meta .= '<object id="mathplayer" classid="clsid:32F66A20-7614-11D4-BD11-00104BD3F987">' . "\n";
b0ccd3fb 1171 $meta .= '<!--comment required to prevent this becoming an empty tag-->'."\n";
1172 $meta .= '</object>'."\n";
8f0cd6ef 1173 $meta .= '<?import namespace="math" implementation="#mathplayer" ?>' . "\n";
1174 }
9fa49e22 1175 }
1176
2eea2cce 1177 $title = str_replace('"', '&quot;', $title);
1d9fc417 1178 $title = strip_tags($title);
2eea2cce 1179
b0ccd3fb 1180 include ($CFG->dirroot .'/theme/'. $CFG->theme .'/header.html');
9fa49e22 1181}
1182
90fcc576 1183
b0ccd3fb 1184function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1185 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='') {
90fcc576 1186/// This version of print_header is simpler because the course name does not have to be
1187/// provided explicitly in the strings. It can be used on the site page as in courses
1188/// Eventually all print_header could be replaced by print_header_simple
1189
1190 global $course; // The same hack is used in print_header
1191
1192 $shortname ='';
1193 if ($course->category) {
b0ccd3fb 1194 $shortname = '<a href="../../course/view.php?id='. $course->id .'">'. $course->shortname .'</a> ->';
90fcc576 1195 }
1196
b0ccd3fb 1197 print_header($course->shortname .': '. $title, $course->fullname .' '. $heading, $shortname .' '. $navigation, $focus, $meta,
90fcc576 1198 $cache, $button, $menu, $usexml, $bodytags);
1199}
629b5885 1200
1201
90fcc576 1202
1f2eec7b 1203function print_footer ($course=NULL, $usercourse=NULL) {
ab9f24ad 1204// Can provide a course object to make the footer contain a link to
9fa49e22 1205// to the course home page, otherwise the link will go to the site home
1206 global $USER, $CFG, $THEME;
1207
9fa49e22 1208/// Course links
1209 if ($course) {
b0ccd3fb 1210 if ($course == 'home') { // special case for site home page - please do not remove
1211 $homelink = '<p align="center"><a title="moodle '. $CFG->release .' ('. $CFG->version .')" href="http://moodle.org/" target="_blank">';
1212 $homelink .= '<br /><img width="100" height="30" src="pix/moodlelogo.gif" border="0" /></a></p>';
9fa49e22 1213 $course = get_site();
1214 $homepage = true;
1215 } else {
76c1650d 1216 $homelink = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
9fa49e22 1217 }
1218 } else {
b0ccd3fb 1219 $homelink = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/\">".get_string('home').'</a>';
9fa49e22 1220 $course = get_site();
1221 }
1222
1f2eec7b 1223 if (!$usercourse) {
1224 $usercourse = $course;
1225 }
1226
9fa49e22 1227/// User links
1f2eec7b 1228 $loggedinas = user_login_string($usercourse, $USER);
a282d0ff 1229
b0ccd3fb 1230 include ($CFG->dirroot .'/theme/'. $CFG->theme .'/footer.html');
a282d0ff 1231}
1232
b0ccd3fb 1233function style_sheet_setup($lastmodified=0, $lifetime=300, $themename='') {
1ddf9329 1234/// This function is called by stylesheets to set up the header
1235/// approriately as well as the current path
6535be85 1236
1237 global $CFG;
ab9f24ad 1238
b0ccd3fb 1239 header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $lastmodified) . ' GMT');
1240 header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT');
1241 header('Cache-control: max_age = '. $lifetime);
1242 header('Pragma: ');
1243 header('Content-type: text/css'); // Correct MIME type
6535be85 1244
1245 if (!empty($themename)) {
1246 $CFG->theme = $themename;
1247 }
1248
b0ccd3fb 1249 return $CFG->wwwroot .'/theme/'. $CFG->theme;
6535be85 1250
1251}
1252
a282d0ff 1253
1254function user_login_string($course, $user=NULL) {
1255 global $USER, $CFG;
1256
8d2accb6 1257 if (empty($user)) {
a282d0ff 1258 $user = $USER;
1259 }
1260
1261 if (isset($user->realuser)) {
b0ccd3fb 1262 if ($realuser = get_record('user', 'id', $user->realuser)) {
2d71e8ee 1263 $fullname = fullname($realuser, true);
1264 $realuserinfo = " [<a target=\"{$CFG->framename}\"
1265 href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&amp;return=$realuser->id\">$fullname</a>] ";
9fa49e22 1266 }
9d378732 1267 } else {
b0ccd3fb 1268 $realuserinfo = '';
9fa49e22 1269 }
1270
87180677 1271 if (empty($CFG->loginhttps)) {
1272 $wwwroot = $CFG->wwwroot;
1273 } else {
1274 $wwwroot = str_replace('http','https',$CFG->wwwroot);
1275 }
1276
a282d0ff 1277 if (isset($user->id) and $user->id) {
2d71e8ee 1278 $fullname = fullname($user, true);
1279 $username = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a>";
0ae7e6f4 1280 if (isguest($user->id)) {
b0ccd3fb 1281 $loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).
1282 " (<a target=\"{$CFG->framename}\" href=\"$wwwroot/login/index.php\">".get_string('login').'</a>)';
0ae7e6f4 1283 } else {
b0ccd3fb 1284 $loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).
1285 " (<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/login/logout.php\">".get_string('logout').'</a>)';
0ae7e6f4 1286 }
9fa49e22 1287 } else {
b0ccd3fb 1288 $loggedinas = get_string('loggedinnot', 'moodle').
1289 " (<a target=\"{$CFG->framename}\" href=\"$wwwroot/login/index.php\">".get_string('login').'</a>)';
9fa49e22 1290 }
a282d0ff 1291 return $loggedinas;
9fa49e22 1292}
1293
1294
9fa49e22 1295function print_navigation ($navigation) {
1296 global $CFG;
1297
1298 if ($navigation) {
1299 if (! $site = get_site()) {
b0ccd3fb 1300 $site->shortname = get_string('home');;
9fa49e22 1301 }
50e4a15e 1302 $navigation = str_replace('->', '&raquo;', $navigation);
1303 echo "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/\">$site->shortname</a> &raquo; $navigation";
9fa49e22 1304 }
1305}
1306
d4df9200 1307function print_headline($text, $size=2) {
b0ccd3fb 1308 echo '<b><font size="'. $size .'">'. $text .'</font></b><br />'."\n";
d4df9200 1309}
1310
b0ccd3fb 1311function print_heading($text, $align='center', $size=3) {
1312 echo '<p align="'. $align .'"><font size="'. $size .'"><b>'. stripslashes_safe($text) .'</b></font></p>';
9fa49e22 1313}
1314
b0ccd3fb 1315function print_heading_with_help($text, $helppage, $module='moodle', $icon='') {
9fa49e22 1316// Centered heading with attached help button (same title text)
c9f6251e 1317// and optional icon attached
b0ccd3fb 1318 echo '<p align="center"><font size="3">'. $icon .'<b>'. stripslashes_safe($text);
9fa49e22 1319 helpbutton($helppage, $text, $module);
b0ccd3fb 1320 echo '</b></font></p>';
9fa49e22 1321}
ab9f24ad 1322
9fa49e22 1323function print_continue($link) {
9fa49e22 1324
51a96819 1325 global $CFG;
1326
9fa49e22 1327 if (!$link) {
b0ccd3fb 1328 $link = $_SERVER['HTTP_REFERER'];
9fa49e22 1329 }
1330
b0ccd3fb 1331 print_heading('<a target="'. $CFG->framename .'" href="'. $link .'">'. get_string('continue').'</a>');
9fa49e22 1332}
1333
1334
b0ccd3fb 1335function print_simple_box($message, $align='', $width='', $color='#FFFFFF', $padding=5, $class='generalbox') {
9fa49e22 1336 print_simple_box_start($align, $width, $color, $padding, $class);
7d8f674d 1337 echo stripslashes_safe($message);
9fa49e22 1338 print_simple_box_end();
1339}
1340
b0ccd3fb 1341function print_simple_box_start($align='', $width='', $color='#FFFFFF', $padding=5, $class='generalbox') {
9fa49e22 1342 global $THEME;
1343
1344 if ($align) {
b0ccd3fb 1345 $align = 'align="'. $align .'"';
9fa49e22 1346 }
1347 if ($width) {
b0ccd3fb 1348 $width = 'width="'. $width .'"';
9fa49e22 1349 }
9d378732 1350 echo "<table $align $width class=\"$class\" border=\"0\" cellpadding=\"$padding\" cellspacing=\"0\"><tr><td bgcolor=\"$color\" class=\"$class"."content\">";
9fa49e22 1351}
1352
1353function print_simple_box_end() {
b0ccd3fb 1354 echo '</td></tr></table>';
9fa49e22 1355}
1356
b0ccd3fb 1357function print_single_button($link, $options, $label='OK', $method='get') {
1358 echo '<form action="'. $link .'" method="'. $method .'">';
9fa49e22 1359 if ($options) {
1360 foreach ($options as $name => $value) {
b0ccd3fb 1361 echo '<input type="hidden" name="'. $name .'" value="'. $value .'" />';
9fa49e22 1362 }
1363 }
b0ccd3fb 1364 echo '<input type="submit" value="'. $label .'" /></form>';
9fa49e22 1365}
1366
1367function print_spacer($height=1, $width=1, $br=true) {
1368 global $CFG;
b0ccd3fb 1369 echo '<img height="'. $height .'" width="'. $width .'" src="'. $CFG->wwwroot .'/pix/spacer.gif" alt="" />';
9fa49e22 1370 if ($br) {
b0ccd3fb 1371 echo '<br />'."\n";
9fa49e22 1372 }
1373}
1374
b0ccd3fb 1375function print_file_picture($path, $courseid=0, $height='', $width='', $link='') {
9fa49e22 1376// Given the path to a picture file in a course, or a URL,
1377// this function includes the picture in the page.
1378 global $CFG;
1379
1380 if ($height) {
b0ccd3fb 1381 $height = 'height="'. $height .'"';
9fa49e22 1382 }
1383 if ($width) {
b0ccd3fb 1384 $width = 'width="'. $width .'"';
9fa49e22 1385 }
1386 if ($link) {
b0ccd3fb 1387 echo '<a href="'. $link .'">';
9fa49e22 1388 }
b0ccd3fb 1389 if (substr(strtolower($path), 0, 7) == 'http://') {
1390 echo '<img border="0" '.$height . $width .' src="'. $path .'" />';
9fa49e22 1391
1392 } else if ($courseid) {
b0ccd3fb 1393 echo '<img border="0" '. $height . $width .' src="';
9fa49e22 1394 if ($CFG->slasharguments) { // Use this method if possible for better caching
b0ccd3fb 1395 echo $CFG->wwwroot .'/file.php/'. $courseid .'/'. $path;
9fa49e22 1396 } else {
b0ccd3fb 1397 echo $CFG->wwwroot .'/file.php?file=/'. $courseid .'/'. $path;
9fa49e22 1398 }
b0ccd3fb 1399 echo '" />';
9fa49e22 1400 } else {
b0ccd3fb 1401 echo 'Error: must pass URL or course';
9fa49e22 1402 }
1403 if ($link) {
b0ccd3fb 1404 echo '</a>';
9fa49e22 1405 }
1406}
1407
1408function print_user_picture($userid, $courseid, $picture, $large=false, $returnstring=false, $link=true) {
f374fb10 1409 global $CFG;
9fa49e22 1410
1411 if ($link) {
b0ccd3fb 1412 $output = '<a href="'. $CFG->wwwroot .'/user/view.php?id='. $userid .'&amp;course='. $courseid .'">';
9fa49e22 1413 } else {
b0ccd3fb 1414 $output = '';
9fa49e22 1415 }
1416 if ($large) {
b0ccd3fb 1417 $file = 'f1';
9fa49e22 1418 $size = 100;
1419 } else {
b0ccd3fb 1420 $file = 'f2';
9fa49e22 1421 $size = 35;
1422 }
67a63a30 1423 if ($picture) { // Print custom user picture
9fa49e22 1424 if ($CFG->slasharguments) { // Use this method if possible for better caching
b0ccd3fb 1425 $output .= '<img align="middle" src="'. $CFG->wwwroot .'/user/pix.php/'. $userid .'/'. $file.jpg .'"'.
1426 ' border="0" width="'. $size .'" height="'. $size .'" alt="" />';
9fa49e22 1427 } else {
b0ccd3fb 1428 $output .= '<img align="middle" src="'. $CFG->wwwroot .'/user/pix.php?file=/'. $userid .'/'. $file.jpg .'"'.
1429 ' border="0" width="'. $size .'" height="'. $size .'" alt="" />';
9fa49e22 1430 }
67a63a30 1431 } else { // Print default user pictures (use theme version if available)
839f2456 1432 $output .= "<img align=\"middle\" src=\"$CFG->pixpath/u/$file.png\"".
66a51452 1433 " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
9fa49e22 1434 }
1435 if ($link) {
b0ccd3fb 1436 $output .= '</a>';
9fa49e22 1437 }
1438
1439 if ($returnstring) {
1440 return $output;
1441 } else {
1442 echo $output;
1443 }
1444}
1445
951b22a8 1446function print_user($user, $course) {
1447/// Prints a summary of a user in a nice little box
1448
54be24ec 1449 global $CFG,$USER;
499795e8 1450
951b22a8 1451 static $string;
1452 static $datestring;
1453 static $countries;
1454 static $isteacher;
37d83d99 1455 static $isadmin;
951b22a8 1456
1457 if (empty($string)) { // Cache all the strings for the rest of the page
1458
b0ccd3fb 1459 $string->email = get_string('email');
1460 $string->location = get_string('location');
1461 $string->lastaccess = get_string('lastaccess');
1462 $string->activity = get_string('activity');
1463 $string->unenrol = get_string('unenrol');
1464 $string->loginas = get_string('loginas');
1465 $string->fullprofile = get_string('fullprofile');
1466 $string->role = get_string('role');
1467 $string->name = get_string('name');
1468 $string->never = get_string('never');
1469
1470 $datestring->day = get_string('day');
1471 $datestring->days = get_string('days');
1472 $datestring->hour = get_string('hour');
1473 $datestring->hours = get_string('hours');
1474 $datestring->min = get_string('min');
1475 $datestring->mins = get_string('mins');
1476 $datestring->sec = get_string('sec');
1477 $datestring->secs = get_string('secs');
951b22a8 1478
1479 $countries = get_list_of_countries();
1480
1481 $isteacher = isteacher($course->id);
37d83d99 1482 $isadmin = isadmin();
951b22a8 1483 }
1484
1485 echo '<table width="80%" align="center" border="0" cellpadding="10" cellspacing="0" class="userinfobox">';
1486 echo '<tr>';
1487 echo '<td width="100" bgcolor="#ffffff" valign="top" class="userinfoboxside">';
1488 print_user_picture($user->id, $course->id, $user->picture, true);
1489 echo '</td>';
1490 echo '<td width="100%" bgcolor="#ffffff" valign="top" class="userinfoboxsummary">';
1491 echo '<font size="-1">';
1492 echo '<font size="3"><b>'.fullname($user, $isteacher).'</b></font>';
1493 echo '<p>';
1494 if (!empty($user->role) and ($user->role <> $course->teacher)) {
b0ccd3fb 1495 echo $string->role .': '. $user->role .'<br />';
951b22a8 1496 }
d0ec93fb 1497 if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category and !isguest()) or $isteacher) {
b0ccd3fb 1498 echo $string->email .': <a href="mailto:'. $user->email .'">'. $user->email .'</a><br />';
951b22a8 1499 }
1500 if ($user->city or $user->country) {
b0ccd3fb 1501 echo $string->location .': ';
b40bc478 1502 if ($user->city) {
1503 echo $user->city;
1504 }
1505 if (!empty($countries[$user->country])) {
1506 if ($user->city) {
1507 echo ', ';
1508 }
1509 echo $countries[$user->country];
1510 }
b0ccd3fb 1511 echo '<br />';
951b22a8 1512 }
1513 if ($user->lastaccess) {
b0ccd3fb 1514 echo $string->lastaccess .': '. userdate($user->lastaccess);
1515 echo '&nbsp ('. format_time(time() - $user->lastaccess, $datestring) .')';
951b22a8 1516 } else {
b0ccd3fb 1517 echo $string->lastaccess .': '. $string->never;
951b22a8 1518 }
1519 echo '</td><td valign="bottom" bgcolor="#ffffff" nowrap="nowrap" class="userinfoboxlinkcontent">';
1520
1521 echo '<font size="1">';
1522 if ($isteacher) {
1523 $timemidnight = usergetmidnight(time());
b0ccd3fb 1524 echo '<a href="'. $CFG->wwwroot .'/course/user.php?id='. $course->id .'&amp;user='. $user->id .'">'. $string->activity .'</a><br />';
37d83d99 1525 if (!iscreator($user->id) or ($isadmin and !isadmin($user->id))) { // Includes admins
f29667f6 1526 if ($course->category and isteacheredit($course->id) and isstudent($course->id, $user->id)) { // Includes admins
b0ccd3fb 1527 echo '<a href="'. $CFG->wwwroot .'/course/unenrol.php?id='. $course->id .'&amp;user='. $user->id .'">'. $string->unenrol .'</a><br />';
4e3a6092 1528 }
1529 if ($USER->id != $user->id) {
b0ccd3fb 1530 echo '<a href="'. $CFG->wwwroot .'/course/loginas.php?id='. $course->id .'&amp;user='. $user->id .'">'. $string->loginas .'</a><br />';
4e3a6092 1531 }
951b22a8 1532 }
ab9f24ad 1533 }
b0ccd3fb 1534 echo '<a href="'. $CFG->wwwroot .'/user/view.php?id='. $user->id .'&amp;course='. $course->id .'">'. $string->fullprofile .'...</a>';
951b22a8 1535 echo '</font>';
1536
1537 echo '</td></tr></table>';
1538}
1539
1540
f2c80965 1541function print_group_picture($group, $courseid, $large=false, $returnstring=false, $link=true) {
f374fb10 1542 global $CFG;
1543
97ea4833 1544 static $isteacheredit;
1545
1546 if (!isset($isteacheredit)) {
1547 $isteacheredit = isteacheredit($courseid);
1548 }
1549
1550 if ($group->hidepicture and !$isteacheredit) {
3c0561cf 1551 return '';
1552 }
c3cbfe7f 1553
97ea4833 1554 if ($link or $isteacheredit) {
b0ccd3fb 1555 $output = '<a href="'. $CFG->wwwroot .'/course/group.php?id='. $courseid .'&amp;group='. $group->id .'">';
3c0561cf 1556 } else {
1557 $output = '';
1558 }
1559 if ($large) {
b0ccd3fb 1560 $file = 'f1';
3c0561cf 1561 $size = 100;
1562 } else {
b0ccd3fb 1563 $file = 'f2';
3c0561cf 1564 $size = 35;
1565 }
1566 if ($group->picture) { // Print custom group picture
1567 if ($CFG->slasharguments) { // Use this method if possible for better caching
839f2456 1568 $output .= "<img align=\"middle\" src=\"$CFG->wwwroot/user/pixgroup.php/$group->id/$file.jpg\"".
97ea4833 1569 " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" title=\"$group->name\"/>";
f2c80965 1570 } else {
839f2456 1571 $output .= "<img align=\"middle\" src=\"$CFG->wwwroot/user/pixgroup.php?file=/$group->id/$file.jpg\"".
97ea4833 1572 " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" title=\"$group->name\"/>";
f2c80965 1573 }
f374fb10 1574 }
97ea4833 1575 if ($link or $isteacheredit) {
b0ccd3fb 1576 $output .= '</a>';
3c0561cf 1577 }
f374fb10 1578
1579 if ($returnstring) {
1580 return $output;
1581 } else {
1582 echo $output;
1583 }
1584}
1585
35067c43 1586
1587function print_png($url, $sizex, $sizey, $returnstring, $parameters='alt=""') {
1588 global $CFG;
1589 static $recentIE;
1590
1591 if (!isset($recentIE)) {
1592 $recentIE = check_browser_version('MSIE', '5.0');
1593 }
1594
1595 if ($recentIE) { // work around the HORRIBLE bug IE has with alpha transparencies
1596 $output .= "<img src=\"$CFG->pixpath/spacer.gif\" width=\"$sizex\" height=\"$sizey\"".
1597 " border=\"0\" style=\"width: {$sizex}px; height: {$sizey}px; ".
1598 " filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='$url', sizingMethod='scale') ".
1599 " $parameters />";
1600 } else {
1601 $output .= "<img src=\"$url\" border=\"0\" width=\"$sizex\" height=\"$sizey\" ".
1602 " $parameters />";
1603 }
1604
1605 if ($returnstring) {
1606 return $output;
1607 } else {
1608 echo $output;
1609 }
1610}
1611
1612
9fa49e22 1613function print_table($table) {
1614// Prints a nicely formatted table.
1615// $table is an object with several properties.
1616// $table->head is an array of heading names.
1617// $table->align is an array of column alignments
1618// $table->size is an array of column sizes
5867bfb5 1619// $table->wrap is an array of "nowrap"s or nothing
9fa49e22 1620// $table->data[] is an array of arrays containing the data.
1621// $table->width is an percentage of the page
1622// $table->cellpadding padding on each cell
1623// $table->cellspacing spacing between cells
1624
e21e20cf 1625 global $THEME;
1626
9fa49e22 1627 if (isset($table->align)) {
1628 foreach ($table->align as $key => $aa) {
1629 if ($aa) {
b0ccd3fb 1630 $align[$key] = ' align="'. $aa .'"';
9fa49e22 1631 } else {
b0ccd3fb 1632 $align[$key] = '';
9fa49e22 1633 }
1634 }
1635 }
1636 if (isset($table->size)) {
1637 foreach ($table->size as $key => $ss) {
1638 if ($ss) {
b0ccd3fb 1639 $size[$key] = ' width="'. $ss .'"';
9fa49e22 1640 } else {
b0ccd3fb 1641 $size[$key] = '';
9fa49e22 1642 }
1643 }
1644 }
5867bfb5 1645 if (isset($table->wrap)) {
1646 foreach ($table->wrap as $key => $ww) {
1647 if ($ww) {
b0ccd3fb 1648 $wrap[$key] = ' nowrap="nowrap" ';
5867bfb5 1649 } else {
b0ccd3fb 1650 $wrap[$key] = '';
5867bfb5 1651 }
1652 }
1653 }
9fa49e22 1654
9d378732 1655 if (empty($table->width)) {
b0ccd3fb 1656 $table->width = '80%';
9fa49e22 1657 }
1658
9d378732 1659 if (empty($table->cellpadding)) {
b0ccd3fb 1660 $table->cellpadding = '5';
9fa49e22 1661 }
1662
9d378732 1663 if (empty($table->cellspacing)) {
b0ccd3fb 1664 $table->cellspacing = '1';
9fa49e22 1665 }
1666
b0ccd3fb 1667 print_simple_box_start('center', $table->width, '#ffffff', 0);
1668 echo '<table width="100%" border="0" align="center" ';
9fa49e22 1669 echo " cellpadding=\"$table->cellpadding\" cellspacing=\"$table->cellspacing\" class=\"generaltable\">\n";
1670
e21e20cf 1671 $countcols = 0;
1672
b79f41cd 1673 if (!empty($table->head)) {
e21e20cf 1674 $countcols = count($table->head);;
b0ccd3fb 1675 echo '<tr>';
9fa49e22 1676 foreach ($table->head as $key => $heading) {
ab9f24ad 1677
9d378732 1678 if (!isset($size[$key])) {
b0ccd3fb 1679 $size[$key] = '';
ab9f24ad 1680 }
9d378732 1681 if (!isset($align[$key])) {
b0ccd3fb 1682 $align[$key] = '';
ab9f24ad 1683 }
b0ccd3fb 1684 echo '<th valign="top" '. $align[$key].$size[$key] .' nowrap="nowrap" class="generaltableheader">'. $heading .'</th>';
9fa49e22 1685 }
b0ccd3fb 1686 echo '</tr>'."\n";
9fa49e22 1687 }
1688
a1f8ff87 1689 if (!empty($table->data)) {
1690 foreach ($table->data as $row) {
b0ccd3fb 1691 echo '<tr valign="top">';
1692 if ($row == 'hr' and $countcols) {
1693 echo '<td colspan="'. $countcols .'"><div class="tabledivider"></div></td>';
e21e20cf 1694 } else { /// it's a normal row of data
1695 foreach ($row as $key => $item) {
1696 if (!isset($size[$key])) {
b0ccd3fb 1697 $size[$key] = '';
ab9f24ad 1698 }
e21e20cf 1699 if (!isset($align[$key])) {
b0ccd3fb 1700 $align[$key] = '';
ab9f24ad 1701 }
e21e20cf 1702 if (!isset($wrap[$key])) {
b0ccd3fb 1703 $wrap[$key] = '';
ab9f24ad 1704 }
b0ccd3fb 1705 echo '<td '. $align[$key].$size[$key].$wrap[$key] .' class="generaltablecell">'. $item .'</td>';
e21e20cf 1706 }
a1f8ff87 1707 }
b0ccd3fb 1708 echo '</tr>'."\n";
9fa49e22 1709 }
9fa49e22 1710 }
b0ccd3fb 1711 echo '</table>'."\n";
9fa49e22 1712 print_simple_box_end();
1713
1714 return true;
1715}
1716
2f4d324b 1717function make_table($table) {
1718// Creates a nicely formatted table and returns it
1719// $table is an object with several properties.
1720// $table->head is an array of heading names.
1721// $table->align is an array of column alignments
1722// $table->size is an array of column sizes
1723// $table->wrap is an array of "nowrap"s or nothing
1724// $table->data[] is an array of arrays containing the data.
1725// $table->width is an percentage of the page
1726// $table->class is a class
1727// $table->fontsize is the size of all the text
1728// $table->tablealign align the whole table
1729// $table->cellpadding padding on each cell
1730// $table->cellspacing spacing between cells
1731
1732 if (isset($table->align)) {
1733 foreach ($table->align as $key => $aa) {
1734 if ($aa) {
b0ccd3fb 1735 $align[$key] = ' align="'. $aa .'"';
2f4d324b 1736 } else {
b0ccd3fb 1737 $align[$key] = '';
2f4d324b 1738 }
1739 }
1740 }
1741 if (isset($table->size)) {
1742 foreach ($table->size as $key => $ss) {
1743 if ($ss) {
b0ccd3fb 1744 $size[$key] = ' width="'. $ss .'"';
2f4d324b 1745 } else {
b0ccd3fb 1746 $size[$key] = '';
2f4d324b 1747 }
1748 }
1749 }
1750 if (isset($table->wrap)) {
1751 foreach ($table->wrap as $key => $ww) {
1752 if ($ww) {
b0ccd3fb 1753 $wrap[$key] = ' nowrap="nowrap" ';
2f4d324b 1754 } else {
b0ccd3fb 1755 $wrap[$key] = '';
2f4d324b 1756 }
1757 }
1758 }
1759
1760 if (empty($table->width)) {
b0ccd3fb 1761 $table->width = '80%';
2f4d324b 1762 }
1763
1764 if (empty($table->tablealign)) {
b0ccd3fb 1765 $table->tablealign = 'center';
2f4d324b 1766 }
1767
1768 if (empty($table->cellpadding)) {
b0ccd3fb 1769 $table->cellpadding = '5';
2f4d324b 1770 }
1771
1772 if (empty($table->cellspacing)) {
b0ccd3fb 1773 $table->cellspacing = '1';
2f4d324b 1774 }
1775
1776 if (empty($table->class)) {
b0ccd3fb 1777 $table->class = 'generaltable';
2f4d324b 1778 }
1779
1780 if (empty($table->fontsize)) {
b0ccd3fb 1781 $fontsize = '';
2f4d324b 1782 } else {
b0ccd3fb 1783 $fontsize = '<font size="'. $table->fontsize .'">';
2f4d324b 1784 }
1785
b0ccd3fb 1786 $output = '<table width="'. $table->width .'" valign="top" align="'. $table->tablealign .'" ';
1787 $output .= ' cellpadding="'. $table->cellpadding .'" cellspacing="'. $table->cellspacing .'" class="'. $table->class .'">'."\n";
2f4d324b 1788
1789 if (!empty($table->head)) {
b0ccd3fb 1790 $output .= '<tr>';
2f4d324b 1791 foreach ($table->head as $key => $heading) {
1792 if (!isset($size[$key])) {
b0ccd3fb 1793 $size[$key] = '';
ab9f24ad 1794 }
2f4d324b 1795 if (!isset($align[$key])) {
b0ccd3fb 1796 $align[$key] = '';
ab9f24ad 1797 }
b0ccd3fb 1798 $output .= '<th valign="top" '. $align[$key].$size[$key] .' nowrap="nowrap" class="'. $table->class .'header">'.$fontsize.$heading.'</th>';
2f4d324b 1799 }
b0ccd3fb 1800 $output .= '</tr>'."\n";
2f4d324b 1801 }
1802
1803 foreach ($table->data as $row) {
b0ccd3fb 1804 $output .= '<tr valign="top">';
2f4d324b 1805 foreach ($row as $key => $item) {
1806 if (!isset($size[$key])) {
b0ccd3fb 1807 $size[$key] = '';
ab9f24ad 1808 }
2f4d324b 1809 if (!isset($align[$key])) {
b0ccd3fb 1810 $align[$key] = '';
ab9f24ad 1811 }
2f4d324b 1812 if (!isset($wrap[$key])) {
b0ccd3fb 1813 $wrap[$key] = '';
ab9f24ad 1814 }
b0ccd3fb 1815 $output .= '<td '. $align[$key].$size[$key].$wrap[$key] .' class="'. $table->class .'cell">'. $fontsize . $item .'</td>';
2f4d324b 1816 }
b0ccd3fb 1817 $output .= '</tr>'."\n";
2f4d324b 1818 }
b0ccd3fb 1819 $output .= '</table>'."\n";
2f4d324b 1820
1821 return $output;
1822}
1823
b0ccd3fb 1824function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $courseid=0) {
47037513 1825/// Prints a basic textarea field
1826/// $width and height are legacy fields and no longer used
4c46c425 1827
47037513 1828 global $CFG, $course;
50bdc74d 1829
408e62f8 1830 if (empty($courseid)) {
50bdc74d 1831 if (!empty($course->id)) { // search for it in global context
1832 $courseid = $course->id;
1833 }
1834 }
9fa49e22 1835
47037513 1836 if ($usehtmleditor) {
1837 if (!empty($courseid) and isteacher($courseid)) {
b0ccd3fb 1838 echo '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/htmlarea.php?id='. $courseid .'"></script>'."\n";
47037513 1839 } else {
b0ccd3fb 1840 echo '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/htmlarea.php"></script>'."\n";
47037513 1841 }
b0ccd3fb 1842 echo '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/dialog.js"></script>'."\n";
1843 echo '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/lang/en.php"></script>'."\n";
1844 echo '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/popupwin.js"></script>'."\n";
50bdc74d 1845
931d5119 1846 if ($rows < 10) {
1847 $rows = 10;
47037513 1848 }
1849 if ($cols < 65) {
1850 $cols = 65;
4c46c425 1851 }
9fa49e22 1852 }
47037513 1853
67b1b6c2 1854 echo "<textarea id=\"$name\" name=\"$name\" rows=\"$rows\" cols=\"$cols\">";
47037513 1855 p($value);
b0ccd3fb 1856 echo '</textarea>'."\n";
9fa49e22 1857}
1858
b0ccd3fb 1859function print_richedit_javascript($form, $name, $source='no') {
47037513 1860/// Legacy function, provided for backward compatability
1861 use_html_editor($name);
1862}
1863
b0ccd3fb 1864function use_html_editor($name='') {
47037513 1865/// Sets up the HTML editor on textareas in the current page.
1866/// If a field name is provided, then it will only be
1867/// applied to that field - otherwise it will be used
1868/// on every textarea in the page.
1869///
1870/// In most cases no arguments need to be supplied
4c46c425 1871
b0ccd3fb 1872 echo '<script language="javascript" type="text/javascript" defer="defer">'."\n";
eb2042f6 1873 print_editor_config();
47037513 1874 if (empty($name)) {
b0ccd3fb 1875 echo "\n".'HTMLArea.replaceAll(config);'."\n";
47037513 1876 } else {
eb2042f6 1877 echo "\nHTMLArea.replace('$name', config);\n";
4c46c425 1878 }
b0ccd3fb 1879 echo '</script>'."\n";
9fa49e22 1880}
1881
1882
1883function update_course_icon($courseid) {
1884// Used to be an icon, but it's now a simple form button
1885 global $CFG, $USER;
1886
b6c12732 1887 if (isteacheredit($courseid)) {
9c9f7d77 1888 if (!empty($USER->editing)) {
b0ccd3fb 1889 $string = get_string('turneditingoff');
1890 $edit = 'off';
9fa49e22 1891 } else {
b0ccd3fb 1892 $string = get_string('turneditingon');
1893 $edit = 'on';
9fa49e22 1894 }
60b9a565 1895 return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/view.php\">".
66a51452 1896 "<input type=\"hidden\" name=\"id\" value=\"$courseid\" />".
1897 "<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
1898 "<input type=\"submit\" value=\"$string\" /></form>";
9fa49e22 1899 }
1900}
1901
1902function update_module_button($moduleid, $courseid, $string) {
1903// Prints the editing button on a module "view" page
1904 global $CFG;
1905
b6c12732 1906 if (isteacheredit($courseid)) {
b0ccd3fb 1907 $string = get_string('updatethis', '', $string);
60b9a565 1908 return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/mod.php\">".
66a51452 1909 "<input type=\"hidden\" name=\"update\" value=\"$moduleid\" />".
1910 "<input type=\"hidden\" name=\"return\" value=\"true\" />".
1911 "<input type=\"submit\" value=\"$string\" /></form>";
b6c12732 1912 } else {
b0ccd3fb 1913 return '';
9fa49e22 1914 }
1915}
1916
c2cb4545 1917function update_category_button($categoryid) {
d2b6ba70 1918// Prints the editing button on a category page
1919 global $CFG, $USER;
c2cb4545 1920
d2b6ba70 1921 if (iscreator()) {
f374fb10 1922 if (!empty($USER->categoryediting)) {
b0ccd3fb 1923 $string = get_string('turneditingoff');
1924 $edit = 'off';
d2b6ba70 1925 } else {
b0ccd3fb 1926 $string = get_string('turneditingon');
1927 $edit = 'on';
ab9f24ad 1928 }
60b9a565 1929 return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/category.php\">".
66a51452 1930 "<input type=\"hidden\" name=\"id\" value=\"$categoryid\" />".
1931 "<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
1932 "<input type=\"submit\" value=\"$string\" /></form>";
d2b6ba70 1933 }
1934}
1935
1936function update_categories_button() {
1937// Prints the editing button on categories listing
1938 global $CFG, $USER;
1939
1940 if (isadmin()) {
f374fb10 1941 if (!empty($USER->categoriesediting)) {
b0ccd3fb 1942 $string = get_string('turneditingoff');
1943 $edit = 'off';
d2b6ba70 1944 } else {
b0ccd3fb 1945 $string = get_string('turneditingon');
1946 $edit = 'on';
d2b6ba70 1947 }
60b9a565 1948 return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/index.php\">".
66a51452 1949 "<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
1950 "<input type=\"submit\" value=\"$string\" /></form>";
c2cb4545 1951 }
1952}
9fa49e22 1953
b3153e4b 1954function update_group_button($courseid, $groupid) {
f374fb10 1955// Prints the editing button on group page
1956 global $CFG, $USER;
1957
1958 if (isteacheredit($courseid)) {
b3153e4b 1959 $string = get_string('editgroupprofile');
f374fb10 1960 return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/group.php\">".
1961 "<input type=\"hidden\" name=\"id\" value=\"$courseid\" />".
b3153e4b 1962 "<input type=\"hidden\" name=\"group\" value=\"$groupid\" />".
1963 "<input type=\"hidden\" name=\"edit\" value=\"on\" />".
f374fb10 1964 "<input type=\"submit\" value=\"$string\" /></form>";
1965 }
1966}
1967
1968function update_groups_button($courseid) {
1969// Prints the editing button on groups page
1970 global $CFG, $USER;
1971
1972 if (isteacheredit($courseid)) {
1973 if (!empty($USER->groupsediting)) {
b0ccd3fb 1974 $string = get_string('turneditingoff');
1975 $edit = 'off';
f374fb10 1976 } else {
b0ccd3fb 1977 $string = get_string('turneditingon');
1978 $edit = 'on';
f374fb10 1979 }
1980 return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/groups.php\">".
1981 "<input type=\"hidden\" name=\"id\" value=\"$courseid\" />".
1982 "<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
1983 "<input type=\"submit\" value=\"$string\" /></form>";
1984 }
1985}
1986
c3cbfe7f 1987function print_group_menu($groups, $groupmode, $currentgroup, $urlroot) {
1988/// Prints an appropriate group selection menu
1989
1d9fc417 1990/// Add an "All groups" to the start of the menu
b0ccd3fb 1991 $groupsmenu[0] = get_string('allparticipants');
1d9fc417 1992 foreach ($groups as $key => $groupname) {
1993 $groupsmenu[$key] = $groupname;
1994 }
1995
e9a551b3 1996 echo '<table><tr><td align="right">';
c3cbfe7f 1997 if ($groupmode == VISIBLEGROUPS) {
1998 print_string('groupsvisible');
1999 } else {
2000 print_string('groupsseparate');
2001 }
2002 echo ':';
e9a551b3 2003 echo '</td><td nowrap="nowrap" align="left">';
b0ccd3fb 2004 popup_form($urlroot.'&amp;group=', $groupsmenu, 'selectgroup', $currentgroup, '', '', '', false, 'self');
c3cbfe7f 2005 echo '</tr></table>';
2006
2007}
2008
f2d91421 2009
b0ccd3fb 2010function navmenu($course, $cm=NULL, $targetwindow='self') {
9fa49e22 2011// Given a course and a (current) coursemodule
f2d91421 2012// This function returns a small popup menu with all the
9fa49e22 2013// course activity modules in it, as a navigation menu
f2d91421 2014// The data is taken from the serialised array stored in
9fa49e22 2015// the course record
2016
2017 global $CFG;
2018
2019 if ($cm) {
f2d91421 2020 $cm = $cm->id;
9fa49e22 2021 }
2022
2023 if ($course->format == 'weeks') {
b0ccd3fb 2024 $strsection = get_string('week');
9fa49e22 2025 } else {
b0ccd3fb 2026 $strsection = get_string('topic');
9fa49e22 2027 }
2028
2029 if (!$modinfo = unserialize($course->modinfo)) {
b0ccd3fb 2030 return '';
9fa49e22 2031 }
f2d91421 2032 $isteacher = isteacher($course->id);
9fa49e22 2033 $section = -1;
b0ccd3fb 2034 $selected = '';
2035 $url = '';
f2d91421 2036 $previousmod = NULL;
2037 $backmod = NULL;
2038 $nextmod = NULL;
4866a367 2039 $selectmod = NULL;
3da47524 2040 $logslink = NULL;
f2d91421 2041 $flag = false;
6f9f3b69 2042 $menu = array();
5bff6751 2043 $strjumpto = get_string('jumpto');
f2d91421 2044
b0ccd3fb 2045 $sections = get_records('course_sections','course',$course->id,'section','section,visible,summary');
ca189cec 2046
9fa49e22 2047 foreach ($modinfo as $mod) {
b0ccd3fb 2048 if ($mod->mod == 'label') {
ab2df10c 2049 continue;
2050 }
ca189cec 2051
9fa49e22 2052 if ($mod->section > 0 and $section <> $mod->section) {
f2b9b6ea 2053 $thissection = $sections[$mod->section];
2054
2055 if ($thissection->visible or !$course->hiddensections or $isteacher) {
2056 $thissection->summary = strip_tags($thissection->summary);
2057 if ($course->format == 'weeks' or empty($thissection->summary)) {
b0ccd3fb 2058 $menu[] = '-------------- '. $strsection ." ". $mod->section .' --------------';
f2b9b6ea 2059 } else {
2060 if (strlen($thissection->summary) < 47) {
2061 $menu[] = '-- '.$thissection->summary;
2062 } else {
2063 $menu[] = '-- '.substr($thissection->summary, 0, 50).'...';
2064 }
2065 }
ca189cec 2066 }
9fa49e22 2067 }
ca189cec 2068
9fa49e22 2069 $section = $mod->section;
ca189cec 2070
cf055081 2071 //Only add visible or teacher mods to jumpmenu
f2d91421 2072 if ($mod->visible or $isteacher) {
b0ccd3fb 2073 $url = $mod->mod .'/view.php?id='. $mod->cm;
f2d91421 2074 if ($flag) { // the current mod is the "next" mod
2075 $nextmod = $mod;
2076 $flag = false;
2077 }
cf055081 2078 if ($cm == $mod->cm) {
2079 $selected = $url;
3da47524 2080 $selectmod = $mod;
f2d91421 2081 $backmod = $previousmod;
2082 $flag = true; // set flag so we know to use next mod for "next"
a2fa19d8 2083 $mod->name = $strjumpto;
5bff6751 2084 $strjumpto = '';
cb648037 2085 } else {
2086 $mod->name = strip_tags(urldecode($mod->name));
2087 if (strlen($mod->name) > 55) {
b0ccd3fb 2088 $mod->name = substr($mod->name, 0, 50).'...';
cb648037 2089 }
2090 if (!$mod->visible) {
b0ccd3fb 2091 $mod->name = '('.$mod->name.')';
cb648037 2092 }
2a409368 2093 }
f2d91421 2094 $menu[$url] = $mod->name;
db0d0337 2095 $previousmod = $mod;
9fa49e22 2096 }
f2d91421 2097 }
69d79bc3 2098 if ($selectmod and $isteacher) {
791b42ee 2099 $logslink = "<td><a target=\"$CFG->framename\" href=".
839f2456 2100 "\"$CFG->wwwroot/course/log.php?chooselog=1&amp;user=0&amp;date=0&amp;id=$course->id&amp;modid=$selectmod->cm\">".
2101 "<img border=\"0\" height=\"16\" width=\"16\" src=\"$CFG->pixpath/i/log.gif\" alt=\"\" /></a></td>";
ab9f24ad 2102
3da47524 2103 }
f2d91421 2104 if ($backmod) {
2105 $backmod = "<form action=\"$CFG->wwwroot/mod/$backmod->mod/view.php\" target=\"$CFG->framename\">".
ad954fc5 2106 "<input type=\"hidden\" name=\"id\" value=\"$backmod->cm\" />".
2107 "<input type=\"submit\" value=\"&lt;\" /></form>";
f2d91421 2108 }
2109 if ($nextmod) {
2110 $nextmod = "<form action=\"$CFG->wwwroot/mod/$nextmod->mod/view.php\" target=\"$CFG->framename\">".
ad954fc5 2111 "<input type=\"hidden\" name=\"id\" value=\"$nextmod->cm\" />".
2112 "<input type=\"submit\" value=\"&gt;\" /></form>";
f2d91421 2113 }
b0ccd3fb 2114 return '<table><tr>'.$logslink .'<td>'. $backmod .'</td><td>' .
2115 popup_form($CFG->wwwroot .'/mod/', $menu, 'navmenu', $selected, $strjumpto,
2116 '', '', true, $targetwindow).
2117 '</td><td>'. $nextmod .'</td></tr></table>';
f2d91421 2118}
9fa49e22 2119
2120
2121function print_date_selector($day, $month, $year, $currenttime=0) {
2122// Currenttime is a default timestamp in GMT
2123// Prints form items with the names $day, $month and $year
2124
2125 if (!$currenttime) {
2126 $currenttime = time();
2127 }
2128 $currentdate = usergetdate($currenttime);
2129
2130 for ($i=1; $i<=31; $i++) {
b0ccd3fb 2131 $days[$i] = $i;
9fa49e22 2132 }
2133 for ($i=1; $i<=12; $i++) {
39e018b3 2134 $months[$i] = userdate(gmmktime(12,0,0,$i,1,2000), "%B");
9fa49e22 2135 }
2136 for ($i=2000; $i<=2010; $i++) {
2137 $years[$i] = $i;
2138 }
b0ccd3fb 2139 choose_from_menu($days, $day, $currentdate['mday'], '');
2140 choose_from_menu($months, $month, $currentdate['mon'], '');
2141 choose_from_menu($years, $year, $currentdate['year'], '');
9fa49e22 2142}
2143
6942583e 2144function print_time_selector($hour, $minute, $currenttime=0, $step=5) {
9fa49e22 2145// Currenttime is a default timestamp in GMT
2146// Prints form items with the names $hour and $minute
2147
2148 if (!$currenttime) {
2149 $currenttime = time();
2150 }
2151 $currentdate = usergetdate($currenttime);
6942583e 2152 if ($step != 1) {
2153 $currentdate['minutes'] = ceil($currentdate['minutes']/$step)*$step;
2154 }
9fa49e22 2155 for ($i=0; $i<=23; $i++) {
2156 $hours[$i] = sprintf("%02d",$i);
2157 }
6942583e 2158 for ($i=0; $i<=59; $i+=$step) {
9fa49e22 2159 $minutes[$i] = sprintf("%02d",$i);
2160 }
b0ccd3fb 2161 choose_from_menu($hours, $hour, $currentdate['hours'], '');
2162 choose_from_menu($minutes, $minute, $currentdate['minutes'], '');
9fa49e22 2163}
2164
b0ccd3fb 2165function print_timer_selector($timelimit = 0, $unit = '') {
2d9b4f4b 2166/// Prints time limit value selector
2d9b4f4b 2167
2168 global $CFG;
2169
a2fa19d8 2170 if ($unit) {
2171 $unit = ' '.$unit;
2172 }
2173
2d9b4f4b 2174 // Max timelimit is sessiontimeout - 10 minutes.
2175 $maxvalue = ($CFG->sessiontimeout / 60) - 10;
2176
a2fa19d8 2177 for ($i=1; $i<=$maxvalue; $i++) {
2178 $minutes[$i] = $i.$unit;
2d9b4f4b 2179 }
b0ccd3fb 2180 choose_from_menu($minutes, 'timelimit', $timelimit, get_string('none'));
2d9b4f4b 2181}
2182
d6bdd9d5 2183function print_grade_menu($courseid, $name, $current, $includenograde=true) {
62ca135d 2184/// Prints a grade menu (as part of an existing form) with help
2185/// Showing all possible numerical grades and scales
2186
c9f6251e 2187 global $CFG;
62ca135d 2188
b0ccd3fb 2189 $strscale = get_string('scale');
2190 $strscales = get_string('scales');
62ca135d 2191
1f7deef6 2192 $scales = get_scales_menu($courseid);
62ca135d 2193 foreach ($scales as $i => $scalename) {
b0ccd3fb 2194 $grades[-$i] = $strscale .': '. $scalename;
62ca135d 2195 }
d6bdd9d5 2196 if ($includenograde) {
b0ccd3fb 2197 $grades[0] = get_string('nograde');
d6bdd9d5 2198 }
62ca135d 2199 for ($i=100; $i>=1; $i--) {
2200 $grades[$i] = $i;
2201 }
b0ccd3fb 2202 choose_from_menu($grades, $name, $current, '');
62ca135d 2203
b0ccd3fb 2204 $helpicon = $CFG->pixpath .'/help.gif';
839f2456 2205 $linkobject = "<img align=\"middle\" border=\"0\" height=\"17\" width=\"22\" alt=\"$strscales\" src=\"$helpicon\" />";
b0ccd3fb 2206 link_to_popup_window ('/course/scales.php?id='. $courseid .'&amp;list=true', 'ratingscales',
62ca135d 2207 $linkobject, 400, 500, $strscales);
2208}
2209
02ebf404 2210function print_scale_menu($courseid, $name, $current) {
2211/// Prints a scale menu (as part of an existing form) including help button
62ca135d 2212/// Just like print_grade_menu but without the numerical grades
02ebf404 2213
c9f6251e 2214 global $CFG;
02ebf404 2215
b0ccd3fb 2216 $strscales = get_string('scales');
2217 choose_from_menu(get_scales_menu($courseid), $name, $current, '');
2218 $helpicon = $CFG->pixpath .'/help.gif';
839f2456 2219 $linkobject = "<img align=\"middle\" border=\"0\" height=\"17\" width=\"22\" alt=\"$strscales\" src=\"$helpicon\" />";
b0ccd3fb 2220 link_to_popup_window ('/course/scales.php?id='. $courseid .'&amp;list=true', 'ratingscales',
02ebf404 2221 $linkobject, 400, 500, $strscales);
2222}
2223
fdc47ee6 2224
02ebf404 2225function print_scale_menu_helpbutton($courseid, $scale) {
2226/// Prints a help button about a scale
2227/// scale is an object
2228
c9f6251e 2229 global $CFG;
02ebf404 2230
b0ccd3fb 2231 $strscales = get_string('scales');
2232 $helpicon = $CFG->pixpath .'/help.gif';
839f2456 2233 $linkobject = "<img align=\"middle\" border=\"0\" height=\"17\" width=\"22\" alt=\"$scale->name\" src=\"$helpicon\" />";
b0ccd3fb 2234 link_to_popup_window ('/course/scales.php?id='. $courseid .'&amp;list=true&amp;scale='. $scale->id, 'ratingscale',
02ebf404 2235 $linkobject, 400, 500, $scale->name);
2236}
2237
2238
b0ccd3fb 2239function error ($message, $link='') {
9fa49e22 2240 global $CFG, $SESSION;
2241
b0ccd3fb 2242 print_header(get_string('error'));
2243 echo '<br />';
2244 print_simple_box($message, 'center', '', '#FFBBBB');
ab9f24ad 2245
9fa49e22 2246 if (!$link) {
2247 if ( !empty($SESSION->fromurl) ) {
b0ccd3fb 2248 $link = $SESSION->fromurl;
9fa49e22 2249 unset($SESSION->fromurl);
9fa49e22 2250 } else {
b0ccd3fb 2251 $link = $CFG->wwwroot .'/';
9fa49e22 2252 }
2253 }
2254 print_continue($link);
2255 print_footer();
2256 die;
2257}
2258
b0ccd3fb 2259function helpbutton ($page, $title='', $module='moodle', $image=true, $linktext=false, $text='', $return=false) {
9fa49e22 2260 // $page = the keyword that defines a help page
2261 // $title = the title of links, rollover tips, alt tags etc
2262 // $module = which module is the page defined in
2263 // $image = use a help image for the link? (true/false/"both")
ab9f24ad 2264 // $text = if defined then this text is used in the page, and
9fa49e22 2265 // the $page variable is ignored.
dc0dc7d5 2266 global $CFG, $THEME;
9fa49e22 2267
b0ccd3fb 2268 if ($module == '') {
2269 $module = 'moodle';
9fa49e22 2270 }
2271
2272 if ($image) {
b0ccd3fb 2273 $icon = $CFG->pixpath .'/help.gif';
9fa49e22 2274 if ($linktext) {
839f2456 2275 $linkobject = "<span style=\"cursor:help;\">$title<img align=\"middle\" border=\"0\" ".
7fc0f9e5 2276 " height=\"17\" width=\"22\" alt=\"\" src=\"$icon\" /></span>";
9fa49e22 2277 } else {
839f2456 2278 $linkobject = "<img align=\"middle\" border=\"0\" height=\"17\" width=\"22\" ".
7fc0f9e5 2279 " alt=\"$title\" style=\"cursor:help;\" src=\"$icon\" />";
9fa49e22 2280 }
2281 } else {
b0ccd3fb 2282 $linkobject = '<span style="cursor:help;">'. $title .'</span>';
9fa49e22 2283 }
2284 if ($text) {
b0ccd3fb 2285 $url = '/help.php?module='. $module .'&amp;text='. htmlentities(urlencode($text));
9fa49e22 2286 } else {
b0ccd3fb 2287 $url = '/help.php?module='. $module .'&amp;file='. $page .'.html';
9fa49e22 2288 }
1f2eec7b 2289
b0ccd3fb 2290 $link = link_to_popup_window ($url, 'popup', $linkobject, 400, 500, $title, 'none', true);
1f2eec7b 2291
2292 if ($return) {
2293 return $link;
2294 } else {
2295 echo $link;
2296 }
9fa49e22 2297}
2298
e825f279 2299function emoticonhelpbutton($form, $field) {
2300/// Prints a special help button that is a link to the "live" emoticon popup
2301 global $CFG, $SESSION;
2302
2303 $SESSION->inserttextform = $form;
2304 $SESSION->inserttextfield = $field;
b0ccd3fb 2305 helpbutton('emoticons', get_string('helpemoticons'), 'moodle', false, true);
2306 echo '&nbsp;';
2307 link_to_popup_window ('/help.php?module=moodle&amp;file=emoticons.html', 'popup',
839f2456 2308 "<img src=\"$CFG->pixpath/s/smiley.gif\" border=\"0\" align=\"middle\" width=\"15\" height=\"15\" alt=\"\" />",
b0ccd3fb 2309 400, 500, get_string('helpemoticons'));
2310 echo '<br />';
e825f279 2311}
2312
b0ccd3fb 2313function notice ($message, $link='') {
750ab759 2314 global $CFG, $THEME;
9fa49e22 2315
2316 if (!$link) {
b0ccd3fb 2317 if (!empty($_SERVER['HTTP_REFERER'])) {
2318 $link = $_SERVER['HTTP_REFERER'];
750ab759 2319 } else {
b0ccd3fb 2320 $link = $CFG->wwwroot .'/';
750ab759 2321 }
9fa49e22 2322 }
2323
b0ccd3fb 2324 echo '<br />';
2325 print_simple_box($message, 'center', '50%', $THEME->cellheading, '20', 'noticebox');
2326 print_heading('<a href="'. $link .'">'. get_string('continue') .'</a>');
9fa49e22 2327 print_footer(get_site());
2328 die;
2329}
2330
2331function notice_yesno ($message, $linkyes, $linkno) {
2332 global $THEME;
2333
b0ccd3fb 2334 print_simple_box_start('center', '60%', $THEME->cellheading);
2335 echo '<p align="center"><font size="3">'. $message .'</font></p>';
2336 echo '<p align="center"><font size="3"><b>';
2337 echo '<a href="'. $linkyes .'">'. get_string('yes') .'</a>';
2338 echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
2339 echo '<a href="'. $linkno .'">'. get_string('no') .'</a>';
2340 echo '</b></font></p>';
9fa49e22 2341 print_simple_box_end();
2342}
2343
b0ccd3fb 2344function redirect($url, $message='', $delay='0') {
5d6c043a 2345// Redirects the user to another page, after printing a notice
9fa49e22 2346
8f0cd6ef 2347 // '&' needs to be encoded into '&amp;' for XHTML compliance,
2348 // however, this is not true for javascript. Therefore we
2349 // first decode all entities in $url (since we cannot rely on)
2350 // the correct input) and then encode for where it's needed
2351 // echo "<script type='text/javascript'>alert('Redirect $url');</script>";
2352 $url = html_entity_decode($url); // for php < 4.3.0 this is defined in moodlelib.php
2353 $encodedurl = htmlentities($url);
c9082a8c 2354 if (empty($message)) {
b0ccd3fb 2355 echo '<meta http-equiv="refresh" content="'. $delay .'; url='. $encodedurl .'" />';
2356 echo '<script type="text/javascript">'. "\n" .'<!--'. "\n". 'location.replace(\'$url\');'. "\n". '//-->'. "\n". '</script>'; // To cope with Mozilla bug
c9082a8c 2357 } else {
ab9f24ad 2358 if (empty($delay)) {
c9082a8c 2359 $delay = 3; // There's no point having a message with no delay
2360 }
b0ccd3fb 2361 print_header('', '', '', '', '<meta http-equiv="refresh" content="'. $delay .'; url='. $encodedurl .'" />');
2362 echo '<center>';
2363 echo '<p>'. $message .'</p>';
2364 echo '<p>( <a href="'. $encodedurl .'">'. get_string('continue') .'</a> )</p>';
2365 echo '</center>';
ff019455 2366 flush();
2367 sleep($delay);
b0ccd3fb 2368 echo '<script type="text/javascript">'."\n".'<!--'."\n".'location.replace(\'$url\');'."\n".'//-->'."\n".'</script>'; // To cope with Mozilla bug
9fa49e22 2369 }
ab9f24ad 2370 die;
9fa49e22 2371}
2372
b0ccd3fb 2373function notify ($message, $color='red', $align='center') {
2374 echo '<p align="'. $align .'"><b><font color="'. $color .'">'. $message .'</font></b></p>' . "\n";
9fa49e22 2375}
2376
43373804 2377function obfuscate_email($email) {
2378/// Given an email address, this function will return an obfuscated version of it
2379 $i = 0;
2380 $length = strlen($email);
b0ccd3fb 2381 $obfuscated = '';
43373804 2382 while ($i < $length) {
2383 if (rand(0,2)) {
2384 $obfuscated.='%'.dechex(ord($email{$i}));
2385 } else {
2386 $obfuscated.=$email{$i};
2387 }
2388 $i++;
2389 }
2390 return $obfuscated;
2391}
2392
2393function obfuscate_text($plaintext) {
2394/// This function takes some text and replaces about half of the characters
2395/// with HTML entity equivalents. Return string is obviously longer.
2396 $i=0;
2397 $length = strlen($plaintext);
b0ccd3fb 2398 $obfuscated='';
2b09e377 2399 $prev_obfuscated = false;
43373804 2400 while ($i < $length) {
2b09e377 2401 $c = ord($plaintext{$i});
2402 $numerical = ($c >= ord('0')) && ($c <= ord('9'));
2403 if ($prev_obfuscated and $numerical ) {
2404 $obfuscated.='&#'.ord($plaintext{$i});
2405 } else if (rand(0,2)) {
43373804 2406 $obfuscated.='&#'.ord($plaintext{$i});
2b09e377 2407 $prev_obfuscated = true;
43373804 2408 } else {
2409 $obfuscated.=$plaintext{$i};
2b09e377 2410 $prev_obfuscated = false;
43373804 2411 }
2b09e377 2412 $i++;
43373804 2413 }
2414 return $obfuscated;
2415}
2416
b0ccd3fb 2417function obfuscate_mailto($email, $label='', $dimmed=false) {
43373804 2418/// This function uses the above two functions to generate a fully
2419/// obfuscated email link, ready to use.
2420
2421 if (empty($label)) {
2422 $label = $email;
2423 }
cadb96f2 2424 if ($dimmed) {
2425 $title = get_string('emaildisable');
2426 $dimmed = ' class="dimmed"';
2427 } else {
2428 $title = '';
2429 $dimmed = '';
2430 }
ab9f24ad 2431 return sprintf("<a href=\"%s:%s\" $dimmed title=\"$title\">%s</a>",
cadb96f2 2432 obfuscate_text('mailto'), obfuscate_email($email),
2433 obfuscate_text($label));
43373804 2434}
2435
8b9c7aa0 2436function print_paging_bar($totalcount, $page, $perpage, $baseurl) {
2437/// Prints a single paging bar to provide access to other pages (usually in a search)
2438
519d369f 2439 $maxdisplay = 18;
8ef9cb56 2440
8b9c7aa0 2441 if ($totalcount > $perpage) {
b0ccd3fb 2442 echo '<center>';
2443 echo '<p>'.get_string('page').':';
f374fb10 2444 if ($page > 0) {
2445 $pagenum=$page-1;
b0ccd3fb 2446 echo '&nbsp;(<a href="'. $baseurl .'page='. $pagenum .'">'. get_string('previous') .'</a>)&nbsp;';
f374fb10 2447 }
be20753e 2448 $lastpage = ceil($totalcount / $perpage);
2449 if ($page > 15) {
2450 $startpage = $page - 10;
b0ccd3fb 2451 echo '&nbsp<a href="'. $baseurl .'page=0">1</a>&nbsp;...';
be20753e 2452 } else {
2453 $startpage = 0;
2454 }
be20753e 2455 $currpage = $startpage;
2456 $displaycount = 0;
2457 while ($displaycount < $maxdisplay and $currpage < $lastpage) {
2458 $displaypage = $currpage+1;
2459 if ($page == $currpage) {
b0ccd3fb 2460 echo '&nbsp;&nbsp;'. $displaypage;
8b9c7aa0 2461 } else {
b0ccd3fb 2462 echo '&nbsp;&nbsp;<a href="'. $baseurl .'page='. $currpage .'">'. $displaypage .'</a>';
e27dbcc8 2463 }
be20753e 2464 $displaycount++;
2465 $currpage++;
8b9c7aa0 2466 }
924cef21 2467 if ($currpage < $lastpage) {
519d369f 2468 $lastpageactual = $lastpage - 1;
b0ccd3fb 2469 echo '&nbsp;...<a href="'. $baseurl .'page='. $lastpageactual .'">'. $lastpage .'</a>&nbsp;';
924cef21 2470 }
8b9c7aa0 2471 $pagenum = $page + 1;
be20753e 2472 if ($pagenum != $displaypage) {
b0ccd3fb 2473 echo '&nbsp;&nbsp;(<a href="'. $baseurl .'page='. $pagenum .'">'. get_string('next') .'</a>)';
8b9c7aa0 2474 }
b0ccd3fb 2475 echo '</p>';
2476 echo '</center>';
8b9c7aa0 2477 }
2478}
9fa49e22 2479
ab892a4f 2480//This function is used to rebuild the <nolink> tag because some formats (PLAIN and WIKI)
2481//will transform it to html entities
2482function rebuildnolinktag($text) {
ab9f24ad 2483
ab892a4f 2484 $text = preg_replace('/&lt;(\/*nolink)&gt;/i','<$1>',$text);
2485
2486 return $text;
2487}
2488
b4bac9b6 2489
2490
2491
89adb174 2492// ================================================
2493// THREE FUNCTIONS MOVED HERE FROM course/lib.php
2494// ================================================
2495
2496function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array()) {
2497// Prints a nice side block with an optional header. The content can either
2498// be a block of HTML or a list of text with optional icons.
2499
2500 global $THEME;
2501
2502 print_side_block_start($heading, $attributes);
2503
2504 if ($content) {
2505 echo $content;
2506 if ($footer) {
b0ccd3fb 2507 echo '<center><font size="-2">'. $footer .'</font></center>';
89adb174 2508 }
2509 } else {
b0ccd3fb 2510 echo '<table width="100%" border="0" cellspacing="0" cellpadding="2">';
89adb174 2511 if ($list) {
2512 foreach ($list as $key => $string) {
b0ccd3fb 2513 echo '<tr bgcolor="'. $THEME->cellcontent2 .'">';
89adb174 2514 if ($icons) {
b0ccd3fb 2515 echo '<td class="sideblocklinks" valign="top" width="16">'. $icons[$key] .'</td>';
89adb174 2516 }
b0ccd3fb 2517 echo '<td class="sideblocklinks" valign="top" width="*"><font size="-1">'. $string .'</font></td>';
2518 echo '</tr>';
89adb174 2519 }
2520 }
2521 if ($footer) {
b0ccd3fb 2522 echo '<tr bgcolor="'. $THEME->cellcontent2 .'">';
2523 echo '<td class="sideblocklinks" ';
89adb174 2524 if ($icons) {
2525 echo ' colspan="2" ';
2526 }
2527 echo '>';
b0ccd3fb 2528 echo '<center><font size="-2">'. $footer .'</font></center>';
2529 echo '</td></tr>';
89adb174 2530 }
b0ccd3fb 2531 echo '</table>';
89adb174 2532 }
2533
2534 print_side_block_end();
2535}
2536
2537function print_side_block_start($heading='', $attributes = array()) {
2538// Starts a nice side block with an optional header.
2539 global $THEME;
2540
2541 // If there are no special attributes, give a default CSS class
2542 if(empty($attributes) || !is_array($attributes)) {
2543 $attributes = array('class' => 'sideblock');
2544 }
2545 else if(!isset($attributes['class'])) {
2546 $attributes['class'] = 'sideblock';
2547 }
2548 else if(!strpos($attributes['class'], 'sideblock')) {
2549 $attributes['class'] .= ' sideblock';
2550 }
2551 // OK, the class is surely there and in addition to anything
2552 // else, it's tagged as a sideblock
2553
2554 $attrtext = '';
2555 foreach($attributes as $attr => $val) {
2556 $attrtext .= ' '.$attr.'="'.$val.'"';
2557 }
2558
2559 // [pj] UGLY UGLY UGLY! I hate myself for doing this!
2560 // When the Lord Moodle 2.0 cometh, his mercy shalt move all this mess
2561 // to CSS and banish the evil to the abyss from whence it came.
2562 echo '<table style="width: 100%;" cellspacing="0" cellpadding="5"'.$attrtext.'>';
2563 if ($heading) {
eb2aa909 2564 echo '<thead><tr><td class="sideblockheading">'.$heading.'</td></tr></thead>';
89adb174 2565 }
2566 echo '<tbody style="background-color: '.$THEME->cellcontent2.';"><tr><td class="sideblockmain">';
2567}
2568
b4bac9b6 2569
2570
89adb174 2571function print_side_block_end() {
2572 echo '</td></tr></tbody></table><br />';
2573 echo "\n";
2574}
2575
eb2042f6 2576function print_editor_config() {
2577/// prints out the editor config.
89adb174 2578
eb2042f6 2579 global $CFG;
2580
2581 // print new config
b0ccd3fb 2582 echo 'var config = new HTMLArea.Config();'."\n";
eb2042f6 2583 echo "config.pageStyle = \"body {";
2584 if(!(empty($CFG->editorbackgroundcolor))) {
2585 echo " background-color: $CFG->editorbackgroundcolor;";
2586 }
2587
2588 if(!(empty($CFG->editorfontfamily))) {
2589 echo " font-family: $CFG->editorfontfamily;";
2590 }
2591
2592 if(!(empty($CFG->editorfontsize))) {
2593 echo " font-size: $CFG->editorfontsize;";
2594 }
2595
2596 echo " }\";\n";
2597 echo "config.killWordOnPaste = ";
629b5885 2598 echo(empty($CFG->editorkillword)) ? "false":"true";
b0ccd3fb 2599 echo ';'."\n";
2600 echo 'config.fontname = {'."\n";
eb2042f6 2601
629b5885 2602 $fontlist = isset($CFG->editorfontlist) ? explode(';', $CFG->editorfontlist) : array();
eb2042f6 2603 $i = 1; // Counter is used to get rid of the last comma.
2604 $count = count($fontlist); // Otherwise IE doesn't load the editor.
2605
2606 foreach($fontlist as $fontline) {
2607 if(!empty($fontline)) {
b0ccd3fb 2608 list($fontkey, $fontvalue) = split(':', $fontline);
2609 echo '"'. $fontkey ."\":\t'". $fontvalue ."'";
eb2042f6 2610 if($i < $count) {
b0ccd3fb 2611 echo ','."\n";
eb2042f6 2612 }
2613 }
2614 $i++;
2615 }
b0ccd3fb 2616 echo '};';
629b5885 2617 if(!empty($CFG->editorspelling) && !empty($CFG->aspellpath)) {
67ccec43 2618 print_speller_code($usehtmleditor=true);
2619 }
eb2042f6 2620}
2621
2622function print_speller_code ($usehtmleditor=false) {
2623/// Prints out code needed for spellchecking.
2624/// Original idea by Ludo (Marc Alier).
2625 global $CFG;
2626
2627 if(!$usehtmleditor) {
b0ccd3fb 2628 echo "\n".'<script language="javascript" type="text/javascript">'."\n";
2629 echo 'function openSpellChecker() {'."\n";
eb2042f6 2630 echo "\tvar speller = new spellChecker();\n";
2631 echo "\tspeller.popUpUrl = \"" . $CFG->wwwroot ."/lib/speller/spellchecker.html\";\n";
2632 echo "\tspeller.spellCheckScript = \"". $CFG->wwwroot ."/lib/speller/server-scripts/spellchecker.php\";\n";
2633 echo "\tspeller.spellCheckAll();\n";
b0ccd3fb 2634 echo '}'."\n";
2635 echo '</script>'."\n";
eb2042f6 2636 } else {
2637 echo "\nfunction spellClickHandler(editor, buttonId) {\n";
2638 echo "\teditor._textArea.value = editor.getHTML();\n";
2639 echo "\tvar speller = new spellChecker( editor._textArea );\n";
2640 echo "\tspeller.popUpUrl = \"" . $CFG->wwwroot ."/lib/speller/spellchecker.html\";\n";
2641 echo "\tspeller.spellCheckScript = \"". $CFG->wwwroot ."/lib/speller/server-scripts/spellchecker.php\";\n";
2642 echo "\tspeller._moogle_edit=1;\n";
2643 echo "\tspeller._editor=editor;\n";
2644 echo "\tspeller.openChecker();\n";
b0ccd3fb 2645 echo '}'."\n";
eb2042f6 2646 }
2647}
2648
2649function print_speller_button () {
2650// print button for spellchecking
2651// when editor is disabled
b0ccd3fb 2652 echo '<input type="button" value="Check spelling" onclick="openSpellChecker();" />'."\n";
eb2042f6 2653}
9d5b689c 2654// vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
b0ccd3fb 2655?>