diff -Naur -b moodle_assignment_work_1.9.4_Pure/lang/en_utf8/assignment.php moodle_assignment_work_1.9.4_Modified/lang/en_utf8/assignment.php --- moodle_assignment_work_1.9.4_Pure/lang/en_utf8/assignment.php 2008-02-28 10:15:14.000000000 +0000 +++ moodle_assignment_work_1.9.4_Modified/lang/en_utf8/assignment.php 2009-04-23 15:43:50.000000000 +0100 @@ -21,6 +21,8 @@ assignment submission for \'$a->assignment\'

You can see it appended to your url\">assignment submission.'; $string['assignmentname'] = 'Assignment name'; +$string['assignmenttemplatefile'] = 'Assignment template location'; +$string['assignmenttemplatetext'] = 'Assignment template text'; $string['assignmenttype'] = 'Assignment type'; $string['availabledate'] = 'Available from'; $string['cannotdeletefiles'] = 'An error occurred and files could not be deleted'; diff -Naur -b moodle_assignment_work_1.9.4_Pure/lang/en_utf8/help/assignment/template.html moodle_assignment_work_1.9.4_Modified/lang/en_utf8/help/assignment/template.html --- moodle_assignment_work_1.9.4_Pure/lang/en_utf8/help/assignment/template.html 1970-01-01 01:00:00.000000000 +0100 +++ moodle_assignment_work_1.9.4_Modified/lang/en_utf8/help/assignment/template.html 2009-04-24 09:45:24.000000000 +0100 @@ -0,0 +1,8 @@ +

Assignment Templates

+ +

This optional feature lets you upload a document for students. This might be a front + sheet, a quiz sheet, an example document or a zip file of many resources.

+ +

The template text box specifies the name the file have when students see it.

+ +

The template location box is the location of the file. Use the 'Choose or upload a file' button to set this.

diff -Naur -b moodle_assignment_work_1.9.4_Pure/mod/assignment/backuplib.php moodle_assignment_work_1.9.4_Modified/mod/assignment/backuplib.php --- moodle_assignment_work_1.9.4_Pure/mod/assignment/backuplib.php 2006-09-22 10:02:08.000000000 +0100 +++ moodle_assignment_work_1.9.4_Modified/mod/assignment/backuplib.php 2009-04-23 15:52:54.000000000 +0100 @@ -73,6 +73,8 @@ fwrite ($bf,full_tag("TIMEAVAILABLE",4,false,$assignment->timeavailable)); fwrite ($bf,full_tag("GRADE",4,false,$assignment->grade)); fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$assignment->timemodified)); + fwrite ($bf,full_tag("TEMPLATETEXT",4,false,$assignment->templatetext)); + fwrite ($bf,full_tag("TEMPLATEFILE",4,false,$assignment->templatefile)); //if we've selected to backup users info, then execute backup_assignment_submisions and //backup_assignment_files_instance if (backup_userdata_selected($preferences,'assignment',$assignment->id)) { @@ -81,12 +83,48 @@ $status = backup_assignment_files_instance($bf,$preferences,$assignment->id); } } + if ($assignment->templatefile != '') { + if ($status) { + $status = backup_template_file($assignment->templatefile,$preferences); + } + } //End mod $status =fwrite ($bf,end_tag("MOD",3,true)); return $status; } + //Backup the assignment template file, which may just be a regular file as storing in + //mod/assignment would force duplication of files + function backup_template_file ($filelocation,$preferences) { + + global $CFG; + + $status = true; + + $intPos = 0; + $intLastPos = 0; + $intCount = 0; + + $status = check_dir_exists($CFG->dataroot.'/temp/backup/'.$preferences->backup_unique_code.'/', true); + + while ($status) { + $intPos = strpos($filelocation, '/', $intLastPos); + if ($intPos == 0 || $intCount > 20) { + break; + } + $strDirs = substr($filelocation, 0, strpos($filelocation, '/', $intPos) + 1); + $status = check_dir_exists($CFG->dataroot."/temp/backup/".$preferences->backup_unique_code.'/'.$strDirs, true); + $intLastPos = $intPos+1; + $intCount = $intCount + 1; + } + + if ($status) { + $status = backup_copy_file($CFG->dataroot."/".$preferences->backup_course."/".$filelocation, $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code.'/'.$filelocation); + } + return $status; + } + //Backup assignment_submissions contents (executed from assignment_backup_mods) function backup_assignment_submissions ($bf,$preferences,$assignment) { diff -Naur -b moodle_assignment_work_1.9.4_Pure/mod/assignment/db/install.xml moodle_assignment_work_1.9.4_Modified/mod/assignment/db/install.xml --- moodle_assignment_work_1.9.4_Pure/mod/assignment/db/install.xml 2007-09-25 10:11:28.000000000 +0100 +++ moodle_assignment_work_1.9.4_Modified/mod/assignment/db/install.xml 2009-04-23 15:46:06.000000000 +0100 @@ -1,5 +1,5 @@ - @@ -24,7 +24,9 @@ - + + + diff -Naur -b moodle_assignment_work_1.9.4_Pure/mod/assignment/db/upgrade.php moodle_assignment_work_1.9.4_Modified/mod/assignment/db/upgrade.php --- moodle_assignment_work_1.9.4_Pure/mod/assignment/db/upgrade.php 2008-05-02 08:16:50.000000000 +0100 +++ moodle_assignment_work_1.9.4_Modified/mod/assignment/db/upgrade.php 2009-04-23 16:09:30.000000000 +0100 @@ -59,6 +59,16 @@ $db->debug = true; } +//===== 1.9.3 upgrade line ======// + if ($result && $oldversion < 2009031213) { + $sql = "ALTER TABLE {$CFG->prefix}assignment ADD COLUMN templatetext varchar(100) NULL"; + $result = execute_sql($sql); + + $sql = "ALTER TABLE {$CFG->prefix}assignment ADD COLUMN templatefile varchar(255) NULL"; + $result = execute_sql($sql); + notify('Updating assignments', 'notifysuccess'); + } + return $result; } diff -Naur -b moodle_assignment_work_1.9.4_Pure/mod/assignment/lib.php moodle_assignment_work_1.9.4_Modified/mod/assignment/lib.php --- moodle_assignment_work_1.9.4_Pure/mod/assignment/lib.php 2009-02-17 07:05:38.000000000 +0000 +++ moodle_assignment_work_1.9.4_Modified/mod/assignment/lib.php 2009-04-23 15:49:02.000000000 +0100 @@ -154,10 +154,24 @@ * The default implementation prints the assignment description in a box */ function view_intro() { + global $CFG; + print_simple_box_start('center', '', '', 0, 'generalbox', 'intro'); $formatoptions = new stdClass; $formatoptions->noclean = true; echo format_text($this->assignment->description, $this->assignment->format, $formatoptions); + + /* See if we can get a filename for assignment documents - redmorris 20090423 + * If we get one then display a link to the file with the description given and appropriate icon */ + if ($this->assignment->templatefile != '') { + $filename = $CFG->wwwroot.'/file.php/'.$this->course->id.'/'.$this->assignment->templatefile; + $filedescription = $this->assignment->templatetext; + if ($filedescription == '') { + $filedescription = get_string('assignmenttemplatetextdefault','assignment'); + } + $icon = mimeinfo('icon', substr(strrchr($filename, '/'),1)); + echo ''.get_string('file').' '.$filedescription.''; + } print_simple_box_end(); } diff -Naur -b moodle_assignment_work_1.9.4_Pure/mod/assignment/restorelib.php moodle_assignment_work_1.9.4_Modified/mod/assignment/restorelib.php --- moodle_assignment_work_1.9.4_Pure/mod/assignment/restorelib.php 2008-12-12 07:03:28.000000000 +0000 +++ moodle_assignment_work_1.9.4_Modified/mod/assignment/restorelib.php 2009-04-23 15:56:42.000000000 +0100 @@ -1,4 +1,4 @@ -timeavailable = backup_todb($info['MOD']['#']['TIMEAVAILABLE']['0']['#']); $assignment->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']); $assignment->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); + $assignment->templatetext = backup_todb($info['MOD']['#']['TEMPLATETEXT']['0']['#']); + $assignment->templatefile = backup_todb($info['MOD']['#']['TEMPLATEFILE']['0']['#']); + + if ($assignment->templatefile != '') { + $status = restore_template_file($assignment->templatefile, $restore); + } //We have to recode the grade field if it is <0 (scale) if ($assignment->grade < 0) { @@ -120,6 +126,35 @@ return $status; } + function restore_template_file($filelocation, $restore) { + + global $CFG; + $status = true; + + $intPos = 0; + $intLastPos = 0; + $intCount = 0; + + $status = check_dir_exists($CFG->dataroot.'/'.$restore->course_id, true); + + while ($status) { + $intPos = strpos($filelocation, '/', $intLastPos); + if ($intPos == 0 || $intCount > 20) { + break; + } + $strDirs = substr($filelocation, 0, strpos($filelocation, '/', $intPos) + 1); + $status = check_dir_exists($CFG->dataroot.'/'.$restore->course_id.'/'.$strDirs, true); + $intLastPos = $intPos+1; + $intCount = $intCount + 1; + } + + if ($status) { + $status = backup_copy_file($CFG->dataroot."/temp/backup/".$restore->backup_unique_code.'/'.$filelocation, $CFG->dataroot."/".$restore->course_id."/".$filelocation); + } + + return $status; + } + //This function restores the assignment_submissions function assignment_submissions_restore_mods($old_assignment_id, $new_assignment_id,$info,$restore) { diff -Naur -b moodle_assignment_work_1.9.4_Pure/mod/assignment/type/upload/assignment.class.php moodle_assignment_work_1.9.4_Modified/mod/assignment/type/upload/assignment.class.php --- moodle_assignment_work_1.9.4_Pure/mod/assignment/type/upload/assignment.class.php 2008-10-10 08:19:46.000000000 +0100 +++ moodle_assignment_work_1.9.4_Modified/mod/assignment/type/upload/assignment.class.php 2009-04-24 09:43:14.000000000 +0100 @@ -1019,6 +1019,11 @@ $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes')); + $mform->addElement('text', 'templatetext', get_string('assignmenttemplatetext', 'assignment'), array('size'=>'64')); + $mform->setHelpButton('templatetext', array('template', get_string('assignmenttemplatetext', 'assignment'), 'assignment')); + $mform->addElement('choosecoursefile', 'templatefile', get_string('assignmenttemplatefile', 'assignment')); + $mform->setHelpButton('templatefile', array('template', get_string('assignmenttemplatefile', 'assignment'), 'assignment')); + $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes); $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')'; $mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $choices); diff -Naur -b moodle_assignment_work_1.9.4_Pure/mod/assignment/type/uploadsingle/assignment.class.php moodle_assignment_work_1.9.4_Modified/mod/assignment/type/uploadsingle/assignment.class.php --- moodle_assignment_work_1.9.4_Pure/mod/assignment/type/uploadsingle/assignment.class.php 2008-04-09 08:16:44.000000000 +0100 +++ moodle_assignment_work_1.9.4_Modified/mod/assignment/type/uploadsingle/assignment.class.php 2009-04-24 09:44:14.000000000 +0100 @@ -165,6 +165,11 @@ $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes')); + $mform->addElement('text', 'templatetext', get_string('assignmenttemplatetext', 'assignment'), array('size'=>'64')); + $mform->setHelpButton('templatetext', array('template', get_string('assignmenttemplatetext', 'assignment'), 'assignment')); + $mform->addElement('choosecoursefile', 'templatefile', get_string('assignmenttemplatefile', 'assignment')); + $mform->setHelpButton('templatefile', array('template', get_string('assignmenttemplatefile', 'assignment'), 'assignment')); + $mform->addElement('select', 'resubmit', get_string("allowresubmit", "assignment"), $ynoptions); $mform->setHelpButton('resubmit', array('resubmit', get_string('allowresubmit', 'assignment'), 'assignment')); $mform->setDefault('resubmit', 0); diff -Naur -b moodle_assignment_work_1.9.4_Pure/mod/assignment/version.php moodle_assignment_work_1.9.4_Modified/mod/assignment/version.php --- moodle_assignment_work_1.9.4_Pure/mod/assignment/version.php 2008-03-20 10:14:02.000000000 +0000 +++ moodle_assignment_work_1.9.4_Modified/mod/assignment/version.php 2009-04-23 15:37:58.000000000 +0100 @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2007101511; +$module->version = 2009042301; $module->requires = 2007101509; // Requires this Moodle version $module->cron = 60; diff -Naur -b moodle_assignment_work_1.9.4_Pure/mod/assignment/view.php moodle_assignment_work_1.9.4_Modified/mod/assignment/view.php --- moodle_assignment_work_1.9.4_Pure/mod/assignment/view.php 2007-08-18 10:06:24.000000000 +0100 +++ moodle_assignment_work_1.9.4_Modified/mod/assignment/view.php 2009-04-23 15:49:42.000000000 +0100 @@ -2,6 +2,7 @@ require_once("../../config.php"); require_once("lib.php"); + require_once("../../lib/filelib.php"); $id = optional_param('id', 0, PARAM_INT); // Course Module ID $a = optional_param('a', 0, PARAM_INT); // Assignment ID