[system] / trunk / wwmoodle / wwquestion / file.php Repository:
ViewVC logotype

View of /trunk/wwmoodle/wwquestion/file.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5486 - (download) (as text) (annotate)
Tue Sep 11 20:10:03 2007 UTC (12 years, 5 months ago) by mleventi
File size: 2631 byte(s)
Version .4 Partial Answer Questions now supported

    1 <?php
    2     //This script fetches files from wwquestions directory, and only that directory.
    3     //It is used to display the cached equation images that are copied to moodledata when derived questions are created
    4 
    5     require_once('../../../config.php');
    6     require_once($CFG->libdir . '/filelib.php');
    7 
    8     // disable moodle specific debug messages
    9     disable_debugging();
   10 
   11     $relativepath = get_file_argument('file.php');
   12     $forcedownload = optional_param('forcedownload', 0, PARAM_BOOL);
   13 
   14     // relative path must start with '/', because of backup/restore!!!
   15     if (!$relativepath) {
   16         error('No valid arguments supplied or incorrect server configuration');
   17     } else if ($relativepath{0} != '/') {
   18         error('No valid arguments supplied, path does not start with slash!');
   19     }
   20 
   21     $pathname = $CFG->dataroot.$relativepath;
   22 
   23     // extract relative path components
   24     $args = explode('/', trim($relativepath, '/'));
   25 
   26     //security this should only be used for wwquestions
   27     if ((count($args) < 3) || ($args[0] != '1') || ($args[1] != 'wwquestions')) {
   28         error('No valid arguments supplied');
   29     }
   30 
   31     //extra security for users
   32     /*if((count($args) > 6) && ($args[5] == 'users')) {
   33         //trying to get a user equation image
   34         if($args[6] != $USER->id) {
   35             require_capability('moodle/mod/quiz:viewreports');
   36         }
   37     }*/
   38 
   39 
   40 
   41     if (is_dir($pathname)) {
   42         if (file_exists($pathname.'/index.html')) {
   43             $pathname = rtrim($pathname, '/').'/index.html';
   44             $args[] = 'index.html';
   45         } else if (file_exists($pathname.'/index.htm')) {
   46             $pathname = rtrim($pathname, '/').'/index.htm';
   47             $args[] = 'index.htm';
   48         } else if (file_exists($pathname.'/Default.htm')) {
   49             $pathname = rtrim($pathname, '/').'/Default.htm';
   50             $args[] = 'Default.htm';
   51         } else {
   52             // security: do not return directory node!
   53             not_found($course->id);
   54         }
   55     }
   56 
   57     // check that file exists
   58     if (!file_exists($pathname)) {
   59         not_found($course->id);
   60     }
   61 
   62     // ========================================
   63     // finally send the file
   64     // ========================================
   65     session_write_close(); // unlock session during fileserving
   66     $filename = $args[count($args)-1];
   67     send_file($pathname, $filename);
   68 
   69     function not_found($courseid) {
   70         global $CFG;
   71         header('HTTP/1.0 404 not found');
   72         error(get_string('filenotfound', 'error'), $CFG->wwwroot.'/course/view.php?id='.$courseid); //this is not displayed on IIS??
   73     }
   74 ?>

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9