2001-11-22 06:23:56 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// weblib.php - functions for web output
|
2001-11-22 06:23:56 +00:00
|
|
|
//
|
2002-12-20 14:44:14 +00:00
|
|
|
// Library of all general-purpose Moodle PHP functions and constants
|
|
|
|
// that produce HTML output
|
2001-11-22 06:23:56 +00:00
|
|
|
//
|
2002-12-20 14:44:14 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
|
|
// NOTICE OF COPYRIGHT //
|
|
|
|
// //
|
|
|
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
|
|
|
// http://moodle.com //
|
|
|
|
// //
|
|
|
|
// Copyright (C) 2001-2003 Martin Dougiamas http://dougiamas.com //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License for more details: //
|
|
|
|
// //
|
|
|
|
// http://www.gnu.org/copyleft/gpl.html //
|
|
|
|
// //
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-10-10 07:26:10 +00:00
|
|
|
/// Constants
|
|
|
|
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Define text formatting types ... eventually we can add Wiki, BBcode etc
|
2002-10-10 07:26:10 +00:00
|
|
|
define("FORMAT_MOODLE", "0");
|
|
|
|
define("FORMAT_HTML", "1");
|
|
|
|
|
2002-10-12 03:53:40 +00:00
|
|
|
$SMILEY_TEXT[] = ":-)";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\":-)\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/smiley.gif\">";
|
|
|
|
$SMILEY_TEXT[] = ":)";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\":-)\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/smiley.gif\">";
|
|
|
|
$SMILEY_TEXT[] = ":-D";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\":-D\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/biggrin.gif\">";
|
|
|
|
$SMILEY_TEXT[] = ";-)";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\";-)\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/wink.gif\">";
|
|
|
|
$SMILEY_TEXT[] = ":-/";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\":-/\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/mixed.gif\">";
|
|
|
|
$SMILEY_TEXT[] = "V-.";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\"V-.\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/thoughtful.gif\">";
|
|
|
|
$SMILEY_TEXT[] = ":-P";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\":-P\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/tongueout.gif\">";
|
|
|
|
$SMILEY_TEXT[] = "B-)";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\"B-)\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/cool.gif\">";
|
|
|
|
$SMILEY_TEXT[] = "^-)";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\"^-)\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/approve.gif\">";
|
|
|
|
$SMILEY_TEXT[] = "8-)";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\"8-)\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/wideeyes.gif\">";
|
|
|
|
$SMILEY_TEXT[] = ":o)";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\":o)\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/clown.gif\">";
|
|
|
|
$SMILEY_TEXT[] = ":-(";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\":-(\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/sad.gif\">";
|
|
|
|
$SMILEY_TEXT[] = ":(";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\":-(\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/sad.gif\">";
|
|
|
|
$SMILEY_TEXT[] = "8-.";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\"8-.\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/shy.gif\">";
|
|
|
|
$SMILEY_TEXT[] = ":-I";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\":-I\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/blush.gif\">";
|
|
|
|
$SMILEY_TEXT[] = ":-X";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\":-X\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/kiss.gif\">";
|
|
|
|
$SMILEY_TEXT[] = "8-o";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\"8-o\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/surprise.gif\">";
|
|
|
|
$SMILEY_TEXT[] = "P-|";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\"P-|\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/blackeye.gif\">";
|
|
|
|
$SMILEY_TEXT[] = "8-[";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\"8-[\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/angry.gif\">";
|
|
|
|
$SMILEY_TEXT[] = "xx-P";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\"xx-P\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/dead.gif\">";
|
|
|
|
$SMILEY_TEXT[] = "|-.";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\"|-.\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/sleepy.gif\">";
|
|
|
|
$SMILEY_TEXT[] = "}-]";
|
|
|
|
$SMILEY_IMAGE[] = "<IMG ALT=\"}-]\" WIDTH=15 HEIGHT=15 SRC=\"$CFG->wwwroot/pix/s/evil.gif\">";
|
2002-10-10 07:26:10 +00:00
|
|
|
|
2002-10-18 09:09:19 +00:00
|
|
|
$JAVASCRIPT_TAGS = array("javascript:", "onclick=", "ondblclick=", "onkeydown=", "onkeypress=", "onkeyup=",
|
|
|
|
"onmouseover=", "onmouseout=", "onmousedown=", "onmouseup=",
|
|
|
|
"onblur=", "onfocus=", "onload=", "onselect=");
|
|
|
|
|
2002-12-30 13:02:21 +00:00
|
|
|
$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>";
|
2002-10-18 09:09:19 +00:00
|
|
|
|
|
|
|
|
2002-10-10 07:26:10 +00:00
|
|
|
/// Functions
|
|
|
|
|
2002-07-11 05:30:57 +00:00
|
|
|
function s($var) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// returns $var with HTML characters (like "<", ">", etc.) properly quoted,
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
return htmlSpecialChars(stripslashes($var));
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function p($var) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// prints $var with HTML characters (like "<", ">", etc.) properly quoted,
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
echo htmlSpecialChars(stripslashes($var));
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2002-07-11 05:30:57 +00:00
|
|
|
function nvl(&$var, $default="") {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// if $var is undefined, return $default, otherwise return $var
|
2002-07-11 05:30:57 +00:00
|
|
|
|
|
|
|
return isset($var) ? $var : $default;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
function strip_querystring($url) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// takes a URL and returns it without the querystring portion
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
if ($commapos = strpos($url, '?')) {
|
|
|
|
return substr($url, 0, $commapos);
|
|
|
|
} else {
|
|
|
|
return $url;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_referer() {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// returns the URL of the HTTP_REFERER, less the querystring portion
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-10-02 02:05:29 +00:00
|
|
|
global $HTTP_REFERER;
|
2002-10-19 04:58:14 +00:00
|
|
|
|
2002-07-11 05:30:57 +00:00
|
|
|
return strip_querystring(nvl($HTTP_REFERER));
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2002-10-19 04:58:14 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
function me() {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// returns the name of the current script, WITH the querystring portion.
|
|
|
|
/// this function is necessary because PHP_SELF and REQUEST_URI and PATH_INFO
|
|
|
|
/// return different things depending on a lot of things like your OS, Web
|
|
|
|
/// server, and the way PHP is compiled (ie. as a CGI, module, ISAPI, etc.)
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-10-02 02:05:29 +00:00
|
|
|
global $REQUEST_URI, $PATH_INFO, $PHP_SELF;
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
if ($REQUEST_URI) {
|
|
|
|
return $REQUEST_URI;
|
2002-10-19 04:58:14 +00:00
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
} else if ($PATH_INFO) {
|
|
|
|
return $PATH_INFO;
|
2002-10-19 04:58:14 +00:00
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
} else if ($PHP_SELF) {
|
|
|
|
return $PHP_SELF;
|
2002-10-19 04:58:14 +00:00
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
} else {
|
2002-10-19 04:58:14 +00:00
|
|
|
notify("Error: Could not find any of these web server variables: \$REQUEST_URI, \$PATH_INFO or \$PHP_SELF");
|
2002-10-02 02:05:29 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function qualified_me() {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// like me() but returns a full URL
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-10-19 04:58:14 +00:00
|
|
|
global $HTTPS, $HTTP_HOST;
|
|
|
|
|
|
|
|
if (!$HTTP_HOST) {
|
|
|
|
notify("Error: could not find web server variable: \$HTTP_HOST");
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
$protocol = (isset($HTTPS) && $HTTPS == "on") ? "https://" : "http://";
|
|
|
|
$url_prefix = "$protocol$HTTP_HOST";
|
|
|
|
return $url_prefix . me();
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function match_referer($good_referer = "") {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// returns true if the referer is the same as the good_referer. If
|
2002-10-25 07:17:23 +00:00
|
|
|
/// good_referer is not specified, use qualified_me as the good_referer
|
2002-11-17 10:45:34 +00:00
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($CFG->buggy_referer) {
|
|
|
|
return true;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
if ($good_referer == "") {
|
2002-10-19 04:58:14 +00:00
|
|
|
$good_referer = qualified_me();
|
|
|
|
}
|
2002-12-30 03:39:42 +00:00
|
|
|
return $good_referer == get_referer();
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-18 09:09:19 +00:00
|
|
|
function stri_replace($find, $replace, $string ) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// This does a search and replace, ignoring case
|
|
|
|
/// This function is only here because one doesn't exist yet in PHP
|
|
|
|
/// Unlike str_replace(), this only works on single values (not arrays)
|
2002-10-18 09:09:19 +00:00
|
|
|
|
|
|
|
$parts = explode(strtolower($find), strtolower($string));
|
|
|
|
|
|
|
|
$pos = 0;
|
|
|
|
|
|
|
|
foreach ($parts as $key => $part) {
|
|
|
|
$parts[$key] = substr($string, $pos, strlen($part));
|
|
|
|
$pos += strlen($part) + strlen($find);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (join($replace, $parts));
|
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
function read_template($filename, &$var) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// return a (big) string containing the contents of a template file with all
|
|
|
|
/// the variables interpolated. all the variables must be in the $var[] array or
|
|
|
|
/// object (whatever you decide to use).
|
|
|
|
///
|
|
|
|
/// WARNING: do not use this on big files!!
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
$temp = str_replace("\\", "\\\\", implode(file($filename), ""));
|
|
|
|
$temp = str_replace('"', '\"', $temp);
|
|
|
|
eval("\$template = \"$temp\";");
|
|
|
|
return $template;
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checked(&$var, $set_value = 1, $unset_value = 0) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// if variable is set, set it to the set_value otherwise set it to the
|
|
|
|
/// unset_value. used to handle checkboxes when you are expecting them from
|
|
|
|
/// a form
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
if (empty($var)) {
|
|
|
|
$var = $unset_value;
|
|
|
|
} else {
|
|
|
|
$var = $set_value;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function frmchecked(&$var, $true_value = "checked", $false_value = "") {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// prints the word "checked" if a variable is true, otherwise prints nothing,
|
|
|
|
/// used for printing the word "checked" in a checkbox form input
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
if ($var) {
|
|
|
|
echo $true_value;
|
|
|
|
} else {
|
|
|
|
echo $false_value;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-21 08:34:25 +00:00
|
|
|
function link_to_popup_window ($url, $name="popup", $linkname="click here", $height=400, $width=500, $title="Popup window") {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// This will create a HTML link that will work on both
|
|
|
|
/// Javascript and non-javascript browsers.
|
|
|
|
/// Relies on the Javascript function openpopup in javascript.php
|
|
|
|
/// $url must be relative to home page eg /mod/survey/stuff.php
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-10-14 16:00:55 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
echo "\n<SCRIPT language=\"Javascript\">";
|
2001-11-22 06:23:56 +00:00
|
|
|
echo "\n<!--";
|
2002-12-30 03:39:42 +00:00
|
|
|
echo "\ndocument.write('<A TITLE=\"$title\" HREF=javascript:openpopup(\"$url\",\"$name\",\"$height\",\"$width\") >$linkname</A>');";
|
2001-11-22 06:23:56 +00:00
|
|
|
echo "\n//-->";
|
2002-12-30 03:39:42 +00:00
|
|
|
echo "\n</SCRIPT>";
|
|
|
|
echo "\n<NOSCRIPT>\n<A TARGET=\"$name\" TITLE=\"$title\" HREF=\"$CFG->wwwroot/$url\">$linkname</A>\n</NOSCRIPT>\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function close_window_button() {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Prints a simple button to close a window
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
echo "<FORM><CENTER>";
|
2002-10-21 03:00:40 +00:00
|
|
|
echo "<INPUT TYPE=button onClick=\"self.close();\" VALUE=\"".get_string("closewindow")."\">";
|
2001-11-22 06:23:56 +00:00
|
|
|
echo "</CENTER></FORM>";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-19 14:51:49 +00:00
|
|
|
function choose_from_menu ($options, $name, $selected="", $nothing="choose", $script="", $nothingvalue="0", $return=false) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Given an array of value, creates a popup menu to be part of a form
|
|
|
|
/// $options["value"]["label"]
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-08-12 07:40:53 +00:00
|
|
|
if ($nothing == "choose") {
|
|
|
|
$nothing = get_string("choose")."...";
|
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
if ($script) {
|
|
|
|
$javascript = "onChange=\"$script\"";
|
2002-12-29 17:32:32 +00:00
|
|
|
} else {
|
|
|
|
$javascript = "";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2002-12-29 17:32:32 +00:00
|
|
|
|
2002-09-19 14:51:49 +00:00
|
|
|
$output = "<SELECT NAME=$name $javascript>\n";
|
2002-06-05 05:37:55 +00:00
|
|
|
if ($nothing) {
|
2002-09-19 14:51:49 +00:00
|
|
|
$output .= " <OPTION VALUE=\"$nothingvalue\"\n";
|
2002-06-05 05:37:55 +00:00
|
|
|
if ($nothingvalue == $selected) {
|
2002-09-19 14:51:49 +00:00
|
|
|
$output .= " SELECTED";
|
2002-06-05 05:37:55 +00:00
|
|
|
}
|
2002-09-19 14:51:49 +00:00
|
|
|
$output .= ">$nothing</OPTION>\n";
|
2002-06-05 03:15:30 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
foreach ($options as $value => $label) {
|
2002-09-19 14:51:49 +00:00
|
|
|
$output .= " <OPTION VALUE=\"$value\"";
|
2001-11-22 06:23:56 +00:00
|
|
|
if ($value == $selected) {
|
2002-09-19 14:51:49 +00:00
|
|
|
$output .= " SELECTED";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
if ($label) {
|
2002-09-19 14:51:49 +00:00
|
|
|
$output .= ">$label</OPTION>\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
2002-09-19 14:51:49 +00:00
|
|
|
$output .= ">$value</OPTION>\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-19 14:51:49 +00:00
|
|
|
$output .= "</SELECT>\n";
|
|
|
|
|
|
|
|
if ($return) {
|
|
|
|
return $output;
|
|
|
|
} else {
|
|
|
|
echo $output;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2002-11-10 07:37:15 +00:00
|
|
|
function popup_form ($common, $options, $formname, $selected="", $nothing="choose", $help="", $helptext="", $return=false) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Implements a complete little popup form
|
|
|
|
/// $common = the URL up to the point of the variable that changes
|
|
|
|
/// $options = A list of value-label pairs for the popup list
|
|
|
|
/// $formname = name must be unique on the page
|
|
|
|
/// $selected = the option that is already selected
|
|
|
|
/// $nothing = The label for the "no choice" option
|
2002-10-21 03:00:40 +00:00
|
|
|
/// $help = The name of a help page if help is required
|
|
|
|
/// $helptext = The name of the label for the help button
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-08-12 07:40:53 +00:00
|
|
|
if ($nothing == "choose") {
|
|
|
|
$nothing = get_string("choose")."...";
|
|
|
|
}
|
|
|
|
|
2002-11-10 08:08:23 +00:00
|
|
|
$output = "<FORM TARGET=_top NAME=$formname>";
|
|
|
|
$output .= "<SELECT NAME=popup onChange=\"top.location=document.$formname.popup.options[document.$formname.popup.selectedIndex].value\">\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
if ($nothing != "") {
|
2002-11-10 07:37:15 +00:00
|
|
|
$output .= " <OPTION VALUE=\"javascript:void(0)\">$nothing</OPTION>\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($options as $value => $label) {
|
2002-11-10 07:37:15 +00:00
|
|
|
if (substr($label,0,1) == "-") {
|
|
|
|
$output .= " <OPTION VALUE=\"\"";
|
|
|
|
} else {
|
|
|
|
$output .= " <OPTION VALUE=\"$common$value\"";
|
|
|
|
if ($value == $selected) {
|
|
|
|
$output .= " SELECTED";
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
if ($label) {
|
2002-11-10 07:37:15 +00:00
|
|
|
$output .= ">$label</OPTION>\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
2002-11-10 07:37:15 +00:00
|
|
|
$output .= ">$value</OPTION>\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
2002-11-10 07:37:15 +00:00
|
|
|
$output .= "</SELECT>";
|
|
|
|
$output .= "</FORM>\n";
|
|
|
|
|
|
|
|
if ($return) {
|
|
|
|
return $output;
|
|
|
|
} else {
|
2002-12-29 17:32:32 +00:00
|
|
|
if ($help) {
|
|
|
|
helpbutton($help, $helptext);
|
|
|
|
}
|
2002-11-10 07:37:15 +00:00
|
|
|
echo $output;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function formerr($error) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Prints some red text
|
2001-11-22 06:23:56 +00:00
|
|
|
if (!empty($error)) {
|
|
|
|
echo "<font color=#ff0000>$error</font>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function validate_email ($address) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Validates an email to make it makes sense.
|
2001-11-22 06:23:56 +00:00
|
|
|
return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
|
|
|
|
'@'.
|
|
|
|
'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
|
|
|
|
'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
|
|
|
|
$address));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function get_slash_arguments($i=0) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Extracts arguments from "/foo/bar/something"
|
|
|
|
/// eg http://mysite.com/script.php/foo/bar/something
|
|
|
|
/// Might only work on Apache
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
global $PATH_INFO;
|
|
|
|
|
|
|
|
if (!isset($PATH_INFO)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-11-21 02:51:50 +00:00
|
|
|
if (strpos($PATH_INFO, "..")) { // check for parent URLs
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (strpos($PATH_INFO, "|")) { // check for pipes
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (strpos($PATH_INFO, "`")) { // check for backquotes
|
2002-09-05 11:53:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
$args = explode("/", $PATH_INFO);
|
|
|
|
|
|
|
|
if ($i) { // return just the required argument
|
|
|
|
return $args[$i];
|
|
|
|
|
|
|
|
} else { // return the whole array
|
|
|
|
array_shift($args); // get rid of the empty first one
|
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-10 07:26:10 +00:00
|
|
|
function format_text_menu() {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Just returns an array of formats suitable for a popup menu
|
2002-10-10 07:26:10 +00:00
|
|
|
return array (FORMAT_MOODLE => get_string("formattext"),
|
|
|
|
FORMAT_HTML => get_string("formathtml") );
|
|
|
|
}
|
|
|
|
|
2002-11-17 10:45:34 +00:00
|
|
|
function format_text($text, $format=FORMAT_MOODLE, $options=NULL) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Given text in a variety of format codings, this function returns
|
|
|
|
/// the text as safe HTML.
|
|
|
|
///
|
|
|
|
/// $text is raw text (originally from a user)
|
|
|
|
/// $format is one of the format constants, defined above
|
2002-10-10 07:26:10 +00:00
|
|
|
|
|
|
|
switch ($format) {
|
|
|
|
case FORMAT_MOODLE:
|
2002-10-12 03:53:40 +00:00
|
|
|
if (!isset($options->smiley)) {
|
|
|
|
$options->smiley=true;
|
|
|
|
}
|
|
|
|
if (!isset($options->para)) {
|
2002-10-12 05:09:49 +00:00
|
|
|
$options->para=true;
|
2002-10-12 03:53:40 +00:00
|
|
|
}
|
2002-10-10 07:26:10 +00:00
|
|
|
return text_to_html($text, $options->smiley, $options->para);
|
|
|
|
break;
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-10-10 07:26:10 +00:00
|
|
|
case FORMAT_HTML:
|
2002-10-12 05:09:49 +00:00
|
|
|
$text = replace_smilies($text);
|
2002-10-18 09:09:19 +00:00
|
|
|
return $text;
|
2002-10-10 07:26:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function clean_text($text, $format) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Given raw text (eg typed in by a user), this function cleans it up
|
|
|
|
/// and removes any nasty tags that could mess up Moodle pages.
|
2002-03-26 12:58:54 +00:00
|
|
|
|
2002-10-18 09:09:19 +00:00
|
|
|
global $JAVASCRIPT_TAGS, $ALLOWED_TAGS;
|
|
|
|
|
|
|
|
switch ($format) { // Does the same thing, currently, but it's nice to have the option
|
2002-10-10 07:26:10 +00:00
|
|
|
case FORMAT_MOODLE:
|
2002-10-18 09:09:19 +00:00
|
|
|
$text = strip_tags($text, $ALLOWED_TAGS);
|
|
|
|
foreach ($JAVASCRIPT_TAGS as $tag) {
|
|
|
|
$text = stri_replace($tag, "", $text);
|
|
|
|
}
|
|
|
|
return $text;
|
2002-10-10 07:26:10 +00:00
|
|
|
|
|
|
|
case FORMAT_HTML:
|
2002-10-18 09:09:19 +00:00
|
|
|
$text = strip_tags($text, $ALLOWED_TAGS);
|
|
|
|
foreach ($JAVASCRIPT_TAGS as $tag) {
|
|
|
|
$text = stri_replace($tag, "", $text);
|
|
|
|
}
|
|
|
|
return $text;
|
2002-10-10 07:26:10 +00:00
|
|
|
}
|
2002-03-26 12:58:54 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-10-12 05:09:49 +00:00
|
|
|
function replace_smilies($text) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Replaces all known smileys in the text with image equivalents
|
|
|
|
|
2002-10-12 05:09:49 +00:00
|
|
|
global $CFG, $SMILEY_TEXT, $SMILEY_IMAGE;
|
2002-03-26 12:58:54 +00:00
|
|
|
|
2002-10-12 05:09:49 +00:00
|
|
|
return str_replace($SMILEY_TEXT, $SMILEY_IMAGE, $text);
|
|
|
|
}
|
2002-10-10 07:26:10 +00:00
|
|
|
|
2002-08-12 13:45:41 +00:00
|
|
|
function text_to_html($text, $smiley=true, $para=true) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Given plain text, makes it into HTML as nicely as possible.
|
|
|
|
/// May contain HTML tags already
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Remove any whitespace that may be between HTML tags
|
2002-08-22 08:31:29 +00:00
|
|
|
$text = eregi_replace(">([[:space:]]+)<", "><", $text);
|
|
|
|
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Remove any returns that precede or follow HTML tags
|
2002-09-02 07:41:39 +00:00
|
|
|
$text = eregi_replace("([\n\r])<", " <", $text);
|
|
|
|
$text = eregi_replace(">([\n\r])", "> ", $text);
|
2002-08-22 08:31:29 +00:00
|
|
|
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Make lone URLs into links. eg http://moodle.com/
|
2002-10-18 17:05:17 +00:00
|
|
|
$text = eregi_replace("([\n\r ([])([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
|
2002-10-18 09:09:19 +00:00
|
|
|
"\\1<A HREF=\"\\2://\\3\\4\" TARGET=\"newpage\">\\2://\\3\\4</A>", $text);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-10-19 04:58:14 +00:00
|
|
|
/// eg www.moodle.com
|
2001-11-22 06:23:56 +00:00
|
|
|
$text = eregi_replace("([[:space:]])www.([^[:space:]]*)([[:alnum:]#?/&=])",
|
|
|
|
"\\1<A HREF=\"http://www.\\2\\3\" TARGET=\"newpage\">www.\\2\\3</A>", $text);
|
|
|
|
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Make returns into HTML newlines.
|
2001-11-22 06:23:56 +00:00
|
|
|
$text = nl2br($text);
|
|
|
|
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Turn smileys into images.
|
2002-05-18 05:22:48 +00:00
|
|
|
if ($smiley) {
|
2002-10-12 05:09:49 +00:00
|
|
|
$text = replace_smilies($text);
|
2002-05-18 05:22:48 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Wrap the whole thing in a paragraph tag if required
|
2002-08-12 13:45:41 +00:00
|
|
|
if ($para) {
|
|
|
|
return "<P>".$text."</P>";
|
|
|
|
} else {
|
|
|
|
return $text;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2002-06-11 07:01:51 +00:00
|
|
|
function highlight($needle, $haystack) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// This function will highlight instances of $needle in $haystack
|
2002-06-11 07:01:51 +00:00
|
|
|
|
|
|
|
$parts = explode(strtolower($needle), strtolower($haystack));
|
|
|
|
|
|
|
|
$pos = 0;
|
|
|
|
|
|
|
|
foreach ($parts as $key => $part) {
|
|
|
|
$parts[$key] = substr($haystack, $pos, strlen($part));
|
|
|
|
$pos += strlen($part);
|
|
|
|
|
|
|
|
$parts[$key] .= "<SPAN CLASS=highlight>".substr($haystack, $pos, strlen($needle))."</SPAN>";
|
|
|
|
$pos += strlen($needle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (join('', $parts));
|
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
|
|
|
|
/// STANDARD WEB PAGE PARTS ///////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function print_header ($title="", $heading="", $navigation="", $focus="", $meta="", $cache=true, $button=" ", $menu="") {
|
|
|
|
// $title - appears top of window
|
|
|
|
// $heading - appears top of page
|
|
|
|
// $navigation - premade navigation string
|
|
|
|
// $focus - indicates form element eg inputform.password
|
|
|
|
// $meta - meta tags in the header
|
|
|
|
// $cache - should this page be cacheable?
|
|
|
|
// $button - HTML code for a button (usually for module editing)
|
|
|
|
// $menu - HTML code for a popup menu
|
|
|
|
global $USER, $CFG, $THEME;
|
|
|
|
|
|
|
|
if (file_exists("$CFG->dirroot/theme/$CFG->theme/styles.php")) {
|
|
|
|
$styles = $CFG->stylesheet;
|
|
|
|
} else {
|
|
|
|
$styles = "$CFG->wwwroot/theme/standard/styles.php";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($navigation == "home") {
|
|
|
|
$home = true;
|
|
|
|
$navigation = "";
|
2002-12-29 04:17:32 +00:00
|
|
|
} else {
|
|
|
|
$home = false;
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($button == "") {
|
|
|
|
$button = " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$menu and $navigation) {
|
|
|
|
if (isset($USER->id)) {
|
|
|
|
$menu = "<FONT SIZE=2><A TARGET=_parent HREF=\"$CFG->wwwroot/login/logout.php\">".get_string("logout")."</A></FONT>";
|
|
|
|
} else {
|
|
|
|
$menu = "<FONT SIZE=2><A TARGET=_parent HREF=\"$CFG->wwwroot/login/index.php\">".get_string("login")."</A></FONT>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Specify character set ... default is iso-8859-1 but some languages might need something else
|
|
|
|
// Could be optimised by carrying the charset variable around in $USER
|
|
|
|
if (current_language() == "en") {
|
|
|
|
$meta = "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">\n$meta\n";
|
|
|
|
} else {
|
|
|
|
$meta = "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=".get_string("thischarset")."\">\n$meta\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($CFG->langdir == "RTL") {
|
|
|
|
$direction = " DIR=\"RTL\"";
|
|
|
|
} else {
|
|
|
|
$direction = " DIR=\"LTR\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$cache) { // Do everything we can to prevent clients and proxies caching
|
|
|
|
@header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
|
|
|
@header("Pragma: no-cache");
|
|
|
|
$meta .= "\n<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">";
|
|
|
|
$meta .= "\n<META HTTP-EQUIV=\"Expires\" CONTENT=\"0\">";
|
|
|
|
}
|
|
|
|
|
|
|
|
include ("$CFG->dirroot/theme/$CFG->theme/header.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_footer ($course=NULL) {
|
|
|
|
// Can provide a course object to make the footer contain a link to
|
|
|
|
// to the course home page, otherwise the link will go to the site home
|
|
|
|
global $USER, $CFG, $THEME;
|
|
|
|
|
|
|
|
|
|
|
|
/// Course links
|
|
|
|
if ($course) {
|
|
|
|
if ($course == "home") { // special case for site home page - please do not remove
|
|
|
|
$homelink = "<P ALIGN=center><A TITLE=\"Moodle $CFG->release ($CFG->version)\" HREF=\"http://moodle.com/\">";
|
|
|
|
$homelink .= "<BR><IMG WIDTH=130 HEIGHT=19 SRC=\"pix/madewithmoodle2.gif\" BORDER=0></A></P>";
|
|
|
|
$course = get_site();
|
|
|
|
$homepage = true;
|
|
|
|
} else {
|
|
|
|
$homelink = "<A TARGET=_top HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A>";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$homelink = "<A TARGET=_top HREF=\"$CFG->wwwroot\">".get_string("home")."</A>";
|
|
|
|
$course = get_site();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// User links
|
2002-12-29 04:17:32 +00:00
|
|
|
if (isset($USER->realuser)) {
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($realuser = get_record("user", "id", $USER->realuser)) {
|
|
|
|
$realuserinfo = " [<A HREF=\"$CFG->wwwroot/course/loginas.php?id=$course->id&return=$realuser->id\">$realuser->firstname $realuser->lastname</A>] ";
|
|
|
|
}
|
2002-12-29 04:17:32 +00:00
|
|
|
} else {
|
|
|
|
$realuserinfo = "";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2002-12-29 17:32:32 +00:00
|
|
|
if (isset($USER->id) and $USER->id) {
|
2002-12-20 14:44:14 +00:00
|
|
|
$username = "<A HREF=\"$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id\">$USER->firstname $USER->lastname</A>";
|
|
|
|
$loggedinas = $realuserinfo.get_string("loggedinas", "moodle", "$username").
|
|
|
|
" (<A HREF=\"$CFG->wwwroot/login/logout.php\">".get_string("logout")."</A>)";
|
|
|
|
} else {
|
|
|
|
$loggedinas = get_string("loggedinnot", "moodle").
|
|
|
|
" (<A HREF=\"$CFG->wwwroot/login/index.php\">".get_string("login")."</A>)";
|
|
|
|
}
|
|
|
|
|
|
|
|
include ("$CFG->dirroot/theme/$CFG->theme/footer.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function print_navigation ($navigation) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($navigation) {
|
|
|
|
if (! $site = get_site()) {
|
|
|
|
$site->shortname = get_string("home");;
|
|
|
|
}
|
|
|
|
echo "<A TARGET=_top HREF=\"$CFG->wwwroot/\">$site->shortname</A> -> $navigation";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_heading($text, $align="CENTER", $size=3) {
|
|
|
|
echo "<P ALIGN=\"$align\"><FONT SIZE=\"$size\"><B>".stripslashes($text)."</B></FONT></P>";
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_heading_with_help($text, $helppage, $module="moodle") {
|
|
|
|
// Centered heading with attached help button (same title text)
|
|
|
|
echo "<P ALIGN=\"CENTER\"><FONT SIZE=\"3\"><B>".stripslashes($text);
|
|
|
|
helpbutton($helppage, $text, $module);
|
|
|
|
echo "</B></FONT></P>";
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_continue($link) {
|
|
|
|
global $HTTP_REFERER;
|
|
|
|
|
|
|
|
if (!$link) {
|
|
|
|
$link = $HTTP_REFERER;
|
|
|
|
}
|
|
|
|
|
|
|
|
print_heading("<A HREF=\"$link\">".get_string("continue")."</A>");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function print_simple_box($message, $align="", $width="", $color="#FFFFFF", $padding=5, $class="generalbox") {
|
|
|
|
print_simple_box_start($align, $width, $color, $padding, $class);
|
|
|
|
echo stripslashes($message);
|
|
|
|
print_simple_box_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_simple_box_start($align="", $width="", $color="#FFFFFF", $padding=5, $class="generalbox") {
|
|
|
|
global $THEME;
|
|
|
|
|
|
|
|
if ($align) {
|
2002-12-29 04:17:32 +00:00
|
|
|
$align = "ALIGN=\"$align\"";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
if ($width) {
|
2002-12-29 04:17:32 +00:00
|
|
|
$width = "WIDTH=\"$width\"";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2002-12-29 04:17:32 +00:00
|
|
|
echo "<table $align $width class=\"$class\" border=\"0\" cellpadding=\"$padding\" cellspacing=\"0\"><tr><td bgcolor=\"$color\" class=\"$class"."content\">";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function print_simple_box_end() {
|
|
|
|
echo "</td></tr></table>";
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_single_button($link, $options, $label="OK") {
|
|
|
|
echo "<FORM ACTION=\"$link\" METHOD=GET>";
|
|
|
|
if ($options) {
|
|
|
|
foreach ($options as $name => $value) {
|
|
|
|
echo "<INPUT TYPE=hidden NAME=\"$name\" VALUE=\"$value\">";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "<INPUT TYPE=submit VALUE=\"$label\"></FORM>";
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_spacer($height=1, $width=1, $br=true) {
|
|
|
|
global $CFG;
|
|
|
|
echo "<IMG HEIGHT=\"$height\" WIDTH=\"$width\" SRC=\"$CFG->wwwroot/pix/spacer.gif\" ALT=\"\">";
|
|
|
|
if ($br) {
|
|
|
|
echo "<BR \>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_file_picture($path, $courseid=0, $height="", $width="", $link="") {
|
|
|
|
// Given the path to a picture file in a course, or a URL,
|
|
|
|
// this function includes the picture in the page.
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($height) {
|
|
|
|
$height = "HEIGHT=\"$height\"";
|
|
|
|
}
|
|
|
|
if ($width) {
|
|
|
|
$width = "WIDTH=\"$width\"";
|
|
|
|
}
|
|
|
|
if ($link) {
|
|
|
|
echo "<A HREF=\"$link\">";
|
|
|
|
}
|
|
|
|
if (substr(strtolower($path), 0, 7) == "http://") {
|
|
|
|
echo "<IMG BORDER=0 $height $width SRC=\"$path\">";
|
|
|
|
|
|
|
|
} else if ($courseid) {
|
|
|
|
echo "<IMG BORDER=0 $height $width SRC=\"";
|
|
|
|
if ($CFG->slasharguments) { // Use this method if possible for better caching
|
|
|
|
echo "$CFG->wwwroot/file.php/$courseid/$path";
|
|
|
|
} else {
|
|
|
|
echo "$CFG->wwwroot/file.php?file=$courseid/$path";
|
|
|
|
}
|
|
|
|
echo "\">";
|
|
|
|
} else {
|
|
|
|
echo "Error: must pass URL or course";
|
|
|
|
}
|
|
|
|
if ($link) {
|
|
|
|
echo "</A>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_user_picture($userid, $courseid, $picture, $large=false, $returnstring=false, $link=true) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($link) {
|
|
|
|
$output = "<A HREF=\"$CFG->wwwroot/user/view.php?id=$userid&course=$courseid\">";
|
|
|
|
} else {
|
|
|
|
$output = "";
|
|
|
|
}
|
|
|
|
if ($large) {
|
|
|
|
$file = "f1.jpg";
|
|
|
|
$size = 100;
|
|
|
|
} else {
|
|
|
|
$file = "f2.jpg";
|
|
|
|
$size = 35;
|
|
|
|
}
|
|
|
|
if ($picture) {
|
|
|
|
if ($CFG->slasharguments) { // Use this method if possible for better caching
|
|
|
|
$output .= "<IMG SRC=\"$CFG->wwwroot/user/pix.php/$userid/$file\" BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"\">";
|
|
|
|
} else {
|
|
|
|
$output .= "<IMG SRC=\"$CFG->wwwroot/user/pix.php?file=/$userid/$file\" BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"\">";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$output .= "<IMG SRC=\"$CFG->wwwroot/user/default/$file\" BORDER=0 WIDTH=$size HEIGHT=$size ALT=\"\">";
|
|
|
|
}
|
|
|
|
if ($link) {
|
|
|
|
$output .= "</A>";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($returnstring) {
|
|
|
|
return $output;
|
|
|
|
} else {
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_table($table) {
|
|
|
|
// Prints a nicely formatted table.
|
|
|
|
// $table is an object with several properties.
|
|
|
|
// $table->head is an array of heading names.
|
|
|
|
// $table->align is an array of column alignments
|
|
|
|
// $table->size is an array of column sizes
|
|
|
|
// $table->data[] is an array of arrays containing the data.
|
|
|
|
// $table->width is an percentage of the page
|
|
|
|
// $table->cellpadding padding on each cell
|
|
|
|
// $table->cellspacing spacing between cells
|
|
|
|
|
|
|
|
if (isset($table->align)) {
|
|
|
|
foreach ($table->align as $key => $aa) {
|
|
|
|
if ($aa) {
|
|
|
|
$align[$key] = " ALIGN=\"$aa\"";
|
|
|
|
} else {
|
|
|
|
$align[$key] = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($table->size)) {
|
|
|
|
foreach ($table->size as $key => $ss) {
|
|
|
|
if ($ss) {
|
|
|
|
$size[$key] = " WIDTH=\"$ss\"";
|
|
|
|
} else {
|
|
|
|
$size[$key] = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-29 04:17:32 +00:00
|
|
|
if (empty($table->width)) {
|
2002-12-20 14:44:14 +00:00
|
|
|
$table->width = "80%";
|
|
|
|
}
|
|
|
|
|
2002-12-29 04:17:32 +00:00
|
|
|
if (empty($table->cellpadding)) {
|
2002-12-20 14:44:14 +00:00
|
|
|
$table->cellpadding = "5";
|
|
|
|
}
|
|
|
|
|
2002-12-29 04:17:32 +00:00
|
|
|
if (empty($table->cellspacing)) {
|
2002-12-20 14:44:14 +00:00
|
|
|
$table->cellspacing = "1";
|
|
|
|
}
|
|
|
|
|
|
|
|
print_simple_box_start("CENTER", "$table->width", "#FFFFFF", 0);
|
|
|
|
echo "<TABLE WIDTH=100% BORDER=0 valign=top align=center ";
|
|
|
|
echo " cellpadding=\"$table->cellpadding\" cellspacing=\"$table->cellspacing\" class=\"generaltable\">\n";
|
|
|
|
|
|
|
|
if ($table->head) {
|
|
|
|
echo "<TR>";
|
|
|
|
foreach ($table->head as $key => $heading) {
|
2002-12-29 04:17:32 +00:00
|
|
|
if (!isset($size[$key])) {
|
|
|
|
$size[$key] = "";
|
|
|
|
}
|
|
|
|
if (!isset($align[$key])) {
|
|
|
|
$align[$key] = "";
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
echo "<TH VALIGN=top ".$align[$key].$size[$key]." NOWRAP class=\"generaltableheader\">$heading</TH>";
|
|
|
|
}
|
|
|
|
echo "</TR>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($table->data as $row) {
|
|
|
|
echo "<TR VALIGN=TOP>";
|
|
|
|
foreach ($row as $key => $item) {
|
2002-12-29 04:17:32 +00:00
|
|
|
if (!isset($size[$key])) {
|
|
|
|
$size[$key] = "";
|
|
|
|
}
|
|
|
|
if (!isset($align[$key])) {
|
|
|
|
$align[$key] = "";
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
echo "<TD ".$align[$key].$size[$key]." class=\"generaltablecell\">$item</TD>";
|
|
|
|
}
|
|
|
|
echo "</TR>\n";
|
|
|
|
}
|
|
|
|
echo "</TABLE>\n";
|
|
|
|
print_simple_box_end();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_editing_switch($courseid) {
|
|
|
|
global $CFG, $USER;
|
|
|
|
|
|
|
|
if (isteacher($courseid)) {
|
|
|
|
if ($USER->editing) {
|
|
|
|
echo "<A HREF=\"$CFG->wwwroot/course/view.php?id=$courseid&edit=off\">Turn editing off</A>";
|
|
|
|
} else {
|
|
|
|
echo "<A HREF=\"$CFG->wwwroot/course/view.php?id=$courseid&edit=on\">Turn editing on</A>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_textarea($richedit, $rows, $cols, $width, $height, $name, $value="") {
|
|
|
|
global $CFG, $THEME;
|
|
|
|
|
|
|
|
if ($richedit) {
|
|
|
|
echo "<object id=richedit style=\"BACKGROUND-COLOR: buttonface\"";
|
|
|
|
echo " data=\"$CFG->wwwroot/lib/rte/richedit.html\"";
|
|
|
|
echo " width=\"$width\" height=\"$height\" ";
|
|
|
|
echo " type=\"text/x-scriptlet\" VIEWASTEXT></object>\n";
|
|
|
|
echo "<TEXTAREA style=\"display:none\" NAME=\"$name\" ROWS=1 COLS=1>";
|
|
|
|
p($value);
|
|
|
|
echo "</TEXTAREA>\n";
|
|
|
|
} else {
|
|
|
|
echo "<TEXTAREA name=\"$name\" rows=\"$rows\" cols=\"$cols\" wrap=virtual>";
|
|
|
|
p($value);
|
|
|
|
echo "</TEXTAREA>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_richedit_javascript($form, $name, $source="no") {
|
|
|
|
echo "<SCRIPT language=\"JavaScript\" event=\"onload\" for=\"window\">\n";
|
|
|
|
echo " document.richedit.options = \"history=no;source=$source\";";
|
|
|
|
echo " document.richedit.docHtml = $form.$name.innerText;";
|
|
|
|
echo "</SCRIPT>";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function update_course_icon($courseid) {
|
|
|
|
// Used to be an icon, but it's now a simple form button
|
|
|
|
global $CFG, $USER;
|
|
|
|
|
|
|
|
if (isteacher($courseid)) {
|
2002-12-29 17:32:32 +00:00
|
|
|
if (!empty($USER->editing)) {
|
2002-12-20 14:44:14 +00:00
|
|
|
$string = get_string("turneditingoff");
|
|
|
|
$edit = "off";
|
|
|
|
} else {
|
|
|
|
$string = get_string("turneditingon");
|
|
|
|
$edit = "on";
|
|
|
|
}
|
|
|
|
return "<FORM TARGET=_parent METHOD=GET ACTION=\"$CFG->wwwroot/course/view.php\">".
|
|
|
|
"<INPUT TYPE=hidden NAME=id VALUE=\"$courseid\">".
|
|
|
|
"<INPUT TYPE=hidden NAME=edit VALUE=\"$edit\">".
|
|
|
|
"<INPUT TYPE=submit VALUE=\"$string\"></FORM>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_module_button($moduleid, $courseid, $string) {
|
|
|
|
// Prints the editing button on a module "view" page
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if (isteacher($courseid)) {
|
|
|
|
$string = get_string("updatethis", "", $string);
|
|
|
|
return "<FORM TARGET=_parent METHOD=GET ACTION=\"$CFG->wwwroot/course/mod.php\">".
|
|
|
|
"<INPUT TYPE=hidden NAME=update VALUE=\"$moduleid\">".
|
|
|
|
"<INPUT TYPE=hidden NAME=return VALUE=\"true\">".
|
|
|
|
"<INPUT TYPE=submit VALUE=\"$string\"></FORM>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function navmenu($course, $cm=NULL) {
|
|
|
|
// Given a course and a (current) coursemodule
|
|
|
|
// This function returns a small popup menu with all the
|
|
|
|
// course activity modules in it, as a navigation menu
|
|
|
|
// The data is taken from the serialised array stored in
|
|
|
|
// the course record
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($cm) {
|
|
|
|
$cm = $cm->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($course->format == 'weeks') {
|
|
|
|
$strsection = get_string("week");
|
|
|
|
} else {
|
|
|
|
$strsection = get_string("topic");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$modinfo = unserialize($course->modinfo)) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
$section = -1;
|
|
|
|
$selected = "";
|
|
|
|
foreach ($modinfo as $mod) {
|
|
|
|
if ($mod->section > 0 and $section <> $mod->section) {
|
|
|
|
$menu[] = "-------------- $strsection $mod->section --------------";
|
|
|
|
}
|
|
|
|
$section = $mod->section;
|
|
|
|
$url = "$mod->mod/view.php?id=$mod->cm";
|
|
|
|
if ($cm == $mod->cm) {
|
|
|
|
$selected = $url;
|
|
|
|
}
|
|
|
|
$mod->name = urldecode($mod->name);
|
|
|
|
if (strlen($mod->name) > 55) {
|
|
|
|
$mod->name = substr($mod->name, 0, 50)."...";
|
|
|
|
}
|
|
|
|
$menu[$url] = $mod->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return popup_form("$CFG->wwwroot/mod/", $menu, "navmenu", $selected, get_string("jumpto"), "", "", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function print_date_selector($day, $month, $year, $currenttime=0) {
|
|
|
|
// Currenttime is a default timestamp in GMT
|
|
|
|
// Prints form items with the names $day, $month and $year
|
|
|
|
|
|
|
|
if (!$currenttime) {
|
|
|
|
$currenttime = time();
|
|
|
|
}
|
|
|
|
$currentdate = usergetdate($currenttime);
|
|
|
|
|
|
|
|
for ($i=1; $i<=31; $i++) {
|
|
|
|
$days[$i] = "$i";
|
|
|
|
}
|
|
|
|
for ($i=1; $i<=12; $i++) {
|
|
|
|
$months[$i] = date("F", mktime(0,0,0,$i,1,2000));
|
|
|
|
}
|
|
|
|
for ($i=2000; $i<=2010; $i++) {
|
|
|
|
$years[$i] = $i;
|
|
|
|
}
|
2002-12-30 05:13:43 +00:00
|
|
|
choose_from_menu($days, $day, $currentdate['mday'], "");
|
|
|
|
choose_from_menu($months, $month, $currentdate['mon'], "");
|
|
|
|
choose_from_menu($years, $year, $currentdate['year'], "");
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function print_time_selector($hour, $minute, $currenttime=0) {
|
|
|
|
// Currenttime is a default timestamp in GMT
|
|
|
|
// Prints form items with the names $hour and $minute
|
|
|
|
|
|
|
|
if (!$currenttime) {
|
|
|
|
$currenttime = time();
|
|
|
|
}
|
|
|
|
$currentdate = usergetdate($currenttime);
|
|
|
|
for ($i=0; $i<=23; $i++) {
|
|
|
|
$hours[$i] = sprintf("%02d",$i);
|
|
|
|
}
|
|
|
|
for ($i=0; $i<=59; $i++) {
|
|
|
|
$minutes[$i] = sprintf("%02d",$i);
|
|
|
|
}
|
2002-12-30 05:13:43 +00:00
|
|
|
choose_from_menu($hours, $hour, $currentdate['hours'], "");
|
|
|
|
choose_from_menu($minutes, $minute, $currentdate['minutes'], "");
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function error ($message, $link="") {
|
|
|
|
global $CFG, $SESSION;
|
|
|
|
|
|
|
|
print_header(get_string("error"));
|
|
|
|
echo "<BR>";
|
|
|
|
print_simple_box($message, "center", "", "#FFBBBB");
|
|
|
|
|
|
|
|
if (!$link) {
|
|
|
|
if ( !empty($SESSION->fromurl) ) {
|
|
|
|
$link = "$SESSION->fromurl";
|
|
|
|
unset($SESSION->fromurl);
|
|
|
|
save_session("SESSION");
|
|
|
|
} else {
|
|
|
|
$link = "$CFG->wwwroot";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print_continue($link);
|
|
|
|
print_footer();
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
function helpbutton ($page, $title="", $module="moodle", $image=true, $linktext=false, $text="") {
|
|
|
|
// $page = the keyword that defines a help page
|
|
|
|
// $title = the title of links, rollover tips, alt tags etc
|
|
|
|
// $module = which module is the page defined in
|
|
|
|
// $image = use a help image for the link? (true/false/"both")
|
|
|
|
// $text = if defined then this text is used in the page, and
|
|
|
|
// the $page variable is ignored.
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($module == "") {
|
|
|
|
$module = "moodle";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($image) {
|
|
|
|
if ($linktext) {
|
|
|
|
$linkobject = "$title<IMG align=\"absmiddle\" BORDER=0 HEIGHT=17 WIDTH=22 ALT=\"\" SRC=\"$CFG->wwwroot/pix/help.gif\">";
|
|
|
|
} else {
|
|
|
|
$linkobject = "<IMG align=\"absmiddle\" BORDER=0 HEIGHT=17 WIDTH=22 ALT=\"$title\" SRC=\"$CFG->wwwroot/pix/help.gif\">";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$linkobject = $title;
|
|
|
|
}
|
|
|
|
if ($text) {
|
|
|
|
$url = "/help.php?module=$module&text=".htmlentities(urlencode($text));
|
|
|
|
} else {
|
|
|
|
$url = "/help.php?module=$module&file=$page.html";
|
|
|
|
}
|
|
|
|
link_to_popup_window ($url, "popup", $linkobject, 400, 500, $title);
|
|
|
|
}
|
|
|
|
|
|
|
|
function notice ($message, $link="") {
|
|
|
|
global $THEME, $HTTP_REFERER;
|
|
|
|
|
|
|
|
if (!$link) {
|
|
|
|
$link = $HTTP_REFERER;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "<BR>";
|
|
|
|
print_simple_box($message, "center", "", "$THEME->cellheading");
|
|
|
|
print_heading("<A HREF=\"$link\">".get_string("continue")."</A>");
|
|
|
|
print_footer(get_site());
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
function notice_yesno ($message, $linkyes, $linkno) {
|
|
|
|
global $THEME;
|
|
|
|
|
|
|
|
print_simple_box_start("center", "", "$THEME->cellheading");
|
|
|
|
echo "<P ALIGN=CENTER><FONT SIZE=3>$message</FONT></P>";
|
|
|
|
echo "<P ALIGN=CENTER><FONT SIZE=3><B>";
|
|
|
|
echo "<A HREF=\"$linkyes\">".get_string("yes")."</A>";
|
|
|
|
echo " ";
|
|
|
|
echo "<A HREF=\"$linkno\">".get_string("no")."</A>";
|
|
|
|
echo "</B></FONT></P>";
|
|
|
|
print_simple_box_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
function redirect($url, $message="", $delay=0) {
|
|
|
|
// Uses META tags to redirect the user, after printing a notice
|
|
|
|
|
|
|
|
echo "<META HTTP-EQUIV='Refresh' CONTENT='$delay; URL=$url'>";
|
|
|
|
|
|
|
|
if (!empty($message)) {
|
|
|
|
print_header();
|
|
|
|
echo "<CENTER>";
|
|
|
|
echo "<P>$message</P>";
|
|
|
|
echo "<P>( <A HREF=\"$url\">".get_string("continue")."</A> )</P>";
|
|
|
|
echo "</CENTER>";
|
|
|
|
}
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
2002-12-23 14:19:45 +00:00
|
|
|
function notify ($message, $color="red", $align="center") {
|
|
|
|
echo "<p align=\"$align\"><b><font color=\"$color\">$message</font></b></p>\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
?>
|