From 840912d5cfe6161eb11929d4ff02f9ea2e884120 Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Fri, 22 Jan 2010 03:02:09 +0000 Subject: [PATCH] "MDL-21170, rename filepicker to core_filepicker, upgrade filemanager to yui3 module" --- files/files_ajax.php | 19 +- lib/ajax/ajaxlib.php | 9 +- lib/editor/tinymce/extra/tinymce_utils.js | 4 +- lib/form/filemanager.js | 1407 +++++++++------------ lib/form/filemanager.php | 28 +- lib/form/filepicker.js | 4 +- repository/filepicker.js | 63 +- 7 files changed, 685 insertions(+), 849 deletions(-) diff --git a/files/files_ajax.php b/files/files_ajax.php index 334460c7c84..a8f131e1d8e 100755 --- a/files/files_ajax.php +++ b/files/files_ajax.php @@ -77,9 +77,9 @@ case 'delete': $fs = get_file_storage(); $filepath = file_correct_filepath($filepath); $return = new stdclass; - if ($file = $fs->get_file($user_context->id, 'user_draft', $itemid, $filepath, $filename)) { - $parent_path = $file->get_parent_directory()->get_filepath(); - if($result = $file->delete()) { + if ($stored_file = $fs->get_file($user_context->id, 'user_draft', $itemid, $filepath, $filename)) { + $parent_path = $stored_file->get_parent_directory()->get_filepath(); + if($result = $stored_file->delete()) { $return->filepath = $parent_path; echo json_encode($return); } else { @@ -93,11 +93,11 @@ case 'delete': case 'renamedir': $fs = get_file_storage(); $fb = get_file_browser(); - $file = $fb->get_file_info($user_context, 'user_draft', $itemid, $filepath, '.'); - if ($result = $file->delete()) { - $fs->create_directory($user_context->id, 'user_draft', $itemid, file_correct_filepath($newfilename)); - $return = new stdclass; - $return->filepath = file_correct_filepath($newfilename); + $return = new stdclass; + $fileinfo = $fb->get_file_info($user_context, 'user_draft', $itemid, $filepath, '.'); + if ($result = $fileinfo->delete()) { + $newdir = $fs->create_directory($user_context->id, 'user_draft', $itemid, file_correct_filepath($newfilename)); + $return->filepath = $newdir->get_parent_directory()->get_filepath(); echo json_encode($return); } else { echo json_encode(false); @@ -192,6 +192,9 @@ case 'unzip': } break; +case 'upload': + break; + default: break; } diff --git a/lib/ajax/ajaxlib.php b/lib/ajax/ajaxlib.php index e61bd51a865..480f9b76273 100644 --- a/lib/ajax/ajaxlib.php +++ b/lib/ajax/ajaxlib.php @@ -343,11 +343,14 @@ class page_requirements_manager { if (strpos($name, 'core_') === 0) { // must be some core stuff - } else { - if ($name === 'filepicker') { // TODO: rename to 'core_filepicker' and move above + if ($name === 'core_filepicker') { $pathtofilepicker = $CFG->httpswwwroot.'/repository/filepicker.js'; - $module = array('fullpath'=>$pathtofilepicker, 'requires' => array('base', 'node', 'json', 'async-queue', 'io', 'yui2-button', 'yui2-container', 'yui2-treeview', 'yui2-layout')); + $module = array('fullpath'=>$pathtofilepicker, 'requires' => array('base', 'node', 'json', 'async-queue', 'io')); + } else if($name === 'core_filemanager') { + $pathtofilemanager = $CFG->httpswwwroot.'/lib/form/filemanager.js'; + $module = array('fullpath'=>$pathtofilemanager, 'requires' => array('base', 'io', 'node', 'json', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview')); } + } else { //TODO: look for plugin info? } diff --git a/lib/editor/tinymce/extra/tinymce_utils.js b/lib/editor/tinymce/extra/tinymce_utils.js index a095c11aeff..b89dd5de179 100644 --- a/lib/editor/tinymce/extra/tinymce_utils.js +++ b/lib/editor/tinymce/extra/tinymce_utils.js @@ -55,14 +55,14 @@ function editor_init_filepicker(editorid, options) { editor_options[editorid] = options; } function mce_moodlefilemanager(target_id, url, type, win) { - YUI(M.yui.loader).use("filepicker", function (Y) { + YUI(M.yui.loader).use('core_filepicker', function (Y) { var editor_id = tinyMCE.selectedInstance.editorId; var options = editor_options[editor_id]; var client_id = options.client_id; options.formcallback = editor_filepicker_callback; options.editor_target = win.document.getElementById(target_id); if (!editor_filepickers[client_id]) { - editor_filepickers[client_id] = new Y.filepicker(options); + editor_filepickers[client_id] = new Y.core_filepicker(options); } editor_filepickers[client_id].show(); }); diff --git a/lib/form/filemanager.js b/lib/form/filemanager.js index 328a88353f9..dc32bda5006 100644 --- a/lib/form/filemanager.js +++ b/lib/form/filemanager.js @@ -12,821 +12,640 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . - /** - * This file contains javascript code used to manage files in draft area * - * @since 2.0 - * @package filemanager - * @copyright 2009 Dongsheng Cai - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * File Manager UI + * ===== + * this.api, stores the URL to make ajax request + * this.currentpath + * this.filepicker_options + * this.movefile_dialog + * this.mkdir_dialog + * this.rename_dialog + * this.client_id + * + * FileManager options: + * ===== + * this.options.currentpath + * this.options.itemid */ +var filemanagers = {}; +var fm_filepickers = {}; -/** - * Namespaces used by filemanager - */ -YAHOO.namespace('moodle.filemanager'); +if (typeof M.core_filemanager == "undefined" || !M.core_filemanager) { + function core_filemanager (args) { + core_filemanager.superclass.constructor.apply(this, arguments); + } + core_filemanager.NAME = "FileManager"; + core_filemanager.ATTRS = { + options: {}, + lang: {} + }; + Y.extend(core_filemanager, Y.Base, { + api: M.cfg.wwwroot+'/files/files_ajax.php', + menus: {}, + initializer: function(args) { + this.options = args; + this.currentpath = '/'; + this.filepicker_options = args.filepicker; + this.client_id = ''; + if (args.client_id) { + this.client_id = args.client_id; + } + this.setup_buttons(); + this.render(); + }, + request: function(args) { + var api = this.api + '?action='+args.action; + var params = {}; + var scope = this; + if (args['scope']) { + scope = args['scope']; + } + params['sesskey']=M.cfg.sesskey; + params['client_id'] = this.client_id; + params['filepath'] = this.currentpath; + params['itemid'] = this.options.itemid?this.options.itemid:0; + if (args['params']) { + for (i in args['params']) { + params[i] = args['params'][i]; + } + } + var cfg = { + method: 'POST', + on: { + complete: function(id,o,p) { + if (!o) { + alert('IO FATAL'); + return; + } + var data = json_decode(o.responseText); + args.callback(id,data,p); + } + }, + arguments: { + scope: scope + }, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', + 'User-Agent': 'MoodleFileManager/3.0' + }, + data: build_querystring(params) + }; + if (args.form) { + cfg.form = args.form; + } + Y.io(api, cfg); + }, + filepicker_callback: function(obj) { + //console.warn(obj); + this.refresh(this.currentpath); + }, + refresh: function(filepath) { + var scope = this; + if (!filepath) { + filepath = this.currentpath; + } else { + this.currentpath = filepath; + } + this.request({ + action: 'list', + scope: scope, + params: {'filepath':filepath}, + callback: function(id, obj, args) { + scope.options = obj; + scope.render(obj); + } + }); + }, + setup_buttons: function() { + var client_id = this.client_id; + var button_download = Y.one("#btndwn-"+client_id); + var button_create = Y.one("#btncrt-"+client_id); + var button_addfile = Y.one("#btnadd-"+client_id); + button_addfile.on('click', function(e) { + var options = this.filepicker_options; + var scope = this; + var client_id = this.client_id; + Y.use('core_filepicker', function (Y) { + options.formcallback = scope.filepicker_callback; + // XXX: magic here, to let filepicker use filemanager scope + options.magicscope = scope; + options.savepath = scope.currentpath; + if (!fm_filepickers[client_id]) { + fm_filepickers[client_id] = new Y.core_filepicker(options); + } + fm_filepickers[client_id].show(); + }); + }, this); -// three dialog box we will used later -YAHOO.moodle.filemanager.movefile_dialog = null; -YAHOO.moodle.filemanager.rename_dialog = null; -YAHOO.moodle.filemanager.mkdir_dialog = null; + // setup 'add file' button + // if maxfiles == -1, the no limit + //if (fm_cfg[client_id].filecount >= fm_cfg[client_id].maxfiles + //&& fm_cfg[client_id].maxfiles!=-1) { + //button_addfile.style.display = 'none'; + //} else { + //button_addfile.onclick = function(e) { + //this.options.savepath = this.options.currentpath; + //fm_launch_filepicker(this.options.target, this.options); + //} + //button_addfile.options = fm_cfg[client_id]; + //} + // setup 'make a folder' button + if (this.options.subdirs) { + button_create.on('click',function(e) { + var scope = this; + // a function used to perform an ajax request + function perform_action(e) { + var foldername = Y.one('#fm-newname').get('value'); + if (!foldername) { + return; + } + scope.request({ + action:'mkdir', + params: {filepath:scope.currentpath, newdirname:foldername}, + callback: function(id, obj, args) { + var filepath = obj.filepath; + scope.mkdir_dialog.hide(); + scope.refresh(filepath); + Y.one('#fm-newname').set('value', ''); + } + }); + } + if (!Y.one('#fm-mkdir-dlg')) { + var dialog = Y.Node.create('
'+mstr.repository.entername+'
'); + Y.one(document.body).appendChild(dialog); + this.mkdir_dialog = new YAHOO.widget.Dialog("fm-mkdir-dlg", { + width: "300px", + visible: true, + x:e.pageX, + y:e.pageY, + constraintoviewport : true + }); -// an object used to record filemanager instances' data, -// we use it quite often -var fm_cfg = {}; -fm_cfg.api = M.cfg.wwwroot + '/files/files_ajax.php'; + } + var buttons = [ { text:mstr.moodle.ok, handler:perform_action, isDefault:true }, + { text:mstr.moodle.cancel, handler:function(){this.cancel();}}]; -// initialize file manager -var filemanager = (function(){ - function _filemanager() { - this.init = function(client_id, options) { - this.client_id = client_id; + this.mkdir_dialog.cfg.queueProperty("buttons", buttons); + this.mkdir_dialog.render(); + this.mkdir_dialog.show(); + }, this); + } else { + button_create.setStyle('display', 'none'); + } - // setup move file dialog - var dialog = null; - if (!YAHOO.moodle.filemanager.movefile_dialog) { - dialog = document.createElement('DIV'); - dialog.id = 'fm-move-dlg'; - document.body.appendChild(dialog); - YAHOO.moodle.filemanager.movefile_dialog = new YAHOO.widget.Dialog("fm-move-dlg", { + // setup 'download this folder' button + // NOTE: popup window must be enabled to perform download process + button_download.on('click',function() { + var scope = this; + // perform downloaddir ajax request + this.request({ + action: 'downloaddir', + scope: scope, + callback: function(id, obj, args) { + scope.refresh(obj.filepath); + var win = window.open(obj.fileurl, 'fm-download-folder'); + if (!win) { + alert(mstr.repository.popupblockeddownload); + } + } + }); + }, this); + }, + render: function() { + var client_id = this.client_id; + var options = this.options; + var path = this.options.path; + var list = this.options.list; + var breadcrumb = Y.one('#fm-path-'+client_id); + // build breadcrumb + if (path) { + // empty breadcrumb + breadcrumb.set('innerHTML', ''); + var count = 0; + for(var p in path) { + var arrow = ''; + if (count==0) { + arrow = Y.Node.create(''+mstr.moodle.path + ': '); + } else { + arrow = Y.Node.create(''); + } + count++; + + var pathid = 'fm-path-node-'+client_id; + pathid += ('-'+count); + + var crumb = Y.Node.create(''+path[p].name+''); + breadcrumb.appendChild(arrow); + breadcrumb.appendChild(crumb); + + var args = {}; + args.requestpath = path[p].path; + args.client_id = client_id; + Y.one('#'+pathid).on('click', function(e, args) { + var scope = this; + var params = {}; + params['filepath'] = args.requestpath; + this.request({ + action: 'list', + scope: scope, + params: params, + callback: function(id, obj, args) { + scope.options = obj; + scope.render(obj); + } + }); + }, this, args); + } + } + var template = Y.one('#fm-template'); + var container = Y.one('#filemanager-' + client_id); + var listhtml = ''; + + // folder list items + var folder_ids = []; + var folder_data = {}; + + // normal file list items + var file_ids = []; + var file_data = {}; + + // archives list items + var zip_ids = []; + var zip_data = {}; + + var html_ids = []; + var html_data = {}; + + file_data.itemid = folder_data.itemid = zip_data.itemid = options.itemid; + file_data.client_id = folder_data.client_id = zip_data.client_id = this.client_id; + + var foldername_ids = []; + if (!list || list.length == 0) { + // hide file browser and breadcrumb + container.setStyle('display', 'none'); + if (!path || path.length <= 1) { + breadcrumb.setStyle('display', 'none'); + } + return; + } else { + container.setStyle('display', 'block'); + breadcrumb.setStyle('display', 'block'); + } + + var count = 0; + for(var i in list) { + count++; + // the li html element + var htmlid = 'fileitem-'+client_id+'-'+count; + // link to file + var fileid = 'filename-'+client_id+'-'+count; + // file menu + var action = 'action-' +client_id+'-'+count; + + var html = template.get('innerHTML'); + + html_ids.push('#'+htmlid); + html_data[htmlid] = action; + + list[i].htmlid = htmlid; + list[i].fileid = fileid; + list[i].action = action; + + var url = "###"; + // check main file + //var ismainfile = false; + //if (fm_cfg[client_id].mainfilename && (fm_cfg[client_id].mainfilename.toLowerCase() == list[i].fullname.toLowerCase())) { + //ismainfile = true; + //} + + switch (list[i].type) { + case 'folder': + // click folder name + foldername_ids.push('#'+fileid); + // click folder menu + folder_ids.push('#'+action); + folder_data[action] = list[i]; + folder_data[fileid] = list[i]; + break; + case 'file': + file_ids.push('#'+action); + file_data[action] = list[i]; + if (list[i].url) { + url = list[i].url; + } + break; + case 'zip': + zip_ids.push('#'+action); + zip_data[action] = list[i]; + if (list[i].url) { + url = list[i].url; + } + break; + } + var fullname = list[i].fullname; + + // add green tick to main file + //if (ismainfile) { + //fullname = ""+list[i].fullname+" "; + //} + + html = html.replace('___fullname___', ' ' + fullname + ''); + html = html.replace('___action___', ''); + html = '
  • '+html+'
  • '; + listhtml += html; + } + if (!Y.one('#draftfiles-'+client_id)) { + var filelist = Y.Node.create('
      '); + container.appendChild(filelist); + } + Y.one('#draftfiles-'+client_id).set('innerHTML', listhtml); + + // click normal file menu + Y.on('click', this.create_filemenu, file_ids, this, file_data); + // click folder menu + Y.on('click', this.create_foldermenu, folder_ids, this, folder_data); + // click archievs menu + Y.on('click', this.create_zipmenu, zip_ids, this, zip_data); + // when mouse moveover every menu + function mouseover_menu(e, obj) { + var node = e.currentTarget; + node.setStyle('backgroundColor', '#0066EE'); + var menu = Y.one('#'+obj[node.get('id')]); + menu.setStyle('display', 'inline'); + } + function mouseout_menu(e, obj) { + var node = e.currentTarget; + node.setStyle('backgroundColor', 'transparent'); + var menu = Y.one('#'+obj[node.get('id')]); + menu.setStyle('display', 'none'); + } + Y.on('mouseover', mouseover_menu, html_ids, this, html_data); + Y.on('mouseout', mouseout_menu, html_ids, this, html_data); + // click folder name + Y.on('click', this.enter_folder, foldername_ids, this, folder_data); + }, + enter_folder: function(e, data) { + var node = e.currentTarget; + var file = data[node.get('id')]; + this.refresh(file.filepath); + }, + create_filemenu: function(e, data) { + var node = e.currentTarget; + var file = data[node.get('id')]; + + var menuitems = [ + {text: mstr.moodle.download, url:file.url} + ]; + this.create_menu(e, 'filemenu', menuitems, file, data); + }, + create_foldermenu: function(e, data) { + var scope = this; + var node = e.currentTarget; + var fileinfo = data[node.get('id')]; + // an extra menu item for folder to zip it + function archive_folder(type,ev,obj) { + var params = {}; + params['filepath'] = fileinfo.filepath; + params['filename'] = '.'; + this.request({ + action: 'zip', + scope: scope, + params: params, + callback: function(id, obj, args) { + scope.refresh(obj.filepath); + } + }); + } + var menuitems = [ + {text: mstr.editor.zip, onclick: {fn: archive_folder, obj: data, scope: this}}, + ]; + this.create_menu(e, 'foldermenu', menuitems, fileinfo, data); + }, + create_zipmenu: function(e, data) { + var scope = this; + var node = e.currentTarget; + var fileinfo = data[node.get('id')]; + + function unzip(type, ev, obj) { + var params = {}; + params['filepath'] = fileinfo.filepath; + params['filename'] = fileinfo.fullname; + this.request({ + action: 'unzip', + scope: scope, + params: params, + callback: function(id, obj, args) { + scope.refresh(obj.filepath); + } + }); + } + var menuitems = [ + {text: mstr.moodle.download, url:fileinfo.url}, + {text: mstr.moodle.unzip, onclick: {fn: unzip, obj: data, scope: this}} + ]; + this.create_menu(e, 'zipmenu', menuitems, fileinfo, data); + }, + create_menu: function(ev, menuid, menuitems, fileinfo, options) { + var position = [ev.pageX, ev.pageY]; + var scope = this; + function remove(type, ev, obj) { + var dialog_options = {}; + var params = {}; + dialog_options.message = mstr.repository.confirmdeletefile; + dialog_options.scope = this; + var filename = ''; + var filepath = ''; + if (fileinfo.type == 'folder') { + params.filename = '.'; + params.filepath = fileinfo.fullname; + } else { + params.filename = fileinfo.fullname; + } + dialog_options.callback = function() { + this.request({ + action: 'delete', + scope: scope, + params: params, + callback: function(id, obj, args) { + scope.refresh(obj.filepath); + } + }); + } + var dlg = confirm_dialog(ev, dialog_options); + } + function rename (type, ev, obj) { + var scope = this; + var perform = function(e) { + var newfilename = Y.one('#fm-rename-input').get('value'); + if (!newfilename) { + return; + } + + var action = ''; + var params = {}; + if (fileinfo.type == 'folder') { + params['filepath'] = fileinfo.filepath; + params['filename'] = '.'; + action = 'renamedir'; + } else { + params['filepath'] = fileinfo.filepath; + params['filename'] = fileinfo.fullname; + action = 'rename'; + } + params['newfilename'] = newfilename; + scope.request({ + action: action, + scope: scope, + params: params, + callback: function(id, obj, args) { + scope.refresh(obj.filepath); + Y.one('#fm-rename-input').set('value', ''); + scope.rename_dialog.hide(); + } + }); + } + + var dialog = Y.one('#fm-rename-dlg'); + if (!dialog) { + dialog = Y.Node.create('
      '+mstr.repository.enternewname+'
      '); + Y.one(document.body).appendChild(dialog); + this.rename_dialog = new YAHOO.widget.Dialog("fm-rename-dlg", { + width: "300px", + fixedcenter: true, + visible: true, + constraintoviewport : true + }); + + } + var buttons = [ { text:mstr.moodle.rename, handler:perform, isDefault:true}, + { text:mstr.moodle.cancel, handler:function(){this.cancel();}}]; + + this.rename_dialog.cfg.queueProperty('buttons', buttons); + this.rename_dialog.render(); + this.rename_dialog.show(); + //var k1 = new YAHOO.util.KeyListener(scope, {keys:13}, {fn:function(){perform();}, correctScope: true}); + //k1.enable(); + Y.one('#fm-rename-input').set('value', fileinfo.fullname); + } + function move(type, ev, obj) { + var scope = this; + var itemid = this.options.itemid; + // setup move file dialog + var dialog = null; + if (!Y.one('#fm-move-dlg')) { + dialog = Y.Node.create('
      '); + Y.one(document.body).appendChild(dialog); + } else { + dialog = Y.one('#fm-move-dlg'); + } + + dialog.set('innerHTML', '
      Moving
      '+mstr.repository.nopathselected+'
      '); + + this.movefile_dialog = new YAHOO.widget.Dialog("fm-move-dlg", { width : "600px", fixedcenter : true, visible : false, constraintoviewport : true }); - } else { - dialog = document.getElementById('fm-move-div'); - } - dialog.innerHTML = '
      '+mstr.repository.nopathselected+'
      '; + var treeview = new YAHOO.widget.TreeView("fm-tree"); - YAHOO.moodle.filemanager.movefile_dialog.render(); - // generate filemanager html - html_compiler(client_id, options); - } - } - return _filemanager; -})(); - - -/** - * This function will be called by filepicker once it got the file successfully - */ -function filemanager_callback(params) { - var client_id = params.client_id; - fm_refresh(params.filepath, fm_cfg[client_id]); - fm_cfg[client_id].currentfiles++; - - if (fm_cfg[client_id].currentfiles>=fm_cfg[client_id].maxfiles - && fm_cfg[client_id].maxfiles!=-1) { - var addfilebutton = document.getElementById('btnadd-'+client_id); - if (addfilebutton) { - addfilebutton.style.display = 'none'; - } - } -} - -var fm_filepickers = {}; -function fp_filepicker_callback(params) { - var html = ''+params['title']+''; - document.getElementById('file_info_'+params['client_id']).innerHTML = html; -} - -function fm_init_filepicker(id, options) { - YUI(M.yui.loader).use("filepicker", function (Y) { - options.formcallback = filemanager_callback; - if (!pickers[options.client_id]) { - fm_filepickers[options.client_id] = new Y.filepicker(options); - } - Y.one('#'+id).on('click', function(e, client_id) { - fm_filepickers[options.client_id].show(); - }, this, options.client_id); - }); -} -/** - * Setup options to launch file picker. - * Fired by add file button. - */ -function fm_launch_filepicker(target, options) { - var picker = document.createElement('DIV'); - picker.id = 'file-picker-'+options.client_id; - picker.className = 'file-picker'; - document.body.appendChild(picker); - - var target=document.getElementById(target); - var params = {}; - params.env = 'filemanager'; - params.itemid = options.itemid; - params.maxfiles = options.maxfiles; - params.maxbytes = options.maxbytes; - params.savepath = options.savepath; - params.target = target; - // setup filemanager callback - params.callback = filemanager_callback; - var fp = open_filepicker(options.client_id, params); - return false; -} - -/** - * This function will create a dialog of creating new folder - * Fired by 'make a folder' button - */ -function fm_create_folder(e, client_id, itemid) { - // deal with ajax response - var mkdir_ajax_callback = { - success: function(o) { - var result = json_decode(o.responseText); - YAHOO.moodle.filemanager.mkdir_dialog.hide(); - fm_refresh(result.filepath, fm_cfg[client_id]); - } - } - // a function used to perform an ajax request - var perform_ajax_mkdir = function(e) { - var foldername = document.getElementById('fm-newname').value; - if (!foldername) { - return; - } - var params = []; - params['itemid'] = itemid; - params['newdirname'] = foldername; - params['sesskey'] = M.cfg.sesskey; - params['filepath'] = fm_cfg[client_id].currentpath; - var trans = YAHOO.util.Connect.asyncRequest('POST', - fm_cfg.api+'?action=mkdir', mkdir_ajax_callback, build_querystring(params)); - YAHOO.util.Event.preventDefault(e); - } - // create dialog html element - if (!document.getElementById('fm-mkdir-dlg')) { - var el = document.createElement('DIV'); - el.id = 'fm-mkdir-dlg'; - el.innerHTML = '
      '+mstr.repository.entername+'
      '; - document.body.appendChild(el); - var x = YAHOO.util.Event.getPageX(e); - var y = YAHOO.util.Event.getPageY(e); - YAHOO.moodle.filemanager.mkdir_dialog = new YAHOO.widget.Dialog("fm-mkdir-dlg", { - width: "300px", - visible: true, - x:y, - y:y, - constraintoviewport : true - }); - - } - var buttons = [ { text:mstr.moodle.ok, handler:perform_ajax_mkdir, isDefault:true }, - { text:mstr.moodle.cancel, handler:function(){this.cancel();}}]; - - YAHOO.moodle.filemanager.mkdir_dialog.cfg.queueProperty("buttons", buttons); - YAHOO.moodle.filemanager.mkdir_dialog.render(); - YAHOO.moodle.filemanager.mkdir_dialog.show(); - - // presss 'enter' key to perform ajax request - var k1 = new YAHOO.util.KeyListener(document.getElementById('fm-mkdir-dlg'), {keys:13}, {fn:function(){perform_ajax_mkdir();}, correctScope: true}); - k1.enable(); - - document.getElementById('fm-newname').value = ''; -} - -// generate html -function html_compiler(client_id, options) { - var list = options.list; - var breadcrumb = document.getElementById('fm-path-'+client_id); - var count = 0; - // build breadcrumb - if (options.path) { - // empty breadcrumb - breadcrumb.innerHTML = ''; - var count = 0; - for(var p in options.path) { - var sep = document.createElement('SPAN'); - sep.innerHTML = ' ▶ '; - if (count==0) { - sep.innerHTML = mstr.moodle.path + ': '; - } else { - sep.innerHTML = ' ▶ '; - } - count++; - - var pathid = 'fm-path-node-'+client_id; - pathid += ('-'+count); - - var pathnode = document.createElement('A'); - pathnode.id = pathid; - pathnode.innerHTML = options.path[p].name; - pathnode.href = '###'; - breadcrumb.appendChild(sep); - breadcrumb.appendChild(pathnode); - - var args = {}; - args.itemid = options.itemid; - args.requestpath = options.path[p].path; - args.client_id = client_id; - - YAHOO.util.Event.addListener(pathid, 'click', fm_click_breadcrumb, args); - } - } - var template = document.getElementById('fm-template'); - var container = document.getElementById('filemanager-' + client_id); - var listhtml = ''; - - // folder list items - var folder_ids = []; - var folder_data = {}; - - // normal file list items - var file_ids = []; - var file_data = {}; - - // archives list items - var zip_ids = []; - var zip_data = {}; - - var html_ids = []; - var html_data = {}; - - file_data.itemid = folder_data.itemid = zip_data.itemid = options.itemid; - file_data.client_id = folder_data.client_id = zip_data.client_id = options.client_id; - - var foldername_ids = []; - if (list.length == 0) { - // hide file browser and breadcrumb - container.style.display='none'; - if (options.path.length <= 1) { - breadcrumb.style.display='none'; - } - return; - } else { - container.style.display='block'; - breadcrumb.style.display='block'; - } - - var count = 0; - for(var i in list) { - count++; - // the li html element - var htmlid = 'fileitem-'+client_id+'-'+count; - // link to file - var fileid = 'filename-'+client_id+'-'+count; - // file menu - var action = 'action-' +client_id+'-'+count; - - var html = template.innerHTML; - - html_ids.push(htmlid); - html_data[htmlid] = action; - - list[i].htmlid = htmlid; - list[i].fileid = fileid; - list[i].action = action; - - var url = "###"; - // check main file - var ismainfile = false; - if (fm_cfg[client_id].mainfilename && (fm_cfg[client_id].mainfilename.toLowerCase() == list[i].fullname.toLowerCase())) { - ismainfile = true; - } - - switch (list[i].type) { - case 'folder': - foldername_ids.push(fileid); - folder_ids.push(action); - folder_data[action] = list[i]; - folder_data[fileid] = list[i]; - break; - case 'file': - file_ids.push(action); - file_data[action] = list[i]; - if (list[i].url) { - url = list[i].url; - } - break; - case 'zip': - zip_ids.push(action); - zip_data[action] = list[i]; - if (list[i].url) { - url = list[i].url; - } - break; - } - var fullname = list[i].fullname; - - // add green tick to main file - if (ismainfile) { - fullname = ""+list[i].fullname+" "; - } - - html = html.replace('___fullname___', ' ' + fullname + ''); - html = html.replace('___action___', ''); - html = '
    • '+html+'
    • '; - listhtml += html; - } - - container.innerHTML = '
        ' + listhtml + '
      '; - - // click normal file menu - YAHOO.util.Event.addListener(file_ids, 'click', fm_create_filemenu, file_data); - // click folder menu - YAHOO.util.Event.addListener(folder_ids, 'click', fm_create_foldermenu, folder_data); - // click archievs menu - YAHOO.util.Event.addListener(zip_ids, 'click', fm_create_zipmenu, zip_data); - // when mouse moveover every menu - YAHOO.util.Event.addListener(html_ids, 'mouseover', fm_mouseover_menu, html_data); - YAHOO.util.Event.addListener(html_ids, 'mouseout', fm_mouseout_menu, html_data); - // click folder name - YAHOO.util.Event.addListener(foldername_ids,'click', fm_click_folder, folder_data); -} - -function fm_refresh(path, args) { - var params = []; - params['itemid'] = args.itemid; - params['filepath'] = path; - params['sesskey'] = M.cfg.sesskey; - this.cb = { - success: function(o) { - var data = json_decode(o.responseText); - for(var key in data) { - this.options[key] = data[key]; - } - html_compiler(this.client_id, this.options); - } - } - this.cb.options = args; - this.cb.client_id = args.client_id; - - fm_cfg[args.client_id].currentpath = params['filepath']; - fm_loading('filemanager-'+args.client_id, 'fm-prgressbar'); - var trans = YAHOO.util.Connect.asyncRequest('POST', - fm_cfg.api+'?action=list', this.cb, build_querystring(params)); -} - -// display menu when mouse over -function fm_mouseover_menu(ev, args) { - this.style.backgroundColor = '#0066EE'; - var menu = args[this.id]; - menu = document.getElementById(menu); - menu.style.display = 'inline'; -} - -// hide menu when mouse over -function fm_mouseout_menu(ev, args) { - this.style.backgroundColor = 'transparent'; - var menu = args[this.id]; - menu = document.getElementById(menu); - menu.style.display = 'none'; -} - -function fm_click_breadcrumb(ev, args) { - var params = []; - params['itemid'] = args.itemid; - params['sesskey'] = M.cfg.sesskey; - params['filepath'] = args.requestpath; - this.cb = { - success: function(o) { - var data = json_decode(o.responseText); - for(var key in data) { - this.options[key] = data[key]; - } - html_compiler(this.client_id, this.options); - } - } - this.cb.options = args; - this.cb.client_id = args.client_id; - - fm_cfg[args.client_id].currentpath = args.requestpath; - fm_loading('filemanager-'+args.client_id, 'fm-prgressbar'); - var trans = YAHOO.util.Connect.asyncRequest('POST', - fm_cfg.api+'?action=list', this.cb, build_querystring(params)); -} - -function fm_click_folder(ev, args) { - var file = args[this.id]; - fm_refresh(file.filepath, args); -} - -function fm_create_foldermenu(e, data) { - var file = data[this.id]; - // an extra menu item for folder to zip it - this.zip = function(type, ev, obj) { - this.cb = { - success: function(o) { - var result = json_decode(o.responseText); - if (result) { - fm_refresh(result.filepath, fm_cfg[this.client_id]); - } - } - } - this.cb.client_id = obj.client_id; - this.cb.file = this.file; - var params = []; - params['itemid'] = obj.itemid; - params['filepath'] = this.file.filepath; - params['filename'] = '.'; - params['sesskey'] = M.cfg.sesskey; - fm_loading('filemanager-'+obj.client_id, 'fm-prgressbar'); - var trans = YAHOO.util.Connect.asyncRequest('POST', - fm_cfg.api+'?action=zip', this.cb, build_querystring(params)); - } - this.zip.file = file; - var menuitems = [ - {text: mstr.editor.zip, onclick: {fn: this.zip, obj: data, scope: this.zip}}, - ]; - fm_create_menu(e, 'foldermenu', menuitems, file, data); -} - -function fm_create_filemenu(e, data) { - var file = data[this.id]; - - var menuitems = [ - {text: mstr.moodle.download, url:file.url} - ]; - fm_create_menu(e, 'filemenu', menuitems, file, data); -} - -function fm_create_zipmenu(e, data) { - var file = data[this.id]; - this.unzip = function(type, ev, obj) { - this.cb = { - success:function(o) { - var result = json_decode(o.responseText); - if (result) { - fm_refresh(result.filepath, fm_cfg[this.client_id]); - } - } - } - this.cb.client_id = obj.client_id; - var params = []; - params['itemid'] = obj.itemid; - params['filepath'] = this.file.filepath; - params['filename'] = this.file.fullname; - params['sesskey'] = M.cfg.sesskey; - fm_loading('filemanager-'+obj.client_id, 'fm-prgressbar'); - var trans = YAHOO.util.Connect.asyncRequest('POST', - fm_cfg.api+'?action=unzip', this.cb, build_querystring(params)); - } - this.unzip.file = file; - - var menuitems = [ - {text: mstr.moodle.download, url:file.url}, - {text: mstr.moodle.unzip, onclick: {fn: this.unzip, obj: data, scope: this.unzip}} - ]; - fm_create_menu(e, 'zipmenu', menuitems, file, data); -} - -function fm_create_menu(ev, menuid, menuitems, file, options) { - var position = YAHOO.util.Event.getXY(ev); - var el = document.getElementById(menuid); - var menu = new YAHOO.widget.Menu(menuid, {xy:position}); - - this.remove = function(type, ev, obj) { - var args = {}; - args.message = mstr.repository.confirmdeletefile; - args.callback = function() { - var params = {}; - if (this.file.type == 'folder') { - params['filename'] = '.'; - params['filepath'] = this.file.fullname; - } else { - params['filename'] = this.file.fullname; - params['filepath'] = fm_cfg[this.client_id].currentpath; - } - params['itemid'] = this.itemid; - params['sesskey'] = M.cfg.sesskey; - fm_loading('filemanager-'+this.client_id, 'fm-prgressbar'); - var trans = YAHOO.util.Connect.asyncRequest('POST', - fm_cfg.api+'?action=delete', this.cb, build_querystring(params)); - } - var dlg = confirm_dialog(ev, args); - dlg.file = file; - dlg.client_id = obj.client_id; - dlg.itemid = obj.itemid; - dlg.cb = { - success: function(o) { - var result = json_decode(o.responseText); - if (!result) { - alert(mstr.error.cannotdeletefile); - } - fm_cfg[this.client_id].currentfiles--; - if (fm_cfg[this.client_id].currentfiles
      '; - document.body.appendChild(el); - YAHOO.moodle.filemanager.rename_dialog = new YAHOO.widget.Dialog("fm-rename-dlg", { - width: "300px", - fixedcenter: true, - visible: true, - constraintoviewport : true - }); - - } - var buttons = [ { text:mstr.moodle.rename, handler:perform, isDefault:true }, - { text:mstr.moodle.cancel, handler:function(){this.cancel();}}]; - - YAHOO.moodle.filemanager.rename_dialog.cfg.queueProperty("buttons", buttons); - YAHOO.moodle.filemanager.rename_dialog.render(); - YAHOO.moodle.filemanager.rename_dialog.show(); - - var k1 = new YAHOO.util.KeyListener(scope, {keys:13}, {fn:function(){perform();}, correctScope: true}); - k1.enable(); - - document.getElementById('fm-rename-input').value = file.fullname; - } - this.rename.file = file; - - this.move = function(type, ev, obj) { - var tree = new YAHOO.widget.TreeView("fm-tree"); - var file = this.file; - - this.asyncMove = function(e) { - if (!tree.targetpath) { - return; - } - var cb = { - success : function(o) { - var result = json_decode(o.responseText); - var p = '/'; - if (result) { - p = result.filepath; - } - fm_refresh(result.filepath, fm_cfg[obj.client_id]); - this.dlg.cancel(); - } - } - cb.dlg = this; - var params = {}; - if (file.type == 'folder') { - alert('Moving folder is not supported yet'); - return; - action = 'movedir'; - } else { - action = 'movefile'; - } - params['filepath'] = file.filepath; - params['filename'] = file.fullname; - params['itemid'] = obj.itemid; - params['sesskey'] = M.cfg.sesskey; - params['newfilepath'] = tree.targetpath; - fm_loading('filemanager-'+obj.client_id, 'fm-prgressbar'); - var trans = YAHOO.util.Connect.asyncRequest('POST', - fm_cfg.api+'?action='+action, cb, build_querystring(params)); - } - - var buttons = [ { text:mstr.moodle.move, handler:this.asyncMove, isDefault:true }, - { text:mstr.moodle.cancel, handler:function(){this.cancel();}}]; - - YAHOO.moodle.filemanager.movefile_dialog.cfg.queueProperty("buttons", buttons); - - - tree.subscribe("dblClickEvent", function(e) { - // update destidatoin folder - this.targetpath = e.node.data.path; - var el = document.getElementById('fm-move-div'); - el.innerHTML = '"' + this.targetpath + '" has been selected.'; - YAHOO.util.Event.preventDefault(e); - }); - - this.loadDataForNode = function(node, onCompleteCallback) { - this.cb = { - success: function(o) { - var data = json_decode(o.responseText); - data = data.children; - if (data.length == 0) { - // so it is empty + var params = {}; + if (fileinfo.type == 'folder') { + alert('Moving folder is not supported yet'); + action = 'movedir'; + return; } else { - for (var i in data) { - var textnode = {label: data[i].fullname, path: data[i].filepath, itemid: this.itemid}; - var tmpNode = new YAHOO.widget.TextNode(textnode, node, false); - } + action = 'movefile'; } - this.complete(); + params['filepath'] = fileinfo.filepath; + params['filename'] = fileinfo.fullname; + params['newfilepath'] = treeview.targetpath; + scope.request({ + action: action, + scope: scope, + params: params, + callback: function(id, obj, args) { + var p = '/'; + if (obj) { + p = result.filepath; + } + this.movefile_dialog.cancel(); + } + }); } + + var buttons = [ { text:mstr.moodle.move, handler:_move, isDefault:true }, + { text:mstr.moodle.cancel, handler:function(){this.cancel();}}]; + + this.movefile_dialog.cfg.queueProperty("buttons", buttons); + this.movefile_dialog.render(); + + treeview.subscribe("dblClickEvent", function(e) { + // update destidatoin folder + this.targetpath = e.node.data.path; + var title = Y.one('#fm-move-div'); + title.set('innerHTML', '"' + this.targetpath + '" has been selected.'); + }); + + function loadDataForNode(node, onCompleteCallback) { + var params = {}; + params['filepath'] = node.data.path; + var obj = { + action: 'dir', + scope: scope, + params: params, + callback: function(id, obj, args) { + data = obj.children; + if (data.length == 0) { + // so it is empty + } else { + for (var i in data) { + var textnode = {label: data[i].fullname, path: data[i].filepath, itemid: this.itemid}; + var tmpNode = new YAHOO.widget.TextNode(textnode, node, false); + } + } + this.oncomplete(); + } + }; + obj.oncomplete = onCompleteCallback; + scope.request(obj); + } + + this.movefile_dialog.subscribe('show', function(){ + var rootNode = treeview.getRoot(); + treeview.setDynamicLoad(loadDataForNode); + treeview.removeChildren(rootNode); + var textnode = {label: "Files", path: '/'}; + var tmpNode = new YAHOO.widget.TextNode(textnode, rootNode, true); + treeview.draw(); + }, this, true); + + this.movefile_dialog.show(); } - var params = {}; - params['itemid'] = node.data.itemid; - params['filepath'] = node.data.path; - params['sesskey'] = M.cfg.sesskey; - var trans = YAHOO.util.Connect.asyncRequest('POST', - fm_cfg.api+'?action=dir', this.cb, build_querystring(params)); - this.cb.complete = onCompleteCallback; - this.cb.itemid = node.data.itemid; + var shared_items = [ + {text: mstr.moodle.rename+'...', onclick: {fn: rename, obj: options, scope: this}}, + {text: mstr.moodle.move+'...', onclick: {fn: move, obj: options, scope: this}}, + // delete is reserve word in Javascript + {text: mstr.moodle['delete']+'...', onclick: {fn: remove, obj: options, scope: this}} + ]; + var menu = new YAHOO.widget.Menu(menuid, {xy:position, clicktohide:true}); + menu.clearContent(); + menu.addItems(menuitems); + menu.addItems(shared_items); + menu.render(document.body); + menu.subscribe('hide', function(){ + this.fireEvent('destroy'); + }); + menu.show(); } - this.loadDataForNode.itemid = obj.itemid; - - YAHOO.moodle.filemanager.movefile_dialog.subscribe('show', function(){ - - var el = document.getElementById('fm-move-div'); - el.innerHTML = '
      '+mstr.repository.nopathselected+'
      '; - - var rootNode = tree.getRoot(); - tree.setDynamicLoad(this.loadDataForNode); - tree.removeChildren(rootNode); - var textnode = {label: "Files", path: '/', itemid: obj.itemid}; - var tmpNode = new YAHOO.widget.TextNode(textnode, rootNode, true); - tree.draw(); - - }, this, true); - - YAHOO.moodle.filemanager.movefile_dialog.render(); - YAHOO.moodle.filemanager.movefile_dialog.show(); - } - this.move.file = file; - var shared_items = [ - {text: mstr.moodle.rename+'...', onclick: {fn: this.rename, obj: options, scope: this.rename}}, - {text: mstr.moodle.move+'...', onclick: {fn: this.move, obj: options, scope: this.move}}, - {text: mstr.moodle['delete']+'...', onclick: {fn: this.remove, obj: options, scope: this.remove}} - ]; - menu.addItems(menuitems); - menu.addItems(shared_items); - if (fm_cfg[options.client_id].mainfile && (file.type!='folder')) { - this.set_mainfile = function(type, ev, obj) { - if (fm_cfg[obj.client_id].mainfile) { - var mainfile = document.getElementById(fm_cfg[obj.client_id].mainfile+'-id'); - mainfile.value = this.file.filepath+this.file.fullname; - document.getElementById(fm_cfg[obj.client_id].mainfile+'-label').innerHTML = mainfile.value; - } - fm_cfg[obj.client_id].mainfilename = this.file.fullname; - fm_refresh(fm_cfg[obj.client_id].currentpath, fm_cfg[obj.client_id]); - - } - this.set_mainfile.file = file; - menu.addItem({text: mstr.resource.setmainfile, onclick: {fn: this.set_mainfile, obj: options, scope: this.set_mainfile}}); - } - menu.render(document.body); - menu.show(); - menu.subscribe('hide', function(){ - this.destroy(); }); -} - -/** - * setup file manager options and initialize filemanger itself - */ -function launch_filemanager(client_id, options) { - // setup options & parameters - if (!options) { - options = {}; - } - fm_cfg[client_id] = {}; - fm_cfg[client_id] = options; - fm_cfg[client_id].currentpath = '/'; - if (fm_cfg[client_id].filecount) { - fm_cfg[client_id].currentfiles = fm_cfg[client_id].filecount; - } else { - fm_cfg[client_id].currentfiles = 0; - } - // - if (options.mainfile) { - var mainfilename = document.getElementById(options.mainfile+'-id'); - if (mainfilename.value) { - var re = new RegExp(".*\/(.*)$", "i"); - var result = mainfilename.value.match(re); - document.getElementById(options.mainfile+'-label').innerHTML = mainfilename.value; - fm_cfg[client_id].mainfilename = result[1]; - } else { - fm_cfg[client_id].mainfilename = ''; - } - } - // setup filemanager - var fm = new filemanager(); - fm.init(client_id, options); - // setup toolbar - fm_setup_buttons(client_id, options); -} - -/** - * Set up buttons - */ -function fm_setup_buttons(client_id, options) { - var button_download = document.getElementById("btndwn-"+client_id); - var button_create = document.getElementById("btncrt-"+client_id); - var button_addfile = document.getElementById("btnadd-"+client_id); - - // setup 'add file' button - // if maxfiles == -1, the no limit - if (fm_cfg[client_id].filecount >= fm_cfg[client_id].maxfiles - && fm_cfg[client_id].maxfiles!=-1) { - button_addfile.style.display = 'none'; - } else { - button_addfile.onclick = function(e) { - this.options.savepath = this.options.currentpath; - fm_launch_filepicker(this.options.target, this.options); - } - button_addfile.options = fm_cfg[client_id]; - } - - // setup 'make a folder' button - if (fm_cfg[client_id].subdirs) { - button_create.onclick = function(e) { - fm_create_folder(e, this.options.client_id, this.options.itemid); - } - button_create.options = fm_cfg[client_id]; - } else { - button_create.style.display = 'none'; - } - - // setup 'download this folder' button - // NOTE: popup window must be enabled to perform download process - button_download.onclick = function() { - var downloaddir_callback = { - success:function(o) { - var result = json_decode(o.responseText); - fm_refresh(result.filepath, fm_cfg[this.client_id]); - var win = window.open(result.fileurl, 'fm-download-folder'); - if (!win) { - alert(mstr.repository.popupblockeddownload); - } - } - }; - downloaddir_callback.client_id = this.options.client_id; - var params = []; - params['itemid'] = this.options.itemid; - params['sesskey'] = M.cfg.sesskey; - params['filepath'] = this.options.currentpath; - // perform downloaddir ajax request - var trans = YAHOO.util.Connect.asyncRequest('POST', - fm_cfg.api+'?action=downloaddir', downloaddir_callback, build_querystring(params)); - } - button_download.options = fm_cfg[client_id]; -} - -/** - * Print a progress bar - */ -function fm_loading(container, id) { - - if (!document.getElementById(id)) { - var el = document.createElement('DIV'); - el.id = id; - el.style.backgroundColor = "white"; - var container = document.getElementById(container); - container.innerHTML = ''; - container.appendChild(el); - } - - var loading = new YAHOO.widget.Module(id, {visible:false}); - loading.setBody('
      '+mstr.repository.loading+'
      '); - loading.render(); - loading.show(); - - return loading; + M.core_filemanager = core_filemanager; } diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php index e81a45c1956..28217c2d67a 100644 --- a/lib/form/filemanager.php +++ b/lib/form/filemanager.php @@ -31,7 +31,7 @@ require_once("$CFG->dirroot/repository/lib.php"); class MoodleQuickForm_filemanager extends HTML_QuickForm_element { public $_helpbutton = ''; - protected $_options = array('mainfile'=>'', 'subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL); + protected $_options = array('mainfile'=>'', 'subdirs'=>1, 'maxbytes'=>0, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL); function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $attributes=null, $options=null) { global $CFG, $PAGE; @@ -46,7 +46,8 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element { $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']); } parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes); - $PAGE->requires->js('/lib/form/filemanager.js'); + $PAGE->requires->js_module('core_filepicker'); + $PAGE->requires->js_module('core_filemanager'); } function setName($name) { @@ -169,7 +170,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element { $args = new stdclass; // need these three to filter repositories list $args->accepted_types = $accepted_types; - $args->return_types = $this->_options['return_types']; + $args->return_types = FILE_INTERNAL; $args->context = $PAGE->context; $args->env = 'filemanager'; @@ -178,6 +179,8 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element { $filepicker_options->client_id = $client_id; $filepicker_options->maxbytes = $this->_options['maxbytes']; $filepicker_options->maxfiles = $this->_options['maxfiles']; + $filepicker_options->env = 'filemanager'; + $filepicker_options->itemid = $draftitemid; // Generate file picker $result = new stdclass; @@ -190,13 +193,19 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element { $options->filecount = $filecount; $options->itemid = $draftitemid; $options->subdirs = $this->_options['subdirs']; + // store filepicker options + $options->filepicker = $filepicker_options; $options->target = $id; $html = $this->_getTabs(); + $PAGE->requires->js_function_call('destroy_item', array("nonjs-filemanager-{$client_id}"))->on_dom_ready(); + $PAGE->requires->js_function_call('show_item', array("filemanager-wrapper-{$client_id}"))->on_dom_ready(); + $PAGE->requires->js_function_call('launch_filemanager', array($options))->on_dom_ready(); + + // print out this only once if (empty($CFG->filemanagertemplateloaded)) { $CFG->filemanagertemplateloaded = true; - // print html template $html .= <<