f77cfb73 |
1 | <?php // $Id$ |
2 | |
3 | /** |
4 | * Extend the base assignment class for assignments where you upload a single file |
5 | * |
6 | */ |
7 | class assignment_online extends assignment_base { |
8 | |
9 | function assignment_online($cmid=0) { |
10 | parent::assignment_base($cmid); |
11 | |
12 | } |
13 | |
f77cfb73 |
14 | function view() { |
15 | |
16 | global $USER; |
17 | |
f0a99707 |
18 | $submission = $this->get_submission(); |
19 | $editable = $this->isopen() && (!$submission || $this->assignment->resubmit); |
20 | $editmode = ($editable && !empty($_GET['edit'])); |
f77cfb73 |
21 | |
22 | if ($editmode) { |
23 | $this->view_header(get_string('editmysubmission', 'assignment')); |
24 | } else { |
25 | $this->view_header(); |
26 | } |
27 | |
28 | $this->view_intro(); |
29 | |
30 | $this->view_dates(); |
31 | |
32 | if ($data = data_submitted()) { // No incoming data? |
f0a99707 |
33 | if ($editable && $this->update_submission($data)) { |
ca4fb814 |
34 | //TODO fix log actions - needs db upgrade |
35 | add_to_log($this->course->id, 'assignment', 'upload', |
36 | 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); |
37 | $this->email_teachers($submission); |
3e7bf58a |
38 | //redirect to get updated submission date and word count |
39 | redirect('view.php?id='.$this->cm->id.'&saved=1'); |
f0a99707 |
40 | } else { |
41 | // TODO: add better error message |
42 | notify(get_string("error")); //submitting not allowed! |
f77cfb73 |
43 | } |
3e7bf58a |
44 | } else if (!empty($_GET['saved'])) { |
45 | notify(get_string('submissionsaved', 'assignment')); |
46 | } |
f77cfb73 |
47 | |
48 | print_simple_box_start('center', '70%', '', '', 'generalbox', 'online'); |
49 | $submission = $this->get_submission(); |
50 | if ($editmode) { |
51 | $this->view_edit_form($submission); |
52 | } else { |
53 | if ($submission) { |
54 | echo format_text($submission->data1, $submission->data2); |
55 | } else { |
d8199f1d |
56 | echo '<center>'.get_string('emptysubmission', 'assignment').'</center>'; |
f77cfb73 |
57 | } |
f0a99707 |
58 | if ($editable) { |
f77cfb73 |
59 | print_single_button('view.php', array('id'=>$this->cm->id,'edit'=>'1'), |
60 | get_string('editmysubmission', 'assignment')); |
61 | } |
62 | } |
63 | print_simple_box_end(); |
64 | |
65 | if ($editmode and $this->usehtmleditor) { |
66 | use_html_editor(); // MUst be at the end of the page |
67 | } |
68 | |
69 | $this->view_feedback(); |
70 | |
71 | $this->view_footer(); |
72 | } |
73 | |
3e7bf58a |
74 | /* |
75 | * Display the assignment dates |
76 | */ |
77 | function view_dates() { |
78 | global $USER; |
79 | |
80 | if (!$this->assignment->timeavailable && !$this->assignment->timedue) { |
81 | return; |
82 | } |
83 | |
84 | print_simple_box_start('center', '', '', '', 'generalbox', 'dates'); |
85 | echo '<table>'; |
86 | if ($this->assignment->timeavailable) { |
87 | echo '<tr><td class="c0">'.get_string('availabledate','assignment').':</td>'; |
88 | echo ' <td class="c1">'.userdate($this->assignment->timeavailable).'</td></tr>'; |
89 | } |
90 | if ($this->assignment->timedue) { |
91 | echo '<tr><td class="c0">'.get_string('duedate','assignment').':</td>'; |
92 | echo ' <td class="c1">'.userdate($this->assignment->timedue).'</td></tr>'; |
93 | } |
94 | $submission = $this->get_submission($USER->id); |
95 | if ($submission) { |
96 | echo '<tr><td class="c0">'.get_string('lastedited').':</td>'; |
97 | echo ' <td class="c1">'.userdate($submission->timemodified); |
98 | echo ' ('.get_string('numwords', '', count_words(format_text($submission->data1, $submission->data2))).')</td></tr>'; |
99 | } |
100 | echo '</table>'; |
101 | print_simple_box_end(); |
102 | } |
103 | |
f77cfb73 |
104 | function view_edit_form($submission = NULL) { |
105 | global $CFG; |
106 | |
107 | $defaulttext = $submission ? $submission->data1 : ''; |
108 | $defaultformat = $submission ? $submission->data2 : $this->defaultformat; |
109 | |
088ec317 |
110 | echo '<form name="theform" action="view.php" method="post">'; // do this so URLs look good |
f77cfb73 |
111 | |
112 | echo '<table cellspacing="0" class="editbox" align="center">'; |
113 | echo '<tr><td align="right">'; |
114 | helpbutton('reading', get_string('helpreading'), 'moodle', true, true); |
115 | echo '<br />'; |
116 | helpbutton('writing', get_string('helpwriting'), 'moodle', true, true); |
117 | echo '<br />'; |
118 | if ($this->usehtmleditor) { |
119 | helpbutton('richtext', get_string('helprichtext'), 'moodle', true, true); |
120 | } else { |
121 | emoticonhelpbutton('theform', 'text'); |
122 | } |
123 | echo '<br />'; |
124 | echo '</td></tr>'; |
125 | echo '<tr><td align="center">'; |
126 | print_textarea($this->usehtmleditor, 20, 60, 630, 400, 'text', $defaulttext); |
127 | if (!$this->usehtmleditor) { |
128 | echo '<div align="right" class="format">'; |
129 | print_string('formattexttype'); |
130 | echo ': '; |
131 | choose_from_menu(format_text_menu(), 'format', $defaultformat, ''); |
132 | helpbutton('textformat', get_string('helpformatting')); |
133 | echo '</div>'; |
134 | } else { |
135 | echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />'; |
136 | } |
137 | echo '</td></tr>'; |
138 | echo '<tr><td align="center">'; |
139 | echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />'; |
140 | echo '<input type="submit" value="'.get_string('savechanges').'" />'; |
141 | echo '<input type="reset" value="'.get_string('revert').'" />'; |
142 | echo '</td></tr></table>'; |
143 | |
144 | echo '</form>'; |
145 | |
146 | } |
147 | |
148 | function update_submission($data) { |
149 | global $CFG, $USER; |
150 | |
151 | $submission = $this->get_submission($USER->id, true); |
152 | |
0cbc1f11 |
153 | $update = NULL; |
154 | $update->id = $submission->id; |
155 | $update->data1 = $data->text; |
156 | $update->format = $data->format; |
157 | $update->timemodified = time(); |
f77cfb73 |
158 | |
0cbc1f11 |
159 | return update_record('assignment_submissions', $update); |
f77cfb73 |
160 | } |
161 | |
162 | |
163 | /* |
164 | * Display and process the submissions |
165 | */ |
166 | function process_feedback() { |
167 | |
168 | global $USER; |
169 | |
170 | if (!$feedback = data_submitted()) { // No incoming data? |
171 | return false; |
172 | } |
173 | |
174 | if (!empty($feedback->cancel)) { // User hit cancel button |
175 | return false; |
176 | } |
177 | |
178 | $newsubmission = $this->get_submission($feedback->userid, true); // Get or make one |
179 | |
180 | $newsubmission->grade = $feedback->grade; |
181 | $newsubmission->comment = $feedback->comment; |
182 | $newsubmission->format = $feedback->format; |
183 | $newsubmission->teacher = $USER->id; |
184 | $newsubmission->mailed = 0; // Make sure mail goes out (again, even) |
185 | $newsubmission->timemarked = time(); |
fd40be3e |
186 | |
187 | unset($newsubmission->data1); // Don't need to update this. |
d4156e80 |
188 | unset($newsubmission->data2); // Don't need to update this. |
fd40be3e |
189 | |
f77cfb73 |
190 | if (! update_record('assignment_submissions', $newsubmission)) { |
191 | return false; |
192 | } |
193 | |
194 | add_to_log($this->course->id, 'assignment', 'update grades', |
195 | 'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id); |
196 | |
197 | return $newsubmission; |
198 | |
199 | } |
200 | |
201 | function print_user_files($userid, $return=false) { |
202 | global $CFG; |
203 | |
204 | if (!$submission = $this->get_submission($userid)) { |
205 | return ''; |
206 | } |
207 | $output = '<div class="files">'. |
208 | '<img align="middle" src="'.$CFG->pixpath.'/f/html.gif" height="16" width="16" alt="html" />'. |
209 | link_to_popup_window ('/mod/assignment/type/online/file.php?id='.$this->cm->id.'&userid='. |
3e7bf58a |
210 | $submission->userid, 'file'.$userid, shorten_text(trim(strip_tags(format_text($submission->data1,$submission->data2))), 15), 450, 580, |
f77cfb73 |
211 | get_string('submission', 'assignment'), 'none', true). |
212 | '</div>'; |
213 | |
214 | if ($return) { |
215 | return $output; |
216 | } |
217 | echo $output; |
218 | } |
219 | |
01e2fdfe |
220 | function preprocess_submission(&$submission) { |
221 | if ($this->assignment->var1 && empty($submission->comment)) { // comment inline |
47263937 |
222 | if ($this->usehtmleditor) { |
223 | // Convert to html, clean & copy student data to teacher |
224 | $submission->comment = format_text($submission->data1, $submission->data2); |
225 | $submission->format = FORMAT_HTML; |
226 | } else { |
227 | // Copy student data to teacher |
228 | $submission->comment = $submission->data1; |
229 | $submission->format = $submission->data2; |
230 | } |
01e2fdfe |
231 | } |
232 | } |
233 | |
f77cfb73 |
234 | } |
235 | |
236 | ?> |