case 'movefile':
     if (!empty($targetpath)) {
         repository::update_draftfile($itemid, $draftpath, $filename, array('filepath' => $targetpath));
         $home_url->param('action', 'browse');
         $home_url->param('draftpath', $targetpath);
         redirect($home_url);
     }
     echo $OUTPUT->header();
     echo $OUTPUT->container_start();
     echo html_writer::link($home_url, get_string('back', 'repository'));
     echo $OUTPUT->container_end();
     $data = new stdClass();
     $home_url->param('action', 'movefile');
     $home_url->param('draftpath', $draftpath);
     $home_url->param('filename', $filename);
     file_get_drafarea_folders($itemid, '/', $data);
     print_draft_area_tree($data, true, $home_url);
     echo $OUTPUT->footer();
     break;
 case 'mkdirform':
     echo $OUTPUT->header();
     echo $OUTPUT->container_start();
     echo html_writer::link($home_url, get_string('back', 'repository'));
     echo $OUTPUT->container_end();
     $home_url->param('draftpath', $draftpath);
     $home_url->param('action', 'mkdir');
     echo ' <form method="post" action="' . $home_url->out() . '">';
     echo html_writer::label(get_string('entername', 'repository'), 'newdirname', array('class' => 'accesshide'));
     echo '  <input name="newdirname" id="newdirname" type="text" />';
     echo '  <input name="draftpath" type="hidden" value="' . s($draftpath) . '" />';
     echo '  <input type="submit" value="' . s(get_string('makeafolder', 'moodle')) . '" />';
Example #2
0
//NOTE TO ALL DEVELOPERS: this script must deal only with draft area of current user, it has to use only file_storage and no file_browser!!
//
switch ($action) {
    case 'dir':
        $data = new stdClass();
        file_get_drafarea_folders($draftid, $filepath, $data);
        echo json_encode($data);
        die;
    case 'list':
        $filepath = optional_param('filepath', '/', PARAM_PATH);
        $data = repository::prepare_listing(file_get_drafarea_files($draftid, $filepath));
        $info = file_get_draft_area_info($draftid);
        $data->filecount = $info['filecount'];
        $data->filesize = $info['filesize'];
        $data->tree = new stdClass();
        file_get_drafarea_folders($draftid, '/', $data->tree);
        echo json_encode($data);
        die;
    case 'mkdir':
        $filepath = required_param('filepath', PARAM_PATH);
        $newdirname = required_param('newdirname', PARAM_FILE);
        $fs = get_file_storage();
        $fs->create_directory($user_context->id, 'user', 'draft', $draftid, file_correct_filepath(file_correct_filepath($filepath) . $newdirname));
        $return = new stdClass();
        $return->filepath = $filepath;
        echo json_encode($return);
        die;
    case 'delete':
        $filename = required_param('filename', PARAM_FILE);
        $filepath = required_param('filepath', PARAM_PATH);
        $fs = get_file_storage();
Example #3
0
/**
 * Generate a folder tree of draft area of current USER recursively
 *
 * @todo MDL-31073 use normal return value instead, this does not fit the rest of api here (skodak)
 * @param int $draftitemid
 * @param string $filepath
 * @param mixed $data
 */
function file_get_drafarea_folders($draftitemid, $filepath, &$data)
{
    global $USER, $OUTPUT, $CFG;
    $data->children = array();
    $context = context_user::instance($USER->id);
    $fs = get_file_storage();
    if ($files = $fs->get_directory_files($context->id, 'user', 'draft', $draftitemid, $filepath, false)) {
        foreach ($files as $file) {
            if ($file->is_directory()) {
                $item = new stdClass();
                $item->sortorder = $file->get_sortorder();
                $item->filepath = $file->get_filepath();
                $foldername = explode('/', trim($item->filepath, '/'));
                $item->fullname = trim(array_pop($foldername), '/');
                $item->id = uniqid();
                file_get_drafarea_folders($draftitemid, $item->filepath, $item);
                $data->children[] = $item;
            } else {
                continue;
            }
        }
    }
}
Example #4
0
    print_error('noguest');
}
require_sesskey();
$action = required_param('action', PARAM_ALPHA);
$draftid = required_param('itemid', PARAM_INT);
$filepath = optional_param('filepath', '/', PARAM_PATH);
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
echo $OUTPUT->header();
// send headers
//
//NOTE TO ALL DEVELOPERS: this script must deal only with draft area of current user, it has to use only file_storage and no file_browser!!
//
switch ($action) {
    case 'dir':
        $data = new stdClass();
        file_get_drafarea_folders($draftid, $filepath, $data);
        echo json_encode($data);
        die;
    case 'list':
        $filepath = optional_param('filepath', '/', PARAM_PATH);
        $data = file_get_drafarea_files($draftid, $filepath);
        echo json_encode($data);
        die;
    case 'mkdir':
        $filepath = required_param('filepath', PARAM_PATH);
        $newdirname = required_param('newdirname', PARAM_FILE);
        $fs = get_file_storage();
        $fs->create_directory($user_context->id, 'user', 'draft', $draftid, file_correct_filepath(file_correct_filepath($filepath) . $newdirname));
        $return = new stdClass();
        $return->filepath = $filepath;
        echo json_encode($return);