libdir/filterlib.php"); require_once("$CFG->libdir/ajax/ajaxlib.php"); /// Constants /// Define text formatting types ... eventually we can add Wiki, BBcode etc /** * Does all sorts of transformations and filtering */ define('FORMAT_MOODLE', '0'); // Does all sorts of transformations and filtering /** * Plain HTML (with some tags stripped) */ define('FORMAT_HTML', '1'); // Plain HTML (with some tags stripped) /** * Plain text (even tags are printed in full) */ define('FORMAT_PLAIN', '2'); // Plain text (even tags are printed in full) /** * Wiki-formatted text * Deprecated: left here just to note that '3' is not used (at the moment) * and to catch any latent wiki-like text (which generates an error) */ define('FORMAT_WIKI', '3'); // Wiki-formatted text /** * Markdown-formatted text http://daringfireball.net/projects/markdown/ */ define('FORMAT_MARKDOWN', '4'); // Markdown-formatted text http://daringfireball.net/projects/markdown/ /** * TRUSTTEXT marker - if present in text, text cleaning should be bypassed */ define('TRUSTTEXT', '#####TRUSTTEXT#####'); /** * Javascript related defines */ define('REQUIREJS_BEFOREHEADER', 0); define('REQUIREJS_INHEADER', 1); define('REQUIREJS_AFTERHEADER', 2); /** * Allowed tags - string of html tags that can be tested against for safe html tags * @global string $ALLOWED_TAGS */ global $ALLOWED_TAGS; $ALLOWED_TAGS = '
'.
''.
get_string('moreinformation').' '. $message .' " . $message;
}
$performanceinfo = '';
if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) {
if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) {
$perf = get_performance_info();
error_log("PERF: " . $perf['txt']);
}
}
/// when no message and header printed yet, try to redirect
if (empty($message) and !defined('HEADER_PRINTED')) {
// Technically, HTTP/1.1 requires Location: header to contain
// the absolute path. (In practice browsers accept relative
// paths - but still, might as well do it properly.)
// This code turns relative into absolute.
if (!preg_match('|^[a-z]+:|', $url)) {
// Get host name http://www.wherever.com
$hostpart = preg_replace('|^(.*?[^:/])/.*$|', '$1', $CFG->wwwroot);
if (preg_match('|^/|', $url)) {
// URLs beginning with / are relative to web server root so we just add them in
$url = $hostpart.$url;
} else {
// URLs not beginning with / are relative to path of current script, so add that on.
$url = $hostpart.preg_replace('|\?.*$|','',me()).'/../'.$url;
}
// Replace all ..s
while (true) {
$newurl = preg_replace('|/(?!\.\.)[^/]*/\.\./|', '/', $url);
if ($newurl == $url) {
break;
}
$url = $newurl;
}
}
$delay = 0;
//try header redirection first
@header($_SERVER['SERVER_PROTOCOL'] . ' 303 See Other'); //302 might not work for POST requests, 303 is ignored by obsolete clients
@header('Location: '.$url);
//another way for older browsers and already sent headers (eg trailing whitespace in config.php)
echo '';
echo ''; // To cope with Mozilla bug
die;
}
if ($delay == -1) {
$delay = 3; // if no delay specified wait 3 seconds
}
if (! defined('HEADER_PRINTED')) {
// this type of redirect might not be working in some browsers - such as lynx :-(
print_header('', '', '', '', $errorprinted ? '' : (''));
$delay += 3; // double redirect prevention, it was sometimes breaking upgrades before 1.7
} else {
print_container_end_all(false, $THEME->open_header_containers);
}
echo '\n";
$output .= '
\n";
}
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* This function will build the navigation string to be used by print_header
* and others.
*
* It automatically generates the site and course level (if appropriate) links.
*
* If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
* and activityinstances (e.g. 'General Developer Forum') navigation levels.
*
* If you want to add any further navigation links after the ones this function generates,
* the pass an array of extra link arrays like this:
* array(
* array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
* array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
* )
* The normal case is to just add one further link, for example 'Editing forum' after
* 'General Developer Forum', with no link.
* To do that, you need to pass
* array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
* However, becuase this is a very common case, you can use a shortcut syntax, and just
* pass the string 'Editing forum', instead of an array as $extranavlinks.
*
* At the moment, the link types only have limited significance. Type 'activity' is
* recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
* that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
* This really needs to be documented better. In the mean time, try to be consistent, it will
* enable people to customise the navigation more in future.
*
* When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
* If you get the $cm object using the function get_coursemodule_from_instance or
* get_coursemodule_from_id (as recommended) then this will be done for you automatically.
* If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
* the $cm->module and $cm->instance fields, but this takes extra database queries, so a
* warning is printed in developer debug mode.
*
* @uses $CFG
* @uses $THEME
*
* @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
* only want one extra item with no link, you can pass a string instead. If you don't want
* any extra links, pass an empty string.
* @param mixed $cm - optionally the $cm object, if you want this function to generate the
* activity and activityinstance levels of navigation too.
*
* @return $navigation as an object so it can be differentiated from old style
* navigation strings.
*/
function build_navigation($extranavlinks, $cm = null) {
global $CFG, $COURSE;
if (is_string($extranavlinks)) {
if ($extranavlinks == '') {
$extranavlinks = array();
} else {
$extranavlinks = array(array('name' => $extranavlinks, 'link' => '', 'type' => 'title'));
}
}
$navlinks = array();
//Site name
if ($site = get_site()) {
$navlinks[] = array(
'name' => format_string($site->shortname),
'link' => "$CFG->wwwroot/",
'type' => 'home');
}
// Course name, if appropriate.
if (isset($COURSE) && $COURSE->id != SITEID) {
$navlinks[] = array(
'name' => format_string($COURSE->shortname),
'link' => "$CFG->wwwroot/course/view.php?id=$COURSE->id",
'type' => 'course');
}
// Activity type and instance, if appropriate.
if (is_object($cm)) {
if (!isset($cm->modname)) {
debugging('The field $cm->modname should be set if you call build_navigation with '.
'a $cm parameter. If you get $cm using get_coursemodule_from_instance or '.
'get_coursemodule_from_id, this will be done automatically.', DEBUG_DEVELOPER);
if (!$cm->modname = get_field('modules', 'name', 'id', $cm->module)) {
error('Cannot get the module type in build navigation.');
}
}
if (!isset($cm->name)) {
debugging('The field $cm->name should be set if you call build_navigation with '.
'a $cm parameter. If you get $cm using get_coursemodule_from_instance or '.
'get_coursemodule_from_id, this will be done automatically.', DEBUG_DEVELOPER);
if (!$cm->name = get_field($cm->modname, 'name', 'id', $cm->instance)) {
error('Cannot get the module name in build navigation.');
}
}
$navlinks[] = array(
'name' => get_string('modulenameplural', $cm->modname),
'link' => $CFG->wwwroot . '/mod/' . $cm->modname . '/index.php?id=' . $cm->course,
'type' => 'activity');
$navlinks[] = array(
'name' => format_string($cm->name),
'link' => $CFG->wwwroot . '/mod/' . $cm->modname . '/view.php?id=' . $cm->id,
'type' => 'activityinstance');
}
//Merge in extra navigation links
$navlinks = array_merge($navlinks, $extranavlinks);
// Work out whether we should be showing the activity (e.g. Forums) link.
// Note: build_navigation() is called from many places --
// install & upgrade for example -- where we cannot count on the
// roles infrastructure to be defined. Hence the $CFG->rolesactive check.
if (!isset($CFG->hideactivitytypenavlink)) {
$CFG->hideactivitytypenavlink = 0;
}
if ($CFG->hideactivitytypenavlink == 2) {
$hideactivitylink = true;
} else if ($CFG->hideactivitytypenavlink == 1 && $CFG->rolesactive &&
!empty($COURSE->id) && $COURSE->id != SITEID) {
if (!isset($COURSE->context)) {
$COURSE->context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
}
$hideactivitylink = !has_capability('moodle/course:manageactivities', $COURSE->context);
} else {
$hideactivitylink = false;
}
//Construct an unordered list from $navlinks
//Accessibility: heading hidden from visual browsers by default.
$navigation = get_accesshide(get_string('youarehere','access'), 'h2')." \n";
$lastindex = count($navlinks) - 1;
$i = -1; // Used to count the times, so we know when we get to the last item.
$first = true;
foreach ($navlinks as $navlink) {
$i++;
$last = ($i == $lastindex);
if (!is_array($navlink)) {
continue;
}
if (!empty($navlink['type']) && $navlink['type'] == 'activity' && !$last && $hideactivitylink) {
continue;
}
if ($first) {
$navigation .= '
";
return(array('newnav' => true, 'navlinks' => $navigation));
}
/**
* Prints a string in a specified size (retained for backward compatibility)
*
* @param string $text The text to be displayed
* @param int $size The size to set the font for text display.
*/
function print_headline($text, $size=2, $return=false) {
$output = print_heading($text, '', $size, true);
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Prints text in a format for use in headings.
*
* @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.
*/
function print_heading($text, $align='', $size=2, $class='main', $return=false) {
if ($align) {
$align = ' style="text-align:'.$align.';"';
}
if ($class) {
$class = ' class="'.$class.'"';
}
$output = "'.$icon.stripslashes_safe($text);
$output .= helpbutton($helppage, $text, $module, true, false, '', true);
$output .= '
';
if ($return) {
return $output;
} else {
echo $output;
}
}
function print_heading_block($heading, $class='', $return=false) {
//Accessibility: 'headingblock' is now H1, see theme/standard/styles_*.css: ??
$output = ''.stripslashes($heading).'
';
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Print a link to continue on to another page.
*
* @uses $CFG
* @param string $link The url to create a link to.
*/
function print_continue($link, $return=false) {
global $CFG;
// in case we are logging upgrade in admin/index.php stop it
if (function_exists('upgrade_log_finish')) {
upgrade_log_finish();
}
$output = '';
if ($link == '') {
if (!empty($_SERVER['HTTP_REFERER'])) {
$link = $_SERVER['HTTP_REFERER'];
$link = str_replace('&', '&', $link); // make it valid XHTML
} else {
$link = $CFG->wwwroot .'/';
}
}
$options = array();
$linkparts = parse_url(str_replace('&', '&', $link));
if (isset($linkparts['query'])) {
parse_str($linkparts['query'], $options);
}
$output .= ' '."\n";
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Print a message in a standard themed box.
* Replaces print_simple_box (see deprecatedlib.php)
*
* @param string $message, the content of the box
* @param string $classes, space-separated class names.
* @param string $idbase
* @param boolean $return, return as string or just print it
* @return mixed string or void
*/
function print_box($message, $classes='generalbox', $ids='', $return=false) {
$output = print_box_start($classes, $ids, true);
$output .= stripslashes_safe($message);
$output .= print_box_end(true);
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Starts a box using divs
* Replaces print_simple_box_start (see deprecatedlib.php)
*
* @param string $classes, space-separated class names.
* @param string $idbase
* @param boolean $return, return as string or just print it
* @return mixed string or void
*/
function print_box_start($classes='generalbox', $ids='', $return=false) {
global $THEME;
if (strpos($classes, 'clearfix') !== false) {
$clearfix = true;
$classes = trim(str_replace('clearfix', '', $classes));
} else {
$clearfix = false;
}
if (!empty($THEME->customcorners)) {
$classes .= ' ccbox box';
} else {
$classes .= ' box';
}
return print_container_start($clearfix, $classes, $ids, $return);
}
/**
* Simple function to end a box (see above)
* Replaces print_simple_box_end (see deprecatedlib.php)
*
* @param boolean $return, return as string or just print it
*/
function print_box_end($return=false) {
return print_container_end($return);
}
/**
* Print a message in a standard themed container.
*
* @param string $message, the content of the container
* @param boolean $clearfix clear both sides
* @param string $classes, space-separated class names.
* @param string $idbase
* @param boolean $return, return as string or just print it
* @return string or void
*/
function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
$output = print_container_start($clearfix, $classes, $idbase, true);
$output .= stripslashes_safe($message);
$output .= print_container_end(true);
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Starts a container using divs
*
* @param boolean $clearfix clear both sides
* @param string $classes, space-separated class names.
* @param string $idbase
* @param boolean $return, return as string or just print it
* @return mixed string or void
*/
function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
global $THEME;
if (!isset($THEME->open_containers)) {
$THEME->open_containers = array();
}
$THEME->open_containers[] = $idbase;
if (!empty($THEME->customcorners)) {
$output = _print_custom_corners_start($clearfix, $classes, $idbase);
} else {
if ($idbase) {
$id = ' id="'.$idbase.'"';
} else {
$id = '';
}
if ($clearfix) {
$clearfix = ' clearfix';
} else {
$clearfix = '';
}
if ($classes or $clearfix) {
$class = ' class="'.$classes.$clearfix.'"';
} else {
$class = '';
}
$output = '';
if ($br) {
$output .= '
'."\n";
}
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Given the path to a picture file in a course, or a URL,
* this function includes the picture in the page.
*
* @param string $path ?
* @param int $courseid ?
* @param int $height ?
* @param int $width ?
* @param string $link ?
* @todo Finish documenting this function
*/
function print_file_picture($path, $courseid=0, $height='', $width='', $link='', $return=false) {
global $CFG;
$output = '';
if ($height) {
$height = 'height="'. $height .'"';
}
if ($width) {
$width = 'width="'. $width .'"';
}
if ($link) {
$output .= '';
}
if (substr(strtolower($path), 0, 7) == 'http://') {
$output .= '';
} else if ($courseid) {
$output .= '
picture is used.
* @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatability
* @param boolean $return If false print picture to current page, otherwise return the output as string
* @param boolean $link enclose printed image in a link the user's profile (default true).
* @param string $target link target attribute. Makes the profile open in a popup window.
* @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
* decorative images, or where the username will be printed anyway.)
* @return string or nothing, depending on $return.
*/
function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
global $CFG;
$needrec = false;
// only touch the DB if we are missing data...
if (is_object($user)) {
// Note - both picture and imagealt _can_ be empty
// what we are trying to see here is if they have been fetched
// from the DB. We should use isset() _except_ that some installs
// have those fields as nullable, and isset() will return false
// on null. The only safe thing is to ask array_key_exists()
// which works on objects. property_exists() isn't quite
// what we want here...
if (! (array_key_exists('picture', $user)
&& ($alttext && array_key_exists('imagealt', $user)
|| (isset($user->firstname) && isset($user->lastname)))) ) {
$needrec = true;
$user = $user->id;
}
} else {
if ($alttext) {
// we need firstname, lastname, imagealt, can't escape...
$needrec = true;
} else {
$userobj = new StdClass; // fake it to save DB traffic
$userobj->id = $user;
$userobj->picture = $picture;
$user = clone($userobj);
unset($userobj);
}
}
if ($needrec) {
$user = get_record('user','id',$user, '', '', '', '', 'id,firstname,lastname,imagealt');
}
if ($link) {
$url = '/user/view.php?id='. $user->id .'&course='. $courseid ;
if ($target) {
$target='onclick="return openpopup(\''.$url.'\');"';
}
$output = '';
} else {
$output = '';
}
if (empty($size)) {
$file = 'f2';
$size = 35;
} else if ($size === true or $size == 1) {
$file = 'f1';
$size = 100;
} else if ($size >= 50) {
$file = 'f1';
} else {
$file = 'f2';
}
$class = "userpicture";
if (is_null($picture) and !empty($user->picture)) {
$picture = $user->picture;
}
if ($picture) { // Print custom user picture
require_once($CFG->libdir.'/filelib.php');
$src = get_file_url($user->id.'/'.$file.'.jpg', null, 'user');
} else { // Print default user pictures (use theme version if available)
$class .= " defaultuserpic";
$src = "$CFG->pixpath/u/$file.png";
}
$imagealt = '';
if ($alttext) {
if (!empty($user->imagealt)) {
$imagealt = $user->imagealt;
} else {
$imagealt = get_string('pictureof','',fullname($user));
}
}
$output .= "
';
if ($link) {
$output .= '';
}
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Prints a summary of a user in a nice little box.
*
* @uses $CFG
* @uses $USER
* @param user $user A {@link $USER} object representing a user
* @param course $course A {@link $COURSE} object representing a course
*/
function print_user($user, $course, $messageselect=false, $return=false) {
global $CFG, $USER;
$output = '';
static $string;
static $datestring;
static $countries;
$context = get_context_instance(CONTEXT_COURSE, $course->id);
if (isset($user->context->id)) {
$usercontext = $user->context;
} else {
$usercontext = get_context_instance(CONTEXT_USER, $user->id);
}
if (empty($string)) { // Cache all the strings for the rest of the page
$string->email = get_string('email');
$string->city = get_string('city');
$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');
$datestring->year = get_string('year');
$datestring->years = get_string('years');
$countries = get_list_of_countries();
}
/// Get the hidden field list
if (has_capability('moodle/course:viewhiddenuserfields', $context)) {
$hiddenfields = array();
} else {
$hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
}
$output .= '
';
$output .= '
';
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Print a specified group's avatar.
*
* @param group $group A single {@link group} object OR array of groups.
* @param int $courseid The course ID.
* @param boolean $large Default small picture, or large.
* @param boolean $return If false print picture, otherwise return the output as string
* @param boolean $link Enclose image in a link to view specified course?
* @return string
* @todo Finish documenting this function
*/
function print_group_picture($group, $courseid, $large=false, $return=false, $link=true) {
global $CFG;
if (is_array($group)) {
$output = '';
foreach($group as $g) {
$output .= print_group_picture($g, $courseid, $large, true, $link);
}
if ($return) {
return $output;
} else {
echo $output;
return;
}
}
$context = get_context_instance(CONTEXT_COURSE, $courseid);
if ($group->hidepicture and !has_capability('moodle/course:managegroups', $context)) {
return '';
}
if ($link or has_capability('moodle/site:accessallgroups', $context)) {
$output = '';
} else {
$output = '';
}
if ($large) {
$file = 'f1';
} else {
$file = 'f2';
}
if ($group->picture) { // Print custom group picture
require_once($CFG->libdir.'/filelib.php');
$grouppictureurl = get_file_url($group->id.'/'.$file.'.jpg', null, 'usergroup');
$output .= '';
$output .= ' ';
$output .= print_user_picture($user, $course->id, $user->picture, true, true);
$output .= ' ';
$output .= '';
$output .= '
';
}
if ($user->maildisplay == 1 or ($user->maildisplay == 2 and ($course->id != SITEID) and !isguest()) or
has_capability('moodle/course:viewhiddenuserfields', $context)) {
$output .= $string->email .': '. $user->email .'
';
}
if (($user->city or $user->country) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) {
$output .= $string->city .': ';
if ($user->city && !isset($hiddenfields['city'])) {
$output .= $user->city;
}
if (!empty($countries[$user->country]) && !isset($hiddenfields['country'])) {
if ($user->city && !isset($hiddenfields['city'])) {
$output .= ', ';
}
$output .= $countries[$user->country];
}
$output .= '
';
}
if (!isset($hiddenfields['lastaccess'])) {
if ($user->lastaccess) {
$output .= $string->lastaccess .': '. userdate($user->lastaccess);
$output .= ' ('. format_time(time() - $user->lastaccess, $datestring) .')';
} else {
$output .= $string->lastaccess .': '. $string->never;
}
}
$output .= '';
//link to blogs
if ($CFG->bloglevel > 0) {
$output .= ''.get_string('blogs','blog').'
';
}
//link to notes
if (!empty($CFG->enablenotes) and (has_capability('moodle/notes:manage', $context) || has_capability('moodle/notes:view', $context))) {
$output .= ''.get_string('notes','notes').'
';
}
if (has_capability('moodle/site:viewreports', $context) or has_capability('moodle/user:viewuseractivitiesreport', $usercontext)) {
$output .= ''. $string->activity .'
';
}
if (has_capability('moodle/role:assign', $context) and get_user_roles($context, $user->id, false)) { // I can unassing and user has some role
$output .= ''. $string->unenrol .'
';
}
if ($USER->id != $user->id && empty($USER->realuser) && has_capability('moodle/user:loginas', $context) &&
! has_capability('moodle/site:doanything', $context, $user->id, false)) {
$output .= ''. $string->loginas .'
';
}
$output .= ''. $string->fullprofile .'...';
if (!empty($messageselect)) {
$output .= '
';
}
$output .= '';
}
if ($link or has_capability('moodle/site:accessallgroups', $context)) {
$output .= '';
}
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Print a png image.
*
* @param string $url ?
* @param int $sizex ?
* @param int $sizey ?
* @param boolean $return ?
* @param string $parameters ?
* @todo Finish documenting this function
*/
function print_png($url, $sizex, $sizey, $return, $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
$output .= '
';
} else {
$output .= '
$table->data[] - An array of arrays containing the data.
*
summary)) {
$output .= " summary=\"$table->summary\"";
}
$output .= " cellpadding=\"$table->cellpadding\" cellspacing=\"$table->cellspacing\" class=\"$table->class boxalign$table->tablealign\" $tableid>\n";
$countcols = 0;
if (!empty($table->head)) {
$countcols = count($table->head);
$output .= '
'."\n";
if ($return) {
return $output;
}
echo $output;
return true;
}
function print_recent_activity_note($time, $user, $text, $link, $return=false, $viewfullnames=null) {
static $strftimerecent = null;
$output = '';
if (is_null($viewfullnames)) {
$context = get_context_instance(CONTEXT_SYSTEM);
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
}
if (is_null($strftimerecent)) {
$strftimerecent = get_string('strftimerecent');
}
$output .= '';
$keys=array_keys($table->head);
$lastkey = end($keys);
foreach ($table->head as $key => $heading) {
if (!isset($size[$key])) {
$size[$key] = '';
}
if (!isset($align[$key])) {
$align[$key] = '';
}
if ($key == $lastkey) {
$extraclass = ' lastcol';
} else {
$extraclass = '';
}
$output .= ' '."\n";
}
if (!empty($table->data)) {
$oddeven = 1;
$keys=array_keys($table->data);
$lastrowkey = end($keys);
foreach ($table->data as $key => $row) {
$oddeven = $oddeven ? 0 : 1;
if (!isset($table->rowclass[$key])) {
$table->rowclass[$key] = '';
}
if ($key == $lastrowkey) {
$table->rowclass[$key] .= ' lastrow';
}
$output .= ''. $heading .' ';
}
$output .= ''."\n";
if ($row == 'hr' and $countcols) {
$output .= ' '."\n";
}
}
$output .= '';
} else { /// it's a normal row of data
$keys2=array_keys($row);
$lastkey = end($keys2);
foreach ($row as $key => $item) {
if (!isset($size[$key])) {
$size[$key] = '';
}
if (!isset($align[$key])) {
$align[$key] = '';
}
if (!isset($wrap[$key])) {
$wrap[$key] = '';
}
if ($key == $lastkey) {
$extraclass = ' lastcol';
} else {
$extraclass = '';
}
$output .= ' '. $item .' ';
}
}
$output .= ''."\n".'
';
$output .= link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true', 'ratingscales',
$linkobject, 400, 500, $strscales, 'none', true);
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Prints a scale menu (as part of an existing form) including help button
* Just like {@link print_grade_menu()} but without the numeric grades
*
* @param int $courseid ?
* @param string $name ?
* @param string $current ?
* @todo Finish documenting this function
*/
function print_scale_menu($courseid, $name, $current, $return=false) {
global $CFG;
$output = '';
$strscales = get_string('scales');
$output .= choose_from_menu(get_scales_menu($courseid), $name, $current, '', '', 0, true);
$linkobject = '
';
$output .= link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true', 'ratingscales',
$linkobject, 400, 500, $strscales, 'none', true);
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Prints a help button about a scale
*
* @uses $CFG
* @param id $courseid ?
* @param object $scale ?
* @todo Finish documenting this function
*/
function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
global $CFG;
$output = '';
$strscales = get_string('scales');
$linkobject = '
';
$output .= link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true&scaleid='. $scale->id, 'ratingscale',
$linkobject, 400, 500, $scale->name, 'none', true);
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Print an error page displaying an error message. New method - use this for new code.
*
* @uses $SESSION
* @uses $CFG
* @param string $errorcode The name of the string from error.php (or other specified file) to print
* @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.
* @param object $a Extra words and phrases that might be required in the error string
* @param array $extralocations An array of strings with other locations to look for string files
* @return does not return, terminates script
*/
function print_error($errorcode, $module='error', $link='', $a=NULL, $extralocations=NULL) {
global $CFG, $SESSION, $THEME;
if (empty($module) || $module === 'moodle' || $module === 'core') {
$module = 'error';
}
$message = get_string($errorcode, $module, $a, $extralocations);
if ($module === 'error' and strpos($message, '[[') === 0) {
//search in moodle file if error specified - needed for backwards compatibility
$message = get_string($errorcode, 'moodle', $a, $extralocations);
}
if (empty($link) and !defined('ADMIN_EXT_HEADER_PRINTED')) {
if ( !empty($SESSION->fromurl) ) {
$link = $SESSION->fromurl;
unset($SESSION->fromurl);
} else {
$link = $CFG->wwwroot .'/';
}
}
if (!empty($CFG->errordocroot)) {
$errordocroot = $CFG->errordocroot;
} else if (!empty($CFG->docroot)) {
$errordocroot = $CFG->docroot;
} else {
$errordocroot = 'http://docs.moodle.org';
}
if (defined('FULLME') && FULLME == 'cron') {
// Errors in cron should be mtrace'd.
mtrace($message);
die;
}
if ($module === 'error') {
$modulelink = 'moodle';
} else {
$modulelink = $module;
}
$message = clean_text(' '.
'
';
print_simple_box($message, '', '', '', '', 'errorbox');
debugging('Stack trace:', DEBUG_DEVELOPER);
// in case we are logging upgrade in admin/index.php stop it
if (function_exists('upgrade_log_finish')) {
upgrade_log_finish();
}
if (!empty($link)) {
print_continue($link);
}
print_footer();
for ($i=0;$i<512;$i++) { // Padding to help IE work with 404
echo ' ';
}
die;
}
/**
* Print an error to STDOUT and exit with a non-zero code. For commandline scripts.
* Default errorcode is 1.
*
* Very useful for perl-like error-handling:
*
* do_somethting() or mdie("Something went wrong");
*
* @param string $msg Error message
* @param integer $errorcode Error code to emit
*/
function mdie($msg='', $errorcode=1) {
trigger_error($msg);
exit($errorcode);
}
/**
* Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
* Should be used only with htmleditor or textarea.
* @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
* helpbutton.
* @return string
*/
function editorhelpbutton(){
global $CFG, $SESSION;
$items = func_get_args();
$i = 1;
$urlparams = array();
$titles = array();
foreach ($items as $item){
if (is_array($item)){
$urlparams[] = "keyword$i=".urlencode($item[0]);
$urlparams[] = "title$i=".urlencode($item[1]);
if (isset($item[2])){
$urlparams[] = "module$i=".urlencode($item[2]);
}
$titles[] = trim($item[1], ". \t");
}elseif (is_string($item)){
$urlparams[] = "button$i=".urlencode($item);
switch ($item){
case 'reading' :
$titles[] = get_string("helpreading");
break;
case 'writing' :
$titles[] = get_string("helpwriting");
break;
case 'questions' :
$titles[] = get_string("helpquestions");
break;
case 'emoticons' :
$titles[] = get_string("helpemoticons");
break;
case 'richtext' :
$titles[] = get_string('helprichtext');
break;
case 'text' :
$titles[] = get_string('helptext');
break;
default :
error('Unknown help topic '.$item);
}
}
$i++;
}
if (count($titles)>1){
//join last two items with an 'and'
$a = new object();
$a->one = $titles[count($titles) - 2];
$a->two = $titles[count($titles) - 1];
$titles[count($titles) - 2] = get_string('and', '', $a);
unset($titles[count($titles) - 1]);
}
$alttag = join (', ', $titles);
$paramstring = join('&', $urlparams);
$linkobject = '';
return link_to_popup_window(s('/lib/form/editorhelp.php?'.$paramstring), 'popup', $linkobject, 400, 500, $alttag, 'none', true);
}
/**
* Print a help button.
*
* @uses $CFG
* @param string $page The keyword that defines a help page
* @param string $title The title of links, rollover tips, alt tags etc
* 'Help with' (or the language equivalent) will be prefixed and '...' will be stripped.
* @param string $module Which module is the page defined in
* @param mixed $image Use a help image for the link? (true/false/"both")
* @param boolean $linktext If true, display the title next to the help icon.
* @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.
* @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif
* @return string
* @todo Finish documenting this function
*/
function helpbutton ($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false,
$imagetext='') {
global $CFG, $COURSE;
//warning if ever $text parameter is used
//$text option won't work properly because the text needs to be always cleaned and,
// when cleaned... html tags always break, so it's unusable.
if ( isset($text) && $text!='') {
debugging('Warning: it\'s not recommended to use $text parameter in helpbutton ($page=' . $page . ', $module=' . $module . ') function', DEBUG_DEVELOPER);
}
// fix for MDL-7734
if (!empty($COURSE->lang)) {
$forcelang = $COURSE->lang;
} else {
$forcelang = '';
}
if ($module == '') {
$module = 'moodle';
}
if ($title == '' && $linktext == '') {
debugging('Error in call to helpbutton function: at least one of $title and $linktext is required');
}
// Warn users about new window for Accessibility
$tooltip = get_string('helpprefix2', '', trim($title, ". \t")) .' ('.get_string('newwindow').')';
$linkobject = '';
if ($image) {
if ($linktext) {
// MDL-7469 If text link is displayed with help icon, change to alt to "help with this".
$linkobject .= $title.' ';
$tooltip = get_string('helpwiththis');
}
if ($imagetext) {
$linkobject .= $imagetext;
} else {
$linkobject .= '
';
}
} else {
$linkobject .= $tooltip;
}
// fix for MDL-7734
if ($text) {
$url = '/help.php?module='. $module .'&text='. s(urlencode($text).'&forcelang='.$forcelang);
} else {
$url = '/help.php?module='. $module .'&file='. $page .'.html&forcelang='.$forcelang;
}
$link = ''.
link_to_popup_window ($url, 'popup', $linkobject, 400, 500, $tooltip, 'none', true).
'';
if ($return) {
return $link;
} else {
echo $link;
}
}
/**
* Print a help button.
*
* Prints a special help button that is a link to the "live" emoticon popup
* @uses $CFG
* @uses $SESSION
* @param string $form ?
* @param string $field ?
* @todo Finish documenting this function
*/
function emoticonhelpbutton($form, $field, $return = false) {
global $CFG, $SESSION;
$SESSION->inserttextform = $form;
$SESSION->inserttextfield = $field;
$imagetext = '
';
$help = helpbutton('emoticons', get_string('helpemoticons'), 'moodle', true, true, '', true, $imagetext);
if (!$return){
echo $help;
} else {
return $help;
}
}
/**
* Print a help button.
*
* Prints a special help button for html editors (htmlarea in this case)
* @uses $CFG
*/
function editorshortcutshelpbutton() {
global $CFG;
$imagetext = '
';
return helpbutton('editorshortcuts', get_string('editorshortcutkeys'), 'moodle', true, false, '', true, $imagetext);
}
/**
* Print a message and exit.
*
* @uses $CFG
* @param string $message ?
* @param string $link ?
* @todo Finish documenting this function
*/
function notice ($message, $link='', $course=NULL) {
global $CFG, $SITE, $THEME, $COURSE;
$message = clean_text($message); // In case nasties are in here
if (defined('FULLME') && FULLME == 'cron') {
// notices in cron should be mtrace'd.
mtrace($message);
die;
}
if (! defined('HEADER_PRINTED')) {
//header not yet printed
print_header(get_string('notice'));
} else {
print_container_end_all(false, $THEME->open_header_containers);
}
print_box($message, 'generalbox', 'notice');
print_continue($link);
if (empty($course)) {
print_footer($COURSE);
} else {
print_footer($course);
}
exit;
}
/**
* Print a message along with "Yes" and "No" links for the user to continue.
*
* @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"
* TODO Document remaining arguments
*/
function notice_yesno ($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
global $CFG;
$message = clean_text($message);
$linkyes = clean_text($linkyes);
$linkno = clean_text($linkno);
print_box_start('generalbox', 'notice');
echo '
.
* @param string $content ?
* @param array $list ?
* @param array $icons ?
* @param string $footer ?
* @param array $attributes ?
* @param string $title Plain text title, as embedded in the $heading.
* @todo Finish documenting this function. Show example of various attributes, etc.
*/
function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
//Accessibility: skip block link, with title-text (or $block_id) to differentiate links.
static $block_id = 0;
$block_id++;
$skip_text = get_string('skipa', 'access', strip_tags($title));
$skip_link = ''.$skip_text.'';
$skip_dest = '';
$strip_title = strip_tags($title);
if (! empty($strip_title)) {
echo $skip_link;
}
//ELSE: a single link on a page "Skip block 4" is too confusing - ignore.
print_side_block_start($heading, $attributes);
if ($content) {
echo $content;
if ($footer) {
echo ' ';
}
} else {
if ($list) {
$row = 0;
//Accessibility: replaced unnecessary table with list, see themes/standard/styles_layout.css
echo "\n
\n";
foreach ($list as $key => $string) {
echo '
\n";
}
if ($footer) {
echo ' ';
}
}
print_side_block_end($attributes, $title);
echo $skip_dest;
}
/**
* Starts a nice side block with an optional header.
*
* @param string $heading ?
* @param array $attributes ?
* @todo Finish documenting this function
*/
function print_side_block_start($heading='', $attributes = array()) {
global $CFG, $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
/*
// IE misery: if I do it this way, blocks which start hidden cannot be "unhidden"
// If there is a cookie to hide this thing, start it hidden
if (!empty($attributes['id']) && isset($_COOKIE['hide:'.$attributes['id']])) {
$attributes['class'] = 'hidden '.$attributes['class'];
}
*/
$attrtext = '';
foreach ($attributes as $attr => $val) {
$attrtext .= ' '.$attr.'="'.$val.'"';
}
echo '