Use AJAX for weekly formats too. HOWEVER, there are some remaining
[moodle.git] / lib / ajax / ajaxlib.php
CommitLineData
9bb74178 1<?php // Library functions for using AJAX with Moodle
2
3/**
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
6 **/
7
8function print_require_js($list) {
9 global $CFG;
10
11 //list of shortname to filepath translations
12 $translatelist = array(
13 'yui_yahoo' => '/lib/yui/yahoo/yahoo.js',
14 'yui_dom' => '/lib/yui/dom/dom.js',
15 'yui_event' => '/lib/yui/event/event.js',
16 'yui_dragdrop' => '/lib/yui/dragdrop/dragdrop.js',
17 'yui_logger' => '/lib/yui/logger/logger.js',
18 'yui_connection' => '/lib/yui/connection/connection.js',
19 'ajaxcourse_blocks' => '/lib/ajax/block_classes.php',
20 'ajaxcourse_sections' => '/lib/ajax/section_classes.php',
21 'ajaxcourse' => '/lib/ajax/ajaxcourse.js'
22 );
23
24
25 for ($i=0;$i<count($list);$i++) {
26 if ($translatelist[$list[$i]]) {
27 echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist[$list[$i]]."'></script>\n\r";
28 } else {
29 echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$list[$i]."'></script>\n\r";
30 }
31 }
32}
33
34//used to create view of document to be passed to javascript on pageload
35class jsportal{
36
0a0bb380 37 var $currentblocksection = null;
9bb74178 38 var $blocks = array();
d4df8fdc 39 var $blocksoutput = '';
40 var $output = '';
0a0bb380 41
9bb74178 42
0a0bb380 43 //takes id of block and adds it
44 function block_add($id,$hidden=false){
45 $hidden_binary = 0;
9bb74178 46
47 if ($hidden) {
48 $hidden_binary = 1;
49 }
50
51 $this->blocks[count($this->blocks)] = array($this->currentblocksection,$id,$hidden_binary);
0a0bb380 52 }
9bb74178 53
54
d4df8fdc 55 function print_javascript($id){
9bb74178 56 global $CFG;
57
d4df8fdc 58 $blocksoutput = $output = '';
9bb74178 59 for ($i=0;$i<count($this->blocks);$i++) {
0a0bb380 60 $blocksoutput.="['".$this->blocks[$i][0]."','".$this->blocks[$i][1]."','".$this->blocks[$i][2]."']";
9bb74178 61 if ($i != (count($this->blocks)-1)) {
0a0bb380 62 $blocksoutput.=",";
9bb74178 63 }
64 }
65
d4df8fdc 66 $output .="<script language='javascript'>\r";
e78a3505 67 $output .=" main.portal.id = ".$id."\r";
d4df8fdc 68 $output .=" main.portal.blocks = new Array(".$blocksoutput.");\r";
e78a3505 69 $output .=" main.portal.strings['wwwroot']='".$CFG->wwwroot."';\r";
70 $output .=" main.portal.strings['update']='".get_string('update')."';\r";
d4df8fdc 71 $output .=" onload.load()\r";
9bb74178 72 $output .=" main.process_blocks();\r";
0a0bb380 73 $output .="</script>";
0a0bb380 74 echo $output;
75 }
9bb74178 76}
77
b2174cc8 78?>