. // /** * This file is used to browse repositories in non-javascript mode * * @since 2.0 * @package core * @subpackage repository * @copyright 2009 Dongsheng Cai * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once('../config.php'); require_once($CFG->libdir.'/filelib.php'); require_once('lib.php'); /// Wait as long as it takes for this script to finish set_time_limit(0); require_sesskey(); require_login(); // disable blocks in this page $PAGE->set_pagelayout('embedded'); // general parameters $action = optional_param('action', '', PARAM_ALPHA); $client_id = optional_param('client_id', '', PARAM_RAW); // client ID $itemid = optional_param('itemid', '', PARAM_INT); // parameters for repository $callback = optional_param('callback', '', PARAM_CLEANHTML); $contextid = optional_param('ctx_id', SYSCONTEXTID, PARAM_INT); // context ID $courseid = optional_param('course', SITEID, PARAM_INT); // course 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_RAW); $thumbnail = optional_param('thumbnail', '', PARAM_RAW); $targetpath = optional_param('targetpath', '', PARAM_PATH); $repo_id = optional_param('repo_id', 0, PARAM_INT); // repository ID $req_path = optional_param('p', '', PARAM_RAW); // the path in repository $curr_page = optional_param('page', '', PARAM_RAW); // What page in repository? $search_text = optional_param('s', '', PARAM_CLEANHTML); $maxfiles = optional_param('maxfiles', -1, PARAM_INT); // maxfiles $maxbytes = optional_param('maxbytes', 0, PARAM_INT); // maxbytes $subdirs = optional_param('subdirs', 0, PARAM_INT); // maxbytes // the path to save files $savepath = optional_param('savepath', '/', PARAM_PATH); // path in draft area $draftpath = optional_param('draftpath', '/', PARAM_PATH); // user context $user_context = get_context_instance(CONTEXT_USER, $USER->id); $PAGE->set_context($user_context); if (!$course = $DB->get_record('course', array('id'=>$courseid))) { print_error('invalidcourseid'); } $PAGE->set_course($course); // 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.'/lib.php')) { require_once($CFG->dirroot.'/repository/'.$type.'/lib.php'); $classname = 'repository_' . $type; try { $repo = new $classname($repo_id, $contextid, array('ajax'=>false, 'name'=>$repository->name, 'type'=>$type)); } catch (repository_exception $e){ print_error('pluginerror', 'repository'); } } else { print_error('invalidplugin', 'repository'); } } // Make sure maxbytes passed is within site filesize limits. $maxbytes = get_max_upload_file_size($CFG->maxbytes, $coursemaxbytes, $maxbytes); $params = array('ctx_id' => $contextid, 'itemid' => $itemid, 'env' => $env, 'course'=>$courseid, 'maxbytes'=>$maxbytes, 'maxfiles'=>$maxfiles, 'subdirs'=>$subdirs, 'sesskey'=>sesskey()); $params['action'] = 'browse'; $params['draftpath'] = $draftpath; $home_url = new moodle_url('/repository/draftfiles_manager.php', $params); $params['savepath'] = $savepath; $params['repo_id'] = $repo_id; $url = new moodle_url($CFG->httpswwwroot."/repository/filepicker.php", $params); $PAGE->set_url('/repository/filepicker.php', $params); switch ($action) { case 'upload': // The uploaded file has been processed in plugin construct function // redirect to default page try { $repo->upload('', $maxbytes); redirect($home_url, get_string('uploadsucc','repository')); } catch (moodle_exception $e) { // inject target URL $e->link = $PAGE->url->out(); echo $OUTPUT->header(); // hack: we need the embedded header here, standard error printing would not use it throw $e; } break; case 'search': echo '
'.get_string('back', 'repository')."
"; try { $search_result = $repo->search($search_text); $search_result['issearchresult'] = true; $search_result['repo_id'] = $repo_id; // TODO: need a better solution $purl = new moodle_url($url, array('search_paging' => 1, 'action' => 'search', 'repo_id' => $repo_id)); $pagingbar = new paging_bar($search_result['total'], $search_result['page'] - 1, $search_result['perpage'], $purl, 'p'); echo $OUTPUT->render($pagingbar); echo ''; foreach ($search_result['list'] as $item) { echo ''; echo ''; echo ''; echo ''; } echo '
'; echo ''; if (!empty($item['url'])) { echo html_writer::link($item['url'], $item['title'], array('target'=>'_blank')); } else { echo $item['title']; } echo ''; echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; echo '
'; } catch (repository_exception $e) { } break; case 'list': case 'sign': echo $OUTPUT->header(); echo $OUTPUT->container_start(); echo html_writer::link($url, get_string('back', 'repository')); echo $OUTPUT->container_end(); if ($repo->check_login()) { $list = $repo->get_listing($req_path, $curr_page); $dynload = !empty($list['dynload'])?true:false; if (!empty($list['upload'])) { echo '
'; echo ''; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo ''; echo '
'; } else { if (!empty($list['path'])) { foreach ($list['path'] as $p) { //echo '
'; //echo '
'; //echo '
'; //echo ''; //echo '
'; $pathurl = new moodle_url($url, array( 'p'=>$p['path'], 'action'=>'list', 'draftpath'=>$draftpath, 'savepath'=>$savepath )); echo '' . html_writer::link($pathurl, $p['name']) . ''; echo ' / '; } } if (!empty($list['page'])) { // TODO MDL-28482: need a better solution // paging_bar is not a good option because it starts page numbering from 0 and // repositories number pages starting from 1. $pagingurl = new moodle_url("$CFG->httpswwwroot/repository/filepicker.php?action=list&itemid=$itemid&ctx_id=$contextid&repo_id=$repo_id&course=$courseid&sesskey=". sesskey()); if (!isset($list['perpage']) && !isset($list['total'])) { $list['perpage'] = 10; // instead of setting perpage&total we use number of pages, the result is the same } if (empty($list['total'])) { if ($list['pages'] == -1) { $total = ($list['page'] + 2) * $list['perpage']; } else { $total = $list['pages'] * $list['perpage']; } } else { $total = $list['total']; } echo $OUTPUT->paging_bar($total, $list['page'], $list['perpage'], $pagingurl); } echo ''; foreach ($list['list'] as $item) { echo ''; echo ''; echo ''; echo ''; } echo '
'; echo ''; if (!empty($item['url'])) { echo html_writer::link($item['url'], $item['title'], array('target'=>'_blank')); } else { echo $item['title']; } echo ''; if (!isset($item['children'])) { echo '
'; echo ''; echo ''; echo '
'; echo '
'; echo ''; echo ''; echo ''; echo '
'; } else { echo '
'; echo ''; echo ''; echo '
'; } echo '
'; } } else { echo '
'; echo ''; echo ''; $repo->print_login(); echo '
'; } echo $OUTPUT->footer(); break; case 'download': $thefile = $repo->get_file($fileurl, $filename); $filesize = filesize($thefile['path']); if (($maxbytes!=-1) && ($filesize>$maxbytes)) { print_error('maxbytes'); } if (!empty($thefile)) { $record = new stdClass(); $record->filepath = $savepath; $record->filename = $filename; $record->component = 'user'; $record->filearea = 'draft'; $record->itemid = $itemid; $record->license = ''; $record->author = ''; $record->source = $thefile['url']; try { $info = repository::move_to_filepool($thefile['path'], $record); redirect($home_url, get_string('downloadsucc', 'repository')); } catch (moodle_exception $e) { // inject target URL $e->link = $PAGE->url->out(); echo $OUTPUT->header(); // hack: we need the embedded header here, standard error printing would not use it throw $e; } } else { print_error('cannotdownload', 'repository'); } break; case 'confirm': echo $OUTPUT->header(); echo '
'.get_string('back', 'repository').'
'; echo ''; echo '
'; echo ''; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo '
'; echo '
'; // the save path echo ' '; echo ' '; echo ' '; echo '
'; echo '
'; echo $OUTPUT->footer(); break; default: case 'plugins': $params = array(); $params['context'] = array($user_context, get_system_context()); $params['currentcontext'] = $PAGE->context; $params['return_types'] = FILE_INTERNAL; $repos = repository::get_instances($params); echo $OUTPUT->header(); echo html_writer::link($home_url->out(false), get_string('backtodraftfiles', 'repository')); echo '
'; echo ''; echo '
'; echo $OUTPUT->footer(); break; }