Browse Source

Export CSV bug fixed

Igor 4 years ago
parent
commit
0ab972632f
3 changed files with 34 additions and 18 deletions
  1. 12 2
      iassign_form.php
  2. 1 1
      lang/en/iassign.php
  3. 21 15
      locallib.php

+ 12 - 2
iassign_form.php

@@ -523,12 +523,22 @@ class mod_iassign_form extends moodleform {
           $file = $fs->get_file_by_id($value);
 
           if ($file) {
+            // Verify if file extension is correct to iLM
+            $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $data['iassign_ilmid']));
+            
             echo "<script>
               window.onload = function(e){ 
-                document.getElementById('iassign_file_link').innerHTML = '".$file->get_filename()."&nbsp;&nbsp;&nbsp;';
-              } </script>";
+                document.getElementById('iassign_file_link').innerHTML = '".$file->get_filename()."&nbsp;&nbsp;&nbsp;';";
+                
+            if ($iassign_ilm->extension != pathinfo($file->get_filename(), PATHINFO_EXTENSION)) {
+              $errors['iassign_ilmid_t'] = get_string('incompatible_extension_file', 'iassign');
+
+              echo "document.getElementById('error_message_file').innerHTML += '<span style=\"font-size: 80%;color: #d9534f; margin-left: 1em;\">".get_string('incompatible_extension_file', 'iassign')."</span>';
+                    document.getElementById('file_border').style.borderColor = '#d9534f';";
             }
 
+            echo "} </script>";
+          }
           
         }
       }

+ 1 - 1
lang/en/iassign.php

@@ -325,7 +325,7 @@ $string['ilm_type_help']                  = 'Please, select the iLM type:<br> -
 $string['import_file']                    = 'File Activity {$a} or compressed (zip):';
 $string['import_ilm']                     = 'Import iLM';
 $string['import_ilm_help']                = 'Import iLM';
-$string['incompatible_extension_file']    = 'File activity incompatible with the selected IMA.';
+$string['incompatible_extension_file']    = 'File activity incompatible with the selected iLM.';
 $string['incorrect']                      = 'Incorrect';
 $string['independent_activity']           = 'Independent activity';
 $string['info_ilm']                       = 'Information about interactive Learning Modules (iLM)';

+ 21 - 15
locallib.php

@@ -2067,22 +2067,27 @@ class iassign {
         $str .= '"' . $iassign->name . '",';
 
         $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
-        $str .= $student_submissions->experiment . ',';
-        $str .= $student_submissions->grade . ',';
-        switch ($student_submissions->status) {
-          case 3:
-            $str .= '"correct",';
-            break;
-          case 2:
-            $str .= '"incorrect",';
-            break;
-          case 1:
-            $str .= '"post",';
-            break;
-          case 0:
-            $str .= '"not_post",';
-            break;
+        if ($student_submissions) {
+          $str .= $student_submissions->experiment . ',';
+          $str .= $student_submissions->grade . ',';
+          switch ($student_submissions->status) {
+            case 3:
+              $str .= '"correct",';
+              break;
+            case 2:
+              $str .= '"incorrect",';
+              break;
+            case 1:
+              $str .= '"post",';
+              break;
+            case 0:
+              $str .= '"not_post",';
+              break;
+          }
+        } else {
+          $str .= ',,"not_post",';
         }
+        
         $str .= $iassign->iassign_ilmid . ',';
 
         $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
@@ -2091,6 +2096,7 @@ class iassign {
       $str .= "\n";
     }
     $str = $fields . "\n" . $str;
+    header("Content-type: text/csv");
     header("Content-disposition: attachment; filename=report.csv");
     header("Pragma: no-cache");
     header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");