}
return $ret;
}
+
+function move_to_filepool($path, $name) {
+ global $DB, $CFG, $USER;
+ $context = get_context_instance(CONTEXT_USER, $USER->id);
+ $entry = new object();
+ $entry->filearea = 'user_draft';
+ $entry->contextid = $context->id;
+ $entry->filename = $name;
+ $entry->filepath = '/';
+ $entry->timecreated = time();
+ $entry->timemodified = time();
+ $entry->itemid = $USER->id;
+ $entry->mimetype = mimeinfo('type', $path);
+ $entry->userid = $USER->id;
+ $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());
+ // TODO
+ // get_params should include id value, talk to Petr.
+ $params = $ret->get_params();
+ $params['id'] = 88;
+ return array('url'=>$ret->get_url(),'id'=>$params['id']);
+ } else {
+ return null;
+ }
+}
+
+
function get_repository_client(){
global $CFG;
$strsubmit = get_string('submit', 'repository');
var file = document.getElementById('fileurl').value;
_client.loading();
var trans = YAHOO.util.Connect.asyncRequest('POST',
- '$CFG->wwwroot/repository/ws.php?id='+_client.repositoryid+'&action=download',
+ '$CFG->wwwroot/repository/ws.php?repo_id='+_client.repositoryid+'&action=download',
_client.dlfile, _client.postdata({'env':_client.env, 'file':file, 'title':title}));
}
_client.login = function(){
'$CFG->wwwroot/repository/ws.php', _client.callback,
_client.postdata(obj));
}
+ _client.end = function(str){
+ _client.target.value = str;
+ _client.viewfiles();
+ }
_client.callback = {
success: function(o) {
var panel = new YAHOO.util.Element('panel');
return;
}
var html = '<h1>Download Successfully!</h1>';
- html += '<a href="###" onclick="repository_client.viewfiles()">Back</a>';
+ //html += '<a href="###" onclick="repository_client.viewfiles()">Back</a>';
+ html += '<a href="###" onclick="repository_client.end(\''+ret+'\')">Add!</a>';
panel.get('element').innerHTML = html;
}
}
_client.viewbar.set('disabled', false);
_client.loading();
_client.repositoryid = id;
- var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?id='+id+'&p='+path+'&reset='+reset+'&env='+_client.env, _client.callback);
+ var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?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?");
}
_client.viewbar.set('disabled', false);
_client.loading();
- var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?id='+id+'&s='+data+'&env='+_client.env, _client.callback);
+ var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?repo_id='+id+'&s='+data+'&env='+_client.env, _client.callback);
}
return _client;
})();
function openpicker(obj) {
if(!repository_client.instance) {
repository_client.env = obj.env;
+ repository_client.target = obj.target;
repository_client.instance = new repository_client();
repository_client.instance.create_picker();
} else {
}
} elseif($action == 'download') {
- $ret = $repo->get_file($file, $title);
- // TODO
- // Ask Petr how to use FILE_API here
+ $path = $repo->get_file($file, $title);
try {
- $pathname = $ret;
- $entry = new object();
- $entry->contextid = SITEID;
- $entry->filearea = 'repository';
- $entry->filepath = '/';
- $entry->filename = $title;
- $entry->timecreated = time();
- $entry->timemodified = time();
- $entry->itemid = $USER->id;
- $entry->mimetype = mimeinfo('type', $pathname);
- $entry->userid = $USER->id;
- $fs = get_file_storage();
- if ($file = $fs->create_file_from_pathname($entry, $pathname)) {
- if($env == 'form'){
- // return reference id
- echo json_encode($file->get_itemid());
- } elseif($env == 'editor') {
- // return url
- // echo json_encode($file->get_content_file_location());
- } else {
- }
+ $info = move_to_filepool($path, $title);
+ if($env == 'form'){
+ echo json_encode($info['id']);
+ } elseif($env == 'editor') {
+ echo json_encode($info['url']);
+ } else {
}
} catch (repository_exception $e){
$err = new stdclass;