2009-06-08 06:25:53 +00:00
|
|
|
<?php
|
2009-11-06 09:07:46 +00:00
|
|
|
|
2009-06-08 06:25:53 +00:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
2009-11-06 09:07:46 +00:00
|
|
|
/**
|
|
|
|
* This file is used to browse repositories in non-javascript mode
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
* @package moodlecore
|
|
|
|
* @subpackage repository
|
|
|
|
* @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2009-06-08 06:25:53 +00:00
|
|
|
require_once('../config.php');
|
|
|
|
require_once($CFG->libdir.'/filelib.php');
|
|
|
|
require_once('lib.php');
|
2009-06-11 08:08:33 +00:00
|
|
|
/// Wait as long as it takes for this script to finish
|
|
|
|
set_time_limit(0);
|
|
|
|
|
2010-07-05 08:57:47 +00:00
|
|
|
debugging('TODO: needs to be converted to use new component and security rules', DEBUG_DEVELOPER);
|
2010-07-03 13:37:13 +00:00
|
|
|
|
2009-06-11 08:08:33 +00:00
|
|
|
require_login();
|
2009-06-08 06:25:53 +00:00
|
|
|
|
2009-09-02 05:43:01 +00:00
|
|
|
// disable blocks in this page
|
2009-12-16 18:00:58 +00:00
|
|
|
$PAGE->set_pagelayout('embedded');
|
2009-09-02 05:43:01 +00:00
|
|
|
|
|
|
|
// general parameters
|
|
|
|
$action = optional_param('action', '', PARAM_ALPHA);
|
2010-03-16 03:30:29 +00:00
|
|
|
$client_id = optional_param('client_id', '', PARAM_RAW); // client ID
|
2009-06-08 06:25:53 +00:00
|
|
|
$itemid = optional_param('itemid', '', PARAM_INT);
|
2009-09-02 05:43:01 +00:00
|
|
|
|
|
|
|
// parameters for repository
|
2009-06-08 06:25:53 +00:00
|
|
|
$callback = optional_param('callback', '', PARAM_CLEANHTML);
|
2010-03-15 06:29:47 +00:00
|
|
|
$contextid = optional_param('ctx_id', SYSCONTEXTID, PARAM_INT); // context ID
|
2010-03-07 16:40:25 +00:00
|
|
|
$courseid = optional_param('course', SITEID, PARAM_INT); // course ID
|
2009-09-02 05:43:01 +00:00
|
|
|
$env = optional_param('env', 'filepicker', PARAM_ALPHA); // opened in file picker, file manager or html editor
|
|
|
|
$filename = optional_param('filename', '', PARAM_FILE);
|
2010-04-29 07:01:00 +00:00
|
|
|
$fileurl = optional_param('fileurl', '', PARAM_RAW);
|
2009-09-02 05:43:01 +00:00
|
|
|
$thumbnail = optional_param('thumbnail', '', PARAM_RAW);
|
2009-09-04 06:48:26 +00:00
|
|
|
$targetpath = optional_param('targetpath', '', PARAM_PATH);
|
2009-09-02 05:43:01 +00:00
|
|
|
$repo_id = optional_param('repo_id', 0, PARAM_INT); // repository ID
|
|
|
|
$req_path = optional_param('p', '', PARAM_RAW); // the path in repository
|
2009-11-06 09:07:46 +00:00
|
|
|
$curr_page = optional_param('page', '', PARAM_RAW); // What page in repository?
|
2009-06-08 06:25:53 +00:00
|
|
|
$search_text = optional_param('s', '', PARAM_CLEANHTML);
|
|
|
|
|
2009-09-02 05:43:01 +00:00
|
|
|
// draft area
|
|
|
|
$newdirname = optional_param('newdirname', '', PARAM_FILE);
|
2009-09-04 06:48:26 +00:00
|
|
|
$newfilename = optional_param('newfilename', '', PARAM_FILE);
|
2009-09-02 05:43:01 +00:00
|
|
|
// path in draft area
|
|
|
|
$draftpath = optional_param('draftpath', '/', PARAM_PATH);
|
|
|
|
|
|
|
|
|
|
|
|
// user context
|
|
|
|
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
|
|
|
|
|
2009-08-04 14:06:41 +00:00
|
|
|
$PAGE->set_url('/repository/filepicker.php');
|
2010-03-07 16:40:25 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
|
|
|
|
print_error('invalidcourseid');
|
|
|
|
}
|
|
|
|
$PAGE->set_course($course);
|
2009-08-04 14:06:41 +00:00
|
|
|
|
2009-06-08 06:25:53 +00:00
|
|
|
// init repository plugin
|
2009-09-02 05:43:01 +00:00
|
|
|
//
|
2009-06-08 06:25:53 +00:00
|
|
|
$sql = 'SELECT i.name, i.typeid, r.type FROM {repository} r, {repository_instances} i '.
|
|
|
|
'WHERE i.id=? AND i.typeid=r.id';
|
2009-06-19 07:22:37 +00:00
|
|
|
if ($repository = $DB->get_record_sql($sql, array($repo_id))) {
|
2009-06-08 06:25:53 +00:00
|
|
|
$type = $repository->type;
|
2010-07-05 07:27:49 +00:00
|
|
|
if (file_exists($CFG->dirroot.'/repository/'.$type.'/lib.php')) {
|
|
|
|
require_once($CFG->dirroot.'/repository/'.$type.'/lib.php');
|
2009-06-19 07:22:37 +00:00
|
|
|
$classname = 'repository_' . $type;
|
|
|
|
try {
|
2009-09-02 05:43:01 +00:00
|
|
|
$repo = new $classname($repo_id, $contextid, array('ajax'=>false, 'name'=>$repository->name));
|
2009-06-19 07:22:37 +00:00
|
|
|
} catch (repository_exception $e){
|
|
|
|
print_error('pluginerror', 'repository');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print_error('invalidplugin', 'repository');
|
2009-06-08 06:25:53 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-02 05:43:01 +00:00
|
|
|
|
2010-07-03 13:37:13 +00:00
|
|
|
$url = new moodle_url($CFG->httpswwwroot."/repository/filepicker.php", array('ctx_id' => $contextid, 'itemid' => $itemid, 'env' => $env, 'course'=>$courseid));
|
2009-09-04 06:48:26 +00:00
|
|
|
$home_url = new moodle_url($url, array('action' => 'browse'));
|
2009-06-11 08:08:33 +00:00
|
|
|
|
2009-06-09 06:43:38 +00:00
|
|
|
switch ($action) {
|
2009-06-18 06:31:51 +00:00
|
|
|
case 'upload':
|
2009-06-19 07:22:37 +00:00
|
|
|
// The uploaded file has been processed in plugin construct function
|
2009-09-02 05:43:01 +00:00
|
|
|
// redirect to default page
|
2009-12-03 04:40:09 +00:00
|
|
|
$repo->upload();
|
2009-06-18 06:31:51 +00:00
|
|
|
redirect($url, get_string('uploadsucc','repository'));
|
|
|
|
break;
|
2009-09-02 05:43:01 +00:00
|
|
|
|
2009-06-09 06:43:38 +00:00
|
|
|
case 'deletedraft':
|
2009-09-02 05:43:01 +00:00
|
|
|
$contextid = $user_context->id;
|
2009-06-09 06:43:38 +00:00
|
|
|
$fs = get_file_storage();
|
2010-07-03 13:37:13 +00:00
|
|
|
if ($file = $fs->get_file($contextid, 'user', 'draft', $itemid, $draftpath, $filename)) {
|
2009-09-04 06:48:26 +00:00
|
|
|
if ($file->is_directory()) {
|
|
|
|
if ($file->get_parent_directory()) {
|
|
|
|
$draftpath = $file->get_parent_directory()->get_filepath();
|
|
|
|
} else {
|
|
|
|
$draftpath = '/';
|
|
|
|
}
|
|
|
|
}
|
2009-06-09 06:43:38 +00:00
|
|
|
if($result = $file->delete()) {
|
2009-09-04 06:48:26 +00:00
|
|
|
$url->param('draftpath', $draftpath);
|
|
|
|
$url->param('action', 'browse');
|
|
|
|
redirect($url);
|
2009-06-09 06:43:38 +00:00
|
|
|
} else {
|
2009-06-11 08:08:33 +00:00
|
|
|
print_error('cannotdelete', 'repository');
|
2009-06-09 06:43:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-09-02 05:43:01 +00:00
|
|
|
|
2009-06-18 07:58:37 +00:00
|
|
|
case 'search':
|
2009-08-04 14:06:41 +00:00
|
|
|
echo '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
|
2009-06-18 07:58:37 +00:00
|
|
|
try {
|
|
|
|
$search_result = $repo->search($search_text);
|
|
|
|
$search_result['search_result'] = true;
|
|
|
|
$search_result['repo_id'] = $repo_id;
|
2009-06-19 07:22:37 +00:00
|
|
|
|
|
|
|
// TODO: need a better solution
|
2010-03-22 01:55:40 +00:00
|
|
|
$purl = new moodle_url($url, array('search_paging' => 1, 'action' => 'search', 'repo_id' => $repo_id));
|
2010-02-17 16:59:41 +00:00
|
|
|
$pagingbar = new paging_bar($search_result['total'], $search_result['page'] - 1, $search_result['perpage'], $purl, 'p');
|
|
|
|
echo $OUTPUT->render($pagingbar);
|
2009-06-19 07:22:37 +00:00
|
|
|
|
2009-06-18 07:58:37 +00:00
|
|
|
echo '<table>';
|
|
|
|
foreach ($search_result['list'] as $item) {
|
|
|
|
echo '<tr>';
|
|
|
|
echo '<td><img src="'.$item['thumbnail'].'" />';
|
|
|
|
echo '</td><td>';
|
|
|
|
if (!empty($item['url'])) {
|
|
|
|
echo '<a href="'.$item['url'].'" target="_blank">'.$item['title'].'</a>';
|
|
|
|
} else {
|
|
|
|
echo $item['title'];
|
|
|
|
}
|
|
|
|
echo '</td>';
|
|
|
|
echo '<td>';
|
2009-06-19 07:22:37 +00:00
|
|
|
echo '<form method="post">';
|
2009-09-02 05:43:01 +00:00
|
|
|
echo '<input type="hidden" name="fileurl" value="'.$item['source'].'"/>';
|
2009-06-19 07:22:37 +00:00
|
|
|
echo '<input type="hidden" name="action" value="confirm"/>';
|
2009-09-02 05:43:01 +00:00
|
|
|
echo '<input type="hidden" name="filename" value="'.$item['title'].'"/>';
|
|
|
|
echo '<input type="hidden" name="thumbnail" value="'.$item['thumbnail'].'"/>';
|
2009-06-19 07:22:37 +00:00
|
|
|
echo '<input type="submit" value="'.get_string('select','repository').'" />';
|
|
|
|
echo '</form>';
|
2009-06-18 07:58:37 +00:00
|
|
|
echo '</td>';
|
2009-06-19 07:22:37 +00:00
|
|
|
echo '</tr>';
|
2009-06-18 07:58:37 +00:00
|
|
|
}
|
|
|
|
echo '</table>';
|
|
|
|
} catch (repository_exception $e) {
|
|
|
|
}
|
|
|
|
break;
|
2009-09-02 05:43:01 +00:00
|
|
|
|
2009-06-09 06:43:38 +00:00
|
|
|
case 'list':
|
|
|
|
case 'sign':
|
2009-09-04 06:48:26 +00:00
|
|
|
echo $OUTPUT->header();
|
2009-08-04 14:06:41 +00:00
|
|
|
echo '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
|
2009-06-08 06:25:53 +00:00
|
|
|
if ($repo->check_login()) {
|
2009-11-06 09:07:46 +00:00
|
|
|
$list = $repo->get_listing($req_path, $curr_page);
|
2009-06-08 06:25:53 +00:00
|
|
|
$dynload = !empty($list['dynload'])?true:false;
|
|
|
|
if (!empty($list['upload'])) {
|
2009-12-16 21:33:01 +00:00
|
|
|
echo '<form action="'.$url->out().'" method="post" enctype="multipart/form-data" style="display:inline">';
|
2009-06-18 06:31:51 +00:00
|
|
|
echo '<label>'.$list['upload']['label'].': </label>';
|
2009-06-08 06:25:53 +00:00
|
|
|
echo '<input type="file" name="repo_upload_file" /><br />';
|
2009-06-18 06:31:51 +00:00
|
|
|
echo '<input type="hidden" name="action" value="upload" /><br />';
|
2009-09-02 05:43:01 +00:00
|
|
|
echo '<input type="hidden" name="draftpath" value="'.$draftpath.'" /><br />';
|
2009-06-18 06:31:51 +00:00
|
|
|
echo '<input type="hidden" name="repo_id" value="'.$repo_id.'" /><br />';
|
2009-06-11 08:08:33 +00:00
|
|
|
echo '<input type="submit" value="'.get_string('upload', 'repository').'" />';
|
2009-06-08 06:25:53 +00:00
|
|
|
echo '</form>';
|
|
|
|
} else {
|
2009-06-11 02:54:33 +00:00
|
|
|
if (!empty($list['path'])) {
|
|
|
|
foreach ($list['path'] as $p) {
|
|
|
|
echo '<form method="post" style="display:inline">';
|
|
|
|
echo '<input type="hidden" name="p" value="'.$p['path'].'"';
|
|
|
|
echo '<input type="hidden" name="action" value="list"';
|
2009-09-02 05:43:01 +00:00
|
|
|
echo '<input type="hidden" name="draftpath" value="'.$draftpath.'" /><br />';
|
2009-06-11 02:54:33 +00:00
|
|
|
echo '<input type="submit" value="'.$p['name'].'" />';
|
|
|
|
echo '</form>';
|
2009-06-11 08:08:33 +00:00
|
|
|
echo '<strong> / </strong>';
|
2009-06-11 02:54:33 +00:00
|
|
|
}
|
2009-06-08 06:25:53 +00:00
|
|
|
}
|
2009-06-19 07:22:37 +00:00
|
|
|
if (!empty($list['page'])) {
|
|
|
|
// TODO: need a better solution
|
2010-03-07 16:40:25 +00:00
|
|
|
$pagingurl = new moodle_url("$CFG->httpswwwroot/repository/filepicker.php?action=list&itemid=$itemid&ctx_id=$contextid&repo_id=$repo_id&course=$courseid");
|
2010-02-17 16:59:41 +00:00
|
|
|
echo $OUTPUT->paging_bar($list['total'], $list['page'] - 1, $list['perpage'], $pagingurl);
|
2009-06-19 07:22:37 +00:00
|
|
|
}
|
2009-06-08 06:25:53 +00:00
|
|
|
echo '<table>';
|
|
|
|
foreach ($list['list'] as $item) {
|
|
|
|
echo '<tr>';
|
|
|
|
echo '<td><img src="'.$item['thumbnail'].'" />';
|
|
|
|
echo '</td><td>';
|
|
|
|
if (!empty($item['url'])) {
|
|
|
|
echo '<a href="'.$item['url'].'" target="_blank">'.$item['title'].'</a>';
|
|
|
|
} else {
|
|
|
|
echo $item['title'];
|
|
|
|
}
|
|
|
|
echo '</td>';
|
|
|
|
echo '<td>';
|
|
|
|
if (!isset($item['children'])) {
|
|
|
|
echo '<form method="post">';
|
2009-09-02 05:43:01 +00:00
|
|
|
echo '<input type="hidden" name="fileurl" value="'.$item['source'].'"/>';
|
2009-06-08 06:25:53 +00:00
|
|
|
echo '<input type="hidden" name="action" value="confirm"/>';
|
2009-09-02 05:43:01 +00:00
|
|
|
echo '<input type="hidden" name="draftpath" value="'.$draftpath.'" /><br />';
|
|
|
|
echo '<input type="hidden" name="filename" value="'.$item['title'].'"/>';
|
|
|
|
echo '<input type="hidden" name="thumbnail" value="'.$item['thumbnail'].'"/>';
|
2009-06-11 08:08:33 +00:00
|
|
|
echo '<input type="submit" value="'.get_string('select','repository').'" />';
|
2009-06-08 06:25:53 +00:00
|
|
|
echo '</form>';
|
|
|
|
} else {
|
|
|
|
echo '<form method="post">';
|
|
|
|
echo '<input type="hidden" name="p" value="'.$item['path'].'"/>';
|
2009-06-11 08:08:33 +00:00
|
|
|
echo '<input type="submit" value="'.get_string('enter', 'repository').'" />';
|
2009-06-08 06:25:53 +00:00
|
|
|
echo '</form>';
|
|
|
|
}
|
|
|
|
echo '</td>';
|
2009-06-19 07:22:37 +00:00
|
|
|
echo '</tr>';
|
2009-06-08 06:25:53 +00:00
|
|
|
}
|
|
|
|
echo '</table>';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo '<form method="post">';
|
|
|
|
echo '<input type="hidden" name="action" value="sign" />';
|
|
|
|
echo '<input type="hidden" name="repo_id" value="'.$repo_id.'" />';
|
2009-06-18 07:58:37 +00:00
|
|
|
$repo->print_login();
|
2009-06-08 06:25:53 +00:00
|
|
|
echo '</form>';
|
|
|
|
}
|
2009-08-06 14:07:52 +00:00
|
|
|
echo $OUTPUT->footer();
|
2009-06-09 06:43:38 +00:00
|
|
|
break;
|
2009-09-02 05:43:01 +00:00
|
|
|
|
2009-06-09 06:43:38 +00:00
|
|
|
case 'download':
|
2010-03-25 07:54:19 +00:00
|
|
|
$thefile = $repo->get_file($fileurl, $filename, $itemid);
|
|
|
|
if (!empty($thefile)) {
|
2010-04-29 07:01:00 +00:00
|
|
|
$record = new stdclass;
|
|
|
|
$record->filepath = $draftpath;
|
|
|
|
$record->filename = $filename;
|
2010-07-03 13:37:13 +00:00
|
|
|
$record->component = 'user';
|
|
|
|
$record->filearea = 'draft';
|
2010-04-29 07:01:00 +00:00
|
|
|
$record->itemid = $itemid;
|
|
|
|
$record->license = '';
|
|
|
|
$record->author = '';
|
|
|
|
$record->source = $thefile['url'];
|
|
|
|
$info = repository::move_to_filepool($thefile['path'], $record);
|
2009-06-09 06:43:38 +00:00
|
|
|
redirect($url, get_string('downloadsucc','repository'));
|
2009-06-19 07:22:37 +00:00
|
|
|
} else {
|
|
|
|
print_error('cannotdownload', 'repository');
|
2009-06-09 06:43:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2009-09-02 05:43:01 +00:00
|
|
|
|
2009-09-04 06:48:26 +00:00
|
|
|
case 'downloaddir':
|
|
|
|
$zipper = new zip_packer();
|
|
|
|
$fs = get_file_storage();
|
|
|
|
|
2010-07-03 13:37:13 +00:00
|
|
|
$file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, '.');
|
2009-09-04 06:48:26 +00:00
|
|
|
if ($file->get_parent_directory()) {
|
|
|
|
$parent_path = $file->get_parent_directory()->get_filepath();
|
|
|
|
$filename = trim($draftpath, '/').'.zip';
|
|
|
|
} else {
|
|
|
|
$parent_path = '/';
|
2010-06-09 06:44:31 +00:00
|
|
|
$filename = get_string('files').'.zip';
|
2009-09-04 06:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user_draft', $itemid, $parent_path, $filename, $USER->id)) {
|
|
|
|
$fileurl = $CFG->wwwroot . '/draftfile.php/' . $user_context->id .'/user_draft/'.$itemid.$parent_path.$filename;
|
|
|
|
header('Location: ' . $fileurl );
|
|
|
|
} else {
|
|
|
|
print_error('cannotdownloaddir', 'repository');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-06-09 06:43:38 +00:00
|
|
|
case 'confirm':
|
2009-09-04 06:48:26 +00:00
|
|
|
echo $OUTPUT->header();
|
2009-06-11 08:08:33 +00:00
|
|
|
echo '<div><a href="'.me().'">'.get_string('back', 'repository').'</a></div>';
|
2009-09-02 05:43:01 +00:00
|
|
|
echo '<img src="'.$thumbnail.'" />';
|
|
|
|
echo '<form method="post">';
|
|
|
|
echo '<table>';
|
|
|
|
echo ' <tr>';
|
|
|
|
echo ' <td><label>'.get_string('filename', 'repository').'</label></td>';
|
|
|
|
echo ' <td><input type="text" name="filename" value="'.$filename.'" /></td>';
|
|
|
|
echo ' <td><input type="hidden" name="fileurl" value="'.$fileurl.'" /></td>';
|
|
|
|
echo ' <td><input type="hidden" name="action" value="download" /></td>';
|
|
|
|
echo ' <td><input type="hidden" name="itemid" value="'.$itemid.'" /></td>';
|
|
|
|
echo ' </tr>';
|
2009-06-09 06:43:38 +00:00
|
|
|
echo '</table>';
|
|
|
|
echo '<div>';
|
2009-09-02 05:43:01 +00:00
|
|
|
// the save path
|
|
|
|
echo ' <input name="draftpath" type="hidden" value="'.$draftpath.'" />';
|
|
|
|
echo ' <input type="submit" value="'.get_string('download', 'repository').'" />';
|
2009-06-09 06:43:38 +00:00
|
|
|
echo '</div>';
|
|
|
|
echo '</form>';
|
2009-08-06 14:07:52 +00:00
|
|
|
echo $OUTPUT->footer();
|
2009-06-09 06:43:38 +00:00
|
|
|
break;
|
2009-09-02 05:43:01 +00:00
|
|
|
|
2009-06-18 06:31:51 +00:00
|
|
|
case 'plugins':
|
|
|
|
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
|
2009-11-06 09:07:46 +00:00
|
|
|
$params = array();
|
|
|
|
$params['context'] = array($user_context, get_system_context());
|
|
|
|
$params['currentcontext'] = $PAGE->context;
|
|
|
|
$params['returntypes'] = 2;
|
|
|
|
$repos = repository::get_instances($params);
|
2009-09-04 06:48:26 +00:00
|
|
|
echo $OUTPUT->header();
|
2009-09-02 05:43:01 +00:00
|
|
|
echo '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
|
|
|
|
echo '<div>';
|
|
|
|
echo '<ul>';
|
2009-06-18 06:31:51 +00:00
|
|
|
foreach($repos as $repo) {
|
|
|
|
$info = $repo->get_meta();
|
2010-01-02 13:17:54 +00:00
|
|
|
|
|
|
|
$aurl = clone($url);
|
|
|
|
$aurl->params(array('action' => 'list', 'repo_id' => $info->id, 'draftpath'=>$draftpath));
|
|
|
|
|
2009-09-03 06:53:40 +00:00
|
|
|
if ($env == 'filemanager' && $info->type == 'draft') {
|
|
|
|
continue;
|
|
|
|
}
|
2010-04-29 07:01:00 +00:00
|
|
|
echo '<li>';
|
|
|
|
echo html_writer::link($aurl, $info->name);
|
|
|
|
echo '</li>';
|
2009-06-18 06:31:51 +00:00
|
|
|
}
|
2009-09-02 05:43:01 +00:00
|
|
|
echo '</ul>';
|
|
|
|
echo '</div>';
|
|
|
|
echo $OUTPUT->footer();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'zip':
|
|
|
|
$zipper = new zip_packer();
|
|
|
|
$fs = get_file_storage();
|
|
|
|
|
2010-07-03 13:37:13 +00:00
|
|
|
$file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, '.');
|
2009-09-02 05:43:01 +00:00
|
|
|
if (!$file->get_parent_directory()) {
|
|
|
|
$parent_path = '/';
|
|
|
|
} else {
|
|
|
|
$parent_path = $file->get_parent_directory()->get_filepath();
|
|
|
|
}
|
|
|
|
|
2010-07-03 13:37:13 +00:00
|
|
|
$newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $file->get_filepath().'.zip', $USER->id);
|
2009-09-02 05:43:01 +00:00
|
|
|
|
|
|
|
$url->param('action', 'browse');
|
|
|
|
$url->param('draftpath', $parent_path);
|
|
|
|
redirect($url, get_string('ziped','repository'));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'unzip':
|
|
|
|
$zipper = new zip_packer();
|
|
|
|
$fs = get_file_storage();
|
2010-07-03 13:37:13 +00:00
|
|
|
$file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, $filename);
|
2009-09-02 05:43:01 +00:00
|
|
|
|
2010-07-03 13:37:13 +00:00
|
|
|
if ($newfile = $file->extract_to_storage($zipper, $user_context->id, 'user', 'draft', $itemid, $draftpath, $USER->id)) {
|
2009-09-02 05:43:01 +00:00
|
|
|
$str = get_string('unziped','repository');
|
|
|
|
} else {
|
|
|
|
$str = get_string('cannotunzip', 'repository');
|
|
|
|
}
|
|
|
|
$url->param('action', 'browse');
|
|
|
|
$url->param('draftpath', $draftpath);
|
|
|
|
redirect($url, $str);
|
|
|
|
break;
|
|
|
|
|
2009-09-04 06:48:26 +00:00
|
|
|
case 'movefile':
|
|
|
|
if (!empty($targetpath)) {
|
|
|
|
$fb = get_file_browser();
|
2010-07-03 13:37:13 +00:00
|
|
|
$file = $fb->get_file_info($user_context, 'user', 'draft', $itemid, $draftpath, $filename);
|
|
|
|
$file->copy_to_storage($user_context->id, 'user', 'draft', $itemid, $targetpath, $filename);
|
2009-09-04 06:48:26 +00:00
|
|
|
if ($file->delete()) {
|
|
|
|
$url->param('action', 'browse');
|
|
|
|
$url->param('draftpath', $targetpath);
|
|
|
|
redirect($url, '');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
echo '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
|
|
|
|
$data = new stdclass;
|
|
|
|
$url->param('action', 'movefile');
|
|
|
|
$url->param('draftpath', $draftpath);
|
|
|
|
$url->param('filename', $filename);
|
2010-07-03 13:37:13 +00:00
|
|
|
file_get_drafarea_folders($itemid, '/', $data);
|
2009-09-04 06:48:26 +00:00
|
|
|
print_draft_area_tree($data, true, $url);
|
|
|
|
echo $OUTPUT->footer();
|
|
|
|
break;
|
|
|
|
case 'mkdirform':
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
echo '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
|
|
|
|
$url->param('draftpath', $draftpath);
|
|
|
|
$url->param('action', 'mkdir');
|
|
|
|
echo ' <form method="post" action="'.$url->out().'">';
|
|
|
|
echo ' <input name="newdirname" type="text" />';
|
|
|
|
echo ' <input name="draftpath" type="hidden" value="'.$draftpath.'" />';
|
|
|
|
echo ' <input type="submit" value="'.get_string('makeafolder', 'moodle').'" />';
|
|
|
|
echo ' </form>';
|
|
|
|
echo $OUTPUT->footer();
|
|
|
|
break;
|
2009-09-02 05:43:01 +00:00
|
|
|
|
2009-09-04 06:48:26 +00:00
|
|
|
case 'mkdir':
|
|
|
|
$fs = get_file_storage();
|
2010-07-03 13:37:13 +00:00
|
|
|
$fs->create_directory($user_context->id, 'user', 'draft', $itemid, file_correct_filepath(file_correct_filepath($draftpath).trim($newdirname, '/')));
|
2009-09-04 06:48:26 +00:00
|
|
|
$url->param('action', 'browse');
|
|
|
|
$url->param('draftpath', $draftpath);
|
|
|
|
if (!empty($newdirname)) {
|
|
|
|
$str = get_string('createfoldersuccess', 'repository');
|
|
|
|
} else {
|
|
|
|
$str = get_string('createfolderfail', 'repository');
|
|
|
|
}
|
|
|
|
redirect($url, $str);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'rename':
|
|
|
|
$fs = get_file_storage();
|
2010-07-03 13:37:13 +00:00
|
|
|
if ($file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, $filename)) {
|
2009-09-04 06:48:26 +00:00
|
|
|
if ($file->is_directory()) {
|
|
|
|
if ($file->get_parent_directory()) {
|
|
|
|
$draftpath = $file->get_parent_directory()->get_filepath();
|
|
|
|
} else {
|
|
|
|
$draftpath = '/';
|
2009-09-02 05:43:01 +00:00
|
|
|
}
|
2009-09-04 06:48:26 +00:00
|
|
|
// use file storage to create new folder
|
|
|
|
$newdir = $draftpath . trim($newfilename , '/') . '/';
|
2010-07-03 13:37:13 +00:00
|
|
|
$fs->create_directory($user_context->id, 'user', 'draft', $itemid, $newdir);
|
2009-09-04 06:48:26 +00:00
|
|
|
} else {
|
|
|
|
// use file browser to copy file
|
|
|
|
$fb = get_file_browser();
|
2010-07-03 13:37:13 +00:00
|
|
|
$file = $fb->get_file_info($user_context, 'user', 'draft', $itemid, $draftpath, $filename);
|
|
|
|
$file->copy_to_storage($user_context->id, 'user', 'draft', $itemid, $draftpath, $newfilename);
|
2009-09-02 05:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-04 06:48:26 +00:00
|
|
|
$file->delete();
|
|
|
|
$url->param('action', 'browse');
|
|
|
|
$url->param('draftpath', $draftpath);
|
|
|
|
redirect($url);
|
|
|
|
break;
|
2009-09-02 05:43:01 +00:00
|
|
|
|
2009-09-04 06:48:26 +00:00
|
|
|
case 'renameform':
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
echo '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
|
|
|
|
$url->param('draftpath', $draftpath);
|
|
|
|
$url->param('action', 'rename');
|
|
|
|
echo ' <form method="post" action="'.$url->out().'">';
|
|
|
|
echo ' <input name="newfilename" type="text" value="'.$filename.'" />';
|
|
|
|
echo ' <input name="filename" type="hidden" value="'.$filename.'" />';
|
|
|
|
echo ' <input name="draftpath" type="hidden" value="'.$draftpath.'" />';
|
|
|
|
echo ' <input type="submit" value="'.get_string('rename', 'moodle').'" />';
|
|
|
|
echo ' </form>';
|
|
|
|
echo $OUTPUT->footer();
|
|
|
|
break;
|
2009-09-02 05:43:01 +00:00
|
|
|
|
2009-09-04 06:48:26 +00:00
|
|
|
case 'browse':
|
|
|
|
default:
|
|
|
|
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
|
2009-11-06 09:07:46 +00:00
|
|
|
$params = array();
|
|
|
|
$params['context'] = array($user_context, get_system_context());
|
|
|
|
$params['currentcontext'] = $PAGE->context;
|
|
|
|
$params['returntypes'] = 2;
|
|
|
|
$repos = repository::get_instances($params);
|
2009-06-11 08:08:33 +00:00
|
|
|
$fs = get_file_storage();
|
2010-07-03 13:37:13 +00:00
|
|
|
$files = $fs->get_directory_files($user_context->id, 'user', 'draft', $itemid, $draftpath, false);
|
2009-09-02 05:43:01 +00:00
|
|
|
|
2009-09-04 06:48:26 +00:00
|
|
|
echo $OUTPUT->header();
|
2009-09-09 04:59:58 +00:00
|
|
|
if ((!empty($files) or $draftpath != '/') and $env == 'filemanager') {
|
2009-09-04 06:48:26 +00:00
|
|
|
echo '<div class="fm-breadcrumb">';
|
|
|
|
$url->param('action', 'browse');
|
|
|
|
$url->param('draftpath', '/');
|
|
|
|
echo '<a href="'.$url->out().'">'.'Files</a> ▶';
|
|
|
|
$trail = '';
|
|
|
|
if ($draftpath !== '/') {
|
|
|
|
$path = file_correct_filepath($draftpath);
|
|
|
|
$parts = explode('/', $path);
|
|
|
|
foreach ($parts as $part) {
|
|
|
|
if (!empty($part)) {
|
|
|
|
$trail .= ('/'.$part.'/');
|
|
|
|
$data->path[] = array('name'=>$part, 'path'=>$trail);
|
|
|
|
$url->param('draftpath', $trail);
|
|
|
|
echo ' <a href="'.$url->out().'">'.$part.'</a> ▶ ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</div>';
|
|
|
|
}
|
2009-09-02 05:43:01 +00:00
|
|
|
|
2009-09-04 06:48:26 +00:00
|
|
|
$url->param('draftpath', $draftpath);
|
|
|
|
$url->param('action', 'plugins');
|
|
|
|
echo '<div class="filemanager-toolbar">';
|
2009-09-09 04:59:58 +00:00
|
|
|
if ($env == 'filepicker' and sizeof($files) > 0) {
|
|
|
|
} else {
|
|
|
|
echo ' <a href="'.$url->out().'">'.get_string('addfile', 'repository').'</a>';
|
|
|
|
}
|
|
|
|
if ($env == 'filemanager') {
|
|
|
|
$url->param('action', 'mkdirform');
|
|
|
|
echo ' <a href="'.$url->out().'">'.get_string('makeafolder', 'moodle').'</a>';
|
|
|
|
$url->param('action', 'downloaddir');
|
|
|
|
echo ' <a href="'.$url->out().'" target="_blank">'.get_string('downloadfolder', 'repository').'</a>';
|
|
|
|
}
|
2009-09-04 06:48:26 +00:00
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
if (!empty($files)) {
|
2009-06-11 08:08:33 +00:00
|
|
|
echo '<ul>';
|
|
|
|
foreach ($files as $file) {
|
2010-07-03 13:37:13 +00:00
|
|
|
$drafturl = new moodle_url($CFG->httpswwwroot.'/draftfile.php/'.$user_context->id.'/user/draft/'.$itemid.'/'.$file->get_filename());
|
2009-09-04 06:48:26 +00:00
|
|
|
if ($file->get_filename() != '.') {
|
2009-09-02 05:43:01 +00:00
|
|
|
// a file
|
|
|
|
$fileicon = $CFG->wwwroot.'/pix/'.(file_extension_icon($file->get_filename()));
|
|
|
|
$type = str_replace('.gif', '', mimeinfo('icon', $file->get_filename()));
|
|
|
|
echo '<li>';
|
|
|
|
echo '<img src="'.$fileicon. '" class="iconsmall" />';
|
|
|
|
echo ' <a href="'.$drafturl->out().'">'.$file->get_filename().'</a> ';
|
|
|
|
|
|
|
|
$url->param('filename', $file->get_filename());
|
2009-09-04 06:48:26 +00:00
|
|
|
|
2009-09-02 05:43:01 +00:00
|
|
|
$url->param('action', 'deletedraft');
|
2009-09-04 06:48:26 +00:00
|
|
|
$url->param('draftpath', $file->get_filepath());
|
|
|
|
echo ' [<a href="'.$url->out().'" class="fm-operation">'.get_string('delete').'</a>]';
|
|
|
|
|
|
|
|
$url->param('action', 'movefile');
|
|
|
|
echo ' [<a href="'.$url->out().'" class="fm-operation">'.get_string('move').'</a>]';
|
|
|
|
|
|
|
|
$url->param('action', 'renameform');
|
|
|
|
echo ' [<a href="'.$url->out().'" class="fm-operation">'.get_string('rename').'</a>]';
|
2009-09-02 05:43:01 +00:00
|
|
|
|
|
|
|
if ($type == 'zip') {
|
|
|
|
$url->param('action', 'unzip');
|
|
|
|
$url->param('draftpath', $file->get_filepath());
|
2009-09-04 06:48:26 +00:00
|
|
|
echo ' [<a href="'.$url->out().'" class="fm-operation">'.get_string('unzip').'</a>]';
|
2009-09-02 05:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '</li>';
|
|
|
|
} else {
|
|
|
|
// a folder
|
|
|
|
echo '<li>';
|
2009-12-16 21:50:45 +00:00
|
|
|
echo '<img src="'.$OUTPUT->pix_url('f/folder') . '" class="iconsmall" />';
|
2009-09-02 05:43:01 +00:00
|
|
|
|
|
|
|
$url->param('action', 'browse');
|
|
|
|
$url->param('draftpath', $file->get_filepath());
|
|
|
|
$foldername = trim(array_pop(explode('/', trim($file->get_filepath(), '/'))), '/');
|
|
|
|
echo ' <a href="'.$url->out().'">'.$foldername.'</a>';
|
|
|
|
|
|
|
|
$url->param('draftpath', $file->get_filepath());
|
|
|
|
$url->param('filename', $file->get_filename());
|
|
|
|
$url->param('action', 'deletedraft');
|
2009-09-04 06:48:26 +00:00
|
|
|
echo ' [<a href="'.$url->out().'" class="fm-operation">'.get_string('delete').'</a>]';
|
|
|
|
|
|
|
|
// file doesn't support rename yet
|
|
|
|
// for folder with existing files, we need to move these files one by one
|
|
|
|
//$url->param('action', 'renameform');
|
|
|
|
//echo ' [<a href="'.$url->out().'" class="fm-operation">'.get_string('rename').'</a>]';
|
2009-09-02 05:43:01 +00:00
|
|
|
|
|
|
|
$url->param('action', 'zip');
|
2009-09-04 06:48:26 +00:00
|
|
|
echo ' [<a href="'.$url->out().'" class="fm-operation">Zip</a>]';
|
2009-09-02 05:43:01 +00:00
|
|
|
echo '</li>';
|
2009-06-11 08:08:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</ul>';
|
2009-09-04 06:48:26 +00:00
|
|
|
} else {
|
|
|
|
//echo get_string('nofilesattached', 'repository');
|
2009-06-11 08:08:33 +00:00
|
|
|
}
|
2009-08-06 14:07:52 +00:00
|
|
|
echo $OUTPUT->footer();
|
2009-06-09 06:43:38 +00:00
|
|
|
break;
|
2009-06-08 06:25:53 +00:00
|
|
|
}
|
2009-09-04 06:48:26 +00:00
|
|
|
function print_draft_area_tree($tree, $root, $url) {
|
|
|
|
echo '<ul>';
|
|
|
|
if ($root) {
|
|
|
|
$url->param('targetpath', '/');
|
|
|
|
if ($url->param('draftpath') == '/') {
|
|
|
|
echo '<li>'.get_string('files').'</li>';
|
|
|
|
} else {
|
|
|
|
echo '<li><a href="'.$url->out().'">'.get_string('files').'</a></li>';
|
|
|
|
}
|
|
|
|
echo '<ul>';
|
|
|
|
if (isset($tree->children)) {
|
|
|
|
$tree = $tree->children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($tree)) {
|
|
|
|
foreach ($tree as $node) {
|
|
|
|
echo '<li>';
|
|
|
|
$url->param('targetpath', $node->filepath);
|
|
|
|
if ($url->param('draftpath') != $node->filepath) {
|
|
|
|
echo '<a href="'.$url->out().'">'.$node->fullname.'</a>';
|
|
|
|
} else {
|
|
|
|
echo $node->fullname;
|
|
|
|
}
|
|
|
|
echo '</li>';
|
|
|
|
if (!empty($node->children)) {
|
|
|
|
print_draft_area_tree($node->children, false, $url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($root) {
|
|
|
|
echo '</ul>';
|
|
|
|
}
|
|
|
|
echo '</ul>';
|
|
|
|
}
|
|
|
|
|