mirrored from git://git.moodle.org/moodle.git
/
assignment.class.php
191 lines (150 loc) · 6.45 KB
/
assignment.class.php
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php // $Id$
/**
* Extend the base assignment class for assignments where you upload a single file
*
*/
class assignment_online extends assignment_base {
function assignment_online($cmid=0) {
parent::assignment_base($cmid);
}
function view() {
global $USER;
$editmode = ($this->isopen() && !empty($_GET['edit']));
if ($editmode) {
$this->view_header(get_string('editmysubmission', 'assignment'));
} else {
$this->view_header();
}
$this->view_intro();
$this->view_dates();
if ($data = data_submitted()) { // No incoming data?
if ($this->update_submission($data)) {
notify(get_string('submissionsaved', 'assignment'));
}
}
print_simple_box_start('center', '70%', '', '', 'generalbox', 'online');
$submission = $this->get_submission();
if ($editmode) {
$this->view_edit_form($submission);
} else {
if ($submission) {
echo format_text($submission->data1, $submission->data2);
} else {
echo '<center>'.get_string('emptysubmission', 'assignment').'</center>';
}
if ($this->isopen()) {
print_single_button('view.php', array('id'=>$this->cm->id,'edit'=>'1'),
get_string('editmysubmission', 'assignment'));
}
}
print_simple_box_end();
if ($editmode and $this->usehtmleditor) {
use_html_editor(); // MUst be at the end of the page
}
$this->view_feedback();
$this->view_footer();
}
function view_edit_form($submission = NULL) {
global $CFG;
$defaulttext = $submission ? $submission->data1 : '';
$defaultformat = $submission ? $submission->data2 : $this->defaultformat;
echo '<form name="theform" action="view.php" method="post">'; // do this so URLs look good
echo '<table cellspacing="0" class="editbox" align="center">';
echo '<tr><td align="right">';
helpbutton('reading', get_string('helpreading'), 'moodle', true, true);
echo '<br />';
helpbutton('writing', get_string('helpwriting'), 'moodle', true, true);
echo '<br />';
if ($this->usehtmleditor) {
helpbutton('richtext', get_string('helprichtext'), 'moodle', true, true);
} else {
emoticonhelpbutton('theform', 'text');
}
echo '<br />';
echo '</td></tr>';
echo '<tr><td align="center">';
print_textarea($this->usehtmleditor, 20, 60, 630, 400, 'text', $defaulttext);
if (!$this->usehtmleditor) {
echo '<div align="right" class="format">';
print_string('formattexttype');
echo ': ';
choose_from_menu(format_text_menu(), 'format', $defaultformat, '');
helpbutton('textformat', get_string('helpformatting'));
echo '</div>';
} else {
echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
}
echo '</td></tr>';
echo '<tr><td align="center">';
echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />';
echo '<input type="submit" value="'.get_string('savechanges').'" />';
echo '<input type="reset" value="'.get_string('revert').'" />';
echo '</td></tr></table>';
echo '</form>';
}
function update_submission($data) {
global $CFG, $USER;
$submission = $this->get_submission($USER->id, true);
$update = NULL;
$update->id = $submission->id;
$update->data1 = $data->text;
$update->format = $data->format;
$update->timemodified = time();
return update_record('assignment_submissions', $update);
}
/*
* Display and process the submissions
*/
function process_feedback() {
global $USER;
if (!$feedback = data_submitted()) { // No incoming data?
return false;
}
if (!empty($feedback->cancel)) { // User hit cancel button
return false;
}
$newsubmission = $this->get_submission($feedback->userid, true); // Get or make one
$newsubmission->grade = $feedback->grade;
$newsubmission->comment = $feedback->comment;
$newsubmission->format = $feedback->format;
$newsubmission->teacher = $USER->id;
$newsubmission->mailed = 0; // Make sure mail goes out (again, even)
$newsubmission->timemarked = time();
if (! update_record('assignment_submissions', $newsubmission)) {
return false;
}
add_to_log($this->course->id, 'assignment', 'update grades',
'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
return $newsubmission;
}
function print_user_files($userid, $return=false) {
global $CFG;
if (!$submission = $this->get_submission($userid)) {
return '';
}
$output = '<div class="files">'.
'<img align="middle" src="'.$CFG->pixpath.'/f/html.gif" height="16" width="16" alt="html" />'.
link_to_popup_window ('/mod/assignment/type/online/file.php?id='.$this->cm->id.'&userid='.
$submission->userid, 'file'.$userid, shorten_text(strip_tags(format_text($submission->data1,$submission->data2)), 15), 450, 580,
get_string('submission', 'assignment'), 'none', true).
'</div>';
if ($return) {
return $output;
}
echo $output;
}
function preprocess_submission(&$submission) {
if ($this->assignment->var1 && empty($submission->comment)) { // comment inline
if ($this->usehtmleditor) {
// Convert to html, clean & copy student data to teacher
$submission->comment = format_text($submission->data1, $submission->data2);
$submission->format = FORMAT_HTML;
} else {
// Copy student data to teacher
$submission->comment = $submission->data1;
$submission->format = $submission->data2;
}
}
}
}
?>