\n$meta\n"; if (!empty($CFG->unicode)) { $encoding = 'utf-8'; } else if (!empty($CFG->courselang)) { $encoding = get_string('thischarset'); moodle_setlocale(); } else { if (!empty($SESSION->encoding)) { $encoding = $SESSION->encoding; } else { $SESSION->encoding = $encoding = get_string('thischarset'); } } $meta = ''. "\n". $meta ."\n"; if (!$usexml) { @header('Content-type: text/html; charset='.$encoding); } if ( get_string('thisdirection') == 'rtl' ) { $direction = ' dir="rtl"'; } else { $direction = ' dir="ltr"'; } if (!$cache) { // Do everything we can to prevent clients and proxies caching @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT'); @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); @header('Cache-Control: no-store, no-cache, must-revalidate'); @header('Cache-Control: post-check=0, pre-check=0', false); @header('Pragma: no-cache'); $meta .= "\n".''; $meta .= "\n".''; } if ($usexml) { // Added by Gustav Delius / Mad Alex for MathML output // Modified by Julian Sedding $currentlanguage = current_language(); $mathplayer = preg_match("/MathPlayer/i", $_SERVER['HTTP_USER_AGENT']); if(!$mathplayer) { header('Content-Type: application/xhtml+xml'); } echo ''."\n"; if (!empty($CFG->xml_stylesheets)) { $stylesheets = explode(';', $CFG->xml_stylesheets); foreach ($stylesheets as $stylesheet) { echo 'wwwroot .'/'. $stylesheet .'" ?>' . "\n"; } } echo ''."\n"; $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 .= '' . "\n"; $meta .= ''."\n"; $meta .= ''."\n"; $meta .= '' . "\n"; } } $title = str_replace('"', '"', $title); $title = strip_tags($title); include ($CFG->dirroot .'/theme/'. $CFG->theme .'/header.html'); } /** * 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 * * @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 tag (useful for onload() etc) */ function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='', $cache=true, $button=' ', $menu='', $usexml=false, $bodytags='') { global $course; // The same hack is used in print_header $shortname =''; if ($course->category) { $shortname = ''. $course->shortname .' ->'; } print_header($course->shortname .': '. $title, $course->fullname .' '. $heading, $shortname .' '. $navigation, $focus, $meta, $cache, $button, $menu, $usexml, $bodytags); } /** * 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 * @param course $course {@link $COURSE} object containing course information * @param ? $usercourse ? * @todo Finish documenting this function */ function print_footer ($course=NULL, $usercourse=NULL) { global $USER, $CFG, $THEME; /// Course links if ($course) { if ($course == 'home') { // special case for site home page - please do not remove $homelink = ''; $homelink .= ''; $course = get_site(); $homepage = true; } else { $homelink = "framename}\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname"; } } else { $homelink = "framename}\" href=\"$CFG->wwwroot/\">".get_string('home').''; $course = get_site(); } if (!$usercourse) { $usercourse = $course; } /// User links $loggedinas = user_login_string($usercourse, $USER); include ($CFG->dirroot .'/theme/'. $CFG->theme .'/footer.html'); } /** * This function is called by stylesheets to set up the header * approriately as well as the current path * * @uses $CFG * @param int $lastmodified ? * @param int $lifetime ? * @param string $thename ? * @todo Finish documenting this function */ function style_sheet_setup($lastmodified=0, $lifetime=300, $themename='') { global $CFG; header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $lastmodified) . ' GMT'); header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT'); header('Cache-control: max_age = '. $lifetime); header('Pragma: '); header('Content-type: text/css'); // Correct MIME type if (!empty($themename)) { $CFG->theme = $themename; } return $CFG->wwwroot .'/theme/'. $CFG->theme; } /** * Returns text to be displayed to the user which reflects their login status * * @uses $CFG * @uses $USER * @param course $course {@link $COURSE} object containing course information * @param user $user {@link $USER} object containing user information * @return string * @todo Finish documenting this function */ function user_login_string($course, $user=NULL) { global $USER, $CFG; if (empty($user)) { $user = $USER; } if (isset($user->realuser)) { if ($realuser = get_record('user', 'id', $user->realuser)) { $fullname = fullname($realuser, true); $realuserinfo = " [framename}\" href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&return=$realuser->id\">$fullname] "; } } else { $realuserinfo = ''; } if (empty($CFG->loginhttps)) { $wwwroot = $CFG->wwwroot; } else { $wwwroot = str_replace('http','https',$CFG->wwwroot); } if (isset($user->id) and $user->id) { $fullname = fullname($user, true); $username = "framename}\" href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">$fullname"; if (isguest($user->id)) { $loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username). " (framename}\" href=\"$wwwroot/login/index.php\">".get_string('login').')'; } else { $loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username). " (framename}\" href=\"$CFG->wwwroot/login/logout.php\">".get_string('logout').')'; } } else { $loggedinas = get_string('loggedinnot', 'moodle'). " (framename}\" href=\"$wwwroot/login/index.php\">".get_string('login').')'; } return $loggedinas; } /** * Prints breadcrumbs links * * @uses $CFG * @param string $navigation The breadcrumbs string to be printed */ function print_navigation ($navigation) { global $CFG; if ($navigation) { if (! $site = get_site()) { $site->shortname = get_string('home');; } $navigation = str_replace('->', '»', $navigation); echo ''. $site->shortname .' » '. $navigation; } } /** * Prints a string in a specified size * * @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) { echo ''. $text .''."\n"; } /** * 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='center', $size=3) { echo ''. stripslashes_safe($text) .''; } /** * Centered heading with attached help button (same title text) * and optional icon attached * * @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 */ function print_heading_with_help($text, $helppage, $module='moodle', $icon='') { echo ''. $icon .''. stripslashes_safe($text); helpbutton($helppage, $text, $module); echo ''; } /** * 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) { global $CFG; if (!$link) { $link = $_SERVER['HTTP_REFERER']; } print_heading(''. get_string('continue').''); } /** * Print a message in a standard themed box. * * @param string $message ? * @param string $align ? * @param string $width ? * @param string $color ? * @param int $padding ? * @param string $class ? * @todo Finish documenting this function */ function print_simple_box($message, $align='', $width='', $color='#FFFFFF', $padding=5, $class='generalbox') { print_simple_box_start($align, $width, $color, $padding, $class); echo stripslashes_safe($message); print_simple_box_end(); } /** * Print the top portion of a standard themed box. * * @param string $align ? * @param string $width ? * @param string $color ? * @param int $padding ? * @param string $class ? * @todo Finish documenting this function */ function print_simple_box_start($align='', $width='', $color='#FFFFFF', $padding=5, $class='generalbox') { global $THEME; if ($align) { $align = 'align="'. $align .'"'; } if ($width) { $width = 'width="'. $width .'"'; } echo ""; } /** * Print the end portion of a standard themed box. */ function print_simple_box_end() { echo ''; } /** * Print a self contained form with a single submit button. * * @param string $link ? * @param array $options ? * @param string $label ? * @param string $method ? * @todo Finish documenting this function */ function print_single_button($link, $options, $label='OK', $method='get') { echo ''; if ($options) { foreach ($options as $name => $value) { echo ''; } } echo ''; } /** * Print a spacer image with the option of including a line break. * * @param int $height ? * @param int $width ? * @param boolean $br ? * @todo Finish documenting this function */ function print_spacer($height=1, $width=1, $br=true) { global $CFG; echo ''; if ($br) { echo ''."\n"; } } /** * 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='') { global $CFG; if ($height) { $height = 'height="'. $height .'"'; } if ($width) { $width = 'width="'. $width .'"'; } if ($link) { echo ''; } if (substr(strtolower($path), 0, 7) == 'http://') { echo ''; } else if ($courseid) { echo ''; } else { echo 'Error: must pass URL or course'; } if ($link) { echo ''; } } /** * Print the specified user's avatar. * * @param int $userid ? * @param int $courseid ? * @param boolean $picture Print the user picture? * @param boolean $large Should the picture be printed at 100 pixels or 35? * @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 * @todo Finish documenting this function */ function print_user_picture($userid, $courseid, $picture, $large=false, $returnstring=false, $link=true) { global $CFG; if ($link) { $output = ''; } else { $output = ''; } if ($large) { $file = 'f1'; $size = 100; } else { $file = 'f2'; $size = 35; } if ($picture) { // Print custom user picture if ($CFG->slasharguments) { // Use this method if possible for better caching $output .= ''; } else { $output .= ''; } } else { // Print default user pictures (use theme version if available) $output .= "pixpath/u/$file.png\"". " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />"; } if ($link) { $output .= ''; } if ($returnstring) { 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) { global $CFG, $USER; static $string; static $datestring; static $countries; static $isteacher; static $isadmin; if (empty($string)) { // Cache all the strings for the rest of the page $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'); $countries = get_list_of_countries(); $isteacher = isteacher($course->id); $isadmin = isadmin(); } echo ''; echo ''; echo ''; print_user_picture($user->id, $course->id, $user->picture, true); echo ''; echo ''; echo ''; echo ''.fullname($user, $isteacher).''; echo ''; if (!empty($user->role) and ($user->role <> $course->teacher)) { echo $string->role .': '. $user->role .''; } if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category and !isguest()) or $isteacher) { echo $string->email .': '. $user->email .''; } if ($user->city or $user->country) { echo $string->location .': '; if ($user->city) { echo $user->city; } if (!empty($countries[$user->country])) { if ($user->city) { echo ', '; } echo $countries[$user->country]; } echo ''; } if ($user->lastaccess) { echo $string->lastaccess .': '. userdate($user->lastaccess); echo '  ('. format_time(time() - $user->lastaccess, $datestring) .')'; } else { echo $string->lastaccess .': '. $string->never; } echo ''; echo ''; if ($isteacher) { $timemidnight = usergetmidnight(time()); echo ''. $string->activity .''; if (!iscreator($user->id) or ($isadmin and !isadmin($user->id))) { // Includes admins if ($course->category and isteacheredit($course->id) and isstudent($course->id, $user->id)) { // Includes admins echo ''. $string->unenrol .''; } if ($USER->id != $user->id) { echo ''. $string->loginas .''; } } } echo ''. $string->fullprofile .'...'; echo ''; echo ''; } /** * Print a specified group's avatar. * * @param group $group A {@link group} object representing a group * @param int $courseid ? * @param boolean $large ? * @param boolean $returnstring ? * @param boolean $link ? * @return string * @todo Finish documenting this function */ function print_group_picture($group, $courseid, $large=false, $returnstring=false, $link=true) { global $CFG; static $isteacheredit; if (!isset($isteacheredit)) { $isteacheredit = isteacheredit($courseid); } if ($group->hidepicture and !$isteacheredit) { return ''; } if ($link or $isteacheredit) { $output = ''; } else { $output = ''; } if ($large) { $file = 'f1'; $size = 100; } else { $file = 'f2'; $size = 35; } if ($group->picture) { // Print custom group picture if ($CFG->slasharguments) { // Use this method if possible for better caching $output .= "wwwroot/user/pixgroup.php/$group->id/$file.jpg\"". " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" title=\"$group->name\"/>"; } else { $output .= "wwwroot/user/pixgroup.php?file=/$group->id/$file.jpg\"". " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" title=\"$group->name\"/>"; } } if ($link or $isteacheredit) { $output .= ''; } if ($returnstring) { return $output; } else { echo $output; } } /** * Print a png image. * * @param string $url ? * @param int $sizex ? * @param int $sizey ? * @param boolean $returnstring ? * @param string $parameters ? * @todo Finish documenting this function */ 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 $output .= ''; } else { $output .= ''; } if ($returnstring) { return $output; } else { echo $output; } } /** * Print a nicely formatted table. * * @uses $THEME * @param array $table is an object with several properties. * $table->head - An array of heading names. * $table->align - An array of column alignments * $table->size - An array of column sizes * $table->wrap - An array of "nowrap"s or nothing * $table->data[] - An array of arrays containing the data. * $table->width - A percentage of the page * $table->cellpadding - Padding on each cell * $table->cellspacing - Spacing between cells * * @return boolean * @todo Finish documenting this function */ function print_table($table) { global $THEME; if (isset($table->align)) { foreach ($table->align as $key => $aa) { if ($aa) { $align[$key] = ' align="'. $aa .'"'; } else { $align[$key] = ''; } } } if (isset($table->size)) { foreach ($table->size as $key => $ss) { if ($ss) { $size[$key] = ' width="'. $ss .'"'; } else { $size[$key] = ''; } } } if (isset($table->wrap)) { foreach ($table->wrap as $key => $ww) { if ($ww) { $wrap[$key] = ' nowrap="nowrap" '; } else { $wrap[$key] = ''; } } } if (empty($table->width)) { $table->width = '80%'; } if (empty($table->cellpadding)) { $table->cellpadding = '5'; } if (empty($table->cellspacing)) { $table->cellspacing = '1'; } print_simple_box_start('center', $table->width, '#ffffff', 0); echo 'cellpadding\" cellspacing=\"$table->cellspacing\" class=\"generaltable\">\n"; $countcols = 0; if (!empty($table->head)) { $countcols = count($table->head);; echo ''; foreach ($table->head as $key => $heading) { if (!isset($size[$key])) { $size[$key] = ''; } if (!isset($align[$key])) { $align[$key] = ''; } echo ''. $heading .''; } echo ''."\n"; } if (!empty($table->data)) { foreach ($table->data as $row) { echo ''; if ($row == 'hr' and $countcols) { echo ''; } else { /// it's a normal row of data foreach ($row as $key => $item) { if (!isset($size[$key])) { $size[$key] = ''; } if (!isset($align[$key])) { $align[$key] = ''; } if (!isset($wrap[$key])) { $wrap[$key] = ''; } echo ''. $item .''; } } echo ''."\n"; } } echo ''."\n"; print_simple_box_end(); return true; } /** * Creates a nicely formatted table and returns it. * * @param array $table is an object with several properties. * $table->head - An array of heading names. * $table->align - An array of column alignments * $table->size - An array of column sizes * $table->wrap - An array of "nowrap"s or nothing * $table->data[] - An array of arrays containing the data. * $table->class - A css class name * $table->fontsize - Is the size of all the text * $table->tablealign - Align the whole table * $table->width - A percentage of the page * $table->cellpadding - Padding on each cell * $table->cellspacing - Spacing between cells * * @return string * @todo Finish documenting this function */ function make_table($table) { if (isset($table->align)) { foreach ($table->align as $key => $aa) { if ($aa) { $align[$key] = ' align="'. $aa .'"'; } else { $align[$key] = ''; } } } if (isset($table->size)) { foreach ($table->size as $key => $ss) { if ($ss) { $size[$key] = ' width="'. $ss .'"'; } else { $size[$key] = ''; } } } if (isset($table->wrap)) { foreach ($table->wrap as $key => $ww) { if ($ww) { $wrap[$key] = ' nowrap="nowrap" '; } else { $wrap[$key] = ''; } } } if (empty($table->width)) { $table->width = '80%'; } if (empty($table->tablealign)) { $table->tablealign = 'center'; } if (empty($table->cellpadding)) { $table->cellpadding = '5'; } if (empty($table->cellspacing)) { $table->cellspacing = '1'; } if (empty($table->class)) { $table->class = 'generaltable'; } if (empty($table->fontsize)) { $fontsize = ''; } else { $fontsize = ''; } $output = 'cellpadding .'" cellspacing="'. $table->cellspacing .'" class="'. $table->class .'">'."\n"; if (!empty($table->head)) { $output .= ''; foreach ($table->head as $key => $heading) { if (!isset($size[$key])) { $size[$key] = ''; } if (!isset($align[$key])) { $align[$key] = ''; } $output .= ''.$fontsize.$heading.''; } $output .= ''."\n"; } foreach ($table->data as $row) { $output .= ''; foreach ($row as $key => $item) { if (!isset($size[$key])) { $size[$key] = ''; } if (!isset($align[$key])) { $align[$key] = ''; } if (!isset($wrap[$key])) { $wrap[$key] = ''; } $output .= ''. $fontsize . $item .''; } $output .= ''."\n"; } $output .= ''."\n"; return $output; } /** * Prints a basic textarea field. * * @uses $CFG * @param boolean $usehtmleditor ? * @param int $rows ? * @param int $cols ? * @param null $width Legacy field no longer used! * @param null $height Legacy field no longer used! * @param string $name ? * @param string $value ? * @param int $courseid ? * @todo Finish documenting this function */ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $courseid=0) { /// $width and height are legacy fields and no longer used global $CFG, $course; if (empty($courseid)) { if (!empty($course->id)) { // search for it in global context $courseid = $course->id; } } if ($usehtmleditor) { if (!empty($courseid) and isteacher($courseid)) { echo ''."\n"; } else { echo ''."\n"; } echo ''."\n"; echo ''."\n"; echo ''."\n"; if ($rows < 10) { $rows = 10; } if ($cols < 65) { $cols = 65; } } echo ''; p($value); echo ''."\n"; } /** * Legacy function, provided for backward compatability. * This method now simply calls {@link use_html_editor()} * * @deprecated Use {@link use_html_editor()} instead. * @param string $name Form element to replace with HTMl editor by name * @todo Finish documenting this function */ function print_richedit_javascript($form, $name, $source='no') { use_html_editor($name); } /** * Sets up the HTML editor on textareas in the current page. * If a field name is provided, then it will only be * applied to that field - otherwise it will be used * on every textarea in the page. * * In most cases no arguments need to be supplied * * @param string $name Form element to replace with HTMl editor by name */ function use_html_editor($name='') { echo ''."\n"; } /** * 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 * * @uses $CFG * @uses $USER * @param int $courseid The course to update by id as found in 'course' table * @return string */ function update_course_icon($courseid) { global $CFG, $USER; if (isteacheredit($courseid)) { if (!empty($USER->editing)) { $string = get_string('turneditingoff'); $edit = 'off'; } else { $string = get_string('turneditingon'); $edit = 'on'; } return "framename\" method=\"get\" action=\"$CFG->wwwroot/course/view.php\">". "". "". ""; } } /** * Prints the editing button on a module "view" page * * @uses $CFG * @param type description * @todo Finish documenting this function */ function update_module_button($moduleid, $courseid, $string) { global $CFG; if (isteacheredit($courseid)) { $string = get_string('updatethis', '', $string); return "framename\" method=\"get\" action=\"$CFG->wwwroot/course/mod.php\">". "". "". ""; } else { return ''; } } /** * Prints the editing button on a category page * * @uses $CFG * @uses $USER * @param int $categoryid ? * @return string * @todo Finish documenting this function */ function update_category_button($categoryid) { global $CFG, $USER; if (iscreator()) { if (!empty($USER->categoryediting)) { $string = get_string('turneditingoff'); $edit = 'off'; } else { $string = get_string('turneditingon'); $edit = 'on'; } return "framename\" method=\"get\" action=\"$CFG->wwwroot/course/category.php\">". "". "". ""; } } /** * Prints the editing button on categories listing * * @uses $CFG * @uses $USER * @return string */ function update_categories_button() { global $CFG, $USER; if (isadmin()) { if (!empty($USER->categoriesediting)) { $string = get_string('turneditingoff'); $edit = 'off'; } else { $string = get_string('turneditingon'); $edit = 'on'; } return "framename\" method=\"get\" action=\"$CFG->wwwroot/course/index.php\">". ''. ''; } } /** * Prints the editing button on group page * * @uses $CFG * @uses $USER * @param int $courseid The course group is associated with * @param int $groupid The group to update * @return string */ function update_group_button($courseid, $groupid) { global $CFG, $USER; if (isteacheredit($courseid)) { $string = get_string('editgroupprofile'); return "framename\" method=\"get\" action=\"$CFG->wwwroot/course/group.php\">". ''. ''. ''. ''; } } /** * Prints the editing button on groups page * * @uses $CFG * @uses $USER * @param int $courseid The id of the course to be edited * @return string * @todo Finish documenting this function */ function update_groups_button($courseid) { global $CFG, $USER; if (isteacheredit($courseid)) { if (!empty($USER->groupsediting)) { $string = get_string('turneditingoff'); $edit = 'off'; } else { $string = get_string('turneditingon'); $edit = 'on'; } return "framename\" method=\"get\" action=\"$CFG->wwwroot/course/groups.php\">". "". "". ""; } } /** * Prints an appropriate group selection menu * * @uses VISIBLEGROUPS * @param array $groups ? * @param int $groupmode ? * @param string $currentgroup ? * @param string $urlroot ? * @todo Finish documenting this function */ function print_group_menu($groups, $groupmode, $currentgroup, $urlroot) { /// Add an "All groups" to the start of the menu $groupsmenu[0] = get_string('allparticipants'); foreach ($groups as $key => $groupname) { $groupsmenu[$key] = $groupname; } echo ''; if ($groupmode == VISIBLEGROUPS) { print_string('groupsvisible'); } else { print_string('groupsseparate'); } echo ':'; echo ''; popup_form($urlroot.'&group=', $groupsmenu, 'selectgroup', $currentgroup, '', '', '', false, 'self'); echo ''; } /** * 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 * * @param course $course A {@link $COURSE} object. * @param course $cm A {@link $COURSE} object. * @param string $targetwindow ? * @return string * @todo Finish documenting this function */ function navmenu($course, $cm=NULL, $targetwindow='self') { global $CFG; if ($cm) { $cm = $cm->id; } if ($course->format == 'weeks') { $strsection = get_string('week'); } else { $strsection = get_string('topic'); } if (!$modinfo = unserialize($course->modinfo)) { return ''; } $isteacher = isteacher($course->id); $section = -1; $selected = ''; $url = ''; $previousmod = NULL; $backmod = NULL; $nextmod = NULL; $selectmod = NULL; $logslink = NULL; $flag = false; $menu = array(); $strjumpto = get_string('jumpto'); $sections = get_records('course_sections','course',$course->id,'section','section,visible,summary'); foreach ($modinfo as $mod) { if ($mod->mod == 'label') { continue; } if ($mod->section > 0 and $section <> $mod->section) { $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)) { $menu[] = '-------------- '. $strsection ." ". $mod->section .' --------------'; } else { if (strlen($thissection->summary) < 47) { $menu[] = '-- '.$thissection->summary; } else { $menu[] = '-- '.substr($thissection->summary, 0, 50).'...'; } } } } $section = $mod->section; //Only add visible or teacher mods to jumpmenu if ($mod->visible or $isteacher) { $url = $mod->mod .'/view.php?id='. $mod->cm; if ($flag) { // the current mod is the "next" mod $nextmod = $mod; $flag = false; } if ($cm == $mod->cm) { $selected = $url; $selectmod = $mod; $backmod = $previousmod; $flag = true; // set flag so we know to use next mod for "next" $mod->name = $strjumpto; $strjumpto = ''; } else { $mod->name = strip_tags(urldecode($mod->name)); if (strlen($mod->name) > 55) { $mod->name = substr($mod->name, 0, 50).'...'; } if (!$mod->visible) { $mod->name = '('.$mod->name.')'; } } $menu[$url] = $mod->name; $previousmod = $mod; } } if ($selectmod and $isteacher) { $logslink = "framename\" href=". "\"$CFG->wwwroot/course/log.php?chooselog=1&user=0&date=0&id=$course->id&modid=$selectmod->cm\">". "pixpath/i/log.gif\" alt=\"\" />"; } if ($backmod) { $backmod = "wwwroot/mod/$backmod->mod/view.php\" target=\"$CFG->framename\">". "cm\" />". ""; } if ($nextmod) { $nextmod = "wwwroot/mod/$nextmod->mod/view.php\" target=\"$CFG->framename\">". "cm\" />". ""; } return ''.$logslink .''. $backmod .'' . popup_form($CFG->wwwroot .'/mod/', $menu, 'navmenu', $selected, $strjumpto, '', '', true, $targetwindow). ''. $nextmod .''; } /** * Prints form items with the names $day, $month and $year * * @param int $day ? * @param int $month ? * @param int $year ? * @param int $currenttime A default timestamp in GMT * @todo Finish documenting this function */ function print_date_selector($day, $month, $year, $currenttime=0) { if (!$currenttime) { $currenttime = time(); } $currentdate = usergetdate($currenttime); for ($i=1; $i<=31; $i++) { $days[$i] = $i; } for ($i=1; $i<=12; $i++) { $months[$i] = userdate(gmmktime(12,0,0,$i,1,2000), "%B"); } for ($i=2000; $i<=2010; $i++) { $years[$i] = $i; } choose_from_menu($days, $day, $currentdate['mday'], ''); choose_from_menu($months, $month, $currentdate['mon'], ''); choose_from_menu($years, $year, $currentdate['year'], ''); } /** *Prints form items with the names $hour and $minute * * @param ? $hour ? * @param ? $minute ? * @param $currenttime A default timestamp in GMT * @param int $step ? * @todo Finish documenting this function */ function print_time_selector($hour, $minute, $currenttime=0, $step=5) { if (!$currenttime) { $currenttime = time(); } $currentdate = usergetdate($currenttime); if ($step != 1) { $currentdate['minutes'] = ceil($currentdate['minutes']/$step)*$step; } for ($i=0; $i<=23; $i++) { $hours[$i] = sprintf("%02d",$i); } for ($i=0; $i<=59; $i+=$step) { $minutes[$i] = sprintf("%02d",$i); } choose_from_menu($hours, $hour, $currentdate['hours'], ''); choose_from_menu($minutes, $minute, $currentdate['minutes'], ''); } /** * Prints time limit value selector * * @uses $CFG * @param int $timelimit ? * @param string $unit ? * @todo Finish documenting this function */ function print_timer_selector($timelimit = 0, $unit = '') { global $CFG; if ($unit) { $unit = ' '.$unit; } // Max timelimit is sessiontimeout - 10 minutes. $maxvalue = ($CFG->sessiontimeout / 60) - 10; for ($i=1; $i<=$maxvalue; $i++) { $minutes[$i] = $i.$unit; } choose_from_menu($minutes, 'timelimit', $timelimit, get_string('none')); } /** * Prints a grade menu (as part of an existing form) with help * Showing all possible numerical grades and scales * * @uses $CFG * @param int $courseid ? * @param string $name ? * @param string $current ? * @param boolean $includenograde ? * @todo Finish documenting this function */ function print_grade_menu($courseid, $name, $current, $includenograde=true) { global $CFG; $strscale = get_string('scale'); $strscales = get_string('scales'); $scales = get_scales_menu($courseid); foreach ($scales as $i => $scalename) { $grades[-$i] = $strscale .': '. $scalename; } if ($includenograde) { $grades[0] = get_string('nograde'); } for ($i=100; $i>=1; $i--) { $grades[$i] = $i; } choose_from_menu($grades, $name, $current, ''); $helpicon = $CFG->pixpath .'/help.gif'; $linkobject = ""; link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true', 'ratingscales', $linkobject, 400, 500, $strscales); } /** * 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) { global $CFG; $strscales = get_string('scales'); choose_from_menu(get_scales_menu($courseid), $name, $current, ''); $helpicon = $CFG->pixpath .'/help.gif'; $linkobject = ''; link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true', 'ratingscales', $linkobject, 400, 500, $strscales); } /** * 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) { global $CFG; $strscales = get_string('scales'); $helpicon = $CFG->pixpath .'/help.gif'; $linkobject = "name\" src=\"$helpicon\" />"; link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true&scale='. $scale->id, 'ratingscale', $linkobject, 400, 500, $scale->name); } /** * Print an error page displaying an error message. * * @uses $SESSION * @uses $CFG * @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. */ function error ($message, $link='') { global $CFG, $SESSION; print_header(get_string('error')); echo ''; $message = clean_text($message); // In case nasties are in here print_simple_box($message, 'center', '', '#FFBBBB'); if (!$link) { if ( !empty($SESSION->fromurl) ) { $link = $SESSION->fromurl; unset($SESSION->fromurl); } else { $link = $CFG->wwwroot .'/'; } } print_continue($link); print_footer(); die; } /** * Print a help button. * * @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 * @todo Finish documenting this function */ function helpbutton ($page, $title='', $module='moodle', $image=true, $linktext=false, $text='', $return=false) { global $CFG, $THEME; if ($module == '') { $module = 'moodle'; } if ($image) { $icon = $CFG->pixpath .'/help.gif'; if ($linktext) { $linkobject = "$title"; } else { $linkobject = ""; } } else { $linkobject = ''. $title .''; } if ($text) { $url = '/help.php?module='. $module .'&text='. htmlentities(urlencode($text)); } else { $url = '/help.php?module='. $module .'&file='. $page .'.html'; } $link = link_to_popup_window ($url, 'popup', $linkobject, 400, 500, $title, '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) { global $CFG, $SESSION; $SESSION->inserttextform = $form; $SESSION->inserttextfield = $field; helpbutton('emoticons', get_string('helpemoticons'), 'moodle', false, true); echo ' '; link_to_popup_window ('/help.php?module=moodle&file=emoticons.html', 'popup', '', 400, 500, get_string('helpemoticons')); echo ''; } /** * Print a message and exit. * * @uses $CFG * @uses $THEME * @param string $message ? * @param string $link ? * @todo Finish documenting this function */ function notice ($message, $link='') { global $CFG, $THEME; $message = clean_text($message); $link = clean_text($link); if (!$link) { if (!empty($_SERVER['HTTP_REFERER'])) { $link = $_SERVER['HTTP_REFERER']; } else { $link = $CFG->wwwroot .'/'; } } echo ''; print_simple_box($message, 'center', '50%', $THEME->cellheading, '20', 'noticebox'); print_heading(''. get_string('continue') .''); print_footer(get_site()); die; } /** * Print a message along with "Yes" and "No" links for the user to continue. * * @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" */ function notice_yesno ($message, $linkyes, $linkno) { global $THEME; $message = clean_text($message); $linkyes = clean_text($linkyes); $linkno = clean_text($linkno); print_simple_box_start('center', '60%', $THEME->cellheading); echo ''. $message .''; echo ''; echo ''. get_string('yes') .''; echo ' '; echo ''. get_string('no') .''; echo ''; print_simple_box_end(); } /** * Redirects the user to another page, after printing a notice * * @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 ""; */ function redirect($url, $message='', $delay='0') { $url = clean_text($url); $message = clean_text($message); $url = html_entity_decode($url); // for php < 4.3.0 this is defined in moodlelib.php $encodedurl = htmlentities($url); if (empty($message)) { echo ''; echo ''; // To cope with Mozilla bug } else { if (empty($delay)) { $delay = 3; // There's no point having a message with no delay } print_header('', '', '', '', ''); echo ''; echo ''. $message .''; echo '( '. get_string('continue') .' )'; echo ''; flush(); sleep($delay); echo ''; // To cope with Mozilla bug } die; } /** * Print a bold message in an optional color. * * @param string $message The message to print out * @param string $color Optional color to display message text in * @param string $align Paragraph alignment option */ function notify ($message, $color='red', $align='center') { $message = clean_text($message); echo ''. $message .'' . "\n"; } /** * Given an email address, this function will return an obfuscated version of it * * @param string $email The email address to obfuscate * @return string */ function obfuscate_email($email) { $i = 0; $length = strlen($email); $obfuscated = ''; while ($i < $length) { if (rand(0,2)) { $obfuscated.='%'.dechex(ord($email{$i})); } else { $obfuscated.=$email{$i}; } $i++; } return $obfuscated; } /** * This function takes some text and replaces about half of the characters * with HTML entity equivalents. Return string is obviously longer. * * @param string $plaintext The text to be obfuscated * @return string */ function obfuscate_text($plaintext) { $i=0; $length = strlen($plaintext); $obfuscated=''; $prev_obfuscated = false; while ($i < $length) { $c = ord($plaintext{$i}); $numerical = ($c >= ord('0')) && ($c <= ord('9')); if ($prev_obfuscated and $numerical ) { $obfuscated.=''.ord($plaintext{$i}).';'; } else if (rand(0,2)) { $obfuscated.=''.ord($plaintext{$i}).';'; $prev_obfuscated = true; } else { $obfuscated.=$plaintext{$i}; $prev_obfuscated = false; } $i++; } return $obfuscated; } /** * This function uses the {@link obfuscate_email()} and {@link obfuscate_text()} * to generate a fully obfuscated email link, ready to use. * * @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 */ function obfuscate_mailto($email, $label='', $dimmed=false) { if (empty($label)) { $label = $email; } if ($dimmed) { $title = get_string('emaildisable'); $dimmed = ' class="dimmed"'; } else { $title = ''; $dimmed = ''; } return sprintf("%s", obfuscate_text('mailto'), obfuscate_email($email), obfuscate_text($label)); } /** * Prints a single paging bar to provide access to other pages (usually in a search) * * @param int $totalcount ? * @param int $page ? * @param int $perpage ? * @param string $baseurl ? * @todo Finish documenting this function */ function print_paging_bar($totalcount, $page, $perpage, $baseurl) { $maxdisplay = 18; if ($totalcount > $perpage) { echo ''; echo ''.get_string('page').':'; if ($page > 0) { $pagenum=$page-1; echo ' ('. get_string('previous') .') '; } $lastpage = ceil($totalcount / $perpage); if ($page > 15) { $startpage = $page - 10; echo ' 1 ...'; } else { $startpage = 0; } $currpage = $startpage; $displaycount = 0; while ($displaycount < $maxdisplay and $currpage < $lastpage) { $displaypage = $currpage+1; if ($page == $currpage) { echo ' '. $displaypage; } else { echo ' '. $displaypage .''; } $displaycount++; $currpage++; } if ($currpage < $lastpage) { $lastpageactual = $lastpage - 1; echo ' ...'. $lastpage .' '; } $pagenum = $page + 1; if ($pagenum != $displaypage) { echo ' ('. get_string('next') .')'; } echo ''; echo ''; } } /** * This function is used to rebuild the tag because some formats (PLAIN and WIKI) * will transform it to html entities * * @param string $text Text to search for nolink tag in * @return string */ function rebuildnolinktag($text) { $text = preg_replace('/<(\/*nolink)>/i','<$1>',$text); return $text; } // ================================================ // THREE FUNCTIONS MOVED HERE FROM course/lib.php // ================================================ /** * 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. * * @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. */ function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array()) { global $THEME; print_side_block_start($heading, $attributes); if ($content) { echo $content; if ($footer) { echo ''. $footer .''; } } else { echo ''; if ($list) { foreach ($list as $key => $string) { echo ''; if ($icons) { echo ''. $icons[$key] .''; } echo ''. $string .''; echo ''; } } if ($footer) { echo ''; echo ''; echo ''. $footer .''; echo ''; } echo ''; } print_side_block_end(); } /** * Starts a nice side block with an optional header. * * @uses $THEME * @param string $heading ? * @param array $attributes ? * @todo Finish documenting this function */ 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 ''; if ($heading) { echo ''.$heading.''; } echo ''; } /** * Print table ending tags for a side block box. */ function print_side_block_end() { echo ''; echo "\n"; } /** * Prints out the HTML editor config. * * @uses $CFG */ function print_editor_config() { global $CFG; // print new config echo 'var config = new HTMLArea.Config();'."\n"; 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 = "; echo(empty($CFG->editorkillword)) ? "false":"true"; echo ';'."\n"; echo 'config.fontname = {'."\n"; $fontlist = isset($CFG->editorfontlist) ? explode(';', $CFG->editorfontlist) : array(); $i = 1; // Counter is used to get rid of the last comma. $count = count($fontlist); // Otherwise IE doesn't load the editor. foreach($fontlist as $fontline) { if(!empty($fontline)) { list($fontkey, $fontvalue) = split(':', $fontline); echo '"'. $fontkey ."\":\t'". $fontvalue ."'"; if($i < $count) { echo ','."\n"; } } $i++; } echo '};'; if(!empty($CFG->editorspelling) && !empty($CFG->aspellpath)) { print_speller_code($usehtmleditor=true); } } /** * Prints out code needed for spellchecking. * Original idea by Ludo (Marc Alier). * * @uses $CFG * @param boolean $usehtmleditor ? * @todo Finish documenting this function */ function print_speller_code ($usehtmleditor=false) { global $CFG; if(!$usehtmleditor) { echo "\n".''."\n"; } 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"; echo '}'."\n"; } } /** * Print button for spellchecking when editor is disabled */ function print_speller_button () { echo ''."\n"; } // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140: ?>
'. stripslashes_safe($text) .'
'. $icon .''. stripslashes_safe($text); helpbutton($helppage, $text, $module); echo '
'; if (!empty($user->role) and ($user->role <> $course->teacher)) { echo $string->role .': '. $user->role .''; } if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category and !isguest()) or $isteacher) { echo $string->email .': '. $user->email .''; } if ($user->city or $user->country) { echo $string->location .': '; if ($user->city) { echo $user->city; } if (!empty($countries[$user->country])) { if ($user->city) { echo ', '; } echo $countries[$user->country]; } echo ''; } if ($user->lastaccess) { echo $string->lastaccess .': '. userdate($user->lastaccess); echo '  ('. format_time(time() - $user->lastaccess, $datestring) .')'; } else { echo $string->lastaccess .': '. $string->never; } echo '
'. $message .'
'; echo ''. get_string('yes') .''; echo ' '; echo ''. get_string('no') .''; echo '
( '. get_string('continue') .' )
'.get_string('page').':'; if ($page > 0) { $pagenum=$page-1; echo ' ('. get_string('previous') .') '; } $lastpage = ceil($totalcount / $perpage); if ($page > 15) { $startpage = $page - 10; echo ' 1 ...'; } else { $startpage = 0; } $currpage = $startpage; $displaycount = 0; while ($displaycount < $maxdisplay and $currpage < $lastpage) { $displaypage = $currpage+1; if ($page == $currpage) { echo ' '. $displaypage; } else { echo ' '. $displaypage .''; } $displaycount++; $currpage++; } if ($currpage < $lastpage) { $lastpageactual = $lastpage - 1; echo ' ...'. $lastpage .' '; } $pagenum = $page + 1; if ($pagenum != $displaypage) { echo ' ('. get_string('next') .')'; } echo '