From: dongsheng Date: Tue, 9 Jun 2009 06:43:38 +0000 (+0000) Subject: "MDL-17316, display attached files in non-js file manager" X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=14f3c8827a076c9f656e7291e58c669ce6aa92cc;p=moodle.git "MDL-17316, display attached files in non-js file manager" --- diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php index 7a9603ff57..4de2e650cf 100644 --- a/lib/form/filemanager.php +++ b/lib/form/filemanager.php @@ -175,7 +175,6 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
- $accessiblefp
EOD; if (empty($CFG->filemanagerjsloaded)) { @@ -225,6 +224,12 @@ function callpicker(el_id, client_id, itemid) { } //]]> + EOD; $CFG->filemanagerjsloaded = true; } diff --git a/repository/filepicker.php b/repository/filepicker.php index d8cb4359d5..19d23454c1 100755 --- a/repository/filepicker.php +++ b/repository/filepicker.php @@ -57,57 +57,55 @@ if (file_exists($CFG->dirroot.'/repository/'.$type.'/repository.class.php')) { $err->e = get_string('invalidplugin', 'repository', $type); die(json_encode($err)); } - -if ($action == 'download') { - $filepath = $repo->get_file($file, $title, $itemid); - if (preg_match('#(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)#', $filepath)) { - // youtube plugin return a url instead a file path - $url = $filepath; - echo json_encode(array( - /* File picker need to know this is a link - * in order to attach title to url - */ - 'type'=>'link', - 'client_id'=>$client_id, - 'url'=>$url, - 'id'=>$url, - 'file'=>$url - ) - ); - } else if (is_array($filepath)) { - // file api don't have real file path, so we need more file api specific info for "local" plugin - $fileinfo = $filepath; - $info = array(); - $info['file'] = $fileinfo['title']; - $info['id'] = $itemid; - $info['url'] = $CFG->httpswwwroot.'/draftfile.php/'.$fileinfo['contextid'].'/user_draft/'.$itemid.'/'.$fileinfo['title']; - echo json_encode($info); - } else { - // normal file path name - $info = repository::move_to_filepool($filepath, $title, $itemid); - //echo json_encode($info); - redirect($url, get_string('downloadsucc','repository')); +//$context = get_context_instance_by_id($ctx_id); +//$PAGE->set_course($context); +switch ($action) { +case 'embedded': + echo << + + + + + +EOD; + $fs = get_file_storage(); + $context = get_context_instance(CONTEXT_USER, $USER->id); + $files = $fs->get_area_files($context->id, 'user_draft', $itemid); + echo ''; + echo ''; + exit; + break; +case 'deletedraft': + if (!$context = get_context_instance(CONTEXT_USER, $USER->id)) { + echo 'non exist'; + } + $contextid = $context->id; + $fs = get_file_storage(); + if ($file = $fs->get_file($contextid, 'user_draft', $itemid, '/', $title)) { + if($result = $file->delete()) { + header("Location: $CFG->httpswwwroot/repository/filepicker.php?action=embedded&itemid=$itemid&ctx_id=$ctx_id"); + } else { + echo 'not deleteed'; + } + } + exit; + break; +case 'list': +case 'sign': -} else if ($action == 'list' or $action == 'sign') { $navlinks = array(); $navlinks[] = array('name' => 'filepicker', 'link' => $url, 'type' => 'activityinstance'); $navlinks[] = array('name' => $repo->get_name()); @@ -173,7 +171,58 @@ if ($action == 'download') { echo ''; } print_footer('empty'); -} else { + break; +case 'download': + $filepath = $repo->get_file($file, $title, $itemid); + if (preg_match('#(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)#', $filepath)) { + // youtube plugin return a url instead a file path + $url = $filepath; + echo json_encode(array( + /* File picker need to know this is a link + * in order to attach title to url + */ + 'type'=>'link', + 'client_id'=>$client_id, + 'url'=>$url, + 'id'=>$url, + 'file'=>$url + ) + ); + } else if (is_array($filepath)) { + // file api don't have real file path, so we need more file api specific info for "local" plugin + $fileinfo = $filepath; + $info = array(); + $info['file'] = $fileinfo['title']; + $info['id'] = $itemid; + $info['url'] = $CFG->httpswwwroot.'/draftfile.php/'.$fileinfo['contextid'].'/user_draft/'.$itemid.'/'.$fileinfo['title']; + echo json_encode($info); + } else { + // normal file path name + $info = repository::move_to_filepool($filepath, $title, $itemid); + //echo json_encode($info); + redirect($url, get_string('downloadsucc','repository')); + } + + break; +case 'confirm': + print_header(get_string('download', 'repository'), get_string('download', 'repository')); + echo ''; + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'; + echo '
'; + echo ''; + echo '
'; + echo '
'; + print_footer('empty'); + break; +default: $user_context = get_context_instance(CONTEXT_USER, $USER->id); $repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id'); $navlinks = array(); @@ -187,5 +236,5 @@ if ($action == 'download') { } echo ''; print_footer('empty'); + break; } -