coursefiles.php

来自「很棒的在线教学系统」· PHP 代码 · 共 814 行 · 第 1/3 页

PHP
814
字号
<?php // $Id: coursefiles.php,v 1.13.8.3 2008/07/11 02:28:32 scyrma Exp $//  Manage all uploaded files in a course file area//  This file is a hack to files/index.php that removes//  the headers and adds some controls so that images//  can be selected within the Richtext editor.//  All the Moodle-specific stuff is in this top section//  Configuration and access control occurs here.//  Must define:  USER, basedir, baseweb, html_header and html_footer//  USER is a persistent variable using sessions    require("../../../config.php");    require_once($CFG->libdir.'/filelib.php');    $id      = required_param('id', PARAM_INT);    $file    = optional_param('file', '', PARAM_PATH);    $wdir    = optional_param('wdir', '', PARAM_PATH);    $action  = optional_param('action', '', PARAM_ACTION);    $name    = optional_param('name', '', PARAM_FILE);    $oldname = optional_param('oldname', '', PARAM_FILE);    $usecheckboxes  = optional_param('usecheckboxes', 1, PARAM_INT);    $save    = optional_param('save', 0, PARAM_BOOL);    $text    = optional_param('text', '', PARAM_RAW);    $confirm = optional_param('confirm', 0, PARAM_BOOL);    if (! $course = get_record("course", "id", $id) ) {        error("That's an invalid course id");    }    require_login($course);    require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id));    function html_footer() {        echo "\n\n</body>\n</html>";    }    function html_header($course, $wdir, $formfield=""){        global $CFG;        ?>        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">        <html>        <head>        <meta http-equiv="content-type" content="text/html; charset=utf-8" />        <title>coursefiles</title>        <script type="text/javascript">//<![CDATA[        function set_value(params) {            /// function's argument is an object containing necessary values            /// to export parent window (url,isize,itype,iwidth,iheight, imodified)            /// set values when user click's an image name.            var upper = window.parent;            var insimg = upper.document.getElementById('f_url');            try {                if(insimg != null) {                    if(params.itype.indexOf("image/gif") == -1 && params.itype.indexOf("image/jpeg") == -1 && params.itype.indexOf("image/png") == -1) {                        alert("<?php print_string("notimage","editor");?>");                        return false;                    }                    for(field in params) {                        var value = params[field];                        switch(field) {                            case "url"   :   upper.document.getElementById('f_url').value = value;                                     upper.ipreview.location.replace('popups/preview.php?id='+ <?php print($course->id);?> +'&imageurl='+ value);                                break;                            case "isize" :   upper.document.getElementById('isize').value = value; break;                            case "itype" :   upper.document.getElementById('itype').value = value; break;                            case "iwidth":    upper.document.getElementById('f_width').value = value; break;                            case "iheight":   upper.document.getElementById('f_height').value = value; break;                        }                    }                } else {                    for(field in params) {                        var value = params[field];                        switch(field) {                            case "url" :                                //upper.document.getElementById('f_href').value = value;                                upper.opener.document.getElementById('f_href').value = value;                                upper.close();                                break;                            //case "imodified" : upper.document.getElementById('imodified').value = value; break;                            //case "isize" : upper.document.getElementById('isize').value = value; break;                            //case "itype" : upper.document.getElementById('itype').value = value; break;                        }                    }                }            } catch(e) {                if ( window.tinyMCE != "undefined" || window.TinyMCE != "undefined" ) {                    upper.opener.Dialog._return(params.url);                    upper.close();                } else {                    alert("Something odd just occurred!!!");                }            }            return false;        }        function set_dir(strdir) {            // sets wdir values            var upper = window.parent.document;            if(upper) {                for(var i = 0; i < upper.forms.length; i++) {                    var f = upper.forms[i];                    try {                        f.wdir.value = strdir;                    } catch (e) {                    }                }            }        }        function set_rename(strfile) {            var upper = window.parent.document;            upper.getElementById('irename').value = strfile;            return true;        }        function reset_value() {            var upper = window.parent.document;            for(var i = 0; i < upper.forms.length; i++) {                var f = upper.forms[i];                for(var j = 0; j < f.elements.length; j++) {                    var e = f.elements[j];                    if(e.type != "submit" && e.type != "button" && e.type != "hidden") {                        try {                            e.value = "";                        } catch (e) {                        }                    }                }            }            upper.getElementById('irename').value = 'xx';            var prev = window.parent.ipreview;            if(prev != null) {                prev.location.replace('about:blank');            }            var uploader = window.parent.document.forms['uploader'];            if(uploader != null) {                uploader.reset();            }            set_dir('<?php print($wdir);?>');            return true;        }//]]>        </script>        <style type="text/css">        body {            background-color: white;            margin-top: 2px;            margin-left: 4px;            margin-right: 4px;        }        body,p,table,td,input,select,a {            font-family: Tahoma, sans-serif;            font-size: 11px;        }        select {            position: absolute;            top: -20px;            left: 0px;        }        img.icon {          vertical-align:middle;          margin-right:4px;          width:16px;          height:16px;          border:0px;        }        </style>        </head>        <body onload="reset_value();">        <?php    }    if (! $basedir = make_upload_directory("$course->id")) {        error("The site administrator needs to fix the file permissions");    }    $baseweb = $CFG->wwwroot;//  End of configuration and access control    if ($wdir == '') {        $wdir='/';    }    switch ($action) {        case "upload":            html_header($course, $wdir);            require_once($CFG->dirroot.'/lib/uploadlib.php');            if ($save and confirm_sesskey()) {                $um = new upload_manager('userfile',false,false,$course,false,0);                $dir = "$basedir$wdir";                if ($um->process_file_uploads($dir)) {                    notify(get_string('uploadedfile'));                }                // um will take care of error reporting.                displaydir($wdir);            } else {                $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes);                $filesize = display_size($upload_max_filesize);                $struploadafile = get_string("uploadafile");                $struploadthisfile = get_string("uploadthisfile");                $strmaxsize = get_string("maxsize", "", $filesize);                $strcancel = get_string("cancel");                echo "<p>$struploadafile ($strmaxsize) --> <strong>$wdir</strong>";                echo "<table border=\"0\"><tr><td colspan=\"2\">\n";                echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"coursefiles.php\">\n";                upload_print_form_fragment(1,array('userfile'),null,false,null,$course->maxbytes,0,false);                echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";                echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";                echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />\n";                echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />\n";                echo " </td><tr><td align=\"right\">";                echo " <input type=\"submit\" name=\"save\" value=\"$struploadthisfile\" />\n";                echo "</form>\n";                echo "</td>\n<td>\n";                echo "<form action=\"coursefiles.php\" method=\"get\">\n";                echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";                echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";                echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />\n";                echo " <input type=\"submit\" value=\"$strcancel\" />\n";                echo "</form>\n";                echo "</td>\n</tr>\n</table>\n";            }            html_footer();            break;        case "delete":            if ($confirm and confirm_sesskey()) {                html_header($course, $wdir);                foreach ($USER->filelist as $file) {                    $fullfile = $basedir.$file;                    if (! fulldelete($fullfile)) {                        echo "<br />Error: Could not delete: $fullfile";                    }                }                clearfilelist();                displaydir($wdir);                html_footer();            } else {                html_header($course, $wdir);                if (setfilelist($_POST)) {                    echo "<p align=center>".get_string("deletecheckwarning").":</p>";                    print_simple_box_start("center");                    printfilelist($USER->filelist);                    print_simple_box_end();                    echo "<br />";                    $frameold = $CFG->framename;                    $CFG->framename = "ibrowser";                    notice_yesno (get_string("deletecheckfiles"),                                "coursefiles.php?id=$id&amp;wdir=$wdir&amp;action=delete&amp;confirm=1&amp;sesskey=$USER->sesskey",                                "coursefiles.php?id=$id&amp;wdir=$wdir&amp;action=cancel");                    $CFG->framename = $frameold;                } else {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?