9 次代码提交 4806ba5b9f ... 41542fe4c3

作者 SHA1 备注 提交日期
  leo 41542fe4c3 Update 'lang/pt_br/iassign.php' 2 年之前
  leo 9a3d1531f7 Update 'lang/fr/iassign.php' 2 年之前
  leo 87d82f7198 Update 'lang/es/iassign.php' 2 年之前
  leo 3a9877e498 Update 'lang/en/iassign.php' 2 年之前
  leo 658fcfb103 Update 'ilm_handlers/html5.php' 2 年之前
  leo 4117bc5f08 Update 'settings_form.php' 2 年之前
  leo 447cbf95f1 Update 'settings_ilm.php' 2 年之前
  leo ea952f46d8 Update 'settings.php' 2 年之前
  leo c3feba807d Update 'locallib.php' 2 年之前
共有 9 个文件被更改,包括 483 次插入222 次删除
  1. 25 9
      ilm_handlers/html5.php
  2. 9 4
      lang/en/iassign.php
  3. 13 6
      lang/es/iassign.php
  4. 14 6
      lang/fr/iassign.php
  5. 9 2
      lang/pt_br/iassign.php
  6. 282 120
      locallib.php
  7. 101 67
      settings.php
  8. 18 5
      settings_form.php
  9. 12 3
      settings_ilm.php

+ 25 - 9
ilm_handlers/html5.php

@@ -3,9 +3,9 @@
 /**
  * Class that implements ilm_handle, in order to allow manipulation and management of HTML5 iLM
  * 
- * @author Igor Moreira Félix
+ * @author Igor Moreira Fe'lix
  * @author Patricia Alves Rodrigues
- * @author Leônidas O. Brandão
+ * @author Leo^nidas O. Branda~o
  * @version v 1 2017/17/10
  * @package mod_iassign_ilm_handlers
  * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
@@ -22,6 +22,7 @@ class html5 implements ilm_handle {
 
 
   /// Produce HTML code to load iLM
+  //  @calledby  locallib.php: class ilm_settings: function build_ilm_tags($ilm_id, $options=array()): $retorno=$typec::build_ilm_tags($ilm_id, $options);
   public static function build_ilm_tags ($ilm_id, $options = array()) {
     global $DB, $OUTPUT;
     global $CONF_WWW; //TODO 1 => use iLM under WWW; otherwise use under MoodleData
@@ -203,6 +204,9 @@ class html5 implements ilm_handle {
       if (!$fileid) { // 'Something is wrong. Maybe your teacher withdrew this exercise file. Please, inform your teacher.';
         print iassign::warning_message_iassign('error_exercise_removed') . "<br/>\n"; // I couldn't find the file in table 'files'!
         }
+      //D echo "ilm_handlers/html5.php: {course_module}.id=" . $USER->cm .", {iassign_statement}.id=" . $iassign_statement_activity_item->id .
+      //D      ", {iassign_statement}.file=" . $iassign_statement_activity_item->file . ", {iassign_statement}.filesid=" . $iassign_statement_activity_item->filesid .
+      //D      ", {context}.id=" . $context->id . ", {files}.id=" . $fileid . ", {files}.filename=" . $files->filename . "<br/>";
       } // if ($view_teacherfileversion)
 
     $ilm_name = strtolower($ilm->name);
@@ -490,7 +494,7 @@ class html5 implements ilm_handle {
     $iassign_ilm->file_jar = null;
 
     $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA); //2019
-    $file_jar = self::save_ilm_by_xml($application_xml, $files_extract); // iLM ath (since iAssign)> ./ilm/...
+    $file_jar = self::save_ilm_by_xml($application_xml, $files_extract); // iLM path (since iAssign)> ./ilm/...
 
     if ($file_jar == null) { // 'save_ilm_by_xml(...)' detected a problem (perhaps no write permission)
       return false;
@@ -536,7 +540,7 @@ class html5 implements ilm_handle {
     $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
 
     $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $ilm_id)); //MOOC 2016
-    /*if (!$iassign_ilm_configs) return;*/
+    //if (!$iassign_ilm_configs) return;
 
     $files_jar = $iassign_ilm->file_jar;
 
@@ -730,6 +734,10 @@ class html5 implements ilm_handle {
     $updentry->enable = $param->enable;
     $updentry->timemodified = $param->timemodified;
     $updentry->evaluate = $param->evaluate;
+    $updentry->reevaluate = $param->reevaluate; // reevaluate = 1 => allows to the teacher calls method to re-evaluate (does it in batch, to all students)
+    $updentry->editingbehavior = $param->editingbehavior; // editingbehavior = 1 => iLM auto-evaluation remains working over a solution sent by the student (iGeom does not work, iVProg does)
+    $updentry->submissionbehavior = $param->submissionbehavior; // 0 => 'After submission, this iLM remains on the same page'; 1 => 'After submission, this iLM changes the current page'
+
     //D echo "./ilm_handlers/html5.php: edit_ilm(...): file_jar=$file_jar, file_class=" . $updentry->file_class . "<br/>"; //D exit;
 
     $DB->update_record("iassign_ilm", $updentry);
@@ -812,16 +820,19 @@ class html5 implements ilm_handle {
         break;
         }
 
-      print($OUTPUT->notification(get_string('error_import_ilm_version', 'iassign'), 'notifyproblem')); // There is another iLM with the sama version!
+      print($OUTPUT->notification(get_string('error_import_ilm_version', 'iassign'), 'notifyproblem')); // There is another iLM with the same version!
       return false;
       }
     else {
       $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
-     if ($file_jar == null) {
-       return false;
-       }
+      if ($file_jar == null) {
+        return false;
+        }
 
+      //2022/05/13
+      //D echo "/var/www/html/saw2021_2/mod/iassign/ilm_handlers/html5.php: file_jar=" . $file_jar . "<br/>\n";
       $file_jar = str_replace("./", "", $file_jar);
+      //D echo "/var/www/html/saw2021_2/mod/iassign/ilm_handlers/html5.php: file_jar=" . $file_jar . "<br/>\n";
 
       if (empty($file_jar)) {
         $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In new_ilm: file_jar empty, files_extract=" . $files_extract . "<br/>\n";
@@ -830,7 +841,9 @@ class html5 implements ilm_handle {
         //print("New file = " . file_jar . "<br/>");	  
         }
       else { // if (empty($file_jar))
-        $iassign_ilm = $DB->get_record('iassign_ilm', array("parent" => 0, "name" => (String) $application_xml->name));
+        $ilm_xml_name = (String) $application_xml->name;
+        //D echo "/var/www/html/saw2021_2/mod/iassign/ilm_handlers/html5.php: ilm_xml_name=" . $ilm_xml_name . "<br/>\n";
+        $iassign_ilm = $DB->get_record('iassign_ilm', array("parent" => 0, "name" => $ilm_xml_name));
         if (!$iassign_ilm) {
           $iassign_ilm = new stdClass(); //MOOC 2016
           $iassign_ilm->id = 0;
@@ -859,6 +872,9 @@ class html5 implements ilm_handle {
         $newentry->submissionbehavior = (String) $application_xml->submissionbehavior;
         $newentry->action_buttons = (String) $application_xml->action_buttons;
 
+        //D echo "/var/www/html/saw2021_2/mod/iassign/ilm_handlers/html5.php: name=" . $$newentry->name . "<br/>version=" . $$newentry->version . "<br/>\n";
+        //D echo "file_jar=" . $$newentry->file_jar . "<br/>\n";
+        //D exit;
         $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
 
         // log event --------------------------------------------------------------------------------------

+ 9 - 4
lang/en/iassign.php

@@ -5,6 +5,7 @@
  * 
  * @author Patricia Alves Rodrigues
  * @author Leônidas O. Brandão
+ * @version v 1.3.2 2022/09/15 (new tags associated to the fields 'evaluate,reevaluate,editingbehavior' of 'iassign_ilm')
  * @version v 1.3.1 2020/07/04 (reordered; adjusted 4 tags); v 1.3 2019/01/10 (480 tags); v 1.2 2017/03/10 ; v 1.1 2013/08/28
  * @package mod_iassign_lang
  * @since 2015/11/02
@@ -78,6 +79,11 @@ $string['auto_evaluate_stopped']          = 'Automatic evaluation has stopped.';
 $string['auto_evaluate_title']            = 'Automatic Evaluation';
 $string['auto_evaluate_title_time']       = 'iLM did not return any information. Click on the icon to details.';
 
+$string['auto_editingbehavior']           = 'Does it allow to edit a solution?';
+$string['auto_editingbehavior_help']      = 'The iLM allows to edit one submitted solution means that the automatic evaluator remains working after the student edit his solution';
+$string['auto_reevaluate']                = 'Does it allow batch re-evaluate?';
+$string['auto_reevaluate_help']           = 'The iLM allows to the teacher to re-evaluate the solutions sent by all the students is useful to avoid JavaScript expert fraud';
+
 $string['auto_result']                    = 'Result of automatic evaluation:';
 $string['automatic_evaluate']             = 'It must be used automatic evaluation in this activity?';
 $string['availabledate']                  = 'Available from';
@@ -438,7 +444,7 @@ $string['new_comment_mail_at']            = 'in the';
 $string['new_comment_mail_course']        = 'Course';
 $string['new_comment_mail_open_exercise'] = 'Open exercise	';
 $string['new_comment_mail_sent_by']       = 'Sent by';
-$string['new_comment_mail_subject']       = 'New received message in activity';
+$string['new_comment_mail_subject']       = 'New received message';
 $string['new_dir']                        = 'New directory';
 $string['new_file_jar']                   = 'New file JAR';
 $string['new_ilm']                        = 'Create a new interactive activity';
@@ -500,7 +506,7 @@ $string['rename_iassign']                 = 'Rename activity';
 $string['repeat']                         = 'Redo activity';
 $string['repeat_alt']                     = 'Use this button to redo the activity';
 $string['repeat_msg']                     = 'If you want to do this activity from the beginning again, use the redo button.';
-$string['report']                         = 'Report';
+$string['report']                         = 'Reports';
 $string['required']                       = 'Field is required';
 $string['required_file']                  = 'You must fill in <u> File Activity </u>';
 $string['required_iassign_file']          = 'You must select an interactive activity';
@@ -513,6 +519,7 @@ $string['return_iassign']                 = 'Back to exercise';
 $string['right']                          = 'Right';
 $string['right_disable']                  = 'Disable';
 $string['script']                         = 'Activity script (algorithm)? <br> (Applicable only to iLM iGeom)';
+$string['see_ilm_activities']             = 'See all the activities associated with this iLM';
 $string['select_move_ilm']                = 'Select the target directory to move files and directory';
 $string['show']                           = 'Show';
 $string['show_answer']                    = 'Show automatic evaluation results to students?';
@@ -535,8 +542,6 @@ $string['submissionbehavior_view']        = 'Submission';
 $string['submissions']                    = 'Submissions';
 $string['submission_behavior_0']          = 'After submission, this iLM remains on the same page.';
 $string['submission_behavior_1']          = 'After submission, this iLM changes the current page.';
-$string['submission_behavior_0']          = 'After submission, this iLM remains on the same page.';
-$string['submission_behavior_1']          = 'After submission, this iLM changes the current page.';
 $string['submit']                         = 'Submit the selected file';
 $string['submit_assign']                  = 'Send activity';
 $string['submit_comment']                 = 'Send message';

+ 13 - 6
lang/es/iassign.php

@@ -6,6 +6,7 @@
  * @author Patricia Alves Rodrigues
  * @author Leônidas O. Brandão
  * @author Marcelo de Arce Alemany (collaborator)
+ * @version v 1.3.2 2022/09/15 (new tags associated to the fields 'evaluate,reevaluate,editingbehavior' of 'iassign_ilm')
  * @version v 1.3.1 2020/07/04 (25 new tags; reordered); v 1.3 2019/01/10 (480 tags) ; v 1.2 2017/03/10 ; v 1.1 2013/08/28
  * @package mod_iassign_lang
  * @since 2015/11/02
@@ -75,6 +76,11 @@ $string['auto_evaluate_stopped']          = 'La evaluación automática se ha de
 $string['auto_evaluate_title']            = 'Evaluación automática';
 $string['auto_evaluate_title_time']       = 'El iMA no devolvió información alguma. Haz clic en el icono para más detalles.';
 
+$string['auto_editingbehavior']           = 'El iMA permite editar uma solución enviada?';
+$string['auto_editingbehavior_help']      = 'El iMA permite editar una solución enviada significa que el evaluador automático sigue funcionando después de que el estudiante edite su solución';
+$string['auto_reevaluate']                = 'El iMA permite al profesor reevaluar las soluciones enviadas por todos los estudiantes?';
+$string['auto_reevaluate_help']           = 'El iMA permite al profesor reevaluar las soluciones enviadas por todos los estudiantes es útil para evitar el fraude de expertos en JavaScript';
+
 $string['auto_result']                    = 'Resultado de la evaluación automática:';
 $string['automatic_evaluate']             = 'Usar evaluación automática en la tarea?';
 $string['availabledate']                  = 'Disponible a partir del';
@@ -422,12 +428,12 @@ $string['N_legend']                       = '(no esta en acuerdo en relación a
 $string['name_ilm']                       = 'Nombre';
 $string['new_category']                   = 'Nueva categoria';
 $string['new_comment']                    = 'Recados nuevos';
-$string['new_comment_mail_answer']        = 'Respuesta';
-$string['new_comment_mail_at']            = 'no';
-$string['new_comment_mail_course']        = 'Curso';
-$string['new_comment_mail_open_exercise'] = 'Ejercicio abierto';
+$string['new_comment_mail_answer']        = 'Responder';
+$string['new_comment_mail_at']            = 'en el';
+$string['new_comment_mail_course']        = 'Courso';
+$string['new_comment_mail_open_exercise'] = 'Abrir el ejercicio';
 $string['new_comment_mail_sent_by']       = 'Enviado por';
-$string['new_comment_mail_subject']       = 'Nueva mensaje recibida en actividad';
+$string['new_comment_mail_subject']       = 'Nueva mensaje recibida';
 $string['new_dir']                        = 'Nuevo directorio';
 $string['new_file_jar']                   = 'Nuevo Fichero JAR';
 $string['new_ilm']                        = 'Crea una nueva actividad interactiva';
@@ -498,6 +504,7 @@ $string['return_iassign']                 = 'Volver al ejercicio';
 $string['right']                          = 'direita';
 $string['right_disable']                  = 'Desactivado';
 $string['script']                         = 'Tarea con "script" (algoritmo)?<br>(Se aplica apenas al iMA iGeom)';
+$string['see_ilm_activities']             = 'Ver todas las actividades asociadas con este iMA';
 $string['select_move_ilm']                = 'Seleccione el directorio de destino para mover archivos y directorio';
 $string['show']                           = 'Mostrar';
 $string['show_answer']                    = 'Mostrar resultado de la evaluación automática a los alumnos?';
@@ -577,4 +584,4 @@ $string['what_do']                        = 'Que desea hacer ?';
 $string['width']                          = 'Largura';
 $string['Y']                              = 'S';
 $string['Y_legend']                       = '(esta en acuerdo en relación a lo que el profesor esperaba)';
-$string['yes']                            = 'Si';
+$string['yes']                            = 'Si';

+ 14 - 6
lang/fr/iassign.php

@@ -6,6 +6,7 @@
  * @author Patricia Alves Rodrigues
  * @author Leônidas O. Brandão
  * @author Danilo Leite Dalmon (collaborator)
+ * @version v 1.3.2 2022/09/15 (new tags associated to the fields 'evaluate,reevaluate,editingbehavior' of 'iassign_ilm')
  * @version v 1.3.1 2020/07/04 (25 new tags; reordered); v 1.3 2019/01/10 (480 tags); v 1.2 2017/03/10 ; v 1.1 2013/08/28 
  * @package mod_iassign_lang
  * @since 2015/11/02
@@ -75,6 +76,11 @@ $string['auto_evaluate_stopped']          = 'L\'évaluation automatique a eté a
 $string['auto_evaluate_title']            = 'Évaluation automatique';
 $string['auto_evaluate_title_time']       = 'iLM n\'a retourné aucune information. Cliquez sur l\'icône pour plus de détails.';
 
+$string['auto_editingbehavior']           = 'L\'iMA permet-il de modifier une solution soumise?';
+$string['auto_editingbehavior_help']      = 'L\'iMA permet de modifier une solution soumise signifie que l\'évaluateur automatique reste fonctionner après que l\'étudiant modifie sa solution';
+$string['auto_reevaluate']                = 'L\'iMA permet-il à l\'enseignant de réévaluer les solutions envoyées par tous les élèves?';
+$string['auto_reevaluate_help']           = 'L\'iMA permet à l\'enseignant de réévaluer les solutions envoyées par tous les élèves c\'est utile pour éviter fraude par l\'experts en JavaScript';
+
 $string['auto_result']                    = 'Résultat de l\'évaluation automatique :';
 $string['automatic_evaluate']             = 'Il faut utiliser l\'évaluation automatique dans cette activité';
 $string['availabledate']                  = 'Disponible à partir de';
@@ -421,11 +427,12 @@ $string['N_legend']                       = '(n\'est pas d\'accord avec ce que l
 $string['name_ilm']                       = 'Nom';
 $string['new_category']                   = 'Nouvelle catégorie';
 $string['new_comment']                    = 'Nouveaux messages';
-$string['new_comment_mail_answer']        = 'Answer';
-$string['new_comment_mail_course']        = 'Course';
-$string['new_comment_mail_open_exercise'] = 'Open exercise';
-$string['new_comment_mail_sent_by']       = 'Sent by';
-$string['new_comment_mail_subject']       = 'New received message';
+$string['new_comment_mail_answer']        = 'Réponse';
+$string['new_comment_mail_at']            = 'dans le';
+$string['new_comment_mail_course']        = 'Cours';
+$string['new_comment_mail_open_exercise'] = 'Ouvrir l\'exercice';
+$string['new_comment_mail_sent_by']       = 'Envoyée par';
+$string['new_comment_mail_subject']       = 'Nouveau message reçu';
 $string['new_dir']                        = 'Nouveau dossier';
 $string['new_file_jar']                   = 'Nouveau fichier JAR';
 $string['new_ilm']                        = 'Créer une nouvelle activité interactive';
@@ -496,6 +503,7 @@ $string['return_iassign']                 = 'Retourner à l\'exercice';
 $string['right']                          = 'droit';
 $string['right_disable']                  = 'Désactivé';
 $string['script']                         = 'Tâche avec un script (algorithme)?';
+$string['see_ilm_activities']             = 'Voir toutes les activités associées à cet iMA';
 $string['select_move_ilm']                = 'Sélectionnez le répertoire cible pour déplacer les fichiers et le répertoire';
 $string['show']                           = 'Montrer';
 $string['show_answer']                    = 'Afficher les résultats de l\'évaluation automatique aux étudiants?';
@@ -575,4 +583,4 @@ $string['what_do']                        = 'Que voulez-vous faire?';
 $string['width']                          = 'Largueur';
 $string['Y']                              = 'Oui';
 $string['Y_legend']                       = '(est d\'accord avec ce que le professeur attendait)';
-$string['yes']                            = 'Oui';
+$string['yes']                            = 'Oui';

+ 9 - 2
lang/pt_br/iassign.php

@@ -5,6 +5,7 @@
  * 
  * @author Patricia Alves Rodrigues
  * @author Leônidas O. Brandão
+ * @version v 1.3.2 2022/09/15 (new tags associated to the fields 'evaluate,reevaluate,editingbehavior' of 'iassign_ilm')
  * @version v 1.3.1 2020/07/04 (reordered; adjusted 4 tags); v 1.3 2019/01/10 (480 tags); v 1.2 2017/03/10 ; v 1.1 2013/08/28
  * @package mod_iassign_lang
  * @since 2015/11/02
@@ -78,6 +79,11 @@ $string['auto_evaluate_stopped']          = 'A avaliação foi interrompida.';
 $string['auto_evaluate_title']            = 'Avaliação Automática';
 $string['auto_evaluate_title_time']       = 'O iMA não respondeu. Clique no ícone para detalhes.';
 
+$string['auto_editingbehavior']           = 'O iMA permite editar uma solução enviada?';
+$string['auto_editingbehavior_help']      = 'O iMA permitir editar uma solução enviada significa que é possível o avaliador automático funcionar mesmo após o aluno editar uma solução enviada';
+$string['auto_reevaluate']                = 'O iMA permite re-avaliar todos os envios?';
+$string['auto_reevaluate_help']           = 'O iMA permite ao professor re-avaliar em lote os envios de todos os alunos, isso é útil para eliminar a chance de fraude via JavaScript';
+
 $string['auto_result']                    = 'Resultado da avaliação automática:';
 $string['automatic_evaluate']             = 'Usar avaliação automática na atividade?';
 $string['availabledate']                  = 'Disponível a partir de';
@@ -435,7 +441,7 @@ $string['new_comment_mail_at']            = 'no';
 $string['new_comment_mail_course']        = 'Curso';
 $string['new_comment_mail_open_exercise'] = 'Ver exercício';
 $string['new_comment_mail_sent_by']       = 'Enviado por';
-$string['new_comment_mail_subject']       = 'Nova mensagem recebida na atividade';
+$string['new_comment_mail_subject']       = 'Nova mensagem recebida';
 $string['new_dir']                        = 'Nova Pasta';
 $string['new_file_jar']                   = 'Novo arquivo jar';
 $string['new_ilm']                        = 'Criar nova atividade interativa online';
@@ -497,7 +503,7 @@ $string['rename_iassign']                 = 'Renomear atividade';
 $string['repeat']                         = 'Refazer atividade';
 $string['repeat_alt']                     = 'Use este botão para refazer a atividade';
 $string['repeat_msg']                     = 'Se deseja recomeçar do início esta atividade, utilize o botão "Refazer". Atenção: você perderá o conteúdo anteriormente enviado!';
-$string['report']                         = 'Relatório';
+$string['report']                         = 'Relatórios';
 $string['required']                       = 'É obrigatório o preenchimento deste campo';
 $string['required_file']                  = 'É obrigatório preencher o campo <u>Arquivo da atividade</u>';
 $string['required_iassign_file']          = 'É obrigatório selecionar uma atividade interativa';
@@ -510,6 +516,7 @@ $string['return_iassign']                 = 'Retornar ao exercício';
 $string['right']                          = 'direita';
 $string['right_disable']                  = 'Desabilitado';
 $string['script']                         = 'Atividade com "script" (algoritmo)?<br>(Aplicável apenas ao iMA iGeom)';
+$string['see_ilm_activities']             = 'Ver todas as atividades associadas com este iMA';
 $string['select_move_ilm']                = 'Selecione a pasta para mover os arquivos e pastas:';
 $string['show']                           = 'Mostrar';
 $string['show_answer']                    = 'Mostrar resultado da avaliação automática aos alunos?';

+ 282 - 120
locallib.php

@@ -4,8 +4,11 @@
  * This class provides all the functionality for an ia (interactive activities).
  *
  * Release Notes:
+ * - v 4.9.8 2022/09/15
+ *   + Fix iLM edition (now is possible to update fields 'reevaluate', 'editingbehavior' and 'evaluate' of table 'iassign_ilm')
  * - v 4.9.7 2022/02/11
- *   + Try to fix teacher edit of activity changing 'statement.id' to 'statement.file' in 'add_edit_iassign()'
+ *   + Try to fix teacher edit of activity changing 'statement.id' to 'statement.file' in 'add_edit_iassign()';
+ *   + Changed fix to activities order in 'show_iassign()', from "student view" to "teacher view"
  *
  * - v 4.9.6 2022/01/21
  *   + Try to fix view activity not sent through report ("view_iassign_current()": else if (!$student_answer) $loadTeacherActivity=true;)
@@ -133,12 +136,9 @@
 $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
 
 
-/**
- * Standard base class for all iAssign
- */
-
+/// Standard base class for all iAssign
+//  Basic class to iAssign block of activities
 class iassign {
-
   var $cm;
   var $course;
   var $iassign;
@@ -213,7 +213,7 @@ class iassign {
     $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
     $this->bottonPost = 0;
     $this->view_iassign = optional_param('action', false, PARAM_BOOL);
-    $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT)); // this is the activity inside iAssign block
+    $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT)); // this is the activity inside iAssign block (content file)
 
     $this->view();
     } // function __construct($iassign, $cm, $course)
@@ -364,6 +364,7 @@ class iassign {
 
 
   /// This method prints the teacher exercise
+  //  @calledby AJAX trhough "function action()" that calls "function auto_evaluate()"
   function get_teacher_exercise () {
     global $DB, $COURSE;
 
@@ -374,7 +375,12 @@ class iassign {
 
     //2021/12: $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
     //TODO 2022: trocar "$iassign_statement->id" por "$iassign_statement->file"???
-    $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->id);
+    // ./lib/filestorage/file_storage.php: public function get_area_files($contextid, $component, $filearea, $itemid = false,...)
+    $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->id); // use itemid=$iassign_statement->id
+    if (!$files) { // try with 'iassign_statement->filesid'
+      //D echo "locallib.php: get_teacher_exercise(): com iassign_statement->id=" . $iassign_statement->id . " resulta vazio! Tente com iassign_statement->filesid=" . $iassign_statement->filesid . "<br/>\n";
+      $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
+      }
 
     foreach ($files as $file) {
       if ($file->get_filename() != ".") {
@@ -641,11 +647,8 @@ class iassign {
     $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
 
     $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
-
     $atual_statement = $DB->get_record("iassign_statement", array("id" => $atual_submission->iassign_statementid));
-
-    $all_submissions = $DB->get_records('iassign_allsubmissions', 
-        array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
+    $all_submissions = $DB->get_records('iassign_allsubmissions', array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
 
     $user = $DB->get_record('user', array('id' => $atual_submission->userid));
 
@@ -726,7 +729,7 @@ class iassign {
         // Duplicate activity file
         $files_ids = $DB->get_records_sql('SELECT id FROM {files} WHERE component="mod_iassign" AND itemid=' . $filesid_from);
 
-        print 'Arquivos a serem copiados: ';
+        print("Files to be copied: "); //TODO: universalizar 'Arquivos a serem copiados: '
         print_r($files_ids);
         
         foreach ($files_ids as $fileid) {
@@ -833,7 +836,7 @@ class iassign {
     return $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
     }
 
-  function get_courses_enroled_as_teacher($userid) {
+  function get_courses_enroled_as_teacher ($userid) {
     $all_enroled = enrol_get_users_courses($userid);
     $return = array();
     foreach ($all_enroled as $enroled) {
@@ -935,9 +938,7 @@ class iassign {
 
     print '<div>';
     foreach ($exercises_list as $exercise) {
-
       $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
-
       $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
 
       print '
@@ -956,7 +957,6 @@ class iassign {
       print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
 
       foreach ($students_list as $student) {
-
         $total = 0;
         $student_submissions = [];
         foreach ($submissions_list as $submission) {
@@ -1081,7 +1081,6 @@ class iassign {
 
     // Get list of student id have submit for each exercise:
     foreach ($exercises_list as $exercise) {
-
       $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
 
       print '
@@ -1106,10 +1105,9 @@ class iassign {
         }
       print ']
         },'; // close "
-
       } // foreach ($exercises_list as $exercise)
 
-
+    // Start of JavaScript code to auto-evaluation
     print "        ];\n";
     print '
     var total_submissions = 0;
@@ -1241,7 +1239,6 @@ class iassign {
         }
       }
 
-
     // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
     function getStudentAnswerURL () {
       return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
@@ -1261,7 +1258,6 @@ class iassign {
       $(".progress-bar").css("width", temp + "%").text(temp + "%");
       if (temp >= 100) {
         $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
-
         $("#button_start").prop("disabled", false);
         $("#button_stop").prop("disabled", true);
         $("input:checkbox").attr("disabled", false);
@@ -1270,7 +1266,6 @@ class iassign {
         }
       }
 
-
     // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
     // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
     function postResultAutoEval (grade = null) {
@@ -1375,7 +1370,6 @@ class iassign {
         actual_student++;
         run_individual_evaluation();
       } else {
-
         actual_student = 0;
         // Does it go to next exercise or is it finished?
         if (actual_exercise < selected_exercises.length) {
@@ -1411,7 +1405,6 @@ class iassign {
         }
       }
 
-
     function stop_evaluation () {
       stoped = true;
       //AJAX
@@ -1420,34 +1413,26 @@ class iassign {
       $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
       $("input:checkbox").attr("disabled", false);
       $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
-  clearInterval(var_interval);
-  }
-var exercises = [ '; // '
+     clearInterval(var_interval);
+     }
+    var exercises = [ '; // '
 
     foreach ($exercises_list as $exercise) {
       print $exercise->id . ',';
       }
-
     print ' ];';
-
     print ' var students = [ ';
-
     foreach ($students_list as $student) {
       print $student->userid . ',';
       }
     print '];';
-
     print ' var ilms = [';
-
     foreach ($exercises_list as $exercise) {
       $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
       print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
       }
-
     print ']';
-
     print '</script>';
-
     print '
     <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
       <div class="modal-dialog modal-dialog-centered" role="document">
@@ -1477,9 +1462,9 @@ var exercises = [ '; // '
               </tr>
             </thead>
             <tbody>'; // "
+    // End of JavaScript code to auto-evaluation
 
     foreach ($students_list as $student) {
-
       $user = $DB->get_record('user', array('id' => $student->userid));
       $avatar = new user_picture($user);
       $avatar->courseid = $COURSE->id;
@@ -1562,64 +1547,87 @@ var exercises = [ '; // '
     } // function move_activity()
 
 
+// AQUI
+
   /// This method duplicates an iAssign activity
   function duplicate_activity () {
     global $USER, $CFG, $COURSE, $DB, $OUTPUT;
 
-    $id = $this->cm->id;
+    // Not used: $id = $this->cm->id; // Get {iassign}.id from {course_module}: {iassign_statement}.iassignid = {course_module}.id = $id
     $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
 
     $context = context_module::instance($this->cm->id);
 
-    $contextuser = context_user::instance($USER->id);
+    // Not used: $contextuser = context_user::instance($USER->id);
+echo "locallib.php: duplicate_activity()<br/>"; //R
+echo "cm.id=" . $id . ", iassignid=" . $iassignid . ", context.id=" . $contextuser->id . "<br/>"; //R  ", context.instanceid=" . $contextuser->instanceid
 
     // Get the the iAssign acitivity to be duplicated
     $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
+echo "{iassign_statement}: #iassign_statement=" . count($iassign_statement) . "<br/>"; //R
 
     // Remove the current id of activity
-    $id_source_copy = $iassign_statement->id;
-    $iassign_statement->id=0;
+    $original_iassign_statement_id = $iassign_statement->id;
+    $iassign_statement->id=0; // will receive the new {iassign_statement}.id - below "$updateentry->id = $id"
 
     // Include prefix (Copy of ...)
-    $iassign_statement->name = get_string('duplicate_iassign_prefix', 'iassign') . ' ' . $iassign_statement->name;
+    $iassign_statement->name = get_string('duplicate_iassign_prefix', 'iassign') . ' ' . $iassign_statement->name; // new name to {iassign_statement}.name
 
     // Get the information about current author, and add this information in author_modified field
-    $author = $DB->get_record("user", array('id' => $USER->id));
-    $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
+    $author = $DB->get_record("user", array('id' => $USER->id)); // id; auth; ... username; password; idnumber; firstname; lastname; email; ... description ...
+    $iassign_statement->author_modified_name = $author->firstname . ' ' . $author->lastname;
     $iassign_statement->author_modified = $iassign_statement->author_modified_name;
+echo "iassign_statement.id=" . $iassign_statement->id . ",iassign_statement.name =" . $iassign_statement->name . ", id_source_copy=" . $original_iassign_statement_id .
+", author.id=" . $author->id . ", author.firstname=" . $author->firstname . "<br/>";
 
     // Store the activity in the table
-    if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
+//R    if ($new_iassign_statement_id = $DB->insert_record("iassign_statement", $iassign_statement)) {
+if (1==1) { //R REMOVER!!!!
 
       // Duplicate activity file
       $fs = get_file_storage(); // Get reference to all files in Moodle data
       //2021/12 $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
-      $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $id_source_copy);
+      $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $original_iassign_statement_id);
+echo "{files}: #files=" . count($files) . "<br/>"; //R
+// {files}.get_id()
 
       foreach ($files as $value) {
         if ($value->get_filename() != ".") {
-          $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
+	  // Must have: {files}.itemid = {iassign_statement}.id ; {iassign_statement}.filesid = {files}.id
+
+	  // Get the last entry in {files} $last_id and use as new {files}.itemid = $last_id+1
+          //2021/12 $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
+echo "{files}: id=" . $value->id . "=" . $value->get_id() . ", filename=" . $value->filename . ", itemid=" . $value->itemid . ", contextid=" . $value->contextid . ", component=" . $value->component
+. ", filearea=" . $value->filearea . ", userid=" . $value->userid . "<br/>"; //R
+//print_r($value); echo "<br/>";
+//R echo "last_id = {files}.itemid = " . $last_id . "<br/>";
 
           //2021/12 $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
-          $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $value);
+/* //R
+          // ./lib/filestorage/file_storage.php: '$newfile' is protected
+          $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $new_iassign_statement_id), $value);
 
+          // Now update {iassign_statement}.filesid with '$newfile->id': {iassign_statement}.filesid = {files}.id
           $updateentry = new stdClass();
-          $updateentry->id = $id_;
+          $updateentry->id = $new_iassign_statement_id; // points {iassign_statement}.id to the new entry of {iassign_statement}
+
           //2021/12 $updateentry->filesid = $newfile->get_itemid();
-          $updateentry->filesid = $id_;
+          $updateentry->filesid = $newfile->get_id(); // points {iassign_statement}.filesid to the new {files}: {iassign_statement}.filesid = {files}.id
 
           // Update the duplicated iLM iAssign with new file id
           $DB->update_record("iassign_statement", $updateentry);
+*/
           }
         }
       }
 
     // log event --------------------------------------------------------------------------------------
-    iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
+//R    iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $new_iassign_statement_id, $this->cm->id);
 
-    $this->return_home_course('duplicated_activity');
+//R    $this->return_home_course('duplicated_activity');
     exit;
-    }
+    } // function duplicate_activity()
+
 
   // / This method gets the content from comment and register it
   function add_comment () {
@@ -2282,7 +2290,102 @@ var exercises = [ '; // '
 
     $this->action = 'viewsubmission';
     $this->view_iassign_current();
-    }
+    } // function edit_grade()
+
+
+//2022: ---------------------------------------------------------------------------------------------------------------------------------
+//2022: Recuperacao {files} {iassign_statement}
+//2022/02 see_all_files_context($context, $DB)
+
+  /// Temporary: fix 'iassign_statement.filesid' and 'files.itemid' (iassign_statement.filesid <- files.id; files.itemid <- iassign_statement.id)
+  //  First version of iAssign used a random value to associate 'files.itemid' with 'iassign_statement.file'
+  //  @calledby locallib.php ! get_update_files($context_id, $component, $filearea, $iassign_statement)
+  static function update_iassign_statement_files ($iassign_statement_id, $context_id, $component, $filearea, $files_ilmid) {
+    global $DB; //2022: echo "update_iassign_statement_files:<br/>";//D2022
+    // $files = $DB->get_records("files", array("component" => "mod_iassign", "filearea" => "exercise", "contextid" => $context_id, "itemid" => $files_ilmid)); // contextid=1390 ; itemid=400 ;
+    // $sql_query = "SELECT * FROM {files} WHERE component='mod_iassign' AND filearea='exercise' AND contextid=" . $context_id . " AND filename<>'.' AND itemid=" . $files_ilmid;
+    $sql_query = "SELECT * FROM {files} WHERE component='mod_iassign' AND filearea='exercise' AND contextid=" . $context_id . " AND itemid=" . $files_ilmid;
+//echo "sql_query=" . $sql_query . "<br/>";//D2022
+    $elem_in_files = $DB->get_records_sql($sql_query);
+    if (!$elem_in_files) {
+      print "Vazio! <br/>"; //TODO: se mantiver, internacionalizar!
+      return NULL;
+      }
+    // if (count($elem_in_files)>1) { echo "Problema! Mais de um arquivo!<br/>"; return NULL; }
+    //2022: echo "#files=" . count($elem_in_files) . ": "; // print_r($elem_in_files); echo "<br/>";//D2022
+    foreach ($elem_in_files as $element_file) { // since ID is greater than 0, only "$file1 = $elem_in_files[0]" will not work!
+      if ($element_file->filename != '.') { // If not '.' is the actual file
+        $file1 = $element_file;
+//2022: echo " - files: id=" . $file1->id . "; contextid=" . $file1->contextid . "; filearea=" . $file1->filearea . "; itemid=" . $file1->itemid . " <- " . $iassign_statement_id . "<br/>";
+        // this '$file1' has the 'hashcontent' of the real file content, then it will be used to update 'iassign_statement.filesid' <- 'files.id'
+        // break;
+        }
+      // Update 'files.itemid' with 'iassign_statement.id'
+      $newentry = new stdClass();
+      $newentry->id = $element_file->id; $newentry->itemid = $iassign_statement_id;
+//2022: echo " &nbsp; &nbsp; &nbsp; &nbsp; Update 'files.itemid': "; print_r($newentry); echo "<br/>";
+
+//2022: //leo voltar a atualizacao ou deixar para ADMIN via 'settings_activities.php'???????????????????????????????????????????????????????????????????????????
+//2022:      if (!$DB->update_record('files', $newentry)) print_error('error_update', 'iassign');
+
+      }
+    // Update 'iassign_statement.filesid' with 'files.id'
+    $newentry = new stdClass();
+    $newentry->id = $iassign_statement_id; $newentry->filesid = $file1->id;
+//2022: echo " &nbsp; &nbsp; &nbsp; &nbsp; Update 'iassign_statement.filesid': "; print_r($newentry); echo "<br/>";
+
+//2022: //leo voltar a atualizacao ou deixar para ADMIN via 'settings_activities.php'???????????????????????????????????????????????????????????????????????????
+//2022:    if (!$DB->update_record('iassign_statement', $newentry)) print_error('error_update', 'iassign');
+    } // static function update_iassign_statement_files($iassign_statement_id, $context_id, $component, $filearea, $files_ilmid)
+
+
+  /// Get file from table 'files', if 'files.itemid != iassign_statement.id' then update 'files.itemid' with 'iassign_statement.id'
+  //  Usually 'context.instanceid' is 'course_modules.id' and 'course_modules.instance = iassign.id'
+  //  However since iAssign is a "block of actual activities" from "iassign_statement", we store in 'files.itemid' the 'iassign_statement.id'
+  //  @calledby function add_edit_iassign(): if ($this->action == 'edit'): to edit iAssign activity
+  static function get_update_files ($context_id, $component, $filearea, $iassign_statement, $fs) {
+    // $fs is the reference to all files in Moodle data
+echo "<br/><br/><br/><br/><br/>get_update_files: iassign_statement: " . $context_id . ", " . $component . ", " . $filearea . ", " . 
+     "id=" . $iassign_statement->id . ", file=" . $iassign_statement->file . ", filesid=" . $iassign_statement->filesid .
+     ", iassign_ilmid =" . $iassign_statement->iassign_ilmid . ",name=" . $iassign_statement->name . "<br/>\n";//D2022
+    $msgAux = ""; $must_update_files_itemid = 0;
+    // To consider old versions with improper association 'files.itemid': try 'iassign_statement.id' (correct one), 'iassign_statement.file' and 'iassign_statement.filesid'
+    // Correct association: {files}->itemid = $iassign_statement->id and {files}->id=$iassign_statement->fileid;
+    $files = $fs->get_area_files($context_id, $component, $filearea, $iassign_statement->id); // try: 'iassign_statement.id'
+    if (!$files) { // Could not find with 'iassign_statement.id'
+      $msgAux .= "- Nao com 'iassign_statement.id'<br/>\n"; $must_update_files_itemid = 1;
+      $files = $fs->get_area_files($context_id, $component, $filearea, $iassign_statement->file); // try with 'iassign_statement.file'
+      if (!$files) { // Could not find with 'iassign_statement.file'
+        $msgAux .= "- Nao com 'iassign_statement.file'<br/>\n";
+        $files = $fs->get_area_files($context_id, $component, $filearea, $iassign_statement->filesid); // try with 'iassign_statement.filesid'
+        if (!$files) { // Could not find with 'iassign_statement.file'
+          //$files = $fs->get_area_files($context_id, $component, $filearea, $iassign_statement->filesid-1); // try with 'iassign_statement.filesid'-1
+          //if (!$files) { // Could not find with 'iassign_statement.file'
+          //  $msgAux .= "- Nao com 'iassign_statement.filesid'-1<br/>\n";
+            echo "ERRO completo: " . $msgAux;//D2022
+            return NULL;
+            // Desisto! $files = $fs->get_area_files($context_id, $component, $filearea, $iassign_statement->filesid); // try with 'iassign_statement.filesid'
+          //  }
+          //else { $must_update_files_itemid = $iassign_statement->filesid-1; echo "OK 4, nao com {'id,file,filesid'), mas pegou com 'iassign_statement.filesid'-1=" . $iassign_statement->filesid . "-1<br/>\n"; }
+          }
+        else { $must_update_files_itemid = $iassign_statement->filesid; echo "OK 3, nao com 'id', nem com 'file', mas pegou com 'iassign_statement.filesid'=" . $iassign_statement->filesid . "<br/>\n"; }
+        }
+      else { $must_update_files_itemid = $iassign_statement->file; echo "OK 2, nao com 'id', pegou com 'iassign_statement.file'=" . $iassign_statement->file . "<br/>\n"; }
+      }
+    else echo "OK 1, pegou com 'iassign_statement.id'=" . $iassign_statement->id . "<br/>\n";//D2022
+
+    if ($must_update_files_itemid!=0) {
+      $res_update = iassign::update_iassign_statement_files($iassign_statement->id, $context_id, $component, $filearea, $must_update_files_itemid);
+      }
+
+    foreach ($files as $file) { if ($file->get_filename() != '.') break; }
+    //$files_itemid = $file->get_itemid(); // /var/www/html/saw2021_1/lib/filestorage/stored_file.php: devolve 'files.itemid'
+    //$files_id = $file->get_id(); // file_record
+    echo "files[.]: id=" . $files_id . ", itemid=" . $files_itemid . "<br/>\n"; //D2022
+    return $file;
+    } // function get_update_files($context_id, $component, $filearea, $iassign_statement)
+//2022: Recuperacao {files} {iassign_statement}
+//2022: ---------------------------------------------------------------------------------------------------------------------------------
 
 
   /// Add or Edit interactive activities
@@ -2370,9 +2473,7 @@ var exercises = [ '; // '
       $param->show_answer = 1;
       } // if ($this->action == 'add')
     elseif ($this->action == 'edit') {
-
       $COURSE->iassign_list = array();
-
       $this_activity = $this->activity->get_activity();
 
       if ($this_activity != null) { // first enter here: fill form data
@@ -2465,19 +2566,77 @@ var exercises = [ '; // '
         $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
         $param->show_answer = $iassign_statement_current->show_answer;
 
+        // Association {iassign_statement} with {files}
+        // Attention to the {files}.contextid and {files}.itemid used: "{files}.itemid" must be "{iassign_statement}.id" (and {iassign_statement}.filesid={files}.id)
+        // Old version used: {iassign_statement}.files = {files}.itemid with a randam value...
+        // ./lib/filestorage/file_storage.php: public function get_area_files($contextid, $component, $filearea, $itemid = false,...)
         $fs = get_file_storage(); // Get reference to all files in Moodle data
 
-        //2021/12 $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
-        //2022/02 $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->id); // em alguns "_files.id" tem 'file' NAO 'id'
-        $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file); // It must have: {files}->id=$iassign_statement_current->file
-
-        if ($files) {
-          foreach ($files as $file) {
-            if ($file->get_filename() != '.') {
-              $param->filename = $file->get_filename();
-              $param->file = $file->get_id();
-              $param->fileold = $file->get_id();
-              $COURSE->iassign_file_id = $file->get_id();
+        //2021/12 $files_list = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
+        //2022/02 $files_list = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->id); // em alguns "_files.id" tem 'file' NAO 'id'
+
+        // It must have: {files}->id=$iassign_statement_current->file
+        //if ($iassign_statement_current->filesid) // new association {files}.itemid = {iassign_statement}.id       //TODO: depois deixar apenas este
+        //  $files_list = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->id); //TODO: depois deixar apenas este
+        //else
+        if ($iassign_statement_current->file) // old association {files}.itemid = {iassign_statement}.file
+          $files_list = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
+
+	// ------------------------------------------------------------------------------------------------------------------------------------
+        // Recover association {iassign_statement}/{files}
+	// It uses "files_functions.php ! update_iassignstatement_files(...)" to (eventually) reconstruct relation
+
+        //D echo "<br/><br/><br/><br/><br/><br/><br/><br/>locallib.php: add_edit_iassign(): #files_list=" . count($files_list) . "<br/>\n";
+        if (!$files_list) { // try with 'iassign_statement->filesid'
+          //D echo "locallib.php: add_edit_iassign(): com iassign_statement->id=" . $iassign_statement->id . " resulta vazio! Tente com iassign_statement->filesid=" . $iassign_statement->filesid . "<br/>\n";
+          //$files_list = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
+          $files_list = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_current->filesid);
+          if (!$files_list) { // try with 'iassign_statement->id'
+            //D echo "locallib.php: add_edit_iassign(): com iassign_statement->id=" . $iassign_statement->id . " resulta vazio! Tente com iassign_statement->id=" . $iassign_statement->id . "<br/>\n";
+            $files_list = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_current->id);
+            }
+          //$files_list = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
+          $files_list = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_current->filesid);
+          if ($files_list) {
+            // Redefine fields {iassign_statement}.filesid and {files}.itemid such as: {iassign_statement}.filesid={files}.id; {files}.itemid={iassign_statement}.id
+            $is_obj = $iassign_statement_current;
+            $count_fs = 0;
+            foreach ($files_list as $one_files) {
+              if ($count_fs==0) $f1_obj = $one_files; // $files_list[0]; // from {files}
+              else if ($count_fs==1) $f2_obj = $one_files; // $files_list[1]; // from {files}
+              $count_fs++;
+              }
+            //D_ echo " + #files_list = " . count($files_list) . "<br/>\n";
+            //D_ echo " + is_obj: " . $is_obj->name . ", id=" . $is_obj->id . ", files=" . $is_obj->files . ", filesid=" . $is_obj->filesid . ", iassignid=" . $is_obj->iassignid
+            //D_      . ", type_iassign=" . $is_obj->type_iassign . ", author_name=" . $is_obj->author_name . ", iassign_ilmid=" . $is_obj->iassign_ilmid
+            //D_      . ", automatic_evaluate=" . $is_obj->automatic_evaluate . ", show_answer=" . $is_obj->show_answer . ", filesid=" . $is_obj->filesid
+            //D_      . ", store_all_submissions=" . $is_obj->store_all_submissions . "<br/>\n";
+            //D_ echo " + f1_obj: filename = '" . $f1_obj->get_filename() . "', id=" . $f1_obj->get_id()
+            //D_      . "', contenthash=" . $f1_obj->get_contenthash() . "', contextid=" . $f1_obj->get_contextid() . "', filearea=" . $f1_obj->get_filearea()
+            //D_      . "', itemid=" . $f1_obj->get_itemid() . "', userid=" . $f1_obj->get_userid() . "', author=" . $f1_obj->get_author()
+            //D_      . "', timecreated=" . date("d/m/Y H:i:s", $f1_obj->get_timecreated()) . "<br/>\n";
+            //D_ echo " + f2_obj: filename = '" . $f2_obj->get_filename() . "', id=" . $f2_obj->get_id()
+            //D_      . "', contenthash=" . $f2_obj->get_contenthash() . "', contextid=" . $f2_obj->get_contextid() . "', filearea=" . $f2_obj->get_filearea()
+            //D_      . "', itemid=" . $f2_obj->get_itemid() . "', userid=" . $f2_obj->get_userid() . "', author=" . $f2_obj->get_author()
+            //D_      . "', timecreated=" . date("d/m/Y H:i:s", $f2_obj->get_timecreated()) . "<br/>\n";
+            require_once('files_functions.php'); // Get auxiliary functions to manage {iassign_statement}/{files}
+            $result = update_iassignstatement_files($DB, $is_obj->id, $f1_obj->get_id(), $is_obj, $f1_obj, $f2_obj); // ./files_functions.php
+            if (!$result) print "Could not change {iassign_statement}.filesid=" . $is_obj->id . " or {files}.itemid=" . $f1_obj->itemid . "<br/>";
+            }
+          } // if (!$files_list)
+
+        //D //echo "locallib.php: add_edit_iassign(): contextid=" . ($this->cm->id)->id . ", iassign_statement->id=" . $iassign_statement->id . ", iassign_statement->filesid=" . $iassign_statement->filesid . ", #files_list=" . count($files_list) . "<br/>\n";
+        //D echo "locallib.php: add_edit_iassign(): contextid=" . $context->id . ", iassign_statement_current->id=" . $iassign_statement_current->id . ", iassign_statement_current->filesid=" . $iassign_statement_current->filesid . ", #files_list=" . count($files_list) . "<br/>\n";
+
+        // $files_list = iassign::get_update_files($context->id, $component, $filearea, $iassign_statement_current, $fs); //2022: tentativa de recupearar arquivos se perdido
+        if ($files_list) { // get the first {files} with real "filename"
+          foreach ($files_list as $file_item) {
+            if ($file_item->get_filename() != '.') {
+              $param->filename = $file_item->get_filename();
+              $param->file = $file_item->get_id();
+              $param->fileold = $file_item->get_id();
+              $COURSE->iassign_file_id = $file_item->get_id();
+              break; // stop at the first with a "real" filename
               }
             }
           }
@@ -2639,7 +2798,7 @@ var exercises = [ '; // '
         } // foreach ($inter_dependency as $tmp)
       } // if ($iassign_statement)
     return $dependency;
-    }
+    } // function search_sub_dependency($search_iassing_id)
 
 
   // Warning message
@@ -2776,7 +2935,7 @@ var exercises = [ '; // '
       \core\notification::error(get_string('activity_not_found', 'iassign'));
       print $OUTPUT->footer();
       exit;
-    }
+      }
 
     $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
 
@@ -3051,24 +3210,18 @@ var exercises = [ '; // '
       print activity::toggle_columns_script();
 
       if ($iassign_submission && $allow_resubmission) {
-
         // Put the iLM to
         print $OUTPUT->box_start();
-
         print '<p><strong>' . $last_iassign . '</strong></p>';
-        //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
+        //d if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
         $enderecoPOST = "";
-
         // Prepare tags to present the iLM
         print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
-
         //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
 
         print $OUTPUT->box_end();
-
         } // if ($iassign_submission && $allow_resubmission)
       else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
-
 	// If '$student_answer' is empty, then the student does not submit any solution to the exercice
         // ATTENTION: exception used by iGeom (exercise with "script")
         $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
@@ -3087,7 +3240,6 @@ var exercises = [ '; // '
         print activity::toggle_columns_script();
         // Prepare tags to present the iLM
         print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
-
         }
 
       //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
@@ -3187,10 +3339,9 @@ var exercises = [ '; // '
 
       $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
 
-      $this->activity->view_dates();
+      $this->activity->view_dates(); // prints "Type of activity:", "Available from:"
 
       if ($this->view_iassign) { // Box 5 to 'proposition' - open
-
         print $OUTPUT->box_start();
 
         print '<table width=100% border=0 valign="top">' . "\n";
@@ -3321,7 +3472,6 @@ var exercises = [ '; // '
           print '</tr></table>' . "\n";
 
           // Presents the iLM
-         
           print '<table width=100% border=0 valign="top">' . "\n";
           print '<td width=80% align="left">';
           print '<strong>' . $last_iassign . ' ' . get_string('repeat_msg', 'iassign') . '</strong></td>' . "\n"; // If you want to do this activity from the beginning again, use the \"Redo button\".
@@ -3336,15 +3486,7 @@ var exercises = [ '; // '
           print '<p class="mt-5"><strong>' . get_string('proposition', 'iassign') . '</strong></p>' . "\n";
           print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
 
-          $output = '';
-
-          if (!$iassign_ilm) {
-            $iassign_ilm = new stdClass();
-            $iassign_ilm->file_jar = "";
-            }
-
-          $output .= $OUTPUT->box_start();
-
+          $output = $OUTPUT->box_start();
           $USER->iassignEdit = $this->bottonPost;
 
           // ---
@@ -3369,7 +3511,7 @@ var exercises = [ '; // '
             $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
             }
 
-           //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
+          //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
           //1 if ($iassign_statement_activity_item->type_iassign == 3) {
           //1   $history_comment = '';
           //1   if ($iassign_submission) {
@@ -3385,14 +3527,11 @@ var exercises = [ '; // '
           //1   $only_one_send_button = 1; // avoid put comment frame again (bellow)
           //1   }
 
-
           $output .= $OUTPUT->box_end();
           print $output;
           } // if ($this->view_iassign)
 
-
         print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
-
         } // if ($this->view_iassign)
 
       } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
@@ -3433,7 +3572,6 @@ var exercises = [ '; // '
 
       $output .= $OUTPUT->box_start();
 
-
       //if (!empty($history_comment)) {
         $output .= "<a id='comments'></a>";
         $output .= "  <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
@@ -5384,7 +5522,7 @@ class activity {
   /// Constructor of class.
   //  @param int $id Id of activity
   //  3.1 update PHP 7.0 compatibility for all moodle versions
-  //D public function activity($id) { self::__construct($id); }
+  //  public function activity($id) { self::__construct($id); }
 
   function __construct ($id) {
     global $DB;
@@ -5433,14 +5571,14 @@ class activity {
 
     $bottonDelete_yes = get_string('delete_iassign', 'iassign');
     $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
-    $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>\n";
-    $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
+    $output .= "<form name='formDelete' id='formDelete' method='post' action='" . $deleteiassignyes . "' enctype='multipart/form-data'>\n";
+    $output .= " <input type=submit value='" . $bottonDelete_yes . "'/>\n";
     $output .= "</form>\n";
     $output .= '</td><td>';
     $bottonDelete_no = get_string('delete_cancel', 'iassign');
     $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
-    $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
-    $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
+    $output .= "<form name='formDelete' id='formDelete' method='post' action='" . $deleteiassignno . "' enctype='multipart/form-data'>\n";
+    $output .= " <p><input type=submit value='" . $bottonDelete_no . "'/></p>\n";
     $output .= "</form>\n";
     $output .= '</td></tr></table>' . "\n";
     $output .= $OUTPUT->box_end();
@@ -5554,7 +5692,7 @@ class activity {
     }
 
 
-  /// Add news interactive activities (register in table 'iassign_statement')
+  /// Add new interactive activities (register in table 'iassign_statement')
   //  @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
   //  @see      ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
   function new_iassign ($param) {
@@ -5618,8 +5756,8 @@ class activity {
 
       $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
 
-      // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
-      //$itemid = $id;
+      // ATTENTION: {files}.itemid must be equal to {iassign_statement}.id
+      // $itemid = $id;
 
       // File already inserted in other context!
       //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
@@ -5734,7 +5872,7 @@ class activity {
     if ($events) {
       foreach ($events as $value) {
         if ($value->description == $iassign_statement_activity_item->name) {
-            $DB->delete_records('event', array('id' => $value->id));
+          $DB->delete_records('event', array('id' => $value->id));
           }
         }
       }
@@ -5752,7 +5890,6 @@ class activity {
     $fileold = $fs->get_file_by_id($param->fileold);
 
     if ($param->file != $param->fileold) {
-
       if ($fileold) {
         $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
         foreach ($fileoldarea as $value) {
@@ -5785,14 +5922,10 @@ class activity {
     else
       $proposition_text = $proposition;
     $newentry->proposition = $proposition_text;
-
     $newentry->iassign_ilmid = $param->iassign_ilmid;
-
     $newentry->filesid = $param->file;    // came from a file from 'get_file_storage()' (it is its ID)
-
     $newentry->grade = $param->grade;
     $newentry->author_modified_name = $param->author_modified_name;
-
     $newentry->timemodified = time();
     if ($param->type_iassign == 1) {
       $newentry->timedue = 0;
@@ -6135,9 +6268,13 @@ class ilm_settings {
 
 
   /// Function for get form variables for add, edit, or copy iLM
-  //  @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
+  //  This function is called to fill in the iLM data to the form
+  //  The function 'edit_ilm(.)' bellow is responsible to process edited data
+  //  @calledby settings_ilm.php: On the first call $ilm_id is defined: the calling is necessary to fill in data to the form
+  //  @calledby settings_ilm.php: On the second call $ilm_id empty (however must be used)
   //  @see      settings_form.php
   //  @see      locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
+  //  @see      locallib.php : static function edit_ilm ($param,$itemid): perform the data register (files and database) in edition process
   //  @param int $ilm_id Id of iLM
   //  @param string $action String with the action
   //  @return object Return an object with forms variables
@@ -6149,7 +6286,7 @@ class ilm_settings {
     $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
 
     $param = new stdClass();
-    //D echo "locallib.php: add_edit_copy_ilm: ilm_id,=$ilm_id, action="; print_r($action); echo "<br/>---------------------------------<br/>";
+
     $param->action = $action;
     $param->ilm_id = $ilm_id;
     $CFG->action_ilm = $action;
@@ -6171,11 +6308,15 @@ class ilm_settings {
       $param->enable = 0; // 0 - hide / 1 - show
       $param->timecreated = time();
       $param->timemodified = time();
-      $param->evaluate = 0;
+      $param->evaluate = 0; // evaluate = 1 => iLM has auto-evaluation method
+      $param->reevaluate = 0; // reevaluate = 1 => allows to the teacher calls method to re-evaluate (does it in batch, to all students)
+      $param->editingbehavior = 0; // editingbehavior = 1 => iLM auto-evaluation remains working over a solution sent by the student (iGeom does not work, iVProg does)
+      $param->submissionbehavior = 0; // 0 => 'After submission, this iLM remains on the same page'; 1 => 'After submission, this iLM changes the current page'
       $param->parent = 0;
       }
     elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
       if ($iassign_ilm) {
+        //D echo "* entrou no iassign_ilm="; print_r($iassign_ilm); echo "<br/>\n"; //exit;
         $description = json_decode($iassign_ilm->description);
 
         $param->title = get_string('edit_ilm', 'iassign');
@@ -6214,10 +6355,13 @@ class ilm_settings {
         $param->enable = $iassign_ilm->enable;
         $param->timecreated = $iassign_ilm->timecreated;
         $param->timemodified = time();
-        $param->evaluate = $iassign_ilm->evaluate;
+        $param->evaluate = $iassign_ilm->evaluate; // evaluate = 1 => iLM has auto-evaluation method
+        $param->reevaluate = $iassign_ilm->reevaluate; // reevaluate = 1 => allows to the teacher calls method to re-evaluate (does it in batch, to all students)
+        $param->editingbehavior = $iassign_ilm->editingbehavior; // editingbehavior = 1 => iLM auto-evaluation remains working over a solution sent by the student (iGeom does not work, iVProg does)
+        $param->submissionbehavior = $iassign_ilm->submissionbehavior; // 0 => 'After submission, this iLM remains on the same page'; 1 => 'After submission, this iLM changes the current page'
         $param->parent = $iassign_ilm->parent;
-        }
-      }
+        } // if ($iassign_ilm)
+      } // elseif ($action == 'edit')
     elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
       // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
       // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
@@ -6255,9 +6399,12 @@ class ilm_settings {
         $param->timecreated = time();
         $param->timemodified = time();
         $param->evaluate = $iassign_ilm->evaluate;
+        $param->reevaluate = $iassign_ilm->reevaluate; // reevaluate = 1 => allows to the teacher calls method to re-evaluate (does it in batch, to all students)
+        $param->editingbehavior = $iassign_ilm->editingbehavior; // editingbehavior = 1 => iLM auto-evaluation remains working over a solution sent by the student (iGeom does not work, iVProg does)
+        $param->submissionbehavior = $iassign_ilm->submissionbehavior; // 0 => 'After submission, this iLM remains on the same page'; 1 => 'After submission, this iLM changes the current page'
         $param->parent = $iassign_ilm->parent;
-        }
-      }
+        } // if ($iassign_ilm)
+      } // elseif ($action == 'new_version')
     elseif ($action == 'copy') {
       $description = json_decode($iassign_ilm->description);
       if ($iassign_ilm) {
@@ -6284,13 +6431,18 @@ class ilm_settings {
         $param->timecreated = time();
         $param->timemodified = time();
         $param->evaluate = $iassign_ilm->evaluate;
+        $param->reevaluate = $iassign_ilm->reevaluate; // reevaluate = 1 => allows to the teacher calls method to re-evaluate (does it in batch, to all students)
+        $param->editingbehavior = $iassign_ilm->editingbehavior; // editingbehavior = 1 => iLM auto-evaluation remains working over a solution sent by the student (iGeom does not work, iVProg does)
+        $param->submissionbehavior = $iassign_ilm->submissionbehavior; // 0 => 'After submission, this iLM remains on the same page'; 1 => 'After submission, this iLM changes the current page'
         $param->parent = $iassign_ilm->parent;
-        }
-      }
+        } // if ($iassign_ilm)
+      } // elseif ($action == 'copy'
 
+   //D debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
    //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
    //D var_dump(debug_backtrace());
-   //D print_r(debug_backtrace());
+   //D print_r(debug_backtrace()); echo "param="; print_r($param); echo "<br/>\n";
+   //D echo "<br/>---------------------------------<br/>"; exit;
 
     return $param;
     } // static function add_edit_copy_ilm($ilm_id, $action)
@@ -6466,11 +6618,16 @@ class ilm_settings {
 
 
   /// Function for save in database an iLM edit
+  //  The above function 'add_edit_copy_ilm(.)' is responsible to provide the iLM data in this form
+  //  The data stored through 'ilm_handlers/html5.php' (or 'java.php')
   //  @param object $param An object with iLM params
+  //  @calledby settings_ilm.php: ilm_settings::edit_ilm($formdata, $formdata->file);
   static function edit_ilm ($param, $itemid) {
     // Descobrir o tipo de iLM:
     global $DB, $USER, $CFG;
 
+    //D debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); //exit;
+
     $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
 
     $pathtemp = $CFG->dataroot . '/temp/';
@@ -8122,7 +8279,6 @@ class ilm_manager {
                  'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
 
               $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
-
               }
             }
           } // if ($files)
@@ -8805,6 +8961,12 @@ class iassign_icons {
     return $string;
     }
 
+  static function insertIT ($icon, $title, $text_alt) {
+    global $CFG;
+    $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($title, 'iassign') . '" alt="' . get_string($text_alt, 'iassign') . '"/>'; // "\n"
+    return $string;
+    }
+
   }
 
 

+ 101 - 67
settings.php

@@ -6,6 +6,10 @@
  * It provides a link to the iAssign general configurations area ('pluginname').
  * 
  * Release Notes:
+ * - v 2.0.1 2022/09/15
+ *   + Considering table 'iassign_ilm': messages to fields 'evaluate', 'reevaluate', 'editingbehavior'; fixes to allow the edition of 'reevaluate', 'editingbehavior'
+ * - v 2.0.0 2022/02/22
+ *   + New option to see all activities of a given iLM (./mod/iassign/settings_activities.php?action=activities&ilm_id=38)
  * - v 1.9.3 2020/08/03
  *   + Debug security added into "else if ($action == 'config')": if (!isset($ilm) || !$ilm) return;* - v 1.9.2 2020/02/15
  *   + Fixed 2 problems inside 'if ($ilm_parent)': 1. Error: '+' -> '.'; 2. Changed 'if (is_object($ilm_parent)) if (is_object($ilm_parent->description))'
@@ -28,12 +32,15 @@
  *   + Now view separate only iLMs for filter versions.
  * 
  * @author Patricia Alves Rodrigues
- * @author Leônidas O. Brandão
+ * @author Leo^nidas de Oliveira Branda~o
  * @version v 1.9.1 2017/12/02
  * @package mod_iassign_settings
  * @since 2010/09/27
  * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
  * 
+ * @calledby ./admin/search.php: every time enter 'search' Moodle class all plugin installed through its 'settings.php'
+ * @calledby ./admin/search.php: when choose iAssign setting enter here again
+ * 
  * <b>License</b> 
  *  - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
@@ -45,6 +52,14 @@ global $OUTPUT, $CFG, $DB;
 require_once($CFG->dirroot . '/mod/iassign/lib.php');
 require_once($CFG->dirroot . '/mod/iassign/locallib.php');
 
+if (!is_siteadmin()) { // ./lib/accesslib.php
+  print "Access denied!<br/>";
+  exit();
+  }
+
+//$context = context_module::instance($USER->cm); // usado no: ilm_handlers/html5.php
+//USER.{context}.id=" . $context->id
+
 $action = optional_param('action', 'view', PARAM_TEXT);
 $ilm_id = optional_param('ilm_id', 0, PARAM_INT);
 $ilm_param_id = optional_param('ilm_param_id', 0, PARAM_INT);
@@ -88,54 +103,67 @@ if (!file_exists($CFG->dirroot . '/lib/editor/tinymce/plugins/iassign/version.ph
   $str .= $OUTPUT->box_end();
   }
 
-if ($action == 'view') {
+if ($action == 'view') { // in Admin interface after "click" over "Activities modules" of iAssign, reaches this point
   $url_add = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'add'));
   $action_add = new popup_action('click', $url_add, 'popup', array('width' => 900, 'height' => 650));
   $link_add = $OUTPUT->action_link($url_add, get_string('add_ilm_iassign', 'iassign'), $action_add) . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
 
+  //2022/02
+  $url_activities = new moodle_url('/mod/iassign/settings_activities.php', array('action' => 'activities')); // examine the data base of all iLM activities
+  $action_activities = new popup_action('click', $url_activities, 'popup', array('width' => 900, 'height' => 650));
+  $link_see_activities = $OUTPUT->action_link($url_activities, get_string('settings_see_activities', 'iassign'), $action_activities) . $OUTPUT->help_icon('settings_see_activities', 'iassign');
+  //$link_see_activities = "";
+
   $url_import = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'import'));
   $action_import = new popup_action('click', $url_import, 'popup', array('width' => 900, 'height' => 650));
   $link_import = $OUTPUT->action_link($url_import, get_string('import_ilm', 'iassign'), $action_import) . $OUTPUT->help_icon('import_ilm', 'iassign');
 
-  // First list all iLM from type HTML
+  // First list all iLM from type HTML, then the "applets"
   // $iassign_ilms = $DB->get_records('iassign_ilm', array('parent' => 0)); // id, version, parent, name
-  $iassign_ilms = $DB->get_records_sql("SELECT id, description, name, parent, url, version FROM {iassign_ilm} WHERE parent = 0 ORDER BY type");
+  // {iassign_ilm} : id name version type description url extension parent file_jar file_class width height enable timemodified author timecreated evaluate reevaluate editingbehavior submissionbehavior action_buttons
+  $iassign_ilms = $DB->get_records_sql("SELECT id,type,description,name,parent,url,version,extension,evaluate,reevaluate,editingbehavior,submissionbehavior FROM {iassign_ilm} WHERE parent=0 ORDER BY type");
 
   $str .= '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . chr(13);
-  $str .= '<tr><td colspan=2 align=left>' . $link_add . '</td>';
-  $str .= '<td colspan=2 align=right>' . $link_import . '</td></tr>';
+  $str .= '<tr><td colspan=2 align=left>' . $link_add . "</td>\n";
+  $str .= "<td align=right></td>\n"; //2022/02
+  $str .= '<td colspan=2 align=right>' . $link_import . "</td>\n";
+  $str .= "</tr>\n";
 
   if ($iassign_ilms) {
-
     foreach ($iassign_ilms as $ilm) {
+      //D echo " - iLM: id=" . $ilm->id . "; name=" . $ilm->name . "; extension=" . $ilm->extension . "<br/>\n";
+
+      // ./mod/iassign/icon/icon_see_activities.gif
+      $url_activities = new moodle_url('/mod/iassign/settings_activities.php', array('action' => 'activities', 'ilm_id' => $ilm->id)); // examine the data base of all iLM activities
+      $link_activities = $OUTPUT->action_link($url_activities, iassign_icons::insertIT('icon_see_activities','see_ilm_activities','see_ilm_activities')); // locallib.php: class 'iassign_icons'
+
       $url_config = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm->id));
-      $link_config = $OUTPUT->action_link($url_config, iassign_icons::insert('config_ilm'));
+      $link_config = $OUTPUT->action_link($url_config, iassign_icons::insertIT('gear_bw_small','config_ilm','config_ilm')); // put the "gear" icon (at right): config_ilm = "Manager the configuration of iLM"
 
       $ilm_count = 1;
-      $ilm_version = 0;
-      //R $iassign_ilm_list = $DB->get_records('iassign_ilm', array('parent' => $ilm->id)); //*******************************************
+      $ilm_version = 0; //R $iassign_ilm_list = $DB->get_records('iassign_ilm', array('parent' => $ilm->id)); //_ other sintax to get iLM
       $iassign_ilm_list = $DB->get_records_sql("SELECT id, version FROM {iassign_ilm} WHERE parent = " . $ilm->id );
 
       if ($iassign_ilm_list) {
         foreach ($iassign_ilm_list as $ilm_parent) {
           $ilm_count++;
-          if (floatval(preg_replace('/[^0-9]+/', '', $ilm_parent->version)) > $ilm_version)
-            $ilm_version = floatval(preg_replace('/[^0-9]+/', '', $ilm_parent->version));
+          if (floatval(preg_replace('/[^0-9]+/', '', $ilm_parent->version)) > $ilm_version) $ilm_version = floatval(preg_replace('/[^0-9]+/', '', $ilm_parent->version));
           }
         }
 
       $str_sql = "SELECT COUNT(id) FROM {iassign_statement} WHERE iassign_ilmid =" . $ilm->id;
-      $iassign_count = $DB->count_records_sql($str_sql, null);
+      $iassign_count = $DB->count_records_sql($str_sql, null); // get the total of activities with this iLM
 
-      //R $iassign_ilm_parent = $DB->get_records('iassign_ilm', array('parent' => $ilm->id)); //*******************************************
+      // Count the number of iLM derived from '$ilm'
+      //R $iassign_ilm_parent = $DB->get_records('iassign_ilm', array('parent' => $ilm->id)); //_ other sintax to get iLM
       $iassign_ilm_parent = $DB->get_records_sql("SELECT id FROM {iassign_ilm} WHERE parent = " . $ilm->id);
       foreach ($iassign_ilm_parent as $ilm_parent) {
-        //R $iassign_statement = $DB->get_records('iassign_statement', array('iassign_ilmid' => $ilm_parent->id)); //*******************************************
-        //R if ($iassign_statement) { // $iassign_count += count($iassign_statement);
-          $str_sql_parents = "SELECT COUNT(id) FROM {iassign_statement} WHERE iassign_ilmid =" . $ilm_parent->id;
-          $iassign_count += $DB->count_records_sql($str_sql_parents, null);
-        //R   }
+        //R $iassign_statement = $DB->get_records('iassign_statement', array('iassign_ilmid' => $ilm_parent->id)); //_ other sintax to get iLM
+        //R if ($iassign_statement) { $iassign_count += count($iassign_statement); }
+        $str_sql_parents = "SELECT COUNT(id) FROM {iassign_statement} WHERE iassign_ilmid =" . $ilm_parent->id;
+        $iassign_count += $DB->count_records_sql($str_sql_parents, null);
         }
+      //D echo " &nbsp; &nbsp; #atividade derivadas do iLM id=" . $ilm->id . " : " . $iassign_count . "<br/>\n"; 
 
       $link_upgrade = "";
       $upgrade_file = $ilm->url . 'ilm-upgrade_' . strtolower($ilm->name) . '.xml';
@@ -158,26 +186,32 @@ if ($action == 'view') {
       else
         $str_description = $description_obj;
 
+      $str_info = 'type=' . $ilm->type . ', evaluate=' . $ilm->evaluate . ', reevaluate=' . $ilm->reevaluate . ', editingbehavior=' . $ilm->editingbehavior . ', submissionbehavior=' . $ilm->submissionbehavior;
       $str .= '<tr>';
-      $str .= '<td class="header c1" width=75% title="fields: name, description"><strong>' . $ilm->name . ' (' . $ilm->version . ')<br/>' .
-          $str_description . '</strong></td>' . chr(13);
+      $str .= '<td class="header c1" width=70% title="fields: name, description"><strong title="' . $str_info . '">' . $ilm->name . ' (' . $ilm->version . ')<br/>' .
+        $str_description . '</strong></td>' . chr(13);
 
       $str .= '<td class="header c1" width=10% ><strong>' . get_string('versions_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm_count . '</td>' . chr(13);
       $str .= '<td class="header c1" width=10% ><strong>' . get_string('activities', 'iassign') . ':</strong>&nbsp;' . $iassign_count . '</td>' . chr(13);
-      $str .= '<td class="header c1" width=5% align=center valign=bottom>' . $link_upgrade . '&nbsp;&nbsp;' . $link_config . '</td>' . chr(13);
-      $str .= '</tr>';
+
+      //$str .= '<td class="header c1" width=5% ><strong>' . get_string('see_activities', 'iassign') . ':</strong>&nbsp;' . $link_see_activities . '</td>' . chr(13);
+      $str .= '<td class="header c1" width=5% align="center">' . $link_activities . '</td>' . chr(13);
+      //$str .= "<td></td>\n"; //$link_see_activities = ""; //2022/02
+
+      $str .= '<td class="header c1" width=5% align="center">' . $link_upgrade . '&nbsp;&nbsp;' . $link_config . '</td>' . chr(13); //  valign=bottom
+      $str .= '</tr>' . chr(13);
       } // foreach ($iassign_ilms as $ilm)
     } // if ($iassign_ilms)
-  $str .= '</table>';
+  $str .= '</table>' . chr(13);
 
+  // Print the iLM table
   $settings->add(new admin_setting_heading('iassign', get_string('config_ilm', 'iassign') . $OUTPUT->help_icon('modulename', 'iassign'), $str));
+
   } // if ($action == 'view')
 else if ($action == 'confirm_upgrade') {
-
   $ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
 
   $upgrade_file = $ilm->url . 'ilm-upgrade_' . strtolower($ilm->name) . '.xml';
-
   $upgrade_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
 
   $lang = current_language();
@@ -187,10 +221,8 @@ else if ($action == 'confirm_upgrade') {
   else
     $description = $upgrade_xml->description->en;
 
-
   $str .= '<table id="outlinetable" class="generaltable boxaligncenter" width="100%">' . chr(13);
   $str .= '<tr><td>' . $description;
-
   $str .= '</td></tr></table>';
 
   $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'view'));
@@ -204,15 +236,13 @@ else if ($action == 'confirm_upgrade') {
   $url_no = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'view'));
   $link_no = $OUTPUT->action_link($url_no, "<b>" . get_string('no', 'iassign') . "</b>");
 
-
   $str .= $link_no . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $link_yes . "</center>";
 
-
   $settings->add(new admin_setting_heading('iassign', get_string('upgrade_ilm_title', 'iassign'), $str));
   } // else if ($action == 'confirm_upgrade')
 
-else if ($action == 'config') { // Administration > plugins > iAssign : after select the iLM reaches this point
-  //D echo "settings.php: action==config<br/>";
+else if ($action == 'config') { // Administration > plugins > iAssign : after "click" over the "gear" icon (at right of the iLM line) reaches this point
+  //D echo "<br/><br/><br/><br/><br/><br/>settings.php: action==config: ilm_id=" . $ilm_id . "<br/>";
 
   $url_return = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign'));
   $link_return = $OUTPUT->action_link($url_return, get_string('return', 'iassign'));
@@ -222,18 +252,22 @@ else if ($action == 'config') { // Administration > plugins > iAssign : after se
   $link_new_version = $OUTPUT->action_link($url_new_version, get_string('new_version_ilm', 'iassign'), $action_new_version);
 
   $str .= '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . chr(13);
-  $str .= '<tr><td colspan=2 align=left>' . $link_return . '</td><td colspan=1 align=right>' . $link_new_version . '</td></tr>';
+  $str .= '<tr><td colspan=2 align=left>' . $link_return . '</td><td colspan=1 align=right>' . $link_new_version . '</td></tr>' . chr(13);
 
   $ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
 
   if (!isset($ilm) || !$ilm) return; // debug security...
 
-  $iassign_ilm_parent = $DB->get_records_sql(
-    'SELECT s.* FROM {iassign_ilm} s WHERE s.parent = :parent ORDER BY s.version DESC', array('parent' => $ilm->id));
+  // $sql_query = 'SELECT s.* FROM {iassign_ilm} s WHERE s.parent = :parent ORDER BY s.version DESC'; // must find ":parent" is $ilm->id
+  $sql_query = 'SELECT s.* FROM {iassign_ilm} s WHERE s.parent = '. $ilm->id . ' ORDER BY s.version DESC'; // more efficient, one string replacement less
+  $iassign_ilm_parent = $DB->get_records_sql($sql_query, array('parent' => $ilm->id));
   array_unshift($iassign_ilm_parent, $ilm);
 
   if ($iassign_ilm_parent) {
+    //D echo "<br/><br/>iassign_ilm_parent: " . $sql_query . "<br/>"; $conta = 0; //hoje
+
     foreach ($iassign_ilm_parent as $ilm_parent) {
+      //D echo $conta . ": ilm_parent="; print_r($ilm_parent); echo "<br/>\n"; $conta++; //hoje
 
       $url_default = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'confirm_default_ilm', 'ilm_id' => $ilm_parent->id, 'ilm_parent' => $ilm->id));
       if (count($iassign_ilm_parent) == 1)
@@ -287,8 +321,7 @@ else if ($action == 'config') { // Administration > plugins > iAssign : after se
         }
       else
         $link_delete = iassign_icons::insert('delete_ilm_disable');
-      
-      
+
       if (strtolower($ilm_parent->type) == 'html5') {
         $url_delete = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'confirm_delete_ilm', 'ilm_id' => $ilm_parent->id, 'ilm_parent' => $ilm->id));
         $link_delete = $OUTPUT->action_link($url_delete, iassign_icons::insert('delete_ilm'));
@@ -340,7 +373,7 @@ else if ($action == 'config') { // Administration > plugins > iAssign : after se
           $str_description = $description_obj;
         }
       $str .= '<td width="50%"><strong>' . get_string('description', 'iassign') . ':</strong>&nbsp;' .
-              $str_description . '</td>'; // iassign_language::get_description_lang($current_language, $ilm_parent->description)
+              $str_description . '</td>' . chr(13); // iassign_language::get_description_lang($current_language, $ilm_parent->description)
 
       $str .= '<td width="50%"><strong>' . get_string('activities', 'iassign') . ':</strong>&nbsp;' . $total . '</td>' . chr(13);
       $str .= '</tr>' . chr(13);
@@ -348,9 +381,9 @@ else if ($action == 'config') { // Administration > plugins > iAssign : after se
       $langs_str = iassign_language::get_all_lang($ilm_parent->description);
       $str .= '<tr>';
       if ($langs_str != "")
-        $str .= '<td><strong>' . get_string('language_label', 'iassign') . ':</strong>&nbsp;' . $langs_str . '</td>';
-      $str .= '<td><strong>' . get_string('type_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->type . '</td>';
-      $str .= '</tr>';
+        $str .= '<td><strong>' . get_string('language_label', 'iassign') . ':</strong>&nbsp;' . $langs_str . '</td>' . chr(13);
+      $str .= '<td><strong>' . get_string('type_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->type . '</td>' . chr(13);
+      $str .= '</tr>' . chr(13);
 
       
       if (strtolower($ilm_parent->type) == 'java') {
@@ -363,31 +396,32 @@ else if ($action == 'config') { // Administration > plugins > iAssign : after se
         $enable = get_string('yes', 'iassign');
       else
         $enable = get_string('no', 'iassign');
-      $str .= '<td width="50%"><strong>' . get_string('enable', 'iassign') . ':</strong>&nbsp;' . $enable . '</td></tr>';
+      $str .= '<td width="50%"><strong>' . get_string('enable', 'iassign') . ':</strong>&nbsp;' . $enable . '</td></tr>' . chr(13);
 
-      $str .= '<tr><td width="50%" title="field: file_jar"><strong>' . get_string('file_jar', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->file_jar . '</td>';
-      $str .= '<td width="50%" title="field: file_class"><strong>' . get_string('file_class', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->file_class . '</td></tr>';
+      $str .= '<tr><td width="50%" title="field: file_jar"><strong>' . get_string('file_jar', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->file_jar . '</td>' . chr(13);
+      $str .= '<td width="50%" title="field: file_class"><strong>' . get_string('file_class', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->file_class . '</td></tr>' . chr(13);
 
-      $str .= '<tr><td width="50%" title="field: extension"><strong>' . get_string('extension', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->extension . '</td>';
+      $str .= '<tr><td width="50%" title="field: extension"><strong>' . get_string('extension', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->extension . '</td>' . chr(13);
       $str .= '<td width="50%" title="field: width"><strong>' . get_string('width', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->width;
-      $str .= '&nbsp;&nbsp;<strong>' . get_string('height', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->height . '</td></tr>';
+      $str .= '&nbsp;&nbsp;<strong>' . get_string('height', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->height . '</td></tr>' . chr(13);
 
+      // Field 'iassign_ilm.evaluate'
       if ($ilm_parent->evaluate == 1)
-        $evaluate = get_string('yes', 'iassign');
+        $opt_evaluate = get_string('yes', 'iassign');
       else
-        $evaluate = get_string('no', 'iassign');
-
-      $str .= '<tr><td width="50%" title="field: evaluate"><strong>' . get_string('evaluate', 'iassign') . ':</strong>&nbsp;' . $evaluate . '</td>';
-
+        $opt_evaluate = get_string('no', 'iassign');
+      $str .= '<tr><td width="50%" title="field: evaluate"><strong>' . get_string('evaluate', 'iassign') . ':</strong>&nbsp;' . $opt_evaluate . '</td>' . chr(13);
       if ($ilm_parent->reevaluate == 1)
-        $reevaluate = get_string('yes', 'iassign');
+        $opt_reevaluate = get_string('yes', 'iassign');
       else
-        $reevaluate = get_string('no', 'iassign');
-      $str .= '<td width="50%"><strong>' . get_string('auto_evaluate_name_config', 'iassign') . ':</strong>&nbsp;' . $reevaluate . '</td></tr>';
-      
-      $str .= '<tr><td><strong>' . get_string('editing_behavior_view', 'iassign') . ':</strong> ';
+        $opt_reevaluate = get_string('no', 'iassign');
+
+      // Field 'iassign_ilm.reevaluate.'
+      $str .= '<td width="50%"><strong>' . get_string('auto_evaluate_name_config', 'iassign') . ':</strong>&nbsp;' . $opt_reevaluate . '</td></tr>' . chr(13);
 
-      if ($ilm_parent->editingbehavior == 0) {
+      // Field 'iassign_ilm.editingbehavior'
+      $str .= '<tr><td><strong>' . get_string('editing_behavior_view', 'iassign') . ':</strong> ';
+      if ($ilm_parent->editingbehavior == 0) { // 'iassign_ilm.editingbehavior' = 1 => the iLM allows the editing of a previous submission
         $str .=  get_string('editing_behavior_0', 'iassign');
       } elseif ($ilm_parent->editingbehavior == 1) {
         $str .=  get_string('editing_behavior_1', 'iassign');
@@ -399,10 +433,10 @@ else if ($action == 'config') { // Administration > plugins > iAssign : after se
       } elseif ($ilm_parent->submissionbehavior == 1) {
         $str .= get_string('submission_behavior_1', 'iassign');
       }
-      $str .= '</td></tr>';
+      $str .= '</td></tr>' . chr(13);
 
       $str .= '<tr>' . chr(13);
-      $str .= '<td width="50%"><strong>' . get_string('file_created', 'iassign') . ':</strong>&nbsp;' . userdate($ilm_parent->timecreated) . '</td>';
+      $str .= '<td width="50%"><strong>' . get_string('file_created', 'iassign') . ':</strong>&nbsp;' . userdate($ilm_parent->timecreated) . '</td>' . chr(13);
       $str .= '<td width="50%"><strong>' . get_string('file_modified', 'iassign') . ':</strong>&nbsp;' . userdate($ilm_parent->timemodified) . '</td>' . chr(13);
       $str .= '</tr>' . chr(13);
 
@@ -410,7 +444,7 @@ else if ($action == 'config') { // Administration > plugins > iAssign : after se
       $user_ilm = $DB->get_record('user', array('id' => $ilm_parent->author));
       if ($user_ilm) {
         $str .= '<tr>' . chr(13);
-        $str .= '<td colspan=2><strong>' . get_string('author', 'iassign') . ':</strong>&nbsp;' . $user_ilm->firstname . '&nbsp;' . $user_ilm->lastname . '</td>';
+        $str .= '<td colspan=2><strong>' . get_string('author', 'iassign') . ':</strong>&nbsp;' . $user_ilm->firstname . '&nbsp;' . $user_ilm->lastname . '</td>' . chr(13);
         $str .= '</tr>' . chr(13);
         }
         
@@ -456,9 +490,9 @@ else if ($action == 'config') { // Administration > plugins > iAssign : after se
         $link_delete_param = $OUTPUT->action_link($url_delete_param, iassign_icons::insert('delete_param'));
 
         $str .= '<tr>' . chr(13);
-        $str .= '<td>' . $ilm_config->param_name . '</td>';
-        $str .= '<td>' . $ilm_config->param_value . '</td>';
-        $str .= '<td width="50%">' . $ilm_config->description . '</td>';
+        $str .= '<td>' . $ilm_config->param_name . '</td>' . chr(13);
+        $str .= '<td>' . $ilm_config->param_value . '</td>' . chr(13);
+        $str .= '<td width="50%">' . $ilm_config->description . '</td>' . chr(13);
         $str .= '<td width="10%"><center>';
         $str .= $link_edit_param . '&nbsp;&nbsp;';
         $str .= $link_copy_param . '&nbsp;&nbsp;';
@@ -474,11 +508,11 @@ else if ($action == 'config') { // Administration > plugins > iAssign : after se
       $str .= '</tr>' . chr(13);
 
       $str .= '</table>';
-      $str .= '</td></tr>';
-      $str .= '</tr><td colspan="3"></td></tr>';
+      $str .= '</td></tr>' . chr(13);
+      $str .= '</tr><td colspan="3"></td></tr>' . chr(13);
       }
-    }
+    } // if ($iassign_ilm_parent)
   $str .= '</table>';
 
   $settings->add(new admin_setting_heading('iassign', $ilm->name . '&nbsp;', $str));
-  }
+  } // else if ($action == 'config')

+ 18 - 5
settings_form.php

@@ -7,6 +7,8 @@
  * then by 'ilm_handlers/(html5 or java).php' with copy_new_version_ilm($param, $files_extract)'
  * 
  * Release Notes:
+ * - v 2.0.1 2022/09/15
+ *   + Considering table 'iassign_ilm': messages to fields 'evaluate', 'reevaluate', 'editingbehavior'; fixes to allow the edition of 'reevaluate', 'editingbehavior'
  * - v 1.6.3 2020/04/28
  *   + Fixed detail: undefinde variable 'if ($filejars!='')' - it was '$filejar'
  * - v 1.6.2 2020/01/20
@@ -32,7 +34,7 @@
  * 'auto_evaluate_help'] = 'If the iLM has automatic evaluation select Yes to use an activity with it.'; // 'What is automatic evaluation
  * 
  * @see ./locallib.php : 'add_edit_copy_ilm($ilm_id,$action)' load this script and provides data to it (defines initial values to the form fields)
- * @see ./settings_ilm.php : load and process this form, it uses data under the name $param
+ * @see ./settings_ilm.php : load and process this form, it uses data under the name $param, calling 'locallib.php!add_edit_copy_ilm(.)'
  * @see ./ilm_handlers/html5.php : save_ilm_by_xml($application_xml, $files_extract): return null;
  * 
  * @author Patricia Alves Rodrigues
@@ -65,8 +67,8 @@ class mod_ilm_form extends moodleform {
     global $CFG, $COURSE, $USER, $DB;
     global $description; // defined in 'settings_ilm.php'
 
-//    $mform = & $this->_form;
-$mform = $this->_form; //leo
+    // $mform = & $this->_form;
+    $mform = $this->_form; //leo
 
     if ($CFG->action_ilm != 'import') {
 
@@ -276,13 +278,24 @@ $mform = $this->_form; //leo
         $mform->setType('height', PARAM_TEXT);
         //$mform->addRule('height', get_string('required', 'iassign'), 'required');
 
-        // Adding the standard "evaluate" field
+        // Adding the field "evaluate"
         $mform->addElement('selectyesno', 'evaluate', get_string('auto_evaluate', 'iassign'));
         $mform->setDefault('evaluate', 1);
         //$mform->addRule('evaluate', get_string('required', 'iassign'), 'required');
         $mform->addHelpButton('evaluate', 'auto_evaluate', 'iassign');
 
-        // Adding the standard "submissionbehavior" field
+        // Adding the field "reevaluate"
+        $mform->addElement('selectyesno', 'reevaluate', get_string('auto_reevaluate', 'iassign'));
+        $mform->setDefault('reevaluate', 1);
+        $mform->addHelpButton('reevaluate', 'auto_reevaluate', 'iassign');
+
+        // Adding the field "editingbehavior"
+        $mform->addElement('selectyesno', 'editingbehavior', get_string('auto_editingbehavior', 'iassign'));
+        $mform->setDefault('editingbehavior', 1);
+        $mform->addHelpButton('editingbehavior', 'auto_editingbehavior', 'iassign');
+
+        // Adding the field "submissionbehavior": behaviour after submission
+	// + 'iassign_ilm.submissionbehavior' = { 0 =>  remains on the same page; 1 => changes the current page; ... }
         $mform->addElement('text', 'submissionbehavior', get_string('auto_evaluate', 'iassign'));
         $mform->setType('submissionbehavior', PARAM_INT);
 

+ 12 - 3
settings_ilm.php

@@ -6,6 +6,8 @@
  * 2. action==new_version
  * 
  * Release Notes:
+ * - v 2.0.1 2022/09/15
+ *   + Considering table 'iassign_ilm': messages to fields 'evaluate', 'reevaluate', 'editingbehavior'; fixes to allow the edition of 'reevaluate', 'editingbehavior'
  * - v 1.6.1 2017/12/02
  *   + Changed 'echo' to 'print'
  * - v 1.6 2013/10/31
@@ -18,8 +20,8 @@
  *   + Insert actions: copy (new version from an iLM) and new version (empty new version).
  * 
  * @author Patricia Alves Rodrigues
- * @author Leônidas O. Brandão
- * @version v 1.6.1 2017/12/02
+ * @author Leo^nidas de Oliveira Branda~o
+ * @version v 2.0.1 2022/09/15
  * @package mod_iassign_settings
  * @since 2013/01/29
  * @see   locallib.php : class ilm_settings
@@ -64,8 +66,15 @@ if ($action == 'edit') { // Edit data of an iLM => processed in 'settings_form.p
   $PAGE->set_title($title);
 
   // Get all fields of this iLM: name, type, set_lang, description_lang, author, action, timecreated, timemodified, parent, ...
+  // On the first time $ilm_id is well defined, but on the second (it is empty), however we need to call "add_edit_copy_ilm(.)"
   $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action); // locallib.php: class ilm_settings: add_edit_copy_ilm($ilm_id, $action)
 
+  // On the first call $ilm_id is defined: the calling is necessary to fill in data to the form
+  // on the second call $ilm_id empty and could be avoided
+  //? if ($ilm_id) $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action); // locallib.php: class ilm_settings: add_edit_copy_ilm($ilm_id, $action)
+  //? else $param = new stdClass();
+  // without 'ilm_settings::add_edit_copy_ilm(.)' the process are not successfully finished
+
   //D echo "settings_ilm.php: edit: $title"; // echo "param->description="; print_r($param->description); 
   //D $description = $param->description_lang; // used to present the iLM description in 'settings_form.php'
   //D $description = $param->description; //TODO in 'settings_form.php' it does NOT present the description!!!
@@ -316,4 +325,4 @@ if ($action == 'view') {
   print($view_ilm);
   print($OUTPUT->footer());
   die;
-  }
+  }