Modifications from Mark (main author) to be more robust with
[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
39dda0fc 40$ALLOWED_TAGS =
4110d37f 41"<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><em><sup><sub><address><cite><blockquote><pre><strike><embed><object><param><acronym><nolink><style>";
3fe3851d 42
43
0095d5cd 44/// Functions
45
3662bce5 46function s($var) {
c1d57101 47/// returns $var with HTML characters (like "<", ">", etc.) properly quoted,
f9903ed0 48
3662bce5 49 if (empty($var)) {
50 return "";
51 }
7d8f674d 52 return htmlSpecialChars(stripslashes_safe($var));
f9903ed0 53}
54
3662bce5 55function p($var) {
c1d57101 56/// prints $var with HTML characters (like "<", ">", etc.) properly quoted,
f9903ed0 57
3662bce5 58 if (empty($var)) {
59 echo "";
60 }
7d8f674d 61 echo htmlSpecialChars(stripslashes_safe($var));
f9903ed0 62}
63
8553b700 64function nvl(&$var, $default="") {
c1d57101 65/// if $var is undefined, return $default, otherwise return $var
8553b700 66
67 return isset($var) ? $var : $default;
68}
f9903ed0 69
70function strip_querystring($url) {
c1d57101 71/// takes a URL and returns it without the querystring portion
f9903ed0 72
b9b8ab69 73 if ($commapos = strpos($url, '?')) {
74 return substr($url, 0, $commapos);
75 } else {
76 return $url;
77 }
f9903ed0 78}
79
80function get_referer() {
c1d57101 81/// returns the URL of the HTTP_REFERER, less the querystring portion
f9903ed0 82
607809b3 83 return strip_querystring(nvl($_SERVER["HTTP_REFERER"]));
f9903ed0 84}
85
c1d57101 86
f9903ed0 87function me() {
c1d57101 88/// returns the name of the current script, WITH the querystring portion.
eaa50dbc 89/// this function is necessary because PHP_SELF and REQUEST_URI and SCRIPT_NAME
c1d57101 90/// return different things depending on a lot of things like your OS, Web
91/// server, and the way PHP is compiled (ie. as a CGI, module, ISAPI, etc.)
f9903ed0 92
607809b3 93 if (!empty($_SERVER["REQUEST_URI"])) {
94 return $_SERVER["REQUEST_URI"];
c1d57101 95
607809b3 96 } else if (!empty($_SERVER["PHP_SELF"])) {
fced815c 97 if (!empty($_SERVER["QUERY_STRING"])) {
98 return $_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"];
99 }
607809b3 100 return $_SERVER["PHP_SELF"];
c1d57101 101
fced815c 102 } else if (!empty($_SERVER["SCRIPT_NAME"])) {
103 if (!empty($_SERVER["QUERY_STRING"])) {
104 return $_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];
105 }
106 return $_SERVER["SCRIPT_NAME"];
107
b9b8ab69 108 } else {
fced815c 109 notify("Warning: Could not find any of these web server variables: \$REQUEST_URI, \$PHP_SELF or \$SCRIPT_NAME");
bcdfe14e 110 return false;
7fbd6b1c 111 }
f9903ed0 112}
113
114
f9903ed0 115function qualified_me() {
c1d57101 116/// like me() but returns a full URL
f9903ed0 117
39e018b3 118 if (!empty($_SERVER["HTTP_HOST"])) {
119 $hostname = $_SERVER["HTTP_HOST"];
120 } else if (!empty($_ENV["HTTP_HOST"])) {
121 $hostname = $_ENV["HTTP_HOST"];
df3fd249 122 } else if (!empty($_SERVER["SERVER_NAME"])) {
123 $hostname = $_SERVER["SERVER_NAME"];
39e018b3 124 } else if (!empty($_ENV["SERVER_NAME"])) {
125 $hostname = $_ENV["SERVER_NAME"];
126 } else {
127 notify("Warning: could not find the name of this server!");
bcdfe14e 128 return false;
c1d57101 129 }
f9903ed0 130
607809b3 131 $protocol = (isset($_SERVER["HTTPS"]) and $_SERVER["HTTPS"] == "on") ? "https://" : "http://";
39e018b3 132 $url_prefix = $protocol.$hostname;
b9b8ab69 133 return $url_prefix . me();
f9903ed0 134}
135
136
a0deb5db 137function match_referer($goodreferer = "") {
138/// returns true if the referer is the same as the goodreferer. If
139/// goodreferer is not specified, use qualified_me as the goodreferer
60f18531 140 global $CFG;
141
ae384ef1 142 if (empty($CFG->secureforms)) { // Don't bother checking referer
60f18531 143 return true;
144 }
f9903ed0 145
ae384ef1 146 if ($goodreferer == "nomatch") { // Don't bother checking referer
a0deb5db 147 return true;
148 }
149
150 if (empty($goodreferer)) {
151 $goodreferer = qualified_me();
c1d57101 152 }
a0deb5db 153 return $goodreferer == get_referer();
f9903ed0 154}
155
36b4f985 156function data_submitted($url="") {
157/// Used on most forms in Moodle to check for data
158/// Returns the data as an object, if it's found.
607809b3 159/// This object can be used in foreach loops without
160/// casting because it's cast to (array) automatically
36b4f985 161///
162/// Checks that submitted POST data exists, and also
163/// checks the referer against the given url (it uses
164/// the current page if none was specified.
165
37208cd2 166 global $CFG;
167
607809b3 168 if (empty($_POST)) {
36b4f985 169 return false;
607809b3 170
36b4f985 171 } else {
172 if (match_referer($url)) {
607809b3 173 return (object)$_POST;
36b4f985 174 } else {
175 if ($CFG->debug > 10) {
176 notice("The form did not come from this page! (referer = ".get_referer().")");
177 }
178 return false;
179 }
180 }
181}
182
7d8f674d 183function stripslashes_safe($string) {
184/// stripslashes() removes ALL backslashes even from strings
185/// so C:\temp becomes C:temp ... this isn't good.
186/// The following should work as a fairly safe replacement
187/// to be called on quoted AND unquoted strings (to be sure)
188
189 $string = str_replace("\\'", "'", $string);
190 $string = str_replace('\\"', '"', $string);
191 $string = str_replace('\\\\', '\\', $string);
192 return $string;
193}
f9903ed0 194
72e4eac6 195if (!function_exists('str_ireplace')) {
7ec2fc00 196 function str_ireplace($find, $replace, $string) {
72e4eac6 197 /// This does a search and replace, ignoring case
3528bae2 198 /// This function is only here versions of PHP older than version 5
199 /// may not have a native version of this function.
200 /// Taken from the PHP manual, by bradhuizenga@softhome.net
7ec2fc00 201
202 if (!is_array($find)) {
203 $find = array($find);
204 }
205
206 if(!is_array($replace)) {
207 if (!is_array($find)) {
208 $replace = array($replace);
209 } else {
210 // this will duplicate the string into an array the size of $find
211 $c = count($find);
212 $rString = $replace;
213 unset($replace);
214 for ($i = 0; $i < $c; $i++) {
215 $replace[$i] = $rString;
216 }
217 }
218 }
219
220 foreach ($find as $fKey => $fItem) {
221 $between = explode(strtolower($fItem),strtolower($string));
222 $pos = 0;
223 foreach($between as $bKey => $bItem) {
224 $between[$bKey] = substr($string,$pos,strlen($bItem));
225 $pos += strlen($bItem) + strlen($fItem);
226 }
227 $string = implode($replace[$fKey],$between);
72e4eac6 228 }
7ec2fc00 229 return ($string);
3fe3851d 230 }
3fe3851d 231}
232
f9903ed0 233function read_template($filename, &$var) {
c1d57101 234/// return a (big) string containing the contents of a template file with all
235/// the variables interpolated. all the variables must be in the $var[] array or
236/// object (whatever you decide to use).
237///
238/// WARNING: do not use this on big files!!
f9903ed0 239
b9b8ab69 240 $temp = str_replace("\\", "\\\\", implode(file($filename), ""));
241 $temp = str_replace('"', '\"', $temp);
242 eval("\$template = \"$temp\";");
243 return $template;
f9903ed0 244}
245
246function checked(&$var, $set_value = 1, $unset_value = 0) {
c1d57101 247/// if variable is set, set it to the set_value otherwise set it to the
248/// unset_value. used to handle checkboxes when you are expecting them from
249/// a form
f9903ed0 250
b9b8ab69 251 if (empty($var)) {
252 $var = $unset_value;
253 } else {
254 $var = $set_value;
255 }
f9903ed0 256}
257
258function frmchecked(&$var, $true_value = "checked", $false_value = "") {
c1d57101 259/// prints the word "checked" if a variable is true, otherwise prints nothing,
260/// used for printing the word "checked" in a checkbox form input
f9903ed0 261
b9b8ab69 262 if ($var) {
263 echo $true_value;
264 } else {
265 echo $false_value;
266 }
f9903ed0 267}
268
269
86aa7ccf 270function link_to_popup_window ($url, $name="popup", $linkname="click here",
b48f834c 271 $height=400, $width=500, $title="Popup window", $options="none") {
c1d57101 272/// This will create a HTML link that will work on both
273/// Javascript and non-javascript browsers.
274/// Relies on the Javascript function openpopup in javascript.php
275/// $url must be relative to home page eg /mod/survey/stuff.php
f9903ed0 276
ff80e012 277 global $CFG;
278
b48f834c 279 if ($options == "none") {
280 $options = "menubar=0,location=0,scrollbars,resizable,width=$width,height=$height";
281 }
86aa7ccf 282 $fullscreen = 0;
f9903ed0 283
55e4b5f9 284 echo "<a target=\"$name\" title=\"$title\" href=\"$CFG->wwwroot$url\" ".
86aa7ccf 285 "onClick=\"return openpopup('$url', '$name', '$options', $fullscreen);\">$linkname</a>\n";
f9903ed0 286}
287
86aa7ccf 288
f9903ed0 289function close_window_button() {
c1d57101 290/// Prints a simple button to close a window
291
86aa7ccf 292 echo "<center>\n";
293 echo "<script>\n";
294 echo "<!--\n";
295 echo "document.write('<form>');\n";
66a51452 296 echo "document.write('<input type=\"button\" onClick=\"self.close();\" value=\"".get_string("closewindow")."\" />');\n";
86aa7ccf 297 echo "document.write('</form>');\n";
298 echo "-->\n";
299 echo "</script>\n";
300 echo "<noscript>\n";
301 echo "<a href=\"".$_SERVER['HTTP_REFERER']."\"><---</a>\n";
302 echo "</noscript>\n";
303 echo "</center>\n";
f9903ed0 304}
305
306
08056730 307function choose_from_menu ($options, $name, $selected="", $nothing="choose", $script="", $nothingvalue="0", $return=false) {
c1d57101 308/// Given an array of value, creates a popup menu to be part of a form
309/// $options["value"]["label"]
f9903ed0 310
618b22c5 311 if ($nothing == "choose") {
312 $nothing = get_string("choose")."...";
313 }
314
f9903ed0 315 if ($script) {
316 $javascript = "onChange=\"$script\"";
9c9f7d77 317 } else {
318 $javascript = "";
f9903ed0 319 }
9c9f7d77 320
66a51452 321 $output = "<select name=\"$name\" $javascript>\n";
bda8d43a 322 if ($nothing) {
76c1650d 323 $output .= " <option value=\"$nothingvalue\"\n";
bda8d43a 324 if ($nothingvalue == $selected) {
66a51452 325 $output .= " selected=\"true\"";
bda8d43a 326 }
76c1650d 327 $output .= ">$nothing</option>\n";
873960de 328 }
607809b3 329 if (!empty($options)) {
330 foreach ($options as $value => $label) {
76c1650d 331 $output .= " <option value=\"$value\"";
607809b3 332 if ($value == $selected) {
66a51452 333 $output .= " selected=\"true\"";
607809b3 334 }
a20c1090 335 if ($label === "") {
76c1650d 336 $output .= ">$value</option>\n";
a20c1090 337 } else {
338 $output .= ">$label</option>\n";
607809b3 339 }
f9903ed0 340 }
341 }
76c1650d 342 $output .= "</select>\n";
08056730 343
344 if ($return) {
345 return $output;
346 } else {
347 echo $output;
348 }
f9903ed0 349}
350
16ef5e78 351function popup_form ($common, $options, $formname, $selected="", $nothing="choose", $help="", $helptext="", $return=false, $targetwindow="self") {
c1d57101 352/// Implements a complete little popup form
353/// $common = the URL up to the point of the variable that changes
354/// $options = A list of value-label pairs for the popup list
355/// $formname = name must be unique on the page
356/// $selected = the option that is already selected
357/// $nothing = The label for the "no choice" option
e5dfd0f3 358/// $help = The name of a help page if help is required
359/// $helptext = The name of the label for the help button
5b472756 360/// $return = Boolean indicating whether the function should return the text
361/// as a string or echo it directly to the page being rendered
f9903ed0 362
0d0baabf 363 global $CFG;
364
618b22c5 365 if ($nothing == "choose") {
366 $nothing = get_string("choose")."...";
367 }
368
66a51452 369 $startoutput = "<form target=\"{$CFG->framename}\" name=\"$formname\">";
370 $output = "<select name=\"popup\" onchange=\"$targetwindow.location=document.$formname.popup.options[document.$formname.popup.selectedIndex].value\">\n";
f9903ed0 371
372 if ($nothing != "") {
dfec7b01 373 $output .= " <option value=\"javascript:void(0)\">$nothing</option>\n";
f9903ed0 374 }
375
376 foreach ($options as $value => $label) {
d897cae4 377 if (substr($label,0,1) == "-") {
dfec7b01 378 $output .= " <option value=\"\"";
d897cae4 379 } else {
dfec7b01 380 $output .= " <option value=\"$common$value\"";
d897cae4 381 if ($value == $selected) {
66a51452 382 $output .= " selected=\"true\"";
d897cae4 383 }
f9903ed0 384 }
385 if ($label) {
dfec7b01 386 $output .= ">$label</option>\n";
f9903ed0 387 } else {
dfec7b01 388 $output .= ">$value</option>\n";
f9903ed0 389 }
390 }
dfec7b01 391 $output .= "</select>";
392 $output .= "</form>\n";
d897cae4 393
394 if ($return) {
dfec7b01 395 return $startoutput.$output;
d897cae4 396 } else {
dfec7b01 397 echo $startoutput;
9c9f7d77 398 if ($help) {
399 helpbutton($help, $helptext);
400 }
d897cae4 401 echo $output;
402 }
f9903ed0 403}
404
405
406
407function formerr($error) {
c1d57101 408/// Prints some red text
f9903ed0 409 if (!empty($error)) {
66a51452 410 echo "<font color=\"#ff0000\">$error</font>";
f9903ed0 411 }
412}
413
414
415function validate_email ($address) {
66a51452 416/// Validates an email to make sure it makes sense.
f9903ed0 417 return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
418 '@'.
419 '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
420 '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
421 $address));
422}
423
6c8e8b5e 424function detect_munged_arguments($string) {
393c9b4f 425 if (ereg('\.\.', $string)) { // check for parent URLs
6c8e8b5e 426 return true;
427 }
393c9b4f 428 if (ereg('[\|\`]', $string)) { // check for other bad characters
6c8e8b5e 429 return true;
430 }
431 return false;
432}
433
6ed3da1d 434function get_slash_arguments($file="file.php") {
435/// Searches the current environment variables for some slash arguments
f9903ed0 436
eaa50dbc 437 if (!$string = me()) {
f9903ed0 438 return false;
439 }
eaa50dbc 440
6ed3da1d 441 $pathinfo = explode($file, $string);
442
bcdfe14e 443 if (!empty($pathinfo[1])) {
444 return $pathinfo[1];
6ed3da1d 445 } else {
446 return false;
447 }
448}
449
450function parse_slash_arguments($string, $i=0) {
451/// Extracts arguments from "/foo/bar/something"
452/// eg http://mysite.com/script.php/foo/bar/something
f9903ed0 453
6c8e8b5e 454 if (detect_munged_arguments($string)) {
780db230 455 return false;
456 }
6ed3da1d 457 $args = explode("/", $string);
f9903ed0 458
459 if ($i) { // return just the required argument
460 return $args[$i];
461
462 } else { // return the whole array
463 array_shift($args); // get rid of the empty first one
464 return $args;
465 }
466}
467
0095d5cd 468function format_text_menu() {
c1d57101 469/// Just returns an array of formats suitable for a popup menu
0095d5cd 470 return array (FORMAT_MOODLE => get_string("formattext"),
6901fa79 471 FORMAT_HTML => get_string("formathtml"),
d342c763 472 FORMAT_PLAIN => get_string("formatplain"),
473 FORMAT_WIKI => get_string("formatwiki"));
0095d5cd 474}
475
60f18531 476function format_text($text, $format=FORMAT_MOODLE, $options=NULL) {
c1d57101 477/// Given text in a variety of format codings, this function returns
478/// the text as safe HTML.
479///
480/// $text is raw text (originally from a user)
481/// $format is one of the format constants, defined above
0095d5cd 482
e67b9e31 483 global $CFG, $course;
a751a4e5 484
0095d5cd 485 switch ($format) {
73f8658c 486 case FORMAT_HTML:
5f350e8f 487 replace_smilies($text);
e67b9e31 488 return filter_text($text);
73f8658c 489 break;
490
6901fa79 491 case FORMAT_PLAIN:
492 $text = htmlentities($text);
3405b212 493 $text = str_replace(" ", "&nbsp; ", $text);
5f350e8f 494 replace_smilies($text);
6901fa79 495 $text = nl2br($text);
496 return $text;
497 break;
498
d342c763 499 case FORMAT_WIKI:
e67b9e31 500 $text = wiki_to_html($text);
501 return filter_text($text);
d342c763 502 break;
503
73f8658c 504 default: // FORMAT_MOODLE or anything else
c9dda990 505 if (!isset($options->smiley)) {
506 $options->smiley=true;
507 }
508 if (!isset($options->para)) {
1a072208 509 $options->para=true;
c9dda990 510 }
e67b9e31 511 $text = text_to_html($text, $options->smiley, $options->para);
512 return filter_text($text);
513
0095d5cd 514 break;
0095d5cd 515 }
516}
517
d342c763 518function format_text_email($text, $format) {
519/// Given text in a variety of format codings, this function returns
520/// the text as plain text suitable for plain email.
521///
522/// $text is raw text (originally from a user)
523/// $format is one of the format constants, defined above
524
525 switch ($format) {
526
527 case FORMAT_PLAIN:
528 return $text;
529 break;
530
531 case FORMAT_WIKI:
532 $text = wiki_to_html($text);
5b472756 533 /// This expression turns links into something nice in a text format. (Russell Jungwirth)
534 /// From: http://php.net/manual/en/function.eregi-replace.php and simplified
535 $text = eregi_replace('(<a [^<]*href=["|\']?([^ "\']*)["|\']?[^>]*>([^<]*)</a>)','\\3 [\\2]', $text);
7c55a29b 536 return strtr(strip_tags($text), array_flip(get_html_translation_table(HTML_ENTITIES)));
d342c763 537 break;
538
6ff45b59 539 case FORMAT_HTML:
540 return html_to_text($text);
541 break;
542
d342c763 543 default: // FORMAT_MOODLE or anything else
5b472756 544 $text = eregi_replace('(<a [^<]*href=["|\']?([^ "\']*)["|\']?[^>]*>([^<]*)</a>)','\\3 [\\2]', $text);
7c55a29b 545 return strtr(strip_tags($text), array_flip(get_html_translation_table(HTML_ENTITIES)));
d342c763 546 break;
547 }
548}
0095d5cd 549
e67b9e31 550
551function filter_text($text) {
552/// Given some text in HTML format, this function will pass it
553/// through any filters that have been defined in $CFG->textfilterx
554/// The variable defines a filepath to a file containing the
555/// filter function. The file must contain a variable called
556/// $textfilter_function which contains the name of the function
557/// with $course->id and $text parameters
558
559 global $CFG, $course; // A dirty hack right now ... should not be assumed global
560
561 if (empty($course->id)) {
562 return $text;
563 }
564
565 for ($i=1; $i<=10; $i++) {
566 $variable = "textfilter$i";
567 if (empty($CFG->$variable)) { /// No more filters
568 return $text;
569 }
570 if (is_readable("$CFG->dirroot/".$CFG->$variable)) {
571 include("$CFG->dirroot/".$CFG->$variable);
572 $text = $textfilter_function($course->id, $text);
573 }
574 }
575 return $text;
576}
577
578
0095d5cd 579function clean_text($text, $format) {
c1d57101 580/// Given raw text (eg typed in by a user), this function cleans it up
581/// and removes any nasty tags that could mess up Moodle pages.
b7a3cf49 582
fc120758 583 global $ALLOWED_TAGS;
3fe3851d 584
d342c763 585 switch ($format) {
0095d5cd 586 case FORMAT_MOODLE:
0095d5cd 587 case FORMAT_HTML:
d342c763 588 case FORMAT_WIKI:
5b472756 589 /// Remove javascript: label
3fe3851d 590 $text = strip_tags($text, $ALLOWED_TAGS);
5b472756 591 /// Remove javascript/VBScript
592 $text = str_ireplace("javascript:", "xxx", $text);
593 /// Remove script events
594 $text = eregi_replace("([^a-z])language([[:space:]]*)=", "xxx", $text);
595 $text = eregi_replace("([^a-z])on([a-z]+)([[:space:]]*)=", "xxx", $text);
3fe3851d 596 return $text;
6901fa79 597
598 case FORMAT_PLAIN:
599 return $text;
0095d5cd 600 }
b7a3cf49 601}
f9903ed0 602
5f350e8f 603function replace_smilies(&$text) {
c1d57101 604/// Replaces all known smileys in the text with image equivalents
2ea9027b 605 global $CFG;
c1d57101 606
5b472756 607/// this builds the mapping array only once
617778f2 608 static $runonce = false;
69081931 609 static $e = array();
610 static $img = array();
617778f2 611 static $emoticons = array(
2ea9027b 612 ':-)' => 'smiley.gif',
613 ':)' => 'smiley.gif',
614 ':-D' => 'biggrin.gif',
615 ';-)' => 'wink.gif',
616 ':-/' => 'mixed.gif',
617 'V-.' => 'thoughtful.gif',
618 ':-P' => 'tongueout.gif',
619 'B-)' => 'cool.gif',
620 '^-)' => 'approve.gif',
621 '8-)' => 'wideeyes.gif',
622 ':o)' => 'clown.gif',
623 ':-(' => 'sad.gif',
624 ':(' => 'sad.gif',
625 '8-.' => 'shy.gif',
626 ':-I' => 'blush.gif',
627 ':-X' => 'kiss.gif',
628 '8-o' => 'surprise.gif',
629 'P-|' => 'blackeye.gif',
630 '8-[' => 'angry.gif',
631 'xx-P' => 'dead.gif',
632 '|-.' => 'sleepy.gif',
633 '}-]' => 'evil.gif',
634 );
635
5b472756 636 /// this is the meat of the code - this is run every time
637 if ($runonce == false){
617778f2 638 foreach ($emoticons as $emoticon => $image){
69081931 639 $e[] = $emoticon;
66a51452 640 $img[] = "<img alt=\"$emoticon\" width=\"15\" height=\"15\" src=\"$CFG->pixpath/s/$image\" />";
617778f2 641 }
642 $runonce = true;
c0f728ba 643 }
b7a3cf49 644
5f350e8f 645 $text = str_replace($e, $img, $text);
1a072208 646}
0095d5cd 647
909f539d 648function text_to_html($text, $smiley=true, $para=true) {
c1d57101 649/// Given plain text, makes it into HTML as nicely as possible.
650/// May contain HTML tags already
f9903ed0 651
27326a3e 652 global $CFG;
653
c1d57101 654/// Remove any whitespace that may be between HTML tags
7b3be1b1 655 $text = eregi_replace(">([[:space:]]+)<", "><", $text);
656
c1d57101 657/// Remove any returns that precede or follow HTML tags
0eae8049 658 $text = eregi_replace("([\n\r])<", " <", $text);
659 $text = eregi_replace(">([\n\r])", "> ", $text);
7b3be1b1 660
5f350e8f 661 convert_urls_into_links($text);
f9903ed0 662
c1d57101 663/// Make returns into HTML newlines.
f9903ed0 664 $text = nl2br($text);
665
c1d57101 666/// Turn smileys into images.
d69cb7f4 667 if ($smiley) {
5f350e8f 668 replace_smilies($text);
d69cb7f4 669 }
f9903ed0 670
c1d57101 671/// Wrap the whole thing in a paragraph tag if required
909f539d 672 if ($para) {
01d79966 673 return "<p>".$text."</p>";
909f539d 674 } else {
675 return $text;
676 }
f9903ed0 677}
678
3e9ca9fb 679function wiki_to_html($text) {
01d79966 680/// Given Wiki formatted text, make it into XHTML using external function
43373804 681 global $CFG;
3e9ca9fb 682
43373804 683 require_once("$CFG->libdir/wiki.php");
3e9ca9fb 684
01d79966 685 $wiki = new Wiki;
686 return $wiki->format($text);
3e9ca9fb 687}
688
6ff45b59 689function html_to_text($html) {
690/// Given HTML text, make it into plain text using external function
428aaa29 691 global $CFG;
6ff45b59 692
693 require_once("$CFG->libdir/html2text.php");
694
695 return html2text($html);
696}
697
698
5f350e8f 699function convert_urls_into_links(&$text) {
700/// Given some text, it converts any URLs it finds into HTML links.
701
702/// Make lone URLs into links. eg http://moodle.com/
3405b212 703 $text = eregi_replace("([[:space:]]|^|\(|\[)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
88438a58 704 "\\1<a href=\"\\2://\\3\\4\" target=\"newpage\">\\2://\\3\\4</a>", $text);
5f350e8f 705
706/// eg www.moodle.com
3405b212 707 $text = eregi_replace("([[:space:]]|^|\(|\[)www\.([^[:space:]]*)([[:alnum:]#?/&=])",
88438a58 708 "\\1<a href=\"http://www.\\2\\3\" target=\"newpage\">www.\\2\\3</a>", $text);
5f350e8f 709}
710
88438a58 711function highlight($needle, $haystack, $case=0,
712 $left_string="<span class=\"highlight\">", $right_string="</span>") {
713/// This function will highlight search words in a given string
714/// It cares about HTML and will not ruin links. It's best to use
715/// this function after performing any conversions to HTML.
716/// Function found here: http://forums.devshed.com/t67822/scdaa2d1c3d4bacb4671d075ad41f0854.html
717
718 $list_of_words = eregi_replace("[^-a-zA-Z0-9&']", " ", $needle);
719 $list_array = explode(" ", $list_of_words);
720 for ($i=0; $i<sizeof($list_array); $i++) {
721 if (strlen($list_array[$i]) == 1) {
722 $list_array[$i] = "";
723 }
724 }
725 $list_of_words = implode(" ", $list_array);
726 $list_of_words_cp = $list_of_words;
727 $final = array();
728 preg_match_all('/<(.+?)>/is',$haystack,$list_of_words);
729
730 foreach (array_unique($list_of_words[0]) as $key=>$value) {
731 $final['<|'.$key.'|>'] = $value;
732 }
733
734 $haystack = str_replace($final,array_keys($final),$haystack);
735 $list_of_words_cp = eregi_replace(" +", "|", $list_of_words_cp);
736
737 if ($list_of_words_cp{0}=="|") {
738 $list_of_words_cp{0} = "";
739 }
740 if ($list_of_words_cp{strlen($list_of_words_cp)-1}=="|") {
741 $list_of_words_cp{strlen($list_of_words_cp)-1}="";
742 }
743 $list_of_words_cp = "(".trim($list_of_words_cp).")";
744
745 if (!$case){
746 $haystack = eregi_replace("$list_of_words_cp", "$left_string"."\\1"."$right_string", $haystack);
747 } else {
748 $haystack = ereg_replace("$list_of_words_cp", "$left_string"."\\1"."$right_string", $haystack);
749 }
750 $haystack = str_replace(array_keys($final),$final,$haystack);
751
752 return stripslashes($haystack);
753}
754
755function highlightfast($needle, $haystack) {
c1d57101 756/// This function will highlight instances of $needle in $haystack
88438a58 757/// It's faster that the above function and doesn't care about
758/// HTML or anything.
5af78ed2 759
760 $parts = explode(strtolower($needle), strtolower($haystack));
761
762 $pos = 0;
763
764 foreach ($parts as $key => $part) {
765 $parts[$key] = substr($haystack, $pos, strlen($part));
766 $pos += strlen($part);
767
88438a58 768 $parts[$key] .= "<span class=\"highlight\">".substr($haystack, $pos, strlen($needle))."</span>";
5af78ed2 769 $pos += strlen($needle);
770 }
771
772 return (join('', $parts));
773}
774
f9903ed0 775
9fa49e22 776/// STANDARD WEB PAGE PARTS ///////////////////////////////////////////////////
777
66a51452 778function print_header ($title="", $heading="", $navigation="", $focus="", $meta="",
779 $cache=true, $button="&nbsp;", $menu="", $usexml=false) {
9fa49e22 780// $title - appears top of window
781// $heading - appears top of page
782// $navigation - premade navigation string
783// $focus - indicates form element eg inputform.password
784// $meta - meta tags in the header
785// $cache - should this page be cacheable?
786// $button - HTML code for a button (usually for module editing)
66a51452 787// $menu - HTML code for a popup menu
788// $usexml - use XML for this page
e825f279 789 global $USER, $CFG, $THEME, $SESSION;
9fa49e22 790
791 if (file_exists("$CFG->dirroot/theme/$CFG->theme/styles.php")) {
792 $styles = $CFG->stylesheet;
793 } else {
794 $styles = "$CFG->wwwroot/theme/standard/styles.php";
795 }
796
797 if ($navigation == "home") {
798 $home = true;
799 $navigation = "";
9d378732 800 } else {
801 $home = false;
9fa49e22 802 }
803
804 if ($button == "") {
805 $button = "&nbsp;";
806 }
807
808 if (!$menu and $navigation) {
809 if (isset($USER->id)) {
66a51452 810 $menu = "<font size=\"2\"><a target=\"$CFG->framename\" href=\"$CFG->wwwroot/login/logout.php\">".get_string("logout")."</a></font>";
9fa49e22 811 } else {
66a51452 812 $menu = "<font size=\"2\"><a target=\"$CFG->framename\" href=\"$CFG->wwwroot/login/index.php\">".get_string("login")."</a></font>";
9fa49e22 813 }
814 }
815
47037513 816 // Add a stylesheet for the HTML editor
817 $meta = "<style type=\"text/css\">@import url($CFG->wwwroot/lib/editor/htmlarea.css);</style>\n$meta\n";
818
9fa49e22 819 // Specify character set ... default is iso-8859-1 but some languages might need something else
820 // Could be optimised by carrying the charset variable around in $USER
821 if (current_language() == "en") {
66a51452 822 $meta = "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\" />\n$meta\n";
9fa49e22 823 } else {
66a51452 824 $meta = "<meta http-equiv=\"content-type\" content=\"text/html; charset=".get_string("thischarset")."\" />\n$meta\n";
9fa49e22 825 }
826
d8152d04 827 if ( get_string("thisdirection") == "rtl" ) {
107b010b 828 $direction = " dir=\"rtl\"";
9fa49e22 829 } else {
107b010b 830 $direction = " dir=\"ltr\"";
9fa49e22 831 }
832
833 if (!$cache) { // Do everything we can to prevent clients and proxies caching
834 @header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
835 @header("Pragma: no-cache");
66a51452 836 $meta .= "\n<meta http-equiv=\"pragma\" content=\"no-cache\" />";
837 $meta .= "\n<meta http-equiv=\"expires\" content=\"0\" />";
838 }
839
840 if ($usexml) { // Added by Gustav Delius / Mad Alex for MathML output
841 $currentlanguage = current_language();
842
843 @header("Content-type: text/xml");
844 echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n";
845 if (!empty($CFG->xml_stylesheets)) {
846 $stylesheets = explode(";", $CFG->xml_stylesheets);
847 foreach ($stylesheets as $stylesheet) {
848 echo "<?xml-stylesheet type=\"text/xsl\" href=\"$CFG->wwwroot/$stylesheet\" ?>\n";
849 }
850 }
851 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1";
e4576482 852 if (!empty($CFG->xml_doctype_extra)) {
66a51452 853 echo " plus $CFG->xml_doctype_extra";
e4576482 854 }
66a51452 855 echo "//" . strtoupper($currentlanguage) . "\" \"$CFG->xml_dtd\">\n";
856 $direction = " xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$currentlanguage\" $direction";
9fa49e22 857 }
858
2eea2cce 859 $title = str_replace('"', '&quot;', $title);
860
9fa49e22 861 include ("$CFG->dirroot/theme/$CFG->theme/header.html");
862}
863
864function print_footer ($course=NULL) {
865// Can provide a course object to make the footer contain a link to
866// to the course home page, otherwise the link will go to the site home
867 global $USER, $CFG, $THEME;
868
869
870/// Course links
871 if ($course) {
872 if ($course == "home") { // special case for site home page - please do not remove
76c1650d 873 $homelink = "<p align=\"center\"><a title=\"moodle $CFG->release ($CFG->version)\" href=\"http://moodle.org/\" target=\"_blank\">";
66a51452 874 $homelink .= "<br /><img width=\"130\" height=\"19\" src=\"pix/madewithmoodle.gif\" border=\"0\" /></a></p>";
9fa49e22 875 $course = get_site();
876 $homepage = true;
877 } else {
76c1650d 878 $homelink = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
9fa49e22 879 }
880 } else {
c2cb4545 881 $homelink = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/\">".get_string("home")."</a>";
9fa49e22 882 $course = get_site();
883 }
884
885/// User links
a282d0ff 886 $loggedinas = user_login_string($course, $USER);
887
888 include ("$CFG->dirroot/theme/$CFG->theme/footer.html");
889}
890
1ddf9329 891function style_sheet_setup($lastmodified=0, $lifetime=300, $themename="") {
892/// This function is called by stylesheets to set up the header
893/// approriately as well as the current path
6535be85 894
895 global $CFG;
896
897 header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
898 header("Expires: " . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT");
899 header("Cache-control: max_age = $lifetime");
900 header("Pragma: ");
901 header("Content-type: text/css"); // Correct MIME type
902
903 if (!empty($themename)) {
904 $CFG->theme = $themename;
905 }
906
907 return "$CFG->wwwroot/theme/$CFG->theme";
908
909}
910
a282d0ff 911
912function user_login_string($course, $user=NULL) {
913 global $USER, $CFG;
914
8d2accb6 915 if (empty($user)) {
a282d0ff 916 $user = $USER;
917 }
918
919 if (isset($user->realuser)) {
920 if ($realuser = get_record("user", "id", $user->realuser)) {
66a51452 921 $realuserinfo = " [<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&amp;return=$realuser->id\">$realuser->firstname $realuser->lastname</a>] ";
9fa49e22 922 }
9d378732 923 } else {
924 $realuserinfo = "";
9fa49e22 925 }
926
a282d0ff 927 if (isset($user->id) and $user->id) {
66a51452 928 $username = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$user->firstname $user->lastname</a>";
9fa49e22 929 $loggedinas = $realuserinfo.get_string("loggedinas", "moodle", "$username").
ca16eaeb 930 " (<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/login/logout.php\">".get_string("logout")."</a>)";
9fa49e22 931 } else {
932 $loggedinas = get_string("loggedinnot", "moodle").
ca16eaeb 933 " (<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/login/index.php\">".get_string("login")."</a>)";
9fa49e22 934 }
a282d0ff 935 return $loggedinas;
9fa49e22 936}
937
938
9fa49e22 939function print_navigation ($navigation) {
940 global $CFG;
941
942 if ($navigation) {
943 if (! $site = get_site()) {
944 $site->shortname = get_string("home");;
945 }
eb347b6b 946 echo "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/\">$site->shortname</a> -> $navigation";
9fa49e22 947 }
948}
949
d4df9200 950function print_headline($text, $size=2) {
951 echo "<b><font size=\"$size\">$text</font></b><br />\n";
952}
953
76c1650d 954function print_heading($text, $align="center", $size=3) {
955 echo "<p align=\"$align\"><font size=\"$size\"><b>".stripslashes_safe($text)."</b></font></p>";
9fa49e22 956}
957
c9f6251e 958function print_heading_with_help($text, $helppage, $module="moodle", $icon="") {
9fa49e22 959// Centered heading with attached help button (same title text)
c9f6251e 960// and optional icon attached
961 echo "<p align=\"center\"><font size=\"3\">$icon<b>".stripslashes_safe($text);
9fa49e22 962 helpbutton($helppage, $text, $module);
eb347b6b 963 echo "</b></font></p>";
9fa49e22 964}
965
966function print_continue($link) {
9fa49e22 967
968 if (!$link) {
607809b3 969 $link = $_SERVER["HTTP_REFERER"];
9fa49e22 970 }
971
eb347b6b 972 print_heading("<a href=\"$link\">".get_string("continue")."</a>");
9fa49e22 973}
974
975
976function print_simple_box($message, $align="", $width="", $color="#FFFFFF", $padding=5, $class="generalbox") {
977 print_simple_box_start($align, $width, $color, $padding, $class);
7d8f674d 978 echo stripslashes_safe($message);
9fa49e22 979 print_simple_box_end();
980}
981
982function print_simple_box_start($align="", $width="", $color="#FFFFFF", $padding=5, $class="generalbox") {
983 global $THEME;
984
985 if ($align) {
76c1650d 986 $align = "align=\"$align\"";
9fa49e22 987 }
988 if ($width) {
76c1650d 989 $width = "width=\"$width\"";
9fa49e22 990 }
9d378732 991 echo "<table $align $width class=\"$class\" border=\"0\" cellpadding=\"$padding\" cellspacing=\"0\"><tr><td bgcolor=\"$color\" class=\"$class"."content\">";
9fa49e22 992}
993
994function print_simple_box_end() {
995 echo "</td></tr></table>";
996}
997
cc7fa0dc 998function print_single_button($link, $options, $label="OK", $method="get") {
999 echo "<form action=\"$link\" method=\"$method\">";
9fa49e22 1000 if ($options) {
1001 foreach ($options as $name => $value) {
66a51452 1002 echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />";
9fa49e22 1003 }
1004 }
66a51452 1005 echo "<input type=\"submit\" value=\"$label\" /></form>";
9fa49e22 1006}
1007
1008function print_spacer($height=1, $width=1, $br=true) {
1009 global $CFG;
66a51452 1010 echo "<img height=\"$height\" width=\"$width\" src=\"$CFG->wwwroot/pix/spacer.gif\" alt=\"\" />";
9fa49e22 1011 if ($br) {
76c1650d 1012 echo "<br />\n";
9fa49e22 1013 }
1014}
1015
1016function print_file_picture($path, $courseid=0, $height="", $width="", $link="") {
1017// Given the path to a picture file in a course, or a URL,
1018// this function includes the picture in the page.
1019 global $CFG;
1020
1021 if ($height) {
76c1650d 1022 $height = "height=\"$height\"";
9fa49e22 1023 }
1024 if ($width) {
76c1650d 1025 $width = "width=\"$width\"";
9fa49e22 1026 }
1027 if ($link) {
76c1650d 1028 echo "<a href=\"$link\">";
9fa49e22 1029 }
1030 if (substr(strtolower($path), 0, 7) == "http://") {
66a51452 1031 echo "<img border=\"0\" $height $width src=\"$path\" />";
9fa49e22 1032
1033 } else if ($courseid) {
66a51452 1034 echo "<img border=\"0\" $height $width src=\"";
9fa49e22 1035 if ($CFG->slasharguments) { // Use this method if possible for better caching
1036 echo "$CFG->wwwroot/file.php/$courseid/$path";
1037 } else {
3f396065 1038 echo "$CFG->wwwroot/file.php?file=/$courseid/$path";
9fa49e22 1039 }
66a51452 1040 echo "\" />";
9fa49e22 1041 } else {
1042 echo "Error: must pass URL or course";
1043 }
1044 if ($link) {
76c1650d 1045 echo "</a>";
9fa49e22 1046 }
1047}
1048
1049function print_user_picture($userid, $courseid, $picture, $large=false, $returnstring=false, $link=true) {
67a63a30 1050 global $CFG, $THEME;
9fa49e22 1051
1052 if ($link) {
66a51452 1053 $output = "<a href=\"$CFG->wwwroot/user/view.php?id=$userid&amp;course=$courseid\">";
9fa49e22 1054 } else {
1055 $output = "";
1056 }
1057 if ($large) {
67a63a30 1058 $file = "f1";
9fa49e22 1059 $size = 100;
1060 } else {
67a63a30 1061 $file = "f2";
9fa49e22 1062 $size = 35;
1063 }
67a63a30 1064 if ($picture) { // Print custom user picture
9fa49e22 1065 if ($CFG->slasharguments) { // Use this method if possible for better caching
67a63a30 1066 $output .= "<img align=\"absmiddle\" src=\"$CFG->wwwroot/user/pix.php/$userid/$file.jpg\"".
66a51452 1067 " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
9fa49e22 1068 } else {
67a63a30 1069 $output .= "<img align=\"absmiddle\" src=\"$CFG->wwwroot/user/pix.php?file=/$userid/$file.jpg\"".
66a51452 1070 " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
9fa49e22 1071 }
67a63a30 1072 } else { // Print default user pictures (use theme version if available)
c9f6251e 1073 $output .= "<img align=\"absmiddle\" src=\"$CFG->pixpath/u/$file.png\"".
66a51452 1074 " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
9fa49e22 1075 }
1076 if ($link) {
76c1650d 1077 $output .= "</a>";
9fa49e22 1078 }
1079
1080 if ($returnstring) {
1081 return $output;
1082 } else {
1083 echo $output;
1084 }
1085}
1086
1087function print_table($table) {
1088// Prints a nicely formatted table.
1089// $table is an object with several properties.
1090// $table->head is an array of heading names.
1091// $table->align is an array of column alignments
1092// $table->size is an array of column sizes
5867bfb5 1093// $table->wrap is an array of "nowrap"s or nothing
9fa49e22 1094// $table->data[] is an array of arrays containing the data.
1095// $table->width is an percentage of the page
1096// $table->cellpadding padding on each cell
1097// $table->cellspacing spacing between cells
1098
1099 if (isset($table->align)) {
1100 foreach ($table->align as $key => $aa) {
1101 if ($aa) {
76c1650d 1102 $align[$key] = " align=\"$aa\"";
9fa49e22 1103 } else {
1104 $align[$key] = "";
1105 }
1106 }
1107 }
1108 if (isset($table->size)) {
1109 foreach ($table->size as $key => $ss) {
1110 if ($ss) {
76c1650d 1111 $size[$key] = " width=\"$ss\"";
9fa49e22 1112 } else {
1113 $size[$key] = "";
1114 }
1115 }
1116 }
5867bfb5 1117 if (isset($table->wrap)) {
1118 foreach ($table->wrap as $key => $ww) {
1119 if ($ww) {
66a51452 1120 $wrap[$key] = " nowrap=\"nowrap\" ";
5867bfb5 1121 } else {
1122 $wrap[$key] = "";
1123 }
1124 }
1125 }
9fa49e22 1126
9d378732 1127 if (empty($table->width)) {
9fa49e22 1128 $table->width = "80%";
1129 }
1130
9d378732 1131 if (empty($table->cellpadding)) {
9fa49e22 1132 $table->cellpadding = "5";
1133 }
1134
9d378732 1135 if (empty($table->cellspacing)) {
9fa49e22 1136 $table->cellspacing = "1";
1137 }
1138
5867bfb5 1139 print_simple_box_start("center", "$table->width", "#ffffff", 0);
66a51452 1140 echo "<table width=\"100%\" border=\"0\" valign=\"top\" align=\"center\" ";
9fa49e22 1141 echo " cellpadding=\"$table->cellpadding\" cellspacing=\"$table->cellspacing\" class=\"generaltable\">\n";
1142
b79f41cd 1143 if (!empty($table->head)) {
5867bfb5 1144 echo "<tr>";
9fa49e22 1145 foreach ($table->head as $key => $heading) {
9d378732 1146 if (!isset($size[$key])) {
1147 $size[$key] = "";
1148 }
1149 if (!isset($align[$key])) {
1150 $align[$key] = "";
1151 }
66a51452 1152 echo "<th valign=\"top\" ".$align[$key].$size[$key]." nowrap=\"nowrap\" class=\"generaltableheader\">$heading</th>";
9fa49e22 1153 }
66a51452 1154 echo "</tr>\n";
9fa49e22 1155 }
1156
a1f8ff87 1157 if (!empty($table->data)) {
1158 foreach ($table->data as $row) {
1159 echo "<tr valign=\"top\">";
1160 foreach ($row as $key => $item) {
1161 if (!isset($size[$key])) {
1162 $size[$key] = "";
1163 }
1164 if (!isset($align[$key])) {
1165 $align[$key] = "";
1166 }
1167 if (!isset($wrap[$key])) {
1168 $wrap[$key] = "";
1169 }
1170 echo "<td ".$align[$key].$size[$key].$wrap[$key]." class=\"generaltablecell\">$item</td>";
1171 }
1172 echo "</tr>\n";
9fa49e22 1173 }
9fa49e22 1174 }
5867bfb5 1175 echo "</table>\n";
9fa49e22 1176 print_simple_box_end();
1177
1178 return true;
1179}
1180
2f4d324b 1181function make_table($table) {
1182// Creates a nicely formatted table and returns it
1183// $table is an object with several properties.
1184// $table->head is an array of heading names.
1185// $table->align is an array of column alignments
1186// $table->size is an array of column sizes
1187// $table->wrap is an array of "nowrap"s or nothing
1188// $table->data[] is an array of arrays containing the data.
1189// $table->width is an percentage of the page
1190// $table->class is a class
1191// $table->fontsize is the size of all the text
1192// $table->tablealign align the whole table
1193// $table->cellpadding padding on each cell
1194// $table->cellspacing spacing between cells
1195
1196 if (isset($table->align)) {
1197 foreach ($table->align as $key => $aa) {
1198 if ($aa) {
1199 $align[$key] = " align=\"$aa\"";
1200 } else {
1201 $align[$key] = "";
1202 }
1203 }
1204 }
1205 if (isset($table->size)) {
1206 foreach ($table->size as $key => $ss) {
1207 if ($ss) {
1208 $size[$key] = " width=\"$ss\"";
1209 } else {
1210 $size[$key] = "";
1211 }
1212 }
1213 }
1214 if (isset($table->wrap)) {
1215 foreach ($table->wrap as $key => $ww) {
1216 if ($ww) {
66a51452 1217 $wrap[$key] = " nowrap=\"nowrap\" ";
2f4d324b 1218 } else {
1219 $wrap[$key] = "";
1220 }
1221 }
1222 }
1223
1224 if (empty($table->width)) {
1225 $table->width = "80%";
1226 }
1227
1228 if (empty($table->tablealign)) {
1229 $table->tablealign = "center";
1230 }
1231
1232 if (empty($table->cellpadding)) {
1233 $table->cellpadding = "5";
1234 }
1235
1236 if (empty($table->cellspacing)) {
1237 $table->cellspacing = "1";
1238 }
1239
1240 if (empty($table->class)) {
1241 $table->class = "generaltable";
1242 }
1243
1244 if (empty($table->fontsize)) {
1245 $fontsize = "";
1246 } else {
1247 $fontsize = "<font size=\"$table->fontsize\">";
1248 }
1249
66a51452 1250 $output = "<table width=\"$table->width\" valign=\"top\" align=\"$table->tablealign\" ";
2f4d324b 1251 $output .= " cellpadding=\"$table->cellpadding\" cellspacing=\"$table->cellspacing\" class=\"$table->class\">\n";
1252
1253 if (!empty($table->head)) {
1254 $output .= "<tr>";
1255 foreach ($table->head as $key => $heading) {
1256 if (!isset($size[$key])) {
1257 $size[$key] = "";
1258 }
1259 if (!isset($align[$key])) {
1260 $align[$key] = "";
1261 }
66a51452 1262 $output .= "<th valign=\"top\" ".$align[$key].$size[$key]." nowrap=\"nowrap\" class=\"{$table->class}header\">$fontsize$heading</th>";
2f4d324b 1263 }
1264 $output .= "</tr>\n";
1265 }
1266
1267 foreach ($table->data as $row) {
66a51452 1268 $output .= "<tr valign=\"top\">";
2f4d324b 1269 foreach ($row as $key => $item) {
1270 if (!isset($size[$key])) {
1271 $size[$key] = "";
1272 }
1273 if (!isset($align[$key])) {
1274 $align[$key] = "";
1275 }
1276 if (!isset($wrap[$key])) {
1277 $wrap[$key] = "";
1278 }
1279 $output .= "<td ".$align[$key].$size[$key].$wrap[$key]." class=\"{$table->class}cell\">$fontsize$item</td>";
1280 }
1281 $output .= "</tr>\n";
1282 }
1283 $output .= "</table>\n";
1284
1285 return $output;
1286}
1287
47037513 1288function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value="", $courseid=0) {
1289/// Prints a basic textarea field
1290/// $width and height are legacy fields and no longer used
4c46c425 1291
47037513 1292 global $CFG, $course;
50bdc74d 1293
408e62f8 1294 if (empty($courseid)) {
50bdc74d 1295 if (!empty($course->id)) { // search for it in global context
1296 $courseid = $course->id;
1297 }
1298 }
9fa49e22 1299
47037513 1300 if ($usehtmleditor) {
1301 if (!empty($courseid) and isteacher($courseid)) {
1302 echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/htmlarea.php?id=$courseid\"></script>\n";
1303 } else {
1304 echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/htmlarea.php\"></script>\n";
1305 }
1306 echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/dialog.js\"></script>\n";
1307 echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/lang/en.php\"></script>\n";
1308 echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/popupwin.js\"></script>\n";
50bdc74d 1309
47037513 1310 if ($rows < 20) {
1311 $rows = 20;
1312 }
1313 if ($cols < 65) {
1314 $cols = 65;
4c46c425 1315 }
9fa49e22 1316 }
47037513 1317
1318 echo "<textarea id=\"$name\" name=\"$name\" rows=\"$rows\" cols=\"$cols\" wrap=\"virtual\">";
1319 p($value);
1320 echo "</textarea>\n";
9fa49e22 1321}
1322
1323function print_richedit_javascript($form, $name, $source="no") {
47037513 1324/// Legacy function, provided for backward compatability
1325 use_html_editor($name);
1326}
1327
1328function use_html_editor($name="") {
1329/// Sets up the HTML editor on textareas in the current page.
1330/// If a field name is provided, then it will only be
1331/// applied to that field - otherwise it will be used
1332/// on every textarea in the page.
1333///
1334/// In most cases no arguments need to be supplied
4c46c425 1335
47037513 1336 echo "<script language=\"javascript\" type=\"text/javascript\" defer=\"1\">\n";
1337 if (empty($name)) {
1338 echo "HTMLArea.replaceAll();";
1339 } else {
1340 echo "HTMLArea.replace('$name')";
4c46c425 1341 }
47037513 1342 echo "</script>";
9fa49e22 1343}
1344
1345
1346function update_course_icon($courseid) {
1347// Used to be an icon, but it's now a simple form button
1348 global $CFG, $USER;
1349
b6c12732 1350 if (isteacheredit($courseid)) {
9c9f7d77 1351 if (!empty($USER->editing)) {
9fa49e22 1352 $string = get_string("turneditingoff");
1353 $edit = "off";
1354 } else {
1355 $string = get_string("turneditingon");
1356 $edit = "on";
1357 }
66a51452 1358 return "<form target=\"_parent\" method=\"get\" action=\"$CFG->wwwroot/course/view.php\">".
1359 "<input type=\"hidden\" name=\"id\" value=\"$courseid\" />".
1360 "<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
1361 "<input type=\"submit\" value=\"$string\" /></form>";
9fa49e22 1362 }
1363}
1364
1365function update_module_button($moduleid, $courseid, $string) {
1366// Prints the editing button on a module "view" page
1367 global $CFG;
1368
b6c12732 1369 if (isteacheredit($courseid)) {
9fa49e22 1370 $string = get_string("updatethis", "", $string);
66a51452 1371 return "<form target=\"_parent\" method=\"get\" action=\"$CFG->wwwroot/course/mod.php\">".
1372 "<input type=\"hidden\" name=\"update\" value=\"$moduleid\" />".
1373 "<input type=\"hidden\" name=\"return\" value=\"true\" />".
1374 "<input type=\"submit\" value=\"$string\" /></form>";
b6c12732 1375 } else {
1376 return "";
9fa49e22 1377 }
1378}
1379
c2cb4545 1380function update_category_button($categoryid) {
d2b6ba70 1381// Prints the editing button on a category page
1382 global $CFG, $USER;
c2cb4545 1383
d2b6ba70 1384 if (iscreator()) {
1385 if (!empty($USER->editing)) {
1386 $string = get_string("turneditingoff");
1387 $edit = "off";
1388 } else {
1389 $string = get_string("turneditingon");
1390 $edit = "on";
9b16d1ea 1391 }
66a51452 1392 return "<form method=\"get\" action=\"$CFG->wwwroot/course/category.php\">".
1393 "<input type=\"hidden\" name=\"id\" value=\"$categoryid\" />".
1394 "<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
1395 "<input type=\"submit\" value=\"$string\" /></form>";
d2b6ba70 1396 }
1397}
1398
1399function update_categories_button() {
1400// Prints the editing button on categories listing
1401 global $CFG, $USER;
1402
1403 if (isadmin()) {
1404 if (!empty($USER->editing)) {
1405 $string = get_string("turneditingoff");
1406 $edit = "off";
1407 } else {
1408 $string = get_string("turneditingon");
1409 $edit = "on";
1410 }
66a51452 1411 return "<form target=\"_parent\" method=\"get\" action=\"$CFG->wwwroot/course/index.php\">".
1412 "<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
1413 "<input type=\"submit\" value=\"$string\" /></form>";
c2cb4545 1414 }
1415}
9fa49e22 1416
16ef5e78 1417function navmenu($course, $cm=NULL, $targetwindow="self") {
9fa49e22 1418// Given a course and a (current) coursemodule
1419// This function returns a small popup menu with all the
1420// course activity modules in it, as a navigation menu
1421// The data is taken from the serialised array stored in
1422// the course record
1423
1424 global $CFG;
1425
1426 if ($cm) {
1427 $cm = $cm->id;
1428 }
1429
1430 if ($course->format == 'weeks') {
1431 $strsection = get_string("week");
1432 } else {
1433 $strsection = get_string("topic");
1434 }
1435
1436 if (!$modinfo = unserialize($course->modinfo)) {
1437 return "";
1438 }
1439 $section = -1;
1440 $selected = "";
1441 foreach ($modinfo as $mod) {
ab2df10c 1442 if ($mod->mod == "label") {
1443 continue;
1444 }
9fa49e22 1445 if ($mod->section > 0 and $section <> $mod->section) {
1446 $menu[] = "-------------- $strsection $mod->section --------------";
1447 }
1448 $section = $mod->section;
cf055081 1449 //Only add visible or teacher mods to jumpmenu
1450 if ($mod->visible or isteacher($course->id)) {
1451 $url = "$mod->mod/view.php?id=$mod->cm";
1452 if ($cm == $mod->cm) {
1453 $selected = $url;
1454 }
1455 $mod->name = urldecode($mod->name);
1456 if (strlen($mod->name) > 55) {
1457 $mod->name = substr($mod->name, 0, 50)."...";
1458 }
2a409368 1459 if (!$mod->visible) {
1460 $mod->name = "(".$mod->name.")";
1461 }
cf055081 1462 $menu[$url] = $mod->name;
9fa49e22 1463 }
9fa49e22 1464 }
1465
16ef5e78 1466 return popup_form("$CFG->wwwroot/mod/", $menu, "navmenu", $selected, get_string("jumpto"),
1467 "", "", true, $targetwindow);
9fa49e22 1468}
1469
1470
1471
1472function print_date_selector($day, $month, $year, $currenttime=0) {
1473// Currenttime is a default timestamp in GMT
1474// Prints form items with the names $day, $month and $year
1475
1476 if (!$currenttime) {
1477 $currenttime = time();
1478 }
1479 $currentdate = usergetdate($currenttime);
1480
1481 for ($i=1; $i<=31; $i++) {
1482 $days[$i] = "$i";
1483 }
1484 for ($i=1; $i<=12; $i++) {
39e018b3 1485 $months[$i] = userdate(gmmktime(12,0,0,$i,1,2000), "%B");
9fa49e22 1486 }
1487 for ($i=2000; $i<=2010; $i++) {
1488 $years[$i] = $i;
1489 }
47f1da80 1490 choose_from_menu($days, $day, $currentdate['mday'], "");
1491 choose_from_menu($months, $month, $currentdate['mon'], "");
1492 choose_from_menu($years, $year, $currentdate['year'], "");
9fa49e22 1493}
1494
1495function print_time_selector($hour, $minute, $currenttime=0) {
1496// Currenttime is a default timestamp in GMT
1497// Prints form items with the names $hour and $minute
1498
1499 if (!$currenttime) {
1500 $currenttime = time();
1501 }
1502 $currentdate = usergetdate($currenttime);
1503 for ($i=0; $i<=23; $i++) {
1504 $hours[$i] = sprintf("%02d",$i);
1505 }
1506 for ($i=0; $i<=59; $i++) {
1507 $minutes[$i] = sprintf("%02d",$i);
1508 }
47f1da80 1509 choose_from_menu($hours, $hour, $currentdate['hours'], "");
1510 choose_from_menu($minutes, $minute, $currentdate['minutes'], "");
9fa49e22 1511}
1512
d6bdd9d5 1513function print_grade_menu($courseid, $name, $current, $includenograde=true) {
62ca135d 1514/// Prints a grade menu (as part of an existing form) with help
1515/// Showing all possible numerical grades and scales
1516
c9f6251e 1517 global $CFG;
62ca135d 1518
1519 $strscale = get_string("scale");
1520 $strscales = get_string("scales");
1521
1f7deef6 1522 $scales = get_scales_menu($courseid);
62ca135d 1523 foreach ($scales as $i => $scalename) {
1524 $grades[-$i] = "$strscale: $scalename";
1525 }
d6bdd9d5 1526 if ($includenograde) {
1527 $grades[0] = get_string("nograde");
1528 }
62ca135d 1529 for ($i=100; $i>=1; $i--) {
1530 $grades[$i] = $i;
1531 }
1532 choose_from_menu($grades, "$name", "$current", "");
1533
c9f6251e 1534 $helpicon = "$CFG->pixpath/help.gif";
66a51452 1535 $linkobject = "<img align=\"absmiddle\" border=\"0\" height=\"17\" width=\"22\" alt=\"$strscales\" src=\"$helpicon\" />";
1536 link_to_popup_window ("/course/scales.php?id=$courseid&amp;list=true", "ratingscales",
62ca135d 1537 $linkobject, 400, 500, $strscales);
1538}
1539
02ebf404 1540function print_scale_menu($courseid, $name, $current) {
1541/// Prints a scale menu (as part of an existing form) including help button
62ca135d 1542/// Just like print_grade_menu but without the numerical grades
02ebf404 1543
c9f6251e 1544 global $CFG;
02ebf404 1545
1546 $strscales = get_string("scales");
1547 choose_from_menu(get_scales_menu($courseid), "$name", $current, "");
c9f6251e 1548 $helpicon = "$CFG->pixpath/help.gif";
66a51452 1549 $linkobject = "<img align=\"absmiddle\" border=\"0\" height=\"17\" width=\"22\" alt=\"$strscales\" src=\"$helpicon\" />";
1550 link_to_popup_window ("/course/scales.php?id=$courseid&amp;list=true", "ratingscales",
02ebf404 1551 $linkobject, 400, 500, $strscales);
1552}
1553
fdc47ee6 1554
02ebf404 1555function print_scale_menu_helpbutton($courseid, $scale) {
1556/// Prints a help button about a scale
1557/// scale is an object
1558
c9f6251e 1559 global $CFG;
02ebf404 1560
1561 $strscales = get_string("scales");
c9f6251e 1562 $helpicon = "$CFG->pixpath/help.gif";
66a51452 1563 $linkobject = "<img align=\"absmiddle\" border=\"0\" height=\"17\" width=\"22\" alt=\"$scale->name\" src=\"$helpicon\" />";
1564 link_to_popup_window ("/course/scales.php?id=$courseid&amp;list=true&amp;scale=$scale->id", "ratingscale",
02ebf404 1565 $linkobject, 400, 500, $scale->name);
1566}
1567
1568
9fa49e22 1569function error ($message, $link="") {
1570 global $CFG, $SESSION;
1571
1572 print_header(get_string("error"));
66a51452 1573 echo "<br />";
9fa49e22 1574 print_simple_box($message, "center", "", "#FFBBBB");
1575
1576 if (!$link) {
1577 if ( !empty($SESSION->fromurl) ) {
1578 $link = "$SESSION->fromurl";
1579 unset($SESSION->fromurl);
9fa49e22 1580 } else {
c2cb4545 1581 $link = "$CFG->wwwroot/";
9fa49e22 1582 }
1583 }
1584 print_continue($link);
1585 print_footer();
1586 die;
1587}
1588
1589function helpbutton ($page, $title="", $module="moodle", $image=true, $linktext=false, $text="") {
1590 // $page = the keyword that defines a help page
1591 // $title = the title of links, rollover tips, alt tags etc
1592 // $module = which module is the page defined in
1593 // $image = use a help image for the link? (true/false/"both")
1594 // $text = if defined then this text is used in the page, and
1595 // the $page variable is ignored.
dc0dc7d5 1596 global $CFG, $THEME;
9fa49e22 1597
1598 if ($module == "") {
1599 $module = "moodle";
1600 }
1601
1602 if ($image) {
c9f6251e 1603 $icon = "$CFG->pixpath/help.gif";
9fa49e22 1604 if ($linktext) {
7fc0f9e5 1605 $linkobject = "<span style=\"cursor:help;\">$title<img align=\"absmiddle\" border=\"0\" ".
1606 " height=\"17\" width=\"22\" alt=\"\" src=\"$icon\" /></span>";
9fa49e22 1607 } else {
7fc0f9e5 1608 $linkobject = "<img align=\"absmiddle\" border=\"0\" height=\"17\" width=\"22\" ".
1609 " alt=\"$title\" style=\"cursor:help;\" src=\"$icon\" />";
9fa49e22 1610 }
1611 } else {
7fc0f9e5 1612 $linkobject = "<span style=\"cursor:help;\">$title</span>";
9fa49e22 1613 }
1614 if ($text) {
66a51452 1615 $url = "/help.php?module=$module&amp;text=".htmlentities(urlencode($text));
9fa49e22 1616 } else {
66a51452 1617 $url = "/help.php?module=$module&amp;file=$page.html";
9fa49e22 1618 }
1619 link_to_popup_window ($url, "popup", $linkobject, 400, 500, $title);
1620}
1621
e825f279 1622function emoticonhelpbutton($form, $field) {
1623/// Prints a special help button that is a link to the "live" emoticon popup
1624 global $CFG, $SESSION;
1625
1626 $SESSION->inserttextform = $form;
1627 $SESSION->inserttextfield = $field;
1628 helpbutton("emoticons", get_string("helpemoticons"), "moodle", false, true);
c9f6251e 1629 echo "&nbsp;";
66a51452 1630 link_to_popup_window ("/help.php?module=moodle&amp;file=emoticons.html", "popup",
1631 "<img src=\"$CFG->pixpath/s/smiley.gif\" border=\"0\" align=\"absmiddle\" width=\"15\" height=\"15\" />",
c9f6251e 1632 400, 500, get_string("helpemoticons"));
1633 echo "<br />";
e825f279 1634}
1635
9fa49e22 1636function notice ($message, $link="") {
750ab759 1637 global $CFG, $THEME;
9fa49e22 1638
1639 if (!$link) {
750ab759 1640 if (!empty($_SERVER["HTTP_REFERER"])) {
1641 $link = $_SERVER["HTTP_REFERER"];
1642 } else {
c2cb4545 1643 $link = "$CFG->wwwroot/";
750ab759 1644 }
9fa49e22 1645 }
1646
01d79966 1647 echo "<br />";
11a876e1 1648 print_simple_box($message, "center", "50%", "$THEME->cellheading", "20", "noticebox");
eb347b6b 1649 print_heading("<a href=\"$link\">".get_string("continue")."</a>");
9fa49e22 1650 print_footer(get_site());
1651 die;
1652}
1653
1654function notice_yesno ($message, $linkyes, $linkno) {
1655 global $THEME;
1656
eb347b6b 1657 print_simple_box_start("center", "60%", "$THEME->cellheading");
66a51452 1658 echo "<p align=\"center\"><font size=\"3\">$message</font></p>";
1659 echo "<p align=\"center\"><font size=\"3\"><b>";
eb347b6b 1660 echo "<a href=\"$linkyes\">".get_string("yes")."</a>";
9fa49e22 1661 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
eb347b6b 1662 echo "<a href=\"$linkno\">".get_string("no")."</a>";
1663 echo "</b></font></p>";
9fa49e22 1664 print_simple_box_end();
1665}
1666
559573a2 1667function redirect($url, $message="", $delay="0") {
5d6c043a 1668// Redirects the user to another page, after printing a notice
9fa49e22 1669
c9082a8c 1670 if (empty($message)) {
2b23eea3 1671 echo "<meta http-equiv=\"refresh\" content=\"$delay; url=$url\" />";
8a55c984 1672 echo "<script>location.replace('$url');</script>"; // To cope with Mozilla bug
c9082a8c 1673 } else {
05c19593 1674 if (empty($delay)) {
c9082a8c 1675 $delay = 3; // There's no point having a message with no delay
1676 }
5f546a46 1677 print_header("", "", "", "", "<meta http-equiv=\"refresh\" content=\"$delay; url=$url\" />");
76c1650d 1678 echo "<center>";
1679 echo "<p>$message</p>";
1680 echo "<p>( <a href=\"$url\">".get_string("continue")."</a> )</p>";
1681 echo "</center>";
ff019455 1682 flush();
1683 sleep($delay);
1684 echo "<script>location.replace('$url');</script>"; // To cope with Mozilla bug
9fa49e22 1685 }
1686 die;
1687}
1688
99988d1a 1689function notify ($message, $color="red", $align="center") {
1690 echo "<p align=\"$align\"><b><font color=\"$color\">$message</font></b></p>\n";
9fa49e22 1691}
1692
43373804 1693function obfuscate_email($email) {
1694/// Given an email address, this function will return an obfuscated version of it
1695 $i = 0;
1696 $length = strlen($email);
1697 $obfuscated = "";
1698 while ($i < $length) {
1699 if (rand(0,2)) {
1700 $obfuscated.='%'.dechex(ord($email{$i}));
1701 } else {
1702 $obfuscated.=$email{$i};
1703 }
1704 $i++;
1705 }
1706 return $obfuscated;
1707}
1708
1709function obfuscate_text($plaintext) {
1710/// This function takes some text and replaces about half of the characters
1711/// with HTML entity equivalents. Return string is obviously longer.
1712 $i=0;
1713 $length = strlen($plaintext);
1714 $obfuscated="";
2b09e377 1715 $prev_obfuscated = false;
43373804 1716 while ($i < $length) {
2b09e377 1717 $c = ord($plaintext{$i});
1718 $numerical = ($c >= ord('0')) && ($c <= ord('9'));
1719 if ($prev_obfuscated and $numerical ) {
1720 $obfuscated.='&#'.ord($plaintext{$i});
1721 } else if (rand(0,2)) {
43373804 1722 $obfuscated.='&#'.ord($plaintext{$i});
2b09e377 1723 $prev_obfuscated = true;
43373804 1724 } else {
1725 $obfuscated.=$plaintext{$i};
2b09e377 1726 $prev_obfuscated = false;
43373804 1727 }
2b09e377 1728 $i++;
43373804 1729 }
1730 return $obfuscated;
1731}
1732
1733function obfuscate_mailto($email, $label="") {
1734/// This function uses the above two functions to generate a fully
1735/// obfuscated email link, ready to use.
1736
1737 if (empty($label)) {
1738 $label = $email;
1739 }
1740 return sprintf('<a href="%s:%s" title="%s">%s</a>', obfuscate_text('mailto'),
1741 obfuscate_email($email),
1742 obfuscate_text($email),
1743 obfuscate_text($label));
1744}
1745
8b9c7aa0 1746function print_paging_bar($totalcount, $page, $perpage, $baseurl) {
1747/// Prints a single paging bar to provide access to other pages (usually in a search)
1748
519d369f 1749 $maxdisplay = 18;
8ef9cb56 1750
8b9c7aa0 1751 if ($totalcount > $perpage) {
f04dc61d 1752 echo "<center>";
1753 echo "<p>".get_string("page").":";
be20753e 1754 $lastpage = ceil($totalcount / $perpage);
1755 if ($page > 15) {
1756 $startpage = $page - 10;
519d369f 1757 echo "&nbsp<a href=\"{$baseurl}page=0\">1</a>&nbsp;...";
be20753e 1758 } else {
1759 $startpage = 0;
1760 }
be20753e 1761 $currpage = $startpage;
1762 $displaycount = 0;
1763 while ($displaycount < $maxdisplay and $currpage < $lastpage) {
1764 $displaypage = $currpage+1;
1765 if ($page == $currpage) {
8b9c7aa0 1766 echo "&nbsp;&nbsp;$displaypage";
1767 } else {
be20753e 1768 echo "&nbsp;&nbsp;<a href=\"{$baseurl}page=$currpage\">$displaypage</a>";
e27dbcc8 1769 }
be20753e 1770 $displaycount++;
1771 $currpage++;
8b9c7aa0 1772 }
924cef21 1773 if ($currpage < $lastpage) {
519d369f 1774 $lastpageactual = $lastpage - 1;
1775 echo "&nbsp;...<a href=\"{$baseurl}page=$lastpageactual\">$lastpage</a>&nbsp;";
924cef21 1776 }
8b9c7aa0 1777 $pagenum = $page + 1;
be20753e 1778 if ($pagenum != $displaypage) {
8b9c7aa0 1779 echo "&nbsp;&nbsp;(<a href=\"{$baseurl}page=$pagenum\">".get_string("next")."</a>)";
1780 }
1781 echo "</p>";
be20753e 1782 echo "</center>";
8b9c7aa0 1783 }
1784}
9fa49e22 1785
9d5b689c 1786// vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
f9903ed0 1787?>