1
<?php // $Id: assignment.class.php,v 1.8.2.5 2005/07/12 19:14:23 skodak Exp $
4
* Extend the base assignment class for assignments where you upload a single file
7
class assignment_uploadsingle extends assignment_base {
9
function assignment_uploadsingle($cmid=0) {
10
parent::assignment_base($cmid);
24
$filecount = $this->count_user_files($USER->id);
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');
34
if ($this->isopen() && (!$filecount || $this->assignment->resubmit)) {
35
$this->view_upload_form();
42
function view_upload_form() {
44
$struploadafile = get_string("uploadafile");
45
$strmaxsize = get_string("maxsize", "", display_size($this->assignment->maxbytes));
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').'" />';
63
if (isguest($USER->id)) {
64
error(get_string('guestnoupload','assignment'));
67
$this->view_header(get_string('upload'));
69
$filecount = $this->count_user_files($USER->id);
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'));
78
$dir = $this->file_area_name($USER->id);
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();
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'));
96
notify(get_string("uploadfailnoupdate", "assignment"));
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'));
110
notify(get_string("uploadnotregistered", "assignment", $newfile_name) );
115
notify(get_string("uploaderror", "assignment")); //submitting not allowed!
118
print_continue('view.php?id='.$this->cm->id);
120
$this->view_footer();
125
* Display and process the submissions
127
function process_feedback() {
131
if (!$feedback = data_submitted()) { // No incoming data?
135
if (!empty($feedback->cancel)) { // User hit cancel button
139
$newsubmission = $this->get_submission($feedback->userid, true); // Get or make one
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();
148
unset($newsubmission->data1); // Don't need to update this.
149
unset($newsubmission->data2); // Don't need to update this.
151
if (! update_record('assignment_submissions', $newsubmission)) {
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);
158
return $newsubmission;