| 
					
				 | 
			
			
				@@ -4,6 +4,9 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * This class provides all the functionality for an ia (interactive activities). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  *  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * Release Notes: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * - v 4.9.3 2020/01/16 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ *   + Several fixes to allow to move activities in a block and improvements in repository 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * - v 4.9.2 2019/03/13 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  *   + Several fixes to allow iLM under HTML stack 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  *  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -313,7 +316,8 @@ class iassign { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     else { // Student reaches this point 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       // When student do/redo activity: do => action = "view"; redo => action = "repeat"  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       // Arrive here with: "get_answer"; "view" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } // function action() 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -6186,7 +6190,7 @@ class ilm_manager { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // (NAO s_iassign_statement.file = s_files.id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $fs = get_file_storage(); // Get reference to all files in Moodle data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    $dir_base = $this->get_dir_ilm('dir_base');       
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $dir_base = $this->get_dir_ilm('dir_base'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $countf = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $array_files_id = array(); // all files from this context 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -6204,13 +6208,15 @@ class ilm_manager { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $countf++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return $countf; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   /// List iassign files from course directory 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   //  @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  function view_files_ilm ($iassign_ilm_class, $extension) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  function view_files_ilm ($iassign_ilm_class, $extension, $start = 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //TODO usar $start para trazer no maximo 50 arquivos iniciando em $start 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     global $CFG, $DB, $USER, $OUTPUT; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $fs = get_file_storage(); // Get reference to all files in Moodle data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $context = context_course::instance($this->id); // $this->id = ID of the current course     
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -6227,29 +6233,44 @@ class ilm_manager { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // Get all files from table '*_files': id ; contenthash ; pathnamehash ; contextid ; component ;... filename ; userid ... 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // $DB is 'mysqli_native_moodle_database' object 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (!has_capability("moodle/site:config", $context, $USER->id, true)) // *_capabilities="moodle/site:config" : greatest one 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      $array_query = array('component' => 'mod_iassign'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      $array_query = array('component' => 'mod_iassign', 'userid' => $USER->id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    $files_iassign = $DB->get_records('files', $array_query); // extensions for all iLM... 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // if (has_capability("moodle/site:config", $context, $USER->id, true)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // if (has_capability("mod/iassign:addinstance", $context, $USER->id, true)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $hascapability = has_capability("moodle/site:config", $context, $USER->id); // *_capabilities="moodle/site:config" : greatest one) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if ($hascapability==1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      //$array_query = array('component' => 'mod_iassign'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      $query_sql = "SELECT * FROM {files} WHERE component='mod_iassign' AND filearea='activity'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      // $array_query = array('component' => 'mod_iassign', 'userid' => $USER->id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      $query_sql = "SELECT * FROM {files} WHERE component='mod_iassign' AND filearea='activity' AND " . 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                   " (license<>'allrightsreserved' OR contextid=" . $context->id . " OR userid=" . $USER->id . ")"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // files : id contenthash pathnamehash contextid component filearea itemid filepath filename userid filesize mimetype status source author license timecreated timemodified sortorder referencefileid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // $files_iassign = $DB->get_records('files', $array_query); // extensions for all iLM... 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $files_iassign = $DB->get_records_sql($query_sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //D echo "view_files_ilm: " . $USER->id . ", " . $hascapability . ": " . $query_sql . "<br/>"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //D SELECT id,contextid,component,filearea,itemid,filepath,filename,userid FROM s_files WHERE component='mod_iassign' AND filearea='exercise'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $count_all_files = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $count_files_with_ext = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $count_thisauthor_contextid = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $count_otherauthors_contextid = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //D echo "view_files_ilm: user.id=" . $USER->id . ", ext=$extension, #files=" . count($files_iassign) . "<br/>"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (is_array($files_iassign)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     foreach ($files_iassign as $item_files_iassign) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       $extensionF = explode(".", $item_files_iassign->filename); // $item_files_iassign->get_filename() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       $lastitem = sizeof($extensionF); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       if ($lastitem>0) $lastitem--; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      else // error: it must have extension (after ".") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      else { echo ".";// error: it must have extension (after ".") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        continue;} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       $str_extension = $extensionF[$lastitem]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       $count_files_with_ext++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       if ($extension == $str_extension) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $contextid = $item_files_iassign->contextid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!in_array($contextid, $array_contextid_files_aux)) { // not yet in array of context with this extension 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	  $array_contextid_files_aux[] = $contextid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           $total_in_context = $this->get_files_in_context($array_all_files, $contextid, $extension, $USER->id); // $array_all_files by reference 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           $count_all_files += $total_in_context; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -6257,10 +6278,17 @@ class ilm_manager { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //D echo "view_files_ilm: #array_contextid_files_aux=".count($array_contextid_files_aux). ", count_all_files=$count_all_files<br/>"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //view_files_ilm: #array_contextid_files_aux=54 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //TODO Deste modo vem: se ADMIN => todos os arquivos de extensao compativel; senao todos os arquivos do usuario 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //TODO Implementar:    se NAO ADMIN => pegar TODOS os arquivos do curso 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //TODO Tabela pegar todos '*_files.contextid' tais que '*_files.component=="mod_iassign"' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $array_files_course = array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $dirs_array = '';  // if there are none 'exercise' file 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $files_array = ''; // idem 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $files_array = "''"; // idem 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $error_files_exists = "''"; // idem 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for ($ii=$count_all_files-1; $ii>0; $ii--) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       //$contextid = $array_contextid_files[$ii]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       //$files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename'); 
			 |