浏览代码

new submission type form
add new fields to feedback table to support pluginfiles
still having problem with the pluginfile manipulation

bernardo 5 年之前
父节点
当前提交
3845c6153d
共有 10 个文件被更改,包括 235 次插入182 次删除
  1. 17 7
      db/install.xml
  2. 5 0
      lang/en/gradeimporter.php
  3. 15 29
      lib.php
  4. 12 7
      locallib.php
  5. 0 50
      mod_form.php
  6. 5 86
      submission.php
  7. 20 3
      submission_form.php
  8. 114 0
      submissiontype.php
  9. 46 0
      submissiontype_form.php
  10. 1 0
      view.php

+ 17 - 7
db/install.xml

@@ -9,7 +9,7 @@
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" COMMENT="primary key" NEXT="course"/>
         <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The id of the course this instance is placed on" 
                   PREVIOUS="id" NEXT="name"/>
-        <FIELD NAME="name" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="Instance name" PREVIOUS="course" NEXT="intro"/>
+        <FIELD NAME="name" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="Instance name" PREVIOUS="course" NEXT="intro"/>
         <FIELD NAME="intro" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Description of the grades that are going to be available on the module" 
               PREVIOUS="NAME" NEXT="timecreated"/>
         <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Time stamp from when the instance was first created" 
@@ -56,19 +56,25 @@
         <KEY NAME="gradeimporterid" TYPE="foreign" FIELDS="gradeimporterid" REFTABLE="gradeimporter" REFFIELDS="id"/>
       </KEYS>
     </TABLE>
+
     <TABLE NAME="gradeimporter_submissiontype" COMMENT="Submission types are recorded by this table, eg: exam, exercises list, etc." PREVIOUS="gradeimporter_submission" NEXT="gradeimporter_feedback">
       <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="name"/>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="gradeimporterid"/>
+        <FIELD NAME="gradeimporterid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Which gradeimporter instance this submission is related to" PREVIOUS="id" NEXT="name"/>
         <FIELD NAME="name" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" COMMENT="Type name (exam, exercises list, etc)." 
-                    PREVIOUS="id" NEXT="info"/>
-        <FIELD NAME="info" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Submission type description. eg for exam type: exams given in class." 
-                    PREVIOUS="name"/>
-        <!--<FIELD NAME="descriptionformat" TYPE="char" LENGTH="10" NOTNULL="false" DEFAULT="plaintext" SEQUENCE="false" COMMENT="Type description format (html, plaintext, etc.)"/>-->
+                    PREVIOUS="gradeimporterid" NEXT="info"/>
+        
+        <FIELD NAME="description" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Submission type description. eg for exam type: exams given in class." 
+                    PREVIOUS="name" NEXT="descriptionformat"/>
+        <FIELD NAME="descriptionformat" TYPE="char" LENGTH="10" NOTNULL="false" DEFAULT="plaintext" SEQUENCE="false" COMMENT="Type description format (html, plaintext, etc.)"/>
       </FIELDS>
+
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+        <KEY NAME="gradeimporterid" TYPE="foreign" FIELDS="gradeimporterid" REFTABLE="gradeimporter" REFFIELDS="id"/>
       </KEYS>
     </TABLE>
+
     <TABLE NAME="gradeimporter_feedback" COMMENT="This table is responsible to link the feedback files from a certain submission to the student" PREVIOUS="gradeimporter_submissiontype">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="submissionid"/>
@@ -87,7 +93,11 @@
         <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"
                     PREVIOUS="usermodified" NEXT="timemodified"/>
         <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"
-                    PREVIOUS="timecreated"/>
+                    PREVIOUS="timecreated" NEXT="contextid"/>
+        <FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"
+                    PREVIOUS="timemodified" NEXT="filename"/>
+        <FIELD NAME="name" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false" COMMENT="File name to fetch at pluginfile." 
+                    PREVIOUS="contextid"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>

+ 5 - 0
lang/en/gradeimporter.php

@@ -64,6 +64,11 @@ $string['newsubmission'] = "Add new submission";
     //submission form errors
 
 
+//Submission type 
+    $string['newsubtype'] = 'Add new submission type';
+
+    //Submission type help
+    $string['newsubtype_help'] = 'Goes to new sub type form (sub type examples: Exam, Test, Activity)';
 
 //events string
     $string['eventmodelsubmissioncreated'] = 'Submission created';

+ 15 - 29
lib.php

@@ -95,32 +95,18 @@ function gradeimporter_check_for_zips ($context, $cm, $submission){
 
     $fs = get_file_storage();
     $files = $fs->get_area_files($context->id, 'mod_gradeimporter', 'submission', $submission->id, "itemid, filepath, filename", false);
-echo "---- DEBUG ---- \n linha 96\n";
     foreach ($files as $storedfile) {
       if ($storedfile->get_mimetype() == 'application/zip') {
-        echo "---- DEBUG ---- \n linha 99 - unpack zip \n";
         //unpack zip
         $packer = get_file_packer('application/zip');
         $fs->delete_area_files($context->id, 'mod_gradeimporter', 'unpacktemp', 0);
         $storedfile->extract_to_storage($packer, $context->id, 'mod_gradeimporter', 'unpacktemp', 0, "item, filepath, filename", false);
         $tempfiles = $fs->get_area_files($context->id, 'mod_gradeimporter', 'unpacktemp', 0, "itemid, filepath, filename", false);
         if (count($tempfiles) > 0) {
-          echo "---- DEBUG ---- \n linha 105 - tempfiles > 0 \n";
           $storedfile->delete(); // delete the zip
 
-          foreach ($tempfiles as $storedfile){
-            //copy files to known directory
-
-            echo $storedfile->get_filename();
-            echo "  mimetype  ";
-            echo $storedfile->get_mimetype();
-            echo "file location";
-            echo $storedfile->get_filepath(). ' \n ';
-          }
-
           foreach ($tempfiles as $storedfile){
             if ($storedfile->get_mimetype() == 'text/csv'){
-              echo "---- DEBUG ---- \n linha 110 - achou csv \n";
 
               $csvData = $storedfile->get_content();
               $csvLines = explode(PHP_EOL, $csvData);
@@ -128,38 +114,38 @@ echo "---- DEBUG ---- \n linha 96\n";
               foreach($csvLines as $line){
                 $csv[] = str_getcsv($line);
               }
-              print_r($csv);
               //array_map('str_getcsv', $storedfile->get_content() );
               array_walk($csv, function(&$a) use ($csv) { //adds first row as keys
                 $a = array_combine($csv[0], $a);
               });
               array_shift($csv); // remove column header
-  print_r($csv);
               for ($i = 0; $i< sizeof($csv); $i++){
-                $fileinfo = array(
-                  'contextid'   =>  $context->id,
-                  'component'   =>  'mod_gradeimporter',
-                  'filearea'    =>  'submission',
-                  'itemid'      =>  $submission->id,
-                  'filepath'    =>  '/',
-                  'file'        =>  $csv[$i]['file'],
-                  'studentid'   => $csv[$i]['id']
-                );
-
                 foreach ($tempfiles as $storedfile) {
-                  echo '---- DEBUG ---- \n linha 129 - file name'.$storedfile->get_filename();
                   if ($storedfile->get_filename() == $csv[$i]['file']){
-                    $storedfile = $fs->create_file_from_storedfile($fileinfo, $storedfile);
+
+                    $fileinfo = array(
+                      'contextid'   =>  $context->id,
+                      'component'   =>  'mod_gradeimporter',
+                      'filearea'    =>  'gradeimporter_feedback',
+                      'itemid'      =>  $submission->id,
+                      'filepath'    =>  '/'.$csv[$i]['file'].'.',
+                      'filename'        =>  $csv[$i]['file']
+                    );
+
+                    //$storedfile = $fs->create_file_from_storedfile($fileinfo, $storedfile);
+
                     $dbentry = new stdClass();
                     $dbentry->id = null;
                     $dbentry->submissionid  = $submission->id;
                     $dbentry->studentid     = $csv[$i]['id'];
                     $dbentry->grade        = $csv[$i]['grade'];
                     $dbentry->comment      = $csv[$i]['comment'];
-                    $dbentry->fileid      = $storedfile;
+                    $dbentry->fileid      = 0; //precisa consertar
                     $dbentry->usermodified = 0;
                     $dbentry->timecreated   = time();
                     $dbentry->timemodified   = time();
+                    $dbentry->contextid   = $context->id;
+                    $dbentry->name    = $csv[$i]['file'];
 
                     $dbentry->id = $DB->insert_record('gradeimporter_feedback', $dbentry);
                     break;

+ 12 - 7
locallib.php

@@ -4,24 +4,26 @@ namespace gradeimporter;
 
 class feedback {
     public static function get_comments() {
-        global $DB, $USER;
+        global $DB, $USER, $CFG;
+        $tp = $CFG->prefix; // gets moodle tables prefix, not everyone uses mdl_
 
         $sql = "
         SELECT gf.id,
                gf.grade,
                gf.comment,
+               gf.contextid,
+               gf.name gf_name,
                gs.name gs_name,
                gs.description gs_description,
                gst.name gst_name,
-               gst.info gst_info,
+               gst.description gst_description,
                fileid
-          FROM mdl_gradeimporter_feedback gf
-          JOIN mdl_gradeimporter_submission gs
+          FROM ".$tp."gradeimporter_feedback gf
+          JOIN ".$tp."gradeimporter_submission gs
             ON gf.submissionid = gs.id
-          JOIN mdl_gradeimporter_submissiontype gst
+          JOIN ".$tp."gradeimporter_submissiontype gst
             ON gs.type = gst.id
          WHERE gf.studentid = ?";
-
         $comments = array();
         $records = $DB->get_records_sql($sql, array('studentid'=>$USER->id));
 
@@ -29,8 +31,11 @@ class feedback {
         if (count($records)) {
           foreach ($records as $key => $value) {
             if (!array_key_exists($value->gst_name, $data)) $data[$value->gst_name] = array();
+            
+              //$fileurl = moodle_url::make_pluginfile_url($value->gf_contextid, 'mod_gradeimporter', 'gradeimporter_feedback', $value->gf_submissionid, '/', $value->gf_filename, false);
 
-              $data[$value->gst_name][] = array($value->gs_name, $value->grade, $value->fileid);
+              $data[$value->gst_name][] = array($value->gs_name, $value->grade, $value->gf_name);
+              //$data[$value->gst_name][] = array($value->gs_name, $value->grade, $value->fileid);
           }
         }
 

+ 0 - 50
mod_form.php

@@ -49,54 +49,4 @@
             $this->add_action_buttons();
             }
 
-//$DB->insert_record($table, $dataobject, $returnid, $bulk); insert records on db
-
-        /*function data_preprocessing (&$default_values) {
-            parent::data_preprocessing($default_values);
-        
-            $mform = & $this->_form;
-        
-            if (!$mform->isSubmitted() && array_key_exists('name', $default_values)) {
-                //TODO Remove when updating all the iassign that are tag &lt;ia_uc&gt;
-                //$ia_uc = explode('&lt;ia_uc&gt;', $default_values['name']);
-                //$default_values['name'] = $ia_uc[0];
-                }
-            }*/
-
-       /* function definition_after_data() {
-            global $DB;
-        
-            $mform = & $this->_form;
-            $data = $mform->exportValues();
-        
-           if ($mform->isSubmitted()) {
-        
-                $iassign_statements = $data['iassign_statement'];
-                foreach ($iassign_statements as $key => $value) {
-                if ($value == 1) {
-                    $updateentry = new stdClass();
-                    $updateentry->id = $key;
-                    $updateentry->timemodified = time();
-        
-                    if (isset($data['grade_enabled']) && $data['grade_enabled'] == 1)
-                    $updateentry->grade = $data['grade'];
-                    if (isset($data['timedue_enabled']) && $data['timedue_enabled'] == 1)
-                    $updateentry->timedue = $data['timedue'];
-                    if (isset($data['timeavailable_enabled']) && $data['timeavailable_enabled'] == 1)
-                    $updateentry->timeavailable = $data['timeavailable'];
-                    if (isset($data['preventlate_enabled']) && $data['preventlate_enabled'] == 1)
-                    $updateentry->preventlate = $data['preventlate'];
-                    if (isset($data['test_enabled']) && $data['test_enabled'] == 1)
-                    $updateentry->test = $data['test'];
-                    if (isset($data['max_experiment_enabled']) && $data['max_experiment_enabled'] == 1)
-                    $updateentry->max_experiment = $data['max_experiment'];
-        
-                    if (!$DB->update_record("iassign_statement", $updateentry))
-                    print_error('error_update', 'iassign');
-                    }
-                }
-                }
-            }*/
-
-            
     }

+ 5 - 86
submission.php

@@ -5,11 +5,10 @@ require_once('locallib.php');
 require_once('lib.php');
 require_once('submission_form.php');
 
-echo "pagina submission";
-
 
 $cmid = required_param('cmid', PARAM_INT);            // Course Module ID
-$id      = required_param('id' , PARAM_INT);           //Gradeimporter id
+$id      = optional_param('id' , 0, PARAM_INT);           //Gradeimporter id
+$subid  =   optional_param('subid', 1, PARAM_INT);       //submission id
 //$delete  = optional_param('delete', 0, PARAM_INT);
 //$confirm = optional_param('confirm', 0, PARAM_INT);
 
@@ -60,7 +59,7 @@ $submission = file_prepare_standard_filemanager($submission, 'submission', $subm
 
 $submission->cmid = $cm->id;
 
-$mform = new mod_gradeimporter_submission_form(null, array('submission'=>$submission, 'cm'=>$cm, 'descriptionoptions'=>$descriptionoptions, 'submissionoptions'=>$submissionoptions));
+$mform = new mod_gradeimporter_submission_form(null, array('submission'=>$submission, 'cm'=>$cm, 'descriptionoptions'=>$descriptionoptions, 'submissionoptions'=>$submissionoptions, 'gradeimporterid'=>$gradeimporter->id));
 
 if ($mform->is_cancelled()){
     if ($id){
@@ -118,7 +117,7 @@ if ($mform->is_cancelled()){
         }
     }
 
-    redirect("view.php?id=$cm->id&edition=1");
+    redirect("view.php?id=$cm->id&edit=1");
 }
 
 if(!empty($id)) {
@@ -135,84 +134,4 @@ if ($gradeimporter->intro){
 
 $mform->display();
 
-echo $OUTPUT->footer();
-
-//codigo antigo
-/*if (!$gradeimporter = $DB->get_record('gradeimporter', array('id' => $id))) {
-    print_error('invalidgradeimproterdid', 'gradeimporter');
-}
-
-list($course, $cm) = get_course_and_cm_from_instance($gradeimporter, 'gradeimporter');
-
-if ($delete && ! $submission = $DB->get_record('gradeimporter_sumbmission', array('gradeimporterid' => $gradeimporter->id, 'id' => $delete))) {
-    print_error('Invalid comment ID');
-}
-
-require_login($course, true, $cm);
-
-$PAGE->set_cm($cm);
-$PAGE->set_url('/mod/gradeimporter/view.php', array('id' => $id));
-$PAGE->set_title($gradeimporter->name);
-$page->set_heading($course->shortname);
-
-$context = context_module::instance($cm->id);
-
-$gradeimporterurl = $CFG->wwwroot.'mod/gradeimporter/view.php?id='.$cm->id;
-
-if ($delete && has_capability('mod/wavefront:edit', $context)) {
-    if($confirm && confirm_sesskey()) {
-        $DB->delete_records('gradeimporter_submission', array('id' => $comment->id));
-        redirect($gradeimporterurl);
-    } else {
-        echo $OUTPUT->header();
-        $paramyes = array('id' => $gradeimporter->id, 'delete' => $gradeimporter->id, 'sesskey' => sesskey(), 'confirm' => 1);
-        $paramsno = array('id' => $cm->id);
-        echo $OUTPUT->confirm(get_string('submissiondelete', 'gradeimporter'),
-                                new moodle_url('/mod/gradeimporter/submission.php', $paramsyes),
-                                new moodle_url('/mod/gradeimporter/view.php', $paramsno));
-        echo $OUTPUT->footer();
-        die();
-    }
-}
-
-require_capability('mod/gradeimporter/addsubmission', $context);
-
-if(!$gradeimporter->submission) {
-    print_error('Submissions disabled', $gradeimporterurl);
-}
-
-$mform = new mod_gradeimporter_submission_form(null, $gradeimporter);
-
-if ($mform-is_cancelled()) {
-    redirect($gradeimporterurl);
-} else if ($formdata = $mform->get_data()) {
-    $newsubmission = new stdClass;
-    $newsubmission->gradeimporter = $gradeimporter->id;
-    $newsubmission->type = $formdata->type;
-    $newsubmission->timemodified = time();
-    $newsubmission->usermodified = $USER->id;
-    //$newsubmission->name = $formdata->name;
-    //$newsubmission->info = $formdata->info;
-    $newsubmission->position = $formdata->position;
-    $newsubmission->visibility = $formdata->visibility;
-    
-    if ($DB->insert_record('gradeimporter_submission', $newsubmission)) {
-        $params = array($cmid = required_param('cmid', PARAM_INT);            // Course Module ID
-            'context' => $context,
-            'other' => array(
-                'gradeimporterid' => $gradeimporter->id
-            )
-        );
-        $event = \mod_gradeimporter\event\gradeimporter_submission_created::create($params);
-        $event->trigger();
-        redirect($gradeimporterurl, get_string('submission added', 'gradeimporter'));
-    } else {
-        print_error('gradeimporter creation failed');
-    }
-}
-
-echo $OUTPUT->header();
-
-$mform->display();
-
-echo $OUTPUT->footer();*/
+echo $OUTPUT->footer();

+ 20 - 3
submission_form.php

@@ -19,6 +19,7 @@
             $cm                 = $this->_customdata['cm'];
             $descriptionoptions = $this->_customdata['descriptionoptions'];
             $submissionoptions  = $this->_customdata['submissionoptions'];
+            $gradeimporterid    = $this->_customdata['gradeimporterid'];
 
             $context = context_module::instance($cm->id);
             $fmtoptions = array('context'=>$context);
@@ -39,11 +40,25 @@
 
             $mform->addElement('header', 'filehandling', get_string('filehandling', 'gradeimporter'));
 
+            $url = new moodle_url('/mod/gradeimporter/submissiontype.php?id='.$gradeimporterid.'&cmid='.$cm->id.'&page=0');
+            $newSubTypeContent = '<a href='.$url.'>'.get_string('newsubtype', 'gradeimporter').'</a>';
+            /*$newSubTypeContent = '<form action="'. $url . '">'.
+                    '<input type="hidden" name="id" value="'. $gradeimporter->id .'" />'.
+                    '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
+                    '<input type="hidden" name="page" value="0" />'.
+                    '<input type="submit" Value="'.get_string('newsubtype', 'gradeimporter').'" />'.
+                    '</form>';*/
+            $mform->addElement('html', $newSubTypeContent);
+
             //submission type
+            $submissionTypesRecords = $DB->get_records('gradeimporter_submissiontype', null, 'id', 'id, name, description');
+            $submissionTypesRecords = array_values($submissionTypesRecords);
             $submissionType = array();
-            $submissionType[0] = get_string('exam', 'gradeimporter');
-            $submissionType[1] = get_string('activity', 'gradeimporter');
-            
+
+            foreach (array_keys($submissionTypesRecords) as $key){
+                $submissionType[$submissionTypesRecords[$key]->id] = $submissionTypesRecords[$key]->name;
+            }
+
    
             $mform->addElement('select', 'type', get_string('submissionType', 'gradeimporter'), $submissionType, array('onChange' => 'config_type(this.value);'));
             //$mform->setDefault('submissionType', 0); // default submissionType = 3
@@ -53,6 +68,8 @@
             $mform->addElement('filemanager', 'submission_filemanager', get_string('submissionFiles', 'gradeimporter'), null, $descriptionoptions);
             $mform->addHelpButton('submission_filemanager', 'submissionFiles', 'gradeimporter');
 
+            
+
             //csv delimiter
             $csv_delimiter = array();
             $csv_delimiter[1] = ',';

+ 114 - 0
submissiontype.php

@@ -0,0 +1,114 @@
+<?php
+
+require_once('../../config.php');
+require_once('locallib.php');
+require_once('lib.php');
+require_once('submissiontype_form.php');
+
+
+$cmid = required_param('cmid', PARAM_INT);            // Course Module ID
+$id   = required_param('id' , PARAM_INT);           //Gradeimporter id
+
+if (!$cm = get_coursemodule_from_id('gradeimporter', $cmid)){
+    print_error('invalidcoursemodule');
+}
+
+if (!$course = $DB->get_record('course', array('id'=>$cm->course))){
+    print_error('coursemisconf');
+}
+
+$context = context_module::instance($cm->id);
+
+require_capability('mod/gradeimporter:edit', $context);
+
+if (!$gradeimporter = $DB->get_record('gradeimporter', array('id'=>$cm->instance))){
+    print_error('invalidid', 'gradeimporter');
+}
+
+$url = new moodle_url('/mod/gradeimporter/submissiontype.php', array('cmid'=>$cm->id));
+if (!empty($id)){
+    $url->param('id', $id);
+}
+$PAGE->set_url($url);
+
+require_login($course, false, $cm);
+
+//attempt to get the correct type
+$submissiontype = $DB->get_record('gradeimporter_submissiontype', array('gradeimporterid'=>$gradeimporter->id));
+
+if ($submissiontype){
+    if (isguestuser()){
+        print_error('guestnoedit', 'gradeimporter', "$CFG->wwwroot/mod/gradeimporter/view.php?id=$cmid");
+    }
+} else {
+
+    $submissiontype = new stdClass();
+    $submissiontype->id = null;
+}
+
+$maxfiles = 50;
+$maxbytes = $course->maxbytes;
+
+$descriptionoptions = array('trusttext'=>true, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes, 'context'=>$context, 'subdirs'=>file_area_contains_subdirs($context, 'mod_gradeimporter', 'submissiontype', $submissiontype->id));
+$submissiontypeoptions = array('subdirs'=>false, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes);
+
+$submissiontype = file_prepare_standard_editor($submissiontype, 'description', $descriptionoptions, $context, 'mod_gradeimporter', 'description', $submissiontype->id);
+$submissiontype->cmid = $cm->id;
+
+$mform = new mod_gradeimporter_submissiontype_form(null, array('submissiontype' =>$submissiontype, 'cm'=>$cm, 'descriptionoptions'=>$descriptionoptions, 'submissiontypeoptions'=>$submissiontypeoptions));;
+
+if ($mform->is_cancelled()){
+    if ($id){
+        redirect("view.php?id=$cm->id&mode=entry&hook=$id");
+    } else{
+        redirect("view.php?id=$cm->id");
+    }
+} else if ($submissiontype = $mform->get_data()){
+    if (empty($submissiontype->id)){
+        $submissiontype->gradeimporterid    = $gradeimporter->id;
+        
+        $isnewentry                         = true;
+    } else{
+        $isnewentry                         = false;
+    }
+
+    $submissiontype->description        ='';
+    $submissiontype->descriptionformat  = FORMAT_HTML;
+    $submissiontype->definitiontrust    = 0;
+    
+    if ($isnewentry){
+        $submissiontype->id = $DB->insert_record('gradeimporter_submissiontype', $submissiontype);
+    } else{
+        $DB->update_record('gradeimporter', $submissiontype);
+    }
+
+    $submissiontype = file_postupdate_standard_editor($submissiontype, 'description', $descriptionoptions, $context, 'mod_gradeimporter', 'submissiontype', $submissiontype->id);
+
+    $DB->update_record('gradeimporter_submissiontype', $submissiontype);
+
+    if ($isnewentry){
+        //update completion state
+        $completion = new completion_info($course);
+        if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $gradeimporter->completionentries) {
+            $completion->update_state($cm, COMPLETION_COMPLETE);
+        }
+    }
+
+    redirect("submission.php?id=$id&cmid=$cm->id&page=0");
+}
+
+if (!empty($id)){
+    $PAGE->navbar->add(get_string('edit'));
+}
+
+$PAGE->set_title($gradeimporter->name);
+$PAGE->set_heading($course->fullname);
+echo $OUTPUT->header();
+echo $OUTPUT->heading(format_string($gradeimporter->name), 2);
+if($gradeimporter->intro){
+    echo $OUTPUT->box(format_module_intro('gradeimporter', $gradeimporter, $cm->id), 'generalbox', 'intro');
+}
+
+$mform->display();
+
+echo $OUTPUT->footer();

+ 46 - 0
submissiontype_form.php

@@ -0,0 +1,46 @@
+<?php
+    if (!defined('MOODLE_INTERNAL')) {
+        die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
+    }
+
+    require_once($CFG->dirroot.'/lib/formslib.php');
+
+    class mod_gradeimporter_submissiontype_form extends moodleform{
+
+        function definition(){
+            global $CFG, $DB;
+
+            $mform =& $this->_form;
+
+            $submissiontype = $this->_customdata['submissiontype'];
+            $cm             = $this->_customdata['cm'];
+            $descriptionoptions = $this->_customdata['descriptionoptions'];
+            $submissiontypeoptions  = $this->_customdata['submissiontypeoptions'];
+
+            $context    = context_module::instance($cm->id);
+            $fmtoptions = array('context'=>$context);
+
+            //-------------------form starts here
+            $mform->addElement('header', 'general', get_string('general', 'form'));
+
+            //submission type name
+            $mform->addElement('text', 'name', get_string('name', 'gradeimporter'), array('size'=>'64'));
+            $mform->setType('name', PARAM_TEXT);
+            $mform->addRule('name', get_string('error_nameField', 'gradeimporter'), 'required', null, 'client');
+
+            //description
+            $mform->addElement('editor', 'description_editor', get_string('submissionDescription', 'gradeimporter'), null, $descriptionoptions);
+            $mform->setType('description_editor', PARAM_RAW);
+
+            //hidden fields
+            $mform->addElement('hidden', 'id');
+            $mform->setType('id', PARAM_INT);
+            $mform->addElement('hidden', 'cmid');
+            $mform->setType('cmid', PARAM_INT);
+
+            //buttons
+            $this->add_action_buttons();
+
+            $this->set_data($submissiontype);
+        }
+    }

+ 1 - 0
view.php

@@ -4,6 +4,7 @@
 
     global $DB;
 
+
     $id = optional_param('id', 0, PARAM_INT); // course_module ID, or
     $g  = optional_param('g', 0, PARAM_INT);  // gradeimporter instance ID, should be named as the first character of the module