2006-09-25 14:59:21 +00:00
|
|
|
<?php // Library functions for using AJAX with Moodle
|
2006-09-23 14:03:48 +00:00
|
|
|
|
|
|
|
/**
|
2006-10-18 07:05:21 +00:00
|
|
|
* Print require statements for javascript libraries.
|
|
|
|
* Takes in an array of either full paths or shortnames and it will translate
|
|
|
|
* them to full paths.
|
2006-09-23 14:03:48 +00:00
|
|
|
**/
|
2006-10-24 08:11:38 +00:00
|
|
|
function require_js($list) {
|
2006-09-23 14:03:48 +00:00
|
|
|
global $CFG;
|
2006-10-24 08:11:38 +00:00
|
|
|
$output = '';
|
2006-10-18 09:47:44 +00:00
|
|
|
|
|
|
|
if (!check_browser_version('MSIE', 6.0) && !check_browser_version('Firefox', 1.5)) {
|
2006-10-17 05:33:18 +00:00
|
|
|
// We still have issues with YUI in other browsers.
|
|
|
|
return;
|
|
|
|
}
|
2006-10-18 09:47:44 +00:00
|
|
|
|
2006-09-23 14:03:48 +00:00
|
|
|
//list of shortname to filepath translations
|
|
|
|
$translatelist = array(
|
|
|
|
'yui_yahoo' => '/lib/yui/yahoo/yahoo.js',
|
|
|
|
'yui_dom' => '/lib/yui/dom/dom.js',
|
|
|
|
'yui_event' => '/lib/yui/event/event.js',
|
|
|
|
'yui_dragdrop' => '/lib/yui/dragdrop/dragdrop.js',
|
|
|
|
'yui_logger' => '/lib/yui/logger/logger.js',
|
|
|
|
'yui_connection' => '/lib/yui/connection/connection.js',
|
2006-09-23 15:11:37 +00:00
|
|
|
'ajaxcourse_blocks' => '/lib/ajax/block_classes.js',
|
|
|
|
'ajaxcourse_sections' => '/lib/ajax/section_classes.js',
|
2006-09-23 14:03:48 +00:00
|
|
|
'ajaxcourse' => '/lib/ajax/ajaxcourse.js'
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2006-10-05 08:47:13 +00:00
|
|
|
for ($i=0; $i<count($list); $i++) {
|
2006-09-23 14:03:48 +00:00
|
|
|
if ($translatelist[$list[$i]]) {
|
2006-10-24 08:11:38 +00:00
|
|
|
$output .= "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist[$list[$i]]."'></script>\n";
|
|
|
|
if ($translatelist[$list[$i]] == '/lib/yui/logger/logger.js') {
|
|
|
|
// Special case. We need the css.
|
|
|
|
$output .= "<link type='text/css' rel='stylesheet' href='{$CFG->wwwroot}/lib/yui/logger/assets/logger.css'>";
|
|
|
|
}
|
2006-09-23 14:03:48 +00:00
|
|
|
} else {
|
2006-10-24 08:11:38 +00:00
|
|
|
$output .= "<script type='text/javascript' src='".$CFG->wwwroot.''.$list[$i]."'></script>\n";
|
2006-09-23 14:03:48 +00:00
|
|
|
}
|
|
|
|
}
|
2006-10-24 08:11:38 +00:00
|
|
|
return $output;
|
2006-09-23 14:03:48 +00:00
|
|
|
}
|
|
|
|
|
2006-10-05 08:47:13 +00:00
|
|
|
|
|
|
|
/**
|
2006-10-24 08:11:38 +00:00
|
|
|
* Used to create view of document to be passed to JavaScript on pageload.
|
|
|
|
* We use this class to pass data from PHP to JavaScript.
|
2006-10-05 08:47:13 +00:00
|
|
|
*/
|
2006-10-17 05:33:18 +00:00
|
|
|
class jsportal {
|
2006-09-23 14:03:48 +00:00
|
|
|
|
2006-08-24 03:20:37 +00:00
|
|
|
var $currentblocksection = null;
|
2006-09-23 14:03:48 +00:00
|
|
|
var $blocks = array();
|
2006-08-24 03:20:37 +00:00
|
|
|
|
2006-09-23 14:03:48 +00:00
|
|
|
|
2006-10-05 08:47:13 +00:00
|
|
|
/**
|
|
|
|
* Takes id of block and adds it
|
|
|
|
*/
|
2006-10-24 08:11:38 +00:00
|
|
|
function block_add($id, $hidden=false){
|
2006-08-24 03:20:37 +00:00
|
|
|
$hidden_binary = 0;
|
2006-09-23 14:03:48 +00:00
|
|
|
|
|
|
|
if ($hidden) {
|
|
|
|
$hidden_binary = 1;
|
|
|
|
}
|
2006-10-05 08:47:13 +00:00
|
|
|
$this->blocks[count($this->blocks)] = array($this->currentblocksection, $id, $hidden_binary);
|
2006-08-24 03:20:37 +00:00
|
|
|
}
|
2006-09-23 14:03:48 +00:00
|
|
|
|
|
|
|
|
2006-10-24 08:11:38 +00:00
|
|
|
/**
|
|
|
|
* Prints the JavaScript code needed to set up AJAX for the course.
|
|
|
|
*/
|
|
|
|
function print_javascript($courseid, $return=false) {
|
2006-09-23 14:03:48 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2006-08-28 02:05:02 +00:00
|
|
|
$blocksoutput = $output = '';
|
2006-10-05 08:47:13 +00:00
|
|
|
for ($i=0; $i<count($this->blocks); $i++) {
|
2006-10-24 08:11:38 +00:00
|
|
|
$blocksoutput .= "['".$this->blocks[$i][0]."',
|
|
|
|
'".$this->blocks[$i][1]."',
|
|
|
|
'".$this->blocks[$i][2]."']";
|
|
|
|
|
|
|
|
if ($i != (count($this->blocks) - 1)) {
|
2006-10-05 08:47:13 +00:00
|
|
|
$blocksoutput .= ',';
|
2006-09-23 14:03:48 +00:00
|
|
|
}
|
|
|
|
}
|
2006-10-05 08:47:13 +00:00
|
|
|
$output .= "<script language='javascript'>\n";
|
2006-10-24 08:11:38 +00:00
|
|
|
$output .= " main.portal.id = ".$courseid.";\n";
|
|
|
|
$output .= " main.portal.blocks = new Array(".$blocksoutput.");\n";
|
|
|
|
$output .= " main.portal.strings['wwwroot']='".$CFG->wwwroot."';\n";
|
2006-11-14 03:07:18 +00:00
|
|
|
$output .= " main.portal.strings['pixpath']='".$CFG->pixpath."';\n";
|
2006-10-17 05:33:18 +00:00
|
|
|
$output .= " main.portal.strings['update']='".get_string('update')."';\n";
|
2006-10-24 08:11:38 +00:00
|
|
|
$output .= " main.portal.strings['deletecheck']='".get_string('deletecheck','','_var_')."';\n";
|
|
|
|
$output .= " main.portal.strings['resource']='".get_string('resource')."';\n";
|
|
|
|
$output .= " main.portal.strings['activity']='".get_string('activity')."';\n";
|
|
|
|
$output .= " onloadobj.load();\n";
|
2006-10-17 05:33:18 +00:00
|
|
|
$output .= " main.process_blocks();\n";
|
2006-10-05 08:47:13 +00:00
|
|
|
$output .= "</script>";
|
2006-10-24 08:11:38 +00:00
|
|
|
if ($return) {
|
|
|
|
return $output;
|
|
|
|
} else {
|
|
|
|
echo $output;
|
|
|
|
}
|
2006-08-24 03:20:37 +00:00
|
|
|
}
|
2006-09-23 14:03:48 +00:00
|
|
|
|
2006-10-24 08:11:38 +00:00
|
|
|
}
|
2006-10-30 07:48:02 +00:00
|
|
|
?>
|