function _get_draftfiles($draftid, $suffix) { global $USER, $CFG; $html = ''; if (!($context = get_context_instance(CONTEXT_USER, $USER->id))) { } $contextid = $context->id; $filearea = 'user_draft'; $browser = get_file_browser(); $fs = get_file_storage(); $filepath = '/'; if (!($directory = $fs->get_file($context->id, 'user_draft', $draftid, $filepath, '.'))) { $directory = new virtual_root_file($context->id, 'user_draft', $draftid); $filepath = $directory->get_filepath(); } $files = $fs->get_directory_files($context->id, 'user_draft', $draftid, $directory->get_filepath()); $parent = $directory->get_parent_directory(); $html .= '<ul class="file-list" id="draftfiles-' . $suffix . '">'; foreach ($files as $file) { $filename = $file->get_filename(); $filenameurl = rawurlencode($filename); $filepath = $file->get_filepath(); $filesize = $file->get_filesize(); $filesize = $filesize ? display_size($filesize) : ''; $mimetype = $file->get_mimetype(); $icon = mimeinfo_from_type('icon', $mimetype); $viewurl = $browser->encodepath("{$CFG->wwwroot}/draftfile.php", "/{$contextid}/user_draft/{$draftid}" . $filepath . $filename, false, false); $html .= '<li>'; $html .= "<a href=\"{$viewurl}\"><img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" /> " . s($filename) . " ({$filesize})</a> "; $html .= "<a href=\"###\" onclick='rm_{$suffix}(" . $file->get_itemid() . ", \"" . $filename . "\", this)'><img src=\"{$CFG->pixpath}/t/delete.gif\" class=\"iconsmall\" /></a>"; $html .= '</li>'; } $html .= '</ul>'; return $html; }
/** * File browsing support for workshop file areas * * @package mod_workshop * @category files * * @param file_browser $browser * @param array $areas * @param stdClass $course * @param stdClass $cm * @param stdClass $context * @param string $filearea * @param int $itemid * @param string $filepath * @param string $filename * @return file_info instance or null if not found */ function workshop_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) { global $CFG, $DB, $USER; /** @var array internal cache for author names */ static $submissionauthors = array(); $fs = get_file_storage(); if ($filearea === 'submission_content' or $filearea === 'submission_attachment') { if (!has_capability('mod/workshop:viewallsubmissions', $context)) { return null; } if (is_null($itemid)) { // no itemid (submissionid) passed, display the list of all submissions require_once($CFG->dirroot . '/mod/workshop/fileinfolib.php'); return new workshop_file_info_submissions_container($browser, $course, $cm, $context, $areas, $filearea); } // make sure the user can see the particular submission in separate groups mode $gmode = groups_get_activity_groupmode($cm, $course); if ($gmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { // check there is at least one common group with both the $USER // and the submission author (this is not expected to be a frequent // usecase so we can live with pretty ineffective one query per submission here...) $sql = "SELECT 'x' FROM {workshop_submissions} s JOIN {user} a ON (a.id = s.authorid) JOIN {groups_members} agm ON (a.id = agm.userid) JOIN {user} u ON (u.id = ?) JOIN {groups_members} ugm ON (u.id = ugm.userid) WHERE s.example = 0 AND s.workshopid = ? AND s.id = ? AND agm.groupid = ugm.groupid"; $params = array($USER->id, $cm->instance, $itemid); if (!$DB->record_exists_sql($sql, $params)) { return null; } } // we are inside some particular submission container $filepath = is_null($filepath) ? '/' : $filepath; $filename = is_null($filename) ? '.' : $filename; if (!$storedfile = $fs->get_file($context->id, 'mod_workshop', $filearea, $itemid, $filepath, $filename)) { if ($filepath === '/' and $filename === '.') { $storedfile = new virtual_root_file($context->id, 'mod_workshop', $filearea, $itemid); } else { // not found return null; } } // Checks to see if the user can manage files or is the owner. // TODO MDL-33805 - Do not use userid here and move the capability check above. if (!has_capability('moodle/course:managefiles', $context) && $storedfile->get_userid() != $USER->id) { return null; } // let us display the author's name instead of itemid (submission id) if (isset($submissionauthors[$itemid])) { $topvisiblename = $submissionauthors[$itemid]; } else { $sql = "SELECT s.id, u.lastname, u.firstname FROM {workshop_submissions} s JOIN {user} u ON (s.authorid = u.id) WHERE s.example = 0 AND s.workshopid = ?"; $params = array($cm->instance); $rs = $DB->get_recordset_sql($sql, $params); foreach ($rs as $submissionauthor) { $title = s(fullname($submissionauthor)); // this is generally not unique... $submissionauthors[$submissionauthor->id] = $title; } $rs->close(); if (!isset($submissionauthors[$itemid])) { // should not happen return null; } else { $topvisiblename = $submissionauthors[$itemid]; } } $urlbase = $CFG->wwwroot . '/pluginfile.php'; // do not allow manual modification of any files! return new file_info_stored($browser, $context, $storedfile, $urlbase, $topvisiblename, true, true, false, false); } if ($filearea == 'instructauthors' or $filearea == 'instructreviewers') { // always only itemid 0 $filepath = is_null($filepath) ? '/' : $filepath; $filename = is_null($filename) ? '.' : $filename; $urlbase = $CFG->wwwroot.'/pluginfile.php'; if (!$storedfile = $fs->get_file($context->id, 'mod_workshop', $filearea, 0, $filepath, $filename)) { if ($filepath === '/' and $filename === '.') { $storedfile = new virtual_root_file($context->id, 'mod_workshop', $filearea, 0); } else { // not found return null; } } return new file_info_stored($browser, $context, $storedfile, $urlbase, $areas[$filearea], false, true, true, false); } }
if (isguestuser()) { print_error('noguest'); } if (!($context = get_context_instance(CONTEXT_USER, $USER->id))) { print_error('invalidcontext'); } $notice = ''; $contextid = $context->id; $filearea = 'user_draft'; $browser = get_file_browser(); $fs = get_file_storage(); if (!$subdirs) { $filepath = '/'; } if (!($directory = $fs->get_file($context->id, 'user_draft', $itemid, $filepath, '.'))) { $directory = new virtual_root_file($context->id, 'user_draft', $itemid); $filepath = $directory->get_filepath(); } $files = $fs->get_directory_files($context->id, 'user_draft', $itemid, $directory->get_filepath()); $parent = $directory->get_parent_directory(); $totalbytes = 0; foreach ($files as $hash => $file) { if (!$subdirs and $file->get_filepath() !== '/') { unset($files[$hash]); continue; } $totalbytes += $file->get_filesize(); } /// process actions if ($newdirname !== '' and data_submitted() and confirm_sesskey()) { $newdirname = $directory->get_filepath() . $newdirname . '/';