Przeglądaj źródła

Comment request finished

Igor 3 lat temu
rodzic
commit
812cc6b345
2 zmienionych plików z 63 dodań i 10 usunięć
  1. 13 3
      ilm_handlers/html5.php
  2. 50 7
      locallib.php

+ 13 - 3
ilm_handlers/html5.php

@@ -264,6 +264,7 @@ class html5 implements ilm_handle {
 
   // ./mod/iassign/ilm/ivprog-html/js/services.js : call this to define the variable 'evaluationResult'
   function getEvaluationCallback (evaluation) {
+    let submissionbehavior = ".$ilm->submissionbehavior.";
     evaluationResult = evaluation;
     //leo 2017/11/22 strAnswer = window.frames.iLM.getAnswer();
     strAnswer = window.frames[0].getAnswer();      
@@ -276,13 +277,21 @@ class html5 implements ilm_handle {
       alert('" . get_string('activity_empty', 'iassign') . "'); // 'Activity sent without content.'
       return false; // error...
       }
-    else {
+    else if (submissionbehavior == 1) {
       document.formEnvio.iLM_PARAM_ArchiveContent.value = strAnswer;
       document.formEnvio.iLM_PARAM_ActivityEvaluation.value = evaluationResult;
       document.formEnvio.iLM_PARAM_RealGrade.value = evaluation;
       //D alert(strAnswer);
       document.formEnvio.submit();
       return true; // success
+      } else if (submissionbehavior == 0) {
+        var formData = new FormData();
+        formData.append('iLM_PARAM_ArchiveContent', strAnswer);
+        formData.append('iLM_PARAM_ActivityEvaluation', evaluationResult);
+        formData.append('iLM_PARAM_RealGrade', evaluation);
+        var request = new XMLHttpRequest();
+        request.open('POST', '$enderecoPOST');
+        request.send(formData);
       }
      }
   //]]>
@@ -315,6 +324,7 @@ class html5 implements ilm_handle {
 
     if (!isguestuser() && $iassign_statement_activity_item->type_iassign != 1
     && ($ilm->editingbehavior == 1 || ($ilm->editingbehavior == 0 && !in_array($_GET['action'], array('viewsubmission', 'view'))))) {
+
       $iassign .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>\n";
       $iassign .= " <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>\n";
       $iassign .= " <input type='hidden' name='iLM_PARAM_RealGrade' value=''>\n";
@@ -325,9 +335,9 @@ class html5 implements ilm_handle {
       elseif ($ilm->action_buttons == 0)
         $disabled_button = " disabled='true' ";
 
-      $iassign .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
+      //$iassign .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
       $iassign .= "<center>\n<!-- load button -->\n" .
-      "  <input $disabled_button type=button value='" . get_string('submit_iassign', 'iassign') . "' onClick = 'javascript:window.jsAnalyseAnswer();' title='" .
+      " <br> <br> <input $disabled_button type=button value='" . get_string('submit_iassign', 'iassign') . "' onClick = 'javascript:window.jsAnalyseAnswer();' title='" .
       get_string('message_submit_iassign', 'iassign') . "'>\n" . "</center>\n";
 
 

+ 50 - 7
locallib.php

@@ -271,7 +271,7 @@ class iassign {
     // edit - edit activity (modificar atividade)
 
     $action_iassign = array(
-      'newcomment' => '$this->get_answer();',
+      'newcomment' => '$this->add_comment();',
       'view' => '$this->view_iassign_current();',
       'get_answer' => '$this->get_answer();',
       'repeat' => '$this->view_iassign_current();',
@@ -991,7 +991,16 @@ class iassign {
     $this->return_home_course('duplicated_activity');
     exit;
     }
-
+  
+  // / This method gets the content from comment and register it
+  function add_comment () {
+    $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
+    $comment = false;
+    if ($submission_comment)
+      $comment = $this->write_comment_submission();
+    $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
+    echo $this->search_comment_submission($id_submission);
+  }
 
   /// This method gets the content from the iLM and register it
   //  It could be the "exercise template" (teacher) or an answer (student)
@@ -1023,6 +1032,17 @@ class iassign {
     $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
     $msg = '';
 
+    if ($this->activity->get_activity()->store_all_submissions == 1) {
+      $newentry = new stdClass();
+      $newentry->iassign_statementid = $this->activity->get_activity()->id;
+      $newentry->userid = $this->userid_iassign;
+      $newentry->timecreated = time();
+      $newentry->grade = round($iLM_PARAM_RealGrade, 2);
+      $newentry->answer = $iLM_PARAM_ArchiveContent;
+
+      $DB->insert_record("iassign_allsubmissions", $newentry);
+    }
+
     // Feedback
     // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
     $str_action = "view"; // repeat
@@ -2574,16 +2594,39 @@ class iassign {
         }
 
       $output .= $OUTPUT->box_start();
-      $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' method='post' action='$enderecoPOSTcomment' enctype='multipart/form-data'>\n";
-      $output .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
-      $output .= "<p><input type=submit value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
-      $output .= "</form></center>\n";
-      if (!empty($history_comment)) {
+      
+
+      //if (!empty($history_comment)) {
         $output .= "  <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
         $output .= "     <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
         $output .= $history_comment;
         $output .= "</table>";
+
+        print " <script type='text/javascript'>
+        //<![CDATA[
+        function submit_comment(url) {
+          var formData = new FormData();
+          formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
+          var request = new XMLHttpRequest();
+          request.open('POST', url);
+          request.onload = function (e) {
+            if (request.readyState === 4) {
+              if (request.status === 200) {
+                alert(request.responseText);
+              }
+            }
+          };          
+          request.send(formData);
         }
+        //]]>
+        </script>";
+
+        $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
+        $output .= "<br><p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
+        $output .= "<p><input onclick=\"submit_comment('$enderecoPOSTcomment')\" type=button value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
+        $output .= "</form></center>\n";
+
+      //  }
       $output .= $OUTPUT->box_end();
       print $output;
       } // if ($iassign_statement_activity_item->type_iassign == 3)