diff --git a/repository/filepicker.php b/repository/filepicker.php index ba9788d075f..5250764136b 100755 --- a/repository/filepicker.php +++ b/repository/filepicker.php @@ -23,34 +23,48 @@ set_time_limit(0); require_login(); -$page = optional_param('page', '', PARAM_RAW); // page -$client_id = optional_param('client_id', SITEID, PARAM_RAW); // client ID -$env = optional_param('env', 'filepicker', PARAM_ALPHA); // opened in editor or moodleform -$file = optional_param('file', '', PARAM_RAW); // file to download -$title = optional_param('title', '', PARAM_FILE); // new file name -$itemid = optional_param('itemid', '', PARAM_INT); -$icon = optional_param('icon', '', PARAM_RAW); +// disable blocks in this page +$PAGE->set_generaltype('form'); + +// general parameters $action = optional_param('action', '', PARAM_ALPHA); -$ctx_id = optional_param('ctx_id', SITEID, PARAM_INT); // context ID -$repo_id = optional_param('repo_id', 0, PARAM_INT); // repository ID -$req_path = optional_param('p', '', PARAM_RAW); // path -$page = optional_param('page', '', PARAM_RAW); +$client_id = optional_param('client_id', SITEID, PARAM_RAW); // client ID +$itemid = optional_param('itemid', '', PARAM_INT); + +// parameters for repository $callback = optional_param('callback', '', PARAM_CLEANHTML); +$contextid = optional_param('ctx_id', SITEID, PARAM_INT); // context ID +$env = optional_param('env', 'filepicker', PARAM_ALPHA); // opened in file picker, file manager or html editor +$filename = optional_param('filename', '', PARAM_FILE); +$fileurl = optional_param('fileurl', '', PARAM_FILE); +$thumbnail = optional_param('thumbnail', '', PARAM_RAW); +$repo_id = optional_param('repo_id', 0, PARAM_INT); // repository ID +$req_path = optional_param('p', '', PARAM_RAW); // the path in repository +$page = optional_param('page', '', PARAM_RAW); // What page in repository? $search_text = optional_param('s', '', PARAM_CLEANHTML); +// draft area +$newdirname = optional_param('newdirname', '', PARAM_FILE); +// path in draft area +$draftpath = optional_param('draftpath', '/', PARAM_PATH); + + +// user context +$user_context = get_context_instance(CONTEXT_USER, $USER->id); + $PAGE->set_url('/repository/filepicker.php'); // init repository plugin +// $sql = 'SELECT i.name, i.typeid, r.type FROM {repository} r, {repository_instances} i '. 'WHERE i.id=? AND i.typeid=r.id'; - if ($repository = $DB->get_record_sql($sql, array($repo_id))) { $type = $repository->type; if (file_exists($CFG->dirroot.'/repository/'.$type.'/repository.class.php')) { require_once($CFG->dirroot.'/repository/'.$type.'/repository.class.php'); $classname = 'repository_' . $type; try { - $repo = new $classname($repo_id, $ctx_id, array('ajax'=>false, 'name'=>$repository->name, 'client_id'=>$client_id)); + $repo = new $classname($repo_id, $contextid, array('ajax'=>false, 'name'=>$repository->name)); } catch (repository_exception $e){ print_error('pluginerror', 'repository'); } @@ -58,29 +72,29 @@ if ($repository = $DB->get_record_sql($sql, array($repo_id))) { print_error('invalidplugin', 'repository'); } } -$url = new moodle_url($CFG->httpswwwroot."/repository/filepicker.php", array('ctx_id' => $ctx_id, 'itemid' => $itemid)); + +$url = new moodle_url($CFG->httpswwwroot."/repository/filepicker.php", array('ctx_id' => $contextid, 'itemid' => $itemid)); $home_url = new moodle_url($url, array('action' => 'embedded')); switch ($action) { case 'upload': // The uploaded file has been processed in plugin construct function + // redirect to default page redirect($url, get_string('uploadsucc','repository')); break; + case 'deletedraft': - if (!$context = get_context_instance(CONTEXT_USER, $USER->id)) { - print_error('wrongcontextid', 'error'); - } - $contextid = $context->id; + $contextid = $user_context->id; $fs = get_file_storage(); - if ($file = $fs->get_file($contextid, 'user_draft', $itemid, '/', $title)) { + if ($file = $fs->get_file($contextid, 'user_draft', $itemid, $draftpath, $filename)) { if($result = $file->delete()) { header('Location: ' . $home_url->out(false, array(), false)); } else { print_error('cannotdelete', 'repository'); } } - exit; break; + case 'search': echo '
"; try { @@ -111,10 +125,10 @@ case 'search': echo ''; echo '| ';
if (!isset($item['children'])) {
echo '';
} else {
@@ -195,76 +213,202 @@ case 'sign':
}
echo $OUTPUT->footer();
break;
+
case 'download':
- $filepath = $repo->get_file($file, $title, $itemid);
+ $filepath = $repo->get_file($fileurl, $filename, $itemid);
if (!empty($filepath)) {
- // normal file path name
- $info = repository::move_to_filepool($filepath, $title, $itemid);
- //echo json_encode($info);
+ $info = repository::move_to_filepool($filepath, $filename, $itemid, $draftpath);
redirect($url, get_string('downloadsucc','repository'));
} else {
print_error('cannotdownload', 'repository');
}
break;
+
case 'confirm':
print_header();
echo '';
- echo ' |