commit 31c6fbc080a89099be35a78f4c8f69571c114aaf Author: Victor Cabral <87657291+victordscabral@users.noreply.github.com> Date: Thu Dec 7 09:06:44 2023 -0300 Adicionando arquivos da versão antiga diff --git a/CHANGES.MD b/CHANGES.MD new file mode 100644 index 0000000..e69de29 diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..c304116 --- /dev/null +++ b/README.txt @@ -0,0 +1,29 @@ +moodle_local_mass_enroll +======================== + +A Moodle 2.x tool for all teachers to enrol/unenrol existing users to their courses using CSV files (without bothering their admins) + +Main features are : + +* users can be specified by username, id number or email +* users can be optionally enroled to groups/groupings (autocreated if needed) +* email reports can be send +* import can be repeated if some users are to be in several groups +* usage can be restricted by modifying specific capabilities (local/mass_enroll:enrol and local:/mass_enroll:unenrol) +* can be inserted in Course's admin menu + +This plugin has been tested from Moodle 2.7 onwards and is a continuation of +Patrick Pollet's initial work. + +See the wiki page https://github.com/rogiervandongen/moodle-local_mass_enroll/wiki for installation and usage. + +IMPORTANT MESSAGE: +Out of respect for Patrick and his family, and out of common courtesy, I have +removed Patrick Pollet's personal contact information from the source code, since +Patrick passed away on the 26th of January, 2015. +The initial copyright has been left intact, and was added to all source files +where it wasn't present. +I, and many Moodle users with me, have been greatful for his work on this plugin +and I'm happy to continue his excellent work where Patrick unfortunately couldn't. +Patrick's original work should still be available on github: +https://github.com/patrickpollet/moodle_local_mass_enroll diff --git a/classes/event/mass_enrolment_created.php b/classes/event/mass_enrolment_created.php new file mode 100644 index 0000000..2f73762 --- /dev/null +++ b/classes/event/mass_enrolment_created.php @@ -0,0 +1,134 @@ +. + +/** + * The mass_enrolment_created event. + * + * File mass_enrolment_created.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_mass_enroll\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * The mass_enrolment_created event class. + * + * @property-read array $other { + * Extra information about event. + * + * - PUT INFO HERE + * } + * + * @since Moodle 2.7 + * + * @package local_mass_enroll + * + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + **/ +class mass_enrolment_created extends \core\event\base { + + /** + * Override in subclass. + * + * Set all required data properties: + * 1/ crud - letter [crud] + * 2/ edulevel - using a constant self::LEVEL_*. + * 3/ objecttable - name of database table if objectid specified + * + * Optionally it can set: + * a/ fixed system context + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'c'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = 'course'; + } + + /** + * Returns localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('event:massenrolcreated', 'local_mass_enroll'); + } + + /** + * Returns non-localised event description with id's for admin use only. + * + * @return string + */ + public function get_description() { + return "The user with id {$this->userid} created a mass enrolment in the course with id {$this->objectid}."; + } + + /** + * Returns relevant URL. + * + * @return \moodle_url + */ + public function get_url() { + global $CFG; + return new \moodle_url($CFG->wwwroot . '/local/mass_enroll/mass_enroll.php', array('id' => $this->courseid)); + } + + /** + * Return legacy logdata. + * + * @return null|array of parameters to be passed to legacy add_to_log() function. + */ + public function get_legacy_logdata() { + // Override if you are migrating an add_to_log() call. + // Path must be relative to 'module name', here 'course'. + // Rev 12/11/2014 : some core function (get_recent_enrolments()) expect the + // info field of log record to be integer when action field is 'enrol'. + // This produced fatal SQL errors with PostGres see https://github.com/patrickpollet/moodle_local_mass_enroll/issues/5 + // so we changed action value from 'enrol' to 'massenrol'. + return array($this->courseid, 'course', 'massenroll', + '../local/mass_enroll/mass_enroll.php?id=' . $this->courseid, + $this->other['info']); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (empty($this->courseid)) { + throw new \coding_exception('The \'courseid\' must be set.'); + } + + if (!isset($this->other['info'])) { + throw new \coding_exception('The \'info\' field must be set in \'other\'.'); + } + } + +} \ No newline at end of file diff --git a/classes/event/mass_unenrolment_created.php b/classes/event/mass_unenrolment_created.php new file mode 100644 index 0000000..6e929ee --- /dev/null +++ b/classes/event/mass_unenrolment_created.php @@ -0,0 +1,134 @@ +. + +/** + * The mass_unenrolment_created event. + * + * File mass_unenrolment_created.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_mass_enroll\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * The mass_unenrolment_created event class. + * + * @property-read array $other { + * Extra information about event. + * + * - PUT INFO HERE + * } + * + * @since Moodle 2.7 + * + * @package local_mass_enroll + * + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + **/ +class mass_unenrolment_created extends \core\event\base { + + /** + * Override in subclass. + * + * Set all required data properties: + * 1/ crud - letter [crud] + * 2/ edulevel - using a constant self::LEVEL_*. + * 3/ objecttable - name of database table if objectid specified + * + * Optionally it can set: + * a/ fixed system context + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'c'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = 'course'; + } + + /** + * Returns localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('event:massunenrolcreated', 'local_mass_enroll'); + } + + /** + * Returns non-localised event description with id's for admin use only. + * + * @return string + */ + public function get_description() { + return "The user with id {$this->userid} performed a mass unenrolment in the course with id {$this->objectid}."; + } + + /** + * Returns relevant URL. + * + * @return \moodle_url + */ + public function get_url() { + global $CFG; + return new \moodle_url($CFG->wwwroot . '/local/mass_enroll/mass_unenroll.php', array('id' => $this->courseid)); + } + + /** + * Return legacy logdata. + * + * @return null|array of parameters to be passed to legacy add_to_log() function. + */ + public function get_legacy_logdata() { + // Override if you are migrating an add_to_log() call. + // Path must be relative to 'module name', here 'course'. + // Rev 12/11/2014 : some core function (get_recent_enrolments()) expect the + // info field of log record to be integer when action field is 'enrol'. + // This produced fatal SQL errors with PostGres see https://github.com/patrickpollet/moodle_local_mass_enroll/issues/5 + // so we changed action value from 'unenrol' to 'massunenrol'. + return array($this->courseid, 'course', 'massunenroll', + '../local/mass_enroll/mass_enroll.php?id=' . $this->courseid, + $this->other['info']); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (empty($this->courseid)) { + throw new \coding_exception('The \'courseid\' must be set.'); + } + + if (!isset($this->other['info'])) { + throw new \coding_exception('The \'info\' field must be set in \'other\'.'); + } + } + +} \ No newline at end of file diff --git a/db/access.php b/db/access.php new file mode 100644 index 0000000..3c97551 --- /dev/null +++ b/db/access.php @@ -0,0 +1,55 @@ +. + +/** + * Capability definitions for the mass enrol local plugin. + * + * For naming conventions, see lib/db/access.php. + * + * File mass_enroll.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +defined('MOODLE_INTERNAL') || die(); + +$capabilities = array( + 'local/mass_enroll:enrol' => array( + 'riskbitmask' => RISK_XSS, + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ), + 'clonepermissionsfrom' => 'moodle/role:assign' + ), + // Not given by default to editingteacher ( life is tough). + 'local/mass_enroll:unenrol' => array( + 'riskbitmask' => RISK_XSS | RISK_DATALOSS, + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'manager' => CAP_ALLOW + ), + 'clonepermissionsfrom' => 'moodle/role:assign' + ), +); diff --git a/lang/de/local_mass_enroll.php b/lang/de/local_mass_enroll.php new file mode 100644 index 0000000..25c1eea --- /dev/null +++ b/lang/de/local_mass_enroll.php @@ -0,0 +1,202 @@ +. + +/** + * Language file for local_mass_enroll, DE + * + * German translation courtesy of Björn Fisseler + * + * File local_mass_enroll.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +$string['pluginname'] = 'Mass enrolments'; + +// Capabilities name required Moodle 2.3. +$string['mass_enroll:enrol'] = 'Einschreiben von Nutzer/innen in einen Kurs per CSV-Datei'; +$string['mass_enroll:unenrol'] = 'Austragen von Nutzer/innen aus einem Kurs per CSV-Datei'; +$string['mass_enroll'] = 'Massen-Einschreibung'; +$string['mass_unenroll'] = 'Massen-Austragung'; + +$string['mass_enroll_info'] = ' +

Mit dieser Option schreiben Sie eine Liste mit bekannten Nutzer/innen ein. Verwenden Sie dazu eine Datei mit einem Nutzerkonto pro Zeile.

+

Die erste Zeile, leere Zeilen oder unbekannte Konten werden übersprungen.

+

Die Datei darf eine oder zwei Spalten enthalten, die durch ein Komma, Semikolon oder Tab voneinander getrennt sind.
+Die erste Spalte muss eine eindeutige Kontenbezeichnung enthalten: ID-Nummer (voreingestellt), Anmeldename oder Email des einzutragenden Nutzerkontos.

+

Die zweite Spalte,sofern vorhanden, enthält den Gruppennamen der Gruppe, zu der das Nutzerkonto hinzugefügt werden soll.

+

Diese Aktion kann beliebig oft wiederholt werden, wenn beispielsweise der Gruppenname vergessen oder falsch angegeben wurde.

+'; + +$string['mass_unenroll_info'] = ' +

Mit dieser Option tragen Sie eine Liste mit bekannten Nutzer/innen aus. Verwenden Sie dazu eine Datei mit einem Nutzerkonto pro Zeile.

+

Die erste Zeile, leere Zeilen oder unbekannte Konten werden übersprungen.

+

Die Datei darf eine oder zwei Spalten enthalten, die durch ein Komma, Semikolon oder Tab voneinander getrennt sind. +Die erste Spalte muss eine eindeutige Kontenbezeichnung enthalten: ID-Nummer (voreingestellt), Anmeldename oder Email des auszutragenden Nutzerkontos.

+

Andere Spalten, sofern vorhanden, werden ignoriert. Daher kann die zur Einschreibung genutzte CSV-Datei auch für die Austragung verwendet werden. +

+'; + +$string['enroll'] = 'In meinen Kurs einschreiben'; +$string['unenroll'] = 'Aus meinem Kurs austragen'; + +$string['mailreport'] = 'Mail-Report schicken'; +$string['creategroups'] = 'Bei Bedarf Gruppe(n) erstellen'; +$string['creategroupings'] = 'Bei Bedarf Gruppierung(en) erstellen'; +$string['firstcolumn'] = 'Erste Spalte enthält'; +$string['roleassign'] = 'Zuzuweisende Rolle'; +$string['idnumber'] = 'ID-Nummer'; +$string['username'] = 'Login'; +$string['mail_enrolment_subject'] = 'Massen-Einschreibung in {$a}'; +$string['mail_unenrolment_subject'] = 'Massen-Austragung in {$a}'; + +$string['mail_enrolment'] = ' +Guten Tag, +Sie haben gerade folgende Nutzerinnen und Nutzer in Ihren Kurs \'{$a->course}\' eingeschrieben. +Hier ist ein Bericht der Aktionen : +{$a->report} +Mit freundlichen Grüßen. +'; +$string['mail_unenrolment'] = ' +Guten Tag, +Sie haben gerade folgende Nutzerinnen und Nutzer aus Ihrem Kurs \'{$a->course}\' ausgetragen. +Hier ist ein Bericht der Aktionen : +{$a->report} +Mit freundlichen Grüßen. +'; + +$string['im:using_role'] = 'Nutzer/in eingeschrieben als: {$a} '; +$string['im:not_in'] = '{$a} NICHT eingeschrieben '; +$string['im:unenrolled_ok'] = '{$a} ausgetragen '; +$string['im:error_out'] = 'Fehler beim austragen von {$a}'; +$string['email_sent'] = 'Email geschickt an {$a}'; +$string['im:opening_file'] = 'Öffne Datei: {$a} '; +$string['im:user_unknown'] = '{$a} unbekannt - Überspringe Zeile'; +$string['im:already_in'] = '{$a} bereits eingeschrieben '; +$string['im:enrolled_ok'] = '{$a} eingeschrieben '; +$string['im:error_in'] = 'Fehler bei Einschreibung von {$a}'; +$string['im:error_addg'] = 'Fehler beim Hinzufügen von Gruppe {$a->groupe} zu Kurs {$a->courseid} '; +$string['im:error_g_unknown'] = 'Fehler - unbekannte Gruppe {$a} '; +$string['im:error_add_grp'] = 'Fehler beim Hinzufügen von Gruppierung {$a->groupe} zu Kurs {$a->courseid}'; +$string['im:error_add_g_grp'] = 'Fehler beim Hinzufügen von Gruppe {$a->groupe} zu Gruppierung {$a->groupe}'; +$string['im:and_added_g'] = ' und zur Moodle-Gruppe {$a} hinzugefügt'; +$string['im:error_adding_u_g'] = 'Fehler beim Hinzufügen zu Gruppe {$a}'; +$string['im:already_in_g'] = ' bereits in Gruppe {$a}'; +$string['im:stats_i'] = '{$a} eingeschrieben'; +$string['im:stats_g'] = '{$a->nb} Gruppe(n) erstellt: {$a->what}'; +$string['im:stats_grp'] = '{$a->nb} Gruppierungen erstellt: {$a->what}'; +$string['im:err_opening_file'] = 'Fehler beim Öffnen von Datei {$a}'; +$string['im:stats_ui'] = '{$a} ausgetragen'; + +$string['mass_enroll_help'] = ' +

Masseneinschreibung

+ +

Mit dieser Option schreiben Sie eine Liste mit bekannten Nutzerinnen und Nutzern ein. Verwenden Sie dazu eine Datei mit einem Nutzerkonto pro Zeile.

+

Die erste Zeile, leere Zeilen oder unbekannte Konten werden übersprungen.

+

Die Datei darf eine oder zwei Spalten enthalten, die durch ein Komma, Semikolon oder Tab voneinander getrennt sind.
+Sie sollten die Datei mit einer Tabellenkalkulation auf Grundlage offizieller Teilnehmendenlisten erstellen und dann bei Bedarf eine Spalte mit den Gruppen hinzufügen, zu denen die Teilnehmenden zugewiesen werden sollen. Speichern Sie die Datei abschlie�end als CSV.(*)

+ +

Die erste Spalte muss eine eindeutige Kontenbezeichnung enthalten: ID-Nummer (voreingestellt), Anmeldename oder Email des einzutragenden Nutzerkontos.(**)

+

Die zweite Spalte,sofern vorhanden, enthält den Gruppennamen der Gruppe, zu der das Nutzerkonto hinzugefügt werden soll.

+ +

Wenn die Gruppe nicht existiert, wird sie in dem Kurs erstellt, gemeinsam mit einer Gruppierung mit demselben Namen, zu dem die Gruppe hinzugefügt wird.
+Das geschieht deshalb, weil Moodle Aktivitäten auf Gruppierungen (Gruppen von Gruppen) beschränkt werden können, nicht aber auf Gruppen. Deshalb wird dieses Vorgehen Ihr Leben leichter machen. Allerdings müssen Gruppierungen vom Admin freigegeben sein.

+ +

In der gleichen CSV-Datei können verschiedene Gruppen verwendet werden oder auch Nutzerkonten ohne Gruppenzuweisung genutzt werden.

+ +

Sie können die entsprechenden Optionen auch deaktivieren, wenn Sie sicher sind, dass die Gruppen und Gruppierungen schon vorhanden sind.

+ +

�blicherweise werden die Nutzer/innen als Studierende eingeschrieben, aber Sie können auch andere Rollen auswählen, wenn Sie die dafür erforderlichen Rechte besitzen.

+ +

Diese Aktion kann beliebig oft wiederholt werden, wenn beispielsweise der Gruppenname vergessen oder falsch angegeben wurde.

+ +

Beispieldatei

+ +

ID-Nummern und eine Gruppen, die bei Bedarf im Kurs erstellt wird(*)

+
+"idnumber";"group"
+" 2513110";" 4GEN"
+" 2512334";" 4GEN"
+" 2314149";" 4GEN"
+" 2514854";" 4GEN"
+" 2734431";" 4GEN"
+" 2514934";" 4GEN"
+" 2631955";" 4GEN"
+" 2512459";" 4GEN"
+" 2510841";" 4GEN"
+
+ +

Nur ID-Nummern (**)

+
+idnumber
+2513110
+2512334
+2314149
+2514854
+2734431
+2514934
+2631955
+
+ +

Nur Email-Adressen(**)

+
+email
+toto@insa-lyon.fr
+titi@]insa-lyon.fr
+tutu@insa-lyon.fr
+
+ +

Kontobezeichnungen und Gruppen, durch Tabulatoren getrennt:

+ +
+username	 group
+ppollet      groupe_de_test              wird in die Gruppe eingetragen
+codet        groupe_de_test              ebenso
+astorck      autre_groupe                wird in eine andere Gruppe eingetragen
+yjayet                                   keine Gruppe für dieses Konto
+                                         leere Zeile wird übersprungen
+unknown                                  unbekanntes Konto wird ignoriert
+
+ +

(*) : doppelte Anführungszeichen und Leerzeichen werden entfernt.

+ +

(**) : Die Nutzerkonten müssen in Moodle vorhanden sein. Das ist normalerweise der Fall, wenn Moodle mit einem externen Verzeichnis (LDAP, ...) synchronisiert wird.

+ + +'; + +$string['mass_unenroll_help'] = ' +

Massen-Austragung

+ +

Mit dieser Option tragen Sie eine Liste mit bekannten Nutzer/innen aus Ihrem Kurs aus. Verwenden Sie dazu eine Datei mit einem Nutzerkonto pro Zeile.

+

Die erste Zeile, leere Zeilen oder unbekannte Konten werden übersprungen.

+

Die Datei darf eine oder zwei Spalten enthalten, die durch ein Komma, Semikolon oder Tab voneinander getrennt sind.
+Sie sollten die Datei mit einer Tabellenkalkulation auf Grundlage offizieller Teilnehmendenlisten erstellen und dann bei Bedarf eine Spalte mit den Gruppen hinzufügen, zu denen die Teilnehmenden zugewiesen werden sollen. Speichern Sie die Datei abschlie�end als CSV.(*)

+ +

Die erste Spalte muss eine eindeutige Kontenbezeichnung enthalten: ID-Nummer (voreingestellt), Anmeldename oder Email des einzutragenden Nutzerkontos.(**)

+

Die zweite Spalte,sofern vorhanden, wird ignoriert.

+ +

Diese Aktion kann beliebig oft wiederholt werden, wenn beispielsweise der Gruppenname vergessen oder falsch angegeben wurde.

+

(*) : doppelte Anführungszeichen und Leerzeichen werden entfernt.

+ +

(**) : Die Nutzerkonten müssen in Moodle vorhanden sein. Das ist normalerweise der Fall, wenn Moodle mit einem externen Verzeichnis (LDAP, ...) synchronisiert wird.

+ +'; \ No newline at end of file diff --git a/lang/en/local_mass_enroll.php b/lang/en/local_mass_enroll.php new file mode 100644 index 0000000..e17e085 --- /dev/null +++ b/lang/en/local_mass_enroll.php @@ -0,0 +1,276 @@ +. + +/** + * Language file for local_mass_enroll, EN + * + * File local_mass_enroll.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +$string['pluginname'] = 'Mass enrolments'; + +// Capabilities name required Moodle 2.3. +$string['mass_enroll:enrol'] = 'Enrol users to a course by CSV file'; +$string['mass_enroll:unenrol'] = 'Unenrol users from a course by CSV file'; + +$string['mass_enroll'] = 'Bulk enrolments'; +$string['mass_unenroll'] = 'Bulk unenrolments'; +$string['mass_enroll_info'] = ' +

+With this option you are going to enrol a list of known users from a file with one account per line +

+

+ The firstline the empty lines or unknown accounts will be skipped.

+

+The file may contains several columns, separated by a comma, a semi-column or a tabulation. +
+The first one must contains a unique account identifier : idnumber (by default) login or email of the target user.
+ +The second if present, contains the group name in wich you want that user be be added.
+ +You may repeat this operation at will without damages, for example if you forgot the group for some users. +

+'; + +$string['mass_unenroll_info'] = ' +

+With this option you are going to unenrol a list on users from a file with one account per line. +

+

+ The firstline the empty lines or unknown accounts will be skipped.

+

+

+The file may contains several columns, separated by a comma, a semi-column or a tabulation. +
+The first one must contains a unique account identifier : idnumber (by default) login or email of the target user.
+ +Other columns, if present, will be ignored. Thus the file can be the same as the one user to mass enrol users into this course.
+ +You may repeat this operation at will without damages, for example if you forgot some users to unenroll. +

+'; + +$string['enroll'] = 'Enrol them to my course'; +$string['unenroll'] = 'Unenrol them from my course'; + +$string['mailreport'] = 'Send me a mail report'; +$string['creategroups'] = 'Create group(s) if needed'; +$string['creategroupings'] = 'Create grouping(s) if needed'; +$string['firstcolumn'] = 'First column contains'; +$string['roleassign'] = 'Role to assign'; +$string['idnumber'] = 'Id number'; +$string['username'] = 'Login'; +$string['mail_enrolment_subject'] = 'Bulk enrolments on {$a}'; +$string['mail_unenrolment_subject'] = 'Bulk unenrolments on {$a}'; +$string['mail_enrolment'] = ' +Hello, +You just enroled the following list of users to your course \'{$a->course}\'. +Here is a report of operations : +{$a->report} +Sincerly. +'; +$string['mail_unenrolment'] = ' +Hello, +You just unenroled the following list of users to your course \'{$a->course}\'. +Here is a report of operations : +{$a->report} +Sincerly. +'; +$string['email_sent'] = 'email sent to {$a}'; +$string['im:using_role'] = 'Enroling users as : {$a} '; +$string['im:opening_file'] = 'Opening file : {$a} '; +$string['im:user_unknown'] = '{$a} unknown - skipping line'; +$string['im:already_in'] = '{$a} already enroled '; +$string['im:enrolled_ok'] = '{$a} enroled '; +$string['im:error_in'] = 'error enroling {$a}'; +$string['im:not_in'] = '{$a} NOT enroled '; +$string['im:unenrolled_ok'] = '{$a} unenroled '; +$string['im:error_out'] = 'error unenroling {$a}'; + +$string['im:error_addg'] = 'error adding group {$a->groupe} to course {$a->courseid} '; +$string['im:error_g_unknown'] = 'error unkown group {$a} '; +$string['im:error_add_grp'] = 'error adding grouping {$a->groupe} to course {$a->courseid}'; +$string['im:error_add_g_grp'] = 'error adding group {$a->groupe} to grouping {$a->groupe}'; +$string['im:and_added_g'] = ' and added to Moodle\'s group {$a}'; +$string['im:error_adding_u_g'] = 'error adding to group {$a}'; +$string['im:already_in_g'] = ' already in group {$a}'; +$string['im:stats_i'] = '{$a} enroled'; +$string['im:stats_ui'] = '{$a} unenroled'; +$string['im:stats_g'] = '{$a->nb} group(s) created : {$a->what}'; +$string['im:stats_grp'] = '{$a->nb} grouping(s) created : {$a->what}'; +$string['im:err_opening_file'] = 'error opening file {$a}'; + +$string['mass_enroll_help'] = ' +

Bulk enrolments

+ +

+With this option you are going to enrol a list of known users from a file with one account per line +

+

+ The firstline the empty lines or unknown accounts will be skipped.

+ +

+The file may contains one or two columns, separated by a comma, a semi-column or a tabulation. + +You should prepare it from your usual spreadsheet program from official lists of students, for example, +and add if needed a column with groups to which you want these users to be added. Finally export it as CSV. (*)

+ +

+ The first one must contains a unique account identifier : idnumber (by default) login or email of the target user. (**).

+ +

+The second if present, contains the group name in wich you want that user to be added.

+ +

+If the group name does not exist, it will be created in your course, together with a grouping of the same name to which the group will be added. +.
+This is due to the fact that in Moodle, activities can be restricted to groupings (group of groups), not groups, + so it will make your life easier. (this requires that groupings are enabled by your site administrator). + +

+You may have in the same file different target groups or no groups for some accounts +

+ +

+You may unselect options to create groups and groupings if you are sure that they already exist in the course. +

+ +

+By default the users will be enroled as students but you may select other roles that you are allowed to manage (teacher, non editing teacher +or any custom roles) +

+ +

+You may repeat this operation at will without dammages, for example if you forgot or mispelled the target group. +

+ + +

Sample files

+ +Id numbers and a group name to be created in needed in the course (*) +
+"idnumber";"group"
+" 2513110";" 4GEN"
+" 2512334";" 4GEN"
+" 2314149";" 4GEN"
+" 2514854";" 4GEN"
+" 2734431";" 4GEN"
+" 2514934";" 4GEN"
+" 2631955";" 4GEN"
+" 2512459";" 4GEN"
+" 2510841";" 4GEN"
+
+ +only idnumbers (**) +
+idnumber
+2513110
+2512334
+2314149
+2514854
+2734431
+2514934
+2631955
+
+ +only emails (**) +
+email
+toto@insa-lyon.fr
+titi@]insa-lyon.fr
+tutu@insa-lyon.fr
+
+ +usernames and groups, separated by a tab : + +
+username	 group
+ppollet      groupe_de_test              will be in that group
+codet        groupe_de_test              also him
+astorck      autre_groupe                will be in another group
+yjayet                                   no group for this one
+                                         empty line skipped
+unknown                                  unknown account skipped
+
+ +

+(*) : double quotes and spaces, added by some spreadsheet programs will be removed. +

+ +

+(**) : target account must exist in Moodle ; this is normally the case if Moodle is synchronized with +some external directory (LDAP...) +

+'; + + +$string['mass_unenroll_help'] = ' +

Bulk unenrolments

+ +

+With this option you are going to unenrol a list of users from a file with one account per line +

+

+ The firstline the empty lines or unknown accounts will be skipped.

+ +

+The file may contains several columns, separated by a comma, a semi-column or a tabulation. + +You should prepare it from your usual spreadsheet program from an official lists of students, for example, +by exporting the course gradebook to CSV, or use the very same file as the one used to mass enrol users. (*)

+ +

+ The first one must contains a unique account identifier : idnumber (by default) login or email of the target user. (**).

+ +

+All other columns will be ignored.

+ + +

+By default the users will be enroled as students but you may select other roles that you are allowed to manage (teacher, non editing teacher +or any custom roles) +

+ +

+You may repeat this operation at will without dammages, for example if you forgot some users to unenrol. +

+ + + +

+(*) : double quotes and spaces, added by some spreadsheet programs will be removed. +

+ +

+(**) : target account must exist in Moodle and be enrolled to this course. +

+'; +$string['massenrollsettings'] = 'Mass enrol settings'; +$string['localmassenrolldefaults'] = 'Mass enrol default settings'; +$string['enablemassenrol'] = 'Allow mass enrolment from course administration'; +$string['enablemassenrol_help'] = 'Check this option to allow extension for mass enrolment in the course administration tree'; +$string['enablemassunenrol'] = 'Allow mass unenrolment from course administration'; +$string['enablemassunenrol_help'] = 'Check this option to allow extension for mass unenrolment in the course administration tree'; +$string['localmassenrollextensions'] = 'Menu extension settings'; +$string['mailreportdefault'] = 'Send reports default'; +$string['mailreportdefault_help'] = 'Configure the default setting for sending reports for the bulk (un)enrolment forms'; \ No newline at end of file diff --git a/lang/en_us/local_mass_enroll.php b/lang/en_us/local_mass_enroll.php new file mode 100644 index 0000000..ef384e8 --- /dev/null +++ b/lang/en_us/local_mass_enroll.php @@ -0,0 +1,276 @@ +. + +/** + * Language file for local_mass_enroll, EN-US + * + * File local_mass_enroll.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +$string['pluginname'] = 'Mass enrollments'; + +// Capabilities name required Moodle 2.3. +$string['mass_enroll:enrol'] = 'Enroll users to a course by CSV file'; +$string['mass_enroll:unenrol'] = 'Unenroll users from a course by CSV file'; + +$string['mass_enroll'] = 'Bulk enrollments'; +$string['mass_unenroll'] = 'Bulk unenrollments'; +$string['mass_enroll_info'] = ' +

+With this option you are going to enroll a list of known users from a file with one account per line +

+

+ The firstline the empty lines or unknown accounts will be skipped.

+

+The file may contains several columns, separated by a comma, a semi-column or a tabulation. +
+The first one must contains a unique account identifier : idnumber (by default) login or email of the target user.
+ +The second if present, contains the group name in wich you want that user be be added.
+ +You may repeat this operation at will without damages, for example if you forgot the group for some users. +

+'; + +$string['mass_unenroll_info'] = ' +

+With this option you are going to unenroll a list on users from a file with one account per line. +

+

+ The firstline the empty lines or unknown accounts will be skipped.

+

+

+The file may contains several columns, separated by a comma, a semi-column or a tabulation. +
+The first one must contains a unique account identifier : idnumber (by default) login or email of the target user.
+ +Other columns, if present, will be ignored. Thus the file can be the same as the one user to mass enroll users into this course.
+ +You may repeat this operation at will without damages, for example if you forgot some users to unenroll. +

+'; + +$string['enroll'] = 'Enroll them to my course'; +$string['unenroll'] = 'Unenroll them from my course'; + +$string['mailreport'] = 'Send me a mail report'; +$string['creategroups'] = 'Create group(s) if needed'; +$string['creategroupings'] = 'Create grouping(s) if needed'; +$string['firstcolumn'] = 'First column contains'; +$string['roleassign'] = 'Role to assign'; +$string['idnumber'] = 'Id number'; +$string['username'] = 'Login'; +$string['mail_enrolment_subject'] = 'Bulk enrollments on {$a}'; +$string['mail_unenrolment_subject'] = 'Bulk unenrollments on {$a}'; +$string['mail_enrolment'] = ' +Hello, +You just enrolled the following list of users to your course \'{$a->course}\'. +Here is a report of operations : +{$a->report} +Sincerly. +'; +$string['mail_unenrolment'] = ' +Hello, +You just unenrolled the following list of users to your course \'{$a->course}\'. +Here is a report of operations : +{$a->report} +Sincerly. +'; +$string['email_sent'] = 'email sent to {$a}'; +$string['im:using_role'] = 'Enrolling users as : {$a} '; +$string['im:opening_file'] = 'Opening file : {$a} '; +$string['im:user_unknown'] = '{$a} unknown - skipping line'; +$string['im:already_in'] = '{$a} already enrolled '; +$string['im:enrolled_ok'] = '{$a} enrolled '; +$string['im:error_in'] = 'error enrolling {$a}'; +$string['im:not_in'] = '{$a} NOT enrolled '; +$string['im:unenrolled_ok'] = '{$a} unenrolled '; +$string['im:error_out'] = 'error unenrolling {$a}'; + +$string['im:error_addg'] = 'error adding group {$a->groupe} to course {$a->courseid} '; +$string['im:error_g_unknown'] = 'error unkown group {$a} '; +$string['im:error_add_grp'] = 'error adding grouping {$a->groupe} to course {$a->courseid}'; +$string['im:error_add_g_grp'] = 'error adding group {$a->groupe} to grouping {$a->groupe}'; +$string['im:and_added_g'] = ' and added to Moodle\'s group {$a}'; +$string['im:error_adding_u_g'] = 'error adding to group {$a}'; +$string['im:already_in_g'] = ' already in group {$a}'; +$string['im:stats_i'] = '{$a} enrolled'; +$string['im:stats_ui'] = '{$a} unenrolled'; +$string['im:stats_g'] = '{$a->nb} group(s) created : {$a->what}'; +$string['im:stats_grp'] = '{$a->nb} grouping(s) created : {$a->what}'; +$string['im:err_opening_file'] = 'error opening file {$a}'; + +$string['mass_enroll_help'] = ' +

Bulk enrollments

+ +

+With this option you are going to enroll a list of known users from a file with one account per line +

+

+ The firstline the empty lines or unknown accounts will be skipped.

+ +

+The file may contains one or two columns, separated by a comma, a semi-column or a tabulation. + +You should prepare it from your usual spreadsheet program from official lists of students, for example, +and add if needed a column with groups to which you want these users to be added. Finally export it as CSV. (*)

+ +

+ The first one must contains a unique account identifier : idnumber (by default) login or email of the target user. (**).

+ +

+The second if present, contains the group name in wich you want that user to be added.

+ +

+If the group name does not exist, it will be created in your course, together with a grouping of the same name to which the group will be added. +.
+This is due to the fact that in Moodle, activities can be restricted to groupings (group of groups), not groups, + so it will make your life easier. (this requires that groupings are enabled by your site administrator). + +

+You may have in the same file different target groups or no groups for some accounts +

+ +

+You may unselect options to create groups and groupings if you are sure that they already exist in the course. +

+ +

+By default the users will be enrolled as students but you may select other roles that you are allowed to manage (teacher, non editing teacher +or any custom roles) +

+ +

+You may repeat this operation at will without dammages, for example if you forgot or mispelled the target group. +

+ + +

Sample files

+ +Id numbers and a group name to be created in needed in the course (*) +
+"idnumber";"group"
+" 2513110";" 4GEN"
+" 2512334";" 4GEN"
+" 2314149";" 4GEN"
+" 2514854";" 4GEN"
+" 2734431";" 4GEN"
+" 2514934";" 4GEN"
+" 2631955";" 4GEN"
+" 2512459";" 4GEN"
+" 2510841";" 4GEN"
+
+ +only idnumbers (**) +
+idnumber
+2513110
+2512334
+2314149
+2514854
+2734431
+2514934
+2631955
+
+ +only emails (**) +
+email
+toto@insa-lyon.fr
+titi@]insa-lyon.fr
+tutu@insa-lyon.fr
+
+ +usernames and groups, separated by a tab : + +
+username   group
+ppollet      groupe_de_test              will be in that group
+codet        groupe_de_test              also him
+astorck      autre_groupe                will be in another group
+yjayet                                   no group for this one
+                                         empty line skipped
+unknown                                  unknown account skipped
+
+ +

+(*) : double quotes and spaces, added by some spreadsheet programs will be removed. +

+ +

+(**) : target account must exist in Moodle ; this is normally the case if Moodle is synchronized with +some external directory (LDAP...) +

+'; + + +$string['mass_unenroll_help'] = ' +

Bulk unenrollments

+ +

+With this option you are going to unenroll a list of users from a file with one account per line +

+

+ The firstline the empty lines or unknown accounts will be skipped.

+ +

+The file may contains several columns, separated by a comma, a semi-column or a tabulation. + +You should prepare it from your usual spreadsheet program from an official lists of students, for example, +by exporting the course gradebook to CSV, or use the very same file as the one used to mass enroll users. (*)

+ +

+ The first one must contains a unique account identifier : idnumber (by default) login or email of the target user. (**).

+ +

+All other columns will be ignored.

+ + +

+By default the users will be enrolled as students but you may select other roles that you are allowed to manage (teacher, non editing teacher +or any custom roles) +

+ +

+You may repeat this operation at will without dammages, for example if you forgot some users to unenrol. +

+ + + +

+(*) : double quotes and spaces, added by some spreadsheet programs will be removed. +

+ +

+(**) : target account must exist in Moodle and be enrolled to this course. +

+'; +$string['massenrollsettings'] = 'Mass enrol settings'; +$string['localmassenrolldefaults'] = 'Mass enrol default settings'; +$string['enablemassenrol'] = 'Allow mass enrolment from course administration'; +$string['enablemassenrol_help'] = 'Check this option to allow extension for mass enrolment in the course administration tree'; +$string['enablemassunenrol'] = 'Allow mass unenrolment from course administration'; +$string['enablemassunenrol_help'] = 'Check this option to allow extension for mass unenrolment in the course administration tree'; +$string['localmassenrollextensions'] = 'Menu extension settings'; +$string['mailreportdefault'] = 'Send reports default'; +$string['mailreportdefault_help'] = 'Configure the default setting for sending reports for the bulk (un)enrolment forms'; \ No newline at end of file diff --git a/lang/fr/local_mass_enroll.php b/lang/fr/local_mass_enroll.php new file mode 100644 index 0000000..e76fc29 --- /dev/null +++ b/lang/fr/local_mass_enroll.php @@ -0,0 +1,256 @@ +. + +/** + * Language file for local_mass_enroll, EN + * + * File local_mass_enroll.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +$string['pluginname'] = 'Inscriptions massives'; + +// Capabilities name required Moodle 2.3. +$string['mass_enroll:enrol'] = 'Inscrire des utilisateurs à un cours par fichier CSV'; +$string['mass_enroll:unenrol'] = 'Désinscrire des utilisateurs d\' un cours par fichier CSV'; + + +$string['mass_enroll'] = 'Inscriptions massives'; +$string['mass_unenroll'] = 'Désinscriptions massives'; +$string['mass_enroll_info'] = ' +

+Avec cette option vous allez pouvoir inscrire massivement à votre cours une liste d\'utilisateurs existants dans Moodle +contenue dans un fichier que vous avez préparé, un compte par ligne +

+

+La premiere ligne , les lignes vides, ou celles contenant un identifiant de compte inconnu seront ignorées. +

+

+Ce fichier peut contenir une ou deux colonnes, séparées alors par une virgule, ou point-virgule ou une tabulation.
+La première doit contenir un identifiant unique : N° étudiant (idnumber Moodle), login ou email de l\'utilisateur concerné.
+La seconde, si elle est présente, indique le groupe (au sens de ce cours Moodle) ou vous voulez inscrire cet utilisateur.
+Vous pouvez répéter l\'opération plusieurs fois sans dommages, par exemple si vous avez oublié le groupe ou inscrire les utilisateurs. +

+'; + +$string['mass_unenroll_info'] = ' +

+Avec cette option vous allez pouvoir désinscrire massivement de votre cours une liste d\'utilisateurs déja inscrits à ce cours, contenue dans un fichier que vous avez préparé, un compte par ligne +

+

+La premiere ligne , les lignes vides, ou celles contenant un identifiant de compte inconnu seront ignorées. +

+

+Ce fichier peut contenir plusieurs colonnes, séparées alors par une virgule, ou point-virgule ou une tabulation.
+La première doit contenir un identifiant unique : N° étudiant (idnumber Moodle), login ou email de l\'utilisateur concerné.
+Les autres colonnes, si présente seront simplement ignorées. Ce fichier peut donc être le même que celui utilisé lors d\'une inscription massive.
+ +Vous pouvez répéter l\'opération plusieurs fois sans dommages, par exemple si vous avez oublié quelques utilisateurs. +

+'; +$string['enroll'] = 'Les inscrire à mon cours'; +$string['unenroll'] = 'Les désincrire de mon cours'; +$string['mailreport'] = 'M\'envoyer un rapport par mail'; +$string['creategroups'] = 'Créer le(s) groupe(s) si nécessaire'; +$string['creategroupings'] = 'Créer le(s) groupement(s) si nécessaire'; +$string['firstcolumn'] = 'La première colonne contient'; +$string['roleassign'] = 'Inscrire comme'; +$string['idnumber'] = 'Numéro d\'étudiant'; +$string['username'] = 'Login'; +$string['mail_enrolment_subject'] = 'Inscriptions massives sur {$a}'; +$string['mail_unenrolment_subject'] = 'Désinscriptions massives sur {$a}'; +$string['mail_enrolment'] = ' +Bonjour, +Vous venez d\'inscrire la liste d\'utilisateurs suivants à votre cours \'{$a->course}\'. +Voici un rapport des opérations : +{$a->report} +Cordialement. +'; +$string['mail_unenrolment'] = ' +Bonjour, +Vous venez de désinscrire la liste d\'utilisateurs suivants de votre cours \'{$a->course}\'. +Voici un rapport des opérations : +{$a->report} +Cordialement. +'; +$string['email_sent'] = 'email envoyé à {$a}'; +$string['im:using_role'] = 'Utilisateurs inscrits comme : {$a} '; +$string['im:user_unknown'] = '{$a} inconnu - ligne ignorée'; +$string['im:already_in'] = '{$a} DÉJA inscrit '; +$string['im:enrolled_ok'] = '{$a} inscrit '; +$string['im:error_in'] = 'erreur en inscrivant {$a}'; +$string['im:not_in'] = '{$a} PAS inscrit '; +$string['im:unenrolled_ok'] = '{$a} désinscrit '; +$string['im:error_out'] = 'erreur en désinscrivant {$a}'; + + +$string['im:error_addg'] = 'erreur en ajoutant le groupe {$a->groupe} au cours {$a->courseid} '; +$string['im:error_g_unknown'] = 'erreur groupe {$a} inconnu'; +$string['im:error_add_grp'] = 'erreur en ajoutant le groupement {$a->groupe} au cours {$a->courseid}'; +$string['im:error_add_g_grp'] = 'erreur en ajoutant le groupe {$a->groupe} au groupement {$a->groupe}'; +$string['im:and_added_g'] = ' et ajouté au groupe Moodle {$a}'; +$string['im:error_adding_u_g'] = 'impossible d\'ajouter au groupe {$a}'; +$string['im:already_in_g'] = ' DEJA dans le groupe {$a}'; +$string['im:stats_i'] = '{$a} inscrits'; +$string['im:stats_ui'] = '{$a} désinscrits'; +$string['im:stats_g'] = '{$a->nb} groupe(s) créé(s) : {$a->what}'; +$string['im:stats_grp'] = '{$a->nb} groupement(s) créé(s) : {$a->what}'; +$string['im:err_opening_file'] = 'ERREUR en ouvrant le fichier {$a}'; + +$string['mass_enroll_help'] = ' + +

Inscriptions massives

+ +

+Avec cette option vous allez pouvoir inscrire massivement à votre cours une liste d\'utilisateurs existants dans Moodle +contenue dans un fichier que vous avez préparé, un compte par ligne +

+

+La premiere ligne , les lignes vides, ou celles contenant un identifiant de compte inconnu seront ignorées. +

+ +

+Ce fichier peut contenir plusieurs colonnes, séparées alors par une virgule, ou point-virgule ou une tabulation. +Il peut être préparé à partir de vos listes de Scolarité par une simple remise en forme et un export CSV depuis votre tableur favori (*)

+ +

+La première colonne doit contenir un identifiant unique de l\'utilisateur concerné, par défaut son numéro interne (idnumber), +mais vous pouvez choisir aussi une liste d\'adresses email ou de logins (**).

+ +

+La seconde, si elle est présente, indique le groupe (au sens de ce cours Moodle) ou vous voulez inscrire cet étudiant.
+Si ce groupe n existe pas déja dans votre cours, il sera automatiquement créé, ainsi que le groupement homonyme correspondant.
+En effet sous Moodle vous pouvez restreindre toute activité à un groupement (un groupe de groupes) mais pas à un groupe.
+ +Il est tout à fait possible dans un même fichier d\'avoir des groupes différents (ou pas de groupes) dans certaines lignes.
+ + + +Vous pouvez décocher ces options de création automatique si le groupe/groupement visé existe déjé ; +

+ +

+Par défaut cette liste est censée contenir des étudiants à inscrire, mais vous pouvez aussi spécifier qu\'ils auront +le rôle enseignant ou enseignant non éditeur. +

+ +

+Vous pouvez répéter l\'opération plusieurs fois sans dommages, par exemple si vous avez oublié le groupe ou inscrire les étudiants +ou si vous l\'avez mal orthographié. +

+ +

Exemples de fichiers

+ +des numéros INSA et un groupe a créer si nécessaire dans le cours (*) +
+"numéro INSA";"groupe"
+" 2513110";" 4GEN"
+" 2512334";" 4GEN"
+" 2314149";" 4GEN"
+" 2514854";" 4GEN"
+" 2734431";" 4GEN"
+" 2514934";" 4GEN"
+" 2631955";" 4GEN"
+" 2512459";" 4GEN"
+" 2510841";" 4GEN"
+
+ +juste des numéros INSA (**) +
+numéro INSA
+2513110
+2512334
+2314149
+2514854
+2734431
+2514934
+2631955
+
+ +juste des emails (**) +
+email
+toto@insa-lyon.fr
+titi@]insa-lyon.fr
+tutu@insa-lyon.fr
+
+ +des logins et des groupes (separés içi par une tabulation) : + +
+login        groupe
+ppollet      groupe_de_test              sera dans ce groupe
+codet        groupe_de_test              lui aussi
+astorck      autre_groupe                et lui dans l\'autre groupe
+yjayet                                    n\'a pas de groupe proposé
+                                          ligne vide ignorée
+inconnu                                   existe pas ligne ignorée
+
+ +

+(*) : les éventuelles apostrophes ou espaces ajoutées lors de l\'export CSV depuis votre tableur favori seront écartés. +

+ +

+(**) : les comptes visés doivent exister dans Moodle, ce qui est normalement le cas après la synchronisation qui s\'effectue chaque nuit +avec l\'annuaire LDAP de l\'établissement. +

+'; + +$string['mass_unenroll_help'] = ' +

Désinscriptions massives

+ +

+Avec cette option vous allez pouvoir désinscrire massivement de votre cours une liste d\'utilisateurs existants dans Moodle +contenue dans un fichier que vous avez préparé, un compte par ligne. +

+ +

+La premiere ligne , les lignes vides, ou celles contenant un identifiant de compte inconnu ou non inscrit au cours seront ignorées. +

+

+Ce fichier peut contenir plusieurs colonnes, séparées alors par une virgule, ou point-virgule ou une tabulation. +Il peut être préparé à partir de vos listes de Scolarité ou par un export du carnet de notes du cours ou en utilisant +le même fichier que celui utilisé lors d\'une inscription massive. (*)

+ +

+La première colonne doit contenir un identifiant unique de l\'utilisateur concerné, par défaut son numéro interne (idnumber), +mais vous pouvez choisir aussi une liste d\'adresses email ou de logins (**).

+ +

+Toutes les autres colonnes seront ignorées.

+ + +

+Vous pouvez répéter l\'opération plusieurs fois sans dommages, par exemple si vous avez oublié quelques utilisateurs à désinscrire. +

+ + + +

+(*) : les éventuelles apostrophes ou espaces ajoutées lors de l\'export CSV depuis votre tableur favori seront écartés. +

+ +

+(**) : les comptes visés doivent exister dans Moodle et être inscrits à ce cours. +

+'; \ No newline at end of file diff --git a/lib.php b/lib.php new file mode 100644 index 0000000..382462c --- /dev/null +++ b/lib.php @@ -0,0 +1,391 @@ +. + +/** + * Code for handling mass enrolment from a cvs file + * + * File lib.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com} + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +defined('MOODLE_INTERNAL') || die(); + +/** + * Quick fix for Moodle 2.9 + * + * @param settings_navigation $navigation + * @param course_context $context + * @return void + */ +function local_mass_enroll_extend_settings_navigation(settings_navigation $navigation, $context) { + local_mass_enroll_extends_settings_navigation($navigation, $context); +} +/** + * Hook to insert a link in settings navigation menu block + * + * @param settings_navigation $navigation + * @param course_context $context + * @return void + */ +function local_mass_enroll_extends_settings_navigation(settings_navigation $navigation, $context) { + global $CFG; + // If not in a course context, then leave. + if ($context == null || $context->contextlevel != CONTEXT_COURSE) { + return; + } + + // Front page has a 'frontpagesettings' node, other courses will have 'courseadmin' node. + if (null == ($courseadminnode = $navigation->get('courseadmin'))) { + // Keeps us off the front page. + return; + } + if (null == ($useradminnode = $courseadminnode->get('users'))) { + return; + } + + $config = get_config('local_mass_enroll'); + if ((bool)$config->enablemassenrol) { + if (has_capability('local/mass_enroll:enrol', $context)) { + $url = new moodle_url($CFG->wwwroot . '/local/mass_enroll/mass_enroll.php', array('id' => $context->instanceid)); + $useradminnode->add(get_string('mass_enroll', 'local_mass_enroll'), $url, + navigation_node::TYPE_SETTING, null, 'massenrols', new pix_icon('i/admin', '')); + } + } + if ((bool)$config->enablemassunenrol) { + if (has_capability('local/mass_enroll:unenrol', $context)) { + $url = new moodle_url($CFG->wwwroot . '/local/mass_enroll/mass_unenroll.php', array('id' => $context->instanceid)); + $useradminnode->add(get_string('mass_unenroll', 'local_mass_enroll'), $url, + navigation_node::TYPE_SETTING, null, 'massunenrols', new pix_icon('i/admin', '')); + } + } +} + +/** + * process the mass enrolment + * + * @param csv_import_reader $cir an import reader created by caller + * @param stdClass $course a course record from table mdl_course + * @param stdClass $context course context instance + * @param stdClass $data data from a moodleform + * @return string log of operations + */ +function mass_enroll($cir, $course, $context, $data) { + global $CFG, $DB; + require_once($CFG->dirroot . '/group/lib.php'); + + $result = ''; + $roleid = $data->roleassign; + $useridfield = $data->firstcolumn; + + $enrollablecount = 0; + $createdgroupscount = 0; + $createdgroupingscount = 0; + $createdgroups = ''; + $createdgroupings = ''; + + $role = $DB->get_record('role', array('id' => $roleid)); + + $result .= get_string('im:using_role', 'local_mass_enroll', $role->name) . "\n"; + + $plugin = enrol_get_plugin('manual'); + // Moodle 2.x enrolment and role assignment are different. + // Assure course has manual enrolment plugin instance we are going to use. + // Only one instance is allowed; see enrol/manual/lib.php get_new_instance(). + $instance = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'manual')); + if (empty($instance)) { + // Only add an enrol instance to the course if non-existent. + $enrolid = $plugin->add_instance($course); + $instance = $DB->get_record('enrol', array('id' => $enrolid)); + } + + // Init csv import helper. + $cir->init(); + while ($fields = $cir->next()) { + $a = new stdClass(); + + if (empty($fields)) { + continue; + } + + // First column = id Moodle (idnumber,username or email). + // Get rid on eventual double quotes unfortunately not done by Moodle CSV importer. + $fields[0] = str_replace('"', '', trim($fields[0])); + + if (!$user = $DB->get_record('user', array($useridfield => $fields[0]))) { + $result .= get_string('im:user_unknown', 'local_mass_enroll', $fields[0]) . "\n"; + continue; + } + // Already enroled? + // We DO NOT support multiple roles in a course. + if ($ue = $DB->get_record('user_enrolments', array('enrolid' => $instance->id, 'userid' => $user->id))) { + $result .= get_string('im:already_in', 'local_mass_enroll', fullname($user)); + } else { + // Take care of timestart/timeend in course settings. + $timestart = time(); + // Remove time part from the timestamp and keep only the date part. + $timestart = make_timestamp(date('Y', $timestart), date('m', $timestart), date('d', $timestart), 0, 0, 0); + if ($instance->enrolperiod) { + $timeend = $timestart + $instance->enrolperiod; + } else { + $timeend = 0; + } + // Enrol the user with this plugin instance (unfortunately return void, no more status). + $plugin->enrol_user($instance, $user->id, $roleid, $timestart, $timeend); + $result .= get_string('im:enrolled_ok', 'local_mass_enroll', fullname($user)); + $enrollablecount++; + } + + $group = str_replace('"', '', trim($fields[1])); + // 2nd column? + if (empty($group)) { + $result .= "\n"; + continue; // No group for this one. + } + + // Create group if needed. + if (!($gid = mass_enroll_group_exists($group, $course->id))) { + if ($data->creategroups) { + if (!($gid = mass_enroll_add_group($group, $course->id))) { + $a->group = $group; + $a->courseid = $course->id; + $result .= get_string('im:error_addg', 'local_mass_enroll', $a) . "\n"; + continue; + } + $createdgroupscount++; + $createdgroups .= " $group"; + } else { + $result .= get_string('im:error_g_unknown', 'local_mass_enroll', $group) . "\n"; + continue; + } + } + + // If groupings are enabled on the site (should be?). + if (!($gpid = mass_enroll_grouping_exists($group, $course->id))) { + if ($data->creategroupings) { + if (!($gpid = mass_enroll_add_grouping($group, $course->id))) { + $a->group = $group; + $a->courseid = $course->id; + $result .= get_string('im:error_add_grp', 'local_mass_enroll', $a) . "\n"; + continue; + } + $createdgroupingscount++; + $createdgroupings .= " $group"; + } + } + // If grouping existed or has just been created. + if ($gpid && !(mass_enroll_group_in_grouping($gid, $gpid))) { + if (!(mass_enroll_add_group_grouping($gid, $gpid))) { + $a->group = $group; + $result .= get_string('im:error_add_g_grp', 'local_mass_enroll', $a) . "\n"; + continue; + } + } + + // Finally add to group if needed. + if (!groups_is_member($gid, $user->id)) { + $ok = groups_add_member($gid, $user->id); + if ($ok) { + $result .= get_string('im:and_added_g', 'local_mass_enroll', $group) . "\n"; + } else { + $result .= get_string('im:error_adding_u_g', 'local_mass_enroll', $group) . "\n"; + } + } else { + $result .= get_string('im:already_in_g', 'local_mass_enroll', $group) . "\n"; + } + } + + // Recap final. + $result .= get_string('im:stats_i', 'local_mass_enroll', $enrollablecount) . "\n"; + $a->nb = $createdgroupscount; + $a->what = $createdgroups; + $result .= get_string('im:stats_g', 'local_mass_enroll', $a) . "\n"; + $a->nb = $createdgroupingscount; + $a->what = $createdgroupings; + $result .= get_string('im:stats_grp', 'local_mass_enroll', $a) . "\n"; + + // Trigger event. + $event = \local_mass_enroll\event\mass_enrolment_created::create( + array( + 'objectid' => $course->id, + 'courseid' => $course->id, + 'context' => \context_course::instance($course->id), + 'other' => array('info' => get_string('mass_enroll', 'local_mass_enroll')) + ) + ); + $event->trigger(); + + return $result; +} + +/** + * process the mass unenrolment + * + * @param csv_import_reader $cir an import reader created by caller + * @param stdClass $course a course record from table mdl_course + * @param stdClass $context course context instance + * @param stdClass $data data from a moodleform + * @return string log of operations + */ +function mass_unenroll($cir, $course, $context, $data) { + global $DB; + $result = ''; + + $useridfield = $data->firstcolumn; + $unenrollablecount = 0; + + $plugin = enrol_get_plugin('manual'); + // Moodle 2.x enrolment and role assignment are different. + // Assure course has manual enrolment plugin instance we are going to use. + // Only one instance is allowed; see enrol/manual/lib.php get_new_instance(). + $instance = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'manual')); + if (empty($instance)) { + // Only add an enrol instance to the course if non-existent. + $enrolid = $plugin->add_instance($course); + $instance = $DB->get_record('enrol', array('id' => $enrolid)); + } + + // Init csv import helper. + $cir->init(); + while ($fields = $cir->next()) { + $a = new stdClass(); + + if (empty($fields)) { + continue; + } + + // First column = id Moodle (idnumber,username or email). + // Get rid on eventual double quotes unfortunately not done by Moodle CSV importer. + $fields[0] = str_replace('"', '', trim($fields[0])); + + if (!$user = $DB->get_record('user', array($useridfield => $fields[0]))) { + $result .= get_string('im:user_unknown', 'local_mass_enroll', $fields[0]) . "\n"; + continue; + } + // Already enroled? + if (!$ue = $DB->get_record('user_enrolments', array('enrolid' => $instance->id, 'userid' => $user->id))) { + // Weird, user not enrolled. + $result .= get_string('im:not_in', 'local_mass_enroll', fullname($user)) . "\n"; + } else { + // Enrol the user with this plugin instance (unfortunately return void, no more status). + $plugin->unenrol_user($instance, $user->id); + $result .= get_string('im:unenrolled_ok', 'local_mass_enroll', fullname($user)) . "\n"; + $unenrollablecount++; + } + } + + // Recap final. + $result .= get_string('im:stats_ui', 'local_mass_enroll', $unenrollablecount) . "\n"; + + // Trigger event. + $event = \local_mass_enroll\event\mass_unenrolment_created::create( + array( + 'objectid' => $course->id, + 'courseid' => $course->id, + 'context' => context_course::instance($course->id), + 'other' => array('info' => get_string('mass_unenroll', 'local_mass_enroll')) + ) + ); + $event->trigger(); + + return $result; +} + +/** + * Add a group + * + * @param string $newgroupname + * @param int $courseid + * @return int id Moodle id of inserted record + */ +function mass_enroll_add_group($newgroupname, $courseid) { + $newgroup = new stdClass(); + $newgroup->name = $newgroupname; + $newgroup->courseid = $courseid; + $newgroup->lang = current_language(); + return groups_create_group($newgroup); +} + +/** + * Add a grouping + * + * @param string $newgroupingname + * @param int $courseid + * @return int id Moodle id of inserted record + */ +function mass_enroll_add_grouping($newgroupingname, $courseid) { + $newgrouping = new stdClass(); + $newgrouping->name = $newgroupingname; + $newgrouping->courseid = $courseid; + return groups_create_grouping($newgrouping); +} + +/** + * Check if a group exists + * + * @param string $name group name + * @param int $courseid course + * @return string or false + */ +function mass_enroll_group_exists($name, $courseid) { + return groups_get_group_by_name($courseid, $name); +} + +/** + * Check if a grouping exists + * + * @param string $name group name + * @param int $courseid course + * @return string or false + */ +function mass_enroll_grouping_exists($name, $courseid) { + return groups_get_grouping_by_name($courseid, $name); +} + +/** + * Get a group in a grouping + * + * @param int $gid group ID + * @param int $gpid grouping ID + * @return mixed a fieldset object containing the first matching record or false + */ +function mass_enroll_group_in_grouping($gid, $gpid) { + global $DB; + $conditions = array('groupingid' => $gpid, 'groupid' => $gid); + return $DB->get_record('groupings_groups', $conditions, '*', IGNORE_MISSING); +} + +/** + * Add a grouping + * + * @param int $gid group ID + * @param int $gpid grouping ID + * @return bool|int true or new id + * @throws dml_exception A DML specific exception is thrown for any errors. + */ +function mass_enroll_add_group_grouping($gid, $gpid) { + global $DB; + $new = new stdClass(); + $new->groupid = $gid; + $new->groupingid = $gpid; + $new->timeadded = time(); + return $DB->insert_record('groupings_groups', $new); +} diff --git a/mass_enroll.php b/mass_enroll.php new file mode 100644 index 0000000..7f31135 --- /dev/null +++ b/mass_enroll.php @@ -0,0 +1,56 @@ +. + +/** + * A bulk enrolment plugin allowing teachers to enrol accounts to their courses, optionally adding every user to a group. + * + * Version for Moodle 1.9.x courtesy of Patrick POLLET & Valery FREMAUX France, February 2010 + * Version for Moodle 2.x by pp@patrickpollet.net March 2012 + * + * File mass_enroll.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com} + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require(dirname(dirname(dirname(__FILE__))) . '/config.php'); + +// Get params. +$id = required_param('id', PARAM_INT); +if (!$course = $DB->get_record('course', array('id' => $id))) { + error("Course is misconfigured"); +} + +// Security and access check. +require_course_login($course); +$context = context_course::instance($course->id); +require_capability('local/mass_enroll:enrol', $context); + +// Start making page. +$strinscriptions = get_string('mass_enroll', 'local_mass_enroll'); +$PAGE->set_pagelayout('incourse'); +$PAGE->set_url(new moodle_url($CFG->wwwroot . '/local/mass_enroll/mass_enroll.php', array('id' => $id))); +$PAGE->set_title($course->fullname . ': ' . $strinscriptions); +$PAGE->set_heading($course->fullname . ': ' . $strinscriptions); + +$renderer = $PAGE->get_renderer('local_mass_enroll'); +echo $renderer->page_mass_enrol(); +exit; \ No newline at end of file diff --git a/mass_enroll_form.php b/mass_enroll_form.php new file mode 100644 index 0000000..76b696a --- /dev/null +++ b/mass_enroll_form.php @@ -0,0 +1,117 @@ +. + +/** + * Bulk enrolment form + * + * File mass_enroll.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->libdir . '/formslib.php'); + +/** + * Bulk enrolment form + * + * @package local_mass_enroll + * + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class mass_enroll_form extends moodleform { + + /** + * Form definition + */ + public function definition() { + global $DB; + + $mform = & $this->_form; + $course = $this->_customdata['course']; + $context = $this->_customdata['context']; + $config = get_config('local_mass_enroll'); + + $mform->addElement('header', 'general', ''); // Fill in the data depending on page params. + // Later using set_data. + $mform->addElement('filepicker', 'attachment', get_string('location', 'enrol_flatfile')); + + $mform->addRule('attachment', null, 'required'); + + $choices = csv_import_reader::get_delimiter_list(); + $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices); + if (array_key_exists('cfg', $choices)) { + $mform->setDefault('delimiter_name', 'cfg'); + } else if (get_string('listsep', 'langconfig') == ';') { + $mform->setDefault('delimiter_name', 'semicolon'); + } else { + $mform->setDefault('delimiter_name', 'comma'); + } + + $choices = \core_text::get_encodings(); + $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices); + $mform->setDefault('encoding', 'UTF-8'); + + $roles = get_assignable_roles($context); + $mform->addElement('select', 'roleassign', get_string('roleassign', 'local_mass_enroll'), $roles); + $studentrole = $DB->get_record('role', array('archetype' => 'student')); + $mform->setDefault('roleassign', $studentrole->id); + + $ids = array( + 'idnumber' => get_string('idnumber', 'local_mass_enroll'), + 'username' => get_string('username', 'local_mass_enroll'), + 'email' => get_string('email') + ); + $mform->addElement('select', 'firstcolumn', get_string('firstcolumn', 'local_mass_enroll'), $ids); + $mform->setDefault('firstcolumn', 'idnumber'); + + $mform->addElement('selectyesno', 'creategroups', get_string('creategroups', 'local_mass_enroll')); + $mform->setDefault('creategroups', 1); + + $mform->addElement('selectyesno', 'creategroupings', get_string('creategroupings', 'local_mass_enroll')); + $mform->setDefault('creategroupings', 1); + + $mform->addElement('selectyesno', 'mailreport', get_string('mailreport', 'local_mass_enroll')); + $mform->setDefault('mailreport', (int)$config->mailreportdefault); + + // Buttons. + $this->add_action_buttons(true, get_string('enroll', 'local_mass_enroll')); + + $mform->addElement('hidden', 'id', $course->id); + $mform->setType('id', PARAM_INT); + } + + /** + * Form data validation + * + * @param \stdClass $data + * @param array $files + * @return array + */ + public function validation($data, $files) { + $errors = parent::validation($data, $files); + return $errors; + } + +} diff --git a/mass_unenroll.php b/mass_unenroll.php new file mode 100644 index 0000000..600169b --- /dev/null +++ b/mass_unenroll.php @@ -0,0 +1,53 @@ +. + +/** + * Mass unenrol + * + * File mass_unenroll.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com} + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require(dirname(dirname(dirname(__FILE__))) . '/config.php'); + +// Get params. +$id = required_param('id', PARAM_INT); +if (!$course = $DB->get_record('course', array('id' => $id))) { + error("Course is misconfigured"); +} + +// Security and access check. +require_course_login($course); +$context = context_course::instance($course->id); +require_capability('local/mass_enroll:unenrol', $context); + +// Start making page. +$strinscriptions = get_string('mass_unenroll', 'local_mass_enroll'); +$PAGE->set_pagelayout('incourse'); +$PAGE->set_url(new moodle_url($CFG->wwwroot . '/local/mass_enroll/mass_unenroll.php', array('id' => $id))); +$PAGE->set_title($course->fullname . ': ' . $strinscriptions); +$PAGE->set_heading($course->fullname . ': ' . $strinscriptions); + +$renderer = $PAGE->get_renderer('local_mass_enroll'); +echo $renderer->page_mass_unenrol(); +exit; \ No newline at end of file diff --git a/mass_unenroll_form.php b/mass_unenroll_form.php new file mode 100644 index 0000000..40233f5 --- /dev/null +++ b/mass_unenroll_form.php @@ -0,0 +1,103 @@ +. + +/** + * Bulk unenrolment form + * + * File mass_enroll.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->libdir . '/formslib.php'); + +/** + * Bulk unenrolment form + * + * @package local_mass_enroll + * + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class mass_unenroll_form extends moodleform { + + /** + * Form definition + */ + public function definition() { + $mform = & $this->_form; + $course = $this->_customdata['course']; + $config = get_config('local_mass_enroll'); + + $mform->addElement('header', 'general', ''); // Fill in the data depending on page params. + // Later using set_data. + $mform->addElement('filepicker', 'attachment', get_string('location', 'enrol_flatfile')); + + $mform->addRule('attachment', null, 'required'); + + $choices = csv_import_reader::get_delimiter_list(); + $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices); + if (array_key_exists('cfg', $choices)) { + $mform->setDefault('delimiter_name', 'cfg'); + } else if (get_string('listsep', 'langconfig') == ';') { + $mform->setDefault('delimiter_name', 'semicolon'); + } else { + $mform->setDefault('delimiter_name', 'comma'); + } + + $choices = \core_text::get_encodings(); + $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices); + $mform->setDefault('encoding', 'UTF-8'); + + $ids = array( + 'idnumber' => get_string('idnumber', 'local_mass_enroll'), + 'username' => get_string('username', 'local_mass_enroll'), + 'email' => get_string('email') + ); + $mform->addElement('select', 'firstcolumn', get_string('firstcolumn', 'local_mass_enroll'), $ids); + $mform->setDefault('firstcolumn', 'idnumber'); + + $mform->addElement('selectyesno', 'mailreport', get_string('mailreport', 'local_mass_enroll')); + $mform->setDefault('mailreport', (int)$config->mailreportdefault); + + // Buttons. + $this->add_action_buttons(true, get_string('unenroll', 'local_mass_enroll')); + + $mform->addElement('hidden', 'id', $course->id); + $mform->setType('id', PARAM_INT); + } + + /** + * Form data validation + * + * @param \stdClass $data + * @param array $files + * @return array + */ + public function validation($data, $files) { + $errors = parent::validation($data, $files); + return $errors; + } + +} diff --git a/pix/icon.gif b/pix/icon.gif new file mode 100644 index 0000000..d8a8c9f Binary files /dev/null and b/pix/icon.gif differ diff --git a/renderer.php b/renderer.php new file mode 100644 index 0000000..faf99fb --- /dev/null +++ b/renderer.php @@ -0,0 +1,210 @@ +. + +/** + * Renderer implementation for local_mass_enroll + * + * File renderer.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * local_mass_enroll_renderer + * + * @package local_mass_enroll + * + * @copyright Sebsoft.nl + * @author R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class local_mass_enroll_renderer extends \plugin_renderer_base { + + /** + * return content for mass enrolment page. + */ + public function page_mass_enrol() { + global $CFG, $USER; + require_once($CFG->libdir . '/csvlib.class.php'); + require_once($CFG->dirroot . '/local/mass_enroll/mass_enroll_form.php'); + require_once($CFG->dirroot . '/local/mass_enroll/lib.php'); + $course = $this->page->course; + $context = $this->page->context; + + $mform = new mass_enroll_form(new moodle_url($CFG->wwwroot . '/local/mass_enroll/mass_enroll.php'), array( + 'course' => $course, + 'context' => $context + )); + + $currenttab = 'mass_enroll'; + $out = ''; + $strinscriptions = get_string('mass_enroll', 'local_mass_enroll'); + if ($mform->is_cancelled()) { + redirect(new moodle_url('/course/view.php', array('id' => $course->id))); + } else if ($data = $mform->get_data(false)) { + + $content = $mform->get_file_content('attachment'); + + $iid = csv_import_reader::get_new_iid('uploaduser'); + $cir = new csv_import_reader($iid, 'uploaduser'); + $readcount = $cir->load_csv_content($content, $data->encoding, $data->delimiter_name); + unset($content); + + $returnurl = $this->page->url; + if ($readcount === false) { + print_error('csvloaderror', '', $returnurl); + } else if ($readcount == 0) { + print_error('csvemptyfile', 'error', $returnurl); + } + + $result = mass_enroll($cir, $course, $context, $data); + + $cir->close(); + $cir->cleanup(false); // Only currently uploaded CSV file. + + if ($data->mailreport) { + $a = new stdClass(); + $a->course = $course->fullname; + $a->report = $result; + email_to_user($USER, $USER, get_string('mail_enrolment_subject', 'local_mass_enroll', $CFG->wwwroot), + get_string('mail_enrolment', 'local_mass_enroll', $a)); + $result .= "\n" . get_string('email_sent', 'local_mass_enroll', $USER->email); + } + + $out .= $this->header(); + $out .= $this->get_tabs($context, $currenttab, array('id' => $course->id)); + $out .= $this->heading($strinscriptions); + $out .= $this->box(nl2br($result), 'center'); + $out .= $this->continue_button($this->page->url); // Back to this page. + $out .= $this->footer($course); + return $out; + } + + $out .= $this->header(); + $out .= $this->get_tabs($context, $currenttab, array('id' => $course->id)); + $out .= $this->heading_with_help($strinscriptions, 'mass_enroll', 'local_mass_enroll', + 'icon', get_string('mass_enroll', 'local_mass_enroll')); + $out .= $this->box(get_string('mass_enroll_info', 'local_mass_enroll'), 'center'); + $out .= $mform->render(); + $out .= $this->footer($course); + + return $out; + } + + /** + * return content for mass unenrolment page. + */ + public function page_mass_unenrol() { + global $CFG, $USER; + require_once($CFG->libdir . '/csvlib.class.php'); + require_once($CFG->dirroot . '/local/mass_enroll/mass_unenroll_form.php'); + require_once($CFG->dirroot . '/local/mass_enroll/lib.php'); + $course = $this->page->course; + $context = $this->page->context; + + $mform = new mass_unenroll_form(new moodle_url($CFG->wwwroot . '/local/mass_enroll/mass_unenroll.php'), array( + 'course' => $course, + 'context' => $context + )); + + $currenttab = 'mass_unenroll'; + $out = ''; + $strinscriptions = get_string('mass_unenroll', 'local_mass_enroll'); + if ($mform->is_cancelled()) { + redirect(new moodle_url('/course/view.php', array('id' => $course->id))); + } else if ($data = $mform->get_data(false)) { + + $content = $mform->get_file_content('attachment'); + + $iid = csv_import_reader::get_new_iid('uploaduser'); + $cir = new csv_import_reader($iid, 'uploaduser'); + $readcount = $cir->load_csv_content($content, $data->encoding, $data->delimiter_name); + unset($content); + + $returnurl = $this->page->url; + if ($readcount === false) { + print_error('csvloaderror', '', $returnurl); + } else if ($readcount == 0) { + print_error('csvemptyfile', 'error', $returnurl); + } + + $result = mass_unenroll($cir, $course, $context, $data); + + $cir->close(); + $cir->cleanup(false); // Only currently uploaded CSV file. + + if ($data->mailreport) { + $a = new stdClass(); + $a->course = $course->fullname; + $a->report = $result; + email_to_user($USER, $USER, get_string('mail_unenrolment_subject', 'local_mass_enroll', $CFG->wwwroot), + get_string('mail_unenrolment', 'local_mass_enroll', $a)); + $result .= "\n" . get_string('email_sent', 'local_mass_enroll', $USER->email); + } + + $out .= $this->header(); + $out .= $this->get_tabs($context, $currenttab, array('id' => $course->id)); + $out .= $this->heading($strinscriptions); + $out .= $this->box(nl2br($result), 'center'); + $out .= $this->continue_button($this->page->url); // Back to this page. + $out .= $this->footer($course); + return $out; + } + + $out .= $this->header(); + $out .= $this->get_tabs($context, $currenttab, array('id' => $course->id)); + $out .= $this->heading_with_help($strinscriptions, 'mass_unenroll', 'local_mass_enroll', + 'icon', get_string('mass_unenroll', 'local_mass_enroll')); + $out .= $this->box(get_string('mass_unenroll_info', 'local_mass_enroll'), 'center'); + $out .= $mform->render(); + $out .= $this->footer($course); + + return $out; + } + + /** + * Get tabs + * + * @param \context $context + * @param string $selected + * @param array $params page parameters + * @return string + */ + protected function get_tabs($context, $selected, $params = array()) { + global $CFG; + $tabs = array(); + + if (has_capability('local/mass_enroll:enrol', $context)) { + $enrol = new \moodle_url($CFG->wwwroot . '/local/mass_enroll/mass_enroll.php', $params); + $tabs[] = new \tabobject('mass_enroll', $enrol, get_string('mass_enroll', 'local_mass_enroll')); + } + + if (has_capability('local/mass_enroll:unenrol', $context)) { + $unenrol = new \moodle_url($CFG->wwwroot . '/local/mass_enroll/mass_unenroll.php', $params); + $tabs[] = new \tabobject('mass_unenroll', $unenrol, get_string('mass_unenroll', 'local_mass_enroll')); + } + + return '
' . $this->tabtree($tabs, $selected) . '
'; + } + +} diff --git a/settings.php b/settings.php new file mode 100644 index 0000000..4414b78 --- /dev/null +++ b/settings.php @@ -0,0 +1,58 @@ +. + +/** + * Mass enrol admin settings and defaults + * + * File settings.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright Sebsoft.nl + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +if ($hassiteconfig) { + $settings = new admin_settingpage('localsettingmassenroll', new lang_string('massenrollsettings', 'local_mass_enroll')); + + $settings->add(new admin_setting_heading('localmassenrolldefaults', + get_string('localmassenrolldefaults', 'local_mass_enroll'), + '')); + + $yesno = array(0 => get_string('no'), 1 => get_string('yes')); + $settings->add(new admin_setting_configselect('local_mass_enroll/mailreportdefault', + get_string('mailreportdefault', 'local_mass_enroll'), + get_string('mailreportdefault_help', 'local_mass_enroll'), 1, $yesno)); + + $settings->add(new admin_setting_heading('localmassenrollextensions', + get_string('localmassenrollextensions', 'local_mass_enroll'), + '')); + + $settings->add(new admin_setting_configcheckbox('local_mass_enroll/enablemassenrol', + get_string('enablemassenrol', 'local_mass_enroll'), + get_string('enablemassenrol_help', 'local_mass_enroll'), 1)); + + $settings->add(new admin_setting_configcheckbox('local_mass_enroll/enablemassunenrol', + get_string('enablemassunenrol', 'local_mass_enroll'), + get_string('enablemassunenrol_help', 'local_mass_enroll'), 1)); + + $ADMIN->add('localplugins', $settings); +} \ No newline at end of file diff --git a/version.php b/version.php new file mode 100644 index 0000000..94e3fe6 --- /dev/null +++ b/version.php @@ -0,0 +1,35 @@ +. + +/** + * Version information + * + * File version.php + * Encoding UTF-8 + * + * @package local_mass_enroll + * + * @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com} + * @copyright 2012 onwards Patrick Pollet + * @copyright 2015 onwards R.J. van Dongen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +defined('MOODLE_INTERNAL') || die(); +$plugin->version = 2015092402; // The current plugin version (Date: YYYYMMDDXX). +$plugin->requires = 2014051200; // Moodle 2.7 onwards. +$plugin->component = 'local_mass_enroll'; // Full name of the plugin (used for diagnostics). +$plugin->maturity = MATURITY_STABLE; // Required for registering to Moodle's database of plugins. +$plugin->release = '2.7.0 (Build 2015092402)';// Required for registering to Moodle's database of plugins.