Ejemplo n.º 1
0
function displaydir($wdir)
{
    //  $wdir == / or /a or /a/b/c/d  etc
    global $basedir;
    global $id;
    global $qid;
    global $USER, $CFG;
    global $choose;
    $fullpath = $basedir . $wdir;
    $dirlist = array();
    $directory = opendir($fullpath);
    // Find all files
    while (false !== ($file = readdir($directory))) {
        if ($file == "." || $file == "..") {
            continue;
        }
        if (is_dir($fullpath . "/" . $file)) {
            $dirlist[] = $file;
        } else {
            $filelist[] = $file;
        }
    }
    closedir($directory);
    $strname = get_string("name");
    $strsize = get_string("size");
    $strmodified = get_string("modified");
    $straction = get_string("action");
    $strmakeafolder = get_string("makeafolder");
    $struploadafile = get_string("uploadafile");
    $strselectall = get_string("selectall");
    $strselectnone = get_string("deselectall");
    $strwithchosenfiles = get_string("withchosenfiles");
    $strmovetoanotherfolder = get_string("movetoanotherfolder");
    $strmovefilestohere = get_string("movefilestohere");
    $strdeletecompletely = get_string("deletecompletely");
    $strcreateziparchive = get_string("createziparchive");
    $strrename = get_string("rename");
    $stredit = get_string("edit");
    $strunzip = get_string("unzip");
    $strlist = get_string("list");
    $strrestore = get_string("restore");
    $strchoose = get_string("choose");
    $strfolder = get_string("folder");
    $strfile = get_string("file");
    echo "<form action=\"files.php\" method=\"post\" id=\"dirform\">";
    echo "<div>";
    echo '<input type="hidden" name="choose" value="' . $choose . '" />';
    // echo "<hr align=\"center\" noshade=\"noshade\" size=\"1\" />";
    echo "<hr/>";
    echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\" class=\"files\">";
    echo "<tr>";
    echo "<th scope=\"col\"></th>";
    echo "<th class=\"header name\" scope=\"col\">{$strname}</th>";
    echo "<th class=\"header size\" scope=\"col\">{$strsize}</th>";
    echo "<th class=\"header date\" scope=\"col\">{$strmodified}</th>";
    echo "<th class=\"header commands\" scope=\"col\">{$straction}</th>";
    echo "</tr>\n";
    if ($wdir != "/") {
        $dirlist[] = '..';
    }
    $count = 0;
    if (!empty($dirlist)) {
        asort($dirlist);
        foreach ($dirlist as $dir) {
            echo "<tr class=\"folder\">";
            if ($dir == '..') {
                //only display parent if we are not in root of question
                if ($qid == -1) {
                    $tempstr = webwork_get_tmp_path() . '/';
                } else {
                    $tempstr = WWQUESTION_ROOTDIR . '/' . $qid . '/';
                }
                if ($tempstr != $wdir) {
                    $fileurl = rawurlencode(dirname($wdir));
                    print_cell();
                    // alt attribute intentionally empty to prevent repetition in screen reader
                    print_cell('left', '<a href="files.php?id=' . $id . '&amp;qid=' . $qid . '&amp;wdir=' . $fileurl . '&amp;choose=' . $choose . '"><img src="' . $CFG->pixpath . '/f/parent.gif" class="icon" alt="" />&nbsp;' . get_string('parentfolder') . '</a>', 'name');
                    print_cell();
                    print_cell();
                    print_cell();
                }
            } else {
                $count++;
                $filename = $fullpath . "/" . $dir;
                $fileurl = rawurlencode($wdir . "/" . $dir);
                $filesafe = rawurlencode($dir);
                $filesize = display_size(get_directory_size("{$fullpath}/{$dir}"));
                $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
                print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" />", 'checkbox');
                print_cell("left", "<a href=\"files.php?id={$id}&amp;qid={$qid}&amp;wdir={$fileurl}&amp;choose={$choose}\"><img src=\"{$CFG->pixpath}/f/folder.gif\" class=\"icon\" alt=\"{$strfolder}\" />&nbsp;" . htmlspecialchars($dir) . "</a>", 'name');
                print_cell("right", $filesize, 'size');
                print_cell("right", $filedate, 'date');
                print_cell("right", "<a href=\"files.php?id={$id}&amp;qid={$qid}&amp;wdir={$wdir}&amp;file={$filesafe}&amp;action=rename&amp;choose={$choose}\">{$strrename}</a>", 'commands');
            }
            echo "</tr>";
        }
    }
    if (!empty($filelist)) {
        asort($filelist);
        foreach ($filelist as $file) {
            $icon = mimeinfo("icon", $file);
            $count++;
            $filename = $fullpath . "/" . $file;
            $fileurl = trim($wdir, "/") . "/{$file}";
            $filesafe = rawurlencode($file);
            $fileurlsafe = rawurlencode($fileurl);
            $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
            $selectfile = trim($fileurl, "/");
            echo "<tr class=\"file\">";
            print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" />", 'checkbox');
            echo "<td align=\"left\" style=\"white-space:nowrap\" class=\"name\">";
            if ($CFG->slasharguments) {
                $ffurl = str_replace('//', '/', "/file.php/{$fileurl}");
            } else {
                $ffurl = str_replace('//', '/', "/file.php?file=/{$fileurl}");
            }
            link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" />&nbsp;" . htmlspecialchars($file), 480, 640);
            echo "</td>";
            $file_size = filesize($filename);
            print_cell("right", display_size($file_size), 'size');
            print_cell("right", $filedate, 'date');
            if ($choose) {
                $edittext = "<strong><a onclick=\"return set_value('{$selectfile}')\" href=\"#\">{$strchoose}</a></strong>&nbsp;";
            } else {
                $edittext = '';
            }
            if ($icon == "text.gif" || $icon == "html.gif") {
                $edittext .= "<a href=\"files.php?id={$id}&amp;qid={$qid}&amp;wdir={$wdir}&amp;file={$fileurl}&amp;action=edit&amp;choose={$choose}\">{$stredit}</a>";
            } else {
                if ($icon == "zip.gif") {
                    $edittext .= "<a href=\"files.php?id={$id}&amp;qid={$qid}&amp;wdir={$wdir}&amp;file={$fileurl}&amp;action=unzip&amp;sesskey={$USER->sesskey}&amp;choose={$choose}\">{$strunzip}</a>&nbsp;";
                    $edittext .= "<a href=\"files.php?id={$id}&amp;qid={$qid}&amp;wdir={$wdir}&amp;file={$fileurl}&amp;action=listzip&amp;sesskey={$USER->sesskey}&amp;choose={$choose}\">{$strlist}</a> ";
                    if (!empty($CFG->backup_version) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
                        $edittext .= "<a href=\"files.php?id={$id}&amp;qid={$qid}&amp;wdir={$wdir}&amp;file={$filesafe}&amp;action=restore&amp;sesskey={$USER->sesskey}&amp;choose={$choose}\">{$strrestore}</a> ";
                    }
                }
            }
            print_cell("right", "{$edittext} <a href=\"files.php?id={$id}&amp;qid={$qid}&amp;wdir={$wdir}&amp;file={$filesafe}&amp;action=rename&amp;choose={$choose}\">{$strrename}</a>", 'commands');
            echo "</tr>";
        }
    }
    echo "</table>";
    echo "<hr />";
    //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
    echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">";
    echo "<tr><td>";
    echo "<input type=\"hidden\" name=\"id\" value=\"{$id}\" />";
    echo " <input type=\"hidden\" name=\"qid\" value=\"{$qid}\" />";
    echo '<input type="hidden" name="choose" value="' . $choose . '" />';
    echo "<input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" /> ";
    echo "<input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />";
    $options = array("move" => "{$strmovetoanotherfolder}", "delete" => "{$strdeletecompletely}", "zip" => "{$strcreateziparchive}");
    if (!empty($count)) {
        choose_from_menu($options, "action", "", "{$strwithchosenfiles}...", "javascript:getElementById('dirform').submit()");
    }
    echo "</td></tr></table>";
    echo "</div>";
    echo "</form>";
    echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\"><tr>";
    echo "<td align=\"center\">";
    if (!empty($USER->fileop) and $USER->fileop == "move" and $USER->filesource != $wdir) {
        echo "<form action=\"files.php\" method=\"get\">";
        echo "<div>";
        echo ' <input type="hidden" name="choose" value="' . $choose . '" />';
        echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />";
        echo " <input type=\"hidden\" name=\"qid\" value=\"{$qid}\" />";
        echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />";
        echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />";
        echo " <input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />";
        echo " <input type=\"submit\" value=\"{$strmovefilestohere}\" />";
        echo "</div>";
        echo "</form>";
    }
    echo "</td>";
    echo "<td align=\"right\">";
    echo "<form action=\"files.php\" method=\"get\">";
    echo "<div>";
    echo ' <input type="hidden" name="choose" value="' . $choose . '" />';
    echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />";
    echo " <input type=\"hidden\" name=\"qid\" value=\"{$qid}\" />";
    echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />";
    echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />";
    echo " <input type=\"submit\" value=\"{$strmakeafolder}\" />";
    echo "</div>";
    echo "</form>";
    echo "</td>";
    echo "<td align=\"right\">";
    echo "<form action=\"files.php\" method=\"get\">";
    //dummy form - alignment only
    echo "<fieldset class=\"invisiblefieldset\">";
    echo " <input type=\"button\" value=\"{$strselectall}\" onclick=\"checkall();\" />";
    echo " <input type=\"button\" value=\"{$strselectnone}\" onclick=\"uncheckall();\" />";
    echo "</fieldset>";
    echo "</form>";
    echo "</td>";
    echo "<td align=\"right\">";
    echo "<form action=\"files.php\" method=\"get\">";
    echo "<div>";
    echo ' <input type="hidden" name="choose" value="' . $choose . '" />';
    echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />";
    echo " <input type=\"hidden\" name=\"qid\" value=\"{$qid}\" />";
    echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />";
    echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />";
    echo " <input type=\"submit\" value=\"{$struploadafile}\" />";
    echo "</div>";
    echo "</form>";
    echo "</td></tr>";
    echo "</table>";
    echo "<hr/>";
    //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
}
Ejemplo n.º 2
0
function webwork_make_tmp_dir()
{
    return make_upload_directory(webwork_get_tmp_path());
}