"; } 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 '
framename\" href=". "\"$CFG->wwwroot/course/log.php?chooselog=1&user=0&date=0&id=$course->id&modid=$selectmod->cm\">". "pixpath/i/log.gif\" alt=\"\" />
'.$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 = "\"$strscales\""; 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 = ''. $strscales .''; 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 = "\"$scale-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 = "\"$title\""; } } 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 ''; } echo ''; echo ''; } } if ($footer) { echo ''; 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 ''; } echo '
'.$heading.'
'; } /** * 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. foreach($fontlist as $fontline) { if(!empty($fontline)) { if ($i > 1) { echo ','."\n"; } list($fontkey, $fontvalue) = split(':', $fontline); echo '"'. $fontkey ."\":\t'". $fontvalue ."'"; $i++; } } echo '};'; if (!empty($CFG->editorhidebuttons)) { echo "\nconfig.hideSomeButtons(\" ". $CFG->editorhidebuttons ." \");\n"; } 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"; } function page_source_script($page) { global $CFG; switch($page->type) { case MOODLE_PAGE_COURSE: return $CFG->wwwroot.'/course/view.php?id='.$page->id; break; } } // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140: ?>