fix course reset unenrollment in to work with roles MDL-7069 ; merged from MOODLE_17_...
[moodle.git] / lib / ajax / ajaxlib.php
CommitLineData
4488daf7 1<?php // Library functions for using AJAX with Moodle
9bb74178 2
3/**
8b8a8779 4 * Print require statements for javascript libraries.
5 * Takes in an array of either full paths or shortnames and it will translate
6 * them to full paths.
9bb74178 7 **/
9bb74178 8function print_require_js($list) {
9 global $CFG;
01059829 10/*
4fc45e1d 11 if (!check_browser_version('MSIE', 6.0) && !check_browser_version('Firefox', '1.5')) {
12 // We still have issues with YUI in other browsers.
13 return;
14 }
01059829 15*/
9bb74178 16 //list of shortname to filepath translations
17 $translatelist = array(
18 'yui_yahoo' => '/lib/yui/yahoo/yahoo.js',
19 'yui_dom' => '/lib/yui/dom/dom.js',
20 'yui_event' => '/lib/yui/event/event.js',
21 'yui_dragdrop' => '/lib/yui/dragdrop/dragdrop.js',
22 'yui_logger' => '/lib/yui/logger/logger.js',
23 'yui_connection' => '/lib/yui/connection/connection.js',
3e1e2b69 24 'ajaxcourse_blocks' => '/lib/ajax/block_classes.js',
25 'ajaxcourse_sections' => '/lib/ajax/section_classes.js',
9bb74178 26 'ajaxcourse' => '/lib/ajax/ajaxcourse.js'
27 );
28
29
35b974da 30 for ($i=0; $i<count($list); $i++) {
9bb74178 31 if ($translatelist[$list[$i]]) {
35b974da 32 echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist[$list[$i]]."'></script>\n";
9bb74178 33 } else {
35b974da 34 echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$list[$i]."'></script>\n";
9bb74178 35 }
36 }
01059829 37
8b8a8779 38 if (debugging('', DEBUG_DEVELOPER)) {
39 echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist['yui_logger']."'></script>\n";
40
41 // Dependencies for the logger.
42 echo "<link type='text/css' rel='stylesheet' href='{$CFG->wwwroot}/lib/yui/logger/assets/logger.css'>";
43
44 // FIXME: Below might get included more than once.
45 echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist['yui_yahoo']."'></script>\n";
46 echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist['yui_dom']."'></script>\n";
47 echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist['yui_event']."'></script>\n";
48 echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist['yui_dragdrop']."'></script>\n";
49 ?>
50 <script type="text/javascript">
8b8a8779 51
01059829 52 function showLogger() {
53 var logcontainer = null;
fc2e40e3 54
01059829 55 var logconfig = {
56 left: "60%",
57 top: "40px"
58 };
59 var logreader = new YAHOO.widget.LogReader(logcontainer, logconfig);
60
61 logreader.newestOnTop = false;
62 logreader.setTitle('Moodle Debug: YUI Log Console');
63 }
64
65 setTimeout(showLogger, 1); // IE does not allow changing HTML
66 // tables via DOM until they are
67 // fully rendered.
8b8a8779 68 </script>
69 <?php
70 }
01059829 71
9bb74178 72}
73
35b974da 74
75/**
76 * Used to create view of document to be passed to javascript on pageload.
77 */
4fc45e1d 78class jsportal {
9bb74178 79
0a0bb380 80 var $currentblocksection = null;
9bb74178 81 var $blocks = array();
d4df8fdc 82 var $blocksoutput = '';
83 var $output = '';
0a0bb380 84
9bb74178 85
35b974da 86 /**
87 * Takes id of block and adds it
88 */
4fc45e1d 89 function block_add($id, $hidden=false ){
0a0bb380 90 $hidden_binary = 0;
9bb74178 91
92 if ($hidden) {
93 $hidden_binary = 1;
94 }
35b974da 95 $this->blocks[count($this->blocks)] = array($this->currentblocksection, $id, $hidden_binary);
0a0bb380 96 }
9bb74178 97
98
4fc45e1d 99 function print_javascript($id) {
9bb74178 100 global $CFG;
101
d4df8fdc 102 $blocksoutput = $output = '';
35b974da 103 for ($i=0; $i<count($this->blocks); $i++) {
104 $blocksoutput .= "['".$this->blocks[$i][0]."','".$this->blocks[$i][1]."','".$this->blocks[$i][2]."']";
9bb74178 105 if ($i != (count($this->blocks)-1)) {
35b974da 106 $blocksoutput .= ',';
9bb74178 107 }
108 }
109
35b974da 110 $output .= "<script language='javascript'>\n";
111 $output .= " main.portal.id = ".$id.";\n";
4fc45e1d 112 $output .= " main.portal.blocks = new Array(".$blocksoutput.");\n";
113 $output .= " main.portal.strings['wwwroot']='".$CFG->wwwroot."';\n";
114 $output .= " main.portal.strings['update']='".get_string('update')."';\n";
115 $output .= " main.portal.strings['deletecheck']='".get_string('deletecheck','','_var_')."';\n";
116 $output .= " main.portal.strings['resource']='".get_string('resource')."';\n";
117 $output .= " main.portal.strings['activity']='".get_string('activity')."';\n";
118 $output .= " onload.load();\n";
119 $output .= " main.process_blocks();\n";
35b974da 120 $output .= "</script>";
0a0bb380 121 echo $output;
122 }
9bb74178 123}
124
479eea41 125?>