File: upload.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (120 lines) | stat: -rw-r--r-- 5,303 bytes parent folder | download | duplicates (2)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php  // $Id: upload.php,v 1.25 2006/04/19 19:48:47 skodak Exp $

    require("../../config.php");
    require("lib.php");
    require("locallib.php");

    $id = required_param('id', PARAM_INT);          // CM ID


    if (! $cm = get_record("course_modules", "id", $id)) {
        error("Course Module ID was incorrect");
    }
    if (! $course = get_record("course", "id", $cm->course)) {
        error("Course is misconfigured");
    }
    if (! $workshop = get_record("workshop", "id", $cm->instance)) {
        error("Course module is incorrect");
    }

    require_login($course->id, false, $cm);

    $strworkshops = get_string('modulenameplural', 'workshop');
    $strworkshop = get_string('modulename', 'workshop');
    $strsubmission = get_string('submission', 'workshop');

    print_header_simple(format_string($workshop->name)." : $strsubmission", "",
                 "<a href=\"index.php?id=$course->id\">$strworkshops</a> ->
                  <a href=\"view.php?a=$workshop->id\">".format_string($workshop->name,true)."</a> -> $strsubmission",
                  "", "", true);
    $timenow = time();

    $form = data_submitted("nomatch"); // POST may come from two forms

    // don't be picky about not having a title
    if (!$title = $form->title) {
        $title = get_string("notitle", "workshop");
    }

    // check that this is not a "rapid" second submission, caused by using the back button
    // only check if a student, teachers may want to submit a set of workshop examples rapidly
    if (isstudent($course->id)) {
        if ($submissions = workshop_get_user_submissions($workshop, $USER)) {
            // returns all submissions, newest on first
            foreach ($submissions as $submission) {
                if ($submission->timecreated > $timenow - $CFG->maxeditingtime) {
                    // ignore this new submission
                    redirect("view.php?id=$cm->id");
                    print_footer($course);
                    exit();
                }
            }
        }
    }

    // get the current set of submissions
    $submissions = workshop_get_user_submissions($workshop, $USER);
    // add new submission record
    $newsubmission->workshopid  = $workshop->id;
    $newsubmission->userid      = $USER->id;
    $newsubmission->title       = clean_param($title, PARAM_CLEAN);
    $newsubmission->description = trim(clean_param($form->description, PARAM_CLEAN));
    $newsubmission->timecreated = $timenow;
    if ($timenow > $workshop->submissionend) {
        $newsubmission->late = 1;
    }
    if (!$newsubmission->id = insert_record("workshop_submissions", $newsubmission)) {
        error("Workshop submission: Failure to create new submission record!");
    }
    // see if this is a resubmission by looking at the previous submissions...
    if ($submissions and ($workshop->submissionstart > time())) { // ...but not teacher submissions
        // find the last submission
        foreach ($submissions as $submission) {
            $lastsubmission = $submission;
            break;
        }
        // find all the possible assessments of this submission
        // ...and if they have been assessed give the assessor a new assessment
        // based on their old assessment, if the assessment has not be made
        // just delete it!
        if ($assessments = workshop_get_assessments($submission, 'ALL')) {
            foreach ($assessments as $assessment) {
                if ($assessment->timecreated < $timenow) {
                    // a Cold or Warm assessment...
                    if ($assessment->userid <> $USER->id) {
                        // only copy other students assessment not the self assessment (if present)
                        // copy it with feedback..
                        $newassessment = workshop_copy_assessment($assessment, $newsubmission, true);
                        // set the resubmission flag so student can be emailed/told about
                        // this assessment
                        set_field("workshop_assessments", "resubmission", 1, "id", $newassessment->id);
                    }
                } else {
                    // a hot assessment, was not used, just dump it
                    delete_records("workshop_assessments", "id", $assessment->id);
                }
            }
        }
        add_to_log($course->id, "workshop", "resubmit", "view.php?id=$cm->id", "$workshop->id","$cm->id");
    }
    // do something about the attachments, if there are any
    if ($workshop->nattachments) {
        require_once($CFG->dirroot.'/lib/uploadlib.php');
        $um = new upload_manager(null,false,false,$course,false,$workshop->maxbytes);
        if ($um->preprocess_files()) {
            $dir = workshop_file_area_name($workshop, $newsubmission);
            if ($um->save_files($dir)) {
                print_heading(get_string("uploadsuccess", "workshop"));
            }
        // um will take care of printing errors.
        }
    }
    if (!$workshop->nattachments) {
        print_heading(get_string("submitted", "workshop")." ".get_string("ok"));
    }
    add_to_log($course->id, "workshop", "submit", "view.php?id=$cm->id", "$workshop->id", "$cm->id");
    print_continue("view.php?id=$cm->id");
    print_footer($course);

?>