Ejemplo n.º 1
0
 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\" />&nbsp;" . 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;
 }
Ejemplo n.º 2
0
    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 . '/';
    $fs->create_directory($contextid, $filearea, $itemid, $newdirname, $USER->id);
    redirect('draftfiles.php?itemid=' . $itemid . '&amp;filepath=' . rawurlencode($newdirname) . '&amp;subdirs=' . $subdirs . '&amp;maxbytes=' . $maxbytes);
}
if (isset($_FILES['newfile']) and data_submitted() and confirm_sesskey()) {