merged fix for MDL-7066, proper capability check for forum attachments
[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;
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 }
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 }
fc2e40e3 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
fc2e40e3 52 var logcontainer = null;
53
8b8a8779 54 var logconfig = {
55 left: "60%",
fc2e40e3 56 top: "40px"
57 };
8b8a8779 58 var logreader = new YAHOO.widget.LogReader(logcontainer, logconfig);
59 logreader.newestOnTop = false;
60 logreader.setTitle('Moodle Debug: YUI Log Console');
61
62 </script>
63 <?php
64 }
fc2e40e3 65 */
9bb74178 66}
67
35b974da 68
69/**
70 * Used to create view of document to be passed to javascript on pageload.
71 */
4fc45e1d 72class jsportal {
9bb74178 73
0a0bb380 74 var $currentblocksection = null;
9bb74178 75 var $blocks = array();
d4df8fdc 76 var $blocksoutput = '';
77 var $output = '';
0a0bb380 78
9bb74178 79
35b974da 80 /**
81 * Takes id of block and adds it
82 */
4fc45e1d 83 function block_add($id, $hidden=false ){
0a0bb380 84 $hidden_binary = 0;
9bb74178 85
86 if ($hidden) {
87 $hidden_binary = 1;
88 }
35b974da 89 $this->blocks[count($this->blocks)] = array($this->currentblocksection, $id, $hidden_binary);
0a0bb380 90 }
9bb74178 91
92
4fc45e1d 93 function print_javascript($id) {
9bb74178 94 global $CFG;
95
d4df8fdc 96 $blocksoutput = $output = '';
35b974da 97 for ($i=0; $i<count($this->blocks); $i++) {
98 $blocksoutput .= "['".$this->blocks[$i][0]."','".$this->blocks[$i][1]."','".$this->blocks[$i][2]."']";
9bb74178 99 if ($i != (count($this->blocks)-1)) {
35b974da 100 $blocksoutput .= ',';
9bb74178 101 }
102 }
103
35b974da 104 $output .= "<script language='javascript'>\n";
105 $output .= " main.portal.id = ".$id.";\n";
4fc45e1d 106 $output .= " main.portal.blocks = new Array(".$blocksoutput.");\n";
107 $output .= " main.portal.strings['wwwroot']='".$CFG->wwwroot."';\n";
108 $output .= " main.portal.strings['update']='".get_string('update')."';\n";
109 $output .= " main.portal.strings['deletecheck']='".get_string('deletecheck','','_var_')."';\n";
110 $output .= " main.portal.strings['resource']='".get_string('resource')."';\n";
111 $output .= " main.portal.strings['activity']='".get_string('activity')."';\n";
112 $output .= " onload.load();\n";
113 $output .= " main.process_blocks();\n";
35b974da 114 $output .= "</script>";
0a0bb380 115 echo $output;
116 }
9bb74178 117}
118
479eea41 119?>