Browse Source

install.xml with new table iassign_allsubmissions

Igor 3 years ago
commit
3d84a13595
100 changed files with 3429 additions and 0 deletions
  1. 77 0
      README.txt
  2. 10 0
      backup/index.html
  3. 73 0
      backup/moodle2/backup_iassign_activity_task.class.php
  4. 132 0
      backup/moodle2/backup_iassign_stepslib.php
  5. 10 0
      backup/moodle2/index.html
  6. 115 0
      backup/moodle2/restore_iassign_activity_task.class.php
  7. 154 0
      backup/moodle2/restore_iassign_stepslib.php
  8. 51 0
      classes/event/course_module_instance_list_viewed.php
  9. 99 0
      classes/event/course_module_viewed.php
  10. 99 0
      classes/event/iassign_created.php
  11. 99 0
      classes/event/iassign_deleted.php
  12. 99 0
      classes/event/iassign_updated.php
  13. 10 0
      classes/event/index.html
  14. 99 0
      classes/event/submission_comment_created.php
  15. 99 0
      classes/event/submission_comment_updated.php
  16. 99 0
      classes/event/submission_created.php
  17. 99 0
      classes/event/submission_updated.php
  18. 99 0
      classes/event/submission_viewed.php
  19. 10 0
      classes/index.html
  20. 128 0
      db/access.php
  21. 10 0
      db/index.html
  22. 159 0
      db/install.php
  23. 191 0
      db/install.xml
  24. 35 0
      db/log.php
  25. 43 0
      db/uninstall.php
  26. 680 0
      db/upgrade.php
  27. 72 0
      grade.php
  28. 568 0
      iassign_form.php
  29. BIN
      icon/__comment_unread.gif
  30. BIN
      icon/add.gif
  31. BIN
      icon/add_iassign.gif
  32. BIN
      icon/add_ilm_iassign.gif
  33. BIN
      icon/add_param.gif
  34. BIN
      icon/addgreen.gif
  35. BIN
      icon/block.gif
  36. BIN
      icon/comment_close red.gif
  37. BIN
      icon/comment_close_green.gif
  38. BIN
      icon/comment_close_red1.gif
  39. BIN
      icon/comment_close_yellown.gif
  40. BIN
      icon/comment_read.gif
  41. BIN
      icon/comment_unread.gif
  42. BIN
      icon/config_ilm.gif
  43. BIN
      icon/confirm.gif
  44. BIN
      icon/copy_ilm.gif
  45. BIN
      icon/copy_param.gif
  46. BIN
      icon/correct.gif
  47. BIN
      icon/default_ilm.gif
  48. BIN
      icon/default_ilm_disabled.gif
  49. BIN
      icon/delete2.gif
  50. BIN
      icon/delete_assign_disable.gif
  51. BIN
      icon/delete_dir.gif
  52. BIN
      icon/delete_dir_disable.gif
  53. BIN
      icon/delete_iassign.gif
  54. BIN
      icon/delete_ilm.gif
  55. BIN
      icon/delete_ilm_disable.gif
  56. BIN
      icon/delete_param.gif
  57. BIN
      icon/dir.gif
  58. BIN
      icon/down_disable.gif
  59. BIN
      icon/download_all_assign.gif
  60. BIN
      icon/download_all_assign_disabled.gif
  61. BIN
      icon/download_assign.gif
  62. BIN
      icon/duplicate_iassign.gif
  63. BIN
      icon/edit_iassign.gif
  64. BIN
      icon/edit_iassign_disable.gif
  65. BIN
      icon/edit_ilm.gif
  66. BIN
      icon/edit_param.gif
  67. BIN
      icon/example.gif
  68. BIN
      icon/export_ilm.gif
  69. BIN
      icon/feedback_correct.gif
  70. BIN
      icon/feedback_incorrect.gif
  71. BIN
      icon/file.gif
  72. BIN
      icon/hbar_blue.gif
  73. BIN
      icon/hbar_blue_l.gif
  74. BIN
      icon/hbar_blue_r.gif
  75. BIN
      icon/hbar_green.gif
  76. BIN
      icon/hbar_green_l.gif
  77. BIN
      icon/hbar_green_r.gif
  78. BIN
      icon/hbar_orange.gif
  79. BIN
      icon/hbar_orange_l.gif
  80. BIN
      icon/hbar_orange_r.gif
  81. BIN
      icon/hbar_red.gif
  82. BIN
      icon/hbar_red_l.gif
  83. BIN
      icon/hbar_red_r.gif
  84. BIN
      icon/help_ilm.gif
  85. BIN
      icon/hide_iassign.gif
  86. BIN
      icon/hide_ilm.gif
  87. BIN
      icon/hide_param.gif
  88. BIN
      icon/home.gif
  89. BIN
      icon/icon.gif
  90. BIN
      icon/incorrect.gif
  91. 10 0
      icon/index.html
  92. BIN
      icon/left_disable.gif
  93. BIN
      icon/maximize.png
  94. BIN
      icon/move_activity.gif
  95. BIN
      icon/move_down_iassign.gif
  96. BIN
      icon/move_up_iassign.gif
  97. BIN
      icon/next_activity.gif
  98. BIN
      icon/next_student.gif
  99. BIN
      icon/next_student_activity.gif
  100. 0 0
      icon/no_edit_iassign.gif

+ 77 - 0
README.txt

@@ -0,0 +1,77 @@
+iAssign version 2.1.70
+------------------------
+
+By iMatica/iMath - free interactive tools for teaching-learning Math
+   Patricia Rodrigues <patricnet@ig.com.br>, Leônidas O. Brandão <leo@ime.usp.br>
+
+
+.: About iAssign :.
+
+This is the iAssign (Interactive Assignment) package, an iMath free system to enrich activities in Moodle. 
+It is created by Patricia Rodrigues and Leônidas de Oliveira Brandão.
+
+iAssign's goal is to increase interactivity in activities related to specific subjects (such as Geometry, Functions, Programming,...)
+in a flexible way. 
+
+In order to improve interactivity, iAssign makes use of iLM (interactive Learning Module),
+that is any interactive tool that runs under a Web browser.
+Typically an iLM is a Java applet or an HTML5 package with a few (mandatory) communication methods, all based on HTTP protocol.
+This implies that any applet can easily became an iLM and can be integrated to Moodle under iAssign package. 
+
+If the iLM offers automatic assessment functionality, iAssign is able
+to deal with it. Under such iLM, iAssign provides immediate feedback to
+the student, and the teachers can get instant information about their
+activities (including reports about the student performance).
+
+It can be added new iLM into iAssign, at any time, but (for security
+reason), only the administrator has the privilege of integrating new iLM into iAssign.
+Once integrated, an iLM can be used by anyone registered in its Moodle.
+For instance, an user with privileges of "teacher" is allowed to use
+the iAssign authoring tools to create activities with any iLM
+(like iGeom, iGraf, or iVprog, respectively to related to the subjects, Geometry, Functions and Programming).
+
+The main features of iAssign package are:
+ - The authoring tool to allow any teacher to easily prepare activities to students. Activities can be:
+   + an exercise (the student must send an answer, and if the iLM has automatic assessment, its results (right/wrong) is also registered);
+   + a test (the student does the activity, if iLM has automatic assessment, the student gets immediate feedback, but no data is recorded in Moodle's database);
+   + an example (the student can interact with the example, but nothing is recorded).
+ - Reports about students activities: 
+   + teachers can see, e.g., a survey or statistics about student's answers and can have quick access to any submited answer;
+   + the students have a survey of their activities (including their grades)
+ - Integration with general Moodle grades
+ - A filter that allows the insertion of iLM content into any (asynchronous) Moodle text.
+
+Besides, as the majority of Moodle modules, iAssign can export (as backup) one activity or a complete lesson (a set of activities).
+
+Note: This plugin is part of iAssign SET see more in https://moodle.org/plugins/browse.php?list=set&id=54
+
+.: Quick install instructions (to be used by the system administrator) :.
+
+0) Be sure you have (at least) Moodle 2.4 until Moodle 2.6 installed
+1) Be sure to have the latest language package, such as English (en), Portuguese (pt_br).
+2) Be sure to have the latest version of the module iAssign (see in https://github.com/leonidasbrandao/iAssign master)
+3) Unpack 'iAssign.2.1.x.zip' (or 'iAssign.2.1.x.tgz')
+4) Copy the 'iassign' module directory into the "mod" subdirectory of Moodle installation
+5) Under role "administrator", go to the 'Site administration' and click on 'Notifications'
+6) Have fun.
+
+
+.: What is news :.
+
+Considering the iAssign for Moodle 1.9, the new featuress in this version are:
+
+ - the teacher can produce a new interactive activity directly "on-line", using the new iLM editor (but is still possible to upload files);
+ - in a course with more than one teacher, it is now possible to use a local repository.
+ - See more in http://docs.moodle.org/en/iAssign.
+
+
+Comments and suggestions are always welcome at http://www.matematica.br/iassign or https://github.com/leonidasbrandao/iAssign.
+(if the comment area is missing, please send us an email).
+
+
+Best regards,
+
+Leônidas <leo@ime.usp.br> and Patricia <patricnet@ig.com.br>
+
+Institute of Mathematics and Statistics - University of São Paulo
+iMath/LInE : http://www.matematica.br : http://line.ime.usp.br

+ 10 - 0
backup/index.html

@@ -0,0 +1,10 @@
+<html>
+    <head>
+        <meta charset="UTF-8">
+        <title>Acess not allowed! - Acesso não permitido</title>
+    </head>
+    <body style="color: #FF0000">
+        <p>Acesso não permitido!</p>
+        <p>Acess not allowed!</p>
+    </body>
+</html>

+ 73 - 0
backup/moodle2/backup_iassign_activity_task.class.php

@@ -0,0 +1,73 @@
+<?php
+
+/**
+ * This file contains the backup task for the iAssign module
+ * 
+ * Release Notes:
+ * - v 1.1 2014/01/06
+ * 		+ Fix bug in activity name, remove tag filter (backup_iassign_activity_task::define_my_settings).
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.1 2014/01/06
+ * @package mod_iassign_backup
+ * @since 2012
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * 
+ * <b>License</b> 
+ *  - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ *  
+ * @see backup_activity_task
+ */
+/**
+ * Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly.
+ */
+defined('MOODLE_INTERNAL') || die();
+
+require_once($CFG->dirroot . '/mod/iassign/backup/moodle2/backup_iassign_stepslib.php');
+
+/**
+ * Provides the steps to perform one complete backup of the iAssign instance
+ * @see backup_activity_task
+ */
+class backup_iassign_activity_task extends backup_activity_task {
+
+  /**
+   * No specific settings for this activity
+   */
+  protected function define_my_settings () {
+
+    //TODO Retirar quando atualizar todo os iassigns que estão com a tag &lt;ia_uc&gt;
+    $temp = explode("&lt;ia_uc&gt;", $this->name);
+    $this->name = $temp[0];
+  }
+
+  /**
+   * Defines a backup step to store the instance data in the iassign.xml file
+   */
+  protected function define_my_steps () {
+    $this->add_step(new backup_iassign_activity_structure_step('iassign_structure', 'iassign.xml'));
+  }
+
+  /**
+   * Encodes URLs to various iAssign scripts
+   * @param string $content some HTML text that eventually contains URLs to the activity instance scripts
+   * @return string The content with the URLs encoded
+   */
+  static public function encode_content_links ($content) {
+    global $CFG;
+
+    $base = preg_quote($CFG->wwwroot, "/");
+    //  $base = preg_quote($CFG->wwwroot.'/mod/iassign','#');
+    // Link to the list of choices
+    $search = "/(" . $base . "\/mod\/iassign\/index.php\?id\=)([0-9]+)/";
+    $content = preg_replace($search, '$@IASSIGNINDEX*$2@$', $content);
+
+    // Link to choice view by moduleid
+    $search = "/(" . $base . "\/mod\/iassign\/view.php\?id\=)([0-9]+)/";
+    $content = preg_replace($search, '$@IASSIGNVIEWBYID*$2@$', $content);
+
+    return $content;
+  }
+
+}

+ 132 - 0
backup/moodle2/backup_iassign_stepslib.php

@@ -0,0 +1,132 @@
+<?php
+
+/**
+ * Define all the backup steps that will be used by the backup_iassign_activity_task
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2012
+ * @package mod_iassign_backup
+ * @since 2012
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * 
+ * <b>License</b> 
+ *  - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ *  
+ * @see backup_activity_structure_step
+ */
+/**
+ * Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly.
+ */
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Define the complete choice structure for backup, with file and id annotations
+ * @see backup_activity_structure_step
+ */
+class backup_iassign_activity_structure_step extends backup_activity_structure_step {
+
+  /**
+   * Define the structure for the iassign activity
+   * @return void Return the root element (choice), wrapped into standard activity structure
+   */
+  protected function define_structure () {
+
+    // To know if we are including userinfo
+    $userinfo = $this->get_setting_value('userinfo');
+
+    $iassign = new backup_nested_element('iassign', array('id'), array('name',
+      'course',
+      'intro',
+      'introformat',
+      'activity_group',
+      'grade',
+      'timeavailable',
+      'timedue',
+      'preventlate',
+      'test',
+      'max_experiment'));
+
+    $statements = new backup_nested_element('statements');
+
+    $statement = new backup_nested_element('statement', array('id'), array('name',
+      'iassignid',
+      'type_iassign',
+      'proposition',
+      'author_name',
+      'author_modified_name',
+      'iassign_ilmid',
+      'file',
+      'grade',
+      'timecreated',
+      'timemodified',
+      'timeavailable',
+      'timedue',
+      'preventlate',
+      'test',
+      'special_param1',
+      'position',
+      'visible',
+      'max_experiment',
+      'dependency',
+      'automatic_evaluate',
+      'show_answer'));
+
+    $iassign_submissions = new backup_nested_element('iassign_submissions');
+
+    $iassign_submission = new backup_nested_element('iassign_submission', array('id'), array('iassign_statementid',
+      'userid',
+      'timecreated',
+      'timemodified',
+      'grade',
+      'teacher',
+      'answer',
+      'experiment',
+      'status'));
+
+    $iassign_submission_comments = new backup_nested_element('iassign_submission_comments');
+
+    $iassign_submission_comment = new backup_nested_element('iassign_submission_comment', array('id'), array('iassign_submissionid',
+      'comment_authorid',
+      'timecreated',
+      'comment',
+      'return_status',
+      'receiver'));
+    // Build the tree
+
+    $iassign->add_child($statements);
+    $statements->add_child($statement);
+
+    $statement->add_child($iassign_submissions);
+    $iassign_submissions->add_child($iassign_submission);
+
+    $iassign_submission->add_child($iassign_submission_comments);
+    $iassign_submission_comments->add_child($iassign_submission_comment);
+
+
+    // Define sources
+    $iassign->set_source_table('iassign', array('id' => backup::VAR_ACTIVITYID));
+
+    $statement->set_source_sql('
+            SELECT *
+              FROM {iassign_statement}
+             WHERE iassignid = ?', array(backup::VAR_PARENTID));
+
+    if($userinfo) {
+      $iassign_submission->set_source_table('iassign_submission', array('iassign_statementid' => backup::VAR_PARENTID));
+
+      $iassign_submission_comment->set_source_table('iassign_submission_comment', array('iassign_submissionid' => backup::VAR_PARENTID));
+    }
+
+    // Define id annotations
+    $iassign_submission->annotate_ids('user', 'userid');
+    $iassign_submission->annotate_ids('user', 'teacher');
+    $iassign_submission_comment->annotate_ids('user', 'comment_authorid');
+
+    // Define file annotations
+    $iassign->annotate_files('mod_iassign', 'exercise', null); // This file area hasn't itemid
+
+    return $this->prepare_activity_structure($iassign);
+  }
+
+}

+ 10 - 0
backup/moodle2/index.html

@@ -0,0 +1,10 @@
+<html>
+    <head>
+        <meta charset="UTF-8">
+        <title>Acess not allowed! - Acesso não permitido</title>
+    </head>
+    <body style="color: #FF0000">
+        <p>Acesso não permitido!</p>
+        <p>Acess not allowed!</p>
+    </body>
+</html>

+ 115 - 0
backup/moodle2/restore_iassign_activity_task.class.php

@@ -0,0 +1,115 @@
+<?php
+
+/**
+ * Define all the backup steps that will be used by the backup_iassign_activity_task
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2012
+ * @package mod_iassign_backup
+ * @since 2012
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * 
+ * <b>License</b> 
+ *  - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ *  
+ * @see restore_activity_task
+ */
+/**
+ * Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly.
+ */
+defined('MOODLE_INTERNAL') || die();
+
+require_once($CFG->dirroot . '/mod/iassign/backup/moodle2/restore_iassign_stepslib.php');
+
+/**
+ * iassign restore task that provides all the settings and steps to perform one complete restore of the activity.
+ */
+class restore_iassign_activity_task extends restore_activity_task {
+
+  /**
+   * Define (add) particular settings this activity can have.
+   */
+  protected function define_my_settings () {
+    // No particular settings for this activity
+  }
+
+  /**
+   * Define (add) particular steps this activity can have.
+   */
+  protected function define_my_steps () {
+    // iAssign only has one structure step
+    $this->add_step(new restore_iassign_activity_structure_step('iassign_structure', 'iassign.xml'));
+  }
+
+  /**
+   * Define the contents in the activity that must be
+   * processed by the link decoder.
+   * @return array Return a content of activity
+   */
+  static public function define_decode_contents () {
+    $contents = array();
+
+    $contents[] = new restore_decode_content('iassign', array('name'), 'iassign');
+
+    return $contents;
+  }
+
+  /**
+   * Define the decoding rules for links belonging
+   * to the activity to be executed by the link decoder.
+   * @return array Return the restore decode rule.
+   */
+  static public function define_decode_rules () {
+    $rules = array();
+
+    $rules[] = new restore_decode_rule('IASSIGNVIEWBYID', '/mod/iassign/view.php?id=$1', 'course_module');
+    $rules[] = new restore_decode_rule('IASSIGNINDEX', '/mod/iassign/index.php?id=$1', 'course_module');
+
+    return $rules;
+  }
+
+  /**
+   * Define the restore log rules that will be applied
+   * by the {@link restore_logs_processor} when restoring
+   * iassign logs. It must return one array
+   * of {@link restore_log_rule} objects.
+   * @return array Return the restore log rule.
+   */
+  static public function define_restore_log_rules () {
+    $rules = array();
+
+    $rules[] = new restore_log_rule('iassign', 'add', 'view.php?id={course_module}', '{iassign}');
+    $rules[] = new restore_log_rule('iassign', 'update', 'view.php?id={course_module}', '{iassign}');
+    $rules[] = new restore_log_rule('iassign', 'view', 'view.php?id={course_module}', '{iassign}');
+    $rules[] = new restore_log_rule('iassign', 'view submission', 'view.php?id={course_module}', '{iassign}');
+    $rules[] = new restore_log_rule('iassign', 'upload', 'view.php?id={course_module}', '{iassign}');
+    $rules[] = new restore_log_rule('iassign', 'update comment', 'view.php?id={course_module}', '{iassign}');
+    $rules[] = new restore_log_rule('iassign', 'update submission', 'view.php?id={course_module}', '{iassign}');
+    $rules[] = new restore_log_rule('iassign', 'delete iassign', 'view.php?id={course_module}', '{iassign}');
+    $rules[] = new restore_log_rule('iassign', 'add comment', 'view.php?id={course_module}', '{iassign}');
+    $rules[] = new restore_log_rule('iassign', 'add submission', 'view.php?id={course_module}', '{iassign}');
+    // more...
+
+    return $rules;
+  }
+
+  /**
+   * Define the restore log rules that will be applied
+   * by the {@link restore_logs_processor} when restoring
+   * course logs. It must return one array
+   * of {@link restore_log_rule} objects
+   *
+   * Note this rules are applied when restoring course logs
+   * by the restore final task, but are defined here at
+   * activity level. All them are rules not linked to any module instance (cmid = 0)
+   *
+   * @return array Return the restore log rule of course.
+   */
+  static public function define_restore_log_rules_for_course () {
+    $rules = array();
+
+    return $rules;
+  }
+
+}

+ 154 - 0
backup/moodle2/restore_iassign_stepslib.php

@@ -0,0 +1,154 @@
+<?php
+
+/**
+ * Define all the restore steps that will be used by the restore_iassign_activity_task
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2012
+ * @package mod_iassign_backup
+ * @since 2012
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * 
+ * <b>License</b> 
+ *  - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ *  
+ * @see restore_activity_structure_step
+ */
+/**
+ * Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly.
+ */
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Define the complete assignment structure for restore, with file and id annotations.
+ * @see restore_activity_structure_step
+ */
+class restore_iassign_activity_structure_step extends restore_activity_structure_step {
+
+  /**
+   * Define the structure of the restore workflow
+   * @return void Adds support for the 'exercise' path that is common to all the activities.
+   */
+  protected function define_structure () {
+
+    $paths = array();
+    // To know if we are including userinfo
+    $userinfo = $this->get_setting_value('userinfo');
+
+
+    // Define each element separated
+    $paths[] = new restore_path_element('iassign', '/activity/iassign');
+    $paths[] = new restore_path_element('iassign_statement', '/activity/iassign/statements/statement');
+
+
+
+    if($userinfo) {
+      $iassign_submissions = new restore_path_element('iassign_submission', '/activity/iassign/statements/statement/iassign_submissions/iassign_submission');
+      $paths[] = $iassign_submissions;
+      $iassign_submission_comments = new restore_path_element('iassign_submission_comment', '/activity/iassign/statements/statement/iassign_submissions/iassign_submission/iassign_submission_comments/iassign_submission_comment');
+      $paths[] = $iassign_submission_comments;
+    }
+    return $this->prepare_activity_structure($paths);
+  }
+
+  /**
+   * Process an ia restore
+   * @param object $data The data in object form
+   */
+  protected function process_iassign ($data) {
+    global $DB;
+
+    $data = (object) $data;
+    $oldid = $data->id;
+    $data->course = $this->get_courseid();
+    $newitemid = $DB->insert_record('iassign', $data);
+    $this->apply_activity_instance($newitemid);
+  }
+
+  /**
+   * Process a iassign_statement restore.
+   * @param object $data The data in object form
+   */
+  protected function process_iassign_statement ($data) {
+    global $DB, $CFG;
+
+    require_once($CFG->dirroot . '/mod/iassign/locallib.php');
+    $data = (object) $data;
+    $oldid = $data->id;
+    $data->iassignid = $this->get_new_parentid('iassign');
+    $newitemid = $DB->insert_record('iassign_statement', $data);
+    $this->set_mapping('iassign_statement', $oldid, $newitemid, true); // Has related fileareas
+    activity::add_calendar($newitemid);
+  }
+
+  /**
+   * Process a iassign_submission restore.
+   * @param object $data The data in object form
+   */
+  protected function process_iassign_submission ($data) {
+    global $DB;
+
+    $data = (object) $data;
+    $oldid = $data->id;
+    $data->iassign_statementid = $this->get_new_parentid('iassign_statement');
+    $data->userid = $this->get_mappingid('user', $data->userid);
+    $data->teacher = $this->get_mappingid('user', $data->teacher);
+    $newitemid = $DB->insert_record('iassign_submission', $data);
+    $this->set_mapping('iassign_submission', $oldid, $newitemid, true); // Has related fileareas
+  }
+
+  /**
+   * Process a iassign_submission_comment restore.
+   * @param object $data The data in object form
+   */
+  protected function process_iassign_submission_comment ($data) {
+    global $DB;
+
+    $data = (object) $data;
+    $oldid = $data->id;
+    $data->iassign_submissionid = $this->get_new_parentid('iassign_submission');
+    $data->comment_authorid = $this->get_mappingid('user', $data->comment_authorid);
+    $newitemid = $DB->insert_record('iassign_submission_comment', $data);
+    $this->set_mapping('iassign_submission_comment', $oldid, $newitemid, true); // Has related fileareas
+  }
+
+  /**
+   * Once the database tables have been fully restored, restore the files.
+   */
+  protected function after_execute () {
+    global $CFG, $DB;
+
+    $this->add_related_files('mod_iassign', 'exercise', null);
+
+    $fs = get_file_storage();
+
+    $iassigns = $DB->get_records('iassign', array('course' => $this->get_courseid()));
+    foreach ($iassigns as $iassign) {
+      $iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassign->id));
+      foreach ($iassign_statements as $iassign_statement) {
+        $files = $DB->get_records('files', array('component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_statement->file));
+        if($files) {
+          $filename = array();
+          foreach ($files as $value) {
+            if($value->filename != '.') {
+              $filename = explode(".", $value->filename);
+            }
+          }
+          $extension = "";
+          if(count($filename) > 1)
+            $extension = strtolower($filename[count($filename) - 1]);
+
+          $iassign_ilms = $DB->get_records('iassign_ilm', array('parent' => 0, 'enable' => 1));
+          foreach ($iassign_ilms as $iassign_ilm) {
+            $extensions = explode(",", $iassign_ilm->extension);
+            if(in_array($extension, $extensions))
+              $iassign_statement->iassign_ilmid = $iassign_ilm->id;
+          }
+          $DB->update_record("iassign_statement", $iassign_statement);
+        }
+      }
+    }
+  }
+
+}

+ 51 - 0
classes/event/course_module_instance_list_viewed.php

@@ -0,0 +1,51 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * The mod_iassign submission created event.
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2015/07/12
+ * @package mod_iassign
+ * @since 2015/10/14
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 
+ */
+
+namespace mod_iassign\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed {
+
+  /**
+   * Create the event from course record.
+   *
+   * @param \stdClass $course
+   * @return course_module_instance_list_viewed
+   */
+  public static function create_from_course (\stdClass $course) {
+    $params = array(
+      'context' => \context_course::instance($course->id)
+    );
+    $event = \mod_iassign\event\course_module_instance_list_viewed::create($params);
+    $event->add_record_snapshot('course', $course);
+    return $event;
+  }
+
+}

+ 99 - 0
classes/event/course_module_viewed.php

@@ -0,0 +1,99 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * The mod_iassign course module viewed event.
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2015/07/12
+ * @package mod_iassign
+ * @since 2015/10/14
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 
+ */
+
+namespace mod_iassign\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+class course_module_viewed extends \core\event\course_module_viewed {
+
+  /**
+   * Init method.
+   */
+  protected function init () {
+    $this->data['crud'] = 'r'; // c(reate), r(ead), u(pdate), d(elete)
+    $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
+    $this->data['objecttable'] = 'iassign';
+  }
+
+  /**
+   * Returns localised general event name.
+   *
+   * @return string
+   */
+  public static function get_name () {
+    return get_string('eventcoursemoduleviewed', 'mod_iassign');
+  }
+
+  /**
+   * Returns non-localised event description with id's for admin use only.
+   *
+   * @return string
+   */
+  public function get_description () {
+    return "The user with id '$this->userid' has viewed the iAssign with id '$this->objectid' in " .
+        "the iAssign activity with course module id '$this->contextinstanceid'.";
+  }
+
+  /**
+   * Get URL related to the action.
+   *
+   * @return \moodle_url
+   */
+  public function get_url () {
+    return new \moodle_url('/mod/iassign/view.php', array('id' => $this->contextinstanceid));
+  }
+
+  /**
+   * Return the legacy event log data.
+   *
+   * @return array|null
+   */
+  public function get_legacy_logdata () {
+
+    return array($this->courseid, 'iassign', 'view',
+      "view.php?id={$this->contextinstanceid}",
+      $this->objectid, $this->contextinstanceid);
+  }
+
+  /**
+   * Custom validation.
+   *
+   * @throws \coding_exception
+   * @return void
+   */
+  protected function validate_data () {
+    parent::validate_data();
+    // Make sure this class is never used without proper object details.
+    if(!$this->contextlevel === CONTEXT_MODULE) {
+      throw new \coding_exception('Context level must be CONTEXT_MODULE.');
+    }
+  }
+
+}

+ 99 - 0
classes/event/iassign_created.php

@@ -0,0 +1,99 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * The mod_iassign created event.
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2015/07/12
+ * @package mod_iassign
+ * @since 2015/10/14
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 
+ */
+
+namespace mod_iassign\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+class iassign_created extends \core\event\base {
+
+  /**
+   * Init method.
+   */
+  protected function init () {
+    $this->data['crud'] = 'c'; // c(reate), r(ead), u(pdate), d(elete)
+    $this->data['edulevel'] = self::LEVEL_TEACHING;
+    $this->data['objecttable'] = 'iassign';
+  }
+
+  /**
+   * Returns localised general event name.
+   *
+   * @return string
+   */
+  public static function get_name () {
+    return get_string('eventiassigncreated', 'mod_iassign');
+  }
+
+  /**
+   * Returns non-localised event description with id's for admin use only.
+   *
+   * @return string
+   */
+  public function get_description () {
+    return "The user with id '$this->userid' has created the iAssign with id '$this->objectid' in " .
+        "the iAssign activity with course module id '$this->contextinstanceid'.";
+  }
+
+  /**
+   * Get URL related to the action.
+   *
+   * @return \moodle_url
+   */
+  public function get_url () {
+    return new \moodle_url('/mod/iassign/view.php', array('id' => $this->contextinstanceid));
+  }
+
+  /**
+   * Return the legacy event log data.
+   *
+   * @return array|null
+   */
+  public function get_legacy_logdata () {
+
+    return array($this->courseid, 'iassign', 'add',
+      "view.php?id={$this->contextinstanceid}",
+      $this->objectid, $this->contextinstanceid);
+  }
+
+  /**
+   * Custom validation.
+   *
+   * @throws \coding_exception
+   * @return void
+   */
+  protected function validate_data () {
+    parent::validate_data();
+    // Make sure this class is never used without proper object details.
+    if(!$this->contextlevel === CONTEXT_MODULE) {
+      throw new \coding_exception('Context level must be CONTEXT_MODULE.');
+    }
+  }
+
+}

+ 99 - 0
classes/event/iassign_deleted.php

@@ -0,0 +1,99 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * The mod_iassign deleted event.
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2015/07/12
+ * @package mod_iassign
+ * @since 2015/07/12
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 
+ */
+
+namespace mod_iassign\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+class iassign_deleted extends \core\event\base {
+
+  /**
+   * Init method.
+   */
+  protected function init () {
+    $this->data['crud'] = 'd'; // c(reate), r(ead), u(pdate), d(elete)
+    $this->data['edulevel'] = self::LEVEL_TEACHING; // LEVEL_TEACHING , LEVEL_PARTICIPATING, LEVEL_OTHER
+    $this->data['objecttable'] = 'iassign';
+  }
+
+  /**
+   * Returns localised general event name.
+   *
+   * @return string
+   */
+  public static function get_name () {
+    return get_string('eventiassigndeleted', 'mod_iassign');
+  }
+
+  /**
+   * Returns non-localised event description with id's for admin use only.
+   *
+   * @return string
+   */
+  public function get_description () {
+    return "The user with id '$this->userid' has deleted the iAssign with id '$this->objectid' in " .
+        "the iAssign activity with course module id '$this->contextinstanceid'.";
+  }
+
+  /**
+   * Get URL related to the action.
+   *
+   * @return \moodle_url
+   */
+  public function get_url () {
+    return new \moodle_url('/mod/iassign/view.php', array('id' => $this->contextinstanceid));
+  }
+
+  /**
+   * Return the legacy event log data.
+   *
+   * @return array|null
+   */
+  public function get_legacy_logdata () {
+
+    return array($this->courseid, 'iassign', 'delete iassign',
+      "view.php?id={$this->contextinstanceid}",
+      $this->objectid, $this->contextinstanceid);
+  }
+
+  /**
+   * Custom validation.
+   *
+   * @throws \coding_exception
+   * @return void
+   */
+  protected function validate_data () {
+    parent::validate_data();
+    // Make sure this class is never used without proper object details.
+    if(!$this->contextlevel === CONTEXT_MODULE) {
+      throw new \coding_exception('Context level must be CONTEXT_MODULE.');
+    }
+  }
+
+}

+ 99 - 0
classes/event/iassign_updated.php

@@ -0,0 +1,99 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * The mod_iassign updated event.
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2015/07/12
+ * @package mod_iassign
+ * @since 2015/07/12
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 
+ */
+
+namespace mod_iassign\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+class iassign_updated extends \core\event\base {
+
+  /**
+   * Init method.
+   */
+  protected function init () {
+    $this->data['crud'] = 'u'; // c(reate), r(ead), u(pdate), d(elete)
+    $this->data['edulevel'] = self::LEVEL_TEACHING; // LEVEL_TEACHING , LEVEL_PARTICIPATING, LEVEL_OTHER
+    $this->data['objecttable'] = 'iassign';
+  }
+
+  /**
+   * Returns localised general event name.
+   *
+   * @return string
+   */
+  public static function get_name () {
+    return get_string('eventiassignupdated', 'mod_iassign');
+  }
+
+  /**
+   * Returns non-localised event description with id's for admin use only.
+   *
+   * @return string
+   */
+  public function get_description () {
+    return "The user with id '$this->userid' has updated the iAssign with id '$this->objectid' in " .
+        "the iAssign activity with course module id '$this->contextinstanceid'.";
+  }
+
+  /**
+   * Get URL related to the action.
+   *
+   * @return \moodle_url
+   */
+  public function get_url () {
+    return new \moodle_url('/mod/iassign/view.php', array('id' => $this->contextinstanceid));
+  }
+
+  /**
+   * Return the legacy event log data.
+   *
+   * @return array|null
+   */
+  public function get_legacy_logdata () {
+
+    return array($this->courseid, 'iassign', 'update',
+      "view.php?id={$this->contextinstanceid}",
+      $this->objectid, $this->contextinstanceid);
+  }
+
+  /**
+   * Custom validation.
+   *
+   * @throws \coding_exception
+   * @return void
+   */
+  protected function validate_data () {
+    parent::validate_data();
+    // Make sure this class is never used without proper object details.
+    if(!$this->contextlevel === CONTEXT_MODULE) {
+      throw new \coding_exception('Context level must be CONTEXT_MODULE.');
+    }
+  }
+
+}

+ 10 - 0
classes/event/index.html

@@ -0,0 +1,10 @@
+<html>
+    <head>
+        <meta charset="UTF-8">
+        <title>Acess not allowed! - Acesso não permitido</title>
+    </head>
+    <body style="color: #FF0000">
+        <p>Acesso não permitido!</p>
+        <p>Acess not allowed!</p>
+    </body>
+</html>

+ 99 - 0
classes/event/submission_comment_created.php

@@ -0,0 +1,99 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * The mod_iassign submission comment created event.
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2015/07/12
+ * @package mod_iassign
+ * @since 2015/07/12
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 
+ */
+
+namespace mod_iassign\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+class submission_comment_created extends \core\event\base {
+
+  /**
+   * Init method.
+   */
+  protected function init () {
+    $this->data['crud'] = 'c'; // c(reate), r(ead), u(pdate), d(elete)
+    $this->data['edulevel'] = self::LEVEL_PARTICIPATING; // LEVEL_TEACHING , LEVEL_PARTICIPATING, LEVEL_OTHER
+    $this->data['objecttable'] = 'iassign';
+  }
+
+  /**
+   * Returns localised general event name.
+   *
+   * @return string
+   */
+  public static function get_name () {
+    return get_string('eventsubmissioncommentcreated', 'mod_iassign');
+  }
+
+  /**
+   * Returns non-localised event description with id's for admin use only.
+   *
+   * @return string
+   */
+  public function get_description () {
+    return "The user with id '$this->userid' has created submission of comment updated the iAssign with id '$this->objectid' in " .
+        "the iAssign activity with course module id '$this->contextinstanceid'.";
+  }
+
+  /**
+   * Get URL related to the action.
+   *
+   * @return \moodle_url
+   */
+  public function get_url () {
+    return new \moodle_url('/mod/iassign/view.php', array('id' => $this->contextinstanceid));
+  }
+
+  /**
+   * Return the legacy event log data.
+   *
+   * @return array|null
+   */
+  public function get_legacy_logdata () {
+
+    return array($this->courseid, 'iassign', 'add comment',
+      "view.php?id={$this->contextinstanceid}",
+      $this->objectid, $this->contextinstanceid);
+  }
+
+  /**
+   * Custom validation.
+   *
+   * @throws \coding_exception
+   * @return void
+   */
+  protected function validate_data () {
+    parent::validate_data();
+    // Make sure this class is never used without proper object details.
+    if(!$this->contextlevel === CONTEXT_MODULE) {
+      throw new \coding_exception('Context level must be CONTEXT_MODULE.');
+    }
+  }
+
+}

+ 99 - 0
classes/event/submission_comment_updated.php

@@ -0,0 +1,99 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * The mod_iassign submission comment update event.
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2015/07/12
+ * @package mod_iassign
+ * @since 2015/07/12
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 
+ */
+
+namespace mod_iassign\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+class submission_comment_updated extends \core\event\base {
+
+  /**
+   * Init method.
+   */
+  protected function init () {
+    $this->data['crud'] = 'u'; // c(reate), r(ead), u(pdate), d(elete)
+    $this->data['edulevel'] = self::LEVEL_PARTICIPATING; // LEVEL_TEACHING , LEVEL_PARTICIPATING, LEVEL_OTHER
+    $this->data['objecttable'] = 'iassign';
+  }
+
+  /**
+   * Returns localised general event name.
+   *
+   * @return string
+   */
+  public static function get_name () {
+    return get_string('eventsubmissioncommentupdated', 'mod_iassign');
+  }
+
+  /**
+   * Returns non-localised event description with id's for admin use only.
+   *
+   * @return string
+   */
+  public function get_description () {
+    return "The user with id '$this->userid' has viewed  activity submission of comment updated the iAssign with id '$this->objectid' in " .
+        "the iAssign activity with course module id '$this->contextinstanceid'.";
+  }
+
+  /**
+   * Get URL related to the action.
+   *
+   * @return \moodle_url
+   */
+  public function get_url () {
+    return new \moodle_url('/mod/iassign/view.php', array('id' => $this->contextinstanceid));
+  }
+
+  /**
+   * Return the legacy event log data.
+   *
+   * @return array|null
+   */
+  public function get_legacy_logdata () {
+
+    return array($this->courseid, 'iassign', 'update comment',
+      "view.php?id={$this->contextinstanceid}",
+      $this->objectid, $this->contextinstanceid);
+  }
+
+  /**
+   * Custom validation.
+   *
+   * @throws \coding_exception
+   * @return void
+   */
+  protected function validate_data () {
+    parent::validate_data();
+    // Make sure this class is never used without proper object details.
+    if(!$this->contextlevel === CONTEXT_MODULE) {
+      throw new \coding_exception('Context level must be CONTEXT_MODULE.');
+    }
+  }
+
+}

+ 99 - 0
classes/event/submission_created.php

@@ -0,0 +1,99 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * The mod_iassign submission created event.
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2015/07/12
+ * @package mod_iassign
+ * @since 2015/07/12
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 
+ */
+
+namespace mod_iassign\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+class submission_created extends \core\event\base {
+
+  /**
+   * Init method.
+   */
+  protected function init () {
+    $this->data['crud'] = 'c'; // c(reate), r(ead), u(pdate), d(elete)
+    $this->data['edulevel'] = self::LEVEL_PARTICIPATING; // LEVEL_TEACHING , LEVEL_PARTICIPATING, LEVEL_OTHER
+    $this->data['objecttable'] = 'iassign';
+  }
+
+  /**
+   * Returns localised general event name.
+   *
+   * @return string
+   */
+  public static function get_name () {
+    return get_string('eventsubmissioncreated', 'mod_iassign');
+  }
+
+  /**
+   * Returns non-localised event description with id's for admin use only.
+   *
+   * @return string
+   */
+  public function get_description () {
+    return "The user with id '$this->userid' has created submission the iAssign with id '$this->objectid' in " .
+        "the iAssign activity with course module id '$this->contextinstanceid'.";
+  }
+
+  /**
+   * Get URL related to the action.
+   *
+   * @return \moodle_url
+   */
+  public function get_url () {
+    return new \moodle_url('/mod/iassign/view.php', array('id' => $this->contextinstanceid));
+  }
+
+  /**
+   * Return the legacy event log data.
+   *
+   * @return array|null
+   */
+  public function get_legacy_logdata () {
+
+    return array($this->courseid, 'iassign', 'add submission',
+      "view.php?id={$this->contextinstanceid}",
+      $this->objectid, $this->contextinstanceid);
+  }
+
+  /**
+   * Custom validation.
+   *
+   * @throws \coding_exception
+   * @return void
+   */
+  protected function validate_data () {
+    parent::validate_data();
+    // Make sure this class is never used without proper object details.
+    if(!$this->contextlevel === CONTEXT_MODULE) {
+      throw new \coding_exception('Context level must be CONTEXT_MODULE.');
+    }
+  }
+
+}

+ 99 - 0
classes/event/submission_updated.php

@@ -0,0 +1,99 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * The mod_iassign submission updated event.
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2015/07/12
+ * @package mod_iassign
+ * @since 2015/07/12
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 
+ */
+
+namespace mod_iassign\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+class submission_updated extends \core\event\base {
+
+  /**
+   * Init method.
+   */
+  protected function init () {
+    $this->data['crud'] = 'u'; // c(reate), r(ead), u(pdate), d(elete)
+    $this->data['edulevel'] = self::LEVEL_PARTICIPATING; // LEVEL_TEACHING , LEVEL_PARTICIPATING, LEVEL_OTHER
+    $this->data['objecttable'] = 'iassign';
+  }
+
+  /**
+   * Returns localised general event name.
+   *
+   * @return string
+   */
+  public static function get_name () {
+    return get_string('eventsubmissionupdated', 'mod_iassign');
+  }
+
+  /**
+   * Returns non-localised event description with id's for admin use only.
+   *
+   * @return string
+   */
+  public function get_description () {
+    return "The user with id '$this->userid' has update submission the iAssign with id '$this->objectid' in " .
+        "the iAssign activity with course module id '$this->contextinstanceid'.";
+  }
+
+  /**
+   * Get URL related to the action.
+   *
+   * @return \moodle_url
+   */
+  public function get_url () {
+    return new \moodle_url('/mod/iassign/view.php', array('id' => $this->contextinstanceid));
+  }
+
+  /**
+   * Return the legacy event log data.
+   *
+   * @return array|null
+   */
+  public function get_legacy_logdata () {
+
+    return array($this->courseid, 'iassign', 'update submission',
+      "view.php?id={$this->contextinstanceid}",
+      $this->objectid, $this->contextinstanceid);
+  }
+
+  /**
+   * Custom validation.
+   *
+   * @throws \coding_exception
+   * @return void
+   */
+  protected function validate_data () {
+    parent::validate_data();
+    // Make sure this class is never used without proper object details.
+    if(!$this->contextlevel === CONTEXT_MODULE) {
+      throw new \coding_exception('Context level must be CONTEXT_MODULE.');
+    }
+  }
+
+}

+ 99 - 0
classes/event/submission_viewed.php

@@ -0,0 +1,99 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * The mod_iassign submission viewed event.
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2015/07/12
+ * @package mod_iassign
+ * @since 2015/07/12
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 
+ */
+
+namespace mod_iassign\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+class submission_viewed extends \core\event\base {
+
+  /**
+   * Init method.
+   */
+  protected function init () {
+    $this->data['crud'] = 'r'; // c(reate), r(ead), u(pdate), d(elete)
+    $this->data['edulevel'] = self::LEVEL_PARTICIPATING; // LEVEL_TEACHING , LEVEL_PARTICIPATING, LEVEL_OTHER
+    $this->data['objecttable'] = 'iassign';
+  }
+
+  /**
+   * Returns localised general event name.
+   *
+   * @return string
+   */
+  public static function get_name () {
+    return get_string('eventsubmissionviewed', 'mod_iassign');
+  }
+
+  /**
+   * Returns non-localised event description with id's for admin use only.
+   *
+   * @return string
+   */
+  public function get_description () {
+    return "The user with id '$this->userid' has viewed  activity submission the iAssign with id '$this->objectid' in " .
+        "the iAssign activity with course module id '$this->contextinstanceid'.";
+  }
+
+  /**
+   * Get URL related to the action.
+   *
+   * @return \moodle_url
+   */
+  public function get_url () {
+    return new \moodle_url('/mod/iassign/view.php', array('id' => $this->contextinstanceid));
+  }
+
+  /**
+   * Return the legacy event log data.
+   *
+   * @return array|null
+   */
+  public function get_legacy_logdata () {
+
+    return array($this->courseid, 'iassign', 'view submission',
+      "view.php?id={$this->contextinstanceid}",
+      $this->objectid, $this->contextinstanceid);
+  }
+
+  /**
+   * Custom validation.
+   *
+   * @throws \coding_exception
+   * @return void
+   */
+  protected function validate_data () {
+    parent::validate_data();
+    // Make sure this class is never used without proper object details.
+    if(!$this->contextlevel === CONTEXT_MODULE) {
+      throw new \coding_exception('Context level must be CONTEXT_MODULE.');
+    }
+  }
+
+}

+ 10 - 0
classes/index.html

@@ -0,0 +1,10 @@
+<html>
+    <head>
+        <meta charset="UTF-8">
+        <title>Acess not allowed! - Acesso não permitido</title>
+    </head>
+    <body style="color: #FF0000">
+        <p>Acesso não permitido!</p>
+        <p>Acess not allowed!</p>
+    </body>
+</html>

+ 128 - 0
db/access.php

@@ -0,0 +1,128 @@
+<?php
+
+/**
+ * Capability definitions for the ia module.
+ * 
+ * The system has four possible values for a capability:
+ *  - CAP_ALLOW
+ *  - CAP_PREVENT
+ *  - CAP_PROHIBIT
+ *  - CAP_INHERIT
+ * Hardening_new_Roles_system: <a href="http://docs.moodle.org/en/Development">http://docs.moodle.org/en/Development</a>
+ *  - manager - manageristrators can do anything at all courses.
+ *  - coursecreator - Creators can create new courses to courses and act as teachers.
+ *  - editingteacher - Teachers can do everything on a course, change, and evaluate activities.
+ *  - teacher - Moderators can interact and evaluate but can not modify the activities.
+ *  - student - Students usually have fewer privileges on a course.
+ *  - guest - Guests have minimal privileges and can not publish texts.
+ *  - user  - All users who login.
+ * 
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2010/09/27
+ * @package mod_iassign_db
+ * @since 2010/09/27
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * 
+ * <b>License</b> 
+ *  - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+$capabilities = array(
+  'mod/iassign:view' => array(
+    'captype' => 'read',
+    'contextlevel' => CONTEXT_MODULE,
+    'legacy' => array(
+      'guest' => CAP_ALLOW,
+      'student' => CAP_ALLOW,
+      'teacher' => CAP_ALLOW,
+      'editingteacher' => CAP_ALLOW,
+      'coursecreator' => CAP_ALLOW,
+      'manager' => CAP_ALLOW
+    )
+  ),
+  'mod/iassign:editiassign' => array(
+    'captype' => 'write',
+    'contextlevel' => CONTEXT_MODULE,
+    'legacy' => array(
+      'editingteacher' => CAP_ALLOW,
+      'coursecreator' => CAP_ALLOW,
+      'manager' => CAP_ALLOW
+    )
+  ),
+  'mod/iassign:evaluateiassign' => array(
+    'riskbitmask' => RISK_XSS,
+    'captype' => 'write',
+    'contextlevel' => CONTEXT_MODULE,
+    'legacy' => array(
+      'teacher' => CAP_ALLOW,
+      'editingteacher' => CAP_ALLOW,
+      'coursecreator' => CAP_ALLOW,
+      'manager' => CAP_ALLOW
+    )
+  ),
+  'mod/iassign:viewiassignall' => array(
+    'captype' => 'read',
+    'contextlevel' => CONTEXT_MODULE,
+    'legacy' => array(
+      'teacher' => CAP_ALLOW,
+      'editingteacher' => CAP_ALLOW,
+      'coursecreator' => CAP_ALLOW,
+      'manager' => CAP_ALLOW
+    )
+  ),
+  'mod/iassign:viewreport' => array(
+    'captype' => 'read',
+    'contextlevel' => CONTEXT_MODULE,
+    'legacy' => array(
+      'teacher' => CAP_ALLOW,
+      'editingteacher' => CAP_ALLOW,
+      'coursecreator' => CAP_ALLOW,
+      'manager' => CAP_ALLOW
+    )
+  ),
+  'mod/iassign:submitiassign' => array(
+    'captype' => 'write',
+    'contextlevel' => CONTEXT_MODULE,
+    'legacy' => array(
+      'student' => CAP_ALLOW
+    )
+  ),
+  'mod/iassign:deleteiassignnull' => array(
+    'riskbitmask' => RISK_XSS,
+    'captype' => 'write',
+    'contextlevel' => CONTEXT_MODULE,
+    'legacy' => array(
+      'editingteacher' => CAP_ALLOW,
+      'coursecreator' => CAP_ALLOW,
+      'manager' => CAP_ALLOW
+    )
+  ),
+  'mod/iassign:deleteiassignnotnull' => array(
+    'riskbitmask' => RISK_XSS,
+    'captype' => 'write',
+    'contextlevel' => CONTEXT_MODULE,
+    'legacy' => array(
+      'manager' => CAP_ALLOW
+    )
+  ),
+  'mod/iassign:addinstance' => array(
+    'riskbitmask' => RISK_XSS,
+    'captype' => 'write',
+    'contextlevel' => CONTEXT_COURSE,
+    'archetypes' => array(
+      'editingteacher' => CAP_ALLOW,
+      'manager' => CAP_ALLOW
+    ),
+    'clonepermissionsfrom' => 'moodle/course:manageactivities'
+  ),
+  'mod/iassign:runautoevaluate' => array(
+    'captype' => 'read',
+    'contextlevel' => CONTEXT_MODULE,
+    'legacy' => array(
+      'teacher' => CAP_ALLOW,
+      'editingteacher' => CAP_ALLOW,
+      'coursecreator' => CAP_ALLOW,
+      'manager' => CAP_ALLOW
+    )
+  )
+);

+ 10 - 0
db/index.html

@@ -0,0 +1,10 @@
+<html>
+    <head>
+        <meta charset="UTF-8">
+        <title>Acess not allowed! - Acesso não permitido</title>
+    </head>
+    <body style="color: #FF0000">
+        <p>Acesso não permitido!</p>
+        <p>Acess not allowed!</p>
+    </body>
+</html>

+ 159 - 0
db/install.php

@@ -0,0 +1,159 @@
+<?php
+
+/**
+ * This file keeps track of brand new installation of iAssign.
+ * 
+ * iAssign allow insertion of new "interactive Learning Modules" (iLM),
+ * at any times, by the Moodle administrator.
+ * It cames with some iLM from Laboratory of Informatics in Education (LInE),
+ * like iVProg (www.matematica.br/ivprog) and iFractions (www.matematica.br/ifractions).
+ * The purpose of this scritp is to insert theses initial iLM in your iAssign module.
+ * 
+ * - v 1.5.3 2020/08/30
+ *     + Removed all commands associated to 'upgrade'
+ * - v 1.5.2 2020/08/03
+ *     + Fixed 'ALTER TABLE' of 'iassign_submission.grade' from BIGINT(11) to REAL 
+ *     + New version of iHanoi 1.0.20200803
+ * - v 1.5.1 2020/05/28-30
+ *     + Avoid to update one iLM causing colision with other instance of the same iLM
+ * - v 1.4 2013/09/19
+ *     + Insert general fields for iassign statement (grade, timeavaliable, timedue, preventlate, test, max_experiment).
+ *     + Change index field 'name' in 'iassign_ilm' table to index field 'name,version'.
+ * - v 1.2 2013/08/30
+ * + Change 'filearea' for new concept for files.
+ * + Change path file for ilm, consider version in pathname.
+ * 
+ * @author Leônidas O. Brandão
+ * @author Patricia Alves Rodrigues
+ * @author Igor Moreira Félix
+ * @version v 1.5.3 2020/08/30
+ * @version v 1.5.1 2020/05/28-30
+ * @version v 1.5 2019/03/13
+ * @version v 1.4 2013/09/19
+ * @package mod_iassign_db
+ * @since 2010/12/21
+ * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
+ * 
+ * <b>License</b> 
+ *  - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ *  
+ * @param $oldversion Number of the old version. 
+ */
+
+require_once ($CFG->dirroot . '/mod/iassign/locallib.php');
+
+///
+//  Code run after the mod_iassign module database tables have been created.
+//  Disables this plugin for new installs
+//  @return bool
+function xmldb_iassign_install () {
+// function xmldb_iassign_upgrade ($oldversion)
+
+  global $CFG, $DB, $USER;
+
+  $dbman = $DB->get_manager();
+
+  // iLM availables: iFractions; iGeom; iGraf; iHanoi; iVProg; Risko
+  // HTML+JS iLM   : iFractions; iHanoi; iVProg
+  // Java iLM      : iGeom; iGraf
+
+    $table = new xmldb_table('iassign_submission');
+    $field = new xmldb_field('previous_grade', XMLDB_TYPE_FLOAT, null, null, null, null, null);
+    if (!$dbman->field_exists($table, $field)) {
+      $dbman->add_field($table, $field);
+      }
+
+    $records = array(
+      array_combine( // iVProg 1.0.20200121 - HTML5
+        array('name', 'url', 'version', 'type', 'description',
+              'extension', 'file_jar', 'file_class', 'width', 'height',
+              'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated'),
+        array('iVProg', 'http://www.usp.br/line/ivprog/', '1.0.20200121', 'HTML5', '{"en":"Visual Interactive Programming on the Internet (HTML)","pt_br":"Programação visual interativa na Internet"}',
+              'ivph', 'ilm/iVProg/1.0.20190717/ivprog/', 'index.html', 800, 600,
+              1, 1, 1, time(), $USER->id, time())),
+      array_combine( // iHanoi 1.0.20200803 - HTML5
+        array('name', 'url', 'version', 'type', 'description',
+              'extension', 'file_jar', 'file_class', 'width', 'height',
+              'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated'),
+        array('iHanoi', 'http://www.matematica.br/ihanoi', '1.0.20200803', 'HTML5', '{"en":"interactive Tower os Hanoi (by LInE)", "pt_br":"Torres de Hanói (do LInE)"}',
+              'ihn', 'ilm/iHanoi/1.0.20200803/ihanoi/', 'index.html', 1100, 500,
+              1, 1, 1, time(), $USER->id, time())),
+      array_combine( // iFractions 0.1.20200221 - HTML5
+        array('name', 'url', 'version', 'type', 'description',
+              'extension', 'file_jar', 'file_class', 'width', 'height',
+              'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated'),
+        array('iFractions', 'http://www.matematica.br/ifractions', '0.1.20200221', 'HTML5', '{"en":"Interactive Fractions game","pt_br":"Jogo interativa de frações"}',
+              'frc', 'ilm/iFractions/0.1.20200221/ifractions/', 'index.html', 1000, 600,
+              1, 1, 0, time(), $USER->id, time())),
+      array_combine( // iGeom 5.9.22 - Java
+        array('name', 'url', 'version', 'type', 'description',
+              'extension', 'file_jar', 'file_class', 'width', 'height',
+              'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated'),
+        array('iGeom', 'http://www.matematica.br/igeom', '5.9.22', 'Java', '{"en":"Interactive Geometry on the Internet","pt_br":"Geometria Interativa na Internet"}',
+              'geo', 'ilm/iGeom/5.9.22/iGeom.jar', 'IGeomApplet.class', 800, 600, 
+              1, 1, 0, time(), $USER->id, time())),
+      array_combine( // Risco 2.2.23 - Java
+        array('name', 'url', 'version', 'type', 'description',
+              'extension', 'file_jar', 'file_class', 'width', 'height',
+              'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated'),
+        array('Risko', 'http://risko.pcc.usp.br/', '2.2.23', 'Java', '{"en":"Technical drawing with triangle and ruler","pt_br":"Desenho Geomẽtrico com esquadro"}',
+              'rsk', 'ilm/Risko/2.2.23/Risko.jar', 'RiskoApplet.class', 800, 600,
+              1, 0, 0, time(), $USER->id, time()))
+      );
+
+    $strInstalled_iLM = "";
+    $error = 0;
+    foreach ($records as $record) {
+      $newentry = new stdClass();
+      $newentry->name = $record['name'];
+      $newentry->version = $record['version'];
+      $newentry->type = $record['type'];
+      $newentry->url = $record['url'];
+      $newentry->description = $record['description'];
+      $newentry->extension = $record['extension'];
+      $newentry->file_jar = $record['file_jar'];
+      $newentry->file_class = $record['file_class'];
+      $newentry->width = $record['width'];
+      $newentry->height = $record['height'];
+      $newentry->enable = $record['enable'];
+      $newentry->evaluate = $record['evaluate'];
+      $newentry->reevaluate = $record['reevaluate'];
+      $newentry->timemodified = time();
+      $newentry->author = $USER->id;
+      $newentry->timecreated = time();
+      try {
+        $DB->insert_record("iassign_ilm", $newentry, false);
+        $strInstalled_iLM += "\n" . '  <li>' . $record['name'] + ';' . $record['type'] . ';' . $record['version'] . ' </li>' . "\n";	  
+      } catch (Exception $e) {
+        print "Error install.php: " . $e->getMessage() . "<br/>";
+        $error = 1;
+        }
+      }
+
+    if ($error == 1) {
+      // $string['error_security_no_userid']       = 'Internal error: must be informed the user identification. Inform the Administrator.';
+      print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
+      print get_string('error_security_no_userid', 'iassign'); // Internal error: must be informed the user identification. Inform the Administrator
+      // print '<a href="'.new moodle_url('/admin/settings.php?section=modsettingiassign').'">' . get_string('upgrade_alert_iMA_solution_pt2', 'iassign') . '</a>.' + "\n";
+      print '</div>' + "\n";
+      }
+    else { // $string['cliinstallfinished'] = 'Installation completed successfully.';
+      print '<div class="modal-content"><p>' . get_string('cliinstallfinished', 'install') . '</p>' . "\n";
+      print ' <ul style="margin-top: 1rem;">' . "\n";
+      print $strInstalled_iLM;
+      print ' </ul>' . "\n";
+      print '</div' . "\n";;
+      }
+
+  // log event -----------------------------------------------------
+  if (class_exists('plugin_manager'))
+    $pluginman = plugin_manager::instance();
+  else
+    $pluginman = core_plugin_manager::instance();
+  $plugins = $pluginman->get_plugins();
+  iassign_log::add_log('install', 'version: ' . $plugins['mod']['iassign']->versiondisk);
+  // log event -----------------------------------------------------
+
+  return true;
+
+  } // function xmldb_iassign_install()

+ 191 - 0
db/install.xml

@@ -0,0 +1,191 @@
+<?xml version="1.0" encoding="UTF-8"  ?>
+<XMLDB PATH="mod/iassign/db" VERSION="20101022" COMMENT="XMLDB file for Moodle mod/iassign" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceScheiaLocation="../../../lib/xmldb/xmldb.xsd">
+  <TABLES>
+    <TABLE NAME="iassign_ilm" COMMENT="Info about Interactive Learning Module - iLM" NEXT= "iassign_ilm_config">
+      <FIELDS>
+        <FIELD NAME="id"             TYPE="int"  LENGTH="10"     NOTNULL="true" UNSIGNED="true" SEQUENCE="true"                ENUM="false" COMMENT="Primary key of table"                                            NEXT="name"/>
+        <FIELD NAME="name"           TYPE="char" LENGTH="20"     NOTNULL="true"                 SEQUENCE="false"               ENUM="false" COMMENT="Name of the iLM"                         PREVIOUS="id"           NEXT="version"/>
+        <FIELD NAME="version"        TYPE="char" LENGTH="30"     NOTNULL="true"                 SEQUENCE="false"               ENUM="false" COMMENT="Version of the iLM"                      PREVIOUS="name"         NEXT="version"/>
+        <FIELD NAME="type"           TYPE="char" LENGTH="20"     NOTNULL="true"                 SEQUENCE="false"               ENUM="false" COMMENT="Type of the iLM"                         PREVIOUS="version"      NEXT="description"/>
+        <FIELD NAME="description"    TYPE="text" LENGTH="medium" NOTNULL="false"                SEQUENCE="false"               ENUM="false" COMMENT="Description of the iLM"                  PREVIOUS="type"         NEXT="url"/>
+        <FIELD NAME="url"            TYPE="text" LENGTH="small"  NOTNULL="false"                SEQUENCE="false"               ENUM="false" COMMENT="URL of iLM"                              PREVIOUS="description"  NEXT="extension"/>
+        <FIELD NAME="extension"      TYPE="char" LENGTH="30"     NOTNULL="true" UNSIGNED="true" SEQUENCE="false"               ENUM="false" COMMENT="File extension iLM"                      PREVIOUS="url"          NEXT="parent"/>
+        <FIELD NAME="parent"         TYPE="int"  LENGTH="10"     NOTNULL="true" UNSIGNED="true" SEQUENCE="false" DEFAULT="0"   ENUM="false" COMMENT="id iLM parent. 0 - parent"               PREVIOUS="extension"    NEXT="file_jar"/>
+        <FIELD NAME="file_jar"       TYPE="char" LENGTH="255"    NOTNULL="true" UNSIGNED="true" SEQUENCE="false"               ENUM="false" COMMENT="File name JAR"                           PREVIOUS="parent"       NEXT="file_class"/>
+        <FIELD NAME="file_class"     TYPE="char" LENGTH="255"    NOTNULL="true" UNSIGNED="true" SEQUENCE="false"               ENUM="false" COMMENT="File name class"                         PREVIOUS="file_jar"     NEXT="width"/>
+        <FIELD NAME="width"          TYPE="int"  LENGTH="10"     NOTNULL="true" UNSIGNED="true" SEQUENCE="false" DEFAULT="800" ENUM="false" COMMENT="Width of area to display the iLM"        PREVIOUS="file_class"   NEXT="height"/>
+        <FIELD NAME="height"         TYPE="int"  LENGTH="10"     NOTNULL="true" UNSIGNED="true" SEQUENCE="false" DEFAULT="700" ENUM="false" COMMENT="Heigth of area to display the iLM"       PREVIOUS="width"        NEXT="enable"/>
+        <FIELD NAME="enable"         TYPE="int"  LENGTH="1"                     UNSIGNED="true" SEQUENCE="false" DEFAULT="0"   ENUM="false" COMMENT="Status iLM. 0 - disabled / 1 - enabled"  PREVIOUS="height"       NEXT="timemodified"/>
+        <FIELD NAME="timemodified"   TYPE="int"  LENGTH="10"     NOTNULL="true" UNSIGNED="true" SEQUENCE="false" DEFAULT="0"   ENUM="false" COMMENT="Date of last modification"               PREVIOUS="enable"       NEXT="author"/>
+        <FIELD NAME="author"         TYPE="int"  LENGTH="10"     NOTNULL="true" UNSIGNED="true" SEQUENCE="false" DEFAULT="0"   ENUM="false" COMMENT="id of the author of the iLM"             PREVIOUS="timemodified" NEXT="timecreated"/>
+        <FIELD NAME="timecreated"    TYPE="int"  LENGTH="10"     NOTNULL="true" UNSIGNED="true" SEQUENCE="false" DEFAULT="0"   ENUM="false" COMMENT="Date of registration of iLM"             PREVIOUS="author"       NEXT="evaluate"/>
+        <FIELD NAME="evaluate"       TYPE="int"  LENGTH="1"                     UNSIGNED="true" SEQUENCE="false" DEFAULT="0"   ENUM="false" COMMENT="iLM has automatic evaluator? 0-no/1-yes" PREVIOUS="timecreated"  NEXT="reevaluate"/>
+        <FIELD NAME="reevaluate"     TYPE="int"  LENGTH="1"      NOTNULL="true" UNSIGNED="true" SEQUENCE="false" DEFAULT="0"   ENUM="false" COMMENT="iLM has automatic reevaluator? 0-no/1-yes" PREVIOUS="timecreated"/>
+      </FIELDS>
+      <KEYS>
+        <KEY   NAME="primary"        TYPE="primary" FIELDS="id"/>
+      </KEYS>
+      <INDEXES>
+        <INDEX NAME="name_version"   UNIQUE="true" FIELDS="name,version" NEXT="file_jar"/>
+        <INDEX NAME="file_jar"       UNIQUE="true" FIELDS="file_jar" PREVIOUS="name_version"/>
+      </INDEXES>
+    </TABLE>
+    <TABLE NAME="iassign_ilm_config" COMMENT="Info about config iLM" PREVIOUS="iassign_ilm" NEXT= "iassign">
+      <FIELDS>
+        <FIELD NAME="id"             TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"             SEQUENCE="true"  ENUM="false"  COMMENT="Primary key of table"                                                                NEXT="iassign_ilmid"/>
+        <FIELD NAME="iassign_ilmid"  TYPE="int"  LENGTH="10"     NOTNULL="true"                              SEQUENCE="false" ENUM="false"  COMMENT="id iLM"                                                    PREVIOUS="id"             NEXT="param_type"/>
+        <FIELD NAME="param_type"     TYPE="char" LENGTH="100"    NOTNULL="true"  UNSIGNED="true"             SEQUENCE="false" ENUM="false"  COMMENT="Parameter type"                                            PREVIOUS="iassign_ilmid"  NEXT="param_name"/>
+        <FIELD NAME="param_name"     TYPE="char" LENGTH="100"    NOTNULL="true"  UNSIGNED="true"             SEQUENCE="false" ENUM="false"  COMMENT="Parameter name"                                            PREVIOUS="param_type"     NEXT="param_value"/>
+        <FIELD NAME="param_value"    TYPE="char" LENGTH="100"    NOTNULL="true"  UNSIGNED="true"             SEQUENCE="false" ENUM="false"  COMMENT="Parameter value"                                           PREVIOUS="param_name"     NEXT="description"/>
+        <FIELD NAME="description"    TYPE="text" LENGTH="medium" NOTNULL="false"                             SEQUENCE="false" ENUM="false"  COMMENT="Parameter description"                                     PREVIOUS="param_value"    NEXT="visible"/>
+        <FIELD NAME="visible"        TYPE="int"  LENGTH="1"      NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false"  COMMENT="Parameter visible in the editing activities? 0-no/1-yes"   PREVIOUS="description"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary"          TYPE="primary" FIELDS="id"     NEXT="iassign_ilmid"/>
+        <KEY NAME="iassign_ilmid"    TYPE="foreign" FIELDS="iassign_ilmid" REFTABLE="iassign_ilm" REFFIELDS="id" PREVIOUS="primary"/>
+      </KEYS>
+    </TABLE>
+    <TABLE NAME="iassign" COMMENT="Instances of the module iAssign" PREVIOUS="iassign_ilm_config" NEXT="iassign_log">
+      <FIELDS>
+        <FIELD NAME="id"             TYPE="int"  LENGTH="10"     NOTNULL="true"   UNSIGNED="true"                SEQUENCE="true"  ENUM="false" COMMENT="Primary key of table"                                                                                         NEXT="course"/>
+        <FIELD NAME="course"         TYPE="int"  LENGTH="10"     NOTNULL="true"   UNSIGNED="true"  DEFAULT="0"   SEQUENCE="false" ENUM="false" COMMENT="id of the course in which the activity is inserted"                                 PREVIOUS="id"             NEXT="name"/>
+        <FIELD NAME="name"           TYPE="char" LENGTH="255"    NOTNULL="true"                                  SEQUENCE="false" ENUM="false" COMMENT="Name of the instance of activity"                                                   PREVIOUS="course"         NEXT="intro"/>
+        <FIELD NAME="intro"          TYPE="text"                 NOTNULL="false"                                 SEQUENCE="false" COMMENT="The description of the assignment. This field is used by feature MOD_INTRO."                     PREVIOUS="name"           NEXT="introformat"/>
+        <FIELD NAME="introformat"    TYPE="int"  LENGTH="4"      NOTNULL="true"                    DEFAULT="0"   SEQUENCE="false" COMMENT="The format of the description field of the assignment. This field is used by feature MOD_INTRO." PREVIOUS="intro"          NEXT="activity_group"/>
+        <FIELD NAME="activity_group" TYPE="int"  LENGTH="1"      NOTNULL="true"   UNSIGNED="true"  DEFAULT="1"   SEQUENCE="false" ENUM="false" COMMENT="Type grouping. 0-do not group / 1-group by type of activity"                        PREVIOUS="introformat"    NEXT="grade"/>
+        <FIELD NAME="grade"          TYPE="float"                NOTNULL="true"   UNSIGNED="false" DEFAULT="0"   SEQUENCE="false" ENUM="false" COMMENT="Maximum score for activity"                                                         PREVIOUS="activity_group" NEXT="timeavailable"/>
+        <FIELD NAME="timeavailable"  TYPE="int"  LENGTH="10"     NOTNULL="true"   UNSIGNED="true"  DEFAULT="0"   SEQUENCE="false" ENUM="false" COMMENT="Date of opening activity"                                                           PREVIOUS="grade"          NEXT="timedue"/>
+        <FIELD NAME="timedue"        TYPE="int"  LENGTH="10"     NOTNULL="true"   UNSIGNED="true"  DEFAULT="0"   SEQUENCE="false" ENUM="false" COMMENT="Closing date of the activity"                                                       PREVIOUS="timeavailable"  NEXT="preventlate"/>
+        <FIELD NAME="preventlate"    TYPE="int"  LENGTH="2"      NOTNULL="false"  UNSIGNED="true"  DEFAULT="1"   SEQUENCE="false" ENUM="false" COMMENT="Allow sending late? 0 - no / 1 - yes"                                               PREVIOUS="timedue"        NEXT="test"/>
+        <FIELD NAME="test"           TYPE="int"  LENGTH="1"      NOTNULL="false"  UNSIGNED="true"  DEFAULT="0"   SEQUENCE="false" ENUM="false" COMMENT="Activity to release test after closing time? 0 - no / 1 - yes"                      PREVIOUS="preventlate"    NEXT="max_experiment"/>
+        <FIELD NAME="max_experiment" TYPE="int"  LENGTH="10"     NOTNULL="true"   UNSIGNED="true"  DEFAULT="0"   SEQUENCE="false" ENUM="false" COMMENT="Maximum number of attempts. 0 - unlimited"                                          PREVIOUS="test"/>
+      </FIELDS>
+      <KEYS>
+        <KEY   NAME="primary" TYPE="primary" FIELDS="id" />
+      </KEYS>
+      <INDEXES>
+        <INDEX NAME="course"  UNIQUE="false" FIELDS="course"/>
+      </INDEXES>
+    </TABLE>
+    <TABLE NAME="iassign_log" COMMENT="Logs of the module iAssign" PREVIOUS="iassign" NEXT="iassign_statement">
+      <FIELDS>
+        <FIELD NAME="id"           TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"                SEQUENCE="true"  ENUM="false" COMMENT="Primary key of table"                                                  NEXT="time"/>
+        <FIELD NAME="time"         TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"  DEFAULT="0"   SEQUENCE="false" ENUM="false" COMMENT="Date of log activity"                            PREVIOUS="id"         NEXT="userid"/>
+        <FIELD NAME="userid"       TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"  DEFAULT="0"   SEQUENCE="false" ENUM="false" COMMENT="Id of active user"                               PREVIOUS="time"       NEXT="ip"/>
+        <FIELD NAME="ip"           TYPE="char" LENGTH="255"    NOTNULL="true"                                 SEQUENCE="false" ENUM="false" COMMENT="Ip of active user"                               PREVIOUS="userid"     NEXT="course"/>
+        <FIELD NAME="course"       TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"  DEFAULT="0"   SEQUENCE="false" ENUM="false" COMMENT="Id of the active course"                         PREVIOUS="ip"         NEXT="cmid"/>
+        <FIELD NAME="cmid"         TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"  DEFAULT="0"   SEQUENCE="false" ENUM="false" COMMENT="Id of the active course module"                  PREVIOUS="course"     NEXT="ilmid"/>
+        <FIELD NAME="ilmid"        TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"  DEFAULT="0"   SEQUENCE="false" ENUM="false" COMMENT="Id of the iLM "                                  PREVIOUS="cmid"       NEXT="action"/>
+        <FIELD NAME="action"       TYPE="char" LENGTH="255"    NOTNULL="true"                                 SEQUENCE="false" ENUM="false" COMMENT="Action of user in active course"                 PREVIOUS="ilmid"      NEXT="info"/>
+        <FIELD NAME="info"         TYPE="text" LENGTH="medium" NOTNULL="false"                                SEQUENCE="false"              COMMENT="The additional information of log"               PREVIOUS="action"     NEXT="language"/>
+        <FIELD NAME="language"     TYPE="char" LENGTH="10"     NOTNULL="true"                                 SEQUENCE="false" ENUM="false" COMMENT="The language code of active user"                PREVIOUS="info"       NEXT="user_agent"/>
+        <FIELD NAME="user_agent"   TYPE="char" LENGTH="255"    NOTNULL="true"                                 SEQUENCE="false" ENUM="false" COMMENT="User agent  of active user"                      PREVIOUS="language"   NEXT="javascript"/>
+        <FIELD NAME="javascript"   TYPE="int"  LENGTH="1"      NOTNULL="true"  UNSIGNED="true"  DEFAULT="0"   SEQUENCE="false" ENUM="false" COMMENT="User agent allow Javascript ? 0 - no / 1 - yes"  PREVIOUS="user_agent" NEXT="java"/>
+        <FIELD NAME="java"         TYPE="int"  LENGTH="1"      NOTNULL="true"  UNSIGNED="true"  DEFAULT="0"   SEQUENCE="false" ENUM="false" COMMENT="User agent allow Java ? 0 - no / 1 - yes"        PREVIOUS="javascript"/>
+      </FIELDS>
+      <KEYS>
+        <KEY   NAME="primary" TYPE="primary" FIELDS="id" />
+      </KEYS>
+      <INDEXES>
+        <INDEX NAME="course"  UNIQUE="false" FIELDS="course"/>
+      </INDEXES>
+    </TABLE>
+    <TABLE NAME="iassign_statement" COMMENT="Info about interactive activities"  PREVIOUS="iassign_log" NEXT="iassign_submission">
+      <FIELDS>
+        <FIELD NAME="id"                       TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"              SEQUENCE="true"  ENUM="false" COMMENT="Primary key of table"                                                                             NEXT="name"/>
+        <FIELD NAME="name"                     TYPE="char" LENGTH="255"    NOTNULL="true"                               SEQUENCE="false" ENUM="false" COMMENT="Title of activity"                                                PREVIOUS="id"                   NEXT="iassignid"/>
+        <FIELD NAME="iassignid"                TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"  DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="id of the task in which the activity is inserted"                 PREVIOUS="name"                 NEXT="type_iassign"/>
+        <FIELD NAME="type_iassign"             TYPE="int"  LENGTH="2"      NOTNULL="true"  UNSIGNED="true"  DEFAULT="3" SEQUENCE="false" ENUM="false" COMMENT="Type of activity. 1 - example / 2 - test / 3 - exercise"          PREVIOUS="iassignid"            NEXT="proposition"/>
+        <FIELD NAME="proposition"              TYPE="text" LENGTH="medium" NOTNULL="false"                              SEQUENCE="false" ENUM="false" COMMENT="Proposition the activity"                                         PREVIOUS="type_iassign"         NEXT="author_name"/>
+        <FIELD NAME="author_name"              TYPE="char" LENGTH="255"    NOTNULL="true"                               SEQUENCE="false" ENUM="false" COMMENT="Author name the activity"                                         PREVIOUS="proposition"          NEXT="author_modified_name"/>
+        <FIELD NAME="author_modified_name"     TYPE="char" LENGTH="255"    NOTNULL="true"                               SEQUENCE="false" ENUM="false" COMMENT="Name of last author to modify the activity"                       PREVIOUS="author_name"          NEXT="iassign_ilmid"/>
+        <FIELD NAME="iassign_ilmid"            TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"              SEQUENCE="false" ENUM="false" COMMENT="iLM id used in the activity"                                      PREVIOUS="author_modified_name" NEXT="file"/>
+        <FIELD NAME="file"                     TYPE="char" LENGTH="255"    NOTNULL="false"                              SEQUENCE="false" ENUM="false" COMMENT="Address and file name of the activity"                            PREVIOUS="iassign_ilmid"        NEXT="grade"/>
+        <FIELD NAME="grade"                    TYPE="float"                NOTNULL="true"  UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Maximum score for activity"                                       PREVIOUS="file"                 NEXT="timemodified"/>
+        <FIELD NAME="timemodified"             TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"  DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Date of last modification"                                        PREVIOUS="grade"                NEXT="timecreated"/>
+        <FIELD NAME="timecreated"              TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"  DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Date of creation"                                                 PREVIOUS="timemodified"         NEXT="timeavailable"/>
+        <FIELD NAME="timeavailable"            TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"  DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Date of opening activity"                                         PREVIOUS="timecreated"          NEXT="timedue"/>
+        <FIELD NAME="timedue"                  TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"  DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Closing date of the activity"                                     PREVIOUS="timeavailable"        NEXT="preventlate"/>
+        <FIELD NAME="preventlate"              TYPE="int"  LENGTH="2"      NOTNULL="false" UNSIGNED="true"  DEFAULT="1" SEQUENCE="false" ENUM="false" COMMENT="Allow sending late? 0 - no / 1 - yes"                             PREVIOUS="timedue"              NEXT="test"/>
+        <FIELD NAME="test"                     TYPE="int"  LENGTH="1"      NOTNULL="false" UNSIGNED="true"  DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Activity to release test after closing time? 0 - no / 1 - yes"    PREVIOUS="preventlate"          NEXT="special_param1"/>
+        <FIELD NAME="special_param1"           TYPE="int"  LENGTH="1"      NOTNULL="false" UNSIGNED="true"  DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Activity contains algorithm? 0 - no / 1 - yes"                    PREVIOUS="test"                 NEXT="position" />
+        <FIELD NAME="position"                 TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"  DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Position of activity within the group"                            PREVIOUS="special_param1"       NEXT="visible"/>
+        <FIELD NAME="visible"                  TYPE="int"  LENGTH="1"      NOTNULL="false" UNSIGNED="true"  DEFAULT="1" SEQUENCE="false" ENUM="false" COMMENT="Status of viewing activity. 0 – hide / 1 - show"                  PREVIOUS="position"             NEXT="max_experiment"/>
+        <FIELD NAME="max_experiment"           TYPE="int"  LENGTH="10"     NOTNULL="true"  UNSIGNED="true"  DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Maximum number of attempts. 0 - unlimited"                        PREVIOUS="visible"              NEXT="dependency"/>
+        <FIELD NAME="dependency"               TYPE="char" LENGTH="255"    NOTNULL="true"  UNSIGNED="true"  DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="List the activities that this activity depends. 0 - independent"  PREVIOUS="max_experiment"       NEXT="automatic_evaluate"/>
+        <FIELD NAME="automatic_evaluate"       TYPE="int"  LENGTH="1"      NOTNULL="false" UNSIGNED="true"  DEFAULT="1" SEQUENCE="false" ENUM="false" COMMENT="Using automatic evaluation activity?0 - no / 1 - yes"             PREVIOUS="dependency"           NEXT="show_answer"/>
+        <FIELD NAME="show_answer"              TYPE="int"  LENGTH="1"      NOTNULL="false" UNSIGNED="true"  DEFAULT="1" SEQUENCE="false" ENUM="false" COMMENT="Show automatic evaluation results to students? 0 - no / 1 - yes"  PREVIOUS="automatic_evaluate"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary"       TYPE="primary" FIELDS="id" NEXT="iassignid"/>
+        <KEY NAME="iassignid"     TYPE="foreign" FIELDS="iassignid"     REFTABLE="iassign"     REFFIELDS="id" PREVIOUS="primary" NEXT="iassign_ilmid"/>
+        <KEY NAME="iassign_ilmid" TYPE="foreign" FIELDS="iassign_ilmid" REFTABLE="iassign_ilm" REFFIELDS="id" PREVIOUS="iassignid"/>
+      </KEYS>
+    </TABLE>
+    <TABLE NAME="iassign_submission" COMMENT="Info about submissions of interactive activities" PREVIOUS="iassign_statement" NEXT="iassign_submission_comment">
+      <FIELDS>
+        <FIELD NAME="id"                  TYPE="int"  LENGTH="10"  NOTNULL="true" UNSIGNED="true"              SEQUENCE="true"   ENUM="false" COMMENT="Primary key of table"                                                                                                              NEXT="iassign_statementid"/>
+        <FIELD NAME="iassign_statementid" TYPE="int"  LENGTH="10"  NOTNULL="true" UNSIGNED="true"  DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="id interactive activity"                                                                            PREVIOUS="id"                  NEXT="userid"/>
+        <FIELD NAME="userid"              TYPE="int"  LENGTH="10"  NOTNULL="true" UNSIGNED="true"  DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="id of submitting author"                                                                            PREVIOUS="iassign_statementid" NEXT="timecreated"/>
+        <FIELD NAME="timecreated"         TYPE="int"  LENGTH="10"  NOTNULL="true" UNSIGNED="true"  DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="Date of first submission"                                                                           PREVIOUS="userid"              NEXT="timemodified"/>
+        <FIELD NAME="timemodified"        TYPE="int"  LENGTH="10"  NOTNULL="true" UNSIGNED="true"  DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="Date last modified"                                                                                 PREVIOUS="timecreated"         NEXT="grade"/>
+        <FIELD NAME="grade"               TYPE="float"             NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="Grade of evaluation"                                                                                PREVIOUS="timemodified"        NEXT="previous_grade"/>
+        <FIELD NAME="previous_grade"      TYPE="float"             NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="Previous grade of evaluation"                                                                       PREVIOUS="grade"               NEXT="teacher"/>
+        <FIELD NAME="teacher"             TYPE="int"  LENGTH="10"  NOTNULL="true" UNSIGNED="true"  DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="id teacher"                                                                                         PREVIOUS="previous_grade"               NEXT="answer"/>
+        <FIELD NAME="answer"              TYPE="text" LENGTH="big" NOTNULL="true"                              SEQUENCE="false"  ENUM="false" COMMENT="String with the last solution sent by the student"                                                  PREVIOUS="teacher"             NEXT="experiment"/>
+        <FIELD NAME="experiment"          TYPE="int"  LENGTH="1"   NOTNULL="true" UNSIGNED="true"  DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="Total  of submissions"                                                                              PREVIOUS="answer"              NEXT="status"/>
+        <FIELD NAME="status"              TYPE="int"  LENGTH="1"   NOTNULL="true" UNSIGNED="true"  DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="Status of activities. 0-not submitted/1-submitted/2-evaluated as incorrect/3-evaluated as correct"  PREVIOUS="experiment"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary"             TYPE="primary" FIELDS="id" NEXT="iassign_statementid"/>
+        <KEY NAME="iassign_statementid" TYPE="foreign" FIELDS="iassign_statementid" REFTABLE="iassign_statement" REFFIELDS="id" PREVIOUS="primary"/>
+      </KEYS>
+      <INDEXES>
+        <INDEX NAME="userid" UNIQUE="false" FIELDS="userid"/>
+      </INDEXES>
+    </TABLE>
+    <TABLE NAME="iassign_submission_comment" COMMENT="Comments of interactive activities" PREVIOUS="iassign_submission" NEXT="iassign_security">
+      <FIELDS>
+        <FIELD NAME="id"                    TYPE="int"  LENGTH="10"   NOTNULL="true" UNSIGNED="true"             SEQUENCE="true"   ENUM="false" COMMENT="Primary key of table"                                                            NEXT="iassign_submissionid"/>
+        <FIELD NAME="iassign_submissionid"  TYPE="int"  LENGTH="10"   NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="id submission comment"                          PREVIOUS="id"                    NEXT="comment_authorid"/>
+        <FIELD NAME="comment_authorid"      TYPE="int"  LENGTH="10"   NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="id author comment"                              PREVIOUS="iassign_submissionid"  NEXT="timecreated"/>
+        <FIELD NAME="timecreated"           TYPE="int"  LENGTH="10"   NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="Date of sending the comment"                    PREVIOUS="comment_authorid"      NEXT="comment"/>
+        <FIELD NAME="comment"               TYPE="text" LENGTH="big"  NOTNULL="true"                             SEQUENCE="false"  ENUM="false" COMMENT="Comment"                                        PREVIOUS="timecreated"           NEXT="return_status"/>
+        <FIELD NAME="return_status"         TYPE="int"  LENGTH="1"    NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="Status of return. 0 - unread / 1 -read"         PREVIOUS="comment"               NEXT="receiver"/>
+        <FIELD NAME="receiver"              TYPE="int"  LENGTH="1"    NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="1 - message to teacher. 2 - message to student" PREVIOUS="return_status"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary"              TYPE="primary" FIELDS="id" NEXT="iassign_submissionid"/>
+        <KEY NAME="iassign_submissionid" TYPE="foreign" FIELDS="iassign_submissionid" REFTABLE="iassign_submission" REFFIELDS="id" PREVIOUS="primary"/>
+      </KEYS>
+    </TABLE>
+    <TABLE NAME="iassign_security" COMMENT="Info about secure access to interactive activities" PREVIOUS="iassign_submission_comment" NEXT="iassign_allsubmissions">
+      <FIELDS>
+        <FIELD NAME="id"                  TYPE="int"  LENGTH="10"   NOTNULL="true" UNSIGNED="true"             SEQUENCE="true"  ENUM="false"  COMMENT="Primary key of table"                                                     NEXT="iassign_statementid"/>
+        <FIELD NAME="iassign_statementid" TYPE="int"  LENGTH="10"   NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false"  COMMENT="id interactive activity"                   PREVIOUS="id"                  NEXT="userid"/>
+        <FIELD NAME="userid"              TYPE="int"  LENGTH="10"   NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false"  COMMENT="id of submitting author"                   PREVIOUS="iassign_statementid" NEXT="file"/>
+        <FIELD NAME="file"                TYPE="text" LENGTH="big"  NOTNULL="true"                             SEQUENCE="false" ENUM="false"  COMMENT="Origin of activity sent"                   PREVIOUS="userid"              NEXT="timecreated"/>
+        <FIELD NAME="timecreated"         TYPE="int"  LENGTH="10"   NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false"  COMMENT="Moment that the activity has been invoked" PREVIOUS="file"                NEXT="view"/>
+        <FIELD NAME="view"                TYPE="int"  LENGTH="10"   NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false"  COMMENT="Preview control flag of the iLM"           PREVIOUS="timecreated"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary"      TYPE="primary" FIELDS="id" NEXT="iassign_statementid"/>
+        <KEY NAME="iassign_statementid" TYPE="foreign" FIELDS="iassign_statementid" REFTABLE="iassign_statement" REFFIELDS="id" PREVIOUS="primary"/>
+      </KEYS>
+    </TABLE>
+    <TABLE NAME="iassign_allsubmissions" COMMENT="Stores all submissions from students" PREVIOUS="iassign_security">
+      <FIELDS>
+        <FIELD NAME="id"                  TYPE="int"  LENGTH="10"  NOTNULL="true" UNSIGNED="true"              SEQUENCE="true"   ENUM="false" COMMENT="Primary key of table"                                                                                                              NEXT="iassign_statementid"/>
+        <FIELD NAME="iassign_statementid" TYPE="int"  LENGTH="10"  NOTNULL="true" UNSIGNED="true"  DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="id interactive activity"                                                                            PREVIOUS="id"                  NEXT="userid"/>
+        <FIELD NAME="userid"              TYPE="int"  LENGTH="10"  NOTNULL="true" UNSIGNED="true"  DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="id of submitting author"                                                                            PREVIOUS="iassign_statementid" NEXT="timecreated"/>
+        <FIELD NAME="timecreated"         TYPE="int"  LENGTH="10"  NOTNULL="true" UNSIGNED="true"  DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="Date of first submission"                                                                           PREVIOUS="userid"              NEXT="grade"/>
+        <FIELD NAME="grade"               TYPE="float"             NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false"  ENUM="false" COMMENT="Grade of evaluation"                                                                                PREVIOUS="timecreated"        NEXT="answer"/>
+        <FIELD NAME="answer"              TYPE="text" LENGTH="big" NOTNULL="true"                              SEQUENCE="false"  ENUM="false" COMMENT="String with the last solution sent by the student"                                                  PREVIOUS="grade" />
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary"      TYPE="primary" FIELDS="id" NEXT="iassign_statementid"/>
+        <KEY NAME="iassign_statementid" TYPE="foreign" FIELDS="iassign_statementid" REFTABLE="iassign_statement" REFFIELDS="id" PREVIOUS="primary"/>
+      </KEYS>
+    </TABLE>
+  </TABLES>
+</XMLDB>

+ 35 - 0
db/log.php

@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * Definition of log events
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2010/09/27
+ * @package mod_iassign_db
+ * @since 2010/09/27
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * 
+ * <b>License</b> 
+ *  - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+/**
+ * Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly.
+ */
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Array of log events.
+ */
+$logs = array(
+  array('module' => 'iassign', 'action' => 'view', 'mtable' => 'iassign_view', 'field' => 'name'),
+  array('module' => 'iassign', 'action' => 'add', 'mtable' => 'iassign_add', 'field' => 'name'),
+  array('module' => 'iassign', 'action' => 'update', 'mtable' => 'iassign_update', 'field' => 'name'),
+  array('module' => 'iassign', 'action' => 'view submission', 'mtable' => 'iassign_view_submission', 'field' => 'name'),
+  array('module' => 'iassign', 'action' => 'upload', 'mtable' => 'iassign_upload', 'field' => 'name'),
+  array('module' => 'iassign', 'action' => 'update comment', 'mtable' => 'iassign_update_comment', 'field' => 'name'),
+  array('module' => 'iassign', 'action' => 'update submission', 'mtable' => 'iassign_update_submission', 'field' => 'name'),
+  array('module' => 'iassign', 'action' => 'delete iassign', 'mtable' => 'iassign_delete', 'field' => 'name'),
+  array('module' => 'iassign', 'action' => 'add comment', 'mtable' => 'iassign_add_comment', 'field' => 'name'),
+  array('module' => 'iassign', 'action' => 'add submission', 'mtable' => 'iassign_add_comment', 'field' => 'name'),
+);

+ 43 - 0
db/uninstall.php

@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * This file replaces the legacy STATEMENTS section in db/install.xml,
+ * lib.php/modulename_install() post installation hook and partially defaults.php
+ *
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.2 2013/08/20
+ * @package mod_iassign_db
+ * @since 2010/09/27
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * 
+ * <b>License</b> 
+ *  - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
+/// Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly.
+defined('MOODLE_INTERNAL') || die();
+
+/// This is called at the beginning of the uninstallation process to give the module
+//  a chance to clean-up its hacks, bits etc. where possible.
+//  @return bool Return true if success.
+
+require_once ($CFG->dirroot . '/mod/iassign/locallib.php');
+
+function xmldb_iassign_uninstall () {
+  global $DB;
+  $fs = get_file_storage();
+
+  $context_system = context_system::instance();
+  $fs->delete_area_files($context_system->id, 'mod_iassign', 'ilm');
+
+  $courses = $DB->get_records('course');
+  foreach ($courses as $course) {
+    $context_course = context_course::instance($course->id);
+    $fs->delete_area_files($context_course->id, 'mod_iassign', 'exercise');
+    $fs->delete_area_files($context_course->id, 'mod_iassign', 'activity');
+    }
+
+  return true;
+  }

+ 680 - 0
db/upgrade.php

@@ -0,0 +1,680 @@
+<?php
+
+/**
+ * This file keeps track of upgrades to the lams module.
+ * 
+ * Sometimes, changes between versions involve
+ * alterations to database structures and other
+ * major things that may break installations.
+ * The upgrade function in this file will attempt
+ * to perform all the necessary actions to upgrade
+ * your older installtion to the current version.
+ * If there's something it cannot do itself, it
+ * will tell you what you need to do.
+ * The commands in here will all be database-neutral,
+ * using the functions defined in lib/ddllib.php
+ * 
+ * - v 1.5.2 2020/08/03
+ *     + Fixed 'ALTER TABLE' of 'iassign_submission.grade' from BIGINT(11) to REAL 
+ *     + New version of iHanoi 1.0.20200803
+ * - v 1.5.1 2020/05/28-30
+ *     + Avoid to update one iLM causing colision with other instance of the same iLM
+ * - v 1.4 2013/09/19
+ *     + Insert general fields for iassign statement (grade, timeavaliable, timedue, preventlate, test, max_experiment).
+ *     + Change index field 'name' in 'iassign_ilm' table to index field 'name,version'.
+ * - v 1.2 2013/08/30
+ * + Change 'filearea' for new concept for files.
+ * + Change path file for ilm, consider version in pathname.
+ * 
+ * @author Leônidas O. Brandão
+ * @author Patricia Alves Rodrigues
+ * @author Igor Moreira Félix
+ * @version v 1.5.1 2020/05/28-30
+ * @version v 1.5 2019/03/13
+ * @version v 1.4 2013/09/19
+ * @package mod_iassign_db
+ * @since 2010/12/21
+ * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
+ * 
+ * <b>License</b> 
+ *  - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ *  
+ * @param $oldversion Number of the old version. 
+ */
+
+require_once ($CFG->dirroot . '/mod/iassign/locallib.php');
+
+function xmldb_iassign_upgrade ($oldversion) {
+
+  global $CFG, $DB, $USER;
+
+  $dbman = $DB->get_manager();
+
+  if ($oldversion < 2014012100) {
+    // Define field and index in iLM table to be added
+    $table = new xmldb_table('iassign_ilm');
+    $index_name = new xmldb_index('name');
+    $index_name->set_attributes(XMLDB_INDEX_UNIQUE, array('name'));
+    if ($dbman->index_exists($table, $index_name)) {
+      $dbman->drop_index($table, $index_name, $continue = true, $feedback = true);
+      }
+    $index_name_version = new xmldb_index('name_version');
+    $index_name_version->set_attributes(XMLDB_INDEX_UNIQUE, array('name', 'version'));
+    if (!$dbman->index_exists($table, $index_name_version)) {
+      $dbman->add_index($table, $index_name_version, $continue = true, $feedback = true);
+      }
+
+    // Fix field name in ilm table to be added.
+    $table = new xmldb_table('iassign_ilm');
+    $field_height = new xmldb_field('heigth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '600', 'width');
+    if ($dbman->field_exists($table, $field_height))
+      $dbman->rename_field($table, $field_height, 'height');
+
+    // Define fields in iassign table to be added.
+    $table = new xmldb_table('iassign');
+    $field_intro = new xmldb_field('intro', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'name');
+    if (!$dbman->field_exists($table, $field_intro))
+      $dbman->add_field($table, $field_intro);
+    $field_introformat = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'intro');
+    if (!$dbman->field_exists($table, $field_introformat))
+      $dbman->add_field($table, $field_introformat);
+    $field_grade = new xmldb_field('grade', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, '0', 'activity_group');
+    if (!$dbman->field_exists($table, $field_grade))
+      $dbman->add_field($table, $field_grade);
+    $field_timeavailable = new xmldb_field('timeavailable', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'grade');
+    if (!$dbman->field_exists($table, $field_timeavailable))
+      $dbman->add_field($table, $field_timeavailable);
+    $field_timedue = new xmldb_field('timedue', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timeavailable');
+    if (!$dbman->field_exists($table, $field_timedue))
+      $dbman->add_field($table, $field_timedue);
+    $field_preventlate = new xmldb_field('preventlate', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, '1', 'timedue');
+    if (!$dbman->field_exists($table, $field_preventlate))
+      $dbman->add_field($table, $field_preventlate);
+    $field_test = new xmldb_field('test', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0', 'preventlate');
+    if (!$dbman->field_exists($table, $field_test))
+      $dbman->add_field($table, $field_test);
+    $field_max_experiment = new xmldb_field('max_experiment', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'test');
+    if (!$dbman->field_exists($table, $field_max_experiment))
+      $dbman->add_field($table, $field_max_experiment);
+
+    if (!$dbman->table_exists($table)) {
+      $field_id = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE);
+      $field_time = new xmldb_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
+      $field_userid = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'time');
+      $field_ip = new xmldb_field('ip', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'userid');
+      $field_course = new xmldb_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ip');
+      $field_cmid = new xmldb_field('cmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'course');
+      $field_ilmid = new xmldb_field('ilmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'cmid');
+      $field_action = new xmldb_field('action', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'ilmid');
+      $field_info = new xmldb_field('info', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'action');
+      $field_language = new xmldb_field('language', XMLDB_TYPE_CHAR, '10', null, null, null, null, 'info');
+      $field_user_agent = new xmldb_field('user_agent', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'language');
+      $field_javascript = new xmldb_field('javascript', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'user_agent');
+      $field_java = new xmldb_field('java', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'javascript');
+
+      $key = new xmldb_key('primary');
+      $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'), null, null);
+
+      $index = new xmldb_index('course');
+      $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
+
+      $table->addField($field_id);
+      $table->addField($field_time);
+      $table->addField($field_userid);
+      $table->addField($field_ip);
+      $table->addField($field_course);
+      $table->addField($field_cmid);
+      $table->addField($field_ilmid);
+      $table->addField($field_action);
+      $table->addField($field_info);
+      $table->addField($field_language);
+      $table->addField($field_user_agent);
+      $table->addField($field_javascript);
+      $table->addField($field_java);
+
+      $table->addKey($key);
+
+      $table->addIndex($index);
+
+      $status = $dbman->create_table($table);
+      } // if (!$dbman->table_exists($table))
+
+    // Now update Moodle table '*_files' related to the iAssign: insert new field 'filearea'
+    $fs = get_file_storage();
+    $is_delete = true;
+    $ilm_path = $CFG->dirroot . "/mod/iassign/ilm/";
+
+    // All iAssign 'exercises' must get the label 'exercise'
+    $exercise_files = $DB->get_records('files', array("component" => "mod_iassign", "filearea" => "activity"));
+    foreach ($exercise_files as $exercise_file) {
+      $exercise_file->filearea = "exercise";
+      $DB->update_record('files', $exercise_file);
+      }
+
+    // All iAssign iLM (usually 'JAR package') must get the label 'activity'
+    $activity_files = $DB->get_records('files', array("component" => "mod_iassign", "filearea" => "ilm"));
+    foreach ($activity_files as $activity_file) {
+      $activity_file->filearea = "activity";
+      $DB->update_record('files', $activity_file);
+      }
+
+    // iAssign savepoint reached
+    upgrade_mod_savepoint(true, 2014012100, 'iassign');
+    } // if ($oldversion < 2014012100)
+
+  if ($oldversion < 2017021900) { // update to migrate from 2016021300 to 2017021900 (2.2.00)
+    // iassign_ilm : id; name; version; description; url; extension; parent; file_jar; file_class; width; height; enable; timemodified; author; timecreated; evaluate
+    $count_iassign_ilm = $DB->count_records_sql('SELECT COUNT(id) FROM {iassign_ilm}'); // count the number of existing iLM in table '*_iassign_ilm'
+    if ($count_iassign_ilm>0) { // Insert new iLM: iVProgH5 (package in HTML5 technology)
+
+      // Insert an entry in the Moodle table '*_files'
+      $context = context_system::instance();
+      $file_ilm = array(
+        'userid' => $USER->id, // ID of context
+        'contextid' => $context->id, // ID of context
+        'component' => 'mod_iassign', // usually = table name
+        'filearea' => 'ilm', // in table '*_files' all iAssign exercises will have 'filearea="exercise"' and all iLM must be 'ilm'
+        'itemid' => 0,
+        'filepath' => '/iassign/ilm/', // any path beginning and ending in /
+        'filename' => "iVProg/1.0.20200221/ivprog/index.html"); // any filename: use the starting point of iVProgH5
+
+      // Now update Moodle table '*_files' related to the iAssign: insert new field 'filearea'
+      $fs = get_file_storage();
+      $is_delete = true;
+      $ilm_path = $CFG->dirroot . "/mod/iassign/ilm/";
+
+      //TODO iLM_HTML5 : What model to implement to HTML5?
+      //TODO 1. The first version of iLM HTML5 in '/var/www/html/moodle/mod/iassign/ilm/ilm-nome' and others in '/var/moodledata/filedir/'?
+      //TODO 2. Inserting new iLM HTML5 by ZIP file => explode it and register in '/var/moodledata/filedir/'?
+
+      // Create file using the content: the file information is inserted in the Moodle table '*_files'
+      // The real file will be registered in Moodle data (default '/var/moodledata/filedir/xx/yy' - 'xxyy' is the first 4 char in '*_files.contenthash')
+      //TODO Keep this even change the model to not insert iLM HTML5 (need this object to connect with '*_iassign_ilm' bellow)
+      $file_ilm = $fs->create_file_from_string($file_ilm, file_get_contents($ilm_path . "ivprog-html/main.html"));
+
+      if ($file_ilm)
+        $is_delete &= @unlink($ilm_path . "ivprog-html");
+
+      // Insert an entry in iAssign table '*_iassign_ilm'
+      $newentry = new stdClass();
+      $newentry->name = 'iVProg';
+      $newentry->url = 'http://www.matematica.br/ivprog';
+      $newentry->version = '1.0.20200221';
+      $newentry->description = '{"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}';
+      $newentry->extension = 'ivph';
+      $newentry->file_jar = 'iVProg/1.0.20200221/ivprog/'; // to JAR this is the '*_files.id' correponding to the iLM storaged in '/var/moodledata/filedir/'
+      $newentry->file_class = 'index.html';
+      $newentry->width = 800;
+      $newentry->height = 700;
+      $newentry->enable = 1;
+      $newentry->timemodified = time();
+      $newentry->author = $USER->id;
+      $newentry->timecreated = time();
+      $newentry->evaluate = 1;
+      // $DB->insert_records('iassign_ilm', $newentry);
+      $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
+
+      // iAssign savepoint reached
+      upgrade_mod_savepoint(true, 2017021900, 'iassign');
+      } // if ($count_iassign_ilm>0)
+
+    } // if ($oldversion < 2017021900)
+
+  if ($oldversion < 2017120100) { // last one: 2017042800 from 2017/02/19
+    // Create new field 'type', putting 'Java' if JAR and 'HTML5' if HTML5
+    // Update fields 'file_jar, file_class' of iLM iVProgH5 (from 'iVProgH5, ivprog-html/main.html' to 'ilm/ivprog-html/, main.html'
+
+    //---
+    // Define new field in iassign table to be added: type varchar(20) in { 'Java' 'HTML5' }
+    $table = new xmldb_table('iassign_ilm');
+    $new_field_type = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, null, null, null, 'version'); // after field 'version'
+    if (!$dbman->field_exists($table, $new_field_type))
+      $dbman->add_field($table, $new_field_type);
+
+    //---
+    // All iAssign iLM (usually 'JAR package') must get the type 'Java'
+    $list_of_ilm_installed = $DB->get_records('iassign_ilm');
+    foreach ($list_of_ilm_installed as $ilm_installed) {
+      $ilm_name = strtolower($ilm_installed->name);
+
+      if ($ilm_name=="ivprogh5" || $ilm_name=="ifractions" || $ilm_name=="fractions") { // if it is 'iVProgH5' (perhaps 'iFractions' already installed?)
+        $ilm_installed->type = "HTML5"; // it is HTML5
+        $file_jar = strtolower($ilm_installed->file_jar);
+        if ($ilm_name=="ivprogh5" && $file_jar=="ivprogh5") { // fields 'file_jar' and 'file_class' must have: 'ilm/ivprog-html/' and 'main.html'
+          $ilm_installed->file_jar = "ilm/ivprog-html/"; //  iVProgH5 ivprog-html/main.html
+          $ilm_installed->file_class = "main.html";
+          }
+        }
+      else
+        $ilm_installed->type = "Java"; // otherwise it is Java
+
+      $DB->update_record('iassign_ilm', $ilm_installed);
+      } // foreach
+
+    //---
+    // Insert in table '{iassign_ilm}' the new iLM iFractions version 0.1.2017.11.22
+    // Table 'iassign_ilm' : id name version type description url extension parent file_jar file_class width height enable timemodified author timecreated evaluate
+
+    } // if ($oldversion < 2017120101)
+
+  if ($oldversion < 2018031000) {
+    // Verify if exist iLM with the same name
+    // then, update the version and file_jar
+
+    $records = array(
+      array_combine( // iGeom 5.9.22
+        array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
+        array('iGeom', 'http://www.matematica.br/igeom', '5.9.22', 'Java', '{"en":"Interactive Geometry on the Internet","pt_br":"Geometria Interativa na Internet"}', 'geo', 'ilm/iGeom/5.9.22/iGeom.jar', 'IGeomApplet.class', 800, 600, 1, time(), $USER->id, time(), 1)),
+      array_combine( // iGraf 4.4.0.10
+        array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
+        array('iGraf', 'http://www.matematica.br/igraf', '4.4.0.10', 'Java', '{"en":"Interactive Graphic on the Internet","pt_br":"Gráficos Interativos na Internet"}', 'grf', 'ilm/iGraf/4.4.0.10/iGraf.jar', 'igraf.IGraf.class', 840, 600, 1, time(), $USER->id, time(), 1)),
+        );
+
+    foreach ($records as $record) {
+      if ($record['type'] == 'HTML5') {
+
+        // Verify if there is a HTML5 iLM register => update it
+        $iassign_ilm = $DB->get_records('iassign_ilm', array('name' => $record['name']));
+
+        if ($iassign_ilm) {
+          // Update file_jar and file_class
+
+          foreach ($iassign_ilm as $iassign) {
+            $iassign->name = trim($iassign->name);
+            $iassign->version = trim($iassign->version);
+            // If HTML5 iLM is the same version, only update the path
+            if ($iassign->version == $record['version']) {
+              $newentry = new stdClass();
+              $newentry->id = $iassign->id;
+              $newentry->file_jar = $record['file_jar'];
+              $newentry->file_class = $record['file_class'];
+
+              $DB->update_record("iassign_ilm", $newentry);
+              }
+            else { // If HTML5 iLM is NOT the same version, make a copy of the iLM
+              $dest = $CFG->dirroot . '/mod/iassign/ilm/' . $iassign->name . '/' . $iassign->version . '/';
+              mkdir($dest, 0755); // permissions "drwxr-xr-x"
+
+              $source = $CFG->dirroot . '/mod/iassign/ilm/' . $iassign->name . '/' . $record['version'] . '/';
+
+              foreach (
+                $iterator = new \RecursiveIteratorIterator(
+                  new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS),
+                  \RecursiveIteratorIterator::SELF_FIRST) as $item) {
+                if ($item->isDir()) {
+                  mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
+                  }
+                else { // copy or move?
+                  copy($item, $dest . $iterator->getSubPathName());
+                  // copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
+                  // rename($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
+                  }
+                }
+
+              $newentry = new stdClass();
+              $newentry->id = $iassign->id;
+              $newentry->file_jar = 'ilm/' . $iassign->name . '/' . $iassign->version . '/' . basename($record['file_jar']) . '/';
+              $newentry->file_class = $record['file_class'];
+
+              $DB->update_record("iassign_ilm", $newentry);
+              }
+            } // foreach ($iassign_ilm as $iassign)
+
+          }
+        else { // if ($iassign_ilm)
+          // If not found a iLM with the same name
+          $DB->insert_record('iassign_ilm', $record, false); // insert new iLM in the table '*_iassign_ilm'
+          }
+
+        } // if ($record['type'] == 'HTML5')
+      else {
+
+        // Verify if there is a Java iLM register to update it
+        $iassign_ilm = $DB->get_record('iassign_ilm', array('name' => $record['name'], 'version' => $record['version']));
+
+        if ($iassign_ilm) {
+          // Update file_jar and file_class
+          $newentry = new stdClass();
+          $newentry->id = $iassign_ilm->id;
+          $newentry->file_jar = $record['file_jar'];
+          $newentry->file_class = $record['file_class'];
+
+          $DB->update_record("iassign_ilm", $newentry);
+          }
+        else { // if ($iassign_ilm) - I couldn't find an iLM with this name ($record['name']) and under this version ($record['version'])
+          // If not found a Java iLM with the same name and version, search a
+          // different version, to use as parent of new version
+
+          $iassign_ilm_parent = $DB->get_record('iassign_ilm', array('name' => $record['name'], 'parent' => 0));
+
+          if ($iassign_ilm_parent) {
+            $record['parent'] = $iassign_ilm_parent->id;
+            $DB->insert_record('iassign_ilm', $record, false); // insert with parent
+
+            // Download the JAR file of parent from MoodleData and put it in iassign/ilm/
+            $dest = $CFG->dirroot . '/mod/iassign/ilm/' . $iassign_ilm_parent->name . '/' . $iassign_ilm_parent->version . '/';
+            mkdir($dest, 0777);
+
+            $fs = get_file_storage();
+            $file = $fs->get_file_by_id($iassign_ilm_parent->file_jar);
+            $file->copy_content_to($dest . $file->get_filename());
+
+            // Update file_jar of iLM parent
+            $update_parent = new stdClass();
+            $update_parent->id = $iassign_ilm_parent->id;
+            $update_parent->file_jar = 'ilm/' . $iassign_ilm_parent->name . '/' . $iassign_ilm_parent->version . '/' . $file->get_filename();
+
+            $DB->update_record("iassign_ilm", $update_parent);
+
+            }
+          else {
+            $DB->insert_record('iassign_ilm', $record, false); // insert new iLM in the table '*_iassign_ilm' without a parent
+            }
+          } // else if ($iassign_ilm)
+        } // else if ($record['type'] == 'HTML5')
+
+      } // foreach ($records as $record)
+
+    } // if ($oldversion < 2018031000)
+
+  //L if ($oldversion < 2019112219) {
+  if ($oldversion < 2020070613) {
+    $table = new xmldb_table('iassign_submission');
+    $field = new xmldb_field('previous_grade', XMLDB_TYPE_FLOAT, null, null, null, null, null);
+    if (!$dbman->field_exists($table, $field)) {
+      $dbman->add_field($table, $field);
+      }
+
+    $records = array( // iLM adjusted to iAssign 2020/08/03
+      array_combine( // iGeom 5.9.22
+        array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
+        array('iGeom', 'http://www.matematica.br/igeom', '5.9.22', 'Java', '{"en":"Interactive Geometry on the Internet","pt_br":"Geometria Interativa na Internet"}', 'geo', 'ilm/iGeom/5.9.22/iGeom.jar', 'IGeomApplet.class', 800, 600, 1, time(), $USER->id, time(), 1, 0)),
+      array_combine( // iGraf 4.4.0.10
+        array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
+        array('iGraf', 'http://www.matematica.br/igraf', '4.4.0.10', 'Java', '{"en":"Interactive Graphic on the Internet","pt_br":"Gráficos Interativos na Internet"}', 'grf', 'ilm/iGraf/4.4.0.10/iGraf.jar', 'igraf.IGraf.class', 840, 600, 1, time(), $USER->id, time(), 1, 0)),
+      array_combine( // iHanoi 1.0.20200803
+        array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
+        array('iHanoi', 'http://www.matematica.br/ihanoi', '1.0.20200803', 'HTML5', '{"en":"interactive Tower os Hanoi (by LInE)", "pt_br":"Torres de Hanói (do LInE)"}', 'ihn', 'ilm/iHanoi/1.0.20200803/ihanoi/', 'index.html', 1100, 500, 1, time(), $USER->id, time(), 1, 0)),
+      array_combine( // iVProg 1.0.20200221/ - HTML5 - 2020
+        array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
+        array('iVProg', 'http://www.usp.br/line/ivprog/', '1.0.20200221', 'HTML5', '{"en":"Visual Interactive Programming on the Internet (HTML)","pt_br":"Programação visual interativa na Internet"}', 'ivph', 'ilm/iVProg/1.0.20200221/ivprog/', 'index.html', 800, 600, 1, time(), $USER->id, time(), 1, 1)),
+      array_combine( // iFractions 0.1.20200221 - HTML5
+        array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'), 
+        array('iFractions', 'http://www.matematica.br/ifractions', '0.1.20200221', 'HTML5', '{"en":"Interactive Fractions game","pt_br":"Jogo interativa de frações"}', 'frc', 'ilm/iFractions/0.1.20200221/ifractions/', 'index.html', 1000, 600, 1, time(), $USER->id, time(), 1, 0))
+        );
+
+    $iassign_ilm = $DB->get_records('iassign_ilm');
+
+    $strNot_installed = '';
+    foreach ($records as $record) { // this version 'iassign_ilm' does not has field 'reevaluate'
+      $newentry = new stdClass();
+      $newentry->name = $record['name'];
+      $newentry->version = $record['version'];
+      $newentry->type = $record['type'];
+      $newentry->url = $record['url'];
+      $newentry->description = $record['description'];
+      $newentry->extension = $record['extension'];
+      $newentry->file_jar = $record['file_jar'];
+      $newentry->file_class = $record['file_class'];
+      $newentry->width = $record['width'];
+      $newentry->height = $record['height'];
+      $newentry->enable = $record['enable'];
+      $newentry->timemodified = time();
+      $newentry->author = $USER->id;
+      $newentry->timecreated = time();
+      $newentry->evaluate = $record['evaluate'];
+
+      $exists = 0;
+      if ($iassign_ilm) { // Search if there is any iLM of this with this version
+        $record_type = strtolower($record['type']);
+        foreach ($iassign_ilm as $iassign) {
+          if ($iassign->name == $record['name'] && strtolower($iassign->type) == $record_type) {
+            if ($iassign->version == $record['version']) { // or with the one with the same version
+              $exists = 1; // iLM found - exit with the last one, same version
+              $strNot_installed += "\n" + '  <li>' + $record['name'] + ';' + $record['type'] + ';' + $record['version'] + ' </li>' + "\n";
+              break;
+              }
+            }
+          }
+        }
+      if ($exists == 0) try { // iLM does not exists or it has old version
+        $DB->insert_record("iassign_ilm", $newentry, false);
+      } catch (Exception $e) {
+        print 'Caught exception: ' . $e->getMessage() . "<br/>\n";
+        }
+      } // foreach ($records as $record)
+    if ($strNot_installed != '') { // ATTENTION: this implies that Moodle administrator updated this iLM, please verify if it is really the current one.
+      print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
+      print get_string('upgrade_alert_exists', 'iassign'); // iLM previouly existent
+      print ' <ul style="margin-top: 1rem;">' + "\n";
+      print $strNot_installed;
+      print ' </ul>' + "\n";
+      print '</div>' + "\n";
+      }
+
+    // Verify if each iLM previously installed is present in fresh new iAssign. This does not means problem, perhaps the admin installed a particular iLM.
+    $strNot_found = '';
+    if ($iassign_ilm) { // exists iLM ($DB->get_records('iassign_ilm'))
+      foreach ($iassign_ilm as $iassign) {
+        $found = false;
+        foreach ($records as $record) {
+          if ($iassign->name == $record['name']) {
+            $found = true;
+            break;
+            }
+          }
+        if (!$found) {
+          $strNot_found .= '<li>' . $iassign->name . ' - <a href="' . $iassign->url . '" target="_blank">' . $iassign->url . '</a></li>' . "\n";
+          $updateentry = new stdClass();
+          $updateentry->id = $iassign->id;
+          $updateentry->enable = 0;
+          $updateentry->timemodified = time();
+          $DB->update_record("iassign_ilm", $updateentry); // insert new iLM
+          }
+        } // foreach ($iassign_ilm as $iassign)
+      } // if ($iassign_ilm)
+
+    if ($strNot_found != '') {
+      print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
+      print get_string('upgrade_alert_iMA_msg', 'iassign'); // Updated but some previous iLM installed are not available in fresh iAssign
+      print '<ul style="margin-top: 1rem;">' + "\n";
+      print $strNot_found;
+      print '</ul>' + "\n";
+      print get_string('upgrade_alert_iMA_solution_pt1', 'iassign');
+      print '<a href="'.new moodle_url('/admin/settings.php?section=modsettingiassign').'">' . get_string('upgrade_alert_iMA_solution_pt2', 'iassign') . '</a>.' . "\n";
+      print '</div>' + "\n";
+      }
+
+    } // if ($oldversion < 2020070613)
+
+  if ($oldversion < 2020070613) {
+    $table = new xmldb_table('iassign_ilm');
+    $field = new xmldb_field('reevaluate');
+    $field->set_attributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', null, null, null);
+    if (!$dbman->field_exists($table, $field)) { // if 'iassign_ilm.reevaluate' does not exist, then create this field
+      $dbman->add_field($table, $field);
+      }
+
+    $iassign_ilm = $DB->get_records('iassign_ilm');
+    foreach ($iassign_ilm as $iassign) { // If already installed iVProg/JS or iHanoi/JS set it with re-evaluate feature
+      if ($iassign->type == 'HTML5' && ($iassign->name == 'iVProg' || $iassign->name == 'iHanoi')) {
+        $updateentry = new stdClass();
+        $updateentry->id = $iassign->id;
+        $updateentry->reevaluate = 1;
+        $updateentry->timemodified = time();
+
+        $DB->update_record("iassign_ilm", $updateentry);
+        break;
+        }
+      }
+    } // if ($oldversion < 2020070612)
+
+  if ($oldversion < 2020080300) { // new iHanoi
+    // iassign_submission . grade : from 'BIGINT(11)' to 'real'
+    if ($dbman->field_exists('iassign', 'grade')) {
+      $sql = 'ALTER TABLE {iassign} CHANGE grade grade FLOAT NOT NULL DEFAULT 0.0';
+      $DB->execute($sql);
+      }
+    if ($dbman->field_exists('iassign_statement', 'grade')) {
+      $sql = 'ALTER TABLE {iassign_statement} CHANGE grade grade FLOAT NOT NULL DEFAULT 0.0';
+      $DB->execute($sql);
+      }
+    if ($dbman->field_exists('iassign_submission', 'grade')) {
+      $sql = 'ALTER TABLE {iassign_submission} CHANGE grade grade FLOAT NOT NULL DEFAULT 0.0';
+      $DB->execute($sql);
+      }
+    if ($dbman->field_exists('iassign_submission', 'previous_grade')) {
+      // $sql = 'ALTER TABLE {iassign_submission} CHANGE previous_grade previous_grade REAL NOT NULL DEFAULT 0.0'; // Invalid use of NULL value
+      $sql = 'ALTER TABLE {iassign_submission} CHANGE previous_grade previous_grade FLOAT DEFAULT 0.0';
+      $DB->execute($sql);
+      }
+
+    // Update iHanoi, iVProg, iFractions and iGeom
+    $records = array(
+      array_combine( // iHanoi 1.0.20200803
+        array('name', 'url', 'version', 'type', 'description',
+              'extension', 'file_jar', 'file_class', 'width', 'height',
+              'enable', 'timemodified', 'evaluate', 'reevaluate', 'author', 'timecreated'),
+        array('iHanoi', 'http://www.matematica.br/ihanoi', '1.0.20200803', 'HTML5', '{"en":"interactive Tower os Hanoi (by LInE)", "pt_br":"Torres de Hanói (do LInE)"}',
+              'ihn', 'ilm/iHanoi/1.0.20200803/ihanoi/', 'index.html', 1100, 500,
+              1, time(), 1, 1, $USER->id, time()))
+        );
+    $iassign_ilm = $DB->get_records('iassign_ilm');
+    foreach ($records as $record) { // For each iLM in the current version of iAssign
+      $newentry = new stdClass();
+      $newentry->name = $record['name'];
+      $newentry->version = $record['version'];
+      $newentry->type = $record['type'];
+      $newentry->url = $record['url'];
+      $newentry->description = $record['description'];
+      $newentry->extension = $record['extension'];
+      $newentry->file_jar = $record['file_jar'];
+      $newentry->file_class = $record['file_class'];
+      $newentry->width = $record['width'];
+      $newentry->height = $record['height'];
+      $newentry->enable = $record['enable'];
+      $newentry->timemodified = time();
+      $newentry->evaluate = $record['evaluate'];
+      $newentry->reevaluate = $record['reevaluate'];
+      $newentry->author = $USER->id;
+      $newentry->timecreated = time();
+      $newentry->evaluate = $record['evaluate'];
+
+      $exists = 0;
+      $last_id = -1;
+      if ($iassign_ilm) { // Search if there is any previous installed iLM that is also in the current version of iAssign
+        $record_type = strtolower($record['type']);
+        foreach ($iassign_ilm as $iassign) {
+          if ($iassign->name == $record['name'] && strtolower($iassign->type) == $record_type) {
+            if ($iassign->id > $last_id)
+              $last_id = $iassign->id; // last ID => last version (hopefully)
+            if ($iassign->version == $record['version']) { // or with the one with the same version
+              $exists = 1; // iLM found - exit with the last one, same version
+              $strNot_installed += "\n" + '  <li>' + $record['name'] + ';' + $record['type'] + ';' + $record['version'] + ' </li>' + "\n";
+              break;
+              }
+            }
+          }
+        }
+      if ($exists == 0) { // iLM does not exists or it has old version
+	$newentry->parent = $record['parent'];
+        $DB->insert_record("iassign_ilm", $newentry, false);
+        }
+      } // foreach ($records as $record)
+
+    if ($strNot_installed != '') {
+      print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
+      print get_string('upgrade_alert_exists', 'iassign'); // iLM previouly existent
+      print ' <ul style="margin-top: 1rem;">' + "\n";
+      print $strNot_installed;
+      print ' </ul>' + "\n";
+      print '</div>' + "\n";
+      }
+
+// s_iassign_ilm: atualizou iHanoi existente, mas nao era isso! Deveria ter inserido novo!
+//   id name   version type  ...  parent file_jar              file_class  width height  ...  evaluate reevaluate
+//   53 iHanoi 2       HTML5 ...  0      ilm/iHanoi/2/ihanoi/  index.html  1100  700     ...  1        0
+
+
+    $iassign_ilm = $DB->get_records('iassign_ilm');
+    foreach ($iassign_ilm as $iassign) { // for iLM iHanoi update the new field 'reevaluate' as 1
+      if ($iassign->name == 'iHanoi' && $iassign->type == 'HTML5' && $iassign->reevaluate!=1) {
+        $updateentry = new stdClass();
+        $updateentry->id = $iassign->id;
+        $updateentry->reevaluate = 1;
+        $updateentry->timemodified = time();
+        $DB->update_record("iassign_ilm", $updateentry);
+        break;
+        }
+      }
+
+    // iAssign savepoint reached.
+    upgrade_mod_savepoint(true, 2020080300, 'iassign');
+
+    } // if ($oldversion < 2020080300)
+
+    //TODO Codigo do Igor para atualizar 'files.itemid' e 'iassign_statement.filesid':
+    if ($oldversion < 2020102800) {
+      // 1. encontrar os contextos dos arquivos do itarefa:
+      $iassign_contexts_list = $DB->get_records_sql("SELECT contextid FROM {files} f " .
+        " WHERE component='mod_iassign'");
+      // 2. compor um array com todos os contextos encontrados: 
+      $contexts = array();
+      foreach ($iassign_contexts_list as $iassign_context_item) {
+        array_push($contexts, $iassign_context_item->contextid);
+      }
+      // 3. encontrar todas as atividades do itarefa, em que o arquivo não tenha o mesmo id do statement:
+      $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
+        " WHERE s.id != s.file");
+      $fs = get_file_storage();
+
+      // 4. percorrer o conjunto de atividades:
+      foreach ($iassign_statement_list as $iassign_statement_activity_item) {
+        
+        // 5. encontrar o arquivo, considerando os possíveis contextos:
+        $files = array();
+        foreach ($contexts as $context) {
+
+          $files = $fs->get_area_files($context, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
+
+          // 6. se o arquivo for encontrado, fazer uma cópia do conteúdo, 
+          // com o itemid novo, atualizar o iassign_statement, e apagar o arquivo antigo:
+          if ($files) {
+            foreach ($files as $value) {
+              if ($value != null && $value->get_filename() != ".") {
+                // 6.A. Fazer uma cópia:
+                $newfile = $fs->create_file_from_storedfile(array('contextid' => $context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_statement_activity_item->id), $value);
+
+                // 6.B. Atualizar o registro da atividade para o arquivo novo:
+                $update_entry = new stdClass();
+                $update_entry->id = $iassign_statement_activity_item->id;
+                $update_entry->file = $newfile->get_itemid();
+                $DB->update_record("iassign_statement", $update_entry);
+
+                // 6.C. Remover o arquivo antigo:
+                $value->delete();
+              } else if ($value != null && $value->get_filename() == ".") {
+                // 6.C.I. Remover também os indicadores de diretório:
+                $value->delete();
+              }
+            }
+            break;
+          }
+        }
+                  
+      }
+    } // if ($oldversion < 2020102800)
+
+
+  // log event -----------------------------------------------------
+  if (class_exists('plugin_manager'))
+    $pluginman = plugin_manager::instance();
+  else
+    $pluginman = core_plugin_manager::instance();
+  $plugins = $pluginman->get_plugins();
+  iassign_log::add_log('upgrade', 'version: ' . $plugins['mod']['iassign']->versiondisk);
+  // log event -----------------------------------------------------
+
+  return true;
+
+  } // function xmldb_iassign_upgrade($oldversion)

+ 72 - 0
grade.php

@@ -0,0 +1,72 @@
+<?php
+
+/**
+ * This script contains all the stuff to display evaluate.
+ * 
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.0 2010/12/21
+ * @package mod_iassign
+ * @since 2010/09/27
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * 
+ * <b>License</b> 
+ *  - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once("../../config.php");
+
+// Recovery th ID of active user.
+$id = required_param('id', PARAM_INT); // Course module ID
+
+// Constrain the url for redirect user.
+$url = new moodle_url('/mod/iassign/view.php'); // novo
+
+if ($id) {
+  if (!$cm = get_coursemodule_from_id('iassign', $id)) {
+    print_error('invalidcoursemodule');
+    }
+
+  if (!$iassign = $DB->get_record("iassign", array("id" => $cm->instance))) {
+    print_error('invalidid', 'iassign');
+    }
+
+  if (!$course = $DB->get_record("course", array("id" => $iassign->course))) {
+    print_error('coursemisconf', 'iassign');
+    }
+  $url->param('id', $id);
+  }
+else {
+  if (!$iassign = $DB->get_record("iassign", array("id" => $a))) {
+    print_error('invalidid', 'iassign');
+    }
+  if (!$course = $DB->get_record("course", array("id" => $iassign->course))) {
+    print_error('coursemisconf', 'iassign');
+    }
+  if (!$cm = get_coursemodule_from_instance("iassign", $iassign->id, $course->id)) {
+    print_error('invalidcoursemodule');
+    }
+  $url->param('a', $a);
+  }
+
+$PAGE->set_url($url);
+
+require_login($course, true, $cm);
+
+$PAGE->set_title(format_string($iassign->name));
+$PAGE->set_heading($course->fullname);
+
+require_once ("$CFG->dirroot/mod/iassign/locallib.php");
+
+
+/// Get an instance of iassign.
+$iassigninstance = new iassign($iassign, $cm, $course);
+
+if (has_capability('mod/iassign:viewreport', context_module::instance($cm->id))) {
+  $iassigninstance->action = 'report';
+  $iassigninstance->stats();
+  }
+elseif (has_capability('mod/iassign:submitiassign', context_module::instance($cm->id)))
+  $iassigninstance->stats_students();
+else
+  $iassigninstance->view();

+ 568 - 0
iassign_form.php

@@ -0,0 +1,568 @@
+<?php
+
+/**
+ * Form to add and edit interactive activities
+ * 
+ * 
+ * Release Notes:
+ * - v 1.5.1 2020/01/21
+ *   + Filter 'addslach(.)' to avoid ' and " close command JavaScript and verify if field 'grade' in JS is 'undefined'
+ * - v 1.5 2013/09/19
+ *   + Insert function for validation form (mod_iassign_form::validation).
+ *   + Fix bugs in download exercise file.
+ * - v 1.4 2013/08/21
+ *   + Change title link with message for get file for donwload file.
+ * - v 1.3 2013/08/15
+ *   + Change view file for allow download file.
+ * - v 1.2 2013/08/01
+ *   + Fix error in sql query for var $igeom.
+ * - v 1.1 2013/07/12
+ *   + Fix error messages of 'setType' in debug mode for hidden fields.
+ * 
+ * @author Patricia Alves Rodrigues
+ * @author Leônidas O. Brandão
+ * @version v 1.5 2013/09/19
+ * @package mod_iassign
+ * @since 2010/09/27
+ * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
+ * 
+ * <b>License</b> 
+ *  - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
+// Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly.
+if (!defined('MOODLE_INTERNAL')) {
+  die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
+  }
+
+require_once($CFG->libdir . '/formslib.php');
+require_once($CFG->dirroot . '/course/moodleform_mod.php');
+require_once($CFG->dirroot . '/mod/iassign/lib.php');
+
+
+/// This class create form based moodleform.
+//  @see moodleform
+class mod_iassign_form extends moodleform {
+
+  /// Add elements to form
+  function definition () {
+    global $CFG, $COURSE, $USER, $DB, $OUTPUT; // $OUTPUT only used to get '$OUTPUT->help_icon(...)'
+    $mform = $this->_form;
+    $instance = $this->_customdata;
+
+    // iGeom has special parameter 'script'
+    $params = array('name' => '%iGeom%', 'parent' => 0);
+    $igeom = $DB->get_records_sql(
+      "SELECT s.id, s.name, s.parent FROM {iassign_ilm} s
+       WHERE s.name LIKE :name AND s.parent = :parent", $params);
+    $id = $COURSE->cm;
+    foreach ($igeom as $item)
+      $idigeom = $item->id; // get the last id of iGeom
+    
+    // Get recently used ilm id: @igor
+    $params = array('curso' => $COURSE->id);
+    $result_recent = $DB->get_record_sql(
+      "SELECT stm.iassign_ilmid FROM {iassign_statement} stm, {iassign} ias
+       WHERE stm.iassignid = ias.id AND ias.course=:curso ORDER BY stm.id DESC LIMIT 1", $params);
+    
+    $all_ilm = $DB->get_records('iassign_ilm', array('enable' => 1)); // or use ./lib.php function: $all_ilm = search_iLM(1);
+    $iassigns = $DB->get_records('iassign_statement', array('iassignid' => $COURSE->iassignid));
+
+    if ($all_ilm) {
+      $ids = "";
+      $names = "";
+      $evaluates = "";
+      foreach ($all_ilm as $one_ilm) {
+        $ids .= "'" . $one_ilm->id . "',";
+        $names .= "'" . $one_ilm->name . "',";
+        $evaluates .= "'" . $one_ilm->evaluate . "',";
+        }
+      $ids .= "'0'";
+      $evaluates .= "'0'";
+      }
+    $name_iassigns = "";
+    if ($iassigns) {
+      foreach ($iassigns as $iassign) {
+        $name_iassigns .= "'" . addslashes($iassign->name) . "',"; // if the name has ' it implies close JavaScript string => error!
+        }
+      }
+    $name_iassigns .= "''";
+
+    $error_name = get_string('error_iassign_name', 'iassign');
+
+    // @todo Código Javascript, verificar alternativa.
+    $code_javascript = "
+  <script type='text/javascript'>
+  //<![CDATA[
+
+   var i;
+   var ids = new Array($ids);
+   var evaluates = new Array($evaluates);
+
+   document.forms['mform1'].filename.disabled=1;  
+
+   if (document.forms['mform1'].type_iassign.value==1) {
+     if (typeof document.forms['mform1'].grade === 'undefined') ; // do nothing
+     else document.forms['mform1'].grade.style.display='none';
+     document.forms['mform1'].max_experiment.style.display='none';
+   } else {
+     if (typeof document.forms['mform1'].grade === 'undefined') ; // do nothing
+     else document.forms['mform1'].grade.style.display='block';
+     document.forms['mform1'].max_experiment.style.display='block';
+     }
+
+  for (i=0;i<ids.length;i++) {
+    if (ids[i]==document.forms['mform1'].iassign_ilmid.value && evaluates[i]==0) {
+      document.forms['mform1'].automatic_evaluate.style.display='none';
+      document.forms['mform1'].show_answer.style.display='none';
+      //document.forms['mform1'].automatic_evaluate.disabled=1;
+      // document.forms['mform1'].show_answer.disabled=1;
+      }
+    }
+
+  if (document.forms['mform1'].iassign_ilmid.value==" . $idigeom .") { // iGeom has special parameter 'script'
+    document.forms['mform1'].special_param1.style.display='block';
+    document.forms['mform1'].special_param1.disabled=0;
+    }
+  else {
+    document.forms['mform1'].special_param1.style.display='none';
+    document.forms['mform1'].special_param1.value=0;
+    document.forms['mform1'].special_param1.disabled=1;
+    }
+
+  function confirm_name (name) {
+    var i;
+    var names = new Array(" . $name_iassigns . ");
+    for (i=0;i<names.length;i++) {
+       if (names[i]==name)
+         alert('" . $error_name . "');
+       }
+    }
+
+  function config_ilm (id) {
+    //alert('config_ilm('+id+'): idigeom=$idigeom, ilmid='+document.forms['mform1'].iassign_ilmid.value);
+    if (id==$idigeom) {
+      document.forms['mform1'].special_param1.style.display='block';
+      document.forms['mform1'].special_param1.disabled=0;
+      }
+    else {
+      document.forms['mform1'].special_param1.style.display='none';
+      document.forms['mform1'].special_param1.value=0;
+      document.forms['mform1'].special_param1.disabled=1;
+      }
+    var i;
+    var ids = new Array($ids);
+    var evaluates = new Array($evaluates);
+    if (document.forms['mform1'].type_iassign.value==1) {
+      document.forms['mform1'].automatic_evaluate.disabled=1;
+      document.forms['mform1'].show_answer.disabled=1;
+      document.forms['mform1'].automatic_evaluate.value=0;
+      document.forms['mform1'].show_answer.value=0;
+      }
+    else { // if (document.forms['mform1'].type_iassign.value==1)
+      for (i=0;i<ids.length;i++) {
+        if (ids[i]==id) {
+          if (document.forms['mform1'].action.value=='edit') {
+            if (evaluates[i]==0){
+              document.forms['mform1'].automatic_evaluate.style.display='none';
+              document.forms['mform1'].show_answer.style.display='none';
+              document.forms['mform1'].automatic_evaluate.disabled=1;
+              document.forms['mform1'].show_answer.disabled=1;
+              document.forms['mform1'].automatic_evaluate.value=0;
+              document.forms['mform1'].show_answer.value=0;
+              }
+            else {
+              document.forms['mform1'].automatic_evaluate.style.display='block';
+              document.forms['mform1'].show_answer.style.display='block';
+              document.forms['mform1'].automatic_evaluate.disabled=0;
+              document.forms['mform1'].show_answer.disabled=0;
+              document.forms['mform1'].automatic_evaluate.value=1;
+              document.forms['mform1'].show_answer.value=1;
+              }
+            }
+
+          if (document.forms['mform1'].action.value=='add') {
+            if (evaluates[i]==0) {
+              document.forms['mform1'].automatic_evaluate.style.display='none';
+              document.forms['mform1'].show_answer.style.display='none';
+              document.forms['mform1'].automatic_evaluate.disabled=1;
+              document.forms['mform1'].show_answer.disabled=1;
+              document.forms['mform1'].automatic_evaluate.value=0;
+              document.forms['mform1'].show_answer.value=0;
+              }
+            else {
+              document.forms['mform1'].automatic_evaluate.style.display='block';
+              document.forms['mform1'].show_answer.style.display='block';
+              document.forms['mform1'].automatic_evaluate.disabled=0;
+              document.forms['mform1'].show_answer.disabled=0;
+              document.forms['mform1'].automatic_evaluate.value=1;
+              document.forms['mform1'].show_answer.value=1;
+              }
+            }
+          } // if (ids[i]==id)
+        } // for (i=0;i<ids.length;i++)
+      } // else if (document.forms['mform1'].type_iassign.value==1)
+    } // function config_ilm(id)
+
+  function disable_answer (resp) {
+    if (resp==0) {
+      document.forms['mform1'].show_answer.value=0;
+      document.forms['mform1'].show_answer.disabled=1;
+      }
+    else {
+      document.forms['mform1'].show_answer.disabled=0;
+      }
+    }
+
+  function view_ilm_manager () {
+    document.forms['mform1'].filename.disabled=1;
+    open_ilm_manager=window.open('$CFG->wwwroot/mod/iassign/ilm_manager.php?id=$COURSE->id&from=iassign&ilmid='+document.forms['mform1'].iassign_ilmid.value,'','width=1000,height=880,menubar=0,location=0,scrollbars,status,fullscreen,resizable');
+    }
+  //]]>
+  </script>";
+
+    //-------------------------------------------------------------------------------
+    // Adding the "title_type_iassign" fieldset, where all the common settings are showed
+    // Data is insert through 'locallib.php ! action() -> new_iassign($param) : 3433/6441'
+
+    $mform->addElement('header', 'title_type_iassign', get_string('type_iassign', 'iassign'));
+    $type_iassign = array();
+    $type_iassign[1] = get_string('example', 'iassign');
+    $type_iassign[2] = get_string('test', 'iassign');
+    $type_iassign[3] = get_string('exercise', 'iassign');
+
+    $mform->addElement('select', 'type_iassign', get_string('choose_type_activity', 'iassign'), $type_iassign, array('onChange' => 'config_type(this.value);'));
+    $mform->setDefault('type_iassign', 3); // default type_iassign = 3
+    $mform->addHelpButton('type_iassign', 'helptypeiassign', 'iassign');
+    //-------------------------------------------------------------------------------
+    // Adding the "data_activity" fieldset, where all the common settings are showed
+
+    $mform->addElement('header', 'data_activity', get_string('data_activity', 'iassign'));
+    $mform->addElement('static', 'author', get_string('author_id', 'iassign'));
+    $mform->addElement('static', 'author_modified', get_string('author_id_modified', 'iassign'));
+
+    // Adding the standard "name" field
+    $mform->addElement('text', 'name', get_string('iassigntitle', 'iassign'), array('size' => '55', 'onChange' => 'confirm_name(this.value);'));
+    $mform->setType('name', PARAM_TEXT);
+    $mform->addRule('name', get_string('required', 'iassign'), 'required');
+
+    // Adding the standard "proposition" field
+    //moodle2: $mform->addElement('htmleditor', 'proposition', get_string('proposition', 'iassign'));
+    $mform->addElement('editor', 'proposition', get_string('proposition', 'iassign')); //moodle 3
+    $mform->setType('proposition', PARAM_RAW);
+    $mform->addRule('proposition', get_string('required', 'iassign'), 'required');
+
+    //-----------------------------------------------------------------------------
+    // Adding the "interactivy_learning_module" fieldset, where all the common settings are showed
+    $mform->addElement('header', 'interactivy_learning_module', get_string('interactivy_learning_module', 'iassign'));
+    $mform->setExpanded('interactivy_learning_module');
+
+    // Search iLM registered in the database
+    // Field : 'iassign_ilmid'
+    // $ilms = search_iLM(1);
+    $ilms = $all_ilm;
+
+    //TODO Trick: was difficult to use 'mform->addGroup(...)', then I made by hand <select name='iassign_ilmid'...>' with 'optgroup' by hand!
+    //TODO But MoodleForm clear/do not register the 'iassign_ilmid' in 'locallib.php!new_iassign($param)'
+    //TODO Then (in 'new_iassign(...)') get $_POST['iassign_ilmid'] directly!!
+    //TODO See: 'locallib.php!add_edit_iassign()', 'locallib.php!function add_edit_iassign()' and 'locallib.php!function new_iassign($param)'
+
+    //2019 $applets = array();
+    //2019 foreach ($ilms as $ilm)
+    //2019   $applets[$ilm->id] = $ilm->name . ' ' . $ilm->version;
+    //2019 $mform->addElement('select', 'iassign_ilmid', get_string('choose_iLM', 'iassign'), $applets, array('onChange' => 'config_ilm(this.value);'));
+    //2019 $mform->addHelpButton('iassign_ilmid', 'helpchoose_ilm', 'iassign');
+
+    //D echo "<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>iassign_form.php:<br/>";
+    // Split all iLM in those HTML from Java
+    $list_html = array(); $list_html_id = array();
+    $list_applets = array(); $list_applets_id = array();
+
+    $num_iLM_html = $num_iLM_java = 0;
+    foreach ($ilms as $ilm) {
+      $type4 = substr($ilm->type, 0,4); // ensure the use of the only first 4 character (avoid difference if type is defined as 'HTML5')
+      if (strcasecmp($type4, "HTML") == 0) { //  Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. 
+        $list_html[$num_iLM_html] = $ilm->name . ' (' . $ilm->version . ')';
+        $list_html_id[$num_iLM_html] = $ilm->id;
+        $num_iLM_html++;
+      } else {
+        $list_applets[$num_iLM_java] = $ilm->name . ' (' . $ilm->version . ')';
+        $list_applets_id[$num_iLM_java] = $ilm->id;
+        $num_iLM_java++;
+        } //D echo $ilm->id . " : " . $ilm->type . " <br/>";
+      }
+    //D echo "" . get_string('interactivy_learning_module', 'iassign') . ": num_iLM_html=$num_iLM_html, num_iLM_java=$num_iLM_java<br/>";
+    //D Interactive Learning Modules: num_iLM_html=0, num_iLM_java=9
+
+    //TODO Assim o '/lib/formslib.php : get_data()' destroi o campo 'iassign_ilmid'...
+    $html_group = get_string("group", "iassign") . " HTML";
+    $java_group = get_string("group", "iassign") . " Java";
+    
+
+    $arrayHTML = array();
+    $arrayJava = array();
+
+    for ($ii=0; $ii<$num_iLM_html; $ii++) {
+      $arrayHTML[$list_html_id[$ii]] = $list_html[$ii];
+    }
+    for ($ii=0; $ii<$num_iLM_java; $ii++) {
+      $arrayJava[$list_applets_id[$ii]] = $list_applets[$ii];
+    }
+
+    $selectElems = array(
+      $html_group => $arrayHTML,
+      $java_group => $arrayJava
+    );
+ 
+    $ilm_select = $mform->addElement('selectgroups', 'iassign_ilmid', get_string('choose_iLM', 'iassign'), $selectElems);
+    $mform->addHelpButton('iassign_ilmid', 'choose_iLM', 'iassign');
+    
+    if ($result_recent && isset($result_recent->iassign_ilmid)) {
+      $code_javascript .= ' <script>  document.forms[0].iassign_ilmid.value = ' . $result_recent->iassign_ilmid . '</script>' ;
+    }
+ 
+    //TODO Adaptives to use API of MoodleForm
+    // addOption($optgroup, $text, $value, $attributes=null)
+    // $allOptions = array(); $ilmHtml = array(); $ilmJava = array();
+    // $ilmHtml[] = $mform->createElement('optgroup', 'groupHtml', 'Group HTML');
+    // for ($ii=0; $ii<$num_iLM_html; $ii++) $ilmHtml[] = $mform->createElement('optgroup', 'groupHtml', 'Group HTML'); //$allOptions[] = $mform->addOption('Group HTML', $list_html[$ii], $list_html_id[$ii]);
+    // $mform->addGroup($ilmHtml, 'groupHtml', '', array(' '), false);
+    // $list_html $list_html_id  $num_iLM_html
+    // $list_applets $list_applets_id   $num_iLM_java
+    // echo "<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>iassign_form.php: num_iLM_html=$num_iLM_html, num_iLM_java=$num_iLM_java<br/>";exit;
+    // $allOptions[] = array('-1' => 'Group HTML'); for ($ii=0; $ii<$num_iLM_html; $ii++) $allOptions[] = array(''.$list_html_id[$ii] => $list_html[$ii]);
+    // $allOptions[] = array('-2' => 'Group Java'); for ($ii=0; $ii<$num_iLM_java; $ii++) $allOptions[] = array(''.$list_applets_id[$ii] => $list_applets[$ii]);
+    //  $allOptions[$ilm->id] = $ilm->name . ' ' . $ilm->version;
+    // $mform->addElement('select', 'iassign_ilmid', get_string('choose_iLM', 'iassign'), $allOptions, array('onChange' => 'config_ilm(this.value);'));
+    // for ($ii=0; $ii<$num_iLM_html; $ii++) $allOptions[] = $list_html[$ii];
+    // for ($jj=0; $jj<$num_iLM_java; $jj++) $allOptions[] = $list_applets[$jj];
+    // $mform->addElement('select', 'iassign_ilmid', get_string('choose_iLM', 'iassign'), $allOptions, array('onChange' => 'config_ilm(this.value);'));
+    // $mform->addHelpButton('iassign_ilmid', 'helpchoose_ilm', 'iassign');
+
+    // Field 'action'
+    $fileurl = "";
+    $filename = "";
+    if (!is_null($COURSE->iassign_file_id)) {
+      $mform->addElement('hidden', 'action', 'viewpluginpage');
+      $fs = get_file_storage();
+      $file = $fs->get_file_by_id($COURSE->iassign_file_id);
+      $fileurl = $CFG->wwwroot . "/pluginfile.php/" . $file->get_contextid() . "/mod_iassign/exercise" . '/' . $file->get_itemid() . $file->get_filepath() . $file->get_filename();
+      $filename = $file->get_filename();
+      }
+    //D echo "123";
+    $html_div = '<div id="fitem_id_iassign_file_id" class="fitem required fitem_fgroup" style="padding: 35px; padding-left: 0;">';
+    $html_div .= '<div class="fitemtitle col-md-3" style="padding: 0; float: left;">' . get_string('choose_file', 'iassign'); // 'Choose the file with the iLM activity'
+    
+    $html_div .= '<span><a><i class="icon fa fa-exclamation-circle text-danger fa-fw " title="' . get_string('requiredelement', 'form') . '" aria-label="' . get_string('requiredelement', 'form') . '" style="float: right; cursor: help; padding-right: 15px;"></i></a></span></div>';
+    
+    $html_div .= '<div class="felement fselect" id="error_message_file"><div class="file_iassign" id="file_border" style="display: inline;margin-left: 14px;border: 1px solid #cecfd1;padding: 8px;padding-right: 8px;border-radius: 4px;padding-right: 2px;">';
+
+    $html_div .= '<i class="icon fa fa-file-text-o fa-fw" id="icon_doc" style="color: #8f8f8f;"></i><span id="iassign_file_link" style="color:#000000;"><a href="' . $fileurl . '" target="_blank" title="' . get_string('download_file', 'iassign') . $filename . '">' . $filename . '</a></span>';
+    
+    if ($fileurl != "")
+      $html_div .= '&nbsp;&nbsp;&nbsp;';
+    $html_div .= '<input onclick="view_ilm_manager()" name="add_ilm" value="' . get_string('add_ilm', 'iassign') . '" type="button" id="id_add_ilm"/></div>';
+    $html_div .= '</div>';
+    $html_div .= '</div>';
+    $mform->addElement('html', $html_div);
+
+
+    //Applies only iLM iGeom
+    $mform->addElement('selectyesno', 'special_param1', get_string('special_param', 'iassign')); //$ynoptions
+    $mform->setDefault('special_param1', 0);
+    $mform->addHelpButton('special_param1', 'helpspecial_param', 'iassign');
+
+    //-----------------------------------------------------------------------------
+    //Applies only when the iLM is automatic evaluate.
+    $mform->addElement('header', 'id_automatic_evaluate', get_string('only_automatic_evaluate', 'iassign'));
+
+    // Using automatic evaluation activity? 0 - no / 1 – yes
+    $mform->addElement('selectyesno', 'automatic_evaluate', get_string('automatic_evaluate', 'iassign'), array('onChange' => 'disable_answer(this.value);'));
+    $mform->disabledIf('automatic_evaluate', 'type_iassign', 'eq', 1); //activity does not display if the type example
+    $mform->setDefault('automatic_evaluate', 0);
+    // @todo Ver código comentado
+    //$mform->addHelpButton('automatic_evaluate', 'helpautomatic_evaluate', 'iassign');
+    //Show automatic evaluation results to students? 0 - no / 1 - yes
+    $mform->addElement('selectyesno', 'show_answer', get_string('show_answer', 'iassign'));
+    $mform->disabledIf('show_answer', 'type_iassign', 'eq', 1); //activity does not display if the type example
+    // $mform->disabledIf('show_answer', 'automatic_evaluate', 'neq', 0);
+    $mform->setDefault('show_answer', 0);
+    //$mform->addHelpButton('show_answer', 'helpshow_answer', 'iassign');
+
+    //-----------------------------------------------------------------------------
+    // Adding the "duration_activity" fieldset, where all the common settings are showed
+    $mform->addElement('header', 'duration_activity', get_string('duration_activity', 'iassign'));
+
+    $mform->addElement('date_time_selector', 'timeavailable', get_string('availabledate', 'iassign'));
+    $mform->setDefault('timeavailable', time());
+    $mform->disabledIf('timeavailable', 'type_iassign', 'eq', 1); // activity does not display if the type example
+    $mform->addElement('date_time_selector', 'timedue', get_string('duedate', 'iassign'));
+    $mform->setDefault('timedue', time() + 7 * 24 * 3600);
+    $mform->disabledIf('timedue', 'type_iassign', 'eq', 1); //activity does not display if the type example
+
+    //Allow sending late? 0 - no or unlocked / 1 - yes or locked
+    $mform->addElement('selectyesno', 'preventlate', get_string('preventlate', 'iassign'));
+    $mform->setDefault('preventlate', 0);
+    $mform->addHelpButton('preventlate', 'helppreventlate', 'iassign');
+
+    $mform->disabledIf('preventlate', 'type_iassign', 'eq', 1); //activity does not display if the type example
+    $mform->disabledIf('preventlate', 'type_iassign', 'eq', 2); //activity does not display if the type test
+    //Allow test after delivery? 0 - no or unlocked / 1 - yes or locked
+    $mform->addElement('selectyesno', 'test', get_string('permission_test', 'iassign'));
+    $mform->setDefault('test', 0);
+    $mform->addHelpButton('test', 'helptest', 'iassign');
+
+    $mform->disabledIf('test', 'type_iassign', 'eq', 1); //activity does not display if the type example
+    $mform->disabledIf('test', 'type_iassign', 'eq', 2); //activity does not display if the type test
+    //--------------
+    $mform->addElement('header', 'op_val', get_string('op_val', 'iassign'));
+
+    $mform->addElement('modgrade', 'grade', get_string('grade', 'iassign'));
+    $mform->setDefault('grade', 100);
+    $mform->disabledIf('grade', 'type_iassign', 'eq', 1); //activity does not display if the type example
+    $mform->disabledIf('grade', 'type_iassign', 'eq', 2); //activity does not display if the type test
+
+    $max_experiment_options = array(0 => get_string('ilimit', 'iassign'));
+    for ($i = 1; $i <= 20; $i++)
+      $max_experiment_options[$i] = $i;
+
+    $mform->addElement('select', 'max_experiment', get_string('experiment', 'iassign'), $max_experiment_options);
+    $mform->setDefault('max_experiment', 0);
+    $mform->addHelpButton('max_experiment', 'helpexperiment', 'iassign');
+    $mform->disabledIf('max_experiment', 'type_iassign', 'eq', 1); //activity does not display if the type example
+    $mform->disabledIf('max_experiment', 'type_iassign', 'eq', 2); //activity does not display if the type test
+
+    if ($COURSE->iassign_list) {
+      //-------------- dependency
+      $mform->addElement('header', 'headerdependency', get_string('dependency', 'iassign'));
+      $mform->addHelpButton('headerdependency', 'helpdependency', 'iassign');
+
+      foreach ($COURSE->iassign_list as $iassign) {
+        $tmp = 'iassign_list[' . $iassign->id . ']';
+        if ($iassign->enable == 1)
+          $mform->addElement('checkbox', $tmp, $iassign->name);
+        } //foreach ($COURSE->iassign_list as $iassign)
+      } //if ($COURSE->iassign_list)
+
+    $mform->addElement('hidden', 'dependency');
+    $mform->setType('dependency', PARAM_RAW);
+
+    //-------------- config
+    $mform->addElement('header', 'config', get_string('general', 'iassign'));
+    $visibleoptions = array(1 => get_string('show'), 0 => get_string('hide'));
+
+    $mform->addElement('select', 'visible', get_string('visible', 'iassign'), $visibleoptions);
+    $mform->setDefault('visible', 0);
+
+    //-------------------------------------------------------------------------------
+    // Hidden fields
+    $mform->addElement('hidden', 'action');
+    $mform->setType('action', PARAM_TEXT);
+    $mform->addElement('hidden', 'oldname');
+    $mform->setType('oldname', PARAM_TEXT);
+    $mform->addElement('hidden', 'id');
+    $mform->setType('id', PARAM_TEXT);
+    $mform->addElement('hidden', 'iassign_id');
+    $mform->setType('iassign_id', PARAM_TEXT);
+    $mform->addElement('hidden', 'file', '0');
+    $mform->setType('file', PARAM_INT);
+    $mform->addElement('hidden', 'filename');
+    $mform->setType('filename', PARAM_TEXT);
+    $mform->addElement('hidden', 'fileold');
+    $mform->setType('fileold', PARAM_TEXT);
+    $mform->addElement('hidden', 'iassignid');
+    $mform->setType('iassignid', PARAM_TEXT);
+    $mform->addElement('hidden', 'author_name');
+    $mform->setType('author_name', PARAM_TEXT);
+    $mform->addElement('hidden', 'author_modified_name');
+    $mform->setType('author_modified_name', PARAM_TEXT);
+    $mform->addElement('hidden', 'timecreated');
+    $mform->setType('timecreated', PARAM_TEXT);
+    $mform->addElement('hidden', 'position');
+    $mform->setType('position', PARAM_TEXT);
+
+    $mform->addElement('html', $code_javascript);
+    // add standard elements, common to all modules
+    $this->add_action_buttons();
+
+    } // function definition()
+
+
+  function validation ($data, $files) {
+    global $COURSE, $DB;
+    $errors = parent::validation($data, $files);
+    $mform = & $this->_form;
+    $errors = array();
+
+    if ($mform->elementExists('name')) {
+      $value = trim($data['name']);
+      if ($value == '') {
+        $errors['name'] = get_string('required', 'iassign');
+        }
+      }
+
+    if ($mform->elementExists('proposition')) {
+      // echo "iassign_form.php : data['proposition'] :<br/>"; print_r($data['proposition']);
+      // $data['proposition'] = Array ([text] => ...  [format] => ) - segundo esta' vazio!
+      if (is_array($data['proposition'])) {
+
+        // foreach ($data['proposition'] as $key => $value) echo "key=" . $key . " - value=" . $value . "<br/>";
+        // $data['proposition'] = [format] => ) key=text - value=
+
+        $aux = $data['proposition']; // Format JSON: {"em":"...","pt":"..."}
+        if (isset($aux['text']))
+          $value = trim($aux['text']);
+        else
+          $value = trim($aux[0]);
+
+        }
+      else
+        $value = trim($data['proposition']);
+
+      if ($value == '') {
+        $errors['proposition'] = get_string('required', 'iassign');
+        }
+      }
+
+    // echo "iassign_form.php : mform :<br/>"; // print_r($mform); exit();
+
+    if ($mform->elementExists('file')) {
+      $value = trim($data['file']);
+      if ($value == 0) {
+        $errors['iassign_ilmid_t'] = get_string('required_iassign_file', 'iassign');
+
+        echo "<script>
+              window.onload = function(e){ 
+                document.getElementById('error_message_file').innerHTML += '<span style=\"font-size: 80%;color: #d9534f; margin-left: 1em;\">".get_string('required_iassign_file', 'iassign')."</span>';
+                document.getElementById('file_border').style.borderColor = '#d9534f';
+              } </script>";
+        } else {
+          $fs = get_file_storage(); // Get reference to all files in Moodle data
+          $file = $fs->get_file_by_id($value);
+
+          if ($file) {
+            // Verify if file extension is correct to iLM
+            $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $data['iassign_ilmid']));
+            
+            echo "<script>
+              window.onload = function(e){ 
+                document.getElementById('iassign_file_link').innerHTML = '".$file->get_filename()."&nbsp;&nbsp;&nbsp;';";
+                
+            if ($iassign_ilm->extension != pathinfo($file->get_filename(), PATHINFO_EXTENSION)) {
+              $errors['iassign_ilmid_t'] = get_string('incompatible_extension_file', 'iassign');
+
+              echo "document.getElementById('error_message_file').innerHTML += '<span style=\"font-size: 80%;color: #d9534f; margin-left: 1em;\">".get_string('incompatible_extension_file', 'iassign')."</span>';
+                    document.getElementById('file_border').style.borderColor = '#d9534f';";
+            }
+
+            echo "} </script>";
+          }
+          
+        }
+      }
+
+    return $errors;
+    } // function validation($data, $files)
+
+  } // class mod_iassign_form extends moodleform

BIN
icon/__comment_unread.gif


BIN
icon/add.gif


BIN
icon/add_iassign.gif


BIN
icon/add_ilm_iassign.gif


BIN
icon/add_param.gif


BIN
icon/addgreen.gif


BIN
icon/block.gif


BIN
icon/comment_close red.gif


BIN
icon/comment_close_green.gif


BIN
icon/comment_close_red1.gif


BIN
icon/comment_close_yellown.gif


BIN
icon/comment_read.gif


BIN
icon/comment_unread.gif


BIN
icon/config_ilm.gif


BIN
icon/confirm.gif


BIN
icon/copy_ilm.gif


BIN
icon/copy_param.gif


BIN
icon/correct.gif


BIN
icon/default_ilm.gif


BIN
icon/default_ilm_disabled.gif


BIN
icon/delete2.gif


BIN
icon/delete_assign_disable.gif


BIN
icon/delete_dir.gif


BIN
icon/delete_dir_disable.gif


BIN
icon/delete_iassign.gif


BIN
icon/delete_ilm.gif


BIN
icon/delete_ilm_disable.gif


BIN
icon/delete_param.gif


BIN
icon/dir.gif


BIN
icon/down_disable.gif


BIN
icon/download_all_assign.gif


BIN
icon/download_all_assign_disabled.gif


BIN
icon/download_assign.gif


BIN
icon/duplicate_iassign.gif


BIN
icon/edit_iassign.gif


BIN
icon/edit_iassign_disable.gif


BIN
icon/edit_ilm.gif


BIN
icon/edit_param.gif


BIN
icon/example.gif


BIN
icon/export_ilm.gif


BIN
icon/feedback_correct.gif


BIN
icon/feedback_incorrect.gif


BIN
icon/file.gif


BIN
icon/hbar_blue.gif


BIN
icon/hbar_blue_l.gif


BIN
icon/hbar_blue_r.gif


BIN
icon/hbar_green.gif


BIN
icon/hbar_green_l.gif


BIN
icon/hbar_green_r.gif


BIN
icon/hbar_orange.gif


BIN
icon/hbar_orange_l.gif


BIN
icon/hbar_orange_r.gif


BIN
icon/hbar_red.gif


BIN
icon/hbar_red_l.gif


BIN
icon/hbar_red_r.gif


BIN
icon/help_ilm.gif


BIN
icon/hide_iassign.gif


BIN
icon/hide_ilm.gif


BIN
icon/hide_param.gif


BIN
icon/home.gif


BIN
icon/icon.gif


BIN
icon/incorrect.gif


+ 10 - 0
icon/index.html

@@ -0,0 +1,10 @@
+<html>
+    <head>
+        <meta charset="UTF-8">
+        <title>Acess not allowed! - Acesso não permitido</title>
+    </head>
+    <body style="color: #FF0000">
+        <p>Acesso não permitido!</p>
+        <p>Acess not allowed!</p>
+    </body>
+</html>

BIN
icon/left_disable.gif


BIN
icon/maximize.png


BIN
icon/move_activity.gif


BIN
icon/move_down_iassign.gif


BIN
icon/move_up_iassign.gif


BIN
icon/next_activity.gif


BIN
icon/next_student.gif


BIN
icon/next_student_activity.gif


+ 0 - 0
icon/no_edit_iassign.gif


Some files were not shown because too many files changed in this diff