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
|
2003-04-27 10:46:16 +00:00
|
|
|
define("FORMAT_MOODLE", "0"); // Does all sorts of transformations and filtering
|
2003-05-04 04:07:36 +00:00
|
|
|
define("FORMAT_HTML", "1"); // Plain HTML (with some tags stripped)
|
|
|
|
define("FORMAT_PLAIN", "2"); // Plain text (even tags are printed in full)
|
|
|
|
define("FORMAT_WIKI", "3"); // Wiki-formatted text
|
2002-10-10 07:26:10 +00:00
|
|
|
|
2003-10-16 14:25:36 +00:00
|
|
|
$ALLOWED_TAGS =
|
2003-11-07 04:53:54 +00:00
|
|
|
"<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>";
|
2002-10-18 09:09:19 +00:00
|
|
|
|
|
|
|
|
2002-10-10 07:26:10 +00:00
|
|
|
/// Functions
|
|
|
|
|
2003-05-26 14:43:19 +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
|
|
|
|
2003-05-26 14:43:19 +00:00
|
|
|
if (empty($var)) {
|
|
|
|
return "";
|
|
|
|
}
|
2003-01-23 13:07:49 +00:00
|
|
|
return htmlSpecialChars(stripslashes_safe($var));
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2003-05-26 14:43:19 +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
|
|
|
|
2003-05-26 14:43:19 +00:00
|
|
|
if (empty($var)) {
|
|
|
|
echo "";
|
|
|
|
}
|
2003-01-23 13:07:49 +00:00
|
|
|
echo htmlSpecialChars(stripslashes_safe($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
|
|
|
|
2003-01-05 06:45:20 +00:00
|
|
|
return strip_querystring(nvl($_SERVER["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.
|
2003-02-05 10:48:13 +00:00
|
|
|
/// this function is necessary because PHP_SELF and REQUEST_URI and SCRIPT_NAME
|
2002-10-19 04:58:14 +00:00
|
|
|
/// 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
|
|
|
|
2003-01-05 06:45:20 +00:00
|
|
|
if (!empty($_SERVER["REQUEST_URI"])) {
|
|
|
|
return $_SERVER["REQUEST_URI"];
|
2002-10-19 04:58:14 +00:00
|
|
|
|
2003-01-05 06:45:20 +00:00
|
|
|
} else if (!empty($_SERVER["PHP_SELF"])) {
|
2003-01-30 15:52:38 +00:00
|
|
|
if (!empty($_SERVER["QUERY_STRING"])) {
|
|
|
|
return $_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"];
|
|
|
|
}
|
2003-01-05 06:45:20 +00:00
|
|
|
return $_SERVER["PHP_SELF"];
|
2002-10-19 04:58:14 +00:00
|
|
|
|
2003-01-30 15:52:38 +00:00
|
|
|
} else if (!empty($_SERVER["SCRIPT_NAME"])) {
|
|
|
|
if (!empty($_SERVER["QUERY_STRING"])) {
|
|
|
|
return $_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];
|
|
|
|
}
|
|
|
|
return $_SERVER["SCRIPT_NAME"];
|
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
} else {
|
2003-01-30 15:52:38 +00:00
|
|
|
notify("Warning: Could not find any of these web server variables: \$REQUEST_URI, \$PHP_SELF or \$SCRIPT_NAME");
|
2003-02-05 10:52:55 +00:00
|
|
|
return false;
|
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
|
|
|
|
2003-01-10 05:40:35 +00:00
|
|
|
if (!empty($_SERVER["HTTP_HOST"])) {
|
|
|
|
$hostname = $_SERVER["HTTP_HOST"];
|
|
|
|
} else if (!empty($_ENV["HTTP_HOST"])) {
|
|
|
|
$hostname = $_ENV["HTTP_HOST"];
|
2003-06-28 18:45:19 +00:00
|
|
|
} else if (!empty($_SERVER["SERVER_NAME"])) {
|
|
|
|
$hostname = $_SERVER["SERVER_NAME"];
|
2003-01-10 05:40:35 +00:00
|
|
|
} else if (!empty($_ENV["SERVER_NAME"])) {
|
|
|
|
$hostname = $_ENV["SERVER_NAME"];
|
|
|
|
} else {
|
|
|
|
notify("Warning: could not find the name of this server!");
|
2003-02-05 10:52:55 +00:00
|
|
|
return false;
|
2002-10-19 04:58:14 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-01-05 06:45:20 +00:00
|
|
|
$protocol = (isset($_SERVER["HTTPS"]) and $_SERVER["HTTPS"] == "on") ? "https://" : "http://";
|
2003-01-10 05:40:35 +00:00
|
|
|
$url_prefix = $protocol.$hostname;
|
2002-12-30 03:39:42 +00:00
|
|
|
return $url_prefix . me();
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-12 09:22:00 +00:00
|
|
|
function match_referer($goodreferer = "") {
|
|
|
|
/// returns true if the referer is the same as the goodreferer. If
|
|
|
|
/// goodreferer is not specified, use qualified_me as the goodreferer
|
2002-11-17 10:45:34 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2003-05-15 15:59:52 +00:00
|
|
|
if (empty($CFG->secureforms)) { // Don't bother checking referer
|
2002-11-17 10:45:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-05-15 15:59:52 +00:00
|
|
|
if ($goodreferer == "nomatch") { // Don't bother checking referer
|
2003-05-12 09:22:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($goodreferer)) {
|
|
|
|
$goodreferer = qualified_me();
|
2002-10-19 04:58:14 +00:00
|
|
|
}
|
2003-05-12 09:22:00 +00:00
|
|
|
return $goodreferer == get_referer();
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2003-01-02 14:49:23 +00:00
|
|
|
function data_submitted($url="") {
|
|
|
|
/// Used on most forms in Moodle to check for data
|
|
|
|
/// Returns the data as an object, if it's found.
|
2003-01-05 06:45:20 +00:00
|
|
|
/// This object can be used in foreach loops without
|
|
|
|
/// casting because it's cast to (array) automatically
|
2003-01-02 14:49:23 +00:00
|
|
|
///
|
|
|
|
/// Checks that submitted POST data exists, and also
|
|
|
|
/// checks the referer against the given url (it uses
|
|
|
|
/// the current page if none was specified.
|
|
|
|
|
2003-01-20 07:13:02 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2003-01-05 06:45:20 +00:00
|
|
|
if (empty($_POST)) {
|
2003-01-02 14:49:23 +00:00
|
|
|
return false;
|
2003-01-05 06:45:20 +00:00
|
|
|
|
2003-01-02 14:49:23 +00:00
|
|
|
} else {
|
|
|
|
if (match_referer($url)) {
|
2003-01-05 06:45:20 +00:00
|
|
|
return (object)$_POST;
|
2003-01-02 14:49:23 +00:00
|
|
|
} else {
|
|
|
|
if ($CFG->debug > 10) {
|
|
|
|
notice("The form did not come from this page! (referer = ".get_referer().")");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-23 13:07:49 +00:00
|
|
|
function stripslashes_safe($string) {
|
|
|
|
/// stripslashes() removes ALL backslashes even from strings
|
|
|
|
/// so C:\temp becomes C:temp ... this isn't good.
|
|
|
|
/// The following should work as a fairly safe replacement
|
|
|
|
/// to be called on quoted AND unquoted strings (to be sure)
|
|
|
|
|
|
|
|
$string = str_replace("\\'", "'", $string);
|
|
|
|
$string = str_replace('\\"', '"', $string);
|
|
|
|
$string = str_replace('\\\\', '\\', $string);
|
|
|
|
return $string;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-06-06 09:46:27 +00:00
|
|
|
if (!function_exists('str_ireplace')) {
|
2003-10-16 09:28:27 +00:00
|
|
|
function str_ireplace($find, $replace, $string) {
|
2003-06-06 09:46:27 +00:00
|
|
|
/// This does a search and replace, ignoring case
|
2003-10-16 10:20:35 +00:00
|
|
|
/// This function is only here versions of PHP older than version 5
|
|
|
|
/// may not have a native version of this function.
|
|
|
|
/// Taken from the PHP manual, by bradhuizenga@softhome.net
|
2003-10-16 09:28:27 +00:00
|
|
|
|
|
|
|
if (!is_array($find)) {
|
|
|
|
$find = array($find);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!is_array($replace)) {
|
|
|
|
if (!is_array($find)) {
|
|
|
|
$replace = array($replace);
|
|
|
|
} else {
|
|
|
|
// this will duplicate the string into an array the size of $find
|
|
|
|
$c = count($find);
|
|
|
|
$rString = $replace;
|
|
|
|
unset($replace);
|
|
|
|
for ($i = 0; $i < $c; $i++) {
|
|
|
|
$replace[$i] = $rString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($find as $fKey => $fItem) {
|
|
|
|
$between = explode(strtolower($fItem),strtolower($string));
|
|
|
|
$pos = 0;
|
|
|
|
foreach($between as $bKey => $bItem) {
|
|
|
|
$between[$bKey] = substr($string,$pos,strlen($bItem));
|
|
|
|
$pos += strlen($bItem) + strlen($fItem);
|
|
|
|
}
|
|
|
|
$string = implode($replace[$fKey],$between);
|
2003-06-06 09:46:27 +00:00
|
|
|
}
|
2003-10-16 09:28:27 +00:00
|
|
|
return ($string);
|
2002-10-18 09:09:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-20 13:53:31 +00:00
|
|
|
function link_to_popup_window ($url, $name="popup", $linkname="click here",
|
2003-09-03 12:13:08 +00:00
|
|
|
$height=400, $width=500, $title="Popup window", $options="none") {
|
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;
|
|
|
|
|
2003-09-03 12:13:08 +00:00
|
|
|
if ($options == "none") {
|
|
|
|
$options = "menubar=0,location=0,scrollbars,resizable,width=$width,height=$height";
|
|
|
|
}
|
2003-07-20 13:53:31 +00:00
|
|
|
$fullscreen = 0;
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-08-10 08:01:14 +00:00
|
|
|
echo "<a target=\"$name\" title=\"$title\" href=\"$CFG->wwwroot$url\" ".
|
2003-07-20 13:53:31 +00:00
|
|
|
"onClick=\"return openpopup('$url', '$name', '$options', $fullscreen);\">$linkname</a>\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2003-07-20 13:53:31 +00:00
|
|
|
|
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
|
|
|
|
|
2003-07-20 13:53:31 +00:00
|
|
|
echo "<center>\n";
|
|
|
|
echo "<script>\n";
|
|
|
|
echo "<!--\n";
|
|
|
|
echo "document.write('<form>');\n";
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "document.write('<input type=\"button\" onClick=\"self.close();\" value=\"".get_string("closewindow")."\" />');\n";
|
2003-07-20 13:53:31 +00:00
|
|
|
echo "document.write('</form>');\n";
|
|
|
|
echo "-->\n";
|
|
|
|
echo "</script>\n";
|
|
|
|
echo "<noscript>\n";
|
|
|
|
echo "<a href=\"".$_SERVER['HTTP_REFERER']."\"><---</a>\n";
|
|
|
|
echo "</noscript>\n";
|
|
|
|
echo "</center>\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2003-09-21 15:45:24 +00:00
|
|
|
$output = "<select name=\"$name\" $javascript>\n";
|
2002-06-05 05:37:55 +00:00
|
|
|
if ($nothing) {
|
2003-05-14 05:01:01 +00:00
|
|
|
$output .= " <option value=\"$nothingvalue\"\n";
|
2002-06-05 05:37:55 +00:00
|
|
|
if ($nothingvalue == $selected) {
|
2003-09-21 15:45:24 +00:00
|
|
|
$output .= " selected=\"true\"";
|
2002-06-05 05:37:55 +00:00
|
|
|
}
|
2003-05-14 05:01:01 +00:00
|
|
|
$output .= ">$nothing</option>\n";
|
2002-06-05 03:15:30 +00:00
|
|
|
}
|
2003-01-05 06:45:20 +00:00
|
|
|
if (!empty($options)) {
|
|
|
|
foreach ($options as $value => $label) {
|
2003-05-14 05:01:01 +00:00
|
|
|
$output .= " <option value=\"$value\"";
|
2003-01-05 06:45:20 +00:00
|
|
|
if ($value == $selected) {
|
2003-09-21 15:45:24 +00:00
|
|
|
$output .= " selected=\"true\"";
|
2003-01-05 06:45:20 +00:00
|
|
|
}
|
2003-08-25 02:32:20 +00:00
|
|
|
if ($label === "") {
|
2003-05-14 05:01:01 +00:00
|
|
|
$output .= ">$value</option>\n";
|
2003-08-25 02:32:20 +00:00
|
|
|
} else {
|
|
|
|
$output .= ">$label</option>\n";
|
2003-01-05 06:45:20 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-14 05:01:01 +00:00
|
|
|
$output .= "</select>\n";
|
2002-09-19 14:51:49 +00:00
|
|
|
|
|
|
|
if ($return) {
|
|
|
|
return $output;
|
|
|
|
} else {
|
|
|
|
echo $output;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2003-08-26 06:01:13 +00:00
|
|
|
function popup_form ($common, $options, $formname, $selected="", $nothing="choose", $help="", $helptext="", $return=false, $targetwindow="self") {
|
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
|
2003-08-26 13:18:10 +00:00
|
|
|
/// $return = Boolean indicating whether the function should return the text
|
|
|
|
/// as a string or echo it directly to the page being rendered
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-03-30 13:25:49 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2002-08-12 07:40:53 +00:00
|
|
|
if ($nothing == "choose") {
|
|
|
|
$nothing = get_string("choose")."...";
|
|
|
|
}
|
|
|
|
|
2003-09-21 15:45:24 +00:00
|
|
|
$startoutput = "<form target=\"{$CFG->framename}\" name=\"$formname\">";
|
|
|
|
$output = "<select name=\"popup\" onchange=\"$targetwindow.location=document.$formname.popup.options[document.$formname.popup.selectedIndex].value\">\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
if ($nothing != "") {
|
2003-05-04 09:43:03 +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) == "-") {
|
2003-05-04 09:43:03 +00:00
|
|
|
$output .= " <option value=\"\"";
|
2002-11-10 07:37:15 +00:00
|
|
|
} else {
|
2003-05-04 09:43:03 +00:00
|
|
|
$output .= " <option value=\"$common$value\"";
|
2002-11-10 07:37:15 +00:00
|
|
|
if ($value == $selected) {
|
2003-09-21 15:45:24 +00:00
|
|
|
$output .= " selected=\"true\"";
|
2002-11-10 07:37:15 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
if ($label) {
|
2003-05-04 09:43:03 +00:00
|
|
|
$output .= ">$label</option>\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
2003-05-04 09:43:03 +00:00
|
|
|
$output .= ">$value</option>\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-04 09:43:03 +00:00
|
|
|
$output .= "</select>";
|
|
|
|
$output .= "</form>\n";
|
2002-11-10 07:37:15 +00:00
|
|
|
|
|
|
|
if ($return) {
|
2003-05-04 09:43:03 +00:00
|
|
|
return $startoutput.$output;
|
2002-11-10 07:37:15 +00:00
|
|
|
} else {
|
2003-05-04 09:43:03 +00:00
|
|
|
echo $startoutput;
|
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)) {
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "<font color=\"#ff0000\">$error</font>";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function validate_email ($address) {
|
2003-09-21 15:45:24 +00:00
|
|
|
/// Validates an email to make sure 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));
|
|
|
|
}
|
|
|
|
|
2003-05-09 02:05:16 +00:00
|
|
|
function detect_munged_arguments($string) {
|
2003-05-12 06:35:32 +00:00
|
|
|
if (ereg('\.\.', $string)) { // check for parent URLs
|
2003-05-09 02:05:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2003-05-12 06:35:32 +00:00
|
|
|
if (ereg('[\|\`]', $string)) { // check for other bad characters
|
2003-05-09 02:05:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-01-12 06:53:25 +00:00
|
|
|
function get_slash_arguments($file="file.php") {
|
|
|
|
/// Searches the current environment variables for some slash arguments
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-02-05 10:48:13 +00:00
|
|
|
if (!$string = me()) {
|
2001-11-22 06:23:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
2003-02-05 10:48:13 +00:00
|
|
|
|
2003-01-12 06:53:25 +00:00
|
|
|
$pathinfo = explode($file, $string);
|
|
|
|
|
2003-02-05 10:52:55 +00:00
|
|
|
if (!empty($pathinfo[1])) {
|
|
|
|
return $pathinfo[1];
|
2003-01-12 06:53:25 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function parse_slash_arguments($string, $i=0) {
|
|
|
|
/// Extracts arguments from "/foo/bar/something"
|
|
|
|
/// eg http://mysite.com/script.php/foo/bar/something
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-05-09 02:05:16 +00:00
|
|
|
if (detect_munged_arguments($string)) {
|
2002-11-21 02:51:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
2003-01-12 06:53:25 +00:00
|
|
|
$args = explode("/", $string);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
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"),
|
2003-04-27 10:46:16 +00:00
|
|
|
FORMAT_HTML => get_string("formathtml"),
|
2003-05-04 04:07:36 +00:00
|
|
|
FORMAT_PLAIN => get_string("formatplain"),
|
|
|
|
FORMAT_WIKI => get_string("formatwiki"));
|
2002-10-10 07:26:10 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2003-10-13 14:11:17 +00:00
|
|
|
global $CFG, $course;
|
2003-08-26 18:44:09 +00:00
|
|
|
|
2002-10-10 07:26:10 +00:00
|
|
|
switch ($format) {
|
2003-02-05 12:41:59 +00:00
|
|
|
case FORMAT_HTML:
|
2003-05-05 16:40:46 +00:00
|
|
|
replace_smilies($text);
|
2003-10-13 14:11:17 +00:00
|
|
|
return filter_text($text);
|
2003-02-05 12:41:59 +00:00
|
|
|
break;
|
|
|
|
|
2003-04-27 10:46:16 +00:00
|
|
|
case FORMAT_PLAIN:
|
|
|
|
$text = htmlentities($text);
|
2003-07-02 11:59:20 +00:00
|
|
|
$text = str_replace(" ", " ", $text);
|
2003-05-05 16:40:46 +00:00
|
|
|
replace_smilies($text);
|
2003-04-27 10:46:16 +00:00
|
|
|
$text = nl2br($text);
|
|
|
|
return $text;
|
|
|
|
break;
|
|
|
|
|
2003-05-04 04:07:36 +00:00
|
|
|
case FORMAT_WIKI:
|
2003-10-13 14:11:17 +00:00
|
|
|
$text = wiki_to_html($text);
|
|
|
|
return filter_text($text);
|
2003-05-04 04:07:36 +00:00
|
|
|
break;
|
|
|
|
|
2003-02-05 12:41:59 +00:00
|
|
|
default: // FORMAT_MOODLE or anything else
|
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
|
|
|
}
|
2003-10-13 14:11:17 +00:00
|
|
|
$text = text_to_html($text, $options->smiley, $options->para);
|
|
|
|
return filter_text($text);
|
|
|
|
|
2002-10-10 07:26:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-04 04:07:36 +00:00
|
|
|
function format_text_email($text, $format) {
|
|
|
|
/// Given text in a variety of format codings, this function returns
|
|
|
|
/// the text as plain text suitable for plain email.
|
|
|
|
///
|
|
|
|
/// $text is raw text (originally from a user)
|
|
|
|
/// $format is one of the format constants, defined above
|
|
|
|
|
|
|
|
switch ($format) {
|
|
|
|
|
|
|
|
case FORMAT_PLAIN:
|
|
|
|
return $text;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FORMAT_WIKI:
|
|
|
|
$text = wiki_to_html($text);
|
2003-08-26 13:18:10 +00:00
|
|
|
/// This expression turns links into something nice in a text format. (Russell Jungwirth)
|
|
|
|
/// From: http://php.net/manual/en/function.eregi-replace.php and simplified
|
|
|
|
$text = eregi_replace('(<a [^<]*href=["|\']?([^ "\']*)["|\']?[^>]*>([^<]*)</a>)','\\3 [\\2]', $text);
|
2003-07-15 02:06:51 +00:00
|
|
|
return strtr(strip_tags($text), array_flip(get_html_translation_table(HTML_ENTITIES)));
|
2003-05-04 04:07:36 +00:00
|
|
|
break;
|
|
|
|
|
2003-11-07 03:27:21 +00:00
|
|
|
case FORMAT_HTML:
|
|
|
|
return html_to_text($text);
|
|
|
|
break;
|
|
|
|
|
2003-05-04 04:07:36 +00:00
|
|
|
default: // FORMAT_MOODLE or anything else
|
2003-08-26 13:18:10 +00:00
|
|
|
$text = eregi_replace('(<a [^<]*href=["|\']?([^ "\']*)["|\']?[^>]*>([^<]*)</a>)','\\3 [\\2]', $text);
|
2003-07-15 02:06:51 +00:00
|
|
|
return strtr(strip_tags($text), array_flip(get_html_translation_table(HTML_ENTITIES)));
|
2003-05-04 04:07:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-10-10 07:26:10 +00:00
|
|
|
|
2003-10-13 14:11:17 +00:00
|
|
|
|
|
|
|
function filter_text($text) {
|
|
|
|
/// Given some text in HTML format, this function will pass it
|
|
|
|
/// through any filters that have been defined in $CFG->textfilterx
|
|
|
|
/// The variable defines a filepath to a file containing the
|
|
|
|
/// filter function. The file must contain a variable called
|
|
|
|
/// $textfilter_function which contains the name of the function
|
|
|
|
/// with $course->id and $text parameters
|
|
|
|
|
|
|
|
global $CFG, $course; // A dirty hack right now ... should not be assumed global
|
|
|
|
|
|
|
|
if (empty($course->id)) {
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ($i=1; $i<=10; $i++) {
|
|
|
|
$variable = "textfilter$i";
|
|
|
|
if (empty($CFG->$variable)) { /// No more filters
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
if (is_readable("$CFG->dirroot/".$CFG->$variable)) {
|
|
|
|
include("$CFG->dirroot/".$CFG->$variable);
|
|
|
|
$text = $textfilter_function($course->id, $text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-10 07:26:10 +00:00
|
|
|
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
|
|
|
|
2003-06-09 03:00:23 +00:00
|
|
|
global $ALLOWED_TAGS;
|
2002-10-18 09:09:19 +00:00
|
|
|
|
2003-05-04 04:07:36 +00:00
|
|
|
switch ($format) {
|
2002-10-10 07:26:10 +00:00
|
|
|
case FORMAT_MOODLE:
|
|
|
|
case FORMAT_HTML:
|
2003-05-04 04:07:36 +00:00
|
|
|
case FORMAT_WIKI:
|
2003-08-26 13:18:10 +00:00
|
|
|
/// Remove javascript: label
|
2002-10-18 09:09:19 +00:00
|
|
|
$text = strip_tags($text, $ALLOWED_TAGS);
|
2003-08-26 13:18:10 +00:00
|
|
|
/// Remove javascript/VBScript
|
|
|
|
$text = str_ireplace("javascript:", "xxx", $text);
|
|
|
|
/// Remove script events
|
|
|
|
$text = eregi_replace("([^a-z])language([[:space:]]*)=", "xxx", $text);
|
|
|
|
$text = eregi_replace("([^a-z])on([a-z]+)([[:space:]]*)=", "xxx", $text);
|
2002-10-18 09:09:19 +00:00
|
|
|
return $text;
|
2003-04-27 10:46:16 +00:00
|
|
|
|
|
|
|
case FORMAT_PLAIN:
|
|
|
|
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
|
|
|
|
2003-05-05 16:40:46 +00:00
|
|
|
function replace_smilies(&$text) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// Replaces all known smileys in the text with image equivalents
|
2003-03-12 03:42:44 +00:00
|
|
|
global $CFG;
|
2002-10-19 04:58:14 +00:00
|
|
|
|
2003-08-26 13:18:10 +00:00
|
|
|
/// this builds the mapping array only once
|
2003-03-12 20:36:55 +00:00
|
|
|
static $runonce = false;
|
2003-03-12 21:37:05 +00:00
|
|
|
static $e = array();
|
|
|
|
static $img = array();
|
2003-03-12 20:36:55 +00:00
|
|
|
static $emoticons = array(
|
2003-03-12 03:42:44 +00:00
|
|
|
':-)' => 'smiley.gif',
|
|
|
|
':)' => 'smiley.gif',
|
|
|
|
':-D' => 'biggrin.gif',
|
|
|
|
';-)' => 'wink.gif',
|
|
|
|
':-/' => 'mixed.gif',
|
|
|
|
'V-.' => 'thoughtful.gif',
|
|
|
|
':-P' => 'tongueout.gif',
|
|
|
|
'B-)' => 'cool.gif',
|
|
|
|
'^-)' => 'approve.gif',
|
|
|
|
'8-)' => 'wideeyes.gif',
|
|
|
|
':o)' => 'clown.gif',
|
|
|
|
':-(' => 'sad.gif',
|
|
|
|
':(' => 'sad.gif',
|
|
|
|
'8-.' => 'shy.gif',
|
|
|
|
':-I' => 'blush.gif',
|
|
|
|
':-X' => 'kiss.gif',
|
|
|
|
'8-o' => 'surprise.gif',
|
|
|
|
'P-|' => 'blackeye.gif',
|
|
|
|
'8-[' => 'angry.gif',
|
|
|
|
'xx-P' => 'dead.gif',
|
|
|
|
'|-.' => 'sleepy.gif',
|
|
|
|
'}-]' => 'evil.gif',
|
|
|
|
);
|
|
|
|
|
2003-08-26 13:18:10 +00:00
|
|
|
/// this is the meat of the code - this is run every time
|
|
|
|
if ($runonce == false){
|
2003-03-12 20:36:55 +00:00
|
|
|
foreach ($emoticons as $emoticon => $image){
|
2003-03-12 21:37:05 +00:00
|
|
|
$e[] = $emoticon;
|
2003-09-21 15:45:24 +00:00
|
|
|
$img[] = "<img alt=\"$emoticon\" width=\"15\" height=\"15\" src=\"$CFG->pixpath/s/$image\" />";
|
2003-03-12 20:36:55 +00:00
|
|
|
}
|
|
|
|
$runonce = true;
|
2003-03-12 21:40:47 +00:00
|
|
|
}
|
2002-03-26 12:58:54 +00:00
|
|
|
|
2003-05-05 16:40:46 +00:00
|
|
|
$text = str_replace($e, $img, $text);
|
2002-10-12 05:09:49 +00:00
|
|
|
}
|
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
|
|
|
|
2003-08-27 06:08:34 +00:00
|
|
|
global $CFG;
|
|
|
|
|
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
|
|
|
|
2003-05-05 16:40:46 +00:00
|
|
|
convert_urls_into_links($text);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
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) {
|
2003-05-05 16:40:46 +00:00
|
|
|
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) {
|
2003-05-05 16:28:40 +00:00
|
|
|
return "<p>".$text."</p>";
|
2002-08-12 13:45:41 +00:00
|
|
|
} else {
|
|
|
|
return $text;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2003-05-01 03:43:16 +00:00
|
|
|
function wiki_to_html($text) {
|
2003-05-05 16:28:40 +00:00
|
|
|
/// Given Wiki formatted text, make it into XHTML using external function
|
2003-07-11 08:38:39 +00:00
|
|
|
global $CFG;
|
2003-05-01 03:43:16 +00:00
|
|
|
|
2003-07-11 08:38:39 +00:00
|
|
|
require_once("$CFG->libdir/wiki.php");
|
2003-05-01 03:43:16 +00:00
|
|
|
|
2003-05-05 16:28:40 +00:00
|
|
|
$wiki = new Wiki;
|
|
|
|
return $wiki->format($text);
|
2003-05-01 03:43:16 +00:00
|
|
|
}
|
|
|
|
|
2003-11-07 03:27:21 +00:00
|
|
|
function html_to_text($html) {
|
|
|
|
/// Given HTML text, make it into plain text using external function
|
2003-11-07 04:14:38 +00:00
|
|
|
global $CFG;
|
2003-11-07 03:27:21 +00:00
|
|
|
|
|
|
|
require_once("$CFG->libdir/html2text.php");
|
|
|
|
|
|
|
|
return html2text($html);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-05 16:40:46 +00:00
|
|
|
function convert_urls_into_links(&$text) {
|
|
|
|
/// Given some text, it converts any URLs it finds into HTML links.
|
|
|
|
|
|
|
|
/// Make lone URLs into links. eg http://moodle.com/
|
2003-07-02 11:59:20 +00:00
|
|
|
$text = eregi_replace("([[:space:]]|^|\(|\[)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
|
2003-08-09 03:57:46 +00:00
|
|
|
"\\1<a href=\"\\2://\\3\\4\" target=\"newpage\">\\2://\\3\\4</a>", $text);
|
2003-05-05 16:40:46 +00:00
|
|
|
|
|
|
|
/// eg www.moodle.com
|
2003-07-02 11:59:20 +00:00
|
|
|
$text = eregi_replace("([[:space:]]|^|\(|\[)www\.([^[:space:]]*)([[:alnum:]#?/&=])",
|
2003-08-09 03:57:46 +00:00
|
|
|
"\\1<a href=\"http://www.\\2\\3\" target=\"newpage\">www.\\2\\3</a>", $text);
|
2003-05-05 16:40:46 +00:00
|
|
|
}
|
|
|
|
|
2003-08-09 03:57:46 +00:00
|
|
|
function highlight($needle, $haystack, $case=0,
|
|
|
|
$left_string="<span class=\"highlight\">", $right_string="</span>") {
|
|
|
|
/// This function will highlight search words in a given string
|
|
|
|
/// It cares about HTML and will not ruin links. It's best to use
|
|
|
|
/// this function after performing any conversions to HTML.
|
|
|
|
/// Function found here: http://forums.devshed.com/t67822/scdaa2d1c3d4bacb4671d075ad41f0854.html
|
|
|
|
|
|
|
|
$list_of_words = eregi_replace("[^-a-zA-Z0-9&']", " ", $needle);
|
|
|
|
$list_array = explode(" ", $list_of_words);
|
|
|
|
for ($i=0; $i<sizeof($list_array); $i++) {
|
|
|
|
if (strlen($list_array[$i]) == 1) {
|
|
|
|
$list_array[$i] = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$list_of_words = implode(" ", $list_array);
|
|
|
|
$list_of_words_cp = $list_of_words;
|
|
|
|
$final = array();
|
|
|
|
preg_match_all('/<(.+?)>/is',$haystack,$list_of_words);
|
|
|
|
|
|
|
|
foreach (array_unique($list_of_words[0]) as $key=>$value) {
|
|
|
|
$final['<|'.$key.'|>'] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
$haystack = str_replace($final,array_keys($final),$haystack);
|
|
|
|
$list_of_words_cp = eregi_replace(" +", "|", $list_of_words_cp);
|
|
|
|
|
|
|
|
if ($list_of_words_cp{0}=="|") {
|
|
|
|
$list_of_words_cp{0} = "";
|
|
|
|
}
|
|
|
|
if ($list_of_words_cp{strlen($list_of_words_cp)-1}=="|") {
|
|
|
|
$list_of_words_cp{strlen($list_of_words_cp)-1}="";
|
|
|
|
}
|
|
|
|
$list_of_words_cp = "(".trim($list_of_words_cp).")";
|
|
|
|
|
|
|
|
if (!$case){
|
|
|
|
$haystack = eregi_replace("$list_of_words_cp", "$left_string"."\\1"."$right_string", $haystack);
|
|
|
|
} else {
|
|
|
|
$haystack = ereg_replace("$list_of_words_cp", "$left_string"."\\1"."$right_string", $haystack);
|
|
|
|
}
|
|
|
|
$haystack = str_replace(array_keys($final),$final,$haystack);
|
|
|
|
|
|
|
|
return stripslashes($haystack);
|
|
|
|
}
|
|
|
|
|
|
|
|
function highlightfast($needle, $haystack) {
|
2002-10-19 04:58:14 +00:00
|
|
|
/// This function will highlight instances of $needle in $haystack
|
2003-08-09 03:57:46 +00:00
|
|
|
/// It's faster that the above function and doesn't care about
|
|
|
|
/// HTML or anything.
|
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);
|
|
|
|
|
2003-08-09 03:57:46 +00:00
|
|
|
$parts[$key] .= "<span class=\"highlight\">".substr($haystack, $pos, strlen($needle))."</span>";
|
2002-06-11 07:01:51 +00:00
|
|
|
$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 ///////////////////////////////////////////////////
|
|
|
|
|
2003-09-21 15:45:24 +00:00
|
|
|
function print_header ($title="", $heading="", $navigation="", $focus="", $meta="",
|
|
|
|
$cache=true, $button=" ", $menu="", $usexml=false) {
|
2002-12-20 14:44:14 +00:00
|
|
|
// $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)
|
2003-09-21 15:45:24 +00:00
|
|
|
// $menu - HTML code for a popup menu
|
|
|
|
// $usexml - use XML for this page
|
2003-05-08 16:09:30 +00:00
|
|
|
global $USER, $CFG, $THEME, $SESSION;
|
2002-12-20 14:44:14 +00:00
|
|
|
|
|
|
|
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)) {
|
2003-09-21 15:45:24 +00:00
|
|
|
$menu = "<font size=\"2\"><a target=\"$CFG->framename\" href=\"$CFG->wwwroot/login/logout.php\">".get_string("logout")."</a></font>";
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2003-09-21 15:45:24 +00:00
|
|
|
$menu = "<font size=\"2\"><a target=\"$CFG->framename\" href=\"$CFG->wwwroot/login/index.php\">".get_string("login")."</a></font>";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-03 15:17:21 +00:00
|
|
|
// Add a stylesheet for the HTML editor
|
|
|
|
$meta = "<style type=\"text/css\">@import url($CFG->wwwroot/lib/editor/htmlarea.css);</style>\n$meta\n";
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
// 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") {
|
2003-09-21 15:45:24 +00:00
|
|
|
$meta = "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\" />\n$meta\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2003-09-21 15:45:24 +00:00
|
|
|
$meta = "<meta http-equiv=\"content-type\" content=\"text/html; charset=".get_string("thischarset")."\" />\n$meta\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 14:05:57 +00:00
|
|
|
if ( get_string("thisdirection") == "rtl" ) {
|
2003-05-03 06:49:37 +00:00
|
|
|
$direction = " dir=\"rtl\"";
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2003-05-03 06:49:37 +00:00
|
|
|
$direction = " dir=\"ltr\"";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2003-09-21 15:45:24 +00:00
|
|
|
$meta .= "\n<meta http-equiv=\"pragma\" content=\"no-cache\" />";
|
|
|
|
$meta .= "\n<meta http-equiv=\"expires\" content=\"0\" />";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($usexml) { // Added by Gustav Delius / Mad Alex for MathML output
|
|
|
|
$currentlanguage = current_language();
|
|
|
|
|
|
|
|
@header("Content-type: text/xml");
|
|
|
|
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n";
|
|
|
|
if (!empty($CFG->xml_stylesheets)) {
|
|
|
|
$stylesheets = explode(";", $CFG->xml_stylesheets);
|
|
|
|
foreach ($stylesheets as $stylesheet) {
|
|
|
|
echo "<?xml-stylesheet type=\"text/xsl\" href=\"$CFG->wwwroot/$stylesheet\" ?>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1";
|
2003-09-21 16:35:49 +00:00
|
|
|
if (!empty($CFG->xml_doctype_extra)) {
|
2003-09-21 15:45:24 +00:00
|
|
|
echo " plus $CFG->xml_doctype_extra";
|
2003-09-21 16:35:49 +00:00
|
|
|
}
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "//" . strtoupper($currentlanguage) . "\" \"$CFG->xml_dtd\">\n";
|
|
|
|
$direction = " xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$currentlanguage\" $direction";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2003-10-24 06:27:15 +00:00
|
|
|
$title = str_replace('"', '"', $title);
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
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
|
2003-05-14 05:01:01 +00:00
|
|
|
$homelink = "<p align=\"center\"><a title=\"moodle $CFG->release ($CFG->version)\" href=\"http://moodle.org/\" target=\"_blank\">";
|
2003-09-21 15:45:24 +00:00
|
|
|
$homelink .= "<br /><img width=\"130\" height=\"19\" src=\"pix/madewithmoodle.gif\" border=\"0\" /></a></p>";
|
2002-12-20 14:44:14 +00:00
|
|
|
$course = get_site();
|
|
|
|
$homepage = true;
|
|
|
|
} else {
|
2003-05-14 05:01:01 +00:00
|
|
|
$homelink = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-07-30 13:02:45 +00:00
|
|
|
$homelink = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/\">".get_string("home")."</a>";
|
2002-12-20 14:44:14 +00:00
|
|
|
$course = get_site();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// User links
|
2003-04-25 06:40:30 +00:00
|
|
|
$loggedinas = user_login_string($course, $USER);
|
|
|
|
|
|
|
|
include ("$CFG->dirroot/theme/$CFG->theme/footer.html");
|
|
|
|
}
|
|
|
|
|
2003-08-12 08:29:47 +00:00
|
|
|
function style_sheet_setup($lastmodified=0, $lifetime=300, $themename="") {
|
|
|
|
/// This function is called by stylesheets to set up the header
|
|
|
|
/// approriately as well as the current path
|
2003-08-12 07:52:19 +00:00
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
|
|
|
|
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT");
|
|
|
|
header("Cache-control: max_age = $lifetime");
|
|
|
|
header("Pragma: ");
|
|
|
|
header("Content-type: text/css"); // Correct MIME type
|
|
|
|
|
|
|
|
if (!empty($themename)) {
|
|
|
|
$CFG->theme = $themename;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "$CFG->wwwroot/theme/$CFG->theme";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-04-25 06:40:30 +00:00
|
|
|
|
|
|
|
function user_login_string($course, $user=NULL) {
|
|
|
|
global $USER, $CFG;
|
|
|
|
|
2003-05-26 07:54:53 +00:00
|
|
|
if (empty($user)) {
|
2003-04-25 06:40:30 +00:00
|
|
|
$user = $USER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($user->realuser)) {
|
|
|
|
if ($realuser = get_record("user", "id", $user->realuser)) {
|
2003-09-21 15:45:24 +00:00
|
|
|
$realuserinfo = " [<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&return=$realuser->id\">$realuser->firstname $realuser->lastname</a>] ";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2002-12-29 04:17:32 +00:00
|
|
|
} else {
|
|
|
|
$realuserinfo = "";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2003-04-25 06:40:30 +00:00
|
|
|
if (isset($user->id) and $user->id) {
|
2003-09-21 15:45:24 +00:00
|
|
|
$username = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</a>";
|
2002-12-20 14:44:14 +00:00
|
|
|
$loggedinas = $realuserinfo.get_string("loggedinas", "moodle", "$username").
|
2003-04-29 13:54:53 +00:00
|
|
|
" (<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/login/logout.php\">".get_string("logout")."</a>)";
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
|
|
|
$loggedinas = get_string("loggedinnot", "moodle").
|
2003-04-29 13:54:53 +00:00
|
|
|
" (<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/login/index.php\">".get_string("login")."</a>)";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2003-04-25 06:40:30 +00:00
|
|
|
return $loggedinas;
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function print_navigation ($navigation) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($navigation) {
|
|
|
|
if (! $site = get_site()) {
|
|
|
|
$site->shortname = get_string("home");;
|
|
|
|
}
|
2003-05-04 03:00:52 +00:00
|
|
|
echo "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/\">$site->shortname</a> -> $navigation";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-21 04:53:55 +00:00
|
|
|
function print_headline($text, $size=2) {
|
|
|
|
echo "<b><font size=\"$size\">$text</font></b><br />\n";
|
|
|
|
}
|
|
|
|
|
2003-05-14 05:01:01 +00:00
|
|
|
function print_heading($text, $align="center", $size=3) {
|
|
|
|
echo "<p align=\"$align\"><font size=\"$size\"><b>".stripslashes_safe($text)."</b></font></p>";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 12:25:16 +00:00
|
|
|
function print_heading_with_help($text, $helppage, $module="moodle", $icon="") {
|
2002-12-20 14:44:14 +00:00
|
|
|
// Centered heading with attached help button (same title text)
|
2003-09-14 12:25:16 +00:00
|
|
|
// and optional icon attached
|
|
|
|
echo "<p align=\"center\"><font size=\"3\">$icon<b>".stripslashes_safe($text);
|
2002-12-20 14:44:14 +00:00
|
|
|
helpbutton($helppage, $text, $module);
|
2003-05-04 03:00:52 +00:00
|
|
|
echo "</b></font></p>";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function print_continue($link) {
|
|
|
|
|
|
|
|
if (!$link) {
|
2003-01-05 06:45:20 +00:00
|
|
|
$link = $_SERVER["HTTP_REFERER"];
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2003-05-04 03:00:52 +00:00
|
|
|
print_heading("<a href=\"$link\">".get_string("continue")."</a>");
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function print_simple_box($message, $align="", $width="", $color="#FFFFFF", $padding=5, $class="generalbox") {
|
|
|
|
print_simple_box_start($align, $width, $color, $padding, $class);
|
2003-01-23 13:07:49 +00:00
|
|
|
echo stripslashes_safe($message);
|
2002-12-20 14:44:14 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_simple_box_start($align="", $width="", $color="#FFFFFF", $padding=5, $class="generalbox") {
|
|
|
|
global $THEME;
|
|
|
|
|
|
|
|
if ($align) {
|
2003-05-14 05:01:01 +00:00
|
|
|
$align = "align=\"$align\"";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
if ($width) {
|
2003-05-14 05:01:01 +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>";
|
|
|
|
}
|
|
|
|
|
2003-05-18 16:41:23 +00:00
|
|
|
function print_single_button($link, $options, $label="OK", $method="get") {
|
|
|
|
echo "<form action=\"$link\" method=\"$method\">";
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($options) {
|
|
|
|
foreach ($options as $name => $value) {
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "<input type=\"submit\" value=\"$label\" /></form>";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function print_spacer($height=1, $width=1, $br=true) {
|
|
|
|
global $CFG;
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "<img height=\"$height\" width=\"$width\" src=\"$CFG->wwwroot/pix/spacer.gif\" alt=\"\" />";
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($br) {
|
2003-05-14 05:01:01 +00:00
|
|
|
echo "<br />\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2003-05-14 05:01:01 +00:00
|
|
|
$height = "height=\"$height\"";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
if ($width) {
|
2003-05-14 05:01:01 +00:00
|
|
|
$width = "width=\"$width\"";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
if ($link) {
|
2003-05-14 05:01:01 +00:00
|
|
|
echo "<a href=\"$link\">";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
if (substr(strtolower($path), 0, 7) == "http://") {
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "<img border=\"0\" $height $width src=\"$path\" />";
|
2002-12-20 14:44:14 +00:00
|
|
|
|
|
|
|
} else if ($courseid) {
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "<img border=\"0\" $height $width src=\"";
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($CFG->slasharguments) { // Use this method if possible for better caching
|
|
|
|
echo "$CFG->wwwroot/file.php/$courseid/$path";
|
|
|
|
} else {
|
2003-02-11 01:53:10 +00:00
|
|
|
echo "$CFG->wwwroot/file.php?file=/$courseid/$path";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "\" />";
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
|
|
|
echo "Error: must pass URL or course";
|
|
|
|
}
|
|
|
|
if ($link) {
|
2003-05-14 05:01:01 +00:00
|
|
|
echo "</a>";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_user_picture($userid, $courseid, $picture, $large=false, $returnstring=false, $link=true) {
|
2003-07-28 11:42:53 +00:00
|
|
|
global $CFG, $THEME;
|
2002-12-20 14:44:14 +00:00
|
|
|
|
|
|
|
if ($link) {
|
2003-09-21 15:45:24 +00:00
|
|
|
$output = "<a href=\"$CFG->wwwroot/user/view.php?id=$userid&course=$courseid\">";
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
|
|
|
$output = "";
|
|
|
|
}
|
|
|
|
if ($large) {
|
2003-07-28 11:42:53 +00:00
|
|
|
$file = "f1";
|
2002-12-20 14:44:14 +00:00
|
|
|
$size = 100;
|
|
|
|
} else {
|
2003-07-28 11:42:53 +00:00
|
|
|
$file = "f2";
|
2002-12-20 14:44:14 +00:00
|
|
|
$size = 35;
|
|
|
|
}
|
2003-07-28 11:42:53 +00:00
|
|
|
if ($picture) { // Print custom user picture
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($CFG->slasharguments) { // Use this method if possible for better caching
|
2003-07-28 11:42:53 +00:00
|
|
|
$output .= "<img align=\"absmiddle\" src=\"$CFG->wwwroot/user/pix.php/$userid/$file.jpg\"".
|
2003-09-21 15:45:24 +00:00
|
|
|
" border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2003-07-28 11:42:53 +00:00
|
|
|
$output .= "<img align=\"absmiddle\" src=\"$CFG->wwwroot/user/pix.php?file=/$userid/$file.jpg\"".
|
2003-09-21 15:45:24 +00:00
|
|
|
" border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2003-07-28 11:42:53 +00:00
|
|
|
} else { // Print default user pictures (use theme version if available)
|
2003-09-14 12:25:16 +00:00
|
|
|
$output .= "<img align=\"absmiddle\" src=\"$CFG->pixpath/u/$file.png\"".
|
2003-09-21 15:45:24 +00:00
|
|
|
" border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
if ($link) {
|
2003-05-14 05:01:01 +00:00
|
|
|
$output .= "</a>";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2003-05-09 17:24:17 +00:00
|
|
|
// $table->wrap is an array of "nowrap"s or nothing
|
2002-12-20 14:44:14 +00:00
|
|
|
// $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) {
|
2003-05-14 05:01:01 +00:00
|
|
|
$align[$key] = " align=\"$aa\"";
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
|
|
|
$align[$key] = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($table->size)) {
|
|
|
|
foreach ($table->size as $key => $ss) {
|
|
|
|
if ($ss) {
|
2003-05-14 05:01:01 +00:00
|
|
|
$size[$key] = " width=\"$ss\"";
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
|
|
|
$size[$key] = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-05-09 17:24:17 +00:00
|
|
|
if (isset($table->wrap)) {
|
|
|
|
foreach ($table->wrap as $key => $ww) {
|
|
|
|
if ($ww) {
|
2003-09-21 15:45:24 +00:00
|
|
|
$wrap[$key] = " nowrap=\"nowrap\" ";
|
2003-05-09 17:24:17 +00:00
|
|
|
} else {
|
|
|
|
$wrap[$key] = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2003-05-09 17:24:17 +00:00
|
|
|
print_simple_box_start("center", "$table->width", "#ffffff", 0);
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "<table width=\"100%\" border=\"0\" valign=\"top\" align=\"center\" ";
|
2002-12-20 14:44:14 +00:00
|
|
|
echo " cellpadding=\"$table->cellpadding\" cellspacing=\"$table->cellspacing\" class=\"generaltable\">\n";
|
|
|
|
|
2003-01-01 15:13:21 +00:00
|
|
|
if (!empty($table->head)) {
|
2003-05-09 17:24:17 +00:00
|
|
|
echo "<tr>";
|
2002-12-20 14:44:14 +00:00
|
|
|
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] = "";
|
|
|
|
}
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "<th valign=\"top\" ".$align[$key].$size[$key]." nowrap=\"nowrap\" class=\"generaltableheader\">$heading</th>";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "</tr>\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2003-09-23 12:18:27 +00:00
|
|
|
if (!empty($table->data)) {
|
|
|
|
foreach ($table->data as $row) {
|
|
|
|
echo "<tr valign=\"top\">";
|
|
|
|
foreach ($row as $key => $item) {
|
|
|
|
if (!isset($size[$key])) {
|
|
|
|
$size[$key] = "";
|
|
|
|
}
|
|
|
|
if (!isset($align[$key])) {
|
|
|
|
$align[$key] = "";
|
|
|
|
}
|
|
|
|
if (!isset($wrap[$key])) {
|
|
|
|
$wrap[$key] = "";
|
|
|
|
}
|
|
|
|
echo "<td ".$align[$key].$size[$key].$wrap[$key]." class=\"generaltablecell\">$item</td>";
|
|
|
|
}
|
|
|
|
echo "</tr>\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-09 17:24:17 +00:00
|
|
|
echo "</table>\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-08-18 16:40:27 +00:00
|
|
|
function make_table($table) {
|
|
|
|
// Creates a nicely formatted table and returns it
|
|
|
|
// $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->wrap is an array of "nowrap"s or nothing
|
|
|
|
// $table->data[] is an array of arrays containing the data.
|
|
|
|
// $table->width is an percentage of the page
|
|
|
|
// $table->class is a class
|
|
|
|
// $table->fontsize is the size of all the text
|
|
|
|
// $table->tablealign align the whole table
|
|
|
|
// $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] = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($table->wrap)) {
|
|
|
|
foreach ($table->wrap as $key => $ww) {
|
|
|
|
if ($ww) {
|
2003-09-21 15:45:24 +00:00
|
|
|
$wrap[$key] = " nowrap=\"nowrap\" ";
|
2003-08-18 16:40:27 +00:00
|
|
|
} else {
|
|
|
|
$wrap[$key] = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($table->width)) {
|
|
|
|
$table->width = "80%";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($table->tablealign)) {
|
|
|
|
$table->tablealign = "center";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($table->cellpadding)) {
|
|
|
|
$table->cellpadding = "5";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($table->cellspacing)) {
|
|
|
|
$table->cellspacing = "1";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($table->class)) {
|
|
|
|
$table->class = "generaltable";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($table->fontsize)) {
|
|
|
|
$fontsize = "";
|
|
|
|
} else {
|
|
|
|
$fontsize = "<font size=\"$table->fontsize\">";
|
|
|
|
}
|
|
|
|
|
2003-09-21 15:45:24 +00:00
|
|
|
$output = "<table width=\"$table->width\" valign=\"top\" align=\"$table->tablealign\" ";
|
2003-08-18 16:40:27 +00:00
|
|
|
$output .= " cellpadding=\"$table->cellpadding\" cellspacing=\"$table->cellspacing\" class=\"$table->class\">\n";
|
|
|
|
|
|
|
|
if (!empty($table->head)) {
|
|
|
|
$output .= "<tr>";
|
|
|
|
foreach ($table->head as $key => $heading) {
|
|
|
|
if (!isset($size[$key])) {
|
|
|
|
$size[$key] = "";
|
|
|
|
}
|
|
|
|
if (!isset($align[$key])) {
|
|
|
|
$align[$key] = "";
|
|
|
|
}
|
2003-09-21 15:45:24 +00:00
|
|
|
$output .= "<th valign=\"top\" ".$align[$key].$size[$key]." nowrap=\"nowrap\" class=\"{$table->class}header\">$fontsize$heading</th>";
|
2003-08-18 16:40:27 +00:00
|
|
|
}
|
|
|
|
$output .= "</tr>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($table->data as $row) {
|
2003-09-21 15:45:24 +00:00
|
|
|
$output .= "<tr valign=\"top\">";
|
2003-08-18 16:40:27 +00:00
|
|
|
foreach ($row as $key => $item) {
|
|
|
|
if (!isset($size[$key])) {
|
|
|
|
$size[$key] = "";
|
|
|
|
}
|
|
|
|
if (!isset($align[$key])) {
|
|
|
|
$align[$key] = "";
|
|
|
|
}
|
|
|
|
if (!isset($wrap[$key])) {
|
|
|
|
$wrap[$key] = "";
|
|
|
|
}
|
|
|
|
$output .= "<td ".$align[$key].$size[$key].$wrap[$key]." class=\"{$table->class}cell\">$fontsize$item</td>";
|
|
|
|
}
|
|
|
|
$output .= "</tr>\n";
|
|
|
|
}
|
|
|
|
$output .= "</table>\n";
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2003-11-03 15:17:21 +00:00
|
|
|
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value="", $courseid=0) {
|
|
|
|
/// Prints a basic textarea field
|
|
|
|
/// $width and height are legacy fields and no longer used
|
2003-10-29 08:06:11 +00:00
|
|
|
|
2003-11-03 15:17:21 +00:00
|
|
|
global $CFG, $course;
|
2003-10-12 17:12:02 +00:00
|
|
|
|
2003-10-12 17:24:46 +00:00
|
|
|
if (empty($courseid)) {
|
2003-10-12 17:12:02 +00:00
|
|
|
if (!empty($course->id)) { // search for it in global context
|
|
|
|
$courseid = $course->id;
|
|
|
|
}
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2003-11-03 15:17:21 +00:00
|
|
|
if ($usehtmleditor) {
|
|
|
|
if (!empty($courseid) and isteacher($courseid)) {
|
|
|
|
echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/htmlarea.php?id=$courseid\"></script>\n";
|
|
|
|
} else {
|
|
|
|
echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/htmlarea.php\"></script>\n";
|
|
|
|
}
|
|
|
|
echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/dialog.js\"></script>\n";
|
|
|
|
echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/lang/en.php\"></script>\n";
|
|
|
|
echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/popupwin.js\"></script>\n";
|
2003-10-12 17:12:02 +00:00
|
|
|
|
2003-11-03 15:17:21 +00:00
|
|
|
if ($rows < 20) {
|
|
|
|
$rows = 20;
|
|
|
|
}
|
|
|
|
if ($cols < 65) {
|
|
|
|
$cols = 65;
|
2003-10-29 08:06:11 +00:00
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2003-11-03 15:17:21 +00:00
|
|
|
|
|
|
|
echo "<textarea id=\"$name\" name=\"$name\" rows=\"$rows\" cols=\"$cols\" wrap=\"virtual\">";
|
|
|
|
p($value);
|
|
|
|
echo "</textarea>\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function print_richedit_javascript($form, $name, $source="no") {
|
2003-11-03 15:17:21 +00:00
|
|
|
/// Legacy function, provided for backward compatability
|
|
|
|
use_html_editor($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
function use_html_editor($name="") {
|
|
|
|
/// Sets up the HTML editor on textareas in the current page.
|
|
|
|
/// If a field name is provided, then it will only be
|
|
|
|
/// applied to that field - otherwise it will be used
|
|
|
|
/// on every textarea in the page.
|
|
|
|
///
|
|
|
|
/// In most cases no arguments need to be supplied
|
2003-10-29 08:06:11 +00:00
|
|
|
|
2003-11-03 15:17:21 +00:00
|
|
|
echo "<script language=\"javascript\" type=\"text/javascript\" defer=\"1\">\n";
|
|
|
|
if (empty($name)) {
|
|
|
|
echo "HTMLArea.replaceAll();";
|
|
|
|
} else {
|
|
|
|
echo "HTMLArea.replace('$name')";
|
2003-10-29 08:06:11 +00:00
|
|
|
}
|
2003-11-03 15:17:21 +00:00
|
|
|
echo "</script>";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function update_course_icon($courseid) {
|
|
|
|
// Used to be an icon, but it's now a simple form button
|
|
|
|
global $CFG, $USER;
|
|
|
|
|
2003-08-16 06:44:03 +00:00
|
|
|
if (isteacheredit($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";
|
|
|
|
}
|
2003-09-21 15:45:24 +00:00
|
|
|
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>";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_module_button($moduleid, $courseid, $string) {
|
|
|
|
// Prints the editing button on a module "view" page
|
|
|
|
global $CFG;
|
|
|
|
|
2003-08-16 06:44:03 +00:00
|
|
|
if (isteacheredit($courseid)) {
|
2002-12-20 14:44:14 +00:00
|
|
|
$string = get_string("updatethis", "", $string);
|
2003-09-21 15:45:24 +00:00
|
|
|
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>";
|
2003-08-16 06:44:03 +00:00
|
|
|
} else {
|
|
|
|
return "";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-30 13:02:45 +00:00
|
|
|
function update_category_button($categoryid) {
|
2003-08-07 16:01:31 +00:00
|
|
|
// Prints the editing button on a category page
|
|
|
|
global $CFG, $USER;
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
if (iscreator()) {
|
|
|
|
if (!empty($USER->editing)) {
|
|
|
|
$string = get_string("turneditingoff");
|
|
|
|
$edit = "off";
|
|
|
|
} else {
|
|
|
|
$string = get_string("turneditingon");
|
|
|
|
$edit = "on";
|
2003-08-22 12:26:36 +00:00
|
|
|
}
|
2003-09-21 15:45:24 +00:00
|
|
|
return "<form method=\"get\" action=\"$CFG->wwwroot/course/category.php\">".
|
|
|
|
"<input type=\"hidden\" name=\"id\" value=\"$categoryid\" />".
|
|
|
|
"<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
|
|
|
|
"<input type=\"submit\" value=\"$string\" /></form>";
|
2003-08-07 16:01:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_categories_button() {
|
|
|
|
// Prints the editing button on categories listing
|
|
|
|
global $CFG, $USER;
|
|
|
|
|
|
|
|
if (isadmin()) {
|
|
|
|
if (!empty($USER->editing)) {
|
|
|
|
$string = get_string("turneditingoff");
|
|
|
|
$edit = "off";
|
|
|
|
} else {
|
|
|
|
$string = get_string("turneditingon");
|
|
|
|
$edit = "on";
|
|
|
|
}
|
2003-09-21 15:45:24 +00:00
|
|
|
return "<form target=\"_parent\" method=\"get\" action=\"$CFG->wwwroot/course/index.php\">".
|
|
|
|
"<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
|
|
|
|
"<input type=\"submit\" value=\"$string\" /></form>";
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2003-08-26 06:01:13 +00:00
|
|
|
function navmenu($course, $cm=NULL, $targetwindow="self") {
|
2002-12-20 14:44:14 +00:00
|
|
|
// 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) {
|
2003-09-15 11:59:15 +00:00
|
|
|
if ($mod->mod == "label") {
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($mod->section > 0 and $section <> $mod->section) {
|
|
|
|
$menu[] = "-------------- $strsection $mod->section --------------";
|
|
|
|
}
|
|
|
|
$section = $mod->section;
|
2003-04-23 16:32:11 +00:00
|
|
|
//Only add visible or teacher mods to jumpmenu
|
|
|
|
if ($mod->visible or isteacher($course->id)) {
|
|
|
|
$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)."...";
|
|
|
|
}
|
2003-04-23 17:25:20 +00:00
|
|
|
if (!$mod->visible) {
|
|
|
|
$mod->name = "(".$mod->name.")";
|
|
|
|
}
|
2003-04-23 16:32:11 +00:00
|
|
|
$menu[$url] = $mod->name;
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-26 06:01:13 +00:00
|
|
|
return popup_form("$CFG->wwwroot/mod/", $menu, "navmenu", $selected, get_string("jumpto"),
|
|
|
|
"", "", true, $targetwindow);
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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++) {
|
2003-01-10 05:40:35 +00:00
|
|
|
$months[$i] = userdate(gmmktime(12,0,0,$i,1,2000), "%B");
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-08-25 12:47:36 +00:00
|
|
|
function print_grade_menu($courseid, $name, $current, $includenograde=true) {
|
2003-08-18 05:28:30 +00:00
|
|
|
/// Prints a grade menu (as part of an existing form) with help
|
|
|
|
/// Showing all possible numerical grades and scales
|
|
|
|
|
2003-09-14 12:25:16 +00:00
|
|
|
global $CFG;
|
2003-08-18 05:28:30 +00:00
|
|
|
|
|
|
|
$strscale = get_string("scale");
|
|
|
|
$strscales = get_string("scales");
|
|
|
|
|
2003-08-18 11:58:07 +00:00
|
|
|
$scales = get_scales_menu($courseid);
|
2003-08-18 05:28:30 +00:00
|
|
|
foreach ($scales as $i => $scalename) {
|
|
|
|
$grades[-$i] = "$strscale: $scalename";
|
|
|
|
}
|
2003-08-25 12:47:36 +00:00
|
|
|
if ($includenograde) {
|
|
|
|
$grades[0] = get_string("nograde");
|
|
|
|
}
|
2003-08-18 05:28:30 +00:00
|
|
|
for ($i=100; $i>=1; $i--) {
|
|
|
|
$grades[$i] = $i;
|
|
|
|
}
|
|
|
|
choose_from_menu($grades, "$name", "$current", "");
|
|
|
|
|
2003-09-14 12:25:16 +00:00
|
|
|
$helpicon = "$CFG->pixpath/help.gif";
|
2003-09-21 15:45:24 +00:00
|
|
|
$linkobject = "<img align=\"absmiddle\" border=\"0\" height=\"17\" width=\"22\" alt=\"$strscales\" src=\"$helpicon\" />";
|
|
|
|
link_to_popup_window ("/course/scales.php?id=$courseid&list=true", "ratingscales",
|
2003-08-18 05:28:30 +00:00
|
|
|
$linkobject, 400, 500, $strscales);
|
|
|
|
}
|
|
|
|
|
2003-08-15 13:59:24 +00:00
|
|
|
function print_scale_menu($courseid, $name, $current) {
|
|
|
|
/// Prints a scale menu (as part of an existing form) including help button
|
2003-08-18 05:28:30 +00:00
|
|
|
/// Just like print_grade_menu but without the numerical grades
|
2003-08-15 13:59:24 +00:00
|
|
|
|
2003-09-14 12:25:16 +00:00
|
|
|
global $CFG;
|
2003-08-15 13:59:24 +00:00
|
|
|
|
|
|
|
$strscales = get_string("scales");
|
|
|
|
choose_from_menu(get_scales_menu($courseid), "$name", $current, "");
|
2003-09-14 12:25:16 +00:00
|
|
|
$helpicon = "$CFG->pixpath/help.gif";
|
2003-09-21 15:45:24 +00:00
|
|
|
$linkobject = "<img align=\"absmiddle\" border=\"0\" height=\"17\" width=\"22\" alt=\"$strscales\" src=\"$helpicon\" />";
|
|
|
|
link_to_popup_window ("/course/scales.php?id=$courseid&list=true", "ratingscales",
|
2003-08-15 13:59:24 +00:00
|
|
|
$linkobject, 400, 500, $strscales);
|
|
|
|
}
|
|
|
|
|
2003-08-18 05:10:35 +00:00
|
|
|
|
2003-08-15 13:59:24 +00:00
|
|
|
function print_scale_menu_helpbutton($courseid, $scale) {
|
|
|
|
/// Prints a help button about a scale
|
|
|
|
/// scale is an object
|
|
|
|
|
2003-09-14 12:25:16 +00:00
|
|
|
global $CFG;
|
2003-08-15 13:59:24 +00:00
|
|
|
|
|
|
|
$strscales = get_string("scales");
|
2003-09-14 12:25:16 +00:00
|
|
|
$helpicon = "$CFG->pixpath/help.gif";
|
2003-09-21 15:45:24 +00:00
|
|
|
$linkobject = "<img align=\"absmiddle\" border=\"0\" height=\"17\" width=\"22\" alt=\"$scale->name\" src=\"$helpicon\" />";
|
|
|
|
link_to_popup_window ("/course/scales.php?id=$courseid&list=true&scale=$scale->id", "ratingscale",
|
2003-08-15 13:59:24 +00:00
|
|
|
$linkobject, 400, 500, $scale->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
function error ($message, $link="") {
|
|
|
|
global $CFG, $SESSION;
|
|
|
|
|
|
|
|
print_header(get_string("error"));
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "<br />";
|
2002-12-20 14:44:14 +00:00
|
|
|
print_simple_box($message, "center", "", "#FFBBBB");
|
|
|
|
|
|
|
|
if (!$link) {
|
|
|
|
if ( !empty($SESSION->fromurl) ) {
|
|
|
|
$link = "$SESSION->fromurl";
|
|
|
|
unset($SESSION->fromurl);
|
|
|
|
} else {
|
2003-07-30 13:02:45 +00:00
|
|
|
$link = "$CFG->wwwroot/";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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.
|
2003-04-28 04:32:55 +00:00
|
|
|
global $CFG, $THEME;
|
2002-12-20 14:44:14 +00:00
|
|
|
|
|
|
|
if ($module == "") {
|
|
|
|
$module = "moodle";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($image) {
|
2003-09-14 12:25:16 +00:00
|
|
|
$icon = "$CFG->pixpath/help.gif";
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($linktext) {
|
2003-11-06 11:47:23 +00:00
|
|
|
$linkobject = "<span style=\"cursor:help;\">$title<img align=\"absmiddle\" border=\"0\" ".
|
|
|
|
" height=\"17\" width=\"22\" alt=\"\" src=\"$icon\" /></span>";
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2003-11-06 11:47:23 +00:00
|
|
|
$linkobject = "<img align=\"absmiddle\" border=\"0\" height=\"17\" width=\"22\" ".
|
|
|
|
" alt=\"$title\" style=\"cursor:help;\" src=\"$icon\" />";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-11-06 11:47:23 +00:00
|
|
|
$linkobject = "<span style=\"cursor:help;\">$title</span>";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
if ($text) {
|
2003-09-21 15:45:24 +00:00
|
|
|
$url = "/help.php?module=$module&text=".htmlentities(urlencode($text));
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2003-09-21 15:45:24 +00:00
|
|
|
$url = "/help.php?module=$module&file=$page.html";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
link_to_popup_window ($url, "popup", $linkobject, 400, 500, $title);
|
|
|
|
}
|
|
|
|
|
2003-05-08 16:09:30 +00:00
|
|
|
function emoticonhelpbutton($form, $field) {
|
|
|
|
/// Prints a special help button that is a link to the "live" emoticon popup
|
|
|
|
global $CFG, $SESSION;
|
|
|
|
|
|
|
|
$SESSION->inserttextform = $form;
|
|
|
|
$SESSION->inserttextfield = $field;
|
|
|
|
helpbutton("emoticons", get_string("helpemoticons"), "moodle", false, true);
|
2003-09-14 12:25:16 +00:00
|
|
|
echo " ";
|
2003-09-21 15:45:24 +00:00
|
|
|
link_to_popup_window ("/help.php?module=moodle&file=emoticons.html", "popup",
|
|
|
|
"<img src=\"$CFG->pixpath/s/smiley.gif\" border=\"0\" align=\"absmiddle\" width=\"15\" height=\"15\" />",
|
2003-09-14 12:25:16 +00:00
|
|
|
400, 500, get_string("helpemoticons"));
|
|
|
|
echo "<br />";
|
2003-05-08 16:09:30 +00:00
|
|
|
}
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
function notice ($message, $link="") {
|
2003-01-26 06:04:14 +00:00
|
|
|
global $CFG, $THEME;
|
2002-12-20 14:44:14 +00:00
|
|
|
|
|
|
|
if (!$link) {
|
2003-01-26 06:04:14 +00:00
|
|
|
if (!empty($_SERVER["HTTP_REFERER"])) {
|
|
|
|
$link = $_SERVER["HTTP_REFERER"];
|
|
|
|
} else {
|
2003-07-30 13:02:45 +00:00
|
|
|
$link = "$CFG->wwwroot/";
|
2003-01-26 06:04:14 +00:00
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2003-05-05 16:28:40 +00:00
|
|
|
echo "<br />";
|
2003-05-05 12:25:08 +00:00
|
|
|
print_simple_box($message, "center", "50%", "$THEME->cellheading", "20", "noticebox");
|
2003-05-04 03:00:52 +00:00
|
|
|
print_heading("<a href=\"$link\">".get_string("continue")."</a>");
|
2002-12-20 14:44:14 +00:00
|
|
|
print_footer(get_site());
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
function notice_yesno ($message, $linkyes, $linkno) {
|
|
|
|
global $THEME;
|
|
|
|
|
2003-05-04 03:00:52 +00:00
|
|
|
print_simple_box_start("center", "60%", "$THEME->cellheading");
|
2003-09-21 15:45:24 +00:00
|
|
|
echo "<p align=\"center\"><font size=\"3\">$message</font></p>";
|
|
|
|
echo "<p align=\"center\"><font size=\"3\"><b>";
|
2003-05-04 03:00:52 +00:00
|
|
|
echo "<a href=\"$linkyes\">".get_string("yes")."</a>";
|
2002-12-20 14:44:14 +00:00
|
|
|
echo " ";
|
2003-05-04 03:00:52 +00:00
|
|
|
echo "<a href=\"$linkno\">".get_string("no")."</a>";
|
|
|
|
echo "</b></font></p>";
|
2002-12-20 14:44:14 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
}
|
|
|
|
|
2003-09-02 01:28:46 +00:00
|
|
|
function redirect($url, $message="", $delay="0") {
|
2003-10-31 08:13:44 +00:00
|
|
|
// Redirects the user to another page, after printing a notice
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2003-03-12 07:44:29 +00:00
|
|
|
if (empty($message)) {
|
2003-11-04 03:35:05 +00:00
|
|
|
echo "<meta http-equiv=\"refresh\" content=\"$delay; url=$url\" />";
|
2003-11-03 03:13:14 +00:00
|
|
|
echo "<script>location.replace('$url');</script>"; // To cope with Mozilla bug
|
2003-03-12 07:44:29 +00:00
|
|
|
} else {
|
2003-08-10 08:17:59 +00:00
|
|
|
if (empty($delay)) {
|
2003-03-12 07:44:29 +00:00
|
|
|
$delay = 3; // There's no point having a message with no delay
|
|
|
|
}
|
2003-10-21 06:42:10 +00:00
|
|
|
print_header("", "", "", "", "<meta http-equiv=\"refresh\" content=\"$delay; url=$url\" />");
|
2003-05-14 05:01:01 +00:00
|
|
|
echo "<center>";
|
|
|
|
echo "<p>$message</p>";
|
|
|
|
echo "<p>( <a href=\"$url\">".get_string("continue")."</a> )</p>";
|
|
|
|
echo "</center>";
|
2003-11-01 06:59:31 +00:00
|
|
|
flush();
|
|
|
|
sleep($delay);
|
|
|
|
echo "<script>location.replace('$url');</script>"; // To cope with Mozilla bug
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-07-11 08:38:39 +00:00
|
|
|
function obfuscate_email($email) {
|
|
|
|
/// Given an email address, this function will return an obfuscated version of it
|
|
|
|
$i = 0;
|
|
|
|
$length = strlen($email);
|
|
|
|
$obfuscated = "";
|
|
|
|
while ($i < $length) {
|
|
|
|
if (rand(0,2)) {
|
|
|
|
$obfuscated.='%'.dechex(ord($email{$i}));
|
|
|
|
} else {
|
|
|
|
$obfuscated.=$email{$i};
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
return $obfuscated;
|
|
|
|
}
|
|
|
|
|
|
|
|
function obfuscate_text($plaintext) {
|
|
|
|
/// This function takes some text and replaces about half of the characters
|
|
|
|
/// with HTML entity equivalents. Return string is obviously longer.
|
|
|
|
$i=0;
|
|
|
|
$length = strlen($plaintext);
|
|
|
|
$obfuscated="";
|
2003-09-09 02:22:36 +00:00
|
|
|
$prev_obfuscated = false;
|
2003-07-11 08:38:39 +00:00
|
|
|
while ($i < $length) {
|
2003-09-09 02:22:36 +00:00
|
|
|
$c = ord($plaintext{$i});
|
|
|
|
$numerical = ($c >= ord('0')) && ($c <= ord('9'));
|
|
|
|
if ($prev_obfuscated and $numerical ) {
|
|
|
|
$obfuscated.='&#'.ord($plaintext{$i});
|
|
|
|
} else if (rand(0,2)) {
|
2003-07-11 08:38:39 +00:00
|
|
|
$obfuscated.='&#'.ord($plaintext{$i});
|
2003-09-09 02:22:36 +00:00
|
|
|
$prev_obfuscated = true;
|
2003-07-11 08:38:39 +00:00
|
|
|
} else {
|
|
|
|
$obfuscated.=$plaintext{$i};
|
2003-09-09 02:22:36 +00:00
|
|
|
$prev_obfuscated = false;
|
2003-07-11 08:38:39 +00:00
|
|
|
}
|
2003-09-09 02:22:36 +00:00
|
|
|
$i++;
|
2003-07-11 08:38:39 +00:00
|
|
|
}
|
|
|
|
return $obfuscated;
|
|
|
|
}
|
|
|
|
|
|
|
|
function obfuscate_mailto($email, $label="") {
|
|
|
|
/// This function uses the above two functions to generate a fully
|
|
|
|
/// obfuscated email link, ready to use.
|
|
|
|
|
|
|
|
if (empty($label)) {
|
|
|
|
$label = $email;
|
|
|
|
}
|
|
|
|
return sprintf('<a href="%s:%s" title="%s">%s</a>', obfuscate_text('mailto'),
|
|
|
|
obfuscate_email($email),
|
|
|
|
obfuscate_text($email),
|
|
|
|
obfuscate_text($label));
|
|
|
|
}
|
|
|
|
|
2003-08-19 03:35:53 +00:00
|
|
|
function print_paging_bar($totalcount, $page, $perpage, $baseurl) {
|
|
|
|
/// Prints a single paging bar to provide access to other pages (usually in a search)
|
|
|
|
|
2003-08-22 06:07:18 +00:00
|
|
|
$maxdisplay = 18;
|
2003-08-21 09:33:07 +00:00
|
|
|
|
2003-08-19 03:35:53 +00:00
|
|
|
if ($totalcount > $perpage) {
|
2003-08-21 14:23:31 +00:00
|
|
|
echo "<center>";
|
|
|
|
echo "<p>".get_string("page").":";
|
2003-08-21 13:47:14 +00:00
|
|
|
$lastpage = ceil($totalcount / $perpage);
|
|
|
|
if ($page > 15) {
|
|
|
|
$startpage = $page - 10;
|
2003-08-22 06:07:18 +00:00
|
|
|
echo " <a href=\"{$baseurl}page=0\">1</a> ...";
|
2003-08-21 13:47:14 +00:00
|
|
|
} else {
|
|
|
|
$startpage = 0;
|
|
|
|
}
|
|
|
|
$currpage = $startpage;
|
|
|
|
$displaycount = 0;
|
|
|
|
while ($displaycount < $maxdisplay and $currpage < $lastpage) {
|
|
|
|
$displaypage = $currpage+1;
|
|
|
|
if ($page == $currpage) {
|
2003-08-19 03:35:53 +00:00
|
|
|
echo " $displaypage";
|
|
|
|
} else {
|
2003-08-21 13:47:14 +00:00
|
|
|
echo " <a href=\"{$baseurl}page=$currpage\">$displaypage</a>";
|
2003-08-19 04:37:32 +00:00
|
|
|
}
|
2003-08-21 13:47:14 +00:00
|
|
|
$displaycount++;
|
|
|
|
$currpage++;
|
2003-08-19 03:35:53 +00:00
|
|
|
}
|
2003-08-21 14:22:06 +00:00
|
|
|
if ($currpage < $lastpage) {
|
2003-08-22 06:07:18 +00:00
|
|
|
$lastpageactual = $lastpage - 1;
|
|
|
|
echo " ...<a href=\"{$baseurl}page=$lastpageactual\">$lastpage</a> ";
|
2003-08-21 14:22:06 +00:00
|
|
|
}
|
2003-08-19 03:35:53 +00:00
|
|
|
$pagenum = $page + 1;
|
2003-08-21 13:47:14 +00:00
|
|
|
if ($pagenum != $displaypage) {
|
2003-08-19 03:35:53 +00:00
|
|
|
echo " (<a href=\"{$baseurl}page=$pagenum\">".get_string("next")."</a>)";
|
|
|
|
}
|
|
|
|
echo "</p>";
|
2003-08-21 13:47:14 +00:00
|
|
|
echo "</center>";
|
2003-08-19 03:35:53 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2003-03-14 07:55:22 +00:00
|
|
|
// vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
|
2001-11-22 06:23:56 +00:00
|
|
|
?>
|