merged fix for MDL-7055 - prohibts at site level not working
[moodle.git] / lib / ajax / ajaxlib.php
CommitLineData
4488daf7 1<?php // Library functions for using AJAX with Moodle
9bb74178 2
3/**
35b974da 4 * Print require statements for javascript libraries
5 * Takes in an array of either full paths or shortnames and it will translate them to full paths
9bb74178 6 **/
9bb74178 7function print_require_js($list) {
8 global $CFG;
9
4fc45e1d 10 if (!check_browser_version('MSIE', 6.0) && !check_browser_version('Firefox', '1.5')) {
11 // We still have issues with YUI in other browsers.
12 return;
13 }
14
9bb74178 15 //list of shortname to filepath translations
16 $translatelist = array(
17 'yui_yahoo' => '/lib/yui/yahoo/yahoo.js',
18 'yui_dom' => '/lib/yui/dom/dom.js',
19 'yui_event' => '/lib/yui/event/event.js',
20 'yui_dragdrop' => '/lib/yui/dragdrop/dragdrop.js',
21 'yui_logger' => '/lib/yui/logger/logger.js',
22 'yui_connection' => '/lib/yui/connection/connection.js',
3e1e2b69 23 'ajaxcourse_blocks' => '/lib/ajax/block_classes.js',
24 'ajaxcourse_sections' => '/lib/ajax/section_classes.js',
9bb74178 25 'ajaxcourse' => '/lib/ajax/ajaxcourse.js'
26 );
27
28
35b974da 29 for ($i=0; $i<count($list); $i++) {
9bb74178 30 if ($translatelist[$list[$i]]) {
35b974da 31 echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist[$list[$i]]."'></script>\n";
9bb74178 32 } else {
35b974da 33 echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$list[$i]."'></script>\n";
9bb74178 34 }
35 }
36}
37
35b974da 38
39/**
40 * Used to create view of document to be passed to javascript on pageload.
41 */
4fc45e1d 42class jsportal {
9bb74178 43
0a0bb380 44 var $currentblocksection = null;
9bb74178 45 var $blocks = array();
d4df8fdc 46 var $blocksoutput = '';
47 var $output = '';
0a0bb380 48
9bb74178 49
35b974da 50 /**
51 * Takes id of block and adds it
52 */
4fc45e1d 53 function block_add($id, $hidden=false ){
0a0bb380 54 $hidden_binary = 0;
9bb74178 55
56 if ($hidden) {
57 $hidden_binary = 1;
58 }
35b974da 59 $this->blocks[count($this->blocks)] = array($this->currentblocksection, $id, $hidden_binary);
0a0bb380 60 }
9bb74178 61
62
4fc45e1d 63 function print_javascript($id) {
9bb74178 64 global $CFG;
65
d4df8fdc 66 $blocksoutput = $output = '';
35b974da 67 for ($i=0; $i<count($this->blocks); $i++) {
68 $blocksoutput .= "['".$this->blocks[$i][0]."','".$this->blocks[$i][1]."','".$this->blocks[$i][2]."']";
9bb74178 69 if ($i != (count($this->blocks)-1)) {
35b974da 70 $blocksoutput .= ',';
9bb74178 71 }
72 }
73
35b974da 74 $output .= "<script language='javascript'>\n";
75 $output .= " main.portal.id = ".$id.";\n";
4fc45e1d 76 $output .= " main.portal.blocks = new Array(".$blocksoutput.");\n";
77 $output .= " main.portal.strings['wwwroot']='".$CFG->wwwroot."';\n";
78 $output .= " main.portal.strings['update']='".get_string('update')."';\n";
79 $output .= " main.portal.strings['deletecheck']='".get_string('deletecheck','','_var_')."';\n";
80 $output .= " main.portal.strings['resource']='".get_string('resource')."';\n";
81 $output .= " main.portal.strings['activity']='".get_string('activity')."';\n";
82 $output .= " onload.load();\n";
83 $output .= " main.process_blocks();\n";
35b974da 84 $output .= "</script>";
0a0bb380 85 echo $output;
86 }
9bb74178 87}
88
479eea41 89?>