From 55b4d096372a8a748925d63cb8df21aae9ee0a90 Mon Sep 17 00:00:00 2001 From: skodak Date: Sat, 30 Sep 2006 15:41:20 +0000 Subject: [PATCH] new advanced upload assignmet type - replaces old upload type, existing data and settings not fully compatible --- lang/en_utf8/assignment.php | 52 +- mod/assignment/db/access.php | 8 +- mod/assignment/delete.php | 42 + mod/assignment/lib.php | 26 +- mod/assignment/type/upload/README.txt | 46 - .../type/upload/assignment.class.php | 1904 ++++++----------- mod/assignment/type/upload/mod.html | 65 +- mod/assignment/type/upload/notes.php | 65 + mod/assignment/version.php | 2 +- 9 files changed, 858 insertions(+), 1352 deletions(-) create mode 100644 mod/assignment/delete.php delete mode 100644 mod/assignment/type/upload/README.txt create mode 100644 mod/assignment/type/upload/notes.php diff --git a/lang/en_utf8/assignment.php b/lang/en_utf8/assignment.php index 243afd2ac6..fec4bb6fb4 100644 --- a/lang/en_utf8/assignment.php +++ b/lang/en_utf8/assignment.php @@ -2,6 +2,9 @@ // assignment.php - created with Moodle 1.2 + (2004032100) +$string['allowdeleting'] = 'Allow deleting'; +$string['allowmaxfiles'] = 'Maximum number of uploaded files'; +$string['allownotes'] = 'Allow notes'; $string['allowresubmit'] = 'Allow resubmitting'; $string['assignment:view'] = 'View assignment'; $string['assignment:grade'] = 'Grade assignment'; @@ -19,20 +22,14 @@ You can see it appended to your url\">assignment submission.'; $string['assignmentname'] = 'Assignment name'; $string['assignmenttype'] = 'Assignment type'; $string['availabledate'] = 'Available from'; -$string['allowmultiple'] = 'Allow multiple files'; -$string['attachfile'] = 'Attach file'; -$string['attachfiletoassignment'] = 'Attach file(s) to assignment'; -$string['backtoassignment'] = 'Back to Assignment'; -$string['backtofeedback'] = 'Back to Feedback'; -$string['choosereviewfile'] = 'Choose a file to upload as an assignment review:'; $string['comment'] = 'Comment'; $string['commentinline'] = 'Comment inline'; $string['configitemstocount'] = 'Nature of items to be counted for student submissions in online assignments.'; $string['configmaxbytes'] = 'Default maximum assignment size for all assignments on the site (subject to course limits and other local settings)'; -$string['deletecheckfile'] = 'Are you absolutely sure you want to delete this file?'; -$string['deleteednotification'] = 'File has been deleted.'; -$string['deletefail'] = 'The following file has not been deleted:'; +$string['confirmdeletefile'] = 'Are you absolutely sure you want to delete this file?
$a'; +$string['deletefilefailed'] = 'Deleting of file failed.'; $string['description'] = 'Description'; +$string['draft'] = 'Draft'; $string['duedate'] = 'Due date'; $string['duedateno'] = 'No due date'; $string['early'] = '$a early'; @@ -66,23 +63,29 @@ $string['helponline'] = '

This assignment type asks users to edit a text, usin editing tools. Teachers can grade them online, and even add inline comments or changes.

(If you are familiar with older versions of Moodle, this Assignment type does the same thing as the old Journal module used to do.)

'; -$string['helpupload'] = '

This type of assignment allows each participant to upload one or several files, of any type.

-

These might be a Word processor documents, images, a zipped web site, or anything you ask them to submit.

-

This type also allows you to upload multiple response files of any type.

'; +$string['helpupload'] = '

This type of assignment allows each participant to upload one or more files in any format. + These might be a Word processor documents, images, a zipped web site, or anything you ask them to submit.

+

This type also allows you to upload multiple response files. Response files can be also uploaded before submission which + can be used to give each participant different file to work with.

+

Participants may also enter notes describing the submitted files, progress status or any other text information.

+

Submission of this type of assignment must be manually finalized by the participant. You can review the current status + at any time, unfinished assignments are marked af Draft. You can revert any ungraded assignment back to draft status.

'; $string['helpuploadsingle'] = '

This type of assignment allows each participant to upload a single file, of any type.

This might be a Word processor document, an image, a zipped web site, or anything you ask them to submit.

'; $string['late'] = '$a late'; -$string['markingsubmitnotification'] = 'File has been submitted for marking successfully.'; $string['maximumgrade'] = 'Maximum grade'; $string['maximumsize'] = 'Maximum size'; $string['modulename'] = 'Assignment'; $string['modulenameplural'] = 'Assignments'; -$string['namedeletefile'] = 'You about to delete this file:'; $string['newsubmissions'] = 'Assignments submitted'; $string['noassignments'] = 'There are no assignments yet'; $string['noattempts'] = 'No attempts have been made on this assignment'; -$string['nofilesforsubmit'] = 'No file was found for submitting - are you sure you uploaded any?'; +$string['nofilesyet'] = 'No files submitted yet'; +$string['nofiles'] = 'No files were submitted'; +$string['notes'] = 'Notes'; +$string['notesempty'] = 'No entry'; +$string['notesupdateerror'] = 'Error when updating notes'; $string['notgradedyet'] = 'Not graded yet'; $string['notsubmittedyet'] = 'Not submitted yet'; $string['onceassignmentsent'] = 'Once the assignment is sent for marking, you will no longer be able to delete or attach file(s).'; @@ -90,31 +93,25 @@ $string['overwritewarning'] = 'Warning: uploading again will REPLACE your curren $string['pagesize'] = 'Submissions shown per page'; $string['preventlate'] = 'Prevent late submissions'; $string['quickgrade'] = 'Allow quick grading'; -$string['removelink'] = 'Remove'; -$string['responsefile'] = 'Response File:'; -$string['responsesfromteacher'] = 'Responses Uploaded by the Teacher'; +$string['responsefiles'] = 'Response files'; $string['saveallfeedback'] = 'Save all my feedback'; $string['sendformarking'] = 'Send for marking'; -$string['step1'] = 'Step 1: '; -$string['step2'] = 'Step 2: '; -$string['submissionstatusblank'] = 'Blank'; -$string['submissionstatusdraft'] = 'Draft'; -$string['submissionstatusmarked'] = 'Marked'; -$string['submissionstatusreturned'] = 'Returned'; -$string['submissionstatus'] = 'Submission status:'; -$string['submissionstatussubmitted'] = 'Submitted'; $string['submission'] = 'Submission'; +$string['submissiondraft'] = 'Submission draft'; $string['submissionfeedback'] = 'Submission feedback'; $string['submissions'] = 'Submissions'; $string['submissionsaved'] = 'Your changes have been saved'; $string['submissionsnotgraded'] = '$a submissions not graded'; $string['submitassignment'] = 'Submit your assignment using this form'; -$string['submitformarking'] = 'Submit assignment for marking'; +$string['submitedformarking'] = 'Assignment was already submitted for marking and can not be updated'; +$string['submitformarking'] = 'Final submission for assignment marking'; $string['submitted'] = 'Submitted'; +$string['submittedfiles'] = 'Submitted files'; $string['typeoffline'] = 'Offline activity'; $string['typeonline'] = 'Online text'; $string['typeupload'] = 'Advanced uploading of files'; $string['typeuploadsingle'] = 'Upload a single file'; +$string['unfinalize'] = 'Revert to draft'; $string['uploadbadname'] = 'This filename contained strange characters and couldn\'t be uploaded'; $string['uploadedfiles'] = 'uploaded files'; $string['uploaderror'] = 'An error happened while saving the file on the server'; @@ -123,7 +120,6 @@ $string['uploadfiletoobig'] = 'Sorry, but that file is too big (limit is $a byte $string['uploadnofilefound'] = 'No file was found - are you sure you selected one to upload?'; $string['uploadnotregistered'] = '\'$a\' was uploaded OK but submission did not register!'; $string['uploadsuccess'] = 'Uploaded \'$a\' successfully'; -$string['uploadsuccessresponse'] = 'Response file uploaded successfully.'; $string['viewfeedback'] = 'View assignment grades and feedback'; $string['viewsubmissions'] = 'View $a submitted assignments'; $string['yoursubmission'] = 'Your submission'; diff --git a/mod/assignment/db/access.php b/mod/assignment/db/access.php index ef2185253b..06305f1f64 100644 --- a/mod/assignment/db/access.php +++ b/mod/assignment/db/access.php @@ -54,10 +54,10 @@ $mod_assignment_capabilities = array( 'legacy' => array( 'guest' => CAP_PREVENT, 'student' => CAP_ALLOW, - 'teacher' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW, - 'coursecreator' => CAP_ALLOW, - 'admin' => CAP_ALLOW + 'teacher' => CAP_INHERIT, + 'editingteacher' => CAP_INHERIT, + 'coursecreator' => CAP_INHERIT, + 'admin' => CAP_INHERIT ) ), diff --git a/mod/assignment/delete.php b/mod/assignment/delete.php new file mode 100644 index 0000000000..402727b8d1 --- /dev/null +++ b/mod/assignment/delete.php @@ -0,0 +1,42 @@ +instance)) { + error("assignment ID was incorrect"); + } + + if (! $course = get_record('course', 'id', $assignment->course)) { + error("Course is misconfigured"); + } + } else { + if (!$assignment = get_record('assignment', 'id', $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record('course', 'id', $assignment->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance('assignment', $assignment->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } + + require_login($course->id, false, $cm); + +/// Load up the required assignment code + require($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php'); + $assignmentclass = 'assignment_'.$assignment->assignmenttype; + $assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm, $course); + + $assignmentinstance->delete(); // delete something + +?> diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index d3d0289bdf..d1489bf9ab 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -32,6 +32,7 @@ class assignment_base { var $currentgroup; var $usehtmleditor; var $defaultformat; + var $context; /** * Constructor for the base assignment class @@ -57,6 +58,8 @@ class assignment_base { error('Course Module ID was incorrect'); } + $this->context = get_context_instance(CONTEXT_MODULE,$this->cm->id); + if ($course) { $this->course = $course; } else if (! $this->course = get_record('course', 'id', $this->cm->course)) { @@ -922,6 +925,12 @@ class assignment_base { } echo ''; echo ''; + + $customfeedback = $this->custom_feedbackform($submission, true); + if (!empty($customfeedback)) { + echo $customfeedback; + } + echo ''; ///End of teacher info row, Start of student info row @@ -1607,6 +1616,21 @@ class assignment_base { return assignment_display_lateness($timesubmitted, $this->assignment->timedue); } + /** + * Empty method stub for all delete actions. + */ + function delete() { + //nothing by default + redirect('view.php?id='.$this->cm->id); + } + + /** + * Empty custom feedback grading form. + */ + function custom_feedbackform($submission, $return=false) { + //nothing by default + return ''; + } } ////// End of the assignment_base class @@ -2390,7 +2414,7 @@ function assignment_print_overview($courses, &$htmlarray) { // count how many people can submit $submissions = 0; // init $students = get_users_by_capability($context, 'mod/assignment:submit'); - foreach ($student as $student) { + foreach ($students as $student) { if (get_record('assignment_submissions', 'assignment', $assignment->id, 'userid', $student->id)) { $submissions++; } diff --git a/mod/assignment/type/upload/README.txt b/mod/assignment/type/upload/README.txt deleted file mode 100644 index 9b6d66a649..0000000000 --- a/mod/assignment/type/upload/README.txt +++ /dev/null @@ -1,46 +0,0 @@ -Athabasca University (upload) assignment type ------------------------------------------ - -INFORMATION ------------ - -This module has been successfully tested for Moodle versions: - -- 1.5.3 - -- 1.5.4 (yes) - -- 1.6 (yes, but not by me) - -Information about this type can be found here http://webunit.cs.athabascau.ca/moodle/au_adb_functionality/ - -Zipped code can be found here -http://webunit.cs.athabascau.ca/moodle/moodle_files_folder/upload_type.zip/file_view -and on Moodle CVS - -Additional thanks to the guys who developed "Upload&Review" and "Upload files" assignment types. Their code I was using as a base code for my assignment type. - - -INSTALLATION: ------------- - -After downloading and unpacking the archive /*, or checking out the files via CVS,*/ you will be left with a directory called "upload", containing a number of files. - -Place the whole folder in the directory your_moodle_folder/mod/assignment - -Copy content of assignment.php file into - -- your_moodle_folder/lang/en/assignment.php for version 1.5.3 or 1.5.4 - -- your_moodle_folder/lang/en-UTF8/assignment.php for version 1.6 - - -NOTE: ------ - -The temporary name of this type is "upload assignment type". It will be changed in the future to something more appropriate. - -If you would like to change the name you may do it by changing the value of -$string['typeupload'] = 'upload assignment type'; -at your_moodle_folder/lang/en/assignment.php - diff --git a/mod/assignment/type/upload/assignment.class.php b/mod/assignment/type/upload/assignment.class.php index 70833c0c67..a28e8280e8 100644 --- a/mod/assignment/type/upload/assignment.class.php +++ b/mod/assignment/type/upload/assignment.class.php @@ -1,1485 +1,909 @@ file_area_name($userid); - - $output = ''; - - if ($basedir = $this->file_area($userid)) { - if ($files = get_directory_list($basedir)) { - require_once($CFG->libdir.'/filelib.php'); - foreach ($files as $key => $file) { - - $icon = mimeinfo('icon', $file); - - if ($CFG->slasharguments) { - $ffurl = "$CFG->wwwroot/file.php/$filearea/$file"; - } else { - $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; - } - //died right here - //require_once($ffurl); - $output .= ''.$icon.''. - ''.$file.'
'; - } - } - } - - $output = '
'.$output.'
'; - return $output; - } function assignment_upload($cmid=0) { parent::assignment_base($cmid); } - //generates page for file upload, list of uploaded files, feedbacks from teachers, etc function view() { - global $USER; - $this->view_header(); + require_capability('mod/assignment:view', $this->context); + add_to_log($this->course->id, 'assignment', 'view', "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id); + + $this->view_header(); $this->view_intro(); + $this->view_dates(); - $this->view_dates(); + if (has_capability('mod/assignment:submit', $this->context)) { + $filecount = $this->count_user_files($USER->id); + $submission = $this->get_submission($USER->id); - $filecount = $this->count_user_files($USER->id); + $this->view_feedback(); - if ($submission = $this->get_submission()) { - if ($submission->timemarked) { - $this->view_feedback(); - }else if ($filecount) { - print_simple_box($this->print_user_files($USER->id, true), 'center'); - } - //from upload&review. check if there are responses from teacher - if ($submission->data2 != NULL) { - print_heading(get_string('responsesfromteacher', 'assignment')); - $this->print_response_students(true); + if ($this->is_finalized($submission)) { + print_heading(get_string('submission', 'assignment'), 'center', 3); + } else { + print_heading(get_string('submissiondraft', 'assignment'), 'center', 3); } - } - //display Blank if there were no files uploaded yet, otherwithe display submission status - if (!$submission->data1) { - $submission_status = get_string('submissionstatusblank','assignment'); - } - else { - $submission_status = $submission->data1; - } + if ($filecount and $submission) { + print_simple_box($this->print_user_files($USER->id, true), 'center'); + } else { + if ($this->is_finalized($submission)) { + print_simple_box(get_string('nofiles', 'assignment'), 'center'); + } else { + print_simple_box(get_string('nofilesyet', 'assignment'), 'center'); + } + } - //display submisison status - notify("".get_string('submissionstatus', 'assignment')." ".$submission_status); - - if ($submission->data1 != get_string("submissionstatussubmitted", "assignment") && has_capability('mod/assignment:submit', get_context_instance(CONTEXT_MODULE, $this->cm->id)) && $this->isopen() && - ((!$this->assignment->var1 && $submission->data1 == get_string("submissionstatusreturned", "assignment")) || - // $this->assignment->var1 || - !$filecount || - ($this->assignment->resubmit && $submission->data1 == get_string("submissionstatusmarked", "assignment")) || - $submission->data1 == get_string("submissionstatusreturned", "assignment") || - !$submission->timemarked) - ) { $this->view_upload_form(); + + if ($this->notes_allowed()) { + print_heading(get_string('notes', 'assignment'), 'center', 3); + $this->view_notes(); + } + + $this->view_final_submission(); } $this->view_footer(); } - function view_upload_form() { - global $CFG; - $struploadafile = get_string("uploadafile"); - $strmaxsize = get_string("maxsize", "", display_size($this->assignment->maxbytes)); - - echo '
'; - echo '
wwwroot/mod/assignment/upload.php\">"; - echo "

".get_string('step1','assignment')."".get_string('attachfiletoassignment','assignment')." ($strmaxsize)

";//$struploadafile - echo ''; - require_once($CFG->libdir.'/uploadlib.php'); - upload_print_form_fragment(1,array('newfile'),false,null,0,$this->assignment->maxbytes,false); - //upload files - echo ''; - echo "

".get_string('step2','assignment')."".get_string('submitformarking','assignment')."

"; - //final submit - echo ''; - echo "

".get_string('onceassignmentsent','assignment')."

"; + function view_feedback($submission=NULL) { + global $USER; - echo '
'; + if (!$submission) { /// Get submission for this assignment + $submission = $this->get_submission($USER->id); + } - echo '
'; - } + if (empty($submission->timemarked)) { /// Nothing to show, so print nothing + if ($this->count_responsefiles($USER->id)) { + print_heading(get_string('responsefiles', 'assignment', $this->course->teacher), '', 3); + $responsefiles = $this->print_responsefiles($USER->id, true); + print_simple_box($responsefiles, 'center'); + } + return; + } - //from upload&review. generates upload form for markers response - function view_upload_response_form($userid,$offset) { - global $CFG; + /// We need the teacher info + if (! $teacher = get_record('user', 'id', $submission->teacher)) { + error('Could not find the teacher'); + } - $userid = required_param('userid'); + /// Print the feedback + print_heading(get_string('submissionfeedback', 'assignment'), '', 3); - echo '
'; - echo get_string('choosereviewfile','assignment').'
'; + echo ''; - echo 'wwwroot/mod/assignment/upload.php\">"; - echo ''; - echo ''; - echo ''; - require_once($CFG->libdir.'/uploadlib.php'); - upload_print_form_fragment(1,array('newfile'),false,null,0,$this->assignment->maxbytes,false); - echo ''; - echo ''; - echo ''; - } + echo ''; + echo ''; + echo ''; + echo ''; - //general function which calls function for drafts upload, final upload, teachers responce upload - function upload(){ - global $offset; + echo ''; + echo ''; + echo ''; - $this->final_upload(); + echo ''; + echo ''; + echo ''; - } else { - //if this is draft upload - if ($_POST['save']==get_string('attachfile','assignment') && !isset($_POST['userid'])){ - - $this->submission_upload(); - - } else { - //if this is upload of teacher's response - $id = optional_param('id', 0, PARAM_INT); // Course module ID - $a = optional_param('a', 0, PARAM_INT); // Assignment ID - $userid = required_param('userid', 0, PARAM_INT); // Stores student id for uploading a review file to - $this->response_upload($userid); // Upload files - echo ""; - echo ""; - echo ""; - echo ''; - echo "
"; - } - } + echo ''; } - //implements upload regular submissuion - draft files - function submission_upload() { - global $CFG, $USER, $counter; - - require_capability('mod/assignment:submit', get_context_instance(CONTEXT_MODULE, $this->cm->id)); - $this->view_header(get_string('upload')); + function view_upload_form() { + global $CFG, $USER; - $filecount = $this->count_user_files($USER->id); $submission = $this->get_submission($USER->id); - //need to get student's directory and all previously uploaded files - $basedir = $this->file_area($USER->id); - $files = get_directory_list($basedir); + $struploadafile = get_string('uploadafile'); + $strmaxsize = get_string('maxsize', '', display_size($this->assignment->maxbytes)); - if ($this->isopen()) {//&& ($this->assignment->var1 || !$filecount || $this->assignment->resubmit || !$submission->timemarked)) { - if ($submission) { - //TODO: change later to ">= 0", to prevent resubmission when graded 0 - if (($submission->grade > 0) and !$this->assignment->resubmit) { - notify(get_string('alreadygraded', 'assignment')); - } - } - - $dir = $this->file_area_name($USER->id); + if ($this->is_finalized($submission)) { + // no uploading + return; + } - require_once($CFG->dirroot.'/lib/uploadlib.php'); - $um = new upload_manager('newfile',!$this->assignment->var1,false,$course,false,$this->assignment->maxbytes); - - if ($um->process_file_uploads($dir)) { - $newfile_name = $um->get_new_filename(); - //if student already submitted smth before - if ($submission) { - // assignment is not submited for marking - $newsubmission->timemodified = '0'; - //$submission->timemodified = time(); - $flag=false; - foreach ($files as $key => $file) { - if ($file == $newfile_name) { - $flag = true; - } - } - //if this is an assignment for single upload - if (!$this->assignment->var1) { - //if numfiles=1 - if ($submission->numfiles==0 && !$flag) { - $submission->numfiles ++; - } - } else { - //if file with the same name has not been uploaded before - if (!$flag) { - $submission->numfiles ++; - } - } - - $submission->submissioncomment = addslashes($submission->submissioncomment); - unset($submission->data1); // Don't need to update this. - //unset($submission->data2); // Don't need to update this. - if (update_record("assignment_submissions", $submission)) { - add_to_log($this->course->id, 'assignment', 'upload', - 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); - //we email teachers on final upload - //$this->email_teachers($submission); - print_heading(get_string('uploadedfile')); - } else { - notify(get_string("uploadfailnoupdate", "assignment")); - } - //if it's first student's submission - } else { - $newsubmission = $this->prepare_new_submission($USER->id); - //submissions has been created, but not submitted for marking - $newsubmission->timecreated = time(); - $newsubmission->timemodified = '0'; - $newsubmission->data1 = get_string("submissionstatusdraft", "assignment"); - $newsubmission->numfiles = 1; - if (insert_record('assignment_submissions', $newsubmission)) { - add_to_log($this->course->id, 'assignment', 'upload', - 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); - //we email teachers on final upload - //$this->email_teachers($newsubmission); - print_heading(get_string('uploadedfile')); - } else { - notify(get_string("uploadnotregistered", "assignment", $newfile_name)); - } - } - } - } else { - notify(get_string("uploaderror", "assignment")); //submitting not allowed! + if ($this->can_upload_file($submission)) { + echo '
'; + echo '
'; + echo "

$struploadafile ($strmaxsize)

"; + echo ''; + echo ''; + require_once($CFG->libdir.'/uploadlib.php'); + upload_print_form_fragment(1,array('newfile'),null,false,null,0,$this->assignment->maxbytes,false); + echo ''; + echo '
'; + echo '
'; + echo '
'; } - print_continue('view.php?id='.$this->cm->id); + } - $this->view_footer(); + function view_notes() { + global $USER; + + if ($submission = $this->get_submission($USER->id) + and !empty($submission->data1)) { + print_simple_box(format_text($submission->data1, FORMAT_HTML), 'center', '630px'); + } else { + print_simple_box(get_string('notesempty', 'assignment'), 'center'); + } + if ($this->can_update_notes($submission)) { + $options = array ('id'=>$this->cm->id, 'action'=>'editnotes'); + echo '
'; + print_single_button('upload.php', $options, get_string('edit'), 'post', '_self', false); + echo '
'; + } } - //implements final upload (submitting for marking) - function final_upload() { + function view_final_submission() { global $CFG, $USER; - require_capability('mod/assignment:submit', get_context_instance(CONTEXT_MODULE, $this->cm->id)); - - $this->view_header(get_string('upload')); - $filecount = $this->count_user_files($USER->id); $submission = $this->get_submission($USER->id); - if ($this->isopen() && ($this->assignment->var1 || $filecount || $this->assignment->resubmit || !$submission->timemarked)) { - if ($submission) { - //TODO: change later to ">= 0", to prevent resubmission when graded 0 - if (($submission->grade > 0) and !$this->assignment->resubmit) { - notify(get_string('alreadygraded', 'assignment')); - } - } + if ($this->can_finalize($submission)) { + //print final submit button + print_heading(get_string('submitformarking','assignment'), '', 3); + echo '
'; + echo '
'; + echo ''; + echo ''; + echo ''; + echo '
'; + echo '
'; + } else if ($this->is_finalized($submission)) { + print_heading(get_string('submitedformarking','assignment'), '', 3); + } else { + //no submission yet + } + } - $dir = $this->file_area_name($USER->id); + function custom_feedbackform($submission, $return=false) { + global $CFG; - require_once($CFG->dirroot.'/lib/uploadlib.php'); - $um = new upload_manager('newfile',!$this->assignment->var1,false,$course,false,$this->assignment->maxbytes); - - //files hass been preprocessed i saved already, we don't need to do it again - //if ($um->process_file_uploads($dir)) { - $newfile_name = $um->get_new_filename(); - - //if student already submitted smth before - if ($submission) { - //if there is no files uploaded we can't do final submit - if ( $submission->numfiles == 0){ - notify(get_string("nofilesforsubmit","assignment"));//'uploadnofilefound')); - }else{ - $submission->timemodified = time(); - //$submission->numfiles ++; - //$submission->comment = addslashes($submission->comment); - $submission->data1 = get_string("submissionstatussubmitted", "assignment"); - //unset($submission->data2); // Don't need to update this. - if (update_record("assignment_submissions", $submission)) { - add_to_log($this->course->id, 'assignment', 'upload', - 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); - $this->email_teachers($submission); - print_heading(get_string('markingsubmitnotification','assignment')); - - } else { - notify(get_string("uploadfailnoupdate", "assignment")); - } - } - //if it's first student's submission - } else {/*//probably this block can be removed. - $newsubmission = $this->prepare_new_submission($USER->id); - $newsubmission->timecreated = '0'; - $newsubmission->timemodified = '1'; - $newsubmission->data1 = get_string("submissionstatussubmitted", "assignment"); - $newsubmission->numfiles = 1; - if (insert_record('assignment_submissions', $newsubmission)) { - add_to_log($this->course->id, 'assignment', 'upload', - 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); - $this->email_teachers($newsubmission); - print_heading(get_string('markingsubmitnotification','assignment')); - } else { - notify(get_string("uploadnotregistered", "assignment", $newfile_name) ); - }*/ - notify(get_string("nofilesforsubmit","assignment")); - } - // } - } else { - notify(get_string("uploaderror", "assignment")); //submitting not allowed! - } + $mode = optional_param('mode', '', PARAM_ALPHA); + $offset = optional_param('offset', 0, PARAM_INT); + $forcerefresh = optional_param('forcerefresh', 0, PARAM_BOOL); - print_continue('view.php?id='.$this->cm->id); + $output = get_string('responsefiles', 'assignment').': '; - $this->view_footer(); - } + $output .= '
wwwroot/mod/assignment/upload.php\">"; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + require_once($CFG->libdir.'/uploadlib.php'); + $output .= upload_print_form_fragment(1,array('newfile'),null,false,null,0,0,true); + $output .= ''; + $output .= '
'; + if ($forcerefresh) { + $output .= $this->update_main_listing($submission); + } - //from upload&review - function response_file_area_name($userid, $teachid = 0) { - // Creates a directory file name, suitable for make_upload_directory() - global $CFG, $USER; - $fileloc = ""; - if ($teachid == 0) { - $fileloc = "$USER->id/$userid"; - } else { - $fileloc = "$teachid/$USER->id"; + $responsefiles = $this->print_responsefiles($submission->userid, true); + if (!empty($responsefiles)) { + $output .= $responsefiles; } - return $this->course->id.'/'.$CFG->moddata.'/assignment/'.$this->assignment->id.'/responses/'.$fileloc; - } - - //from upload&review - //make the folder which going to hold response files - function response_file_area($userid, $teachid = 0) { - if ($teachid == 0) { - return make_upload_directory( $this->response_file_area_name($userid) ); - } else { - return make_upload_directory( $this->response_file_area_name($userid, $teachid) ); + + if ($return) { + return $output; } - } + echo $output; + return; + } - //from upload&review - //upload responce file - function response_upload($userid) { - global $CFG, $USER; - // $this->view_header(get_string('upload')); + function print_student_answer($userid, $return=false){ + global $CFG; - if (!$this->isopen()) { - notify(get_string("uploadfailnoupdate", "assignment")); - } else { - $submission = $this->get_submission($userid); + $filearea = $this->file_area_name($userid); + $submission = $this->get_submission($userid); - $dir = $this->response_file_area_name($userid); + $output = ''; - require_once($CFG->dirroot.'/lib/uploadlib.php'); - //$um = new upload_manager('newfile',true,false,$course,false,$this->assignment->maxbytes); - //set up $deletothers=false to allow multiple feedback uploads - $um = new upload_manager('newfile',false,false,$course,false,$this->assignment->maxbytes); - - if ($um->process_file_uploads($dir)) { - $newfile_name = $um->get_new_filename(); - if ($submission) { - // stores teacher id's in data2 in comma-separated list so students can view all responses from all teachers - if ($teachids = $submission->data2) { - $teachidarr = explode(',', $teachids); - $teachidexists = false; - foreach($teachidarr as $t) { - if ($t == $USER->id) { - $teachidexists = true; - } - } - if ($teachidexists == false) { - $teachids .= ",$USER->id"; - } - $submission->data2 = $teachids; - } else { - $submission->data2 = $USER->id; - } - //$submission->timemodified = time(); - //$submission->numfiles = 1; - //$submission->comment = addslashes($submission->comment); - - if (update_record("assignment_submissions", $submission)) { - $this->email_students($submission); - //print_heading(get_string('uploadedfile')); - } else { - notify(get_string("uploadfailnoupdate", "assignment")); - } - } else { - notify(get_string("studentrecorderror", "assignment")); + if ($basedir = $this->file_area($userid)) { + if (!$this->is_finalized($submission)) { + $output .= ''.get_string('draft', 'assignment').': '; + } + + if ($this->notes_allowed() and !empty($submission->data1)) { + $output .= link_to_popup_window ('/mod/assignment/type/upload/notes.php?id='.$this->cm->id.'&userid='.$userid, + 'notes'.$userid, get_string('notes', 'assignment'), 500, 780, get_string('notes', 'assignment'), 'none', true, 'notesbutton'.$userid); + $output .= ' '; + } + + if ($files = get_directory_list($basedir, 'responses')) { + foreach ($files as $key => $file) { + require_once($CFG->libdir.'/filelib.php'); + $icon = mimeinfo('icon', $file); + $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; + $output .= ''.$icon.''. + ''.$file.' '; } - notify(get_string("uploadsuccessresponse", "assignment")); } } + $output = '
'.$output.'
'; + $output .= '
'; - // print_continue('view.php?id='.$this->cm->id); - - // $this->view_footer(); + return $output; } - //from upload&review - function email_students($submission) { - /// Alerts students by email of assignments that recieve a new response -// Email students when uploaded & when grade changed? - global $CFG; - //changed from var1 to var2 becasue of the merging two assignment types - if (empty($this->assignment->var2)) { // No need to do anything - return; - } -/* - $user = get_record('user', 'id', $submission->userid); + /** + * Produces a list of links to the files uploaded by a user + * + * @param $userid int optional id of the user. If 0 then $USER->id is used. + * @param $return boolean optional defaults to false. If true the list is returned rather than printed + * @return string optional + */ + function print_user_files($userid=0, $return=false) { + global $CFG, $USER; + + $mode = optional_param('mode', '', PARAM_ALPHA); + $offset = optional_param('offset', 0, PARAM_INT); - if (groupmode($this->course, $this->cm) == SEPARATEGROUPS) { // Separate groups are being used - if (!$group = user_group($this->course->id, $user->id)) { // Try to find a group - $group->id = 0; // Not in a group, never mind + if (!$userid) { + if (!isloggedin()) { + return ''; } - $teachers = get_group_teachers($this->course->id, $group->id); // Works even if not in group - } else { - $teachers = get_course_teachers($this->course->id); + $userid = $USER->id; } - if ($teachers) { + $filearea = $this->file_area_name($userid); - $strassignments = get_string('modulenameplural', 'assignment'); - $strassignment = get_string('modulename', 'assignment'); - $strsubmitted = get_string('submitted', 'assignment'); + $output = ''; - foreach ($teachers as $teacher) { - unset($info); - $info->username = fullname($user); - $info->assignment = format_string($this->assignment->name,true); - $info->url = $CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id; + if ($submission = $this->get_submission($userid)) { - $postsubject = $strsubmitted.': '.$info->username.' -> '.$this->assignment->name; - $posttext = $this->email_teachers_text($info); - $posthtml = ($teacher->mailformat == 1) ? $this->email_teachers_html($info) : ''; + $candelete = $this->can_delete_files($submission); + $strdelete = get_string('delete'); - @email_to_user($teacher, $user, $postsubject, $posttext, $posthtml); // If it fails, oh well, too bad. + if (!$this->is_finalized($submission) and !empty($mode)) { // only during grading + $output .= ''.get_string('draft', 'assignment').':
'; } - } -*/ - } + if ($this->notes_allowed() and !empty($submission->data1) and !empty($mode)) { // only during grading + $offset = required_param('offset', PARAM_INT); - /* - * Display and process the submissions - */ - function process_feedback() { - - global $USER; - - if (!$feedback = data_submitted()) { // No incoming data? - return false; - } - - ///For save and next, we need to know the userid to save, and the userid to go... - ///We use a new hidden field in the form, and set it to -1. If it's set, we use this - ///as the userid to store... - //removed by Oksana. it was braking functionality and submitting teacher's feedback to.. teacher-user - //this was inherited from upload type. check if nothing brackes??????????????? - if ((int)$feedback->saveuserid !== -1) { - $feedback->userid = $feedback->saveuserid; - } - if (!empty($feedback->cancel)) { // User hit cancel button - return false; - } - - $newsubmission = $this->get_submission($feedback->userid, true); // Get or make one - $newsubmission->grade = $feedback->grade; - $newsubmission->submissioncomment = $feedback->submissioncomment; - $newsubmission->format = $feedback->format; - $newsubmission->teacher = $USER->id; - $newsubmission->mailed = 0; // Make sure mail goes out (again, even) - $newsubmission->timemarked = time(); - //marker graded assignment then status set into Marked; if marker didn't grade it then status set into Returned - if (/*$feedback->grade != 0 && */ $feedback->grade != -1 ) { - $newsubmission->data1 = get_string("submissionstatusmarked", "assignment"); - } - else { - $newsubmission->data1 = get_string("submissionstatusreturned", "assignment"); - } - //unset($newsubmission->data1); // Don't need to update this. - //unset($newsubmission->data2); // Don't need to update this. + $npurl = "type/upload/notes.php?id={$this->cm->id}&userid=$userid&offset=$offset&mode=single"; + $output .= ''.get_string('notes', 'assignment').'
'; - if (! update_record('assignment_submissions', $newsubmission)) { - return false; - } - - add_to_log($this->course->id, 'assignment', 'update grades', - 'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id); - - return $newsubmission; - - } - - /* - * Top-level function for handling of submissions called by submissions.php - * - */ - //from lib.php - //needed to update case of fastgrading. upgrade upload_statuses - function submissions($mode) { - ///The main switch is changed to facilitate - ///1) Batch fast grading - ///2) Skip to the next one on the popup - ///3) Save and Skip to the next one on the popup - - //make user global so we can use the id - global $USER; + } - switch ($mode) { - case 'grade': // We are in a popup window grading - if ($submission = $this->process_feedback()) { - //IE needs proper header with encoding - print_header(get_string('feedback', 'assignment').':'.format_string($this->assignment->name)); - print_heading(get_string('changessaved')); - $this->update_main_listing($submission); - } - close_window(); + if ($basedir = $this->file_area($userid)) { + if ($files = get_directory_list($basedir, 'responses')) { + require_once($CFG->libdir.'/filelib.php'); + foreach ($files as $key => $file) { - break; + $icon = mimeinfo('icon', $file); - case 'single': // We are in a popup window displaying submission - $this->display_submission(); - break; + $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; - case 'all': // Main window, display everything - $this->display_submissions(); - break; - case 'fastgrade': - ///do the fast grading stuff - this process should work for all 3 subclasses - $grading = false; - $commenting = false; - $col = false; - if (isset($_POST['submissioncomment'])) { - $col = 'submissioncomment'; - $commenting = true; - } - if (isset($_POST['menu'])) { - $col = 'menu'; - $grading = true; - } - if (!$col) { - //both submissioncomment and grade columns collapsed.. - $this->display_submissions(); - break; - } + $output .= ''.$icon.'' + .''.$file.''; - foreach ($_POST[$col] as $id => $unusedvalue) { + if ($candelete) { + $delurl = "$CFG->wwwroot/mod/assignment/delete.php?id={$this->cm->id}&file=$file&userid={$submission->userid}&mode=$mode&offset=$offset"; - $id = (int)$id; //clean parameter name - if (!$submission = $this->get_submission($id)) { - $submission = $this->prepare_new_submission($id); - $newsubmission = true; - } else { - $newsubmission = false; - } - unset($submission->data1); // Don't need to update this. - unset($submission->data2); // Don't need to update this. - - //for fast grade, we need to check if any changes take place - $updatedb = false; - - if ($grading) { - $grade = $_POST['menu'][$id]; - $updatedb = $updatedb || ($submission->grade != $grade); - $submission->grade = $grade; - } else { - if (!$newsubmission) { - unset($submission->grade); // Don't need to update this. + $output .= ' ' + .''.$strdelete.' '; } - } - - //change status if assignment was graded or returned - if ($submission->grade != -1 ) { - $submission->data1 = get_string("submissionstatusmarked", "assignment"); - } - else { - $submission->data1 = get_string("submissionstatusreturned", "assignment"); - } - if ($commenting) { - $commentvalue = trim($_POST['submissioncomment'][$id]); - $updatedb = $updatedb || ($submission->submissioncomment != stripslashes($commentvalue)); - $submission->submissioncomment = $commentvalue; - } else { - unset($submission->submissioncomment); // Don't need to update this. - } - $submission->teacher = $USER->id; - $submission->mailed = $updatedb?0:$submission->mailed;//only change if it's an update - $submission->timemarked = time(); - - //if it is not an update, we don't change the last modified time etc. - //this will also not write into database if no submissioncomment and grade is entered. - - if ($updatedb) { - if ($newsubmission) { - if (!insert_record('assignment_submissions', $submission)) { - return false; - } - } else { - if (!update_record('assignment_submissions', $submission)) { - return false; - } - } - //add to log only if updating - add_to_log($this->course->id, 'assignment', 'update grades', - 'submissions.php?id='.$this->assignment->id.'&user='.$submission->userid, - $submission->userid, $this->cm->id); + $output .= '
'; } - } - $this->display_submissions(); - break; + } + if (has_capability('mod/assignment:grade', $this->context) + and $this->can_unfinalize($submission) + and $mode != '') { // we do not want it on view.php page + $options = array ('id'=>$this->cm->id, 'userid'=>$userid, 'action'=>'unfinalize', 'mode'=>$mode, 'offset'=>$offset); + $output .= print_single_button('upload.php', $options, get_string('unfinalize', 'assignment'), 'post', '_self', true); + } + $output = '
'.$output.'
'; - case 'next': - /// We are currently in pop up, but we want to skip to next one without saving. - /// This turns out to be similar to a single case - /// The URL used is for the next submission. + } - $this->display_submission(); - break; + if ($return) { + return $output; + } + echo $output; + } - case 'saveandnext': - ///We are in pop up. save the current one and go to the next one. - //first we save the current changes - if ($submission = $this->process_feedback()) { - //print_heading(get_string('changessaved')); - $this->update_main_listing($submission); - } + function print_responsefiles($userid, $return=false) { + global $CFG, $USER; - //then we display the next submission - $this->display_submission(); - break; + $mode = optional_param('mode', '', PARAM_ALPHA); + $offset = optional_param('offset', 0, PARAM_INT); - default: - echo "something seriously is wrong!!"; - break; - } - } + $filearea = $this->file_area_name($userid).'/responses'; - //function that updates the listing on the main script from popup using javascript - //from lib.php - //needed to display teachers responce files and upload_statuses - function update_main_listing($submission) { - global $SESSION; - - $perpage = get_user_preferences('assignment_perpage', 10); - - $quickgrade = get_user_preferences('assignment_quickgrade', 0); - - /// Run some Javascript to try and update the parent page - echo '"; - flush(); - } + if ($files = get_directory_list($basedir)) { + require_once($CFG->libdir.'/filelib.php'); + foreach ($files as $key => $file) { -//display student's submission for marking in pop-up window - function display_submission() { + $icon = mimeinfo('icon', $file); - global $CFG, $offset; + $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; - $userid = required_param('userid', PARAM_INT); - $offset = required_param('offset', PARAM_INT);//offset for where to start looking for student. + $output .= ''.$icon.'' + .''.$file.''; - if (!$user = get_record('user', 'id', $userid)) { - error('No such user!'); - } + if ($candelete) { + $delurl = "$CFG->wwwroot/mod/assignment/delete.php?id={$this->cm->id}&file=$file&userid=$userid&mode=$mode&offset=$offset&action=response"; - if (!$submission = $this->get_submission($user->id)) { - $submission = $this->prepare_new_submission($userid); - } + $output .= ' ' + .''.$strdelete.' '; + } - if ($submission->timemodified > $submission->timemarked) { - $subtype = 'assignmentnew'; - } else { - $subtype = 'assignmentold'; - } + $output .= ' '; + } + } - ///construct SQL, using current offset to find the data of the next student - $course = $this->course; - $assignment = $this->assignment; - $cm = $this->cm; - if ($groupmode = groupmode($course, $cm)) { // Groups are being used - $currentgroup = setup_and_print_groups($course, $groupmode, 'submissions.php?id='.$this->cm->id); - } else { - $currentgroup = false; + $output = '
'.$output.'
'; + } - /// Get all teachers and students - if ($currentgroup) { - $users = get_group_users($currentgroup); - } else { - $users = get_course_users($course->id); + if ($return) { + return $output; } + echo $output; + } - $select = 'SELECT u.id, u.id, u.firstname, u.lastname, u.picture,'. - 's.id AS submissionid, s.grade, s.submissioncomment, s.timemodified, s.timemarked, ((s.timemarked > 0) AND (s.timemarked >= s.timemodified)) AS status '; - $sql = 'FROM '.$CFG->prefix.'user u '. - 'LEFT JOIN '.$CFG->prefix.'assignment_submissions s ON u.id = s.userid AND s.assignment = '.$this->assignment->id.' '. - 'WHERE u.id IN ('.implode(',', array_keys($users)).') AND s.data1 <> "Draft" AND s.data1 <> ""'; - //we don't need to grade draft or empty assignments - require_once($CFG->libdir.'/tablelib.php'); - if ($sort = flexible_table::get_sql_sort('mod-assignment-submissions')) { - $sort = 'ORDER BY '.$sort.' '; - } + function upload() { + $action = required_param('action', PARAM_ALPHA); - $limit = sql_paging_limit($offset+1, 1); - $nextid = 0; - if (($auser = get_record_sql($select.$sql.$sort.$limit, false, true)) !== false) { - $nextid = $auser->id; + switch ($action) { + case 'finalize': + $this->finalize(); + break; + case 'unfinalize': + $this->unfinalize(); + break; + case 'uploadresponse': + $this->upload_responsefile(); + break; + case 'uploadfile': + $this->upload_file(); + case 'savenotes': + case 'editnotes': + $this->upload_notes(); + default: + error('Error: Unknow upload action ('.$action.').'); } -//1111 -//echo "$auser->id $auser->firstname $auser->lastname -next user
$offset -- offset
$userid -- present userid "; -//echo $offset."-offset on display submission
"; - print_header(get_string('feedback', 'assignment').':'.fullname($user, true).':'.format_string($this->assignment->name)); - - ///SOme javascript to help with setting up >.> + } - echo ''."\n"; + $returnurl = 'view.php?id='.$this->cm->id; -//+++ - // Prints upload form for teachers to upload response file - $this->view_upload_response_form($userid,$offset); -//+++ - echo ''; + if (data_submitted() and $action == 'savenotes') { + $text = required_param('text', PARAM_RAW); // to be cleaned before display + $submission = $this->get_submission($USER->id, true); // get or create submission + $updated = new object(); + $updated->id = $submission->id; + $updated->timemodified = time(); + $updated->data1 = $text; - ///Start of teacher info row + if (update_record('assignment_submissions', $updated)) { + add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); + redirect($returnurl); + } else { + $this->view_header(get_string('notes', 'assignment')); + notify(get_string('notesupdateerror', 'assignment')); + print_continue($returnurl); + $this->view_footer(); + die; + } + } - echo ''; - echo ''; - echo ''; + echo ''; + echo ''; - if ($this->usehtmleditor) { - use_html_editor(); + if (can_use_html_editor()) { + use_html_editor(); // MUst be at the end of the page } - print_footer('none'); + $this->view_footer(); + die; } - //from upload&review - // Prints response files to students - function print_response_students($return) { - global $CFG, $USER; + function upload_responsefile() { + global $CFG; - $stuid = $USER->id; + $userid = required_param('userid', PARAM_INT); + $mode = required_param('mode', PARAM_ALPHA); + $offset = required_param('offset', PARAM_INT); - echo ''; + $returnurl = "submissions.php?id={$this->cm->id}&userid=$userid&mode=$mode&offset=$offset"; - $submission = $this->get_submission($stuid); - if ($teachids = $submission->data2) { // Only will show files if there is a submission - $teachidarr = explode(',', $teachids); + if (data_submitted() and $this->can_manage_responsefiles()) { + $dir = $this->file_area_name($userid).'/responses'; + check_dir_exists($CFG->dataroot.'/'.$dir,true); - foreach ($teachidarr as $t) { - if (! $teacher = get_record('user', 'id', $t)) { - print_object($submission); - error('Could not find the teacher'); - } - echo ''; - echo ''; - echo '';*/ - //displays multiple teachers responces - $output .=''.$icon.''. - link_to_popup_window ('/'.$ffurl, 'file'.$key, $file, 450, 580, $file, 'none', true)."
"; - } - } - } - echo '
'.$output.'
'; - echo ''; + require_once($CFG->dirroot.'/lib/uploadlib.php'); + $um = new upload_manager('newfile',false,true,$this->course,false,0,true); + + if (!$um->process_file_uploads($dir)) { + print_header(get_string('upload')); + notify(get_string('uploaderror', 'assignment')); + echo $um->get_errors(); + print_continue($returnurl); + print_footer('none'); + die; } - echo ''; } + redirect($returnurl); } - //print teacher's files - function print_user_response_files($stuid,$display_remove_button=false,$offset=NULL) {//, $return=false) { - + function upload_file() { global $CFG, $USER; - $userid = $USER->id; + $mode = optional_param('mode', '', PARAM_ALPHA); + $offset = optional_param('offset', 0, PARAM_INT); - $filearea = $this->response_file_area_name($stuid); + $returnurl = 'view.php?id='.$this->cm->id; - $output = ''; + $filecount = $this->count_user_files($USER->id); + $submission = $this->get_submission($USER->id); - if ($basedir = $this->response_file_area($stuid)) { - if ($files = get_directory_list($basedir)) { - require_once($CFG->libdir.'/filelib.php'); - foreach ($files as $key => $file) { + if (!$this->can_upload_file($submission)) { + $this->view_header(get_string('upload')); + notify(get_string('uploaderror', 'assignment')); + print_continue($returnurl); + $this->view_footer(); + die; + } - $icon = mimeinfo('icon', $file); + $dir = $this->file_area_name($USER->id); + check_dir_exists($CFG->dataroot.'/'.$dir.'/responses',true); // better to create now so that student submissions do not block it later - if ($CFG->slasharguments) { - $ffurl = "file.php/$filearea/$file"; - } else { - $ffurl = "file.php?file=/$filearea/$file"; - } + require_once($CFG->dirroot.'/lib/uploadlib.php'); + $um = new upload_manager('newfile',false,true,$this->course,false,$this->assignment->maxbytes,true); - //get feedback file size, generate and display remove file link - $filesize = display_size(filesize($basedir."/".$file)); - $remove_link=''; - if ($display_remove_button) { - $course_mod_id=$this->cm->id; - $deleteurl="$CFG->wwwroot/mod/assignment/type/upload/deleteonesubmission.php?confirm=0&view=teacher&userid=$stuid&id=$course_mod_id&name=$file&file=".$basedir."/".$file."&offset=".$offset; - $remove_link='['.get_string("removelink", "assignment").']'; - } - $output .= ''.$icon.''. - // link_to_popup_window ('/'.$ffurl, 'file'.$key, $file, 450, 580, $file, 'none', true). - $file.' ['.$filesize.'] '.$remove_link.'
'; - } + if ($um->process_file_uploads($dir)) { + $submission = $this->get_submission($USER->id, true); //create new submission if needed + $updated = new object(); + $updated->id = $submission->id; + $updated->timemodified = time(); + + if (update_record('assignment_submissions', $updated)) { + add_to_log($this->course->id, 'assignment', 'upload', + 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); + } else { + $new_filename = $um->get_new_filename(); + $this->view_header(get_string('upload')); + notify(get_string('uploadnotregistered', 'assignment', $new_filename)); + print_continue($returnurl); + $this->view_footer(); + die; } + redirect('view.php?id='.$this->cm->id); } - $output = '
'.$output.'
'; - - return $output; + $this->view_header(get_string('upload')); + notify(get_string('uploaderror', 'assignment')); + echo $um->get_errors(); + print_continue($returnurl); + $this->view_footer(); + die; } - //print student's files. - //if it's teacher view - teacher can view the files, but can't delete them - //if it's student's view - stident can delete files, but can't view them - function print_user_files($userid=0, $return=false) { - global $CFG, $USER; + function finalize() { + global $USER; - if (!$userid) { - if (!isloggedin()) { - return ''; + $confirm = optional_param('confirm', 0, PARAM_BOOL); + + $returnurl = 'view.php?id='.$this->cm->id; + $submission = $this->get_submission($USER->id); + + if (!$this->can_finalize($submission)) { + redirect($returnurl); // probably already graded, erdirect to assignment page, the reason should be obvious + } + + if (!data_submitted() or !$confirm) { + $optionsno = array('id'=>$this->cm->id); + $optionsyes = array ('id'=>$this->cm->id, 'confirm'=>1, 'action'=>'finalize'); + $this->view_header(get_string('submitformarking', 'assignment')); + print_heading(get_string('submitformarking', 'assignment')); + notice_yesno(get_string('onceassignmentsent', 'assignment'), 'upload.php', 'view.php', $optionsyes, $optionsno, 'post', 'get'); + $this->view_footer(); + die; + + } else { + $updated = new object(); + $updated->id = $submission->id; + $updated->data2 = ASSIGNMENT_STATUS_SUBMITTED; + $updated->timemodified = time(); + if (update_record('assignment_submissions', $updated)) { + add_to_log($this->course->id, 'assignment', 'upload', //TODO: add finilize action to log + 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); + $this->email_teachers($submission); + } else { + $this->view_header(get_string('submitformarking', 'assignment')); + notify(get_string('finalizeerror', 'assignment')); + print_continue($returnurl); + $this->view_footer(); + die; } - $userid = $USER->id; } + redirect($returnurl); + } - $filearea = $this->file_area_name($userid); + function unfinalize() { - $output = ''; + $userid = required_param('userid', PARAM_INT); + $mode = required_param('mode', PARAM_ALPHA); + $offset = required_param('offset', PARAM_INT); - if ($basedir = $this->file_area($userid)) { - if ($files = get_directory_list($basedir)) { + $returnurl = "submissions.php?id={$this->cm->id}&userid=$userid&mode=$mode&offset=$offset&forcerefresh=1"; - foreach ($files as $key => $file) { - require_once($CFG->libdir.'/filelib.php'); + if (data_submitted() + and $submission = $this->get_submission($userid) + and $this->can_unfinalize($submission)) { - $icon = mimeinfo('icon', $file); - //get filesize for displaying - $filesize = display_size(filesize($basedir."/".$file)); - - if ($CFG->slasharguments) { - $ffurl = "$CFG->wwwroot/file.php/$filearea/$file"; - } else { - $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; - } - if (has_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $this->course->id))) { - $output .= ''.$icon.''. - ''.$file.' ['.$filesize.']
'; - } else { - if (!empty($USER->id)) { - if ($submission = $this->get_submission($USER->id)) { - //i have changed timemodified=0 for Draft assignments, thats' why we remove this condition - //otherwise student's dont' se etheir own submissions -// if ($submission->timemodified) { - if ($submission->timemodified <= $this->assignment->timedue || empty($this->assignment->timedue)) { - //remove link shouldn't be displayed if file was marked or submited for marking - $remove_link = ''; - if ($submission->data1 == get_string("submissionstatusdraft", "assignment") || $submission->data1 == get_string("submissionstatusreturned", "assignment")) { - $course_mod_id=$this->cm->id; - $deleteurl="$CFG->wwwroot/mod/assignment/type/upload/deleteonesubmission.php?confirm=0&view=student&userid=$userid&id=$course_mod_id&name=$file&file=".$basedir."/".$file; - $remove_link= '['.get_string("removelink", "assignment").']'; //students of the course - } - $output .= ''.$icon.''.$file.' ['.$filesize.']'.$remove_link.'
'; - } else { - $output .= ''; - } - } - } - } - } + $updated = new object(); + $updated->id = $submission->id; + $updated->data2 = ''; + if (update_record('assignment_submissions', $updated)) { + //TODO: add unfinilize action to log + add_to_log($this->course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->assignment->id, $this->assignment->id, $this->cm->id); + } else { + $this->view_header(get_string('submitformarking')); + notify(get_string('finalizeerror', 'assignment')); + print_continue($returnurl); + $this->view_footer(); + die; } } + redirect($returnurl); + } - $output = '
'.$output.'
'; - if ($return) { - return $output; - } - echo $output; - } + function delete() { + $action = optional_param('action', '', PARAM_ALPHA); - /* - * Display all the submissions ready for grading - */ - //from lib.php - //we needed so select more information from database and add upload_statuses display - function display_submissions() { - global $CFG, $db, $USER; - - /* first we check to see if the form has just been submitted - * to request user_preference updates - */ - if (isset($_POST['updatepref'])) { - $perpage = optional_param('perpage', 10, PARAM_INT); - $perpage = ($perpage <= 0) ? 10 : $perpage ; - set_user_preference('assignment_perpage', $perpage); - set_user_preference('assignment_quickgrade', optional_param('quickgrade',0, PARAM_BOOL)); + switch ($action) { + case 'response': + $this->delete_responsefile(); + break; + default: + $this->delete_file(); } + die; + } - /* next we get perpage and quickgrade (allow quick grade) params - * from database - */ - $perpage = get_user_preferences('assignment_perpage', 10); - $quickgrade = get_user_preferences('assignment_quickgrade', 0); - - $teacherattempts = true; /// Temporary measure - $page = optional_param('page', 0, PARAM_INT); - $strsaveallfeedback = get_string('saveallfeedback', 'assignment'); - /// Some shortcuts to make the code read better + function delete_responsefile() { + global $CFG; - $course = $this->course; - $assignment = $this->assignment; - $cm = $this->cm; + $file = required_param('file', PARAM_FILE); + $userid = required_param('userid', PARAM_INT); + $mode = required_param('mode', PARAM_ALPHA); + $offset = required_param('offset', PARAM_INT); + $confirm = optional_param('confirm', 0, PARAM_BOOL); - $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet + $returnurl = "submissions.php?id={$this->cm->id}&userid=$userid&mode=$mode&offset=$offset"; - add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->assignment->id, $this->assignment->id, $this->cm->id); + if (!$this->can_manage_responsefiles()) { + redirect($returnurl); + } - print_header_simple(format_string($this->assignment->name,true), "", ''.$this->strassignments.' -> '.format_string($this->assignment->name,true).' -> '. $this->strsubmissions, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm)); + $urlreturn = 'submissions.php'; + $optionsreturn = array('id'=>$this->cm->id, 'offset'=>$offset, 'mode'=>$mode, 'userid'=>$userid); - //change column name to upload_status to allow ordering by upload_statuses - $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'upload_status'); - $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified').' ('.$course->student.')', get_string('lastmodified').' ('.$course->teacher.')', get_string('status')); + if (!data_submitted() or !$confirm) { + $optionsyes = array ('id'=>$this->cm->id, 'file'=>$file, 'userid'=>$userid, 'confirm'=>1, 'action'=>'response', 'mode'=>$mode, 'offset'=>$offset); + print_header(get_string('delete')); + print_heading(get_string('delete')); + notice_yesno(get_string('confirmdeletefile', 'assignment', $file), 'delete.php', $urlreturn, $optionsyes, $optionsreturn, 'post', 'get'); + print_footer('none'); + die; + } - require_once($CFG->libdir.'/tablelib.php'); - $table = new flexible_table('mod-assignment-submissions'); + $dir = $this->file_area_name($userid).'/responses'; + $filepath = $CFG->dataroot.'/'.$dir.'/'.$file; + if (file_exists($filepath)) { + if (@unlink($filepath)) { + redirect($returnurl); + } + } - $table->define_columns($tablecolumns); - $table->define_headers($tableheaders); - $table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id); + // print delete error + print_header(get_string('delete')); + notify(get_string('deletefilefailed', 'assignment')); + print_continue($returnurl); + print_footer('none'); + die; - $table->sortable(true); - $table->collapsible(true); - $table->initialbars(true); + } - $table->column_suppress('picture'); - $table->column_suppress('fullname'); - $table->column_class('picture', 'picture'); - $table->column_class('fullname', 'fullname'); - $table->column_class('grade', 'grade'); - $table->column_class('submissioncomment', 'comment'); - $table->column_class('timemodified', 'timemodified'); - $table->column_class('timemarked', 'timemarked'); - $table->column_class('status', 'status'); + function delete_file() { + global $CFG; - $table->set_attribute('cellspacing', '0'); - $table->set_attribute('id', 'attempts'); - $table->set_attribute('class', 'submissions'); - $table->set_attribute('width', '90%'); - $table->set_attribute('align', 'center'); + $file = required_param('file', PARAM_FILE); + $userid = required_param('userid', PARAM_INT); + $confirm = optional_param('confirm', 0, PARAM_BOOL); + $mode = optional_param('mode', '', PARAM_ALPHA); + $offset = optional_param('offset', 0, PARAM_INT); - // Start working -- this is necessary as soon as the niceties are over - $table->setup(); + require_login($this->course->id, false, $this->cm); - /// Check to see if groups are being used in this assignment - if ($groupmode = groupmode($course, $cm)) { // Groups are being used - $currentgroup = setup_and_print_groups($course, $groupmode, 'submissions.php?id='.$this->cm->id); + if (empty($mode)) { + $urlreturn = 'view.php'; + $optionsreturn = array('id'=>$this->cm->id); + $returnurl = 'view.php?id='.$this->cm->id; } else { - $currentgroup = false; + $urlreturn = 'submissions.php'; + $optionsreturn = array('id'=>$this->cm->id, 'offset'=>$offset, 'mode'=>$mode, 'userid'=>$userid); + $returnurl = "submissions.php?id={$this->cm->id}&offset=$offset&mode=$mode&userid=$userid"; } - /// Get all teachers and students - if ($currentgroup) { - $users = get_group_users($currentgroup); - } else { - $users = get_course_users($course->id); + if (!$submission = $this->get_submission($userid) // incorrect submission + or !$this->can_delete_files($submission)) { // can not delete + $this->view_header(get_string('delete')); + notify(get_string('cannotdeletefiles', 'assignment')); + print_continue($returnurl); + $this->view_footer(); + die; } + $dir = $this->file_area_name($userid); - if (!$teacherattempts) { - $teachers = get_course_teachers($course->id); - if (!empty($teachers)) { - $keys = array_keys($teachers); + if (!data_submitted() or !$confirm) { + $optionsyes = array ('id'=>$this->cm->id, 'file'=>$file, 'userid'=>$userid, 'confirm'=>1, 'sesskey'=>sesskey(), 'mode'=>$mode, 'offset'=>$offset); + if (empty($mode)) { + $this->view_header(get_string('delete')); + } else { + print_header(get_string('delete')); } - foreach ($keys as $key) { - unset($users[$key]); + print_heading(get_string('delete')); + notice_yesno(get_string('confirmdeletefile', 'assignment', $file), 'delete.php', $urlreturn, $optionsyes, $optionsreturn, 'post', 'get'); + if (empty($mode)) { + $this->view_footer(); + } else { + print_footer('none'); } + die; } - if (empty($users)) { - print_heading(get_string('noattempts','assignment')); - return true; + $filepath = $CFG->dataroot.'/'.$dir.'/'.$file; + if (file_exists($filepath)) { + if (@unlink($filepath)) { + $updated = new object(); + $updated->id = $submission->id; + $updated->timemodified = time(); + if (update_record('assignment_submissions', $updated)) { + add_to_log($this->course->id, 'assignment', 'upload', //TODO: add delete action to log + 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); + } + redirect($returnurl); + } } - /// Construct the SQL - - if ($where = $table->get_sql_where()) { - $where .= ' AND '; + // print delete error + if (empty($mode)) { + $this->view_header(get_string('delete')); + } else { + print_header(get_string('delete')); } - - if ($sort = $table->get_sql_sort()) { - $sort = ' ORDER BY '.$sort; + notify(get_string('deletefilefailed', 'assignment')); + print_continue($returnurl); + if (empty($mode)) { + $this->view_footer(); + } else { + print_footer('none'); } + die; + } - //select has been modified. because we also need to get student id & assignment status == upload_status = {Draft, Submitted, Marked, Returned} - $select = 'SELECT u.id, u.id, u.firstname, u.lastname, u.picture, u.idnumber, s.id AS submissionid, s.grade, s.submissioncomment, s.timemodified, s.timemarked, ((s.timemarked > 0) AND (s.timemarked >= s.timemodified)) AS status, s.data1 as upload_status '; - - // $select = 'SELECT u.id, u.id, u.firstname, u.lastname, u.picture, s.id AS submissionid, s.grade, s.comment, s.timemodified, s.timemarked, ((s.timemarked > 0) AND (s.timemarked >= s.timemodified)) AS status '; - $sql = 'FROM '.$CFG->prefix.'user u '. - 'LEFT JOIN '.$CFG->prefix.'assignment_submissions s ON u.id = s.userid AND s.assignment = '.$this->assignment->id.' '. - 'WHERE '.$where.'u.id IN ('.implode(',', array_keys($users)).') '; - $table->pagesize($perpage, count($users)); + function can_upload_file($submission) { + global $USER; - if($table->get_page_start() !== '' && $table->get_page_size() !== '') { - $limit = ' '.sql_paging_limit($table->get_page_start(), $table->get_page_size()); - } - else { - $limit = ''; + if (has_capability('mod/assignment:submit', $this->context) // can submit + and $this->isopen() // assignment not closed yet + and (empty($submission) or $submission->grade == -1) // not graded + and (empty($submission) or $submission->userid == $USER->id) // his/her own submission + and $this->count_user_files($USER->id) < $this->assignment->var1) { // file limit not reached + return true; + } else { + return false; } + } - ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next - $offset = $page * $perpage; - - // we have changed the wording. - //$strupdate = get_string('update'); - //$strgrade = get_string('grade'); - $grademenu = make_grades_menu($this->assignment->grade); - - if (($ausers = get_records_sql($select.$sql.$sort.$limit)) !== false) { - - foreach ($ausers as $auser) { - $picture = print_user_picture($auser->id, $course->id, $auser->picture, false, true); - - if (empty($auser->submissionid)){ - $auser->grade = -1; //no submission yet - } - - //if there is no upload status, then display "blank" - if (empty($auser->upload_status)) { - $auser->upload_status=get_string("submissionstatusblank", "assignment"); - } - if (!empty($auser->submissionid)) { - ///Prints student answer and student modified date - ///attach file or print link to student answer, depending on the type of the assignment. - ///Refer to print_student_answer in inherited classes - // do not display draft submissions to marker. - if ($auser->timemodified > 0 && $auser->upload_status != get_string("submissionstatusdraft", "assignment")) { - $studentmodified = '
'.$this->print_student_answer($auser->id).userdate($auser->timemodified).'
'; - } else { - $studentmodified = '
 
'; - } - ///Print grade, dropdown or text - if ($auser->timemarked > 0) { - //display teachers feedback files here as well - $teachermodified = '
'.$this->print_user_response_files($auser->id,false).userdate($auser->timemarked).'
'; - //disable grading ability in case of Blank or Draft assignment - if ($quickgrade) {//&& ($auser->upload_status != get_string("submissionstatusdraft", "assignment") || !$auser->upload_status )){// get_string("submissionstatusblank", "assignment"))){ - $grade = '
'.choose_from_menu(make_grades_menu($this->assignment->grade), - 'menu['.$auser->id.']', $auser->grade, get_string('nograde'),'',-1,true,false,$tabindex++).'
'; - } else { - $grade = '
'.$this->display_grade($auser->grade).'
'; - } - - } else { - $teachermodified = '
 
'; - - if ($quickgrade && $auser->upload_status != get_string("submissionstatusdraft", "assignment") && $auser->upload_status != get_string("submissionstatusblank", "assignment")) { - $grade = '
'.choose_from_menu(make_grades_menu($this->assignment->grade), - 'menu['.$auser->id.']', $auser->grade, get_string('nograde'),'',-1,true,false,$tabindex++).'
'; - } else { - $grade = '
'.$this->display_grade($auser->grade).'
'; - } - } - ///Print Comment - if ($quickgrade && $auser->upload_status != get_string("submissionstatusdraft", "assignment") && $auser->upload_status != get_string("submissionstatusblank", "assignment")) { - $comment = '
'; - } else { - $comment = '
'.shorten_text(strip_tags($auser->submissioncomment),15).'
'; - } - } else { - $studentmodified = '
 
'; - $teachermodified = '
 
'; - $status = '
 
'; - - if ($quickgrade && $auser->upload_status != get_string("submissionstatusdraft", "assignment") && $auser->upload_status != get_string("submissionstatusblank", "assignment")) { // allow editing - $grade = '
'.choose_from_menu(make_grades_menu($this->assignment->grade), - 'menu['.$auser->id.']', $auser->grade, get_string('nograde'),'',-1,true,false,$tabindex++).'
'; - } else { - $grade = '
-
'; - } - if ($quickgrade && $auser->upload_status != get_string("submissionstatusdraft", "assignment") && $auser->upload_status != get_string("submissionstatusblank", "assignment") ){ - $comment = '
'; - } else { - $comment = '
 
'; - } - } + function can_manage_responsefiles() { + if (has_capability('mod/assignment:grade', $this->context)) { + return true; + } else { + return false; + } + } - //display upload statuses instead of old ones ={Grade, Update} - //if ($auser->status === NULL) { - // $auser->status = 0; - //} - $buttontext=$auser->upload_status; - //$buttontext = ($auser->status == 1) ? $strupdate : $strgrade; + function can_delete_files($submission) { + global $USER; - //do not display link to the grading pop-up if upload_status={Blank, Draft} - if ($auser->upload_status == get_string("submissionstatusdraft", "assignment") || $auser->upload_status == get_string("submissionstatusblank", "assignment")){ - $button = $buttontext; - } else { - ///No more buttons, we use popups ;-). - $button = link_to_popup_window ('/mod/assignment/submissions.php?id='.$this->cm->id.'&userid='.$auser->id.'&mode=single'.'&offset='.$offset++,'grade'.$auser->id, $buttontext, 500, 780, $buttontext, 'none', true, 'button'.$auser->id); - } - //changed to $auser->upload_status - $status = '
'.$button.'
'; - $row = array($picture, $this->fullname($auser), $grade, $comment, $studentmodified, $teachermodified, $status); - $table->add_data($row); - } + if (has_capability('mod/assignment:grade', $this->context)) { + return true; } - /// Print quickgrade form around the table - if ($quickgrade) { - echo '
'; - echo ''; - echo ''; - echo ''; + if (has_capability('mod/assignment:submit', $this->context) + and $this->isopen() // assignment not closed yet + and (!empty($submission) and $submission->grade == -1) // not graded + and $this->assignment->resubmit // deleting allowed + and $USER->id == $submission->userid // his/her own submission + and !$this->is_finalized($submission)) { // no deleting after final submission + return true; + } else { + return false; } + } - $table->print_html(); /// Print the whole table - - if ($quickgrade) { - echo '

'; - echo '
'; + function is_finalized($submission) { + if (!empty($submission) + and $submission->data2 == ASSIGNMENT_STATUS_SUBMITTED) { + return true; + } else { + return false; } - /// End of fast grading form + } - /// Mini form for setting user preference - echo '
'; - echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo '
'; - echo ''; - echo ':'; - echo ''; - helpbutton('pagesize', get_string('pagesize','assignment'), 'assignment'); - echo '
'; - print_string('quickgrade','assignment'); - echo ':'; - if ($quickgrade) { - echo ''; + function can_unfinalize($submission) { + if (has_capability('mod/assignment:grade', $this->context) + and !empty($submission) + and $this->is_finalized($submission) + and $submission->grade == -1) { + return true; } else { - echo ''; + return false; } - helpbutton('quickgrade', get_string('quickgrade', 'assignment'), 'assignment').'

'; - echo '
'; - echo ''; - echo '
'; - echo '
'; - ///End of mini form - print_footer($this->course); } - //deletes submitted file (assignment or response) - function deleteonesubmission () { - global $CFG, $USER; - - require_once($CFG->libdir.'/filelib.php'); - - $id = required_param('id', PARAM_INT); // Course module ID - $a = optional_param('a'); // Assignment ID - $file = optional_param('file', '', PARAM_PATH); - $userid = optional_param('userid'); - $confirm = optional_param('confirm'); - $name = optional_param('name'); - $offset = optional_param('offset'); - $view = optional_param('view'); //teacher or student view - - $submission = $this->get_submission($USER->id); + function can_finalize($submission) { + global $USER; + if (has_capability('mod/assignment:submit', $this->context) // can submit + and $this->isopen() // assignment not closed yet + and !empty($submission) // submission must exist + and $submission->data2 != ASSIGNMENT_STATUS_SUBMITTED // not graded + and $submission->userid == $USER->id // his/her own submission + and $submission->grade == -1 // no reason to finalize already graded submission + and ($this->count_user_files($USER->id) + or ($this->notes_allowed() and !empty($submission->data1)))) { // something must be submitted - if ($view == 'teacher') { - $yes_url = "$CFG->wwwroot/mod/assignment/type/upload/deleteonesubmission.php?confirm=1&view=teacher&userid=$userid&id=$id&name=$name&file=$file&offset=$offset"; - $no_url = "../../submissions.php?userid=$userid&id=$id&mode=single&offset=$offset"; - $back_button = get_string("backtofeedback", "assignment"); - $action_url = '../../submissions.php'; + return true; } else { - $yes_url = "$CFG->wwwroot/mod/assignment/type/upload/deleteonesubmission.php?confirm=1&view=student&userid=$userid&id=$id&name=$name&file=$file&offset=$offset"; - $no_url = "../../view.php?id=$id&offset=$offset"; - $back_button = get_string("backtoassignment", "assignment"); - $action_url = '../../view.php'; - } - - if ($view == 'student') { - $this->view_header(); + return false; } + } - if (!empty($confirm)) { + function can_update_notes($submission) { + global $USER; - if (!fulldelete($file)) { - notify(get_string("deletefail", "assignment")); - notify($file); - } else { - //if student deletes submitted files then numfiles should be changed - if ($view == 'student'){ - $submission->numfiles --; - if (update_record("assignment_submissions", $submission)) { - notify(get_string("deleteednotification", "assignment")); - } else { - notify(get_string("deletefail", "assignment")); - notify($file); - } - } else { - notify(get_string("deleteednotification", "assignment")); - } - - } -/* echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; - echo '';//selected menu index - //new hidden field, initialized to -1. - echo ''; -*/ - echo ""; - echo ''; - echo ""; - echo ""; - //echo ""; - echo ""; - echo "
"; - + if (has_capability('mod/assignment:submit', $this->context) + and $this->notes_allowed() // notesd must be allowed + and $this->isopen() // assignment not closed yet + and (empty($submission) or $submission->grade == -1) // not graded + and (empty($submission) or $USER->id == $submission->userid) // his/her own submission + and !$this->is_finalized($submission)) { // no updateingafter final submission + return true; } else { - notify (get_string("namedeletefile", "assignment")); - notify($name); - notice_yesno (get_string("deletecheckfile", "assignment"), $yes_url, $no_url); + return false; } - - if ($view == 'student') $this->view_footer(); - } - //from moodlelib.php - //we need to dispaly studentID along with student name in a grading interface - function fullname($user, $override=false) { - - global $CFG, $SESSION; + function notes_allowed() { + return (boolean)$this->assignment->var2; + } - $user_id=''; - if ($user->idnumber) { - $user_id = ' ('. $user->idnumber .') '; - } + /** + * Count the files uploaded by a given user + * + * @param $userid int The user id + * @return int + */ + function count_user_files($userid) { + global $CFG; - if (!isset($user->firstname) and !isset($user->lastname)) { - return ''; - } + $filearea = $this->file_area_name($userid); - if (!$override) { - if (!empty($CFG->forcefirstname)) { - $user->firstname = $CFG->forcefirstname; - } - if (!empty($CFG->forcelastname)) { - $user->lastname = $CFG->forcelastname; + if ( is_dir($CFG->dataroot.'/'.$filearea) && $basedir = $this->file_area($userid)) { + if ($files = get_directory_list($basedir, 'responses')) { + return count($files); } } + return 0; + } - if (!empty($SESSION->fullnamedisplay)) { - $CFG->fullnamedisplay = $SESSION->fullnamedisplay; - } - - if ($CFG->fullnamedisplay == 'firstname lastname') { - return $user->firstname .' '. $user->lastname . $user_id; + function count_responsefiles($userid) { + global $CFG; - } else if ($CFG->fullnamedisplay == 'lastname firstname') { - return $user->lastname .' '. $user->firstname . $user_id; + $filearea = $this->file_area_name($userid).'/responses'; - } else if ($CFG->fullnamedisplay == 'firstname') { - if ($override) { - return get_string('fullnamedisplay', '', $user); - } else { - return $user->firstname . $user_id;; - } - } else if ($CFG->fullnamedisplay == 'textuid') { - if ( $override ) { - return get_string('fullnamedisplay', '', $user) . $user_id; - } else if (isset($user->username)) { - return $user->username . $user_id; - } else { - return $user->firstname . $user_id; + if ( is_dir($CFG->dataroot.'/'.$filearea) && $basedir = $this->file_area($userid)) { + $basedir .= '/responses'; + if ($files = get_directory_list($basedir)) { + return count($files); } } - - return get_string('fullnamedisplay', '', $user) . $user_id; + return 0; } + } ?> diff --git a/mod/assignment/type/upload/mod.html b/mod/assignment/type/upload/mod.html index ab27e9dd2f..f5f14a1d83 100644 --- a/mod/assignment/type/upload/mod.html +++ b/mod/assignment/type/upload/mod.html @@ -1,22 +1,19 @@ var1)) { + $form->var1 = 3; // max number of uploaded files + } + if (empty($form->var2)) { + $form->var2 = 0; // enable notes + } if (empty($form->resubmit)) { - $form->resubmit = 0; //upload&rev: =1 + $form->resubmit = 1; // allow deleting } if (empty($form->maxbytes)) { $form->maxbytes = $CFG->assignment_maxbytes; } if (empty($form->emailteachers)) { - $form->emailteachers = ''; - } - //allow multiple files (from new upload type) - if (empty($form->var1)) { - $form->var1 = 0; + $form->emailteachers = 0; } - //email to students (from upload&review) - if (empty($form->var2)) { - $form->var2 = ''; - } - ?> @@ -30,24 +27,39 @@ ?> + - + + + + + + - + @@ -55,24 +67,13 @@ - - - -
:: get_string("no"), 1=>get_string("yes")); + choose_from_menu($options, "resubmit", $form->resubmit, ""); + helpbutton("allowdeleting", get_string("allowdeleting", "assignment"), "assignment"); + ?> +
: + var1, ""); + helpbutton("allowmaxfiles", get_string("allowmaxfiles", "assignment"), "assignment"); ?>
:: - resubmit, ""); //that's how it's un U&R - // choose_from_menu($options, "var2", $form->var2, ""); - helpbutton("resubmit", get_string("allowresubmit", "assignment"), "assignment"); + get_string("no"), 1=>get_string("yes")); + choose_from_menu($options, "var2", $form->var2, ""); + helpbutton("allownotes", get_string("allownotes", "assignment"), "assignment"); ?>
: - get_string("no"), 1=>get_string("yes")); choose_from_menu($options, "emailteachers", $form->emailteachers, ""); helpbutton("emailteachers", get_string("emailteachers", "assignment"), "assignment"); ?>
: - var2, ""); - // choose_from_menu($options, "emailstudents", $form->emailstudents, ""); - helpbutton("emailstudents", get_string("emailstudents", "assignment"), "assignment"); - ?> -
diff --git a/mod/assignment/type/upload/notes.php b/mod/assignment/type/upload/notes.php new file mode 100644 index 0000000000..0887c9eb74 --- /dev/null +++ b/mod/assignment/type/upload/notes.php @@ -0,0 +1,65 @@ +instance)) { + error("Assignment ID was incorrect"); + } + + if (! $course = get_record('course', 'id', $assignment->course)) { + error("Course is misconfigured"); + } + + if (! $user = get_record('user', 'id', $userid)) { + error("User is misconfigured"); + } + + require_login($course->id, false, $cm); + + if (!has_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $cm->id))) { + error("You can not view this assignment"); + } + + if ($assignment->assignmenttype != 'upload') { + error("Incorrect assignment type"); + } + + $assignmentinstance = new assignment_upload($cm->id, $assignment, $cm, $course); + + $returnurl = "../../submissions.php?id={$assignmentinstance->cm->id}&userid=$userid&offset=$offset&mode=single"; + + if ($submission = $assignmentinstance->get_submission($user->id) + and !empty($submission->data1)) { + print_header(fullname($user,true).': '.$assignment->name); + print_heading(get_string('notes', 'assignment').' - '.fullname($user,true)); + print_simple_box(format_text($submission->data1, FORMAT_HTML), 'center', '100%'); + if ($mode != 'single') { + close_window_button(); + } else { + print_continue($returnurl); + } + print_footer('none'); + } else { + print_header(fullname($user,true).': '.$assignment->name); + print_heading(get_string('notes', 'assignment').' - '.fullname($user,true)); + print_simple_box(get_string('notesempty', 'assignment'), 'center', '100%'); + if ($mode != 'single') { + close_window_button(); + } else { + print_continue($returnurl); + } + print_footer('none'); + } + +?> diff --git a/mod/assignment/version.php b/mod/assignment/version.php index 7e5557cb82..6b1a134597 100644 --- a/mod/assignment/version.php +++ b/mod/assignment/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2006092100; +$module->version = 2006092800; $module->requires = 2006080900; // Requires this Moodle version $module->cron = 60; -- 2.39.5