<?php //$Id$
+$string['add'] = 'Add';
$string['activaterep'] = 'Active repositories';
$string['back'] = '< Back';
-$string['download'] = 'Download';
$string['close'] = 'Close';
+$string['download'] = 'Download';
+$string['downloadsucc'] = 'Download Successfully!';
$string['filename'] = 'Filename';
$string['filesaved'] = 'File Saved!';
$string['invalidrepositoryid'] = 'Invalid Repository ID';
$string['invalidplugin'] = 'Invalid Repository Plug-in';
$string['manageuserrepository'] = 'Manage individual repository';
+$string['noenter'] = 'Nothing entered';
$string['plugin'] = 'Repository Plug-ins';
$string['settings'] = 'Settings';
$string['openpicker'] = 'Open file picker';
$string['loading'] = 'Loading...';
$string['thumbview'] = 'Thumbnail View';
$string['search'] = 'Search ';
+$string['searching'] = 'What are you searching?';
$string['submit'] = 'Submit';
$string['sync'] = 'Sync';
$string['title'] = 'Repository File Picker';
return $this->getFrozenHtml();
} else {
$strsaved = get_string('filesaved', 'repository');
- $itemid = substr(hexdec(uniqid()), 0, 9)+rand(1,100);
if(empty($COURSE->context)) {
$ctx = get_context_instance(CONTEXT_SYSTEM);
} else {
$ret = get_repository_client($ctx);
$suffix = $ret['suffix'];
$str = $this->_getTabs();
- $str .= '<input type="hidden" value="'.$itemid.'" name="'.$this->_attributes['name'].'" id="'.$this->_attributes['id'].'_'.$suffix.'" />';
+ $str .= '<input type="hidden" value="" name="'.$this->_attributes['name'].'" id="'.$this->_attributes['id'].'_'.$suffix.'" />';
$id = $this->_attributes['id'];
$str .= <<<EOD
<script type="text/javascript">
-function updatefile(){
- alert('$strsaved');
+function updatefile_$suffix(){
document.getElementById('repo_info_$suffix').innerHTML = '$strsaved';
}
function callpicker_$suffix(){
var el=document.getElementById('${id}_${suffix}');
- openpicker_$suffix({"env":"form", 'itemid': $itemid, 'target':el, 'callback':updatefile})
+ openpicker_$suffix({"env":"form", 'target':el, 'callback':updatefile_$suffix})
}
</script>
EOD;
$fs = get_file_storage();
$browser = get_file_browser();
if ($file = $fs->create_file_from_pathname($entry, $path)) {
- $id = json_encode($file->get_itemid());
$ret = $browser->get_file_info($context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
return array('url'=>$ret->get_url(),'id'=>$file->get_itemid());
} else {
$strdownload = get_string('download', 'repository');
$strback = get_string('back', 'repository');
$strclose = get_string('close', 'repository');
+ $strdownload = get_string('downloadsucc', 'repository');
+ $strnoenter = get_string('noenter', 'repository');
+ $strsearching = get_string('searching', 'repository');
+ $stradd = get_string('add', 'repository');
$js = <<<EOD
<style type="text/css">
underlay: 'none',
width: '510px',
zindex: 666666,
- xy: [100, 100]
+ xy: ['50%', YAHOO.util.Dom.getDocumentScrollTop()]
});
// construct code section
{
}
_client.loading = function(){
var panel = new YAHOO.util.Element('panel-$suffix');
- panel.get('element').innerHTML = '<span>$strloading</span>';
+ panel.get('element').innerHTML = '';
+ var content = document.createElement('div');
+ content.innerHTML = '$strloading';
+ panel.get('element').appendChild(content);
}
_client.rename = function(oldname, url){
var panel = new YAHOO.util.Element('panel-$suffix');
_client.download = function(){
var title = document.getElementById('newname-$suffix').value;
var file = document.getElementById('fileurl-$suffix').value;
- var itemid = 1;
- if(_client.itemid){
- itemid = _client.itemid;
- }
_client.loading();
var trans = YAHOO.util.Connect.asyncRequest('POST',
- '$CFG->wwwroot/repository/ws.php?ctx_id=$context->id&repo_id='+_client.repositoryid+
- '&action=download',
- _client.dlfile, _client.postdata({'itemid': itemid, 'env':_client.env, 'file':file, 'title':title}));
+ '$CFG->wwwroot/repository/ws.php?ctx_id=$context->id&repo_id='
+ +_client.repositoryid+'&action=download',
+ _client.dlfile, _client.postdata({'env':_client.env, 'file':file, 'title':title}));
}
_client.login = function(){
var obj = {};
panel.get('element').innerHTML = ret.e;
return;
}
- var html = '<h1>Download Successfully!</h1>';
- html += '<button onclick="repository_client_$suffix.end(\''+ret+'\')">Add!</button>';
- panel.get('element').innerHTML = html;
+ var title = document.createElement('h1');
+ title.innerHTML = '$strdownload';
+ var btn = document.createElement('button');
+ btn.innerHTML = '$stradd';
+ btn.onclick = function(){
+ repository_client_$suffix.end(ret);
+ }
+ panel.get('element').innerHTML = '';
+ panel.get('element').appendChild(title);
+ panel.get('element').appendChild(btn);
}
}
// request file list or login
var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?ctx_id=$context->id&repo_id='+id+'&p='+path+'&reset='+reset+'&env='+_client.env, _client.callback);
}
_client.search = function(id){
- var data = window.prompt("What are you searching for?");
- if(data == null || data == '') {
- alert('nothing entered');
+ var data = window.prompt("$strsearching");
+ if(data == '') {
+ alert('$strnoenter');
return;
}
_client.viewbar.set('disabled', false);
repository_client_$suffix.target = obj.target;
repository_client_$suffix.instance = new repository_client_$suffix();
repository_client_$suffix.instance.create_picker();
- if(obj.itemid){
- repository_client_$suffix.itemid = obj.itemid;
- }
if(obj.callback){
repository_client_$suffix.formcallback = obj.callback;
} else {
// opened in editor or moodleform
$env = optional_param('env', 'form', PARAM_ALPHA);
// file to download
-$file = optional_param('file', '', PARAM_URL);
+// TODO: which type should be?
+$file = optional_param('file', '', PARAM_RAW);
// rename the file name
$title = optional_param('title', '', PARAM_FILE);
$action = optional_param('action', '', PARAM_ALPHA);
// what will happen if user use a fake ctx_id?
// Think about using $SESSION save it
$ctx_id = optional_param('ctx_id', SITEID, PARAM_INT);
-$itemid = optional_param('itemid', 0, PARAM_INT);
$userid = $USER->id;
if(!$repository = $DB->get_record('repository', array('id'=>$repo_id)))
} elseif($action == 'download') {
$path = $repo->get_file($file, $title);
+ $itemid = (int)substr(hexdec(uniqid()), 0, 9)+rand(1,100);
try {
$info = move_to_filepool($path, $title, $itemid);
if($env == 'form'){