|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00025 require_once(dirname(__FILE__).'/upload_form.php'); 00026 require_once($CFG->libdir . '/portfoliolib.php'); 00027 require_once($CFG->dirroot . '/mod/assignment/lib.php'); 00028 00029 define('ASSIGNMENT_STATUS_SUBMITTED', 'submitted'); // student thinks it is finished 00030 define('ASSIGNMENT_STATUS_CLOSED', 'closed'); // teacher prevents more submissions 00031 00036 class assignment_upload extends assignment_base { 00037 00038 function assignment_upload($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) { 00039 parent::assignment_base($cmid, $assignment, $cm, $course); 00040 $this->type = 'upload'; 00041 } 00042 00043 function view() { 00044 global $USER, $OUTPUT; 00045 00046 require_capability('mod/assignment:view', $this->context); 00047 $cansubmit = has_capability('mod/assignment:submit', $this->context); 00048 00049 add_to_log($this->course->id, 'assignment', 'view', "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id); 00050 00051 $this->view_header(); 00052 00053 if ($this->assignment->timeavailable > time() 00054 and !has_capability('mod/assignment:grade', $this->context) // grading user can see it anytime 00055 and $this->assignment->var3) { // force hiding before available date 00056 echo $OUTPUT->box_start('generalbox boxaligncenter', 'intro'); 00057 print_string('notavailableyet', 'assignment'); 00058 echo $OUTPUT->box_end(); 00059 } else { 00060 $this->view_intro(); 00061 } 00062 00063 $this->view_dates(); 00064 00065 if (is_enrolled($this->context, $USER)) { 00066 if ($submission = $this->get_submission($USER->id)) { 00067 $filecount = $this->count_user_files($submission->id); 00068 } else { 00069 $filecount = 0; 00070 } 00071 if ($cansubmit or !empty($filecount)) { //if a user has submitted files using a previous role we should still show the files 00072 $this->view_feedback(); 00073 00074 if (!$this->drafts_tracked() or !$this->isopen() or $this->is_finalized($submission)) { 00075 echo $OUTPUT->heading(get_string('submission', 'assignment'), 3); 00076 } else { 00077 echo $OUTPUT->heading(get_string('submissiondraft', 'assignment'), 3); 00078 } 00079 00080 if ($filecount and $submission) { 00081 echo $OUTPUT->box($this->print_user_files($USER->id, true), 'generalbox boxaligncenter', 'userfiles'); 00082 } else { 00083 if (!$this->isopen() or $this->is_finalized($submission)) { 00084 echo $OUTPUT->box(get_string('nofiles', 'assignment'), 'generalbox boxaligncenter nofiles', 'userfiles'); 00085 } else { 00086 echo $OUTPUT->box(get_string('nofilesyet', 'assignment'), 'generalbox boxaligncenter nofiles', 'userfiles'); 00087 } 00088 } 00089 00090 $this->view_upload_form(); 00091 00092 if ($this->notes_allowed()) { 00093 echo $OUTPUT->heading(get_string('notes', 'assignment'), 3); 00094 $this->view_notes(); 00095 } 00096 00097 $this->view_final_submission(); 00098 } 00099 } 00100 $this->view_footer(); 00101 } 00102 00103 00104 function view_feedback($submission=NULL) { 00105 global $USER, $CFG, $DB, $OUTPUT, $PAGE; 00106 require_once($CFG->libdir.'/gradelib.php'); 00107 require_once("$CFG->dirroot/grade/grading/lib.php"); 00108 00109 if (!$submission) { 00110 $userid = $USER->id; 00111 $submission = $this->get_submission($userid); 00112 } else { 00113 $userid = $submission->userid; 00114 } 00115 00116 if (empty($submission->timemarked)) { 00117 return; 00118 } 00119 // Check the user can submit 00120 $canviewfeedback = ($userid == $USER->id && has_capability('mod/assignment:submit', $this->context, $USER->id, false)); 00121 // If not then check if the user still has the view cap and has a previous submission 00122 $canviewfeedback = $canviewfeedback || (!empty($submission) && $submission->userid == $USER->id && has_capability('mod/assignment:view', $this->context)); 00123 // Or if user can grade (is a teacher or admin) 00124 $canviewfeedback = $canviewfeedback || has_capability('mod/assignment:grade', $this->context); 00125 00126 if (!$canviewfeedback) { 00127 // can not view or submit assignments -> no feedback 00128 return; 00129 } 00130 00131 $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $userid); 00132 $item = $grading_info->items[0]; 00133 $grade = $item->grades[$userid]; 00134 00135 if ($grade->hidden or $grade->grade === false) { // hidden or error 00136 return; 00137 } 00138 00139 if ($grade->grade === null and empty($grade->str_feedback)) { // No grade to show yet 00140 if ($this->count_responsefiles($userid)) { // but possibly response files are present 00141 echo $OUTPUT->heading(get_string('responsefiles', 'assignment'), 3); 00142 $responsefiles = $this->print_responsefiles($userid, true); 00143 echo $OUTPUT->box($responsefiles, 'generalbox boxaligncenter'); 00144 } 00145 return; 00146 } 00147 00148 $graded_date = $grade->dategraded; 00149 $graded_by = $grade->usermodified; 00150 00152 if (!$teacher = $DB->get_record('user', array('id'=>$graded_by))) { 00153 print_error('cannotfindteacher'); 00154 } 00155 00157 echo $OUTPUT->heading(get_string('submissionfeedback', 'assignment'), 3); 00158 00159 echo '<table cellspacing="0" class="feedback">'; 00160 00161 echo '<tr>'; 00162 echo '<td class="left picture">'; 00163 echo $OUTPUT->user_picture($teacher); 00164 echo '</td>'; 00165 echo '<td class="topic">'; 00166 echo '<div class="from">'; 00167 echo '<div class="fullname">'.fullname($teacher).'</div>'; 00168 echo '<div class="time">'.userdate($graded_date).'</div>'; 00169 echo '</div>'; 00170 echo '</td>'; 00171 echo '</tr>'; 00172 00173 echo '<tr>'; 00174 echo '<td class="left side"> </td>'; 00175 echo '<td class="content">'; 00176 $gradestr = '<div class="grade">'. get_string("grade").': '.$grade->str_long_grade. '</div>'; 00177 if (!empty($submission) && $controller = get_grading_manager($this->context, 'mod_assignment', 'submission')->get_active_controller()) { 00178 $controller->set_grade_range(make_grades_menu($this->assignment->grade)); 00179 echo $controller->render_grade($PAGE, $submission->id, $item, $gradestr, has_capability('mod/assignment:grade', $this->context)); 00180 } else { 00181 echo $gradestr; 00182 } 00183 echo '<div class="clearer"></div>'; 00184 00185 echo '<div class="comment">'; 00186 echo $grade->str_feedback; 00187 echo '</div>'; 00188 echo '</tr>'; 00189 00190 echo '<tr>'; 00191 echo '<td class="left side"> </td>'; 00192 echo '<td class="content">'; 00193 echo $this->print_responsefiles($userid, true); 00194 echo '</tr>'; 00195 00196 echo '</table>'; 00197 } 00198 00199 00200 function view_upload_form() { 00201 global $CFG, $USER, $OUTPUT; 00202 00203 $submission = $this->get_submission($USER->id); 00204 00205 if ($this->is_finalized($submission)) { 00206 // no uploading 00207 return; 00208 } 00209 00210 if ($this->can_upload_file($submission)) { 00211 $fs = get_file_storage(); 00212 // edit files in another page 00213 if ($submission) { 00214 if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) { 00215 $str = get_string('editthesefiles', 'assignment'); 00216 } else { 00217 $str = get_string('uploadfiles', 'assignment'); 00218 } 00219 } else { 00220 $str = get_string('uploadfiles', 'assignment'); 00221 } 00222 echo $OUTPUT->single_button(new moodle_url('/mod/assignment/type/upload/upload.php', array('contextid'=>$this->context->id, 'userid'=>$USER->id)), $str, 'get'); 00223 } 00224 } 00225 00226 function view_notes() { 00227 global $USER, $OUTPUT; 00228 00229 if ($submission = $this->get_submission($USER->id) 00230 and !empty($submission->data1)) { 00231 echo $OUTPUT->box(format_text($submission->data1, FORMAT_HTML, array('overflowdiv'=>true)), 'generalbox boxaligncenter boxwidthwide'); 00232 } else { 00233 echo $OUTPUT->box(get_string('notesempty', 'assignment'), 'generalbox boxaligncenter'); 00234 } 00235 if ($this->can_update_notes($submission)) { 00236 $options = array ('id'=>$this->cm->id, 'action'=>'editnotes'); 00237 echo '<div style="text-align:center">'; 00238 echo $OUTPUT->single_button(new moodle_url('upload.php', $options), get_string('edit')); 00239 echo '</div>'; 00240 } 00241 } 00242 00243 function view_final_submission() { 00244 global $CFG, $USER, $OUTPUT; 00245 00246 $submission = $this->get_submission($USER->id); 00247 00248 if ($this->isopen() and $this->can_finalize($submission)) { 00249 //print final submit button 00250 echo $OUTPUT->heading(get_string('submitformarking','assignment'), 3); 00251 echo '<div style="text-align:center">'; 00252 echo '<form method="post" action="upload.php">'; 00253 echo '<fieldset class="invisiblefieldset">'; 00254 echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />'; 00255 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; 00256 echo '<input type="hidden" name="action" value="finalize" />'; 00257 echo '<input type="submit" name="formarking" value="'.get_string('sendformarking', 'assignment').'" />'; 00258 echo '</fieldset>'; 00259 echo '</form>'; 00260 echo '</div>'; 00261 } else if (!$this->isopen()) { 00262 echo $OUTPUT->heading(get_string('nomoresubmissions','assignment'), 3); 00263 00264 } else if ($this->drafts_tracked() and $state = $this->is_finalized($submission)) { 00265 if ($state == ASSIGNMENT_STATUS_SUBMITTED) { 00266 echo $OUTPUT->heading(get_string('submitedformarking','assignment'), 3); 00267 } else { 00268 echo $OUTPUT->heading(get_string('nomoresubmissions','assignment'), 3); 00269 } 00270 } else { 00271 //no submission yet 00272 } 00273 } 00274 00275 00281 function description_is_hidden() { 00282 return ($this->assignment->var3 && (time() <= $this->assignment->timeavailable)); 00283 } 00284 00285 function print_student_answer($userid, $return=false){ 00286 global $CFG, $OUTPUT, $PAGE; 00287 00288 $submission = $this->get_submission($userid); 00289 00290 $output = ''; 00291 00292 if ($this->drafts_tracked() and $this->isopen() and !$this->is_finalized($submission)) { 00293 $output .= '<strong>'.get_string('draft', 'assignment').':</strong> '; 00294 } 00295 00296 if ($this->notes_allowed() and !empty($submission->data1)) { 00297 $link = new moodle_url("/mod/assignment/type/upload/notes.php", array('id'=>$this->cm->id, 'userid'=>$userid)); 00298 $action = new popup_action('click', $link, 'notes', array('height' => 500, 'width' => 780)); 00299 $output .= $OUTPUT->action_link($link, get_string('notes', 'assignment'), $action, array('title'=>get_string('notes', 'assignment'))); 00300 00301 $output .= ' '; 00302 } 00303 00304 00305 $renderer = $PAGE->get_renderer('mod_assignment'); 00306 $output = $OUTPUT->box_start('files').$output; 00307 $output .= $renderer->assignment_files($this->context, $submission->id); 00308 $output .= $OUTPUT->box_end(); 00309 00310 return $output; 00311 } 00312 00313 00321 function print_user_files($userid=0, $return=false) { 00322 global $CFG, $USER, $OUTPUT, $PAGE; 00323 00324 $mode = optional_param('mode', '', PARAM_ALPHA); 00325 $offset = optional_param('offset', 0, PARAM_INT); 00326 00327 if (!$userid) { 00328 if (!isloggedin()) { 00329 return ''; 00330 } 00331 $userid = $USER->id; 00332 } 00333 00334 $output = $OUTPUT->box_start('files'); 00335 00336 $submission = $this->get_submission($userid); 00337 00338 // only during grading 00339 if ($this->drafts_tracked() and $this->isopen() and !$this->is_finalized($submission) and !empty($mode)) { 00340 $output .= '<strong>'.get_string('draft', 'assignment').':</strong><br />'; 00341 } 00342 00343 if ($this->notes_allowed() and !empty($submission->data1) and !empty($mode)) { // only during grading 00344 00345 $npurl = $CFG->wwwroot."/mod/assignment/type/upload/notes.php?id={$this->cm->id}&userid=$userid&offset=$offset&mode=single"; 00346 $output .= '<a href="'.$npurl.'">'.get_string('notes', 'assignment').'</a><br />'; 00347 00348 } 00349 00350 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 00351 if ($this->can_unfinalize($submission)) { 00352 //$options = array ('id'=>$this->cm->id, 'userid'=>$userid, 'action'=>'unfinalize', 'mode'=>$mode, 'offset'=>$offset); 00353 $output .= '<br /><input type="submit" name="unfinalize" value="'.get_string('unfinalize', 'assignment').'" />'; 00354 $output .= $OUTPUT->help_icon('unfinalize', 'assignment'); 00355 00356 } else if ($this->can_finalize($submission)) { 00357 //$options = array ('id'=>$this->cm->id, 'userid'=>$userid, 'action'=>'finalizeclose', 'mode'=>$mode, 'offset'=>$offset); 00358 $output .= '<br /><input type="submit" name="finalize" value="'.get_string('finalize', 'assignment').'" />'; 00359 } 00360 } 00361 00362 if ($submission) { 00363 $renderer = $PAGE->get_renderer('mod_assignment'); 00364 $output .= $renderer->assignment_files($this->context, $submission->id); 00365 } 00366 $output .= $OUTPUT->box_end(); 00367 00368 if ($return) { 00369 return $output; 00370 } 00371 echo $output; 00372 } 00373 00374 function submissions($mode) { 00375 // redirects out of form to process (un)finalizing. 00376 $unfinalize = optional_param('unfinalize', FALSE, PARAM_TEXT); 00377 $finalize = optional_param('finalize', FALSE, PARAM_TEXT); 00378 if ($unfinalize) { 00379 $this->unfinalize('single'); 00380 } else if ($finalize) { 00381 $this->finalize('single'); 00382 } 00383 if ($unfinalize || $finalize) { 00384 $mode = 'singlenosave'; 00385 } 00386 parent::submissions($mode); 00387 } 00388 00389 function process_feedback() { 00390 if (!$feedback = data_submitted() or !confirm_sesskey()) { // No incoming data? 00391 return false; 00392 } 00393 $userid = required_param('userid', PARAM_INT); 00394 $offset = required_param('offset', PARAM_INT); 00395 $mform = $this->display_submission($offset, $userid, false); 00396 parent::process_feedback($mform); 00397 } 00398 00399 function print_responsefiles($userid, $return=false) { 00400 global $CFG, $USER, $OUTPUT, $PAGE; 00401 00402 $mode = optional_param('mode', '', PARAM_ALPHA); 00403 $offset = optional_param('offset', 0, PARAM_INT); 00404 00405 $output = $OUTPUT->box_start('responsefiles'); 00406 00407 $candelete = $this->can_manage_responsefiles(); 00408 $strdelete = get_string('delete'); 00409 00410 $fs = get_file_storage(); 00411 $browser = get_file_browser(); 00412 00413 if ($submission = $this->get_submission($userid)) { 00414 $renderer = $PAGE->get_renderer('mod_assignment'); 00415 $output .= $renderer->assignment_files($this->context, $submission->id, 'response'); 00416 } 00417 $output .= $OUTPUT->box_end(); 00418 00419 if ($return) { 00420 return $output; 00421 } 00422 echo $output; 00423 } 00424 00425 00432 function upload($mform = null, $filemanager_options = null) { 00433 $action = required_param('action', PARAM_ALPHA); 00434 switch ($action) { 00435 case 'finalize': 00436 $this->finalize(); 00437 break; 00438 case 'finalizeclose': 00439 $this->finalizeclose(); 00440 break; 00441 case 'unfinalize': 00442 $this->unfinalize(); 00443 break; 00444 case 'uploadresponse': 00445 $this->upload_responsefile($mform, $filemanager_options); 00446 break; 00447 case 'uploadfile': 00448 $this->upload_file($mform, $filemanager_options); 00449 case 'savenotes': 00450 case 'editnotes': 00451 $this->upload_notes(); 00452 default: 00453 print_error('unknowuploadaction', '', '', $action); 00454 } 00455 } 00456 00457 function upload_notes() { 00458 global $CFG, $USER, $OUTPUT, $DB; 00459 00460 $action = required_param('action', PARAM_ALPHA); 00461 00462 $returnurl = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id)); 00463 00464 $mform = new mod_assignment_upload_notes_form(); 00465 00466 $defaults = new stdClass(); 00467 $defaults->id = $this->cm->id; 00468 00469 if ($submission = $this->get_submission($USER->id)) { 00470 $defaults->text = clean_text($submission->data1); 00471 } else { 00472 $defaults->text = ''; 00473 } 00474 00475 $mform->set_data($defaults); 00476 00477 if ($mform->is_cancelled()) { 00478 $returnurl = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id)); 00479 redirect($returnurl); 00480 } 00481 00482 if (!$this->can_update_notes($submission)) { 00483 $this->view_header(get_string('upload')); 00484 echo $OUTPUT->notification(get_string('uploaderror', 'assignment')); 00485 echo $OUTPUT->continue_button($returnurl); 00486 $this->view_footer(); 00487 die; 00488 } 00489 00490 if ($data = $mform->get_data() and $action == 'savenotes') { 00491 $submission = $this->get_submission($USER->id, true); // get or create submission 00492 $updated = new stdClass(); 00493 $updated->id = $submission->id; 00494 $updated->timemodified = time(); 00495 $updated->data1 = $data->text; 00496 00497 $DB->update_record('assignment_submissions', $updated); 00498 add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); 00499 redirect($returnurl); 00500 $submission = $this->get_submission($USER->id); 00501 $this->update_grade($submission); 00502 } 00503 00505 $this->view_header(get_string('notes', 'assignment')); 00506 00507 echo $OUTPUT->heading(get_string('notes', 'assignment')); 00508 00509 $mform->display(); 00510 00511 $this->view_footer(); 00512 die; 00513 } 00514 00515 function upload_responsefile($mform, $options) { 00516 global $CFG, $USER, $OUTPUT, $PAGE; 00517 00518 $userid = required_param('userid', PARAM_INT); 00519 $mode = required_param('mode', PARAM_ALPHA); 00520 $offset = required_param('offset', PARAM_INT); 00521 00522 $returnurl = new moodle_url("submissions.php", array('id'=>$this->cm->id,'userid'=>$userid,'mode'=>$mode,'offset'=>$offset)); //not xhtml, just url. 00523 00524 if ($formdata = $mform->get_data() and $this->can_manage_responsefiles()) { 00525 $fs = get_file_storage(); 00526 $submission = $this->get_submission($userid, true, true); 00527 if ($formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $this->context, 'mod_assignment', 'response', $submission->id)) { 00528 $returnurl = new moodle_url("/mod/assignment/submissions.php", array('id'=>$this->cm->id,'userid'=>$formdata->userid,'mode'=>$formdata->mode,'offset'=>$formdata->offset)); 00529 redirect($returnurl->out(false)); 00530 } 00531 } 00532 $PAGE->set_title(get_string('upload')); 00533 echo $OUTPUT->header(); 00534 echo $OUTPUT->notification(get_string('uploaderror', 'assignment')); 00535 echo $OUTPUT->continue_button($returnurl->out(true)); 00536 echo $OUTPUT->footer(); 00537 die; 00538 } 00539 00540 function upload_file($mform, $options) { 00541 global $CFG, $USER, $DB, $OUTPUT; 00542 00543 $returnurl = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id)); 00544 $submission = $this->get_submission($USER->id); 00545 00546 if (!$this->can_upload_file($submission)) { 00547 $this->view_header(get_string('upload')); 00548 echo $OUTPUT->notification(get_string('uploaderror', 'assignment')); 00549 echo $OUTPUT->continue_button($returnurl); 00550 $this->view_footer(); 00551 die; 00552 } 00553 00554 if ($formdata = $mform->get_data()) { 00555 $fs = get_file_storage(); 00556 $submission = $this->get_submission($USER->id, true); //create new submission if needed 00557 $fs->delete_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id); 00558 $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $this->context, 'mod_assignment', 'submission', $submission->id); 00559 $updates = new stdClass(); 00560 $updates->id = $submission->id; 00561 $updates->timemodified = time(); 00562 $DB->update_record('assignment_submissions', $updates); 00563 add_to_log($this->course->id, 'assignment', 'upload', 00564 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); 00565 $this->update_grade($submission); 00566 if (!$this->drafts_tracked()) { 00567 $this->email_teachers($submission); 00568 } 00569 00570 // send files to event system 00571 $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id); 00572 // Let Moodle know that assessable files were uploaded (eg for plagiarism detection) 00573 $eventdata = new stdClass(); 00574 $eventdata->modulename = 'assignment'; 00575 $eventdata->cmid = $this->cm->id; 00576 $eventdata->itemid = $submission->id; 00577 $eventdata->courseid = $this->course->id; 00578 $eventdata->userid = $USER->id; 00579 if ($files) { 00580 $eventdata->files = $files; 00581 } 00582 events_trigger('assessable_file_uploaded', $eventdata); 00583 $returnurl = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id)); 00584 redirect($returnurl); 00585 } 00586 00587 $this->view_header(get_string('upload')); 00588 echo $OUTPUT->notification(get_string('uploaderror', 'assignment')); 00589 echo $OUTPUT->continue_button($returnurl); 00590 $this->view_footer(); 00591 die; 00592 } 00593 00594 function send_file($filearea, $args) { 00595 global $CFG, $DB, $USER; 00596 require_once($CFG->libdir.'/filelib.php'); 00597 00598 require_login($this->course, false, $this->cm); 00599 00600 if ($filearea === 'submission') { 00601 $submissionid = (int)array_shift($args); 00602 00603 if (!$submission = $DB->get_record('assignment_submissions', array('assignment'=>$this->assignment->id, 'id'=>$submissionid))) { 00604 return false; 00605 } 00606 00607 if ($USER->id != $submission->userid and !has_capability('mod/assignment:grade', $this->context)) { 00608 return false; 00609 } 00610 00611 $relativepath = implode('/', $args); 00612 $fullpath = "/{$this->context->id}/mod_assignment/submission/$submission->id/$relativepath"; 00613 00614 $fs = get_file_storage(); 00615 if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { 00616 return false; 00617 } 00618 send_stored_file($file, 0, 0, true); // download MUST be forced - security! 00619 00620 } else if ($filearea === 'response') { 00621 $submissionid = (int)array_shift($args); 00622 00623 if (!$submission = $DB->get_record('assignment_submissions', array('assignment'=>$this->assignment->id, 'id'=>$submissionid))) { 00624 return false; 00625 } 00626 00627 if ($USER->id != $submission->userid and !has_capability('mod/assignment:grade', $this->context)) { 00628 return false; 00629 } 00630 00631 $relativepath = implode('/', $args); 00632 $fullpath = "/{$this->context->id}/mod_assignment/response/$submission->id/$relativepath"; 00633 00634 $fs = get_file_storage(); 00635 if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { 00636 return false; 00637 } 00638 send_stored_file($file, 0, 0, true); 00639 } 00640 00641 return false; 00642 } 00643 00644 function finalize($forcemode=null) { 00645 global $USER, $DB, $OUTPUT; 00646 $userid = optional_param('userid', $USER->id, PARAM_INT); 00647 $offset = optional_param('offset', 0, PARAM_INT); 00648 $confirm = optional_param('confirm', 0, PARAM_BOOL); 00649 $returnurl = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id)); 00650 $submission = $this->get_submission($userid); 00651 00652 if ($forcemode!=null) { 00653 $returnurl = new moodle_url('/mod/assignment/submissions.php', 00654 array('id'=>$this->cm->id, 00655 'userid'=>$userid, 00656 'mode'=>$forcemode, 00657 'offset'=>$offset 00658 )); 00659 } 00660 00661 if (!$this->can_finalize($submission)) { 00662 redirect($returnurl->out(false)); // probably already graded, redirect to assignment page, the reason should be obvious 00663 } 00664 00665 if ($forcemode==null) { 00666 if (!data_submitted() or !$confirm or !confirm_sesskey()) { 00667 $optionsno = array('id'=>$this->cm->id); 00668 $optionsyes = array ('id'=>$this->cm->id, 'confirm'=>1, 'action'=>'finalize', 'sesskey'=>sesskey()); 00669 $this->view_header(get_string('submitformarking', 'assignment')); 00670 echo $OUTPUT->heading(get_string('submitformarking', 'assignment')); 00671 echo $OUTPUT->confirm(get_string('onceassignmentsent', 'assignment'), new moodle_url('upload.php', $optionsyes),new moodle_url( 'view.php', $optionsno)); 00672 $this->view_footer(); 00673 die; 00674 } 00675 } 00676 $updated = new stdClass(); 00677 $updated->id = $submission->id; 00678 $updated->data2 = ASSIGNMENT_STATUS_SUBMITTED; 00679 $updated->timemodified = time(); 00680 00681 $DB->update_record('assignment_submissions', $updated); 00682 add_to_log($this->course->id, 'assignment', 'upload', //TODO: add finalize action to log 00683 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); 00684 $submission = $this->get_submission($userid); 00685 $this->update_grade($submission); 00686 $this->email_teachers($submission); 00687 00688 // Trigger assessable_files_done event to show files are complete 00689 $eventdata = new stdClass(); 00690 $eventdata->modulename = 'assignment'; 00691 $eventdata->cmid = $this->cm->id; 00692 $eventdata->itemid = $submission->id; 00693 $eventdata->courseid = $this->course->id; 00694 $eventdata->userid = $userid; 00695 events_trigger('assessable_files_done', $eventdata); 00696 00697 if ($forcemode==null) { 00698 redirect($returnurl->out(false)); 00699 } 00700 } 00701 00702 function finalizeclose() { 00703 global $DB; 00704 00705 $userid = optional_param('userid', 0, PARAM_INT); 00706 $mode = required_param('mode', PARAM_ALPHA); 00707 $offset = required_param('offset', PARAM_INT); 00708 $returnurl = new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id, 'userid'=>$userid, 'mode'=>$mode, 'offset'=>$offset, 'forcerefresh'=>1)); 00709 00710 // create but do not add student submission date 00711 $submission = $this->get_submission($userid, true, true); 00712 00713 if (!data_submitted() or !$this->can_finalize($submission) or !confirm_sesskey()) { 00714 redirect($returnurl); // probably closed already 00715 } 00716 00717 $updated = new stdClass(); 00718 $updated->id = $submission->id; 00719 $updated->data2 = ASSIGNMENT_STATUS_CLOSED; 00720 00721 $DB->update_record('assignment_submissions', $updated); 00722 add_to_log($this->course->id, 'assignment', 'upload', //TODO: add finalize action to log 00723 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); 00724 $submission = $this->get_submission($userid, false, true); 00725 $this->update_grade($submission); 00726 redirect($returnurl); 00727 } 00728 00729 function unfinalize($forcemode=null) { 00730 global $DB; 00731 00732 $userid = required_param('userid', PARAM_INT); 00733 $mode = required_param('mode', PARAM_ALPHA); 00734 $offset = required_param('offset', PARAM_INT); 00735 00736 if ($forcemode!=null) { 00737 $mode=$forcemode; 00738 } 00739 $returnurl = new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id, 'userid'=>$userid, 'mode'=>$mode, 'offset'=>$offset, 'forcerefresh'=>1) ); 00740 if (data_submitted() 00741 and $submission = $this->get_submission($userid) 00742 and $this->can_unfinalize($submission) 00743 and confirm_sesskey()) { 00744 00745 $updated = new stdClass(); 00746 $updated->id = $submission->id; 00747 $updated->data2 = ''; 00748 $DB->update_record('assignment_submissions', $updated); 00749 //TODO: add unfinalize action to log 00750 add_to_log($this->course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->cm->id.'&userid='.$userid.'&mode='.$mode.'&offset='.$offset, $this->assignment->id, $this->cm->id); 00751 $submission = $this->get_submission($userid); 00752 $this->update_grade($submission); 00753 } 00754 00755 if ($forcemode==null) { 00756 redirect($returnurl); 00757 } 00758 } 00759 00760 00761 function delete() { 00762 $action = optional_param('action', '', PARAM_ALPHA); 00763 00764 switch ($action) { 00765 case 'response': 00766 $this->delete_responsefile(); 00767 break; 00768 default: 00769 $this->delete_file(); 00770 } 00771 die; 00772 } 00773 00774 00775 function delete_responsefile() { 00776 global $CFG, $OUTPUT,$PAGE; 00777 00778 $file = required_param('file', PARAM_FILE); 00779 $userid = required_param('userid', PARAM_INT); 00780 $mode = required_param('mode', PARAM_ALPHA); 00781 $offset = required_param('offset', PARAM_INT); 00782 $confirm = optional_param('confirm', 0, PARAM_BOOL); 00783 00784 $returnurl = new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id, 'userid'=>$userid, 'mode'=>$mode, 'offset'=>$offset)); 00785 00786 if (!$this->can_manage_responsefiles()) { 00787 redirect($returnurl); 00788 } 00789 00790 $urlreturn = 'submissions.php'; 00791 $optionsreturn = array('id'=>$this->cm->id, 'offset'=>$offset, 'mode'=>$mode, 'userid'=>$userid); 00792 00793 if (!data_submitted() or !$confirm or !confirm_sesskey()) { 00794 $optionsyes = array ('id'=>$this->cm->id, 'file'=>$file, 'userid'=>$userid, 'confirm'=>1, 'action'=>'response', 'mode'=>$mode, 'offset'=>$offset, 'sesskey'=>sesskey()); 00795 $PAGE->set_title(get_string('delete')); 00796 echo $OUTPUT->header(); 00797 echo $OUTPUT->heading(get_string('delete')); 00798 echo $OUTPUT->confirm(get_string('confirmdeletefile', 'assignment', $file), new moodle_url('delete.php', $optionsyes), new moodle_url($urlreturn, $optionsreturn)); 00799 echo $OUTPUT->footer(); 00800 die; 00801 } 00802 00803 if ($submission = $this->get_submission($userid)) { 00804 $fs = get_file_storage(); 00805 if ($file = $fs->get_file($this->context->id, 'mod_assignment', 'response', $submission->id, '/', $file)) { 00806 $file->delete(); 00807 } 00808 } 00809 redirect($returnurl); 00810 } 00811 00812 00813 function delete_file() { 00814 global $CFG, $DB, $OUTPUT, $PAGE; 00815 00816 $file = required_param('file', PARAM_FILE); 00817 $userid = required_param('userid', PARAM_INT); 00818 $confirm = optional_param('confirm', 0, PARAM_BOOL); 00819 $mode = optional_param('mode', '', PARAM_ALPHA); 00820 $offset = optional_param('offset', 0, PARAM_INT); 00821 00822 require_login($this->course->id, false, $this->cm); 00823 00824 if (empty($mode)) { 00825 $urlreturn = 'view.php'; 00826 $optionsreturn = array('id'=>$this->cm->id); 00827 $returnurl = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id)); 00828 } else { 00829 $urlreturn = 'submissions.php'; 00830 $optionsreturn = array('id'=>$this->cm->id, 'offset'=>$offset, 'mode'=>$mode, 'userid'=>$userid); 00831 $returnurl = new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id, 'offset'=>$offset, 'userid'=>$userid)); 00832 } 00833 00834 if (!$submission = $this->get_submission($userid) // incorrect submission 00835 or !$this->can_delete_files($submission)) { // can not delete 00836 $this->view_header(get_string('delete')); 00837 echo $OUTPUT->notification(get_string('cannotdeletefiles', 'assignment')); 00838 echo $OUTPUT->continue_button($returnurl); 00839 $this->view_footer(); 00840 die; 00841 } 00842 00843 if (!data_submitted() or !$confirm or !confirm_sesskey()) { 00844 $optionsyes = array ('id'=>$this->cm->id, 'file'=>$file, 'userid'=>$userid, 'confirm'=>1, 'sesskey'=>sesskey(), 'mode'=>$mode, 'offset'=>$offset, 'sesskey'=>sesskey()); 00845 if (empty($mode)) { 00846 $this->view_header(get_string('delete')); 00847 } else { 00848 $PAGE->set_title(get_string('delete')); 00849 echo $OUTPUT->header(); 00850 } 00851 echo $OUTPUT->heading(get_string('delete')); 00852 echo $OUTPUT->confirm(get_string('confirmdeletefile', 'assignment', $file), new moodle_url('delete.php', $optionsyes), new moodle_url($urlreturn, $optionsreturn)); 00853 if (empty($mode)) { 00854 $this->view_footer(); 00855 } else { 00856 echo $OUTPUT->footer(); 00857 } 00858 die; 00859 } 00860 00861 $fs = get_file_storage(); 00862 if ($file = $fs->get_file($this->context->id, 'mod_assignment', 'submission', $submission->id, '/', $file)) { 00863 $file->delete(); 00864 $submission->timemodified = time(); 00865 $DB->update_record('assignment_submissions', $submission); 00866 add_to_log($this->course->id, 'assignment', 'upload', //TODO: add delete action to log 00867 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); 00868 $this->update_grade($submission); 00869 } 00870 redirect($returnurl); 00871 } 00872 00873 00874 function can_upload_file($submission) { 00875 global $USER; 00876 00877 if (is_enrolled($this->context, $USER, 'mod/assignment:submit') 00878 and $this->isopen() // assignment not closed yet 00879 and (empty($submission) or ($submission->userid == $USER->id)) // his/her own submission 00880 and !$this->is_finalized($submission)) { // no uploading after final submission 00881 return true; 00882 } else { 00883 return false; 00884 } 00885 } 00886 00887 function can_manage_responsefiles() { 00888 if (has_capability('mod/assignment:grade', $this->context)) { 00889 return true; 00890 } else { 00891 return false; 00892 } 00893 } 00894 00895 function can_delete_files($submission) { 00896 global $USER; 00897 00898 if (has_capability('mod/assignment:grade', $this->context)) { 00899 return true; 00900 } 00901 00902 if (is_enrolled($this->context, $USER, 'mod/assignment:submit') 00903 and $this->isopen() // assignment not closed yet 00904 and $this->assignment->resubmit // deleting allowed 00905 and $USER->id == $submission->userid // his/her own submission 00906 and !$this->is_finalized($submission)) { // no deleting after final submission 00907 return true; 00908 } else { 00909 return false; 00910 } 00911 } 00912 00913 function drafts_tracked() { 00914 return !empty($this->assignment->var4); 00915 } 00916 00922 function is_finalized($submission) { 00923 if (!$this->drafts_tracked()) { 00924 return ''; 00925 00926 } else if (empty($submission)) { 00927 return ''; 00928 00929 } else if ($submission->data2 == ASSIGNMENT_STATUS_SUBMITTED or $submission->data2 == ASSIGNMENT_STATUS_CLOSED) { 00930 return $submission->data2; 00931 00932 } else { 00933 return ''; 00934 } 00935 } 00936 00937 function can_unfinalize($submission) { 00938 if(is_bool($submission)) { 00939 return false; 00940 } 00941 00942 if (!$this->drafts_tracked()) { 00943 return false; 00944 } 00945 00946 if (has_capability('mod/assignment:grade', $this->context) 00947 and $this->isopen() 00948 and $this->is_finalized($submission)) { 00949 return true; 00950 } else { 00951 return false; 00952 } 00953 } 00954 00955 function can_finalize($submission) { 00956 global $USER; 00957 00958 if(is_bool($submission)) { 00959 return false; 00960 } 00961 00962 if (!$this->drafts_tracked()) { 00963 return false; 00964 } 00965 00966 if ($this->is_finalized($submission)) { 00967 return false; 00968 } 00969 00970 if (has_capability('mod/assignment:grade', $this->context)) { 00971 return true; 00972 00973 } else if (is_enrolled($this->context, $USER, 'mod/assignment:submit') 00974 and $this->isopen() // assignment not closed yet 00975 and !empty($submission) // submission must exist 00976 and $submission->userid == $USER->id // his/her own submission 00977 and ($this->count_user_files($submission->id) 00978 or ($this->notes_allowed() and !empty($submission->data1)))) { // something must be submitted 00979 00980 return true; 00981 } else { 00982 return false; 00983 } 00984 } 00985 00986 function can_update_notes($submission) { 00987 global $USER; 00988 00989 if (is_enrolled($this->context, $USER, 'mod/assignment:submit') 00990 and $this->notes_allowed() // notesd must be allowed 00991 and $this->isopen() // assignment not closed yet 00992 and (empty($submission) or $USER->id == $submission->userid) // his/her own submission 00993 and !$this->is_finalized($submission)) { // no updateingafter final submission 00994 return true; 00995 } else { 00996 return false; 00997 } 00998 } 00999 01000 function notes_allowed() { 01001 return (boolean)$this->assignment->var2; 01002 } 01003 01004 function count_responsefiles($userid) { 01005 if ($submission = $this->get_submission($userid)) { 01006 $fs = get_file_storage(); 01007 $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'response', $submission->id, "id", false); 01008 return count($files); 01009 } else { 01010 return 0; 01011 } 01012 } 01013 01014 function setup_elements(&$mform) { 01015 global $CFG, $COURSE; 01016 01017 $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes')); 01018 01019 $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes); 01020 $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')'; 01021 $mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $choices); 01022 $mform->setDefault('maxbytes', $CFG->assignment_maxbytes); 01023 01024 $mform->addElement('select', 'resubmit', get_string('allowdeleting', 'assignment'), $ynoptions); 01025 $mform->addHelpButton('resubmit', 'allowdeleting', 'assignment'); 01026 $mform->setDefault('resubmit', 1); 01027 01028 $options = array(); 01029 for($i = 1; $i <= 20; $i++) { 01030 $options[$i] = $i; 01031 } 01032 $mform->addElement('select', 'var1', get_string('allowmaxfiles', 'assignment'), $options); 01033 $mform->addHelpButton('var1', 'allowmaxfiles', 'assignment'); 01034 $mform->setDefault('var1', 3); 01035 01036 $mform->addElement('select', 'var2', get_string('allownotes', 'assignment'), $ynoptions); 01037 $mform->addHelpButton('var2', 'allownotes', 'assignment'); 01038 $mform->setDefault('var2', 0); 01039 01040 $mform->addElement('select', 'var3', get_string('hideintro', 'assignment'), $ynoptions); 01041 $mform->addHelpButton('var3', 'hideintro', 'assignment'); 01042 $mform->setDefault('var3', 0); 01043 01044 $mform->addElement('select', 'emailteachers', get_string('emailteachers', 'assignment'), $ynoptions); 01045 $mform->addHelpButton('emailteachers', 'emailteachers', 'assignment'); 01046 $mform->setDefault('emailteachers', 0); 01047 01048 $mform->addElement('select', 'var4', get_string('trackdrafts', 'assignment'), $ynoptions); 01049 $mform->addHelpButton('var4', 'trackdrafts', 'assignment'); 01050 $mform->setDefault('var4', 1); 01051 01052 $course_context = get_context_instance(CONTEXT_COURSE, $COURSE->id); 01053 plagiarism_get_form_elements_module($mform, $course_context); 01054 } 01055 01056 function portfolio_exportable() { 01057 return true; 01058 } 01059 01060 function extend_settings_navigation($node) { 01061 global $CFG, $USER, $OUTPUT; 01062 01063 // get users submission if there is one 01064 $submission = $this->get_submission(); 01065 if (is_enrolled($this->context, $USER, 'mod/assignment:submit')) { 01066 $editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked); 01067 } else { 01068 $editable = false; 01069 } 01070 01071 // If the user has submitted something add some related links and data 01072 if (isset($submission->data2) AND $submission->data2 == 'submitted') { 01073 // Add a view link to the settings nav 01074 $link = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id)); 01075 $node->add(get_string('viewmysubmission', 'assignment'), $link, navigation_node::TYPE_SETTING); 01076 if (!empty($submission->timemodified)) { 01077 $submittednode = $node->add(get_string('submitted', 'assignment') . ' ' . userdate($submission->timemodified)); 01078 $submittednode->text = preg_replace('#([^,])\s#', '$1 ', $submittednode->text); 01079 $submittednode->add_class('note'); 01080 if ($submission->timemodified <= $this->assignment->timedue || empty($this->assignment->timedue)) { 01081 $submittednode->add_class('early'); 01082 } else { 01083 $submittednode->add_class('late'); 01084 } 01085 } 01086 } 01087 01088 // Check if the user has uploaded any files, if so we can add some more stuff to the settings nav 01089 if ($submission && is_enrolled($this->context, $USER, 'mod/assignment:submit') && $this->count_user_files($submission->id)) { 01090 $fs = get_file_storage(); 01091 if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) { 01092 if (!$this->drafts_tracked() or !$this->isopen() or $this->is_finalized($submission)) { 01093 $filenode = $node->add(get_string('submission', 'assignment')); 01094 } else { 01095 $filenode = $node->add(get_string('submissiondraft', 'assignment')); 01096 } 01097 foreach ($files as $file) { 01098 $filename = $file->get_filename(); 01099 $mimetype = $file->get_mimetype(); 01100 $link = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename); 01101 $filenode->add($filename, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon(file_mimetype_icon($mimetype),'')); 01102 } 01103 } 01104 } 01105 01106 // Show a notes link if they are enabled 01107 if ($this->notes_allowed()) { 01108 $link = new moodle_url('/mod/assignment/upload.php', array('id'=>$this->cm->id, 'action'=>'editnotes', 'sesskey'=>sesskey())); 01109 $node->add(get_string('notes', 'assignment'), $link); 01110 } 01111 } 01112 01116 public function download_submissions() { 01117 global $CFG,$DB; 01118 require_once($CFG->libdir.'/filelib.php'); 01119 $submissions = $this->get_submissions('',''); 01120 if (empty($submissions)) { 01121 print_error('errornosubmissions', 'assignment'); 01122 } 01123 $filesforzipping = array(); 01124 $fs = get_file_storage(); 01125 01126 $groupmode = groups_get_activity_groupmode($this->cm); 01127 $groupid = 0; // All users 01128 $groupname = ''; 01129 if ($groupmode) { 01130 $groupid = groups_get_activity_group($this->cm, true); 01131 $groupname = groups_get_group_name($groupid).'-'; 01132 } 01133 $filename = str_replace(' ', '_', clean_filename($this->course->shortname.'-'.$this->assignment->name.'-'.$groupname.$this->assignment->id.".zip")); //name of new zip file. 01134 foreach ($submissions as $submission) { 01135 $a_userid = $submission->userid; //get userid 01136 if ((groups_is_member($groupid,$a_userid)or !$groupmode or !$groupid)) { 01137 $a_assignid = $submission->assignment; //get name of this assignment for use in the file names. 01138 $a_user = $DB->get_record("user", array("id"=>$a_userid),'id,username,firstname,lastname'); //get user firstname/lastname 01139 01140 $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false); 01141 foreach ($files as $file) { 01142 //get files new name. 01143 $fileext = strstr($file->get_filename(), '.'); 01144 $fileoriginal = str_replace($fileext, '', $file->get_filename()); 01145 $fileforzipname = clean_filename(fullname($a_user) . "_" . $fileoriginal."_".$a_userid.$fileext); 01146 //save file name to array for zipping. 01147 $filesforzipping[$fileforzipname] = $file; 01148 } 01149 } 01150 } // end of foreach loop 01151 if ($zipfile = assignment_pack_files($filesforzipping)) { 01152 send_temp_file($zipfile, $filename); //send file and delete after sending. 01153 } 01154 } 01155 01164 public function is_submitted_with_required_data($submission) { 01165 return ($submission->timemodified AND $submission->data2); 01166 } 01167 } 01168 01169 class mod_assignment_upload_notes_form extends moodleform { 01170 01171 function get_data() { 01172 $data = parent::get_data(); 01173 if ($data) { 01174 $data->format = $data->text['format']; 01175 $data->text = $data->text['text']; 01176 } 01177 return $data; 01178 } 01179 01180 function set_data($data) { 01181 if (!isset($data->format)) { 01182 $data->format = FORMAT_HTML; 01183 } 01184 if (isset($data->text)) { 01185 $data->text = array('text'=>$data->text, 'format'=>$data->format); 01186 } 01187 parent::set_data($data); 01188 } 01189 01190 function definition() { 01191 $mform = $this->_form; 01192 01193 // visible elements 01194 $mform->addElement('editor', 'text', get_string('notes', 'assignment'), null, null); 01195 $mform->setType('text', PARAM_RAW); // to be cleaned before display 01196 01197 // hidden params 01198 $mform->addElement('hidden', 'id', 0); 01199 $mform->setType('id', PARAM_INT); 01200 $mform->addElement('hidden', 'action', 'savenotes'); 01201 $mform->setType('action', PARAM_ALPHA); 01202 01203 // buttons 01204 $this->add_action_buttons(); 01205 } 01206 } 01207 01208 class mod_assignment_upload_response_form extends moodleform { 01209 function definition() { 01210 $mform = $this->_form; 01211 $instance = $this->_customdata; 01212 01213 // visible elements 01214 $mform->addElement('filemanager', 'files_filemanager', get_string('uploadafile'), null, $instance->options); 01215 01216 // hidden params 01217 $mform->addElement('hidden', 'id', $instance->cm->id); 01218 $mform->setType('id', PARAM_INT); 01219 $mform->addElement('hidden', 'contextid', $instance->contextid); 01220 $mform->setType('contextid', PARAM_INT); 01221 $mform->addElement('hidden', 'action', 'uploadresponse'); 01222 $mform->setType('action', PARAM_ALPHA); 01223 $mform->addElement('hidden', 'mode', $instance->mode); 01224 $mform->setType('mode', PARAM_ALPHA); 01225 $mform->addElement('hidden', 'offset', $instance->offset); 01226 $mform->setType('offset', PARAM_INT); 01227 $mform->addElement('hidden', 'forcerefresh' , $instance->forcerefresh); 01228 $mform->setType('forcerefresh', PARAM_INT); 01229 $mform->addElement('hidden', 'userid', $instance->userid); 01230 $mform->setType('userid', PARAM_INT); 01231 01232 // buttons 01233 $this->add_action_buttons(false, get_string('uploadthisfile')); 01234 } 01235 } 01236 01237 01238 01239