webservice MDL-12886 web service administration
[moodle.git] / mod / assignment / type / upload / assignment.class.php
CommitLineData
fcdcc372 1<?php // $Id$
67a87e7d 2require_once($CFG->libdir . '/portfoliolib.php');
3require_once($CFG->dirroot . '/mod/assignment/lib.php');
fcdcc372 4
39bc9fbb 5define('ASSIGNMENT_STATUS_SUBMITTED', 'submitted'); // student thinks it is finished
6define('ASSIGNMENT_STATUS_CLOSED', 'closed'); // teacher prevents more submissions
55b4d096 7
fcdcc372 8/**
55b4d096 9 * Extend the base assignment class for assignments where you upload a single file
fcdcc372 10 *
11 */
12class assignment_upload extends assignment_base {
fcdcc372 13
7bddd4b7 14 function assignment_upload($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
15 parent::assignment_base($cmid, $assignment, $cm, $course);
0b5a80a1 16 $this->type = 'upload';
fcdcc372 17 }
18
fcdcc372 19 function view() {
867aeead 20 global $USER, $OUTPUT;
fcdcc372 21
55b4d096 22 require_capability('mod/assignment:view', $this->context);
fcdcc372 23
55b4d096 24 add_to_log($this->course->id, 'assignment', 'view', "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id);
25
26 $this->view_header();
29889a2a 27
28 if ($this->assignment->timeavailable > time()
8c408f8e 29 and !has_capability('mod/assignment:grade', $this->context) // grading user can see it anytime
30 and $this->assignment->var3) { // force hiding before available date
3a003ead 31 echo $OUTPUT->box_start('generalbox boxaligncenter', 'intro');
29889a2a 32 print_string('notavailableyet', 'assignment');
3a003ead 33 echo $OUTPUT->box_end();
29889a2a 34 } else {
35 $this->view_intro();
36 }
37
55b4d096 38 $this->view_dates();
fcdcc372 39
55b4d096 40 if (has_capability('mod/assignment:submit', $this->context)) {
41 $filecount = $this->count_user_files($USER->id);
42 $submission = $this->get_submission($USER->id);
6fc73d59 43
55b4d096 44 $this->view_feedback();
6fc73d59 45
42f50aec 46 if (!$this->drafts_tracked() or !$this->isopen() or $this->is_finalized($submission)) {
867aeead 47 echo $OUTPUT->heading(get_string('submission', 'assignment'), 3);
55b4d096 48 } else {
867aeead 49 echo $OUTPUT->heading(get_string('submissiondraft', 'assignment'), 3);
fcdcc372 50 }
fcdcc372 51
55b4d096 52 if ($filecount and $submission) {
3a003ead 53 echo $OUTPUT->box($this->print_user_files($USER->id, true), 'generalbox boxaligncenter');
55b4d096 54 } else {
39bc9fbb 55 if (!$this->isopen() or $this->is_finalized($submission)) {
3a003ead 56 echo $OUTPUT->box(get_string('nofiles', 'assignment'), 'generalbox boxaligncenter');
55b4d096 57 } else {
3a003ead 58 echo $OUTPUT->box(get_string('nofilesyet', 'assignment'), 'generalbox boxaligncenter');
55b4d096 59 }
60 }
6fc73d59 61
8ba4cbd2 62 $this->view_upload_form();
55b4d096 63
64 if ($this->notes_allowed()) {
867aeead 65 echo $OUTPUT->heading(get_string('notes', 'assignment'), 3);
55b4d096 66 $this->view_notes();
67 }
68
69 $this->view_final_submission();
8ba4cbd2 70 }
71 $this->view_footer();
fcdcc372 72 }
73
fcdcc372 74
55b4d096 75 function view_feedback($submission=NULL) {
867aeead 76 global $USER, $CFG, $DB, $OUTPUT;
12dce253 77 require_once($CFG->libdir.'/gradelib.php');
8ba4cbd2 78
55b4d096 79 if (!$submission) { /// Get submission for this assignment
80 $submission = $this->get_submission($USER->id);
81 }
8ba4cbd2 82
55b4d096 83 if (empty($submission->timemarked)) { /// Nothing to show, so print nothing
84 if ($this->count_responsefiles($USER->id)) {
867aeead 85 echo $OUTPUT->heading(get_string('responsefiles', 'assignment'), 3);
55b4d096 86 $responsefiles = $this->print_responsefiles($USER->id, true);
3a003ead 87 echo $OUTPUT->box($responsefiles, 'generalbox boxaligncenter');
55b4d096 88 }
89 return;
90 }
fcdcc372 91
12dce253 92 $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $USER->id);
93 $item = $grading_info->items[0];
94 $grade = $item->grades[$USER->id];
95
96 if ($grade->hidden or $grade->grade === false) { // hidden or error
97 return;
98 }
99
100 if ($grade->grade === null and empty($grade->str_feedback)) { /// Nothing to show yet
101 return;
102 }
103
104 $graded_date = $grade->dategraded;
105 $graded_by = $grade->usermodified;
106
55b4d096 107 /// We need the teacher info
74d7d735 108 if (!$teacher = $DB->get_record('user', array('id'=>$graded_by))) {
a939f681 109 print_error('cannotfindteacher');
55b4d096 110 }
fcdcc372 111
55b4d096 112 /// Print the feedback
867aeead 113 echo $OUTPUT->heading(get_string('submissionfeedback', 'assignment'), 3);
8ba4cbd2 114
55b4d096 115 echo '<table cellspacing="0" class="feedback">';
fcdcc372 116
55b4d096 117 echo '<tr>';
118 echo '<td class="left picture">';
75d47fa9 119 echo $OUTPUT->user_picture(moodle_user_picture::make($teacher, $this->course->id));
55b4d096 120 echo '</td>';
121 echo '<td class="topic">';
122 echo '<div class="from">';
123 echo '<div class="fullname">'.fullname($teacher).'</div>';
12dce253 124 echo '<div class="time">'.userdate($graded_date).'</div>';
55b4d096 125 echo '</div>';
126 echo '</td>';
127 echo '</tr>';
fcdcc372 128
55b4d096 129 echo '<tr>';
130 echo '<td class="left side">&nbsp;</td>';
131 echo '<td class="content">';
132 if ($this->assignment->grade) {
133 echo '<div class="grade">';
12dce253 134 echo get_string("grade").': '.$grade->str_long_grade;
55b4d096 135 echo '</div>';
136 echo '<div class="clearer"></div>';
137 }
8ba4cbd2 138
55b4d096 139 echo '<div class="comment">';
12dce253 140 echo $grade->str_feedback;
55b4d096 141 echo '</div>';
142 echo '</tr>';
8ba4cbd2 143
55b4d096 144 echo '<tr>';
145 echo '<td class="left side">&nbsp;</td>';
146 echo '<td class="content">';
147 echo $this->print_responsefiles($USER->id, true);
148 echo '</tr>';
8ba4cbd2 149
55b4d096 150 echo '</table>';
fcdcc372 151 }
152
fcdcc372 153
55b4d096 154 function view_upload_form() {
155 global $CFG, $USER;
fcdcc372 156
8ba4cbd2 157 $submission = $this->get_submission($USER->id);
fcdcc372 158
55b4d096 159 if ($this->is_finalized($submission)) {
160 // no uploading
161 return;
162 }
8ba4cbd2 163
55b4d096 164 if ($this->can_upload_file($submission)) {
172dd12c 165 $mform = new mod_assignment_upload_file_form('upload.php', $this);
166 $mform->display();
fcdcc372 167 }
8ba4cbd2 168
55b4d096 169 }
8ba4cbd2 170
55b4d096 171 function view_notes() {
3a003ead 172 global $USER, $OUTPUT;
55b4d096 173
174 if ($submission = $this->get_submission($USER->id)
175 and !empty($submission->data1)) {
3a003ead 176 echo $OUTPUT->box(format_text($submission->data1, FORMAT_HTML), 'generalbox boxaligncenter boxwidthwide');
55b4d096 177 } else {
3a003ead 178 echo $OUTPUT->box(get_string('notesempty', 'assignment'), 'generalbox boxaligncenter');
55b4d096 179 }
180 if ($this->can_update_notes($submission)) {
181 $options = array ('id'=>$this->cm->id, 'action'=>'editnotes');
d9cb14b8 182 echo '<div style="text-align:center">';
75d47fa9 183 echo $OUTPUT->button(html_form::make_button('upload.php', $options, get_string('edit')));
d9cb14b8 184 echo '</div>';
55b4d096 185 }
fcdcc372 186 }
187
55b4d096 188 function view_final_submission() {
867aeead 189 global $CFG, $USER, $OUTPUT;
fcdcc372 190
8ba4cbd2 191 $submission = $this->get_submission($USER->id);
fcdcc372 192
39bc9fbb 193 if ($this->isopen() and $this->can_finalize($submission)) {
55b4d096 194 //print final submit button
867aeead 195 echo $OUTPUT->heading(get_string('submitformarking','assignment'), 3);
d9cb14b8 196 echo '<div style="text-align:center">';
55b4d096 197 echo '<form method="post" action="upload.php">';
d9cb14b8 198 echo '<fieldset class="invisiblefieldset">';
55b4d096 199 echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />';
200 echo '<input type="hidden" name="action" value="finalize" />';
201 echo '<input type="submit" name="formarking" value="'.get_string('sendformarking', 'assignment').'" />';
d9cb14b8 202 echo '</fieldset>';
55b4d096 203 echo '</form>';
d9cb14b8 204 echo '</div>';
39bc9fbb 205 } else if (!$this->isopen()) {
867aeead 206 echo $OUTPUT->heading(get_string('nomoresubmissions','assignment'), 3);
39bc9fbb 207
42f50aec 208 } else if ($this->drafts_tracked() and $state = $this->is_finalized($submission)) {
39bc9fbb 209 if ($state == ASSIGNMENT_STATUS_SUBMITTED) {
867aeead 210 echo $OUTPUT->heading(get_string('submitedformarking','assignment'), 3);
39bc9fbb 211 } else {
867aeead 212 echo $OUTPUT->heading(get_string('nomoresubmissions','assignment'), 3);
39bc9fbb 213 }
55b4d096 214 } else {
215 //no submission yet
216 }
217 }
39bc9fbb 218
219
220 /**
dc6cb74e 221 * Return true if var3 == hide description till available day
39bc9fbb 222 *
dc6cb74e 223 *@return boolean
39bc9fbb 224 */
dc6cb74e 225 function description_is_hidden() {
226 return ($this->assignment->var3 && (time() <= $this->assignment->timeavailable));
227 }
fcdcc372 228
55b4d096 229 function custom_feedbackform($submission, $return=false) {
230 global $CFG;
8ba4cbd2 231
55b4d096 232 $mode = optional_param('mode', '', PARAM_ALPHA);
233 $offset = optional_param('offset', 0, PARAM_INT);
234 $forcerefresh = optional_param('forcerefresh', 0, PARAM_BOOL);
8ba4cbd2 235
172dd12c 236 $mform = new mod_assignment_upload_response_form("$CFG->wwwroot/mod/assignment/upload.php", $this);
237
238 $mform->set_data(array('id'=>$this->cm->id, 'offset'=>$offset, 'forcerefresh'=>$forcerefresh, 'userid'=>$submission->userid, 'mode'=>$mode));
239
55b4d096 240 $output = get_string('responsefiles', 'assignment').': ';
8ba4cbd2 241
172dd12c 242 ob_start();
243 $mform->display();
244 $output = ob_get_clean();
fcdcc372 245
55b4d096 246 if ($forcerefresh) {
247 $output .= $this->update_main_listing($submission);
248 }
fcdcc372 249
55b4d096 250 $responsefiles = $this->print_responsefiles($submission->userid, true);
251 if (!empty($responsefiles)) {
252 $output .= $responsefiles;
38ac07d2 253 }
55b4d096 254
255 if ($return) {
256 return $output;
38ac07d2 257 }
55b4d096 258 echo $output;
259 return;
260 }
fcdcc372 261
fcdcc372 262
55b4d096 263 function print_student_answer($userid, $return=false){
d436d197 264 global $CFG, $OUTPUT;
fcdcc372 265
55b4d096 266 $submission = $this->get_submission($userid);
8ba4cbd2 267
55b4d096 268 $output = '';
8ba4cbd2 269
172dd12c 270 if ($this->drafts_tracked() and $this->isopen() and !$this->is_finalized($submission)) {
271 $output .= '<strong>'.get_string('draft', 'assignment').':</strong> ';
272 }
55b4d096 273
172dd12c 274 if ($this->notes_allowed() and !empty($submission->data1)) {
a9573c08 275 $link = html_link::make("/mod/assignment/type/upload/notes.php?id=$this->cm->id&userid=$userid", get_string('notes', 'assignment'));
276 $link->add_action(new popup_action('click', $link->url, 'notes', array('height' => 500, 'width' => 780)));
277 $link->title = get_string('notes', 'assignment');
278 $output .= $OUTPUT->link($link);
279
172dd12c 280 $output .= '&nbsp;';
281 }
55b4d096 282
172dd12c 283 $fs = get_file_storage();
284 $browser = get_file_browser();
285
286 if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "timemodified", false)) {
287
288 foreach ($files as $file) {
289 $filename = $file->get_filename();
290 $found = true;
291 $mimetype = $file->get_mimetype();
4eef1399 292 $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
19c9f094 293 $output .= '<a href="'.$path.'" ><img class="icon" src="'.$OUTPUT->old_icon_url(file_mimetype_icon($mimetype)).'" alt="'.$mimetype.'" />'.s($filename).'</a>&nbsp;';
617ac19b 294
fcdcc372 295 }
172dd12c 296
fcdcc372 297 }
55b4d096 298 $output = '<div class="files">'.$output.'</div>';
299 $output .= '<br />';
8ba4cbd2 300
55b4d096 301 return $output;
fcdcc372 302 }
303
fcdcc372 304
55b4d096 305 /**
306 * Produces a list of links to the files uploaded by a user
307 *
308 * @param $userid int optional id of the user. If 0 then $USER->id is used.
309 * @param $return boolean optional defaults to false. If true the list is returned rather than printed
310 * @return string optional
311 */
312 function print_user_files($userid=0, $return=false) {
f2a1963c 313 global $CFG, $USER, $OUTPUT;
55b4d096 314
315 $mode = optional_param('mode', '', PARAM_ALPHA);
316 $offset = optional_param('offset', 0, PARAM_INT);
fcdcc372 317
55b4d096 318 if (!$userid) {
319 if (!isloggedin()) {
320 return '';
8ba4cbd2 321 }
55b4d096 322 $userid = $USER->id;
8ba4cbd2 323 }
324
55b4d096 325 $output = '';
8ba4cbd2 326
39bc9fbb 327 $submission = $this->get_submission($userid);
8ba4cbd2 328
39bc9fbb 329 $candelete = $this->can_delete_files($submission);
330 $strdelete = get_string('delete');
8ba4cbd2 331
42f50aec 332 if ($this->drafts_tracked() and $this->isopen() and !$this->is_finalized($submission) and !empty($mode)) { // only during grading
39bc9fbb 333 $output .= '<strong>'.get_string('draft', 'assignment').':</strong><br />';
334 }
fcdcc372 335
39bc9fbb 336 if ($this->notes_allowed() and !empty($submission->data1) and !empty($mode)) { // only during grading
fcdcc372 337
39bc9fbb 338 $npurl = $CFG->wwwroot."/mod/assignment/type/upload/notes.php?id={$this->cm->id}&amp;userid=$userid&amp;offset=$offset&amp;mode=single";
339 $output .= '<a href="'.$npurl.'">'.get_string('notes', 'assignment').'</a><br />';
fcdcc372 340
39bc9fbb 341 }
8ba4cbd2 342
172dd12c 343 $fs = get_file_storage();
344 $browser = get_file_browser();
345
346 if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "timemodified", false)) {
0d06b6fd 347 $button = new portfolio_add_button();
172dd12c 348 foreach ($files as $file) {
349 $filename = $file->get_filename();
350 $mimetype = $file->get_mimetype();
4eef1399 351 $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
19c9f094 352 $output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->old_icon_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />'.s($filename).'</a>';
617ac19b 353
172dd12c 354 if ($candelete) {
355 $delurl = "$CFG->wwwroot/mod/assignment/delete.php?id={$this->cm->id}&amp;file=".rawurlencode($filename)."&amp;userid={$submission->userid}&amp;mode=$mode&amp;offset=$offset";
617ac19b 356
172dd12c 357 $output .= '<a href="'.$delurl.'">&nbsp;'
f2a1963c 358 .'<img title="'.$strdelete.'" src="'.$OUTPUT->old_icon_url('t/delete') . '" class="iconsmall" alt="" /></a> ';
8ba4cbd2 359 }
617ac19b 360
728e1931 361 if (has_capability('mod/assignment:exportownsubmission', $this->context)) {
6be1dcae 362 $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/lib.php');
0d06b6fd 363 $button->set_formats(portfolio_format_from_file($file));
364 $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
67a87e7d 365 }
172dd12c 366 $output .= '<br />';
367 }
0d06b6fd 368 if (count($files) > 1 && has_capability('mod/assignment:exportownsubmission', $this->context)) {
0d06b6fd 369 $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/lib.php');
9d7432f6 370 $button->set_formats(PORTFOLIO_FORMAT_FILE);
0d06b6fd 371 $output .= $button->to_html();
55b4d096 372 }
39bc9fbb 373 }
03076be4 374
375 if ($this->drafts_tracked() and $this->isopen() and has_capability('mod/assignment:grade', $this->context) and $mode != '') { // we do not want it on view.php page
39bc9fbb 376 if ($this->can_unfinalize($submission)) {
377 $options = array ('id'=>$this->cm->id, 'userid'=>$userid, 'action'=>'unfinalize', 'mode'=>$mode, 'offset'=>$offset);
75d47fa9 378 $output .= $OUTPUT->button(html_form::make_button('upload.php', $options, get_string('unfinalize', 'assignment')));
39bc9fbb 379 } else if ($this->can_finalize($submission)) {
380 $options = array ('id'=>$this->cm->id, 'userid'=>$userid, 'action'=>'finalizeclose', 'mode'=>$mode, 'offset'=>$offset);
75d47fa9 381 $output .= $OUTPUT->button(html_form::make_button('upload.php', $options, get_string('finalize', 'assignment')));
55b4d096 382 }
55b4d096 383 }
8ba4cbd2 384
39bc9fbb 385 $output = '<div class="files">'.$output.'</div>';
386
55b4d096 387 if ($return) {
388 return $output;
389 }
390 echo $output;
391 }
8ba4cbd2 392
55b4d096 393 function print_responsefiles($userid, $return=false) {
f2a1963c 394 global $CFG, $USER, $OUTPUT;
8ba4cbd2 395
55b4d096 396 $mode = optional_param('mode', '', PARAM_ALPHA);
397 $offset = optional_param('offset', 0, PARAM_INT);
8ba4cbd2 398
55b4d096 399 $output = '';
fcdcc372 400
55b4d096 401 $candelete = $this->can_manage_responsefiles();
402 $strdelete = get_string('delete');
fcdcc372 403
172dd12c 404 $fs = get_file_storage();
405 $browser = get_file_browser();
fcdcc372 406
172dd12c 407 if ($files = $fs->get_area_files($this->context->id, 'assignment_response', $userid, "timemodified", false)) {
408 foreach ($files as $file) {
409 $filename = $file->get_filename();
410 $found = true;
411 $mimetype = $file->get_mimetype();
4eef1399 412 $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_response/'.$userid.'/'.$filename);
fcdcc372 413
19c9f094 414 $output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->old_icon_url(file_mimetype_icon($mimetype)).'" alt="'.$mimetype.'" />'.$filename.'</a>';
fcdcc372 415
172dd12c 416 if ($candelete) {
417 $delurl = "$CFG->wwwroot/mod/assignment/delete.php?id={$this->cm->id}&amp;file=".rawurlencode($filename)."&amp;userid=$userid&amp;mode=$mode&amp;offset=$offset&amp;action=response";
fcdcc372 418
172dd12c 419 $output .= '<a href="'.$delurl.'">&nbsp;'
f2a1963c 420 .'<img title="'.$strdelete.'" src="'.$OUTPUT->old_icon_url('t/delete') . '" class="iconsmall" alt=""/></a> ';
55b4d096 421 }
fcdcc372 422
172dd12c 423 $output .= '&nbsp;';
424 }
fcdcc372 425
55b4d096 426 $output = '<div class="responsefiles">'.$output.'</div>';
8ba4cbd2 427 }
fcdcc372 428
55b4d096 429 if ($return) {
430 return $output;
8ba4cbd2 431 }
55b4d096 432 echo $output;
433 }
fcdcc372 434
fcdcc372 435
55b4d096 436 function upload() {
437 $action = required_param('action', PARAM_ALPHA);
fcdcc372 438
55b4d096 439 switch ($action) {
440 case 'finalize':
441 $this->finalize();
442 break;
39bc9fbb 443 case 'finalizeclose':
03076be4 444 $this->finalizeclose();
39bc9fbb 445 break;
55b4d096 446 case 'unfinalize':
447 $this->unfinalize();
448 break;
449 case 'uploadresponse':
450 $this->upload_responsefile();
451 break;
452 case 'uploadfile':
453 $this->upload_file();
454 case 'savenotes':
455 case 'editnotes':
456 $this->upload_notes();
457 default:
a939f681 458 print_error('unknowuploadaction', '', '', $action);
8ba4cbd2 459 }
55b4d096 460 }
fcdcc372 461
55b4d096 462 function upload_notes() {
867aeead 463 global $CFG, $USER, $OUTPUT;
fcdcc372 464
55b4d096 465 $action = required_param('action', PARAM_ALPHA);
fcdcc372 466
55b4d096 467 $returnurl = 'view.php?id='.$this->cm->id;
fcdcc372 468
1d284fbd 469 $mform = new mod_assignment_upload_notes_form();
6117edc7 470
471 $defaults = new object();
472 $defaults->id = $this->cm->id;
473
e38204d1 474 if ($submission = $this->get_submission($USER->id)) {
6117edc7 475 $defaults->text = $submission->data1;
e38204d1 476 } else {
6117edc7 477 $defaults->text = '';
e38204d1 478 }
479
beac4717 480 $mform->set_data($defaults);
6117edc7 481
5571b5f4 482 if ($mform->is_cancelled()) {
483 redirect('view.php?id='.$this->cm->id);
484 }
485
e38204d1 486 if (!$this->can_update_notes($submission)) {
487 $this->view_header(get_string('upload'));
3a003ead 488 echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
489 echo $OUTPUT->continue_button($returnurl);
e38204d1 490 $this->view_footer();
491 die;
492 }
493
294ce987 494 if ($data = $mform->get_data() and $action == 'savenotes') {
55b4d096 495 $submission = $this->get_submission($USER->id, true); // get or create submission
496 $updated = new object();
497 $updated->id = $submission->id;
498 $updated->timemodified = time();
6117edc7 499 $updated->data1 = $data->text;
fcdcc372 500
74d7d735 501 if ($DB->update_record('assignment_submissions', $updated)) {
55b4d096 502 add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
503 redirect($returnurl);
12dce253 504 $submission = $this->get_submission($USER->id);
505 $this->update_grade($submission);
506
55b4d096 507 } else {
508 $this->view_header(get_string('notes', 'assignment'));
3a003ead 509 echo $OUTPUT->notification(get_string('notesupdateerror', 'assignment'));
510 echo $OUTPUT->continue_button($returnurl);
55b4d096 511 $this->view_footer();
512 die;
513 }
514 }
fcdcc372 515
55b4d096 516 /// show notes edit form
55b4d096 517 $this->view_header(get_string('notes', 'assignment'));
6117edc7 518
867aeead 519 echo $OUTPUT->heading(get_string('notes', 'assignment'));
6fc73d59 520
6117edc7 521 $mform->display();
8ba4cbd2 522
55b4d096 523 $this->view_footer();
524 die;
fcdcc372 525 }
526
55b4d096 527 function upload_responsefile() {
83a7f058 528 global $CFG, $USER, $OUTPUT, $PAGE;
8ba4cbd2 529
55b4d096 530 $userid = required_param('userid', PARAM_INT);
531 $mode = required_param('mode', PARAM_ALPHA);
532 $offset = required_param('offset', PARAM_INT);
fcdcc372 533
55b4d096 534 $returnurl = "submissions.php?id={$this->cm->id}&amp;userid=$userid&amp;mode=$mode&amp;offset=$offset";
fcdcc372 535
172dd12c 536 $mform = new mod_assignment_upload_response_form(null, $this);
537 if ($mform->get_data() and $this->can_manage_responsefiles()) {
538 $fs = get_file_storage();
539 $filename = $mform->get_new_filename('newfile');
540 if ($filename !== false) {
541 if (!$fs->file_exists($this->context->id, 'assignment_response', $userid, '/', $filename)) {
542 if ($file = $mform->save_stored_file('newfile', $this->context->id, 'assignment_response', $userid, '/', $filename, false, $USER->id)) {
543 redirect($returnurl);
544 }
545 }
38ac07d2 546 }
fcdcc372 547 }
83a7f058 548 $PAGE->set_title(get_string('upload'));
549 echo $OUTPUT->header();
3a003ead 550 echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
551 echo $OUTPUT->continue_button($returnurl);
256d2850 552 echo $OUTPUT->footer();
172dd12c 553 die;
fcdcc372 554 }
555
55b4d096 556 function upload_file() {
3a003ead 557 global $CFG, $USER, $DB, $OUTPUT;
8ba4cbd2 558
55b4d096 559 $returnurl = 'view.php?id='.$this->cm->id;
8ba4cbd2 560
55b4d096 561 $filecount = $this->count_user_files($USER->id);
562 $submission = $this->get_submission($USER->id);
8ba4cbd2 563
55b4d096 564 if (!$this->can_upload_file($submission)) {
565 $this->view_header(get_string('upload'));
3a003ead 566 echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
567 echo $OUTPUT->continue_button($returnurl);
55b4d096 568 $this->view_footer();
569 die;
570 }
8ba4cbd2 571
172dd12c 572 $mform = new mod_assignment_upload_file_form('upload.php', $this);
573 if ($mform->get_data()) {
574 $fs = get_file_storage();
575 $filename = $mform->get_new_filename('newfile');
576 if ($filename !== false) {
577 if (!$fs->file_exists($this->context->id, 'assignment_submission', $USER->id, '/', $filename)) {
578 if ($file = $mform->save_stored_file('newfile', $this->context->id, 'assignment_submission', $USER->id, '/', $filename, false, $USER->id)) {
579 $submission = $this->get_submission($USER->id, true); //create new submission if needed
580 $submission->timemodified = time();
581 if ($DB->update_record('assignment_submissions', $submission)) {
582 add_to_log($this->course->id, 'assignment', 'upload',
583 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
584 $this->update_grade($submission);
585 if (!$this->drafts_tracked()) {
586 $this->email_teachers($submission);
587 }
588 redirect('view.php?id='.$this->cm->id);
589 } else {
590 $file->delete();
591 }
592 }
91d8d9a0 593 }
fcdcc372 594 }
595 }
172dd12c 596
55b4d096 597 $this->view_header(get_string('upload'));
3a003ead 598 echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
599 echo $OUTPUT->continue_button($returnurl);
55b4d096 600 $this->view_footer();
601 die;
fcdcc372 602 }
603
172dd12c 604 function send_file($filearea, $args) {
605 global $CFG, $DB, $USER;
606 require_once($CFG->libdir.'/filelib.php');
607
608 require_login($this->course, false, $this->cm);
609
610 $userid = (int)array_shift($args);
611 $relativepath = '/'.implode('/', $args);
612 $fullpath = $this->context->id.$filearea.$userid.$relativepath;
613
614 $fs = get_file_storage();
615
616 if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
617 return false;
618 }
619
620 if ($filearea === 'assignment_submission') {
621 if ($USER->id != $userid and !has_capability('mod/assignment:grade', $this->context)) {
622 return false;
623 }
624
625 } else if ($filearea === 'assignment_response') {
626 if ($USER->id != $userid and !has_capability('mod/assignment:grade', $this->context)) {
627 return false;
628 }
629
630 } else {
631 return false;
632 }
633
43c60e88 634 send_stored_file($file, 0, 0, true); // download MUST be forced - security!
172dd12c 635 }
636
03076be4 637 function finalize() {
867aeead 638 global $USER, $DB, $OUTPUT;
fcdcc372 639
03076be4 640 $confirm = optional_param('confirm', 0, PARAM_BOOL);
641 $returnurl = 'view.php?id='.$this->cm->id;
642 $submission = $this->get_submission($USER->id);
55b4d096 643
644 if (!$this->can_finalize($submission)) {
39bc9fbb 645 redirect($returnurl); // probably already graded, redirect to assignment page, the reason should be obvious
55b4d096 646 }
647
03076be4 648 if (!data_submitted() or !$confirm) {
55b4d096 649 $optionsno = array('id'=>$this->cm->id);
650 $optionsyes = array ('id'=>$this->cm->id, 'confirm'=>1, 'action'=>'finalize');
651 $this->view_header(get_string('submitformarking', 'assignment'));
867aeead 652 echo $OUTPUT->heading(get_string('submitformarking', 'assignment'));
75d47fa9 653 echo $OUTPUT->confirm(get_string('onceassignmentsent', 'assignment'), new moodle_url('upload.php', $optionsyes),new moodle_url( 'view.php', $optionsno));
55b4d096 654 $this->view_footer();
655 die;
656
03076be4 657 }
658 $updated = new object();
659 $updated->id = $submission->id;
660 $updated->data2 = ASSIGNMENT_STATUS_SUBMITTED;
661 $updated->timemodified = time();
662
74d7d735 663 if ($DB->update_record('assignment_submissions', $updated)) {
03076be4 664 add_to_log($this->course->id, 'assignment', 'upload', //TODO: add finalize action to log
665 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
12dce253 666 $submission = $this->get_submission($USER->id);
667 $this->update_grade($submission);
03076be4 668 $this->email_teachers($submission);
55b4d096 669 } else {
03076be4 670 $this->view_header(get_string('submitformarking', 'assignment'));
3a003ead 671 echo $OUTPUT->notification(get_string('finalizeerror', 'assignment'));
672 echo $OUTPUT->continue_button($returnurl);
03076be4 673 $this->view_footer();
674 die;
675 }
676 redirect($returnurl);
677 }
39bc9fbb 678
03076be4 679 function finalizeclose() {
74d7d735 680 global $DB;
681
03076be4 682 $userid = optional_param('userid', 0, PARAM_INT);
683 $mode = required_param('mode', PARAM_ALPHA);
684 $offset = required_param('offset', PARAM_INT);
685 $returnurl = "submissions.php?id={$this->cm->id}&amp;userid=$userid&amp;mode=$mode&amp;offset=$offset&amp;forcerefresh=1";
686
12dce253 687 // create but do not add student submission date
03076be4 688 $submission = $this->get_submission($userid, true, true);
689
690 if (!data_submitted() or !$this->can_finalize($submission)) {
691 redirect($returnurl); // probably closed already
692 }
693
694 $updated = new object();
695 $updated->id = $submission->id;
696 $updated->data2 = ASSIGNMENT_STATUS_CLOSED;
697
74d7d735 698 if ($DB->update_record('assignment_submissions', $updated)) {
03076be4 699 add_to_log($this->course->id, 'assignment', 'upload', //TODO: add finalize action to log
700 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
12dce253 701 $submission = $this->get_submission($userid, false, true);
702 $this->update_grade($submission);
fcdcc372 703 }
55b4d096 704 redirect($returnurl);
705 }
fcdcc372 706
55b4d096 707 function unfinalize() {
74d7d735 708 global $DB;
8ba4cbd2 709
55b4d096 710 $userid = required_param('userid', PARAM_INT);
711 $mode = required_param('mode', PARAM_ALPHA);
712 $offset = required_param('offset', PARAM_INT);
fcdcc372 713
55b4d096 714 $returnurl = "submissions.php?id={$this->cm->id}&amp;userid=$userid&amp;mode=$mode&amp;offset=$offset&amp;forcerefresh=1";
8ba4cbd2 715
74d7d735 716 if (data_submitted()
55b4d096 717 and $submission = $this->get_submission($userid)
718 and $this->can_unfinalize($submission)) {
fcdcc372 719
55b4d096 720 $updated = new object();
721 $updated->id = $submission->id;
722 $updated->data2 = '';
74d7d735 723 if ($DB->update_record('assignment_submissions', $updated)) {
39bc9fbb 724 //TODO: add unfinalize action to log
55b4d096 725 add_to_log($this->course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->assignment->id, $this->assignment->id, $this->cm->id);
12dce253 726 $submission = $this->get_submission($userid);
727 $this->update_grade($submission);
55b4d096 728 } else {
0de80bcf 729 $this->view_header(get_string('submitformarking', 'assignment'));
3a003ead 730 echo $OUTPUT->notification(get_string('unfinalizeerror', 'assignment'));
731 echo $OUTPUT->continue_button($returnurl);
55b4d096 732 $this->view_footer();
733 die;
fcdcc372 734 }
735 }
55b4d096 736 redirect($returnurl);
737 }
fcdcc372 738
fcdcc372 739
55b4d096 740 function delete() {
741 $action = optional_param('action', '', PARAM_ALPHA);
fcdcc372 742
55b4d096 743 switch ($action) {
744 case 'response':
745 $this->delete_responsefile();
746 break;
747 default:
748 $this->delete_file();
fcdcc372 749 }
55b4d096 750 die;
751 }
fcdcc372 752
fcdcc372 753
55b4d096 754 function delete_responsefile() {
83a7f058 755 global $CFG, $OUTPUT,$PAGE;
8ba4cbd2 756
55b4d096 757 $file = required_param('file', PARAM_FILE);
758 $userid = required_param('userid', PARAM_INT);
759 $mode = required_param('mode', PARAM_ALPHA);
760 $offset = required_param('offset', PARAM_INT);
761 $confirm = optional_param('confirm', 0, PARAM_BOOL);
fcdcc372 762
75d47fa9 763 $returnurl = "submissions.php?id={$this->cm->id}&userid=$userid&mode=$mode&offset=$offset";
fcdcc372 764
55b4d096 765 if (!$this->can_manage_responsefiles()) {
766 redirect($returnurl);
767 }
fcdcc372 768
55b4d096 769 $urlreturn = 'submissions.php';
770 $optionsreturn = array('id'=>$this->cm->id, 'offset'=>$offset, 'mode'=>$mode, 'userid'=>$userid);
fcdcc372 771
74d7d735 772 if (!data_submitted() or !$confirm) {
55b4d096 773 $optionsyes = array ('id'=>$this->cm->id, 'file'=>$file, 'userid'=>$userid, 'confirm'=>1, 'action'=>'response', 'mode'=>$mode, 'offset'=>$offset);
83a7f058 774 $PAGE->set_title(get_string('delete'));
775 echo $OUTPUT->header();
867aeead 776 echo $OUTPUT->heading(get_string('delete'));
75d47fa9 777 echo $OUTPUT->confirm(get_string('confirmdeletefile', 'assignment', $file), new moodle_url('delete.php', $optionsyes), new moodle_url($urlreturn, $optionsreturn));
256d2850 778 echo $OUTPUT->footer();
55b4d096 779 die;
780 }
fcdcc372 781
172dd12c 782 $fs = get_file_storage();
783 if ($file = $fs->get_file($this->context->id, 'assignment_submission', $userid, '/', $file)) {
784 if ($file->delete()) {
55b4d096 785 redirect($returnurl);
786 }
787 }
fcdcc372 788
55b4d096 789 // print delete error
83a7f058 790 $PAGE->set_title(get_string('delete'));
791 echo $OUTPUT->header();
3a003ead 792 echo $OUTPUT->notification(get_string('deletefilefailed', 'assignment'));
793 echo $OUTPUT->continue_button($returnurl);
256d2850 794 echo $OUTPUT->footer();
55b4d096 795 die;
fcdcc372 796
55b4d096 797 }
fcdcc372 798
fcdcc372 799
55b4d096 800 function delete_file() {
55c7042d 801 global $CFG, $DB, $OUTPUT, $PAGE;
fcdcc372 802
55b4d096 803 $file = required_param('file', PARAM_FILE);
804 $userid = required_param('userid', PARAM_INT);
805 $confirm = optional_param('confirm', 0, PARAM_BOOL);
806 $mode = optional_param('mode', '', PARAM_ALPHA);
807 $offset = optional_param('offset', 0, PARAM_INT);
fcdcc372 808
55b4d096 809 require_login($this->course->id, false, $this->cm);
fcdcc372 810
55b4d096 811 if (empty($mode)) {
812 $urlreturn = 'view.php';
813 $optionsreturn = array('id'=>$this->cm->id);
814 $returnurl = 'view.php?id='.$this->cm->id;
8ba4cbd2 815 } else {
55b4d096 816 $urlreturn = 'submissions.php';
817 $optionsreturn = array('id'=>$this->cm->id, 'offset'=>$offset, 'mode'=>$mode, 'userid'=>$userid);
75d47fa9 818 $returnurl = "submissions.php?id={$this->cm->id}&offset=$offset&mode=$mode&userid=$userid";
fcdcc372 819 }
820
55b4d096 821 if (!$submission = $this->get_submission($userid) // incorrect submission
822 or !$this->can_delete_files($submission)) { // can not delete
823 $this->view_header(get_string('delete'));
3a003ead 824 echo $OUTPUT->notification(get_string('cannotdeletefiles', 'assignment'));
825 echo $OUTPUT->continue_button($returnurl);
55b4d096 826 $this->view_footer();
827 die;
fcdcc372 828 }
829
74d7d735 830 if (!data_submitted() or !$confirm) {
55b4d096 831 $optionsyes = array ('id'=>$this->cm->id, 'file'=>$file, 'userid'=>$userid, 'confirm'=>1, 'sesskey'=>sesskey(), 'mode'=>$mode, 'offset'=>$offset);
832 if (empty($mode)) {
833 $this->view_header(get_string('delete'));
834 } else {
55c7042d 835 $PAGE->set_title(get_string('delete'));
836 echo $OUTPUT->header();
fcdcc372 837 }
867aeead 838 echo $OUTPUT->heading(get_string('delete'));
75d47fa9 839 echo $OUTPUT->confirm(get_string('confirmdeletefile', 'assignment', $file), new moodle_url('delete.php', $optionsyes), new moodle_url($urlreturn, $optionsreturn));
55b4d096 840 if (empty($mode)) {
841 $this->view_footer();
842 } else {
256d2850 843 echo $OUTPUT->footer();
fcdcc372 844 }
55b4d096 845 die;
fcdcc372 846 }
847
172dd12c 848 $fs = get_file_storage();
849 if ($file = $fs->get_file($this->context->id, 'assignment_submission', $userid, '/', $file)) {
850 if ($file->delete()) {
851 $submission->timemodified = time();
852 if ($DB->update_record('assignment_submissions', $submission)) {
55b4d096 853 add_to_log($this->course->id, 'assignment', 'upload', //TODO: add delete action to log
854 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
12dce253 855 $this->update_grade($submission);
55b4d096 856 }
857 redirect($returnurl);
858 }
fcdcc372 859 }
860
55b4d096 861 // print delete error
862 if (empty($mode)) {
863 $this->view_header(get_string('delete'));
864 } else {
55c7042d 865 $PAGE->set_title(get_string('delete'));
866 echo $OUTPUT->header();
8ba4cbd2 867 }
3a003ead 868 echo $OUTPUT->notification(get_string('deletefilefailed', 'assignment'));
869 echo $OUTPUT->continue_button($returnurl);
55b4d096 870 if (empty($mode)) {
871 $this->view_footer();
872 } else {
256d2850 873 echo $OUTPUT->footer();
8ba4cbd2 874 }
55b4d096 875 die;
876 }
8ba4cbd2 877
8ba4cbd2 878
55b4d096 879 function can_upload_file($submission) {
880 global $USER;
fcdcc372 881
55b4d096 882 if (has_capability('mod/assignment:submit', $this->context) // can submit
883 and $this->isopen() // assignment not closed yet
55b4d096 884 and (empty($submission) or $submission->userid == $USER->id) // his/her own submission
83774723 885 and $this->count_user_files($USER->id) < $this->assignment->var1 // file limit not reached
886 and !$this->is_finalized($submission)) { // no uploading after final submission
55b4d096 887 return true;
888 } else {
889 return false;
8ba4cbd2 890 }
55b4d096 891 }
fcdcc372 892
55b4d096 893 function can_manage_responsefiles() {
894 if (has_capability('mod/assignment:grade', $this->context)) {
895 return true;
896 } else {
897 return false;
898 }
899 }
fcdcc372 900
55b4d096 901 function can_delete_files($submission) {
902 global $USER;
fcdcc372 903
55b4d096 904 if (has_capability('mod/assignment:grade', $this->context)) {
905 return true;
fcdcc372 906 }
907
55b4d096 908 if (has_capability('mod/assignment:submit', $this->context)
909 and $this->isopen() // assignment not closed yet
55b4d096 910 and $this->assignment->resubmit // deleting allowed
911 and $USER->id == $submission->userid // his/her own submission
912 and !$this->is_finalized($submission)) { // no deleting after final submission
913 return true;
914 } else {
915 return false;
fcdcc372 916 }
55b4d096 917 }
fcdcc372 918
42f50aec 919 function drafts_tracked() {
920 return !empty($this->assignment->var4);
921 }
922
39bc9fbb 923 /**
924 * Returns submission status
925 * @param object $submission - may be empty
926 * @return string submission state - empty, ASSIGNMENT_STATUS_SUBMITTED or ASSIGNMENT_STATUS_CLOSED
927 */
55b4d096 928 function is_finalized($submission) {
42f50aec 929 if (!$this->drafts_tracked()) {
930 return '';
931
932 } else if (empty($submission)) {
39bc9fbb 933 return '';
934
935 } else if ($submission->data2 == ASSIGNMENT_STATUS_SUBMITTED or $submission->data2 == ASSIGNMENT_STATUS_CLOSED) {
936 return $submission->data2;
937
55b4d096 938 } else {
39bc9fbb 939 return '';
fcdcc372 940 }
55b4d096 941 }
fcdcc372 942
55b4d096 943 function can_unfinalize($submission) {
42f50aec 944 if (!$this->drafts_tracked()) {
945 return false;
946 }
55b4d096 947 if (has_capability('mod/assignment:grade', $this->context)
ad1e3409 948 and $this->isopen()
949 and $this->is_finalized($submission)) {
55b4d096 950 return true;
fcdcc372 951 } else {
55b4d096 952 return false;
fcdcc372 953 }
fcdcc372 954 }
955
55b4d096 956 function can_finalize($submission) {
957 global $USER;
42f50aec 958 if (!$this->drafts_tracked()) {
959 return false;
960 }
8ba4cbd2 961
ad1e3409 962 if ($this->is_finalized($submission)) {
963 return false;
964 }
965
966 if (has_capability('mod/assignment:grade', $this->context)) {
967 return true;
968
969 } else if (has_capability('mod/assignment:submit', $this->context) // can submit
55b4d096 970 and $this->isopen() // assignment not closed yet
971 and !empty($submission) // submission must exist
55b4d096 972 and $submission->userid == $USER->id // his/her own submission
55b4d096 973 and ($this->count_user_files($USER->id)
ad1e3409 974 or ($this->notes_allowed() and !empty($submission->data1)))) { // something must be submitted
8ba4cbd2 975
55b4d096 976 return true;
8ba4cbd2 977 } else {
55b4d096 978 return false;
8ba4cbd2 979 }
55b4d096 980 }
8ba4cbd2 981
55b4d096 982 function can_update_notes($submission) {
983 global $USER;
8ba4cbd2 984
55b4d096 985 if (has_capability('mod/assignment:submit', $this->context)
ad1e3409 986 and $this->notes_allowed() // notesd must be allowed
55b4d096 987 and $this->isopen() // assignment not closed yet
55b4d096 988 and (empty($submission) or $USER->id == $submission->userid) // his/her own submission
989 and !$this->is_finalized($submission)) { // no updateingafter final submission
990 return true;
8ba4cbd2 991 } else {
55b4d096 992 return false;
8ba4cbd2 993 }
8ba4cbd2 994 }
995
55b4d096 996 function notes_allowed() {
997 return (boolean)$this->assignment->var2;
998 }
8ba4cbd2 999
55b4d096 1000 function count_responsefiles($userid) {
172dd12c 1001 $fs = get_file_storage();
1002 $files = $fs->get_area_files($this->context->id, 'assignment_response', $userid, "id", false);
1003 return count($files);
38ac07d2 1004 }
8ba4cbd2 1005
436cfa9f 1006 function setup_elements(&$mform) {
1007 global $CFG, $COURSE;
1008
1009 $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
1010
1011 $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
436cfa9f 1012 $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
1013 $mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $choices);
1014 $mform->setDefault('maxbytes', $CFG->assignment_maxbytes);
1015
1016 $mform->addElement('select', 'resubmit', get_string("allowdeleting", "assignment"), $ynoptions);
1017 $mform->setHelpButton('resubmit', array('allowdeleting', get_string('allowdeleting', 'assignment'), 'assignment'));
1018 $mform->setDefault('resubmit', 1);
1019
1020 $options = array();
1021 for($i = 1; $i <= 20; $i++) {
1022 $options[$i] = $i;
1023 }
1024 $mform->addElement('select', 'var1', get_string("allowmaxfiles", "assignment"), $options);
1025 $mform->setHelpButton('var1', array('allowmaxfiles', get_string('allowmaxfiles', 'assignment'), 'assignment'));
1026 $mform->setDefault('var1', 3);
1027
1028 $mform->addElement('select', 'var2', get_string("allownotes", "assignment"), $ynoptions);
1029 $mform->setHelpButton('var2', array('allownotes', get_string('allownotes', 'assignment'), 'assignment'));
1030 $mform->setDefault('var2', 0);
1031
1032 $mform->addElement('select', 'var3', get_string("hideintro", "assignment"), $ynoptions);
1033 $mform->setHelpButton('var3', array('hideintro', get_string('hideintro', 'assignment'), 'assignment'));
1034 $mform->setDefault('var3', 0);
1035
1036 $mform->addElement('select', 'emailteachers', get_string("emailteachers", "assignment"), $ynoptions);
1037 $mform->setHelpButton('emailteachers', array('emailteachers', get_string('emailteachers', 'assignment'), 'assignment'));
1038 $mform->setDefault('emailteachers', 0);
1039
42f50aec 1040 $mform->addElement('select', 'var4', get_string("trackdrafts", "assignment"), $ynoptions);
1041 $mform->setHelpButton('var4', array('trackdrafts', get_string('trackdrafts', 'assignment'), 'assignment'));
26087ac5 1042 $mform->setDefault('var4', 1);
436cfa9f 1043
1044 }
1045
67a87e7d 1046 function portfolio_exportable() {
1047 return true;
1048 }
1049
6117edc7 1050}
1051
f07b9627 1052class mod_assignment_upload_notes_form extends moodleform {
6117edc7 1053 function definition() {
172dd12c 1054 $mform = $this->_form;
6117edc7 1055
1056 // visible elements
1057 $mform->addElement('htmleditor', 'text', get_string('notes', 'assignment'), array('cols'=>85, 'rows'=>30));
1058 $mform->setType('text', PARAM_RAW); // to be cleaned before display
18a77361 1059 $mform->setHelpButton('text', array('reading', 'writing'), false, 'editorhelpbutton');
55b4d096 1060
6117edc7 1061 // hidden params
1062 $mform->addElement('hidden', 'id', 0);
1063 $mform->setType('id', PARAM_INT);
1064 $mform->addElement('hidden', 'action', 'savenotes');
172dd12c 1065 $mform->setType('action', PARAM_ALPHA);
6117edc7 1066
1067 // buttons
a23f0aaf 1068 $this->add_action_buttons();
6117edc7 1069 }
fcdcc372 1070}
8ba4cbd2 1071
172dd12c 1072class mod_assignment_upload_response_form extends moodleform {
1073 function definition() {
1074 $mform = $this->_form;
1075 $instance = $this->_customdata;
1076
1077 // visible elements
1078 $mform->addElement('file', 'newfile', get_string('uploadafile'));
1079
1080 // hidden params
1081 $mform->addElement('hidden', 'id', $instance->cm->id);
1082 $mform->setType('id', PARAM_INT);
1083 $mform->addElement('hidden', 'action', 'uploadresponse');
1084 $mform->setType('action', PARAM_ALPHA);
1085 $mform->addElement('hidden', 'mode');
1086 $mform->setType('mode', PARAM_ALPHA);
1087 $mform->addElement('hidden', 'offset');
1088 $mform->setType('offset', PARAM_INT);
1089 $mform->addElement('hidden', 'forcerefresh');
1090 $mform->setType('forcerefresh', PARAM_INT);
1091 $mform->addElement('hidden', 'userid');
1092 $mform->setType('userid', PARAM_INT);
1093
1094 // buttons
1095 $this->add_action_buttons(false, get_string('uploadthisfile'));
1096 }
1097}
1098
67a87e7d 1099
1100
fcdcc372 1101?>