2009-06-08 06:25:53 +00:00
|
|
|
<?php
|
|
|
|
// 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/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
require_login();
|
2009-06-08 06:25:53 +00:00
|
|
|
|
|
|
|
$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);
|
|
|
|
$action = optional_param('action', '', PARAM_ALPHA);
|
|
|
|
$ctx_id = optional_param('ctx_id', SITEID, PARAM_INT); // context ID
|
2009-06-19 07:22:37 +00:00
|
|
|
$repo_id = optional_param('repo_id', 0, PARAM_INT); // repository ID
|
2009-06-08 06:25:53 +00:00
|
|
|
$req_path = optional_param('p', '', PARAM_RAW); // path
|
2009-06-19 07:22:37 +00:00
|
|
|
$page = optional_param('page', '', PARAM_RAW);
|
2009-06-08 06:25:53 +00:00
|
|
|
$callback = optional_param('callback', '', PARAM_CLEANHTML);
|
|
|
|
$search_text = optional_param('s', '', PARAM_CLEANHTML);
|
|
|
|
|
2009-08-04 14:06:41 +00:00
|
|
|
$PAGE->set_url('/repository/filepicker.php');
|
|
|
|
|
2009-06-08 06:25:53 +00:00
|
|
|
// 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';
|
2009-08-04 14:06:41 +00:00
|
|
|
|
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;
|
2009-06-19 07:22:37 +00:00
|
|
|
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));
|
|
|
|
} catch (repository_exception $e){
|
|
|
|
print_error('pluginerror', 'repository');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print_error('invalidplugin', 'repository');
|
2009-06-08 06:25:53 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-04 14:06:41 +00:00
|
|
|
$url = new moodle_url($CFG->httpswwwroot."/repository/filepicker.php", array('ctx_id' => $ctx_id, 'itemid' => $itemid));
|
|
|
|
$home_url = new moodle_url($url, array('action' => 'embedded'));
|
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-06-18 06:31:51 +00:00
|
|
|
redirect($url, get_string('uploadsucc','repository'));
|
|
|
|
break;
|
2009-06-09 06:43:38 +00:00
|
|
|
case 'deletedraft':
|
|
|
|
if (!$context = get_context_instance(CONTEXT_USER, $USER->id)) {
|
2009-06-11 08:08:33 +00:00
|
|
|
print_error('wrongcontextid', 'error');
|
2009-06-09 06:43:38 +00:00
|
|
|
}
|
|
|
|
$contextid = $context->id;
|
|
|
|
$fs = get_file_storage();
|
|
|
|
if ($file = $fs->get_file($contextid, 'user_draft', $itemid, '/', $title)) {
|
|
|
|
if($result = $file->delete()) {
|
2009-08-04 14:06:41 +00:00
|
|
|
header('Location: ' . $home_url->out(false, array(), false));
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
break;
|
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
|
2009-08-04 14:06:41 +00:00
|
|
|
$pagingbar = new moodle_paging_bar();
|
|
|
|
$pagingbar->totalcount = $search_result['total'];
|
|
|
|
$pagingbar->page = $search_result['page'] - 1;
|
|
|
|
$pagingbar->perpage = $search_result['perpage'];
|
|
|
|
$pagingbar->baseurl = clone($url);
|
|
|
|
$pagingbar->baseurl->params(array('search_paging' => 1, 'action' => 'search', 'repo_id' => $repo_id));
|
|
|
|
$pagingbar->pagevar = 'p';
|
|
|
|
echo $OUTPUT->paging_bar($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">';
|
|
|
|
echo '<input type="hidden" name="file" value="'.$item['source'].'"/>';
|
|
|
|
echo '<input type="hidden" name="action" value="confirm"/>';
|
|
|
|
echo '<input type="hidden" name="title" value="'.$item['title'].'"/>';
|
|
|
|
echo '<input type="hidden" name="icon" value="'.$item['thumbnail'].'"/>';
|
|
|
|
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-06-09 06:43:38 +00:00
|
|
|
case 'list':
|
|
|
|
case 'sign':
|
2009-06-11 08:08:33 +00:00
|
|
|
print_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-06-19 07:22:37 +00:00
|
|
|
$list = $repo->get_listing($req_path, $page);
|
2009-06-08 06:25:53 +00:00
|
|
|
$dynload = !empty($list['dynload'])?true:false;
|
|
|
|
if (!empty($list['upload'])) {
|
2009-08-04 14:06:41 +00:00
|
|
|
echo '<form action="'.$url->out(false).'" 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 />';
|
|
|
|
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"';
|
|
|
|
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
|
2009-08-07 00:34:17 +00:00
|
|
|
$pagingurl = new moodle_url("$CFG->httpswwwroot/repository/filepicker.php?action=list&itemid=$itemid&ctx_id=$ctx_id&repo_id=$repo_id");
|
|
|
|
echo $OUTPUT->paging_bar(moodle_paging_bar::make($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">';
|
|
|
|
echo '<input type="hidden" name="file" value="'.$item['source'].'"/>';
|
|
|
|
echo '<input type="hidden" name="action" value="confirm"/>';
|
|
|
|
echo '<input type="hidden" name="title" value="'.$item['title'].'"/>';
|
|
|
|
echo '<input type="hidden" name="icon" 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;
|
|
|
|
case 'download':
|
|
|
|
$filepath = $repo->get_file($file, $title, $itemid);
|
2009-06-19 07:22:37 +00:00
|
|
|
if (!empty($filepath)) {
|
2009-06-09 06:43:38 +00:00
|
|
|
// normal file path name
|
|
|
|
$info = repository::move_to_filepool($filepath, $title, $itemid);
|
|
|
|
//echo json_encode($info);
|
|
|
|
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;
|
|
|
|
case 'confirm':
|
2009-06-11 08:08:33 +00:00
|
|
|
print_header();
|
|
|
|
echo '<div><a href="'.me().'">'.get_string('back', 'repository').'</a></div>';
|
2009-06-09 06:43:38 +00:00
|
|
|
echo '<img src="'.$icon.'" />';
|
|
|
|
echo '<form method="post"><table>';
|
|
|
|
echo '<tr>';
|
|
|
|
echo '<td><label>'.get_string('filename', 'repository').'</label></td>';
|
|
|
|
echo '<td><input type="text" name="title" value="'.$title.'" /></td>';
|
|
|
|
echo '<td><input type="hidden" name="file" value="'.$file.'" /></td>';
|
|
|
|
echo '<td><input type="hidden" name="action" value="download" /></td>';
|
|
|
|
echo '<td><input type="hidden" name="itemid" value="'.$itemid.'" /></td>';
|
|
|
|
echo '</tr>';
|
|
|
|
echo '</table>';
|
|
|
|
echo '<div>';
|
|
|
|
echo '<input type="submit" value="'.get_string('download', 'repository').'" />';
|
|
|
|
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-06-18 06:31:51 +00:00
|
|
|
case 'plugins':
|
|
|
|
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
|
|
|
|
$repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id');
|
|
|
|
print_header();
|
|
|
|
echo '<div><ul>';
|
|
|
|
foreach($repos as $repo) {
|
|
|
|
$info = $repo->get_meta();
|
2009-08-10 06:37:29 +00:00
|
|
|
$icon = new moodle_action_icon();
|
2009-08-04 14:06:41 +00:00
|
|
|
$icon->image->src = $info->icon;
|
|
|
|
$icon->image->style = 'height: 16px; width: 16px;';
|
|
|
|
$icon->link->url = clone($url);
|
|
|
|
$icon->link->url->params(array('action' => 'list', 'repo_id' => $info->id));
|
|
|
|
$icon->linktext = $info->name;
|
|
|
|
echo '<li>' . $OUTPUT->action_icon($icon) . '</li>';
|
2009-06-18 06:31:51 +00:00
|
|
|
}
|
|
|
|
echo '</ul></div>';
|
|
|
|
break;
|
2009-06-09 06:43:38 +00:00
|
|
|
default:
|
2009-06-08 06:25:53 +00:00
|
|
|
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
|
|
|
|
$repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id');
|
2009-06-11 08:08:33 +00:00
|
|
|
print_header();
|
|
|
|
$fs = get_file_storage();
|
|
|
|
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
|
|
|
$files = $fs->get_area_files($context->id, 'user_draft', $itemid);
|
|
|
|
if (empty($files)) {
|
|
|
|
echo get_string('nofilesattached', 'repository');
|
|
|
|
} else {
|
|
|
|
echo '<ul>';
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file->get_filename()!='.') {
|
2009-08-04 14:06:41 +00:00
|
|
|
$drafturl = new moodle_url($CFG->httpswwwroot.'/draftfile.php/'.$context->id.'/user_draft/'.$itemid.'/'.$file->get_filename());
|
|
|
|
echo '<li><a href="'.$drafturl->out().'">'.$file->get_filename().'</a> ';
|
2009-07-02 11:09:15 +00:00
|
|
|
echo '<a href="'.$CFG->httpswwwroot.'/repository/filepicker.php?action=deletedraft&itemid='.$itemid.'&ctx_id='.$ctx_id.'&title='.$file->get_filename().'"><img src="'.$OUTPUT->old_icon_url('t/delete') . '" class="iconsmall" /></a></li>';
|
2009-06-11 08:08:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</ul>';
|
|
|
|
}
|
2009-08-04 14:06:41 +00:00
|
|
|
$url->param('action', 'plugins');
|
|
|
|
echo '<div><a href="'.$url->out().'">'.get_string('addfile', 'repository').'</a></div>';
|
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
|
|
|
}
|