User accounts are now included in XML generation
[moodle.git] / lib / weblib.php
CommitLineData
f9903ed0 1<?PHP // $Id$
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
6901fa79 35define("FORMAT_MOODLE", "0"); // Does all sorts of transformations and filtering
d342c763 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
0095d5cd 39
3fe3851d 40$JAVASCRIPT_TAGS = array("javascript:", "onclick=", "ondblclick=", "onkeydown=", "onkeypress=", "onkeyup=",
41 "onmouseover=", "onmouseout=", "onmousedown=", "onmouseup=",
42 "onblur=", "onfocus=", "onload=", "onselect=");
43
db11e52d 44$ALLOWED_TAGS = "<p><br><b><i><u><font><table><tbody><span><div><tr><td><ol><ul><dl><li><dt><dd><h1><h2><h3><h4><h5><h6><hr><img><a><strong><emphasis><sup><sub><address><cite><blockquote><pre><strike><embed><object><param>";
3fe3851d 45
46
0095d5cd 47/// Functions
48
8553b700 49function s($var) {
c1d57101 50/// returns $var with HTML characters (like "<", ">", etc.) properly quoted,
f9903ed0 51
7d8f674d 52 return htmlSpecialChars(stripslashes_safe($var));
f9903ed0 53}
54
55function p($var) {
c1d57101 56/// prints $var with HTML characters (like "<", ">", etc.) properly quoted,
f9903ed0 57
7d8f674d 58 echo htmlSpecialChars(stripslashes_safe($var));
f9903ed0 59}
60
8553b700 61function nvl(&$var, $default="") {
c1d57101 62/// if $var is undefined, return $default, otherwise return $var
8553b700 63
64 return isset($var) ? $var : $default;
65}
f9903ed0 66
67function strip_querystring($url) {
c1d57101 68/// takes a URL and returns it without the querystring portion
f9903ed0 69
b9b8ab69 70 if ($commapos = strpos($url, '?')) {
71 return substr($url, 0, $commapos);
72 } else {
73 return $url;
74 }
f9903ed0 75}
76
77function get_referer() {
c1d57101 78/// returns the URL of the HTTP_REFERER, less the querystring portion
f9903ed0 79
607809b3 80 return strip_querystring(nvl($_SERVER["HTTP_REFERER"]));
f9903ed0 81}
82
c1d57101 83
f9903ed0 84function me() {
c1d57101 85/// returns the name of the current script, WITH the querystring portion.
eaa50dbc 86/// this function is necessary because PHP_SELF and REQUEST_URI and SCRIPT_NAME
c1d57101 87/// return different things depending on a lot of things like your OS, Web
88/// server, and the way PHP is compiled (ie. as a CGI, module, ISAPI, etc.)
f9903ed0 89
607809b3 90 if (!empty($_SERVER["REQUEST_URI"])) {
91 return $_SERVER["REQUEST_URI"];
c1d57101 92
607809b3 93 } else if (!empty($_SERVER["PHP_SELF"])) {
fced815c 94 if (!empty($_SERVER["QUERY_STRING"])) {
95 return $_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"];
96 }
607809b3 97 return $_SERVER["PHP_SELF"];
c1d57101 98
fced815c 99 } else if (!empty($_SERVER["SCRIPT_NAME"])) {
100 if (!empty($_SERVER["QUERY_STRING"])) {
101 return $_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];
102 }
103 return $_SERVER["SCRIPT_NAME"];
104
b9b8ab69 105 } else {
fced815c 106 notify("Warning: Could not find any of these web server variables: \$REQUEST_URI, \$PHP_SELF or \$SCRIPT_NAME");
bcdfe14e 107 return false;
7fbd6b1c 108 }
f9903ed0 109}
110
111
f9903ed0 112function qualified_me() {
c1d57101 113/// like me() but returns a full URL
f9903ed0 114
39e018b3 115 if (!empty($_SERVER["HTTP_HOST"])) {
116 $hostname = $_SERVER["HTTP_HOST"];
117 } else if (!empty($_ENV["HTTP_HOST"])) {
118 $hostname = $_ENV["HTTP_HOST"];
119 } else if (!empty($_ENV["SERVER_NAME"])) {
120 $hostname = $_ENV["SERVER_NAME"];
121 } else {
122 notify("Warning: could not find the name of this server!");
bcdfe14e 123 return false;
c1d57101 124 }
f9903ed0 125
607809b3 126 $protocol = (isset($_SERVER["HTTPS"]) and $_SERVER["HTTPS"] == "on") ? "https://" : "http://";
39e018b3 127 $url_prefix = $protocol.$hostname;
b9b8ab69 128 return $url_prefix . me();
f9903ed0 129}
130
131
132function match_referer($good_referer = "") {
c1d57101 133/// returns true if the referer is the same as the good_referer. If
87a2fa03 134/// good_referer is not specified, use qualified_me as the good_referer
60f18531 135 global $CFG;
136
ce78926d 137 if (!empty($CFG->buggy_referer)) {
60f18531 138 return true;
139 }
f9903ed0 140
ce78926d 141 if (empty($good_referer)) {
c1d57101 142 $good_referer = qualified_me();
143 }
b9b8ab69 144 return $good_referer == get_referer();
f9903ed0 145}
146
36b4f985 147function data_submitted($url="") {
148/// Used on most forms in Moodle to check for data
149/// Returns the data as an object, if it's found.
607809b3 150/// This object can be used in foreach loops without
151/// casting because it's cast to (array) automatically
36b4f985 152///
153/// Checks that submitted POST data exists, and also
154/// checks the referer against the given url (it uses
155/// the current page if none was specified.
156
37208cd2 157 global $CFG;
158
607809b3 159 if (empty($_POST)) {
36b4f985 160 return false;
607809b3 161
36b4f985 162 } else {
163 if (match_referer($url)) {
607809b3 164 return (object)$_POST;
36b4f985 165 } else {
166 if ($CFG->debug > 10) {
167 notice("The form did not come from this page! (referer = ".get_referer().")");
168 }
169 return false;
170 }
171 }
172}
173
7d8f674d 174function stripslashes_safe($string) {
175/// stripslashes() removes ALL backslashes even from strings
176/// so C:\temp becomes C:temp ... this isn't good.
177/// The following should work as a fairly safe replacement
178/// to be called on quoted AND unquoted strings (to be sure)
179
180 $string = str_replace("\\'", "'", $string);
181 $string = str_replace('\\"', '"', $string);
182 $string = str_replace('\\\\', '\\', $string);
183 return $string;
184}
f9903ed0 185
3fe3851d 186function stri_replace($find, $replace, $string ) {
c1d57101 187/// This does a search and replace, ignoring case
188/// This function is only here because one doesn't exist yet in PHP
189/// Unlike str_replace(), this only works on single values (not arrays)
3fe3851d 190
191 $parts = explode(strtolower($find), strtolower($string));
192
193 $pos = 0;
194
195 foreach ($parts as $key => $part) {
196 $parts[$key] = substr($string, $pos, strlen($part));
197 $pos += strlen($part) + strlen($find);
198 }
199
200 return (join($replace, $parts));
201}
202
f9903ed0 203function read_template($filename, &$var) {
c1d57101 204/// return a (big) string containing the contents of a template file with all
205/// the variables interpolated. all the variables must be in the $var[] array or
206/// object (whatever you decide to use).
207///
208/// WARNING: do not use this on big files!!
f9903ed0 209
b9b8ab69 210 $temp = str_replace("\\", "\\\\", implode(file($filename), ""));
211 $temp = str_replace('"', '\"', $temp);
212 eval("\$template = \"$temp\";");
213 return $template;
f9903ed0 214}
215
216function checked(&$var, $set_value = 1, $unset_value = 0) {
c1d57101 217/// if variable is set, set it to the set_value otherwise set it to the
218/// unset_value. used to handle checkboxes when you are expecting them from
219/// a form
f9903ed0 220
b9b8ab69 221 if (empty($var)) {
222 $var = $unset_value;
223 } else {
224 $var = $set_value;
225 }
f9903ed0 226}
227
228function frmchecked(&$var, $true_value = "checked", $false_value = "") {
c1d57101 229/// prints the word "checked" if a variable is true, otherwise prints nothing,
230/// used for printing the word "checked" in a checkbox form input
f9903ed0 231
b9b8ab69 232 if ($var) {
233 echo $true_value;
234 } else {
235 echo $false_value;
236 }
f9903ed0 237}
238
239
65cf9fc3 240function link_to_popup_window ($url, $name="popup", $linkname="click here", $height=400, $width=500, $title="Popup window") {
c1d57101 241/// This will create a HTML link that will work on both
242/// Javascript and non-javascript browsers.
243/// Relies on the Javascript function openpopup in javascript.php
244/// $url must be relative to home page eg /mod/survey/stuff.php
f9903ed0 245
ff80e012 246 global $CFG;
247
b9b8ab69 248 echo "\n<SCRIPT language=\"Javascript\">";
f9903ed0 249 echo "\n<!--";
ef49e5c3 250 echo "\ndocument.write('<A TITLE=\"$title\" HREF=javascript:openpopup(\"$url\",\"$name\",\"$height\",\"$width\") >".addslashes($linkname)."</A>');";
f9903ed0 251 echo "\n//-->";
b9b8ab69 252 echo "\n</SCRIPT>";
253 echo "\n<NOSCRIPT>\n<A TARGET=\"$name\" TITLE=\"$title\" HREF=\"$CFG->wwwroot/$url\">$linkname</A>\n</NOSCRIPT>\n";
f9903ed0 254
255}
256
257function close_window_button() {
c1d57101 258/// Prints a simple button to close a window
259
f9903ed0 260 echo "<FORM><CENTER>";
e5dfd0f3 261 echo "<INPUT TYPE=button onClick=\"self.close();\" VALUE=\"".get_string("closewindow")."\">";
f9903ed0 262 echo "</CENTER></FORM>";
263}
264
265
08056730 266function choose_from_menu ($options, $name, $selected="", $nothing="choose", $script="", $nothingvalue="0", $return=false) {
c1d57101 267/// Given an array of value, creates a popup menu to be part of a form
268/// $options["value"]["label"]
f9903ed0 269
618b22c5 270 if ($nothing == "choose") {
271 $nothing = get_string("choose")."...";
272 }
273
f9903ed0 274 if ($script) {
275 $javascript = "onChange=\"$script\"";
9c9f7d77 276 } else {
277 $javascript = "";
f9903ed0 278 }
9c9f7d77 279
08056730 280 $output = "<SELECT NAME=$name $javascript>\n";
bda8d43a 281 if ($nothing) {
08056730 282 $output .= " <OPTION VALUE=\"$nothingvalue\"\n";
bda8d43a 283 if ($nothingvalue == $selected) {
08056730 284 $output .= " SELECTED";
bda8d43a 285 }
08056730 286 $output .= ">$nothing</OPTION>\n";
873960de 287 }
607809b3 288 if (!empty($options)) {
289 foreach ($options as $value => $label) {
290 $output .= " <OPTION VALUE=\"$value\"";
291 if ($value == $selected) {
292 $output .= " SELECTED";
293 }
294 if ($label) {
295 $output .= ">$label</OPTION>\n";
296 } else {
297 $output .= ">$value</OPTION>\n";
298 }
f9903ed0 299 }
300 }
08056730 301 $output .= "</SELECT>\n";
302
303 if ($return) {
304 return $output;
305 } else {
306 echo $output;
307 }
f9903ed0 308}
309
d897cae4 310function popup_form ($common, $options, $formname, $selected="", $nothing="choose", $help="", $helptext="", $return=false) {
c1d57101 311/// Implements a complete little popup form
312/// $common = the URL up to the point of the variable that changes
313/// $options = A list of value-label pairs for the popup list
314/// $formname = name must be unique on the page
315/// $selected = the option that is already selected
316/// $nothing = The label for the "no choice" option
e5dfd0f3 317/// $help = The name of a help page if help is required
318/// $helptext = The name of the label for the help button
f9903ed0 319
0d0baabf 320 global $CFG;
321
618b22c5 322 if ($nothing == "choose") {
323 $nothing = get_string("choose")."...";
324 }
325
dfec7b01 326 $startoutput = "<form target=\"{$CFG->framename}\" name=$formname>";
2bc269fd 327 $output = "<select name=popup onchange=\"top.location=document.$formname.popup.options[document.$formname.popup.selectedIndex].value\">\n";
f9903ed0 328
329 if ($nothing != "") {
dfec7b01 330 $output .= " <option value=\"javascript:void(0)\">$nothing</option>\n";
f9903ed0 331 }
332
333 foreach ($options as $value => $label) {
d897cae4 334 if (substr($label,0,1) == "-") {
dfec7b01 335 $output .= " <option value=\"\"";
d897cae4 336 } else {
dfec7b01 337 $output .= " <option value=\"$common$value\"";
d897cae4 338 if ($value == $selected) {
dfec7b01 339 $output .= " selected";
d897cae4 340 }
f9903ed0 341 }
342 if ($label) {
dfec7b01 343 $output .= ">$label</option>\n";
f9903ed0 344 } else {
dfec7b01 345 $output .= ">$value</option>\n";
f9903ed0 346 }
347 }
dfec7b01 348 $output .= "</select>";
349 $output .= "</form>\n";
d897cae4 350
351 if ($return) {
dfec7b01 352 return $startoutput.$output;
d897cae4 353 } else {
dfec7b01 354 echo $startoutput;
9c9f7d77 355 if ($help) {
356 helpbutton($help, $helptext);
357 }
d897cae4 358 echo $output;
359 }
f9903ed0 360}
361
362
363
364function formerr($error) {
c1d57101 365/// Prints some red text
f9903ed0 366 if (!empty($error)) {
367 echo "<font color=#ff0000>$error</font>";
368 }
369}
370
371
372function validate_email ($address) {
c1d57101 373/// Validates an email to make it makes sense.
f9903ed0 374 return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
375 '@'.
376 '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
377 '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
378 $address));
379}
380
6c8e8b5e 381function detect_munged_arguments($string) {
382 if (ereg("\.\.", $string)) { // check for parent URLs
383 return true;
384 }
385 if (ereg("\|", $string)) { // check for pipes
386 return true;
387 }
388 if (ereg("\'", $string)) { // check for backquotes
389 return true;
390 }
391 return false;
392}
393
6ed3da1d 394function get_slash_arguments($file="file.php") {
395/// Searches the current environment variables for some slash arguments
f9903ed0 396
eaa50dbc 397 if (!$string = me()) {
f9903ed0 398 return false;
399 }
eaa50dbc 400
6ed3da1d 401 $pathinfo = explode($file, $string);
402
bcdfe14e 403 if (!empty($pathinfo[1])) {
404 return $pathinfo[1];
6ed3da1d 405 } else {
406 return false;
407 }
408}
409
410function parse_slash_arguments($string, $i=0) {
411/// Extracts arguments from "/foo/bar/something"
412/// eg http://mysite.com/script.php/foo/bar/something
f9903ed0 413
6c8e8b5e 414 if (detect_munged_arguments($string)) {
780db230 415 return false;
416 }
6ed3da1d 417 $args = explode("/", $string);
f9903ed0 418
419 if ($i) { // return just the required argument
420 return $args[$i];
421
422 } else { // return the whole array
423 array_shift($args); // get rid of the empty first one
424 return $args;
425 }
426}
427
0095d5cd 428function format_text_menu() {
c1d57101 429/// Just returns an array of formats suitable for a popup menu
0095d5cd 430 return array (FORMAT_MOODLE => get_string("formattext"),
6901fa79 431 FORMAT_HTML => get_string("formathtml"),
d342c763 432 FORMAT_PLAIN => get_string("formatplain"),
433 FORMAT_WIKI => get_string("formatwiki"));
0095d5cd 434}
435
60f18531 436function format_text($text, $format=FORMAT_MOODLE, $options=NULL) {
c1d57101 437/// Given text in a variety of format codings, this function returns
438/// the text as safe HTML.
439///
440/// $text is raw text (originally from a user)
441/// $format is one of the format constants, defined above
0095d5cd 442
443 switch ($format) {
73f8658c 444 case FORMAT_HTML:
5f350e8f 445 replace_smilies($text);
73f8658c 446 return $text;
447 break;
448
6901fa79 449 case FORMAT_PLAIN:
450 $text = htmlentities($text);
5f350e8f 451 replace_smilies($text);
452 convert_urls_into_links($text);
6901fa79 453 $text = nl2br($text);
454 return $text;
455 break;
456
d342c763 457 case FORMAT_WIKI:
458 $text = wiki_to_html($text);
5f350e8f 459 replace_smilies($text);
d342c763 460 return $text;
461 break;
462
463
73f8658c 464 default: // FORMAT_MOODLE or anything else
c9dda990 465 if (!isset($options->smiley)) {
466 $options->smiley=true;
467 }
468 if (!isset($options->para)) {
1a072208 469 $options->para=true;
c9dda990 470 }
0095d5cd 471 return text_to_html($text, $options->smiley, $options->para);
472 break;
0095d5cd 473 }
474}
475
d342c763 476function format_text_email($text, $format) {
477/// Given text in a variety of format codings, this function returns
478/// the text as plain text suitable for plain email.
479///
480/// $text is raw text (originally from a user)
481/// $format is one of the format constants, defined above
482
483 switch ($format) {
484
485 case FORMAT_PLAIN:
486 return $text;
487 break;
488
489 case FORMAT_WIKI:
490 $text = wiki_to_html($text);
491 return strip_tags($text);
492 break;
493
494 default: // FORMAT_MOODLE or anything else
495 // Need to add something in here to create a text-friendly way of presenting URLs
496 return strip_tags($text);
497 break;
498 }
499}
0095d5cd 500
501function clean_text($text, $format) {
c1d57101 502/// Given raw text (eg typed in by a user), this function cleans it up
503/// and removes any nasty tags that could mess up Moodle pages.
b7a3cf49 504
3fe3851d 505 global $JAVASCRIPT_TAGS, $ALLOWED_TAGS;
506
d342c763 507 switch ($format) {
0095d5cd 508 case FORMAT_MOODLE:
0095d5cd 509 case FORMAT_HTML:
d342c763 510 case FORMAT_WIKI:
3fe3851d 511 $text = strip_tags($text, $ALLOWED_TAGS);
512 foreach ($JAVASCRIPT_TAGS as $tag) {
513 $text = stri_replace($tag, "", $text);
514 }
515 return $text;
6901fa79 516
517 case FORMAT_PLAIN:
518 return $text;
0095d5cd 519 }
b7a3cf49 520}
f9903ed0 521
5f350e8f 522function replace_smilies(&$text) {
c1d57101 523/// Replaces all known smileys in the text with image equivalents
2ea9027b 524 global $CFG;
c1d57101 525
617778f2 526 static $runonce = false;
69081931 527 static $e = array();
528 static $img = array();
617778f2 529 static $emoticons = array(
2ea9027b 530 ':-)' => 'smiley.gif',
531 ':)' => 'smiley.gif',
532 ':-D' => 'biggrin.gif',
533 ';-)' => 'wink.gif',
534 ':-/' => 'mixed.gif',
535 'V-.' => 'thoughtful.gif',
536 ':-P' => 'tongueout.gif',
537 'B-)' => 'cool.gif',
538 '^-)' => 'approve.gif',
539 '8-)' => 'wideeyes.gif',
540 ':o)' => 'clown.gif',
541 ':-(' => 'sad.gif',
542 ':(' => 'sad.gif',
543 '8-.' => 'shy.gif',
544 ':-I' => 'blush.gif',
545 ':-X' => 'kiss.gif',
546 '8-o' => 'surprise.gif',
547 'P-|' => 'blackeye.gif',
548 '8-[' => 'angry.gif',
549 'xx-P' => 'dead.gif',
550 '|-.' => 'sleepy.gif',
551 '}-]' => 'evil.gif',
552 );
553
01d79966 554 if ($runonce == false){
617778f2 555 foreach ($emoticons as $emoticon => $image){
69081931 556 $e[] = $emoticon;
01d79966 557 $img[] = "<img alt=\"$emoticon\" width=15 height=15 src=\"$CFG->wwwroot/pix/s/$image\">";
617778f2 558 }
559 $runonce = true;
c0f728ba 560 }
b7a3cf49 561
5f350e8f 562 $text = str_replace($e, $img, $text);
1a072208 563}
0095d5cd 564
909f539d 565function text_to_html($text, $smiley=true, $para=true) {
c1d57101 566/// Given plain text, makes it into HTML as nicely as possible.
567/// May contain HTML tags already
f9903ed0 568
c1d57101 569/// Remove any whitespace that may be between HTML tags
7b3be1b1 570 $text = eregi_replace(">([[:space:]]+)<", "><", $text);
571
c1d57101 572/// Remove any returns that precede or follow HTML tags
0eae8049 573 $text = eregi_replace("([\n\r])<", " <", $text);
574 $text = eregi_replace(">([\n\r])", "> ", $text);
7b3be1b1 575
5f350e8f 576 convert_urls_into_links($text);
f9903ed0 577
c1d57101 578/// Make returns into HTML newlines.
f9903ed0 579 $text = nl2br($text);
580
c1d57101 581/// Turn smileys into images.
d69cb7f4 582 if ($smiley) {
5f350e8f 583 replace_smilies($text);
d69cb7f4 584 }
f9903ed0 585
c1d57101 586/// Wrap the whole thing in a paragraph tag if required
909f539d 587 if ($para) {
01d79966 588 return "<p>".$text."</p>";
909f539d 589 } else {
590 return $text;
591 }
f9903ed0 592}
593
3e9ca9fb 594function wiki_to_html($text) {
01d79966 595/// Given Wiki formatted text, make it into XHTML using external function
3e9ca9fb 596
01d79966 597 require_once('wiki.php');
3e9ca9fb 598
01d79966 599 $wiki = new Wiki;
600 return $wiki->format($text);
3e9ca9fb 601}
602
5f350e8f 603function convert_urls_into_links(&$text) {
604/// Given some text, it converts any URLs it finds into HTML links.
605
606/// Make lone URLs into links. eg http://moodle.com/
607 $text = eregi_replace("([[:space:]]|^|\(|\[|\<)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
608 "\\1<a href=\"\\2://\\3\\4\" TARGET=\"newpage\">\\2://\\3\\4</a>", $text);
609
610/// eg www.moodle.com
611 $text = eregi_replace("([[:space:]]|^|\(|\[|\<)www\.([^[:space:]]*)([[:alnum:]#?/&=])",
612 "\\1<a href=\"http://www.\\2\\3\" TARGET=\"newpage\">www.\\2\\3</a>", $text);
613}
614
5af78ed2 615function highlight($needle, $haystack) {
c1d57101 616/// This function will highlight instances of $needle in $haystack
5af78ed2 617
618 $parts = explode(strtolower($needle), strtolower($haystack));
619
620 $pos = 0;
621
622 foreach ($parts as $key => $part) {
623 $parts[$key] = substr($haystack, $pos, strlen($part));
624 $pos += strlen($part);
625
626 $parts[$key] .= "<SPAN CLASS=highlight>".substr($haystack, $pos, strlen($needle))."</SPAN>";
627 $pos += strlen($needle);
628 }
629
630 return (join('', $parts));
631}
632
f9903ed0 633
9fa49e22 634
635/// STANDARD WEB PAGE PARTS ///////////////////////////////////////////////////
636
637function print_header ($title="", $heading="", $navigation="", $focus="", $meta="", $cache=true, $button="&nbsp;", $menu="") {
638// $title - appears top of window
639// $heading - appears top of page
640// $navigation - premade navigation string
641// $focus - indicates form element eg inputform.password
642// $meta - meta tags in the header
643// $cache - should this page be cacheable?
644// $button - HTML code for a button (usually for module editing)
645// $menu - HTML code for a popup menu
e825f279 646 global $USER, $CFG, $THEME, $SESSION;
9fa49e22 647
648 if (file_exists("$CFG->dirroot/theme/$CFG->theme/styles.php")) {
649 $styles = $CFG->stylesheet;
650 } else {
651 $styles = "$CFG->wwwroot/theme/standard/styles.php";
652 }
653
654 if ($navigation == "home") {
655 $home = true;
656 $navigation = "";
9d378732 657 } else {
658 $home = false;
9fa49e22 659 }
660
661 if ($button == "") {
662 $button = "&nbsp;";
663 }
664
665 if (!$menu and $navigation) {
666 if (isset($USER->id)) {
107b010b 667 $menu = "<font size=2><a target=_parent href=\"$CFG->wwwroot/login/logout.php\">".get_string("logout")."</a></font>";
9fa49e22 668 } else {
107b010b 669 $menu = "<font size=2><a target=_parent href=\"$CFG->wwwroot/login/index.php\">".get_string("login")."</a></font>";
9fa49e22 670 }
671 }
672
673 // Specify character set ... default is iso-8859-1 but some languages might need something else
674 // Could be optimised by carrying the charset variable around in $USER
675 if (current_language() == "en") {
107b010b 676 $meta = "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n$meta\n";
9fa49e22 677 } else {
107b010b 678 $meta = "<meta http-equiv=\"content-type\" content=\"text/html; charset=".get_string("thischarset")."\">\n$meta\n";
9fa49e22 679 }
680
681 if ($CFG->langdir == "RTL") {
107b010b 682 $direction = " dir=\"rtl\"";
9fa49e22 683 } else {
107b010b 684 $direction = " dir=\"ltr\"";
9fa49e22 685 }
686
687 if (!$cache) { // Do everything we can to prevent clients and proxies caching
688 @header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
689 @header("Pragma: no-cache");
690 $meta .= "\n<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">";
691 $meta .= "\n<META HTTP-EQUIV=\"Expires\" CONTENT=\"0\">";
692 }
693
694 include ("$CFG->dirroot/theme/$CFG->theme/header.html");
695}
696
697function print_footer ($course=NULL) {
698// Can provide a course object to make the footer contain a link to
699// to the course home page, otherwise the link will go to the site home
700 global $USER, $CFG, $THEME;
701
702
703/// Course links
704 if ($course) {
705 if ($course == "home") { // special case for site home page - please do not remove
9a9a2907 706 $homelink = "<P ALIGN=center><A TITLE=\"Moodle $CFG->release ($CFG->version)\" HREF=\"http://moodle.com/\" TARGET=\"_blank\">";
9fa49e22 707 $homelink .= "<BR><IMG WIDTH=130 HEIGHT=19 SRC=\"pix/madewithmoodle2.gif\" BORDER=0></A></P>";
708 $course = get_site();
709 $homepage = true;
710 } else {
f82c2d42 711 $homelink = "<A TARGET=\"{$CFG->framename}\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A>";
9fa49e22 712 }
713 } else {
f82c2d42 714 $homelink = "<A TARGET=\"{$CFG->framename}\" HREF=\"$CFG->wwwroot\">".get_string("home")."</A>";
9fa49e22 715 $course = get_site();
716 }
717
718/// User links
a282d0ff 719 $loggedinas = user_login_string($course, $USER);
720
721 include ("$CFG->dirroot/theme/$CFG->theme/footer.html");
722}
723
724
725function user_login_string($course, $user=NULL) {
726 global $USER, $CFG;
727
728 if (!$user) {
729 $user = $USER;
730 }
731
732 if (isset($user->realuser)) {
733 if ($realuser = get_record("user", "id", $user->realuser)) {
ca16eaeb 734 $realuserinfo = " [<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&return=$realuser->id\">$realuser->firstname $realuser->lastname</A>] ";
9fa49e22 735 }
9d378732 736 } else {
737 $realuserinfo = "";
9fa49e22 738 }
739
a282d0ff 740 if (isset($user->id) and $user->id) {
ca16eaeb 741 $username = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</a>";
9fa49e22 742 $loggedinas = $realuserinfo.get_string("loggedinas", "moodle", "$username").
ca16eaeb 743 " (<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/login/logout.php\">".get_string("logout")."</a>)";
9fa49e22 744 } else {
745 $loggedinas = get_string("loggedinnot", "moodle").
ca16eaeb 746 " (<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/login/index.php\">".get_string("login")."</a>)";
9fa49e22 747 }
a282d0ff 748 return $loggedinas;
9fa49e22 749}
750
751
9fa49e22 752function print_navigation ($navigation) {
753 global $CFG;
754
755 if ($navigation) {
756 if (! $site = get_site()) {
757 $site->shortname = get_string("home");;
758 }
eb347b6b 759 echo "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/\">$site->shortname</a> -> $navigation";
9fa49e22 760 }
761}
762
763function print_heading($text, $align="CENTER", $size=3) {
7d8f674d 764 echo "<P ALIGN=\"$align\"><FONT SIZE=\"$size\"><B>".stripslashes_safe($text)."</B></FONT></P>";
9fa49e22 765}
766
767function print_heading_with_help($text, $helppage, $module="moodle") {
768// Centered heading with attached help button (same title text)
eb347b6b 769 echo "<p align=\"center\"><font size=\"3\"><b>".stripslashes_safe($text);
9fa49e22 770 helpbutton($helppage, $text, $module);
eb347b6b 771 echo "</b></font></p>";
9fa49e22 772}
773
774function print_continue($link) {
9fa49e22 775
776 if (!$link) {
607809b3 777 $link = $_SERVER["HTTP_REFERER"];
9fa49e22 778 }
779
eb347b6b 780 print_heading("<a href=\"$link\">".get_string("continue")."</a>");
9fa49e22 781}
782
783
784function print_simple_box($message, $align="", $width="", $color="#FFFFFF", $padding=5, $class="generalbox") {
785 print_simple_box_start($align, $width, $color, $padding, $class);
7d8f674d 786 echo stripslashes_safe($message);
9fa49e22 787 print_simple_box_end();
788}
789
790function print_simple_box_start($align="", $width="", $color="#FFFFFF", $padding=5, $class="generalbox") {
791 global $THEME;
792
793 if ($align) {
9d378732 794 $align = "ALIGN=\"$align\"";
9fa49e22 795 }
796 if ($width) {
9d378732 797 $width = "WIDTH=\"$width\"";
9fa49e22 798 }
9d378732 799 echo "<table $align $width class=\"$class\" border=\"0\" cellpadding=\"$padding\" cellspacing=\"0\"><tr><td bgcolor=\"$color\" class=\"$class"."content\">";
9fa49e22 800}
801
802function print_simple_box_end() {
803 echo "</td></tr></table>";
804}
805
806function print_single_button($link, $options, $label="OK") {
807 echo "<FORM ACTION=\"$link\" METHOD=GET>";
808 if ($options) {
809 foreach ($options as $name => $value) {
810 echo "<INPUT TYPE=hidden NAME=\"$name\" VALUE=\"$value\">";
811 }
812 }
813 echo "<INPUT TYPE=submit VALUE=\"$label\"></FORM>";
814}
815
816function print_spacer($height=1, $width=1, $br=true) {
817 global $CFG;
818 echo "<IMG HEIGHT=\"$height\" WIDTH=\"$width\" SRC=\"$CFG->wwwroot/pix/spacer.gif\" ALT=\"\">";
819 if ($br) {
820 echo "<BR \>\n";
821 }
822}
823
824function print_file_picture($path, $courseid=0, $height="", $width="", $link="") {
825// Given the path to a picture file in a course, or a URL,
826// this function includes the picture in the page.
827 global $CFG;
828
829 if ($height) {
830 $height = "HEIGHT=\"$height\"";
831 }
832 if ($width) {
833 $width = "WIDTH=\"$width\"";
834 }
835 if ($link) {
836 echo "<A HREF=\"$link\">";
837 }
838 if (substr(strtolower($path), 0, 7) == "http://") {
839 echo "<IMG BORDER=0 $height $width SRC=\"$path\">";
840
841 } else if ($courseid) {
842 echo "<IMG BORDER=0 $height $width SRC=\"";
843 if ($CFG->slasharguments) { // Use this method if possible for better caching
844 echo "$CFG->wwwroot/file.php/$courseid/$path";
845 } else {
3f396065 846 echo "$CFG->wwwroot/file.php?file=/$courseid/$path";
9fa49e22 847 }
848 echo "\">";
849 } else {
850 echo "Error: must pass URL or course";
851 }
852 if ($link) {
853 echo "</A>";
854 }
855}
856
857function print_user_picture($userid, $courseid, $picture, $large=false, $returnstring=false, $link=true) {
858 global $CFG;
859
860 if ($link) {
861 $output = "<A HREF=\"$CFG->wwwroot/user/view.php?id=$userid&course=$courseid\">";
862 } else {
863 $output = "";
864 }
865 if ($large) {
866 $file = "f1.jpg";
867 $size = 100;
868 } else {
869 $file = "f2.jpg";
870 $size = 35;
871 }
872 if ($picture) {
873 if ($CFG->slasharguments) { // Use this method if possible for better caching
874 $output .= "<IMG SRC=\"$CFG->wwwroot/user/pix.php/$userid/$file\" BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"\">";
875 } else {
876 $output .= "<IMG SRC=\"$CFG->wwwroot/user/pix.php?file=/$userid/$file\" BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"\">";
877 }
878 } else {
879 $output .= "<IMG SRC=\"$CFG->wwwroot/user/default/$file\" BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"\">";
880 }
881 if ($link) {
882 $output .= "</A>";
883 }
884
885 if ($returnstring) {
886 return $output;
887 } else {
888 echo $output;
889 }
890}
891
892function print_table($table) {
893// Prints a nicely formatted table.
894// $table is an object with several properties.
895// $table->head is an array of heading names.
896// $table->align is an array of column alignments
897// $table->size is an array of column sizes
898// $table->data[] is an array of arrays containing the data.
899// $table->width is an percentage of the page
900// $table->cellpadding padding on each cell
901// $table->cellspacing spacing between cells
902
903 if (isset($table->align)) {
904 foreach ($table->align as $key => $aa) {
905 if ($aa) {
906 $align[$key] = " ALIGN=\"$aa\"";
907 } else {
908 $align[$key] = "";
909 }
910 }
911 }
912 if (isset($table->size)) {
913 foreach ($table->size as $key => $ss) {
914 if ($ss) {
915 $size[$key] = " WIDTH=\"$ss\"";
916 } else {
917 $size[$key] = "";
918 }
919 }
920 }
921
9d378732 922 if (empty($table->width)) {
9fa49e22 923 $table->width = "80%";
924 }
925
9d378732 926 if (empty($table->cellpadding)) {
9fa49e22 927 $table->cellpadding = "5";
928 }
929
9d378732 930 if (empty($table->cellspacing)) {
9fa49e22 931 $table->cellspacing = "1";
932 }
933
934 print_simple_box_start("CENTER", "$table->width", "#FFFFFF", 0);
935 echo "<TABLE WIDTH=100% BORDER=0 valign=top align=center ";
936 echo " cellpadding=\"$table->cellpadding\" cellspacing=\"$table->cellspacing\" class=\"generaltable\">\n";
937
b79f41cd 938 if (!empty($table->head)) {
9fa49e22 939 echo "<TR>";
940 foreach ($table->head as $key => $heading) {
9d378732 941 if (!isset($size[$key])) {
942 $size[$key] = "";
943 }
944 if (!isset($align[$key])) {
945 $align[$key] = "";
946 }
9fa49e22 947 echo "<TH VALIGN=top ".$align[$key].$size[$key]." NOWRAP class=\"generaltableheader\">$heading</TH>";
948 }
949 echo "</TR>\n";
950 }
951
952 foreach ($table->data as $row) {
953 echo "<TR VALIGN=TOP>";
954 foreach ($row as $key => $item) {
9d378732 955 if (!isset($size[$key])) {
956 $size[$key] = "";
957 }
958 if (!isset($align[$key])) {
959 $align[$key] = "";
960 }
9fa49e22 961 echo "<TD ".$align[$key].$size[$key]." class=\"generaltablecell\">$item</TD>";
962 }
963 echo "</TR>\n";
964 }
965 echo "</TABLE>\n";
966 print_simple_box_end();
967
968 return true;
969}
970
971function print_editing_switch($courseid) {
972 global $CFG, $USER;
973
974 if (isteacher($courseid)) {
975 if ($USER->editing) {
976 echo "<A HREF=\"$CFG->wwwroot/course/view.php?id=$courseid&edit=off\">Turn editing off</A>";
977 } else {
978 echo "<A HREF=\"$CFG->wwwroot/course/view.php?id=$courseid&edit=on\">Turn editing on</A>";
979 }
980 }
981}
982
983function print_textarea($richedit, $rows, $cols, $width, $height, $name, $value="") {
7d8f674d 984/// Prints a richtext field or a normal textarea
9fa49e22 985 global $CFG, $THEME;
986
987 if ($richedit) {
988 echo "<object id=richedit style=\"BACKGROUND-COLOR: buttonface\"";
989 echo " data=\"$CFG->wwwroot/lib/rte/richedit.html\"";
990 echo " width=\"$width\" height=\"$height\" ";
991 echo " type=\"text/x-scriptlet\" VIEWASTEXT></object>\n";
992 echo "<TEXTAREA style=\"display:none\" NAME=\"$name\" ROWS=1 COLS=1>";
993 p($value);
994 echo "</TEXTAREA>\n";
995 } else {
996 echo "<TEXTAREA name=\"$name\" rows=\"$rows\" cols=\"$cols\" wrap=virtual>";
997 p($value);
998 echo "</TEXTAREA>\n";
999 }
1000}
1001
1002function print_richedit_javascript($form, $name, $source="no") {
1003 echo "<SCRIPT language=\"JavaScript\" event=\"onload\" for=\"window\">\n";
1004 echo " document.richedit.options = \"history=no;source=$source\";";
1005 echo " document.richedit.docHtml = $form.$name.innerText;";
1006 echo "</SCRIPT>";
1007}
1008
1009
1010function update_course_icon($courseid) {
1011// Used to be an icon, but it's now a simple form button
1012 global $CFG, $USER;
1013
1014 if (isteacher($courseid)) {
9c9f7d77 1015 if (!empty($USER->editing)) {
9fa49e22 1016 $string = get_string("turneditingoff");
1017 $edit = "off";
1018 } else {
1019 $string = get_string("turneditingon");
1020 $edit = "on";
1021 }
1022 return "<FORM TARGET=_parent METHOD=GET ACTION=\"$CFG->wwwroot/course/view.php\">".
1023 "<INPUT TYPE=hidden NAME=id VALUE=\"$courseid\">".
1024 "<INPUT TYPE=hidden NAME=edit VALUE=\"$edit\">".
1025 "<INPUT TYPE=submit VALUE=\"$string\"></FORM>";
1026 }
1027}
1028
1029function update_module_button($moduleid, $courseid, $string) {
1030// Prints the editing button on a module "view" page
1031 global $CFG;
1032
1033 if (isteacher($courseid)) {
1034 $string = get_string("updatethis", "", $string);
1035 return "<FORM TARGET=_parent METHOD=GET ACTION=\"$CFG->wwwroot/course/mod.php\">".
1036 "<INPUT TYPE=hidden NAME=update VALUE=\"$moduleid\">".
1037 "<INPUT TYPE=hidden NAME=return VALUE=\"true\">".
1038 "<INPUT TYPE=submit VALUE=\"$string\"></FORM>";
1039 }
1040}
1041
1042
1043function navmenu($course, $cm=NULL) {
1044// Given a course and a (current) coursemodule
1045// This function returns a small popup menu with all the
1046// course activity modules in it, as a navigation menu
1047// The data is taken from the serialised array stored in
1048// the course record
1049
1050 global $CFG;
1051
1052 if ($cm) {
1053 $cm = $cm->id;
1054 }
1055
1056 if ($course->format == 'weeks') {
1057 $strsection = get_string("week");
1058 } else {
1059 $strsection = get_string("topic");
1060 }
1061
1062 if (!$modinfo = unserialize($course->modinfo)) {
1063 return "";
1064 }
1065 $section = -1;
1066 $selected = "";
1067 foreach ($modinfo as $mod) {
1068 if ($mod->section > 0 and $section <> $mod->section) {
1069 $menu[] = "-------------- $strsection $mod->section --------------";
1070 }
1071 $section = $mod->section;
cf055081 1072 //Only add visible or teacher mods to jumpmenu
1073 if ($mod->visible or isteacher($course->id)) {
1074 $url = "$mod->mod/view.php?id=$mod->cm";
1075 if ($cm == $mod->cm) {
1076 $selected = $url;
1077 }
1078 $mod->name = urldecode($mod->name);
1079 if (strlen($mod->name) > 55) {
1080 $mod->name = substr($mod->name, 0, 50)."...";
1081 }
2a409368 1082 if (!$mod->visible) {
1083 $mod->name = "(".$mod->name.")";
1084 }
cf055081 1085 $menu[$url] = $mod->name;
9fa49e22 1086 }
9fa49e22 1087 }
1088
1089 return popup_form("$CFG->wwwroot/mod/", $menu, "navmenu", $selected, get_string("jumpto"), "", "", true);
1090}
1091
1092
1093
1094function print_date_selector($day, $month, $year, $currenttime=0) {
1095// Currenttime is a default timestamp in GMT
1096// Prints form items with the names $day, $month and $year
1097
1098 if (!$currenttime) {
1099 $currenttime = time();
1100 }
1101 $currentdate = usergetdate($currenttime);
1102
1103 for ($i=1; $i<=31; $i++) {
1104 $days[$i] = "$i";
1105 }
1106 for ($i=1; $i<=12; $i++) {
39e018b3 1107 $months[$i] = userdate(gmmktime(12,0,0,$i,1,2000), "%B");
9fa49e22 1108 }
1109 for ($i=2000; $i<=2010; $i++) {
1110 $years[$i] = $i;
1111 }
47f1da80 1112 choose_from_menu($days, $day, $currentdate['mday'], "");
1113 choose_from_menu($months, $month, $currentdate['mon'], "");
1114 choose_from_menu($years, $year, $currentdate['year'], "");
9fa49e22 1115}
1116
1117function print_time_selector($hour, $minute, $currenttime=0) {
1118// Currenttime is a default timestamp in GMT
1119// Prints form items with the names $hour and $minute
1120
1121 if (!$currenttime) {
1122 $currenttime = time();
1123 }
1124 $currentdate = usergetdate($currenttime);
1125 for ($i=0; $i<=23; $i++) {
1126 $hours[$i] = sprintf("%02d",$i);
1127 }
1128 for ($i=0; $i<=59; $i++) {
1129 $minutes[$i] = sprintf("%02d",$i);
1130 }
47f1da80 1131 choose_from_menu($hours, $hour, $currentdate['hours'], "");
1132 choose_from_menu($minutes, $minute, $currentdate['minutes'], "");
9fa49e22 1133}
1134
1135function error ($message, $link="") {
1136 global $CFG, $SESSION;
1137
1138 print_header(get_string("error"));
1139 echo "<BR>";
1140 print_simple_box($message, "center", "", "#FFBBBB");
1141
1142 if (!$link) {
1143 if ( !empty($SESSION->fromurl) ) {
1144 $link = "$SESSION->fromurl";
1145 unset($SESSION->fromurl);
9fa49e22 1146 } else {
1147 $link = "$CFG->wwwroot";
1148 }
1149 }
1150 print_continue($link);
1151 print_footer();
1152 die;
1153}
1154
1155function helpbutton ($page, $title="", $module="moodle", $image=true, $linktext=false, $text="") {
1156 // $page = the keyword that defines a help page
1157 // $title = the title of links, rollover tips, alt tags etc
1158 // $module = which module is the page defined in
1159 // $image = use a help image for the link? (true/false/"both")
1160 // $text = if defined then this text is used in the page, and
1161 // the $page variable is ignored.
dc0dc7d5 1162 global $CFG, $THEME;
9fa49e22 1163
1164 if ($module == "") {
1165 $module = "moodle";
1166 }
1167
dc0dc7d5 1168 if (empty($THEME->custompix)) {
1169 $icon = "$CFG->wwwroot/pix/help.gif";
1170 } else {
1171 $icon = "$CFG->wwwroot/theme/$CFG->theme/pix/help.gif";
1172 }
1173
9fa49e22 1174 if ($image) {
1175 if ($linktext) {
dc0dc7d5 1176 $linkobject = "$title<img align=\"absmiddle\" border=0 height=17 width=22 alt=\"\" src=\"$icon\">";
9fa49e22 1177 } else {
dc0dc7d5 1178 $linkobject = "<img align=\"absmiddle\" border=0 height=17 width=22 alt=\"$title\" src=\"$icon\">";
9fa49e22 1179 }
1180 } else {
1181 $linkobject = $title;
1182 }
1183 if ($text) {
1184 $url = "/help.php?module=$module&text=".htmlentities(urlencode($text));
1185 } else {
1186 $url = "/help.php?module=$module&file=$page.html";
1187 }
1188 link_to_popup_window ($url, "popup", $linkobject, 400, 500, $title);
1189}
1190
e825f279 1191function emoticonhelpbutton($form, $field) {
1192/// Prints a special help button that is a link to the "live" emoticon popup
1193 global $CFG, $SESSION;
1194
1195 $SESSION->inserttextform = $form;
1196 $SESSION->inserttextfield = $field;
1197 helpbutton("emoticons", get_string("helpemoticons"), "moodle", false, true);
1198 echo "&nbsp;<img src=\"$CFG->wwwroot/pix/s/smiley.gif\" align=\"absmiddle\" width=15 height=15></a>";
1199}
1200
9fa49e22 1201function notice ($message, $link="") {
750ab759 1202 global $CFG, $THEME;
9fa49e22 1203
1204 if (!$link) {
750ab759 1205 if (!empty($_SERVER["HTTP_REFERER"])) {
1206 $link = $_SERVER["HTTP_REFERER"];
1207 } else {
1208 $link = $CFG->wwwroot;
1209 }
9fa49e22 1210 }
1211
01d79966 1212 echo "<br />";
11a876e1 1213 print_simple_box($message, "center", "50%", "$THEME->cellheading", "20", "noticebox");
eb347b6b 1214 print_heading("<a href=\"$link\">".get_string("continue")."</a>");
9fa49e22 1215 print_footer(get_site());
1216 die;
1217}
1218
1219function notice_yesno ($message, $linkyes, $linkno) {
1220 global $THEME;
1221
eb347b6b 1222 print_simple_box_start("center", "60%", "$THEME->cellheading");
1223 echo "<p align=center><font size=3>$message</font></p>";
1224 echo "<p align=center><font size=3><b>";
1225 echo "<a href=\"$linkyes\">".get_string("yes")."</a>";
9fa49e22 1226 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
eb347b6b 1227 echo "<a href=\"$linkno\">".get_string("no")."</a>";
1228 echo "</b></font></p>";
9fa49e22 1229 print_simple_box_end();
1230}
1231
1232function redirect($url, $message="", $delay=0) {
1233// Uses META tags to redirect the user, after printing a notice
1234
c9082a8c 1235 if (empty($message)) {
1236 echo "<META HTTP-EQUIV='Refresh' CONTENT='$delay; URL=$url'>";
1237 } else {
1238 if (! $delay) {
1239 $delay = 3; // There's no point having a message with no delay
1240 }
1241 echo "<META HTTP-EQUIV='Refresh' CONTENT='$delay; URL=$url'>";
9fa49e22 1242 print_header();
1243 echo "<CENTER>";
1244 echo "<P>$message</P>";
1245 echo "<P>( <A HREF=\"$url\">".get_string("continue")."</A> )</P>";
1246 echo "</CENTER>";
1247 }
1248 die;
1249}
1250
99988d1a 1251function notify ($message, $color="red", $align="center") {
1252 echo "<p align=\"$align\"><b><font color=\"$color\">$message</font></b></p>\n";
9fa49e22 1253}
1254
1255
9d5b689c 1256// vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
f9903ed0 1257?>