File: upload.php

package info (click to toggle)
moodle 1.4.4.dfsg.1-3sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 57,876 kB
  • ctags: 29,496
  • sloc: php: 271,617; sql: 5,084; xml: 702; perl: 638; sh: 403; java: 283; makefile: 42; pascal: 21
file content (95 lines) | stat: -rw-r--r-- 4,090 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?PHP  // $Id: upload.php,v 1.14 2004/08/21 20:20:53 gustav_delius Exp $

    require_once("../../config.php");
    require_once("lib.php");

    require_variable($id);          // Assignment ID

    if (!empty($_FILES['newfile'])) {
        $newfile = $_FILES['newfile'];
    }

    if (! $assignment = get_record("assignment", "id", $id)) {
        error("Not a valid assignment ID");
    }

    if (! $course = get_record("course", "id", $assignment->course)) {
        error("Course is misconfigured");
    }

    if (! $cm = get_coursemodule_from_instance("assignment", $assignment->id, $course->id)) {
        error("Course Module ID was incorrect");
    }

    require_login($course->id);

    add_to_log($course->id, "assignment", "upload", "view.php?a=$assignment->id", "$assignment->id", $cm->id);

    $strassignments = get_string("modulenameplural", "assignment");
    $strassignment  = get_string("modulename", "assignment");
    $strupload      = get_string("upload");

    print_header_simple("$assignment->name : $strupload", "",
                 "<A HREF=index.php?id=$course->id>$strassignments</A> -> 
                  <A HREF=\"view.php?a=$assignment->id\">$assignment->name</A> -> $strupload", 
                  "", "", true);

    if ($submission = get_record("assignment_submissions", "assignment", $assignment->id, "userid", $USER->id)) {
        if ($submission->grade and !$assignment->resubmit) {
            error("You've already been graded - there's no point in uploading anything");
        }
    }

    if (! $dir = assignment_file_area($assignment, $USER)) {
        error("Sorry, an error in the system prevents you from uploading files: contact your teacher or system administrator");
    }

    if (empty($newfile)) {
        notify(get_string("uploadnofilefound", "assignment") );

    } else if (is_uploaded_file($newfile['tmp_name']) and $newfile['size'] > 0) {
        if ($newfile['size'] > $assignment->maxbytes) {
            notify(get_string("uploadfiletoobig", "assignment", $assignment->maxbytes));
        } else {
            $newfile_name = clean_filename($newfile['name']);
            if ($newfile_name) {
                if (move_uploaded_file($newfile['tmp_name'], "$dir/$newfile_name")) {
                    chmod("$dir/$newfile_name", $CFG->directorypermissions);
                    assignment_delete_user_files($assignment, $USER, $newfile_name);
                    if ($submission) {
                        $submission->timemodified = time();
                        $submission->numfiles     = 1;
                        $submission->comment = addslashes($submission->comment);
                        if (update_record("assignment_submissions", $submission)) {
                            print_heading(get_string("uploadsuccess", "assignment", $newfile_name) );
                        } else {
                            notify(get_string("uploadfailnoupdate", "assignment"));
                        }
                    } else {
                        $newsubmission->assignment   = $assignment->id;
                        $newsubmission->userid       = $USER->id;
                        $newsubmission->timecreated  = time();
                        $newsubmission->timemodified = time();
                        $newsubmission->numfiles     = 1;
                        if (insert_record("assignment_submissions", $newsubmission)) {
                            print_heading(get_string("uploadsuccess", "assignment", $newfile_name) );
                        } else {
                            notify(get_string("uploadnotregistered", "assignment", $newfile_name) );
                        }
                    }
                } else {
                    notify(get_string("uploaderror", "assignment") );
                }
            } else {
                notify(get_string("uploadbadname", "assignment") );
            }
        }
    } else {
        notify(get_string("uploadnofilefound", "assignment") );
    }
    
    print_continue("view.php?a=$assignment->id");

    print_footer($course);

?>