|
|
@@ -2,8 +2,22 @@
|
|
|
|
|
|
/**
|
|
|
* iLM manager
|
|
|
+ * Provides form to choose file activity in new iAssign activity (through 'mod/iassign/view.php?action=add')
|
|
|
+ *
|
|
|
+ * Use 'ilm_manager_form.php' to generate the form to create new activity
|
|
|
+ *
|
|
|
+ * The 'locallib.php!class ilm_manage view_files_ilm($iassign_ilm_class, $extension)' will buid the icons with
|
|
|
+ * JavaScript calling functions or this 'ilm_manager.php' (last case):
|
|
|
+ * - "Rename activity" : rename_ilm(...)
|
|
|
+ * - "Delete activity" : delete_ilm(...)
|
|
|
+ * - "Duplicate" : duplicate_ilm(...)
|
|
|
+ * - "Edit activity" : update_ilm(...)
|
|
|
+ * - "Preview" : preview_ilm(...) and
|
|
|
+ * - "Add iLM" : "ilm_manager.php?...action=addilm..." - TODO this "Add iLM" must be change in "lang/*" to something like "Select this iLM file content"
|
|
|
*
|
|
|
* Release Notes
|
|
|
+ * - v 2.7.2 2022/09/21
|
|
|
+ * + improved variables names ($files,$file to $all_context_files,$one_file)
|
|
|
* - v 2.7.1 2020/08/03
|
|
|
* + added parameter 'iLM_PARAM_Authoring=true&' to indicate is teacher accessing (authoring process)
|
|
|
* - v 2.7 2017/03/10
|
|
|
@@ -49,7 +63,7 @@
|
|
|
* + Filter file extension for permission only compatilbe with iLM and block view all user files.
|
|
|
*
|
|
|
* @author Patricia Alves Rodrigues
|
|
|
- * @author Leônidas O. Brandão
|
|
|
+ * @author Leo^nidas de Oliveria Branda~o
|
|
|
* @version v 2.7 2019/03/13
|
|
|
* @version v 2.6 2016/05/12
|
|
|
* @package mod_iassign_ilm
|
|
|
@@ -78,7 +92,7 @@ require_once($CFG->dirroot . '/mod/iassign/ilm_manager_form.php');
|
|
|
//D print $ilm_manager_instance->get_file_ilm($ilmid, $fileid);
|
|
|
//D exit;
|
|
|
|
|
|
-require_login();
|
|
|
+require_login(); // to avoid snooping
|
|
|
if (isguestuser()) { // Security!
|
|
|
die();
|
|
|
}
|
|
|
@@ -86,6 +100,7 @@ if (isguestuser()) { // Security!
|
|
|
if (session_id() === "")
|
|
|
session_start();
|
|
|
|
|
|
+
|
|
|
// Prepare iLM content file in secure are to the iLM access it
|
|
|
function prepare_secure_access ($ilmid, $fileid, $userid) {
|
|
|
require_once ('ilm_security.php');
|
|
|
@@ -130,7 +145,7 @@ if (empty($iassign_ilm)) {
|
|
|
$returnurl = optional_param('returnurl', NULL, PARAM_TEXT);
|
|
|
|
|
|
if ($returnurl != NULL)
|
|
|
- $_SESSION['returnurl'] = optional_param('returnurl', $CFG->wwwroot . "/course/view.php?id=$id&ilmid=$ilmid", PARAM_TEXT); //2016:: PARAM_ALPHANUMEXT
|
|
|
+ $_SESSION['returnurl'] = optional_param('returnurl', $CFG->wwwroot . '/course/view.php?id=' . $id . '&ilmid=' . $ilmid, PARAM_TEXT); //2016:: PARAM_ALPHANUMEXT
|
|
|
|
|
|
$title = get_string('ilm_manager_title', 'iassign');
|
|
|
|
|
|
@@ -247,8 +262,9 @@ if (has_capability('mod/iassign:editiassign', $context, $USER->id)) {
|
|
|
}
|
|
|
else if ($formdata = $mform->get_data()) { // if exists '$mform->get_data()' use with '$formdata'
|
|
|
$fs = get_file_storage();
|
|
|
- if ($formdata->dirid == 0)
|
|
|
+ if ($formdata->dirid == 0) {
|
|
|
$dir_base = '/';
|
|
|
+ }
|
|
|
else {
|
|
|
$dir_base = $fs->get_file_by_id($formdata->dirid);
|
|
|
//$dir_base = $dir_base->get_filepath();
|
|
|
@@ -275,22 +291,11 @@ if (has_capability('mod/iassign:editiassign', $context, $USER->id)) {
|
|
|
$filename = iassign_utils::version_filename($value->get_filename());
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
|
|
|
$ilm_extensions = explode(",", $iassign_ilm->extension);
|
|
|
if (in_array($file_extension, $ilm_extensions))
|
|
|
- $file = $mform->save_stored_file(
|
|
|
- 'file',
|
|
|
- $context->id,
|
|
|
- 'mod_iassign',
|
|
|
- 'activity',
|
|
|
- 0,
|
|
|
- '/',
|
|
|
- $filename,
|
|
|
- 0,
|
|
|
- $USER->id);
|
|
|
-
|
|
|
+ $file = $mform->save_stored_file('file', $context->id, 'mod_iassign', 'activity', 0, '/', $filename,0,$USER->id);
|
|
|
else if ($from == 'block' || $from == 'tinymce' || $from == 'atto')
|
|
|
$file = $mform->save_stored_file('file', $context->id, 'mod_iassign', 'activity', 0, $dir_base, iassign_utils::format_filename($filename), 0, $USER->id);
|
|
|
else
|
|
|
@@ -301,13 +306,13 @@ if (has_capability('mod/iassign:editiassign', $context, $USER->id)) {
|
|
|
$zip = new zip_packer();
|
|
|
$mform->save_file('file', $zip_filename, true) or die("Save file not found");
|
|
|
$zip_files = $zip->list_files($zip_filename);
|
|
|
- $files = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
|
|
|
+ $all_context_files = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
|
|
|
|
|
|
//TODO: --- inicio : linhas abaixo estavam comentadas, mas noutra versao funcional (MOOC) estao ativas
|
|
|
$rename_files = array();
|
|
|
foreach ($zip_files as $zip_file) {
|
|
|
- foreach ($files as $file) {
|
|
|
- if (iassign_utils::format_filename($zip_file->original_pathname) == $file->get_filename())
|
|
|
+ foreach ($all_context_files as $one_file) {
|
|
|
+ if (iassign_utils::format_filename($zip_file->original_pathname) == $one_file->get_filename())
|
|
|
$rename_files = array_merge($rename_files, array(iassign_utils::version_filename(iassign_utils::format_filename($zip_file->original_pathname)) => iassign_utils::format_filename($zip_file->original_pathname)));
|
|
|
}
|
|
|
} //TODO: --- final 2016/02/16
|
|
|
@@ -315,14 +320,14 @@ if (has_capability('mod/iassign:editiassign', $context, $USER->id)) {
|
|
|
$zip->extract_to_storage($zip_filename, $context->id, 'mod_iassign', 'activity', 0, $dir_base, $USER->id);
|
|
|
|
|
|
//TODO: --- inicio : linhas abaixo estavam comentadas, mas noutra versao funcional (MOOC) estao ativas
|
|
|
- $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity', 0, 'filename');
|
|
|
- foreach ($files as $file) {
|
|
|
- if ($file->get_author() == "") {
|
|
|
- $file->set_author($USER->firstname . ' ' . $USER->lastname);
|
|
|
- if ($new_name = array_search($file->get_filename(), $rename_files))
|
|
|
- $file->rename($dir_base, $new_name);
|
|
|
- else if ($file->get_filename() != '.' && $file->get_filename() != iassign_utils::format_filename($file->get_filename()))
|
|
|
- $file->rename($dir_base, iassign_utils::format_filename($file->get_filename()));
|
|
|
+ $all_context_files = $fs->get_area_files($context->id, 'mod_iassign', 'activity', 0, 'filename');
|
|
|
+ foreach ($all_context_files as $one_file) {
|
|
|
+ if ($one_file->get_author() == "") {
|
|
|
+ $one_file->set_author($USER->firstname . ' ' . $USER->lastname);
|
|
|
+ if ($new_name = array_search($one_file->get_filename(), $rename_files))
|
|
|
+ $one_file->rename($dir_base, $new_name);
|
|
|
+ else if ($one_file->get_filename() != '.' && $one_file->get_filename() != iassign_utils::format_filename($one_file->get_filename()))
|
|
|
+ $one_file->rename($dir_base, iassign_utils::format_filename($one_file->get_filename()));
|
|
|
}
|
|
|
} //TODO: --- final 2016/02/16
|
|
|
|
|
|
@@ -332,7 +337,7 @@ if (has_capability('mod/iassign:editiassign', $context, $USER->id)) {
|
|
|
$fs->delete_area_files($contextuser->id, 'user', 'draft', $formdata->file);
|
|
|
} // if ($newfilename = $mform->get_new_filename('file'))
|
|
|
|
|
|
- redirect(new moodle_url($url));
|
|
|
+ redirect(new moodle_url($url));
|
|
|
} // else if ($formdata = $mform->get_data()) - 172/271,10
|
|
|
|
|
|
print $OUTPUT->header();
|
|
|
@@ -364,7 +369,13 @@ if (has_capability('mod/iassign:editiassign', $context, $USER->id)) {
|
|
|
|
|
|
$mform->display();
|
|
|
|
|
|
+ //D if (isset($formdata->dirid)) $aux = $formdata->dirid; else $aux = "[empty]";
|
|
|
+ //D echo "<br/><br/><br/><br/><br/><br/> - ilm_manager.php: action=".$action.", formdata->dirid=".$aux."<br/>";
|
|
|
+
|
|
|
+ // In 'locallib.php!view_files_ilm($iassign_ilm_class, $extension)' are loaded all file to this iLM
|
|
|
+ // From './lib/filestorage/file_storage.php'
|
|
|
$ilm_manager_instance->view_files_ilm($iassign_ilm, $iassign_ilm->extension); // locallib.php : function view_files_ilm($iassign_ilm, $extension)
|
|
|
+ //D echo "ilm_manager.php: ilmid=" . $ilmid . "; file_extension=" . $file_extension . "=" . $iassign_ilm->extension . "<br/>\n";//leo1
|
|
|
|
|
|
print $OUTPUT->footer();
|
|
|
|