$fullpath = '/' . $context->id . '/mod_referentiel/archive/0' . $zformat->get_export_dir() . $exportfilename . $file_ext; $efile = new moodle_url($CFG->wwwroot . '/pluginfile.php' . $fullpath); echo "<p><div class=\"boxaligncenter\"><a href=\"{$efile}\">{$txt->download}</a></div></p>"; echo "<p><div class=\"boxaligncenter\"><font size=\"-1\">{$txt->downloadextra}</font></div></p>"; echo $OUTPUT->continue_button($CFG->wwwroot . '/mod/referentiel/certificat.php?id=' . $cm->id); echo $OUTPUT->footer(); die; } else { // BOITES DE SELECTION if (has_capability('mod/referentiel:export', $context)) { echo '<div align="center"><h3><img src="' . $icon . '" border="0" title="" alt="" /> ' . get_string('selectcertificat', 'referentiel') . ' ' . $OUTPUT->help_icon('selectcertificath', 'referentiel') . '</h3></div>' . "\n"; referentiel_select_liste_certificats($referentiel, $list_pedagoids, $userid_filtre, $gusers, $select_acc, $mode, $CFG->wwwroot . '/mod/referentiel/archive.php?d=' . $referentiel->id, $select_all, $sql_filtre_where, $data_archive); } /// Display upload form // get valid formats to generate dropdown list $fileformatnames = referentiel_get_import_export_formats('archive', 'zformat'); // get filename if (empty($exportfilename)) { $exportfilename = referentiel_default_export_filename($course, $referentiel, 'archive'); } echo "\n<br />\n"; echo $OUTPUT->box_start('generalbox boxaligncenter'); echo "\n<div align=\"center\">\n"; ?> <form enctype="multipart/form-data" method="post" action="archive.php?id=<?php echo $cm->id; ?> "> <fieldset class="invisiblefieldset" style="display: block;"> <input type="hidden" name="sesskey" value="<?php echo sesskey();
// une seule action possible $url->param('action', $action); // AFFICHAGE DE LA PAGE Moodle 2 $strreferentiels = get_string('modulenameplural', 'referentiel'); $strreferentiel = get_string('referentiel', 'referentiel'); $strmessage = get_string('importetudiants', 'referentiel'); $strpagename = get_string('import_etudiant', 'referentiel'); $strlastmodified = get_string('lastmodified'); $pagetitle = strip_tags($course->shortname . ': ' . $strreferentiel . ': ' . format_string($referentiel->name, true)); $icon = $OUTPUT->pix_url('icon', 'referentiel'); $PAGE->set_url($url); $PAGE->set_title($pagetitle); $PAGE->navbar->add($strpagename); $PAGE->set_heading($course->fullname); // formulaire de saisie d'un fichier $fileformatnames = referentiel_get_import_export_formats('import', 'eformat'); $options = array('subdirs' => 0, 'maxbytes' => get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, 0), 'maxfiles' => 1, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL); $mform = new referentiel_import_form(null, array('d' => $referentiel->id, 'contextid' => $context->id, 'filearea' => 'scolarite', 'fileformats' => $fileformatnames, 'stoponerror' => 1, 'msg' => get_string('importetudiants', 'referentiel'), 'options' => $options)); // recuperer le fichier charge if ($mform->is_cancelled()) { // redirect(new moodle_url('/course/view.php', array('id'=>$course->id))); redirect(new moodle_url('/mod/referentiel/etudiant.php', array('id' => $cm->id, 'mode' => 'listetudiant', 'select_acc' => 0))); } else { if ($mform->get_data()) { $returnlink = new moodle_url('/mod/referentiel/etudiant.php', array('id' => $cm->id, 'mode' => 'listetudiant', 'select_acc' => 0)); if ($formdata = $mform->get_data()) { // DEBUG // echo "<br />DEBUG :: import_instance.php :: 193 :: FORMDATA\n"; // print_object($formdata); // $fileareas = array('referentiel', 'document', 'consigne', 'activite', 'task', 'certificat', 'scolarite', 'pedagogie');
/** * Import the referentiel, used by import_instance.php * * This in turn calls the methods producing individual parts of the page */ function load_referentiel($mode, $format = '', $action = '') { global $CFG, $USER; global $PAGE, $OUTPUT; // check role capability ////if ($CFG->version < 2011120100) { $this->context = context_module::instance($this->cm->id); //} else { // // $this->context = context_module::instance($this->cm); //} require_capability('mod/referentiel:import', $this->context); if ($CFG->version > 2014051200) { // Moodle 2.7+ $params = array('contextid' => $this->context->id, 'objectid' => $this->referentiel->id); $event = \mod_referentiel\event\import_intance::create($params); $event->trigger(); } else { // Before Moodle 2.7 add_to_log($this->course->id, 'referentiel', 'view', "import_instance.php?id={$this->cm->id}", $this->referentiel->id, $this->cm->id); } $this->view_header(); // get parameters $parametres = new stdClass(); $parametres->choosefile = optional_param('choosefile', '', PARAM_PATH); $parametres->stoponerror = optional_param('stoponerror', 0, PARAM_BOOL); $parametres->override = optional_param('override', 0, PARAM_BOOL); $parametres->newinstance = optional_param('newinstance', 0, PARAM_BOOL); // get display strings $txt = new stdClass(); $txt->referentiel = get_string('referentiel', 'referentiel'); $txt->fileformat = get_string('fileformat', 'referentiel'); $txt->choosefile = get_string('choosefile', 'referentiel'); $txt->formatincompatible = get_string('formatincompatible', 'referentiel'); $txt->file = get_string('file'); $txt->fileformat = get_string('fileformat', 'referentiel'); $txt->fromfile = get_string('fromfile', 'referentiel'); $txt->importerror_referentiel_id = get_string('importerror_referentiel_id', 'referentiel'); $txt->importerror = get_string('importerror', 'referentiel'); $txt->importfilearea = get_string('importfilearea', 'referentiel'); $txt->importfileupload = get_string('importfileupload', 'referentiel'); $txt->importfromthisfile = get_string('importfromthisfile', 'referentiel'); $txt->modulename = get_string('modulename', 'referentiel'); $txt->modulenameplural = get_string('modulenameplural', 'referentiel'); $txt->onlyteachersimport = get_string('onlyteachersimport', 'referentiel'); $txt->stoponerror = get_string('stoponerror', 'referentiel'); $txt->upload = get_string('upload'); $txt->uploadproblem = get_string('uploadproblem'); $txt->uploadthisfile = get_string('uploadthisfile'); $txt->importreferentiel = get_string('importreferentiel', 'referentiel'); $txt->newinstance = get_string('newinstance', 'referentiel'); $txt->choix_newinstance = get_string('choix_newinstance', 'referentiel'); $txt->choix_notnewinstance = get_string('choix_notnewinstance', 'referentiel'); $txt->override = get_string('override', 'referentiel'); $txt->choix_override = get_string('choix_override', 'referentiel'); $txt->choix_notoverride = get_string('choix_notoverride', 'referentiel'); /* /// Print the page header $strreferentiels = get_string('modulenameplural','referentiel'); $strreferentiel = get_string('referentiel','referentiel'); $strmessage = $icon = '<img class="icon" src="'.$CFG->wwwroot.'/mod/referentiel/icon.gif" alt="'.get_string('modulename','referentiel').'"/>'; $strpagename=get_string('modifier_referentiel','referentiel'); */ // echo $OUTPUT->heading($strmessage, 'importreferentiel', 'referentiel', $icon); echo $OUTPUT->heading(get_string('importreferentiel', 'referentiel'), 2); // file upload form submitted if (!empty($format)) { if (!confirm_sesskey()) { print_error('sesskey'); } // file checks out ok $fileisgood = false; // work out if this is an uploaded file // or one from the filesarea. if (!empty($parametres->choosefile)) { $importfile = "{$CFG->dataroot}/{$this->course->id}/{$parametres->choosefile}"; if (file_exists($importfile)) { $fileisgood = true; } else { notify($txt->uploadproblem); } } else { // must be upload file if (empty($_FILES['newfile'])) { notify($txt->uploadproblem); } else { if (!is_uploaded_file($_FILES['newfile']['tmp_name']) or $_FILES['newfile']['size'] == 0) { notify($txt->uploadproblem); } else { $importfile = $_FILES['newfile']['tmp_name']; // tester l'extention du fichier // DEBUG // echo "<br />DEBUG : 214 import_instance.php<br />FORMAT : $format<br />IMPORT_FILE $importfile\n"; // Les données suivantes sont disponibles après chargement // echo "<br />DEBUG :: Fichier téléchargé : '". $_FILES['newfile']['tmp_name'] ."'\n"; // echo "<br />DEBUG :: Nom : '". $_FILES['newfile']['name'] ."'\n"; // echo "<br />DEBUG :: Erreur : '". $_FILES['newfile']['error'] ."'\n"; // echo "<br />DEBUG :: Taille : '". $_FILES['newfile']['size'] ."'\n"; // echo "<br />DEBUG :: Type : '". $_FILES['newfile']['type'] ."'\n"; $nom_fichier_charge_extension = substr(strrchr($_FILES['newfile']['name'], "."), 1); // echo "<br />DEBUG :: LIGNE 223 :: Extension : '". $nom_fichier_charge_extension ."'\n"; // echo "<br />DEBUG :: LE FICHIER EST CHARGE\n"; if ($nom_fichier_charge_extension != $format) { notify($txt->formatincompatible); } else { $fileisgood = true; } } } } // process if we are happy, file is ok if ($fileisgood) { $returnlink = $CFG->wwwroot . '/mod/referentiel/import_instance.php?courseid=' . $this->course->id . '&sesskey=' . sesskey() . '&instance=' . $instance . '&mode=' . $mode . '&action=' . $action; // DEBUG // echo "<br/>RETURNLINK : $returnlink\n"; if (!is_readable("format/{$format}/format.php")) { print_error(get_string('formatnotfound', 'referentiel', $format)); } require "format.php"; // Parent class require "format/{$format}/format.php"; $classname = "rformat_{$format}"; $rformat = new $classname(); // load data into class $rformat->setIReferentiel($this->referentiel); // instance // $rformat->setRReferentiel( $this->referentiel_referentiel ); // not yet $rformat->setCourse($this->course); $rformat->setContext($this->context); $rformat->setCoursemodule($cm); $rformat->setFilename($importfile); $rformat->setStoponerror($parametres->stoponerror); $rformat->setOverride($parametres->override); $rformat->setNewinstance($parametres->newinstance); $rformat->setAction($action); // $rformat->setReturnpage(""); // Do anything before that we need to if (!$rformat->importpreprocess()) { print_error($txt->importerror, $returnlink); } // Process the uploaded file if (!$rformat->importprocess()) { print_error($txt->importerror, $returnlink); } // In case anything needs to be done after if (!$rformat->importpostprocess()) { print_error($txt->importerror, $returnlink); } // Verifier si referentiel charge if (!$rformat->new_referentiel_id) { print_error($txt->importerror_referentiel_id, $returnlink); } echo '<hr /> <form name="form" method="post" action="add.php?id=' . $this->cm->id . '"> <input type="hidden" name="name_instance" value="' . $this->referentiel->name_instance . '" /> <input type="hidden" name="description_instance" value="' . htmlentities($this->referentiel->description_instance, ENT_QUOTES, 'UTF-8') . '" /> <input type="hidden" name="label_domaine" value="' . $this->referentiel->label_domaine . '" /> <input type="hidden" name="label_competence" value="' . $this->referentiel->label_competence . '" /> <input type="hidden" name="label_item" value="' . $this->referentiel->label_item . '" /> <input type="hidden" name="action" value="importreferentiel" /> <input type="hidden" name="new_referentiel_id" value="' . $rformat->new_referentiel_id . '" /> <input type="hidden" name="action" value="' . $rformat->action . '" /> <input type="hidden" name="sesskey" value="' . sesskey() . '" /> <input type="hidden" name="courseid" value="' . $this->course->id . '" /> <input type="hidden" name="instance" value="' . $this->referentiel->id . '" /> <input type="hidden" name="mode" value="' . $mode . '" /> <input type="submit" value="' . get_string("continue") . '" /> </form> <div> ' . "\n"; $this->view_footer(); die; } } /// Print upload form // get list of available import formats $fileformatnames = referentiel_get_import_export_formats('import', 'rformat'); //========== // DISPLAY //========== echo '<form id="form" enctype="multipart/form-data" method="post" action="import_instance.php?id=' . $this->cm->id . '"> <fieldset class="invisiblefieldset" style="display: block;">' . "\n"; //echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter'); echo $OUTPUT->box_start('generalbox boxaligncenter'); echo ' <table cellpadding="5"> <tr> <td align="right">' . $txt->fileformat . '</td> <td>' . html_writer::select($fileformatnames, 'format', 'xml', false) . '</td> <td>' . $OUTPUT->help_icon('formath', 'referentiel'); //, "referentiel", $txt->importreferentiel); echo '</td> </tr> <tr> <td align="right">' . $txt->stoponerror . ' </td> <td> <input name="stoponerror" type="checkbox" checked="checked" /> </td> <td> </td> </tr> <tr> <td align="right">' . $txt->override . ' </td> <td> <input name="override" type="radio" value="1" /> ' . $txt->choix_override . ' <br /> <input name="override" type="radio" value="0" checked="checked" /> ' . $txt->choix_notoverride . ' </td> <td>' . $OUTPUT->help_icon('overrider', 'referentiel') . '</td> </tr> '; if (!empty($this->referentiel->ref_referentiel)) { echo ' <tr> <td align="right">' . $txt->newinstance . '</td> <td> <input name="newinstance" type="radio" value="1" checked="checked"/> ' . $txt->choix_newinstance . ' <br /> <input name="newinstance" type="radio" value="0" /> ' . $txt->choix_notnewinstance . ' </td> <td> ' . $OUTPUT->help_icon('overrideo', 'referentiel') . ' </td> </tr> '; } else { echo '<input name="newinstance" type="hidden" value="1" />' . "\n"; } echo ' </table> '; echo $OUTPUT->box_end(); echo $OUTPUT->box_start('generalbox boxaligncenter'); echo $txt->importfileupload . ' <table cellpadding="5"> <tr> <!-- td align="right">' . $txt->upload . ':</td --> <td colspan="2"> '; // upload_print_form_fragment(1,array('newfile'),null,false,null,$this->course->maxbytes,0,false); echo 'upload_print_form_fragment deprecated'; echo '</td> </tr> <tr> <td> </td> <td><input type="submit" name="save" value="' . $txt->uploadthisfile . '" /></td> </tr> </table> '; echo $OUTPUT->box_end(); echo $OUTPUT->box_start('generalbox boxaligncenter'); echo $txt->importfilearea . ' <table cellpadding="5"> <tr> <td align="right">' . $txt->file . ':</td> <td><input type="text" name="choosefile" size="60" /></td> </tr> <tr> <td> </td> <td> '; echo $OUTPUT->single_button("/files/index.php?id={$this->course->id}&choose=form.choosefile", $txt->choosefile); echo '<br /> <input type="submit" name="save" value="' . $txt->importfromthisfile . '" /></td> </tr> </table> '; echo $OUTPUT->box_end(); echo ' <input type="hidden" name="action" value="' . $action . '" /> <input type="hidden" name="name_instance" value="' . $this->referentiel->name . '" /> <input type="hidden" name="description_instance" value="' . htmlentities($this->referentiel->description_instance, ENT_QUOTES, 'UTF-8') . '" /> <input type="hidden" name="label_domaine" value="' . $this->referentiel->label_domaine . '" /> <input type="hidden" name="label_competence" value="' . $this->referentiel->label_competence . '" /> <input type="hidden" name="label_item" value="' . $this->referentiel->label_item . '" /> <!-- These hidden variables are always the same --> <input type="hidden" name="sesskey" value="' . sesskey() . '" /> <input type="hidden" name="courseid" value="' . $this->course->id . '" /> <input type="hidden" name="instance" value="' . $this->referentiel->id . '" /> <input type="hidden" name="mode" value="' . $mode . '" /> </fieldset> </form>' . "\n"; $this->view_footer(); die; }