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