2004-10-08 16:52:20 +00:00
|
|
|
<?php // $Id$
|
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
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Library of functions for web output
|
|
|
|
*
|
|
|
|
* Library of all general-purpose Moodle PHP functions and constants
|
|
|
|
* that produce HTML output
|
|
|
|
*
|
|
|
|
* Other main libraries:
|
|
|
|
* - datalib.php - functions that access the database.
|
|
|
|
* - moodlelib.php - general-purpose Moodle functions.
|
|
|
|
* @author Martin Dougiamas
|
|
|
|
* @version $Id$
|
2004-09-25 05:29:21 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
2004-09-23 02:48:41 +00:00
|
|
|
* @package moodlecore
|
|
|
|
*/
|
|
|
|
|
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
|
2004-09-23 02:48:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Does all sorts of transformations and filtering
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
define('FORMAT_MOODLE', '0'); // Does all sorts of transformations and filtering
|
2004-09-23 02:48:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Plain HTML (with some tags stripped)
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
define('FORMAT_HTML', '1'); // Plain HTML (with some tags stripped)
|
2004-09-23 02:48:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Plain text (even tags are printed in full)
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
define('FORMAT_PLAIN', '2'); // Plain text (even tags are printed in full)
|
2004-09-23 02:48:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wiki-formatted text
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
define('FORMAT_WIKI', '3'); // Wiki-formatted text
|
2004-09-23 02:48:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Markdown-formatted text http://daringfireball.net/projects/markdown/
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
define('FORMAT_MARKDOWN', '4'); // Markdown-formatted text http://daringfireball.net/projects/markdown/
|
2002-10-10 07:26:10 +00:00
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allowed tags - string of html tags that can be tested against for safe html tags
|
|
|
|
* @global string $ALLOWED_TAGS
|
|
|
|
*/
|
2003-10-16 14:25:36 +00:00
|
|
|
$ALLOWED_TAGS =
|
2004-10-29 17:17:57 +00:00
|
|
|
'<p><br><b><i><u><font><table><tbody><span><div><tr><td><th><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><lang><tex><algebra><math><mi><mn><mo><mtext><mspace><ms><mrow><mfrac><msqrt><mroot><mstyle><merror><mpadded><mphantom><mfenced><msub><msup><msubsup><munder><mover><munderover><mmultiscripts><mtable><mtr><mtd><maligngroup><malignmark><maction><cn><ci><apply><reln><fn><interval><inverse><sep><condition><declare><lambda><compose><ident><quotient><exp><factorial><divide><max><min><minus><plus><power><rem><times><root><gcd><and><or><xor><not><implies><forall><exists><abs><conjugate><eq><neq><gt><lt><geq><leq><ln><log><int><diff><partialdiff><lowlimit><uplimit><bvar><degree><set><list><union><intersect><in><notin><subset><prsubset><notsubset><notprsubset><setdiff><sum><product><limit><tendsto><mean><sdev><variance><median><mode><moment><vector><matrix><matrixrow><determinant><transpose><selector><annotation><semantics><annotation-xml><tt><code>';
|
2002-10-18 09:09:19 +00:00
|
|
|
|
2004-09-29 14:00:35 +00:00
|
|
|
/**
|
|
|
|
* Allowed protocols - array of protocols that are safe to use in links and so on
|
|
|
|
* @global string $ALLOWED_PROTOCOLS
|
|
|
|
*/
|
|
|
|
$ALLOWED_PROTOCOLS = array('http', 'https', 'ftp', 'news', 'mailto', 'rtsp', 'teamspeak', 'gopher', 'color');
|
|
|
|
|
|
|
|
|
2002-10-10 07:26:10 +00:00
|
|
|
/// Functions
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Add quotes to HTML characters
|
|
|
|
*
|
|
|
|
* Returns $var with HTML characters (like "<", ">", etc.) properly quoted.
|
|
|
|
* This function is very similar to {@link p()}
|
|
|
|
*
|
|
|
|
* @param string $var the string potentially containing HTML characters
|
|
|
|
* @return string
|
|
|
|
*/
|
2003-05-26 14:43:19 +00:00
|
|
|
function s($var) {
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-05-26 14:43:19 +00:00
|
|
|
if (empty($var)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
return '';
|
2003-05-26 14:43:19 +00:00
|
|
|
}
|
2003-01-23 13:07:49 +00:00
|
|
|
return htmlSpecialChars(stripslashes_safe($var));
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Add quotes to HTML characters
|
|
|
|
*
|
2004-09-23 04:36:43 +00:00
|
|
|
* Prints $var with HTML characters (like "<", ">", etc.) properly quoted.
|
2004-09-23 02:48:41 +00:00
|
|
|
* This function is very similar to {@link s()}
|
|
|
|
*
|
|
|
|
* @param string $var the string potentially containing HTML characters
|
|
|
|
* @return string
|
|
|
|
*/
|
2003-05-26 14:43:19 +00:00
|
|
|
function p($var) {
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-05-26 14:43:19 +00:00
|
|
|
if (empty($var)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '';
|
2003-05-26 14:43:19 +00:00
|
|
|
}
|
2003-01-23 13:07:49 +00:00
|
|
|
echo htmlSpecialChars(stripslashes_safe($var));
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure that a variable is set
|
|
|
|
*
|
|
|
|
* Return $var if it is defined, otherwise return $default,
|
|
|
|
* This function is very similar to {@link optional_variable()}
|
|
|
|
*
|
|
|
|
* @param mixed $var the variable which may be unset
|
|
|
|
* @param mixed $default the value to return if $var is unset
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function nvl(&$var, $default='') {
|
2002-07-11 05:30:57 +00:00
|
|
|
|
|
|
|
return isset($var) ? $var : $default;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Remove query string from url
|
|
|
|
*
|
|
|
|
* Takes in a URL and returns it without the querystring portion
|
|
|
|
*
|
|
|
|
* @param string $url the url which may have a query string attached
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function strip_querystring($url) {
|
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
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Returns the URL of the HTTP_REFERER, less the querystring portion
|
|
|
|
* @return string
|
|
|
|
*/
|
2001-11-22 06:23:56 +00:00
|
|
|
function get_referer() {
|
|
|
|
|
2004-09-22 14:39:15 +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
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Returns the name of the current script, WITH the querystring portion.
|
|
|
|
* this function is necessary because PHP_SELF and REQUEST_URI and SCRIPT_NAME
|
|
|
|
* 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.)
|
2004-09-23 04:36:43 +00:00
|
|
|
* <b>NOTE:</b> This function returns false if the global variables needed are not set.
|
|
|
|
*
|
2004-09-23 02:48:41 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function me() {
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
if (!empty($_SERVER['REQUEST_URI'])) {
|
|
|
|
return $_SERVER['REQUEST_URI'];
|
2002-10-19 04:58:14 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
} else if (!empty($_SERVER['PHP_SELF'])) {
|
|
|
|
if (!empty($_SERVER['QUERY_STRING'])) {
|
|
|
|
return $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'];
|
2003-01-30 15:52:38 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
return $_SERVER['PHP_SELF'];
|
2002-10-19 04:58:14 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
} else if (!empty($_SERVER['SCRIPT_NAME'])) {
|
|
|
|
if (!empty($_SERVER['QUERY_STRING'])) {
|
|
|
|
return $_SERVER['SCRIPT_NAME'] .'?'. $_SERVER['QUERY_STRING'];
|
2003-01-30 15:52:38 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
return $_SERVER['SCRIPT_NAME'];
|
2003-01-30 15:52:38 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
} else if (!empty($_SERVER['URL'])) { // May help IIS (not well tested)
|
|
|
|
if (!empty($_SERVER['QUERY_STRING'])) {
|
|
|
|
return $_SERVER['URL'] .'?'. $_SERVER['QUERY_STRING'];
|
2004-07-06 12:34:33 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
return $_SERVER['URL'];
|
2004-07-06 12:34:33 +00:00
|
|
|
|
2002-12-30 03:39:42 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
notify('Warning: Could not find any of these web server variables: $REQUEST_URI, $PHP_SELF, $SCRIPT_NAME or $URL');
|
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
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
2004-09-23 04:36:43 +00:00
|
|
|
* Like {@link me()} but returns a full URL
|
2004-09-23 02:48:41 +00:00
|
|
|
* @see me()
|
|
|
|
* @return string
|
|
|
|
*/
|
2001-11-22 06:23:56 +00:00
|
|
|
function qualified_me() {
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
if (!empty($_SERVER['SERVER_NAME'])) {
|
|
|
|
$hostname = $_SERVER['SERVER_NAME'];
|
|
|
|
} else if (!empty($_ENV['SERVER_NAME'])) {
|
|
|
|
$hostname = $_ENV['SERVER_NAME'];
|
|
|
|
} else if (!empty($_SERVER['HTTP_HOST'])) {
|
|
|
|
$hostname = $_SERVER['HTTP_HOST'];
|
|
|
|
} else if (!empty($_ENV['HTTP_HOST'])) {
|
|
|
|
$hostname = $_ENV['HTTP_HOST'];
|
2003-01-10 05:40:35 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
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
|
|
|
}
|
2004-09-14 08:41:17 +00:00
|
|
|
if (isset($_SERVER['HTTPS'])) {
|
|
|
|
$protocol = ($_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
|
|
|
|
} else if (isset($_SERVER['SERVER_PORT'])) { # Apache2 does not export $_SERVER['HTTPS']
|
|
|
|
$protocol = ($_SERVER['SERVER_PORT'] == '443') ? 'https://' : 'http://';
|
|
|
|
} else {
|
|
|
|
$protocol = 'http://';
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Determine if a web referer is valid
|
|
|
|
*
|
|
|
|
* Returns true if the referer is the same as the goodreferer. If
|
|
|
|
* the referer to test is not specified, use {@link qualified_me()}.
|
|
|
|
* If the admin has not set secure forms ($CFG->secureforms) then
|
|
|
|
* this function returns true regardless of a match.
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
2004-09-23 02:48:41 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @param string $goodreferer the url to compare to referer
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function match_referer($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
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
if ($goodreferer == 'nomatch') { // Don't bother checking referer
|
2003-05-12 09:22:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-05-21 13:07:11 +00:00
|
|
|
if (empty($goodreferer)) {
|
|
|
|
$goodreferer = qualified_me();
|
2002-10-19 04:58:14 +00:00
|
|
|
}
|
2004-09-09 10:26:11 +00:00
|
|
|
|
2004-09-01 11:24:35 +00:00
|
|
|
$referer = get_referer();
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
return (($referer == $goodreferer) or ($referer == $CFG->wwwroot .'/'));
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Determine if there is data waiting to be processed from a form
|
|
|
|
*
|
|
|
|
* Used on most forms in Moodle to check for data
|
|
|
|
* Returns the data as an object, if it's found.
|
|
|
|
* This object can be used in foreach loops without
|
|
|
|
* casting because it's cast to (array) automatically
|
|
|
|
*
|
|
|
|
* Checks that submitted POST data exists, and also
|
|
|
|
* checks the referer against the given url (it uses
|
2004-09-23 04:36:43 +00:00
|
|
|
* the current page if none was specified.
|
|
|
|
*
|
2004-09-23 02:48:41 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @param string $url the url to compare to referer for secure forms
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function data_submitted($url='') {
|
2004-09-23 04:36:43 +00:00
|
|
|
|
2003-01-02 14:49:23 +00:00
|
|
|
|
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) {
|
2004-09-22 14:39:15 +00:00
|
|
|
notice('The form did not come from this page! (referer = '. get_referer() .')');
|
2003-01-02 14:49:23 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Moodle replacement for php stripslashes() function
|
|
|
|
*
|
|
|
|
* The standard php stripslashes() removes ALL backslashes
|
|
|
|
* even from strings - so C:\temp becomes C:temp - this isn't good.
|
|
|
|
* This function should work as a fairly safe replacement
|
|
|
|
* to be called on quoted AND unquoted strings (to be sure)
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
2004-09-23 02:48:41 +00:00
|
|
|
* @param string the string to remove unsafe slashes from
|
|
|
|
* @return string
|
|
|
|
*/
|
2003-01-23 13:07:49 +00:00
|
|
|
function stripslashes_safe($string) {
|
|
|
|
|
|
|
|
$string = str_replace("\\'", "'", $string);
|
|
|
|
$string = str_replace('\\"', '"', $string);
|
2004-12-27 23:40:42 +00:00
|
|
|
$string = str_replace('\\\\', '\\', $string);
|
2003-01-23 13:07:49 +00:00
|
|
|
return $string;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-10-19 21:04:28 +00:00
|
|
|
/**
|
|
|
|
* Recursive implementation of stripslashes()
|
|
|
|
*
|
|
|
|
* This function will allow you to strip the slashes from a variable.
|
|
|
|
* If the variable is an array or object, slashes will be stripped
|
|
|
|
* from the items (or properties) it contains, even if they are arrays
|
|
|
|
* or objects themselves.
|
|
|
|
*
|
|
|
|
* @param mixed the variable to remove slashes from
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function stripslashes_recursive($var) {
|
|
|
|
if(is_object($var)) {
|
|
|
|
$properties = get_object_vars($var);
|
|
|
|
foreach($properties as $property => $value) {
|
|
|
|
$var->$property = stripslashes_recursive($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(is_array($var)) {
|
|
|
|
foreach($var as $property => $value) {
|
|
|
|
$var[$property] = stripslashes_recursive($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(is_string($var)) {
|
|
|
|
$var = stripslashes($var);
|
|
|
|
}
|
|
|
|
return $var;
|
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
2004-09-23 04:36:43 +00:00
|
|
|
* Given some normal text this function will break up any
|
|
|
|
* long words to a given size by inserting the given character
|
|
|
|
*
|
2004-09-23 02:48:41 +00:00
|
|
|
* @param string $string the string to be modified
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $maxsize maximum length of the string to be returned
|
2004-09-23 02:48:41 +00:00
|
|
|
* @param string $cutchar the string used to represent word breaks
|
|
|
|
* @return string
|
|
|
|
*/
|
2004-03-10 02:19:17 +00:00
|
|
|
function break_up_long_words($string, $maxsize=20, $cutchar=' ') {
|
|
|
|
|
2005-01-14 11:53:10 +00:00
|
|
|
if (in_array(current_language(), array('ja', 'ja_utf8', 'kn_utf8', 'sr_utf8', 'vi_utf8', 'zh_cn', 'zh_tw', 'zh_tw_utf8'))) { // Multibyte languages
|
2004-07-07 17:45:42 +00:00
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2004-03-10 02:19:17 +00:00
|
|
|
$output = '';
|
|
|
|
$length = strlen($string);
|
|
|
|
$wordlength = 0;
|
|
|
|
|
|
|
|
for ($i=0; $i<$length; $i++) {
|
|
|
|
$char = $string[$i];
|
|
|
|
if ($char == ' ' or $char == "\t" or $char == "\n" or $char == "\r") {
|
|
|
|
$wordlength = 0;
|
|
|
|
} else {
|
|
|
|
$wordlength++;
|
|
|
|
if ($wordlength > $maxsize) {
|
|
|
|
$output .= $cutchar;
|
|
|
|
$wordlength = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$output .= $char;
|
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* This does a search and replace, ignoring case
|
|
|
|
* This function is only used for versions of PHP older than version 5
|
|
|
|
* which do not have a native version of this function.
|
|
|
|
* Taken from the PHP manual, by bradhuizenga @ softhome.net
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
2004-09-23 02:48:41 +00:00
|
|
|
* @param string $find the string to search for
|
|
|
|
* @param string $replace the string to replace $find with
|
|
|
|
* @param string $string the string to search through
|
|
|
|
* return string
|
|
|
|
*/
|
2004-01-20 08:51:43 +00:00
|
|
|
if (!function_exists('str_ireplace')) { /// Only exists in PHP 5
|
2003-10-16 09:28:27 +00:00
|
|
|
function str_ireplace($find, $replace, $string) {
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Locate the position of a string in another string
|
|
|
|
*
|
|
|
|
* This function is only used for versions of PHP older than version 5
|
|
|
|
* which do not have a native version of this function.
|
|
|
|
* Taken from the PHP manual, by dmarsh @ spscc.ctc.edu
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
2004-09-23 02:48:41 +00:00
|
|
|
* @param string $haystack The string to be searched
|
|
|
|
* @param string $needle The string to search for
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $offset The position in $haystack where the search should begin.
|
2004-09-23 02:48:41 +00:00
|
|
|
*/
|
2004-01-20 08:51:43 +00:00
|
|
|
if (!function_exists('stripos')) { /// Only exists in PHP 5
|
|
|
|
function stripos($haystack, $needle, $offset=0) {
|
2004-09-23 04:36:43 +00:00
|
|
|
|
2004-01-20 08:51:43 +00:00
|
|
|
return strpos(strtoupper($haystack), strtoupper($needle), $offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Load a template from file
|
|
|
|
*
|
|
|
|
* Returns 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).
|
|
|
|
*
|
|
|
|
* <b>WARNING: do not use this on big files!!</b>
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
2004-09-23 02:48:41 +00:00
|
|
|
* @param string $filename Location on the server's filesystem where template can be found.
|
|
|
|
* @param mixed $var Passed in by reference. An array or object which will be loaded with data from the template file.
|
|
|
|
*/
|
2001-11-22 06:23:56 +00:00
|
|
|
function read_template($filename, &$var) {
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
$temp = str_replace("\\", "\\\\", implode(file($filename), ''));
|
2002-12-30 03:39:42 +00:00
|
|
|
$temp = str_replace('"', '\"', $temp);
|
|
|
|
eval("\$template = \"$temp\";");
|
|
|
|
return $template;
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Set a variable's value depending on whether or not it already has a value.
|
|
|
|
*
|
|
|
|
* 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
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
2004-09-23 02:48:41 +00:00
|
|
|
* @param mixed $var Passed in by reference. The variable to check.
|
|
|
|
* @param mixed $set_value The value to set $var to if $var already has a value.
|
|
|
|
* @param mixed $unset_value The value to set $var to if $var does not already have a value.
|
|
|
|
*/
|
2001-11-22 06:23:56 +00:00
|
|
|
function checked(&$var, $set_value = 1, $unset_value = 0) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Prints the word "checked" if a variable is true, otherwise prints nothing,
|
2004-09-23 04:36:43 +00:00
|
|
|
* used for printing the word "checked" in a checkbox form element.
|
|
|
|
*
|
2004-09-23 02:48:41 +00:00
|
|
|
* @param boolean $var Variable to be checked for true value
|
|
|
|
* @param string $true_value Value to be printed if $var is true
|
|
|
|
* @param string $false_value Value to be printed if $var is false
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function frmchecked(&$var, $true_value = 'checked', $false_value = '') {
|
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
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* This function will create a HTML link that will work on both
|
|
|
|
* Javascript and non-javascript browsers.
|
|
|
|
* Relies on the Javascript function openpopup in javascript.php
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
2004-09-23 02:48:41 +00:00
|
|
|
* $url must be relative to home page eg /mod/survey/stuff.php
|
|
|
|
* @param string $url Web link relative to home page
|
|
|
|
* @param string $name Name to be assigned to the popup window
|
|
|
|
* @param string $linkname Text to be displayed as web link
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $height Height to assign to popup window
|
|
|
|
* @param int $width Height to assign to popup window
|
2004-09-23 02:48:41 +00:00
|
|
|
* @param string $title Text to be displayed as popup page title
|
|
|
|
* @param string $options List of additional options for popup window
|
|
|
|
* @todo Add code examples and list of some options that might be used.
|
|
|
|
* @param boolean $return Should the link to the popup window be returned as a string (true) or printed immediately (false)?
|
|
|
|
* @return string
|
|
|
|
* @uses $CFG
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function link_to_popup_window ($url, $name='popup', $linkname='click here',
|
|
|
|
$height=400, $width=500, $title='Popup window', $options='none', $return=false) {
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-10-14 16:00:55 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
if ($options == 'none') {
|
|
|
|
$options = 'menubar=0,location=0,scrollbars,resizable,width='. $width .',height='. $height;
|
2003-09-03 12:13:08 +00:00
|
|
|
}
|
2003-07-20 13:53:31 +00:00
|
|
|
$fullscreen = 0;
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-09-17 00:10:53 +00:00
|
|
|
if (!(strpos($url,$CFG->wwwroot) === false)) { // some log url entries contain _SERVER[HTTP_REFERRER] in which case wwwroot is already there.
|
2004-09-23 02:48:41 +00:00
|
|
|
$url = substr($url, strlen($CFG->wwwroot)+1);
|
2004-09-17 00:10:53 +00:00
|
|
|
}
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
$link = '<a target="'. $name .'" title="'. $title .'" href="'. $CFG->wwwroot . $url .'" '.
|
2005-01-05 17:40:38 +00:00
|
|
|
"onclick=\"return openpopup('$url', '$name', '$options', $fullscreen);\">$linkname</a>";
|
2004-08-02 19:09:06 +00:00
|
|
|
if ($return) {
|
|
|
|
return $link;
|
|
|
|
} else {
|
|
|
|
echo $link;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* This function will print a button submit form element
|
|
|
|
* that will work on both Javascript and non-javascript browsers.
|
|
|
|
* Relies on the Javascript function openpopup in javascript.php
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
2004-09-23 02:48:41 +00:00
|
|
|
* $url must be relative to home page eg /mod/survey/stuff.php
|
|
|
|
* @param string $url Web link relative to home page
|
|
|
|
* @param string $name Name to be assigned to the popup window
|
|
|
|
* @param string $linkname Text to be displayed as web link
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $height Height to assign to popup window
|
|
|
|
* @param int $width Height to assign to popup window
|
2004-09-23 02:48:41 +00:00
|
|
|
* @param string $title Text to be displayed as popup page title
|
|
|
|
* @param string $options List of additional options for popup window
|
|
|
|
* @todo Add code examples and list of some options that might be used.
|
|
|
|
* @return string
|
|
|
|
* @uses $CFG
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function button_to_popup_window ($url, $name='popup', $linkname='click here',
|
|
|
|
$height=400, $width=500, $title='Popup window', $options='none') {
|
2004-02-15 08:04:33 +00:00
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
if ($options == 'none') {
|
|
|
|
$options = 'menubar=0,location=0,scrollbars,resizable,width='. $width .',height='. $height;
|
2004-02-15 08:04:33 +00:00
|
|
|
}
|
|
|
|
$fullscreen = 0;
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<input type="button" name="popupwindow" title="'. $title .'" value="'. $linkname .' ..." '.
|
2004-10-08 13:58:33 +00:00
|
|
|
"onclick=\"return openpopup('$url', '$name', '$options', $fullscreen);\" />\n";
|
2004-02-15 08:04:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-23 02:48:41 +00:00
|
|
|
/**
|
|
|
|
* Prints a simple button to close a window
|
|
|
|
*/
|
2001-11-22 06:23:56 +00:00
|
|
|
function close_window_button() {
|
2002-10-19 04:58:14 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<center>' . "\n";
|
|
|
|
echo '<script type="text/javascript">' . "\n";
|
|
|
|
echo '<!--' . "\n";
|
2003-07-20 13:53:31 +00:00
|
|
|
echo "document.write('<form>');\n";
|
2004-10-08 13:58:33 +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";
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '-->' . "\n";
|
|
|
|
echo '</script>' . "\n";
|
|
|
|
echo '<noscript>' . "\n";
|
2004-10-26 07:42:08 +00:00
|
|
|
print_string('closewindow');
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '</noscript>' . "\n";
|
|
|
|
echo '</center>' . "\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Given an array of value, creates a popup menu to be part of a form
|
|
|
|
* $options["value"]["label"]
|
|
|
|
*
|
|
|
|
* @param type description
|
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false) {
|
2004-05-21 13:07:11 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
if ($nothing == 'choose') {
|
|
|
|
$nothing = get_string('choose') .'...';
|
2002-08-12 07:40:53 +00:00
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
if ($script) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$javascript = 'onchange="'. $script .'"';
|
2002-12-29 17:32:32 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$javascript = '';
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2002-12-29 17:32:32 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
$output = '<select name="'. $name .'" '. $javascript .'>' . "\n";
|
2002-06-05 05:37:55 +00:00
|
|
|
if ($nothing) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= ' <option value="'. $nothingvalue .'"'. "\n";
|
2004-04-27 13:57:46 +00:00
|
|
|
if ($nothingvalue === $selected) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= ' selected="selected"';
|
2002-06-05 05:37:55 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +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) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= ' <option value="'. $value .'"';
|
2003-01-05 06:45:20 +00:00
|
|
|
if ($value == $selected) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= ' selected="selected"';
|
2003-01-05 06:45:20 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
if ($label === '') {
|
|
|
|
$output .= '>'. $value .'</option>' . "\n";
|
2003-08-25 02:32:20 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= '>'. $label .'</option>' . "\n";
|
2003-01-05 06:45:20 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= '</select>' . "\n";
|
2002-09-19 14:51:49 +00:00
|
|
|
|
|
|
|
if ($return) {
|
|
|
|
return $output;
|
|
|
|
} else {
|
|
|
|
echo $output;
|
|
|
|
}
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Implements a complete little popup form
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @param string $common The URL up to the point of the variable that changes
|
|
|
|
* @param array $options Alist of value-label pairs for the popup list
|
|
|
|
* @param string $formname Name must be unique on the page
|
|
|
|
* @param string $selected The option that is already selected
|
|
|
|
* @param string $nothing The label for the "no choice" option
|
|
|
|
* @param string $help The name of a help page if help is required
|
|
|
|
* @param string $helptext The name of the label for the help button
|
|
|
|
* @param boolean $return Indicates whether the function should return the text
|
|
|
|
* as a string or echo it directly to the page being rendered
|
|
|
|
* @param string $targetwindow The name of the target page to open the linked page in.
|
|
|
|
* @return string If $return is true then the entire form is returned as a string.
|
|
|
|
* @todo Finish documenting this function<br>
|
|
|
|
*/
|
|
|
|
function popup_form($common, $options, $formname, $selected='', $nothing='choose', $help='', $helptext='', $return=false, $targetwindow='self') {
|
|
|
|
|
2004-09-29 14:00:35 +00:00
|
|
|
global $CFG;
|
2004-09-30 10:52:48 +00:00
|
|
|
static $go, $choose; /// Locally cached, in case there's lots on a page
|
2004-06-22 18:35:59 +00:00
|
|
|
|
2004-06-09 08:36:28 +00:00
|
|
|
if (empty($options)) {
|
|
|
|
return '';
|
|
|
|
}
|
2003-03-30 13:25:49 +00:00
|
|
|
|
2004-09-30 10:52:48 +00:00
|
|
|
if (!isset($go)) {
|
|
|
|
$go = get_string('go');
|
2004-09-29 14:00:35 +00:00
|
|
|
}
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
if ($nothing == 'choose') {
|
2004-09-29 14:00:35 +00:00
|
|
|
if (!isset($choose)) {
|
|
|
|
$choose = get_string('choose');
|
|
|
|
}
|
|
|
|
$nothing = $choose.'...';
|
2002-08-12 07:40:53 +00:00
|
|
|
}
|
|
|
|
|
2004-09-29 14:00:35 +00:00
|
|
|
$startoutput = '<form action="'.$CFG->wwwroot.'/course/jumpto.php"'.
|
|
|
|
' method="get"'.
|
|
|
|
' target="'.$CFG->framename.'"'.
|
|
|
|
' name="'.$formname.'"'.
|
|
|
|
' style="display: inline;">';
|
|
|
|
|
|
|
|
$output = '<select name="jump" onchange="'.$targetwindow.'.location=document.'.$formname.
|
2004-09-30 07:56:27 +00:00
|
|
|
'.jump.options[document.'.$formname.'.jump.selectedIndex].value;">'."\n";
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-09-22 14:39:15 +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
|
|
|
}
|
|
|
|
|
2004-09-28 09:47:14 +00:00
|
|
|
$inoptgroup = false;
|
2001-11-22 06:23:56 +00:00
|
|
|
foreach ($options as $value => $label) {
|
2004-10-26 07:42:08 +00:00
|
|
|
|
|
|
|
if (substr($label,0,2) == '--') { /// we are starting a new optgroup
|
|
|
|
|
|
|
|
/// Check to see if we already have a valid open optgroup
|
|
|
|
/// XHTML demands that there be at least 1 option within an optgroup
|
|
|
|
if ($inoptgroup and (count($optgr) > 1) ) {
|
|
|
|
$output .= implode('', $optgr);
|
2004-09-28 09:47:14 +00:00
|
|
|
$output .= ' </optgroup>';
|
|
|
|
}
|
2004-10-26 07:42:08 +00:00
|
|
|
|
|
|
|
unset($optgr);
|
|
|
|
$optgr = array();
|
|
|
|
|
|
|
|
$optgr[] = ' <optgroup label="'. substr($label,2) .'">'; // Plain labels
|
|
|
|
|
|
|
|
$inoptgroup = true; /// everything following will be in an optgroup
|
2004-07-21 05:41:58 +00:00
|
|
|
continue;
|
2004-10-26 07:42:08 +00:00
|
|
|
|
2002-11-10 07:37:15 +00:00
|
|
|
} else {
|
2004-10-26 07:42:08 +00:00
|
|
|
$optstr = ' <option value="' . $common . $value . '"';
|
|
|
|
|
2002-11-10 07:37:15 +00:00
|
|
|
if ($value == $selected) {
|
2004-10-26 07:42:08 +00:00
|
|
|
$optstr .= ' selected="selected"';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($label) {
|
|
|
|
$optstr .= '>'. $label .'</option>' . "\n";
|
|
|
|
} else {
|
|
|
|
$optstr .= '>'. $value .'</option>' . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($inoptgroup) {
|
|
|
|
$optgr[] = $optstr;
|
|
|
|
} else {
|
|
|
|
$output .= $optstr;
|
2002-11-10 07:37:15 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2004-10-26 07:42:08 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2004-10-26 07:42:08 +00:00
|
|
|
|
|
|
|
/// catch the final group if not closed
|
|
|
|
if ($inoptgroup and count($optgr) > 1) {
|
|
|
|
$output .= implode('', $optgr);
|
2004-09-28 09:47:14 +00:00
|
|
|
$output .= ' </optgroup>';
|
|
|
|
}
|
2004-10-26 07:42:08 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= '</select>';
|
2004-09-29 14:00:35 +00:00
|
|
|
$output .= '<noscript id="noscript'.$formname.'" style="display: inline;">';
|
2004-09-30 10:52:48 +00:00
|
|
|
$output .= '<input type="submit" value="'.$go.'" /></noscript>';
|
2004-09-29 14:00:35 +00:00
|
|
|
$output .= '<script type="text/javascript">'.
|
|
|
|
"\n<!--\n".
|
|
|
|
'document.getElementById("noscript'.$formname.'").style.display = "none";'.
|
|
|
|
"\n-->\n".'</script>';
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= '</form>' . "\n";
|
2002-11-10 07:37:15 +00:00
|
|
|
|
2004-08-02 19:09:06 +00:00
|
|
|
if ($help) {
|
|
|
|
$button = helpbutton($help, $helptext, 'moodle', true, false, '', true);
|
|
|
|
} else {
|
|
|
|
$button = '';
|
|
|
|
}
|
|
|
|
|
2002-11-10 07:37:15 +00:00
|
|
|
if ($return) {
|
2004-08-02 19:09:06 +00:00
|
|
|
return $startoutput.$button.$output;
|
2002-11-10 07:37:15 +00:00
|
|
|
} else {
|
2004-08-02 19:09:06 +00:00
|
|
|
echo $startoutput.$button.$output;
|
2002-11-10 07:37:15 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints some red text
|
|
|
|
*
|
|
|
|
* @param string $error The text to be displayed in red
|
|
|
|
*/
|
2001-11-22 06:23:56 +00:00
|
|
|
function formerr($error) {
|
2004-09-23 04:36:43 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
if (!empty($error)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<font color="#ff0000">'. $error .'</font>';
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Validates an email to make sure it makes sense.
|
|
|
|
*
|
|
|
|
* @param string $address The email address to validate.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2004-09-25 05:29:21 +00:00
|
|
|
function validate_email($address) {
|
2004-09-23 04:36:43 +00:00
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2004-11-30 19:44:08 +00:00
|
|
|
/**
|
|
|
|
* Extracts file argument either from file parameter or PATH_INFO
|
|
|
|
*
|
|
|
|
* @param string $scriptname name of the calling script
|
|
|
|
* @return string file path (only safe characters)
|
|
|
|
*/
|
|
|
|
function get_file_argument($scriptname) {
|
|
|
|
global $_SERVER;
|
|
|
|
|
|
|
|
$relativepath = FALSE;
|
|
|
|
|
|
|
|
// first try normal parameter (compatible method == no relative links!)
|
|
|
|
$relativepath = optional_param('file', FALSE, PARAM_PATH);
|
|
|
|
|
|
|
|
// then try extract file from PATH_INFO (slasharguments method)
|
|
|
|
if (!$relativepath and !empty($_SERVER['PATH_INFO'])) {
|
|
|
|
$path_info = $_SERVER['PATH_INFO'];
|
|
|
|
// check that PATH_INFO works == must not contain the script name
|
|
|
|
if (!strpos($path_info, $scriptname)) {
|
|
|
|
$relativepath = clean_param(rawurldecode($path_info), PARAM_PATH);
|
|
|
|
if ($relativepath === '/test') {
|
|
|
|
print_header();
|
|
|
|
notice ('Slasharguments work - using PATH_INFO parameter :-D');
|
|
|
|
print_footer();
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now if both fail try the old way
|
|
|
|
// (for compatibility with misconfigured or older buggy php implementations)
|
|
|
|
if (!$relativepath) {
|
|
|
|
$arr = explode($scriptname, me());
|
|
|
|
if (!empty($arr[1])) {
|
|
|
|
$path_info = strip_querystring($arr[1]);
|
|
|
|
$relativepath = clean_param(rawurldecode($path_info), PARAM_PATH);
|
|
|
|
if ($relativepath === '/test') {
|
|
|
|
print_header();
|
|
|
|
notice ('Slasharguments work - using compatibility hack :-|');
|
|
|
|
print_footer();
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $relativepath;
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Check for bad characters ?
|
|
|
|
*
|
|
|
|
* @param string $string ?
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $allowdots ?
|
|
|
|
* @todo Finish documenting this function - more detail needed in description as well as details on arguments
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-08-18 05:52:01 +00:00
|
|
|
function detect_munged_arguments($string, $allowdots=1) {
|
|
|
|
if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
|
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;
|
|
|
|
}
|
2004-03-16 07:11:14 +00:00
|
|
|
if (empty($string) or $string == '/') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-05-09 02:05:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Searches the current environment variables for some slash arguments
|
|
|
|
*
|
|
|
|
* @param string $file ?
|
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function get_slash_arguments($file='file.php') {
|
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);
|
2004-05-21 13:07:11 +00:00
|
|
|
|
2003-02-05 10:52:55 +00:00
|
|
|
if (!empty($pathinfo[1])) {
|
2004-11-04 07:00:12 +00:00
|
|
|
return addslashes($pathinfo[1]);
|
2003-01-12 06:53:25 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Extracts arguments from "/foo/bar/something"
|
|
|
|
* eg http://mysite.com/script.php/foo/bar/something
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $string ?
|
|
|
|
* @param int $i ?
|
|
|
|
* @return array|string
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2003-01-12 06:53:25 +00:00
|
|
|
function parse_slash_arguments($string, $i=0) {
|
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;
|
|
|
|
}
|
2004-09-22 14:39:15 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
2004-09-25 05:29:21 +00:00
|
|
|
* Just returns an array of text formats suitable for a popup menu
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses FORMAT_MOODLE
|
|
|
|
* @uses FORMAT_HTML
|
|
|
|
* @uses FORMAT_PLAIN
|
|
|
|
* @uses FORMAT_WIKI
|
|
|
|
* @uses FORMAT_MARKDOWN
|
|
|
|
* @return array
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2002-10-10 07:26:10 +00:00
|
|
|
function format_text_menu() {
|
2004-09-23 04:36:43 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
return array (FORMAT_MOODLE => get_string('formattext'),
|
|
|
|
FORMAT_HTML => get_string('formathtml'),
|
|
|
|
FORMAT_PLAIN => get_string('formatplain'),
|
|
|
|
FORMAT_WIKI => get_string('formatwiki'),
|
|
|
|
FORMAT_MARKDOWN => get_string('formatmarkdown'));
|
2002-10-10 07:26:10 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Given text in a variety of format codings, this function returns
|
2004-09-25 05:29:21 +00:00
|
|
|
* the text as safe HTML.
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
|
|
|
* @uses $CFG
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses FORMAT_MOODLE
|
|
|
|
* @uses FORMAT_HTML
|
|
|
|
* @uses FORMAT_PLAIN
|
|
|
|
* @uses FORMAT_WIKI
|
|
|
|
* @uses FORMAT_MARKDOWN
|
|
|
|
* @param string $text The text to be formatted. This is raw text originally from user input.
|
|
|
|
* @param int $format Identifier of the text format to be used
|
|
|
|
* (FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN)
|
|
|
|
* @param array $options ?
|
|
|
|
* @param int $courseid ?
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-01-16 10:49:07 +00:00
|
|
|
function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL ) {
|
2002-10-10 07:26:10 +00:00
|
|
|
|
2004-05-21 13:07:11 +00:00
|
|
|
global $CFG, $course;
|
2004-01-16 10:49:07 +00:00
|
|
|
|
2004-02-09 12:33:44 +00:00
|
|
|
if (!empty($CFG->cachetext)) {
|
|
|
|
$time = time() - $CFG->cachetext;
|
|
|
|
$md5key = md5($text);
|
2004-02-09 13:10:19 +00:00
|
|
|
if ($cacheitem = get_record_select('cache_text', "md5key = '$md5key' AND timemodified > '$time'")) {
|
2004-02-09 12:33:44 +00:00
|
|
|
return $cacheitem->formattedtext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-16 10:49:07 +00:00
|
|
|
if (empty($courseid)) {
|
2004-02-10 09:59:46 +00:00
|
|
|
if (!empty($course->id)) { // An ugly hack for better compatibility
|
2004-01-16 10:49:07 +00:00
|
|
|
$courseid = $course->id;
|
|
|
|
}
|
|
|
|
}
|
2003-08-26 18:44:09 +00:00
|
|
|
|
2004-02-10 09:59:46 +00:00
|
|
|
$CFG->currenttextiscacheable = true; // Default status - can be changed by any filter
|
|
|
|
|
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);
|
2004-08-09 14:54:39 +00:00
|
|
|
if (!isset($options->noclean)) {
|
|
|
|
$text = clean_text($text, $format);
|
|
|
|
}
|
2004-08-10 09:16:16 +00:00
|
|
|
$text = filter_text($text, $courseid);
|
2003-02-05 12:41:59 +00:00
|
|
|
break;
|
|
|
|
|
2003-04-27 10:46:16 +00:00
|
|
|
case FORMAT_PLAIN:
|
|
|
|
$text = htmlentities($text);
|
2004-05-11 23:17:25 +00:00
|
|
|
$text = rebuildnolinktag($text);
|
2004-09-22 14:39:15 +00:00
|
|
|
$text = str_replace(' ', ' ', $text);
|
2003-04-27 10:46:16 +00:00
|
|
|
$text = nl2br($text);
|
|
|
|
break;
|
|
|
|
|
2003-05-04 04:07:36 +00:00
|
|
|
case FORMAT_WIKI:
|
2004-08-27 14:31:40 +00:00
|
|
|
$text = wiki_to_html($text,$courseid);
|
2004-05-11 23:17:25 +00:00
|
|
|
$text = rebuildnolinktag($text);
|
2004-08-09 14:54:39 +00:00
|
|
|
if (!isset($options->noclean)) {
|
|
|
|
$text = clean_text($text, $format);
|
|
|
|
}
|
2004-08-10 09:16:16 +00:00
|
|
|
$text = filter_text($text, $courseid);
|
2003-05-04 04:07:36 +00:00
|
|
|
break;
|
|
|
|
|
2004-07-30 04:02:58 +00:00
|
|
|
case FORMAT_MARKDOWN:
|
|
|
|
$text = markdown_to_html($text);
|
2004-08-09 14:54:39 +00:00
|
|
|
if (!isset($options->noclean)) {
|
|
|
|
$text = clean_text($text, $format);
|
|
|
|
}
|
2004-09-08 16:18:45 +00:00
|
|
|
replace_smilies($text);
|
2004-08-10 09:16:16 +00:00
|
|
|
$text = filter_text($text, $courseid);
|
2004-07-30 04:02:58 +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
|
|
|
}
|
2004-03-09 06:44:27 +00:00
|
|
|
if (!isset($options->newlines)) {
|
|
|
|
$options->newlines=true;
|
|
|
|
}
|
|
|
|
$text = text_to_html($text, $options->smiley, $options->para, $options->newlines);
|
2004-08-09 14:54:39 +00:00
|
|
|
if (!isset($options->noclean)) {
|
|
|
|
$text = clean_text($text, $format);
|
|
|
|
}
|
2004-08-10 09:16:16 +00:00
|
|
|
$text = filter_text($text, $courseid);
|
2002-10-10 07:26:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-02-09 12:33:44 +00:00
|
|
|
|
2004-02-10 09:59:46 +00:00
|
|
|
if (!empty($CFG->cachetext) and $CFG->currenttextiscacheable) {
|
2004-02-09 12:33:44 +00:00
|
|
|
$newrecord->md5key = $md5key;
|
|
|
|
$newrecord->formattedtext = addslashes($text);
|
|
|
|
$newrecord->timemodified = time();
|
2004-08-09 14:54:39 +00:00
|
|
|
@insert_record('cache_text', $newrecord);
|
2004-02-09 12:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $text;
|
2002-10-10 07:26:10 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Given text in a variety of format codings, this function returns
|
|
|
|
* the text as plain text suitable for plain email.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses FORMAT_MOODLE
|
|
|
|
* @uses FORMAT_HTML
|
|
|
|
* @uses FORMAT_PLAIN
|
|
|
|
* @uses FORMAT_WIKI
|
|
|
|
* @uses FORMAT_MARKDOWN
|
|
|
|
* @param string $text The text to be formatted. This is raw text originally from user input.
|
|
|
|
* @param int $format Identifier of the text format to be used
|
|
|
|
* (FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN)
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2003-05-04 04:07:36 +00:00
|
|
|
function format_text_email($text, $format) {
|
|
|
|
|
|
|
|
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
|
2004-08-17 08:09:13 +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;
|
|
|
|
|
2003-11-07 03:27:21 +00:00
|
|
|
case FORMAT_HTML:
|
|
|
|
return html_to_text($text);
|
|
|
|
break;
|
|
|
|
|
2004-07-30 04:02:58 +00:00
|
|
|
case FORMAT_MOODLE:
|
|
|
|
case FORMAT_MARKDOWN:
|
2004-08-21 14:21:09 +00:00
|
|
|
default:
|
2004-08-17 08:09:13 +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
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* 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 $courseid and $text parameters
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $text The text to be passed through format filters
|
|
|
|
* @param int $courseid ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @return string
|
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-01-16 10:49:07 +00:00
|
|
|
function filter_text($text, $courseid=NULL) {
|
2003-10-13 14:11:17 +00:00
|
|
|
|
2004-01-16 10:49:07 +00:00
|
|
|
global $CFG;
|
2003-10-13 14:11:17 +00:00
|
|
|
|
2004-02-10 05:05:28 +00:00
|
|
|
if (!empty($CFG->textfilters)) {
|
|
|
|
$textfilters = explode(',', $CFG->textfilters);
|
|
|
|
foreach ($textfilters as $textfilter) {
|
2004-09-22 14:39:15 +00:00
|
|
|
if (is_readable($CFG->dirroot .'/'. $textfilter .'/filter.php')) {
|
|
|
|
include_once($CFG->dirroot .'/'. $textfilter .'/filter.php');
|
2004-08-08 06:57:44 +00:00
|
|
|
$functionname = basename($textfilter).'_filter';
|
|
|
|
if (function_exists($functionname)) {
|
|
|
|
$text = $functionname($courseid, $text);
|
|
|
|
}
|
2004-02-10 05:05:28 +00:00
|
|
|
}
|
2003-10-13 14:11:17 +00:00
|
|
|
}
|
|
|
|
}
|
2004-02-10 05:05:28 +00:00
|
|
|
|
2005-01-18 06:57:59 +00:00
|
|
|
/// <nolink> tags removed for XHTML compatibility
|
|
|
|
$text = str_replace('<nolink>', '', $text);
|
|
|
|
$text = str_replace('</nolink>', '', $text);
|
|
|
|
|
2003-10-13 14:11:17 +00:00
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +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.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses FORMAT_MOODLE
|
|
|
|
* @uses FORMAT_PLAIN
|
|
|
|
* @uses ALLOWED_TAGS
|
|
|
|
* @param string $text The text to be cleaned
|
|
|
|
* @param int $format Identifier of the text format to be used
|
|
|
|
* (FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN)
|
|
|
|
* @return string The cleaned up text
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-01-15 07:17:47 +00:00
|
|
|
function clean_text($text, $format=FORMAT_MOODLE) {
|
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
|
|
|
|
2004-05-21 13:07:11 +00:00
|
|
|
switch ($format) {
|
2004-07-30 04:02:58 +00:00
|
|
|
case FORMAT_PLAIN:
|
|
|
|
return $text;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
2004-03-28 06:31:27 +00:00
|
|
|
/// Remove tags that are not allowed
|
2002-10-18 09:09:19 +00:00
|
|
|
$text = strip_tags($text, $ALLOWED_TAGS);
|
2004-07-30 04:02:58 +00:00
|
|
|
|
2003-08-26 13:18:10 +00:00
|
|
|
/// Remove script events
|
2004-05-21 13:07:11 +00:00
|
|
|
$text = eregi_replace("([^a-z])language([[:space:]]*)=", "\\1Xlanguage=", $text);
|
|
|
|
$text = eregi_replace("([^a-z])on([a-z]+)([[:space:]]*)=", "\\1Xon\\2=", $text);
|
2003-04-27 10:46:16 +00:00
|
|
|
|
2004-08-21 14:21:09 +00:00
|
|
|
/// Clean up embedded scripts and , using kses
|
2004-08-21 04:34:06 +00:00
|
|
|
$text = cleanAttributes($text);
|
2004-07-30 04:02:58 +00:00
|
|
|
|
2003-04-27 10:46:16 +00:00
|
|
|
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
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
2004-09-25 05:29:21 +00:00
|
|
|
* This function takes a string and examines it for HTML tags.
|
2004-09-23 04:36:43 +00:00
|
|
|
* If tags are detected it passes the string to a helper function {@link cleanAttributes2()}
|
|
|
|
* which checks for attributes and filters them for malicious content
|
|
|
|
* 17/08/2004 :: Eamon DOT Costello AT dcu DOT ie
|
|
|
|
*
|
|
|
|
* @param string $str The string to be examined for html tags
|
|
|
|
* @return string
|
|
|
|
*/
|
2004-08-21 04:34:06 +00:00
|
|
|
function cleanAttributes($str){
|
|
|
|
$result = preg_replace(
|
|
|
|
'%(<[^>]*(>|$)|>)%me', #search for html tags
|
2004-08-21 14:21:09 +00:00
|
|
|
"cleanAttributes2('\\1')",
|
2004-08-21 04:34:06 +00:00
|
|
|
$str
|
2004-08-21 14:21:09 +00:00
|
|
|
);
|
2004-08-21 04:34:06 +00:00
|
|
|
return $result;
|
2004-08-21 14:21:09 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* This function takes a string with an html tag and strips out any unallowed
|
|
|
|
* protocols e.g. javascript:
|
|
|
|
* It calls ancillary functions in kses which are prefixed by kses
|
|
|
|
* 17/08/2004 :: Eamon DOT Costello AT dcu DOT ie
|
|
|
|
*
|
|
|
|
* @param string $htmlTag An html tag to be examined
|
|
|
|
* @return string
|
|
|
|
*/
|
2004-08-21 04:34:06 +00:00
|
|
|
function cleanAttributes2($htmlTag){
|
|
|
|
|
2004-09-29 14:00:35 +00:00
|
|
|
global $CFG, $ALLOWED_PROTOCOLS;
|
2004-09-22 14:39:15 +00:00
|
|
|
require_once($CFG->libdir .'/kses.php');
|
2004-08-21 04:34:06 +00:00
|
|
|
|
|
|
|
$htmlTag = kses_stripslashes($htmlTag);
|
2004-09-29 14:00:35 +00:00
|
|
|
if (substr($htmlTag, 0, 1) != '<') {
|
2004-08-21 04:34:06 +00:00
|
|
|
return '>'; //a single character ">" detected
|
|
|
|
}
|
2004-09-29 14:00:35 +00:00
|
|
|
if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $htmlTag, $matches)) {
|
2004-08-21 14:21:09 +00:00
|
|
|
return ''; // It's seriously malformed
|
|
|
|
}
|
2004-08-21 04:34:06 +00:00
|
|
|
$slash = trim($matches[1]); //trailing xhtml slash
|
2004-08-21 14:21:09 +00:00
|
|
|
$elem = $matches[2]; //the element name
|
2004-08-21 04:34:06 +00:00
|
|
|
$attrlist = $matches[3]; // the list of attributes as a string
|
|
|
|
|
2004-09-29 14:00:35 +00:00
|
|
|
$attrArray = kses_hair($attrlist, $ALLOWED_PROTOCOLS);
|
2004-08-21 04:34:06 +00:00
|
|
|
|
2004-08-21 14:21:09 +00:00
|
|
|
$attStr = '';
|
2004-09-29 14:00:35 +00:00
|
|
|
foreach ($attrArray as $arreach) {
|
2004-08-23 02:21:59 +00:00
|
|
|
$attStr .= ' '.strtolower($arreach['name']).'="'.$arreach['value'].'" ';
|
2004-08-21 04:34:06 +00:00
|
|
|
}
|
|
|
|
$xhtml_slash = '';
|
2004-09-29 14:00:35 +00:00
|
|
|
if (preg_match('%/\s*$%', $attrlist)) {
|
2004-08-21 14:21:09 +00:00
|
|
|
$xhtml_slash = ' /';
|
2004-08-21 04:34:06 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
return '<'. $slash . $elem . $attStr . $xhtml_slash .'>';
|
2004-08-21 04:34:06 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Replaces all known smileys in the text with image equivalents
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
|
|
|
* @param string $text Passed by reference. The string to search for smily strings.
|
|
|
|
* @return string
|
|
|
|
*/
|
2003-05-05 16:40:46 +00:00
|
|
|
function replace_smilies(&$text) {
|
2004-09-23 04:36:43 +00:00
|
|
|
///
|
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-11-07 14:55:44 +00:00
|
|
|
':-)' => 'smiley',
|
|
|
|
':)' => 'smiley',
|
|
|
|
':-D' => 'biggrin',
|
|
|
|
';-)' => 'wink',
|
|
|
|
':-/' => 'mixed',
|
|
|
|
'V-.' => 'thoughtful',
|
|
|
|
':-P' => 'tongueout',
|
|
|
|
'B-)' => 'cool',
|
|
|
|
'^-)' => 'approve',
|
|
|
|
'8-)' => 'wideeyes',
|
|
|
|
':o)' => 'clown',
|
|
|
|
':-(' => 'sad',
|
|
|
|
':(' => 'sad',
|
|
|
|
'8-.' => 'shy',
|
|
|
|
':-I' => 'blush',
|
|
|
|
':-X' => 'kiss',
|
|
|
|
'8-o' => 'surprise',
|
|
|
|
'P-|' => 'blackeye',
|
|
|
|
'8-[' => 'angry',
|
|
|
|
'xx-P' => 'dead',
|
|
|
|
'|-.' => 'sleepy',
|
|
|
|
'}-]' => 'evil',
|
2003-03-12 03:42:44 +00:00
|
|
|
);
|
|
|
|
|
2003-11-07 14:55:44 +00:00
|
|
|
if ($runonce == false) { /// After the first time this is not run again
|
2003-03-12 20:36:55 +00:00
|
|
|
foreach ($emoticons as $emoticon => $image){
|
2003-11-07 14:55:44 +00:00
|
|
|
$alttext = get_string($image, 'pix');
|
|
|
|
|
2003-03-12 21:37:05 +00:00
|
|
|
$e[] = $emoticon;
|
2004-09-23 04:36:43 +00:00
|
|
|
$img[] = '<img alt="'. $alttext .'" width="15" height="15" src="'. $CFG->pixpath .'/s/'. $image .'.gif" />';
|
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
|
|
|
|
2004-03-25 06:31:44 +00:00
|
|
|
// Exclude from transformations all the code inside <script> tags
|
|
|
|
// Needed to solve Bug 1185. Thanks to jouse 2001 detecting it. :-)
|
|
|
|
// Based on code from glossary fiter by Williams Castillo.
|
|
|
|
// - Eloy
|
|
|
|
|
|
|
|
// Detect all the <script> zones to take out
|
|
|
|
$excludes = array();
|
|
|
|
preg_match_all('/<script language(.+?)<\/script>/is',$text,$list_of_excludes);
|
|
|
|
|
|
|
|
// Take out all the <script> zones from text
|
|
|
|
foreach (array_unique($list_of_excludes[0]) as $key=>$value) {
|
|
|
|
$excludes['<+'.$key.'+>'] = $value;
|
|
|
|
}
|
|
|
|
if ($excludes) {
|
|
|
|
$text = str_replace($excludes,array_keys($excludes),$text);
|
|
|
|
}
|
|
|
|
|
2003-11-07 14:55:44 +00:00
|
|
|
/// this is the meat of the code - this is run every time
|
2003-05-05 16:40:46 +00:00
|
|
|
$text = str_replace($e, $img, $text);
|
2004-03-25 06:31:44 +00:00
|
|
|
|
|
|
|
// Recover all the <script> zones to text
|
|
|
|
if ($excludes) {
|
|
|
|
$text = str_replace(array_keys($excludes),$excludes,$text);
|
|
|
|
}
|
2002-10-12 05:09:49 +00:00
|
|
|
}
|
2002-10-10 07:26:10 +00:00
|
|
|
|
2004-09-25 05:29:21 +00:00
|
|
|
/**
|
|
|
|
* Given plain text, makes it into HTML as nicely as possible.
|
|
|
|
* May contain HTML tags already
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
|
|
|
* @param string $text The string to convert.
|
|
|
|
* @param boolean $smiley Convert any smiley characters to smiley images?
|
|
|
|
* @param boolean $para If true then the returned string will be wrapped in paragraph tags
|
|
|
|
* @param boolean $newlines If true then lines newline breaks will be converted to HTML newline breaks.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
|
2004-03-09 06:44:27 +00:00
|
|
|
function text_to_html($text, $smiley=true, $para=true, $newlines=true) {
|
2004-09-25 05:29:21 +00:00
|
|
|
///
|
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.
|
2004-03-09 06:44:27 +00:00
|
|
|
if ($newlines) {
|
|
|
|
$text = nl2br($text);
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
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) {
|
2004-09-22 14:39:15 +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
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Given Wiki formatted text, make it into XHTML using external function
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
|
|
|
* @param string $text The text to be converted.
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $courseid The id, as found in 'course' table, of the course this text is being placed in.
|
2004-09-23 04:36:43 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function wiki_to_html($text, $courseid) {
|
|
|
|
|
2004-08-27 14:31:40 +00:00
|
|
|
global $CFG;
|
2003-05-01 03:43:16 +00:00
|
|
|
|
2004-09-22 14:39:15 +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;
|
2004-09-23 04:36:43 +00:00
|
|
|
return $wiki->format($text, $courseid);
|
2003-05-01 03:43:16 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Given Markdown formatted text, make it into XHTML using external function
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @param string $text The markdown formatted text to be converted.
|
|
|
|
* @return string Converted text
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-07-30 04:02:58 +00:00
|
|
|
function markdown_to_html($text) {
|
|
|
|
global $CFG;
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
require_once($CFG->libdir .'/markdown.php');
|
2004-07-30 04:02:58 +00:00
|
|
|
|
|
|
|
return Markdown($text);
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
2004-09-25 05:29:21 +00:00
|
|
|
* Given HTML text, make it into plain text using external function
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
|
|
|
* @uses $CFG
|
|
|
|
* @param string $html The text to be converted.
|
|
|
|
* @return string
|
|
|
|
*/
|
2003-11-07 03:27:21 +00:00
|
|
|
function html_to_text($html) {
|
2004-09-25 05:29:21 +00:00
|
|
|
|
2003-11-07 04:14:38 +00:00
|
|
|
global $CFG;
|
2003-11-07 03:27:21 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
require_once($CFG->libdir .'/html2text.php');
|
2003-11-07 03:27:21 +00:00
|
|
|
|
|
|
|
return html2text($html);
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Given some text this function converts any URLs it finds into HTML links
|
|
|
|
*
|
|
|
|
* @param string $text Passed in by reference. The string to be searched for urls.
|
|
|
|
*/
|
2003-05-05 16:40:46 +00:00
|
|
|
function convert_urls_into_links(&$text) {
|
|
|
|
/// 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
|
2004-05-21 13:07:11 +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
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $needle The string to search for
|
|
|
|
* @param string $haystack The string to search for $needle in
|
|
|
|
* @param int $case ?
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-05-21 13:07:11 +00:00
|
|
|
function highlight($needle, $haystack, $case=0,
|
2004-09-22 14:39:15 +00:00
|
|
|
$left_string='<span class="highlight">', $right_string='</span>') {
|
2003-12-13 06:27:25 +00:00
|
|
|
if (empty($needle)) {
|
|
|
|
return $haystack;
|
|
|
|
}
|
|
|
|
|
2004-12-31 15:23:50 +00:00
|
|
|
$list_of_words = eregi_replace("[^-a-zA-Z0-9&.']", " ", $needle);
|
2004-09-22 14:39:15 +00:00
|
|
|
$list_array = explode(' ', $list_of_words);
|
2003-08-09 03:57:46 +00:00
|
|
|
for ($i=0; $i<sizeof($list_array); $i++) {
|
|
|
|
if (strlen($list_array[$i]) == 1) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$list_array[$i] = '';
|
2003-08-09 03:57:46 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
$list_of_words = implode(' ', $list_array);
|
2003-08-09 03:57:46 +00:00
|
|
|
$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);
|
2004-09-22 14:39:15 +00:00
|
|
|
$list_of_words_cp = eregi_replace(' +', '|', $list_of_words_cp);
|
2003-08-09 03:57:46 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
if ($list_of_words_cp{0}=='|') {
|
|
|
|
$list_of_words_cp{0} = '';
|
2003-08-09 03:57:46 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
if ($list_of_words_cp{strlen($list_of_words_cp)-1}=='|') {
|
|
|
|
$list_of_words_cp{strlen($list_of_words_cp)-1}='';
|
2003-08-09 03:57:46 +00:00
|
|
|
}
|
|
|
|
|
2004-12-31 15:23:50 +00:00
|
|
|
$list_of_words_cp = trim($list_of_words_cp);
|
|
|
|
|
|
|
|
if ($list_of_words_cp) {
|
|
|
|
|
|
|
|
$list_of_words_cp = "(". $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);
|
|
|
|
}
|
2003-08-09 03:57:46 +00:00
|
|
|
}
|
|
|
|
$haystack = str_replace(array_keys($final),$final,$haystack);
|
|
|
|
|
2004-09-23 07:41:37 +00:00
|
|
|
return $haystack;
|
2003-08-09 03:57:46 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* This function will highlight instances of $needle in $haystack
|
|
|
|
* It's faster that the above function and doesn't care about
|
|
|
|
* HTML or anything.
|
|
|
|
*
|
|
|
|
* @param string $needle The string to search for
|
|
|
|
* @param string $haystack The string to search for $needle in
|
|
|
|
* @return string
|
|
|
|
*/
|
2003-08-09 03:57:46 +00:00
|
|
|
function highlightfast($needle, $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);
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
$parts[$key] .= '<span class="highlight">'.substr($haystack, $pos, strlen($needle)).'</span>';
|
2002-06-11 07:01:51 +00:00
|
|
|
$pos += strlen($needle);
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2002-06-11 07:01:51 +00:00
|
|
|
|
|
|
|
return (join('', $parts));
|
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
/// STANDARD WEB PAGE PARTS ///////////////////////////////////////////////////
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print a standard header
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $USER
|
|
|
|
* @uses $CFG
|
|
|
|
* @uses $THEME
|
|
|
|
* @uses $SESSION
|
|
|
|
* @param string $title Appears at the top of the window
|
|
|
|
* @param string $heading Appears at the top of the page
|
|
|
|
* @param string $navigation Premade navigation string (for use as breadcrumbs links)
|
|
|
|
* @param string $focus Indicates form element to get cursor focus on load eg inputform.password
|
|
|
|
* @param string $meta Meta tags to be added to the header
|
|
|
|
* @param boolean $cache Should this page be cacheable?
|
|
|
|
* @param string $button HTML code for a button (usually for module editing)
|
|
|
|
* @param string $menu HTML code for a popup menu
|
|
|
|
* @param boolean $usexml use XML for this page
|
|
|
|
* @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function print_header ($title='', $heading='', $navigation='', $focus='', $meta='',
|
|
|
|
$cache=true, $button=' ', $menu='', $usexml=false, $bodytags='') {
|
2004-07-14 06:54:43 +00:00
|
|
|
|
2003-05-08 16:09:30 +00:00
|
|
|
global $USER, $CFG, $THEME, $SESSION;
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2004-02-09 07:31:04 +00:00
|
|
|
global $course; // This is a bit of an ugly hack to be gotten rid of later
|
|
|
|
if (!empty($course->lang)) {
|
|
|
|
$CFG->courselang = $course->lang;
|
|
|
|
}
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
if (file_exists($CFG->dirroot .'/theme/'. $CFG->theme .'/styles.php')) {
|
2002-12-20 14:44:14 +00:00
|
|
|
$styles = $CFG->stylesheet;
|
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$styles = $CFG->wwwroot .'/theme/standard/styles.php';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
if ($navigation == 'home') {
|
2002-12-20 14:44:14 +00:00
|
|
|
$home = true;
|
2004-09-22 14:39:15 +00:00
|
|
|
$navigation = '';
|
2002-12-29 04:17:32 +00:00
|
|
|
} else {
|
|
|
|
$home = false;
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
if ($button == '') {
|
|
|
|
$button = ' ';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$menu and $navigation) {
|
2004-06-19 16:13:28 +00:00
|
|
|
if (empty($CFG->loginhttps)) {
|
|
|
|
$wwwroot = $CFG->wwwroot;
|
|
|
|
} else {
|
|
|
|
$wwwroot = str_replace('http','https',$CFG->wwwroot);
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
if (isset($USER->id)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$menu = '<font size="2"><a target="'. $CFG->framename .'" href="'. $wwwroot .'/login/logout.php">'. get_string('logout') .'</a></font>';
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$menu = '<font size="2"><a target="'. $CFG->framename .'" href="'. $wwwroot .'/login/index.php">'. get_string('login') .'</a></font>';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-21 14:21:09 +00:00
|
|
|
|
2004-07-25 13:47:38 +00:00
|
|
|
if (isset($SESSION->justloggedin)) {
|
|
|
|
unset($SESSION->justloggedin);
|
|
|
|
if (!empty($CFG->displayloginfailures)) {
|
|
|
|
if (!empty($USER->username) and !isguest()) {
|
|
|
|
if ($count = count_login_failures($CFG->displayloginfailures, $USER->username, $USER->lastlogin)) {
|
|
|
|
$menu .= ' <font size="1">';
|
|
|
|
if (empty($count->accounts)) {
|
|
|
|
$menu .= get_string('failedloginattempts', '', $count);
|
|
|
|
} else {
|
|
|
|
$menu .= get_string('failedloginattemptsall', '', $count);
|
|
|
|
}
|
|
|
|
if (isadmin()) {
|
|
|
|
$menu .= ' (<a href="'.$CFG->wwwroot.'/course/log.php'.
|
2004-09-16 17:13:57 +00:00
|
|
|
'?chooselog=1&id=1&modid=site_errors">'.get_string('logs').'</a>)';
|
2004-07-25 13:47:38 +00:00
|
|
|
}
|
|
|
|
$menu .= '</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";
|
|
|
|
|
2004-04-27 13:57:46 +00:00
|
|
|
if (!empty($CFG->unicode)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$encoding = 'utf-8';
|
2004-06-21 13:07:44 +00:00
|
|
|
} else if (!empty($CFG->courselang)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$encoding = get_string('thischarset');
|
2004-06-21 13:07:44 +00:00
|
|
|
moodle_setlocale();
|
|
|
|
} else {
|
|
|
|
if (!empty($SESSION->encoding)) {
|
|
|
|
$encoding = $SESSION->encoding;
|
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$SESSION->encoding = $encoding = get_string('thischarset');
|
2004-06-21 13:07:44 +00:00
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
$meta = '<meta http-equiv="content-type" content="text/html; charset='. $encoding .'" />'. "\n". $meta ."\n";
|
2004-07-21 12:16:36 +00:00
|
|
|
if (!$usexml) {
|
|
|
|
@header('Content-type: text/html; charset='.$encoding);
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
if ( get_string('thisdirection') == 'rtl' ) {
|
|
|
|
$direction = ' dir="rtl"';
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$direction = ' dir="ltr"';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2004-05-21 13:07:11 +00:00
|
|
|
|
2004-12-10 06:20:54 +00:00
|
|
|
if ($cache) { // Allow caching on "back" (but not on normal clicks)
|
|
|
|
@header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
|
|
|
|
@header('Pragma: no-cache');
|
|
|
|
@header('Expires: ');
|
|
|
|
} else { // Do everything we can to always prevent clients and proxies caching
|
2004-07-21 12:16:36 +00:00
|
|
|
@header('Cache-Control: no-store, no-cache, must-revalidate');
|
|
|
|
@header('Cache-Control: post-check=0, pre-check=0', false);
|
|
|
|
@header('Pragma: no-cache');
|
2004-12-10 06:20:54 +00:00
|
|
|
@header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
|
|
|
|
@header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
2004-07-21 12:16:36 +00:00
|
|
|
|
2004-12-10 06:20:54 +00:00
|
|
|
$meta .= "\n<meta http-equiv=\"pragma\" content=\"no-cache\" />";
|
|
|
|
$meta .= "\n<meta http-equiv=\"expires\" content=\"0\" />";
|
2003-09-21 15:45:24 +00:00
|
|
|
}
|
2004-12-10 06:20:54 +00:00
|
|
|
@header('Accept-Ranges: none');
|
2003-09-21 15:45:24 +00:00
|
|
|
|
|
|
|
if ($usexml) { // Added by Gustav Delius / Mad Alex for MathML output
|
2004-09-21 11:41:58 +00:00
|
|
|
// Modified by Julian Sedding
|
2003-09-21 15:45:24 +00:00
|
|
|
$currentlanguage = current_language();
|
2004-09-21 11:41:58 +00:00
|
|
|
$mathplayer = preg_match("/MathPlayer/i", $_SERVER['HTTP_USER_AGENT']);
|
|
|
|
if(!$mathplayer) {
|
|
|
|
header('Content-Type: application/xhtml+xml');
|
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<?xml version="1.0" ?>'."\n";
|
2003-09-21 15:45:24 +00:00
|
|
|
if (!empty($CFG->xml_stylesheets)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$stylesheets = explode(';', $CFG->xml_stylesheets);
|
2003-09-21 15:45:24 +00:00
|
|
|
foreach ($stylesheets as $stylesheet) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<?xml-stylesheet type="text/xsl" href="'. $CFG->wwwroot .'/'. $stylesheet .'" ?>' . "\n";
|
2003-09-21 15:45:24 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1';
|
2003-09-21 16:35:49 +00:00
|
|
|
if (!empty($CFG->xml_doctype_extra)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo ' plus '. $CFG->xml_doctype_extra;
|
2003-09-21 16:35:49 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '//' . strtoupper($currentlanguage) . '" "'. $CFG->xml_dtd .'">'."\n";
|
2004-09-21 11:41:58 +00:00
|
|
|
$direction = " xmlns=\"http://www.w3.org/1999/xhtml\"
|
|
|
|
xmlns:math=\"http://www.w3.org/1998/Math/MathML\"
|
|
|
|
xml:lang=\"en\"
|
|
|
|
xmlns:xlink=\"http://www.w3.org/1999/xlink\"
|
|
|
|
$direction";
|
|
|
|
if($mathplayer) {
|
|
|
|
$meta .= '<object id="mathplayer" classid="clsid:32F66A20-7614-11D4-BD11-00104BD3F987">' . "\n";
|
2004-09-22 14:39:15 +00:00
|
|
|
$meta .= '<!--comment required to prevent this becoming an empty tag-->'."\n";
|
|
|
|
$meta .= '</object>'."\n";
|
2004-09-21 11:41:58 +00:00
|
|
|
$meta .= '<?import namespace="math" implementation="#mathplayer" ?>' . "\n";
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2003-10-24 06:27:15 +00:00
|
|
|
$title = str_replace('"', '"', $title);
|
2004-02-19 17:56:05 +00:00
|
|
|
$title = strip_tags($title);
|
2003-10-24 06:27:15 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
include ($CFG->dirroot .'/theme/'. $CFG->theme .'/header.html');
|
2004-12-30 12:54:22 +00:00
|
|
|
|
|
|
|
echo message_popup_window();
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* This version of print_header is simpler because the course name does not have to be
|
|
|
|
* provided explicitly in the strings. It can be used on the site page as in courses
|
|
|
|
* Eventually all print_header could be replaced by print_header_simple
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $title Appears at the top of the window
|
|
|
|
* @param string $heading Appears at the top of the page
|
|
|
|
* @param string $navigation Premade navigation string (for use as breadcrumbs links)
|
|
|
|
* @param string $focus Indicates form element to get cursor focus on load eg inputform.password
|
|
|
|
* @param string $meta Meta tags to be added to the header
|
|
|
|
* @param boolean $cache Should this page be cacheable?
|
|
|
|
* @param string $button HTML code for a button (usually for module editing)
|
|
|
|
* @param string $menu HTML code for a popup menu
|
|
|
|
* @param boolean $usexml use XML for this page
|
|
|
|
* @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
|
|
|
|
$cache=true, $button=' ', $menu='', $usexml=false, $bodytags='') {
|
2004-08-21 20:20:58 +00:00
|
|
|
|
|
|
|
global $course; // The same hack is used in print_header
|
|
|
|
|
|
|
|
$shortname ='';
|
|
|
|
if ($course->category) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$shortname = '<a href="../../course/view.php?id='. $course->id .'">'. $course->shortname .'</a> ->';
|
2004-08-21 20:20:58 +00:00
|
|
|
}
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
print_header($course->shortname .': '. $title, $course->fullname .' '. $heading, $shortname .' '. $navigation, $focus, $meta,
|
2004-08-21 20:20:58 +00:00
|
|
|
$cache, $button, $menu, $usexml, $bodytags);
|
|
|
|
}
|
2004-08-23 13:18:39 +00:00
|
|
|
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
|
|
|
* @uses $USER
|
|
|
|
* @uses $THEME
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param course $course {@link $COURSE} object containing course information
|
|
|
|
* @param ? $usercourse ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2005-01-11 08:26:35 +00:00
|
|
|
function print_footer($course=NULL, $usercourse=NULL) {
|
2002-12-20 14:44:14 +00:00
|
|
|
global $USER, $CFG, $THEME;
|
|
|
|
|
|
|
|
/// Course links
|
|
|
|
if ($course) {
|
2005-01-11 08:26:35 +00:00
|
|
|
if ($course == 'none') { // Don't print any links etc
|
|
|
|
$homelink = '';
|
|
|
|
$loggedinas = '';
|
|
|
|
} else if ($course == 'home') { // special case for site home page - please do not remove
|
|
|
|
$course = get_site();
|
2004-09-23 12:09:19 +00:00
|
|
|
$homelink = '<a title="moodle '. $CFG->release .' ('. $CFG->version .')" href="http://moodle.org/" target="_blank">';
|
|
|
|
$homelink .= '<br /><img width="100" height="30" src="pix/moodlelogo.gif" border="0" alt="moodlelogo" /></a>';
|
2005-01-11 08:26:35 +00:00
|
|
|
$homepage = true;
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2005-01-11 08:26:35 +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 {
|
2005-01-11 08:26:35 +00:00
|
|
|
$course = get_site(); // Set course as site course by default
|
|
|
|
$homelink = '<a target="'.$CFG->framename.'" href="'.$CFG->wwwroot.'/">'.get_string('home').'</a>';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2005-01-11 08:26:35 +00:00
|
|
|
/// Set the user link if necessary
|
|
|
|
if (!$usercourse and is_object($course)) {
|
2004-08-02 19:09:06 +00:00
|
|
|
$usercourse = $course;
|
|
|
|
}
|
|
|
|
|
2005-01-11 08:26:35 +00:00
|
|
|
if (!isset($loggedinas)) {
|
|
|
|
$loggedinas = user_login_string($usercourse, $USER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Include the actual footer file
|
2003-04-25 06:40:30 +00:00
|
|
|
|
2005-01-11 08:26:35 +00:00
|
|
|
include ($CFG->dirroot.'/theme/'.$CFG->theme.'/footer.html');
|
2003-04-25 06:40:30 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* This function is called by stylesheets to set up the header
|
|
|
|
* approriately as well as the current path
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $lastmodified ?
|
|
|
|
* @param int $lifetime ?
|
|
|
|
* @param string $thename ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function style_sheet_setup($lastmodified=0, $lifetime=300, $themename='') {
|
2003-08-12 07:52:19 +00:00
|
|
|
|
|
|
|
global $CFG;
|
2004-05-21 13:07:11 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
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
|
2003-08-12 07:52:19 +00:00
|
|
|
|
|
|
|
if (!empty($themename)) {
|
|
|
|
$CFG->theme = $themename;
|
|
|
|
}
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
return $CFG->wwwroot .'/theme/'. $CFG->theme;
|
2003-08-12 07:52:19 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Returns text to be displayed to the user which reflects their login status
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
|
|
|
* @uses $USER
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param course $course {@link $COURSE} object containing course information
|
|
|
|
* @param user $user {@link $USER} object containing user information
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
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)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
if ($realuser = get_record('user', 'id', $user->realuser)) {
|
2003-11-28 11:00:46 +00:00
|
|
|
$fullname = fullname($realuser, true);
|
|
|
|
$realuserinfo = " [<a target=\"{$CFG->framename}\"
|
|
|
|
href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&return=$realuser->id\">$fullname</a>] ";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2002-12-29 04:17:32 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$realuserinfo = '';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-06-22 18:35:59 +00:00
|
|
|
if (empty($CFG->loginhttps)) {
|
|
|
|
$wwwroot = $CFG->wwwroot;
|
|
|
|
} else {
|
|
|
|
$wwwroot = str_replace('http','https',$CFG->wwwroot);
|
|
|
|
}
|
|
|
|
|
2003-04-25 06:40:30 +00:00
|
|
|
if (isset($user->id) and $user->id) {
|
2003-11-28 11:00:46 +00:00
|
|
|
$fullname = fullname($user, true);
|
|
|
|
$username = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">$fullname</a>";
|
2004-05-30 00:55:48 +00:00
|
|
|
if (isguest($user->id)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).
|
|
|
|
" (<a target=\"{$CFG->framename}\" href=\"$wwwroot/login/index.php\">".get_string('login').'</a>)';
|
2004-05-30 00:55:48 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).
|
|
|
|
" (<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/login/logout.php\">".get_string('logout').'</a>)';
|
2004-05-30 00:55:48 +00:00
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$loggedinas = get_string('loggedinnot', 'moodle').
|
|
|
|
" (<a target=\"{$CFG->framename}\" href=\"$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
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints breadcrumbs links
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $navigation The breadcrumbs string to be printed
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2002-12-20 14:44:14 +00:00
|
|
|
function print_navigation ($navigation) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($navigation) {
|
|
|
|
if (! $site = get_site()) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$site->shortname = get_string('home');;
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2004-05-31 05:21:58 +00:00
|
|
|
$navigation = str_replace('->', '»', $navigation);
|
2004-09-25 05:29:21 +00:00
|
|
|
echo '<a target="'. $CFG->framename .'" href="'. $CFG->wwwroot .'/">'. $site->shortname .'</a> » '. $navigation;
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints a string in a specified size
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $text The text to be displayed
|
|
|
|
* @param int $size The size to set the font for text display.
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2003-07-21 04:53:55 +00:00
|
|
|
function print_headline($text, $size=2) {
|
2004-09-23 04:36:43 +00:00
|
|
|
echo '<strong><font size="'. $size .'">'. $text .'</font></strong><br />'."\n";
|
2003-07-21 04:53:55 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints text in a format for use in headings.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $text The text to be displayed
|
|
|
|
* @param string $align The alignment of the printed paragraph of text
|
|
|
|
* @param int $size The size to set the font for text display.
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function print_heading($text, $align='center', $size=3) {
|
2004-09-23 04:36:43 +00:00
|
|
|
echo '<p align="'. $align .'"><font size="'. $size .'"><strong>'. stripslashes_safe($text) .'</strong></font></p>';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Centered heading with attached help button (same title text)
|
|
|
|
* and optional icon attached
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $text The text to be displayed
|
|
|
|
* @param string $helppage The help page to link to
|
|
|
|
* @param string $module The module whose help should be linked to
|
|
|
|
* @param string $icon Image to display if needed
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function print_heading_with_help($text, $helppage, $module='moodle', $icon='') {
|
2004-09-23 04:36:43 +00:00
|
|
|
echo '<p align="center"><font size="3">'. $icon .'<strong>'. stripslashes_safe($text);
|
2002-12-20 14:44:14 +00:00
|
|
|
helpbutton($helppage, $text, $module);
|
2004-09-23 04:36:43 +00:00
|
|
|
echo '</strong></font></p>';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2004-05-21 13:07:11 +00:00
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print a link to continue on to another page.
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
|
|
|
* @param string $link The url to create a link to.
|
|
|
|
*/
|
2002-12-20 14:44:14 +00:00
|
|
|
function print_continue($link) {
|
|
|
|
|
2004-08-07 13:43:01 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if (!$link) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$link = $_SERVER['HTTP_REFERER'];
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
print_heading('<a target="'. $CFG->framename .'" href="'. $link .'">'. get_string('continue').'</a>');
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print a message in a standard themed box.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $message ?
|
|
|
|
* @param string $align ?
|
|
|
|
* @param string $width ?
|
|
|
|
* @param string $color ?
|
|
|
|
* @param int $padding ?
|
|
|
|
* @param string $class ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function print_simple_box($message, $align='', $width='', $color='#FFFFFF', $padding=5, $class='generalbox') {
|
2002-12-20 14:44:14 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print the top portion of a standard themed box.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $align ?
|
|
|
|
* @param string $width ?
|
|
|
|
* @param string $color ?
|
|
|
|
* @param int $padding ?
|
|
|
|
* @param string $class ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function print_simple_box_start($align='', $width='', $color='#FFFFFF', $padding=5, $class='generalbox') {
|
2002-12-20 14:44:14 +00:00
|
|
|
global $THEME;
|
|
|
|
|
|
|
|
if ($align) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$align = 'align="'. $align .'"';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
if ($width) {
|
2004-09-22 14:39:15 +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
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print the end portion of a standard themed box.
|
|
|
|
*/
|
2002-12-20 14:44:14 +00:00
|
|
|
function print_simple_box_end() {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '</td></tr></table>';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print a self contained form with a single submit button.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $link ?
|
|
|
|
* @param array $options ?
|
|
|
|
* @param string $label ?
|
|
|
|
* @param string $method ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-12-23 08:58:15 +00:00
|
|
|
function print_single_button($link, $options, $label='OK', $method='get', $target='_self') {
|
|
|
|
echo '<form action="'. $link .'" method="'. $method .'" target="'.$target.'">';
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($options) {
|
|
|
|
foreach ($options as $name => $value) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<input type="hidden" name="'. $name .'" value="'. $value .'" />';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<input type="submit" value="'. $label .'" /></form>';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print a spacer image with the option of including a line break.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $height ?
|
|
|
|
* @param int $width ?
|
|
|
|
* @param boolean $br ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2002-12-20 14:44:14 +00:00
|
|
|
function print_spacer($height=1, $width=1, $br=true) {
|
|
|
|
global $CFG;
|
2004-09-22 14:39:15 +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) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<br />'."\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Given the path to a picture file in a course, or a URL,
|
|
|
|
* this function includes the picture in the page.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $path ?
|
|
|
|
* @param int $courseid ?
|
|
|
|
* @param int $height ?
|
|
|
|
* @param int $width ?
|
|
|
|
* @param string $link ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function print_file_picture($path, $courseid=0, $height='', $width='', $link='') {
|
2002-12-20 14:44:14 +00:00
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($height) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$height = 'height="'. $height .'"';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
if ($width) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$width = 'width="'. $width .'"';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
if ($link) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<a href="'. $link .'">';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
if (substr(strtolower($path), 0, 7) == 'http://') {
|
|
|
|
echo '<img border="0" '.$height . $width .' src="'. $path .'" />';
|
2002-12-20 14:44:14 +00:00
|
|
|
|
|
|
|
} else if ($courseid) {
|
2004-09-22 14:39:15 +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
|
2004-09-22 14:39:15 +00:00
|
|
|
echo $CFG->wwwroot .'/file.php/'. $courseid .'/'. $path;
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo $CFG->wwwroot .'/file.php?file=/'. $courseid .'/'. $path;
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '" />';
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo 'Error: must pass URL or course';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
if ($link) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '</a>';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print the specified user's avatar.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $userid ?
|
|
|
|
* @param int $courseid ?
|
|
|
|
* @param boolean $picture Print the user picture?
|
2004-12-23 08:58:15 +00:00
|
|
|
* @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatability
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param boolean $returnstring If false print picture to current page, otherwise return the output as string
|
|
|
|
* @param boolean $link Enclose printed image in a link to view specified course?
|
|
|
|
* return string
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2005-01-01 04:22:19 +00:00
|
|
|
function print_user_picture($userid, $courseid, $picture, $size=0, $returnstring=false, $link=true, $target='') {
|
2003-12-30 17:18:06 +00:00
|
|
|
global $CFG;
|
2002-12-20 14:44:14 +00:00
|
|
|
|
|
|
|
if ($link) {
|
2005-01-01 04:22:19 +00:00
|
|
|
if ($target) {
|
|
|
|
$target=' target="_blank"';
|
|
|
|
}
|
|
|
|
$output = '<a '.$target.' href="'. $CFG->wwwroot .'/user/view.php?id='. $userid .'&course='. $courseid .'">';
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$output = '';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2004-12-23 08:58:15 +00:00
|
|
|
if (empty($size)) {
|
|
|
|
$file = 'f2';
|
|
|
|
$size = 35;
|
|
|
|
} else if ($size === true or $size == 1) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$file = 'f1';
|
2002-12-20 14:44:14 +00:00
|
|
|
$size = 100;
|
2004-12-23 08:58:15 +00:00
|
|
|
} else if ($size >= 50) {
|
|
|
|
$file = 'f1';
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$file = 'f2';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
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
|
2004-09-23 03:17:25 +00:00
|
|
|
$output .= '<img align="middle" src="'. $CFG->wwwroot .'/user/pix.php/'. $userid .'/'. $file .'.jpg"'.
|
2004-09-22 14:39:15 +00:00
|
|
|
' border="0" width="'. $size .'" height="'. $size .'" alt="" />';
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-23 03:17:25 +00:00
|
|
|
$output .= '<img align="middle" src="'. $CFG->wwwroot .'/user/pix.php?file=/'. $userid .'/'. $file .'.jpg"'.
|
2004-09-22 14:39:15 +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)
|
2004-09-16 17:13:57 +00:00
|
|
|
$output .= "<img align=\"middle\" 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) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= '</a>';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($returnstring) {
|
|
|
|
return $output;
|
|
|
|
} else {
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints a summary of a user in a nice little box.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @uses $USER
|
|
|
|
* @param user $user A {@link $USER} object representing a user
|
|
|
|
* @param course $course A {@link $COURSE} object representing a course
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-01-10 16:41:29 +00:00
|
|
|
function print_user($user, $course) {
|
|
|
|
|
2004-09-25 05:29:21 +00:00
|
|
|
global $CFG, $USER;
|
2004-01-10 16:47:14 +00:00
|
|
|
|
2004-01-10 16:41:29 +00:00
|
|
|
static $string;
|
|
|
|
static $datestring;
|
|
|
|
static $countries;
|
|
|
|
static $isteacher;
|
2004-09-06 14:03:17 +00:00
|
|
|
static $isadmin;
|
2004-01-10 16:41:29 +00:00
|
|
|
|
|
|
|
if (empty($string)) { // Cache all the strings for the rest of the page
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
$string->email = get_string('email');
|
|
|
|
$string->location = get_string('location');
|
|
|
|
$string->lastaccess = get_string('lastaccess');
|
|
|
|
$string->activity = get_string('activity');
|
|
|
|
$string->unenrol = get_string('unenrol');
|
|
|
|
$string->loginas = get_string('loginas');
|
|
|
|
$string->fullprofile = get_string('fullprofile');
|
|
|
|
$string->role = get_string('role');
|
|
|
|
$string->name = get_string('name');
|
|
|
|
$string->never = get_string('never');
|
|
|
|
|
|
|
|
$datestring->day = get_string('day');
|
|
|
|
$datestring->days = get_string('days');
|
|
|
|
$datestring->hour = get_string('hour');
|
|
|
|
$datestring->hours = get_string('hours');
|
|
|
|
$datestring->min = get_string('min');
|
|
|
|
$datestring->mins = get_string('mins');
|
|
|
|
$datestring->sec = get_string('sec');
|
|
|
|
$datestring->secs = get_string('secs');
|
2004-01-10 16:41:29 +00:00
|
|
|
|
|
|
|
$countries = get_list_of_countries();
|
|
|
|
|
|
|
|
$isteacher = isteacher($course->id);
|
2004-09-06 14:03:17 +00:00
|
|
|
$isadmin = isadmin();
|
2004-01-10 16:41:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '<table width="80%" align="center" border="0" cellpadding="10" cellspacing="0" class="userinfobox">';
|
|
|
|
echo '<tr>';
|
|
|
|
echo '<td width="100" bgcolor="#ffffff" valign="top" class="userinfoboxside">';
|
|
|
|
print_user_picture($user->id, $course->id, $user->picture, true);
|
|
|
|
echo '</td>';
|
|
|
|
echo '<td width="100%" bgcolor="#ffffff" valign="top" class="userinfoboxsummary">';
|
|
|
|
echo '<font size="-1">';
|
2004-09-23 04:36:43 +00:00
|
|
|
echo '<font size="3"><strong>'.fullname($user, $isteacher).'</strong></font>';
|
2004-01-10 16:41:29 +00:00
|
|
|
echo '<p>';
|
|
|
|
if (!empty($user->role) and ($user->role <> $course->teacher)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo $string->role .': '. $user->role .'<br />';
|
2004-01-10 16:41:29 +00:00
|
|
|
}
|
2004-03-24 12:23:43 +00:00
|
|
|
if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category and !isguest()) or $isteacher) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo $string->email .': <a href="mailto:'. $user->email .'">'. $user->email .'</a><br />';
|
2004-01-10 16:41:29 +00:00
|
|
|
}
|
|
|
|
if ($user->city or $user->country) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo $string->location .': ';
|
2004-07-29 14:54:25 +00:00
|
|
|
if ($user->city) {
|
|
|
|
echo $user->city;
|
|
|
|
}
|
|
|
|
if (!empty($countries[$user->country])) {
|
|
|
|
if ($user->city) {
|
|
|
|
echo ', ';
|
|
|
|
}
|
|
|
|
echo $countries[$user->country];
|
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<br />';
|
2004-01-10 16:41:29 +00:00
|
|
|
}
|
|
|
|
if ($user->lastaccess) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo $string->lastaccess .': '. userdate($user->lastaccess);
|
|
|
|
echo '  ('. format_time(time() - $user->lastaccess, $datestring) .')';
|
2004-01-10 16:41:29 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo $string->lastaccess .': '. $string->never;
|
2004-01-10 16:41:29 +00:00
|
|
|
}
|
|
|
|
echo '</td><td valign="bottom" bgcolor="#ffffff" nowrap="nowrap" class="userinfoboxlinkcontent">';
|
|
|
|
|
|
|
|
echo '<font size="1">';
|
|
|
|
if ($isteacher) {
|
|
|
|
$timemidnight = usergetmidnight(time());
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<a href="'. $CFG->wwwroot .'/course/user.php?id='. $course->id .'&user='. $user->id .'">'. $string->activity .'</a><br />';
|
2004-09-06 14:03:17 +00:00
|
|
|
if (!iscreator($user->id) or ($isadmin and !isadmin($user->id))) { // Includes admins
|
2004-07-31 13:02:06 +00:00
|
|
|
if ($course->category and isteacheredit($course->id) and isstudent($course->id, $user->id)) { // Includes admins
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<a href="'. $CFG->wwwroot .'/course/unenrol.php?id='. $course->id .'&user='. $user->id .'">'. $string->unenrol .'</a><br />';
|
2004-03-13 14:34:32 +00:00
|
|
|
}
|
|
|
|
if ($USER->id != $user->id) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<a href="'. $CFG->wwwroot .'/course/loginas.php?id='. $course->id .'&user='. $user->id .'">'. $string->loginas .'</a><br />';
|
2004-03-13 14:34:32 +00:00
|
|
|
}
|
2004-01-10 16:41:29 +00:00
|
|
|
}
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<a href="'. $CFG->wwwroot .'/user/view.php?id='. $user->id .'&course='. $course->id .'">'. $string->fullprofile .'...</a>';
|
2004-01-10 16:41:29 +00:00
|
|
|
echo '</font>';
|
|
|
|
|
|
|
|
echo '</td></tr></table>';
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print a specified group's avatar.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param group $group A {@link group} object representing a group
|
|
|
|
* @param int $courseid ?
|
|
|
|
* @param boolean $large ?
|
|
|
|
* @param boolean $returnstring ?
|
|
|
|
* @param boolean $link ?
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2003-12-31 13:39:08 +00:00
|
|
|
function print_group_picture($group, $courseid, $large=false, $returnstring=false, $link=true) {
|
2003-12-30 17:18:06 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2004-02-15 07:37:48 +00:00
|
|
|
static $isteacheredit;
|
|
|
|
|
|
|
|
if (!isset($isteacheredit)) {
|
|
|
|
$isteacheredit = isteacheredit($courseid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($group->hidepicture and !$isteacheredit) {
|
2004-02-15 07:29:55 +00:00
|
|
|
return '';
|
|
|
|
}
|
2004-02-15 07:13:08 +00:00
|
|
|
|
2004-02-15 07:37:48 +00:00
|
|
|
if ($link or $isteacheredit) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$output = '<a href="'. $CFG->wwwroot .'/course/group.php?id='. $courseid .'&group='. $group->id .'">';
|
2004-02-15 07:29:55 +00:00
|
|
|
} else {
|
|
|
|
$output = '';
|
|
|
|
}
|
|
|
|
if ($large) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$file = 'f1';
|
2004-02-15 07:29:55 +00:00
|
|
|
$size = 100;
|
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$file = 'f2';
|
2004-02-15 07:29:55 +00:00
|
|
|
$size = 35;
|
|
|
|
}
|
|
|
|
if ($group->picture) { // Print custom group picture
|
|
|
|
if ($CFG->slasharguments) { // Use this method if possible for better caching
|
2004-09-16 17:13:57 +00:00
|
|
|
$output .= "<img align=\"middle\" src=\"$CFG->wwwroot/user/pixgroup.php/$group->id/$file.jpg\"".
|
2004-02-15 07:37:48 +00:00
|
|
|
" border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" title=\"$group->name\"/>";
|
2003-12-31 13:39:08 +00:00
|
|
|
} else {
|
2004-09-16 17:13:57 +00:00
|
|
|
$output .= "<img align=\"middle\" src=\"$CFG->wwwroot/user/pixgroup.php?file=/$group->id/$file.jpg\"".
|
2004-02-15 07:37:48 +00:00
|
|
|
" border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" title=\"$group->name\"/>";
|
2003-12-31 13:39:08 +00:00
|
|
|
}
|
2003-12-30 17:18:06 +00:00
|
|
|
}
|
2004-02-15 07:37:48 +00:00
|
|
|
if ($link or $isteacheredit) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= '</a>';
|
2004-02-15 07:29:55 +00:00
|
|
|
}
|
2003-12-30 17:18:06 +00:00
|
|
|
|
|
|
|
if ($returnstring) {
|
|
|
|
return $output;
|
|
|
|
} else {
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print a png image.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $url ?
|
|
|
|
* @param int $sizex ?
|
|
|
|
* @param int $sizey ?
|
|
|
|
* @param boolean $returnstring ?
|
|
|
|
* @param string $parameters ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-02-10 14:22:20 +00:00
|
|
|
function print_png($url, $sizex, $sizey, $returnstring, $parameters='alt=""') {
|
|
|
|
global $CFG;
|
|
|
|
static $recentIE;
|
|
|
|
|
|
|
|
if (!isset($recentIE)) {
|
|
|
|
$recentIE = check_browser_version('MSIE', '5.0');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($recentIE) { // work around the HORRIBLE bug IE has with alpha transparencies
|
2004-09-25 05:29:21 +00:00
|
|
|
$output .= '<img src="'. $CFG->pixpath .'/spacer.gif" width="'. $sizex .'" height="'. $sizey .'"'.
|
|
|
|
' border="0" style="width: '. $sizex .'px; height: '. $sizey .'px; '.
|
|
|
|
' filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='.
|
|
|
|
"'$url', sizingMethod='scale') ".
|
|
|
|
' '. $parameters .' />';
|
2004-02-10 14:22:20 +00:00
|
|
|
} else {
|
2004-09-25 05:29:21 +00:00
|
|
|
$output .= '<img src="'. $url .'" border="0" width="'. $sizex .'" height="'. $sizey .'" '.
|
|
|
|
' '. $parameters .' />';
|
2004-02-10 14:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($returnstring) {
|
|
|
|
return $output;
|
|
|
|
} else {
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print a nicely formatted table.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $THEME
|
|
|
|
* @param array $table is an object with several properties.
|
|
|
|
* <ul<li>$table->head - An array of heading names.
|
|
|
|
* <li>$table->align - An array of column alignments
|
|
|
|
* <li>$table->size - An array of column sizes
|
|
|
|
* <li>$table->wrap - An array of "nowrap"s or nothing
|
|
|
|
* <li>$table->data[] - An array of arrays containing the data.
|
|
|
|
* <li>$table->width - A percentage of the page
|
|
|
|
* <li>$table->cellpadding - Padding on each cell
|
|
|
|
* <li>$table->cellspacing - Spacing between cells
|
|
|
|
* </ul>
|
|
|
|
* @return boolean
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2002-12-20 14:44:14 +00:00
|
|
|
function print_table($table) {
|
|
|
|
|
2004-01-26 09:48:00 +00:00
|
|
|
global $THEME;
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if (isset($table->align)) {
|
|
|
|
foreach ($table->align as $key => $aa) {
|
|
|
|
if ($aa) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$align[$key] = ' align="'. $aa .'"';
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$align[$key] = '';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($table->size)) {
|
|
|
|
foreach ($table->size as $key => $ss) {
|
|
|
|
if ($ss) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$size[$key] = ' width="'. $ss .'"';
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$size[$key] = '';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-05-09 17:24:17 +00:00
|
|
|
if (isset($table->wrap)) {
|
|
|
|
foreach ($table->wrap as $key => $ww) {
|
|
|
|
if ($ww) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$wrap[$key] = ' nowrap="nowrap" ';
|
2003-05-09 17:24:17 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$wrap[$key] = '';
|
2003-05-09 17:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2002-12-29 04:17:32 +00:00
|
|
|
if (empty($table->width)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$table->width = '80%';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2002-12-29 04:17:32 +00:00
|
|
|
if (empty($table->cellpadding)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$table->cellpadding = '5';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2002-12-29 04:17:32 +00:00
|
|
|
if (empty($table->cellspacing)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$table->cellspacing = '1';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
print_simple_box_start('center', $table->width, '#ffffff', 0);
|
|
|
|
echo '<table width="100%" border="0" align="center" ';
|
2002-12-20 14:44:14 +00:00
|
|
|
echo " cellpadding=\"$table->cellpadding\" cellspacing=\"$table->cellspacing\" class=\"generaltable\">\n";
|
|
|
|
|
2004-01-26 09:48:00 +00:00
|
|
|
$countcols = 0;
|
|
|
|
|
2003-01-01 15:13:21 +00:00
|
|
|
if (!empty($table->head)) {
|
2004-01-26 09:48:00 +00:00
|
|
|
$countcols = count($table->head);;
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<tr>';
|
2002-12-20 14:44:14 +00:00
|
|
|
foreach ($table->head as $key => $heading) {
|
2004-05-21 13:07:11 +00:00
|
|
|
|
2002-12-29 04:17:32 +00:00
|
|
|
if (!isset($size[$key])) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$size[$key] = '';
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2002-12-29 04:17:32 +00:00
|
|
|
if (!isset($align[$key])) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$align[$key] = '';
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<th valign="top" '. $align[$key].$size[$key] .' nowrap="nowrap" class="generaltableheader">'. $heading .'</th>';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +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) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<tr valign="top">';
|
|
|
|
if ($row == 'hr' and $countcols) {
|
|
|
|
echo '<td colspan="'. $countcols .'"><div class="tabledivider"></div></td>';
|
2004-01-26 09:48:00 +00:00
|
|
|
} else { /// it's a normal row of data
|
|
|
|
foreach ($row as $key => $item) {
|
|
|
|
if (!isset($size[$key])) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$size[$key] = '';
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2004-01-26 09:48:00 +00:00
|
|
|
if (!isset($align[$key])) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$align[$key] = '';
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2004-01-26 09:48:00 +00:00
|
|
|
if (!isset($wrap[$key])) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$wrap[$key] = '';
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<td '. $align[$key].$size[$key].$wrap[$key] .' class="generaltablecell">'. $item .'</td>';
|
2004-01-26 09:48:00 +00:00
|
|
|
}
|
2003-09-23 12:18:27 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '</tr>'."\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '</table>'."\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Creates a nicely formatted table and returns it.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param array $table is an object with several properties.
|
|
|
|
* <ul<li>$table->head - An array of heading names.
|
|
|
|
* <li>$table->align - An array of column alignments
|
|
|
|
* <li>$table->size - An array of column sizes
|
|
|
|
* <li>$table->wrap - An array of "nowrap"s or nothing
|
|
|
|
* <li>$table->data[] - An array of arrays containing the data.
|
|
|
|
* <li>$table->class - A css class name
|
|
|
|
* <li>$table->fontsize - Is the size of all the text
|
|
|
|
* <li>$table->tablealign - Align the whole table
|
|
|
|
* <li>$table->width - A percentage of the page
|
|
|
|
* <li>$table->cellpadding - Padding on each cell
|
|
|
|
* <li>$table->cellspacing - Spacing between cells
|
|
|
|
* </ul>
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2003-08-18 16:40:27 +00:00
|
|
|
function make_table($table) {
|
|
|
|
|
|
|
|
if (isset($table->align)) {
|
|
|
|
foreach ($table->align as $key => $aa) {
|
|
|
|
if ($aa) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$align[$key] = ' align="'. $aa .'"';
|
2003-08-18 16:40:27 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$align[$key] = '';
|
2003-08-18 16:40:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($table->size)) {
|
|
|
|
foreach ($table->size as $key => $ss) {
|
|
|
|
if ($ss) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$size[$key] = ' width="'. $ss .'"';
|
2003-08-18 16:40:27 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$size[$key] = '';
|
2003-08-18 16:40:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($table->wrap)) {
|
|
|
|
foreach ($table->wrap as $key => $ww) {
|
|
|
|
if ($ww) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$wrap[$key] = ' nowrap="nowrap" ';
|
2003-08-18 16:40:27 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$wrap[$key] = '';
|
2003-08-18 16:40:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($table->width)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$table->width = '80%';
|
2003-08-18 16:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($table->tablealign)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$table->tablealign = 'center';
|
2003-08-18 16:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($table->cellpadding)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$table->cellpadding = '5';
|
2003-08-18 16:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($table->cellspacing)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$table->cellspacing = '1';
|
2003-08-18 16:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($table->class)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$table->class = 'generaltable';
|
2003-08-18 16:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($table->fontsize)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$fontsize = '';
|
2003-08-18 16:40:27 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$fontsize = '<font size="'. $table->fontsize .'">';
|
2003-08-18 16:40:27 +00:00
|
|
|
}
|
|
|
|
|
2005-01-13 07:55:24 +00:00
|
|
|
$output = '<table width="'. $table->width .'" align="'. $table->tablealign .'" ';
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= ' cellpadding="'. $table->cellpadding .'" cellspacing="'. $table->cellspacing .'" class="'. $table->class .'">'."\n";
|
2003-08-18 16:40:27 +00:00
|
|
|
|
|
|
|
if (!empty($table->head)) {
|
2005-01-13 07:55:24 +00:00
|
|
|
$output .= '<tr valign="top">';
|
2003-08-18 16:40:27 +00:00
|
|
|
foreach ($table->head as $key => $heading) {
|
|
|
|
if (!isset($size[$key])) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$size[$key] = '';
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2003-08-18 16:40:27 +00:00
|
|
|
if (!isset($align[$key])) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$align[$key] = '';
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +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
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= '</tr>'."\n";
|
2003-08-18 16:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($table->data as $row) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= '<tr valign="top">';
|
2003-08-18 16:40:27 +00:00
|
|
|
foreach ($row as $key => $item) {
|
|
|
|
if (!isset($size[$key])) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$size[$key] = '';
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2003-08-18 16:40:27 +00:00
|
|
|
if (!isset($align[$key])) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$align[$key] = '';
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2003-08-18 16:40:27 +00:00
|
|
|
if (!isset($wrap[$key])) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$wrap[$key] = '';
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= '<td '. $align[$key].$size[$key].$wrap[$key] .' class="'. $table->class .'cell">'. $fontsize . $item .'</td>';
|
2003-08-18 16:40:27 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= '</tr>'."\n";
|
2003-08-18 16:40:27 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
$output .= '</table>'."\n";
|
2003-08-18 16:40:27 +00:00
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints a basic textarea field.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @param boolean $usehtmleditor ?
|
|
|
|
* @param int $rows ?
|
|
|
|
* @param int $cols ?
|
|
|
|
* @param null $width <b>Legacy field no longer used!</b>
|
|
|
|
* @param null $height <b>Legacy field no longer used!</b>
|
|
|
|
* @param string $name ?
|
|
|
|
* @param string $value ?
|
|
|
|
* @param int $courseid ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $courseid=0) {
|
2003-11-03 15:17:21 +00:00
|
|
|
/// $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)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/htmlarea.php?id='. $courseid .'"></script>'."\n";
|
2003-11-03 15:17:21 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/htmlarea.php"></script>'."\n";
|
2003-11-03 15:17:21 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
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
|
|
|
|
2004-04-28 02:57:37 +00:00
|
|
|
if ($rows < 10) {
|
|
|
|
$rows = 10;
|
2003-11-03 15:17:21 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2004-09-25 05:29:21 +00:00
|
|
|
echo '<textarea id="'. $name .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">';
|
2003-11-03 15:17:21 +00:00
|
|
|
p($value);
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '</textarea>'."\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Legacy function, provided for backward compatability.
|
|
|
|
* This method now simply calls {@link use_html_editor()}
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @deprecated Use {@link use_html_editor()} instead.
|
|
|
|
* @param string $name Form element to replace with HTMl editor by name
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function print_richedit_javascript($form, $name, $source='no') {
|
2003-11-03 15:17:21 +00:00
|
|
|
use_html_editor($name);
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $name Form element to replace with HTMl editor by name
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function use_html_editor($name='') {
|
|
|
|
echo '<script language="javascript" type="text/javascript" defer="defer">'."\n";
|
2004-08-21 10:12:09 +00:00
|
|
|
print_editor_config();
|
2003-11-03 15:17:21 +00:00
|
|
|
if (empty($name)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo "\n".'HTMLArea.replaceAll(config);'."\n";
|
2003-11-03 15:17:21 +00:00
|
|
|
} else {
|
2004-08-21 10:12:09 +00:00
|
|
|
echo "\nHTMLArea.replace('$name', config);\n";
|
2003-10-29 08:06:11 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '</script>'."\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Returns a turn edit on/off button for course in a self contained form.
|
|
|
|
* Used to be an icon, but it's now a simple form button
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @uses $USER
|
|
|
|
* @param int $courseid The course to update by id as found in 'course' table
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2002-12-20 14:44:14 +00:00
|
|
|
function update_course_icon($courseid) {
|
2004-09-25 05:29:21 +00:00
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
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)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$string = get_string('turneditingoff');
|
|
|
|
$edit = 'off';
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$string = get_string('turneditingon');
|
|
|
|
$edit = 'on';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2003-12-14 15:03:23 +00:00
|
|
|
return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/view.php\">".
|
2003-09-21 15:45:24 +00:00
|
|
|
"<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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints the editing button on a module "view" page
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
|
|
|
* @param type description
|
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2002-12-20 14:44:14 +00:00
|
|
|
function update_module_button($moduleid, $courseid, $string) {
|
2004-10-12 18:47:39 +00:00
|
|
|
global $CFG, $USER;
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2003-08-16 06:44:03 +00:00
|
|
|
if (isteacheredit($courseid)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$string = get_string('updatethis', '', $string);
|
2003-12-14 15:03:23 +00:00
|
|
|
return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/mod.php\">".
|
2003-09-21 15:45:24 +00:00
|
|
|
"<input type=\"hidden\" name=\"update\" value=\"$moduleid\" />".
|
|
|
|
"<input type=\"hidden\" name=\"return\" value=\"true\" />".
|
2004-10-12 18:47:39 +00:00
|
|
|
"<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />".
|
2003-09-21 15:45:24 +00:00
|
|
|
"<input type=\"submit\" value=\"$string\" /></form>";
|
2003-08-16 06:44:03 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
return '';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints the editing button on a category page
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
|
|
|
* @uses $USER
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $categoryid ?
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2003-07-30 13:02:45 +00:00
|
|
|
function update_category_button($categoryid) {
|
2003-08-07 16:01:31 +00:00
|
|
|
global $CFG, $USER;
|
2003-07-30 13:02:45 +00:00
|
|
|
|
2003-08-07 16:01:31 +00:00
|
|
|
if (iscreator()) {
|
2003-12-30 17:18:06 +00:00
|
|
|
if (!empty($USER->categoryediting)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$string = get_string('turneditingoff');
|
|
|
|
$edit = 'off';
|
2003-08-07 16:01:31 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$string = get_string('turneditingon');
|
|
|
|
$edit = 'on';
|
2004-05-21 13:07:11 +00:00
|
|
|
}
|
2003-12-14 15:03:23 +00:00
|
|
|
return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/category.php\">".
|
2003-09-21 15:45:24 +00:00
|
|
|
"<input type=\"hidden\" name=\"id\" value=\"$categoryid\" />".
|
|
|
|
"<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
|
2004-10-08 16:52:20 +00:00
|
|
|
"<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />".
|
2003-09-21 15:45:24 +00:00
|
|
|
"<input type=\"submit\" value=\"$string\" /></form>";
|
2003-08-07 16:01:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints the editing button on categories listing
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @uses $USER
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2003-08-07 16:01:31 +00:00
|
|
|
function update_categories_button() {
|
|
|
|
global $CFG, $USER;
|
|
|
|
|
|
|
|
if (isadmin()) {
|
2003-12-30 17:18:06 +00:00
|
|
|
if (!empty($USER->categoriesediting)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$string = get_string('turneditingoff');
|
|
|
|
$edit = 'off';
|
2003-08-07 16:01:31 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$string = get_string('turneditingon');
|
|
|
|
$edit = 'on';
|
2003-08-07 16:01:31 +00:00
|
|
|
}
|
2003-12-14 15:03:23 +00:00
|
|
|
return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/index.php\">".
|
2004-09-25 05:29:21 +00:00
|
|
|
'<input type="hidden" name="edit" value="'. $edit .'" />'.
|
2004-10-09 13:22:59 +00:00
|
|
|
'<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />'.
|
2004-09-25 05:29:21 +00:00
|
|
|
'<input type="submit" value="'. $string .'" /></form>';
|
2003-07-30 13:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints the editing button on group page
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @uses $USER
|
|
|
|
* @param int $courseid The course group is associated with
|
|
|
|
* @param int $groupid The group to update
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-02-09 07:31:04 +00:00
|
|
|
function update_group_button($courseid, $groupid) {
|
2003-12-30 17:18:06 +00:00
|
|
|
global $CFG, $USER;
|
|
|
|
|
|
|
|
if (isteacheredit($courseid)) {
|
2004-02-09 07:31:04 +00:00
|
|
|
$string = get_string('editgroupprofile');
|
2003-12-30 17:18:06 +00:00
|
|
|
return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/group.php\">".
|
2004-09-25 05:29:21 +00:00
|
|
|
'<input type="hidden" name="id" value="'. $courseid .'" />'.
|
|
|
|
'<input type="hidden" name="group" value="'. $groupid .'" />'.
|
|
|
|
'<input type="hidden" name="edit" value="on" />'.
|
|
|
|
'<input type="submit" value="'. $string .'" /></form>';
|
2003-12-30 17:18:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints the editing button on groups page
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @uses $USER
|
|
|
|
* @param int $courseid The id of the course to be edited
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2003-12-30 17:18:06 +00:00
|
|
|
function update_groups_button($courseid) {
|
|
|
|
global $CFG, $USER;
|
|
|
|
|
|
|
|
if (isteacheredit($courseid)) {
|
|
|
|
if (!empty($USER->groupsediting)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$string = get_string('turneditingoff');
|
|
|
|
$edit = 'off';
|
2003-12-30 17:18:06 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$string = get_string('turneditingon');
|
|
|
|
$edit = 'on';
|
2003-12-30 17:18:06 +00:00
|
|
|
}
|
|
|
|
return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/groups.php\">".
|
|
|
|
"<input type=\"hidden\" name=\"id\" value=\"$courseid\" />".
|
|
|
|
"<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
|
|
|
|
"<input type=\"submit\" value=\"$string\" /></form>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints an appropriate group selection menu
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses VISIBLEGROUPS
|
|
|
|
* @param array $groups ?
|
|
|
|
* @param int $groupmode ?
|
|
|
|
* @param string $currentgroup ?
|
|
|
|
* @param string $urlroot ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-02-15 07:13:08 +00:00
|
|
|
function print_group_menu($groups, $groupmode, $currentgroup, $urlroot) {
|
|
|
|
|
2004-02-19 17:56:05 +00:00
|
|
|
/// Add an "All groups" to the start of the menu
|
2004-09-22 14:39:15 +00:00
|
|
|
$groupsmenu[0] = get_string('allparticipants');
|
2004-02-19 17:56:05 +00:00
|
|
|
foreach ($groups as $key => $groupname) {
|
|
|
|
$groupsmenu[$key] = $groupname;
|
|
|
|
}
|
|
|
|
|
2004-02-24 06:43:13 +00:00
|
|
|
echo '<table><tr><td align="right">';
|
2004-02-15 07:13:08 +00:00
|
|
|
if ($groupmode == VISIBLEGROUPS) {
|
|
|
|
print_string('groupsvisible');
|
|
|
|
} else {
|
|
|
|
print_string('groupsseparate');
|
|
|
|
}
|
|
|
|
echo ':';
|
2004-02-24 06:43:13 +00:00
|
|
|
echo '</td><td nowrap="nowrap" align="left">';
|
2004-09-22 14:39:15 +00:00
|
|
|
popup_form($urlroot.'&group=', $groupsmenu, 'selectgroup', $currentgroup, '', '', '', false, 'self');
|
2004-02-15 07:13:08 +00:00
|
|
|
echo '</tr></table>';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +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
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param course $course A {@link $COURSE} object.
|
|
|
|
* @param course $cm A {@link $COURSE} object.
|
|
|
|
* @param string $targetwindow ?
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function navmenu($course, $cm=NULL, $targetwindow='self') {
|
2002-12-20 14:44:14 +00:00
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($cm) {
|
2003-11-25 04:19:58 +00:00
|
|
|
$cm = $cm->id;
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($course->format == 'weeks') {
|
2004-09-22 14:39:15 +00:00
|
|
|
$strsection = get_string('week');
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$strsection = get_string('topic');
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$modinfo = unserialize($course->modinfo)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
return '';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2003-11-25 04:19:58 +00:00
|
|
|
$isteacher = isteacher($course->id);
|
2002-12-20 14:44:14 +00:00
|
|
|
$section = -1;
|
2004-09-22 14:39:15 +00:00
|
|
|
$selected = '';
|
|
|
|
$url = '';
|
2003-11-25 04:19:58 +00:00
|
|
|
$previousmod = NULL;
|
|
|
|
$backmod = NULL;
|
|
|
|
$nextmod = NULL;
|
2004-02-16 00:41:52 +00:00
|
|
|
$selectmod = NULL;
|
2004-01-15 07:17:47 +00:00
|
|
|
$logslink = NULL;
|
2003-11-25 04:19:58 +00:00
|
|
|
$flag = false;
|
2004-06-09 08:36:28 +00:00
|
|
|
$menu = array();
|
2004-06-09 08:55:44 +00:00
|
|
|
$strjumpto = get_string('jumpto');
|
2003-11-25 04:19:58 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
$sections = get_records('course_sections','course',$course->id,'section','section,visible,summary');
|
2004-04-27 16:29:21 +00:00
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
foreach ($modinfo as $mod) {
|
2004-09-22 14:39:15 +00:00
|
|
|
if ($mod->mod == 'label') {
|
2003-09-15 11:59:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-04-27 16:29:21 +00:00
|
|
|
|
2004-11-21 06:28:17 +00:00
|
|
|
if ($mod->section > $course->numsections) { /// Don't show excess hidden sections
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($mod->section > 0 and $section <> $mod->section) {
|
2004-07-21 06:06:10 +00:00
|
|
|
$thissection = $sections[$mod->section];
|
|
|
|
|
|
|
|
if ($thissection->visible or !$course->hiddensections or $isteacher) {
|
|
|
|
$thissection->summary = strip_tags($thissection->summary);
|
|
|
|
if ($course->format == 'weeks' or empty($thissection->summary)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$menu[] = '-------------- '. $strsection ." ". $mod->section .' --------------';
|
2004-07-21 06:06:10 +00:00
|
|
|
} else {
|
|
|
|
if (strlen($thissection->summary) < 47) {
|
|
|
|
$menu[] = '-- '.$thissection->summary;
|
|
|
|
} else {
|
|
|
|
$menu[] = '-- '.substr($thissection->summary, 0, 50).'...';
|
|
|
|
}
|
|
|
|
}
|
2004-04-27 16:29:21 +00:00
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2004-04-27 16:29:21 +00:00
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
$section = $mod->section;
|
2004-04-27 16:29:21 +00:00
|
|
|
|
2003-04-23 16:32:11 +00:00
|
|
|
//Only add visible or teacher mods to jumpmenu
|
2003-11-25 04:19:58 +00:00
|
|
|
if ($mod->visible or $isteacher) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$url = $mod->mod .'/view.php?id='. $mod->cm;
|
2003-11-25 04:19:58 +00:00
|
|
|
if ($flag) { // the current mod is the "next" mod
|
|
|
|
$nextmod = $mod;
|
|
|
|
$flag = false;
|
|
|
|
}
|
2003-04-23 16:32:11 +00:00
|
|
|
if ($cm == $mod->cm) {
|
|
|
|
$selected = $url;
|
2004-01-15 07:17:47 +00:00
|
|
|
$selectmod = $mod;
|
2003-11-25 04:19:58 +00:00
|
|
|
$backmod = $previousmod;
|
|
|
|
$flag = true; // set flag so we know to use next mod for "next"
|
2004-06-21 13:07:44 +00:00
|
|
|
$mod->name = $strjumpto;
|
2004-06-09 08:55:44 +00:00
|
|
|
$strjumpto = '';
|
2004-06-09 08:46:43 +00:00
|
|
|
} else {
|
|
|
|
$mod->name = strip_tags(urldecode($mod->name));
|
|
|
|
if (strlen($mod->name) > 55) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$mod->name = substr($mod->name, 0, 50).'...';
|
2004-06-09 08:46:43 +00:00
|
|
|
}
|
|
|
|
if (!$mod->visible) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$mod->name = '('.$mod->name.')';
|
2004-06-09 08:46:43 +00:00
|
|
|
}
|
2003-04-23 17:25:20 +00:00
|
|
|
}
|
2003-11-25 04:19:58 +00:00
|
|
|
$menu[$url] = $mod->name;
|
2003-11-29 02:27:04 +00:00
|
|
|
$previousmod = $mod;
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2003-11-25 04:19:58 +00:00
|
|
|
}
|
2004-01-31 14:47:57 +00:00
|
|
|
if ($selectmod and $isteacher) {
|
2004-02-03 10:21:20 +00:00
|
|
|
$logslink = "<td><a target=\"$CFG->framename\" href=".
|
2004-09-16 17:13:57 +00:00
|
|
|
"\"$CFG->wwwroot/course/log.php?chooselog=1&user=0&date=0&id=$course->id&modid=$selectmod->cm\">".
|
|
|
|
"<img border=\"0\" height=\"16\" width=\"16\" src=\"$CFG->pixpath/i/log.gif\" alt=\"\" /></a></td>";
|
2004-05-21 13:07:11 +00:00
|
|
|
|
2004-01-15 07:17:47 +00:00
|
|
|
}
|
2003-11-25 04:19:58 +00:00
|
|
|
if ($backmod) {
|
|
|
|
$backmod = "<form action=\"$CFG->wwwroot/mod/$backmod->mod/view.php\" target=\"$CFG->framename\">".
|
2004-09-16 18:23:38 +00:00
|
|
|
"<input type=\"hidden\" name=\"id\" value=\"$backmod->cm\" />".
|
|
|
|
"<input type=\"submit\" value=\"<\" /></form>";
|
2003-11-25 04:19:58 +00:00
|
|
|
}
|
|
|
|
if ($nextmod) {
|
|
|
|
$nextmod = "<form action=\"$CFG->wwwroot/mod/$nextmod->mod/view.php\" target=\"$CFG->framename\">".
|
2004-09-16 18:23:38 +00:00
|
|
|
"<input type=\"hidden\" name=\"id\" value=\"$nextmod->cm\" />".
|
|
|
|
"<input type=\"submit\" value=\">\" /></form>";
|
2003-11-25 04:19:58 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
return '<table><tr>'.$logslink .'<td>'. $backmod .'</td><td>' .
|
|
|
|
popup_form($CFG->wwwroot .'/mod/', $menu, 'navmenu', $selected, $strjumpto,
|
|
|
|
'', '', true, $targetwindow).
|
|
|
|
'</td><td>'. $nextmod .'</td></tr></table>';
|
2003-11-25 04:19:58 +00:00
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints form items with the names $day, $month and $year
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $day ?
|
|
|
|
* @param int $month ?
|
|
|
|
* @param int $year ?
|
|
|
|
* @param int $currenttime A default timestamp in GMT
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2002-12-20 14:44:14 +00:00
|
|
|
function print_date_selector($day, $month, $year, $currenttime=0) {
|
|
|
|
|
|
|
|
if (!$currenttime) {
|
|
|
|
$currenttime = time();
|
|
|
|
}
|
|
|
|
$currentdate = usergetdate($currenttime);
|
|
|
|
|
|
|
|
for ($i=1; $i<=31; $i++) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$days[$i] = $i;
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2004-09-22 14:39:15 +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
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
*Prints form items with the names $hour and $minute
|
|
|
|
*
|
|
|
|
* @param ? $hour ?
|
|
|
|
* @param ? $minute ?
|
|
|
|
* @param $currenttime A default timestamp in GMT
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $step ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2003-12-08 17:20:31 +00:00
|
|
|
function print_time_selector($hour, $minute, $currenttime=0, $step=5) {
|
2002-12-20 14:44:14 +00:00
|
|
|
|
|
|
|
if (!$currenttime) {
|
|
|
|
$currenttime = time();
|
|
|
|
}
|
|
|
|
$currentdate = usergetdate($currenttime);
|
2003-12-08 17:20:31 +00:00
|
|
|
if ($step != 1) {
|
|
|
|
$currentdate['minutes'] = ceil($currentdate['minutes']/$step)*$step;
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
for ($i=0; $i<=23; $i++) {
|
|
|
|
$hours[$i] = sprintf("%02d",$i);
|
|
|
|
}
|
2003-12-08 17:20:31 +00:00
|
|
|
for ($i=0; $i<=59; $i+=$step) {
|
2002-12-20 14:44:14 +00:00
|
|
|
$minutes[$i] = sprintf("%02d",$i);
|
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
choose_from_menu($hours, $hour, $currentdate['hours'], '');
|
|
|
|
choose_from_menu($minutes, $minute, $currentdate['minutes'], '');
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints time limit value selector
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $timelimit ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @param string $unit ?
|
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-12-23 07:09:33 +00:00
|
|
|
function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit') {
|
2004-06-02 18:00:12 +00:00
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
2004-06-21 13:07:44 +00:00
|
|
|
if ($unit) {
|
|
|
|
$unit = ' '.$unit;
|
|
|
|
}
|
|
|
|
|
2004-06-02 18:00:12 +00:00
|
|
|
// Max timelimit is sessiontimeout - 10 minutes.
|
|
|
|
$maxvalue = ($CFG->sessiontimeout / 60) - 10;
|
|
|
|
|
2004-06-21 13:07:44 +00:00
|
|
|
for ($i=1; $i<=$maxvalue; $i++) {
|
|
|
|
$minutes[$i] = $i.$unit;
|
2004-06-02 18:00:12 +00:00
|
|
|
}
|
2004-12-23 07:09:33 +00:00
|
|
|
choose_from_menu($minutes, $name, $timelimit, get_string('none'));
|
2004-06-02 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints a grade menu (as part of an existing form) with help
|
|
|
|
* Showing all possible numerical grades and scales
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @param int $courseid ?
|
|
|
|
* @param string $name ?
|
|
|
|
* @param string $current ?
|
|
|
|
* @param boolean $includenograde ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
|
|
|
function print_grade_menu($courseid, $name, $current, $includenograde=true) {
|
2003-08-18 05:28:30 +00:00
|
|
|
|
2003-09-14 12:25:16 +00:00
|
|
|
global $CFG;
|
2003-08-18 05:28:30 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
$strscale = get_string('scale');
|
|
|
|
$strscales = get_string('scales');
|
2003-08-18 05:28:30 +00:00
|
|
|
|
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) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$grades[-$i] = $strscale .': '. $scalename;
|
2003-08-18 05:28:30 +00:00
|
|
|
}
|
2003-08-25 12:47:36 +00:00
|
|
|
if ($includenograde) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$grades[0] = get_string('nograde');
|
2003-08-25 12:47:36 +00:00
|
|
|
}
|
2003-08-18 05:28:30 +00:00
|
|
|
for ($i=100; $i>=1; $i--) {
|
|
|
|
$grades[$i] = $i;
|
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
choose_from_menu($grades, $name, $current, '');
|
2003-08-18 05:28:30 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
$helpicon = $CFG->pixpath .'/help.gif';
|
2004-09-16 17:13:57 +00:00
|
|
|
$linkobject = "<img align=\"middle\" border=\"0\" height=\"17\" width=\"22\" alt=\"$strscales\" src=\"$helpicon\" />";
|
2004-09-22 14:39:15 +00:00
|
|
|
link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true', 'ratingscales',
|
2003-08-18 05:28:30 +00:00
|
|
|
$linkobject, 400, 500, $strscales);
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints a scale menu (as part of an existing form) including help button
|
2004-09-25 05:29:21 +00:00
|
|
|
* Just like {@link print_grade_menu()} but without the numeric grades
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $courseid ?
|
|
|
|
* @param string $name ?
|
|
|
|
* @param string $current ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2003-08-15 13:59:24 +00:00
|
|
|
function print_scale_menu($courseid, $name, $current) {
|
|
|
|
|
2003-09-14 12:25:16 +00:00
|
|
|
global $CFG;
|
2003-08-15 13:59:24 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
$strscales = get_string('scales');
|
|
|
|
choose_from_menu(get_scales_menu($courseid), $name, $current, '');
|
|
|
|
$helpicon = $CFG->pixpath .'/help.gif';
|
2004-09-25 05:29:21 +00:00
|
|
|
$linkobject = '<img align="middle" border="0" height="17" width="22" alt="'. $strscales .'" src="'. $helpicon .'" />';
|
2004-09-22 14:39:15 +00:00
|
|
|
link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true', 'ratingscales',
|
2003-08-15 13:59:24 +00:00
|
|
|
$linkobject, 400, 500, $strscales);
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints a help button about a scale
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
|
|
|
* @param id $courseid ?
|
|
|
|
* @param object $scale ?
|
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2003-08-15 13:59:24 +00:00
|
|
|
function print_scale_menu_helpbutton($courseid, $scale) {
|
|
|
|
|
2003-09-14 12:25:16 +00:00
|
|
|
global $CFG;
|
2003-08-15 13:59:24 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
$strscales = get_string('scales');
|
|
|
|
$helpicon = $CFG->pixpath .'/help.gif';
|
2004-09-16 17:13:57 +00:00
|
|
|
$linkobject = "<img align=\"middle\" border=\"0\" height=\"17\" width=\"22\" alt=\"$scale->name\" src=\"$helpicon\" />";
|
2004-09-22 14:39:15 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print an error page displaying an error message.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $SESSION
|
|
|
|
* @uses $CFG
|
2004-09-23 04:36:43 +00:00
|
|
|
* @param string $message The message to display to the user about the error.
|
|
|
|
* @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function error ($message, $link='') {
|
2002-12-20 14:44:14 +00:00
|
|
|
global $CFG, $SESSION;
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
print_header(get_string('error'));
|
|
|
|
echo '<br />';
|
2004-10-01 02:25:02 +00:00
|
|
|
|
|
|
|
$message = clean_text($message); // In case nasties are in here
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
print_simple_box($message, 'center', '', '#FFBBBB');
|
2004-05-21 13:07:11 +00:00
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if (!$link) {
|
|
|
|
if ( !empty($SESSION->fromurl) ) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$link = $SESSION->fromurl;
|
2002-12-20 14:44:14 +00:00
|
|
|
unset($SESSION->fromurl);
|
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$link = $CFG->wwwroot .'/';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
print_continue($link);
|
|
|
|
print_footer();
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print a help button.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @uses $THEME
|
|
|
|
* @param string $page The keyword that defines a help page
|
|
|
|
* @param string $title The title of links, rollover tips, alt tags etc
|
|
|
|
* @param string $module Which module is the page defined in
|
|
|
|
* @param mixed $image Use a help image for the link? (true/false/"both")
|
|
|
|
* @param string $text If defined then this text is used in the page, and
|
|
|
|
* the $page variable is ignored.
|
|
|
|
* @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function helpbutton ($page, $title='', $module='moodle', $image=true, $linktext=false, $text='', $return=false) {
|
2003-04-28 04:32:55 +00:00
|
|
|
global $CFG, $THEME;
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
if ($module == '') {
|
|
|
|
$module = 'moodle';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($image) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$icon = $CFG->pixpath .'/help.gif';
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($linktext) {
|
2005-01-21 02:37:02 +00:00
|
|
|
$linkobject = "<span class=\"formhelplinks\">$title<img align=\"middle\" border=\"0\" ".
|
2003-11-06 11:47:23 +00:00
|
|
|
" height=\"17\" width=\"22\" alt=\"\" src=\"$icon\" /></span>";
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-16 17:13:57 +00:00
|
|
|
$linkobject = "<img align=\"middle\" border=\"0\" height=\"17\" width=\"22\" ".
|
2003-11-06 11:47:23 +00:00
|
|
|
" alt=\"$title\" style=\"cursor:help;\" src=\"$icon\" />";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2005-01-21 02:37:02 +00:00
|
|
|
$linkobject = '<span class="formhelplinks">'. $title .'</span>';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
if ($text) {
|
2004-09-22 14:39:15 +00:00
|
|
|
$url = '/help.php?module='. $module .'&text='. htmlentities(urlencode($text));
|
2002-12-20 14:44:14 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$url = '/help.php?module='. $module .'&file='. $page .'.html';
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2004-08-02 19:09:06 +00:00
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
$link = link_to_popup_window ($url, 'popup', $linkobject, 400, 500, $title, 'none', true);
|
2004-08-02 19:09:06 +00:00
|
|
|
|
|
|
|
if ($return) {
|
|
|
|
return $link;
|
|
|
|
} else {
|
|
|
|
echo $link;
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print a help button.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* Prints a special help button that is a link to the "live" emoticon popup
|
|
|
|
* @uses $CFG
|
|
|
|
* @uses $SESSION
|
|
|
|
* @param string $form ?
|
|
|
|
* @param string $field ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2003-05-08 16:09:30 +00:00
|
|
|
function emoticonhelpbutton($form, $field) {
|
2004-09-25 05:29:21 +00:00
|
|
|
|
2003-05-08 16:09:30 +00:00
|
|
|
global $CFG, $SESSION;
|
|
|
|
|
|
|
|
$SESSION->inserttextform = $form;
|
|
|
|
$SESSION->inserttextfield = $field;
|
2004-09-22 14:39:15 +00:00
|
|
|
helpbutton('emoticons', get_string('helpemoticons'), 'moodle', false, true);
|
|
|
|
echo ' ';
|
|
|
|
link_to_popup_window ('/help.php?module=moodle&file=emoticons.html', 'popup',
|
2004-09-25 05:29:21 +00:00
|
|
|
'<img src="'. $CFG->pixpath .'/s/smiley.gif" border="0" align="middle" width="15" height="15" alt="" />',
|
2004-09-22 14:39:15 +00:00
|
|
|
400, 500, get_string('helpemoticons'));
|
|
|
|
echo '<br />';
|
2003-05-08 16:09:30 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print a message and exit.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @uses $THEME
|
|
|
|
* @param string $message ?
|
|
|
|
* @param string $link ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-09-22 14:39:15 +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
|
|
|
|
2004-10-01 02:43:09 +00:00
|
|
|
$message = clean_text($message);
|
|
|
|
$link = clean_text($link);
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if (!$link) {
|
2004-09-22 14:39:15 +00:00
|
|
|
if (!empty($_SERVER['HTTP_REFERER'])) {
|
|
|
|
$link = $_SERVER['HTTP_REFERER'];
|
2003-01-26 06:04:14 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
$link = $CFG->wwwroot .'/';
|
2003-01-26 06:04:14 +00:00
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<br />';
|
|
|
|
print_simple_box($message, 'center', '50%', $THEME->cellheading, '20', 'noticebox');
|
|
|
|
print_heading('<a href="'. $link .'">'. get_string('continue') .'</a>');
|
2002-12-20 14:44:14 +00:00
|
|
|
print_footer(get_site());
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print a message along with "Yes" and "No" links for the user to continue.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $THEME
|
|
|
|
* @param string $message The text to display
|
|
|
|
* @param string $linkyes The link to take the user to if they choose "Yes"
|
|
|
|
* @param string $linkno The link to take the user to if they choose "No"
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2002-12-20 14:44:14 +00:00
|
|
|
function notice_yesno ($message, $linkyes, $linkno) {
|
|
|
|
global $THEME;
|
|
|
|
|
2004-10-01 02:43:09 +00:00
|
|
|
$message = clean_text($message);
|
|
|
|
$linkyes = clean_text($linkyes);
|
|
|
|
$linkno = clean_text($linkno);
|
|
|
|
|
2004-09-22 14:39:15 +00:00
|
|
|
print_simple_box_start('center', '60%', $THEME->cellheading);
|
|
|
|
echo '<p align="center"><font size="3">'. $message .'</font></p>';
|
2004-09-23 04:36:43 +00:00
|
|
|
echo '<p align="center"><font size="3"><strong>';
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<a href="'. $linkyes .'">'. get_string('yes') .'</a>';
|
|
|
|
echo ' ';
|
|
|
|
echo '<a href="'. $linkno .'">'. get_string('no') .'</a>';
|
2004-09-23 04:36:43 +00:00
|
|
|
echo '</strong></font></p>';
|
2002-12-20 14:44:14 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Redirects the user to another page, after printing a notice
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $url The url to take the user to
|
|
|
|
* @param string $message The text message to display to the user about the redirect, if any
|
|
|
|
* @param string $delay How long before refreshing to the new page at $url?
|
|
|
|
* @todo '&' needs to be encoded into '&' for XHTML compliance,
|
|
|
|
* however, this is not true for javascript. Therefore we
|
|
|
|
* first decode all entities in $url (since we cannot rely on)
|
|
|
|
* the correct input) and then encode for where it's needed
|
|
|
|
* echo "<script type='text/javascript'>alert('Redirect $url');</script>";
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function redirect($url, $message='', $delay='0') {
|
2004-10-01 02:43:09 +00:00
|
|
|
|
|
|
|
$url = clean_text($url);
|
|
|
|
$message = clean_text($message);
|
|
|
|
|
2004-09-21 11:41:58 +00:00
|
|
|
$url = html_entity_decode($url); // for php < 4.3.0 this is defined in moodlelib.php
|
|
|
|
$encodedurl = htmlentities($url);
|
2004-10-01 02:43:09 +00:00
|
|
|
|
2003-03-12 07:44:29 +00:00
|
|
|
if (empty($message)) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<meta http-equiv="refresh" content="'. $delay .'; url='. $encodedurl .'" />';
|
2004-09-23 02:48:41 +00:00
|
|
|
echo '<script type="text/javascript">'. "\n" .'<!--'. "\n". "location.replace('$url');". "\n". '//-->'. "\n". '</script>'; // To cope with Mozilla bug
|
2003-03-12 07:44:29 +00:00
|
|
|
} else {
|
2004-05-21 13:07:11 +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
|
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
print_header('', '', '', '', '<meta http-equiv="refresh" content="'. $delay .'; url='. $encodedurl .'" />');
|
|
|
|
echo '<center>';
|
|
|
|
echo '<p>'. $message .'</p>';
|
|
|
|
echo '<p>( <a href="'. $encodedurl .'">'. get_string('continue') .'</a> )</p>';
|
|
|
|
echo '</center>';
|
2003-11-01 06:59:31 +00:00
|
|
|
flush();
|
|
|
|
sleep($delay);
|
2004-09-23 02:48:41 +00:00
|
|
|
echo '<script type="text/javascript">'."\n".'<!--'."\nlocation.replace('$url');\n".'//-->'."\n".'</script>'; // To cope with Mozilla bug
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2004-05-21 13:07:11 +00:00
|
|
|
die;
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print a bold message in an optional color.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $message The message to print out
|
|
|
|
* @param string $color Optional color to display message text in
|
|
|
|
* @param string $align Paragraph alignment option
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function notify ($message, $color='red', $align='center') {
|
2004-10-01 02:43:09 +00:00
|
|
|
|
|
|
|
$message = clean_text($message);
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
echo '<p align="'. $align .'"><strong><font color="'. $color .'">'. $message .'</font></strong></p>' . "\n";
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Given an email address, this function will return an obfuscated version of it
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $email The email address to obfuscate
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
|
|
|
function obfuscate_email($email) {
|
|
|
|
|
2003-07-11 08:38:39 +00:00
|
|
|
$i = 0;
|
|
|
|
$length = strlen($email);
|
2004-09-22 14:39:15 +00:00
|
|
|
$obfuscated = '';
|
2003-07-11 08:38:39 +00:00
|
|
|
while ($i < $length) {
|
|
|
|
if (rand(0,2)) {
|
|
|
|
$obfuscated.='%'.dechex(ord($email{$i}));
|
|
|
|
} else {
|
|
|
|
$obfuscated.=$email{$i};
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
return $obfuscated;
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* This function takes some text and replaces about half of the characters
|
|
|
|
* with HTML entity equivalents. Return string is obviously longer.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $plaintext The text to be obfuscated
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2003-07-11 08:38:39 +00:00
|
|
|
function obfuscate_text($plaintext) {
|
2004-09-23 04:36:43 +00:00
|
|
|
|
2003-07-11 08:38:39 +00:00
|
|
|
$i=0;
|
|
|
|
$length = strlen($plaintext);
|
2004-09-22 14:39:15 +00:00
|
|
|
$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 ) {
|
2004-09-23 12:09:19 +00:00
|
|
|
$obfuscated.='&#'.ord($plaintext{$i}).';';
|
2003-09-09 02:22:36 +00:00
|
|
|
} else if (rand(0,2)) {
|
2004-09-23 12:09:19 +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;
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
2004-09-25 05:29:21 +00:00
|
|
|
* This function uses the {@link obfuscate_email()} and {@link obfuscate_text()}
|
|
|
|
* to generate a fully obfuscated email link, ready to use.
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $email The email address to display
|
|
|
|
* @param string $label The text to dispalyed as hyperlink to $email
|
|
|
|
* @param boolean $dimmed If true then use css class 'dimmed' for hyperlink
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-09-22 14:39:15 +00:00
|
|
|
function obfuscate_mailto($email, $label='', $dimmed=false) {
|
2003-07-11 08:38:39 +00:00
|
|
|
|
|
|
|
if (empty($label)) {
|
|
|
|
$label = $email;
|
|
|
|
}
|
2004-02-20 10:27:24 +00:00
|
|
|
if ($dimmed) {
|
|
|
|
$title = get_string('emaildisable');
|
|
|
|
$dimmed = ' class="dimmed"';
|
|
|
|
} else {
|
|
|
|
$title = '';
|
|
|
|
$dimmed = '';
|
|
|
|
}
|
2004-05-21 13:07:11 +00:00
|
|
|
return sprintf("<a href=\"%s:%s\" $dimmed title=\"$title\">%s</a>",
|
2004-02-20 10:27:24 +00:00
|
|
|
obfuscate_text('mailto'), obfuscate_email($email),
|
|
|
|
obfuscate_text($label));
|
2003-07-11 08:38:39 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints a single paging bar to provide access to other pages (usually in a search)
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param int $totalcount ?
|
|
|
|
* @param int $page ?
|
|
|
|
* @param int $perpage ?
|
|
|
|
* @param string $baseurl ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2003-08-19 03:35:53 +00:00
|
|
|
function print_paging_bar($totalcount, $page, $perpage, $baseurl) {
|
|
|
|
|
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) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<center>';
|
|
|
|
echo '<p>'.get_string('page').':';
|
2003-12-30 17:18:06 +00:00
|
|
|
if ($page > 0) {
|
|
|
|
$pagenum=$page-1;
|
2004-09-22 14:39:15 +00:00
|
|
|
echo ' (<a href="'. $baseurl .'page='. $pagenum .'">'. get_string('previous') .'</a>) ';
|
2003-12-30 17:18:06 +00:00
|
|
|
}
|
2003-08-21 13:47:14 +00:00
|
|
|
$lastpage = ceil($totalcount / $perpage);
|
|
|
|
if ($page > 15) {
|
|
|
|
$startpage = $page - 10;
|
2004-09-22 14:39:15 +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) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo ' '. $displaypage;
|
2003-08-19 03:35:53 +00:00
|
|
|
} else {
|
2004-09-22 14:39:15 +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;
|
2004-09-22 14:39:15 +00:00
|
|
|
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) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo ' (<a href="'. $baseurl .'page='. $pagenum .'">'. get_string('next') .'</a>)';
|
2003-08-19 03:35:53 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '</p>';
|
|
|
|
echo '</center>';
|
2003-08-19 03:35:53 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* This function is used to rebuild the <nolink> tag because some formats (PLAIN and WIKI)
|
|
|
|
* will transform it to html entities
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @param string $text Text to search for nolink tag in
|
|
|
|
* @return string
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
2004-05-11 23:17:25 +00:00
|
|
|
function rebuildnolinktag($text) {
|
2004-05-21 13:07:11 +00:00
|
|
|
|
2004-05-11 23:17:25 +00:00
|
|
|
$text = preg_replace('/<(\/*nolink)>/i','<$1>',$text);
|
|
|
|
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2004-07-25 13:47:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-28 10:53:54 +00:00
|
|
|
// ================================================
|
|
|
|
// THREE FUNCTIONS MOVED HERE FROM course/lib.php
|
|
|
|
// ================================================
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints a nice side block with an optional header. The content can either
|
|
|
|
* be a block of HTML or a list of text with optional icons.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $THEME
|
|
|
|
* @param string $heading ?
|
|
|
|
* @param string $content ?
|
|
|
|
* @param array $list ?
|
|
|
|
* @param array $icons ?
|
|
|
|
* @param string $footer ?
|
|
|
|
* @param array $attributes ?
|
|
|
|
* @todo Finish documenting this function. Show example of various attributes, etc.
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
|
|
|
function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array()) {
|
2004-05-28 10:53:54 +00:00
|
|
|
|
|
|
|
global $THEME;
|
|
|
|
|
|
|
|
print_side_block_start($heading, $attributes);
|
|
|
|
|
|
|
|
if ($content) {
|
|
|
|
echo $content;
|
|
|
|
if ($footer) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<center><font size="-2">'. $footer .'</font></center>';
|
2004-05-28 10:53:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<table width="100%" border="0" cellspacing="0" cellpadding="2">';
|
2004-05-28 10:53:54 +00:00
|
|
|
if ($list) {
|
|
|
|
foreach ($list as $key => $string) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<tr bgcolor="'. $THEME->cellcontent2 .'">';
|
2004-05-28 10:53:54 +00:00
|
|
|
if ($icons) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<td class="sideblocklinks" valign="top" width="16">'. $icons[$key] .'</td>';
|
2004-05-28 10:53:54 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<td class="sideblocklinks" valign="top" width="*"><font size="-1">'. $string .'</font></td>';
|
|
|
|
echo '</tr>';
|
2004-05-28 10:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($footer) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<tr bgcolor="'. $THEME->cellcontent2 .'">';
|
|
|
|
echo '<td class="sideblocklinks" ';
|
2004-05-28 10:53:54 +00:00
|
|
|
if ($icons) {
|
|
|
|
echo ' colspan="2" ';
|
|
|
|
}
|
|
|
|
echo '>';
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<center><font size="-2">'. $footer .'</font></center>';
|
|
|
|
echo '</td></tr>';
|
2004-05-28 10:53:54 +00:00
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '</table>';
|
2004-05-28 10:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print_side_block_end();
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Starts a nice side block with an optional header.
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $THEME
|
|
|
|
* @param string $heading ?
|
|
|
|
* @param array $attributes ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-05-28 10:53:54 +00:00
|
|
|
function print_side_block_start($heading='', $attributes = array()) {
|
|
|
|
global $THEME;
|
|
|
|
|
|
|
|
// If there are no special attributes, give a default CSS class
|
|
|
|
if(empty($attributes) || !is_array($attributes)) {
|
|
|
|
$attributes = array('class' => 'sideblock');
|
|
|
|
}
|
|
|
|
else if(!isset($attributes['class'])) {
|
|
|
|
$attributes['class'] = 'sideblock';
|
|
|
|
}
|
|
|
|
else if(!strpos($attributes['class'], 'sideblock')) {
|
|
|
|
$attributes['class'] .= ' sideblock';
|
|
|
|
}
|
|
|
|
// OK, the class is surely there and in addition to anything
|
|
|
|
// else, it's tagged as a sideblock
|
|
|
|
|
|
|
|
$attrtext = '';
|
|
|
|
foreach($attributes as $attr => $val) {
|
|
|
|
$attrtext .= ' '.$attr.'="'.$val.'"';
|
|
|
|
}
|
|
|
|
|
|
|
|
// [pj] UGLY UGLY UGLY! I hate myself for doing this!
|
|
|
|
// When the Lord Moodle 2.0 cometh, his mercy shalt move all this mess
|
|
|
|
// to CSS and banish the evil to the abyss from whence it came.
|
|
|
|
echo '<table style="width: 100%;" cellspacing="0" cellpadding="5"'.$attrtext.'>';
|
|
|
|
if ($heading) {
|
2004-08-26 14:35:14 +00:00
|
|
|
echo '<thead><tr><td class="sideblockheading">'.$heading.'</td></tr></thead>';
|
2004-05-28 10:53:54 +00:00
|
|
|
}
|
|
|
|
echo '<tbody style="background-color: '.$THEME->cellcontent2.';"><tr><td class="sideblockmain">';
|
|
|
|
}
|
|
|
|
|
2004-07-25 13:47:38 +00:00
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print table ending tags for a side block box.
|
|
|
|
*/
|
2004-05-28 10:53:54 +00:00
|
|
|
function print_side_block_end() {
|
|
|
|
echo '</td></tr></tbody></table><br />';
|
|
|
|
echo "\n";
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
|
|
|
|
/**
|
2004-09-25 05:29:21 +00:00
|
|
|
* Prints out the HTML editor config.
|
2004-09-23 04:36:43 +00:00
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $CFG
|
2004-09-23 04:36:43 +00:00
|
|
|
*/
|
|
|
|
function print_editor_config() {
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2004-08-21 10:12:09 +00:00
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
// print new config
|
2004-09-22 14:39:15 +00:00
|
|
|
echo 'var config = new HTMLArea.Config();'."\n";
|
2004-08-21 10:12:09 +00:00
|
|
|
echo "config.pageStyle = \"body {";
|
|
|
|
if(!(empty($CFG->editorbackgroundcolor))) {
|
|
|
|
echo " background-color: $CFG->editorbackgroundcolor;";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(empty($CFG->editorfontfamily))) {
|
|
|
|
echo " font-family: $CFG->editorfontfamily;";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(empty($CFG->editorfontsize))) {
|
|
|
|
echo " font-size: $CFG->editorfontsize;";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo " }\";\n";
|
|
|
|
echo "config.killWordOnPaste = ";
|
2004-08-23 13:18:39 +00:00
|
|
|
echo(empty($CFG->editorkillword)) ? "false":"true";
|
2004-09-22 14:39:15 +00:00
|
|
|
echo ';'."\n";
|
|
|
|
echo 'config.fontname = {'."\n";
|
2004-08-21 10:12:09 +00:00
|
|
|
|
2004-08-23 13:18:39 +00:00
|
|
|
$fontlist = isset($CFG->editorfontlist) ? explode(';', $CFG->editorfontlist) : array();
|
2004-08-21 10:12:09 +00:00
|
|
|
$i = 1; // Counter is used to get rid of the last comma.
|
|
|
|
|
|
|
|
foreach($fontlist as $fontline) {
|
|
|
|
if(!empty($fontline)) {
|
2004-10-26 08:43:41 +00:00
|
|
|
if ($i > 1) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo ','."\n";
|
2004-08-21 10:12:09 +00:00
|
|
|
}
|
2004-10-26 08:43:41 +00:00
|
|
|
list($fontkey, $fontvalue) = split(':', $fontline);
|
|
|
|
echo '"'. $fontkey ."\":\t'". $fontvalue ."'";
|
|
|
|
|
|
|
|
$i++;
|
2004-08-21 10:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '};';
|
2004-10-16 09:11:00 +00:00
|
|
|
|
|
|
|
if (!empty($CFG->editorhidebuttons)) {
|
|
|
|
echo "\nconfig.hideSomeButtons(\" ". $CFG->editorhidebuttons ." \");\n";
|
|
|
|
}
|
|
|
|
|
2004-08-23 13:18:39 +00:00
|
|
|
if(!empty($CFG->editorspelling) && !empty($CFG->aspellpath)) {
|
2004-08-21 14:21:09 +00:00
|
|
|
print_speller_code($usehtmleditor=true);
|
|
|
|
}
|
2004-08-21 10:12:09 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Prints out code needed for spellchecking.
|
|
|
|
* Original idea by Ludo (Marc Alier).
|
|
|
|
*
|
2004-09-25 05:29:21 +00:00
|
|
|
* @uses $CFG
|
|
|
|
* @param boolean $usehtmleditor ?
|
2004-09-23 04:36:43 +00:00
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
|
|
|
function print_speller_code ($usehtmleditor=false) {
|
2004-08-21 10:12:09 +00:00
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if(!$usehtmleditor) {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo "\n".'<script language="javascript" type="text/javascript">'."\n";
|
|
|
|
echo 'function openSpellChecker() {'."\n";
|
2004-08-21 10:12:09 +00:00
|
|
|
echo "\tvar speller = new spellChecker();\n";
|
|
|
|
echo "\tspeller.popUpUrl = \"" . $CFG->wwwroot ."/lib/speller/spellchecker.html\";\n";
|
|
|
|
echo "\tspeller.spellCheckScript = \"". $CFG->wwwroot ."/lib/speller/server-scripts/spellchecker.php\";\n";
|
|
|
|
echo "\tspeller.spellCheckAll();\n";
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '}'."\n";
|
|
|
|
echo '</script>'."\n";
|
2004-08-21 10:12:09 +00:00
|
|
|
} else {
|
|
|
|
echo "\nfunction spellClickHandler(editor, buttonId) {\n";
|
|
|
|
echo "\teditor._textArea.value = editor.getHTML();\n";
|
|
|
|
echo "\tvar speller = new spellChecker( editor._textArea );\n";
|
|
|
|
echo "\tspeller.popUpUrl = \"" . $CFG->wwwroot ."/lib/speller/spellchecker.html\";\n";
|
|
|
|
echo "\tspeller.spellCheckScript = \"". $CFG->wwwroot ."/lib/speller/server-scripts/spellchecker.php\";\n";
|
|
|
|
echo "\tspeller._moogle_edit=1;\n";
|
|
|
|
echo "\tspeller._editor=editor;\n";
|
|
|
|
echo "\tspeller.openChecker();\n";
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '}'."\n";
|
2004-08-21 10:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-23 04:36:43 +00:00
|
|
|
/**
|
|
|
|
* Print button for spellchecking when editor is disabled
|
|
|
|
*/
|
2004-08-21 10:12:09 +00:00
|
|
|
function print_speller_button () {
|
2004-09-22 14:39:15 +00:00
|
|
|
echo '<input type="button" value="Check spelling" onclick="openSpellChecker();" />'."\n";
|
2004-08-21 10:12:09 +00:00
|
|
|
}
|
2004-10-19 21:04:28 +00:00
|
|
|
|
2003-03-14 07:55:22 +00:00
|
|
|
// vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
|
2004-09-28 09:47:14 +00:00
|
|
|
?>
|