~ubuntu-branches/ubuntu/breezy/moodle/breezy

« back to all changes in this revision

Viewing changes to mod/assignment/type/uploadsingle/assignment.class.php

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-10-13 02:00:59 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051013020059-y2qcyo41t7nqppcg
Tags: 1.5.2-1ubuntu1
* Resync with debian (security update)
* changed dependencys to php5
* changed apache dependency to apache2 
* References
  CAN-2005-2247

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php // $Id: assignment.class.php,v 1.8.2.5 2005/07/12 19:14:23 skodak Exp $
 
2
 
 
3
/**
 
4
 * Extend the base assignment class for assignments where you upload a single file
 
5
 *
 
6
 */
 
7
class assignment_uploadsingle extends assignment_base {
 
8
 
 
9
    function assignment_uploadsingle($cmid=0) {
 
10
        parent::assignment_base($cmid);
 
11
 
 
12
    }
 
13
 
 
14
    function view() {
 
15
 
 
16
        global $USER;
 
17
 
 
18
        $this->view_header();
 
19
 
 
20
        $this->view_intro();
 
21
 
 
22
        $this->view_dates();
 
23
 
 
24
        $filecount = $this->count_user_files($USER->id);
 
25
 
 
26
        if ($submission = $this->get_submission()) {
 
27
            if ($submission->timemarked) {
 
28
                $this->view_feedback();
 
29
            } else if ($filecount) {
 
30
                print_simple_box($this->print_user_files($USER->id, true), 'center');
 
31
            }
 
32
        }
 
33
 
 
34
        if ($this->isopen() && (!$filecount || $this->assignment->resubmit)) {
 
35
            $this->view_upload_form();
 
36
        }
 
37
 
 
38
        $this->view_footer();
 
39
    }
 
40
 
 
41
 
 
42
    function view_upload_form() {
 
43
        global $CFG;
 
44
        $struploadafile = get_string("uploadafile");
 
45
        $strmaxsize = get_string("maxsize", "", display_size($this->assignment->maxbytes));
 
46
 
 
47
        echo '<center>';
 
48
        echo '<form enctype="multipart/form-data" method="post" '.
 
49
             "action=\"$CFG->wwwroot/mod/assignment/upload.php\">";
 
50
        echo "<p>$struploadafile ($strmaxsize)</p>";
 
51
        echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />';
 
52
        require_once($CFG->libdir.'/uploadlib.php');
 
53
        upload_print_form_fragment(1,array('newfile'),false,null,0,$this->assignment->maxbytes,false);
 
54
        echo '<input type="submit" name="save" value="'.get_string('uploadthisfile').'" />';
 
55
        echo '</form>';
 
56
        echo '</center>';
 
57
    }
 
58
 
 
59
 
 
60
    function upload() {
 
61
        global $CFG, $USER;
 
62
 
 
63
        if (isguest($USER->id)) {
 
64
            error(get_string('guestnoupload','assignment'));
 
65
        }
 
66
 
 
67
        $this->view_header(get_string('upload'));
 
68
 
 
69
        $filecount = $this->count_user_files($USER->id);
 
70
 
 
71
        if ($this->isopen() && (!$filecount || $this->assignment->resubmit)) {
 
72
            if ($submission = $this->get_submission($USER->id)) {
 
73
                if ($submission->grade and !$this->assignment->resubmit) {
 
74
                    notify(get_string('alreadygraded', 'assignment'));
 
75
                }
 
76
            }
 
77
 
 
78
            $dir = $this->file_area_name($USER->id);
 
79
 
 
80
            require_once($CFG->dirroot.'/lib/uploadlib.php');
 
81
            $um = new upload_manager('newfile',true,false,$course,false,$this->assignment->maxbytes);
 
82
            if ($um->process_file_uploads($dir)) {
 
83
                $newfile_name = $um->get_new_filename();
 
84
                if ($submission) {
 
85
                    $submission->timemodified = time();
 
86
                    $submission->numfiles     = 1;
 
87
                    $submission->comment = addslashes($submission->comment);
 
88
                    unset($submission->data1);  // Don't need to update this.
 
89
                    unset($submission->data2);  // Don't need to update this.
 
90
                    if (update_record("assignment_submissions", $submission)) {
 
91
                        add_to_log($this->course->id, 'assignment', 'upload', 
 
92
                                'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
 
93
                        $this->email_teachers($submission);
 
94
                        print_heading(get_string('uploadedfile'));
 
95
                    } else {
 
96
                        notify(get_string("uploadfailnoupdate", "assignment"));
 
97
                    }
 
98
                } else {
 
99
                    $newsubmission->assignment   = $this->assignment->id;
 
100
                    $newsubmission->userid       = $USER->id;
 
101
                    $newsubmission->timecreated  = time();
 
102
                    $newsubmission->timemodified = time();
 
103
                    $newsubmission->numfiles     = 1;
 
104
                    if (insert_record('assignment_submissions', $newsubmission)) {
 
105
                        add_to_log($this->course->id, 'assignment', 'upload', 
 
106
                                'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
 
107
                        $this->email_teachers($newsubmission);
 
108
                        print_heading(get_string('uploadedfile'));
 
109
                    } else {
 
110
                        notify(get_string("uploadnotregistered", "assignment", $newfile_name) );
 
111
                    }
 
112
                }
 
113
            }
 
114
        } else {
 
115
            notify(get_string("uploaderror", "assignment")); //submitting not allowed!
 
116
        }
 
117
 
 
118
        print_continue('view.php?id='.$this->cm->id);
 
119
 
 
120
        $this->view_footer();
 
121
    }
 
122
 
 
123
 
 
124
    /*
 
125
     *  Display and process the submissions 
 
126
     */ 
 
127
    function process_feedback() {                 
 
128
                
 
129
        global $USER;
 
130
                    
 
131
        if (!$feedback = data_submitted()) {      // No incoming data?
 
132
            return false;
 
133
        }       
 
134
        
 
135
        if (!empty($feedback->cancel)) {          // User hit cancel button
 
136
            return false;
 
137
        }       
 
138
        
 
139
        $newsubmission = $this->get_submission($feedback->userid, true);  // Get or make one
 
140
                
 
141
        $newsubmission->grade      = $feedback->grade;
 
142
        $newsubmission->comment    = $feedback->comment;
 
143
        $newsubmission->format     = $feedback->format;
 
144
        $newsubmission->teacher    = $USER->id;
 
145
        $newsubmission->mailed     = 0;       // Make sure mail goes out (again, even)
 
146
        $newsubmission->timemarked = time();
 
147
 
 
148
        unset($newsubmission->data1);  // Don't need to update this.
 
149
        unset($newsubmission->data2);  // Don't need to update this.
 
150
 
 
151
        if (! update_record('assignment_submissions', $newsubmission)) {
 
152
            return false;
 
153
        }
 
154
        
 
155
        add_to_log($this->course->id, 'assignment', 'update grades', 
 
156
                   'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);   
 
157
        
 
158
        return $newsubmission;
 
159
                 
 
160
    }   
 
161
 
 
162
 
 
163
}
 
164
 
 
165
?>