From b0f2597e1716dfc6f32654ecf049384d3f5de603 Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 14 Apr 2005 13:24:40 +0000 Subject: [PATCH] Refactored Assignment Module ============================ This new assignment module allows Plugin Assignment types. This should allow a whole lot of new stuff to easily be placed in Moodle without making the modules list longer for no good reason. This checkin is still a really rough version that needs work on it. Normally I would want it better than this to check in, but I need to collaborate with Shane on the remaining code and CVS is the best way. Give it a day or two to settle in. :-) This is the last thing I wanted to get into 1.5. Getting close now!! Cheers! Martin --- mod/assignment/backuplib.php | 2 +- mod/assignment/config.html | 11 +- mod/assignment/db/mysql.php | 19 +- mod/assignment/db/mysql.sql | 3 +- mod/assignment/db/postgres7.php | 18 +- mod/assignment/db/postgres7.sql | 3 +- mod/assignment/details.php | 40 + mod/assignment/index.php | 31 +- mod/assignment/lib.php | 1487 ++++++++--------- mod/assignment/mod.html | 129 +- mod/assignment/plan.txt | 48 + mod/assignment/restorelib.php | 9 + mod/assignment/styles.php | 8 + mod/assignment/submissions.php | 207 +-- mod/assignment/type/common.html | 26 + mod/assignment/type/common_end.html | 1 + .../type/offline/assignment.class.php | 48 + mod/assignment/type/offline/mod.html | 3 + mod/assignment/type/postdata.html | 26 + .../type/uploadsingle/assignment.class.php | 55 + mod/assignment/type/uploadsingle/mod.html | 3 + mod/assignment/upload.php | 4 +- mod/assignment/version.php | 4 +- mod/assignment/view.php | 131 +- 24 files changed, 1111 insertions(+), 1205 deletions(-) create mode 100644 mod/assignment/details.php create mode 100644 mod/assignment/plan.txt create mode 100644 mod/assignment/styles.php create mode 100644 mod/assignment/type/common.html create mode 100644 mod/assignment/type/common_end.html create mode 100644 mod/assignment/type/offline/assignment.class.php create mode 100644 mod/assignment/type/offline/mod.html create mode 100644 mod/assignment/type/postdata.html create mode 100644 mod/assignment/type/uploadsingle/assignment.class.php create mode 100644 mod/assignment/type/uploadsingle/mod.html diff --git a/mod/assignment/backuplib.php b/mod/assignment/backuplib.php index f7a9fbd279a..bffd08e4bb7 100644 --- a/mod/assignment/backuplib.php +++ b/mod/assignment/backuplib.php @@ -42,7 +42,7 @@ fwrite ($bf,full_tag("FORMAT",4,false,$assignment->format)); fwrite ($bf,full_tag("RESUBMIT",4,false,$assignment->resubmit)); fwrite ($bf,full_tag("EMAILTEACHERS",4,false,$assignment->emailteachers)); - fwrite ($bf,full_tag("TYPE",4,false,$assignment->type)); + fwrite ($bf,full_tag("ASSIGNMENTTYPE",4,false,$assignment->assignmenttype)); fwrite ($bf,full_tag("MAXBYTES",4,false,$assignment->maxbytes)); fwrite ($bf,full_tag("TIMEDUE",4,false,$assignment->timedue)); fwrite ($bf,full_tag("GRADE",4,false,$assignment->grade)); diff --git a/mod/assignment/config.html b/mod/assignment/config.html index 79fe9dbfe5b..26248960d46 100644 --- a/mod/assignment/config.html +++ b/mod/assignment/config.html @@ -1,9 +1,8 @@
- - - - +
assignment_maxbytes:
+ + - +

assignment_maxbytes:

maxbytes); choose_from_menu ($choices, "assignment_maxbytes", $CFG->assignment_maxbytes, ""); @@ -15,8 +14,8 @@
- " /> + ">
diff --git a/mod/assignment/db/mysql.php b/mod/assignment/db/mysql.php index af4615944dc..ba8c5ea79e5 100644 --- a/mod/assignment/db/mysql.php +++ b/mod/assignment/db/mysql.php @@ -113,16 +113,25 @@ function assignment_upgrade($oldversion) { modify_database('','ALTER TABLE prefix_assignment_submissions ADD INDEX timemarked (timemarked);'); } - if ($oldversion < 2005010500) { + if ($oldversion < 2005010500) { // New field for sending out mail to teachers table_column('assignment', '', 'emailteachers', 'integer', '2', 'unsigned', 0, 'not null', 'resubmit'); } - if ($oldversion < 2005041100) { // replace wiki-like with markdown - include_once( "$CFG->dirroot/lib/wiki_to_markdown.php" ); - $wtm = new WikiToMarkdown(); - $wtm->update( 'assignment','description','format' ); + if ($oldversion < 2005022202) { // Add new fields for the new refactored version of assignment + table_column('assignment', '', 'timeavailable', 'integer', '10', 'unsigned', 0, 'not null', 'timedue'); + table_column('assignment', '', 'assignmenttype', 'varchar', '50', '', '', 'not null', 'format'); + execute_sql("UPDATE {$CFG->prefix}assignment SET assignmenttype = 'offline' WHERE type = '0';"); + execute_sql("UPDATE {$CFG->prefix}assignment SET assignmenttype = 'uploadsingle' WHERE type = '1';"); + execute_sql('ALTER TABLE '.$CFG->prefix.'assignment DROP type;'); } + + + +/// These lines ALWAYS need to be here at the end of this file. Don't mess with them. :-) + include_once("$CFG->dirroot/mod/assignment/lib.php"); + assignment_upgrade_submodules(); + return true; } diff --git a/mod/assignment/db/mysql.sql b/mod/assignment/db/mysql.sql index ac7608f0154..941748e2ffb 100644 --- a/mod/assignment/db/mysql.sql +++ b/mod/assignment/db/mysql.sql @@ -8,11 +8,12 @@ CREATE TABLE `prefix_assignment` ( `name` varchar(255) NOT NULL default '', `description` text NOT NULL, `format` tinyint(2) unsigned NOT NULL default '0', + `assignmenttype` varchar(50) NOT NULL default '', `resubmit` tinyint(2) unsigned NOT NULL default '0', `emailteachers` tinyint(2) unsigned NOT NULL default '0', - `type` int(10) unsigned NOT NULL default '1', `maxbytes` int(10) unsigned NOT NULL default '100000', `timedue` int(10) unsigned NOT NULL default '0', + `timeavailable` int(10) unsigned NOT NULL default '0', `grade` int(10) NOT NULL default '0', `timemodified` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`), diff --git a/mod/assignment/db/postgres7.php b/mod/assignment/db/postgres7.php index 859fe890f4c..1d0b3f3cd2d 100644 --- a/mod/assignment/db/postgres7.php +++ b/mod/assignment/db/postgres7.php @@ -115,12 +115,22 @@ function assignment_upgrade($oldversion) { table_column('assignment', '', 'emailteachers', 'integer', '2', 'unsigned', 0, 'not null', 'resubmit'); } - if ($oldversion < 2005041100) { // replace wiki-like with markdown - include_once( "$CFG->dirroot/lib/wiki_to_markdown.php" ); - $wtm = new WikiToMarkdown(); - $wtm->update( 'assignment','description','format' ); + if ($oldversion < 2005022202) { // Add new fields for the new refactored version of assignment + table_column('assignment', '', 'timeavailable', 'integer', '10', 'unsigned', 0, 'not null', 'timedue'); + table_column('assignment', '', 'assignmenttype', 'varchar', '50', '', '', 'not null', 'format'); + execute_sql("UPDATE {$CFG->prefix}assignment SET assignmenttype = 'offline' WHERE type = '0';",false); + execute_sql("UPDATE {$CFG->prefix}assignment SET assignmenttype = 'uploadsingle' WHERE type = '1';",false); + execute_sql('ALTER TABLE '.$CFG->prefix.'assignment DROP type;'); } + + + + +/// These lines ALWAYS need to be here at the end of this file. Don't mess with them. :-) + include_once("$CFG->dirroot/mod/assignment/lib.php"); + assignment_upgrade_submodules(); + return true; } diff --git a/mod/assignment/db/postgres7.sql b/mod/assignment/db/postgres7.sql index 7d57ce7cdd1..3e2948694c0 100644 --- a/mod/assignment/db/postgres7.sql +++ b/mod/assignment/db/postgres7.sql @@ -8,11 +8,12 @@ CREATE TABLE prefix_assignment ( name varchar(255) NOT NULL default '', description text NOT NULL default '', format integer NOT NULL default '0', + assignmenttype varchar(50) NOT NULL default '', resubmit integer NOT NULL default '0', emailteachers integer NOT NULL default '0', - type integer NOT NULL default '1', maxbytes integer NOT NULL default '100000', timedue integer NOT NULL default '0', + timeavailable integer NOT NULL default '0', grade integer NOT NULL default '0', timemodified integer NOT NULL default '0' ); diff --git a/mod/assignment/details.php b/mod/assignment/details.php new file mode 100644 index 00000000000..d83408004c3 --- /dev/null +++ b/mod/assignment/details.php @@ -0,0 +1,40 @@ +course)) { + error("Non-existent course!"); + } + + require_login($course->id); + + if (!isteacheredit($course->id)) { + redirect($CFG->wwwroot.'/course/view.php?id='.$course->id); + } + +/// Set up things for a HTML editor if it's needed + + if ($usehtmleditor = can_use_html_editor()) { + $defaultformat = FORMAT_HTML; + $editorfields = ''; + } else { + $defaultformat = FORMAT_MOODLE; + } + + require_once("$CFG->dirroot/mod/assignment/type/$form->assignmenttype/assignment.class.php"); + + $assignmentclass = "assignment_$form->assignmenttype"; + + $assignmentinstance = new $assignmentclass(); + + echo $assignmentinstance->setup($form); /// The actual form is all printed here + + +?> diff --git a/mod/assignment/index.php b/mod/assignment/index.php index 5be03e06f2a..2c22b8be008 100644 --- a/mod/assignment/index.php +++ b/mod/assignment/index.php @@ -52,35 +52,20 @@ $currentsection = ""; foreach ($assignments as $assignment) { - $submitted = get_string("no"); - if (isteacher($course->id)) { - if ($assignment->type == OFFLINE) { - $submitted = "id\">" . - get_string("viewfeedback", "assignment") . ""; - } else { - $count = assignment_count_real_submissions($assignment, $currentgroup); - $submitted = "id\">" . - get_string("viewsubmissions", "assignment", $count) . "$groupname"; - } - } else { - if (isset($USER->id)) { - if ($submission = assignment_get_submission($assignment, $USER)) { - if ($submission->timemodified <= $assignment->timedue) { - $submitted = userdate($submission->timemodified); - } else { - $submitted = "".userdate($submission->timemodified).""; - } - } - } - } + + require_once ($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php'); + $assignmentclass = 'assignment_'.$assignment->assignmenttype; + $assignmentinstance = new $assignmentclass($assignment->coursemodule); + + $submitted = $assignmentinstance->submittedlink(); $due = userdate($assignment->timedue); if (!$assignment->visible) { //Show dimmed if the mod is hidden - $link = "coursemodule\">".format_string($assignment->name,true).""; + $link = "coursemodule\">$assignment->name"; } else { //Show normal if the mod is visible - $link = "coursemodule\">".format_string($assignment->name,true).""; + $link = "coursemodule\">$assignment->name"; } $printsection = ""; diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 6744deed5b8..a04ea21f6fd 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -1,890 +1,783 @@ -libdir.'/filelib.php'); - -define("OFFLINE", "0"); -define("UPLOADSINGLE", "1"); - -$ASSIGNMENT_TYPE = array (OFFLINE => get_string("typeoffline", "assignment"), - UPLOADSINGLE => get_string("typeuploadsingle", "assignment") ); if (!isset($CFG->assignment_maxbytes)) { set_config("assignment_maxbytes", 1024000); // Default maximum size for all assignments -} - - -function assignment_add_instance($assignment) { -// Given an object containing all the necessary data, -// (defined by the form in mod.html) this function -// will create a new instance and return the id number -// of the new instance. - - $assignment->timemodified = time(); - - $assignment->timedue = make_timestamp($assignment->dueyear, $assignment->duemonth, $assignment->dueday, - $assignment->duehour, $assignment->dueminute); - - if ($returnid = insert_record("assignment", $assignment)) { - - $event = NULL; - $event->name = $assignment->name; - $event->description = $assignment->description; - $event->courseid = $assignment->course; - $event->groupid = 0; - $event->userid = 0; - $event->modulename = 'assignment'; - $event->instance = $returnid; - $event->eventtype = 'due'; - $event->timestart = $assignment->timedue; - $event->timeduration = 0; - - add_event($event); - } - - return $returnid; } -function assignment_update_instance($assignment) { -// Given an object containing all the necessary data, -// (defined by the form in mod.html) this function -// will update an existing instance with new data. +/* + * Standard base class for all assignment submodules (assignment types). + * + * + */ +class assignment_base { - $assignment->timemodified = time(); - $assignment->timedue = make_timestamp($assignment->dueyear, $assignment->duemonth, $assignment->dueday, - $assignment->duehour, $assignment->dueminute); - $assignment->id = $assignment->instance; + var $cm; + var $course; + var $assignment; + /** + * Constructor for the base assignment class + * + * Constructor for the base assignment class. + * If cmid is set create the cm, course, assignment objects. + * + * @param cmid integer, the current course module id - not set for new assignments + */ + function assignment_base($cmid=0) { - if ($returnid = update_record("assignment", $assignment)) { + global $CFG; - $event = NULL; + if ($cmid) { + if (! $this->cm = get_record("course_modules", "id", $cmid)) { + error("Course Module ID was incorrect"); + } - if ($event->id = get_field('event', 'id', 'modulename', 'assignment', 'instance', $assignment->id)) { + if (! $this->course = get_record("course", "id", $this->cm->course)) { + error("Course is misconfigured"); + } - $event->name = $assignment->name; - $event->description = $assignment->description; - $event->timestart = $assignment->timedue; + if (! $this->assignment = get_record("assignment", "id", $this->cm->instance)) { + error("assignment ID was incorrect"); + } + + $this->strassignment = get_string('modulename', 'assignment'); + $this->strassignments = get_string('modulenameplural', 'assignment'); + $this->strsubmissions = get_string('submissions', 'assignment'); + $this->strlastmodified = get_string('lastmodified'); + + if ($this->course->category) { + $this->navigation = "framename}\" href=\"$CFG->wwwroot/course/view.php?id={$this->course->id}\">{$this->course->shortname} -> ". + "framename}\" href=\"index.php?id={$this->course->id}\">$this->strassignments ->"; + } else { + $this->navigation = "framename}\" href=\"index.php?id={$this->course->id}\">$this->strassignments ->"; + } + + $this->pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment.': '.$this->assignment->name); + + if (!$this->cm->visible and !isteacher($this->course->id)) { + $pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment); + print_header($pagetitle, $this->course->fullname, "$this->navigation $this->strassignment", + "", "", true, '', navmenu($this->course, $this->cm)); + notice(get_string("activityiscurrentlyhidden"), "$CFG->wwwroot/course/view.php?id={$this->course->id}"); + } + + $this->currentgroup = get_current_group($this->course->id); - update_event($event); } } - return $returnid; -} + /* + * Display the assignment to students (sub-modules will most likely override this) + */ + function view() { + global $CFG; -function assignment_delete_instance($id) { -// Given an ID of an instance of this module, -// this function will permanently delete the instance -// and any data that depends on it. + add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", + $this->assignment->id, $this->cm->id); - if (! $assignment = get_record("assignment", "id", "$id")) { - return false; - } + print_header($this->pagetitle, $this->course->fullname, $this->navigation.' '.$this->assignment->name, '', '', + true, update_module_button($this->cm->id, $this->course->id, $this->strassignment), + navmenu($this->course, $this->cm)); - $result = true; + echo ''; - if (! delete_records("assignment_submissions", "assignment", "$assignment->id")) { - $result = false; - } + print_simple_box_start('center'); + echo format_text($this->assignment->description, $this->assignment->format); + print_simple_box_end(); - if (! delete_records("assignment", "id", "$assignment->id")) { - $result = false; - } - - if (! delete_records('event', 'modulename', 'assignment', 'instance', $assignment->id)) { - $result = false; - } - - return $result; -} - -function assignment_refresh_events($courseid = 0) { -// This standard function will check all instances of this module -// and make sure there are up-to-date events created for each of them. -// If courseid = 0, then every assignment event in the site is checked, else -// only assignment events belonging to the course specified are checked. -// This function is used, in its new format, by restore_refresh_events() - - if ($courseid == 0) { - if (! $assignments = get_records("assignment")) { - return true; - } - } else { - if (! $assignments = get_records("assignment", "course", $courseid)) { - return true; - } - } - $moduleid = get_field('modules', 'id', 'name', 'assignment'); - - foreach ($assignments as $assignment) { - $event = NULL; - $event->name = addslashes($assignment->name); - $event->description = addslashes($assignment->description); - $event->timestart = $assignment->timedue; - - if ($event->id = get_field('event', 'id', 'modulename', 'assignment', 'instance', $assignment->id)) { - update_event($event); - - } else { - $event->courseid = $assignment->course; - $event->groupid = 0; - $event->userid = 0; - $event->modulename = 'assignment'; - $event->instance = $assignment->id; - $event->eventtype = 'due'; - $event->timeduration = 0; - $event->visible = get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $assignment->id); - add_event($event); - } - - } - return true; -} - - -function assignment_user_outline($course, $user, $mod, $assignment) { - if ($submission = assignment_get_submission($assignment, $user)) { + print_simple_box_start('center', '', '', '', 'time'); + echo ''; + echo ''; + echo ' '; + echo ''; + echo ' '; + echo '
'.get_string('availabledate','assignment').':'.userdate($this->assignment->timeavailable).'
'.get_string('duedate','assignment').':'.userdate($this->assignment->timedue).'
'; - if ($submission->grade) { - $result->info = get_string("grade").": $submission->grade"; - } - $result->time = $submission->timemodified; - return $result; - } - return NULL; -} + print_simple_box_end(); -function assignment_user_complete($course, $user, $mod, $assignment) { - if ($submission = assignment_get_submission($assignment, $user)) { - if ($basedir = assignment_file_area($assignment, $user)) { - if ($files = get_directory_list($basedir)) { - $countfiles = count($files)." ".get_string("uploadedfiles", "assignment"); - foreach ($files as $file) { - $countfiles .= "; $file"; - } + $this->view_feedback(); + + print_footer($this->course); + } + + + function view_feedback() { + global $USER; + + /// Get submission for this assignment + /// If no submission then just return quietly + $submission = $this->get_submission($USER->id); + if (empty($submission->timemarked)) { + return; + } + + /// We need the teacher info + if (! $teacher = get_record('user', 'id', $submission->teacher)) { + print_object($submission); + error('Could not find the teacher'); + } + + /// Print the feedback + echo ''; + + echo ''; + echo ''; + echo ''; + echo ''; + + echo ''; + echo ''; + echo ''; + + echo ''; + } + + + + /* + * Print the start of the setup form for the current assignment type + */ + function setup(&$form, $action='') { + global $CFG, $THEME; + + if (empty($this->course)) { + if (! $this->course = get_record("course", "id", $form->course)) { + error("Course is misconfigured"); } } - - print_simple_box_start(); - echo get_string("lastmodified").": "; - echo userdate($submission->timemodified); - echo assignment_print_difference($assignment->timedue - $submission->timemodified); - - assignment_print_user_files($assignment, $user); - - echo "
"; - - if (empty($submission->timemarked)) { - print_string("notgradedyet", "assignment"); - } else { - assignment_print_feedback($course, $submission, $assignment); + if (empty($action)) { // Default destination for this form + $action = $CFG->wwwroot.'/course/mod.php'; } + if (empty($form->name)) { + $form->name = ""; + } + if (empty($form->assignmenttype)) { + $form->assignmenttype = ""; + } + if (empty($form->description)) { + $form->description = ""; + } + + $strname = get_string('name'); + $strassignments = get_string('modulenameplural', 'assignment'); + $strheading = empty($form->name) ? get_string("type$form->assignmenttype",'assignment') : $form->name; + + print_header($this->course->shortname.': '.$strheading, "$strheading", + "wwwroot/course/view.php?id={$this->course->id}\">{$this->course->shortname} -> ". + "wwwroot/mod/assignment/index.php?id={$this->course->id}\">$strassignments -> $strheading"); + + print_simple_box_start("center"); + print_heading(get_string("type$form->assignmenttype",'assignment')); + include("$CFG->dirroot/mod/assignment/type/common.html"); + } + + /* + * Print the end of the setup form for the current assignment type + */ + function setup_end() { + global $CFG, $usehtmleditor; + + include($CFG->dirroot.'/mod/assignment/type/common_end.html'); + print_simple_box_end(); - } else { - print_string("notsubmittedyet", "assignment"); - } -} - - -function assignment_cron () { -// Function to be run periodically according to the moodle cron -// Finds all assignment notifications that have yet to be mailed out, and mails them - - global $CFG, $USER; - - /// Notices older than 1 day will not be mailed. This is to avoid the problem where - /// cron has not been running for a long time, and then suddenly people are flooded - /// with mail from the past few weeks or months - - $timenow = time(); - $endtime = $timenow - $CFG->maxeditingtime; - $starttime = $endtime - 24 * 3600; /// One day earlier - - if ($submissions = assignment_get_unmailed_submissions($starttime, $endtime)) { - - foreach ($submissions as $key => $submission) { - if (! set_field("assignment_submissions", "mailed", "1", "id", "$submission->id")) { - echo "Could not update the mailed field for id $submission->id. Not mailed.\n"; - unset($submissions[$key]); - } + if ($usehtmleditor) { + use_html_editor(); } - $timenow = time(); + print_footer($this->course); + } - foreach ($submissions as $submission) { - echo "Processing assignment submission $submission->id\n"; + function add_instance($assignment) { + // Given an object containing all the necessary data, + // (defined by the form in mod.html) this function + // will create a new instance and return the id number + // of the new instance. - if (! $user = get_record("user", "id", "$submission->userid")) { - echo "Could not find user $post->userid\n"; - continue; + $assignment->timemodified = time(); + $assignment->timedue = make_timestamp($assignment->dueyear, $assignment->duemonth, + $assignment->dueday, $assignment->duehour, + $assignment->dueminute); + $assignment->timeavailable = make_timestamp($assignment->availableyear, $assignment->availablemonth, + $assignment->availableday, $assignment->availablehour, + $assignment->availableminute); + + return insert_record("assignment", $assignment); + } + + function delete_instance($assignment) { + if (! delete_records("assignment", "id", "$assignment->id")) { + $result = false; + } + return $result; + } + + function update_instance($assignment) { + // Given an object containing all the necessary data, + // (defined by the form in mod.html) this function + // will create a new instance and return the id number + // of the new instance. + + $assignment->timemodified = time(); + $assignment->timedue = make_timestamp($assignment->dueyear, $assignment->duemonth, + $assignment->dueday, $assignment->duehour, + $assignment->dueminute); + $assignment->timeavailable = make_timestamp($assignment->availableyear, $assignment->availablemonth, + $assignment->availableday, $assignment->availablehour, + $assignment->availableminute); + $assignment->id = $assignment->instance; + return update_record("assignment", $assignment); + } + + + + /* + * Top-level function for handling of submissions called by submissions.php + * + */ + function submissions($mode) { + switch ($mode) { + case 'grade': // We are in a popup window grading + if ($submission = $this->process_feedback()) { + print_heading(get_string('changessaved')); + /// Run some Javascript to try and update the parent page + echo '"; + fflush(); + } + close_window(); + break; + + case 'single': // We are in a popup window displaying submission + $this->display_submission(); + break; + + case 'all': // Main window, display everything + $this->display_submissions(); + break; + } + } + + + /* + * Display a single submission, ready for grading on a popup window + * + */ + function display_submission() { + + + $userid = required_param('userid'); + + if (!$user = get_record('user', 'id', $userid)) { + error('No such user!'); + } + + if (!$submission = $this->get_submission($user->id)) { // Get or make one + error('Could not find submission!'); + } + + if ($submission->timemodified > $submission->timemarked) { + $subtype = 'assignmentnew'; + } else { + $subtype = 'assignmentold'; + } + + print_header($this->assignment->name.' '.fullname($user, true)); + + echo ''; + echo ''; + echo ''; + echo ''; + + echo ''; + + echo ''; + echo ''; + echo ''; + echo ''; + + echo ''; + echo ''; + echo ''; + echo '
'; + print_user_picture($user->id, $this->course->id, $user->picture); + echo ''.fullname($user, true).'
'; + if ($submission->teacher) { + $teacher = get_record('user', 'id', $submission->teacher); + } else { + global $USER; + $teacher = $USER; + } + print_user_picture($teacher->id, $this->course->id, $teacher->picture); + echo ''; + + if (!$submission->grade and !$submission->timemarked) { + $submission->grade = -1; /// Hack to stop zero being selected on the menu below (so it shows 'no grade') + } + echo get_string('feedback', 'assignment').':'; + choose_from_menu(make_grades_menu($this->assignment->grade), 'grade', + $submission->grade, get_string('nograde')); + + if ($submission->timemarked) { + echo '  '.userdate($submission->timemarked); + } + echo '
'; + print_textarea(false, 6, 60, 500, 400, 'comment', $submission->comment, $this->course->id); + echo '
'; + + echo ''; + echo ''; + echo '
'; + print_footer('none'); + } + + + /* + * Display all the submissions ready for grading + */ + function display_submissions() { + + global $CFG, $db; + + $teacherattempts = true; /// Temporary measure + + + $sort = optional_param('sort', 'timemodified'); + $dir = optional_param('dir', 'DESC'); + $timenow = optional_param('timenow', 0); + $page = optional_param('page', 0); + $perpage = optional_param('perpage', 10); + + $strsaveallfeedback = get_string('saveallfeedback', 'assignment'); + + /// Some shortcuts to make the code read better + + $course = $this->course; + $assignment = $this->assignment; + $cm = $this->cm; + + + add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->assignment->id, $this->assignment->id, $this->cm->id); + + print_header_simple($this->assignment->name, "", ''.$this->strassignments.' -> '.$this->assignment->name.' -> '. $this->strsubmissions, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm)); + + + $tablecolumns = array('picture', 'fullname', 'grade', 'timemodified', 'timemarked', 'status'); + $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('lastmodified').' ('.$course->student.')', get_string('lastmodified').' ('.$course->teacher.')', get_string('status')); + + + require_once($CFG->libdir.'/tablelib.php'); + $table = new flexible_table('mod-assignment-submissions'); + + $table->define_columns($tablecolumns); + $table->define_headers($tableheaders); + $table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id); + + $table->sortable(true); + $table->collapsible(true); + $table->initialbars(true); + + $table->column_suppress('picture'); + $table->column_suppress('fullname'); + + $table->column_class('picture', 'picture'); + + $table->set_attribute('cellspacing', '0'); + $table->set_attribute('id', 'attempts'); + $table->set_attribute('class', 'generaltable generalbox'); + $table->set_attribute('width', '90%'); + $table->set_attribute('align', 'center'); + + // Start working -- this is necessary as soon as the niceties are over + $table->setup(); + + + + /// 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='.$assignment->id.'&sort='.$sort.'&dir='.$dir); + } else { + $currentgroup = false; + } + + + /// Get all teachers and students + if ($currentgroup) { + $users = get_group_users($currentgroup); + } else { + $users = get_course_users($course->id); + } + + if (!$teacherattempts) { + $teachers = get_course_teachers($course->id); + if (!empty($teachers)) { + $keys = array_keys($teachers); } - - $USER->lang = $user->lang; - - if (! $course = get_record("course", "id", "$submission->course")) { - echo "Could not find course $submission->course\n"; - continue; + foreach ($keys as $key) { + unset($users[$key]); } + } + + if (empty($users)) { + print_heading($strnoattempts); + return true; + } - if (! isstudent($course->id, $user->id) and !isteacher($course->id, $user->id)) { - echo fullname($user)." not an active participant in $course->shortname\n"; - continue; + + /// Construct the SQL + + if ($where = $table->get_sql_where()) { + $where = str_replace('firstname', 'u.firstname', $where); + $where = str_replace('lastname', 'u.lastname', $where); + $where .= ' AND '; + } + + if ($sort = $table->get_sql_sort()) { + $sortparts = explode(',', $sort); + $newsort = array(); + foreach ($sortparts as $sortpart) { + $sortpart = trim($sortpart); + $newsort[] = $sortpart; } + $sort = ' ORDER BY '.implode(', ', $newsort); + } - if (! $teacher = get_record("user", "id", "$submission->teacher")) { - echo "Could not find teacher $submission->teacher\n"; - continue; - } - if (! $mod = get_coursemodule_from_instance("assignment", $submission->assignment, $course->id)) { - echo "Could not find course module for assignment id $submission->assignment\n"; - continue; - } + $select = 'SELECT u.id, u.firstname, u.lastname, u.picture '; + $group = ''; + $sql = 'FROM '.$CFG->prefix.'user u '. + 'WHERE '.$where.'u.id IN ('.implode(',', array_keys($users)).')'; - if (! $mod->visible) { /// Hold mail notification for hidden assignments until later - continue; - } - $strassignments = get_string("modulenameplural", "assignment"); - $strassignment = get_string("modulename", "assignment"); + $total = count_records_sql('SELECT COUNT(u.id) '.$sql); - unset($assignmentinfo); - $assignmentinfo->teacher = fullname($teacher); - $assignmentinfo->assignment = format_string($submission->name,true); - $assignmentinfo->url = "$CFG->wwwroot/mod/assignment/view.php?id=$mod->id"; + $table->pagesize($perpage, $total); + + if($table->get_page_start() !== '' && $table->get_page_size() !== '') { + $limit = ' '.sql_paging_limit($table->get_page_start(), $table->get_page_size()); + } + else { + $limit = ''; + } - $postsubject = "$course->shortname: $strassignments: ".format_string($submission->name,true); - $posttext = "$course->shortname -> $strassignments -> ".format_string($submission->name,true)."\n"; - $posttext .= "---------------------------------------------------------------------\n"; - $posttext .= get_string("assignmentmail", "assignment", $assignmentinfo); - $posttext .= "---------------------------------------------------------------------\n"; + $strupdate = get_string('update'); + $grademenu = make_grades_menu($this->assignment->grade); + + $ausers = get_records_sql($select.$sql.$sort.$limit); + + $submissions = get_records_sql("SELECT s.userid, s.id, s.grade, s.timemodified, s.timemarked + FROM {$CFG->prefix}assignment_submissions s + WHERE s.assignment = ".$this->assignment->id." + AND s.userid IN (".implode(',', array_keys($ausers)).')'); + + foreach ($ausers as $auser) { + $picture = print_user_picture($auser->id, $course->id, $auser->picture, false, true); + if (!empty($submissions[$auser->id])) { + $submission = $submissions[$auser->id]; + if ($submission->timemodified > 0) { + $studentmodified = '
'.userdate($submission->timemodified).'
'; + if ($submission->timemarked > $submission->timemodified) { + $status = '
YES
'; + } else { + $status = '
NO
'; + } + } else { + $studentmodified = '
-
'; + $status = '
'; + } + if ($submission->timemarked > 0) { + $teachermodified = '
'.userdate($submission->timemarked).'
'; + } else { + $teachermodified = '
-
'; + } + + $grade = choose_from_menu($grademenu, 'g'.$auser->id, $submission->grade, get_string('nograde'), '', 0, true); - if ($user->mailformat == 1) { // HTML - $posthtml = "

". - "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". - "wwwroot/mod/assignment/index.php?id=$course->id\">$strassignments ->". - "wwwroot/mod/assignment/view.php?id=$mod->id\">".format_string($submission->name,true)."

"; - $posthtml .= "
"; - $posthtml .= "

".get_string("assignmentmailhtml", "assignment", $assignmentinfo)."

"; - $posthtml .= "

"; } else { - $posthtml = ""; + $studentmodified = '
-
'; + $teachermodified = '
-
'; + $status = '
'; + $grade = choose_from_menu($grademenu, 'g'.$auser->id, -1, get_string('nograde'), '', 0, true); } - if (! email_to_user($user, $teacher, $postsubject, $posttext, $posthtml)) { - echo "Error: assignment cron: Could not send out mail for id $submission->id to user $user->id ($user->email)\n"; - } + $button = button_to_popup_window ('/mod/assignment/submissions.php?id='.$this->cm->id.'&userid='.$auser->id.'&mode=single', + 'grade'.$auser->id, $strupdate, 450, 600, $strupdate, 'none', true); + + $row = array($picture, fullname($auser), $grade, $studentmodified, $teachermodified, $status.' '.$button); + $table->add_data($row); } + + + $table->print_html(); + + print_footer($this->course); + } - return true; -} -function assignment_print_recent_activity($course, $isteacher, $timestart) { + + /* + * Display and process the submissions + */ + function process_feedback() { + + global $USER; + + if (!$feedback = data_submitted()) { // No incoming data? + return false; + } + + if (!empty($feedback->cancel)) { // User hit cancel button + return false; + } + + $newsubmission = $this->get_submission($feedback->userid); + + $newsubmission->grade = $feedback->grade; + $newsubmission->comment = $feedback->comment; + $newsubmission->teacher = $USER->id; + $newsubmission->mailed = 0; // Make sure mail goes out (again, even) + $newsubmission->timemarked = time(); + + if (empty($submission->timemodified)) { // eg for offline assignments + $newsubmission->timemodified = time(); + } + + 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; + + } + + + function get_submission($userid, $createnew=true) { + $submission = get_record('assignment_submissions', 'assignment', $this->assignment->id, 'userid', $userid); + + if ($submission || !$createnew) { + return $submission; + } + + $newsubmission = new Object; + $newsubmission->assignment = $this->assignment->id; + $newsubmission->userid = $userid; + $newsubmission->timecreated = time(); + if (!insert_record("assignment_submissions", $newsubmission)) { + error("Could not insert a new empty submission"); + } + + return get_record('assignment_submissions', 'assignment', $this->assignment->id, 'userid', $userid); + } + + + function get_submissions($sort='', $dir='DESC') { + /// Return all assignment submissions by ENROLLED students (even empty) + global $CFG; + + if ($sort == "lastname" or $sort == "firstname") { + $sort = "u.$sort $dir"; + } else if (empty($sort)) { + $sort = "a.timemodified DESC"; + } else { + $sort = "a.$sort $dir"; + } + + $select = "s.course = '$this->assignment->course' AND"; + $site = get_site(); + if ($this->assignment->course == $site->id) { + $select = ''; + } + return get_records_sql("SELECT a.* + FROM {$CFG->prefix}assignment_submissions a, + {$CFG->prefix}user_students s, + {$CFG->prefix}user u + WHERE a.userid = s.userid + AND u.id = a.userid + AND $select a.assignment = '$this->assignment->id' + ORDER BY $sort"); + } + + + function count_real_submissions($groupid=0) { + /// Return all real assignment submissions by ENROLLED students (not empty ones) + global $CFG; + + if ($groupid) { /// How many in a particular group? + return count_records_sql("SELECT COUNT(DISTINCT g.userid, g.groupid) + FROM {$CFG->prefix}assignment_submissions a, + {$CFG->prefix}groups_members g + WHERE a.assignment = {$this->assignment->id} + AND a.timemodified > 0 + AND g.groupid = '$groupid' + AND a.userid = g.userid "); + } else { + $select = "s.course = '{$this->assignment->course}' AND"; + if ($this->assignment->course == SITEID) { + $select = ''; + } + return count_records_sql("SELECT COUNT(*) + FROM {$CFG->prefix}assignment_submissions a, + {$CFG->prefix}user_students s + WHERE a.assignment = '{$this->assignment->id}' + AND a.timemodified > 0 + AND $select a.userid = s.userid "); + } + } + +} ////// End of the assignment_base class + + + +/// OTHER STANDARD FUNCTIONS //////////////////////////////////////////////////////// + + +function assignment_delete_instance($id){ global $CFG; - $content = false; - $assignments = NULL; - - if (!$logs = get_records_select('log', 'time > \''.$timestart.'\' AND '. - 'course = \''.$course->id.'\' AND '. - 'module = \'assignment\' AND '. - 'action = \'upload\' ', 'time ASC')) { + if (! $assignment = get_record('assignment', 'id', $id)) { return false; } - foreach ($logs as $log) { - //Create a temp valid module structure (course,id) - $tempmod->course = $log->course; - $tempmod->id = $log->info; - //Obtain the visible property from the instance - $modvisible = instance_is_visible($log->module,$tempmod); - - //Only if the mod is visible - if ($modvisible) { - $assignments[$log->info] = assignment_log_info($log); - $assignments[$log->info]->time = $log->time; - $assignments[$log->info]->url = str_replace('&', '&', $log->url); - } - } - - if ($assignments) { - print_headline(get_string('newsubmissions', 'assignment').':'); - foreach ($assignments as $assignment) { - print_recent_activity_note($assignment->time, $assignment, $isteacher, $assignment->name, - $CFG->wwwroot.'/mod/assignment/'.$assignment->url); - } - $content = true; - } - - return $content; + require_once("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php"); + $assignmentclass = "assignment_$assignment->assignmenttype"; + $ass = new $assignmentclass(); + return $ass->delete_instance($assignment); } -function assignment_grades($assignmentid) { -/// Must return an array of grades, indexed by user, and a max grade. + +function assignment_update_instance($assignment){ + global $CFG; + + require_once("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php"); + $assignmentclass = "assignment_$assignment->assignmenttype"; + $ass = new $assignmentclass(); + return $ass->update_instance($assignment); +} - if (!$assignment = get_record("assignment", "id", $assignmentid)) { - return NULL; +function assignment_add_instance($assignment) { + global $CFG; + + require_once("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php"); + $assignmentclass = "assignment_$assignment->assignmenttype"; + $ass = new $assignmentclass(); + return $ass->add_instance($assignment); +} + +function assignment_types() { + $types = array(); + $names = get_list_of_plugins('mod/assignment/type'); + foreach ($names as $name) { + $types[$name] = get_string('type'.$name, 'assignment'); } + asort($types); + return $types; +} - $grades = get_records_menu("assignment_submissions", "assignment", - $assignment->id, "", "userid,grade"); +function assignment_upgrade_submodules() { + global $CFG; - if ($assignment->grade >= 0) { - $return->grades = $grades; - $return->maxgrade = $assignment->grade; + $types = assignment_types(); - } else { - $scaleid = - ($assignment->grade); - if ($scale = get_record("scale", "id", $scaleid)) { - $scalegrades = make_menu_from_list($scale->scale); - if ($grades) { - foreach ($grades as $key => $grade) { - $grades[$key] = $scalegrades[$grade]; - } - } - } - $return->grades = $grades; - $return->maxgrade = ""; - } - - return $return; -} + include_once($CFG->dirroot.'/mod/assignment/version.php'); // defines $module with version etc -function assignment_get_participants($assignmentid) { -//Returns the users with data in one assignment -//(users with records in assignment_submissions, students and teachers) + foreach ($types as $type) { - global $CFG; + $fullpath = $CFG->dirroot.'/mod/assignment/type/'.$type; - //Get students - $students = get_records_sql("SELECT DISTINCT u.id, u.id - FROM {$CFG->prefix}user u, - {$CFG->prefix}assignment_submissions a - WHERE a.assignment = '$assignmentid' and - u.id = a.userid"); - //Get teachers - $teachers = get_records_sql("SELECT DISTINCT u.id, u.id - FROM {$CFG->prefix}user u, - {$CFG->prefix}assignment_submissions a - WHERE a.assignment = '$assignmentid' and - u.id = a.teacher"); + /// Check for an external version file (defines $submodule) - //Add teachers to students - if ($teachers) { - foreach ($teachers as $teacher) { - $students[$teacher->id] = $teacher; + if (!is_readable($fullpath .'/version.php')) { + continue; } - } - //Return students array (it contains an array of unique users) - return ($students); -} - -function assignment_scale_used ($assignmentid,$scaleid) { -//This function returns if a scale is being used by one assignment - - $return = false; - - $rec = get_record("assignment","id","$assignmentid","grade","-$scaleid"); - - if (!empty($rec) && !empty($scaleid)) { - $return = true; - } - - return $return; -} - -/// SQL STATEMENTS ////////////////////////////////////////////////////////////////// - -function assignment_log_info($log) { - global $CFG; - return get_record_sql("SELECT a.name, u.firstname, u.lastname - FROM {$CFG->prefix}assignment a, - {$CFG->prefix}user u - WHERE a.id = '$log->info' - AND u.id = '$log->userid'"); -} - -function assignment_count_real_submissions($assignment, $groupid=0) { -/// Return all real assignment submissions by ENROLLED students (not empty ones) - global $CFG; - - if ($groupid) { /// How many in a particular group? - return count_records_sql("SELECT COUNT(DISTINCT g.userid, g.groupid) - FROM {$CFG->prefix}assignment_submissions a, - {$CFG->prefix}groups_members g - WHERE a.assignment = $assignment->id - AND a.timemodified > 0 - AND g.groupid = '$groupid' - AND a.userid = g.userid "); - } else { - $select = "s.course = '$assignment->course' AND"; - if ($assignment->course == SITEID) { - $select = ''; - } - return count_records_sql("SELECT COUNT(*) - FROM {$CFG->prefix}assignment_submissions a, - {$CFG->prefix}user_students s - WHERE a.assignment = '$assignment->id' - AND a.timemodified > 0 - AND $select a.userid = s.userid "); - } -} - -function assignment_get_all_submissions($assignment, $sort="", $dir="DESC") { -/// Return all assignment submissions by ENROLLED students (even empty) - global $CFG; - - if ($sort == "lastname" or $sort == "firstname") { - $sort = "u.$sort $dir"; - } else if (empty($sort)) { - $sort = "a.timemodified DESC"; - } else { - $sort = "a.$sort $dir"; - } - - $select = "s.course = '$assignment->course' AND"; - if ($assignment->course == SITEID) { - $select = ''; - } - return get_records_sql("SELECT a.* - FROM {$CFG->prefix}assignment_submissions a, - {$CFG->prefix}user_students s, - {$CFG->prefix}user u - WHERE a.userid = s.userid - AND u.id = a.userid - AND $select a.assignment = '$assignment->id' - ORDER BY $sort"); -} - -function assignment_get_users_done($assignment) { -/// Return list of users who have done an assignment - global $CFG; - - $select = "s.course = '$assignment->course' AND"; - if ($assignment->course == SITEID) { - $select = ''; - } - return get_records_sql("SELECT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}user_students s, - {$CFG->prefix}assignment_submissions a - WHERE $select s.userid = u.id - AND u.id = a.userid - AND a.assignment = '$assignment->id' - ORDER BY a.timemodified DESC"); -} - -function assignment_get_unmailed_submissions($starttime, $endtime) { -/// Return list of marked submissions that have not been mailed out for currently enrolled students - global $CFG; - return get_records_sql("SELECT s.*, a.course, a.name - FROM {$CFG->prefix}assignment_submissions s, - {$CFG->prefix}assignment a, - {$CFG->prefix}user_students us - WHERE s.mailed = 0 - AND s.timemarked <= $endtime - AND s.timemarked >= $starttime - AND s.assignment = a.id - AND s.userid = us.userid - AND a.course = us.course"); -} - + unset($module); + include_once($fullpath .'/version.php'); -////////////////////////////////////////////////////////////////////////////////////// + /// Check whether we need to upgrade -function assignment_file_area_name($assignment, $user) { -// Creates a directory file name, suitable for make_upload_directory() - global $CFG; - - return "$assignment->course/$CFG->moddata/assignment/$assignment->id/$user->id"; -} - -function assignment_file_area($assignment, $user) { - return make_upload_directory( assignment_file_area_name($assignment, $user) ); -} - -function assignment_get_submission($assignment, $user) { - $submission = get_record("assignment_submissions", "assignment", $assignment->id, "userid", $user->id); - if (!empty($submission->timemodified)) { - return $submission; - } - return NULL; -} - -function assignment_print_difference($time) { - if ($time < 0) { - $timetext = get_string("late", "assignment", format_time($time)); - return " ($timetext)"; - } else { - $timetext = get_string("early", "assignment", format_time($time)); - return " ($timetext)"; - } -} - -function assignment_print_submission($assignment, $user, $submission, $teachers, $grades) { - global $USER; - - if ($submission->timemodified > $submission->timemarked) { - $subtype = 'assignmentnew'; - } else { - $subtype = 'assignmentold'; - } - echo "\n"; - - echo "\n"; - if ($assignment->type == OFFLINE) { - echo "\n"; - echo "\n"; - echo ""; - - if ($assignment->type != OFFLINE) { - echo "\n"; - } - echo "\n"; - echo "\n"; - echo '"; - - echo "
"; - } else { - echo "\n"; - } - print_user_picture($user->id, $assignment->course, $user->picture); - echo "".fullname($user, true); - if ($assignment->type != OFFLINE and $submission->timemodified) { - echo "  ".get_string("lastmodified").": "; - echo userdate($submission->timemodified); - echo assignment_print_difference($assignment->timedue - $submission->timemodified); - } - echo "
"; - if ($submission->timemodified) { - assignment_print_user_files($assignment, $user); - } else { - print_string("notsubmittedyet", "assignment"); + if (!isset($submodule->version)) { + continue; } - echo "
"; - if (!$submission->teacher) { - $submission->teacher = $USER->id; - } - print_user_picture($submission->teacher, $assignment->course, $teachers[$submission->teacher]->picture); - echo "'; + /// Make sure this submodule will work with this assignment version - if (!$submission->grade and !$submission->timemarked) { - $submission->grade = -1; /// Hack to stop zero being selected on the menu below (so it shows 'no grade') - } - echo get_string("feedback", "assignment").":"; - choose_from_menu($grades, "g$submission->id", $submission->grade, get_string("nograde")); - if ($submission->timemarked) { - echo "  ".userdate($submission->timemarked); - } - echo "

"; - echo "

\n"; -} - -function assignment_print_feedback($course, $submission, $assignment) { - global $CFG, $RATING; - - if (! $teacher = get_record("user", "id", $submission->teacher)) { - error("Weird assignment error"); - } - - echo "\n"; + if (isset($submodule->requires) and ($submodules->requires > $module->version)) { + notify("Assignment submodule '$type' is too new for your assignment"); + continue; + } - echo "\n"; - echo "\n"; - echo ""; + /// If we use versions, make sure an internal record exists - echo "\n
"; - print_user_picture($teacher->id, $course->id, $teacher->picture); - echo "".fullname($teacher); - echo "  ".userdate($submission->timemarked).""; - echo "
"; + $currentversion = 'assignment_'.$type.'_version'; - echo "

"; - if ($assignment->grade) { - if ($submission->grade or $submission->timemarked) { - echo get_string("grade").": $submission->grade"; - } else { - echo get_string("nograde"); + if (!isset($CFG->$currentversion)) { + set_config($currentversion, 0); } - } - echo "

"; - echo text_to_html($submission->comment); - echo "
"; -} - + /// See if we need to upgrade + + if ($submodule->version <= $CFG->$currentversion) { + continue; + } -function assignment_print_user_files($assignment, $user) { -// Arguments are objects + /// Look for the upgrade file - global $CFG; + if (!is_readable($fullpath .'/db/'.$CFG->dbtype.'.php')) { + continue; + } - $filearea = assignment_file_area_name($assignment, $user); + include_once($fullpath .'/db/'. $CFG->dbtype .'.php'); // defines assignment_xxx_upgrade - if ($basedir = assignment_file_area($assignment, $user)) { - if ($files = get_directory_list($basedir)) { - foreach ($files as $file) { - $icon = mimeinfo("icon", $file); - if ($CFG->slasharguments) { - $ffurl = "file.php/$filearea/$file"; - } else { - $ffurl = "file.php?file=/$filearea/$file"; - } + /// Perform the upgrade - echo "pixpath/f/$icon\" height=\"16\" width=\"16\" border=\"0\" alt=\"file\" />"; - echo " wwwroot/$ffurl\">$file"; - echo "
"; + $upgrade_function = 'assignment_'.$type.'_upgrade'; + if (function_exists($upgrade_function)) { + $db->debug=true; + if ($upgrade_function($CFG->$currentversion)) { + $db->debug=false; + set_config($currentversion, $submodule->version); } + $db->debug=false; } } } -// this function should be defunct now that we're using uploadlib.php -function assignment_delete_user_files($assignment, $user, $exception) { -// Deletes all the user files in the assignment area for a user -// EXCEPT for any file named $exception - - if ($basedir = assignment_file_area($assignment, $user)) { - if ($files = get_directory_list($basedir)) { - foreach ($files as $file) { - if ($file != $exception) { - unlink("$basedir/$file"); - notify(get_string("existingfiledeleted", "assignment", $file)); - } - } - } - } -} - -function assignment_print_upload_form($assignment) { -// Arguments are objects - - global $CFG; - - echo '
'; - echo "
id\">"; - echo ''; - require_once($CFG->dirroot.'/lib/uploadlib.php'); - upload_print_form_fragment(1,array('newfile'),false,null,0,$assignment->maxbytes,false); - echo ''; - echo '
'; - echo '
'; -} - -function assignment_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $assignment="0", $user="", $groupid="") { -// Returns all assignments since a given time. If assignment is specified then -// this restricts the results - - global $CFG; - - if ($assignment) { - $assignmentselect = " AND cm.id = '$assignment'"; - } else { - $assignmentselect = ""; - } - if ($user) { - $userselect = " AND u.id = '$user'"; - } else { - $userselect = ""; - } - - $assignments = get_records_sql("SELECT asub.*, u.firstname, u.lastname, u.picture, u.id as userid, - a.grade as maxgrade, name, cm.instance, cm.section, a.type - FROM {$CFG->prefix}assignment_submissions asub, - {$CFG->prefix}user u, - {$CFG->prefix}assignment a, - {$CFG->prefix}course_modules cm - WHERE asub.timemodified > '$sincetime' - AND asub.userid = u.id $userselect - AND a.id = asub.assignment $assignmentselect - AND cm.course = '$courseid' - AND cm.instance = a.id - ORDER BY asub.timemodified ASC"); - - if (empty($assignments)) - return; - - foreach ($assignments as $assignment) { - if (empty($groupid) || ismember($groupid, $assignment->userid)) { - - $tmpactivity = new Object; - - $tmpactivity->type = "assignment"; - $tmpactivity->defaultindex = $index; - $tmpactivity->instance = $assignment->instance; - $tmpactivity->name = $assignment->name; - $tmpactivity->section = $assignment->section; - - $tmpactivity->content->grade = $assignment->grade; - $tmpactivity->content->maxgrade = $assignment->maxgrade; - $tmpactivity->content->type = $assignment->type; - - $tmpactivity->user->userid = $assignment->userid; - $tmpactivity->user->fullname = fullname($assignment); - $tmpactivity->user->picture = $assignment->picture; - - $tmpactivity->timestamp = $assignment->timemodified; - - $activities[] = $tmpactivity; - - $index++; - } - } - - return; -} - -function assignment_print_recent_mod_activity($activity, $course, $detail=false) { - global $CFG; - - echo ''; - - echo ""; - echo "
"; - print_user_picture($activity->user->userid, $course, $activity->user->picture); - echo ""; - - if ($detail) { - echo "modpixpath/$activity->type/icon.gif\" ". - "height=16 width=16 alt=\"$activity->type\"> "; - echo "wwwroot/mod/assignment/view.php?id=" . $activity->instance . "\">" - . format_string($activity->name,true) . " - "; - - } - - if (isteacher($course)) { - $grades = "(" . $activity->content->grade . " / " . $activity->content->maxgrade . ") "; - - $assignment->id = $activity->instance; - $assignment->course = $course; - $user->id = $activity->user->userid; - - echo $grades; - if ($activity->content->type == UPLOADSINGLE) { - $file = assignment_get_user_file($assignment, $user); - echo "pixpath/f/$file->icon\" height=16 width=16 border=0 alt=\"file\">"; - echo " wwwroot/$file->url\">$file->name"; - } - echo "
"; - } - echo "wwwroot/user/view.php?id=" - . $activity->user->userid . "&course=$course\">" - . $activity->user->fullname . " "; - - echo " - " . userdate($activity->timestamp); - - echo "
"; - - return; -} - -function assignment_get_user_file($assignment, $user) { - global $CFG; - - $tmpfile = ""; - - $filearea = assignment_file_area_name($assignment, $user); - - if ($basedir = assignment_file_area($assignment, $user)) { - if ($files = get_directory_list($basedir)) { - foreach ($files as $file) { - $icon = mimeinfo("icon", $file); - if ($CFG->slasharguments) { - $ffurl = "file.php/$filearea/$file"; - } else { - $ffurl = "file.php?file=/$filearea/$file"; - } - $tmpfile->url = $ffurl; - $tmpfile->name = $file; - $tmpfile->icon = $icon; - } - } - } - return $tmpfile; -} - -if (!function_exists('get_group_teachers')) { // Will be in datalib.php later - function get_group_teachers($courseid, $groupid) { - /// Returns a list of all the teachers who can access a group - if ($teachers = get_course_teachers($courseid)) { - foreach ($teachers as $key => $teacher) { - if ($teacher->editall) { // These can access anything - continue; - } - if (($teacher->authority > 0) and ismember($groupid, $teacher->id)) { // Specific group teachers - continue; - } - unset($teacher[$key]); - } - } - return $teachers; - } -} - -function assignment_email_teachers($course, $cm, $assignment, $submission) { -/// Alerts teachers by email of new or changed assignments that need grading - - global $CFG; - - if (empty($assignment->emailteachers)) { // No need to do anything - return; - } - - $user = get_record('user', 'id', $submission->userid); - - if (groupmode($course, $cm) == SEPARATEGROUPS) { // Separate groups are being used - if (!$group = user_group($course->id, $user->id)) { // Try to find a group - $group->id = 0; // Not in a group, never mind - } - $teachers = get_group_teachers($course->id, $group->id); // Works even if not in group - } else { - $teachers = get_course_teachers($course->id); - } - - if ($teachers) { - - $strassignments = get_string('modulenameplural', 'assignment'); - $strassignment = get_string('modulename', 'assignment'); - $strsubmitted = get_string('submitted', 'assignment'); - - foreach ($teachers as $teacher) { - unset($info); - $info->username = fullname($user); - $info->assignment = format_string($assignment->name,true); - $info->url = "$CFG->wwwroot/mod/assignment/submissions.php?id=$assignment->id"; - - $postsubject = "$strsubmitted: $info->username -> $assignment->name"; - $posttext = "$course->shortname -> $strassignments -> ".format_string($assignment->name,true)."\n"; - $posttext .= "---------------------------------------------------------------------\n"; - $posttext .= get_string("emailteachermail", "assignment", $info); - $posttext .= "\n---------------------------------------------------------------------\n"; - - if ($user->mailformat == 1) { // HTML - $posthtml = "

". - "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". - "wwwroot/mod/assignment/index.php?id=$course->id\">$strassignments ->". - "wwwroot/mod/assignment/view.php?id=$cm->id\">".format_string($assignment->name,true)."

"; - $posthtml .= "
"; - $posthtml .= "

".get_string("emailteachermailhtml", "assignment", $info)."

"; - $posthtml .= "

"; - } else { - $posthtml = ""; - } - - @email_to_user($teacher, $user, $postsubject, $posttext, $posthtml); // If it fails, oh well, too bad. - } - } -} - - ?> diff --git a/mod/assignment/mod.html b/mod/assignment/mod.html index e2742a633df..ebdd58fe400 100644 --- a/mod/assignment/mod.html +++ b/mod/assignment/mod.html @@ -1,18 +1,29 @@ dirroot/mod/assignment/lib.php"); + if (empty($form->name)) { - $form->name = ''; + $form->name = ""; } if (empty($form->description)) { - $form->description = ''; + $form->description = ""; } if (empty($form->format)) { - $form->format = ''; + $form->format = ""; } - if (empty($form->type)) { - $form->type = ''; + if (empty($form->assignmenttype)) { + $form->assignmenttype = "uploadsingle"; } if (empty($form->resubmit)) { - $form->resubmit = ''; + $form->resubmit = ""; + } + if (!isset($form->grade)) { + $form->grade = 100; + } + if (!isset($form->timedue)) { + $form->timedue = time()+7*24*3600; + } + if (!isset($form->timeavailable)) { + $form->timeavailable = time(); } if (!isset($form->grade)) { $form->grade = 100; @@ -21,33 +32,30 @@ $form->maxbytes = $CFG->assignment_maxbytes; } if (empty($form->timedue)) { - $form->timedue = ''; - } - if (empty($form->emailteachers)) { - $form->emailteachers = ''; + $form->timedue = ""; } ?> - -
+ - + - - - - - - - - - - - - - - - + + - - + + - + + + + + + + - +
:: - +
:

+
: +

'; - helpbutton('questions', get_string('helpquestions'), 'moodle', true, true); - echo '
'; + helpbutton("writing", get_string("helpwriting"), "moodle", true, true); + echo "
"; + helpbutton("questions", get_string("helpquestions"), "moodle", true, true); + echo "
"; if ($usehtmleditor) { helpbutton("richtext", get_string("helprichtext"), "moodle", true, true); } else { emoticonhelpbutton("form", "description"); - } + } ?>
@@ -70,39 +78,8 @@ ?>
: - dirroot/mod/assignment/lib.php"); - asort($ASSIGNMENT_TYPE); - choose_from_menu($ASSIGNMENT_TYPE, "type", $form->type, ""); - helpbutton("assignmenttype", get_string("assignmenttype", "assignment"), "assignment"); - ?> -
: - resubmit, ""); - helpbutton("resubmit", get_string("allowresubmit", "assignment"), "assignment"); - ?> -
: - emailteachers, ""); - helpbutton("emailteachers", get_string("emailteachers", "assignment"), "assignment"); - ?> -
:
: id, "grade", "$form->grade"); @@ -110,14 +87,26 @@
:maxbytes, $course->maxbytes); - choose_from_menu ($choices, "maxbytes", $form->maxbytes, ""); + : + assignmenttype, ""); + helpbutton("assignmenttype", get_string("assignmenttype", "assignment"), "assignment"); ?> -
:timeavailable); + echo " - "; + print_time_selector("availablehour", "availableminute", $form->timeavailable); + ?>
: timedue); @@ -125,19 +114,19 @@ print_time_selector("duehour", "dueminute", $form->timedue); ?>

- - - - - - - - -" /> -" /> + + + + + + + + + +
diff --git a/mod/assignment/plan.txt b/mod/assignment/plan.txt new file mode 100644 index 00000000000..06b071182f0 --- /dev/null +++ b/mod/assignment/plan.txt @@ -0,0 +1,48 @@ +Development priorities + +1) The first is to refactor the assignment module into a + class-based structure that allows new assignment types + to be plugged in. (Some similar work is already starting + with quiz questions and resources). This is easiest to + do now while assignment is still fairly small, and will allow + a lot of growth and assignment variants in the future. + + The idea is that new plugins like Exercise should just be + dropped into mod/assignment/types/exercise and will then + appear as a new type in the assignment menu. + + Each directory contains a subclass of a main class file + (eg mod/assignments/types/types.php) which define a number + of functions used in various places within the assignment + interface. + + +2) The second thing is to make this module more scalable for + teachers (ie on the grading screen). + + The format I'm thinking of is something like this (you may + have some ideas also). It's meant to still allow the quick + run down the page technique we have now (but even quicker) while + also allowing for detailed feedback. Imagine a long table with + lines like this: + + Student name {Info} [grade] [short comment field...] {More} + + The {Info} could be a filename, or a link to a popup that shows a full + assignment, or something else defined by the plugin. + + The {More} is a button that creates a popup window containing + longer feedback, again defined by the plugin. There would usually be + the grade menu (or text field), a large textarea, an upload button, + etc ... + + +3) Online assignments. This is just like the Journal module except + Teachers can also edit the assignment and perhaps ask them to + revise and resubmit. Versions of pages are kept, like the Wiki, + but there's only one page. All in the HTML editor. This should + be trivial to implement once the above framework exists. + + This will also allow me to get rid of the current Journal module + which duplicates alot of assignment code (but not well). + diff --git a/mod/assignment/restorelib.php b/mod/assignment/restorelib.php index ef8db22f20f..8975daf1f96 100644 --- a/mod/assignment/restorelib.php +++ b/mod/assignment/restorelib.php @@ -46,6 +46,7 @@ $assignment->resubmit = backup_todb($info['MOD']['#']['RESUBMIT']['0']['#']); $assignment->emailteachers = backup_todb($info['MOD']['#']['EMAILTEACHERS']['0']['#']); $assignment->type = backup_todb($info['MOD']['#']['TYPE']['0']['#']); + $assignment->assignmenttype = backup_todb($info['MOD']['#']['ASSIGNMENTTYPE']['0']['#']); $assignment->maxbytes = backup_todb($info['MOD']['#']['MAXBYTES']['0']['#']); $assignment->timedue = backup_todb($info['MOD']['#']['TIMEDUE']['0']['#']); $assignment->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']); @@ -59,6 +60,14 @@ } } + if (empty($assignment->assignmenttype)) { /// Pre 1.5 assignment + if ($assignment->type == 1) { + $assignment->assignmenttype = 'uploadsingle'; + } else { + $assignment->assignmenttype = 'offline'; + } + } + //The structure is equal to the db, so insert the assignment $newid = insert_record ("assignment",$assignment); diff --git a/mod/assignment/styles.php b/mod/assignment/styles.php new file mode 100644 index 00000000000..419f087df55 --- /dev/null +++ b/mod/assignment/styles.php @@ -0,0 +1,8 @@ +#mod-assignment-submissions .submission td { + padding: 10px; +} + +#mod-assignment-submissions .generaltable .r1 { + background-color: #FFFFFF; +} + diff --git a/mod/assignment/submissions.php b/mod/assignment/submissions.php index 4db6b598fcf..2a2b29444f9 100644 --- a/mod/assignment/submissions.php +++ b/mod/assignment/submissions.php @@ -3,22 +3,32 @@ require_once("../../config.php"); require_once("lib.php"); - require_variable($id); // Assignment - optional_variable($sort, "timemodified"); - optional_variable($dir, "DESC"); - optional_variable($timenow, 0); + $id = optional_param('id'); // Course module ID + $a = optional_param('a'); // Assignment ID + $mode = optional_param('mode', 'all'); // What mode are we in? - $timewas = $timenow; - $timenow = time(); + if ($id) { + if (! $cm = get_record("course_modules", "id", $id)) { + error("Course Module ID was incorrect"); + } - if (! $assignment = get_record("assignment", "id", $id)) { - 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"); + if (! $assignment = get_record("assignment", "id", $cm->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); @@ -27,170 +37,11 @@ error("Only teachers can look at this page"); } - $strassignments = get_string("modulenameplural", "assignment"); - $strassignment = get_string("modulename", "assignment"); - $strsubmissions = get_string("submissions", "assignment"); - $strsaveallfeedback = get_string("saveallfeedback", "assignment"); +/// 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); - print_header_simple(format_string($assignment->name), "", - "id\">$strassignments -> - id\">".format_string($assignment->name,true)." -> $strsubmissions", - "", "", true, update_module_button($cm->id, $course->id, $strassignment), navmenu($course, $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=$assignment->id&sort=$sort&dir=$dir"); - } else { - $currentgroup = false; - } - -/// Get all teachers and students - $teachers = get_course_teachers($course->id); - - if ($currentgroup) { - $users = get_group_users($currentgroup); - } else { - $users = get_course_students($course->id); - } - if (!$users) { - print_heading(get_string("nostudentsyet")); - print_footer($course); - exit; - } - -/// Make some easy ways to reference submissions - if ($submissions = assignment_get_all_submissions($assignment, $sort, $dir)) { - foreach ($submissions as $submission) { - $submissionbyuser[$submission->userid] = $submission; - } - } - -/// Get all existing submissions and check for missing ones - foreach($users as $user) { - if (!isset($submissionbyuser[$user->id])) { // Need to create empty entry - $newsubmission->assignment = $assignment->id; - $newsubmission->userid = $user->id; - $newsubmission->timecreated = time(); - if (!insert_record("assignment_submissions", $newsubmission)) { - error("Could not insert a new empty submission"); - } - } - } - - if (isset($newsubmission)) { // Get them all out again to be sure - $submissions = assignment_get_all_submissions($assignment, $sort, $dir); - } - - -/// If data is being submitted, then process it - if ($data = data_submitted()) { - - $feedback = array(); - // Peel out all the data from variable names. - foreach ($data as $key => $val) { - if (!in_array($key, array("id", "timenow"))) { - $type = substr($key,0,1); - $num = substr($key,1); - $feedback[$num][$type] = $val; - } - } - - $count = 0; - foreach ($feedback as $num => $vals) { - $submission = $submissions[$num]; - // Only update entries where feedback has actually changed. - if (($vals['g'] <> $submission->grade) || ($vals['c'] <> addslashes($submission->comment))) { - unset($newsubmission); - $newsubmission->grade = $vals['g']; - $newsubmission->comment = $vals['c']; - $newsubmission->teacher = $USER->id; - $newsubmission->timemarked = $timenow; - $newsubmission->mailed = 0; // Make sure mail goes out (again, even) - $newsubmission->id = $num; - - // Make sure that we aren't overwriting any recent feedback from other teachers. (see bug #324) - if ($timewas < $submission->timemarked && (!empty($submission->grade)) && (!empty($submission->comment))) { - notify(get_string("failedupdatefeedback", "assignment", fullname($users[$submission->userid])) - . "
" . get_string("grade") . ": $newsubmission->grade" - . "
" . get_string("feedback", "assignment") . ": $newsubmission->comment\n"); - } else { //print out old feedback and grade - if (empty($submission->timemodified)) { // eg for offline assignments - $newsubmission->timemodified = $timenow; - } - if (! update_record("assignment_submissions", $newsubmission)) { - notify(get_string("failedupdatefeedback", "assignment", $submission->userid)); - } else { - $count++; - } - } - } - } - $submissions = assignment_get_all_submissions($assignment,$sort, $dir); - add_to_log($course->id, "assignment", "update grades", "submissions.php?id=$assignment->id", "$count users", $cm->id); - notify(get_string("feedbackupdated", "assignment", $count)); - } else { - add_to_log($course->id, "assignment", "view submission", "submissions.php?id=$assignment->id", "$assignment->id", $cm->id); - } - - // Submission sorting - - $sorttypes = array('firstname', 'lastname', 'timemodified', 'grade'); - - print_simple_box_start("center", "50%"); - echo '

'.get_string('order').':  '; - - foreach ($sorttypes as $sorttype) { - if ($sorttype == 'timemodified') { - $label = get_string("lastmodified"); - } else { - $label = get_string($sorttype); - } - if ($sort == $sorttype) { // Current sort - $newdir = $dir == 'ASC' ? 'DESC' : 'ASC'; - } else { - $newdir = 'ASC'; - } - echo "id&sort=$sorttype&dir=$newdir\">$label"; - if ($sort == $sorttype) { // Current sort - $diricon = $dir == 'ASC' ? 'down' : 'up'; - echo " pixpath/t/$diricon.gif\" alt=\"\" />"; - } - echo "      "; - } - - echo "

"; - print_simple_box_end(); - - print_spacer(8,1); - - $allowedtograde = ($groupmode != VISIBLEGROUPS or isteacheredit($course->id) or ismember($currentgroup)); - - if ($allowedtograde) { - echo '
'; - echo "
"; - echo ""; - echo ""; - echo "id\" />"; - echo ""; - echo "
"; - } - - $grades = make_grades_menu($assignment->grade); - - foreach ($submissions as $submission) { - if (isset($users[$submission->userid])) { - $user = $users[$submission->userid]; - assignment_print_submission($assignment, $user, $submission, $teachers, $grades); - } - } - - if ($allowedtograde) { - echo "
"; - echo ""; - echo "
"; - echo "
"; - } - - print_footer($course); + $assignmentinstance->submissions($mode); // Display or process the submissions ?> diff --git a/mod/assignment/type/common.html b/mod/assignment/type/common.html new file mode 100644 index 00000000000..e0ba22c4db1 --- /dev/null +++ b/mod/assignment/type/common.html @@ -0,0 +1,26 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mod/assignment/type/common_end.html b/mod/assignment/type/common_end.html new file mode 100644 index 00000000000..55823541d1e --- /dev/null +++ b/mod/assignment/type/common_end.html @@ -0,0 +1 @@ +
diff --git a/mod/assignment/type/offline/assignment.class.php b/mod/assignment/type/offline/assignment.class.php new file mode 100644 index 00000000000..cec552fdd4f --- /dev/null +++ b/mod/assignment/type/offline/assignment.class.php @@ -0,0 +1,48 @@ +dirroot/mod/assignment/type/offline/mod.html"); + parent::setup_end(); + } + + function submittedlink() { + global $USER; + + $submitted = ''; + + if (isteacher($this->course->id)) { + $submitted = '' . + get_string('viewfeedback', 'assignment') . ''; + } else { + if (isset($USER->id)) { + if ($submission = $this->get_submission($USER->id)) { + if ($submission->timemodified <= $assignment->timedue) { + $submitted = userdate($submission->timemodified); + } else { + $submitted = ''.userdate($submission->timemodified).''; + } + } + } + } + + return $submitted; + } + + + +} + +?> diff --git a/mod/assignment/type/offline/mod.html b/mod/assignment/type/offline/mod.html new file mode 100644 index 00000000000..7f98198e7c2 --- /dev/null +++ b/mod/assignment/type/offline/mod.html @@ -0,0 +1,3 @@ +
+"> +
diff --git a/mod/assignment/type/postdata.html b/mod/assignment/type/postdata.html new file mode 100644 index 00000000000..7c19c582e22 --- /dev/null +++ b/mod/assignment/type/postdata.html @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mod/assignment/type/uploadsingle/assignment.class.php b/mod/assignment/type/uploadsingle/assignment.class.php new file mode 100644 index 00000000000..8cdf38ca906 --- /dev/null +++ b/mod/assignment/type/uploadsingle/assignment.class.php @@ -0,0 +1,55 @@ +dirroot/mod/assignment/type/uploadsingle/mod.html"); + parent::setup_end(); + } + + function submittedlink() { + global $USER; + + $submitted = ''; + + if (isteacher($this->course->id)) { + if ($this->currentgroup and isteacheredit($this->course->id)) { + $group = get_record('groups', 'id', $this->currentgroup); + $groupname = ' ('.$group->name.')'; + } else { + $groupname = ''; + } + $count = $this->count_real_submissions($this->currentgroup); + $submitted = ''. + get_string('viewsubmissions', 'assignment', $count).''.$groupname; + } else { + if (isset($USER->id)) { + if ($submission = $this->get_submission($USER)) { + if ($submission->timemodified <= $this->assignment->timedue) { + $submitted = userdate($submission->timemodified); + } else { + $submitted = ''.userdate($submission->timemodified).''; + } + } + } + } + + return $submitted; + } + + +} + +?> diff --git a/mod/assignment/type/uploadsingle/mod.html b/mod/assignment/type/uploadsingle/mod.html new file mode 100644 index 00000000000..7f98198e7c2 --- /dev/null +++ b/mod/assignment/type/uploadsingle/mod.html @@ -0,0 +1,3 @@ +
+"> +
diff --git a/mod/assignment/upload.php b/mod/assignment/upload.php index cf35ddeb258..fb73f967517 100644 --- a/mod/assignment/upload.php +++ b/mod/assignment/upload.php @@ -23,9 +23,9 @@ $strassignment = get_string("modulename", "assignment"); $strupload = get_string("upload"); - print_header_simple(format_string($assignment->name)." : $strupload", "", + print_header_simple("$assignment->name : $strupload", "", "id>$strassignments -> - id\">".format_string($assignment->name,true)." -> $strupload", + id\">$assignment->name -> $strupload", "", "", true); if ($submission = get_record("assignment_submissions", "assignment", $assignment->id, "userid", $USER->id)) { diff --git a/mod/assignment/version.php b/mod/assignment/version.php index e85d4d8164c..e16f5fdbefd 100644 --- a/mod/assignment/version.php +++ b/mod/assignment/version.php @@ -1,11 +1,11 @@ -version = 2005041100; +$module->version = 2005031000; $module->requires = 2005031000; // Requires this Moodle version $module->cron = 60; diff --git a/mod/assignment/view.php b/mod/assignment/view.php index 21a9aa8ee29..42cc6239db3 100644 --- a/mod/assignment/view.php +++ b/mod/assignment/view.php @@ -2,25 +2,28 @@ require_once("../../config.php"); require_once("lib.php"); + + $id = optional_param('id'); // Course Module ID + $a = optional_param('a'); - optional_variable($id); // Course Module ID - optional_variable($a); // Assignment ID + if (!empty($CFG->forcelogin)) { + require_login(); + } if ($id) { if (! $cm = get_record("course_modules", "id", $id)) { error("Course Module ID was incorrect"); } - if (! $course = get_record("course", "id", $cm->course)) { + if (! $assignment = get_record("assignment", "id", $cm->instance)) { + error("assignment ID was incorrect"); + } + + if (! $course = get_record("course", "id", $assignment->course)) { error("Course is misconfigured"); } - - if (! $assignment = get_record("assignment", "id", $cm->instance)) { - error("Course module is incorrect"); - } - } else { - if (! $assignment = get_record("assignment", "id", $a)) { + if (!$assignment = get_record("assignment", "id", $a)) { error("Course module is incorrect"); } if (! $course = get_record("course", "id", $assignment->course)) { @@ -31,112 +34,10 @@ } } - require_course_login($course, true, $cm); + require ("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php"); + $assignmentclass = "assignment_$assignment->assignmenttype"; + $assignmentinstance = new $assignmentclass($cm->id); - add_to_log($course->id, "assignment", "view", "view.php?id=$cm->id", $assignment->id, $cm->id); - - $strassignments = get_string("modulenameplural", "assignment"); - $strassignment = get_string("modulename", "assignment"); - - print_header_simple(format_string($assignment->name), "", - "id\">$strassignments -> ".format_string($assignment->name,true), - "", "", true, update_module_button($cm->id, $course->id, $strassignment), navmenu($course, $cm)); - - if (isteacher($course->id)) { - echo ''; - } else if (!$cm->visible) { - notice(get_string("activityiscurrentlyhidden")); - } - - print_simple_box_start('center', '70%', '', 5, 'generalbox', 'intro'); - print_heading(format_string($assignment->name), "center"); - - $timedifference = $assignment->timedue - time(); - if ($timedifference < 31536000) { // Don't bother showing dates over a year in the future - $strdifference = format_time($timedifference); - if ($timedifference < 0) { - $strdifference = "$strdifference"; - } - $strduedate = userdate($assignment->timedue)." ($strdifference)"; - echo "".get_string("duedate", "assignment").": $strduedate
"; - } - - if ($assignment->grade < 0) { - $scaleid = - ($assignment->grade); - if ($scale = get_record("scale", "id", $scaleid)) { - $scalegrades = make_menu_from_list($scale->scale); - echo "".get_string("grade").": $scale->name "; - print_scale_menu_helpbutton($course->id, $scale); - echo "
"; - } - } else if ($assignment->grade > 0) { - echo "".get_string("maximumgrade").": $assignment->grade
"; - } - - echo "
"; - echo format_text($assignment->description, $assignment->format); - print_simple_box_end(); - echo "
"; - - if (isstudent($course->id)) { - $submission = assignment_get_submission($assignment, $USER); - - if ($assignment->type == OFFLINE) { - if ($submission->timemarked) { - if (isset($scalegrades)) { - $submission->grade = $scalegrades[$submission->grade]; - } - assignment_print_feedback($course, $submission, $assignment); - } - } else { - if ($submission and $submission->timemodified) { - print_simple_box_start("center"); - echo "
"; - print_heading(get_string("yoursubmission","assignment").":", "center"); - echo "

".get_string("lastmodified").": ".userdate($submission->timemodified)."

"; - assignment_print_user_files($assignment, $USER); - print_simple_box_end(); - } else { - print_heading(get_string("notsubmittedyet","assignment")); - } - - echo '
'; - - if ($submission and $submission->timemarked) { - print_heading(get_string("submissionfeedback", "assignment").":", "center"); - if (isset($scalegrades)) { - $submission->grade = $scalegrades[$submission->grade]; - } - assignment_print_feedback($course, $submission, $assignment); - } - if (empty($submission->timemarked) or (!empty($assignment->resubmit))) { - if ($submission and $submission->timemodified) { - echo "

".get_string("overwritewarning", "assignment")."

"; - } - print_heading(get_string("submitassignment", "assignment").":", "center"); - - $assignment->maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $assignment->maxbytes); - assignment_print_upload_form($assignment); - } - } - } - - print_footer($course); + $assignmentinstance->view(); // Actually display the assignment! ?>